Nebula
Loading...
Searching...
No Matches
message.h
Go to the documentation of this file.
1#pragma once
2//------------------------------------------------------------------------------
17#include "core/refcounted.h"
18#include "io/binaryreader.h"
19#include "io/binarywriter.h"
20#include "messaging/id.h"
22
23//------------------------------------------------------------------------------
27#define __DeclareMsgId \
28public:\
29 static Messaging::Id Id; \
30 virtual const Messaging::Id& GetId() const;\
31private:
32
33#define __ImplementMsgId(type) \
34 Messaging::Id type::Id; \
35 const Messaging::Id& type::GetId() const { return type::Id; }
36
37//------------------------------------------------------------------------------
38namespace Messaging
39{
40class MessageReader;
41class MessageWriter;
42class Port;
43
45{
48public:
50 Message();
52 bool CheckId(const Messaging::Id& id) const;
54 virtual void Encode(const Ptr<IO::BinaryWriter>& writer);
56 virtual void Decode(const Ptr<IO::BinaryReader>& reader);
58 void SetHandled(bool b);
60 bool Handled() const;
62 void SetDeferred(bool b);
64 bool IsDeferred() const;
66 void SetDeferredHandled(bool b);
68 bool DeferredHandled() const;
70 bool GetDistribute() const;
72 void SetDistribute(bool b);
73protected:
74 volatile int handled;
78};
79
80//------------------------------------------------------------------------------
83inline bool
85{
86 return (id == this->GetId());
87}
88
89//------------------------------------------------------------------------------
92inline void
97
98//------------------------------------------------------------------------------
101inline bool
103{
104 return 0 != this->handled;
105}
106
107//------------------------------------------------------------------------------
110inline void
112{
113 this->deferred = b;
114}
115
116//------------------------------------------------------------------------------
119inline bool
121{
122 return this->deferred;
123}
124
125//------------------------------------------------------------------------------
128inline void
130{
131 this->deferredHandled = b;
132}
133
134//------------------------------------------------------------------------------
137inline bool
139{
140 return this->deferredHandled;
141}
142
143//------------------------------------------------------------------------------
146inline bool
148{
149 return distribute;
150}
151
152//------------------------------------------------------------------------------
155inline void
157{
158 this->distribute = b;
159}
160
161} // namespace Messaging
162//------------------------------------------------------------------------------
The common base class of Nebula.
Definition refcounted.h:38
A message identifier.
Definition id.h:19
Messages are packets of data which can be sent to a message port.
Definition message.h:45
virtual void Encode(const Ptr< IO::BinaryWriter > &writer)
encode message into a stream
Definition message.cc:30
void SetDistribute(bool b)
enable distribution over network
Definition message.h:156
bool deferred
Definition message.h:75
__DeclareClass(Message)
void SetDeferred(bool b)
set deferred flag
Definition message.h:111
bool deferredHandled
Definition message.h:76
void SetHandled(bool b)
set the handled flag
Definition message.h:93
bool DeferredHandled() const
get the deferred handled flag
Definition message.h:138
bool CheckId(const Messaging::Id &id) const
return true if message is of the given id
Definition message.h:84
virtual void Decode(const Ptr< IO::BinaryReader > &reader)
decode message from a stream
Definition message.cc:39
volatile int handled
Definition message.h:74
bool GetDistribute() const
should this message be distributed over the network
Definition message.h:147
Message()
constructor
Definition message.cc:17
__DeclareMsgId
Definition message.h:47
bool distribute
Definition message.h:77
bool Handled() const
return true if the message has been handled
Definition message.h:102
void SetDeferredHandled(bool b)
set the deferred handled flag
Definition message.h:129
bool IsDeferred() const
get deferred flag
Definition message.h:120
Nebula's smart pointer class which manages the life time of RefCounted objects.
Definition ptr.h:38
Definition asyncport.cc:10
int Exchange(int volatile *dest, int value)
interlocked exchange
Definition gccinterlocked.cc:94