Commit cd5b6ba0 authored by Matthieu Dorier's avatar Matthieu Dorier
Browse files

implemented fileset

parent 54733c46
...@@ -30,6 +30,11 @@ int remi_provider_handle_release(remi_provider_handle_t handle); ...@@ -30,6 +30,11 @@ int remi_provider_handle_release(remi_provider_handle_t handle);
int remi_shutdown_service(remi_client_t client, hg_addr_t addr); int remi_shutdown_service(remi_client_t client, hg_addr_t addr);
int remi_fileset_migrate(
remi_provider_handle_t handle,
remi_fileset_t fileset,
int flag);
#if defined(__cplusplus) #if defined(__cplusplus)
} }
#endif #endif
......
...@@ -15,17 +15,19 @@ extern "C" { ...@@ -15,17 +15,19 @@ extern "C" {
#define REMI_ERR_INVALID_ARG -2 /* An argument is invalid */ #define REMI_ERR_INVALID_ARG -2 /* An argument is invalid */
#define REMI_ERR_MERCURY -3 /* An error happened calling a Mercury function */ #define REMI_ERR_MERCURY -3 /* An error happened calling a Mercury function */
#define REMI_ERR_UNKNOWN_CLASS -4 /* Database refered to by id is not known to provider */ #define REMI_ERR_UNKNOWN_CLASS -4 /* Database refered to by id is not known to provider */
#define REMI_ERR_UNKNOWN_PR -5 /* Mplex id could not be matched with a provider */ #define REMI_ERR_UNKNOWN_FILE -5 /* File not found in fileset or in file system */
#define REMI_ERR_SIZE -6 /* Client did not allocate enough for the requested data */ #define REMI_ERR_UNKNOWN_PR -6 /* Provider id could not be matched with a provider */
#define REMI_ERR_MIGRATION -7 /* Error during data migration */ #define REMI_ERR_UNKNOWN_META -7 /* Unknown metadata entry */
#define REMI_ERR_SIZE -8 /* Client did not allocate enough for the requested data */
#define REMI_ERR_MIGRATION -9 /* Error during data migration */
typedef struct remi_fileset* remi_fileset_t; typedef struct remi_fileset* remi_fileset_t;
#define REMI_FILESET_NULL ((remi_fileset_t)0) #define REMI_FILESET_NULL ((remi_fileset_t)0)
typedef void (*remi_fileset_callback_t)(remi_fileset_t, const char*, void*); typedef void (*remi_fileset_callback_t)(const char*, void*);
#define REMI_FILESET_CALLBACK_NULL ((remi_fileset_callback_t)0) #define REMI_FILESET_CALLBACK_NULL ((remi_fileset_callback_t)0)
typedef void (*remi_metadata_callback_t)(remi_fileset_t, const char*, const char*, void*); typedef void (*remi_metadata_callback_t)(const char*, const char*, void*);
#define REMI_METADATA_CALLBACK_NULL ((remi_metadata_callback_t)0) #define REMI_METADATA_CALLBACK_NULL ((remi_metadata_callback_t)0)
int remi_fileset_create( int remi_fileset_create(
...@@ -65,8 +67,7 @@ int remi_fileset_register_metadata( ...@@ -65,8 +67,7 @@ int remi_fileset_register_metadata(
int remi_fileset_deregister_metadata( int remi_fileset_deregister_metadata(
remi_fileset_t fileset, remi_fileset_t fileset,
const char* key, const char* key);
const char* value);
int remi_fileset_foreach_metadata( int remi_fileset_foreach_metadata(
remi_fileset_t fileset, remi_fileset_t fileset,
......
#include "remi/remi-client.h" #include "remi/remi-client.h"
#include "remi-fileset.hpp"
#if 0
typedef struct remi_client* remi_client_t;
#define REMI_CLIENT_NULL ((remi_client_t)0)
typedef struct remi_provider_handle* remi_provider_handle_t;
#define REMI_PROVIDER_HANDLE_NULL ((remi_provider_handle_t)0)
#endif
extern "C" int remi_client_init(margo_instance_id mid, remi_client_t* client) extern "C" int remi_client_init(margo_instance_id mid, remi_client_t* client)
{ {
...@@ -41,3 +34,11 @@ extern "C" int remi_shutdown_service(remi_client_t client, hg_addr_t addr) ...@@ -41,3 +34,11 @@ extern "C" int remi_shutdown_service(remi_client_t client, hg_addr_t addr)
{ {
} }
extern "C" int remi_fileset_migrate(
remi_provider_handle_t handle,
remi_fileset_t fileset,
int flag)
{
}
#include <cstring>
#include "remi/remi-common.h" #include "remi/remi-common.h"
#include "remi-fileset.hpp"
#if 0
typedef struct remi_fileset* remi_fileset_t;
#define REMI_FILESET_NULL ((remi_fileset_t)0)
typedef void (*remi_fileset_callback_t)(remi_fileset_t, const char*, void*);
#define REMI_FILESET_CALLBACK_NULL ((remi_fileset_callback_t)0)
typedef void (*remi_metadata_callback_t)(remi_fileset_t, const char*, const char*, void*);
#define REMI_METADATA_CALLBACK_NULL ((remi_metadata_callback_t)0)
#endif
extern "C" int remi_fileset_create( extern "C" int remi_fileset_create(
const char* fileset_class, const char* fileset_class,
const char* fileset_root, const char* fileset_root,
remi_fileset_t* fileset) remi_fileset_t* fileset)
{ {
if(fileset_class == NULL || fileset_root == NULL)
return REMI_ERR_INVALID_ARG;
if(fileset_root[0] != '/')
return REMI_ERR_INVALID_ARG;
auto fs = new remi_fileset;
fs->m_class = fileset_class;
fs->m_root = fileset_root;
if(fs->m_root[fs->m_root.size()-1] != '/') {
fs->m_root += "/";
}
*fileset = fs;
return REMI_SUCCESS;
} }
extern "C" int remi_fileset_free(remi_fileset_t fileset) extern "C" int remi_fileset_free(remi_fileset_t fileset)
{ {
if(fileset == REMI_FILESET_NULL)
return REMI_SUCCESS;
delete fileset;
return REMI_SUCCESS;
} }
extern "C" int remi_fileset_get_class( extern "C" int remi_fileset_get_class(
...@@ -30,7 +34,18 @@ extern "C" int remi_fileset_get_class( ...@@ -30,7 +34,18 @@ extern "C" int remi_fileset_get_class(
char* buf, char* buf,
size_t* size) size_t* size)
{ {
if(fileset == REMI_FILESET_NULL)
return REMI_ERR_INVALID_ARG;
if(buf == nullptr) {
*size = fileset->m_class.size()+1;
return REMI_SUCCESS;
} else if(*size < fileset->m_class.size()+1) {
return REMI_ERR_SIZE;
} else {
std::memcpy(buf, fileset->m_class.c_str(), fileset->m_class.size()+1);
*size = fileset->m_class.size()+1;
}
return REMI_SUCCESS;
} }
extern "C" int remi_fileset_get_root( extern "C" int remi_fileset_get_root(
...@@ -39,20 +54,46 @@ extern "C" int remi_fileset_get_root( ...@@ -39,20 +54,46 @@ extern "C" int remi_fileset_get_root(
size_t* size) size_t* size)
{ {
if(fileset == REMI_FILESET_NULL)
return REMI_ERR_INVALID_ARG;
if(buf == nullptr) {
*size = fileset->m_root.size()+1;
return REMI_SUCCESS;
} else if(*size < fileset->m_root.size()+1) {
return REMI_ERR_SIZE;
} else {
std::strcpy(buf, fileset->m_root.c_str());
*size = fileset->m_root.size()+1;
}
return REMI_SUCCESS;
} }
extern "C" int remi_fileset_register_file( extern "C" int remi_fileset_register_file(
remi_fileset_t fileset, remi_fileset_t fileset,
const char* filename) const char* filename)
{ {
if(fileset == REMI_FILESET_NULL || filename == NULL)
return REMI_ERR_INVALID_ARG;
unsigned i = 0;
while(filename[i] == '/') i += 1;
fileset->m_files.insert(filename+i);
return REMI_SUCCESS;
} }
extern "C" int remi_fileset_deregister_file( extern "C" int remi_fileset_deregister_file(
remi_fileset_t fileset, remi_fileset_t fileset,
const char* filename) const char* filename)
{ {
if(fileset == REMI_FILESET_NULL || filename == NULL)
return REMI_ERR_INVALID_ARG;
unsigned i = 0;
while(filename[i] == '/') i += 1;
auto it = fileset->m_files.find(filename+i);
if(it == fileset->m_files.end())
return REMI_ERR_UNKNOWN_FILE;
else
fileset->m_files.erase(filename+i);
return REMI_SUCCESS;
} }
extern "C" int remi_fileset_foreach_file( extern "C" int remi_fileset_foreach_file(
...@@ -60,7 +101,12 @@ extern "C" int remi_fileset_foreach_file( ...@@ -60,7 +101,12 @@ extern "C" int remi_fileset_foreach_file(
remi_fileset_callback_t callback, remi_fileset_callback_t callback,
void* uargs) void* uargs)
{ {
if(fileset == REMI_FILESET_NULL || callback == NULL)
return REMI_ERR_INVALID_ARG;
for(auto& filename : fileset->m_files) {
callback(filename.c_str(), uargs);
}
return REMI_SUCCESS;
} }
extern "C" int remi_fileset_register_metadata( extern "C" int remi_fileset_register_metadata(
...@@ -68,15 +114,23 @@ extern "C" int remi_fileset_register_metadata( ...@@ -68,15 +114,23 @@ extern "C" int remi_fileset_register_metadata(
const char* key, const char* key,
const char* value) const char* value)
{ {
if(fileset == REMI_FILESET_NULL || key == NULL)
return REMI_ERR_INVALID_ARG;
fileset->m_metadata[key] = value;
return REMI_SUCCESS;
} }
extern "C" int remi_fileset_deregister_metadata( extern "C" int remi_fileset_deregister_metadata(
remi_fileset_t fileset, remi_fileset_t fileset,
const char* key, const char* key)
const char* value)
{ {
if(fileset == REMI_FILESET_NULL || key == NULL)
return REMI_ERR_INVALID_ARG;
auto it = fileset->m_metadata.find(key);
if(it == fileset->m_metadata.end())
return REMI_ERR_UNKNOWN_META;
fileset->m_metadata.erase(it);
return REMI_SUCCESS;
} }
extern "C" int remi_fileset_foreach_metadata( extern "C" int remi_fileset_foreach_metadata(
...@@ -84,5 +138,10 @@ extern "C" int remi_fileset_foreach_metadata( ...@@ -84,5 +138,10 @@ extern "C" int remi_fileset_foreach_metadata(
remi_metadata_callback_t callback, remi_metadata_callback_t callback,
void* uargs) void* uargs)
{ {
if(fileset == REMI_FILESET_NULL || callback == NULL)
return REMI_ERR_INVALID_ARG;
for(auto& meta : fileset->m_metadata) {
callback(meta.first.c_str(), meta.second.c_str(), uargs);
}
return REMI_SUCCESS;
} }
#ifndef __REMI_FILESET_HPP
#define __REMI_FILESET_HPP
#include <string>
#include <map>
#include <set>
#include <thallium/serialization/stl/string.hpp>
#include <thallium/serialization/stl/set.hpp>
#include <thallium/serialization/stl/map.hpp>
struct remi_fileset {
std::string m_class;
std::string m_root;
std::map<std::string,std::string> m_metadata;
std::set<std::string> m_files;
template<typename A>
void serialize(A& ar) {
ar & m_class;
ar & m_root;
ar & m_metadata;
ar & m_files;
}
};
#endif
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