Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Brayns 344 make network synchronous #988

Merged
merged 15 commits into from
Feb 28, 2022
15 changes: 0 additions & 15 deletions brayns/Brayns.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -188,11 +188,6 @@ struct Brayns::Impl : public PluginAPI
_engine->getStatistics().resetModified();
}

NetworkManager *getNetworkManager()
{
return _pluginManager.getNetworkManager();
}

Engine &getEngine() final
{
return *_engine;
Expand All @@ -218,16 +213,6 @@ struct Brayns::Impl : public PluginAPI
return _loaderRegistry;
}

INetworkInterface *getNetworkInterface() final
{
auto manager = _pluginManager.getNetworkManager();
if (!manager)
{
return nullptr;
}
return &manager->getInterface();
}

Scene &getScene() final
{
return _engine->getScene();
Expand Down
9 changes: 9 additions & 0 deletions brayns/PluginManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,15 @@ void PluginManager::initPlugins(PluginAPI *api)
extension->_api = api;
extension->init();
}

if (_networkManager)
{
auto &interface = _networkManager->getInterface();
for (const auto &extension : _extensions)
{
extension->registerEntrypoints(interface);
}
}
}

void PluginManager::destroyPlugins()
Expand Down
4 changes: 1 addition & 3 deletions brayns/common/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
set(BRAYNSCOMMON_SOURCES
BaseObject.cpp
Log.cpp
Progress.cpp
PropertyObject.cpp
Statistics.cpp
Timer.cpp
Expand All @@ -31,8 +30,7 @@ set(BRAYNSCOMMON_PUBLIC_HEADERS
Log.h
MaterialsColorMap.h
MathTypes.h
PixelFormat.h
Progress.h
PixelFormat.h
PropertyObject.h
Statistics.h
TextureType.h
Expand Down
53 changes: 0 additions & 53 deletions brayns/common/Progress.cpp

This file was deleted.

59 changes: 0 additions & 59 deletions brayns/common/Progress.h

This file was deleted.

99 changes: 57 additions & 42 deletions brayns/json/JsonObjectInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,58 +23,73 @@

#include "JsonExtractor.h"

namespace brayns
namespace
{
JsonSchema JsonObjectProperty::getSchemaWithOptions(const void *message) const
class JsonObjectHelper
{
auto schema = getSchema(message);
JsonSchemaOptions::add(schema, options);
return schema;
}
public:
static brayns::JsonSchema getSchemaWithOptions(const brayns::JsonObjectProperty &property, const void *message)
{
auto schema = property.getSchema(message);
auto &options = property.options;
brayns::JsonSchemaOptions::add(schema, options);
return schema;
}

void JsonObjectProperty::add(JsonSchema &schema, const void *message) const
{
if (isRequired())
static void add(const brayns::JsonObjectProperty &property, brayns::JsonSchema &schema, const void *message)
{
auto &required = schema.required;
required.push_back(name);
auto &key = property.name;
if (isRequired(property))
{
auto &required = schema.required;
required.push_back(key);
}
auto &properties = schema.properties;
properties[key] = getSchemaWithOptions(property, message);
}
schema.properties[name] = getSchemaWithOptions(message);
}

JsonValue JsonObjectProperty::extract(const JsonObject &object) const
{
auto json = object.get(name);
if (!json.isEmpty())
static brayns::JsonValue extract(const brayns::JsonObjectProperty &property, const brayns::JsonObject &object)
{
return json;
auto &key = property.name;
auto json = object.get(key);
if (!json.isEmpty())
{
return json;
}
auto &options = property.options;
auto &defaultValue = options.defaultValue;
if (!defaultValue)
{
return json;
}
return *defaultValue;
}
auto &defaultValue = options.defaultValue;
if (!defaultValue)

static bool isRequired(const brayns::JsonObjectProperty &property)
{
return json;
auto &options = property.options;
auto &required = options.required;
return required.value_or(false);
}
return *defaultValue;
}

bool JsonObjectProperty::isRequired() const
{
auto &required = options.required;
return required.value_or(false);
}
static bool isReadOnly(const brayns::JsonObjectProperty &property)
{
auto &options = property.options;
auto &readOnly = options.readOnly;
return readOnly.value_or(false);
}

bool JsonObjectProperty::isReadOnly() const
{
auto &readOnly = options.readOnly;
return readOnly.value_or(false);
}
static bool isWriteOnly(const brayns::JsonObjectProperty &property)
{
auto &options = property.options;
auto &writeOnly = options.writeOnly;
return writeOnly.value_or(false);
}
};
} // namespace

bool JsonObjectProperty::isWriteOnly() const
namespace brayns
{
auto &writeOnly = options.writeOnly;
return writeOnly.value_or(false);
}

JsonObjectInfo::JsonObjectInfo(std::string title)
: _title(std::move(title))
{
Expand All @@ -87,7 +102,7 @@ JsonSchema JsonObjectInfo::getSchema(const void *message) const
schema.type = JsonType::Object;
for (const auto &property : _properties)
{
property.add(schema, message);
JsonObjectHelper::add(property, schema, message);
}
return schema;
}
Expand All @@ -97,7 +112,7 @@ bool JsonObjectInfo::serialize(const void *message, JsonValue &json) const
auto object = Poco::makeShared<JsonObject>();
for (const auto &property : _properties)
{
if (property.isWriteOnly())
if (JsonObjectHelper::isWriteOnly(property))
{
continue;
}
Expand All @@ -120,11 +135,11 @@ bool JsonObjectInfo::deserialize(const JsonValue &json, void *message) const
}
for (const auto &property : _properties)
{
if (property.isReadOnly())
if (JsonObjectHelper::isReadOnly(property))
{
continue;
}
auto child = property.extract(*object);
auto child = JsonObjectHelper::extract(property, *object);
property.deserialize(child, message);
}
return true;
Expand Down
7 changes: 0 additions & 7 deletions brayns/json/JsonObjectInfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,13 +49,6 @@ struct JsonObjectProperty
std::function<JsonSchema(const void *)> getSchema;
std::function<bool(const void *, JsonValue &)> serialize;
std::function<bool(const JsonValue &, void *)> deserialize;

JsonSchema getSchemaWithOptions(const void *message) const;
void add(JsonSchema &schema, const void *message) const;
JsonValue extract(const JsonObject &object) const;
bool isRequired() const;
bool isReadOnly() const;
bool isWriteOnly() const;
};

/**
Expand Down
Loading