]> git.mxchange.org Git - hub.git/blobdiff - application/hub/main/factories/socket/class_SocketFactory.php
Continued with hub:
[hub.git] / application / hub / main / factories / socket / class_SocketFactory.php
index 1d484264efb49e58a976073071e53e06f6ee6edd..9a1973d083cfdb498a82104a06b34b5cf5cee4bf 100644 (file)
@@ -2,11 +2,11 @@
 /**
  * A socket factory class
  *
- * @author             Roland Haeder <webmaster@ship-simu.org>
+ * @author             Roland Haeder <webmaster@shipsimu.org>
  * @version            0.0.0
- * @copyright  Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2012 Core Developer Team
+ * @copyright  Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2014 Core Developer Team
  * @license            GNU GPL 3.0 or any newer version
- * @link               http://www.ship-simu.org
+ * @link               http://www.shipsimu.org
  * @todo               Find an interface for hub helper
  *
  * This program is free software: you can redistribute it and/or modify
@@ -22,7 +22,7 @@
  * 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 SocketFactory extends BaseHubHelper {
+class SocketFactory extends ObjectFactory {
        /**
         * Protected constructor
         *
@@ -37,18 +37,18 @@ class SocketFactory extends BaseHubHelper {
         * Creates a valid socket resource from given packae data and protocol
         *
         * @param       $packageData            Raw package data
-        * @param       $protocolName           Protocol name (TCP/UDP)
+        * @param       $protocolInstance       An instance of a ProtocolHandler class
         * @return      $socketResource         Socket resource
         */
-       public static function createSocketFromPackageData (array $packageData, $protocolName) {
+       public static function createSocketFromPackageData (array $packageData, ProtocolHandler $protocolInstance) {
                // Get an instance
                $factoryInstance = new SocketFactory();
 
                // Construct registry key
-               $registryKey = 'socket_' . $protocolName . '_' . $packageData[NetworkPackage::PACKAGE_DATA_RECIPIENT];
+               $registryKey = 'socket_' . $protocolInstance->getProtocolName() . '_' . $packageData[NetworkPackage::PACKAGE_DATA_RECIPIENT];
 
                // Debug message
-               self::createDebugInstance(__CLASS__)->debugOutput('SOCKET-FACTORY: Trying to find a socket with registryKey=' . $registryKey);
+               //*NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('SOCKET-FACTORY[' . __METHOD__ . ':' . __LINE__ . ']: Trying to find a socket with registryKey=' . $registryKey);
 
                // Is the key there?
                if (Registry::getRegistry()->instanceExists($registryKey)) {
@@ -59,28 +59,28 @@ class SocketFactory extends BaseHubHelper {
                        $socketResource = $containerInstance->getSocketResource();
 
                        // Debug message
-                       self::createDebugInstance(__CLASS__)->debugOutput('SOCKET-FACTORY: Using socket ' . $socketResource . '(' . gettype($socketResource) . ') from registry.');
+                       //*NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('SOCKET-FACTORY[' . __METHOD__ . ':' . __LINE__ . ']: Using socket ' . $socketResource . '(' . gettype($socketResource) . ') from registry.');
                } else {
                        // Construct configuration entry for object factory and get it
-                       $className = FrameworkConfiguration::getSelfInstance()->getConfigEntry($protocolName . '_connection_helper_class');
+                       $className = FrameworkConfiguration::getSelfInstance()->getConfigEntry($protocolInstance->getProtocolName() . '_connection_helper_class');
 
                        // Debug message
-                       self::createDebugInstance(__CLASS__)->debugOutput('SOCKET-FACTORY: Going to use class ' . $className . ' for creating a socket resource ...');
+                       //*NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('SOCKET-FACTORY[' . __METHOD__ . ':' . __LINE__ . ']: Going to use class ' . $className . ' for creating a socket resource ...');
 
                        // And call the static method
                        $socketResource = call_user_func($className . '::createConnectionFromPackageData', $packageData);
 
                        // Debug message
-                       self::createDebugInstance(__CLASS__)->debugOutput('SOCKET-FACTORY: Created socket ' . $socketResource . '(' . gettype($socketResource) . ') from class ' . $className . '.');
+                       //*NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('SOCKET-FACTORY[' . __METHOD__ . ':' . __LINE__ . ']: Created socket ' . $socketResource . '(' . gettype($socketResource) . ') from class ' . $className . '.');
 
                        // Construct container class, this won't be reached if an exception is thrown
-                       $containerInstance = ObjectFactory::CreateObjectByConfiguredName('socket_container_class', array($socketResource, NULL, $packageData));
+                       $containerInstance = self::CreateObjectByConfiguredName('socket_container_class', array($socketResource, NULL, $packageData));
 
                        // Register it with the registry
                        Registry::getRegistry()->addInstance($registryKey, $containerInstance);
 
                        // Debug message
-                       self::createDebugInstance(__CLASS__)->debugOutput('SOCKET-FACTORY: Socket is now registered in registry.');
+                       //*NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('SOCKET-FACTORY[' . __METHOD__ . ':' . __LINE__ . ']: Socket is now registered in registry.');
                }
 
                // Return the resource