2011-12-03 12:28:02 +01:00
< ? php
namespace JPT\SocketFramework\Client ;
/**
* Abstract class that implements the basic api for the client dispatcher .
* If you want to write your own client dispatcher ( which should be very normal ),
* you have to extend this class , so you ' re able to use it in this socket framework .
*
* @ author jpt
* @ abstract
* @ package Client
*/
abstract class AbstractClientDispatcher implements \JPT\SocketFramework\Client\ClientDispatcherInterface {
/**
* @ var int
*/
protected $ID ;
/**
* @ var string
*/
protected $group ;
2011-12-04 14:31:18 +01:00
/**
* Contains data that the ClientDispatcher sends .
*
* @ var \JPT\SocketFramework\Misc\Buffer
*/
protected $outputBuffer ;
2011-12-03 12:28:02 +01:00
/**
* Contains a reference to the ClientManager in order to change stuff on the fly .
*
* @ var \JPT\SocketFramework\Client\ClientManager
*/
protected $clientManager ;
2011-12-04 14:31:18 +01:00
/**
* Default constructor .
* Creates the outputBuffer .
*/
public function __construct () {
$this -> outputBuffer = new \JPT\SocketFramework\Misc\Buffer ();
}
/**
* Adds data that shall be sent to the outputBuffer .
* Feel free to overwrite this if you need something different .
*
* @ param string $rawData
*/
protected function send ( $rawData ) {
$this -> outputBuffer -> addData ( $rawData );
}
/**
* Returns all data from the outputBuffer .
* Feel free to overwrite this if you need something different .
*
* @ return string
*/
public function getOutputData () {
return $this -> outputBuffer -> getAllBufferContents ();
}
2011-12-03 12:28:02 +01:00
/**
* Forwards incoming data to the ProtocolHandler
* Let ' s the ProtocolHandler do all the work and forward its results to the Clients .
* Return resulting raw data .
*
* @ param string $rawData
* @ return string
*/
public function processRawData ( $rawData ) {
}
/**
* This function will load the given config .
*
* @ param array $config
* @ return void
*/
2011-12-03 20:58:08 +01:00
public function loadConfig ( $config ) {
}
2011-12-03 12:28:02 +01:00
/**
* Will reset the connectionStatus of the client .
* Implementation is optional and depends on the client .
* Should be used to reset internal variables .
*
* @ return void
*/
public function resetConnectionStatus () {
}
/**
* This function gets called every time , the connection is established .
* This allows the client to send initial data .
*
* @ return void
*/
public function initializeConnection () {
}
/**
* Sets the ID .
*
* @ param int $id
* @ return void
*/
public function setID ( $id ) {
$this -> ID = $id ;
}
/**
* Sets the group .
*
* @ param string $group
* @ return void
*/
public function setGroup ( $group ) {
$this -> group = $group ;
}
/**
* Injects ClientManager
*
* @ param \JPT\SocketFramework\Client\ClientManager $clientManager
* @ return void
* @ throws \JPT\SocketFramework\Exception\WrongDatatypeException
*/
public function injectClientManager ( $clientManager ) {
if ( ! $clientManager instanceof \JPT\SocketFramework\Client\ClientManager ) {
throw new Exception_WrongDatatypeException ( " Cannot inject ClientManager! Expected an instance of \ JPT \ SocketFramework \ Client \ ClientManager, ' " . get_type ( $clientManager ) . " ' given. " , 1291156565 );
}
$this -> clientManager = $clientManager ;
}
}
?>