NMActiveConnection:specific-object was renamed to
NMActiveConnection:specific-object-path in 677314c5, but it didn't
actually work, because of assumptions NMObject makes. Fix that.
3e5b3833 changed various libnm methods to return 0-length arrays
rather than NULL, and changed various other places to assume this
behavior. The guarantee that they didn't return NULL relied on the
assumption that all D-Bus properties would get initialized by NMObject
code before anyone could call their get methods.
However, this assumption was violated in the case where two objects
circularly referenced each other (eg, NMDevice and
NMActiveConnection). f9f9d297 attempted to fix this by slightly
changing the ordering of NMObjectCache operations, but it actually
ended up breaking things and causing infinite loops of object creation
in some cases.
There's no way to guarantee we never return partially-initialized
objects without heavily rewriting the object-creation code, so this
reverts most of f9f9d297 (leaving only the new comment in
_nm_object_create()). The crashes introduced by 3e5b3833 will no
longer happen because we've now fixed the classes to have initialized
their object arrays to non-NULL values even before they get the real
values.
Make enum- and flags-valued properties use GParamSpecEnum and
GParamSpecFlags, for better introspectability/bindability.
This requires no changes outside libnm-core/libnm since the expected
data size is still the same with g_object_get()/g_object_set(), and
GLib will internally convert between int/uint and enum/flags GValues
when using g_object_get_property()/g_object_set_property().
Redo the HANDLE_TYPE macro in demarshal_generic() in a more
syntactically-sane way (both to help the editor with indentation and
to make it not look so weird).
Also, if demarshal_generic() is asked to handle a property of a type
that it doesn't know how to handle, that's a programmer error, so do a
g_warning() in that case (as opposed to being asked to demarshal a
value of the wrong D-Bus type, which could just be a bug in the peer
that sent the data, so that stays as a debug message).
The code was mistakenly still using G_VALUE_TYPE_NAME() instead of
g_variant_get_type_string().
Also, refer to the properties with standard gtk-doc punctuation:
"TypeName:property-name".
Commit b732380d1e removed the gobject
property "NMObject:connection". However, this property is still needed
to inject the DBUS connection when creating new proxy objects. Without it,
we call _nm_dbus_new_connection() in the constructor for every proxy NMObject.
In case of non-private connections, g_bus_get_sync() already returns the same
connection. However for private connections, g_dbus_connection_new_for_address_sync()
would create a separate DBUS connection.
https://bugzilla.gnome.org/show_bug.cgi?id=737725
Signed-off-by: Thomas Haller <thaller@redhat.com>
Port libnm-core/libnm to GDBus.
The NetworkManager daemon continues to use dbus-glib; the
previously-added connection hash/variant conversion methods are now
moved to NetworkManagerUtils (along with a few other utilities that
are now only needed by the daemon code).
dbus-glib's functions to get a DBusGConnection or a DBusGProxy return
right away, but gdbus's corresponding functions do some initial setup
and communication as part of initialization, and so either block or
run async. So split _nm_dbus_new_connection() and
_nm_dbus_new_proxy_for_connection() into sync and async versions now,
and update NMObject to use the correct one depending on whether it is
working synchronously or asynchronously.
NMObject has a system that lets devices and active connections get
created as the correct subtypes (NMDeviceFoo / NMActiveConnection vs
NMVpnConnection). But it was much more generic than it needed to be,
because NMDevice and NMActiveConnection both did the same thing (fetch
a D-Bus property and then look at its value). So move the
property-fetching part into NMObject, and only use the callback for
converting the property value to a GType.
Add _nm_object_class_add_interface(), for declaring that a class
implements a particular interface, and then have NMObject create the
corresponding proxies itself. (The subclass can get a copy with
_nm_object_get_proxy() if it needs it for something).
(In GDBus, creating a proxy is a heavier operation than in dbus-glib,
so we'll need to create the proxies asynchronously. Moving the
creation to NMObject makes that easier since we can do it as part
of the existing init/init_async.)
If two code paths try to asynchronously create the same object at the
same time (eg, because it shows up in two different properties), we
are supposed to deal with that. But at some point a race condition
appeared where we could end up returning a partially-initialized
object for one of the properties in the async case. Fix that.
Also add comments to both the sync and async cases explaining why they
work the way they do.
If _nm_object_create() hit an error, it would return the
(half-initialized) object anyway. If _nm_object_create_async() hit an
error, it would return NULL, but leak the half-initialized object. Fix
both cases.
The only plausible use case for the NMObject:dbus-connection property
is for using the session bus in test programs. So just drop it and use
an environment variable to decide which bus to use instead.
The docs for NMIP4Config:addresses and NMIP4Config:routes claimed that
they were GPtrArrays of NMIP4Address/NMIP4Route, but get_property()
was actually trying to set them the D-Bus representation type, and it
was failing anyway because it used g_value_set_boxed() on a parameter
that was declared GParamSpecPointer. Fix it to use a GPtrArray-valued
property, and set it to the right thing.
NMIP6Config did the right thing with its :addresses and :routes
properties, but was using custom types (NM_TYPE_IP6_ADDRESS_OBJECT_ARRAY and
NM_TYPE_IP6_ROUTE_OBJECT_ARRAY). Make it use G_TYPE_PTR_ARRAY instead.
nm-types.c, nm-types.h, and nm-types-private.h are now empty, and so
can be dropped.
Use G_TYPE_PTR_ARRAY for GPtrArray-of-NMObject-valued properties,
because it has better introspection/bindings support.
As with the strdict change in libnm-core, we need to manually copy the
array in get_property() implementations, to preserve the standard
semantics that get_property() returns a copy, not the internal array.
(This patch also changes those properties so that they are always
non-NULL until dispose(); previously some of them could be either NULL
or 0-length at different times.)
NMRemoteConnection had two DBusGConnection properties
(NMRemoteConnection:bus and NMRemoteConnection:dbus-connection) and
two D-Bus path properties (NMConnection:path and
NMRemoteConnection:dbus-path). The former of each pair were the
traditional names, and the latter were added for compatibility with
NMObject.
In libnm, we can just drop NMRemoteConnection:bus, and use the
NMObject-compatible :dbus-connection name instead.
For the path properties, we need to rename either NMConnection:path or
NMObject:dbus-path. Since NMObject already has "nm_object_get_path()"
rather than "nm_object_get_dbus_path()", and it already mistakenly
referred to the property as "NMObject:path" in the gtk-docs, it seemed
to make sense to rename that one rather than the NMConnection one.
(And then, for consistency, rename "nm_object_get_connection()" to
"nm_object_get_dbus_connection()" to also match its property.)
NMClient was watching to see whether NetworkManager was running, but
its parent class NMObject was already doing that anyway, so NMClient
doesn't need to do it itself.
This also requires making NMClient:init_async() wait for NMObject's
init_async() code to finish before calling GetPermissions, rather than
running the two in parallel like before (since we don't know if NM is
running or not until after NMObject's init_async() returns). This is
probably more correct anyway in terms of inheritance, and it's not as
much slower than the original code as it sounds, since previously
we were calling NameHasOwner twice (in serial) anyway.
"NetworkManager.h"'s name (and non-standard capitalization) suggest
that it's some sort of high-level super-important header, but it's
really just low-level D-Bus stuff. Rename it to "nm-dbus-interface.h"
and likewise "NetworkManagerVPN.h" to "nm-vpn-dbus-interface.h"
Remove _nm_object_ensure_inited(), etc; objects that implement
GInitable are now mandatory-to-init().
Remove constructor() implementations that sometimes return NULL; do
all the relevant checking in init() instead.
Make nm_client_new() and nm_remote_settings_new() take a GCancellable
and a GError**.
Rather than having each object type override constructed() to call
_nm_object_register_properties(), have NMObject call a virtual method
on the subclass to ask it to register them.
Move some code around in nm-client.c and nm-object.c so that all
D-Bus-related initialization happens in init_dbus(), and
non-D-Bus-related stuff stays in construct().
(This simplifies the next commit.)
This fixes up the code from the previous "clean" import, and adds
build infrastructure.
[There are two slightly orthogonal sets of changes in this patch.
First, the files added in the previous commit were modified as followed:
# Replace internal references to "libnm-util" and "libnm-glib" with "libnm"
perl -pi -e 's/libnm-(util|glib)/libnm/;' libnm-core/*.[ch] libnm-core/tests/*.[ch] libnm/*.[ch] libnm/tests/*.[ch]
# Fix includes of the enum-types files
perl -pi -e 's/nm-utils-enum-types/nm-core-enum-types/;' libnm-core/*.[ch] libnm-core/tests/*.[ch] libnm/*.[ch] libnm/tests/*.[ch]
perl -pi -e 's/nm-glib-enum-types/nm-enum-types/;' libnm/*.[ch] libnm/tests/*.[ch]
# Fix some python example code
perl -pi -e 's/import NMClient/import NM/;' -e 's/NMClient.Client\(\)/NM.Client()/;' libnm/nm-client.c
Then, the build infrastructure was added (without further modifying
any existing files in libnm-core or libnm.)
Note: to regenerate libnm.ver after rebase:
(head -2 libnm-util/libnm-util.ver; (grep -h '\s'nm_ libnm-util/libnm-util.ver libnm-glib/libnm-glib.ver | env LANG=C sort); tail -3 libnm-util/libnm-util.ver) > libnm/libnm.ver
]
This commit begins creating the new "libnm", which will replace
libnm-util and libnm-glib.
The main reason for the libnm-util/libnm-glib split is that the daemon
needs to link to libnm-util (to get NMSettings, NMConnection, etc),
but can't link to libnm-glib (because it uses many of the same type
names as the NetworkManager daemon. eg, NMDevice). So the daemon links
to only libnm-util, but basically all clients link to both.
With libnm, there will be only a single client-visible library, and
NetworkManager will internally link against a private "libnm-core"
containing the parts that used to be in libnm-util.
(The "libnm-core" parts still need to be in their own directory so
that the daemon can see those header files without also seeing the
ones in libnm/ that conflict with its own headers.)
[This commit just copies the source code from libnm-util/ to
libnm-core/, and libnm-glib/ to libnm/:
mkdir -p libnm-core/tests/
mkdir -p libnm/tests/
cp libnm-util/*.[ch] libnm-util/nm-version.h.in libnm-core/
rm -f libnm-core/nm-version.h libnm-core/nm-setting-template.[ch] libnm-core/nm-utils-enum-types.[ch]
cp libnm-util/tests/*.[ch] libnm-core/tests/
cp libnm-glib/*.[ch] libnm/
rm -f libnm/libnm_glib.[ch] libnm/libnm-glib-test.c libnm/nm-glib-enum-types.[ch]
cp libnm-glib/tests/*.[ch] libnm/tests/
]