gnunet-svn
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[GNUnet-SVN] r6105 - flightrecorder/src/libflightrecorder


From: gnunet
Subject: [GNUnet-SVN] r6105 - flightrecorder/src/libflightrecorder
Date: Sun, 20 Jan 2008 05:26:05 -0700 (MST)

Author: durner
Date: 2008-01-20 05:26:01 -0700 (Sun, 20 Jan 2008)
New Revision: 6105

Added:
   flightrecorder/src/libflightrecorder/func.c
   flightrecorder/src/libflightrecorder/opt.c
Log:


Added: flightrecorder/src/libflightrecorder/func.c
===================================================================
--- flightrecorder/src/libflightrecorder/func.c                         (rev 0)
+++ flightrecorder/src/libflightrecorder/func.c 2008-01-20 12:26:01 UTC (rev 
6105)
@@ -0,0 +1,54 @@
+/* 
+   libflightrecorder - Client library for flightrecorder, a recorder for
+   runtime information gathered by AOP advices or other process internal
+   checks
+
+   Copyright (C) 2007 Nils Durner
+
+   This library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 2.1 of the License, or (at your option) any later version.
+
+   This library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with this library; if not, write to the Free Software
+   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  
USA
+*/
+
+int fr_func_enter(char *file, unsigned int line, char *function)
+{
+       if (fr_opt_get_int(FR_OPT_RECORD_STACK_TRACE))
+       {
+               if (!fr_st_enter(file, line, function))
+                       return 0;
+       }
+       
+       return 1;
+}
+
+int fr_func_leave(char *file, unsigned int line, char *function)
+{
+       if (fr_opt_get_int(FR_OPT_RECORD_STACK_TRACE))
+       {
+               if (!fr_st_leave(file, line, function))
+                       return 0;
+       }
+       
+       return 1;
+}
+
+int fr_func_add_info(char *info)
+{
+       if (fr_opt_get_int(FR_OPT_RECORD_STACK_TRACE))
+       {
+               if (!fr_st_add_info(info))
+                       return 0;
+       }
+       
+       return 1;
+}

Added: flightrecorder/src/libflightrecorder/opt.c
===================================================================
--- flightrecorder/src/libflightrecorder/opt.c                          (rev 0)
+++ flightrecorder/src/libflightrecorder/opt.c  2008-01-20 12:26:01 UTC (rev 
6105)
@@ -0,0 +1,122 @@
+/* 
+   libflightrecorder - Client library for flightrecorder, a recorder for
+   runtime information gathered by AOP advices or other process internal
+   checks
+
+   Copyright (C) 2007 Nils Durner
+
+   This library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 2.1 of the License, or (at your option) any later version.
+
+   This library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with this library; if not, write to the Free Software
+   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  
USA
+*/
+
+#include <stddef.h>
+#include "flightrecorder.h"
+#include "private.h"
+
+typedef struct
+{
+  unsigned int opt;
+  void *val;
+} Option;
+
+static Option *options = NULL;
+static unsigned long option_count = 0;
+
+int fr_opt_set(const unsigned int opt, const void *val, const unsigned int len)
+{
+       Option *option;
+       unsigned int idx, found;
+       
+       found = 0;
+       option = options;
+       for (idx = 0; idx <= option_count; idx++)
+       {
+               if (opt == option->opt)
+               {
+                       found = 1;
+                       break;
+               }
+       }
+
+       if (!found)
+       {
+               if (option_count == 0)
+                       options = (Option *) fr_malloc(sizeof(Option));
+               else
+                       options = (Option *) fr_realloc(options, (option_count 
+ 1) * sizeof(Option));
+       }
+       
+       if (!options)
+               return 0;
+       
+       option = options + option_count;
+       
+       option->opt = opt;
+       option->val = fr_malloc(len);
+       memcpy(option->val, val);
+       option_count++;
+       
+       return 1;
+}
+
+int fr_opt_set_int(const unsigned int opt, const unsigned int val)
+{
+       return fr_opt_set(opt, &val, sizeof(val));
+}
+
+int fr_opt_set_str(const unsigned int opt, const char *val)
+{
+       return fr_opt_set(opt, val, strlen(val));
+}
+
+const void *fr_opt_get(const unsigned int opt)
+{
+       Option *option;
+       unsigned int idx;
+       
+       option = options;
+       for (idx = 0; idx <= option_count; idx++)
+       {
+               if (opt == option->opt)
+                       return option->val;
+       }
+       
+       return NULL;
+}
+
+const char *fr_opt_get_str(const unsigned int opt)
+{
+       return (const char *) fr_opt_get(opt);
+}
+
+unsigned int fr_opt_get_int(const unsigned int opt)
+{
+       return *((unsigned int) fr_opt_get(opt));
+}
+
+void fr_opt_cleanup()
+{
+       Option *opt;
+       unsigned int idx;
+       
+       opt = options;
+       for (idx = 0; idx <= option_count; idx++)
+       {
+               fr_free(opt->val);
+               opt++;
+       }
+       
+       fr_free(options);
+       options = NULL;
+}





reply via email to

[Prev in Thread] Current Thread [Next in Thread]