原创作品,允许转载,转载时请务必以超链接形式标明文章
原始出处 、作者信息和本声明。否则将追究法律责任。
http://buaadallas.blog.51cto.com/399160/371545
- .
- |-- apps -- 测试应用程序
- | |-- LedClient -- 直接调用service控制硬件
- | | |-- AndroidManifest.xml
- | | `-- src
- | | `-- com
- | | `-- mokoid
- | | `-- LedClient
- | | `-- LedClient.java
- | `-- LedTest -- 通过manager来控制硬件
- | |-- AndroidManifest.xml
- | `-- src
- | `-- com
- | `-- mokoid
- | `-- LedTest
- | |-- LedSystemServer.java
- | `-- LedTest.java
- |-- frameworks -- 框架代码
- | `-- base
- | |-- core
- | | `-- java
- | | `-- mokoid
- | | `-- hardware
- | | |-- ILedService.aidl -- Android Interface Definition Language 代码,提供LedService的接口
- | | `-- LedManager.java -- LedManager实现代码
- | `-- service
- | |-- com.mokoid.server.xml
- | |-- java
- | | `-- com
- | | `-- mokoid
- | | `-- server
- | | `-- LedService.java -- LedService的java实现代码
- | `-- jni
- | `-- com_mokoid_server_LedService.cpp -- LedService的jni实现代码
- |-- hardware
- `-- modules
- |-- include
- | `-- mokoid
- | `-- led.h
- `-- led
- `-- led.c -- led实际控制硬件的代码
- struct led_module_t {
- struct hw_module_t common;
- };
- struct led_control_device_t {
- struct hw_device_t common;
- /* attributes */
- int fd;
- /* supporting control APIs go here */
- /* 打开led操作*/
- int (*set_on)(struct led_control_device_t *dev, int32_t led);
- /* 关闭led操作 */
- int (*set_off)(struct led_control_device_t *dev, int32_t led);
- };
- /* 打开led操作 */
- int led_on(struct led_control_device_t *dev, int32_t led)
- {
- LOGI("LED Stub: set %d on.", led);
- return 0;
- }
- /* 关闭led操作 */
- int led_off(struct led_control_device_t *dev, int32_t led)
- {
- LOGI("LED Stub: set %d off.", led);
- return 0;
- }
- /* 打开led硬件时候的操作 */
- static int led_device_open(const struct hw_module_t* module, const char* name,
- struct hw_device_t** device)
- {
- struct led_control_device_t *dev;
- dev = (struct led_control_device_t *)malloc(sizeof(*dev));
- memset(dev, 0, sizeof(*dev));
- ...
- /* 提供给service可用的硬件操作接口 */
- dev->set_on = led_on;
- dev->set_off = led_off;
- *device = &dev->common;
- success:
- return 0;
- }
- static struct hw_module_methods_t led_module_methods = {
- open: led_device_open
- };
- const struct led_module_t HAL_MODULE_INFO_SYM = {
- common: {
- tag: HARDWARE_MODULE_TAG,
- version_major: 1,
- version_minor: 0,
- id: LED_HARDWARE_MODULE_ID,
- name: "Sample LED Stub",
- author: "The Mokoid Open Source Project",
- methods: &led_module_methods,
- }
- /* supporting APIs go here */
- };