|
| CSession () |
| Constructor of a DDS Session class. More...
|
|
| ~CSession () |
| A destructor. More...
|
|
boost::uuids::uuid | create () |
| Creates a new DDS session. More...
|
|
void | attach (const std::string &_sid) |
| Attaches to an existing DDS session. More...
|
|
void | attach (const boost::uuids::uuid &_sid) |
| Attaches to an existing DDS session. More...
|
|
void | shutdown () |
| Shutdown currently attached DDS session. More...
|
|
void | detach () |
| Detach from the session without shutting it down. More...
|
|
bool | IsRunning () const |
| Check if DDS session is running. More...
|
|
boost::uuids::uuid | getSessionID () const |
| Returns DDS session ID. More...
|
|
void | blockCurrentThread () |
| blockCurrentThread Blocks current thread. More...
|
|
void | unblockCurrentThread () |
| Stop DDS session. More...
|
|
template<class T > |
void | sendRequest (typename T::ptr_t _request) |
| Sends the async request to DDS commander. More...
|
|
template<class Request_t > |
void | syncSendRequest (const typename Request_t::request_t &_requestData, const std::chrono::seconds &_timeout=std::chrono::seconds(0), std::ostream *_out=nullptr) |
| Sends the sync request to DDS commander. More...
|
|
template<class Request_t > |
void | syncSendRequest (const typename Request_t::request_t &_requestData, typename Request_t::response_t &_responseData, const std::chrono::seconds &_timeout=std::chrono::seconds(0), std::ostream *_out=nullptr) |
| Sends the sync request to DDS commander. More...
|
|
template<class Request_t > |
void | syncSendRequest (const typename Request_t::request_t &_requestData, typename Request_t::responseVector_t &_responseDataVector, const std::chrono::seconds &_timeout=std::chrono::seconds(0), std::ostream *_out=nullptr) |
| Sends the sync request to DDS commander. More...
|
|
template<CSession::EAgentState _state> |
void | waitForNumAgents (size_t _numAgents, const std::chrono::seconds &_timeout=std::chrono::seconds(0), const std::chrono::milliseconds &_requestInterval=std::chrono::milliseconds(500), std::ostream *_out=nullptr) |
| Wait for the required number of agents with a certain state. More...
|
|
std::string | userDefaultsGetValueForKey (const std::string &_key) const noexcept |
| This method returns a configuration value for a given configuration key. It uses the DDS configuration of the current session. More...
|
|
template<CSession::EAgentState _state> |
void | waitForNumAgents (size_t _numAgents, const std::chrono::seconds &_timeout, const std::chrono::milliseconds &_requestInterval, ostream *_out) |
|
The main class of the Tools API. It represets a DDS session.
It can be used to create new DDS sessions or attach to existing ones. Also, this class can be used to send and recieve Tools commands. Currently the following commands are ToolsProtocol.h
Please note, when you send a requests, server will respond with a corresponding reply with a following Done event. But the server can also send an error message. Once you receive either Done or an error, don't expect the server to send anything else in the regards of the request. So, you can then stop the API or send another request.
- Example1: Create a new DDS session, spawn 10 localhost agents
boost::uuids::uuid sessionID = session.create();
submitInfo.m_config = "";
submitInfo.m_rms = "localhost";
submitInfo.m_instances = "10";
submitInfo.m_pluginPath = "";
submitRequestPtr->setMessageCallback([&session](const SMessageResponseData& _message) {
cout << "Server reports: " << _message.m_msg << endl;
});
submitRequestPtr->setDoneCallback([&session, &start]() {
auto end = chrono::high_resolution_clock::now();
chrono::duration<double, std::milli> elapsed = end - start;
cout << "Submission took: " << elapsed.count() << " ms\n";
session.unblockCurrentThread();
});
session.blockCurrentThread();
- Example2: Attach to an existing DDS session and request the number of running agent
session.attach("446b4183-1313-4648-99aa-4f8fae81311c");
SAgentInfoRequest::ptr_t agentInfoRequestPtr = SAgentInfoRequest::makeRequest();
agentInfoRequestPtr->setMessageCallback([&session](const SMessageResponseData& _message) {
cout << "Server reports: " << _message.m_msg << endl;
});
agentInfoRequestPtr->setDoneCallback([&session]() {
session.unblockCurrentThread();
});
agentInfoRequestPtr->setResponseCallback([&session](const SAgentInfoRequest::response_t& _info) {
cout << _info.m_activeAgentsCount << endl;
});
session.sendRequest<SAgentInfoRequest>(agentInfoRequestPtr);
session.blockCurrentThread();
- Example3: Sync Tools API example
const string topoFile("property_test.xml");
const std::chrono::seconds timeout(20);
const std::chrono::milliseconds requestInterval(500);
boost::uuids::uuid sid = session.create();
CTopology topo(topoFile);
size_t numAgents = topo.getRequiredNofAgents();
submitInfo.m_rms = "localhost";
submitInfo.m_instances = numAgents;
session.syncSendRequest<
SSubmitRequest>(submitInfo, timeout, &std::cout);
topoInfo.m_topologyFile = topoFile;
topoInfo.m_updateType = STopologyRequest::request_t::EUpdateType::ACTIVATE;
&std::cout);
session.shutdown();
- Example4: DDS User defaults. Retrieving DDS log directory on the commander server within an active
- session.
boost::uuids::uuid sid = session.create();
cout << session.userDefaultsGetValueForKey("server.log_dir") << endl;
output> $HOME/.DDS/log/sessions/b383d852-19a7-4ac5-9cbe-dc00d686d36f
- Example5: DDS User defaults. Retrieving DDS log directory without attaching to a session.
cout << session.userDefaultsGetValueForKey("server.log_dir") << endl;
output> $HOME/.DDS/log
- Example5: Subscribe on TaskDone events
...
SOnTaskDoneRequest::request_t request;
SOnTaskDoneRequest::ptr_t requestPtr = SOnTaskDoneRequest::makeRequest(request);
int nTaskDoneCount{ 0 };
requestPtr->setResponseCallback(
[&nTaskDoneCount](const SOnTaskDoneResponseData& _info)
{
++nTaskDoneCount;
cout << "Recieved onTaskDone event. TaskID: " << _info.m_taskID
<< " ; ExitCode: " << _info.m_exitCode
<< " ; Signal: " << _info.m_signal;
});
session.sendRequest<SOnTaskDoneRequest>(requestPtr);
...
- Example5: Request Agent shutdown by AgentID with a sync request
...
SAgentCommandRequest::request_t agentCmd;
agentCmd.m_arg1 = <Given AgentID>;
...