aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorChristian Weiske <cweiske@cweiske.de>2012-07-26 07:49:09 +0200
committerChristian Weiske <cweiske@cweiske.de>2012-07-26 07:49:09 +0200
commitb618b8360a69ada6b0ca412d5d15d7ec1edb9e82 (patch)
tree56f51cc63a62fc106633d7b4bde1ef3e41e80041 /src
parente60135e26ab4b374642f6f9293ddcac26adcacc8 (diff)
downloadauerswald-callnotifier-b618b8360a69ada6b0ca412d5d15d7ec1edb9e82.tar.gz
auerswald-callnotifier-b618b8360a69ada6b0ca412d5d15d7ec1edb9e82.zip
introduce separate log object and callmonitor
Diffstat (limited to 'src')
-rw-r--r--src/callnotifier/CLI.php8
-rw-r--r--src/callnotifier/CallMonitor.php22
-rw-r--r--src/callnotifier/Log.php57
-rw-r--r--src/callnotifier/Logger/Debug.php10
-rw-r--r--src/callnotifier/MessageHandler.php66
5 files changed, 101 insertions, 62 deletions
diff --git a/src/callnotifier/CLI.php b/src/callnotifier/CLI.php
index 55f7f71..5fdde92 100644
--- a/src/callnotifier/CLI.php
+++ b/src/callnotifier/CLI.php
@@ -23,15 +23,19 @@ class CLI
$this->fillConfig($this->config, $result);
- $handler = new MessageHandler($this->config);
+ $log = new Log();
if ($result->options['debug'] || $result->options['debugEdss1']) {
$debugLogger = new Logger_Debug();
- $handler->addLogger($debugLogger, '*');
+ $log->addLogger($debugLogger, '*');
if ($result->options['debugEdss1']) {
$debugLogger->edss1MsgOnly = true;
}
}
+ $callMonitor = new CallMonitor($this->config, $log);
+
+ $handler = new MessageHandler($this->config, $log, $callMonitor);
+
if ($this->config->replayFile !== null) {
$sourceClass = 'callnotifier\Source_File';
} else {
diff --git a/src/callnotifier/CallMonitor.php b/src/callnotifier/CallMonitor.php
new file mode 100644
index 0000000..a910e9f
--- /dev/null
+++ b/src/callnotifier/CallMonitor.php
@@ -0,0 +1,22 @@
+<?php
+namespace callnotifier;
+
+/**
+ * Watches EDSS1 messages for calls. Keeps an internal call state
+ * and notifies loggers of incoming and finished calls.
+ */
+class CallMonitor
+{
+ public function __construct($config, $log)
+ {
+ $this->config = $config;
+ $this->log = $log;
+ }
+
+ public function handle(EDSS1_Message $msg)
+ {
+ }
+
+}
+
+?>
diff --git a/src/callnotifier/Log.php b/src/callnotifier/Log.php
new file mode 100644
index 0000000..9f7a654
--- /dev/null
+++ b/src/callnotifier/Log.php
@@ -0,0 +1,57 @@
+<?php
+namespace callnotifier;
+
+class Log
+{
+ /**
+ * Array of logger object arrays.
+ * Key is the notification type, value is an array of logger objects
+ * that want to get notified about the type.
+ *
+ * @var array
+ */
+ protected $logger = array(
+ 'msgData' => array(),
+ 'edss1msg' => array(),
+ );
+
+ /**
+ * Add a logger
+ *
+ * @param Logger $logger Logger object to register
+ * @param array|string $types Single notification type or array of such
+ * types. "*" means "register for all types".
+ *
+ * @return self
+ */
+ public function addLogger(Logger $logger, $types)
+ {
+ if ($types == '*') {
+ $types = array_keys($this->logger);
+ }
+ $types = (array)$types;
+
+ foreach ($types as $type) {
+ if (!isset($this->logger[$type])) {
+ throw new \Exception('Unknown log type: ' . $type);
+ }
+ $this->logger[$type][] = $logger;
+ }
+ }
+
+ public function log($type, $arData)
+ {
+ if (!isset($this->logger[$type])) {
+ throw new \Exception('Unknown log type: ' . $type);
+ }
+
+ if (count($this->logger[$type])) {
+ foreach ($this->logger[$type] as $logger) {
+ $logger->log($type, $arData);
+ }
+ }
+ }
+
+}
+
+?>
diff --git a/src/callnotifier/Logger/Debug.php b/src/callnotifier/Logger/Debug.php
index 460f91f..06f7b08 100644
--- a/src/callnotifier/Logger/Debug.php
+++ b/src/callnotifier/Logger/Debug.php
@@ -8,11 +8,11 @@ class Logger_Debug implements Logger
public function __construct()
{
$cc = new \Console_Color2();
- $this->begin = $cc->convert('%y');
- $this->end = $cc->convert('%n');
- $this->blue = $cc->convert('%b');
- $this->red = $cc->convert('%r');
- $this->white = $cc->convert('%w');
+ $this->begin = $cc->convert('%y');
+ $this->end = $cc->convert('%n');
+ $this->blue = $cc->convert('%b');
+ $this->red = $cc->convert('%r');
+ $this->white = $cc->convert('%w');
$this->purple = $cc->convert('%p');
}
diff --git a/src/callnotifier/MessageHandler.php b/src/callnotifier/MessageHandler.php
index 59e8fa0..2df7969 100644
--- a/src/callnotifier/MessageHandler.php
+++ b/src/callnotifier/MessageHandler.php
@@ -5,47 +5,13 @@ class MessageHandler
{
protected $dumpHdl;
- /**
- * Array of logger object arrays.
- * Key is the notification type, value is an array of logger objects
- * that want to get notified about the type.
- *
- * @var array
- */
- protected $logger = array(
- 'msgData' => array(),
- 'edss1msg' => array(),
- );
-
- public function __construct($config)
+ public function __construct($config, $log, $callMonitor)
{
$this->config = $config;
$this->prepareDump();
- }
-
- /**
- * Add a logger
- *
- * @param Logger $logger Logger object to register
- * @param array|string $types Single notification type or array of such
- * types. "*" means "register for all types".
- *
- * @return self
- */
- public function addLogger(Logger $logger, $types)
- {
- if ($types == '*') {
- $types = array_keys($this->logger);
- }
- $types = (array)$types;
-
- foreach ($types as $type) {
- if (!isset($this->logger[$type])) {
- throw new \Exception('Unknown log type: ' . $type);
- }
- $this->logger[$type][] = $logger;
- }
+ $this->log = $log;
+ $this->callMonitor = $callMonitor;
}
public function handle($msg)
@@ -63,7 +29,7 @@ class MessageHandler
return false;
}
list(, $type, $someid, $details) = $matches;
- $this->log(
+ $this->log->log(
'msgData',
array(
'type' => $type,
@@ -73,7 +39,11 @@ class MessageHandler
);
if ($type == 'Debug') {
- $this->parseEDSS1($details);
+ $msg = $this->parseEDSS1($details);
+ if (is_object($msg)) {
+ $this->log->log('edss1msg', array('msg' => $msg));
+ $this->callMonitor->handle($msg);
+ }
}
}
@@ -82,6 +52,7 @@ class MessageHandler
*
* @param string $details Detail string of a debug message
*
+ * @return EDSS1_Message The retrieved message, NULL if none.
*/
protected function parseEDSS1($details)
{
@@ -98,22 +69,7 @@ class MessageHandler
$bytes = static::getBytesFromHexString($bytestring);
$mp = new EDSS1_Parser();
- $msg = $mp->parse($bytes);
-
- $this->log('edss1msg', array('msg' => $msg));
- }
-
- protected function log($type, $arData)
- {
- if (!isset($this->logger[$type])) {
- throw new \Exception('Unknown log type: ' . $type);
- }
-
- if (count($this->logger[$type])) {
- foreach ($this->logger[$type] as $logger) {
- $logger->log($type, $arData);
- }
- }
+ return $mp->parse($bytes);
}
public static function getBytesFromHexString($bytestring)