summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorwang_zhiqiang <wang_zhiqiang@dl.cn.nexty-ele.com>2018-11-14 11:14:04 +0800
committerwang_zhiqiang <wang_zhiqiang@dl.cn.nexty-ele.com>2018-11-21 16:51:10 +0800
commitc0146077906057bf97688a617870228eaad0cf54 (patch)
tree7d7bcc9a8a58c8c1f137be3872b643566c08e78c
parent43452ff8a759da135525678528c159f1e4e68504 (diff)
homescreen-service: add five verbs. 1.showWindow: instead of tap_shortcut and show onscreen. 2.hideWindow: used when want to hide onscreen. 3.replyShowWindow: used when post onscreen reply information to application. 4.showNotification: used by application who want to display notification on homescreen top area. 5.showInformation: used by application who want to display information on homescreen botton area. homescreen: 1.add fullscreen transfer button. 2.display notification and information. Bug-AGL: SPEC-1931 Change-Id: Ie0753fe0656282b1ff8c04dcef625f2a4154edde Signed-off-by: wang_zhiqiang <wang_zhiqiang@dl.cn.nexty-ele.com>
-rw-r--r--include/libhomescreen.hpp106
-rw-r--r--sample/simple-egl/src/simple-egl.cpp14
-rw-r--r--sample/template/main.cpp27
-rw-r--r--src/libhomescreen.cpp210
4 files changed, 285 insertions, 72 deletions
diff --git a/include/libhomescreen.hpp b/include/libhomescreen.hpp
index 54662d4..0fed49f 100644
--- a/include/libhomescreen.hpp
+++ b/include/libhomescreen.hpp
@@ -31,65 +31,87 @@ extern "C"
class LibHomeScreen
{
public:
- LibHomeScreen();
- ~LibHomeScreen();
+ LibHomeScreen();
+ ~LibHomeScreen();
- LibHomeScreen(const LibHomeScreen &) = delete;
- LibHomeScreen &operator=(const LibHomeScreen &) = delete;
+ LibHomeScreen(const LibHomeScreen &) = delete;
+ LibHomeScreen &operator=(const LibHomeScreen &) = delete;
- using handler_func = std::function<void(json_object*)>;
+ using handler_func = std::function<void(json_object*)>;
- enum EventType {
- Event_TapShortcut = 1,
- Event_OnScreenMessage,
- Event_OnScreenReply
- };
+ enum EventType {
+ Event_ShowWindow = 1,
+ Event_TapShortcut = 1,
+ Event_OnScreenMessage,
+ Event_OnScreenReply,
+ Event_HideWindow,
+ Event_ReplyShowWindow,
+ Event_ShowNotification,
+ Event_ShowInformation
+ };
- static const std::vector<std::string> api_list;
- static const std::vector<std::string> event_list;
+ /* Key for json obejct */
+ const char *_keyParameter = "parameter";
+ const char *_keyArea = "area";
- /* Method */
- int init(const int port, const std::string& token);
+ /* display area */
+ const char *_areaNormal = "normal";
+ const char *_areaFullScreen = "fullscreen";
+ const char *_areaSplitMain = "split.main";
+ const char *_areaSplitSub = "split.sub";
- int tapShortcut(const char* application_id);
- int onScreenMessage(const char* display_message);
- int onScreenReply(const char* reply_message);
+ static const std::vector<std::string> api_list;
+ static const std::vector<std::string> event_list;
- void set_event_handler(enum EventType et, handler_func f);
+ /* Method */
+ int init(const int port, const std::string& token);
- void registerCallback(
- void (*event_cb)(const std::string& event, struct json_object* event_contents),
- void (*reply_cb)(struct json_object* reply_contents),
- void (*hangup_cb)(void) = nullptr);
+ int tapShortcut(const char* application_id);
+ int onScreenMessage(const char* display_message);
+ int onScreenReply(const char* reply_message);
+
+ void set_event_handler(enum EventType et, handler_func f);
+
+ void registerCallback(
+ void (*event_cb)(const std::string& event, struct json_object* event_contents),
+ void (*reply_cb)(struct json_object* reply_contents),
+ void (*hangup_cb)(void) = nullptr);
+
+ int call(const std::string& verb, struct json_object* arg);
+ int call(const char* verb, struct json_object* arg);
+ int subscribe(const std::string& event_name);
+ int unsubscribe(const std::string& event_name);
+
+ int showWindow(const char* application_id, json_object* json);
+ int hideWindow(const char* application_id);
+ int replyShowWindow(const char* application_id, json_object* json);
+ int showNotification(json_object* json);
+ int showInformation(json_object* json);
- int call(const std::string& verb, struct json_object* arg);
- int call(const char* verb, struct json_object* arg);
- int subscribe(const std::string& event_name);
- int unsubscribe(const std::string& event_name);
private:
- int initialize_websocket();
+ int initialize_websocket();
- void (*onEvent)(const std::string& event, struct json_object* event_contents);
- void (*onReply)(struct json_object* reply);
- void (*onHangup)(void);
+ void (*onEvent)(const std::string& event, struct json_object* event_contents);
+ void (*onReply)(struct json_object* reply);
+ void (*onHangup)(void);
- struct afb_wsj1* sp_websock;
- struct afb_wsj1_itf minterface;
- sd_event* mploop;
- std::string muri;
+ struct afb_wsj1* sp_websock;
+ struct afb_wsj1_itf minterface;
+ sd_event* mploop;
+ std::string muri;
- int mport = 2000;
- std::string mtoken = "hs";
+ int mport = 2000;
+ std::string mtoken = "hs";
- std::map<EventType, handler_func> handlers;
+ std::map<EventType, handler_func> handlers;
public:
- /* Don't use/ Internal only */
- void on_hangup(void *closure, struct afb_wsj1 *wsj);
- void on_call(void *closure, const char *api, const char *verb, struct afb_wsj1_msg *msg);
- void on_event(void *closure, const char *event, struct afb_wsj1_msg *msg);
- void on_reply(void *closure, struct afb_wsj1_msg *msg);
+ /* Don't use/ Internal only */
+ void on_hangup(void *closure, struct afb_wsj1 *wsj);
+ void on_call(void *closure, const char *api, const char *verb, struct afb_wsj1_msg *msg);
+ void on_event(void *closure, const char *event, struct afb_wsj1_msg *msg);
+ void on_reply(void *closure, struct afb_wsj1_msg *msg);
};
#endif /* LIBHOMESCREEN_H */
diff --git a/sample/simple-egl/src/simple-egl.cpp b/sample/simple-egl/src/simple-egl.cpp
index 4271a66..aa6ea19 100644
--- a/sample/simple-egl/src/simple-egl.cpp
+++ b/sample/simple-egl/src/simple-egl.cpp
@@ -569,9 +569,17 @@ init_hs(LibHomeScreen* hs){
return -1;
}
- hs->set_event_handler(LibHomeScreen::Event_TapShortcut, [](json_object *object){
- HMI_DEBUG("simple-egl","try to activesurface %s ", app_name.c_str());
- wm->activateWindow(main_role);
+ hs->set_event_handler(LibHomeScreen::Event_ShowWindow, [hs](json_object *object){
+ HMI_DEBUG("simple-egl","try to activeWindow %s ", app_name.c_str());
+
+ struct json_object *param_obj = json_object_object_get(object, hs->_keyParameter);
+ const char *area = json_object_get_string(
+ json_object_object_get(param_obj, hs->_keyArea));
+ // Application should call LibWindowmanager::activateWindow() in showWindow handler
+ if(area == nullptr)
+ wm->activateWindow(main_role, hs->_areaNormal);
+ else
+ wm->activateWindow(main_role, area);
});
return 0;
diff --git a/sample/template/main.cpp b/sample/template/main.cpp
index fef270b..848d2c5 100644
--- a/sample/template/main.cpp
+++ b/sample/template/main.cpp
@@ -90,9 +90,7 @@ int main(int argc, char *argv[])
}
// Application should call requestSurface at first
- json_object *obj = json_object_new_object();
- json_object_object_add(obj, wm->kKeyDrawingName, json_object_new_string(app_name.c_str()));
- if (wm->requestSurface(obj) != 0) {
+ if (wm->requestSurface(myname.c_str()) != 0) {
exit(EXIT_FAILURE);
}
@@ -122,11 +120,9 @@ int main(int argc, char *argv[])
json_object_object_get(object, wm->kKeyDrawingName));
const char *area = json_object_get_string(
json_object_object_get(object, wm->kKeyDrawingArea));
- fprintf(stderr, "Surface %s got syncDraw!\n", label);
+ fprintf(stderr, "Surface %s got syncDraw! area: %s.\n", label, area);
// Application should call LibWindowmanager::endDraw() in SyncDraw handler
- json_object *obj = json_object_new_object();
- json_object_object_add(obj, wm->kKeyDrawingName, json_object_new_string(app_name.c_str()));
- wm->endDraw(obj);
+ wm->endDraw(app_name.c_str());
});
wm->set_event_handler(LibWindowmanager::Event_FlushDraw, [wm](json_object *object) {
const char *label = json_object_get_string(
@@ -145,13 +141,16 @@ int main(int argc, char *argv[])
hs->init(port, token.c_str());
// Set event handler
- hs->set_event_handler(LibHomeScreen::Event_TapShortcut, [wm](json_object *object) {
- qDebug("Surface %s got tapShortcut\n", myname.c_str());
- // Application should call LibWindowmanager::endDraw() in TapShortcut handler
- json_object *obj = json_object_new_object();
- json_object_object_add(obj, wm->kKeyDrawingName, json_object_new_string(myname.c_str()));
- json_object_object_add(obj, wm->kKeyDrawingArea, json_object_new_string("normal.full"));
- wm->activateSurface(obj);
+ hs->set_event_handler(LibHomeScreen::Event_ShowWindow, [hs, wm](json_object *object) {
+ qDebug("Surface %s got showWindow\n", myname.c_str());
+ struct json_object *param_obj = json_object_object_get(object, hs->_keyParameter);
+ const char *area = json_object_get_string(
+ json_object_object_get(param_obj, hs->_keyArea));
+ // Application should call LibWindowmanager::activateWindow() in showWindow handler
+ if(area == nullptr)
+ wm->activateWindow(myname.c_str(), hs->_areaNormal);
+ else
+ wm->activateWindow(myname.c_str(), area);
});
/*
diff --git a/src/libhomescreen.cpp b/src/libhomescreen.cpp
index 29ba7ef..84e3472 100644
--- a/src/libhomescreen.cpp
+++ b/src/libhomescreen.cpp
@@ -33,6 +33,7 @@ using namespace std;
static bool has_verb(const string& verb);
static const char API[] = "homescreen";
+static const char ApplicationId[] = "application_id";
const std::vector<std::string> LibHomeScreen::api_list {
std::string("ping"), // debug do not use
@@ -40,13 +41,23 @@ const std::vector<std::string> LibHomeScreen::api_list {
std::string("on_screen_message"),
std::string("on_screen_reply"),
std::string("subscribe"),
- std::string("unsubscribe")
+ std::string("unsubscribe"),
+ std::string("showWindow"),
+ std::string("hideWindow"),
+ std::string("replyShowWindow"),
+ std::string("showNotification"),
+ std::string("showInformation")
};
const std::vector<std::string> LibHomeScreen::event_list {
- std::string("tap_shortcut"),
+// std::string("tap_shortcut"),
+ std::string("showWindow"),
std::string("on_screen_message"),
std::string("on_screen_reply"),
+ std::string("hideWindow"),
+ std::string("replyShowWindow"),
+ std::string("showNotification"),
+ std::string("showInformation"),
std::string("none")
};
@@ -210,15 +221,11 @@ END:
*/
int LibHomeScreen::tapShortcut(const char* application_id)
{
- if(!sp_websock)
- {
- return -1;
- }
+ struct json_object* obj = json_object_new_object();
+ struct json_object* val = json_object_new_string("normal");
+ json_object_object_add(obj, "area", val);
- struct json_object* j_obj = json_object_new_object();
- struct json_object* val = json_object_new_string(application_id);
- json_object_object_add(j_obj, "application_id", val);
- return this->call("tap_shortcut", j_obj);
+ return showWindow(application_id, obj);
}
/**
@@ -287,9 +294,9 @@ int LibHomeScreen::onScreenReply(const char* reply_message)
*/
void LibHomeScreen::set_event_handler(enum EventType et, handler_func f)
{
- if (et >= 1 && et <= 3) {
+ if (et >= 1 && et <= 7) {
switch (et) {
- case Event_TapShortcut:
+ case Event_ShowWindow:
this->subscribe(LibHomeScreen::event_list[0]);
break;
case Event_OnScreenMessage:
@@ -298,6 +305,18 @@ void LibHomeScreen::set_event_handler(enum EventType et, handler_func f)
case Event_OnScreenReply:
this->subscribe(LibHomeScreen::event_list[2]);
break;
+ case Event_HideWindow:
+ this->subscribe(LibHomeScreen::event_list[3]);
+ break;
+ case Event_ReplyShowWindow:
+ this->subscribe(LibHomeScreen::event_list[4]);
+ break;
+ case Event_ShowNotification:
+ this->subscribe(LibHomeScreen::event_list[5]);
+ break;
+ case Event_ShowInformation:
+ this->subscribe(LibHomeScreen::event_list[6]);
+ break;
}
this->handlers[et] = std::move(f);
@@ -429,6 +448,147 @@ int LibHomeScreen::unsubscribe(const string& event_name)
return ret;
}
+/**
+ * Sending show window event
+ *
+ * Call HomeScreen Service's showWindow verb to request display id's screen.
+ *
+ * #### Parameters
+ * - application_id [in] : This argument should be specified to the application's id.
+ * - json [in] : This argument should be specified to the json parameters.
+ *
+ * #### Return
+ * - Returns 0 on success or -1 in case of error.
+ *
+ */
+int LibHomeScreen::showWindow(const char* application_id, json_object* json)
+{
+ if(!sp_websock)
+ {
+ return -1;
+ }
+
+ struct json_object* j_obj = json_object_new_object();
+ struct json_object* val = json_object_new_string(application_id);
+ json_object_object_add(j_obj, ApplicationId, val);
+
+ if (json == nullptr) {
+ struct json_object* j_json = json_object_new_object();
+ struct json_object* value = json_object_new_string("normal");
+ json_object_object_add(j_json, "area", value);
+ json_object_object_add(j_obj, "parameter", j_json);
+ }
+ else {
+ json_object_object_add(j_obj, "parameter", json);
+ }
+
+ return this->call("showWindow", j_obj);
+}
+
+/**
+ * Sending hide window event
+ *
+ * Call HomeScreen Service's hideWindow verb to release id's screen.
+ *
+ * #### Parameters
+ * - application_id [in] : This argument should be specified to the application's id.
+ *
+ * #### Return
+ * - Returns 0 on success or -1 in case of error.
+ *
+ */
+int LibHomeScreen::hideWindow(const char* application_id)
+{
+ if(!sp_websock)
+ {
+ return -1;
+ }
+
+ struct json_object* j_obj = json_object_new_object();
+ struct json_object* val = json_object_new_string(application_id);
+ json_object_object_add(j_obj, ApplicationId, val);
+
+ return this->call("hideWindow", j_obj);
+}
+
+/**
+ * Sending reply onscreen message event
+ *
+ * Call HomeScreen Service's replyShowWindow verb to reply onscreen message.
+ *
+ * #### Parameters
+ * - application_id [in] : This argument should be specified to the onscreen reply to applilcation id.
+ * - json [in] : This argument should be specified to the json parameters.
+ *
+ * #### Return
+ * - Returns 0 on success or -1 in case of error.
+ *
+ */
+int LibHomeScreen::replyShowWindow(const char* application_id, json_object* json)
+{
+ if(!sp_websock)
+ {
+ return -1;
+ }
+
+ if (json == nullptr) {
+ HMI_WARNING("libhomescreen", "replyShowWindow`s parameter is null");
+ return -1;
+ }
+
+ struct json_object* j_obj = json_object_new_object();
+ struct json_object* val = json_object_new_string(application_id);
+ json_object_object_add(j_obj, ApplicationId, val);
+ json_object_object_add(j_obj, "parameter", json);
+
+ return this->call("replyShowWindow", j_obj);
+}
+
+/**
+ * Sending show notification event
+ *
+ * Call HomeScreen Service's notification verb to show notification on Status Bar.
+ *
+ * #### 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::showNotification(json_object* json)
+{
+ if(!sp_websock)
+ {
+ return -1;
+ }
+
+ return this->call("showNotification", json);
+}
+
+/**
+ * Sending show information event
+ *
+ * Call HomeScreen Service's information verb to show notification on Information Bar.
+ *
+ * #### 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::showInformation(json_object* json)
+{
+ if(!sp_websock)
+ {
+ return -1;
+ }
+
+ return this->call("showInformation", json);
+}
+
+
/************* Callback Function *************/
void LibHomeScreen::on_hangup(void *closure, struct afb_wsj1 *wsj)
@@ -482,7 +642,7 @@ void LibHomeScreen::on_event(void *closure, const char *event, struct afb_wsj1_m
}
if (strcasecmp(event_type, LibHomeScreen::event_list[0].c_str()) == 0) {
- auto i = this->handlers.find(Event_TapShortcut);
+ auto i = this->handlers.find(Event_ShowWindow);
if ( i != this->handlers.end() ) {
i->second(json_data);
}
@@ -499,6 +659,30 @@ void LibHomeScreen::on_event(void *closure, const char *event, struct afb_wsj1_m
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);
+ }
+ }
}
/**