diff options
author | Christian Grothoff <christian@grothoff.org> | 2011-12-19 21:26:34 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2011-12-19 21:26:34 +0000 |
commit | 3d08414cb6729815c74c895ff6f7b36c4e954989 (patch) | |
tree | 09bb981ec10693fa16bd6d7fe46eae5f318740fa /src/statistics | |
parent | 158c660519935bdec0a17310d79ea5a71eb6913e (diff) | |
download | gnunet-3d08414cb6729815c74c895ff6f7b36c4e954989.tar.gz gnunet-3d08414cb6729815c74c895ff6f7b36c4e954989.zip |
implement watch_cancel function
Diffstat (limited to 'src/statistics')
-rw-r--r-- | src/statistics/statistics_api.c | 53 |
1 files changed, 48 insertions, 5 deletions
diff --git a/src/statistics/statistics_api.c b/src/statistics/statistics_api.c index 8335e9e0c..c30279e71 100644 --- a/src/statistics/statistics_api.c +++ b/src/statistics/statistics_api.c | |||
@@ -492,7 +492,8 @@ process_statistics_value_message (struct GNUNET_STATISTICS_Handle *h, | |||
492 | * | 492 | * |
493 | * @param h statistics handle | 493 | * @param h statistics handle |
494 | * @param msg the watch value message | 494 | * @param msg the watch value message |
495 | * @return GNUNET_OK if the message was well-formed, GNUNET_SYSERR if not | 495 | * @return GNUNET_OK if the message was well-formed, GNUNET_SYSERR if not, |
496 | * GNUNET_NO if this watch has been cancelled | ||
496 | */ | 497 | */ |
497 | static int | 498 | static int |
498 | process_watch_value (struct GNUNET_STATISTICS_Handle *h, | 499 | process_watch_value (struct GNUNET_STATISTICS_Handle *h, |
@@ -516,6 +517,8 @@ process_watch_value (struct GNUNET_STATISTICS_Handle *h, | |||
516 | return GNUNET_SYSERR; | 517 | return GNUNET_SYSERR; |
517 | } | 518 | } |
518 | w = h->watches[wid]; | 519 | w = h->watches[wid]; |
520 | if (NULL == w) | ||
521 | return GNUNET_NO; | ||
519 | (void) w->proc (w->proc_cls, w->subsystem, w->name, | 522 | (void) w->proc (w->proc_cls, w->subsystem, w->name, |
520 | GNUNET_ntohll (wvm->value), | 523 | GNUNET_ntohll (wvm->value), |
521 | 0 != (ntohl (wvm->flags) & GNUNET_STATISTICS_PERSIST_BIT)); | 524 | 0 != (ntohl (wvm->flags) & GNUNET_STATISTICS_PERSIST_BIT)); |
@@ -534,7 +537,7 @@ receive_stats (void *cls, const struct GNUNET_MessageHeader *msg) | |||
534 | { | 537 | { |
535 | struct GNUNET_STATISTICS_Handle *h = cls; | 538 | struct GNUNET_STATISTICS_Handle *h = cls; |
536 | struct GNUNET_STATISTICS_GetHandle *c; | 539 | struct GNUNET_STATISTICS_GetHandle *c; |
537 | 540 | int ret; | |
538 | 541 | ||
539 | if (msg == NULL) | 542 | if (msg == NULL) |
540 | { | 543 | { |
@@ -594,9 +597,11 @@ receive_stats (void *cls, const struct GNUNET_MessageHeader *msg) | |||
594 | return; | 597 | return; |
595 | case GNUNET_MESSAGE_TYPE_STATISTICS_WATCH_VALUE: | 598 | case GNUNET_MESSAGE_TYPE_STATISTICS_WATCH_VALUE: |
596 | if (GNUNET_OK != | 599 | if (GNUNET_OK != |
597 | process_watch_value (h, msg)) | 600 | (ret = process_watch_value (h, msg))) |
598 | { | 601 | { |
599 | do_disconnect (h); | 602 | do_disconnect (h); |
603 | if (GNUNET_NO == ret) | ||
604 | h->backoff = GNUNET_TIME_UNIT_MILLISECONDS; | ||
600 | reconnect_later (h); | 605 | reconnect_later (h); |
601 | return; | 606 | return; |
602 | } | 607 | } |
@@ -1076,8 +1081,6 @@ GNUNET_STATISTICS_get_cancel (struct GNUNET_STATISTICS_GetHandle *gh) | |||
1076 | 1081 | ||
1077 | /** | 1082 | /** |
1078 | * Watch statistics from the peer (be notified whenever they change). | 1083 | * Watch statistics from the peer (be notified whenever they change). |
1079 | * Note that the only way to cancel a "watch" request is to destroy | ||
1080 | * the statistics handle given as the first argument to this call. | ||
1081 | * | 1084 | * |
1082 | * @param handle identification of the statistics service | 1085 | * @param handle identification of the statistics service |
1083 | * @param subsystem limit to the specified subsystem, never NULL | 1086 | * @param subsystem limit to the specified subsystem, never NULL |
@@ -1107,6 +1110,46 @@ GNUNET_STATISTICS_watch (struct GNUNET_STATISTICS_Handle *handle, | |||
1107 | 1110 | ||
1108 | 1111 | ||
1109 | /** | 1112 | /** |
1113 | * Stop watching statistics from the peer. | ||
1114 | * | ||
1115 | * @param handle identification of the statistics service | ||
1116 | * @param subsystem limit to the specified subsystem, never NULL | ||
1117 | * @param name name of the statistic value, never NULL | ||
1118 | * @param proc function to call on each value | ||
1119 | * @param proc_cls closure for proc | ||
1120 | * @return GNUNET_OK on success, GNUNET_SYSERR on error (no such watch) | ||
1121 | */ | ||
1122 | int | ||
1123 | GNUNET_STATISTICS_watch_cancel (struct GNUNET_STATISTICS_Handle *handle, | ||
1124 | const char *subsystem, const char *name, | ||
1125 | GNUNET_STATISTICS_Iterator proc, void *proc_cls) | ||
1126 | { | ||
1127 | struct GNUNET_STATISTICS_WatchEntry *w; | ||
1128 | unsigned int i; | ||
1129 | |||
1130 | if (handle == NULL) | ||
1131 | return GNUNET_SYSERR; | ||
1132 | for (i=0;i<handle->watches_size;i++) | ||
1133 | { | ||
1134 | w = handle->watches[i]; | ||
1135 | if ( (w->proc == proc) && | ||
1136 | (w->proc_cls == proc_cls) && | ||
1137 | (0 == strcmp (w->name, name)) && | ||
1138 | (0 == strcmp (w->subsystem, subsystem)) ) | ||
1139 | { | ||
1140 | GNUNET_free (w->name); | ||
1141 | GNUNET_free (w->subsystem); | ||
1142 | GNUNET_free (w); | ||
1143 | handle->watches[i] = NULL; | ||
1144 | return GNUNET_OK; | ||
1145 | } | ||
1146 | } | ||
1147 | return GNUNET_SYSERR; | ||
1148 | } | ||
1149 | |||
1150 | |||
1151 | |||
1152 | /** | ||
1110 | * Queue a request to change a statistic. | 1153 | * Queue a request to change a statistic. |
1111 | * | 1154 | * |
1112 | * @param h statistics handle | 1155 | * @param h statistics handle |