libnm: merge branch 'th/libnm-no-dbus-codegen-4'

https://gitlab.freedesktop.org/NetworkManager/NetworkManager/merge_requests/331
This commit is contained in:
Thomas Haller 2019-11-25 15:16:36 +01:00
commit ee52656ce3
67 changed files with 8168 additions and 7053 deletions

View file

@ -1274,15 +1274,17 @@ libnm_lib_h_priv = \
libnm/nm-dns-manager.h \
libnm/nm-ip4-config.h \
libnm/nm-ip6-config.h \
libnm/nm-manager.h \
libnm/nm-object-private.h \
libnm/nm-remote-connection-private.h \
libnm/nm-remote-settings.h
$(NULL)
libnm_lib_c_real = \
libnm/nm-access-point.c \
libnm/nm-active-connection.c \
libnm/nm-checkpoint.c \
libnm/nm-client.c \
libnm/nm-object.c \
libnm/nm-device.c \
libnm/nm-active-connection.c \
\
libnm/nm-access-point.c \
libnm/nm-checkpoint.c \
libnm/nm-dbus-helpers.c \
libnm/nm-device-6lowpan.c \
libnm/nm-device-adsl.c \
@ -1311,7 +1313,6 @@ libnm_lib_c_real = \
libnm/nm-device-wimax.c \
libnm/nm-device-wireguard.c \
libnm/nm-device-wpan.c \
libnm/nm-device.c \
libnm/nm-dhcp-config.c \
libnm/nm-dhcp4-config.c \
libnm/nm-dhcp6-config.c \
@ -1320,10 +1321,7 @@ libnm_lib_c_real = \
libnm/nm-ip4-config.c \
libnm/nm-ip6-config.c \
libnm/nm-libnm-utils.c \
libnm/nm-manager.c \
libnm/nm-object.c \
libnm/nm-remote-connection.c \
libnm/nm-remote-settings.c \
libnm/nm-secret-agent-old.c \
libnm/nm-vpn-connection.c \
libnm/nm-vpn-editor.c \

3
NEWS
View file

@ -25,6 +25,9 @@ USE AT YOUR OWN RISK. NOT RECOMMENDED FOR PRODUCTION USE!
type instances would have been created by NMClient for a while now.
* DHCP: switch "internal" DHCPv4 plugin from code based on systemd to use nettools'
n-dhcp4 library.
* libnm: heavily internal rework NMClient. This slims down libnm and makes the
implementation more efficient. NMClient should work now well with a separate
GMainContext.
=============================================
NetworkManager-1.20

View file

@ -49,7 +49,6 @@ IGNORE_HFILES= \
nm-object-private.h \
nm-property-compare.h \
nm-remote-connection-private.h \
nm-remote-settings.h \
nm-setting-private.h \
nm-utils-private.h \
nm-core-tests-enum-types.h \

View file

@ -20,7 +20,6 @@ private_headers = [
'nm-object-private.h',
'nm-property-compare.h',
'nm-remote-connection-private.h',
'nm-remote-settings.h',
'nm-setting-private.h',
'nm-utils-private.h',
'nm-core-tests-enum-types.h',

View file

@ -7,6 +7,11 @@
#include "nm-default.h"
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <glib-unix.h>
#include "nm-std-aux/c-list-util.h"
#include "nm-glib-aux/nm-enum-utils.h"
@ -8103,6 +8108,191 @@ test_ethtool_offload (void)
/*****************************************************************************/
typedef struct {
GMainLoop *loop1;
GMainContext *c2;
GSource *extra_sources[2];
bool got_signal[5];
int fd_2;
} IntegData;
static gboolean
_test_integrate_cb_handle (IntegData *d, int signal)
{
int i;
g_assert (d);
g_assert (signal >= 0);
g_assert (signal < G_N_ELEMENTS (d->got_signal));
g_assert (!d->got_signal[signal]);
d->got_signal[signal] = TRUE;
for (i = 0; i < G_N_ELEMENTS (d->got_signal); i++) {
if (!d->got_signal[i])
break;
}
if (i == G_N_ELEMENTS (d->got_signal))
g_main_loop_quit (d->loop1);
return G_SOURCE_REMOVE;
}
static gboolean
_test_integrate_cb_timeout_1 (gpointer user_data)
{
return _test_integrate_cb_handle (user_data, 0);
}
static gboolean
_test_integrate_cb_fd_2 (int fd,
GIOCondition condition,
gpointer user_data)
{
IntegData *d = user_data;
g_assert (d->got_signal[1]);
g_assert (d->got_signal[2]);
g_assert (d->got_signal[3]);
g_assert (d->extra_sources[0]);
g_assert (d->extra_sources[1]);
return _test_integrate_cb_handle (d, 4);
}
static gboolean
_test_integrate_cb_idle_2 (gpointer user_data)
{
IntegData *d = user_data;
GSource *extra_source;
g_assert (d->got_signal[1]);
g_assert (d->got_signal[2]);
g_assert (d->extra_sources[0]);
g_assert (!d->extra_sources[1]);
extra_source = g_unix_fd_source_new (d->fd_2, G_IO_IN);
g_source_set_callback (extra_source, G_SOURCE_FUNC (_test_integrate_cb_fd_2), d, NULL);
g_source_attach (extra_source, d->c2);
d->extra_sources[1] = extra_source;
return _test_integrate_cb_handle (d, 3);
}
static gboolean
_test_integrate_cb_idle_1 (gpointer user_data)
{
IntegData *d = user_data;
GSource *extra_source;
g_assert (d->got_signal[2]);
g_assert (!d->extra_sources[0]);
extra_source = g_idle_source_new ();
g_source_set_callback (extra_source, _test_integrate_cb_idle_2, d, NULL);
g_source_attach (extra_source, d->c2);
d->extra_sources[0] = extra_source;
return _test_integrate_cb_handle (d, 1);
}
static gboolean
_test_integrate_cb_fd_1 (int fd,
GIOCondition condition,
gpointer user_data)
{
IntegData *d = user_data;
g_assert (!d->got_signal[1]);
return _test_integrate_cb_handle (d, 2);
}
static gboolean
_test_integrate_maincontext_cb_idle1 (gpointer user_data)
{
guint32 *p_count = user_data;
g_assert (*p_count < 5);
(*p_count)++;
return G_SOURCE_CONTINUE;
}
static void
test_integrate_maincontext (gconstpointer test_data)
{
const guint TEST_IDX = GPOINTER_TO_UINT (test_data);
GMainContext *c1 = g_main_context_default ();
nm_auto_unref_gmaincontext GMainContext *c2 = g_main_context_new ();
nm_auto_destroy_and_unref_gsource GSource *integ_source = NULL;
integ_source = nm_utils_g_main_context_create_integrate_source (c2);
g_source_attach (integ_source, c1);
if (TEST_IDX == 1) {
nm_auto_destroy_and_unref_gsource GSource *idle_source_1 = NULL;
guint32 count = 0;
idle_source_1 = g_idle_source_new ();
g_source_set_callback (idle_source_1, _test_integrate_maincontext_cb_idle1, &count, NULL);
g_source_attach (idle_source_1, c2);
nmtst_main_context_iterate_until (c1, 2000, count == 5);
}
if (TEST_IDX == 2) {
nm_auto_destroy_and_unref_gsource GSource *main_timeout_source = NULL;
nm_auto_destroy_and_unref_gsource GSource *timeout_source_1 = NULL;
nm_auto_destroy_and_unref_gsource GSource *idle_source_1 = NULL;
nm_auto_destroy_and_unref_gsource GSource *fd_source_1 = NULL;
nm_auto_unref_gmainloop GMainLoop *loop1 = NULL;
nm_auto_close int fd_1 = -1;
nm_auto_close int fd_2 = -1;
IntegData d;
int i;
main_timeout_source = g_timeout_source_new (3000);
g_source_set_callback (main_timeout_source, nmtst_g_source_assert_not_called, NULL, NULL);
g_source_attach (main_timeout_source, c1);
loop1 = g_main_loop_new (c1, FALSE);
d = (IntegData) {
.loop1 = loop1,
.c2 = c2,
};
fd_1 = open ("/dev/null", O_RDONLY | O_CLOEXEC);
g_assert (fd_1 >= 0);
fd_source_1 = g_unix_fd_source_new (fd_1, G_IO_IN);
g_source_set_callback (fd_source_1, G_SOURCE_FUNC (_test_integrate_cb_fd_1), &d, NULL);
g_source_attach (fd_source_1, c2);
fd_2 = open ("/dev/null", O_RDONLY | O_CLOEXEC);
g_assert (fd_2 >= 0);
d.fd_2 = fd_2;
idle_source_1 = g_idle_source_new ();
g_source_set_callback (idle_source_1, _test_integrate_cb_idle_1, &d, NULL);
g_source_attach (idle_source_1, c2);
timeout_source_1 = g_timeout_source_new (5);
g_source_set_callback (timeout_source_1, _test_integrate_cb_timeout_1, &d, NULL);
g_source_attach (timeout_source_1, c2);
g_main_loop_run (loop1);
for (i = 0; i < G_N_ELEMENTS (d.extra_sources); i++) {
g_assert (d.extra_sources[i]);
nm_clear_pointer (&d.extra_sources[i], nm_g_source_destroy_and_unref);
}
}
}
/*****************************************************************************/
NMTST_DEFINE ();
int main (int argc, char **argv)
@ -8263,5 +8453,8 @@ int main (int argc, char **argv)
g_test_add_func ("/core/general/test_nm_va_args_macros", test_nm_va_args_macros);
g_test_add_func ("/core/general/test_ethtool_offload", test_ethtool_offload);
g_test_add_data_func ("/core/general/test_integrate_maincontext/1", GUINT_TO_POINTER (1), test_integrate_maincontext);
g_test_add_data_func ("/core/general/test_integrate_maincontext/2", GUINT_TO_POINTER (2), test_integrate_maincontext);
return g_test_run ();
}

View file

@ -1638,6 +1638,7 @@ libnm_1_22_0 {
global:
nm_client_get_dbus_connection;
nm_client_get_dbus_name_owner;
nm_client_get_metered;
nm_client_reload;
nm_client_reload_finish;
nm_device_get_interface_flags;

View file

@ -119,10 +119,8 @@ libnm_sources = files(
'nm-ip4-config.c',
'nm-ip6-config.c',
'nm-libnm-utils.c',
'nm-manager.c',
'nm-object.c',
'nm-remote-connection.c',
'nm-remote-settings.c',
'nm-secret-agent-old.c',
'nm-vpn-connection.c',
'nm-vpn-editor.c',

View file

@ -19,7 +19,7 @@
/*****************************************************************************/
NM_GOBJECT_PROPERTIES_DEFINE_BASE (
NM_GOBJECT_PROPERTIES_DEFINE (NMAccessPoint,
PROP_FLAGS,
PROP_WPA_FLAGS,
PROP_RSN_FLAGS,
@ -34,16 +34,16 @@ NM_GOBJECT_PROPERTIES_DEFINE_BASE (
);
typedef struct {
NM80211ApFlags flags;
NM80211ApSecurityFlags wpa_flags;
NM80211ApSecurityFlags rsn_flags;
GBytes *ssid;
guint32 frequency;
char *bssid;
NM80211Mode mode;
guint32 flags;
guint32 wpa_flags;
guint32 rsn_flags;
guint32 frequency;
guint32 mode;
guint32 max_bitrate;
gint32 last_seen;
guint8 strength;
int last_seen;
} NMAccessPointPrivate;
struct _NMAccessPoint {
@ -127,9 +127,7 @@ nm_access_point_get_ssid (NMAccessPoint *ap)
g_return_val_if_fail (NM_IS_ACCESS_POINT (ap), NULL);
priv = NM_ACCESS_POINT_GET_PRIVATE (ap);
if (!priv->ssid || g_bytes_get_size (priv->ssid) == 0)
return NULL;
nm_assert (!priv->ssid || g_bytes_get_size (priv->ssid) > 0);
return priv->ssid;
}
@ -263,6 +261,9 @@ nm_access_point_connection_valid (NMAccessPoint *ap, NMConnection *connection)
const char *setting_band;
guint32 ap_freq, setting_chan, ap_chan;
g_return_val_if_fail (NM_IS_ACCESS_POINT (ap), FALSE);
g_return_val_if_fail (NM_IS_CONNECTION (connection), FALSE);
s_con = nm_connection_get_setting_connection (connection);
if (!s_con)
return FALSE;
@ -368,7 +369,12 @@ GPtrArray *
nm_access_point_filter_connections (NMAccessPoint *ap, const GPtrArray *connections)
{
GPtrArray *filtered;
int i;
guint i;
g_return_val_if_fail (NM_IS_ACCESS_POINT (ap), NULL);
if (!connections)
return NULL;
filtered = g_ptr_array_new_with_free_func (g_object_unref);
for (i = 0; i < connections->len; i++) {
@ -383,6 +389,24 @@ nm_access_point_filter_connections (NMAccessPoint *ap, const GPtrArray *connecti
/*****************************************************************************/
static NMLDBusNotifyUpdatePropFlags
_notify_update_prop_hw_address (NMClient *client,
NMLDBusObject *dbobj,
const NMLDBusMetaIface *meta_iface,
guint dbus_property_idx,
GVariant *value)
{
NMAccessPoint *self = NM_ACCESS_POINT (dbobj->nmobj);
NMAccessPointPrivate *priv = NM_ACCESS_POINT_GET_PRIVATE (self);
g_free (priv->bssid);
priv->bssid = value ? g_variant_dup_string (value, NULL) : 0u;
_notify (self, PROP_HW_ADDRESS);
return NML_DBUS_NOTIFY_UPDATE_PROP_FLAGS_NOTIFY;
}
/*****************************************************************************/
static void
nm_access_point_init (NMAccessPoint *ap)
{
@ -396,7 +420,6 @@ finalize (GObject *object)
if (priv->ssid)
g_bytes_unref (priv->ssid);
g_free (priv->bssid);
G_OBJECT_CLASS (nm_access_point_parent_class)->finalize (object);
@ -450,43 +473,32 @@ get_property (GObject *object,
}
}
static void
init_dbus (NMObject *object)
{
NMAccessPointPrivate *priv = NM_ACCESS_POINT_GET_PRIVATE (object);
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 },
{ NM_ACCESS_POINT_FREQUENCY, &priv->frequency },
/* The D-Bus property is HwAddress, but the GObject property is "bssid" */
{ 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 },
{ NM_ACCESS_POINT_LAST_SEEN, &priv->last_seen },
{ NULL },
};
NM_OBJECT_CLASS (nm_access_point_parent_class)->init_dbus (object);
_nm_object_register_properties (object,
NM_DBUS_INTERFACE_ACCESS_POINT,
property_info);
}
const NMLDBusMetaIface _nml_dbus_meta_iface_nm_accesspoint = NML_DBUS_META_IFACE_INIT_PROP (
NM_DBUS_INTERFACE_ACCESS_POINT,
nm_access_point_get_type,
NML_DBUS_META_INTERFACE_PRIO_INSTANTIATE_HIGH,
NML_DBUS_META_IFACE_DBUS_PROPERTIES (
NML_DBUS_META_PROPERTY_INIT_U ("Flags", PROP_FLAGS, NMAccessPoint, _priv.flags ),
NML_DBUS_META_PROPERTY_INIT_U ("Frequency", PROP_FREQUENCY, NMAccessPoint, _priv.frequency ),
NML_DBUS_META_PROPERTY_INIT_FCN ("HwAddress", PROP_BSSID, "s", _notify_update_prop_hw_address ),
NML_DBUS_META_PROPERTY_INIT_I ("LastSeen", PROP_LAST_SEEN, NMAccessPoint, _priv.last_seen ),
NML_DBUS_META_PROPERTY_INIT_U ("MaxBitrate", PROP_MAX_BITRATE, NMAccessPoint, _priv.max_bitrate ),
NML_DBUS_META_PROPERTY_INIT_U ("Mode", PROP_MODE, NMAccessPoint, _priv.mode ),
NML_DBUS_META_PROPERTY_INIT_U ("RsnFlags", PROP_RSN_FLAGS, NMAccessPoint, _priv.rsn_flags ),
NML_DBUS_META_PROPERTY_INIT_AY ("Ssid", PROP_SSID, NMAccessPoint, _priv.ssid ),
NML_DBUS_META_PROPERTY_INIT_Y ("Strength", PROP_STRENGTH, NMAccessPoint, _priv.strength ),
NML_DBUS_META_PROPERTY_INIT_U ("WpaFlags", PROP_WPA_FLAGS, NMAccessPoint, _priv.wpa_flags ),
),
);
static void
nm_access_point_class_init (NMAccessPointClass *ap_class)
{
GObjectClass *object_class = G_OBJECT_CLASS (ap_class);
NMObjectClass *nm_object_class = NM_OBJECT_CLASS (ap_class);
object_class->get_property = get_property;
object_class->finalize = finalize;
nm_object_class->init_dbus = init_dbus;
/**
* NMAccessPoint:flags:
*
@ -620,5 +632,5 @@ nm_access_point_class_init (NMAccessPointClass *ap_class)
G_PARAM_READABLE |
G_PARAM_STATIC_STRINGS);
g_object_class_install_properties (object_class, _PROPERTY_ENUMS_LAST, obj_properties);
_nml_dbus_meta_class_init_with_properties (object_class, &_nml_dbus_meta_iface_nm_accesspoint);
}

View file

@ -21,8 +21,6 @@
#include "nm-ip6-config.h"
#include "nm-remote-connection.h"
#include "introspection/org.freedesktop.NetworkManager.Connection.Active.h"
/*****************************************************************************/
NM_GOBJECT_PROPERTIES_DEFINE (NMActiveConnection,
@ -50,26 +48,34 @@ enum {
LAST_SIGNAL
};
static guint signals[LAST_SIGNAL] = { 0 };
static guint signals[LAST_SIGNAL];
enum {
PROPERTY_O_IDX_CONNECTION,
PROPERTY_O_IDX_MASTER,
PROPERTY_O_IDX_IP4_CONFIG,
PROPERTY_O_IDX_IP6_CONFIG,
PROPERTY_O_IDX_DHCP4_CONFIG,
PROPERTY_O_IDX_DHCP6_CONFIG,
_PROPERTY_O_IDX_NUM,
};
typedef struct _NMActiveConnectionPrivate {
NMRemoteConnection *connection;
NMLDBusPropertyO property_o[_PROPERTY_O_IDX_NUM];
NMLDBusPropertyAO devices;
NMRefString *specific_object_path;
char *id;
char *uuid;
char *type;
char *specific_object_path;
GPtrArray *devices;
NMActiveConnectionState state;
guint state_flags;
gboolean is_default;
NMIPConfig *ip4_config;
NMDhcpConfig *dhcp4_config;
gboolean is_default6;
NMIPConfig *ip6_config;
NMDhcpConfig *dhcp6_config;
gboolean is_vpn;
NMDevice *master;
NMActiveConnectionStateReason reason;
guint32 state;
guint32 state_flags;
bool is_default;
bool is_default6;
bool is_vpn;
guint32 reason;
} NMActiveConnectionPrivate;
G_DEFINE_TYPE (NMActiveConnection, nm_active_connection, NM_TYPE_OBJECT);
@ -92,7 +98,7 @@ nm_active_connection_get_connection (NMActiveConnection *connection)
{
g_return_val_if_fail (NM_IS_ACTIVE_CONNECTION (connection), NULL);
return NM_ACTIVE_CONNECTION_GET_PRIVATE (connection)->connection;
return nml_dbus_property_o_get_obj (&NM_ACTIVE_CONNECTION_GET_PRIVATE (connection)->property_o[PROPERTY_O_IDX_CONNECTION]);
}
/**
@ -166,7 +172,7 @@ nm_active_connection_get_specific_object_path (NMActiveConnection *connection)
{
g_return_val_if_fail (NM_IS_ACTIVE_CONNECTION (connection), NULL);
return NM_ACTIVE_CONNECTION_GET_PRIVATE (connection)->specific_object_path;
return _nml_coerce_property_object_path (NM_ACTIVE_CONNECTION_GET_PRIVATE (connection)->specific_object_path);
}
/**
@ -183,7 +189,7 @@ nm_active_connection_get_devices (NMActiveConnection *connection)
{
g_return_val_if_fail (NM_IS_ACTIVE_CONNECTION (connection), NULL);
return NM_ACTIVE_CONNECTION_GET_PRIVATE (connection)->devices;
return nml_dbus_property_ao_get_objs_as_ptrarray (&NM_ACTIVE_CONNECTION_GET_PRIVATE (connection)->devices);
}
/**
@ -269,7 +275,7 @@ nm_active_connection_get_ip4_config (NMActiveConnection *connection)
{
g_return_val_if_fail (NM_IS_ACTIVE_CONNECTION (connection), NULL);
return NM_ACTIVE_CONNECTION_GET_PRIVATE (connection)->ip4_config;
return nml_dbus_property_o_get_obj (&NM_ACTIVE_CONNECTION_GET_PRIVATE (connection)->property_o[PROPERTY_O_IDX_IP4_CONFIG]);
}
/**
@ -288,7 +294,7 @@ nm_active_connection_get_dhcp4_config (NMActiveConnection *connection)
{
g_return_val_if_fail (NM_IS_ACTIVE_CONNECTION (connection), NULL);
return NM_ACTIVE_CONNECTION_GET_PRIVATE (connection)->dhcp4_config;
return nml_dbus_property_o_get_obj (&NM_ACTIVE_CONNECTION_GET_PRIVATE (connection)->property_o[PROPERTY_O_IDX_DHCP4_CONFIG]);
}
/**
@ -322,7 +328,7 @@ nm_active_connection_get_ip6_config (NMActiveConnection *connection)
{
g_return_val_if_fail (NM_IS_ACTIVE_CONNECTION (connection), NULL);
return NM_ACTIVE_CONNECTION_GET_PRIVATE (connection)->ip6_config;
return nml_dbus_property_o_get_obj (&NM_ACTIVE_CONNECTION_GET_PRIVATE (connection)->property_o[PROPERTY_O_IDX_IP6_CONFIG]);
}
/**
@ -341,7 +347,7 @@ nm_active_connection_get_dhcp6_config (NMActiveConnection *connection)
{
g_return_val_if_fail (NM_IS_ACTIVE_CONNECTION (connection), NULL);
return NM_ACTIVE_CONNECTION_GET_PRIVATE (connection)->dhcp6_config;
return nml_dbus_property_o_get_obj (&NM_ACTIVE_CONNECTION_GET_PRIVATE (connection)->property_o[PROPERTY_O_IDX_DHCP6_CONFIG]);
}
/**
@ -373,9 +379,55 @@ nm_active_connection_get_master (NMActiveConnection *connection)
{
g_return_val_if_fail (NM_IS_ACTIVE_CONNECTION (connection), NULL);
return NM_ACTIVE_CONNECTION_GET_PRIVATE (connection)->master;
return nml_dbus_property_o_get_obj (&NM_ACTIVE_CONNECTION_GET_PRIVATE (connection)->property_o[PROPERTY_O_IDX_MASTER]);
}
/*****************************************************************************/
static void
_notify_event_state_changed (NMClient *client,
NMClientNotifyEventWithPtr *notify_event)
{
gs_unref_object NMActiveConnection *self = notify_event->user_data;
NMActiveConnectionPrivate *priv = NM_ACTIVE_CONNECTION_GET_PRIVATE (self);
/* we expose here the value cache in @priv. In practice, this is the same
* value as we received from the signal. In the unexpected case where they
* differ, the cached value of the current instance would still be more correct. */
g_signal_emit (self,
signals[STATE_CHANGED],
0,
(guint) priv->state,
(guint) priv->reason);
}
void
_nm_active_connection_state_changed_commit (NMActiveConnection *self,
guint32 state,
guint32 reason)
{
NMClient *client;
NMActiveConnectionPrivate *priv = NM_ACTIVE_CONNECTION_GET_PRIVATE (self);
client = _nm_object_get_client (self);
if (priv->state != state) {
priv->state = state;
_nm_client_queue_notify_object (client,
self,
obj_properties[PROP_STATE]);
}
priv->reason = reason;
_nm_client_notify_event_queue_with_ptr (client,
NM_CLIENT_NOTIFY_EVENT_PRIO_GPROP + 1,
_notify_event_state_changed,
g_object_ref (self));
}
/*****************************************************************************/
static void
nm_active_connection_init (NMActiveConnection *self)
{
@ -384,60 +436,6 @@ nm_active_connection_init (NMActiveConnection *self)
priv = G_TYPE_INSTANCE_GET_PRIVATE (self, NM_TYPE_ACTIVE_CONNECTION, NMActiveConnectionPrivate);
self->_priv = priv;
priv->devices = g_ptr_array_new ();
}
static void
state_changed_proxy (NMDBusActiveConnectionProxy *proxy,
NMActiveConnectionState state,
NMActiveConnectionStateReason reason,
gpointer user_data)
{
NMActiveConnection *connection = NM_ACTIVE_CONNECTION (user_data);
NMActiveConnectionPrivate *priv = NM_ACTIVE_CONNECTION_GET_PRIVATE (connection);
priv->state = state;
priv->reason = reason;
g_signal_emit (connection, signals[STATE_CHANGED], 0, state, reason);
_notify (connection, PROP_STATE);
}
static void
constructed (GObject *object)
{
GDBusProxy *proxy;
proxy = _nm_object_get_proxy (NM_OBJECT (object), NM_DBUS_INTERFACE_ACTIVE_CONNECTION);
g_signal_connect (proxy, "state-changed",
G_CALLBACK (state_changed_proxy), object);
g_object_unref (proxy);
G_OBJECT_CLASS (nm_active_connection_parent_class)->constructed (object);
}
static void
dispose (GObject *object)
{
NMActiveConnectionPrivate *priv = NM_ACTIVE_CONNECTION_GET_PRIVATE (object);
GDBusProxy *proxy;
g_clear_pointer (&priv->devices, g_ptr_array_unref);
g_clear_object (&priv->connection);
g_clear_object (&priv->master);
g_clear_object (&priv->ip4_config);
g_clear_object (&priv->dhcp4_config);
g_clear_object (&priv->ip6_config);
g_clear_object (&priv->dhcp6_config);
proxy = _nm_object_get_proxy (NM_OBJECT (object), NM_DBUS_INTERFACE_ACTIVE_CONNECTION);
if (proxy) {
g_signal_handlers_disconnect_by_data (proxy, object);
g_object_unref (proxy);
}
G_OBJECT_CLASS (nm_active_connection_parent_class)->dispose (object);
}
static void
@ -448,7 +446,7 @@ finalize (GObject *object)
g_free (priv->id);
g_free (priv->uuid);
g_free (priv->type);
g_free (priv->specific_object_path);
nm_ref_string_unref (priv->specific_object_path);
G_OBJECT_CLASS (nm_active_connection_parent_class)->finalize (object);
}
@ -516,73 +514,46 @@ get_property (GObject *object,
}
}
static gboolean
demarshal_specific_object_path (NMObject *object, GParamSpec *pspec, GVariant *value, gpointer field)
{
const char *v;
char **param = (char **) field;
/* We have to demarshal this manually, because the D-Bus property name
* ("SpecificObject"), doesn't match the object property name
* ("specific-object-path"). (The name "specific-object" is reserved for
* future use as an NMObject-valued property.)
*/
if (!g_variant_is_of_type (value, G_VARIANT_TYPE_OBJECT_PATH))
return FALSE;
v = g_variant_get_string (value, NULL);
g_free (*param);
*param = nm_streq0 (v, "/") ? NULL : g_strdup (v);
return TRUE;
}
const NMLDBusMetaIface _nml_dbus_meta_iface_nm_connection_active = NML_DBUS_META_IFACE_INIT_PROP (
NM_DBUS_INTERFACE_ACTIVE_CONNECTION,
nm_active_connection_get_type,
NML_DBUS_META_INTERFACE_PRIO_INSTANTIATE_LOW,
NML_DBUS_META_IFACE_DBUS_PROPERTIES (
NML_DBUS_META_PROPERTY_INIT_O_PROP ("Connection", PROP_CONNECTION, NMActiveConnectionPrivate, property_o[PROPERTY_O_IDX_CONNECTION], nm_remote_connection_get_type ),
NML_DBUS_META_PROPERTY_INIT_B ("Default", PROP_DEFAULT, NMActiveConnectionPrivate, is_default ),
NML_DBUS_META_PROPERTY_INIT_B ("Default6", PROP_DEFAULT6, NMActiveConnectionPrivate, is_default6 ),
NML_DBUS_META_PROPERTY_INIT_AO_PROP ("Devices", PROP_DEVICES, NMActiveConnectionPrivate, devices, nm_device_get_type ),
NML_DBUS_META_PROPERTY_INIT_O_PROP ("Dhcp4Config", PROP_DHCP4_CONFIG, NMActiveConnectionPrivate, property_o[PROPERTY_O_IDX_DHCP4_CONFIG], nm_dhcp4_config_get_type ),
NML_DBUS_META_PROPERTY_INIT_O_PROP ("Dhcp6Config", PROP_DHCP6_CONFIG, NMActiveConnectionPrivate, property_o[PROPERTY_O_IDX_DHCP6_CONFIG], nm_dhcp6_config_get_type ),
NML_DBUS_META_PROPERTY_INIT_S ("Id", PROP_ID, NMActiveConnectionPrivate, id ),
NML_DBUS_META_PROPERTY_INIT_O_PROP ("Ip4Config", PROP_IP4_CONFIG, NMActiveConnectionPrivate, property_o[PROPERTY_O_IDX_IP4_CONFIG], nm_ip4_config_get_type ),
NML_DBUS_META_PROPERTY_INIT_O_PROP ("Ip6Config", PROP_IP6_CONFIG, NMActiveConnectionPrivate, property_o[PROPERTY_O_IDX_IP6_CONFIG], nm_ip6_config_get_type ),
NML_DBUS_META_PROPERTY_INIT_O_PROP ("Master", PROP_MASTER, NMActiveConnectionPrivate, property_o[PROPERTY_O_IDX_MASTER], nm_device_get_type ),
NML_DBUS_META_PROPERTY_INIT_O ("SpecificObject", PROP_SPECIFIC_OBJECT_PATH, NMActiveConnectionPrivate, specific_object_path ),
NML_DBUS_META_PROPERTY_INIT_U ("State", PROP_STATE, NMActiveConnectionPrivate, state ),
NML_DBUS_META_PROPERTY_INIT_U ("StateFlags", PROP_STATE_FLAGS, NMActiveConnectionPrivate, state_flags ),
NML_DBUS_META_PROPERTY_INIT_S ("Type", PROP_TYPE, NMActiveConnectionPrivate, type ),
NML_DBUS_META_PROPERTY_INIT_S ("Uuid", PROP_UUID, NMActiveConnectionPrivate, uuid ),
NML_DBUS_META_PROPERTY_INIT_B ("Vpn", PROP_VPN, NMActiveConnectionPrivate, is_vpn ),
),
.base_struct_offset = G_STRUCT_OFFSET (NMActiveConnection, _priv),
);
static void
init_dbus (NMObject *object)
nm_active_connection_class_init (NMActiveConnectionClass *klass)
{
NMActiveConnectionPrivate *priv = NM_ACTIVE_CONNECTION_GET_PRIVATE (object);
const NMPropertiesInfo property_info[] = {
{ NM_ACTIVE_CONNECTION_CONNECTION, &priv->connection, NULL, NM_TYPE_REMOTE_CONNECTION },
{ NM_ACTIVE_CONNECTION_ID, &priv->id },
{ NM_ACTIVE_CONNECTION_UUID, &priv->uuid },
{ NM_ACTIVE_CONNECTION_TYPE, &priv->type },
{ "specific-object", &priv->specific_object_path, demarshal_specific_object_path },
{ NM_ACTIVE_CONNECTION_DEVICES, &priv->devices, NULL, NM_TYPE_DEVICE },
{ NM_ACTIVE_CONNECTION_STATE, &priv->state },
{ NM_ACTIVE_CONNECTION_STATE_FLAGS, &priv->state_flags },
{ NM_ACTIVE_CONNECTION_DEFAULT, &priv->is_default },
{ NM_ACTIVE_CONNECTION_IP4_CONFIG, &priv->ip4_config, NULL, NM_TYPE_IP4_CONFIG },
{ NM_ACTIVE_CONNECTION_DHCP4_CONFIG, &priv->dhcp4_config, NULL, NM_TYPE_DHCP4_CONFIG },
{ NM_ACTIVE_CONNECTION_DEFAULT6, &priv->is_default6 },
{ NM_ACTIVE_CONNECTION_IP6_CONFIG, &priv->ip6_config, NULL, NM_TYPE_IP6_CONFIG },
{ NM_ACTIVE_CONNECTION_DHCP6_CONFIG, &priv->dhcp6_config, NULL, NM_TYPE_DHCP6_CONFIG },
{ NM_ACTIVE_CONNECTION_VPN, &priv->is_vpn },
{ NM_ACTIVE_CONNECTION_MASTER, &priv->master, NULL, NM_TYPE_DEVICE },
GObjectClass *object_class = G_OBJECT_CLASS (klass);
NMObjectClass *nm_object_class = NM_OBJECT_CLASS (klass);
{ NULL },
};
NM_OBJECT_CLASS (nm_active_connection_parent_class)->init_dbus (object);
_nm_object_register_properties (object,
NM_DBUS_INTERFACE_ACTIVE_CONNECTION,
property_info);
}
static void
nm_active_connection_class_init (NMActiveConnectionClass *ap_class)
{
GObjectClass *object_class = G_OBJECT_CLASS (ap_class);
NMObjectClass *nm_object_class = NM_OBJECT_CLASS (ap_class);
g_type_class_add_private (ap_class, sizeof (NMActiveConnectionPrivate));
g_type_class_add_private (klass, sizeof (NMActiveConnectionPrivate));
object_class->get_property = get_property;
object_class->constructed = constructed;
object_class->dispose = dispose;
object_class->finalize = finalize;
nm_object_class->init_dbus = init_dbus;
_NM_OBJECT_CLASS_INIT_PRIV_PTR_INDIRECT (nm_object_class, NMActiveConnection);
_NM_OBJECT_CLASS_INIT_PROPERTY_O_FIELDS_N (nm_object_class, NMActiveConnectionPrivate, property_o);
_NM_OBJECT_CLASS_INIT_PROPERTY_AO_FIELDS_1 (nm_object_class, NMActiveConnectionPrivate, devices);
/**
* NMActiveConnection:connection:
@ -765,7 +736,13 @@ nm_active_connection_class_init (NMActiveConnectionClass *ap_class)
G_PARAM_READABLE |
G_PARAM_STATIC_STRINGS);
g_object_class_install_properties (object_class, _PROPERTY_ENUMS_LAST, obj_properties);
_nml_dbus_meta_class_init_with_properties (object_class, &_nml_dbus_meta_iface_nm_connection_active);
/* TODO: the state reason should also be exposed as a property in libnm's NMActiveConnection,
* like done for NMDevice's state reason. */
/* TODO: the D-Bus API should also expose the state-reason as a property instead of
* a "StateChanged" signal. Like done for Device's "StateReason". */
/**
* NMActiveConnection::state-changed:

View file

@ -6,6 +6,7 @@
#include "nm-default.h"
#include "nm-checkpoint.h"
#include "nm-core-internal.h"
#include "nm-dbus-interface.h"
#include "nm-device.h"
@ -20,7 +21,7 @@ NM_GOBJECT_PROPERTIES_DEFINE_BASE (
);
typedef struct {
GPtrArray *devices;
NMLDBusPropertyAO devices;
gint64 created;
guint32 rollback_timeout;
} NMCheckpointPrivate;
@ -55,7 +56,7 @@ nm_checkpoint_get_devices (NMCheckpoint *checkpoint)
{
g_return_val_if_fail (NM_IS_CHECKPOINT (checkpoint), NULL);
return NM_CHECKPOINT_GET_PRIVATE (checkpoint)->devices;
return nml_dbus_property_ao_get_objs_as_ptrarray (&NM_CHECKPOINT_GET_PRIVATE (checkpoint)->devices);
}
/**
@ -104,16 +105,6 @@ nm_checkpoint_init (NMCheckpoint *checkpoint)
{
}
static void
finalize (GObject *object)
{
NMCheckpointPrivate *priv = NM_CHECKPOINT_GET_PRIVATE (NM_CHECKPOINT (object));
g_ptr_array_unref (priv->devices);
G_OBJECT_CLASS (nm_checkpoint_parent_class)->finalize (object);
}
static void
get_property (GObject *object,
guint prop_id,
@ -125,7 +116,7 @@ get_property (GObject *object,
switch (prop_id) {
case PROP_DEVICES:
g_value_take_boxed (value, _nm_utils_copy_object_array (priv->devices));
g_value_take_boxed (value, _nm_utils_copy_object_array (nm_checkpoint_get_devices (checkpoint)));
break;
case PROP_CREATED:
g_value_set_int64 (value, priv->created);
@ -139,34 +130,28 @@ get_property (GObject *object,
}
}
static void
init_dbus (NMObject *object)
{
NMCheckpointPrivate *priv = NM_CHECKPOINT_GET_PRIVATE (NM_CHECKPOINT (object));
const NMPropertiesInfo property_info[] = {
{ NM_CHECKPOINT_DEVICES, &priv->devices, NULL, NM_TYPE_DEVICE },
{ NM_CHECKPOINT_CREATED, &priv->created },
{ NM_CHECKPOINT_ROLLBACK_TIMEOUT, &priv->rollback_timeout },
{ NULL },
};
NM_OBJECT_CLASS (nm_checkpoint_parent_class)->init_dbus (object);
_nm_object_register_properties (object,
NM_DBUS_INTERFACE_CHECKPOINT,
property_info);
}
const NMLDBusMetaIface _nml_dbus_meta_iface_nm_checkpoint = NML_DBUS_META_IFACE_INIT_PROP (
NM_DBUS_INTERFACE_CHECKPOINT,
nm_checkpoint_get_type,
NML_DBUS_META_INTERFACE_PRIO_INSTANTIATE_HIGH,
NML_DBUS_META_IFACE_DBUS_PROPERTIES (
NML_DBUS_META_PROPERTY_INIT_X ("Created", PROP_CREATED, NMCheckpoint, _priv.created ),
NML_DBUS_META_PROPERTY_INIT_AO_PROP ("Devices", PROP_DEVICES, NMCheckpoint, _priv.devices, nm_device_get_type, .is_always_ready = TRUE ),
NML_DBUS_META_PROPERTY_INIT_U ("RollbackTimeout", PROP_ROLLBACK_TIMEOUT, NMCheckpoint, _priv.rollback_timeout ),
),
);
static void
nm_checkpoint_class_init (NMCheckpointClass *checkpoint_class)
nm_checkpoint_class_init (NMCheckpointClass *klass)
{
GObjectClass *object_class = G_OBJECT_CLASS (checkpoint_class);
NMObjectClass *nm_object_class = NM_OBJECT_CLASS (checkpoint_class);
GObjectClass *object_class = G_OBJECT_CLASS (klass);
NMObjectClass *nm_object_class = NM_OBJECT_CLASS (klass);
object_class->get_property = get_property;
object_class->finalize = finalize;
nm_object_class->init_dbus = init_dbus;
_NM_OBJECT_CLASS_INIT_PRIV_PTR_DIRECT (nm_object_class, NMCheckpoint);
_NM_OBJECT_CLASS_INIT_PROPERTY_AO_FIELDS_1 (nm_object_class, NMCheckpointPrivate, devices);
/**
* NMCheckpoint:devices: (type GPtrArray(NMDevice))
@ -207,5 +192,5 @@ nm_checkpoint_class_init (NMCheckpointClass *checkpoint_class)
G_PARAM_READABLE |
G_PARAM_STATIC_STRINGS);
g_object_class_install_properties (object_class, _PROPERTY_ENUMS_LAST, obj_properties);
_nml_dbus_meta_class_init_with_properties (object_class, &_nml_dbus_meta_iface_nm_checkpoint);
}

File diff suppressed because it is too large Load diff

View file

@ -45,6 +45,7 @@ _NM_DEPRECATED_SYNC_WRITABLE_PROPERTY
#define NM_CLIENT_ACTIVE_CONNECTIONS "active-connections"
#define NM_CLIENT_CONNECTIVITY "connectivity"
#define NM_CLIENT_CONNECTIVITY_CHECK_URI "connectivity-check-uri"
#define NM_CLIENT_CONNECTIVITY_CHECK_AVAILABLE "connectivity-check-available"
_NM_DEPRECATED_SYNC_WRITABLE_PROPERTY
@ -224,6 +225,9 @@ NMState nm_client_get_state (NMClient *client);
gboolean nm_client_get_startup (NMClient *client);
gboolean nm_client_get_nm_running (NMClient *client);
NM_AVAILABLE_IN_1_22
NMMetered nm_client_get_metered (NMClient *client);
gboolean nm_client_networking_get_enabled (NMClient *client);
_NM_DEPRECATED_SYNC_METHOD

View file

@ -27,65 +27,6 @@ _nm_dbus_bus_type (void)
return v;
}
/* D-Bus has an upper limit on number of Match rules and it's rather easy
* to hit as the proxy likes to add one for each object. Let's remove the Match
* rule the proxy added and ensure a less granular rule is present instead.
*
* Also, don't do this immediately since it has a performance penalty.
* Still better than losing the signals altogether.
*
* Ideally, we should be able to tell glib not to hook its rules:
* https://bugzilla.gnome.org/show_bug.cgi?id=758749
*/
void
_nm_dbus_proxy_replace_match (GDBusProxy *proxy)
{
GDBusConnection *connection = g_dbus_proxy_get_connection (proxy);
static unsigned match_counter = 1024;
char *match;
if (match_counter == 1) {
/* If we hit the low matches watermark, install a
* less granular one. */
g_dbus_connection_call (connection,
"org.freedesktop.DBus",
"/org/freedesktop/DBus",
"org.freedesktop.DBus",
"AddMatch",
g_variant_new ("(s)", "type='signal',sender='" NM_DBUS_SERVICE "'"),
NULL,
G_DBUS_CALL_FLAGS_NONE,
-1,
NULL,
NULL,
NULL);
}
if (match_counter)
match_counter--;
if (match_counter)
return;
/* Remove what this proxy added. */
match = g_strdup_printf ("type='signal',sender='" NM_DBUS_SERVICE "',"
"interface='%s',path='%s'",
g_dbus_proxy_get_interface_name (proxy),
g_dbus_proxy_get_object_path (proxy));
g_dbus_connection_call (connection,
"org.freedesktop.DBus",
"/org/freedesktop/DBus",
"org.freedesktop.DBus",
"RemoveMatch",
g_variant_new ("(s)", match),
NULL,
G_DBUS_CALL_FLAGS_NONE,
-1,
NULL,
NULL,
NULL);
g_free (match);
}
/* Binds the properties on a generated server-side GDBus object to the
* corresponding properties on the public object.
*/

View file

@ -16,8 +16,6 @@
GBusType _nm_dbus_bus_type (void);
void _nm_dbus_proxy_replace_match (GDBusProxy *proxy);
void _nm_dbus_bind_properties (gpointer object,
gpointer skeleton);

View file

@ -17,7 +17,7 @@ NM_GOBJECT_PROPERTIES_DEFINE_BASE (
);
typedef struct {
NMDevice *parent;
NMLDBusPropertyO parent;
char *hw_address;
} NMDevice6LowpanPrivate;
@ -49,7 +49,7 @@ nm_device_6lowpan_get_parent (NMDevice6Lowpan *device)
{
g_return_val_if_fail (NM_IS_DEVICE_6LOWPAN (device), NULL);
return NM_DEVICE_6LOWPAN_GET_PRIVATE (device)->parent;
return nml_dbus_property_o_get_obj (&NM_DEVICE_6LOWPAN_GET_PRIVATE (device)->parent);
}
/**
@ -77,7 +77,7 @@ get_hw_address (NMDevice *device)
return nm_device_6lowpan_get_hw_address (NM_DEVICE_6LOWPAN (device));
}
/***********************************************************/
/*****************************************************************************/
static void
nm_device_6lowpan_init (NMDevice6Lowpan *device)
@ -85,31 +85,13 @@ nm_device_6lowpan_init (NMDevice6Lowpan *device)
}
static void
init_dbus (NMObject *object)
{
NMDevice6LowpanPrivate *priv = NM_DEVICE_6LOWPAN_GET_PRIVATE (object);
const NMPropertiesInfo property_info[] = {
{ NM_DEVICE_6LOWPAN_PARENT, &priv->parent, NULL, NM_TYPE_DEVICE },
{ NM_DEVICE_6LOWPAN_HW_ADDRESS, &priv->hw_address },
{ NULL },
};
NM_OBJECT_CLASS (nm_device_6lowpan_parent_class)->init_dbus (object);
_nm_object_register_properties (object,
NM_DBUS_INTERFACE_DEVICE_6LOWPAN,
property_info);
}
static void
finalize (GObject *object)
dispose (GObject *object)
{
NMDevice6LowpanPrivate *priv = NM_DEVICE_6LOWPAN_GET_PRIVATE (object);
g_free (priv->hw_address);
g_clear_object (&priv->parent);
G_OBJECT_CLASS (nm_device_6lowpan_parent_class)->dispose (object);
G_OBJECT_CLASS (nm_device_6lowpan_parent_class)->finalize (object);
nm_clear_g_free (&priv->hw_address);
}
static void
@ -133,6 +115,16 @@ get_property (GObject *object,
}
}
const NMLDBusMetaIface _nml_dbus_meta_iface_nm_device_lowpan = NML_DBUS_META_IFACE_INIT_PROP (
NM_DBUS_INTERFACE_DEVICE_6LOWPAN,
nm_device_6lowpan_get_type,
NML_DBUS_META_INTERFACE_PRIO_INSTANTIATE_HIGH,
NML_DBUS_META_IFACE_DBUS_PROPERTIES (
NML_DBUS_META_PROPERTY_INIT_S ("HwAddress", PROP_HW_ADDRESS, NMDevice6Lowpan, _priv.hw_address ),
NML_DBUS_META_PROPERTY_INIT_O_PROP ("Parent", PROP_PARENT, NMDevice6Lowpan, _priv.parent, nm_device_get_type ),
),
);
static void
nm_device_6lowpan_class_init (NMDevice6LowpanClass *klass)
{
@ -141,9 +133,11 @@ nm_device_6lowpan_class_init (NMDevice6LowpanClass *klass)
NMDeviceClass *device_class = NM_DEVICE_CLASS (klass);
object_class->get_property = get_property;
object_class->finalize = finalize;
object_class->dispose = dispose;
nm_object_class->init_dbus = init_dbus;
_NM_OBJECT_CLASS_INIT_PRIV_PTR_DIRECT (nm_object_class, NMDevice6Lowpan);
_NM_OBJECT_CLASS_INIT_PROPERTY_O_FIELDS_1 (nm_object_class, NMDevice6LowpanPrivate, parent);
device_class->get_hw_address = get_hw_address;
@ -173,5 +167,5 @@ nm_device_6lowpan_class_init (NMDevice6LowpanClass *klass)
G_PARAM_READABLE |
G_PARAM_STATIC_STRINGS);
g_object_class_install_properties (object_class, _PROPERTY_ENUMS_LAST, obj_properties);
_nml_dbus_meta_class_init_with_properties (object_class, &_nml_dbus_meta_iface_nm_device_lowpan);
}

View file

@ -19,7 +19,7 @@ NM_GOBJECT_PROPERTIES_DEFINE_BASE (
);
typedef struct {
gboolean carrier;
bool carrier;
} NMDeviceAdslPrivate;
struct _NMDeviceAdsl {
@ -81,22 +81,6 @@ nm_device_adsl_init (NMDeviceAdsl *device)
{
}
static void
init_dbus (NMObject *object)
{
NMDeviceAdslPrivate *priv = NM_DEVICE_ADSL_GET_PRIVATE (object);
const NMPropertiesInfo property_info[] = {
{ NM_DEVICE_ADSL_CARRIER, &priv->carrier },
{ NULL },
};
NM_OBJECT_CLASS (nm_device_adsl_parent_class)->init_dbus (object);
_nm_object_register_properties (object,
NM_DBUS_INTERFACE_DEVICE_ADSL,
property_info);
}
static void
get_property (GObject *object,
guint prop_id,
@ -115,17 +99,23 @@ get_property (GObject *object,
}
}
const NMLDBusMetaIface _nml_dbus_meta_iface_nm_device_adsl = NML_DBUS_META_IFACE_INIT_PROP (
NM_DBUS_INTERFACE_DEVICE_ADSL,
nm_device_adsl_get_type,
NML_DBUS_META_INTERFACE_PRIO_INSTANTIATE_HIGH,
NML_DBUS_META_IFACE_DBUS_PROPERTIES (
NML_DBUS_META_PROPERTY_INIT_B ("Carrier", PROP_CARRIER, NMDeviceAdsl, _priv.carrier),
),
);
static void
nm_device_adsl_class_init (NMDeviceAdslClass *adsl_class)
{
GObjectClass *object_class = G_OBJECT_CLASS (adsl_class);
NMObjectClass *nm_object_class = NM_OBJECT_CLASS (adsl_class);
NMDeviceClass *device_class = NM_DEVICE_CLASS (adsl_class);
object_class->get_property = get_property;
nm_object_class->init_dbus = init_dbus;
device_class->connection_compatible = connection_compatible;
device_class->get_setting_type = get_setting_type;
@ -140,5 +130,5 @@ nm_device_adsl_class_init (NMDeviceAdslClass *adsl_class)
G_PARAM_READABLE |
G_PARAM_STATIC_STRINGS);
g_object_class_install_properties (object_class, _PROPERTY_ENUMS_LAST, obj_properties);
_nml_dbus_meta_class_init_with_properties (object_class, &_nml_dbus_meta_iface_nm_device_adsl);
}

View file

@ -22,9 +22,9 @@ NM_GOBJECT_PROPERTIES_DEFINE_BASE (
);
typedef struct {
NMLDBusPropertyAO slaves;
char *hw_address;
gboolean carrier;
GPtrArray *slaves;
bool carrier;
} NMDeviceBondPrivate;
struct _NMDeviceBond {
@ -90,7 +90,7 @@ nm_device_bond_get_slaves (NMDeviceBond *device)
{
g_return_val_if_fail (NM_IS_DEVICE_BOND (device), FALSE);
return NM_DEVICE_BOND_GET_PRIVATE (device)->slaves;
return nml_dbus_property_ao_get_objs_as_ptrarray (&NM_DEVICE_BOND_GET_PRIVATE (device)->slaves);
}
static gboolean
@ -127,37 +127,6 @@ get_hw_address (NMDevice *device)
static void
nm_device_bond_init (NMDeviceBond *device)
{
NMDeviceBondPrivate *priv = NM_DEVICE_BOND_GET_PRIVATE (device);
priv->slaves = g_ptr_array_new ();
}
static void
init_dbus (NMObject *object)
{
NMDeviceBondPrivate *priv = NM_DEVICE_BOND_GET_PRIVATE (object);
const NMPropertiesInfo property_info[] = {
{ NM_DEVICE_BOND_HW_ADDRESS, &priv->hw_address },
{ NM_DEVICE_BOND_CARRIER, &priv->carrier },
{ NM_DEVICE_BOND_SLAVES, &priv->slaves, NULL, NM_TYPE_DEVICE },
{ NULL },
};
NM_OBJECT_CLASS (nm_device_bond_parent_class)->init_dbus (object);
_nm_object_register_properties (object,
NM_DBUS_INTERFACE_DEVICE_BOND,
property_info);
}
static void
dispose (GObject *object)
{
NMDeviceBondPrivate *priv = NM_DEVICE_BOND_GET_PRIVATE (object);
g_clear_pointer (&priv->slaves, g_ptr_array_unref);
G_OBJECT_CLASS (nm_device_bond_parent_class)->dispose (object);
}
static void
@ -194,18 +163,30 @@ get_property (GObject *object,
}
}
const NMLDBusMetaIface _nml_dbus_meta_iface_nm_device_bond = NML_DBUS_META_IFACE_INIT_PROP (
NM_DBUS_INTERFACE_DEVICE_BOND,
nm_device_bond_get_type,
NML_DBUS_META_INTERFACE_PRIO_INSTANTIATE_HIGH,
NML_DBUS_META_IFACE_DBUS_PROPERTIES (
NML_DBUS_META_PROPERTY_INIT_B ("Carrier", PROP_CARRIER, NMDeviceBond, _priv.carrier ),
NML_DBUS_META_PROPERTY_INIT_S ("HwAddress", PROP_HW_ADDRESS, NMDeviceBond, _priv.hw_address ),
NML_DBUS_META_PROPERTY_INIT_AO_PROP ("Slaves", PROP_SLAVES, NMDeviceBond, _priv.slaves, nm_device_get_type ),
),
);
static void
nm_device_bond_class_init (NMDeviceBondClass *bond_class)
nm_device_bond_class_init (NMDeviceBondClass *klass)
{
GObjectClass *object_class = G_OBJECT_CLASS (bond_class);
NMObjectClass *nm_object_class = NM_OBJECT_CLASS (bond_class);
NMDeviceClass *device_class = NM_DEVICE_CLASS (bond_class);
GObjectClass *object_class = G_OBJECT_CLASS (klass);
NMObjectClass *nm_object_class = NM_OBJECT_CLASS (klass);
NMDeviceClass *device_class = NM_DEVICE_CLASS (klass);
object_class->get_property = get_property;
object_class->dispose = dispose;
object_class->finalize = finalize;
nm_object_class->init_dbus = init_dbus;
_NM_OBJECT_CLASS_INIT_PRIV_PTR_DIRECT (nm_object_class, NMDeviceBond);
_NM_OBJECT_CLASS_INIT_PROPERTY_AO_FIELDS_1 (nm_object_class, NMDeviceBondPrivate, slaves);
device_class->connection_compatible = connection_compatible;
device_class->get_setting_type = get_setting_type;
@ -244,5 +225,5 @@ nm_device_bond_class_init (NMDeviceBondClass *bond_class)
G_PARAM_READABLE |
G_PARAM_STATIC_STRINGS);
g_object_class_install_properties (object_class, _PROPERTY_ENUMS_LAST, obj_properties);
_nml_dbus_meta_class_init_with_properties (object_class, &_nml_dbus_meta_iface_nm_device_bond);
}

View file

@ -22,9 +22,9 @@ NM_GOBJECT_PROPERTIES_DEFINE_BASE (
);
typedef struct {
NMLDBusPropertyAO slaves;
char *hw_address;
gboolean carrier;
GPtrArray *slaves;
bool carrier;
} NMDeviceBridgePrivate;
struct _NMDeviceBridge {
@ -90,7 +90,7 @@ nm_device_bridge_get_slaves (NMDeviceBridge *device)
{
g_return_val_if_fail (NM_IS_DEVICE_BRIDGE (device), FALSE);
return NM_DEVICE_BRIDGE_GET_PRIVATE (device)->slaves;
return nml_dbus_property_ao_get_objs_as_ptrarray (&NM_DEVICE_BRIDGE_GET_PRIVATE (device)->slaves);
}
static gboolean
@ -132,37 +132,6 @@ get_hw_address (NMDevice *device)
static void
nm_device_bridge_init (NMDeviceBridge *device)
{
NMDeviceBridgePrivate *priv = NM_DEVICE_BRIDGE_GET_PRIVATE (device);
priv->slaves = g_ptr_array_new ();
}
static void
init_dbus (NMObject *object)
{
NMDeviceBridgePrivate *priv = NM_DEVICE_BRIDGE_GET_PRIVATE (object);
const NMPropertiesInfo property_info[] = {
{ NM_DEVICE_BRIDGE_HW_ADDRESS, &priv->hw_address },
{ NM_DEVICE_BRIDGE_CARRIER, &priv->carrier },
{ NM_DEVICE_BRIDGE_SLAVES, &priv->slaves, NULL, NM_TYPE_DEVICE },
{ NULL },
};
NM_OBJECT_CLASS (nm_device_bridge_parent_class)->init_dbus (object);
_nm_object_register_properties (object,
NM_DBUS_INTERFACE_DEVICE_BRIDGE,
property_info);
}
static void
dispose (GObject *object)
{
NMDeviceBridgePrivate *priv = NM_DEVICE_BRIDGE_GET_PRIVATE (object);
g_clear_pointer (&priv->slaves, g_ptr_array_unref);
G_OBJECT_CLASS (nm_device_bridge_parent_class)->dispose (object);
}
static void
@ -199,18 +168,30 @@ get_property (GObject *object,
}
}
static void
nm_device_bridge_class_init (NMDeviceBridgeClass *bridge_class)
{
GObjectClass *object_class = G_OBJECT_CLASS (bridge_class);
NMObjectClass *nm_object_class = NM_OBJECT_CLASS (bridge_class);
NMDeviceClass *device_class = NM_DEVICE_CLASS (bridge_class);
const NMLDBusMetaIface _nml_dbus_meta_iface_nm_device_bridge = NML_DBUS_META_IFACE_INIT_PROP (
NM_DBUS_INTERFACE_DEVICE_BRIDGE,
nm_device_bridge_get_type,
NML_DBUS_META_INTERFACE_PRIO_INSTANTIATE_HIGH,
NML_DBUS_META_IFACE_DBUS_PROPERTIES (
NML_DBUS_META_PROPERTY_INIT_B ("Carrier", PROP_CARRIER, NMDeviceBridge, _priv.carrier ),
NML_DBUS_META_PROPERTY_INIT_S ("HwAddress", PROP_HW_ADDRESS, NMDeviceBridge, _priv.hw_address ),
NML_DBUS_META_PROPERTY_INIT_AO_PROP ("Slaves", PROP_SLAVES, NMDeviceBridge, _priv.slaves, nm_device_get_type ),
),
);
static void
nm_device_bridge_class_init (NMDeviceBridgeClass *klass)
{
GObjectClass *object_class = G_OBJECT_CLASS (klass);
NMObjectClass *nm_object_class = NM_OBJECT_CLASS (klass);
NMDeviceClass *device_class = NM_DEVICE_CLASS (klass);
object_class->dispose = dispose;
object_class->finalize = finalize;
object_class->get_property = get_property;
nm_object_class->init_dbus = init_dbus;
_NM_OBJECT_CLASS_INIT_PRIV_PTR_DIRECT (nm_object_class, NMDeviceBridge);
_NM_OBJECT_CLASS_INIT_PROPERTY_AO_FIELDS_1 (nm_object_class, NMDeviceBridgePrivate, slaves);
device_class->connection_compatible = connection_compatible;
device_class->get_setting_type = get_setting_type;
@ -249,5 +230,5 @@ nm_device_bridge_class_init (NMDeviceBridgeClass *bridge_class)
G_PARAM_READABLE |
G_PARAM_STATIC_STRINGS);
g_object_class_install_properties (object_class, _PROPERTY_ENUMS_LAST, obj_properties);
_nml_dbus_meta_class_init_with_properties (object_class, &_nml_dbus_meta_iface_nm_device_bridge);
}

View file

@ -183,24 +183,6 @@ nm_device_bt_init (NMDeviceBt *device)
{
}
static void
init_dbus (NMObject *object)
{
NMDeviceBtPrivate *priv = NM_DEVICE_BT_GET_PRIVATE (object);
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_CLASS (nm_device_bt_parent_class)->init_dbus (object);
_nm_object_register_properties (object,
NM_DBUS_INTERFACE_DEVICE_BLUETOOTH,
property_info);
}
static void
finalize (GObject *object)
{
@ -236,18 +218,26 @@ get_property (GObject *object,
}
}
const NMLDBusMetaIface _nml_dbus_meta_iface_nm_device_bluetooth = NML_DBUS_META_IFACE_INIT_PROP (
NM_DBUS_INTERFACE_DEVICE_BLUETOOTH,
nm_device_bt_get_type,
NML_DBUS_META_INTERFACE_PRIO_INSTANTIATE_HIGH,
NML_DBUS_META_IFACE_DBUS_PROPERTIES (
NML_DBUS_META_PROPERTY_INIT_U ("BtCapabilities", PROP_BT_CAPABILITIES, NMDeviceBt, _priv.bt_capabilities ),
NML_DBUS_META_PROPERTY_INIT_S ("HwAddress", PROP_HW_ADDRESS, NMDeviceBt, _priv.hw_address ),
NML_DBUS_META_PROPERTY_INIT_S ("Name", PROP_NAME, NMDeviceBt, _priv.name ),
),
);
static void
nm_device_bt_class_init (NMDeviceBtClass *bt_class)
{
GObjectClass *object_class = G_OBJECT_CLASS (bt_class);
NMObjectClass *nm_object_class = NM_OBJECT_CLASS (bt_class);
NMDeviceClass *device_class = NM_DEVICE_CLASS (bt_class);
object_class->get_property = get_property;
object_class->finalize = finalize;
nm_object_class->init_dbus = init_dbus;
device_class->connection_compatible = connection_compatible;
device_class->get_setting_type = get_setting_type;
device_class->get_hw_address = get_hw_address;
@ -286,5 +276,5 @@ nm_device_bt_class_init (NMDeviceBtClass *bt_class)
G_PARAM_READABLE |
G_PARAM_STATIC_STRINGS);
g_object_class_install_properties (object_class, _PROPERTY_ENUMS_LAST, obj_properties);
_nml_dbus_meta_class_init_with_properties (object_class, &_nml_dbus_meta_iface_nm_device_bluetooth);
}

View file

@ -99,29 +99,13 @@ nm_device_dummy_init (NMDeviceDummy *device)
}
static void
init_dbus (NMObject *object)
{
NMDeviceDummyPrivate *priv = NM_DEVICE_DUMMY_GET_PRIVATE (object);
const NMPropertiesInfo property_info[] = {
{ NM_DEVICE_DUMMY_HW_ADDRESS, &priv->hw_address },
{ NULL },
};
NM_OBJECT_CLASS (nm_device_dummy_parent_class)->init_dbus (object);
_nm_object_register_properties (object,
NM_DBUS_INTERFACE_DEVICE_DUMMY,
property_info);
}
static void
dispose (GObject *object)
finalize (GObject *object)
{
NMDeviceDummyPrivate *priv = NM_DEVICE_DUMMY_GET_PRIVATE (object);
g_clear_pointer (&priv->hw_address, g_free);
g_free (priv->hw_address);
G_OBJECT_CLASS (nm_device_dummy_parent_class)->dispose (object);
G_OBJECT_CLASS (nm_device_dummy_parent_class)->finalize (object);
}
static void
@ -142,17 +126,23 @@ get_property (GObject *object,
}
}
const NMLDBusMetaIface _nml_dbus_meta_iface_nm_device_dummy = NML_DBUS_META_IFACE_INIT_PROP (
NM_DBUS_INTERFACE_DEVICE_DUMMY,
nm_device_dummy_get_type,
NML_DBUS_META_INTERFACE_PRIO_INSTANTIATE_HIGH,
NML_DBUS_META_IFACE_DBUS_PROPERTIES (
NML_DBUS_META_PROPERTY_INIT_S ("HwAddress", PROP_HW_ADDRESS, NMDeviceDummy, _priv.hw_address ),
),
);
static void
nm_device_dummy_class_init (NMDeviceDummyClass *dummy_class)
{
GObjectClass *object_class = G_OBJECT_CLASS (dummy_class);
NMObjectClass *nm_object_class = NM_OBJECT_CLASS (dummy_class);
NMDeviceClass *device_class = NM_DEVICE_CLASS (dummy_class);
object_class->get_property = get_property;
object_class->dispose = dispose;
nm_object_class->init_dbus = init_dbus;
object_class->finalize = finalize;
device_class->connection_compatible = connection_compatible;
device_class->get_hw_address = get_hw_address;
@ -171,5 +161,5 @@ nm_device_dummy_class_init (NMDeviceDummyClass *dummy_class)
G_PARAM_READABLE |
G_PARAM_STATIC_STRINGS);
g_object_class_install_properties (object_class, _PROPERTY_ENUMS_LAST, obj_properties);
_nml_dbus_meta_class_init_with_properties (object_class, &_nml_dbus_meta_iface_nm_device_dummy);
}

View file

@ -25,11 +25,11 @@ NM_GOBJECT_PROPERTIES_DEFINE_BASE (
);
typedef struct {
char **s390_subchannels;
char *hw_address;
char *perm_hw_address;
guint32 speed;
gboolean carrier;
char **s390_subchannels;
bool carrier;
} NMDeviceEthernetPrivate;
struct _NMDeviceEthernet {
@ -124,24 +124,12 @@ nm_device_ethernet_get_carrier (NMDeviceEthernet *device)
*
* Since: 1.2
**/
const char * const *
const char *const*
nm_device_ethernet_get_s390_subchannels (NMDeviceEthernet *device)
{
g_return_val_if_fail (NM_IS_DEVICE_ETHERNET (device), NULL);
return (const char * const *) NM_DEVICE_ETHERNET_GET_PRIVATE (device)->s390_subchannels;
}
static guint32
_subchannels_count_num (const char * const *array)
{
int i;
if (!array)
return 0;
for (i = 0; array[i]; i++)
/* NOP */;
return i;
return (const char *const*) NM_DEVICE_ETHERNET_GET_PRIVATE (device)->s390_subchannels;
}
static gboolean
@ -149,14 +137,14 @@ match_subchans (NMDeviceEthernet *self, NMSettingWired *s_wired, gboolean *try_m
{
NMDeviceEthernetPrivate *priv = NM_DEVICE_ETHERNET_GET_PRIVATE (self);
const char * const *subchans;
guint32 num1, num2;
int i, j;
gsize num1, num2;
gsize i, j;
*try_mac = TRUE;
subchans = nm_setting_wired_get_s390_subchannels (s_wired);
num1 = _subchannels_count_num (subchans);
num2 = _subchannels_count_num ((const char * const *) priv->s390_subchannels);
num1 = NM_PTRARRAY_LEN (subchans);
num2 = NM_PTRARRAY_LEN (priv->s390_subchannels);
/* connection has no subchannels */
if (num1 == 0)
return TRUE;
@ -276,26 +264,6 @@ nm_device_ethernet_init (NMDeviceEthernet *device)
{
}
static void
init_dbus (NMObject *object)
{
NMDeviceEthernetPrivate *priv = NM_DEVICE_ETHERNET_GET_PRIVATE (object);
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 },
{ NM_DEVICE_ETHERNET_S390_SUBCHANNELS, &priv->s390_subchannels },
{ NULL },
};
NM_OBJECT_CLASS (nm_device_ethernet_parent_class)->init_dbus (object);
_nm_object_register_properties (object,
NM_DBUS_INTERFACE_DEVICE_WIRED,
property_info);
}
static void
finalize (GObject *object)
{
@ -339,18 +307,35 @@ get_property (GObject *object,
}
}
/* TODO: implemented Veth. */
const NMLDBusMetaIface _nml_dbus_meta_iface_nm_device_veth = NML_DBUS_META_IFACE_INIT (
NM_DBUS_INTERFACE_DEVICE_VETH,
NULL,
NML_DBUS_META_INTERFACE_PRIO_NONE,
);
const NMLDBusMetaIface _nml_dbus_meta_iface_nm_device_wired = NML_DBUS_META_IFACE_INIT_PROP (
NM_DBUS_INTERFACE_DEVICE_WIRED,
nm_device_ethernet_get_type,
NML_DBUS_META_INTERFACE_PRIO_INSTANTIATE_HIGH,
NML_DBUS_META_IFACE_DBUS_PROPERTIES (
NML_DBUS_META_PROPERTY_INIT_B ("Carrier", PROP_CARRIER, NMDeviceEthernet, _priv.carrier ),
NML_DBUS_META_PROPERTY_INIT_S ("HwAddress", PROP_HW_ADDRESS, NMDeviceEthernet, _priv.hw_address ),
NML_DBUS_META_PROPERTY_INIT_S ("PermHwAddress", PROP_PERM_HW_ADDRESS, NMDeviceEthernet, _priv.perm_hw_address ),
NML_DBUS_META_PROPERTY_INIT_AS ("S390Subchannels", PROP_S390_SUBCHANNELS, NMDeviceEthernet, _priv.s390_subchannels ),
NML_DBUS_META_PROPERTY_INIT_U ("Speed", PROP_SPEED, NMDeviceEthernet, _priv.speed ),
),
);
static void
nm_device_ethernet_class_init (NMDeviceEthernetClass *eth_class)
{
GObjectClass *object_class = G_OBJECT_CLASS (eth_class);
NMObjectClass *nm_object_class = NM_OBJECT_CLASS (eth_class);
NMDeviceClass *device_class = NM_DEVICE_CLASS (eth_class);
object_class->get_property = get_property;
object_class->finalize = finalize;
nm_object_class->init_dbus = init_dbus;
device_class->connection_compatible = connection_compatible;
device_class->get_setting_type = get_setting_type;
device_class->get_hw_address = get_hw_address;
@ -413,5 +398,5 @@ nm_device_ethernet_class_init (NMDeviceEthernetClass *eth_class)
G_PARAM_READABLE |
G_PARAM_STATIC_STRINGS);
g_object_class_install_properties (object_class, _PROPERTY_ENUMS_LAST, obj_properties);
_nml_dbus_meta_class_init_with_properties (object_class, &_nml_dbus_meta_iface_nm_device_wired);
}

View file

@ -108,23 +108,6 @@ nm_device_generic_init (NMDeviceGeneric *device)
{
}
static void
init_dbus (NMObject *object)
{
NMDeviceGenericPrivate *priv = NM_DEVICE_GENERIC_GET_PRIVATE (object);
const NMPropertiesInfo property_info[] = {
{ NM_DEVICE_GENERIC_HW_ADDRESS, &priv->hw_address },
{ NM_DEVICE_GENERIC_TYPE_DESCRIPTION, &priv->type_description },
{ NULL },
};
NM_OBJECT_CLASS (nm_device_generic_parent_class)->init_dbus (object);
_nm_object_register_properties (object,
NM_DBUS_INTERFACE_DEVICE_GENERIC,
property_info);
}
static void
finalize (GObject *object)
{
@ -158,18 +141,25 @@ get_property (GObject *object,
}
}
const NMLDBusMetaIface _nml_dbus_meta_iface_nm_device_generic = NML_DBUS_META_IFACE_INIT_PROP (
NM_DBUS_INTERFACE_DEVICE_GENERIC,
nm_device_generic_get_type,
NML_DBUS_META_INTERFACE_PRIO_INSTANTIATE_HIGH,
NML_DBUS_META_IFACE_DBUS_PROPERTIES (
NML_DBUS_META_PROPERTY_INIT_S ("HwAddress", PROP_HW_ADDRESS, NMDeviceGeneric, _priv.hw_address ),
NML_DBUS_META_PROPERTY_INIT_S ("TypeDescription", PROP_TYPE_DESCRIPTION, NMDeviceGeneric, _priv.type_description ),
),
);
static void
nm_device_generic_class_init (NMDeviceGenericClass *klass)
{
GObjectClass *object_class = G_OBJECT_CLASS (klass);
NMObjectClass *nm_object_class = NM_OBJECT_CLASS (klass);
NMDeviceClass *device_class = NM_DEVICE_CLASS (klass);
object_class->get_property = get_property;
object_class->finalize = finalize;
nm_object_class->init_dbus = init_dbus;
device_class->get_type_description = get_type_description;
device_class->get_hw_address = get_hw_address;
device_class->connection_compatible = connection_compatible;
@ -198,5 +188,5 @@ nm_device_generic_class_init (NMDeviceGenericClass *klass)
G_PARAM_READABLE |
G_PARAM_STATIC_STRINGS);
g_object_class_install_properties (object_class, _PROPERTY_ENUMS_LAST, obj_properties);
_nml_dbus_meta_class_init_with_properties (object_class, &_nml_dbus_meta_iface_nm_device_generic);
}

View file

@ -21,7 +21,7 @@ NM_GOBJECT_PROPERTIES_DEFINE_BASE (
typedef struct {
char *hw_address;
gboolean carrier;
bool carrier;
} NMDeviceInfinibandPrivate;
struct _NMDeviceInfiniband {
@ -126,23 +126,6 @@ nm_device_infiniband_init (NMDeviceInfiniband *device)
{
}
static void
init_dbus (NMObject *object)
{
NMDeviceInfinibandPrivate *priv = NM_DEVICE_INFINIBAND_GET_PRIVATE (object);
const NMPropertiesInfo property_info[] = {
{ NM_DEVICE_INFINIBAND_HW_ADDRESS, &priv->hw_address },
{ NM_DEVICE_INFINIBAND_CARRIER, &priv->carrier },
{ NULL },
};
NM_OBJECT_CLASS (nm_device_infiniband_parent_class)->init_dbus (object);
_nm_object_register_properties (object,
NM_DBUS_INTERFACE_DEVICE_INFINIBAND,
property_info);
}
static void
finalize (GObject *object)
{
@ -174,18 +157,25 @@ get_property (GObject *object,
}
}
const NMLDBusMetaIface _nml_dbus_meta_iface_nm_device_infiniband = NML_DBUS_META_IFACE_INIT_PROP (
NM_DBUS_INTERFACE_DEVICE_INFINIBAND,
nm_device_infiniband_get_type,
NML_DBUS_META_INTERFACE_PRIO_INSTANTIATE_HIGH,
NML_DBUS_META_IFACE_DBUS_PROPERTIES (
NML_DBUS_META_PROPERTY_INIT_B ("Carrier", PROP_CARRIER, NMDeviceInfiniband, _priv.carrier ),
NML_DBUS_META_PROPERTY_INIT_S ("HwAddress", PROP_HW_ADDRESS, NMDeviceInfiniband, _priv.hw_address ),
),
);
static void
nm_device_infiniband_class_init (NMDeviceInfinibandClass *ib_class)
{
GObjectClass *object_class = G_OBJECT_CLASS (ib_class);
NMObjectClass *nm_object_class = NM_OBJECT_CLASS (ib_class);
NMDeviceClass *device_class = NM_DEVICE_CLASS (ib_class);
object_class->get_property = get_property;
object_class->finalize = finalize;
nm_object_class->init_dbus = init_dbus;
device_class->connection_compatible = connection_compatible;
device_class->get_setting_type = get_setting_type;
device_class->get_hw_address = get_hw_address;
@ -212,5 +202,5 @@ nm_device_infiniband_class_init (NMDeviceInfinibandClass *ib_class)
G_PARAM_READABLE |
G_PARAM_STATIC_STRINGS);
g_object_class_install_properties (object_class, _PROPERTY_ENUMS_LAST, obj_properties);
_nml_dbus_meta_class_init_with_properties (object_class, &_nml_dbus_meta_iface_nm_device_infiniband);
}

View file

@ -31,18 +31,18 @@ NM_GOBJECT_PROPERTIES_DEFINE_BASE (
);
typedef struct {
NMIPTunnelMode mode;
NMDevice *parent;
NMLDBusPropertyO parent;
char *local;
char *remote;
guint8 ttl;
guint8 tos;
gboolean path_mtu_discovery;
char *input_key;
char *output_key;
guint8 encap_limit;
guint32 mode;
guint32 flow_label;
guint32 flags;
guint8 ttl;
guint8 tos;
guint8 encapsulation_limit;
bool path_mtu_discovery;
} NMDeviceIPTunnelPrivate;
struct _NMDeviceIPTunnel {
@ -89,7 +89,7 @@ nm_device_ip_tunnel_get_parent (NMDeviceIPTunnel *device)
{
g_return_val_if_fail (NM_IS_DEVICE_IP_TUNNEL (device), NULL);
return NM_DEVICE_IP_TUNNEL_GET_PRIVATE (device)->parent;
return nml_dbus_property_o_get_obj (&NM_DEVICE_IP_TUNNEL_GET_PRIVATE (device)->parent);
}
/**
@ -218,7 +218,7 @@ nm_device_ip_tunnel_get_encapsulation_limit (NMDeviceIPTunnel *device)
{
g_return_val_if_fail (NM_IS_DEVICE_IP_TUNNEL (device), 0);
return NM_DEVICE_IP_TUNNEL_GET_PRIVATE (device)->encap_limit;
return NM_DEVICE_IP_TUNNEL_GET_PRIVATE (device)->encapsulation_limit;
}
/**
@ -281,33 +281,6 @@ nm_device_ip_tunnel_init (NMDeviceIPTunnel *device)
{
}
static void
init_dbus (NMObject *object)
{
NMDeviceIPTunnelPrivate *priv = NM_DEVICE_IP_TUNNEL_GET_PRIVATE (object);
const NMPropertiesInfo property_info[] = {
{ NM_DEVICE_IP_TUNNEL_PARENT, &priv->parent, NULL, NM_TYPE_DEVICE },
{ NM_DEVICE_IP_TUNNEL_MODE, &priv->mode },
{ NM_DEVICE_IP_TUNNEL_LOCAL, &priv->local },
{ NM_DEVICE_IP_TUNNEL_REMOTE, &priv->remote },
{ NM_DEVICE_IP_TUNNEL_TTL, &priv->ttl },
{ NM_DEVICE_IP_TUNNEL_TOS, &priv->tos },
{ NM_DEVICE_IP_TUNNEL_PATH_MTU_DISCOVERY, &priv->path_mtu_discovery },
{ NM_DEVICE_IP_TUNNEL_INPUT_KEY, &priv->input_key },
{ NM_DEVICE_IP_TUNNEL_OUTPUT_KEY, &priv->output_key },
{ NM_DEVICE_IP_TUNNEL_ENCAPSULATION_LIMIT, &priv->encap_limit },
{ NM_DEVICE_IP_TUNNEL_FLOW_LABEL, &priv->flow_label },
{ NM_DEVICE_IP_TUNNEL_FLAGS, &priv->flags },
{ NULL },
};
NM_OBJECT_CLASS (nm_device_ip_tunnel_parent_class)->init_dbus (object);
_nm_object_register_properties (object,
NM_DBUS_INTERFACE_DEVICE_IP_TUNNEL,
property_info);
}
static void
finalize (GObject *object)
{
@ -317,7 +290,6 @@ finalize (GObject *object)
g_free (priv->remote);
g_free (priv->input_key);
g_free (priv->output_key);
g_clear_object (&priv->parent);
G_OBJECT_CLASS (nm_device_ip_tunnel_parent_class)->finalize (object);
}
@ -373,17 +345,39 @@ get_property (GObject *object,
}
}
const NMLDBusMetaIface _nml_dbus_meta_iface_nm_device_iptunnel = NML_DBUS_META_IFACE_INIT_PROP (
NM_DBUS_INTERFACE_DEVICE_IP_TUNNEL,
nm_device_ip_tunnel_get_type,
NML_DBUS_META_INTERFACE_PRIO_INSTANTIATE_HIGH,
NML_DBUS_META_IFACE_DBUS_PROPERTIES (
NML_DBUS_META_PROPERTY_INIT_Y ("EncapsulationLimit", PROP_ENCAPSULATION_LIMIT, NMDeviceIPTunnel, _priv.encapsulation_limit ),
NML_DBUS_META_PROPERTY_INIT_U ("Flags", PROP_FLAGS, NMDeviceIPTunnel, _priv.flags ),
NML_DBUS_META_PROPERTY_INIT_U ("FlowLabel", PROP_FLOW_LABEL, NMDeviceIPTunnel, _priv.flow_label ),
NML_DBUS_META_PROPERTY_INIT_S ("InputKey", PROP_INPUT_KEY, NMDeviceIPTunnel, _priv.input_key ),
NML_DBUS_META_PROPERTY_INIT_S ("Local", PROP_LOCAL, NMDeviceIPTunnel, _priv.local ),
NML_DBUS_META_PROPERTY_INIT_U ("Mode", PROP_MODE, NMDeviceIPTunnel, _priv.mode ),
NML_DBUS_META_PROPERTY_INIT_S ("OutputKey", PROP_OUTPUT_KEY, NMDeviceIPTunnel, _priv.output_key ),
NML_DBUS_META_PROPERTY_INIT_O_PROP ("Parent", PROP_PARENT, NMDeviceIPTunnel, _priv.parent, nm_device_get_type ),
NML_DBUS_META_PROPERTY_INIT_B ("PathMtuDiscovery", PROP_PATH_MTU_DISCOVERY, NMDeviceIPTunnel, _priv.path_mtu_discovery ),
NML_DBUS_META_PROPERTY_INIT_S ("Remote", PROP_REMOTE, NMDeviceIPTunnel, _priv.remote ),
NML_DBUS_META_PROPERTY_INIT_Y ("Tos", PROP_TOS, NMDeviceIPTunnel, _priv.tos ),
NML_DBUS_META_PROPERTY_INIT_Y ("Ttl", PROP_TTL, NMDeviceIPTunnel, _priv.ttl ),
),
);
static void
nm_device_ip_tunnel_class_init (NMDeviceIPTunnelClass *bond_class)
nm_device_ip_tunnel_class_init (NMDeviceIPTunnelClass *klass)
{
GObjectClass *object_class = G_OBJECT_CLASS (bond_class);
NMObjectClass *nm_object_class = NM_OBJECT_CLASS (bond_class);
NMDeviceClass *device_class = NM_DEVICE_CLASS (bond_class);
GObjectClass *object_class = G_OBJECT_CLASS (klass);
NMObjectClass *nm_object_class = NM_OBJECT_CLASS (klass);
NMDeviceClass *device_class = NM_DEVICE_CLASS (klass);
object_class->get_property = get_property;
object_class->finalize = finalize;
nm_object_class->init_dbus = init_dbus;
_NM_OBJECT_CLASS_INIT_PRIV_PTR_DIRECT (nm_object_class, NMDeviceIPTunnel);
_NM_OBJECT_CLASS_INIT_PROPERTY_O_FIELDS_1 (nm_object_class, NMDeviceIPTunnelPrivate, parent);
device_class->connection_compatible = connection_compatible;
device_class->get_setting_type = get_setting_type;
@ -549,5 +543,5 @@ nm_device_ip_tunnel_class_init (NMDeviceIPTunnelClass *bond_class)
G_PARAM_READABLE |
G_PARAM_STATIC_STRINGS);
g_object_class_install_properties (object_class, _PROPERTY_ENUMS_LAST, obj_properties);
_nml_dbus_meta_class_init_with_properties (object_class, &_nml_dbus_meta_iface_nm_device_iptunnel);
}

View file

@ -31,20 +31,20 @@ NM_GOBJECT_PROPERTIES_DEFINE_BASE (
);
typedef struct {
NMDevice *parent;
NMLDBusPropertyO parent;
char *hw_address;
char *validation;
guint64 sci;
guint64 cipher_suite;
guint8 icv_length;
guint32 window;
guint8 icv_length;
guint8 encoding_sa;
gboolean encrypt;
gboolean protect;
gboolean include_sci;
gboolean es;
gboolean scb;
gboolean replay_protect;
char *validation;
bool encrypt;
bool protect;
bool include_sci;
bool es;
bool scb;
bool replay_protect;
} NMDeviceMacsecPrivate;
struct _NMDeviceMacsec {
@ -75,7 +75,7 @@ nm_device_macsec_get_parent (NMDeviceMacsec *device)
{
g_return_val_if_fail (NM_IS_DEVICE_MACSEC (device), NULL);
return NM_DEVICE_MACSEC_GET_PRIVATE (device)->parent;
return nml_dbus_property_o_get_obj (&NM_DEVICE_MACSEC_GET_PRIVATE (device)->parent);
}
/**
@ -331,35 +331,6 @@ nm_device_macsec_init (NMDeviceMacsec *device)
{
}
static void
init_dbus (NMObject *object)
{
NMDeviceMacsecPrivate *priv = NM_DEVICE_MACSEC_GET_PRIVATE (object);
const NMPropertiesInfo property_info[] = {
{ NM_DEVICE_MACSEC_PARENT, &priv->parent, NULL, NM_TYPE_DEVICE },
{ NM_DEVICE_MACSEC_HW_ADDRESS, &priv->hw_address },
{ NM_DEVICE_MACSEC_SCI, &priv->sci },
{ NM_DEVICE_MACSEC_CIPHER_SUITE, &priv->cipher_suite },
{ NM_DEVICE_MACSEC_ICV_LENGTH, &priv->icv_length },
{ NM_DEVICE_MACSEC_WINDOW, &priv->window },
{ NM_DEVICE_MACSEC_ENCODING_SA, &priv->encoding_sa },
{ NM_DEVICE_MACSEC_ENCRYPT, &priv->encrypt },
{ NM_DEVICE_MACSEC_PROTECT, &priv->protect },
{ NM_DEVICE_MACSEC_INCLUDE_SCI, &priv->include_sci },
{ NM_DEVICE_MACSEC_ES, &priv->es },
{ NM_DEVICE_MACSEC_SCB, &priv->scb },
{ NM_DEVICE_MACSEC_REPLAY_PROTECT, &priv->replay_protect },
{ NM_DEVICE_MACSEC_VALIDATION, &priv->validation },
{ NULL },
};
NM_OBJECT_CLASS (nm_device_macsec_parent_class)->init_dbus (object);
_nm_object_register_properties (object,
NM_DBUS_INTERFACE_DEVICE_MACSEC,
property_info);
}
static void
finalize (GObject *object)
{
@ -367,7 +338,6 @@ finalize (GObject *object)
g_free (priv->validation);
g_free (priv->hw_address);
g_clear_object (&priv->parent);
G_OBJECT_CLASS (nm_device_macsec_parent_class)->finalize (object);
}
@ -429,17 +399,40 @@ get_property (GObject *object,
}
}
const NMLDBusMetaIface _nml_dbus_meta_iface_nm_device_macsec = NML_DBUS_META_IFACE_INIT_PROP (
NM_DBUS_INTERFACE_DEVICE_MACSEC,
nm_device_macsec_get_type,
NML_DBUS_META_INTERFACE_PRIO_INSTANTIATE_HIGH,
NML_DBUS_META_IFACE_DBUS_PROPERTIES (
NML_DBUS_META_PROPERTY_INIT_T ("CipherSuite", PROP_CIPHER_SUITE, NMDeviceMacsec, _priv.cipher_suite ),
NML_DBUS_META_PROPERTY_INIT_Y ("EncodingSa", PROP_ENCODING_SA, NMDeviceMacsec, _priv.encoding_sa ),
NML_DBUS_META_PROPERTY_INIT_B ("Encrypt", PROP_ENCRYPT, NMDeviceMacsec, _priv.encrypt ),
NML_DBUS_META_PROPERTY_INIT_B ("Es", PROP_ES, NMDeviceMacsec, _priv.es ),
NML_DBUS_META_PROPERTY_INIT_Y ("IcvLength", PROP_ICV_LENGTH, NMDeviceMacsec, _priv.icv_length ),
NML_DBUS_META_PROPERTY_INIT_B ("IncludeSci", PROP_INCLUDE_SCI, NMDeviceMacsec, _priv.include_sci ),
NML_DBUS_META_PROPERTY_INIT_O_PROP ("Parent", PROP_PARENT, NMDeviceMacsec, _priv.parent, nm_device_get_type ),
NML_DBUS_META_PROPERTY_INIT_B ("Protect", PROP_PROTECT, NMDeviceMacsec, _priv.protect ),
NML_DBUS_META_PROPERTY_INIT_B ("ReplayProtect", PROP_REPLAY_PROTECT, NMDeviceMacsec, _priv.replay_protect ),
NML_DBUS_META_PROPERTY_INIT_B ("Scb", PROP_SCB, NMDeviceMacsec, _priv.scb ),
NML_DBUS_META_PROPERTY_INIT_T ("Sci", PROP_SCI, NMDeviceMacsec, _priv.sci ),
NML_DBUS_META_PROPERTY_INIT_S ("Validation", PROP_VALIDATION, NMDeviceMacsec, _priv.validation ),
NML_DBUS_META_PROPERTY_INIT_U ("Window", PROP_WINDOW, NMDeviceMacsec, _priv.window ),
),
);
static void
nm_device_macsec_class_init (NMDeviceMacsecClass *macsec_class)
nm_device_macsec_class_init (NMDeviceMacsecClass *klass)
{
GObjectClass *object_class = G_OBJECT_CLASS (macsec_class);
NMObjectClass *nm_object_class = NM_OBJECT_CLASS (macsec_class);
NMDeviceClass *device_class = NM_DEVICE_CLASS (macsec_class);
GObjectClass *object_class = G_OBJECT_CLASS (klass);
NMObjectClass *nm_object_class = NM_OBJECT_CLASS (klass);
NMDeviceClass *device_class = NM_DEVICE_CLASS (klass);
object_class->get_property = get_property;
object_class->finalize = finalize;
nm_object_class->init_dbus = init_dbus;
_NM_OBJECT_CLASS_INIT_PRIV_PTR_DIRECT (nm_object_class, NMDeviceMacsec);
_NM_OBJECT_CLASS_INIT_PROPERTY_O_FIELDS_1 (nm_object_class, NMDeviceMacsecPrivate, parent);
device_class->get_hw_address = get_hw_address;
@ -630,5 +623,5 @@ nm_device_macsec_class_init (NMDeviceMacsecClass *macsec_class)
G_PARAM_READABLE |
G_PARAM_STATIC_STRINGS);
g_object_class_install_properties (object_class, _PROPERTY_ENUMS_LAST, obj_properties);
_nml_dbus_meta_class_init_with_properties (object_class, &_nml_dbus_meta_iface_nm_device_macsec);
}

View file

@ -24,10 +24,10 @@ NM_GOBJECT_PROPERTIES_DEFINE_BASE (
);
typedef struct {
NMDevice *parent;
NMLDBusPropertyO parent;
char *mode;
gboolean no_promisc;
gboolean tap;
bool no_promisc;
bool tap;
} NMDeviceMacvlanPrivate;
struct _NMDeviceMacvlan {
@ -58,7 +58,7 @@ nm_device_macvlan_get_parent (NMDeviceMacvlan *device)
{
g_return_val_if_fail (NM_IS_DEVICE_MACVLAN (device), FALSE);
return NM_DEVICE_MACVLAN_GET_PRIVATE (device)->parent;
return nml_dbus_property_o_get_obj (&NM_DEVICE_MACVLAN_GET_PRIVATE (device)->parent);
}
/**
@ -180,32 +180,12 @@ nm_device_macvlan_init (NMDeviceMacvlan *device)
{
}
static void
init_dbus (NMObject *object)
{
NMDeviceMacvlanPrivate *priv = NM_DEVICE_MACVLAN_GET_PRIVATE (object);
const NMPropertiesInfo property_info[] = {
{ NM_DEVICE_MACVLAN_PARENT, &priv->parent, NULL, NM_TYPE_DEVICE },
{ NM_DEVICE_MACVLAN_MODE, &priv->mode },
{ NM_DEVICE_MACVLAN_NO_PROMISC, &priv->no_promisc },
{ NM_DEVICE_MACVLAN_TAP, &priv->tap },
{ NULL },
};
NM_OBJECT_CLASS (nm_device_macvlan_parent_class)->init_dbus (object);
_nm_object_register_properties (object,
NM_DBUS_INTERFACE_DEVICE_MACVLAN,
property_info);
}
static void
finalize (GObject *object)
{
NMDeviceMacvlanPrivate *priv = NM_DEVICE_MACVLAN_GET_PRIVATE (object);
g_free (priv->mode);
g_clear_object (&priv->parent);
G_OBJECT_CLASS (nm_device_macvlan_parent_class)->finalize (object);
}
@ -240,17 +220,31 @@ get_property (GObject *object,
}
}
const NMLDBusMetaIface _nml_dbus_meta_iface_nm_device_macvlan = NML_DBUS_META_IFACE_INIT_PROP (
NM_DBUS_INTERFACE_DEVICE_MACVLAN,
nm_device_macvlan_get_type,
NML_DBUS_META_INTERFACE_PRIO_INSTANTIATE_HIGH,
NML_DBUS_META_IFACE_DBUS_PROPERTIES (
NML_DBUS_META_PROPERTY_INIT_S ("Mode", PROP_MODE, NMDeviceMacvlan, _priv.mode ),
NML_DBUS_META_PROPERTY_INIT_B ("NoPromisc", PROP_NO_PROMISC, NMDeviceMacvlan, _priv.no_promisc ),
NML_DBUS_META_PROPERTY_INIT_O_PROP ("Parent", PROP_PARENT, NMDeviceMacvlan, _priv.parent, nm_device_get_type ),
NML_DBUS_META_PROPERTY_INIT_B ("Tap", PROP_TAP, NMDeviceMacvlan, _priv.tap ),
),
);
static void
nm_device_macvlan_class_init (NMDeviceMacvlanClass *gre_class)
nm_device_macvlan_class_init (NMDeviceMacvlanClass *klass)
{
GObjectClass *object_class = G_OBJECT_CLASS (gre_class);
NMObjectClass *nm_object_class = NM_OBJECT_CLASS (gre_class);
NMDeviceClass *device_class = NM_DEVICE_CLASS (gre_class);
GObjectClass *object_class = G_OBJECT_CLASS (klass);
NMObjectClass *nm_object_class = NM_OBJECT_CLASS (klass);
NMDeviceClass *device_class = NM_DEVICE_CLASS (klass);
object_class->get_property = get_property;
object_class->finalize = finalize;
nm_object_class->init_dbus = init_dbus;
_NM_OBJECT_CLASS_INIT_PRIV_PTR_DIRECT (nm_object_class, NMDeviceMacvlan);
_NM_OBJECT_CLASS_INIT_PROPERTY_O_FIELDS_1 (nm_object_class, NMDeviceMacvlanPrivate, parent);
device_class->connection_compatible = connection_compatible;
device_class->get_setting_type = get_setting_type;
@ -323,5 +317,5 @@ nm_device_macvlan_class_init (NMDeviceMacvlanClass *gre_class)
G_PARAM_READABLE |
G_PARAM_STATIC_STRINGS);
g_object_class_install_properties (object_class, _PROPERTY_ENUMS_LAST, obj_properties);
_nml_dbus_meta_class_init_with_properties (object_class, &_nml_dbus_meta_iface_nm_device_macvlan);
}

View file

@ -25,11 +25,11 @@ NM_GOBJECT_PROPERTIES_DEFINE_BASE (
);
typedef struct {
NMDeviceModemCapabilities caps;
NMDeviceModemCapabilities current_caps;
char *device_id;
char *operator_code;
char *apn;
guint32 modem_capabilities;
guint32 current_capabilities;
} NMDeviceModemPrivate;
struct _NMDeviceModem {
@ -62,7 +62,7 @@ nm_device_modem_get_modem_capabilities (NMDeviceModem *self)
{
g_return_val_if_fail (NM_IS_DEVICE_MODEM (self), NM_DEVICE_MODEM_CAPABILITY_NONE);
return NM_DEVICE_MODEM_GET_PRIVATE (self)->caps;
return NM_DEVICE_MODEM_GET_PRIVATE (self)->modem_capabilities;
}
/**
@ -81,7 +81,7 @@ nm_device_modem_get_current_capabilities (NMDeviceModem *self)
{
g_return_val_if_fail (NM_IS_DEVICE_MODEM (self), NM_DEVICE_MODEM_CAPABILITY_NONE);
return NM_DEVICE_MODEM_GET_PRIVATE (self)->current_caps;
return NM_DEVICE_MODEM_GET_PRIVATE (self)->current_capabilities;
}
/**
@ -215,26 +215,6 @@ nm_device_modem_init (NMDeviceModem *device)
{
}
static void
init_dbus (NMObject *object)
{
NMDeviceModemPrivate *priv = NM_DEVICE_MODEM_GET_PRIVATE (object);
const NMPropertiesInfo property_info[] = {
{ NM_DEVICE_MODEM_MODEM_CAPABILITIES, &priv->caps },
{ NM_DEVICE_MODEM_CURRENT_CAPABILITIES, &priv->current_caps },
{ NM_DEVICE_MODEM_DEVICE_ID, &priv->device_id },
{ NM_DEVICE_MODEM_OPERATOR_CODE, &priv->operator_code },
{ NM_DEVICE_MODEM_APN, &priv->apn },
{ NULL },
};
NM_OBJECT_CLASS (nm_device_modem_parent_class)->init_dbus (object);
_nm_object_register_properties (object,
NM_DBUS_INTERFACE_DEVICE_MODEM,
property_info);
}
static void
finalize (GObject *object)
{
@ -277,18 +257,28 @@ get_property (GObject *object,
}
}
const NMLDBusMetaIface _nml_dbus_meta_iface_nm_device_modem = NML_DBUS_META_IFACE_INIT_PROP (
NM_DBUS_INTERFACE_DEVICE_MODEM,
nm_device_modem_get_type,
NML_DBUS_META_INTERFACE_PRIO_INSTANTIATE_HIGH,
NML_DBUS_META_IFACE_DBUS_PROPERTIES (
NML_DBUS_META_PROPERTY_INIT_S ("Apn", PROP_APN, NMDeviceModem, _priv.apn ),
NML_DBUS_META_PROPERTY_INIT_U ("CurrentCapabilities", PROP_CURRENT_CAPABILITIES, NMDeviceModem, _priv.current_capabilities ),
NML_DBUS_META_PROPERTY_INIT_S ("DeviceId", PROP_DEVICE_ID, NMDeviceModem, _priv.device_id ),
NML_DBUS_META_PROPERTY_INIT_U ("ModemCapabilities", PROP_MODEM_CAPABILITIES, NMDeviceModem, _priv.modem_capabilities ),
NML_DBUS_META_PROPERTY_INIT_S ("OperatorCode", PROP_OPERATOR_CODE, NMDeviceModem, _priv.operator_code ),
),
);
static void
nm_device_modem_class_init (NMDeviceModemClass *modem_class)
{
GObjectClass *object_class = G_OBJECT_CLASS (modem_class);
NMObjectClass *nm_object_class = NM_OBJECT_CLASS (modem_class);
NMDeviceClass *device_class = NM_DEVICE_CLASS (modem_class);
object_class->get_property = get_property;
object_class->finalize = finalize;
nm_object_class->init_dbus = init_dbus;
device_class->get_type_description = get_type_description;
device_class->connection_compatible = connection_compatible;
device_class->get_setting_type = get_setting_type;
@ -354,5 +344,5 @@ nm_device_modem_class_init (NMDeviceModemClass *modem_class)
G_PARAM_READABLE |
G_PARAM_STATIC_STRINGS);
g_object_class_install_properties (object_class, _PROPERTY_ENUMS_LAST, obj_properties);
_nml_dbus_meta_class_init_with_properties (object_class, &_nml_dbus_meta_iface_nm_device_modem);
}

View file

@ -21,8 +21,8 @@ NM_GOBJECT_PROPERTIES_DEFINE_BASE (
);
typedef struct {
NMLDBusPropertyO companion;
char *hw_address;
NMDeviceWifi *companion;
guint32 active_channel;
} NMDeviceOlpcMeshPrivate;
@ -71,7 +71,7 @@ nm_device_olpc_mesh_get_companion (NMDeviceOlpcMesh *device)
{
g_return_val_if_fail (NM_IS_DEVICE_OLPC_MESH (device), NULL);
return NM_DEVICE_OLPC_MESH_GET_PRIVATE (device)->companion;
return nml_dbus_property_o_get_obj (&NM_DEVICE_OLPC_MESH_GET_PRIVATE (device)->companion);
}
/**
@ -124,34 +124,6 @@ nm_device_olpc_mesh_init (NMDeviceOlpcMesh *device)
{
}
static void
init_dbus (NMObject *object)
{
NMDeviceOlpcMeshPrivate *priv = NM_DEVICE_OLPC_MESH_GET_PRIVATE (object);
const NMPropertiesInfo property_info[] = {
{ NM_DEVICE_OLPC_MESH_HW_ADDRESS, &priv->hw_address },
{ NM_DEVICE_OLPC_MESH_COMPANION, &priv->companion, NULL, NM_TYPE_DEVICE_WIFI },
{ NM_DEVICE_OLPC_MESH_ACTIVE_CHANNEL, &priv->active_channel },
{ NULL },
};
NM_OBJECT_CLASS (nm_device_olpc_mesh_parent_class)->init_dbus (object);
_nm_object_register_properties (object,
NM_DBUS_INTERFACE_DEVICE_OLPC_MESH,
property_info);
}
static void
dispose (GObject *object)
{
NMDeviceOlpcMeshPrivate *priv = NM_DEVICE_OLPC_MESH_GET_PRIVATE (object);
g_clear_object (&priv->companion);
G_OBJECT_CLASS (nm_device_olpc_mesh_parent_class)->dispose (object);
}
static void
finalize (GObject *object)
{
@ -186,18 +158,30 @@ get_property (GObject *object,
}
}
const NMLDBusMetaIface _nml_dbus_meta_iface_nm_device_olpcmesh = NML_DBUS_META_IFACE_INIT_PROP (
NM_DBUS_INTERFACE_DEVICE_OLPC_MESH,
nm_device_olpc_mesh_get_type,
NML_DBUS_META_INTERFACE_PRIO_INSTANTIATE_HIGH,
NML_DBUS_META_IFACE_DBUS_PROPERTIES (
NML_DBUS_META_PROPERTY_INIT_U ("ActiveChannel", PROP_ACTIVE_CHANNEL, NMDeviceOlpcMesh, _priv.active_channel ),
NML_DBUS_META_PROPERTY_INIT_O_PROP ("Companion", PROP_COMPANION, NMDeviceOlpcMesh, _priv.companion, nm_device_wifi_get_type ),
NML_DBUS_META_PROPERTY_INIT_S ("HwAddress", PROP_HW_ADDRESS, NMDeviceOlpcMesh, _priv.hw_address ),
),
);
static void
nm_device_olpc_mesh_class_init (NMDeviceOlpcMeshClass *olpc_mesh_class)
nm_device_olpc_mesh_class_init (NMDeviceOlpcMeshClass *klass)
{
GObjectClass *object_class = G_OBJECT_CLASS (olpc_mesh_class);
NMObjectClass *nm_object_class = NM_OBJECT_CLASS (olpc_mesh_class);
NMDeviceClass *device_class = NM_DEVICE_CLASS (olpc_mesh_class);
GObjectClass *object_class = G_OBJECT_CLASS (klass);
NMObjectClass *nm_object_class = NM_OBJECT_CLASS (klass);
NMDeviceClass *device_class = NM_DEVICE_CLASS (klass);
object_class->get_property = get_property;
object_class->dispose = dispose;
object_class->finalize = finalize;
nm_object_class->init_dbus = init_dbus;
_NM_OBJECT_CLASS_INIT_PRIV_PTR_DIRECT (nm_object_class, NMDeviceOlpcMesh);
_NM_OBJECT_CLASS_INIT_PROPERTY_O_FIELDS_1 (nm_object_class, NMDeviceOlpcMeshPrivate, companion);
device_class->connection_compatible = connection_compatible;
device_class->get_setting_type = get_setting_type;
@ -236,5 +220,5 @@ nm_device_olpc_mesh_class_init (NMDeviceOlpcMeshClass *olpc_mesh_class)
G_PARAM_READABLE |
G_PARAM_STATIC_STRINGS);
g_object_class_install_properties (object_class, _PROPERTY_ENUMS_LAST, obj_properties);
_nml_dbus_meta_class_init_with_properties (object_class, &_nml_dbus_meta_iface_nm_device_olpcmesh);
}

View file

@ -20,7 +20,7 @@ NM_GOBJECT_PROPERTIES_DEFINE_BASE (
);
typedef struct {
GPtrArray *slaves;
NMLDBusPropertyAO slaves;
} NMDeviceOvsBridgePrivate;
struct _NMDeviceOvsBridge {
@ -55,7 +55,7 @@ nm_device_ovs_bridge_get_slaves (NMDeviceOvsBridge *device)
{
g_return_val_if_fail (NM_IS_DEVICE_OVS_BRIDGE (device), FALSE);
return NM_DEVICE_OVS_BRIDGE_GET_PRIVATE (device)->slaves;
return nml_dbus_property_ao_get_objs_as_ptrarray (&NM_DEVICE_OVS_BRIDGE_GET_PRIVATE (device)->slaves);
}
static const char *
@ -96,22 +96,6 @@ get_setting_type (NMDevice *device)
/*****************************************************************************/
static void
init_dbus (NMObject *object)
{
NMDeviceOvsBridge *device = NM_DEVICE_OVS_BRIDGE (object);
const NMPropertiesInfo property_info[] = {
{ NM_DEVICE_OVS_BRIDGE_SLAVES, &device->_priv.slaves, NULL, NM_TYPE_DEVICE },
{ NULL },
};
NM_OBJECT_CLASS (nm_device_ovs_bridge_parent_class)->init_dbus (object);
_nm_object_register_properties (object,
NM_DBUS_INTERFACE_DEVICE_OVS_BRIDGE,
property_info);
}
static void
get_property (GObject *object,
guint prop_id,
@ -130,32 +114,34 @@ get_property (GObject *object,
}
}
/*****************************************************************************/
static void
nm_device_ovs_bridge_init (NMDeviceOvsBridge *device)
{
}
static void
dispose (GObject *object)
{
NMDeviceOvsBridgePrivate *priv = NM_DEVICE_OVS_BRIDGE_GET_PRIVATE (object);
g_clear_pointer (&priv->slaves, g_ptr_array_unref);
G_OBJECT_CLASS (nm_device_ovs_bridge_parent_class)->dispose (object);
}
const NMLDBusMetaIface _nml_dbus_meta_iface_nm_device_ovsbridge = NML_DBUS_META_IFACE_INIT_PROP (
NM_DBUS_INTERFACE_DEVICE_OVS_BRIDGE,
nm_device_ovs_bridge_get_type,
NML_DBUS_META_INTERFACE_PRIO_INSTANTIATE_HIGH,
NML_DBUS_META_IFACE_DBUS_PROPERTIES (
NML_DBUS_META_PROPERTY_INIT_AO_PROP ("Slaves", PROP_SLAVES, NMDeviceOvsBridge, _priv.slaves, nm_device_get_type ),
),
);
static void
nm_device_ovs_bridge_class_init (NMDeviceOvsBridgeClass *ovs_bridge_class)
nm_device_ovs_bridge_class_init (NMDeviceOvsBridgeClass *klass)
{
GObjectClass *object_class = G_OBJECT_CLASS (ovs_bridge_class);
NMObjectClass *nm_object_class = NM_OBJECT_CLASS (ovs_bridge_class);
NMDeviceClass *device_class = NM_DEVICE_CLASS (ovs_bridge_class);
GObjectClass *object_class = G_OBJECT_CLASS (klass);
NMObjectClass *nm_object_class = NM_OBJECT_CLASS (klass);
NMDeviceClass *device_class = NM_DEVICE_CLASS (klass);
object_class->get_property = get_property;
object_class->dispose = dispose;
nm_object_class->init_dbus = init_dbus;
_NM_OBJECT_CLASS_INIT_PRIV_PTR_DIRECT (nm_object_class, NMDeviceOvsBridge);
_NM_OBJECT_CLASS_INIT_PROPERTY_AO_FIELDS_1 (nm_object_class, NMDeviceOvsBridgePrivate, slaves);
device_class->get_type_description = get_type_description;
device_class->connection_compatible = connection_compatible;
@ -174,5 +160,5 @@ nm_device_ovs_bridge_class_init (NMDeviceOvsBridgeClass *ovs_bridge_class)
G_PARAM_READABLE |
G_PARAM_STATIC_STRINGS);
g_object_class_install_properties (object_class, _PROPERTY_ENUMS_LAST, obj_properties);
_nml_dbus_meta_class_init_with_properties (object_class, &_nml_dbus_meta_iface_nm_device_ovsbridge);
}

View file

@ -69,6 +69,12 @@ nm_device_ovs_interface_init (NMDeviceOvsInterface *device)
{
}
const NMLDBusMetaIface _nml_dbus_meta_iface_nm_device_ovsinterface = NML_DBUS_META_IFACE_INIT (
NM_DBUS_INTERFACE_DEVICE_OVS_INTERFACE,
nm_device_ovs_interface_get_type,
NML_DBUS_META_INTERFACE_PRIO_INSTANTIATE_HIGH,
);
static void
nm_device_ovs_interface_class_init (NMDeviceOvsInterfaceClass *ovs_interface_class)
{

View file

@ -20,7 +20,7 @@ NM_GOBJECT_PROPERTIES_DEFINE_BASE (
);
typedef struct {
GPtrArray *slaves;
NMLDBusPropertyAO slaves;
} NMDeviceOvsPortPrivate;
struct _NMDeviceOvsPort {
@ -55,7 +55,7 @@ nm_device_ovs_port_get_slaves (NMDeviceOvsPort *device)
{
g_return_val_if_fail (NM_IS_DEVICE_OVS_PORT (device), FALSE);
return NM_DEVICE_OVS_PORT_GET_PRIVATE (device)->slaves;
return nml_dbus_property_ao_get_objs_as_ptrarray (&NM_DEVICE_OVS_PORT_GET_PRIVATE (device)->slaves);
}
static const char *
@ -96,23 +96,6 @@ get_setting_type (NMDevice *device)
/*****************************************************************************/
static void
init_dbus (NMObject *object)
{
NMDeviceOvsPort *device = NM_DEVICE_OVS_PORT (object);
NMDeviceOvsPortPrivate *priv = NM_DEVICE_OVS_PORT_GET_PRIVATE (device);
const NMPropertiesInfo property_info[] = {
{ NM_DEVICE_OVS_PORT_SLAVES, &priv->slaves, NULL, NM_TYPE_DEVICE },
{ NULL },
};
NM_OBJECT_CLASS (nm_device_ovs_port_parent_class)->init_dbus (object);
_nm_object_register_properties (object,
NM_DBUS_INTERFACE_DEVICE_OVS_PORT,
property_info);
}
static void
get_property (GObject *object,
guint prop_id,
@ -131,32 +114,34 @@ get_property (GObject *object,
}
}
/*****************************************************************************/
static void
nm_device_ovs_port_init (NMDeviceOvsPort *device)
{
}
static void
dispose (GObject *object)
{
NMDeviceOvsPortPrivate *priv = NM_DEVICE_OVS_PORT_GET_PRIVATE (object);
g_clear_pointer (&priv->slaves, g_ptr_array_unref);
G_OBJECT_CLASS (nm_device_ovs_port_parent_class)->dispose (object);
}
const NMLDBusMetaIface _nml_dbus_meta_iface_nm_device_ovsport = NML_DBUS_META_IFACE_INIT_PROP (
NM_DBUS_INTERFACE_DEVICE_OVS_PORT,
nm_device_ovs_port_get_type,
NML_DBUS_META_INTERFACE_PRIO_INSTANTIATE_HIGH,
NML_DBUS_META_IFACE_DBUS_PROPERTIES (
NML_DBUS_META_PROPERTY_INIT_AO_PROP ("Slaves", PROP_SLAVES, NMDeviceOvsPort, _priv.slaves, nm_device_get_type ),
),
);
static void
nm_device_ovs_port_class_init (NMDeviceOvsPortClass *ovs_port_class)
nm_device_ovs_port_class_init (NMDeviceOvsPortClass *klass)
{
GObjectClass *object_class = G_OBJECT_CLASS (ovs_port_class);
NMObjectClass *nm_object_class = NM_OBJECT_CLASS (ovs_port_class);
NMDeviceClass *device_class = NM_DEVICE_CLASS (ovs_port_class);
GObjectClass *object_class = G_OBJECT_CLASS (klass);
NMObjectClass *nm_object_class = NM_OBJECT_CLASS (klass);
NMDeviceClass *device_class = NM_DEVICE_CLASS (klass);
object_class->get_property = get_property;
object_class->dispose = dispose;
nm_object_class->init_dbus = init_dbus;
_NM_OBJECT_CLASS_INIT_PRIV_PTR_DIRECT (nm_object_class, NMDeviceOvsPort);
_NM_OBJECT_CLASS_INIT_PROPERTY_AO_FIELDS_1 (nm_object_class, NMDeviceOvsPortPrivate, slaves);
device_class->get_type_description = get_type_description;
device_class->connection_compatible = connection_compatible;
@ -175,5 +160,5 @@ nm_device_ovs_port_class_init (NMDeviceOvsPortClass *ovs_port_class)
G_PARAM_READABLE |
G_PARAM_STATIC_STRINGS);
g_object_class_install_properties (object_class, _PROPERTY_ENUMS_LAST, obj_properties);
_nml_dbus_meta_class_init_with_properties (object_class, &_nml_dbus_meta_iface_nm_device_ovsport);
}

View file

@ -6,6 +6,7 @@
#include "nm-default.h"
#include "nm-device-ppp.h"
#include "nm-device.h"
/*****************************************************************************/
@ -27,6 +28,12 @@ nm_device_ppp_init (NMDevicePpp *device)
{
}
const NMLDBusMetaIface _nml_dbus_meta_iface_nm_device_ppp = NML_DBUS_META_IFACE_INIT (
NM_DBUS_INTERFACE_DEVICE_PPP,
nm_device_ppp_get_type,
NML_DBUS_META_INTERFACE_PRIO_INSTANTIATE_HIGH,
);
static void
nm_device_ppp_class_init (NMDevicePppClass *klass)
{

View file

@ -23,10 +23,10 @@ NM_GOBJECT_PROPERTIES_DEFINE_BASE (
);
typedef struct {
NMLDBusPropertyAO slaves;
char *hw_address;
gboolean carrier;
GPtrArray *slaves;
char *config;
bool carrier;
} NMDeviceTeamPrivate;
struct _NMDeviceTeam {
@ -92,7 +92,7 @@ nm_device_team_get_slaves (NMDeviceTeam *device)
{
g_return_val_if_fail (NM_IS_DEVICE_TEAM (device), FALSE);
return NM_DEVICE_TEAM_GET_PRIVATE (device)->slaves;
return nml_dbus_property_ao_get_objs_as_ptrarray (&NM_DEVICE_TEAM_GET_PRIVATE (device)->slaves);
}
/**
@ -148,38 +148,6 @@ get_setting_type (NMDevice *device)
static void
nm_device_team_init (NMDeviceTeam *device)
{
NMDeviceTeamPrivate *priv = NM_DEVICE_TEAM_GET_PRIVATE (device);
priv->slaves = g_ptr_array_new ();
}
static void
init_dbus (NMObject *object)
{
NMDeviceTeamPrivate *priv = NM_DEVICE_TEAM_GET_PRIVATE (object);
const NMPropertiesInfo property_info[] = {
{ NM_DEVICE_TEAM_HW_ADDRESS, &priv->hw_address },
{ NM_DEVICE_TEAM_CARRIER, &priv->carrier },
{ NM_DEVICE_TEAM_SLAVES, &priv->slaves, NULL, NM_TYPE_DEVICE },
{ NM_DEVICE_TEAM_CONFIG, &priv->config },
{ NULL },
};
NM_OBJECT_CLASS (nm_device_team_parent_class)->init_dbus (object);
_nm_object_register_properties (object,
NM_DBUS_INTERFACE_DEVICE_TEAM,
property_info);
}
static void
dispose (GObject *object)
{
NMDeviceTeamPrivate *priv = NM_DEVICE_TEAM_GET_PRIVATE (object);
g_clear_pointer (&priv->slaves, g_ptr_array_unref);
G_OBJECT_CLASS (nm_device_team_parent_class)->dispose (object);
}
static void
@ -220,18 +188,31 @@ get_property (GObject *object,
}
}
const NMLDBusMetaIface _nml_dbus_meta_iface_nm_device_team = NML_DBUS_META_IFACE_INIT_PROP (
NM_DBUS_INTERFACE_DEVICE_TEAM,
nm_device_team_get_type,
NML_DBUS_META_INTERFACE_PRIO_INSTANTIATE_HIGH,
NML_DBUS_META_IFACE_DBUS_PROPERTIES (
NML_DBUS_META_PROPERTY_INIT_B ("Carrier", PROP_CARRIER, NMDeviceTeam, _priv.carrier ),
NML_DBUS_META_PROPERTY_INIT_S ("Config", PROP_CONFIG, NMDeviceTeam, _priv.config ),
NML_DBUS_META_PROPERTY_INIT_S ("HwAddress", PROP_HW_ADDRESS, NMDeviceTeam, _priv.hw_address ),
NML_DBUS_META_PROPERTY_INIT_AO_PROP ("Slaves", PROP_SLAVES, NMDeviceTeam, _priv.slaves, nm_device_get_type ),
),
);
static void
nm_device_team_class_init (NMDeviceTeamClass *team_class)
nm_device_team_class_init (NMDeviceTeamClass *klass)
{
GObjectClass *object_class = G_OBJECT_CLASS (team_class);
NMObjectClass *nm_object_class = NM_OBJECT_CLASS (team_class);
NMDeviceClass *device_class = NM_DEVICE_CLASS (team_class);
GObjectClass *object_class = G_OBJECT_CLASS (klass);
NMObjectClass *nm_object_class = NM_OBJECT_CLASS (klass);
NMDeviceClass *device_class = NM_DEVICE_CLASS (klass);
object_class->get_property = get_property;
object_class->dispose = dispose;
object_class->finalize = finalize;
nm_object_class->init_dbus = init_dbus;
_NM_OBJECT_CLASS_INIT_PRIV_PTR_DIRECT (nm_object_class, NMDeviceTeam);
_NM_OBJECT_CLASS_INIT_PROPERTY_AO_FIELDS_1 (nm_object_class, NMDeviceTeamPrivate, slaves);
device_class->connection_compatible = connection_compatible;
device_class->get_setting_type = get_setting_type;
@ -283,5 +264,5 @@ nm_device_team_class_init (NMDeviceTeamClass *team_class)
G_PARAM_READABLE |
G_PARAM_STATIC_STRINGS);
g_object_class_install_properties (object_class, _PROPERTY_ENUMS_LAST, obj_properties);
_nml_dbus_meta_class_init_with_properties (object_class, &_nml_dbus_meta_iface_nm_device_team);
}

View file

@ -31,9 +31,9 @@ typedef struct {
char *mode;
gint64 owner;
gint64 group;
gboolean no_pi;
gboolean vnet_hdr;
gboolean multi_queue;
bool no_pi;
bool vnet_hdr;
bool multi_queue;
} NMDeviceTunPrivate;
struct _NMDeviceTun {
@ -234,28 +234,6 @@ nm_device_tun_init (NMDeviceTun *device)
{
}
static void
init_dbus (NMObject *object)
{
NMDeviceTunPrivate *priv = NM_DEVICE_TUN_GET_PRIVATE (object);
const NMPropertiesInfo property_info[] = {
{ NM_DEVICE_TUN_HW_ADDRESS, &priv->hw_address },
{ NM_DEVICE_TUN_MODE, &priv->mode },
{ NM_DEVICE_TUN_OWNER, &priv->owner },
{ NM_DEVICE_TUN_GROUP, &priv->group },
{ NM_DEVICE_TUN_NO_PI, &priv->no_pi },
{ NM_DEVICE_TUN_VNET_HDR, &priv->vnet_hdr },
{ NM_DEVICE_TUN_MULTI_QUEUE, &priv->multi_queue },
{ NULL },
};
NM_OBJECT_CLASS (nm_device_tun_parent_class)->init_dbus (object);
_nm_object_register_properties (object,
NM_DBUS_INTERFACE_DEVICE_TUN,
property_info);
}
static void
finalize (GObject *object)
{
@ -304,18 +282,30 @@ get_property (GObject *object,
}
}
const NMLDBusMetaIface _nml_dbus_meta_iface_nm_device_tun = NML_DBUS_META_IFACE_INIT_PROP (
NM_DBUS_INTERFACE_DEVICE_TUN,
nm_device_tun_get_type,
NML_DBUS_META_INTERFACE_PRIO_INSTANTIATE_HIGH,
NML_DBUS_META_IFACE_DBUS_PROPERTIES (
NML_DBUS_META_PROPERTY_INIT_X ("Group", PROP_GROUP, NMDeviceTun, _priv.group ),
NML_DBUS_META_PROPERTY_INIT_S ("HwAddress", PROP_HW_ADDRESS, NMDeviceTun, _priv.hw_address ),
NML_DBUS_META_PROPERTY_INIT_S ("Mode", PROP_MODE, NMDeviceTun, _priv.mode ),
NML_DBUS_META_PROPERTY_INIT_B ("MultiQueue", PROP_MULTI_QUEUE, NMDeviceTun, _priv.multi_queue ),
NML_DBUS_META_PROPERTY_INIT_B ("NoPi", PROP_NO_PI, NMDeviceTun, _priv.no_pi ),
NML_DBUS_META_PROPERTY_INIT_X ("Owner", PROP_OWNER, NMDeviceTun, _priv.owner ),
NML_DBUS_META_PROPERTY_INIT_B ("VnetHdr", PROP_VNET_HDR, NMDeviceTun, _priv.vnet_hdr ),
),
);
static void
nm_device_tun_class_init (NMDeviceTunClass *gre_class)
{
GObjectClass *object_class = G_OBJECT_CLASS (gre_class);
NMObjectClass *nm_object_class = NM_OBJECT_CLASS (gre_class);
NMDeviceClass *device_class = NM_DEVICE_CLASS (gre_class);
object_class->get_property = get_property;
object_class->finalize = finalize;
nm_object_class->init_dbus = init_dbus;
device_class->connection_compatible = connection_compatible;
device_class->get_setting_type = get_setting_type;
device_class->get_hw_address = get_hw_address;
@ -415,5 +405,5 @@ nm_device_tun_class_init (NMDeviceTunClass *gre_class)
G_PARAM_READABLE |
G_PARAM_STATIC_STRINGS);
g_object_class_install_properties (object_class, _PROPERTY_ENUMS_LAST, obj_properties);
_nml_dbus_meta_class_init_with_properties (object_class, &_nml_dbus_meta_iface_nm_device_tun);
}

View file

@ -23,10 +23,10 @@ NM_GOBJECT_PROPERTIES_DEFINE_BASE (
);
typedef struct {
NMLDBusPropertyO parent;
char *hw_address;
gboolean carrier;
NMDevice *parent;
guint vlan_id;
guint32 vlan_id;
bool carrier;
} NMDeviceVlanPrivate;
struct _NMDeviceVlan {
@ -88,7 +88,7 @@ nm_device_vlan_get_parent (NMDeviceVlan *device)
{
g_return_val_if_fail (NM_IS_DEVICE_VLAN (device), FALSE);
return NM_DEVICE_VLAN_GET_PRIVATE (device)->parent;
return nml_dbus_property_o_get_obj (&NM_DEVICE_VLAN_GET_PRIVATE (device)->parent);
}
/**
@ -166,32 +166,12 @@ nm_device_vlan_init (NMDeviceVlan *device)
{
}
static void
init_dbus (NMObject *object)
{
NMDeviceVlanPrivate *priv = NM_DEVICE_VLAN_GET_PRIVATE (object);
const NMPropertiesInfo property_info[] = {
{ NM_DEVICE_VLAN_HW_ADDRESS, &priv->hw_address },
{ NM_DEVICE_VLAN_CARRIER, &priv->carrier },
{ NM_DEVICE_VLAN_PARENT, &priv->parent, NULL, NM_TYPE_DEVICE },
{ NM_DEVICE_VLAN_VLAN_ID, &priv->vlan_id },
{ NULL },
};
NM_OBJECT_CLASS (nm_device_vlan_parent_class)->init_dbus (object);
_nm_object_register_properties (object,
NM_DBUS_INTERFACE_DEVICE_VLAN,
property_info);
}
static void
finalize (GObject *object)
{
NMDeviceVlanPrivate *priv = NM_DEVICE_VLAN_GET_PRIVATE (object);
g_free (priv->hw_address);
g_clear_object (&priv->parent);
G_OBJECT_CLASS (nm_device_vlan_parent_class)->finalize (object);
}
@ -223,17 +203,31 @@ get_property (GObject *object,
}
}
const NMLDBusMetaIface _nml_dbus_meta_iface_nm_device_vlan = NML_DBUS_META_IFACE_INIT_PROP (
NM_DBUS_INTERFACE_DEVICE_VLAN,
nm_device_vlan_get_type,
NML_DBUS_META_INTERFACE_PRIO_INSTANTIATE_HIGH,
NML_DBUS_META_IFACE_DBUS_PROPERTIES (
NML_DBUS_META_PROPERTY_INIT_B ("Carrier", PROP_CARRIER, NMDeviceVlan, _priv.carrier ),
NML_DBUS_META_PROPERTY_INIT_S ("HwAddress", PROP_HW_ADDRESS, NMDeviceVlan, _priv.hw_address ),
NML_DBUS_META_PROPERTY_INIT_O_PROP ("Parent", PROP_PARENT, NMDeviceVlan, _priv.parent, nm_device_get_type ),
NML_DBUS_META_PROPERTY_INIT_U ("VlanId", PROP_VLAN_ID, NMDeviceVlan, _priv.vlan_id ),
),
);
static void
nm_device_vlan_class_init (NMDeviceVlanClass *vlan_class)
nm_device_vlan_class_init (NMDeviceVlanClass *klass)
{
GObjectClass *object_class = G_OBJECT_CLASS (vlan_class);
NMObjectClass *nm_object_class = NM_OBJECT_CLASS (vlan_class);
NMDeviceClass *device_class = NM_DEVICE_CLASS (vlan_class);
GObjectClass *object_class = G_OBJECT_CLASS (klass);
NMObjectClass *nm_object_class = NM_OBJECT_CLASS (klass);
NMDeviceClass *device_class = NM_DEVICE_CLASS (klass);
object_class->get_property = get_property;
object_class->finalize = finalize;
nm_object_class->init_dbus = init_dbus;
_NM_OBJECT_CLASS_INIT_PRIV_PTR_DIRECT (nm_object_class, NMDeviceVlan);
_NM_OBJECT_CLASS_INIT_PROPERTY_O_FIELDS_1 (nm_object_class, NMDeviceVlanPrivate, parent);
device_class->connection_compatible = connection_compatible;
device_class->get_setting_type = get_setting_type;
@ -283,5 +277,5 @@ nm_device_vlan_class_init (NMDeviceVlanClass *vlan_class)
G_PARAM_READABLE |
G_PARAM_STATIC_STRINGS);
g_object_class_install_properties (object_class, _PROPERTY_ENUMS_LAST, obj_properties);
_nml_dbus_meta_class_init_with_properties (object_class, &_nml_dbus_meta_iface_nm_device_vlan);
}

View file

@ -36,23 +36,23 @@ NM_GOBJECT_PROPERTIES_DEFINE_BASE (
);
typedef struct {
NMDevice *parent;
NMLDBusPropertyO parent;
char *hw_address;
guint id;
char *group;
char *local;
guint src_port_min;
guint src_port_max;
guint dst_port;
guint tos;
guint ttl;
guint limit;
gboolean learning;
guint ageing;
gboolean proxy;
gboolean rsc;
gboolean l2miss;
gboolean l3miss;
guint32 id;
guint32 limit;
guint32 ageing;
guint16 src_port_min;
guint16 src_port_max;
guint16 dst_port;
guint8 tos;
guint8 ttl;
bool learning;
bool proxy;
bool rsc;
bool l2miss;
bool l3miss;
} NMDeviceVxlanPrivate;
struct _NMDeviceVxlan {
@ -123,7 +123,7 @@ nm_device_vxlan_get_parent (NMDeviceVxlan *device)
{
g_return_val_if_fail (NM_IS_DEVICE_VXLAN (device), NULL);
return NM_DEVICE_VXLAN_GET_PRIVATE (device)->parent;
return nml_dbus_property_o_get_obj (&NM_DEVICE_VXLAN_GET_PRIVATE (device)->parent);
}
/**
@ -411,45 +411,12 @@ nm_device_vxlan_init (NMDeviceVxlan *device)
{
}
static void
init_dbus (NMObject *object)
{
NMDeviceVxlanPrivate *priv = NM_DEVICE_VXLAN_GET_PRIVATE (object);
const NMPropertiesInfo property_info[] = {
{ NM_DEVICE_VXLAN_HW_ADDRESS, &priv->hw_address },
{ NM_DEVICE_VXLAN_PARENT, &priv->parent, NULL, NM_TYPE_DEVICE },
{ NM_DEVICE_VXLAN_ID, &priv->id },
{ NM_DEVICE_VXLAN_GROUP, &priv->group },
{ NM_DEVICE_VXLAN_LOCAL, &priv->local },
{ NM_DEVICE_VXLAN_SRC_PORT_MIN, &priv->src_port_min },
{ NM_DEVICE_VXLAN_SRC_PORT_MAX, &priv->src_port_max },
{ NM_DEVICE_VXLAN_DST_PORT, &priv->dst_port },
{ NM_DEVICE_VXLAN_TOS, &priv->tos },
{ NM_DEVICE_VXLAN_TTL, &priv->ttl },
{ NM_DEVICE_VXLAN_LIMIT, &priv->limit },
{ NM_DEVICE_VXLAN_LEARNING, &priv->learning },
{ NM_DEVICE_VXLAN_AGEING, &priv->ageing },
{ NM_DEVICE_VXLAN_PROXY, &priv->proxy },
{ NM_DEVICE_VXLAN_RSC, &priv->rsc },
{ NM_DEVICE_VXLAN_L2MISS, &priv->l2miss },
{ NM_DEVICE_VXLAN_L3MISS, &priv->l3miss },
{ NULL },
};
NM_OBJECT_CLASS (nm_device_vxlan_parent_class)->init_dbus (object);
_nm_object_register_properties (object,
NM_DBUS_INTERFACE_DEVICE_VXLAN,
property_info);
}
static void
finalize (GObject *object)
{
NMDeviceVxlanPrivate *priv = NM_DEVICE_VXLAN_GET_PRIVATE (object);
g_free (priv->hw_address);
g_clear_object (&priv->parent);
g_free (priv->group);
g_free (priv->local);
@ -525,17 +492,44 @@ get_property (GObject *object,
}
}
const NMLDBusMetaIface _nml_dbus_meta_iface_nm_device_vxlan = NML_DBUS_META_IFACE_INIT_PROP (
NM_DBUS_INTERFACE_DEVICE_VXLAN,
nm_device_vxlan_get_type,
NML_DBUS_META_INTERFACE_PRIO_INSTANTIATE_HIGH,
NML_DBUS_META_IFACE_DBUS_PROPERTIES (
NML_DBUS_META_PROPERTY_INIT_U ("Ageing", PROP_AGEING, NMDeviceVxlan, _priv.ageing ),
NML_DBUS_META_PROPERTY_INIT_Q ("DstPort", PROP_DST_PORT, NMDeviceVxlan, _priv.dst_port ),
NML_DBUS_META_PROPERTY_INIT_S ("Group", PROP_GROUP, NMDeviceVxlan, _priv.group ),
NML_DBUS_META_PROPERTY_INIT_S ("HwAddress", PROP_HW_ADDRESS, NMDeviceVxlan, _priv.hw_address ),
NML_DBUS_META_PROPERTY_INIT_U ("Id", PROP_ID, NMDeviceVxlan, _priv.id ),
NML_DBUS_META_PROPERTY_INIT_B ("L2miss", PROP_L2MISS, NMDeviceVxlan, _priv.l2miss ),
NML_DBUS_META_PROPERTY_INIT_B ("L3miss", PROP_L3MISS, NMDeviceVxlan, _priv.l3miss ),
NML_DBUS_META_PROPERTY_INIT_B ("Learning", PROP_LEARNING, NMDeviceVxlan, _priv.learning ),
NML_DBUS_META_PROPERTY_INIT_U ("Limit", PROP_LIMIT, NMDeviceVxlan, _priv.limit ),
NML_DBUS_META_PROPERTY_INIT_S ("Local", PROP_LOCAL, NMDeviceVxlan, _priv.local ),
NML_DBUS_META_PROPERTY_INIT_O_PROP ("Parent", PROP_PARENT, NMDeviceVxlan, _priv.parent, nm_device_get_type ),
NML_DBUS_META_PROPERTY_INIT_B ("Proxy", PROP_PROXY, NMDeviceVxlan, _priv.proxy ),
NML_DBUS_META_PROPERTY_INIT_B ("Rsc", PROP_RSC, NMDeviceVxlan, _priv.rsc ),
NML_DBUS_META_PROPERTY_INIT_Q ("SrcPortMax", PROP_SRC_PORT_MAX, NMDeviceVxlan, _priv.src_port_max ),
NML_DBUS_META_PROPERTY_INIT_Q ("SrcPortMin", PROP_SRC_PORT_MIN, NMDeviceVxlan, _priv.src_port_min ),
NML_DBUS_META_PROPERTY_INIT_Y ("Tos", PROP_TOS, NMDeviceVxlan, _priv.tos ),
NML_DBUS_META_PROPERTY_INIT_Y ("Ttl", PROP_TTL, NMDeviceVxlan, _priv.ttl ),
),
);
static void
nm_device_vxlan_class_init (NMDeviceVxlanClass *vxlan_class)
nm_device_vxlan_class_init (NMDeviceVxlanClass *klass)
{
GObjectClass *object_class = G_OBJECT_CLASS (vxlan_class);
NMObjectClass *nm_object_class = NM_OBJECT_CLASS (vxlan_class);
NMDeviceClass *device_class = NM_DEVICE_CLASS (vxlan_class);
GObjectClass *object_class = G_OBJECT_CLASS (klass);
NMObjectClass *nm_object_class = NM_OBJECT_CLASS (klass);
NMDeviceClass *device_class = NM_DEVICE_CLASS (klass);
object_class->get_property = get_property;
object_class->finalize = finalize;
nm_object_class->init_dbus = init_dbus;
_NM_OBJECT_CLASS_INIT_PRIV_PTR_DIRECT (nm_object_class, NMDeviceVxlan);
_NM_OBJECT_CLASS_INIT_PROPERTY_O_FIELDS_1 (nm_object_class, NMDeviceVxlanPrivate, parent);
device_class->connection_compatible = connection_compatible;
device_class->get_setting_type = get_setting_type;
@ -783,5 +777,5 @@ nm_device_vxlan_class_init (NMDeviceVxlanClass *vxlan_class)
G_PARAM_READABLE |
G_PARAM_STATIC_STRINGS);
g_object_class_install_properties (object_class, _PROPERTY_ENUMS_LAST, obj_properties);
_nml_dbus_meta_class_init_with_properties (object_class, &_nml_dbus_meta_iface_nm_device_vxlan);
}

View file

@ -16,8 +16,6 @@
#include "nm-core-internal.h"
#include "nm-dbus-helpers.h"
#include "introspection/org.freedesktop.NetworkManager.Device.WifiP2P.h"
/*****************************************************************************/
NM_GOBJECT_PROPERTIES_DEFINE_BASE (
@ -35,11 +33,8 @@ enum {
static guint signals[LAST_SIGNAL] = { 0 };
typedef struct {
NMDBusDeviceWifiP2P *proxy;
NMLDBusPropertyAO peers;
char *hw_address;
GPtrArray *peers;
} NMDeviceWifiP2PPrivate;
struct _NMDeviceWifiP2P {
@ -93,7 +88,7 @@ nm_device_wifi_p2p_get_peers (NMDeviceWifiP2P *device)
{
g_return_val_if_fail (NM_IS_DEVICE_WIFI_P2P (device), NULL);
return NM_DEVICE_WIFI_P2P_GET_PRIVATE (device)->peers;
return nml_dbus_property_ao_get_objs_as_ptrarray (&NM_DEVICE_WIFI_P2P_GET_PRIVATE (device)->peers);
}
/**
@ -164,7 +159,8 @@ nm_device_wifi_p2p_start_find (NMDeviceWifiP2P *device,
if (!options)
options = g_variant_new_array (G_VARIANT_TYPE ("{sv}"), NULL, 0);
_nm_object_dbus_call (device,
_nm_client_dbus_call (_nm_object_get_client (device),
device,
nm_device_wifi_p2p_start_find,
cancellable,
callback,
@ -222,7 +218,8 @@ nm_device_wifi_p2p_stop_find (NMDeviceWifiP2P *device,
g_return_if_fail (NM_IS_DEVICE_WIFI_P2P (device));
g_return_if_fail (!cancellable || G_IS_CANCELLABLE (cancellable));
_nm_object_dbus_call (device,
_nm_client_dbus_call (_nm_object_get_client (device),
device,
nm_device_wifi_p2p_stop_find,
cancellable,
callback,
@ -260,21 +257,6 @@ nm_device_wifi_p2p_stop_find_finish (NMDeviceWifiP2P *device,
return g_task_propagate_boolean (G_TASK (result), error);
}
static void
clean_up_peers (NMDeviceWifiP2P *self)
{
NMDeviceWifiP2PPrivate *priv = NM_DEVICE_WIFI_P2P_GET_PRIVATE (self);
while (priv->peers->len > 0) {
NMWifiP2PPeer *peer;
peer = priv->peers->pdata[priv->peers->len - 1];
g_ptr_array_remove_index (priv->peers, priv->peers->len - 1);
g_signal_emit (self, signals[PEER_REMOVED], 0, peer);
}
}
static gboolean
connection_compatible (NMDevice *device, NMConnection *connection, GError **error)
{
@ -310,6 +292,24 @@ get_type_description (NMDevice *device)
/*****************************************************************************/
static void
_property_ao_notify_changed_peers_cb (NMLDBusPropertyAO *pr_ao,
NMClient *client,
NMObject *nmobj,
gboolean is_added /* or else removed */)
{
_nm_client_notify_event_queue_emit_obj_signal (client,
G_OBJECT (pr_ao->owner_dbobj->nmobj),
nmobj,
is_added,
10,
is_added
? signals[PEER_ADDED]
: signals[PEER_REMOVED]);
}
/*****************************************************************************/
static void
get_property (GObject *object,
guint prop_id,
@ -331,38 +331,11 @@ get_property (GObject *object,
}
}
/*****************************************************************************/
static void
nm_device_wifi_p2p_init (NMDeviceWifiP2P *device)
{
NMDeviceWifiP2PPrivate *priv = NM_DEVICE_WIFI_P2P_GET_PRIVATE (device);
priv->peers = g_ptr_array_new ();
}
static void
init_dbus (NMObject *object)
{
NMDeviceWifiP2PPrivate *priv = NM_DEVICE_WIFI_P2P_GET_PRIVATE (object);
const NMPropertiesInfo property_info[] = {
{ NM_DEVICE_WIFI_P2P_HW_ADDRESS, &priv->hw_address },
{ NM_DEVICE_WIFI_P2P_PEERS, &priv->peers, NULL, NM_TYPE_WIFI_P2P_PEER, "peer" },
{ NULL },
};
NM_OBJECT_CLASS (nm_device_wifi_p2p_parent_class)->init_dbus (object);
priv->proxy = NMDBUS_DEVICE_WIFI_P2P (_nm_object_get_proxy (object, NM_DBUS_INTERFACE_DEVICE_WIFI_P2P));
_nm_object_register_properties (object,
NM_DBUS_INTERFACE_DEVICE_WIFI_P2P,
property_info);
}
static void
dispose (GObject *object)
{
clean_up_peers (NM_DEVICE_WIFI_P2P (object));
G_OBJECT_CLASS (nm_device_wifi_p2p_parent_class)->dispose (object);
}
static void
@ -370,32 +343,40 @@ finalize (GObject *object)
{
NMDeviceWifiP2PPrivate *priv = NM_DEVICE_WIFI_P2P_GET_PRIVATE (object);
g_clear_object (&priv->proxy);
g_free (priv->hw_address);
if (priv->peers)
g_ptr_array_unref (priv->peers);
G_OBJECT_CLASS (nm_device_wifi_p2p_parent_class)->finalize (object);
}
const NMLDBusMetaIface _nml_dbus_meta_iface_nm_device_wifip2p = NML_DBUS_META_IFACE_INIT_PROP (
NM_DBUS_INTERFACE_DEVICE_WIFI_P2P,
nm_device_wifi_p2p_get_type,
NML_DBUS_META_INTERFACE_PRIO_INSTANTIATE_HIGH,
NML_DBUS_META_IFACE_DBUS_PROPERTIES (
NML_DBUS_META_PROPERTY_INIT_S ("HwAddress", PROP_HW_ADDRESS, NMDeviceWifiP2P, _priv.hw_address ),
NML_DBUS_META_PROPERTY_INIT_AO_PROP ("Peers", PROP_PEERS, NMDeviceWifiP2P, _priv.peers, nm_wifi_p2p_peer_get_type, .notify_changed_ao = _property_ao_notify_changed_peers_cb ),
),
);
static void
nm_device_wifi_p2p_class_init (NMDeviceWifiP2PClass *wifi_class)
nm_device_wifi_p2p_class_init (NMDeviceWifiP2PClass *klass)
{
GObjectClass *object_class = G_OBJECT_CLASS (wifi_class);
NMObjectClass *nm_object_class = NM_OBJECT_CLASS (wifi_class);
NMDeviceClass *device_class = NM_DEVICE_CLASS (wifi_class);
GObjectClass *object_class = G_OBJECT_CLASS (klass);
NMObjectClass *nm_object_class = NM_OBJECT_CLASS (klass);
NMDeviceClass *device_class = NM_DEVICE_CLASS (klass);
object_class->get_property = get_property;
object_class->dispose = dispose;
object_class->finalize = finalize;
_NM_OBJECT_CLASS_INIT_PRIV_PTR_DIRECT (nm_object_class, NMDeviceWifiP2P);
_NM_OBJECT_CLASS_INIT_PROPERTY_AO_FIELDS_1 (nm_object_class, NMDeviceWifiP2PPrivate, peers);
device_class->connection_compatible = connection_compatible;
device_class->get_setting_type = get_setting_type;
device_class->get_hw_address = get_hw_address;
device_class->get_type_description = get_type_description;
nm_object_class->init_dbus = init_dbus;
/**
* NMDeviceWifiP2P:hw-address:
*
@ -422,7 +403,7 @@ nm_device_wifi_p2p_class_init (NMDeviceWifiP2PClass *wifi_class)
G_PARAM_READABLE |
G_PARAM_STATIC_STRINGS);
g_object_class_install_properties (object_class, _PROPERTY_ENUMS_LAST, obj_properties);
_nml_dbus_meta_class_init_with_properties (object_class, &_nml_dbus_meta_iface_nm_device_wifip2p);
/**
* NMDeviceWifiP2P::peer-added:

View file

@ -18,8 +18,6 @@
#include "nm-core-internal.h"
#include "nm-dbus-helpers.h"
#include "introspection/org.freedesktop.NetworkManager.Device.Wireless.h"
/*****************************************************************************/
NM_GOBJECT_PROPERTIES_DEFINE_BASE (
@ -27,23 +25,21 @@ NM_GOBJECT_PROPERTIES_DEFINE_BASE (
PROP_PERM_HW_ADDRESS,
PROP_MODE,
PROP_BITRATE,
PROP_ACCESS_POINTS,
PROP_ACTIVE_ACCESS_POINT,
PROP_WIRELESS_CAPABILITIES,
PROP_ACCESS_POINTS,
PROP_LAST_SCAN,
);
typedef struct {
NMDBusDeviceWifi *proxy;
NMLDBusPropertyAO access_points;
NMLDBusPropertyO active_access_point;
char *hw_address;
char *perm_hw_address;
NM80211Mode mode;
guint32 rate;
NMAccessPoint *active_ap;
NMDeviceWifiCapabilities wireless_caps;
GPtrArray *aps;
gint64 last_scan;
guint32 mode;
guint32 bitrate;
guint32 wireless_capabilities;
} NMDeviceWifiPrivate;
enum {
@ -55,7 +51,6 @@ enum {
static guint signals[LAST_SIGNAL] = { 0 };
struct _NMDeviceWifi {
NMDevice parent;
NMDeviceWifiPrivate _priv;
@ -63,8 +58,6 @@ struct _NMDeviceWifi {
struct _NMDeviceWifiClass {
NMDeviceClass parent;
void (*access_point_removed) (NMDeviceWifi *device, NMAccessPoint *ap);
};
G_DEFINE_TYPE (NMDeviceWifi, nm_device_wifi, NM_TYPE_DEVICE)
@ -73,11 +66,6 @@ G_DEFINE_TYPE (NMDeviceWifi, nm_device_wifi, NM_TYPE_DEVICE)
/*****************************************************************************/
void _nm_device_wifi_set_wireless_enabled (NMDeviceWifi *device, gboolean enabled);
static void state_changed_cb (NMDevice *device, GParamSpec *pspec, gpointer user_data);
/*****************************************************************************/
/**
* nm_device_wifi_get_hw_address:
* @device: a #NMDeviceWifi
@ -155,7 +143,7 @@ nm_device_wifi_get_bitrate (NMDeviceWifi *device)
return 0;
}
return NM_DEVICE_WIFI_GET_PRIVATE (device)->rate;
return NM_DEVICE_WIFI_GET_PRIVATE (device)->bitrate;
}
/**
@ -171,7 +159,7 @@ nm_device_wifi_get_capabilities (NMDeviceWifi *device)
{
g_return_val_if_fail (NM_IS_DEVICE_WIFI (device), 0);
return NM_DEVICE_WIFI_GET_PRIVATE (device)->wireless_caps;
return NM_DEVICE_WIFI_GET_PRIVATE (device)->wireless_capabilities;
}
/**
@ -185,27 +173,9 @@ nm_device_wifi_get_capabilities (NMDeviceWifi *device)
NMAccessPoint *
nm_device_wifi_get_active_access_point (NMDeviceWifi *device)
{
NMDeviceState state;
g_return_val_if_fail (NM_IS_DEVICE_WIFI (device), NULL);
state = nm_device_get_state (NM_DEVICE (device));
switch (state) {
case NM_DEVICE_STATE_PREPARE:
case NM_DEVICE_STATE_CONFIG:
case NM_DEVICE_STATE_NEED_AUTH:
case NM_DEVICE_STATE_IP_CONFIG:
case NM_DEVICE_STATE_IP_CHECK:
case NM_DEVICE_STATE_SECONDARIES:
case NM_DEVICE_STATE_ACTIVATED:
case NM_DEVICE_STATE_DEACTIVATING:
break;
default:
return NULL;
break;
}
return NM_DEVICE_WIFI_GET_PRIVATE (device)->active_ap;
return nml_dbus_property_o_get_obj (&NM_DEVICE_WIFI_GET_PRIVATE (device)->active_access_point);
}
/**
@ -223,7 +193,7 @@ nm_device_wifi_get_access_points (NMDeviceWifi *device)
{
g_return_val_if_fail (NM_IS_DEVICE_WIFI (device), NULL);
return NM_DEVICE_WIFI_GET_PRIVATE (device)->aps;
return nml_dbus_property_ao_get_objs_as_ptrarray (&NM_DEVICE_WIFI_GET_PRIVATE (device)->access_points);
}
/**
@ -342,9 +312,9 @@ nm_device_wifi_request_scan_options (NMDeviceWifi *device,
if (!options)
options = g_variant_new_array (G_VARIANT_TYPE ("{sv}"), NULL, 0);
return _nm_object_dbus_call_sync_void (device,
return _nm_client_dbus_call_sync_void (_nm_object_get_client (device),
cancellable,
g_dbus_proxy_get_object_path (G_DBUS_PROXY (NM_DEVICE_WIFI_GET_PRIVATE (device)->proxy)),
_nm_object_get_path (device),
NM_DBUS_INTERFACE_DEVICE_WIRELESS,
"RequestScan",
g_variant_new ("(@a{sv})", options),
@ -412,12 +382,13 @@ nm_device_wifi_request_scan_options_async (NMDeviceWifi *device,
if (!options)
options = g_variant_new_array (G_VARIANT_TYPE ("{sv}"), NULL, 0);
_nm_object_dbus_call (device,
_nm_client_dbus_call (_nm_object_get_client (device),
device,
nm_device_wifi_request_scan_async,
cancellable,
callback,
user_data,
g_dbus_proxy_get_object_path (G_DBUS_PROXY (NM_DEVICE_WIFI_GET_PRIVATE (device)->proxy)),
_nm_object_get_path (device),
NM_DBUS_INTERFACE_DEVICE_WIRELESS,
"RequestScan",
g_variant_new ("(@a{sv})", options),
@ -454,53 +425,6 @@ nm_device_wifi_request_scan_finish (NMDeviceWifi *device,
return g_task_propagate_boolean (G_TASK (result), error);
}
static void
clean_up_aps (NMDeviceWifi *self, gboolean in_dispose)
{
NMDeviceWifiPrivate *priv;
GPtrArray *aps;
int i;
g_return_if_fail (NM_IS_DEVICE_WIFI (self));
priv = NM_DEVICE_WIFI_GET_PRIVATE (self);
g_clear_object (&priv->active_ap);
aps = priv->aps;
if (in_dispose)
priv->aps = NULL;
else {
priv->aps = g_ptr_array_new ();
for (i = 0; i < aps->len; i++) {
NMAccessPoint *ap = NM_ACCESS_POINT (g_ptr_array_index (aps, i));
g_signal_emit (self, signals[ACCESS_POINT_REMOVED], 0, ap);
}
}
g_ptr_array_unref (aps);
}
/**
* _nm_device_wifi_set_wireless_enabled:
* @device: a #NMDeviceWifi
* @enabled: %TRUE to enable the device
*
* Enables or disables the wireless device.
**/
void
_nm_device_wifi_set_wireless_enabled (NMDeviceWifi *device,
gboolean enabled)
{
g_return_if_fail (NM_IS_DEVICE_WIFI (device));
if (!enabled)
clean_up_aps (device, FALSE);
}
#define WPA_CAPS (NM_WIFI_DEVICE_CAP_CIPHER_TKIP | \
NM_WIFI_DEVICE_CAP_CIPHER_CCMP | \
NM_WIFI_DEVICE_CAP_WPA | \
@ -599,17 +523,29 @@ get_hw_address (NMDevice *device)
/*****************************************************************************/
static void
_property_ao_notify_changed_access_points_cb (NMLDBusPropertyAO *pr_ao,
NMClient *client,
NMObject *nmobj,
gboolean is_added /* or else removed */)
{
_nm_client_notify_event_queue_emit_obj_signal (client,
G_OBJECT (pr_ao->owner_dbobj->nmobj),
nmobj,
is_added,
10,
is_added
? signals[ACCESS_POINT_ADDED]
: signals[ACCESS_POINT_REMOVED]);
}
/*****************************************************************************/
static void
nm_device_wifi_init (NMDeviceWifi *device)
{
NMDeviceWifiPrivate *priv = NM_DEVICE_WIFI_GET_PRIVATE (device);
g_signal_connect (device,
"notify::" NM_DEVICE_STATE,
G_CALLBACK (state_changed_cb),
NULL);
priv->aps = g_ptr_array_new ();
priv->last_scan = -1;
}
@ -652,80 +588,6 @@ get_property (GObject *object,
}
}
static void
state_changed_cb (NMDevice *device, GParamSpec *pspec, gpointer user_data)
{
NMDeviceWifi *self = NM_DEVICE_WIFI (device);
NMDeviceWifiPrivate *priv = NM_DEVICE_WIFI_GET_PRIVATE (self);
switch (nm_device_get_state (device)) {
case NM_DEVICE_STATE_UNKNOWN:
case NM_DEVICE_STATE_UNMANAGED:
case NM_DEVICE_STATE_UNAVAILABLE:
case NM_DEVICE_STATE_DISCONNECTED:
case NM_DEVICE_STATE_FAILED:
/* Just clear active AP; don't clear the AP list unless wireless is disabled completely */
g_clear_object (&priv->active_ap);
_nm_object_queue_notify (NM_OBJECT (device), NM_DEVICE_WIFI_ACTIVE_ACCESS_POINT);
priv->rate = 0;
_nm_object_queue_notify (NM_OBJECT (device), NM_DEVICE_WIFI_BITRATE);
break;
default:
break;
}
}
static void
init_dbus (NMObject *object)
{
NMDeviceWifiPrivate *priv = NM_DEVICE_WIFI_GET_PRIVATE (object);
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, NULL, NM_TYPE_ACCESS_POINT },
{ NM_DEVICE_WIFI_CAPABILITIES, &priv->wireless_caps },
{ NM_DEVICE_WIFI_ACCESS_POINTS, &priv->aps, NULL, NM_TYPE_ACCESS_POINT, "access-point" },
{ NM_DEVICE_WIFI_LAST_SCAN, &priv->last_scan },
{ NULL },
};
NM_OBJECT_CLASS (nm_device_wifi_parent_class)->init_dbus (object);
priv->proxy = NMDBUS_DEVICE_WIFI (_nm_object_get_proxy (object, NM_DBUS_INTERFACE_DEVICE_WIRELESS));
_nm_object_register_properties (object,
NM_DBUS_INTERFACE_DEVICE_WIRELESS,
property_info);
}
static void
access_point_removed (NMDeviceWifi *self, NMAccessPoint *ap)
{
NMDeviceWifiPrivate *priv = NM_DEVICE_WIFI_GET_PRIVATE (self);
if (ap == priv->active_ap) {
g_clear_object (&priv->active_ap);
_nm_object_queue_notify (NM_OBJECT (self), NM_DEVICE_WIFI_ACTIVE_ACCESS_POINT);
priv->rate = 0;
_nm_object_queue_notify (NM_OBJECT (self), NM_DEVICE_WIFI_BITRATE);
}
}
static void
dispose (GObject *object)
{
NMDeviceWifiPrivate *priv = NM_DEVICE_WIFI_GET_PRIVATE (object);
if (priv->aps)
clean_up_aps (NM_DEVICE_WIFI (object), TRUE);
g_clear_object (&priv->proxy);
G_OBJECT_CLASS (nm_device_wifi_parent_class)->dispose (object);
}
static void
finalize (GObject *object)
{
@ -737,25 +599,41 @@ finalize (GObject *object)
G_OBJECT_CLASS (nm_device_wifi_parent_class)->finalize (object);
}
const NMLDBusMetaIface _nml_dbus_meta_iface_nm_device_wireless = NML_DBUS_META_IFACE_INIT_PROP (
NM_DBUS_INTERFACE_DEVICE_WIRELESS,
nm_device_wifi_get_type,
NML_DBUS_META_INTERFACE_PRIO_INSTANTIATE_HIGH,
NML_DBUS_META_IFACE_DBUS_PROPERTIES (
NML_DBUS_META_PROPERTY_INIT_AO_PROP ("AccessPoints", PROP_ACCESS_POINTS, NMDeviceWifi, _priv.access_points, nm_access_point_get_type, .notify_changed_ao = _property_ao_notify_changed_access_points_cb ),
NML_DBUS_META_PROPERTY_INIT_O_PROP ("ActiveAccessPoint", PROP_ACTIVE_ACCESS_POINT, NMDeviceWifi, _priv.active_access_point, nm_access_point_get_type ),
NML_DBUS_META_PROPERTY_INIT_U ("Bitrate", PROP_BITRATE, NMDeviceWifi, _priv.bitrate ),
NML_DBUS_META_PROPERTY_INIT_S ("HwAddress", PROP_HW_ADDRESS, NMDeviceWifi, _priv.hw_address ),
NML_DBUS_META_PROPERTY_INIT_X ("LastScan", PROP_LAST_SCAN, NMDeviceWifi, _priv.last_scan ),
NML_DBUS_META_PROPERTY_INIT_U ("Mode", PROP_MODE, NMDeviceWifi, _priv.mode ),
NML_DBUS_META_PROPERTY_INIT_S ("PermHwAddress", PROP_PERM_HW_ADDRESS, NMDeviceWifi, _priv.perm_hw_address ),
NML_DBUS_META_PROPERTY_INIT_U ("WirelessCapabilities", PROP_WIRELESS_CAPABILITIES, NMDeviceWifi, _priv.wireless_capabilities ),
),
);
static void
nm_device_wifi_class_init (NMDeviceWifiClass *wifi_class)
nm_device_wifi_class_init (NMDeviceWifiClass *klass)
{
GObjectClass *object_class = G_OBJECT_CLASS (wifi_class);
NMObjectClass *nm_object_class = NM_OBJECT_CLASS (wifi_class);
NMDeviceClass *device_class = NM_DEVICE_CLASS (wifi_class);
GObjectClass *object_class = G_OBJECT_CLASS (klass);
NMObjectClass *nm_object_class = NM_OBJECT_CLASS (klass);
NMDeviceClass *device_class = NM_DEVICE_CLASS (klass);
object_class->get_property = get_property;
object_class->dispose = dispose;
object_class->finalize = finalize;
nm_object_class->init_dbus = init_dbus;
_NM_OBJECT_CLASS_INIT_PRIV_PTR_DIRECT (nm_object_class, NMDeviceWifi);
_NM_OBJECT_CLASS_INIT_PROPERTY_O_FIELDS_1 (nm_object_class, NMDeviceWifiPrivate, active_access_point);
_NM_OBJECT_CLASS_INIT_PROPERTY_AO_FIELDS_1 (nm_object_class, NMDeviceWifiPrivate, access_points);
device_class->connection_compatible = connection_compatible;
device_class->get_setting_type = get_setting_type;
device_class->get_hw_address = get_hw_address;
wifi_class->access_point_removed = access_point_removed;
/**
* NMDeviceWifi:hw-address:
*
@ -850,7 +728,7 @@ nm_device_wifi_class_init (NMDeviceWifiClass *wifi_class)
G_PARAM_READABLE |
G_PARAM_STATIC_STRINGS);
g_object_class_install_properties (object_class, _PROPERTY_ENUMS_LAST, obj_properties);
_nml_dbus_meta_class_init_with_properties (object_class, &_nml_dbus_meta_iface_nm_device_wireless);
/**
* NMDeviceWifi::access-point-added:
@ -879,8 +757,7 @@ nm_device_wifi_class_init (NMDeviceWifiClass *wifi_class)
g_signal_new ("access-point-removed",
G_OBJECT_CLASS_TYPE (object_class),
G_SIGNAL_RUN_FIRST,
G_STRUCT_OFFSET (NMDeviceWifiClass, access_point_removed),
NULL, NULL,
0, NULL, NULL,
g_cclosure_marshal_VOID__OBJECT,
G_TYPE_NONE, 1,
G_TYPE_OBJECT);

View file

@ -19,8 +19,8 @@ NM_GOBJECT_PROPERTIES_DEFINE_BASE (
typedef struct {
GBytes *public_key;
guint listen_port;
guint fwmark;
guint32 fwmark;
guint16 listen_port;
} NMDeviceWireGuardPrivate;
struct _NMDeviceWireGuard {
@ -125,24 +125,6 @@ nm_device_wireguard_init (NMDeviceWireGuard *device)
{
}
static void
init_dbus (NMObject *object)
{
NMDeviceWireGuardPrivate *priv = NM_DEVICE_WIREGUARD_GET_PRIVATE (object);
const NMPropertiesInfo property_info[] = {
{ NM_DEVICE_WIREGUARD_PUBLIC_KEY, &priv->public_key },
{ NM_DEVICE_WIREGUARD_LISTEN_PORT, &priv->listen_port },
{ NM_DEVICE_WIREGUARD_FWMARK, &priv->fwmark },
{ NULL }
};
NM_OBJECT_CLASS (nm_device_wireguard_parent_class)->init_dbus (object);
_nm_object_register_properties (object,
NM_DBUS_INTERFACE_DEVICE_WIREGUARD,
property_info);
}
static void
finalize (GObject *object)
{
@ -153,17 +135,25 @@ finalize (GObject *object)
G_OBJECT_CLASS (nm_device_wireguard_parent_class)->finalize (object);
}
const NMLDBusMetaIface _nml_dbus_meta_iface_nm_device_wireguard = NML_DBUS_META_IFACE_INIT_PROP (
NM_DBUS_INTERFACE_DEVICE_WIREGUARD,
nm_device_wireguard_get_type,
NML_DBUS_META_INTERFACE_PRIO_INSTANTIATE_HIGH,
NML_DBUS_META_IFACE_DBUS_PROPERTIES (
NML_DBUS_META_PROPERTY_INIT_U ("FwMark", PROP_FWMARK, NMDeviceWireGuard, _priv.fwmark ),
NML_DBUS_META_PROPERTY_INIT_Q ("ListenPort", PROP_LISTEN_PORT, NMDeviceWireGuard, _priv.listen_port ),
NML_DBUS_META_PROPERTY_INIT_AY ("PublicKey", PROP_PUBLIC_KEY, NMDeviceWireGuard, _priv.public_key ),
),
);
static void
nm_device_wireguard_class_init (NMDeviceWireGuardClass *wireguard_class)
{
GObjectClass *object_class = G_OBJECT_CLASS (wireguard_class);
NMObjectClass *nm_object_class = NM_OBJECT_CLASS (wireguard_class);
object_class->get_property = get_property;
object_class->finalize = finalize;
nm_object_class->init_dbus = init_dbus;
/**
* NMDeviceWireGuard:public-key:
*
@ -203,5 +193,5 @@ nm_device_wireguard_class_init (NMDeviceWireGuardClass *wireguard_class)
0, G_MAXUINT32, 0,
G_PARAM_READABLE | G_PARAM_STATIC_STRINGS);
g_object_class_install_properties (object_class, _PROPERTY_ENUMS_LAST, obj_properties);
_nml_dbus_meta_class_init_with_properties (object_class, &_nml_dbus_meta_iface_nm_device_wireguard);
}

View file

@ -48,9 +48,9 @@ G_DEFINE_TYPE (NMDeviceWpan, nm_device_wpan, NM_TYPE_DEVICE)
const char *
nm_device_wpan_get_hw_address (NMDeviceWpan *device)
{
g_return_val_if_fail (NM_IS_DEVICE_WPAN (device), NULL);
g_return_val_if_fail (NM_IS_DEVICE_WPAN (device), NULL);
return _nml_coerce_property_str_not_empty (NM_DEVICE_WPAN_GET_PRIVATE (device)->hw_address);
return _nml_coerce_property_str_not_empty (NM_DEVICE_WPAN_GET_PRIVATE (device)->hw_address);
}
static gboolean
@ -95,49 +95,41 @@ get_property (GObject *object, guint prop_id, GValue *value, GParamSpec *pspec)
}
}
/*****************************************************************************/
static void
nm_device_wpan_init (NMDeviceWpan *device)
{
}
static void
init_dbus (NMObject *object)
{
NMDeviceWpanPrivate *priv = NM_DEVICE_WPAN_GET_PRIVATE (object);
const NMPropertiesInfo property_info[] = {
{ NM_DEVICE_WPAN_HW_ADDRESS, &priv->hw_address },
{ NULL },
};
NM_OBJECT_CLASS (nm_device_wpan_parent_class)->init_dbus (object);
_nm_object_register_properties (object,
NM_DBUS_INTERFACE_DEVICE_WPAN,
property_info);
}
static void
finalize (GObject *object)
{
NMDeviceWpanPrivate *priv = NM_DEVICE_WPAN_GET_PRIVATE (object);
NMDeviceWpanPrivate *priv = NM_DEVICE_WPAN_GET_PRIVATE (object);
g_free (priv->hw_address);
g_free (priv->hw_address);
G_OBJECT_CLASS (nm_device_wpan_parent_class)->finalize (object);
G_OBJECT_CLASS (nm_device_wpan_parent_class)->finalize (object);
}
const NMLDBusMetaIface _nml_dbus_meta_iface_nm_device_wpan = NML_DBUS_META_IFACE_INIT_PROP (
NM_DBUS_INTERFACE_DEVICE_WPAN,
nm_device_wpan_get_type,
NML_DBUS_META_INTERFACE_PRIO_INSTANTIATE_HIGH,
NML_DBUS_META_IFACE_DBUS_PROPERTIES (
NML_DBUS_META_PROPERTY_INIT_S ("HwAddress", PROP_HW_ADDRESS, NMDeviceWpan, _priv.hw_address ),
),
);
static void
nm_device_wpan_class_init (NMDeviceWpanClass *wpan_class)
{
GObjectClass *object_class = G_OBJECT_CLASS (wpan_class);
NMObjectClass *nm_object_class = NM_OBJECT_CLASS (wpan_class);
NMDeviceClass *device_class = NM_DEVICE_CLASS (wpan_class);
object_class->get_property = get_property;
object_class->finalize = finalize;
nm_object_class->init_dbus = init_dbus;
device_class->connection_compatible = connection_compatible;
device_class->get_setting_type = get_setting_type;
device_class->get_hw_address = get_hw_address;
@ -153,5 +145,5 @@ nm_device_wpan_class_init (NMDeviceWpanClass *wpan_class)
G_PARAM_READABLE |
G_PARAM_STATIC_STRINGS);
g_object_class_install_properties (object_class, _PROPERTY_ENUMS_LAST, obj_properties);
_nml_dbus_meta_class_init_with_properties (object_class, &_nml_dbus_meta_iface_nm_device_wpan);
}

View file

@ -27,11 +27,9 @@
#include "nm-setting-connection.h"
#include "nm-udev-aux/nm-udev-utils.h"
#include "introspection/org.freedesktop.NetworkManager.Device.h"
/*****************************************************************************/
NM_GOBJECT_PROPERTIES_DEFINE_BASE (
NM_GOBJECT_PROPERTIES_DEFINE (NMDevice,
PROP_INTERFACE,
PROP_UDI,
PROP_DRIVER,
@ -72,46 +70,51 @@ enum {
static guint signals[LAST_SIGNAL] = { 0 };
typedef struct _NMDevicePrivate {
NMDBusDevice *proxy;
enum {
PROPERTY_O_IDX_ACTIVE_CONNECTION,
PROPERTY_O_IDX_IP4_CONFIG,
PROPERTY_O_IDX_IP6_CONFIG,
PROPERTY_O_IDX_DHCP4_CONFIG,
PROPERTY_O_IDX_DHCP6_CONFIG,
_PROPERTY_O_IDX_NUM,
};
char *iface;
char *ip_iface;
NMDeviceType device_type;
char *udi;
typedef struct _NMDevicePrivate {
NMLDBusPropertyO property_o[_PROPERTY_O_IDX_NUM];
NMLDBusPropertyAO available_connections;
GPtrArray *lldp_neighbors;
char *driver;
char *driver_version;
char *interface;
char *ip_interface;
char *firmware_version;
char *type_description;
NMMetered metered;
NMDeviceCapabilities capabilities;
gboolean real;
gboolean managed;
gboolean firmware_missing;
gboolean nm_plugin_missing;
gboolean autoconnect;
NMIPConfig *ip4_config;
NMDhcpConfig *dhcp4_config;
NMIPConfig *ip6_config;
NMDhcpConfig *dhcp6_config;
NMConnectivityState ip4_connectivity;
NMConnectivityState ip6_connectivity;
NMDeviceState state;
NMDeviceState last_seen_state;
NMDeviceStateReason reason;
char *physical_port_id;
char *udi;
guint32 capabilities;
guint32 device_type;
guint32 ip4_connectivity;
guint32 ip6_connectivity;
guint32 metered;
guint32 mtu;
guint32 state;
guint32 state_reason;
guint32 interface_flags;
bool firmware_missing;
bool nm_plugin_missing;
bool autoconnect;
bool managed;
bool real;
NMActiveConnection *active_connection;
GPtrArray *available_connections;
guint32 old_state;
struct udev *udev;
char *type_description;
char *product;
char *vendor, *short_vendor;
char *description, *bus_name;
char *vendor;
char *short_vendor;
char *description;
char *bus_name;
char *physical_port_id;
guint32 mtu;
GPtrArray *lldp_neighbors;
guint32 interface_flags;
} NMDevicePrivate;
G_DEFINE_ABSTRACT_TYPE (NMDevice, nm_device, NM_TYPE_OBJECT);
@ -132,6 +135,8 @@ struct _NMLldpNeighbor {
G_DEFINE_BOXED_TYPE (NMLldpNeighbor, nm_lldp_neighbor, nm_lldp_neighbor_dup, nm_lldp_neighbor_unref)
/*****************************************************************************/
static void
nm_device_init (NMDevice *self)
{
@ -141,120 +146,121 @@ nm_device_init (NMDevice *self)
self->_priv = priv;
priv->ip4_connectivity = NM_CONNECTIVITY_UNKNOWN;
priv->ip6_connectivity = NM_CONNECTIVITY_UNKNOWN;
priv->state = NM_DEVICE_STATE_UNKNOWN;
priv->reason = NM_DEVICE_STATE_REASON_NONE;
priv->lldp_neighbors = g_ptr_array_new ();
priv->old_state = NM_DEVICE_STATE_UNKNOWN;
}
static gboolean
demarshal_state_reason (NMObject *object, GParamSpec *pspec, GVariant *value, gpointer field)
{
guint32 *reason_field = field;
g_variant_get (value, "(uu)", NULL, reason_field);
_nm_object_queue_notify (object, NM_DEVICE_STATE_REASON);
return TRUE;
}
static gboolean
demarshal_lldp_neighbors (NMObject *object, GParamSpec *pspec, GVariant *value, gpointer field)
{
NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE (object);
GVariantIter iter, attrs_iter;
GVariant *variant, *attr_variant;
const char *attr_name;
g_return_val_if_fail (g_variant_is_of_type (value, G_VARIANT_TYPE ("aa{sv}")), FALSE);
g_ptr_array_unref (priv->lldp_neighbors);
priv->lldp_neighbors = g_ptr_array_new_with_free_func ((GDestroyNotify) nm_lldp_neighbor_unref);
g_variant_iter_init (&iter, value);
while (g_variant_iter_next (&iter, "@a{sv}", &variant)) {
NMLldpNeighbor *neigh;
neigh = nm_lldp_neighbor_new ();
g_variant_iter_init (&attrs_iter, variant);
while (g_variant_iter_next (&attrs_iter, "{&sv}", &attr_name, &attr_variant))
g_hash_table_insert (neigh->attrs, g_strdup (attr_name), attr_variant);
g_variant_unref (variant);
g_ptr_array_add (priv->lldp_neighbors, neigh);
}
_nm_object_queue_notify (object, NM_DEVICE_LLDP_NEIGHBORS);
return TRUE;
}
/*****************************************************************************/
static void
device_state_reason_changed (GObject *object, GParamSpec *pspec, gpointer user_data);
static void
init_dbus (NMObject *object)
_notify_event_state_changed (NMClient *client,
NMClientNotifyEventWithPtr *notify_event)
{
NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE (object);
const NMPropertiesInfo property_info[] = {
{ NM_DEVICE_UDI, &priv->udi },
{ NM_DEVICE_INTERFACE, &priv->iface },
{ NM_DEVICE_DEVICE_TYPE, &priv->device_type },
{ NM_DEVICE_IP_INTERFACE, &priv->ip_iface },
{ NM_DEVICE_DRIVER, &priv->driver },
{ NM_DEVICE_DRIVER_VERSION, &priv->driver_version },
{ NM_DEVICE_FIRMWARE_VERSION, &priv->firmware_version },
{ NM_DEVICE_CAPABILITIES, &priv->capabilities },
{ NM_DEVICE_REAL, &priv->real },
{ NM_DEVICE_MANAGED, &priv->managed },
{ NM_DEVICE_AUTOCONNECT, &priv->autoconnect },
{ NM_DEVICE_FIRMWARE_MISSING, &priv->firmware_missing },
{ NM_DEVICE_NM_PLUGIN_MISSING, &priv->nm_plugin_missing },
{ NM_DEVICE_IP4_CONFIG, &priv->ip4_config, NULL, NM_TYPE_IP4_CONFIG },
{ NM_DEVICE_DHCP4_CONFIG, &priv->dhcp4_config, NULL, NM_TYPE_DHCP4_CONFIG },
{ NM_DEVICE_IP6_CONFIG, &priv->ip6_config, NULL, NM_TYPE_IP6_CONFIG },
{ NM_DEVICE_DHCP6_CONFIG, &priv->dhcp6_config, NULL, NM_TYPE_DHCP6_CONFIG },
{ NM_DEVICE_IP4_CONNECTIVITY, &priv->ip4_connectivity },
{ NM_DEVICE_IP6_CONNECTIVITY, &priv->ip6_connectivity },
{ NM_DEVICE_STATE, &priv->state },
{ NM_DEVICE_STATE_REASON, &priv->reason, demarshal_state_reason },
{ NM_DEVICE_ACTIVE_CONNECTION, &priv->active_connection, NULL, NM_TYPE_ACTIVE_CONNECTION },
{ NM_DEVICE_AVAILABLE_CONNECTIONS, &priv->available_connections, NULL, NM_TYPE_REMOTE_CONNECTION },
{ NM_DEVICE_PHYSICAL_PORT_ID, &priv->physical_port_id },
{ NM_DEVICE_MTU, &priv->mtu },
{ NM_DEVICE_METERED, &priv->metered },
{ NM_DEVICE_LLDP_NEIGHBORS, &priv->lldp_neighbors, demarshal_lldp_neighbors },
{ NM_DEVICE_INTERFACE_FLAGS, &priv->interface_flags },
/* Properties that exist in D-Bus but that we don't track */
{ "ip4-address", NULL },
{ NULL },
};
NM_OBJECT_CLASS (nm_device_parent_class)->init_dbus (object);
priv->proxy = NMDBUS_DEVICE (_nm_object_get_proxy (object, NM_DBUS_INTERFACE_DEVICE));
_nm_object_register_properties (object,
NM_DBUS_INTERFACE_DEVICE,
property_info);
g_signal_connect (priv->proxy, "notify::state-reason",
G_CALLBACK (device_state_reason_changed), object);
}
static void
device_state_reason_changed (GObject *object, GParamSpec *pspec, gpointer user_data)
{
NMDevice *self = NM_DEVICE (user_data);
gs_unref_object NMDevice *self = notify_event->user_data;
NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE (self);
g_signal_emit (self, signals[STATE_CHANGED], 0,
priv->state, priv->last_seen_state, priv->reason);
priv->last_seen_state = priv->state;
NML_NMCLIENT_LOG_T (_nm_object_get_client (self),
"[%s] emit Device's StateChanged signal %u -> %u, reason: %u",
_nm_object_get_path (self),
(guint) priv->old_state,
(guint) priv->state,
(guint) priv->state_reason);
g_signal_emit (self,
signals[STATE_CHANGED],
0,
(guint) priv->state,
(guint) priv->old_state,
(guint) priv->state_reason);
}
static NMLDBusNotifyUpdatePropFlags
_notify_update_prop_state_reason (NMClient *client,
NMLDBusObject *dbobj,
const NMLDBusMetaIface *meta_iface,
guint dbus_property_idx,
GVariant *value)
{
NMDevice *self = NM_DEVICE (dbobj->nmobj);
NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE (self);
guint32 new_state = NM_DEVICE_STATE_UNKNOWN;
guint32 reason = NM_DEVICE_STATE_REASON_NONE;
/* We ignore the "State" property and the "StateChanged" signal of the device.
* This information is redundant to the "StateReason" property, and we rely
* on that one alone. In the best case, the information is identical. If it
* would not be, then we stick to the information from "StateReason" property. */
if (value)
g_variant_get (value, "(uu)", &new_state, &reason);
if ( priv->state == new_state
&& priv->state_reason == reason) {
/* no changes. */
return NML_DBUS_NOTIFY_UPDATE_PROP_FLAGS_NONE;
}
if (priv->state != new_state) {
priv->old_state = priv->state;
priv->state = new_state;
_nm_client_queue_notify_object (client,
self,
obj_properties[PROP_STATE]);
}
if (priv->state_reason != reason) {
priv->state_reason = reason;
_nm_client_queue_notify_object (client,
self,
obj_properties[PROP_STATE_REASON]);
}
_nm_client_notify_event_queue_with_ptr (client,
NM_CLIENT_NOTIFY_EVENT_PRIO_GPROP + 1,
_notify_event_state_changed,
g_object_ref (self));
return NML_DBUS_NOTIFY_UPDATE_PROP_FLAGS_NONE;
}
static NMLDBusNotifyUpdatePropFlags
_notify_update_prop_lldp_neighbors (NMClient *client,
NMLDBusObject *dbobj,
const NMLDBusMetaIface *meta_iface,
guint dbus_property_idx,
GVariant *value)
{
NMDevice *self = NM_DEVICE (dbobj->nmobj);
NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE (self);
gs_unref_ptrarray GPtrArray *old = NULL;
gs_unref_ptrarray GPtrArray *new = NULL;
GVariantIter *attrs_iter;
GVariantIter iter;
new = g_ptr_array_new_with_free_func ((GDestroyNotify) nm_lldp_neighbor_unref);
if (value) {
g_variant_iter_init (&iter, value);
while (g_variant_iter_next (&iter, "a{sv}", &attrs_iter)) {
GVariant *attr_variant;
const char *attr_name;
NMLldpNeighbor *neigh;
neigh = nm_lldp_neighbor_new ();
while (g_variant_iter_next (attrs_iter, "{&sv}", &attr_name, &attr_variant))
g_hash_table_insert (neigh->attrs, g_strdup (attr_name), attr_variant);
g_ptr_array_add (new, neigh);
g_variant_iter_free (attrs_iter);
}
}
old = g_steal_pointer (&priv->lldp_neighbors);
priv->lldp_neighbors = g_steal_pointer (&new);
return NML_DBUS_NOTIFY_UPDATE_PROP_FLAGS_NOTIFY;
}
/*****************************************************************************/
static NMDeviceType
coerce_type (NMDeviceType type)
{
@ -295,37 +301,33 @@ coerce_type (NMDeviceType type)
return NM_DEVICE_TYPE_UNKNOWN;
}
/*****************************************************************************/
static void
dispose (GObject *object)
register_client (NMObject *nmobj,
NMClient *client,
NMLDBusObject *dbobj)
{
NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE (object);
NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE (nmobj);
g_clear_object (&priv->ip4_config);
g_clear_object (&priv->dhcp4_config);
g_clear_object (&priv->ip6_config);
g_clear_object (&priv->dhcp6_config);
g_clear_object (&priv->active_connection);
priv->udev = _nm_client_get_udev (client);
if (priv->udev)
udev_ref (priv->udev);
udev_unref (priv->udev);
priv->udev = NULL;
g_clear_pointer (&priv->available_connections, g_ptr_array_unref);
g_clear_pointer (&priv->lldp_neighbors, g_ptr_array_unref);
if (priv->proxy)
g_signal_handlers_disconnect_by_func (priv->proxy, device_state_reason_changed, object);
g_clear_object (&priv->proxy);
G_OBJECT_CLASS (nm_device_parent_class)->dispose (object);
NM_OBJECT_CLASS (nm_device_parent_class)->register_client (nmobj, client, dbobj);
}
/*****************************************************************************/
static void
finalize (GObject *object)
{
NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE (object);
g_free (priv->iface);
g_free (priv->ip_iface);
g_clear_pointer (&priv->lldp_neighbors, g_ptr_array_unref);
g_free (priv->interface);
g_free (priv->ip_interface);
g_free (priv->udi);
g_free (priv->driver);
g_free (priv->driver_version);
@ -338,6 +340,8 @@ finalize (GObject *object)
g_free (priv->type_description);
g_free (priv->physical_port_id);
nm_clear_pointer (&priv->udev, udev_unref);
G_OBJECT_CLASS (nm_device_parent_class)->finalize (object);
}
@ -468,22 +472,76 @@ set_property (GObject *object,
}
}
static void
nm_device_class_init (NMDeviceClass *device_class)
{
GObjectClass *object_class = G_OBJECT_CLASS (device_class);
NMObjectClass *nm_object_class = NM_OBJECT_CLASS (device_class);
/* TODO: statistics interface not yet implemented. */
const NMLDBusMetaIface _nml_dbus_meta_iface_nm_device_statistics = NML_DBUS_META_IFACE_INIT (
NM_DBUS_INTERFACE_DEVICE_STATISTICS,
NULL,
NML_DBUS_META_INTERFACE_PRIO_NONE,
NML_DBUS_META_IFACE_DBUS_PROPERTIES (
NML_DBUS_META_PROPERTY_INIT_TODO ("RefreshRateMs", "u" ),
NML_DBUS_META_PROPERTY_INIT_TODO ("RxBytes", "t" ),
NML_DBUS_META_PROPERTY_INIT_TODO ("TxBytes", "t" ),
),
);
g_type_class_add_private (device_class, sizeof (NMDevicePrivate));
const NMLDBusMetaIface _nml_dbus_meta_iface_nm_device = NML_DBUS_META_IFACE_INIT_PROP (
NM_DBUS_INTERFACE_DEVICE,
nm_device_get_type,
NML_DBUS_META_INTERFACE_PRIO_PARENT_TYPE,
NML_DBUS_META_IFACE_DBUS_PROPERTIES (
NML_DBUS_META_PROPERTY_INIT_O_PROP ("ActiveConnection", PROP_ACTIVE_CONNECTION, NMDevicePrivate, property_o[PROPERTY_O_IDX_ACTIVE_CONNECTION], nm_active_connection_get_type, .is_always_ready = TRUE ),
NML_DBUS_META_PROPERTY_INIT_B ("Autoconnect", PROP_AUTOCONNECT, NMDevicePrivate, autoconnect ),
NML_DBUS_META_PROPERTY_INIT_AO_PROP ("AvailableConnections", PROP_AVAILABLE_CONNECTIONS, NMDevicePrivate, available_connections, nm_remote_connection_get_type, .is_always_ready = TRUE ),
NML_DBUS_META_PROPERTY_INIT_U ("Capabilities", PROP_CAPABILITIES, NMDevicePrivate, capabilities ),
NML_DBUS_META_PROPERTY_INIT_U ("DeviceType", PROP_DEVICE_TYPE, NMDevicePrivate, device_type ),
NML_DBUS_META_PROPERTY_INIT_O_PROP ("Dhcp4Config", PROP_DHCP4_CONFIG, NMDevicePrivate, property_o[PROPERTY_O_IDX_DHCP4_CONFIG], nm_dhcp4_config_get_type ),
NML_DBUS_META_PROPERTY_INIT_O_PROP ("Dhcp6Config", PROP_DHCP6_CONFIG, NMDevicePrivate, property_o[PROPERTY_O_IDX_DHCP6_CONFIG], nm_dhcp6_config_get_type ),
NML_DBUS_META_PROPERTY_INIT_S ("Driver", PROP_DRIVER, NMDevicePrivate, driver ),
NML_DBUS_META_PROPERTY_INIT_S ("DriverVersion", PROP_DRIVER_VERSION, NMDevicePrivate, driver_version ),
NML_DBUS_META_PROPERTY_INIT_B ("FirmwareMissing", PROP_FIRMWARE_MISSING, NMDevicePrivate, firmware_missing ),
NML_DBUS_META_PROPERTY_INIT_S ("FirmwareVersion", PROP_FIRMWARE_VERSION, NMDevicePrivate, firmware_version ),
NML_DBUS_META_PROPERTY_INIT_S ("Interface", PROP_INTERFACE, NMDevicePrivate, interface ),
NML_DBUS_META_PROPERTY_INIT_U ("InterfaceFlags", PROP_INTERFACE_FLAGS, NMDevicePrivate, interface_flags ),
NML_DBUS_META_PROPERTY_INIT_IGNORE ("Ip4Address", "u" ),
NML_DBUS_META_PROPERTY_INIT_O_PROP ("Ip4Config", PROP_IP4_CONFIG, NMDevicePrivate, property_o[PROPERTY_O_IDX_IP4_CONFIG], nm_ip4_config_get_type ),
NML_DBUS_META_PROPERTY_INIT_U ("Ip4Connectivity", PROP_IP4_CONNECTIVITY, NMDevicePrivate, ip4_connectivity ),
NML_DBUS_META_PROPERTY_INIT_O_PROP ("Ip6Config", PROP_IP6_CONFIG, NMDevicePrivate, property_o[PROPERTY_O_IDX_IP6_CONFIG], nm_ip6_config_get_type ),
NML_DBUS_META_PROPERTY_INIT_U ("Ip6Connectivity", PROP_IP6_CONNECTIVITY, NMDevicePrivate, ip6_connectivity ),
NML_DBUS_META_PROPERTY_INIT_S ("IpInterface", PROP_IP_INTERFACE, NMDevicePrivate, ip_interface ),
NML_DBUS_META_PROPERTY_INIT_FCN ("LldpNeighbors", PROP_LLDP_NEIGHBORS, "aa{sv}", _notify_update_prop_lldp_neighbors ),
NML_DBUS_META_PROPERTY_INIT_B ("Managed", PROP_MANAGED, NMDevicePrivate, managed ),
NML_DBUS_META_PROPERTY_INIT_U ("Metered", PROP_METERED, NMDevicePrivate, metered ),
NML_DBUS_META_PROPERTY_INIT_U ("Mtu", PROP_MTU, NMDevicePrivate, mtu ),
NML_DBUS_META_PROPERTY_INIT_B ("NmPluginMissing", PROP_NM_PLUGIN_MISSING, NMDevicePrivate, nm_plugin_missing ),
NML_DBUS_META_PROPERTY_INIT_S ("PhysicalPortId", PROP_PHYSICAL_PORT_ID, NMDevicePrivate, physical_port_id ),
NML_DBUS_META_PROPERTY_INIT_B ("Real", PROP_REAL, NMDevicePrivate, real ),
NML_DBUS_META_PROPERTY_INIT_IGNORE ("State", "u" ),
NML_DBUS_META_PROPERTY_INIT_FCN ("StateReason", PROP_STATE_REASON, "(uu)", _notify_update_prop_state_reason ),
NML_DBUS_META_PROPERTY_INIT_S ("Udi", PROP_UDI, NMDevicePrivate, udi ),
),
.base_struct_offset = G_STRUCT_OFFSET (NMDevice, _priv),
);
static void
nm_device_class_init (NMDeviceClass *klass)
{
GObjectClass *object_class = G_OBJECT_CLASS (klass);
NMObjectClass *nm_object_class = NM_OBJECT_CLASS (klass);
g_type_class_add_private (klass, sizeof (NMDevicePrivate));
object_class->get_property = get_property;
object_class->set_property = set_property;
object_class->dispose = dispose;
object_class->finalize = finalize;
nm_object_class->init_dbus = init_dbus;
nm_object_class->register_client = register_client;
device_class->connection_compatible = connection_compatible;
_NM_OBJECT_CLASS_INIT_PRIV_PTR_INDIRECT (nm_object_class, NMDevice);
_NM_OBJECT_CLASS_INIT_PROPERTY_O_FIELDS_N (nm_object_class, NMDevicePrivate, property_o);
_NM_OBJECT_CLASS_INIT_PROPERTY_AO_FIELDS_1 (nm_object_class, NMDevicePrivate, available_connections);
klass->connection_compatible = connection_compatible;
/**
* NMDevice:interface:
@ -844,7 +902,7 @@ nm_device_class_init (NMDeviceClass *device_class)
G_PARAM_READABLE |
G_PARAM_STATIC_STRINGS);
g_object_class_install_properties (object_class, _PROPERTY_ENUMS_LAST, obj_properties);
_nml_dbus_meta_class_init_with_properties (object_class, &_nml_dbus_meta_iface_nm_device);
/**
* NMDevice::state-changed:
@ -859,8 +917,7 @@ nm_device_class_init (NMDeviceClass *device_class)
g_signal_new ("state-changed",
G_OBJECT_CLASS_TYPE (object_class),
G_SIGNAL_RUN_FIRST,
G_STRUCT_OFFSET (NMDeviceClass, state_changed),
NULL, NULL, NULL,
0, NULL, NULL, NULL,
G_TYPE_NONE, 3,
G_TYPE_UINT, G_TYPE_UINT, G_TYPE_UINT);
}
@ -879,7 +936,7 @@ nm_device_get_iface (NMDevice *device)
{
g_return_val_if_fail (NM_IS_DEVICE (device), NULL);
return _nml_coerce_property_str_not_empty (NM_DEVICE_GET_PRIVATE (device)->iface);
return _nml_coerce_property_str_not_empty (NM_DEVICE_GET_PRIVATE (device)->interface);
}
/**
@ -897,7 +954,7 @@ nm_device_get_ip_iface (NMDevice *device)
{
g_return_val_if_fail (NM_IS_DEVICE (device), NULL);
return _nml_coerce_property_str_not_empty (NM_DEVICE_GET_PRIVATE (device)->ip_iface);
return _nml_coerce_property_str_not_empty (NM_DEVICE_GET_PRIVATE (device)->ip_interface);
}
/**
@ -1101,10 +1158,12 @@ nm_device_set_managed (NMDevice *device, gboolean managed)
NM_DEVICE_GET_PRIVATE (device)->managed = managed;
_nm_object_set_property (NM_OBJECT (device),
NM_DBUS_INTERFACE_DEVICE,
"Managed",
"b", managed);
_nm_client_set_property_sync_legacy (_nm_object_get_client (device),
_nm_object_get_path (device),
NM_DBUS_INTERFACE_DEVICE,
"Managed",
"b",
managed);
}
/**
@ -1144,10 +1203,12 @@ nm_device_set_autoconnect (NMDevice *device, gboolean autoconnect)
NM_DEVICE_GET_PRIVATE (device)->autoconnect = autoconnect;
_nm_object_set_property (NM_OBJECT (device),
NM_DBUS_INTERFACE_DEVICE,
"Autoconnect",
"b", autoconnect);
_nm_client_set_property_sync_legacy (_nm_object_get_client (device),
_nm_object_get_path (device),
NM_DBUS_INTERFACE_DEVICE,
"AutoConnect",
"b",
autoconnect);
}
/**
@ -1203,7 +1264,7 @@ nm_device_get_ip4_config (NMDevice *device)
{
g_return_val_if_fail (NM_IS_DEVICE (device), NULL);
return NM_DEVICE_GET_PRIVATE (device)->ip4_config;
return nml_dbus_property_o_get_obj (&NM_DEVICE_GET_PRIVATE (device)->property_o[PROPERTY_O_IDX_IP4_CONFIG]);
}
/**
@ -1223,7 +1284,7 @@ nm_device_get_dhcp4_config (NMDevice *device)
{
g_return_val_if_fail (NM_IS_DEVICE (device), NULL);
return NM_DEVICE_GET_PRIVATE (device)->dhcp4_config;
return nml_dbus_property_o_get_obj (&NM_DEVICE_GET_PRIVATE (device)->property_o[PROPERTY_O_IDX_DHCP4_CONFIG]);
}
/**
@ -1242,7 +1303,7 @@ nm_device_get_ip6_config (NMDevice *device)
{
g_return_val_if_fail (NM_IS_DEVICE (device), NULL);
return NM_DEVICE_GET_PRIVATE (device)->ip6_config;
return nml_dbus_property_o_get_obj (&NM_DEVICE_GET_PRIVATE (device)->property_o[PROPERTY_O_IDX_IP6_CONFIG]);
}
/**
@ -1262,7 +1323,7 @@ nm_device_get_dhcp6_config (NMDevice *device)
{
g_return_val_if_fail (NM_IS_DEVICE (device), NULL);
return NM_DEVICE_GET_PRIVATE (device)->dhcp6_config;
return nml_dbus_property_o_get_obj (&NM_DEVICE_GET_PRIVATE (device)->property_o[PROPERTY_O_IDX_DHCP6_CONFIG]);
}
/**
@ -1342,7 +1403,7 @@ nm_device_get_state_reason (NMDevice *device)
{
g_return_val_if_fail (NM_IS_DEVICE (device), NM_DEVICE_STATE_REASON_UNKNOWN);
return NM_DEVICE_GET_PRIVATE (device)->reason;
return NM_DEVICE_GET_PRIVATE (device)->state_reason;
}
/**
@ -1359,7 +1420,7 @@ nm_device_get_active_connection (NMDevice *device)
{
g_return_val_if_fail (NM_IS_DEVICE (device), NULL);
return NM_DEVICE_GET_PRIVATE (device)->active_connection;
return nml_dbus_property_o_get_obj (&NM_DEVICE_GET_PRIVATE (device)->property_o[PROPERTY_O_IDX_ACTIVE_CONNECTION]);
}
/**
@ -1378,7 +1439,7 @@ nm_device_get_available_connections (NMDevice *device)
{
g_return_val_if_fail (NM_IS_DEVICE (device), NULL);
return NM_DEVICE_GET_PRIVATE (device)->available_connections;
return nml_dbus_property_ao_get_objs_as_ptrarray (&NM_DEVICE_GET_PRIVATE (device)->available_connections);
}
static const char *
@ -1481,7 +1542,8 @@ get_bus_name (NMDevice *device)
{
NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE (device);
struct udev_device *udevice;
const char *ifname, *bus;
const char *ifname;
const char *bus;
if (priv->bus_name)
goto out;
@ -1519,31 +1581,18 @@ out:
return NULL;
}
void
_nm_device_set_udev (NMDevice *device, struct udev *udev)
{
NMDevicePrivate *priv;
nm_assert (NM_IS_DEVICE (device));
nm_assert (udev);
priv = NM_DEVICE_GET_PRIVATE (device);
nm_assert (!priv->udev);
priv->udev = udev_ref (udev);
}
static char *
_get_udev_property (NMDevice *device,
const char *enc_prop, /* ID_XXX_ENC */
const char *db_prop) /* ID_XXX_FROM_DATABASE */
{
NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE (device);
struct udev_device *udev_device, *tmpdev;
struct udev_device *udev_device;
struct udev_device *tmpdev;
const char *ifname;
guint32 count = 0;
char *enc_value = NULL, *db_value = NULL;
char *enc_value = NULL;
char *db_value = NULL;
if (!priv->udev)
return NULL;
@ -1960,9 +2009,14 @@ NM_BACKPORT_SYMBOL (libnm_1_0_6, NMMetered, nm_device_get_metered, (NMDevice *de
GPtrArray *
nm_device_get_lldp_neighbors (NMDevice *device)
{
g_return_val_if_fail (NM_IS_DEVICE (device), NULL);
NMDevicePrivate *priv;
return NM_DEVICE_GET_PRIVATE (device)->lldp_neighbors;
g_return_val_if_fail (NM_IS_DEVICE (device), NULL);
priv = NM_DEVICE_GET_PRIVATE (device);
if (!priv->lldp_neighbors)
priv->lldp_neighbors = g_ptr_array_new_with_free_func ((GDestroyNotify) nm_lldp_neighbor_unref);
return priv->lldp_neighbors;
}
/**
@ -2040,9 +2094,9 @@ nm_device_reapply (NMDevice *device,
if (!arg_connection)
arg_connection = g_variant_new_array (G_VARIANT_TYPE ("{sa{sv}}"), NULL, 0);
return _nm_object_dbus_call_sync_void (device,
return _nm_client_dbus_call_sync_void (_nm_object_get_client (device),
cancellable,
g_dbus_proxy_get_object_path (G_DBUS_PROXY (NM_DEVICE_GET_PRIVATE (device)->proxy)),
_nm_object_get_path (device),
NM_DBUS_INTERFACE_DEVICE,
"Reapply",
g_variant_new ("(@a{sa{sv}}tu)",
@ -2094,12 +2148,13 @@ nm_device_reapply_async (NMDevice *device,
if (!arg_connection)
arg_connection = g_variant_new_array (G_VARIANT_TYPE ("{sa{sv}}"), NULL, 0);
_nm_object_dbus_call (device,
_nm_client_dbus_call (_nm_object_get_client (device),
device,
nm_device_reapply_async,
cancellable,
callback,
user_data,
g_dbus_proxy_get_object_path (G_DBUS_PROXY (NM_DEVICE_GET_PRIVATE (device)->proxy)),
_nm_object_get_path (device),
NM_DBUS_INTERFACE_DEVICE,
"Reapply",
g_variant_new ("(@a{sa{sv}}tu)",
@ -2175,9 +2230,9 @@ nm_device_get_applied_connection (NMDevice *device,
g_return_val_if_fail (!cancellable || G_IS_CANCELLABLE (cancellable), NULL);
g_return_val_if_fail (!error || !*error, NULL);
ret = _nm_object_dbus_call_sync (device,
ret = _nm_client_dbus_call_sync (_nm_object_get_client (device),
cancellable,
g_dbus_proxy_get_object_path (G_DBUS_PROXY (NM_DEVICE_GET_PRIVATE (device)->proxy)),
_nm_object_get_path (device),
NM_DBUS_INTERFACE_DEVICE,
"GetAppliedConnection",
g_variant_new ("(u)", flags),
@ -2224,12 +2279,13 @@ nm_device_get_applied_connection_async (NMDevice *device,
g_return_if_fail (NM_IS_DEVICE (device));
g_return_if_fail (!cancellable || G_IS_CANCELLABLE (cancellable));
_nm_object_dbus_call (device,
_nm_client_dbus_call (_nm_object_get_client (device),
device,
nm_device_get_applied_connection_async,
cancellable,
callback,
user_data,
g_dbus_proxy_get_object_path (G_DBUS_PROXY (NM_DEVICE_GET_PRIVATE (device)->proxy)),
_nm_object_get_path (device),
NM_DBUS_INTERFACE_DEVICE,
"GetAppliedConnection",
g_variant_new ("(u)", flags),
@ -2314,9 +2370,9 @@ nm_device_disconnect (NMDevice *device,
g_return_val_if_fail (!cancellable || G_IS_CANCELLABLE (cancellable), FALSE);
g_return_val_if_fail (!error || !*error, FALSE);
return _nm_object_dbus_call_sync_void (device,
return _nm_client_dbus_call_sync_void (_nm_object_get_client (device),
cancellable,
g_dbus_proxy_get_object_path (G_DBUS_PROXY (NM_DEVICE_GET_PRIVATE (device)->proxy)),
_nm_object_get_path (device),
NM_DBUS_INTERFACE_DEVICE,
"Disconnect",
g_variant_new ("()"),
@ -2346,12 +2402,13 @@ nm_device_disconnect_async (NMDevice *device,
g_return_if_fail (NM_IS_DEVICE (device));
g_return_if_fail (!cancellable || G_IS_CANCELLABLE (cancellable));
_nm_object_dbus_call (device,
_nm_client_dbus_call (_nm_object_get_client (device),
device,
nm_device_disconnect_async,
cancellable,
callback,
user_data,
g_dbus_proxy_get_object_path (G_DBUS_PROXY (NM_DEVICE_GET_PRIVATE (device)->proxy)),
_nm_object_get_path (device),
NM_DBUS_INTERFACE_DEVICE,
"Disconnect",
g_variant_new ("()"),
@ -2405,9 +2462,9 @@ nm_device_delete (NMDevice *device,
g_return_val_if_fail (!cancellable || G_IS_CANCELLABLE (cancellable), FALSE);
g_return_val_if_fail (!error || !*error, FALSE);
return _nm_object_dbus_call_sync_void (device,
return _nm_client_dbus_call_sync_void (_nm_object_get_client (device),
cancellable,
g_dbus_proxy_get_object_path (G_DBUS_PROXY (NM_DEVICE_GET_PRIVATE (device)->proxy)),
_nm_object_get_path (device),
NM_DBUS_INTERFACE_DEVICE,
"Delete",
g_variant_new ("()"),
@ -2436,12 +2493,13 @@ nm_device_delete_async (NMDevice *device,
g_return_if_fail (NM_IS_DEVICE (device));
g_return_if_fail (!cancellable || G_IS_CANCELLABLE (cancellable));
_nm_object_dbus_call (device,
_nm_client_dbus_call (_nm_object_get_client (device),
device,
nm_device_delete_async,
cancellable,
callback,
user_data,
g_dbus_proxy_get_object_path (G_DBUS_PROXY (NM_DEVICE_GET_PRIVATE (device)->proxy)),
_nm_object_get_path (device),
NM_DBUS_INTERFACE_DEVICE,
"Delete",
g_variant_new ("()"),

View file

@ -16,7 +16,7 @@
/*****************************************************************************/
NM_GOBJECT_PROPERTIES_DEFINE_BASE (
NM_GOBJECT_PROPERTIES_DEFINE (NMDhcpConfig,
PROP_FAMILY,
PROP_OPTIONS,
);
@ -31,6 +31,36 @@ G_DEFINE_ABSTRACT_TYPE (NMDhcpConfig, nm_dhcp_config, NM_TYPE_OBJECT)
/*****************************************************************************/
static NMLDBusNotifyUpdatePropFlags
_notify_update_prop_options (NMClient *client,
NMLDBusObject *dbobj,
const NMLDBusMetaIface *meta_iface,
guint dbus_property_idx,
GVariant *value)
{
NMDhcpConfig *self = NM_DHCP_CONFIG (dbobj->nmobj);
NMDhcpConfigPrivate *priv = NM_DHCP_CONFIG_GET_PRIVATE (self);
g_hash_table_remove_all (priv->options);
if (value) {
GVariantIter iter;
const char *key;
GVariant *opt;
g_variant_iter_init (&iter, value);
while (g_variant_iter_next (&iter, "{&sv}", &key, &opt)) {
if (g_variant_is_of_type (opt, G_VARIANT_TYPE_STRING))
g_hash_table_insert (priv->options, g_strdup (key), g_variant_dup_string (opt, NULL));
g_variant_unref (opt);
}
}
return NML_DBUS_NOTIFY_UPDATE_PROP_FLAGS_NOTIFY;
}
/*****************************************************************************/
static void
nm_dhcp_config_init (NMDhcpConfig *self)
{
@ -43,51 +73,12 @@ nm_dhcp_config_init (NMDhcpConfig *self)
priv->options = g_hash_table_new_full (nm_str_hash, g_str_equal, g_free, g_free);
}
static gboolean
demarshal_dhcp_options (NMObject *object, GParamSpec *pspec, GVariant *value, gpointer field)
{
NMDhcpConfigPrivate *priv = NM_DHCP_CONFIG_GET_PRIVATE (object);
GVariantIter iter;
const char *key;
GVariant *opt;
g_hash_table_remove_all (priv->options);
g_variant_iter_init (&iter, value);
while (g_variant_iter_next (&iter, "{&sv}", &key, &opt)) {
g_hash_table_insert (priv->options, g_strdup (key), g_variant_dup_string (opt, NULL));
g_variant_unref (opt);
}
_nm_object_queue_notify (object, NM_DHCP_CONFIG_OPTIONS);
return TRUE;
}
static void
init_dbus (NMObject *object)
{
NMDhcpConfigPrivate *priv = NM_DHCP_CONFIG_GET_PRIVATE (object);
const NMPropertiesInfo property_info[] = {
{ NM_DHCP_CONFIG_OPTIONS, &priv->options, demarshal_dhcp_options },
{ NULL },
};
NM_OBJECT_CLASS (nm_dhcp_config_parent_class)->init_dbus (object);
_nm_object_register_properties (object,
(NM_IS_DHCP4_CONFIG (object) ?
NM_DBUS_INTERFACE_DHCP4_CONFIG :
NM_DBUS_INTERFACE_DHCP6_CONFIG),
property_info);
}
static void
finalize (GObject *object)
{
NMDhcpConfigPrivate *priv = NM_DHCP_CONFIG_GET_PRIVATE (object);
if (priv->options)
g_hash_table_destroy (priv->options);
g_hash_table_destroy (priv->options);
G_OBJECT_CLASS (nm_dhcp_config_parent_class)->finalize (object);
}
@ -113,19 +104,36 @@ get_property (GObject *object,
}
}
const NMLDBusMetaIface _nml_dbus_meta_iface_nm_dhcp4config = NML_DBUS_META_IFACE_INIT_PROP (
NM_DBUS_INTERFACE_DHCP4_CONFIG,
nm_dhcp4_config_get_type,
NML_DBUS_META_INTERFACE_PRIO_INSTANTIATE_HIGH,
NML_DBUS_META_IFACE_DBUS_PROPERTIES (
NML_DBUS_META_PROPERTY_INIT_FCN ("Options", PROP_OPTIONS, "a{sv}", _notify_update_prop_options ),
),
.base_struct_offset = G_STRUCT_OFFSET (NMDhcpConfig, _priv),
);
const NMLDBusMetaIface _nml_dbus_meta_iface_nm_dhcp6config = NML_DBUS_META_IFACE_INIT_PROP (
NM_DBUS_INTERFACE_DHCP6_CONFIG,
nm_dhcp6_config_get_type,
NML_DBUS_META_INTERFACE_PRIO_INSTANTIATE_HIGH,
NML_DBUS_META_IFACE_DBUS_PROPERTIES (
NML_DBUS_META_PROPERTY_INIT_FCN ("Options", PROP_OPTIONS, "a{sv}", _notify_update_prop_options ),
),
.base_struct_offset = G_STRUCT_OFFSET (NMDhcpConfig, _priv),
);
static void
nm_dhcp_config_class_init (NMDhcpConfigClass *config_class)
{
GObjectClass *object_class = G_OBJECT_CLASS (config_class);
NMObjectClass *nm_object_class = NM_OBJECT_CLASS (config_class);
g_type_class_add_private (config_class, sizeof (NMDhcpConfigPrivate));
object_class->get_property = get_property;
object_class->finalize = finalize;
nm_object_class->init_dbus = init_dbus;
/**
* NMDhcpConfig:family:
*
@ -149,7 +157,8 @@ nm_dhcp_config_class_init (NMDhcpConfigClass *config_class)
G_PARAM_READABLE |
G_PARAM_STATIC_STRINGS);
g_object_class_install_properties (object_class, _PROPERTY_ENUMS_LAST, obj_properties);
_nml_dbus_meta_class_init_with_properties (object_class, &_nml_dbus_meta_iface_nm_dhcp4config,
&_nml_dbus_meta_iface_nm_dhcp6config);
}
/**

View file

@ -14,25 +14,6 @@
#include "nm-dbus-helpers.h"
#include "nm-core-internal.h"
#include "introspection/org.freedesktop.NetworkManager.DnsManager.h"
G_DEFINE_TYPE (NMDnsManager, nm_dns_manager, NM_TYPE_OBJECT)
#define NM_DNS_MANAGER_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), NM_TYPE_DNS_MANAGER, NMDnsManagerPrivate))
typedef struct {
NMDBusDnsManager *proxy;
char *mode;
char *rc_manager;
GPtrArray *configuration;
} NMDnsManagerPrivate;
NM_GOBJECT_PROPERTIES_DEFINE_BASE (
PROP_MODE,
PROP_RC_MANAGER,
PROP_CONFIGURATION,
);
/*****************************************************************************
* NMDnsEntry
*****************************************************************************/
@ -234,192 +215,3 @@ nm_dns_entry_get_priority (NMDnsEntry *entry)
return entry->priority;
}
/*****************************************************************************/
static gboolean
demarshal_dns_configuration (NMObject *object, GParamSpec *pspec, GVariant *value, gpointer field)
{
NMDnsManagerPrivate *priv = NM_DNS_MANAGER_GET_PRIVATE (object);
GVariant *entry_var;
GVariantIter iter, *iterp;
NMDnsEntry *entry;
GPtrArray *array;
g_return_val_if_fail (g_variant_is_of_type (value, G_VARIANT_TYPE ("aa{sv}")), FALSE);
g_variant_iter_init (&iter, value);
g_ptr_array_unref (priv->configuration);
priv->configuration = g_ptr_array_new_with_free_func ((GDestroyNotify) nm_dns_entry_unref);
while (g_variant_iter_next (&iter, "@a{sv}", &entry_var)) {
char **nameservers = NULL, **domains = NULL;
gboolean vpn = FALSE;
char *interface = NULL, *str;
int priority;
if ( !g_variant_lookup (entry_var, "nameservers", "as", &iterp)
|| !g_variant_lookup (entry_var, "priority", "i", &priority)) {
g_warning ("Ignoring invalid DNS configuration");
g_variant_unref (entry_var);
continue;
}
array = g_ptr_array_new ();
while (g_variant_iter_next (iterp, "&s", &str))
g_ptr_array_add (array, str);
g_ptr_array_add (array, NULL);
nameservers = (char **) g_ptr_array_free (array, FALSE);
g_variant_iter_free (iterp);
if (g_variant_lookup (entry_var, "domains", "as", &iterp)) {
array = g_ptr_array_new ();
while (g_variant_iter_next (iterp, "&s", &str))
g_ptr_array_add (array, str);
g_ptr_array_add (array, NULL);
domains = (char **) g_ptr_array_free (array, FALSE);
g_variant_iter_free (iterp);
}
g_variant_lookup (entry_var, "interface", "&s", &interface);
g_variant_lookup (entry_var, "priority", "i", &priority);
g_variant_lookup (entry_var, "vpn", "b", &vpn);
entry = nm_dns_entry_new (interface,
(const char * const *) nameservers,
(const char * const *) domains,
priority,
vpn);
g_free (domains);
g_free (nameservers);
g_variant_unref (entry_var);
if (!entry) {
g_warning ("Ignoring invalid DNS entry");
continue;
}
g_ptr_array_add (priv->configuration, entry);
}
_nm_object_queue_notify (object, NM_DNS_MANAGER_CONFIGURATION);
return TRUE;
}
/*****************************************************************************/
const char *
nm_dns_manager_get_mode (NMDnsManager *manager)
{
return NM_DNS_MANAGER_GET_PRIVATE (manager)->mode;
}
const char *
nm_dns_manager_get_rc_manager (NMDnsManager *manager)
{
return NM_DNS_MANAGER_GET_PRIVATE (manager)->rc_manager;
}
const GPtrArray *
nm_dns_manager_get_configuration (NMDnsManager *manager)
{
return NM_DNS_MANAGER_GET_PRIVATE (manager)->configuration;
}
/*****************************************************************************/
static void
nm_dns_manager_init (NMDnsManager *self)
{
NMDnsManagerPrivate *priv = NM_DNS_MANAGER_GET_PRIVATE (self);
priv->configuration = g_ptr_array_new ();
}
static void
init_dbus (NMObject *object)
{
NMDnsManagerPrivate *priv = NM_DNS_MANAGER_GET_PRIVATE (object);
const NMPropertiesInfo property_info[] = {
{ NM_DNS_MANAGER_MODE, &priv->mode },
{ NM_DNS_MANAGER_RC_MANAGER, &priv->rc_manager },
{ NM_DNS_MANAGER_CONFIGURATION, &priv->configuration, demarshal_dns_configuration },
{ NULL },
};
NM_OBJECT_CLASS (nm_dns_manager_parent_class)->init_dbus (object);
priv->proxy = NMDBUS_DNS_MANAGER (_nm_object_get_proxy (object, NM_DBUS_INTERFACE_DNS_MANAGER));
_nm_object_register_properties (object,
NM_DBUS_INTERFACE_DNS_MANAGER,
property_info);
}
static void
dispose (GObject *object)
{
NMDnsManager *self = NM_DNS_MANAGER (object);
NMDnsManagerPrivate *priv = NM_DNS_MANAGER_GET_PRIVATE (self);
g_clear_pointer (&priv->mode, g_free);
g_clear_pointer (&priv->rc_manager, g_free);
g_clear_pointer (&priv->configuration, g_ptr_array_unref);
G_OBJECT_CLASS (nm_dns_manager_parent_class)->dispose (object);
}
static void
get_property (GObject *object, guint prop_id,
GValue *value, GParamSpec *pspec)
{
NMDnsManagerPrivate *priv = NM_DNS_MANAGER_GET_PRIVATE (object);
switch (prop_id) {
case PROP_MODE:
g_value_set_string (value, priv->mode);
break;
case PROP_RC_MANAGER:
g_value_set_string (value, priv->rc_manager);
break;
case PROP_CONFIGURATION:
g_value_take_boxed (value, _nm_utils_copy_array (priv->configuration,
(NMUtilsCopyFunc) nm_dns_entry_dup,
(GDestroyNotify) nm_dns_entry_unref));
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
}
}
static void
nm_dns_manager_class_init (NMDnsManagerClass *class)
{
GObjectClass *object_class = G_OBJECT_CLASS (class);
NMObjectClass *nm_object_class = NM_OBJECT_CLASS (class);
g_type_class_add_private (class, sizeof (NMDnsManagerPrivate));
object_class->get_property = get_property;
object_class->dispose = dispose;
nm_object_class->init_dbus = init_dbus;
obj_properties[PROP_MODE] =
g_param_spec_string (NM_DNS_MANAGER_MODE, "", "",
NULL,
G_PARAM_READABLE |
G_PARAM_STATIC_STRINGS);
obj_properties[PROP_RC_MANAGER] =
g_param_spec_string (NM_DNS_MANAGER_RC_MANAGER, "", "",
NULL,
G_PARAM_READABLE |
G_PARAM_STATIC_STRINGS);
obj_properties[PROP_CONFIGURATION] =
g_param_spec_boxed (NM_DNS_MANAGER_CONFIGURATION, "", "",
G_TYPE_PTR_ARRAY,
G_PARAM_READABLE |
G_PARAM_STATIC_STRINGS);
g_object_class_install_properties (object_class, _PROPERTY_ENUMS_LAST, obj_properties);
}

View file

@ -10,45 +10,13 @@
#error Cannot use this header.
#endif
#include "nm-object.h"
#include "nm-client.h"
#define NM_TYPE_DNS_MANAGER (nm_dns_manager_get_type ())
#define NM_DNS_MANAGER(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), NM_TYPE_DNS_MANAGER, NMDnsManager))
#define NM_DNS_MANAGER_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), NM_TYPE_DNS_MANAGER, NMDnsManagerClass))
#define NM_IS_DNS_MANAGER(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), NM_TYPE_DNS_MANAGER))
#define NM_IS_DNS_MANAGER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), NM_TYPE_DNS_MANAGER))
#define NM_DNS_MANAGER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), NM_TYPE_DNS_MANAGER, NMDnsManagerClass))
#define NM_DNS_MANAGER_MODE "mode"
#define NM_DNS_MANAGER_RC_MANAGER "rc-manager"
#define NM_DNS_MANAGER_CONFIGURATION "configuration"
typedef struct _NMDnsManager NMDnsManager;
typedef struct _NMDnsManagerClass NMDnsManagerClass;
/**
* NMDnsManager:
*/
struct _NMDnsManager {
NMObject parent;
};
struct _NMDnsManagerClass {
NMObjectClass parent;
};
GType nm_dns_manager_get_type (void);
const char *nm_dns_manager_get_mode (NMDnsManager *manager);
const char *nm_dns_manager_get_rc_manager (NMDnsManager *manager);
const GPtrArray *nm_dns_manager_get_configuration (NMDnsManager *manager);
NMDnsEntry * nm_dns_entry_new (const char *interface,
const char * const *nameservers,
const char * const *domains,
int priority,
gboolean vpn);
NMDnsEntry * nm_dns_entry_dup (NMDnsEntry *entry);
NMDnsEntry *nm_dns_entry_new (const char *interface,
const char * const *nameservers,
const char * const *domains,
int priority,
gboolean vpn);
NMDnsEntry *nm_dns_entry_dup (NMDnsEntry *entry);
#endif /* __NM_DNS_MANAGER_H__ */

View file

@ -18,7 +18,7 @@
/*****************************************************************************/
NM_GOBJECT_PROPERTIES_DEFINE_BASE (
NM_GOBJECT_PROPERTIES_DEFINE (NMIPConfig,
PROP_FAMILY,
PROP_GATEWAY,
PROP_ADDRESSES,
@ -30,15 +30,18 @@ NM_GOBJECT_PROPERTIES_DEFINE_BASE (
);
typedef struct _NMIPConfigPrivate {
char *gateway;
GPtrArray *addresses;
GPtrArray *routes;
char **nameservers;
char **domains;
char **searches;
char **wins;
char **wins_servers;
char *gateway;
gboolean new_style_data;
bool addresses_new_style:1;
bool routes_new_style:1;
bool nameservers_new_style:1;
bool wins_servers_new_style:1;
} NMIPConfigPrivate;
G_DEFINE_ABSTRACT_TYPE (NMIPConfig, nm_ip_config, NM_TYPE_OBJECT)
@ -47,157 +50,192 @@ G_DEFINE_ABSTRACT_TYPE (NMIPConfig, nm_ip_config, NM_TYPE_OBJECT)
/*****************************************************************************/
static void
nm_ip_config_init (NMIPConfig *self)
static NMLDBusNotifyUpdatePropFlags
_notify_update_prop_addresses (NMClient *client,
NMLDBusObject *dbobj,
const NMLDBusMetaIface *meta_iface,
guint dbus_property_idx,
GVariant *value)
{
NMIPConfigPrivate *priv;
NMIPConfig *self = NM_IP_CONFIG (dbobj->nmobj);
NMIPConfigPrivate *priv = NM_IP_CONFIG_GET_PRIVATE (self);
gs_unref_ptrarray GPtrArray *addresses_old = NULL;
gs_unref_ptrarray GPtrArray *addresses_new = NULL;
int addr_family = meta_iface == &_nml_dbus_meta_iface_nm_ip4config
? AF_INET : AF_INET6;
gboolean new_style;
priv = G_TYPE_INSTANCE_GET_PRIVATE (self, NM_TYPE_IP_CONFIG, NMIPConfigPrivate);
new_style = (((const char *) meta_iface->dbus_properties[dbus_property_idx].dbus_type)[2] == '{');
self->_priv = priv;
if (priv->addresses_new_style) {
if (!new_style)
return NML_DBUS_NOTIFY_UPDATE_PROP_FLAGS_NONE;
} else
priv->addresses_new_style = new_style;
priv->addresses = g_ptr_array_new ();
priv->routes = g_ptr_array_new ();
priv->nameservers = g_new0 (char *, 1);
priv->domains = g_new0 (char *, 1);
priv->searches = g_new0 (char *, 1);
priv->wins = g_new0 (char *, 1);
if (value) {
if (new_style)
addresses_new = nm_utils_ip_addresses_from_variant (value, addr_family);
else if (addr_family == AF_INET)
addresses_new = nm_utils_ip4_addresses_from_variant (value, NULL);
else
addresses_new = nm_utils_ip6_addresses_from_variant (value, NULL);
nm_assert (addresses_new);
}
if (!addresses_new)
addresses_new = g_ptr_array_new_with_free_func ((GDestroyNotify) nm_ip_address_unref);
addresses_old = priv->addresses;
priv->addresses = g_steal_pointer (&addresses_new);
return NML_DBUS_NOTIFY_UPDATE_PROP_FLAGS_NOTIFY;
}
static gboolean
demarshal_ip_addresses (NMObject *object, GParamSpec *pspec, GVariant *value, gpointer field)
static NMLDBusNotifyUpdatePropFlags
_notify_update_prop_routes (NMClient *client,
NMLDBusObject *dbobj,
const NMLDBusMetaIface *meta_iface,
guint dbus_property_idx,
GVariant *value)
{
NMIPConfigPrivate *priv = NM_IP_CONFIG_GET_PRIVATE (object);
NMIPConfig *self = NM_IP_CONFIG (dbobj->nmobj);
NMIPConfigPrivate *priv = NM_IP_CONFIG_GET_PRIVATE (self);
gs_unref_ptrarray GPtrArray *routes_old = NULL;
gs_unref_ptrarray GPtrArray *routes_new = NULL;
int addr_family = meta_iface == &_nml_dbus_meta_iface_nm_ip4config
? AF_INET : AF_INET6;
gboolean new_style;
if (priv->new_style_data)
return TRUE;
new_style = (((const char *) meta_iface->dbus_properties[dbus_property_idx].dbus_type)[2] == '{');
g_ptr_array_unref (priv->addresses);
if (NM_IS_IP4_CONFIG (object))
priv->addresses = nm_utils_ip4_addresses_from_variant (value, NULL);
else
priv->addresses = nm_utils_ip6_addresses_from_variant (value, NULL);
_nm_object_queue_notify (object, NM_IP_CONFIG_ADDRESSES);
if (priv->routes_new_style) {
if (!new_style)
return NML_DBUS_NOTIFY_UPDATE_PROP_FLAGS_NONE;
} else
priv->routes_new_style = new_style;
return TRUE;
if (value) {
if (new_style)
routes_new = nm_utils_ip_routes_from_variant (value, addr_family);
else if (addr_family == AF_INET)
routes_new = nm_utils_ip4_routes_from_variant (value);
else
routes_new = nm_utils_ip6_routes_from_variant (value);
nm_assert (routes_new);
}
if (!routes_new)
routes_new = g_ptr_array_new_with_free_func ((GDestroyNotify) nm_ip_route_unref);
routes_old = priv->routes;
priv->routes = g_steal_pointer (&routes_new);
return NML_DBUS_NOTIFY_UPDATE_PROP_FLAGS_NOTIFY;
}
static gboolean
demarshal_ip_address_data (NMObject *object, GParamSpec *pspec, GVariant *value, gpointer field)
static NMLDBusNotifyUpdatePropFlags
_notify_update_prop_nameservers (NMClient *client,
NMLDBusObject *dbobj,
const NMLDBusMetaIface *meta_iface,
guint dbus_property_idx,
GVariant *value)
{
NMIPConfigPrivate *priv = NM_IP_CONFIG_GET_PRIVATE (object);
NMIPConfig *self = NM_IP_CONFIG (dbobj->nmobj);
NMIPConfigPrivate *priv = NM_IP_CONFIG_GET_PRIVATE (self);
gs_strfreev char **nameservers_new = NULL;
gboolean new_style = TRUE;
int addr_family = meta_iface == &_nml_dbus_meta_iface_nm_ip4config
? AF_INET : AF_INET6;
priv->new_style_data = TRUE;
if (addr_family == AF_INET) {
new_style = (((const char *) meta_iface->dbus_properties[dbus_property_idx].dbus_type)[1] == 'a');
g_ptr_array_unref (priv->addresses);
if (NM_IS_IP4_CONFIG (object))
priv->addresses = nm_utils_ip_addresses_from_variant (value, AF_INET);
else
priv->addresses = nm_utils_ip_addresses_from_variant (value, AF_INET6);
_nm_object_queue_notify (object, NM_IP_CONFIG_ADDRESSES);
if (priv->nameservers_new_style) {
if (!new_style)
return NML_DBUS_NOTIFY_UPDATE_PROP_FLAGS_NONE;
} else
priv->nameservers_new_style = new_style;
}
return TRUE;
}
if (value) {
if (addr_family == AF_INET6)
nameservers_new = nm_utils_ip6_dns_from_variant (value);
else if (!new_style)
nameservers_new = nm_utils_ip4_dns_from_variant (value);
else {
GVariantIter iter;
GVariantIter *iter_v;
gs_unref_ptrarray GPtrArray *arr = NULL;
static gboolean
demarshal_ip_array (NMObject *object, GParamSpec *pspec, GVariant *value, gpointer field)
{
char ***obj_field;
g_variant_iter_init (&iter, value);
while (g_variant_iter_next (&iter, "a{sv}", &iter_v)) {
const char *key;
GVariant *val;
obj_field = field;
if (*obj_field)
g_strfreev (*obj_field);
while (g_variant_iter_next (iter_v, "{&sv}", &key, &val)) {
if (nm_streq (key, "address")) {
gs_free char *val_str = NULL;
if (NM_IS_IP4_CONFIG (object))
*obj_field = nm_utils_ip4_dns_from_variant (value);
else
*obj_field = nm_utils_ip6_dns_from_variant (value);
_nm_object_queue_notify (object, pspec->name);
return TRUE;
}
static gboolean
demarshal_ip_routes (NMObject *object, GParamSpec *pspec, GVariant *value, gpointer field)
{
NMIPConfigPrivate *priv = NM_IP_CONFIG_GET_PRIVATE (object);
if (priv->new_style_data)
return TRUE;
g_ptr_array_unref (priv->routes);
if (NM_IS_IP4_CONFIG (object))
priv->routes = nm_utils_ip4_routes_from_variant (value);
else
priv->routes = nm_utils_ip6_routes_from_variant (value);
_nm_object_queue_notify (object, NM_IP_CONFIG_ROUTES);
return TRUE;
}
static gboolean
demarshal_ip_route_data (NMObject *object, GParamSpec *pspec, GVariant *value, gpointer field)
{
NMIPConfigPrivate *priv = NM_IP_CONFIG_GET_PRIVATE (object);
priv->new_style_data = TRUE;
g_ptr_array_unref (priv->routes);
if (NM_IS_IP4_CONFIG (object))
priv->routes = nm_utils_ip_routes_from_variant (value, AF_INET);
else
priv->routes = nm_utils_ip_routes_from_variant (value, AF_INET6);
_nm_object_queue_notify (object, NM_IP_CONFIG_ROUTES);
return TRUE;
}
static void
init_dbus (NMObject *object)
{
NMIPConfigPrivate *priv = NM_IP_CONFIG_GET_PRIVATE (object);
const NMPropertiesInfo property_info[] = {
{ NM_IP_CONFIG_GATEWAY, &priv->gateway, },
{ NM_IP_CONFIG_ADDRESSES, &priv->addresses, demarshal_ip_addresses },
{ "address-data", &priv->addresses, demarshal_ip_address_data },
{ NM_IP_CONFIG_ROUTES, &priv->routes, demarshal_ip_routes },
{ "route-data", &priv->routes, demarshal_ip_route_data },
/* Still use deprecated "Nameservers" property instead of "NameserverData" */
{ NM_IP_CONFIG_NAMESERVERS, &priv->nameservers, demarshal_ip_array },
{ NM_IP_CONFIG_DOMAINS, &priv->domains, },
{ NM_IP_CONFIG_SEARCHES, &priv->searches, },
/* Still use deprecated "WinsServers" property instead of "WinsServerData" */
{ NM_IP_CONFIG_WINS_SERVERS, &priv->wins, demarshal_ip_array },
{ NULL },
};
NM_OBJECT_CLASS (nm_ip_config_parent_class)->init_dbus (object);
_nm_object_register_properties (object,
(NM_IS_IP4_CONFIG (object) ?
NM_DBUS_INTERFACE_IP4_CONFIG :
NM_DBUS_INTERFACE_IP6_CONFIG),
property_info);
}
static void
finalize (GObject *object)
{
NMIPConfigPrivate *priv = NM_IP_CONFIG_GET_PRIVATE (object);
g_free (priv->gateway);
g_ptr_array_unref (priv->addresses);
g_ptr_array_unref (priv->routes);
if (!g_variant_is_of_type (val, G_VARIANT_TYPE_STRING))
goto next;
if (!nm_utils_parse_inaddr (AF_INET, g_variant_get_string (val, NULL), &val_str))
goto next;
if (!arr)
arr = g_ptr_array_new ();
g_ptr_array_add (arr, g_steal_pointer (&val_str));
goto next;
}
next:
g_variant_unref (val);
}
g_variant_iter_free (iter_v);
}
if ( arr
&& arr->len > 0)
nameservers_new = nm_utils_strv_dup (arr->pdata, arr->len, FALSE);
else
nameservers_new = g_new0 (char *, 1);
}
nm_assert (nameservers_new);
}
g_strfreev (priv->nameservers);
g_strfreev (priv->domains);
g_strfreev (priv->searches);
g_strfreev (priv->wins);
G_OBJECT_CLASS (nm_ip_config_parent_class)->finalize (object);
priv->nameservers = g_steal_pointer (&nameservers_new);
return NML_DBUS_NOTIFY_UPDATE_PROP_FLAGS_NOTIFY;
}
static NMLDBusNotifyUpdatePropFlags
_notify_update_prop_wins_servers (NMClient *client,
NMLDBusObject *dbobj,
const NMLDBusMetaIface *meta_iface,
guint dbus_property_idx,
GVariant *value)
{
NMIPConfig *self = NM_IP_CONFIG (dbobj->nmobj);
NMIPConfigPrivate *priv = NM_IP_CONFIG_GET_PRIVATE (self);
gs_strfreev char **wins_servers_new = NULL;
gboolean new_style;
new_style = (((const char *) meta_iface->dbus_properties[dbus_property_idx].dbus_type)[1] == 's');
if (priv->wins_servers_new_style) {
if (!new_style)
return NML_DBUS_NOTIFY_UPDATE_PROP_FLAGS_NONE;
} else
priv->wins_servers_new_style = new_style;
if (value) {
if (new_style)
wins_servers_new = g_variant_dup_strv (value, NULL);
else
wins_servers_new = nm_utils_ip4_dns_from_variant (value);
nm_assert (wins_servers_new);
}
g_strfreev (priv->wins_servers);
priv->wins_servers = g_steal_pointer (&wins_servers_new);
return NML_DBUS_NOTIFY_UPDATE_PROP_FLAGS_NOTIFY;
}
/*****************************************************************************/
static void
get_property (GObject *object,
guint prop_id,
@ -241,19 +279,90 @@ get_property (GObject *object,
}
}
/*****************************************************************************/
static void
nm_ip_config_init (NMIPConfig *self)
{
NMIPConfigPrivate *priv;
priv = G_TYPE_INSTANCE_GET_PRIVATE (self, NM_TYPE_IP_CONFIG, NMIPConfigPrivate);
self->_priv = priv;
priv->addresses = g_ptr_array_new_with_free_func ((GDestroyNotify) nm_ip_address_unref);
priv->routes = g_ptr_array_new_with_free_func ((GDestroyNotify) nm_ip_route_unref);
}
static void
finalize (GObject *object)
{
NMIPConfigPrivate *priv = NM_IP_CONFIG_GET_PRIVATE (object);
g_free (priv->gateway);
g_ptr_array_unref (priv->routes);
g_ptr_array_unref (priv->addresses);
g_strfreev (priv->nameservers);
g_strfreev (priv->domains);
g_strfreev (priv->searches);
g_strfreev (priv->wins_servers);
G_OBJECT_CLASS (nm_ip_config_parent_class)->finalize (object);
}
const NMLDBusMetaIface _nml_dbus_meta_iface_nm_ip4config = NML_DBUS_META_IFACE_INIT_PROP (
NM_DBUS_INTERFACE_IP4_CONFIG,
nm_ip4_config_get_type,
NML_DBUS_META_INTERFACE_PRIO_INSTANTIATE_HIGH,
NML_DBUS_META_IFACE_DBUS_PROPERTIES (
NML_DBUS_META_PROPERTY_INIT_FCN ("AddressData", PROP_ADDRESSES, "aa{sv}", _notify_update_prop_addresses ),
NML_DBUS_META_PROPERTY_INIT_FCN ("Addresses", PROP_ADDRESSES, "aau", _notify_update_prop_addresses, .obj_property_no_reverse_idx = TRUE ),
NML_DBUS_META_PROPERTY_INIT_TODO ("DnsOptions", "as" ),
NML_DBUS_META_PROPERTY_INIT_TODO ("DnsPriority", "i" ),
NML_DBUS_META_PROPERTY_INIT_AS ("Domains", PROP_DOMAINS, NMIPConfigPrivate, domains ),
NML_DBUS_META_PROPERTY_INIT_S ("Gateway", PROP_GATEWAY, NMIPConfigPrivate, gateway ),
NML_DBUS_META_PROPERTY_INIT_FCN ("NameserverData", PROP_NAMESERVERS, "aa{sv}", _notify_update_prop_nameservers ),
NML_DBUS_META_PROPERTY_INIT_FCN ("Nameservers", PROP_NAMESERVERS, "au", _notify_update_prop_nameservers, .obj_property_no_reverse_idx = TRUE ),
NML_DBUS_META_PROPERTY_INIT_FCN ("RouteData", PROP_ROUTES, "aa{sv}", _notify_update_prop_routes ),
NML_DBUS_META_PROPERTY_INIT_FCN ("Routes", PROP_ROUTES, "aau", _notify_update_prop_routes, .obj_property_no_reverse_idx = TRUE ),
NML_DBUS_META_PROPERTY_INIT_AS ("Searches", PROP_SEARCHES, NMIPConfigPrivate, searches ),
NML_DBUS_META_PROPERTY_INIT_FCN ("WinsServerData", PROP_WINS_SERVERS, "as", _notify_update_prop_wins_servers ),
NML_DBUS_META_PROPERTY_INIT_FCN ("WinsServers", PROP_WINS_SERVERS, "au", _notify_update_prop_wins_servers, .obj_property_no_reverse_idx = TRUE ),
),
.base_struct_offset = G_STRUCT_OFFSET (NMIPConfig, _priv),
);
const NMLDBusMetaIface _nml_dbus_meta_iface_nm_ip6config = NML_DBUS_META_IFACE_INIT_PROP (
NM_DBUS_INTERFACE_IP6_CONFIG,
nm_ip6_config_get_type,
NML_DBUS_META_INTERFACE_PRIO_INSTANTIATE_HIGH,
NML_DBUS_META_IFACE_DBUS_PROPERTIES (
NML_DBUS_META_PROPERTY_INIT_FCN ("AddressData", PROP_ADDRESSES, "aa{sv}", _notify_update_prop_addresses ),
NML_DBUS_META_PROPERTY_INIT_FCN ("Addresses", PROP_ADDRESSES, "a(ayuay)", _notify_update_prop_addresses, .obj_property_no_reverse_idx = TRUE ),
NML_DBUS_META_PROPERTY_INIT_TODO ("DnsOptions", "as" ),
NML_DBUS_META_PROPERTY_INIT_TODO ("DnsPriority", "i" ),
NML_DBUS_META_PROPERTY_INIT_AS ("Domains", PROP_DOMAINS, NMIPConfigPrivate, domains ),
NML_DBUS_META_PROPERTY_INIT_S ("Gateway", PROP_GATEWAY, NMIPConfigPrivate, gateway ),
NML_DBUS_META_PROPERTY_INIT_FCN ("Nameservers", PROP_NAMESERVERS, "aay", _notify_update_prop_nameservers ),
NML_DBUS_META_PROPERTY_INIT_FCN ("RouteData", PROP_ROUTES, "aa{sv}", _notify_update_prop_routes ),
NML_DBUS_META_PROPERTY_INIT_FCN ("Routes", PROP_ROUTES, "a(ayuayu)", _notify_update_prop_routes, .obj_property_no_reverse_idx = TRUE ),
NML_DBUS_META_PROPERTY_INIT_AS ("Searches", PROP_SEARCHES, NMIPConfigPrivate, searches ),
),
.base_struct_offset = G_STRUCT_OFFSET (NMIPConfig, _priv),
);
static void
nm_ip_config_class_init (NMIPConfigClass *config_class)
{
GObjectClass *object_class = G_OBJECT_CLASS (config_class);
NMObjectClass *nm_object_class = NM_OBJECT_CLASS (config_class);
g_type_class_add_private (config_class, sizeof (NMIPConfigPrivate));
object_class->get_property = get_property;
object_class->finalize = finalize;
nm_object_class->init_dbus = init_dbus;
/**
* NMIPConfig:family:
*
@ -344,7 +453,8 @@ nm_ip_config_class_init (NMIPConfigClass *config_class)
G_PARAM_READABLE |
G_PARAM_STATIC_STRINGS);
g_object_class_install_properties (object_class, _PROPERTY_ENUMS_LAST, obj_properties);
_nml_dbus_meta_class_init_with_properties (object_class, &_nml_dbus_meta_iface_nm_ip4config,
&_nml_dbus_meta_iface_nm_ip6config);
}
/**
@ -407,12 +517,12 @@ nm_ip_config_get_addresses (NMIPConfig *config)
*
* Returns: (transfer none): the array of nameserver IP addresses
**/
const char * const *
const char *const*
nm_ip_config_get_nameservers (NMIPConfig *config)
{
g_return_val_if_fail (NM_IS_IP_CONFIG (config), NULL);
return (const char * const *) NM_IP_CONFIG_GET_PRIVATE (config)->nameservers;
return _nml_coerce_property_strv_not_null (NM_IP_CONFIG_GET_PRIVATE (config)->nameservers);
}
/**
@ -424,12 +534,12 @@ nm_ip_config_get_nameservers (NMIPConfig *config)
* Returns: (transfer none): the array of domains.
* (This is never %NULL, though it may be 0-length).
**/
const char * const *
const char *const*
nm_ip_config_get_domains (NMIPConfig *config)
{
g_return_val_if_fail (NM_IS_IP_CONFIG (config), NULL);
return (const char * const *) NM_IP_CONFIG_GET_PRIVATE (config)->domains;
return _nml_coerce_property_strv_not_null (NM_IP_CONFIG_GET_PRIVATE (config)->domains);
}
/**
@ -441,12 +551,12 @@ nm_ip_config_get_domains (NMIPConfig *config)
* Returns: (transfer none): the array of DNS search strings.
* (This is never %NULL, though it may be 0-length).
**/
const char * const *
const char *const*
nm_ip_config_get_searches (NMIPConfig *config)
{
g_return_val_if_fail (NM_IS_IP_CONFIG (config), NULL);
return (const char * const *) NM_IP_CONFIG_GET_PRIVATE (config)->searches;
return _nml_coerce_property_strv_not_null (NM_IP_CONFIG_GET_PRIVATE (config)->searches);
}
/**
@ -458,12 +568,12 @@ nm_ip_config_get_searches (NMIPConfig *config)
* Returns: (transfer none): the arry of WINS server IP address strings.
* (This is never %NULL, though it may be 0-length.)
**/
const char * const *
const char *const*
nm_ip_config_get_wins_servers (NMIPConfig *config)
{
g_return_val_if_fail (NM_IS_IP_CONFIG (config), NULL);
return (const char * const *) NM_IP_CONFIG_GET_PRIVATE (config)->wins;
return _nml_coerce_property_strv_not_null (NM_IP_CONFIG_GET_PRIVATE (config)->wins_servers);
}
/**

View file

@ -10,6 +10,7 @@
#include "nm-glib-aux/nm-time-utils.h"
#include "nm-libnm-core-intern/nm-common-macros.h"
#include "nm-object.h"
/*****************************************************************************/
@ -741,3 +742,205 @@ nm_permission_result_to_client (const char *nm)
return NM_CLIENT_PERMISSION_RESULT_AUTH;
return NM_CLIENT_PERMISSION_RESULT_UNKNOWN;
}
/*****************************************************************************/
const NMLDBusMetaIface *const _nml_dbus_meta_ifaces[] = {
&_nml_dbus_meta_iface_nm,
&_nml_dbus_meta_iface_nm_accesspoint,
&_nml_dbus_meta_iface_nm_agentmanager,
&_nml_dbus_meta_iface_nm_checkpoint,
&_nml_dbus_meta_iface_nm_connection_active,
&_nml_dbus_meta_iface_nm_dhcp4config,
&_nml_dbus_meta_iface_nm_dhcp6config,
&_nml_dbus_meta_iface_nm_device,
&_nml_dbus_meta_iface_nm_device_adsl,
&_nml_dbus_meta_iface_nm_device_bluetooth,
&_nml_dbus_meta_iface_nm_device_bond,
&_nml_dbus_meta_iface_nm_device_bridge,
&_nml_dbus_meta_iface_nm_device_dummy,
&_nml_dbus_meta_iface_nm_device_generic,
&_nml_dbus_meta_iface_nm_device_iptunnel,
&_nml_dbus_meta_iface_nm_device_infiniband,
&_nml_dbus_meta_iface_nm_device_lowpan,
&_nml_dbus_meta_iface_nm_device_macsec,
&_nml_dbus_meta_iface_nm_device_macvlan,
&_nml_dbus_meta_iface_nm_device_modem,
&_nml_dbus_meta_iface_nm_device_olpcmesh,
&_nml_dbus_meta_iface_nm_device_ovsbridge,
&_nml_dbus_meta_iface_nm_device_ovsinterface,
&_nml_dbus_meta_iface_nm_device_ovsport,
&_nml_dbus_meta_iface_nm_device_ppp,
&_nml_dbus_meta_iface_nm_device_statistics,
&_nml_dbus_meta_iface_nm_device_team,
&_nml_dbus_meta_iface_nm_device_tun,
&_nml_dbus_meta_iface_nm_device_veth,
&_nml_dbus_meta_iface_nm_device_vlan,
&_nml_dbus_meta_iface_nm_device_vxlan,
&_nml_dbus_meta_iface_nm_device_wifip2p,
&_nml_dbus_meta_iface_nm_device_wireguard,
&_nml_dbus_meta_iface_nm_device_wired,
&_nml_dbus_meta_iface_nm_device_wireless,
&_nml_dbus_meta_iface_nm_device_wpan,
&_nml_dbus_meta_iface_nm_dnsmanager,
&_nml_dbus_meta_iface_nm_ip4config,
&_nml_dbus_meta_iface_nm_ip6config,
&_nml_dbus_meta_iface_nm_settings,
&_nml_dbus_meta_iface_nm_settings_connection,
&_nml_dbus_meta_iface_nm_vpn_connection,
&_nml_dbus_meta_iface_nm_wifip2ppeer,
};
#define COMMON_PREFIX "org.freedesktop.NetworkManager"
static int
_strcmp_common_prefix (gconstpointer a, gconstpointer b, gpointer user_data)
{
const NMLDBusMetaIface *iface = a;
const char *dbus_iface_name = b;
nm_assert (g_str_has_prefix (iface->dbus_iface_name, COMMON_PREFIX));
return strcmp (&iface->dbus_iface_name[NM_STRLEN (COMMON_PREFIX)], dbus_iface_name);
}
const NMLDBusMetaIface *
nml_dbus_meta_iface_get (const char *dbus_iface_name)
{
gssize idx;
nm_assert (dbus_iface_name);
G_STATIC_ASSERT_EXPR (G_STRUCT_OFFSET (NMLDBusMetaIface, dbus_iface_name) == 0);
/* we assume that NetworkManager only uses unique interface names. E.g. one
* interface name always has one particular meaning (and offers one set of
* properties, signals and methods). This is a convenient assumption, and
* we sure would never violate it when extending NM's D-Bus API. */
if (NM_STR_HAS_PREFIX (dbus_iface_name, COMMON_PREFIX)) {
/* optimize, that in fact all our interfaces have the same prefix. */
idx = nm_utils_ptrarray_find_binary_search ((gconstpointer *) _nml_dbus_meta_ifaces,
G_N_ELEMENTS (_nml_dbus_meta_ifaces),
&dbus_iface_name[NM_STRLEN (COMMON_PREFIX)],
_strcmp_common_prefix,
NULL,
NULL,
NULL);
} else
return NULL;
if (idx < 0)
return NULL;
return _nml_dbus_meta_ifaces[idx];
}
const NMLDBusMetaProperty *
nml_dbus_meta_property_get (const NMLDBusMetaIface *meta_iface,
const char *dbus_property_name,
guint *out_idx)
{
gssize idx;
nm_assert (meta_iface);
nm_assert (dbus_property_name);
idx = nm_utils_array_find_binary_search (meta_iface->dbus_properties,
sizeof (meta_iface->dbus_properties[0]),
meta_iface->n_dbus_properties,
&dbus_property_name,
nm_strcmp_p_with_data,
NULL);
if (idx < 0) {
NM_SET_OUT (out_idx, meta_iface->n_dbus_properties);
return NULL;
}
NM_SET_OUT (out_idx, idx);
return &meta_iface->dbus_properties[idx];
}
void
_nml_dbus_meta_class_init_with_properties_impl (GObjectClass *object_class,
const NMLDBusMetaIface *const*meta_ifaces)
{
int i_iface;
nm_assert (G_IS_OBJECT_CLASS (object_class));
nm_assert (meta_ifaces);
nm_assert (meta_ifaces[0]);
for (i_iface = 0; meta_ifaces[i_iface]; i_iface++) {
const NMLDBusMetaIface *meta_iface = meta_ifaces[i_iface];
guint8 *reverse_idx;
guint8 i;
nm_assert (g_type_is_a (meta_iface->get_type_fcn (), G_OBJECT_CLASS_TYPE (object_class)));
nm_assert (meta_iface->n_obj_properties > 0);
nm_assert (meta_iface->obj_properties);
nm_assert (meta_iface->obj_properties_reverse_idx[0] == 0);
nm_assert (meta_iface->obj_properties == meta_ifaces[0]->obj_properties);
if (i_iface == 0)
g_object_class_install_properties (object_class, meta_iface->n_obj_properties, (GParamSpec **) meta_iface->obj_properties);
reverse_idx = (guint8 *) meta_iface->obj_properties_reverse_idx;
for (i = 0; i < meta_iface->n_obj_properties; i++)
reverse_idx[i] = 0xFFu;
for (i = 0; i < meta_iface->n_dbus_properties; i++) {
const NMLDBusMetaProperty *mpr = &meta_iface->dbus_properties[i];
if ( mpr->obj_properties_idx != 0
&& !mpr->obj_property_no_reverse_idx) {
nm_assert (mpr->obj_properties_idx < meta_iface->n_obj_properties);
nm_assert (reverse_idx[mpr->obj_properties_idx] == 0xFFu);
reverse_idx[mpr->obj_properties_idx] = i;
}
}
}
}
gboolean
nm_utils_g_param_spec_is_default (const GParamSpec *pspec)
{
g_return_val_if_fail (pspec, FALSE);
if (pspec->value_type == G_TYPE_BOOLEAN)
return ((((GParamSpecBoolean *) pspec)->default_value) == FALSE);
if (pspec->value_type == G_TYPE_UCHAR)
return ((((GParamSpecUChar *) pspec)->default_value) == 0u);
if (pspec->value_type == G_TYPE_INT)
return ((((GParamSpecInt *) pspec)->default_value) == 0);
if (pspec->value_type == G_TYPE_UINT)
return ((((GParamSpecUInt *) pspec)->default_value) == 0u);
if (pspec->value_type == G_TYPE_INT64)
return ((((GParamSpecInt64 *) pspec)->default_value) == 0);
if (pspec->value_type == G_TYPE_UINT64)
return ((((GParamSpecUInt64 *) pspec)->default_value) == 0u);
if (g_type_is_a (pspec->value_type, G_TYPE_ENUM))
return ((((GParamSpecEnum *) pspec)->default_value) == 0);
if (g_type_is_a (pspec->value_type, G_TYPE_FLAGS))
return ((((GParamSpecFlags *) pspec)->default_value) == 0u);
if (pspec->value_type == G_TYPE_STRING)
return ((((GParamSpecString *) pspec)->default_value) == NULL);
if (NM_IN_SET (pspec->value_type, G_TYPE_BYTES,
G_TYPE_PTR_ARRAY,
G_TYPE_HASH_TABLE,
G_TYPE_STRV)) {
/* boxed types have NULL default. */
g_return_val_if_fail (G_IS_PARAM_SPEC_BOXED (pspec), FALSE);
g_return_val_if_fail (G_TYPE_IS_BOXED (pspec->value_type), FALSE);
return TRUE;
}
if (g_type_is_a (pspec->value_type, NM_TYPE_OBJECT)) {
/* object types have NULL default. */
g_return_val_if_fail (G_IS_PARAM_SPEC_OBJECT (pspec), FALSE);
g_return_val_if_fail (G_TYPE_IS_OBJECT (pspec->value_type), FALSE);
return TRUE;
}
/* This function is only used for asserting/testing. It thus
* strictly asserts and only support argument types that we expect. */
g_return_val_if_reached (FALSE);
}

View file

@ -6,8 +6,10 @@
#ifndef __NM_LIBNM_UTILS_H__
#define __NM_LIBNM_UTILS_H__
#include "nm-types.h"
#include "c-list/src/c-list.h"
#include "nm-glib-aux/nm-ref-string.h"
#include "nm-types.h"
#include "nm-object.h"
#include "nm-client.h"
/*****************************************************************************/
@ -18,6 +20,15 @@
/*****************************************************************************/
char *nm_utils_fixup_vendor_string (const char *desc);
char *nm_utils_fixup_product_string (const char *desc);
char *nm_utils_wincaps_to_dash (const char *caps);
gboolean nm_utils_g_param_spec_is_default (const GParamSpec *pspec);
/*****************************************************************************/
NMClientPermission nm_permission_to_client (const char *nm);
NMClientPermissionResult nm_permission_result_to_client (const char *nm);
@ -142,35 +153,585 @@ _nml_coerce_property_strv_not_null (char **strv)
/*****************************************************************************/
char *nm_utils_wincaps_to_dash (const char *caps);
typedef struct _NMLDBusObject NMLDBusObject;
typedef struct _NMLDBusObjWatcher NMLDBusObjWatcher;
typedef struct _NMLDBusMetaIface NMLDBusMetaIface;
typedef struct _NMLDBusPropertyO NMLDBusPropertyO;
typedef struct _NMLDBusPropertyAO NMLDBusPropertyAO;
typedef enum {
/* See comments below for NMLDBusMetaIface.interface_prio.
*
* Higher numbers means more important to detect the GObject type. */
NML_DBUS_META_INTERFACE_PRIO_NONE = 0,
NML_DBUS_META_INTERFACE_PRIO_NMCLIENT = 1,
NML_DBUS_META_INTERFACE_PRIO_PARENT_TYPE = 2,
NML_DBUS_META_INTERFACE_PRIO_INSTANTIATE_LOW = 3,
NML_DBUS_META_INTERFACE_PRIO_INSTANTIATE_HIGH = 4,
} NMLDBusMetaInteracePrio;
/*****************************************************************************/
char *nm_utils_fixup_vendor_string (const char *desc);
char *nm_utils_fixup_product_string (const char *desc);
typedef struct {
GType (*get_o_type_fcn) (void);
/* Ignore whether the referenced NMObject is ready or not. That means,
* the property is always ready (and if the pointed object itself is
* not yet ready, the property pretends to be %NULL for the moment. */
bool is_always_ready:1;
} NMLDBusPropertVTableO;
struct _NMLDBusPropertyO {
NMLDBusObject *owner_dbobj;
NMLDBusObjWatcher *obj_watcher;
GObject *nmobj;
const NMLDBusMetaIface *meta_iface;
guint dbus_property_idx;
bool is_ready:1;
bool is_changed:1;
bool block_is_changed:1;
};
gpointer nml_dbus_property_o_get_obj (NMLDBusPropertyO *pr_o);
gboolean nml_dbus_property_o_is_ready (const NMLDBusPropertyO *pr_o);
void nml_dbus_property_o_clear (NMLDBusPropertyO *pr_o,
NMClient *client);
void nml_dbus_property_o_clear_many (NMLDBusPropertyO *pr_o,
guint len,
NMClient *self);
void nml_dbus_property_o_notify_changed_many (NMLDBusPropertyO *ptr,
guint len,
NMClient *self);
/*****************************************************************************/
typedef struct {
GType (*get_o_type_fcn) (void);
void (*notify_changed_ao) (NMLDBusPropertyAO *pr_ao,
NMClient *self,
NMObject *nmobj,
gboolean is_added /* or else removed */);
gboolean (*check_nmobj_visible_fcn) (GObject *nmobj);
/* Ignore whether the referenced NMObject is ready or not. That means,
* the property is always ready (and if the pointed object itself is
* not yet ready, the property pretends to be %NULL for the moment. */
bool is_always_ready:1;
} NMLDBusPropertVTableAO;
struct _NMLDBusPropertyAOData;
struct _NMLDBusPropertyAO {
CList data_lst_head;
GHashTable *hash;
NMLDBusObject *owner_dbobj;
const NMLDBusMetaIface *meta_iface;
GPtrArray *arr;
struct _NMLDBusPropertyAOData *changed_head;
guint dbus_property_idx;
guint n_not_ready;
bool is_changed:1;
};
const GPtrArray *nml_dbus_property_ao_get_objs_as_ptrarray (NMLDBusPropertyAO *pr_ao);
gboolean nml_dbus_property_ao_is_ready (const NMLDBusPropertyAO *pr_ao);
void nml_dbus_property_ao_clear (NMLDBusPropertyAO *pr_ao,
NMClient *client);
void nml_dbus_property_ao_clear_many (NMLDBusPropertyAO *pr_ao,
guint len,
NMClient *self);
void nml_dbus_property_ao_notify_changed_many (NMLDBusPropertyAO *ptr,
guint len,
NMClient *self);
/*****************************************************************************/
typedef enum {
NML_DBUS_NOTIFY_UPDATE_PROP_FLAGS_NONE = 0,
NML_DBUS_NOTIFY_UPDATE_PROP_FLAGS_NOTIFY = 0x1,
} NMLDBusNotifyUpdatePropFlags;
NMLDBusNotifyUpdatePropFlags _nml_dbus_notify_update_prop_ignore (NMClient *client,
NMLDBusObject *dbobj,
const NMLDBusMetaIface *meta_iface,
guint dbus_property_idx,
GVariant *value);
NMLDBusNotifyUpdatePropFlags _nml_dbus_notify_update_prop_o (NMClient *client,
NMLDBusObject *dbobj,
const NMLDBusMetaIface *meta_iface,
guint dbus_property_idx,
GVariant *value);
typedef struct {
const char *dbus_property_name;
const GVariantType *dbus_type;
guint16 prop_struct_offset;
guint8 obj_properties_idx;
bool use_notify_update_prop:1;
bool obj_property_no_reverse_idx:1;
union {
union {
const NMLDBusPropertVTableO *property_vtable_o;
const NMLDBusPropertVTableAO *property_vtable_ao;
} extra;
NMLDBusNotifyUpdatePropFlags (*notify_update_prop) (NMClient *client,
NMLDBusObject *dbobj,
const NMLDBusMetaIface *meta_iface,
guint dbus_property_idx,
GVariant *value);
};
} NMLDBusMetaProperty;
#define NML_DBUS_META_PROPERTY_INIT(v_dbus_property_name, \
v_dbus_type, \
v_obj_properties_idx, \
...) \
{ \
.dbus_property_name = ""v_dbus_property_name"", \
.dbus_type = NM_G_VARIANT_TYPE (""v_dbus_type""), \
.obj_properties_idx = v_obj_properties_idx, \
##__VA_ARGS__ \
}
#define _NML_DBUS_META_PROPERTY_INIT_DEFAULT(v_dbus_type, \
v_exp_type, \
v_dbus_property_name, \
v_obj_properties_idx, \
v_container, \
v_field) \
NML_DBUS_META_PROPERTY_INIT (v_dbus_property_name, \
v_dbus_type, \
v_obj_properties_idx, \
.prop_struct_offset = NM_STRUCT_OFFSET_ENSURE_TYPE (v_exp_type, v_container, v_field))
#define NML_DBUS_META_PROPERTY_INIT_B(...) _NML_DBUS_META_PROPERTY_INIT_DEFAULT ("b", bool, __VA_ARGS__)
#define NML_DBUS_META_PROPERTY_INIT_Y(...) _NML_DBUS_META_PROPERTY_INIT_DEFAULT ("y", guint8, __VA_ARGS__)
#define NML_DBUS_META_PROPERTY_INIT_Q(...) _NML_DBUS_META_PROPERTY_INIT_DEFAULT ("q", guint16, __VA_ARGS__)
#define NML_DBUS_META_PROPERTY_INIT_I(...) _NML_DBUS_META_PROPERTY_INIT_DEFAULT ("i", gint32, __VA_ARGS__)
#define NML_DBUS_META_PROPERTY_INIT_U(...) _NML_DBUS_META_PROPERTY_INIT_DEFAULT ("u", guint32, __VA_ARGS__)
#define NML_DBUS_META_PROPERTY_INIT_X(...) _NML_DBUS_META_PROPERTY_INIT_DEFAULT ("x", gint64, __VA_ARGS__)
#define NML_DBUS_META_PROPERTY_INIT_T(...) _NML_DBUS_META_PROPERTY_INIT_DEFAULT ("t", guint64, __VA_ARGS__)
#define NML_DBUS_META_PROPERTY_INIT_S(...) _NML_DBUS_META_PROPERTY_INIT_DEFAULT ("s", char *, __VA_ARGS__)
#define NML_DBUS_META_PROPERTY_INIT_AS(...) _NML_DBUS_META_PROPERTY_INIT_DEFAULT ("as", char **, __VA_ARGS__)
#define NML_DBUS_META_PROPERTY_INIT_AY(...) _NML_DBUS_META_PROPERTY_INIT_DEFAULT ("ay", GBytes *, __VA_ARGS__)
#define NML_DBUS_META_PROPERTY_INIT_O(v_dbus_property_name, \
v_obj_properties_idx, \
v_container, \
v_field) \
NML_DBUS_META_PROPERTY_INIT (v_dbus_property_name, \
"o", \
v_obj_properties_idx, \
.prop_struct_offset = NM_STRUCT_OFFSET_ENSURE_TYPE (NMRefString *, v_container, v_field), \
.use_notify_update_prop = TRUE, \
.notify_update_prop = _nml_dbus_notify_update_prop_o)
#define NML_DBUS_META_PROPERTY_INIT_O_PROP(v_dbus_property_name, \
v_obj_properties_idx, \
v_container, \
v_field, \
v_get_o_type_fcn, \
...) \
NML_DBUS_META_PROPERTY_INIT (v_dbus_property_name, \
"o", \
v_obj_properties_idx, \
.prop_struct_offset = NM_STRUCT_OFFSET_ENSURE_TYPE (NMLDBusPropertyO, v_container, v_field), \
.extra.property_vtable_o = &((const NMLDBusPropertVTableO) { \
.get_o_type_fcn = (v_get_o_type_fcn), \
##__VA_ARGS__ \
}))
#define NML_DBUS_META_PROPERTY_INIT_AO_PROP(v_dbus_property_name, \
v_obj_properties_idx, \
v_container, \
v_field, \
v_get_o_type_fcn, \
...) \
NML_DBUS_META_PROPERTY_INIT (v_dbus_property_name, \
"ao", \
v_obj_properties_idx, \
.prop_struct_offset = NM_STRUCT_OFFSET_ENSURE_TYPE (NMLDBusPropertyAO, v_container, v_field), \
.extra.property_vtable_ao = &((const NMLDBusPropertVTableAO) { \
.get_o_type_fcn = (v_get_o_type_fcn), \
##__VA_ARGS__ \
}))
#define NML_DBUS_META_PROPERTY_INIT_FCN(v_dbus_property_name, \
v_obj_properties_idx, \
v_dbus_type, \
v_notify_update_prop, \
...) \
NML_DBUS_META_PROPERTY_INIT (v_dbus_property_name, \
v_dbus_type, \
v_obj_properties_idx, \
.use_notify_update_prop = TRUE, \
.notify_update_prop = (v_notify_update_prop), \
##__VA_ARGS__)
#define NML_DBUS_META_PROPERTY_INIT_IGNORE(v_dbus_property_name, \
v_dbus_type) \
NML_DBUS_META_PROPERTY_INIT (v_dbus_property_name, \
v_dbus_type, \
0, \
.use_notify_update_prop = TRUE, \
.notify_update_prop = _nml_dbus_notify_update_prop_ignore)
/* "TODO" is like "IGNORE". The difference is that we don't plan to ever implement "IGNORE", but
* "TODO" is something we should add support for. */
#define NML_DBUS_META_PROPERTY_INIT_TODO(...) \
NML_DBUS_META_PROPERTY_INIT_IGNORE (__VA_ARGS__)
struct _NMLDBusMetaIface {
const char *dbus_iface_name;
GType (*get_type_fcn) (void);
/* Usually there is a one-to-one correspondence between the properties
* on D-Bus (dbus_properties) and the GObject properties (obj_properties).
*
* With:
* meta_iface->obj_properties[o_idx] (o_idx < n_obj_properties)
* &meta_iface->dbus_properties[d_idx] (d_idx < n_dbus_properties)
* it follows that
* assert (meta_iface->obj_properties_reverse_idx[o_idx] == d_idx)
* assert (meta_iface->dbus_properties[d_idx].obj_properties_idx == o_idx)
* if (and only if) two properties correspond.
*/
const GParamSpec *const*obj_properties;
const NMLDBusMetaProperty *dbus_properties;
const guint8 *obj_properties_reverse_idx;
guint8 n_dbus_properties;
guint8 n_obj_properties;
/* The offsets "prop_struct_offset" in NMLDBusMetaProperty are based on some base
* struct. If "base_struct_offset" is 0, then the base struct is the GObject pointer
* itself.
* If this is non-null, then we expect at that location a pointer to the offset.
* In this case we need to first find the base pointer via
* *((gpointer *) ((char *) nmobj + meta_iface->base_struct_offset)).
*
* This covers NMDeviceBridge._priv vs. NMDevice._priv. In the second case,
* _priv is a pointer that we first need to follow.
*/
guint8 base_struct_offset;
/* We create the appropriate NMObject GType based on the D-Bus interfaces that
* are present. For example, if we see a "org.freedesktop.NetworkManager.Device.Bridge"
* interface, we create a NMDeviceBridge. Basically, if it looks like a certain
* object (based on the D-Bus interface), we assume it is.
*
* Some interfaces are purely additional ("org.freedesktop.NetworkManager.Device.Statistics")
* and don't determine the NMObject type (%NML_DBUS_META_INTERFACE_PRIO_NONE).
*
* Some interfaces are of a parent type ("org.freedesktop.NetworkManager.Device" for
* NMDevice), and don't determine the type either (%NML_DBUS_META_INTERFACE_PRIO_PARENT_TYPE).
*
* Some interfaces ("org.freedesktop.NetworkManager.AgentManager") belong to NMClient
* itself. Those have priority %NML_DBUS_META_INTERFACE_PRIO_NMCLIENT.
*
* In most cases, each D-Bus object is expected to have only one D-Bus interface
* to determine the type. While theoretically an object
* "/org/freedesktop/NetworkManager/Devices/3" could have interfaces "org.freedesktop.NetworkManager.Device.Bridge"
* and "org.freedesktop.NetworkManager.Device.Bond" at the same time, in practice it doesn't.
* Note that we also assume that once a D-Bus object gets a NMObject, it cannot change (*).
* NetworkManager's API does not add/remove interfaces after exporting the object the
* first time, so in practice each D-Bus object is expected to have a suitable D-Bus
* interface (and only determining interface, which doesn't change). Those interfaces have
* priority %NML_DBUS_META_INTERFACE_PRIO_INSTANTIATE_HIGH.
*
* (*) note that nothing bad would happen if a faulty NetworkManager would violate that.
* Of course, something would not work correctly, but the D-Bus interface we find is unexpected
* and wrong.
*
* One exception is "org.freedesktop.NetworkManager.Connection.Active". This can either
* be a NMActiveConnection or a NMVpnConnection. Hence, this profile has priority
* %NML_DBUS_META_INTERFACE_PRIO_INSTANTIATE_LOW, and depending on whether there is
* a "org.freedesktop.NetworkManager.VPN.Connection" (with high priority), we create
* one or the other type.
*/
NMLDBusMetaInteracePrio interface_prio:3;
};
#define NML_DBUS_META_IFACE_OBJ_PROPERTIES() \
.obj_properties = (const GParamSpec *const*) (obj_properties), \
.n_obj_properties = _PROPERTY_ENUMS_LAST, \
.obj_properties_reverse_idx = ((guint8 [_PROPERTY_ENUMS_LAST]) { })
#define NML_DBUS_META_IFACE_DBUS_PROPERTIES(...) \
.dbus_properties = ((const NMLDBusMetaProperty []) { __VA_ARGS__ }), \
.n_dbus_properties = sizeof ((const NMLDBusMetaProperty []) { __VA_ARGS__ }) / sizeof (NMLDBusMetaProperty) \
#define NML_DBUS_META_IFACE_INIT(v_dbus_iface_name, \
v_get_type_fcn, \
v_interface_prio, \
...) \
{ \
.dbus_iface_name = ""v_dbus_iface_name"", \
.get_type_fcn = v_get_type_fcn, \
.interface_prio = v_interface_prio, \
##__VA_ARGS__ \
}
#define NML_DBUS_META_IFACE_INIT_PROP(...) \
NML_DBUS_META_IFACE_INIT (__VA_ARGS__ \
NML_DBUS_META_IFACE_OBJ_PROPERTIES ())
extern const NMLDBusMetaIface *const _nml_dbus_meta_ifaces[43];
extern const NMLDBusMetaIface _nml_dbus_meta_iface_nm;
extern const NMLDBusMetaIface _nml_dbus_meta_iface_nm_accesspoint;
extern const NMLDBusMetaIface _nml_dbus_meta_iface_nm_agentmanager;
extern const NMLDBusMetaIface _nml_dbus_meta_iface_nm_checkpoint;
extern const NMLDBusMetaIface _nml_dbus_meta_iface_nm_connection_active;
extern const NMLDBusMetaIface _nml_dbus_meta_iface_nm_device;
extern const NMLDBusMetaIface _nml_dbus_meta_iface_nm_device_adsl;
extern const NMLDBusMetaIface _nml_dbus_meta_iface_nm_device_bluetooth;
extern const NMLDBusMetaIface _nml_dbus_meta_iface_nm_device_bond;
extern const NMLDBusMetaIface _nml_dbus_meta_iface_nm_device_bridge;
extern const NMLDBusMetaIface _nml_dbus_meta_iface_nm_device_dummy;
extern const NMLDBusMetaIface _nml_dbus_meta_iface_nm_device_generic;
extern const NMLDBusMetaIface _nml_dbus_meta_iface_nm_device_infiniband;
extern const NMLDBusMetaIface _nml_dbus_meta_iface_nm_device_iptunnel;
extern const NMLDBusMetaIface _nml_dbus_meta_iface_nm_device_lowpan;
extern const NMLDBusMetaIface _nml_dbus_meta_iface_nm_device_macsec;
extern const NMLDBusMetaIface _nml_dbus_meta_iface_nm_device_macvlan;
extern const NMLDBusMetaIface _nml_dbus_meta_iface_nm_device_modem;
extern const NMLDBusMetaIface _nml_dbus_meta_iface_nm_device_olpcmesh;
extern const NMLDBusMetaIface _nml_dbus_meta_iface_nm_device_ovsbridge;
extern const NMLDBusMetaIface _nml_dbus_meta_iface_nm_device_ovsinterface;
extern const NMLDBusMetaIface _nml_dbus_meta_iface_nm_device_ovsport;
extern const NMLDBusMetaIface _nml_dbus_meta_iface_nm_device_ppp;
extern const NMLDBusMetaIface _nml_dbus_meta_iface_nm_device_statistics;
extern const NMLDBusMetaIface _nml_dbus_meta_iface_nm_device_team;
extern const NMLDBusMetaIface _nml_dbus_meta_iface_nm_device_tun;
extern const NMLDBusMetaIface _nml_dbus_meta_iface_nm_device_veth;
extern const NMLDBusMetaIface _nml_dbus_meta_iface_nm_device_vlan;
extern const NMLDBusMetaIface _nml_dbus_meta_iface_nm_device_vxlan;
extern const NMLDBusMetaIface _nml_dbus_meta_iface_nm_device_wifip2p;
extern const NMLDBusMetaIface _nml_dbus_meta_iface_nm_device_wired;
extern const NMLDBusMetaIface _nml_dbus_meta_iface_nm_device_wireguard;
extern const NMLDBusMetaIface _nml_dbus_meta_iface_nm_device_wireless;
extern const NMLDBusMetaIface _nml_dbus_meta_iface_nm_device_wpan;
extern const NMLDBusMetaIface _nml_dbus_meta_iface_nm_dhcp4config;
extern const NMLDBusMetaIface _nml_dbus_meta_iface_nm_dhcp6config;
extern const NMLDBusMetaIface _nml_dbus_meta_iface_nm_dnsmanager;
extern const NMLDBusMetaIface _nml_dbus_meta_iface_nm_ip4config;
extern const NMLDBusMetaIface _nml_dbus_meta_iface_nm_ip6config;
extern const NMLDBusMetaIface _nml_dbus_meta_iface_nm_settings;
extern const NMLDBusMetaIface _nml_dbus_meta_iface_nm_settings_connection;
extern const NMLDBusMetaIface _nml_dbus_meta_iface_nm_vpn_connection;
extern const NMLDBusMetaIface _nml_dbus_meta_iface_nm_wifip2ppeer;
const NMLDBusMetaIface *nml_dbus_meta_iface_get (const char *dbus_iface_name);
const NMLDBusMetaProperty *nml_dbus_meta_property_get (const NMLDBusMetaIface *meta_iface,
const char *dbus_property_name,
guint *out_idx);
void _nml_dbus_meta_class_init_with_properties_impl (GObjectClass *object_class, const NMLDBusMetaIface *const*meta_iface);
#define _nml_dbus_meta_class_init_with_properties(object_class, ...) \
_nml_dbus_meta_class_init_with_properties_impl ((object_class), ((const NMLDBusMetaIface *const[]) { __VA_ARGS__, NULL }))
/*****************************************************************************/
typedef enum {
NML_DBUS_OBJ_STATE_UNLINKED = 0,
NML_DBUS_OBJ_STATE_WATCHED_ONLY,
NML_DBUS_OBJ_STATE_ON_DBUS,
NML_DBUS_OBJ_STATE_WITH_NMOBJ_NOT_READY,
NML_DBUS_OBJ_STATE_WITH_NMOBJ_READY,
} NMLDBusObjState;
typedef enum {
NML_DBUS_OBJ_CHANGED_TYPE_NONE = 0,
NML_DBUS_OBJ_CHANGED_TYPE_DBUS = (1LL << 0),
NML_DBUS_OBJ_CHANGED_TYPE_NMOBJ = (1LL << 1),
} NMLDBusObjChangedType;
struct _NMLDBusObject {
NMRefString *dbus_path;
/* While the object is tracked by NMClient, it is linked with this list.
* The lists are partitioned based on the NMLDBusObjState. */
CList dbus_objects_lst;
/* The list of D-Bus interface NMLDBusObjIfaceData.
*
* Some may be about to be removed (iface_removed) or
* unknown (!dbus_iface_is_wellknown). */
CList iface_lst_head;
/* The list of registered NMLDBusObjWatcher. */
CList watcher_lst_head;
/* When an object changes (e.g. because of new information on D-Bus), we often
* don't process the changes right away, but enqueue the object in a changed
* list. This list goes together with obj_changed_type property below, which
* tracks what changed. */
CList obj_changed_lst;
GObject *nmobj;
int ref_count;
NMLDBusObjState obj_state:4;
NMLDBusObjChangedType obj_changed_type:3;
};
static inline gboolean
NML_IS_DBUS_OBJECT (NMLDBusObject *dbobj)
{
nm_assert ( !dbobj
|| ( NM_IS_REF_STRING (dbobj->dbus_path)
&& dbobj->ref_count > 0));
nm_assert ( !dbobj->nmobj
|| NM_IS_OBJECT (dbobj->nmobj)
|| NM_IS_CLIENT (dbobj->nmobj));
return !!dbobj;
}
NMLDBusObject *nml_dbus_object_ref (NMLDBusObject *dbobj);
void nml_dbus_object_unref (NMLDBusObject *dbobj);
NM_AUTO_DEFINE_FCN0 (NMLDBusObject *, _nm_auto_unref_nml_dbusobj, nml_dbus_object_unref)
#define nm_auto_unref_nml_dbusobj nm_auto (_nm_auto_unref_nml_dbusobj)
gpointer nml_dbus_object_get_property_location (NMLDBusObject *dbobj,
const NMLDBusMetaIface *meta_iface,
const NMLDBusMetaProperty *meta_property);
/*****************************************************************************/
/* NMClient is not an NMObject, but in some aspects we want to track it like
* an NMObject. For that, both NMClient and NMObject "implement" NMObjectBase,
* despite not actually implementing such a GObject type. */
typedef struct {
GObject parent;
CList queue_notify_lst;
bool is_disposing:1;
} NMObjectBase;
typedef struct {
GObjectClass parent;
} NMObjectBaseClass;
struct _NMObjectPrivate;
struct _NMObject {
GObject parent;
union {
GObject parent;
NMObjectBase obj_base;
};
struct _NMObjectPrivate *_priv;
};
typedef struct _NMObjectClassFieldInfo {
const struct _NMObjectClassFieldInfo *parent;
NMObjectClass *klass;
guint16 offset;
guint16 num;
} _NMObjectClassFieldInfo;
struct _NMObjectClass {
GObjectClass parent;
union {
GObjectClass parent;
NMObjectBaseClass obj_base;
};
void (*init_dbus) (struct _NMObject *object);
void (*register_client) (NMObject *self,
NMClient *client,
NMLDBusObject *dbobj);
/* The "object-creation-failed" method is PRIVATE for libnm and
* is not meant for any external usage. It indicates that an error
* occurred during creation of an object.
*/
void (*object_creation_failed) (struct _NMObject *master_object,
const char *failed_path);
void (*unregister_client) (NMObject *self,
NMClient *client,
NMLDBusObject *dbobj);
gboolean (*is_ready) (NMObject *self);
void (*obj_changed_notify) (NMObject *self);
const _NMObjectClassFieldInfo *property_o_info;
const _NMObjectClassFieldInfo *property_ao_info;
guint16 priv_ptr_offset;
bool priv_ptr_indirect:1;
};
#define _NM_OBJECT_CLASS_INIT_PRIV_PTR_DIRECT(nm_object_class, type_name) \
G_STMT_START { \
(nm_object_class)->priv_ptr_offset = NM_STRUCT_OFFSET_ENSURE_TYPE (type_name##Private, type_name, _priv); \
(nm_object_class)->priv_ptr_indirect = FALSE; \
} G_STMT_END
#define _NM_OBJECT_CLASS_INIT_PRIV_PTR_INDIRECT(nm_object_class, type_name) \
G_STMT_START { \
(nm_object_class)->priv_ptr_offset = NM_STRUCT_OFFSET_ENSURE_TYPE (type_name##Private *, type_name, _priv); \
(nm_object_class)->priv_ptr_indirect = TRUE; \
} G_STMT_END
#define _NM_OBJECT_CLASS_INIT_FIELD_INFO(_nm_object_class, _field_name, _offset, _num) \
G_STMT_START { \
(_nm_object_class)->_field_name = ({ \
static _NMObjectClassFieldInfo _f; \
\
_f = (_NMObjectClassFieldInfo) { \
.parent = (_nm_object_class)->_field_name, \
.klass = (_nm_object_class), \
.offset = _offset, \
.num = _num, \
}; \
&_f; \
}); \
} G_STMT_END
#define _NM_OBJECT_CLASS_INIT_PROPERTY_O_FIELDS_1(nm_object_class, type_name, field_name) \
_NM_OBJECT_CLASS_INIT_FIELD_INFO (nm_object_class, \
property_o_info, \
NM_STRUCT_OFFSET_ENSURE_TYPE (NMLDBusPropertyO, type_name, field_name), \
1)
#define _NM_OBJECT_CLASS_INIT_PROPERTY_O_FIELDS_N(nm_object_class, type_name, field_name) \
_NM_OBJECT_CLASS_INIT_FIELD_INFO (nm_object_class, \
property_o_info, \
NM_STRUCT_OFFSET_ENSURE_TYPE (NMLDBusPropertyO *, type_name, field_name), \
G_N_ELEMENTS (((type_name *) NULL)->field_name))
#define _NM_OBJECT_CLASS_INIT_PROPERTY_AO_FIELDS_1(nm_object_class, type_name, field_name) \
_NM_OBJECT_CLASS_INIT_FIELD_INFO (nm_object_class, \
property_ao_info, \
NM_STRUCT_OFFSET_ENSURE_TYPE (NMLDBusPropertyAO, type_name, field_name), \
1)
#define _NM_OBJECT_CLASS_INIT_PROPERTY_AO_FIELDS_N(nm_object_class, type_name, field_name) \
_NM_OBJECT_CLASS_INIT_FIELD_INFO (nm_object_class, \
property_ao_info, \
NM_STRUCT_OFFSET_ENSURE_TYPE (NMLDBusPropertyAO *, type_name, field_name), \
G_N_ELEMENTS (((type_name *) NULL)->field_name))
/*****************************************************************************/
struct _NMDevicePrivate;
@ -183,19 +744,13 @@ struct _NMDevice {
struct _NMDeviceClass {
struct _NMObjectClass parent;
/* Signals */
void (*state_changed) (NMDevice *device,
NMDeviceState new_state,
NMDeviceState old_state,
NMDeviceStateReason reason);
/* Methods */
gboolean (*connection_compatible) (NMDevice *device,
NMConnection *connection,
GError **error);
const char * (*get_type_description) (NMDevice *device);
const char * (*get_hw_address) (NMDevice *device);
const char *(*get_type_description) (NMDevice *device);
const char *(*get_hw_address) (NMDevice *device);
GType (*get_setting_type) (NMDevice *device);
};
@ -241,4 +796,154 @@ struct _NMIPConfigClass {
/*****************************************************************************/
NMLDBusObject *_nm_object_get_dbobj (gpointer self);
const char *_nm_object_get_path (gpointer self);
NMClient *_nm_object_get_client (gpointer self);
GDBusConnection *_nm_client_get_dbus_connection (NMClient *client);
const char *_nm_client_get_dbus_name_owner (NMClient *client);
GMainContext *_nm_client_get_context_main (NMClient *client);
GMainContext *_nm_client_get_context_dbus (NMClient *client);
void _nm_client_queue_notify_object (NMClient *client,
gpointer nmobj,
const GParamSpec *pspec);
void _nm_client_notify_object_changed (NMClient *self,
NMLDBusObject *dbobj);
struct udev *_nm_client_get_udev (NMClient *self);
/*****************************************************************************/
#define NM_CLIENT_NOTIFY_EVENT_PRIO_BEFORE (-100)
#define NM_CLIENT_NOTIFY_EVENT_PRIO_GPROP 0
#define NM_CLIENT_NOTIFY_EVENT_PRIO_AFTER 100
typedef struct _NMClientNotifyEvent NMClientNotifyEvent;
typedef void (*NMClientNotifyEventCb) (NMClient *self,
gpointer notify_event);
struct _NMClientNotifyEvent {
CList lst;
NMClientNotifyEventCb callback;
int priority;
};
gpointer _nm_client_notify_event_queue (NMClient *self,
int priority,
NMClientNotifyEventCb callback,
gsize event_size);
typedef struct _NMClientNotifyEventWithPtr NMClientNotifyEventWithPtr;
typedef void (*NMClientNotifyEventWithPtrCb) (NMClient *self,
NMClientNotifyEventWithPtr *notify_event);
struct _NMClientNotifyEventWithPtr {
NMClientNotifyEvent parent;
gpointer user_data;
};
NMClientNotifyEventWithPtr *_nm_client_notify_event_queue_with_ptr (NMClient *self,
int priority,
NMClientNotifyEventWithPtrCb callback,
gpointer user_data);
void _nm_client_notify_event_queue_emit_obj_signal (NMClient *self,
GObject *source,
NMObject *nmobj,
gboolean is_added /* or else removed */,
int prio_offset,
guint signal_id);
/*****************************************************************************/
GError *_nm_client_new_error_nm_not_running (void);
GError *_nm_client_new_error_nm_not_cached (void);
void _nm_client_dbus_call_simple (NMClient *self,
GCancellable *cancellable,
const char *object_path,
const char *interface_name,
const char *method_name,
GVariant *parameters,
const GVariantType *reply_type,
GDBusCallFlags flags,
int timeout_msec,
GAsyncReadyCallback callback,
gpointer user_data);
void _nm_client_dbus_call (NMClient *self,
gpointer source_obj,
gpointer source_tag,
GCancellable *cancellable,
GAsyncReadyCallback user_callback,
gpointer user_callback_data,
const char *object_path,
const char *interface_name,
const char *method_name,
GVariant *parameters,
const GVariantType *reply_type,
GDBusCallFlags flags,
int timeout_msec,
GAsyncReadyCallback internal_callback);
GVariant *_nm_client_dbus_call_sync (NMClient *self,
GCancellable *cancellable,
const char *object_path,
const char *interface_name,
const char *method_name,
GVariant *parameters,
const GVariantType *reply_type,
GDBusCallFlags flags,
int timeout_msec,
gboolean strip_dbus_error,
GError **error);
gboolean _nm_client_dbus_call_sync_void (NMClient *self,
GCancellable *cancellable,
const char *object_path,
const char *interface_name,
const char *method_name,
GVariant *parameters,
GDBusCallFlags flags,
int timeout_msec,
gboolean strip_dbus_error,
GError **error);
void _nm_client_set_property_sync_legacy (NMClient *self,
const char *object_path,
const char *interface,
const char *prop_name,
const char *format_string,
...);
/*****************************************************************************/
void _nm_client_get_settings_call (NMClient *self,
NMLDBusObject *dbobj);
GCancellable *_nm_remote_settings_get_settings_prepare (NMRemoteConnection *self);
void _nm_remote_settings_get_settings_commit (NMRemoteConnection *self,
GVariant *settings);
/*****************************************************************************/
void _nm_active_connection_state_changed_commit (NMActiveConnection *self,
guint32 state,
guint32 reason);
void _nm_vpn_connection_state_changed_commit (NMVpnConnection *self,
guint32 state,
guint32 reason);
/*****************************************************************************/
#endif /* __NM_LIBNM_UTILS_H__ */

File diff suppressed because it is too large Load diff

View file

@ -1,166 +0,0 @@
// SPDX-License-Identifier: LGPL-2.1+
/*
* Copyright (C) 2007 - 2008 Novell, Inc.
* Copyright (C) 2007 - 2014 Red Hat, Inc.
*/
#ifndef __NM_MANAGER_H__
#define __NM_MANAGER_H__
#if !((NETWORKMANAGER_COMPILATION) & NM_NETWORKMANAGER_COMPILATION_WITH_LIBNM_PRIVATE)
#error Cannot use this header.
#endif
#include "nm-object.h"
#include "nm-client.h"
#define NM_TYPE_MANAGER (nm_manager_get_type ())
#define NM_MANAGER(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), NM_TYPE_MANAGER, NMManager))
#define NM_MANAGER_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), NM_TYPE_MANAGER, NMManagerClass))
#define NM_IS_MANAGER(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), NM_TYPE_MANAGER))
#define NM_IS_MANAGER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), NM_TYPE_MANAGER))
#define NM_MANAGER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), NM_TYPE_MANAGER, NMManagerClass))
#define NM_MANAGER_VERSION "version"
#define NM_MANAGER_STATE "state"
#define NM_MANAGER_STARTUP "startup"
#define NM_MANAGER_NETWORKING_ENABLED "networking-enabled"
_NM_DEPRECATED_SYNC_WRITABLE_PROPERTY_INTERNAL
#define NM_MANAGER_WIRELESS_ENABLED "wireless-enabled"
_NM_DEPRECATED_SYNC_WRITABLE_PROPERTY_INTERNAL
#define NM_MANAGER_WWAN_ENABLED "wwan-enabled"
_NM_DEPRECATED_SYNC_WRITABLE_PROPERTY_INTERNAL
#define NM_MANAGER_WIMAX_ENABLED "wimax-enabled"
#define NM_MANAGER_WIRELESS_HARDWARE_ENABLED "wireless-hardware-enabled"
#define NM_MANAGER_WWAN_HARDWARE_ENABLED "wwan-hardware-enabled"
#define NM_MANAGER_WIMAX_HARDWARE_ENABLED "wimax-hardware-enabled"
#define NM_MANAGER_ACTIVE_CONNECTIONS "active-connections"
#define NM_MANAGER_CONNECTIVITY "connectivity"
#define NM_MANAGER_CONNECTIVITY_CHECK_AVAILABLE "connectivity-check-available"
_NM_DEPRECATED_SYNC_WRITABLE_PROPERTY_INTERNAL
#define NM_MANAGER_CONNECTIVITY_CHECK_ENABLED "connectivity-check-enabled"
#define NM_MANAGER_PRIMARY_CONNECTION "primary-connection"
#define NM_MANAGER_ACTIVATING_CONNECTION "activating-connection"
#define NM_MANAGER_DEVICES "devices"
#define NM_MANAGER_CHECKPOINTS "checkpoints"
#define NM_MANAGER_METERED "metered"
#define NM_MANAGER_ALL_DEVICES "all-devices"
/**
* NMManager:
*/
typedef struct {
NMObject parent;
} NMManager;
typedef struct {
NMObjectClass parent;
/* Signals */
void (*device_added) (NMManager *manager, NMDevice *device);
void (*device_removed) (NMManager *manager, NMDevice *device);
void (*active_connection_added) (NMManager *manager, NMActiveConnection *ac);
void (*active_connection_removed) (NMManager *manager, NMActiveConnection *ac);
void (*checkpoint_added) (NMManager *manager, NMCheckpoint *checkpoint);
void (*checkpoint_removed) (NMManager *manager, NMCheckpoint *checkpoint);
void (*permission_changed) (NMManager *manager,
NMClientPermission permission,
NMClientPermissionResult result);
} NMManagerClass;
GType nm_manager_get_type (void);
const char *nm_manager_get_version (NMManager *manager);
NMState nm_manager_get_state (NMManager *manager);
gboolean nm_manager_get_startup (NMManager *manager);
gboolean nm_manager_networking_get_enabled (NMManager *manager);
_NM_DEPRECATED_SYNC_METHOD_INTERNAL
gboolean _nm_manager_networking_set_enabled (GDBusConnection *dbus_connection,
const char *name_owner,
gboolean enable,
GError **error);
gboolean nm_manager_wireless_get_enabled (NMManager *manager);
_NM_DEPRECATED_SYNC_METHOD_INTERNAL
void nm_manager_wireless_set_enabled (NMManager *manager, gboolean enabled);
gboolean nm_manager_wireless_hardware_get_enabled (NMManager *manager);
gboolean nm_manager_wwan_get_enabled (NMManager *manager);
void nm_manager_wwan_set_enabled (NMManager *manager, gboolean enabled);
gboolean nm_manager_wwan_hardware_get_enabled (NMManager *manager);
gboolean nm_manager_wimax_get_enabled (NMManager *manager);
void nm_manager_wimax_set_enabled (NMManager *manager, gboolean enabled);
gboolean nm_manager_wimax_hardware_get_enabled (NMManager *manager);
gboolean nm_manager_connectivity_check_get_available (NMManager *manager);
gboolean nm_manager_connectivity_check_get_enabled (NMManager *manager);
void nm_manager_connectivity_check_set_enabled (NMManager *manager,
gboolean enabled);
const char *nm_manager_connectivity_check_get_uri (NMManager *manager);
NMClientPermissionResult nm_manager_get_permission_result (NMManager *manager,
NMClientPermission permission);
NMConnectivityState nm_manager_get_connectivity (NMManager *manager);
void _nm_manager_set_connectivity_hack (NMManager *manager,
guint32 connectivity);
/* Devices */
const GPtrArray *nm_manager_get_devices (NMManager *manager);
const GPtrArray *nm_manager_get_all_devices(NMManager *manager);
NMDevice *nm_manager_get_device_by_path (NMManager *manager, const char *object_path);
NMDevice *nm_manager_get_device_by_iface (NMManager *manager, const char *iface);
/* Active Connections */
const GPtrArray *nm_manager_get_active_connections (NMManager *manager);
NMActiveConnection *nm_manager_get_primary_connection (NMManager *manager);
NMActiveConnection *nm_manager_get_activating_connection (NMManager *manager);
void nm_manager_wait_for_active_connection (NMManager *self,
const char *active_path,
const char *connection_path,
GVariant *add_and_activate_output_take,
GTask *task_take);
const GPtrArray *nm_manager_get_checkpoints (NMManager *manager);
void nm_manager_wait_for_checkpoint (NMManager *self,
const char *checkpoint_path,
GTask *task_take);
/*****************************************************************************/
typedef struct {
NMActiveConnection *active;
GVariant *add_and_activate_output;
} _NMActivateResult;
_NMActivateResult *_nm_activate_result_new (NMActiveConnection *active,
GVariant *add_and_activate_output);
void _nm_activate_result_free (_NMActivateResult *result);
NM_AUTO_DEFINE_FCN0 (_NMActivateResult *, _nm_auto_free_activate_result, _nm_activate_result_free)
#define nm_auto_free_activate_result nm_auto(_nm_auto_free_activate_result)
/*****************************************************************************/
#endif /* __NM_MANAGER_H__ */

View file

@ -12,86 +12,4 @@
#include "nm-object.h"
typedef gboolean (*PropertyMarshalFunc) (NMObject *, GParamSpec *, GVariant *, gpointer);
typedef GObject * (*NMObjectCreatorFunc) (GDBusConnection *, const char *);
typedef struct {
const char *name;
gpointer field;
PropertyMarshalFunc func;
GType object_type;
const char *signal_prefix;
} NMPropertiesInfo;
void _nm_object_register_properties (NMObject *object,
const char *interface,
const NMPropertiesInfo *info);
void _nm_object_queue_notify (NMObject *object, const char *property);
GDBusObjectManager *_nm_object_get_dbus_object_manager (NMObject *object);
GQuark _nm_object_obj_nm_quark (void);
GDBusConnection *_nm_object_get_dbus_connection (gpointer self);
const char *_nm_object_get_dbus_name_owner (gpointer self);
GDBusConnection *_nm_client_get_dbus_connection (NMClient *client);
const char *_nm_client_get_dbus_name_owner (NMClient *client);
void _nm_object_dbus_call (gpointer self,
gpointer source_tag,
GCancellable *cancellable,
GAsyncReadyCallback user_callback,
gpointer user_callback_data,
const char *object_path,
const char *interface_name,
const char *method_name,
GVariant *parameters,
const GVariantType *reply_type,
GDBusCallFlags flags,
int timeout_msec,
GAsyncReadyCallback internal_callback);
GVariant *_nm_object_dbus_call_sync (gpointer self,
GCancellable *cancellable,
const char *object_path,
const char *interface_name,
const char *method_name,
GVariant *parameters,
const GVariantType *reply_type,
GDBusCallFlags flags,
int timeout_msec,
gboolean strip_dbus_error,
GError **error);
gboolean _nm_object_dbus_call_sync_void (gpointer self,
GCancellable *cancellable,
const char *object_path,
const char *interface_name,
const char *method_name,
GVariant *parameters,
GDBusCallFlags flags,
int timeout_msec,
gboolean strip_dbus_error,
GError **error);
void _nm_object_set_property (NMObject *object,
const char *interface,
const char *prop_name,
const char *format_string,
...);
GDBusProxy *_nm_object_get_proxy (NMObject *object,
const char *interface);
GError *_nm_object_new_error_nm_not_running (void);
void _nm_object_set_error_nm_not_running (GError **error);
struct udev;
void _nm_device_set_udev (NMDevice *device, struct udev *udev);
#endif /* __NM_OBJECT_PRIVATE_H__ */

File diff suppressed because it is too large Load diff

View file

@ -23,9 +23,6 @@ G_BEGIN_DECLS
#define NM_OBJECT_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), NM_TYPE_OBJECT, NMObjectClass))
#define NM_OBJECT_PATH "path"
#define NM_OBJECT_DBUS_CONNECTION "dbus-connection"
#define NM_OBJECT_DBUS_OBJECT "dbus-object"
#define NM_OBJECT_DBUS_OBJECT_MANAGER "dbus-object-manager"
/**
* NMObject:

View file

@ -17,8 +17,6 @@
#include "nm-object-private.h"
#include "nm-dbus-helpers.h"
#include "introspection/org.freedesktop.NetworkManager.Settings.Connection.h"
/**
* SECTION:nm-remote-connection
* @short_description: A connection managed by NetworkManager server
@ -37,13 +35,14 @@ NM_GOBJECT_PROPERTIES_DEFINE (NMRemoteConnection,
);
typedef struct {
NMDBusSettingsConnection *proxy;
GCancellable *get_settings_cancellable;
gboolean unsaved;
guint32 flags;
char *filename;
guint32 flags;
bool unsaved;
gboolean visible;
bool visible:1;
bool is_initialized:1;
} NMRemoteConnectionPrivate;
struct _NMRemoteConnection {
@ -56,23 +55,15 @@ struct _NMRemoteConnectionClass {
};
static void nm_remote_connection_connection_iface_init (NMConnectionInterface *iface);
static void nm_remote_connection_initable_iface_init (GInitableIface *iface);
static void nm_remote_connection_async_initable_iface_init (GAsyncInitableIface *iface);
G_DEFINE_TYPE_WITH_CODE (NMRemoteConnection, nm_remote_connection, NM_TYPE_OBJECT,
G_IMPLEMENT_INTERFACE (NM_TYPE_CONNECTION, nm_remote_connection_connection_iface_init);
G_IMPLEMENT_INTERFACE (G_TYPE_INITABLE, nm_remote_connection_initable_iface_init);
G_IMPLEMENT_INTERFACE (G_TYPE_ASYNC_INITABLE, nm_remote_connection_async_initable_iface_init);
)
#define NM_REMOTE_CONNECTION_GET_PRIVATE(self) _NM_GET_PRIVATE(self, NMRemoteConnection, NM_IS_REMOTE_CONNECTION, NMObject)
/*****************************************************************************/
static GInitableIface *nm_remote_connection_parent_initable_iface;
static GAsyncInitableIface *nm_remote_connection_parent_async_initable_iface;
/*****************************************************************************/
/**
* nm_remote_connection_update2:
* @connection: the #NMRemoteConnection
@ -106,12 +97,13 @@ nm_remote_connection_update2 (NMRemoteConnection *connection,
if (!args)
args = g_variant_new_array (G_VARIANT_TYPE ("{sv}"), NULL, 0);
_nm_object_dbus_call (connection,
_nm_client_dbus_call (_nm_object_get_client (connection),
connection,
nm_remote_connection_update2,
cancellable,
callback,
user_data,
g_dbus_proxy_get_object_path (G_DBUS_PROXY (NM_REMOTE_CONNECTION_GET_PRIVATE (connection)->proxy)),
_nm_object_get_path (connection),
NM_DBUS_INTERFACE_SETTINGS_CONNECTION,
"Update2",
g_variant_new ("(@a{sa{sv}}u@a{sv})",
@ -185,9 +177,9 @@ nm_remote_connection_commit_changes (NMRemoteConnection *connection,
g_return_val_if_fail (NM_IS_REMOTE_CONNECTION (connection), FALSE);
g_return_val_if_fail (!cancellable || G_IS_CANCELLABLE (cancellable), FALSE);
ret = _nm_object_dbus_call_sync (connection,
ret = _nm_client_dbus_call_sync (_nm_object_get_client (connection),
cancellable,
g_dbus_proxy_get_object_path (G_DBUS_PROXY (NM_REMOTE_CONNECTION_GET_PRIVATE (connection)->proxy)),
_nm_object_get_path (connection),
NM_DBUS_INTERFACE_SETTINGS_CONNECTION,
"Update2",
g_variant_new ("(@a{sa{sv}}u@a{sv})",
@ -287,9 +279,9 @@ nm_remote_connection_save (NMRemoteConnection *connection,
g_return_val_if_fail (NM_IS_REMOTE_CONNECTION (connection), FALSE);
g_return_val_if_fail (!cancellable || G_IS_CANCELLABLE (cancellable), FALSE);
return _nm_object_dbus_call_sync_void (connection,
return _nm_client_dbus_call_sync_void (_nm_object_get_client (connection),
cancellable,
g_dbus_proxy_get_object_path (G_DBUS_PROXY (NM_REMOTE_CONNECTION_GET_PRIVATE (connection)->proxy)),
_nm_object_get_path (connection),
NM_DBUS_INTERFACE_SETTINGS_CONNECTION,
"Save",
g_variant_new ("()"),
@ -318,12 +310,13 @@ nm_remote_connection_save_async (NMRemoteConnection *connection,
g_return_if_fail (NM_IS_REMOTE_CONNECTION (connection));
g_return_if_fail (!cancellable || G_IS_CANCELLABLE (cancellable));
_nm_object_dbus_call (connection,
_nm_client_dbus_call (_nm_object_get_client (connection),
connection,
nm_remote_connection_save_async,
cancellable,
callback,
user_data,
g_dbus_proxy_get_object_path (G_DBUS_PROXY (NM_REMOTE_CONNECTION_GET_PRIVATE (connection)->proxy)),
_nm_object_get_path (connection),
NM_DBUS_INTERFACE_SETTINGS_CONNECTION,
"Save",
g_variant_new ("()"),
@ -375,9 +368,9 @@ nm_remote_connection_delete (NMRemoteConnection *connection,
{
g_return_val_if_fail (NM_IS_REMOTE_CONNECTION (connection), FALSE);
return _nm_object_dbus_call_sync_void (connection,
return _nm_client_dbus_call_sync_void (_nm_object_get_client (connection),
cancellable,
g_dbus_proxy_get_object_path (G_DBUS_PROXY (NM_REMOTE_CONNECTION_GET_PRIVATE (connection)->proxy)),
_nm_object_get_path (connection),
NM_DBUS_INTERFACE_SETTINGS_CONNECTION,
"Delete",
g_variant_new ("()"),
@ -405,12 +398,13 @@ nm_remote_connection_delete_async (NMRemoteConnection *connection,
g_return_if_fail (NM_IS_REMOTE_CONNECTION (connection));
g_return_if_fail (!cancellable || G_IS_CANCELLABLE (cancellable));
_nm_object_dbus_call (connection,
_nm_client_dbus_call (_nm_object_get_client (connection),
connection,
nm_remote_connection_delete_async,
cancellable,
callback,
user_data,
g_dbus_proxy_get_object_path (G_DBUS_PROXY (NM_REMOTE_CONNECTION_GET_PRIVATE (connection)->proxy)),
_nm_object_get_path (connection),
NM_DBUS_INTERFACE_SETTINGS_CONNECTION,
"Delete",
g_variant_new ("()"),
@ -469,9 +463,9 @@ nm_remote_connection_get_secrets (NMRemoteConnection *connection,
g_return_val_if_fail (setting_name, NULL);
g_return_val_if_fail (!cancellable || G_IS_CANCELLABLE (cancellable), NULL);
ret = _nm_object_dbus_call_sync (connection,
ret = _nm_client_dbus_call_sync (_nm_object_get_client (connection),
cancellable,
g_dbus_proxy_get_object_path (G_DBUS_PROXY (NM_REMOTE_CONNECTION_GET_PRIVATE (connection)->proxy)),
_nm_object_get_path (connection),
NM_DBUS_INTERFACE_SETTINGS_CONNECTION,
"GetSecrets",
g_variant_new ("(s)", setting_name),
@ -511,12 +505,13 @@ nm_remote_connection_get_secrets_async (NMRemoteConnection *connection,
g_return_if_fail (setting_name);
g_return_if_fail (!cancellable || G_IS_CANCELLABLE (cancellable));
_nm_object_dbus_call (connection,
_nm_client_dbus_call (_nm_object_get_client (connection),
connection,
nm_remote_connection_get_secrets_async,
cancellable,
callback,
user_data,
g_dbus_proxy_get_object_path (G_DBUS_PROXY (NM_REMOTE_CONNECTION_GET_PRIVATE (connection)->proxy)),
_nm_object_get_path (connection),
NM_DBUS_INTERFACE_SETTINGS_CONNECTION,
"GetSecrets",
g_variant_new ("(s)", setting_name),
@ -633,195 +628,94 @@ nm_remote_connection_get_visible (NMRemoteConnection *connection)
/*****************************************************************************/
static void
replace_settings (NMRemoteConnection *self, GVariant *new_settings)
GCancellable *
_nm_remote_settings_get_settings_prepare (NMRemoteConnection *self)
{
GError *error = NULL;
NMRemoteConnectionPrivate *priv = NM_REMOTE_CONNECTION_GET_PRIVATE (self);
if (!_nm_connection_replace_settings ((NMConnection *) self,
new_settings,
NM_SETTING_PARSE_FLAGS_BEST_EFFORT,
&error))
g_clear_error (&error);
nm_clear_g_cancellable (&priv->get_settings_cancellable);
priv->get_settings_cancellable = g_cancellable_new ();
return priv->get_settings_cancellable;
}
static void
updated_get_settings_cb (GObject *proxy,
GAsyncResult *result,
gpointer user_data)
void
_nm_remote_settings_get_settings_commit (NMRemoteConnection *self,
GVariant *settings)
{
NMRemoteConnection *self = user_data;
NMRemoteConnectionPrivate *priv = NM_REMOTE_CONNECTION_GET_PRIVATE (self);
GVariant *new_settings;
gboolean visible;
GError *error = NULL;
gboolean visible = FALSE;
gboolean changed = FALSE;
if (!nmdbus_settings_connection_call_get_settings_finish (priv->proxy, &new_settings,
result, NULL)) {
/* Connection is no longer visible to this user. */
g_clear_object (&priv->get_settings_cancellable);
if (!priv->is_initialized) {
changed = TRUE;
priv->is_initialized = TRUE;
}
if (settings) {
if (!_nm_connection_replace_settings ((NMConnection *) self,
settings,
NM_SETTING_PARSE_FLAGS_BEST_EFFORT,
&error)) {
NML_NMCLIENT_LOG_E (_nm_object_get_client (self), "[%s] failure to update settings: %s",
_nm_object_get_path (self),
error->message);
g_clear_error (&error);
} else
visible = TRUE;
} else
nm_connection_clear_settings (NM_CONNECTION (self));
visible = FALSE;
} else {
replace_settings (self, new_settings);
g_variant_unref (new_settings);
visible = TRUE;
}
if (visible != priv->visible) {
if (priv->visible != visible) {
priv->visible = visible;
_notify (self, PROP_VISIBLE);
_nm_client_queue_notify_object (_nm_object_get_client (self),
self,
obj_properties[PROP_VISIBLE]);
changed = TRUE;
}
g_object_unref (self);
if (changed)
_nm_client_notify_object_changed (_nm_object_get_client (self), _nm_object_get_dbobj (self));
}
static void
updated_cb (NMDBusSettingsConnection *proxy, gpointer user_data)
{
NMRemoteConnection *self = NM_REMOTE_CONNECTION (user_data);
NMRemoteConnectionPrivate *priv = NM_REMOTE_CONNECTION_GET_PRIVATE (self);
/*****************************************************************************/
/* The connection got updated; request the replacement settings */
nmdbus_settings_connection_call_get_settings (priv->proxy,
NULL,
updated_get_settings_cb,
g_object_ref (self));
static gboolean
is_ready (NMObject *nmobj)
{
NMRemoteConnectionPrivate *priv = NM_REMOTE_CONNECTION_GET_PRIVATE (nmobj);
if (!priv->is_initialized)
return FALSE;;
return NM_OBJECT_CLASS (nm_remote_connection_parent_class)->is_ready (nmobj);
}
/*****************************************************************************/
static void
init_dbus (NMObject *object)
register_client (NMObject *nmobj,
NMClient *client,
NMLDBusObject *dbobj)
{
NMRemoteConnectionPrivate *priv = NM_REMOTE_CONNECTION_GET_PRIVATE (object);
const NMPropertiesInfo property_info[] = {
{ NM_REMOTE_CONNECTION_UNSAVED, &priv->unsaved },
{ NM_REMOTE_CONNECTION_FLAGS, &priv->flags },
{ NM_REMOTE_CONNECTION_FILENAME, &priv->filename },
{ NULL },
};
NM_OBJECT_CLASS (nm_remote_connection_parent_class)->init_dbus (object);
_nm_object_register_properties (object,
NM_DBUS_INTERFACE_SETTINGS_CONNECTION,
property_info);
}
static gboolean
init_sync (GInitable *initable, GCancellable *cancellable, GError **error)
{
NMRemoteConnection *self = NM_REMOTE_CONNECTION (initable);
NMRemoteConnectionPrivate *priv = NM_REMOTE_CONNECTION_GET_PRIVATE (self);
GVariant *settings;
priv->proxy = NMDBUS_SETTINGS_CONNECTION (_nm_object_get_proxy (NM_OBJECT (initable), NM_DBUS_INTERFACE_SETTINGS_CONNECTION));
g_signal_connect_object (priv->proxy, "updated", G_CALLBACK (updated_cb), initable, 0);
if (nmdbus_settings_connection_call_get_settings_sync (priv->proxy,
&settings,
cancellable,
NULL)) {
priv->visible = TRUE;
replace_settings (self, settings);
g_variant_unref (settings);
}
if (!nm_remote_connection_parent_initable_iface->init (initable, cancellable, error))
return FALSE;
return TRUE;
}
typedef struct {
NMRemoteConnection *connection;
GCancellable *cancellable;
GSimpleAsyncResult *result;
GAsyncInitable *initable;
int io_priority;
} NMRemoteConnectionInitData;
static void
init_async_complete (NMRemoteConnectionInitData *init_data, GError *error)
{
if (error)
g_simple_async_result_take_error (init_data->result, error);
else
g_simple_async_result_set_op_res_gboolean (init_data->result, TRUE);
g_simple_async_result_complete (init_data->result);
g_object_unref (init_data->result);
g_clear_object (&init_data->cancellable);
g_slice_free (NMRemoteConnectionInitData, init_data);
NM_OBJECT_CLASS (nm_remote_connection_parent_class)->register_client (nmobj, client, dbobj);
nm_connection_set_path (NM_CONNECTION (nmobj),
dbobj->dbus_path->str);
_nm_client_get_settings_call (client, dbobj);
}
static void
init_async_parent_inited (GObject *source, GAsyncResult *result, gpointer user_data)
unregister_client (NMObject *nmobj,
NMClient *client,
NMLDBusObject *dbobj)
{
NMRemoteConnectionInitData *init_data = user_data;
GError *error = NULL;
init_async_complete (init_data, error);
nm_clear_g_cancellable (&NM_REMOTE_CONNECTION_GET_PRIVATE (nmobj)->get_settings_cancellable);
NM_OBJECT_CLASS (nm_remote_connection_parent_class)->unregister_client (nmobj, client, dbobj);
}
static void
init_get_settings_cb (GObject *proxy,
GAsyncResult *result,
gpointer user_data)
{
NMRemoteConnectionInitData *init_data = user_data;
NMRemoteConnection *self = NM_REMOTE_CONNECTION (init_data->initable);
NMRemoteConnectionPrivate *priv = NM_REMOTE_CONNECTION_GET_PRIVATE (self);
GVariant *settings;
GError *error = NULL;
if (!nmdbus_settings_connection_call_get_settings_finish (priv->proxy, &settings,
result, &error)) {
g_error_free (error);
} else {
priv->visible = TRUE;
replace_settings (NM_REMOTE_CONNECTION (init_data->initable), settings);
g_variant_unref (settings);
}
nm_remote_connection_parent_async_initable_iface->
init_async (init_data->initable, init_data->io_priority, init_data->cancellable, init_async_parent_inited, init_data);
}
static void
init_async (GAsyncInitable *initable, int io_priority,
GCancellable *cancellable, GAsyncReadyCallback callback,
gpointer user_data)
{
NMRemoteConnectionInitData *init_data;
NMRemoteConnection *self = NM_REMOTE_CONNECTION (initable);
NMRemoteConnectionPrivate *priv = NM_REMOTE_CONNECTION_GET_PRIVATE (self);
init_data = g_slice_new0 (NMRemoteConnectionInitData);
init_data->cancellable = cancellable ? g_object_ref (cancellable) : NULL;
init_data->result = g_simple_async_result_new (G_OBJECT (initable), callback,
user_data, init_async);
if (cancellable)
g_simple_async_result_set_check_cancellable (init_data->result, cancellable);
init_data->initable = initable;
init_data->io_priority = io_priority;
priv->proxy = NMDBUS_SETTINGS_CONNECTION (_nm_object_get_proxy (NM_OBJECT (initable),
NM_DBUS_INTERFACE_SETTINGS_CONNECTION));
g_signal_connect_object (priv->proxy, "updated",
G_CALLBACK (updated_cb), initable, 0);
nmdbus_settings_connection_call_get_settings (NM_REMOTE_CONNECTION_GET_PRIVATE (NM_REMOTE_CONNECTION (init_data->initable))->proxy,
init_data->cancellable,
init_get_settings_cb, init_data);
}
static void
nm_remote_connection_init (NMRemoteConnection *self)
{
}
/*****************************************************************************/
static void
get_property (GObject *object, guint prop_id,
@ -846,13 +740,11 @@ get_property (GObject *object, guint prop_id,
}
}
static void
constructed (GObject *object)
{
G_OBJECT_CLASS (nm_remote_connection_parent_class)->constructed (object);
/*****************************************************************************/
nm_connection_set_path (NM_CONNECTION (object),
nm_object_get_path (NM_OBJECT (object)));
static void
nm_remote_connection_init (NMRemoteConnection *self)
{
}
static void
@ -860,23 +752,34 @@ dispose (GObject *object)
{
NMRemoteConnectionPrivate *priv = NM_REMOTE_CONNECTION_GET_PRIVATE (object);
g_clear_object (&priv->proxy);
nm_clear_g_free (&priv->filename);
G_OBJECT_CLASS (nm_remote_connection_parent_class)->dispose (object);
}
const NMLDBusMetaIface _nml_dbus_meta_iface_nm_settings_connection = NML_DBUS_META_IFACE_INIT_PROP (
NM_DBUS_INTERFACE_SETTINGS_CONNECTION,
nm_remote_connection_get_type,
NML_DBUS_META_INTERFACE_PRIO_INSTANTIATE_HIGH,
NML_DBUS_META_IFACE_DBUS_PROPERTIES (
NML_DBUS_META_PROPERTY_INIT_S ("Filename", PROP_FILENAME, NMRemoteConnection, _priv.filename ),
NML_DBUS_META_PROPERTY_INIT_U ("Flags", PROP_FLAGS, NMRemoteConnection, _priv.flags ),
NML_DBUS_META_PROPERTY_INIT_B ("Unsaved", PROP_UNSAVED, NMRemoteConnection, _priv.unsaved ),
),
);
static void
nm_remote_connection_class_init (NMRemoteConnectionClass *remote_class)
nm_remote_connection_class_init (NMRemoteConnectionClass *klass)
{
GObjectClass *object_class = G_OBJECT_CLASS (remote_class);
NMObjectClass *nm_object_class = NM_OBJECT_CLASS (remote_class);
GObjectClass *object_class = G_OBJECT_CLASS (klass);
NMObjectClass *nm_object_class = NM_OBJECT_CLASS (klass);
object_class->get_property = get_property;
object_class->constructed = constructed;
object_class->dispose = dispose;
nm_object_class->init_dbus = init_dbus;
nm_object_class->is_ready = is_ready;
nm_object_class->register_client = register_client;
nm_object_class->unregister_client = unregister_client;
/**
* NMRemoteConnection:unsaved:
@ -935,26 +838,10 @@ nm_remote_connection_class_init (NMRemoteConnectionClass *remote_class)
G_PARAM_READABLE |
G_PARAM_STATIC_STRINGS);
g_object_class_install_properties (object_class, _PROPERTY_ENUMS_LAST, obj_properties);
_nml_dbus_meta_class_init_with_properties (object_class, &_nml_dbus_meta_iface_nm_settings_connection);
}
static void
nm_remote_connection_connection_iface_init (NMConnectionInterface *iface)
{
}
static void
nm_remote_connection_initable_iface_init (GInitableIface *iface)
{
nm_remote_connection_parent_initable_iface = g_type_interface_peek_parent (iface);
iface->init = init_sync;
}
static void
nm_remote_connection_async_initable_iface_init (GAsyncInitableIface *iface)
{
nm_remote_connection_parent_async_initable_iface = g_type_interface_peek_parent (iface);
iface->init_async = init_async;
}

View file

@ -1,479 +0,0 @@
// SPDX-License-Identifier: LGPL-2.1+
/*
* Copyright (C) 2008 Novell, Inc.
* Copyright (C) 2009 - 2012 Red Hat, Inc.
*/
#include "nm-default.h"
#include "nm-remote-settings.h"
#include "c-list/src/c-list.h"
#include "nm-dbus-interface.h"
#include "nm-connection.h"
#include "nm-client.h"
#include "nm-remote-connection.h"
#include "nm-remote-connection-private.h"
#include "nm-object-private.h"
#include "nm-dbus-helpers.h"
#include "nm-core-internal.h"
#include "introspection/org.freedesktop.NetworkManager.Settings.h"
G_DEFINE_TYPE (NMRemoteSettings, nm_remote_settings, NM_TYPE_OBJECT)
#define NM_REMOTE_SETTINGS_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), NM_TYPE_REMOTE_SETTINGS, NMRemoteSettingsPrivate))
typedef struct {
NMDBusSettings *proxy;
GPtrArray *all_connections;
GPtrArray *visible_connections;
/* AddConnectionInfo objects that are waiting for the connection to become initialized */
CList add_lst_head;
char *hostname;
gboolean can_modify;
} NMRemoteSettingsPrivate;
NM_GOBJECT_PROPERTIES_DEFINE_BASE (
PROP_CONNECTIONS,
PROP_HOSTNAME,
PROP_CAN_MODIFY,
);
/* Signals */
enum {
CONNECTION_ADDED,
CONNECTION_REMOVED,
LAST_SIGNAL
};
static guint signals[LAST_SIGNAL] = { 0 };
/*****************************************************************************/
typedef struct {
CList add_lst;
NMRemoteSettings *self;
GTask *task;
char *connection_path;
GVariant *extra_results;
gulong cancellable_id;
} AddConnectionInfo;
static AddConnectionInfo *
_add_connection_info_find (NMRemoteSettings *self, const char *connection_path)
{
NMRemoteSettingsPrivate *priv = NM_REMOTE_SETTINGS_GET_PRIVATE (self);
AddConnectionInfo *info;
c_list_for_each_entry (info, &priv->add_lst_head, add_lst) {
if (nm_streq (info->connection_path, connection_path))
return info;
}
return NULL;
}
static void
_add_connection_info_complete (AddConnectionInfo *info,
NMRemoteConnection *connection,
GError *error_take)
{
nm_assert (info);
c_list_unlink_stale (&info->add_lst);
nm_clear_g_signal_handler (g_task_get_cancellable (info->task), &info->cancellable_id);
if (error_take)
g_task_return_error (info->task, error_take);
else {
NMAddConnectionResultData *result_info;
result_info = g_slice_new (NMAddConnectionResultData);
*result_info = (NMAddConnectionResultData) {
.connection = g_object_ref (connection),
.extra_results = g_steal_pointer (&info->extra_results),
};
g_task_return_pointer (info->task, result_info, (GDestroyNotify) nm_add_connection_result_data_free);
}
g_object_unref (info->task);
g_object_unref (info->self);
g_free (info->connection_path);
nm_g_variant_unref (info->extra_results);
nm_g_slice_free (info);
}
static void
_wait_for_connection_cancelled_cb (GCancellable *cancellable,
AddConnectionInfo *info)
{
_add_connection_info_complete (info,
NULL,
g_error_new_literal (G_IO_ERROR,
G_IO_ERROR_CANCELLED,
"Operation was cancelled"));
}
typedef const char * (*ConnectionStringGetter) (NMConnection *);
static NMRemoteConnection *
get_connection_by_string (NMRemoteSettings *settings,
const char *string,
ConnectionStringGetter get_comparison_string)
{
NMRemoteSettingsPrivate *priv;
NMConnection *candidate;
int i;
priv = NM_REMOTE_SETTINGS_GET_PRIVATE (settings);
for (i = 0; i < priv->visible_connections->len; i++) {
candidate = priv->visible_connections->pdata[i];
if (!g_strcmp0 (string, get_comparison_string (candidate)))
return NM_REMOTE_CONNECTION (candidate);
}
return NULL;
}
NMRemoteConnection *
nm_remote_settings_get_connection_by_id (NMRemoteSettings *settings, const char *id)
{
g_return_val_if_fail (NM_IS_REMOTE_SETTINGS (settings), NULL);
g_return_val_if_fail (id != NULL, NULL);
return get_connection_by_string (settings, id, nm_connection_get_id);
}
NMRemoteConnection *
nm_remote_settings_get_connection_by_path (NMRemoteSettings *settings, const char *path)
{
g_return_val_if_fail (NM_IS_REMOTE_SETTINGS (settings), NULL);
g_return_val_if_fail (path != NULL, NULL);
return get_connection_by_string (settings, path, nm_connection_get_path);
}
NMRemoteConnection *
nm_remote_settings_get_connection_by_uuid (NMRemoteSettings *settings, const char *uuid)
{
g_return_val_if_fail (NM_IS_REMOTE_SETTINGS (settings), NULL);
g_return_val_if_fail (uuid != NULL, NULL);
return get_connection_by_string (settings, uuid, nm_connection_get_uuid);
}
static void
connection_visible_changed (GObject *object,
GParamSpec *pspec,
gpointer user_data)
{
NMRemoteConnection *connection = NM_REMOTE_CONNECTION (object);
NMRemoteSettings *self = NM_REMOTE_SETTINGS (user_data);
if (nm_remote_connection_get_visible (connection))
g_signal_emit (self, signals[CONNECTION_ADDED], 0, connection);
else
g_signal_emit (self, signals[CONNECTION_REMOVED], 0, connection);
}
static void
cleanup_connection (NMRemoteSettings *self,
NMRemoteConnection *remote)
{
g_signal_handlers_disconnect_by_func (remote, G_CALLBACK (connection_visible_changed), self);
}
static void
connection_removed (NMRemoteSettings *self,
NMRemoteConnection *remote)
{
NMRemoteSettingsPrivate *priv = NM_REMOTE_SETTINGS_GET_PRIVATE (self);
gboolean still_exists = FALSE;
int i;
/* Check if the connection was actually removed or if it just turned invisible. */
for (i = 0; i < priv->all_connections->len; i++) {
if (remote == priv->all_connections->pdata[i]) {
still_exists = TRUE;
break;
}
}
if (!still_exists)
cleanup_connection (self, remote);
/* Allow the signal to propagate if and only if @remote was in visible_connections */
if (!g_ptr_array_remove (priv->visible_connections, remote))
g_signal_stop_emission (self, signals[CONNECTION_REMOVED], 0);
}
static void
connection_added (NMRemoteSettings *self,
NMRemoteConnection *remote)
{
NMRemoteSettingsPrivate *priv = NM_REMOTE_SETTINGS_GET_PRIVATE (self);
AddConnectionInfo *info;
const char *path;
if (!g_signal_handler_find (remote, G_SIGNAL_MATCH_FUNC | G_SIGNAL_MATCH_DATA, 0, 0, NULL,
G_CALLBACK (connection_visible_changed), self)) {
g_signal_connect (remote,
"notify::" NM_REMOTE_CONNECTION_VISIBLE,
G_CALLBACK (connection_visible_changed),
self);
}
if (nm_remote_connection_get_visible (remote))
g_ptr_array_add (priv->visible_connections, remote);
else
g_signal_stop_emission (self, signals[CONNECTION_ADDED], 0);
/* FIXME: this doesn't look right. Why does it not care about whether the
* connection is visible? Anyway, this will be reworked. */
path = nm_connection_get_path (NM_CONNECTION (remote));
info = path
? _add_connection_info_find (self, path)
: NULL;
if (info)
_add_connection_info_complete (info, remote, NULL);
}
static void
object_creation_failed (NMObject *object,
const char *failed_path)
{
NMRemoteSettings *self = NM_REMOTE_SETTINGS (object);
AddConnectionInfo *info;
info = _add_connection_info_find (self, failed_path);
if (!info)
return;
_add_connection_info_complete (info,
NULL,
g_error_new_literal (NM_CLIENT_ERROR,
NM_CLIENT_ERROR_OBJECT_CREATION_FAILED,
_("Connection removed before it was initialized")));
}
const GPtrArray *
nm_remote_settings_get_connections (NMRemoteSettings *settings)
{
g_return_val_if_fail (NM_IS_REMOTE_SETTINGS (settings), NULL);
return NM_REMOTE_SETTINGS_GET_PRIVATE (settings)->visible_connections;
}
void
nm_remote_settings_wait_for_connection (NMRemoteSettings *self,
const char *connection_path,
GVariant *extra_results_take,
GTask *task_take)
{
NMRemoteSettingsPrivate *priv;
gs_unref_object GTask *task = task_take;
gs_unref_variant GVariant *extra_results = extra_results_take;
GCancellable *cancellable;
AddConnectionInfo *info;
priv = NM_REMOTE_SETTINGS_GET_PRIVATE (self);
/* FIXME: there is no timeout for how long we wait. But this entire
* code will be reworked, also that we have a suitable GMainContext
* where we can schedule the timeout (we shouldn't use g_main_context_default()). */
info = g_slice_new (AddConnectionInfo);
*info = (AddConnectionInfo) {
.self = g_object_ref (self),
.connection_path = g_strdup (connection_path),
.task = g_steal_pointer (&task),
.extra_results = g_steal_pointer (&extra_results),
};
c_list_link_tail (&priv->add_lst_head, &info->add_lst);
cancellable = g_task_get_cancellable (info->task);
/* On success, we still have to wait until the connection is fully
* initialized before calling the callback.
*/
if (cancellable) {
gulong id;
id = g_cancellable_connect (cancellable,
G_CALLBACK (_wait_for_connection_cancelled_cb),
info,
NULL);
if (id == 0) {
/* the callback was invoked synchronously, which destroyed @info.
* We must not touch @info anymore. */
} else
info->cancellable_id = id;
}
/* FIXME: OK, we just assume the the connection is here, and that we are bound
* to get the suitable signal when the connection is fully initalized (or failed).
* Obviously, that needs reworking. */
}
/*****************************************************************************/
static void
nm_remote_settings_init (NMRemoteSettings *self)
{
NMRemoteSettingsPrivate *priv = NM_REMOTE_SETTINGS_GET_PRIVATE (self);
c_list_init (&priv->add_lst_head);
priv->all_connections = g_ptr_array_new ();
priv->visible_connections = g_ptr_array_new ();
}
static void
init_dbus (NMObject *object)
{
NMRemoteSettingsPrivate *priv = NM_REMOTE_SETTINGS_GET_PRIVATE (object);
const NMPropertiesInfo property_info[] = {
{ NM_REMOTE_SETTINGS_CONNECTIONS, &priv->all_connections, NULL, NM_TYPE_REMOTE_CONNECTION, "connection" },
{ NM_REMOTE_SETTINGS_HOSTNAME, &priv->hostname },
{ NM_REMOTE_SETTINGS_CAN_MODIFY, &priv->can_modify },
{ NULL },
};
NM_OBJECT_CLASS (nm_remote_settings_parent_class)->init_dbus (object);
priv->proxy = NMDBUS_SETTINGS (_nm_object_get_proxy (object, NM_DBUS_INTERFACE_SETTINGS));
_nm_object_register_properties (object,
NM_DBUS_INTERFACE_SETTINGS,
property_info);
}
static GObject *
constructor (GType type,
guint n_construct_params,
GObjectConstructParam *construct_params)
{
guint i;
const char *dbus_path;
/* Fill in the right D-Bus path if none was specified */
for (i = 0; i < n_construct_params; i++) {
if (strcmp (construct_params[i].pspec->name, NM_OBJECT_PATH) == 0) {
dbus_path = g_value_get_string (construct_params[i].value);
if (dbus_path == NULL) {
g_value_set_static_string (construct_params[i].value, NM_DBUS_PATH_SETTINGS);
} else {
if (!g_variant_is_object_path (dbus_path)) {
g_warning ("Passed D-Bus object path '%s' is invalid; using default '%s' instead",
dbus_path, NM_DBUS_PATH);
g_value_set_static_string (construct_params[i].value, NM_DBUS_PATH_SETTINGS);
}
}
break;
}
}
return G_OBJECT_CLASS (nm_remote_settings_parent_class)->constructor (type,
n_construct_params,
construct_params);
}
static void
dispose (GObject *object)
{
NMRemoteSettings *self = NM_REMOTE_SETTINGS (object);
NMRemoteSettingsPrivate *priv = NM_REMOTE_SETTINGS_GET_PRIVATE (self);
guint i;
if (priv->all_connections) {
for (i = 0; i < priv->all_connections->len; i++)
cleanup_connection (self, priv->all_connections->pdata[i]);
g_clear_pointer (&priv->all_connections, g_ptr_array_unref);
}
g_clear_pointer (&priv->visible_connections, g_ptr_array_unref);
g_clear_pointer (&priv->hostname, g_free);
g_clear_object (&priv->proxy);
G_OBJECT_CLASS (nm_remote_settings_parent_class)->dispose (object);
}
static void
get_property (GObject *object, guint prop_id,
GValue *value, GParamSpec *pspec)
{
NMRemoteSettingsPrivate *priv = NM_REMOTE_SETTINGS_GET_PRIVATE (object);
switch (prop_id) {
case PROP_CONNECTIONS:
g_value_take_boxed (value, _nm_utils_copy_object_array (priv->visible_connections));
break;
case PROP_HOSTNAME:
g_value_set_string (value, priv->hostname);
break;
case PROP_CAN_MODIFY:
g_value_set_boolean (value, priv->can_modify);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
}
}
static void
nm_remote_settings_class_init (NMRemoteSettingsClass *class)
{
GObjectClass *object_class = G_OBJECT_CLASS (class);
NMObjectClass *nm_object_class = NM_OBJECT_CLASS (class);
g_type_class_add_private (class, sizeof (NMRemoteSettingsPrivate));
object_class->get_property = get_property;
object_class->constructor = constructor;
object_class->dispose = dispose;
nm_object_class->init_dbus = init_dbus;
nm_object_class->object_creation_failed = object_creation_failed;
class->connection_added = connection_added;
class->connection_removed = connection_removed;
obj_properties[PROP_CONNECTIONS] =
g_param_spec_boxed (NM_REMOTE_SETTINGS_CONNECTIONS, "", "",
G_TYPE_PTR_ARRAY,
G_PARAM_READABLE |
G_PARAM_STATIC_STRINGS);
obj_properties[PROP_HOSTNAME] =
g_param_spec_string (NM_REMOTE_SETTINGS_HOSTNAME, "", "",
NULL,
G_PARAM_READABLE |
G_PARAM_STATIC_STRINGS);
obj_properties[PROP_CAN_MODIFY] =
g_param_spec_boolean (NM_REMOTE_SETTINGS_CAN_MODIFY, "", "",
FALSE,
G_PARAM_READABLE |
G_PARAM_STATIC_STRINGS);
g_object_class_install_properties (object_class, _PROPERTY_ENUMS_LAST, obj_properties);
signals[CONNECTION_ADDED] =
g_signal_new (NM_REMOTE_SETTINGS_CONNECTION_ADDED,
G_OBJECT_CLASS_TYPE (object_class),
G_SIGNAL_RUN_FIRST,
G_STRUCT_OFFSET (NMRemoteSettingsClass, connection_added),
NULL, NULL, NULL,
G_TYPE_NONE, 1,
NM_TYPE_REMOTE_CONNECTION);
signals[CONNECTION_REMOVED] =
g_signal_new (NM_REMOTE_SETTINGS_CONNECTION_REMOVED,
G_OBJECT_CLASS_TYPE (object_class),
G_SIGNAL_RUN_FIRST,
G_STRUCT_OFFSET (NMRemoteSettingsClass, connection_removed),
NULL, NULL, NULL,
G_TYPE_NONE, 1,
NM_TYPE_REMOTE_CONNECTION);
}

View file

@ -1,77 +0,0 @@
// SPDX-License-Identifier: LGPL-2.1+
/*
* Copyright (C) 2008 Novell, Inc.
* Copyright (C) 2009 - 2011 Red Hat, Inc.
*/
#ifndef __NM_REMOTE_SETTINGS_H__
#define __NM_REMOTE_SETTINGS_H__
#if !((NETWORKMANAGER_COMPILATION) & NM_NETWORKMANAGER_COMPILATION_WITH_LIBNM_PRIVATE)
#error Cannot use this header.
#endif
#include "nm-object.h"
#define NM_TYPE_REMOTE_SETTINGS (nm_remote_settings_get_type ())
#define NM_REMOTE_SETTINGS(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), NM_TYPE_REMOTE_SETTINGS, NMRemoteSettings))
#define NM_REMOTE_SETTINGS_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), NM_TYPE_REMOTE_SETTINGS, NMRemoteSettingsClass))
#define NM_IS_REMOTE_SETTINGS(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), NM_TYPE_REMOTE_SETTINGS))
#define NM_IS_REMOTE_SETTINGS_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), NM_TYPE_REMOTE_SETTINGS))
#define NM_REMOTE_SETTINGS_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), NM_TYPE_REMOTE_SETTINGS, NMRemoteSettingsClass))
#define NM_REMOTE_SETTINGS_CONNECTIONS "connections"
#define NM_REMOTE_SETTINGS_HOSTNAME "hostname"
#define NM_REMOTE_SETTINGS_CAN_MODIFY "can-modify"
#define NM_REMOTE_SETTINGS_CONNECTION_ADDED "connection-added"
#define NM_REMOTE_SETTINGS_CONNECTION_REMOVED "connection-removed"
typedef struct _NMRemoteSettings NMRemoteSettings;
typedef struct _NMRemoteSettingsClass NMRemoteSettingsClass;
/**
* NMRemoteSettings:
*/
struct _NMRemoteSettings {
NMObject parent;
};
struct _NMRemoteSettingsClass {
NMObjectClass parent;
void (*connection_added) (NMRemoteSettings *settings,
NMRemoteConnection *connection);
void (*connection_removed) (NMRemoteSettings *settings,
NMRemoteConnection *connection);
};
GType nm_remote_settings_get_type (void);
const GPtrArray *nm_remote_settings_get_connections (NMRemoteSettings *settings);
NMRemoteConnection *nm_remote_settings_get_connection_by_id (NMRemoteSettings *settings,
const char *id);
NMRemoteConnection *nm_remote_settings_get_connection_by_path (NMRemoteSettings *settings,
const char *path);
NMRemoteConnection *nm_remote_settings_get_connection_by_uuid (NMRemoteSettings *settings,
const char *uuid);
typedef struct {
NMRemoteConnection *connection;
GVariant *extra_results;
} NMAddConnectionResultData;
void nm_add_connection_result_data_free (NMAddConnectionResultData *result_data);
NM_AUTO_DEFINE_FCN0 (NMAddConnectionResultData *, _nm_auto_free_add_connection_result_data, nm_add_connection_result_data_free)
#define nm_auto_free_add_connection_result_data nm_auto (_nm_auto_free_add_connection_result_data)
void nm_remote_settings_wait_for_connection (NMRemoteSettings *settings,
const char *connection_path,
GVariant *extra_results_take,
GTask *task_take);
#endif /* __NM_REMOTE_SETTINGS_H__ */

View file

@ -14,8 +14,6 @@
#include "nm-active-connection.h"
#include "nm-dbus-helpers.h"
#include "introspection/org.freedesktop.NetworkManager.VPN.Connection.h"
/*****************************************************************************/
NM_GOBJECT_PROPERTIES_DEFINE (NMVpnConnection,
@ -33,7 +31,8 @@ static guint signals[LAST_SIGNAL] = { 0 };
typedef struct {
char *banner;
NMVpnConnectionState vpn_state;
guint32 vpn_state;
guint32 reason;
} NMVpnConnectionPrivate;
struct _NMVpnConnection {
@ -86,20 +85,48 @@ nm_vpn_connection_get_vpn_state (NMVpnConnection *vpn)
return NM_VPN_CONNECTION_GET_PRIVATE (vpn)->vpn_state;
}
static void
vpn_state_changed_proxy (NMDBusVpnConnection *proxy,
guint vpn_state,
guint reason,
gpointer user_data)
{
NMVpnConnection *connection = NM_VPN_CONNECTION (user_data);
NMVpnConnectionPrivate *priv = NM_VPN_CONNECTION_GET_PRIVATE (connection);
/*****************************************************************************/
if (priv->vpn_state != vpn_state) {
priv->vpn_state = vpn_state;
g_signal_emit (connection, signals[VPN_STATE_CHANGED], 0, vpn_state, reason);
_notify (connection, PROP_VPN_STATE);
static void
_notify_event_state_changed (NMClient *client,
NMClientNotifyEventWithPtr *notify_event)
{
gs_unref_object NMVpnConnection *self = notify_event->user_data;
NMVpnConnectionPrivate *priv = NM_VPN_CONNECTION_GET_PRIVATE (self);
/* we expose here the value cache in @priv. In practice, this is the same
* value as we received from the signal. In the unexpected case where they
* differ, the cached value of the current instance would still be more correct. */
g_signal_emit (self,
signals[VPN_STATE_CHANGED],
0,
(guint) priv->vpn_state,
(guint) priv->reason);
}
void
_nm_vpn_connection_state_changed_commit (NMVpnConnection *self,
guint32 state,
guint32 reason)
{
NMClient *client;
NMVpnConnectionPrivate *priv = NM_VPN_CONNECTION_GET_PRIVATE (self);
client = _nm_object_get_client (self);
if (priv->vpn_state != state) {
priv->vpn_state = state;
_nm_client_queue_notify_object (client,
self,
obj_properties[PROP_VPN_STATE]);
}
priv->reason = reason;
_nm_client_notify_event_queue_with_ptr (client,
NM_CLIENT_NOTIFY_EVENT_PRIO_GPROP + 1,
_notify_event_state_changed,
g_object_ref (self));
}
/*****************************************************************************/
@ -107,32 +134,6 @@ vpn_state_changed_proxy (NMDBusVpnConnection *proxy,
static void
nm_vpn_connection_init (NMVpnConnection *connection)
{
NMVpnConnectionPrivate *priv = NM_VPN_CONNECTION_GET_PRIVATE (connection);
priv->vpn_state = NM_VPN_CONNECTION_STATE_UNKNOWN;
}
static void
init_dbus (NMObject *object)
{
NMVpnConnectionPrivate *priv = NM_VPN_CONNECTION_GET_PRIVATE (object);
const NMPropertiesInfo property_info[] = {
{ NM_VPN_CONNECTION_BANNER, &priv->banner },
{ NM_VPN_CONNECTION_VPN_STATE, &priv->vpn_state },
{ NULL },
};
GDBusProxy *proxy;
NM_OBJECT_CLASS (nm_vpn_connection_parent_class)->init_dbus (object);
_nm_object_register_properties (object,
NM_DBUS_INTERFACE_VPN_CONNECTION,
property_info);
proxy = _nm_object_get_proxy (object, NM_DBUS_INTERFACE_VPN_CONNECTION);
g_signal_connect_object (proxy, "vpn-state-changed",
G_CALLBACK (vpn_state_changed_proxy), object, 0);
g_object_unref (proxy);
}
static void
@ -166,17 +167,24 @@ get_property (GObject *object,
}
}
const NMLDBusMetaIface _nml_dbus_meta_iface_nm_vpn_connection = NML_DBUS_META_IFACE_INIT_PROP (
NM_DBUS_INTERFACE_VPN_CONNECTION,
nm_vpn_connection_get_type,
NML_DBUS_META_INTERFACE_PRIO_INSTANTIATE_HIGH,
NML_DBUS_META_IFACE_DBUS_PROPERTIES (
NML_DBUS_META_PROPERTY_INIT_S ("Banner", PROP_BANNER, NMVpnConnection, _priv.banner ),
NML_DBUS_META_PROPERTY_INIT_U ("VpnState", PROP_VPN_STATE, NMVpnConnection, _priv.vpn_state ),
),
);
static void
nm_vpn_connection_class_init (NMVpnConnectionClass *connection_class)
{
GObjectClass *object_class = G_OBJECT_CLASS (connection_class);
NMObjectClass *nm_object_class = NM_OBJECT_CLASS (connection_class);
object_class->get_property = get_property;
object_class->finalize = finalize;
nm_object_class->init_dbus = init_dbus;
/**
* NMVpnConnection:vpn-state:
*
@ -200,7 +208,13 @@ nm_vpn_connection_class_init (NMVpnConnectionClass *connection_class)
G_PARAM_READABLE |
G_PARAM_STATIC_STRINGS);
g_object_class_install_properties (object_class, _PROPERTY_ENUMS_LAST, obj_properties);
_nml_dbus_meta_class_init_with_properties (object_class, &_nml_dbus_meta_iface_nm_vpn_connection);
/* TODO: the state reason should also be exposed as a property in libnm's NMVpnConnection,
* like done for NMDevice's state reason. */
/* TODO: the D-Bus API should also expose the state-reason as a property instead of
* a "VpnStateChanged" signal. Like done for Device's "StateReason". */
G_GNUC_BEGIN_IGNORE_DEPRECATIONS
signals[VPN_STATE_CHANGED] =

View file

@ -30,20 +30,15 @@ NM_GOBJECT_PROPERTIES_DEFINE_BASE (
);
typedef struct {
GBytes *wfd_ies;
char *name;
char *manufacturer;
char *model;
char *model_number;
char *serial;
GBytes *wfd_ies;
char *hw_address;
int last_seen;
NM80211ApFlags flags;
gint32 last_seen;
guint32 flags;
guint8 strength;
} NMWifiP2PPeerPrivate;
@ -339,33 +334,6 @@ nm_wifi_p2p_peer_filter_connections (NMWifiP2PPeer *peer, const GPtrArray *conne
/*****************************************************************************/
static void
init_dbus (NMObject *object)
{
NMWifiP2PPeerPrivate *priv = NM_WIFI_P2P_PEER_GET_PRIVATE (object);
const NMPropertiesInfo property_info[] = {
{ NM_WIFI_P2P_PEER_FLAGS, &priv->flags },
{ NM_WIFI_P2P_PEER_NAME, &priv->name },
{ NM_WIFI_P2P_PEER_MANUFACTURER, &priv->manufacturer },
{ NM_WIFI_P2P_PEER_MODEL, &priv->model },
{ NM_WIFI_P2P_PEER_MODEL_NUMBER, &priv->model_number },
{ NM_WIFI_P2P_PEER_SERIAL, &priv->serial },
{ NM_WIFI_P2P_PEER_WFD_IES, &priv->wfd_ies },
{ NM_WIFI_P2P_PEER_HW_ADDRESS, &priv->hw_address },
{ NM_WIFI_P2P_PEER_STRENGTH, &priv->strength },
{ NM_WIFI_P2P_PEER_LAST_SEEN, &priv->last_seen },
{ NULL },
};
NM_OBJECT_CLASS (nm_wifi_p2p_peer_parent_class)->init_dbus (object);
_nm_object_register_properties (object,
NM_DBUS_INTERFACE_WIFI_P2P_PEER,
property_info);
}
/*****************************************************************************/
static void
get_property (GObject *object,
guint prop_id,
@ -429,7 +397,6 @@ finalize (GObject *object)
g_free (priv->model);
g_free (priv->model_number);
g_free (priv->serial);
g_free (priv->hw_address);
g_bytes_unref (priv->wfd_ies);
@ -437,17 +404,31 @@ finalize (GObject *object)
G_OBJECT_CLASS (nm_wifi_p2p_peer_parent_class)->finalize (object);
}
const NMLDBusMetaIface _nml_dbus_meta_iface_nm_wifip2ppeer = NML_DBUS_META_IFACE_INIT_PROP (
NM_DBUS_INTERFACE_WIFI_P2P_PEER,
nm_wifi_p2p_peer_get_type,
NML_DBUS_META_INTERFACE_PRIO_INSTANTIATE_HIGH,
NML_DBUS_META_IFACE_DBUS_PROPERTIES (
NML_DBUS_META_PROPERTY_INIT_U ("Flags", PROP_FLAGS, NMWifiP2PPeer, _priv.flags ),
NML_DBUS_META_PROPERTY_INIT_S ("HwAddress", PROP_HW_ADDRESS, NMWifiP2PPeer, _priv.hw_address ),
NML_DBUS_META_PROPERTY_INIT_I ("LastSeen", PROP_LAST_SEEN, NMWifiP2PPeer, _priv.last_seen ),
NML_DBUS_META_PROPERTY_INIT_S ("Manufacturer", PROP_MANUFACTURER, NMWifiP2PPeer, _priv.manufacturer ),
NML_DBUS_META_PROPERTY_INIT_S ("Model", PROP_MODEL, NMWifiP2PPeer, _priv.model ),
NML_DBUS_META_PROPERTY_INIT_S ("ModelNumber", PROP_MODEL_NUMBER, NMWifiP2PPeer, _priv.model_number ),
NML_DBUS_META_PROPERTY_INIT_S ("Serial", PROP_SERIAL, NMWifiP2PPeer, _priv.serial ),
NML_DBUS_META_PROPERTY_INIT_Y ("Strength", PROP_STRENGTH, NMWifiP2PPeer, _priv.strength ),
NML_DBUS_META_PROPERTY_INIT_AY ("WfdIEs", PROP_WFD_IES, NMWifiP2PPeer, _priv.wfd_ies ),
),
);
static void
nm_wifi_p2p_peer_class_init (NMWifiP2PPeerClass *klass)
{
GObjectClass *object_class = G_OBJECT_CLASS (klass);
NMObjectClass *nm_object_class = NM_OBJECT_CLASS (klass);
object_class->get_property = get_property;
object_class->finalize = finalize;
nm_object_class->init_dbus = init_dbus;
/**
* NMWifiP2PPeer:flags:
*
@ -579,5 +560,5 @@ nm_wifi_p2p_peer_class_init (NMWifiP2PPeerClass *klass)
G_PARAM_READABLE |
G_PARAM_STATIC_STRINGS);
g_object_class_install_properties (object_class, _PROPERTY_ENUMS_LAST, obj_properties);
_nml_dbus_meta_class_init_with_properties (object_class, &_nml_dbus_meta_iface_nm_wifip2ppeer);
}

View file

@ -11,7 +11,16 @@
#include <sys/mman.h>
#include "NetworkManager.h"
#include "nm-access-point.h"
#include "nm-checkpoint.h"
#include "nm-dhcp4-config.h"
#include "nm-dhcp6-config.h"
#include "nm-dns-manager.h"
#include "nm-ip4-config.h"
#include "nm-ip6-config.h"
#include "nm-libnm-utils.h"
#include "nm-object.h"
#include "nm-vpn-service-plugin.h"
#include "nm-utils/nm-test-utils.h"
@ -2488,7 +2497,6 @@ test_types (void)
G (nm_dhcp6_config_get_type),
G (nm_dhcp_config_get_type),
G (nm_dns_entry_get_type),
G (nm_dns_manager_get_type),
G (nm_ip4_config_get_type),
G (nm_ip6_config_get_type),
G (nm_ip_address_get_type),
@ -2500,12 +2508,10 @@ test_types (void)
G (nm_ip_tunnel_mode_get_type),
G (nm_lldp_neighbor_get_type),
G (nm_manager_error_get_type),
G (nm_manager_get_type),
G (nm_manager_reload_flags_get_type),
G (nm_metered_get_type),
G (nm_object_get_type),
G (nm_remote_connection_get_type),
G (nm_remote_settings_get_type),
G (nm_secret_agent_capabilities_get_type),
G (nm_secret_agent_error_get_type),
G (nm_secret_agent_get_secrets_flags_get_type),
@ -2665,6 +2671,401 @@ test_types (void)
/*****************************************************************************/
static void
test_nml_dbus_meta (void)
{
const NMLDBusMetaIface *meta_iface;
const NMLDBusMetaProperty *meta_property;
guint prop_idx;
gsize i, j;
guint l, m;
for (i = 0; i < G_N_ELEMENTS (_nml_dbus_meta_ifaces); i++) {
const NMLDBusMetaIface *mif = _nml_dbus_meta_ifaces[i];
nm_auto_unref_gtypeclass GObjectClass *klass_unref = NULL;
GObjectClass *klass;
GType gtype;
#define COMMON_PREFIX "org.freedesktop.NetworkManager"
g_assert (mif);
g_assert (mif->dbus_iface_name);
g_assert ( g_str_has_prefix (mif->dbus_iface_name, COMMON_PREFIX)
&& !g_str_has_suffix (mif->dbus_iface_name, ".")
&& NM_IN_SET (mif->dbus_iface_name[NM_STRLEN (COMMON_PREFIX)], '\0', '.'));
for (j = i + 1; j < G_N_ELEMENTS (_nml_dbus_meta_ifaces); j++)
g_assert (mif != _nml_dbus_meta_ifaces[j]);
if (i > 0) {
if (strcmp (_nml_dbus_meta_ifaces[i - 1]->dbus_iface_name, mif->dbus_iface_name) >= 0) {
g_error ("meta-ifaces are not properly sorted: [%zu] \"%s\" should be after [%zu] \"%s\"",
i - 1, _nml_dbus_meta_ifaces[i - 1]->dbus_iface_name, i, mif->dbus_iface_name);
}
}
g_assert ((mif->n_dbus_properties > 0) == (!!mif->dbus_properties));
if (mif->interface_prio == NML_DBUS_META_INTERFACE_PRIO_NONE) {
g_assert (!mif->get_type_fcn);
g_assert (!mif->obj_properties);
g_assert (mif->n_obj_properties == 0);
g_assert (!mif->obj_properties_reverse_idx);
if (!NM_IN_STRSET (mif->dbus_iface_name, NM_DBUS_INTERFACE_AGENT_MANAGER,
NM_DBUS_INTERFACE_DEVICE_STATISTICS,
NM_DBUS_INTERFACE_DEVICE_VETH))
g_error ("D-Bus interface \"%s\" is unexpectedly empty", mif->dbus_iface_name);
if (mif->n_dbus_properties == 0)
continue;
gtype = G_TYPE_NONE;
klass = NULL;
goto check_dbus_properties;
}
g_assert (NM_IN_SET ((NMLDBusMetaInteracePrio) mif->interface_prio, NML_DBUS_META_INTERFACE_PRIO_NMCLIENT,
NML_DBUS_META_INTERFACE_PRIO_PARENT_TYPE,
NML_DBUS_META_INTERFACE_PRIO_INSTANTIATE_LOW,
NML_DBUS_META_INTERFACE_PRIO_INSTANTIATE_HIGH));
g_assert (mif->get_type_fcn);
gtype = mif->get_type_fcn ();
g_assert (g_type_is_a (gtype, G_TYPE_OBJECT));
if (mif->interface_prio == NML_DBUS_META_INTERFACE_PRIO_NMCLIENT)
g_assert (gtype == NM_TYPE_CLIENT);
else
g_assert (g_type_is_a (gtype, NM_TYPE_OBJECT));
/* We only test parts of the types, and avoid initializing all the types.
* That is so that other unit tests in this process randomly run with either
* the class instance already initialized or not. */
if ((nmtst_get_rand_uint () % 5) == 0) {
klass = (klass_unref = g_type_class_ref (gtype));
g_assert (klass);
} else
klass = g_type_class_peek (gtype);
if (klass) {
if (NM_IS_OBJECT_CLASS (klass)) {
NMObjectClass *nm_object_class = NM_OBJECT_CLASS (klass);
const _NMObjectClassFieldInfo *p_prev;
const _NMObjectClassFieldInfo *p;
p_prev = NULL;
for (p = nm_object_class->property_o_info; p; p_prev = p, p = p->parent) {
g_assert (p->num > 0);
g_assert (NM_IS_OBJECT_CLASS (p->klass));
g_assert (g_type_is_a (gtype, G_TYPE_FROM_CLASS (p->klass)));
g_assert (p->klass->property_o_info == p);
if (p_prev) {
g_assert (g_type_is_a (G_TYPE_FROM_CLASS (p_prev->klass), G_TYPE_FROM_CLASS (p->klass)));
g_assert (p_prev->klass != p->klass);
}
}
} else
g_assert (NM_IS_CLIENT_CLASS (klass));
}
if (!mif->obj_properties) {
g_assert_cmpint (mif->n_obj_properties, ==, 0);
g_assert (!mif->obj_properties_reverse_idx);
} else {
g_assert (mif->obj_properties);
g_assert (mif->obj_properties[0] == 0);
g_assert_cmpint (mif->n_obj_properties, >, 1);
if (klass) {
for (l = 1; l < mif->n_obj_properties; l++) {
const GParamSpec *sp = mif->obj_properties[l];
g_assert (sp);
g_assert (sp->name);
g_assert (strlen (sp->name) > 0);
}
}
g_assert (mif->obj_properties_reverse_idx);
if (klass) {
g_assert (mif->obj_properties_reverse_idx[0] == 0xFFu);
for (l = 0; l < mif->n_obj_properties; l++) {
guint8 ridx = mif->obj_properties_reverse_idx[l];
if (ridx != 0xFFu) {
g_assert_cmpint (ridx, <=, mif->n_dbus_properties);
for (m = l + 1; m < mif->n_obj_properties; m++)
g_assert_cmpint (ridx, !=, mif->obj_properties_reverse_idx[m]);
}
}
}
}
check_dbus_properties:
for (l = 0; l < mif->n_dbus_properties; l++) {
const NMLDBusMetaProperty *mpr = &mif->dbus_properties[l];
gs_free char *obj_property_name = NULL;
const struct {
const char *dbus_type;
GType default_gtype;
} *p_expected_type, *p_expected_type_2, expected_types[] = {
{ "b", G_TYPE_BOOLEAN },
{ "q", G_TYPE_UINT },
{ "y", G_TYPE_UCHAR },
{ "i", G_TYPE_INT },
{ "u", G_TYPE_UINT },
{ "x", G_TYPE_INT64 },
{ "t", G_TYPE_UINT64 },
{ "s", G_TYPE_STRING },
{ "o", G_TYPE_STRING },
{ "ay", G_TYPE_BYTES },
{ "as", G_TYPE_STRV },
{ "ao", G_TYPE_PTR_ARRAY },
{ "a{sv}", G_TYPE_HASH_TABLE },
{ "aa{sv}", G_TYPE_PTR_ARRAY },
{ "(uu)", G_TYPE_NONE },
{ "aau", G_TYPE_NONE },
{ "au", G_TYPE_NONE },
{ "a(ayuay)", G_TYPE_NONE },
{ "aay", G_TYPE_NONE },
{ "a(ayuayu)", G_TYPE_NONE },
{ "u", G_TYPE_FLAGS },
{ "u", G_TYPE_ENUM },
{ "o", NM_TYPE_OBJECT },
};
const GParamSpec *pspec = NULL;
g_assert (mpr->dbus_property_name);
g_assert (g_variant_type_string_is_valid ((const char *) mpr->dbus_type));
if (l > 0) {
if (strcmp (mif->dbus_properties[l - 1].dbus_property_name, mpr->dbus_property_name) >= 0) {
g_error ("meta-ifaces[%s] must have property #%u \"%s\" after #%u \"%s\"",
mif->dbus_iface_name, l - 1, mif->dbus_properties[l - 1].dbus_property_name, l, mpr->dbus_property_name);
}
}
obj_property_name = nm_utils_wincaps_to_dash (mpr->dbus_property_name);
g_assert (obj_property_name);
for (p_expected_type = &expected_types[0]; TRUE; ) {
if (nm_streq ((const char *) mpr->dbus_type, p_expected_type->dbus_type))
break;
p_expected_type++;
if (p_expected_type >= &expected_types[G_N_ELEMENTS (expected_types)]) {
g_error ("D-Bus type \"%s\" is not implemented (in property %s.%s)",
(const char *) mpr->dbus_type,
mif->dbus_iface_name,
mpr->dbus_property_name);
}
}
if ( klass
&& mpr->obj_properties_idx > 0) {
g_assert_cmpint (mpr->obj_properties_idx, <, mif->n_obj_properties);
if (!mpr->obj_property_no_reverse_idx)
g_assert_cmpint (mif->obj_properties_reverse_idx[mpr->obj_properties_idx], ==, l);
else {
g_assert_cmpint (mif->obj_properties_reverse_idx[mpr->obj_properties_idx], !=, l);
g_assert_cmpint (mif->obj_properties_reverse_idx[mpr->obj_properties_idx], !=, 0xFFu);
}
pspec = mif->obj_properties[mpr->obj_properties_idx];
}
if (mpr->use_notify_update_prop) {
g_assert (mpr->notify_update_prop);
} else {
if (klass)
g_assert (pspec);
}
if (pspec) {
const char *expected_property_name;
if ( mif == &_nml_dbus_meta_iface_nm_connection_active
&& nm_streq (pspec->name, NM_ACTIVE_CONNECTION_SPECIFIC_OBJECT_PATH)) {
g_assert_cmpstr (obj_property_name, ==, "specific-object");
expected_property_name = NM_ACTIVE_CONNECTION_SPECIFIC_OBJECT_PATH;
} else if ( mif == &_nml_dbus_meta_iface_nm_accesspoint
&& nm_streq (pspec->name, NM_ACCESS_POINT_BSSID)) {
g_assert_cmpstr (obj_property_name, ==, "hw-address");
expected_property_name = NM_ACCESS_POINT_BSSID;
} else if ( mif == &_nml_dbus_meta_iface_nm_device_wireguard
&& nm_streq (pspec->name, NM_DEVICE_WIREGUARD_FWMARK)) {
g_assert_cmpstr (obj_property_name, ==, "fw-mark");
expected_property_name = NM_DEVICE_WIREGUARD_FWMARK;
} else if ( NM_IN_SET (mif, &_nml_dbus_meta_iface_nm_ip4config,
&_nml_dbus_meta_iface_nm_ip6config)
&& nm_streq (pspec->name, NM_IP_CONFIG_ADDRESSES)) {
g_assert (NM_IN_STRSET (obj_property_name, "addresses", "address-data"));
expected_property_name = NM_IP_CONFIG_ADDRESSES;
} else if ( NM_IN_SET (mif, &_nml_dbus_meta_iface_nm_ip4config,
&_nml_dbus_meta_iface_nm_ip6config)
&& nm_streq (pspec->name, NM_IP_CONFIG_ROUTES)) {
g_assert (NM_IN_STRSET (obj_property_name, "routes", "route-data"));
expected_property_name = NM_IP_CONFIG_ROUTES;
} else if ( NM_IN_SET (mif, &_nml_dbus_meta_iface_nm_ip4config,
&_nml_dbus_meta_iface_nm_ip6config)
&& nm_streq (pspec->name, NM_IP_CONFIG_NAMESERVERS)) {
g_assert (NM_IN_STRSET (obj_property_name, "nameservers", "nameserver-data"));
expected_property_name = NM_IP_CONFIG_NAMESERVERS;
} else if ( mif == &_nml_dbus_meta_iface_nm_ip4config
&& nm_streq (pspec->name, NM_IP_CONFIG_WINS_SERVERS)) {
g_assert (NM_IN_STRSET (obj_property_name, "wins-servers", "wins-server-data"));
expected_property_name = NM_IP_CONFIG_WINS_SERVERS;
} else if ( mif == &_nml_dbus_meta_iface_nm_dnsmanager
&& nm_streq (pspec->name, NM_CLIENT_DNS_CONFIGURATION)) {
g_assert_cmpstr (obj_property_name, ==, "configuration");
expected_property_name = NM_CLIENT_DNS_CONFIGURATION;
} else if ( mif == &_nml_dbus_meta_iface_nm_dnsmanager
&& nm_streq (pspec->name, NM_CLIENT_DNS_MODE)) {
g_assert_cmpstr (obj_property_name, ==, "mode");
expected_property_name = NM_CLIENT_DNS_MODE;
} else if ( mif == &_nml_dbus_meta_iface_nm_dnsmanager
&& nm_streq (pspec->name, NM_CLIENT_DNS_RC_MANAGER)) {
g_assert_cmpstr (obj_property_name, ==, "rc-manager");
expected_property_name = NM_CLIENT_DNS_RC_MANAGER;
} else
expected_property_name = obj_property_name;
g_assert_cmpstr (expected_property_name, ==, pspec->name);
if (!mpr->use_notify_update_prop) {
for (p_expected_type_2 = &expected_types[0]; p_expected_type_2 < &expected_types[G_N_ELEMENTS (expected_types)]; p_expected_type_2++) {
if (!nm_streq ((const char *) mpr->dbus_type, p_expected_type_2->dbus_type))
continue;
if ( pspec->value_type == p_expected_type_2->default_gtype
|| ( p_expected_type_2->default_gtype == G_TYPE_ENUM
&& g_type_is_a (pspec->value_type, G_TYPE_ENUM))
|| ( p_expected_type_2->default_gtype == G_TYPE_FLAGS
&& g_type_is_a (pspec->value_type, G_TYPE_FLAGS))
|| ( p_expected_type_2->default_gtype == NM_TYPE_OBJECT
&& nm_streq ((const char *) mpr->dbus_type, "o")
&& g_type_is_a (pspec->value_type, NM_TYPE_OBJECT)))
break;
}
if (p_expected_type_2 >= &expected_types[G_N_ELEMENTS (expected_types)]) {
g_error ("D-Bus property \"%s.%s\" (type \"%s\") maps to property \"%s\", but that has an unexpected property type %s (expected %s)",
mif->dbus_iface_name,
mpr->dbus_property_name,
(const char *) mpr->dbus_type,
pspec->name,
g_type_name (pspec->value_type),
g_type_name (p_expected_type->default_gtype));
}
}
if (!nm_utils_g_param_spec_is_default (pspec)) {
/* We expect our properties to have a default value of zero/NULL.
* Except those whitelisted here: */
if ( ( mif == &_nml_dbus_meta_iface_nm_accesspoint
&& nm_streq (pspec->name, NM_ACCESS_POINT_LAST_SEEN))
|| ( mif == &_nml_dbus_meta_iface_nm_device_vxlan
&& nm_streq (pspec->name, NM_DEVICE_VXLAN_LEARNING))
|| ( mif == &_nml_dbus_meta_iface_nm_device_wireless
&& nm_streq (pspec->name, NM_DEVICE_WIFI_LAST_SCAN))
|| ( mif == &_nml_dbus_meta_iface_nm_wifip2ppeer
&& nm_streq (pspec->name, NM_WIFI_P2P_PEER_LAST_SEEN))
|| ( mif == &_nml_dbus_meta_iface_nm_device_tun
&& NM_IN_STRSET (pspec->name, NM_DEVICE_TUN_GROUP,
NM_DEVICE_TUN_OWNER))) {
/* pass */
} else {
g_error ("property %s.%s (%s.%s) does not have a default value of zero",
mif->dbus_iface_name,
mpr->dbus_property_name,
g_type_name (gtype),
pspec->name);
}
}
}
}
if (klass) {
for (l = 0; l < mif->n_obj_properties; l++) {
guint8 ridx = mif->obj_properties_reverse_idx[l];
if (ridx != 0xFFu)
g_assert_cmpint (mif->dbus_properties[ridx].obj_properties_idx, ==, l);
}
}
g_assert (mif == nml_dbus_meta_iface_get (mif->dbus_iface_name));
}
meta_iface = nml_dbus_meta_iface_get (NM_DBUS_INTERFACE);
g_assert (meta_iface);
g_assert (meta_iface == &_nml_dbus_meta_iface_nm);
g_assert_cmpstr (meta_iface->dbus_iface_name, ==, NM_DBUS_INTERFACE);
meta_property = nml_dbus_meta_property_get (meta_iface, "Version", &prop_idx);
g_assert (meta_property);
g_assert_cmpstr (meta_property->dbus_property_name, ==, "Version");
g_assert (&meta_iface->dbus_properties[prop_idx] == meta_property);
}
/*****************************************************************************/
static void
test_dbus_meta_types (void)
{
struct list_data {
const char *dbus_iface_name;
GType gtype;
NMLDBusMetaInteracePrio interface_prio;
} list[] = {
{ NM_DBUS_INTERFACE, NM_TYPE_CLIENT, NML_DBUS_META_INTERFACE_PRIO_NMCLIENT, },
{ NM_DBUS_INTERFACE_ACCESS_POINT, NM_TYPE_ACCESS_POINT, NML_DBUS_META_INTERFACE_PRIO_INSTANTIATE_HIGH, },
{ NM_DBUS_INTERFACE_ACTIVE_CONNECTION, NM_TYPE_ACTIVE_CONNECTION, NML_DBUS_META_INTERFACE_PRIO_INSTANTIATE_LOW, }, /* otherwise, NM_TYPE_VPN_CONNECTION. */
{ NM_DBUS_INTERFACE_DEVICE_6LOWPAN, NM_TYPE_DEVICE_6LOWPAN, NML_DBUS_META_INTERFACE_PRIO_INSTANTIATE_HIGH, },
{ NM_DBUS_INTERFACE_DEVICE_ADSL, NM_TYPE_DEVICE_ADSL, NML_DBUS_META_INTERFACE_PRIO_INSTANTIATE_HIGH, },
{ NM_DBUS_INTERFACE_DEVICE_BOND, NM_TYPE_DEVICE_BOND, NML_DBUS_META_INTERFACE_PRIO_INSTANTIATE_HIGH, },
{ NM_DBUS_INTERFACE_DEVICE_BRIDGE, NM_TYPE_DEVICE_BRIDGE, NML_DBUS_META_INTERFACE_PRIO_INSTANTIATE_HIGH, },
{ NM_DBUS_INTERFACE_DEVICE_BLUETOOTH, NM_TYPE_DEVICE_BT, NML_DBUS_META_INTERFACE_PRIO_INSTANTIATE_HIGH, },
{ NM_DBUS_INTERFACE_DEVICE_DUMMY, NM_TYPE_DEVICE_DUMMY, NML_DBUS_META_INTERFACE_PRIO_INSTANTIATE_HIGH, },
{ NM_DBUS_INTERFACE_DEVICE_WIRED, NM_TYPE_DEVICE_ETHERNET, NML_DBUS_META_INTERFACE_PRIO_INSTANTIATE_HIGH, },
{ NM_DBUS_INTERFACE_DEVICE_GENERIC, NM_TYPE_DEVICE_GENERIC, NML_DBUS_META_INTERFACE_PRIO_INSTANTIATE_HIGH, },
{ NM_DBUS_INTERFACE_DEVICE_INFINIBAND, NM_TYPE_DEVICE_INFINIBAND, NML_DBUS_META_INTERFACE_PRIO_INSTANTIATE_HIGH, },
{ NM_DBUS_INTERFACE_DEVICE_IP_TUNNEL, NM_TYPE_DEVICE_IP_TUNNEL, NML_DBUS_META_INTERFACE_PRIO_INSTANTIATE_HIGH, },
{ NM_DBUS_INTERFACE_DEVICE_MACSEC, NM_TYPE_DEVICE_MACSEC, NML_DBUS_META_INTERFACE_PRIO_INSTANTIATE_HIGH, },
{ NM_DBUS_INTERFACE_DEVICE_MACVLAN, NM_TYPE_DEVICE_MACVLAN, NML_DBUS_META_INTERFACE_PRIO_INSTANTIATE_HIGH, },
{ NM_DBUS_INTERFACE_DEVICE_MODEM, NM_TYPE_DEVICE_MODEM, NML_DBUS_META_INTERFACE_PRIO_INSTANTIATE_HIGH, },
{ NM_DBUS_INTERFACE_DEVICE_OLPC_MESH, NM_TYPE_DEVICE_OLPC_MESH, NML_DBUS_META_INTERFACE_PRIO_INSTANTIATE_HIGH, },
{ NM_DBUS_INTERFACE_DEVICE_OVS_INTERFACE, NM_TYPE_DEVICE_OVS_INTERFACE, NML_DBUS_META_INTERFACE_PRIO_INSTANTIATE_HIGH, },
{ NM_DBUS_INTERFACE_DEVICE_OVS_PORT, NM_TYPE_DEVICE_OVS_PORT, NML_DBUS_META_INTERFACE_PRIO_INSTANTIATE_HIGH, },
{ NM_DBUS_INTERFACE_DEVICE_OVS_BRIDGE, NM_TYPE_DEVICE_OVS_BRIDGE, NML_DBUS_META_INTERFACE_PRIO_INSTANTIATE_HIGH, },
{ NM_DBUS_INTERFACE_DEVICE_WIFI_P2P, NM_TYPE_DEVICE_WIFI_P2P, NML_DBUS_META_INTERFACE_PRIO_INSTANTIATE_HIGH, },
{ NM_DBUS_INTERFACE_DEVICE_PPP, NM_TYPE_DEVICE_PPP, NML_DBUS_META_INTERFACE_PRIO_INSTANTIATE_HIGH, },
{ NM_DBUS_INTERFACE_DEVICE_TEAM, NM_TYPE_DEVICE_TEAM, NML_DBUS_META_INTERFACE_PRIO_INSTANTIATE_HIGH, },
{ NM_DBUS_INTERFACE_DEVICE_TUN, NM_TYPE_DEVICE_TUN, NML_DBUS_META_INTERFACE_PRIO_INSTANTIATE_HIGH, },
{ NM_DBUS_INTERFACE_DEVICE_VLAN, NM_TYPE_DEVICE_VLAN, NML_DBUS_META_INTERFACE_PRIO_INSTANTIATE_HIGH, },
{ NM_DBUS_INTERFACE_DEVICE_WPAN, NM_TYPE_DEVICE_WPAN, NML_DBUS_META_INTERFACE_PRIO_INSTANTIATE_HIGH, },
{ NM_DBUS_INTERFACE_DEVICE_VXLAN, NM_TYPE_DEVICE_VXLAN, NML_DBUS_META_INTERFACE_PRIO_INSTANTIATE_HIGH, },
{ NM_DBUS_INTERFACE_DEVICE_WIRELESS, NM_TYPE_DEVICE_WIFI, NML_DBUS_META_INTERFACE_PRIO_INSTANTIATE_HIGH, },
{ NM_DBUS_INTERFACE_DEVICE_WIREGUARD, NM_TYPE_DEVICE_WIREGUARD, NML_DBUS_META_INTERFACE_PRIO_INSTANTIATE_HIGH, },
{ NM_DBUS_INTERFACE_DHCP4_CONFIG, NM_TYPE_DHCP4_CONFIG, NML_DBUS_META_INTERFACE_PRIO_INSTANTIATE_HIGH, },
{ NM_DBUS_INTERFACE_DHCP6_CONFIG, NM_TYPE_DHCP6_CONFIG, NML_DBUS_META_INTERFACE_PRIO_INSTANTIATE_HIGH, },
{ NM_DBUS_INTERFACE_IP4_CONFIG, NM_TYPE_IP4_CONFIG, NML_DBUS_META_INTERFACE_PRIO_INSTANTIATE_HIGH, },
{ NM_DBUS_INTERFACE_IP6_CONFIG, NM_TYPE_IP6_CONFIG, NML_DBUS_META_INTERFACE_PRIO_INSTANTIATE_HIGH, },
{ NM_DBUS_INTERFACE_WIFI_P2P_PEER, NM_TYPE_WIFI_P2P_PEER, NML_DBUS_META_INTERFACE_PRIO_INSTANTIATE_HIGH, },
{ NM_DBUS_INTERFACE_SETTINGS_CONNECTION, NM_TYPE_REMOTE_CONNECTION, NML_DBUS_META_INTERFACE_PRIO_INSTANTIATE_HIGH, },
{ NM_DBUS_INTERFACE_SETTINGS, NM_TYPE_CLIENT, NML_DBUS_META_INTERFACE_PRIO_NMCLIENT, },
{ NM_DBUS_INTERFACE_DNS_MANAGER, NM_TYPE_CLIENT, NML_DBUS_META_INTERFACE_PRIO_NMCLIENT, },
{ NM_DBUS_INTERFACE_VPN_CONNECTION, NM_TYPE_VPN_CONNECTION, NML_DBUS_META_INTERFACE_PRIO_INSTANTIATE_HIGH, },
{ NM_DBUS_INTERFACE_CHECKPOINT, NM_TYPE_CHECKPOINT, NML_DBUS_META_INTERFACE_PRIO_INSTANTIATE_HIGH, },
};
guint i;
/* These iface<->gtype associations are copied from "nm-client.c"'s obj_nm_for_gdbus_object().
* This is redundant to the meta-data, still check that the meta data matches. */
for (i = 0; i < G_N_ELEMENTS (list); i++) {
const struct list_data *d = &list[i];
const NMLDBusMetaIface *meta_iface;
meta_iface = nml_dbus_meta_iface_get (d->dbus_iface_name);
g_assert (meta_iface);
g_assert_cmpint (meta_iface->interface_prio, ==, d->interface_prio);
g_assert (meta_iface->get_type_fcn() == d->gtype);
}
}
/*****************************************************************************/
NMTST_DEFINE ();
int main (int argc, char **argv)
@ -2675,6 +3076,8 @@ int main (int argc, char **argv)
g_test_add_func ("/libnm/general/fixup_vendor_string", test_fixup_vendor_string);
g_test_add_func ("/libnm/general/nm_vpn_service_plugin_read_vpn_details", test_nm_vpn_service_plugin_read_vpn_details);
g_test_add_func ("/libnm/general/test_types", test_types);
g_test_add_func ("/libnm/general/test_nml_dbus_meta", test_nml_dbus_meta);
g_test_add_func ("/libnm/general/test_dbus_meta_types", test_dbus_meta_types);
return g_test_run ();
}

View file

@ -180,8 +180,8 @@ test_device_added_signal_after_init (void)
g_signal_handlers_disconnect_by_func (client, device_sai_added_cb, &result);
g_signal_handlers_disconnect_by_func (client, devices_sai_notify_cb, &result);
g_assert ((result & SIGNAL_MASK) == SIGNAL_FIRST);
g_assert ((result & NOTIFY_MASK) == NOTIFY_SECOND);
g_assert ((result & SIGNAL_MASK) == SIGNAL_SECOND);
g_assert ((result & NOTIFY_MASK) == NOTIFY_FIRST);
devices = nm_client_get_devices (client);
g_assert (devices);
@ -635,13 +635,18 @@ assert_ac_and_device (NMClient *client)
device = devices->pdata[0];
if (device != ac_device && devices->len > 1)
device = devices->pdata[1];
device_ac = nm_device_get_active_connection (device);
g_assert (device_ac != NULL);
g_assert_cmpstr (nm_object_get_path (NM_OBJECT (device)), ==, nm_object_get_path (NM_OBJECT (ac_device)));
g_assert (device == ac_device);
g_assert_cmpstr (nm_object_get_path (NM_OBJECT (ac)), ==, nm_object_get_path (NM_OBJECT (device_ac)));
g_assert (ac == device_ac);
device_ac = nm_device_get_active_connection (device);
if (!device_ac) {
/* the stub NetworkManager service starts activating in an idle handler (delayed). That means, the
* device may not yet refer to the active connection at this point. */
} else {
g_assert_cmpstr (nm_object_get_path (NM_OBJECT (ac)), ==, nm_object_get_path (NM_OBJECT (device_ac)));
g_assert (ac == device_ac);
}
}
static void
@ -995,6 +1000,8 @@ test_connection_invalid (void)
gssize idx[4];
gs_unref_variant GVariant *variant = NULL;
g_assert (g_main_loop_get_context (gl.loop) == (g_main_context_get_thread_default () ?: g_main_context_default ()));
/**************************************************************************
* Add three connections before starting libnm. One valid, two invalid.
*************************************************************************/

View file

@ -106,6 +106,7 @@ libnm-core/nm-team-utils.c
libnm-core/nm-utils.c
libnm-core/nm-vpn-editor-plugin.c
libnm-core/nm-vpn-plugin-info.c
libnm/nm-client.c
libnm/nm-device-6lowpan.c
libnm/nm-device-adsl.c
libnm/nm-device-bond.c
@ -131,10 +132,8 @@ libnm/nm-device-wifi.c
libnm/nm-device-wimax.c
libnm/nm-device-wpan.c
libnm/nm-device.c
libnm/nm-manager.c
libnm/nm-object.c
libnm/nm-remote-connection.c
libnm/nm-remote-settings.c
libnm/nm-vpn-plugin-old.c
libnm/nm-vpn-service-plugin.c
data/org.freedesktop.NetworkManager.policy.in.in

View file

@ -185,6 +185,26 @@ nm_pstr_equal (gconstpointer a, gconstpointer b)
&& nm_streq0 (*s1, *s2));
}
guint
nm_pint_hash (gconstpointer p)
{
const int *s = p;
if (!s)
return nm_hash_static (298377461u);
return nm_hash_val (1208815757u, *s);
}
gboolean
nm_pint_equals (gconstpointer a, gconstpointer b)
{
const int *s1 = a;
const int *s2 = a;
return s1 == s2
|| (s1 && s2 && *s1 == *s2);
}
guint
nm_pdirect_hash (gconstpointer p)
{

View file

@ -278,6 +278,14 @@ gboolean nm_pstr_equal (gconstpointer a, gconstpointer b);
/*****************************************************************************/
/* nm_pint_*() are for hashing keys that are pointers to int values,
* that is, "const int *" types. */
guint nm_pint_hash (gconstpointer p);
gboolean nm_pint_equals (gconstpointer a, gconstpointer b);
/*****************************************************************************/
/* this hashes/compares the pointer value that we point to. Basically,
* (*((const void *const*) a) == *((const void *const*) b)). */

View file

@ -635,8 +635,8 @@ NM_G_ERROR_MSG (GError *error)
#define _NM_ENSURE_TYPE_CONST(type, value) ((const type) (value))
#endif
#if _NM_CC_SUPPORT_GENERIC
#define NM_STRUCT_OFFSET_ENSURE_TYPE(type, container, field) (_Generic ((((container *) NULL)->field), \
#if _NM_CC_SUPPORT_GENERIC && ( !defined (__clang__) || __clang_major__ > 3 )
#define NM_STRUCT_OFFSET_ENSURE_TYPE(type, container, field) (_Generic ( (&(((container *) NULL)->field))[0] , \
type: G_STRUCT_OFFSET (container, field)))
#else
#define NM_STRUCT_OFFSET_ENSURE_TYPE(type, container, field) G_STRUCT_OFFSET (container, field)
@ -1043,7 +1043,7 @@ _nm_gobject_notify_together_impl (obj_type *obj, guint n, const property_enums_t
g_object_thaw_notify ((GObject *) obj); \
} \
\
static inline void \
_nm_unused static inline void \
_notify (obj_type *obj, property_enums_type prop) \
{ \
_nm_gobject_notify_together_impl (obj, 1, &prop); \

View file

@ -3535,3 +3535,368 @@ nm_g_unix_signal_source_new (int signum,
g_source_set_callback (source, handler, user_data, notify);
return source;
}
/*****************************************************************************/
#define _CTX_LOG(fmt, ...) \
G_STMT_START { \
if (FALSE) { \
gint64 _ts = g_get_monotonic_time () / 100; \
\
g_printerr (">>>> [%"G_GINT64_FORMAT".%05"G_GINT64_FORMAT"] [src:%p]: " fmt "\n", \
_ts / 10000, \
_ts % 10000, \
(ctx_src), \
##__VA_ARGS__); \
} \
} G_STMT_END
typedef struct {
int fd;
guint events;
guint registered_events;
union {
int one;
int *many;
} idx;
gpointer tag;
bool stale:1;
bool has_many_idx:1;
} PollData;
typedef struct {
GSource source;
GMainContext *context;
GHashTable *fds;
GPollFD *fds_arr;
int fds_len;
int max_priority;
bool acquired:1;
} CtxIntegSource;
static void
_poll_data_free (gpointer user_data)
{
PollData *poll_data = user_data;
if (poll_data->has_many_idx)
g_free (poll_data->idx.many);
nm_g_slice_free (poll_data);
}
static void
_ctx_integ_source_reacquire (CtxIntegSource *ctx_src)
{
if (G_LIKELY ( ctx_src->acquired
&& g_main_context_is_owner (ctx_src->context)))
return;
/* the parent context now iterates on a different thread.
* We need to release and reacquire the inner context. */
if (ctx_src->acquired)
g_main_context_release (ctx_src->context);
if (G_UNLIKELY (!g_main_context_acquire (ctx_src->context))) {
/* Nobody is supposed to reacquire the context while we use it. This is a bug
* of the user. */
ctx_src->acquired = FALSE;
g_return_if_reached ();
}
ctx_src->acquired = TRUE;
}
static gboolean
_ctx_integ_source_prepare (GSource *source,
int *out_timeout)
{
CtxIntegSource *ctx_src = ((CtxIntegSource *) source);
int max_priority;
int timeout = -1;
gboolean any_ready;
int fds_allocated;
int fds_len_old;
gs_free GPollFD *fds_arr_old = NULL;
GHashTableIter h_iter;
PollData *poll_data;
gboolean fds_changed;
int i;
_CTX_LOG ("prepare...");
_ctx_integ_source_reacquire (ctx_src);
any_ready = g_main_context_prepare (ctx_src->context, &max_priority);
fds_arr_old = g_steal_pointer (&ctx_src->fds_arr);
fds_len_old = ctx_src->fds_len;
fds_allocated = NM_MAX (1, fds_len_old); /* there is at least the wakeup's FD */
ctx_src->fds_arr = g_new (GPollFD, fds_allocated);
while ((ctx_src->fds_len = g_main_context_query (ctx_src->context,
max_priority,
&timeout,
ctx_src->fds_arr,
fds_allocated)) > fds_allocated) {
fds_allocated = ctx_src->fds_len;
g_free (ctx_src->fds_arr);
ctx_src->fds_arr = g_new (GPollFD, fds_allocated);
}
fds_changed = FALSE;
if (fds_len_old != ctx_src->fds_len)
fds_changed = TRUE;
else {
for (i = 0; i < ctx_src->fds_len; i++) {
if ( fds_arr_old[i].fd != ctx_src->fds_arr[i].fd
|| fds_arr_old[i].events != ctx_src->fds_arr[i].events) {
fds_changed = TRUE;
break;
}
}
}
if (G_UNLIKELY (fds_changed)) {
g_hash_table_iter_init (&h_iter, ctx_src->fds);
while (g_hash_table_iter_next (&h_iter, (gpointer *) &poll_data, NULL))
poll_data->stale = TRUE;
for (i = 0; i < ctx_src->fds_len; i++) {
const GPollFD *fd = &ctx_src->fds_arr[i];
poll_data = g_hash_table_lookup (ctx_src->fds, &fd->fd);
if (G_UNLIKELY (!poll_data)) {
poll_data = g_slice_new (PollData);
*poll_data = (PollData) {
.fd = fd->fd,
.idx.one = i,
.has_many_idx = FALSE,
.events = fd->events,
.registered_events = 0,
.tag = NULL,
.stale = FALSE,
};
g_hash_table_add (ctx_src->fds, poll_data);
nm_assert (poll_data == g_hash_table_lookup (ctx_src->fds, &fd->fd));
continue;
}
if (G_LIKELY (poll_data->stale)) {
if (poll_data->has_many_idx) {
g_free (poll_data->idx.many);
poll_data->has_many_idx = FALSE;
}
poll_data->events = fd->events;
poll_data->idx.one = i;
poll_data->stale = FALSE;
continue;
}
/* How odd. We have duplicate FDs. In fact, currently g_main_context_query() always
* coalesces the FDs and this cannot happen. However, that is not documented behavior,
* so we should not rely on that. So we need to keep a list of indexes... */
poll_data->events |= fd->events;
if (!poll_data->has_many_idx) {
int idx0;
idx0 = poll_data->idx.one;
poll_data->has_many_idx = TRUE;
poll_data->idx.many = g_new (int, 4);
poll_data->idx.many[0] = 2; /* number allocated */
poll_data->idx.many[1] = 2; /* number used */
poll_data->idx.many[2] = idx0;
poll_data->idx.many[3] = i;
} else {
if (poll_data->idx.many[0] == poll_data->idx.many[1]) {
poll_data->idx.many[0] *= 2;
poll_data->idx.many = g_realloc (poll_data->idx.many, sizeof (int) * (2 + poll_data->idx.many[0]));
}
poll_data->idx.many[2 + poll_data->idx.many[1]] = i;
poll_data->idx.many[1]++;
}
}
g_hash_table_iter_init (&h_iter, ctx_src->fds);
while (g_hash_table_iter_next (&h_iter, (gpointer *) &poll_data, NULL)) {
if (poll_data->stale) {
nm_assert (poll_data->tag);
nm_assert (poll_data->events == poll_data->registered_events);
_CTX_LOG ("prepare: remove poll fd=%d, events=0x%x", poll_data->fd, poll_data->events);
g_source_remove_unix_fd (&ctx_src->source, poll_data->tag);
g_hash_table_iter_remove (&h_iter);
continue;
}
if (!poll_data->tag) {
_CTX_LOG ("prepare: add poll fd=%d, events=0x%x", poll_data->fd, poll_data->events);
poll_data->registered_events = poll_data->events;
poll_data->tag = g_source_add_unix_fd (&ctx_src->source, poll_data->fd, poll_data->registered_events);
continue;
}
if (poll_data->registered_events != poll_data->events) {
_CTX_LOG ("prepare: update poll fd=%d, events=0x%x", poll_data->fd, poll_data->events);
poll_data->registered_events = poll_data->events;
g_source_modify_unix_fd (&ctx_src->source, poll_data->tag, poll_data->registered_events);
}
}
}
NM_SET_OUT (out_timeout, timeout);
ctx_src->max_priority = max_priority;
_CTX_LOG ("prepare: done, any-ready=%d, timeout=%d, max-priority=%d", any_ready, timeout, max_priority);
/* we always need to poll, because we have some file descriptors. */
return FALSE;
}
static gboolean
_ctx_integ_source_check (GSource *source)
{
CtxIntegSource *ctx_src = ((CtxIntegSource *) source);
GHashTableIter h_iter;
gboolean some_ready;
PollData *poll_data;
nm_assert (ctx_src->context);
_CTX_LOG ("check");
_ctx_integ_source_reacquire (ctx_src);
g_hash_table_iter_init (&h_iter, ctx_src->fds);
while (g_hash_table_iter_next (&h_iter, (gpointer *) &poll_data, NULL)) {
guint revents;
revents = g_source_query_unix_fd (&ctx_src->source, poll_data->tag);
if (G_UNLIKELY (poll_data->has_many_idx)) {
int num = poll_data->idx.many[1];
int *p_idx = &poll_data->idx.many[2];
for (; num > 0; num--, p_idx++)
ctx_src->fds_arr[*p_idx].revents = revents;
} else
ctx_src->fds_arr[poll_data->idx.one].revents = revents;
}
some_ready = g_main_context_check (ctx_src->context,
ctx_src->max_priority,
ctx_src->fds_arr,
ctx_src->fds_len);
_CTX_LOG ("check (some-ready=%d)...", some_ready);
return some_ready;
}
static gboolean
_ctx_integ_source_dispatch (GSource *source,
GSourceFunc callback,
gpointer user_data)
{
CtxIntegSource *ctx_src = ((CtxIntegSource *) source);
nm_assert (ctx_src->context);
_ctx_integ_source_reacquire (ctx_src);
_CTX_LOG ("dispatch");
g_main_context_dispatch (ctx_src->context);
return G_SOURCE_CONTINUE;
}
static void
_ctx_integ_source_finalize (GSource *source)
{
CtxIntegSource *ctx_src = ((CtxIntegSource *) source);
GHashTableIter h_iter;
PollData *poll_data;
g_return_if_fail (ctx_src->context);
_CTX_LOG ("finalize...");
g_hash_table_iter_init (&h_iter, ctx_src->fds);
while (g_hash_table_iter_next (&h_iter, (gpointer *) &poll_data, NULL)) {
nm_assert (poll_data->tag);
_CTX_LOG ("prepare: remove poll fd=%d, events=0x%x", poll_data->fd, poll_data->events);
g_source_remove_unix_fd (&ctx_src->source, poll_data->tag);
g_hash_table_iter_remove (&h_iter);
}
nm_clear_pointer (&ctx_src->fds, g_hash_table_unref);
nm_clear_g_free (&ctx_src->fds_arr);
ctx_src->fds_len = 0;
if (ctx_src->acquired) {
ctx_src->acquired = FALSE;
g_main_context_release (ctx_src->context);
}
nm_clear_pointer (&ctx_src->context, g_main_context_unref);
}
static GSourceFuncs ctx_integ_source_funcs = {
.prepare = _ctx_integ_source_prepare,
.check = _ctx_integ_source_check,
.dispatch = _ctx_integ_source_dispatch,
.finalize = _ctx_integ_source_finalize,
};
/**
* nm_utils_g_main_context_create_integrate_source:
* @inner_context: the inner context that will be integrated to an
* outer #GMainContext.
*
* By integrating the inner context with an outer context, when iterating the outer
* context sources on the inner context will be dispatched. Note that while the
* created source exists, the @inner_context will be acquired. The user gets restricted
* what to do with the inner context. In particular while the inner context is integrated,
* the user should not acquire the inner context again or explicitly iterate it. What
* the user of course still can (and wants to) do is attaching new sources to the inner
* context.
*
* Note that GSource has a priority. While each context dispatches events based on
* their source's priorities, the outer context dispatches to the inner context
* only with one priority (the priority of the created source). That is, the sources
* from the two contexts are kept separate and are not sorted by their priorities.
*
* Returns: a newly created GSource that should be attached to the
* outer context.
*/
GSource *
nm_utils_g_main_context_create_integrate_source (GMainContext *inner_context)
{
CtxIntegSource *ctx_src;
g_return_val_if_fail (inner_context, NULL);
if (!g_main_context_acquire (inner_context)) {
/* We require to acquire the context while it's integrated. We need to keep it acquired
* for the entire duration.
*
* This is also necessary because g_source_attach() only wakes up the context, if
* the context is currently acquired. */
g_return_val_if_reached (NULL);
}
ctx_src = (CtxIntegSource *) g_source_new (&ctx_integ_source_funcs, sizeof (CtxIntegSource));
g_source_set_name (&ctx_src->source, "ContextIntegrateSource");
ctx_src->context = g_main_context_ref (inner_context);
ctx_src->fds = g_hash_table_new_full (nm_pint_hash, nm_pint_equals, _poll_data_free, NULL);
ctx_src->fds_len = 0;
ctx_src->fds_arr = NULL;
ctx_src->acquired = TRUE;
ctx_src->max_priority = G_MAXINT;
_CTX_LOG ("create new integ-source for %p", inner_context);
return &ctx_src->source;
}

View file

@ -963,6 +963,9 @@ nm_g_source_attach (GSource *source,
return source;
}
NM_AUTO_DEFINE_FCN0 (GMainContext *, _nm_auto_unref_gmaincontext, g_main_context_unref)
#define nm_auto_unref_gmaincontext nm_auto (_nm_auto_unref_gmaincontext)
static inline GMainContext *
nm_g_main_context_push_thread_default (GMainContext *context)
{
@ -1291,6 +1294,10 @@ void nm_utils_invoke_on_idle (NMUtilsInvokeOnIdleCallback callback,
/*****************************************************************************/
GSource *nm_utils_g_main_context_create_integrate_source (GMainContext *internal);
/*****************************************************************************/
static inline void
nm_strv_ptrarray_add_string_take (GPtrArray *cmd,
char *str)

View file

@ -528,12 +528,53 @@ _nmtstc_client_new_inside_loop (gboolean sync)
return d.client;
}
static NMClient *
_nmtstc_client_new_extra_context (void)
{
GMainContext *inner_context;
NMClient *client;
GSource *source;
guint key_idx;
inner_context = g_main_context_new ();
g_main_context_push_thread_default (inner_context);
client = nmtstc_client_new (TRUE);
source = nm_utils_g_main_context_create_integrate_source (inner_context);
g_main_context_pop_thread_default (inner_context);
g_main_context_unref (inner_context);
g_source_attach (source, g_main_context_get_thread_default ());
for (key_idx = 0; TRUE; key_idx++) {
char s[100];
/* nmtstc_client_new() may call _nmtstc_client_new_extra_context() repeatedly. We
* need to attach the source to a previously unused key. */
nm_sprintf_buf (s, "nm-test-extra-context-%u", key_idx);
if (!g_object_get_data (G_OBJECT (client), s)) {
g_object_set_data_full (G_OBJECT (client),
s,
source,
(GDestroyNotify) nm_g_source_destroy_and_unref);
break;
}
}
return client;
}
NMClient *
nmtstc_client_new (gboolean allow_iterate_main_context)
{
gboolean inside_loop;
gboolean sync;
if (nmtst_get_rand_uint32 () % 5 == 0)
return _nmtstc_client_new_extra_context ();
if (!allow_iterate_main_context) {
sync = TRUE;
inside_loop = FALSE;

View file

@ -18,7 +18,6 @@ typedef struct SDEventSource {
GSource source;
GPollFD pollfd;
sd_event *event;
guint *default_source_id;
} SDEventSource;
static gboolean
@ -36,41 +35,49 @@ event_check (GSource *source)
static gboolean
event_dispatch (GSource *source, GSourceFunc callback, gpointer user_data)
{
return sd_event_dispatch (((SDEventSource *)source)->event) > 0;
return sd_event_dispatch (((SDEventSource *) source)->event) > 0;
}
static void
event_finalize (GSource *source)
{
SDEventSource *s;
SDEventSource *s = (SDEventSource *) source;
s = (SDEventSource *) source;
sd_event_unref (s->event);
if (s->default_source_id)
*s->default_source_id = 0;
}
static SDEventSource *
event_create_source (sd_event *event, guint *default_source_id)
event_create_source (sd_event *event)
{
static GSourceFuncs event_funcs = {
static const GSourceFuncs event_funcs = {
.prepare = event_prepare,
.check = event_check,
.dispatch = event_dispatch,
.finalize = event_finalize,
};
SDEventSource *source;
gboolean is_default_event = FALSE;
int r;
g_return_val_if_fail (event, NULL);
if (!event) {
is_default_event = TRUE;
r = sd_event_default (&event);
if (r < 0)
g_return_val_if_reached (NULL);
}
source = (SDEventSource *) g_source_new (&event_funcs, sizeof (SDEventSource));
source = (SDEventSource *) g_source_new ((GSourceFuncs *) &event_funcs, sizeof (SDEventSource));
source->event = sd_event_ref (event);
source->pollfd.fd = sd_event_get_fd (event);
source->pollfd.events = G_IO_IN | G_IO_HUP | G_IO_ERR;
source->default_source_id = default_source_id;
source->event = is_default_event
? g_steal_pointer (&event)
: sd_event_ref (event);
g_source_add_poll ((GSource *) source, &source->pollfd);
source->pollfd = (GPollFD) {
.fd = sd_event_get_fd (source->event),
.events = G_IO_IN | G_IO_HUP | G_IO_ERR,
};
g_source_add_poll (&source->source, &source->pollfd);
return source;
}
@ -80,35 +87,15 @@ event_attach (sd_event *event, GMainContext *context)
{
SDEventSource *source;
guint id;
int r;
sd_event *e = event;
guint *p_default_source_id = NULL;
if (!e) {
static guint default_source_id = 0;
source = event_create_source (event);
if (default_source_id) {
/* The default event cannot be registered multiple times. */
g_return_val_if_reached (0);
}
g_return_val_if_fail (source, 0);
r = sd_event_default (&e);
if (r < 0)
g_return_val_if_reached (0);
p_default_source_id = &default_source_id;
}
source = event_create_source (e, p_default_source_id);
id = g_source_attach ((GSource *) source, context);
g_source_unref ((GSource *) source);
if (!event) {
*p_default_source_id = id;
sd_event_unref (e);
}
g_return_val_if_fail (id, 0);
nm_assert (id != 0);
return id;
}