3 * A NodeMessageAnnouncement handler
5 * @author Roland Haeder <webmaster@ship-simu.org>
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
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.
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.
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/>.
24 class NodeMessageAnnouncementHandler extends BaseMessageHandler implements HandleableMessage, Registerable {
26 * Array with all data XML nodes (which hold the actual data) and their values
28 private $messageDataElements = array();
31 * Protected constructor
35 protected function __construct () {
36 // Call parent constructor
37 parent::__construct(__CLASS__);
40 $this->setHandlerName('message_type_announcement');
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
53 * Creates an instance of this class
55 * @return $handlerInstance An instance of a HandleableMessage class
57 public final static function createNodeMessageAnnouncementHandler () {
59 $handlerInstance = new NodeMessageAnnouncementHandler();
61 // Return the prepared instance
62 return $handlerInstance;
66 * Handles data array of the message
68 * @param $messageData An array with message data to handle
69 * @param $packageInstance An instance of a Receivable class
72 public function handleMessageData (array $messageData, Receivable $packageInstance) {
73 // Register the announcing node with this node
74 $this->registerNodeByMessageData($messageData);
76 // Prepare answer message to be delivered back to the other node
77 $this->prepareAnswerMessage($messageData, $packageInstance);
81 * Adds all required elements from given array into data set instance
83 * @param $dataSetInstance An instance of a StoreableCriteria class
84 * @param $messageData An array with all message data
87 public function addArrayToDataSet (StoreableCriteria $dataSetInstance, array $messageData) {
89 foreach ($this->messageDataElements as $key) {
91 assert(isset($messageData[$key]));
94 $dataSetInstance->addCriteria('node_' . $key, $messageData[$key]);