i6engine  1.0
NetworkFacade.h
Go to the documentation of this file.
1 /*
2  * i6engine
3  * Copyright (2016) Daniel Bonrath, Michael Baer, All rights reserved.
4  *
5  * This file is part of i6engine; i6engine is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Lesser General Public
7  * License as published by the Free Software Foundation; either
8  * version 2.1 of the License, or (at your option) any later version.
9  *
10  * This library is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  * Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public
16  * License along with this library; if not, write to the Free Software
17  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18  */
19 
25 #ifndef __I6ENGINE_API_NETWORKFACADE_H__
26 #define __I6ENGINE_API_NETWORKFACADE_H__
27 
29 
31 
32 #include "boost/function.hpp"
33 
34 namespace i6e {
35 namespace api {
36 
38  public:
39  NetworkFacade();
40  ~NetworkFacade();
41 
45  inline core::IPKey getIP() const { return _ownIP; }
46 
50  inline std::string getSimpleIP() const { return _IP; }
51 
55  bool connect(const core::IPKey remoteIP, const uint16_t localPort);
56 
57  bool listen(const uint16_t localPort);
58 
62  void disconnect();
63 
67  void enablePing(bool enabled);
68 
72  void subscribe(uint16_t channel); // TODO: (Daniel) add second subscribe method registering a filter predicate too
73 
77  void unsubscribe(uint16_t channel); // TODO: (Daniel) add second unsubscribe method registering a filter predicate too
78 
82  void publish(uint16_t channel, const GameMessage::Ptr & msg);
83 
87  void registerSubscribeCallback(const boost::function<void(uint16_t)> & f);
88 
92  void registerUnsubscribeCallback(const boost::function<void(uint16_t)> & f);
93 
97  void registerPublishCallback(const boost::function<void(uint16_t, const GameMessage::Ptr &)> & f);
98 
102  void registerConnectCallback(const boost::function<bool(const core::IPKey &, const core::IPKey &)> & f);
103 
107  void registerDisconnectCallback(const boost::function<void(void)> & f);
108 
112  void resetSubSystem();
113 
114  private:
118  core::IPKey _ownIP;
119 
123  bool _subscribeInit;
124 
128  bool _unsubscribeInit;
129 
133  bool _publishInit;
134 
138  boost::function<void(uint16_t)> _subscribe;
139 
143  boost::function<void(uint16_t)> _unsubscribe;
144 
148  boost::function<void(uint16_t, const GameMessage::Ptr &)> _publish;
149 
153  bool _connectInit;
154 
158  bool _disconnectInit;
159 
163  boost::function<bool(const core::IPKey &, const core::IPKey &)> _connect;
164 
168  boost::function<void(void)> _disconnect;
169 
170  bool _connected;
171 
176  std::string _IP;
177 
181  NetworkFacade(const NetworkFacade &) = delete;
182 
186  NetworkFacade & operator= (const NetworkFacade &) = delete;
187  };
188 
189 } /* namespace api */
190 } /* namespace i6e */
191 
192 #endif /* __I6ENGINE_API_NETWORKFACADE_H__ */
193 
#define ISIXE_MODULES_API
boost::shared_ptr< Message > Ptr
Definition: Message.h:66
std::string getSimpleIP() const
returns the IP without Port as a string
Definition: NetworkFacade.h:50
core::IPKey getIP() const
returns the IP
Definition: NetworkFacade.h:45