b23086f811faadf165e879ad551269cf64c0717c
[core.git] / inc / classes / main / registry / socket / class_SocketRegistry.php
1 <?php
2 /**
3  * A Socket registry
4  *
5  * @author              Roland Haeder <webmaster@ship-simu.org>
6  * @version             0.0.0
7  * @copyright   Copyright (c) 2007, 2008 Roland Haeder, 2009, 2010 Core 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 SocketRegistry extends BaseRegistry implements Register, RegisterableSocket {
25         // Exception constants
26         const SOCKET_NOT_REGISTERED = 0xd00;
27
28         /**
29          * Instance of this class
30          */
31         private static $registryInstance = null;
32
33         /**
34          * Protected constructor
35          *
36          * @return      void
37          */
38         protected function __construct () {
39                 // Call parent constructor
40                 parent::__construct(__CLASS__);
41         }
42
43         /**
44          * Singleton getter for self instance. This class has no factory pattern
45          * because here is no need for special parameters.
46          *
47          * @return      $registryInstance       Instance of this class
48          */
49         public final static function createSocketRegistry () {
50                 // Is an instance there?
51                 if (is_null(self::$registryInstance)) {
52                         // Not yet, so create one
53                         self::$registryInstance = new SocketRegistry();
54                 } // END - if
55
56                 // Return the instance
57                 return self::$registryInstance;
58         }
59
60         /**
61          * Checks wether given socket resource is registered. If $socketResource is
62          * false only the instance will be checked.
63          *
64          * @param       $listenerInstance       An instance of a Listenable class
65          * @param       $socketResource         A valid socket resource
66          * @return      $isRegistered           Wether the given socket resource is registered
67          */
68         public function isSocketRegistered (Listenable $listenerInstance, $socketResource) {
69                 $this->partialStub('Not yet implemented.');
70         }
71
72         /**
73          * Registeres given socket for listener or throws an exception if it is already registered
74          *
75          * @param       $listenerInstance       An instance of a Listenable class
76          * @param       $socketResource         A valid socket resource
77          * @throws      SocketAlreadyRegisteredException        If the given socket is already registered
78          * @return      void
79          */
80         public function registerSocket (Listenable $listenerInstance, $socketResource) {
81                 // Is the socket already registered?
82                 if ($this->isSocketRegistered($listenerInstance, $socketResource)) {
83                         // Throw the exception
84                         throw new SocketAlreadyRegisteredException($listenerInstance, BaseListener::EXCEPTION_SOCKET_ALREADY_REGISTERED);
85                 } // END - if
86
87                 $this->partialStub('Not yet implemented.');
88         }
89
90         /**
91          * Getter for given listener's socket resource
92          *
93          * @param       $listenerInstance       An instance of a Listenable class
94          * @return      $socketResource         A valid socket resource
95          * @throws      NoSocketRegisteredException             If the requested socket is not registered
96          */
97         public function getSocketResource (Listenable $listenerInstance) {
98                 // The socket must be registered before we can return it
99                 if (!$this->isSocketRegistered($listenerInstance, false)) {
100                         // Throw the exception
101                         throw new NoSocketRegisteredException ($listenerInstance, self::SOCKET_NOT_REGISTERED);
102                 } // END - if
103
104                 $this->partialStub('Not yet implemented.');
105         }
106 }
107
108 // [EOF]
109 ?>