Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

Last change on this file since 8472 was 8327, checked in by scheusso, 14 years ago

merging network6 into trunk

  • 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 <scheusso [at] ee.ethz.ch>, (C) 2008
24 *   Co-authors:
25 *      ...
26 *
27 */
28#ifndef _NETWORK_Packet_H__
29#define _NETWORK_Packet_H__
30
31#include "network/NetworkPrereqs.h"
32#include <map>
33
34namespace orxonox
35{
36
37namespace packet
38{
39
40namespace Direction
41{
42  enum Value
43  {
44    Incoming,
45    Outgoing,
46    Bidirectional
47  };
48}
49namespace Type
50{
51  enum Value
52  {
53    Acknowledgement,
54    Chat,
55    ClassID,
56    DeleteObjects,
57    FunctionIDs,
58    FunctionCalls,
59    Gamestate,
60    Welcome
61  };
62}
63
64/**
65    @author Oliver Scheuss <scheusso [at] ee.ethz.ch>
66*/
67class _NetworkExport Packet
68{
69  public:
70    Packet(const Packet &p);
71    virtual ~Packet();
72    static Packet* createPacket(ENetPacket* packet, uint32_t peerID);
73    static void deletePacket(ENetPacket* packet);
74
75    virtual unsigned char* getData(){ return data_; };
76    virtual unsigned int getSize() const =0;
77    virtual bool process(orxonox::Host* host)=0;
78    inline uint32_t getFlags()
79      { return flags_; }
80    inline int getPeerID()
81      { return peerID_; }
82    inline void setPeerID( int id )
83      { peerID_ = id; }
84    inline bool isReliable()
85      { return this->flags_ & PacketFlag::Reliable; }
86    inline uint32_t getRequiredGamestateID()
87      { return this->requiredGamestateID_; }
88
89    virtual bool send(orxonox::Host* host);
90  protected:
91    Packet();
92    Packet(uint8_t *data, unsigned int peerID);
93//    Packet(ENetPacket *packet, ENetPeer *peer);
94    inline bool isDataENetAllocated() const
95      { return bDataENetAllocated_; }
96
97    uint32_t flags_;
98    unsigned int peerID_;
99    uint32_t requiredGamestateID_;
100    Direction::Value packetDirection_;
101    /** Pointer to the data. Be careful when deleting it because it might
102        point to a location that was allocated by ENet.
103        See bDataENetAllocated_ */
104    uint8_t *data_;
105    /** Tells whether data_ was allocated by ENet or ourselves.
106        data_ might no correlate with enetPacket_->data. */
107    bool bDataENetAllocated_;
108  private:
109    static std::map<size_t, Packet *> packetMap_;
110    static boost::mutex               packetMapMutex_;
111    ENetPacket *enetPacket_;
112};
113
114} //namespace packet
115
116} //namespace orxonox
117
118#endif /* _NETWORK_Packet_H__ */
Note: See TracBrowser for help on using the repository browser.