write-actions.h 2.55 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102
/*
 * (C) 2017 The University of Chicago
 * 
 * See COPYRIGHT in top-level directory.
 */
#ifndef __MOBJECT_WRITE_OPCODES_H
#define __MOBJECT_WRITE_OPCODES_H

#include "mobject-store-config.h"

typedef enum {
	WRITE_OPCODE_BASE = 0,
	WRITE_OPCODE_CREATE,
	WRITE_OPCODE_WRITE,
	WRITE_OPCODE_WRITE_FULL,
	WRITE_OPCODE_WRITE_SAME,
	WRITE_OPCODE_APPEND,
	WRITE_OPCODE_REMOVE,
	WRITE_OPCODE_TRUNCATE,
	WRITE_OPCODE_ZERO,
	WRITE_OPCODE_OMAP_SET,
	WRITE_OPCODE_RM_KEYS
} write_op_code_t;

#define WRITE_ACTION_DOWNCAST(child_obj, base_obj, child_category) \
	if(WRITE_OPCODE_ ## child_category != base_obj->type) {\
		MOBJECT_LOG("Downcast error: " #base_obj " is not of type WRITE_ACTION_" #child_category);\
	}\
	struct wr_action_ ## child_category * child_obj = (struct wr_action_ ## child_category *) base_obj;

#define WRITE_ACTION_UPCAST(base_obj, child_obj) \
	struct wr_action_BASE* base_obj = (struct wr_action_BASE*) child_obj;

typedef struct wr_action_BASE {
	write_op_code_t        type;
	struct wr_action_base* prev;
	struct wr_action_base* next;
}* wr_action_base_t;

typedef struct wr_action_CREATE {
	struct wr_action_BASE base;
	int                   exclusive;
}* wr_action_create_t;

typedef struct wr_action_WRITE {
	struct wr_action_BASE base;
	const char*           buffer;
	size_t                len;
	uint64_t              offset;
}* wr_action_write_t;

typedef struct wr_action_WRITE_FULL {
	struct wr_action_BASE base;
	const char*           buffer;
	size_t                len;
}* wr_action_write_full_t;

typedef struct wr_action_WRITE_SAME {
	struct wr_action_BASE base;
	const char*           buffer;
	size_t                data_len;
	size_t                write_len;
	uint64_t              offset;
}* wr_action_write_same_t;

typedef struct wr_action_APPEND {
	struct wr_action_BASE base;
	const char*           buffer;
	size_t                len;
}* wr_action_append_t;

typedef struct wr_action_REMOVE {
	struct wr_action_BASE base;
}* wr_action_remove_t;

typedef struct wr_action_TRUNCATE {
	struct wr_action_BASE base;
	uint64_t              offset;
}* wr_action_truncate_t;

typedef struct wr_action_ZERO {
	struct wr_action_BASE base;
	uint64_t              offset;
	uint64_t              len;
}* wr_action_zero_t;

typedef struct wr_action_OMAP_SET {
	struct wr_action_BASE base;
	char const* const*    keys;
	char const* const*    vals;
	const size_t*         lens;
	size_t                num;
}* wr_action_omap_set_t;

typedef struct wr_action_RM_KEYS {
	struct wr_action_BASE base;
	char const* const*    keys;
	size_t                keys_len;
}* wr_action_rm_keys_t;

#endif