aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/callnotifier/CLI.php3
-rw-r--r--src/callnotifier/CallMonitor.php56
-rw-r--r--src/callnotifier/CallMonitor/Call.php34
-rw-r--r--src/callnotifier/EDSS1/Parameter.php8
-rw-r--r--src/callnotifier/Log.php2
-rw-r--r--src/callnotifier/Logger/CallEcho.php33
6 files changed, 132 insertions, 4 deletions
diff --git a/src/callnotifier/CLI.php b/src/callnotifier/CLI.php
index 5fdde92..6ec9a7e 100644
--- a/src/callnotifier/CLI.php
+++ b/src/callnotifier/CLI.php
@@ -31,6 +31,9 @@ class CLI
$debugLogger->edss1MsgOnly = true;
}
}
+ $log->addLogger(
+ new Logger_CallEcho(), array('incomingCall', 'finishedCall')
+ );
$callMonitor = new CallMonitor($this->config, $log);
diff --git a/src/callnotifier/CallMonitor.php b/src/callnotifier/CallMonitor.php
index a910e9f..9abdba8 100644
--- a/src/callnotifier/CallMonitor.php
+++ b/src/callnotifier/CallMonitor.php
@@ -4,9 +4,15 @@ namespace callnotifier;
/**
* Watches EDSS1 messages for calls. Keeps an internal call state
* and notifies loggers of incoming and finished calls.
+ *
+ * Notifications:
+ * - incomingCall
+ * - finishedCall
*/
class CallMonitor
{
+ protected $currentCalls = array();
+
public function __construct($config, $log)
{
$this->config = $config;
@@ -15,8 +21,58 @@ class CallMonitor
public function handle(EDSS1_Message $msg)
{
+ $callId = $msg->callRef;
+ if (!array_key_exists($callId, $this->currentCalls)) {
+ $this->handleNew($callId, $msg);
+ } else {
+ $this->handleExisting($callId, $msg);
+ }
+ }
+
+ protected function handleNew($callId, EDSS1_Message $msg)
+ {
+ if ($msg->type != EDSS1_Message::SETUP) {
+ return;
+ }
+ $this->currentCalls[$callId] = new CallMonitor_Call();
+ $this->handleSetup($callId, $msg);
}
+
+ protected function handleSetup($callId, EDSS1_Message $msg)
+ {
+ $call = $this->currentCalls[$callId];
+ $call->start = time();
+ foreach ($msg->parameters as $param) {
+ switch ($param->type) {
+ case EDSS1_Parameter::CALLING_PARTY_NUMBER:
+ $call->from = $param->number;
+ break;
+ case EDSS1_Parameter::CALLED_PARTY_NUMBER:
+ $call->to = $param->number;
+ break;
+ }
+ }
+ }
+
+
+ protected function handleExisting($callId, EDSS1_Message $msg)
+ {
+ $call = $this->currentCalls[$callId];
+
+ switch ($msg->type) {
+ case EDSS1_Message::CALL_PROCEEDING:
+ $this->log->log('incomingCall', array('call' => $call));
+ break;
+
+ case EDSS1_Message::RELEASE:
+ case EDSS1_Message::RELEASE_COMPLETE:
+ $call->end = time();
+ $this->log->log('finishedCall', array('call' => $call));
+ unset($this->currentCalls[$callId]);
+ break;
+ }
+ }
}
?>
diff --git a/src/callnotifier/CallMonitor/Call.php b/src/callnotifier/CallMonitor/Call.php
new file mode 100644
index 0000000..3ebd251
--- /dev/null
+++ b/src/callnotifier/CallMonitor/Call.php
@@ -0,0 +1,34 @@
+<?php
+namespace callnotifier;
+
+class CallMonitor_Call
+{
+ /**
+ * Telephone number of caller
+ *
+ * @var string
+ */
+ public $from;
+
+ /**
+ * Telephone number of called person
+ *
+ * @var string
+ */
+ public $to;
+
+ /**
+ * Time when the call started, unix timestamp
+ *
+ * @var int
+ */
+ public $start;
+
+ /**
+ * Time when the call ended, unix timestamp
+ */
+ public $end;
+
+}
+
+?>
diff --git a/src/callnotifier/EDSS1/Parameter.php b/src/callnotifier/EDSS1/Parameter.php
index 0f20427..87bc3c3 100644
--- a/src/callnotifier/EDSS1/Parameter.php
+++ b/src/callnotifier/EDSS1/Parameter.php
@@ -6,10 +6,10 @@ namespace callnotifier;
*/
class EDSS1_Parameter
{
- const CALLING_PARTY_NUMBER = "\x6C";
- const CALLED_PARTY_NUMBER = "\x70";
- const CONNECTED_NUMBER = "\x4C";
- const KEYPAD = "\x2C";
+ const CALLING_PARTY_NUMBER = 0x6C;
+ const CALLED_PARTY_NUMBER = 0x70;
+ const CONNECTED_NUMBER = 0x4C;
+ const KEYPAD = 0x2C;
public $type;
public $length;
diff --git a/src/callnotifier/Log.php b/src/callnotifier/Log.php
index 9f7a654..8a6b79a 100644
--- a/src/callnotifier/Log.php
+++ b/src/callnotifier/Log.php
@@ -13,6 +13,8 @@ class Log
protected $logger = array(
'msgData' => array(),
'edss1msg' => array(),
+ 'incomingCall' => array(),
+ 'finishedCall' => array(),
);
/**
diff --git a/src/callnotifier/Logger/CallEcho.php b/src/callnotifier/Logger/CallEcho.php
new file mode 100644
index 0000000..fe8b9b4
--- /dev/null
+++ b/src/callnotifier/Logger/CallEcho.php
@@ -0,0 +1,33 @@
+<?php
+namespace callnotifier;
+
+class Logger_CallEcho implements Logger
+{
+ public function log($type, $arData)
+ {
+ switch ($type) {
+ case 'incomingCall':
+ $this->displayIncoming($arData['call']);
+ break;
+ case 'finishedCall':
+ $this->displayFinished($arData['call']);
+ break;
+ }
+ }
+
+
+ protected function displayIncoming(CallMonitor_Call $call)
+ {
+ echo 'Incoming call from ' . $call->from
+ . ' to ' . $call->to . "\n";
+ }
+
+ protected function displayFinished(CallMonitor_Call $call)
+ {
+ echo 'Finished call from ' . $call->from
+ . ' to ' . $call->to
+ . ', length ' . date('H:i:s', $call->end - $call->start - 3600)
+ . "\n";
+ }
+}
+?>