client.h 28 KB

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