]> git.proxmox.com Git - ceph.git/blame - ceph/src/jaegertracing/thrift/lib/c_glib/src/thrift/c_glib/thrift_application_exception.c
buildsys: switch source download to quincy
[ceph.git] / ceph / src / jaegertracing / thrift / lib / c_glib / src / thrift / c_glib / thrift_application_exception.c
CommitLineData
f67539c2
TL
1/*
2 * Licensed to the Apache Software Foundation (ASF) under one
3 * or more contributor license agreements. See the NOTICE file
4 * distributed with this work for additional information
5 * regarding copyright ownership. The ASF licenses this file
6 * to you under the Apache License, Version 2.0 (the
7 * "License"); you may not use this file except in compliance
8 * with the License. You may obtain a copy of the License at
9 *
10 * http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing,
13 * software distributed under the License is distributed on an
14 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 * KIND, either express or implied. See the License for the
16 * specific language governing permissions and limitations
17 * under the License.
18 */
19
20#include "thrift_application_exception.h"
21#include <thrift/c_glib/protocol/thrift_protocol.h>
22
23/* object properties */
24enum _ThriftApplicationExceptionProperties
25{
26 PROP_0,
27 PROP_THRIFT_APPLICATION_EXCEPTION_TYPE,
28 PROP_THRIFT_APPLICATION_EXCEPTION_MESSAGE
29};
30
31G_DEFINE_TYPE(ThriftApplicationException, thrift_application_exception, THRIFT_TYPE_STRUCT)
32
33gint32
34thrift_application_exception_read (ThriftStruct *object,
35 ThriftProtocol *protocol, GError **error)
36{
37 gint32 ret;
38 gint32 xfer = 0;
39 gchar *name;
40 ThriftType ftype;
41 gint16 fid;
42 ThriftApplicationException *this = THRIFT_APPLICATION_EXCEPTION (object);
43
44 /* read the struct begin marker */
45 if ((ret = thrift_protocol_read_struct_begin (protocol, &name, error)) < 0)
46 {
47 if (name) g_free (name);
48 return -1;
49 }
50 xfer += ret;
51 if (name) g_free (name);
52
53 while (1)
54 {
55 if ((ret = thrift_protocol_read_field_begin (protocol, &name, &ftype,
56 &fid, error)) < 0)
57 {
58 if (name) g_free (name);
59 return -1;
60 }
61 xfer += ret;
62 if (name) g_free (name);
63
64 /* break if we get a STOP field */
65 if (ftype == T_STOP)
66 {
67 break;
68 }
69
70 switch (fid)
71 {
72 case 1:
73 if (ftype == T_STRING)
74 {
75 if ((ret = thrift_protocol_read_string (protocol, &this->message,
76 error)) < 0)
77 return -1;
78 xfer += ret;
79 this->__isset_message = TRUE;
80 } else {
81 if ((ret = thrift_protocol_skip (protocol, ftype, error)) < 0)
82 return -1;
83 xfer += ret;
84 }
85 break;
86 case 2:
87 if (ftype == T_I32)
88 {
89 if ((ret = thrift_protocol_read_i32 (protocol, &this->type,
90 error)) < 0)
91 return -1;
92 xfer += ret;
93 this->__isset_type = TRUE;
94 } else {
95 if ((ret = thrift_protocol_skip (protocol, ftype, error)) < 0)
96 return -1;
97 xfer += ret;
98 }
99 break;
100 default:
101 if ((ret = thrift_protocol_skip (protocol, ftype, error)) < 0)
102 return -1;
103 xfer += ret;
104 break;
105 }
106 if ((ret = thrift_protocol_read_field_end (protocol, error)) < 0)
107 return -1;
108 xfer += ret;
109 }
110
111 if ((ret = thrift_protocol_read_struct_end (protocol, error)) < 0)
112 return -1;
113 xfer += ret;
114
115 return xfer;
116}
117
118gint32
119thrift_application_exception_write (ThriftStruct *object,
120 ThriftProtocol *protocol, GError **error)
121{
122 gint32 ret;
123 gint32 xfer = 0;
124
125 ThriftApplicationException *this = THRIFT_APPLICATION_EXCEPTION (object);
126
127 if ((ret = thrift_protocol_write_struct_begin (protocol,
128 "TApplicationException",
129 error)) < 0)
130 return -1;
131 xfer += ret;
132 if ((ret = thrift_protocol_write_field_begin (protocol, "message",
133 T_STRING, 1, error)) < 0)
134 return -1;
135 xfer += ret;
136 if ((ret = thrift_protocol_write_string (protocol, this->message, error)) < 0)
137 return -1;
138 xfer += ret;
139 if ((ret = thrift_protocol_write_field_end (protocol, error)) < 0)
140 return -1;
141 xfer += ret;
142 if ((ret = thrift_protocol_write_field_begin (protocol, "type",
143 T_I32, 2, error)) < 0)
144 return -1;
145 xfer += ret;
146 if ((ret = thrift_protocol_write_i32 (protocol, this->type, error)) < 0)
147 return -1;
148 xfer += ret;
149 if ((ret = thrift_protocol_write_field_end (protocol, error)) < 0)
150 return -1;
151 xfer += ret;
152 if ((ret = thrift_protocol_write_field_stop (protocol, error)) < 0)
153 return -1;
154 xfer += ret;
155 if ((ret = thrift_protocol_write_struct_end (protocol, error)) < 0)
156 return -1;
157 xfer += ret;
158
159 return xfer;
160}
161
162
163/* GError domain */
164#define THRIFT_APPLICATION_EXCEPTION_ERROR_DOMAIN "thrift-application-exception-error-quark"
165
166GQuark
167thrift_application_exception_error_quark (void)
168{
169 return g_quark_from_static_string (THRIFT_APPLICATION_EXCEPTION_ERROR_DOMAIN);
170}
171
172static void
173thrift_application_exception_get_property (GObject *object,
174 guint property_id,
175 GValue *value,
176 GParamSpec *pspec)
177{
178 ThriftApplicationException *tae = THRIFT_APPLICATION_EXCEPTION (object);
179
180 switch (property_id)
181 {
182 case PROP_THRIFT_APPLICATION_EXCEPTION_TYPE:
183 g_value_set_int (value, tae->type);
184 break;
185 case PROP_THRIFT_APPLICATION_EXCEPTION_MESSAGE:
186 g_value_set_string (value, tae->message);
187 break;
188 default:
189 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
190 break;
191 }
192}
193
194static void
195thrift_application_exception_set_property (GObject *object,
196 guint property_id,
197 const GValue *value,
198 GParamSpec *pspec)
199{
200 ThriftApplicationException *tae = THRIFT_APPLICATION_EXCEPTION (object);
201
202 switch (property_id)
203 {
204 case PROP_THRIFT_APPLICATION_EXCEPTION_TYPE:
205 tae->type = g_value_get_int (value);
206 tae->__isset_type = TRUE;
207 break;
208 case PROP_THRIFT_APPLICATION_EXCEPTION_MESSAGE:
209 if (tae->message != NULL)
210 g_free (tae->message);
211
212 tae->message = g_value_dup_string (value);
213 tae->__isset_message = TRUE;
214 break;
215 default:
216 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
217 break;
218 }
219}
220
221void
222thrift_application_exception_init (ThriftApplicationException *object)
223{
224 object->type = 0;
225 object->__isset_type = FALSE;
226 object->message = NULL;
227 object->__isset_message = FALSE;
228}
229
230void
231thrift_application_exception_finalize (GObject *object)
232{
233 ThriftApplicationException *tae = THRIFT_APPLICATION_EXCEPTION (object);
234
235 if (tae->__isset_message) {
236 g_free(tae->message);
237 }
238}
239
240void
241thrift_application_exception_class_init (ThriftApplicationExceptionClass *class)
242{
243 GObjectClass *gobject_class = G_OBJECT_CLASS(class);
244 ThriftStructClass *cls = THRIFT_STRUCT_CLASS(class);
245 GParamSpec *param_spec;
246
247 cls->read = thrift_application_exception_read;
248 cls->write = thrift_application_exception_write;
249
250 gobject_class->finalize = thrift_application_exception_finalize;
251 gobject_class->get_property = thrift_application_exception_get_property;
252 gobject_class->set_property = thrift_application_exception_set_property;
253
254 param_spec = g_param_spec_int ("type",
255 "Exception type",
256 "The type of the exception, one of the "
257 "values defined by the "
258 "ThriftApplicationExceptionError "
259 "enumeration.",
260 0,
261 THRIFT_APPLICATION_EXCEPTION_ERROR_N - 1,
262 0,
263 G_PARAM_READWRITE);
264 g_object_class_install_property (gobject_class,
265 PROP_THRIFT_APPLICATION_EXCEPTION_TYPE,
266 param_spec);
267
268 param_spec = g_param_spec_string ("message",
269 "Exception message",
270 "A string describing the exception that "
271 "occurred.",
272 NULL,
273 G_PARAM_READWRITE);
274 g_object_class_install_property (gobject_class,
275 PROP_THRIFT_APPLICATION_EXCEPTION_MESSAGE,
276 param_spec);
277}