Make it possible to unsubscribe to the time (#612)

This commit is contained in:
Emil Axelsson
2018-05-16 12:47:06 +02:00
committed by GitHub
parent a6501cb288
commit 1c000a045b
2 changed files with 11 additions and 1 deletions

View File

@@ -31,6 +31,8 @@
namespace {
const char* _loggerCat = "TimeTopic";
const char* PropertyKey = "property";
const char* EventKey = "event";
const char* UnsubscribeEvent = "stop_subscription";
const char* CurrentTimeKey = "currentTime";
const char* DeltaTimeKey = "deltaTime";
const int UNSET_ONCHANGE_HANDLE = -1;
@@ -43,6 +45,7 @@ namespace openspace {
TimeTopic::TimeTopic()
: Topic()
, _isDone(false)
, _timeCallbackHandle(UNSET_ONCHANGE_HANDLE)
, _deltaTimeCallbackHandle(UNSET_ONCHANGE_HANDLE)
, _lastUpdateTime(std::chrono::system_clock::now())
@@ -60,10 +63,15 @@ TimeTopic::~TimeTopic() {
}
bool TimeTopic::isDone() {
return false;
return _isDone;
}
void TimeTopic::handleJson(json j) {
std::string event = j.at(EventKey).get<std::string>();
if (event == UnsubscribeEvent) {
_isDone = true;
return;
}
std::string requestedKey = j.at(PropertyKey).get<std::string>();
LDEBUG("Subscribing to " + requestedKey);
@@ -92,6 +100,7 @@ void TimeTopic::handleJson(json j) {
}
else {
LWARNING("Cannot get " + requestedKey);
_isDone = true;
}
}