]> git.mxchange.org Git - hub.git/blobdiff - application/hub/main/class_BaseHubSystem.php
Cruncher continued and rewritten to use states:
[hub.git] / application / hub / main / class_BaseHubSystem.php
index 53ed8c0525904600fcff52a4358f64956e25cfae..bb5df64688ba06a950efd2bbacc5dde81603b7b9 100644 (file)
@@ -4,7 +4,7 @@
  *
  * @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 - 2011 Hub Developer Team
  * @license            GNU GPL 3.0 or any newer version
  * @link               http://www.ship-simu.org
  *
@@ -27,6 +27,26 @@ class BaseHubSystem extends BaseFrameworkSystem {
         */
        private $nodeInstance = null;
 
+       /**
+        * An instance of a cruncher
+        */
+       private $cruncherInstance = null;
+
+       /**
+        * Listener instance
+        */
+       private $listenerInstance = null;
+
+       /**
+        * A network package handler instance
+        */
+       private $packageInstance = null;
+
+       /**
+        * State instance
+        */
+       private $stateInstance = null;
+
        /**
         * Protected constructor
         *
@@ -36,10 +56,15 @@ class BaseHubSystem extends BaseFrameworkSystem {
        protected function __construct ($className) {
                // Call parent constructor
                parent::__construct($className);
+       }
 
-               // Clean up a little
-               $this->removeNumberFormaters();
-               $this->removeSystemArray();
+       /**
+        * Getter for node instance
+        *
+        * @return      $nodeInstance   An instance of a node node
+        */
+       public final function getNodeInstance () {
+               return $this->nodeInstance;
        }
 
        /**
@@ -53,12 +78,122 @@ class BaseHubSystem extends BaseFrameworkSystem {
        }
 
        /**
-        * Getter for node instance
+        * Getter for cruncher instance
         *
-        * @return      $nodeInstance   An instance of a node node
+        * @return      $cruncherInstance       An instance of a cruncher cruncher
         */
-       public final function getNodeInstance () {
-               return $this->nodeInstance;
+       public final function getCruncherInstance () {
+               return $this->cruncherInstance;
+       }
+
+       /**
+        * Setter for cruncher instance
+        *
+        * @param       $cruncherInstance       An instance of a cruncher cruncher
+        * @return      void
+        */
+       protected final function setCruncherInstance (CruncherHelper $cruncherInstance) {
+               $this->cruncherInstance = $cruncherInstance;
+       }
+
+       /**
+        * Setter for listener instance
+        *
+        * @param       $listenerInstance       A Listenable instance
+        * @return      void
+        */
+       protected final function setListenerInstance (Listenable $listenerInstance) {
+               $this->listenerInstance = $listenerInstance;
+       }
+
+       /**
+        * Getter for listener instance
+        *
+        * @return      $listenerInstance       A Listenable instance
+        */
+       protected final function getListenerInstance () {
+               return $this->listenerInstance;
+       }
+
+       /**
+        * Setter for network package handler instance
+        *
+        * @param       $packageInstance        The network package handler instance we shall set
+        * @return      void
+        */
+       protected final function setPackageInstance (Networkable $packageInstance) {
+               $this->packageInstance = $packageInstance;
+       }
+
+       /**
+        * Getter for network package handler instance
+        *
+        * @return      $packageInstance        The network package handler instance we shall set
+        */
+       protected final function getPackageInstance () {
+               return $this->packageInstance;
+       }
+
+       /**
+        * Setter for state instance
+        *
+        * @param       $stateInstance  A Stateable instance
+        * @return      void
+        */
+       public final function setStateInstance (Stateable $stateInstance) {
+               $this->stateInstance = $stateInstance;
+       }
+
+       /**
+        * Getter for state instance
+        *
+        * @return      $stateInstance  A Stateable instance
+        */
+       public final function getStateInstance () {
+               return $this->stateInstance;
+       }
+
+       /**
+        * Shuts down a given socket resource. This method does only ease calling
+        * the right visitor.
+        *
+        * @param       $socketResource         A valid socket resource
+        * @return      void
+        */
+       public function shutdownSocket ($socketResource) {
+               // Debug message
+               $this->debugOutput('Shutting down socket ' . $socketResource . ' ...');
+
+               // Set socket resource
+               $this->setSocketResource($socketResource);
+
+               // Get a visitor instance
+               $visitorInstance = ObjectFactory::createObjectByConfiguredName('shutdown_socket_visitor_class');
+
+               // Call the visitor
+               $this->accept($visitorInstance);
+       }
+
+       /**
+        * "Getter" for a printable state name
+        *
+        * @return      $stateName      Name of the node's state in a printable format
+        */
+       public final function getPrintableState () {
+               // Default is 'null'
+               $stateName = 'null';
+
+               // Get the state instance
+               $stateInstance = $this->getStateInstance();
+
+               // Is it an instance of Stateable?
+               if ($stateInstance instanceof Stateable) {
+                       // Then use that state name
+                       $stateName = $stateInstance->getStateName();
+               } // END - if
+
+               // Return result
+               return $stateName;
        }
 }