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