kstats_wrapper.h

Go to the documentation of this file.
00001 /* 
00002  * $Id$
00003  * 
00004  * Copyright (C) 2010 iptelorg GmbH
00005  *
00006  * Permission to use, copy, modify, and distribute this software for any
00007  * purpose with or without fee is hereby granted, provided that the above
00008  * copyright notice and this permission notice appear in all copies.
00009  *
00010  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
00011  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
00012  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
00013  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
00014  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
00015  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
00016  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
00017  */
00034 /*
00035  * History:
00036  * --------
00037  *  2010-08-08  initial version (andrei)
00038  *  2010-08-18  type declaration needed by sr_module.c moved to
00039  *               ../../kstats_types.h (andrei)
00040 */
00041 
00042 #ifndef __kstats_wrapper_h
00043 #define __kstats_wrapper_h
00044 
00045 #include "../../counters.h"
00046 #include "../../kstats_types.h"
00047 
00048 /* k stat flags */
00049 #define STAT_NO_RESET   1  /* used in dialog(k), nat_traversal(k),
00050                                                           registrar(k), statistics(k), usrloc(k) */
00051 /* #define STAT_NO_SYN  2  -- not used */
00052 #define STAT_SHM_NAME   4 /* used only from usrloc(k) */
00053 #define STAT_IS_FUNC    8
00054 
00055 
00056 
00057 #ifdef STATISTICS
00058 
00059 /* statistics support check */
00060 #define stats_support() 1
00061 
00062 int register_stat( char *module, char *name, stat_var **pvar, int flags);
00063 int register_module_stats(char *module, stat_export_t *stats);
00064 
00065 inline static stat_var* get_stat(str *name)
00066 {
00067         counter_handle_t h;
00068         str grp;
00069         
00070         grp.s = 0;
00071         grp.len = 0;
00072         if (counter_lookup_str(&h, &grp, name) < 0)
00073                 return 0;
00074         return (void*)(unsigned long)h.id;
00075 }
00076 
00077 
00078 
00079 inline static unsigned long get_stat_val(stat_var *v)
00080 {
00081         counter_handle_t h;
00082         h.id = (unsigned short)(unsigned long)v;
00083         return (unsigned long)counter_get_val(h);
00084 }
00085 
00086 
00087 
00088 inline static char* get_stat_name(stat_var *v)
00089 {
00090         counter_handle_t h;
00091         h.id = (unsigned short)(unsigned long)v;
00092         return counter_get_name(h);
00093 }
00094 
00095 
00096 
00097 inline static char* get_stat_module(stat_var *v)
00098 {
00099         counter_handle_t h;
00100         h.id = (unsigned short)(unsigned long)v;
00101         return counter_get_group(h);
00102 }
00103 
00104 
00105 
00106 inline static void update_stat(stat_var* v, int n)
00107 {
00108         counter_handle_t h;
00109         h.id = (unsigned short)(unsigned long)v;
00110         counter_add(h, n);
00111 }
00112 
00113 
00114 
00115 inline static void reset_stat(stat_var* v)
00116 {
00117         counter_handle_t h;
00118         h.id = (unsigned short)(unsigned long)v;
00119         counter_reset(h);
00120 }
00121 
00122 
00123 #define if_update_stat(c, var, n) \
00124         do{ \
00125                 if ((c)) update_stat((var), (n)); \
00126         }while(0)
00127 
00128 #define if_reset_stat(c, var) \
00129         do{ \
00130                 if ((c)) reset_stat((var)); \
00131         }while(0)
00132 
00133 #else /* STATISTICS */
00134 
00135 /* statistics support check */
00136 #define stats_support() 0
00137 #define register_module_stats(mod, stats) 0
00138 #define register_stat(mod, name, var, flags) 0
00139 #define get_stat(name)  0
00140 #define get_stat_val(var) 0
00141 #define update_stat(v, n)
00142 #define reset_stat(v)
00143 #define if_update_stat(c, v, n)
00144 #define if_reset_stat(c, v)
00145 
00146 #endif /* STATISTICS */
00147 
00148 #endif /*__kstats_wrapper_h*/
00149 
00150 /* vi: set ts=4 sw=4 tw=79:ai:cindent: */