code clean up
[oweals/gnunet.git] / src / statistics / statistics_api.c
index f68cf9396286e071f8497bceeee0b640602af644..26e2425e60298d9332d08498c5d3b65a47d5921b 100644 (file)
@@ -131,7 +131,7 @@ struct GNUNET_STATISTICS_Handle
   /**
    * Configuration to use.
    */
-  struct GNUNET_CONFIGURATION_Handle *cfg;
+  const struct GNUNET_CONFIGURATION_Handle *cfg;
 
   /**
    * Socket (if available).
@@ -178,8 +178,10 @@ try_connect (struct GNUNET_STATISTICS_Handle *ret)
   ret->client = GNUNET_CLIENT_connect (ret->sched, "statistics", ret->cfg);
   if (ret->client != NULL)
     return GNUNET_YES;
-  GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+#if DEBUG_STATISTICS
+  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
               _("Failed to connect to statistics service!\n"));
+#endif
   return GNUNET_NO;
 }
 
@@ -206,7 +208,7 @@ free_action_item (struct ActionItem *ai)
 struct GNUNET_STATISTICS_Handle *
 GNUNET_STATISTICS_create (struct GNUNET_SCHEDULER_Handle *sched,
                           const char *subsystem,
-                          struct GNUNET_CONFIGURATION_Handle *cfg)
+                          const struct GNUNET_CONFIGURATION_Handle *cfg)
 {
   struct GNUNET_STATISTICS_Handle *ret;
 
@@ -347,9 +349,10 @@ receive_stats (void *cls, const struct GNUNET_MessageHeader *msg)
     {
       GNUNET_CLIENT_disconnect (h->client);
       h->client = NULL;
-      GNUNET_log (GNUNET_ERROR_TYPE_WARNING | GNUNET_ERROR_TYPE_BULK,
-                  _
-                  ("Error receiving statistics from service, is the service running?\n"));
+#if DEBUG_STATISTICS
+      GNUNET_log (GNUNET_ERROR_TYPE_DEBUG | GNUNET_ERROR_TYPE_BULK,
+                 "Error receiving statistics from service, is the service running?\n" );
+#endif
       finish (h, GNUNET_SYSERR);
       return;
     }
@@ -369,9 +372,8 @@ receive_stats (void *cls, const struct GNUNET_MessageHeader *msg)
           GNUNET_CLIENT_receive (h->client,
                                  &receive_stats,
                                  h,
-                                 GNUNET_TIME_absolute_get_remaining (h->
-                                                                     current->
-                                                                     timeout));
+                                 GNUNET_TIME_absolute_get_remaining
+                                 (h->current->timeout));
           return;
         }
       GNUNET_break (0);
@@ -401,8 +403,10 @@ transmit_get (struct GNUNET_STATISTICS_Handle *handle, size_t size, void *buf)
   if (buf == NULL)
     {
       /* timeout / error */
-      GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
-                  _("Transmission of request for statistics failed!\n"));
+#if DEBUG_STATISTICS
+      GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+                  "Transmission of request for statistics failed!\n");
+#endif
       finish (handle, GNUNET_SYSERR);
       return 0;
     }
@@ -422,8 +426,8 @@ transmit_get (struct GNUNET_STATISTICS_Handle *handle, size_t size, void *buf)
   GNUNET_CLIENT_receive (handle->client,
                          &receive_stats,
                          handle,
-                         GNUNET_TIME_absolute_get_remaining (handle->current->
-                                                             timeout));
+                         GNUNET_TIME_absolute_get_remaining (handle->
+                                                             current->timeout));
   return msize;
 }
 
@@ -490,6 +494,10 @@ transmit_action (void *cls, size_t size, void *buf)
     case ACTION_UPDATE:
       ret = transmit_set (handle, size, buf);
       break;
+    default:
+      ret = 0;
+      GNUNET_break (0);
+      break; 
     }
   return ret;
 }
@@ -532,8 +540,10 @@ schedule_action (struct GNUNET_STATISTICS_Handle *h)
                                            h->current->msize,
                                            timeout, &transmit_action, h))
     {
-      GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+#if DEBUG_STATISTICS
+      GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
                   "Failed to transmit request to statistics service.\n");
+#endif
       finish (h, GNUNET_SYSERR);
     }
 }
@@ -584,11 +594,14 @@ GNUNET_STATISTICS_get (struct GNUNET_STATISTICS_Handle *handle,
   GNUNET_assert (proc != NULL);
   if (GNUNET_YES != try_connect (handle))
     {
-      GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+#if DEBUG_STATISTICS
+      GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
                   "Failed to connect to statistics service, can not get value `%s:%s'.\n",
                   strlen (subsystem) ? subsystem : "*",
                   strlen (name) ? name : "*");
-      cont (cls, GNUNET_SYSERR);
+#endif
+      if (cont != NULL)
+       cont (cls, GNUNET_SYSERR);
       return;
     }
   if (subsystem == NULL)