]> git.mxchange.org Git - hub.git/blobdiff - application/hub/main/tasks/network/class_NetworkPackageReaderTask.php
Continued with hub:
[hub.git] / application / hub / main / tasks / network / class_NetworkPackageReaderTask.php
index 3f847aa83f92c0e09e62276af7607b1c2d72498d..da1a84a49097493c2e7fc01d106228c834833aab 100644 (file)
@@ -2,11 +2,11 @@
 /**
  * A NetworkPackageReader task
  *
- * @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 - 2011 Hub Developer Team
+ * @copyright  Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2014 Hub Developer Team
  * @license            GNU GPL 3.0 or any newer version
- * @link               http://www.ship-simu.org
+ * @link               http://www.shipsimu.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
@@ -35,21 +35,32 @@ class NetworkPackageReaderTask extends BaseTask implements Taskable, Visitable {
        /**
         * Creates an instance of this class
         *
+        * @param       $poolInstance   An instance of a PoolableListener class
         * @return      $taskInstance   An instance of a Taskable/Visitable class
         */
-       public static final function createNetworkPackageReaderTask () {
+       public static final function createNetworkPackageReaderTask (PoolableListener $poolInstance) {
                // Get new instance
                $taskInstance = new NetworkPackageReaderTask();
 
+               // Set the listener instance here
+               $taskInstance->setListenerPoolInstance($poolInstance);
+
+               // Get a singleton network package instance
+               $packageInstance = NetworkPackageFactory::createNetworkPackageInstance();
+
+               // And set it in this task
+               $taskInstance->setPackageInstance($packageInstance);
+
                // Return the prepared instance
                return $taskInstance;
        }
 
        /**
-        * Accepts the visitor to process the visit "request"
+        * Accepts the visitor to process the visitor
         *
         * @param       $visitorInstance        An instance of a Visitor class
         * @return      void
+        * @todo        Also visit some sub-objects?
         */
        public function accept (Visitor $visitorInstance) {
                // Visit this task
@@ -62,16 +73,44 @@ class NetworkPackageReaderTask extends BaseTask implements Taskable, Visitable {
         * @return      void
         */
        public function executeTask () {
-               // Get a singleton network package instance
-               $packageInstance = NetworkPackageFactory::createNetworkPackageInstance();
+               // "Cache" package instance
+               $packageInstance = $this->getPackageInstance();
 
                // Do we have something to handle?
-               if ($packageInstance->isNewRawDataPending()) {
-                       // We have to handle raw data from the socket
-                       $packageInstance->handleIncomingSocketRawData();
-               } elseif ($packageInstance->isNewPackageArrived()) {
-                       // Okay, then handle newly arrived package
-                       $packageInstance->handleNewlyArrivedPackage();
+               if ($packageInstance->isProcessedMessagePending()) {
+                       /*
+                        * A previously proccessed message is waiting for being
+                        * "interpreted". This is done by trying to find a configuration
+                        * entry based on 'message_type' element.
+                        */
+                       $packageInstance->handleProcessedMessage();
+               } elseif ($packageInstance->isNewMessageArrived()) {
+                       /*
+                        * A fully "decoded" message has been received and added for being
+                        * processed. Processing a message should not take long, so mostly
+                        * this step involves reading all data through a XML template engine
+                        * as "XML variables" from the content (which must be a well-formed
+                        * XML) and then pushing it on the next stack "processed messages".
+                        */
+                       $packageInstance->handleNewlyArrivedMessage();
+               } elseif ($packageInstance->isIncomingRawDataHandled()) {
+                       /*
+                        * Incoming decoded data has been handled (see below) so it needs to
+                        * be assembled back to a "package array". Please see NetworkPackage
+                        * for further details (what array elements are required et cetera).
+                        */
+                       $packageInstance->assembleDecodedDataToPackage();
+               } elseif ($packageInstance->ifMultipleMessagesPending()) {
+                       /*
+                        * Some raw data contained multiple messages which where now splitted.
+                        */
+                       $packageInstance->handleMultipleMessages();
+               } elseif ($packageInstance->isNewRawDataPending($this->getListenerPoolInstance())) {
+                       // Raw, decoded data has been received
+                       $packageInstance->handleIncomingDecodedData();
+               } elseif ($packageInstance->ifAssemblerHasPendingDataLeft()) {
+                       // Handle any pending data from the package assembler
+                       $packageInstance->handleAssemblerPendingData();
                } // END - if
        }
 }