ircbot/Classes/Protocol/AbstractProtocolHandler.php

75 lines
1.8 KiB
PHP

<?php
/**
* 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
* @abstract
* @package Protocol
* TODO: finish this shit
* TODO: Move the buffers here, they will be more useful.
*/
abstract class Protocol_AbstractProtocolHandler {
/**
* 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;
/**
* This function will be called by the constructor.
* It will create the necessary instances of Misc_Buffer and
* put them in $buffer_incoming and $buffer_outgoing.
* @return void
*/
abstract public function createBuffers();
/**
* General constructor.
* Calls createBuffers()
* @return void
*/
public function __construct() {
$this->createBuffers();
}
/**
* 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
*/
abstract public function work();
/**
* Adds the incoming data to the internal buffer.
* @param string $rawData
* @return void
*/
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();
}
}
?>