diff options
author | James Bottomley <JBottomley@Parallels.com> | 2013-05-10 13:45:54 -0700 |
---|---|---|
committer | James Bottomley <JBottomley@Parallels.com> | 2013-05-10 13:45:54 -0700 |
commit | e3fdb2eb7f00060886da399d2938a7cb07407c14 (patch) | |
tree | c33d16ac522664616ae514a4c128e86a2bb9c5d7 | |
parent | 0d554d683251425e2bcf4013c77d72d8e5e49677 (diff) | |
download | asterisk-aastra-e3fdb2eb7f00060886da399d2938a7cb07407c14.tar.gz |
AastraAsterisk: update AMI functions
Split the send_request function so we can send a request without waiting, add
Hangup and PlayDTMF events, allow specification of the event mask, really set
the timeout on the listen streams, add a timed wait_event() function which
waits for either an event or the timeout.
Signed-off-by: James Bottomley <JBottomley@Parallels.com>
-rw-r--r-- | include/AastraAsterisk.class.php | 48 |
1 files changed, 44 insertions, 4 deletions
diff --git a/include/AastraAsterisk.class.php b/include/AastraAsterisk.class.php index 6e59a4e..ddb4866 100644 --- a/include/AastraAsterisk.class.php +++ b/include/AastraAsterisk.class.php @@ -69,19 +69,29 @@ class AGI_AsteriskManager $handler = ''; if(isset($this->event_handlers[$e])) $handler = $this->event_handlers[$e]; elseif(isset($this->event_handlers['*'])) $handler = $this->event_handlers['*']; - if(function_exists($handler)) $ret = $handler($e, $parameters, $this->server, $this->port); + if(is_callable($handler)) $ret = call_user_func($handler, $e, $parameters, $this->server, $this->port); return $ret; } - function send_request($action, $parameters=array()) + function send_request_nowait($action, $parameters=array()) { $req="Action: $action\r\n"; foreach($parameters as $var=>$val) $req.="$var: $val\r\n"; $req.="\r\n"; fwrite($this->socket, $req); - return $this->wait_response(); } + function send_request($action, $parameters=array()) + { + $this->send_request_nowait($action, $parameters); + return $this->wait_response(); + } + + function events($mask='off') + { + return $this->send_request('Events', array('EventMask' => $mask)); + } + function get_socket() { if($this->socket) return(True); @@ -154,7 +164,7 @@ class AGI_AsteriskManager return $parameters; } - function listen($timeout='60') + function wait_event($timeout='60') { $exit=False; $time1=time(); @@ -162,6 +172,7 @@ class AGI_AsteriskManager { $type=''; $parameters=array(); + stream_set_timeout($this->socket, $timeout); $temp=fgets($this->socket, 4096); if($temp===False) { @@ -206,6 +217,7 @@ class AGI_AsteriskManager { case 'event': $this->process_event($parameters); + $exit=True; break; default: if($type!='') $this->log('Unhandled response packet from Manager: '.$type); @@ -219,6 +231,14 @@ class AGI_AsteriskManager return $parameters; } + function listen($timeout=60) + { + $time1=time(); + do { + $this->wait_event($timeout); + } while (time() < $time1+$timeout); + } + function connect($server=NULL,$username=NULL,$secret=NULL,$display=True) { @@ -323,6 +343,19 @@ class AGI_AsteriskManager return $retval; } + function hangup($channel) { + $parameters=array('Channel'=>$channel); + return $this->send_request('Hangup', $parameters); + } + + function playDTMF($channel, $digit) { + $parameters=array('Channel'=>$channel,'Digit'=>$digit); + $this->log_array('PLAY DTMF', $parameters); + $err = $this->send_request('PlayDTMF', $parameters); + $this->log_array('PLAY DTMF RETURNS', $err); + return $err; + } + function get_user() { $ret = $this->Command('sip show peers'); $ret = split("\n", $ret['data']); @@ -391,6 +424,13 @@ class AGI_AsteriskManager # Aastra_debug($message); } + function log_array($msg, $a) { + foreach ($a as $k=>$v) { + $msg.= ' '.$k.'=>'.$v; + } + error_log($msg); + } + function database_show($family='') { $r=$this->command('database show '.$family); |