Skip to content

Commit

Permalink
fixing bedrock module
Browse files Browse the repository at this point in the history
  • Loading branch information
mdorier committed Sep 24, 2024
1 parent cdc7f20 commit e00c867
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 63 deletions.
5 changes: 2 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 2 additions & 0 deletions spack.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,5 @@ spack:
require: "@0.15.0:"
mochi-thallium:
require: "@0.12.0:"
mochi-bedrock-module-api:
require: "@0.2.0:"
107 changes: 47 additions & 60 deletions src/BedrockModule.cpp
Original file line number Diff line number Diff line change
@@ -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 <bedrock/AbstractServiceFactory.hpp>

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<void *>(provider);
}

void deregisterProvider(void *p) override {
auto provider = static_cast<alpha::Provider *>(p);
delete provider;
}

std::string getProviderConfig(void *p) override {
auto provider = static_cast<alpha::Provider *>(p);
return provider->getConfig();
}
#include <bedrock/AbstractComponent.hpp>

void *initClient(const bedrock::FactoryArgs& args) override {
return static_cast<void *>(new alpha::Client(args.mid));
}

void finalizeClient(void *client) override {
delete static_cast<alpha::Client *>(client);
}
namespace tl = thallium;

std::string getClientConfig(void* c) override {
auto client = static_cast<alpha::Client*>(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<alpha::Client *>(c);
auto ph = new alpha::ProviderHandle(
client->engine(),
address,
provider_id,
false);
return static_cast<void *>(ph);
}
std::unique_ptr<alpha::Provider> m_provider;

void destroyProviderHandle(void *providerHandle) override {
auto ph = static_cast<alpha::ProviderHandle *>(providerHandle);
delete ph;
}

const std::vector<bedrock::Dependency> &getProviderDependencies() override {
static const std::vector<bedrock::Dependency> no_dependency;
return no_dependency;
}
public:

const std::vector<bedrock::Dependency> &getClientDependencies() override {
static const std::vector<bedrock::Dependency> 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<alpha::Provider>(engine, provider_id, config, pool)}
{}

void* getHandle() override {
return static_cast<void*>(m_provider.get());
}

std::string getConfig() override {
return m_provider->getConfig();
}

static std::shared_ptr<bedrock::AbstractComponent>
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<tl::pool>();
}
return std::make_shared<AlphaComponent>(
args.engine, args.provider_id, args.config, pool);
}

static std::vector<bedrock::Dependency>
GetDependencies(const bedrock::ComponentArgs& args) {
(void)args;
std::vector<bedrock::Dependency> 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)
3 changes: 3 additions & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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
Expand All @@ -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 $<INSTALL_INTERFACE:include>)
target_include_directories (alpha-bedrock-module BEFORE PUBLIC
Expand Down

0 comments on commit e00c867

Please sign in to comment.