Commit 2e48cc09 authored by Dan Winship's avatar Dan Winship Committed by Dan Williams

libnm-glib: simplify and genericize property declaration

Rename _nm_object_handle_properties_changed(), etc, to be about
properties in general, rather than just property changes.

Interpret func==NULL in NMPropertiesInfo as meaning "use
_nm_object_demarshal_generic", and then reorder the fields so that you
can just leave that field out in the declarations when it's NULL.

Add a way to register properties that exist in D-Bus but aren't
tracked by the NMObjects, and use that for NMDevice's D-Bus Ip4Address
property, replacing the existing hack.

Also add a few other missing properties noticed along the way.
parent 38382770
......@@ -593,25 +593,25 @@ demarshal_ssid (NMObject *object, GParamSpec *pspec, GValue *value, gpointer fie
}
static void
register_for_property_changed (NMAccessPoint *ap)
register_properties (NMAccessPoint *ap)
{
NMAccessPointPrivate *priv = NM_ACCESS_POINT_GET_PRIVATE (ap);
const NMPropertiesChangedInfo property_changed_info[] = {
{ NM_ACCESS_POINT_FLAGS, _nm_object_demarshal_generic, &priv->flags },
{ NM_ACCESS_POINT_WPA_FLAGS, _nm_object_demarshal_generic, &priv->wpa_flags },
{ NM_ACCESS_POINT_RSN_FLAGS, _nm_object_demarshal_generic, &priv->rsn_flags },
{ NM_ACCESS_POINT_SSID, demarshal_ssid, &priv->ssid },
{ NM_ACCESS_POINT_FREQUENCY, _nm_object_demarshal_generic, &priv->frequency },
{ NM_ACCESS_POINT_HW_ADDRESS, _nm_object_demarshal_generic, &priv->bssid },
{ NM_ACCESS_POINT_MODE, _nm_object_demarshal_generic, &priv->mode },
{ NM_ACCESS_POINT_MAX_BITRATE, _nm_object_demarshal_generic, &priv->max_bitrate },
{ NM_ACCESS_POINT_STRENGTH, _nm_object_demarshal_generic, &priv->strength },
const NMPropertiesInfo property_info[] = {
{ NM_ACCESS_POINT_FLAGS, &priv->flags },
{ NM_ACCESS_POINT_WPA_FLAGS, &priv->wpa_flags },
{ NM_ACCESS_POINT_RSN_FLAGS, &priv->rsn_flags },
{ NM_ACCESS_POINT_SSID, &priv->ssid, demarshal_ssid },
{ NM_ACCESS_POINT_FREQUENCY, &priv->frequency },
{ NM_ACCESS_POINT_HW_ADDRESS, &priv->bssid },
{ NM_ACCESS_POINT_MODE, &priv->mode },
{ NM_ACCESS_POINT_MAX_BITRATE, &priv->max_bitrate },
{ NM_ACCESS_POINT_STRENGTH, &priv->strength },
{ NULL },
};
_nm_object_handle_properties_changed (NM_OBJECT (ap),
priv->proxy,
property_changed_info);
_nm_object_register_properties (NM_OBJECT (ap),
priv->proxy,
property_info);
}
static GObject*
......@@ -635,7 +635,7 @@ constructor (GType type,
nm_object_get_path (object),
NM_DBUS_INTERFACE_ACCESS_POINT);
register_for_property_changed (NM_ACCESS_POINT (object));
register_properties (NM_ACCESS_POINT (object));
return G_OBJECT (object);
}
......
......@@ -410,22 +410,24 @@ demarshal_devices (NMObject *object, GParamSpec *pspec, GValue *value, gpointer
}
static void
register_for_property_changed (NMActiveConnection *connection)
register_properties (NMActiveConnection *connection)
{
NMActiveConnectionPrivate *priv = NM_ACTIVE_CONNECTION_GET_PRIVATE (connection);
const NMPropertiesChangedInfo property_changed_info[] = {
{ NM_ACTIVE_CONNECTION_CONNECTION, _nm_object_demarshal_generic, &priv->connection },
{ NM_ACTIVE_CONNECTION_SPECIFIC_OBJECT, _nm_object_demarshal_generic, &priv->specific_object },
{ NM_ACTIVE_CONNECTION_DEVICES, demarshal_devices, &priv->devices },
{ NM_ACTIVE_CONNECTION_STATE, _nm_object_demarshal_generic, &priv->state },
{ NM_ACTIVE_CONNECTION_DEFAULT, _nm_object_demarshal_generic, &priv->is_default },
{ NM_ACTIVE_CONNECTION_DEFAULT6, _nm_object_demarshal_generic, &priv->is_default6 },
const NMPropertiesInfo property_info[] = {
{ NM_ACTIVE_CONNECTION_CONNECTION, &priv->connection },
{ NM_ACTIVE_CONNECTION_UUID, &priv->uuid },
{ NM_ACTIVE_CONNECTION_SPECIFIC_OBJECT, &priv->specific_object },
{ NM_ACTIVE_CONNECTION_DEVICES, &priv->devices, demarshal_devices },
{ NM_ACTIVE_CONNECTION_STATE, &priv->state },
{ NM_ACTIVE_CONNECTION_DEFAULT, &priv->is_default },
{ NM_ACTIVE_CONNECTION_DEFAULT6, &priv->is_default6 },
{ NM_ACTIVE_CONNECTION_MASTER, &priv->master },
{ NULL },
};
_nm_object_handle_properties_changed (NM_OBJECT (connection),
priv->proxy,
property_changed_info);
_nm_object_register_properties (NM_OBJECT (connection),
priv->proxy,
property_info);
}
static GObject*
......@@ -449,7 +451,7 @@ constructor (GType type,
nm_object_get_path (object),
NM_DBUS_INTERFACE_ACTIVE_CONNECTION);
register_for_property_changed (NM_ACTIVE_CONNECTION (object));
register_properties (NM_ACTIVE_CONNECTION (object));
return G_OBJECT (object);
}
......
......@@ -314,26 +314,26 @@ demarshal_active_connections (NMObject *object,
}
static void
register_for_property_changed (NMClient *client)
register_properties (NMClient *client)
{
NMClientPrivate *priv = NM_CLIENT_GET_PRIVATE (client);
const NMPropertiesChangedInfo property_changed_info[] = {
{ NM_CLIENT_VERSION, _nm_object_demarshal_generic, &priv->version },
{ NM_CLIENT_STATE, _nm_object_demarshal_generic, &priv->state },
{ NM_CLIENT_NETWORKING_ENABLED, _nm_object_demarshal_generic, &priv->networking_enabled },
{ NM_CLIENT_WIRELESS_ENABLED, _nm_object_demarshal_generic, &priv->wireless_enabled },
{ NM_CLIENT_WIRELESS_HARDWARE_ENABLED, _nm_object_demarshal_generic, &priv->wireless_hw_enabled },
{ NM_CLIENT_WWAN_ENABLED, _nm_object_demarshal_generic, &priv->wwan_enabled },
{ NM_CLIENT_WWAN_HARDWARE_ENABLED, _nm_object_demarshal_generic, &priv->wwan_hw_enabled },
{ NM_CLIENT_WIMAX_ENABLED, _nm_object_demarshal_generic, &priv->wimax_enabled },
{ NM_CLIENT_WIMAX_HARDWARE_ENABLED, _nm_object_demarshal_generic, &priv->wimax_hw_enabled },
{ NM_CLIENT_ACTIVE_CONNECTIONS, demarshal_active_connections, &priv->active_connections },
const NMPropertiesInfo property_info[] = {
{ NM_CLIENT_VERSION, &priv->version },
{ NM_CLIENT_STATE, &priv->state },
{ NM_CLIENT_NETWORKING_ENABLED, &priv->networking_enabled },
{ NM_CLIENT_WIRELESS_ENABLED, &priv->wireless_enabled },
{ NM_CLIENT_WIRELESS_HARDWARE_ENABLED, &priv->wireless_hw_enabled },
{ NM_CLIENT_WWAN_ENABLED, &priv->wwan_enabled },
{ NM_CLIENT_WWAN_HARDWARE_ENABLED, &priv->wwan_hw_enabled },
{ NM_CLIENT_WIMAX_ENABLED, &priv->wimax_enabled },
{ NM_CLIENT_WIMAX_HARDWARE_ENABLED, &priv->wimax_hw_enabled },
{ NM_CLIENT_ACTIVE_CONNECTIONS, &priv->active_connections, demarshal_active_connections },
{ NULL },
};
_nm_object_handle_properties_changed (NM_OBJECT (client),
priv->client_proxy,
property_changed_info);
_nm_object_register_properties (NM_OBJECT (client),
priv->client_proxy,
property_info);
}
#define NM_AUTH_PERMISSION_ENABLE_DISABLE_NETWORK "org.freedesktop.NetworkManager.enable-disable-network"
......@@ -1385,7 +1385,7 @@ constructor (GType type,
nm_object_get_path (object),
NM_DBUS_INTERFACE);
register_for_property_changed (NM_CLIENT (object));
register_properties (NM_CLIENT (object));
dbus_g_proxy_add_signal (priv->client_proxy, "DeviceAdded", DBUS_TYPE_G_OBJECT_PATH, G_TYPE_INVALID);
dbus_g_proxy_connect_signal (priv->client_proxy,
......
......@@ -230,19 +230,19 @@ nm_device_bt_init (NMDeviceBt *device)
}
static void
register_for_property_changed (NMDeviceBt *device)
register_properties (NMDeviceBt *device)
{
NMDeviceBtPrivate *priv = NM_DEVICE_BT_GET_PRIVATE (device);
const NMPropertiesChangedInfo property_changed_info[] = {
{ NM_DEVICE_BT_HW_ADDRESS, _nm_object_demarshal_generic, &priv->hw_address },
{ NM_DEVICE_BT_NAME, _nm_object_demarshal_generic, &priv->name },
{ NM_DEVICE_BT_CAPABILITIES, _nm_object_demarshal_generic, &priv->bt_capabilities },
const NMPropertiesInfo property_info[] = {
{ NM_DEVICE_BT_HW_ADDRESS, &priv->hw_address },
{ NM_DEVICE_BT_NAME, &priv->name },
{ NM_DEVICE_BT_CAPABILITIES, &priv->bt_capabilities },
{ NULL },
};
_nm_object_handle_properties_changed (NM_OBJECT (device),
priv->proxy,
property_changed_info);
_nm_object_register_properties (NM_OBJECT (device),
priv->proxy,
property_info);
}
static GObject*
......@@ -263,7 +263,7 @@ constructor (GType type,
nm_object_get_path (NM_OBJECT (object)),
NM_DBUS_INTERFACE_DEVICE_BLUETOOTH);
register_for_property_changed (NM_DEVICE_BT (object));
register_properties (NM_DEVICE_BT (object));
}
return object;
......
......@@ -247,20 +247,20 @@ nm_device_ethernet_init (NMDeviceEthernet *device)
}
static void
register_for_property_changed (NMDeviceEthernet *device)
register_properties (NMDeviceEthernet *device)
{
NMDeviceEthernetPrivate *priv = NM_DEVICE_ETHERNET_GET_PRIVATE (device);
const NMPropertiesChangedInfo property_changed_info[] = {
{ NM_DEVICE_ETHERNET_HW_ADDRESS, _nm_object_demarshal_generic, &priv->hw_address },
{ NM_DEVICE_ETHERNET_PERMANENT_HW_ADDRESS, _nm_object_demarshal_generic, &priv->perm_hw_address },
{ NM_DEVICE_ETHERNET_SPEED, _nm_object_demarshal_generic, &priv->speed },
{ NM_DEVICE_ETHERNET_CARRIER, _nm_object_demarshal_generic, &priv->carrier },
const NMPropertiesInfo property_info[] = {
{ NM_DEVICE_ETHERNET_HW_ADDRESS, &priv->hw_address },
{ NM_DEVICE_ETHERNET_PERMANENT_HW_ADDRESS, &priv->perm_hw_address },
{ NM_DEVICE_ETHERNET_SPEED, &priv->speed },
{ NM_DEVICE_ETHERNET_CARRIER, &priv->carrier },
{ NULL },
};
_nm_object_handle_properties_changed (NM_OBJECT (device),
priv->proxy,
property_changed_info);
_nm_object_register_properties (NM_OBJECT (device),
priv->proxy,
property_info);
}
static GObject*
......@@ -284,7 +284,7 @@ constructor (GType type,
nm_object_get_path (NM_OBJECT (object)),
NM_DBUS_INTERFACE_DEVICE_WIRED);
register_for_property_changed (NM_DEVICE_ETHERNET (object));
register_properties (NM_DEVICE_ETHERNET (object));
return object;
}
......
......@@ -175,18 +175,18 @@ nm_device_infiniband_init (NMDeviceInfiniband *device)
}
static void
register_for_property_changed (NMDeviceInfiniband *device)
register_properties (NMDeviceInfiniband *device)
{
NMDeviceInfinibandPrivate *priv = NM_DEVICE_INFINIBAND_GET_PRIVATE (device);
const NMPropertiesChangedInfo property_changed_info[] = {
{ NM_DEVICE_INFINIBAND_HW_ADDRESS, _nm_object_demarshal_generic, &priv->hw_address },
{ NM_DEVICE_INFINIBAND_CARRIER, _nm_object_demarshal_generic, &priv->carrier },
const NMPropertiesInfo property_info[] = {
{ NM_DEVICE_INFINIBAND_HW_ADDRESS, &priv->hw_address },
{ NM_DEVICE_INFINIBAND_CARRIER, &priv->carrier },
{ NULL },
};
_nm_object_handle_properties_changed (NM_OBJECT (device),
priv->proxy,
property_changed_info);
_nm_object_register_properties (NM_OBJECT (device),
priv->proxy,
property_info);
}
static GObject*
......@@ -210,7 +210,7 @@ constructor (GType type,
nm_object_get_path (NM_OBJECT (object)),
NM_DBUS_INTERFACE_DEVICE_INFINIBAND);
register_for_property_changed (NM_DEVICE_INFINIBAND (object));
register_properties (NM_DEVICE_INFINIBAND (object));
return object;
}
......
......@@ -151,18 +151,18 @@ connection_valid (NMDevice *device, NMConnection *connection)
/*******************************************************************/
static void
register_for_property_changed (NMDeviceModem *device)
register_properties (NMDeviceModem *device)
{
NMDeviceModemPrivate *priv = NM_DEVICE_MODEM_GET_PRIVATE (device);
const NMPropertiesChangedInfo property_changed_info[] = {
{ NM_DEVICE_MODEM_MODEM_CAPABILITIES, _nm_object_demarshal_generic, &priv->caps },
{ NM_DEVICE_MODEM_CURRENT_CAPABILITIES, _nm_object_demarshal_generic, &priv->current_caps },
const NMPropertiesInfo property_info[] = {
{ NM_DEVICE_MODEM_MODEM_CAPABILITIES, &priv->caps },
{ NM_DEVICE_MODEM_CURRENT_CAPABILITIES, &priv->current_caps },
{ NULL },
};
_nm_object_handle_properties_changed (NM_OBJECT (device),
priv->proxy,
property_changed_info);
_nm_object_register_properties (NM_OBJECT (device),
priv->proxy,
property_info);
}
static GObject*
......@@ -184,7 +184,7 @@ constructor (GType type,
nm_object_get_path (NM_OBJECT (object)),
NM_DBUS_INTERFACE_DEVICE_MODEM);
register_for_property_changed (NM_DEVICE_MODEM (object));
register_properties (NM_DEVICE_MODEM (object));
}
return object;
......
......@@ -667,22 +667,22 @@ demarshal_active_ap (NMObject *object, GParamSpec *pspec, GValue *value, gpointe
}
static void
register_for_property_changed (NMDeviceWifi *device)
register_properties (NMDeviceWifi *device)
{
NMDeviceWifiPrivate *priv = NM_DEVICE_WIFI_GET_PRIVATE (device);
const NMPropertiesChangedInfo property_changed_info[] = {
{ NM_DEVICE_WIFI_HW_ADDRESS, _nm_object_demarshal_generic, &priv->hw_address },
{ NM_DEVICE_WIFI_PERMANENT_HW_ADDRESS, _nm_object_demarshal_generic, &priv->perm_hw_address },
{ NM_DEVICE_WIFI_MODE, _nm_object_demarshal_generic, &priv->mode },
{ NM_DEVICE_WIFI_BITRATE, _nm_object_demarshal_generic, &priv->rate },
{ NM_DEVICE_WIFI_ACTIVE_ACCESS_POINT, demarshal_active_ap, &priv->active_ap },
{ NM_DEVICE_WIFI_CAPABILITIES, _nm_object_demarshal_generic, &priv->wireless_caps },
const NMPropertiesInfo property_info[] = {
{ NM_DEVICE_WIFI_HW_ADDRESS, &priv->hw_address },
{ NM_DEVICE_WIFI_PERMANENT_HW_ADDRESS, &priv->perm_hw_address },
{ NM_DEVICE_WIFI_MODE, &priv->mode },
{ NM_DEVICE_WIFI_BITRATE, &priv->rate },
{ NM_DEVICE_WIFI_ACTIVE_ACCESS_POINT, &priv->active_ap, demarshal_active_ap },
{ NM_DEVICE_WIFI_CAPABILITIES, &priv->wireless_caps },
{ NULL },
};
_nm_object_handle_properties_changed (NM_OBJECT (device),
priv->proxy,
property_changed_info);
_nm_object_register_properties (NM_OBJECT (device),
priv->proxy,
property_info);
}
static GObject*
......@@ -720,7 +720,7 @@ constructor (GType type,
G_CALLBACK (access_point_removed_proxy),
object, NULL);
register_for_property_changed (NM_DEVICE_WIFI (object));
register_properties (NM_DEVICE_WIFI (object));
g_signal_connect (NM_DEVICE (object),
"notify::" NM_DEVICE_STATE,
......
......@@ -658,23 +658,23 @@ demarshal_active_nsp (NMObject *object, GParamSpec *pspec, GValue *value, gpoint
}
static void
register_for_property_changed (NMDeviceWimax *wimax)
register_properties (NMDeviceWimax *wimax)
{
NMDeviceWimaxPrivate *priv = NM_DEVICE_WIMAX_GET_PRIVATE (wimax);
const NMPropertiesChangedInfo property_changed_info[] = {
{ NM_DEVICE_WIMAX_HW_ADDRESS, _nm_object_demarshal_generic, &priv->hw_address },
{ NM_DEVICE_WIMAX_ACTIVE_NSP, demarshal_active_nsp, &priv->active_nsp },
{ NM_DEVICE_WIMAX_CENTER_FREQUENCY, _nm_object_demarshal_generic, &priv->center_freq },
{ NM_DEVICE_WIMAX_RSSI, _nm_object_demarshal_generic, &priv->rssi },
{ NM_DEVICE_WIMAX_CINR, _nm_object_demarshal_generic, &priv->cinr },
{ NM_DEVICE_WIMAX_TX_POWER, _nm_object_demarshal_generic, &priv->tx_power },
{ NM_DEVICE_WIMAX_BSID, _nm_object_demarshal_generic, &priv->bsid },
const NMPropertiesInfo property_info[] = {
{ NM_DEVICE_WIMAX_HW_ADDRESS, &priv->hw_address },
{ NM_DEVICE_WIMAX_ACTIVE_NSP, &priv->active_nsp, demarshal_active_nsp },
{ NM_DEVICE_WIMAX_CENTER_FREQUENCY, &priv->center_freq },
{ NM_DEVICE_WIMAX_RSSI, &priv->rssi },
{ NM_DEVICE_WIMAX_CINR, &priv->cinr },
{ NM_DEVICE_WIMAX_TX_POWER, &priv->tx_power },
{ NM_DEVICE_WIMAX_BSID, &priv->bsid },
{ NULL },
};
_nm_object_handle_properties_changed (NM_OBJECT (wimax),
priv->proxy,
property_changed_info);
_nm_object_register_properties (NM_OBJECT (wimax),
priv->proxy,
property_info);
}
static GObject*
......@@ -712,7 +712,7 @@ constructor (GType type,
G_CALLBACK (nsp_removed_proxy),
object, NULL);
register_for_property_changed (NM_DEVICE_WIMAX (object));
register_properties (NM_DEVICE_WIMAX (object));
g_signal_connect (object,
"notify::" NM_DEVICE_STATE,
......
......@@ -293,28 +293,35 @@ demarshal_active_connection (NMObject *object, GParamSpec *pspec, GValue *value,
}
static void
register_for_property_changed (NMDevice *device)
register_properties (NMDevice *device)
{
NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE (device);
const NMPropertiesChangedInfo property_changed_info[] = {
{ NM_DEVICE_UDI, _nm_object_demarshal_generic, &priv->udi },
{ NM_DEVICE_INTERFACE, _nm_object_demarshal_generic, &priv->iface },
{ NM_DEVICE_IP_INTERFACE, _nm_object_demarshal_generic, &priv->ip_iface },
{ NM_DEVICE_DRIVER, _nm_object_demarshal_generic, &priv->driver },
{ NM_DEVICE_CAPABILITIES, _nm_object_demarshal_generic, &priv->capabilities },
{ NM_DEVICE_MANAGED, _nm_object_demarshal_generic, &priv->managed },
{ NM_DEVICE_FIRMWARE_MISSING, _nm_object_demarshal_generic, &priv->firmware_missing },
{ NM_DEVICE_IP4_CONFIG, demarshal_ip4_config, &priv->ip4_config },
{ NM_DEVICE_DHCP4_CONFIG, demarshal_dhcp4_config, &priv->dhcp4_config },
{ NM_DEVICE_IP6_CONFIG, demarshal_ip6_config, &priv->ip6_config },
{ NM_DEVICE_DHCP6_CONFIG, demarshal_dhcp6_config, &priv->dhcp6_config },
{ NM_DEVICE_ACTIVE_CONNECTION,demarshal_active_connection, &priv->active_connection },
const NMPropertiesInfo property_info[] = {
{ NM_DEVICE_UDI, &priv->udi },
{ NM_DEVICE_INTERFACE, &priv->iface },
{ NM_DEVICE_IP_INTERFACE, &priv->ip_iface },
{ NM_DEVICE_DRIVER, &priv->driver },
{ NM_DEVICE_CAPABILITIES, &priv->capabilities },
{ NM_DEVICE_MANAGED, &priv->managed },
{ NM_DEVICE_FIRMWARE_MISSING, &priv->firmware_missing },
{ NM_DEVICE_IP4_CONFIG, &priv->ip4_config, demarshal_ip4_config },
{ NM_DEVICE_DHCP4_CONFIG, &priv->dhcp4_config, demarshal_dhcp4_config },
{ NM_DEVICE_IP6_CONFIG, &priv->ip6_config, demarshal_ip6_config },
{ NM_DEVICE_DHCP6_CONFIG, &priv->dhcp6_config, demarshal_dhcp6_config },
{ NM_DEVICE_STATE, &priv->state },
{ NM_DEVICE_ACTIVE_CONNECTION, &priv->active_connection, demarshal_active_connection },
/* The D-Bus interface has this property, but we don't; register
* it so that handle_property_changed() doesn't complain.
*/
{ "ip4-address", NULL },
{ NULL },
};
_nm_object_handle_properties_changed (NM_OBJECT (device),
priv->proxy,
property_changed_info);
_nm_object_register_properties (NM_OBJECT (device),
priv->proxy,
property_info);
}
static void
......@@ -356,11 +363,6 @@ get_all_cb (DBusGProxy *proxy, DBusGProxyCall *call, gpointer user_data)
}
g_object_unref (proxy);
/* Hack: libnm-glib's NMDevice doesn't have ip4-address property. Remove
* it from the hash to prevent warnings.
*/
g_hash_table_remove (props, "Ip4Address");
_nm_object_process_properties_changed (NM_OBJECT (self), props);
g_hash_table_destroy (props);
......@@ -409,7 +411,7 @@ constructor (GType type,
nm_object_get_path (object),
NM_DBUS_INTERFACE_DEVICE);
register_for_property_changed (NM_DEVICE (object));
register_properties (NM_DEVICE (object));
/* Get initial properties, so that we have all properties set even if
* no PropertiesChanged signal is received.
......
......@@ -77,17 +77,17 @@ demarshal_dhcp4_options (NMObject *object, GParamSpec *pspec, GValue *value, gpo
}
static void
register_for_property_changed (NMDHCP4Config *config)
register_properties (NMDHCP4Config *config)
{
NMDHCP4ConfigPrivate *priv = NM_DHCP4_CONFIG_GET_PRIVATE (config);
const NMPropertiesChangedInfo property_changed_info[] = {
{ NM_DHCP4_CONFIG_OPTIONS, demarshal_dhcp4_options, &priv->options },
const NMPropertiesInfo property_info[] = {
{ NM_DHCP4_CONFIG_OPTIONS, &priv->options, demarshal_dhcp4_options },
{ NULL },
};
_nm_object_handle_properties_changed (NM_OBJECT (config),
priv->proxy,
property_changed_info);
_nm_object_register_properties (NM_OBJECT (config),
priv->proxy,
property_info);
}
static GObject*
......@@ -115,7 +115,7 @@ constructor (GType type,
nm_object_get_path (object),
NM_DBUS_INTERFACE_DHCP4_CONFIG);
register_for_property_changed (NM_DHCP4_CONFIG (object));
register_properties (NM_DHCP4_CONFIG (object));
return G_OBJECT (object);
}
......
......@@ -77,17 +77,17 @@ demarshal_dhcp6_options (NMObject *object, GParamSpec *pspec, GValue *value, gpo
}
static void
register_for_property_changed (NMDHCP6Config *config)
register_properties (NMDHCP6Config *config)
{
NMDHCP6ConfigPrivate *priv = NM_DHCP6_CONFIG_GET_PRIVATE (config);
const NMPropertiesChangedInfo property_changed_info[] = {
{ NM_DHCP6_CONFIG_OPTIONS, demarshal_dhcp6_options, &priv->options },
const NMPropertiesInfo property_info[] = {
{ NM_DHCP6_CONFIG_OPTIONS, &priv->options, demarshal_dhcp6_options },
{ NULL },
};
_nm_object_handle_properties_changed (NM_OBJECT (config),
priv->proxy,
property_changed_info);
_nm_object_register_properties (NM_OBJECT (config),
priv->proxy,
property_info);
}
static GObject*
......@@ -115,7 +115,7 @@ constructor (GType type,
nm_object_get_path (object),
NM_DBUS_INTERFACE_DHCP6_CONFIG);
register_for_property_changed (NM_DHCP6_CONFIG (object));
register_properties (NM_DHCP6_CONFIG (object));
return G_OBJECT (object);
}
......
......@@ -115,21 +115,21 @@ demarshal_ip4_routes_array (NMObject *object, GParamSpec *pspec, GValue *value,
}
static void
register_for_property_changed (NMIP4Config *config)
register_properties (NMIP4Config *config)
{
NMIP4ConfigPrivate *priv = NM_IP4_CONFIG_GET_PRIVATE (config);
const NMPropertiesChangedInfo property_changed_info[] = {
{ NM_IP4_CONFIG_ADDRESSES, demarshal_ip4_address_array, &priv->addresses },
{ NM_IP4_CONFIG_NAMESERVERS, demarshal_ip4_array, &priv->nameservers },
{ NM_IP4_CONFIG_DOMAINS, demarshal_domains, &priv->domains },
{ NM_IP4_CONFIG_ROUTES, demarshal_ip4_routes_array, &priv->routes },
{ NM_IP4_CONFIG_WINS_SERVERS, demarshal_ip4_array, &priv->wins },
const NMPropertiesInfo property_info[] = {
{ NM_IP4_CONFIG_ADDRESSES, &priv->addresses, demarshal_ip4_address_array },
{ NM_IP4_CONFIG_NAMESERVERS, &priv->nameservers, demarshal_ip4_array },
{ NM_IP4_CONFIG_DOMAINS, &priv->domains, demarshal_domains },
{ NM_IP4_CONFIG_ROUTES, &priv->routes, demarshal_ip4_routes_array },
{ NM_IP4_CONFIG_WINS_SERVERS, &priv->wins, demarshal_ip4_array },
{ NULL },
};
_nm_object_handle_properties_changed (NM_OBJECT (config),
priv->proxy,
property_changed_info);
_nm_object_register_properties (NM_OBJECT (config),
priv->proxy,
property_info);
}
static GObject*
......@@ -155,7 +155,7 @@ constructor (GType type,
nm_object_get_path (object),
NM_DBUS_INTERFACE_IP4_CONFIG);
register_for_property_changed (NM_IP4_CONFIG (object));
register_properties (NM_IP4_CONFIG (object));
return G_OBJECT (object);
}
......
......@@ -124,20 +124,20 @@ demarshal_ip6_routes_array (NMObject *object, GParamSpec *pspec, GValue *value,
}
static void
register_for_property_changed (NMIP6Config *config)
register_properties (NMIP6Config *config)
{
NMIP6ConfigPrivate *priv = NM_IP6_CONFIG_GET_PRIVATE (config);
const NMPropertiesChangedInfo property_changed_info[] = {
{ NM_IP6_CONFIG_ADDRESSES, demarshal_ip6_address_array, &priv->addresses },
{ NM_IP6_CONFIG_NAMESERVERS, demarshal_ip6_nameserver_array, &priv->nameservers },
{ NM_IP6_CONFIG_DOMAINS, demarshal_domains, &priv->domains },
{ NM_IP6_CONFIG_ROUTES, demarshal_ip6_routes_array, &priv->routes },
const NMPropertiesInfo property_info[] = {
{ NM_IP6_CONFIG_ADDRESSES, &priv->addresses, demarshal_ip6_address_array },
{ NM_IP6_CONFIG_NAMESERVERS, &priv->nameservers, demarshal_ip6_nameserver_array },
{ NM_IP6_CONFIG_DOMAINS, &priv->domains, demarshal_domains },
{ NM_IP6_CONFIG_ROUTES, &priv->routes, demarshal_ip6_routes_array },
{ NULL },
};
_nm_object_handle_properties_changed (NM_OBJECT (config),
priv->proxy,
property_changed_info);
_nm_object_register_properties (NM_OBJECT (config),
priv->proxy,
property_info);
}
/**
......@@ -309,7 +309,7 @@ constructor (GType type,
nm_object_get_path (NM_OBJECT (object)),
NM_DBUS_INTERFACE_IP6_CONFIG);
register_for_property_changed (NM_IP6_CONFIG (object));
register_properties (NM_IP6_CONFIG (object));
return object;
}
......
......@@ -27,24 +27,22 @@
#include <glib-object.h>
#include "nm-object.h"
typedef gboolean (*PropChangedMarshalFunc) (NMObject *, GParamSpec *, GValue *, gpointer);
typedef gboolean (*PropertyMarshalFunc) (NMObject *, GParamSpec *, GValue *, gpointer);
typedef GObject * (*NMObjectCreatorFunc) (DBusGConnection *, const char *);
typedef struct {
const char *name;
PropChangedMarshalFunc func;
gpointer field;
} NMPropertiesChangedInfo;
PropertyMarshalFunc func;
} NMPropertiesInfo;
void _nm_object_handle_properties_changed (NMObject *object,
DBusGProxy *proxy,
const NMPropertiesChangedInfo *info);
void _nm_object_register_properties (NMObject *object,
DBusGProxy *proxy,
const NMPropertiesInfo *info);
void _nm_object_process_properties_changed (NMObject *self, GHashTable *properties);
gboolean _nm_object_demarshal_generic (NMObject *object, GParamSpec *pspec, GValue *value, gpointer field);
void _nm_object_queue_notify (NMObject *object, const char *property);
/* DBus property accessors */
......
......@@ -22,6 +22,7 @@
*/
#include <string.h>
#include <gio/gio.h>
#include <nm-utils.h>
#include "NetworkManager.h"
#include "nm-object.h"
......@@ -37,15 +38,16 @@ G_DEFINE_ABSTRACT_TYPE (NMObject, nm_object, G_TYPE_OBJECT)
#define NM_OBJECT_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), NM_TYPE_OBJECT, NMObjectPrivate))
typedef struct {
PropChangedMarshalFunc func;
PropertyMarshalFunc func;
gpointer field;
} PropChangedInfo;
} PropertyInfo;
typedef struct {
DBusGConnection *connection;
char *path;
DBusGProxy *properties_proxy;
GSList *pcs;
GSList *property_interfaces;
GSList *property_tables;
NMObject *parent;
GSList *notify_props;
......@@ -118,6 +120,9 @@ dispose (GObject *object)
g_slist_foreach (priv->notify_props, (GFunc) g_free, NULL);
g_slist_free (priv->notify_props);
g_slist_foreach (priv->property_interfaces, (GFunc) g_free, NULL);
g_slist_free (priv->property_interfaces);
g_object_unref (priv->properties_proxy);
dbus_g_connection_unref (priv->connection);
......@@ -129,8 +134,8 @@ finalize (GObject *object)
{
NMObjectPrivate *priv = NM_OBJECT_GET_PRIVATE (object);
g_slist_foreach (priv->pcs, (GFunc) g_hash_table_destroy, NULL);
g_slist_free (priv->pcs);
g_slist_foreach (priv->property_tables, (GFunc) g_hash_table_destroy, NULL);
g_slist_free (priv->property_tables);
g_free (priv->path);
G_OBJECT_CLASS (nm_object_parent_class)->finalize (object);
......@@ -334,37 +339,25 @@ handle_property_changed (gpointer key, gpointer data, gpointer user_data)
NMObject *self = NM_OBJECT (user_data);
NMObjectPrivate *priv = NM_OBJECT_GET_PRIVATE (self);
char *prop_name;
PropChangedInfo *pci;
PropertyInfo *pi;
GParamSpec *pspec;
gboolean success = FALSE, found = FALSE;
GSList *iter;
GValue *value = data;
prop_name = wincaps_to_dash ((char *) key);
pspec = g_object_class_find_property (G_OBJECT_GET_CLASS (G_OBJECT (self)), prop_name);
if (!pspec) {
g_warning ("%s: property '%s' changed but wasn't defined by object type %s.",
__func__,
prop_name,
G_OBJECT_TYPE_NAME (self));
goto out;
}
/* Iterate through the object and its parents to find the property */
for (iter = priv->pcs; iter; iter = g_slist_next (iter)) {
pci = g_hash_table_lookup ((GHashTable *) iter->data, prop_name);
if (pci) {
found = TRUE;
/* Handle NULL object paths */
if (G_VALUE_HOLDS (value, DBUS_TYPE_G_OBJECT_PATH)) {
if (g_strcmp0 (g_value_get_boxed (value), "/") == 0)