eventInfo是對消息的抽象,根據(jù)不同的應用場景,event庫提供了三種類型的消息:
-
SimpleEventInfo: 只有一個消息號,沒有消息內(nèi)容,相當于一個信號。 -
ScatteredEventInfo:有消息號,有消息內(nèi)容,但是消息長度為無效值,沒看懂有啥用。 -
ConsecutiveEventInfo:既有消息號,又有消息內(nèi)容的消息。消息內(nèi)容既可以是一個結構體,也可以是一個內(nèi)存緩沖區(qū)。
event結構.PNG
EventInfo是一個接口:
DEFINE_ROLE(EventInfo)
{
ABSTRACT(EventId getEventId() const);
ABSTRACT(const void* getMsg() const);
ABSTRACT(size_t getMsgSize() const);
ABSTRACT(cub::Status updateEventId(const EventId) const);
};
BaseEventInfo提取了公共代碼,因為每個事件都有事件號(eventId):
struct BaseEventInfo : EventInfo
{
explicit BaseEventInfo(const EventId eventId);
OVERRIDE(EventId getEventId() const);
OVERRIDE(cub::Status updateEventId(const EventId id) const);
private:
mutable EventId eventId;
};
在Transaction DSL中我們依賴的是Event這個概念,Event提供了一個轉換構造函數(shù):
struct Event
{
Event();
Event(const EventInfo& info); // 轉換構造函數(shù)
EventId getEventId() const;
const void* getMsg() const;
size_t getMsgSize() const;
bool matches(const EventId eventId) const;
cub::Status updateEventId(const EventId) const;
void assignEventInfoTo(Event&) const;
const EventInfo& getEventInfo() const
{
return *info;
}
void consume() const;
bool isConsumed() const;
private:
const EventInfo* info;
mutable bool consumed;
};