Commit 5afcee46 authored by Dan Winship's avatar Dan Winship Committed by Dan Williams

libnm-glib: simplify property getter methods

Rather than having every property getter method have code to fetch
that specific property's value, just call the new
_nm_object_ensure_inited() (which makes sure that we've read all the
property values on the object at least once), and then return the
cached value. (After we've read the initial property values, the
PropertiesChanged signal handler will ensure that the values are kept
up to date, so we can always just return cached property values after
that point.)

This then lets us get rid of _nm_object_get_property() and its
wrappers.
parent 2e48cc09
......@@ -113,19 +113,10 @@ nm_access_point_new (DBusGConnection *connection, const char *path)
NM80211ApFlags
nm_access_point_get_flags (NMAccessPoint *ap)
{
NMAccessPointPrivate *priv;
g_return_val_if_fail (NM_IS_ACCESS_POINT (ap), NM_802_11_AP_FLAGS_NONE);
priv = NM_ACCESS_POINT_GET_PRIVATE (ap);
if (!priv->flags) {
priv->flags = _nm_object_get_uint_property (NM_OBJECT (ap),
NM_DBUS_INTERFACE_ACCESS_POINT,
DBUS_PROP_FLAGS,
NULL);
}
return priv->flags;
_nm_object_ensure_inited (NM_OBJECT (ap));
return NM_ACCESS_POINT_GET_PRIVATE (ap)->flags;
}
/**
......@@ -139,19 +130,10 @@ nm_access_point_get_flags (NMAccessPoint *ap)
NM80211ApSecurityFlags
nm_access_point_get_wpa_flags (NMAccessPoint *ap)
{
NMAccessPointPrivate *priv;
g_return_val_if_fail (NM_IS_ACCESS_POINT (ap), NM_802_11_AP_SEC_NONE);
priv = NM_ACCESS_POINT_GET_PRIVATE (ap);
if (!priv->wpa_flags) {
priv->wpa_flags = _nm_object_get_uint_property (NM_OBJECT (ap),
NM_DBUS_INTERFACE_ACCESS_POINT,
DBUS_PROP_WPA_FLAGS,
NULL);
}
return priv->wpa_flags;
_nm_object_ensure_inited (NM_OBJECT (ap));
return NM_ACCESS_POINT_GET_PRIVATE (ap)->wpa_flags;
}
/**
......@@ -166,19 +148,10 @@ nm_access_point_get_wpa_flags (NMAccessPoint *ap)
NM80211ApSecurityFlags
nm_access_point_get_rsn_flags (NMAccessPoint *ap)
{
NMAccessPointPrivate *priv;
g_return_val_if_fail (NM_IS_ACCESS_POINT (ap), NM_802_11_AP_SEC_NONE);
priv = NM_ACCESS_POINT_GET_PRIVATE (ap);
if (!priv->rsn_flags) {
priv->rsn_flags = _nm_object_get_uint_property (NM_OBJECT (ap),
NM_DBUS_INTERFACE_ACCESS_POINT,
DBUS_PROP_RSN_FLAGS,
NULL);
}
return priv->rsn_flags;
_nm_object_ensure_inited (NM_OBJECT (ap));
return NM_ACCESS_POINT_GET_PRIVATE (ap)->rsn_flags;
}
/**
......@@ -193,19 +166,10 @@ nm_access_point_get_rsn_flags (NMAccessPoint *ap)
const GByteArray *
nm_access_point_get_ssid (NMAccessPoint *ap)
{
NMAccessPointPrivate *priv;
g_return_val_if_fail (NM_IS_ACCESS_POINT (ap), NULL);
priv = NM_ACCESS_POINT_GET_PRIVATE (ap);
if (!priv->ssid) {
priv->ssid = _nm_object_get_byte_array_property (NM_OBJECT (ap),
NM_DBUS_INTERFACE_ACCESS_POINT,
DBUS_PROP_SSID,
NULL);
}
return priv->ssid;
_nm_object_ensure_inited (NM_OBJECT (ap));
return NM_ACCESS_POINT_GET_PRIVATE (ap)->ssid;
}
/**
......@@ -219,19 +183,10 @@ nm_access_point_get_ssid (NMAccessPoint *ap)
guint32
nm_access_point_get_frequency (NMAccessPoint *ap)
{
NMAccessPointPrivate *priv;
g_return_val_if_fail (NM_IS_ACCESS_POINT (ap), 0);
priv = NM_ACCESS_POINT_GET_PRIVATE (ap);
if (!priv->frequency) {
priv->frequency = _nm_object_get_uint_property (NM_OBJECT (ap),
NM_DBUS_INTERFACE_ACCESS_POINT,
DBUS_PROP_FREQUENCY,
NULL);
}
return priv->frequency;
_nm_object_ensure_inited (NM_OBJECT (ap));
return NM_ACCESS_POINT_GET_PRIVATE (ap)->frequency;
}
/**
......@@ -246,19 +201,10 @@ nm_access_point_get_frequency (NMAccessPoint *ap)
const char *
nm_access_point_get_bssid (NMAccessPoint *ap)
{
NMAccessPointPrivate *priv;
g_return_val_if_fail (NM_IS_ACCESS_POINT (ap), NULL);
priv = NM_ACCESS_POINT_GET_PRIVATE (ap);
if (!priv->bssid) {
priv->bssid = _nm_object_get_string_property (NM_OBJECT (ap),
NM_DBUS_INTERFACE_ACCESS_POINT,
DBUS_PROP_HW_ADDRESS,
NULL);
}
return priv->bssid;
_nm_object_ensure_inited (NM_OBJECT (ap));
return NM_ACCESS_POINT_GET_PRIVATE (ap)->bssid;
}
/**
......@@ -289,19 +235,10 @@ nm_access_point_get_hw_address (NMAccessPoint *ap)
NM80211Mode
nm_access_point_get_mode (NMAccessPoint *ap)
{
NMAccessPointPrivate *priv;
g_return_val_if_fail (NM_IS_ACCESS_POINT (ap), 0);
priv = NM_ACCESS_POINT_GET_PRIVATE (ap);
if (!priv->mode) {
priv->mode = _nm_object_get_uint_property (NM_OBJECT (ap),
NM_DBUS_INTERFACE_ACCESS_POINT,
DBUS_PROP_MODE,
NULL);
}
return priv->mode;
_nm_object_ensure_inited (NM_OBJECT (ap));
return NM_ACCESS_POINT_GET_PRIVATE (ap)->mode;
}
/**
......@@ -315,19 +252,10 @@ nm_access_point_get_mode (NMAccessPoint *ap)
guint32
nm_access_point_get_max_bitrate (NMAccessPoint *ap)
{
NMAccessPointPrivate *priv;
g_return_val_if_fail (NM_IS_ACCESS_POINT (ap), 0);
priv = NM_ACCESS_POINT_GET_PRIVATE (ap);
if (!priv->max_bitrate) {
priv->max_bitrate = _nm_object_get_uint_property (NM_OBJECT (ap),
NM_DBUS_INTERFACE_ACCESS_POINT,
DBUS_PROP_MAX_BITRATE,
NULL);
}
return priv->max_bitrate;
_nm_object_ensure_inited (NM_OBJECT (ap));
return NM_ACCESS_POINT_GET_PRIVATE (ap)->max_bitrate;
}
/**
......@@ -341,19 +269,10 @@ nm_access_point_get_max_bitrate (NMAccessPoint *ap)
guint8
nm_access_point_get_strength (NMAccessPoint *ap)
{
NMAccessPointPrivate *priv;
g_return_val_if_fail (NM_IS_ACCESS_POINT (ap), 0);
priv = NM_ACCESS_POINT_GET_PRIVATE (ap);
if (!priv->strength) {
priv->strength = _nm_object_get_byte_property (NM_OBJECT (ap),
NM_DBUS_INTERFACE_ACCESS_POINT,
DBUS_PROP_STRENGTH,
NULL);
}
return priv->strength;
_nm_object_ensure_inited (NM_OBJECT (ap));
return NM_ACCESS_POINT_GET_PRIVATE (ap)->strength;
}
/**
......
......@@ -107,19 +107,10 @@ nm_active_connection_new (DBusGConnection *connection, const char *path)
const char *
nm_active_connection_get_connection (NMActiveConnection *connection)
{
NMActiveConnectionPrivate *priv;
g_return_val_if_fail (NM_IS_ACTIVE_CONNECTION (connection), NULL);
priv = NM_ACTIVE_CONNECTION_GET_PRIVATE (connection);
if (!priv->connection) {
priv->connection = _nm_object_get_string_property (NM_OBJECT (connection),
NM_DBUS_INTERFACE_ACTIVE_CONNECTION,
DBUS_PROP_CONNECTION,
NULL);
}
return priv->connection;
_nm_object_ensure_inited (NM_OBJECT (connection));
return NM_ACTIVE_CONNECTION_GET_PRIVATE (connection)->connection;
}
/**
......@@ -134,19 +125,10 @@ nm_active_connection_get_connection (NMActiveConnection *connection)
const char *
nm_active_connection_get_uuid (NMActiveConnection *connection)
{
NMActiveConnectionPrivate *priv;
g_return_val_if_fail (NM_IS_ACTIVE_CONNECTION (connection), NULL);
priv = NM_ACTIVE_CONNECTION_GET_PRIVATE (connection);
if (!priv->uuid) {
priv->uuid = _nm_object_get_string_property (NM_OBJECT (connection),
NM_DBUS_INTERFACE_ACTIVE_CONNECTION,
DBUS_PROP_UUID,
NULL);
}
return priv->uuid;
_nm_object_ensure_inited (NM_OBJECT (connection));
return NM_ACTIVE_CONNECTION_GET_PRIVATE (connection)->uuid;
}
/**
......@@ -161,19 +143,10 @@ nm_active_connection_get_uuid (NMActiveConnection *connection)
const char *
nm_active_connection_get_specific_object (NMActiveConnection *connection)
{
NMActiveConnectionPrivate *priv;
g_return_val_if_fail (NM_IS_ACTIVE_CONNECTION (connection), NULL);
priv = NM_ACTIVE_CONNECTION_GET_PRIVATE (connection);
if (!priv->specific_object) {
priv->specific_object = _nm_object_get_string_property (NM_OBJECT (connection),
NM_DBUS_INTERFACE_ACTIVE_CONNECTION,
DBUS_PROP_SPECIFIC_OBJECT,
NULL);
}
return priv->specific_object;
_nm_object_ensure_inited (NM_OBJECT (connection));
return NM_ACTIVE_CONNECTION_GET_PRIVATE (connection)->specific_object;
}
/**
......@@ -188,27 +161,10 @@ nm_active_connection_get_specific_object (NMActiveConnection *connection)
const GPtrArray *
nm_active_connection_get_devices (NMActiveConnection *connection)
{
NMActiveConnectionPrivate *priv;
GValue value = { 0, };
g_return_val_if_fail (NM_IS_ACTIVE_CONNECTION (connection), NULL);
priv = NM_ACTIVE_CONNECTION_GET_PRIVATE (connection);
if (priv->devices)
return handle_ptr_array_return (priv->devices);
if (!_nm_object_get_property (NM_OBJECT (connection),
NM_DBUS_INTERFACE_ACTIVE_CONNECTION,
DBUS_PROP_DEVICES,
&value,
NULL)) {
return NULL;
}
demarshal_devices (NM_OBJECT (connection), NULL, &value, &priv->devices);
g_value_unset (&value);
return handle_ptr_array_return (priv->devices);
_nm_object_ensure_inited (NM_OBJECT (connection));
return handle_ptr_array_return (NM_ACTIVE_CONNECTION_GET_PRIVATE (connection)->devices);
}
/**
......@@ -222,19 +178,10 @@ nm_active_connection_get_devices (NMActiveConnection *connection)
NMActiveConnectionState
nm_active_connection_get_state (NMActiveConnection *connection)
{
NMActiveConnectionPrivate *priv;
g_return_val_if_fail (NM_IS_ACTIVE_CONNECTION (connection), NM_ACTIVE_CONNECTION_STATE_UNKNOWN);
priv = NM_ACTIVE_CONNECTION_GET_PRIVATE (connection);
if (!priv->state) {
priv->state = _nm_object_get_uint_property (NM_OBJECT (connection),
NM_DBUS_INTERFACE_ACTIVE_CONNECTION,
DBUS_PROP_STATE,
NULL);
}
return priv->state;
_nm_object_ensure_inited (NM_OBJECT (connection));
return NM_ACTIVE_CONNECTION_GET_PRIVATE (connection)->state;
}
/**
......@@ -249,19 +196,10 @@ nm_active_connection_get_state (NMActiveConnection *connection)
gboolean
nm_active_connection_get_default (NMActiveConnection *connection)
{
NMActiveConnectionPrivate *priv;
g_return_val_if_fail (NM_IS_ACTIVE_CONNECTION (connection), FALSE);
priv = NM_ACTIVE_CONNECTION_GET_PRIVATE (connection);
if (!priv->is_default) {
priv->is_default = _nm_object_get_boolean_property (NM_OBJECT (connection),
NM_DBUS_INTERFACE_ACTIVE_CONNECTION,
DBUS_PROP_DEFAULT,
NULL);
}
return priv->is_default;
_nm_object_ensure_inited (NM_OBJECT (connection));
return NM_ACTIVE_CONNECTION_GET_PRIVATE (connection)->is_default;
}
/**
......@@ -276,19 +214,10 @@ nm_active_connection_get_default (NMActiveConnection *connection)
gboolean
nm_active_connection_get_default6 (NMActiveConnection *connection)
{
NMActiveConnectionPrivate *priv;
g_return_val_if_fail (NM_IS_ACTIVE_CONNECTION (connection), FALSE);
priv = NM_ACTIVE_CONNECTION_GET_PRIVATE (connection);
if (!priv->is_default6) {
priv->is_default6 = _nm_object_get_boolean_property (NM_OBJECT (connection),
NM_DBUS_INTERFACE_ACTIVE_CONNECTION,
DBUS_PROP_DEFAULT6,
NULL);
}
return priv->is_default6;
_nm_object_ensure_inited (NM_OBJECT (connection));
return NM_ACTIVE_CONNECTION_GET_PRIVATE (connection)->is_default6;
}
/**
......@@ -303,19 +232,10 @@ nm_active_connection_get_default6 (NMActiveConnection *connection)
const char *
nm_active_connection_get_master (NMActiveConnection *connection)
{
NMActiveConnectionPrivate *priv;
g_return_val_if_fail (NM_IS_ACTIVE_CONNECTION (connection), NULL);
priv = NM_ACTIVE_CONNECTION_GET_PRIVATE (connection);
if (!priv->master) {
priv->master = _nm_object_get_string_property (NM_OBJECT (connection),
NM_DBUS_INTERFACE_ACTIVE_CONNECTION,
DBUS_PROP_MASTER,
NULL);
}
return priv->master;
_nm_object_ensure_inited (NM_OBJECT (connection));
return NM_ACTIVE_CONNECTION_GET_PRIVATE (connection)->master;
}
static void
......
......@@ -62,7 +62,6 @@ typedef struct {
*/
GSList *pending_activations;
gboolean have_networking_enabled;
gboolean networking_enabled;
gboolean wireless_enabled;
gboolean wireless_hw_enabled;
......@@ -110,18 +109,6 @@ static void proxy_name_owner_changed (DBusGProxy *proxy,
static void client_device_added_proxy (DBusGProxy *proxy, char *path, gpointer user_data);
static void client_device_removed_proxy (DBusGProxy *proxy, char *path, gpointer user_data);
static void
handle_net_enabled_changed (GObject *object,
GParamSpec *pspec,
GValue *value,
gpointer user_data)
{
NMClientPrivate *priv = NM_CLIENT_GET_PRIVATE (object);
/* Update the cache flag when it changes */
priv->have_networking_enabled = TRUE;
}
static void
nm_client_init (NMClient *client)
{
......@@ -130,11 +117,6 @@ nm_client_init (NMClient *client)
priv->state = NM_STATE_UNKNOWN;
priv->permissions = g_hash_table_new (g_direct_hash, g_direct_equal);
g_signal_connect (client,
"notify::" NM_CLIENT_NETWORKING_ENABLED,
G_CALLBACK (handle_net_enabled_changed),
client);
}
static void
......@@ -155,29 +137,29 @@ static void
update_wireless_status (NMClient *client, gboolean notify)
{
NMClientPrivate *priv = NM_CLIENT_GET_PRIVATE (client);
gboolean val;
gboolean oldval;
gboolean poke = FALSE;
val = _nm_object_get_boolean_property (NM_OBJECT (client),
NM_DBUS_INTERFACE,
"WirelessHardwareEnabled",
NULL);
if (val != priv->wireless_hw_enabled) {
priv->wireless_hw_enabled = val;
oldval = priv->wireless_hw_enabled;
_nm_object_reload_property (NM_OBJECT (client),
NM_DBUS_INTERFACE,
"WirelessHardwareEnabled");
if (oldval != priv->wireless_hw_enabled) {
poke = TRUE;
if (notify)
_nm_object_queue_notify (NM_OBJECT (client), NM_CLIENT_WIRELESS_HARDWARE_ENABLED);
}
if (priv->wireless_hw_enabled == FALSE)
val = FALSE;
else
val = _nm_object_get_boolean_property (NM_OBJECT (client),
NM_DBUS_INTERFACE,
"WirelessEnabled",
NULL);
if (val != priv->wireless_enabled) {
priv->wireless_enabled = val;
oldval = priv->wireless_enabled;
if (priv->wireless_hw_enabled == FALSE) {
priv->wireless_enabled = FALSE;
} else {
_nm_object_reload_property (NM_OBJECT (client),
NM_DBUS_INTERFACE,
"WirelessEnabled");
}
if (oldval != priv->wireless_enabled) {
poke = TRUE;
if (notify)
_nm_object_queue_notify (NM_OBJECT (client), NM_CLIENT_WIRELESS_ENABLED);
......@@ -197,29 +179,27 @@ static void
update_wwan_status (NMClient *client, gboolean notify)
{
NMClientPrivate *priv = NM_CLIENT_GET_PRIVATE (client);
gboolean val;
val = _nm_object_get_boolean_property (NM_OBJECT (client),
NM_DBUS_INTERFACE,
"WwanHardwareEnabled",
NULL);
if (val != priv->wwan_hw_enabled) {
priv->wwan_hw_enabled = val;
gboolean oldval;
oldval = priv->wwan_hw_enabled;
_nm_object_reload_property (NM_OBJECT (client),
NM_DBUS_INTERFACE,
"WwanHardwareEnabled");
if (oldval != priv->wwan_hw_enabled) {
if (notify)
_nm_object_queue_notify (NM_OBJECT (client), NM_CLIENT_WWAN_HARDWARE_ENABLED);
}
if (priv->wwan_hw_enabled == FALSE)
val = FALSE;
else {
val = _nm_object_get_boolean_property (NM_OBJECT (client),
NM_DBUS_INTERFACE,
"WwanEnabled",
NULL);
oldval = priv->wwan_enabled;
if (priv->wwan_hw_enabled == FALSE) {
priv->wwan_enabled = FALSE;
} else {
_nm_object_reload_property (NM_OBJECT (client),
NM_DBUS_INTERFACE,
"WwanEnabled");
}
if (val != priv->wwan_enabled) {
priv->wwan_enabled = val;
if (oldval != priv->wwan_enabled) {
if (notify)
_nm_object_queue_notify (NM_OBJECT (client), NM_CLIENT_WWAN_ENABLED);
}
......@@ -229,29 +209,27 @@ static void
update_wimax_status (NMClient *client, gboolean notify)
{
NMClientPrivate *priv = NM_CLIENT_GET_PRIVATE (client);
gboolean val;
val = _nm_object_get_boolean_property (NM_OBJECT (client),
NM_DBUS_INTERFACE,
"WimaxHardwareEnabled",
NULL);
if (val != priv->wimax_hw_enabled) {
priv->wimax_hw_enabled = val;
gboolean oldval;
oldval = priv->wimax_hw_enabled;
_nm_object_reload_property (NM_OBJECT (client),
NM_DBUS_INTERFACE,
"WimaxHardwareEnabled");
if (oldval != priv->wimax_hw_enabled) {
if (notify)
_nm_object_queue_notify (NM_OBJECT (client), NM_CLIENT_WIMAX_HARDWARE_ENABLED);
}
oldval = priv->wimax_enabled;
if (priv->wimax_hw_enabled == FALSE)
val = FALSE;
priv->wimax_enabled = FALSE;
else {
val = _nm_object_get_boolean_property (NM_OBJECT (client),
NM_DBUS_INTERFACE,
"WimaxEnabled",
NULL);
_nm_object_reload_property (NM_OBJECT (client),
NM_DBUS_INTERFACE,
"WimaxEnabled");
}
if (val != priv->wimax_enabled) {
priv->wimax_enabled = val;
if (oldval != priv->wimax_enabled) {
if (notify)
_nm_object_queue_notify (NM_OBJECT (client), NM_CLIENT_WIMAX_ENABLED);
}
......@@ -877,28 +855,14 @@ const GPtrArray *
nm_client_get_active_connections (NMClient *client)
{
NMClientPrivate *priv;
GValue value = { 0, };
g_return_val_if_fail (NM_IS_CLIENT (client), NULL);
priv = NM_CLIENT_GET_PRIVATE (client);
if (priv->active_connections)
return handle_ptr_array_return (priv->active_connections);
if (!priv->manager_running)
return NULL;
if (!_nm_object_get_property (NM_OBJECT (client),
"org.freedesktop.NetworkManager",
"ActiveConnections",
&value,
NULL)) {
return NULL;
}
demarshal_active_connections (NM_OBJECT (client), NULL, &value, &priv->active_connections);
g_value_unset (&value);
_nm_object_ensure_inited (NM_OBJECT (client));
return handle_ptr_array_return (priv->active_connections);
}
......@@ -915,6 +879,7 @@ nm_client_wireless_get_enabled (NMClient *client)
{
g_return_val_if_fail (NM_IS_CLIENT (client), FALSE);
_nm_object_ensure_inited (NM_OBJECT (client));
return NM_CLIENT_GET_PRIVATE (client)->wireless_enabled;
}
......@@ -954,6 +919,7 @@ nm_client_wireless_hardware_get_enabled (NMClient *client)
{
g_return_val_if_fail (NM_IS_CLIENT (client), FALSE);
_nm_object_ensure_inited (NM_OBJECT (client));
return NM_CLIENT_GET_PRIVATE (client)->wireless_hw_enabled;
}
......@@ -970,6 +936,7 @@ nm_client_wwan_get_enabled (NMClient *client)
{
g_return_val_if_fail (NM_IS_CLIENT (client), FALSE);
_nm_object_ensure_inited (NM_OBJECT (client));
return NM_CLIENT_GET_PRIVATE (client)->wwan_enabled;
}
......@@ -1009,6 +976,7 @@ nm_client_wwan_hardware_get_enabled (NMClient *client)
{
g_return_val_if_fail (NM_IS_CLIENT (client), FALSE);
_nm_object_ensure_inited (NM_OBJECT (client));
return NM_CLIENT_GET_PRIVATE (client)->wwan_hw_enabled;
}
......@@ -1025,6 +993,7 @@ nm_client_wimax_get_enabled (NMClient *client)
{
g_return_val_if_fail (NM_IS_CLIENT (client), FALSE);
_nm_object_ensure_inited (NM_OBJECT (client));
return NM_CLIENT_GET_PRIVATE (client)->wimax_enabled;
}
......@@ -1064,6 +1033,7 @@ nm_client_wimax_hardware_get_enabled (NMClient *client)
{
g_return_val_if_fail (NM_IS_CLIENT (client), FALSE);
_nm_object_ensure_inited (NM_OBJECT (client));
return NM_CLIENT_GET_PRIVATE (client)->wimax_hw_enabled;
}
......@@ -1079,7 +1049,6 @@ const char *
nm_client_get_version (NMClient *client)
{