packaging: Update spec and deb packaging
[src/app-framework-binder.git] / README.md
1 ### Application Framework Binder
2 This is an undergoing work, publication is only intended for developers to review and provide feedback. 
3
4 ### License
5 Apache 2
6
7 ### Building
8 Building Application Framework Binder has been tested under **Ubuntu 16.04 LTS (Xenial Xerus)** or **Fedora 23**, and requires the following libraries:
9  * libmagic ("libmagic-dev" under Ubuntu, "file-devel" under Fedora);
10  * libmicrohttpd >= 0.9.48  (fetch and build from "http://ftp.gnu.org/gnu/libmicrohttpd");
11  * json-c ("libjson-c-dev/devel");
12  * uuid ("uuid-dev/libuuid-devel");
13  * openssl ("libssl-dev/openssl-devel");
14  * systemd >= 222 ("libsystemd-dev/systemd-devel");
15
16 Optionally, for plugins :
17  * alsa ("libasound2-dev/alsa-devel");
18  * pulseaudio ("libpulse-dev/libpulse-devel");
19  * rtl-sdr >= 0.5.0 ("librtlsdr-dev", or fetch and build from "git://git.osmocom.org/rtl-sdr" under Fedora);
20  * GUPnP ("libglib2.0-dev libgupnp-av-1.0-dev/glib2-devel libgupnp-av-devel");
21
22 Libmicrohttpd :
23  * version >= 0.9.54
24
25 and the following tools:
26  * gcc;
27  * make;
28  * pkg-config;
29  * cmake >= 2.8.8.
30
31 To install all dependencies under Ubuntu (excepting libmicrohttpd), please type:
32 ```
33 $ apt-get install libmagic-dev libjson-c-dev uuid-dev libsystemd-dev libssl-dev libasound2-dev libpulse-dev librtlsdr-dev libglib2.0-dev libgupnp-av-1.0-dev gcc make pkg-config cmake
34 ```
35 or under Fedora (excepting libmicrohttpd and rtl-sdr):
36 ```
37 $ dnf install git passwd iproute openssh-server openssh-client openssh-server # Tools needed on top of Docker Minimal Fedora
38 $ dnf install file-devel gcc gdb make pkgconfig cmake  # install gcc developement tool chain + cmake
39 $ dnf install file-devel json-c-devel libuuid-devel systemd-devel openssl-devel 
40 $ dnf install alsa-lib-devel pulseaudio-libs-devel glib2-devel gupnp-av-devel # optional but require to build audio plugin
41 ```
42
43  To build, move to your HOME directory and type:
44 ```
45 $ LIB_MH_VERSION=0.9.54
46 $ export LIBMICRODEST=/opt/libmicrohttpd-${LIB_MH_VERSION}
47 $ wget https://ftp.gnu.org/gnu/libmicrohttpd/libmicrohttpd-${LIB_MH_VERSION}.tar.gz
48 $ tar -xzf libmicrohttpd-${LIB_MH_VERSION}.tar.gz
49 $ cd libmicrohttpd-${LIB_MH_VERSION}
50 $ ./configure --prefix=${LIBMICRODEST}
51 $ make
52 $ sudo make install-strip
53
54 $ AFB_DAEMON_DIR=$HOME/app-framework-binder
55 $ git clone https://gerrit.automotivelinux.org/gerrit/src/app-framework-binder ${AFB_DAEMON_DIR}
56 $ cd ${AFB_DAEMON_DIR}
57 $ mkdir -p build; cd build<br />
58 $ export PKG_CONFIG_PATH=${LIBMICRODEST}/lib/pkgconfig 
59 $ cmake ..<br />
60 $ make; 
61 $ sudo make install<br />
62 ```
63
64 ### Archive
65
66 ```
67 VERSION=2.0
68 GIT_TAG=master
69 PKG_NAME=app-framework-binder
70 git archive --format=tar.gz --prefix=agl-${PKG_NAME}-${VERSION}/ ${GIT_TAG} -o agl-${PKG_NAME}_${VERSION}.orig.tar.gz
71 ```
72
73 ### Testing/Debug
74 ```
75 $ ${AFB_DAEMON_DIR}/build/src/afb-daemon --help
76 $ ${AFB_DAEMON_DIR}/build/src/afb-daemon --port=1234 --token='' --ldpaths=${AFB_DAEMON_DIR}/build --sessiondir=/tmp --rootdir=${AFB_DAEMON_DIR}/test 
77 ```
78
79 ### Starting
80 ```
81 $ afb-daemon --help 
82 $ afb-daemon --verbose --port=<port> --token='' --sessiondir=<working directory> --rootdir=<web directory (index.html)>
83 ```
84
85 ### Example
86 ```
87 $ afb-daemon --verbose --port=1234 --token='' --sessiondir=/tmp --rootdir=/srv/www/htdocs --alias=icons:/usr/share/icons
88 ```
89
90 ### Directories & Paths
91 Default behaviour is to locate ROOTDIR in $HOME/.AFB
92
93 ### REST API
94
95 Developers are intended to provide a structure containing : API name, corresponding methods/callbacks, and optionally a context and a handle.
96 A handle is a void* structure automatically passed to API callbacks. 
97 Callbacks also receive HTTP GET data as well as HTTP POST data, in case a POST method was used. 
98 Every method should return a JSON object or NULL in case of error.
99
100 API plugins can be protected from timeout and other errors. By default this behaviour is deactivated, use --apitimeout to activate it.
101         
102         STATIC AFB_restapi myApis[]= {
103           {"ping"    , AFB_SESSION_NONE,  (AFB_apiCB)ping,     "Ping Function"},
104           {"action1" , AFB_SESSION_CHECK, (AFB_apiCB)action1 , "Action-1"},
105           {"action2" , AFB_SESSION_CHECK, (AFB_apiCB)action2 , "Action-2"},
106           {NULL}
107         };
108
109         PUBLIC AFB_plugin *pluginRegister () {
110             AFB_plugin *plugin = malloc (sizeof (AFB_plugin));
111             plugin->type  = AFB_PLUGIN_JSON;
112             plugin->info  = "Plugin Sample";
113             plugin->prefix= "myPlugin";        
114             plugin->apis  = myApis;
115             return (plugin);
116         }
117
118 ### HTML5 and AngularJS Redirects
119
120 Binder supports HTML5 redirect mode even with an application baseurl. 
121 Default value for application base URL is /opa. 
122 See Application Framework HTML5 Client template at https://github.com/iotbzh/afb-client-sample
123
124 If the Binder receives something like _http://myopa/sample_ when sample is not the homepage of the AngularJS OPA, 
125 it will redirect to _http://myopa/#!sample_. 
126 This redirect will return the _index.html_ OPA file and will notify AngularJS not to display the homepage, but the sample page.
127
128 Warning: in order for AngularJS applications to be able to work with both BASEURL="/" and BASEURL="/MyApp/", all page references have to be relative. 
129
130 Recommended model is to develop with a BASEURL="/opa" as any application working with a BASEURL will work without, while the opposite is not true.
131
132 Note: If a resource is not accessible from ROOTDIR then the "--alias" switch should be used, as in: --alias=/icons:/usr/share/icons. 
133 Only use alias for external support static files. This should not be used for API and OPA.
134
135
136 ### Ongoing work
137
138 Javascript plugins. As of today, only C plugins are supported, but JS plugins are on the TODO list.
139