]> git.mxchange.org Git - hub.git/blob - application/hub/main/handler/message-types/class_BaseMessageHandler.php
Updated 'core'.
[hub.git] / application / hub / main / handler / message-types / class_BaseMessageHandler.php
1 <?php
2 /**
3  * A general message handler, this class must be abstract to make the template
4  * method pattern working.
5  *
6  * @author              Roland Haeder <webmaster@shipsimu.org>
7  * @version             0.0.0
8  * @copyright   Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 Hub Developer Team
9  * @license             GNU GPL 3.0 or any newer version
10  * @link                http://www.shipsimu.org
11  *
12  * This program is free software: you can redistribute it and/or modify
13  * it under the terms of the GNU General Public License as published by
14  * the Free Software Foundation, either version 3 of the License, or
15  * (at your option) any later version.
16  *
17  * This program is distributed in the hope that it will be useful,
18  * but WITHOUT ANY WARRANTY; without even the implied warranty of
19  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
20  * GNU General Public License for more details.
21  *
22  * You should have received a copy of the GNU General Public License
23  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
24  */
25 abstract class BaseMessageHandler extends BaseDataHandler {
26         /**
27          * Protected constructor
28          *
29          * @param       $className      Name of the class
30          * @return      void
31          */
32         protected function __construct ($className) {
33                 // Call parent constructor
34                 parent::__construct($className);
35         }
36
37         /**
38          * "Getter" for a translated last exception as a status code
39          *
40          * @return      $statusCode             Translated status code from last exception
41          */
42         protected function getTranslatedStatusFromLastException () {
43                 // Default is all fine
44                 $statusCode = BaseHubSystem::MESSAGE_STATUS_CODE_OKAY;
45
46                 // Is the last exception not NULL?
47                 if ($this->getLastException() instanceof FrameworkException) {
48                         // "Determine" the right status code (may differ from exception to exception)
49                         $this->debugInstance('lastException=' . $this->getLastException()->__toString() . ',message=' . $this->getLastException()->getMessage() . ' is not finished!');
50                 } // END - if
51
52                 // Return the status code
53                 return $statusCode;
54         }
55
56         /**
57          * Registers an other node with this node by given message data. The
58          * following data must always be present:
59          *
60          * - session-id  (for finding the node's record together with below data)
61          * - external-address (hostname or IP number)
62          * - listen-port (TCP/UDP listen port for inbound connections)
63          *
64          * @param       $messageArray   An array with all minimum message data
65          * @return      void
66          */
67         protected function registerNodeByMessageData (array $messageData) {
68                 // Check if searchData has entries
69                 assert(count($this->getSearchData()) > 0);
70
71                 // Let the DHT facade do the work
72                 $this->getDhtInstance()->registerNodeByMessageData($messageData, $this);
73         }
74
75         /**
76          * Posty-handles data array of the message
77          *
78          * @param       $messageData            An array with message data to handle
79          * @param       $packageInstance        An instance of a Receivable class
80          * @return      void
81          */
82         public function postHandleMessageData (array $messageData, Receivable $packageInstance) {
83                 /*
84                  * Feed hash to miner by handling over the whole array as also the
85                  * sender and tags are needed.
86                  */
87                 $packageInstance->feedHashToMiner($messageData);
88         }
89 }
90
91 // [EOF]
92 ?>