1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603
| /** * Autogenerated by Thrift Compiler (0.17.0) * * DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING * @generated */ #include <string.h> #include <thrift/c_glib/thrift.h> #include <thrift/c_glib/thrift_application_exception.h> #include <stdio.h> #include <stdbool.h> #include "request_service.h"
gboolean request_service_if_send_message(RequestServiceIf *iface, Result **_return, const Param *param, GError **error) { return REQUEST_SERVICE_IF_GET_INTERFACE (iface)->send_message(iface, _return, param, error); }
GType request_service_if_get_type(void) { static GType type = 0; if (type == 0) { static const GTypeInfo type_info = { sizeof(RequestServiceIfInterface), NULL, /* base_init */ NULL, /* base_finalize */ NULL, /* class_init */ NULL, /* class_finalize */ NULL, /* class_data */ 0, /* instance_size */ 0, /* n_preallocs */ NULL, /* instance_init */ NULL /* value_table */ }; type = g_type_register_static(G_TYPE_INTERFACE, "RequestServiceIf", &type_info, 0); } return type; }
static void request_service_if_interface_init(RequestServiceIfInterface *iface);
G_DEFINE_TYPE_WITH_CODE (RequestServiceClient, request_service_client, G_TYPE_OBJECT, G_IMPLEMENT_INTERFACE(TYPE_REQUEST_SERVICE_IF, request_service_if_interface_init))
enum _RequestServiceClientProperties { PROP_0, PROP_REQUEST_SERVICE_CLIENT_INPUT_PROTOCOL, PROP_REQUEST_SERVICE_CLIENT_OUTPUT_PROTOCOL };
void request_service_client_set_property(GObject *object, guint property_id, const GValue *value, GParamSpec *pspec) { RequestServiceClient *client = REQUEST_SERVICE_CLIENT (object);
THRIFT_UNUSED_VAR (pspec);
switch (property_id) { case PROP_REQUEST_SERVICE_CLIENT_INPUT_PROTOCOL: client->input_protocol = g_value_get_object(value); break; case PROP_REQUEST_SERVICE_CLIENT_OUTPUT_PROTOCOL: client->output_protocol = g_value_get_object(value); break; } }
void request_service_client_get_property(GObject *object, guint property_id, GValue *value, GParamSpec *pspec) { RequestServiceClient *client = REQUEST_SERVICE_CLIENT (object);
THRIFT_UNUSED_VAR (pspec);
switch (property_id) { case PROP_REQUEST_SERVICE_CLIENT_INPUT_PROTOCOL: g_value_set_object(value, client->input_protocol); break; case PROP_REQUEST_SERVICE_CLIENT_OUTPUT_PROTOCOL: g_value_set_object(value, client->output_protocol); break; } }
gboolean request_service_client_send_send_message(RequestServiceIf *iface, const Param *param, GError **error) { gint32 cseqid = 0; ThriftProtocol *protocol = REQUEST_SERVICE_CLIENT (iface)->output_protocol;
if (thrift_protocol_write_message_begin(protocol, "sendMessage", T_CALL, cseqid, error) < 0) return FALSE;
{ gint32 ret; gint32 xfer = 0;
if ((ret = thrift_protocol_write_struct_begin(protocol, "sendMessage_args", error)) < 0) return 0; xfer += ret; if ((ret = thrift_protocol_write_field_begin(protocol, "param", T_STRUCT, 1, error)) < 0) return 0; xfer += ret; if ((ret = thrift_struct_write(THRIFT_STRUCT (param), protocol, error)) < 0) return 0; xfer += ret;
if ((ret = thrift_protocol_write_field_end(protocol, error)) < 0) return 0; xfer += ret; if ((ret = thrift_protocol_write_field_stop(protocol, error)) < 0) return 0; xfer += ret; if ((ret = thrift_protocol_write_struct_end(protocol, error)) < 0) return 0; xfer += ret;
}
if (thrift_protocol_write_message_end(protocol, error) < 0) return FALSE; if (!thrift_transport_flush(protocol->transport, error)) return FALSE; if (!thrift_transport_write_end(protocol->transport, error)) return FALSE;
return TRUE; }
gboolean request_service_client_recv_send_message(RequestServiceIf *iface, Result **_return, GError **error) { gint32 rseqid; gchar *fname = NULL; ThriftMessageType mtype; ThriftProtocol *protocol = REQUEST_SERVICE_CLIENT (iface)->input_protocol; ThriftApplicationException *xception;
if (thrift_protocol_read_message_begin(protocol, &fname, &mtype, &rseqid, error) < 0) { if (fname) g_free(fname); return FALSE; }
if (mtype == T_EXCEPTION) { if (fname) g_free(fname); xception = g_object_new(THRIFT_TYPE_APPLICATION_EXCEPTION, NULL); thrift_struct_read(THRIFT_STRUCT (xception), protocol, NULL); thrift_protocol_read_message_end(protocol, NULL); thrift_transport_read_end(protocol->transport, NULL); g_set_error(error, THRIFT_APPLICATION_EXCEPTION_ERROR, xception->type, "application error: %s", xception->message); g_object_unref(xception); return FALSE; } else if (mtype != T_REPLY) { if (fname) g_free(fname); thrift_protocol_skip(protocol, T_STRUCT, NULL); thrift_protocol_read_message_end(protocol, NULL); thrift_transport_read_end(protocol->transport, NULL); g_set_error(error, THRIFT_APPLICATION_EXCEPTION_ERROR, THRIFT_APPLICATION_EXCEPTION_ERROR_INVALID_MESSAGE_TYPE, "invalid message type %d, expected T_REPLY", mtype); return FALSE; } else if (strncmp(fname, "sendMessage", 11) != 0) { thrift_protocol_skip(protocol, T_STRUCT, NULL); thrift_protocol_read_message_end(protocol, error); thrift_transport_read_end(protocol->transport, error); g_set_error(error, THRIFT_APPLICATION_EXCEPTION_ERROR, THRIFT_APPLICATION_EXCEPTION_ERROR_WRONG_METHOD_NAME, "wrong method name %s, expected sendMessage", fname); if (fname) g_free(fname); return FALSE; } if (fname) g_free(fname);
{ gint32 ret; gint32 xfer = 0; gchar *name = NULL; ThriftType ftype; gint16 fid; guint32 len = 0; gpointer data = NULL;
/* satisfy -Wall in case these aren't used */ THRIFT_UNUSED_VAR (len); THRIFT_UNUSED_VAR (data);
/* read the struct begin marker */ if ((ret = thrift_protocol_read_struct_begin(protocol, &name, error)) < 0) { if (name) g_free(name); return 0; } xfer += ret; if (name) g_free(name); name = NULL;
/* read the struct fields */ while (1) { /* read the beginning of a field */ if ((ret = thrift_protocol_read_field_begin(protocol, &name, &ftype, &fid, error)) < 0) { if (name) g_free(name); return 0; } xfer += ret; if (name) g_free(name); name = NULL;
/* break if we get a STOP field */ if (ftype == T_STOP) { break; }
switch (fid) { case 0: if (ftype == T_STRUCT) { if ((ret = thrift_struct_read(THRIFT_STRUCT (*_return), protocol, error)) < 0) { return 0; } xfer += ret; } else { if ((ret = thrift_protocol_skip(protocol, ftype, error)) < 0) return 0; xfer += ret; } break; default: if ((ret = thrift_protocol_skip(protocol, ftype, error)) < 0) return 0; xfer += ret; break; } if ((ret = thrift_protocol_read_field_end(protocol, error)) < 0) return 0; xfer += ret; }
if ((ret = thrift_protocol_read_struct_end(protocol, error)) < 0) return 0; xfer += ret;
}
if (thrift_protocol_read_message_end(protocol, error) < 0) return FALSE;
if (!thrift_transport_read_end(protocol->transport, error)) return FALSE;
return TRUE; }
gboolean request_service_client_send_message(RequestServiceIf *iface, Result **_return, const Param *param, GError **error) { if (!request_service_client_send_send_message(iface, param, error)) return FALSE; if (!request_service_client_recv_send_message(iface, _return, error)) return FALSE; return TRUE; }
static void request_service_if_interface_init(RequestServiceIfInterface *iface) { iface->send_message = request_service_client_send_message; }
static void request_service_client_init(RequestServiceClient *client) { client->input_protocol = NULL; client->output_protocol = NULL; }
static void request_service_client_class_init(RequestServiceClientClass *cls) { GObjectClass *gobject_class = G_OBJECT_CLASS (cls); GParamSpec *param_spec;
gobject_class->set_property = request_service_client_set_property; gobject_class->get_property = request_service_client_get_property;
param_spec = g_param_spec_object("input_protocol", "input protocol (construct)", "Set the client input protocol", THRIFT_TYPE_PROTOCOL, G_PARAM_READWRITE); g_object_class_install_property(gobject_class, PROP_REQUEST_SERVICE_CLIENT_INPUT_PROTOCOL, param_spec);
param_spec = g_param_spec_object("output_protocol", "output protocol (construct)", "Set the client output protocol", THRIFT_TYPE_PROTOCOL, G_PARAM_READWRITE); g_object_class_install_property(gobject_class, PROP_REQUEST_SERVICE_CLIENT_OUTPUT_PROTOCOL, param_spec); }
static void request_service_handler_request_service_if_interface_init(RequestServiceIfInterface *iface);
G_DEFINE_TYPE_WITH_CODE (RequestServiceHandler, request_service_handler, G_TYPE_OBJECT, G_IMPLEMENT_INTERFACE(TYPE_REQUEST_SERVICE_IF, request_service_handler_request_service_if_interface_init))
gboolean request_service_handler_send_message(RequestServiceIf *iface, Result **_return, const Param *param, GError **error) { g_return_val_if_fail (IS_REQUEST_SERVICE_HANDLER(iface), FALSE);
printf("%p %p \n", param->key, error); // 这里写自己server的业务,有点头大。。。
return REQUEST_SERVICE_HANDLER_GET_CLASS (iface)->send_message(iface, _return, param, error); }
static void request_service_handler_request_service_if_interface_init(RequestServiceIfInterface *iface) { iface->send_message = request_service_handler_send_message; //这里自己注册 }
static void request_service_handler_init(RequestServiceHandler *self) { THRIFT_UNUSED_VAR (self); }
static gboolean request_service_handler_sends_message(RequestServiceIf *iface, Result **_return, const Param *param, GError **error) { THRIFT_UNUSED_VAR (iface); THRIFT_UNUSED_VAR (error); printf("service request_service_handler_sends_message run key-> %s, value -> %d \n",param->key,param->value); puts("zip()"); Result *result = g_object_new(TYPE_RESULT, NULL); result->result = true; *_return = result; return TRUE; }
static void request_service_handler_class_init(RequestServiceHandlerClass *cls) { printf("request_service_handler_class_init in request\n");
cls->send_message = request_service_handler_sends_message; }
enum _RequestServiceProcessorProperties { PROP_REQUEST_SERVICE_PROCESSOR_0, PROP_REQUEST_SERVICE_PROCESSOR_HANDLER };
G_DEFINE_TYPE (RequestServiceProcessor, request_service_processor, THRIFT_TYPE_DISPATCH_PROCESSOR)
typedef gboolean (*RequestServiceProcessorProcessFunction)(RequestServiceProcessor *, gint32, ThriftProtocol *, ThriftProtocol *, GError **);
typedef struct { gchar *name; RequestServiceProcessorProcessFunction function; } request_service_processor_process_function_def;
static gboolean request_service_processor_process_send_message(RequestServiceProcessor *, gint32, ThriftProtocol *, ThriftProtocol *, GError **);
static request_service_processor_process_function_def request_service_processor_process_function_defs[1] = { { "sendMessage", request_service_processor_process_send_message } };
static gboolean request_service_processor_process_send_message(RequestServiceProcessor *self, gint32 sequence_id, ThriftProtocol *input_protocol, ThriftProtocol *output_protocol, GError **error) { gboolean result = TRUE; ThriftTransport *transport; ThriftApplicationException *xception; RequestServiceSendMessageArgs *args = g_object_new(TYPE_REQUEST_SERVICE_SEND_MESSAGE_ARGS, NULL);
printf("request_service_processor_process_send_message\n"); g_object_get(input_protocol, "transport", &transport, NULL);
if ((thrift_struct_read(THRIFT_STRUCT (args), input_protocol, error) != -1) && (thrift_protocol_read_message_end(input_protocol, error) != -1) && (thrift_transport_read_end(transport, error) != FALSE)) { Param *param; Result *return_value; RequestServiceSendMessageResult *result_struct;
g_object_get(args, "param", ¶m, NULL);
g_object_unref(transport); g_object_get(output_protocol, "transport", &transport, NULL);
result_struct = g_object_new(TYPE_REQUEST_SERVICE_SEND_MESSAGE_RESULT, NULL); g_object_get(result_struct, "success", &return_value, NULL);
if (request_service_handler_send_message(REQUEST_SERVICE_IF (self->handler), &return_value, param, error) == TRUE) { g_object_set(result_struct, "success", return_value, NULL);
result = ((thrift_protocol_write_message_begin(output_protocol, "sendMessage", T_REPLY, sequence_id, error) != -1) && (thrift_struct_write(THRIFT_STRUCT (result_struct), output_protocol, error) != -1)); } else { if (*error == NULL) g_warning ("RequestService.sendMessage implementation returned FALSE " "but did not set an error");
xception = g_object_new(THRIFT_TYPE_APPLICATION_EXCEPTION, "type", *error != NULL ? (*error)->code : THRIFT_APPLICATION_EXCEPTION_ERROR_UNKNOWN, "message", *error != NULL ? (*error)->message : NULL, NULL); g_clear_error(error);
result = ((thrift_protocol_write_message_begin(output_protocol, "sendMessage", T_EXCEPTION, sequence_id, error) != -1) && (thrift_struct_write(THRIFT_STRUCT (xception), output_protocol, error) != -1));
g_object_unref(xception); }
if (param != NULL) g_object_unref(param); if (return_value != NULL) g_object_unref(return_value); g_object_unref(result_struct);
if (result == TRUE) result = ((thrift_protocol_write_message_end(output_protocol, error) != -1) && (thrift_transport_write_end(transport, error) != FALSE) && (thrift_transport_flush(transport, error) != FALSE)); } else result = FALSE;
g_object_unref(transport); g_object_unref(args);
return result; }
static gboolean request_service_processor_dispatch_call(ThriftDispatchProcessor *dispatch_processor, ThriftProtocol *input_protocol, ThriftProtocol *output_protocol, gchar *method_name, gint32 sequence_id, GError **error) { request_service_processor_process_function_def *process_function_def; gboolean dispatch_result = FALSE;
RequestServiceProcessor *self = REQUEST_SERVICE_PROCESSOR (dispatch_processor); ThriftDispatchProcessorClass *parent_class = g_type_class_peek_parent(REQUEST_SERVICE_PROCESSOR_GET_CLASS (self));
process_function_def = g_hash_table_lookup(self->process_map, method_name); if (process_function_def != NULL) { g_free(method_name); dispatch_result = (*process_function_def->function)(self, sequence_id, input_protocol, output_protocol, error); } else { dispatch_result = parent_class->dispatch_call(dispatch_processor, input_protocol, output_protocol, method_name, sequence_id, error); }
return dispatch_result; }
static void request_service_processor_set_property(GObject *object, guint property_id, const GValue *value, GParamSpec *pspec) { RequestServiceProcessor *self = REQUEST_SERVICE_PROCESSOR (object);
switch (property_id) { case PROP_REQUEST_SERVICE_PROCESSOR_HANDLER: if (self->handler != NULL) g_object_unref(self->handler); self->handler = g_value_get_object(value); g_object_ref (self->handler); break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); break; } }
static void request_service_processor_get_property(GObject *object, guint property_id, GValue *value, GParamSpec *pspec) { RequestServiceProcessor *self = REQUEST_SERVICE_PROCESSOR (object);
switch (property_id) { case PROP_REQUEST_SERVICE_PROCESSOR_HANDLER: g_value_set_object(value, self->handler); break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); break; } }
static void request_service_processor_dispose(GObject *gobject) { RequestServiceProcessor *self = REQUEST_SERVICE_PROCESSOR (gobject);
if (self->handler != NULL) { g_object_unref(self->handler); self->handler = NULL; }
G_OBJECT_CLASS (request_service_processor_parent_class)->dispose(gobject); }
static void request_service_processor_finalize(GObject *gobject) { RequestServiceProcessor *self = REQUEST_SERVICE_PROCESSOR (gobject);
thrift_safe_hash_table_destroy(self->process_map);
G_OBJECT_CLASS (request_service_processor_parent_class)->finalize(gobject); }
static void request_service_processor_init(RequestServiceProcessor *self) { guint index;
self->handler = NULL; self->process_map = g_hash_table_new(g_str_hash, g_str_equal);
for (index = 0; index < 1; index += 1) g_hash_table_insert(self->process_map, request_service_processor_process_function_defs[index].name, &request_service_processor_process_function_defs[index]); }
static void request_service_processor_class_init(RequestServiceProcessorClass *cls) { GObjectClass *gobject_class = G_OBJECT_CLASS (cls); ThriftDispatchProcessorClass *dispatch_processor_class = THRIFT_DISPATCH_PROCESSOR_CLASS (cls); GParamSpec *param_spec;
gobject_class->dispose = request_service_processor_dispose; gobject_class->finalize = request_service_processor_finalize; gobject_class->set_property = request_service_processor_set_property; gobject_class->get_property = request_service_processor_get_property;
dispatch_processor_class->dispatch_call = request_service_processor_dispatch_call; cls->dispatch_call = request_service_processor_dispatch_call;
param_spec = g_param_spec_object("handler", "Service handler implementation", "The service handler implementation " "to which method calls are dispatched.", TYPE_REQUEST_SERVICE_HANDLER, G_PARAM_READWRITE); g_object_class_install_property(gobject_class, PROP_REQUEST_SERVICE_PROCESSOR_HANDLER, param_spec); }
|