89a79129f8e4be688236c348ece480694b39f413
[core.git] / framework / main / classes / info / connection / class_ConnectionInfo.php
1 <?php
2 // Own namespace
3 namespace CoreFramework\Information\Connection;
4
5 // Import framework stuff
6 use CoreFramework\Information\BaseInfo;
7 use CoreFramework\Information\ShareableInfo;
8 use CoreFramework\Listener\Listenable;
9 use CoreFramework\Registry\Registerable;
10
11 /**
12  * A Connection information class
13  *
14  * @author              Roland Haeder <webmaster@ship-simu.org>
15  * @version             0.0.0
16  * @copyright   Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2017 Core Developer Team
17  * @license             GNU GPL 3.0 or any newer version
18  * @link                http://www.ship-simu.org
19  *
20  * This program is free software: you can redistribute it and/or modify
21  * it under the terms of the GNU General Public License as published by
22  * the Free Software Foundation, either version 3 of the License, or
23  * (at your option) any later version.
24  *
25  * This program is distributed in the hope that it will be useful,
26  * but WITHOUT ANY WARRANTY; without even the implied warranty of
27  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
28  * GNU General Public License for more details.
29  *
30  * You should have received a copy of the GNU General Public License
31  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
32  */
33 class ConnectionInfo extends BaseInfo implements ShareableInfo, Registerable {
34         /**
35          * Protected constructor
36          *
37          * @return      void
38          */
39         protected function __construct () {
40                 // Call parent constructor
41                 parent::__construct(__CLASS__);
42         }
43
44         /**
45          * Creates an instance of this class
46          *
47          * @return      $infoInstance   An instance of a ShareableInfo class
48          */
49         public final static function createConnectionInfo () {
50                 // Get new instance
51                 $infoInstance = new ConnectionInfo();
52
53                 // Return the prepared instance
54                 return $infoInstance;
55         }
56
57         /**
58          * Fills the information class with data from a Listenable instance
59          *
60          * @param       $listenerInstance       An instance of a Listenable class
61          * @return      void
62          */
63         public function fillWithListenerInformation (Listenable $listenerInstance) {
64                 // Debug message
65                 //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('[' . __METHOD__ . ':' . __LINE__ . ']: protocolName=' . $listenerInstance->getProtocolName() . ',listenerInstance=' . $listenerInstance->__toString() . ' - CALLED!');
66
67                 // Fill the generic array with several data from the listener:
68                 $this->setProtocolName($listenerInstance->getProtocolName());
69                 $this->setGenericArrayElement('connection', 'dummy', 'dummy', UniversalNodeLocator::UNL_PART_ADDRESS , $listenerInstance->getListenAddress());
70                 $this->setGenericArrayElement('connection', 'dummy', 'dummy', UniversalNodeLocator::UNL_PART_PORT    , $listenerInstance->getListenPort());
71
72                 // Set listener here
73                 $this->setListenerInstance($listenerInstance);
74
75                 // Debug message
76                 //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('[' . __METHOD__ . ':' . __LINE__ . ']: EXIT!');
77         }
78
79         /**
80          * Fills the information class with data from a ConnectionHelper instance
81          *
82          * @param       $helperInstance         An instance of a ConnectionHelper class
83          * @return      void
84          */
85         public function fillWithConnectionHelperInformation (ConnectionHelper $helperInstance) {
86                 // Debug message
87                 //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('[' . __METHOD__ . ':' . __LINE__ . ']: protocolName=' . $helperInstance->getProtocolName() . ',helperInstance=' . $helperInstance->__toString() . ',socketResource=' . $helperInstance->getSocketResource() . ' - CALLED!');
88
89                 // Fill the generic array with several data from the listener:
90                 $this->setProtocolName($helperInstance->getProtocolName());
91                 $this->setGenericArrayElement('connection', 'dummy', 'dummy', UniversalNodeLocator::UNL_PART_ADDRESS , $helperInstance->getAddress());
92                 $this->setGenericArrayElement('connection', 'dummy', 'dummy', UniversalNodeLocator::UNL_PART_PORT    , $helperInstance->getConnectionPort());
93
94                 // Set helper here
95                 $this->setHelperInstance($helperInstance);
96
97                 // Debug message
98                 //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('[' . __METHOD__ . ':' . __LINE__ . ']: EXIT!');
99         }
100
101         /**
102          * Getter for address
103          *
104          * @return      $address        Address from shared information
105          */
106         public final function getAddress () {
107                 // Return it from generic array
108                 return $this->getGenericArrayElement('connection', 'dummy', 'dummy', UniversalNodeLocator::UNL_PART_ADDRESS);
109         }
110
111         /**
112          * Getter for port
113          *
114          * @return      $port   Port from shared information
115          */
116         public final function getPort () {
117                 // Return it from generic array
118                 return $this->getGenericArrayElement('connection', 'dummy', 'dummy', UniversalNodeLocator::UNL_PART_PORT);
119         }
120
121 }