Created by Vladislav Molodtsov for communication between modules without naoqi sockets
Channels.h Custom.h Custom.cpp Message.h
#include"Channels.h"
#include"Custom.h"
#include"Message.h"
using namespace message;
private:
Message<MessageType<Send>, MessageType<Receive>> message_;
MyModule::MyModule() : message_(FROM_YOUR_MODULE_TO_OTHER, FROM_OTHER_MODULE_TO_YOUR)
Here FROM_YOUR_MODULE_TO_OTHER and FROM_OTHER _MODULE_TO_YOUR - message types which you can find in channels.h.
- Class Message uses two templates: one for desctiprion of received data and one for description of sending data.
- Calls SendMessage and ReceiveMessage work with struct MessageType. It's a template struct, which contains field data. You can access this field to call your own methods, that you will write in Custom.h. Also there some examples next.
For instance,
void StrategyModule::ReceiveLoop()
{
std::cout << "start receive loop\n";
while(1)
{
MessageType<Receive> buf = ReceiveMessage();
// Example of using
currentGameState = buf.data.state;
}
}
and call it (for example, in init()) using std::threads:
void StrategyModule::init()
{
std::thread receive([&](){
ReceiveLoop();
});
receive.detach();
}
For more details about threads: link.
MessageType<Send> buf;
// For example:
buf.data.state = currentGameState;
message_.SendMessage(buf);