Commit graph

32 commits

Author SHA1 Message Date
Dan Winship 2ff4a7d4b0 libnm: strip GDBus gunk from GErrors
Call g_dbus_error_strip_remote_error() on all errors returned from
gdbus calls. (Blah!)
2014-10-22 08:29:10 -04:00
Dan Winship 1f8ec6122e libnm: fix NMActiveConnection:specific-object-path
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.
2014-10-21 09:45:20 -04:00
Dan Winship 2ac83c0e8b libnm: fix async property circular reference handling
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.
2014-10-19 09:26:49 -04:00
Dan Winship fcfb4b40ba libnm: make use of GParamSpecFlags and GParamSpecEnum
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().
2014-10-03 09:36:28 -04:00
Dan Winship ad25e5c970 libnm: reorganize demarshal_generic(), make unrecognized type a warning
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).
2014-10-03 09:36:28 -04:00
Dan Winship 5c2d2eed30 libnm: fix properties-changed debug logging
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".
2014-10-03 09:36:27 -04:00
Thomas Haller df57b6b4d1 libnm: add NMObject:dbus-connection property to inject DBUS connection
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>
2014-10-03 11:21:17 +02:00
Thomas Haller 284a14d62f libnm: assert for interface name in _nm_object_class_add_interface()
Signed-off-by: Thomas Haller <thaller@redhat.com>
2014-10-03 11:21:17 +02:00
Thomas Haller 94331184d8 libnm: remove unused variable NMObjectPrivate:private_connection
Signed-off-by: Thomas Haller <thaller@redhat.com>
2014-10-03 11:21:17 +02:00
Thomas Haller 351cf9b328 libnm: fix warning about returning zero instead of %NULL in _nm_object_create()
clang warns:
    make[4]: Entering directory `./NetworkManager/libnm'
      CC       nm-object.lo
    nm-object.c:640:11: error: expression which evaluates to zero treated as a null pointer constant of type 'GObject *' (aka 'struct _GObject *') [-Werror,-Wnon-literal-null-conversion]
                            return G_TYPE_INVALID;
                                   ^~~~~~~~~~~~~~
    /usr/include/glib-2.0/gobject/gtype.h:57:26: note: expanded from macro 'G_TYPE_INVALID'
    #define G_TYPE_INVALID                  G_TYPE_MAKE_FUNDAMENTAL (0)
                                            ^~~~~~~~~~~~~~~~~~~~~~~~~~~
    /usr/include/glib-2.0/gobject/gtype.h:221:36: note: expanded from macro 'G_TYPE_MAKE_FUNDAMENTAL'
    #define G_TYPE_MAKE_FUNDAMENTAL(x)      ((GType) ((x) << G_TYPE_FUNDAMENTAL_SHIFT))
                                            ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    nm-object.c:655:11: error: expression which evaluates to zero treated as a null pointer constant of type 'GObject *' (aka 'struct _GObject *') [-Werror,-Wnon-literal-null-conversion]
                            return G_TYPE_INVALID;
                                   ^~~~~~~~~~~~~~
    /usr/include/glib-2.0/gobject/gtype.h:57:26: note: expanded from macro 'G_TYPE_INVALID'
    #define G_TYPE_INVALID                  G_TYPE_MAKE_FUNDAMENTAL (0)
                                            ^~~~~~~~~~~~~~~~~~~~~~~~~~~
    /usr/include/glib-2.0/gobject/gtype.h:221:36: note: expanded from macro 'G_TYPE_MAKE_FUNDAMENTAL'
    #define G_TYPE_MAKE_FUNDAMENTAL(x)      ((GType) ((x) << G_TYPE_FUNDAMENTAL_SHIFT))
                                            ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    2 errors generated.

Fixes: b3c4917b0f
Signed-off-by: Thomas Haller <thaller@redhat.com>
2014-09-22 16:32:01 +02:00
Dan Winship 6793a32a8c libnm: port to GDBus
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).
2014-09-18 11:51:09 -04:00
Dan Winship 4750559548 libnm: rename nm-dbus-helpers-private.h to nm-dbus-helpers.h
The .h file should have the same name as the .c file.
2014-09-18 11:51:08 -04:00
Dan Winship acf4b5a572 libnm: split nm-dbus-helpers utils into sync/async versions
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.
2014-09-18 11:51:08 -04:00
Dan Winship b3c4917b0f libnm: move most of the subclass-type-deciding code into NMObject
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.
2014-09-18 11:51:08 -04:00
Dan Winship b728d1fb70 libnm: let NMObject create all D-Bus proxies
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.)
2014-09-18 11:51:08 -04:00
Dan Winship aa18b88a4f libnm: don't hardcode things like "org.freedesktop.DBus.Properties"
Use the #defines provided by libdbus instead.
2014-09-18 11:51:08 -04:00
Dan Winship f9f9d297f8 libnm: fix race conditions when creating the same object twice
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.
2014-09-17 08:21:22 -04:00
Dan Winship f3c02058d4 libnm: drop two unnecessary NM_IS_OBJECT() checks
Now that NMRemoteConnection is an NMObject, the code only creates
NMObjects, so we don't need that check.
2014-09-17 08:21:22 -04:00
Dan Winship a59136878a libnm: fix object-creation-failure code
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.
2014-09-17 08:21:21 -04:00
Dan Winship b732380d1e libnm: drop NMObject:dbus-connection
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.
2014-09-09 12:10:13 -04:00
Dan Winship 98959d5432 libnm: fix NMIP4Config/NMIP6Config addresses/routes properties
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.
2014-09-04 09:21:05 -04:00
Dan Winship 074c2093b6 libnm: drop NM_TYPE_OBJECT_ARRAY, use G_TYPE_PTR_ARRAY
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.)
2014-09-04 09:21:04 -04:00
Dan Winship 20dc44bda9 libnm: drop NM_TYPE_SSID, use G_TYPE_BYTES
Make NMAccessPoint:ssid be G_TYPE_BYTES and update the corresponding
APIs accordingly.
2014-09-04 09:21:04 -04:00
Dan Winship 4eb04dbcf8 libnm: drop NM_TYPE_STRING_ARRAY, use G_TYPE_STRV
Make NMIP4Config and NMIP6Config's array-of-string properties be
G_TYPE_STRV, and update the corresponding APIs accordingly.
2014-09-04 09:21:04 -04:00
Dan Winship 0fdd71fe6e libnm: make NMRemoteConnection an NMObject 2014-08-16 10:17:53 -04:00
Dan Winship 5ed054aca9 libnm: get rid of redundant NMRemoteConnection properties
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.)
2014-08-16 10:17:53 -04:00
Dan Winship c4a86eba52 libnm: remove redundant NM name watching code
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.
2014-08-07 15:43:43 -04:00
Dan Winship 3ddce74803 libnm: rename NetworkManager.h and NetworkManagerVPN.h
"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"
2014-08-01 14:34:40 -04:00
Dan Winship 258e74eb0c libnm: make the the use of GInitable mandatory
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**.
2014-08-01 14:34:40 -04:00
Dan Winship 8ca2998d81 libnm: add init_dbus() virtual method to NMObject
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.)
2014-08-01 14:34:40 -04:00
Dan Winship eedcf185a7 libnm: add libnm/libnm-core (part 2)
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
]
2014-08-01 14:34:04 -04:00
Dan Winship d595f7843e libnm: add libnm/libnm-core (part 1)
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/

]
2014-08-01 14:34:04 -04:00