From bf1117c4c93300d5820f2afbd1aac41da029cd49 Mon Sep 17 00:00:00 2001 From: Luis Ontanon Date: Mon, 16 May 2005 17:16:52 +0000 Subject: [PATCH] Transforms and Pdus are working already, Gops start to work. svn path=/trunk/; revision=14376 --- plugins/mate/mate.h | 2 +- plugins/mate/mate_plugin.c | 2 - plugins/mate/mate_runtime.c | 41 +++++++---- plugins/mate/mate_setup.c | 132 +----------------------------------- plugins/mate/mate_util.c | 4 +- plugins/mate/mate_util.h | 2 +- 6 files changed, 33 insertions(+), 150 deletions(-) diff --git a/plugins/mate/mate.h b/plugins/mate/mate.h index 32a7b4ee75..61060dbdcb 100644 --- a/plugins/mate/mate.h +++ b/plugins/mate/mate.h @@ -308,7 +308,7 @@ struct _mate_gop { guint32 id; mate_cfg_gop* cfg; - guint8* gop_key; + gchar* gop_key; AVPL* avpl; /* the attributes of the pdu/gop/gog */ guint last_n; diff --git a/plugins/mate/mate_plugin.c b/plugins/mate/mate_plugin.c index d8009854ef..af8ecba96a 100644 --- a/plugins/mate/mate_plugin.c +++ b/plugins/mate/mate_plugin.c @@ -49,8 +49,6 @@ G_MODULE_EXPORT const gchar version[] = VERSION; G_MODULE_EXPORT void plugin_register(void) { - g_message("---"); - if (! initialized ) { proto_register_mate(); initialized = 1; diff --git a/plugins/mate/mate_runtime.c b/plugins/mate/mate_runtime.c index 3475807330..ec08bb145e 100644 --- a/plugins/mate/mate_runtime.c +++ b/plugins/mate/mate_runtime.c @@ -50,7 +50,7 @@ typedef struct _gogkey { static mate_runtime_data* rd = NULL; static mate_config* mc = NULL; -static int zero = 0; +static int zero = 5; static int* dbg = &zero; static int* dbg_pdu = &zero; @@ -155,6 +155,7 @@ extern void initialize_mate_runtime(void) { rd->frames = g_hash_table_new(g_direct_hash,g_direct_equal); + mc->dbg_gop_lvl = 5; dbg_pdu = &(mc->dbg_pdu_lvl); dbg_gop = &(mc->dbg_gop_lvl); dbg_gog = &(mc->dbg_gog_lvl); @@ -171,8 +172,8 @@ static mate_gop* new_gop(mate_cfg_gop* cfg, mate_pdu* pdu, gchar* key) { gop->id = ++(cfg->last_id); gop->cfg = cfg; - dbg_print (dbg_gop,1,dbg_facility,"new_gop: %s: ``%s:%d''",gop->cfg->name,gop->id,key); - + dbg_print(dbg_gop, 1, dbg_facility, "new_gop: %s: ``%s:%d''", key, gop->cfg->name, gop->id); + gop->gop_key = key; gop->avpl = new_avpl(cfg->name); gop->last_n = 0; @@ -180,26 +181,28 @@ static mate_gop* new_gop(mate_cfg_gop* cfg, mate_pdu* pdu, gchar* key) { gop->gog = NULL; gop->next = NULL; - gop->expiration = 0.0; - gop->idle_expiration = 0.0; + gop->expiration = cfg->expiration > 0.0 ? cfg->expiration + rd->now : (float) -1.0 ; + gop->idle_expiration = cfg->idle_timeout > 0.0 ? cfg->idle_timeout + rd->now : (float) -1.0 ; gop->time_to_die = cfg->lifetime > 0.0 ? cfg->lifetime + rd->now : (float) -1.0 ; gop->time_to_timeout = 0.0; gop->last_time = gop->start_time = rd->now; gop->release_time = 0.0; - gop->num_of_pdus = 1; + gop->num_of_pdus = 0; gop->num_of_after_release_pdus = 0; gop->pdus = pdu; gop->last_pdu = pdu; + gop->released = FALSE; pdu->gop = gop; pdu->next = NULL; pdu->is_start = TRUE; pdu->time_in_gop = 0.0; + g_hash_table_insert(cfg->gop_index,gop->gop_key,gop); return gop; } @@ -484,7 +487,7 @@ static void analize_pdu(mate_pdu* pdu) { if ((gopkey_match = new_avpl_exact_match("gop_key_match",pdu->avpl,cfg->key, TRUE))) { gop_key = avpl_to_str(gopkey_match); - + g_hash_table_lookup_extended(cfg->gop_index,(gconstpointer)gop_key,(gpointer*)&orig_gop_key,(gpointer*)&gop); if ( gop ) { @@ -494,6 +497,7 @@ static void analize_pdu(mate_pdu* pdu) { if ( ! gop->released && ( ( gop->cfg->lifetime > 0.0 && gop->time_to_die >= rd->now) || ( gop->cfg->idle_timeout > 0.0 && gop->time_to_timeout >= rd->now) ) ) { + dbg_print (dbg_gop,4,dbg_facility,"analize_pdu: expiring released gop"); gop->released = TRUE; if (gop->gog && gop->cfg->start) gop->gog->num_of_released_gops++; @@ -576,18 +580,27 @@ static void analize_pdu(mate_pdu* pdu) { return; } - } else { - dbg_print (dbg_gop,6,dbg_facility,"analize_pdu: an unassigned pdu"); + } else { + candidate_start = cfg->start; - pdu->gop = NULL; - pdu->next = NULL; + if (( is_start = new_avpl_exact_match("",pdu->avpl, candidate_start, FALSE) )) { + delete_avpl(is_start,FALSE); + gop = new_gop(cfg,pdu,gop_key); + } else { + g_free(gop_key); + return; + } - g_free(gop_key); - delete_avpl(gopkey_match,TRUE); - return; + pdu->gop = gop; } } + if (gop->last_pdu) gop->last_pdu->next = pdu; + gop->last_pdu = pdu; + pdu->next = NULL; + + pdu->time_in_gop = rd->now - gop->start_time; + gop->num_of_pdus++; gop->time_to_timeout = cfg->idle_timeout > 0.0 ? cfg->idle_timeout + rd->now : (float) -1.0 ; diff --git a/plugins/mate/mate_setup.c b/plugins/mate/mate_setup.c index 41e3470c5e..a947d8cff6 100644 --- a/plugins/mate/mate_setup.c +++ b/plugins/mate/mate_setup.c @@ -216,135 +216,6 @@ extern gchar* add_ranges(gchar* range,GPtrArray* range_ptr_arr) { return NULL; } - -#if 0 -#define true_false_str(v) ((v) ? "TRUE" : "FALSE") - - -static void print_gog_config(gpointer k _U_, gpointer v, gpointer p _U_) { - mate_cfg_gop* cfg = (mate_cfg_gop*) v; - guint8* avplstr = NULL; - void* cookie = NULL; - AVPL* avpl; - - dbg_print (dbg_cfg,0,dbg_facility,"Action=GogDef; Name=%s; Expiration=%f;",cfg->name,cfg->expiration); - - if (cfg->keys) { - while (( avpl = get_next_avpl(cfg->keys,&cookie) )) { - avplstr = avpl_to_str(avpl); - dbg_print (dbg_cfg,0,dbg_facility,"Action=GogKey; For=%s; On=%s; %s",cfg->name,avpl->name,avplstr); - g_free(avplstr); - } - } - - if (cfg->extra) { - avplstr = avpl_to_str(cfg->extra); - dbg_print (dbg_cfg,0,dbg_facility,"Action=GogExtra; For=%s; %s",cfg->name,avplstr); - g_free(avplstr); - } - - print_xxx_transforms(cfg); - -} - - - -static void print_gop_config(gpointer k _U_ , gpointer v, gpointer p _U_) { - mate_cfg_gop* cfg = (mate_cfg_gop*) v; - guint8* avplstr = NULL; - guint8* show_pdu_tree; - GString* gopdef; - - gopdef = g_string_new("Action=GopDef; "); - - show_pdu_tree = cfg->show_pdu_tree ? "TRUE" : "FALSE"; - g_string_sprintfa(gopdef,"Name=%s; ShowPduTree=%s; ShowGopTimes=%s; " - "GopExpiration=%f; GopIdleTimeout=%f GopLifetime=%f;", - cfg->name,show_pdu_tree,true_false_str(cfg->show_times), - cfg->expiration,cfg->idle_timeout,cfg->lifetime); - - if (cfg->key) { - avplstr = avpl_to_str(cfg->key); - g_string_sprintfa(gopdef," %s",avplstr); - g_free(avplstr); - } - - dbg_print (dbg_cfg,0,dbg_facility,"%s",gopdef->str); - - - if (cfg->start) { - avplstr = avpl_to_str(cfg->start); - dbg_print (dbg_cfg,0,dbg_facility,"Action=GopStart; For=%s; %s",cfg->name,avplstr); - g_free(avplstr); - } - - if (cfg->stop) { - avplstr = avpl_to_str(cfg->stop); - dbg_print (dbg_cfg,0,dbg_facility,"Action=GopStop; For=%s; %s",cfg->name,avplstr); - g_free(avplstr); - } - - if (cfg->extra) { - avplstr = avpl_to_str(cfg->extra); - dbg_print (dbg_cfg,0,dbg_facility,"Action=GopExtra; For=%s; %s",cfg->name,avplstr); - g_free(avplstr); - } - - print_xxx_transforms(cfg); - - g_string_free(gopdef,TRUE); - -} - - -static void print_gogs_by_gopname(gpointer k, gpointer v, gpointer p _U_) { - void* cookie = NULL; - guint8* str = NULL; - AVPL* avpl; - - while(( avpl = get_next_avpl((LoAL*)v,&cookie) )) { - str = avpl_to_str(avpl); - dbg_print(dbg_cfg,0,dbg_facility,"Gop=%s; Gog=%s; --> %s",(guint8*)k,avpl->name,str); - g_free(str); - } - -} - -static void print_gops_by_pduname(gpointer k, gpointer v, gpointer p _U_) { - dbg_print(dbg_cfg,0,dbg_facility, - "PduName=%s; GopName=%s;", (guint8*)k,((mate_cfg_gop*)v)->name); -} - -static void print_config(void) { - guint i; - - /* FIXME: print the settings */ - - dbg_print(dbg_cfg,0,dbg_facility,"###########################" - " CURRENT CONFIGURATION " "###########################"); - - g_hash_table_foreach(matecfg->transfs,print_transforms,NULL); - - for (i=0; ipducfglist->len; i++) { - print_pdu_config((mate_cfg_pdu*) g_ptr_array_index(matecfg->pducfglist,i)); - } - - g_hash_table_foreach(matecfg->gopcfgs,print_gop_config,NULL); - g_hash_table_foreach(matecfg->gogcfgs,print_gog_config,NULL); - - dbg_print(dbg_cfg,0,dbg_facility,"###########################" - " END OF CURRENT CONFIGURATION " "###########################"); - - if (*dbg_cfg > 1) { - dbg_print(dbg_cfg,0,dbg_facility,"******* Config Hashes"); - dbg_print(dbg_cfg,0,dbg_facility,"*** Gops by PduName"); - g_hash_table_foreach(matecfg->gops_by_pduname,print_gops_by_pduname,NULL); - dbg_print(dbg_cfg,0,dbg_facility,"*** GogKeys by GopName"); - g_hash_table_foreach(matecfg->gogs_by_gopname,print_gogs_by_gopname,NULL); - } -} -#endif - static void new_attr_hfri(gchar* item_name, GHashTable* hfids, gchar* name) { int* p_id = g_malloc(sizeof(int)); @@ -548,6 +419,7 @@ static void analyze_gop_config(gpointer k _U_, gpointer v, gpointer p _U_) { ett = &cfg->ett_children; g_array_append_val(matecfg->ett,ett); + g_hash_table_insert(matecfg->gops_by_pduname,cfg->name,cfg); } @@ -1022,7 +894,7 @@ extern mate_config* mate_make_config(gchar* filename, int mate_hfid) { g_hash_table_foreach(matecfg->gopcfgs,(GHFunc)print_gop_config,config_text); g_hash_table_foreach(matecfg->gogcfgs,(GHFunc)print_gog_config,config_text); - g_message("Current configuration\n%s\nDone;\n",config_text->str); + g_message("Current configuration:\n%s\nDone;\n",config_text->str); /* } */ analyze_config(); diff --git a/plugins/mate/mate_util.c b/plugins/mate/mate_util.c index 9de22c8ca7..1020046ad4 100644 --- a/plugins/mate/mate_util.c +++ b/plugins/mate/mate_util.c @@ -40,7 +40,7 @@ * fmt, ...: what to print */ -void dbg_print(const gint* which, gint how, FILE* where, gchar* fmt, ... ) { +void dbg_print(const gint* which, gint how, FILE* where, const gchar* fmt, ... ) { static gchar debug_buffer[DEBUG_BUFFER_SIZE]; va_list list; @@ -63,7 +63,7 @@ void dbg_print(const gint* which, gint how, FILE* where, gchar* fmt, ... ) { /*************************************************************************** * single copy strings *************************************************************************** - * In order to save memory and since strings repeat more often than don't, + * Strings repeat more often than don't. In order to save memory * we'll keep only one copy of each as key to a hash with a count of * subscribers as value. ***************************************************************************/ diff --git a/plugins/mate/mate_util.h b/plugins/mate/mate_util.h index a8963e22eb..27af4fdccb 100644 --- a/plugins/mate/mate_util.h +++ b/plugins/mate/mate_util.h @@ -38,7 +38,7 @@ /******* dbg_print *********/ #define DEBUG_BUFFER_SIZE 4096 -extern void dbg_print(const gint* which, gint how, FILE* where, gchar* fmt, ... ); +extern void dbg_print(const gint* which, gint how, FILE* where, const gchar* fmt, ... ); /******* single copy strings *********/