3 namespace CoreFramework\Listener\Socket;
5 // Import framework stuff
6 use CoreFramework\Listener\Listenable;
9 * A decorator for the SocketFileListener to communicate to hubs
11 * @author Roland Haeder <webmaster@shipsimu.org>
13 * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2017 Core Developer Team
14 * @license GNU GPL 3.0 or any newer version
15 * @link http://www.shipsimu.org
17 * This program is free software: you can redistribute it and/or modify
18 * it under the terms of the GNU General Public License as published by
19 * the Free Software Foundation, either version 3 of the License, or
20 * (at your option) any later version.
22 * This program is distributed in the hope that it will be useful,
23 * but WITHOUT ANY WARRANTY; without even the implied warranty of
24 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25 * GNU General Public License for more details.
27 * You should have received a copy of the GNU General Public License
28 * along with this program. If not, see <http://www.gnu.org/licenses/>.
30 class SocketFileListenerDecorator extends BaseListenerDecorator implements Listenable {
32 * Protected constructor
36 protected function __construct () {
37 // Call parent constructor
38 parent::__construct(__CLASS__);
40 // Set listener type and protocol name
41 $this->setListenerType('hub');
42 $this->setProtocolName('tcp');
46 * Creates an instance of this class
48 * @param $listenerInstance A Listener instance
49 * @return $decoratorInstance An instance a prepared listener decorator class
51 public static final function createSocketFileListenerDecorator (Listenable $listenerInstance) {
53 $decoratorInstance = new SocketFileListenerDecorator();
55 // Set the application instance
56 $decoratorInstance->setListenerInstance($listenerInstance);
58 // Return the prepared instance
59 return $decoratorInstance;
63 * Initializes the listener by setting up the required socket server
67 public function initListener () {
68 $this->partialStub('WARNING: This method should not be called.');
72 * "Listens" for incoming network packages
76 public function doListen () {
77 // Handle generic TCP package
78 $this->getListenerInstance()->doListen();
80 // Handle hub TCP package
81 $this->partialStub('Need to handle hub TCP package.');
85 * Checks whether the listener would accept the given package data array
87 * @param $packageData Raw package data
88 * @return $accepts Whether this listener does accept
90 public function ifListenerAcceptsPackageData (array $packageData) {
91 // Get a tags instance
92 $tagsInstance = PackageTagsFactory::createPackageTagsInstance();
94 // So is the package accepted with this listener?
95 $accepts = $tagsInstance->ifPackageDataIsAcceptedByListener($packageData, $this);