summaryrefslogtreecommitdiff
path: root/misc/freeswitch/scripts/dialplan/call_parking.lua
diff options
context:
space:
mode:
authorStefan Wintermeyer <stefan.wintermeyer@amooma.de>2013-02-16 11:10:02 +0100
committerStefan Wintermeyer <stefan.wintermeyer@amooma.de>2013-02-16 11:10:02 +0100
commit5d8ce5f4775ac8bc5f523964e6e36f63ff3c4683 (patch)
tree49ed889b1d10cda98c475f3453abff1b97afb4e7 /misc/freeswitch/scripts/dialplan/call_parking.lua
parentc9066760fd1f5f2f892ce2be5cf2a83bb5210246 (diff)
parent55784bcffc0678ce6102c0b81447434a8030ebd2 (diff)
Merge branch 'develop'5.1-beta5
Diffstat (limited to 'misc/freeswitch/scripts/dialplan/call_parking.lua')
-rw-r--r--misc/freeswitch/scripts/dialplan/call_parking.lua83
1 files changed, 83 insertions, 0 deletions
diff --git a/misc/freeswitch/scripts/dialplan/call_parking.lua b/misc/freeswitch/scripts/dialplan/call_parking.lua
new file mode 100644
index 0000000..cc2cf4b
--- /dev/null
+++ b/misc/freeswitch/scripts/dialplan/call_parking.lua
@@ -0,0 +1,83 @@
+-- Gemeinschaft 5 module: call parking class
+-- (c) AMOOMA GmbH 2013
+--
+
+module(...,package.seeall)
+
+PARKING_STALL_FORMAT = '[0-9A-Z_%+%-]+';
+UUID_FORMAT = '[0-9a-f%-]+';
+
+CallParking = {}
+
+-- create acd object
+function CallParking.new(self, arg)
+ arg = arg or {}
+ object = arg.object or {}
+ setmetatable(object, self);
+ self.__index = self;
+ self.class = 'parkingstall';
+ self.log = arg.log;
+ self.database = arg.database;
+ self.lot = arg.lot or 'default';
+ self.caller = arg.caller;
+ return object;
+end
+
+
+function CallParking.find_by_name(self, name)
+ local sql_query = 'SELECT * FROM `parking_stalls` WHERE `name`= '.. self.database:escape(name, '"') .. ' LIMIT 1';
+ local parking_stall = nil;
+
+ self.database:query(sql_query, function(entry)
+ parking_stall = CallParking:new(self);
+ parking_stall.record = entry;
+ parking_stall.id = tonumber(entry.id);
+ parking_stall.name = entry.name;
+ end)
+
+ return parking_stall;
+end
+
+
+function CallParking.list_occupied(self, lot)
+ lot = lot or self.lot;
+
+ require 'common.fapi'
+ local valet_info = common.fapi.FApi:new{ log = self.log }:execute('valet_info', lot);
+
+ local parking_stalls = {};
+ tostring(valet_info):gsub('<extension uuid="(' .. UUID_FORMAT .. ')">(' .. PARKING_STALL_FORMAT .. ')</extension>', function(channel_uuid, parking_stall)
+ parking_stalls[parking_stall] = channel_uuid;
+ end);
+
+ return parking_stalls;
+end
+
+
+function CallParking.occupied(self)
+ local occupied_stalls = self:list_occupied();
+ if occupied_stalls then
+ return occupied_stalls[self.name];
+ end
+end
+
+
+function CallParking.park_retrieve(self)
+ self.caller:execute("valet_park", self.lot .. ' ' .. self.name);
+end
+
+
+function CallParking.park(self)
+ if self:occupied() then
+ return false;
+ end
+ self.caller:execute("valet_park", self.lot .. ' ' .. self.name);
+end
+
+
+function CallParking.retrieve(self)
+ if not self:occupied() then
+ return false;
+ end
+ self.caller:execute("valet_park", self.lot .. ' ' .. self.name);
+end