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 {
33 template <u
int16_t tag>
44 template <
typename Message> Message&
get();
45 template <
typename Message> Message
const&
get()
const;
46 template <
typename Message>
void setPayload(Message
const&);
47 template <
typename Message,
typename ...Args>
void setPayloadInPlace(Args&& ... args);
57 uint64_t reserved : 48;
59 } __attribute__((packed));
60 static_assert(
sizeof(Scratchpad) ==
sizeof(reserved2) +
sizeof(reserved),
"");
61 static_assert(
sizeof(Scratchpad::seq) ==
sizeof(reserved2) +
sizeof(reserved),
"");
62 Scratchpad& scratchpad() {
return *
reinterpret_cast<Scratchpad*
>(&reserved2);}
63 Scratchpad
const& scratchpad()
const{
return *
reinterpret_cast<Scratchpad const*
>(&reserved2);}
65 std::ostream& operator << (std::ostream& os,
MessageHead const & h) {
66 return os << h.scratchpad().reserved <<
' ' << h.typeTag;
68 } __attribute__((packed));
69 static_assert(
sizeof(
MessageHead) == 8,
"pakcing issue?");
71 template <
typename Message>
73 template <
typename ...Args>
76 , payload(std::forward<Args>(args)...) {
77 static_assert(std::is_class<Message>::value,
"wrong type to wrap");
82 std::ostream& operator << (std::ostream& os, MessageWrap<Message>
const & w) {
83 return os << static_cast<MessageHead const&>(w) <<
' ' << w.payload;
87 template <
typename Message>
93 template <
typename Message>
95 MessageHead::get()
const{
99 template <
typename Message>
102 setPayload(Message
const& m) {
103 new (&get<Message>()) Message(m);
104 typeTag = Message::typeTag;
107 template <
typename Message,
typename ...Args>
110 setPayloadInPlace(Args&& ... args) {
111 new (&get<Message>()) Message(std::forward<Args>(args)...);
112 typeTag = Message::typeTag;
119 template <
size_t MaxStreamableSize>
122 char payload[MaxStreamableSize];
123 } __attribute__((__may_alias__, packed));
140 ts[0] = (time::SysTime::now());
145 std::ostream& operator << (std::ostream& os,
Trace const & t) {
146 for (
auto i = 0u; i < t.tsIndex; ++i) os << t.ts[i] <<
' ';
153 MessageWrap(uint16_t tag,
void const* bytes,
size_t len)
155 memcpy(&payload, bytes, len);
160 std::ostream& operator << (std::ostream& os, MessageWrap<JustBytes>
const & w) {
161 return os << static_cast<MessageHead const&>(w) <<
" *";
196 : afterConsumedCleanupFunc(nullptr)
197 , attachment(nullptr)
203 if (afterConsumedCleanupFunc) {
204 afterConsumedCleanupFunc(
this);
205 afterConsumedCleanupFunc =
nullptr;
216 size_t map(
char const* fileName);
217 AfterConsumedCleanupFunc afterConsumedCleanupFunc;
236 return os <<
"hasMemoryAttachment " << m.attachment <<
' ' << m.len;
246 ::free(a->attachment);
247 a->attachment =
nullptr;
249 } __attribute__((aligned (8)));
259 return os <<
"StartAttachmentTrain " << m.underlyingMessageTypeTag
260 <<
' ' << m.att <<
' ' << m.segCount;
262 } __attribute__((aligned(8)));
269 std::ostream& operator << (std::ostream& os,
MemorySeg const & m) {
270 return os <<
"MemorySeg " << m.seg <<
' ' << m.len;
272 } __attribute__((packed));
Definition: Message.hpp:152
hasMemoryAttachment(char const *fileName)
file mapped memory
Definition: Message.hpp:195
each message type has 16 bit tag
Definition: Message.hpp:34
hasMemoryAttachment()
default ctor
Definition: Message.hpp:182
Definition: Message.hpp:120
Definition: Message.hpp:115
Definition: Message.hpp:38
A special type of message.
Definition: Message.hpp:132
Definition: Message.hpp:251
hmbdc system messages use tag values less than this one
Definition: Message.hpp:278
Definition: Message.hpp:137
void unmap()
does the reverse of map
Definition: Message.hpp:228
Definition: Message.hpp:72
Definition: Message.hpp:264
if a specific hmbdc network transport (for example tcpcast, rmcast, and rnetmap) supports message wit...
Definition: Message.hpp:175