diff options
-rw-r--r-- | Controler-afb/ctl-apidef.h | 41 | ||||
-rw-r--r-- | Controler-afb/ctl-apidef.json | 2 | ||||
-rw-r--r-- | Controler-afb/ctl-binding.h | 17 | ||||
-rw-r--r-- | Controler-afb/ctl-lua.c | 182 | ||||
-rw-r--r-- | Controler-afb/ctl-misc.c | 35 | ||||
-rw-r--r-- | Controler-afb/ctl-misc2.c | 74 | ||||
-rw-r--r-- | conf.d/cmake/config.cmake | 1 | ||||
-rw-r--r-- | conf.d/project/config.d/onload-audio-control.json | 6 | ||||
-rw-r--r-- | conf.d/project/lua.d/doscript-helloworld.lua | 36 | ||||
-rw-r--r-- | conf.d/project/lua.d/onload-audio-controls.lua (renamed from conf.d/project/lua.d/onload-audio-policy.lua) | 13 | ||||
-rw-r--r-- | conf.d/project/lua.d/onload-audio-oncall.lua | 88 | ||||
-rw-r--r-- | conf.d/project/lua.d/onload-audio-samples.lua | 93 | ||||
-rw-r--r-- | conf.d/project/lua.d/onload-audio-utils.lua (renamed from conf.d/project/lua.d/helloworld-lua-script.lua) | 35 | ||||
-rw-r--r-- | htdocs/audio-control.html | 2 | ||||
-rw-r--r-- | nbproject/configurations.xml | 113 |
15 files changed, 399 insertions, 339 deletions
diff --git a/Controler-afb/ctl-apidef.h b/Controler-afb/ctl-apidef.h index 0f801cb..1bd80f9 100644 --- a/Controler-afb/ctl-apidef.h +++ b/Controler-afb/ctl-apidef.h @@ -46,21 +46,26 @@ static const char _afb_description_v2_control[] = ",\"get\":{\"x-permissions\":{\"$ref\":\"#/components/x-permissions/navig" "ation\"},\"parameters\":[{\"in\":\"query\",\"name\":\"zone\",\"required\"" ":false,\"schema\":{\"type\":\"string\"}}],\"responses\":{\"200\":{\"$ref" - "\":\"#/components/responses/200\"}}}},\"/lua_docall\":{\"description\":\"" - "Execute LUA string script.\",\"get\":{\"x-permissions\":{\"$ref\":\"#/co" - "mponents/x-permissions/navigation\"},\"parameters\":[{\"in\":\"query\",\"" - "name\":\"func\",\"required\":true,\"schema\":{\"type\":\"string\"}},{\"i" - "n\":\"query\",\"name\":\"args\",\"required\":false,\"schema\":{\"type\":" - "\"array\"}}],\"responses\":{\"200\":{\"$ref\":\"#/components/responses/2" - "00\"}}}},\"/lua_dostring\":{\"description\":\"Execute LUA string script." + "\":\"#/components/responses/200\"}}}},\"/emergency\":{\"description\":\"" + "Request Access to Navigation Audio Channel.\",\"get\":{\"x-permissions\"" + ":{\"$ref\":\"#/components/x-permissions/navigation\"},\"parameters\":[{\"" + "in\":\"query\",\"name\":\"zone\",\"required\":false,\"schema\":{\"type\"" + ":\"string\"}}],\"responses\":{\"200\":{\"$ref\":\"#/components/responses" + "/200\"}}}},\"/lua_docall\":{\"description\":\"Execute LUA string script." "\",\"get\":{\"x-permissions\":{\"$ref\":\"#/components/x-permissions/nav" - "igation\"},\"parameters\":[{\"in\":\"query\",\"required\":true,\"schema\"" - ":{\"type\":\"string\"}}],\"responses\":{\"200\":{\"$ref\":\"#/components" - "/responses/200\"}}}},\"/lua_doscript\":{\"description\":\"Execute LUA st" - "ring script.\",\"get\":{\"x-permissions\":{\"$ref\":\"#/components/x-per" - "missions/navigation\"},\"parameters\":[{\"in\":\"query\",\"name\":\"file" - "name\",\"required\":true,\"schema\":{\"type\":\"string\"}}],\"responses\"" - ":{\"200\":{\"$ref\":\"#/components/responses/200\"}}}}}}" + "igation\"},\"parameters\":[{\"in\":\"query\",\"name\":\"func\",\"require" + "d\":true,\"schema\":{\"type\":\"string\"}},{\"in\":\"query\",\"name\":\"" + "args\",\"required\":false,\"schema\":{\"type\":\"array\"}}],\"responses\"" + ":{\"200\":{\"$ref\":\"#/components/responses/200\"}}}},\"/lua_dostring\"" + ":{\"description\":\"Execute LUA string script.\",\"get\":{\"x-permission" + "s\":{\"$ref\":\"#/components/x-permissions/navigation\"},\"parameters\":" + "[{\"in\":\"query\",\"required\":true,\"schema\":{\"type\":\"string\"}}]," + "\"responses\":{\"200\":{\"$ref\":\"#/components/responses/200\"}}}},\"/l" + "ua_doscript\":{\"description\":\"Execute LUA string script.\",\"get\":{\"" + "x-permissions\":{\"$ref\":\"#/components/x-permissions/navigation\"},\"p" + "arameters\":[{\"in\":\"query\",\"name\":\"filename\",\"required\":true,\"" + "schema\":{\"type\":\"string\"}}],\"responses\":{\"200\":{\"$ref\":\"#/co" + "mponents/responses/200\"}}}}}}" ; static const struct afb_auth _afb_auths_v2_control[] = { @@ -71,6 +76,7 @@ static const struct afb_auth _afb_auths_v2_control[] = { void ctlapi_event_test(struct afb_req req); void ctlapi_navigation(struct afb_req req); void ctlapi_multimedia(struct afb_req req); + void ctlapi_emergency(struct afb_req req); void ctlapi_lua_docall(struct afb_req req); void ctlapi_lua_dostring(struct afb_req req); void ctlapi_lua_doscript(struct afb_req req); @@ -105,6 +111,13 @@ static const struct afb_verb_v2 _afb_verbs_v2_control[] = { .session = AFB_SESSION_NONE_V2 }, { + .verb = "emergency", + .callback = ctlapi_emergency, + .auth = &_afb_auths_v2_control[0], + .info = NULL, + .session = AFB_SESSION_NONE_V2 + }, + { .verb = "lua_docall", .callback = ctlapi_lua_docall, .auth = &_afb_auths_v2_control[0], diff --git a/Controler-afb/ctl-apidef.json b/Controler-afb/ctl-apidef.json index 438a9ef..28b8581 100644 --- a/Controler-afb/ctl-apidef.json +++ b/Controler-afb/ctl-apidef.json @@ -224,7 +224,7 @@ } } }, - "/navigation": { + "/emergency": { "description": "Request Access to Navigation Audio Channel.", "get": { "x-permissions": { diff --git a/Controler-afb/ctl-binding.h b/Controler-afb/ctl-binding.h index 01840b8..70ad0c3 100644 --- a/Controler-afb/ctl-binding.h +++ b/Controler-afb/ctl-binding.h @@ -42,6 +42,14 @@ typedef struct { #define CTL_PLUGIN_REGISTER(pluglabel) CtlPluginMagicT CtlPluginMagic={.magic=CTL_PLUGIN_MAGIC,.label=pluglabel}; struct afb_binding_data_v2; // ctl-misc.c +typedef enum { + CTL_SCAN_FLAT=0, + CTL_SCAN_RECURSIVE=1, +} CtlScanDirModeT; + +PUBLIC const char *GetMidleName(const char*name); +PUBLIC const char *GetBinderName(); +PUBLIC json_object* ScanForConfig (char* searchPath, CtlScanDirModeT mode, char *pre, char *ext); // polctl-binding.c @@ -49,21 +57,12 @@ PUBLIC int CtlBindingInit (); // ctl-timerevt.c // ---------------------- - - PUBLIC int TimerEvtInit (void); PUBLIC afb_event TimerEvtGet(void); PUBLIC void ctlapi_event_test (afb_req request); // ctl-policy // ----------- -typedef enum { - CTL_SCAN_FLAT=0, - CTL_SCAN_RECURSIVE=1, -} CtlScanDirModeT; - -PUBLIC json_object* ScanForConfig (char* searchPath, CtlScanDirModeT mode, char *pre, char *ext); -PUBLIC const char *GetBinderName(); typedef enum { CTL_MODE_NONE=0, diff --git a/Controler-afb/ctl-lua.c b/Controler-afb/ctl-lua.c index c1bc5f3..275b9d3 100644 --- a/Controler-afb/ctl-lua.c +++ b/Controler-afb/ctl-lua.c @@ -104,36 +104,10 @@ STATIC void LuaCtxFree (LuaAfbContextT *afbContext) { free (afbContext->info); } - -STATIC void LuaDumpArgs(lua_State* luaState, int start) { - int count = lua_gettop(luaState); - - for (int idx=start; idx <= count; idx++) { - int luaType = lua_type(luaState, idx); - switch(luaType) { - case LUA_TNUMBER: - AFB_NOTICE ("idx=%d type=%s value=%d", idx, lua_typename(luaState, luaType), (int)lua_tonumber(luaState, idx)); - break; - case LUA_TBOOLEAN: - AFB_NOTICE ("idx=%d type=%s value=%d", idx, lua_typename(luaState, luaType), lua_toboolean(luaState, idx)); - break; - case LUA_TSTRING: - AFB_NOTICE ("idx=%d type=%s value=%s", idx, lua_typename(luaState, luaType), lua_tostring(luaState, idx)); - break; - case LUA_TTABLE: { - AFB_NOTICE ("-++-- START luatable idx=%d ", idx); - (void)LuaDumpArgs(luaState, idx+1); - AFB_NOTICE ("-++-- END luatable idx=%d ", idx); - break; - } - default: - AFB_NOTICE ("PopOneArg: script returned Unknown/Unsupported idx=%d type:%d/%s", idx, luaType, lua_typename(luaState, luaType)); - } - } -} - // Push a json structure on the stack as a LUA table STATIC int LuaPushArgument (json_object *argsJ) { + + AFB_NOTICE("LuaPushArgument argsJ=%s", json_object_get_string(argsJ)); json_type jtype= json_object_get_type(argsJ); switch (jtype) { @@ -183,21 +157,18 @@ STATIC int LuaPushArgument (json_object *argsJ) { STATIC json_object *PopOneArg (lua_State* luaState, int idx); STATIC json_object *LuaTableToJson (lua_State* luaState, int index) { - + int idx; + json_object *tableJ= json_object_new_object(); const char *key; char number[3]; lua_pushnil(luaState); // 1st key - for (int jdx=1; lua_next(luaState, index) != 0; jdx++) { - - //printf("jdx=%d %s - %s\n", jdx, - //lua_typename(luaState, lua_type(luaState, -2)), - //lua_typename(luaState, lua_type(luaState, -1))); + for (idx=1; lua_next(luaState, index) != 0; idx++) { // uses 'key' (at index -2) and 'value' (at index -1) if (lua_type(luaState,-2) == LUA_TSTRING) key= lua_tostring(luaState, -2); else { - snprintf(number, sizeof(number),"%d", jdx); + snprintf(number, sizeof(number),"%d", idx); key=number; } @@ -205,6 +176,11 @@ STATIC json_object *LuaTableToJson (lua_State* luaState, int index) { lua_pop(luaState, 1); // removes 'value'; keeps 'key' for next iteration } + // Query is empty free empty json object + if (idx == 1) { + json_object_put(tableJ); + return NULL; + } return tableJ; } @@ -223,7 +199,6 @@ STATIC json_object *PopOneArg (lua_State* luaState, int idx) { value= json_object_new_string(lua_tostring(luaState, idx)); break; case LUA_TTABLE: { - AFB_NOTICE ("-++-- luatable idx=%d ", idx); value= LuaTableToJson(luaState, idx); break; } @@ -263,9 +238,7 @@ STATIC void LuaFormatMessage(lua_State* luaState, LuaAfbMessageT action) { message="-- Empty Message ???"; goto PrintMessage; } - - AFB_NOTICE ("**** responseJ=%s", json_object_get_string(responseJ)); - + // if we have only on argument just return the value. if (json_object_get_type(responseJ)!=json_type_array || json_object_array_length(responseJ) <2) { message= (char*)json_object_get_string(responseJ); @@ -287,17 +260,17 @@ STATIC void LuaFormatMessage(lua_State* luaState, LuaAfbMessageT action) { switch (format[++idx]) { case 'd': if (slotJ) targetIdx += snprintf (&message[targetIdx], LUA_MSG_MAX_LENGTH-targetIdx,"%d", json_object_get_int(slotJ)); - else targetIdx += snprintf (&message[targetIdx], LUA_MSG_MAX_LENGTH-targetIdx,"Nil"); + else targetIdx += snprintf (&message[targetIdx], LUA_MSG_MAX_LENGTH-targetIdx,"nil"); break; case 'f': if (slotJ) targetIdx += snprintf (&message[targetIdx], LUA_MSG_MAX_LENGTH-targetIdx,"%f", json_object_get_double(slotJ)); - else targetIdx += snprintf (&message[targetIdx], LUA_MSG_MAX_LENGTH-targetIdx,"Nil"); + else targetIdx += snprintf (&message[targetIdx], LUA_MSG_MAX_LENGTH-targetIdx,"nil"); break; case 's': default: if (slotJ) targetIdx += snprintf (&message[targetIdx], LUA_MSG_MAX_LENGTH-targetIdx,"%s", json_object_get_string(slotJ)); - else targetIdx += snprintf (&message[targetIdx], LUA_MSG_MAX_LENGTH-targetIdx,"Nil"); + else targetIdx += snprintf (&message[targetIdx], LUA_MSG_MAX_LENGTH-targetIdx,"nil"); } } else { @@ -394,9 +367,6 @@ STATIC void LuaAfbServiceCB(void *handle, int iserror, struct json_object *respo count+= LuaPushArgument(responseJ); count+= LuaPushArgument(contextCB->context); - AFB_NOTICE ("*** context=%s", json_object_get_string(contextCB->context)); - - int err=lua_pcall(luaState, count, LUA_MULTRET, 0); if (err) { AFB_ERROR ("LUA-SERICE-CB:FAIL response=%s err=%s", json_object_get_string(responseJ), lua_tostring(luaState,-1) ); @@ -431,6 +401,34 @@ STATIC int LuaAfbService(lua_State* luaState) { return 1; } +STATIC int LuaAfbServiceSync(lua_State* luaState) { + int count = lua_gettop(luaState); + json_object *responseJ; + + // note: argument start at 2 because of AFB: table + if (count <3 || !lua_isstring(luaState, 2) || !lua_isstring(luaState, 3) || !lua_istable(luaState, 4)) { + lua_pushliteral (luaState, "LuaAfbServiceSync-Syntax is error,data=AFB:service_call (api, verb, query)"); + goto OnErrorExit; + } + + // get api/verb+query + const char *api = lua_tostring(luaState,2); + const char *verb= lua_tostring(luaState,3); + json_object *queryJ= LuaTableToJson(luaState, 4); + + int iserror=afb_service_call_sync (api, verb, queryJ, &responseJ); + + // push error status & response + count=1; lua_pushboolean(luaState, iserror); + count+= LuaPushArgument(responseJ); + + return count; // return count values + + OnErrorExit: + lua_error(luaState); + return 1; +} + STATIC int LuaAfbMakeEvent(lua_State* luaState) { int count = lua_gettop(luaState); LuaAfbEvent *afbevt=calloc(1,sizeof(LuaAfbEvent)); @@ -508,16 +506,22 @@ PUBLIC int LuaCallFunc (DispatchActionT *action, json_object *queryJ) { lua_getglobal(luaState, func); // push argsJ on the stack - if (json_object_get_type(argsJ) != json_type_array) { + if (!argsJ) { + lua_pushnil(luaState); + count++; + } else if (json_object_get_type(argsJ) != json_type_array) { count+= LuaPushArgument (argsJ); } else { for (int idx=0; idx<json_object_array_length(argsJ); idx++) { count += LuaPushArgument (json_object_array_get_idx(argsJ, idx)); } - } + } // push queryJ on the stack - if (json_object_get_type(queryJ) != json_type_array) { + if (!queryJ) { + lua_pushnil(luaState); + count++; + } else if (json_object_get_type(queryJ) != json_type_array) { count+= LuaPushArgument (queryJ); } else { for (int idx=0; idx<json_object_array_length(queryJ); idx++) { @@ -541,11 +545,12 @@ PUBLIC int LuaCallFunc (DispatchActionT *action, json_object *queryJ) { } -// Execute LUA code from recieved API request +// Execute LUA code from received API request STATIC void LuaDoAction (LuaDoActionT action, afb_req request) { int err, count=0; - + const char *middleName=NULL; + json_object* queryJ = afb_req_json(request); switch (action) { @@ -581,7 +586,7 @@ STATIC void LuaDoAction (LuaDoActionT action, afb_req request) { LuaAfbContextT *afbContext= LuaCtxPush(luaState, request, func); if (!afbContext) goto OnErrorExit; - // push arguments on the stack + // push query on the stack if (json_object_get_type(args) != json_type_array) { count= LuaPushArgument (args); } else { @@ -596,70 +601,64 @@ STATIC void LuaDoAction (LuaDoActionT action, afb_req request) { case LUA_DOSCRIPT: { // Fulup need to fix argument passing const char *script; + char luaScriptPath[CONTROL_MAXPATH_LEN]; json_object *args; int index; // scan luascript search path once static json_object *luaScriptPathJ =NULL; - if (!luaScriptPathJ) luaScriptPathJ= ScanForConfig(CONTROL_LUA_PATH , CTL_SCAN_FLAT, NULL, "lua"); + if (!luaScriptPathJ) luaScriptPathJ= ScanForConfig(CONTROL_LUA_PATH , CTL_SCAN_RECURSIVE, CONTROL_DOSCRIPT_PRE, "lua"); err= wrap_json_unpack (queryJ, "{s:s, s?o s?o !}", "script", &script,"args", &args, "arg", &args); if (err) { - AFB_ERROR ("LUA-DOCALL-SYNTAX missing script|(args,arg) args=%s", json_object_get_string(queryJ)); + AFB_ERROR ("LUA-DOSCRIPT-SYNTAX:missing script|(args,arg) args=%s", json_object_get_string(queryJ)); goto OnErrorExit; } - - // Push AFB client context on the stack - LuaAfbContextT *afbContext= LuaCtxPush(luaState, request, script); - if (!afbContext) goto OnErrorExit; - - // push arguments on the stack - if (json_object_get_type(args) != json_type_array) { - lua_createtable(luaState, 1, 0); - count= LuaPushArgument (args); - } else { - int length= json_object_array_length(args); - lua_createtable(luaState, length, 0); - for (int idx=0; idx < length; idx++) { - count += LuaPushArgument (json_object_array_get_idx(args, idx)); - if (err) break; - } - } + // search for filename=script in CONTROL_LUA_PATH for (index=0; index < json_object_array_length(luaScriptPathJ); index++) { + json_object *entryJ=json_object_array_get_idx(luaScriptPathJ, index); char *filename; char*fullpath; - json_object *entryJ=json_object_array_get_idx(luaScriptPathJ, index); - + err= wrap_json_unpack (entryJ, "{s:s, s:s !}", "fullpath", &fullpath,"filename", &filename); if (err) { - AFB_ERROR ("LUA-DOSCRIPT HOOPs invalid LUA script path = %s", json_object_get_string(entryJ)); + AFB_ERROR ("LUA-DOSCRIPT-SCAN:HOOPs invalid config file path = %s", json_object_get_string(entryJ)); goto OnErrorExit; } - if (strcmp(filename, script)) continue; - - char filepath[CONTROL_MAXPATH_LEN]; - strncpy(filepath, fullpath, sizeof(filepath)); - strncat(filepath, "/", sizeof(filepath)); - strncat(filepath, filename, sizeof(filepath)); - err= luaL_loadfile(luaState, filepath); - if (err) { - AFB_ERROR ("LUA-DOSCRIPT HOOPs Error in LUA loading scripts=%s err=%s", filepath, lua_tostring(luaState,-1)); - goto OnErrorExit; - } - break; + if (!middleName && !strcmp (filename, script)) { + middleName= GetMidleName(script); + strncpy (luaScriptPath, fullpath, sizeof(luaScriptPath)); + strncat (luaScriptPath, "/", sizeof(luaScriptPath)); + strncat (luaScriptPath, filename, sizeof(luaScriptPath)); + + } else { + AFB_WARNING("LUA-DOSCRIPT-SCAN:Ignore second script=%s path=%s", filename, fullpath); + } } - - if (index == json_object_array_length(luaScriptPathJ)) { - AFB_ERROR ("LUA-DOSCRIPT HOOPs script=%s not in path=%s", script, CONTROL_LUA_PATH); + + // script was loaded we need to parse to make it executable + err=lua_pcall(luaState, 0, 0, 0); + if (err) { + AFB_ERROR ("LUA-DOSCRIPT:FAIL to load %s", luaScriptPath); goto OnErrorExit; } + // push query on the stack + if (json_object_get_type(args) != json_type_array) { + count= LuaPushArgument (args); + } else { + for (int idx=0; idx<json_object_array_length(args); idx++) { + count += LuaPushArgument (json_object_array_get_idx(args, idx)); + if (err) break; + } + } + break; } default: - AFB_ERROR ("LUA-DOCALL-ACTION unknown query=%s", json_object_get_string(queryJ)); + AFB_ERROR ("LUA-DOSCRIPT-ACTION unknown query=%s", json_object_get_string(queryJ)); goto OnErrorExit; } @@ -670,7 +669,7 @@ STATIC void LuaDoAction (LuaDoActionT action, afb_req request) { goto OnErrorExit; } - + OnErrorExit: afb_req_fail(request,"LUA:ERROR", lua_tostring(luaState,-1)); @@ -682,7 +681,7 @@ PUBLIC void ctlapi_lua_dostring (afb_req request) { } PUBLIC void ctlapi_lua_docall (afb_req request) { - LuaDoAction (LUA_DOCALL, request); + LuaDoAction (LUA_DOSCRIPT, request); } PUBLIC void ctlapi_lua_doscript (afb_req request) { @@ -695,6 +694,7 @@ static const luaL_Reg afbFunction[] = { {"warning", LuaPrintWarning}, {"debug" , LuaPrintDebug}, {"error" , LuaPrintError}, + {"callsync", LuaAfbServiceSync}, {"service", LuaAfbService}, {"success", LuaAfbSuccess}, {"fail" , LuaAfbFail}, diff --git a/Controler-afb/ctl-misc.c b/Controler-afb/ctl-misc.c index a022b38..773e8f9 100644 --- a/Controler-afb/ctl-misc.c +++ b/Controler-afb/ctl-misc.c @@ -88,6 +88,26 @@ PUBLIC json_object* ScanForConfig (char* searchPath, CtlScanDirModeT mode, char return (responseJ); } +PUBLIC const char *GetMidleName(const char*name) { + char *fullname = strdup(name); + + for (int idx = 0; fullname[idx] != '\0'; idx++) { + int start; + if (fullname[idx] == '-') { + start = idx + 1; + for (int jdx = start; fullname[jdx] != '\0'; jdx++) { + if (fullname[jdx] == '-') { + fullname[jdx] = '\0'; + return &fullname[start]; + break; + } + } + break; + } + } + return ""; +} + PUBLIC const char *GetBinderName() { char psName[17]; static char *binderName=NULL; @@ -96,20 +116,7 @@ PUBLIC const char *GetBinderName() { // retrieve binder name from process name afb-name-trailer prctl(PR_GET_NAME, psName,NULL,NULL,NULL); - for (int idx=0; idx < sizeof(psName); idx++) { - int start; - if (psName[idx] == '-') { - start=idx+1; - for (int jdx=start; jdx < sizeof(psName); jdx++) { - if (psName[jdx] == '-') { - psName[jdx] = '\0'; - binderName=strdup(&psName[start]); - break; - } - } - break; - } - } + binderName=GetMidleName(psName); return binderName; }
\ No newline at end of file diff --git a/Controler-afb/ctl-misc2.c b/Controler-afb/ctl-misc2.c deleted file mode 100644 index dc225a4..0000000 --- a/Controler-afb/ctl-misc2.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 "audio-common.h" -#include "ctl-binding.h" - - - -// Include Binding Stub generated from Json OpenAPI -#include "ctl-apidef.h" - - -PUBLIC void ctlapi_navigation (afb_req request) { - - ctlapi_dispatch ("NAVIGATION", request); -} - -PUBLIC void ctlapi_multimedia (afb_req request) { - - ctlapi_dispatch ("MULTIMEDIA", request); -} - -PUBLIC void ctlapi_emergency (afb_req request) { - - ctlapi_dispatch ("EMERGENCY", request); -} - -PUBLIC void ctlapi_monitor (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(); - errcount += LuaLibInit(); - - AFB_DEBUG ("Audio Policy Control Binding Done errcount=%d", errcount); - return errcount; -} - diff --git a/conf.d/cmake/config.cmake b/conf.d/cmake/config.cmake index 510eb70..ff8bf38 100644 --- a/conf.d/cmake/config.cmake +++ b/conf.d/cmake/config.cmake @@ -69,6 +69,7 @@ set (PKG_REQUIRED_LIST # --------------------------------------------------------- add_compile_options(-DCONTROL_ONLOAD_DEFAULT="onload-default") add_compile_options(-DCONTROL_MAXPATH_LEN=255) + add_compile_options(-DCONTROL_DOSCRIPT_PRE="doscript") add_compile_options(-DCONTROL_CONFIG_PRE="onload") add_compile_options(-DCONTROL_CONFIG_POST="control" ) add_compile_options(-DCONTROL_CONFIG_PATH="${CMAKE_SOURCE_DIR}/conf.d/project/config.d:${CMAKE_INSTALL_PREFIX}/controler/config.d") diff --git a/conf.d/project/config.d/onload-audio-control.json b/conf.d/project/config.d/onload-audio-control.json index aecf1b3..c8f9be2 100644 --- a/conf.d/project/config.d/onload-audio-control.json +++ b/conf.d/project/config.d/onload-audio-control.json @@ -39,7 +39,7 @@ "actions": [{ "label": "multimedia-control-lua", "info": "Call Lua Script function Test_Lua_Engin", - "lua": "Audio_Set_Use_Case_Multimedia", + "lua": "Audio_Set_Multimedia", }] }, { "label": "navigation", @@ -61,13 +61,13 @@ }, { "label": "navigation-control-lua", "info": "Call Lua Script to set Navigation", - "lua": "Audio_Set_Use_Case_Navigation", + "lua": "Audio_Set_Navigation", }] }, { "label": "emergency", "actions": [{ "label": "emergency-control-ucm", - "lua": "Audio_Set_Use_Case_Emergency", + "lua": "Audio_Set_Emergency", }] } ], diff --git a/conf.d/project/lua.d/doscript-helloworld.lua b/conf.d/project/lua.d/doscript-helloworld.lua new file mode 100644 index 0000000..b70ba8d --- /dev/null +++ b/conf.d/project/lua.d/doscript-helloworld.lua @@ -0,0 +1,36 @@ +--[[ + 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:error ("LUA HelloWorld:FX query should not be empty"); + AFB:fail (request, "LUA HelloWorld: query should not be empty"); + else + AFB:error ("LUA HelloWorld:OK query=%s", query); + AFB:sucess (request, {arg0="Demat", arg1="Bonjours", arg2="Gootentag", arg3="Morning"}); + end + +end
\ No newline at end of file diff --git a/conf.d/project/lua.d/onload-audio-policy.lua b/conf.d/project/lua.d/onload-audio-controls.lua index 0b7c358..eb6a61b 100644 --- a/conf.d/project/lua.d/onload-audio-policy.lua +++ b/conf.d/project/lua.d/onload-audio-controls.lua @@ -37,10 +37,15 @@ end function Audio_Set_Navigation(args, query) - AFB:notice ("--LUA:Audio_Set_Use_Case args=%s query=%s", args, query, {myint=1234, mystring="abcd"}); - -- Print_Table("args", args) - - + AFB:notice ("--LUA:Audio_Set_Use_Case args=%s query=%s", args, query); + + -- synchronous call to alsacore service + local error,data= AFB:callsync ('alsacore', 'ping', {}) + if (error) then + AFB:error ("--LUA:Audio_Set_Use_Case FAIL args=%s", args) + else + AFB:notice ("--LUA:Audio_Set_Use_Case DONE args=%s response=%s", args, data["response"]) + end -- return OK return 0 diff --git a/conf.d/project/lua.d/onload-audio-oncall.lua b/conf.d/project/lua.d/onload-audio-oncall.lua new file mode 100644 index 0000000..22cba85 --- /dev/null +++ b/conf.d/project/lua.d/onload-audio-oncall.lua @@ -0,0 +1,88 @@ +--[[ + 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 + +-- Adjust Volume function of vehicle speed +function Oncall_Helloworld (request, args) + count=count+1 + + AFB:notice("LUA OnCall Helloworld count=%d args=%s", count, args); + AFB:success (request, {"count"=count}) +end + +function Test_Async_CB (request, result, context) + + AFB:notice ("Test_Async_CB result=%s context=%s", result, context) + AFB:success (request, {"response"=result, "context"=context}) +end + +function Test_Call_Async (request, args) + local context={ + "value1"="abcd", + "value2"=1234 + } + + AFB:notice ("Test_Call_Async args=%s", args) + AFB:service("alsacore","ping", args, "Test_Async_CB", context) +end + +function Test_Call_Sync (request, args) + + AFB:notice ("Test_Call_Sync args=%s", args) + local err, response= AFB:service_sync ("alsacore","ping", args) + if (err) then + AFB:fail ("AFB:service_call_sync fail"); + else + AFB:success (request, response) + end +end + +-- create a new event name +function Test_Event_Make (request, args) + + AFB:notice ("Test_Event_Make args=%s", args) + local err eventFD AFB:event (args["evtname"]) + if (err) then + AFB:fail ("AFB:Test_Event_Make fail event=%s", args["evtname"]); + else + AFB:success (request, {}) + end + + local evtData = { + val1="My 1st private Event", + val2=5678 + } + + AFB:notify (eventFD, evtData) +end + +-- send an event on default binder event +function Test_Event_Notify (request, args) + + AFB:notice ("Test_Event_Notify args=%s", args) + local err AFB:notify (args) + if (err) then + AFB:fail ("AFB:Test_Event_Make fail event=%s", args["evtname"]); + else + AFB:success (request, {}) + end +end diff --git a/conf.d/project/lua.d/onload-audio-samples.lua b/conf.d/project/lua.d/onload-audio-samples.lua deleted file mode 100644 index 055a15d..0000000 --- a/conf.d/project/lua.d/onload-audio-samples.lua +++ /dev/null @@ -1,93 +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 policy function for AGL Advance Audio Agent ---]] - -count=0 - --- Adjust Volume function of vehicle speed -function Adjust_Volume_Speed (request, speed_meters_second) - - AFB:notice("In Adjust_Volume_Speed speed=%d", speed_meters_second); - - print (string.format("*****(From Lua) Adjust_Volume_Speed speed=%d count=%d", speed_meters_second, count)); - - -- compute volume - volume = speed_meters_second * 2 - count=count+1 - - AFB:success (request, 1234, volume, count, 5678) -end - - -function Test_Binder_CB (result, context) - - local myTable= { ["arg1"] = "myString", ["arg2"] = 1234, ["arg4"] = true, ["arg5"] = 3.1416 } - - AFB:notice ("In Test_Binder_CB", result, context) - - AFB:success (1234, "ABCD", myTable, 5678) - -end - -function Test_Binder_Call_Async () - - local query= { - ["arg1"] = "myString", - ["arg2"] = 1234, - ["arg4"] = true, - ["arg5"] = 3.1416, - } - - AFB:service("alsacore","ping", query, Test_Binder_CB, "myContext") - -end - -function Test_Binder_Call_Sync () - - local query= { - ["arg1"] = "myString", - ["arg2"] = 1234, - ["arg4"] = true, - ["arg5"] = 3.1416, - } - - err= AFB:service_sync ("alsacore","ping", query) - - if (err) then - AFB:fail ("AFB:service_call_sync fail"); - else - AFB:success (1234, "ABCD", myTable) - end - - -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 diff --git a/conf.d/project/lua.d/helloworld-lua-script.lua b/conf.d/project/lua.d/onload-audio-utils.lua index 7dd0459..40ef8a3 100644 --- a/conf.d/project/lua.d/helloworld-lua-script.lua +++ b/conf.d/project/lua.d/onload-audio-utils.lua @@ -14,28 +14,19 @@ See the License for the specific language governing permissions and limitations under the License. - - Simple API script --]] - -- retrieve calling arguments - args= ... - - print ("Helloworld script arguments:") - - - for key,value in pairs(args) - do - print("args: ", key,value) - end - - -- loop on script arguments - --for i=1,#args - --do - -- print(" -- ", i, args[i]) - --end - - - -- return two arguments on top of status - return true, 1234, "ABCD", 5678 +-- 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 diff --git a/htdocs/audio-control.html b/htdocs/audio-control.html index 318caba..2025581 100644 --- a/htdocs/audio-control.html +++ b/htdocs/audio-control.html @@ -27,7 +27,7 @@ <li><button onclick="callbinder('control','navigation' ,{'var': 'nav'});">Select Navigation</button></li> <li><button onclick="callbinder('control','multimedia' ,{'xxx': 'multi'});">Select Mutimedia</button></li> - <li><button onclick="callbinder('control','emergency' ,{'yyy': 'emerg'});">Select Navigation</button></li> + <li><button onclick="callbinder('control','emergency' ,{'yyy': 'emerg'});">Select Emergency</button></li> <br> <li><button onclick="callbinder('control','lua_dostring','print(\'Bonjours\'); return true, 4567');">LUA string</button></li> <li><button onclick="callbinder('control','lua_docall' , {'func':'Adjust_Volume_Speed', 'args':[20]});">LUA function</button></li> diff --git a/nbproject/configurations.xml b/nbproject/configurations.xml index 2cf8b1c..6ac0844 100644 --- a/nbproject/configurations.xml +++ b/nbproject/configurations.xml @@ -44,7 +44,11 @@ </df> <df name="Controler-afb"> <in>ctl-binding.c</in> + <in>ctl-dispatch.c</in> + <in>ctl-events.c</in> <in>ctl-lua.c</in> + <in>ctl-misc.c</in> + <in>ctl-plugin-sample.c</in> </df> <df name="HAL-afb"> <df name="HAL-interface"> @@ -136,8 +140,6 @@ <pElem>/usr/include/p11-kit-1</pElem> <pElem>/usr/include/json-c</pElem> <pElem>/usr/include/lua5.3</pElem> - <pElem>Audio-Common</pElem> - <pElem>build/Controler-afb</pElem> </incDir> <preprocessorList> <Elem>CONTROL_CONFIG_PATH="/home/fulup/Workspace/AGL-AppFW/audio-bindings-dev/conf.d/project/config.d:/usr/local/controler/config.d"</Elem> @@ -152,7 +154,6 @@ <Elem>MAX_LINEAR_DB_SCALE=24</Elem> <Elem>MAX_SND_CARD=16</Elem> <Elem>TLV_BYTE_SIZE=256</Elem> - <Elem>control_afb_EXPORTS</Elem> </preprocessorList> </cTool> </makeTool> @@ -203,10 +204,67 @@ </item> <item path="Controler-afb/ctl-binding.c" ex="false" tool="0" flavor2="0"> <cTool flags="0"> + <incDir> + <pElem>Audio-Common</pElem> + <pElem>build/Controler-afb</pElem> + </incDir> + <preprocessorList> + <Elem>control_afb_EXPORTS</Elem> + </preprocessorList> + </cTool> + </item> + <item path="Controler-afb/ctl-dispatch.c" ex="false" tool="0" flavor2="2"> + <cTool flags="0"> + <incDir> + <pElem>Audio-Common</pElem> + <pElem>build/Controler-afb</pElem> + </incDir> + <preprocessorList> + <Elem>control_afb_EXPORTS</Elem> + </preprocessorList> + </cTool> + </item> + <item path="Controler-afb/ctl-events.c" ex="false" tool="0" flavor2="2"> + <cTool flags="0"> + <incDir> + <pElem>Audio-Common</pElem> + <pElem>build/Controler-afb</pElem> + </incDir> + <preprocessorList> + <Elem>control_afb_EXPORTS</Elem> + </preprocessorList> + </cTool> + </item> + <item path="Controler-afb/ctl-lua.c" ex="false" tool="0" flavor2="2"> + <cTool flags="0"> + <incDir> + <pElem>Audio-Common</pElem> + <pElem>build/Controler-afb</pElem> + </incDir> + <preprocessorList> + <Elem>control_afb_EXPORTS</Elem> + </preprocessorList> + </cTool> + </item> + <item path="Controler-afb/ctl-misc.c" ex="false" tool="0" flavor2="2"> + <cTool flags="0"> + <incDir> + <pElem>Audio-Common</pElem> + <pElem>build/Controler-afb</pElem> + </incDir> + <preprocessorList> + <Elem>control_afb_EXPORTS</Elem> + </preprocessorList> </cTool> </item> - <item path="Controler-afb/ctl-lua.c" ex="false" tool="0" flavor2="0"> + <item path="Controler-afb/ctl-plugin-sample.c" ex="false" tool="0" flavor2="2"> <cTool flags="0"> + <incDir> + <pElem>build/Controler-afb</pElem> + </incDir> + <preprocessorList> + <Elem>audio_plugin_sample_EXPORTS</Elem> + </preprocessorList> </cTool> </item> <item path="HAL-afb/HAL-interface/hal-interface.c" @@ -314,8 +372,8 @@ <pElem>build/Alsa-Plugin/Alsa-Policy-Hook</pElem> </incDir> <preprocessorList> + <Elem>CONTROL_DOSCRIPT_PRE="doscript"</Elem> <Elem>PIC</Elem> - <Elem>audio_plugin_sample_EXPORTS</Elem> <Elem>policy_hook_cb_EXPORTS</Elem> </preprocessorList> </cTool> @@ -323,27 +381,31 @@ <folder path="0/Alsa-afb"> <cTool> <incDir> + <pElem>Audio-Common</pElem> <pElem>build/Alsa-afb</pElem> </incDir> <preprocessorList> + <Elem>CONTROL_DOSCRIPT_PRE="doscript"</Elem> <Elem>alsa_lowlevel_EXPORTS</Elem> - <Elem>audio_plugin_sample_EXPORTS</Elem> </preprocessorList> </cTool> </folder> <folder path="0/Audio-Common"> <cTool> <incDir> + <pElem>Audio-Common</pElem> <pElem>build/Audio-Common</pElem> </incDir> <preprocessorList> - <Elem>audio_plugin_sample_EXPORTS</Elem> + <Elem>CONTROL_DOSCRIPT_PRE="doscript"</Elem> </preprocessorList> </cTool> </folder> <folder path="0/Common"> <cTool> <incDir> + <pElem>Audio-Common</pElem> + <pElem>build/Controler-afb</pElem> <pElem>build/HAL-afb/HAL-plugin</pElem> <pElem>/usr/include/alsa</pElem> <pElem>build/Common</pElem> @@ -352,17 +414,14 @@ <Elem>CONTROL_CDEV_RX="/dev/inic-usb-crx"</Elem> <Elem>CONTROL_CDEV_TX="/dev/inic-usb-ctx"</Elem> <Elem>audio_plugin_sample_EXPORTS</Elem> + <Elem>control_afb_EXPORTS</Elem> </preprocessorList> </cTool> </folder> - <folder path="0/HAL-afb"> + <folder path="0/Controler-afb"> <cTool> - <incDir> - <pElem>build/HAL-afb/HAL-plugin</pElem> - <pElem>../../../opt/include/afb</pElem> - </incDir> <preprocessorList> - <Elem>audio_plugin_sample_EXPORTS</Elem> + <Elem>CONTROL_DOSCRIPT_PRE="doscript"</Elem> </preprocessorList> </cTool> </folder> @@ -370,18 +429,28 @@ <cTool> <incDir> <pElem>HAL-afb/HAL-interface</pElem> + <pElem>Audio-Common</pElem> <pElem>build/HAL-afb/HAL-interface</pElem> </incDir> + <preprocessorList> + <Elem>CONTROL_DOSCRIPT_PRE="doscript"</Elem> + </preprocessorList> </cTool> </folder> <folder path="0/HAL-afb/HAL-plugin"> <cTool> <incDir> + <pElem>Audio-Common</pElem> + <pElem>build/Controler-afb</pElem> + <pElem>build/HAL-afb/HAL-plugin</pElem> + <pElem>../../../opt/include/afb</pElem> <pElem>HAL-afb/HAL-plugin</pElem> </incDir> <preprocessorList> <Elem>CONTROL_CDEV_RX="/dev/inic-usb-crx"</Elem> <Elem>CONTROL_CDEV_TX="/dev/inic-usb-ctx"</Elem> + <Elem>audio_plugin_sample_EXPORTS</Elem> + <Elem>control_afb_EXPORTS</Elem> </preprocessorList> </cTool> </folder> @@ -389,9 +458,11 @@ <cTool> <incDir> <pElem>HAL-afb/HAL-interface</pElem> + <pElem>Audio-Common</pElem> <pElem>build/HAL-afb/HDA-intel</pElem> </incDir> <preprocessorList> + <Elem>CONTROL_DOSCRIPT_PRE="doscript"</Elem> <Elem>hal_intel_hda_EXPORTS</Elem> </preprocessorList> </cTool> @@ -400,9 +471,11 @@ <cTool> <incDir> <pElem>HAL-afb/HAL-interface</pElem> + <pElem>Audio-Common</pElem> <pElem>build/HAL-afb/Jabra-Solemate</pElem> </incDir> <preprocessorList> + <Elem>CONTROL_DOSCRIPT_PRE="doscript"</Elem> <Elem>hal_jabra_usb_EXPORTS</Elem> </preprocessorList> </cTool> @@ -411,9 +484,11 @@ <cTool> <incDir> <pElem>HAL-afb/HAL-interface</pElem> + <pElem>Audio-Common</pElem> <pElem>build/HAL-afb/Scarlett-Focusrite</pElem> </incDir> <preprocessorList> + <Elem>CONTROL_DOSCRIPT_PRE="doscript"</Elem> <Elem>hal_scalett_usb_EXPORTS</Elem> </preprocessorList> </cTool> @@ -421,17 +496,25 @@ <folder path="0/HAL-afb/Unicens-USB"> <cTool> <incDir> + <pElem>Audio-Common</pElem> + <pElem>build/Controler-afb</pElem> + <pElem>build/HAL-afb/HAL-plugin</pElem> + <pElem>../../../opt/include/afb</pElem> <pElem>HAL-afb/Unicens-USB</pElem> </incDir> <preprocessorList> <Elem>CONTROL_CDEV_RX="/dev/inic-usb-crx"</Elem> <Elem>CONTROL_CDEV_TX="/dev/inic-usb-ctx"</Elem> + <Elem>audio_plugin_sample_EXPORTS</Elem> + <Elem>control_afb_EXPORTS</Elem> </preprocessorList> </cTool> </folder> <folder path="0/HighLevel-afb"> <cTool> <incDir> + <pElem>Audio-Common</pElem> + <pElem>build/Controler-afb</pElem> <pElem>build/HAL-afb/HAL-plugin</pElem> <pElem>../../../opt/include/afb</pElem> <pElem>HighLevel-afb</pElem> @@ -440,16 +523,20 @@ </incDir> <preprocessorList> <Elem>audio_plugin_sample_EXPORTS</Elem> + <Elem>control_afb_EXPORTS</Elem> </preprocessorList> </cTool> </folder> <folder path="0/MostVolume"> <cTool> <incDir> + <pElem>Audio-Common</pElem> + <pElem>build/Controler-afb</pElem> <pElem>build/HAL-afb/HAL-plugin</pElem> </incDir> <preprocessorList> <Elem>audio_plugin_sample_EXPORTS</Elem> + <Elem>control_afb_EXPORTS</Elem> </preprocessorList> </cTool> </folder> |