client.h 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727
  1. /* vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
  2. *
  3. * Gearmand client and server library.
  4. *
  5. * Copyright (C) 2011 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 Client Declarations
  41. */
  42. #pragma once
  43. /** @addtogroup gearman_client Client Declarations
  44. *
  45. * This is the interface gearman clients should use. You can run tasks one at a
  46. * time or concurrently.
  47. *
  48. * @ref main_page_client "See Main Page for full details."
  49. * @{
  50. */
  51. enum gearman_client_t {
  52. GEARMAN_CLIENT_STATE_IDLE,
  53. GEARMAN_CLIENT_STATE_NEW,
  54. GEARMAN_CLIENT_STATE_SUBMIT,
  55. GEARMAN_CLIENT_STATE_PACKET
  56. };
  57. /**
  58. * @ingroup gearman_client
  59. */
  60. struct gearman_client_st
  61. {
  62. struct {
  63. bool allocated;
  64. bool non_blocking;
  65. bool unbuffered_result;
  66. bool no_new;
  67. bool free_tasks;
  68. } options;
  69. enum gearman_client_t state;
  70. uint32_t new_tasks;
  71. uint32_t running_tasks;
  72. uint32_t task_count;
  73. void *context;
  74. gearman_connection_st *con;
  75. gearman_task_st *task;
  76. gearman_task_st *task_list;
  77. gearman_task_context_free_fn *task_context_free_fn;
  78. struct gearman_universal_st universal;
  79. struct gearman_actions_t actions;
  80. gearman_job_handle_t _do_handle; // Backwards compatible
  81. };
  82. #ifdef __cplusplus
  83. extern "C" {
  84. #endif
  85. /**
  86. * Initialize a client structure. Always check the return value even if passing
  87. * in a pre-allocated structure. Some other initialization may have failed. It
  88. * is not required to memset() a structure before providing it.
  89. *
  90. * @param[in] client Caller allocated structure, or NULL to allocate one.
  91. * @return On success, a pointer to the (possibly allocated) structure. On
  92. * failure this will be NULL.
  93. */
  94. GEARMAN_API
  95. gearman_client_st *gearman_client_create(gearman_client_st *client);
  96. /**
  97. * Clone a client structure.
  98. *
  99. * @param[in] client Caller allocated structure, or NULL to allocate one.
  100. * @param[in] from Structure to use as a source to clone from.
  101. * @return Same return as gearman_client_create().
  102. */
  103. GEARMAN_API
  104. gearman_client_st *gearman_client_clone(gearman_client_st *client,
  105. const gearman_client_st *from);
  106. /**
  107. * Free resources used by a client structure.
  108. *
  109. * @param[in] client Structure previously initialized with
  110. * gearman_client_create() or gearman_client_clone().
  111. */
  112. GEARMAN_API
  113. void gearman_client_free(gearman_client_st *client);
  114. /**
  115. * See gearman_error() for details.
  116. */
  117. GEARMAN_API
  118. const char *gearman_client_error(const gearman_client_st *client);
  119. /**
  120. * See gearman_errno() for details.
  121. */
  122. GEARMAN_API
  123. int gearman_client_errno(const gearman_client_st *client);
  124. /**
  125. * Get options for a client structure.
  126. *
  127. * @param[in] client Structure previously initialized with
  128. * gearman_client_create() or gearman_client_clone().
  129. * @return Options set for the client structure.
  130. */
  131. GEARMAN_API
  132. gearman_client_options_t gearman_client_options(const gearman_client_st *client);
  133. /**
  134. * Set options for a client structure.
  135. *
  136. * @param[in] client Structure previously initialized with
  137. * gearman_client_create() or gearman_client_clone().
  138. * @param[in] options Available options for client structures.
  139. */
  140. GEARMAN_API
  141. void gearman_client_set_options(gearman_client_st *client,
  142. gearman_client_options_t options);
  143. /**
  144. * Add options for a client structure.
  145. *
  146. * @param[in] client Structure previously initialized with
  147. * gearman_client_create() or gearman_client_clone().
  148. * @param[in] options Available options for client structures.
  149. */
  150. GEARMAN_API
  151. void gearman_client_add_options(gearman_client_st *client,
  152. gearman_client_options_t options);
  153. GEARMAN_API
  154. bool gearman_client_has_option(gearman_client_st *client,
  155. gearman_client_options_t option);
  156. /**
  157. * Remove options for a client structure.
  158. *
  159. * @param[in] client Structure previously initialized with
  160. * gearman_client_create() or gearman_client_clone().
  161. * @param[in] options Available options for client structures.
  162. */
  163. GEARMAN_API
  164. void gearman_client_remove_options(gearman_client_st *client,
  165. gearman_client_options_t options);
  166. /**
  167. * See gearman_universal_timeout() for details.
  168. */
  169. GEARMAN_API
  170. int gearman_client_timeout(gearman_client_st *client);
  171. /**
  172. * See gearman_universal_set_timeout() for details.
  173. */
  174. GEARMAN_API
  175. void gearman_client_set_timeout(gearman_client_st *client, int timeout);
  176. /**
  177. * Get the application context for a client.
  178. *
  179. * @param[in] client Structure previously initialized with
  180. * gearman_client_create() or gearman_client_clone().
  181. * @return Application context that was previously set, or NULL.
  182. */
  183. GEARMAN_API
  184. void *gearman_client_context(const gearman_client_st *client);
  185. /**
  186. * Set the application context for a client.
  187. *
  188. * @param[in] client Structure previously initialized with
  189. * gearman_client_create() or gearman_client_clone().
  190. * @param[in] context Application context to set.
  191. */
  192. GEARMAN_API
  193. void gearman_client_set_context(gearman_client_st *client, void *context);
  194. /**
  195. * See gearman_set_log_fn() for details.
  196. */
  197. GEARMAN_API
  198. void gearman_client_set_log_fn(gearman_client_st *client,
  199. gearman_log_fn *function, void *context,
  200. gearman_verbose_t verbose);
  201. /**
  202. * See gearman_set_workload_malloc_fn() for details.
  203. */
  204. GEARMAN_API
  205. void gearman_client_set_workload_malloc_fn(gearman_client_st *client,
  206. gearman_malloc_fn *function,
  207. void *context);
  208. /**
  209. * See gearman_set_workload_malloc_fn() for details.
  210. */
  211. GEARMAN_API
  212. void gearman_client_set_workload_free_fn(gearman_client_st *client,
  213. gearman_free_fn *function,
  214. void *context);
  215. GEARMAN_API
  216. gearman_return_t gearman_client_set_memory_allocators(gearman_client_st *,
  217. gearman_malloc_fn *malloc_fn,
  218. gearman_free_fn *free_fn,
  219. gearman_realloc_fn *realloc_fn,
  220. gearman_calloc_fn *calloc_fn,
  221. void *context);
  222. /**
  223. * Add a job server to a client. This goes into a list of servers that can be
  224. * used to run tasks. No socket I/O happens here, it is just added to a list.
  225. *
  226. * @param[in] client Structure previously initialized with
  227. * gearman_client_create() or gearman_client_clone().
  228. * @param[in] host Hostname or IP address (IPv4 or IPv6) of the server to add.
  229. * @param[in] port Port of the server to add.
  230. * @return Standard gearman return value.
  231. */
  232. GEARMAN_API
  233. gearman_return_t gearman_client_add_server(gearman_client_st *client,
  234. const char *host, in_port_t port);
  235. /**
  236. * Add a list of job servers to a client. The format for the server list is:
  237. * SERVER[:PORT][,SERVER[:PORT]]...
  238. * Some examples are:
  239. * 10.0.0.1,10.0.0.2,10.0.0.3
  240. * localhost234,jobserver2.domain.com:7003,10.0.0.3
  241. *
  242. * @param[in] client Structure previously initialized with
  243. * gearman_client_create() or gearman_client_clone().
  244. * @param[in] servers Server list described above.
  245. * @return Standard gearman return value.
  246. */
  247. GEARMAN_API
  248. gearman_return_t gearman_client_add_servers(gearman_client_st *client,
  249. const char *servers);
  250. /**
  251. * Remove all servers currently associated with the client.
  252. *
  253. * @param[in] client Structure previously initialized with
  254. * gearman_client_create() or gearman_client_clone().
  255. */
  256. GEARMAN_API
  257. void gearman_client_remove_servers(gearman_client_st *client);
  258. /**
  259. * When in non-blocking I/O mode, wait for activity from one of the servers.
  260. *
  261. * @param[in] client Structure previously initialized with
  262. * gearman_client_create() or gearman_client_clone().
  263. * @return Standard gearman return value.
  264. */
  265. GEARMAN_API
  266. gearman_return_t gearman_client_wait(gearman_client_st *client);
  267. /** @} */
  268. /**
  269. * @addtogroup gearman_client_single Single Task Interface
  270. * @ingroup gearman_client
  271. * Use the following set of functions to run one task at a time.
  272. *
  273. * @ref main_page_client_single "See Main Page for full details."
  274. * @{
  275. */
  276. /**
  277. * Run a single task and return an allocated result.
  278. *
  279. * @param[in] client Structure previously initialized with
  280. * gearman_client_create() or gearman_client_clone().
  281. * @param[in] function_name The name of the function to run.
  282. * @param[in] unique Optional unique job identifier, or NULL for a new UUID.
  283. * @param[in] workload The workload to pass to the function when it is run.
  284. * @param[in] workload_size Size of the workload.
  285. * @param[out] result_size The size of the data being returned.
  286. * @param[out] ret_ptr Standard gearman return value. In the case of
  287. * GEARMAN_WORK_DATA, GEARMAN_WORK_WARNING, or GEARMAN_WORK_STATUS, the caller
  288. * should take any actions to handle the event and then call this function
  289. * again. This may happen multiple times until a GEARMAN_WORK_ERROR,
  290. * GEARMAN_WORK_FAIL, or GEARMAN_SUCCESS (work complete) is returned. For
  291. * GEARMAN_WORK_DATA or GEARMAN_WORK_WARNING, the result_size will be set to
  292. * the intermediate data chunk being returned and an allocated data buffer
  293. * will be returned. For GEARMAN_WORK_STATUS, the caller can use
  294. * gearman_client_do_status() to get the current tasks status.
  295. * @return The result allocated by the library, this needs to be freed when the
  296. * caller is done using it.
  297. */
  298. GEARMAN_API
  299. void *gearman_client_do(gearman_client_st *client, const char *function_name,
  300. const char *unique, const void *workload,
  301. size_t workload_size, size_t *result_size,
  302. gearman_return_t *ret_ptr);
  303. /**
  304. * Run a high priority task and return an allocated result. See
  305. * gearman_client_do() for parameter and return information.
  306. */
  307. GEARMAN_API
  308. void *gearman_client_do_high(gearman_client_st *client,
  309. const char *function_name, const char *unique,
  310. const void *workload, size_t workload_size,
  311. size_t *result_size, gearman_return_t *ret_ptr);
  312. /**
  313. * Run a low priority task and return an allocated result. See
  314. * gearman_client_do() for parameter and return information.
  315. */
  316. GEARMAN_API
  317. void *gearman_client_do_low(gearman_client_st *client,
  318. const char *function_name, const char *unique,
  319. const void *workload, size_t workload_size,
  320. size_t *result_size, gearman_return_t *ret_ptr);
  321. /**
  322. * Get the job handle for the running task. This should be used between
  323. * repeated gearman_client_do() (and related) calls to get information.
  324. *
  325. * @param[in] client Structure previously initialized with
  326. * gearman_client_create() or gearman_client_clone().
  327. * @return Pointer to static buffer in the client structure that holds the job
  328. * handle.
  329. */
  330. GEARMAN_API
  331. const char *gearman_client_do_job_handle(gearman_client_st *client);
  332. // Deprecatd
  333. GEARMAN_API
  334. void gearman_client_do_status(gearman_client_st *client, uint32_t *numerator,
  335. uint32_t *denominator);
  336. /**
  337. * Run a task in the background.
  338. *
  339. * @param[in] client Structure previously initialized with
  340. * gearman_client_create() or gearman_client_clone().
  341. * @param[in] function_name The name of the function to run.
  342. * @param[in] unique Optional unique job identifier, or NULL for a new UUID.
  343. * @param[in] workload The workload to pass to the function when it is run.
  344. * @param[in] workload_size Size of the workload.
  345. * @param[out] job_handle A buffer to store the job handle in. Must be at least
  346. GEARMAN_JOB_HANDLE_SIZE bytes long.
  347. * @return Standard gearman return value.
  348. */
  349. GEARMAN_API
  350. gearman_return_t gearman_client_do_background(gearman_client_st *client,
  351. const char *function_name,
  352. const char *unique,
  353. const void *workload,
  354. size_t workload_size,
  355. gearman_job_handle_t job_handle);
  356. /**
  357. * Run a high priority task in the background. See
  358. * gearman_client_do_background() for parameter and return information.
  359. */
  360. GEARMAN_API
  361. gearman_return_t gearman_client_do_high_background(gearman_client_st *client,
  362. const char *function_name,
  363. const char *unique,
  364. const void *workload,
  365. size_t workload_size,
  366. gearman_job_handle_t job_handle);
  367. /**
  368. * Run a low priority task in the background. See
  369. * gearman_client_do_background() for parameter and return information.
  370. */
  371. GEARMAN_API
  372. gearman_return_t gearman_client_do_low_background(gearman_client_st *client,
  373. const char *function_name,
  374. const char *unique,
  375. const void *workload,
  376. size_t workload_size,
  377. gearman_job_handle_t job_handle);
  378. /**
  379. * Get the status for a backgound job.
  380. *
  381. * @param[in] client Structure previously initialized with
  382. * gearman_client_create() or gearman_client_clone().
  383. * @param[in] job_handle The job handle to get status for.
  384. * @param[out] is_known Optional parameter to store the known status in.
  385. * @param[out] is_running Optional parameter to store the running status in.
  386. * @param[out] numerator Optional parameter to store the numerator in.
  387. * @param[out] denominator Optional parameter to store the denominator in.
  388. * @return Standard gearman return value.
  389. */
  390. GEARMAN_API
  391. gearman_return_t gearman_client_job_status(gearman_client_st *client,
  392. const gearman_job_handle_t job_handle,
  393. bool *is_known, bool *is_running,
  394. uint32_t *numerator,
  395. uint32_t *denominator);
  396. /**
  397. * Send data to all job servers to see if they echo it back. This is a test
  398. * function to see if the job servers are responding properly.
  399. *
  400. * @param[in] client Structure previously initialized with
  401. * gearman_client_create() or gearman_client_clone().
  402. * @param[in] workload The workload to ask the server to echo back.
  403. * @param[in] workload_size Size of the workload.
  404. * @return Standard gearman return value.
  405. */
  406. GEARMAN_API
  407. gearman_return_t gearman_client_echo(gearman_client_st *client,
  408. const void *workload,
  409. size_t workload_size);
  410. /** @} */
  411. /**
  412. * @addtogroup gearman_client_concurrent Concurrent Task Interface
  413. * @ingroup gearman_client
  414. * Use the following set of functions to multiple run tasks concurrently.
  415. *
  416. * @ref main_page_client_concurrent "See Main Page for full details."
  417. * @{
  418. */
  419. /**
  420. * Free all tasks for a gearman structure.
  421. *
  422. * @param[in] client Structure previously initialized with
  423. * gearman_client_create() or gearman_client_clone().
  424. */
  425. GEARMAN_API
  426. void gearman_client_task_free_all(gearman_client_st *client);
  427. /**
  428. * Set function to call when tasks are being cleaned up so applications can
  429. * clean up the task context.
  430. *
  431. * @param[in] client Structure previously initialized with
  432. * gearman_client_create() or gearman_client_clone().
  433. * @param[in] function Function to call to clean up task context.
  434. */
  435. GEARMAN_API
  436. void gearman_client_set_task_context_free_fn(gearman_client_st *client,
  437. gearman_task_context_free_fn *function);
  438. /**
  439. * Add a task to be run in parallel.
  440. *
  441. * @param[in] client Structure previously initialized with
  442. * gearman_client_create() or gearman_client_clone().
  443. * @param[in] task Caller allocated structure, or NULL to allocate one.
  444. * @param[in] context Application context to associate with the task.
  445. * @param[in] function_name The name of the function to run.
  446. * @param[in] unique Optional unique job identifier, or NULL for a new UUID.
  447. * @param[in] workload The workload to pass to the function when it is run.
  448. * @param[in] workload_size Size of the workload.
  449. * @param[out] ret_ptr Standard gearman return value.
  450. * @return On success, a pointer to the (possibly allocated) structure. On
  451. * failure this will be NULL.
  452. */
  453. GEARMAN_API
  454. gearman_task_st *gearman_client_add_task(gearman_client_st *client,
  455. gearman_task_st *task,
  456. void *context,
  457. const char *function_name,
  458. const char *unique,
  459. const void *workload,
  460. size_t workload_size,
  461. gearman_return_t *ret_ptr);
  462. /**
  463. * Add a high priority task to be run in parallel. See
  464. * gearman_client_add_task() for details.
  465. */
  466. GEARMAN_API
  467. gearman_task_st *gearman_client_add_task_high(gearman_client_st *client,
  468. gearman_task_st *task,
  469. void *context,
  470. const char *function_name,
  471. const char *unique,
  472. const void *workload,
  473. size_t workload_size,
  474. gearman_return_t *ret_ptr);
  475. /**
  476. * Add a low priority task to be run in parallel. See
  477. * gearman_client_add_task() for details.
  478. */
  479. GEARMAN_API
  480. gearman_task_st *gearman_client_add_task_low(gearman_client_st *client,
  481. gearman_task_st *task,
  482. void *context,
  483. const char *function_name,
  484. const char *unique,
  485. const void *workload,
  486. size_t workload_size,
  487. gearman_return_t *ret_ptr);
  488. /**
  489. * Add a background task to be run in parallel. See
  490. * gearman_client_add_task() for details.
  491. */
  492. GEARMAN_API
  493. gearman_task_st *gearman_client_add_task_background(gearman_client_st *client,
  494. gearman_task_st *task,
  495. void *context,
  496. const char *function_name,
  497. const char *unique,
  498. const void *workload,
  499. size_t workload_size,
  500. gearman_return_t *ret_ptr);
  501. /**
  502. * Add a high priority background task to be run in parallel. See
  503. * gearman_client_add_task() for details.
  504. */
  505. GEARMAN_API
  506. gearman_task_st *
  507. gearman_client_add_task_high_background(gearman_client_st *client,
  508. gearman_task_st *task,
  509. void *context,
  510. const char *function_name,
  511. const char *unique,
  512. const void *workload,
  513. size_t workload_size,
  514. gearman_return_t *ret_ptr);
  515. /**
  516. * Add a low priority background task to be run in parallel. See
  517. * gearman_client_add_task() for details.
  518. */
  519. GEARMAN_API
  520. gearman_task_st *
  521. gearman_client_add_task_low_background(gearman_client_st *client,
  522. gearman_task_st *task,
  523. void *context,
  524. const char *function_name,
  525. const char *unique,
  526. const void *workload,
  527. size_t workload_size,
  528. gearman_return_t *ret_ptr);
  529. /**
  530. * Add task to get the status for a backgound task in parallel.
  531. *
  532. * @param[in] client Structure previously initialized with
  533. * gearman_client_create() or gearman_client_clone().
  534. * @param[in] task Caller allocated structure, or NULL to allocate one.
  535. * @param[in] context Application context to associate with the task.
  536. * @param[in] job_handle The job handle to get status for.
  537. * @param[out] ret_ptr Standard gearman return value.
  538. * @return On success, a pointer to the (possibly allocated) structure. On
  539. * failure this will be NULL.
  540. */
  541. GEARMAN_API
  542. gearman_task_st *gearman_client_add_task_status(gearman_client_st *client,
  543. gearman_task_st *task,
  544. void *context,
  545. const char *job_handle,
  546. gearman_return_t *ret_ptr);
  547. /**
  548. * Callback function when workload data needs to be sent for a task.
  549. *
  550. * @param[in] client Structure previously initialized with
  551. * gearman_client_create() or gearman_client_clone().
  552. * @param[in] function Function to call.
  553. */
  554. GEARMAN_API
  555. void gearman_client_set_workload_fn(gearman_client_st *client,
  556. gearman_workload_fn *function);
  557. /**
  558. * Callback function when a job has been created for a task.
  559. *
  560. * @param[in] client Structure previously initialized with
  561. * gearman_client_create() or gearman_client_clone().
  562. * @param[in] function Function to call.
  563. */
  564. GEARMAN_API
  565. void gearman_client_set_created_fn(gearman_client_st *client,
  566. gearman_created_fn *function);
  567. /**
  568. * Callback function when there is a data packet for a task.
  569. *
  570. * @param[in] client Structure previously initialized with
  571. * gearman_client_create() or gearman_client_clone().
  572. * @param[in] function Function to call.
  573. */
  574. GEARMAN_API
  575. void gearman_client_set_data_fn(gearman_client_st *client,
  576. gearman_data_fn *function);
  577. /**
  578. * Callback function when there is a warning packet for a task.
  579. *
  580. * @param[in] client Structure previously initialized with
  581. * gearman_client_create() or gearman_client_clone().
  582. * @param[in] function Function to call.
  583. */
  584. GEARMAN_API
  585. void gearman_client_set_warning_fn(gearman_client_st *client,
  586. gearman_warning_fn *function);
  587. /**
  588. * Callback function when there is a status packet for a task.
  589. *
  590. * @param[in] client Structure previously initialized with
  591. * gearman_client_create() or gearman_client_clone().
  592. * @param[in] function Function to call.
  593. */
  594. GEARMAN_API
  595. void gearman_client_set_status_fn(gearman_client_st *client,
  596. gearman_universal_status_fn *function);
  597. /**
  598. * Callback function when a task is complete.
  599. *
  600. * @param[in] client Structure previously initialized with
  601. * gearman_client_create() or gearman_client_clone().
  602. * @param[in] function Function to call.
  603. */
  604. GEARMAN_API
  605. void gearman_client_set_complete_fn(gearman_client_st *client,
  606. gearman_complete_fn *function);
  607. /**
  608. * Callback function when there is an exception packet for a task.
  609. *
  610. * @param[in] client Structure previously initialized with
  611. * gearman_client_create() or gearman_client_clone().
  612. * @param[in] function Function to call.
  613. */
  614. GEARMAN_API
  615. void gearman_client_set_exception_fn(gearman_client_st *client,
  616. gearman_exception_fn *function);
  617. /**
  618. * Callback function when a task has failed.
  619. *
  620. * @param[in] client Structure previously initialized with
  621. * gearman_client_create() or gearman_client_clone().
  622. * @param[in] function Function to call.
  623. */
  624. GEARMAN_API
  625. void gearman_client_set_fail_fn(gearman_client_st *client,
  626. gearman_fail_fn *function);
  627. /**
  628. * Clear all task callback functions.
  629. *
  630. * @param[in] client Structure previously initialized with
  631. * gearman_client_create() or gearman_client_clone().
  632. */
  633. GEARMAN_API
  634. void gearman_client_clear_fn(gearman_client_st *client);
  635. /**
  636. * Run tasks that have been added in parallel.
  637. *
  638. * @param[in] client Structure previously initialized with
  639. * gearman_client_create() or gearman_client_clone().
  640. * @return Standard gearman return value.
  641. */
  642. GEARMAN_API
  643. gearman_return_t gearman_client_run_tasks(gearman_client_st *client);
  644. GEARMAN_LOCAL
  645. gearman_return_t gearman_client_run_block_tasks(gearman_client_st *client);
  646. GEARMAN_API
  647. bool gearman_client_compare(const gearman_client_st *first, const gearman_client_st *second);
  648. GEARMAN_API
  649. bool gearman_client_set_server_option(gearman_client_st *self, const char *option_arg, size_t option_arg_size);
  650. GEARMAN_LOCAL
  651. size_t gearman_client_count_tasks(gearman_client_st *client);
  652. GEARMAN_API
  653. void gearman_client_set_namespace(gearman_client_st *self, const char *namespace_key, size_t namespace_key_size);
  654. /** @} */
  655. #ifdef __cplusplus
  656. }
  657. #endif