[1505] | 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, (C) 2007 |
---|
| 24 | * Co-authors: |
---|
| 25 | * ... |
---|
| 26 | * |
---|
| 27 | */ |
---|
| 28 | |
---|
| 29 | // |
---|
| 30 | // C++ Interface: PacketBuffer |
---|
| 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 | |
---|
| 41 | #ifndef _PacketBuffer_H__ |
---|
| 42 | #define _PacketBuffer_H__ |
---|
| 43 | |
---|
| 44 | #include "NetworkPrereqs.h" |
---|
| 45 | |
---|
[2756] | 46 | #ifndef WIN32_LEAN_AND_MEAN |
---|
| 47 | # define WIN32_LEAN_AND_MEAN |
---|
| 48 | #endif |
---|
| 49 | #define NOMINMAX // required to stop windows.h screwing up std::min definition |
---|
[1505] | 50 | #include <enet/enet.h> |
---|
| 51 | #include <boost/thread/recursive_mutex.hpp> |
---|
| 52 | |
---|
[2171] | 53 | namespace orxonox |
---|
[1505] | 54 | { |
---|
[2087] | 55 | struct _NetworkExport PacketEnvelope{ |
---|
[1505] | 56 | int length; |
---|
| 57 | int data; |
---|
| 58 | }; |
---|
| 59 | |
---|
[2087] | 60 | struct _NetworkExport QueueItem{ |
---|
[1505] | 61 | ENetEvent *event; |
---|
| 62 | //ENetAddress address; |
---|
| 63 | QueueItem *next; |
---|
| 64 | }; |
---|
| 65 | |
---|
[2087] | 66 | class _NetworkExport PacketBuffer{ |
---|
[1505] | 67 | public: |
---|
| 68 | PacketBuffer(); |
---|
| 69 | bool isEmpty(); |
---|
| 70 | bool isClosed(); |
---|
| 71 | void setClosed(bool value); |
---|
| 72 | void print(); |
---|
| 73 | // pops a packet from the queue |
---|
| 74 | //ENetPacket *pop(); |
---|
| 75 | //ENetPacket *pop(ENetAddress &address); |
---|
| 76 | ENetEvent *pop(); |
---|
| 77 | // pushs a packet to the queue |
---|
| 78 | bool push(ENetEvent *ev); |
---|
| 79 | |
---|
| 80 | private: |
---|
| 81 | QueueItem *first; |
---|
| 82 | QueueItem *last; |
---|
| 83 | bool closed; |
---|
| 84 | static boost::recursive_mutex mutex_; |
---|
| 85 | }; |
---|
| 86 | |
---|
| 87 | } //namespace |
---|
| 88 | #endif /* _PacketBuffer_H__ */ |
---|