mmi_module_t MMI_MODULE_INFO_SYM = {
.version_major = 1,
.version_minor = 0,
.name = "Light",
.author = "Qualcomm Technologies, Inc.",
.methods = &module_methods,
.module_handle = NULL,
.supported_cmd_list = NULL,
.supported_cmd_list_size = 0,
.cb_print = NULL, /**it is initialized by mmi agent*/
.run_pid = -1,
};
MMI_MODULE_INFO_SYM
module_methods
module_init
pthread_mutex_init(&g_mutex, NULL); //初始化互斥
ret = hal_init();
devices = (struct Devices *) malloc(sizeof(struct Devices)); //分配设备的内存
ret = hw_get_module(LIGHTS_HARDWARE_MODULE_ID, (hw_module_t const **) &hw_module); //拉去light module
devices->lights[LIGHT_INDEX_BACKLIGHT] = get_device(hw_module, LIGHT_ID_BACKLIGHT); //分配light 的类型
devices->lights[LIGHT_INDEX_KEYBOARD] = get_device(hw_module, LIGHT_ID_KEYBOARD);
devices->lights[LIGHT_INDEX_BUTTONS] = get_device(hw_module, LIGHT_ID_BUTTONS);
devices->lights[LIGHT_INDEX_BATTERY] = get_device(hw_module, LIGHT_ID_BATTERY);
devices->lights[LIGHT_INDEX_NOTIFICATIONS] = get_device(hw_module, LIGHT_ID_NOTIFICATIONS);
devices->lights[LIGHT_INDEX_ATTENTION] = get_device(hw_module, LIGHT_ID_ATTENTION);
devices->lights[LIGHT_INDEX_BLUETOOTH] = get_device(hw_module, LIGHT_ID_BLUETOOTH);
devices->lights[LIGHT_INDEX_WIFI] = get_device(hw_module, LIGHT_ID_WIFI);
err = module->methods->open(module, name, &device); //打开设备
return (light_device_t *) device; //成功打开设备,返回指针
module_deinit
module_run
ret = module_run_mmi(module, params); //建立了一个runtest的任务
pthread_mutex_lock(&g_mutex); //互斥的锁定
ret = init(params); //初始化参数
light_delay = atoi(params["delay"].c_str()); //获取延时的时间
params["type"].c_str() light_device = LIGHT_INDEX_NOTIFICATIONS; //解析指令的类型
params["color"].c_str() led_color = LED_COLOR_RED;
//解析控制灯的颜色
ret = pthread_create((pthread_t *) & module->run_pid, NULL, run_test, (void *) module); //建立亮灯的任务
signal(SIGUSR1, signal_handler); //获取信号量,但不知道信号量从哪里获取的
enable((const mmi_module_t *) mod, true);
usleep(1000 * light_delay);
enable((const mmi_module_t *) mod, false);
usleep(1000 * light_delay);
pthread_join(module->run_pid, NULL); //把建立的任务加入任务联中
pthread_mutex_unlock(&g_mutex); //解除互斥
ret = module_run_pcba(module, params); //单个指令的控制
ret = init(params); //获取解析参数
light_delay = atoi(params["delay"].c_str());
params["type"].c_str() light_device = LIGHT_INDEX_NOTIFICATIONS;
params["color"].c_str() led_color = LED_COLOR_RED;
enable(module, true); //打开灯
module_stop
kill_thread(module->run_pid); //结束建立的任务
deinit(module);
enable(mod, false);