sdskv-rpc-types.h 3.34 KB
Newer Older
Matthieu Dorier's avatar
Matthieu Dorier committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
#ifndef SDSKV_RPC_TYPE_H
#define SDSKV_RPC_TYPE_H

#include <stdint.h>
#include <assert.h>

#include <mercury.h>
#include <mercury_macros.h>
#include <mercury_proc_string.h>

#include <margo.h>

#include "sdskv-common.h"

// setup to support opaque type handling
16
typedef char* kv_ptr_t;
Matthieu Dorier's avatar
Matthieu Dorier committed
17
18

typedef struct {
19
20
21
    hg_size_t size;
    kv_ptr_t  data;
} kv_data_t;
Matthieu Dorier's avatar
Matthieu Dorier committed
22

23
static inline hg_return_t hg_proc_kv_data_t(hg_proc_t proc, void *arg)
Matthieu Dorier's avatar
Matthieu Dorier committed
24
25
{
  hg_return_t ret;
26
  kv_data_t *in = (kv_data_t*)arg;
Matthieu Dorier's avatar
Matthieu Dorier committed
27

28
  ret = hg_proc_hg_size_t(proc, &in->size);
Matthieu Dorier's avatar
Matthieu Dorier committed
29
  if(ret != HG_SUCCESS) return ret;
30
  if (in->size) {
Matthieu Dorier's avatar
Matthieu Dorier committed
31
32
    switch (hg_proc_get_op(proc)) {
    case HG_ENCODE:
33
      ret = hg_proc_raw(proc, in->data, in->size);
Matthieu Dorier's avatar
Matthieu Dorier committed
34
35
36
      if(ret != HG_SUCCESS) return ret;
      break;
    case HG_DECODE:
37
38
      in->data = (kv_ptr_t)malloc(in->size);
      ret = hg_proc_raw(proc, in->data, in->size);
Matthieu Dorier's avatar
Matthieu Dorier committed
39
40
41
      if(ret != HG_SUCCESS) return ret;
      break;
    case HG_FREE:
42
      free(in->data);
Matthieu Dorier's avatar
Matthieu Dorier committed
43
44
45
46
47
48
49
50
      break;
    default:
      break;
    }
  }
  return HG_SUCCESS;
}

51
52
53
54
// ------------- OPEN ------------- //
MERCURY_GEN_PROC(open_in_t, 
        ((hg_string_t)(name)))
MERCURY_GEN_PROC(open_out_t, ((uint64_t)(db_id)) ((int32_t)(ret)))
Matthieu Dorier's avatar
Matthieu Dorier committed
55

56
57
58
59
60
// ------------- PUT ------------- //
MERCURY_GEN_PROC(put_in_t, ((uint64_t)(db_id))\
        ((kv_data_t)(key))\
        ((kv_data_t)(value)))
MERCURY_GEN_PROC(put_out_t, ((int32_t)(ret)))
Matthieu Dorier's avatar
Matthieu Dorier committed
61

62
63
64
65
// ------------- GET ------------- //
MERCURY_GEN_PROC(get_in_t, ((uint64_t)(db_id))\
        ((kv_data_t)(key))\
        ((hg_size_t)(vsize)))
Matthieu Dorier's avatar
Matthieu Dorier committed
66

67
68
MERCURY_GEN_PROC(get_out_t, ((int32_t)(ret))\
        ((kv_data_t)(value)))
Matthieu Dorier's avatar
Matthieu Dorier committed
69

Matthieu Dorier's avatar
Matthieu Dorier committed
70
// ------------- LENGTH ------------- //
71
MERCURY_GEN_PROC(length_in_t, ((uint64_t)(db_id))((kv_data_t)(key)))
Matthieu Dorier's avatar
Matthieu Dorier committed
72
73
MERCURY_GEN_PROC(length_out_t, ((hg_size_t)(size)) ((int32_t)(ret)))

74
75
76
77
// ------------- EXISTS ------------- //
MERCURY_GEN_PROC(exists_in_t, ((uint64_t)(db_id))((kv_data_t)(key)))
MERCURY_GEN_PROC(exists_out_t, ((int32_t)(flag)) ((int32_t)(ret)))

Matthieu Dorier's avatar
Matthieu Dorier committed
78
// ------------- ERASE ------------- //
Matthieu Dorier's avatar
Matthieu Dorier committed
79
MERCURY_GEN_PROC(erase_out_t, ((int32_t)(ret)))
80
MERCURY_GEN_PROC(erase_in_t, ((uint64_t)(db_id))((kv_data_t)(key)))
Matthieu Dorier's avatar
Matthieu Dorier committed
81

Matthieu Dorier's avatar
Matthieu Dorier committed
82
// ------------- LIST KEYS ------------- //
83
84
MERCURY_GEN_PROC(list_keys_in_t, ((uint64_t)(db_id))\
        ((kv_data_t)(start_key))\
85
        ((kv_data_t)(prefix))\
86
87
88
        ((hg_size_t)(max_keys))\
        ((hg_bulk_t)(ksizes_bulk_handle))\
        ((hg_bulk_t)(keys_bulk_handle)))
Matthieu Dorier's avatar
Matthieu Dorier committed
89
MERCURY_GEN_PROC(list_keys_out_t, ((hg_size_t)(nkeys)) ((int32_t)(ret)))
90

91
// ------------- LIST KEYVALS ------------- //
92
93
MERCURY_GEN_PROC(list_keyvals_in_t, ((uint64_t)(db_id))\
        ((kv_data_t)(start_key))\
94
        ((kv_data_t)(prefix))\
95
96
97
98
99
        ((hg_size_t)(max_keys))\
        ((hg_bulk_t)(ksizes_bulk_handle))\
        ((hg_bulk_t)(keys_bulk_handle))\
        ((hg_bulk_t)(vsizes_bulk_handle))\
        ((hg_bulk_t)(vals_bulk_handle)))
100
101
MERCURY_GEN_PROC(list_keyvals_out_t, ((hg_size_t)(nkeys)) ((int32_t)(ret)))

Matthieu Dorier's avatar
Matthieu Dorier committed
102
// ------------- BULK PUT ------------- //
103
104
105
106
MERCURY_GEN_PROC(bulk_put_in_t, ((uint64_t)(db_id))\
        ((kv_data_t)(key))\
        ((hg_size_t)(vsize))\
        ((hg_bulk_t)(handle)))
Matthieu Dorier's avatar
Matthieu Dorier committed
107
108
MERCURY_GEN_PROC(bulk_put_out_t, ((int32_t)(ret)))

Matthieu Dorier's avatar
Matthieu Dorier committed
109
// ------------- BULK GET ------------- //
110
111
112
113
MERCURY_GEN_PROC(bulk_get_in_t, ((uint64_t)(db_id))\
        ((kv_data_t)(key))\
        ((hg_size_t)(vsize))\
        ((hg_bulk_t)(handle)))
Matthieu Dorier's avatar
Matthieu Dorier committed
114
115
116
MERCURY_GEN_PROC(bulk_get_out_t, ((hg_size_t)(size)) ((int32_t)(ret)))

#endif