[TASK] Continued to work on the Buffer thingy. Code still broken.
This commit is contained in:
parent
c382cfe756
commit
2b8263a49d
@ -42,14 +42,18 @@ abstract class Client_AbstractClient {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Forwards incoming data to the ProtocolParser.
|
* Forwards incoming data to the ProtocolHandler
|
||||||
* Calls protected processData()
|
* Let's the ProtocolHandler do all the work and forward its results to the Clients.
|
||||||
|
* Return resulting raw data.
|
||||||
* @param string $rawData
|
* @param string $rawData
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
public function processRawData($rawData) {
|
public function processRawData($rawData) {
|
||||||
$contentObject = $this->protocolHandler->pushRawData($rawData);
|
$this->protocolHandler->pushRawData($rawData);
|
||||||
return $this->processContentObject($this->protocolHandler->);
|
while($this->protocolHandler->canWork()) {
|
||||||
|
$this->processContentObject($this->protocolHandler->work());
|
||||||
|
}
|
||||||
|
return $this->protocolHandler->getRawData();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -1,6 +1,8 @@
|
|||||||
<?php
|
<?php
|
||||||
/**
|
/**
|
||||||
* Abstract ProtocolHandler with the basic api.
|
* Abstract ProtocolHandler with the basic api.
|
||||||
|
* 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.
|
||||||
* @author jpt
|
* @author jpt
|
||||||
* @abstract
|
* @abstract
|
||||||
* @package Protocol
|
* @package Protocol
|
||||||
@ -10,11 +12,46 @@
|
|||||||
abstract class Protocol_AbstractProtocolHandler {
|
abstract class Protocol_AbstractProtocolHandler {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Parses incoming data, returns a ProtocolObject
|
* Buffer for data that was received by the Client.
|
||||||
* @param string $data
|
* @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.
|
||||||
* @return mixed instance of Protocol_AbstractProtocolContentObject
|
* @return mixed instance of Protocol_AbstractProtocolContentObject
|
||||||
*/
|
*/
|
||||||
abstract public function parse($data);
|
abstract public function work();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
?>
|
?>
|
Loading…
Reference in New Issue
Block a user