Skip to content

Commit e52facc

Browse files
authored
fixes issues with nulls in protobufs resulting in lopped messages (#10)
* add more logging to event dispatcher * add more logging to message dispatcher * Adds more log messages * fixes issues with nulls in protobufs resulting in lopped messages
1 parent 6a8ae34 commit e52facc

File tree

2 files changed

+28
-1
lines changed

2 files changed

+28
-1
lines changed

src/Events/EventDispatcher.cpp

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
#include "../Commands/JoinSecurityCommand.h"
2424
#include "../Commands/LeaveSecurityCommand.h"
2525
#include "../Shared/FactoryT.h"
26+
#include "../Logging/loguru.hpp"
2627
#include <Poco/Delegate.h>
2728
#include <assert.h>
2829

@@ -107,13 +108,15 @@ EventDispatcher::~EventDispatcher()
107108
// Helper(s)
108109
void EventDispatcher::Enqueue(Message* pMessage)
109110
{
111+
LOG_SCOPE_FUNCTION(8);
110112
m_anEventQueueMutex.lock();
111113
m_anEventQueue.push(pMessage);
112114
m_anEventQueueMutex.unlock();
113115
}
114116

115117
Message* EventDispatcher::Dequeue()
116118
{
119+
LOG_SCOPE_FUNCTION(8);
117120
Message* pMessage = NULL;
118121

119122
m_anEventQueueMutex.lock();
@@ -126,6 +129,8 @@ Message* EventDispatcher::Dequeue()
126129

127130
GameEventBuffer* EventDispatcher::CreateGameEvent(EntityGameEventBuffer_EntityGameEventBufferType eEntityGameEvent_EntityGameEventBufferType, AEntity* pEntity)
128131
{
132+
LOG_SCOPE_FUNCTION(8);
133+
LOG_F(8, "Entity Game Event");
129134
EntityGameEvent_Dependencies anEntityGameEvent_Dependencies(eEntityGameEvent_EntityGameEventBufferType, pEntity);
130135
GameEventBuffer* pGameEvent = m_anEntityGameEventFactory.Create(anEntityGameEvent_Dependencies);
131136

@@ -134,6 +139,8 @@ GameEventBuffer* EventDispatcher::CreateGameEvent(EntityGameEventBuffer_EntityGa
134139

135140
GameEventBuffer* EventDispatcher::CreateGameEvent(SecurityGameEventBuffer_SecurityGameEventBufferType eSecurityGameEvent_SecurityGameEventBufferType, const std::string& strUUID)
136141
{
142+
LOG_SCOPE_FUNCTION(8);
143+
LOG_F(8, "Security Game Event");
137144
SecurityGameEvent_Dependencies aSecurityGameEvent_Dependencies(eSecurityGameEvent_SecurityGameEventBufferType, strUUID);
138145
GameEventBuffer* pGameEvent = m_aSecurityGameEventFactory.Create(aSecurityGameEvent_Dependencies);
139146

@@ -143,6 +150,7 @@ GameEventBuffer* EventDispatcher::CreateGameEvent(SecurityGameEventBuffer_Securi
143150
// Dispatches all the events it has received to it's listeners
144151
void EventDispatcher::Dispatch()
145152
{
153+
LOG_SCOPE_FUNCTION(8);
146154
Message* pMessage = NULL;
147155
m_anEventQueueMutex.lock();
148156
while (!m_anEventQueue.empty())
@@ -157,75 +165,87 @@ void EventDispatcher::Dispatch()
157165
// Entity event response
158166
void EventDispatcher::HandlePodCreatedEvent(const void* pSender, Pod*& pPod)
159167
{
168+
LOG_SCOPE_FUNCTION(8);
160169
GameEventBuffer* pGameEvent = CreateGameEvent(EntityGameEventBuffer_EntityGameEventBufferType_CREATE, static_cast<AEntity*>(pPod));
161170
Enqueue(pGameEvent);
162171
}
163172

164173
void EventDispatcher::HandlePodUpdatedEvent(const void* pSender, Pod*& pPod)
165174
{
175+
LOG_SCOPE_FUNCTION(8);
166176
GameEventBuffer* pGameEvent = CreateGameEvent(EntityGameEventBuffer_EntityGameEventBufferType_UPDATE, static_cast<AEntity*>(pPod));
167177
Enqueue(pGameEvent);}
168178

169179
void EventDispatcher::HandlePodDestroyedEvent(const void* pSender, Pod*& pPod)
170180
{
181+
LOG_SCOPE_FUNCTION(8);
171182
GameEventBuffer* pGameEvent = CreateGameEvent(EntityGameEventBuffer_EntityGameEventBufferType_DESTROY, static_cast<AEntity*>(pPod));
172183
Enqueue(pGameEvent);}
173184

174185
void EventDispatcher::HandleBulletCreatedEvent(const void* pSender, Bullet*& pBullet)
175186
{
187+
LOG_SCOPE_FUNCTION(8);
176188
GameEventBuffer* pGameEvent = CreateGameEvent(EntityGameEventBuffer_EntityGameEventBufferType_CREATE, static_cast<AEntity*>(pBullet));
177189
Enqueue(pGameEvent);
178190
}
179191

180192
void EventDispatcher::HandleBulletUpdatedEvent(const void* pSender, Bullet*& pBullet)
181193
{
194+
LOG_SCOPE_FUNCTION(8);
182195
GameEventBuffer* pGameEvent = CreateGameEvent(EntityGameEventBuffer_EntityGameEventBufferType_UPDATE, static_cast<AEntity*>(pBullet));
183196
Enqueue(pGameEvent);
184197
}
185198

186199
void EventDispatcher::HandleBulletDestroyedEvent(const void* pSender, Bullet*& pBullet)
187200
{
201+
LOG_SCOPE_FUNCTION(8);
188202
GameEventBuffer* pGameEvent = CreateGameEvent(EntityGameEventBuffer_EntityGameEventBufferType_DESTROY, static_cast<AEntity*>(pBullet));
189203
Enqueue(pGameEvent);
190204
}
191205

192206
// Event Consumer event response
193207
void EventDispatcher::HandleJoinSecurityCommandFactoryCreatedEvent(const void* pSender, JoinSecurityCommand*& pJoinSecurityCommand)
194208
{
209+
LOG_SCOPE_FUNCTION(8);
195210
assert(pJoinSecurityCommand);
196211

197212
pJoinSecurityCommand->ExecutedEvent += Poco::Delegate<EventDispatcher, const std::string&>(this, &EventDispatcher::HandleJoinSecurityCommandExecutedEvent);
198213
}
199214

200215
void EventDispatcher::HandleJoinSecurityCommandFactoryDestroyedEvent(const void* pSender, JoinSecurityCommand*& pJoinSecurityCommand)
201216
{
217+
LOG_SCOPE_FUNCTION(8);
202218
assert(pJoinSecurityCommand);
203219

204220
pJoinSecurityCommand->ExecutedEvent -= Poco::Delegate<EventDispatcher, const std::string&>(this, &EventDispatcher::HandleJoinSecurityCommandExecutedEvent);
205221
}
206222

207223
void EventDispatcher::HandleLeaveSecurityCommandFactoryCreatedEvent(const void* pSender, LeaveSecurityCommand*& pLeaveSecurityCommand)
208224
{
225+
LOG_SCOPE_FUNCTION(8);
209226
assert(pLeaveSecurityCommand);
210227

211228
pLeaveSecurityCommand->ExecutedEvent += Poco::Delegate<EventDispatcher, const std::string&>(this, &EventDispatcher::HandleLeaveSecurityCommandExecutedEvent);
212229
}
213230

214231
void EventDispatcher::HandleLeaveSecurityCommandFactoryDestroyedEvent(const void* pSender, LeaveSecurityCommand*& pLeaveSecurityCommand)
215232
{
233+
LOG_SCOPE_FUNCTION(8);
216234
assert(pLeaveSecurityCommand);
217235

218236
pLeaveSecurityCommand->ExecutedEvent -= Poco::Delegate<EventDispatcher, const std::string&>(this, &EventDispatcher::HandleLeaveSecurityCommandExecutedEvent);
219237
}
220238

221239
void EventDispatcher::HandleJoinSecurityCommandExecutedEvent(const void* pSender, const std::string& strUUID)
222240
{
241+
LOG_SCOPE_FUNCTION(8);
223242
GameEventBuffer* pGameEvent = CreateGameEvent(SecurityGameEventBuffer_SecurityGameEventBufferType_JOIN, strUUID);
224243
Enqueue(pGameEvent);
225244
}
226245

227246
void EventDispatcher::HandleLeaveSecurityCommandExecutedEvent(const void* pSender, const std::string& strUUID)
228247
{
248+
LOG_SCOPE_FUNCTION(8);
229249
GameEventBuffer* pGameEvent = CreateGameEvent(SecurityGameEventBuffer_SecurityGameEventBufferType_LEAVE, strUUID);
230250
Enqueue(pGameEvent);
231251
}

src/Network/MessageDispatcher.cpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ void MessageDispatcher::Enqueue(std::pair<const unsigned char*, unsigned long>*
7474

7575
void MessageDispatcher::Enqueue(google::protobuf::Message* pEventMessage)
7676
{
77+
LOG_SCOPE_FUNCTION(4);
7778
assert(pEventMessage);
7879

7980
std::pair<const unsigned char*, unsigned long>* pMessagePair = MessageToPair(pEventMessage);
@@ -131,6 +132,7 @@ std::pair<const unsigned char*, unsigned long>* MessageDispatcher::MessageToPair
131132
// via the configured simple async producer
132133
void MessageDispatcher::Dispatch()
133134
{
135+
int x = 1;
134136
LOG_SCOPE_FUNCTION(3);
135137
m_aMessageQueueMutex.lock();
136138
while (!m_aMessageQueue.empty())
@@ -143,18 +145,23 @@ void MessageDispatcher::Dispatch()
143145
{
144146
// TODO: Proton TESTME
145147
// proton::message msg((const unsigned char*)pMessagePair->first);
146-
proton::binary* body = new proton::binary(std::string((const char*)pMessagePair->first));
148+
std::string pre_proton = (const char*)(pMessagePair->first);
149+
LOG_F(8, "pMessagePair length(): %i", pre_proton.length());
150+
LOG_F(8, "pMessagePair second(): %i", pMessagePair->second);
151+
proton::binary* body = new proton::binary(std::string((const char*)pMessagePair->first, pMessagePair->second));
147152
proton::message msg(*body);
148153
// msg->body(*body);
149154
msg.content_type("proton::BINARY");
150155
msg.content_encoding("proton::BINARY");
151156

157+
LOG_F(7, "message #: %i", x);
152158
LOG_F(7, "proton msg body type is %s", proton::type_name(msg.body().type()).c_str());
153159
LOG_F(7, "proton msg content_type is %s", msg.content_type().c_str());
154160
LOG_F(8, "proton msg content_encoding is %s", msg.content_encoding().c_str());
155161
LOG_F(7, "proton msg body is %s", proton::coerce<std::string>(msg.body()).c_str());
156162

157163
m_psender->send(msg);
164+
x++;
158165
}
159166
}
160167
catch ( std::exception& e )

0 commit comments

Comments
 (0)