core: add an NMExportedObject base class

Add NMExportedObject, make it the base class of all D-Bus-exported
types, and move the nm-properties-changed-signal logic into it. (Also,
make NMSettings use the same properties-changed code as everything
else, which it was not previously doing, presumably for historical
reasons).

(This is mostly just shuffling code around at this point, but
NMExportedObject will be more important in the gdbus port, since
gdbus-codegen doesn't do a very good job of supporting objects that
export multiple interfaces [as each NMDevice subclass does, for
example], so we will need more glue/helper code in NMExportedObject
then.)
This commit is contained in:
Dan Winship
2015-04-13 13:31:42 -04:00
parent f3d10b3ec8
commit 6fcc1deee0
56 changed files with 399 additions and 515 deletions

View File

@@ -324,6 +324,8 @@ nm_sources = \
nm-dispatcher.h \
nm-enum-types.c \
nm-enum-types.h \
nm-exported-object.c \
nm-exported-object.h \
nm-firewall-manager.c \
nm-firewall-manager.h \
nm-ip4-config.c \
@@ -344,8 +346,6 @@ nm_sources = \
nm-multi-index.h \
nm-policy.c \
nm-policy.h \
nm-properties-changed-signal.c \
nm-properties-changed-signal.h \
nm-rfkill-manager.c \
nm-rfkill-manager.h \
nm-session-monitor.h \
@@ -505,6 +505,8 @@ libnm_iface_helper_la_SOURCES = \
nm-route-manager.c \
nm-route-manager.h \
\
nm-exported-object.c \
nm-exported-object.h \
nm-ip4-config.c \
nm-ip4-config.h \
nm-ip6-config.c \

View File

@@ -39,7 +39,6 @@
#include "NetworkManagerUtils.h"
#include "nm-logging.h"
#include "nm-enum-types.h"
#include "nm-dbus-manager.h"
#include "nm-platform.h"
#include "ppp-manager/nm-ppp-manager.h"
@@ -615,7 +614,6 @@ nm_device_adsl_class_init (NMDeviceAdslClass *klass)
parent_class->act_stage3_ip4_config_start = act_stage3_ip4_config_start;
parent_class->deactivate = deactivate;
nm_dbus_manager_register_exported_type (nm_dbus_manager_get (),
G_TYPE_FROM_CLASS (klass),
nm_exported_object_class_add_interface (NM_EXPORTED_OBJECT_CLASS (klass),
&dbus_glib_nm_device_adsl_object_info);
}

View File

@@ -1196,7 +1196,6 @@ nm_device_bt_class_init (NMDeviceBtClass *klass)
G_TYPE_NONE, 2,
G_TYPE_UINT, G_TYPE_UINT);
nm_dbus_manager_register_exported_type (nm_dbus_manager_get (),
G_TYPE_FROM_CLASS (klass),
nm_exported_object_class_add_interface (NM_EXPORTED_OBJECT_CLASS (klass),
&dbus_glib_nm_device_bt_object_info);
}

View File

@@ -33,7 +33,6 @@
#include "nm-device-private.h"
#include "nm-platform.h"
#include "nm-dbus-glib-types.h"
#include "nm-dbus-manager.h"
#include "nm-enum-types.h"
#include "nm-device-factory.h"
#include "nm-core-internal.h"
@@ -542,8 +541,7 @@ nm_device_bond_class_init (NMDeviceBondClass *klass)
G_PARAM_READABLE |
G_PARAM_STATIC_STRINGS));
nm_dbus_manager_register_exported_type (nm_dbus_manager_get (),
G_TYPE_FROM_CLASS (klass),
nm_exported_object_class_add_interface (NM_EXPORTED_OBJECT_CLASS (klass),
&dbus_glib_nm_device_bond_object_info);
}

View File

@@ -31,7 +31,6 @@
#include "NetworkManagerUtils.h"
#include "nm-device-private.h"
#include "nm-dbus-glib-types.h"
#include "nm-dbus-manager.h"
#include "nm-enum-types.h"
#include "nm-platform.h"
#include "nm-device-factory.h"
@@ -466,8 +465,7 @@ nm_device_bridge_class_init (NMDeviceBridgeClass *klass)
G_PARAM_READABLE |
G_PARAM_STATIC_STRINGS));
nm_dbus_manager_register_exported_type (nm_dbus_manager_get (),
G_TYPE_FROM_CLASS (klass),
nm_exported_object_class_add_interface (NM_EXPORTED_OBJECT_CLASS (klass),
&dbus_glib_nm_device_bridge_object_info);
}

View File

@@ -41,7 +41,6 @@
#include "ppp-manager/nm-ppp-manager.h"
#include "nm-logging.h"
#include "nm-enum-types.h"
#include "nm-dbus-manager.h"
#include "nm-platform.h"
#include "nm-platform-utils.h"
#include "nm-dcb.h"
@@ -1706,8 +1705,7 @@ nm_device_ethernet_class_init (NMDeviceEthernetClass *klass)
G_PARAM_READABLE |
G_PARAM_STATIC_STRINGS));
nm_dbus_manager_register_exported_type (nm_dbus_manager_get (),
G_TYPE_FROM_CLASS (klass),
nm_exported_object_class_add_interface (NM_EXPORTED_OBJECT_CLASS (klass),
&dbus_glib_nm_device_ethernet_object_info);
}

View File

@@ -24,7 +24,6 @@
#include "nm-device-private.h"
#include "nm-enum-types.h"
#include "nm-platform.h"
#include "nm-dbus-manager.h"
#include "nm-core-internal.h"
#include "nm-device-generic-glue.h"
@@ -203,7 +202,6 @@ nm_device_generic_class_init (NMDeviceGenericClass *klass)
G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY |
G_PARAM_STATIC_STRINGS));
nm_dbus_manager_register_exported_type (nm_dbus_manager_get (),
G_TYPE_FROM_CLASS (klass),
nm_exported_object_class_add_interface (NM_EXPORTED_OBJECT_CLASS (klass),
&dbus_glib_nm_device_generic_object_info);
}

View File

@@ -25,7 +25,6 @@
#include "nm-device-gre.h"
#include "nm-device-private.h"
#include "nm-dbus-manager.h"
#include "nm-logging.h"
#include "nm-manager.h"
#include "nm-platform.h"
@@ -256,8 +255,7 @@ nm_device_gre_class_init (NMDeviceGreClass *klass)
G_PARAM_READABLE |
G_PARAM_STATIC_STRINGS));
nm_dbus_manager_register_exported_type (nm_dbus_manager_get (),
G_TYPE_FROM_CLASS (klass),
nm_exported_object_class_add_interface (NM_EXPORTED_OBJECT_CLASS (klass),
&dbus_glib_nm_device_gre_object_info);
}

View File

@@ -30,7 +30,6 @@
#include "NetworkManagerUtils.h"
#include "nm-device-private.h"
#include "nm-enum-types.h"
#include "nm-dbus-manager.h"
#include "nm-activation-request.h"
#include "nm-ip4-config.h"
#include "nm-platform.h"
@@ -295,8 +294,7 @@ nm_device_infiniband_class_init (NMDeviceInfinibandClass *klass)
G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY |
G_PARAM_STATIC_STRINGS));
nm_dbus_manager_register_exported_type (nm_dbus_manager_get (),
G_TYPE_FROM_CLASS (klass),
nm_exported_object_class_add_interface (NM_EXPORTED_OBJECT_CLASS (klass),
&dbus_glib_nm_device_infiniband_object_info);
}

View File

@@ -24,7 +24,6 @@
#include "nm-device-macvlan.h"
#include "nm-device-private.h"
#include "nm-dbus-manager.h"
#include "nm-logging.h"
#include "nm-manager.h"
#include "nm-platform.h"
@@ -164,8 +163,7 @@ nm_device_macvlan_class_init (NMDeviceMacvlanClass *klass)
G_PARAM_READABLE |
G_PARAM_STATIC_STRINGS));
nm_dbus_manager_register_exported_type (nm_dbus_manager_get (),
G_TYPE_FROM_CLASS (klass),
nm_exported_object_class_add_interface (NM_EXPORTED_OBJECT_CLASS (klass),
&dbus_glib_nm_device_macvlan_object_info);
}

View File

@@ -25,7 +25,6 @@
#include "nm-device-tun.h"
#include "nm-device-private.h"
#include "nm-dbus-manager.h"
#include "nm-logging.h"
#include "nm-platform.h"
#include "nm-device-factory.h"
@@ -258,8 +257,7 @@ nm_device_tun_class_init (NMDeviceTunClass *klass)
FALSE,
G_PARAM_READABLE | G_PARAM_STATIC_STRINGS));
nm_dbus_manager_register_exported_type (nm_dbus_manager_get (),
G_TYPE_FROM_CLASS (klass),
nm_exported_object_class_add_interface (NM_EXPORTED_OBJECT_CLASS (klass),
&dbus_glib_nm_device_tun_object_info);
}

View File

@@ -32,7 +32,6 @@
#include "nm-logging.h"
#include "nm-manager.h"
#include "nm-platform.h"
#include "nm-dbus-manager.h"
#include "nm-device-factory.h"
#include "nm-device-veth-glue.h"
@@ -166,8 +165,7 @@ nm_device_veth_class_init (NMDeviceVethClass *klass)
G_PARAM_READABLE |
G_PARAM_STATIC_STRINGS));
nm_dbus_manager_register_exported_type (nm_dbus_manager_get (),
G_TYPE_FROM_CLASS (klass),
nm_exported_object_class_add_interface (NM_EXPORTED_OBJECT_CLASS (klass),
&dbus_glib_nm_device_veth_object_info);
}

View File

@@ -32,7 +32,6 @@
#include "NetworkManagerUtils.h"
#include "nm-device-private.h"
#include "nm-enum-types.h"
#include "nm-dbus-manager.h"
#include "nm-connection-provider.h"
#include "nm-activation-request.h"
#include "nm-ip4-config.h"
@@ -606,8 +605,7 @@ nm_device_vlan_class_init (NMDeviceVlanClass *klass)
G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY |
G_PARAM_STATIC_STRINGS));
nm_dbus_manager_register_exported_type (nm_dbus_manager_get (),
G_TYPE_FROM_CLASS (klass),
nm_exported_object_class_add_interface (NM_EXPORTED_OBJECT_CLASS (klass),
&dbus_glib_nm_device_vlan_object_info);
}

View File

@@ -24,7 +24,6 @@
#include "nm-device-vxlan.h"
#include "nm-device-private.h"
#include "nm-dbus-manager.h"
#include "nm-logging.h"
#include "nm-manager.h"
#include "nm-platform.h"
@@ -342,8 +341,7 @@ nm_device_vxlan_class_init (NMDeviceVxlanClass *klass)
G_PARAM_READABLE |
G_PARAM_STATIC_STRINGS));
nm_dbus_manager_register_exported_type (nm_dbus_manager_get (),
G_TYPE_FROM_CLASS (klass),
nm_exported_object_class_add_interface (NM_EXPORTED_OBJECT_CLASS (klass),
&dbus_glib_nm_device_vxlan_object_info);
}

View File

@@ -55,7 +55,6 @@
#include "nm-dhcp6-config.h"
#include "nm-rfkill-manager.h"
#include "nm-firewall-manager.h"
#include "nm-properties-changed-signal.h"
#include "nm-enum-types.h"
#include "nm-settings-connection.h"
#include "nm-connection-provider.h"
@@ -79,7 +78,7 @@ static void ip_check_ping_watch_cb (GPid pid, gint status, gpointer user_data);
#include "nm-device-glue.h"
G_DEFINE_ABSTRACT_TYPE (NMDevice, nm_device, G_TYPE_OBJECT)
G_DEFINE_ABSTRACT_TYPE (NMDevice, nm_device, NM_TYPE_EXPORTED_OBJECT)
#define NM_DEVICE_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), NM_TYPE_DEVICE, NMDevicePrivate))
@@ -526,6 +525,7 @@ nm_device_dbus_export (NMDevice *self)
priv->path = g_strdup_printf ("/org/freedesktop/NetworkManager/Devices/%d", devcount++);
_LOGD (LOGD_DEVICE, "exported as %s", priv->path);
nm_dbus_manager_register_object (nm_dbus_manager_get (), priv->path, self);
}
@@ -9766,10 +9766,8 @@ nm_device_class_init (NMDeviceClass *klass)
0, NULL, NULL, NULL,
G_TYPE_NONE, 0);
nm_dbus_manager_register_exported_type (nm_dbus_manager_get (),
G_TYPE_FROM_CLASS (klass),
nm_exported_object_class_add_interface (NM_EXPORTED_OBJECT_CLASS (klass),
&dbus_glib_nm_device_object_info);
dbus_g_error_domain_register (NM_DEVICE_ERROR, NULL, NM_TYPE_DEVICE_ERROR);
}

View File

@@ -25,7 +25,7 @@
#include <dbus/dbus-glib.h>
#include <netinet/in.h>
#include "nm-glib.h"
#include "nm-exported-object.h"
#include "nm-dbus-interface.h"
#include "nm-types.h"
#include "nm-connection.h"
@@ -104,7 +104,7 @@ typedef enum { /*< skip >*/
} NMDeviceCheckConAvailableFlags;
struct _NMDevice {
GObject parent;
NMExportedObject parent;
};
/* The flags have an relaxing meaning, that means, specifying more flags, can make
@@ -118,7 +118,7 @@ typedef enum { /*< skip >*/
} NMDeviceCheckDevAvailableFlags;
typedef struct {
GObjectClass parent;
NMExportedObjectClass parent;
const char *connection_type;

View File

@@ -35,7 +35,6 @@
#include "nm-device-private.h"
#include "nm-platform.h"
#include "nm-dbus-glib-types.h"
#include "nm-dbus-manager.h"
#include "nm-enum-types.h"
#include "nm-team-enum-types.h"
#include "nm-core-internal.h"
@@ -824,7 +823,7 @@ nm_device_team_class_init (NMDeviceTeamClass *klass)
G_PARAM_READABLE |
G_PARAM_STATIC_STRINGS));
nm_dbus_manager_register_exported_type (nm_dbus_manager_get (),
G_TYPE_FROM_CLASS (klass),
nm_exported_object_class_add_interface (NM_EXPORTED_OBJECT_CLASS (klass),
&dbus_glib_nm_device_team_object_info);
}

View File

@@ -50,7 +50,6 @@
#include "nm-setting-olpc-mesh.h"
#include "nm-manager.h"
#include "nm-enum-types.h"
#include "nm-dbus-manager.h"
#include "nm-platform.h"
#include "nm-wifi-enum-types.h"
@@ -551,8 +550,7 @@ nm_device_olpc_mesh_class_init (NMDeviceOlpcMeshClass *klass)
G_PARAM_READABLE |
G_PARAM_STATIC_STRINGS));
nm_dbus_manager_register_exported_type (nm_dbus_manager_get (),
G_TYPE_FROM_CLASS (klass),
nm_exported_object_class_add_interface (NM_EXPORTED_OBJECT_CLASS (klass),
&dbus_glib_nm_device_olpc_mesh_object_info);
}

View File

@@ -29,7 +29,6 @@
#include <errno.h>
#include "nm-glib.h"
#include "nm-dbus-manager.h"
#include "nm-device.h"
#include "nm-device-wifi.h"
#include "nm-device-private.h"
@@ -3062,8 +3061,7 @@ nm_device_wifi_class_init (NMDeviceWifiClass *klass)
scanning_allowed_accumulator, NULL, NULL,
G_TYPE_BOOLEAN, 0);
nm_dbus_manager_register_exported_type (nm_dbus_manager_get (),
G_TYPE_FROM_CLASS (klass),
nm_exported_object_class_add_interface (NM_EXPORTED_OBJECT_CLASS (klass),
&dbus_glib_nm_device_wifi_object_info);
}

View File

@@ -67,7 +67,7 @@ typedef struct
#define NM_AP_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), NM_TYPE_AP, NMAccessPointPrivate))
G_DEFINE_TYPE (NMAccessPoint, nm_ap, G_TYPE_OBJECT)
G_DEFINE_TYPE (NMAccessPoint, nm_ap, NM_TYPE_EXPORTED_OBJECT)
enum {
PROP_0,
@@ -1074,8 +1074,7 @@ nm_ap_class_init (NMAccessPointClass *ap_class)
-1, G_MAXINT, -1,
G_PARAM_READABLE | G_PARAM_STATIC_STRINGS));
nm_dbus_manager_register_exported_type (nm_dbus_manager_get (),
G_TYPE_FROM_CLASS (ap_class),
nm_exported_object_class_add_interface (NM_EXPORTED_OBJECT_CLASS (ap_class),
&dbus_glib_nm_access_point_object_info);
}

View File

@@ -22,7 +22,7 @@
#ifndef __NETWORKMANAGER_ACCESS_POINT_H__
#define __NETWORKMANAGER_ACCESS_POINT_H__
#include "nm-glib.h"
#include "nm-exported-object.h"
#include "nm-dbus-interface.h"
#include "nm-connection.h"
@@ -45,11 +45,11 @@
#define NM_AP_LAST_SEEN "last-seen"
typedef struct {
GObject parent;
NMExportedObject parent;
} NMAccessPoint;
typedef struct {
GObjectClass parent;
NMExportedObjectClass parent;
} NMAccessPointClass;

View File

@@ -28,7 +28,6 @@
#include "nm-device-private.h"
#include "nm-rfkill-manager.h"
#include "nm-logging.h"
#include "nm-dbus-manager.h"
#include "nm-settings-connection.h"
#include "nm-modem-broadband.h"
#include "NetworkManagerUtils.h"
@@ -795,7 +794,6 @@ nm_device_modem_class_init (NMDeviceModemClass *mclass)
G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY |
G_PARAM_STATIC_STRINGS));
nm_dbus_manager_register_exported_type (nm_dbus_manager_get (),
G_TYPE_FROM_CLASS (mclass),
nm_exported_object_class_add_interface (NM_EXPORTED_OBJECT_CLASS (mclass),
&dbus_glib_nm_device_modem_object_info);
}

View File

@@ -26,7 +26,6 @@
#include "nm-platform.h"
#include "nm-dbus-manager.h"
#include "nm-setting-connection.h"
#include "nm-properties-changed-signal.h"
#include "nm-logging.h"
#include "NetworkManagerUtils.h"
#include "nm-device-private.h"

View File

@@ -9,6 +9,7 @@ AM_CPPFLAGS = \
-DNETWORKMANAGER_COMPILATION \
-DNM_VERSION_MAX_ALLOWED=NM_VERSION_NEXT_STABLE \
$(GLIB_CFLAGS) \
$(DBUS_CFLAGS) \
-DTESTDIR="\"$(abs_srcdir)\""
noinst_PROGRAMS = \

View File

@@ -37,7 +37,7 @@
#include "nm-active-connection-glue.h"
/* Base class for anything implementing the Connection.Active D-Bus interface */
G_DEFINE_ABSTRACT_TYPE (NMActiveConnection, nm_active_connection, G_TYPE_OBJECT)
G_DEFINE_ABSTRACT_TYPE (NMActiveConnection, nm_active_connection, NM_TYPE_EXPORTED_OBJECT)
#define NM_ACTIVE_CONNECTION_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), \
NM_TYPE_ACTIVE_CONNECTION, \
@@ -1066,8 +1066,7 @@ nm_active_connection_class_init (NMActiveConnectionClass *ac_class)
NULL, NULL, NULL,
G_TYPE_NONE, 1, G_TYPE_UINT);
nm_dbus_manager_register_exported_type (nm_dbus_manager_get (),
G_TYPE_FROM_CLASS (ac_class),
nm_exported_object_class_add_interface (NM_EXPORTED_OBJECT_CLASS (ac_class),
&dbus_glib_nm_active_connection_object_info);
}

View File

@@ -21,8 +21,7 @@
#ifndef __NETWORKMANAGER_ACTIVE_CONNECTION_H__
#define __NETWORKMANAGER_ACTIVE_CONNECTION_H__
#include "nm-glib.h"
#include "nm-types.h"
#include "nm-exported-object.h"
#include "nm-connection.h"
#define NM_TYPE_ACTIVE_CONNECTION (nm_active_connection_get_type ())
@@ -61,11 +60,11 @@
#define NM_ACTIVE_CONNECTION_DEVICE_METERED_CHANGED "device-metered-changed"
struct _NMActiveConnection {
GObject parent;
NMExportedObject parent;
};
typedef struct {
GObjectClass parent;
NMExportedObjectClass parent;
/* re-emits device state changes as a convenience for subclasses for
* device states >= DISCONNECTED.

View File

@@ -29,7 +29,6 @@
#include "nm-glib.h"
#include "nm-dbus-interface.h"
#include "nm-dbus-manager.h"
#include "nm-properties-changed-signal.h"
#include <dbus/dbus.h>
#include <dbus/dbus-glib.h>
@@ -854,33 +853,6 @@ object_destroyed (NMDBusManager *self, gpointer object)
g_hash_table_remove (NM_DBUS_MANAGER_GET_PRIVATE (self)->exported, object);
}
void
nm_dbus_manager_register_exported_type (NMDBusManager *self,
GType object_type,
const DBusGObjectInfo *info)
{
const char *properties_info, *dbus_name, *gobject_name, *tmp_access;
dbus_g_object_type_install_info (object_type, info);
if (!info->exported_properties)
return;
properties_info = info->exported_properties;
while (*properties_info) {
/* The format is: "interface\0DBusPropertyName\0gobject_property_name\0access\0" */
dbus_name = strchr (properties_info, '\0') + 1;
gobject_name = strchr (dbus_name, '\0') + 1;
tmp_access = strchr (gobject_name, '\0') + 1;
properties_info = strchr (tmp_access, '\0') + 1;
/* Note that nm-properties-changed-signal takes advantage of the
* fact that @dbus_name and @gobject_name are static data that won't
* ever be freed.
*/
nm_properties_changed_signal_add_property (object_type, dbus_name, gobject_name);
}
}
void
nm_dbus_manager_register_object (NMDBusManager *self,
const char *path,

View File

@@ -104,10 +104,6 @@ gboolean nm_dbus_manager_get_caller_info_from_message (NMDBusManager *self,
gulong *out_uid,
gulong *out_pid);
void nm_dbus_manager_register_exported_type (NMDBusManager *self,
GType object_type,
const DBusGObjectInfo *info);
void nm_dbus_manager_register_object (NMDBusManager *self,
const char *path,
gpointer object);

View File

@@ -30,7 +30,7 @@
#include "nm-dbus-glib-types.h"
#include "nm-utils.h"
G_DEFINE_TYPE (NMDhcp4Config, nm_dhcp4_config, G_TYPE_OBJECT)
G_DEFINE_TYPE (NMDhcp4Config, nm_dhcp4_config, NM_TYPE_EXPORTED_OBJECT)
#define NM_DHCP4_CONFIG_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), NM_TYPE_DHCP4_CONFIG, NMDhcp4ConfigPrivate))
@@ -185,7 +185,6 @@ nm_dhcp4_config_class_init (NMDhcp4ConfigClass *config_class)
G_PARAM_READABLE |
G_PARAM_STATIC_STRINGS));
nm_dbus_manager_register_exported_type (nm_dbus_manager_get (),
G_TYPE_FROM_CLASS (config_class),
nm_exported_object_class_add_interface (NM_EXPORTED_OBJECT_CLASS (config_class),
&dbus_glib_nm_dhcp4_config_object_info);
}

View File

@@ -21,9 +21,7 @@
#ifndef __NETWORKMANAGER_DHCP4_CONFIG_H__
#define __NETWORKMANAGER_DHCP4_CONFIG_H__
#include "nm-glib.h"
#include "nm-types.h"
#include "nm-exported-object.h"
#define NM_TYPE_DHCP4_CONFIG (nm_dhcp4_config_get_type ())
#define NM_DHCP4_CONFIG(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), NM_TYPE_DHCP4_CONFIG, NMDhcp4Config))
@@ -33,11 +31,11 @@
#define NM_DHCP4_CONFIG_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), NM_TYPE_DHCP4_CONFIG, NMDhcp4ConfigClass))
struct _NMDhcp4Config {
GObject parent;
NMExportedObject parent;
};
typedef struct {
GObjectClass parent;
NMExportedObjectClass parent;
} NMDhcp4ConfigClass;

View File

@@ -30,7 +30,7 @@
#include "nm-dbus-glib-types.h"
#include "nm-utils.h"
G_DEFINE_TYPE (NMDhcp6Config, nm_dhcp6_config, G_TYPE_OBJECT)
G_DEFINE_TYPE (NMDhcp6Config, nm_dhcp6_config, NM_TYPE_EXPORTED_OBJECT)
#define NM_DHCP6_CONFIG_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), NM_TYPE_DHCP6_CONFIG, NMDhcp6ConfigPrivate))
@@ -185,7 +185,6 @@ nm_dhcp6_config_class_init (NMDhcp6ConfigClass *config_class)
G_PARAM_READABLE |
G_PARAM_STATIC_STRINGS));
nm_dbus_manager_register_exported_type (nm_dbus_manager_get (),
G_TYPE_FROM_CLASS (config_class),
nm_exported_object_class_add_interface (NM_EXPORTED_OBJECT_CLASS (config_class),
&dbus_glib_nm_dhcp6_config_object_info);
}

View File

@@ -21,9 +21,7 @@
#ifndef __NETWORKMANAGER_DHCP6_CONFIG_H__
#define __NETWORKMANAGER_DHCP6_CONFIG_H__
#include "nm-glib.h"
#include "nm-types.h"
#include "nm-exported-object.h"
#define NM_TYPE_DHCP6_CONFIG (nm_dhcp6_config_get_type ())
#define NM_DHCP6_CONFIG(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), NM_TYPE_DHCP6_CONFIG, NMDhcp6Config))
@@ -33,11 +31,11 @@
#define NM_DHCP6_CONFIG_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), NM_TYPE_DHCP6_CONFIG, NMDhcp6ConfigClass))
struct _NMDhcp6Config {
GObject parent;
NMExportedObject parent;
};
typedef struct {
GObjectClass parent;
NMExportedObjectClass parent;
} NMDhcp6ConfigClass;

247
src/nm-exported-object.c Normal file
View File

@@ -0,0 +1,247 @@
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */
/* NetworkManager -- Network link manager
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Copyright 2014-2015 Red Hat, Inc.
*/
#include "config.h"
#include <string.h>
#include "nm-exported-object.h"
#include "nm-dbus-glib-types.h"
#include "nm-logging.h"
G_DEFINE_ABSTRACT_TYPE (NMExportedObject, nm_exported_object, G_TYPE_OBJECT)
typedef struct {
GHashTable *pending_notifies;
guint notify_idle_id;
} NMExportedObjectPrivate;
#define NM_EXPORTED_OBJECT_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), NM_TYPE_EXPORTED_OBJECT, NMExportedObjectPrivate))
enum {
PROPERTIES_CHANGED,
LAST_SIGNAL
};
static guint signals[LAST_SIGNAL] = { 0 };
typedef struct {
GHashTable *properties;
} NMExportedObjectClassInfo;
GQuark nm_exported_object_class_info_quark (void);
G_DEFINE_QUARK (NMExportedObjectClassInfo, nm_exported_object_class_info)
/**
* nm_exported_object_class_add_interface:
* @object_class: an #NMExportedObjectClass
* @info: generated #DBusGObjectInfo for the class
*
* Adds @info to the list of D-Bus interfaces implemented by @object_class and
* sets up automatic dbus-glib handling for instances of that class.
*
* If @info includes any properties, then a "PropertiesChanged" signal will
* be emitted on @info's interface whenever any of those properties change on
* an exported instance of @object_class.
*/
void
nm_exported_object_class_add_interface (NMExportedObjectClass *object_class,
const DBusGObjectInfo *info)
{
GType object_type = G_TYPE_FROM_CLASS (object_class);
NMExportedObjectClassInfo *classinfo;
const char *properties_info, *dbus_name, *gobject_name, *tmp_access;
char *hyphen_name, *p;
dbus_g_object_type_install_info (object_type, info);
if (!info->exported_properties)
return;
classinfo = g_type_get_qdata (object_type, nm_exported_object_class_info_quark ());
if (!classinfo) {
classinfo = g_slice_new (NMExportedObjectClassInfo);
classinfo->properties = g_hash_table_new (g_str_hash, g_str_equal);
g_type_set_qdata (object_type, nm_exported_object_class_info_quark (), classinfo);
}
properties_info = info->exported_properties;
while (*properties_info) {
/* The format is: "interface\0DBusPropertyName\0gobject_property_name\0access\0" */
dbus_name = strchr (properties_info, '\0') + 1;
gobject_name = strchr (dbus_name, '\0') + 1;
tmp_access = strchr (gobject_name, '\0') + 1;
properties_info = strchr (tmp_access, '\0') + 1;
if (strchr (gobject_name, '_')) {
hyphen_name = g_strdup (gobject_name);
for (p = hyphen_name; *p; p++) {
if (*p == '_')
*p = '-';
}
g_assert (!g_hash_table_contains (classinfo->properties, hyphen_name));
g_hash_table_insert (classinfo->properties,
(char *) g_intern_string (hyphen_name),
(char *) dbus_name);
g_free (hyphen_name);
} else {
g_assert (!g_hash_table_contains (classinfo->properties, (char *) gobject_name));
g_hash_table_insert (classinfo->properties,
(char *) gobject_name,
(char *) dbus_name);
}
}
}
static void
destroy_value (gpointer data)
{
GValue *val = (GValue *) data;
g_value_unset (val);
g_slice_free (GValue, val);
}
static void
nm_exported_object_init (NMExportedObject *self)
{
NMExportedObjectPrivate *priv = NM_EXPORTED_OBJECT_GET_PRIVATE (self);
priv->pending_notifies = g_hash_table_new_full (g_str_hash, g_str_equal,
NULL, destroy_value);
}
static void
add_to_string (gpointer key, gpointer value, gpointer user_data)
{
const char *name = (const char *) key;
GString *buf = user_data;
GValue str_val = G_VALUE_INIT;
g_value_init (&str_val, G_TYPE_STRING);
if (!g_value_transform ((GValue *) value, &str_val)) {
if (G_VALUE_HOLDS_OBJECT (value)) {
GObject *obj = g_value_get_object (value);
if (obj) {
g_string_append_printf (buf, "{%s: %p (%s)}, ", name, obj,
G_OBJECT_TYPE_NAME (obj));
} else
g_string_append_printf (buf, "{%s: %p}, ", name, obj);
} else
g_string_append_printf (buf, "{%s: <transform error>}, ", name);
} else
g_string_append_printf (buf, "{%s: %s}, ", name, g_value_get_string (&str_val));
g_value_unset (&str_val);
}
static gboolean
idle_emit_properties_changed (gpointer self)
{
NMExportedObjectPrivate *priv = NM_EXPORTED_OBJECT_GET_PRIVATE (self);
priv->notify_idle_id = 0;
if (nm_logging_enabled (LOGL_DEBUG, LOGD_DBUS_PROPS)) {
GString *buf = g_string_new (NULL);
g_hash_table_foreach (priv->pending_notifies, add_to_string, buf);
nm_log_dbg (LOGD_DBUS_PROPS, "%s -> %s", G_OBJECT_TYPE_NAME (self), buf->str);
g_string_free (buf, TRUE);
}
g_signal_emit (self, signals[PROPERTIES_CHANGED], 0, priv->pending_notifies);
g_hash_table_remove_all (priv->pending_notifies);
return FALSE;
}
static void
nm_exported_object_notify (GObject *object, GParamSpec *pspec)
{
NMExportedObjectPrivate *priv = NM_EXPORTED_OBJECT_GET_PRIVATE (object);
NMExportedObjectClassInfo *classinfo;
const char *dbus_property_name = NULL;
GValue *value;
GType type;
for (type = G_OBJECT_TYPE (object); type; type = g_type_parent (type)) {
classinfo = g_type_get_qdata (type, nm_exported_object_class_info_quark ());
if (!classinfo)
continue;
dbus_property_name = g_hash_table_lookup (classinfo->properties, pspec->name);
if (dbus_property_name)
break;
}
if (!dbus_property_name) {
nm_log_trace (LOGD_DBUS_PROPS, "ignoring notification for prop %s on type %s",
pspec->name, G_OBJECT_TYPE_NAME (object));
return;
}
value = g_slice_new0 (GValue);
g_value_init (value, pspec->value_type);
g_object_get_property (object, pspec->name, value);
g_hash_table_insert (priv->pending_notifies, (char *) dbus_property_name, value);
if (!priv->notify_idle_id)
priv->notify_idle_id = g_idle_add (idle_emit_properties_changed, object);
}
static void
nm_exported_object_dispose (GObject *object)
{
NMExportedObjectPrivate *priv = NM_EXPORTED_OBJECT_GET_PRIVATE (object);
g_hash_table_remove_all (priv->pending_notifies);
nm_clear_g_source (&priv->notify_idle_id);
G_OBJECT_CLASS (nm_exported_object_parent_class)->dispose (object);
}
static void
nm_exported_object_finalize (GObject *object)
{
NMExportedObjectPrivate *priv = NM_EXPORTED_OBJECT_GET_PRIVATE (object);
g_hash_table_destroy (priv->pending_notifies);
G_OBJECT_CLASS (nm_exported_object_parent_class)->finalize (object);
}
static void
nm_exported_object_class_init (NMExportedObjectClass *klass)
{
GObjectClass *object_class = G_OBJECT_CLASS (klass);
g_type_class_add_private (object_class, sizeof (NMExportedObjectPrivate));
object_class->notify = nm_exported_object_notify;
object_class->dispose = nm_exported_object_dispose;
object_class->finalize = nm_exported_object_finalize;
signals[PROPERTIES_CHANGED] = g_signal_new ("properties-changed",
G_OBJECT_CLASS_TYPE (object_class),
G_SIGNAL_RUN_FIRST,
0, NULL, NULL, NULL,
G_TYPE_NONE, 1, DBUS_TYPE_G_MAP_OF_VARIANT);
}

53
src/nm-exported-object.h Normal file
View File

@@ -0,0 +1,53 @@
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */
/* NetworkManager -- Network link manager
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Copyright 2014 Red Hat, Inc.
*/
#ifndef NM_EXPORTED_OBJECT_H
#define NM_EXPORTED_OBJECT_H
#include <dbus/dbus-glib.h>
#include "nm-glib.h"
#include "nm-types.h"
G_BEGIN_DECLS
#define NM_TYPE_EXPORTED_OBJECT (nm_exported_object_get_type ())
#define NM_EXPORTED_OBJECT(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), NM_TYPE_EXPORTED_OBJECT, NMExportedObject))
#define NM_EXPORTED_OBJECT_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), NM_TYPE_EXPORTED_OBJECT, NMExportedObjectClass))
#define NM_IS_EXPORTED_OBJECT(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), NM_TYPE_EXPORTED_OBJECT))
#define NM_IS_EXPORTED_OBJECT_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), NM_TYPE_EXPORTED_OBJECT))
#define NM_EXPORTED_OBJECT_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), NM_TYPE_EXPORTED_OBJECT, NMExportedObjectClass))
typedef struct {
GObject parent;
} NMExportedObject;
typedef struct {
GObjectClass parent;
} NMExportedObjectClass;
GType nm_exported_object_get_type (void);
void nm_exported_object_class_add_interface (NMExportedObjectClass *object_class,
const DBusGObjectInfo *info);
G_END_DECLS
#endif /* NM_EXPORTED_OBJECT_H */

View File

@@ -37,7 +37,7 @@
#include "nm-core-internal.h"
#include "gsystem-local-alloc.h"
G_DEFINE_TYPE (NMIP4Config, nm_ip4_config, G_TYPE_OBJECT)
G_DEFINE_TYPE (NMIP4Config, nm_ip4_config, NM_TYPE_EXPORTED_OBJECT)
#define NM_IP4_CONFIG_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), NM_TYPE_IP4_CONFIG, NMIP4ConfigPrivate))
@@ -2410,7 +2410,6 @@ nm_ip4_config_class_init (NMIP4ConfigClass *config_class)
g_object_class_install_properties (object_class, LAST_PROP, obj_properties);
nm_dbus_manager_register_exported_type (nm_dbus_manager_get (),
G_TYPE_FROM_CLASS (config_class),
nm_exported_object_class_add_interface (NM_EXPORTED_OBJECT_CLASS (config_class),
&dbus_glib_nm_ip4_config_object_info);
}

View File

@@ -21,9 +21,7 @@
#ifndef __NETWORKMANAGER_IP4_CONFIG_H__
#define __NETWORKMANAGER_IP4_CONFIG_H__
#include "nm-glib.h"
#include "nm-types.h"
#include "nm-exported-object.h"
#include "nm-setting-ip4-config.h"
#define NM_TYPE_IP4_CONFIG (nm_ip4_config_get_type ())
@@ -34,11 +32,11 @@
#define NM_IP4_CONFIG_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), NM_TYPE_IP4_CONFIG, NMIP4ConfigClass))
struct _NMIP4Config {
GObject parent;
NMExportedObject parent;
};
typedef struct {
GObjectClass parent;
NMExportedObjectClass parent;
} NMIP4ConfigClass;
/* internal */

View File

@@ -36,7 +36,7 @@
#include "nm-core-internal.h"
#include "NetworkManagerUtils.h"
G_DEFINE_TYPE (NMIP6Config, nm_ip6_config, G_TYPE_OBJECT)
G_DEFINE_TYPE (NMIP6Config, nm_ip6_config, NM_TYPE_EXPORTED_OBJECT)
#define NM_IP6_CONFIG_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), NM_TYPE_IP6_CONFIG, NMIP6ConfigPrivate))
@@ -2215,7 +2215,6 @@ nm_ip6_config_class_init (NMIP6ConfigClass *config_class)
g_object_class_install_properties (object_class, LAST_PROP, obj_properties);
nm_dbus_manager_register_exported_type (nm_dbus_manager_get (),
G_TYPE_FROM_CLASS (config_class),
nm_exported_object_class_add_interface (NM_EXPORTED_OBJECT_CLASS (config_class),
&dbus_glib_nm_ip6_config_object_info);
}

View File

@@ -23,8 +23,7 @@
#include <netinet/in.h>
#include "nm-glib.h"
#include "nm-types.h"
#include "nm-exported-object.h"
#include "nm-setting-ip6-config.h"
#define NM_TYPE_IP6_CONFIG (nm_ip6_config_get_type ())
@@ -35,11 +34,11 @@
#define NM_IP6_CONFIG_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), NM_TYPE_IP6_CONFIG, NMIP6ConfigClass))
struct _NMIP6Config {
GObject parent;
NMExportedObject parent;
};
typedef struct {
GObjectClass parent;
NMExportedObjectClass parent;
} NMIP6ConfigClass;
/* internal */

View File

@@ -194,7 +194,7 @@ typedef struct {
#define NM_MANAGER_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), NM_TYPE_MANAGER, NMManagerPrivate))
G_DEFINE_TYPE (NMManager, nm_manager, G_TYPE_OBJECT)
G_DEFINE_TYPE (NMManager, nm_manager, NM_TYPE_EXPORTED_OBJECT)
enum {
DEVICE_ADDED,
@@ -5298,8 +5298,7 @@ nm_manager_class_init (NMManagerClass *manager_class)
0, NULL, NULL, NULL,
G_TYPE_NONE, 0);
nm_dbus_manager_register_exported_type (nm_dbus_manager_get (),
G_TYPE_FROM_CLASS (manager_class),
nm_exported_object_class_add_interface (NM_EXPORTED_OBJECT_CLASS (manager_class),
&dbus_glib_nm_manager_object_info);
dbus_g_error_domain_register (NM_MANAGER_ERROR, NM_DBUS_INTERFACE, NM_TYPE_MANAGER_ERROR);

View File

@@ -22,9 +22,7 @@
#ifndef __NETWORKMANAGER_MANAGER_H__
#define __NETWORKMANAGER_MANAGER_H__
#include "nm-glib.h"
#include "nm-types.h"
#include "nm-exported-object.h"
#include "nm-connection.h"
#define NM_TYPE_MANAGER (nm_manager_get_type ())
@@ -63,11 +61,11 @@
struct _NMManager {
GObject parent;
NMExportedObject parent;
};
typedef struct {
GObjectClass parent;
NMExportedObjectClass parent;
/* Signals */
void (*device_added) (NMManager *manager, NMDevice *device);

View File

@@ -1,248 +0,0 @@
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */
/* NetworkManager -- Network link manager
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Copyright (C) 2007 - 2008 Novell, Inc.
* Copyright (C) 2008 - 2012 Red Hat, Inc.
*/
#include "config.h"
#include <string.h>
#include <stdio.h>
#include <dbus/dbus-glib.h>
#include "nm-logging.h"
#include "nm-properties-changed-signal.h"
#include "nm-dbus-glib-types.h"
typedef struct {
GHashTable *exported_props;
guint signal_id;
} NMPropertiesChangedClassInfo;
typedef struct {
GHashTable *hash;
guint signal_id;
guint idle_id;
} NMPropertiesChangedInfo;
static GQuark
nm_properties_changed_signal_quark (void)
{
static GQuark q;
if (G_UNLIKELY (q == 0))
q = g_quark_from_static_string ("nm-properties-changed-signal");
return q;
}
static void
destroy_value (gpointer data)
{
GValue *val = (GValue *) data;
g_value_unset (val);
g_slice_free (GValue, val);
}
static void
properties_changed_info_destroy (gpointer data)
{
NMPropertiesChangedInfo *info = data;
if (info->idle_id)
g_source_remove (info->idle_id);
g_hash_table_destroy (info->hash);
g_slice_free (NMPropertiesChangedInfo, info);
}
static void
add_to_string (gpointer key, gpointer value, gpointer user_data)
{
const char *name = (const char *) key;
GString *buf = user_data;
GValue str_val = G_VALUE_INIT;
g_value_init (&str_val, G_TYPE_STRING);
if (!g_value_transform ((GValue *) value, &str_val)) {
if (G_VALUE_HOLDS_OBJECT (value)) {
GObject *obj = g_value_get_object (value);
if (obj) {
g_string_append_printf (buf, "{%s: %p (%s)}, ", name, obj,
G_OBJECT_TYPE_NAME (obj));
} else
g_string_append_printf (buf, "{%s: %p}, ", name, obj);
} else
g_string_append_printf (buf, "{%s: <transform error>}, ", name);
} else
g_string_append_printf (buf, "{%s: %s}, ", name, g_value_get_string (&str_val));
g_value_unset (&str_val);
}
static gboolean
properties_changed (gpointer data)
{
GObject *object = G_OBJECT (data);
NMPropertiesChangedInfo *info = g_object_get_qdata (object, nm_properties_changed_signal_quark ());
g_assert (info);
if (nm_logging_enabled (LOGL_DEBUG, LOGD_DBUS_PROPS)) {
GString *buf = g_string_new (NULL);
g_hash_table_foreach (info->hash, add_to_string, buf);
nm_log_dbg (LOGD_DBUS_PROPS, "%s -> %s", G_OBJECT_TYPE_NAME (object), buf->str);
g_string_free (buf, TRUE);
}
g_signal_emit (object, info->signal_id, 0, info->hash);
g_hash_table_remove_all (info->hash);
return FALSE;
}
static void
idle_id_reset (gpointer data)
{
GObject *object = G_OBJECT (data);
NMPropertiesChangedInfo *info = g_object_get_qdata (object, nm_properties_changed_signal_quark ());
/* info is unset when the object is being destroyed */
if (info)
info->idle_id = 0;
}
static void
notify (GObject *object, GParamSpec *pspec)
{
NMPropertiesChangedClassInfo *classinfo;
NMPropertiesChangedInfo *info;
const char *dbus_property_name = NULL;
GValue *value;
GType type;
for (type = G_OBJECT_TYPE (object); type; type = g_type_parent (type)) {
classinfo = g_type_get_qdata (type, nm_properties_changed_signal_quark ());
if (!classinfo)
continue;
dbus_property_name = g_hash_table_lookup (classinfo->exported_props, pspec->name);
if (dbus_property_name)
break;
}
if (!dbus_property_name) {
nm_log_trace (LOGD_DBUS_PROPS, "ignoring notification for prop %s on type %s",
pspec->name, G_OBJECT_TYPE_NAME (object));
return;
}
info = g_object_get_qdata (object, nm_properties_changed_signal_quark ());
if (!info) {
info = g_slice_new0 (NMPropertiesChangedInfo);
info->hash = g_hash_table_new_full (g_str_hash, g_str_equal,
NULL, destroy_value);
info->signal_id = classinfo->signal_id;
g_object_set_qdata_full (object, nm_properties_changed_signal_quark (),
info, properties_changed_info_destroy);
}
value = g_slice_new0 (GValue);
g_value_init (value, pspec->value_type);
g_object_get_property (object, pspec->name, value);
g_hash_table_insert (info->hash, (char *) dbus_property_name, value);
if (!info->idle_id)
info->idle_id = g_idle_add_full (G_PRIORITY_DEFAULT_IDLE, properties_changed, object, idle_id_reset);
}
static NMPropertiesChangedClassInfo *
nm_properties_changed_signal_setup_type (GType type)
{
NMPropertiesChangedClassInfo *classinfo;
NMPropertiesChangedClassInfo *parent_classinfo = NULL;
GObjectClass *object_class;
GType parent;
classinfo = g_slice_new (NMPropertiesChangedClassInfo);
g_type_set_qdata (type, nm_properties_changed_signal_quark (), classinfo);
object_class = g_type_class_ref (type);
object_class->notify = notify;
g_type_class_unref (object_class);
classinfo->exported_props = g_hash_table_new (g_str_hash, g_str_equal);
/* See if we've already added the signal to a parent class. (We can't just use
* g_signal_lookup() here because it prints a warning if the signal doesn't exist!)
*/
parent = g_type_parent (type);
while (parent) {
parent_classinfo = g_type_get_qdata (parent, nm_properties_changed_signal_quark ());
if (parent_classinfo)
break;
parent = g_type_parent (parent);
}
if (parent_classinfo)
classinfo->signal_id = parent_classinfo->signal_id;
else {
classinfo->signal_id = g_signal_new ("properties-changed",
type,
G_SIGNAL_RUN_FIRST,
0,
NULL, NULL,
g_cclosure_marshal_VOID__BOXED,
G_TYPE_NONE, 1, DBUS_TYPE_G_MAP_OF_VARIANT);
}
return classinfo;
}
void
nm_properties_changed_signal_add_property (GType type,
const char *dbus_property_name,
const char *gobject_property_name)
{
NMPropertiesChangedClassInfo *classinfo;
char *hyphen_name, *p;
classinfo = g_type_get_qdata (type, nm_properties_changed_signal_quark ());
if (!classinfo)
classinfo = nm_properties_changed_signal_setup_type (type);
g_assert (!g_hash_table_contains (classinfo->exported_props, (char *) gobject_property_name));
g_hash_table_insert (classinfo->exported_props,
(char *) gobject_property_name,
(char *) dbus_property_name);
if (!strchr (gobject_property_name, '_'))
return;
hyphen_name = g_strdup (gobject_property_name);
for (p = hyphen_name; *p; p++) {
if (*p == '_')
*p = '-';
}
g_assert (!g_hash_table_contains (classinfo->exported_props, hyphen_name));
g_hash_table_insert (classinfo->exported_props,
(char *) g_intern_string (hyphen_name),
(char *) dbus_property_name);
g_free (hyphen_name);
}

View File

@@ -1,31 +0,0 @@
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */
/* NetworkManager -- Network link manager
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Copyright (C) 2007 - 2008 Novell, Inc.
* Copyright (C) 2008 Red Hat, Inc.
*/
#ifndef _NM_PROPERTIES_CHANGED_SIGNAL_H_
#define _NM_PROPERTIES_CHANGED_SIGNAL_H_
#include "nm-glib.h"
void nm_properties_changed_signal_add_property (GType type,
const char *dbus_property_name,
const char *gobject_property_name);
#endif /* _NM_PROPERTIES_CHANGED_SIGNAL_H_ */

View File

@@ -95,7 +95,7 @@ typedef struct {
#define NM_PPP_MANAGER_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), NM_TYPE_PPP_MANAGER, NMPPPManagerPrivate))
G_DEFINE_TYPE (NMPPPManager, nm_ppp_manager, G_TYPE_OBJECT)
G_DEFINE_TYPE (NMPPPManager, nm_ppp_manager, NM_TYPE_EXPORTED_OBJECT)
enum {
STATE_CHANGED,
@@ -672,8 +672,8 @@ nm_ppp_manager_class_init (NMPPPManagerClass *manager_class)
G_TYPE_NONE, 2,
G_TYPE_UINT, G_TYPE_UINT);
dbus_g_object_type_install_info (G_TYPE_FROM_CLASS (manager_class),
&dbus_glib_nm_ppp_manager_object_info);
nm_exported_object_class_add_interface (NM_EXPORTED_OBJECT_CLASS (manager_class),
&dbus_glib_nm_ppp_manager_object_info);
}
/*******************************************/

View File

@@ -23,7 +23,7 @@
#define __NETWORKMANAGER_PPP_MANAGER_H__
#include "nm-glib.h"
#include "nm-exported-object.h"
#include "nm-ppp-status.h"
#include "nm-activation-request.h"
#include "nm-connection.h"
@@ -42,11 +42,11 @@
#define NM_PPP_MANAGER_PARENT_IFACE "parent-iface"
typedef struct {
GObject parent;
NMExportedObject parent;
} NMPPPManager;
typedef struct {
GObjectClass parent;
NMExportedObjectClass parent;
/* Signals */
void (*state_changed) (NMPPPManager *manager, NMPPPStatus status);

View File

@@ -43,7 +43,7 @@
#include "nm-simple-connection.h"
#include "NetworkManagerUtils.h"
G_DEFINE_TYPE (NMAgentManager, nm_agent_manager, G_TYPE_OBJECT)
G_DEFINE_TYPE (NMAgentManager, nm_agent_manager, NM_TYPE_EXPORTED_OBJECT)
#define NM_AGENT_MANAGER_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), \
NM_TYPE_AGENT_MANAGER, \
@@ -1622,8 +1622,8 @@ nm_agent_manager_class_init (NMAgentManagerClass *agent_manager_class)
G_TYPE_NONE, 1,
G_TYPE_OBJECT);
dbus_g_object_type_install_info (G_TYPE_FROM_CLASS (agent_manager_class),
&dbus_glib_nm_agent_manager_object_info);
nm_exported_object_class_add_interface (NM_EXPORTED_OBJECT_CLASS (agent_manager_class),
&dbus_glib_nm_agent_manager_object_info);
dbus_g_error_domain_register (NM_AGENT_MANAGER_ERROR,
NM_DBUS_INTERFACE_AGENT_MANAGER,

View File

@@ -22,9 +22,9 @@
#define __NETWORKMANAGER_AGENT_MANAGER_H__
#include <nm-connection.h>
#include "nm-glib.h"
#include "nm-exported-object.h"
#include "nm-secret-agent.h"
#include "nm-types.h"
#define NM_TYPE_AGENT_MANAGER (nm_agent_manager_get_type ())
#define NM_AGENT_MANAGER(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), NM_TYPE_AGENT_MANAGER, NMAgentManager))
@@ -34,11 +34,11 @@
#define NM_AGENT_MANAGER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), NM_TYPE_AGENT_MANAGER, NMAgentManagerClass))
struct _NMAgentManager {
GObject parent;
NMExportedObject parent;
};
typedef struct {
GObjectClass parent;
NMExportedObjectClass parent;
/* Signals */
void (*agent_registered) (NMAgentManager *agent_mgr, NMSecretAgent *agent);

View File

@@ -36,7 +36,6 @@
#include "nm-auth-subject.h"
#include "nm-agent-manager.h"
#include "NetworkManagerUtils.h"
#include "nm-properties-changed-signal.h"
#include "nm-core-internal.h"
#include "gsystem-local-alloc.h"
@@ -113,7 +112,7 @@ static void impl_settings_connection_clear_secrets (NMSettingsConnection *self,
static void nm_settings_connection_connection_interface_init (NMConnectionInterface *iface);
G_DEFINE_TYPE_WITH_CODE (NMSettingsConnection, nm_settings_connection, G_TYPE_OBJECT,
G_DEFINE_TYPE_WITH_CODE (NMSettingsConnection, nm_settings_connection, NM_TYPE_EXPORTED_OBJECT,
G_IMPLEMENT_INTERFACE (NM_TYPE_CONNECTION, nm_settings_connection_connection_interface_init)
)
@@ -2513,8 +2512,7 @@ nm_settings_connection_class_init (NMSettingsConnectionClass *class)
g_cclosure_marshal_VOID__VOID,
G_TYPE_NONE, 0);
nm_dbus_manager_register_exported_type (nm_dbus_manager_get (),
G_TYPE_FROM_CLASS (class),
nm_exported_object_class_add_interface (NM_EXPORTED_OBJECT_CLASS (class),
&dbus_glib_nm_settings_connection_object_info);
}

View File

@@ -24,6 +24,7 @@
#include <net/ethernet.h>
#include "nm-exported-object.h"
#include <nm-connection.h>
#include "nm-types.h"
@@ -95,11 +96,11 @@ typedef void (*NMSettingsConnectionDeleteFunc) (NMSettingsConnection *self,
gpointer user_data);
struct _NMSettingsConnection {
GObject parent;
NMExportedObject parent;
};
struct _NMSettingsConnectionClass {
GObjectClass parent;
NMExportedObjectClass parent;
/* virtual methods */
void (*replace_and_commit) (NMSettingsConnection *self,

View File

@@ -156,7 +156,7 @@ static void unrecognized_specs_changed (NMSystemConfigInterface *config, gpointe
static void connection_provider_init (NMConnectionProvider *cp_class);
G_DEFINE_TYPE_EXTENDED (NMSettings, nm_settings, G_TYPE_OBJECT, 0,
G_DEFINE_TYPE_EXTENDED (NMSettings, nm_settings, NM_TYPE_EXPORTED_OBJECT, 0,
G_IMPLEMENT_INTERFACE (NM_TYPE_CONNECTION_PROVIDER, connection_provider_init))
@@ -192,7 +192,6 @@ typedef struct {
#define NM_SETTINGS_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), NM_TYPE_SETTINGS, NMSettingsPrivate))
enum {
PROPERTIES_CHANGED,
CONNECTION_ADDED,
CONNECTION_UPDATED,
CONNECTION_UPDATED_BY_USER,
@@ -456,51 +455,6 @@ nm_settings_get_connection_by_path (NMSettings *self, const char *path)
return (NMSettingsConnection *) g_hash_table_lookup (priv->connections, path);
}
static char*
uscore_to_wincaps (const char *uscore)
{
const char *p;
GString *str;
gboolean last_was_uscore;
last_was_uscore = TRUE;
str = g_string_new (NULL);
p = uscore;
while (p && *p) {
if (*p == '-' || *p == '_')
last_was_uscore = TRUE;
else {
if (last_was_uscore) {
g_string_append_c (str, g_ascii_toupper (*p));
last_was_uscore = FALSE;
} else
g_string_append_c (str, *p);
}
++p;
}
return g_string_free (str, FALSE);
}
static void
notify (GObject *object, GParamSpec *pspec)
{
GValue *value;
GHashTable *hash;
value = g_slice_new0 (GValue);
hash = g_hash_table_new_full (g_str_hash, g_str_equal, (GDestroyNotify) g_free, NULL);
g_value_init (value, pspec->value_type);
g_object_get_property (object, pspec->name, value);
g_hash_table_insert (hash, uscore_to_wincaps (pspec->name), value);
g_signal_emit (object, signals[PROPERTIES_CHANGED], 0, hash);
g_hash_table_destroy (hash);
g_value_unset (value);
g_slice_free (GValue, value);
}
gboolean
nm_settings_has_connection (NMSettings *self, NMConnection *connection)
{
@@ -2329,7 +2283,6 @@ nm_settings_class_init (NMSettingsClass *class)
g_type_class_add_private (class, sizeof (NMSettingsPrivate));
/* virtual methods */
object_class->notify = notify;
object_class->get_property = get_property;
object_class->dispose = dispose;
object_class->finalize = finalize;
@@ -2365,14 +2318,6 @@ nm_settings_class_init (NMSettingsClass *class)
G_PARAM_STATIC_STRINGS));
/* signals */
signals[PROPERTIES_CHANGED] =
g_signal_new ("properties-changed",
G_OBJECT_CLASS_TYPE (object_class),
G_SIGNAL_RUN_FIRST,
G_STRUCT_OFFSET (NMSettingsClass, properties_changed),
NULL, NULL,
g_cclosure_marshal_VOID__BOXED,
G_TYPE_NONE, 1, DBUS_TYPE_G_MAP_OF_VARIANT);
signals[CONNECTION_ADDED] =
g_signal_new (NM_SETTINGS_SIGNAL_CONNECTION_ADDED,
G_OBJECT_CLASS_TYPE (object_class),
@@ -2435,14 +2380,14 @@ nm_settings_class_init (NMSettingsClass *class)
g_cclosure_marshal_VOID__OBJECT,
G_TYPE_NONE, 1, G_TYPE_OBJECT);
nm_exported_object_class_add_interface (NM_EXPORTED_OBJECT_CLASS (class),
&dbus_glib_nm_settings_object_info);
dbus_g_error_domain_register (NM_SETTINGS_ERROR,
NM_DBUS_INTERFACE_SETTINGS,
NM_TYPE_SETTINGS_ERROR);
dbus_g_error_domain_register (NM_CONNECTION_ERROR,
NM_DBUS_INTERFACE_SETTINGS_CONNECTION,
NM_TYPE_CONNECTION_ERROR);
dbus_g_object_type_install_info (NM_TYPE_SETTINGS, &dbus_glib_nm_settings_object_info);
}

View File

@@ -28,8 +28,7 @@
#include <nm-connection.h>
#include "nm-glib.h"
#include "nm-types.h"
#include "nm-exported-object.h"
#define NM_TYPE_SETTINGS (nm_settings_get_type ())
#define NM_SETTINGS(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), NM_TYPE_SETTINGS, NMSettings))
@@ -52,11 +51,11 @@
#define NM_SETTINGS_SIGNAL_AGENT_REGISTERED "agent-registered"
struct _NMSettings {
GObject parent_instance;
NMExportedObject parent_instance;
};
typedef struct {
GObjectClass parent_class;
NMExportedObjectClass parent_class;
/* Signals */
void (*properties_changed) (NMSettings *self, GHashTable *properties);

View File

@@ -98,7 +98,7 @@ static NMIfcfgConnection *update_connection (SCPluginIfcfg *plugin,
static void system_config_interface_init (NMSystemConfigInterface *system_config_interface_class);
G_DEFINE_TYPE_EXTENDED (SCPluginIfcfg, sc_plugin_ifcfg, G_TYPE_OBJECT, 0,
G_DEFINE_TYPE_EXTENDED (SCPluginIfcfg, sc_plugin_ifcfg, NM_TYPE_EXPORTED_OBJECT, 0,
G_IMPLEMENT_INTERFACE (NM_TYPE_SYSTEM_CONFIG_INTERFACE,
system_config_interface_init))
@@ -897,8 +897,8 @@ sc_plugin_ifcfg_class_init (SCPluginIfcfgClass *req_class)
NM_SYSTEM_CONFIG_INTERFACE_PROP_CAPABILITIES,
NM_SYSTEM_CONFIG_INTERFACE_CAPABILITIES);
dbus_g_object_type_install_info (G_TYPE_FROM_CLASS (req_class),
&dbus_glib_nm_ifcfg_rh_object_info);
nm_exported_object_class_add_interface (NM_EXPORTED_OBJECT_CLASS (req_class),
&dbus_glib_nm_ifcfg_rh_object_info);
}
static void

View File

@@ -24,7 +24,7 @@
#ifndef _PLUGIN_H_
#define _PLUGIN_H_
#include "nm-glib.h"
#include "nm-exported-object.h"
#define SC_TYPE_PLUGIN_IFCFG (sc_plugin_ifcfg_get_type ())
#define SC_PLUGIN_IFCFG(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), SC_TYPE_PLUGIN_IFCFG, SCPluginIfcfg))
@@ -37,11 +37,11 @@ typedef struct _SCPluginIfcfg SCPluginIfcfg;
typedef struct _SCPluginIfcfgClass SCPluginIfcfgClass;
struct _SCPluginIfcfg {
GObject parent;
NMExportedObject parent;
};
struct _SCPluginIfcfgClass {
GObjectClass parent;
NMExportedObjectClass parent;
};
GType sc_plugin_ifcfg_get_type (void);

View File

@@ -13,6 +13,7 @@ AM_CPPFLAGS = \
-DNETWORKMANAGER_COMPILATION \
-DNM_VERSION_MAX_ALLOWED=NM_VERSION_NEXT_STABLE \
$(GLIB_CFLAGS) \
$(DBUS_CFLAGS) \
-DSYSCONFDIR=\"$(sysconfdir)\"
-DSBINDIR=\"$(sbindir)\"

View File

@@ -15,6 +15,7 @@ AM_CPPFLAGS= \
-DNM_VERSION_MAX_ALLOWED=NM_VERSION_NEXT_STABLE \
$(CHECK_CFLAGS) \
$(GLIB_CFLAGS) \
$(DBUS_CFLAGS) \
$(CODE_COVERAGE_CFLAGS) \
-DTEST_IFNET_DIR=\"$(abs_srcdir)\" \
-DTEST_SCRATCH_DIR=\"$(abs_builddir)/\" \

View File

@@ -12,6 +12,7 @@ AM_CPPFLAGS = \
-DNETWORKMANAGER_COMPILATION \
-DNM_VERSION_MAX_ALLOWED=NM_VERSION_NEXT_STABLE \
$(GLIB_CFLAGS) \
$(DBUS_CFLAGS) \
$(GUDEV_CFLAGS) \
-DSYSCONFDIR=\"$(sysconfdir)\"

View File

@@ -32,7 +32,6 @@
#include "nm-vpn-connection.h"
#include "nm-ip4-config.h"
#include "nm-ip6-config.h"
#include "nm-dbus-manager.h"
#include "nm-platform.h"
#include "nm-logging.h"
#include "nm-active-connection.h"
@@ -2362,8 +2361,7 @@ nm_vpn_connection_class_init (NMVpnConnectionClass *connection_class)
0, NULL, NULL, NULL,
G_TYPE_NONE, 0);
nm_dbus_manager_register_exported_type (nm_dbus_manager_get (),
G_TYPE_FROM_CLASS (object_class),
nm_exported_object_class_add_interface (NM_EXPORTED_OBJECT_CLASS (connection_class),
&dbus_glib_nm_vpn_connection_object_info);
}