85216dfae356a734dd15210ce8409ba90ccf97c0
[apps/agl-service-homescreen.git] / doc / ApplicationGuide.md
1 **HomeScreen GUI Application / HomeScreen Service Guide**\r
2 ====\r
3 <div align="right">Revision: 0.1</div>\r
4 <div align="right">TOYOTA MOTOR CORPORATION</div>\r
5 <div align="right">Advanced Driver Information Technology</div>\r
6 <div align="right">26th/Sep/2017</div>\r
7 \r
8 * * *\r
9 \r
10 ## **<div id="Table\ of\ content">Table of content</div>**\r
11 - [Target reader of this document](#Target\ reader\ of\ this\ document)\r
12 - [Overview](#Overview)\r
13 - [Getting Start](#Getting\ Start)\r
14         - [Supported environment](#Supported\ environment)\r
15         - [Build](#Build)\r
16         - [Configuring](#Configuring)\r
17         - [How to call HomeScreen APIs from your Application?](#How\ to\ call\ HomeScreen\ APIs\ from\ your\ Application?)\r
18 - [Supported usecase](#Supported\ usecase)\r
19 - [Software Architecture](#Software\ Architecture)\r
20 - [API reference](#API\ reference)\r
21 - [Sequence](#Sequence)\r
22         - [Initialize](#InitializeSequence)\r
23         - [Tap Shortcut](#TapShortcutSequence)\r
24         - [On Screen Message](#OnScreenMessageSequence)\r
25 - [Sample code](#Sample\ code)\r
26 - [Limitation](#Limitation)\r
27 - [Next Plan](#Next\ Plan)\r
28 \r
29 * * *\r
30 \r
31 ## **<div id="Target\ reader\ of\ this\ document">Target reader of this document</div>**\r
32 Application developer whose software uses HomeScreen.\r
33 \r
34 * * *\r
35 \r
36 ## **<div id="Overview">Overview</div>**\r
37 HomeScreenはQtで作成されたGUIアプリケーション(以下、HomeScreenGUI)と、afb-daemonで動作するサービス(以下HomeScreenBinder)で構築されます。HomeScreeはAGLにて動作するアプリケーションの起動、切り替え、およびオンスクリーンメッセージなどの情報表示を行います。\r
38 \r
39 HomeScreenGUIはWindowManagerが提供するAPIを使用しています。\r
40 \r
41 ## **<div id="Getting\ Start">Getting Start</div>**\r
42 \r
43 ### **<div id="Supported\ environment">Supported environment</div>**\r
44 | Item        | Description                       |\r
45 |:------------|:----------------------------------|\r
46 | AGL version | Daring Dab                        |\r
47 | Hardware    | Renesas R-Car Starter Kit Pro(M3) |\r
48 \r
49 \r
50 ### **<div id="Build">Build</div>**\r
51 \r
52 You can make HomeScreen object files by the following two stage operations.\r
53 \r
54 **Download recipe**\r
55 \r
56 If repo is already done, please start with git clone\r
57 \r
58 ```\r
59 $ mkdir WORK\r
60 $ cd WORK\r
61 $ repo init -b dab -m dab_4.0.0_xml -u https://gerrit.automotivelinux.org/gerrit/AGL/AGL-repo\r
62 $ repo sync\r
63 $ git clone git clone https://gerrit.automotivelinux.org/gerrit/staging/meta-hmi-framework\r
64 \r
65 ```\r
66 \r
67 Then you can get the following recipe.\r
68 \r
69 * `meta-hmi-framework/homescreen-2017`\r
70 \r
71 \r
72 **Bitbake**\r
73 \r
74 ```\r
75 $ source meta-agl/scripts/aglsetup.sh -m m3ulcb agl-demo agl-devel agl-appfw-smack\r
76 $ bitbake homescreen-2017\r
77 ```\r
78 \r
79 \r
80 * * *\r
81 \r
82 ### **<div id="Configuring">Configuring</div>**\r
83 To use HomeScreen API, an application shall paste the following configuration definition into "config.xml" of application.\r
84 \r
85 ```\r
86 <feature name="urn:AGL:widget:required-api">\r
87         <param name="homescreen" value="ws" />\r
88 </feature>\r
89 ```\r
90 \r
91 *) HomeScreenBindingはWindowManagerと同じport、tokenでのアクセスとなります。\r
92 \r
93 * * *\r
94 \r
95 ### **<div id="How\ to\ call\ HomeScreen\ APIs\ from\ your\ Application?">How to call HomeScreen APIs from your Application?</div>**\r
96 HomeScreen provides a library which is called "libhomescreen".  \r
97 This library treats "json format" as API calling.  \r
98 For example, if an application wants to call "tap_shortcut()" API, the you should implement as below.  \r
99 \r
100 At first the application should create the instance of libhomescreen.\r
101 \r
102 ```\r
103 LibHomeScreen* libhs;\r
104 libhs = new LibHomeScreen();\r
105 libhs->init(port, token);\r
106 ```\r
107 \r
108 The port and token is provided by Application Framework\r
109 \r
110 Then assign the argument to JSON object\r
111 \r
112 ```\r
113 struct json_object* jobj = json_object_new_object();\r
114 \r
115 json_object_object_add(jobj, "application_name", json_object_new_string("MediaPlayer"));\r
116 \r
117 ```\r
118 \r
119 \r
120 And finally execute the "cal()" function.\r
121 \r
122 ```\r
123 libhs->call("tap_shortcut", jobj);\r
124 ```\r
125 \r
126 Regarding the detail of tap_shortcut() API, please refer [this](#HomeScreen\ API) section.  \r
127 The first parameter is the name of API, so in this case "tap_shortcut" is proper string.  \r
128 And the second parameter corresponds to arguments of "connect()" API.  \r
129 \r
130 \r
131 See also our [Sample code](#Sample\ code).\r
132 \r
133 \r
134 <br />\r
135 \r
136 * * *\r
137 \r
138 ## **<div id="Supported\ usecase">Supported usecase</div>**\r
139 1. HomeScreenGUIでショートカットアイコンがタップされたときに発行されるイベントを取得する\r
140         - 各アプリケーションは自身がアイコンタップにより起動(または表示)されたことを知るために、HomeScreenBinderに対してイベント登録を行い、そのイベントを取得することができます。\r
141 2. オンスクリーンにメッセージを表示する\r
142         - T.B.D\r
143 \r
144 * * *\r
145 \r
146 ## **<div id="Software\ Architecture">Software Architecture</div>**\r
147 The architecture of HomeScreen is shown below.  \r
148 HomeScreen is the service designed to be used by multiple applications.  \r
149 Therefore HomeScreen framework consists on two binder layers. Please refer the following figure.  \r
150 The upper binder is for application side security context for applications. The lower binder is for servide side security context.  \r
151 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
152 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
153 \r
154 The communication protocols between libhomescreen and upper binder, upper binder and lower binder, lower binder (homescreen-binding) are WebSocket.\r
155 \r
156 ![software-stack.png](parts/software-stack.png)\r
157 \r
158 * * *\r
159 \r
160 ## **<div id="API%20reference">API reference</div>**\r
161 "libhomescreen" and "HomeScreenBinding" provides several kinds of APIs.\r
162 \r
163 ### **<div id="Home\ Screen\ Specific\ API">HomeScreen Specific API</div>**\r
164 \r
165 - [LibHomeScreen ()](api-ref/html/de/dd0/class_lib_home_screen.html#a724bd949c4154fad041f96a15ef0f5dc)\r
166 - [init (const int port, const std::string &token)](api-ref/html/de/dd0/class_lib_home_screen.html#a6a57b573cc767725762ba9beab032220)\r
167 - [tapShortcut(const char *application_name)](api-ref/html/de/dd0/class_lib_home_screen.html#afb571c9577087b47065eb23e7fdbc903)\r
168 - [onScreenMessage(const char *display_message)](api-ref/html/de/dd0/class_lib_home_screen.html#ac336482036a72b51a822725f1929523c)\r
169 - [set\_event\_handler(enum EventType et, handler_func f)](api-ref/html/de/dd0/class_lib_home_screen.html#ab1b0e08bf35415de9064afed899e9f85)\r
170 - [call (const string& verb, struct json_object* arg)](api-ref/html/de/dd0/class_lib_home_screen.html#a527b49dcfe581be6275d0eb2236ba37f)\r
171 - [call (const char* verb, struct json_object* arg)](api-ref/html/de/dd0/class_lib_home_screen.html#ab5e8e8ab7d53e0f114e9e907fcbb7643)\r
172 - [subscribe (const string& event_name)](api-ref/html/de/dd0/class_lib_home_screen.html#aa4c189807b75d070f567967f0d690738)\r
173 - [unsubscribe (const string& event_name)](api-ref/html/de/dd0/class_lib_home_screen.html#aac03a45cbd453ba69ddb00c1016930a6)\r
174 \r
175 * * *\r
176 \r
177 ## **<div id="Sequence">Sequence</div>**\r
178 \r
179 ### **<div id="InitializeSequence">Initialize</div>**\r
180 ![initialize.svg](parts/initialize.svg)\r
181 \r
182 ### **<div id="TapShortcutSequence">Tap Shortcut</div>**\r
183 ![tap_shortcut.svg](parts/tap_shortcut.svg)\r
184 \r
185 ### **<div id="OnScreenMessageSequence">On Screen Message</div>**\r
186 ![on_screen_message.svg](parts/on_screen_message.svg)\r
187 \r
188 \r
189 # **<div id="Sample\ code">Sample code</div>**\r
190 You can find sample implementation of HomeScreen as below.\r
191 \r
192 * `HomeScreenBinding/libhomescreen/test.cpp`\r
193 \r
194 ### Appendix\r
195 \r
196 ```\r
197 @startuml\r
198 title Application initialization phase\r
199 entity App\r
200 entity HomeScreenBinder\r
201 entity HomeScreenGUI\r
202 App->HomeScreenBinder: init(port, token)\r
203 App->HomeScreenBinder: subscribe()\r
204 \r
205 note over HomeScreenBinder\r
206     Appが受信したいイベントを登録する\r
207     ・tap_shortcut\r
208 end note\r
209 \r
210 App->HomeScreenBinder: registerCallback()\r
211 App->HomeScreenBinder: set_event_handler()\r
212 \r
213 note over HomeScreenBinder\r
214     イベント受信のコールバック登録\r
215     registerCallbackによる登録または\r
216     set_event_handlerによる登録どちらかでOK\r
217 end note\r
218 \r
219 @enduml\r
220 ```\r
221 \r
222 ```\r
223 @startuml\r
224 title Application Callback Event TapShortcut phase\r
225 entity App\r
226 entity HomeScreenBinder\r
227 entity HomeScreenGUI\r
228 note over App\r
229     Appは初期化時に\r
230     TapShortcutのイベントを受け取る設定をしていること\r
231 end note\r
232 HomeScreenGUI->HomeScreenBinder: tapShortcut(application_name)\r
233 HomeScreenBinder->App: eventCallback(application_name)\r
234 @enduml\r
235 \r
236 ```\r
237 \r
238 ```\r
239 @startuml\r
240 title Application Callback Event TapShortcut phase\r
241 entity App\r
242 entity HomeScreenBinder\r
243 entity HomeScreenGUI\r
244 App->HomeScreenBinder: onScreenMessage(display_message)\r
245 HomeScreenBinder->HomeScreenGUI: eventCallback(display_message)\r
246 @enduml\r
247 \r
248 ```