Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

network is now multithreaded again
further testing needed

  • Property svn:eol-style set to native
File size: 3.0 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 processQueue();
99    virtual void addPeer(ENetEvent* event)=0;
100    virtual void removePeer(ENetEvent* event)=0;
101    virtual bool processPacket(ENetEvent* event);
102
103    ENetHost*                   host_;
104    boost::mutex*               incomingEventsMutex_;
105    boost::mutex*               outgoingEventsMutex_;
106  private:
107    boost::thread*              communicationThread_;
108    bool                        bCommunicationThreadRunning_;
109    ENetAddress*                bindAddress_;
110    std::deque<ENetEvent>       incomingEvents_;
111    std::deque<outgoingEvent>   outgoingEvents_;
112
113//     static Connection *instance_;
114
115  };
116
117}
118
119#endif /* _Connection_H__ */
Note: See TracBrowser for help on using the repository browser.