Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

Last change on this file since 380 was 380, checked in by scheusso, 16 years ago

problem in connectionmanager

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 network{
29  //
30#define NETWORK_PORT 55556
31#define NETWORK_MAX_CONNECTIONS 50
32#define NETWORK_WAIT_TIMEOUT 5000
33#define NETWORK_SEND_WAIT 5
34
35  struct ClientList{
36    ENetEvent *event;
37    int ID;
38    ClientList *next;
39  };
40
41  class ConnectionManager{
42    public:
43    ConnectionManager();
44    ConnectionManager(int port, const char *address);
45    ConnectionManager(int port, std::string address);
46    ENetPacket *getPacket(ENetAddress &address); // thread1
47    ENetPacket *getPacket(int &clientID);
48    bool queueEmpty();
49    void createListener();
50    bool quitListener();
51    bool addPacket(ENetPacket *packet, ENetPeer *peer);
52    bool addPacket(ENetPacket *packet, int ID);
53    bool addPacketAll(ENetPacket *packet);
54    bool sendPackets(ENetEvent *event);
55    bool sendPackets();
56    private:
57    bool clientDisconnect(ENetPeer *peer);
58    bool clientDisconnect(ENetPeer peer);
59    bool processData(ENetEvent *event);
60    bool addClient(ENetEvent *event);
61    void receiverThread();
62    void disconnectClients();
63    int getClientID(ENetPeer peer);
64    int getClientID(ENetAddress address);
65    ENetPeer getClientPeer(int clientID);
66    PacketBuffer buffer;
67   
68    ENetHost *server;
69    ENetAddress bindAddress;
70   
71    bool quit; // quit-variable (communication with threads)
72    std::map<ENetAddress, int> clientMap;
73    std::map<ENetAddress, ENetPeer> peerMap;
74    std::vector<ENetAddress> clientVector;
75  };
76
77
78
79
80
81
82
83
84}
85
86#endif
Note: See TracBrowser for help on using the repository browser.