aboutsummaryrefslogtreecommitdiffstats
path: root/doc/ApplicationGuide.md
blob: 902e9b61a9355b91cfdd25c3bc86ea57457f50a3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
**HomeScreen GUI Application / HomeScreen Service Guide**
====
    Revision: 0.1
    TOYOTA MOTOR CORPORATION
    Advanced Driver Information Technology
    17th/June/2019

* * *

## Table of content
- [Target reader of this document](#target-reader-of-this-document)
- [Overview](#overview)
- [Getting Start](#getting-start)
    - [Supported environment](#supported-environment)
    - [Build](#build)
    - [Configuring](#configuring)
    - [How to call HomeScreen APIs from your Application?](#how-to-call-homescreen-apis-from-your-application)
- [Supported usecase](#supported-usecase)
- [Software Architecture](#software-architecture)
- [API reference](#api-reference)
- [Sequence](#sequence)
    - [Initialize](#initialize-sequence)
    - [Tap Shortcut(deprecated)](#tap-shortcut-sequence)
    - [On Screen Message / Reply Sequence](#on-screen-message-/-reply-sequence)
- [Sample code](#sample-code)
- [Limitation](#limitation)
- [Next Plan](#next-plan)
- [Appendix](#appendix)

* * *

## Target reader of this document
Application developer whose software uses HomeScreen.

* * *

## Overview
HomeScreen is built with a GUI application created with Qt(referred as HomeScreenGUI), and a service running on afb-daemon (referred as HomeScreenBinder).
HomeScreen can start/switch applications run in AGL, also displays information such as onscreen messages.

You can find these projects in AGL gerrit.

- [homescreen-2017(HomeScreenGUI)](https://gerrit.automotivelinux.org/gerrit/#/admin/projects/staging/homescreen-2017)
- [agl-service-homescreen-2017(HomeScreenBinder's binding library)](https://gerrit.automotivelinux.org/gerrit/#/admin/projects/apps/agl-service-homescreen-2017)
- [libhomescreen(library for application to communication with HomeScreenBinder)](https://gerrit.automotivelinux.org/gerrit/#/admin/projects/src/libhomescreen)

Also HomeScreenGUI is using libwindowmanager.

* * *

## Getting Start

### Supported environment

| Item        | Description                       |
|:------------|:----------------------------------|
| AGL version | Funky Flounder                      |
| Hardware    | Renesas R-Car Starter Kit Pro(M3) |


### Build

**Download recipe**

```
$ mkdir WORK
$ cd WORK
$ repo init -u https://gerrit.automotivelinux.org/gerrit/AGL/AGL-repo
$ repo sync

```

Then you can find the following recipes.

* `meta-agl-devel/meta-hmi-framework/homescreen-2017`

* `meta-agl-devel/meta-hmi-framework/agl-service-homescreen-2017`

* `meta-agl-demo/recipes-demo-hmi/libhomescreen`


**Bitbake**

```
$ source meta-agl/scripts/aglsetup.sh -m m3ulcb agl-demo agl-devel agl-appfw-smack agl-hmi-framework
$ bitbake agl-demo-platform
```

### Configuring
To use HomeScreen API, an application shall paste the following configuration definition into "config.xml" of application.

```
<feature name="urn:AGL:widget:required-api">
	<param name="homescreen" value="ws" />
</feature>
```

### How to call HomeScreen APIs from your Application?
HomeScreen provides a library which is called "libhomescreen".
This library treats "json format" as API calling.
For example, if an application wants to call "tap_shortcut()" API, the you should implement as below.

At first the application should create the instance of libhomescreen.

```
LibHomeScreen* libhs;
libhs = new LibHomeScreen();
libhs->init(port, token);
```

The port and token is provided by Application Framework

Execute the "tapShortcut()" function.

```
libhs->tapShortcut("application_name");
```

Regarding the detail of tap_shortcut() API, please refer [this](#HomeScreen\ API) section.
The first parameter is the name of API, so in this case "tap_shortcut" is proper string.
And the second parameter corresponds to arguments of "connect()" API.

See also our [Sample code](#sample-code).

* * *

## Supported usecase
1. HomeScreenGUI sending ShortCut Icon tapped event to applications
	- Applications using libhomescreen to subscribe the tapShortcut event,
        HomeScreenGUI will send ShortCut Icon tapped event to applications.
2. Display OnScreen messages
	- Applications sending OnScreen messages to homescreen-service, and OnScreenAPP
        will get these message and display.
3. Get OnSreen Reply event
	- When OnScreen messages is displaying, OnScreenAPP will send a reply event to applications.

* * *

## Software Architecture
The architecture of HomeScreen is shown below.
HomeScreen is the service designed to be used by multiple applications.
Therefore HomeScreen framework consists on two binder layers. Please refer the following figure.
The upper binder is for application side security context for applications. The lower binder is for servide side security context.
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.
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).

The communication protocols between libhomescreen and upper binder, upper binder and lower binder, lower binder (homescreen-binding) are WebSocket.

![software-stack.png](parts/software-stack.png)

* * *

## API reference
"libhomescreen" and "agl-service-homescreen-2017" provides several kinds of APIs.

### HomeScreen Specific API

- LibHomeScreen::init (const int port, const std::string &token)
```
    port [in] : This argument should be specified to the port number to be used for websocket
    token [in] : This argument should be specified to the token to be used for websocket

    Create connection to homescreen-service by port and token which provided by
    application framework. This API must be called before calling other api.
```
- LibHomeScreen::tapShortcut(const char *application_name)
```
    application_name [in] : Tapped application name (label)

    Request to show the window of application_name.
```
- LibHomeScreen::onScreenMessage(const char *display_message)
```
    display_message [in] : message for display

    Request to display message in onscreen.
```
- LibHomeScreen::onScreenReply(const char *reply_message)
```
    reply_message [in] : message for reply

    Post reply message to application.
```
- LibHomeScreen::registerCallback(void(*event_cb)(const std::string &event, struct json_object *event_contents), void(*reply_cb)(struct json_object *reply_contents), void(*hangup_cb)(void)=nullptr)
```
    event_cb [in] : This argument should be specified to the callback for subscribed event
    reply_cb [in] : This argument should be specified to the reply callback for call function
    hangup_cb [in] : This argument should be specified to the hangup callback for call function

    This api is deprecated, recommend using set_event_handler.
```
- LibHomeScreen::set_event_handler(enum EventType et, handler_func f)
```
    et [in] : event name
    f [in] : event handler

    Setting event handler for Homescreen-Service Event.
```
- LibHomeScreen::call(const string& verb, struct json_object* arg)
- LibHomeScreen::call(const char* verb, struct json_object* arg)
```
    verb [in] : This argument should be specified to the API name (e.g. "tap_shortcut")
    arg [in] : This argument should be specified to the argument of API.
    And this argument expects JSON object

    Call homescreen-service verb.
```
- LibHomeScreen::subscribe(const string& event_name)
```
    event_name [in] : This argument should be specified to the event name

    Subscribe homescreen-service event. Deprecated, recommend using set_event_handler.
```
- LibHomeScreen::unsubscribe(const string& event_name)
```
    event_name [in] : This argument should be specified to the event name

    Unsubscribe homescreen-service event. Deprecated, recommend using set_event_handler.
```

* * *

## Sequence

### Initialize Sequence
![initialize-registercallback.svg](parts/initialize-registercallback.svg) * deprecated
![initialize-set-event-handler](parts/initialize-set-event-handler.svg)

### Tap Shortcut Sequence
![tap_shortcut.svg](parts/tap_shortcut.svg)

### On Screen Message / Reply Sequence
![on_screen_message.svg](parts/on_screen_message.svg)

## Sample code
You can find sample implementation of HomeScreen as below.

* `libhomescreen/sample/simple-egl`

* `libhomescreen/sample/template`

* * *

## Limitation
None.

* * *

## Next Plan
None.

* * *

## Appendix

```
@startuml
title Application initialization phase (ex. registerCallback)
entity App
entity HomeScreenBinder
entity HomeScreenGUI
App->HomeScreenBinder: init(port, token)
App->HomeScreenBinder: subscribe()

note over HomeScreenBinder
    Register the event the App wishes to receive
    ・tap_shortcut
    ・on_screen_message
    ・on_screen_reply
end note

App->HomeScreenBinder: registerCallback()

@enduml
```

```
@startuml
title Application initialization phase (ex. set_event_handler)
entity App
entity HomeScreenBinder
entity HomeScreenGUI
App->HomeScreenBinder: init(port, token)
App->HomeScreenBinder: set_event_handler()

note over HomeScreenBinder
    setup event handler the App wishes to receive
    ・LibHomeScreen::Event_TapShortcut
    ・LibHomeScreen::Event_OnScreenMessage
    ・LibHomeScreen::Event_OnScreenReply
end note

@enduml
```

```
@startuml
title Application Callback Event TapShortcut phase
entity App
entity HomeScreenBinder
entity HomeScreenGUI
App->HomeScreenBinder: set_event_handler()

note over App
    LibHomeScreen::Event_TapShortcut
end note

HomeScreenGUI->HomeScreenBinder: tapShortcut(application_name)
HomeScreenBinder->App: event_handler(application_name)
@enduml
```

```
@startuml
title Application Callback Event On Screen Message / Reply phase
entity App
entity HomeScreenBinder
entity HomeScreenGUI

HomeScreenGUI->HomeScreenBinder: set_event_handler()

note over HomeScreenGUI
    LibHomeScreen::Event_OnScreenMessage
end note


App->HomeScreenBinder: set_event_handler()

note over App
    LibHomeScreen::Event_OnScreenReply
end note

App->HomeScreenBinder: onScreenMessage(display_message)
HomeScreenBinder->HomeScreenGUI: event_handler(display_message)
HomeScreenGUI->HomeScreenBinder: onScreenReply(reply_message)
HomeScreenBinder->App: event_handler(reply_message)
@enduml
```