From 082d083a96f4be23ea6f54fc26eeaece7cfa4507 Mon Sep 17 00:00:00 2001 From: Fulup Ar Foll Date: Fri, 18 Aug 2017 01:43:18 +0200 Subject: Documented Controller standalone mode and provided a sample config. --- Controller-afb/README.md | 11 +++ .../project/config.d/onload-daemon-standalone.json | 72 ++++++++++++++++++ .../lua.d/standalone-sample/onload-daemon-00.lua | 86 ++++++++++++++++++++++ .../lua.d/standalone-sample/onload-daemon-01.lua | 57 ++++++++++++++ 4 files changed, 226 insertions(+) create mode 100644 conf.d/project/config.d/onload-daemon-standalone.json create mode 100644 conf.d/project/lua.d/standalone-sample/onload-daemon-00.lua create mode 100644 conf.d/project/lua.d/standalone-sample/onload-daemon-01.lua diff --git a/Controller-afb/README.md b/Controller-afb/README.md index 403f637..e6cab72 100644 --- a/Controller-afb/README.md +++ b/Controller-afb/README.md @@ -183,6 +183,17 @@ input parameter. When funcname is not given by default the controller try to exe 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 +``` +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. + ## Config Sample Here after a simple configuration sample. diff --git a/conf.d/project/config.d/onload-daemon-standalone.json b/conf.d/project/config.d/onload-daemon-standalone.json new file mode 100644 index 0000000..de52c22 --- /dev/null +++ b/conf.d/project/config.d/onload-daemon-standalone.json @@ -0,0 +1,72 @@ +{ + "$schema": "ToBeDone", + "metadata": { + "label": "sample-standalone-control", + "info": "Minimal Standalone Controller Config", + "version": "1.0" + }, + "onload": [{ + "label": "onload-default", + "info": "onload initialisation config", + "actions": + { + "label": "control-init", + "lua": "_Control_Init" + } + }], + "controls": + [ + { + "label": "Button-1", + "actions": { + "label": "Action on Button One", + "lua": "_Button_Press", + "args": { + "button": 1 + } + } + }, { + "label": "Button-1", + "actions": { + "label": "Action on Button Two", + "lua": "_Button_Press", + "args": { + "button": 2 + } + } + }, { + "label": "Button-1", + "actions": { + "label": "Action on Button Three", + "lua": "_Button_Press", + "args": { + "button": 3 + } + } + } + ], + "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/standalone-sample/onload-daemon-00.lua b/conf.d/project/lua.d/standalone-sample/onload-daemon-00.lua new file mode 100644 index 0000000..b8ecd7e --- /dev/null +++ b/conf.d/project/lua.d/standalone-sample/onload-daemon-00.lua @@ -0,0 +1,86 @@ +--[[ + Copyright (C) 2016 "IoT.bzh" + Author Fulup Ar Foll + + 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/standalone-sample/onload-daemon-01.lua b/conf.d/project/lua.d/standalone-sample/onload-daemon-01.lua new file mode 100644 index 0000000..7b22db0 --- /dev/null +++ b/conf.d/project/lua.d/standalone-sample/onload-daemon-01.lua @@ -0,0 +1,57 @@ +--[[ + Copyright (C) 2016 "IoT.bzh" + Author Fulup Ar Foll + + 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 + +--]] + +-- Set Navigation lower sound when play +function _Control_Init(source, args) + + -- in strict mode every variables should be declared + local err=0 + + AFB:notice ("Control_Init args=%s", args); + + return 0 -- control accepted +end + +-- Set Navigation lower sound when play +function _Button_Press(source, args, query) + + -- in strict mode every variables should be declared + local err=0 + + AFB:notice ("Button_Press button=%s", args["button"]); + + return 0 -- control accepted +end + +-- Set Navigation lower sound when play +function _Event_Received(source, args, query) + + -- in strict mode every variables should be declared + local err=0 + + AFB:notice ("Event_Received event=%s", args["evtname"]); + + return 0 -- control accepted +end + -- cgit 1.2.3-korg