Gearman Public API Documentation

libgearman/constants.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_CONSTANTS_H__
00015 #define __GEARMAN_CONSTANTS_H__
00016 
00017 #ifdef __cplusplus
00018 extern "C" {
00019 #endif
00020 
00029 /* Defines. */
00030 #define GEARMAN_DEFAULT_TCP_HOST "127.0.0.1"
00031 #define GEARMAN_DEFAULT_TCP_PORT 4730
00032 #define GEARMAN_DEFAULT_SOCKET_TIMEOUT 10
00033 #define GEARMAN_DEFAULT_SOCKET_SEND_SIZE 32768
00034 #define GEARMAN_DEFAULT_SOCKET_RECV_SIZE 32768
00035 #define GEARMAN_MAX_ERROR_SIZE 1024
00036 #define GEARMAN_PACKET_HEADER_SIZE 12
00037 #define GEARMAN_JOB_HANDLE_SIZE 64
00038 #define GEARMAN_OPTION_SIZE 64
00039 #define GEARMAN_UNIQUE_SIZE 64
00040 #define GEARMAN_MAX_COMMAND_ARGS 8
00041 #define GEARMAN_ARGS_BUFFER_SIZE 128
00042 #define GEARMAN_SEND_BUFFER_SIZE 8192
00043 #define GEARMAN_RECV_BUFFER_SIZE 8192
00044 #define GEARMAN_WORKER_WAIT_TIMEOUT (10 * 1000) /* Milliseconds */
00045 
00049 typedef enum
00050 {
00051   GEARMAN_SUCCESS,
00052   GEARMAN_IO_WAIT,
00053   GEARMAN_SHUTDOWN,
00054   GEARMAN_SHUTDOWN_GRACEFUL,
00055   GEARMAN_ERRNO,
00056   GEARMAN_EVENT,
00057   GEARMAN_TOO_MANY_ARGS,
00058   GEARMAN_NO_ACTIVE_FDS,
00059   GEARMAN_INVALID_MAGIC,
00060   GEARMAN_INVALID_COMMAND,
00061   GEARMAN_INVALID_PACKET,
00062   GEARMAN_UNEXPECTED_PACKET,
00063   GEARMAN_GETADDRINFO,
00064   GEARMAN_NO_SERVERS,
00065   GEARMAN_LOST_CONNECTION,
00066   GEARMAN_MEMORY_ALLOCATION_FAILURE,
00067   GEARMAN_JOB_EXISTS,
00068   GEARMAN_JOB_QUEUE_FULL,
00069   GEARMAN_SERVER_ERROR,
00070   GEARMAN_WORK_ERROR,
00071   GEARMAN_WORK_DATA,
00072   GEARMAN_WORK_WARNING,
00073   GEARMAN_WORK_STATUS,
00074   GEARMAN_WORK_EXCEPTION,
00075   GEARMAN_WORK_FAIL,
00076   GEARMAN_NOT_CONNECTED,
00077   GEARMAN_COULD_NOT_CONNECT,
00078   GEARMAN_SEND_IN_PROGRESS,
00079   GEARMAN_RECV_IN_PROGRESS,
00080   GEARMAN_NOT_FLUSHING,
00081   GEARMAN_DATA_TOO_LARGE,
00082   GEARMAN_INVALID_FUNCTION_NAME,
00083   GEARMAN_INVALID_WORKER_FUNCTION,
00084   GEARMAN_NO_REGISTERED_FUNCTION,
00085   GEARMAN_NO_REGISTERED_FUNCTIONS,
00086   GEARMAN_NO_JOBS,
00087   GEARMAN_ECHO_DATA_CORRUPTION,
00088   GEARMAN_NEED_WORKLOAD_FN,
00089   GEARMAN_PAUSE,
00090   GEARMAN_UNKNOWN_STATE,
00091   GEARMAN_PTHREAD,
00092   GEARMAN_PIPE_EOF,
00093   GEARMAN_QUEUE_ERROR,
00094   GEARMAN_FLUSH_DATA,
00095   GEARMAN_SEND_BUFFER_TOO_SMALL,
00096   GEARMAN_IGNORE_PACKET,
00097   GEARMAN_UNKNOWN_OPTION,
00098   GEARMAN_TIMEOUT,
00099   GEARMAN_ARGUMENT_TOO_LARGE,
00100   GEARMAN_MAX_RETURN /* Always add new error code before */
00101 } gearman_return_t;
00102 
00106 typedef enum
00107 {
00108   GEARMAN_VERBOSE_NEVER,
00109   GEARMAN_VERBOSE_FATAL,
00110   GEARMAN_VERBOSE_ERROR,
00111   GEARMAN_VERBOSE_INFO,
00112   GEARMAN_VERBOSE_DEBUG,
00113   GEARMAN_VERBOSE_CRAZY,
00114   GEARMAN_VERBOSE_MAX
00115 } gearman_verbose_t;
00116 
00123 typedef enum
00124 {
00125   GEARMAN_NON_BLOCKING,
00126   GEARMAN_DONT_TRACK_PACKETS,
00127   GEARMAN_MAX
00128 } gearman_universal_options_t;
00129 
00134 typedef enum
00135 {
00136   GEARMAN_CON_READY,
00137   GEARMAN_CON_PACKET_IN_USE,
00138   GEARMAN_CON_EXTERNAL_FD,
00139   GEARMAN_CON_IGNORE_LOST_CONNECTION,
00140   GEARMAN_CON_CLOSE_AFTER_FLUSH,
00141   GEARMAN_CON_MAX
00142 } gearman_connection_options_t;
00143 
00149 typedef enum
00150 {
00151   GEARMAN_COMMAND_TEXT,
00152   GEARMAN_COMMAND_CAN_DO,              /* W->J: FUNC */
00153   GEARMAN_COMMAND_CANT_DO,             /* W->J: FUNC */
00154   GEARMAN_COMMAND_RESET_ABILITIES,     /* W->J: -- */
00155   GEARMAN_COMMAND_PRE_SLEEP,           /* W->J: -- */
00156   GEARMAN_COMMAND_UNUSED,
00157   GEARMAN_COMMAND_NOOP,                /* J->W: -- */
00158   GEARMAN_COMMAND_SUBMIT_JOB,          /* C->J: FUNC[0]UNIQ[0]ARGS */
00159   GEARMAN_COMMAND_JOB_CREATED,         /* J->C: HANDLE  */
00160   GEARMAN_COMMAND_GRAB_JOB,            /* W->J: --  */
00161   GEARMAN_COMMAND_NO_JOB,              /* J->W: -- */
00162   GEARMAN_COMMAND_JOB_ASSIGN,          /* J->W: HANDLE[0]FUNC[0]ARG  */
00163   GEARMAN_COMMAND_WORK_STATUS,         /* W->J/C: HANDLE[0]NUMERATOR[0]DENOMINATOR */
00164   GEARMAN_COMMAND_WORK_COMPLETE,       /* W->J/C: HANDLE[0]RES */
00165   GEARMAN_COMMAND_WORK_FAIL,           /* W->J/C: HANDLE */
00166   GEARMAN_COMMAND_GET_STATUS,          /* C->J: HANDLE */
00167   GEARMAN_COMMAND_ECHO_REQ,            /* ?->J: TEXT */
00168   GEARMAN_COMMAND_ECHO_RES,            /* J->?: TEXT */
00169   GEARMAN_COMMAND_SUBMIT_JOB_BG,       /* C->J: FUNC[0]UNIQ[0]ARGS  */
00170   GEARMAN_COMMAND_ERROR,               /* J->?: ERRCODE[0]ERR_TEXT */
00171   GEARMAN_COMMAND_STATUS_RES,          /* C->J: HANDLE[0]KNOWN[0]RUNNING[0]NUM[0]DENOM */
00172   GEARMAN_COMMAND_SUBMIT_JOB_HIGH,     /* C->J: FUNC[0]UNIQ[0]ARGS  */
00173   GEARMAN_COMMAND_SET_CLIENT_ID,       /* W->J: [RANDOM_STRING_NO_WHITESPACE] */
00174   GEARMAN_COMMAND_CAN_DO_TIMEOUT,      /* W->J: FUNC[0]TIMEOUT */
00175   GEARMAN_COMMAND_ALL_YOURS,
00176   GEARMAN_COMMAND_WORK_EXCEPTION,
00177   GEARMAN_COMMAND_OPTION_REQ,
00178   GEARMAN_COMMAND_OPTION_RES,
00179   GEARMAN_COMMAND_WORK_DATA,
00180   GEARMAN_COMMAND_WORK_WARNING,
00181   GEARMAN_COMMAND_GRAB_JOB_UNIQ,
00182   GEARMAN_COMMAND_JOB_ASSIGN_UNIQ,
00183   GEARMAN_COMMAND_SUBMIT_JOB_HIGH_BG,
00184   GEARMAN_COMMAND_SUBMIT_JOB_LOW,
00185   GEARMAN_COMMAND_SUBMIT_JOB_LOW_BG,
00186   GEARMAN_COMMAND_SUBMIT_JOB_SCHED,
00187   GEARMAN_COMMAND_SUBMIT_JOB_EPOCH,
00188   GEARMAN_COMMAND_MAX /* Always add new commands before this. */
00189 } gearman_command_t;
00190 
00195 typedef enum
00196 {
00197   GEARMAN_JOB_PRIORITY_HIGH,
00198   GEARMAN_JOB_PRIORITY_NORMAL,
00199   GEARMAN_JOB_PRIORITY_LOW,
00200   GEARMAN_JOB_PRIORITY_MAX /* Always add new commands before this. */
00201 } gearman_job_priority_t;
00202 
00207 typedef enum
00208 {
00209   GEARMAN_CLIENT_ALLOCATED=         (1 << 0),
00210   GEARMAN_CLIENT_NON_BLOCKING=      (1 << 1),
00211   GEARMAN_CLIENT_TASK_IN_USE=       (1 << 2),
00212   GEARMAN_CLIENT_UNBUFFERED_RESULT= (1 << 3),
00213   GEARMAN_CLIENT_NO_NEW=            (1 << 4),
00214   GEARMAN_CLIENT_FREE_TASKS=        (1 << 5),
00215   GEARMAN_CLIENT_MAX=               (1 << 6)
00216 } gearman_client_options_t;
00217 
00222 typedef enum
00223 {
00224   GEARMAN_WORKER_ALLOCATED=        (1 << 0),
00225   GEARMAN_WORKER_NON_BLOCKING=     (1 << 1),
00226   GEARMAN_WORKER_PACKET_INIT=      (1 << 2),
00227   GEARMAN_WORKER_GRAB_JOB_IN_USE=  (1 << 3),
00228   GEARMAN_WORKER_PRE_SLEEP_IN_USE= (1 << 4),
00229   GEARMAN_WORKER_WORK_JOB_IN_USE=  (1 << 5),
00230   GEARMAN_WORKER_CHANGE=           (1 << 6),
00231   GEARMAN_WORKER_GRAB_UNIQ=        (1 << 7),
00232   GEARMAN_WORKER_TIMEOUT_RETURN=   (1 << 8),
00233   GEARMAN_WORKER_MAX=   (1 << 9)
00234 } gearman_worker_options_t;
00235 
00244 /* Types. */
00245 typedef struct gearman_universal_st gearman_universal_st;
00246 typedef struct gearman_connection_st gearman_connection_st;
00247 typedef struct gearman_packet_st gearman_packet_st;
00248 typedef struct gearman_command_info_st gearman_command_info_st;
00249 typedef struct gearman_task_st gearman_task_st;
00250 typedef struct gearman_client_st gearman_client_st;
00251 typedef struct gearman_job_st gearman_job_st;
00252 typedef struct gearman_worker_st gearman_worker_st;
00253 
00254 /* Function types. */
00255 typedef gearman_return_t (gearman_workload_fn)(gearman_task_st *task);
00256 typedef gearman_return_t (gearman_created_fn)(gearman_task_st *task);
00257 typedef gearman_return_t (gearman_data_fn)(gearman_task_st *task);
00258 typedef gearman_return_t (gearman_warning_fn)(gearman_task_st *task);
00259 typedef gearman_return_t (gearman_universal_status_fn)(gearman_task_st *task);
00260 typedef gearman_return_t (gearman_complete_fn)(gearman_task_st *task);
00261 typedef gearman_return_t (gearman_exception_fn)(gearman_task_st *task);
00262 typedef gearman_return_t (gearman_fail_fn)(gearman_task_st *task);
00263 
00264 typedef gearman_return_t (gearman_parse_server_fn)(const char *host,
00265                                                    in_port_t port,
00266                                                    void *context);
00267 
00268 typedef void* (gearman_worker_fn)(gearman_job_st *job, void *context,
00269                                   size_t *result_size,
00270                                   gearman_return_t *ret_ptr);
00271 
00275 typedef gearman_return_t (gearman_event_watch_fn)(gearman_connection_st *con,
00276                                                   short events, void *context);
00277 
00278 typedef void* (gearman_malloc_fn)(size_t size, void *context);
00279 typedef void (gearman_free_fn)(void *ptr, void *context);
00280 
00281 typedef void (gearman_task_context_free_fn)(gearman_task_st *task,
00282                                             void *context);
00283 
00284 typedef void (gearman_log_fn)(const char *line, gearman_verbose_t verbose,
00285                               void *context);
00286 
00287 typedef void (gearman_connection_protocol_context_free_fn)(gearman_connection_st *con,
00288                                                            void *context);
00289 
00290 typedef size_t (gearman_packet_pack_fn)(const gearman_packet_st *packet,
00291                                         gearman_connection_st *con,
00292                                         void *data, size_t data_size,
00293                                         gearman_return_t *ret_ptr);
00294 typedef size_t (gearman_packet_unpack_fn)(gearman_packet_st *packet,
00295                                           gearman_connection_st *con, const void *data,
00296                                           size_t data_size,
00297                                           gearman_return_t *ret_ptr);
00298 
00301 #ifdef __cplusplus
00302 }
00303 #endif
00304 
00305 #endif /* __GEARMAN_CONSTANTS_H__ */