]> git.mxchange.org Git - hub.git/blobdiff - application/hub/main/template/announcement/class_XmlAnnouncementTemplateEngine.php
Added 'registering of other nodes' ability, added protocol name to relevant method...
[hub.git] / application / hub / main / template / announcement / class_XmlAnnouncementTemplateEngine.php
index 52e3664322e5d657a7a9d23919d601839353ec71..935ddb64ff4a029c508f437211c000c3823bfc5a 100644 (file)
@@ -4,7 +4,7 @@
  *
  * @author             Roland Haeder <webmaster@ship-simu.org>
  * @version            0.0.0
- * @copyright  Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2011 Core Developer Team
+ * @copyright  Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2012 Core Developer Team
  * @license            GNU GPL 3.0 or any newer version
  * @link               http://www.ship-simu.org
  * @todo               This template engine does not make use of setTemplateType()
  * along with this program. If not, see <http://www.gnu.org/licenses/>.
  */
 class XmlAnnouncementTemplateEngine extends BaseTemplateEngine implements CompileableTemplate, Registerable {
+       /**
+        * Some XML nodes must be available for later data extraction
+        */
+       const ANNOUNCEMENT_DATA_SESSION_ID  = 'session-id';
+       const ANNOUNCEMENT_DATA_NODE_STATUS = 'node-status';
+       const ANNOUNCEMENT_DATA_EXTERNAL_IP = 'external-ip';
+       const ANNOUNCEMENT_DATA_TCP_PORT    = 'tcp-port';
+       const ANNOUNCEMENT_DATA_UDP_PORT    = 'udp-port';
+
        /**
         * Main nodes in the XML tree
         */
@@ -33,18 +42,7 @@ class XmlAnnouncementTemplateEngine extends BaseTemplateEngine implements Compil
        /**
         * Sub nodes in the XML tree
         */
-       private $subNodes = array(
-               'announcement-data',
-               'listener',
-               'hub-listener',
-               'client-listener',
-               'node-id',
-               'node-status',
-               'tcp-port',
-               'udp-port',
-               'session-id',
-               'object-type-list',
-       );
+       private $subNodes = array();
 
        /**
         * Current main node
@@ -64,6 +62,18 @@ class XmlAnnouncementTemplateEngine extends BaseTemplateEngine implements Compil
        protected function __construct () {
                // Call parent constructor
                parent::__construct(__CLASS__);
+
+               // Init array
+               $this->subNodes = array(
+                       'announcement-data',
+                       'listener',
+                       self::ANNOUNCEMENT_DATA_NODE_STATUS,
+                       self::ANNOUNCEMENT_DATA_TCP_PORT,
+                       self::ANNOUNCEMENT_DATA_UDP_PORT,
+                       self::ANNOUNCEMENT_DATA_SESSION_ID,
+                       self::ANNOUNCEMENT_DATA_EXTERNAL_IP,
+                       'object-type-list',
+               );
        }
 
        /**
@@ -284,6 +294,21 @@ class XmlAnnouncementTemplateEngine extends BaseTemplateEngine implements Compil
                } // END - if
        }
 
+       /**
+        * Read announcement variables by calling readVariable() with 'general' as
+        * variable stack.
+        *
+        * @param       $key    Key to read from
+        * @return      $value  Value from variable
+        */
+       public function readAnnouncementData ($key) {
+               // Read the variable
+               $value = parent::readVariable($key, 'general');
+
+               // Return value
+               return $value;
+       }
+
        /**
         * Getter for cache file (FQFN)
         *
@@ -313,16 +338,6 @@ class XmlAnnouncementTemplateEngine extends BaseTemplateEngine implements Compil
                $this->getStackerInstance()->pushNamed('announcement', 'announcement-data');
        }
 
-       /**
-        * Starts the node id
-        *
-        * @return      void
-        */
-       private function startNodeId () {
-               // Push the node name on the stacker
-               $this->getStackerInstance()->pushNamed('announcement', 'node-id');
-       }
-
        /**
         * Starts the node status
         *
@@ -330,7 +345,7 @@ class XmlAnnouncementTemplateEngine extends BaseTemplateEngine implements Compil
         */
        private function startNodeStatus () {
                // Push the node name on the stacker
-               $this->getStackerInstance()->pushNamed('announcement', 'node-status');
+               $this->getStackerInstance()->pushNamed('announcement', self::ANNOUNCEMENT_DATA_NODE_STATUS);
        }
 
        /**
@@ -344,53 +359,43 @@ class XmlAnnouncementTemplateEngine extends BaseTemplateEngine implements Compil
        }
 
        /**
-        * Starts the client listener
-        *
-        * @return      void
-        */
-       private function startClientListener () {
-               // Push the node name on the stacker
-               $this->getStackerInstance()->pushNamed('announcement', 'client-listener');
-       }
-
-       /**
-        * Starts the hub listener
+        * Starts the TCP port
         *
         * @return      void
         */
-       private function startHubListener () {
+       private function startTcpPort () {
                // Push the node name on the stacker
-               $this->getStackerInstance()->pushNamed('announcement', 'hub-listener');
+               $this->getStackerInstance()->pushNamed('announcement', self::ANNOUNCEMENT_DATA_TCP_PORT);
        }
 
        /**
-        * Starts the TCP port
+        * Starts the UDP port
         *
         * @return      void
         */
-       private function startTcpPort () {
+       private function startUdpPort () {
                // Push the node name on the stacker
-               $this->getStackerInstance()->pushNamed('announcement', 'tcp-port');
+               $this->getStackerInstance()->pushNamed('announcement', self::ANNOUNCEMENT_DATA_UDP_PORT);
        }
 
        /**
-        * Starts the UDP port
+        * Starts the session id
         *
         * @return      void
         */
-       private function startUdpPort () {
+       private function startSessionId () {
                // Push the node name on the stacker
-               $this->getStackerInstance()->pushNamed('announcement', 'udp-port');
+               $this->getStackerInstance()->pushNamed('announcement', self::ANNOUNCEMENT_DATA_SESSION_ID);
        }
 
        /**
-        * Starts the session id
+        * Starts the public ip
         *
         * @return      void
         */
-       private function startSessionId () {
+       private function startExternalIp () {
                // Push the node name on the stacker
-               $this->getStackerInstance()->pushNamed('announcement', 'session-id');
+               $this->getStackerInstance()->pushNamed('announcement', self::ANNOUNCEMENT_DATA_EXTERNAL_IP);
        }
 
        /**
@@ -444,41 +449,31 @@ class XmlAnnouncementTemplateEngine extends BaseTemplateEngine implements Compil
        }
 
        /**
-        * Finishes the UDP port
-        *
-        * @return      void
-        */
-       private function finishUdpPort () {
-               // Pop the last entry
-               $this->getStackerInstance()->popNamed('announcement');
-       }
-
-       /**
-        * Finishes the TCP port
+        * Finishes the public ip
         *
         * @return      void
         */
-       private function finishTcpPort () {
+       private function finishExternalIp () {
                // Pop the last entry
                $this->getStackerInstance()->popNamed('announcement');
        }
 
        /**
-        * Finishes the hub listener
+        * Finishes the UDP port
         *
         * @return      void
         */
-       private function finishHubListener () {
+       private function finishUdpPort () {
                // Pop the last entry
                $this->getStackerInstance()->popNamed('announcement');
        }
 
        /**
-        * Finishes the client listener
+        * Finishes the TCP port
         *
         * @return      void
         */
-       private function finishClientListener () {
+       private function finishTcpPort () {
                // Pop the last entry
                $this->getStackerInstance()->popNamed('announcement');
        }
@@ -503,16 +498,6 @@ class XmlAnnouncementTemplateEngine extends BaseTemplateEngine implements Compil
                $this->getStackerInstance()->popNamed('announcement');
        }
 
-       /**
-        * Finishes the node id
-        *
-        * @return      void
-        */
-       private function finishNodeId () {
-               // Pop the last entry
-               $this->getStackerInstance()->popNamed('announcement');
-       }
-
        /**
         * Finishes the announcement data
         *