2010-11-27 20:59:11 +01:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* Abstract ProtocolHandler with the basic api.
|
2010-12-02 23:34:12 +01:00
|
|
|
* The ProtocolHandler contains two buffers for incoming and outgoing data.
|
|
|
|
* It will store the data and provide functions to add incoming and get outgoing data.
|
2010-11-27 20:59:11 +01:00
|
|
|
* @author jpt
|
|
|
|
* @abstract
|
|
|
|
* @package Protocol
|
|
|
|
* TODO: finish this shit
|
2010-11-28 19:35:08 +01:00
|
|
|
* TODO: Move the buffers here, they will be more useful.
|
2010-11-27 20:59:11 +01:00
|
|
|
*/
|
|
|
|
abstract class Protocol_AbstractProtocolHandler {
|
|
|
|
|
|
|
|
/**
|
2010-12-02 23:34:12 +01:00
|
|
|
* Buffer for data that was received by the Client.
|
|
|
|
* @var Misc_Buffer
|
|
|
|
*/
|
|
|
|
protected $buffer_incoming;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Buffer for data that will be sent by the Client.
|
|
|
|
* @var Misc_Buffer
|
|
|
|
*/
|
|
|
|
protected $buffer_outgoing;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns whether work() can be called or not.
|
|
|
|
* Depends on the protocol and its implementation.
|
|
|
|
* @return boolean
|
|
|
|
*/
|
|
|
|
abstract public function canWork();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Main worker function of the ProtocolHandler.
|
|
|
|
* Will fetch data from the buffer_incoming, process it,
|
|
|
|
* and create a ProtocolContentObject out of it that will be returned to the client.
|
2010-11-28 01:04:35 +01:00
|
|
|
* @return mixed instance of Protocol_AbstractProtocolContentObject
|
2010-11-27 20:59:11 +01:00
|
|
|
*/
|
2010-12-02 23:34:12 +01:00
|
|
|
abstract public function work();
|
2010-11-27 20:59:11 +01:00
|
|
|
|
2010-12-02 23:34:12 +01:00
|
|
|
/**
|
|
|
|
* Adds the incoming data to the internal buffer.
|
|
|
|
* @param string $rawData
|
|
|
|
*/
|
|
|
|
public function pushRawData($rawData) {
|
|
|
|
$this->buffer_incoming->addData($rawData);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns all outgoing data of the internal buffer.
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
public function getRawData() {
|
|
|
|
return $this->buffer_outgoing->getAllBufferContents();
|
|
|
|
}
|
2010-11-27 20:59:11 +01:00
|
|
|
}
|
|
|
|
?>
|