17a72d95e038ddd5fea3a42bd8dd5b55d444dabc
[oweals/gnunet.git] / src / auction / gnunet-service-auction.c
1 /*
2    This file is part of GNUnet.
3    Copyright (C) 2009 GNUnet e.V.
4
5    GNUnet is free software: you can redistribute it and/or modify it
6    under the terms of the GNU Affero General Public License as published
7    by the Free Software Foundation, either version 3 of the License,
8    or (at your option) any later version.
9
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    Affero General Public License for more details.
14   
15    You should have received a copy of the GNU Affero General Public License
16    along with this program.  If not, see <http://www.gnu.org/licenses/>.
17    */
18
19 /**
20  * @file auction/gnunet-service-auction.c
21  * @brief service for executing auctions
22  * @author Markus Teich
23  */
24 #include "platform.h"
25 #include "gnunet_util_lib.h"
26
27 #include "auction.h"
28
29 /**
30  * Check AUCTION CREATE messages from the client.
31  *
32  * @param cls the client we received this message from
33  * @param msg the actual message received
34  * @return #GNUNET_OK (always)
35  */
36 static int
37 check_create (void *cls, const struct GNUNET_AUCTION_ClientCreateMessage *msg)
38 {
39         /* always well-formed due to arbitrary length description */
40         return GNUNET_OK;
41 }
42
43
44 /**
45  * Handler for CREATE messages.
46  *
47  * @param cls the client we received this message from
48  * @param msg the actual message received
49  */
50 static void
51 handle_create (void *cls, const struct GNUNET_AUCTION_ClientCreateMessage *msg)
52 {
53         struct GNUNET_SERVICE_Client *client = cls;
54 //      struct GNUNET_MQ_Handle *mq;
55 //      struct GNUNET_MQ_Envelope *env;
56 //      struct GNUNET_AUCTION_blabla em;
57         uint16_t size;
58
59         GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
60                     "Received CREATE message from client\n");
61
62         size = ntohs (msg->header.size);
63
64         /**TODO: create auction and return auction object */
65 //      mq = GNUNET_SERVICE_client_get_mq (client);
66 //      setup_info_message (&em);
67 //      env = GNUNET_MQ_msg_copy (&em.header);
68 //      GNUNET_MQ_send (mq, env);
69
70         GNUNET_SERVICE_client_continue (client);
71 }
72
73
74 /**
75  * Task run during shutdown.
76  *
77  * @param cls unused
78  */
79 static void
80 cleanup_task (void *cls)
81 {
82         /* FIXME: do clean up here */
83 }
84
85
86 /**
87  * Callback called when a client connects to the service.
88  *
89  * @param cls closure for the service
90  * @param c the new client that connected to the service
91  * @param mq the message queue used to send messages to the client
92  * @return @a c
93  */
94 static void *
95 client_connect_cb (void *cls,
96                    struct GNUNET_SERVICE_Client *c,
97                    struct GNUNET_MQ_Handle *mq)
98 {
99         return c;
100 }
101
102
103 /**
104  * Callback called when a client disconnected from the service
105  *
106  * @param cls closure for the service
107  * @param c the client that disconnected
108  * @param internal_cls should be equal to @a c
109  */
110 static void
111 client_disconnect_cb (void *cls,
112                       struct GNUNET_SERVICE_Client *c,
113                       void *internal_cls)
114 {
115         GNUNET_assert (c == internal_cls);
116 }
117
118
119 /**
120  * Process auction requests.
121  *
122  * @param cls closure
123  * @param cfg configuration to use
124  * @param service the initialized service
125  */
126 static void
127 run (void *cls,
128      const struct GNUNET_CONFIGURATION_Handle *cfg,
129      struct GNUNET_SERVICE_Handle *service)
130 {
131         /* FIXME: do setup here */
132         GNUNET_SCHEDULER_add_shutdown (&cleanup_task, NULL);
133 }
134
135
136 /**
137  * Define "main" method using service macro.
138  */
139 GNUNET_SERVICE_MAIN
140 ("auction",
141  GNUNET_SERVICE_OPTION_NONE,
142  &run,
143  &client_connect_cb,
144  &client_disconnect_cb,
145  NULL,
146  GNUNET_MQ_hd_var_size (create,
147                         GNUNET_MESSAGE_TYPE_AUCTION_CLIENT_CREATE,
148                         struct GNUNET_AUCTION_ClientCreateMessage,
149                         NULL),
150  GNUNET_MQ_handler_end ())
151
152
153 /* end of gnunet-service-auction.c */