modify
authorwang_zhiqiang <wang_zhiqiang@dl.cn.nexty-ele.com>
Wed, 10 Apr 2019 09:36:11 +0000 (17:36 +0800)
committerwang_zhiqiang <wang_zhiqiang@dl.cn.nexty-ele.com>
Wed, 10 Apr 2019 09:36:21 +0000 (17:36 +0800)
add wm proxy
add read/write json file
add getRunnables to ApplicationGuide.md

Change-Id: I65e9e6620ecb207c999e590410782590edd7005d

doc/ApplicationGuide.md
doc/parts/getRunnables.svg [new file with mode: 0644]
src/hs-helper.cpp
src/hs-helper.h
src/hs-proxy.cpp
src/hs-proxy.h

index 9c5c409..34b8a14 100644 (file)
@@ -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.
 * * *
 
 <div id="Software\ Architecture"></div>
@@ -275,6 +279,10 @@ The communication protocols between libhomescreen and upper binder, upper binder
 ### ShowInformation Sequence
 ![showInformation.svg](parts/showInformation.svg)
 
+<div id="GetRunnablesSequence"></div>
+
+### GetRunnables Sequence
+![getRunnables.svg](parts/getRunnables.svg)
 
 <div id="Sample\ code"></div>
 
diff --git a/doc/parts/getRunnables.svg b/doc/parts/getRunnables.svg
new file mode 100644 (file)
index 0000000..3b342f8
--- /dev/null
@@ -0,0 +1,45 @@
+<?xml version="1.0" encoding="UTF-8" standalone="no"?><svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" contentScriptType="application/ecmascript" contentStyleType="text/css" height="578px" preserveAspectRatio="none" style="width:591px;height:578px;" version="1.1" viewBox="0 0 591 578" width="591px" zoomAndPan="magnify"><defs><filter height="300%" id="f1l9mb3ztqbpmo" width="300%" x="-1" y="-1"><feGaussianBlur result="blurOut" stdDeviation="2.0"/><feColorMatrix in="blurOut" result="blurOut2" type="matrix" values="0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 .4 0"/><feOffset dx="4.0" dy="4.0" in="blurOut2" result="blurOut3"/><feBlend in="SourceGraphic" in2="blurOut3" mode="normal"/></filter></defs><g><text fill="#000000" font-family="sans-serif" font-size="14" font-weight="bold" lengthAdjust="spacingAndGlyphs" textLength="206" x="193.5" y="24.5332">got runnables list in launcher</text><rect fill="#FFFFFF" filter="url(#f1l9mb3ztqbpmo)" height="201.1094" style="stroke: #A80036; stroke-width: 1.0;" width="10" x="137" y="293.625"/><rect fill="#FFFFFF" filter="url(#f1l9mb3ztqbpmo)" height="140.0547" style="stroke: #A80036; stroke-width: 1.0;" width="10" x="394" y="116.2188"/><rect fill="#FFFFFF" filter="url(#f1l9mb3ztqbpmo)" height="91.0547" style="stroke: #A80036; stroke-width: 1.0;" width="10" x="394" y="367.3281"/><rect fill="#FFFFFF" filter="url(#f1l9mb3ztqbpmo)" height="30" style="stroke: #A80036; stroke-width: 1.0;" width="10" x="548" y="189.9219"/><line style="stroke: #A80036; stroke-width: 1.0; stroke-dasharray: 5.0,5.0;" x1="37" x2="37" y1="84.2188" y2="520.0859"/><line style="stroke: #A80036; stroke-width: 1.0; stroke-dasharray: 5.0,5.0;" x1="141.5" x2="141.5" y1="84.2188" y2="520.0859"/><line style="stroke: #A80036; stroke-width: 1.0; stroke-dasharray: 5.0,5.0;" x1="399" x2="399" y1="84.2188" y2="520.0859"/><line style="stroke: #A80036; stroke-width: 1.0; stroke-dasharray: 5.0,5.0;" x1="553" x2="553" y1="84.2188" y2="520.0859"/><text fill="#000000" font-family="sans-serif" font-size="14" lengthAdjust="spacingAndGlyphs" textLength="52" x="8" y="81.1426">systemd</text><ellipse cx="37" cy="50.6094" fill="#FEFECE" filter="url(#f1l9mb3ztqbpmo)" rx="12" ry="12" style="stroke: #A80036; stroke-width: 2.0;"/><line style="stroke: #A80036; stroke-width: 2.0;" x1="25" x2="49" y1="64.6094" y2="64.6094"/><text fill="#000000" font-family="sans-serif" font-size="14" lengthAdjust="spacingAndGlyphs" textLength="52" x="8" y="533.6191">systemd</text><ellipse cx="37" cy="552.6953" fill="#FEFECE" filter="url(#f1l9mb3ztqbpmo)" rx="12" ry="12" style="stroke: #A80036; stroke-width: 2.0;"/><line style="stroke: #A80036; stroke-width: 2.0;" x1="25" x2="49" y1="566.6953" y2="566.6953"/><text fill="#000000" font-family="sans-serif" font-size="14" lengthAdjust="spacingAndGlyphs" textLength="55" x="111.5" y="81.1426">launcher</text><ellipse cx="142" cy="50.6094" fill="#FEFECE" filter="url(#f1l9mb3ztqbpmo)" rx="12" ry="12" style="stroke: #A80036; stroke-width: 2.0;"/><line style="stroke: #A80036; stroke-width: 2.0;" x1="130" x2="154" y1="64.6094" y2="64.6094"/><text fill="#000000" font-family="sans-serif" font-size="14" lengthAdjust="spacingAndGlyphs" textLength="55" x="111.5" y="533.6191">launcher</text><ellipse cx="142" cy="552.6953" fill="#FEFECE" filter="url(#f1l9mb3ztqbpmo)" rx="12" ry="12" style="stroke: #A80036; stroke-width: 2.0;"/><line style="stroke: #A80036; stroke-width: 2.0;" x1="130" x2="154" y1="566.6953" y2="566.6953"/><text fill="#000000" font-family="sans-serif" font-size="14" lengthAdjust="spacingAndGlyphs" textLength="128" x="332" y="81.1426">homescreen-service</text><ellipse cx="399" cy="50.6094" fill="#FEFECE" filter="url(#f1l9mb3ztqbpmo)" rx="12" ry="12" style="stroke: #A80036; stroke-width: 2.0;"/><line style="stroke: #A80036; stroke-width: 2.0;" x1="387" x2="411" y1="64.6094" y2="64.6094"/><text fill="#000000" font-family="sans-serif" font-size="14" lengthAdjust="spacingAndGlyphs" textLength="128" x="332" y="533.6191">homescreen-service</text><ellipse cx="399" cy="552.6953" fill="#FEFECE" filter="url(#f1l9mb3ztqbpmo)" rx="12" ry="12" style="stroke: #A80036; stroke-width: 2.0;"/><line style="stroke: #A80036; stroke-width: 2.0;" x1="387" x2="411" y1="566.6953" y2="566.6953"/><text fill="#000000" font-family="sans-serif" font-size="14" lengthAdjust="spacingAndGlyphs" textLength="58" x="521" y="81.1426">afm-main</text><ellipse cx="553" cy="50.6094" fill="#FEFECE" filter="url(#f1l9mb3ztqbpmo)" rx="12" ry="12" style="stroke: #A80036; stroke-width: 2.0;"/><line style="stroke: #A80036; stroke-width: 2.0;" x1="541" x2="565" y1="64.6094" y2="64.6094"/><text fill="#000000" font-family="sans-serif" font-size="14" lengthAdjust="spacingAndGlyphs" textLength="58" x="521" y="533.6191">afm-main</text><ellipse cx="553" cy="552.6953" fill="#FEFECE" filter="url(#f1l9mb3ztqbpmo)" rx="12" ry="12" style="stroke: #A80036; stroke-width: 2.0;"/><line style="stroke: #A80036; stroke-width: 2.0;" x1="541" x2="565" y1="566.6953" y2="566.6953"/><rect fill="#FFFFFF" filter="url(#f1l9mb3ztqbpmo)" height="201.1094" style="stroke: #A80036; stroke-width: 1.0;" width="10" x="137" y="293.625"/><rect fill="#FFFFFF" filter="url(#f1l9mb3ztqbpmo)" height="140.0547" style="stroke: #A80036; stroke-width: 1.0;" width="10" x="394" y="116.2188"/><rect fill="#FFFFFF" filter="url(#f1l9mb3ztqbpmo)" height="91.0547" style="stroke: #A80036; stroke-width: 1.0;" width="10" x="394" y="367.3281"/><rect fill="#FFFFFF" filter="url(#f1l9mb3ztqbpmo)" height="30" style="stroke: #A80036; stroke-width: 1.0;" width="10" x="548" y="189.9219"/><polygon fill="#A80036" points="382,112.2188,392,116.2188,382,120.2188,386,116.2188" style="stroke: #A80036; stroke-width: 1.0;"/><line style="stroke: #A80036; stroke-width: 1.0; stroke-dasharray: 2.0,2.0;" x1="37" x2="388" y1="116.2188" y2="116.2188"/><text fill="#000000" font-family="sans-serif" font-size="13" lengthAdjust="spacingAndGlyphs" textLength="147" x="44" y="111.7139">exec homescreen-service</text><line style="stroke: #A80036; stroke-width: 1.0;" x1="404" x2="446" y1="146.9219" y2="146.9219"/><line style="stroke: #A80036; stroke-width: 1.0;" x1="446" x2="446" y1="146.9219" y2="159.9219"/><line style="stroke: #A80036; stroke-width: 1.0;" x1="405" x2="446" y1="159.9219" y2="159.9219"/><polygon fill="#A80036" points="415,155.9219,405,159.9219,415,163.9219,411,159.9219" style="stroke: #A80036; stroke-width: 1.0;"/><text fill="#000000" font-family="sans-serif" font-size="13" lengthAdjust="spacingAndGlyphs" textLength="25" x="411" y="142.0654">init()</text><polygon fill="#A80036" points="536,185.9219,546,189.9219,536,193.9219,540,189.9219" style="stroke: #A80036; stroke-width: 1.0;"/><line style="stroke: #A80036; stroke-width: 1.0;" x1="404" x2="542" y1="189.9219" y2="189.9219"/><text fill="#000000" font-family="sans-serif" font-size="13" lengthAdjust="spacingAndGlyphs" textLength="99" x="411" y="185.417">got runnables list</text><line style="stroke: #A80036; stroke-width: 1.0;" x1="404" x2="446" y1="255.625" y2="255.625"/><line style="stroke: #A80036; stroke-width: 1.0;" x1="446" x2="446" y1="255.625" y2="268.625"/><line style="stroke: #A80036; stroke-width: 1.0;" x1="399" x2="446" y1="268.625" y2="268.625"/><polygon fill="#A80036" points="409,264.625,399,268.625,409,272.625,405,268.625" style="stroke: #A80036; stroke-width: 1.0;"/><text fill="#000000" font-family="sans-serif" font-size="13" lengthAdjust="spacingAndGlyphs" textLength="130" x="411" y="250.7686">maintain runnables list</text><polygon fill="#A80036" points="125,289.625,135,293.625,125,297.625,129,293.625" style="stroke: #A80036; stroke-width: 1.0;"/><line style="stroke: #A80036; stroke-width: 1.0; stroke-dasharray: 2.0,2.0;" x1="37" x2="131" y1="293.625" y2="293.625"/><text fill="#000000" font-family="sans-serif" font-size="13" lengthAdjust="spacingAndGlyphs" textLength="81" x="44" y="289.1201">exec launcher</text><line style="stroke: #A80036; stroke-width: 1.0;" x1="147" x2="189" y1="324.3281" y2="324.3281"/><line style="stroke: #A80036; stroke-width: 1.0;" x1="189" x2="189" y1="324.3281" y2="337.3281"/><line style="stroke: #A80036; stroke-width: 1.0;" x1="148" x2="189" y1="337.3281" y2="337.3281"/><polygon fill="#A80036" points="158,333.3281,148,337.3281,158,341.3281,154,337.3281" style="stroke: #A80036; stroke-width: 1.0;"/><text fill="#000000" font-family="sans-serif" font-size="13" lengthAdjust="spacingAndGlyphs" textLength="17" x="154" y="319.4717">init</text><polygon fill="#A80036" points="382,363.3281,392,367.3281,382,371.3281,386,367.3281" style="stroke: #A80036; stroke-width: 1.0;"/><line style="stroke: #A80036; stroke-width: 1.0; stroke-dasharray: 2.0,2.0;" x1="147" x2="388" y1="367.3281" y2="367.3281"/><text fill="#000000" font-family="sans-serif" font-size="13" lengthAdjust="spacingAndGlyphs" textLength="198" x="154" y="362.8232">set_event_handler("showWindow")</text><polygon fill="#A80036" points="382,393.6797,392,397.6797,382,401.6797,386,397.6797" style="stroke: #A80036; stroke-width: 1.0;"/><line style="stroke: #A80036; stroke-width: 1.0; stroke-dasharray: 2.0,2.0;" x1="147" x2="388" y1="397.6797" y2="397.6797"/><text fill="#000000" font-family="sans-serif" font-size="13" lengthAdjust="spacingAndGlyphs" textLength="223" x="154" y="393.1748">set_event_handler("app_list_changed")</text><polygon fill="#A80036" points="382,424.0313,392,428.0313,382,432.0313,386,428.0313" style="stroke: #A80036; stroke-width: 1.0;"/><line style="stroke: #A80036; stroke-width: 1.0; stroke-dasharray: 2.0,2.0;" x1="147" x2="388" y1="428.0313" y2="428.0313"/><text fill="#000000" font-family="sans-serif" font-size="13" lengthAdjust="spacingAndGlyphs" textLength="99" x="154" y="423.5264">got runnables list</text><polygon fill="#A80036" points="158,454.3828,148,458.3828,158,462.3828,154,458.3828" style="stroke: #A80036; stroke-width: 1.0;"/><line style="stroke: #A80036; stroke-width: 1.0; stroke-dasharray: 2.0,2.0;" x1="152" x2="398" y1="458.3828" y2="458.3828"/><text fill="#000000" font-family="sans-serif" font-size="13" lengthAdjust="spacingAndGlyphs" textLength="145" x="164" y="453.8779">set runnables list in reply</text><line style="stroke: #A80036; stroke-width: 1.0;" x1="147" x2="189" y1="494.0859" y2="494.0859"/><line style="stroke: #A80036; stroke-width: 1.0;" x1="189" x2="189" y1="494.0859" y2="507.0859"/><line style="stroke: #A80036; stroke-width: 1.0;" x1="142" x2="189" y1="507.0859" y2="507.0859"/><polygon fill="#A80036" points="152,503.0859,142,507.0859,152,511.0859,148,507.0859" style="stroke: #A80036; stroke-width: 1.0;"/><text fill="#000000" font-family="sans-serif" font-size="13" lengthAdjust="spacingAndGlyphs" textLength="144" x="154" y="489.2295">update application model</text><!--
+@startuml\r
+\r
+title got runnables list in launcher\r
+\r
+entity systemd\r
+entity launcher\r
+entity "homescreen-service" as hss\r
+entity "afm-main" as afm\r
+\r
+\r
+systemd- ->hss: exec homescreen-service\r
+activate hss\r
+hss->hss: init()\r
+hss->afm: got runnables list\r
+activate afm\r
+deactivate afm\r
+hss->hss: maintain runnables list\r
+deactivate hss\r
+\r
+systemd- ->launcher: exec launcher\r
+activate launcher\r
+launcher->launcher: init\r
+launcher- ->hss: set_event_handler("showWindow")\r
+activate hss\r
+launcher- ->hss: set_event_handler("app_list_changed")\r
+launcher- ->hss: got runnables list\r
+hss- ->launcher: set runnables list in reply\r
+deactivate hss\r
+launcher->launcher: update application model\r
+deactivate launcher\r
+\r
+@enduml\r
+
+PlantUML version 1.2018.01(Mon Jan 29 02:08:22 CST 2018)
+(GPL source distribution)
+Java Runtime: Java(TM) SE Runtime Environment
+JVM: Java HotSpot(TM) 64-Bit Server VM
+Java Version: 1.8.0_201-b09
+Operating System: Windows 7
+OS Version: 6.1
+Default Encoding: MS932
+Language: ja
+Country: JP
+--></g></svg>
\ No newline at end of file
index 50a3ae1..159668e 100644 (file)
@@ -17,6 +17,7 @@
 #include <string.h>
 #include <cstdarg>
 #include "hs-helper.h"
+#include <unistd.h>
 
 
 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;
+}
index f57799d..55f9386 100644 (file)
@@ -17,7 +17,7 @@
 #ifndef HOMESCREEN_HELPER_H
 #define HOMESCREEN_HELPER_H
 #define AFB_BINDING_VERSION 3
-#include <afb/afb-binding.h>
+#include <afb/afb-binding>
 #include <json-c/json.h>
 #include <string>
 
@@ -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);
index f0ee5f0..967c1b1 100644 (file)
@@ -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);
+}
index 8741e49..b6283d6 100644 (file)
@@ -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