diff --git a/CMakeLists.txt b/CMakeLists.txt index a2e1607..1c37ad2 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -2,11 +2,10 @@ # See COPYRIGHT in top-level directory. cmake_minimum_required (VERSION 3.8) project (alpha C CXX) -set (CMAKE_CXX_STANDARD 14) +set (CMAKE_CXX_STANDARD 17) +set (CMAKE_CXX_STANDARD_REQUIRED ON) enable_testing () -add_definitions (-Wextra -Wall -Wpedantic) - add_library (coverage_config INTERFACE) option (ENABLE_TESTS "Build tests" OFF) diff --git a/spack.yaml b/spack.yaml index 8ef4d1a..bdb0bec 100644 --- a/spack.yaml +++ b/spack.yaml @@ -20,3 +20,5 @@ spack: require: "@0.15.0:" mochi-thallium: require: "@0.12.0:" + mochi-bedrock-module-api: + require: "@0.2.0:" diff --git a/src/BedrockModule.cpp b/src/BedrockModule.cpp index 3257203..c165bb9 100644 --- a/src/BedrockModule.cpp +++ b/src/BedrockModule.cpp @@ -1,75 +1,62 @@ /* - * (C) 2020 The University of Chicago + * (C) 2024 The University of Chicago * * See COPYRIGHT in top-level directory. */ #include "alpha/Client.hpp" #include "alpha/Provider.hpp" #include "alpha/ProviderHandle.hpp" -#include -namespace tl = thallium; - -class AlphaFactory : public bedrock::AbstractServiceFactory { - - public: - - AlphaFactory() {} - - void *registerProvider(const bedrock::FactoryArgs &args) override { - auto provider = new alpha::Provider(args.mid, args.provider_id, - args.config, tl::pool(args.pool)); - return static_cast(provider); - } - - void deregisterProvider(void *p) override { - auto provider = static_cast(p); - delete provider; - } - - std::string getProviderConfig(void *p) override { - auto provider = static_cast(p); - return provider->getConfig(); - } +#include - void *initClient(const bedrock::FactoryArgs& args) override { - return static_cast(new alpha::Client(args.mid)); - } - - void finalizeClient(void *client) override { - delete static_cast(client); - } +namespace tl = thallium; - std::string getClientConfig(void* c) override { - auto client = static_cast(c); - return client->getConfig(); - } +class AlphaComponent : public bedrock::AbstractComponent { - void *createProviderHandle(void *c, hg_addr_t address, - uint16_t provider_id) override { - auto client = static_cast(c); - auto ph = new alpha::ProviderHandle( - client->engine(), - address, - provider_id, - false); - return static_cast(ph); - } + std::unique_ptr m_provider; - void destroyProviderHandle(void *providerHandle) override { - auto ph = static_cast(providerHandle); - delete ph; - } - - const std::vector &getProviderDependencies() override { - static const std::vector no_dependency; - return no_dependency; - } + public: - const std::vector &getClientDependencies() override { - static const std::vector no_dependency; - return no_dependency; - } + AlphaComponent(const tl::engine& engine, + uint16_t provider_id, + const std::string& config, + const tl::pool& pool) + : m_provider{std::make_unique(engine, provider_id, config, pool)} + {} + + void* getHandle() override { + return static_cast(m_provider.get()); + } + + std::string getConfig() override { + return m_provider->getConfig(); + } + + static std::shared_ptr + Register(const bedrock::ComponentArgs& args) { + tl::pool pool; + auto it = args.dependencies.find("pool"); + if(it != args.dependencies.end() && !it->second.empty()) { + pool = it->second[0]->getHandle(); + } + return std::make_shared( + args.engine, args.provider_id, args.config, pool); + } + + static std::vector + GetDependencies(const bedrock::ComponentArgs& args) { + (void)args; + std::vector dependencies{ + bedrock::Dependency{ + /* name */ "pool", + /* type */ "pool", + /* is_required */ false, + /* is_array */ false, + /* is_updatable */ false + } + }; + return dependencies; + } }; -BEDROCK_REGISTER_MODULE_FACTORY(alpha, AlphaFactory) +BEDROCK_REGISTER_COMPONENT_TYPE(alpha, AlphaComponent) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index b71daf6..16f0229 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -26,6 +26,7 @@ set (alpha-vers "${ALPHA_VERSION_MAJOR}.${ALPHA_VERSION_MINOR}") # server library add_library (alpha-server ${server-src-files} ${dummy-src-files}) add_library (alpha::server ALIAS alpha-server) +target_compile_features (alpha-server PUBLIC cxx_std_17) target_link_libraries (alpha-server PUBLIC thallium nlohmann_json::nlohmann_json PRIVATE spdlog::spdlog fmt::fmt coverage_config) @@ -40,6 +41,7 @@ set_target_properties (alpha-server # client library add_library (alpha-client ${client-src-files}) +target_compile_features (alpha-client PUBLIC cxx_std_17) add_library (alpha::client ALIAS alpha-client) target_link_libraries (alpha-client PUBLIC thallium nlohmann_json::nlohmann_json @@ -57,6 +59,7 @@ if (${ENABLE_BEDROCK}) # bedrock module library add_library (alpha-bedrock-module ${module-src-files}) add_library (alpha::bedrock ALIAS alpha-bedrock-module) +target_compile_features (alpha-bedrock-module PUBLIC cxx_std_17) target_link_libraries (alpha-bedrock-module alpha-server alpha-client bedrock::module-api coverage_config) target_include_directories (alpha-bedrock-module PUBLIC $) target_include_directories (alpha-bedrock-module BEFORE PUBLIC