update
git-svn-id: http://svn.openzap.org/svn/openzap/trunk@15 a93c3328-9c30-0410-af19-c9cd2b2d52af
This commit is contained in:
parent
22433a9970
commit
f57307bf91
|
@ -42,6 +42,9 @@ $(MYLIB): $(OBJS)
|
|||
ar rcs $(MYLIB) $(OBJS)
|
||||
ranlib $(MYLIB)
|
||||
|
||||
testapp: testapp.c $(MYLIB)
|
||||
$(CC) -L. -Iinclude testapp.c -o testapp -lopenzap -lm
|
||||
|
||||
openzap.o: openzap.c
|
||||
$(CC) $(MOD_CFLAGS) $(CC_CFLAGS) $(CFLAGS) -c $< -o $@
|
||||
|
||||
|
|
|
@ -22,13 +22,13 @@ static const unsigned int primes[] = {
|
|||
805306457, 1610612741
|
||||
};
|
||||
const unsigned int prime_table_length = sizeof(primes)/sizeof(primes[0]);
|
||||
const float max_load_factor = 0.65f;
|
||||
const float max_load_factor = 0.65;
|
||||
|
||||
/*****************************************************************************/
|
||||
struct hashtable *
|
||||
create_hashtable(unsigned int minsize,
|
||||
unsigned int (*hashf) (const void*),
|
||||
int (*eqf) (const void*,const void*))
|
||||
unsigned int (*hashf) (void*),
|
||||
int (*eqf) (void*,void*))
|
||||
{
|
||||
struct hashtable *h;
|
||||
unsigned int pindex, size = primes[0];
|
||||
|
@ -54,7 +54,7 @@ create_hashtable(unsigned int minsize,
|
|||
|
||||
/*****************************************************************************/
|
||||
unsigned int
|
||||
hash(struct hashtable *h, const void *k)
|
||||
hash(struct hashtable *h, void *k)
|
||||
{
|
||||
/* Aim to protect against poor hash functions by adding logic here
|
||||
* - logic taken from java 1.4 hashtable source */
|
||||
|
@ -160,7 +160,7 @@ hashtable_insert(struct hashtable *h, void *k, void *v)
|
|||
|
||||
/*****************************************************************************/
|
||||
void * /* returns value associated with key */
|
||||
hashtable_search(struct hashtable *h, const void *k)
|
||||
hashtable_search(struct hashtable *h, void *k)
|
||||
{
|
||||
struct entry *e;
|
||||
unsigned int hashvalue, index;
|
||||
|
|
|
@ -34,6 +34,18 @@ hashtable_iterator(struct hashtable *h)
|
|||
return itr;
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
/* key - return the key of the (key,value) pair at the current position */
|
||||
/* value - return the value of the (key,value) pair at the current position */
|
||||
|
||||
void *
|
||||
hashtable_iterator_key(struct hashtable_itr *i)
|
||||
{ return i->e->k; }
|
||||
|
||||
void *
|
||||
hashtable_iterator_value(struct hashtable_itr *i)
|
||||
{ return i->e->v; }
|
||||
|
||||
/*****************************************************************************/
|
||||
/* advance - advance the iterator to the next element
|
||||
* returns zero if advanced to end of table */
|
||||
|
|
|
@ -2,6 +2,11 @@
|
|||
|
||||
#ifndef __HASHTABLE_CWC22_H__
|
||||
#define __HASHTABLE_CWC22_H__
|
||||
#ifdef _MSC_VER
|
||||
#ifndef __inline__
|
||||
#define __inline__ __inline
|
||||
#endif
|
||||
#endif
|
||||
|
||||
struct hashtable;
|
||||
|
||||
|
@ -73,8 +78,8 @@ struct hashtable;
|
|||
|
||||
struct hashtable *
|
||||
create_hashtable(unsigned int minsize,
|
||||
unsigned int (*hashfunction) (const void*),
|
||||
int (*key_eq_fn) (const void*,const void*));
|
||||
unsigned int (*hashfunction) (void*),
|
||||
int (*key_eq_fn) (void*,void*));
|
||||
|
||||
/*****************************************************************************
|
||||
* hashtable_insert
|
||||
|
@ -114,7 +119,7 @@ int fnname (struct hashtable *h, keytype *k, valuetype *v) \
|
|||
*/
|
||||
|
||||
void *
|
||||
hashtable_search(struct hashtable *h, const void *k);
|
||||
hashtable_search(struct hashtable *h, void *k);
|
||||
|
||||
#define DEFINE_HASHTABLE_SEARCH(fnname, keytype, valuetype) \
|
||||
valuetype * fnname (struct hashtable *h, keytype *k) \
|
||||
|
|
|
@ -28,12 +28,20 @@ hashtable_iterator(struct hashtable *h);
|
|||
/* hashtable_iterator_key
|
||||
* - return the value of the (key,value) pair at the current position */
|
||||
|
||||
#define hashtable_iterator_key(i) (void *)i->e->k
|
||||
extern __inline__ void *
|
||||
hashtable_iterator_key(struct hashtable_itr *i)
|
||||
{
|
||||
return i->e->k;
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
/* value - return the value of the (key,value) pair at the current position */
|
||||
|
||||
#define hashtable_iterator_value (void *)i->e->v
|
||||
extern __inline__ void *
|
||||
hashtable_iterator_value(struct hashtable_itr *i)
|
||||
{
|
||||
return i->e->v;
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
/* advance - advance the iterator to the next element
|
||||
|
|
|
@ -5,6 +5,7 @@
|
|||
|
||||
#include "hashtable.h"
|
||||
|
||||
|
||||
/*****************************************************************************/
|
||||
struct entry
|
||||
{
|
||||
|
@ -19,17 +20,20 @@ struct hashtable {
|
|||
unsigned int entrycount;
|
||||
unsigned int loadlimit;
|
||||
unsigned int primeindex;
|
||||
unsigned int (*hashfn) (const void *k);
|
||||
int (*eqfn) (const void *k1, const void *k2);
|
||||
unsigned int (*hashfn) (void *k);
|
||||
int (*eqfn) (void *k1, void *k2);
|
||||
};
|
||||
|
||||
/*****************************************************************************/
|
||||
unsigned int
|
||||
hash(struct hashtable *h, const void *k);
|
||||
hash(struct hashtable *h, void *k);
|
||||
|
||||
/*****************************************************************************/
|
||||
/* indexFor */
|
||||
#define indexFor(hashvalue, tablelength) (unsigned int)(hashvalue % tablelength)
|
||||
static __inline__ unsigned int
|
||||
indexFor(unsigned int tablelength, unsigned int hashvalue) {
|
||||
return (hashvalue % tablelength);
|
||||
}
|
||||
|
||||
/* Only works if tablelength == 2^N */
|
||||
/*static inline unsigned int
|
||||
|
|
|
@ -209,18 +209,27 @@ typedef zap_status_t (*zint_write_t) ZINT_WRITE_ARGS ;
|
|||
#define ZINT_WRITE_MUZZLE assert(zchan != NULL); assert(data != NULL); assert(datalen != NULL)
|
||||
|
||||
#define ZAP_PRE __FILE__, __FUNCTION__, __LINE__
|
||||
#define ZAP_LOG_DEBUG ZAP_PRE, 7
|
||||
#define ZAP_LOG_INFO ZAP_PRE, 6
|
||||
#define ZAP_LOG_NOTICE ZAP_PRE, 5
|
||||
#define ZAP_LOG_WARNING ZAP_PRE, 4
|
||||
#define ZAP_LOG_ERROR ZAP_PRE, 3
|
||||
#define ZAP_LOG_CRIT ZAP_PRE, 2
|
||||
#define ZAP_LOG_ALERT ZAP_PRE, 1
|
||||
#define ZAP_LOG_EMERG ZAP_PRE, 0
|
||||
|
||||
#define ZAP_LOG_LEVEL_DEBUG 7
|
||||
#define ZAP_LOG_LEVEL_INFO 6
|
||||
#define ZAP_LOG_LEVEL_NOTICE 5
|
||||
#define ZAP_LOG_LEVEL_WARNING 4
|
||||
#define ZAP_LOG_LEVEL_ERROR 3
|
||||
#define ZAP_LOG_LEVEL_CRIT 2
|
||||
#define ZAP_LOG_LEVEL_ALERT 1
|
||||
#define ZAP_LOG_LEVEL_EMERG 0
|
||||
|
||||
#define ZAP_LOG_DEBUG ZAP_PRE, ZAP_LOG_LEVEL_DEBUG
|
||||
#define ZAP_LOG_INFO ZAP_PRE, ZAP_LOG_LEVEL_INFO
|
||||
#define ZAP_LOG_NOTICE ZAP_PRE, ZAP_LOG_LEVEL_NOTICE
|
||||
#define ZAP_LOG_WARNING ZAP_PRE, ZAP_LOG_LEVEL_WARNING
|
||||
#define ZAP_LOG_ERROR ZAP_PRE, ZAP_LOG_LEVEL_ERROR
|
||||
#define ZAP_LOG_CRIT ZAP_PRE, ZAP_LOG_LEVEL_CRIT
|
||||
#define ZAP_LOG_ALERT ZAP_PRE, ZAP_LOG_LEVEL_ALERT
|
||||
#define ZAP_LOG_EMERG ZAP_PRE, ZAP_LOG_LEVEL_EMERG
|
||||
|
||||
typedef void (*zap_logger_t)(char *file, const char *func, int line, int level, char *fmt, ...);
|
||||
extern zap_logger_t global_logger;
|
||||
#define zap_log global_logger;
|
||||
extern zap_logger_t zap_log;
|
||||
|
||||
struct zap_software_interface {
|
||||
const char *name;
|
||||
|
@ -252,7 +261,7 @@ zap_status_t zap_channel_write(zap_channel_t *zchan, void *data, zap_size_t *dat
|
|||
zap_status_t zap_global_init(void);
|
||||
zap_status_t zap_global_destroy(void);
|
||||
void zap_global_set_logger(zap_logger_t logger);
|
||||
void zap_global_set_default_logger(void);
|
||||
void zap_global_set_default_logger(int level);
|
||||
|
||||
typedef struct hashtable zap_hash_t;
|
||||
|
||||
|
|
|
@ -74,18 +74,25 @@ static char *cut_path(char *in)
|
|||
|
||||
static void null_logger(char *file, const char *func, int line, int level, char *fmt, ...)
|
||||
{
|
||||
if (file && func && line && level && fmt) {
|
||||
return;
|
||||
if (0) {
|
||||
null_logger(file, func, line, level, fmt, fmt + sizeof(fmt));
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
static int zap_log_level;
|
||||
|
||||
static void default_logger(char *file, const char *func, int line, int level, char *fmt, ...)
|
||||
{
|
||||
char *fp;
|
||||
char data[1024];
|
||||
|
||||
va_list ap;
|
||||
|
||||
if (level < 0 || level > 7) {
|
||||
level = 7;
|
||||
}
|
||||
if (level > zap_log_level) {
|
||||
return;
|
||||
}
|
||||
|
||||
fp = cut_path(file);
|
||||
|
||||
|
@ -93,9 +100,6 @@ static void default_logger(char *file, const char *func, int line, int level, ch
|
|||
|
||||
vsnprintf(data, sizeof(data), fmt, ap);
|
||||
|
||||
if (level < 0 || level > 7) {
|
||||
level = 7;
|
||||
}
|
||||
|
||||
fprintf(stderr, "[%s] %s:%d %s() %s", LEVEL_NAMES[level], file, line, func, data);
|
||||
|
||||
|
@ -103,37 +107,42 @@ static void default_logger(char *file, const char *func, int line, int level, ch
|
|||
|
||||
}
|
||||
|
||||
zap_logger_t global_logger = null_logger;
|
||||
zap_logger_t zap_log = null_logger;
|
||||
|
||||
void zap_global_set_logger(zap_logger_t logger)
|
||||
{
|
||||
if (logger) {
|
||||
global_logger = logger;
|
||||
zap_log = logger;
|
||||
} else {
|
||||
global_logger = null_logger;
|
||||
zap_log = null_logger;
|
||||
}
|
||||
}
|
||||
|
||||
void zap_global_set_default_logger(void)
|
||||
void zap_global_set_default_logger(int level)
|
||||
{
|
||||
global_logger = default_logger;
|
||||
if (level < 0 || level > 7) {
|
||||
level = 7;
|
||||
}
|
||||
|
||||
zap_log = default_logger;
|
||||
zap_log_level = level;
|
||||
}
|
||||
|
||||
static int equalkeys(const void *k1, const void *k2)
|
||||
static int equalkeys(void *k1, void *k2)
|
||||
{
|
||||
return strcmp((char *) k1, (char *) k2) ? 0 : 1;
|
||||
}
|
||||
|
||||
static unsigned hashfromstring(const void *ky)
|
||||
static unsigned hashfromstring(void *ky)
|
||||
{
|
||||
unsigned char *str = (unsigned char *) ky;
|
||||
unsigned hash = 0;
|
||||
int c;
|
||||
|
||||
|
||||
while ((c = *str++)) {
|
||||
hash = c + (hash << 6) + (hash << 16) - hash;
|
||||
}
|
||||
|
||||
|
||||
return hash;
|
||||
}
|
||||
|
||||
|
@ -176,7 +185,7 @@ zap_status_t zap_span_destroy(zap_span_t **span);
|
|||
|
||||
zap_status_t zap_channel_open(const char *name, unsigned span_id, unsigned chan_id, zap_channel_t **zchan)
|
||||
{
|
||||
zap_software_interface_t *zint = (zap_software_interface_t *) hashtable_search(globals.interface_hash, name);
|
||||
zap_software_interface_t *zint = (zap_software_interface_t *) hashtable_search(globals.interface_hash, (char *)name);
|
||||
|
||||
if (span_id < ZAP_MAX_SPANS_INTERFACE && chan_id < ZAP_MAX_CHANNELS_SPAN && zint) {
|
||||
zap_channel_t *check;
|
||||
|
@ -303,37 +312,51 @@ zap_status_t zap_global_init(void)
|
|||
char *var, *val;
|
||||
unsigned configured = 0;
|
||||
zap_software_interface_t *zint;
|
||||
int modcount;
|
||||
|
||||
globals.interface_hash = create_hashtable(16, hashfromstring, equalkeys);
|
||||
zint = NULL;
|
||||
modcount = 0;
|
||||
|
||||
#ifdef ZAP_WANPIPE_SUPPORT
|
||||
if (wanpipe_init(&zint) == ZAP_SUCCESS) {
|
||||
hashtable_insert(globals.interface_hash, (void *)zint->name, zint);
|
||||
modcount++;
|
||||
} else {
|
||||
zap_log(ZAP_LOG_ERROR, "Error initilizing wanpipe.\n");
|
||||
}
|
||||
#endif
|
||||
zint = NULL;
|
||||
#ifdef ZAP_ZT_SUPPORT
|
||||
if (zt_init(&zint) == ZAP_SUCCESS) {
|
||||
hashtable_insert(globals.interface_hash, (void *)zint->name, zint);
|
||||
modcount++;
|
||||
} else {
|
||||
zap_log(ZAP_LOG_ERROR, "Error initilizing zt.\n");
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
if (!zap_config_open_file(&cfg, "openzap.conf")) {
|
||||
if (!modcount) {
|
||||
zap_log(ZAP_LOG_ERROR, "Error initilizing anything.\n");
|
||||
return ZAP_FAIL;
|
||||
}
|
||||
|
||||
if (!zap_config_open_file(&cfg, "openzap.conf")) {
|
||||
return ZAP_FAIL;
|
||||
}
|
||||
|
||||
while (zap_config_next_pair(&cfg, &var, &val)) {
|
||||
if (!strcasecmp(cfg.category, "openzap")) {
|
||||
if (!strcmp(var, "load")) {
|
||||
zap_software_interface_t *zint;
|
||||
|
||||
|
||||
zint = (zap_software_interface_t *) hashtable_search(globals.interface_hash, val);
|
||||
if (zint) {
|
||||
if (zint->configure(zint) == ZAP_SUCCESS) {
|
||||
configured++;
|
||||
}
|
||||
} else {
|
||||
zap_log(ZAP_LOG_WARNING, "Attempted to load Non-Existant module '%s'\n", val);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -341,7 +364,12 @@ zap_status_t zap_global_init(void)
|
|||
|
||||
zap_config_close_file(&cfg);
|
||||
|
||||
return configured ? ZAP_SUCCESS : ZAP_FAIL;
|
||||
if (configured) {
|
||||
return ZAP_SUCCESS;
|
||||
}
|
||||
|
||||
zap_log(ZAP_LOG_ERROR, "No modules configured!\n");
|
||||
return ZAP_FAIL;
|
||||
}
|
||||
|
||||
zap_status_t zap_global_destroy(void)
|
||||
|
|
|
@ -0,0 +1,9 @@
|
|||
#include "openzap.h"
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
printf("hello\n");
|
||||
|
||||
zap_global_set_default_logger(ZAP_LOG_LEVEL_DEBUG);
|
||||
zap_global_init();
|
||||
}
|
|
@ -71,6 +71,8 @@ typedef unsigned __int32 u_int32_t;
|
|||
#include <sdla_front_end.h>
|
||||
#include <sdla_aft_te1.h>
|
||||
|
||||
static zap_software_interface_t wanpipe_interface;
|
||||
|
||||
struct wanpipe_channel {
|
||||
struct zap_channel zchan;
|
||||
int x;
|
||||
|
@ -81,18 +83,35 @@ static ZINT_CONFIGURE_FUNCTION(wanpipe_configure)
|
|||
zap_config_t cfg;
|
||||
char *var, *val;
|
||||
int catno = -1;
|
||||
zap_span_t *span = NULL;
|
||||
|
||||
ZINT_CONFIGURE_MUZZLE;
|
||||
|
||||
zap_log(ZAP_LOG_DEBUG, "configuring wanpipe\n");
|
||||
if (!zap_config_open_file(&cfg, "wanpipe.conf")) {
|
||||
return ZAP_FAIL;
|
||||
}
|
||||
|
||||
|
||||
while (zap_config_next_pair(&cfg, &var, &val)) {
|
||||
if (!strcasecmp(cfg.category, "span")) {
|
||||
if (cfg.catno != catno) {
|
||||
zap_log(ZAP_LOG_DEBUG, "found config for span %d\n", cfg.catno);
|
||||
catno = cfg.catno;
|
||||
if (zap_span_create(&wanpipe_interface, &span) == ZAP_SUCCESS) {
|
||||
zap_log(ZAP_LOG_DEBUG, "created span %d\n", span->span_id);
|
||||
} else {
|
||||
zap_log(ZAP_LOG_CRIT, "failure creating span\n");
|
||||
span = NULL;
|
||||
}
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!span) {
|
||||
continue;
|
||||
}
|
||||
|
||||
zap_log(ZAP_LOG_DEBUG, "span %d [%s]=[%s]\n", span->span_id, var, val);
|
||||
}
|
||||
}
|
||||
zap_config_close_file(&cfg);
|
||||
|
@ -142,8 +161,6 @@ static ZINT_WRITE_FUNCTION(wanpipe_write)
|
|||
return ZAP_FAIL;
|
||||
}
|
||||
|
||||
static zap_software_interface_t wanpipe_interface;
|
||||
|
||||
zap_status_t wanpipe_init(zap_software_interface_t **zint)
|
||||
{
|
||||
assert(zint != NULL);
|
||||
|
@ -160,7 +177,7 @@ zap_status_t wanpipe_init(zap_software_interface_t **zint)
|
|||
wanpipe_interface.write = wanpipe_write;
|
||||
*zint = &wanpipe_interface;
|
||||
|
||||
return ZAP_FAIL;
|
||||
return ZAP_SUCCESS;
|
||||
}
|
||||
|
||||
zap_status_t wanpipe_destroy(void)
|
||||
|
|
Loading…
Reference in New Issue