]> 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 6a4608d536dee8c12a4edb7ffa07f14ec3c35ba1..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, 2010 Hub 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,11 +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
         *
@@ -43,6 +58,44 @@ class BaseHubSystem extends BaseFrameworkSystem {
                parent::__construct($className);
        }
 
+       /**
+        * Getter for node instance
+        *
+        * @return      $nodeInstance   An instance of a node node
+        */
+       public final function getNodeInstance () {
+               return $this->nodeInstance;
+       }
+
+       /**
+        * Setter for node instance
+        *
+        * @param       $nodeInstance   An instance of a node node
+        * @return      void
+        */
+       protected final function setNodeInstance (NodeHelper $nodeInstance) {
+               $this->nodeInstance = $nodeInstance;
+       }
+
+       /**
+        * Getter for cruncher instance
+        *
+        * @return      $cruncherInstance       An instance of a cruncher cruncher
+        */
+       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
         *
@@ -63,22 +116,84 @@ class BaseHubSystem extends BaseFrameworkSystem {
        }
 
        /**
-        * Setter for node instance
+        * Setter for network package handler instance
         *
-        * @param       $nodeInstance   An instance of a node node
+        * @param       $packageInstance        The network package handler instance we shall set
         * @return      void
         */
-       protected final function setNodeInstance (NodeHelper $nodeInstance) {
-               $this->nodeInstance = $nodeInstance;
+       protected final function setPackageInstance (Networkable $packageInstance) {
+               $this->packageInstance = $packageInstance;
        }
 
        /**
-        * Getter for node instance
+        * Getter for network package handler instance
         *
-        * @return      $nodeInstance   An instance of a node node
+        * @return      $packageInstance        The network package handler instance we shall set
         */
-       public final function getNodeInstance () {
-               return $this->nodeInstance;
+       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;
        }
 }