testbed_api_operations.h 7.3 KB

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