testbed_api_operations.h 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233
  1. /*
  2. This file is part of GNUnet
  3. Copyright (C) 2008--2013 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 testbed/testbed_api_operations.h
  18. * @brief internal API to access the 'operations' subsystem
  19. * @author Christian Grothoff
  20. */
  21. #ifndef NEW_TESTING_API_OPERATIONS_H
  22. #define NEW_TESTING_API_OPERATIONS_H
  23. #include "gnunet_testbed_service.h"
  24. #include "gnunet_helper_lib.h"
  25. /**
  26. * Queue of operations where we can only support a certain
  27. * number of concurrent operations of a particular type.
  28. */
  29. struct OperationQueue;
  30. /**
  31. * The type of operation queue
  32. */
  33. enum OperationQueueType
  34. {
  35. /**
  36. * Operation queue which permits a fixed maximum number of operations to be
  37. * active at any time
  38. */
  39. OPERATION_QUEUE_TYPE_FIXED,
  40. /**
  41. * Operation queue which adapts the number of operations to be active based on
  42. * the operation completion times of previously executed operation in it
  43. */
  44. OPERATION_QUEUE_TYPE_ADAPTIVE
  45. };
  46. /**
  47. * Create an operation queue.
  48. *
  49. * @param type the type of operation queue
  50. * @param max_active maximum number of operations in this queue that can be
  51. * active in parallel at the same time.
  52. * @return handle to the queue
  53. */
  54. struct OperationQueue *
  55. GNUNET_TESTBED_operation_queue_create_ (enum OperationQueueType type,
  56. unsigned int max_active);
  57. /**
  58. * Destroy an operation queue. The queue MUST be empty
  59. * at this time.
  60. *
  61. * @param queue queue to destroy
  62. */
  63. void
  64. GNUNET_TESTBED_operation_queue_destroy_ (struct OperationQueue *queue);
  65. /**
  66. * Destroys the operation queue if it is empty. If not empty return GNUNET_NO.
  67. *
  68. * @param queue the queue to destroy if empty
  69. * @return GNUNET_YES if the queue is destroyed. GNUNET_NO if not (because it
  70. * is not empty)
  71. */
  72. int
  73. GNUNET_TESTBED_operation_queue_destroy_empty_ (struct OperationQueue *queue);
  74. /**
  75. * Function to reset the maximum number of operations in the given queue. If
  76. * max_active is lesser than the number of currently active operations, the
  77. * active operations are not stopped immediately.
  78. *
  79. * @param queue the operation queue which has to be modified
  80. * @param max_active the new maximum number of active operations
  81. */
  82. void
  83. GNUNET_TESTBED_operation_queue_reset_max_active_ (struct OperationQueue *queue,
  84. unsigned int max_active);
  85. /**
  86. * Add an operation to a queue. An operation can be in multiple queues at
  87. * once. Once the operation is inserted into all the queues
  88. * GNUNET_TESTBED_operation_begin_wait_() has to be called to actually start
  89. * waiting for the operation to become active.
  90. *
  91. * @param queue queue to add the operation to
  92. * @param op operation to add to the queue
  93. * @param nres the number of units of the resources of queue needed by the
  94. * operation. Should be greater than 0.
  95. */
  96. void
  97. GNUNET_TESTBED_operation_queue_insert2_ (struct OperationQueue *queue,
  98. struct GNUNET_TESTBED_Operation *op,
  99. unsigned int nres);
  100. /**
  101. * Add an operation to a queue. An operation can be in multiple queues at
  102. * once. Once the operation is inserted into all the queues
  103. * GNUNET_TESTBED_operation_begin_wait_() has to be called to actually start
  104. * waiting for the operation to become active.
  105. *
  106. * @param queue queue to add the operation to
  107. * @param op operation to add to the queue
  108. */
  109. void
  110. GNUNET_TESTBED_operation_queue_insert_ (struct OperationQueue *queue,
  111. struct GNUNET_TESTBED_Operation *op);
  112. /**
  113. * Marks the given operation as waiting on the queues. Once all queues permit
  114. * the operation to become active, the operation will be activated. The actual
  115. * activation will occur in a separate task (thus allowing multiple queue
  116. * insertions to be made without having the first one instantly trigger the
  117. * operation if the first queue has sufficient resources).
  118. *
  119. * @param op the operation to marks as waiting
  120. */
  121. void
  122. GNUNET_TESTBED_operation_begin_wait_ (struct GNUNET_TESTBED_Operation *op);
  123. /**
  124. * Function to call to start an operation once all
  125. * queues the operation is part of declare that the
  126. * operation can be activated.
  127. *
  128. * @param cls the closure from GNUNET_TESTBED_operation_create_()
  129. */
  130. typedef void (*OperationStart) (void *cls);
  131. /**
  132. * Function to call to cancel an operation (release all associated
  133. * resources). This can be because of a call to
  134. * "GNUNET_TESTBED_operation_cancel" (before the operation generated
  135. * an event) or AFTER the operation generated an event due to a call
  136. * to "GNUNET_TESTBED_operation_done". Thus it is not guaranteed that
  137. * a callback to the 'OperationStart' preceeds the call to
  138. * 'OperationRelease'. Implementations of this function are expected
  139. * to clean up whatever state is in 'cls' and release all resources
  140. * associated with the operation.
  141. *
  142. * @param cls the closure from GNUNET_TESTBED_operation_create_()
  143. */
  144. typedef void (*OperationRelease) (void *cls);
  145. /**
  146. * Create an 'operation' to be performed.
  147. *
  148. * @param cls closure for the callbacks
  149. * @param start function to call to start the operation
  150. * @param release function to call to close down the operation
  151. * @return handle to the operation
  152. */
  153. struct GNUNET_TESTBED_Operation *
  154. GNUNET_TESTBED_operation_create_ (void *cls, OperationStart start,
  155. OperationRelease release);
  156. /**
  157. * An operation is 'done' (was cancelled or finished); remove
  158. * it from the queues and release associated resources.
  159. *
  160. * @param op operation that finished
  161. */
  162. void
  163. GNUNET_TESTBED_operation_release_ (struct GNUNET_TESTBED_Operation *op);
  164. /**
  165. * Marks an active operation as inactive - the operation will be kept in a
  166. * ready-to-be-released state and continues to hold resources until another
  167. * operation contents for them.
  168. *
  169. * @param op the operation to be marked as inactive. The operation start
  170. * callback should have been called before for this operation to mark
  171. * it as inactive.
  172. */
  173. void
  174. GNUNET_TESTBED_operation_inactivate_ (struct GNUNET_TESTBED_Operation *op);
  175. /**
  176. * Marks and inactive operation as active. This fuction should be called to
  177. * ensure that the oprelease callback will not be called until it is either
  178. * marked as inactive or released.
  179. *
  180. * @param op the operation to be marked as active
  181. */
  182. void
  183. GNUNET_TESTBED_operation_activate_ (struct GNUNET_TESTBED_Operation *op);
  184. /**
  185. * Marks an operation as failed
  186. *
  187. * @param op the operation to be marked as failed
  188. */
  189. void
  190. GNUNET_TESTBED_operation_mark_failed (struct GNUNET_TESTBED_Operation *op);
  191. #endif
  192. /* end of testbed_api_operations.h */