2 This file is part of GNUnet.
3 (C) 2011 Christian Grothoff (and other contributing authors)
5 GNUnet is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published
7 by the Free Software Foundation; either version 3, or (at your
8 option) any later version.
10 GNUnet is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with GNUnet; see the file COPYING. If not, write to the
17 Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA.
22 * @file ats/gnunet-service-ats_performance.c
23 * @brief ats service, interaction with 'performance' API
24 * @author Matthias Wachs
25 * @author Christian Grothoff
28 #include "gnunet-service-ats_performance.h"
33 * We keep clients that are interested in performance notifications in a linked list.
34 * Note that not ALL clients that are handeled by this module also register for
35 * notifications. Only those clients that are in this list are managed by the
36 * notification context.
38 struct PerformanceClient
41 * Next in doubly-linked list.
43 struct PerformanceClient * next;
46 * Previous in doubly-linked list.
48 struct PerformanceClient * prev;
51 * Actual handle to the client.
53 struct GNUNET_SERVER_Client *client;
59 * Head of linked list of all clients to this service.
61 static struct PerformanceClient *pc_head;
64 * Tail of linked list of all clients to this service.
66 static struct PerformanceClient *pc_tail;
69 * Context for sending messages to performance clients.
71 static struct GNUNET_SERVER_NotificationContext *nc;
75 * Find the performance client associated with the given handle.
77 * @param client server handle
78 * @return internal handle
80 static struct PerformanceClient *
81 find_client (struct GNUNET_SERVER_Client *client)
83 struct PerformanceClient * pc;
85 for (pc = pc_head; pc != NULL; pc = pc->next)
86 if (pc->client == client)
93 * Register a new performance client.
95 * @param client handle of the new client
98 GAS_performance_add_client (struct GNUNET_SERVER_Client *client)
100 struct PerformanceClient * pc;
102 GNUNET_break (NULL == find_client (client));
103 pc = GNUNET_malloc (sizeof (struct PerformanceClient));
105 GNUNET_SERVER_notification_context_add (nc, client);
106 GNUNET_SERVER_client_keep (client);
107 GNUNET_CONTAINER_DLL_insert(pc_head, pc_tail, pc);
112 * Unregister a client (which may have been a performance client,
113 * but this is not assured).
115 * @param client handle of the (now dead) client
118 GAS_performance_remove_client (struct GNUNET_SERVER_Client *client)
120 struct PerformanceClient * pc;
122 pc = find_client (client);
125 GNUNET_CONTAINER_DLL_remove (pc_head, pc_tail, pc);
126 GNUNET_SERVER_client_drop (client);
132 GAS_handle_reservation_request (void *cls, struct GNUNET_SERVER_Client *client,
133 const struct GNUNET_MessageHeader *message)
135 // const struct ReservationRequestMessage * msg = (const struct ReservationRequestMessage *) message;
136 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received `%s' message\n", "RESERVATION_REQUEST");
142 GAS_handle_preference_change (void *cls, struct GNUNET_SERVER_Client *client,
143 const struct GNUNET_MessageHeader *message)
146 // const struct ChangePreferenceMessage * msg = (const struct ChangePreferenceMessage *) message;
147 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received `%s' message\n", "PREFERENCE_CHANGE");
148 // FIXME: implement later (we can safely ignore these for now)
149 GNUNET_SERVER_receive_done (client, GNUNET_OK);
154 * Initialize performance subsystem.
156 * @param server handle to our server
159 GAS_performance_init (struct GNUNET_SERVER_Handle *server)
161 nc = GNUNET_SERVER_notification_context_create (server, 128);
166 * Shutdown performance subsystem.
169 GAS_performance_done ()
171 GNUNET_SERVER_notification_context_destroy (nc);
175 /* end of gnunet-service-ats_performance.c */