task.h 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189
  1. /* vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
  2. *
  3. * Gearmand client and server library.
  4. *
  5. * Copyright (C) 2011-2013 Data Differential, http://datadifferential.com/
  6. * Copyright (C) 2008 Brian Aker, Eric Day
  7. * All rights reserved.
  8. *
  9. * Redistribution and use in source and binary forms, with or without
  10. * modification, are permitted provided that the following conditions are
  11. * met:
  12. *
  13. * * Redistributions of source code must retain the above copyright
  14. * notice, this list of conditions and the following disclaimer.
  15. *
  16. * * Redistributions in binary form must reproduce the above
  17. * copyright notice, this list of conditions and the following disclaimer
  18. * in the documentation and/or other materials provided with the
  19. * distribution.
  20. *
  21. * * The names of its contributors may not be used to endorse or
  22. * promote products derived from this software without specific prior
  23. * written permission.
  24. *
  25. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  26. * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  27. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  28. * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  29. * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  30. * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  31. * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  32. * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  33. * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  34. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  35. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  36. *
  37. */
  38. /**
  39. * @file
  40. * @brief Task Declarations
  41. */
  42. #pragma once
  43. #include <libgearman-1.0/actions.h>
  44. #include <libgearman-1.0/interface/task.h>
  45. #ifdef __cplusplus
  46. extern "C" {
  47. #endif
  48. /**
  49. * Free a task structure.
  50. *
  51. * @param[in] task Structure previously initialized with one of the
  52. * gearman_client_add_task() functions.
  53. */
  54. GEARMAN_API
  55. void gearman_task_free(gearman_task_st *task);
  56. /**
  57. * Get context for a task.
  58. */
  59. GEARMAN_API
  60. void *gearman_task_context(const gearman_task_st *task);
  61. /**
  62. * Set context for a task.
  63. */
  64. GEARMAN_API
  65. void gearman_task_set_context(gearman_task_st *task, void *context);
  66. /**
  67. * Get function name associated with a task.
  68. */
  69. GEARMAN_API
  70. const char *gearman_task_function_name(const gearman_task_st *task);
  71. /**
  72. * Get unique identifier for a task.
  73. */
  74. GEARMAN_API
  75. const char *gearman_task_unique(const gearman_task_st *task);
  76. /**
  77. * Get job handle for a task.
  78. */
  79. GEARMAN_API
  80. const char *gearman_task_job_handle(const gearman_task_st *task);
  81. /**
  82. * Get status on whether a task is known or not.
  83. */
  84. GEARMAN_API
  85. bool gearman_task_is_known(const gearman_task_st *task);
  86. /**
  87. * Get status on whether a task is running or not.
  88. */
  89. GEARMAN_API
  90. bool gearman_task_is_running(const gearman_task_st *task);
  91. /**
  92. * Get the numerator of percentage complete for a task.
  93. */
  94. GEARMAN_API
  95. uint32_t gearman_task_numerator(const gearman_task_st *task);
  96. /**
  97. * Get the denominator of percentage complete for a task.
  98. */
  99. GEARMAN_API
  100. uint32_t gearman_task_denominator(const gearman_task_st *task);
  101. /**
  102. * Give allocated memory to task. After this, the library will be responsible
  103. * for freeing the workload memory when the task is destroyed.
  104. */
  105. GEARMAN_API
  106. void gearman_task_give_workload(gearman_task_st *task, const void *workload,
  107. size_t workload_size);
  108. /**
  109. * Send packet workload for a task.
  110. */
  111. GEARMAN_API
  112. size_t gearman_task_send_workload(gearman_task_st *task, const void *workload,
  113. size_t workload_size,
  114. gearman_return_t *ret_ptr);
  115. /**
  116. * Get result data being returned for a task.
  117. */
  118. GEARMAN_API
  119. const void *gearman_task_data(const gearman_task_st *task);
  120. /**
  121. * Get result data size being returned for a task.
  122. */
  123. GEARMAN_API
  124. size_t gearman_task_data_size(const gearman_task_st *task);
  125. /**
  126. * Take allocated result data from task. After this, the caller is responsible
  127. * for free()ing the memory.
  128. */
  129. GEARMAN_API
  130. void *gearman_task_take_data(gearman_task_st *task, size_t *data_size);
  131. /**
  132. * Read result data into a buffer for a task.
  133. */
  134. GEARMAN_API
  135. size_t gearman_task_recv_data(gearman_task_st *task, void *data,
  136. size_t data_size, gearman_return_t *ret_ptr);
  137. GEARMAN_API
  138. const char *gearman_task_error(const gearman_task_st *task);
  139. GEARMAN_API
  140. gearman_result_st *gearman_task_result(gearman_task_st *task);
  141. GEARMAN_API
  142. gearman_return_t gearman_task_return(const gearman_task_st *task);
  143. GEARMAN_API
  144. const char *gearman_task_strstate(const gearman_task_st *);
  145. GEARMAN_API
  146. bool gearman_task_has_exception(const gearman_task_st* task_shell);
  147. GEARMAN_API
  148. gearman_string_t gearman_task_exception(const gearman_task_st *);
  149. /**
  150. * Get status on whether a task is running or not.
  151. */
  152. GEARMAN_API
  153. bool gearman_task_is_finished(const gearman_task_st *task);
  154. /** @} */
  155. #ifdef __cplusplus
  156. }
  157. #endif