Improves the documentation
[src/app-framework-binder.git] / doc / afb-application-writing.md
1 HOWTO WRITE an APPLICATION above AGL FRAMEWORK
2 ==============================================
3     version: 1
4     Date:    30 mai 2016
5     Author:  José Bollo
6
7 TABLE-OF-CONTENT-HERE
8
9 Writing an HTML5 application
10 ----------------------------
11
12 Developpers of HTML5 applications (client side) can easyly create
13 applications for AGL framework using their prefered
14 HTML framework.
15
16 Developpers can also create powerful server side plugins to improve
17 their application. This server side plugin should return the mime-type
18 application/json and can be accessed either by HTTP or by Websockets.
19
20 In a near future, the JSON-RPC protocol will be available together
21 with the current x-afb-json1 protocol.
22
23 Two examples of HTML5 applications are given:
24
25 - [afb-client](https://github.com/iotbzh/afb-client) a simple "hello world" application
26
27 - [afm-client](https://github.com/iotbzh/afm-client) a simple "Home screen" application
28
29 Writing a Qt application
30 ------------------------
31
32 Writing Qt applications is also possible because Qt offers APIs to
33 make HTTP queries and to connect using WebSockets.
34
35 It is even possible to write a QML application.
36 It is demontrated by the sample application token-websock:
37
38 - [token-websock](https://github.com/iotbzh/afb-daemon/blob/master/test/token-websock.qml) 
39 a simple "hello world" application in QML
40
41 Writing a C application
42 -----------------------
43
44 C applications can use the binder afb-daemon through a websocket connection.
45
46 The library **libafbwsc** is made for C clients that want
47 to connect to the afb-daemon binder.
48
49 The program **afb-client-demo** is the C program that use
50 the provided library **libafbwsc**.
51 Its source code is here
52 [src/afb-client-demo.c](https://github.com/iotbzh/afb-daemon/blob/master/src/afb-client-demo.c).
53
54 The current implementation use libsystemd and file descriptors.
55 This may be changed in the future to also support secure sockets
56 and being less dependant of libsystemd.
57
58 Handling sessions within applications
59 -------------------------------------
60
61 ### Exchanging tokens
62
63 Applications are communicating with their binder afb-daemon using
64 a network connection or a kind of network connection (unix domain
65 socket isn't currently implemented but could be used in near future).
66 Also, HTTP protocol is not a connected protocol. It means that
67 the socket connection can not be used to authenticate a client.
68
69 For this reason, the binder should authenticate the application
70 by using a commonly shared secret named token.
71
72 At start, the framework communicate a common secret to both the binder
73 and its client: the application. When the application 
74
75 ### Handling sessions
76
77