summaryrefslogtreecommitdiff
path: root/misc/freeswitch/scripts/dialplan/callback.lua
diff options
context:
space:
mode:
authorStefan Wintermeyer <stefan.wintermeyer@amooma.de>2013-03-25 10:27:27 +0100
committerStefan Wintermeyer <stefan.wintermeyer@amooma.de>2013-03-25 10:27:27 +0100
commitdf6e17e48995f25e72509986f30700d778b179b6 (patch)
treef432c24b8e4ad81009188650dabfd99194883265 /misc/freeswitch/scripts/dialplan/callback.lua
parent11f186a118285fbc87a536af26730780a9ad01f5 (diff)
parentcce94a74aa5c9691f9b37cd9be5a6831f8063812 (diff)
Merge branch 'develop'5.1.2
Diffstat (limited to 'misc/freeswitch/scripts/dialplan/callback.lua')
-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