]> git.mxchange.org Git - hub.git/blob - application/hub/main/handler/message-types/anouncement/class_NodeMessageAnnouncementHandler.php
Added 'registering of other nodes' ability, added protocol name to relevant method...
[hub.git] / application / hub / main / handler / message-types / anouncement / class_NodeMessageAnnouncementHandler.php
1 <?php
2 /**
3  * A NodeMessageAnnouncement handler
4  *
5  * @author              Roland Haeder <webmaster@ship-simu.org>
6  * @version             0.0.0
7  * @copyright   Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2012 Hub Developer Team
8  * @license             GNU GPL 3.0 or any newer version
9  * @link                http://www.ship-simu.org
10  *
11  * This program is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU General Public License as published by
13  * the Free Software Foundation, either version 3 of the License, or
14  * (at your option) any later version.
15  *
16  * This program is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19  * GNU General Public License for more details.
20  *
21  * You should have received a copy of the GNU General Public License
22  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
23  */
24 class NodeMessageAnnouncementHandler extends BaseMessageHandler implements HandleableMessage, Registerable {
25         /**
26          * Array with all data XML nodes (which hold the actual data) and their values
27          */
28         private $messageDataElements = array();
29
30         /**
31          * Protected constructor
32          *
33          * @return      void
34          */
35         protected function __construct () {
36                 // Call parent constructor
37                 parent::__construct(__CLASS__);
38
39                 // Set handler name
40                 $this->setHandlerName('message_type_announcement');
41
42                 // Init message data array
43                 $this->messageDataElements = array(
44                         XmlAnnouncementTemplateEngine::ANNOUNCEMENT_DATA_EXTERNAL_IP,
45                         XmlAnnouncementTemplateEngine::ANNOUNCEMENT_DATA_NODE_STATUS,
46                         XmlAnnouncementTemplateEngine::ANNOUNCEMENT_DATA_SESSION_ID,
47                         XmlAnnouncementTemplateEngine::ANNOUNCEMENT_DATA_TCP_PORT,
48                         XmlAnnouncementTemplateEngine::ANNOUNCEMENT_DATA_UDP_PORT
49                 );
50         }
51
52         /**
53          * Creates an instance of this class
54          *
55          * @return      $handlerInstance        An instance of a HandleableMessage class
56          */
57         public final static function createNodeMessageAnnouncementHandler () {
58                 // Get new instance
59                 $handlerInstance = new NodeMessageAnnouncementHandler();
60
61                 // Return the prepared instance
62                 return $handlerInstance;
63         }
64
65         /**
66          * Handles data array of the message
67          *
68          * @param       $messageData            An array with message data to handle
69          * @param       $packageInstance        An instance of a Receivable class
70          * @return      void
71          */
72         public function handleMessageData (array $messageData, Receivable $packageInstance) {
73                 // Register the announcing node with this node
74                 $this->registerNodeByMessageData($messageData);
75
76                 // Prepare answer message to be delivered back to the other node
77                 $this->prepareAnswerMessage($messageData, $packageInstance);
78         }
79
80         /**
81          * Adds all required elements from given array into data set instance
82          *
83          * @param       $dataSetInstance        An instance of a StoreableCriteria class
84          * @param       $messageData            An array with all message data
85          * @return      void
86          */
87         public function addArrayToDataSet (StoreableCriteria $dataSetInstance, array $messageData) {
88                 // Add all ements
89                 foreach ($this->messageDataElements as $key) {
90                         // Is it there?
91                         assert(isset($messageData[$key]));
92
93                         // Add it
94                         $dataSetInstance->addCriteria('node_' . $key, $messageData[$key]);
95                 } // END - foreach
96         }
97 }
98
99 // [EOF]
100 ?>