gnunet-service-template.c 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. /*
  2. This file is part of GNUnet.
  3. Copyright (C) 2009 GNUnet e.V.
  4. GNUnet is free software: you can redistribute it and/or modify it
  5. under the terms of the GNU Affero General Public License as published
  6. by the Free Software Foundation, either version 3 of the License,
  7. or (at your option) any later version.
  8. GNUnet is distributed in the hope that it will be useful, but
  9. WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  11. Affero General Public License for more details.
  12. You should have received a copy of the GNU Affero General Public License
  13. along with this program. If not, see <http://www.gnu.org/licenses/>.
  14. SPDX-License-Identifier: AGPL3.0-or-later
  15. */
  16. /**
  17. * @file template/gnunet-service-template.c
  18. * @brief program that does template
  19. * @author Christian Grothoff
  20. */
  21. #include "platform.h"
  22. #include "gnunet_util_lib.h"
  23. /**
  24. * Task run during shutdown.
  25. *
  26. * @param cls unused
  27. */
  28. static void
  29. cleanup_task (void *cls)
  30. {
  31. /* FIXME: do clean up here */
  32. }
  33. /**
  34. * Callback called when a client connects to the service.
  35. *
  36. * @param cls closure for the service
  37. * @param c the new client that connected to the service
  38. * @param mq the message queue used to send messages to the client
  39. * @return @a c
  40. */
  41. static void *
  42. client_connect_cb (void *cls,
  43. struct GNUNET_SERVICE_Client *c,
  44. struct GNUNET_MQ_Handle *mq)
  45. {
  46. return c;
  47. }
  48. /**
  49. * Callback called when a client disconnected from the service
  50. *
  51. * @param cls closure for the service
  52. * @param c the client that disconnected
  53. * @param internal_cls should be equal to @a c
  54. */
  55. static void
  56. client_disconnect_cb (void *cls,
  57. struct GNUNET_SERVICE_Client *c,
  58. void *internal_cls)
  59. {
  60. GNUNET_assert (c == internal_cls);
  61. }
  62. /**
  63. * Process template requests.
  64. *
  65. * @param cls closure
  66. * @param cfg configuration to use
  67. * @param service the initialized service
  68. */
  69. static void
  70. run (void *cls,
  71. const struct GNUNET_CONFIGURATION_Handle *cfg,
  72. struct GNUNET_SERVICE_Handle *service)
  73. {
  74. /* FIXME: do setup here */
  75. GNUNET_SCHEDULER_add_shutdown (&cleanup_task, NULL);
  76. }
  77. /**
  78. * Define "main" method using service macro.
  79. */
  80. GNUNET_SERVICE_MAIN ("template",
  81. GNUNET_SERVICE_OPTION_NONE,
  82. &run,
  83. &client_connect_cb,
  84. &client_disconnect_cb,
  85. NULL,
  86. GNUNET_MQ_handler_end ());
  87. /* end of gnunet-service-template.c */