Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

Last change on this file since 10255 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
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 */
[3214]28#ifndef _NETWORK_Packet_H__
29#define _NETWORK_Packet_H__
[1701]30
[2171]31#include "network/NetworkPrereqs.h"
[1711]32#include <map>
[1701]33
[8327]34namespace orxonox
35{
[1701]36
[8327]37namespace packet
38{
[2087]39
[8327]40namespace Direction
41{
42  enum Value
43  {
[1701]44    Incoming,
45    Outgoing,
46    Bidirectional
47  };
[3280]48}
[8327]49namespace Type
50{
51  enum Value
52  {
[1701]53    Acknowledgement,
[3084]54    Chat,
55    ClassID,
56    DeleteObjects,
57    FunctionIDs,
58    FunctionCalls,
[1701]59    Gamestate,
[3084]60    Welcome
[1701]61  };
62}
[2087]63
[1701]64/**
[6073]65    @author Oliver Scheuss <scheusso [at] ee.ethz.ch>
[1701]66*/
[8327]67class _NetworkExport Packet
68{
[1701]69  public:
[1711]70    Packet(const Packet &p);
[1709]71    virtual ~Packet();
[8327]72    static Packet* createPacket(ENetPacket* packet, uint32_t peerID);
73    static void deletePacket(ENetPacket* packet);
[2087]74
[8327]75    virtual unsigned char* getData(){ return data_; };
[1711]76    virtual unsigned int getSize() const =0;
[7801]77    virtual bool process(orxonox::Host* host)=0;
[3084]78    inline uint32_t getFlags()
[1711]79      { return flags_; }
[7801]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_; }
[2087]88
[7801]89    virtual bool send(orxonox::Host* host);
[1701]90  protected:
[1711]91    Packet();
[7801]92    Packet(uint8_t *data, unsigned int peerID);
[1713]93//    Packet(ENetPacket *packet, ENetPeer *peer);
[3084]94    inline bool isDataENetAllocated() const
95      { return bDataENetAllocated_; }
96
[2773]97    uint32_t flags_;
[7801]98    unsigned int peerID_;
99    uint32_t requiredGamestateID_;
[3280]100    Direction::Value packetDirection_;
[2087]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_ */
[1907]104    uint8_t *data_;
[2087]105    /** Tells whether data_ was allocated by ENet or ourselves.
106        data_ might no correlate with enetPacket_->data. */
107    bool bDataENetAllocated_;
[1701]108  private:
[2171]109    static std::map<size_t, Packet *> packetMap_;
[7801]110    static boost::mutex               packetMapMutex_;
[1701]111    ENetPacket *enetPacket_;
112};
113
114} //namespace packet
115
[2171]116} //namespace orxonox
[1701]117
[3214]118#endif /* _NETWORK_Packet_H__ */
Note: See TracBrowser for help on using the repository browser.