<?php
/*
 * This file is part of the easy-CMS project.
 * easy-CMS is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * easy-CMS is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with easy-CMS; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */

/**
 * @package    Core
 * @subpackage Engines
 */
include_once('classes/core/CoreObject.class.php');

class BatchEngine extends CoreObject {
	var $startTime;
	var $duration;
	var $operations;

	// @public
	function batchEngine() {
	}

	// @public
	function start() {
		list($usec, $sec) = explode(" ", microtime());
		$this->startTime = ((float)$usec + (float)$sec);
		$this->operations = 0;
		$this->process();
	}

	function stop() {
	}

	function doStep() {
	}

	// @private
	function process() {
		while($this->executionTime() < BATCH_DURATION && $this->operations < BATCH_SIZE) {
			if(!$this->doStep()) {
				break;
			}
			++$this->operations;
		}
		list($usec, $sec) = explode(" ", microtime());
		$stopTime = ((float)$usec + (float)$sec);
		$this->duration = $stopTime-$this->startTime;
		$this->stop();
	}

	function executionTime() {
		list($usec, $sec) = explode(" ", microtime());
		$now = ((float)$usec + (float)$sec);
		return $now - $this->startTime;
	}
}
?>