From 38c913bb1e10ec33c84494325ce8427d5bbbf847 Mon Sep 17 00:00:00 2001 From: Michael Meckelein Date: Mon, 25 Feb 2008 23:18:05 +0100 Subject: [PATCH] added new classes --- classes/enums.class.php | 16 ++++ classes/logstream.class.php | 78 ++++++++++++++++ classes/logstreamconfig.class.php | 12 +++ classes/logstreamconfigdisk.class.php | 14 +++ classes/logstreamdisk.class.php | 128 ++++++++++++++++++++++++++ 5 files changed, 248 insertions(+) create mode 100644 classes/enums.class.php create mode 100644 classes/logstream.class.php create mode 100644 classes/logstreamconfig.class.php create mode 100644 classes/logstreamconfigdisk.class.php create mode 100644 classes/logstreamdisk.class.php diff --git a/classes/enums.class.php b/classes/enums.class.php new file mode 100644 index 0000000..a3f0cc7 --- /dev/null +++ b/classes/enums.class.php @@ -0,0 +1,16 @@ + \ No newline at end of file diff --git a/classes/logstream.class.php b/classes/logstream.class.php new file mode 100644 index 0000000..7931711 --- /dev/null +++ b/classes/logstream.class.php @@ -0,0 +1,78 @@ + \ No newline at end of file diff --git a/classes/logstreamconfig.class.php b/classes/logstreamconfig.class.php new file mode 100644 index 0000000..508cb71 --- /dev/null +++ b/classes/logstreamconfig.class.php @@ -0,0 +1,12 @@ + \ No newline at end of file diff --git a/classes/logstreamconfigdisk.class.php b/classes/logstreamconfigdisk.class.php new file mode 100644 index 0000000..c437904 --- /dev/null +++ b/classes/logstreamconfigdisk.class.php @@ -0,0 +1,14 @@ + \ No newline at end of file diff --git a/classes/logstreamdisk.class.php b/classes/logstreamdisk.class.php new file mode 100644 index 0000000..b1d588e --- /dev/null +++ b/classes/logstreamdisk.class.php @@ -0,0 +1,128 @@ +_logStreamConfigObj = $streamConfigObj; + } + + /** + * Open the file with read access. + * + * @param streamConfigObj object in: It has to be a LogSteamDiskConfig object. + * @return integer Error stat + */ + public function Open($arrProperties) { + if(!file_exists($this->_logStreamConfigObj->FileName)) { + return ERROR_FILE_NOT_FOUND; + } + + $this->_fp = fopen($this->_logStreamConfigObj->FileName, 'r'); + $this->_currentOffset = 0; + $this->_arrProperties = $arrProperties; + return SUCCESS; + } + + /** + * Close the file. + * + * @return integer Error state + */ + public function Close() { + + if (!fclose($this->_fp)) { + return ERROR_FILE_CANT_CLOSE; + } + return SUCCESS; + } + + + /** + * Read the next line from the file depending on the current + * read direction. + * + * Hint: If the current stream becomes unavailable an error + * stated is retuned. A typical case is if a log rotation + * changed the original data source. + * + * @param uID integer out: uID is the offset of data row + * @param logLine string out: data row + * @return integer Error state + * @see ReadNext + */ + public function ReadNext(&$uID, &$logLine) { + + $uID = $this->_currentOffset; + + if (feof($this->_fp)) { + return ERROR_FILE_EOF; + } + + $logLine = fgets($this->_fp); + if ($logLine === false) { + // ToDo: error occurs, or EOF + return 1; + } + + $this->_currentOffset = $this->_currentOffset + sizeof($logLine); + + return 0; + } + + /** + * Read the data from a specific uID which means in this + * case from a given offset of the file. + * + * @param uID integer in/out: unique id of the data row + * @param logLine string out: data row + * @return integer Error state + * @see ReadNext() + */ + public function Read($uID, &$logLine) { + $this->_currentOffset = $uID; + fseek($fp, $this->_currentOffset); + + // with Read we can only read forwards. + // so we have to remember the current read + // direction + $tmp = $this->_readDirection; + $iRet = $this->ReadNext($uID, $logLine); + $this->_readDirection = $tmp; + + return $iRet; + } + + /** + * Set the filter for the current stream. + * + * @param filter object in: filter object + * @return integer Error state + */ + public function SetFilter($filter) { + return 0; + } + + /** + * Set the direction the stream should read data. + * + * @param enumReadDirectionfilter EnumReadDirection in: The new direction. + * @return integer Error state + */ + public function SetReadDirection($enumReadDirection) { + return 0; + } +} + +?> \ No newline at end of file