Commit 3f6144ce authored by Matthieu Dorier's avatar Matthieu Dorier

added read_op visitor

parent 057664bc
......@@ -7,7 +7,8 @@ src_libmobject_store_la_SOURCES = \
src/proc-read-actions.c \
src/prepare-write-op.c \
src/prepare-read-op.c \
src/write-op-visitor.c
src/write-op-visitor.c \
src/read-op-visitor.c
noinst_HEADERS += \
src/log.h \
......@@ -22,4 +23,5 @@ noinst_HEADERS += \
src/prepare-write-op.h \
src/prepare-read-op.h \
src/write-op-visitor.h \
src/buffer-union.h
src/read-op-visitor.h \
src/buffer-union.h
......@@ -7,6 +7,7 @@
#define __MOBJECT_READ_OPCODES_H
#include "mobject-store-config.h"
#include "buffer-union.h"
typedef enum {
READ_OPCODE_BASE = 0,
......@@ -44,10 +45,7 @@ typedef struct rd_action_READ {
struct rd_action_BASE base;
uint64_t offset;
size_t len;
union {
char* as_pointer;
uint64_t as_offset;
} buffer;
buffer_u buffer;
size_t* bytes_read;
int* prval;
}* rd_action_read_t;
......
/*
* (C) 2017 The University of Chicago
*
* See COPYRIGHT in top-level directory.
*/
#include "libmobject-store.h"
#include "read-op-visitor.h"
#include "read-op-impl.h"
#include "utlist.h"
static void execute_read_op_visitor_on_stat(read_op_visitor_t visitor, rd_action_stat_t a);
static void execute_read_op_visitor_on_read(read_op_visitor_t visitor, rd_action_read_t a);
static void execute_read_op_visitor_on_omap_get_keys(read_op_visitor_t visitor, rd_action_omap_get_keys_t a);
static void execute_read_op_visitor_on_omap_get_vals(read_op_visitor_t visitor, rd_action_omap_get_vals_t a);
static void execute_read_op_visitor_on_omap_get_vals_by_keys(read_op_visitor_t visitor, rd_action_omap_get_vals_by_keys_t a);
typedef void (*dispatch_fn)(read_op_visitor_t, rd_action_base_t);
static dispatch_fn visitor_dispatch[_READ_OPCODE_END_ENUM_] = {
NULL,
(dispatch_fn)execute_read_op_visitor_on_stat,
(dispatch_fn)execute_read_op_visitor_on_read,
(dispatch_fn)execute_read_op_visitor_on_omap_get_keys,
(dispatch_fn)execute_read_op_visitor_on_omap_get_vals,
(dispatch_fn)execute_read_op_visitor_on_omap_get_vals_by_keys,
};
void execute_read_op_visitor(read_op_visitor_t visitor, mobject_store_read_op_t read_op)
{
void* uargs = visitor->uargs;
rd_action_base_t a;
visitor->visit_begin(uargs);
DL_FOREACH((read_op->actions), a) {
visitor_dispatch[a->type](visitor, a);
}
visitor->visit_end(uargs);
}
////////////////////////////////////////////////////////////////////////////////
// STATIC FUNCTIONS BELOW //
////////////////////////////////////////////////////////////////////////////////
static void execute_read_op_visitor_on_stat(read_op_visitor_t visitor, rd_action_stat_t a)
{
visitor->visit_stat(visitor->uargs, a->psize, a->pmtime, a->prval);
}
static void execute_read_op_visitor_on_read(read_op_visitor_t visitor, rd_action_read_t a)
{
visitor->visit_read(visitor->uargs, a->offset, a->len, a->buffer, a->bytes_read, a->prval);
}
static void execute_read_op_visitor_on_omap_get_keys(read_op_visitor_t visitor, rd_action_omap_get_keys_t a)
{
visitor->visit_omap_get_keys(visitor->uargs, a->start_after, a->max_return, a->iter, a->prval);
}
static void execute_read_op_visitor_on_omap_get_vals(read_op_visitor_t visitor, rd_action_omap_get_vals_t a)
{
visitor->visit_omap_get_vals(visitor->uargs, a->start_after, a->filter_prefix, a->max_return, a->iter, a->prval);
}
static void execute_read_op_visitor_on_omap_get_vals_by_keys(read_op_visitor_t visitor, rd_action_omap_get_vals_by_keys_t a)
{
const char* keys[a->num_keys];
unsigned i;
const char* ptr = a->data;
for(i = 0; i < a->num_keys; i++) {
keys[i] = ptr;
ptr += strlen(keys[i])+1;
}
visitor->visit_omap_get_vals_by_keys(visitor->uargs, keys, a->num_keys, a->iter, a->prval);
}
/*
* (C) 2017 The University of Chicago
*
* See COPYRIGHT in top-level directory.
*/
#ifndef __MOBJECT_READ_OP_VISITOR_H
#define __MOBJECT_READ_OP_VISITOR_H
#include "libmobject-store.h"
#include "buffer-union.h"
typedef struct read_op_visitor {
void* uargs;
void (*visit_begin)(void*);
void (*visit_stat)(void*, uint64_t*, time_t*, int*);
void (*visit_read)(void*, uint64_t, size_t, buffer_u, size_t*, int*);
void (*visit_omap_get_keys)(void*, const char*, uint64_t, mobject_store_omap_iter_t*, int*);
void (*visit_omap_get_vals)(void*, const char*, const char*, uint64_t, mobject_store_omap_iter_t*, int*);
void (*visit_omap_get_vals_by_keys)(void*, char const* const*, size_t, mobject_store_omap_iter_t*, int*);
void (*visit_end)(void*);
}* read_op_visitor_t;
void execute_read_op_visitor(read_op_visitor_t visitor, mobject_store_read_op_t read_op);
#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