Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/tutorial/src/libraries/network/Connection.h @ 10169

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