diff options
| author | Michael Biebl <biebl@debian.org> | 2011-04-21 10:42:53 +0200 |
|---|---|---|
| committer | Michael Biebl <biebl@debian.org> | 2011-04-21 10:42:53 +0200 |
| commit | 8baa1aca8dfd35e3190d7d5655eb83b5b901e263 (patch) | |
| tree | a9ac1e67d0c22a48330c76f08fc5291f85307055 /libnm-util/nm-utils.h | |
| parent | f75dd6fd1975146623052b843b182dc32c3fbe46 (diff) | |
Imported Upstream version 0.8.4.0 upstream/0.8.4.0
Diffstat (limited to 'libnm-util/nm-utils.h')
| -rw-r--r-- | libnm-util/nm-utils.h | 133 |
1 files changed, 125 insertions, 8 deletions
diff --git a/libnm-util/nm-utils.h b/libnm-util/nm-utils.h index c3eb29bc..6be91793 100644 --- a/libnm-util/nm-utils.h +++ b/libnm-util/nm-utils.h @@ -20,7 +20,7 @@ * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301 USA. * - * (C) Copyright 2005 - 2011 Red Hat, Inc. + * (C) Copyright 2005 - 2010 Red Hat, Inc. */ #ifndef NM_UTILS_H @@ -33,21 +33,138 @@ G_BEGIN_DECLS +/*********************************************************/ +/* The API defined here is _NOT_ guaranteed in any way!! */ +/*********************************************************/ + +/** + * nm_print_backtrace: + * + * Prints a backtrace of the calling process to the logging location. + */ +#define nm_print_backtrace() \ +G_STMT_START \ +{ \ + void *_call_stack[512]; \ + int _call_stack_size; \ + char **_symbols; \ + _call_stack_size = backtrace (_call_stack, \ + G_N_ELEMENTS (_call_stack)); \ + _symbols = backtrace_symbols (_call_stack, _call_stack_size); \ + if (_symbols != NULL) \ + { \ + int _i; \ + _i = 0; \ + g_critical ("traceback:\n"); \ + while (_i < _call_stack_size) \ + { \ + g_critical ("\t%s\n", _symbols[_i]); \ + _i++; \ + } \ + free (_symbols); \ + } \ +} \ +G_STMT_END + +/** + * nm_get_timestamp: + * @timestamp: location in which to place the current timestamp + * + * For debugging only. + */ +#define nm_get_timestamp(timestamp) \ +G_STMT_START \ +{ \ + GTimeVal _tv; \ + g_get_current_time (&_tv); \ + *timestamp = (_tv.tv_sec * (1.0 * G_USEC_PER_SEC) + \ + _tv.tv_usec) / G_USEC_PER_SEC; \ +} \ +G_STMT_END + +#define nm_info(fmt, args...) \ +G_STMT_START \ +{ \ + g_message ("<info> " fmt "\n", ##args); \ +} G_STMT_END + +#define nm_info_str(fmt_str, args...) \ +G_STMT_START \ +{ \ + g_message ("<info> %s\n", fmt_str, ##args); \ +} G_STMT_END + +#define nm_debug(fmt, args...) \ +G_STMT_START \ +{ \ + gdouble _timestamp; \ + nm_get_timestamp (&_timestamp); \ + g_debug ("<debug> [%f] %s(): " fmt "\n", _timestamp, \ + G_STRFUNC, ##args); \ +} G_STMT_END + +#define nm_debug_str(fmt_str, args...) \ +G_STMT_START \ +{ \ + gdouble _timestamp; \ + nm_get_timestamp (&_timestamp); \ + g_debug ("<debug> [%f] %s(): %s\n", _timestamp, \ + G_STRFUNC, fmt_str, ##args); \ +} G_STMT_END + +#define nm_warning(fmt, args...) \ +G_STMT_START \ +{ \ + g_warning ("<WARN> %s(): " fmt "\n", \ + G_STRFUNC, ##args); \ +} G_STMT_END + +#define nm_warning_str(fmt_str, args...) \ +G_STMT_START \ +{ \ + g_warning ("<WARN> %s(): %s\n", \ + G_STRFUNC, fmt_str, ##args); \ +} G_STMT_END + +#define nm_error(fmt, args...) \ +G_STMT_START \ +{ \ + gdouble _timestamp; \ + nm_get_timestamp (&_timestamp); \ + g_critical ("<ERROR>\t[%f] %s (): " fmt "\n", _timestamp, \ + G_STRFUNC, ##args); \ + nm_print_backtrace (); \ + G_BREAKPOINT (); \ +} G_STMT_END + +#define nm_error_str(fmt_str, args...) \ +G_STMT_START \ +{ \ + gdouble _timestamp; \ + nm_get_timestamp (&_timestamp); \ + g_critical ("<ERROR>\t[%f] %s (): %s\n", _timestamp, \ + G_STRFUNC, fmt_str, ##args); \ + nm_print_backtrace (); \ + G_BREAKPOINT (); \ +} G_STMT_END + /* init, deinit nm_utils */ gboolean nm_utils_init (GError **error); void nm_utils_deinit (void); /* SSID helpers */ -gboolean nm_utils_is_empty_ssid (const guint8 *ssid, int len); -const char *nm_utils_escape_ssid (const guint8 *ssid, guint32 len); -gboolean nm_utils_same_ssid (const GByteArray *ssid1, - const GByteArray *ssid2, - gboolean ignore_trailing_null); -char * nm_utils_ssid_to_utf8 (const GByteArray *ssid); +gboolean nm_utils_is_empty_ssid (const guint8 * ssid, int len); +const char *nm_utils_escape_ssid (const guint8 *ssid, guint32 len); +gboolean nm_utils_same_ssid (const GByteArray * ssid1, + const GByteArray * ssid2, + gboolean ignore_trailing_null); + +char *nm_utils_ssid_to_utf8 (const char *ssid, guint32 len); GHashTable *nm_utils_gvalue_hash_dup (GHashTable *hash); -void nm_utils_slist_free (GSList *list, GDestroyNotify elem_destroy_fn); +void nm_utils_slist_free (GSList *list, + GDestroyNotify elem_destroy_fn); typedef enum { NMU_SEC_INVALID = 0, |