source: source/ariba/DataMessage.h@ 2418

Last change on this file since 2418 was 2409, checked in by mies, 16 years ago

moved tidy & pingpong

File size: 1.7 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
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 Message* getMessage() const {
57 return (Message*)data;
58 }
59
60 inline operator Message* () const {
61 return (Message*)data;
62 }
63#endif
64
65 inline bool isMessage() const {
66 return size >= 0;
67 }
68
69 inline bool isData() const {
70 return size == ~0;
71 }
72
73 inline void* getData() const {
74 return data;
75 }
76
77 inline size_t getSize() const {
78 return size;
79 }
80
81 inline bool isUnspecified() const {
82 return data == NULL;
83 }
84};
85} // namespace ariba
86
87
88
89#endif /* DATAMESSAGE_H_ */
Note: See TracBrowser for help on using the repository browser.