Gearman Developer Documentation

libgearman/worker.h
Go to the documentation of this file.
00001 /* Gearman server and library
00002  * Copyright (C) 2008 Brian Aker, Eric Day
00003  * All rights reserved.
00004  *
00005  * Use and distribution licensed under the BSD license.  See
00006  * the COPYING file in the parent directory for full text.
00007  */
00008 
00014 #ifndef __GEARMAN_WORKER_H__
00015 #define __GEARMAN_WORKER_H__
00016 
00017 #ifdef __cplusplus
00018 extern "C" {
00019 #endif
00020 
00033 struct gearman_worker_st
00034 {
00035   struct {
00036     bool allocated LIBGEARMAN_BITFIELD;
00037     bool non_blocking LIBGEARMAN_BITFIELD;
00038     bool packet_init LIBGEARMAN_BITFIELD;
00039     bool grab_job_in_use LIBGEARMAN_BITFIELD;
00040     bool pre_sleep_in_use LIBGEARMAN_BITFIELD;
00041     bool work_job_in_use LIBGEARMAN_BITFIELD;
00042     bool change LIBGEARMAN_BITFIELD;
00043     bool grab_uniq LIBGEARMAN_BITFIELD;
00044     bool timeout_return LIBGEARMAN_BITFIELD;
00045   } options;
00046   enum {
00047     GEARMAN_WORKER_STATE_START,
00048     GEARMAN_WORKER_STATE_FUNCTION_SEND,
00049     GEARMAN_WORKER_STATE_CONNECT,
00050     GEARMAN_WORKER_STATE_GRAB_JOB_SEND,
00051     GEARMAN_WORKER_STATE_GRAB_JOB_RECV,
00052     GEARMAN_WORKER_STATE_PRE_SLEEP
00053   } state;
00054   enum {
00055     GEARMAN_WORKER_WORK_UNIVERSAL_GRAB_JOB,
00056     GEARMAN_WORKER_WORK_UNIVERSAL_FUNCTION,
00057     GEARMAN_WORKER_WORK_UNIVERSAL_COMPLETE,
00058     GEARMAN_WORKER_WORK_UNIVERSAL_FAIL
00059   } work_state;
00060   uint32_t function_count;
00061   uint32_t job_count;
00062   size_t work_result_size;
00063   void *context;
00064   gearman_connection_st *con;
00065   gearman_job_st *job;
00066   gearman_job_st *job_list;
00067   struct _worker_function_st *function;
00068   struct _worker_function_st *function_list;
00069   struct _worker_function_st *work_function;
00070   void *work_result;
00071   gearman_universal_st universal;
00072   gearman_packet_st grab_job;
00073   gearman_packet_st pre_sleep;
00074   gearman_job_st work_job;
00075 };
00076 
00077 
00087 GEARMAN_API
00088 gearman_worker_st *gearman_worker_create(gearman_worker_st *worker);
00089 
00097 GEARMAN_API
00098 gearman_worker_st *gearman_worker_clone(gearman_worker_st *worker,
00099                                         const gearman_worker_st *from);
00100 
00107 GEARMAN_API
00108 void gearman_worker_free(gearman_worker_st *worker);
00109 
00113 GEARMAN_API
00114 const char *gearman_worker_error(gearman_worker_st *worker);
00115 
00119 GEARMAN_API
00120 int gearman_worker_errno(gearman_worker_st *worker);
00121 
00129 GEARMAN_API
00130 gearman_worker_options_t gearman_worker_options(const gearman_worker_st *worker);
00131 
00139 GEARMAN_API
00140 void gearman_worker_set_options(gearman_worker_st *worker,
00141                                 gearman_worker_options_t options);
00142 
00150 GEARMAN_API
00151 void gearman_worker_add_options(gearman_worker_st *worker,
00152                                 gearman_worker_options_t options);
00153 
00161 GEARMAN_API
00162 void gearman_worker_remove_options(gearman_worker_st *worker,
00163                                    gearman_worker_options_t options);
00164 
00168 GEARMAN_API
00169 int gearman_worker_timeout(gearman_worker_st *worker);
00170 
00174 GEARMAN_API
00175 void gearman_worker_set_timeout(gearman_worker_st *worker, int timeout);
00176 
00184 GEARMAN_API
00185 void *gearman_worker_context(const gearman_worker_st *worker);
00186 
00194 GEARMAN_API
00195 void gearman_worker_set_context(gearman_worker_st *worker, void *context);
00196 
00200 GEARMAN_API
00201 void gearman_worker_set_log_fn(gearman_worker_st *worker,
00202                                gearman_log_fn *function, void *context,
00203                                gearman_verbose_t verbose);
00204 
00208 GEARMAN_API
00209 void gearman_worker_set_workload_malloc_fn(gearman_worker_st *worker,
00210                                            gearman_malloc_fn *function,
00211                                            void *context);
00212 
00223 GEARMAN_API
00224 void gearman_worker_set_workload_free_fn(gearman_worker_st *worker,
00225                                          gearman_free_fn *function,
00226                                          void *context);
00227 
00238 GEARMAN_API
00239 gearman_return_t gearman_worker_add_server(gearman_worker_st *worker,
00240                                            const char *host, in_port_t port);
00241 
00254 GEARMAN_API
00255 gearman_return_t gearman_worker_add_servers(gearman_worker_st *worker,
00256                                             const char *servers);
00257 
00264 GEARMAN_API
00265 void gearman_worker_remove_servers(gearman_worker_st *worker);
00266 
00274 GEARMAN_API
00275 gearman_return_t gearman_worker_wait(gearman_worker_st *worker);
00276 
00290 GEARMAN_API
00291 gearman_return_t gearman_worker_register(gearman_worker_st *worker,
00292                                          const char *function_name,
00293                                          uint32_t timeout);
00294 
00303 GEARMAN_API
00304 gearman_return_t gearman_worker_unregister(gearman_worker_st *worker,
00305                                            const char *function_name);
00306 
00314 GEARMAN_API
00315 gearman_return_t gearman_worker_unregister_all(gearman_worker_st *worker);
00316 
00330 GEARMAN_API
00331 gearman_job_st *gearman_worker_grab_job(gearman_worker_st *worker,
00332                                         gearman_job_st *job,
00333                                         gearman_return_t *ret_ptr);
00334 
00341 GEARMAN_API
00342 void gearman_job_free_all(gearman_worker_st *worker);
00343 
00352 GEARMAN_API
00353 bool gearman_worker_function_exist(gearman_worker_st *worker,
00354                                    const char *function_name,
00355                                    size_t function_length);
00356 
00372 GEARMAN_API
00373 gearman_return_t gearman_worker_add_function(gearman_worker_st *worker,
00374                                              const char *function_name,
00375                                              uint32_t timeout,
00376                                              gearman_worker_fn *function,
00377                                              void *context);
00378 
00386 GEARMAN_API
00387 gearman_return_t gearman_worker_work(gearman_worker_st *worker);
00388 
00399 GEARMAN_API
00400 gearman_return_t gearman_worker_echo(gearman_worker_st *worker,
00401                                      const void *workload,
00402                                      size_t workload_size);
00403 
00406 #ifdef __cplusplus
00407 }
00408 #endif
00409 
00410 #endif /* __GEARMAN_WORKER_H__ */