An Overlay-based
Virtual Network Substrate
SpoVNet

source: source/ariba/DataMessage.h @ 7468

Last change on this file since 7468 was 6919, checked in by mies, 14 years ago

Fixed tons of warnings when using CXXFLAGS="-Wall"!

File size: 1.8 KB
Line 
1#ifndef DATAMESSAGE_H_
2#define DATAMESSAGE_H_
3
4#define USE_MESSAGE_UTILITY
5
6#include <memory>
7#include <inttypes.h>
8
9// use message utility
10#ifdef USE_MESSAGE_UTILITY
11  #include "ariba/utility/messages.h"
12  namespace ariba {
13    typedef utility::Message Message;
14  }
15#endif
16
17namespace ariba {
18
19// define sequence number type
20typedef uint16_t seqnum_t;
21
22/**
23 * This class wraps different representations of a message. In its current
24 * version is allows to specify binary data (as void*) with a size specifying
25 * the number of bytes of data or an message object that can be
26 * serialized if necessary. The main idea is, that simulation environments
27 * do not necessarily need to serialize messages.
28 *
29 * For performance reasons methods of this class are inlined where possible!
30 *
31 * @author Sebastian Mies <mies@tm.uka.de>
32 */
33class DataMessage {
34private:
35        void* data;
36        size_t size;
37public:
38        static const DataMessage UNSPECIFIED;
39
40        inline DataMessage() {
41                this->data = NULL;
42                this->size = 0;
43        }
44
45        inline DataMessage( const void* data, const size_t size ) {
46                this->data = const_cast<void*>(data);
47                this->size = size;
48        }
49
50#ifdef USE_MESSAGE_UTILITY
51        inline DataMessage( const Message* message ) {
52                this->data = (void*)const_cast<Message*>(message);
53                this->size = ~0;
54        }
55
56        inline DataMessage( const Message& message ) {
57                this->data = (void*)const_cast<Message*>(&message);
58                this->size = ~0;
59        }
60
61        inline Message* getMessage() const {
62                return (Message*)data;
63        }
64
65        inline operator Message* () const {
66                return (Message*)data;
67        }
68#endif
69
70        inline bool isMessage() const {
71                return size >= 0;
72        }
73
74        inline bool isData() const {
75                return size == ~(size_t)0;
76        }
77
78        inline void* getData() const {
79                return data;
80        }
81
82        inline size_t getSize() const {
83                return size;
84        }
85
86        inline bool isUnspecified() const {
87                return data == NULL;
88        }
89};
90
91} // namespace ariba
92
93#endif /* DATAMESSAGE_H_ */
Note: See TracBrowser for help on using the repository browser.