Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/trunk/src/network/packet/Packet.h @ 2520

Last change on this file since 2520 was 2171, checked in by landauf, 16 years ago

merged revisions 2111-2170 from objecthierarchy branch back to trunk.

  • Property svn:eol-style set to native
File size: 2.7 KB
RevLine 
[1701]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 <scheusso [at] ee.ethz.ch>, (C) 2008
24 *   Co-authors:
25 *      ...
26 *
27 */
28#ifndef NETWORKPACKET_H
29#define NETWORKPACKET_H
30
[2171]31#include "network/NetworkPrereqs.h"
[2087]32
[1711]33#include <map>
[1701]34#include <enet/enet.h>
[2171]35#include <boost/thread/recursive_mutex.hpp>
[1701]36
[1907]37#include "util/Integers.h"
38
[2171]39namespace orxonox {
[1701]40
41namespace packet{
[2087]42
[1701]43namespace ENUM{
44  enum Direction{
45    Incoming,
46    Outgoing,
47    Bidirectional
48  };
49  enum Type{
50    Acknowledgement,
51    Gamestate,
52    ClassID,
[1705]53    Chat,
[1907]54    Welcome,
55    DeleteObjects
[1701]56  };
57}
[2087]58
[1701]59/**
60        @author Oliver Scheuss <scheusso [at] ee.ethz.ch>
61*/
[2087]62class _NetworkExport Packet{
[1701]63  public:
[1711]64    Packet(const Packet &p);
[1709]65    virtual ~Packet();
[1711]66    static Packet *createPacket(ENetPacket *packet, ENetPeer *peer);
67    static void deletePacket(ENetPacket *packet);
[2087]68
[1711]69    virtual unsigned char *getData(){ return data_; };
70    virtual unsigned int getSize() const =0;
71    virtual bool process()=0;
72    enet_uint32 getFlags()
73      { return flags_; }
74    int getClientID()
75      { return clientID_; }
76    void setClientID( int id )
77      { clientID_ = id; }
[2087]78
[1701]79    bool send();
80  protected:
[1711]81    Packet();
[1907]82    Packet(uint8_t *data, unsigned int clientID);
[1713]83//    Packet(ENetPacket *packet, ENetPeer *peer);
[1711]84    enet_uint32 flags_;
[1907]85    unsigned int clientID_;
[1751]86    ENUM::Direction packetDirection_;
[2087]87    /** Pointer to the data. Be careful when deleting it because it might
88        point to a location that was allocated by ENet.
89        See bDataENetAllocated_ */
[1907]90    uint8_t *data_;
[2087]91    /** Tells whether data_ was allocated by ENet or ourselves.
92        data_ might no correlate with enetPacket_->data. */
93    bool bDataENetAllocated_;
[1701]94  private:
[2171]95    static std::map<size_t, Packet *> packetMap_;
96    //! Static mutex for any packetMap_ access
97    static boost::recursive_mutex packetMap_mutex;
[1701]98    ENetPacket *enetPacket_;
99};
100
101} //namespace packet
102
[2171]103} //namespace orxonox
[1701]104
105#endif
Note: See TracBrowser for help on using the repository browser.