1 /*  vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
2  *
3  *  Gearmand client and server library.
4  *
5  *  Copyright (C) 2011-2012 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  * @file
41  * @brief Packet Declarations
42  */
43 
44 #pragma once
45 
46 #include <libgearman-server/struct/packet.h>
47 
48 #include <libgearman-1.0/protocol.h>
49 
50 #ifdef __cplusplus
51 extern "C" {
52 #endif
53 
54 /**
55  * @addtogroup gearman_server_packet Packet Declarations
56  * @ingroup gearman_server
57  *
58  * This is a low level interface for gearman server connections. This is used
59  * internally by the server interface, so you probably want to look there first.
60  *
61  * @{
62  */
63 
64 
65 /**
66  * Initialize a server packet structure.
67  */
68 GEARMAN_API
69 gearman_server_packet_st *
70 gearman_server_packet_create(gearman_server_thread_st *thread,
71                              bool from_thread);
72 
73 GEARMAN_LOCAL
74 const char *gearmand_strcommand(gearmand_packet_st *packet);
75 
76 /**
77  * Free a server connection structure.
78  */
79 GEARMAN_API
80 void gearman_server_packet_free(gearman_server_packet_st *packet,
81                                 gearman_server_thread_st *thread,
82                                 bool from_thread);
83 
84 /**
85  * Add a server packet structure to io queue for a connection.
86  */
87 GEARMAN_API
88 gearmand_error_t gearman_server_io_packet_add(gearman_server_con_st *con,
89                                               bool take_data,
90                                               enum gearman_magic_t magic,
91                                               gearman_command_t command,
92                                               const void *arg, ...);
93 
94 /**
95  * Remove the first server packet structure from io queue for a connection.
96  */
97 GEARMAN_API
98 void gearman_server_io_packet_remove(gearman_server_con_st *con);
99 
100 /**
101  * Add a server packet structure to proc queue for a connection.
102  */
103 GEARMAN_API
104 void gearman_server_proc_packet_add(gearman_server_con_st *con,
105                                     gearman_server_packet_st *packet);
106 
107 /**
108  * Remove the first server packet structure from proc queue for a connection.
109  */
110 GEARMAN_API
111 gearman_server_packet_st *
112 gearman_server_proc_packet_remove(gearman_server_con_st *con);
113 
114 
115 /**
116  * Initialize a packet structure.
117  *
118  * @param[in] gearman Structure previously initialized with gearman_create() or
119  *  gearman_clone().
120  * @param[in] packet Caller allocated structure, or NULL to allocate one.
121  * @return On success, a pointer to the (possibly allocated) structure. On
122  *  failure this will be NULL.
123  */
124 GEARMAN_INTERNAL_API
125 void gearmand_packet_init(gearmand_packet_st *packet, enum gearman_magic_t magic, gearman_command_t command);
126 
127 /**
128  * Free a packet structure.
129  *
130  * @param[in] packet Structure previously initialized with
131  *   gearmand_packet_init() or gearmand_packet_creates().
132  */
133 GEARMAN_INTERNAL_API
134 void gearmand_packet_free(gearmand_packet_st *packet);
135 
136 /**
137  * Add an argument to a packet.
138  */
139 GEARMAN_INTERNAL_API
140   gearmand_error_t gearmand_packet_create(gearmand_packet_st *packet,
141                                               const void *arg, size_t arg_size);
142 
143 /**
144  * Pack header.
145  */
146 GEARMAN_INTERNAL_API
147   gearmand_error_t gearmand_packet_pack_header(gearmand_packet_st *packet);
148 
149 void destroy_gearman_server_packet_st(gearman_server_packet_st *packet);
150 
151 /** @} */
152 
153 #ifdef __cplusplus
154 }
155 #endif
156