From ffa45cc277ea3b09d12553e4257352a88b30f2c9 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Roland=20H=C3=A4der?= Date: Tue, 7 Jul 2009 19:05:07 +0000 Subject: [PATCH] Listener classes added, setter/getter added --- .gitattributes | 4 + application/hub/interfaces/listener/.htaccess | 1 + .../interfaces/listener/class_Listenable.php | 28 +++++++ .../hub/main/listener/class_BaseListener.php | 73 +++++++++++++++++++ .../main/listener/tcp/class_TcpListener.php | 54 ++++++++++++++ .../main/listener/udp/class_UdpListener.php | 54 ++++++++++++++ 6 files changed, 214 insertions(+) create mode 100644 application/hub/interfaces/listener/.htaccess create mode 100644 application/hub/interfaces/listener/class_Listenable.php create mode 100644 application/hub/main/listener/tcp/class_TcpListener.php create mode 100644 application/hub/main/listener/udp/class_UdpListener.php diff --git a/.gitattributes b/.gitattributes index 9f1b7ac6a..f8514f59f 100644 --- a/.gitattributes +++ b/.gitattributes @@ -12,6 +12,8 @@ application/hub/init.php -text application/hub/interfaces/.htaccess -text application/hub/interfaces/connectors/.htaccess -text application/hub/interfaces/connectors/class_Connectable.php -text +application/hub/interfaces/listener/.htaccess -text +application/hub/interfaces/listener/class_Listenable.php -text application/hub/interfaces/nodes/.htaccess -text application/hub/interfaces/nodes/class_NodeHelper.php -text application/hub/interfaces/pool/.htaccess -text @@ -42,7 +44,9 @@ application/hub/main/listener/.htaccess -text application/hub/main/listener/class_ -text application/hub/main/listener/class_BaseListener.php -text application/hub/main/listener/tcp/.htaccess -text +application/hub/main/listener/tcp/class_TcpListener.php -text application/hub/main/listener/udp/.htaccess -text +application/hub/main/listener/udp/class_UdpListener.php -text application/hub/main/nodes/.htaccess -text application/hub/main/nodes/boot/.htaccess -text application/hub/main/nodes/boot/class_HubBootNode.php -text diff --git a/application/hub/interfaces/listener/.htaccess b/application/hub/interfaces/listener/.htaccess new file mode 100644 index 000000000..3a4288278 --- /dev/null +++ b/application/hub/interfaces/listener/.htaccess @@ -0,0 +1 @@ +Deny from all diff --git a/application/hub/interfaces/listener/class_Listenable.php b/application/hub/interfaces/listener/class_Listenable.php new file mode 100644 index 000000000..334c3bef7 --- /dev/null +++ b/application/hub/interfaces/listener/class_Listenable.php @@ -0,0 +1,28 @@ + + * @version 0.0.0 + * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 Core Developer Team + * @license GNU GPL 3.0 or any newer version + * @link http://www.ship-simu.org + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +interface Listenable extends FrameworkInterface { +} + +// +?> diff --git a/application/hub/main/listener/class_BaseListener.php b/application/hub/main/listener/class_BaseListener.php index ababd57ed..f86ff5100 100644 --- a/application/hub/main/listener/class_BaseListener.php +++ b/application/hub/main/listener/class_BaseListener.php @@ -22,6 +22,21 @@ * along with this program. If not, see . */ class BaseListener extends BaseHubSystem { + /** + * Address (IP mostly) we shall listen on + */ + private $listenAddress = '0.0.0.0'; // This is the default and listens on all interfaces + + /** + * Port we shall listen on (or wait for incoming data) + */ + private $listenPort = 0; // This port MUST be changed by your application + + /** + * Wether we are in blocking or non-blocking mode (default: non-blocking + */ + private $blockingMode = false; + /** * Protected constructor * @@ -32,6 +47,64 @@ class BaseListener extends BaseHubSystem { // Call parent constructor parent::__construct($className); } + + /** + * Setter for listen address + * + * @param $listenAddress The address this listener should listen on + * @return void + */ + protected final function setListenAddress ($listenAddress) { + $this->listenAddress = (string) $listenAddress; + } + + /** + * Getter for listen address + * + * @return $listenAddress The address this listener should listen on + */ + public final function getListenAddress () { + return $this->listenAddress; + } + + /** + * Setter for listen port + * + * @param $listenPort The port this listener should listen on + * @return void + */ + protected final function setListenPort ($listenPort) { + $this->listenPort = (int) $listenPort; + } + + /** + * Getter for listen port + * + * @return $listenPort The port this listener should listen on + */ + public final function getListenPort () { + return $this->listenPort; + } + + /** + * "Setter" to set listen address from configuration entry + * + * @param $configEntry The configuration entry holding our listen address + * @return void + */ + public final function setListenAddressByConfiguration ($configEntry) { + $this->setListenAddress($this->getConfigInstance()->readConfig($configEntry)); + } + + /** + * "Setter" to set listen port from configuration entry + * + * @param $configEntry The configuration entry holding our listen port + * @return void + */ + public final function setListenPortByConfiguration ($configEntry) { + $this->setListenPort($this->getConfigInstance()->readConfig($configEntry)); + } } // [EOF] diff --git a/application/hub/main/listener/tcp/class_TcpListener.php b/application/hub/main/listener/tcp/class_TcpListener.php new file mode 100644 index 000000000..098defb96 --- /dev/null +++ b/application/hub/main/listener/tcp/class_TcpListener.php @@ -0,0 +1,54 @@ + + * @version 0.0.0 + * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 Core Developer Team + * @license GNU GPL 3.0 or any newer version + * @link http://www.ship-simu.org + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +class TcpListener extends BaseListener implements Listenable { + /** + * Protected constructor + * + * @return void + */ + protected function __construct () { + // Call parent constructor + parent::__construct(__CLASS__); + } + + /** + * Creates an instance of this class + * + * @param $nodeInstance A NodeHelper instance + * @return $listenerInstance An instance a prepared listener class + */ + public final static function createTcpListener (NodeHelper $nodeInstance) { + // Get new instance + $listenerInstance = new TcpListener(); + + // Set the application instance + $listenerInstance->setNodeInstance($nodeInstance); + + // Return the prepared instance + return $listenerInstance; + } +} + +// [EOF] +?> diff --git a/application/hub/main/listener/udp/class_UdpListener.php b/application/hub/main/listener/udp/class_UdpListener.php new file mode 100644 index 000000000..ee23e2789 --- /dev/null +++ b/application/hub/main/listener/udp/class_UdpListener.php @@ -0,0 +1,54 @@ + + * @version 0.0.0 + * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 Core Developer Team + * @license GNU GPL 3.0 or any newer version + * @link http://www.ship-simu.org + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +class UdpListener extends BaseListener implements Listenable { + /** + * Protected constructor + * + * @return void + */ + protected function __construct () { + // Call parent constructor + parent::__construct(__CLASS__); + } + + /** + * Creates an instance of this class + * + * @param $nodeInstance A NodeHelper instance + * @return $listenerInstance An instance a prepared listener class + */ + public final static function createUdpListener (NodeHelper $nodeInstance) { + // Get new instance + $listenerInstance = new UdpListener(); + + // Set the application instance + $listenerInstance->setNodeInstance($nodeInstance); + + // Return the prepared instance + return $listenerInstance; + } +} + +// [EOF] +?> -- 2.39.5