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 distuributed 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/c_glib/thrift.h>
21 #include "thrift_configuration.h"
22
23 /* object properties */
24 enum _ThriftConfigurationProperties
25 {
26 PROP_0,
27 PROP_THRIFT_CONFIGURATION_MAX_MESSAGE_SIZE,
28 PROP_THRIFT_CONFIGURATION_MAX_FRAME_SIZE,
29 PROP_THRIFT_CONFIGURATION_RECURSION_LIMIT
30 };
31
G_DEFINE_TYPE(ThriftConfiguration,thrift_configuration,G_TYPE_OBJECT)32 G_DEFINE_TYPE(ThriftConfiguration, thrift_configuration, G_TYPE_OBJECT)
33
34 /* property accessor */
35 void
36 thrift_configuration_get_property(GObject *object, guint property_id,
37 GValue *value, GParamSpec *pspec)
38 {
39 ThriftConfiguration *configuration = THRIFT_CONFIGURATION(object);
40
41 THRIFT_UNUSED_VAR (pspec);
42
43 switch (property_id)
44 {
45 case PROP_THRIFT_CONFIGURATION_MAX_MESSAGE_SIZE:
46 g_value_set_int(value, configuration->maxMessageSize_);
47 break;
48 case PROP_THRIFT_CONFIGURATION_MAX_FRAME_SIZE:
49 g_value_set_int(value, configuration->maxFrameSize_);
50 break;
51 case PROP_THRIFT_CONFIGURATION_RECURSION_LIMIT:
52 g_value_set_int(value, configuration->recursionLimit_);
53 break;
54 }
55 }
56
57 /* property mutator */
58 void
thrift_configuration_set_property(GObject * object,guint property_id,const GValue * value,GParamSpec * pspec)59 thrift_configuration_set_property(GObject *object, guint property_id,
60 const GValue *value, GParamSpec *pspec)
61 {
62 ThriftConfiguration *configuration = THRIFT_CONFIGURATION (object);
63
64 THRIFT_UNUSED_VAR (pspec);
65
66 switch (property_id)
67 {
68 case PROP_THRIFT_CONFIGURATION_MAX_MESSAGE_SIZE:
69 configuration->maxMessageSize_ = g_value_get_int (value);
70 break;
71 case PROP_THRIFT_CONFIGURATION_MAX_FRAME_SIZE:
72 configuration->maxFrameSize_ = g_value_get_int (value);
73 break;
74 case PROP_THRIFT_CONFIGURATION_RECURSION_LIMIT:
75 configuration->recursionLimit_ = g_value_get_int (value);
76 break;
77 }
78 }
79
80 static void
thrift_configuration_class_init(ThriftConfigurationClass * cls)81 thrift_configuration_class_init (ThriftConfigurationClass *cls)
82 {
83 GObjectClass *gobject_class = G_OBJECT_CLASS (cls);
84 GParamSpec *param_spec = NULL;
85
86 /* setup accessors and mutators */
87 gobject_class->get_property = thrift_configuration_get_property;
88 gobject_class->set_property = thrift_configuration_set_property;
89
90 param_spec = g_param_spec_int ("max_message_size",
91 "max_message_size (construct)",
92 "Set the max size of the message",
93 0, /* min */
94 G_MAXINT32, /* max */
95 DEFAULT_MAX_MESSAGE_SIZE, /* default by convention */
96 G_PARAM_CONSTRUCT_ONLY |
97 G_PARAM_READWRITE);
98
99 g_object_class_install_property (gobject_class, PROP_THRIFT_CONFIGURATION_MAX_MESSAGE_SIZE,
100 param_spec);
101
102 param_spec = g_param_spec_int ("max_frame_size",
103 "max_frame_size (construct)",
104 "Set the max size of the frame",
105 0, /* min */
106 G_MAXINT32, /* max */
107 DEFAULT_MAX_FRAME_SIZE, /* default by convention */
108 G_PARAM_CONSTRUCT_ONLY |
109 G_PARAM_READWRITE);
110
111 g_object_class_install_property (gobject_class, PROP_THRIFT_CONFIGURATION_MAX_FRAME_SIZE,
112 param_spec);
113
114 param_spec = g_param_spec_int ("recursion_limit",
115 "recursion_limit (construct)",
116 "Set the limit of the resursion",
117 0, /* min */
118 G_MAXINT32, /* max */
119 DEFAULT_RECURSION_DEPTH, /* default by convention */
120 G_PARAM_CONSTRUCT_ONLY |
121 G_PARAM_READWRITE);
122
123 g_object_class_install_property (gobject_class, PROP_THRIFT_CONFIGURATION_RECURSION_LIMIT,
124 param_spec);
125
126 }
127
128 static void
thrift_configuration_init(ThriftConfiguration * configuration)129 thrift_configuration_init (ThriftConfiguration *configuration)
130 {
131 THRIFT_UNUSED_VAR (configuration);
132 }
133