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 
40 
41 #pragma once
42 
43 #include <libgearman-1.0/priority.h>
44 #include <libgearman-1.0/protocol.h>
45 #include <libgearman-1.0/return.h>
46 #include <libgearman-1.0/limits.h>
47 
48 #ifdef __cplusplus
49 extern "C" {
50 #endif
51 
52 /**
53  * @addtogroup gearman_constants Constants
54  * @ingroup gearman_universal
55  * @ingroup gearman_client
56  * @ingroup gearman_worker
57  * @{
58  */
59 
60 /**
61  * Verbosity levels.
62  */
63 typedef enum
64 {
65   GEARMAN_VERBOSE_NEVER,
66   GEARMAN_VERBOSE_FATAL,
67   GEARMAN_VERBOSE_ERROR,
68   GEARMAN_VERBOSE_INFO,
69   GEARMAN_VERBOSE_DEBUG,
70   GEARMAN_VERBOSE_CRAZY,
71   GEARMAN_VERBOSE_MAX
72 } gearman_verbose_t;
73 
74 /** @} */
75 
76 /**
77  * @ingroup gearman_universal
78  * Options for gearman_universal_st.
79  */
80 typedef enum
81 {
82   GEARMAN_NON_BLOCKING,
83   GEARMAN_DONT_TRACK_PACKETS,
84   GEARMAN_MAX
85 } gearman_universal_options_t;
86 
87 /**
88  * @ingroup gearman_con
89  * Options for gearman_connection_st.
90  */
91 typedef enum
92 {
93   GEARMAN_CON_READY,
94   GEARMAN_CON_PACKET_IN_USE,
95   GEARMAN_CON_EXTERNAL_FD,
96   GEARMAN_CON_IGNORE_LOST_CONNECTION,
97   GEARMAN_CON_CLOSE_AFTER_FLUSH,
98   GEARMAN_CON_MAX
99 } gearman_connection_options_t;
100 
101 /**
102  * @ingroup gearman_client
103  * Options for gearman_client_st.
104  */
105 typedef enum
106 {
107   GEARMAN_CLIENT_ALLOCATED=         (1 << 0),
108   GEARMAN_CLIENT_NON_BLOCKING=      (1 << 1),
109   GEARMAN_CLIENT_TASK_IN_USE=       (1 << 2),
110   GEARMAN_CLIENT_UNBUFFERED_RESULT= (1 << 3),
111   GEARMAN_CLIENT_NO_NEW=            (1 << 4),
112   GEARMAN_CLIENT_FREE_TASKS=        (1 << 5),
113   GEARMAN_CLIENT_GENERATE_UNIQUE=   (1 << 6),
114   GEARMAN_CLIENT_MAX=               (1 << 7)
115 } gearman_client_options_t;
116 
117 /**
118  * @ingroup gearman_worker
119  * Options for gearman_worker_st.
120  */
121 typedef enum
122 {
123   GEARMAN_WORKER_ALLOCATED=        (1 << 0),
124   GEARMAN_WORKER_NON_BLOCKING=     (1 << 1),
125   GEARMAN_WORKER_PACKET_INIT=      (1 << 2),
126   GEARMAN_WORKER_GRAB_JOB_IN_USE=  (1 << 3),
127   GEARMAN_WORKER_PRE_SLEEP_IN_USE= (1 << 4),
128   GEARMAN_WORKER_WORK_JOB_IN_USE=  (1 << 5),
129   GEARMAN_WORKER_CHANGE=           (1 << 6),
130   GEARMAN_WORKER_GRAB_UNIQ=        (1 << 7),
131   GEARMAN_WORKER_TIMEOUT_RETURN=   (1 << 8),
132   GEARMAN_WORKER_GRAB_ALL=   (1 << 9),
133   GEARMAN_WORKER_MAX=   (1 << 10)
134 } gearman_worker_options_t;
135 
136 /* Types. */
137 typedef struct gearman_packet_st gearman_packet_st;
138 typedef struct gearman_task_st gearman_task_st;
139 typedef struct gearman_client_st gearman_client_st;
140 typedef struct gearman_job_st gearman_job_st;
141 typedef struct gearman_worker_st gearman_worker_st;
142 typedef struct gearman_allocator_t gearman_allocator_t;
143 typedef struct gearman_task_attr_t gearman_task_attr_t;
144 typedef struct gearman_result_st gearman_result_st;
145 typedef struct gearman_string_t gearman_string_t;
146 typedef struct gearman_argument_t gearman_argument_t;
147 typedef struct gearman_status_t gearman_status_t;
148 
149 // Custom allocators
150 typedef void* (gearman_malloc_fn)(size_t size, void *context);
151 typedef void* (gearman_realloc_fn)(void *ptr, size_t size, void *context);
152 typedef void* (gearman_calloc_fn)(size_t nelm, size_t size, void *context);
153 typedef void (gearman_free_fn)(void *ptr, void *context);
154 
155 
156 typedef gearman_return_t (gearman_parse_server_fn)(const char *host, in_port_t port, void *context);
157 
158 typedef void (gearman_task_context_free_fn)(gearman_task_st *task, void *context);
159 
160 typedef void (gearman_log_fn)(const char *line, gearman_verbose_t verbose, void *context);
161 
162 
163 // Worker types
164 
165 typedef void* (gearman_worker_fn)(gearman_job_st *job, void *context,
166                                   size_t *result_size,
167                                   gearman_return_t *ret_ptr);
168 
169 typedef gearman_return_t (gearman_function_fn)(gearman_job_st *job, void *worker_context);
170 
171 typedef struct gearman_aggregator_st gearman_aggregator_st;
172 typedef gearman_return_t (gearman_aggregator_fn)(gearman_aggregator_st *, gearman_task_st *, gearman_result_st *);
173 
174 /** @} */
175 
176 #ifdef __cplusplus
177 }
178 #endif
179