Skip to content

Commit

Permalink
updated bedrock module to latest API (remains to be tested)
Browse files Browse the repository at this point in the history
  • Loading branch information
mdorier committed Sep 19, 2024
1 parent 684db8d commit fcecde6
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 59 deletions.
2 changes: 2 additions & 0 deletions spack.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ spack:
packages:
mochi-thallium:
require: "@0.14.0:"
mochi-bedrock-module-api:
require: "@0.2.0:"
mruby:
require:
- cflags=-fPIC
Expand Down
105 changes: 46 additions & 59 deletions src/BedrockModule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,70 +6,57 @@
#include "poesie/Client.hpp"
#include "poesie/Provider.hpp"
#include "poesie/ProviderHandle.hpp"
#include <bedrock/AbstractServiceFactory.hpp>

namespace tl = thallium;

class PoesieFactory : public bedrock::AbstractServiceFactory {

public:

PoesieFactory() {}

void *registerProvider(const bedrock::FactoryArgs &args) override {
auto provider = new poesie::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<poesie::Provider *>(p);
delete provider;
}

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

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

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

std::string getClientConfig(void* c) override {
auto client = static_cast<poesie::Client*>(c);
return client->getConfig();
}
class PoesieComponent : public bedrock::AbstractComponent {

void *createProviderHandle(void *c, hg_addr_t address,
uint16_t provider_id) override {
auto client = static_cast<poesie::Client *>(c);
auto ph = new poesie::ProviderHandle(
client->engine(),
address,
provider_id,
false);
return static_cast<void *>(ph);
}
std::unique_ptr<poesie::Provider> m_provider;

void destroyProviderHandle(void *providerHandle) override {
auto ph = static_cast<poesie::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;
}
PoesieComponent(const tl::engine& engine,
uint16_t provider_id,
const std::string& config,
const tl::pool& pool)
: m_provider{std::make_unique<poesie::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<PoesieComponent>(
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(poesie, PoesieFactory)
BEDROCK_REGISTER_COMPONENT_TYPE(poesie, PoesieComponent)

0 comments on commit fcecde6

Please sign in to comment.