]> git.mxchange.org Git - core.git/blobdiff - inc/main/classes/listener/class_BaseListener.php
Renamed Registry -> GenericRegistry to make it clear that this registry does
[core.git] / inc / main / classes / listener / class_BaseListener.php
index ff89553e3e88abb347d740ae1bef1b34623c29f0..e22ceea1d155b851c5f51a815afb663554ebde36 100644 (file)
@@ -1,17 +1,10 @@
 <?php
-// Own namespace
-namespace CoreFramework\Listener;
-
-// Import framework stuff
-use CoreFramework\Factory\ObjectFactory;
-use CoreFramework\Object\BaseFrameworkSystem;
-
 /**
  * A general listener class
  *
  * @author             Roland Haeder <webmaster@shipsimu.org>
  * @version            0.0.0
- * @copyright  Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2017 Core Developer Team
+ * @copyright  Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2016 Core Developer Team
  * @license            GNU GPL 3.0 or any newer version
  * @link               http://www.shipsimu.org
  *
@@ -28,7 +21,7 @@ use CoreFramework\Object\BaseFrameworkSystem;
  * You should have received a copy of the GNU General Public License
  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  */
-class BaseListener extends BaseFrameworkSystem implements Visitable {
+abstract class BaseListener extends BaseFrameworkSystem implements Visitable {
        // Exception code constants
        const EXCEPTION_INVALID_SOCKET                   = 0xa00;
        const EXCEPTION_SOCKET_ALREADY_REGISTERED        = 0xa01;
@@ -84,7 +77,7 @@ class BaseListener extends BaseFrameworkSystem implements Visitable {
                // We need to clear the error here if it is a resource
                if ($isServerSocket === TRUE) {
                        // Clear the error
-                       //* DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('socketResource[]=' . gettype($socketResource));
+                       //* DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('socketResource[]=' . gettype($socketResource));
                        socket_clear_error($socketResource);
                } // END - if
 
@@ -268,7 +261,7 @@ class BaseListener extends BaseFrameworkSystem implements Visitable {
         */
        public function accept (Visitor $visitorInstance) {
                // Debug message
-               //* DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(strtoupper($this->getProtocolName()) . '-LISTENER[' . __METHOD__ . ':' . __LINE__ . ']: ' . $visitorInstance->__toString() . ' has visited ' . $this->__toString() . ' - CALLED!');
+               //* DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput(strtoupper($this->getProtocolName()) . '-LISTENER[' . __METHOD__ . ':' . __LINE__ . ']: ' . $visitorInstance->__toString() . ' has visited ' . $this->__toString() . ' - CALLED!');
 
                // Visit this listener
                $visitorInstance->visitListener($this);
@@ -279,7 +272,7 @@ class BaseListener extends BaseFrameworkSystem implements Visitable {
                } // END - if
 
                // Debug message
-               //* DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(strtoupper($this->getProtocolName()) . '-LISTENER[' . __METHOD__ . ':' . __LINE__ . ']: ' . $visitorInstance->__toString() . ' has visited ' . $this->__toString() . ' - EXIT!');
+               //* DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput(strtoupper($this->getProtocolName()) . '-LISTENER[' . __METHOD__ . ':' . __LINE__ . ']: ' . $visitorInstance->__toString() . ' has visited ' . $this->__toString() . ' - EXIT!');
        }
 
        /**
@@ -376,7 +369,7 @@ class BaseListener extends BaseFrameworkSystem implements Visitable {
 
                        default: // Everything else <> 0
                                // Unhandled error code detected, so first debug it because we may want to handle it like the others
-                               self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-HUB[' . __METHOD__ . ':' . __LINE__ . '] UNKNOWN ERROR CODE = ' . $errorCode . ', MESSAGE = ' . socket_strerror($errorCode));
+                               self::createDebugInstance(__CLASS__)->debugOutput('BASE-HUB[' . __METHOD__ . ':' . __LINE__ . '] UNKNOWN ERROR CODE = ' . $errorCode . ', MESSAGE = ' . socket_strerror($errorCode));
 
                                // Change it only in this class
                                $errorName = BaseRawDataHandler::SOCKET_ERROR_UNKNOWN;
@@ -396,7 +389,7 @@ class BaseListener extends BaseFrameworkSystem implements Visitable {
         */
        public function shutdownSocket ($socketResource) {
                // Debug message
-               self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('HUB-SYSTEM: Shutting down socket resource ' . $socketResource . ' with state ' . $this->getPrintableState() . ' ...');
+               self::createDebugInstance(__CLASS__)->debugOutput('HUB-SYSTEM: Shutting down socket resource ' . $socketResource . ' with state ' . $this->getPrintableState() . ' ...');
 
                // Set socket resource
                $this->setSocketResource($socketResource);
@@ -405,7 +398,7 @@ class BaseListener extends BaseFrameworkSystem implements Visitable {
                $visitorInstance = ObjectFactory::createObjectByConfiguredName('shutdown_socket_visitor_class');
 
                // Debug output
-               self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('HUB-SYSTEM:' . $this->__toString() . ': visitorInstance=' . $visitorInstance->__toString());
+               self::createDebugInstance(__CLASS__)->debugOutput('HUB-SYSTEM:' . $this->__toString() . ': visitorInstance=' . $visitorInstance->__toString());
 
                // Call the visitor
                $this->accept($visitorInstance);
@@ -420,7 +413,7 @@ class BaseListener extends BaseFrameworkSystem implements Visitable {
         */
        public function halfShutdownSocket ($socketResource) {
                // Debug message
-               self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('HUB-SYSTEM: Half-shutting down socket resource ' . $socketResource . ' with state ' . $this->getPrintableState() . ' ...');
+               self::createDebugInstance(__CLASS__)->debugOutput('HUB-SYSTEM: Half-shutting down socket resource ' . $socketResource . ' with state ' . $this->getPrintableState() . ' ...');
 
                // Set socket resource
                $this->setSocketResource($socketResource);
@@ -429,7 +422,7 @@ class BaseListener extends BaseFrameworkSystem implements Visitable {
                $visitorInstance = ObjectFactory::createObjectByConfiguredName('half_shutdown_socket_visitor_class');
 
                // Debug output
-               self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('HUB-SYSTEM:' . $this->__toString() . ': visitorInstance=' . $visitorInstance->__toString());
+               self::createDebugInstance(__CLASS__)->debugOutput('HUB-SYSTEM:' . $this->__toString() . ': visitorInstance=' . $visitorInstance->__toString());
 
                // Call the visitor
                $this->accept($visitorInstance);
@@ -491,14 +484,14 @@ class BaseListener extends BaseFrameworkSystem implements Visitable {
                // Some new peers found?
                if ($left < 1) {
                        // Debug message
-                       //* EXTREME-NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('TCP-LISTENER[' . __METHOD__ . ':' . __LINE__ . ']: left=' . $left . ',serverSocket=' . $this->getSocketResource() . ',readers=' . print_r($readers, TRUE));
+                       //* EXTREME-NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('TCP-LISTENER[' . __METHOD__ . ':' . __LINE__ . ']: left=' . $left . ',serverSocket=' . $this->getSocketResource() . ',readers=' . print_r($readers, TRUE));
 
                        // Nothing new found
                        return;
                } // END - if
 
                // Debug message
-               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('TCP-LISTENER[' . __METHOD__ . ':' . __LINE__ . ']: serverSocket=' . $this->getSocketResource() . ',readers=' . print_r($readers, TRUE));
+               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('TCP-LISTENER[' . __METHOD__ . ':' . __LINE__ . ']: serverSocket=' . $this->getSocketResource() . ',readers=' . print_r($readers, TRUE));
 
                // Do we have changed peers?
                if (in_array($this->getSocketResource(), $readers)) {
@@ -512,7 +505,7 @@ class BaseListener extends BaseFrameworkSystem implements Visitable {
                        $newSocket = socket_accept($this->getSocketResource());
 
                        // Debug message
-                       //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('TCP-LISTENER[' . __METHOD__ . ':' . __LINE__ . ']: newSocket=' . $newSocket . ',serverSocket=' .$this->getSocketResource());
+                       //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('TCP-LISTENER[' . __METHOD__ . ':' . __LINE__ . ']: newSocket=' . $newSocket . ',serverSocket=' .$this->getSocketResource());
 
                        // Array for timeout settings
                        $options  = array(
@@ -532,7 +525,7 @@ class BaseListener extends BaseFrameworkSystem implements Visitable {
                        // Output result (only for debugging!)
                        /*
                        $option = socket_get_option($newSocket, SOL_SOCKET, SO_RCVTIMEO);
-                       self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('SO_RCVTIMEO[' . gettype($option) . ']=' . print_r($option, TRUE));
+                       self::createDebugInstance(__CLASS__)->debugOutput('SO_RCVTIMEO[' . gettype($option) . ']=' . print_r($option, TRUE));
                        */
 
                        // Enable SO_OOBINLINE
@@ -589,7 +582,7 @@ class BaseListener extends BaseFrameworkSystem implements Visitable {
                $currentSocket = $this->getIteratorInstance()->current();
 
                // Handle it here, if not main server socket
-               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('TCP-LISTENER[' . __METHOD__ . ':' . __LINE__ . ']: currentSocket=' . $currentSocket[BasePool::SOCKET_ARRAY_RESOURCE] . ',type=' . $currentSocket[BasePool::SOCKET_ARRAY_CONN_TYPE] . ',serverSocket=' . $this->getSocketResource());
+               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('TCP-LISTENER[' . __METHOD__ . ':' . __LINE__ . ']: currentSocket=' . $currentSocket[BasePool::SOCKET_ARRAY_RESOURCE] . ',type=' . $currentSocket[BasePool::SOCKET_ARRAY_CONN_TYPE] . ',serverSocket=' . $this->getSocketResource());
                if (($currentSocket[BasePool::SOCKET_ARRAY_CONN_TYPE] != BaseConnectionHelper::CONNECTION_TYPE_SERVER) && ($currentSocket[BasePool::SOCKET_ARRAY_RESOURCE] != $this->getSocketResource())) {
                        // ... or else it will raise warnings like 'Transport endpoint is not connected'
                        $this->getHandlerInstance()->processRawDataFromResource($currentSocket);