stuff
authorChristian Grothoff <christian@grothoff.org>
Fri, 14 Oct 2011 08:13:38 +0000 (08:13 +0000)
committerChristian Grothoff <christian@grothoff.org>
Fri, 14 Oct 2011 08:13:38 +0000 (08:13 +0000)
src/ats/gnunet-service-ats_performance.c
src/ats/gnunet-service-ats_performance.h

index a0062ab7ad44b2b05e07883ecedc4096c241fb44..f68b1b8aeb5b73630cbbecf6c6517a2dd7a17a1d 100644 (file)
 #include "ats.h"
 
 
+/**
+ * We keep clients that are interested in performance notifications in a linked list.
+ * Note that not ALL clients that are handeled by this module also register for
+ * notifications.  Only those clients that are in this list are managed by the
+ * notification context.
+ */
 struct PerformanceClient
 {
+  /**
+   * Next in doubly-linked list.
+   */
   struct PerformanceClient * next;
 
+  /**
+   * Previous in doubly-linked list.
+   */
   struct PerformanceClient * prev;
-
+  
+  /**
+   * Actual handle to the client.
+   */
   struct GNUNET_SERVER_Client *client;
 
 };
@@ -50,7 +65,18 @@ static struct PerformanceClient *pc_head;
  */
 static struct PerformanceClient *pc_tail;
  
+/**
+ * Context for sending messages to performance clients.
+ */
+static struct GNUNET_SERVER_NotificationContext *nc;
+
 
+/**
+ * Find the performance client associated with the given handle.
+ *
+ * @param client server handle
+ * @return internal handle
+ */
 static struct PerformanceClient * 
 find_client (struct GNUNET_SERVER_Client *client)
 {
@@ -63,6 +89,11 @@ find_client (struct GNUNET_SERVER_Client *client)
 }
 
 
+/**
+ * Register a new performance client.
+ *
+ * @param client handle of the new client
+ */
 void
 GAS_performance_add_client (struct GNUNET_SERVER_Client *client)
 {
@@ -71,10 +102,18 @@ GAS_performance_add_client (struct GNUNET_SERVER_Client *client)
   GNUNET_break (NULL == find_client (client));
   pc = GNUNET_malloc (sizeof (struct PerformanceClient));
   pc->client = client;
+  GNUNET_SERVER_notification_context_add (nc, client);
+  GNUNET_SERVER_client_keep (client);
   GNUNET_CONTAINER_DLL_insert(pc_head, pc_tail, pc);
 }
 
 
+/**
+ * Unregister a client (which may have been a performance client,
+ * but this is not assured).
+ *
+ * @param client handle of the (now dead) client
+ */
 void
 GAS_performance_remove_client (struct GNUNET_SERVER_Client *client)
 {
@@ -91,22 +130,46 @@ GAS_performance_remove_client (struct GNUNET_SERVER_Client *client)
 
 void
 GAS_handle_reservation_request (void *cls, struct GNUNET_SERVER_Client *client,
-                      const struct GNUNET_MessageHeader *message)
-
+                               const struct GNUNET_MessageHeader *message)
 {
-  // struct AddressUpdateMessage * msg = (struct AddressUpdateMessage *) message;
+  // const struct ReservationRequestMessage * msg = (const struct ReservationRequestMessage *) message;
   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received `%s' message\n", "RESERVATION_REQUEST");
+
 }
 
 
 void
 GAS_handle_preference_change (void *cls, struct GNUNET_SERVER_Client *client,
-                      const struct GNUNET_MessageHeader *message)
+                             const struct GNUNET_MessageHeader *message)
 
 {
-  // struct ChangePreferenceMessage * msg = (struct ChangePreferenceMessage *) message;
+  // const struct ChangePreferenceMessage * msg = (const struct ChangePreferenceMessage *) message;
   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received `%s' message\n", "PREFERENCE_CHANGE");
+  // FIXME: implement later (we can safely ignore these for now)
+  GNUNET_SERVER_receive_done (client, GNUNET_OK);
 }
 
 
+/**
+ * Initialize performance subsystem.
+ *
+ * @param server handle to our server
+ */
+void
+GAS_performance_init (struct GNUNET_SERVER_Handle *server)
+{
+  nc = GNUNET_SERVER_notification_context_create (server, 128);
+}
+
+
+/**
+ * Shutdown performance subsystem.
+ */
+void
+GAS_performance_done ()
+{
+  GNUNET_SERVER_notification_context_destroy (nc);
+  nc = NULL;
+}
+
 /* end of gnunet-service-ats_performance.c */
index cb6677f5b36d66426ba5cc258023d01d24881bc3..e3a5aa394a6c145ad2432fa9281e185a73932432 100644 (file)
 
 #include "gnunet_util_lib.h"
 
+/**
+ * Register a new performance client.
+ *
+ * @param client handle of the new client
+ */
 void
 GAS_performance_add_client (struct GNUNET_SERVER_Client *client);
 
 
+/**
+ * Unregister a client (which may have been a performance client,
+ * but this is not assured).
+ *
+ * @param client handle of the (now dead) client
+ */
 void
 GAS_performance_remove_client (struct GNUNET_SERVER_Client *client);
 
@@ -47,5 +58,21 @@ GAS_handle_preference_change (void *cls, struct GNUNET_SERVER_Client *client,
                              const struct GNUNET_MessageHeader *message);
 
 
+/**
+ * Initialize performance subsystem.
+ *
+ * @param server handle to our server
+ */
+void
+GAS_performance_init (struct GNUNET_SERVER_Handle *server);
+
+
+/**
+ * Shutdown performance subsystem.
+ */
+void
+GAS_performance_done (void);
+
+
 #endif
 /* end of gnunet-service-ats_performance.h */