source: source/ariba/DataMessage.h@ 9736

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

almost forgot to commit: doxygen modules :)

File size: 3.3 KB
RevLine 
[2393]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/**
[9684]23 * \addtogroup public
24 * @{
[2393]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:
[7535]37 void* data; //< internal buffer pointer
38 size_t size; //< internal buffer pointer size
[2393]39public:
[7535]40 static const DataMessage UNSPECIFIED; //< default implementation of a data message
[2393]41
[7535]42 /**
43 * Default constructor for a data message
44 */
[2393]45 inline DataMessage() {
46 this->data = NULL;
47 this->size = 0;
48 }
49
[7535]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 */
[2393]55 inline DataMessage( const void* data, const size_t size ) {
56 this->data = const_cast<void*>(data);
57 this->size = size;
58 }
59
[7535]60 /**
61 * Copy constructor for a data message
62 * @param message The other message to copy from
63 */
[7497]64 inline DataMessage(const DataMessage& message){
65 this->data = message.data;
66 this->size = message.size;
67 }
68
[2393]69#ifdef USE_MESSAGE_UTILITY
[7535]70 /**
71 * Construct a data message from a normal message
72 * @param message The normal message to store
73 */
[2393]74 inline DataMessage( const Message* message ) {
75 this->data = (void*)const_cast<Message*>(message);
76 this->size = ~0;
77 }
78
[7535]79 /**
80 * Construct a data message from a normal message
81 * @param message The normal message to store
82 */
[2473]83 inline DataMessage( const Message& message ) {
84 this->data = (void*)const_cast<Message*>(&message);
85 this->size = ~0;
86 }
87
[7535]88 /**
89 * Get the internal message when constructued through one
90 * @return pointer to the message
91 */
[2393]92 inline Message* getMessage() const {
[7499]93 if (isData()) {
94 return new Message( Data((uint8_t*)data,size*8) );
95 }
[2393]96 return (Message*)data;
97 }
98
[7535]99 /**
100 * Conversion function to convert to Message*
101 * @return internal message
102 */
[2393]103 inline operator Message* () const {
[7499]104 return getMessage();
[2393]105 }
106#endif
107
[7535]108 /**
109 * Is the data message a normal message?
110 * @return true, if the data message is a normal message
111 */
[2393]112 inline bool isMessage() const {
[7500]113 return size == ~(size_t)0;
[2393]114 }
115
[7535]116 /**
117 * Is the data message a data message
118 * @return true, if the data message is not a normal message
119 */
[2393]120 inline bool isData() const {
[7500]121 return !isMessage();
[2393]122 }
123
[7535]124 /**
125 * Directly access the internal data pointer
126 * @return internal data pointer
127 */
[2393]128 inline void* getData() const {
129 return data;
130 }
131
[7535]132 /**
133 * Get the size of the internal buffer
134 * @return internal buffer size
135 */
[2393]136 inline size_t getSize() const {
137 return size;
138 }
139
[7535]140 /**
141 * Is the data message invalid?
142 * @return true, if data message is invalid
143 */
[2393]144 inline bool isUnspecified() const {
145 return data == NULL;
146 }
[7535]147
[2393]148};
[2435]149
[2393]150} // namespace ariba
151
[9684]152/** @} */
153
[2393]154#endif /* DATAMESSAGE_H_ */
Note: See TracBrowser for help on using the repository browser.