Commit 8f87b68f authored by nomad's avatar nomad

Add timeout for nomad state in case of ne server publisher (server is

done)
parent 8ebc50fb
......@@ -27,7 +27,9 @@
#include <cameo/cameo.h>
#include <common/base/BaseTypes.h>
#include <memory>
#include <mutex>
#include <condition_variable>
#include <chrono>
#include <boost/filesystem/operations.hpp>
#include <protobuf/generated/ServantConfiguration.pb.h>
......@@ -199,17 +201,22 @@ class NomadState {
public:
NomadState(Server& lserver) :
server(lserver) {
server(lserver), _serverAlived(false), m_Exit(false) {
}
~NomadState() {
_subscriber->cancel();
m_Condition.notify_all();
}
private:
Server& server;
std::shared_ptr<cameo::application::Subscriber> _subscriber;
bool _serverAlived;
std::mutex m_Mutex;
std::condition_variable m_Condition;
bool m_Exit;
void loop(const string& name) {
string instrumentName = "inc/" + name;
......@@ -217,8 +224,12 @@ private:
instrumentName.append(".inc");
instrumentNameTmp.append(".tmp");
string data1, data2;
while (_subscriber->receiveTwoBinaryParts(data1, data2)) {
if (_subscriber->hasEnded() == false) {
thread timeoutThread(bind(&NomadState::timeout, this));
while(true) {
_subscriber->receiveTwoBinaryParts(data1, data2);
if ((_subscriber->hasEnded() == false) && (_subscriber->isCanceled() == false) && (m_Exit == false)) {
unique_lock<mutex> lock(m_Mutex);
m_Condition.notify_all();
configuration::WebSpyMessage message;
message.ParseFromString(data1);
if (message.type() == configuration::WebSpyMessage::ControllersProperties) {
......@@ -268,6 +279,26 @@ private:
}
}
else {
if (m_Exit == false) {
m_Exit = true;
unique_lock<mutex> lock(m_Mutex);
m_Condition.notify_all();
}
timeoutThread.join();
break;
}
}
}
void timeout() {
while(m_Exit == false) {
unique_lock<mutex> lock(m_Mutex);
if (m_Condition.wait_for(lock, chrono::seconds(90)) == std::cv_status::timeout) {
if (m_Exit == false) {
m_Exit = true;
_subscriber->cancel();
}
break;
}
}
......@@ -325,7 +356,7 @@ int32 main(int32 argc, char* argv[]) {
if (argc > 2) {
port = string(argv[2]);
}
cout << "instrumentName " << instrumentName << endl;
cout << "--> InstrumentName " << instrumentName << endl;
// Define the Cameo server to connect.
Server server("tcp://" + instrumentName + ":" + port);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment