application/hub/interfaces/handler/class_Handleable.php -text
application/hub/interfaces/handler/network/.htaccess -text
application/hub/interfaces/handler/network/class_Networkable.php -text
+application/hub/interfaces/handler/task/.htaccess -text
+application/hub/interfaces/handler/task/class_HandleableTask.php -text
application/hub/interfaces/listener/.htaccess -text
application/hub/interfaces/listener/class_Listenable.php -text
application/hub/interfaces/lists/.htaccess -text
application/hub/interfaces/nodes/class_NodeHelper.php -text
application/hub/interfaces/pool/.htaccess -text
application/hub/interfaces/pool/class_Poolable.php -text
-application/hub/interfaces/pool/class_PoolableClient.php -text
-application/hub/interfaces/pool/class_PoolableListener.php -text
application/hub/interfaces/pool/client/.htaccess -text
application/hub/interfaces/pool/client/class_PoolableClient.php -text
application/hub/interfaces/pool/listener/.htaccess -text
application/hub/main/filter/shutdown/class_HubShutdownFlushNodeListFilter.php -text
application/hub/main/filter/shutdown/class_HubShutdownListenerPoolFilter.php -text
application/hub/main/filter/shutdown/class_HubShutdownNodeFilter.php -text
+application/hub/main/filter/task/.htaccess -text
+application/hub/main/filter/task/class_TaskHandlerInitializerFilter.php -text
application/hub/main/handler/.htaccess -text
application/hub/main/handler/class_ -text
application/hub/main/handler/class_BaseHandler.php -text
application/hub/main/handler/network/class_ -text
application/hub/main/handler/network/class_BaseNetworkPackageHandler.php -text
application/hub/main/handler/network/tcp/.htaccess -text
+application/hub/main/handler/network/tcp/class_ -text
application/hub/main/handler/network/tcp/class_TcpNetworkPackageHandler.php -text
application/hub/main/handler/network/udp/.htaccess -text
application/hub/main/handler/network/udp/class_UdpNetworkPackageHandler.php -text
+application/hub/main/handler/tasks/.htaccess -text
+application/hub/main/handler/tasks/class_TaskHandler.php -text
application/hub/main/iterator/.htaccess -text
application/hub/main/iterator/class_ -text
application/hub/main/iterator/class_BaseIterator.php -text
application/hub/main/resolver/controller/.htaccess -text
application/hub/main/resolver/controller/console/.htaccess -text
application/hub/main/resolver/controller/console/class_HubConsoleControllerResolver.php -text
+application/hub/main/resolver/state/.htaccess -text
+application/hub/main/resolver/state/class_BaseStateResolver.php -text
+application/hub/main/resolver/state/network/.htaccess -text
+application/hub/main/resolver/state/network/class_NetworkStateResolver.php -text
application/hub/main/states/.htaccess -text
application/hub/main/states/class_ -text
application/hub/main/states/class_BaseState.php -text
application/hub/main/states/client/.htaccess -text
application/hub/main/states/client/class_BaseClientState.php -text
+application/hub/main/states/generic/.htaccess -text
application/hub/main/states/hub/.htaccess -text
application/hub/main/states/hub/class_BaseHubState.php -text
application/hub/main/visitor/.htaccess -text
// CFG: HUBCONSOLE-CMD-RESOLVER-CLASS
$cfg->setConfigEntry('hubconsole_cmd_resolver_class', 'HubConsoleCommandResolver');
+// CFG: NETWORK-STATE-RESOLVER-CLASS
+$cfg->setConfigEntry('network_state_resolver_class', 'NetworkStateResolver');
+
// CFG: NEWS-DOWNLOAD-FILTER
$cfg->setConfigEntry('news_download_filter', 'NewsDownloadFilter');
// CFG: NEWS-PROCESS-FILTER
$cfg->setConfigEntry('news_process_filter', 'NewsProcessFilter');
-// CFG: NODE-INITIALIZATION-FILTER
+// CFG: NODE-INITIALIZER-FILTER
$cfg->setConfigEntry('node_initializer_filter', 'NodeInitializationFilter');
+// CFG: HUB-ACTIVATION-TASK-HANDLER-INITIALIZER-FILTER
+$cfg->setConfigEntry('hub_activation_task_handler_initializer_filter', 'TaskHandlerInitializerFilter');
+
// CFG: CONSOLE-WELCOME-TEASER-FILTER
$cfg->setConfigEntry('console_welcome_teaser_filter', 'ConsoleWelcomeTeaserFilter');
// CFG: NEWS-MAIN-LIMIT
$cfg->setConfigEntry('news_main_limit', 5);
+// CFG: TASK-HANDLER-CLASS
+$cfg->setConfigEntry('task_handler_class', 'TaskHandler');
+
+// CFG: TASK-NETWORK-PACKAGE-READER-STARTUP-DELAY
+$cfg->setConfigEntry('task_network_package_reader_startup_delay', 5000);
+
+// CFG: TASK-NETWORK-PACKAGE-READER-INTERVAL-DELAY
+$cfg->setConfigEntry('task_network_package_reader_interval_delay', 10);
+
+// CFG: TASK-QUERY-HANDLER-STARTUP-DELAY
+$cfg->setConfigEntry('task_query_handler_startup_delay', 3000);
+
+// CFG: TASK-QUERY-HANDLER-INTERVAL-DELAY
+$cfg->setConfigEntry('task_query_handler_interval_delay', 10);
+
// [EOF]
?>
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
-// Hub main loop debugging
-define('HUB_DEBUG_MAIN', true);
+// Set error reporting
+error_reporting(E_ALL | E_STRICT);
// [EOF]
?>
*
* @author Roland Haeder <webmaster@ship-simu.org>
* @version 0.0.0
- * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 Core Developer Team
+ * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 Hub Developer Team
* @license GNU GPL 3.0 or any newer version
* @link http://www.ship-simu.org
*
*
* @author Roland Haeder <webmaster@ship-simu.org>
* @version 0.0.0
- * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 Core Developer Team
+ * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 Hub Developer Team
* @license GNU GPL 3.0 or any newer version
* @link http://www.ship-simu.org
*
*
* @author Roland Haeder <webmaster@ship-simu.org>
* @version 0.0.0
- * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 Core Developer Team
+ * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 Hub Developer Team
* @license GNU GPL 3.0 or any newer version
* @link http://www.ship-simu.org
*
*
* @author Roland Haeder <webmaster@ship-simu.org>
* @version 0.0.0
- * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 Core Developer Team
+ * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 Hub Developer Team
* @license GNU GPL 3.0 or any newer version
* @link http://www.ship-simu.org
*
*
* @author Roland Haeder <webmaster@ship-simu.org>
* @version 0.0.0
- * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 Core Developer Team
+ * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 Hub Developer Team
* @license GNU GPL 3.0 or any newer version
* @link http://www.ship-simu.org
*
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
interface Networkable extends Handleable {
+ /**
+ * Processes a package from given resource. This is mostly useful for TCP
+ * package handling and is implemented in the TcpListener class
+ *
+ * @param $resource A valid resource identifier
+ * @return void
+ * @throws InvalidResourceException If the given resource is invalid
+ */
+ function processResourcePackage ($resource);
}
//
--- /dev/null
+Deny from all
--- /dev/null
+<?php
+/**
+ * A HandleableTask interface
+ *
+ * @author Roland Haeder <webmaster@ship-simu.org>
+ * @version 0.0.0
+ * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 Hub Developer Team
+ * @license GNU GPL 3.0 or any newer version
+ * @link http://www.ship-simu.org
+ *
+ * This program 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 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program 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 this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+interface HandleableTask extends Handleable {
+ /**
+ * Registers a task with a task handler. This method throws a
+ * TaskAlreadyRegisteredException if the task has already been registered
+ *
+ * @param $taskName A task name to register the task on
+ * @param $taskInstance The instance we should register as a task
+ * @return void
+ */
+ function registerTask ($taskName, Visitable $taskInstance);
+}
+
+//
+?>
+++ /dev/null
-<?php
-/**
- * A default client pool class
- *
- * @author Roland Haeder <webmaster@ship-simu.org>
- * @version 0.0.0
- * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 Hub Developer Team
- * @license GNU GPL 3.0 or any newer version
- * @link http://www.ship-simu.org
- *
- * This program 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 3 of the License, or
- * (at your option) any later version.
- *
- * This program 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 this program. If not, see <http://www.gnu.org/licenses/>.
- */
-interface PoolableClient extends Poolable {
- /**
- * Adds a socket resource to the client pool
- *
- * @param $socketResource A valid (must be!) socket resource
- * @return void
- * @todo 0% done
- */
- function addClient ($socketResource);
-}
-
-//
-?>
+++ /dev/null
-<?php
-/**
- * An interface for pools
- *
- * @author Roland Haeder <webmaster@ship-simu.org>
- * @version 0.0.0
- * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 Hub Developer Team
- * @license GNU GPL 3.0 or any newer version
- * @link http://www.ship-simu.org
- *
- * This program 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 3 of the License, or
- * (at your option) any later version.
- *
- * This program 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 this program. If not, see <http://www.gnu.org/licenses/>.
- */
-interface PoolableListener extends Poolable {
- /**
- * Adds a listener instance to this pool
- *
- * @param $listenerInstance An instance of a Listenable class
- * @return void
- */
- function addListener (Listenable $listenerInstance);
-}
-
-//
-?>
function accept (Visitor $visitorInstance);
}
-//
+// [EOF]
?>
interface Visitor extends FrameworkInterface {
}
-//
+// [EOF]
?>
function visitPool (Poolable $poolInstance);
}
-//
+// [EOF]
?>
function visitDecorator (Listenable $listenerInstance);
}
-//
+// [EOF]
?>
<?php
/**
- * A command for 'main'
+ * A command for the 'main' routine
*
* @author Roland Haeder <webmaster@ship-simu.org>
* @version 0.0.0
- * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 Core Developer Team
+ * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 Hub Developer Team
* @license GNU GPL 3.0 or any newer version
* @link http://www.ship-simu.org
*
* @param $requestInstance An instance of a class with an Requestable interface
* @param $responseInstance An instance of a class with an Responseable interface
* @return void
- * @throws NullPointerException When $applicationInstance is null
- * @throws InvalidInterfaceException When $applicationInstance does not implement ManageableApplication
- * @todo ~10% done
*/
public function execute (Requestable $requestInstance, Responseable $responseInstance) {
// Get a registry and the application instance from it
$applicationInstance = Registry::getRegistry()->getInstance('app');
- // Is this a ManageableApplication instance?
- if (is_null($applicationInstance)) {
- // Something really bad went wrong
- throw new NullPointerException($this, self::EXCEPTION_IS_NULL_POINTER);
- } elseif (!$applicationInstance instanceof ManageableApplication) {
- // Something went badly wrong
- throw new InvalidInterfaceException(array($this, 'ManageableApplication'), self::EXCEPTION_REQUIRED_INTERFACE_MISSING);
- } // END - if
-
// ----------------------- Bootstrapping phase ------------------------
// Try to bootstrap the node and pass the request instance to it for
// extra arguments which mostly override config entries or enable special
// Get node instance
$nodeInstance = Registry::getRegistry()->getInstance('node');
- // Sanity-check on it
- if (is_null($nodeInstance)) {
- // Throws a NullPointerException here
- throw new NullPointerException($this, self::EXCEPTION_IS_NULL_POINTER);
- } // END - if
-
// -------------------------- Hub activation --------------------------
// Activates the hub by doing some final preparation steps and setting
// the attribute $hubIsActive to true
$nodeInstance->activateHub($requestInstance, $responseInstance);
+ // Get task handler instance
+ $handlerInstance = Registry::getRegistry()->getInstance('task');
+
// Debug message
$this->debugOutput('MAIN: --- Entering main loop. ---');
// This is the main loop. Queried calls should come back here very fast
// so the whole application runs on nice speed. This while-loop goes
// until the hub is no longer active.
- while ($nodeInstance->isHubActive()) {
+ while (($nodeInstance->isHubActive()) && ($handlerInstance->hasTasksLeft())) {
// Handle the listeners
// @TODO We may have to catch some exceptions here
$nodeInstance->getListenerPoolInstance()->handleListenerPool();
$controllerInstance->addBootstrapFilter(ObjectFactory::createObjectByConfiguredName('hub_bootstrap_listener_pool_filter'));
// Add hub activation filters
+ $controllerInstance->addActivationFilter(ObjectFactory::createObjectByConfiguredName('hub_activation_task_handler_initializer_filter'));
// Add shutdown filters
$controllerInstance->addShutdownFilter(ObjectFactory::createObjectByConfiguredName('hub_shutdown_flush_node_list_filter'));
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
-class LocalQueryConnector extends BaseQueryConnector implements Connectable, Queryable {
+class LocalQueryConnector extends BaseQueryConnector implements Connectable, Queryable, Visitable {
/**
* Protected constructor
*
// Finally return it
return $connectorInstance;
}
+
+ /**
+ * Accepts the visitor to rpocess the visit "request"
+ *
+ * @param $visitorInstance An instance of a Visitor class
+ * @return void
+ */
+ public function accept (Visitor $visitorInstance) {
+ $this->partialStub('visitor='.$visitorInstance->__toString());
+ }
}
// [EOF]
*
* @author Roland Haeder <webmaster@ship-simu.org>
* @version 0.0.0
- * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 Core Developer Team
+ * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 Hub Developer Team
* @license GNU GPL 3.0 or any newer version
* @link http://www.ship-simu.org
*
* @param $filterInstance A Filterable class
* @return void
*/
- public function addHubActivationFilter (Filterable $filterInstance) {
+ public function addActivationFilter (Filterable $filterInstance) {
$this->addFilter('activation', $filterInstance);
}
* @param $responseInstance A Responseable class
* @return void
*/
- public function executeHubActivationFilters (Requestable $requestInstance, Responseable $responseInstance) {
+ public function executeActivationFilters (Requestable $requestInstance, Responseable $responseInstance) {
$this->executeFilters('activation', $requestInstance, $responseInstance);
}
*
* @author Roland Haeder <webmaster@ship-simu.org>
* @version 0.0.0
- * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 Core Developer Team
+ * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 Hub Developer Team
* @license GNU GPL 3.0 or any newer version
* @link http://www.ship-simu.org
*
// Get node instance
$nodeInstance = Registry::getRegistry()->getInstance('node');
- // Sanity-check on it
- if (is_null($nodeInstance)) {
- // Throws a FilterChainException to stop further processing
- throw new FilterChainException($this, self::EXCEPTION_FILTER_CHAIN_INTERCEPTED);
- } // END if
-
// Now do something
$this->partialStub('Please implement this step.');
}
*
* @author Roland Haeder <webmaster@ship-simu.org>
* @version 0.0.0
- * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 Core Developer Team
+ * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 Hub Developer Team
* @license GNU GPL 3.0 or any newer version
* @link http://www.ship-simu.org
*
// Get node instance
$nodeInstance = Registry::getRegistry()->getInstance('node');
- // Sanity-check on it
- if (is_null($nodeInstance)) {
- // Throws a FilterChainException to stop further processing
- throw new FilterChainException($this, self::EXCEPTION_FILTER_CHAIN_INTERCEPTED);
- } // END - if
-
// Now do something
$this->partialStub('Please implement this step.');
}
*
* @author Roland Haeder <webmaster@ship-simu.org>
* @version 0.0.0
- * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 Core Developer Team
+ * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 Hub Developer Team
* @license GNU GPL 3.0 or any newer version
* @link http://www.ship-simu.org
*
// Get node instance
$nodeInstance = Registry::getRegistry()->getInstance('node');
- // Sanity-check on it
- if (is_null($nodeInstance)) {
- // Throws a FilterChainException to stop further processing
- throw new FilterChainException($this, self::EXCEPTION_FILTER_CHAIN_INTERCEPTED);
- } // END - if
-
// Do some extra bootstrapping steps
$nodeInstance->doBootstrapping();
}
*
* @author Roland Haeder <webmaster@ship-simu.org>
* @version 0.0.0
- * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 Core Developer Team
+ * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 Hub Developer Team
* @license GNU GPL 3.0 or any newer version
* @link http://www.ship-simu.org
*
// Get node instance
$nodeInstance = Registry::getRegistry()->getInstance('node');
- // Sanity-check on it
- if (is_null($nodeInstance)) {
- // Throws a FilterChainException to stop further processing
- throw new FilterChainException($this, self::EXCEPTION_FILTER_CHAIN_INTERCEPTED);
- } // END - if
-
// --------------------- Hub-id acquirement phase ---------------------
// Acquire a hub-id. This step generates on first launch a new one and
// on any later launches it will restore the hub-id from the database.
*
* @author Roland Haeder <webmaster@ship-simu.org>
* @version 0.0.0
- * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 Core Developer Team
+ * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 Hub Developer Team
* @license GNU GPL 3.0 or any newer version
* @link http://www.ship-simu.org
*
// Get node instance
$nodeInstance = Registry::getRegistry()->getInstance('node');
- // Sanity-check on it
- if (is_null($nodeInstance)) {
- // Throws a FilterChainException to stop further processing
- throw new FilterChainException($this, self::EXCEPTION_FILTER_CHAIN_INTERCEPTED);
- } // END - if
-
// ------------------- More generic bootstrap steps -------------------
// Generate the session id which will only be stored in RAM and kept for
// the whole "session".
*
* @author Roland Haeder <webmaster@ship-simu.org>
* @version 0.0.0
- * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 Core Developer Team
+ * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 Hub Developer Team
* @license GNU GPL 3.0 or any newer version
* @link http://www.ship-simu.org
*
// Get node instance
$nodeInstance = Registry::getRegistry()->getInstance('node');
- // Sanity-check on it
- if (is_null($nodeInstance)) {
- // Throws a FilterChainException to stop further processing
- throw new FilterChainException($this, self::EXCEPTION_FILTER_CHAIN_INTERCEPTED);
- } // END - if
-
// Now init the queues
$nodeInstance->initQueues();
}
*
* @author Roland Haeder <webmaster@ship-simu.org>
* @version 0.0.0
- * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 Core Developer Team
+ * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 Hub Developer Team
* @license GNU GPL 3.0 or any newer version
* @link http://www.ship-simu.org
*
// Get node instance
$nodeInstance = Registry::getRegistry()->getInstance('node');
- // Sanity-check on it
- if (is_null($nodeInstance)) {
- // Throws a FilterChainException to stop further processing
- throw new FilterChainException($this, self::EXCEPTION_FILTER_CHAIN_INTERCEPTED);
- } // END - if
-
// Now do something
$nodeInstance->initializeListenerPool();
}
*
* @author Roland Haeder <webmaster@ship-simu.org>
* @version 0.0.0
- * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 Core Developer Team
+ * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 Hub Developer Team
* @license GNU GPL 3.0 or any newer version
* @link http://www.ship-simu.org
*
// Get node instance
$nodeInstance = Registry::getRegistry()->getInstance('node');
- // Sanity-check on it
- if (is_null($nodeInstance)) {
- // Throws a FilterChainException to stop further processing
- throw new FilterChainException($this, self::EXCEPTION_FILTER_CHAIN_INTERCEPTED);
- } // END - if
-
// Restore a previously downloaded bootstrap-node list.
$nodeInstance->bootstrapRestoreNodeList();
}
*
* @author Roland Haeder <webmaster@ship-simu.org>
* @version 0.0.0
- * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 Core Developer Team
+ * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 Hub Developer Team
* @license GNU GPL 3.0 or any newer version
* @link http://www.ship-simu.org
*
// Get node instance
$nodeInstance = Registry::getRegistry()->getInstance('node');
- // Sanity-check on it
- if (is_null($nodeInstance)) {
- // Throws a FilterChainException to stop further processing
- throw new FilterChainException($this, self::EXCEPTION_FILTER_CHAIN_INTERCEPTED);
- } // END - if
-
// Now do something
$this->partialStub('Please implement this step.');
}
*
* @author Roland Haeder <webmaster@ship-simu.org>
* @version 0.0.0
- * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 Core Developer Team
+ * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 Hub Developer Team
* @license GNU GPL 3.0 or any newer version
* @link http://www.ship-simu.org
*
// Get node instance
$nodeInstance = Registry::getRegistry()->getInstance('node');
- // Sanity-check on it
- if (is_null($nodeInstance)) {
- // Throws a FilterChainException to stop further processing
- throw new FilterChainException($this, self::EXCEPTION_FILTER_CHAIN_INTERCEPTED);
- } // END - if
-
// Implement this!
$this->partialStub('Please implement this method.');
}
*
* @author Roland Haeder <webmaster@ship-simu.org>
* @version 0.0.0
- * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 Core Developer Team
+ * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 Hub Developer Team
* @license GNU GPL 3.0 or any newer version
* @link http://www.ship-simu.org
*
// Get node instance
$nodeInstance = Registry::getRegistry()->getInstance('node');
- // Sanity-check on it
- if (is_null($nodeInstance)) {
- // Throws a FilterChainException to stop further processing
- throw new FilterChainException($this, self::EXCEPTION_FILTER_CHAIN_INTERCEPTED);
- } // END - if
-
// Now output the teaser
$nodeInstance->outputConsoleTeaser();
}
*
* @author Roland Haeder <webmaster@ship-simu.org>
* @version 0.0.0
- * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 Core Developer Team
+ * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 Hub Developer Team
* @license GNU GPL 3.0 or any newer version
* @link http://www.ship-simu.org
*
*
* @author Roland Haeder <webmaster@ship-simu.org>
* @version 0.0.0
- * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 Core Developer Team
+ * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 Hub Developer Team
* @license GNU GPL 3.0 or any newer version
* @link http://www.ship-simu.org
*
*
* @author Roland Haeder <webmaster@ship-simu.org>
* @version 0.0.0
- * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 Core Developer Team
+ * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 Hub Developer Team
* @license GNU GPL 3.0 or any newer version
* @link http://www.ship-simu.org
*
// Get node instance
$nodeInstance = Registry::getRegistry()->getInstance('node');
- // Sanity-check on it
- if (is_null($nodeInstance)) {
- // Throws a FilterChainException to stop further processing
- throw new FilterChainException($this, self::EXCEPTION_FILTER_CHAIN_INTERCEPTED);
- } // END - if
-
// Now do something
$this->partialStub('Please implement this step.');
}
*
* @author Roland Haeder <webmaster@ship-simu.org>
* @version 0.0.0
- * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 Core Developer Team
+ * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 Hub Developer Team
* @license GNU GPL 3.0 or any newer version
* @link http://www.ship-simu.org
*
// Get node instance
$nodeInstance = Registry::getRegistry()->getInstance('node');
- // Sanity-check on it
- if (is_null($nodeInstance)) {
- // Throws a FilterChainException to stop further processing
- throw new FilterChainException($this, self::EXCEPTION_FILTER_CHAIN_INTERCEPTED);
- } // END - if
-
// Get query instance
$queryInstance = $nodeInstance->getQueryInstance();
*
* @author Roland Haeder <webmaster@ship-simu.org>
* @version 0.0.0
- * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 Core Developer Team
+ * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 Hub Developer Team
* @license GNU GPL 3.0 or any newer version
* @link http://www.ship-simu.org
*
// Get node instance
$nodeInstance = Registry::getRegistry()->getInstance('node');
- // Sanity-check on it
- if (is_null($nodeInstance)) {
- // Throws a FilterChainException to stop further processing
- throw new FilterChainException($this, self::EXCEPTION_FILTER_CHAIN_INTERCEPTED);
- } // END - if
-
// Now do something
$this->partialStub('Please implement this step.');
}
*
* @author Roland Haeder <webmaster@ship-simu.org>
* @version 0.0.0
- * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 Core Developer Team
+ * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 Hub Developer Team
* @license GNU GPL 3.0 or any newer version
* @link http://www.ship-simu.org
*
// Get node instance
$nodeInstance = Registry::getRegistry()->getInstance('node');
- // Sanity-check on it
- if (is_null($nodeInstance)) {
- // Throws a FilterChainException to stop further processing
- throw new FilterChainException($this, self::EXCEPTION_FILTER_CHAIN_INTERCEPTED);
- } // END - if
-
// Get listener pool instance
$listenerPoolInstance = $nodeInstance->getListenerPoolInstance();
*
* @author Roland Haeder <webmaster@ship-simu.org>
* @version 0.0.0
- * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 Core Developer Team
+ * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 Hub Developer Team
* @license GNU GPL 3.0 or any newer version
* @link http://www.ship-simu.org
*
// Get node instance
$nodeInstance = Registry::getRegistry()->getInstance('node');
- // Sanity-check on it
- if (is_null($nodeInstance)) {
- // Throws a FilterChainException to stop further processing
- throw new FilterChainException($this, self::EXCEPTION_FILTER_CHAIN_INTERCEPTED);
- } // END - if
-
// Shutdown the node. This should be the last line
$nodeInstance->doShutdown();
}
--- /dev/null
+Deny from all
--- /dev/null
+<?php
+/**
+ * A ??? filter for !!!
+ *
+ * @author Roland Haeder <webmaster@ship-simu.org>
+ * @version 0.0.0
+ * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 Hub Developer Team
+ * @license GNU GPL 3.0 or any newer version
+ * @link http://www.ship-simu.org
+ *
+ * This program 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 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program 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 this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+class TaskHandlerInitializerFilter extends BaseFilter implements Filterable {
+ /**
+ * Protected constructor
+ *
+ * @return void
+ */
+ protected function __construct () {
+ // Call parent constructor
+ parent::__construct(__CLASS__);
+ }
+
+ /**
+ * Creates an instance of this filter class
+ *
+ * @return $filterInstance An instance of this filter class
+ */
+ public final static function createTaskHandlerInitializerFilter () {
+ // Get a new instance
+ $filterInstance = new TaskHandlerInitializerFilter();
+
+ // Return the instance
+ return $filterInstance;
+ }
+
+ /**
+ * Executes the filter with given request and response objects
+ *
+ * @param $requestInstance An instance of a class with an Requestable interface
+ * @param $responseInstance An instance of a class with an Responseable interface
+ * @return void
+ * @throws FilterChainException If we need to interrupt the filter chain
+ * @todo 0% done
+ */
+ public function execute (Requestable $requestInstance, Responseable $responseInstance) {
+ // Get node instance
+ $nodeInstance = Registry::getRegistry()->getInstance('node');
+
+ // Get a new task handler instance
+ $handlerInstance = ObjectFactory::createObjectByConfiguredName('task_handler_class');
+
+ // Register some tasks and provide both instances for this:
+ // 1.) Network package reader, needs to be delayed a little
+ $handlerInstance->registerTask('network_package_reader', $nodeInstance->getListenerPoolInstance());
+ // 2.) Query instance
+ $handlerInstance->registerTask('query_handler', $nodeInstance->getQueryInstance());
+
+ // Put the task handler in registry
+ Registry::getRegistry()->addInstance('task', $handlerInstance);
+ }
+}
+
+// [EOF]
+?>
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
-class ???NetworkPackageHandler extends BaseNetworkPackageHandler implements !!! {
+class ???NetworkPackageHandler extends BaseNetworkPackageHandler implements Networkable {
/**
* Protected constructor
*
/**
* Creates an instance of this class
*
- * @return $handlerInstance An instance of a !!! class
+ * @return $handlerInstance An instance of a Networkable class
*/
public final static function create???NetworkPackageHandler () {
// Get new instance
// Return the prepared instance
return $handlerInstance;
}
+
+ /**
+ * Processes a package from given resource. This is mostly useful for TCP
+ * package handling and is implemented in the TcpListener class
+ *
+ * @param $resource A valid resource identifier
+ * @return void
+ * @throws InvalidResourceException If the given resource is invalid
+ * @todo 0%
+ */
+ public function processResourcePackage ($resource) {
+ // Check the resource
+ if (!is_resource($resource)) {
+ // Throw an exception
+ throw new InvalidResourceException($this, self::EXCEPTION_INVALID_RESOURCE);
+ } // END - if
+
+ // Implement processing here
+ $this->partialStub('Please implement this method.');
+ }
}
// [EOF]
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
class BaseNetworkPackageHandler extends BaseHandler {
+ // Error codes
+ const SOCKET_ERROR_GENERAL = 'general_error';
+ const SOCKET_ERROR_TRANSPORT_ENDPOINT = 'transport_endpoint';
+ const SOCKET_ERROR_UNHANDLED = 'unhandled_package';
+ const SOCKET_ERROR_EMPTY_DATA = 'empty_data';
+ const PACKAGE_ERROR_INVALID_DATA = 'invalid_data';
+ const PACKAGE_LEVEL_CHECK_OKAY = 'checked_package';
+
+ /**
+ * Error code from socket
+ */
+ private $errorCode = -1;
+
/**
* Protected constructor
*
// Call parent constructor
parent::__construct($className);
}
+
+ /**
+ * Setter for error code
+ *
+ * @param $errorCode The error code we shall set
+ * @return void
+ */
+ protected final function setErrorCode ($errorCode) {
+ $this->errorCode = $errorCode;
+ }
+
+ /**
+ * Getter for error code
+ *
+ * @return $errorCode The error code
+ */
+ public final function getErrorCode () {
+ return $this->errorCode;
+ }
}
// [EOF]
--- /dev/null
+while (count($clients) > 0) {
+ // create a copy, so $clients doesn't get modified by socket_select()
+ $read = $clients;
+
+ // get a list of all the clients that have data to be read from
+ // if there are no clients with data, go to next iteration
+ $left = @socket_select($read, $write = null, $except = null, 0, 150);
+ if ($left < 1) {
+ continue;
+ }
+
+ // check if there is a client trying to connect
+ if (in_array($mainSocket, $read)) {
+ // accept the client, and add him to the $clients array
+ $new_sock = socket_accept($mainSocket);
+ $clients[] = $new_sock;
+
+ // send the client a welcome message
+ socket_write($new_sock, "No noobs, but I'll make an exception. :)\n".
+ "There are ".(count($clients) - 1)." client(s) connected to the server.\n");
+
+ socket_getpeername($new_sock, $ip);
+ out(__FILE__, __LINE__, '['.date('m/d/Y:H:i:s', time())."]:New client connected: {$ip}");
+
+ // Notify all chatter
+ if (count($clients) > 2) {
+ foreach ($clients as $send_sock) {
+ if ($send_sock != $mainSocket && $send_sock != $new_sock) {
+ socket_write($send_sock, "Server: Chatter has joined from {$ip}. There are now ".(count($clients) - 1)." clients.\n");
+ }
+ }
+ }
+
+ // remove the listening socket from the clients-with-data array
+ $key = array_search($mainSocket, $read);
+ unset($read[$key]);
+ }
+
+ // loop through all the clients that have data to read from
+ foreach ($read as $read_sock) {
+ // Get client data
+ socket_getpeername($read_sock, $ip);
+
+ // read until newline or 1024 bytes
+ // socket_read while show errors when the client is disconnected, so silence the error messages
+ $data = @socket_read($read_sock, 1024, PHP_NORMAL_READ);
+
+ // check if the client is disconnected
+ if (($data === false) || (in_array(strtolower(trim($data)), $leaving))) {
+
+ // remove client for $clients array
+ $key = array_search($read_sock, $clients);
+ unset($clients[$key]);
+ out(__FILE__, __LINE__, '['.date('m/d/Y:H:i:s', time())."]:Client from {$ip} disconnected. Left: ".(count($clients) - 1)."");
+
+ // Notify all chatter
+ if (count($clients) > 1) {
+ foreach ($clients as $send_sock) {
+ if ($send_sock != $mainSocket) {
+ socket_write($send_sock, "Server: Chatter from {$ip} has logged out. ".(count($clients) - 1)." client(s) left.\n");
+ }
+ }
+ }
+
+ // continue to the next client to read from, if any
+ socket_write($read_sock, "Server: Good bye.\n");
+ socket_shutdown($read_sock, 2);
+ socket_close($read_sock);
+ continue;
+ } elseif (in_array(trim($data), $shutdown)) {
+ // Is he allowed to shutdown?
+ if (!in_array($ip, $masters)) {
+ out(__FILE__, __LINE__, '['.date('m/d/Y:H:i:s', time())."]:Client {$ip} has tried to shutdown the server!");
+ socket_write($read_sock, "Server: You are not allowed to shutdown the server!\n");
+ $data = "";
+ continue;
+ }
+
+ // Close all connections a leave here
+ foreach ($clients as $client) {
+ // Send message to client
+ if ($client !== $mainSocket && $client != $read_sock) {
+ socket_write($client, "Server: Shutting down! Thank you for joining us.\n");
+ }
+
+ // Quit him
+ socket_shutdown($client, 2);
+ socket_close($client);
+ } // end foreach
+
+ // Leave the loop
+ $data = "";
+ $clients = array();
+ continue;
+ }
+
+ // trim off the trailing/beginning white spaces
+ $data = trim($data);
+
+ // Test for HTML codes
+ $tags = strip_tags($data);
+
+ // check if there is any data after trimming off the spaces
+ if (!empty($data) && $tags == $data && count($clients) > 2) {
+ // Send confirmation to "chatter"
+ socket_write($read_sock, "\nServer: Message accepted.\n");
+
+ // send this to all the clients in the $clients array (except the first one, which is a listening socket)
+ foreach ($clients as $send_sock) {
+
+ // if its the listening sock or the client that we got the message from, go to the next one in the list
+ if ($send_sock == $mainSocket || $send_sock == $read_sock)
+ continue;
+
+ // write the message to the client -- add a newline character to the end of the message
+ socket_write($send_sock, "{$ip}:{$data}\n");
+
+ } // end of broadcast foreach
+ } elseif ($tags != $data) {
+ // HTML codes are not allowed
+ out(__FILE__, __LINE__, '['.date('m/d/Y:H:i:s', time())."]:Client {$ip} has entered HTML code!");
+ socket_write($read_sock, "Server: HTML is forbidden!\n");
+ } elseif ((count($clients) == 2) && ($read_sock != $mainSocket)) {
+ // No one else will hear the "chatter"
+ out(__FILE__, __LINE__, '['.date('m/d/Y:H:i:s', time())."]:Client {$ip} speaks with himself.");
+ socket_write($read_sock, "Server: No one will hear you!\n");
+ }
+ } // end of reading foreach
+}
+
+// close the listening socket
+socket_close($mainSocket);
+
+?>
+<?php
+/**
+ * A TCP ??? listener
+ *
+ * @author Roland Haeder <webmaster@ship-simu.org>
+ * @version 0.0.0
+ * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 Hub Developer Team
+ * @license GNU GPL 3.0 or any newer version
+ * @link http://www.ship-simu.org
+ *
+ * This program 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 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program 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 this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+class ???Listener extends BaseListener implements Listenable, Visitable {
+ /**
+ * Protected constructor
+ *
+ * @return void
+ */
+ protected function __construct () {
+ // Call parent constructor
+ parent::__construct(__CLASS__);
+ }
+
+ /**
+ * Creates an instance of this class
+ *
+ * @param $nodeInstance A NodeHelper instance
+ * @return $listenerInstance An instance a prepared listener class
+ */
+ public final static function create???Listener (NodeHelper $nodeInstance) {
+ // Get new instance
+ $listenerInstance = new ???Listener();
+
+ // Set the application instance
+ $listenerInstance->setNodeInstance($nodeInstance);
+
+ // Return the prepared instance
+ return $listenerInstance;
+ }
+
+ /**
+ * Initializes the listener by setting up the required socket server
+ *
+ * @return void
+ * @todo 0% done
+ */
+ public function initListener() {
+ $this->partialStub('Need to implement this method.');
+ }
+
+ /**
+ * "Listens" for incoming network packages
+ *
+ * @return void
+ * @todo 0% done
+ */
+ public function doListen() {
+ $this->partialStub('Need to implement this method.');
+ }
+}
+
+// [EOF]
+?>
/**
* Creates an instance of this class
*
- * @return $handlerInstance An instance of a !!! class
+ * @return $handlerInstance An instance of a Networkable class
*/
public final static function createTcpNetworkPackageHandler () {
// Get new instance
$handlerInstance = new TcpNetworkPackageHandler();
+ // Initialize new resolver instance
+ $resolverInstance = ObjectFactory::createObjectByConfiguredName('network_state_resolver_class');
+
+ // Set it in this class
+ $handlerInstance->setResolverInstance($resolverInstance);
+
// Return the prepared instance
return $handlerInstance;
}
+
+ /**
+ * Processes a package from given resource. This is mostly useful for TCP
+ * package handling and is implemented in the TcpListener class
+ *
+ * @param $resource A valid resource identifier
+ * @return void
+ * @throws InvalidResourceException If the given resource is invalid
+ * @todo 0%
+ */
+ public function processResourcePackage ($resource) {
+ // Check the resource
+ if (!is_resource($resource)) {
+ // Throw an exception
+ throw new InvalidResourceException($this, self::EXCEPTION_INVALID_RESOURCE);
+ } // END - if
+
+ // Reset error code to unhandled
+ $this->setErrorCode(self::SOCKET_ERROR_UNHANDLED);
+
+ // Read the raw data from socket
+ $rawData = socket_read($resource, 1500, PHP_BINARY_READ);
+
+ // Is it valid?
+ if (($rawData === false) || (socket_last_error($resource) > 0)) {
+ // Network error or connection lost
+ $this->setErrorCode(socket_last_error($resource));
+ } elseif (empty($rawData)) {
+ // The peer did send nothing to us
+ $this->setErrorCode(self::SOCKET_ERROR_EMPTY_DATA);
+ } elseif (!$this->isPackageDataValid($rawData)) {
+ // Invalid package data
+ $this->setErrorCode(self::PACKAGE_ERROR_INVALID_DATA);
+ } else {
+ // Low-level checks are all green
+ $this->setErrorCode(self::PACKAGE_LEVEL_CHECK_OKAY);
+ }
+
+ // Get a state from the resolver for this package
+ $stateInstance = $this->getResolverInstance()->resolveStateByPackage($this, $rawData);
+ }
}
// [EOF]
/**
* Creates an instance of this class
*
- * @return $handlerInstance An instance of a !!! class
+ * @return $handlerInstance An instance of a Networkable class
*/
public final static function createUdpNetworkPackageHandler () {
// Get new instance
// Return the prepared instance
return $handlerInstance;
}
+
+ /**
+ * Processes a package from given resource. This is mostly useful for TCP
+ * package handling and is implemented in the TcpListener class
+ *
+ * @param $resource A valid resource identifier
+ * @return void
+ * @throws InvalidResourceException If the given resource is invalid
+ * @todo 0%
+ */
+ public function processResourcePackage ($resource) {
+ // Check the resource
+ if (!is_resource($resource)) {
+ // Throw an exception
+ throw new InvalidResourceException($this, self::EXCEPTION_INVALID_RESOURCE);
+ } // END - if
+
+ // Implement processing here
+ $this->partialStub('Please implement this method.');
+ }
}
// [EOF]
--- /dev/null
+Deny from all
--- /dev/null
+<?php
+/**
+ * A Task handler
+ *
+ * @author Roland Haeder <webmaster@ship-simu.org>
+ * @version 0.0.0
+ * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 Hub Developer Team
+ * @license GNU GPL 3.0 or any newer version
+ * @link http://www.ship-simu.org
+ *
+ * This program 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 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program 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 this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+class TaskHandler extends BaseHandler implements Registerable, HandleableTask {
+ /**
+ * Protected constructor
+ *
+ * @return void
+ */
+ protected function __construct () {
+ // Call parent constructor
+ parent::__construct(__CLASS__);
+ }
+
+ /**
+ * Creates an instance of this class
+ *
+ * @return $handlerInstance An instance of a HandleableTask class
+ */
+ public final static function createTaskHandler () {
+ // Get new instance
+ $handlerInstance = new TaskHandler();
+
+ // Output debug message
+ $handlerInstance->debugOutput('TASK-HANDLER: Task handler initialized.');
+
+ // Return the prepared instance
+ return $handlerInstance;
+ }
+
+ /**
+ * Registers a task with a task handler. This method throws a
+ * TaskAlreadyRegisteredException if the task has already been registered
+ *
+ * @param $taskName A task name to register the task on
+ * @param $taskInstance The instance we should register as a task
+ * @return void
+ */
+ public function registerTask ($taskName, Visitable $taskInstance) {
+ $this->partialStub('taskName=' . $taskName . '/' . $taskInstance->__toString());
+ }
+}
+
+// [EOF]
+?>
$current = $this->getIteratorInstance()->current();
// Handle it here
- $this->getPackageInstance()->processPackage($current);
+ $this->getPackageInstance()->processResourcePackage($current);
// Advance to next entry. This should be the last line
$this->getIteratorInstance()->next();
$controllerInstance = Registry::getRegistry()->getInstance('controller');
// Run all filters for the hub activation
- $controllerInstance->executeHubActivationFilters($requestInstance, $responseInstance);
+ $controllerInstance->executeActivationFilters($requestInstance, $responseInstance);
// ----------------------- Last step from here ------------------------
// Activate the hub. This is ALWAYS the last step in this method
*
* @author Roland Haeder <webmaster@ship-simu.org>
* @version 0.0.0
- * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 Core Developer Team
+ * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 Hub Developer Team
* @license GNU GPL 3.0 or any newer version
* @link http://www.ship-simu.org
*
*
* @author Roland Haeder <webmaster@ship-simu.org>
* @version 0.0.0
- * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 Core Developer Team
+ * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 Hub Developer Team
* @license GNU GPL 3.0 or any newer version
* @link http://www.ship-simu.org
*
--- /dev/null
+Deny from all
--- /dev/null
+<?php
+/**
+ * A generic state resolver class
+ *
+ * @author Roland Haeder <webmaster@ship-simu.org>
+ * @version 0.0.0
+ * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 Hub Developer Team
+ * @license GNU GPL 3.0 or any newer version
+ * @link http://www.ship-simu.org
+ *
+ * This program 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 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program 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 this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+class BaseStateResolver extends BaseResolver {
+ /**
+ * Prefix for local, remote or other resolver
+ */
+ private $statePrefix = '';
+
+ /**
+ * Validated state name
+ */
+ private $stateName = '';
+
+ /**
+ * Protected constructor
+ *
+ * @param $className Name of the real class
+ * @return void
+ */
+ protected function __construct ($className) {
+ // Call parent constructor
+ parent::__construct($className);
+ }
+
+ /**
+ * Setter for state prefix
+ *
+ * @param $statePrefix Last validated statePrefix
+ * @return void
+ */
+ protected final function setStatePrefix ($statePrefix) {
+ $this->statePrefix = $statePrefix;
+ }
+
+ /**
+ * Getter for state prefix
+ *
+ * @param $statePrefix Last validated statePrefix
+ * @return void
+ */
+ protected final function getStatePrefix () {
+ return $this->statePrefix;
+ }
+
+ /**
+ * Setter for state name
+ *
+ * @param $stateName Last validated state name
+ * @return void
+ */
+ protected final function setStateName ($stateName) {
+ $this->stateName = $stateName;
+ }
+
+ /**
+ * Getter for state name
+ *
+ * @return $stateName Last validated state name
+ */
+ public final function getStateName () {
+ return $this->stateName;
+ }
+
+ /**
+ * "Loads" a given state and instances it if not yet cached. If the
+ * state was not found an InvalidStateException is thrown
+ *
+ * @param $stateName A state name we shall look for
+ * @return $stateInstance A loaded state instance
+ * @throws InvalidStateException Thrown if even the requested
+ * state class is missing (bad!)
+ */
+ protected function loadState ($stateName) {
+ // Init state instance
+ $stateInstance = null;
+
+ // Create state class name
+ $className = $this->getStatePrefix() . '' . $this->convertToClassName($stateName) . 'State';
+
+ // ... and set it
+ $this->setClassName($className);
+
+ // Is this class loaded?
+ if (!class_exists($this->getClassName())) {
+ // Throw an exception here
+ throw new InvalidStateException(array($this, $stateName), self::EXCEPTION_INVALID_STATE);
+ } // END - if
+
+ // Initialize the state
+ $stateInstance = ObjectFactory::createObjectByName(
+ $this->getClassName(),
+ array($this)
+ );
+
+ // Return the result
+ return $stateInstance;
+ }
+
+ /**
+ * Checks wether the given state is valid
+ *
+ * @param $stateName The default state we shall execute
+ * @return $isValid Wether the given state is valid
+ * @throws EmptyVariableException Thrown if given state is not set
+ * @throws DefaultStateException Thrown if default state was not found
+ */
+ public function isStateValid ($stateName) {
+ // By default nothing shall be valid
+ $isValid = false;
+
+ // Is a state set?
+ if (empty($stateName)) {
+ // Then thrown an exception here
+ throw new EmptyVariableException(array($this, 'stateName'), self::EXCEPTION_UNEXPECTED_EMPTY_STRING);
+ } // END - if
+
+ // Create class name
+ $className = $this->statePrefix . $this->convertToClassName($stateName) . 'State';
+
+ // Now, let us create the full name of the state class
+ $this->setClassName($className);
+
+ // Try it hard to get an state
+ while ($isValid === false) {
+ // Is this class already loaded?
+ if (class_exists($this->getClassName())) {
+ // This class does exist. :-)
+ $isValid = true;
+ } elseif ($this->getClassName() != $this->statePrefix.'DefaultNewsState') {
+ // Set default state
+ $this->setClassName($this->statePrefix . 'DefaultNewsState');
+ } else {
+ // All is tried, give it up here
+ throw new DefaultStateException($this, self::EXCEPTION_DEFAULT_STATE_GONE);
+ }
+ } // END - while
+
+ // Return the result
+ return $isValid;
+ }
+}
+
+// [EOF]
+?>
--- /dev/null
+Deny from all
--- /dev/null
+<?php
+/**
+ * A resolver for resolving states locally
+ *
+ * @author Roland Haeder <webmaster@ship-simu.org>
+ * @version 0.0.0
+ * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 Hub Developer Team
+ * @license GNU GPL 3.0 or any newer version
+ * @link http://www.ship-simu.org
+ *
+ * This program 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 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program 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 this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+class NetworkStateResolver extends BaseStateResolver implements StateResolver {
+ /**
+ * Last successfull resolved state (name)
+ */
+ private $lastStateName = '';
+
+ /**
+ * Last successfull resolved state (instance)
+ */
+ private $lastStateInstance = null;
+
+ /**
+ * Protected constructor
+ *
+ * @return void
+ */
+ protected function __construct () {
+ // Call parent constructor
+ parent::__construct(__CLASS__);
+
+ // Set prefix to 'Network'
+ $this->setStatePrefix('Network');
+ }
+
+ /**
+ * Creates an instance of a resolver class with a given state
+ *
+ * @return $resolverInstance The prepared state resolver instance
+ * @throws EmptyVariableException Thrown if default state is not set
+ * @throws InvalidStateException Thrown if default state is invalid
+ */
+ public final static function createNetworkStateResolver () {
+ // Create the new instance
+ $resolverInstance = new NetworkStateResolver();
+
+ // Return the prepared instance
+ return $resolverInstance;
+ }
+
+ /**
+ * Returns an state instance for a given package class
+ *
+ * @param $packageInstance An instance of a package class
+ * @param $rawData The raw data
+ * @return $stateInstance An instance of the resolved state
+ * @todo 0%
+ */
+ public function resolveStateByPackage (Networkable $packageInstance, $rawData) {
+ // Get error code
+ $errorCode = $packageInstance->getErrorCode();
+
+ // Is the code a number, then we have to change it
+ if ($errorCode == 134) {
+ // Transport endpoint not connected, should be handled else!
+ $errorCode = BaseNetworkPackageHandler::SOCKET_ERROR_TRANSPORT_ENDPOINT;
+ } elseif (is_int($errorCode)) {
+ // Debug output (because we might want to handle it like the above(s)
+ $this->debugOutput(__METHOD__ . ': errorCode=' . $errorCode);
+
+ // Change it only in this class
+ $errorCode = BaseNetworkPackageHandler::SOCKET_ERROR_GENERAL;
+ } // END - if
+
+ $this->partialStub('errorCode='.$errorCode.',rawData[] = '.gettype($rawData).'('.strlen($rawData).')');
+ }
+}
+
+// [EOF]
+?>
--- /dev/null
+Deny from all
*
* @author Roland Haeder <webmaster@ship-simu.org>
* @version 0.0.0
- * @copyright Copyright (c) 2007, 2008 Roland Haeder, this is free software
+ * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 Core Developer Team
* @license GNU GPL 3.0 or any newer version
* @link http://www.ship-simu.org
*