Add agl-service-homescreen-2017
[apps/agl-service-homescreen.git] / doc / ApplicationGuide.md
diff --git a/doc/ApplicationGuide.md b/doc/ApplicationGuide.md
new file mode 100644 (file)
index 0000000..85216df
--- /dev/null
@@ -0,0 +1,248 @@
+**HomeScreen GUI Application / HomeScreen Service Guide**\r
+====\r
+<div align="right">Revision: 0.1</div>\r
+<div align="right">TOYOTA MOTOR CORPORATION</div>\r
+<div align="right">Advanced Driver Information Technology</div>\r
+<div align="right">26th/Sep/2017</div>\r
+\r
+* * *\r
+\r
+## **<div id="Table\ of\ content">Table of content</div>**\r
+- [Target reader of this document](#Target\ reader\ of\ this\ document)\r
+- [Overview](#Overview)\r
+- [Getting Start](#Getting\ Start)\r
+       - [Supported environment](#Supported\ environment)\r
+       - [Build](#Build)\r
+       - [Configuring](#Configuring)\r
+       - [How to call HomeScreen APIs from your Application?](#How\ to\ call\ HomeScreen\ APIs\ from\ your\ Application?)\r
+- [Supported usecase](#Supported\ usecase)\r
+- [Software Architecture](#Software\ Architecture)\r
+- [API reference](#API\ reference)\r
+- [Sequence](#Sequence)\r
+       - [Initialize](#InitializeSequence)\r
+       - [Tap Shortcut](#TapShortcutSequence)\r
+       - [On Screen Message](#OnScreenMessageSequence)\r
+- [Sample code](#Sample\ code)\r
+- [Limitation](#Limitation)\r
+- [Next Plan](#Next\ Plan)\r
+\r
+* * *\r
+\r
+## **<div id="Target\ reader\ of\ this\ document">Target reader of this document</div>**\r
+Application developer whose software uses HomeScreen.\r
+\r
+* * *\r
+\r
+## **<div id="Overview">Overview</div>**\r
+HomeScreenはQtで作成されたGUIアプリケーション(以下、HomeScreenGUI)と、afb-daemonで動作するサービス(以下HomeScreenBinder)で構築されます。HomeScreeはAGLにて動作するアプリケーションの起動、切り替え、およびオンスクリーンメッセージなどの情報表示を行います。\r
+\r
+HomeScreenGUIはWindowManagerが提供するAPIを使用しています。\r
+\r
+## **<div id="Getting\ Start">Getting Start</div>**\r
+\r
+### **<div id="Supported\ environment">Supported environment</div>**\r
+| Item        | Description                       |\r
+|:------------|:----------------------------------|\r
+| AGL version | Daring Dab                        |\r
+| Hardware    | Renesas R-Car Starter Kit Pro(M3) |\r
+\r
+\r
+### **<div id="Build">Build</div>**\r
+\r
+You can make HomeScreen object files by the following two stage operations.\r
+\r
+**Download recipe**\r
+\r
+If repo is already done, please start with git clone\r
+\r
+```\r
+$ mkdir WORK\r
+$ cd WORK\r
+$ repo init -b dab -m dab_4.0.0_xml -u https://gerrit.automotivelinux.org/gerrit/AGL/AGL-repo\r
+$ repo sync\r
+$ git clone git clone https://gerrit.automotivelinux.org/gerrit/staging/meta-hmi-framework\r
+\r
+```\r
+\r
+Then you can get the following recipe.\r
+\r
+* `meta-hmi-framework/homescreen-2017`\r
+\r
+\r
+**Bitbake**\r
+\r
+```\r
+$ source meta-agl/scripts/aglsetup.sh -m m3ulcb agl-demo agl-devel agl-appfw-smack\r
+$ bitbake homescreen-2017\r
+```\r
+\r
+\r
+* * *\r
+\r
+### **<div id="Configuring">Configuring</div>**\r
+To use HomeScreen API, an application shall paste the following configuration definition into "config.xml" of application.\r
+\r
+```\r
+<feature name="urn:AGL:widget:required-api">\r
+       <param name="homescreen" value="ws" />\r
+</feature>\r
+```\r
+\r
+*) HomeScreenBindingはWindowManagerと同じport、tokenでのアクセスとなります。\r
+\r
+* * *\r
+\r
+### **<div id="How\ to\ call\ HomeScreen\ APIs\ from\ your\ Application?">How to call HomeScreen APIs from your Application?</div>**\r
+HomeScreen provides a library which is called "libhomescreen".  \r
+This library treats "json format" as API calling.  \r
+For example, if an application wants to call "tap_shortcut()" API, the you should implement as below.  \r
+\r
+At first the application should create the instance of libhomescreen.\r
+\r
+```\r
+LibHomeScreen* libhs;\r
+libhs = new LibHomeScreen();\r
+libhs->init(port, token);\r
+```\r
+\r
+The port and token is provided by Application Framework\r
+\r
+Then assign the argument to JSON object\r
+\r
+```\r
+struct json_object* jobj = json_object_new_object();\r
+\r
+json_object_object_add(jobj, "application_name", json_object_new_string("MediaPlayer"));\r
+\r
+```\r
+\r
+\r
+And finally execute the "cal()" function.\r
+\r
+```\r
+libhs->call("tap_shortcut", jobj);\r
+```\r
+\r
+Regarding the detail of tap_shortcut() API, please refer [this](#HomeScreen\ API) section.  \r
+The first parameter is the name of API, so in this case "tap_shortcut" is proper string.  \r
+And the second parameter corresponds to arguments of "connect()" API.  \r
+\r
+\r
+See also our [Sample code](#Sample\ code).\r
+\r
+\r
+<br />\r
+\r
+* * *\r
+\r
+## **<div id="Supported\ usecase">Supported usecase</div>**\r
+1. HomeScreenGUIでショートカットアイコンがタップされたときに発行されるイベントを取得する\r
+       - 各アプリケーションは自身がアイコンタップにより起動(または表示)されたことを知るために、HomeScreenBinderに対してイベント登録を行い、そのイベントを取得することができます。\r
+2. オンスクリーンにメッセージを表示する\r
+       - T.B.D\r
+\r
+* * *\r
+\r
+## **<div id="Software\ Architecture">Software Architecture</div>**\r
+The architecture of HomeScreen is shown below.  \r
+HomeScreen is the service designed to be used by multiple applications.  \r
+Therefore HomeScreen framework consists on two binder layers. Please refer the following figure.  \r
+The upper binder is for application side security context for applications. The lower binder is for servide side security context.  \r
+Usually application side binder has some business logic for each application, so the number of binders depend on the number of applications which use HomeScreen.  \r
+On the other hand, regarding lower binder there is only one module in the system. This binder receives all messages from multiple applications (in detail, it comes from upper layer binder).\r
+\r
+The communication protocols between libhomescreen and upper binder, upper binder and lower binder, lower binder (homescreen-binding) are WebSocket.\r
+\r
+![software-stack.png](parts/software-stack.png)\r
+\r
+* * *\r
+\r
+## **<div id="API%20reference">API reference</div>**\r
+"libhomescreen" and "HomeScreenBinding" provides several kinds of APIs.\r
+\r
+### **<div id="Home\ Screen\ Specific\ API">HomeScreen Specific API</div>**\r
+\r
+- [LibHomeScreen ()](api-ref/html/de/dd0/class_lib_home_screen.html#a724bd949c4154fad041f96a15ef0f5dc)\r
+- [init (const int port, const std::string &token)](api-ref/html/de/dd0/class_lib_home_screen.html#a6a57b573cc767725762ba9beab032220)\r
+- [tapShortcut(const char *application_name)](api-ref/html/de/dd0/class_lib_home_screen.html#afb571c9577087b47065eb23e7fdbc903)\r
+- [onScreenMessage(const char *display_message)](api-ref/html/de/dd0/class_lib_home_screen.html#ac336482036a72b51a822725f1929523c)\r
+- [set\_event\_handler(enum EventType et, handler_func f)](api-ref/html/de/dd0/class_lib_home_screen.html#ab1b0e08bf35415de9064afed899e9f85)\r
+- [call (const string& verb, struct json_object* arg)](api-ref/html/de/dd0/class_lib_home_screen.html#a527b49dcfe581be6275d0eb2236ba37f)\r
+- [call (const char* verb, struct json_object* arg)](api-ref/html/de/dd0/class_lib_home_screen.html#ab5e8e8ab7d53e0f114e9e907fcbb7643)\r
+- [subscribe (const string& event_name)](api-ref/html/de/dd0/class_lib_home_screen.html#aa4c189807b75d070f567967f0d690738)\r
+- [unsubscribe (const string& event_name)](api-ref/html/de/dd0/class_lib_home_screen.html#aac03a45cbd453ba69ddb00c1016930a6)\r
+\r
+* * *\r
+\r
+## **<div id="Sequence">Sequence</div>**\r
+\r
+### **<div id="InitializeSequence">Initialize</div>**\r
+![initialize.svg](parts/initialize.svg)\r
+\r
+### **<div id="TapShortcutSequence">Tap Shortcut</div>**\r
+![tap_shortcut.svg](parts/tap_shortcut.svg)\r
+\r
+### **<div id="OnScreenMessageSequence">On Screen Message</div>**\r
+![on_screen_message.svg](parts/on_screen_message.svg)\r
+\r
+\r
+# **<div id="Sample\ code">Sample code</div>**\r
+You can find sample implementation of HomeScreen as below.\r
+\r
+* `HomeScreenBinding/libhomescreen/test.cpp`\r
+\r
+### Appendix\r
+\r
+```\r
+@startuml\r
+title Application initialization phase\r
+entity App\r
+entity HomeScreenBinder\r
+entity HomeScreenGUI\r
+App->HomeScreenBinder: init(port, token)\r
+App->HomeScreenBinder: subscribe()\r
+\r
+note over HomeScreenBinder\r
+    Appが受信したいイベントを登録する\r
+    ・tap_shortcut\r
+end note\r
+\r
+App->HomeScreenBinder: registerCallback()\r
+App->HomeScreenBinder: set_event_handler()\r
+\r
+note over HomeScreenBinder\r
+    イベント受信のコールバック登録\r
+    registerCallbackによる登録または\r
+    set_event_handlerによる登録どちらかでOK\r
+end note\r
+\r
+@enduml\r
+```\r
+\r
+```\r
+@startuml\r
+title Application Callback Event TapShortcut phase\r
+entity App\r
+entity HomeScreenBinder\r
+entity HomeScreenGUI\r
+note over App\r
+    Appは初期化時に\r
+    TapShortcutのイベントを受け取る設定をしていること\r
+end note\r
+HomeScreenGUI->HomeScreenBinder: tapShortcut(application_name)\r
+HomeScreenBinder->App: eventCallback(application_name)\r
+@enduml\r
+\r
+```\r
+\r
+```\r
+@startuml\r
+title Application Callback Event TapShortcut phase\r
+entity App\r
+entity HomeScreenBinder\r
+entity HomeScreenGUI\r
+App->HomeScreenBinder: onScreenMessage(display_message)\r
+HomeScreenBinder->HomeScreenGUI: eventCallback(display_message)\r
+@enduml\r
+\r
+```
\ No newline at end of file