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
|
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */
#include "nm-wimax-nsp.h"
#include "NetworkManager.h"
#include "nm-dbus-manager.h"
#include "nm-setting-wimax.h"
#include "nm-properties-changed-signal.h"
#include "nm-wimax-nsp-glue.h"
#include "nm-utils.h"
G_DEFINE_TYPE (NMWimaxNsp, nm_wimax_nsp, G_TYPE_OBJECT)
enum {
PROPERTIES_CHANGED,
LAST_SIGNAL
};
static guint signals[LAST_SIGNAL] = { 0 };
enum {
PROP_0,
PROP_NAME,
PROP_SIGNAL_QUALITY,
PROP_NETWORK_TYPE,
LAST_PROP
};
#define GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), NM_TYPE_WIMAX_NSP, NMWimaxNspPrivate))
typedef struct {
char *dbus_path;
char *name;
guint32 signal_quality;
NMWimaxNspNetworkType network_type;
} NMWimaxNspPrivate;
NMWimaxNsp *
nm_wimax_nsp_new (const char *name)
{
g_return_val_if_fail (name != NULL, NULL);
return NM_WIMAX_NSP (g_object_new (NM_TYPE_WIMAX_NSP,
NM_WIMAX_NSP_NAME, name,
NULL));
}
const char *
nm_wimax_nsp_get_name (NMWimaxNsp *self)
{
g_return_val_if_fail (NM_IS_WIMAX_NSP (self), NULL);
return GET_PRIVATE (self)->name;
}
guint32
nm_wimax_nsp_get_signal_quality (NMWimaxNsp *self)
{
g_return_val_if_fail (NM_IS_WIMAX_NSP (self), 0);
return GET_PRIVATE (self)->signal_quality;
}
NMWimaxNspNetworkType
nm_wimax_nsp_get_network_type (NMWimaxNsp *self)
{
g_return_val_if_fail (NM_IS_WIMAX_NSP (self), 0);
return GET_PRIVATE (self)->network_type;
}
void
nm_wimax_nsp_export_to_dbus (NMWimaxNsp *self)
{
NMWimaxNspPrivate *priv;
NMDBusManager *mgr;
DBusGConnection *g_connection;
static guint32 counter = 0;
g_return_if_fail (NM_IS_WIMAX_NSP (self));
priv = GET_PRIVATE (self);
g_return_if_fail (priv->dbus_path == NULL);
mgr = nm_dbus_manager_get ();
g_assert (mgr);
g_connection = nm_dbus_manager_get_connection (mgr);
g_assert (g_connection);
priv->dbus_path = g_strdup_printf (NM_DBUS_PATH_WIMAX_NSP "/%d", counter++);
dbus_g_connection_register_g_object (g_connection, priv->dbus_path, G_OBJECT (self));
g_object_unref (mgr);
}
const char *
nm_wimax_nsp_get_dbus_path (NMWimaxNsp *self)
{
g_return_val_if_fail (NM_IS_WIMAX_NSP (self), NULL);
return GET_PRIVATE (self)->dbus_path;
}
gboolean
nm_wimax_nsp_check_compatible (NMWimaxNsp *self,
NMConnection *connection)
{
NMWimaxNspPrivate *priv;
NMSettingWimax *s_wimax;
g_return_val_if_fail (NM_IS_WIMAX_NSP (self), FALSE);
g_return_val_if_fail (NM_IS_CONNECTION (connection), FALSE);
priv = GET_PRIVATE (self);
s_wimax = NM_SETTING_WIMAX (nm_connection_get_setting (connection, NM_TYPE_SETTING_WIMAX));
if (!s_wimax)
return FALSE;
return g_strcmp0 (nm_wimax_nsp_get_name (self), nm_setting_wimax_get_network_name (s_wimax)) == 0;
}
static void
nm_wimax_nsp_init (NMWimaxNsp *self)
{
}
static void
set_property (GObject *object, guint prop_id,
const GValue *value, GParamSpec *pspec)
{
NMWimaxNspPrivate *priv = GET_PRIVATE (object);
guint32 quality;
guint network_type;
switch (prop_id) {
case PROP_NAME:
/* Construct only */
priv->name = g_value_dup_string (value);
break;
case PROP_SIGNAL_QUALITY:
quality = g_value_get_uint (value);
if (quality != priv->signal_quality) {
priv->signal_quality = CLAMP (quality, 0, 100);
g_object_notify (object, NM_WIMAX_NSP_SIGNAL_QUALITY);
}
break;
case PROP_NETWORK_TYPE:
network_type = g_value_get_uint (value);
if (network_type != priv->network_type) {
priv->network_type = network_type;
g_object_notify (object, NM_WIMAX_NSP_NETWORK_TYPE);
}
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
}
}
static void
get_property (GObject *object, guint prop_id,
GValue *value, GParamSpec *pspec)
{
NMWimaxNsp *self = NM_WIMAX_NSP (object);
switch (prop_id) {
case PROP_NAME:
g_value_set_string (value, nm_wimax_nsp_get_name (self));
break;
case PROP_SIGNAL_QUALITY:
g_value_set_uint (value, nm_wimax_nsp_get_signal_quality (self));
break;
case PROP_NETWORK_TYPE:
g_value_set_uint (value, nm_wimax_nsp_get_network_type (self));
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
}
}
static void
finalize (GObject *object)
{
NMWimaxNspPrivate *priv = GET_PRIVATE (object);
g_free (priv->name);
g_free (priv->dbus_path);
G_OBJECT_CLASS (nm_wimax_nsp_parent_class)->finalize (object);
}
static void
nm_wimax_nsp_class_init (NMWimaxNspClass *klass)
{
GObjectClass *object_class = G_OBJECT_CLASS (klass);
g_type_class_add_private (object_class, sizeof (NMWimaxNspPrivate));
/* Virtual methods */
object_class->set_property = set_property;
object_class->get_property = get_property;
object_class->finalize = finalize;
g_object_class_install_property
(object_class, PROP_NAME,
g_param_spec_string (NM_WIMAX_NSP_NAME,
"Name",
"Name",
NULL,
G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY));
g_object_class_install_property
(object_class, PROP_SIGNAL_QUALITY,
g_param_spec_uint (NM_WIMAX_NSP_SIGNAL_QUALITY,
"SignalQuality",
"SignalQuality",
0,
100,
0,
G_PARAM_READWRITE));
g_object_class_install_property
(object_class, PROP_NETWORK_TYPE,
g_param_spec_uint (NM_WIMAX_NSP_NETWORK_TYPE,
"NetworkType",
"NetworkType",
NM_WIMAX_NSP_NETWORK_TYPE_UNKNOWN,
NM_WIMAX_NSP_NETWORK_TYPE_ROAMING_PARTNER,
NM_WIMAX_NSP_NETWORK_TYPE_UNKNOWN,
G_PARAM_READWRITE));
/* Signals */
signals[PROPERTIES_CHANGED] =
nm_properties_changed_signal_new (object_class,
G_STRUCT_OFFSET (NMWimaxNspClass, properties_changed));
dbus_g_object_type_install_info (G_TYPE_FROM_CLASS (klass),
&dbus_glib_nm_wimax_nsp_object_info);
}
|