1 #include "hmbdc/Copyright.hpp" 4 #include "hmbdc/time/Time.hpp" 5 #include "hmbdc/Config.hpp" 6 #include "hmbdc/Endian.hpp" 10 #include <type_traits> 15 namespace hmbdc {
namespace app {
28 template <u
int16_t tag>
48 template <
typename Message> Message&
get();
49 template <
typename Message> Message
const&
get()
const;
50 template <
typename Message>
void setPayload(Message
const&);
51 template <
typename Message,
typename ...Args>
void setPayloadInPlace(Args&& ... args);
61 uint64_t reserved : 48;
63 } __attribute__((packed));
64 static_assert(
sizeof(Scratchpad) ==
sizeof(reserved2) +
sizeof(reserved),
"");
65 static_assert(
sizeof(Scratchpad::seq) ==
sizeof(reserved2) +
sizeof(reserved),
"");
66 Scratchpad& scratchpad() {
return *
reinterpret_cast<Scratchpad*
>(&reserved2);}
67 Scratchpad
const& scratchpad()
const{
return *
reinterpret_cast<Scratchpad const*
>(&reserved2);}
69 std::ostream& operator << (std::ostream& os,
MessageHead const & h) {
70 return os << h.scratchpad().reserved <<
' ' << h.typeTag;
72 } __attribute__((packed));
73 static_assert(
sizeof(
MessageHead) == 8,
"pakcing issue?");
75 template <
typename Message>
77 template <
typename ...Args>
80 , payload(std::forward<Args>(args)...) {
82 ,
"not a properly defined Message");
93 std::ostream& operator << (std::ostream& os, MessageWrap<Message>
const & w) {
94 return os << static_cast<MessageHead const&>(w) <<
' ' << w.payload;
98 template <
typename Message>
104 template <
typename Message>
106 MessageHead::get()
const{
110 template <
typename Message>
113 setPayload(Message
const& m) {
114 new (&get<Message>()) Message(m);
115 typeTag = Message::typeTag;
118 template <
typename Message,
typename ...Args>
121 setPayloadInPlace(Args&& ... args) {
122 new (&get<Message>()) Message(std::forward<Args>(args)...);
123 typeTag = Message::typeTag;
130 template <
size_t MaxStreamableSize>
133 char payload[MaxStreamableSize];
134 } __attribute__((__may_alias__, packed));
151 ts[0] = (time::SysTime::now());
156 std::ostream& operator << (std::ostream& os,
Trace const & t) {
157 for (
auto i = 0u; i < t.tsIndex; ++i) os << t.ts[i] <<
' ';
164 MessageWrap(uint16_t tag,
void const* bytes,
size_t len)
166 memcpy(&payload, bytes, len);
171 std::ostream& operator << (std::ostream& os, MessageWrap<JustBytes>
const & w) {
172 return os << static_cast<MessageHead const&>(w) <<
" *";
207 : afterConsumedCleanupFunc(nullptr)
208 , attachment(nullptr)
214 if (afterConsumedCleanupFunc) {
215 afterConsumedCleanupFunc(
this);
216 afterConsumedCleanupFunc =
nullptr;
227 size_t map(
char const* fileName);
228 AfterConsumedCleanupFunc afterConsumedCleanupFunc;
247 return os <<
"hasMemoryAttachment " << m.attachment <<
' ' << m.len;
257 ::free(a->attachment);
258 a->attachment =
nullptr;
260 } __attribute__((aligned (8)));
270 return os <<
"StartAttachmentTrain " << m.underlyingMessageTypeTag
271 <<
' ' << m.att <<
' ' << m.segCount;
273 } __attribute__((aligned(8)));
280 std::ostream& operator << (std::ostream& os,
MemorySeg const & m) {
281 return os <<
"MemorySeg " << m.seg <<
' ' << m.len;
283 } __attribute__((packed));
Definition: Message.hpp:163
hasMemoryAttachment(char const *fileName)
file mapped memory
Definition: Message.hpp:206
each message type has 16 bit tag
Definition: Message.hpp:29
hasMemoryAttachment()
default ctor
Definition: Message.hpp:193
Definition: Message.hpp:131
Definition: Message.hpp:126
Definition: Message.hpp:42
A special type of message.
Definition: Message.hpp:143
Definition: Message.hpp:262
hmbdc system messages use tag values less than this one
Definition: Message.hpp:289
Definition: Message.hpp:148
void unmap()
does the reverse of map
Definition: Message.hpp:239
Definition: Message.hpp:76
Definition: Message.hpp:275
if a specific hmbdc network transport (for example tcpcast, rmcast, and rnetmap) supports message wit...
Definition: Message.hpp:186