Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/network5/src/libraries/network/Connection.h @ 7777

Last change on this file since 7777 was 7777, checked in by scheusso, 13 years ago

some () structural changes
some functional changes (GamestateClient replaced through GamestateManager on client)
reliable packets get buffered until a recent gamestate arrived and got processed

  • Property svn:eol-style set to native
File size: 3.1 KB
Line 
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
45#include <deque>
46
47namespace boost
48{
49  class thread;
50  class mutex;
51}
52
53namespace orxonox
54{
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  {
81  public:
82    virtual ~Connection();
83
84    void addPacket(ENetPacket *packet, ENetPeer *peer, uint8_t channelID);
85    void broadcastPacket(ENetPacket* packet, uint8_t channelID);
86//     ENetHost* getHost(){ return this->host_; }
87
88  protected:
89    Connection();
90//     static Connection* getInstance(){ return Connection::instance_; }
91
92//     int service(ENetEvent* event);
93    void startCommunicationThread();
94    void stopCommunicationThread();
95    void communicationThread();
96    virtual void disconnectPeer(ENetPeer *peer);
97   
98    void enableCompression();
99
100    void processQueue();
101    virtual void addPeer(ENetEvent* event)=0;
102    virtual void removePeer(ENetEvent* event)=0;
103    virtual void processPacket( packet::Packet* packet)=0;
104    virtual packet::Packet* createPacket(ENetEvent* event);
105
106    ENetHost*                   host_;
107  private:
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_;
115
116//     static Connection *instance_;
117
118  };
119
120}
121
122#endif /* _Connection_H__ */
Note: See TracBrowser for help on using the repository browser.