gnunet_op_lib.h 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  1. /*
  2. This file is part of GNUnet.
  3. Copyright (C) 2016 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
  18. * Asynchronous operations; register callbacks for operations and call them when a response arrives.
  19. *
  20. * @author Gabor X Toth
  21. */
  22. #ifndef GNUNET_OP_H
  23. #define GNUNET_OP_H
  24. #include "gnunet_util_lib.h"
  25. /**
  26. * Operations handle.
  27. */
  28. struct GNUNET_OP_Handle;
  29. /**
  30. * Create new operations handle.
  31. */
  32. struct GNUNET_OP_Handle *
  33. GNUNET_OP_create ();
  34. /**
  35. * Destroy operations handle.
  36. */
  37. void
  38. GNUNET_OP_destroy (struct GNUNET_OP_Handle *h);
  39. /**
  40. * Get a unique operation ID to distinguish between asynchronous requests.
  41. *
  42. * @param h
  43. * Operations handle.
  44. *
  45. * @return Operation ID to use.
  46. */
  47. uint64_t
  48. GNUNET_OP_get_next_id (struct GNUNET_OP_Handle *h);
  49. /**
  50. * Find operation by ID.
  51. *
  52. * @param h
  53. * Operations handle.
  54. * @param op_id
  55. * Operation ID to look up.
  56. * @param[out] result_cb
  57. * If an operation was found, its result callback is returned here.
  58. * @param[out] cls
  59. * If an operation was found, its closure is returned here.
  60. * @param[out] ctx
  61. * User context.
  62. *
  63. * @return #GNUNET_YES if an operation was found,
  64. * #GNUNET_NO if not found.
  65. */
  66. int
  67. GNUNET_OP_get (struct GNUNET_OP_Handle *h,
  68. uint64_t op_id,
  69. GNUNET_ResultCallback *result_cb,
  70. void **cls,
  71. void **ctx);
  72. /**
  73. * Add a new operation.
  74. *
  75. * @param h
  76. * Operations handle.
  77. * @param result_cb
  78. * Function to call with the result of the operation.
  79. * @param cls
  80. * Closure for @a result_cb.
  81. * @param ctx
  82. * User context.
  83. *
  84. * @return ID of the new operation.
  85. */
  86. uint64_t
  87. GNUNET_OP_add (struct GNUNET_OP_Handle *h,
  88. GNUNET_ResultCallback result_cb,
  89. void *cls,
  90. void *ctx);
  91. /**
  92. * Call the result callback of an operation and remove it.
  93. *
  94. * @param h
  95. * Operations handle.
  96. * @param op_id
  97. * Operation ID.
  98. * @param result_code
  99. * Result of the operation.
  100. * @param data
  101. * Data result of the operation.
  102. * @param data_size
  103. * Size of @a data.
  104. * @param[out] ctx
  105. * User context.
  106. *
  107. * @return #GNUNET_YES if the operation was found and removed,
  108. * #GNUNET_NO if the operation was not found.
  109. */
  110. int
  111. GNUNET_OP_result (struct GNUNET_OP_Handle *h,
  112. uint64_t op_id,
  113. int64_t result_code,
  114. const void *data,
  115. uint16_t data_size,
  116. void **ctx);
  117. /**
  118. * Remove / cancel an operation.
  119. *
  120. * @param h
  121. * Operations handle.
  122. * @param op_id
  123. * Operation ID.
  124. *
  125. * @return #GNUNET_YES if the operation was found and removed,
  126. * #GNUNET_NO if the operation was not found.
  127. */
  128. int
  129. GNUNET_OP_remove (struct GNUNET_OP_Handle *h,
  130. uint64_t op_id);
  131. #endif // GNUNET_OP_H