libnm: drop NM_TYPE_OBJECT_ARRAY, use G_TYPE_PTR_ARRAY

Use G_TYPE_PTR_ARRAY for GPtrArray-of-NMObject-valued properties,
because it has better introspection/bindings support.

As with the strdict change in libnm-core, we need to manually copy the
array in get_property() implementations, to preserve the standard
semantics that get_property() returns a copy, not the internal array.

(This patch also changes those properties so that they are always
non-NULL until dispose(); previously some of them could be either NULL
or 0-length at different times.)
This commit is contained in:
Dan Winship
2014-08-26 08:31:04 -04:00
parent 20dc44bda9
commit 074c2093b6
16 changed files with 148 additions and 224 deletions

View File

@@ -73,4 +73,9 @@ GPtrArray *_nm_utils_copy_slist_to_array (const GSList *list,
GSList *_nm_utils_copy_array_to_slist (const GPtrArray *array,
NMUtilsCopyFunc copy_func);
GPtrArray *_nm_utils_copy_array (const GPtrArray *array,
NMUtilsCopyFunc copy_func,
GDestroyNotify free_func);
GPtrArray *_nm_utils_copy_object_array (const GPtrArray *array);
#endif

View File

@@ -626,6 +626,26 @@ _nm_utils_copy_array_to_slist (const GPtrArray *array,
return g_slist_reverse (slist);
}
GPtrArray *
_nm_utils_copy_array (const GPtrArray *array,
NMUtilsCopyFunc copy_func,
GDestroyNotify free_func)
{
GPtrArray *copy;
int i;
copy = g_ptr_array_new_full (array->len, free_func);
for (i = 0; i < array->len; i++)
g_ptr_array_add (copy, copy_func (array->pdata[i]));
return copy;
}
GPtrArray *
_nm_utils_copy_object_array (const GPtrArray *array)
{
return _nm_utils_copy_array (array, g_object_ref, g_object_unref);
}
void
_nm_utils_bytes_to_dbus (const GValue *prop_value,
GValue *dbus_value)

View File

@@ -337,7 +337,6 @@ global:
nm_ip6_route_set_next_hop;
nm_ip6_route_set_prefix;
nm_ip6_route_unref;
nm_object_array_get_type;
nm_object_error_get_type;
nm_object_error_quark;
nm_object_get_dbus_connection;

View File

@@ -24,7 +24,7 @@
#include "nm-dbus-interface.h"
#include "nm-active-connection.h"
#include "nm-object-private.h"
#include "nm-types-private.h"
#include "nm-core-internal.h"
#include "nm-device.h"
#include "nm-device-private.h"
#include "nm-connection.h"
@@ -454,11 +454,7 @@ dispose (GObject *object)
{
NMActiveConnectionPrivate *priv = NM_ACTIVE_CONNECTION_GET_PRIVATE (object);
if (priv->devices) {
g_ptr_array_set_free_func (priv->devices, g_object_unref);
g_ptr_array_free (priv->devices, TRUE);
priv->devices = NULL;
}
g_clear_pointer (&priv->devices, g_ptr_array_unref);
g_clear_object (&priv->ip4_config);
g_clear_object (&priv->dhcp4_config);
@@ -510,7 +506,7 @@ get_property (GObject *object,
g_value_set_boxed (value, nm_active_connection_get_specific_object (self));
break;
case PROP_DEVICES:
g_value_set_boxed (value, nm_active_connection_get_devices (self));
g_value_take_boxed (value, _nm_utils_copy_object_array (nm_active_connection_get_devices (self)));
break;
case PROP_STATE:
g_value_set_uint (value, nm_active_connection_get_state (self));
@@ -656,14 +652,16 @@ nm_active_connection_class_init (NMActiveConnectionClass *ap_class)
G_PARAM_STATIC_STRINGS));
/**
* NMActiveConnection:device:
* NMActiveConnection:devices:
*
* The devices (#NMDevice) of the active connection.
* The devices of the active connection.
*
* Element-type: NMDevice
**/
g_object_class_install_property
(object_class, PROP_DEVICES,
g_param_spec_boxed (NM_ACTIVE_CONNECTION_DEVICES, "", "",
NM_TYPE_OBJECT_ARRAY,
G_TYPE_PTR_ARRAY,
G_PARAM_READABLE |
G_PARAM_STATIC_STRINGS));

View File

@@ -27,7 +27,7 @@
#include "nm-device-ethernet.h"
#include "nm-device-wifi.h"
#include "nm-device-private.h"
#include "nm-types-private.h"
#include "nm-core-internal.h"
#include "nm-object-private.h"
#include "nm-active-connection.h"
#include "nm-vpn-connection.h"
@@ -152,7 +152,7 @@ poke_wireless_devices_with_rf_status (NMClient *client)
NMClientPrivate *priv = NM_CLIENT_GET_PRIVATE (client);
int i;
for (i = 0; priv->devices && (i < priv->devices->len); i++) {
for (i = 0; i < priv->devices->len; i++) {
NMDevice *device = g_ptr_array_index (priv->devices, i);
if (NM_IS_DEVICE_WIFI (device))
@@ -1243,7 +1243,7 @@ nm_client_get_activating_connection (NMClient *client)
/****************************************************************/
static void
free_devices (NMClient *client, gboolean emit_signals)
free_devices (NMClient *client, gboolean in_dispose)
{
NMClientPrivate *priv = NM_CLIENT_GET_PRIVATE (client);
GPtrArray *devices;
@@ -1254,18 +1254,23 @@ free_devices (NMClient *client, gboolean emit_signals)
return;
devices = priv->devices;
priv->devices = NULL;
for (i = 0; i < devices->len; i++) {
device = devices->pdata[i];
if (emit_signals)
if (in_dispose)
priv->devices = NULL;
else {
priv->devices = g_ptr_array_new ();
for (i = 0; i < devices->len; i++) {
device = devices->pdata[i];
g_signal_emit (client, signals[DEVICE_REMOVED], 0, device);
g_object_unref (device);
}
}
g_ptr_array_free (devices, TRUE);
g_ptr_array_unref (devices);
}
static void
free_active_connections (NMClient *client, gboolean emit_signals)
free_active_connections (NMClient *client, gboolean in_dispose)
{
NMClientPrivate *priv = NM_CLIENT_GET_PRIVATE (client);
GPtrArray *active_connections;
@@ -1277,16 +1282,18 @@ free_active_connections (NMClient *client, gboolean emit_signals)
active_connections = priv->active_connections;
priv->active_connections = NULL;
for (i = 0; i < active_connections->len; i++) {
active_connection = active_connections->pdata[i];
/* Break circular refs */
g_object_run_dispose (G_OBJECT (active_connection));
g_object_unref (active_connection);
}
g_ptr_array_free (active_connections, TRUE);
g_ptr_array_unref (active_connections);
if (emit_signals)
if (!in_dispose) {
priv->active_connections = g_ptr_array_new ();
g_object_notify (G_OBJECT (client), NM_CLIENT_ACTIVE_CONNECTIONS);
}
}
static void
@@ -1317,8 +1324,8 @@ nm_running_changed_cb (GObject *object,
_nm_object_queue_notify (NM_OBJECT (client), NM_CLIENT_NM_RUNNING);
_nm_object_suppress_property_updates (NM_OBJECT (client), TRUE);
poke_wireless_devices_with_rf_status (client);
free_devices (client, TRUE);
free_active_connections (client, TRUE);
free_devices (client, FALSE);
free_active_connections (client, FALSE);
update_permissions (client, NULL);
priv->wireless_enabled = FALSE;
priv->wireless_hw_enabled = FALSE;
@@ -1817,8 +1824,8 @@ dispose (GObject *object)
g_clear_object (&priv->client_proxy);
free_devices (client, FALSE);
free_active_connections (client, FALSE);
free_devices (client, TRUE);
free_active_connections (client, TRUE);
g_clear_object (&priv->primary_connection);
g_clear_object (&priv->activating_connection);
@@ -1927,7 +1934,7 @@ get_property (GObject *object,
g_value_set_boolean (value, priv->wimax_hw_enabled);
break;
case PROP_ACTIVE_CONNECTIONS:
g_value_set_boxed (value, nm_client_get_active_connections (self));
g_value_take_boxed (value, _nm_utils_copy_object_array (nm_client_get_active_connections (self)));
break;
case PROP_CONNECTIVITY:
g_value_set_uint (value, priv->connectivity);
@@ -1939,7 +1946,7 @@ get_property (GObject *object,
g_value_set_object (value, priv->activating_connection);
break;
case PROP_DEVICES:
g_value_set_boxed (value, nm_client_get_devices (self));
g_value_take_boxed (value, _nm_utils_copy_object_array (nm_client_get_devices (self)));
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
@@ -2103,12 +2110,13 @@ nm_client_class_init (NMClientClass *client_class)
* NMClient:active-connections:
*
* The active connections.
* Type: GLib.PtrArray
*
* Element-type: NMActiveConnection
**/
g_object_class_install_property
(object_class, PROP_ACTIVE_CONNECTIONS,
g_param_spec_boxed (NM_CLIENT_ACTIVE_CONNECTIONS, "", "",
NM_TYPE_OBJECT_ARRAY,
G_TYPE_PTR_ARRAY,
G_PARAM_READABLE |
G_PARAM_STATIC_STRINGS));
@@ -2154,11 +2162,13 @@ nm_client_class_init (NMClientClass *client_class)
* NMClient:devices:
*
* List of known network devices.
*
* Element-type: NMDevice
**/
g_object_class_install_property
(object_class, PROP_DEVICES,
g_param_spec_boxed (NM_CLIENT_DEVICES, "", "",
NM_TYPE_OBJECT_ARRAY,
G_TYPE_PTR_ARRAY,
G_PARAM_READABLE |
G_PARAM_STATIC_STRINGS));

View File

@@ -30,7 +30,7 @@
#include "nm-device-bond.h"
#include "nm-device-private.h"
#include "nm-object-private.h"
#include "nm-types.h"
#include "nm-core-internal.h"
G_DEFINE_TYPE (NMDeviceBond, nm_device_bond, NM_TYPE_DEVICE)
@@ -204,11 +204,7 @@ dispose (GObject *object)
g_clear_object (&priv->proxy);
if (priv->slaves) {
g_ptr_array_set_free_func (priv->slaves, g_object_unref);
g_ptr_array_free (priv->slaves, TRUE);
priv->slaves = NULL;
}
g_clear_pointer (&priv->slaves, g_ptr_array_unref);
G_OBJECT_CLASS (nm_device_bond_parent_class)->dispose (object);
}
@@ -239,7 +235,7 @@ get_property (GObject *object,
g_value_set_boolean (value, nm_device_bond_get_carrier (device));
break;
case PROP_SLAVES:
g_value_set_boxed (value, nm_device_bond_get_slaves (device));
g_value_take_boxed (value, _nm_utils_copy_object_array (nm_device_bond_get_slaves (device)));
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
@@ -296,12 +292,14 @@ nm_device_bond_class_init (NMDeviceBondClass *bond_class)
/**
* NMDeviceBond:slaves:
*
* The devices (#NMDevice) slaved to the bond device.
* The devices slaved to the bond device.
*
* Element-type: NMDevice
**/
g_object_class_install_property
(object_class, PROP_SLAVES,
g_param_spec_boxed (NM_DEVICE_BOND_SLAVES, "", "",
NM_TYPE_OBJECT_ARRAY,
G_TYPE_PTR_ARRAY,
G_PARAM_READABLE |
G_PARAM_STATIC_STRINGS));
}

View File

@@ -30,7 +30,7 @@
#include "nm-device-bridge.h"
#include "nm-device-private.h"
#include "nm-object-private.h"
#include "nm-types.h"
#include "nm-core-internal.h"
G_DEFINE_TYPE (NMDeviceBridge, nm_device_bridge, NM_TYPE_DEVICE)
@@ -204,11 +204,7 @@ dispose (GObject *object)
g_clear_object (&priv->proxy);
if (priv->slaves) {
g_ptr_array_set_free_func (priv->slaves, g_object_unref);
g_ptr_array_free (priv->slaves, TRUE);
priv->slaves = NULL;
}
g_clear_pointer (&priv->slaves, g_ptr_array_unref);
G_OBJECT_CLASS (nm_device_bridge_parent_class)->dispose (object);
}
@@ -239,7 +235,7 @@ get_property (GObject *object,
g_value_set_boolean (value, nm_device_bridge_get_carrier (device));
break;
case PROP_SLAVES:
g_value_set_boxed (value, nm_device_bridge_get_slaves (device));
g_value_take_boxed (value, _nm_utils_copy_object_array (nm_device_bridge_get_slaves (device)));
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
@@ -296,12 +292,14 @@ nm_device_bridge_class_init (NMDeviceBridgeClass *bridge_class)
/**
* NMDeviceBridge:slaves:
*
* The devices (#NMDevice) slaved to the bridge device.
* The devices slaved to the bridge device.
*
* Element-type: NMDevice
**/
g_object_class_install_property
(object_class, PROP_SLAVES,
g_param_spec_boxed (NM_DEVICE_BRIDGE_SLAVES, "", "",
NM_TYPE_OBJECT_ARRAY,
G_TYPE_PTR_ARRAY,
G_PARAM_READABLE |
G_PARAM_STATIC_STRINGS));
}

View File

@@ -30,7 +30,7 @@
#include "nm-device-team.h"
#include "nm-device-private.h"
#include "nm-object-private.h"
#include "nm-types.h"
#include "nm-core-internal.h"
G_DEFINE_TYPE (NMDeviceTeam, nm_device_team, NM_TYPE_DEVICE)
@@ -204,11 +204,7 @@ dispose (GObject *object)
g_clear_object (&priv->proxy);
if (priv->slaves) {
g_ptr_array_set_free_func (priv->slaves, g_object_unref);
g_ptr_array_free (priv->slaves, TRUE);
priv->slaves = NULL;
}
g_clear_pointer (&priv->slaves, g_ptr_array_unref);
G_OBJECT_CLASS (nm_device_team_parent_class)->dispose (object);
}
@@ -239,7 +235,7 @@ get_property (GObject *object,
g_value_set_boolean (value, nm_device_team_get_carrier (device));
break;
case PROP_SLAVES:
g_value_set_boxed (value, nm_device_team_get_slaves (device));
g_value_take_boxed (value, _nm_utils_copy_object_array (nm_device_team_get_slaves (device)));
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
@@ -296,12 +292,14 @@ nm_device_team_class_init (NMDeviceTeamClass *team_class)
/**
* NMDeviceTeam:slaves:
*
* The devices (#NMDevice) enslaved to the team device.
* The devices enslaved to the team device.
*
* Element-type: NMDevice
**/
g_object_class_install_property
(object_class, PROP_SLAVES,
g_param_spec_boxed (NM_DEVICE_TEAM_SLAVES, "", "",
NM_TYPE_OBJECT_ARRAY,
G_TYPE_PTR_ARRAY,
G_PARAM_READABLE |
G_PARAM_STATIC_STRINGS));
}

View File

@@ -34,7 +34,7 @@
#include "nm-object-private.h"
#include "nm-object-cache.h"
#include "nm-dbus-glib-types.h"
#include "nm-types-private.h"
#include "nm-core-internal.h"
G_DEFINE_TYPE (NMDeviceWifi, nm_device_wifi, NM_TYPE_DEVICE)
@@ -348,9 +348,11 @@ nm_device_wifi_request_scan_simple (NMDeviceWifi *device,
}
static void
clean_up_aps (NMDeviceWifi *self, gboolean notify)
clean_up_aps (NMDeviceWifi *self, gboolean in_dispose)
{
NMDeviceWifiPrivate *priv;
GPtrArray *aps;
int i;
g_return_if_fail (NM_IS_DEVICE_WIFI (self));
@@ -361,18 +363,21 @@ clean_up_aps (NMDeviceWifi *self, gboolean notify)
priv->active_ap = NULL;
}
if (priv->aps) {
while (priv->aps->len) {
NMAccessPoint *ap = NM_ACCESS_POINT (g_ptr_array_index (priv->aps, 0));
aps = priv->aps;
if (notify)
g_signal_emit (self, signals[ACCESS_POINT_REMOVED], 0, ap);
g_ptr_array_remove (priv->aps, ap);
g_object_unref (ap);
}
g_ptr_array_free (priv->aps, TRUE);
if (in_dispose)
priv->aps = NULL;
else {
priv->aps = g_ptr_array_new ();
for (i = 0; i < aps->len; i++) {
NMAccessPoint *ap = NM_ACCESS_POINT (g_ptr_array_index (aps, i));
g_signal_emit (self, signals[ACCESS_POINT_REMOVED], 0, ap);
}
}
g_ptr_array_unref (aps);
}
/**
@@ -389,7 +394,7 @@ _nm_device_wifi_set_wireless_enabled (NMDeviceWifi *device,
g_return_if_fail (NM_IS_DEVICE_WIFI (device));
if (!enabled)
clean_up_aps (device, TRUE);
clean_up_aps (device, FALSE);
}
#define WPA_CAPS (NM_WIFI_DEVICE_CAP_CIPHER_TKIP | \
@@ -538,7 +543,7 @@ get_property (GObject *object,
g_value_set_uint (value, nm_device_wifi_get_capabilities (self));
break;
case PROP_ACCESS_POINTS:
g_value_set_boxed (value, nm_device_wifi_get_access_points (self));
g_value_take_boxed (value, _nm_utils_copy_object_array (nm_device_wifi_get_access_points (self)));
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
@@ -631,7 +636,8 @@ dispose (GObject *object)
priv->scan_call = NULL;
}
clean_up_aps (NM_DEVICE_WIFI (object), FALSE);
if (priv->aps)
clean_up_aps (NM_DEVICE_WIFI (object), TRUE);
g_clear_object (&priv->proxy);
G_OBJECT_CLASS (nm_device_wifi_parent_class)->dispose (object);
@@ -748,11 +754,13 @@ nm_device_wifi_class_init (NMDeviceWifiClass *wifi_class)
* NMDeviceWifi:access-points:
*
* List of all Wi-Fi access points the device can see.
*
* Element-type: NMAccessPoint
**/
g_object_class_install_property
(object_class, PROP_ACCESS_POINTS,
g_param_spec_boxed (NM_DEVICE_WIFI_ACCESS_POINTS, "", "",
NM_TYPE_OBJECT_ARRAY,
G_TYPE_PTR_ARRAY,
G_PARAM_READABLE |
G_PARAM_STATIC_STRINGS));

View File

@@ -32,7 +32,7 @@
#include "nm-object-private.h"
#include "nm-object-cache.h"
#include "nm-dbus-glib-types.h"
#include "nm-types-private.h"
#include "nm-core-internal.h"
#include "nm-device-private.h"
G_DEFINE_TYPE (NMDeviceWimax, nm_device_wimax, NM_TYPE_DEVICE)
@@ -200,7 +200,7 @@ nm_device_wimax_get_nsp_by_path (NMDeviceWimax *wimax,
}
static void
clean_up_nsps (NMDeviceWimax *self, gboolean notify)
clean_up_nsps (NMDeviceWimax *self)
{
NMDeviceWimaxPrivate *priv;
@@ -213,18 +213,7 @@ clean_up_nsps (NMDeviceWimax *self, gboolean notify)
priv->active_nsp = NULL;
}
if (priv->nsps) {
while (priv->nsps->len) {
NMWimaxNsp *nsp = NM_WIMAX_NSP (g_ptr_array_index (priv->nsps, 0));
if (notify)
g_signal_emit (self, signals[NSP_REMOVED], 0, nsp);
g_ptr_array_remove (priv->nsps, nsp);
g_object_unref (nsp);
}
g_ptr_array_free (priv->nsps, TRUE);
priv->nsps = NULL;
}
g_clear_pointer (&priv->nsps, g_ptr_array_unref);
}
/**
@@ -416,7 +405,7 @@ get_property (GObject *object,
g_value_set_string (value, nm_device_wimax_get_bsid (self));
break;
case PROP_NSPS:
g_value_set_boxed (value, nm_device_wimax_get_nsps (self));
g_value_take_boxed (value, _nm_utils_copy_object_array (nm_device_wimax_get_nsps (self)));
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
@@ -539,7 +528,8 @@ dispose (GObject *object)
priv->bsid = NULL;
}
clean_up_nsps (NM_DEVICE_WIMAX (object), FALSE);
if (priv->nsps)
clean_up_nsps (NM_DEVICE_WIMAX (object));
g_clear_object (&priv->proxy);
G_OBJECT_CLASS (nm_device_wimax_parent_class)->dispose (object);
@@ -666,11 +656,13 @@ nm_device_wimax_class_init (NMDeviceWimaxClass *wimax_class)
* NMDeviceWimax:nsps:
*
* List of all WiMAX Network Service Providers the device can see.
*
* Element-type: NMWimaxNsp
**/
g_object_class_install_property
(object_class, PROP_NSPS,
g_param_spec_boxed (NM_DEVICE_WIMAX_NSPS, "", "",
NM_TYPE_OBJECT_ARRAY,
G_TYPE_PTR_ARRAY,
G_PARAM_READABLE |
G_PARAM_STATIC_STRINGS));

View File

@@ -43,7 +43,7 @@
#include "nm-object-private.h"
#include "nm-object-cache.h"
#include "nm-remote-connection.h"
#include "nm-types.h"
#include "nm-core-internal.h"
#include "nm-dbus-glib-types.h"
#include "nm-glib-compat.h"
#include "nm-utils.h"
@@ -375,14 +375,7 @@ dispose (GObject *object)
g_clear_object (&priv->client);
g_clear_object (&priv->active_connection);
if (priv->available_connections) {
int i;
for (i = 0; i < priv->available_connections->len; i++)
g_object_unref (priv->available_connections->pdata[i]);
g_ptr_array_free (priv->available_connections, TRUE);
priv->available_connections = NULL;
}
g_clear_pointer (&priv->available_connections, g_ptr_array_unref);
G_OBJECT_CLASS (nm_device_parent_class)->dispose (object);
}
@@ -474,7 +467,7 @@ get_property (GObject *object,
g_value_set_object (value, nm_device_get_active_connection (device));
break;
case PROP_AVAILABLE_CONNECTIONS:
g_value_set_boxed (value, nm_device_get_available_connections (device));
g_value_take_boxed (value, _nm_utils_copy_object_array (nm_device_get_available_connections (device)));
break;
case PROP_PRODUCT:
g_value_set_string (value, nm_device_get_product (device));
@@ -766,12 +759,14 @@ nm_device_class_init (NMDeviceClass *device_class)
/**
* NMDevice:available-connections:
*
* The available connections (#NMRemoteConnection) of the device
* The available connections of the device
*
* Element-type: NMRemoteConnection
**/
g_object_class_install_property
(object_class, PROP_AVAILABLE_CONNECTIONS,
g_param_spec_boxed (NM_DEVICE_AVAILABLE_CONNECTIONS, "", "",
NM_TYPE_OBJECT_ARRAY,
G_TYPE_PTR_ARRAY,
G_PARAM_READABLE |
G_PARAM_STATIC_STRINGS));

View File

@@ -806,7 +806,7 @@ object_property_complete (ObjectCreatedData *odata)
int i;
/* Build up new array */
new = g_ptr_array_sized_new (odata->length);
new = g_ptr_array_new_full (odata->length, g_object_unref);
for (i = 0; i < odata->length; i++)
add_to_object_array_unique (new, odata->objects[i]);
@@ -843,8 +843,8 @@ object_property_complete (ObjectCreatedData *odata)
}
different = removed->len || added->len;
g_ptr_array_free (added, TRUE);
g_ptr_array_free (removed, TRUE);
g_ptr_array_unref (added);
g_ptr_array_unref (removed);
} else {
/* No added/removed signals to send, just replace the property with
* the new values.
@@ -857,7 +857,7 @@ object_property_complete (ObjectCreatedData *odata)
* any objects in the 'removed' array.
*/
if (old)
g_boxed_free (NM_TYPE_OBJECT_ARRAY, old);
g_ptr_array_unref (old);
} else {
GObject **obj_p = pi->field;

View File

@@ -30,7 +30,7 @@
#include "nm-dbus-helpers-private.h"
#include "nm-glib-compat.h"
#include "nm-object-private.h"
#include "nm-types.h"
#include "nm-core-internal.h"
/**
* SECTION:nm-remote-settings
@@ -333,12 +333,10 @@ connection_removed (NMRemoteSettings *self,
int i;
/* Check if the connection was actually removed or if it just turned invisible. */
if (priv->all_connections) {
for (i = 0; i < priv->all_connections->len; i++) {
if (remote == priv->all_connections->pdata[i]) {
still_exists = TRUE;
break;
}
for (i = 0; i < priv->all_connections->len; i++) {
if (remote == priv->all_connections->pdata[i]) {
still_exists = TRUE;
break;
}
}
@@ -743,19 +741,15 @@ nm_running_changed (GObject *object,
g_object_freeze_notify (object);
if (!_nm_object_get_nm_running (NM_OBJECT (self))) {
if (priv->all_connections) {
GPtrArray *connections;
int i;
GPtrArray *connections;
int i;
connections = priv->all_connections;
priv->all_connections = NULL;
for (i = 0; i < connections->len; i++) {
g_signal_emit (self, signals[CONNECTION_REMOVED], 0, connections->pdata[i]);
g_object_unref (connections->pdata[i]);
}
g_ptr_array_unref (connections);
}
/* Clear connections */
connections = priv->all_connections;
priv->all_connections = g_ptr_array_new ();
for (i = 0; i < connections->len; i++)
g_signal_emit (self, signals[CONNECTION_REMOVED], 0, connections->pdata[i]);
g_ptr_array_unref (connections);
/* Clear properties */
if (priv->hostname) {
@@ -912,19 +906,17 @@ dispose (GObject *object)
{
NMRemoteSettings *self = NM_REMOTE_SETTINGS (object);
NMRemoteSettingsPrivate *priv = NM_REMOTE_SETTINGS_GET_PRIVATE (self);
int i;
while (g_slist_length (priv->add_list))
add_connection_info_dispose (self, (AddConnectionInfo *) priv->add_list->data);
if (priv->all_connections) {
int i;
for (i = 0; i < priv->all_connections->len; i++) {
for (i = 0; i < priv->all_connections->len; i++)
cleanup_connection (self, priv->all_connections->pdata[i]);
g_object_unref (priv->all_connections->pdata[i]);
}
g_clear_pointer (&priv->all_connections, g_ptr_array_unref);
}
g_clear_pointer (&priv->visible_connections, g_ptr_array_unref);
g_clear_pointer (&priv->hostname, g_free);
g_clear_object (&priv->proxy);
@@ -943,7 +935,7 @@ get_property (GObject *object, guint prop_id,
g_value_set_boolean (value, _nm_object_get_nm_running (NM_OBJECT (object)));
break;
case PROP_CONNECTIONS:
g_value_set_boxed (value, priv->visible_connections);
g_value_take_boxed (value, _nm_utils_copy_object_array (priv->visible_connections));
break;
case PROP_HOSTNAME:
g_value_set_string (value, priv->hostname);
@@ -998,12 +990,12 @@ nm_remote_settings_class_init (NMRemoteSettingsClass *class)
* contain the object paths of connections that the user does not have
* permission to read the details of.)
*
* Type: GPtrArray
* Element-type: NMRemoteConnection
*/
g_object_class_install_property
(object_class, PROP_CONNECTIONS,
g_param_spec_boxed (NM_REMOTE_SETTINGS_CONNECTIONS, "", "",
NM_TYPE_OBJECT_ARRAY,
G_TYPE_PTR_ARRAY,
G_PARAM_READABLE |
G_PARAM_STATIC_STRINGS));

View File

@@ -26,10 +26,6 @@
#include "nm-object-private.h"
gboolean _nm_uint_array_demarshal (GValue *value, GArray **dest);
gboolean _nm_object_array_demarshal (GValue *value,
GPtrArray **dest,
DBusGConnection *connection,
NMObjectCreatorFunc func);
gboolean _nm_ip6_address_array_demarshal (GValue *value, GSList **dest);
#endif /* __NM_TYPES_PRIVATE_H__ */

View File

@@ -80,88 +80,6 @@ _nm_uint_array_demarshal (GValue *value, GArray **dest)
/*****************************/
static gpointer
_nm_object_array_copy (GPtrArray *src)
{
GPtrArray *dest;
int i;
dest = g_ptr_array_sized_new (src->len);
for (i = 0; i < src->len; i++)
g_ptr_array_add (dest, g_object_ref (g_ptr_array_index (src, i)));
return dest;
}
static void
_nm_object_array_free (GPtrArray *array)
{
int i;
for (i = 0; i < array->len; i++)
g_object_unref (g_ptr_array_index (array, i));
g_ptr_array_free (array, TRUE);
}
GType
nm_object_array_get_type (void)
{
static GType our_type = 0;
if (our_type == 0)
our_type = g_boxed_type_register_static (g_intern_static_string ("NMObjectArray"),
(GBoxedCopyFunc) _nm_object_array_copy,
(GBoxedFreeFunc) _nm_object_array_free);
return our_type;
}
gboolean
_nm_object_array_demarshal (GValue *value,
GPtrArray **dest,
DBusGConnection *connection,
NMObjectCreatorFunc func)
{
GPtrArray *temp = NULL;
GPtrArray *array;
if (!G_VALUE_HOLDS (value, DBUS_TYPE_G_ARRAY_OF_OBJECT_PATH))
return FALSE;
array = (GPtrArray *) g_value_get_boxed (value);
if (array && array->len) {
int i;
temp = g_ptr_array_sized_new (array->len);
for (i = 0; i < array->len; i++) {
const char *path;
GObject *object;
path = g_ptr_array_index (array, i);
object = G_OBJECT (_nm_object_cache_get (path));
if (object)
g_ptr_array_add (temp, object);
else {
object = (*func) (connection, path);
if (object)
g_ptr_array_add (temp, object);
else
g_warning ("%s: couldn't create object for %s", __func__, path);
}
}
} else
temp = g_ptr_array_new ();
/* Deallocate after to ensure that an object that might already
* be in the array doesn't get destroyed due to refcounting.
*/
if (*dest)
g_boxed_free (NM_TYPE_OBJECT_ARRAY, *dest);
*dest = temp;
return TRUE;
}
/*****************************/
static gpointer
_nm_ip6_address_object_array_copy (GPtrArray *src)
{

View File

@@ -35,9 +35,6 @@ G_BEGIN_DECLS
#define NM_TYPE_UINT_ARRAY (nm_uint_array_get_type ())
GType nm_uint_array_get_type (void) G_GNUC_CONST;
#define NM_TYPE_OBJECT_ARRAY (nm_object_array_get_type ())
GType nm_object_array_get_type (void) G_GNUC_CONST;
#define NM_TYPE_IP6_ADDRESS_OBJECT_ARRAY (nm_ip6_address_object_array_get_type ())
GType nm_ip6_address_object_array_get_type (void) G_GNUC_CONST;