application/hub/main/lists/class_BaseList.php -text
application/hub/main/lists/groups/.htaccess -text
application/hub/main/lists/groups/class_ListGroupList.php -text
+application/hub/main/lists/hub/.htaccess -text
application/hub/main/lists/pool/.htaccess -text
application/hub/main/lists/pool/class_PoolEntriesList.php -text
application/hub/main/lists/query/.htaccess -text
// CFG: RAW-PACKAGE-COMPRESSOR-CLASS
$cfg->setConfigEntry('raw_package_compressor_class', 'GzipCompressor');
+// CFG: HUB-LIST-CLASS
+$cfg->setConfigEntry('hub_list_class', 'HubList');
+
// [EOF]
?>
* @return void
*/
function enqueueRawDataFromTemplate (BaseHubHelper $helperInstance);
+
+ /**
+ * Checks wether a package has been enqueued for delivery.
+ *
+ * @return $isEnqueued Wether a package is enqueued
+ */
+ function isPackageEnqueued ();
+
+ /**
+ * Delivers an enqueued package to the stated destination. If none is
+ * provided, the registered helper class is being iterated until no target
+ * is left. This allows that a single package is being delivered to multiple
+ * targets without enqueueing it for every target. If no target is provided
+ * or it can't be determined a NoTargetException is being thrown.
+ *
+ * @return void
+ * @throws NoTargetException If no target can't be determined
+ */
+ function deliverEnqueuedPackage ();
}
// [EOF]
*
* @return void
*/
- function execute ();
+ function executeTask ();
}
// [EOF]
--- /dev/null
+<?php
+/**
+ * A factory class for network packages
+ *
+ * @author Roland Haeder <webmaster@ship-simu.org>
+ * @version 0.0.0
+ * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009, 2010 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 NetworkPackageFactory extends ObjectFactory {
+ /**
+ * Returns a singleton network package instance. If an instance is found in
+ * the registry it will be returned, else a new instance is created and
+ * stored in the same registry entry.
+ *
+ * @return $packageInstance A network package instance
+ */
+ public static final function createNetworkPackageInstance () {
+ // Do we have an instance in the registry?
+ if (Registry::getRegistry()->instanceExists('network_package')) {
+ // Then use this instance
+ $packageInstance = Registry::getRegistry()->getInstance('network_package');
+ } else {
+ /**
+ * Prepare the compressor for our package, GZIP should be fine but we
+ * keep it open here so you can experiment with the settings and don't
+ * need to touch any code.
+ */
+ $compressorInstance = ObjectFactory::createObjectByConfiguredName('raw_package_compressor_class');
+
+ // Prepare the decorator compressor (for later flawless and easy updates)
+ $compressorInstance = ObjectFactory::createObjectByConfiguredName('deco_package_compressor_class', array($compressorInstance));
+
+ // Now prepare the network package for delivery so only need to do this
+ // once just before the "big announcement loop".
+ $packageInstance = ObjectFactory::createObjectByConfiguredName('network_package_class', array($compressorInstance));
+
+ // Set the instance in registry for further use
+ Registry::getRegistry()->addInstance('network_package', $packageInstance);
+ }
+
+ // Return the instance
+ return $packageInstance;
+ }
+
+ /**
+ * Protected constructor
+ *
+ * @return void
+ */
+ protected function __construct () {
+ // Call parent constructor
+ parent::__construct(__CLASS__);
+ }
+}
+?>
+++ /dev/null
-<?php
-/**
- * A factory class for packages
- *
- * @author Roland Haeder <webmaster@ship-simu.org>
- * @version 0.0.0
- * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009, 2010 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 PackageFactory extends ObjectFactory {
- /**
- * Returns a singleton network package instance. If an instance is found in
- * the registry it will be returned, else a new instance is created and
- * stored in the same registry entry.
- *
- * @return $packageInstance A network package instance
- */
- public static final function createPackageInstance () {
- // Do we have an instance in the registry?
- if (Registry::getRegistry()->instanceExists('network_package')) {
- // Then use this instance
- $packageInstance = Registry::getRegistry()->getInstance('network_package');
- } else {
- /**
- * Prepare the compressor for our package, GZIP should be fine but we
- * keep it open here so you can experiment with the settings and don't
- * need to touch any code.
- */
- $compressorInstance = ObjectFactory::createObjectByConfiguredName('raw_package_compressor_class');
-
- // Prepare the decorator compressor (for later flawless and easy updates)
- $compressorInstance = ObjectFactory::createObjectByConfiguredName('deco_package_compressor_class', array($compressorInstance));
-
- // Now prepare the network package for delivery so only need to do this
- // once just before the "big announcement loop".
- $packageInstance = ObjectFactory::createObjectByConfiguredName('network_package_class', array($compressorInstance));
-
- // Set the instance in registry for further use
- Registry::getRegistry()->addInstance('network_package', $packageInstance);
- }
-
- // Return the instance
- return $packageInstance;
- }
-
- /**
- * Protected constructor
- *
- * @return void
- */
- protected function __construct () {
- // Call parent constructor
- parent::__construct(__CLASS__);
- }
-}
-?>
// Compile the template, this inserts the loaded node data into the gaps.
$this->getTemplateInstance()->compileTemplate();
- // Get a singleton package instance
- $packageInstance = PackageFactory::createPackageInstance();
+ // Get a singleton network package instance
+ $packageInstance = NetworkPackageFactory::createNetworkPackageInstance();
// Next, feed the content in. The network package class is a pipe-through class.
$packageInstance->enqueueRawDataFromTemplate($this);
*
* @return $socketResource The socket resource we shall set
*/
- protected final function getSocketResource () {
+ public final function getSocketResource () {
return $this->socketResource;
}
*/
public function accept (Visitor $visitorInstance) {
// Debug message
- //* DEBUG: */ $this->debugOutput('LISTENER: ' . $visitorInstance->__toString() . ' has visited - START');
+ //* DEBUG: */ $this->debugOutput('LISTENER: ' . $visitorInstance->__toString() . ' has visited ' . $this->__toString() . ' - START');
// Visit this listener
$visitorInstance->visitListener($this);
} // END - if
// Debug message
- //* DEBUG: */ $this->debugOutput('LISTENER: ' . $visitorInstance->__toString() . ' has visited - FINISHED');
+ //* DEBUG: */ $this->debugOutput('LISTENER: ' . $visitorInstance->__toString() . ' has visited ' . $this->__toString() . ' - FINISHED');
}
}
$current = $this->getIteratorInstance()->current();
// Handle it here, if not main socket
- if ($current !== $this->getSocketResource()) {
+ if ($current != $this->getSocketResource()) {
// ... or else it will raise warnings like 'Transport endpoint is not connected'
$this->getPackageInstance()->processResourcePackage($current);
} // END - if
throw new InvalidSocketException(array($this, gettype($socket), $errno, $errstr), BaseListener::EXCEPTION_INVALID_SOCKET);
} // END - if
+ // Now, we want non-blocking mode
+ $this->debugOutput('LISTENER: Setting non-blocking mode.');
+ if (!stream_set_blocking($socket, false)) {
+ // Get socket error code for verification
+ $socketError = socket_last_error($socket);
+
+ // Get error message
+ $errorMessage = socket_strerror($socketError);
+
+ // Shutdown this socket
+ $this->shutdownSocket($socket);
+
+ // And throw again
+ throw new InvalidSocketException(array($this, gettype($socket), $socketError, $errorMessage), BaseListener::EXCEPTION_INVALID_SOCKET);
+ } // END - if
+
// Remember the socket in our class
$this->setSocketResource($socket);
* "Listens" for incoming network packages
*
* @return void
- * @todo 0% done
+ * @todo ~50% done
*/
public function doListen() {
- $this->partialStub('Need to implement this method.');
+ // Read a package and determine the client
+ $pkt = trim(stream_socket_recvfrom($this->getSocketResource(), 1500, 0, $peer));
+
+ // Zero sized packages/peer names are usual in non-blocking mode
+ if ((empty($pkt)) || (trim($peer) == '')) {
+ // Skip here
+ return;
+ } // END - if
+
+ // Debug only
+ $this->debugOutput('LISTENER: Handling UDP package with size ' . strlen($pkt) . ' from peer ' . $peer);
}
}
--- /dev/null
+Deny from all
--- /dev/null
+<?php
+/**
+ * A Hub list
+ *
+ * @author Roland Haeder <webmaster@ship-simu.org>
+ * @version 0.0.0
+ * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009, 2010 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 HubList extends BaseList implements Listable {
+ /**
+ * Protected constructor
+ *
+ * @return void
+ */
+ protected function __construct () {
+ // Call parent constructor
+ parent::__construct(__CLASS__);
+ }
+
+ /**
+ * Creates an instance of this class
+ *
+ * @return $listInstance An instance a Listable class
+ */
+ public final static function createHubList () {
+ // Get new instance
+ $listInstance = new HubList();
+
+ // Add groups for e.g. connected/disconnected hubs
+ $listInstance->addGroup('connected');
+ $listInstance->addGroup('disconnected');
+
+ // Return the prepared instance
+ return $listInstance;
+ }
+}
+
+// [EOF]
+?>
*/
private $isActive = false;
+ /**
+ * List instance of all hubs
+ */
+ private $hubsInstance = false;
+
/**
* Protected constructor
*
// Call parent constructor
parent::__construct($className);
+ // Init list for connected hubs
+ $this->hubsInstance = ObjectFactory::createObjectByConfiguredName('hub_list_class');
+
// Init state which sets the state to 'init'
$this->initState();
}
'callback' => $helperInstance
));
}
+
+ /**
+ * Checks wether a package has been enqueued for delivery.
+ *
+ * @return $isEnqueued Wether a package is enqueued
+ */
+ public function isPackageEnqueued () {
+ // Check wether the stacker is not empty
+ $isEnqueued = (($this->getStackerInstance()->isStackInitialized(self::STACKER_NAME_UNDECLARED)) && (!$this->getStackerInstance()->isStackEmpty(self::STACKER_NAME_UNDECLARED)));
+
+ // Return the result
+ return $isEnqueued;
+ }
+
+ /**
+ * Delivers an enqueued package to the stated destination. If none is
+ * provided, the registered helper class is being iterated until no target
+ * is left. This allows that a single package is being delivered to multiple
+ * targets without enqueueing it for every target. If no target is provided
+ * or it can't be determined a NoTargetException is being thrown.
+ *
+ * @return void
+ * @throws NoTargetException If no target can't be determined
+ */
+ public function deliverEnqueuedPackage () {
+ $this->partialStub('Please implement this method.');
+ }
}
// [EOF]
// Validate the socket
$this->validateSocket($socketResource);
+ // Default is this peer's IP
+ $peerName = '0.0.0.0';
+
+ // The socket resource should not match server socket
+ if ($socketResource != $this->getListenerInstance()->getSocketResource()) {
+ // Try to determine the peer's IP number
+ if (!socket_getpeername($socketResource, $peerName)) {
+ // Get last error
+ $lastError = socket_last_error($socketResource);
+
+ // Doesn't work!
+ throw new InvalidSocketException(array($this, gettype($socketResource), $lastError, socket_strerror($lastError)), BaseListener::EXCEPTION_INVALID_SOCKET);
+ } // END - if
+ } else {
+ // Server sockets won't work with socket_getpeername()
+ $this->debugOutput('POOL: Socket resource is server socket. This is no bug.');
+ }
+
// Output error message
- $this->debugOutput('POOL: Adding client ' . $socketResource);
+ $this->debugOutput('POOL: Adding client ' . $peerName);
// Add it finally to the pool
$this->addPoolEntry($socketResource);
*
* @return void
*/
- public function execute () {
+ public function executeTask () {
// Get the node instance and announce us
Registry::getRegistry()->getInstance('node')->announceSelfToUpperNodes($this);
}
*
* @return void
*/
- public function execute () {
+ public function executeTask () {
$this->partialStub('Unimplemented task.');
}
}
*
* @return void
*/
- public function execute () {
+ public function executeTask () {
$this->partialStub('Unimplemented task.');
}
}
*
* @return void
*/
- public function execute () {
+ public function executeTask () {
$this->partialStub('Unimplemented task.');
}
}
*
* @return void
*/
- public function execute () {
+ public function executeTask () {
// Idle here a little (2 milliseconds)
$this->idle(2);
}
*
* @param $visitorInstance An instance of a Visitor class
* @return void
- * @todo 0%
*/
public function accept (Visitor $visitorInstance) {
// Visit this task
* Executes the task
*
* @return void
+ * @todo 0%
*/
- public function execute () {
- $this->partialStub('Unimplemented task.');
+ public function executeTask () {
+ // Get a singleton network package instance
+ $packageInstance = NetworkPackageFactory::createNetworkPackageInstance();
+
+ // Do we have something to deliver?
+ if ($packageInstance->isPackageEnqueued()) {
+ // Okay, then deliver this package
+ $packageInstance->deliverEnqueuedPackage();
+ } // END - if
}
}
*/
public function visitTask (Taskable $taskInstance) {
// Execute the task from this visitor
- $taskInstance->execute();
+ //* DEBUG: */ $this->debugOutput('VISITOR: Visiting task ' . $taskInstance->__toString() . ' - START');
+ $taskInstance->executeTask();
+ //* DEBUG: */ $this->debugOutput('VISITOR: Visiting task ' . $taskInstance->__toString() . ' - FINISHED');
}
/**
* @return void
*/
public function visitDecorator (BaseDecorator $decoratorInstance) {
- // A decorator itself can never bevome an active task so this method
+ // A decorator itself can never become an active task so this method
// remains empty.
}
}