mirror of
https://github.com/OpenSpace/OpenSpace.git
synced 2026-01-06 11:39:49 -06:00
Code cleanup branch (#618)
* Make height map fallback layer work again * Add documentation to joystick button bindings * Removed grouped property headers * Add new version number constant generated by CMake * Make Joystick deadzone work properly * Change the startup date on Earth to today * Fix key modifier handling * Add debugging indices for TreeNodeDebugging * Fix script schedule for OsirisRex * Do not open Mission schedule automatically * Upload default projection texture automatically * General code cleanup * Fix check_style_guide warnings * Remove .clang-format * MacOS compile fixes * Clang analyzer fixes
This commit is contained in:
@@ -25,51 +25,49 @@
|
||||
#ifndef __OPENSPACE_MODULE_SERVER___CONNECTION___H__
|
||||
#define __OPENSPACE_MODULE_SERVER___CONNECTION___H__
|
||||
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <ghoul/io/socket/tcpsocketserver.h>
|
||||
#include <ghoul/io/socket/websocketserver.h>
|
||||
#include <ghoul/misc/templatefactory.h>
|
||||
#include <ext/json/json.hpp>
|
||||
#include <ghoul/logging/logmanager.h>
|
||||
#include <fmt/format.h>
|
||||
#include <include/openspace/engine/openspaceengine.h>
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <thread>
|
||||
|
||||
#include "topic.h"
|
||||
namespace ghoul::io { class Socket; }
|
||||
|
||||
namespace openspace {
|
||||
|
||||
using TopicId = size_t;
|
||||
|
||||
class Topic;
|
||||
|
||||
class Connection {
|
||||
public:
|
||||
Connection(std::shared_ptr<ghoul::io::Socket> s, const std::string &address);
|
||||
Connection(std::unique_ptr<ghoul::io::Socket> s, std::string address);
|
||||
|
||||
void handleMessage(std::string message);
|
||||
void handleMessage(const std::string& message);
|
||||
void sendMessage(const std::string& message);
|
||||
void handleJson(nlohmann::json json);
|
||||
void handleJson(const nlohmann::json& json);
|
||||
void sendJson(const nlohmann::json& json);
|
||||
void setAuthorized(const bool status);
|
||||
void setAuthorized(bool status);
|
||||
|
||||
bool isAuthorized();
|
||||
bool isAuthorized() const;
|
||||
|
||||
std::shared_ptr<ghoul::io::Socket> socket();
|
||||
ghoul::io::Socket* socket();
|
||||
std::thread& thread();
|
||||
void setThread(std::thread&& thread);
|
||||
|
||||
private:
|
||||
ghoul::TemplateFactory<Topic> _topicFactory;
|
||||
std::map<TopicId, std::unique_ptr<Topic>> _topics;
|
||||
std::shared_ptr<ghoul::io::Socket> _socket;
|
||||
std::unique_ptr<ghoul::io::Socket> _socket;
|
||||
std::thread _thread;
|
||||
|
||||
std::string _address;
|
||||
bool _requireAuthorization;
|
||||
bool _isAuthorized;
|
||||
std::map <TopicId, std::string> _messageQueue;
|
||||
std::map <TopicId, std::chrono::system_clock::time_point> _sentMessages;
|
||||
bool _isAuthorized = false;
|
||||
std::map<TopicId, std::string> _messageQueue;
|
||||
std::map<TopicId, std::chrono::system_clock::time_point> _sentMessages;
|
||||
|
||||
bool isWhitelisted();
|
||||
bool isWhitelisted() const;
|
||||
};
|
||||
|
||||
} // namespace openspace
|
||||
|
||||
@@ -25,22 +25,23 @@
|
||||
#ifndef __OPENSPACE_MODULE_SERVER___CONNECTIONPOOL___H__
|
||||
#define __OPENSPACE_MODULE_SERVER___CONNECTIONPOOL___H__
|
||||
|
||||
#include <ghoul/io/socket/socketserver.h>
|
||||
|
||||
#include <memory>
|
||||
#include <thread>
|
||||
#include <mutex>
|
||||
#include <map>
|
||||
#include <functional>
|
||||
#include <memory>
|
||||
#include <mutex>
|
||||
#include <vector>
|
||||
#include <atomic>
|
||||
|
||||
namespace ghoul::io {
|
||||
class Socket;
|
||||
class SocketServer;
|
||||
} // namespace ghoul::io
|
||||
|
||||
namespace openspace {
|
||||
|
||||
class ConnectionPool {
|
||||
public:
|
||||
ConnectionPool(
|
||||
std::function<void(std::shared_ptr<ghoul::io::Socket> socket)> handleSocket);
|
||||
using SocketHandleFunc = std::function<void(ghoul::io::Socket& socket)>;
|
||||
|
||||
ConnectionPool(SocketHandleFunc handleSocket);
|
||||
~ConnectionPool();
|
||||
|
||||
void addServer(std::shared_ptr<ghoul::io::SocketServer> server);
|
||||
@@ -54,9 +55,9 @@ private:
|
||||
void removeDisconnectedSockets();
|
||||
void acceptNewSockets();
|
||||
|
||||
std::function<void(std::shared_ptr<ghoul::io::Socket>)> _handleSocket;
|
||||
SocketHandleFunc _handleSocket;
|
||||
std::vector<std::shared_ptr<ghoul::io::SocketServer>> _socketServers;
|
||||
std::vector<std::shared_ptr<ghoul::io::Socket>> _sockets;
|
||||
std::vector<std::unique_ptr<ghoul::io::Socket>> _sockets;
|
||||
};
|
||||
|
||||
} // namespace openspace
|
||||
|
||||
@@ -25,36 +25,37 @@
|
||||
#ifndef __OPENSPACE_MODULE_SERVER___JSON_CONVERTERS___H__
|
||||
#define __OPENSPACE_MODULE_SERVER___JSON_CONVERTERS___H__
|
||||
|
||||
#include <openspace/properties/property.h>
|
||||
#include <openspace/scene/scenegraphnode.h>
|
||||
#include <openspace/rendering/renderable.h>
|
||||
#include <ext/json/json.hpp>
|
||||
#include <ghoul/glm.h>
|
||||
|
||||
using json = nlohmann::json;
|
||||
|
||||
namespace openspace::properties {
|
||||
|
||||
void to_json(json &j, const Property &p);
|
||||
void to_json(json &j, const Property* pP);
|
||||
void to_json(json &j, const PropertyOwner &p);
|
||||
void to_json(json &j, const PropertyOwner *p);
|
||||
class Property;
|
||||
class PropertyOwner;
|
||||
|
||||
void to_json(nlohmann::json& j, const Property& p);
|
||||
void to_json(nlohmann::json& j, const Property* pP);
|
||||
void to_json(nlohmann::json& j, const PropertyOwner& p);
|
||||
void to_json(nlohmann::json& j, const PropertyOwner* p);
|
||||
|
||||
} // namespace openspace::properties
|
||||
|
||||
namespace openspace {
|
||||
|
||||
void to_json(json &j, const SceneGraphNode &n);
|
||||
void to_json(json &j, const SceneGraphNode* pN);
|
||||
class Renderable;
|
||||
class SceneGraphNode;
|
||||
|
||||
void to_json(json &j, const Renderable &r);
|
||||
void to_json(json &j, const Renderable* pR);
|
||||
void to_json(nlohmann::json& j, const SceneGraphNode& n);
|
||||
void to_json(nlohmann::json& j, const SceneGraphNode* pN);
|
||||
|
||||
void to_json(nlohmann::json& j, const Renderable& r);
|
||||
void to_json(nlohmann::json& j, const Renderable* pR);
|
||||
|
||||
} // namespace openspace
|
||||
|
||||
namespace glm {
|
||||
|
||||
void to_json(json &j, const dvec3 &v);
|
||||
void to_json(nlohmann::json& j, const dvec3& v);
|
||||
|
||||
} // namespace glm
|
||||
|
||||
|
||||
@@ -25,41 +25,21 @@
|
||||
#ifndef __OPENSPACE_MODULE_SERVER___AUTHORIZATION_TOPIC___H__
|
||||
#define __OPENSPACE_MODULE_SERVER___AUTHORIZATION_TOPIC___H__
|
||||
|
||||
#include <ctime>
|
||||
#include <ext/json/json.hpp>
|
||||
#include <ghoul/logging/logmanager.h>
|
||||
#include <fmt/format.h>
|
||||
|
||||
#include "topic.h"
|
||||
#include "connection.h"
|
||||
#include <modules/server/include/topics/topic.h>
|
||||
|
||||
namespace openspace {
|
||||
|
||||
class AuthorizationTopic : public Topic {
|
||||
public:
|
||||
AuthorizationTopic();
|
||||
void handleJson(nlohmann::json json);
|
||||
bool isDone();
|
||||
AuthorizationTopic() = default;
|
||||
|
||||
/* https://httpstatuses.com/ */
|
||||
enum class StatusCode : int {
|
||||
OK = 200,
|
||||
Accepted = 202,
|
||||
|
||||
BadRequest = 400,
|
||||
Unauthorized = 401,
|
||||
NotAcceptable = 406,
|
||||
|
||||
NotImplemented = 501
|
||||
};
|
||||
void handleJson(const nlohmann::json& json) override;
|
||||
bool isDone() const override;
|
||||
|
||||
private:
|
||||
bool _isAuthenticated;
|
||||
bool authorize(const std::string& key);
|
||||
|
||||
const std::string getKey() const;
|
||||
bool authorize(const std::string key);
|
||||
nlohmann::json message(const std::string &message,
|
||||
StatusCode statusCode = StatusCode::NotImplemented);
|
||||
bool _isAuthenticated = false;
|
||||
};
|
||||
|
||||
} // namespace openspace
|
||||
45
modules/server/include/topics/bouncetopic.h
Normal file
45
modules/server/include/topics/bouncetopic.h
Normal file
@@ -0,0 +1,45 @@
|
||||
/*****************************************************************************************
|
||||
* *
|
||||
* OpenSpace *
|
||||
* *
|
||||
* Copyright (c) 2014-2018 *
|
||||
* *
|
||||
* 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___BOUNCETOPIC___H__
|
||||
#define __OPENSPACE_MODULE_SERVER___BOUNCETOPIC___H__
|
||||
|
||||
#include <modules/server/include/topics/topic.h>
|
||||
|
||||
namespace openspace {
|
||||
|
||||
class Connection;
|
||||
|
||||
class BounceTopic : public Topic {
|
||||
public:
|
||||
BounceTopic() = default;
|
||||
virtual ~BounceTopic() = default;
|
||||
|
||||
void handleJson(const nlohmann::json& json) override;
|
||||
bool isDone() const override;
|
||||
};
|
||||
|
||||
} // namespace openspace
|
||||
|
||||
#endif // __OPENSPACE_MODULE_SERVER___BOUNCETOPIC___H__
|
||||
@@ -25,22 +25,21 @@
|
||||
#ifndef __OPENSPACE_MODULE_SERVER___GETPROPERTY_TOPIC___H__
|
||||
#define __OPENSPACE_MODULE_SERVER___GETPROPERTY_TOPIC___H__
|
||||
|
||||
#include <openspace/query/query.h>
|
||||
#include "topic.h"
|
||||
#include "connection.h"
|
||||
#include <modules/server/include/topics/topic.h>
|
||||
|
||||
namespace openspace {
|
||||
|
||||
class GetPropertyTopic : public Topic {
|
||||
public:
|
||||
GetPropertyTopic();
|
||||
~GetPropertyTopic() {};
|
||||
void handleJson(nlohmann::json json);
|
||||
bool isDone();
|
||||
GetPropertyTopic() = default;
|
||||
virtual ~GetPropertyTopic() = default;
|
||||
|
||||
void handleJson(const nlohmann::json& json) override;
|
||||
bool isDone() const override;
|
||||
|
||||
private:
|
||||
nlohmann::json getAllProperties();
|
||||
nlohmann::json getPropertyFromKey(const std::string& key);
|
||||
nlohmann::json allProperties();
|
||||
nlohmann::json propertyFromKey(const std::string& key);
|
||||
};
|
||||
|
||||
} // namespace openspace
|
||||
@@ -25,17 +25,17 @@
|
||||
#ifndef __OPENSPACE_MODULE_SERVER___LUASCRIPTTOPIC___H__
|
||||
#define __OPENSPACE_MODULE_SERVER___LUASCRIPTTOPIC___H__
|
||||
|
||||
#include <ext/json/json.hpp>
|
||||
#include <modules/server/include/topic.h>
|
||||
#include <modules/server/include/topics/topic.h>
|
||||
|
||||
namespace openspace {
|
||||
|
||||
class LuaScriptTopic : public Topic {
|
||||
public:
|
||||
LuaScriptTopic() : Topic() {};
|
||||
~LuaScriptTopic() {};
|
||||
void handleJson(nlohmann::json json);
|
||||
bool isDone() { return true; };
|
||||
LuaScriptTopic() = default;
|
||||
virtual ~LuaScriptTopic() = default;
|
||||
|
||||
void handleJson(const nlohmann::json& json) override;
|
||||
bool isDone() const override;
|
||||
};
|
||||
|
||||
} // namespace openspace
|
||||
@@ -25,20 +25,17 @@
|
||||
#ifndef __OPENSPACE_MODULE_SERVER___SETPROPERTYTOPIC___H__
|
||||
#define __OPENSPACE_MODULE_SERVER___SETPROPERTYTOPIC___H__
|
||||
|
||||
#include <ext/json/json.hpp>
|
||||
#include <modules/server/include/topic.h>
|
||||
#include <modules/server/include/topics/topic.h>
|
||||
|
||||
namespace openspace {
|
||||
|
||||
class SetPropertyTopic : public Topic {
|
||||
public:
|
||||
SetPropertyTopic() : Topic() {};
|
||||
~SetPropertyTopic() {};
|
||||
void handleJson(nlohmann::json json);
|
||||
bool isDone() { return true; };
|
||||
SetPropertyTopic() = default;
|
||||
virtual ~SetPropertyTopic() = default;
|
||||
|
||||
private:
|
||||
void setTime(const std::string& value);
|
||||
void handleJson(const nlohmann::json& json) override;
|
||||
bool isDone() const override;
|
||||
};
|
||||
|
||||
} // namespace
|
||||
@@ -25,26 +25,28 @@
|
||||
#ifndef __OPENSPACE_MODULE_SERVER___SUBSCRIPTION_TOPIC___H__
|
||||
#define __OPENSPACE_MODULE_SERVER___SUBSCRIPTION_TOPIC___H__
|
||||
|
||||
#include <openspace/util/timemanager.h>
|
||||
#include <openspace/query/query.h>
|
||||
#include "topic.h"
|
||||
#include "connection.h"
|
||||
#include <modules/server/include/topics/topic.h>
|
||||
|
||||
namespace openspace::properties { class Property; }
|
||||
|
||||
namespace openspace {
|
||||
class property;
|
||||
|
||||
class SubscriptionTopic : public Topic {
|
||||
public:
|
||||
SubscriptionTopic();
|
||||
SubscriptionTopic() = default;
|
||||
~SubscriptionTopic();
|
||||
void handleJson(nlohmann::json json);
|
||||
bool isDone();
|
||||
|
||||
void handleJson(const nlohmann::json& json) override;
|
||||
bool isDone() const override;
|
||||
|
||||
private:
|
||||
bool _requestedResourceIsSubscribable;
|
||||
bool _isSubscribedTo;
|
||||
int _onChangeHandle;
|
||||
int _onDeleteHandle;
|
||||
properties::Property* _prop;
|
||||
const int UnsetCallbackHandle = -1;
|
||||
|
||||
bool _requestedResourceIsSubscribable = false;
|
||||
bool _isSubscribedTo = false;
|
||||
int _onChangeHandle = UnsetCallbackHandle;
|
||||
int _onDeleteHandle = UnsetCallbackHandle;
|
||||
properties::Property* _prop = nullptr;
|
||||
};
|
||||
|
||||
} // namespace openspace
|
||||
@@ -25,25 +25,28 @@
|
||||
#ifndef __OPENSPACE_MODULE_SERVER___TIME_TOPIC___H__
|
||||
#define __OPENSPACE_MODULE_SERVER___TIME_TOPIC___H__
|
||||
|
||||
#include <openspace/util/timemanager.h>
|
||||
#include "topic.h"
|
||||
#include <modules/server/include/topics/topic.h>
|
||||
#include <chrono>
|
||||
|
||||
namespace openspace {
|
||||
|
||||
class TimeTopic : public Topic {
|
||||
public:
|
||||
TimeTopic();
|
||||
~TimeTopic();
|
||||
void handleJson(nlohmann::json json);
|
||||
bool isDone();
|
||||
virtual ~TimeTopic();
|
||||
|
||||
void handleJson(const nlohmann::json& json) override;
|
||||
bool isDone() const override;
|
||||
|
||||
private:
|
||||
const int UnsetOnChangeHandle = -1;
|
||||
|
||||
nlohmann::json currentTime();
|
||||
nlohmann::json deltaTime();
|
||||
|
||||
bool _isDone;
|
||||
int _timeCallbackHandle;
|
||||
int _deltaTimeCallbackHandle;
|
||||
int _timeCallbackHandle = UnsetOnChangeHandle;
|
||||
int _deltaTimeCallbackHandle = UnsetOnChangeHandle;
|
||||
bool _isDone = false;
|
||||
std::chrono::system_clock::time_point _lastUpdateTime;
|
||||
};
|
||||
|
||||
@@ -37,25 +37,17 @@ public:
|
||||
virtual ~Topic() = default;
|
||||
|
||||
void initialize(Connection* connection, size_t topicId);
|
||||
nlohmann::json wrappedPayload(const nlohmann::json &payload) const;
|
||||
nlohmann::json wrappedPayload(const nlohmann::json& payload) const;
|
||||
nlohmann::json wrappedError(std::string message = "Could not complete request.",
|
||||
int code = 500);
|
||||
virtual void handleJson(nlohmann::json json) = 0;
|
||||
virtual bool isDone() = 0;
|
||||
virtual void handleJson(const nlohmann::json& json) = 0;
|
||||
virtual bool isDone() const = 0;
|
||||
|
||||
protected:
|
||||
size_t _topicId;
|
||||
Connection* _connection;
|
||||
};
|
||||
|
||||
class BounceTopic : public Topic {
|
||||
public:
|
||||
BounceTopic() : Topic() {};
|
||||
~BounceTopic() {};
|
||||
void handleJson(nlohmann::json json);
|
||||
bool isDone() { return false; }
|
||||
};
|
||||
|
||||
} // namespace openspace
|
||||
|
||||
#endif // __OPENSPACE_MODULE_SERVER___TOPIC___H__
|
||||
@@ -25,17 +25,17 @@
|
||||
#ifndef __OPENSPACE_MODULE_SERVER___TRIGGERPROPERTYTOPIC___H__
|
||||
#define __OPENSPACE_MODULE_SERVER___TRIGGERPROPERTYTOPIC___H__
|
||||
|
||||
#include <ext/json/json.hpp>
|
||||
#include <modules/server/include/topic.h>
|
||||
#include <modules/server/include/topics/topic.h>
|
||||
|
||||
namespace openspace {
|
||||
|
||||
class TriggerPropertyTopic : public Topic {
|
||||
public:
|
||||
TriggerPropertyTopic() : Topic() {};
|
||||
~TriggerPropertyTopic() {};
|
||||
void handleJson(nlohmann::json json);
|
||||
bool isDone() { return true; };
|
||||
TriggerPropertyTopic() = default;
|
||||
virtual ~TriggerPropertyTopic() = default;
|
||||
|
||||
void handleJson(const nlohmann::json& json) override;
|
||||
bool isDone() const override;
|
||||
};
|
||||
|
||||
} // namespace
|
||||
Reference in New Issue
Block a user