diff --git a/modules/server/CMakeLists.txt b/modules/server/CMakeLists.txt index 723fc24295..c39537163d 100644 --- a/modules/server/CMakeLists.txt +++ b/modules/server/CMakeLists.txt @@ -33,7 +33,6 @@ set(HEADER_FILES include/serverinterface.h include/topics/authorizationtopic.h include/topics/bouncetopic.h - include/topics/deltatimestepstopic.h include/topics/documentationtopic.h include/topics/flightcontrollertopic.h include/topics/getpropertytopic.h @@ -57,7 +56,6 @@ set(SOURCE_FILES src/serverinterface.cpp src/topics/authorizationtopic.cpp src/topics/bouncetopic.cpp - src/topics/deltatimestepstopic.cpp src/topics/documentationtopic.cpp src/topics/flightcontrollertopic.cpp src/topics/getpropertytopic.cpp diff --git a/modules/server/include/topics/deltatimestepstopic.h b/modules/server/include/topics/deltatimestepstopic.h deleted file mode 100644 index 6b06999151..0000000000 --- a/modules/server/include/topics/deltatimestepstopic.h +++ /dev/null @@ -1,57 +0,0 @@ -/***************************************************************************************** - * * - * OpenSpace * - * * - * Copyright (c) 2014-2020 * - * * - * Permission is hereby granted, free of charge, to any person obtaining a copy of this * - * software and associated documentation files (the "Software"), to deal in the Software * - * without restriction, including without limitation the rights to use, copy, modify, * - * merge, publish, distribute, sublicense, and/or sell copies of the Software, and to * - * permit persons to whom the Software is furnished to do so, subject to the following * - * conditions: * - * * - * The above copyright notice and this permission notice shall be included in all copies * - * or substantial portions of the Software. * - * * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, * - * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A * - * PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT * - * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF * - * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE * - * OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. * - ****************************************************************************************/ - -#ifndef __OPENSPACE_MODULE_SERVER___DELTA_TIME_STEPS_TOPIC___H__ -#define __OPENSPACE_MODULE_SERVER___DELTA_TIME_STEPS_TOPIC___H__ - -#include -#include - -namespace openspace { - -class DeltaTimeStepsTopic : public Topic { -public: - DeltaTimeStepsTopic(); - virtual ~DeltaTimeStepsTopic(); - - void handleJson(const nlohmann::json& json) override; - bool isDone() const override; - -private: - const int UnsetOnChangeHandle = -1; - - bool dataHasChanged(); - void sendDeltaTimesData(); - - int _deltaTimeCallbackHandle = UnsetOnChangeHandle; - int _deltaTimesListCallbackHandle = UnsetOnChangeHandle; - bool _isDone = false; - - std::optional _lastNextDeltaTime = std::nullopt; - std::optional _lastPrevDeltaTime = std::nullopt; -}; - -} // namespace openspace - -#endif // __OPENSPACE_MODULE_SERVER___DELTA_TIME_STEPS_TOPIC___H__ diff --git a/modules/server/src/connection.cpp b/modules/server/src/connection.cpp index f45595788b..89cb02a96c 100644 --- a/modules/server/src/connection.cpp +++ b/modules/server/src/connection.cpp @@ -26,7 +26,6 @@ #include #include -#include #include #include #include @@ -57,7 +56,6 @@ namespace { constexpr const char* VersionTopicKey = "version"; constexpr const char* AuthenticationTopicKey = "authorize"; - constexpr const char* DeltaTimeStepsTopicKey = "deltatimesteps"; constexpr const char* DocumentationTopicKey = "documentation"; constexpr const char* GetPropertyTopicKey = "get"; constexpr const char* LuaScriptTopicKey = "luascript"; @@ -97,7 +95,6 @@ Connection::Connection(std::unique_ptr s, ); _topicFactory.registerClass(DocumentationTopicKey); - _topicFactory.registerClass(DeltaTimeStepsTopicKey); _topicFactory.registerClass(GetPropertyTopicKey); _topicFactory.registerClass(LuaScriptTopicKey); _topicFactory.registerClass(SessionRecordingTopicKey); diff --git a/modules/server/src/topics/deltatimestepstopic.cpp b/modules/server/src/topics/deltatimestepstopic.cpp deleted file mode 100644 index 1399825f59..0000000000 --- a/modules/server/src/topics/deltatimestepstopic.cpp +++ /dev/null @@ -1,127 +0,0 @@ -/***************************************************************************************** - * * - * OpenSpace * - * * - * Copyright (c) 2014-2020 * - * * - * Permission is hereby granted, free of charge, to any person obtaining a copy of this * - * software and associated documentation files (the "Software"), to deal in the Software * - * without restriction, including without limitation the rights to use, copy, modify, * - * merge, publish, distribute, sublicense, and/or sell copies of the Software, and to * - * permit persons to whom the Software is furnished to do so, subject to the following * - * conditions: * - * * - * The above copyright notice and this permission notice shall be included in all copies * - * or substantial portions of the Software. * - * * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, * - * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A * - * PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT * - * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF * - * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE * - * OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. * - ****************************************************************************************/ - -#include "modules/server/include/topics/deltatimestepstopic.h" - -#include -#include -#include -#include -#include -#include - -namespace { - constexpr const char* EventKey = "event"; - constexpr const char* SubscribeEvent = "start_subscription"; - constexpr const char* UnsubscribeEvent = "stop_subscription"; -} // namespace - -using nlohmann::json; - -namespace openspace { - -DeltaTimeStepsTopic::DeltaTimeStepsTopic() {} - -DeltaTimeStepsTopic::~DeltaTimeStepsTopic() { - if (_deltaTimeCallbackHandle != UnsetOnChangeHandle) { - global::timeManager.removeDeltaTimeChangeCallback( - _deltaTimeCallbackHandle - ); - } - if (_deltaTimesListCallbackHandle != UnsetOnChangeHandle) { - global::timeManager.removeDeltaTimeStepsChangeCallback( - _deltaTimesListCallbackHandle - ); - } -} - -bool DeltaTimeStepsTopic::isDone() const { - return _isDone; -} - -bool DeltaTimeStepsTopic::dataHasChanged() { - std::optional nextStep = global::timeManager.nextDeltaTimeStep(); - std::optional prevStep = global::timeManager.previousDeltaTimeStep(); - - return (nextStep != _lastNextDeltaTime || prevStep != _lastPrevDeltaTime); -} - -void DeltaTimeStepsTopic::handleJson(const nlohmann::json& json) { - std::string event = json.at(EventKey).get(); - if (event == UnsubscribeEvent) { - _isDone = true; - return; - } - - sendDeltaTimesData(); - - if (event != SubscribeEvent) { - _isDone = true; - return; - } - - _deltaTimeCallbackHandle = global::timeManager.addDeltaTimeChangeCallback( - [this]() { - if (dataHasChanged()) { - sendDeltaTimesData(); - } - } - ); - - _deltaTimesListCallbackHandle = global::timeManager.addDeltaTimeStepsChangeCallback( - [this]() { - if (dataHasChanged()) { - sendDeltaTimesData(); - } - } - ); -} - -void DeltaTimeStepsTopic::sendDeltaTimesData() { - std::optional nextStep = global::timeManager.nextDeltaTimeStep(); - std::optional prevStep = global::timeManager.previousDeltaTimeStep(); - - bool hasNext = nextStep.has_value(); - bool hasPrev = prevStep.has_value(); - - json deltaTimesListJson = { - { "hasNextStep", hasNext }, - { "hasPrevStep", hasPrev } - }; - - if (hasNext) { - deltaTimesListJson["nextStep"] = nextStep.value(); - } - - if (hasPrev) { - deltaTimesListJson["prevStep"] = prevStep.value(); - } - - _connection->sendJson(wrappedPayload(deltaTimesListJson)); - - _lastNextDeltaTime = nextStep; - _lastPrevDeltaTime = prevStep; -} - -} // namespace openspace diff --git a/modules/server/src/topics/timetopic.cpp b/modules/server/src/topics/timetopic.cpp index 789b9da924..e092a3bbaf 100644 --- a/modules/server/src/topics/timetopic.cpp +++ b/modules/server/src/topics/timetopic.cpp @@ -30,6 +30,7 @@ #include #include #include +#include namespace { constexpr const char* EventKey = "event"; @@ -110,13 +111,29 @@ void TimeTopic::sendFullTimeData() { const double targetDeltaTime = global::timeManager.targetDeltaTime(); const bool isPaused = global::timeManager.isPaused(); - const json timeJson = { + std::optional nextStep = global::timeManager.nextDeltaTimeStep(); + std::optional prevStep = global::timeManager.previousDeltaTimeStep(); + + bool hasNext = nextStep.has_value(); + bool hasPrev = prevStep.has_value(); + + json timeJson = { { "time", currentTime }, { "deltaTime", deltaTime}, { "targetDeltaTime", targetDeltaTime}, { "isPaused", isPaused }, + { "hasNextStep", hasNext }, + { "hasPrevStep", hasPrev } }; + if (hasNext) { + timeJson["nextStep"] = nextStep.value(); + } + + if (hasPrev) { + timeJson["prevStep"] = prevStep.value(); + } + _connection->sendJson(wrappedPayload(timeJson)); _lastUpdateTime = std::chrono::system_clock::now(); _lastPauseState = isPaused;