Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/FICN/src/network/ConnectionManager.h @ 396

Last change on this file since 396 was 381, checked in by scheusso, 17 years ago

using stl-map and stl-vector in ConnectionManaget should now work

File size: 2.0 KB
Line 
1//
2// C++ Interface: ConnectionManager
3//
4// Description:
5//
6//
7// Author:  Oliver Scheuss, (C) 2007
8//
9// Copyright: See COPYING file that comes with this distribution
10//
11//
12#ifndef NETWORK_CONNECTIONMANAGER_H
13#define NETWORK_CONNECTIONMANAGER_H
14
15#include <iostream>
16#include <string>
17#include <map>
18#include <vector>
19// enet library for networking support
20#include <enet/enet.h>
21// boost.thread library for multithreading support
22#include <boost/thread/thread.hpp>
23#include <boost/bind.hpp>
24// headerfiles
25#include "ConnectionManager.h"
26#include "PacketBuffer.h"
27
28namespace std{
29  bool operator<(ENetAddress a, ENetAddress b);
30}
31
32namespace network{
33  //
34#define NETWORK_PORT 55556
35#define NETWORK_MAX_CONNECTIONS 50
36#define NETWORK_WAIT_TIMEOUT 5000
37#define NETWORK_SEND_WAIT 5
38
39  struct ClientList{
40    ENetEvent *event;
41    int ID;
42    ClientList *next;
43  };
44 
45  class ConnectionManager{
46    public:
47    ConnectionManager();
48    ConnectionManager(int port, const char *address);
49    ConnectionManager(int port, std::string address);
50    ENetPacket *getPacket(ENetAddress &address); // thread1
51    ENetPacket *getPacket(int &clientID);
52    bool queueEmpty();
53    void createListener();
54    bool quitListener();
55    bool addPacket(ENetPacket *packet, ENetPeer *peer);
56    bool addPacket(ENetPacket *packet, int ID);
57    bool addPacketAll(ENetPacket *packet);
58    bool sendPackets(ENetEvent *event);
59    bool sendPackets();
60    private:
61    bool clientDisconnect(ENetPeer *peer);
62    bool clientDisconnect(ENetPeer peer);
63    bool processData(ENetEvent *event);
64    bool addClient(ENetEvent *event);
65    void receiverThread();
66    void disconnectClients();
67    int getClientID(ENetPeer peer);
68    int getClientID(ENetAddress address);
69    ENetPeer getClientPeer(int clientID);
70    PacketBuffer buffer;
71   
72    ENetHost *server;
73    ENetAddress bindAddress;
74   
75    bool quit; // quit-variable (communication with threads)
76    std::map<ENetAddress, int> clientMap;
77    std::map<ENetAddress, ENetPeer> peerMap;
78    std::vector<ENetAddress> clientVector;
79  };
80
81
82
83
84
85
86
87
88}
89
90#endif
Note: See TracBrowser for help on using the repository browser.