aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorwang_zhiqiang <wang_zhiqiang@dl.cn.nexty-ele.com>2019-05-25 10:47:36 +0800
committerwang_zhiqiang <wang_zhiqiang@dl.cn.nexty-ele.com>2019-05-25 10:47:36 +0800
commitedde653b1e4735618242811bd4af8b34ae2f9053 (patch)
treec6e4f78faefeb3d32a33ed3c03fbfe59d1db2012
parentddd0edd5b9e56264bedc19ad7887150c51bb3071 (diff)
add register/update shortcut
Change-Id: If0f4095ce405fb89831cec7e18dfa63aec78717b
-rw-r--r--include/libhomescreen.hpp6
-rw-r--r--src/libhomescreen.cpp114
2 files changed, 72 insertions, 48 deletions
diff --git a/include/libhomescreen.hpp b/include/libhomescreen.hpp
index 32a9121..4abb8b2 100644
--- a/include/libhomescreen.hpp
+++ b/include/libhomescreen.hpp
@@ -51,6 +51,8 @@ public:
Event_ShowNotification,
Event_ShowInformation,
Event_AppListChanged,
+ Event_RegisterShortcut,
+ Event_UpdateShortcut,
Event_Max
};
@@ -83,10 +85,12 @@ public:
int showNotification(json_object* json);
int showInformation(json_object* json);
int getRunnables(void);
-
+ int registerShortcut(json_object* json);
+ int updateShortcut(json_object* json);
private:
int initialize_websocket();
+ int getEventType(const char *event);
void (*onEvent)(const std::string& event, struct json_object* event_contents);
void (*onReply)(struct json_object* reply);
diff --git a/src/libhomescreen.cpp b/src/libhomescreen.cpp
index 71afa66..d0c0d1c 100644
--- a/src/libhomescreen.cpp
+++ b/src/libhomescreen.cpp
@@ -49,7 +49,9 @@ const std::vector<std::string> LibHomeScreen::api_list {
std::string("replyShowWindow"),
std::string("showNotification"),
std::string("showInformation"),
- std::string("getRunnables")
+ std::string("getRunnables"),
+ std::string("registerShortcut"),
+ std::string("updateShortcut")
};
const std::vector<std::string> LibHomeScreen::event_list {
@@ -62,6 +64,8 @@ const std::vector<std::string> LibHomeScreen::event_list {
std::string("showNotification"),
std::string("showInformation"),
std::string("application-list-changed"),
+ std::string("registerShortcut"),
+ std::string("updateShortcut"),
std::string("none")
};
@@ -613,6 +617,49 @@ int LibHomeScreen::getRunnables(void)
return this->call("getRunnables", nullptr);
}
+/**
+ * register shortcut to homescreen
+ *
+ * Call HomeScreen Service's registerShortcut verb to regitster shortcut.
+ *
+ * #### Parameters
+ * - json [in] : This argument should be specified to the json parameters.
+ *
+ * #### Return
+ * - Returns 0 on success or -1 in case of error.
+ *
+ */
+int LibHomeScreen::registerShortcut(json_object* json)
+{
+ if(!sp_websock)
+ {
+ return -1;
+ }
+
+ return this->call("registerShortcut", json);
+}
+
+/**
+ * update shortcut list
+ *
+ * Call HomeScreen Service's updateShortcut verb to notify shortcut list.
+ *
+ * #### Parameters
+ * - json [in] : This argument should be specified to the json parameters.
+ *
+ * #### Return
+ * - Returns 0 on success or -1 in case of error.
+ *
+ */
+int LibHomeScreen::updateShortcut(json_object* json)
+{
+ if(!sp_websock)
+ {
+ return -1;
+ }
+
+ return this->call("updateShortcut", json);
+}
/************* Callback Function *************/
@@ -666,52 +713,11 @@ void LibHomeScreen::on_event(void *closure, const char *event, struct afb_wsj1_m
return;
}
- if (strcasecmp(event_type, LibHomeScreen::event_list[0].c_str()) == 0) {
- auto i = this->handlers.find(Event_ShowWindow);
- if ( i != this->handlers.end() ) {
- i->second(json_data);
- }
- }
- else if (strcasecmp(event_type, LibHomeScreen::event_list[1].c_str()) == 0) {
- auto i = this->handlers.find(Event_OnScreenMessage);
- if ( i != this->handlers.end() ) {
- i->second(json_data);
- }
- }
- else if (strcasecmp(event_type, LibHomeScreen::event_list[2].c_str()) == 0) {
- auto i = this->handlers.find(Event_OnScreenReply);
- if ( i != this->handlers.end() ) {
- i->second(json_data);
- }
- }
- else if (strcasecmp(event_type, LibHomeScreen::event_list[3].c_str()) == 0) {
- auto i = this->handlers.find(Event_HideWindow);
- if ( i != this->handlers.end() ) {
- i->second(json_data);
- }
- }
- else if (strcasecmp(event_type, LibHomeScreen::event_list[4].c_str()) == 0) {
- auto i = this->handlers.find(Event_ReplyShowWindow);
- if ( i != this->handlers.end() ) {
- i->second(json_data);
- }
- }
- else if (strcasecmp(event_type, LibHomeScreen::event_list[5].c_str()) == 0) {
- auto i = this->handlers.find(Event_ShowNotification);
- if ( i != this->handlers.end() ) {
- i->second(json_data);
- }
- }
- else if (strcasecmp(event_type, LibHomeScreen::event_list[6].c_str()) == 0) {
- auto i = this->handlers.find(Event_ShowInformation);
- if ( i != this->handlers.end() ) {
- i->second(json_data);
- }
- }
- else if (strcasecmp(event_type, LibHomeScreen::event_list[7].c_str()) == 0) {
- auto i = this->handlers.find(Event_AppListChanged);
- if ( i != this->handlers.end() ) {
- i->second(json_data);
+ int e_type = getEventType(event_type);
+ if(e_type < Event_Max) {
+ auto it = this->handlers.find(EventType(e_type));
+ if ( it != this->handlers.end() ) {
+ it->second(json_data);
}
}
}
@@ -730,6 +736,20 @@ void LibHomeScreen::on_reply(void *closure, struct afb_wsj1_msg *msg)
}
}
+/*
+* convert event name to event type
+*/
+int LibHomeScreen::getEventType(const char *event)
+{
+ int i = 0;
+ for(; i < LibHomeScreen::event_list.size(); ++i) {
+ if (strcasecmp(event, LibHomeScreen::event_list[i].c_str()) == 0) {
+ break;
+ }
+ }
+ return (i + 1) < Event_Max ? i : Event_Max;
+}
+
static bool has_verb(const string& verb)
{
HMI_DEBUG("libhomescreen","verb is %s", verb.c_str());