ScummVM API documentation
host.h
1 /* ScummVM - Graphic Adventure Engine
2  *
3  * ScummVM is the legal property of its developers, whose names
4  * are too numerous to list here. Please refer to the COPYRIGHT
5  * file distributed with this source distribution.
6  *
7  * This program is free software: you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation, either version 3 of the License, or
10  * (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program. If not, see <http://www.gnu.org/licenses/>.
19  *
20  */
21 
22 #ifndef BACKENDS_NETWORKING_ENET_HOST_H
23 #define BACKENDS_NETWORKING_ENET_HOST_H
24 
25 typedef struct _ENetHost ENetHost;
26 typedef struct _ENetPeer ENetPeer;
27 
28 typedef struct _ENetEvent ENetEvent;
29 typedef struct _ENetPacket ENetPacket;
30 
31 
32 // Event types
33 #define ENET_EVENT_TYPE_NONE 0
34 #define ENET_EVENT_TYPE_CONNECT 1
35 #define ENET_EVENT_TYPE_DISCONNECT 2
36 #define ENET_EVENT_TYPE_RECEIVE 3
37 
38 #include "common/system.h"
39 #include "common/str.h"
40 #include "common/debug.h"
41 
42 namespace Networking {
43 
44 class Host {
45 public:
51  Host(ENetHost *host);
58  Host(ENetHost *host, ENetPeer *serverPeer);
59  ~Host();
60 
69  uint8 service(int timeout = 0);
70 
80  bool connectPeer(const Common::String &address, int port, int timeout = 5000, int numChannels = 1);
86  void disconnectPeer(int peerIndex);
87 
98  bool send(const char *data, int peerIndex, int channel = 0, bool reliable = true);
109  bool sendRawData(const Common::String &address, int port, const char *data);
110 
122  int getPort();
123 
131  int getPeerIndexFromHost(const Common::String &host, int port);
132 
142  void destroyPacket();
143 private:
144 
150  ENetHost *_host;
155  ENetPeer *_serverPeer;
160  Common::String _recentHost;
165  int _recentPort;
170  ENetPacket *_recentPacket;
171 };
172 
173 } // End of namespace Networking
174 
175 #endif
Definition: str.h:59
int getPeerIndexFromHost(const Common::String &host, int port)
Definition: scummvmcloud.h:31
void disconnectPeer(int peerIndex)
bool send(const char *data, int peerIndex, int channel=0, bool reliable=true)
Definition: enet.h:363
Definition: enet.h:439
Definition: enet.h:263
bool connectPeer(const Common::String &address, int port, int timeout=5000, int numChannels=1)
Common::String getHost()
bool sendRawData(const Common::String &address, int port, const char *data)
Common::String getPacketData()
Definition: host.h:44
Host(ENetHost *host)
uint8 service(int timeout=0)
Definition: enet.h:148