Implement basic node.js binding (not published on npm yet)
This commit is contained in:
+3
-3
@@ -25,7 +25,7 @@ public:
|
||||
std::map<std::string, std::string> cfg;
|
||||
std::vector<std::string> cli_cmd;
|
||||
|
||||
kv_dbw_t *db = NULL;
|
||||
vitastorkv_dbw_t *db = NULL;
|
||||
ring_loop_t *ringloop = NULL;
|
||||
epoll_manager_t *epmgr = NULL;
|
||||
cluster_client_t *cli = NULL;
|
||||
@@ -144,7 +144,7 @@ void kv_cli_t::run()
|
||||
ringloop = new ring_loop_t(512);
|
||||
epmgr = new epoll_manager_t(ringloop);
|
||||
cli = new cluster_client_t(ringloop, epmgr->tfd, cfg);
|
||||
db = new kv_dbw_t(cli);
|
||||
db = new vitastorkv_dbw_t(cli);
|
||||
// Load image metadata
|
||||
while (!cli->is_ready())
|
||||
{
|
||||
@@ -289,7 +289,7 @@ void kv_cli_t::next_cmd()
|
||||
|
||||
struct kv_cli_list_t
|
||||
{
|
||||
kv_dbw_t *db = NULL;
|
||||
vitastorkv_dbw_t *db = NULL;
|
||||
void *handle = NULL;
|
||||
int format = 0;
|
||||
int n = 0;
|
||||
|
||||
+13
-13
@@ -501,7 +501,7 @@ void kv_block_t::dump(int base_level)
|
||||
|
||||
void kv_db_t::open(inode_t inode_id, json11::Json cfg, std::function<void(int)> cb)
|
||||
{
|
||||
if (block_cache.size() > 0)
|
||||
if (block_cache.size() > 0 || inode_id)
|
||||
{
|
||||
cb(-EINVAL);
|
||||
return;
|
||||
@@ -1958,38 +1958,38 @@ void kv_op_t::next_go_up()
|
||||
}
|
||||
}
|
||||
|
||||
kv_dbw_t::kv_dbw_t(cluster_client_t *cli)
|
||||
vitastorkv_dbw_t::vitastorkv_dbw_t(cluster_client_t *cli)
|
||||
{
|
||||
db = new kv_db_t();
|
||||
db->cli = cli;
|
||||
}
|
||||
|
||||
kv_dbw_t::~kv_dbw_t()
|
||||
vitastorkv_dbw_t::~vitastorkv_dbw_t()
|
||||
{
|
||||
delete db;
|
||||
}
|
||||
|
||||
void kv_dbw_t::open(uint64_t inode_id, std::map<std::string, std::string> cfg, std::function<void(int)> cb)
|
||||
void vitastorkv_dbw_t::open(uint64_t inode_id, std::map<std::string, std::string> cfg, std::function<void(int)> cb)
|
||||
{
|
||||
db->open(inode_id, cfg, cb);
|
||||
}
|
||||
|
||||
void kv_dbw_t::set_config(std::map<std::string, std::string> cfg)
|
||||
void vitastorkv_dbw_t::set_config(std::map<std::string, std::string> cfg)
|
||||
{
|
||||
db->set_config(cfg);
|
||||
}
|
||||
|
||||
uint64_t kv_dbw_t::get_size()
|
||||
uint64_t vitastorkv_dbw_t::get_size()
|
||||
{
|
||||
return db->next_free;
|
||||
}
|
||||
|
||||
void kv_dbw_t::close(std::function<void()> cb)
|
||||
void vitastorkv_dbw_t::close(std::function<void()> cb)
|
||||
{
|
||||
db->close(cb);
|
||||
}
|
||||
|
||||
void kv_dbw_t::get(const std::string & key, std::function<void(int res, const std::string & value)> cb, bool cached)
|
||||
void vitastorkv_dbw_t::get(const std::string & key, std::function<void(int res, const std::string & value)> cb, bool cached)
|
||||
{
|
||||
auto *op = new kv_op_t;
|
||||
op->db = db;
|
||||
@@ -2003,7 +2003,7 @@ void kv_dbw_t::get(const std::string & key, std::function<void(int res, const st
|
||||
op->exec();
|
||||
}
|
||||
|
||||
void kv_dbw_t::set(const std::string & key, const std::string & value, std::function<void(int res)> cb,
|
||||
void vitastorkv_dbw_t::set(const std::string & key, const std::string & value, std::function<void(int res)> cb,
|
||||
std::function<bool(int res, const std::string & value)> cas_compare)
|
||||
{
|
||||
auto *op = new kv_op_t;
|
||||
@@ -2023,7 +2023,7 @@ void kv_dbw_t::set(const std::string & key, const std::string & value, std::func
|
||||
op->exec();
|
||||
}
|
||||
|
||||
void kv_dbw_t::del(const std::string & key, std::function<void(int res)> cb,
|
||||
void vitastorkv_dbw_t::del(const std::string & key, std::function<void(int res)> cb,
|
||||
std::function<bool(int res, const std::string & value)> cas_compare)
|
||||
{
|
||||
auto *op = new kv_op_t;
|
||||
@@ -2042,7 +2042,7 @@ void kv_dbw_t::del(const std::string & key, std::function<void(int res)> cb,
|
||||
op->exec();
|
||||
}
|
||||
|
||||
void* kv_dbw_t::list_start(const std::string & start)
|
||||
void* vitastorkv_dbw_t::list_start(const std::string & start)
|
||||
{
|
||||
if (!db->inode_id || db->closing)
|
||||
return NULL;
|
||||
@@ -2055,7 +2055,7 @@ void* kv_dbw_t::list_start(const std::string & start)
|
||||
return op;
|
||||
}
|
||||
|
||||
void kv_dbw_t::list_next(void *handle, std::function<void(int res, const std::string & key, const std::string & value)> cb)
|
||||
void vitastorkv_dbw_t::list_next(void *handle, std::function<void(int res, const std::string & key, const std::string & value)> cb)
|
||||
{
|
||||
kv_op_t *op = (kv_op_t*)handle;
|
||||
if (cb)
|
||||
@@ -2068,7 +2068,7 @@ void kv_dbw_t::list_next(void *handle, std::function<void(int res, const std::st
|
||||
op->next();
|
||||
}
|
||||
|
||||
void kv_dbw_t::list_close(void *handle)
|
||||
void vitastorkv_dbw_t::list_close(void *handle)
|
||||
{
|
||||
kv_op_t *op = (kv_op_t*)handle;
|
||||
delete op;
|
||||
|
||||
@@ -73,7 +73,7 @@ public:
|
||||
timespec prev_stat_time, start_stat_time;
|
||||
|
||||
// State
|
||||
kv_dbw_t *db = NULL;
|
||||
vitastorkv_dbw_t *db = NULL;
|
||||
ring_loop_t *ringloop = NULL;
|
||||
epoll_manager_t *epmgr = NULL;
|
||||
cluster_client_t *cli = NULL;
|
||||
@@ -272,7 +272,7 @@ void kv_test_t::run(json11::Json cfg)
|
||||
ringloop = new ring_loop_t(512);
|
||||
epmgr = new epoll_manager_t(ringloop);
|
||||
cli = new cluster_client_t(ringloop, epmgr->tfd, cfg);
|
||||
db = new kv_dbw_t(cli);
|
||||
db = new vitastorkv_dbw_t(cli);
|
||||
// Load image metadata
|
||||
while (!cli->is_ready())
|
||||
{
|
||||
|
||||
@@ -19,11 +19,11 @@ class cluster_client_t;
|
||||
|
||||
struct kv_db_t;
|
||||
|
||||
struct kv_dbw_t
|
||||
struct vitastorkv_dbw_t
|
||||
{
|
||||
// cli = vitastor_c_get_internal_client(client)
|
||||
kv_dbw_t(cluster_client_t *cli);
|
||||
~kv_dbw_t();
|
||||
vitastorkv_dbw_t(cluster_client_t *cli);
|
||||
~vitastorkv_dbw_t();
|
||||
|
||||
void open(uint64_t inode_id, std::map<std::string, std::string> cfg, std::function<void(int)> cb);
|
||||
void set_config(std::map<std::string, std::string> cfg);
|
||||
|
||||
Reference in New Issue
Block a user