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 namespace ENet {
44 
45 class Host {
46 public:
52  Host(ENetHost *host);
59  Host(ENetHost *host, ENetPeer *serverPeer);
60  ~Host();
61 
70  uint8 service(int timeout = 0);
71 
81  bool connectPeer(const Common::String &address, int port, int timeout = 5000, int numChannels = 1);
87  void disconnectPeer(int peerIndex);
88 
99  bool send(const char *data, int peerIndex, int channel = 0, bool reliable = true);
110  bool sendRawData(const Common::String &address, int port, const char *data);
111 
123  int getPort();
124 
132  int getPeerIndexFromHost(const Common::String &host, int port);
133 
143  void destroyPacket();
144 private:
145 
151  ENetHost *_host;
156  ENetPeer *_serverPeer;
161  Common::String _recentHost;
166  int _recentPort;
171  ENetPacket *_recentPacket;
172 };
173 
174 } // End of namespace ENet
175 } // End of namespace Networking
176 
177 #endif
Definition: str.h:59
Host(ENetHost *host)
bool sendRawData(const Common::String &address, int port, const char *data)
void disconnectPeer(int peerIndex)
Definition: scummvmcloud.h:32
Common::String getPacketData()
Definition: enet.h:363
int getPeerIndexFromHost(const Common::String &host, int port)
bool send(const char *data, int peerIndex, int channel=0, bool reliable=true)
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()
Definition: host.h:45
uint8 service(int timeout=0)
Definition: enet.h:148