source: source/ariba/DataMessage.h@ 9982

Last change on this file since 9982 was 9684, checked in by mies, 14 years ago

almost forgot to commit: doxygen modules :)

File size: 3.3 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 * \addtogroup public
24 * @{
25 * This class wraps different representations of a message. In its current
26 * version is allows to specify binary data (as void*) with a size specifying
27 * the number of bytes of data or an message object that can be
28 * serialized if necessary. The main idea is, that simulation environments
29 * do not necessarily need to serialize messages.
30 *
31 * For performance reasons methods of this class are inlined where possible!
32 *
33 * @author Sebastian Mies <mies@tm.uka.de>
34 */
35class DataMessage {
36private:
37 void* data; //< internal buffer pointer
38 size_t size; //< internal buffer pointer size
39public:
40 static const DataMessage UNSPECIFIED; //< default implementation of a data message
41
42 /**
43 * Default constructor for a data message
44 */
45 inline DataMessage() {
46 this->data = NULL;
47 this->size = 0;
48 }
49
50 /**
51 * Constructor for a data message
52 * @param data Data buffer to carry in the message
53 * @param size Size of the buffer pointed to
54 */
55 inline DataMessage( const void* data, const size_t size ) {
56 this->data = const_cast<void*>(data);
57 this->size = size;
58 }
59
60 /**
61 * Copy constructor for a data message
62 * @param message The other message to copy from
63 */
64 inline DataMessage(const DataMessage& message){
65 this->data = message.data;
66 this->size = message.size;
67 }
68
69#ifdef USE_MESSAGE_UTILITY
70 /**
71 * Construct a data message from a normal message
72 * @param message The normal message to store
73 */
74 inline DataMessage( const Message* message ) {
75 this->data = (void*)const_cast<Message*>(message);
76 this->size = ~0;
77 }
78
79 /**
80 * Construct a data message from a normal message
81 * @param message The normal message to store
82 */
83 inline DataMessage( const Message& message ) {
84 this->data = (void*)const_cast<Message*>(&message);
85 this->size = ~0;
86 }
87
88 /**
89 * Get the internal message when constructued through one
90 * @return pointer to the message
91 */
92 inline Message* getMessage() const {
93 if (isData()) {
94 return new Message( Data((uint8_t*)data,size*8) );
95 }
96 return (Message*)data;
97 }
98
99 /**
100 * Conversion function to convert to Message*
101 * @return internal message
102 */
103 inline operator Message* () const {
104 return getMessage();
105 }
106#endif
107
108 /**
109 * Is the data message a normal message?
110 * @return true, if the data message is a normal message
111 */
112 inline bool isMessage() const {
113 return size == ~(size_t)0;
114 }
115
116 /**
117 * Is the data message a data message
118 * @return true, if the data message is not a normal message
119 */
120 inline bool isData() const {
121 return !isMessage();
122 }
123
124 /**
125 * Directly access the internal data pointer
126 * @return internal data pointer
127 */
128 inline void* getData() const {
129 return data;
130 }
131
132 /**
133 * Get the size of the internal buffer
134 * @return internal buffer size
135 */
136 inline size_t getSize() const {
137 return size;
138 }
139
140 /**
141 * Is the data message invalid?
142 * @return true, if data message is invalid
143 */
144 inline bool isUnspecified() const {
145 return data == NULL;
146 }
147
148};
149
150} // namespace ariba
151
152/** @} */
153
154#endif /* DATAMESSAGE_H_ */
Note: See TracBrowser for help on using the repository browser.