aboutsummaryrefslogtreecommitdiffstats
path: root/src/homescreen.cpp
diff options
context:
space:
mode:
authorwang_zhiqiang <wang_zhiqiang@dl.cn.nexty-ele.com>2018-09-19 14:42:30 +0800
committerwang_zhiqiang <wang_zhiqiang@dl.cn.nexty-ele.com>2018-09-19 14:43:45 +0800
commitbe6dd71ae4f9de1b1151f419aef39b6196903db9 (patch)
treea6ac0812d739940be9120d5e62443845b9209d67 /src/homescreen.cpp
parent2aa2fc0f925fb529b0a4db038d91398bb627fd1a (diff)
Init afb_daemon event with loop
use loop to make afb_daemon event automatically. Change-Id: I599d333fea7feb18db91ed3bbe43faad405c41c1 Signed-off-by: wang_zhiqiang <wang_zhiqiang@dl.cn.nexty-ele.com>
Diffstat (limited to 'src/homescreen.cpp')
-rw-r--r--src/homescreen.cpp44
1 files changed, 13 insertions, 31 deletions
diff --git a/src/homescreen.cpp b/src/homescreen.cpp
index 5de15b8..744535b 100644
--- a/src/homescreen.cpp
+++ b/src/homescreen.cpp
@@ -26,18 +26,12 @@
/* To Do hash table is better */
struct event{
const char* name;
- struct afb_event* event;
- };
+ struct afb_event event;
+};
static struct event event_list[COMMAND_EVENT_NUM];
-static struct afb_event ev_tap_shortcut;
-static struct afb_event ev_on_screen_message;
-static struct afb_event ev_on_screen_reply;
-static struct afb_event ev_reserved;
-
static const char _error[] = "error";
-
static const char _application_name[] = "application_name";
static const char _display_message[] = "display_message";
static const char _reply_message[] = "reply_message";
@@ -79,7 +73,7 @@ static void tap_shortcut (struct afb_req request)
struct json_object* push_obj = json_object_new_object();
hs_add_object_to_json_object_str( push_obj, 2,
_application_name, value);
- afb_event_push(ev_tap_shortcut, push_obj);
+ afb_event_push(event_list[hs_search_event_name_index(__FUNCTION__)].event, push_obj);
} else {
afb_req_fail_f(request, "failed", "called %s, Unknown palameter", __FUNCTION__);
return;
@@ -116,7 +110,7 @@ static void on_screen_message (struct afb_req request)
struct json_object* push_obj = json_object_new_object();
hs_add_object_to_json_object_str( push_obj, 2,
_display_message, value);
- afb_event_push(ev_on_screen_message, push_obj);
+ afb_event_push(event_list[hs_search_event_name_index(__FUNCTION__)].event, push_obj);
} else {
afb_req_fail_f(request, "failed", "called %s, Unknown palameter", __FUNCTION__);
return;
@@ -153,7 +147,7 @@ static void on_screen_reply (struct afb_req request)
struct json_object* push_obj = json_object_new_object();
hs_add_object_to_json_object_str( push_obj, 2,
_reply_message, value);
- afb_event_push(ev_on_screen_reply, push_obj);
+ afb_event_push(event_list[hs_search_event_name_index(__FUNCTION__)].event, push_obj);
} else {
afb_req_fail_f(request, "failed", "called %s, Unknown palameter", __FUNCTION__);
return;
@@ -190,7 +184,7 @@ static void subscribe(struct afb_req request)
}
else
{
- afb_req_subscribe(request, *event_list[index].event);
+ afb_req_subscribe(request, event_list[index].event);
}
}
else{
@@ -228,7 +222,7 @@ static void unsubscribe(struct afb_req request)
}
else
{
- afb_req_unsubscribe(request, *event_list[index].event);
+ afb_req_unsubscribe(request, event_list[index].event);
}
}
else{
@@ -284,26 +278,14 @@ static int preinit()
*/
static int init()
{
- HMI_NOTICE("homescreen-service","binding init");
-
- ev_tap_shortcut = afb_daemon_make_event(evlist[0]);
- ev_on_screen_message = afb_daemon_make_event(evlist[1]);
- ev_on_screen_reply = afb_daemon_make_event(evlist[2]);
- ev_reserved = afb_daemon_make_event(evlist[3]);
-
- event_list[0].name = evlist[0];
- event_list[0].event = &ev_tap_shortcut;
+ HMI_NOTICE("homescreen-service","binding init");
- event_list[1].name = evlist[1];
- event_list[1].event = &ev_on_screen_message;
-
- event_list[2].name = evlist[2];
- event_list[2].event = &ev_on_screen_reply;
-
- event_list[3].name = evlist[3];
- event_list[3].event = &ev_reserved;
+ for(int i = 0; i < COMMAND_EVENT_NUM; ++i) {
+ event_list[i].name = evlist[i];
+ event_list[i].event = afb_daemon_make_event(evlist[i]);
+ }
- return 0;
+ return 0;
}
/**