summaryrefslogtreecommitdiffstats
path: root/veslibrary/ves_clibrary/evel/evel-library/code/evel_library/evel_other.c
diff options
context:
space:
mode:
Diffstat (limited to 'veslibrary/ves_clibrary/evel/evel-library/code/evel_library/evel_other.c')
-rw-r--r--veslibrary/ves_clibrary/evel/evel-library/code/evel_library/evel_other.c338
1 files changed, 182 insertions, 156 deletions
diff --git a/veslibrary/ves_clibrary/evel/evel-library/code/evel_library/evel_other.c b/veslibrary/ves_clibrary/evel/evel-library/code/evel_library/evel_other.c
index b238e38..61809f0 100644
--- a/veslibrary/ves_clibrary/evel/evel-library/code/evel_library/evel_other.c
+++ b/veslibrary/ves_clibrary/evel/evel-library/code/evel_library/evel_other.c
@@ -28,6 +28,7 @@
#include "evel.h"
#include "evel_internal.h"
+#include "evel_throttle.h"
/**************************************************************************//**
* Create a new Other event.
@@ -70,9 +71,9 @@ EVENT_OTHER * evel_new_other(const char* ev_name, const char *ev_id)
other->major_version = EVEL_OTHER_EVENT_MAJOR_VERSION;
other->minor_version = EVEL_OTHER_EVENT_MINOR_VERSION;
- other->namedarrays = NULL;
+ other->hashMap = ht_create();
dlist_initialize(&other->jsonobjects);
- dlist_initialize(&other->namedvalues);
+ dlist_initialize(&other->arrayOfNamedHashMap);
exit_label:
EVEL_EXIT();
@@ -106,16 +107,22 @@ void evel_other_type_set(EVENT_OTHER * other,
EVEL_EXIT();
}
+
/**************************************************************************//**
- * Set size of Named arrays hash table
+ * Add a json object to jsonObject list.
*
- * The max size of hash table is passed
+ * The name and value are null delimited ASCII strings. The library takes
+ * a copy so the caller does not have to preserve values after the function
+ * returns.
*
* @param other Pointer to the Other.
* @param size size of hashtable
*****************************************************************************/
-void evel_other_field_set_namedarraysize(EVENT_OTHER * other, const int size)
+void evel_other_field_add_hashmap(EVENT_OTHER * other, char * name, char *value)
{
+ char *nam=NULL;
+ char *val=NULL;
+
EVEL_ENTER();
/***************************************************************************/
@@ -123,31 +130,28 @@ void evel_other_field_set_namedarraysize(EVENT_OTHER * other, const int size)
/***************************************************************************/
assert(other != NULL);
assert(other->header.event_domain == EVEL_DOMAIN_OTHER);
- assert(other->namedarrays == NULL);
- assert(size > 0);
- EVEL_DEBUG("Adding Named array");
+ assert(name != NULL);
+ assert(value != NULL);
+
+ EVEL_DEBUG("Adding values to hashMap");
+
+ EVEL_DEBUG("Adding name=%s value=%s", name, value);
- other->namedarrays = ht_create(size);
+ nam = strdup(name);
+ val = strdup(value);
+
+ ht_insert(other->hashMap, nam, val);
EVEL_EXIT();
}
-
-/**************************************************************************//**
- * Add a json object to jsonObject list.
- *
- * The name and value are null delimited ASCII strings. The library takes
- * a copy so the caller does not have to preserve values after the function
- * returns.
- *
- * @param other Pointer to the Other.
- * @param size size of hashtable
- *****************************************************************************/
-void evel_other_field_add_namedarray(EVENT_OTHER * other, const char *hashname, char * name, char *value)
+HASHTABLE_T * evel_other_add_new_hashmap_to_hmarray(EVENT_OTHER * const other,
+ const char * const name)
{
- OTHER_FIELD * other_field = NULL;
- DLIST *list = NULL;
+ HASHTABLE_T *ht;
+ char *nam=NULL;
+
EVEL_ENTER();
/***************************************************************************/
@@ -155,84 +159,73 @@ void evel_other_field_add_namedarray(EVENT_OTHER * other, const char *hashname,
/***************************************************************************/
assert(other != NULL);
assert(other->header.event_domain == EVEL_DOMAIN_OTHER);
- assert(other->namedarrays != NULL);
+ assert(name != NULL);
- EVEL_DEBUG("Adding values to Named array");
-
- EVEL_DEBUG("Adding name=%s value=%s", name, value);
- other_field = malloc(sizeof(OTHER_FIELD));
- assert(other_field != NULL);
- memset(other_field, 0, sizeof(OTHER_FIELD));
- other_field->name = strdup(name);
- other_field->value = strdup(value);
- assert(other_field->name != NULL);
- assert(other_field->value != NULL);
+ nam = strdup(name);
+ EVEL_DEBUG("Adding HashMap to array of hashmap - %s", nam);
+ ht = nht_create(nam);
- list = (DLIST *)ht_get(other->namedarrays, hashname);
- if( list == NULL )
+ if (ht != NULL)
{
- DLIST * nlist = malloc(sizeof(DLIST));
- dlist_initialize(nlist);
- dlist_push_last(nlist, other_field);
- ht_set(other->namedarrays, hashname,(void*)nlist);
- EVEL_DEBUG("Created to new namedarray table %p",nlist);
- }
- else
- {
- dlist_push_last(list, other_field);
- EVEL_DEBUG("Adding to existing table %p",list);
+ dlist_push_last(&other->arrayOfNamedHashMap, ht);
}
EVEL_EXIT();
-}
+ return ht;
+}
/**************************************************************************//**
- * Add a json object to jsonObject list.
+ * Add a field name/value pair to the Other.
*
* The name and value are null delimited ASCII strings. The library takes
* a copy so the caller does not have to preserve values after the function
* returns.
*
- * @param other Pointer to the Other.
- * @param jsonobj Pointer to json object
+ * @param ht Pointer to the hasmap array.
+ * @param name ASCIIZ string with the field's name. The caller does not
+ * need to preserve the value once the function returns.
+ * @param value ASCIIZ string with the field's value. The caller does not
+ * need to preserve the value once the function returns.
*****************************************************************************/
-void evel_other_field_add_jsonobj(EVENT_OTHER * other, EVEL_JSON_OBJECT *jsonobj)
+void evel_other_set_hashmap_in_hmarray(
+ HASHTABLE_T * const ht,
+ const char * const name,
+ const char * const value)
{
- OTHER_FIELD * other_field = NULL;
+ char *nam=NULL;
+ char *val=NULL;
+
EVEL_ENTER();
/***************************************************************************/
/* Check preconditions. */
/***************************************************************************/
- assert(other != NULL);
- assert(other->header.event_domain == EVEL_DOMAIN_OTHER);
- assert(jsonobj != NULL);
+ assert(ht != NULL);
+ assert(name != NULL);
- EVEL_DEBUG("Adding jsonObject");
+ EVEL_DEBUG("Adding name=%s value=%s", name, value);
- dlist_push_last(&other->jsonobjects, jsonobj);
+ nam = strdup(name);
+ val = strdup(value);
+
+ ht_insert(ht, nam, val);
EVEL_EXIT();
}
-
/**************************************************************************//**
- * Add a field name/value pair to the Other.
+ * Add a json object to jsonObject list.
*
* The name and value are null delimited ASCII strings. The library takes
* a copy so the caller does not have to preserve values after the function
* returns.
*
* @param other Pointer to the Other.
- * @param name ASCIIZ string with the field's name. The caller does not
- * need to preserve the value once the function returns.
- * @param value ASCIIZ string with the field's value. The caller does not
- * need to preserve the value once the function returns.
+ * @param jsonobj Pointer to json object
*****************************************************************************/
-void evel_other_field_add(EVENT_OTHER * other, char * name, char * value)
+void evel_other_field_add_jsonobj(EVENT_OTHER * other, EVEL_JSON_OBJECT *jsonobj)
{
- OTHER_FIELD * other_field = NULL;
EVEL_ENTER();
/***************************************************************************/
@@ -240,19 +233,11 @@ void evel_other_field_add(EVENT_OTHER * other, char * name, char * value)
/***************************************************************************/
assert(other != NULL);
assert(other->header.event_domain == EVEL_DOMAIN_OTHER);
- assert(name != NULL);
- assert(value != NULL);
+ assert(jsonobj != NULL);
- EVEL_DEBUG("Adding name=%s value=%s", name, value);
- other_field = malloc(sizeof(OTHER_FIELD));
- assert(other_field != NULL);
- memset(other_field, 0, sizeof(OTHER_FIELD));
- other_field->name = strdup(name);
- other_field->value = strdup(value);
- assert(other_field->name != NULL);
- assert(other_field->value != NULL);
+ EVEL_DEBUG("Adding jsonObject");
- dlist_push_last(&other->namedvalues, other_field);
+ dlist_push_last(&other->jsonobjects, jsonobj);
EVEL_EXIT();
}
@@ -266,7 +251,6 @@ void evel_other_field_add(EVENT_OTHER * other, char * name, char * value)
void evel_json_encode_other(EVEL_JSON_BUFFER * jbuf,
EVENT_OTHER * event)
{
- OTHER_FIELD * other_field = NULL;
EVEL_JSON_OBJECT * jsonobjp = NULL;
DLIST_ITEM * other_field_item = NULL;
EVEL_JSON_OBJECT_INSTANCE * jsonobjinst = NULL;
@@ -274,10 +258,8 @@ void evel_json_encode_other(EVEL_JSON_BUFFER * jbuf,
EVEL_INTERNAL_KEY * keyinst = NULL;
DLIST_ITEM * keyinst_field_item = NULL;
HASHTABLE_T *ht = NULL;
- int idx;
- bool itm_added = false;
- DLIST *itm_list = NULL;
ENTRY_T *entry = NULL;
+ DLIST_ITEM *dlist_item;
EVEL_ENTER();
@@ -290,52 +272,52 @@ void evel_json_encode_other(EVEL_JSON_BUFFER * jbuf,
evel_json_encode_header(jbuf, &event->header);
evel_json_open_named_object(jbuf, "otherFields");
-// iterate through hashtable and print DLIST for each entry
-
- evel_json_checkpoint(jbuf);
- ht = event->namedarrays;
- if( ht != NULL )
- {
- if( ht->size > 0)
- {
-
- evel_json_open_opt_named_list(jbuf, "hashOfNameValuePairArrays");
- for( idx = 0; idx < ht->size; idx++ ) {
- if( ht->table[idx] != NULL)
- {
- entry = ht->table[idx];
- EVEL_DEBUG("Encoding other %s %p",(char *) (entry->key), entry->value);
-
- evel_json_open_object(jbuf);
- evel_enc_kv_string(jbuf, "name", entry->key);
-
- itm_list = (DLIST*)(entry->value);
- evel_json_open_opt_named_list(jbuf, "arrayOfFields");
-
- other_field_item = dlist_get_first(itm_list);
- while (other_field_item != NULL)
+ evel_json_checkpoint(jbuf);
+ ht = event->hashMap;
+ if( ht != NULL )
+ {
+ bool added = false;
+ if( ht->size > 0)
{
- other_field = (OTHER_FIELD *) other_field_item->item;
- EVEL_DEBUG("Encoding other %s %s",(char *)other_field->name,(char*)other_field->value);
- if(other_field != NULL){
- evel_json_open_object(jbuf);
- evel_enc_kv_string(jbuf, "name", other_field->name);
- evel_enc_kv_string(jbuf, "value", other_field->value);
- evel_json_close_object(jbuf);
- other_field_item = dlist_get_next(other_field_item);
- }
- }
- evel_json_close_list(jbuf);
- evel_json_close_object(jbuf);
+ evel_json_checkpoint(jbuf);
+ if (evel_json_open_opt_named_object(jbuf, "hashMap"))
+ {
- }
+ for(unsigned int idx = 0; idx < ht->size; idx++ )
+ {
+ /*****************************************************************/
+ /* Get the first entry of a particular Key and loop through the */
+ /* remaining if any. Then proceed to next key. */
+ /*****************************************************************/
+ entry = ht->table[idx];
+ while( entry != NULL && entry->key != NULL)
+ {
+ EVEL_DEBUG("Encoding Other Fields %s %s",(char *) (entry->key), entry->value);
+ if (!evel_throttle_suppress_nv_pair(jbuf->throttle_spec,
+ "hashMap",
+ entry->key))
+ {
+
+ // evel_json_open_object(jbuf);
+ evel_enc_kv_string(jbuf, entry->key, entry->value);
+ // evel_json_close_object(jbuf);
+ added = true;
+ }
+ entry = entry->next;
+ }
}
- evel_json_close_list(jbuf);
+ evel_json_close_object(jbuf);
+ }
+ }
- } else {
- evel_json_rewind(jbuf);
- }
- }
+ /*************************************************************************/
+ /* If we've not written anything, rewind to before we opened the list. */
+ /*************************************************************************/
+ if (!added)
+ {
+ evel_json_rewind(jbuf);
+ }
+ }
evel_json_checkpoint(jbuf);
if(evel_json_open_opt_named_list(jbuf, "jsonObjects"))
@@ -345,7 +327,7 @@ void evel_json_encode_other(EVEL_JSON_BUFFER * jbuf,
while (other_field_item != NULL)
{
jsonobjp = (EVEL_JSON_OBJECT *) other_field_item->item;
- if(jsonobjp != NULL);
+ if(jsonobjp != NULL) //;
{
evel_json_open_object(jbuf);
@@ -360,11 +342,11 @@ void evel_json_encode_other(EVEL_JSON_BUFFER * jbuf,
{
evel_json_open_object(jbuf);
evel_enc_kv_object(jbuf, "objectInstance", jsonobjinst->jsonstring);
- evel_enc_kv_ull(jbuf, "objectInstanceEpochMicrosec", jsonobjinst->objinst_epoch_microsec);
+ evel_enc_kv_opt_ull(jbuf, "objectInstanceEpochMicrosec", &jsonobjinst->objinst_epoch_microsec);
//evel_json_checkpoint(jbuf);
if (evel_json_open_opt_named_list(jbuf, "objectKeys"))
{
- bool item_added3 = false;
+// bool item_added3 = false;
keyinst_field_item = dlist_get_first(&jsonobjinst->object_keys);
while (keyinst_field_item != NULL)
@@ -377,7 +359,7 @@ void evel_json_encode_other(EVEL_JSON_BUFFER * jbuf,
evel_enc_kv_opt_int(jbuf, "keyOrder", &keyinst->keyorder);
evel_enc_kv_opt_string(jbuf, "keyValue", &keyinst->keyvalue);
evel_json_close_object(jbuf);
- item_added3 = false;
+// item_added3 = false;
}
keyinst_field_item = dlist_get_next(keyinst_field_item);
}
@@ -422,35 +404,67 @@ void evel_json_encode_other(EVEL_JSON_BUFFER * jbuf,
}
+ /***************************************************************************/
+ /* Checkpoint, so that we can wind back if all fields are suppressed. */
+ /***************************************************************************/
evel_json_checkpoint(jbuf);
- if( evel_json_open_opt_named_list(jbuf, "nameValuePairs"))
+ if (evel_json_open_opt_named_list(jbuf, "arrayOfNamedHashMap"))
{
- bool item_added = false;
+ bool added_array = false;
- other_field_item = dlist_get_first(&event->namedvalues);
- while (other_field_item != NULL)
- {
- other_field = (OTHER_FIELD *) other_field_item->item;
- if(other_field != NULL)
+ dlist_item = dlist_get_first(&event->arrayOfNamedHashMap);
+ while (dlist_item != NULL)
{
- evel_json_open_object(jbuf);
- evel_enc_kv_string(jbuf, "name", other_field->name);
- evel_enc_kv_string(jbuf, "value", other_field->value);
- evel_json_close_object(jbuf);
- item_added = true;
+ bool added = false;
+ ht = (HASHTABLE_T *) dlist_item->item;
+ assert(ht != NULL);
+
+ if((ht->size > 0) && (ht-> n > 0))
+ {
+ evel_json_checkpoint(jbuf);
+ evel_json_open_object(jbuf);
+ evel_enc_kv_string(jbuf, "name", ht->hmName);
+ if (evel_json_open_opt_named_object(jbuf, "hashMap"))
+ {
+ for(unsigned int idx = 0; idx < ht->size; idx++ )
+ {
+ /*****************************************************************/
+ /* Get the first entry of a particular Key and loop through the */
+ /* remaining if any. Then proceed to next key. */
+ /*****************************************************************/
+ entry = ht->table[idx];
+ while( entry != NULL && entry->key != NULL)
+ {
+ EVEL_DEBUG("Encoding OtherFields %s %s",(char *) (entry->key), entry->value);
+ if (!evel_throttle_suppress_nv_pair(jbuf->throttle_spec,
+ "arrayOfNamedHashMap",
+ entry->key))
+ {
+ evel_enc_kv_string(jbuf, entry->key, entry->value);
+ added = true;
+ added_array = true;
+ }
+ entry = entry->next;
+ }
+ }
+ evel_json_close_object(jbuf);
+ if (!added)
+ {
+ evel_json_rewind(jbuf);
+ }
+ }
+ evel_json_close_object(jbuf);
+ }
+
+ dlist_item = dlist_get_next(dlist_item);
}
- other_field_item = dlist_get_next(other_field_item);
- }
- evel_json_close_list(jbuf);
- /*************************************************************************/
- /* If we've not written anything, rewind to before we opened the list. */
- /*************************************************************************/
- if (!item_added)
+ evel_json_close_list(jbuf);
+
+ if (!added_array)
{
evel_json_rewind(jbuf);
}
-
}
evel_enc_version(jbuf, "otherFieldsVersion", event->major_version,event->minor_version);
@@ -470,7 +484,8 @@ void evel_json_encode_other(EVEL_JSON_BUFFER * jbuf,
*****************************************************************************/
void evel_free_other(EVENT_OTHER * event)
{
- OTHER_FIELD * other_field = NULL;
+ HASHTABLE_T *ht;
+ EVEL_JSON_OBJECT * jsonobjp = NULL;
EVEL_ENTER();
@@ -484,17 +499,28 @@ void evel_free_other(EVENT_OTHER * event)
/***************************************************************************/
/* Free all internal strings then the header itself. */
/***************************************************************************/
- other_field = dlist_pop_last(&event->namedvalues);
- while (other_field != NULL)
+ ht = event->hashMap;
+ if( ht != NULL )
{
- EVEL_DEBUG("Freeing Other Field (%s, %s)",
- other_field->name,
- other_field->value);
- free(other_field->name);
- free(other_field->value);
- free(other_field);
- other_field = dlist_pop_last(&event->namedvalues);
+ ht_destroy(ht);
}
+
+ ht = dlist_pop_last(&event->arrayOfNamedHashMap);
+ while (ht != NULL)
+ {
+ EVEL_DEBUG("Freeing Other arrayOfNamedHashMap");
+ ht_destroy(ht);
+ ht = dlist_pop_last(&event->arrayOfNamedHashMap);
+ }
+
+ jsonobjp = dlist_pop_last(&event->jsonobjects);
+ while (jsonobjp != NULL)
+ {
+ evel_free_jsonobject( jsonobjp );
+
+ jsonobjp = dlist_pop_last(&event->jsonobjects);
+ }
+
evel_free_header(&event->header);
EVEL_EXIT();