Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/presentation2/src/libraries/network/Connection.h @ 7795

Last change on this file since 7795 was 7788, checked in by scheusso, 14 years ago

merged network5 into presentation2 branch (untested)

  • Property svn:eol-style set to native
File size: 3.1 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
[7788]45#include <deque>
46
47namespace boost
48{
49  class thread;
50  class mutex;
51}
52
[3214]53namespace orxonox
54{
[7788]55  const unsigned int NETWORK_PORT                   = 55556;
56  const unsigned int NETWORK_MAX_CONNECTIONS        = 50;
57  const unsigned int NETWORK_WAIT_TIMEOUT           = 1;
58  const unsigned int NETWORK_MAX_QUEUE_PROCESS_TIME = 5;
59 
60  namespace outgoingEventType
61  {
62    enum Value
63    {
64      sendPacket      = 1,
65      disconnectPeer  = 2,
66      broadcastPacket = 3
67    };
68   
69  }
70 
71  struct _NetworkExport outgoingEvent
72  {
73    ENetPeer*                 peer;
74    outgoingEventType::Value  type;
75    ENetPacket*               packet;
76    ENetChannelID             channelID;
77  };
78 
79  class _NetworkExport Connection
80  {
[3214]81  public:
82    virtual ~Connection();
[6417]83
[7788]84    void addPacket(ENetPacket *packet, ENetPeer *peer, uint8_t channelID);
85    void broadcastPacket(ENetPacket* packet, uint8_t channelID);
86//     ENetHost* getHost(){ return this->host_; }
[3214]87
88  protected:
89    Connection();
[7163]90//     static Connection* getInstance(){ return Connection::instance_; }
[6417]91
[7788]92//     int service(ENetEvent* event);
93    void startCommunicationThread();
94    void stopCommunicationThread();
95    void communicationThread();
[5929]96    virtual void disconnectPeer(ENetPeer *peer);
[7788]97   
98    void enableCompression();
[6417]99
[3214]100    void processQueue();
[5929]101    virtual void addPeer(ENetEvent* event)=0;
102    virtual void removePeer(ENetEvent* event)=0;
[7788]103    virtual void processPacket( packet::Packet* packet)=0;
104    virtual packet::Packet* createPacket(ENetEvent* event);
[6417]105
[7788]106    ENetHost*                   host_;
[3214]107  private:
[7788]108    boost::thread*              communicationThread_;
109    bool                        bCommunicationThreadRunning_;
110    ENetAddress*                bindAddress_;
111    std::deque<ENetEvent>       incomingEvents_;
112    std::deque<outgoingEvent>   outgoingEvents_;
113    boost::mutex*               incomingEventsMutex_;
114    boost::mutex*               outgoingEventsMutex_;
[3214]115
[7163]116//     static Connection *instance_;
[3214]117
118  };
119
120}
121
122#endif /* _Connection_H__ */
Note: See TracBrowser for help on using the repository browser.