aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--.gitmodules6
-rw-r--r--CMakeLists.txt5
-rw-r--r--README.md422
m---------afb-utilities0
-rw-r--r--conf.d/CMakeLists.txt22
m---------conf.d/app-templates0
-rwxr-xr-xconf.d/autobuild/agl/autobuild63
-rwxr-xr-xconf.d/autobuild/linux/autobuild63
-rw-r--r--conf.d/cmake/00-debian-specific.cmake3
-rw-r--r--conf.d/cmake/00-default-osconfig.cmake1
-rw-r--r--conf.d/cmake/config.cmake237
-rw-r--r--conf.d/packaging/agl-afb-controller.dsc21
-rw-r--r--conf.d/packaging/agl-afb-controller.spec68
-rw-r--r--conf.d/packaging/debian.agl-afb-controller.install2
-rw-r--r--conf.d/packaging/debian.changelog5
-rw-r--r--conf.d/packaging/debian.compat1
-rw-r--r--conf.d/packaging/debian.control22
-rw-r--r--conf.d/packaging/debian.rules87
-rw-r--r--conf.d/project/CMakeLists.txt24
-rw-r--r--conf.d/project/json.d/CMakeLists.txt32
-rw-r--r--conf.d/project/json.d/README.md23
-rw-r--r--conf.d/project/json.d/onload-daemon-sample.json69
-rw-r--r--conf.d/project/lua.d/CMakeLists.txt32
-rw-r--r--conf.d/project/lua.d/doscript-helloworld.lua36
-rw-r--r--conf.d/project/lua.d/onload-daemon-00-utils.lua86
-rw-r--r--conf.d/project/lua.d/onload-daemon-01-init.lua48
-rw-r--r--conf.d/project/lua.d/onload-daemon-03-controls.lua47
-rw-r--r--conf.d/project/lua.d/onload-daemon-04-oncall.lua70
-rw-r--r--conf.d/project/lua.d/onload-daemon-10-event.lua74
-rw-r--r--conf.d/project/vscode.d/c_cpp_properties.json18
-rw-r--r--conf.d/wgt/config.xml.in23
-rw-r--r--conf.d/wgt/icon.pngbin3934 -> 0 bytes
-rw-r--r--ctl-binding/ctl-apidef.h118
-rw-r--r--ctl-binding/ctl-apidef.json249
-rw-r--r--ctl-binding/ctl-binding.c74
-rw-r--r--ctl-binding/ctl-binding.h145
-rw-r--r--ctl-binding/ctl-dispatch.c678
-rw-r--r--ctl-binding/ctl-policy.c221
-rw-r--r--ctl-dispatch/CMakeLists.txt (renamed from ctl-binding/CMakeLists.txt)18
-rw-r--r--ctl-dispatch/ctl-action.c174
-rw-r--r--ctl-dispatch/ctl-config.c176
-rw-r--r--ctl-dispatch/ctl-config.h113
-rw-r--r--ctl-dispatch/ctl-lua.c (renamed from ctl-binding/ctl-lua.c)71
-rw-r--r--ctl-dispatch/ctl-lua.h77
-rw-r--r--ctl-dispatch/ctl-onload.c57
-rw-r--r--ctl-dispatch/ctl-plugin.c219
-rw-r--r--ctl-dispatch/ctl-plugin.h74
-rw-r--r--ctl-dispatch/ctl-timer.c (renamed from ctl-binding/ctl-timer.c)4
-rw-r--r--ctl-dispatch/ctl-timer.h42
-rw-r--r--ctl-plugin/CMakeLists.txt52
-rw-r--r--ctl-plugin/ctl-plugin-sample.c134
-rw-r--r--htdocs/AFB-websock.js177
-rw-r--r--htdocs/AudioBinding.css7
-rw-r--r--htdocs/AudioBinding.js197
-rw-r--r--htdocs/CMakeLists.txt34
-rw-r--r--htdocs/README.md7
-rw-r--r--htdocs/index.html37
-rw-r--r--nbproject/project.xml2
58 files changed, 1021 insertions, 3746 deletions
diff --git a/.gitmodules b/.gitmodules
deleted file mode 100644
index cb8ad34..0000000
--- a/.gitmodules
+++ /dev/null
@@ -1,6 +0,0 @@
-[submodule "conf.d/app-templates"]
- path = conf.d/app-templates
- url = https://gerrit.automotivelinux.org/gerrit/apps/app-templates
-[submodule "afb-utilities"]
- path = afb-utilities
- url = https://github.com/iotbzh/afb-utilities.git
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 22adb2a..25b8bf7 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -15,7 +15,6 @@
# See the License for the specific language governing permissions and
# limitations under the License.
###########################################################################
-CMAKE_MINIMUM_REQUIRED(VERSION 3.5)
-# Do not change this file, config is located into conf.d
-include(${CMAKE_CURRENT_SOURCE_DIR}/conf.d/cmake/config.cmake)
+# This component should be included as a submodule and wont compile as standalone
+add_subdirectory("ctl-dispatch")
diff --git a/README.md b/README.md
index 32b798a..ba10cb0 100644
--- a/README.md
+++ b/README.md
@@ -1,401 +1,55 @@
-# Controler AAAA(AGL Advance Audio Controller) and more.
+# Controller Utilities
-* Object: Generic Controller to handle Policy,Small Business Logic, Glue in between components, ...
+* Object: Generic Controller Utilities to handle Policy,Small Business Logic, Glue in between components, ...
* Status: Release Candidate
* Author: Fulup Ar Foll fulup@iot.bzh
-* Date : August-2017
+* Date : October-2017
-## Cloning afb-controller from Git
+## Usage
-```bash
-# Initial clone with submodules
-git clone --recurse-submodules https://github.com/iotbzh/afb-controller
-cd audio-binding
-
-# Do not forget submodules with pulling
-git pull --recurse-submodules https://github.com/iotbzh/afb-controller
-git submodule update
+1) Add ctl-utilities as a submodule to include in your project
```
-
-## Features
-
-* Create an application dedicate controller from a JSON config file
-* Each controls (eg: navigation, multimedia, ...) is a suite of actions. When all actions succeed control is granted, if one fail control acces is denied.
-* Actions can either be:
- * Invocation to an other binding API, either internal or external (eg: a policy service, Alsa UCM, ...)
- * C routines from a user provider plugin (eg: policy routine, proprietary code, ...)
- * Lua script function. Lua provides access to every AGL appfw functionalities and can be extended from C user provided plugins.
-
-## Installation
-
-* Controller is a native part of AGL Advance Audio Framework but may be used independently with any other service or application binder.
-* Dependencies: the only dependencies are audio-common for JSON-WRAP and Filescan-utils capabilities.
-* Controller relies on Lua-5.3, when not needed Lua might be removed at compilation time.
-
-## Monitoring
-
-* Default test HTML page expect monitoring HTML page to be accessible from /monitoring for this to work you should
-* place monitoring HTML pages in a well known location eg: $HOME/opt/monitoring
-* start your binder with the alias option e.g. afb-daemon --port=1234 --alias=/monitoring:/home/fulup/opt/afb-monitoring --ldpaths=. --workdir=. --roothttp=../htdocs
-
-## Controller binding configuration
-
-By default controller searches for a config filename with the same 'middlename' as daemon process. As an example if your process name is afb-daemon then middle name is 'daemon'.
-
-```bash
-# Middlename is taken from process middlename.
-onload-middlename-xxxxx.json
+git submodule add git@github.com:iotbzh/afb-utilities
```
-You may overload config search path with environment variables
-
-* **AFB_BINDER_NAME**: change patern config search path. 'export AFB_BINDER_NAME=sample' will make controller to search for a configfile name 'onload-sample-xxx.json'.
-* **CONTROL_CONFIG_PATH**: change default reserch path for configuration. You may provide multiple directories separated by ':'.
-* **CONTROL_LUA_PATH**: same as CONTROL_CONFIG_PATH but for Lua script files.
-
-Example to load a config name 'onload-myconfig-test.json' do
-
-```bash
-AFB_BINDER_NAME='myconfig' afb-daemon --verbose ...'
+2) Add ctl-utilities as a static library to your binding
+```
+ # Library dependencies (include updates automatically)
+ TARGET_LINK_LIBRARIES(${TARGET_NAME}
+ ctl-utilities
+ ... other dependencies ....
+ )
```
-> **Note**: you may change search pattern for Lua script by adding 'ctlname=afb-middlename-xxx' in the metadata section of your config 'onload-*.json'
-
-The configuration is loaded dynamically during startup time. The controller scans **CONTROL_CONFIG_PATH** for a file corresponding to pattern
-"onload-bindername-xxxxx.json". When controller runs within AAAA binder it searches for "onload-audio-xxxx.json". First file found in the path the loaded
-any other files corresponding to the same path are ignored and only generate a warning.
-
-Each bloc in the configuration file are defined with
-
-* **label**: must be provided is used either for debugging or as input for the action (eg: signal name, control name, ...)
-* **info**: optional used for documentation purpose only
-
-> **Note**: by default controller config search path is defined at compilation time, but path might be overloaded with **CONTROL_CONFIG_PATH**
-> environment variable. Setenv 'CONTROL_ONLOAD_PROFILE'=xxxx to overload 'onload-default-profile' initialisation sequence.
-
-### Config is organised in 4 sections:
-
-* **metadata**: describe the configuration
-* **onload**: defines the set of action to be executed at startup time
-* **control**: defines the set of controls with corresponding actions
-* **event**: define the set of actions to be executed when receiving a given signal
-
-### Metadata
-
-As today matadata is only used for documentation purpose.
-
-* **label**: mandatory
-* **version**: mandatory
-* **info**: optional
-
-### OnLoad section
-
-Defines startup time configuration. Onload may provide multiple initialisation profiles, each with a different label.
-
-* **label**: is mandatory. Label is used to select onload profile at initialisation through DispatchOneOnLoad("onload-label") API;
-* **info**: is optional
-* **plugin**: provides optional unique plugin name. Plugin should follow "onload-bindername-xxxxx.ctlso" pattern
- and are searched into CONTROL_PLUGIN_PATH. When defined controller will execute user provided function context=**CTLP_ONLOAD(label,version,info)**.
- The context returned by this routine is provided back to any C routines call later by the controller. Note that Lua2C function
- are prefix in Lua script with plugin label (eg: MyPlug: in following config sample)
- * **label**: mandatory
- * **sharedlib**: file name of the built shared library of the provided plugin
- * **lua2c**: list of Lua commands shipped with provided plugin.
-* **require**: list of binding that should be initialised before the controller starts. Note that some listed requirer binding might be absent,
- nevertheless any present binding from this list will be started before controller binding, missing ones generate a warning.
-* **action**: the list of action to execute during loadtime. Any failure in action will prevent controller binding from starting.
-
-### Control section
-
-Defines a list of controls that are accessible through (api="control", verb="request", control="control-label").
-
-* **label**: mandatory
-* **info**: optional
-* **permissions**: Cynara needed privileges to request this control (same as AppFw-V2)
-* **action**: the list of actions
-
-### Event section
-
-Defines a list of actions to be executed on event reception. Even can do anything a controller can (change state,
-send back signal, ...) eg: if a controller subscribes to vehicle speed, then speed-event may adjust master-volume to speed.
-
-* **label**: mandatory
-* **info**: optional
-* **action**: the list of actions
-
-### Actions Categories
-
-Controller support tree categories of actions. Each action return a status status where 0=success and 1=failure.
-
-* AppFw API, Provides a generic model to request other bindings. Requested binding can be local (eg: ALSA/UCM) or
- external (eg: vehicle signalling).
- * api provides requested binding API name
- * verb provides verb to requested binding
- * args optionally provides a jsonc object for targeted binding API. Note that 'args' are statically defined
- in JSON configuration file. Controller client may also provided its own arguments from the query list. Targeted
- binding receives both arguments defined in the config file and the argument provided by controller client.
-* C-API, when defined in the onload section, the plugin may provide C native API with **CTLP-CAPI(apiname, label, args, query, context)**.
- Plugin may also create Lua command with **CTLP-Lua2C(LuaFuncName, label, args, query, context)**. Where *args*+*query* are JSON-C object
- and context the value return from **CTLP_ONLOAD** function. Any missing value is set to NULL.
-* Lua-API, when compiled with Lua option, the controller support action defined directly in Lua script. During "*onload*" phase the
- controller search in *CONTROL_LUA_PATH* file with pattern "onload-bindername-xxxx.lua". Any file corresponding to this pattern
- is automatically loaded. Any function defined in those Lua script can be called through a controller action. Lua functions receive
- three parameters (label, args, query).
-
-> **Note**: Lua added functions systematically prefix. AGL standard AppFw functions are prefixed with AGL: (eg: AGL:notice(), AGL_success(), ...).
-> User Lua functions added though the plugin and CTLP_Lua2C are prefix with plugin label (eg: MyPlug:HelloWorld1).
-
-Actions is a list with the following fields:
-
-* **label**: mandatory
-* **info**: optional
-* **callback**: to specify a plugin callback
-* **api**: name an api from another binding
-* **verb**: name called from the other api specified with api field
-* **args**: could be is a JSON object with arguments when calling a callback or an api/verb
-* **lua**: map a LUA function
-
-### Available Application Framework Commands
-
-Each Lua AppFw commands should be prefixed by AFB:
-
-* AFB:notice ("format", arg1,... argn) LUA table are print directly as json string with '%s'.
- AFB:error, AFB:warning, AFB:info, AFB:debug work on the same model. Printed message are limited to 512 characters.
-
-* AFB:service ('API', 'VERB', {query}, "Lua_Callback_Name", {context}) asynchronous call to an other binding. When empty query/context should be set to '{}'
- and not to 'nil'. When 'nil' Lua does not send 'NULL' value but remove arguments to calling stack. WARNING:"Callback"
- is the name of the callback as a string and not a pointer to the callback. (If someone as a solution to fix this, please
- let me known). Callback is call as LUA "function Alsa_Get_Hal_CB (error, result, context)" where:
- * error is a Boolean
- * result is the full answer from AppFw (do not forget to extract response)
- * context is a copy of the Lua table pas as argument (warning it's a copy not a pointer to original table)
-
-* error,result=AFB:servsync('API', 'VERB', {query}) Save as previous but for synchronous call. Note that Lua accept multiple
- return. AFB:servsync return both the error message and the response as a Lua table. Like for AFB:service user should not
- forget to extract response from result.
-
-* AFB:success(request, response) request is the opaque handle pass when Lua is called from (api="control", verb="docall").
- Response is a Lua table that will be return to client.
-
-* AFB:fail(request, response) same as for success. Note that LUA generate automatically the error code from Lua function name.
- The response is transformed to a json string before being return to client.
-
-* EventHandle=AFB:evtmake("MyEventName") Create an event and return the handle as an opaque handle. Note that due to a limitation
- of json_object this opaque handle cannot be passed as argument in a callback context.
-
-* AFB:subscribe(request, MyEventHandle) Subscribe a given client to previously created event.
-
-* AFB:evtpush (MyEventHandle, MyEventData) Push an event to every subscribed client. MyEventData is a Lua table that will be
- send as a json object to corresponding clients.
-
-* timerHandle=AFB:timerset (MyTimer, "Timer_Test_CB", context) Initialise a timer from MyTimer Lua table. This table should contend 3 elements:
- MyTimer={[l"abel"]="MyTimerName", ["delay"]=timeoutInMs, ["count"]=nBOfCycles}. Note that is count==0 then timer is cycle
- infinitely. Context is a standard Lua table. This function return an opaque handle to be use to further control the timer.
-
-* AFB:timerclear(timerHandle) Kill an existing timer. Return an error when timer does not exit.
-
-* MyTimer=AFB:timerget(timerHandle) Return Label, Delay and Count of an active timer. Return an error when timerHandle does not
- point on an active timer.
-
-> **Note**: Except for function call during binding initialisation period. Lua call are protected and should return clean message
-> even when improperly used. If you find bug please report.
-
-### Adding Lua command from User Plugin
-
-User Plugin is optional and may provide either native C-action accessible directly from controller actions as defined in
-JSON config file, or alternatively may provide at set of Lua commands usable inside any script (onload, control,event). A simple
-plugin that provides both notice C API and Lua commands is provided as example (see ctl-plugin-sample.c). Technically a
-plugin is a simple sharelibrary and any code fitting in sharelib might be used as a plugin. Developer should nevertheless
-not forget that except when no-concurrency flag was at binding construction time, any binding should to be thread safe.
-
-A plugin must be declare with **CTLP_REGISTER**("MyCtlSamplePlugin"). This entry point defines a special structure that is check
-at plugin load time by the controller. Then you have an optional init routine declare with **CTLP_ONLOAD**(label, version, info).
-This init routine receives controller onload profile as selected by DispatchOnLoad("profile"). The init routine may create
-a plugin context that is later one presented to every plugin API this for both LUA and native C ones. Then each:
-
-* C API declare with **CTLP_CAPI**(MyCFunction, label, argsJ, queryJ, context) {your code}. Where:
- * MyFunction is your function
- * Label is a string containing the name of your function
- * ArgsJ a json_object containing the argument attach the this control in JSON config file.
- * context is your C context as return from **CTLP_ONLOAD**
-
-* Lua API declarewith **TLP_LUA2C**(MyLuaCFunction, label, argsJ, context) {your code}. Where
- * MyLuaCFunction is both the name of your C function and Lua command
- * Label your function name as a string
- * Args the arguments passed this time from Lua script and not from Json config file.
- * Query is not provided as LuaC function are called from a script and not directly from controller action list.
-
-> **Warning**: Lua samples use with controller enforce strict mode. As a result every variables should be declare either as
-> local or as global. Unfortunately "luac" is not smart enough to handle strict mode at build time and errors only appear
-> at run time. Because of this strict mode every global variables (which include functions) should be prefix by '_'.
-> Note that LUA require an initialisation value for every variables and declaring something like "local myvar" wont
-> allocate "myvar"
-
-### Debugging Facilities
-
-Controller Lua script are check for syntax from CMAKE template with Luac. When needed to go further an developer API allow to
-execute directly Lua command within controller context from Rest/Ws (api=control, verb=lua_doscript). DoScript API takes two
-other optional arguments func=xxxx where xxxx is the function to execute within Lua script and args a JSON object to provide
-input parameter. When funcname is not given by default the controller try to execute middle filename doscript-xxxx-????.lua.
-
-When executed from controller Lua script may use any AppFw Apis as well as any L2C user defined commands in plugin.
-
-### Running as Standalone Controller
-
-Controller is a standard binding and can then be started independently of AAAA. When started with from build repository with
+3) Declare your controller config section in your binding
+```
+// CtlSectionT syntax:
+// key: "section name in config file"
+// loadCB: callback to process section
+// handle: a void* pass to callback when processing section
+static CtlSectionT ctlSections[]= {
+ {.key="plugins" , .loadCB= PluginConfig, .handle= &halCallbacks},
+ {.key="onload" , .loadCB= OnloadConfig},
+ {.key="halmap" , .loadCB= MapConfigLoad},
+ {.key=NULL}
+};
-```bash
-afb-daemon --port=1234 --workdir=. --roothttp=../htdocs --tracereq=common --token= --verbose --binding=./Controller-afb/afb-control-afb.so
```
-Afb-Daemon only load controller bindings without search for the other binding. In this case the name of the process is not change
-to afb-audio and controller binding will search for a configuration file name 'onload-daemon-xxx.json'. This model can be used
-to implement for testing purpose or simply to act as the glue in between a UI and other binder/services.
+3) Do controller config parsing at binding pre-init
+```
+ // check if config file exist
+ const char *dirList= getenv("CTL_CONFIG_PATH");
+ if (!dirList) dirList=CONTROL_CONFIG_PATH;
-## Config Sample
+ ctlConfig = CtlConfigLoad(dirList, ctlSections);
+ if (!ctlConfig) goto OnErrorExit;
+```
-Here after a simple configuration sample.
+4) Exec controller config during binding init
+```
+ int err = CtlConfigExec (ctlConfig);
+```
-```json
-{
- "$schema": "ToBeDone",
- "metadata": {
- "label": "sample-audio-control",
- "info": "Provide Default Audio Policy for Multimedia, Navigation and Emergency",
- "version": "1.0"
- },
- "onload": [{
- "label": "onload-default",
- "info": "onload initialisation config",
- "plugin": {
- "label" : "MyPlug",
- "sharelib": "ctl-audio-plugin-sample.ctlso",
- "lua2c": ["Lua2cHelloWorld1", "Lua2cHelloWorld2"]
- },
- "require": ["intel-hda", "jabra-usb", "scarlett-usb"],
- "actions": [
- {
- "label": "onload-sample-cb",
- "info": "Call control sharelib install entrypoint",
- "callback": "SamplePolicyInit",
- "args": {
- "arg1": "first_arg",
- "nextarg": "second arg value"
- }
- }, {
- "label": "onload-sample-api",
- "info": "Assert AlsaCore Presence",
- "api": "alsacore",
- "verb": "ping",
- "args": "test"
- }, {
- "label": "onload-hal-lua",
- "info": "Load avaliable HALs",
- "lua": "Audio_Init_Hal"
- }
- ]
- }],
- "controls":
- [
- {
- "label": "multimedia",
- "permissions": "urn:AGL:permission:audio:public:mutimedia",
- "actions": {
- "label": "multimedia-control-lua",
- "info": "Call Lua Script function Test_Lua_Engin",
- "lua": "Audio_Set_Multimedia"
- }
- }, {
- "label": "navigation",
- "permissions": "urn:AGL:permission:audio:public:navigation",
- "actions": {
- "label": "navigation-control-lua",
- "info": "Call Lua Script to set Navigation",
- "lua": "Audio_Set_Navigation"
- }
- }, {
- "label": "emergency",
- "permissions": "urn:AGL:permission:audio:public:emergency",
- "actions": {
- "label": "emergency-control-ucm",
- "lua": "Audio_Set_Emergency"
- }
- }, {
- "label": "multi-step-sample",
- "info" : "all actions must succeed for control to be accepted",
- "actions": [{
- "label": "multimedia-control-cb",
- "info": "Call Sharelib Sample Callback",
- "callback": "sampleControlNavigation",
- "args": {
- "arg1": "snoopy",
- "arg2": "toto"
- }
- }, {
- "label": "navigation-control-ucm",
- "api": "alsacore",
- "verb": "ping",
- "args": {
- "test": "navigation"
- }
- }, {
- "label": "navigation-control-lua",
- "info": "Call Lua Script to set Navigation",
- "lua": "Audio_Set_Navigation"
- }]
- }
- ],
- "events":
- [
- {
- "label": "Vehicle-Speed",
- "info": "Action when Vehicle speed change",
- "actions": [
- {
- "label": "speed-action-1",
- "callback": "Blink-when-over-130",
- "args": {
- "speed": 130
- "blink-speed": 1000
- }
- }, {
- "label": "Adjust-Volume",
- "lua": "Adjust_Volume_To_Speed",
- }
- ]
- },
- {
- "label": "Reverse-Engage",
- "info": "When Reverse Gear is Engage",
- "actions": [
- {
- "label": "Display-Rear-Camera",
- "callback": "Display-Rear-Camera",
- }, {
- "label": "Prevent-Phone-Call",
- "api" : "phone",
- "verb" : "status",
- "args": {
- "call-accepted": false
- }
- }
- ]
- },
- {
- "label": "Neutral-Engage",
- "info": "When Reverse Neutral is Engage",
- "actions": [
- {
- "label": "Authorize-Video",
- "api" : "video",
- "verb" : "status",
- "args": {
- "tv-accepted": true
- }
- }
- ]
- }
- ]
-}
+For sample usage look at https://github.com/iotbzh/afb-controller
-```
diff --git a/afb-utilities b/afb-utilities
deleted file mode 160000
-Subproject 55f0a986d2c819731e45e5612dfc76a5d1ca76c
diff --git a/conf.d/CMakeLists.txt b/conf.d/CMakeLists.txt
deleted file mode 100644
index 28a0609..0000000
--- a/conf.d/CMakeLists.txt
+++ /dev/null
@@ -1,22 +0,0 @@
-###########################################################################
-# Copyright 2015, 2016, 2017 IoT.bzh
-#
-# author: Fulup Ar Foll <fulup@iot.bzh>
-#
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-###########################################################################
-
-
-# Include any directory not starting with _
-# -----------------------------------------------------
-PROJECT_SUBDIRS_ADD(${PROJECT_SRC_DIR_PATTERN})
diff --git a/conf.d/app-templates b/conf.d/app-templates
deleted file mode 160000
-Subproject b5fb4364e02d4d3db339e966c69cbe1177f4f52
diff --git a/conf.d/autobuild/agl/autobuild b/conf.d/autobuild/agl/autobuild
deleted file mode 100755
index 4811441..0000000
--- a/conf.d/autobuild/agl/autobuild
+++ /dev/null
@@ -1,63 +0,0 @@
-#!/usr/bin/make -f
-# Copyright (C) 2015, 2016 "IoT.bzh"
-# Author "Romain Forlot" <romain.forlot@iot.bzh>
-#
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-
-THISFILE := $(lastword $(MAKEFILE_LIST))
-BUILD_DIR := $(abspath $(dir $(THISFILE)/../../../../..)/build)
-DEST := ${BUILD_DIR}/target
-
-.PHONY: all clean distclean configure build package help update
-
-all: help
-
-help:
- @echo "List of targets available:"
- @echo ""
- @echo "- all"
- @echo "- clean"
- @echo "- distclean"
- @echo "- configure"
- @echo "- build"
- @echo "- package"
- @echo ""
- @echo "Usage: ./conf.d/autobuild/agl/autobuild package DEST=${HOME}/opt"
- @echo "Don't use your build dir as DEST as wgt file is generated at this location"
-
-update: configure
- @cmake --build ${BUILD_DIR} --target autobuild
-
-clean:
- @([ -d ${BUILD_DIR} ] && make -C ${BUILD_DIR} clean) || echo Nothing to clean
-
-distclean:
- @rm -rf ${BUILD_DIR}
-
-configure: ${BUILD_DIR}/Makefile
-
-build: configure
- @cmake --build ${BUILD_DIR} ${BUILD_ARGS} --target all
-
-package: build
- @mkdir -p ${BUILD_DIR}/$@/bin
- @mkdir -p ${BUILD_DIR}/$@/etc
- @mkdir -p ${BUILD_DIR}/$@/lib
- @mkdir -p ${BUILD_DIR}/$@/htdocs
- @mkdir -p ${BUILD_DIR}/$@/data
- @cmake --build ${BUILD_DIR} --target widget
- @mkdir -p ${DEST} && cp ${BUILD_DIR}/*wgt ${DEST}
-
-${BUILD_DIR}/Makefile:
- @[ -d ${BUILD_DIR} ] || mkdir -p ${BUILD_DIR}
- @[ -f ${BUILD_DIR}/Makefile ] || (cd ${BUILD_DIR} && cmake ${CONFIGURE_ARGS} ..)
diff --git a/conf.d/autobuild/linux/autobuild b/conf.d/autobuild/linux/autobuild
deleted file mode 100755
index 4811441..0000000
--- a/conf.d/autobuild/linux/autobuild
+++ /dev/null
@@ -1,63 +0,0 @@
-#!/usr/bin/make -f
-# Copyright (C) 2015, 2016 "IoT.bzh"
-# Author "Romain Forlot" <romain.forlot@iot.bzh>
-#
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-
-THISFILE := $(lastword $(MAKEFILE_LIST))
-BUILD_DIR := $(abspath $(dir $(THISFILE)/../../../../..)/build)
-DEST := ${BUILD_DIR}/target
-
-.PHONY: all clean distclean configure build package help update
-
-all: help
-
-help:
- @echo "List of targets available:"
- @echo ""
- @echo "- all"
- @echo "- clean"
- @echo "- distclean"
- @echo "- configure"
- @echo "- build"
- @echo "- package"
- @echo ""
- @echo "Usage: ./conf.d/autobuild/agl/autobuild package DEST=${HOME}/opt"
- @echo "Don't use your build dir as DEST as wgt file is generated at this location"
-
-update: configure
- @cmake --build ${BUILD_DIR} --target autobuild
-
-clean:
- @([ -d ${BUILD_DIR} ] && make -C ${BUILD_DIR} clean) || echo Nothing to clean
-
-distclean:
- @rm -rf ${BUILD_DIR}
-
-configure: ${BUILD_DIR}/Makefile
-
-build: configure
- @cmake --build ${BUILD_DIR} ${BUILD_ARGS} --target all
-
-package: build
- @mkdir -p ${BUILD_DIR}/$@/bin
- @mkdir -p ${BUILD_DIR}/$@/etc
- @mkdir -p ${BUILD_DIR}/$@/lib
- @mkdir -p ${BUILD_DIR}/$@/htdocs
- @mkdir -p ${BUILD_DIR}/$@/data
- @cmake --build ${BUILD_DIR} --target widget
- @mkdir -p ${DEST} && cp ${BUILD_DIR}/*wgt ${DEST}
-
-${BUILD_DIR}/Makefile:
- @[ -d ${BUILD_DIR} ] || mkdir -p ${BUILD_DIR}
- @[ -f ${BUILD_DIR}/Makefile ] || (cd ${BUILD_DIR} && cmake ${CONFIGURE_ARGS} ..)
diff --git a/conf.d/cmake/00-debian-specific.cmake b/conf.d/cmake/00-debian-specific.cmake
deleted file mode 100644
index dbdcdca..0000000
--- a/conf.d/cmake/00-debian-specific.cmake
+++ /dev/null
@@ -1,3 +0,0 @@
-list(APPEND PKG_REQUIRED_LIST lua-5.3>=5.3)
-set (EXTRA_REQUIRED_LIST lua5.3)
-set(LUA_CHECKER "luac5.3" "-p" CACHE STRING "LUA compiler")
diff --git a/conf.d/cmake/00-default-osconfig.cmake b/conf.d/cmake/00-default-osconfig.cmake
deleted file mode 100644
index a2b9325..0000000
--- a/conf.d/cmake/00-default-osconfig.cmake
+++ /dev/null
@@ -1 +0,0 @@
-list(APPEND PKG_REQUIRED_LIST lua>=5.3)
diff --git a/conf.d/cmake/config.cmake b/conf.d/cmake/config.cmake
deleted file mode 100644
index c331a81..0000000
--- a/conf.d/cmake/config.cmake
+++ /dev/null
@@ -1,237 +0,0 @@
-###########################################################################
-# Copyright 2015, 2016, 2017 IoT.bzh
-#
-# author: Fulup Ar Foll <fulup@iot.bzh>
-#
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-###########################################################################
-
-# Project Info
-# ------------------
-set(PROJECT_NAME afb-controller)
-set(PROJECT_VERSION "1.0")
-set(PROJECT_PRETTY_NAME "Controller Binding for AGL Application Framework")
-set(PROJECT_DESCRIPTION "Create controls that could be mapped to LUA functions, callback or API/VERB methods.")
-set(PROJECT_URL "https://github.com/iotbzh/controller-binding")
-set(PROJECT_ICON "icon.png")
-set(PROJECT_AUTHOR "Fulup Ar Foll")
-set(PROJECT_AUTHOR_MAIL "fulup@iot.bzh")
-set(PROJECT_LICENSE "APL2.0")
-set(PROJECT_LANGUAGES,"C")
-
-# Where are stored default templates files from submodule or subtree app-templates in your project tree
-# relative to the root project directory
-set(PROJECT_APP_TEMPLATES_DIR "conf.d/app-templates")
-
-# Where are stored your external libraries for your project. This is 3rd party library that you don't maintain
-# but used and must be built and linked.
-# set(PROJECT_LIBDIR "libs")
-
-# Where are stored data for your application. Pictures, static resources must be placed in that folder.
-# set(PROJECT_RESOURCES "data")
-
-# Which directories inspect to find CMakeLists.txt target files
-# set(PROJECT_SRC_DIR_PATTERN "*")
-
-# Compilation Mode (DEBUG, RELEASE)
-# ----------------------------------
-set(CMAKE_BUILD_TYPE "DEBUG")
-
-# Kernel selection if needed. You can choose between a
-# mandatory version to impose a minimal version.
-# Or check Kernel minimal version and just print a Warning
-# about missing features and define a preprocessor variable
-# to be used as preprocessor condition in code to disable
-# incompatibles features. Preprocessor define is named
-# KERNEL_MINIMAL_VERSION_OK.
-#
-# NOTE*** FOR NOW IT CHECKS KERNEL Yocto environment and
-# Yocto SDK Kernel version.
-# -----------------------------------------------
-#set (kernel_mandatory_version 4.8)
-#set (kernel_minimal_version 4.8)
-
-# Compiler selection if needed. Impose a minimal version.
-# -----------------------------------------------
-set (gcc_minimal_version 4.9)
-
-# PKG_CONFIG required packages
-# -----------------------------
-set (PKG_REQUIRED_LIST
- json-c
- libsystemd>=222
- afb-daemon
- libmicrohttpd>=0.9.55
- libafbwsc
-)
-
-# EXTRA required packages
-# -----------------------------
-#set (EXTRA_REQUIRED_LIST a_package)
-
-# Prefix path where will be installed the files
-# Default: /usr/local (need root permission to write in)
-# ------------------------------------------------------
-set(CMAKE_INSTALL_PREFIX $ENV{HOME}/opt)
-
-# Customize link option
-# -----------------------------
-list(APPEND link_libraries -ldl)
-
-# When Present LUA is used by the controller
-# ---------------------------------------------------------------
-set(CONTROL_SUPPORT_LUA 1 CACHE BOOL "Active or not LUA Support")
-
-# Controller project needed variables.
-# Compilation options specific to that target set
-# in the CMakeLists.txt of that target to correctly
-# expand variables.
-# ----------------------------------------------------
-set (CTL_PLUGIN_PRE "ctl-" CACHE STRING "Prefix for Controller share plugin")
-set (CTL_PLUGIN_EXT ".ctlso" CACHE STRING "Postfix for Controller share plugin")
-
-# Compilation options definition
-# Use CMake generator expressions to specify only for a specific language
-# Values are prefilled with default options that is currently used.
-# Either separate options with ";", or each options must be quoted separately
-# DO NOT PUT ALL OPTION QUOTED AT ONCE , COMPILATION COULD FAILED !
-# ----------------------------------------------------------------------------
-set(COMPILE_OPTIONS
--Wall
--Wextra
--Wconversion
--Wno-unused-parameter
--Wno-sign-compare
--Wno-sign-conversion
--Werror=maybe-uninitialized
--Werror=implicit-function-declaration
--ffunction-sections
--fdata-sections
--fPIC
-# Personal compilation options
--DCONTROL_MAXPATH_LEN=255
--DCONTROL_ONLOAD_PROFILE="onload-default"
--DCONTROL_DOSCRIPT_PRE="doscript"
--DCONTROL_CONFIG_PRE="onload"
--DCONTROL_CONFIG_POST="control"
--DCONTROL_CONFIG_PATH="${CMAKE_SOURCE_DIR}/conf.d/project/json.d:${CMAKE_INSTALL_PREFIX}/${PROJECT_NAME}/json.d"
--DCTL_PLUGIN_MAGIC=2468013579
--DCONTROL_PLUGIN_PATH="${CMAKE_BINARY_DIR}:${CMAKE_INSTALL_PREFIX}/${PROJECT_NAME}/lib/controller-plugins:/usr/lib/afb/controller-plugins/ctlplug"
- CACHE STRING "Compilation flags")
-#set(C_COMPILE_OPTIONS "" CACHE STRING "Compilation flags for C language.")
-#set(CXX_COMPILE_OPTIONS "" CACHE STRING "Compilation flags for C++ language.")
-#set(PROFILING_COMPILE_OPTIONS
-# -g
-# -O0
-# -pg
-# -Wp,-U_FORTIFY_SOURCE
-# CACHE STRING "Compilation flags for PROFILING build type.")
-#set(DEBUG_COMPILE_OPTIONS
-# -g
-# -ggdb
-# -Wp,-U_FORTIFY_SOURCE
-# CACHE STRING "Compilation flags for DEBUG build type.")
-#set(CCOV_COMPILE_OPTIONS
-# -g
-# -O2
-# --coverage
-# CACHE STRING "Compilation flags for CCOV build type.")
-#set(RELEASE_COMPILE_OPTIONS
-# -g
-# -O2
-# CACHE STRING "Compilation flags for RELEASE build type.")
-
-# Print a helper message when every thing is finished
-# ----------------------------------------------------
-if(IS_DIRECTORY $ENV{HOME}/opt/afb-monitoring)
-set(MONITORING_ALIAS "--alias=/monitoring:$ENV{HOME}/opt/afb-monitoring")
-endif()
-set(CLOSING_MESSAGE "Debug from afb-daemon --port=1234 ${MONITORING_ALIAS} --ldpaths=. --workdir=. --roothttp=../htdocs --tracereq=common --token= --verbose ")
-set(PACKAGE_MESSAGE "Install widget file using in the target : afm-util install ${PROJECT_NAME}.wgt")
-
-# (BUG!!!) as PKG_CONFIG_PATH does not work [should be an env variable]
-# ---------------------------------------------------------------------
-set(CMAKE_PREFIX_PATH ${CMAKE_INSTALL_PREFIX}/lib64/pkgconfig ${CMAKE_INSTALL_PREFIX}/lib/pkgconfig)
-set(LD_LIBRARY_PATH ${CMAKE_INSTALL_PREFIX}/lib64 ${CMAKE_INSTALL_PREFIX}/lib)
-
-# Optional location for config.xml.in
-# -----------------------------------
-set(WIDGET_ICON conf.d/wgt/${PROJECT_ICON} CACHE PATH "Path to the widget icon")
-set(WIDGET_CONFIG_TEMPLATE ${CMAKE_CURRENT_SOURCE_DIR}/conf.d/wgt/config.xml.in CACHE PATH "Path to widget config file template (config.xml.in)")
-
-# Mandatory widget Mimetype specification of the main unit
-# --------------------------------------------------------------------------
-# Choose between :
-#- text/html : HTML application,
-# content.src designates the home page of the application
-#
-#- application/vnd.agl.native : AGL compatible native,
-# content.src designates the relative path of the binary.
-#
-# - application/vnd.agl.service: AGL service, content.src is not used.
-#
-#- ***application/x-executable***: Native application,
-# content.src designates the relative path of the binary.
-# For such application, only security setup is made.
-#
-set(WIDGET_TYPE application/vnd.agl.service)
-
-# Mandatory Widget entry point file of the main unit
-# --------------------------------------------------------------
-# This is the file that will be executed, loaded,
-# at launch time by the application framework.
-#
-set(WIDGET_ENTRY_POINT lib/afb-control-afb.so)
-
-# Optional dependencies order
-# ---------------------------
-#set(EXTRA_DEPENDENCIES_ORDER)
-
-# Optional Extra global include path
-# -----------------------------------
-#set(EXTRA_INCLUDE_DIRS)
-
-# Optional extra libraries
-# -------------------------
-#set(EXTRA_LINK_LIBRARIES)
-
-# Optional force binding Linking flag
-# ------------------------------------
-# set(BINDINGS_LINK_FLAG LinkOptions )
-
-# Optional force package prefix generation, like widget
-# -----------------------------------------------------
-# set(PKG_PREFIX DestinationPath)
-
-# Optional Application Framework security token
-# and port use for remote debugging.
-#------------------------------------------------------------
-#set(AFB_TOKEN "" CACHE PATH "Default AFB_TOKEN")
-#set(AFB_REMPORT "1234" CACHE PATH "Default AFB_TOKEN")
-
-# Print a helper message when every thing is finished
-# ----------------------------------------------------
-set(CLOSING_MESSAGE "Typical binding launch: afb-daemon --port=${AFB_REMPORT} --workdir=${CMAKE_BINARY_DIR}/package --ldpaths=lib --roothttp=htdocs --token=\"${AFB_TOKEN}\" --tracereq=common --verbose")
-set(PACKAGE_MESSAGE "Install widget file using in the target : afm-util install ${PROJECT_NAME}.wgt")
-
-# Optional schema validator about now only XML, LUA and JSON
-# are supported
-#------------------------------------------------------------
-#set(LUA_CHECKER "luac" "-p" CACHE STRING "LUA compiler")
-#set(XML_CHECKER "xmllint" CACHE STRING "XML linter")
-#set(JSON_CHECKER "json_verify" CACHE STRING "JSON linter")
-
-# This include is mandatory and MUST happens at the end
-# of this file, else you expose you to unexpected behavior
-# -----------------------------------------------------------
-include(${PROJECT_APP_TEMPLATES_DIR}/cmake/common.cmake)
diff --git a/conf.d/packaging/agl-afb-controller.dsc b/conf.d/packaging/agl-afb-controller.dsc
deleted file mode 100644
index 7ee03d6..0000000
--- a/conf.d/packaging/agl-afb-controller.dsc
+++ /dev/null
@@ -1,21 +0,0 @@
-Format: 1.0
-Source: agl-afb-controller
-Binary: agl-afb-controller-bin
-Architecture: any
-Version: 2.0-0
-Maintainer: Fulup Ar Foll <fulup@iot.bzh>
-Standards-Version: 3.8.2
-Homepage: https://github.com/iotbzh/controller-binding
-Build-Depends: debhelper (>= 5),
- pkg-config,
- cmake,
- gcc,
- g++,
- libjson-c-dev ,
- libsystemd-dev (>= 222),
- agl-app-framework-binder-dev ,
- agl-libmicrohttpd-dev (>= 0.9.55),
- agl-app-framework-binder-dev ,
- liblua5.3-dev (>= 5.3),
- lua5.3
-Debtransform-Tar: agl-afb-controller_1.0.orig.tar.gz
diff --git a/conf.d/packaging/agl-afb-controller.spec b/conf.d/packaging/agl-afb-controller.spec
deleted file mode 100644
index a3e9478..0000000
--- a/conf.d/packaging/agl-afb-controller.spec
+++ /dev/null
@@ -1,68 +0,0 @@
-###########################################################################
-# Copyright 2015, 2016, 2017 IoT.bzh
-#
-# author: Fulup Ar Foll <fulup@iot.bzh>
-#
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-###########################################################################
-
-
-Name: agl-afb-controller
-Version: 1.0
-Release: 1
-Group: AGL
-License: APL2.0
-Summary: Create controls that could be mapped to LUA functions, callback or API/VERB methods.
-Url: https://github.com/iotbzh/controller-binding
-Source0: %{name}_%{version}.orig.tar.gz
-
-BuildRequires: cmake
-BuildRequires: gcc gcc-c++
-BuildRequires: pkgconfig(json-c)
-BuildRequires: pkgconfig(libsystemd) >= 222
-BuildRequires: pkgconfig(afb-daemon)
-BuildRequires: pkgconfig(libmicrohttpd) >= 0.9.55
-BuildRequires: pkgconfig(libafbwsc)
-BuildRequires: pkgconfig(lua) >= 5.3
-
-
-BuildRoot: %{_tmppath}/%{name}-%{version}-build
-
-%define _prefix /opt/AGL/afb-controller
-%define __cmake cmake
-
-%description
-Create controls that could be mapped to LUA functions, callback or API/VERB methods.
-
-%prep
-%setup -q
-
-%build
-%cmake -DCMAKE_INSTALL_PREFIX:PATH=%{_libdir}
-make %{?_smp_mflags}
-
-%install
-CURDIR=$(pwd)
-[ -d build ] && cd build
-make populate
-mkdir -p %{?buildroot}%{_prefix}
-cp -r package/* %{?buildroot}%{_prefix}
-
-cd $CURDIR
-find %{?buildroot}%{_prefix} -type d -exec echo "%dir {}" \;>> pkg_file
-find %{?buildroot}%{_prefix} -type f -exec echo "{}" \;>> pkg_file
-sed -i 's@%{?buildroot}@@g' pkg_file
-
-
-%files -f pkg_file
-%defattr(-,root,root)
diff --git a/conf.d/packaging/debian.agl-afb-controller.install b/conf.d/packaging/debian.agl-afb-controller.install
deleted file mode 100644
index 5858efd..0000000
--- a/conf.d/packaging/debian.agl-afb-controller.install
+++ /dev/null
@@ -1,2 +0,0 @@
-/opt/AGL/*
-/etc/profile.d/*
diff --git a/conf.d/packaging/debian.changelog b/conf.d/packaging/debian.changelog
deleted file mode 100644
index a97aeb1..0000000
--- a/conf.d/packaging/debian.changelog
+++ /dev/null
@@ -1,5 +0,0 @@
-agl-afb-controller (1.0-0) UNRELEASED; urgency=low
-
- * init build
-
- -- Fulup Ar Foll <fulup@iot.bzh> Mon, 25 Dec 2007 10:50:38 +0100
diff --git a/conf.d/packaging/debian.compat b/conf.d/packaging/debian.compat
deleted file mode 100644
index 45a4fb7..0000000
--- a/conf.d/packaging/debian.compat
+++ /dev/null
@@ -1 +0,0 @@
-8
diff --git a/conf.d/packaging/debian.control b/conf.d/packaging/debian.control
deleted file mode 100644
index 80c2931..0000000
--- a/conf.d/packaging/debian.control
+++ /dev/null
@@ -1,22 +0,0 @@
-Priority: optional
-Maintainer: Fulup Ar Foll <fulup@iot.bzh>
-Source: agl-afb-controller
-Build-Depends: debhelper (>= 5),
- pkg-config,
- cmake,
- gcc,
- g++,
- libjson-c-dev ,
- libsystemd-dev (>= 222),
- agl-app-framework-binder-dev ,
- agl-libmicrohttpd-dev (>= 0.9.55),
- agl-app-framework-binder-dev ,
- liblua5.3-dev (>= 5.3),
- lua5.3
-Standards-Version: 3.8.2
-Homepage: https://github.com/iotbzh/controller-binding
-
-Package: agl-afb-controller
-Section: libs
-Architecture: any
-Description: Create controls that could be mapped to LUA functions, callback or API/VERB methods.
diff --git a/conf.d/packaging/debian.rules b/conf.d/packaging/debian.rules
deleted file mode 100644
index fb3c060..0000000
--- a/conf.d/packaging/debian.rules
+++ /dev/null
@@ -1,87 +0,0 @@
-#!/usr/bin/make -f
-# -*- makefile -*-
-# Uncomment this to turn on verbose mode.
-export DH_VERBOSE=1
-
-# These are used for cross-compiling and for saving the configure script
-# from having to guess our platform (since we know it already)
-DEB_HOST_GNU_TYPE ?= $(shell dpkg-architecture -qDEB_HOST_GNU_TYPE)
-DEB_BUILD_GNU_TYPE ?= $(shell dpkg-architecture -qDEB_BUILD_GNU_TYPE)
-
-
-CFLAGS = -Wall -g
-
-ifneq (,$(findstring noopt,$(DEB_BUILD_OPTIONS)))
- CFLAGS += -O0
-else
- CFLAGS += -O2
-endif
-ifeq (,$(findstring nostrip,$(DEB_BUILD_OPTIONS)))
- INSTALL_PROGRAM += -s
-endif
-
-configure: configure-stamp
-configure-stamp:
- dh_testdir
- #
- touch configure-stamp
-
-build: build-stamp
-build-stamp: configure-stamp
- dh_testdir
- mkdir -p build
- cd build;cmake ../ -DCMAKE_INSTALL_PREFIX:PATH=/opt/AGL/afb-controller -DCMAKE_INSTALL_LIBDIR:PATH=lib/$(DEB_HOST_MULTIARCH);$(MAKE)
- #
- touch build-stamp
-
-clean:
- #dh_testdir
- dh_testroot
- rm -f configure-stamp build-stamp
- [ ! -f Makefile ] || $(MAKE) distclean
- #dh_clean
-
-install: build
- dh_testdir
- dh_testroot
- dh_prep
- dh_installdirs
- # Add here commands to install the package into debian/tmp
- mkdir -p debian/tmp/opt/AGL/afb-controller;cd build;make populate;cp -r package/* ../debian/tmp/opt/AGL/afb-controller/
- mkdir -p debian/tmp/etc/profile.d
- echo '#---------- AGL afb-controller options Start ---------" ' > debian/tmp/etc/profile.d/AGL_afb-controller.sh
- echo '# Object: AGL cmake option for binder/bindings' >> debian/tmp/etc/profile.d/AGL_afb-controller.sh
- echo 'export LD_LIBRARY_PATH=/opt/AGL/afb-controller/lib/$(DEB_HOST_MULTIARCH):$$LD_LIBRARY_PATH' >> debian/tmp/etc/profile.d/AGL_afb-controller.sh
- echo 'export LIBRARY_PATH=/opt/AGL/afb-controller/lib/$(DEB_HOST_MULTIARCH):$$LIBRARY_PATH' >> debian/tmp/etc/profile.d/AGL_afb-controller.sh
- echo 'export PATH=/opt/AGL/afb-controller/bin:$$PATH' >> debian/tmp/etc/profile.d/AGL_afb-controller.sh
- echo '#---------- AGL options End ---------' >> debian/tmp/etc/profile.d/AGL_afb-controller.sh
- # Move all files in their corresponding package
- dh_install --list-missing -s --sourcedir=debian/tmp
- # empty dependency_libs in .la files
- #sed -i "/dependency_libs/ s/'.*'/''/" `find debian/ -name '*.la'`
-
-# Build architecture-independent files here.
-binary-indep: build install
-# We have nothing to do by default.
-
-# Build architecture-dependent files here.
-binary-arch: build install
- dh_testdir
- dh_testroot
- dh_installchangelogs
- dh_installdocs
- dh_installexamples
- dh_installman
- dh_link
- dh_strip
- dh_compress
- dh_fixperms
- dh_makeshlibs -V
- dh_installdeb
- dh_shlibdeps --dpkg-shlibdeps-params=--ignore-missing-info
- dh_gencontrol
- dh_md5sums
- dh_builddeb
-
-binary: binary-indep binary-arch
-.PHONY: build clean binary-indep binary-arch binary install
diff --git a/conf.d/project/CMakeLists.txt b/conf.d/project/CMakeLists.txt
deleted file mode 100644
index fd4d454..0000000
--- a/conf.d/project/CMakeLists.txt
+++ /dev/null
@@ -1,24 +0,0 @@
-###########################################################################
-# Copyright 2015, 2016, 2017 IoT.bzh
-#
-# author: Fulup Ar Foll <fulup@iot.bzh>
-#
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-###########################################################################
-
-
-
-# Include anything not starting with _
-PROJECT_SUBDIRS_ADD(${PROJECT_SRC_DIR_PATTERN})
-
-
diff --git a/conf.d/project/json.d/CMakeLists.txt b/conf.d/project/json.d/CMakeLists.txt
deleted file mode 100644
index 8070997..0000000
--- a/conf.d/project/json.d/CMakeLists.txt
+++ /dev/null
@@ -1,32 +0,0 @@
-###########################################################################
-# Copyright 2017 IoT.bzh
-#
-# author: Fulup Ar Foll <fulup@iot.bzh>
-#
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-###########################################################################
-
-
-##################################################
-# Control Policy Config file
-##################################################
-PROJECT_TARGET_ADD(ctl-config.d)
-
- file(GLOB XML_FILES "*.json")
-
- add_input_files("${XML_FILES}")
-
- SET_TARGET_PROPERTIES(${TARGET_NAME} PROPERTIES
- LABELS "DATA"
- OUTPUT_NAME ${TARGET_NAME}
- )
diff --git a/conf.d/project/json.d/README.md b/conf.d/project/json.d/README.md
deleted file mode 100644
index 209e708..0000000
--- a/conf.d/project/json.d/README.md
+++ /dev/null
@@ -1,23 +0,0 @@
-# Controller binding configuration
-
-By default controller searches for a config filename with the same 'middlename' as daemon process. As an example if your process name is afb-daemon then middle name is 'daemon'.
-
-```bash
-# Middlename is taken from process middlename.
-onload-middlename-xxxxx.json
-```
-
-You may overload config search path with environement variables
-
-* AFB_BINDER_NAME: change patern config search path. 'export AFB_BINDER_NAME=sample' will make controller to search for a configfile name 'onload-sample-xxx.json'.
-* CONTROL_CONFIG_PATH: change default reserch path for configuration. You may provide multiple directories separated by ':'.
-* CONTROL_LUA_PATH: same as CONTROL_CONFIG_PATH but for Lua script files.
-
-Example to load a config name 'onload-myconfig-test.json' do
-
-```bash
- AFB_BINDER_NAME='myconfig' afb-daemon --verbose ...'
-```
-
-Note: you may change search pattern for Lua script by adding 'ctlname=afb-middlename-xxx' in the metadata section of your config 'onload-*.json'
-
diff --git a/conf.d/project/json.d/onload-daemon-sample.json b/conf.d/project/json.d/onload-daemon-sample.json
deleted file mode 100644
index cb6ca55..0000000
--- a/conf.d/project/json.d/onload-daemon-sample.json
+++ /dev/null
@@ -1,69 +0,0 @@
-{
- "$schema": "ToBeDone",
- "metadata": {
- "label": "sample-standalone-control",
- "info": "Minimal Standalone Controller Config",
- "name": "afb-sample-controller",
- "version": "1.0"
- },
- "onload": [{
- "label": "onload-default",
- "info": "onload initialisation config",
- "actions":
- {
- "label": "control-init",
- "lua": "_Sample_Controller_Init",
- "args": {
- "xxxx": 1234,
- "yyyy": "Bien le bonjours à vous",
- "zzzz": "simple-evt"
- }
- }
- }],
- "controls":
- [
- {
- "label": "Button-Happy",
- "actions": {
- "label": "Action Happy",
- "lua": "_Button_Happy",
- "args": {
- "button": 5678
- }
- }
- }, {
- "label": "Button-UnHappy",
- "actions": {
- "label": "Action Unhappy",
- "lua": "_Button_UnHappy",
- "args": {
- "button": "abcd"
- }
- }
- }
- ],
- "events":
- [
- {
- "label": "Event1",
- "actions": {
- "label": "Action Event 1",
- "lua": "_Event_Received",
- "args": {
- "evtname": "xxx"
- }
- }
- },
- {
- "label": "Event2",
- "actions": {
- "label": "Action Event 2",
- "lua": "_Event_Received",
- "args": {
- "evtname": "yyy"
- }
- }
- }
- ]
-}
-
diff --git a/conf.d/project/lua.d/CMakeLists.txt b/conf.d/project/lua.d/CMakeLists.txt
deleted file mode 100644
index 5cd61f2..0000000
--- a/conf.d/project/lua.d/CMakeLists.txt
+++ /dev/null
@@ -1,32 +0,0 @@
-###########################################################################
-# Copyright 2017 IoT.bzh
-#
-# author: Fulup Ar Foll <fulup@iot.bzh>
-#
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-###########################################################################
-
-
-##################################################
-# Control Policy Config file
-##################################################
-PROJECT_TARGET_ADD(ctl-lua.d)
-
- file(GLOB LUA_FILES "*.lua")
-
- add_input_files("${LUA_FILES}")
-
- SET_TARGET_PROPERTIES(${TARGET_NAME} PROPERTIES
- LABELS "DATA"
- OUTPUT_NAME ${TARGET_NAME}
- )
diff --git a/conf.d/project/lua.d/doscript-helloworld.lua b/conf.d/project/lua.d/doscript-helloworld.lua
deleted file mode 100644
index e722db7..0000000
--- a/conf.d/project/lua.d/doscript-helloworld.lua
+++ /dev/null
@@ -1,36 +0,0 @@
---[[
- Copyright (C) 2016 "IoT.bzh"
- Author Fulup Ar Foll <fulup@iot.bzh>
-
- Licensed under the Apache License, Version 2.0 (the "License");
- you may not use this file except in compliance with the License.
- You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
- Unless required by applicable law or agreed to in writing, software
- distributed under the License is distributed on an "AS IS" BASIS,
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- See the License for the specific language governing permissions and
- limitations under the License.
-
-
- Simple API script to be use with AGL control LuaDoCall API
- - After the script is loaded by lua_docall
- - Controller start function=xxxx where xxxx is taken from script filename doscript-xxxx-anything
-
---]]
-
-function _helloworld (request, query)
-
- AFB:notice ("LUA HelloWorld: Simple test query=%s", query);
-
- if (query == nil) then
- AFB:notice ("LUA HelloWorld:FX query should not be empty");
- AFB:fail (request, "LUA HelloWorld: query should not be empty");
- else
- AFB:notice ("LUA HelloWorld:OK query=%s", query);
- AFB:success (request, {arg0="Demat", arg1="Bonjours", arg2="Gootentag", arg3="Morning"});
- end
-
-end
diff --git a/conf.d/project/lua.d/onload-daemon-00-utils.lua b/conf.d/project/lua.d/onload-daemon-00-utils.lua
deleted file mode 100644
index 29d2c70..0000000
--- a/conf.d/project/lua.d/onload-daemon-00-utils.lua
+++ /dev/null
@@ -1,86 +0,0 @@
---[[
- Copyright (C) 2016 "IoT.bzh"
- Author Fulup Ar Foll <fulup@iot.bzh>
-
- Licensed under the Apache License, Version 2.0 (the "License");
- you may not use this file except in compliance with the License.
- You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
- Unless required by applicable law or agreed to in writing, software
- distributed under the License is distributed on an "AS IS" BASIS,
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- See the License for the specific language governing permissions and
- limitations under the License.
-
- Note: this file should be called before any other to assert declare function
- is loaded before anything else.
-
- References:
- http://lua-users.org/wiki/DetectingUndefinedVariables
-
---]]
-
-
---===================================================
---= Niklas Frykholm
--- basically if user tries to create global variable
--- the system will not let them!!
--- call GLOBAL_lock(_G)
---
---===================================================
-function GLOBAL_lock(t)
- local mt = getmetatable(t) or {}
- mt.__newindex = lock_new_index
- setmetatable(t, mt)
-end
-
---===================================================
--- call GLOBAL_unlock(_G)
--- to change things back to normal.
---===================================================
-function GLOBAL_unlock(t)
- local mt = getmetatable(t) or {}
- mt.__newindex = unlock_new_index
- setmetatable(t, mt)
-end
-
-function lock_new_index(t, k, v)
- if (string.sub(k,1,1) ~= "_") then
- GLOBAL_unlock(_G)
- error("GLOBALS are locked -- " .. k ..
- " must be declared local or prefix with '_' for globals.", 2)
- else
- rawset(t, k, v)
- end
-end
-
-function unlock_new_index(t, k, v)
- rawset(t, k, v)
-end
-
--- return serialised version of printable table
-function Dump_Table(o)
- if type(o) == 'table' then
- local s = '{ '
- for k,v in pairs(o) do
- if type(k) ~= 'number' then k = '"'..k..'"' end
- s = s .. '['..k..'] = ' .. Dump_Table(v) .. ','
- end
- return s .. '} '
- else
- return tostring(o)
- end
-end
-
-
--- simulate C prinf function
-printf = function(s,...)
- io.write(s:format(...))
- io.write("\n")
- return
-end
-
--- lock global variable
-GLOBAL_lock(_G)
diff --git a/conf.d/project/lua.d/onload-daemon-01-init.lua b/conf.d/project/lua.d/onload-daemon-01-init.lua
deleted file mode 100644
index 26ff08a..0000000
--- a/conf.d/project/lua.d/onload-daemon-01-init.lua
+++ /dev/null
@@ -1,48 +0,0 @@
---[[
- Copyright (C) 2016 "IoT.bzh"
- Author Fulup Ar Foll <fulup@iot.bzh>
-
- Licensed under the Apache License, Version 2.0 (the "License");
- you may not use this file except in compliance with the License.
- You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
- Unless required by applicable law or agreed to in writing, software
- distributed under the License is distributed on an "AS IS" BASIS,
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- See the License for the specific language governing permissions and
- limitations under the License.
---]]
-
--- Global variable SHOULD start with _
-_Global_Context={}
-
---[[
- This function is call during controller init phase as describe in onload-daemon-sample.json
- It receives two argument 1st one is the source (here on load) second one is the arguments
- as expose in config file.
-
- In this sample we create an event that take the name of args["zzzz"], the resulting handle
- is save into _Global_Context for further use.
-
- Note: init functions are not call from a client and thus do not receive query
-
---]]
-function _Sample_Controller_Init(source, control)
-
- printf ("[-- Sample_Controller_Init --] source=%d control=%s", source, Dump_Table(control))
-
- -- if no argument return now
- if (control==nil or control["zzzz"]==nil) then
- printf ("[-- Sample_Controller_Init --] no event name given")
- return
- end
-
- -- set a count to make more visible each call
- _Global_Context["counter"]=0
-
- -- just for fun create an event
- _Global_Context["event"]=AFB:evtmake(control["zzzz"])
-
-end
diff --git a/conf.d/project/lua.d/onload-daemon-03-controls.lua b/conf.d/project/lua.d/onload-daemon-03-controls.lua
deleted file mode 100644
index e9c8b51..0000000
--- a/conf.d/project/lua.d/onload-daemon-03-controls.lua
+++ /dev/null
@@ -1,47 +0,0 @@
---[[
- Copyright (C) 2016 "IoT.bzh"
- Author Fulup Ar Foll <fulup@iot.bzh>
-
- Licensed under the Apache License, Version 2.0 (the "License");
- you may not use this file except in compliance with the License.
- You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
- Unless required by applicable law or agreed to in writing, software
- distributed under the License is distributed on an "AS IS" BASIS,
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- See the License for the specific language governing permissions and
- limitations under the License.
-
- Following function are called when a client activate a control with
- controller api -> APi=control VERB=dispatch
- arguments are
- - source (0) when requesting the control (-1) when releasing
- - control comme from config given with 'args' in onload-middlename-xxxxx.json
- - client is the argument part of the query as providing by client requesting the control.
-
---]]
-
-
-
--- Simple Happy(granted) Control
-function _Button_Happy(source, control, client)
-
- -- print argument to make sure we understant what we get
- printf ("[-- _Button_Happy --] source=%d control=%s client=%s", source, Dump_Table(client), Dump_Table(control))
-
- AFB:notice ("[-- _Button_Happy --] To Be Done")
- return 0 -- control granted
-end
-
-
--- Simple UnHappy(debu) Control
-function _Button_UnHappy(source, control, client)
-
- -- print argument to make sure we understant what we get
- printf ("[-- _Button_UnHappy --] source=%d control=%s client=%s", source, Dump_Table(client), Dump_Table(control))
-
- AFB:error ("[-- _Button_UnHappy --] To Be Done")
- return 1 -- control is refused
-end
diff --git a/conf.d/project/lua.d/onload-daemon-04-oncall.lua b/conf.d/project/lua.d/onload-daemon-04-oncall.lua
deleted file mode 100644
index b450932..0000000
--- a/conf.d/project/lua.d/onload-daemon-04-oncall.lua
+++ /dev/null
@@ -1,70 +0,0 @@
---[[
- Copyright (C) 2016 "IoT.bzh"
- Author Fulup Ar Foll <fulup@iot.bzh>
-
- Licensed under the Apache License, Version 2.0 (the "License");
- you may not use this file except in compliance with the License.
- You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
- Unless required by applicable law or agreed to in writing, software
- distributed under the License is distributed on an "AS IS" BASIS,
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- See the License for the specific language governing permissions and
- limitations under the License.
-
-
- Provide sample LUA routines to be used with AGL control "lua_docall" API
---]]
-
---global counter to keep track of calls
-_count=0
-
--- Display receive arguments and echo them to caller
-function _Simple_Echo_Args (request, args)
- _count=_count+1
- AFB:notice("LUA OnCall Echo Args count=%d args=%s", count, args)
-
- print ("--inlua-- args=", Dump_Table(args))
-
- local response={
- ["count"]=_count,
- ["args"]=args,
- }
-
- -- fulup Embdeded table ToeDone AFB:success (request, response)
- AFB:success (request, {["func"]="Simple_Echo_Args", ["ret1"]=5678, ["ret2"]="abcd"})
-end
-
-local function Test_Async_CB (request, result, context)
- response={
- ["result"]=result,
- ["context"]=context,
- }
-
- AFB:notice ("Test_Async_CB result=%s context=%s", result, context)
- AFB:success (request, response)
-end
-
-function _Test_Call_Async (request, args)
- local context={
- ["value1"]="abcd",
- ["value2"]=1234
- }
-
- AFB:notice ("Test_Call_Async args=%s cb=Test_Async_CB", args)
- AFB:service("monitor","ping", "Test_Async_CB", context)
-end
-
-function _Simple_Monitor_Call (request, args)
-
- AFB:notice ("_Simple_Server_Call args=%s", args)
- local err, result= AFB:servsync ("monitor","get", args)
- if (err) then
- AFB:fail ("AFB:service_call_sync fail");
- else
- AFB:success (request, result["response"])
- end
-end
-
diff --git a/conf.d/project/lua.d/onload-daemon-10-event.lua b/conf.d/project/lua.d/onload-daemon-10-event.lua
deleted file mode 100644
index 474ebe0..0000000
--- a/conf.d/project/lua.d/onload-daemon-10-event.lua
+++ /dev/null
@@ -1,74 +0,0 @@
---[[
- Copyright (C) 2016 "IoT.bzh"
- Author Fulup Ar Foll <fulup@iot.bzh>
-
- Licensed under the Apache License, Version 2.0 (the "License");
- you may not use this file except in compliance with the License.
- You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
- Unless required by applicable law or agreed to in writing, software
- distributed under the License is distributed on an "AS IS" BASIS,
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- See the License for the specific language governing permissions and
- limitations under the License.
-
-
- Provide Sample Timer Handing to push event from LUA
---]]
-
--- Create event on Lua script load
-_MyContext={}
-
--- WARNING: call back are global and should start with '_'
-function _Timer_Test_CB (timer, context)
-
- local evtinfo= AFB:timerget(timer)
- printf ("[-- _Timer_Test_C --] evtInfo=%s", Dump_Table(evtinfo))
-
- --send an event an event with count as value
- AFB:evtpush (_MyContext["event"], {["label"]= evtinfo["label"], ["count"]=evtinfo["count"], ["info"]=context["info"]})
-
- -- note when timerCB return!=0 timer is kill
- return 0
-
-end
-
--- sendback event depending on count and delay
-function _Simple_Timer_Test (request, client)
-
- local context = {
- ["info"]="My 1st private Event",
- }
-
- -- if event does not exit create it now.
- if (_MyContext["event"] == nil) then
- _MyContext["event"]= AFB:evtmake(client["label"])
- end
-
- -- if delay not defined default is 5s
- if (client["delay"]==nil) then client["delay"]=5000 end
-
- -- if count is not defined default is 10
- if (client["count"]==nil) then client["count"]=10 end
-
- -- we could use directly client but it is a sample
- local myTimer = {
- ["label"]=client["label"],
- ["delay"]=client["delay"],
- ["count"]=client["count"],
- }
- AFB:notice ("Test_Timer myTimer=%s", myTimer)
-
- -- subscribe to event
- AFB:subscribe (request, _MyContext["event"])
-
- -- settimer take a table with delay+count as input (count==0 means infinite)
- AFB:timerset (myTimer, "_Timer_Test_CB", context)
-
- -- nothing special to return send back
- AFB:success (request, myTimer)
-
- return 0
-end
diff --git a/conf.d/project/vscode.d/c_cpp_properties.json b/conf.d/project/vscode.d/c_cpp_properties.json
deleted file mode 100644
index 5512cb3..0000000
--- a/conf.d/project/vscode.d/c_cpp_properties.json
+++ /dev/null
@@ -1,18 +0,0 @@
-{
- "configurations": [
- {
- "name": "null",
- "includePath": [],
- "defines": [],
- "browse": {
- "path": [
- "${workspaceRoot}"
- ],
- "limitSymbolsToIncludedHeaders": true,
- "databaseFilename": ""
- },
- "intelliSenseMode": "clang-x64"
- }
- ],
- "version": 2
-} \ No newline at end of file
diff --git a/conf.d/wgt/config.xml.in b/conf.d/wgt/config.xml.in
deleted file mode 100644
index 197dedc..0000000
--- a/conf.d/wgt/config.xml.in
+++ /dev/null
@@ -1,23 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<widget xmlns="http://www.w3.org/ns/widgets" id="@PROJECT_NAME@" version="@PROJECT_VERSION@">
- <name>@PROJECT_NAME@</name>
- <icon src="@PROJECT_ICON@"/>
- <content src="@WIDGET_ENTRY_POINT@" type="@WIDGET_TYPE@"/>
- <description>@PROJECT_DESCRIPTION@</description>
- <author>@PROJECT_AUTHOR@ &lt;@PROJECT_AUTHOR_MAIL@&gt;</author>
- <license>@PROJECT_LICENSE@</license>
-
- <feature name="urn:AGL:widget:required-permission">
- <param name="urn:AGL:permission::public:hidden" value="required" />
- <param name="urn:AGL:permission::public:no-htdocs" value="required" />
- </feature>
-
- <feature name="urn:AGL:widget:provided-api">
- <param name="control" value="ws" />
- </feature>
-
- <feature name="urn:AGL:widget:required-api">
- <param name="lib/afb-control-afb.so" value="local" />
- </feature>
-</widget>
-
diff --git a/conf.d/wgt/icon.png b/conf.d/wgt/icon.png
deleted file mode 100644
index d127aaa..0000000
--- a/conf.d/wgt/icon.png
+++ /dev/null
Binary files differ
diff --git a/ctl-binding/ctl-apidef.h b/ctl-binding/ctl-apidef.h
deleted file mode 100644
index c408d5e..0000000
--- a/ctl-binding/ctl-apidef.h
+++ /dev/null
@@ -1,118 +0,0 @@
-
-static const char _afb_description_v2_control[] =
- "{\"openapi\":\"3.0.0\",\"$schema\":\"http:iot.bzh/download/openapi/schem"
- "a-3.0/default-schema.json\",\"info\":{\"description\":\"\",\"title\":\"c"
- "ontroler\",\"version\":\"1.0\",\"x-binding-c-generator\":{\"api\":\"cont"
- "rol\",\"version\":2,\"prefix\":\"ctlapi_\",\"postfix\":\"\",\"start\":nu"
- "ll,\"onevent\":\"DispatchOneEvent\",\"init\":\"CtlBindingInit\",\"scope\""
- ":\"\",\"private\":false}},\"servers\":[{\"url\":\"ws://{host}:{port}/api"
- "/polctl\",\"description\":\"Unicens2 API.\",\"variables\":{\"host\":{\"d"
- "efault\":\"localhost\"},\"port\":{\"default\":\"1234\"}},\"x-afb-events\""
- ":[{\"$ref\":\"#/components/schemas/afb-event\"}]}],\"components\":{\"sch"
- "emas\":{\"afb-reply\":{\"$ref\":\"#/components/schemas/afb-reply-v2\"},\""
- "afb-event\":{\"$ref\":\"#/components/schemas/afb-event-v2\"},\"afb-reply"
- "-v2\":{\"title\":\"Generic response.\",\"type\":\"object\",\"required\":"
- "[\"jtype\",\"request\"],\"properties\":{\"jtype\":{\"type\":\"string\",\""
- "const\":\"afb-reply\"},\"request\":{\"type\":\"object\",\"required\":[\""
- "status\"],\"properties\":{\"status\":{\"type\":\"string\"},\"info\":{\"t"
- "ype\":\"string\"},\"token\":{\"type\":\"string\"},\"uuid\":{\"type\":\"s"
- "tring\"},\"reqid\":{\"type\":\"string\"}}},\"response\":{\"type\":\"obje"
- "ct\"}}},\"afb-event-v2\":{\"type\":\"object\",\"required\":[\"jtype\",\""
- "event\"],\"properties\":{\"jtype\":{\"type\":\"string\",\"const\":\"afb-"
- "event\"},\"event\":{\"type\":\"string\"},\"data\":{\"type\":\"object\"}}"
- "}},\"x-permissions\":{\"control\":{\"permission\":\"urn:AGL:permission:a"
- "udio:public:control\"},\"dispatch\":{\"permission\":\"urn:AGL:permission"
- ":audio:public:dispatch\"},\"request\":{\"permission\":\"urn:AGL:permissi"
- "on:audio:public:request\"},\"debug\":{\"permission\":\"urn:AGL:permissio"
- "n:audio:public:debug\"}},\"responses\":{\"200\":{\"description\":\"A com"
- "plex object array response\",\"content\":{\"application/json\":{\"schema"
- "\":{\"$ref\":\"#/components/schemas/afb-reply\"}}}}}},\"paths\":{\"/ping"
- "\":{\"description\":\"Ping Binding\",\"get\":{\"x-permissions\":{\"$ref\""
- ":\"#/components/x-permissions/control\"},\"parameters\":[{\"in\":\"query"
- "\",\"name\":\"args\",\"required\":false,\"schema\":{\"type\":\"json\"}}]"
- ",\"responses\":{\"200\":{\"$ref\":\"#/components/responses/200\"}}}},\"/"
- "subscribe\":{\"description\":\"Subcribe Audio Agent Policy Control End\""
- ",\"get\":{\"x-permissions\":{\"$ref\":\"#/components/x-permissions/contr"
- "ol\"},\"parameters\":[{\"in\":\"query\",\"name\":\"event_patern\",\"requ"
- "ired\":true,\"schema\":{\"type\":\"string\"}}],\"responses\":{\"200\":{\""
- "$ref\":\"#/components/responses/200\"}}}},\"/dispatch\":{\"description\""
- ":\"Request Access to Navigation Audio Channel.\",\"get\":{\"x-permission"
- "s\":{\"$ref\":\"#/components/x-permissions/dispatch\"},\"parameters\":[{"
- "\"in\":\"query\",\"name\":\"zone\",\"required\":false,\"schema\":{\"type"
- "\":\"string\"}}],\"responses\":{\"200\":{\"$ref\":\"#/components/respons"
- "es/200\"}}}},\"/request\":{\"description\":\"Execute LUA string script.\""
- ",\"get\":{\"x-permissions\":{\"$ref\":\"#/components/x-permissions/reque"
- "st\"},\"parameters\":[{\"in\":\"query\",\"name\":\"func\",\"required\":t"
- "rue,\"schema\":{\"type\":\"string\"}},{\"in\":\"query\",\"name\":\"args\""
- ",\"required\":false,\"schema\":{\"type\":\"array\"}}],\"responses\":{\"2"
- "00\":{\"$ref\":\"#/components/responses/200\"}}}},\"/debuglua\":{\"descr"
- "iption\":\"Execute LUA string script.\",\"get\":{\"x-permissions\":{\"$r"
- "ef\":\"#/components/x-permissions/debug\"},\"parameters\":[{\"in\":\"que"
- "ry\",\"name\":\"filename\",\"required\":true,\"schema\":{\"type\":\"stri"
- "ng\"}}],\"responses\":{\"200\":{\"$ref\":\"#/components/responses/200\"}"
- "}}}}}"
-;
-
-static const struct afb_auth _afb_auths_v2_control[] = {
- { .type = afb_auth_Permission, .text = "urn:AGL:permission:audio:public:control" },
- { .type = afb_auth_Permission, .text = "urn:AGL:permission:audio:public:dispatch" },
- { .type = afb_auth_Permission, .text = "urn:AGL:permission:audio:public:request" },
- { .type = afb_auth_Permission, .text = "urn:AGL:permission:audio:public:debug" }
-};
-
- void ctlapi_ping(struct afb_req req);
- void ctlapi_subscribe(struct afb_req req);
- void ctlapi_dispatch(struct afb_req req);
- void ctlapi_request(struct afb_req req);
- void ctlapi_debuglua(struct afb_req req);
-
-static const struct afb_verb_v2 _afb_verbs_v2_control[] = {
- {
- .verb = "ping",
- .callback = ctlapi_ping,
- .auth = &_afb_auths_v2_control[0],
- .info = NULL,
- .session = AFB_SESSION_NONE_V2
- },
- {
- .verb = "subscribe",
- .callback = ctlapi_subscribe,
- .auth = &_afb_auths_v2_control[0],
- .info = NULL,
- .session = AFB_SESSION_NONE_V2
- },
- {
- .verb = "dispatch",
- .callback = ctlapi_dispatch,
- .auth = &_afb_auths_v2_control[1],
- .info = NULL,
- .session = AFB_SESSION_NONE_V2
- },
- {
- .verb = "request",
- .callback = ctlapi_request,
- .auth = &_afb_auths_v2_control[2],
- .info = NULL,
- .session = AFB_SESSION_NONE_V2
- },
- {
- .verb = "debuglua",
- .callback = ctlapi_debuglua,
- .auth = &_afb_auths_v2_control[3],
- .info = NULL,
- .session = AFB_SESSION_NONE_V2
- },
- { .verb = NULL }
-};
-
-const struct afb_binding_v2 afbBindingV2 = {
- .api = "control",
- .specification = _afb_description_v2_control,
- .info = NULL,
- .verbs = _afb_verbs_v2_control,
- .preinit = NULL,
- .init = CtlBindingInit,
- .onevent = DispatchOneEvent,
- .noconcurrency = 0
-};
-
diff --git a/ctl-binding/ctl-apidef.json b/ctl-binding/ctl-apidef.json
deleted file mode 100644
index a8b433e..0000000
--- a/ctl-binding/ctl-apidef.json
+++ /dev/null
@@ -1,249 +0,0 @@
-{
- "openapi": "3.0.0",
- "$schema": "http:iot.bzh/download/openapi/schema-3.0/default-schema.json",
- "info": {
- "description": "",
- "title": "controler",
- "version": "1.0",
- "x-binding-c-generator": {
- "api": "control",
- "version": 2,
- "prefix": "ctlapi_",
- "postfix": "",
- "start": null,
- "onevent": "DispatchOneEvent",
- "init": "CtlBindingInit",
- "scope": "",
- "private": false
- }
- },
- "servers": [
- {
- "url": "ws://{host}:{port}/api/polctl",
- "description": "Unicens2 API.",
- "variables": {
- "host": {
- "default": "localhost"
- },
- "port": {
- "default": "1234"
- }
- },
- "x-afb-events": [
- {
- "$ref": "#/components/schemas/afb-event"
- }
- ]
- }
- ],
- "components": {
- "schemas": {
- "afb-reply": {
- "$ref": "#/components/schemas/afb-reply-v2"
- },
- "afb-event": {
- "$ref": "#/components/schemas/afb-event-v2"
- },
- "afb-reply-v2": {
- "title": "Generic response.",
- "type": "object",
- "required": ["jtype", "request"],
- "properties": {
- "jtype": {
- "type": "string",
- "const": "afb-reply"
- },
- "request": {
- "type": "object",
- "required": ["status"],
- "properties": {
- "status": {
- "type": "string"
- },
- "info": {
- "type": "string"
- },
- "token": {
- "type": "string"
- },
- "uuid": {
- "type": "string"
- },
- "reqid": {
- "type": "string"
- }
- }
- },
- "response": {
- "type": "object"
- }
- }
- },
- "afb-event-v2": {
- "type": "object",
- "required": ["jtype", "event"],
- "properties": {
- "jtype": {
- "type": "string",
- "const": "afb-event"
- },
- "event": {
- "type": "string"
- },
- "data": {
- "type": "object"
- }
- }
- }
- },
- "x-permissions": {
- "control": {
- "permission": "urn:AGL:permission:audio:public:control"
- },
- "dispatch": {
- "permission": "urn:AGL:permission:audio:public:dispatch"
- },
- "request": {
- "permission": "urn:AGL:permission:audio:public:request"
- },
- "debug": {
- "permission": "urn:AGL:permission:audio:public:debug"
- }
- },
- "responses": {
- "200": {
- "description": "A complex object array response",
- "content": {
- "application/json": {
- "schema": {
- "$ref": "#/components/schemas/afb-reply"
- }
- }
- }
- }
- }
- },
- "paths": {
- "/ping": {
- "description": "Ping Binding",
- "get": {
- "x-permissions": {
- "$ref": "#/components/x-permissions/control"
- },
- "parameters": [{
- "in": "query",
- "name": "args",
- "required": false,
- "schema": {
- "type": "json"
- }
- }],
- "responses": {
- "200": {
- "$ref": "#/components/responses/200"
- }
- }
- }
- },
- "/subscribe": {
- "description": "Subcribe Audio Agent Policy Control End",
- "get": {
- "x-permissions": {
- "$ref": "#/components/x-permissions/control"
- },
- "parameters": [
- {
- "in": "query",
- "name": "event_patern",
- "required": true,
- "schema": {
- "type": "string"
- }
- }
- ],
- "responses": {
- "200": {
- "$ref": "#/components/responses/200"
- }
- }
- }
- },
- "/dispatch": {
- "description": "Request Access to Navigation Audio Channel.",
- "get": {
- "x-permissions": {
- "$ref": "#/components/x-permissions/dispatch"
- },
- "parameters": [
- {
- "in": "query",
- "name": "zone",
- "required": false,
- "schema": {
- "type": "string"
- }
- }
- ],
- "responses": {
- "200": {
- "$ref": "#/components/responses/200"
- }
- }
- }
- },
- "/request": {
- "description": "Execute LUA string script.",
- "get": {
- "x-permissions": {
- "$ref": "#/components/x-permissions/request"
- },
- "parameters": [
- {
- "in": "query",
- "name": "func",
- "required": true,
- "schema": {
- "type": "string"
- }
- },
- {
- "in": "query",
- "name": "args",
- "required": false,
- "schema": {
- "type": "array"
- }
- }
- ],
- "responses": {
- "200": {
- "$ref": "#/components/responses/200"
- }
- }
- }
- },
- "/debuglua": {
- "description": "Execute LUA string script.",
- "get": {
- "x-permissions": {
- "$ref": "#/components/x-permissions/debug"
- },
- "parameters": [
- {
- "in": "query",
- "name": "filename",
- "required": true,
- "schema": {
- "type": "string"
- }
- }
- ],
- "responses": {
- "200": {
- "$ref": "#/components/responses/200"
- }
- }
- }
- }
- }
-}
diff --git a/ctl-binding/ctl-binding.c b/ctl-binding/ctl-binding.c
deleted file mode 100644
index 6840b5c..0000000
--- a/ctl-binding/ctl-binding.c
+++ /dev/null
@@ -1,74 +0,0 @@
-/*
- * Copyright (C) 2016 "IoT.bzh"
- * Author Fulup Ar Foll <fulup@iot.bzh>
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#define _GNU_SOURCE
-#include <stdio.h>
-#include <string.h>
-#include <time.h>
-
-#include "ctl-binding.h"
-
-// Include Binding Stub generated from Json OpenAPI
-#include "ctl-apidef.h"
-
-PUBLIC void ctlapi_ping (afb_req request) {
- static int count=0;
-
- count++;
- AFB_NOTICE ("Controller:ping count=%d", count);
- afb_req_success(request,json_object_new_int(count), NULL);
-
- return;
-}
-
-PUBLIC void ctlapi_subscribe (afb_req request) {
-
- // subscribe Client to event
- int err = afb_req_subscribe(request, TimerEvtGet());
- if (err != 0) {
- afb_req_fail_f(request, "register-event", "Fail to subscribe binder event");
- goto OnErrorExit;
- }
-
- afb_req_success(request, NULL, NULL);
-
- OnErrorExit:
- return;
-}
-
-// Create Binding Event at Init
-PUBLIC int CtlBindingInit () {
-
- int errcount=0;
-
- errcount += TimerEvtInit();
- errcount += DispatchInit();
-#ifdef CONTROL_SUPPORT_LUA
- errcount += LuaLibInit();
-#endif
-
- const char *profile= getenv("CONTROL_ONLOAD_PROFILE");
- if (!profile) profile=CONTROL_ONLOAD_PROFILE;
-
- // now that everything is initialised execute the onload action
- if (!errcount)
- errcount += DispatchOnLoad(CONTROL_ONLOAD_PROFILE);
-
- AFB_DEBUG ("Audio Policy Control Binding Done errcount=%d", errcount);
- return errcount;
-}
-
diff --git a/ctl-binding/ctl-binding.h b/ctl-binding/ctl-binding.h
deleted file mode 100644
index f159440..0000000
--- a/ctl-binding/ctl-binding.h
+++ /dev/null
@@ -1,145 +0,0 @@
-/*
- * Copyright (C) 2016 "IoT.bzh"
- * Author Fulup Ar Foll <fulup@iot.bzh>
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-
-#ifndef CONTROLLER_BINDING_INCLUDE
-#define CONTROLLER_BINDING_INCLUDE
-
-#define AFB_BINDING_VERSION 2
-#include <afb/afb-binding.h>
-#include <json-c/json.h>
-#include <systemd/sd-event.h>
-#include "filescan-utils.h"
-#include "wrap-json.h"
-
-#ifdef CONTROL_SUPPORT_LUA
-#include "lua.h"
-#include "lauxlib.h"
-#include "lualib.h"
-#endif
-
-#ifndef PUBLIC
- #define PUBLIC
-#endif
-#define STATIC static
-
-#ifndef UNUSED_ARG
-#define UNUSED_ARG(x) UNUSED_ ## x __attribute__((__unused__))
-#define UNUSED_FUNCTION(x) __attribute__((__unused__)) UNUSED_ ## x
-#endif
-
-// polctl-binding.c
-PUBLIC int CtlBindingInit ();
-
-// ctl-timerevt.c
-// ----------------------
-typedef int (*timerCallbackT)(void *context);
-
-typedef struct TimerHandleS {
- int count;
- int delay;
- const char*label;
- void *context;
- 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
diff --git a/ctl-binding/ctl-dispatch.c b/ctl-binding/ctl-dispatch.c
deleted file mode 100644
index da900ec..0000000
--- a/ctl-binding/ctl-dispatch.c
+++ /dev/null
@@ -1,678 +0,0 @@
-/*
- * Copyright (C) 2016 "IoT.bzh"
- * Author Fulup Ar Foll <fulup@iot.bzh>
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, something express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- * Reference:
- * Json load using json_unpack https://jansson.readthedocs.io/en/2.9/apiref.html#parsing-and-validating-values
- */
-
-#define _GNU_SOURCE
-#include <stdio.h>
-#include <string.h>
-#include <dlfcn.h>
-#include <sys/prctl.h>
-
-#include "ctl-binding.h"
-
-typedef void*(*DispatchPluginInstallCbT)(const char* label, const char*version, const char*info);
-
-
-static afb_req NULL_AFBREQ = {};
-
-
-typedef struct {
- const char* label;
- const char *info;
- DispatchActionT *actions;
-} DispatchHandleT;
-
-typedef struct {
- const char *label;
- const char *info;
- void *context;
- char *sharelib;
- void *dlHandle;
- luaL_Reg *l2cFunc;
- int l2cCount;
-} DispatchPluginT;
-
-typedef struct {
- const char* label;
- const char *info;
- const char *version;
- DispatchPluginT *plugin;
- DispatchHandleT **onloads;
- DispatchHandleT **events;
- DispatchHandleT **controls;
-} DispatchConfigT;
-
-// global config handle
-STATIC DispatchConfigT *configHandle = NULL;
-
-STATIC int DispatchControlToIndex(DispatchHandleT **controls, const char* controlLabel) {
-
- for (int idx = 0; controls[idx]; idx++) {
- if (!strcasecmp(controlLabel, controls[idx]->label)) return idx;
- }
- return -1;
-}
-
-STATIC int DispatchOneControl(DispatchSourceT source, DispatchHandleT **controls, const char* controlLabel, json_object *queryJ, afb_req request) {
- int err;
-
- if (!configHandle) {
- AFB_ERROR("DISPATCH-CTL-API: (Hoops/Bug!!!) No Config Loaded");
- goto OnErrorExit;
- }
-
- if (!configHandle->controls) {
- AFB_ERROR("DISPATCH-CTL-API: No Control Action in Json config label=%s version=%s", configHandle->label, configHandle->version);
- goto OnErrorExit;
- }
-
- int index = DispatchControlToIndex(controls, controlLabel);
- if (index < 0 || !controls[index]->actions) {
- AFB_ERROR("DISPATCH-CTL-API:NotFound/Error label=%s in Json Control Config File", controlLabel);
- goto OnErrorExit;
- }
-
- // Fulup (Bug/Feature) in current version is unique to every onload profile
- if (configHandle->plugin && configHandle->plugin->l2cCount) {
- LuaL2cNewLib (configHandle->plugin->label, configHandle->plugin->l2cFunc, configHandle->plugin->l2cCount);
- }
-
- // loop on action for this control
- DispatchActionT *actions = controls[index]->actions;
- for (int idx = 0; actions[idx].label; idx++) {
-
- switch (actions[idx].mode) {
- case CTL_MODE_API:
- {
- json_object *returnJ;
-
- // if query is empty increment usage count and pass args
- if (!queryJ || json_object_get_type(queryJ) != json_type_object) {
- json_object_get(actions[idx].argsJ);
- queryJ= actions[idx].argsJ;
- } else if (actions[idx].argsJ) {
-
- // Merge queryJ and argsJ before sending request
- if (json_object_get_type(actions[idx].argsJ) == json_type_object) {
- json_object_object_foreach(actions[idx].argsJ, key, val) {
- json_object_object_add(queryJ, key, val);
- }
- } else {
- json_object_object_add(queryJ, "args", actions[idx].argsJ);
- }
- }
-
- int err = afb_service_call_sync(actions[idx].api, actions[idx].call, queryJ, &returnJ);
- if (err) {
- static const char*format = "DispatchOneControl(Api) api=%s verb=%s args=%s";
- if (afb_req_is_valid(request))afb_req_fail_f(request, "DISPATCH-CTL-MODE:API", format, actions[idx].label, actions[idx].api, actions[idx].call);
- else AFB_ERROR(format, actions[idx].api, actions[idx].call, actions[idx].label);
- goto OnErrorExit;
- }
- break;
- }
-
-#ifdef CONTROL_SUPPORT_LUA
- case CTL_MODE_LUA:
- err = LuaCallFunc(source, &actions[idx], queryJ);
- if (err) {
- static const char*format = "DispatchOneControl(Lua) label=%s func=%s args=%s";
- if (afb_req_is_valid(request)) afb_req_fail_f(request, "DISPATCH-CTL-MODE:Lua", format, actions[idx].label, actions[idx].call, json_object_get_string(actions[idx].argsJ));
- else AFB_ERROR(format, actions[idx].label, actions[idx].call, json_object_get_string(actions[idx].argsJ));
- goto OnErrorExit;
- }
- break;
-#endif
-
- case CTL_MODE_CB:
- err = (*actions[idx].actionCB) (source, actions[idx].label, actions[idx].argsJ, queryJ, configHandle->plugin->context);
- if (err) {
- static const char*format = "DispatchOneControl(Callback) label%s func=%s args=%s";
- if (afb_req_is_valid(request)) afb_req_fail_f(request, "DISPATCH-CTL-MODE:Cb", format, actions[idx].label, actions[idx].call, json_object_get_string(actions[idx].argsJ));
- else AFB_ERROR(format, actions[idx].label, actions[idx].call, json_object_get_string(actions[idx].argsJ));
- goto OnErrorExit;
- }
- break;
-
- default:
- {
- static const char*format = "DispatchOneControl(unknown) mode control=%s action=%s";
- AFB_ERROR(format, controls[index]->label);
- if (afb_req_is_valid(request))afb_req_fail_f(request, "DISPATCH-CTL-MODE:Unknown", format, controls[index]->label);
- }
- }
- }
-
- // everything when fine
- if (afb_req_is_valid(request))afb_req_success(request, NULL, controls[index]->label);
- return 0;
-
-OnErrorExit:
- return -1;
-}
-
-
-// Event name is mapped on control label and executed as a standard control
-
-PUBLIC void DispatchOneEvent(const char *evtLabel, json_object *eventJ) {
- DispatchHandleT **events = configHandle->events;
-
- (void) DispatchOneControl(CTL_SOURCE_EVENT, events, evtLabel, eventJ, NULL_AFBREQ);
-}
-
-// Event name is mapped on control label and executed as a standard control
-
-PUBLIC int DispatchOnLoad(const char *onLoadLabel) {
- if (!configHandle) return 1;
-
- DispatchHandleT **onloads = configHandle->onloads;
-
- int err = DispatchOneControl(CTL_SOURCE_ONLOAD, onloads, onLoadLabel, NULL, NULL_AFBREQ);
- return err;
-}
-
-PUBLIC void ctlapi_dispatch(afb_req request) {
- DispatchHandleT **controls = configHandle->controls;
- json_object *queryJ, *argsJ=NULL;
- const char *target;
- DispatchSourceT source= CTL_SOURCE_UNKNOWN;
-
- queryJ = afb_req_json(request);
- int err = wrap_json_unpack(queryJ, "{s:s, s?i s?o !}", "target", &target, "source", &source, "args", &argsJ);
- if (err) {
- afb_req_fail_f(request, "CTL-DISPTACH-INVALID", "missing target or args not a valid json object query=%s", json_object_get_string(queryJ));
- goto OnErrorExit;
- }
-
- (void) DispatchOneControl(source, controls, target, argsJ, request);
-
-OnErrorExit:
- return;
-}
-
-// Wrapper to Lua2c plugin command add context dans delegate to LuaWrapper
-PUBLIC int DispatchOneL2c(lua_State* luaState, char *funcname, Lua2cFunctionT callback) {
-#ifndef CONTROL_SUPPORT_LUA
- AFB_ERROR("DISPATCH-ONE-L2C: LUA support not selected (cf:CONTROL_SUPPORT_LUA) in config.cmake");
- return 1;
-#else
- int err=Lua2cWrapper(luaState, funcname, callback, configHandle->plugin->context);
- return err;
-#endif
-}
-
-
-// List Avaliable Configuration Files
-
-PUBLIC void ctlapi_config(struct afb_req request) {
- json_object*tmpJ;
- char *dirList;
-
-
- json_object* queryJ = afb_req_json(request);
- if (queryJ && json_object_object_get_ex(queryJ, "cfgpath", &tmpJ)) {
- dirList = strdup(json_object_get_string(tmpJ));
- } else {
-
- dirList = getenv("CONTROL_CONFIG_PATH");
- if (!dirList) dirList = strdup(CONTROL_CONFIG_PATH);
- AFB_NOTICE("CONFIG-MISSING: use default CONTROL_CONFIG_PATH=%s", CONTROL_CONFIG_PATH);
- }
-
- // get list of config file
- struct json_object *responseJ = ScanForConfig(dirList, CTL_SCAN_RECURSIVE, "onload", "json");
-
- if (json_object_array_length(responseJ) == 0) {
- afb_req_fail(request, "CONFIGPATH:EMPTY", "No Config Found in CONTROL_CONFIG_PATH");
- } else {
- afb_req_success(request, responseJ, NULL);
- }
-
- return;
-}
-
-// unpack individual action object
-
-STATIC int DispatchLoadOneAction(DispatchConfigT *controlConfig, json_object *actionJ, DispatchActionT *action) {
- char *api = NULL, *verb = NULL, *callback = NULL, *lua = NULL;
- int err, modeCount = 0;
-
- err = wrap_json_unpack(actionJ, "{ss,s?s,s?s,s?s,s?s,s?s,s?o !}"
- , "label", &action->label, "info", &action->info, "callback", &callback, "lua", &lua, "api", &api, "verb", &verb, "args", &action->argsJ);
- if (err) {
- AFB_ERROR("DISPATCH-LOAD-ACTION Missing something label|info|callback|lua|(api+verb)|args in %s", json_object_get_string(actionJ));
- goto OnErrorExit;
- }
-
- if (lua) {
- action->mode = CTL_MODE_LUA;
- action->call = lua;
- modeCount++;
- }
-
- if (api && verb) {
- action->mode = CTL_MODE_API;
- action->api = api;
- action->call = verb;
- modeCount++;
- }
-
- if (callback && controlConfig->plugin) {
- action->mode = CTL_MODE_CB;
- action->call = callback;
- modeCount++;
-
- action->actionCB = dlsym(controlConfig->plugin->dlHandle, callback);
- if (!action->actionCB) {
- AFB_ERROR("DISPATCH-LOAD-ACTION fail to find calbback=%s in %s", callback, controlConfig->plugin->sharelib);
- goto OnErrorExit;
- }
- }
-
- // make sure at least one mode is selected
- if (modeCount == 0) {
- AFB_ERROR("DISPATCH-LOAD-ACTION No Action Selected lua|callback|(api+verb) in %s", json_object_get_string(actionJ));
- goto OnErrorExit;
- }
-
- if (modeCount > 1) {
- AFB_ERROR("DISPATCH-LOAD-ACTION:ToMany arguments lua|callback|(api+verb) in %s", json_object_get_string(actionJ));
- goto OnErrorExit;
- }
- return 0;
-
-OnErrorExit:
- return -1;
-};
-
-STATIC DispatchActionT *DispatchLoadActions(DispatchConfigT *controlConfig, json_object *actionsJ) {
- int err;
- DispatchActionT *actions;
-
- // action array is close with a nullvalue;
- if (json_object_get_type(actionsJ) == json_type_array) {
- int count = json_object_array_length(actionsJ);
- actions = calloc(count + 1, sizeof (DispatchActionT));
-
- for (int idx = 0; idx < count; idx++) {
- json_object *actionJ = json_object_array_get_idx(actionsJ, idx);
- err = DispatchLoadOneAction(controlConfig, actionJ, &actions[idx]);
- if (err) goto OnErrorExit;
- }
-
- } else {
- actions = calloc(2, sizeof (DispatchActionT));
- err = DispatchLoadOneAction(controlConfig, actionsJ, &actions[0]);
- if (err) goto OnErrorExit;
- }
-
- return actions;
-
-OnErrorExit:
- return NULL;
-
-}
-
-STATIC DispatchHandleT *DispatchLoadControl(DispatchConfigT *controlConfig, json_object *controlJ) {
- json_object *actionsJ, *permissionsJ;
- int err;
-
- DispatchHandleT *dispatchHandle = calloc(1, sizeof (DispatchHandleT));
- err = wrap_json_unpack(controlJ, "{ss,s?s,s?o, so !}", "label", &dispatchHandle->label, "info", &dispatchHandle->info
- , "permissions", &permissionsJ, "actions", &actionsJ);
- if (err) {
- AFB_ERROR("DISPATCH-LOAD-CONFIG:CONTROL Missing something label|[info]|actions in %s", json_object_get_string(controlJ));
- goto OnErrorExit;
- }
-
- dispatchHandle->actions = DispatchLoadActions(controlConfig, actionsJ);
- if (!dispatchHandle->actions) {
- AFB_ERROR("DISPATCH-LOAD-CONFIG:CONTROL Error when parsing actions %s", dispatchHandle->label);
- goto OnErrorExit;
- }
- return dispatchHandle;
-
-OnErrorExit:
- return NULL;
-}
-
-STATIC DispatchHandleT *DispatchLoadOnload(DispatchConfigT *controlConfig, json_object *onloadJ) {
- json_object *actionsJ = NULL, *requireJ = NULL, *pluginJ = NULL;
- int err;
-
- DispatchHandleT *dispatchHandle = calloc(1, sizeof (DispatchHandleT));
- err = wrap_json_unpack(onloadJ, "{ss,s?s,s?o,s?o,s?o !}",
- "label", &dispatchHandle->label, "info", &dispatchHandle->info, "plugin", &pluginJ, "require", &requireJ, "actions", &actionsJ);
- if (err) {
- AFB_ERROR("DISPATCH-LOAD-CONFIG:ONLOAD Missing something label|[info]|[plugin]|[actions] in %s", json_object_get_string(onloadJ));
- goto OnErrorExit;
- }
-
- // best effort to initialise everything before starting
- if (requireJ) {
-
- void DispatchRequireOneApi(json_object * bindindJ) {
- const char* requireBinding = json_object_get_string(bindindJ);
- err = afb_daemon_require_api(requireBinding, 1);
- if (err) {
- AFB_WARNING("DISPATCH-LOAD-CONFIG:REQUIRE Fail to get=%s", requireBinding);
- }
- }
-
- if (json_object_get_type(requireJ) == json_type_array) {
- for (int idx = 0; idx < json_object_array_length(requireJ); idx++) {
- DispatchRequireOneApi(json_object_array_get_idx(requireJ, idx));
- }
- } else {
- DispatchRequireOneApi(requireJ);
- }
- }
-
- if (pluginJ) {
- json_object *lua2csJ = NULL;
- DispatchPluginT *dPlugin= calloc(1, sizeof(DispatchPluginT));
- controlConfig->plugin = dPlugin;
- const char*ldSearchPath=NULL;
-
- err = wrap_json_unpack(pluginJ, "{ss,s?s,s?s,ss,s?o!}",
- "label", &dPlugin->label, "info", &dPlugin->info, "ldpath", &ldSearchPath, "sharelib", &dPlugin->sharelib, "lua2c", &lua2csJ);
- if (err) {
- AFB_ERROR("DISPATCH-LOAD-CONFIG:ONLOAD Plugin missing label|[info]|sharelib|[lua2c] in %s", json_object_get_string(onloadJ));
- goto OnErrorExit;
- }
-
- // if search path not in Json config file, then try default
- if (!ldSearchPath) ldSearchPath=CONTROL_PLUGIN_PATH;
-
- // search for default policy config file
- json_object *pluginPathJ = ScanForConfig(ldSearchPath, CTL_SCAN_RECURSIVE, dPlugin->sharelib, NULL);
- if (!pluginPathJ || json_object_array_length(pluginPathJ) == 0) {
- AFB_ERROR("DISPATCH-LOAD-CONFIG:PLUGIN Missing plugin=%s in path=%s", dPlugin->sharelib, ldSearchPath);
- goto OnErrorExit;
- }
-
- char *filename;
- char*fullpath;
- err = wrap_json_unpack(json_object_array_get_idx(pluginPathJ, 0), "{s:s, s:s !}", "fullpath", &fullpath, "filename", &filename);
- if (err) {
- AFB_ERROR("DISPATCH-LOAD-CONFIG:PLUGIN HOOPs invalid plugin file path = %s", json_object_get_string(pluginPathJ));
- goto OnErrorExit;
- }
-
- if (json_object_array_length(pluginPathJ) > 1) {
- AFB_WARNING("DISPATCH-LOAD-CONFIG:PLUGIN plugin multiple instances in searchpath will use %s/%s", fullpath, filename);
- }
-
- char pluginpath[CONTROL_MAXPATH_LEN];
- strncpy(pluginpath, fullpath, sizeof (pluginpath));
- strncat(pluginpath, "/", sizeof (pluginpath)-strlen(pluginpath)-1);
- strncat(pluginpath, filename, sizeof (pluginpath)-strlen(pluginpath)-1);
- dPlugin->dlHandle = dlopen(pluginpath, RTLD_NOW);
- if (!dPlugin->dlHandle) {
- AFB_ERROR("DISPATCH-LOAD-CONFIG:PLUGIN Fail to load pluginpath=%s err= %s", pluginpath, dlerror());
- goto OnErrorExit;
- }
-
- CtlPluginMagicT *ctlPluginMagic = (CtlPluginMagicT*) dlsym(dPlugin->dlHandle, "CtlPluginMagic");
- if (!ctlPluginMagic || ctlPluginMagic->magic != CTL_PLUGIN_MAGIC) {
- AFB_ERROR("DISPATCH-LOAD-CONFIG:Plugin symbol'CtlPluginMagic' missing or != CTL_PLUGIN_MAGIC plugin=%s", pluginpath);
- goto OnErrorExit;
- } else {
- AFB_NOTICE("DISPATCH-LOAD-CONFIG:Plugin %s successfully registered", ctlPluginMagic->label);
- }
-
- // Jose hack to make verbosity visible from sharelib
- struct afb_binding_data_v2 *afbHidenData = dlsym(dPlugin->dlHandle, "afbBindingV2data");
- if (afbHidenData) *afbHidenData = afbBindingV2data;
-
- // Push lua2cWrapper @ into plugin
- Lua2cWrapperT *lua2cInPlug = dlsym(dPlugin->dlHandle, "Lua2cWrap");
-#ifndef CONTROL_SUPPORT_LUA
- if (lua2cInPlug) *lua2cInPlug = NULL;
-#else
- // Lua2cWrapper is part of binder and not expose to dynamic link
- if (lua2cInPlug) *lua2cInPlug = DispatchOneL2c;
-
- {
- int Lua2cAddOne(luaL_Reg *l2cFunc, const char* l2cName, int index) {
- char funcName[CONTROL_MAXPATH_LEN];
- strncpy(funcName, "lua2c_", sizeof(funcName));
- strncat(funcName, l2cName, sizeof(funcName)-strlen(funcName)-1);
-
- Lua2cFunctionT l2cFunction= (Lua2cFunctionT)dlsym(dPlugin->dlHandle, funcName);
- if (!l2cFunction) {
- AFB_ERROR("DISPATCH-LOAD-CONFIG:Plugin symbol'%s' missing err=%s", funcName, dlerror());
- return 1;
- }
- l2cFunc[index].func=(void*)l2cFunction;
- l2cFunc[index].name=strdup(l2cName);
-
- return 0;
- }
-
- int errCount = 0;
- luaL_Reg *l2cFunc=NULL;
- int count=0;
-
- // look on l2c command and push them to LUA
- if (json_object_get_type(lua2csJ) == json_type_array) {
- int length = json_object_array_length(lua2csJ);
- l2cFunc = calloc(length + 1, sizeof (luaL_Reg));
- for (count=0; count < length; count++) {
- int err;
- const char *l2cName = json_object_get_string(json_object_array_get_idx(lua2csJ, count));
- err = Lua2cAddOne(l2cFunc, l2cName, count);
- if (err) errCount++;
- }
- } else {
- l2cFunc = calloc(2, sizeof (luaL_Reg));
- const char *l2cName = json_object_get_string(lua2csJ);
- errCount = Lua2cAddOne(l2cFunc, l2cName, 0);
- count=1;
- }
- if (errCount) {
- AFB_ERROR("DISPATCH-LOAD-CONFIG:Plugin %d symbols not found in plugin='%s'", errCount, pluginpath);
- goto OnErrorExit;
- } else {
- dPlugin->l2cFunc= l2cFunc;
- dPlugin->l2cCount= count;
- }
- }
-#endif
- DispatchPluginInstallCbT ctlPluginOnload = dlsym(dPlugin->dlHandle, "CtlPluginOnload");
- if (ctlPluginOnload) {
- dPlugin->context = (*ctlPluginOnload) (controlConfig->label, controlConfig->version, controlConfig->info);
- }
- }
-
- dispatchHandle->actions = DispatchLoadActions(controlConfig, actionsJ);
- if (!dispatchHandle->actions) {
- AFB_ERROR("DISPATCH-LOAD-CONFIG:ONLOAD Error when parsing actions %s", dispatchHandle->label);
- goto OnErrorExit;
- }
- return dispatchHandle;
-
-OnErrorExit:
- return NULL;
-}
-
-STATIC DispatchConfigT *DispatchLoadConfig(const char* filepath) {
- json_object *controlConfigJ, *ignoreJ;
- int err;
-
- // Load JSON file
- controlConfigJ = json_object_from_file(filepath);
- if (!controlConfigJ) {
- AFB_ERROR("DISPATCH-LOAD-CONFIG:JsonLoad invalid JSON %s ", filepath);
- goto OnErrorExit;
- }
-
- AFB_INFO("DISPATCH-LOAD-CONFIG: loading config filepath=%s", filepath);
-
- json_object *metadataJ = NULL, *onloadsJ = NULL, *controlsJ = NULL, *eventsJ = NULL;
- err = wrap_json_unpack(controlConfigJ, "{s?s,s?o,s?o,s?o,s?o !}", "$schema", &ignoreJ, "metadata", &metadataJ, "onload", &onloadsJ, "controls", &controlsJ, "events", &eventsJ);
- if (err) {
- AFB_ERROR("DISPATCH-LOAD-CONFIG Missing something metadata|[onload]|[controls]|[events] in %s", json_object_get_string(controlConfigJ));
- goto OnErrorExit;
- }
-
-
-
- DispatchConfigT *controlConfig = calloc(1, sizeof (DispatchConfigT));
- if (metadataJ) {
- const char*ctlname=NULL;
- err = wrap_json_unpack(metadataJ, "{ss,s?s,s?s,ss !}", "label", &controlConfig->label, "version", &controlConfig->version, "name", &ctlname, "info", &controlConfig->info);
- if (err) {
- AFB_ERROR("DISPATCH-LOAD-CONFIG:METADATA Missing something label|version|[label] in %s", json_object_get_string(metadataJ));
- goto OnErrorExit;
- }
-
- // if ctlname is provided change process name now
- if (ctlname) {
- err= prctl(PR_SET_NAME, ctlname,NULL,NULL,NULL);
- if (err) AFB_WARNING("Fail to set Process Name to:%s",ctlname);
- }
-
- }
-
- if (onloadsJ) {
- DispatchHandleT *dispatchHandle;
-
- if (json_object_get_type(onloadsJ) != json_type_array) {
- controlConfig->onloads = (DispatchHandleT**) calloc(2, sizeof (void*));
- dispatchHandle = DispatchLoadOnload(controlConfig, onloadsJ);
- controlConfig->onloads[0] = dispatchHandle;
- } else {
- int length = json_object_array_length(onloadsJ);
- controlConfig->onloads = (DispatchHandleT**) calloc(length + 1, sizeof (void*));
-
- for (int jdx = 0; jdx < length; jdx++) {
- json_object *onloadJ = json_object_array_get_idx(onloadsJ, jdx);
- dispatchHandle = DispatchLoadOnload(controlConfig, onloadJ);
- controlConfig->onloads[jdx] = dispatchHandle;
- }
- }
- }
-
- if (controlsJ) {
- DispatchHandleT *dispatchHandle;
-
- if (json_object_get_type(controlsJ) != json_type_array) {
- controlConfig->controls = (DispatchHandleT**) calloc(2, sizeof (void*));
- dispatchHandle = DispatchLoadControl(controlConfig, controlsJ);
- controlConfig->controls[0] = dispatchHandle;
- } else {
- int length = json_object_array_length(controlsJ);
- controlConfig->controls = (DispatchHandleT**) calloc(length + 1, sizeof (void*));
-
- for (int jdx = 0; jdx < length; jdx++) {
- json_object *controlJ = json_object_array_get_idx(controlsJ, jdx);
- dispatchHandle = DispatchLoadControl(controlConfig, controlJ);
- controlConfig->controls[jdx] = dispatchHandle;
- }
- }
- }
-
- if (eventsJ) {
- DispatchHandleT *dispatchHandle;
-
- if (json_object_get_type(eventsJ) != json_type_array) {
- controlConfig->events = (DispatchHandleT**) calloc(2, sizeof (void*));
- dispatchHandle = DispatchLoadControl(controlConfig, eventsJ);
- controlConfig->events[0] = dispatchHandle;
- } else {
- int length = json_object_array_length(eventsJ);
- controlConfig->events = (DispatchHandleT**) calloc(length + 1, sizeof (void*));
-
- for (int jdx = 0; jdx < length; jdx++) {
- json_object *eventJ = json_object_array_get_idx(eventsJ, jdx);
- dispatchHandle = DispatchLoadControl(controlConfig, eventJ);
- controlConfig->events[jdx] = dispatchHandle;
- }
- }
- }
-
- return controlConfig;
-
-OnErrorExit:
- return NULL;
-}
-
-
-// Load default config file at init
-
-PUBLIC int DispatchInit() {
- int index, err, luaLoaded = 0;
- char controlFile [CONTROL_MAXPATH_LEN];
-
- const char *dirList= getenv("CONTROL_CONFIG_PATH");
- if (!dirList) dirList=CONTROL_CONFIG_PATH;
-
- strncpy(controlFile, CONTROL_CONFIG_PRE "-", CONTROL_MAXPATH_LEN);
- strncat(controlFile, GetBinderName(), CONTROL_MAXPATH_LEN-strlen(controlFile)-1);
-
- // search for default dispatch config file
- json_object* responseJ = ScanForConfig(dirList, CTL_SCAN_RECURSIVE, controlFile, "json");
-
- // We load 1st file others are just warnings
- for (index = 0; index < json_object_array_length(responseJ); index++) {
- json_object *entryJ = json_object_array_get_idx(responseJ, index);
-
- char *filename;
- char*fullpath;
- err = wrap_json_unpack(entryJ, "{s:s, s:s !}", "fullpath", &fullpath, "filename", &filename);
- if (err) {
- AFB_ERROR("DISPATCH-INIT HOOPs invalid JSON entry= %s", json_object_get_string(entryJ));
- goto OnErrorExit;
- }
-
- if (index == 0) {
- if (strcasestr(filename, controlFile)) {
- char filepath[CONTROL_MAXPATH_LEN];
- strncpy(filepath, fullpath, sizeof (filepath));
- strncat(filepath, "/", sizeof (filepath)-strlen(filepath)-1);
- strncat(filepath, filename, sizeof (filepath)-strlen(filepath)-1);
- configHandle = DispatchLoadConfig(filepath);
- if (!configHandle) {
- AFB_ERROR("DISPATCH-INIT:ERROR Fail loading [%s]", filepath);
- goto OnErrorExit;
- }
- luaLoaded = 1;
- break;
- }
- } else {
- AFB_WARNING("DISPATCH-INIT:WARNING Secondary Control Config Ignored %s/%s", fullpath, filename);
- }
- }
-
- // no dispatch config found remove control API from binder
- if (!luaLoaded) {
- AFB_WARNING("DISPATCH-INIT:WARNING (setenv CONTROL_CONFIG_PATH) No Config '%s-*.json' in '%s'", controlFile, dirList);
- }
-
- AFB_NOTICE("DISPATCH-INIT:SUCCES: Control Dispatch Init");
- return 0;
-
-OnErrorExit:
- AFB_NOTICE("DISPATCH-INIT:ERROR: Control Dispatch Init");
- return 1;
-}
-
-
-
diff --git a/ctl-binding/ctl-policy.c b/ctl-binding/ctl-policy.c
deleted file mode 100644
index 9fe220c..0000000
--- a/ctl-binding/ctl-policy.c
+++ /dev/null
@@ -1,221 +0,0 @@
-/*
- * Copyright (C) 2016 "IoT.bzh"
- * Author Fulup Ar Foll <fulup@iot.bzh>
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, something express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#define _GNU_SOURCE
-#include <stdio.h>
-#include <string.h>
-#include <dirent.h>
-#include <json-c/json_object.h>
-
-#include "wrap-json.h"
-#include "ctl-binding.h"
-
-STATIC PolicyCtlConfigT *ctlHandle = NULL;
-
-// List Avaliable Configuration Files
-STATIC json_object* ScanForConfig (char* searchPath) {
- json_object *responseJ;
- DIR *dirHandle;
- char *dirPath;
- char* dirList= strdup(searchPath);
-
- responseJ = json_object_new_array();
- for (dirPath= strtok(dirList, ":"); dirPath && *dirPath; dirPath=strtok(NULL,":")) {
- struct dirent *dirEnt;
-
- dirHandle = opendir (dirPath);
- if (!dirHandle) {
- AFB_NOTICE ("CONFIG-SCANNING dir=%s not readable", dirPath);
- continue;
- }
-
- AFB_NOTICE ("CONFIG-SCANNING:ctl_listconfig scanning: %s", dirPath);
- while ((dirEnt = readdir(dirHandle)) != NULL) {
- // Unknown type is accepted to support dump filesystems
- if (dirEnt->d_type == DT_REG || dirEnt->d_type == DT_UNKNOWN) {
- struct json_object *pathJ = json_object_new_object();
- json_object_object_add(pathJ, "dirpath", json_object_new_string(dirPath));
- json_object_object_add(pathJ, "filename", json_object_new_string(dirEnt->d_name));
- json_object_array_add(responseJ, pathJ);
- }
- }
- }
-
- free (dirList);
- return (responseJ);
-}
-
-PUBLIC void ctlapi_authorize (PolicyCtlEnumT control, afb_req request) {
- json_object*tmpJ;
-
- json_object* queryJ= afb_req_json(request);
- int done=json_object_object_get_ex(queryJ, "closing", &tmpJ);
- if (done) return;
-
-}
-
-
-// List Avaliable Configuration Files
-PUBLIC void ctlapi_config (struct afb_req request) {
- json_object*tmpJ;
- char *dirList;
-
- json_object* queryJ = afb_req_json(request);
- if (queryJ && json_object_object_get_ex (queryJ, "cfgpath" , &tmpJ)) {
- dirList = strdup (json_object_get_string(tmpJ));
- } else {
- dirList = strdup (CONTROL_CONFIG_PATH);
- AFB_NOTICE ("CONFIG-MISSING: use default CONTROL_CONFIG_PATH=%s", CONTROL_CONFIG_PATH);
- }
-
- // get list of config file
- struct json_object *responseJ = ScanForConfig(dirList);
-
- if (json_object_array_length(responseJ) == 0) {
- afb_req_fail(request, "CONFIGPATH:EMPTY", "No Config Found in CONTROL_CONFIG_PATH");
- } else {
- afb_req_success(request, responseJ, NULL);
- }
-
- return;
-}
-
-STATIC PolicyActionT **PolicyLoadActions (json_object *actionsJ) {
- int err;
- PolicyActionT ** actions;
-
- // unpack individual action object
- int actionUnpack (json_object *actionJ, PolicyActionT *action) {
-
- err= wrap_json_unpack(actionJ, "{ss,s?s,s?s,s?s,s?s,s?s !}"
- , "label",&action->label, "info",&action->info, "callback",&action->callback, "query",&queryJ, "api",&action->api, "verb", &action->verb);
- if (err) {
- AFB_ERROR ("POLICY-LOAD-ACTION Missing something label|info|callback|api|verb|query in %s", json_object_get_string(actionJ));
- return -1;
- }
- if (!action->callback || !(action->api && action->verb)) {
- AFB_ERROR ("POLICY-LOAD-ACTION Missing something callback|(api+verb) in %s", json_object_get_string(actionJ));
- return -1;
- }
- return 0;
- };
-
- // action array is close with a nullvalue;
- if (json_object_get_type(actionsJ) == json_type_array) {
- int count = json_object_array_length(actionsJ);
- actions = calloc (count+1, sizeof(PolicyActionT));
-
- for (int idx=0; idx < count; idx++) {
- json_object *actionJ = json_object_array_get_idx(actionsJ, idx);
- err = actionUnpack (actionJ, &actions[idx]);
- if (err) goto OnErrorExit;
- }
-
- } else {
- actions = calloc (2, sizeof(PolicyActionT));
- err = actionUnpack (actionsJ, &actions[0]);
- if (err) goto OnErrorExit;
- }
-
- return actions;
-
- OnErrorExit:
- return NULL;
-
-}
-
-// load control policy from file using json_unpack https://jansson.readthedocs.io/en/2.9/apiref.html#parsing-and-validating-values
-STATIC PolicyCtlConfigT *PolicyLoadConfig (const char* filepath) {
- json_object *policyConfigJ, *ignoreJ, *actionsJ;
- PolicyCtlConfigT *policyConfig = calloc (1, sizeof(PolicyCtlConfigT));
- int err;
-
- // Load JSON file
- policyConfigJ= json_object_from_file(filepath);
- if (!policyConfigJ) goto OnErrorExit;
-
- json_object *metadataJ, *onloadJ, *controlsJ, *eventsJ;
- err= wrap_json_unpack(policyConfigJ, "{s?o,so,s?o,so,so !}", "$schema", &ignoreJ, "metadata",&metadataJ, "onload",&onloadJ, "controls",&controlsJ, "events",&eventsJ);
- if (err) {
- AFB_ERROR ("POLICY-LOAD-ERRROR Missing something metadata|onload|controls|events in %s", json_object_get_string(policyConfigJ));
- goto OnErrorExit;
- }
-
- PolicyHandleT *policyHandle = calloc (1, sizeof(PolicyHandleT));
- err= wrap_json_unpack(metadataJ, "{so,s?s,s?s !}", "label", &policyHandle->label, "info",&policyHandle->info, "version",&policyHandle->version);
- if (err) {
- AFB_ERROR ("POLICY-LOAD-CONFIG Missing something label|info|version in %s", json_object_get_string(metadataJ));
- goto OnErrorExit;
- }
-
- if (onloadJ) {
- err= wrap_json_unpack(onloadJ, "{s?o,s?s,s?s !}", "info",&ignoreJ, "label",&ignoreJ, "actions",&actionsJ);
- if (err) {
- AFB_ERROR ("POLICY-LOAD-CONFIG Missing something label|info|plugin|actions in %s", json_object_get_string(metadataJ));
- goto OnErrorExit;
- }
- policyConfig->onload = PolicyLoadActions (actionsJ);
- }
-
- return policyControl;
-
-OnErrorExit:
- return NULL;
-}
-
-// Load default config file at init
-PUBLIC int PolicyInit () {
- int index, err;
-
-
- // search for default policy config file
- json_object* responseJ = ScanForConfig(CONTROL_CONFIG_PATH);
-
- for (index=0; index < json_object_array_length(responseJ); index++) {
- json_object *entryJ=json_object_array_get_idx(responseJ, index);
-
- char *filename; char*dirpath;
- err= wrap_json_unpack (entryJ, "{s:s, s:s !}", "dirpath", &dirpath,"filename", &filename);
- if (err) {
- AFB_ERROR ("POLICY-INIT HOOPs invalid config file path = %s", json_object_get_string(entryJ));
- goto OnErrorExit;
- }
-
- if (strcasestr(filename, CONTROL_CONFIG_FILE)) {
- char filepath[255];
- strncpy(filepath, dirpath, sizeof(filepath));
- strncat(filepath, "/", sizeof(filepath));
- strncat(filepath, filename, sizeof(filepath));
- ctlHandle = PolicyLoadConfig (filepath);
- if (!ctlHandle) goto OnErrorExit;
- break;
- }
- }
-
- // no policy config found remove control API from binder
- if (index == 0) goto OnErrorExit;
-
- AFB_NOTICE ("SUCCES: Audio Control Policy Init");
- return 0;
-
-OnErrorExit:
- AFB_NOTICE ("ERROR: Audio Control Policy Init");
- return 1;
-}
-
-
-
diff --git a/ctl-binding/CMakeLists.txt b/ctl-dispatch/CMakeLists.txt
index d62a1e2..b3d0c32 100644
--- a/ctl-binding/CMakeLists.txt
+++ b/ctl-dispatch/CMakeLists.txt
@@ -19,32 +19,22 @@
# Include LUA only when requested
if(CONTROL_SUPPORT_LUA)
message(STATUS "Notice: LUA Controler Support Selected")
- set(CTL_LUA_SOURCE ctl-lua.c)
+ set(CTL_LUA_SOURCE ctl-lua.c ctl-timer.c)
ADD_COMPILE_OPTIONS(-DCONTROL_SUPPORT_LUA)
- ADD_COMPILE_OPTIONS(-DCONTROL_LUA_EVENT="luaevt")
- ADD_COMPILE_OPTIONS(-DCONTROL_LUA_PATH="${CMAKE_SOURCE_DIR}/conf.d/project/lua.d:${CMAKE_INSTALL_PREFIX}/controller-plugins/ctl-lua.d")
else(CONTROL_SUPPORT_LUA)
message(STATUS "Warning: LUA Without Support ")
endif(CONTROL_SUPPORT_LUA)
+
# Add target to project dependency list
PROJECT_TARGET_ADD(afb-controller)
# Define project Targets
- ADD_LIBRARY(${TARGET_NAME} SHARED ctl-binding.c ctl-timer.c ctl-dispatch.c ${CTL_LUA_SOURCE})
-
- SET_OPENAPI_FILENAME("ctl-apidef")
- # Binder exposes a unique public entry point
- SET_TARGET_PROPERTIES(${TARGET_NAME} PROPERTIES
- PREFIX ""
- LABELS "BINDINGV2"
- LINK_FLAGS ${BINDINGS_LINK_FLAG}
- OUTPUT_NAME ${TARGET_NAME}
- )
+ ADD_LIBRARY(${TARGET_NAME} STATIC ctl-action.c ctl-config.c ctl-onload.c ctl-plugin.c ${CTL_LUA_SOURCE})
+ # Library dependencies (include updates automatically)
TARGET_LINK_LIBRARIES(${TARGET_NAME}
afb-utilities
- ${link_libraries}
)
# Define target includes for this target client
diff --git a/ctl-dispatch/ctl-action.c b/ctl-dispatch/ctl-action.c
new file mode 100644
index 0000000..b24269c
--- /dev/null
+++ b/ctl-dispatch/ctl-action.c
@@ -0,0 +1,174 @@
+/*
+ * Copyright (C) 2016 "IoT.bzh"
+ * Author Fulup Ar Foll <fulup@iot.bzh>
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, something express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * Reference:
+ * Json load using json_unpack https://jansson.readthedocs.io/en/2.9/apiref.html#parsing-and-validating-values
+ */
+
+#define _GNU_SOURCE
+#include <stdio.h>
+#include <string.h>
+
+#include "ctl-config.h"
+
+
+PUBLIC int ActionExecOne(CtlActionT* action, json_object *queryJ) {
+ int err;
+
+
+ switch (action->type) {
+ case CTL_TYPE_API:
+ {
+ json_object *returnJ;
+
+ // if query is empty increment usage count and pass args
+ if (!queryJ || json_object_get_type(queryJ) != json_type_object) {
+ json_object_get(action->argsJ);
+ queryJ = action->argsJ;
+ } else if (action->argsJ) {
+
+ // Merge queryJ and argsJ before sending request
+ if (json_object_get_type(action->argsJ) == json_type_object) {
+
+ json_object_object_foreach(action->argsJ, key, val) {
+ json_object_object_add(queryJ, key, val);
+ }
+ } else {
+ json_object_object_add(queryJ, "args", action->argsJ);
+ }
+ }
+
+ json_object_object_add(queryJ, "label", json_object_new_string(action->source.label));
+
+ int err = afb_service_call_sync(action->api, action->call, queryJ, &returnJ);
+ if (err) {
+ static const char*format = "ActionExecOne(Api) api=%s verb=%s args=%s";
+ AFB_ERROR(format, action->api, action->call, action->source.label);
+ goto OnErrorExit;
+ }
+ break;
+ }
+
+#ifdef CONTROL_SUPPORT_LUA
+ case CTL_TYPE_LUA:
+ err = LuaCallFunc(action, queryJ);
+ if (err) {
+ AFB_ERROR("ActionExecOne(Lua) label=%s func=%s args=%s", action->source.label, action->call, json_object_get_string(action->argsJ));
+ goto OnErrorExit;
+ }
+ break;
+#endif
+
+ case CTL_TYPE_CB:
+ err = (*action->actionCB) (&action->source, action->argsJ, queryJ);
+ if (err) {
+ AFB_ERROR("ActionExecOne(Callback) label%s func=%s args=%s", action->source.label, action->call, json_object_get_string(action->argsJ));
+ goto OnErrorExit;
+ }
+ break;
+
+ default:
+ {
+ AFB_ERROR("ActionExecOne(unknown) API type label=%s", action->source.label);
+ goto OnErrorExit;
+ }
+ }
+
+ return 0;
+
+OnErrorExit:
+ return -1;
+}
+
+
+// unpack individual action object
+
+PUBLIC int ActionLoadOne(CtlActionT *action, json_object *actionJ) {
+ char *api = NULL, *verb = NULL, *lua = NULL;
+ int err, modeCount = 0;
+ json_object *callbackJ=NULL;
+
+ err = wrap_json_unpack(actionJ, "{ss,s?s,s?o,s?s,s?s,s?s,s?o !}"
+ , "label", &action->source.label, "info", &action->source.info, "callback", &callbackJ, "lua", &lua, "api", &api, "verb", &verb, "args", &action->argsJ);
+ if (err) {
+ AFB_ERROR("ACTION-LOAD-ONE Missing something label|info|callback|lua|(api+verb)|args in:\n-- %s", json_object_get_string(actionJ));
+ goto OnErrorExit;
+ }
+
+ if (lua) {
+ action->type = CTL_TYPE_LUA;
+ action->call = lua;
+ modeCount++;
+ }
+
+ if (api && verb) {
+ action->type = CTL_TYPE_API;
+ action->api = api;
+ action->call = verb;
+ modeCount++;
+ }
+
+ if (callbackJ) {
+ action->type = CTL_TYPE_CB;
+ modeCount++;
+ err = PluginGetCB (action, callbackJ);
+ if (err) goto OnErrorExit;
+
+ }
+
+ // make sure at least one mode is selected
+ if (modeCount == 0) {
+ AFB_ERROR("ACTION-LOAD-ONE No Action Selected lua|callback|(api+verb) in %s", json_object_get_string(actionJ));
+ goto OnErrorExit;
+ }
+
+ if (modeCount > 1) {
+ AFB_ERROR("ACTION-LOAD-ONE:ToMany arguments lua|callback|(api+verb) in %s", json_object_get_string(actionJ));
+ goto OnErrorExit;
+ }
+ return 0;
+
+OnErrorExit:
+ return 1;
+};
+
+PUBLIC CtlActionT *ActionLoad(json_object *actionsJ) {
+ int err;
+ CtlActionT *actions;
+
+ // action array is close with a nullvalue;
+ if (json_object_get_type(actionsJ) == json_type_array) {
+ int count = json_object_array_length(actionsJ);
+ actions = calloc(count + 1, sizeof (CtlActionT));
+
+ for (int idx = 0; idx < count; idx++) {
+ json_object *actionJ = json_object_array_get_idx(actionsJ, idx);
+ err = ActionLoadOne(&actions[idx], actionJ);
+ if (err) goto OnErrorExit;
+ }
+
+ } else {
+ actions = calloc(2, sizeof (CtlActionT));
+ err = ActionLoadOne(&actions[0], actionsJ);
+ if (err) goto OnErrorExit;
+ }
+
+ return actions;
+
+OnErrorExit:
+ return NULL;
+
+}
diff --git a/ctl-dispatch/ctl-config.c b/ctl-dispatch/ctl-config.c
new file mode 100644
index 0000000..b7c0d54
--- /dev/null
+++ b/ctl-dispatch/ctl-config.c
@@ -0,0 +1,176 @@
+/*
+ * Copyright (C) 2016 "IoT.bzh"
+ * Author Fulup Ar Foll <fulup@iot.bzh>
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, something express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * Reference:
+ * Json load using json_unpack https://jansson.readthedocs.io/en/2.9/apiref.html#parsing-and-validating-values
+ */
+
+#define _GNU_SOURCE
+#include <stdio.h>
+#include <string.h>
+
+#include "filescan-utils.h"
+#include "ctl-config.h"
+
+
+// Load control config file
+
+PUBLIC char* CtlConfigSearch(const char *dirList) {
+ int index, err;
+ char controlFile [CONTROL_MAXPATH_LEN];
+
+ strncpy(controlFile, CONTROL_CONFIG_PRE "-", CONTROL_MAXPATH_LEN);
+ strncat(controlFile, GetBinderName(), CONTROL_MAXPATH_LEN);
+
+ // search for default dispatch config file
+ json_object* responseJ = ScanForConfig(dirList, CTL_SCAN_RECURSIVE, controlFile, ".json");
+
+ // We load 1st file others are just warnings
+ for (index = 0; index < json_object_array_length(responseJ); index++) {
+ json_object *entryJ = json_object_array_get_idx(responseJ, index);
+
+ char *filename;
+ char*fullpath;
+ err = wrap_json_unpack(entryJ, "{s:s, s:s !}", "fullpath", &fullpath, "filename", &filename);
+ if (err) {
+ AFB_ERROR("CTL-INIT HOOPs invalid JSON entry= %s", json_object_get_string(entryJ));
+ return NULL;
+ }
+
+ if (index == 0) {
+ if (strcasestr(filename, controlFile)) {
+ char filepath[CONTROL_MAXPATH_LEN];
+ strncpy(filepath, fullpath, sizeof (filepath));
+ strncat(filepath, "/", sizeof (filepath));
+ strncat(filepath, filename, sizeof (filepath));
+ return (strdup(filepath));
+ }
+ }
+ }
+
+ // no config found
+ return NULL;
+}
+
+PUBLIC int CtlConfigExec(CtlConfigT *ctlConfig) {
+ // best effort to initialise everything before starting
+ if (ctlConfig->requireJ) {
+
+ void DispatchRequireOneApi(json_object * bindindJ) {
+ const char* requireBinding = json_object_get_string(bindindJ);
+ int err = afb_daemon_require_api(requireBinding, 1);
+ if (err) {
+ AFB_WARNING("CTL-LOAD-CONFIG:REQUIRE Fail to get=%s", requireBinding);
+ }
+ }
+
+ if (json_object_get_type(ctlConfig->requireJ) == json_type_array) {
+ for (int idx = 0; idx < json_object_array_length(ctlConfig->requireJ); idx++) {
+ DispatchRequireOneApi(json_object_array_get_idx(ctlConfig->requireJ, idx));
+ }
+ } else {
+ DispatchRequireOneApi(ctlConfig->requireJ);
+ }
+ }
+
+#ifdef CONTROL_SUPPORT_LUA
+ int err= LuaConfigExec();
+ if (err) goto OnErrorExit;
+#endif
+
+ // Loop on every section and process config
+ int errcount=0;
+ for (int idx = 0; ctlConfig->sections[idx].key != NULL; idx++) {
+ errcount += ctlConfig->sections[idx].loadCB(&ctlConfig->sections[idx], NULL);
+ }
+ return errcount;
+
+OnErrorExit:
+ return 1;
+}
+
+PUBLIC CtlConfigT *CtlConfigLoad(const char* filepath, CtlSectionT *sections) {
+ json_object *ctlConfigJ;
+ CtlConfigT *ctlConfig;
+ int err;
+
+#ifdef CONTROL_SUPPORT_LUA
+ err= LuaConfigLoad();
+ if (err) goto OnErrorExit;
+#endif
+
+ // Search for config in filepath
+ filepath = CtlConfigSearch(filepath);
+
+ if (!filepath) {
+ AFB_ERROR("CTL-LOAD-CONFIG No JSON Config found invalid JSON %s ", filepath);
+ goto OnErrorExit;
+ }
+
+ // Load JSON file
+ ctlConfigJ = json_object_from_file(filepath);
+ if (!ctlConfigJ) {
+ AFB_ERROR("CTL-LOAD-CONFIG Not invalid JSON %s ", filepath);
+ goto OnErrorExit;
+ }
+
+ AFB_INFO("CTL-LOAD-CONFIG: loading config filepath=%s", filepath);
+
+ json_object *metadataJ;
+ int done = json_object_object_get_ex(ctlConfigJ, "metadata", &metadataJ);
+ if (done) {
+ ctlConfig = calloc(1, sizeof (CtlConfigT));
+ err = wrap_json_unpack(metadataJ, "{ss,ss,ss,s?s,s?o !}", "label", &ctlConfig->label, "version", &ctlConfig->version
+ , "api", &ctlConfig->api, "info", &ctlConfig->info, "require", &ctlConfig->requireJ);
+ if (err) {
+ AFB_ERROR("CTL-LOAD-CONFIG:METADATA Missing something label|api|version|[info]|[require] in:\n-- %s", json_object_get_string(metadataJ));
+ goto OnErrorExit;
+ }
+
+ // Should replace this with API name change
+ if (ctlConfig->api) {
+ err = afb_daemon_rename_api(ctlConfig->api);
+ if (err) AFB_WARNING("Fail to rename api to:%s", ctlConfig->api);
+ }
+
+ }
+
+ //load config sections
+ err = 0;
+ ctlConfig->sections = sections;
+ for (int idx = 0; sections[idx].key != NULL; idx++) {
+ json_object * sectionJ;
+ int done = json_object_object_get_ex(ctlConfigJ, sections[idx].key, &sectionJ);
+ if (!done) {
+ AFB_ERROR("CtlConfigLoad: fail to find '%s' section in config '%s'", sections[idx].key, filepath);
+ err++;
+ } else {
+ err += sections[idx].loadCB(&sections[idx], sectionJ);
+ }
+
+ }
+ if (err) goto OnErrorExit;
+
+ return (ctlConfig);
+
+OnErrorExit:
+ free(ctlConfig);
+ return NULL;
+}
+
+
+
+
diff --git a/ctl-dispatch/ctl-config.h b/ctl-dispatch/ctl-config.h
new file mode 100644
index 0000000..2e3a16a
--- /dev/null
+++ b/ctl-dispatch/ctl-config.h
@@ -0,0 +1,113 @@
+/*
+ * Copyright (C) 2016 "IoT.bzh"
+ * Author Fulup Ar Foll <fulup@iot.bzh>
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, something express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * Reference:
+ * Json load using json_unpack https://jansson.readthedocs.io/en/2.9/apiref.html#parsing-and-validating-values
+ */
+
+#ifndef _CTL_CONFIG_INCLUDE_
+#define _CTL_CONFIG_INCLUDE_
+
+#define _GNU_SOURCE
+#define AFB_BINDING_VERSION 2
+#include <afb/afb-binding.h>
+#include <json-c/json.h>
+#include <filescan-utils.h>
+#include <wrap-json.h>
+
+#include "ctl-plugin.h"
+
+#ifndef CONTROL_MAXPATH_LEN
+ #define CONTROL_MAXPATH_LEN 255
+#endif
+
+#ifndef CONTROL_CONFIG_PRE
+ #define CONTROL_CONFIG_PRE "onload"
+#endif
+
+#ifndef CTL_PLUGIN_EXT
+ #define CTL_PLUGIN_EXT ".ctlso"
+#endif
+
+
+
+typedef enum {
+ CTL_TYPE_NONE=0,
+ CTL_TYPE_API,
+ CTL_TYPE_CB,
+ CTL_TYPE_LUA,
+} CtlActionTypeT;
+
+
+typedef struct {
+ CtlActionTypeT type;
+ const char* api;
+ const char* call;
+ json_object *argsJ;
+ int (*actionCB)(CtlSourceT *source, json_object *argsJ, json_object *queryJ);
+ CtlSourceT source;
+} CtlActionT;
+
+typedef struct {
+ const char* label;
+ const char *info;
+ CtlActionT *actions;
+} DispatchHandleT;
+
+typedef struct ConfigSectionS {
+ const char *key;
+ const char *label;
+ const char *info;
+ int (*loadCB)(struct ConfigSectionS *section, json_object *sectionJ);
+ void *handle;
+} CtlSectionT;
+
+typedef struct {
+ const char* api;
+ const char* label;
+ const char *info;
+ const char *version;
+ json_object *requireJ;
+ CtlSectionT *sections;
+} CtlConfigT;
+
+
+#ifdef CONTROL_SUPPORT_LUA
+ #include "ctl-lua.h"
+#else
+ typedef void* Lua2cWrapperT;
+#endif
+
+
+// ctl-action.c
+PUBLIC CtlActionT *ActionLoad(json_object *actionsJ);
+PUBLIC int ActionExecOne(CtlActionT* action, json_object *queryJ);
+PUBLIC int ActionLoadOne(CtlActionT *action, json_object *actionJ);
+
+// ctl-config.c
+PUBLIC CtlConfigT *CtlConfigLoad(const char* filepath, CtlSectionT *sections);
+PUBLIC int CtlConfigExec(CtlConfigT *ctlConfig);
+
+// ctl-onload.c
+PUBLIC int OnloadConfig(CtlSectionT *section, json_object *actionsJ);
+
+
+// ctl-plugin.c
+PUBLIC int PluginConfig(CtlSectionT *section, json_object *pluginsJ);
+PUBLIC int PluginGetCB (CtlActionT *action , json_object *callbackJ);
+
+
+#endif /* _CTL_CONFIG_INCLUDE_ */ \ No newline at end of file
diff --git a/ctl-binding/ctl-lua.c b/ctl-dispatch/ctl-lua.c
index 2c80205..7b68fe2 100644
--- a/ctl-binding/ctl-lua.c
+++ b/ctl-dispatch/ctl-lua.c
@@ -28,9 +28,7 @@
#include <stdio.h>
#include <string.h>
-
-#include "ctl-binding.h"
-#include "wrap-json.h"
+#include "ctl-config.h"
#define LUA_FIST_ARG 2 // when using luaL_newlib calllback receive libtable as 1st arg
#define LUA_MSG_MAX_LENGTH 512
@@ -613,18 +611,18 @@ STATIC int LuaAfbEventMake(lua_State* luaState) {
}
// Function call from LUA when lua2c plugin L2C is used
-PUBLIC int Lua2cWrapper(lua_State* luaState, char *funcname, Lua2cFunctionT callback, void *context) {
+PUBLIC int Lua2cWrapper(lua_State* luaState, char *funcname, Lua2cFunctionT callback) {
json_object *argsJ= LuaPopArgs(luaState, LUA_FIST_ARG+1);
- int response = (*callback) (funcname, argsJ, context);
+ int response = (*callback) (funcname, argsJ);
// push response to LUA
lua_pushinteger(luaState, response);
return 1;
}
-// Generated some fake event based on watchdog/counter
-PUBLIC int LuaCallFunc (DispatchSourceT source, DispatchActionT *action, json_object *queryJ) {
+// Call a Lua function from a control action
+PUBLIC int LuaCallFunc (CtlActionT *action, json_object *queryJ) {
int err, count;
@@ -636,7 +634,7 @@ PUBLIC int LuaCallFunc (DispatchSourceT source, DispatchActionT *action, json_ob
// push source on the stack
count=1;
- lua_pushinteger(luaState, source);
+ lua_pushstring(luaState, action->source.label);
// push argsJ on the stack
if (!argsJ) {
@@ -741,8 +739,8 @@ STATIC void LuaDoAction (LuaDoActionT action, afb_req request) {
// search for filename=script in CONTROL_LUA_PATH
if (!luaScriptPathJ) {
strncpy(luaScriptPath,CONTROL_DOSCRIPT_PRE, sizeof(luaScriptPath));
- strncat(luaScriptPath,"-", sizeof(luaScriptPath)-strlen(luaScriptPath)-1);
- strncat(luaScriptPath,target, sizeof(luaScriptPath)-strlen(luaScriptPath)-1);
+ strncat(luaScriptPath,"-", sizeof(luaScriptPath));
+ strncat(luaScriptPath,target, sizeof(luaScriptPath));
luaScriptPathJ= ScanForConfig(CONTROL_LUA_PATH , CTL_SCAN_RECURSIVE,luaScriptPath,".lua");
}
for (index=0; index < json_object_array_length(luaScriptPathJ); index++) {
@@ -757,8 +755,8 @@ STATIC void LuaDoAction (LuaDoActionT action, afb_req request) {
if (index > 0) AFB_WARNING("LUA-DOSCRIPT-SCAN:Ignore second script=%s path=%s", filename, fullpath);
else {
strncpy (luaScriptPath, fullpath, sizeof(luaScriptPath));
- strncat (luaScriptPath, "/", sizeof(luaScriptPath)-strlen(luaScriptPath)-1);
- strncat (luaScriptPath, filename, sizeof(luaScriptPath)-strlen(luaScriptPath)-1);
+ strncat (luaScriptPath, "/", sizeof(luaScriptPath));
+ strncat (luaScriptPath, filename, sizeof(luaScriptPath));
}
}
@@ -778,7 +776,7 @@ STATIC void LuaDoAction (LuaDoActionT action, afb_req request) {
// if no func name given try to deduct from filename
if (!func && (func=(char*)GetMidleName(filename))!=NULL) {
strncpy(luaScriptPath,"_", sizeof(luaScriptPath));
- strncat(luaScriptPath,func, sizeof(luaScriptPath)-strlen(luaScriptPath)-1);
+ strncat(luaScriptPath,func, sizeof(luaScriptPath));
func=luaScriptPath;
}
if (!func) {
@@ -988,20 +986,9 @@ static const luaL_Reg afbFunction[] = {
{NULL, NULL} /* sentinel */
};
-// Create Binding Event at Init
-PUBLIC int LuaLibInit () {
- int err, index;
-
- // search for default policy config file
- char fullprefix[CONTROL_MAXPATH_LEN];
- strncpy (fullprefix, CONTROL_CONFIG_PRE "-", sizeof(fullprefix));
- strncat (fullprefix, GetBinderName(), sizeof(fullprefix)-strlen(fullprefix)-1);
- strncat (fullprefix, "-", sizeof(fullprefix)-strlen(fullprefix)-1);
-
- const char *dirList= getenv("CONTROL_LUA_PATH");
- if (!dirList) dirList=CONTROL_LUA_PATH;
-
- json_object *luaScriptPathJ = ScanForConfig(dirList , CTL_SCAN_RECURSIVE, fullprefix, "lua");
+// Load Lua Interpreter
+PUBLIC int LuaConfigLoad () {
+
// open a new LUA interpretor
luaState = luaL_newstate();
@@ -1016,7 +1003,17 @@ PUBLIC int LuaLibInit () {
// redirect print to AFB_NOTICE
luaL_newlib(luaState, afbFunction);
lua_setglobal(luaState, "AFB");
+
+ return 0;
+
+ OnErrorExit:
+ return 1;
+}
+// Create Binding Event at Init Exec Time
+PUBLIC int LuaConfigExec () {
+
+ int err, index;
// create default lua event to send test pause/resume
luaDefaultEvt=calloc(1,sizeof(LuaAfbEvent));
luaDefaultEvt->name=CONTROL_LUA_EVENT;
@@ -1026,6 +1023,22 @@ PUBLIC int LuaLibInit () {
goto OnErrorExit;;
}
+ // search for default policy config file
+ char fullprefix[CONTROL_MAXPATH_LEN];
+ strncpy (fullprefix, CONTROL_CONFIG_PRE "-", sizeof(fullprefix));
+ strncat (fullprefix, GetBinderName(), sizeof(fullprefix));
+ strncat (fullprefix, "-", sizeof(fullprefix));
+
+ const char *dirList= getenv("CONTROL_LUA_PATH");
+ if (!dirList) dirList=CONTROL_LUA_PATH;
+
+ // special case for no lua even when avaliable
+ if (!strcasecmp ("/dev/null", dirList)) {
+ return 0;
+ }
+
+ json_object *luaScriptPathJ = ScanForConfig(dirList , CTL_SCAN_RECURSIVE, fullprefix, "lua");
+
// load+exec any file found in LUA search path
for (index=0; index < json_object_array_length(luaScriptPathJ); index++) {
json_object *entryJ=json_object_array_get_idx(luaScriptPathJ, index);
@@ -1039,8 +1052,8 @@ PUBLIC int LuaLibInit () {
char filepath[CONTROL_MAXPATH_LEN];
strncpy(filepath, fullpath, sizeof(filepath));
- strncat(filepath, "/", sizeof(filepath)-strlen(filepath)-1);
- strncat(filepath, filename, sizeof(filepath)-strlen(filepath)-1);
+ strncat(filepath, "/", sizeof(filepath));
+ strncat(filepath, filename, sizeof(filepath));
err= luaL_loadfile(luaState, filepath);
if (err) {
AFB_ERROR ("LUA-LOAD HOOPs Error in LUA loading scripts=%s err=%s", filepath, lua_tostring(luaState,-1));
diff --git a/ctl-dispatch/ctl-lua.h b/ctl-dispatch/ctl-lua.h
new file mode 100644
index 0000000..6f2ce7d
--- /dev/null
+++ b/ctl-dispatch/ctl-lua.h
@@ -0,0 +1,77 @@
+/*
+ * Copyright (C) 2016 "IoT.bzh"
+ * Author Fulup Ar Foll <fulup@iot.bzh>
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, something express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * Reference:
+ * Json load using json_unpack https://jansson.readthedocs.io/en/2.9/apiref.html#parsing-and-validating-values
+ */
+
+#ifndef _LUA_CTL_INCLUDE_
+#define _LUA_CTL_INCLUDE_
+
+#define _GNU_SOURCE
+
+// prefix start debug script
+#ifndef CONTROL_DOSCRIPT_PRE
+#define CONTROL_DOSCRIPT_PRE "debug"
+#endif
+
+// default event name used by LUA
+#ifndef CONTROL_LUA_EVENT
+#define CONTROL_LUA_EVENT "luaevt"
+#endif
+
+// default use same search path for config.json and script.lua
+#ifndef CONTROL_LUA_PATH
+#define CONTROL_LUA_PATH CONTROL_CONFIG_PATH
+#endif
+
+// standard lua include file
+#ifdef CONTROL_SUPPORT_LUA
+#include "lua.h"
+#include "lauxlib.h"
+#include "lualib.h"
+#endif
+
+#include "ctl-timer.h"
+
+PUBLIC int LuaLibInit ();
+
+typedef int (*Lua2cFunctionT)(char *funcname, json_object *argsJ);
+typedef int (*Lua2cWrapperT) (lua_State* luaState, char *funcname, Lua2cFunctionT callback);
+
+#define CTLP_LUALOAD Lua2cWrapperT Lua2cWrap;
+#define CTLP_LUA2C(FuncName, label,argsJ, context) static int FuncName(char*label,json_object*argsJ);\
+ int lua2c_ ## FuncName(lua_State* luaState){return((*Lua2cWrap)(luaState, MACRO_STR_VALUE(FuncName), FuncName, PLUGIN_NAME));};\
+ static int FuncName(char* label, json_object* argsJ, void* context)
+
+typedef enum {
+ LUA_DOCALL,
+ LUA_DOSTRING,
+ LUA_DOSCRIPT,
+} LuaDoActionT;
+
+
+PUBLIC int LuaConfigLoad();
+PUBLIC int LuaConfigExec();
+PUBLIC void LuaL2cNewLib(const char *label, luaL_Reg *l2cFunc, int count);
+PUBLIC int Lua2cWrapper(lua_State* luaState, char *funcname, Lua2cFunctionT callback);
+PUBLIC int LuaCallFunc (CtlActionT *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);
+
+
+#endif \ No newline at end of file
diff --git a/ctl-dispatch/ctl-onload.c b/ctl-dispatch/ctl-onload.c
new file mode 100644
index 0000000..97bd109
--- /dev/null
+++ b/ctl-dispatch/ctl-onload.c
@@ -0,0 +1,57 @@
+/*
+ * Copyright (C) 2016 "IoT.bzh"
+ * Author Fulup Ar Foll <fulup@iot.bzh>
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, something express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+#define _GNU_SOURCE
+#include <stdio.h>
+#include <string.h>
+
+#include "ctl-config.h"
+
+// onload section receive one action or an array of actions
+PUBLIC int OnloadConfig(CtlSectionT *section, json_object *actionsJ) {
+ CtlActionT *actions;
+
+ // Load time parse actions in config file
+ if (actionsJ != NULL) {
+ actions= ActionLoad(actionsJ);
+ section->handle=actions;
+
+ if (!actions) {
+ AFB_ERROR ("OnloadLoad config fail processing onload actions");
+ goto OnErrorExit;
+ }
+
+ } else {
+ // Exec time process onload action now
+ actions=(CtlActionT*)section->handle;
+ if (!actions) {
+ AFB_ERROR ("OnloadLoad Cannot Exec Non Existing Onload Action");
+ goto OnErrorExit;
+ }
+
+ for (int idx=0; actions[idx].source.label != NULL; idx ++) {
+ ActionExecOne(&actions[idx], NULL);
+ }
+ }
+
+ return 0;
+
+OnErrorExit:
+ return 1;
+
+}
diff --git a/ctl-dispatch/ctl-plugin.c b/ctl-dispatch/ctl-plugin.c
new file mode 100644
index 0000000..f589035
--- /dev/null
+++ b/ctl-dispatch/ctl-plugin.c
@@ -0,0 +1,219 @@
+/*
+ * Copyright (C) 2016 "IoT.bzh"
+ * Author Fulup Ar Foll <fulup@iot.bzh>
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, something express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * Reference:
+ * Json load using json_unpack https://jansson.readthedocs.io/en/2.9/apiref.html#parsing-and-validating-values
+ */
+
+#define _GNU_SOURCE
+#include <string.h>
+#include <dlfcn.h>
+
+#include "ctl-config.h"
+
+static CtlPluginT *ctlPlugins=NULL;
+
+PUBLIC int PluginGetCB (CtlActionT *action , json_object *callbackJ) {
+ const char *plugin=NULL, *function=NULL;
+ json_object *argsJ;
+ int idx;
+
+ if (!ctlPlugins) {
+ AFB_ERROR ("PluginGetCB plugin section missing cannot call '%s'", json_object_get_string(callbackJ));
+ goto OnErrorExit;
+ }
+
+
+ int err = wrap_json_unpack(callbackJ, "{ss,ss,s?s,s?o!}", "plugin", &plugin, "function", &function, "args", &argsJ);
+ if (err) {
+ AFB_ERROR("PluginGet missing plugin|function|[args] in %s", json_object_get_string(callbackJ));
+ goto OnErrorExit;
+ }
+
+ for (idx=0; ctlPlugins[idx].label != NULL; idx++) {
+ if (!strcasecmp (ctlPlugins[idx].label, plugin)) break;
+ }
+
+ if (!ctlPlugins[idx].label) {
+ AFB_ERROR ("PluginGetCB no plugin with label=%s", plugin);
+ goto OnErrorExit;
+ }
+
+ action->actionCB = dlsym(ctlPlugins[idx].dlHandle, function);
+ action->source.context = ctlPlugins[idx].context;
+
+ if (!action->actionCB) {
+ AFB_ERROR ("PluginGetCB no plugin=%s no function=%s", plugin, function);
+ goto OnErrorExit;
+ }
+ return 0;
+
+OnErrorExit:
+ return 1;
+
+}
+
+// Wrapper to Lua2c plugin command add context and delegate to LuaWrapper
+STATIC int DispatchOneL2c(lua_State* luaState, char *funcname, Lua2cFunctionT callback) {
+#ifndef CONTROL_SUPPORT_LUA
+ AFB_ERROR("CTL-ONE-L2C: LUA support not selected (cf:CONTROL_SUPPORT_LUA) in config.cmake");
+ return 1;
+#else
+ int err=Lua2cWrapper(luaState, funcname, callback);
+ return err;
+#endif
+}
+
+STATIC int PluginLoadOne (CtlPluginT *ctlPlugin, json_object *pluginJ, void* handle) {
+ json_object *lua2csJ = NULL, *actionsJ = NULL;
+ const char*ldSearchPath = NULL, *basename = NULL;
+ void *dlHandle;
+
+
+ // plugin initialises at 1st load further init actions should be place into onload section
+ if (!pluginJ) return 0;
+
+ int err = wrap_json_unpack(pluginJ, "{ss,s?s,s?s,s?s,ss,s?o,s?o!}",
+ "label", &ctlPlugin->label, "version", &ctlPlugin->version, "info", &ctlPlugin->info, "ldpath", &ldSearchPath, "basename", &basename, "lua2c", &lua2csJ, "actions", &actionsJ);
+ if (err) {
+ AFB_ERROR("CTL-PLUGIN-LOADONE Plugin missing label|basename|version|[info]|[ldpath]|[lua2c]|[actions] in:\n-- %s", json_object_get_string(pluginJ));
+ goto OnErrorExit;
+ }
+
+ // if search path not in Json config file, then try default
+ if (!ldSearchPath) ldSearchPath = CONTROL_PLUGIN_PATH;
+
+ // search for default policy config file
+ json_object *pluginPathJ = ScanForConfig(ldSearchPath, CTL_SCAN_RECURSIVE, basename, CTL_PLUGIN_EXT);
+ if (!pluginPathJ || json_object_array_length(pluginPathJ) == 0) {
+ AFB_ERROR("CTL-PLUGIN-LOADONE Missing plugin=%s*%s (config ldpath?) search=\n-- %s", basename, CTL_PLUGIN_EXT, ldSearchPath);
+ goto OnErrorExit;
+ }
+
+ char *filename;
+ char*fullpath;
+ err = wrap_json_unpack(json_object_array_get_idx(pluginPathJ, 0), "{s:s, s:s !}", "fullpath", &fullpath, "filename", &filename);
+ if (err) {
+ AFB_ERROR("CTL-PLUGIN-LOADONE HOOPs invalid plugin file path=\n-- %s", json_object_get_string(pluginPathJ));
+ goto OnErrorExit;
+ }
+
+ if (json_object_array_length(pluginPathJ) > 1) {
+ AFB_WARNING("CTL-PLUGIN-LOADONE plugin multiple instances in searchpath will use %s/%s", fullpath, filename);
+ }
+
+ char pluginpath[CONTROL_MAXPATH_LEN];
+ strncpy(pluginpath, fullpath, sizeof (pluginpath));
+ strncat(pluginpath, "/", sizeof (pluginpath));
+ strncat(pluginpath, filename, sizeof (pluginpath));
+ dlHandle = dlopen(pluginpath, RTLD_NOW);
+ if (!dlHandle) {
+ AFB_ERROR("CTL-PLUGIN-LOADONE Fail to load pluginpath=%s err= %s", pluginpath, dlerror());
+ goto OnErrorExit;
+ }
+
+ CtlPluginMagicT *ctlPluginMagic = (CtlPluginMagicT*) dlsym(dlHandle, "CtlPluginMagic");
+ if (!ctlPluginMagic || ctlPluginMagic->magic != CTL_PLUGIN_MAGIC) {
+ AFB_ERROR("CTL-PLUGIN-LOADONE symbol'CtlPluginMagic' missing or != CTL_PLUGIN_MAGIC plugin=%s", pluginpath);
+ goto OnErrorExit;
+ } else {
+ AFB_NOTICE("CTL-PLUGIN-LOADONE %s successfully registered", ctlPluginMagic->label);
+ }
+
+ // store dlopen handle to enable onload action at exec time
+ ctlPlugin->dlHandle = dlHandle;
+
+ // Jose hack to make verbosity visible from sharelib
+ struct afb_binding_data_v2 *afbHidenData = dlsym(dlHandle, "afbBindingV2data");
+ if (afbHidenData) *afbHidenData = afbBindingV2data;
+
+ // Push lua2cWrapper @ into plugin
+ Lua2cWrapperT *lua2cInPlug = dlsym(dlHandle, "Lua2cWrap");
+#ifndef CONTROL_SUPPORT_LUA
+ if (lua2cInPlug) *lua2cInPlug = NULL;
+#else
+ // Lua2cWrapper is part of binder and not expose to dynamic link
+ if (lua2csJ && lua2cInPlug) {
+ *lua2cInPlug = DispatchOneL2c;
+
+ int Lua2cAddOne(luaL_Reg *l2cFunc, const char* l2cName, int index) {
+ char funcName[CONTROL_MAXPATH_LEN];
+ strncpy(funcName, "lua2c_", sizeof (funcName));
+ strncat(funcName, l2cName, sizeof (funcName));
+
+ Lua2cFunctionT l2cFunction = (Lua2cFunctionT) dlsym(dlHandle, funcName);
+ if (!l2cFunction) {
+ AFB_ERROR("CTL-PLUGIN-LOADONE symbol'%s' missing err=%s", funcName, dlerror());
+ return 1;
+ }
+ l2cFunc[index].func = (void*) l2cFunction;
+ l2cFunc[index].name = strdup(l2cName);
+
+ return 0;
+ }
+
+ int errCount = 0;
+ luaL_Reg *l2cFunc = NULL;
+
+ // look on l2c command and push them to LUA
+ if (json_object_get_type(lua2csJ) == json_type_array) {
+ int length = json_object_array_length(lua2csJ);
+ l2cFunc = calloc(length + 1, sizeof (luaL_Reg));
+ for (int count = 0; count < length; count++) {
+ int err;
+ const char *l2cName = json_object_get_string(json_object_array_get_idx(lua2csJ, count));
+ err = Lua2cAddOne(l2cFunc, l2cName, count);
+ if (err) errCount++;
+ }
+ } else {
+ l2cFunc = calloc(2, sizeof (luaL_Reg));
+ const char *l2cName = json_object_get_string(lua2csJ);
+ errCount = Lua2cAddOne(l2cFunc, l2cName, 0);
+ }
+ if (errCount) {
+ AFB_ERROR("CTL-PLUGIN-LOADONE %d symbols not found in plugin='%s'", errCount, pluginpath);
+ goto OnErrorExit;
+ }
+ }
+#endif
+ DispatchPluginInstallCbT ctlPluginOnload = dlsym(dlHandle, "CtlPluginOnload");
+ if (ctlPluginOnload) {
+ ctlPlugin->context = (*ctlPluginOnload) (ctlPlugin, handle);
+ }
+ return 0;
+
+OnErrorExit:
+ return 1;
+}
+
+
+PUBLIC int PluginConfig(CtlSectionT *section, json_object *pluginsJ) {
+ int err=0;
+
+ if (json_object_get_type(pluginsJ) == json_type_array) {
+ int length = json_object_array_length(pluginsJ);
+ ctlPlugins = calloc (length+1, sizeof(CtlPluginT));
+ for (int idx=0; idx < length; idx++) {
+ json_object *pluginJ = json_object_array_get_idx(pluginsJ, idx);
+ err += PluginLoadOne(&ctlPlugins[idx], pluginJ, section->handle);
+ }
+ } else {
+ ctlPlugins = calloc (2, sizeof(CtlPluginT));
+ err += PluginLoadOne(&ctlPlugins[0], pluginsJ, section->handle);
+ }
+
+ return err;
+} \ No newline at end of file
diff --git a/ctl-dispatch/ctl-plugin.h b/ctl-dispatch/ctl-plugin.h
new file mode 100644
index 0000000..e0ab3dd
--- /dev/null
+++ b/ctl-dispatch/ctl-plugin.h
@@ -0,0 +1,74 @@
+/*
+ * Copyright (C) 2016 "IoT.bzh"
+ * Author Fulup Ar Foll <fulup@iot.bzh>
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, something express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+
+#ifndef _CTL_PLUGIN_INCLUDE_
+#define _CTL_PLUGIN_INCLUDE_
+
+#define _GNU_SOURCE
+#include <json-c/json.h>
+
+#ifndef CTL_PLUGIN_MAGIC
+ #define CTL_PLUGIN_MAGIC 852369147
+#endif
+
+#ifndef PUBLIC
+ #define PUBLIC
+#endif
+
+#ifndef STATIC
+ #define STATIC static
+#endif
+
+#ifndef UNUSED_ARG
+ #define UNUSED_ARG(x) UNUSED_ ## x __attribute__((__unused__))
+ #define UNUSED_FUNCTION(x) __attribute__((__unused__)) UNUSED_ ## x
+#endif
+
+typedef struct {
+ char *label;
+ char *info;
+ afb_req request;
+ void *context;
+} CtlSourceT;
+
+
+typedef struct {
+ long magic;
+ char *label;
+ void *handle;
+} CtlPluginMagicT;
+
+
+typedef struct {
+ const char *label;
+ const char *info;
+ const char *version;
+ void *context;
+ void *dlHandle;
+} CtlPluginT;
+
+typedef void*(*DispatchPluginInstallCbT)(CtlPluginT *plugin, void* handle);
+
+
+#define MACRO_STR_VALUE(arg) #arg
+#define CTLP_REGISTER(pluglabel) CtlPluginMagicT CtlPluginMagic={.magic=CTL_PLUGIN_MAGIC,.label=pluglabel}; struct afb_binding_data_v2;
+#define CTLP_ONLOAD(plugin, handle) void* CtlPluginOnload(CtlPluginT *plugin, void* handle)
+#define CTLP_CAPI(funcname, source, argsJ, queryJ) int funcname(CtlSourceT *source, json_object* argsJ, json_object* queryJ)
+
+#endif /* _CTL_PLUGIN_INCLUDE_ */ \ No newline at end of file
diff --git a/ctl-binding/ctl-timer.c b/ctl-dispatch/ctl-timer.c
index 50e181b..1de6f99 100644
--- a/ctl-binding/ctl-timer.c
+++ b/ctl-dispatch/ctl-timer.c
@@ -19,9 +19,9 @@
#include <stdio.h>
#include <string.h>
#include <time.h>
-#include <systemd/sd-event.h>
-#include "ctl-binding.h"
+#include "ctl-config.h"
+#include "ctl-timer.h"
#define DEFAULT_PAUSE_DELAY 3000
#define DEFAULT_TEST_COUNT 1
diff --git a/ctl-dispatch/ctl-timer.h b/ctl-dispatch/ctl-timer.h
new file mode 100644
index 0000000..b08299f
--- /dev/null
+++ b/ctl-dispatch/ctl-timer.h
@@ -0,0 +1,42 @@
+/*
+ * Copyright (C) 2016 "IoT.bzh"
+ * Author Fulup Ar Foll <fulup@iot.bzh>
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+
+#ifndef CTL_TIMER_INCLUDE
+#define CTL_TIMER_INCLUDE
+
+#include <systemd/sd-event.h>
+
+// ctl-timer.c
+// ----------------------
+typedef int (*timerCallbackT)(void *context);
+
+typedef struct TimerHandleS {
+ int count;
+ int delay;
+ const char*label;
+ void *context;
+ 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);
+
+#endif // CTL_TIMER_INCLUDE
diff --git a/ctl-plugin/CMakeLists.txt b/ctl-plugin/CMakeLists.txt
deleted file mode 100644
index d89e67d..0000000
--- a/ctl-plugin/CMakeLists.txt
+++ /dev/null
@@ -1,52 +0,0 @@
-###########################################################################
-# Copyright 2015, 2016, 2017 IoT.bzh
-#
-# author: Fulup Ar Foll <fulup@iot.bzh>
-#
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-###########################################################################
-
-# Include LUA only when requested
-if(CONTROL_SUPPORT_LUA)
- message(STATUS "Notice: LUA Controler Support Selected")
- set(CTL_LUA_SOURCE ctl-lua.c)
- ADD_COMPILE_OPTIONS(-DCONTROL_SUPPORT_LUA)
- ADD_COMPILE_OPTIONS(-DCONTROL_LUA_EVENT="luaevt")
- ADD_COMPILE_OPTIONS(-DCONTROL_LUA_PATH="${CMAKE_SOURCE_DIR}/conf.d/project/lua.d:${CMAKE_INSTALL_PREFIX}/controller-plugins/ctl-lua.d")
-else(CONTROL_SUPPORT_LUA)
- message(STATUS "Warning: LUA Without Support ")
-endif(CONTROL_SUPPORT_LUA)
-
-
-PROJECT_TARGET_ADD(audio-plugin-sample)
-
- # Define targets
- ADD_LIBRARY(${TARGET_NAME} MODULE ctl-plugin-sample.c)
-
- # Alsa Plugin properties
- SET_TARGET_PROPERTIES(${TARGET_NAME} PROPERTIES
- PREFIX ${CTL_PLUGIN_PRE}
- SUFFIX ${CTL_PLUGIN_EXT}
- OUTPUT_NAME ${TARGET_NAME}
- )
-
- # Library dependencies (include updates automatically)
- TARGET_LINK_LIBRARIES(${TARGET_NAME}
- afb-utilities
- ${link_libraries}
- )
-
- include_directories("../ctl-binding")
-
-
-
diff --git a/ctl-plugin/ctl-plugin-sample.c b/ctl-plugin/ctl-plugin-sample.c
deleted file mode 100644
index 300bd1c..0000000
--- a/ctl-plugin/ctl-plugin-sample.c
+++ /dev/null
@@ -1,134 +0,0 @@
-/*
- * Copyright (C) 2016 "IoT.bzh"
- * Author Fulup Ar Foll <fulup@iot.bzh>
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- * Sample plugin for Controller
- */
-
-
-#define _GNU_SOURCE
-#include <stdio.h>
-#include <string.h>
-
-#include "ctl-binding.h"
-
-#define MY_PLUGIN_MAGIC 987654321
-
-typedef struct {
- int magic;
- int count;
-} MyPluginCtxT;
-
-STATIC const char* jsonToString (json_object *valueJ) {
- const char *value;
- if (valueJ)
- value=json_object_get_string(valueJ);
- else
- value="NULL";
-
- return value;
-}
-
-// Declare this sharelib as a Controller Plugin
-CTLP_REGISTER("MyCtlSamplePlugin");
-
-// Call at initialisation time
-PUBLIC CTLP_ONLOAD(label, version, info) {
- MyPluginCtxT *pluginCtx= (MyPluginCtxT*)calloc (1, sizeof(MyPluginCtxT));
- pluginCtx->magic = MY_PLUGIN_MAGIC;
- pluginCtx->count = -1;
-
- AFB_NOTICE ("CONTROLLER-PLUGIN-SAMPLE:Onload label=%s version=%s info=%s", label, info, version);
- return (void*)pluginCtx;
-}
-
-PUBLIC CTLP_CAPI (SamplePolicyInit, source, label, argsJ, queryJ, context) {
- MyPluginCtxT *pluginCtx= (MyPluginCtxT*)context;
- if (!context || pluginCtx->magic != MY_PLUGIN_MAGIC) {
- AFB_ERROR("CONTROLLER-PLUGIN-SAMPLE:SamplePolicyInit (Hoops) Invalid Sample Plugin Context");
- return -1;
- };
-
- pluginCtx->count = 0;
- AFB_NOTICE ("CONTROLLER-PLUGIN-SAMPLE:Init label=%s args=%s\n", label, jsonToString(argsJ));
- return 0;
-}
-
-PUBLIC CTLP_CAPI (sampleControlMultimedia, source, label, argsJ,queryJ,context) {
- MyPluginCtxT *pluginCtx= (MyPluginCtxT*)context;
-
- if (!context || pluginCtx->magic != MY_PLUGIN_MAGIC) {
- AFB_ERROR("CONTROLLER-PLUGIN-SAMPLE:sampleControlMultimedia (Hoops) Invalid Sample Plugin Context");
- return -1;
- };
- pluginCtx->count++;
- AFB_NOTICE ("CONTROLLER-PLUGIN-SAMPLE:sampleControlMultimedia SamplePolicyCount action=%s args=%s query=%s count=%d"
- , label, jsonToString(argsJ), jsonToString(queryJ), pluginCtx->count);
- return 0;
-}
-
-PUBLIC CTLP_CAPI (sampleControlNavigation, source, label, argsJ, queryJ, context) {
- MyPluginCtxT *pluginCtx= (MyPluginCtxT*)context;
-
- if (!context || pluginCtx->magic != MY_PLUGIN_MAGIC) {
- AFB_ERROR("CONTROLLER-PLUGIN-SAMPLE:sampleControlNavigation (Hoops) Invalid Sample Plugin Context");
- return -1;
- };
- pluginCtx->count++;
- AFB_NOTICE ("CONTROLLER-PLUGIN-SAMPLE:sampleControlNavigation SamplePolicyCount action=%s args=%s query=%s count=%d"
- ,label, jsonToString(argsJ), jsonToString(queryJ), pluginCtx->count);
- return 0;
-}
-
-PUBLIC CTLP_CAPI (SampleControlEvent, source, label, argsJ, queryJ, context) {
- MyPluginCtxT *pluginCtx= (MyPluginCtxT*)context;
-
- if (!context || pluginCtx->magic != MY_PLUGIN_MAGIC) {
- AFB_ERROR("CONTROLLER-PLUGIN-SAMPLE:cousampleControlMultimediant (Hoops) Invalid Sample Plugin Context");
- return -1;
- };
- pluginCtx->count++;
- AFB_NOTICE ("CONTROLLER-PLUGIN-SAMPLE:sampleControlMultimedia SamplePolicyCount action=%s args=%s query=%s count=%d"
- ,label, jsonToString(argsJ), jsonToString(queryJ), pluginCtx->count);
- return 0;
-}
-
-// This function is a LUA function. Lua2CHelloWorld label should be declare in the "onload" section of JSON config file
-PUBLIC CTLP_LUA2C (Lua2cHelloWorld1, label, argsJ, context) {
- MyPluginCtxT *pluginCtx= (MyPluginCtxT*)context;
-
- if (!context || pluginCtx->magic != MY_PLUGIN_MAGIC) {
- AFB_ERROR("CONTROLLER-PLUGIN-SAMPLE:Lua2cHelloWorld1 (Hoops) Invalid Sample Plugin Context");
- return -1;
- };
- pluginCtx->count++;
- AFB_NOTICE ("CONTROLLER-PLUGIN-SAMPLE:Lua2cHelloWorld1 SamplePolicyCount action=%s args=%s count=%d"
- ,label, jsonToString(argsJ), pluginCtx->count);
- return 0;
-}
-
-// This function is a LUA function. Lua2CHelloWorld label should be declare in the "onload" section of JSON config file
-PUBLIC CTLP_LUA2C (Lua2cHelloWorld2, label, argsJ, context) {
- MyPluginCtxT *pluginCtx= (MyPluginCtxT*)context;
-
- if (!context || pluginCtx->magic != MY_PLUGIN_MAGIC) {
- AFB_ERROR("CONTROLLER-PLUGIN-SAMPLE:Lua2cHelloWorld2 (Hoops) Invalid Sample Plugin Context");
- return -1;
- };
- pluginCtx->count++;
- AFB_NOTICE ("CONTROLLER-PLUGIN-SAMPLE:Lua2cHelloWorld2 SamplePolicyCount action=%s args=%s count=%d"
- ,label, jsonToString(argsJ), pluginCtx->count);
- return 0;
-}
diff --git a/htdocs/AFB-websock.js b/htdocs/AFB-websock.js
deleted file mode 100644
index 99ab3b8..0000000
--- a/htdocs/AFB-websock.js
+++ /dev/null
@@ -1,177 +0,0 @@
-var urlws;
-var urlhttp;
-
-AFB = function(base, initialtoken){
-
-urlws = "ws://"+window.location.host+"/"+base;
-urlhttp = "http://"+window.location.host+"/"+base;
-
-/*********************************************/
-/**** ****/
-/**** AFB_context ****/
-/**** ****/
-/*********************************************/
-var AFB_context;
-{
- var UUID = undefined;
- var TOKEN = initialtoken;
-
- var context = function(token, uuid) {
- this.token = token;
- this.uuid = uuid;
- }
-
- context.prototype = {
- get token() {return TOKEN;},
- set token(tok) {if(tok) TOKEN=tok;},
- get uuid() {return UUID;},
- set uuid(id) {if(id) UUID=id;}
- };
-
- AFB_context = new context();
-}
-/*********************************************/
-/**** ****/
-/**** AFB_websocket ****/
-/**** ****/
-/*********************************************/
-var AFB_websocket;
-{
- var CALL = 2;
- var RETOK = 3;
- var RETERR = 4;
- var EVENT = 5;
-
- var PROTO1 = "x-afb-ws-json1";
-
- AFB_websocket = function(onopen, onabort) {
- var u = urlws;
- if (AFB_context.token) {
- u = u + '?x-afb-token=' + AFB_context.token;
- if (AFB_context.uuid)
- u = u + '&x-afb-uuid=' + AFB_context.uuid;
- }
- this.ws = new WebSocket(u, [ PROTO1 ]);
- this.pendings = {};
- this.awaitens = {};
- this.counter = 0;
- this.ws.onopen = onopen.bind(this);
- this.ws.onerror = onerror.bind(this);
- this.ws.onclose = onclose.bind(this);
- this.ws.onmessage = onmessage.bind(this);
- this.onopen = onopen;
- this.onabort = onabort;
- this.onclose = onabort;
- }
-
- function onerror(event) {
- var f = this.onabort;
- if (f) {
- delete this.onopen;
- delete this.onabort;
- f && f(this);
- }
- this.onerror && this.onerror(this);
- }
-
- function onopen(event) {
- var f = this.onopen;
- delete this.onopen;
- delete this.onabort;
- f && f(this);
- }
-
- function onclose(event) {
- for (var id in this.pendings) {
- var ferr = this.pendings[id].onerror;
- ferr && ferr(null, this);
- }
- this.pendings = {};
- this.onclose && this.onclose();
- }
-
- function fire(awaitens, name, data) {
- var a = awaitens[name];
- if (a)
- a.forEach(function(handler){handler(data);});
- var i = name.indexOf("/");
- if (i >= 0) {
- a = awaitens[name.substring(0,i)];
- if (a)
- a.forEach(function(handler){handler(data);});
- }
- a = awaitens["*"];
- if (a)
- a.forEach(function(handler){handler(data);});
- }
-
- function reply(pendings, id, ans, offset) {
- if (id in pendings) {
- var p = pendings[id];
- delete pendings[id];
- var f = p[offset];
- f(ans);
- }
- }
-
- function onmessage(event) {
- var obj = JSON.parse(event.data);
- var code = obj[0];
- var id = obj[1];
- var ans = obj[2];
- AFB_context.token = obj[3];
- switch (code) {
- case RETOK:
- reply(this.pendings, id, ans, 0);
- break;
- case RETERR:
- reply(this.pendings, id, ans, 1);
- break;
- case EVENT:
- default:
- fire(this.awaitens, id, ans);
- break;
- }
- }
-
- function close() {
- this.ws.close();
- this.onabort();
- }
-
- function call(method, request) {
- return new Promise((function(resolve, reject){
- var id, arr;
- do {
- id = String(this.counter = 4095 & (this.counter + 1));
- } while (id in this.pendings);
- this.pendings[id] = [ resolve, reject ];
- arr = [CALL, id, method, request ];
- if (AFB_context.token) arr.push(AFB_context.token);
- this.ws.send(JSON.stringify(arr));
- }).bind(this));
- }
-
- function onevent(name, handler) {
- var id = name;
- var list = this.awaitens[id] || (this.awaitens[id] = []);
- list.push(handler);
- }
-
- AFB_websocket.prototype = {
- close: close,
- call: call,
- onevent: onevent
- };
-}
-/*********************************************/
-/**** ****/
-/**** ****/
-/**** ****/
-/*********************************************/
-return {
- context: AFB_context,
- ws: AFB_websocket
-};
-};
-
diff --git a/htdocs/AudioBinding.css b/htdocs/AudioBinding.css
deleted file mode 100644
index 1052aa7..0000000
--- a/htdocs/AudioBinding.css
+++ /dev/null
@@ -1,7 +0,0 @@
-pre {outline: 1px solid #ccc; padding: 5px; margin: 5px; }
-.string { color: green; }
-.number { color: darkorange; }
-.boolean { color: blue; }
-.null { color: magenta; }
-.key { color: red; }
-
diff --git a/htdocs/AudioBinding.js b/htdocs/AudioBinding.js
deleted file mode 100644
index 0f5caf9..0000000
--- a/htdocs/AudioBinding.js
+++ /dev/null
@@ -1,197 +0,0 @@
- var afb = new AFB("api", "mysecret");
- var ws;
- var sndcard="HALNotSelected";
- var evtidx=0;
- var numid=0;
-
- function syntaxHighlight(json) {
- if (typeof json !== 'string') {
- json = JSON.stringify(json, undefined, 2);
- }
- json = json.replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;');
- return json.replace(/("(\\u[a-zA-Z0-9]{4}|\\[^u]|[^\\"])*"(\s*:)?|\b(true|false|null)\b|-?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?)/g, function (match) {
- var cls = 'number';
- if (/^"/.test(match)) {
- if (/:$/.test(match)) {
- cls = 'key';
- } else {
- cls = 'string';
- }
- } else if (/true|false/.test(match)) {
- cls = 'boolean';
- } else if (/null/.test(match)) {
- cls = 'null';
- }
- return '<span class="' + cls + '">' + match + '</span>';
- });
- }
-
- function getParameterByName(name, url) {
- if (!url) {
- url = window.location.href;
- }
- name = name.replace(/[\[\]]/g, "\\$&");
- var regex = new RegExp("[?&]" + name + "(=([^&#]*)|&|#|$)"),
- results = regex.exec(url);
- if (!results) return null;
- if (!results[2]) return '';
- return decodeURIComponent(results[2].replace(/\+/g, " "));
- }
-
- // default soundcard is "PCH"
- var devid=getParameterByName("devid");
- if (!devid) devid="hw:1";
-
- var haldev=getParameterByName("haldev");
- if (!haldev) haldev="scarlett-usb";
-
- var sndname=getParameterByName("sndname");
- if (!sndname) sndname="PCH";
-
- var mode=getParameterByName("mode");
- if (!mode) mode="0";
-
-
-
-
- function replyok(obj) {
- console.log("replyok:" + JSON.stringify(obj));
- document.getElementById("output").innerHTML = "OK: "+ syntaxHighlight(obj);
- }
-
- function replyerr(obj) {
- console.log("replyerr:" + JSON.stringify(obj));
- document.getElementById("output").innerHTML = "ERROR: "+ syntaxHighlight(obj);
- }
-
- function gotevent(obj) {
- console.log("gotevent:" + JSON.stringify(obj));
- document.getElementById("outevt").innerHTML = (evtidx++) +": "+JSON.stringify(obj);
- }
-
- function send(message) {
- var api = document.getElementById("api").value;
- var verb = document.getElementById("verb").value;
- document.getElementById("question").innerHTML = "subscribe: "+api+"/"+verb + " (" + JSON.stringify(message) +")";
- ws.call(api+"/"+verb, {data:message}).then(replyok, replyerr);
- }
-
-
- // On button click from HTML page
- function callbinder(api, verb, query) {
- console.log ("subscribe api="+api+" verb="+verb+" query=" +query);
- var question = urlws +"/" +api +"/" +verb + "?query=" + JSON.stringify(query);
- document.getElementById("question").innerHTML = syntaxHighlight(question);
- ws.call(api+"/"+verb, query).then(replyok, replyerr);
- }
-
-
- // Retreive Select value and Text from the binder
- // Note: selection of value/text for a given context is huggly!!!
- function querySelectList (elemid, api, verb, query) {
-
- console.log("querySelectList elemid=%s api=%s verb=%s query=%s", elemid, api, verb, query);
-
- var selectobj = document.getElementById(elemid);
- if (!selectobj) {
- return;
- }
-
- // onlick update selected HAL api
- selectobj.onclick=function(){
- sndcard= this.value;
- console.log ("Default Selection=" + sndcard);
- };
-
- function gotit (result) {
-
- // display response as for normal onclick action
- replyok(result);
- var response=result.response;
-
- // fulfill select with avaliable active HAL
- for (idx=0; idx<response.length; idx++) {
- var opt = document.createElement('option');
-
- // Alsa LowLevel selection mode
- if (response[idx].name) opt.text = response[idx].name;
- if (response[idx].devid) opt.value = response[idx].devid;
-
- // HAL selection mode
- if (response[idx].shortname) opt.text = response[idx].shortname;
- if (response[idx].api) opt.value = response[idx].api;
-
- selectobj.appendChild(opt);
- }
-
- sndcard= selectobj.value;
- }
-
- var question = urlws +"/"+api +"/" +verb + "?query=" + JSON.stringify(query);
- document.getElementById("question").innerHTML = syntaxHighlight(question);
-
- // request lowlevel ALSA to get API list
- ws.call(api+"/"+verb, query).then(gotit, replyerr);
- }
-
- function refresh_list (self, api, verb, query) {
- console.log("refresh_list id=%s api=%s verb=%s query=%s", self.id, api, verb, query);
-
- if (self.value > 0) return;
-
- // onlick update selected HAL api
- self.onclick=function(){
- numid = parseInt(self.value);
- console.log ("Default numid=%d", numid);
- };
-
- function gotit (result) {
-
- // display response as for normal onclick action
- replyok(result);
- var response=result.response;
-
-
-
- // fulfill select with avaliable active HAL
- for (idx=0; idx<response.length; idx++) {
- var opt = document.createElement('option');
-
- // Alsa LowLevel selection mode
- opt.text = response[idx].name + ' id=' + response[idx].id;
- opt.value = response[idx].id;
-
- self.appendChild(opt);
- }
- self.selectedIndex=2;
- numid = parseInt (self.value);
- }
-
- var question = urlws +"/"+api +"/" +verb + "?query=" + JSON.stringify(query);
- document.getElementById("question").innerHTML = syntaxHighlight(question);
-
- // request lowlevel ALSA to get API list
- ws.call(api+"/"+verb, query).then(gotit, replyerr);
- }
-
-
- function init(elemid, api, verb, query) {
-
- function onopen() {
- // check for active HALs
- querySelectList (elemid, api, verb, query);
-
- document.getElementById("main").style.visibility = "visible";
- document.getElementById("connected").innerHTML = "Binder WS Active";
- document.getElementById("connected").style.background = "lightgreen";
- ws.onevent("*", gotevent);
- }
-
- function onabort() {
- document.getElementById("main").style.visibility = "hidden";
- document.getElementById("connected").innerHTML = "Connected Closed";
- document.getElementById("connected").style.background = "red";
-
- }
- ws = new afb.ws(onopen, onabort);
- }
diff --git a/htdocs/CMakeLists.txt b/htdocs/CMakeLists.txt
deleted file mode 100644
index 322033d..0000000
--- a/htdocs/CMakeLists.txt
+++ /dev/null
@@ -1,34 +0,0 @@
-###########################################################################
-# Copyright 2015, 2016, 2017 IoT.bzh
-#
-# author: Fulup Ar Foll <fulup@iot.bzh>
-#
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-###########################################################################
-
-
-
-##################################################
-# HTML Testing Files
-##################################################
-PROJECT_TARGET_ADD(htdocs)
-
- file(GLOB SOURCE_FILES "*.html" "*.js" "*.jpg" "*.css")
-
- add_input_files("${SOURCE_FILES}")
-
- SET_TARGET_PROPERTIES(${TARGET_NAME} PROPERTIES
- LABELS "HTDOCS"
- OUTPUT_NAME ${TARGET_NAME}
- )
-
diff --git a/htdocs/README.md b/htdocs/README.md
deleted file mode 100644
index 7aafea0..0000000
--- a/htdocs/README.md
+++ /dev/null
@@ -1,7 +0,0 @@
-------------------------------------------------------------------------
- Basic HTML & WS test
-------------------------------------------------------------------------
-
- # Load bindings directly from development tree for debug
- AFB_BINDER_NAME='sample' afb-daemon --verbose --verbose --token="" --ldpaths=build --port=1234 --roothttp=htdocs
-
diff --git a/htdocs/index.html b/htdocs/index.html
deleted file mode 100644
index 3d51f2f..0000000
--- a/htdocs/index.html
+++ /dev/null
@@ -1,37 +0,0 @@
-<html>
-<head>
- <title>Simple COntroller Test</title>
- <link rel="stylesheet" href="AudioBinding.css">
- <script type="text/javascript" src="AFB-websock.js"></script>
- <script type="text/javascript" src="AudioBinding.js"></script>
-</head>
-
-<body onload="init('hal_registry','alsacore', 'hallist')">
-
- <h1>Simple Control Test</h1>
- <button id="connected" onclick="init('hal_registry','alsacore', 'hallist')">Binder WS Fail</button>
- <button id="mnitoring" onclick="window.open('/monitoring/monitor.html','_monitor_ctl')">Debug/Monitoring</a></button>
- <br><br>
-
-
- <ol>
-
- <li><button onclick="callbinder('control','dispatch' ,{'target':'Button-Happy',args:{'var1':1234, 'var2':4567}});">Button Happy (Granted)</button></li>
- <li><button onclick="callbinder('control','dispatch' ,{'target':'Button-UnHappy',args:{'var1':1234, 'var2':4567}});">Button UnHappy (Refused)</button></li>
- <br>
- <li><button onclick="callbinder('control','request' ,{'target':'_Simple_Timer_Test',args:{'label':'myTimer', 'delay':3000, 'count':10}});">Start Events Timer</button></li>
- <br>
- <li><button onclick="callbinder('control','request' ,{'target':'_Simple_Echo_Args', 'args':{speed:20}});">Simple Echo args</button></li>
- <li><button onclick="callbinder('control','request' ,{'target':'_Simple_Monitor_Call', 'args':{verbosity:true}});">Service Call to Monitor</button></li>
- <br>
- <li><button onclick="callbinder('control','debuglua' ,{'target':'helloworld', args:{'arg1':'abcd', 'next':7890, 'last':[1,2,3,4]}});">Lua Debug Script</button></li>
-
- </ol>
-
- <div id="main" style="visibility:hidden">
- <ol>
- <li>Question <pre id="question"></pre>
- <li>Response <pre id="output"></pre>
- <li>Events: <pre id="outevt"></pre>
- </ol>
- </div>
diff --git a/nbproject/project.xml b/nbproject/project.xml
index 193a3cd..0ba53c6 100644
--- a/nbproject/project.xml
+++ b/nbproject/project.xml
@@ -3,7 +3,7 @@
<type>org.netbeans.modules.cnd.makeproject</type>
<configuration>
<data xmlns="http://www.netbeans.org/ns/make-project/1">
- <name>AFB-Controller</name>
+ <name>ctl-utilities</name>
<c-extensions>c</c-extensions>
<cpp-extensions>cpp,cxx</cpp-extensions>
<header-extensions>h</header-extensions>