3 * A general hub system class
5 * @author Roland Haeder <webmaster@ship-simu.org>
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
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.
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.
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/>.
24 class BaseHubSystem extends BaseFrameworkSystem {
26 * An instance of a node
28 private $nodeInstance = null;
31 * An instance of a cruncher
33 private $cruncherInstance = null;
38 private $listenerInstance = null;
41 * A network package handler instance
43 private $packageInstance = null;
48 private $stateInstance = null;
51 * Protected constructor
53 * @param $className Name of the class
56 protected function __construct ($className) {
57 // Call parent constructor
58 parent::__construct($className);
62 * Getter for node instance
64 * @return $nodeInstance An instance of a node node
66 public final function getNodeInstance () {
67 return $this->nodeInstance;
71 * Setter for node instance
73 * @param $nodeInstance An instance of a node node
76 protected final function setNodeInstance (NodeHelper $nodeInstance) {
77 $this->nodeInstance = $nodeInstance;
81 * Getter for cruncher instance
83 * @return $cruncherInstance An instance of a cruncher cruncher
85 public final function getCruncherInstance () {
86 return $this->cruncherInstance;
90 * Setter for cruncher instance
92 * @param $cruncherInstance An instance of a cruncher cruncher
95 protected final function setCruncherInstance (CruncherHelper $cruncherInstance) {
96 $this->cruncherInstance = $cruncherInstance;
100 * Setter for listener instance
102 * @param $listenerInstance A Listenable instance
105 protected final function setListenerInstance (Listenable $listenerInstance) {
106 $this->listenerInstance = $listenerInstance;
110 * Getter for listener instance
112 * @return $listenerInstance A Listenable instance
114 protected final function getListenerInstance () {
115 return $this->listenerInstance;
119 * Setter for network package handler instance
121 * @param $packageInstance The network package handler instance we shall set
124 protected final function setPackageInstance (Networkable $packageInstance) {
125 $this->packageInstance = $packageInstance;
129 * Getter for network package handler instance
131 * @return $packageInstance The network package handler instance we shall set
133 protected final function getPackageInstance () {
134 return $this->packageInstance;
138 * Setter for state instance
140 * @param $stateInstance A Stateable instance
143 public final function setStateInstance (Stateable $stateInstance) {
144 $this->stateInstance = $stateInstance;
148 * Getter for state instance
150 * @return $stateInstance A Stateable instance
152 public final function getStateInstance () {
153 return $this->stateInstance;
157 * Shuts down a given socket resource. This method does only ease calling
160 * @param $socketResource A valid socket resource
163 public function shutdownSocket ($socketResource) {
165 $this->debugOutput('Shutting down socket ' . $socketResource . ' ...');
167 // Set socket resource
168 $this->setSocketResource($socketResource);
170 // Get a visitor instance
171 $visitorInstance = ObjectFactory::createObjectByConfiguredName('shutdown_socket_visitor_class');
174 $this->accept($visitorInstance);
178 * "Getter" for a printable state name
180 * @return $stateName Name of the node's state in a printable format
182 public final function getPrintableState () {
186 // Get the state instance
187 $stateInstance = $this->getStateInstance();
189 // Is it an instance of Stateable?
190 if ($stateInstance instanceof Stateable) {
191 // Then use that state name
192 $stateName = $stateInstance->getStateName();