mirror of https://github.com/sipwise/rtpengine.git
obsoletes the entire plugin/module system Change-Id: I6997b7e6e49dac568e844c3e132fa3756cf147cbchanges/69/2669/1
parent
a934fb4568
commit
dafde10571
File diff suppressed because it is too large
Load Diff
@ -1,47 +1,125 @@
|
||||
#ifndef __REDIS_H__
|
||||
#define __REDIS_H__
|
||||
#ifndef __REDIS_MOD_H__
|
||||
#define __REDIS_MOD_H__
|
||||
|
||||
|
||||
|
||||
|
||||
#include <sys/types.h>
|
||||
#include "compat.h"
|
||||
#include "aux.h"
|
||||
|
||||
#include <glib.h>
|
||||
#include <sys/types.h>
|
||||
#include <hiredis/hiredis.h>
|
||||
|
||||
|
||||
|
||||
struct callmaster;
|
||||
struct call;
|
||||
struct redis;
|
||||
|
||||
|
||||
|
||||
extern struct redis *(*redis_new_mod)(u_int32_t, u_int16_t, int);
|
||||
extern int (*redis_restore_mod)(struct callmaster *, struct redis *);
|
||||
extern void (*redis_update_mod)(struct call *, struct redis *);
|
||||
extern void (*redis_delete_mod)(struct call *, struct redis *);
|
||||
extern void (*redis_wipe_mod)(struct redis *);
|
||||
struct redis {
|
||||
u_int32_t ip;
|
||||
char host[32];
|
||||
int port;
|
||||
|
||||
redisContext *ctx;
|
||||
int db;
|
||||
mutex_t lock;
|
||||
unsigned int pipeline;
|
||||
};
|
||||
struct redis_hash {
|
||||
redisReply *rr;
|
||||
GHashTable *ht;
|
||||
};
|
||||
struct redis_list {
|
||||
GQueue q;
|
||||
struct redis_hash rh;
|
||||
};
|
||||
struct list_item {
|
||||
redisReply *id;
|
||||
struct redis_hash rh;
|
||||
void *ptr;
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
INLINE void redis_update(struct call *c, struct redis *r) {
|
||||
if (!redis_update_mod)
|
||||
return;
|
||||
redis_update_mod(c, r);
|
||||
|
||||
|
||||
|
||||
#if !GLIB_CHECK_VERSION(2,40,0)
|
||||
INLINE gboolean g_hash_table_insert_check(GHashTable *h, gpointer k, gpointer v) {
|
||||
gboolean ret = TRUE;
|
||||
if (g_hash_table_contains(h, k))
|
||||
ret = FALSE;
|
||||
g_hash_table_insert(h, k, v);
|
||||
return ret;
|
||||
}
|
||||
INLINE void redis_delete(struct call *c, struct redis *r) {
|
||||
if (!redis_delete_mod)
|
||||
return;
|
||||
redis_delete_mod(c, r);
|
||||
#else
|
||||
# define g_hash_table_insert_check g_hash_table_insert
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
#define rlog(l, x...) ilog(l | LOG_FLAG_RESTORE, x)
|
||||
|
||||
|
||||
|
||||
#define REDIS_FMT(x) (x)->len, (x)->str
|
||||
|
||||
|
||||
|
||||
|
||||
struct redis *redis_new(u_int32_t, u_int16_t, int);
|
||||
int redis_restore(struct callmaster *, struct redis *);
|
||||
void redis_update(struct call *, struct redis *);
|
||||
void redis_delete(struct call *, struct redis *);
|
||||
void redis_wipe(struct redis *);
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
#define define_get_type_format(name, type) \
|
||||
static int redis_hash_get_ ## name ## _v(type *out, const struct redis_hash *h, const char *f, \
|
||||
va_list ap) \
|
||||
{ \
|
||||
char key[64]; \
|
||||
\
|
||||
vsnprintf(key, sizeof(key), f, ap); \
|
||||
return redis_hash_get_ ## name(out, h, key); \
|
||||
} \
|
||||
static int redis_hash_get_ ## name ## _f(type *out, const struct redis_hash *h, const char *f, ...) { \
|
||||
va_list ap; \
|
||||
int ret; \
|
||||
\
|
||||
va_start(ap, f); \
|
||||
ret = redis_hash_get_ ## name ## _v(out, h, f, ap); \
|
||||
va_end(ap); \
|
||||
return ret; \
|
||||
}
|
||||
INLINE int redis_restore(struct callmaster *m, struct redis *r) {
|
||||
if (!redis_restore_mod)
|
||||
return 0;
|
||||
return redis_restore_mod(m, r);
|
||||
|
||||
#define define_get_int_type(name, type, func) \
|
||||
static int redis_hash_get_ ## name(type *out, const struct redis_hash *h, const char *k) { \
|
||||
redisReply *r; \
|
||||
\
|
||||
r = g_hash_table_lookup(h->ht, k); \
|
||||
if (!r) \
|
||||
return -1; \
|
||||
*out = func(r->str, NULL, 10); \
|
||||
return 0; \
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
Loading…
Reference in new issue