You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
libsxmp/include/ydaemon/dataobject.h

288 lines
7.3 KiB
C

/*
* Yet another daemon library especially designed to be used
* with libsxmp based daemons.
*
* (c) Alexander Vdolainen 2016 <avdolainen@zoho.com>
*
* libsxmp is free software: you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as published
* by the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* libsxmp is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.";
*
*/
#ifndef __DM_DATAOBJECT_H__
#define __DM_DATAOBJECT_H__
#include <stdint.h>
#include <stdlib.h>
#include <errno.h>
#include <sys/types.h>
#include <string.h>
#include <pthread.h>
#include <tdata/usrtc.h>
#include <tdata/list.h>
#define MAX_ITEM_NAME 32
#define MAX_ITEMS 255
typedef uint64_t oid_t;
enum {
U8 = 0,
S8,
U16,
S16,
U32,
S32,
U64,
S64,
CSTR,
TBLOB,
TACRT,
};
struct typelen {
uint8_t type;
uint64_t len;
};
typedef struct __access_rights_type {
uint32_t ouid;
uint32_t ogid;
uint8_t domainid;
uint8_t sal;
uint8_t amask;
uint8_t reserve;
}__attribute__((packed)) acc_right_t;
typedef struct __dataacc_pemctx_type {
acc_right_t *uobj;
uint32_t gids[16];
} dataacc_pemctx_t;
#ifdef DMUX_USE
static struct typelen tltable[] = {
{.type = U8, .len = 1},
{.type = S8, .len = 1},
{.type = U16, .len = 2},
{.type = S16, .len = 2},
{.type = U32, .len = 4},
{.type = S32, .len = 4},
{.type = U64, .len = 8},
{.type = S64, .len = 8},
{.type = CSTR, .len = 0},
{.type = TBLOB, .len = 0},
{.type = TACRT, .len = sizeof(acc_right_t) },
};
#endif
typedef struct __dataobject_item_type {
uint8_t id;
uint8_t type;
uint64_t len;
char name[MAX_ITEM_NAME];
list_node_t node;
}__attribute__ ((packed)) dataobject_item_t;
typedef struct __item_idx_type {
void *key;
dataobject_item_t *dtr;
usrtc_node_t node;
} item_idx_t;
typedef struct __dataobject_type {
char name[MAX_ITEMS];
list_head_t description; /* description of the data */
usrtc_t id_index;
usrtc_t name_index;
} dataobject_t;
/* API */
dataobject_t *dotr_create(const char *name);
int dotr_set_item(dataobject_t *dotr, uint8_t type, uint64_t len, const char *name);
uint8_t dotr_item_type(dataobject_t *obj, const char *name, uint64_t *len);
char *dotr_item_nameptr(dataobject_t *obj, const char *name);
int dotr_item_nameidx(dataobject_t *obj, const char *name);
void dotr_destroy(dataobject_t *dotr);
/* dataobject misc operations */
int dtocmp(const dataobject_t *src, const dataobject_t *dst);
size_t dtolen(const dataobject_t *src);
/*
* Filtering used for access to the data stream.
*/
typedef enum {
YDM_NO_FILTER = 0, /* no access right filter */
YDM_DOMAIN_FILTER, /* filter only by domain */
YDM_USERDAC_FILTER, /* filter by domain and user with DAC */
YDM_FULL_FILTER, /* all above filter plus additional filtering */
} ydm_access_filter_t;
typedef struct __sxmp_ch_entry_type {
char instance[32];
uint16_t chtid;
ydm_access_filter_t filter;
list_node_t node;
} sxmp_ch_entry_t;
struct __domx_dsbe_type;
/* some intermodular structures */
typedef struct __domx_type {
dataobject_t *dox;
char *name;
list_head_t sxmp_channels;
struct __domx_dsbe_type *be;
void *cache;
} domx_t;
/* initialization */
int domx_init(domx_t *dt, dataobject_t *dodesc);
int domx_set_be(domx_t *dt, void *be, const char *key);
int domx_set_cache(domx_t *dt, size_t size);
int domx_set_sxmpchannel(domx_t *dt, const char *instance, int typeid, int access);
/* data operations */
int domx_get(domx_t *dt, uint64_t oid, void **refdata);
int domx_set(domx_t *dt, uint64_t oid, const void *refdata);
int domx_remove(domx_t *dt, uint64_t oid);
int domx_creat(domx_t *dt, uint64_t *oid, const void *refdata);
/* cache ops for backends */
int domx_cache_invalidate(domx_t *dt, uint64_t oid);
int domx_cache_invalidate_list(domx_t *dt, list_head_t *oids);
int domx_cache_getdirtylist(domx_t *dt, uint16_t amount, list_head_t **list);
int domx_cache_freelist(domx_t *dt, list_head_t *list);
int domx_cache_freeitems(domx_t *dt, uint16_t amount);
/* data filters */
typedef enum {
YDEQUAL = 0,
YDNOTEQUAL,
YDGREATER,
YDLESS,
YDEQOGREATER,
YDEQOLESS,
YDINRANGE,
YDINLIST,
} filt_t;
typedef struct __yd_inlist_item_type {
union {
uint64_t val;
char *dta;
};
list_node_t node;
}__attribute__((packed)) yd_inlist_item_t;
typedef struct __yd_filter_item_type {
char *name; /* dataobject item name ptr */
filt_t ftype; /* filtering type */
union {
struct {
uint64_t vf; /* first value */
uint64_t vc; /* second value if applicable */
};
struct {
char *cstr;
list_head_t *inlist;
};
};
list_node_t node;
}__attribute__((packed)) yd_filter_item_t;
typedef struct __yd_filter_type {
domx_t *domx;
list_head_t filter;
} yd_filter_t;
yd_filter_t *yd_filter_create(domx_t *refobj);
void yd_filter_destroy(yd_filter_t *f);
int yd_filter_add_sf(yd_filter_t *f, const char *name, filt_t ftype,
uint64_t vf, uint64_t vc);
int yd_filter_add_str(yd_filter_t *f, const char *name, const char *value, int eq);
int yd_filter_add_inlist(yd_filter_t *f, const char *name, int length, void **array);
#define YD_CHUNK_AMOUNT 128
typedef struct __yd_wlist_node_type {
oid_t oid;
list_node_t node;
} yd_wlist_node_t;
typedef struct __yd_index_stream_type {
yd_filter_t *filter;
uint32_t offset;
uint8_t amount;
list_head_t entries_wlist;
void *priv;
} yd_idx_stream_t;
#define yd_index_stream_setfilter(sw, filt) (sw)->filter = (filt)
#define yd_index_stream_setpriv(sw, prv) (sw)->priv = prv
#define yd_index_stream_getpriv(sw) (sw)->priv
yd_idx_stream_t *yd_index_stream_init(void);
void yd_index_stream_destroy(yd_idx_stream_t *);
void yd_index_stream_emptylist(yd_idx_stream_t *);
typedef struct __yd_index_stream_window_type {
uint8_t amount;
list_head_t *wlist;
} yd_idx_stream_win_t;
#define yd_idx_stream_win_size(sw) (sw)->amount
/* domx stream operations */
yd_idx_stream_t *domx_idxl_open(domx_t *dt, ydm_access_filter_t afilter,
dataacc_pemctx_t *dacc, yd_filter_t *datafilter);
void domx_idxl_close(domx_t *dt, yd_idx_stream_t *idxl);
yd_idx_stream_win_t *domx_idxl_read(domx_t *dt, yd_idx_stream_t *idxl);
struct be_ops;
#define BEMAGIC 0xffffbeef
typedef struct __domx_dsbe_type {
domx_t *domx;
void *priv;
struct be_ops *f;
} domx_dsbe_t;
struct be_ops {
uint32_t be_magic;
/* initialization part */
int (*init)(domx_dsbe_t *, const char *);
/* data manipulation */
int (*get)(domx_dsbe_t *, oid_t, void *);
int (*set)(domx_dsbe_t *, oid_t, void *);
oid_t (*creat)(domx_dsbe_t *, const void *);
int (*remove)(domx_dsbe_t *, oid_t);
/* list requesting */
yd_idx_stream_t* (*create_idx_stream)(domx_dsbe_t *, ydm_access_filter_t,
dataacc_pemctx_t *, yd_filter_t *);
void (*destroy_idx_stream)(yd_idx_stream_t *);
yd_idx_stream_win_t* (*getportion_idx_stream)(yd_idx_stream_t *);
};
#endif /* __YD_DATAOBJECT_H__ */