From 134be0531d2aa3926bb6ed441c7839174a8bba17 Mon Sep 17 00:00:00 2001 From: wang_zhiqiang Date: Wed, 10 Apr 2019 17:36:11 +0800 Subject: [PATCH] modify add wm proxy add read/write json file add getRunnables to ApplicationGuide.md Change-Id: I65e9e6620ecb207c999e590410782590edd7005d --- doc/ApplicationGuide.md | 8 ++++++++ doc/parts/getRunnables.svg | 45 ++++++++++++++++++++++++++++++++++++++++++ src/hs-helper.cpp | 49 ++++++++++++++++++++++++++++++++++++++++++++++ src/hs-helper.h | 4 +++- src/hs-proxy.cpp | 29 ++++++++++++++++++++++++--- src/hs-proxy.h | 28 ++++++++++++++++++++++++++ 6 files changed, 159 insertions(+), 4 deletions(-) create mode 100644 doc/parts/getRunnables.svg diff --git a/doc/ApplicationGuide.md b/doc/ApplicationGuide.md index 9c5c409..34b8a14 100644 --- a/doc/ApplicationGuide.md +++ b/doc/ApplicationGuide.md @@ -28,6 +28,7 @@ - [ShowOnscreen](###ShowOnscreen\ Sequence) - [ShowNotification](###ShowNotification\ Sequence) - [ShowInformation](###ShowInformation\ Sequence) + - [GetRunnables](###GetRunnables\ Sequence) - [Sample code](#Sample\ code) - [Limitation](#Limitation) - [Next Plan](#Next\ Plan) @@ -189,6 +190,9 @@ See also our [Sample code](#Sample\ code). 8. Show Information on HomeScreenGUI - When application who want to display a information,it can call "showInformation",then HomeScreenGUI will display the information contents on the screen bottom area. +9. Get runnables list + - When launcher starting, it want to get runnalbes list,it can call "getRunnables",then launcher will + receive the runnalbes list in reply. * * *
@@ -275,6 +279,10 @@ The communication protocols between libhomescreen and upper binder, upper binder ### ShowInformation Sequence ![showInformation.svg](parts/showInformation.svg) +
+ +### GetRunnables Sequence +![getRunnables.svg](parts/getRunnables.svg)
diff --git a/doc/parts/getRunnables.svg b/doc/parts/getRunnables.svg new file mode 100644 index 0000000..3b342f8 --- /dev/null +++ b/doc/parts/getRunnables.svg @@ -0,0 +1,45 @@ +got runnables list in launchersystemdsystemdlauncherlauncherhomescreen-servicehomescreen-serviceafm-mainafm-mainexec homescreen-serviceinit()got runnables listmaintain runnables listexec launcherinitset_event_handler("showWindow")set_event_handler("app_list_changed")got runnables listset runnables list in replyupdate application model \ No newline at end of file diff --git a/src/hs-helper.cpp b/src/hs-helper.cpp index 50a3ae1..159668e 100644 --- a/src/hs-helper.cpp +++ b/src/hs-helper.cpp @@ -17,6 +17,7 @@ #include #include #include "hs-helper.h" +#include const char* evlist[] = { @@ -272,3 +273,51 @@ std::string get_application_id(const afb_req_t request) return appid; } + +/** + * read json file + * + * #### Parameters + * - file : file name + * - obj : json_object + * + * #### Return + * 0 : read success + * 1 : read fail + * + */ +int readJsonFile(const char* file, struct json_object **obj) +{ + *obj = nullptr; + int ret = -1; + FILE *fp = fopen(file, "rb"); + if(fp == nullptr) { + AFB_ERROR("open %s failed", file); + return ret; + } + + const int buf_size = 128; + char buf[buf_size]; + struct json_tokener *tokener = json_tokener_new(); + enum json_tokener_error json_error; + while(1) { + size_t len = fread(buf, sizeof(char), buf_size, fp); + *obj = json_tokener_parse_ex(tokener, buf, len); + if(nullptr != *obj) { + AFB_NOTICE("read %s success", file); + ret = 0; + break; + } + + json_error = json_tokener_get_error(tokener); + if ((json_tokener_continue != json_error) || (buf_size > len)) { + AFB_ERROR("parse %s error", file); + *obj = nullptr; + break; + } + } + + fclose(fp); + json_tokener_free(tokener); + return ret; +} diff --git a/src/hs-helper.h b/src/hs-helper.h index f57799d..55f9386 100644 --- a/src/hs-helper.h +++ b/src/hs-helper.h @@ -17,7 +17,7 @@ #ifndef HOMESCREEN_HELPER_H #define HOMESCREEN_HELPER_H #define AFB_BINDING_VERSION 3 -#include +#include #include #include @@ -53,6 +53,8 @@ void hs_add_object_to_json_object_str(struct json_object* j_obj, int count, ...) void hs_add_object_to_json_object_func(struct json_object* j_obj, const char* verb_name, int count, ...); int hs_search_event_name_index(const char* value); std::string get_application_id(const afb_req_t request); +int readJsonFile(const char* file, struct json_object **obj); +int writeJsonFile(const char* file, struct json_object *obj); typedef int (*event_hook_func)(afb_api_t api, const char *event, struct json_object *object); void setEventHook(const char *event, const event_hook_func f); diff --git a/src/hs-proxy.cpp b/src/hs-proxy.cpp index f0ee5f0..967c1b1 100644 --- a/src/hs-proxy.cpp +++ b/src/hs-proxy.cpp @@ -16,8 +16,9 @@ #include "hs-proxy.h" -const char _afm_main[] = "afm-main"; - +static const char _afm_main[] = "afm-main"; +static const char _windowmanager[] = "windowmanager"; +static const char _event[] = "event"; /** * the callback function @@ -80,6 +81,8 @@ static int api_call_sync(afb_api_t api, const char *service, const char *verb, s return ret; } +/* -------------------------------------HS_AfmMainProxy------------------------------------------ */ + /** * get runnables application list * @@ -131,4 +134,24 @@ void HS_AfmMainProxy::start(afb_req_t request, const std::string &id) { struct json_object *args = json_object_new_string(id.c_str()); api_call(request->api, _afm_main, __FUNCTION__, args); -} \ No newline at end of file +} + +/* -------------------------------------HS_WmProxy------------------------------------------ */ + +/** + * subscribe windowmanager event + * + * #### Parameters + * - api : the api serving the request + * - event : windowmanager event + * + * #### Return + * None + * + */ +void HS_WmProxy::subscribe(afb_api_t api, EventType event) +{ + struct json_object* push_obj = json_object_new_object(); + json_object_object_add(push_obj, _event, json_object_new_int(event)); + api_call(api, _windowmanager, "wm_subscribe", push_obj); +} diff --git a/src/hs-proxy.h b/src/hs-proxy.h index 8741e49..b6283d6 100644 --- a/src/hs-proxy.h +++ b/src/hs-proxy.h @@ -31,4 +31,32 @@ struct HS_AfmMainProxy { void start(afb_req_t request, const std::string &id); }; +class HS_WmProxy { +public: + HS_WmProxy() = default; + ~HS_WmProxy() = default; + + enum EventType + { + Event_Val_Min = 0, + + Event_Active = Event_Val_Min, + Event_Inactive, + + Event_Visible, + Event_Invisible, + + Event_SyncDraw, + Event_FlushDraw, + + Event_ScreenUpdated, + + Event_Error, + + Event_Val_Max = Event_Error, + }; + + // asynchronous call, reply in callback function + void subscribe(afb_api_t api, EventType event); +}; #endif // HOMESCREEN_PROXY_H \ No newline at end of file -- 2.16.6