ioacademy-jikim 3 years ago
parent
commit
b313330e0f

BIN
04_day.pptx View File


BIN
04_day/hal/a.out View File


+ 19
- 0
04_day/hal/led.c View File

@@ -0,0 +1,19 @@
1
+#include <stdio.h>
2
+
3
+typedef struct module
4
+{
5
+	void (*on)();
6
+	void (*off)();
7
+} module_t;
8
+
9
+void ledOn()
10
+{
11
+	printf("ledOn()\n");
12
+}
13
+
14
+void ledOff()
15
+{
16
+	printf("ledOff()\n");
17
+}
18
+
19
+module_t  HMI = { ledOn, ledOff };

BIN
04_day/hal/led.o View File


BIN
04_day/hal/libled.a View File


BIN
04_day/hal/libled.so View File


+ 19
- 0
04_day/hal/main.c View File

@@ -0,0 +1,19 @@
1
+#include <dlfcn.h>
2
+
3
+typedef struct module
4
+{
5
+	void (*on)();
6
+	void (*off)();
7
+} module_t;
8
+
9
+int main()
10
+{
11
+    void *handle;
12
+	module_t *module;
13
+	handle = dlopen("libled.so", RTLD_NOW);
14
+	module = dlsym( handle, "HMI" );
15
+	module->on();
16
+	module->off();
17
+	dlclose(handle);
18
+	return 0;
19
+}

+ 7
- 0
04_day/hidl/Android.bp View File

@@ -0,0 +1,7 @@
1
+subdirs = [
2
+    "server",
3
+]
4
+
5
+
6
+
7
+

+ 7
- 0
04_day/hidl/client/Android.mk View File

@@ -0,0 +1,7 @@
1
+LOCAL_PATH:= $(call my-dir)
2
+
3
+include $(CLEAR_VARS)
4
+LOCAL_SHARED_LIBRARIES = liblog libutils libhidlbase android.hardware.samples@1.0
5
+LOCAL_SRC_FILES := client.cpp 
6
+LOCAL_MODULE := my_client
7
+include $(BUILD_EXECUTABLE)

+ 20
- 0
04_day/hidl/client/client.cpp View File

@@ -0,0 +1,20 @@
1
+#include <android-base/logging.h>
2
+#include <android/hardware/samples/1.0/IFoo.h>
3
+#include <set>
4
+#include <unistd.h>
5
+#include <stdio.h>
6
+
7
+using ::android::hardware::samples::V1_0::IFoo;
8
+using ::android::hardware::Return;
9
+using ::android::hardware::Void;
10
+using ::android::sp;
11
+
12
+
13
+int main()
14
+{
15
+	sp<IFoo> foo;
16
+	foo = IFoo::getService();
17
+	foo->foo();
18
+	return 0;
19
+}
20
+

+ 7
- 0
04_day/hidl/client_light/Android.mk View File

@@ -0,0 +1,7 @@
1
+LOCAL_PATH:= $(call my-dir)
2
+
3
+include $(CLEAR_VARS)
4
+LOCAL_SHARED_LIBRARIES = liblog libutils libhidlbase android.hardware.light@2.0
5
+LOCAL_SRC_FILES := light_client.cpp 
6
+LOCAL_MODULE := light_client
7
+include $(BUILD_EXECUTABLE)

+ 38
- 0
04_day/hidl/client_light/light_client.cpp View File

@@ -0,0 +1,38 @@
1
+#include <android-base/logging.h>
2
+#include <android/hardware/light/2.0/ILight.h>
3
+#include <android/hardware/light/2.0/types.h>
4
+#include <set>
5
+#include <unistd.h>
6
+#include <stdio.h>
7
+
8
+using ::android::hardware::light::V2_0::Brightness;
9
+using ::android::hardware::light::V2_0::Flash;
10
+using ::android::hardware::light::V2_0::ILight;
11
+using ::android::hardware::light::V2_0::LightState;
12
+using ::android::hardware::light::V2_0::Status;
13
+using ::android::hardware::light::V2_0::Type;
14
+using ::android::hardware::Return;
15
+using ::android::hardware::Void;
16
+using ::android::sp;
17
+
18
+
19
+const static LightState kWhite = {
20
+    .color = 0xFFFFFFFF,
21
+    .flashMode = Flash::TIMED,
22
+    .flashOnMs = 100,
23
+    .flashOffMs = 50,
24
+    .brightnessMode = Brightness::USER,
25
+};
26
+
27
+int main()
28
+{
29
+	sp<ILight> light;
30
+	light = ILight::getService();
31
+	Return<Status> ret = light->setLight( Type::BACKLIGHT, kWhite);
32
+	//if( ret.isOk() == false )
33
+	//	return -1;
34
+	//if( Status::SUCCESS == static_cast<Status>(ret) )
35
+	//	return 0;
36
+	return 0;
37
+}
38
+

+ 66
- 0
04_day/hidl/server/.hardware/interfaces/samples/1.0/Android.bp View File

@@ -0,0 +1,66 @@
1
+// This file is autogenerated by hidl-gen. Do not edit manually.
2
+
3
+filegroup {
4
+    name: "android.hardware.samples@1.0_hal",
5
+    srcs: [
6
+        "types.hal",
7
+        "IFoo.hal",
8
+    ],
9
+}
10
+
11
+genrule {
12
+    name: "android.hardware.samples@1.0_genc++",
13
+    tools: ["hidl-gen"],
14
+    cmd: "$(location hidl-gen) -o $(genDir) -Lc++-sources -randroid.hardware:hardware/interfaces -randroid.hidl:system/libhidl/transport android.hardware.samples@1.0",
15
+    srcs: [
16
+        ":android.hardware.samples@1.0_hal",
17
+    ],
18
+    out: [
19
+        "android/hardware/samples/1.0/types.cpp",
20
+        "android/hardware/samples/1.0/FooAll.cpp",
21
+    ],
22
+}
23
+
24
+genrule {
25
+    name: "android.hardware.samples@1.0_genc++_headers",
26
+    tools: ["hidl-gen"],
27
+    cmd: "$(location hidl-gen) -o $(genDir) -Lc++-headers -randroid.hardware:hardware/interfaces -randroid.hidl:system/libhidl/transport android.hardware.samples@1.0",
28
+    srcs: [
29
+        ":android.hardware.samples@1.0_hal",
30
+    ],
31
+    out: [
32
+        "android/hardware/samples/1.0/types.h",
33
+        "android/hardware/samples/1.0/hwtypes.h",
34
+        "android/hardware/samples/1.0/IFoo.h",
35
+        "android/hardware/samples/1.0/IHwFoo.h",
36
+        "android/hardware/samples/1.0/BnHwFoo.h",
37
+        "android/hardware/samples/1.0/BpHwFoo.h",
38
+        "android/hardware/samples/1.0/BsFoo.h",
39
+    ],
40
+}
41
+
42
+cc_library {
43
+    name: "android.hardware.samples@1.0",
44
+    defaults: ["hidl-module-defaults"],
45
+    generated_sources: ["android.hardware.samples@1.0_genc++"],
46
+    generated_headers: ["android.hardware.samples@1.0_genc++_headers"],
47
+    export_generated_headers: ["android.hardware.samples@1.0_genc++_headers"],
48
+    vendor_available: true,
49
+    vndk: {
50
+        enabled: true,
51
+    },
52
+    shared_libs: [
53
+        "libhidlbase",
54
+        "libhidltransport",
55
+        "libhwbinder",
56
+        "liblog",
57
+        "libutils",
58
+        "libcutils",
59
+    ],
60
+    export_shared_lib_headers: [
61
+        "libhidlbase",
62
+        "libhidltransport",
63
+        "libhwbinder",
64
+        "libutils",
65
+    ],
66
+}

+ 15
- 0
04_day/hidl/server/Android.bp View File

@@ -0,0 +1,15 @@
1
+cc_binary {
2
+    name: "android.hardware.samples@1.0-service",
3
+    relative_install_path: "hw",
4
+    proprietary: true,
5
+    srcs: [
6
+        "Foo.cpp",
7
+        "service.cpp",
8
+    ],
9
+    shared_libs: [
10
+        "libhidlbase",
11
+        "libhidltransport",
12
+        "libutils",
13
+        "android.hardware.samples@1.0",
14
+    ],
15
+}

+ 27
- 0
04_day/hidl/server/Foo.cpp View File

@@ -0,0 +1,27 @@
1
+#include <iostream>
2
+#include "Foo.h"
3
+
4
+namespace android {
5
+namespace hardware {
6
+namespace samples {
7
+namespace V1_0 {
8
+namespace implementation {
9
+
10
+// Methods from IFoo follow.
11
+Return<void> Foo::foo() {
12
+	std::cout << "Foo::foo()" <<std::endl;
13
+    return Void();
14
+}
15
+
16
+
17
+// Methods from ::android::hidl::base::V1_0::IBase follow.
18
+
19
+//IFoo* HIDL_FETCH_IFoo(const char* /* name */) {
20
+//    return new Foo();
21
+//}
22
+
23
+}  // namespace implementation
24
+}  // namespace V1_0
25
+}  // namespace samples
26
+}  // namespace hardware
27
+}  // namespace android

+ 39
- 0
04_day/hidl/server/Foo.h View File

@@ -0,0 +1,39 @@
1
+#ifndef ANDROID_HARDWARE_SAMPLES_V1_0_FOO_H
2
+#define ANDROID_HARDWARE_SAMPLES_V1_0_FOO_H
3
+
4
+#include <android/hardware/samples/1.0/IFoo.h>
5
+#include <hidl/MQDescriptor.h>
6
+#include <hidl/Status.h>
7
+
8
+namespace android {
9
+namespace hardware {
10
+namespace samples {
11
+namespace V1_0 {
12
+namespace implementation {
13
+
14
+using ::android::hardware::hidl_array;
15
+using ::android::hardware::hidl_memory;
16
+using ::android::hardware::hidl_string;
17
+using ::android::hardware::hidl_vec;
18
+using ::android::hardware::Return;
19
+using ::android::hardware::Void;
20
+using ::android::sp;
21
+
22
+struct Foo : public IFoo {
23
+    // Methods from IFoo follow.
24
+    Return<void> foo() override;
25
+
26
+    // Methods from ::android::hidl::base::V1_0::IBase follow.
27
+
28
+};
29
+
30
+// FIXME: most likely delete, this is only for passthrough implementations
31
+// extern "C" IFoo* HIDL_FETCH_IFoo(const char* name);
32
+
33
+}  // namespace implementation
34
+}  // namespace V1_0
35
+}  // namespace samples
36
+}  // namespace hardware
37
+}  // namespace android
38
+
39
+#endif  // ANDROID_HARDWARE_SAMPLES_V1_0_FOO_H

+ 32
- 0
04_day/hidl/server/service.cpp View File

@@ -0,0 +1,32 @@
1
+#include <android-base/logging.h>
2
+#include <hidl/HidlTransportSupport.h>
3
+#include <utils/Errors.h>
4
+#include <iostream>
5
+
6
+#include "Foo.h"
7
+
8
+using android::sp;
9
+using android::status_t;
10
+using android::OK;
11
+
12
+// libhwbinder:
13
+using android::hardware::configureRpcThreadpool;
14
+using android::hardware::joinRpcThreadpool;
15
+
16
+// Generated HIDL files
17
+using android::hardware::samples::V1_0::IFoo;
18
+using android::hardware::samples::V1_0::implementation::Foo;
19
+
20
+int main() {
21
+    status_t status;
22
+    android::sp<Foo> service = nullptr;
23
+
24
+	service = new Foo();
25
+
26
+	configureRpcThreadpool(1, true);
27
+	service->registerAsService();
28
+	std::cout << "Foo HAL Service is ready." << std::endl;
29
+    joinRpcThreadpool();
30
+	return 0;
31
+}
32
+