source: source/ariba/DataMessage.h@ 7500

Last change on this file since 7500 was 7500, checked in by Christoph Mayer, 14 years ago
File size: 2.0 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/**
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
[7497]50 inline DataMessage(const DataMessage& message){
51 this->data = message.data;
52 this->size = message.size;
53 }
54
[2393]55#ifdef USE_MESSAGE_UTILITY
56 inline DataMessage( const Message* message ) {
57 this->data = (void*)const_cast<Message*>(message);
58 this->size = ~0;
59 }
60
[2473]61 inline DataMessage( const Message& message ) {
62 this->data = (void*)const_cast<Message*>(&message);
63 this->size = ~0;
64 }
65
[2393]66 inline Message* getMessage() const {
[7499]67 if (isData()) {
68 return new Message( Data((uint8_t*)data,size*8) );
69 }
[2393]70 return (Message*)data;
71 }
72
73 inline operator Message* () const {
[7499]74 return getMessage();
[2393]75 }
76#endif
77
78 inline bool isMessage() const {
[7500]79 return size == ~(size_t)0;
[2393]80 }
81
82 inline bool isData() const {
[7500]83 return !isMessage();
[2393]84 }
85
86 inline void* getData() const {
87 return data;
88 }
89
90 inline size_t getSize() const {
91 return size;
92 }
93
94 inline bool isUnspecified() const {
95 return data == NULL;
96 }
97};
[2435]98
[2393]99} // namespace ariba
100
101#endif /* DATAMESSAGE_H_ */
Note: See TracBrowser for help on using the repository browser.