gnunet-svn
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[GNUnet-SVN] r38177 - gnunet/src/template


From: gnunet
Subject: [GNUnet-SVN] r38177 - gnunet/src/template
Date: Sat, 22 Oct 2016 00:00:26 +0200

Author: grothoff
Date: 2016-10-22 00:00:26 +0200 (Sat, 22 Oct 2016)
New Revision: 38177

Modified:
   gnunet/src/template/gnunet-service-template.c
   gnunet/src/template/gnunet-template.c
Log:
migrate template to new service API

Modified: gnunet/src/template/gnunet-service-template.c
===================================================================
--- gnunet/src/template/gnunet-service-template.c       2016-10-21 21:48:19 UTC 
(rev 38176)
+++ gnunet/src/template/gnunet-service-template.c       2016-10-21 22:00:26 UTC 
(rev 38177)
@@ -40,23 +40,51 @@
 
 
 /**
+ * Callback called when a client connects to the service.
+ *
+ * @param cls closure for the service
+ * @param c the new client that connected to the service
+ * @param mq the message queue used to send messages to the client
+ * @return @a c
+ */
+static void *
+client_connect_cb (void *cls,
+                  struct GNUNET_SERVICE_Client *c,
+                  struct GNUNET_MQ_Handle *mq)
+{
+  return c;
+}
+
+
+/**
+ * Callback called when a client disconnected from the service
+ *
+ * @param cls closure for the service
+ * @param c the client that disconnected
+ * @param internal_cls should be equal to @a c
+ */
+static void
+client_disconnect_cb (void *cls,
+                     struct GNUNET_SERVICE_Client *c,
+                     void *internal_cls)
+{
+  GNUNET_assert (c == internal_cls);
+}
+
+
+/**
  * Process template requests.
  *
  * @param cls closure
- * @param server the initialized server
  * @param cfg configuration to use
+ * @param service the initialized service
  */
 static void
 run (void *cls,
-     struct GNUNET_SERVER_Handle *server,
-     const struct GNUNET_CONFIGURATION_Handle *cfg)
+     const struct GNUNET_CONFIGURATION_Handle *cfg,
+     struct GNUNET_SERVICE_Handle *service)
 {
-  static const struct GNUNET_SERVER_MessageHandler handlers[] = {
-    /* FIXME: add handlers here! */
-    {NULL, NULL, 0, 0}
-  };
   /* FIXME: do setup here */
-  GNUNET_SERVER_add_handlers (server, handlers);
   GNUNET_SCHEDULER_add_shutdown (&cleanup_task,
                                 NULL);
 }
@@ -63,18 +91,16 @@
 
 
 /**
- * The main function for the template service.
- *
- * @param argc number of arguments from the command line
- * @param argv command line arguments
- * @return 0 ok, 1 on error
+ * Define "main" method using service macro.
  */
-int
-main (int argc, char *const *argv)
-{
-  return (GNUNET_OK ==
-          GNUNET_SERVICE_run (argc, argv, "template",
-                              GNUNET_SERVICE_OPTION_NONE, &run, NULL)) ? 0 : 1;
-}
+GNUNET_SERVICE_MAIN
+("template",
+ GNUNET_SERVICE_OPTION_NONE,
+ &run,
+ &client_connect_cb,
+ &client_disconnect_cb,
+ NULL,
+ GNUNET_MQ_handler_end ());
 
+
 /* end of gnunet-service-template.c */

Modified: gnunet/src/template/gnunet-template.c
===================================================================
--- gnunet/src/template/gnunet-template.c       2016-10-21 21:48:19 UTC (rev 
38176)
+++ gnunet/src/template/gnunet-template.c       2016-10-21 22:00:26 UTC (rev 
38177)
@@ -32,6 +32,7 @@
  */
 static int ret;
 
+
 /**
  * Main function that will be run by the scheduler.
  *
@@ -41,7 +42,9 @@
  * @param cfg configuration
  */
 static void
-run (void *cls, char *const *args, const char *cfgfile,
+run (void *cls,
+     char *const *args,
+     const char *cfgfile,
      const struct GNUNET_CONFIGURATION_Handle *cfg)
 {
   /* main code here */
@@ -62,12 +65,17 @@
     /* FIMXE: add options here */
     GNUNET_GETOPT_OPTION_END
   };
-  if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args (argc, argv, &argc, &argv))
+  if (GNUNET_OK !=
+      GNUNET_STRINGS_get_utf8_args (argc, argv,
+                                   &argc, &argv))
     return 2;
 
   ret = (GNUNET_OK ==
-        GNUNET_PROGRAM_run (argc, argv, "gnunet-template",
-                            gettext_noop ("help text"), options, &run,
+        GNUNET_PROGRAM_run (argc, argv,
+                            "gnunet-template",
+                            gettext_noop ("help text"),
+                            options,
+                            &run,
                             NULL)) ? ret : 1;
   GNUNET_free ((void*) argv);
   return ret;




reply via email to

[Prev in Thread] Current Thread [Next in Thread]