summaryrefslogtreecommitdiff
path: root/misc/freeswitch/scripts/dialplan
diff options
context:
space:
mode:
authorPeter Kozak <spag@golwen.net>2013-03-24 19:54:49 +0100
committerPeter Kozak <spag@golwen.net>2013-03-24 19:54:49 +0100
commit9415eec4b7cc19d97fb9e7c30c3e0891f2cc5523 (patch)
tree70a81c3af07d4c014053c42eee734636aa8cde10 /misc/freeswitch/scripts/dialplan
parentfc406e45e4a5ce26e0117ff94e632522fcfa066b (diff)
session callback class added
Diffstat (limited to 'misc/freeswitch/scripts/dialplan')
-rw-r--r--misc/freeswitch/scripts/dialplan/callback.lua85
1 files changed, 85 insertions, 0 deletions
diff --git a/misc/freeswitch/scripts/dialplan/callback.lua b/misc/freeswitch/scripts/dialplan/callback.lua
new file mode 100644
index 0000000..f6fd48e
--- /dev/null
+++ b/misc/freeswitch/scripts/dialplan/callback.lua
@@ -0,0 +1,85 @@
+-- Gemeinschaft 5 module: callback class
+-- (c) AMOOMA GmbH 2013
+--
+
+module(...,package.seeall)
+
+Callback = {}
+
+-- create callback callback ;)
+function Callback.new(self, arg)
+ arg = arg or {}
+ callback = arg.callback or {}
+ setmetatable(callback, self);
+ self.__index = self;
+ self.class = 'callback';
+ self.log = arg.log;
+ self.session = arg.session;
+ self.sessions = {};
+ local id = common.str.to_i(self.session);
+ self.sessions[id] = { id = id, session = self.session, dtmf = {} };
+ return callback;
+end
+
+
+function Callback.callback(self, class, identifier, callback_function, callback_instance, callback_session)
+ local id = common.str.to_i(callback_session or self.session);
+ local session_record = self.sessions[id];
+
+ if not session_record and callback_session then
+ self.sessions[id] = { id = id, session = callback_session, dtmf = {} };
+ session_record = self.sessions[id];
+ end
+
+ if not session_record then
+ return false;
+ end
+
+
+ _G['global_callback_record_' .. id] = session_record;
+
+ session_record.session:setInputCallback('global_callback_handler', 'global_callback_record_' .. id);
+ session_record[class][identifier] = { method = callback_function, instance = callback_instance };
+
+ return true;
+end
+
+
+function Callback.callback_unset(self, class, identifier, callback_session)
+ local session_record = self.sessions[tostring(callback_session or self.session)];
+ if not session_record then
+ return false;
+ end
+
+ -- session_record.session:unsetInputCallback();
+ session_record[class][identifier] = nil;
+
+ return true;
+end
+
+
+function Callback.run(self, arg)
+ local identifier = arg[2];
+ local data = arg[3];
+ local session_record = arg[4];
+ local callbacks = session_record[identifier];
+
+ local return_value = nil;
+ if callbacks then
+ for identifier, callback in pairs(callbacks) do
+ if callback.method then
+ local result = nil;
+ if callback.instance then
+ result = callback.method(callback.instance, data);
+ else
+ result = callback.method(data.digit, data);
+ end
+ if result == false then
+ return_value = 'break';
+ end
+ end
+ end
+ end
+
+ return return_value;
+end