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
10 * http://www.apache.org/licenses/LICENSE-2.0
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
20 #include <thrift/c_glib/thrift.h>
21 #include "thrift_server.h"
23 /* object properties */
24 enum _ThriftServerProperties
27 PROP_THRIFT_SERVER_PROCESSOR
,
28 PROP_THRIFT_SERVER_SERVER_TRANSPORT
,
29 PROP_THRIFT_SERVER_INPUT_TRANSPORT_FACTORY
,
30 PROP_THRIFT_SERVER_OUTPUT_TRANSPORT_FACTORY
,
31 PROP_THRIFT_SERVER_INPUT_PROTOCOL_FACTORY
,
32 PROP_THRIFT_SERVER_OUTPUT_PROTOCOL_FACTORY
35 G_DEFINE_ABSTRACT_TYPE(ThriftServer
, thrift_server
, G_TYPE_OBJECT
)
38 thrift_server_get_property (GObject
*object
, guint property_id
,
39 GValue
*value
, GParamSpec
*pspec
)
41 ThriftServer
*server
= THRIFT_SERVER (object
);
43 THRIFT_UNUSED_VAR (pspec
);
47 case PROP_THRIFT_SERVER_PROCESSOR
:
48 g_value_set_object (value
, server
->processor
);
50 case PROP_THRIFT_SERVER_SERVER_TRANSPORT
:
51 g_value_set_object (value
, server
->server_transport
);
53 case PROP_THRIFT_SERVER_INPUT_TRANSPORT_FACTORY
:
54 g_value_set_object (value
, server
->input_transport_factory
);
56 case PROP_THRIFT_SERVER_OUTPUT_TRANSPORT_FACTORY
:
57 g_value_set_object (value
, server
->output_transport_factory
);
59 case PROP_THRIFT_SERVER_INPUT_PROTOCOL_FACTORY
:
60 g_value_set_object (value
, server
->input_protocol_factory
);
62 case PROP_THRIFT_SERVER_OUTPUT_PROTOCOL_FACTORY
:
63 g_value_set_object (value
, server
->output_protocol_factory
);
69 thrift_server_set_property (GObject
*object
, guint property_id
,
70 const GValue
*value
, GParamSpec
*pspec
)
72 ThriftServer
*server
= THRIFT_SERVER (object
);
74 THRIFT_UNUSED_VAR (pspec
);
78 case PROP_THRIFT_SERVER_PROCESSOR
:
79 server
->processor
= g_value_dup_object (value
);
81 case PROP_THRIFT_SERVER_SERVER_TRANSPORT
:
82 server
->server_transport
= g_value_dup_object (value
);
84 case PROP_THRIFT_SERVER_INPUT_TRANSPORT_FACTORY
:
85 server
->input_transport_factory
= g_value_dup_object (value
);
87 case PROP_THRIFT_SERVER_OUTPUT_TRANSPORT_FACTORY
:
88 server
->output_transport_factory
= g_value_dup_object (value
);
90 case PROP_THRIFT_SERVER_INPUT_PROTOCOL_FACTORY
:
91 server
->input_protocol_factory
= g_value_dup_object (value
);
93 case PROP_THRIFT_SERVER_OUTPUT_PROTOCOL_FACTORY
:
94 server
->output_protocol_factory
= g_value_dup_object (value
);
100 thrift_server_serve (ThriftServer
*server
, GError
**error
)
102 return THRIFT_SERVER_GET_CLASS (server
)->serve (server
, error
);
106 thrift_server_stop (ThriftServer
*server
)
108 THRIFT_SERVER_GET_CLASS (server
)->stop (server
);
111 /* instance initializer for Thrift Server */
113 thrift_server_init (ThriftServer
*server
)
115 server
->processor
= NULL
;
116 server
->server_transport
= NULL
;
117 server
->input_transport_factory
= NULL
;
118 server
->output_transport_factory
= NULL
;
119 server
->input_protocol_factory
= NULL
;
120 server
->output_protocol_factory
= NULL
;
124 thrift_server_dispose (GObject
*gobject
)
126 ThriftServer
*self
= THRIFT_SERVER (gobject
);
128 g_clear_object(&self
->output_protocol_factory
);
129 g_clear_object(&self
->input_protocol_factory
);
130 g_clear_object(&self
->output_transport_factory
);
131 g_clear_object(&self
->input_transport_factory
);
132 g_clear_object(&self
->server_transport
);
133 g_clear_object(&self
->processor
);
135 /* Always chain up to the parent class; there is no need to check if
136 * the parent class implements the dispose() virtual function: it is
137 * always guaranteed to do so
139 G_OBJECT_CLASS (thrift_server_parent_class
)->dispose(gobject
);
143 * class initializer for ThriftServer
144 * TODO: implement ServerEventHandler as a GClosure
147 thrift_server_class_init (ThriftServerClass
*cls
)
149 GObjectClass
*gobject_class
= G_OBJECT_CLASS (cls
);
151 gobject_class
->get_property
= thrift_server_get_property
;
152 gobject_class
->set_property
= thrift_server_set_property
;
153 gobject_class
->dispose
= thrift_server_dispose
;
155 g_object_class_install_property (gobject_class
,
156 PROP_THRIFT_SERVER_PROCESSOR
,
157 g_param_spec_object ("processor", "Processor", "Thrift Processor",
158 THRIFT_TYPE_PROCESSOR
,
159 G_PARAM_READWRITE
| G_PARAM_CONSTRUCT_ONLY
));
160 g_object_class_install_property (gobject_class
,
161 PROP_THRIFT_SERVER_SERVER_TRANSPORT
,
162 g_param_spec_object ("server_transport", "Server Transport",
163 "Thrift Server Transport",
164 THRIFT_TYPE_SERVER_TRANSPORT
,
165 G_PARAM_READWRITE
| G_PARAM_CONSTRUCT_ONLY
));
166 g_object_class_install_property (gobject_class
,
167 PROP_THRIFT_SERVER_INPUT_TRANSPORT_FACTORY
,
168 g_param_spec_object ("input_transport_factory", "Input Transport Factory",
169 "Thrift Server Input Transport Factory",
170 THRIFT_TYPE_TRANSPORT_FACTORY
,
171 G_PARAM_READWRITE
| G_PARAM_CONSTRUCT_ONLY
));
172 g_object_class_install_property (gobject_class
,
173 PROP_THRIFT_SERVER_OUTPUT_TRANSPORT_FACTORY
,
174 g_param_spec_object ("output_transport_factory",
175 "Output Transport Factory",
176 "Thrift Server Output Transport Factory",
177 THRIFT_TYPE_TRANSPORT_FACTORY
,
178 G_PARAM_READWRITE
| G_PARAM_CONSTRUCT_ONLY
));
179 g_object_class_install_property (gobject_class
,
180 PROP_THRIFT_SERVER_INPUT_PROTOCOL_FACTORY
,
181 g_param_spec_object ("input_protocol_factory", "Input Protocol Factory",
182 "Thrift Server Input Protocol Factory",
183 THRIFT_TYPE_PROTOCOL_FACTORY
,
184 G_PARAM_READWRITE
| G_PARAM_CONSTRUCT_ONLY
));
185 g_object_class_install_property (gobject_class
,
186 PROP_THRIFT_SERVER_OUTPUT_PROTOCOL_FACTORY
,
187 g_param_spec_object ("output_protocol_factory", "Output Protocol Factory",
188 "Thrift Server Output Protocol Factory",
189 THRIFT_TYPE_PROTOCOL_FACTORY
,
190 G_PARAM_READWRITE
| G_PARAM_CONSTRUCT_ONLY
));
192 /* set these as virtual methods to be implemented by a subclass */
193 cls
->serve
= thrift_server_serve
;
194 cls
->stop
= thrift_server_stop
;