summaryrefslogtreecommitdiffstats
path: root/conf.d/project/lua.d
diff options
context:
space:
mode:
authorFulup Ar Foll <fulup@iot.bzh>2017-09-29 12:23:26 +0200
committerFulup Ar Foll <fulup@iot.bzh>2017-09-29 12:23:26 +0200
commitacde5b8a880ff6f5e19ee91bd1f213339947b62f (patch)
tree333ebb3e87531da12fe447309e77a6fa57ba4165 /conf.d/project/lua.d
parentacfdebd511ebcde861c7975af0a92c0d6bc87678 (diff)
Initial Commit as submodule
Diffstat (limited to 'conf.d/project/lua.d')
-rw-r--r--conf.d/project/lua.d/CMakeLists.txt32
-rw-r--r--conf.d/project/lua.d/doscript-helloworld.lua36
-rw-r--r--conf.d/project/lua.d/onload-daemon-00-utils.lua86
-rw-r--r--conf.d/project/lua.d/onload-daemon-01-init.lua48
-rw-r--r--conf.d/project/lua.d/onload-daemon-03-controls.lua47
-rw-r--r--conf.d/project/lua.d/onload-daemon-04-oncall.lua70
-rw-r--r--conf.d/project/lua.d/onload-daemon-10-event.lua74
7 files changed, 0 insertions, 393 deletions
diff --git a/conf.d/project/lua.d/CMakeLists.txt b/conf.d/project/lua.d/CMakeLists.txt
deleted file mode 100644
index 5cd61f2..0000000
--- a/conf.d/project/lua.d/CMakeLists.txt
+++ /dev/null
@@ -1,32 +0,0 @@
-###########################################################################
-# Copyright 2017 IoT.bzh
-#
-# author: Fulup Ar Foll <fulup@iot.bzh>
-#
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-###########################################################################
-
-
-##################################################
-# Control Policy Config file
-##################################################
-PROJECT_TARGET_ADD(ctl-lua.d)
-
- file(GLOB LUA_FILES "*.lua")
-
- add_input_files("${LUA_FILES}")
-
- SET_TARGET_PROPERTIES(${TARGET_NAME} PROPERTIES
- LABELS "DATA"
- OUTPUT_NAME ${TARGET_NAME}
- )
diff --git a/conf.d/project/lua.d/doscript-helloworld.lua b/conf.d/project/lua.d/doscript-helloworld.lua
deleted file mode 100644
index e722db7..0000000
--- a/conf.d/project/lua.d/doscript-helloworld.lua
+++ /dev/null
@@ -1,36 +0,0 @@
---[[
- Copyright (C) 2016 "IoT.bzh"
- Author Fulup Ar Foll <fulup@iot.bzh>
-
- Licensed under the Apache License, Version 2.0 (the "License");
- you may not use this file except in compliance with the License.
- You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
- Unless required by applicable law or agreed to in writing, software
- distributed under the License is distributed on an "AS IS" BASIS,
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- See the License for the specific language governing permissions and
- limitations under the License.
-
-
- Simple API script to be use with AGL control LuaDoCall API
- - After the script is loaded by lua_docall
- - Controller start function=xxxx where xxxx is taken from script filename doscript-xxxx-anything
-
---]]
-
-function _helloworld (request, query)
-
- AFB:notice ("LUA HelloWorld: Simple test query=%s", query);
-
- if (query == nil) then
- AFB:notice ("LUA HelloWorld:FX query should not be empty");
- AFB:fail (request, "LUA HelloWorld: query should not be empty");
- else
- AFB:notice ("LUA HelloWorld:OK query=%s", query);
- AFB:success (request, {arg0="Demat", arg1="Bonjours", arg2="Gootentag", arg3="Morning"});
- end
-
-end
diff --git a/conf.d/project/lua.d/onload-daemon-00-utils.lua b/conf.d/project/lua.d/onload-daemon-00-utils.lua
deleted file mode 100644
index 29d2c70..0000000
--- a/conf.d/project/lua.d/onload-daemon-00-utils.lua
+++ /dev/null
@@ -1,86 +0,0 @@
---[[
- Copyright (C) 2016 "IoT.bzh"
- Author Fulup Ar Foll <fulup@iot.bzh>
-
- Licensed under the Apache License, Version 2.0 (the "License");
- you may not use this file except in compliance with the License.
- You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
- Unless required by applicable law or agreed to in writing, software
- distributed under the License is distributed on an "AS IS" BASIS,
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- See the License for the specific language governing permissions and
- limitations under the License.
-
- Note: this file should be called before any other to assert declare function
- is loaded before anything else.
-
- References:
- http://lua-users.org/wiki/DetectingUndefinedVariables
-
---]]
-
-
---===================================================
---= Niklas Frykholm
--- basically if user tries to create global variable
--- the system will not let them!!
--- call GLOBAL_lock(_G)
---
---===================================================
-function GLOBAL_lock(t)
- local mt = getmetatable(t) or {}
- mt.__newindex = lock_new_index
- setmetatable(t, mt)
-end
-
---===================================================
--- call GLOBAL_unlock(_G)
--- to change things back to normal.
---===================================================
-function GLOBAL_unlock(t)
- local mt = getmetatable(t) or {}
- mt.__newindex = unlock_new_index
- setmetatable(t, mt)
-end
-
-function lock_new_index(t, k, v)
- if (string.sub(k,1,1) ~= "_") then
- GLOBAL_unlock(_G)
- error("GLOBALS are locked -- " .. k ..
- " must be declared local or prefix with '_' for globals.", 2)
- else
- rawset(t, k, v)
- end
-end
-
-function unlock_new_index(t, k, v)
- rawset(t, k, v)
-end
-
--- return serialised version of printable table
-function Dump_Table(o)
- if type(o) == 'table' then
- local s = '{ '
- for k,v in pairs(o) do
- if type(k) ~= 'number' then k = '"'..k..'"' end
- s = s .. '['..k..'] = ' .. Dump_Table(v) .. ','
- end
- return s .. '} '
- else
- return tostring(o)
- end
-end
-
-
--- simulate C prinf function
-printf = function(s,...)
- io.write(s:format(...))
- io.write("\n")
- return
-end
-
--- lock global variable
-GLOBAL_lock(_G)
diff --git a/conf.d/project/lua.d/onload-daemon-01-init.lua b/conf.d/project/lua.d/onload-daemon-01-init.lua
deleted file mode 100644
index 26ff08a..0000000
--- a/conf.d/project/lua.d/onload-daemon-01-init.lua
+++ /dev/null
@@ -1,48 +0,0 @@
---[[
- Copyright (C) 2016 "IoT.bzh"
- Author Fulup Ar Foll <fulup@iot.bzh>
-
- Licensed under the Apache License, Version 2.0 (the "License");
- you may not use this file except in compliance with the License.
- You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
- Unless required by applicable law or agreed to in writing, software
- distributed under the License is distributed on an "AS IS" BASIS,
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- See the License for the specific language governing permissions and
- limitations under the License.
---]]
-
--- Global variable SHOULD start with _
-_Global_Context={}
-
---[[
- This function is call during controller init phase as describe in onload-daemon-sample.json
- It receives two argument 1st one is the source (here on load) second one is the arguments
- as expose in config file.
-
- In this sample we create an event that take the name of args["zzzz"], the resulting handle
- is save into _Global_Context for further use.
-
- Note: init functions are not call from a client and thus do not receive query
-
---]]
-function _Sample_Controller_Init(source, control)
-
- printf ("[-- Sample_Controller_Init --] source=%d control=%s", source, Dump_Table(control))
-
- -- if no argument return now
- if (control==nil or control["zzzz"]==nil) then
- printf ("[-- Sample_Controller_Init --] no event name given")
- return
- end
-
- -- set a count to make more visible each call
- _Global_Context["counter"]=0
-
- -- just for fun create an event
- _Global_Context["event"]=AFB:evtmake(control["zzzz"])
-
-end
diff --git a/conf.d/project/lua.d/onload-daemon-03-controls.lua b/conf.d/project/lua.d/onload-daemon-03-controls.lua
deleted file mode 100644
index e9c8b51..0000000
--- a/conf.d/project/lua.d/onload-daemon-03-controls.lua
+++ /dev/null
@@ -1,47 +0,0 @@
---[[
- Copyright (C) 2016 "IoT.bzh"
- Author Fulup Ar Foll <fulup@iot.bzh>
-
- Licensed under the Apache License, Version 2.0 (the "License");
- you may not use this file except in compliance with the License.
- You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
- Unless required by applicable law or agreed to in writing, software
- distributed under the License is distributed on an "AS IS" BASIS,
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- See the License for the specific language governing permissions and
- limitations under the License.
-
- Following function are called when a client activate a control with
- controller api -> APi=control VERB=dispatch
- arguments are
- - source (0) when requesting the control (-1) when releasing
- - control comme from config given with 'args' in onload-middlename-xxxxx.json
- - client is the argument part of the query as providing by client requesting the control.
-
---]]
-
-
-
--- Simple Happy(granted) Control
-function _Button_Happy(source, control, client)
-
- -- print argument to make sure we understant what we get
- printf ("[-- _Button_Happy --] source=%d control=%s client=%s", source, Dump_Table(client), Dump_Table(control))
-
- AFB:notice ("[-- _Button_Happy --] To Be Done")
- return 0 -- control granted
-end
-
-
--- Simple UnHappy(debu) Control
-function _Button_UnHappy(source, control, client)
-
- -- print argument to make sure we understant what we get
- printf ("[-- _Button_UnHappy --] source=%d control=%s client=%s", source, Dump_Table(client), Dump_Table(control))
-
- AFB:error ("[-- _Button_UnHappy --] To Be Done")
- return 1 -- control is refused
-end
diff --git a/conf.d/project/lua.d/onload-daemon-04-oncall.lua b/conf.d/project/lua.d/onload-daemon-04-oncall.lua
deleted file mode 100644
index b450932..0000000
--- a/conf.d/project/lua.d/onload-daemon-04-oncall.lua
+++ /dev/null
@@ -1,70 +0,0 @@
---[[
- Copyright (C) 2016 "IoT.bzh"
- Author Fulup Ar Foll <fulup@iot.bzh>
-
- Licensed under the Apache License, Version 2.0 (the "License");
- you may not use this file except in compliance with the License.
- You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
- Unless required by applicable law or agreed to in writing, software
- distributed under the License is distributed on an "AS IS" BASIS,
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- See the License for the specific language governing permissions and
- limitations under the License.
-
-
- Provide sample LUA routines to be used with AGL control "lua_docall" API
---]]
-
---global counter to keep track of calls
-_count=0
-
--- Display receive arguments and echo them to caller
-function _Simple_Echo_Args (request, args)
- _count=_count+1
- AFB:notice("LUA OnCall Echo Args count=%d args=%s", count, args)
-
- print ("--inlua-- args=", Dump_Table(args))
-
- local response={
- ["count"]=_count,
- ["args"]=args,
- }
-
- -- fulup Embdeded table ToeDone AFB:success (request, response)
- AFB:success (request, {["func"]="Simple_Echo_Args", ["ret1"]=5678, ["ret2"]="abcd"})
-end
-
-local function Test_Async_CB (request, result, context)
- response={
- ["result"]=result,
- ["context"]=context,
- }
-
- AFB:notice ("Test_Async_CB result=%s context=%s", result, context)
- AFB:success (request, response)
-end
-
-function _Test_Call_Async (request, args)
- local context={
- ["value1"]="abcd",
- ["value2"]=1234
- }
-
- AFB:notice ("Test_Call_Async args=%s cb=Test_Async_CB", args)
- AFB:service("monitor","ping", "Test_Async_CB", context)
-end
-
-function _Simple_Monitor_Call (request, args)
-
- AFB:notice ("_Simple_Server_Call args=%s", args)
- local err, result= AFB:servsync ("monitor","get", args)
- if (err) then
- AFB:fail ("AFB:service_call_sync fail");
- else
- AFB:success (request, result["response"])
- end
-end
-
diff --git a/conf.d/project/lua.d/onload-daemon-10-event.lua b/conf.d/project/lua.d/onload-daemon-10-event.lua
deleted file mode 100644
index 474ebe0..0000000
--- a/conf.d/project/lua.d/onload-daemon-10-event.lua
+++ /dev/null
@@ -1,74 +0,0 @@
---[[
- Copyright (C) 2016 "IoT.bzh"
- Author Fulup Ar Foll <fulup@iot.bzh>
-
- Licensed under the Apache License, Version 2.0 (the "License");
- you may not use this file except in compliance with the License.
- You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
- Unless required by applicable law or agreed to in writing, software
- distributed under the License is distributed on an "AS IS" BASIS,
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- See the License for the specific language governing permissions and
- limitations under the License.
-
-
- Provide Sample Timer Handing to push event from LUA
---]]
-
--- Create event on Lua script load
-_MyContext={}
-
--- WARNING: call back are global and should start with '_'
-function _Timer_Test_CB (timer, context)
-
- local evtinfo= AFB:timerget(timer)
- printf ("[-- _Timer_Test_C --] evtInfo=%s", Dump_Table(evtinfo))
-
- --send an event an event with count as value
- AFB:evtpush (_MyContext["event"], {["label"]= evtinfo["label"], ["count"]=evtinfo["count"], ["info"]=context["info"]})
-
- -- note when timerCB return!=0 timer is kill
- return 0
-
-end
-
--- sendback event depending on count and delay
-function _Simple_Timer_Test (request, client)
-
- local context = {
- ["info"]="My 1st private Event",
- }
-
- -- if event does not exit create it now.
- if (_MyContext["event"] == nil) then
- _MyContext["event"]= AFB:evtmake(client["label"])
- end
-
- -- if delay not defined default is 5s
- if (client["delay"]==nil) then client["delay"]=5000 end
-
- -- if count is not defined default is 10
- if (client["count"]==nil) then client["count"]=10 end
-
- -- we could use directly client but it is a sample
- local myTimer = {
- ["label"]=client["label"],
- ["delay"]=client["delay"],
- ["count"]=client["count"],
- }
- AFB:notice ("Test_Timer myTimer=%s", myTimer)
-
- -- subscribe to event
- AFB:subscribe (request, _MyContext["event"])
-
- -- settimer take a table with delay+count as input (count==0 means infinite)
- AFB:timerset (myTimer, "_Timer_Test_CB", context)
-
- -- nothing special to return send back
- AFB:success (request, myTimer)
-
- return 0
-end