aboutsummaryrefslogtreecommitdiffstats
path: root/docs/controller.md
blob: 8e6331b39de12d69612945c654dae445d611b3eb (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
# Controller

* Object: Generic Controller to handle Policy,Small Business Logic, Glue in between components, ...
* Status: Release Candidate
* Author: Fulup Ar Foll fulup@iot.bzh
* Date  : May-2018
* Require : af-binder version >= FF (handle only bindings v3)

## Features

* Create a controller application from a JSON config file
* Each control (eg: navigation, multimedia, ...) is a suite of actions. When all actions succeed
 control is granted, if one fails control access is denied.
* Actions can either be:
  * Invocation of an other binding API, either internal or external (eg: a policy service, Alsa UCM, ...)
  * C routines from a user provided plugin (eg: policy routine, proprietary code, ...)
  * Lua script function. Lua provides access to every AGL appfw functionality and can be extended by
   plugins written in C.

## Installation

* Controller can easily be included as a separate library in any AGL service or application binder.
* Dependencies: the only dependencies are [AGL application framework](https://gerrit.automotivelinux.org/gerrit/p/src/app-framework-binder.git)
 and [libafb-helpers](https://gerrit.automotivelinux.org/gerrit/p/src/libafb-helpers.git).
* Controller relies on Lua-5.3, when not needed Lua might be removed at compilation time.

The controller library is integrated by default in the AGL SDK since the Guppy
version (>=7) and is also available as a package for the AGL supported linux
distributions.

You could find the SDK build from Yocto which embed the afb-helpers library
here:

* For [releases](https://download.automotivelinux.org/AGL/release/) >= Guppy, in
 the latest machine's deploy directory. (e.g for Guppy in
 `latest/<yourmachine>/deploy/sdk` directory)
* For the [master](https://download.automotivelinux.org/AGL/snapshots/master/)
 development branch, in the latest machine's deploy directory. (e.g in
 `latest/<yourmachine>/deploy/sdk` directory)

To install the native package please refer to [this chapter](../1-verify-build-host.html)
in the AGL documentation to install the AGL repository for your distribution.

Then use your package manager to install the library.

### OpenSuse

```bash
sudo zypper ref
sudo zypper install agl-libappcontroller-devel
```

### Fedora

```bash
sudo dnf ref
sudo dnf install agl-libappcontroller-devel
```

### Ubuntu/Debian

```bash
sudo apt-get update
sudo apt-get install agl-libappcontroller-dev
```

## Monitoring

* The default test HTML page expect the monitoring HTML page to be accessible under /monitoring with
 the --monitoring option.
* The monitoring HTML pages are installed with the app framework binder in a subdirectory called
 monitoring.
* You can add other HTML pages with the alias options e.g:
 afb-daemon --port=1234 --monitoring --alias=/path1/to/htmlpages:/path2/to/htmlpages --ldpaths=. --workdir=. --roothttp=../htdocs
* The monitoring is accessible at http://localhost:1234/monitoring.
"p">; timerCallbackT callback; sd_event_source *evtSource; } TimerHandleT; PUBLIC int TimerEvtInit (void); PUBLIC afb_event TimerEvtGet(void); PUBLIC void TimerEvtStart(TimerHandleT *timerHandle, timerCallbackT callback, void *context); PUBLIC void TimerEvtStop(TimerHandleT *timerHandle); // ctl-policy // ----------- typedef enum { CTL_MODE_NONE=0, CTL_MODE_API, CTL_MODE_CB, CTL_MODE_LUA, } CtlRequestModeT; typedef enum { CTL_SOURCE_CLOSE=-1, CTL_SOURCE_UNKNOWN=0, CTL_SOURCE_ONLOAD=1, CTL_SOURCE_OPEN=2, CTL_SOURCE_EVENT=3, } DispatchSourceT; typedef struct DispatchActionS{ const char *info; const char* label; CtlRequestModeT mode; const char* api; const char* call; json_object *argsJ; int timeout; int (*actionCB)(DispatchSourceT source, const char*label, json_object *argsJ, json_object *queryJ, void *context); } DispatchActionT; typedef int (*Lua2cFunctionT)(char *funcname, json_object *argsJ, void*context); PUBLIC int DispatchInit(void); PUBLIC int DispatchOnLoad(const char *onLoadLabel); PUBLIC void DispatchOneEvent(const char *evtLabel, json_object *eventJ); PUBLIC int DispatchOneL2c(lua_State* luaState, char *funcname, Lua2cFunctionT callback); PUBLIC void ctlapi_dispatch (afb_req request); #ifdef CONTROL_SUPPORT_LUA // ctl-lua.c typedef int (*Lua2cWrapperT) (lua_State* luaState, char *funcname, Lua2cFunctionT callback); #define CTLP_LUA2C(FuncName, label,argsJ, context) static int FuncName(char*label,json_object*argsJ, void*context);\ int lua2c_ ## FuncName(lua_State* luaState){return((*Lua2cWrap)(luaState, MACRO_STR_VALUE(FuncName), FuncName));};\ static int FuncName(char* label, json_object* argsJ, void* context) typedef enum { LUA_DOCALL, LUA_DOSTRING, LUA_DOSCRIPT, } LuaDoActionT; PUBLIC int LuaLibInit (); PUBLIC void LuaL2cNewLib(const char *label, luaL_Reg *l2cFunc, int count); PUBLIC int Lua2cWrapper(lua_State* luaState, char *funcname, Lua2cFunctionT callback, void *context); PUBLIC int LuaCallFunc (DispatchSourceT source, DispatchActionT *action, json_object *queryJ) ; PUBLIC void ctlapi_lua_docall (afb_req request); PUBLIC void ctlapi_lua_dostring (afb_req request); PUBLIC void ctlapi_lua_doscript (afb_req request); #else typedef void* Lua2cWrapperT; #endif // CONTROL_SUPPORT_LUA // sharelib ctl-plugin* typedef struct { long magic; char *label; } CtlPluginMagicT; #define MACRO_STR_VALUE(arg) #arg #define CTLP_REGISTER(pluglabel) CtlPluginMagicT CtlPluginMagic={.magic=CTL_PLUGIN_MAGIC,.label=pluglabel}; struct afb_binding_data_v2; Lua2cWrapperT Lua2cWrap; #define CTLP_ONLOAD(label,version,info) void* CtlPluginOnload(char* label, char* version, char* info) #define CTLP_CAPI(funcname,source, label,argsJ, queryJ, context) int funcname(DispatchSourceT source, char* label, json_object* argsJ, json_object* queryJ, void* context) #endif // CONTROLLER_BINDING_INCLUDE