112
120
NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE (device);
114
122
priv->state = NM_DEVICE_STATE_UNKNOWN;
118
demarshal_ip4_config (NMObject *object, GParamSpec *pspec, GValue *value, gpointer field)
120
NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE (object);
122
NMIP4Config *config = NULL;
123
DBusGConnection *connection;
126
if (!G_VALUE_HOLDS (value, DBUS_TYPE_G_OBJECT_PATH))
129
path = g_value_get_boxed (value);
131
config = NM_IP4_CONFIG (_nm_object_cache_get (path));
133
connection = nm_object_get_connection (object);
134
config = NM_IP4_CONFIG (nm_ip4_config_new (connection, path));
139
priv->got_ip4_config = TRUE;
141
if (priv->ip4_config) {
142
g_object_unref (priv->ip4_config);
143
priv->ip4_config = NULL;
147
priv->ip4_config = config;
149
_nm_object_queue_notify (object, NM_DEVICE_IP4_CONFIG);
154
demarshal_dhcp4_config (NMObject *object, GParamSpec *pspec, GValue *value, gpointer field)
156
NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE (object);
158
NMDHCP4Config *config = NULL;
159
DBusGConnection *connection;
162
if (!G_VALUE_HOLDS (value, DBUS_TYPE_G_OBJECT_PATH))
165
path = g_value_get_boxed (value);
167
config = NM_DHCP4_CONFIG (_nm_object_cache_get (path));
169
connection = nm_object_get_connection (object);
170
config = NM_DHCP4_CONFIG (nm_dhcp4_config_new (connection, path));
175
priv->got_dhcp4_config = TRUE;
177
if (priv->dhcp4_config) {
178
g_object_unref (priv->dhcp4_config);
179
priv->dhcp4_config = NULL;
183
priv->dhcp4_config = config;
185
_nm_object_queue_notify (object, NM_DEVICE_DHCP4_CONFIG);
190
demarshal_ip6_config (NMObject *object, GParamSpec *pspec, GValue *value, gpointer field)
192
NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE (object);
194
NMIP6Config *config = NULL;
195
DBusGConnection *connection;
198
if (!G_VALUE_HOLDS (value, DBUS_TYPE_G_OBJECT_PATH))
201
path = g_value_get_boxed (value);
203
config = NM_IP6_CONFIG (_nm_object_cache_get (path));
205
connection = nm_object_get_connection (object);
206
config = NM_IP6_CONFIG (nm_ip6_config_new (connection, path));
211
priv->got_ip6_config = TRUE;
213
if (priv->ip6_config) {
214
g_object_unref (priv->ip6_config);
215
priv->ip6_config = NULL;
219
priv->ip6_config = config;
221
_nm_object_queue_notify (object, NM_DEVICE_IP6_CONFIG);
226
demarshal_dhcp6_config (NMObject *object, GParamSpec *pspec, GValue *value, gpointer field)
228
NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE (object);
230
NMDHCP6Config *config = NULL;
231
DBusGConnection *connection;
234
if (!G_VALUE_HOLDS (value, DBUS_TYPE_G_OBJECT_PATH))
237
path = g_value_get_boxed (value);
239
config = NM_DHCP6_CONFIG (_nm_object_cache_get (path));
241
connection = nm_object_get_connection (object);
242
config = NM_DHCP6_CONFIG (nm_dhcp6_config_new (connection, path));
247
priv->got_dhcp6_config = TRUE;
249
if (priv->dhcp6_config) {
250
g_object_unref (priv->dhcp6_config);
251
priv->dhcp6_config = NULL;
255
priv->dhcp6_config = config;
257
_nm_object_queue_notify (object, NM_DEVICE_DHCP6_CONFIG);
262
demarshal_active_connection (NMObject *object, GParamSpec *pspec, GValue *value, gpointer field)
264
NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE (object);
266
NMActiveConnection *active = NULL;
267
DBusGConnection *connection;
270
if (!G_VALUE_HOLDS (value, DBUS_TYPE_G_OBJECT_PATH))
273
path = g_value_get_boxed (value);
275
active = NM_ACTIVE_CONNECTION (_nm_object_cache_get (path));
277
connection = nm_object_get_connection (object);
278
active = NM_ACTIVE_CONNECTION (nm_active_connection_new (connection, path));
283
priv->got_active_connection = TRUE;
285
if (priv->active_connection) {
286
g_object_unref (priv->active_connection);
287
priv->active_connection = NULL;
291
priv->active_connection = active;
293
_nm_object_queue_notify (object, NM_DEVICE_ACTIVE_CONNECTION);
123
priv->reason = NM_DEVICE_STATE_REASON_NONE;
127
demarshal_state_reason (NMObject *object, GParamSpec *pspec, GValue *value, gpointer field)
129
NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE (object);
131
if (!G_VALUE_HOLDS (value, DBUS_G_TYPE_UINT_STRUCT))
134
dbus_g_type_struct_get (value,
139
_nm_object_queue_notify (object, NM_DEVICE_STATE_REASON);
298
register_for_property_changed (NMDevice *device)
144
register_properties (NMDevice *device)
300
146
NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE (device);
301
const NMPropertiesChangedInfo property_changed_info[] = {
302
{ NM_DEVICE_UDI, _nm_object_demarshal_generic, &priv->udi },
303
{ NM_DEVICE_INTERFACE, _nm_object_demarshal_generic, &priv->iface },
304
{ NM_DEVICE_IP_INTERFACE, _nm_object_demarshal_generic, &priv->ip_iface },
305
{ NM_DEVICE_DRIVER, _nm_object_demarshal_generic, &priv->driver },
306
{ NM_DEVICE_CAPABILITIES, _nm_object_demarshal_generic, &priv->capabilities },
307
{ NM_DEVICE_MANAGED, _nm_object_demarshal_generic, &priv->managed },
308
{ NM_DEVICE_FIRMWARE_MISSING, _nm_object_demarshal_generic, &priv->firmware_missing },
309
{ NM_DEVICE_IP4_CONFIG, demarshal_ip4_config, &priv->ip4_config },
310
{ NM_DEVICE_DHCP4_CONFIG, demarshal_dhcp4_config, &priv->dhcp4_config },
311
{ NM_DEVICE_IP6_CONFIG, demarshal_ip6_config, &priv->ip6_config },
312
{ NM_DEVICE_DHCP6_CONFIG, demarshal_dhcp6_config, &priv->dhcp6_config },
313
{ NM_DEVICE_ACTIVE_CONNECTION,demarshal_active_connection, &priv->active_connection },
147
const NMPropertiesInfo property_info[] = {
148
{ NM_DEVICE_UDI, &priv->udi },
149
{ NM_DEVICE_INTERFACE, &priv->iface },
150
{ NM_DEVICE_IP_INTERFACE, &priv->ip_iface },
151
{ NM_DEVICE_DRIVER, &priv->driver },
152
{ NM_DEVICE_CAPABILITIES, &priv->capabilities },
153
{ NM_DEVICE_MANAGED, &priv->managed },
154
{ NM_DEVICE_FIRMWARE_MISSING, &priv->firmware_missing },
155
{ NM_DEVICE_IP4_CONFIG, &priv->ip4_config, NULL, NM_TYPE_IP4_CONFIG },
156
{ NM_DEVICE_DHCP4_CONFIG, &priv->dhcp4_config, NULL, NM_TYPE_DHCP4_CONFIG },
157
{ NM_DEVICE_IP6_CONFIG, &priv->ip6_config, NULL, NM_TYPE_IP6_CONFIG },
158
{ NM_DEVICE_DHCP6_CONFIG, &priv->dhcp6_config, NULL, NM_TYPE_DHCP6_CONFIG },
159
{ NM_DEVICE_STATE, &priv->state },
160
{ NM_DEVICE_STATE_REASON, &priv->state, demarshal_state_reason },
161
{ NM_DEVICE_ACTIVE_CONNECTION, &priv->active_connection, NULL, NM_TYPE_ACTIVE_CONNECTION },
163
/* The D-Bus interface has this property, but we don't; register
164
* it so that handle_property_changed() doesn't complain.
166
{ "ip4-address", NULL },
317
_nm_object_handle_properties_changed (NM_OBJECT (device),
319
property_changed_info);
171
_nm_object_register_properties (NM_OBJECT (device),
327
181
gpointer user_data)
329
183
NMDevice *self = NM_DEVICE (user_data);
330
NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE (self);
332
if (priv->state != new_state) {
333
priv->state = new_state;
185
if (old_state != new_state)
334
186
g_signal_emit (self, signals[STATE_CHANGED], 0, new_state, old_state, reason);
335
_nm_object_queue_notify (NM_OBJECT (self), "state");
340
get_all_cb (DBusGProxy *proxy, DBusGProxyCall *call, gpointer user_data)
342
NMObject *self = NM_OBJECT (user_data);
343
GHashTable *props = NULL;
344
GError *error = NULL;
346
if (!dbus_g_proxy_end_call (proxy, call, &error,
347
DBUS_TYPE_G_MAP_OF_VARIANT, &props,
349
if (!(error->domain == DBUS_GERROR && error->code == DBUS_GERROR_NO_REPLY)) {
350
g_warning ("%s: couldn't retrieve device properties: (%d) %s.",
352
error ? error->code : -1,
353
(error && error->message) ? error->message : "(unknown)");
355
g_clear_error (&error);
356
g_object_unref (proxy);
359
g_object_unref (proxy);
361
/* Hack: libnm-glib's NMDevice doesn't have ip4-address property. Remove
362
* it from the hash to prevent warnings.
364
g_hash_table_remove (props, "Ip4Address");
366
_nm_object_process_properties_changed (NM_OBJECT (self), props);
367
g_hash_table_destroy (props);
372
initialize_properties (NMObject *object)
374
DBusGProxy *props_proxy;
376
/* D-Bus properties proxy */
377
props_proxy = dbus_g_proxy_new_for_name (nm_object_get_connection (object),
379
nm_object_get_path (object),
380
"org.freedesktop.DBus.Properties");
381
g_assert (props_proxy);
384
dbus_g_proxy_begin_call (props_proxy, "GetAll",
388
G_TYPE_STRING, NM_DBUS_INTERFACE_DEVICE,
394
constructor (GType type,
395
guint n_construct_params,
396
GObjectConstructParam *construct_params)
190
constructed (GObject *object)
399
192
NMDevicePrivate *priv;
401
object = (NMObject *) G_OBJECT_CLASS (nm_device_parent_class)->constructor (type,
194
G_OBJECT_CLASS (nm_device_parent_class)->constructed (object);
407
196
priv = NM_DEVICE_GET_PRIVATE (object);
409
priv->proxy = dbus_g_proxy_new_for_name (nm_object_get_connection (object),
198
priv->proxy = dbus_g_proxy_new_for_name (nm_object_get_connection (NM_OBJECT (object)),
411
nm_object_get_path (object),
200
nm_object_get_path (NM_OBJECT (object)),
412
201
NM_DBUS_INTERFACE_DEVICE);
414
register_for_property_changed (NM_DEVICE (object));
416
/* Get initial properties, so that we have all properties set even if
417
* no PropertiesChanged signal is received.
418
* It has to be called after register_for_property_changed().
420
initialize_properties (object);
203
register_properties (NM_DEVICE (object));
422
205
dbus_g_object_register_marshaller (_nm_marshal_VOID__UINT_UINT_UINT,
851
663
G_TYPE_STRING, "DeviceType",
853
665
G_TYPE_VALUE, &value, G_TYPE_INVALID)) {
666
g_object_unref (proxy);
854
667
g_warning ("Error in get_property: %s\n", err->message);
855
668
g_error_free (err);
670
g_object_unref (proxy);
859
672
nm_dtype = g_value_get_uint (&value);
861
case NM_DEVICE_TYPE_ETHERNET:
862
dtype = NM_TYPE_DEVICE_ETHERNET;
864
case NM_DEVICE_TYPE_WIFI:
865
dtype = NM_TYPE_DEVICE_WIFI;
867
case NM_DEVICE_TYPE_MODEM:
868
dtype = NM_TYPE_DEVICE_MODEM;
870
case NM_DEVICE_TYPE_BT:
871
dtype = NM_TYPE_DEVICE_BT;
873
case NM_DEVICE_TYPE_WIMAX:
874
dtype = NM_TYPE_DEVICE_WIMAX;
876
case NM_DEVICE_TYPE_INFINIBAND:
877
dtype = NM_TYPE_DEVICE_INFINIBAND;
880
g_warning ("Unknown device type %d", g_value_get_uint (&value));
885
device = (NMDevice *) g_object_new (dtype,
886
NM_OBJECT_DBUS_CONNECTION, connection,
887
NM_OBJECT_DBUS_PATH, path,
888
NM_DEVICE_DEVICE_TYPE, nm_dtype,
893
g_object_unref (proxy);
673
return nm_device_gtype_from_dtype (nm_dtype);
678
* @connection: the #DBusGConnection
679
* @path: the DBus object path of the device
681
* Creates a new #NMDevice.
683
* Returns: (transfer full): a new device
686
nm_device_new (DBusGConnection *connection, const char *path)
689
NMDevice *device = NULL;
691
g_return_val_if_fail (connection != NULL, NULL);
692
g_return_val_if_fail (path != NULL, NULL);
694
dtype = nm_device_type_for_path (connection, path);
695
if (dtype == G_TYPE_INVALID)
698
device = (NMDevice *) g_object_new (dtype,
699
NM_OBJECT_DBUS_CONNECTION, connection,
700
NM_OBJECT_DBUS_PATH, path,
702
_nm_object_ensure_inited (NM_OBJECT (device));
894
703
return G_OBJECT (device);
707
DBusGConnection *connection;
708
NMObjectTypeCallbackFunc callback;
713
async_got_type (DBusGProxy *proxy, DBusGProxyCall *call, gpointer user_data)
715
NMDeviceAsyncData *async_data = user_data;
716
GValue value = G_VALUE_INIT;
717
const char *path = dbus_g_proxy_get_path (proxy);
718
GError *error = NULL;
721
if (dbus_g_proxy_end_call (proxy, call, &error,
722
G_TYPE_VALUE, &value,
726
dtype = g_value_get_uint (&value);
727
type = nm_device_gtype_from_dtype (dtype);
729
g_warning ("%s: could not read properties for %s: %s", __func__, path, error->message);
730
g_error_free (error);
731
type = G_TYPE_INVALID;
734
async_data->callback (type, async_data->user_data);
735
g_object_unref (proxy);
736
g_slice_free (NMDeviceAsyncData, async_data);
740
nm_device_type_for_path_async (DBusGConnection *connection,
742
NMObjectTypeCallbackFunc callback,
745
NMDeviceAsyncData *async_data;
748
async_data = g_slice_new (NMDeviceAsyncData);
749
async_data->connection = connection;
750
async_data->callback = callback;
751
async_data->user_data = user_data;
753
proxy = dbus_g_proxy_new_for_name (connection, NM_DBUS_SERVICE, path,
754
"org.freedesktop.DBus.Properties");
755
dbus_g_proxy_begin_call (proxy, "Get",
756
async_got_type, async_data, NULL,
757
G_TYPE_STRING, NM_DBUS_INTERFACE_DEVICE,
758
G_TYPE_STRING, "DeviceType",
898
763
* nm_device_get_iface:
899
764
* @device: a #NMDevice