]> git.mxchange.org Git - hub.git/blob - application/hub/main/resolver/state/network/class_NetworkStateResolver.php
The packageData array should be used for handling package data
[hub.git] / application / hub / main / resolver / state / network / class_NetworkStateResolver.php
1 <?php
2 /**
3  * A resolver for resolving states locally
4  *
5  * @author              Roland Haeder <webmaster@ship-simu.org>
6  * @version             0.0.0
7  * @copyright   Copyright (c) 2007, 2008 Roland Haeder, 2009, 2010 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 NetworkStateResolver extends BaseStateResolver implements StateResolver {
25         /**
26          * Last successfull resolved state (name)
27          */
28         private $lastStateName = '';
29
30         /**
31          * Last successfull resolved state (instance)
32          */
33         private $lastStateInstance = null;
34
35         /**
36          * Protected constructor
37          *
38          * @return      void
39          */
40         protected function __construct () {
41                 // Call parent constructor
42                 parent::__construct(__CLASS__);
43
44                 // Set prefix to 'Network'
45                 $this->setStatePrefix('Network');
46         }
47
48         /**
49          * Creates an instance of a resolver class with a given state
50          *
51          * @return      $resolverInstance       The prepared state resolver instance
52          */
53         public final static function createNetworkStateResolver () {
54                 // Create the new instance
55                 $resolverInstance = new NetworkStateResolver();
56
57                 // Return the prepared instance
58                 return $resolverInstance;
59         }
60
61         /**
62          * Returns an state instance for a given package class
63          *
64          * @param       $packageInstance        An instance of a package class
65          * @param       $packageData            Raw package data
66          * @return      $stateInstance          An instance of the resolved state
67          * @todo        ~30% done
68          */
69         public function resolveStateByPackage (Networkable $packageInstance, array $packageData) {
70                 // Init state instance
71                 $stateInstance = null;
72
73                 // Get error code
74                 $errorCode = $packageInstance->getErrorCode();
75
76                 // Is the code a number, then we have to change it
77                 if (($errorCode == 134) || ($errorCode == 107)) {
78                         // Transport endpoint not connected, should be handled else!
79                         // @TODO On some systems it is 134, on some 107?
80                         $errorCode = BaseNetworkPackageHandler::SOCKET_ERROR_TRANSPORT_ENDPOINT;
81                 } elseif (is_int($errorCode)) {
82                         // Debug output (because we might want to handle it like the above(s)
83                         $this->debugOutput(__METHOD__ . ': UNKNOWN ERROR CODE = ' . $errorCode, ', MESSAGE = ' . socket_strerror($errorCode));
84
85                         // Change it only in this class
86                         $errorCode = BaseNetworkPackageHandler::SOCKET_ERROR_UNKNOWN;
87                 } // END - if
88
89                 // @TODO We need to somehow detect the state/status of the remote peer and still maintain good speed.
90                 // @TODO So maybe some pre-instancing of classes might help here to speedup this I/O intensive process.
91                 $this->partialStub('errorCode=' . $errorCode . ',rawData[] = ' . gettype($rawData) . '(' . count($rawData) . ')');
92
93                 // Return the prepared instance
94                 return $stateInstance;
95         }
96 }
97
98 // [EOF]
99 ?>