[TASK] Cleanup in the ClientManager and added an AbstractProtocolHandler.

This commit is contained in:
Jan Philipp Timme 2010-11-27 19:59:11 +00:00
parent 952af43b97
commit f3b1354aa2
2 changed files with 24 additions and 17 deletions

View File

@ -6,6 +6,7 @@
* @author jpt * @author jpt
* @package Client * @package Client
* @depends Connection * @depends Connection
* TODO: implement routing with some more detailed rules, remove hardcoded client-based routing.
*/ */
class Client_ClientManager { class Client_ClientManager {
@ -23,7 +24,7 @@ class Client_ClientManager {
/** /**
* @var array * @var array
*/ */
protected $rawRoutingRules; protected $routingRules;
/** /**
* An array that contains all protocols we have clients for. * An array that contains all protocols we have clients for.
@ -47,7 +48,7 @@ class Client_ClientManager {
$this->connectionPool = new Connection_ConnectionPool($linebreak); $this->connectionPool = new Connection_ConnectionPool($linebreak);
$this->clientPool = array(); $this->clientPool = array();
$this->registeredProtocols = array(); $this->registeredProtocols = array();
$this->rawRoutingRules = array(); $this->routingRules = array();
$this->configPool = array(); $this->configPool = array();
} }
@ -81,18 +82,15 @@ class Client_ClientManager {
if($connectionHandler->isConnected() === FALSE && $connectionHandler->isListening() === FALSE) { if($connectionHandler->isConnected() === FALSE && $connectionHandler->isListening() === FALSE) {
$this->removeClientForConnectionHandler($connectionHandler); $this->removeClientForConnectionHandler($connectionHandler);
} }
//handle accepted sockets, adopt them and treat them with care :-)
//ne warte mal, das geht nicht...oder so
if($connectionHandler->isListening() === TRUE) { if($connectionHandler->isListening() === TRUE) {
$this->addClientForConnectionHandler($connectionHandler); $this->addClientForConnectionHandler($connectionHandler);
} }
//create a client for a connection without one. //create a client for a connection without one.
if(!isset($this->clientPool[$connectionHandler->getID()])) { if(!isset($this->clientPool[$connectionHandler->getID()])) {
$this->addClientForConnectionHandler($connectionHandler); $this->addClientForConnectionHandler($connectionHandler);
} }
//call the registered client
if(isset($this->clientPool[$connectionHandler->getID()])) { if(isset($this->clientPool[$connectionHandler->getID()])) {
//let the client process the data, send the results back. //let the client process the data, send the results back.
while($data = $connectionHandler->read()) { while($data = $connectionHandler->read()) {
@ -102,19 +100,9 @@ class Client_ClientManager {
} }
} }
} }
} }
} }
/**
* TODO: implement this!
* @param unknown_type $from
* @param unknown_type $to
*/
public function addRawRouting($from, $to) {
$this->rawRoutingRules[] = array("");
}
/** /**
* Calls ConnectionPool in order to create a simple connection. * Calls ConnectionPool in order to create a simple connection.
* @see Connection_ConnectionPool * @see Connection_ConnectionPool

View File

@ -0,0 +1,19 @@
<?php
/**
* Abstract ProtocolHandler with the basic api.
* @author jpt
* @abstract
* @package Protocol
* TODO: finish this shit
*/
abstract class Protocol_AbstractProtocolHandler {
/**
* Parses incoming data, returns a ProtocolObject
* @param string $data
* @return Protocol_ProtocolObejct
*/
abstract public function parse($data);
}
?>