mirror of
https://github.com/OpenSpace/OpenSpace.git
synced 2026-01-06 03:29:44 -06:00
Merge branch 'master' into issue/2645
# Conflicts: # src/documentation/documentationengine.cpp # src/properties/propertyowner.cpp # src/scripting/scriptengine.cpp # src/util/factorymanager.cpp
This commit is contained in:
@@ -50,8 +50,8 @@
|
||||
#include <ghoul/io/socket/tcpsocketserver.h>
|
||||
#include <ghoul/io/socket/websocketserver.h>
|
||||
#include <ghoul/logging/logmanager.h>
|
||||
#include <ghoul/fmt.h>
|
||||
#include <ghoul/misc/profiling.h>
|
||||
#include <fmt/format.h>
|
||||
|
||||
namespace {
|
||||
constexpr std::string_view _loggerCat = "ServerModule: Connection";
|
||||
@@ -109,40 +109,40 @@ void Connection::handleMessage(const std::string& message) {
|
||||
ZoneScoped;
|
||||
|
||||
try {
|
||||
nlohmann::json j = nlohmann::json::parse(message.c_str());
|
||||
const nlohmann::json j = nlohmann::json::parse(message.c_str());
|
||||
try {
|
||||
handleJson(j);
|
||||
}
|
||||
catch (const std::domain_error& e) {
|
||||
LERROR(fmt::format("JSON handling error from: {}. {}", message, e.what()));
|
||||
LERROR(std::format("JSON handling error from: {}. {}", message, e.what()));
|
||||
}
|
||||
}
|
||||
catch (const std::out_of_range& e) {
|
||||
LERROR(fmt::format("JSON handling error from: {}. {}", message, e.what()));
|
||||
LERROR(std::format("JSON handling error from: {}. {}", message, e.what()));
|
||||
}
|
||||
catch (const std::exception& e) {
|
||||
LERROR(e.what());
|
||||
} catch (...) {
|
||||
}
|
||||
catch (...) {
|
||||
if (!isAuthorized()) {
|
||||
_socket->disconnect();
|
||||
LERROR(fmt::format(
|
||||
"Could not parse JSON: '{}'. Connection is unauthorized. Disconnecting",
|
||||
LERROR(std::format(
|
||||
"Could not parse JSON '{}'. Connection is unauthorized. Disconnecting",
|
||||
message
|
||||
));
|
||||
return;
|
||||
}
|
||||
else {
|
||||
std::string sanitizedString = message;
|
||||
std::transform(
|
||||
message.begin(),
|
||||
message.end(),
|
||||
sanitizedString.begin(),
|
||||
[](wchar_t c) {
|
||||
return std::isprint(c, std::locale("")) ? char(c) : ' ';
|
||||
}
|
||||
);
|
||||
LERROR(fmt::format("Could not parse JSON: '{}'", sanitizedString));
|
||||
}
|
||||
|
||||
std::string sanitizedString = message;
|
||||
std::transform(
|
||||
message.begin(),
|
||||
message.end(),
|
||||
sanitizedString.begin(),
|
||||
[](wchar_t c) {
|
||||
return std::isprint(c, std::locale("")) ? char(c) : ' ';
|
||||
}
|
||||
);
|
||||
LERROR(std::format("Could not parse JSON '{}'", sanitizedString));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -163,7 +163,7 @@ void Connection::handleJson(const nlohmann::json& json) {
|
||||
}
|
||||
|
||||
// The topic id may be an already discussed topic, or a new one.
|
||||
TopicId topicId = *topicJson;
|
||||
const TopicId topicId = *topicJson;
|
||||
auto topicIt = _topics.find(topicId);
|
||||
|
||||
if (topicIt == _topics.end()) {
|
||||
@@ -173,9 +173,9 @@ void Connection::handleJson(const nlohmann::json& json) {
|
||||
LERROR("Type must be specified as a string when a new topic is initialized");
|
||||
return;
|
||||
}
|
||||
std::string type = *typeJson;
|
||||
const std::string type = *typeJson;
|
||||
|
||||
if (!isAuthorized() && type != "authorize") {
|
||||
if (!isAuthorized() && (type != "authorize")) {
|
||||
LERROR("Connection is not authorized");
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -65,7 +65,7 @@ void ConnectionPool::updateConnections() {
|
||||
}
|
||||
|
||||
void ConnectionPool::acceptNewSockets() {
|
||||
for (std::shared_ptr<ghoul::io::SocketServer>& server : _socketServers) {
|
||||
for (const std::shared_ptr<ghoul::io::SocketServer>& server : _socketServers) {
|
||||
std::unique_ptr<ghoul::io::Socket> socket;
|
||||
while ((socket = server->nextPendingSocket())) {
|
||||
_handleSocket(*socket);
|
||||
|
||||
@@ -34,10 +34,10 @@ using json = nlohmann::json;
|
||||
namespace openspace::properties {
|
||||
|
||||
void to_json(json& j, const Property& p) {
|
||||
std::string description = p.generateJsonDescription();
|
||||
const std::string description = p.generateJsonDescription();
|
||||
json desc = json::parse(description);
|
||||
|
||||
std::string value = p.jsonValue();
|
||||
const std::string value = p.jsonValue();
|
||||
json val = json::parse(value);
|
||||
|
||||
j = {
|
||||
@@ -70,37 +70,37 @@ void to_json(json& j, const PropertyOwner* p) {
|
||||
|
||||
namespace ghoul {
|
||||
|
||||
void to_json(json& j, const Dictionary& dictionary) {
|
||||
void to_json(json& j, const Dictionary& d) {
|
||||
json object;
|
||||
for (std::string_view k : dictionary.keys()) {
|
||||
std::string key = std::string(k);
|
||||
if (dictionary.hasValue<glm::dvec4>(key)) {
|
||||
const glm::dvec4 v = dictionary.value<glm::dvec4>(key);
|
||||
for (const std::string_view k : d.keys()) {
|
||||
const std::string key = std::string(k);
|
||||
if (d.hasValue<glm::dvec4>(key)) {
|
||||
const glm::dvec4 v = d.value<glm::dvec4>(key);
|
||||
object[key] = json::array({ v[0], v[1], v[2], v[3] });
|
||||
}
|
||||
else if (dictionary.hasValue<glm::dvec3>(key)) {
|
||||
const glm::dvec3 v = dictionary.value<glm::dvec3>(key);
|
||||
else if (d.hasValue<glm::dvec3>(key)) {
|
||||
const glm::dvec3 v = d.value<glm::dvec3>(key);
|
||||
object[key] = json::array({ v[0], v[1], v[2] });
|
||||
}
|
||||
else if (dictionary.hasValue<glm::dvec2>(key)) {
|
||||
const glm::dvec2 v = dictionary.value<glm::dvec2>(key);
|
||||
else if (d.hasValue<glm::dvec2>(key)) {
|
||||
const glm::dvec2 v = d.value<glm::dvec2>(key);
|
||||
object[key] = json::array({ v[0], v[1] });
|
||||
}
|
||||
else if (dictionary.hasValue<double>(key)) {
|
||||
object[key] = dictionary.value<double>(key);
|
||||
else if (d.hasValue<double>(key)) {
|
||||
object[key] = d.value<double>(key);
|
||||
}
|
||||
else if (dictionary.hasValue<int>(key)) {
|
||||
object[key] = dictionary.value<int>(key);
|
||||
else if (d.hasValue<int>(key)) {
|
||||
object[key] = d.value<int>(key);
|
||||
}
|
||||
else if (dictionary.hasValue<std::string>(key)) {
|
||||
object[key] = dictionary.value<std::string>(key);
|
||||
else if (d.hasValue<std::string>(key)) {
|
||||
object[key] = d.value<std::string>(key);
|
||||
}
|
||||
else if (dictionary.hasValue<bool>(key)) {
|
||||
object[key] = dictionary.value<bool>(key);
|
||||
else if (d.hasValue<bool>(key)) {
|
||||
object[key] = d.value<bool>(key);
|
||||
}
|
||||
else if (dictionary.hasValue<Dictionary>(key)) {
|
||||
else if (d.hasValue<Dictionary>(key)) {
|
||||
json child;
|
||||
to_json(child, dictionary.value<Dictionary>(key));
|
||||
to_json(child, d.value<Dictionary>(key));
|
||||
object[key] = child;
|
||||
}
|
||||
else {
|
||||
@@ -167,4 +167,4 @@ void to_json(json& j, const dvec3& v) {
|
||||
};
|
||||
}
|
||||
|
||||
} // namepsace glm
|
||||
} // namespace glm
|
||||
|
||||
@@ -99,14 +99,14 @@ namespace {
|
||||
namespace openspace {
|
||||
|
||||
std::unique_ptr<ServerInterface> ServerInterface::createFromDictionary(
|
||||
const ghoul::Dictionary& config)
|
||||
const ghoul::Dictionary& dictionary)
|
||||
{
|
||||
// TODO: Use documentation to verify dictionary
|
||||
auto si = std::make_unique<ServerInterface>(config);
|
||||
auto si = std::make_unique<ServerInterface>(dictionary);
|
||||
return si;
|
||||
}
|
||||
|
||||
ServerInterface::ServerInterface(const ghoul::Dictionary& config)
|
||||
ServerInterface::ServerInterface(const ghoul::Dictionary& dictionary)
|
||||
: properties::PropertyOwner({ "", "", "" })
|
||||
, _socketType(TypeInfo)
|
||||
, _port(PortInfo, 0)
|
||||
@@ -140,8 +140,10 @@ ServerInterface::ServerInterface(const ghoul::Dictionary& config)
|
||||
std::string(AllowAccess)
|
||||
);
|
||||
|
||||
if (config.hasKey(DefaultAccessInfo.identifier)) {
|
||||
std::string access = config.value<std::string>(DefaultAccessInfo.identifier);
|
||||
if (dictionary.hasKey(DefaultAccessInfo.identifier)) {
|
||||
const std::string access = dictionary.value<std::string>(
|
||||
DefaultAccessInfo.identifier
|
||||
);
|
||||
if (access == DenyAccess) {
|
||||
_defaultAccess.setValue(static_cast<int>(Access::Deny));
|
||||
}
|
||||
@@ -153,14 +155,14 @@ ServerInterface::ServerInterface(const ghoul::Dictionary& config)
|
||||
}
|
||||
}
|
||||
|
||||
const std::string identifier = config.value<std::string>(KeyIdentifier);
|
||||
const std::string identifier = dictionary.value<std::string>(KeyIdentifier);
|
||||
|
||||
auto readList =
|
||||
[config](const std::string& key, properties::StringListProperty& list) {
|
||||
if (config.hasValue<ghoul::Dictionary>(key)) {
|
||||
const ghoul::Dictionary& dict = config.value<ghoul::Dictionary>(key);
|
||||
[dictionary](const std::string& key, properties::StringListProperty& list) {
|
||||
if (dictionary.hasValue<ghoul::Dictionary>(key)) {
|
||||
const ghoul::Dictionary& dict = dictionary.value<ghoul::Dictionary>(key);
|
||||
std::vector<std::string> v;
|
||||
for (std::string_view k : dict.keys()) {
|
||||
for (const std::string_view k : dict.keys()) {
|
||||
v.push_back(dict.value<std::string>(k));
|
||||
}
|
||||
list = v;
|
||||
@@ -175,7 +177,7 @@ ServerInterface::ServerInterface(const ghoul::Dictionary& config)
|
||||
setGuiName(identifier);
|
||||
setDescription("Settings for server interface " + identifier);
|
||||
|
||||
const std::string type = config.value<std::string>(TypeInfo.identifier);
|
||||
const std::string type = dictionary.value<std::string>(TypeInfo.identifier);
|
||||
if (type == TcpSocketType) {
|
||||
_socketType = static_cast<int>(InterfaceType::TcpSocket);
|
||||
}
|
||||
@@ -183,12 +185,12 @@ ServerInterface::ServerInterface(const ghoul::Dictionary& config)
|
||||
_socketType = static_cast<int>(InterfaceType::WebSocket);
|
||||
}
|
||||
|
||||
if (config.hasValue<std::string>(PasswordInfo.identifier)) {
|
||||
_password = config.value<std::string>(PasswordInfo.identifier);
|
||||
if (dictionary.hasValue<std::string>(PasswordInfo.identifier)) {
|
||||
_password = dictionary.value<std::string>(PasswordInfo.identifier);
|
||||
}
|
||||
|
||||
_port = static_cast<int>(config.value<double>(PortInfo.identifier));
|
||||
_enabled = config.value<bool>(EnabledInfo.identifier);
|
||||
_port = static_cast<int>(dictionary.value<double>(PortInfo.identifier));
|
||||
_enabled = dictionary.value<bool>(EnabledInfo.identifier);
|
||||
|
||||
auto reinitialize = [this]() {
|
||||
deinitialize();
|
||||
@@ -213,8 +215,6 @@ ServerInterface::ServerInterface(const ghoul::Dictionary& config)
|
||||
addProperty(_password);
|
||||
}
|
||||
|
||||
ServerInterface::~ServerInterface() {}
|
||||
|
||||
void ServerInterface::initialize() {
|
||||
if (!_enabled) {
|
||||
return;
|
||||
@@ -258,7 +258,7 @@ bool ServerInterface::clientHasAccessWithoutPassword(
|
||||
return true;
|
||||
}
|
||||
}
|
||||
Access access = static_cast<Access>(_defaultAccess.value());
|
||||
const Access access = static_cast<Access>(_defaultAccess.value());
|
||||
if (access == Access::Allow) {
|
||||
for (const std::string& address : _denyAddresses.value()) {
|
||||
if (clientAddress == address) {
|
||||
@@ -276,7 +276,7 @@ bool ServerInterface::clientIsBlocked(const std::string& clientAddress) const {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
Access access = static_cast<Access>(_defaultAccess.value());
|
||||
const Access access = static_cast<Access>(_defaultAccess.value());
|
||||
if (access == Access::Deny) {
|
||||
for (const std::string& address : _allowAddresses.value()) {
|
||||
if (clientAddress == address) {
|
||||
@@ -297,5 +297,4 @@ ghoul::io::SocketServer* ServerInterface::server() {
|
||||
return _socketServer.get();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
} // namespace openspace
|
||||
|
||||
@@ -54,7 +54,7 @@ void AuthorizationTopic::handleJson(const nlohmann::json& json) {
|
||||
}
|
||||
else {
|
||||
try {
|
||||
std::string providedKey = json.at("key").get<std::string>();
|
||||
const std::string providedKey = json.at("key").get<std::string>();
|
||||
if (authorize(providedKey)) {
|
||||
_connection->setAuthorized(true);
|
||||
_connection->sendJson(wrappedPayload({ KeyStatus, Authorized }));
|
||||
|
||||
@@ -60,7 +60,7 @@ bool CameraPathTopic::isDone() const {
|
||||
}
|
||||
|
||||
void CameraPathTopic::handleJson(const nlohmann::json& json) {
|
||||
std::string event = json.at("event").get<std::string>();
|
||||
const std::string event = json.at("event").get<std::string>();
|
||||
|
||||
if (event != SubscribeEvent) {
|
||||
_isDone = true;
|
||||
@@ -70,10 +70,10 @@ void CameraPathTopic::handleJson(const nlohmann::json& json) {
|
||||
ServerModule* module = global::moduleEngine->module<ServerModule>();
|
||||
_dataCallbackHandle = module->addPreSyncCallback(
|
||||
[this]() {
|
||||
bool isInPath = (global::openSpaceEngine->currentMode()
|
||||
const bool isInPath =(global::openSpaceEngine->currentMode()
|
||||
== OpenSpaceEngine::Mode::CameraPath);
|
||||
|
||||
std::chrono::system_clock::time_point now = std::chrono::system_clock::now();
|
||||
const auto now = std::chrono::system_clock::now();
|
||||
if (isInPath && (now - _lastUpdateTime) > _cameraPathUpdateTime) {
|
||||
sendCameraPathData();
|
||||
_lastUpdateTime = std::chrono::system_clock::now();
|
||||
@@ -100,7 +100,7 @@ void CameraPathTopic::sendCameraPathData() {
|
||||
);
|
||||
seconds = std::max(seconds, 0);
|
||||
|
||||
nlohmann::json jsonData = {
|
||||
const nlohmann::json jsonData = {
|
||||
{ "target", path->endPoint().nodeIdentifier() },
|
||||
{ "remainingTime", seconds },
|
||||
//{ "remainingDistance", path->remainingDistance() },
|
||||
|
||||
@@ -59,7 +59,7 @@ bool CameraTopic::isDone() const {
|
||||
}
|
||||
|
||||
void CameraTopic::handleJson(const nlohmann::json& json) {
|
||||
std::string event = json.at("event").get<std::string>();
|
||||
const std::string event = json.at("event").get<std::string>();
|
||||
|
||||
if (event != SubscribeEvent) {
|
||||
_isDone = true;
|
||||
@@ -69,7 +69,7 @@ void CameraTopic::handleJson(const nlohmann::json& json) {
|
||||
ServerModule* module = global::moduleEngine->module<ServerModule>();
|
||||
_dataCallbackHandle = module->addPreSyncCallback(
|
||||
[this]() {
|
||||
std::chrono::system_clock::time_point now = std::chrono::system_clock::now();
|
||||
const auto now = std::chrono::system_clock::now();
|
||||
if (now - _lastUpdateTime > _cameraPositionUpdateTime) {
|
||||
sendCameraData();
|
||||
_lastUpdateTime = std::chrono::system_clock::now();
|
||||
@@ -83,7 +83,7 @@ void CameraTopic::sendCameraData() {
|
||||
glm::dvec3 position = module->geoPosition();
|
||||
std::pair<double, std::string_view> altSimplified = simplifyDistance(position.z);
|
||||
|
||||
nlohmann::json jsonData = {
|
||||
const nlohmann::json jsonData = {
|
||||
{ "latitude", position.x },
|
||||
{ "longitude", position.y },
|
||||
{ "altitude", altSimplified.first },
|
||||
|
||||
@@ -38,7 +38,7 @@ using nlohmann::json;
|
||||
namespace openspace {
|
||||
|
||||
void DocumentationTopic::handleJson(const nlohmann::json& json) {
|
||||
std::string requestedType = json.at("type").get<std::string>();
|
||||
const std::string requestedType = json.at("type").get<std::string>();
|
||||
|
||||
nlohmann::json response;
|
||||
|
||||
|
||||
@@ -75,11 +75,10 @@ void EngineModeTopic::handleJson(const nlohmann::json& json) {
|
||||
if (event == SubscribeEvent) {
|
||||
_modeCallbackHandle = global::openSpaceEngine->addModeChangeCallback(
|
||||
[this]() {
|
||||
OpenSpaceEngine::Mode currentMode =
|
||||
global::openSpaceEngine->currentMode();
|
||||
if (currentMode != _lastMode) {
|
||||
const OpenSpaceEngine::Mode mode = global::openSpaceEngine->currentMode();
|
||||
if (mode != _lastMode) {
|
||||
sendJsonData();
|
||||
_lastMode = currentMode;
|
||||
_lastMode = mode;
|
||||
}
|
||||
}
|
||||
);
|
||||
@@ -87,9 +86,7 @@ void EngineModeTopic::handleJson(const nlohmann::json& json) {
|
||||
}
|
||||
|
||||
void EngineModeTopic::sendJsonData() {
|
||||
json stateJson;
|
||||
|
||||
OpenSpaceEngine::Mode mode = global::openSpaceEngine->currentMode();
|
||||
const OpenSpaceEngine::Mode mode = global::openSpaceEngine->currentMode();
|
||||
std::string modeString;
|
||||
switch (mode) {
|
||||
case OpenSpaceEngine::Mode::UserControl:
|
||||
@@ -102,6 +99,8 @@ void EngineModeTopic::sendJsonData() {
|
||||
modeString = "camera_path";
|
||||
break;
|
||||
}
|
||||
|
||||
json stateJson;
|
||||
stateJson["mode"] = modeString;
|
||||
|
||||
if (!stateJson.empty()) {
|
||||
|
||||
@@ -74,7 +74,7 @@ void EventTopic::handleJson(const nlohmann::json& json) {
|
||||
|
||||
for (uint8_t i = 0; i < lastEvent; i++) {
|
||||
auto type = static_cast<events::Event::Type>(i);
|
||||
events.push_back(std::string(events::toString(type)));
|
||||
events.emplace_back(events::toString(type));
|
||||
}
|
||||
}
|
||||
else {
|
||||
@@ -99,7 +99,7 @@ void EventTopic::handleJson(const nlohmann::json& json) {
|
||||
global::eventEngine->registerEventTopic(_topicId, type, onCallback);
|
||||
}
|
||||
else if (status == StopSubscription) {
|
||||
events::Event::Type type = events::fromString(event);
|
||||
const events::Event::Type type = events::fromString(event);
|
||||
_subscribedEvents.erase(type);
|
||||
global::eventEngine->unregisterEventTopic(_topicId, type);
|
||||
}
|
||||
@@ -111,7 +111,7 @@ bool EventTopic::isSubscribed() const {
|
||||
return false;
|
||||
}
|
||||
|
||||
bool hasActiveSubscription = std::any_of(
|
||||
const bool hasActiveSubscription = std::any_of(
|
||||
_subscribedEvents.begin(),
|
||||
_subscribedEvents.end(),
|
||||
[](const std::pair<const events::Event::Type, bool>& subscription) {
|
||||
|
||||
@@ -118,7 +118,7 @@ namespace {
|
||||
constexpr const char* Friction = "friction";
|
||||
constexpr const char* Lua = "lua";
|
||||
|
||||
const static std::unordered_map<std::string, AxisType> AxisIndexMap ({
|
||||
const std::unordered_map<std::string, AxisType> AxisIndexMap ({
|
||||
{ OrbitX, AxisType::OrbitX },
|
||||
{ OrbitY, AxisType::OrbitY },
|
||||
{ ZoomIn, AxisType::ZoomIn },
|
||||
@@ -131,7 +131,7 @@ namespace {
|
||||
{ PanY, AxisType::PanY }
|
||||
});
|
||||
|
||||
const static std::unordered_map<std::string, Command> CommandMap ({
|
||||
const std::unordered_map<std::string, Command> CommandMap ({
|
||||
{ Connect, Command::Connect },
|
||||
{ Disconnect, Command::Disconnect },
|
||||
{ InputState, Command::InputState },
|
||||
@@ -147,7 +147,7 @@ using nlohmann::json;
|
||||
namespace openspace {
|
||||
|
||||
FlightControllerTopic::FlightControllerTopic() {
|
||||
for (auto it = AxisIndexMap.begin(); it != AxisIndexMap.end(); ++it) {
|
||||
for (auto it = AxisIndexMap.begin(); it != AxisIndexMap.end(); it++) {
|
||||
global::navigationHandler->setWebsocketAxisMapping(
|
||||
int(std::distance(AxisIndexMap.begin(), it)),
|
||||
it->second
|
||||
@@ -175,7 +175,7 @@ void FlightControllerTopic::handleJson(const nlohmann::json& json) {
|
||||
auto it = CommandMap.find(json[TypeKey]);
|
||||
if (it == CommandMap.end()) {
|
||||
LWARNING(
|
||||
fmt::format("Poorly formatted JSON command: no '{}' in payload", TypeKey)
|
||||
std::format("Malformed JSON command: no '{}' in payload", TypeKey)
|
||||
);
|
||||
return;
|
||||
}
|
||||
@@ -203,7 +203,7 @@ void FlightControllerTopic::handleJson(const nlohmann::json& json) {
|
||||
processLua(json[Lua]);
|
||||
break;
|
||||
default:
|
||||
LWARNING(fmt::format("Unrecognized action: {}", it->first));
|
||||
LWARNING(std::format("Unrecognized action: {}", it->first));
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -270,15 +270,15 @@ void FlightControllerTopic::changeFocus(const nlohmann::json& json) const {
|
||||
if (json.find(FocusKey) == json.end()) {
|
||||
const std::string j = json;
|
||||
LWARNING(
|
||||
fmt::format("Could not find {} key in JSON. JSON was:\n{}", FocusKey, j)
|
||||
std::format("Could not find '{}' key in JSON. JSON was:\n{}", FocusKey, j)
|
||||
);
|
||||
if (json.find(AimKey) == json.end()) {
|
||||
LWARNING(
|
||||
fmt::format("Could not find {} key in JSON. JSON was:\n{}", AimKey, j)
|
||||
std::format("Could not find '{}' key in JSON. JSON was:\n{}", AimKey, j)
|
||||
);
|
||||
if (json.find(AnchorKey) == json.end()) {
|
||||
LWARNING(fmt::format(
|
||||
"Could not find {} key in JSON. JSON was:\n{}", AnchorKey, j
|
||||
LWARNING(std::format(
|
||||
"Could not find '{}' key in JSON. JSON was:\n{}", AnchorKey, j
|
||||
));
|
||||
return;
|
||||
}
|
||||
@@ -324,7 +324,7 @@ void FlightControllerTopic::setRenderableEnabled(const nlohmann::json& json) con
|
||||
if (json[RenderableKey].find(SceneNodeName) == json[RenderableKey].end()) {
|
||||
const std::string j = json;
|
||||
LWARNING(
|
||||
fmt::format("Could not find {} key in JSON. JSON was:\n{}", FocusKey, j)
|
||||
std::format("Could not find '{}' key in JSON. JSON was:\n{}", FocusKey, j)
|
||||
);
|
||||
return;
|
||||
}
|
||||
@@ -389,12 +389,12 @@ void FlightControllerTopic::engageAutopilot(const nlohmann::json &json) {
|
||||
std::fill(_inputState.axes.begin(), _inputState.axes.end(), 0.f);
|
||||
_inputState.isConnected = true;
|
||||
|
||||
for (auto it = input.begin(); it != input.end(); ++it) {
|
||||
for (auto it = input.begin(); it != input.end(); it++) {
|
||||
const auto mapIt = AxisIndexMap.find(it.key());
|
||||
if (mapIt == AxisIndexMap.end()) {
|
||||
if (it.key() != TypeKey || CommandMap.find(it.value()) == CommandMap.end()) {
|
||||
LWARNING(fmt::format(
|
||||
"No axis, button, or command named {} (value: {})",
|
||||
LWARNING(std::format(
|
||||
"No axis, button, or command named '{}' (value: {})",
|
||||
it.key(), static_cast<int>(it.value())
|
||||
));
|
||||
}
|
||||
@@ -429,12 +429,12 @@ void FlightControllerTopic::processInputState(const nlohmann::json& json) {
|
||||
// Get "inputState" object from "payload"
|
||||
auto input = json[InputState][ValuesKey];
|
||||
|
||||
for (auto it = input.begin(); it != input.end(); ++it) {
|
||||
for (auto it = input.begin(); it != input.end(); it++) {
|
||||
const auto mapIt = AxisIndexMap.find(it.key());
|
||||
if (mapIt == AxisIndexMap.end()) {
|
||||
if (it.key() != TypeKey || CommandMap.find(it.value()) == CommandMap.end()) {
|
||||
LWARNING(fmt::format(
|
||||
"No axis, button, or command named {} (value: {})",
|
||||
LWARNING(std::format(
|
||||
"No axis, button, or command named '{}' (value: {})",
|
||||
it.key() , static_cast<int>(it.value())
|
||||
));
|
||||
}
|
||||
|
||||
@@ -52,7 +52,7 @@ namespace {
|
||||
namespace openspace {
|
||||
|
||||
void GetPropertyTopic::handleJson(const nlohmann::json& json) {
|
||||
std::string requestedKey = json.at("property").get<std::string>();
|
||||
const std::string requestedKey = json.at("property").get<std::string>();
|
||||
LDEBUG("Getting property '" + requestedKey + "'...");
|
||||
nlohmann::json response;
|
||||
if (requestedKey == AllPropertiesValue) {
|
||||
@@ -80,7 +80,7 @@ bool GetPropertyTopic::isDone() const {
|
||||
}
|
||||
|
||||
json GetPropertyTopic::allProperties() {
|
||||
json payload {
|
||||
const json payload {
|
||||
{
|
||||
"value",
|
||||
{
|
||||
@@ -100,7 +100,7 @@ json GetPropertyTopic::propertyFromKey(const std::string& key) {
|
||||
return wrappedPayload(prop);
|
||||
}
|
||||
|
||||
return wrappedError(fmt::format("Property '{}' not found", key), 404);
|
||||
return wrappedError(std::format("Property '{}' not found", key), 404);
|
||||
}
|
||||
|
||||
} // namespace openspace
|
||||
|
||||
@@ -73,7 +73,7 @@ namespace {
|
||||
std::string formatObjectAsLuaTable(const nlohmann::json& json) {
|
||||
std::string output = "{";
|
||||
auto it = json.begin();
|
||||
for (size_t i = 0; i < json.size(); ++i, ++it) {
|
||||
for (size_t i = 0; i < json.size(); i++, it++) {
|
||||
output += formatKeyValuePair(it);
|
||||
if (i < json.size() - 1) {
|
||||
output += ",";
|
||||
@@ -85,7 +85,7 @@ namespace {
|
||||
std::string formatArrayAsLuaTable(const nlohmann::json& json) {
|
||||
std::string output = "{";
|
||||
auto it = json.begin();
|
||||
for (size_t i = 0; i < json.size(); ++i, ++it) {
|
||||
for (size_t i = 0; i < json.size(); i++, it++) {
|
||||
output += formatLua(it);
|
||||
if (i < json.size() - 1) {
|
||||
output += ",";
|
||||
@@ -102,7 +102,7 @@ namespace {
|
||||
return formatArrayAsLuaTable(it->get<nlohmann::json>());
|
||||
}
|
||||
if (it->is_number()) {
|
||||
return fmt::format("{}", it->get<double>());
|
||||
return std::format("{}", it->get<double>());
|
||||
}
|
||||
if (it->is_string()) {
|
||||
return formatLuaString(it->get<std::string>());
|
||||
@@ -121,7 +121,7 @@ namespace {
|
||||
{
|
||||
std::string script = "return " + function + "(";
|
||||
auto it = args.begin();
|
||||
for (size_t i = 0; i < args.size(); ++i, ++it) {
|
||||
for (size_t i = 0; i < args.size(); i++, it++) {
|
||||
script += *it;
|
||||
if (i < args.size() - 1) {
|
||||
script += ",";
|
||||
@@ -137,50 +137,48 @@ namespace openspace {
|
||||
|
||||
void LuaScriptTopic::handleJson(const nlohmann::json& json) {
|
||||
try {
|
||||
nlohmann::json::const_iterator script = json.find(KeyScript);
|
||||
nlohmann::json::const_iterator function = json.find(KeyFunction);
|
||||
const auto script = json.find(KeyScript);
|
||||
const auto function = json.find(KeyFunction);
|
||||
|
||||
if (script != json.end() && script->is_string()) {
|
||||
std::string luaScript = script->get<std::string>();
|
||||
nlohmann::json::const_iterator ret = json.find(KeyReturn);
|
||||
bool shouldReturn = (ret != json.end()) &&
|
||||
ret->is_boolean() &&
|
||||
ret->get<bool>();
|
||||
const auto ret = json.find(KeyReturn);
|
||||
const bool shouldReturn =
|
||||
(ret != json.end()) && ret->is_boolean() && ret->get<bool>();
|
||||
|
||||
nlohmann::json::const_iterator sync = json.find(KeyShouldBeSynchronized);
|
||||
const auto sync = json.find(KeyShouldBeSynchronized);
|
||||
bool shouldBeSynchronized = true;
|
||||
if (sync != json.end() && sync->is_boolean()) {
|
||||
shouldBeSynchronized = sync->get<bool>();
|
||||
}
|
||||
|
||||
runScript(luaScript, shouldReturn, shouldBeSynchronized);
|
||||
runScript(std::move(luaScript), shouldReturn, shouldBeSynchronized);
|
||||
}
|
||||
else if (function != json.end() && function->is_string()) {
|
||||
std::string luaFunction = function->get<std::string>();
|
||||
nlohmann::json::const_iterator ret = json.find(KeyReturn);
|
||||
bool shouldReturn = (ret != json.end()) &&
|
||||
ret->is_boolean() &&
|
||||
ret->get<bool>();
|
||||
const std::string luaFunction = function->get<std::string>();
|
||||
const auto ret = json.find(KeyReturn);
|
||||
const bool shouldReturn =
|
||||
(ret != json.end()) && ret->is_boolean() && ret->get<bool>();
|
||||
|
||||
nlohmann::json::const_iterator sync = json.find(KeyShouldBeSynchronized);
|
||||
const auto sync = json.find(KeyShouldBeSynchronized);
|
||||
bool shouldBeSynchronized = true;
|
||||
if (sync != json.end() && sync->is_boolean()) {
|
||||
shouldBeSynchronized = sync->get<bool>();
|
||||
}
|
||||
|
||||
nlohmann::json::const_iterator args = json.find(KeyArguments);
|
||||
const nlohmann::json::const_iterator args = json.find(KeyArguments);
|
||||
if (!args->is_array()) {
|
||||
return;
|
||||
}
|
||||
|
||||
std::vector<std::string> formattedArgs;
|
||||
formattedArgs.reserve(args->size());
|
||||
for (auto it = args->begin(); it != args->end(); ++it) {
|
||||
for (auto it = args->begin(); it != args->end(); it++) {
|
||||
formattedArgs.push_back(formatLua(it));
|
||||
}
|
||||
|
||||
std::string luaScript = generateScript(luaFunction, formattedArgs);
|
||||
runScript(luaScript, shouldReturn, shouldBeSynchronized);
|
||||
runScript(std::move(luaScript), shouldReturn, shouldBeSynchronized);
|
||||
}
|
||||
}
|
||||
catch (const std::out_of_range& e) {
|
||||
@@ -194,10 +192,9 @@ void LuaScriptTopic::runScript(std::string script, bool shouldReturn,
|
||||
{
|
||||
scripting::ScriptEngine::ScriptCallback callback;
|
||||
if (shouldReturn) {
|
||||
callback = [this](ghoul::Dictionary data) {
|
||||
callback = [this](const ghoul::Dictionary& data) {
|
||||
if (_connection) {
|
||||
nlohmann::json j = data;
|
||||
nlohmann::json payload = wrappedPayload(j);
|
||||
const nlohmann::json payload = wrappedPayload(data);
|
||||
_connection->sendJson(payload);
|
||||
_waitingForReturnValue = false;
|
||||
}
|
||||
|
||||
@@ -45,7 +45,7 @@ nlohmann::json MissionTopic::missionJson() const {
|
||||
const std::map<std::string, Mission>& missions =
|
||||
global::missionManager->missionMap();
|
||||
|
||||
ImageSequencer& sequencer = ImageSequencer::ref();
|
||||
const ImageSequencer& sequencer = ImageSequencer::ref();
|
||||
const std::vector<double>& captureTimes = sequencer.captureProgression();
|
||||
std::vector<std::string> captureTimesString(captureTimes.size());
|
||||
|
||||
@@ -69,7 +69,7 @@ nlohmann::json MissionTopic::createPhaseJson(const MissionPhase& phase) const {
|
||||
json phases = json::array();
|
||||
for (const MissionPhase& missionPhase : phase.phases()) {
|
||||
json subphaseJson = createPhaseJson(missionPhase);
|
||||
phases.push_back(subphaseJson);
|
||||
phases.push_back(std::move(subphaseJson));
|
||||
}
|
||||
|
||||
json milestones = json::array();
|
||||
@@ -116,7 +116,7 @@ nlohmann::json MissionTopic::createPhaseJson(const MissionPhase& phase) const {
|
||||
}
|
||||
|
||||
void MissionTopic::handleJson(const nlohmann::json&) {
|
||||
nlohmann::json data = { {"missions", missionJson()} };
|
||||
const nlohmann::json data = { {"missions", missionJson()} };
|
||||
_connection->sendJson(wrappedPayload(data));
|
||||
}
|
||||
|
||||
|
||||
@@ -78,7 +78,8 @@ void SessionRecordingTopic::handleJson(const nlohmann::json& json) {
|
||||
if (!json.at(PropertiesKey).is_array()) {
|
||||
LERROR("Properties must be an array of strings");
|
||||
}
|
||||
nlohmann::json requestedProperties = json.at(PropertiesKey).get<nlohmann::json>();
|
||||
const nlohmann::json requestedProperties =
|
||||
json.at(PropertiesKey).get<nlohmann::json>();
|
||||
for (const auto& p : requestedProperties) {
|
||||
if (!p.is_string()) {
|
||||
_isDone = true;
|
||||
@@ -100,7 +101,7 @@ void SessionRecordingTopic::handleJson(const nlohmann::json& json) {
|
||||
if (event == SubscribeEvent && _sendState) {
|
||||
_stateCallbackHandle = global::sessionRecording->addStateChangeCallback(
|
||||
[this]() {
|
||||
interaction::SessionRecording::SessionState currentState =
|
||||
const interaction::SessionRecording::SessionState currentState =
|
||||
global::sessionRecording->state();
|
||||
if (currentState != _lastState) {
|
||||
sendJsonData();
|
||||
@@ -113,9 +114,9 @@ void SessionRecordingTopic::handleJson(const nlohmann::json& json) {
|
||||
|
||||
void SessionRecordingTopic::sendJsonData() {
|
||||
json stateJson;
|
||||
using SessionRecording = openspace::interaction::SessionRecording;
|
||||
using SessionRecording = interaction::SessionRecording;
|
||||
if (_sendState) {
|
||||
SessionRecording::SessionState state = global::sessionRecording->state();
|
||||
const SessionRecording::SessionState state = global::sessionRecording->state();
|
||||
std::string stateString;
|
||||
switch (state) {
|
||||
case SessionRecording::SessionState::Recording:
|
||||
|
||||
@@ -81,7 +81,7 @@ namespace {
|
||||
}
|
||||
|
||||
std::string literal = "{";
|
||||
for (nlohmann::json::iterator it = value.begin(); it != value.end(); ++it) {
|
||||
for (nlohmann::json::iterator it = value.begin(); it != value.end(); it++) {
|
||||
literal += luaLiteralFromJson(it.value()) += ",";
|
||||
}
|
||||
literal.pop_back(); // remove last comma
|
||||
@@ -94,7 +94,7 @@ namespace {
|
||||
}
|
||||
|
||||
std::string literal = "{";
|
||||
for (nlohmann::json::iterator it = value.begin(); it != value.end(); ++it) {
|
||||
for (nlohmann::json::iterator it = value.begin(); it != value.end(); it++) {
|
||||
literal += it.key() + "=" + luaLiteralFromJson(it.value()) += ",";
|
||||
}
|
||||
literal.pop_back(); // remove last comma
|
||||
@@ -119,11 +119,11 @@ void SetPropertyTopic::handleJson(const nlohmann::json& json) {
|
||||
global::timeManager->setTimeNextFrame(newTime);
|
||||
}
|
||||
else {
|
||||
nlohmann::json value = json.at("value");
|
||||
const nlohmann::json value = json.at("value");
|
||||
std::string literal = luaLiteralFromJson(value);
|
||||
|
||||
global::scriptEngine->queueScript(
|
||||
fmt::format(
|
||||
std::format(
|
||||
"openspace.setPropertyValueSingle(\"{}\", {})", propertyKey, literal
|
||||
),
|
||||
scripting::ScriptEngine::ShouldBeSynchronized::Yes,
|
||||
|
||||
@@ -55,7 +55,7 @@ std::vector<nlohmann::json> ShortcutTopic::shortcutsJson() const {
|
||||
);
|
||||
|
||||
for (const interaction::Action& action : actions) {
|
||||
nlohmann::json shortcutJson = {
|
||||
const nlohmann::json shortcutJson = {
|
||||
{ "identifier", action.identifier },
|
||||
{ "name", action.name },
|
||||
{ "script", action.command },
|
||||
@@ -84,7 +84,7 @@ std::vector<nlohmann::json> ShortcutTopic::shortcutsJson() const {
|
||||
keyBinding.second
|
||||
);
|
||||
|
||||
nlohmann::json shortcutJson = {
|
||||
const nlohmann::json shortcutJson = {
|
||||
{ "key", ghoul::to_string(k.key) },
|
||||
{ "modifiers",
|
||||
{
|
||||
@@ -102,7 +102,7 @@ std::vector<nlohmann::json> ShortcutTopic::shortcutsJson() const {
|
||||
}
|
||||
|
||||
void ShortcutTopic::sendData() const {
|
||||
nlohmann::json data = { {"shortcuts", shortcutsJson()} };
|
||||
const nlohmann::json data = { {"shortcuts", shortcutsJson()} };
|
||||
_connection->sendJson(wrappedPayload(data));
|
||||
}
|
||||
|
||||
|
||||
@@ -66,7 +66,7 @@ bool SkyBrowserTopic::isDone() const {
|
||||
}
|
||||
|
||||
void SkyBrowserTopic::handleJson(const nlohmann::json& json) {
|
||||
std::string event = json.at("event").get<std::string>();
|
||||
const std::string event = json.at("event").get<std::string>();
|
||||
if (event == UnsubscribeEvent) {
|
||||
_isDone = true;
|
||||
return;
|
||||
@@ -80,7 +80,7 @@ void SkyBrowserTopic::handleJson(const nlohmann::json& json) {
|
||||
ServerModule* module = global::moduleEngine->module<ServerModule>();
|
||||
_targetDataCallbackHandle = module->addPreSyncCallback(
|
||||
[this]() {
|
||||
std::chrono::system_clock::time_point now = std::chrono::system_clock::now();
|
||||
const auto now = std::chrono::system_clock::now();
|
||||
if (now - _lastUpdateTime > _skyBrowserUpdateTime) {
|
||||
sendBrowserData();
|
||||
_lastUpdateTime = std::chrono::system_clock::now();
|
||||
@@ -104,8 +104,8 @@ void SkyBrowserTopic::sendBrowserData() {
|
||||
const std::vector<std::unique_ptr<TargetBrowserPair>>& pairs = module->pairs();
|
||||
ghoul::Dictionary targets;
|
||||
for (const std::unique_ptr<TargetBrowserPair>& pair : pairs) {
|
||||
std::string id = pair->browserId();
|
||||
ghoul::Dictionary target = pair->dataAsDictionary();
|
||||
const std::string id = pair->browserId();
|
||||
const ghoul::Dictionary target = pair->dataAsDictionary();
|
||||
targets.setValue(id, target);
|
||||
}
|
||||
data.setValue("browsers", targets);
|
||||
@@ -115,7 +115,7 @@ void SkyBrowserTopic::sendBrowserData() {
|
||||
|
||||
// Only send message if data actually changed
|
||||
if (jsonString != _lastUpdateJsonString) {
|
||||
json jsonData = json::parse(jsonString.begin(), jsonString.end());
|
||||
const json jsonData = json::parse(jsonString.begin(), jsonString.end());
|
||||
_connection->sendJson(wrappedPayload(jsonData));
|
||||
}
|
||||
|
||||
|
||||
@@ -92,7 +92,7 @@ void SubscriptionTopic::handleJson(const nlohmann::json& json) {
|
||||
onChange();
|
||||
}
|
||||
else {
|
||||
LWARNING(fmt::format("Could not subscribe. Property '{}' not found", key));
|
||||
LWARNING(std::format("Could not subscribe. Property '{}' not found", key));
|
||||
}
|
||||
}
|
||||
if (event == StopSubscription) {
|
||||
|
||||
@@ -64,7 +64,7 @@ bool TimeTopic::isDone() const {
|
||||
}
|
||||
|
||||
void TimeTopic::handleJson(const nlohmann::json& json) {
|
||||
std::string event = json.at("event").get<std::string>();
|
||||
const std::string event = json.at("event").get<std::string>();
|
||||
if (event == UnsubscribeEvent) {
|
||||
_isDone = true;
|
||||
return;
|
||||
@@ -79,7 +79,7 @@ void TimeTopic::handleJson(const nlohmann::json& json) {
|
||||
}
|
||||
|
||||
_timeCallbackHandle = global::timeManager->addTimeChangeCallback([this]() {
|
||||
std::chrono::system_clock::time_point now = std::chrono::system_clock::now();
|
||||
const auto now = std::chrono::system_clock::now();
|
||||
if (now - _lastUpdateTime > TimeUpdateInterval) {
|
||||
sendCurrentTime();
|
||||
}
|
||||
@@ -89,7 +89,7 @@ void TimeTopic::handleJson(const nlohmann::json& json) {
|
||||
// Throttle by last update,
|
||||
// but force update if pause state or target delta changes.
|
||||
|
||||
std::chrono::system_clock::time_point now = std::chrono::system_clock::now();
|
||||
const auto now = std::chrono::system_clock::now();
|
||||
const double targetDeltaTime = global::timeManager->targetDeltaTime();
|
||||
const bool isPaused = global::timeManager->isPaused();
|
||||
const bool forceUpdate =
|
||||
@@ -110,7 +110,7 @@ void TimeTopic::handleJson(const nlohmann::json& json) {
|
||||
);
|
||||
}
|
||||
|
||||
const json TimeTopic::getNextPrevDeltaTimeStepJson() {
|
||||
json TimeTopic::getNextPrevDeltaTimeStepJson() {
|
||||
const std::optional<double> nextStep = global::timeManager->nextDeltaTimeStep();
|
||||
const std::optional<double> prevStep = global::timeManager->previousDeltaTimeStep();
|
||||
const bool hasNext = nextStep.has_value();
|
||||
|
||||
@@ -41,7 +41,7 @@ void TriggerPropertyTopic::handleJson(const nlohmann::json& json) {
|
||||
try {
|
||||
const std::string& propertyKey = json.at("property").get<std::string>();
|
||||
global::scriptEngine->queueScript(
|
||||
fmt::format(
|
||||
std::format(
|
||||
"openspace.setPropertyValueSingle(\"{}\", nil)", propertyKey
|
||||
),
|
||||
scripting::ScriptEngine::ShouldBeSynchronized::Yes,
|
||||
|
||||
Reference in New Issue
Block a user