Hi,
From a class I’m trying to send a callback but I’m facing problem on the data which are empty.
Let’s explain. Here is my class:
Header:
class ProtocolManager
{
private:
Thread * _callbackThread;
public:
ProtocolManager();
~ProtocolManager();
Callback<void(int,int,char*,int)> CommandCallback;
Message * _pMessage;
// Function to process the received buffer from serial source
void ProcessBuffer(char * receivedBuffer, int * receivedBufferSize);
void RegisterCommandCallback(Callback<void(int,int,char*,int)> commandCallback);
private:
static void SendCallback(ProtocolManager * pManager);
};
Implementation:
void ProtocolManager::RegisterCommandCallback(Callback<void(int,int,char*,int)> commandCallback)
{
CommandCallback = commandCallback;
}
void ProtocolManager::ProcessBuffer(char * receivedBuffer, int * receivedBufferSize)
{
if(_pMessage != NULL)
delete _pMessage;
// Check the dataRaw buffer and extract frame if detected
_pMessage = new Message();
_pMessage->Build(receivedBuffer, receivedBufferSize);
_callbackThread = new Thread();
_callbackThread->start(callback(ProtocolManager::SendCallback, this));
}
void ProtocolManager::SendCallback(ProtocolManager * pManager)
{
// Send command info to client
pManager->CommandCallback.call(pManager->_pMessage->_commandId, pManager->_pMessage->_frameId, pManager->_pMessage->_data, pManager->_pMessage->_dataLength);
}
In the main.cpp:
void (*CommandCallback)(int commandId, int frameId, char * data, int dataLength) = &OnCommand;
ProtocolManager _manager;
_manager.RegisterCommandCallback(callback(CommandCallback));
...
void OnCommand(int commandId, int frameId, char * data, int dataLength)
{
// Here all arguments are empty, i.e commandId == 0
printf("Command received = %d, %d, %d [%p]\r\n", commandId, frameId, dataLength, ThisThread::get_id());
}
My problem is that in the OnCommand function (inside the main) the commandId parameter becomes 0 instead of 7 (for example). So it seems that inside the CommandCallback its arguments were reset.
Can you help me achieving this callback ?
Thanks
Frédéric