5 * @author Roland Haeder <webmaster@ship-simu.org>
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
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 SocketRegistry extends BaseRegistry implements Register, RegisterableSocket {
25 // Exception constants
26 const SOCKET_NOT_REGISTERED = 0xd00;
29 * Instance of this class
31 private static $registryInstance = null;
34 * Protected constructor
38 protected function __construct () {
39 // Call parent constructor
40 parent::__construct(__CLASS__);
44 * Singleton getter for self instance. This class has no factory pattern
45 * because here is no need for special parameters.
47 * @return $registryInstance Instance of this class
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();
56 // Return the instance
57 return self::$registryInstance;
61 * Checks wether given socket resource is registered. If $socketResource is
62 * false only the instance will be checked.
64 * @param $protocolInstance An instance of a ProtocolHandler class
65 * @param $socketResource A valid socket resource
66 * @return $isRegistered Wether the given socket resource is registered
68 public function isSocketRegistered (ProtocolHandler $protocolInstance, $socketResource) {
69 $this->partialStub('Not yet implemented.');
73 * Registeres given socket for listener or throws an exception if it is already registered
75 * @param $protocolInstance An instance of a ProtocolHandler class
76 * @param $socketResource A valid socket resource
77 * @throws SocketAlreadyRegisteredException If the given socket is already registered
80 public function registerSocket (ProtocolHandler $protocolInstance, $socketResource) {
81 // Is the socket already registered?
82 if ($this->isSocketRegistered($protocolInstance, $socketResource)) {
83 // Throw the exception
84 throw new SocketAlreadyRegisteredException($protocolInstance, BaseListener::EXCEPTION_SOCKET_ALREADY_REGISTERED);
87 $this->partialStub('Not yet implemented.');
91 * Getter for given listener's socket resource
93 * @param $protocolInstance An instance of a ProtocolHandler class
94 * @return $socketResource A valid socket resource
95 * @throws NoSocketRegisteredException If the requested socket is not registered
97 public function getSocketResource (ProtocolHandler $protocolInstance) {
98 // The socket must be registered before we can return it
99 if (!$this->isSocketRegistered($protocolInstance, false)) {
100 // Throw the exception
101 throw new NoSocketRegisteredException ($protocolInstance, self::SOCKET_NOT_REGISTERED);
104 $this->partialStub('Not yet implemented.');