[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[GNUnet-SVN] r18704 - in gnunet/src: include statistics
From: |
gnunet |
Subject: |
[GNUnet-SVN] r18704 - in gnunet/src: include statistics |
Date: |
Mon, 19 Dec 2011 22:26:34 +0100 |
Author: grothoff
Date: 2011-12-19 22:26:34 +0100 (Mon, 19 Dec 2011)
New Revision: 18704
Modified:
gnunet/src/include/gnunet_statistics_service.h
gnunet/src/statistics/statistics_api.c
Log:
implement watch_cancel function
Modified: gnunet/src/include/gnunet_statistics_service.h
===================================================================
--- gnunet/src/include/gnunet_statistics_service.h 2011-12-19 21:04:43 UTC
(rev 18703)
+++ gnunet/src/include/gnunet_statistics_service.h 2011-12-19 21:26:34 UTC
(rev 18704)
@@ -91,8 +91,6 @@
/**
* Watch statistics from the peer (be notified whenever they change).
- * Note that the only way to cancel a "watch" request is to destroy
- * the statistics handle given as the first argument to this call.
*
* @param handle identification of the statistics service
* @param subsystem limit to the specified subsystem, never NULL
@@ -108,6 +106,22 @@
/**
+ * Stop watching statistics from the peer.
+ *
+ * @param handle identification of the statistics service
+ * @param subsystem limit to the specified subsystem, never NULL
+ * @param name name of the statistic value, never NULL
+ * @param proc function to call on each value
+ * @param proc_cls closure for proc
+ * @return GNUNET_OK on success, GNUNET_SYSERR on error (no such watch)
+ */
+int
+GNUNET_STATISTICS_watch_cancel (struct GNUNET_STATISTICS_Handle *handle,
+ const char *subsystem, const char *name,
+ GNUNET_STATISTICS_Iterator proc, void
*proc_cls);
+
+
+/**
* Continuation called by the "get_all" and "get" functions.
*
* @param cls closure
@@ -116,6 +130,7 @@
*/
typedef void (*GNUNET_STATISTICS_Callback) (void *cls, int success);
+
/**
* Handle that can be used to cancel a statistics 'get' operation.
*/
Modified: gnunet/src/statistics/statistics_api.c
===================================================================
--- gnunet/src/statistics/statistics_api.c 2011-12-19 21:04:43 UTC (rev
18703)
+++ gnunet/src/statistics/statistics_api.c 2011-12-19 21:26:34 UTC (rev
18704)
@@ -492,7 +492,8 @@
*
* @param h statistics handle
* @param msg the watch value message
- * @return GNUNET_OK if the message was well-formed, GNUNET_SYSERR if not
+ * @return GNUNET_OK if the message was well-formed, GNUNET_SYSERR if not,
+ * GNUNET_NO if this watch has been cancelled
*/
static int
process_watch_value (struct GNUNET_STATISTICS_Handle *h,
@@ -516,6 +517,8 @@
return GNUNET_SYSERR;
}
w = h->watches[wid];
+ if (NULL == w)
+ return GNUNET_NO;
(void) w->proc (w->proc_cls, w->subsystem, w->name,
GNUNET_ntohll (wvm->value),
0 != (ntohl (wvm->flags) & GNUNET_STATISTICS_PERSIST_BIT));
@@ -534,7 +537,7 @@
{
struct GNUNET_STATISTICS_Handle *h = cls;
struct GNUNET_STATISTICS_GetHandle *c;
-
+ int ret;
if (msg == NULL)
{
@@ -594,9 +597,11 @@
return;
case GNUNET_MESSAGE_TYPE_STATISTICS_WATCH_VALUE:
if (GNUNET_OK !=
- process_watch_value (h, msg))
+ (ret = process_watch_value (h, msg)))
{
do_disconnect (h);
+ if (GNUNET_NO == ret)
+ h->backoff = GNUNET_TIME_UNIT_MILLISECONDS;
reconnect_later (h);
return;
}
@@ -1076,8 +1081,6 @@
/**
* Watch statistics from the peer (be notified whenever they change).
- * Note that the only way to cancel a "watch" request is to destroy
- * the statistics handle given as the first argument to this call.
*
* @param handle identification of the statistics service
* @param subsystem limit to the specified subsystem, never NULL
@@ -1107,6 +1110,46 @@
/**
+ * Stop watching statistics from the peer.
+ *
+ * @param handle identification of the statistics service
+ * @param subsystem limit to the specified subsystem, never NULL
+ * @param name name of the statistic value, never NULL
+ * @param proc function to call on each value
+ * @param proc_cls closure for proc
+ * @return GNUNET_OK on success, GNUNET_SYSERR on error (no such watch)
+ */
+int
+GNUNET_STATISTICS_watch_cancel (struct GNUNET_STATISTICS_Handle *handle,
+ const char *subsystem, const char *name,
+ GNUNET_STATISTICS_Iterator proc, void *proc_cls)
+{
+ struct GNUNET_STATISTICS_WatchEntry *w;
+ unsigned int i;
+
+ if (handle == NULL)
+ return GNUNET_SYSERR;
+ for (i=0;i<handle->watches_size;i++)
+ {
+ w = handle->watches[i];
+ if ( (w->proc == proc) &&
+ (w->proc_cls == proc_cls) &&
+ (0 == strcmp (w->name, name)) &&
+ (0 == strcmp (w->subsystem, subsystem)) )
+ {
+ GNUNET_free (w->name);
+ GNUNET_free (w->subsystem);
+ GNUNET_free (w);
+ handle->watches[i] = NULL;
+ return GNUNET_OK;
+ }
+ }
+ return GNUNET_SYSERR;
+}
+
+
+
+/**
* Queue a request to change a statistic.
*
* @param h statistics handle
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [GNUnet-SVN] r18704 - in gnunet/src: include statistics,
gnunet <=