Commit 478c6f24 authored by Matthieu Dorier's avatar Matthieu Dorier
Browse files

added REMI provider as argument to bake provider

parent 66ede0bb
......@@ -27,11 +27,17 @@ typedef struct bake_provider* bake_provider_t;
* can be memset to zero to use default values.
*/
struct bake_provider_init_info {
const char* json_config; /* JSON-formatted string */
ABT_pool rpc_pool; /* pool on which to run RPC handlers */
const char* json_config; /* optional JSON-formatted string */
ABT_pool rpc_pool; /* optional pool on which to run RPC handlers */
abt_io_instance_id aid; /* optional abt-io instance, used by file backend */
void* remi_provider; /* optional REMI provider */
};
#define BAKE_PROVIDER_INIT_INFO_INITIALIZER \
{ \
NULL, ABT_POOL_NULL, ABT_IO_INSTANCE_NULL, NULL \
}
/**
* Initializes a BAKE provider.
*
......
......@@ -12,7 +12,7 @@
#include <bake-server.h>
#define _CHECK_RET(__ret) \
if(__ret != BAKE_SUCCESS) throw exception(__ret)
if (__ret != BAKE_SUCCESS) throw exception(__ret)
namespace bake {
......@@ -23,7 +23,8 @@ namespace bake {
* @param pool_size Pool size.
* @param pool_mode Mode.
*/
inline void create_raw_target(const std::string& path, size_t size) {
inline void create_raw_target(const std::string& path, size_t size)
{
int ret = bake_create_raw_target(path.c_str(), size);
_CHECK_RET(ret);
}
......@@ -33,24 +34,25 @@ inline void create_raw_target(const std::string& path, size_t size) {
*/
class provider {
margo_instance_id m_mid = MARGO_INSTANCE_NULL;
bake_provider_t m_provider = NULL;
margo_instance_id m_mid = MARGO_INSTANCE_NULL;
bake_provider_t m_provider = NULL;
provider(margo_instance_id mid,
uint16_t provider_id,
provider(margo_instance_id mid,
uint16_t provider_id,
const bake_provider_init_info* args)
: m_mid(mid) {
: m_mid(mid)
{
int ret = bake_provider_register(mid, provider_id, args, &m_provider);
_CHECK_RET(ret);
}
static void finalize_callback(void* args) {
static void finalize_callback(void* args)
{
auto* p = static_cast<provider*>(args);
delete p;
}
public:
public:
/**
* @brief Factory method to create an instance of provider.
*
......@@ -59,18 +61,22 @@ class provider {
* @param pool Argobots pool.
* @param config JSON config.
* @param abtid ABT-IO instance.
* @param remi REMI provider.
*
* @return Pointer to newly created provider.
*/
static provider* create(margo_instance_id mid,
uint16_t provider_id = 0,
ABT_pool pool = ABT_POOL_NULL,
const std::string& config = "",
abt_io_instance_id abtio = ABT_IO_INSTANCE_NULL) {
bake_provider_init_info args;
args.json_config = config.c_str();
args.rpc_pool = pool;
args.aid = abtio;
static provider* create(margo_instance_id mid,
uint16_t provider_id = 0,
ABT_pool pool = ABT_POOL_NULL,
const std::string& config = "",
abt_io_instance_id abtio = ABT_IO_INSTANCE_NULL,
void* remi = NULL)
{
bake_provider_init_info args = BAKE_PROVIDER_INIT_INFO_INITIALIZER;
args.json_config = config.c_str();
args.rpc_pool = pool;
args.aid = abtio;
args.remi_provider = remi;
return create(mid, provider_id, &args);
}
......@@ -83,9 +89,10 @@ class provider {
*
* @return Pointer to newly created provider.
*/
static provider* create(margo_instance_id mid,
uint16_t provider_id,
const bake_provider_init_info* args = nullptr) {
static provider* create(margo_instance_id mid,
uint16_t provider_id,
const bake_provider_init_info* args = nullptr)
{
auto p = new provider(mid, provider_id, args);
margo_provider_push_finalize_callback(mid, p, &finalize_callback, p);
return p;
......@@ -114,7 +121,8 @@ class provider {
/**
* @brief Destructor.
*/
~provider() {
~provider()
{
margo_provider_pop_finalize_callback(m_mid, this);
bake_provider_deregister(m_provider);
}
......@@ -127,12 +135,11 @@ class provider {
*
* @return a target object.
*/
target attach_target(const std::string& target_name) {
target attach_target(const std::string& target_name)
{
target t;
int ret = bake_provider_attach_target(
m_provider,
target_name.c_str(),
&(t.m_tid));
int ret = bake_provider_attach_target(m_provider, target_name.c_str(),
&(t.m_tid));
_CHECK_RET(ret);
return t;
}
......@@ -145,18 +152,15 @@ class provider {
*
* @return a target object.
*/
target create_target(const std::string& target_name, size_t size) {
target create_target(const std::string& target_name, size_t size)
{
target t;
int ret = bake_provider_create_target(
m_provider,
target_name.c_str(),
size,
&(t.m_tid));
int ret = bake_provider_create_target(m_provider, target_name.c_str(),
size, &(t.m_tid));
_CHECK_RET(ret);
return t;
}
/**
* @brief Removes the storage target from the provider.
* This does not removes the storage target from the device, it
......@@ -164,7 +168,8 @@ class provider {
*
* @param t target to remove.
*/
void detach_target(const target& t) {
void detach_target(const target& t)
{
int ret = bake_provider_detach_target(m_provider, t.m_tid);
_CHECK_RET(ret);
}
......@@ -172,7 +177,8 @@ class provider {
/**
* @brief Removes all the storage targets managed by the provider.
*/
void detach_all_targets() {
void detach_all_targets()
{
int ret = bake_provider_detach_all_targets(m_provider);
_CHECK_RET(ret);
}
......@@ -182,9 +188,10 @@ class provider {
*
* @return number of storage targets.
*/
uint64_t count_targets() const {
uint64_t count_targets() const
{
uint64_t count;
int ret = bake_provider_count_targets(m_provider, &count);
int ret = bake_provider_count_targets(m_provider, &count);
_CHECK_RET(ret);
return count;
}
......@@ -194,28 +201,28 @@ class provider {
*
* @return Vector of targets.
*/
std::vector<target> list_targets() const {
uint64_t count = count_targets();
std::vector<target> result(count);
std::vector<target> list_targets() const
{
uint64_t count = count_targets();
std::vector<target> result(count);
std::vector<bake_target_id_t> tgts(count);
int ret = bake_provider_list_targets(m_provider, tgts.data());
_CHECK_RET(ret);
for(unsigned i=0; i < count; i++) {
result[i].m_tid = tgts[i];
}
for (unsigned i = 0; i < count; i++) { result[i].m_tid = tgts[i]; }
return result;
}
std::string get_config() const {
std::string get_config() const
{
char* cfg = bake_provider_get_config(m_provider);
if(!cfg) return std::string();
if (!cfg) return std::string();
auto str_cfg = std::string(cfg);
free(cfg);
return str_cfg;
}
};
}
} // namespace bake
#undef _CHECK_RET
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment