Commit Graph

60 Commits

Author SHA1 Message Date
Dan Winship
1981323b19 libnm-glib: fix a crash in NMObject
deferred_notify_cb() needs to take a ref on the object around emitting
its deferred signals, since otherwise if a notify:: handler drops the
last reference on an object, a following g_object_notify() call would
crash.
2013-11-14 13:01:55 -05:00
Thomas Haller
3eb1d5e902 core: cleanup freeing of glib collections of pointers
When freeing one of the collections such as GArray, GPtrArray, GSList,
etc. it is common that the items inside the connections must be
freed/unrefed too.

The previous code often iterated over the collection first with
e.g. g_ptr_array_foreach and passing e.g. g_free as GFunc argument.
For one, this has the problem, that g_free has a different signature
GDestroyNotify then the expected GFunc. Moreover, this can be
simplified either by setting a clear function
(g_ptr_array_set_clear_func) or by passing the destroy function to the
free function (g_slist_free_full).

Signed-off-by: Thomas Haller <thaller@redhat.com>
2013-10-22 19:53:57 +02:00
Thomas Haller
9d0167c374 trivial: whitespace fix
Signed-off-by: Thomas Haller <thaller@redhat.com>
2013-10-14 12:08:53 +02:00
Dan Winship
cbe261caa2 libnm: more valgrinding fixes 2013-10-03 11:04:45 -04:00
Dan Winship
28e67c7d73 libnm-glib: fix the leak that breaks the shell network status icon
All NMObjects created in response to property changes were getting
leaked, which in particular included all NMAccessPoint objects, which
meant that after disconnecting and reconnecting a wifi interface some
number of times (depending on how many access points were in the
area), gnome-shell would be watching so many D-Bus AccessPoint objects
(most of which didn't exist any more) that it would hit dbus-daemon's
limit on the number of match rules you can register, which meant that
NMActiveConnections created after that point wouldn't be able to
register for PropertiesChanged notifications, which meant that the
network status icon would get out of sync.
2013-10-03 11:04:45 -04:00
Dan Williams
1b773f4e6e libnm-glib: make properties-changed debugging available at runtime
Use an environment variable LIBNM_GLIB_DEBUG=properties-changed to
indicate that properties-changed debugging messages should be printed.
Also cleans up the debug output formatting.
2013-10-01 11:17:59 -05:00
Thomas Haller
2766829a67 libnm-glib: don't warn when dbus object initialization fails with UNKNOWN_METHOD
A common case where this warning was triggered, was the removal of
IP6Config objects. As this can happen as a regular event, do not warn in
this case.

Signed-off-by: Thomas Haller <thaller@redhat.com>
2013-09-05 22:08:43 +02:00
Dan Winship
3b498b3ec0 libnm-glib: fix the object creation warning for remote connections
NMRemoteConnection is not a NMObject, so we can't always use
nm_object_get_path(),

https://bugzilla.gnome.org/show_bug.cgi?id=701762
2013-06-08 12:27:03 -03:00
Dan Winship
d529580cbb libnm-glib, core: use g_cclosure_marshal_generic
Since we depend on new glib now, we can just use the generic
marshaller rather than generating our own.
2013-05-08 14:59:29 -04:00
Dan Williams
110a40358d libnm-glib: never call NM D-Bus methods if NM isn't running
Though the client shouldn't be calling anything when NM isn't running
(because clients have nm_client_get_manager_running()), make sure
that NMClient never calls a NetworkManager method when NM isn't
on the bus.

Next, ensure NMObject doesn't try to refresh properties when NM isn't
running.  Creating an NMClient may trigger a property refresh request,
but if NM isn't running, defer that until NM starts, to ensure that
we don't D-Bus autostart NM.

Third, ensure NMRemoteSettings doesn't attempt to list connections
unless NM is running.

This prevents service activation of NetworkManager in lieu of dbus-glib
learning about DBUS_HEADER_FLAG_NO_AUTO_START.
2013-04-08 11:30:32 -05:00
Dan Williams
a87b5a15df libnm-glib: use private connection before trying the system bus
Use the D-Bus connection helper whenever we need a connection to
NM, which by default tries to use a private connection instead of
the shared bus connection whenever the user is root.  Doing this
by default will not change the behavior of libnm-glib, and allows
tools like nmcli and libnm-glib-using clients to work in minimal
environments (those without a bus daemon) by default.
2013-04-08 11:30:32 -05:00
Dan Williams
661d09852d libnm-glib: use helpers to create dbus proxies
When using a private connection, we need to use dbus_g_proxy_new_for_peer()
because the bus isn't involved.  Since many parts of libnm-glib create a
proxy for their corresponding remote object, consolidate the proxy creation
logic.

A later patch will add logic to use a private connection versus a bus-based
one.
2013-04-08 11:30:32 -05:00
Dan Williams
1699a93be3 libnm-glib: fix memory leak of GSimpleAsyncResult loading object properties 2013-04-01 17:18:53 -05:00
Jiří Klimeš
82fb1978a4 all: use G_VALUE_INIT to initialize GValue variables
It makes the initializations more explicit.
G_VALUE_INIT is available since glib 2.30, and NM now require glib >= 2.32
2013-03-25 08:41:18 +01:00
Dan Winship
1eaf919bc6 libnm-glib: update properties before NMDevice:state-changed
Because object-valued properties (like ip4-config) get reloaded
asynchronously when they change, we will still have out-of-date values
for them cached at the point when we get the StateChanged signal from
the daemon. Work around this by manually reloading all properties
before emitting the client-side signal.

Also, fix a dumb bug in NMObject...
2012-08-29 15:46:15 -04:00
Dan Winship
320464490e libnm-glib: fix GAsyncInitable implementations
If a class implements init_async, it should implement init_finish too,
rather than assuming the default implementation will do the right
thing (which it briefly didn't in glib 2.33).
2012-07-17 09:43:15 -04:00
Jiří Klimeš
7c7e8dc692 libnm-glib: add "object-creation-failed" signal to NMObject
The signal is private for libnm-glib and should not be used externally.
It is emitted when there's an error while creating an object.
In addition, this commit makes use of the signal in NMClient to ensure
that the callbacks are always called for nm_client_activate_connection()
and nm_client_add_and_activate_connection().
2012-04-25 16:39:17 +02:00
Dan Winship
be18dd06cd libnm-glib: NULL out priv fields on dispose()
In some situations, objects might get used after being disposed, so
clear out their various priv fields so we don't try to access unreffed
objects, freed strings, etc.

https://bugzilla.gnome.org/show_bug.cgi?id=674473
2012-04-23 16:09:58 -04:00
Dan Williams
411cb36344 libnm-glib: protect against potentially NULL changed property values (rh #808784)
No idea *why* they're NULL, unless perhaps that dbus-glib can't demarshal
the variants for some reason, but until we know why at least log the
problem so we know what properties the issue might affect.
2012-04-23 14:30:42 -05:00
Dan Williams
8e503afeda libnm-glib: two object uniqueness fixes
First: object creation requests get triggered each time a property
that refers to the object is read.  That can happen from a couple
of places around the same time (like initialization) and to be
expected.  But when those requests are processed (after we've
determined the type of object to create) a previous request may
have already created the object.  If that's the case don't create
a duplicate.

Second: properties can also be updated from a few places which
don't know about each other (from both regular code and the
"pseudo property" signal handlers) so when adding objects to
array properties, make sure the object hasn't already been
added to that array.
2012-03-13 14:31:26 -05:00
Dan Winship
2c6bade5b9 libnm-glib: fix some property-handling warnings
Fix handle_object_array_property() to deal with receiving an empty
list correctly (rather than warning and leaving the property with its
previous value still set).

Also, add two more untracked properties that shouldn't be warned about
(NMDevice:device-type and NMActiveConnection:vpn, both of which are
only used at construct time).
2012-02-20 11:48:31 -05:00
Dan Williams
8572ecfd7c libnm-glib: don't crash on unknown object types
Like when an old libnm-glib is being run against a newer NM when
a new device type has been added.
2012-02-16 12:54:47 -06:00
Dan Winship
c721477d11 libnm-glib: fix premature child object signal emission
The notifications for child objects (like NMClient's device-added
signal or NMDeviceWifi's access-point-added signal) could get emitted
before the child objects were actually constructed, because
object_created() decrements the properties-retrieved tracking
variable, which wasn't always incremented before calling that
function.
2012-02-09 13:25:59 -06:00
Dan Williams
7f9fe7601e libnm-glib: better debugging of property accesses and updates
Need to initialize libnm-util to get GValue transforms registered
so the property values print out as strings.  Then actually print
some debugging information about properties.
2012-02-07 12:36:45 -06:00
Dan Williams
57bd84139f libnm-glib: ensure synchronous property updates are actually synchronous
Some property updates (mainly those dealing with properties that
hold objects themsevles) weren't being done in a synchronous manner
when synchronicity was requested.  Make sure that happens.
2012-02-07 12:35:12 -06:00
Dan Winship
410ac72325 libnm-glib: fix to not depend on newer glib 2012-02-06 17:29:49 -06:00
Dan Winship
7844ead116 libnm-glib: nm_client_new_async, fix up NMClient asynchrony issues 2012-02-03 10:33:43 -06:00
Dan Winship
9fd98ef91b libnm-glib: implement GInitable/GAsyncInitable in NMObject
Implement GInitable and GAsyncInitable in NMObject, with
implementations that synchronously or asynchonously load all
properties, and change _nm_object_ensure_inited() to run
g_initable_init().

Update the object/object-array property handling to initialize the
objects after creating them (synchronously or asynchronously,
according to the situation), so that they will have all of their
properties preloaded before they are ever visible to the caller.

Move the non-blocking/non-failable parts of various objects'
constructor() methods to constructed(), and move the blocking/failable
parts to init(), and implement init_async() methods with non-blocking
versions of the blocking methods.

Make nm_device_new() and nm_client_new() call
_nm_object_ensure_inited(), to preserve the behaviour formerly
enforced by their construct() methods, that properties are guaranteed
to be initialized before any signals involving them are emitted.
2012-02-03 10:33:43 -06:00
Dan Winship
ad5daa098c libnm-glib: add "pseudoproperties" for things like Client.GetDevices
Add generic handling for "properties" that consist of a "Get" method,
an "Added" signal, and a "Removed" signal, reusing some of the code
for handling object-array-valued properties. And load the values of
pseudo properties from _nm_object_reload/ensure_properties as well.
2012-02-03 10:33:43 -06:00
Dan Winship
cc90f1010e libnm-glib: simplify handling of object and object array properties
Add an "object_type" field to NMPropertiesInfo, and use that with
DBUS_TYPE_G_OBJECT_PATH and DBUS_TYPE_G_ARRAY_OF_OBJECT_PATH
properties so that we don't need custom marshallers for each one.

When creating an NMDevice or NMActiveConnection, we need to fetch an
extra property first to figure out the exact subclass to use, so add a
bit of infrastructure for that as well. Also, do that preprocessing
asynchronously when processing a property change notification, so that
it doesn't block the main loop.
2012-02-03 10:33:43 -06:00
Dan Winship
5afcee4693 libnm-glib: simplify property getter methods
Rather than having every property getter method have code to fetch
that specific property's value, just call the new
_nm_object_ensure_inited() (which makes sure that we've read all the
property values on the object at least once), and then return the
cached value. (After we've read the initial property values, the
PropertiesChanged signal handler will ensure that the values are kept
up to date, so we can always just return cached property values after
that point.)

This then lets us get rid of _nm_object_get_property() and its
wrappers.
2012-02-03 10:33:43 -06:00
Dan Winship
2e48cc092c libnm-glib: simplify and genericize property declaration
Rename _nm_object_handle_properties_changed(), etc, to be about
properties in general, rather than just property changes.

Interpret func==NULL in NMPropertiesInfo as meaning "use
_nm_object_demarshal_generic", and then reorder the fields so that you
can just leave that field out in the declarations when it's NULL.

Add a way to register properties that exist in D-Bus but aren't
tracked by the NMObjects, and use that for NMDevice's D-Bus Ip4Address
property, replacing the existing hack.

Also add a few other missing properties noticed along the way.
2012-02-03 10:33:43 -06:00
Dan Williams
d8437ffaf1 core: fix deprecated usage of g_value_[get|set]_char() (bgo #662694) 2011-10-28 11:35:59 -05:00
Tomeu Vizoso
77e9cd53a8 libnm-glib: allow to constuct NMObject with NULL bus 2011-08-16 17:21:07 -05:00
Tomeu Vizoso
dd175e3bf7 libnm-glib: warn early if an object is tried to be instantiated without a path 2011-08-16 17:20:49 -05:00
Dan Williams
8afce8590a libnm-glib: handle NULL object paths generically
Since D-Bus doesn't allow NULL or zero-length object paths, NM
uses "/" as a placeholder here.  Make sure the generic marshalling
code handles that so we don't have to do it in multiple places and
simplify handling of NULL objects somewhat.
2011-05-26 19:19:32 -05:00
Dan Williams
df511f74f7 build: use -Wundef and fix up cases where stuff wasn't defined (bgo #647157) 2011-04-14 13:19:12 -05:00
Dan Williams
c17721b360 libnm-glib: allow manual processing of properties changed events
Mostly for handling the GetAll response.
2011-02-16 15:04:39 -06:00
Jiří Klimeš
d6905a8d66 libnm-glib: add GError parameter to _nm_object_get_... functions
It allows us to get the error back and have control over printing
the error.
2011-02-15 17:34:11 +01:00
Giovanni Campagna
3ebecd2a29 introspection: add GObject introspection support (bgo #637032)
Add the necessary annotations (the mininum required, that is those
on return values. NULL parameters or container types may require
more), and the Autotools stuff to get a NetworkManager GIR for
libnm-util and a NMClient for libnm-glib.
2011-01-21 14:46:09 -06:00
Jiří Klimeš
9f2b48ef08 libnm-glib: call D-Bus with a timeout when Set()ting properties
The caller needs to be authenticated, so wait a bit to be sure
it didn't quit too quickly.
2010-10-15 09:41:34 +02:00
Dan Williams
4eea398b06 libnm-glib: fix invalid memory access during property notification
If an NMObject listened to property change notifications from
other NMObjects and then in response to that queued up other
property changes of it's own, those would get added to the
property change list that was being iterated through already.
Each name in the change list is freed after being notified,
but the change list itself is actually freed when all
properties have been notified.  So an object that queues up
another change notification ends up in _nm_object_queue_notify()
which iterates the change list where half of the data elements
are already freed...
2010-06-30 11:51:40 -07:00
Dan Williams
c9d2d977dd libnm-glib: tighter warning print checks
Should be checking for dbus-glib errors of the right type,
instead of any error code (dbus-glib or not) that happens to be
4.
2009-10-20 12:10:30 -07:00
Dan Williams
3d194df94a libnm-glib: warning cleanups 2009-10-20 11:48:23 -07:00
Dan Williams
7118676968 2008-11-14 Dan Williams <dcbw@redhat.com>
Relicense libnm-glib to LGPLv2+ with agreement from contributors



git-svn-id: http://svn-archive.gnome.org/svn/NetworkManager/trunk@4285 4912f4e0-d625-0410-9fb7-b9a5a253dbdc
2008-11-14 17:41:16 +00:00
Michael Biebl
d7940bcb9b Rename private nm_* functions to _nm_*
git-svn-id: http://svn-archive.gnome.org/svn/NetworkManager/trunk@4012 4912f4e0-d625-0410-9fb7-b9a5a253dbdc
2008-08-26 09:34:31 +00:00
Tambet Ingo
0f534a9f8f 2008-08-12 Tambet Ingo <tambet@gmail.com>
Start documenting libnm-glib public API using gtk-doc.

	* libnm-glib/nm-serial-device.c:
	* libnm-glib/nm-object.c:
	* libnm-glib/nm-gsm-device.c:
	* libnm-glib/nm-device.c:
	* libnm-glib/nm-device-wifi.c:
	* libnm-glib/nm-device-ethernet.c:
	* libnm-glib/nm-client.c:
	* libnm-glib/nm-cdma-device.c: Document the public API.

	* docs/libnm-glib/libnm-glib.types: Implement.

	* docs/libnm-glib/Makefile.am: Implement.

	* autogen.sh:
	* configure.in:
	* Makefile.am: Add gtk-doc support.


git-svn-id: http://svn-archive.gnome.org/svn/NetworkManager/trunk@3932 4912f4e0-d625-0410-9fb7-b9a5a253dbdc
2008-08-12 08:05:21 +00:00
Dan Williams
291019fb79 Quiet warning about unhandled property for now
git-svn-id: http://svn-archive.gnome.org/svn/NetworkManager/trunk@3867 4912f4e0-d625-0410-9fb7-b9a5a253dbdc
2008-07-28 14:04:31 +00:00
Dan Williams
c01b4c9e2e 2008-03-27 Dan Williams <dcbw@redhat.com>
* nm-object.c
		- (nm_object_queue_notify): don't notify multiple times for the same
			property

	* nm-object-private.h
		- (handle_ptr_array_return): return NULL if the given array is NULL or
			if it has zero elements

	* nm-ip4-config.c
		- (finalize): use g_ptr_array_foreach() when freeing domains
		- (nm_ip4_config_get_domains): use handle_ptr_array_return()

	* nm-active-connection.c
		- (nm_active_connection_get_devices): use handle_ptr_array_return()

	* nm-device-802-11-wireless.c
	  nm-device-802-11-wireless.h
		- (nm_device_802_11_wireless_get_access_points): return const; use
			handle_ptr_array_return()

	* nm-types.c
		- (nm_object_array_demarshal): always create an array, even of length
			zero, to distinguish between "NM returned no items" and "haven't
			asked NM yet"

	* nm-client.c
		- (dispose): free active connections too
		- (proxy_name_owner_changed): free active connections too when NM goes
			away
		- (nm_client_get_devices): return const; use handle_ptr_array_return()
		- (nm_client_get_active_connections): use handle_ptr_array_return()



git-svn-id: http://svn-archive.gnome.org/svn/NetworkManager/trunk@3506 4912f4e0-d625-0410-9fb7-b9a5a253dbdc
2008-03-27 14:10:43 +00:00
Dan Williams
9a163be59a 2008-03-25 Dan Williams <dcbw@redhat.com>
* libnm-glib/nm-object.c
	  libnm-glib/nm-object-private.h
		- (nm_object_queue_notify): add helper to batch & postpone GObject notify
			signals to an idle handler
		- (nm_object_get_property): add a timeout to the D-Bus method call



git-svn-id: http://svn-archive.gnome.org/svn/NetworkManager/trunk@3501 4912f4e0-d625-0410-9fb7-b9a5a253dbdc
2008-03-25 11:34:33 +00:00