1 #include "hmbdc/Copyright.hpp" 4 #include "hmbdc/time/Time.hpp" 11 namespace hmbdc {
namespace app {
29 template <u
int16_t tag>
40 template <
typename Message> Message&
get();
41 template <
typename Message> Message
const&
get()
const;
42 template <
typename Message>
void setPayload(Message
const&);
43 template <
typename Message,
typename ...Args>
void setPayloadInPlace(Args&& ... args);
49 std::ostream& operator << (std::ostream& os,
MessageHead const & h) {
50 return os << h.reserved <<
' ' << h.typeTag;
52 } __attribute__((packed));
54 template <
typename Message>
56 template <
typename ...Args>
59 , payload(std::forward<Args>(args)...) {
60 static_assert(std::is_class<Message>::value,
"wrong type to wrap");
65 std::ostream& operator << (std::ostream& os, MessageWrap<Message>
const & w) {
66 return os << static_cast<MessageHead const&>(w) <<
' ' << w.payload;
70 template <
typename Message>
76 template <
typename Message>
78 MessageHead::get()
const{
82 template <
typename Message>
85 setPayload(Message
const& m) {
86 new (&get<Message>()) Message(m);
87 typeTag = Message::typeTag;
90 template <
typename Message,
typename ...Args>
93 setPayloadInPlace(Args&& ... args) {
94 new (&get<Message>()) Message(std::forward<Args>(args)...);
95 typeTag = Message::typeTag;
102 template <
size_t MaxStreamableSize>
105 char payload[MaxStreamableSize];
106 } __attribute__((__may_alias__, packed));
123 ts[0] = (time::SysTime::now());
128 std::ostream& operator << (std::ostream& os,
Trace const & t) {
129 for (
auto i = 0u; i < t.tsIndex; ++i) os << t.ts[i] <<
' ';
136 MessageWrap(uint16_t tag,
void const* bytes,
size_t len)
138 memcpy(&payload, bytes, len);
143 std::ostream& operator << (std::ostream& os, MessageWrap<JustBytes>
const & w) {
144 return os << static_cast<MessageHead const&>(w) <<
" *";
189 size_t map(
char const* fileName);
190 AfterConsumedCleanupFunc afterConsumedCleanupFunc;
214 ::free(a->attachment);
215 a->attachment =
nullptr;
220 return os <<
"hasMemoryAttachment " << m.attachment <<
' ' << m.len;
222 } __attribute__((aligned (8)));
226 uint16_t underlyingMessageTypeTag;
232 return os <<
"StartAttachmentTrain " << m.underlyingMessageTypeTag
233 <<
' ' << m.att <<
' ' << m.segCount;
235 } __attribute__((aligned(8)));
242 std::ostream& operator << (std::ostream& os,
MemorySeg const & m) {
243 return os <<
"MemorySeg " << m.seg <<
' ' << m.len;
245 } __attribute__((packed));
Definition: Message.hpp:135
hasMemoryAttachment(char const *fileName)
file mapped memory
Definition: Message.hpp:178
each message type has 16 bit tag
Definition: Message.hpp:30
hasMemoryAttachment()
default ctor
Definition: Message.hpp:165
Definition: Message.hpp:103
Definition: Message.hpp:98
Definition: Message.hpp:34
A special type of message.
Definition: Message.hpp:115
Definition: Message.hpp:224
hmbdc system messages use tag values less than this one
Definition: Message.hpp:251
Definition: Message.hpp:120
void unmap()
does the reverse of map
Definition: Message.hpp:201
Definition: Message.hpp:55
Definition: Message.hpp:237
if a specific hmbdc network transport (for example tcpcast) supports message with memory attachment...
Definition: Message.hpp:158