]> git.proxmox.com Git - ceph.git/blame - ceph/src/jaegertracing/thrift/lib/c_glib/src/thrift/c_glib/protocol/thrift_multiplexed_protocol.c
buildsys: switch source download to quincy
[ceph.git] / ceph / src / jaegertracing / thrift / lib / c_glib / src / thrift / c_glib / protocol / thrift_multiplexed_protocol.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 <string.h>
21#include <stdio.h>
22#include <glib.h>
23#include <glib-object.h>
24
25#include <thrift/c_glib/thrift.h>
26#include <thrift/c_glib/protocol/thrift_protocol.h>
27#include <thrift/c_glib/protocol/thrift_protocol_decorator.h>
28#include <thrift/c_glib/protocol/thrift_multiplexed_protocol.h>
29
30
31enum
32{
33 PROP_THRIFT_MULTIPLEXED_PROTOCOL_SERVICE_NAME = 1,
34 PROP_THRIFT_MULTIPLEXED_PROTOCOL_END
35};
36
37G_DEFINE_TYPE(ThriftMultiplexedProtocol, thrift_multiplexed_protocol, THRIFT_TYPE_PROTOCOL_DECORATOR)
38
39
40static GParamSpec *thrift_multiplexed_protocol_obj_properties[PROP_THRIFT_MULTIPLEXED_PROTOCOL_END] = { NULL, };
41
42gint32
43thrift_multiplexed_protocol_write_message_begin (ThriftMultiplexedProtocol *protocol,
44 const gchar *name, const ThriftMessageType message_type,
45 const gint32 seqid, GError **error)
46{
47 gint32 ret;
48 gchar *service_name = NULL;
49 g_return_val_if_fail (THRIFT_IS_MULTIPLEXED_PROTOCOL (protocol), -1);
50
51 ThriftMultiplexedProtocol *self = THRIFT_MULTIPLEXED_PROTOCOL (protocol);
52
53 if( (message_type == T_CALL || message_type == T_ONEWAY) && self->service_name != NULL) {
54 service_name = g_strdup_printf("%s%s%s", self->service_name, THRIFT_MULTIPLEXED_PROTOCOL_DEFAULT_SEPARATOR, name);
55 }else{
56 service_name = g_strdup(name);
57 }
58
59 /* relay to the protocol_decorator */
60 ret = thrift_protocol_decorator_write_message_begin(protocol, service_name, message_type, seqid, error);
61
62 g_free(service_name);
63
64 return ret;
65}
66
67
68static void
69thrift_multiplexed_protocol_set_property (GObject *object,
70 guint property_id,
71 const GValue *value,
72 GParamSpec *pspec)
73{
74 ThriftMultiplexedProtocol *self = THRIFT_MULTIPLEXED_PROTOCOL (object);
75
76 switch (property_id)
77 {
78 case PROP_THRIFT_MULTIPLEXED_PROTOCOL_SERVICE_NAME:
79 g_free(self->service_name);
80 self->service_name = g_value_dup_string (value);
81 break;
82
83 default:
84 /* We don't have any other property... */
85 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
86 break;
87 }
88}
89
90static void
91thrift_multiplexed_protocol_get_property (GObject *object,
92 guint property_id,
93 GValue *value,
94 GParamSpec *pspec)
95{
96 ThriftMultiplexedProtocol *self = THRIFT_MULTIPLEXED_PROTOCOL (object);
97
98 switch (property_id)
99 {
100 case PROP_THRIFT_MULTIPLEXED_PROTOCOL_SERVICE_NAME:
101 g_value_set_string (value, self->service_name);
102 break;
103
104 default:
105 /* We don't have any other property... */
106 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
107 break;
108 }
109}
110
111
112static void
113thrift_multiplexed_protocol_init (ThriftMultiplexedProtocol *protocol)
114{
115 protocol->service_name = NULL;
116}
117
118static void
119thrift_multiplexed_protocol_finalize (GObject *gobject)
120{
121 ThriftMultiplexedProtocol *self = THRIFT_MULTIPLEXED_PROTOCOL (gobject);
122
123 if (self->service_name) {
124 g_free(self->service_name);
125 self->service_name = NULL;
126 }
127
128 /* Always chain up to the parent class; as with dispose(), finalize()
129 * is guaranteed to exist on the parent's class virtual function table
130 */
131 G_OBJECT_CLASS (thrift_multiplexed_protocol_parent_class)->finalize(gobject);
132}
133
134
135/* initialize the class */
136static void
137thrift_multiplexed_protocol_class_init (ThriftMultiplexedProtocolClass *klass)
138{
139 ThriftProtocolClass *cls = THRIFT_PROTOCOL_CLASS (klass);
140 GObjectClass *object_class = G_OBJECT_CLASS (klass);
141
142 cls->write_message_begin = thrift_multiplexed_protocol_write_message_begin;
143
144 object_class->set_property = thrift_multiplexed_protocol_set_property;
145 object_class->get_property = thrift_multiplexed_protocol_get_property;
146 object_class->finalize = thrift_multiplexed_protocol_finalize;
147
148 thrift_multiplexed_protocol_obj_properties[PROP_THRIFT_MULTIPLEXED_PROTOCOL_SERVICE_NAME] =
149 g_param_spec_string ("service-name",
150 "Service name the protocol points to",
151 "Set the service name",
152 NULL,
153 (G_PARAM_CONSTRUCT_ONLY | G_PARAM_READWRITE));
154
155 g_object_class_install_properties (object_class,
156 PROP_THRIFT_MULTIPLEXED_PROTOCOL_END,
157 thrift_multiplexed_protocol_obj_properties);
158}