forked from thejinchao/AxTrace
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAT4_Message.h
243 lines (188 loc) · 6.17 KB
/
AT4_Message.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
/***************************************************
AXIA|Trace4
(C) Copyright thecodeway.com 2019
***************************************************/
#pragma once
#include "AT4_Interface.h"
#include "AT4_Session.h"
class Message
{
public:
virtual bool build(const axtrace_head_s& head, cyclone::RingBuf* ringBuf) = 0;
virtual unsigned int getType(void) const = 0;
SessionPtr getSession(void) { return m_session; }
const SessionPtr getSession(void) const { return m_session; }
const axtrace_time_s& getTime(void) const { return m_time; }
protected:
SessionPtr m_session;
axtrace_time_s m_time;
protected:
static int _lua_get_type(lua_State *L);
static int _lua_get_process_id(lua_State *L);
static int _lua_get_thread_id(lua_State *L);
public:
Message(SessionPtr session, const axtrace_time_s& traceTime);
virtual ~Message();
public:
virtual void reccycleMessage(void) = 0;
};
typedef QVector< Message* > MessageVector;
#define DEFINE_POOL(Name) \
public: \
static int debugCounts(void) { return (int)s_messagePool.size(); } \
static Name* allocMessage(SessionPtr session, const axtrace_time_s& traceTime) \
{ \
if (s_messagePool.empty()) { \
return new Name(session, traceTime); \
} \
else { \
Name* msg = s_messagePool.front(); \
s_messagePool.pop_front(); \
msg->m_session = session; \
memcpy(&(msg->m_time), &traceTime, sizeof(axtrace_time_s)); \
return msg; \
} \
} \
virtual void reccycleMessage() \
{ \
m_session = nullptr; \
s_messagePool.push_back(this); \
} \
static void deletePool(void) \
{ \
for(auto msg : s_messagePool) { \
delete msg; \
} \
s_messagePool.clear(); \
} \
private: \
static QQueue<Name*> s_messagePool;
class ShakehandMessage : public Message
{
public:
virtual bool build(const axtrace_head_s& head, cyclone::RingBuf* ringBuf);
virtual unsigned int getType(void) const { return AXTRACE_CMD_TYPE_SHAKEHAND; }
int32_t getVersion(void) const { return m_version; }
unsigned int getProcessID(void) const { return m_processID; }
unsigned int getThreadID(void) const { return m_threadID; }
const QString& geetSessionName(void) const { return m_sessionName; }
private:
int32_t m_version;
uint32_t m_processID;
uint32_t m_threadID;
QString m_sessionName;
public:
ShakehandMessage(SessionPtr session, const axtrace_time_s& traceTime);
virtual ~ShakehandMessage();
DEFINE_POOL(ShakehandMessage);
};
class LogMessage : public Message
{
public:
static const char* MetaName;
static void _luaopen(lua_State *L);
virtual bool build(const axtrace_head_s& head, cyclone::RingBuf* ringBuf);
virtual unsigned int getType(void) const { return AXTRACE_CMD_TYPE_LOG; }
unsigned int getLogType(void) const { return m_logType; }
const QString& getLog(void) const { return m_log; }
private:
unsigned int m_logType;
QString m_log;
protected:
static int _lua_get_log_type(lua_State *L);
static int _lua_get_log(lua_State *L);
public:
LogMessage(SessionPtr session, const axtrace_time_s& traceTime);
virtual ~LogMessage();
DEFINE_POOL(LogMessage);
};
class ValueMessage : public Message
{
public:
static const char* MetaName;
static void _luaopen(lua_State *L);
virtual bool build(const axtrace_head_s& head, cyclone::RingBuf* ringBuf);
virtual unsigned int getType(void) const { return AXTRACE_CMD_TYPE_VALUE; }
const QString& getName(void) const { return m_name; }
void getValueAsString(QString& value) const;
private:
QString m_name;
unsigned int m_valueType;
size_t m_valueSize;
void* m_valueBuf;
enum { STANDARD_VALUE_SIZE = 32 };
unsigned char m_standValueBuf[STANDARD_VALUE_SIZE];
protected:
static int _lua_get_value(lua_State *L);
public:
ValueMessage(SessionPtr session, const axtrace_time_s& traceTime);
virtual ~ValueMessage();
DEFINE_POOL(ValueMessage);
};
class Begin2DSceneMessage : public Message
{
public:
static const char* MetaName;
static void _luaopen(lua_State *L);
virtual bool build(const axtrace_head_s& head, cyclone::RingBuf* ringBuf);
virtual unsigned int getType(void) const { return AXTRACE_CMD_TYPE_2D_BEGIN_SCENE; }
const QString& getSceneName(void) const { return m_sceneName; }
const QRectF& getSceneRect(void) const { return m_sceneRect; }
const QJsonObject& getSceneDefine(void) const { return m_sceneDefine; }
private:
QString m_sceneName;
QRectF m_sceneRect;
QJsonObject m_sceneDefine;
public:
Begin2DSceneMessage(SessionPtr session, const axtrace_time_s& traceTime);
virtual ~Begin2DSceneMessage();
DEFINE_POOL(Begin2DSceneMessage);
};
class Update2DActorMessage : public Message
{
public:
static const char* MetaName;
static void _luaopen(lua_State *L);
virtual bool build(const axtrace_head_s& head, cyclone::RingBuf* ringBuf);
virtual unsigned int getType(void) const { return AXTRACE_CMD_TYPE_2D_ACTOR; }
const QString& getSceneName(void) const { return m_sceneName; }
qint64 getActorID(void) const { return m_actorID; }
const QPointF& getActorPosition(void) const { return m_position; }
qreal getActorDir(void) const { return m_dir; }
quint32 getActorStyle(void) const { return m_style; }
const QString& getActorInfo(void) const { return m_actorInfo; }
private:
QString m_sceneName;
qint64 m_actorID;
QPointF m_position;
qreal m_dir;
quint32 m_style;
QString m_actorInfo;
protected:
static int _lua_get_actor_id(lua_State *L);
static int _lua_get_actor_position(lua_State *L);
static int _lua_get_actor_dir(lua_State *L);
static int _lua_get_actor_style(lua_State *L);
static int _lua_get_actor_info(lua_State *L);
public:
Update2DActorMessage(SessionPtr session, const axtrace_time_s& traceTime);
virtual ~Update2DActorMessage();
DEFINE_POOL(Update2DActorMessage);
};
class End2DSceneMessage : public Message
{
public:
static const char* MetaName;
static void _luaopen(lua_State *L);
virtual bool build(const axtrace_head_s& head, cyclone::RingBuf* ringBuf);
virtual unsigned int getType(void) const { return AXTRACE_CMD_TYPE_2D_END_SCENE; }
const QString& getSceneName(void) const { return m_sceneName; }
private:
QString m_sceneName;
protected:
static int _lua_get_actor_id(lua_State *L);
public:
End2DSceneMessage(SessionPtr session, const axtrace_time_s& traceTime);
virtual ~End2DSceneMessage();
DEFINE_POOL(End2DSceneMessage);
};