-lockmanager build skeleton
[oweals/gnunet.git] / src / lockmanager / gnunet-service-lockmanager.c
1 /*
2      This file is part of GNUnet.
3      (C) 2012 Christian Grothoff (and other contributing authors)
4
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 2, or (at your
8      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      General Public License for more details.
14
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.
19 */
20
21 /**
22  * @file lockmanager/gnunet-service-lockmanager.c
23  * @brief implementation of the LOCKMANAGER service
24  * @author Sree Harsha Totakura
25  */
26
27 #include "platform.h"
28 #include "gnunet_common.h"
29 #include "gnunet_protocols.h"
30 #include "gnunet_service_lib.h"
31 #include "gnunet_server_lib.h"
32
33 #include "lockmanager.h"
34
35 #define LOG(kind,...) \
36   GNUNET_log_from (kind, "gnunet-service-lockmanager",__VA_ARGS__)
37
38
39 /**
40  * Handler for GNUNET_MESSAGE_TYPE_LOCKMANAGER_ACQUIRE
41  *
42  * @param 
43  * @return 
44  */
45 static void
46 handle_acquire (void *cls,
47                 struct GNUNET_SERVER_Client *client,
48                 const struct GNUNET_MessageHeader *message)
49 {
50   // const struct GNUNET_LOCKMANAGER_Message *msg = message;
51   LOG (GNUNET_ERROR_TYPE_DEBUG,
52        "Received a ACQUIRE message\n");
53
54   GNUNET_SERVER_receive_done (client, GNUNET_OK);
55 }
56
57
58 /**
59  * Handle for GNUNET_MESSAGE_TYPE_LOCKMANAGER_RELEASE
60  *
61  * @param 
62  * @return 
63  */
64 static void
65 handle_release (void *cls,
66                 struct GNUNET_SERVER_Client *client,
67                 const struct GNUNET_MessageHeader *message)
68 {
69   LOG (GNUNET_ERROR_TYPE_DEBUG,
70        "Received a RELEASE message\n");
71
72   GNUNET_SERVER_receive_done (client, GNUNET_OK);
73 }
74
75
76 /**
77  * Lock manager setup
78  *
79  * @param cls closure
80  * @param server the initialized server
81  * @param cfg configuration to use
82  */
83 static void 
84 lockmanager_run (void *cls,
85                  struct GNUNET_SERVER_Handle * server,
86                  const struct GNUNET_CONFIGURATION_Handle *cfg)
87 {
88   struct GNUNET_SERVER_MessageHandler message_handlers[] =
89     {
90       {&handle_acquire, NULL, GNUNET_MESSAGE_TYPE_LOCKMANAGER_ACQUIRE, 0},
91       {&handle_release, NULL, GNUNET_MESSAGE_TYPE_LOCKMANAGER_RELEASE, 0},
92       {NULL}
93     };
94   
95   LOG (GNUNET_ERROR_TYPE_DEBUG, "Starting lockmanager\n");
96   GNUNET_SERVER_add_handlers (server,
97                               message_handlers);
98   
99 }
100
101 /**
102  * The starting point of execution
103  */
104 int main (int argc, char *const *argv)
105 {
106   int ret;
107
108   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "main()\n");
109   ret = 
110     (GNUNET_OK ==
111      GNUNET_SERVICE_run (argc,
112                          argv,
113                          "lockmanager",
114                          GNUNET_SERVICE_OPTION_NONE,
115                          &lockmanager_run,
116                          NULL)) ? 0 : 1;
117   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "main() END\n");
118   return ret;
119 }