From eabd10ffe2f9cb5c31262ad3152b037eb2286857 Mon Sep 17 00:00:00 2001 From: zheng_wenlong Date: Mon, 23 Oct 2017 14:46:17 +0900 Subject: Modify function argument from char to json Change libhomescreen event api from char to json. Also modify samples who use this. BUG-AGL: SPEC-992 Change-Id: Id3986d413f9494019f6b175488dd73de226ba020 Signed-off-by: zheng_wenlong --- sample/template/main.cpp | 45 ++++++++++++++++++++++++++++++++----------- sample/template/wmhandler.cpp | 9 ++++++--- 2 files changed, 40 insertions(+), 14 deletions(-) (limited to 'sample/template') diff --git a/sample/template/main.cpp b/sample/template/main.cpp index 589d314..831df41 100644 --- a/sample/template/main.cpp +++ b/sample/template/main.cpp @@ -90,29 +90,47 @@ int main(int argc, char *argv[]) } // Application should call requestSurface at first - if (wm->requestSurface(myname.c_str()) != 0) { + 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) { exit(EXIT_FAILURE); } // Set event handlers for each event - wm->set_event_handler(LibWindowmanager::Event_Active, [](char const *label) { + wm->set_event_handler(LibWindowmanager::Event_Active, [wm](json_object *object) { + const char *label = json_object_get_string( + json_object_object_get(object, wm->kKeyDrawingName)); fprintf(stderr, "Surface %s got activated!\n", label); }); - wm->set_event_handler(LibWindowmanager::Event_Inactive, [](char const *label) { + wm->set_event_handler(LibWindowmanager::Event_Inactive, [wm](json_object *object) { + const char *label = json_object_get_string( + json_object_object_get(object, wm->kKeyDrawingName)); fprintf(stderr, "Surface %s got deactivated!\n", label); }); - wm->set_event_handler(LibWindowmanager::Event_Visible, [](char const *label) { + wm->set_event_handler(LibWindowmanager::Event_Visible, [wm](json_object *object) { + const char *label = json_object_get_string( + json_object_object_get(object, wm->kKeyDrawingName)); fprintf(stderr, "Surface %s got visible!\n", label); }); - wm->set_event_handler(LibWindowmanager::Event_Invisible, [](char const *label) { + wm->set_event_handler(LibWindowmanager::Event_Invisible, [wm](json_object *object) { + const char *label = json_object_get_string( + json_object_object_get(object, wm->kKeyDrawingName)); fprintf(stderr, "Surface %s got invisible!\n", label); }); - wm->set_event_handler(LibWindowmanager::Event_SyncDraw, [wm](char const *label) { - fprintf(stderr, "Surface %s got syncDraw!\n", label); + wm->set_event_handler(LibWindowmanager::Event_SyncDraw, [wm](json_object *object) { + const char *label = json_object_get_string( + 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); // Application should call LibWindowmanager::endDraw() in SyncDraw handler - wm->endDraw(label); + 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->set_event_handler(LibWindowmanager::Event_FlushDraw, [](char const *label) { + wm->set_event_handler(LibWindowmanager::Event_FlushDraw, [wm](json_object *object) { + const char *label = json_object_get_string( + json_object_object_get(object, wm->kKeyDrawingName)); fprintf(stderr, "Surface %s got flushDraw!\n", label); }); @@ -127,11 +145,16 @@ int main(int argc, char *argv[]) hs->init(port, token.c_str()); // Set event handler - hs->set_event_handler(LibHomeScreen::Event_TapShortcut, [wm](const char* appname) { + hs->set_event_handler(LibHomeScreen::Event_TapShortcut, [wm](json_object *object) { + const char *appname = json_object_get_string( + json_object_object_get(object, "application_name")); if(myname == appname) { qDebug("Surface %s got tapShortcut\n", appname); // Application should call LibWindowmanager::endDraw() in TapShortcut handler - wm->activateSurface(myname.c_str()); + json_object *obj = json_object_new_object(); + json_object_object_add(obj, wm->kKeyDrawingName, json_object_new_string(app_name.c_str())); + json_object_object_add(obj, wm->kKeyDrawingArea, json_object_new_string("normal.full")); + wm->activateSurface(obj); } }); diff --git a/sample/template/wmhandler.cpp b/sample/template/wmhandler.cpp index 761915f..9972104 100644 --- a/sample/template/wmhandler.cpp +++ b/sample/template/wmhandler.cpp @@ -18,17 +18,20 @@ #include -void WmHandler::init(LibWindowmanager *p_wm, std::string applabel) +void WmHandler::init(LibWindowmanager *p_wm, std::string applabel) { mp_wm = p_wm; m_applabel = applabel; } void WmHandler::slotActivateSurface() { - mp_wm->activateSurface(m_applabel.c_str()); + json_object *obj = json_object_new_object(); + json_object_object_add(obj, wm->kKeyDrawingName, json_object_new_string(m_applabel.c_str())); + json_object_object_add(obj, wm->kKeyDrawingArea, json_object_new_string("normal.full")); + mp_wm->activateSurface(obj); } -WmHandler::WmHandler(QObject *parent) +WmHandler::WmHandler(QObject *parent) :QObject(parent) { } -- cgit 1.2.3-korg