Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/trunk/src/libraries/network/Connection.h @ 7957

Last change on this file since 7957 was 7801, checked in by dafrick, 14 years ago

Merging presentation2 branch back to trunk.

  • Property svn:eol-style set to native
File size: 3.2 KB
RevLine 
[3214]1/*
2 *   ORXONOX - the hottest 3D action shooter ever to exist
3 *                    > www.orxonox.net <
4 *
5 *
6 *   License notice:
7 *
8 *   This program is free software; you can redistribute it and/or
9 *   modify it under the terms of the GNU General Public License
10 *   as published by the Free Software Foundation; either version 2
11 *   of the License, or (at your option) any later version.
12 *
13 *   This program is distributed in the hope that it will be useful,
14 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
15 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16 *   GNU General Public License for more details.
17 *
18 *   You should have received a copy of the GNU General Public License
19 *   along with this program; if not, write to the Free Software
20 *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
21 *
22 *   Author:
23 *      Oliver Scheuss
24 *   Co-authors:
25 *      ...
26 *
27 */
28
29//
30// C++ Interface: Connection
31//
32// Description:
33//
34//
35// Author:  Oliver Scheuss, (C) 2007
36//
37// Copyright: See COPYING file that comes with this distribution
38//
39//
40#ifndef _Connection_H__
41#define _Connection_H__
42
43#include "NetworkPrereqs.h"
44
[7801]45#include <deque>
46#include <enet/enet.h>
47
48namespace boost
49{
50  class thread;
51  class mutex;
52}
53
[3214]54namespace orxonox
55{
[7801]56  const unsigned int NETWORK_PORT                   = 55556;
57  const unsigned int NETWORK_MAX_CONNECTIONS        = 50;
58  const unsigned int NETWORK_WAIT_TIMEOUT           = 1;
59  const unsigned int NETWORK_MAX_QUEUE_PROCESS_TIME = 5;
60 
61  namespace outgoingEventType
62  {
63    enum Value
64    {
65      sendPacket      = 1,
66      disconnectPeer  = 2,
67      broadcastPacket = 3
68    };
69   
70  }
71 
72  struct _NetworkExport outgoingEvent
73  {
74    ENetPeer*                 peer;
75    outgoingEventType::Value  type;
76    ENetPacket*               packet;
77    ENetChannelID             channelID;
78  };
79 
80  class _NetworkExport Connection
81  {
[3214]82  public:
83    virtual ~Connection();
[6417]84
[7801]85    void addPacket(ENetPacket *packet, ENetPeer *peer, uint8_t channelID);
86    void broadcastPacket(ENetPacket* packet, uint8_t channelID);
87//     ENetHost* getHost(){ return this->host_; }
[3214]88
89  protected:
90    Connection();
[7163]91//     static Connection* getInstance(){ return Connection::instance_; }
[6417]92
[7801]93//     int service(ENetEvent* event);
94    void startCommunicationThread();
95    void stopCommunicationThread();
96    void communicationThread();
[5929]97    virtual void disconnectPeer(ENetPeer *peer);
[7801]98   
99    void enableCompression();
[6417]100
[3214]101    void processQueue();
[5929]102    virtual void addPeer(ENetEvent* event)=0;
103    virtual void removePeer(ENetEvent* event)=0;
[7801]104    virtual void processPacket( packet::Packet* packet)=0;
105    virtual packet::Packet* createPacket(ENetEvent* event);
[6417]106
[7801]107    ENetHost*                   host_;
[3214]108  private:
[7801]109    boost::thread*              communicationThread_;
110    bool                        bCommunicationThreadRunning_;
111    ENetAddress*                bindAddress_;
112    std::deque<ENetEvent>       incomingEvents_;
113    std::deque<outgoingEvent>   outgoingEvents_;
114    boost::mutex*               incomingEventsMutex_;
115    boost::mutex*               outgoingEventsMutex_;
[3214]116
[7163]117//     static Connection *instance_;
[3214]118
119  };
120
121}
122
123#endif /* _Connection_H__ */
Note: See TracBrowser for help on using the repository browser.