-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
54 additions
and
63 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,3 +20,5 @@ spack: | |
require: "@0.15.0:" | ||
mochi-thallium: | ||
require: "@0.12.0:" | ||
mochi-bedrock-module-api: | ||
require: "@0.2.0:" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters