]> git.mxchange.org Git - hub.git/blob - application/hub/main/class_BaseHubSystem.php
Cruncher continued and rewritten to use states:
[hub.git] / application / hub / main / class_BaseHubSystem.php
1 <?php
2 /**
3  * A general hub system class
4  *
5  * @author              Roland Haeder <webmaster@ship-simu.org>
6  * @version             0.0.0
7  * @copyright   Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2011 Hub Developer Team
8  * @license             GNU GPL 3.0 or any newer version
9  * @link                http://www.ship-simu.org
10  *
11  * This program is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU General Public License as published by
13  * the Free Software Foundation, either version 3 of the License, or
14  * (at your option) any later version.
15  *
16  * This program is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19  * GNU General Public License for more details.
20  *
21  * You should have received a copy of the GNU General Public License
22  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
23  */
24 class BaseHubSystem extends BaseFrameworkSystem {
25         /**
26          * An instance of a node
27          */
28         private $nodeInstance = null;
29
30         /**
31          * An instance of a cruncher
32          */
33         private $cruncherInstance = null;
34
35         /**
36          * Listener instance
37          */
38         private $listenerInstance = null;
39
40         /**
41          * A network package handler instance
42          */
43         private $packageInstance = null;
44
45         /**
46          * State instance
47          */
48         private $stateInstance = null;
49
50         /**
51          * Protected constructor
52          *
53          * @param       $className      Name of the class
54          * @return      void
55          */
56         protected function __construct ($className) {
57                 // Call parent constructor
58                 parent::__construct($className);
59         }
60
61         /**
62          * Getter for node instance
63          *
64          * @return      $nodeInstance   An instance of a node node
65          */
66         public final function getNodeInstance () {
67                 return $this->nodeInstance;
68         }
69
70         /**
71          * Setter for node instance
72          *
73          * @param       $nodeInstance   An instance of a node node
74          * @return      void
75          */
76         protected final function setNodeInstance (NodeHelper $nodeInstance) {
77                 $this->nodeInstance = $nodeInstance;
78         }
79
80         /**
81          * Getter for cruncher instance
82          *
83          * @return      $cruncherInstance       An instance of a cruncher cruncher
84          */
85         public final function getCruncherInstance () {
86                 return $this->cruncherInstance;
87         }
88
89         /**
90          * Setter for cruncher instance
91          *
92          * @param       $cruncherInstance       An instance of a cruncher cruncher
93          * @return      void
94          */
95         protected final function setCruncherInstance (CruncherHelper $cruncherInstance) {
96                 $this->cruncherInstance = $cruncherInstance;
97         }
98
99         /**
100          * Setter for listener instance
101          *
102          * @param       $listenerInstance       A Listenable instance
103          * @return      void
104          */
105         protected final function setListenerInstance (Listenable $listenerInstance) {
106                 $this->listenerInstance = $listenerInstance;
107         }
108
109         /**
110          * Getter for listener instance
111          *
112          * @return      $listenerInstance       A Listenable instance
113          */
114         protected final function getListenerInstance () {
115                 return $this->listenerInstance;
116         }
117
118         /**
119          * Setter for network package handler instance
120          *
121          * @param       $packageInstance        The network package handler instance we shall set
122          * @return      void
123          */
124         protected final function setPackageInstance (Networkable $packageInstance) {
125                 $this->packageInstance = $packageInstance;
126         }
127
128         /**
129          * Getter for network package handler instance
130          *
131          * @return      $packageInstance        The network package handler instance we shall set
132          */
133         protected final function getPackageInstance () {
134                 return $this->packageInstance;
135         }
136
137         /**
138          * Setter for state instance
139          *
140          * @param       $stateInstance  A Stateable instance
141          * @return      void
142          */
143         public final function setStateInstance (Stateable $stateInstance) {
144                 $this->stateInstance = $stateInstance;
145         }
146
147         /**
148          * Getter for state instance
149          *
150          * @return      $stateInstance  A Stateable instance
151          */
152         public final function getStateInstance () {
153                 return $this->stateInstance;
154         }
155
156         /**
157          * Shuts down a given socket resource. This method does only ease calling
158          * the right visitor.
159          *
160          * @param       $socketResource         A valid socket resource
161          * @return      void
162          */
163         public function shutdownSocket ($socketResource) {
164                 // Debug message
165                 $this->debugOutput('Shutting down socket ' . $socketResource . ' ...');
166
167                 // Set socket resource
168                 $this->setSocketResource($socketResource);
169
170                 // Get a visitor instance
171                 $visitorInstance = ObjectFactory::createObjectByConfiguredName('shutdown_socket_visitor_class');
172
173                 // Call the visitor
174                 $this->accept($visitorInstance);
175         }
176
177         /**
178          * "Getter" for a printable state name
179          *
180          * @return      $stateName      Name of the node's state in a printable format
181          */
182         public final function getPrintableState () {
183                 // Default is 'null'
184                 $stateName = 'null';
185
186                 // Get the state instance
187                 $stateInstance = $this->getStateInstance();
188
189                 // Is it an instance of Stateable?
190                 if ($stateInstance instanceof Stateable) {
191                         // Then use that state name
192                         $stateName = $stateInstance->getStateName();
193                 } // END - if
194
195                 // Return result
196                 return $stateName;
197         }
198 }
199
200 // [EOF]
201 ?>