From ef8d8570dcf44d723868df339223b132b19121c3 Mon Sep 17 00:00:00 2001 From: Dmitri Pal Date: Tue, 24 Feb 2009 13:39:26 -0500 Subject: Changed tree. Added all folders to build. --- collection/elapi_debug.h | 35 +++++++++ collection/elapi_tools.c | 192 +++++++++++++++++++++++++++++++++++++++++++++++ collection/elapi_tools.h | 27 +++++++ 3 files changed, 254 insertions(+) create mode 100644 collection/elapi_debug.h create mode 100644 collection/elapi_tools.c create mode 100644 collection/elapi_tools.h (limited to 'collection') diff --git a/collection/elapi_debug.h b/collection/elapi_debug.h new file mode 100644 index 0000000..3da0685 --- /dev/null +++ b/collection/elapi_debug.h @@ -0,0 +1,35 @@ +/* Copyright */ + +#ifndef ELAPI_DEBUG_H +#define ELAPI_DEBUG_H + +#ifdef ELAPI_LOG_DEBUG +#include +#endif + +#ifdef ELAPI_LOG_DEBUG +#define DEBUG_STRING(message,str) printf("[DEBUG] %23s (%4d) %s %s\n",__FILE__,__LINE__,message,str); +#else +#define DEBUG_STRING(message,str) ; +#endif + +#ifdef ELAPI_LOG_DEBUG +#define DEBUG_NUMBER(message,number) printf("[DEBUG] %23s (%4d) %s %lu\n",__FILE__,__LINE__,message,(unsigned long int)(number)); +#else +#define DEBUG_NUMBER(message,number) ; +#endif + +#ifdef ELAPI_LOG_DEBUG +#define DEBUG_DOUBLE(message,number) printf("[DEBUG] %23s (%4d) %s %e\n",__FILE__,__LINE__,message,(double)(number)); +#else +#define DEBUG_DOUBLE(message,number) ; +#endif + +#ifdef ELAPI_LOG_DEBUG +#define DEBUG_ASSERT(expression) expression ? ; : printf("ASSERTION FAILED\n"); +#else +#define DEBUG_ASSERT(expression) ; +#endif + + +#endif diff --git a/collection/elapi_tools.c b/collection/elapi_tools.c new file mode 100644 index 0000000..d1d00c0 --- /dev/null +++ b/collection/elapi_tools.c @@ -0,0 +1,192 @@ +/* Copyright */ + +#include +#include +#include "elapi_collection.h" +#include "elapi_debug.h" +#include "elapi_util.h" +#include "elapi_tools.h" + +/* Debug handle */ +int debug_handle(char *property, + int property_len, + int type, + void *data, + int length, + void *custom_data, + int *dummy) +{ + int i; + int nest_level; + + DEBUG_STRING("debug_handle","Entry."); + + + nest_level = *(int *)(custom_data); + DEBUG_NUMBER("We are getting this pointer:",custom_data); + DEBUG_NUMBER("Nest level:",nest_level); + + switch(type) { + case ELAPI_TYPE_STRING: + printf("%*s %s[%d] str: %s (%d)\n", + (nest_level-1)*4,"", + property, + length, + (char *)(data), + (int)(nest_level)); + break; + case ELAPI_TYPE_BINARY: + printf("%*s %s[%d] bin: ", + (nest_level-1)*4,"", + property, + length); + for(i=0;icount, + ((struct collection_header *)(data))->reference_count); + for(i=0;iproperty); + + flag |= ELAPI_TRAVERSE_END; + + printf("Traverse flags %d\n",flag); + + /* Traverse collection */ + error = traverse_collection(handle,flag,debug_handle,(void *)(&nest_level)); + if(error) printf("Error debuging collection %d\n",error); + + DEBUG_STRING("debug_collection","Exit."); + return error; +} + +/* Print the collection using default serialization */ +int print_collection(struct collection_item *handle) +{ + struct serial_data buf_data; + int error = EOK; + + printf("COLLECTION:\n"); + + buf_data.buffer=NULL; + buf_data.length=0; + buf_data.size=0; + buf_data.nest_level=0; + + /* Traverse collection */ + error = traverse_collection(handle,ELAPI_TRAVERSE_DEFAULT | ELAPI_TRAVERSE_END ,serialize,(void *)(&buf_data)); + if(error) printf("Error traversing collection %d\n",error); + else printf("%s\n",buf_data.buffer); + + free(buf_data.buffer); + + return error; +} + + +/* Find and print one item using default serialization */ +int print_item(struct collection_item *handle, char *name) +{ + struct serial_data buf_data; + int error = EOK; + + printf("FIND ITEM:\n"); + + buf_data.buffer=NULL; + buf_data.length=0; + buf_data.size=0; + buf_data.nest_level=0; + + error = get_item_and_do(handle, name, ELAPI_TYPE_ANY,ELAPI_TRAVERSE_DEFAULT, serialize,&buf_data); + if(error) printf("Error searching collection %d\n",error); + else { + if(buf_data.buffer != NULL) { + if(buf_data.length> 0) buf_data.length--; + *(buf_data.buffer+buf_data.length)= '\0', + printf("%s\n",buf_data.buffer); + free(buf_data.buffer); + } + else printf("Name %s is not found in the collection %s.\n",name,handle->property); + } + return error; +} + + diff --git a/collection/elapi_tools.h b/collection/elapi_tools.h new file mode 100644 index 0000000..fd9bf63 --- /dev/null +++ b/collection/elapi_tools.h @@ -0,0 +1,27 @@ +/* Copyright */ + +#ifndef ELAPI_TOOLS_H +#define ELAPI_TOOLS_H + +#include "elapi_collection.h" + +/* Debug handle */ +int debug_handle(char *property, + int property_len, + int type, + void *data, + int length, + void *custom_data, + int *dummy); + +/* Print collection for debugging purposes */ +int debug_collection(struct collection_item *handle,int flag); + +/* Print the collection using default serialization */ +int print_collection(struct collection_item *handle); + + +/* Find and print one item using default serialization */ +int print_item(struct collection_item *handle, char *name); + +#endif -- cgit