From a7d41a6fa1e29d800ce8ac9e95e8f943814463e8 Mon Sep 17 00:00:00 2001 From: Fulup Ar Foll Date: Fri, 18 Aug 2017 01:09:56 +0200 Subject: Integration with Alsa HookPlugin is now working. --- Controller-afb/ctl-lua.c | 1033 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 1033 insertions(+) create mode 100644 Controller-afb/ctl-lua.c (limited to 'Controller-afb/ctl-lua.c') diff --git a/Controller-afb/ctl-lua.c b/Controller-afb/ctl-lua.c new file mode 100644 index 0000000..4ef6b65 --- /dev/null +++ b/Controller-afb/ctl-lua.c @@ -0,0 +1,1033 @@ +/* + * 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. + * ref: + * (manual) https://www.lua.org/manual/5.3/manual.html + * (lua->C) http://www.troubleshooters.com/codecorn/lua/lua_c_calls_lua.htm#_Anatomy_of_a_Lua_Call + * (lua/C Var) http://acamara.es/blog/2012/08/passing-variables-from-lua-5-2-to-c-and-vice-versa/ + * (Lua/C Lib)https://john.nachtimwald.com/2014/07/12/wrapping-a-c-library-in-lua/ + * (Lua/C Table) https://gist.github.com/SONIC3D/10388137 + * (Lua/C Nested table) https://stackoverflow.com/questions/45699144/lua-nested-table-from-lua-to-c + * (Lua/C Wrapper) https://stackoverflow.com/questions/45699950/lua-passing-handle-to-function-created-with-newlib + * + */ + +#define _GNU_SOURCE +#include +#include + + +#include "ctl-binding.h" +#include "wrap-json.h" + +#define LUA_FIST_ARG 2 // when using luaL_newlib calllback receive libtable as 1st arg +#define LUA_MSG_MAX_LENGTH 512 +#define JSON_ERROR (json_object*)-1 +static afb_req NULL_AFBREQ = {}; + + +static lua_State* luaState; + +#define CTX_MAGIC 123456789 +#define CTX_TOKEN "AFB_ctx" + +typedef struct { + char *name; + int count; + afb_event event; +} LuaAfbEvent; +static LuaAfbEvent *luaDefaultEvt; + +typedef struct { + int ctxMagic; + afb_req request; + void *handle; + char *info; +} LuaAfbContextT; + +typedef struct { + const char *callback; + json_object *context; + void *handle; +} LuaCallServiceT; + +typedef enum { + AFB_MSG_INFO, + AFB_MSG_WARNING, + AFB_MSG_NOTICE, + AFB_MSG_DEBUG, + AFB_MSG_ERROR, +} LuaAfbMessageT; + +/* + * Note(Fulup): I fail to use luaL_setmetatable and replaced it with a simple opaque + * handle while waiting for someone smarter than me to find a better solution + * https://stackoverflow.com/questions/45596493/lua-using-lua-newuserdata-from-lua-pcall + */ + +STATIC LuaAfbContextT *LuaCtxCheck (lua_State *luaState, int index) { + LuaAfbContextT *afbContext; + //luaL_checktype(luaState, index, LUA_TUSERDATA); + //afbContext = (LuaAfbContextT *)luaL_checkudata(luaState, index, CTX_TOKEN); + luaL_checktype(luaState, index, LUA_TLIGHTUSERDATA); + afbContext = (LuaAfbContextT *) lua_touserdata(luaState, index); + if (afbContext == NULL && afbContext->ctxMagic != CTX_MAGIC) { + luaL_error(luaState, "Fail to retrieve user data context=%s", CTX_TOKEN); + AFB_ERROR ("afbContextCheck error retrieving afbContext"); + return NULL; + } + return afbContext; +} + +STATIC LuaAfbContextT *LuaCtxPush (lua_State *luaState, afb_req request, void *handle, const char* info) { + // LuaAfbContextT *afbContext = (LuaAfbContextT *)lua_newuserdata(luaState, sizeof(LuaAfbContextT)); + // luaL_setmetatable(luaState, CTX_TOKEN); + LuaAfbContextT *afbContext = (LuaAfbContextT *)calloc(1, sizeof(LuaAfbContextT)); + lua_pushlightuserdata(luaState, afbContext); + if (!afbContext) { + AFB_ERROR ("LuaCtxPush fail to allocate user data context"); + return NULL; + } + afbContext->ctxMagic=CTX_MAGIC; + afbContext->info=strdup(info); + afbContext->request= request; + afbContext->handle= handle; + return afbContext; +} + +STATIC void LuaCtxFree (LuaAfbContextT *afbContext) { + free(afbContext->info); + free(afbContext); +} + +// 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) { + case json_type_object: { + lua_newtable (luaState); + json_object_object_foreach (argsJ, key, val) { + int done = LuaPushArgument (val); + if (done) { + lua_setfield(luaState,-2, key); + } + } + break; + } + case json_type_array: { + int length= json_object_array_length(argsJ); + lua_newtable (luaState); + for (int idx=0; idx < length; idx ++) { + json_object *val=json_object_array_get_idx(argsJ, idx); + LuaPushArgument (val); + lua_seti (luaState,-2, idx); + } + break; + } + case json_type_int: + lua_pushinteger(luaState, json_object_get_int(argsJ)); + break; + case json_type_string: + lua_pushstring(luaState, json_object_get_string(argsJ)); + break; + case json_type_boolean: + lua_pushboolean(luaState, json_object_get_boolean(argsJ)); + break; + case json_type_double: + lua_pushnumber(luaState, json_object_get_double(argsJ)); + break; + case json_type_null: + AFB_WARNING("LuaPushArgument: NULL object type %s", json_object_get_string(argsJ)); + return 0; + break; + + default: + AFB_ERROR("LuaPushArgument: unsupported Json object type %s", json_object_get_string(argsJ)); + return 0; + } + return 1; +} + +STATIC json_object *LuaPopOneArg (lua_State* luaState, int idx); + +STATIC json_object *LuaTableToJson (lua_State* luaState, int index) { + int idx; + #define LUA_KEY_INDEX -2 + #define LUA_VALUE_INDEX -1 + + json_object *tableJ= json_object_new_object(); + const char *key; + char number[3]; + lua_pushnil(luaState); // 1st key + if (index < 0) index--; + for (idx=1; lua_next(luaState, index) != 0; idx++) { + + // uses 'key' (at index -2) and 'value' (at index -1) + if (lua_type(luaState,LUA_KEY_INDEX) == LUA_TSTRING) key= lua_tostring(luaState, LUA_KEY_INDEX); + else { + snprintf(number, sizeof(number),"%d", idx); + key=number; + } + json_object *argJ= LuaPopOneArg(luaState, LUA_VALUE_INDEX); + json_object_object_add(tableJ, key, argJ); + 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; +} + +STATIC json_object *LuaPopOneArg (lua_State* luaState, int idx) { + json_object *value=NULL; + + int luaType = lua_type(luaState, idx); + switch(luaType) { + case LUA_TNUMBER: { + lua_Number number= lua_tonumber(luaState, idx);; + int nombre = (int)number; // evil trick to determine wether n fits in an integer. (stolen from ltcl.c) + if (number == nombre) { + value= json_object_new_int((int)number); + } else { + value= json_object_new_double(number); + } + break; + } + case LUA_TBOOLEAN: + value= json_object_new_boolean(lua_toboolean(luaState, idx)); + break; + case LUA_TSTRING: + value= json_object_new_string(lua_tostring(luaState, idx)); + break; + case LUA_TTABLE: + value= LuaTableToJson(luaState, idx); + break; + case LUA_TNIL: + value=json_object_new_string("nil") ; + break; + case LUA_TUSERDATA: + value=json_object_new_int64((int64_t)lua_touserdata(luaState, idx)); // store userdata as int !!! + break; + + default: + AFB_NOTICE ("LuaPopOneArg: script returned Unknown/Unsupported idx=%d type:%d/%s", idx, luaType, lua_typename(luaState, luaType)); + value=NULL; + } + + return value; +} + +static json_object *LuaPopArgs (lua_State* luaState, int start) { + json_object *responseJ; + + int stop = lua_gettop(luaState); + if(stop-start <0) return NULL; + + // start at 2 because we are using a function array lib + if (start == stop) { + responseJ=LuaPopOneArg (luaState, start); + } else { + // loop on remaining return arguments + responseJ= json_object_new_array(); + for (int idx=start; idx <= stop; idx++) { + json_object *argJ=LuaPopOneArg (luaState, idx); + if (!argJ) goto OnErrorExit; + json_object_array_add(responseJ, argJ); + } + } + + return responseJ; + + OnErrorExit: + return NULL; +} + + +STATIC int LuaFormatMessage(lua_State* luaState, LuaAfbMessageT action) { + char *message; + + json_object *responseJ= LuaPopArgs(luaState, LUA_FIST_ARG); + + if (!responseJ) { + luaL_error(luaState,"LuaFormatMessage empty message"); + goto OnErrorExit; + } + + // 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); + goto PrintMessage; + } + + // extract format and push all other parameter on the stack + message = alloca (LUA_MSG_MAX_LENGTH); + const char *format = json_object_get_string(json_object_array_get_idx(responseJ, 0)); + + int arrayIdx=1; + int targetIdx=0; + + for (int idx=0; format[idx] !='\0'; idx++) { + + if (format[idx]=='%' && format[idx] !='\0') { + json_object *slotJ= json_object_array_get_idx(responseJ, arrayIdx); + //if (slotJ) AFB_NOTICE("**** idx=%d slotJ=%s", arrayIdx, json_object_get_string(slotJ)); + + + 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"); + arrayIdx++; + 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"); + arrayIdx++; + break; + + case'%': + message[targetIdx]='%'; + targetIdx++; + 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"); + arrayIdx++; + } + + } else { + if (targetIdx >= LUA_MSG_MAX_LENGTH) { + AFB_WARNING ("LuaFormatMessage: message[%s] owerverflow LUA_MSG_MAX_LENGTH=%d", format, LUA_MSG_MAX_LENGTH); + targetIdx --; // move backward for EOL + break; + } else { + message[targetIdx++] = format[idx]; + } + } + } + message[targetIdx]='\0'; + +PrintMessage: + switch (action) { + case AFB_MSG_WARNING: + AFB_WARNING (message); + break; + case AFB_MSG_NOTICE: + AFB_NOTICE (message); + break; + case AFB_MSG_DEBUG: + AFB_DEBUG (message); + break; + case AFB_MSG_INFO: + AFB_INFO (message); + break; + case AFB_MSG_ERROR: + default: + AFB_ERROR (message); + } + return 0; // nothing return to lua + + OnErrorExit: // on argument to return (the error message) + return 1; +} + +STATIC int LuaPrintInfo(lua_State* luaState) { + int err=LuaFormatMessage (luaState, AFB_MSG_INFO); + return err; +} + +STATIC int LuaPrintError(lua_State* luaState) { + int err=LuaFormatMessage (luaState, AFB_MSG_ERROR); + return err; // no value return +} + +STATIC int LuaPrintWarning(lua_State* luaState) { + int err=LuaFormatMessage (luaState, AFB_MSG_WARNING); + return err; +} + +STATIC int LuaPrintNotice(lua_State* luaState) { + int err=LuaFormatMessage (luaState, AFB_MSG_NOTICE); + return err; +} + +STATIC int LuaPrintDebug(lua_State* luaState) { + int err=LuaFormatMessage (luaState, AFB_MSG_DEBUG); + return err; +} + +STATIC int LuaAfbSuccess(lua_State* luaState) { + LuaAfbContextT *afbContext= LuaCtxCheck(luaState, LUA_FIST_ARG); + if (!afbContext) goto OnErrorExit; + + // ignore context argument + json_object *responseJ= LuaPopArgs(luaState, LUA_FIST_ARG+1); + if (responseJ == JSON_ERROR) return 1; + + afb_req_success(afbContext->request, responseJ, NULL); + + LuaCtxFree(afbContext); + return 0; + + OnErrorExit: + lua_error(luaState); + return 1; +} + +STATIC int LuaAfbFail(lua_State* luaState) { + LuaAfbContextT *afbContext= LuaCtxCheck(luaState, LUA_FIST_ARG); + if (!afbContext) goto OnErrorExit; + + json_object *responseJ= LuaPopArgs(luaState, LUA_FIST_ARG+1); + if (responseJ == JSON_ERROR) return 1; + + afb_req_fail(afbContext->request, afbContext->info, json_object_get_string(responseJ)); + + LuaCtxFree(afbContext); + return 0; + + OnErrorExit: + lua_error(luaState); + return 1; +} + +STATIC void LuaAfbServiceCB(void *handle, int iserror, struct json_object *responseJ) { + LuaCallServiceT *contextCB= (LuaCallServiceT*)handle; + int count=1; + + lua_getglobal(luaState, contextCB->callback); + + // push error status & response + lua_pushboolean(luaState, iserror); + count+= LuaPushArgument(responseJ); + count+= LuaPushArgument(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) ); + } + + free (contextCB); +} + + +STATIC int LuaAfbService(lua_State* luaState) { + int count = lua_gettop(luaState); + + // note: argument start at 2 because of AFB: table + if (count <5 || !lua_isstring(luaState, 2) || !lua_isstring(luaState, 3) || !lua_istable(luaState, 4) || !lua_isstring(luaState, 5)) { + lua_pushliteral (luaState, "LuaAfbServiceCall-Syntax is AFB:service_call (api, verb, query, callback, handle ...."); + 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); + if (queryJ == JSON_ERROR) return 1; + + LuaCallServiceT *contextCB = calloc (1, sizeof(LuaCallServiceT)); + contextCB->callback= lua_tostring(luaState, 5); + contextCB->context = LuaPopArgs(luaState, 6); + + afb_service_call(api, verb, queryJ, LuaAfbServiceCB, contextCB); + + return 0; // no value return + + OnErrorExit: + lua_error(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 LuaAfbEventPush(lua_State* luaState) { + LuaAfbEvent *afbevt; + int index; + + // if no private event handle then use default binding event + if (lua_islightuserdata(luaState, LUA_FIST_ARG)) { + afbevt = (LuaAfbEvent*) lua_touserdata(luaState, LUA_FIST_ARG); + index=LUA_FIST_ARG+1; + } else { + index=LUA_FIST_ARG; + afbevt=luaDefaultEvt; + } + + if (!afb_event_is_valid(afbevt->event)) { + lua_pushliteral (luaState, "LuaAfbMakePush-Fail invalid event"); + goto OnErrorExit; + } + + json_object *ctlEventJ= LuaTableToJson(luaState, index); + if (!ctlEventJ) { + lua_pushliteral (luaState, "LuaAfbEventPush-Syntax is AFB:signal ([evtHandle], {lua table})"); + goto OnErrorExit; + } + + int done = afb_event_push(afbevt->event, ctlEventJ); + if (!done) { + lua_pushliteral (luaState, "LuaAfbEventPush-Fail No Subscriber to event"); + AFB_ERROR ("LuaAfbEventPush-Fail name subscriber event=%s count=%d", afbevt->name, afbevt->count); + goto OnErrorExit; + } + afbevt->count++; + return 0; + + OnErrorExit: + lua_error(luaState); + return 1; +} + +STATIC int LuaAfbEventSubscribe(lua_State* luaState) { + LuaAfbEvent *afbevt; + + LuaAfbContextT *afbContext= LuaCtxCheck(luaState, LUA_FIST_ARG); + if (!afbContext) { + lua_pushliteral (luaState, "LuaAfbEventSubscribe-Fail Invalid request handle"); + goto OnErrorExit; + } + + // if no private event handle then use default binding event + if (lua_islightuserdata(luaState, LUA_FIST_ARG+1)) { + afbevt = (LuaAfbEvent*) lua_touserdata(luaState, LUA_FIST_ARG+1); + } else { + afbevt=luaDefaultEvt; + } + + if (!afb_event_is_valid(afbevt->event)) { + lua_pushliteral (luaState, "LuaAfbMakePush-Fail invalid event handle"); + goto OnErrorExit; + } + + int err = afb_req_subscribe(afbContext->request, afbevt->event); + if (err) { + lua_pushliteral (luaState, "LuaAfbEventSubscribe-Fail No Subscriber to event"); + AFB_ERROR ("LuaAfbEventPush-Fail name subscriber event=%s count=%d", afbevt->name, afbevt->count); + goto OnErrorExit; + } + afbevt->count++; + return 0; + + OnErrorExit: + lua_error(luaState); + return 1; +} + +STATIC int LuaAfbEventMake(lua_State* luaState) { + int count = lua_gettop(luaState); + LuaAfbEvent *afbevt=calloc(1,sizeof(LuaAfbEvent)); + + if (count != LUA_FIST_ARG || !lua_isstring(luaState, LUA_FIST_ARG)) { + lua_pushliteral (luaState, "LuaAfbEventMake-Syntax is evtHandle= AFB:event ('myEventName')"); + goto OnErrorExit; + } + + // event name should be the only argument + afbevt->name= strdup (lua_tostring(luaState,LUA_FIST_ARG)); + + // create a new binder event + afbevt->event = afb_daemon_make_event(afbevt->name); + if (!afb_event_is_valid(afbevt->event)) { + lua_pushliteral (luaState, "LuaAfbEventMake-Fail to Create Binder event"); + goto OnErrorExit; + } + + // push event handler as a LUA opaque handle + lua_pushlightuserdata(luaState, afbevt); + return 1; + + OnErrorExit: + lua_error(luaState); + return 1; +} + +// Function call from LUA when lua2c plugin L2C is used +PUBLIC int Lua2cWrapper(lua_State* luaState, char *funcname, Lua2cFunctionT callback, void *context) { + + json_object *argsJ= LuaPopArgs(luaState, LUA_FIST_ARG+1); + int response = (*callback) (funcname, argsJ, context); + + // 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) { + + int err, count; + + json_object* argsJ = action->argsJ; + const char* func = action->call; + + // load function (should exist in CONTROL_PATH_LUA + lua_getglobal(luaState, func); + + // push source on the stack + count=1; + lua_pushinteger(luaState, source); + + // push argsJ on the stack + if (!argsJ) { + lua_pushnil(luaState); + count++; + } else { + count+= LuaPushArgument (argsJ); + } + + // push queryJ on the stack + if (!queryJ) { + lua_pushnil(luaState); + count++; + } else { + count+= LuaPushArgument (queryJ); + } + + // effectively exec LUA script code + err=lua_pcall(luaState, count, 1, 0); + if (err) { + AFB_ERROR("LuaCallFunc Fail calling %s error=%s", func, lua_tostring(luaState,-1)); + goto OnErrorExit; + } + + // return LUA script value + int rc= (int)lua_tointeger(luaState, -1); + return rc; + + OnErrorExit: + return -1; +} + + +// Execute LUA code from received API request +STATIC void LuaDoAction (LuaDoActionT action, afb_req request) { + + int err, count=0; + + json_object* queryJ = afb_req_json(request); + + switch (action) { + + case LUA_DOSTRING: { + const char *script = json_object_get_string(queryJ); + err=luaL_loadstring(luaState, script); + if (err) { + AFB_ERROR ("LUA-DO-COMPILE:FAIL String=%s err=%s", script, lua_tostring(luaState,-1) ); + goto OnErrorExit; + } + // Push AFB client context on the stack + LuaAfbContextT *afbContext= LuaCtxPush(luaState, request,NULL,script); + if (!afbContext) goto OnErrorExit; + + break; + } + + case LUA_DOCALL: { + const char *func; + json_object *argsJ=NULL; + + err= wrap_json_unpack (queryJ, "{s:s, s?o !}", "func", &func, "args", &argsJ); + if (err) { + AFB_ERROR ("LUA-DOCALL-SYNTAX missing func|args query=%s", json_object_get_string(queryJ)); + goto OnErrorExit; + } + + // load function (should exist in CONTROL_PATH_LUA + lua_getglobal(luaState, func); + + // Push AFB client context on the stack + LuaAfbContextT *afbContext= LuaCtxPush(luaState, request, NULL, func); + if (!afbContext) goto OnErrorExit; + + // push query on the stack + if (!argsJ) { + lua_pushnil(luaState); + count++; + } else { + count+= LuaPushArgument (argsJ); + } + + break; + } + + case LUA_DOSCRIPT: { // Fulup need to fix argument passing + const char *script; + char*func=NULL; + char *filename; char*fullpath; + char luaScriptPath[CONTROL_MAXPATH_LEN]; + json_object *argsJ=NULL; + int index; + + // scan luascript search path once + static json_object *luaScriptPathJ =NULL; + + err= wrap_json_unpack (queryJ, "{s:s, s?s s?o !}", "script", &script,"func", &func, "args", &argsJ); + if (err) { + AFB_ERROR ("LUA-DOSCRIPT-SYNTAX:missing script|(args,arg) query=%s", json_object_get_string(queryJ)); + goto OnErrorExit; + } + + // search for filename=script in CONTROL_LUA_PATH + if (!luaScriptPathJ) luaScriptPathJ= ScanForConfig(CONTROL_LUA_PATH , CTL_SCAN_RECURSIVE,CONTROL_DOSCRIPT_PRE "-", script); + for (index=0; index < json_object_array_length(luaScriptPathJ); index++) { + 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-SCAN:HOOPs invalid config file path = %s", json_object_get_string(entryJ)); + goto OnErrorExit; + } + + 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)); + strncat (luaScriptPath, filename, sizeof(luaScriptPath)); + } + } + + err= luaL_loadfile(luaState, luaScriptPath); + if (err) { + AFB_ERROR ("LUA-DOSCRIPT HOOPs Error in LUA loading scripts=%s err=%s", luaScriptPath, lua_tostring(luaState,-1)); + goto OnErrorExit; + } + + // 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; + } + + // if no func name given try to deduct from filename + if (!func) func= (char*)GetMidleName(filename); + if (!func) { + AFB_ERROR ("LUA-DOSCRIPT:FAIL to deduct funcname from %s", filename); + goto OnErrorExit; + } + + // load function (should exist in CONTROL_PATH_LUA + lua_getglobal(luaState, func); + + // Push AFB client context on the stack + LuaAfbContextT *afbContext= LuaCtxPush(luaState, request, NULL, func); + if (!afbContext) goto OnErrorExit; + + // push function arguments + if (!argsJ) { + lua_pushnil(luaState); + count++; + } else { + count+= LuaPushArgument(argsJ); + } + + break; + } + + default: + AFB_ERROR ("LUA-DOSCRIPT-ACTION unknown query=%s", json_object_get_string(queryJ)); + goto OnErrorExit; + } + + // effectively exec LUA code (afb_reply/fail done later from callback) + err=lua_pcall(luaState, count+1, 0, 0); + if (err) { + AFB_ERROR ("LUA-DO-EXEC:FAIL query=%s err=%s", json_object_get_string(queryJ), lua_tostring(luaState,-1)); + goto OnErrorExit; + } + return; + + OnErrorExit: + afb_req_fail(request,"LUA:ERROR", lua_tostring(luaState,-1)); + return; +} + +PUBLIC void ctlapi_lua_dostring (afb_req request) { + LuaDoAction (LUA_DOSTRING, request); +} + +PUBLIC void ctlapi_lua_docall (afb_req request) { + LuaDoAction (LUA_DOCALL, request); +} + +PUBLIC void ctlapi_lua_doscript (afb_req request) { + LuaDoAction (LUA_DOSCRIPT, request); +} + +STATIC int LuaTimerClear (lua_State* luaState) { + + // Get Timer Handle + LuaAfbContextT *afbContext= LuaCtxCheck(luaState, LUA_FIST_ARG); + if (!afbContext) goto OnErrorExit; + + // retrieve useful information opaque handle + TimerHandleT *timerHandle = (TimerHandleT*)afbContext->handle; + + AFB_NOTICE ("LuaTimerClear timer=%s", timerHandle->label); + TimerEvtStop(timerHandle); + + return 0; //happy end + +OnErrorExit: + return 1; +} +STATIC int LuaTimerGet (lua_State* luaState) { + + // Get Timer Handle + LuaAfbContextT *afbContext= LuaCtxCheck(luaState, LUA_FIST_ARG); + if (!afbContext) goto OnErrorExit; + + // retrieve useful information opaque handle + TimerHandleT *timerHandle = (TimerHandleT*)afbContext->handle; + + // create response as a JSON object + json_object *responseJ= json_object_new_object(); + json_object_object_add(responseJ,"label", json_object_new_string(timerHandle->label)); + json_object_object_add(responseJ,"delay", json_object_new_int(timerHandle->delay)); + json_object_object_add(responseJ,"count", json_object_new_int(timerHandle->count)); + + // return JSON object as Lua table + int count=LuaPushArgument(responseJ); + + // free json object + json_object_put(responseJ); + + return count; // return argument + +OnErrorExit: + return 0; +} + +// Timer Callback + +// Set timer +STATIC int LuaTimerSetCB (void *handle) { + LuaCallServiceT *contextCB =(LuaCallServiceT*) handle; + TimerHandleT *timerHandle = (TimerHandleT*) contextCB->handle; + int count; + + // push timer handle and user context on Lua stack + lua_getglobal(luaState, contextCB->callback); + + // Push timer handle + LuaAfbContextT *afbContext= LuaCtxPush(luaState, NULL_AFBREQ, contextCB->handle, timerHandle->label); + if (!afbContext) goto OnErrorExit; + count=1; + + // Push user Context + count+= LuaPushArgument(contextCB->context); + + int err=lua_pcall(luaState, count, LUA_MULTRET, 0); + if (err) { + AFB_ERROR ("LUA-TIMER-CB:FAIL response=%s err=%s", json_object_get_string(contextCB->context), lua_tostring(luaState,-1)); + goto OnErrorExit; + } + + // get return parameter + if (!lua_isboolean(luaState, -1)) { + return (lua_toboolean(luaState, -1)); + } + + // timer last run free context resource + if (timerHandle->count == 1) { + LuaCtxFree(afbContext); + } + return 0; // By default we are happy + + OnErrorExit: + return 1; // stop timer +} + +STATIC int LuaTimerSet(lua_State* luaState) { + const char *label=NULL, *info=NULL; + int delay=0, count=0; + + json_object *timerJ = LuaPopOneArg(luaState, LUA_FIST_ARG); + const char *callback = lua_tostring(luaState, LUA_FIST_ARG + 1); + json_object *contextJ = LuaPopOneArg(luaState, LUA_FIST_ARG + 2); + + if (lua_gettop(luaState) != LUA_FIST_ARG+2 || !timerJ || !callback || !contextJ) { + lua_pushliteral(luaState, "LuaTimerSet-Syntax timerset (timerT, 'callback', contextT)"); + goto OnErrorExit; + } + + int err = wrap_json_unpack(timerJ, "{ss, s?s si, si !}", "label", &label, "info", &info, "delay", &delay, "count", &count); + if (err) { + lua_pushliteral(luaState, "LuaTimerSet-Syntax timerT={label:xxx delay:ms, count:xx}"); + goto OnErrorExit; + } + + // everything look fine create timer structure + TimerHandleT *timerHandle = malloc (sizeof (TimerHandleT)); + timerHandle->delay=delay; + timerHandle->count=count; + timerHandle->label=label; + + // Allocate handle to store context and callback + LuaCallServiceT *contextCB = calloc (1, sizeof(LuaCallServiceT)); + contextCB->callback= callback; + contextCB->context = contextJ; + contextCB->handle = timerHandle; + + // fire timer + TimerEvtStart (timerHandle, LuaTimerSetCB, contextCB); + + return 0; // Happy No Return Function + +OnErrorExit: + lua_error(luaState); + return 1; // return error code +} + +// Register a new L2c list of LUA user plugin commands +PUBLIC void LuaL2cNewLib(const char *label, luaL_Reg *l2cFunc, int count) { + // luaL_newlib(luaState, l2cFunc); macro does not work with pointer :( + luaL_checkversion(luaState); + lua_createtable(luaState, 0, count+1); + luaL_setfuncs(luaState,l2cFunc,0); + lua_setglobal(luaState, label); +} + +static const luaL_Reg afbFunction[] = { + {"timerclear", LuaTimerClear}, + {"timerget" , LuaTimerGet}, + {"timerset" , LuaTimerSet}, + {"notice" , LuaPrintNotice}, + {"info" , LuaPrintInfo}, + {"warning" , LuaPrintWarning}, + {"debug" , LuaPrintDebug}, + {"error" , LuaPrintError}, + {"servsync" , LuaAfbServiceSync}, + {"service" , LuaAfbService}, + {"success" , LuaAfbSuccess}, + {"fail" , LuaAfbFail}, + {"subscribe" , LuaAfbEventSubscribe}, + {"evtmake" , LuaAfbEventMake}, + {"evtpush" , LuaAfbEventPush}, + + {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)); + strncat (fullprefix, "-", sizeof(fullprefix)); + + json_object *luaScriptPathJ = ScanForConfig(CONTROL_LUA_PATH , CTL_SCAN_RECURSIVE, fullprefix, "lua"); + + // open a new LUA interpretor + luaState = luaL_newstate(); + if (!luaState) { + AFB_ERROR ("LUA_INIT: Fail to open lua interpretor"); + goto OnErrorExit; + } + + // load auxiliary libraries + luaL_openlibs(luaState); + + // redirect print to AFB_NOTICE + luaL_newlib(luaState, afbFunction); + lua_setglobal(luaState, "AFB"); + + // create default lua event to send test pause/resume + luaDefaultEvt=calloc(1,sizeof(LuaAfbEvent)); + luaDefaultEvt->name=CONTROL_LUA_EVENT; + luaDefaultEvt->event = afb_daemon_make_event(CONTROL_LUA_EVENT); + if (!afb_event_is_valid(luaDefaultEvt->event)) { + AFB_ERROR ("POLCTL_INIT: Cannot register lua-events=%s ", CONTROL_LUA_EVENT); + goto OnErrorExit;; + } + + // 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); + + char *filename; char*fullpath; + err= wrap_json_unpack (entryJ, "{s:s, s:s !}", "fullpath", &fullpath,"filename", &filename); + if (err) { + AFB_ERROR ("LUA-INIT HOOPs invalid config file path = %s", json_object_get_string(entryJ)); + goto OnErrorExit; + } + + 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-LOAD HOOPs Error in LUA loading scripts=%s err=%s", filepath, lua_tostring(luaState,-1)); + goto OnErrorExit; + } + + // exec/compil script + err = lua_pcall(luaState, 0, 0, 0); + if (err) { + AFB_ERROR ("LUA-LOAD HOOPs Error in LUA exec scripts=%s err=%s", filepath, lua_tostring(luaState,-1)); + goto OnErrorExit; + } + } + + // no policy config found remove control API from binder + if (index == 0) { + AFB_WARNING ("POLICY-INIT:WARNING No Control LUA file in path=[%s]", CONTROL_LUA_PATH); + } + + AFB_DEBUG ("Audio control-LUA Init Done"); + return 0; + + OnErrorExit: + return 1; +} + \ No newline at end of file -- cgit 1.2.3-korg From d51d083be8e34000cd00ce979445eacb45a16e97 Mon Sep 17 00:00:00 2001 From: Fulup Ar Foll Date: Sun, 20 Aug 2017 17:16:28 +0200 Subject: Updated to latest App Template --- Alsa-afb/Alsa-ApiHat.c | 2 +- Alsa-afb/CMakeLists.txt | 3 - Audio-Common/filescan-utils.c | 9 +- Controller-afb/CMakeLists.txt | 5 +- Controller-afb/README.md | 2 +- Controller-afb/ctl-binding.c | 7 +- Controller-afb/ctl-dispatch.c | 4 +- Controller-afb/ctl-lua.c | 7 +- HAL-afb/HDA-intel/CMakeLists.txt | 3 - HAL-afb/Jabra-Solemate/CMakeLists.txt | 4 - HAL-afb/Scarlett-Focusrite/CMakeLists.txt | 4 - README.md | 4 +- conf.d/app-templates | 2 +- conf.d/project/config.d/CMakeLists.txt | 32 - conf.d/project/config.d/onload-audio-control.json | 128 ---- .../project/config.d/onload-daemon-standalone.json | 72 -- conf.d/project/json.d/CMakeLists.txt | 32 + conf.d/project/json.d/onload-audio-control.json | 128 ++++ .../project/json.d/onload-daemon-standalone.json | 72 ++ conf.d/project/lua.d/onload-aaaa-00-utils.lua | 86 +++ conf.d/project/lua.d/onload-aaaa-01-controls.lua | 162 +++++ conf.d/project/lua.d/onload-aaaa-02-timer.lua | 69 ++ conf.d/project/lua.d/onload-aaaa-03-oncall.lua | 70 ++ conf.d/project/lua.d/onload-audio-0utils.lua | 86 --- conf.d/project/lua.d/onload-audio-controls.lua | 162 ----- conf.d/project/lua.d/onload-audio-oncall.lua | 70 -- conf.d/project/lua.d/onload-audio-timer.lua | 69 -- data/CMakeLists.txt | 33 - data/default-control-policy.json | 90 --- nbproject/configurations.xml | 759 +++++++++++++++++++-- nbproject/project.xml | 4 + 31 files changed, 1339 insertions(+), 841 deletions(-) delete mode 100644 conf.d/project/config.d/CMakeLists.txt delete mode 100644 conf.d/project/config.d/onload-audio-control.json delete mode 100644 conf.d/project/config.d/onload-daemon-standalone.json create mode 100644 conf.d/project/json.d/CMakeLists.txt create mode 100644 conf.d/project/json.d/onload-audio-control.json create mode 100644 conf.d/project/json.d/onload-daemon-standalone.json create mode 100644 conf.d/project/lua.d/onload-aaaa-00-utils.lua create mode 100644 conf.d/project/lua.d/onload-aaaa-01-controls.lua create mode 100644 conf.d/project/lua.d/onload-aaaa-02-timer.lua create mode 100644 conf.d/project/lua.d/onload-aaaa-03-oncall.lua delete mode 100644 conf.d/project/lua.d/onload-audio-0utils.lua delete mode 100644 conf.d/project/lua.d/onload-audio-controls.lua delete mode 100644 conf.d/project/lua.d/onload-audio-oncall.lua delete mode 100644 conf.d/project/lua.d/onload-audio-timer.lua delete mode 100644 data/CMakeLists.txt delete mode 100644 data/default-control-policy.json (limited to 'Controller-afb/ctl-lua.c') diff --git a/Alsa-afb/Alsa-ApiHat.c b/Alsa-afb/Alsa-ApiHat.c index a8663ca..e22f2d5 100644 --- a/Alsa-afb/Alsa-ApiHat.c +++ b/Alsa-afb/Alsa-ApiHat.c @@ -31,7 +31,7 @@ #include "Alsa-ApiHat.h" STATIC int AlsaInit(void) { - int rc= prctl(PR_SET_NAME, "afb-audio-agent",NULL,NULL,NULL); + int rc= prctl(PR_SET_NAME, "afb-aaaa-agent",NULL,NULL,NULL); if (rc) AFB_ERROR("ERROR: AlsaCore fail to rename process"); return rc; diff --git a/Alsa-afb/CMakeLists.txt b/Alsa-afb/CMakeLists.txt index 38b957d..fab49ae 100644 --- a/Alsa-afb/CMakeLists.txt +++ b/Alsa-afb/CMakeLists.txt @@ -36,6 +36,3 @@ PROJECT_TARGET_ADD(alsa-lowlevel) ${link_libraries} ) - # installation directory - INSTALL(TARGETS ${TARGET_NAME} - LIBRARY DESTINATION ${CMAKE_INSTALL_PREFIX}) diff --git a/Audio-Common/filescan-utils.c b/Audio-Common/filescan-utils.c index af0b5c9..4a5613f 100644 --- a/Audio-Common/filescan-utils.c +++ b/Audio-Common/filescan-utils.c @@ -113,9 +113,12 @@ PUBLIC const char *GetBinderName() { if (binderName) return binderName; - // retrieve binder name from process name afb-name-trailer - prctl(PR_GET_NAME, psName,NULL,NULL,NULL); - binderName=(char*)GetMidleName(psName); + binderName= getenv("AFB_BINDER_NAME"); + if (!binderName) { + // retrieve binder name from process name afb-name-trailer + prctl(PR_GET_NAME, psName,NULL,NULL,NULL); + binderName=(char*)GetMidleName(psName); + } return binderName; } \ No newline at end of file diff --git a/Controller-afb/CMakeLists.txt b/Controller-afb/CMakeLists.txt index d1eb886..c7602f8 100644 --- a/Controller-afb/CMakeLists.txt +++ b/Controller-afb/CMakeLists.txt @@ -16,7 +16,7 @@ # limitations under the License. ########################################################################### -ADD_COMPILE_OPTIONS(-DCONTROL_ONLOAD_DEFAULT="onload-default") +ADD_COMPILE_OPTIONS(-DCONTROL_ONLOAD_PROFILE="onload-default-profile") ADD_COMPILE_OPTIONS(-DCONTROL_DOSCRIPT_PRE="doscript") ADD_COMPILE_OPTIONS(-DCONTROL_CONFIG_PRE="onload") @@ -57,9 +57,6 @@ PROJECT_TARGET_ADD(control-afb) ${link_libraries} ) - # installation directory - INSTALL(TARGETS ${TARGET_NAME} - LIBRARY DESTINATION ${CMAKE_INSTALL_PREFIX} ) PROJECT_TARGET_ADD(audio-plugin-sample) diff --git a/Controller-afb/README.md b/Controller-afb/README.md index e6cab72..9bab485 100644 --- a/Controller-afb/README.md +++ b/Controller-afb/README.md @@ -30,7 +30,7 @@ Each bloc in the configuration file are defined with * 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. +environment variable. Setenv 'CONTROL_ONLOAD_PROFILE'=xxxx to overload 'onload-default-profile' initialisation sequence. ### Config is organised in 4 sections: diff --git a/Controller-afb/ctl-binding.c b/Controller-afb/ctl-binding.c index 8771fc0..ec33f82 100644 --- a/Controller-afb/ctl-binding.c +++ b/Controller-afb/ctl-binding.c @@ -55,9 +55,12 @@ PUBLIC int CtlBindingInit () { 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_DEFAULT); + if (!errcount) + errcount += DispatchOnLoad(CONTROL_ONLOAD_PROFILE); AFB_DEBUG ("Audio Policy Control Binding Done errcount=%d", errcount); return errcount; diff --git a/Controller-afb/ctl-dispatch.c b/Controller-afb/ctl-dispatch.c index 1708204..0104229 100644 --- a/Controller-afb/ctl-dispatch.c +++ b/Controller-afb/ctl-dispatch.c @@ -178,6 +178,8 @@ PUBLIC void DispatchOneEvent(const char *evtLabel, json_object *eventJ) { // 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); @@ -650,7 +652,7 @@ PUBLIC int DispatchInit() { // no dispatch config found remove control API from binder if (!luaLoaded) { - AFB_WARNING("DISPATCH-INIT:WARNING Not Found Control dispatch file [%s]", controlFile); + AFB_WARNING("DISPATCH-INIT:WARNING (setenv CONTROL_CONFIG_PATH) No Config '%s-*.json' in '%s'", controlFile, dirList); } AFB_NOTICE("DISPATCH-INIT:SUCCES: Audio Control Dispatch Init"); diff --git a/Controller-afb/ctl-lua.c b/Controller-afb/ctl-lua.c index 4ef6b65..3f45055 100644 --- a/Controller-afb/ctl-lua.c +++ b/Controller-afb/ctl-lua.c @@ -965,7 +965,10 @@ PUBLIC int LuaLibInit () { strncat (fullprefix, GetBinderName(), sizeof(fullprefix)); strncat (fullprefix, "-", sizeof(fullprefix)); - json_object *luaScriptPathJ = ScanForConfig(CONTROL_LUA_PATH , CTL_SCAN_RECURSIVE, fullprefix, "lua"); + const char *dirList= getenv("CONTROL_LUA_PATH"); + if (!dirList) dirList=CONTROL_LUA_PATH; + + json_object *luaScriptPathJ = ScanForConfig(dirList , CTL_SCAN_RECURSIVE, fullprefix, "lua"); // open a new LUA interpretor luaState = luaL_newstate(); @@ -1021,7 +1024,7 @@ PUBLIC int LuaLibInit () { // no policy config found remove control API from binder if (index == 0) { - AFB_WARNING ("POLICY-INIT:WARNING No Control LUA file in path=[%s]", CONTROL_LUA_PATH); + AFB_WARNING ("POLICY-INIT:WARNING (setenv CONTROL_LUA_PATH) No LUA '%s*.lua' in '%s'", fullprefix, dirList); } AFB_DEBUG ("Audio control-LUA Init Done"); diff --git a/HAL-afb/HDA-intel/CMakeLists.txt b/HAL-afb/HDA-intel/CMakeLists.txt index aa67e0b..380e493 100644 --- a/HAL-afb/HDA-intel/CMakeLists.txt +++ b/HAL-afb/HDA-intel/CMakeLists.txt @@ -37,6 +37,3 @@ PROJECT_TARGET_ADD(hal-intel-hda) audio-common ) - # installation directory - INSTALL(TARGETS ${TARGET_NAME} - LIBRARY DESTINATION ${CMAKE_INSTALL_PREFIX}) diff --git a/HAL-afb/Jabra-Solemate/CMakeLists.txt b/HAL-afb/Jabra-Solemate/CMakeLists.txt index bf61dad..41d6915 100644 --- a/HAL-afb/Jabra-Solemate/CMakeLists.txt +++ b/HAL-afb/Jabra-Solemate/CMakeLists.txt @@ -36,7 +36,3 @@ PROJECT_TARGET_ADD(hal-jabra-usb) hal-interface audio-common ) - - # installation directory - INSTALL(TARGETS ${TARGET_NAME} - LIBRARY DESTINATION ${CMAKE_INSTALL_PREFIX}) diff --git a/HAL-afb/Scarlett-Focusrite/CMakeLists.txt b/HAL-afb/Scarlett-Focusrite/CMakeLists.txt index 1cc83e6..90ee92a 100644 --- a/HAL-afb/Scarlett-Focusrite/CMakeLists.txt +++ b/HAL-afb/Scarlett-Focusrite/CMakeLists.txt @@ -36,7 +36,3 @@ PROJECT_TARGET_ADD(hal-scalett-usb) hal-interface audio-common ) - - # installation directory - INSTALL(TARGETS ${TARGET_NAME} - LIBRARY DESTINATION ${CMAKE_INSTALL_PREFIX}) diff --git a/README.md b/README.md index 2063677..e9ad55f 100644 --- a/README.md +++ b/README.md @@ -113,9 +113,7 @@ from the wrong relative directory, either you have to use 'set solib-search-path # ToBeBone (WorkInProgess: This list is getting longer every day) ------------------------------------------------------------------- -* Support response from LUA with nested table (currently fail miserably) -* Add timer base callback from Lua -* Enable export of LUA commands directly from Plugin + * Allow LUA to run a shell command # Running an debugging on a target ------------------------------------------------------- diff --git a/conf.d/app-templates b/conf.d/app-templates index 9a73785..350c5b9 160000 --- a/conf.d/app-templates +++ b/conf.d/app-templates @@ -1 +1 @@ -Subproject commit 9a737858056dae3348e4659ed5e9168d39f1b23a +Subproject commit 350c5b97459226f7e031c73edb3a79a2d99cb250 diff --git a/conf.d/project/config.d/CMakeLists.txt b/conf.d/project/config.d/CMakeLists.txt deleted file mode 100644 index 8070997..0000000 --- a/conf.d/project/config.d/CMakeLists.txt +++ /dev/null @@ -1,32 +0,0 @@ -########################################################################### -# Copyright 2017 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. -########################################################################### - - -################################################## -# 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/config.d/onload-audio-control.json b/conf.d/project/config.d/onload-audio-control.json deleted file mode 100644 index 77a8fce..0000000 --- a/conf.d/project/config.d/onload-audio-control.json +++ /dev/null @@ -1,128 +0,0 @@ -{ - "$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": {"data": "none"} - }, { - "label": "onload-hal-lua", - "info": "Load avaliable HALs", - "lua": "_Alsa_Get_Hal" - } - ] - }], - "controls": - [ - { - "label": "multimedia", - "actions": { - "label": "multimedia-control-lua", - "info": "Call Lua Script function Test_Lua_Engin", - "lua": "_Audio_Set_Multimedia" - } - }, { - "label": "navigation", - "actions": { - "label": "navigation-control-lua", - "info": "Call Lua Script to set Navigation", - "lua": "_Audio_Set_Navigation" - } - }, { - "label": "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": "SampleEvent1", - "info": "define action when receiving a given event", - "actions": [ - { - "label": "Event Callback-1", - "callback": "SampleControlEvent", - "args": { - "arg": "action-1" - } - }, { - "label": "Event Callback-2", - "callback": "SampleControlEvent", - "args": { - "arg": "action-2" - } - } - ] - }, - { - "label": "SampleEvent2", - "info": "define action when receiving a given event", - "actions": [ - { - "label": "Event Callback-1", - "callback": "SampleControlEvent", - "args": { - "arg": "action-1" - } - }, { - "label": "Event Callback-2", - "callback": "SampleControlEvent", - "args": { - "arg": "action-2" - } - } - ] - } - ] -} - diff --git a/conf.d/project/config.d/onload-daemon-standalone.json b/conf.d/project/config.d/onload-daemon-standalone.json deleted file mode 100644 index de52c22..0000000 --- a/conf.d/project/config.d/onload-daemon-standalone.json +++ /dev/null @@ -1,72 +0,0 @@ -{ - "$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/json.d/CMakeLists.txt b/conf.d/project/json.d/CMakeLists.txt new file mode 100644 index 0000000..8070997 --- /dev/null +++ b/conf.d/project/json.d/CMakeLists.txt @@ -0,0 +1,32 @@ +########################################################################### +# Copyright 2017 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. +########################################################################### + + +################################################## +# 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/onload-audio-control.json b/conf.d/project/json.d/onload-audio-control.json new file mode 100644 index 0000000..77a8fce --- /dev/null +++ b/conf.d/project/json.d/onload-audio-control.json @@ -0,0 +1,128 @@ +{ + "$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": {"data": "none"} + }, { + "label": "onload-hal-lua", + "info": "Load avaliable HALs", + "lua": "_Alsa_Get_Hal" + } + ] + }], + "controls": + [ + { + "label": "multimedia", + "actions": { + "label": "multimedia-control-lua", + "info": "Call Lua Script function Test_Lua_Engin", + "lua": "_Audio_Set_Multimedia" + } + }, { + "label": "navigation", + "actions": { + "label": "navigation-control-lua", + "info": "Call Lua Script to set Navigation", + "lua": "_Audio_Set_Navigation" + } + }, { + "label": "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": "SampleEvent1", + "info": "define action when receiving a given event", + "actions": [ + { + "label": "Event Callback-1", + "callback": "SampleControlEvent", + "args": { + "arg": "action-1" + } + }, { + "label": "Event Callback-2", + "callback": "SampleControlEvent", + "args": { + "arg": "action-2" + } + } + ] + }, + { + "label": "SampleEvent2", + "info": "define action when receiving a given event", + "actions": [ + { + "label": "Event Callback-1", + "callback": "SampleControlEvent", + "args": { + "arg": "action-1" + } + }, { + "label": "Event Callback-2", + "callback": "SampleControlEvent", + "args": { + "arg": "action-2" + } + } + ] + } + ] +} + diff --git a/conf.d/project/json.d/onload-daemon-standalone.json b/conf.d/project/json.d/onload-daemon-standalone.json new file mode 100644 index 0000000..de52c22 --- /dev/null +++ b/conf.d/project/json.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/onload-aaaa-00-utils.lua b/conf.d/project/lua.d/onload-aaaa-00-utils.lua new file mode 100644 index 0000000..b8ecd7e --- /dev/null +++ b/conf.d/project/lua.d/onload-aaaa-00-utils.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/onload-aaaa-01-controls.lua b/conf.d/project/lua.d/onload-aaaa-01-controls.lua new file mode 100644 index 0000000..24c4f71 --- /dev/null +++ b/conf.d/project/lua.d/onload-aaaa-01-controls.lua @@ -0,0 +1,162 @@ +--[[ + 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. + + + Provide sample policy function for AGL Advance Audio Agent +--]] + +-- Global HAL registry +_Audio_Hal_Registry={} + +-- Callback when receiving HAL registry +function _Alsa_Get_Hal_CB (error, result, context) + -- Initialise an empty table + local registry={} + + -- Only process when response is valid + if (error) then + AFB_ErrOr ("[Audio_Init_CB] ErrOr result=%s", result) + return + end + + -- Extract response from result + local response=result["response"] + + -- Index HAL Bindings APIs by shortname + for key,value in pairs(response) do + registry[value["shortname"]]=value["api"] + end + + -- store Exiting HAL for further use + printf ("-- [Audio_Init_CB] -- Audio_register_Hal=%s", Dump_Table(registry)) + _Audio_Hal_Registry=registry + +end + +-- Function call at binding load time +function _Alsa_Get_Hal(args) + + printf ("[-- Audio_Get_Hal --] args=%s", Dump_Table(argsT)) + + -- Query AlsaCore for Active HALs (no query, no context) + AFB:service ('alsacore', 'hallist', {}, "_Alsa_Get_Hal_CB", {}) + +end + +-- In sample configuration Query/Args parsing is common to all audio control +local function Audio_Parse_Request (source, args, query) + + local apihal={} + + -- In this test we expect targeted device to be given from query (could come for args as well) + if (query == nil ) then + AFB:error ("--LUA:Audio_Set_Navigation query should contain and args with targeted apihal|device") + return -- refuse control + end + + -- Alsa Hook plugin asound sample config provides target sound card by name + if (query["device"] ~= nil) then + apihal=_Audio_Hal_Registry[query["device"]] + end + + -- HTML5 test page provides directly HAL api. + if (query["apihal"] ~= nil) then + apihal= query["apihal"] + end + + -- if requested HAL is not found then deny the control + if (apihal == nil) then + AFB:error ("--LUA:Audio_Set_Navigation No Active HAL Found") + return -- refuse control + end + + -- return api or nil when not found + return apihal +end + +-- Set Navigation lower sound when play +function _Audio_Set_Navigation(source, args, query) + + -- in strict mode every variables should be declared + local err=0 + local ctlhal={} + local response={} + local apihal={} + + AFB:notice ("LUA:Audio_Set_Use_Case source=%d args=%s query=%s", source, args, query); + + -- Parse Query/Args and if HAL not found then refuse access + apihal= Audio_Parse_Request (source, args, query) + if (apihal == nil) then return 1 end + + + -- if source < 0 then Alsa HookPlugin is closing PCM + if (source < 0) then + -- Ramp Up Multimedia channel synchronously + ctlhal={['label']='Master_Playback_Volume', ['val']=100} + err, response= AFB:servsync (apihal, 'ctlset',ctlhal) + else + -- Ramp Down Multimedia channel synchronously + ctlhal={['label']='Master_Playback_Volume', ['val']=50} + err, response= AFB:servsync (apihal, 'ctlset',ctlhal) + end + + if (err) then + AFB:error("--LUA:Audio_Set_Navigation halapi=%s refuse ctl=%s", apihal, ctlhal) + return 1 -- control refused + end + + + return 0 -- control accepted +end + + +-- Select Multimedia mode +function _Audio_Set_Multimedia (source, args, query) + + -- in strict mode every variables should be declared + local err=0 + local ctlhal={} + local response={} + local apihal={} + + AFB:notice ("LUA:Audio_Set_Use_Case source=%d args=%s query=%s", source, args, query); + + -- Parse Query/Args and if HAL not found then refuse access + apihal= Audio_Parse_Request (source, args, query) + if (apihal == nil) then return 1 end + + + -- if Mumtimedia control only increase volume on open + if (source >= 0) then + -- Ramp Down Multimedia channel synchronously + ctlhal={['label']='Master_Playback_Volume', ['val']=100} + err, response= AFB:servsync (apihal, 'ctlset',ctlhal) + end + + if (err) then + AFB:error("--LUA:Audio_Set_Navigation halapi=%s refuse ctl=%s", apihal, ctlhal) + return 1 -- control refused + end + + + return 0 -- control accepted +end + +-- Select Emergency Mode +function _Audio_Set_Emergency(source, args, query) + return 1 -- Always refuse in this test +end diff --git a/conf.d/project/lua.d/onload-aaaa-02-timer.lua b/conf.d/project/lua.d/onload-aaaa-02-timer.lua new file mode 100644 index 0000000..db7a937 --- /dev/null +++ b/conf.d/project/lua.d/onload-aaaa-02-timer.lua @@ -0,0 +1,69 @@ +--[[ + 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. + + + Provide Sample Timer Handing to push event from LUA +--]] + +-- Create event on Lua script load +local MyEventHandle=AFB:evtmake("MyTestEvent") + +-- Call count time every delay/ms +local function Timer_Test_CB (timer, context) + + local evtinfo= AFB:timerget(timer) + print ("timer=", Dump_Table(evtinfo)) + + --send an event an event with count as value + AFB:evtpush (MyEventHandle, {["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, args) + + local context = { + ["info"]="My 1st private Event", + } + + -- if delay not defined default is 5s + if (args["delay"]==nil) then args["delay"]=5000 end + + -- if count is not defined default is 10 + if (args["count"]==nil) then args["count"]=10 end + + -- we could use directly args but it is a sample + local myTimer = { + ["label"]=args["label"], + ["delay"]=args["delay"], + ["count"]=args["count"], + } + AFB:notice ("Test_Timer myTimer=%s", myTimer) + + -- subscribe to event + AFB:subscribe (request, MyEventHandle) + + -- 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 args + AFB:success (request, myTimer) + + return 0 +end diff --git a/conf.d/project/lua.d/onload-aaaa-03-oncall.lua b/conf.d/project/lua.d/onload-aaaa-03-oncall.lua new file mode 100644 index 0000000..23b538e --- /dev/null +++ b/conf.d/project/lua.d/onload-aaaa-03-oncall.lua @@ -0,0 +1,70 @@ +--[[ + 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. + + + 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("alsacore","ping", "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 + diff --git a/conf.d/project/lua.d/onload-audio-0utils.lua b/conf.d/project/lua.d/onload-audio-0utils.lua deleted file mode 100644 index b8ecd7e..0000000 --- a/conf.d/project/lua.d/onload-audio-0utils.lua +++ /dev/null @@ -1,86 +0,0 @@ ---[[ - 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/onload-audio-controls.lua b/conf.d/project/lua.d/onload-audio-controls.lua deleted file mode 100644 index 24c4f71..0000000 --- a/conf.d/project/lua.d/onload-audio-controls.lua +++ /dev/null @@ -1,162 +0,0 @@ ---[[ - 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. - - - Provide sample policy function for AGL Advance Audio Agent ---]] - --- Global HAL registry -_Audio_Hal_Registry={} - --- Callback when receiving HAL registry -function _Alsa_Get_Hal_CB (error, result, context) - -- Initialise an empty table - local registry={} - - -- Only process when response is valid - if (error) then - AFB_ErrOr ("[Audio_Init_CB] ErrOr result=%s", result) - return - end - - -- Extract response from result - local response=result["response"] - - -- Index HAL Bindings APIs by shortname - for key,value in pairs(response) do - registry[value["shortname"]]=value["api"] - end - - -- store Exiting HAL for further use - printf ("-- [Audio_Init_CB] -- Audio_register_Hal=%s", Dump_Table(registry)) - _Audio_Hal_Registry=registry - -end - --- Function call at binding load time -function _Alsa_Get_Hal(args) - - printf ("[-- Audio_Get_Hal --] args=%s", Dump_Table(argsT)) - - -- Query AlsaCore for Active HALs (no query, no context) - AFB:service ('alsacore', 'hallist', {}, "_Alsa_Get_Hal_CB", {}) - -end - --- In sample configuration Query/Args parsing is common to all audio control -local function Audio_Parse_Request (source, args, query) - - local apihal={} - - -- In this test we expect targeted device to be given from query (could come for args as well) - if (query == nil ) then - AFB:error ("--LUA:Audio_Set_Navigation query should contain and args with targeted apihal|device") - return -- refuse control - end - - -- Alsa Hook plugin asound sample config provides target sound card by name - if (query["device"] ~= nil) then - apihal=_Audio_Hal_Registry[query["device"]] - end - - -- HTML5 test page provides directly HAL api. - if (query["apihal"] ~= nil) then - apihal= query["apihal"] - end - - -- if requested HAL is not found then deny the control - if (apihal == nil) then - AFB:error ("--LUA:Audio_Set_Navigation No Active HAL Found") - return -- refuse control - end - - -- return api or nil when not found - return apihal -end - --- Set Navigation lower sound when play -function _Audio_Set_Navigation(source, args, query) - - -- in strict mode every variables should be declared - local err=0 - local ctlhal={} - local response={} - local apihal={} - - AFB:notice ("LUA:Audio_Set_Use_Case source=%d args=%s query=%s", source, args, query); - - -- Parse Query/Args and if HAL not found then refuse access - apihal= Audio_Parse_Request (source, args, query) - if (apihal == nil) then return 1 end - - - -- if source < 0 then Alsa HookPlugin is closing PCM - if (source < 0) then - -- Ramp Up Multimedia channel synchronously - ctlhal={['label']='Master_Playback_Volume', ['val']=100} - err, response= AFB:servsync (apihal, 'ctlset',ctlhal) - else - -- Ramp Down Multimedia channel synchronously - ctlhal={['label']='Master_Playback_Volume', ['val']=50} - err, response= AFB:servsync (apihal, 'ctlset',ctlhal) - end - - if (err) then - AFB:error("--LUA:Audio_Set_Navigation halapi=%s refuse ctl=%s", apihal, ctlhal) - return 1 -- control refused - end - - - return 0 -- control accepted -end - - --- Select Multimedia mode -function _Audio_Set_Multimedia (source, args, query) - - -- in strict mode every variables should be declared - local err=0 - local ctlhal={} - local response={} - local apihal={} - - AFB:notice ("LUA:Audio_Set_Use_Case source=%d args=%s query=%s", source, args, query); - - -- Parse Query/Args and if HAL not found then refuse access - apihal= Audio_Parse_Request (source, args, query) - if (apihal == nil) then return 1 end - - - -- if Mumtimedia control only increase volume on open - if (source >= 0) then - -- Ramp Down Multimedia channel synchronously - ctlhal={['label']='Master_Playback_Volume', ['val']=100} - err, response= AFB:servsync (apihal, 'ctlset',ctlhal) - end - - if (err) then - AFB:error("--LUA:Audio_Set_Navigation halapi=%s refuse ctl=%s", apihal, ctlhal) - return 1 -- control refused - end - - - return 0 -- control accepted -end - --- Select Emergency Mode -function _Audio_Set_Emergency(source, args, query) - return 1 -- Always refuse in this test -end diff --git a/conf.d/project/lua.d/onload-audio-oncall.lua b/conf.d/project/lua.d/onload-audio-oncall.lua deleted file mode 100644 index 23b538e..0000000 --- a/conf.d/project/lua.d/onload-audio-oncall.lua +++ /dev/null @@ -1,70 +0,0 @@ ---[[ - 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. - - - 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("alsacore","ping", "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 - diff --git a/conf.d/project/lua.d/onload-audio-timer.lua b/conf.d/project/lua.d/onload-audio-timer.lua deleted file mode 100644 index db7a937..0000000 --- a/conf.d/project/lua.d/onload-audio-timer.lua +++ /dev/null @@ -1,69 +0,0 @@ ---[[ - 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. - - - Provide Sample Timer Handing to push event from LUA ---]] - --- Create event on Lua script load -local MyEventHandle=AFB:evtmake("MyTestEvent") - --- Call count time every delay/ms -local function Timer_Test_CB (timer, context) - - local evtinfo= AFB:timerget(timer) - print ("timer=", Dump_Table(evtinfo)) - - --send an event an event with count as value - AFB:evtpush (MyEventHandle, {["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, args) - - local context = { - ["info"]="My 1st private Event", - } - - -- if delay not defined default is 5s - if (args["delay"]==nil) then args["delay"]=5000 end - - -- if count is not defined default is 10 - if (args["count"]==nil) then args["count"]=10 end - - -- we could use directly args but it is a sample - local myTimer = { - ["label"]=args["label"], - ["delay"]=args["delay"], - ["count"]=args["count"], - } - AFB:notice ("Test_Timer myTimer=%s", myTimer) - - -- subscribe to event - AFB:subscribe (request, MyEventHandle) - - -- 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 args - AFB:success (request, myTimer) - - return 0 -end diff --git a/data/CMakeLists.txt b/data/CMakeLists.txt deleted file mode 100644 index 3b052c9..0000000 --- a/data/CMakeLists.txt +++ /dev/null @@ -1,33 +0,0 @@ -########################################################################### -# Copyright 2017 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. -########################################################################### - - - -################################################## -# Control Policy Config file -################################################## -PROJECT_TARGET_ADD(Control_config) - - 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/data/default-control-policy.json b/data/default-control-policy.json deleted file mode 100644 index c6f8bd0..0000000 --- a/data/default-control-policy.json +++ /dev/null @@ -1,90 +0,0 @@ -{ - "$schema": "ToBeDone", - "metadata": { - "label": "sample-audio-policy", - "info": "Provide Default Audio Policy for Multimedia, Navigation and Emergency", - "version": "1.0" - }, - "onload": { - "info": "controller initialisation config", - "plugin": "sample-audio-policy.so", - "actions": [ - { - "info": "Call policy sharelib install entrypoint", - "callback": "SamplePolicyInstall", - "query": {"arg1" : "first_arg", "nextarg": "second arg value"} - }, { - "info": "Assert AlsaCore Presence", - "api": "alsacore", - "verb": "ping" - } - ] - }, - "controls": - [{ - "label": "multimedia", - "actions": [ - { - "label": "multimedia-policy-cb", - "info": "Call Sharelib Sample Callback", - "callback": "samplePolicyCB", - "query": { - "arg1": "snoopy", - "arg2": "toto" - } - }, { - "label": "multimedia-policy-ucm", - "info": "Subcall AlSA UCM navigation", - "api": "alsacore", - "verb": "ucmset", - "query": { - "verb": "multimedia" - } - } - ] - }, - { - "label":"navigation", - "action" : { - "api": "alsacore", - "verb": "ucmset", - "query": { - "verb": "navigation" - }, - "optional": true, - "timeout": 100 - } - }, { - "label":"emergency", - "action": { - "api": "alsacore", - "verb": "ucmset", - "query": { - "verb": "emergency" - } - } - }] - , - "events": [ - { - "label": "SampleEvent", - "comment": "define action when receiving a given event", - "actions": [ - { - "info": "Event Callback-1", - "callback": "ProcessEventCB", - "query": { - "arg": "action-1" - } - }, { - "info": "Event Callback-2", - "callback": "ProcessEventCB", - "query": { - "arg": "action-2" - } - } - ] - } - ] -} - diff --git a/nbproject/configurations.xml b/nbproject/configurations.xml index 235c3b0..cf14956 100644 --- a/nbproject/configurations.xml +++ b/nbproject/configurations.xml @@ -49,6 +49,7 @@ ctl-lua.c ctl-misc.c ctl-plugin-sample.c + ctl-policy.c ctl-timer.c @@ -118,11 +119,10 @@ false - - - - - + + + @@ -134,7 +134,7 @@ ${MAKE} -f Makefile install ${MAKE} -f Makefile clean build/CMakeFiles/feature_tests.bin - + @@ -147,11 +147,11 @@ ex="false" tool="0" flavor2="3"> - + - + ../../../opt/include/alsa /usr/include/json-c @@ -162,14 +162,14 @@ - + build/Alsa-afb - + ../../../opt/include/alsa /usr/include/json-c @@ -180,7 +180,7 @@ - + ../../../opt/include/alsa /usr/include/json-c @@ -191,7 +191,7 @@ - + ../../../opt/include/alsa /usr/include/json-c @@ -202,7 +202,7 @@ - + ../../../opt/include/afb Audio-Common @@ -212,7 +212,7 @@ - + ../../../opt/include/afb Audio-Common @@ -222,7 +222,7 @@ - + Audio-Common /usr/include/json-c @@ -231,45 +231,19 @@ - + - + - ../../../opt/include - ../../../opt/include/alsa - /usr/include/p11-kit-1 - /usr/include/json-c - /usr/include/lua5.3 - Audio-Common build/Controller-afb - - CONTROL_CONFIG_PATH="/home/fulup/Workspace/AGL-AppFW/audio-bindings-dev/conf.d/project/config.d:/usr/local/controller/config.d" - CONTROL_CONFIG_POST="control" - CONTROL_CONFIG_PRE="onload" - CONTROL_DOSCRIPT_PRE="doscript" - CONTROL_LUA_EVENT="luaevt" - CONTROL_LUA_PATH="/home/fulup/Workspace/AGL-AppFW/audio-bindings-dev/conf.d/project/lua.d:/usr/local/controller/ctl-lua.d" - CONTROL_MAXPATH_LEN=255 - CONTROL_ONLOAD_DEFAULT="onload-default" - CONTROL_PLUGIN_PATH="/home/fulup/Workspace/AGL-AppFW/audio-bindings-dev/build:/home/fulup/opt/audio-bindings/ctlplug:/usr/lib/afb/ctlplug" - CONTROL_SUPPORT_LUA - CTL_PLUGIN_MAGIC=2468013579 - MAX_LINEAR_DB_SCALE=24 - MAX_SND_CARD=16 - NATIVE_LINUX - TLV_BYTE_SIZE=256 - control_afb_EXPORTS - - + - ../../../opt/include/afb - Controller-afb /usr/include/json-c /usr/include/lua5.3 Audio-Common @@ -279,10 +253,8 @@ - + - ../../../opt/include/afb - Controller-afb /usr/include/json-c /usr/include/lua5.3 Audio-Common @@ -292,20 +264,16 @@ - + - ../../../opt/include/afb - Controller-afb /usr/include/json-c build/Controller-afb - + - ../../../opt/include/afb - Controller-afb /usr/include/json-c /usr/include/lua5.3 build/Controller-afb @@ -313,10 +281,8 @@ - + - ../../../opt/include/afb - Controller-afb ../../../opt/include build/Controller-afb @@ -326,9 +292,10 @@ ex="false" tool="0" flavor2="3"> - + Audio-Common + ../../../opt/include build/HAL-afb/HAL-interface @@ -337,7 +304,7 @@ ex="false" tool="0" flavor2="3"> - + Audio-Common build/HAL-afb/HAL-interface @@ -345,36 +312,36 @@ - + build/HAL-afb/HAL-interface - + - + - + - + - + Shared-Interface HAL-afb/HAL-interface @@ -383,7 +350,7 @@ - + HAL-afb/HAL-interface build/HAL-afb/Unicens-USB @@ -391,11 +358,11 @@ - + - + @@ -505,6 +472,14 @@ + + + + ../../../opt/include/afb + Controller-afb + + + @@ -2562,5 +2537,655 @@ + + + GNU|GNU + false + false + + + + + + + + + + true + + + + build + ${MAKE} -f Makefile install + ${MAKE} -f Makefile clean + build/CMakeFiles/feature_tests.bin + + + + + build + cmake .. + true + + + + + + + + + + ../../../opt/include/afb + Alsa-afb + ../../../opt/include/alsa + /usr/include/json-c + Audio-Common + ../../../opt/include + build/Alsa-afb + + + + + + + ../../../opt/include + ../../../opt/include/alsa + /usr/include/p11-kit-1 + /usr/include/json-c + /usr/include/lua5.3 + Audio-Common + build/Alsa-afb + + + CONTROL_MAXPATH_LEN=255 + MAX_LINEAR_DB_SCALE=24 + MAX_SND_CARD=16 + NATIVE_LINUX + TLV_BYTE_SIZE=256 + alsa_lowlevel_EXPORTS + + + + + + + ../../../opt/include/afb + Alsa-afb + ../../../opt/include/alsa + /usr/include/json-c + Audio-Common + ../../../opt/include + build/Alsa-afb + + + + + + + ../../../opt/include/afb + Alsa-afb + ../../../opt/include/alsa + /usr/include/json-c + Audio-Common + ../../../opt/include + build/Alsa-afb + + + + + + + ../../../opt/include/afb + Alsa-afb + ../../../opt/include/alsa + /usr/include/json-c + Audio-Common + ../../../opt/include + build/Alsa-afb + + + + + + + ../../../opt/include/afb + Audio-Common + /usr/include/json-c + build/Audio-Common + + + + + + + ../../../opt/include/afb + Audio-Common + /usr/include/json-c + build/Audio-Common + + + + + + + Audio-Common + /usr/include/json-c + build/Audio-Common + + + + + + + + + + + ../../../opt/include + ../../../opt/include/alsa + /usr/include/p11-kit-1 + /usr/include/json-c + /usr/include/lua5.3 + Audio-Common + build/Controller-afb + + + CONTROL_CONFIG_PATH="/home/fulup/Workspace/AGL-AppFW/audio-bindings-dev/conf.d/project/config.d:/home/fulup/opt/controller/config.d" + CONTROL_CONFIG_POST="control" + CONTROL_CONFIG_PRE="onload" + CONTROL_DOSCRIPT_PRE="doscript" + CONTROL_LUA_EVENT="luaevt" + CONTROL_LUA_PATH="/home/fulup/Workspace/AGL-AppFW/audio-bindings-dev/conf.d/project/lua.d:/home/fulup/opt/controller-plugins/ctl-lua.d" + CONTROL_MAXPATH_LEN=255 + CONTROL_ONLOAD_PROFILE="onload-default-profile" + CONTROL_PLUGIN_PATH="/home/fulup/Workspace/AGL-AppFW/audio-bindings-dev/build:/home/fulup/opt/controller-plugins:/usr/lib/afb/controller-plugins/ctlplug" + CONTROL_SUPPORT_LUA + CTL_PLUGIN_MAGIC=2468013579 + MAX_LINEAR_DB_SCALE=24 + MAX_SND_CARD=16 + NATIVE_LINUX + TLV_BYTE_SIZE=256 + control_afb_EXPORTS + + + + + + + ../../../opt/include + ../../../opt/include/alsa + /usr/include/p11-kit-1 + /usr/include/json-c + /usr/include/lua5.3 + Audio-Common + build/Controller-afb + + + CONTROL_CONFIG_PATH="/home/fulup/Workspace/AGL-AppFW/audio-bindings-dev/conf.d/project/config.d:/home/fulup/opt/controller/config.d" + CONTROL_CONFIG_POST="control" + CONTROL_CONFIG_PRE="onload" + CONTROL_DOSCRIPT_PRE="doscript" + CONTROL_LUA_EVENT="luaevt" + CONTROL_LUA_PATH="/home/fulup/Workspace/AGL-AppFW/audio-bindings-dev/conf.d/project/lua.d:/home/fulup/opt/controller-plugins/ctl-lua.d" + CONTROL_MAXPATH_LEN=255 + CONTROL_ONLOAD_PROFILE="onload-default-profile" + CONTROL_PLUGIN_PATH="/home/fulup/Workspace/AGL-AppFW/audio-bindings-dev/build:/home/fulup/opt/controller-plugins:/usr/lib/afb/controller-plugins/ctlplug" + CONTROL_SUPPORT_LUA + CTL_PLUGIN_MAGIC=2468013579 + MAX_LINEAR_DB_SCALE=24 + MAX_SND_CARD=16 + NATIVE_LINUX + TLV_BYTE_SIZE=256 + control_afb_EXPORTS + + + + + + + ../../../opt/include + ../../../opt/include/alsa + /usr/include/p11-kit-1 + /usr/include/json-c + /usr/include/lua5.3 + Audio-Common + build/Controller-afb + + + CONTROL_CONFIG_PATH="/home/fulup/Workspace/AGL-AppFW/audio-bindings-dev/conf.d/project/config.d:/home/fulup/opt/controller/config.d" + CONTROL_CONFIG_POST="control" + CONTROL_CONFIG_PRE="onload" + CONTROL_DOSCRIPT_PRE="doscript" + CONTROL_LUA_EVENT="luaevt" + CONTROL_LUA_PATH="/home/fulup/Workspace/AGL-AppFW/audio-bindings-dev/conf.d/project/lua.d:/home/fulup/opt/controller-plugins/ctl-lua.d" + CONTROL_MAXPATH_LEN=255 + CONTROL_ONLOAD_PROFILE="onload-default-profile" + CONTROL_PLUGIN_PATH="/home/fulup/Workspace/AGL-AppFW/audio-bindings-dev/build:/home/fulup/opt/controller-plugins:/usr/lib/afb/controller-plugins/ctlplug" + CONTROL_SUPPORT_LUA + CTL_PLUGIN_MAGIC=2468013579 + MAX_LINEAR_DB_SCALE=24 + MAX_SND_CARD=16 + NATIVE_LINUX + TLV_BYTE_SIZE=256 + control_afb_EXPORTS + + + + + + + ../../../opt/include/afb + Controller-afb + /usr/include/json-c + build/Controller-afb + + + + + + + ../../../opt/include + ../../../opt/include/alsa + /usr/include/p11-kit-1 + /usr/include/json-c + /usr/include/lua5.3 + Audio-Common + build/Controller-afb + + + CONTROL_CONFIG_PATH="/home/fulup/Workspace/AGL-AppFW/audio-bindings-dev/conf.d/project/config.d:/home/fulup/opt/controller/config.d" + CONTROL_CONFIG_POST="control" + CONTROL_CONFIG_PRE="onload" + CONTROL_DOSCRIPT_PRE="doscript" + CONTROL_LUA_EVENT="luaevt" + CONTROL_LUA_PATH="/home/fulup/Workspace/AGL-AppFW/audio-bindings-dev/conf.d/project/lua.d:/home/fulup/opt/controller-plugins/ctl-lua.d" + CONTROL_MAXPATH_LEN=255 + CONTROL_ONLOAD_PROFILE="onload-default-profile" + CONTROL_PLUGIN_PATH="/home/fulup/Workspace/AGL-AppFW/audio-bindings-dev/build:/home/fulup/opt/controller-plugins:/usr/lib/afb/controller-plugins/ctlplug" + CONTROL_SUPPORT_LUA + CTL_PLUGIN_MAGIC=2468013579 + MAX_LINEAR_DB_SCALE=24 + MAX_SND_CARD=16 + NATIVE_LINUX + TLV_BYTE_SIZE=256 + audio_plugin_sample_EXPORTS + + + + + + + ../../../opt/include + ../../../opt/include/alsa + /usr/include/p11-kit-1 + /usr/include/json-c + /usr/include/lua5.3 + Audio-Common + build/Controller-afb + + + CONTROL_CONFIG_PATH="/home/fulup/Workspace/AGL-AppFW/audio-bindings-dev/conf.d/project/config.d:/home/fulup/opt/controller/config.d" + CONTROL_CONFIG_POST="control" + CONTROL_CONFIG_PRE="onload" + CONTROL_DOSCRIPT_PRE="doscript" + CONTROL_LUA_EVENT="luaevt" + CONTROL_LUA_PATH="/home/fulup/Workspace/AGL-AppFW/audio-bindings-dev/conf.d/project/lua.d:/home/fulup/opt/controller-plugins/ctl-lua.d" + CONTROL_MAXPATH_LEN=255 + CONTROL_ONLOAD_PROFILE="onload-default-profile" + CONTROL_PLUGIN_PATH="/home/fulup/Workspace/AGL-AppFW/audio-bindings-dev/build:/home/fulup/opt/controller-plugins:/usr/lib/afb/controller-plugins/ctlplug" + CONTROL_SUPPORT_LUA + CTL_PLUGIN_MAGIC=2468013579 + MAX_LINEAR_DB_SCALE=24 + MAX_SND_CARD=16 + NATIVE_LINUX + TLV_BYTE_SIZE=256 + control_afb_EXPORTS + + + + + + + Audio-Common + build/HAL-afb/HAL-interface + + + + + + + Audio-Common + build/HAL-afb/HAL-interface + + + + + + + build/HAL-afb/HAL-interface + + + + + + + + + + + + + + + + + + + + + + + Shared-Interface + HAL-afb/HAL-interface + build/HAL-afb/Unicens-USB + + + + + + + HAL-afb/HAL-interface + build/HAL-afb/Unicens-USB + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Alsa-Plugin/Alsa-Policy-Hook + ../../../opt/include/alsa + /usr/include/json-c + ../../../opt/include/afb + ../../../opt/include + build/Alsa-Plugin/Alsa-Policy-Hook + + + CONTROL_CONFIG_PATH="/home/fulup/Workspace/AGL-AppFW/audio-bindings-dev/conf.d/project/config.d:/usr/local/controller/config.d" + CONTROL_CONFIG_POST="control" + CONTROL_CONFIG_PRE="onload" + CONTROL_DOSCRIPT_PRE="doscript" + CONTROL_LUA_EVENT="luaevt" + CONTROL_LUA_PATH="/home/fulup/Workspace/AGL-AppFW/audio-bindings-dev/conf.d/project/lua.d:/usr/local/controller/ctl-lua.d" + CONTROL_MAXPATH_LEN=255 + CONTROL_ONLOAD_DEFAULT="onload-default" + CONTROL_PLUGIN_PATH="/home/fulup/Workspace/AGL-AppFW/audio-bindings-dev/build:/home/fulup/opt/audio-bindings/ctlplug:/usr/lib/afb/ctlplug" + CONTROL_SUPPORT_LUA + CTL_PLUGIN_MAGIC=2468013579 + MAX_LINEAR_DB_SCALE=24 + MAX_SND_CARD=16 + NATIVE_LINUX + PIC + TLV_BYTE_SIZE=256 + policy_hook_cb_EXPORTS + + + + + + + ../../../opt/include + ../../../opt/include/alsa + /usr/include/p11-kit-1 + /usr/include/json-c + /usr/include/lua5.3 + Audio-Common + build/Controller-afb + build/HAL-afb/HAL-plugin + /usr/include/alsa + build/Common + + + CONTROL_CDEV_RX="/dev/inic-usb-crx" + CONTROL_CDEV_TX="/dev/inic-usb-ctx" + CONTROL_CONFIG_PATH="/home/fulup/Workspace/AGL-AppFW/audio-bindings-dev/conf.d/project/config.d:/usr/local/controller/config.d" + CONTROL_CONFIG_POST="control" + CONTROL_CONFIG_PRE="onload" + CONTROL_LUA_EVENT="luaevt" + CONTROL_LUA_PATH="/home/fulup/Workspace/AGL-AppFW/audio-bindings-dev/conf.d/project/lua.d:/usr/local/controller/ctl-lua.d" + CONTROL_MAXPATH_LEN=255 + CONTROL_ONLOAD_DEFAULT="onload-default" + CONTROL_PLUGIN_PATH="/home/fulup/Workspace/AGL-AppFW/audio-bindings-dev/build:/home/fulup/opt/audio-bindings/ctlplug:/usr/lib/afb/ctlplug" + CTL_PLUGIN_MAGIC=2468013579 + MAX_LINEAR_DB_SCALE=24 + MAX_SND_CARD=16 + TLV_BYTE_SIZE=256 + audio_plugin_sample_EXPORTS + control_afb_EXPORTS + + + + + + + ../../../opt/include + ../../../opt/include/alsa + /usr/include/p11-kit-1 + /usr/include/json-c + /usr/include/lua5.3 + + + CONTROL_CONFIG_PATH="/home/fulup/Workspace/AGL-AppFW/audio-bindings-dev/conf.d/project/config.d:/usr/local/controller/config.d" + CONTROL_CONFIG_POST="control" + CONTROL_CONFIG_PRE="onload" + CONTROL_LUA_EVENT="luaevt" + CONTROL_LUA_PATH="/home/fulup/Workspace/AGL-AppFW/audio-bindings-dev/conf.d/project/lua.d:/usr/local/controller/ctl-lua.d" + CONTROL_MAXPATH_LEN=255 + CONTROL_ONLOAD_DEFAULT="onload-default" + CONTROL_PLUGIN_PATH="/home/fulup/Workspace/AGL-AppFW/audio-bindings-dev/build:/home/fulup/opt/audio-bindings/ctlplug:/usr/lib/afb/ctlplug" + CTL_PLUGIN_MAGIC=2468013579 + MAX_LINEAR_DB_SCALE=24 + MAX_SND_CARD=16 + TLV_BYTE_SIZE=256 + + + + + + + ../../../opt/include/afb + HAL-afb/HAL-interface + + + + + + + Audio-Common + build/Controller-afb + build/HAL-afb/HAL-plugin + ../../../opt/include/afb + HAL-afb/HAL-plugin + + + CONTROL_CDEV_RX="/dev/inic-usb-crx" + CONTROL_CDEV_TX="/dev/inic-usb-ctx" + audio_plugin_sample_EXPORTS + control_afb_EXPORTS + + + + + + + ../../../opt/include/afb + HAL-afb/HDA-intel + Audio-Common + HAL-afb/HAL-interface + build/HAL-afb/HDA-intel + + + + + + + HAL-afb/Jabra-Solemate + ../../../opt/include/afb + Audio-Common + HAL-afb/HAL-interface + build/HAL-afb/Jabra-Solemate + + + + + + + ../../../opt/include/afb + HAL-afb/Scarlett-Focusrite + Audio-Common + HAL-afb/HAL-interface + build/HAL-afb/Scarlett-Focusrite + + + + + + + Audio-Common + build/Controller-afb + build/HAL-afb/HAL-plugin + ../../../opt/include/afb + HAL-afb/Unicens-USB + + + CONTROL_CDEV_RX="/dev/inic-usb-crx" + CONTROL_CDEV_TX="/dev/inic-usb-ctx" + audio_plugin_sample_EXPORTS + control_afb_EXPORTS + + + + + + + ../../../opt/include + ../../../opt/include/alsa + /usr/include/p11-kit-1 + /usr/include/json-c + /usr/include/lua5.3 + Audio-Common + build/Controller-afb + build/HAL-afb/HAL-plugin + ../../../opt/include/afb + HighLevel-afb + Shared-Interface + build/HighLevel-afb + + + CONTROL_CONFIG_PATH="/home/fulup/Workspace/AGL-AppFW/audio-bindings-dev/conf.d/project/config.d:/usr/local/controller/config.d" + CONTROL_CONFIG_POST="control" + CONTROL_CONFIG_PRE="onload" + CONTROL_LUA_EVENT="luaevt" + CONTROL_LUA_PATH="/home/fulup/Workspace/AGL-AppFW/audio-bindings-dev/conf.d/project/lua.d:/usr/local/controller/ctl-lua.d" + CONTROL_MAXPATH_LEN=255 + CONTROL_ONLOAD_DEFAULT="onload-default" + CONTROL_PLUGIN_PATH="/home/fulup/Workspace/AGL-AppFW/audio-bindings-dev/build:/home/fulup/opt/audio-bindings/ctlplug:/usr/lib/afb/ctlplug" + CTL_PLUGIN_MAGIC=2468013579 + MAX_LINEAR_DB_SCALE=24 + MAX_SND_CARD=16 + TLV_BYTE_SIZE=256 + audio_plugin_sample_EXPORTS + control_afb_EXPORTS + + + + + + + ../../../opt/include + ../../../opt/include/alsa + /usr/include/p11-kit-1 + /usr/include/json-c + /usr/include/lua5.3 + Audio-Common + build/Controller-afb + build/HAL-afb/HAL-plugin + + + CONTROL_CONFIG_PATH="/home/fulup/Workspace/AGL-AppFW/audio-bindings-dev/conf.d/project/config.d:/usr/local/controller/config.d" + CONTROL_CONFIG_POST="control" + CONTROL_CONFIG_PRE="onload" + CONTROL_LUA_EVENT="luaevt" + CONTROL_LUA_PATH="/home/fulup/Workspace/AGL-AppFW/audio-bindings-dev/conf.d/project/lua.d:/usr/local/controller/ctl-lua.d" + CONTROL_MAXPATH_LEN=255 + CONTROL_ONLOAD_DEFAULT="onload-default" + CONTROL_PLUGIN_PATH="/home/fulup/Workspace/AGL-AppFW/audio-bindings-dev/build:/home/fulup/opt/audio-bindings/ctlplug:/usr/lib/afb/ctlplug" + CTL_PLUGIN_MAGIC=2468013579 + MAX_LINEAR_DB_SCALE=24 + MAX_SND_CARD=16 + TLV_BYTE_SIZE=256 + audio_plugin_sample_EXPORTS + control_afb_EXPORTS + + + + diff --git a/nbproject/project.xml b/nbproject/project.xml index db3bdab..b229af2 100644 --- a/nbproject/project.xml +++ b/nbproject/project.xml @@ -33,6 +33,10 @@ Local_Raw_Controller 0 + + Demo-AudioController + 0 + false -- cgit 1.2.3-korg