Corrected some things from the previous commit

This commit is contained in:
Subv
2014-07-01 23:05:06 -05:00
parent 9817f5e23e
commit c8fe4b8d50
2 changed files with 8 additions and 9 deletions

View File

@@ -56,7 +56,7 @@ void TCSoapThread(const std::string& host, uint16 port)
void process_message(struct soap* soap_message)
{
ACE_TRACE (ACE_TEXT ("SOAPWorkingThread::process_message"));
TC_LOG_TRACE("network.soap", "SOAPWorkingThread::process_message");
soap_serve(soap_message);
soap_destroy(soap_message); // dealloc C++ data
@@ -105,16 +105,15 @@ int ns1__executeCommand(soap* soap, char* command, char** result)
// commands are executed in the world thread. We have to wait for them to be completed
{
// CliCommandHolder will be deleted from world, accessing after queueing is NOT save
// CliCommandHolder will be deleted from world, accessing after queueing is NOT safe
CliCommandHolder* cmd = new CliCommandHolder(&connection, command, &SOAPCommand::print, &SOAPCommand::commandFinished);
sWorld->QueueCliCommand(cmd);
}
// wait for callback to complete command
connection.pendingCommands.lock();
// alright, command finished
// Wait until the command has finished executing
connection.finishedPromise.get_future().wait();
// The command has finished executing already
char* printBuffer = soap_strdup(soap, connection.m_printBuffer.c_str());
if (connection.hasCommandSucceeded())
{
@@ -129,7 +128,6 @@ void SOAPCommand::commandFinished(void* soapconnection, bool success)
{
SOAPCommand* con = (SOAPCommand*)soapconnection;
con->setCommandSuccess(success);
con->pendingCommands.unlock();
}
////////////////////////////////////////////////////////////////////////////////

View File

@@ -20,6 +20,7 @@
#include "Define.h"
#include <mutex>
#include <future>
void process_message(struct soap* soap_message);
void TCSoapThread(const std::string& host, uint16 port);
@@ -41,11 +42,10 @@ class SOAPCommand
m_printBuffer += msg;
}
std::mutex pendingCommands;
void setCommandSuccess(bool val)
{
m_success = val;
finishedPromise.set_value();
}
bool hasCommandSucceeded() const
@@ -62,6 +62,7 @@ class SOAPCommand
bool m_success;
std::string m_printBuffer;
std::promise<void> finishedPromise;
};
#endif