os-cmpi-xen

changeset 106:d5331bc6ed99

Added trace function for tracing error descriptions in XenAPI session object.

The trace function uses cmpitrace interface.

Signed-off-by: Jim Fehlig <jfehlig@novell.com>
author Jim Fehlig <jfehlig@novell.com>
date Fri May 11 13:05:27 2007 -0600 (2007-05-11)
parents 05efdeb98072
children 69ad830f2a6e
files src/cmpitrace.h src/xen_utils.c src/xen_utils.h
line diff
     1.1 --- a/src/cmpitrace.h	Thu May 10 16:08:16 2007 -0600
     1.2 +++ b/src/cmpitrace.h	Fri May 11 13:05:27 2007 -0600
     1.3 @@ -64,9 +64,7 @@
     1.4     abort(); } 
     1.5  
     1.6  #define _SBLIM_TRACE_FUNCTION( LEVEL, f ) \
     1.7 -   if ((LEVEL <= _SBLIM_TRACE_LEVEL) && (LEVEL > 0)) { \
     1.8 -      _SBLIM_TRACE(LEVEL,("Calling trace function %f()", #f)); \
     1.9 -      {f;} }
    1.10 +   if ((LEVEL <= _SBLIM_TRACE_LEVEL) && (LEVEL > 0)) { f; }
    1.11  
    1.12  #else /* #ifdef SBLIM_DEBUG */
    1.13  
     2.1 --- a/src/xen_utils.c	Thu May 10 16:08:16 2007 -0600
     2.2 +++ b/src/xen_utils.c	Fri May 11 13:05:27 2007 -0600
     2.3 @@ -739,3 +739,38 @@ char *xen_utils_get_value_from_map(xen_s
     2.4  
     2.5     return NULL;
     2.6  }
     2.7 +
     2.8 +
     2.9 +/*
    2.10 + * Trace the error descriptions found in xen session object.
    2.11 + * This routine uses _sblim_trace function in cmpitrace interface
    2.12 + * for actual tracing.  Output is to a location specified in the
    2.13 + * cmpitrace module.
    2.14 +*/
    2.15 +void xen_utils_trace_error(xen_session *session)
    2.16 +{
    2.17 +   char *msg = (char *)calloc(1, XEN_UTILS_ERROR_BUF_LEN);
    2.18 +   if (msg == NULL)
    2.19 +      return;
    2.20 +
    2.21 +   int ndx;
    2.22 +   for (ndx = 0; ndx < session->error_description_count; ndx++)
    2.23 +   {
    2.24 +      strncat(msg, session->error_description[ndx],
    2.25 +              XEN_UTILS_ERROR_BUF_LEN - (strlen(msg) + 1));
    2.26 +      strncat(msg, " ", XEN_UTILS_ERROR_BUF_LEN - (strlen(msg) + 1));
    2.27 +   }
    2.28 +
    2.29 +   if (msg[0] == '\0') {
    2.30 +      free(msg);
    2.31 +      return;
    2.32 +   }
    2.33 +   
    2.34 +   _sblim_trace(_SBLIM_TRACE_LEVEL_ERROR, __FILE__, __LINE__, msg);
    2.35 +
    2.36 +   /* TODO:
    2.37 +    * msg is freed in _sblim_trace.  The cmpitrace interface needs a little
    2.38 +    * work to remove the freeing in _sblim_trace.  For now, let it free the
    2.39 +    * msg buffer - nothing left to do.
    2.40 +    */
    2.41 +}
     3.1 --- a/src/xen_utils.h	Thu May 10 16:08:16 2007 -0600
     3.2 +++ b/src/xen_utils.h	Fri May 11 13:05:27 2007 -0600
     3.3 @@ -60,6 +60,7 @@ typedef struct {
     3.4  
     3.5  #define XEN_UTILS_ERROR_BUF_LEN   512
     3.6  
     3.7 +
     3.8  /*
     3.9   * Macro for populating a char buffer with error messages contained
    3.10   * in xen session object.
    3.11 @@ -307,10 +308,19 @@ int xen_utils_is_domain_active(xen_utils
    3.12  /*
    3.13   * Extract a value with given key.
    3.14   * Returns pointer to value on success, NULL on failure.
    3.15 - *
    3.16  */
    3.17  char *xen_utils_get_value_from_map(xen_string_string_map *map, const char *key);
    3.18  
    3.19  
    3.20 +/*
    3.21 + * Trace the error descriptions found in xen session object.
    3.22 + * This routine uses _sblim_trace function in cmpitrace interface
    3.23 + * for actual tracing.  Output is to a location specified in the
    3.24 + * cmpitrace module.
    3.25 +*/
    3.26 +void xen_utils_trace_error(xen_session *session);
    3.27 +
    3.28 +
    3.29 +
    3.30  
    3.31  #endif /* __XEN_UTILS_H__ */