36#ifndef MSG_PACKET_H_INCLUDED
37#define MSG_PACKET_H_INCLUDED
41#include "memutils/common_utils/common_types.h"
42#include "memutils/common_utils/common_assert.h"
44#include "memutils/message/type_holder.h"
47#include "get_cpu_id.h"
49#define GET_CPU_ID() (0)
50#define MEMORY_BARRIER() {;}
55typedef uint16_t MsgType;
56typedef uint16_t MsgQueId;
57typedef uint8_t MsgCpuId;
58typedef uint8_t MsgFlags;
70#define MSG_PARAM_TYPE_MATCH_CHECK false
81 static const MsgFlags MsgFlagNull = 0x00;
85 static const MsgFlags MsgFlagWaitParam = 0x80;
89 static const MsgFlags MsgFlagTypedParam = 0x40;
90 MsgPacketHeader(MsgType type, MsgQueId reply, MsgFlags flags, uint16_t size = 0) :
93 m_src_cpu(GET_CPU_ID()),
97 MsgType getType()
const {
return m_type; }
98 MsgQueId getReply()
const {
return m_reply; }
99 MsgCpuId getSrcCpu()
const {
return m_src_cpu; }
100 MsgFlags getFlags()
const {
return m_flags; }
101 uint16_t getParamSize()
const {
return m_param_size; }
102 void popParamNoDestruct() { m_param_size = 0; }
105 bool isSelfCpu()
const {
return GET_CPU_ID() == getSrcCpu(); }
106 bool isTypedParam()
const {
return (m_flags & MsgFlagTypedParam) != 0; }
113 uint16_t m_param_size;
128 m_param_size(param_size) {}
129 const void* getParam()
const {
return m_param; }
130 size_t getParamSize()
const {
return m_param_size; }
146 T param = peekParam<T>();
152 const T& peekParam()
const {
153 D_ASSERT2(
sizeof(T) == getParamSize(),
AssertParamLog(AssertIdSizeError,
sizeof(T), getParamSize()));
154 if (isTypeCheckEnable()) {
155 return reinterpret_cast<const TypeHolderBase*
>(&m_param[0])->
template get<T>();
157 return *
reinterpret_cast<const T*
>(&m_param[0]);
162 const T& peekParamOther()
const {
163 D_ASSERT2(
sizeof(T) <= getParamSize(),
AssertParamLog(AssertIdSizeError,
sizeof(T), getParamSize()));
164 return peekParamAny<T>();
169 D_ASSERT2(
sizeof(T) == getParamSize(),
AssertParamLog(AssertIdSizeError,
sizeof(T), getParamSize()));
170 if (isTypeCheckEnable()) {
172 D_ASSERT2(p->template is_type<T>(),
173 AssertParamLog(AssertIdTypeUnmatch, (uint32_t)p->id(), (uint32_t)GET_TYPE_ID(T)));
174 p->~TypeHolderBase();
176 reinterpret_cast<T*
>(&m_param[0])->~T();
182 printf(
"T:%04x, R:%04x, C:%02x, F:%02x, S:%04x, P:",
183 m_type, m_reply, m_src_cpu, m_flags, m_param_size);
184 for (uint16_t i = 0; i < MIN(m_param_size, 16); ++i)
185 printf(
"%02x ", m_param[i]);
194 MsgPacket(MsgType type, MsgQueId reply, MsgFlags flags) :
200 void setParam(
const T& param,
bool type_check) {
202 m_flags |= MsgFlagTypedParam;
205 new (&m_param[0]) T(param);
207 m_param_size =
sizeof(T);
209 m_flags &= ~MsgFlagWaitParam;
213 D_ASSERT((param.getParam() != NULL) && (0 < param.getParamSize()));
214 memcpy(&m_param[0], param.getParam(), param.getParamSize());
215 m_param_size = param.getParamSize();
217 m_flags &= ~MsgFlagWaitParam;
220 bool isTypeCheckEnable()
const {
return MSG_PARAM_TYPE_MATCH_CHECK && isTypedParam(); }
225 const T& peekParamAny()
const {
226 if (isTypeCheckEnable()) {
227 return reinterpret_cast<const TypeHolderBase*
>(&m_param[0])->
template get_any<T>(
false);
229 return *
reinterpret_cast<const T*
>(&m_param[0]);
238 uint32_t peekParamHead()
const {
return peekParamAny<uint32_t>(); }
Message Library Class.
Definition: Message.h:88
Definition: MsgPacket.h:119
Definition: MsgPacket.h:142
Message Queue Class.
Definition: MsgQueBlock.h:72
Definition: MsgPacket.h:124
Definition: type_holder.h:53
Definition: type_holder.h:122
Definition: AssertInfo.h:210