Commit Graph

218 Commits

Author SHA1 Message Date
Matthias Clasen
adf892e96a Annotate all examples with their language
The C ones, at least.
2014-02-01 15:11:49 -05:00
Matthias Clasen
42cf80780b Docs: Big entity cleanup
Strip lots of entity use from |[ ]| examples (which are now
implicit CDATA). Also remove many redundant uses of <!-- -->.
2014-02-01 12:00:30 -05:00
Matthias Clasen
3247d11704 GDBusConnection: Convert docs to markdown
And straighten out capitalization across the file.
2014-02-01 10:22:42 -05:00
Matthias Clasen
4d12e0d66f Docs: Don't use the emphasis tag
Most of the time, the text read just as well without the extra
boldness.
2014-01-31 20:34:33 -05:00
Daniel Mustieles
078dbda148 Updated FSF's address 2014-01-31 14:31:55 +01:00
Matthias Clasen
acfb76afe2 Docs: don't use <footnote>
It basically does not work in the HTML output.
2014-01-30 23:52:58 -05:00
Ryan Lortie
51b3dd7332 GDBusConnection: don't write to stdout
When losing the D-Bus connection, we would write to stdout about it just
before killing ourselves with SIGTERM.  We're a library, so we should
probably use stderr instead.

https://bugzilla.gnome.org/show_bug.cgi?id=721324
2014-01-02 10:08:55 -05:00
Matthias Clasen
0356d7f4c3 Fix a typo in a comment
The D-Bus interface is org.freedesktop.DBus.Peer, not
org.freedesktop.DBus.
2014-01-01 17:59:21 -05:00
Dan Winship
158dde0507 Replace #ifdef HAVE_UNISTD_H checks with #ifdef G_OS_UNIX
In Windows development environments that have it, <unistd.h> is mostly
just a wrapper around several other native headers (in particular,
<io.h>, which contains read(), close(), etc, and <process.h>, which
contains getpid()). But given that some Windows dev environments don't
have <unistd.h>, everything that uses those functions on Windows
already needed to include the correct Windows header as well, and so
there is never any point to including <unistd.h> on Windows.

Also, remove some <unistd.h> includes (and a few others) that were
unnecessary even on unix.

https://bugzilla.gnome.org/show_bug.cgi?id=710519
2013-11-20 09:25:39 -05:00
Ryan Lortie
cb4469600c GDBusConnection: be more careful with async GetAll
It's possible to get a org.freedesktop.Properties.GetAll call even if we
have no readable properties in the introspection, in which case we
should return the empty list in the usual way.

We should certainly _not_ be dispatching to the method call handler of
an interface which has no properties (since it will not be expecting
this).

Add a check to make sure that there is at least one readable property
before assuming that a NULL get_property handler implies that we want to
handle properties asynchronously.

Add a testcase that was failing before the change and works after it.

https://bugzilla.gnome.org/show_bug.cgi?id=703437
2013-07-01 23:36:30 -04:00
Ryan Lortie
f754c4e85b GDBusConnection: allow async property handling
The existing advice in the documentation to "simply" register the
"org.freedesktop.DBus.Properties" interface if you want to handle
properties asynchronously is pretty unreasonable.  If you want to handle
this interface you have to deal with all properties for all interfaces
on the path, and you have to do all of the checking for yourself.  You
also have to provide your own introspection data.

Introduce a new convention for dealing with properties asynchronously.

If the user provides NULL for their get_property() or set_property()
functions in the vtable and has properties registered then the
properties are sent to the method_call() handler.  We get lucky here
that this function takes an "interface_name" parameter that we can set
to "org.freedesktop.DBus.Properties".

We also do the user the favour of setting the GDBusPropertyInfo on the
GDBusMethodInvocation for their convenience (for much the same reasons
as they might want the already-available GDBusMethodInfo).

Add a testcase as well as a bunch of documentation about this new
feature.

https://bugzilla.gnome.org/show_bug.cgi?id=698375
2013-06-22 13:38:31 -04:00
Ryan Lortie
c691f7b6ca GDBusMethodInvocation: add 'property_info'
Add a field on GDBusMethodInvocation for GDBusPropertyInfo.

For now, it is always %NULL.  It will be set in future patches.

https://bugzilla.gnome.org/show_bug.cgi?id=698375
2013-06-22 13:38:31 -04:00
Ryan Lortie
14dc028003 GDBusConnection: some straight-up refactoring
Separate the code for validating a method call from the code for
actually scheduling it for dispatch.

This will allow property Get/Set/GetAll calls to be dispatched to the
method_call handler without duplicating a lot of code.

https://bugzilla.gnome.org/show_bug.cgi?id=698375
2013-06-22 13:38:30 -04:00
Ryan Lortie
02f5cdd983 GDBusConnection: move 'Set' typecheck to worker
We presently do a lot of checks on property sets (signature check,
correct interface, property exists, etc.) from the worker thread before
dispatching the call to the user's thread.  The typecheck, however, is
saved until just before calling the user's vfunc, in their thread.

My best guess is that this was done to save having to unpack the value
from the tuple twice (since we don't unpack it until we're just about
the call the user).

This patch moves the check to the same place as all of the other checks.

The purpose of this change is to allow for sharing this check with the
(soon-to-be-introduced) case of handing property sets from
method_call().

This change has a minor side effect: error messages generated by sending
invalid values to property sets are no longer guaranteed to be correctly
ordered with respect to the void returns from successful property sets.
They will instead be correctly ordered with respect to the other error
messages.

https://bugzilla.gnome.org/show_bug.cgi?id=698375
2013-06-22 13:37:54 -04:00
Ryan Lortie
0d29b17af7 GDBusConnection: remove an unused g_variant_get()
https://bugzilla.gnome.org/show_bug.cgi?id=698375
2013-06-22 13:36:51 -04:00
Dan Winship
4b94c0831e Use 'dumb quotes' rather than `really dumb quotes'
Back in the far-off twentieth century, it was normal on unix
workstations for U+0060 GRAVE ACCENT to be drawn as "‛" and for U+0027
APOSTROPHE to be drawn as "’". This led to the convention of using
them as poor-man's ‛smart quotes’ in ASCII-only text.

However, "'" is now universally drawn as a vertical line, and "`" at a
45-degree angle, making them an `odd couple' when used together.

Unfortunately, there are lots of very old strings in glib, and also
lots of new strings in which people have kept up the old tradition,
perhaps entirely unaware that it used to not look stupid.

Fix this by just using 'dumb quotes' everywhere.

https://bugzilla.gnome.org/show_bug.cgi?id=700746
2013-05-21 11:23:22 -03:00
Lars Uebernickel
00f6d78125 g_dbus_connection_signal_subscribe: add path and namespace matching
https://bugzilla.gnome.org/show_bug.cgi?id=695156
2013-04-08 15:59:39 +02:00
Thomas Bechtold
c9a3cd6d8b Fix gdbus connection annotations
g_dbus_connection_call_with_unix_fd_list_sync () and
g_dbus_connection_call_sync () should allow None for the
bus_name parameter.

https://bugzilla.gnome.org/show_bug.cgi?id=683771

Signed-off-by: Richard Hughes <richard@hughsie.com>
2012-09-11 13:16:32 +01:00
Phil Clayton
02eed18a4e Add missing annotation to GDBusConnection::closed
Add annotation (allow-none) to the parameter error.

https://bugzilla.gnome.org/show_bug.cgi?id=677952
2012-06-23 17:54:33 -04:00
Tomas Bzatek
032e8dabd1 gdbus: Implement g_dbus_connection_get_last_serial()
This patch brings an ability to retrieve serial number of the last
message sent within the current thread.

https://bugzilla.gnome.org/show_bug.cgi?id=676825
2012-06-06 19:44:39 +02:00
Xavier Claessens
2e3d50631f Add private _g_bus_get_singleton_if_exists() function
This is used by g_test_dbus_down() to ensure the GDBusConnection
gets disposed, but not create one if the singleton already got
disposed.

https://bugzilla.gnome.org/show_bug.cgi?id=672985
2012-04-19 10:06:21 +02:00
David Zeuthen
26d4da2352 Revert "Add private _g_bus_get_singleton_if_exists() function"
This reverts commit f8a8e90398.
2012-04-18 13:48:09 -04:00
Xavier Claessens
f8a8e90398 Add private _g_bus_get_singleton_if_exists() function
This is used by g_test_dbus_down() to ensure the GDBusConnection
gets disposed, but not create one if the singleton already got
disposed.

https://bugzilla.gnome.org/show_bug.cgi?id=672985
2012-04-18 11:19:13 -04:00
David Zeuthen
ce81bd87c5 GDBusAuthObserver: Add a way to control what authentication mechanisms to use
This is related to https://bugzilla.gnome.org/show_bug.cgi?id=673943
but also useful in a lot of other contexts.
2012-04-14 11:52:20 -04:00
Robert Ancell
4143842eb4 Add missing allow-none annotations for function parameters.
Found using:
find . -name '*.c' | xargs grep 'or %NULL' | grep ' \* @' | grep -v '@error' | grep -v allow-none
2012-03-31 20:34:28 +11:00
Marco Trevisan (Treviño)
322c6e9344 GDBusConnection: Avoid dereferencing vtable for unregistered objects
https://bugzilla.gnome.org/show_bug.cgi?id=671988

Signed-off-by: David Zeuthen <davidz@redhat.com>
2012-03-19 17:12:00 -04:00
Ryan Lortie
2afbc425eb GDBus: set no-reply flag on calls with no callback
If g_dbus_connection_call() or g_dbus_proxy_call() are given a NULL
callback then set the no-reply flag on the outgoing D-Bus message.

https://bugzilla.gnome.org/show_bug.cgi?id=672239
2012-03-19 12:41:23 -04:00
David Zeuthen
f025c9c4f4 GDBusConnection: Don't store GCancellable in qdata
Now that we're using g_simple_async_result_set_check_cancellable() we
no longer need this terrible hack of carrying the GCancellable on the
GSimpleAsyncResult using qdata. See bug 672013 for more details.

https://bugzilla.gnome.org/show_bug.cgi?id=672013

Signed-off-by: David Zeuthen <davidz@redhat.com>
2012-03-15 14:04:39 -04:00
Ryan Lortie
e3c7fdd7a4 GDBus: make use of reliable async cancellation
Call g_simple_async_result_set_check_cancellable() after all
GSimpleAsyncResult creation in order to take advantage of the new
reliable cancellation feature.

The guarantee of reliable cancellation fixes a bug in dbusmenu (which
was already assuming that cancellation was reliable).  See this bug:
https://bugs.launchpad.net/ubuntu/+source/libdbusmenu/+bug/953562

https://bugzilla.gnome.org/show_bug.cgi?id=672013

Signed-off-by: David Zeuthen <davidz@redhat.com>
2012-03-15 14:01:35 -04:00
David Zeuthen
7a4a973cfd GDBusConnection: Don't leak message reply in error path
This was reported in bug 670909.

https://bugzilla.gnome.org/show_bug.cgi?id=670909

Signed-off-by: David Zeuthen <davidz@redhat.com>
2012-02-27 14:53:13 -05:00
David King
8ee2cadd7f docs: Fix some GDBusConnection typos 2012-02-21 01:10:54 +01:00
Will Thompson
7a0bddd768 GDBusConnection: note that exit-on-close is sometimes TRUE
g_bus_get_finish() and g_bus_get_sync() both document that the returned
object will usually have exit-on-close set to TRUE, but the property's
documentation specified that its default is FALSE. While that's
technically true from a GObject perspective, it's not accurate from the
API user's perspective.

https://bugzilla.gnome.org/show_bug.cgi?id=668163

Reviewed-by: Simon McVittie <simon.mcvittie@collabora.co.uk>
Reviewed-by: David Zeuthen <zeuthen@gmail.com>
2012-01-18 16:16:58 +00:00
Simon McVittie
1e09bfc77c GDBusConnection: use GWeakRef to make the singletons thread-safe
Bug: https://bugzilla.gnome.org/show_bug.cgi?id=665211

https://bugzilla.gnome.org/show_bug.cgi?id=548954
2012-01-02 12:23:24 -05:00
David Zeuthen
70dacf83d2 Bug 665733 – GDBusConnection holds lock while calling destroynotify
Fix this problem by always running the destroynotify from an idle.

https://bugzilla.gnome.org/show_bug.cgi?id=665733

Signed-off-by: David Zeuthen <davidz@redhat.com>
2011-12-07 10:30:42 -05:00
Simon McVittie
83d0c8a739 GDBusConnection: propagate error correctly if flags are inappropriate
Previously, this would fail the assertion
"connection->initialization_error != NULL" after the label "out".

Bug: https://bugzilla.gnome.org/show_bug.cgi?id=665067
Signed-off-by: Simon McVittie <simon.mcvittie@collabora.co.uk>
Reviewed-by: David Zeuthen <davidz@redhat.com>
2011-12-05 18:15:19 +00:00
Simon McVittie
c4a11858cf GDBusConnection: don't pass boolean > 1 to _g_dbus_worker_new
This happens to work at the moment (because GDBusWorker.frozen is a
gboolean and not just a 1-bit bitfield), but isn't right: the gboolean
ends up with values 0 or G_DBUS_CONNECTION_FLAGS_DELAY_MESSAGE_PROCESSING
(which is more than 1).

Bug: https://bugzilla.gnome.org/show_bug.cgi?id=664558
Signed-off-by: Simon McVittie <simon.mcvittie@collabora.co.uk>
Reviewed-by: David Zeuthen <davidz@redhat.com>
2011-11-22 16:08:14 +00:00
Matthias Clasen
6c7387f6d1 Trivial doc typo fix 2011-11-19 16:23:33 -05:00
Simon McVittie
a124562d1b GDBusConnection: document that this object is (meant to be) thread-safe
Bug: https://bugzilla.gnome.org/show_bug.cgi?id=661992
Signed-off-by: Simon McVittie <simon.mcvittie@collabora.co.uk>
Reviewed-by: David Zeuthen <davidz@redhat.com>
2011-10-24 10:40:29 +01:00
Simon McVittie
a031bacaac GDBusConnection: make the closed flag atomic (but still lock to write)
Strictly speaking, neither of the two uses that aren't under the lock
*needs* to be atomic, but it seems better to be obviously correct (and
we save another 4 bytes of struct).

One of these uses is in g_dbus_connection_is_closed(), any use of which
is inherently a race condition anyway.

The other is g_dbus_connection_flush_sync, which as far as I can tell
just needs a best-effort check, to not waste effort on a connection that
has been closed for a while (but I could be wrong).

I removed the check for the closed flag altogether in
g_dbus_connection_send_message_with_reply_unlocked, because it turns out
to be redundant with one in g_dbus_connection_send_message_unlocked,
which is called immediately after.

g_dbus_connection_close_sync held the lock to check the closed flag,
which is no longer needed.

As far as I can tell, the only reason why the lock is still desirable
when setting the closed flag is so that remove_match_rule can't fail
by racing with close notification from the worker thread - but
on_worker_closed needs to hold the lock anyway, to deal with other
data structures, so there's no point in trying to eliminate the
requirement to hold the lock.

Bug: https://bugzilla.gnome.org/show_bug.cgi?id=661992
Signed-off-by: Simon McVittie <simon.mcvittie@collabora.co.uk>
Reviewed-by: David Zeuthen <davidz@redhat.com>
2011-10-24 10:40:26 +01:00
Simon McVittie
9857cf8c46 GDBusConnection: document which properties are protected by @lock
Also, a few that don't need to be.

Bug: https://bugzilla.gnome.org/show_bug.cgi?id=661992
Signed-off-by: Simon McVittie <simon.mcvittie@collabora.co.uk>
Reviewed-by: David Zeuthen <davidz@redhat.com>
2011-10-24 10:40:23 +01:00
Simon McVittie
8df114f597 GDBusConnection: access the exit-on-close flag atomically
This isn't strictly necessary, because in every location where it's
checked, if the reading thread misses an update from another thread,
it's indistinguishable from the reading thread having been scheduled
before the writing thread, which is an unavoidable race condition that
callers need to cope with anyway. On the other hand, merging exit_on_close
into atomic_flags gives the least astonishing semantics to library users
and saves 4 bytes of struct, and if you're accessing exit-on-close often
enough for it to be a performance concern, you're probably doing it wrong.

Bug: https://bugzilla.gnome.org/show_bug.cgi?id=661992
Signed-off-by: Simon McVittie <simon.mcvittie@collabora.co.uk>
Reviewed-by: David Zeuthen <davidz@redhat.com>
2011-10-24 10:40:20 +01:00
Simon McVittie
3a0b60647d Annotate GDBusConnection private functions with thread/lock status
The thread shared between all GDBusWorker instances was variously called
the "worker thread" or "message handler thread", which I mostly changed to
"the GDBusWorker thread" to avoid ambiguity.

Bug: https://bugzilla.gnome.org/show_bug.cgi?id=661992
Signed-off-by: Simon McVittie <simon.mcvittie@collabora.co.uk>
Reviewed-by: David Zeuthen <davidz@redhat.com>
2011-10-24 10:40:06 +01:00
Simon McVittie
848df03e16 GDBusConnection: check for initializedness in most public API
The only exceptions are those of the trivial getters/setters that don't
already need the initialization check for its secondary role as a memory
barrier (this is consistent with GSocket, where trivial getters/setters
don't check):

* g_dbus_connection_set_exit_on_close
* g_dbus_connection_get_exit_on_close
* g_dbus_connection_is_closed

g_dbus_connection_set_exit_on_close needs to be safe for
use before initialization anyway, so it can be set at construct-time.

Bug: https://bugzilla.gnome.org/show_bug.cgi?id=661689
Signed-off-by: Simon McVittie <simon.mcvittie@collabora.co.uk>
Reviewed-by: David Zeuthen <davidz@redhat.com>
2011-10-21 16:02:33 +01:00
Simon McVittie
3958a9fc1e GDBusConnection: document use while uninitialized as undefined behaviour
Bug: https://bugzilla.gnome.org/show_bug.cgi?id=661689
Bug: https://bugzilla.gnome.org/show_bug.cgi?id=662208
Signed-off-by: Simon McVittie <simon.mcvittie@collabora.co.uk>
Reviewed-by: David Zeuthen <davidz@redhat.com>
2011-10-21 16:02:31 +01:00
Simon McVittie
a7ea949294 GDBusConnection: check for initialization where needed for thread-safety
Also document which fields require such a check in order to have correct
threading semantics.

This usage doesn't matches the GInitable documentation, which suggests
use of a GError - but using an uninitialized GDBusConnection is
programming error, and not usefully recoverable. (The GInitable
documentation may have been a mistake - GNOME#662208.) Also, not all of
the places where we need it can raise a GError.

The check serves a dual purpose: it turns a non-deterministic crash into
a deterministic critical warning, and is also a memory barrier for
thread-safety. All of these functions dereference or return fields that
are meant to be protected by FLAG_INITIALIZED, so they could crash or
return an undefined value to their caller without this, if called from a
thread that isn't the one that called initable_init() (although I can't
think of any way to do that without encountering a memory barrier,
undefined behaviour, or a race condition that leads to undefined
behaviour if the non-initializing thread wins the race).

One exception is that initable_init() itself makes a synchronous call.
We deal with that by passing new internal flags up the call stack, to
reassure g_dbus_connection_send_message_unlocked() that it can go ahead.

Bug: https://bugzilla.gnome.org/show_bug.cgi?id=661689
Bug: https://bugzilla.gnome.org/show_bug.cgi?id=661992
Signed-off-by: Simon McVittie <simon.mcvittie@collabora.co.uk>
Reviewed-by: David Zeuthen <davidz@redhat.com>
2011-10-21 16:02:27 +01:00
Simon McVittie
245d68be6f GDBusConnection: replace is_initialized with an atomic flag
The comment implied that even failed initialization would set
is_initialized = TRUE, but this wasn't the case - failed initialization
would only set initialization_error, and it was necessary to check both.

It turns out the documented semantics are nicer than the implemented
semantics, since this lets us use atomic operations, which are also
memory barriers, to avoid needing separate memory barriers or locks
for initialization_error (and other members that are read-only after
construction).

I expect to need more than one atomically-accessed flag to fix thread
safety, so instead of a minimal implementation I've turned is_initialized
into a flags word.

Signed-off-by: Simon McVittie <simon.mcvittie@collabora.co.uk>
Bug: https://bugzilla.gnome.org/show_bug.cgi?id=661689
Bug: https://bugzilla.gnome.org/show_bug.cgi?id=661992
Reviewed-by: David Zeuthen <davidz@redhat.com>
2011-10-21 16:02:22 +01:00
Simon McVittie
a7143a0e9f GDBusConnection: warn that direct access to the stream is a bad idea
Bug: https://bugzilla.gnome.org/show_bug.cgi?id=661679
Signed-off-by: Simon McVittie <simon.mcvittie@collabora.co.uk>
2011-10-15 18:03:19 -04:00
David Zeuthen
3c4d3dec09 GDBusConnection: Make pending calls error when the connection is lost
If the connection to the bus is lost while a method call is ongoing,
the method call does not get cancelled. Instead it just sits around
until it times out.

This is visible here on XO laptops when stopping the display manager
during shutdown. imsettings starts sending a sync message to give up
its bus name (via g_bus_unown_name()), then systemd terminates the
session bus at approximately the same time. imsettings then hangs for
about 20 seconds before timing out the message.

 http://lists.freedesktop.org/archives/dbus/2011-September/014717.html

imsettings behaviour could be improved as described in that thread,
but I think this is a glib bug. I've also come up with the attached
patch which fixes it.

Credits for the bug-fix goes to Daniel Drake <dsd@laptop.org>. The test
case was written by David Zeuthen <zeuthen@gmail.com>.

https://bugzilla.gnome.org/show_bug.cgi?id=660637

Signed-off-by: David Zeuthen <davidz@redhat.com>
2011-10-07 14:23:03 -04:00
Dan Winship
59f1f54655 Add g_main_context_ref_thread_default()
Add g_main_context_ref_thread_default(), which always returns a
reffed GMainContext, rather than sometimes returning a (non-reffed)
GMainContext, and sometimes returning NULL. This simplifies the
bookkeeping in any code that needs to keep a reference to the
thread-default context for a while.

https://bugzilla.gnome.org/show_bug.cgi?id=660994
2011-10-07 10:14:34 -04:00
Ryan Lortie
5f48e2cde5 GDBus: switch to struct-embedded GMutex and GCond
Now that we have those, we should use them.

https://bugzilla.gnome.org/show_bug.cgi?id=660739
2011-10-04 11:13:46 -04:00
Simon McVittie
8097e2de85 GDBusConnection: delegate to the worker to close the stream
We can't safely close the output part of the I/O stream until any
pending write or flush has been completed. In the worst case, this could
lead to an assertion failure in the worker (when the close wins the
race) or not closing the stream at all (when the write wins the race).

Bug: https://bugzilla.gnome.org/show_bug.cgi?id=651268
Bug-NB: NB#271520
Signed-off-by: Simon McVittie <simon.mcvittie@collabora.co.uk>
Signed-off-by: David Zeuthen <davidz@redhat.com>
2011-09-16 12:00:22 -04:00
Matthias Clasen
1b28408b8b Spelling fixes
Spelling fixes in comments and docs, provided by
Kjartan Maraas in bug 657336.
2011-08-29 14:49:32 -04:00
Brian Cameron
b5f1ea4bb1 void functions should not return. Fixes bug #656675. 2011-08-17 03:01:14 -05:00
Martin Pitt
c783bfd4e7 [gi] Add missing (allow-none) annotations to g_dbus_connection_register_object() 2011-08-09 14:52:53 +02:00
David Zeuthen
659ba3d0b3 GDBusConnection: Only apply exit-on-closed semantics if properly initialized
Otherwise there is no point in gracefully handling the error...

https://bugzilla.gnome.org/show_bug.cgi?id=655664

Signed-off-by: David Zeuthen <davidz@redhat.com>
2011-08-01 11:58:05 -04:00
David Zeuthen
32b1349a23 More fixes for non-Unix builds
Signed-off-by: David Zeuthen <davidz@redhat.com>
2011-07-25 10:31:17 -04:00
David Zeuthen
f8b98841ad Fix the build on non-Unix
https://bugzilla.gnome.org/show_bug.cgi?id=655148

Signed-off-by: David Zeuthen <davidz@redhat.com>
2011-07-25 09:56:01 -04:00
Matthias Clasen
1f9e84896b Fix a typo 2011-07-23 21:07:48 -04:00
David Zeuthen
c404dbed11 gdbus-codegen: Add support for new org.gtk.GDBus.C.UnixFD annotation
Also add convenience _with_unix_fd_list variants to GDBusConnection,
GDBusProxy and GDBusMethodInvocation types to easily support this.

Signed-off-by: David Zeuthen <davidz@redhat.com>
2011-07-21 16:06:18 -04:00
Johan Dahlin
ec98953e42 Pass in NULL instead of g_cclosure_marshal_generic
NULL is now a shortcut for g_cclosure_marshal_generic, so avoid
referencing it directly.

https://bugzilla.gnome.org/show_bug.cgi?id=654917
2011-07-19 14:38:34 -03:00
Ryan Lortie
58c247e51b GVariant: add g_variant_take_ref()
This function implements the following logic:

  if (g_variant_is_floating (value))
    g_variant_ref_sink (value);

which is used for consuming the return value of callbacks that may or
may not return floating references.

This patch also replaces a few instances of the above code with the new
function (GSettings, GDBus) and lifts a long-standing restriction on the
use of floating values as the return value for signal handlers by
improving g_value_take_variant().

https://bugzilla.gnome.org/show_bug.cgi?id=627974
2011-07-12 19:44:21 +02:00
Colin Walters
b74e2a720a Stop using glib-genmarshal at build time
To help cross compilation, don't use glib-genmarshal in our
build.  This is easy now that we have g_cclosure_marshal_generic().

In gobject/, add gmarshal.[ch] to git (making the existing entry
points stubs).

In gio/, simply switch to using g_cclosure_marshal_generic().

https://bugzilla.gnome.org/show_bug.cgi?id=652168
2011-06-20 17:24:07 -04:00
Matthias Clasen
339cac8fc7 Remove unneeded NULL check
We ensure 10 lines up that parameters is not NULL.
2011-06-14 09:53:26 -04:00
Matthias Clasen
01f63b19f9 Fix links in gio docs 2011-06-04 18:48:19 -04:00
David Zeuthen
b9e3e03767 GDBusConnection: Document that sockets are frobbed into non-blocking mode
Signed-off-by: David Zeuthen <davidz@redhat.com>
2011-05-12 15:36:34 -04:00
Martin Pitt
21c2291496 [gi] Add missing allow-none annotations to GDBusConnection 2011-05-08 23:07:40 +02:00
Matthias Clasen
122a53a9bc Fix up some harmless FALSE <> NULL confusions
Reported in bug 643134.
2011-04-26 22:51:54 -04:00
Colin Walters
68b16deb1f gdbusconnection: Avoid tripping assertion if we fail to authenticate twice
If g_bus_get_sync() fails in authentication (because e.g. the process
uid, doesn't match the expected in EXTERNAL), a secondary call to
g_bus_get_sync() would notice we aren't initialized, and try
to initialize.

The assertion here is just wrong; we now explicitly and clearly handle
both cases where we already have an error, or we already succeeded.

https://bugzilla.gnome.org/show_bug.cgi?id=635694
2011-04-13 15:01:28 -04:00
David Zeuthen
0729260141 Silence a bunch of -Wunused-but-set-variable warnings
Signed-off-by: David Zeuthen <davidz@redhat.com>
2011-04-08 15:44:25 -04:00
Matthias Clasen
a2e3a4d150 Add a warning to the g_dbus_connection_set_exit_on_close docs
Tell people to not leak their apps out of the session.
2011-04-07 17:15:41 -04:00
David Zeuthen
91f97ebbaa GDBusConnection: Make interface lookups O(1)
Signed-off-by: David Zeuthen <davidz@redhat.com>
2011-03-28 11:39:22 -04:00
Matthias Clasen
5df049706f Don't report standard interfaces more than once
If they have a custom implementation, don't add the canned
introspection XML, just rely on the generated XML. Fixes
https://bugzilla.gnome.org/show_bug.cgi?id=642042
2011-02-15 19:50:55 -05:00
Peng Huang
735fcf918e Bug 632544 – Cannot send a locked message with PRESERVE_SERIAL flag
https://bugzilla.gnome.org/show_bug.cgi?id=632544

Signed-off-by: David Zeuthen <davidz@redhat.com>
2010-12-13 13:09:38 -05:00
Ryan Lortie
71088701af Add G_DBUS_SIGNAL_FLAGS_NO_MATCH_RULE
If specified, the signal subscription is setup client-side but the match
rule is not sent to the server.  This allows the caller to manually
register more detailed match rules.
2010-11-06 17:35:10 -04:00
Christian Persch
9e0c07870a Use g_simple_async_result_{new_,}take_error
Bug #633685.
2010-11-03 14:25:35 +01:00
Ryan Lortie
fac2a8278e Bug 633356 - (GDBus) Make G_MAXINT mean no timeout
Don't register a timeout function in the case that G_MAXINT is given for
the timeout length.
2010-10-28 16:47:13 -04:00
Johan Dahlin
30132c44c1 Add a lot of missing annotations 2010-09-24 18:24:41 -03:00
David Zeuthen
4d9ae95ae0 GDBus: Don't use abstract sockets in test code
It doesn't really work right now because of a dbus-daemon(1) bug - see
the comment added in the TODO section of gdbusconnection.c. So revert
to old behavior. The downside is a lot of files in /tmp but right now
that's better than not being able to run tests in a loop.

Signed-off-by: David Zeuthen <davidz@redhat.com>
2010-09-23 19:16:25 -04:00
David Zeuthen
7036415cc1 GDBusConnection: Use correct GMainContext when invoking free functions
Without this fix, the ./gdbus-connection test case occasionally fails, see

 https://bugzilla.gnome.org/show_bug.cgi?id=629945#c5

like this

 /gdbus/connection/basic: OK
 /gdbus/connection/life-cycle: **
ERROR:gdbus-connection.c:223:test_connection_life_cycle: assertion failed:
(!quit_mainloop_fired)
 cleaning up bus with pid 21794
 Aborted (core dumped)

because the callback didn't happen on the same thread as where we are
running the loop.

Signed-off-by: David Zeuthen <davidz@redhat.com>
2010-09-23 17:36:07 -04:00
David Zeuthen
f0b04acfd3 GDBusConnection: Avoid callbacks on finalized connection
Turns out that GDBusWorker will issue callbacks (in its own thread)
even after g_dbus_worker_stop() has been called. This would rarely
happen (and unreffing a connection is even rarer) so only saw this bug
occasionally when running the gdbus-connection test case in a loop.

Fix up this issue by maintaining a set of GDBusConnection objects that
are currently "alive" and do nothing in the callbacks if the passed
user_data pointer is not in this set.

Also attempted to fix up a race condition with
_g_object_wait_for_single_ref_do() and its use of GObject toggle
references - for now, just resort to busy waiting, thereby
sidestepping the toggle reference mess altogether.

Signed-off-by: David Zeuthen <davidz@redhat.com>
2010-09-23 15:16:56 -04:00
Christian Persch
1220501ec8 GDBusConnection leaks its GCredentials
==7269== 144 bytes in 6 blocks are definitely lost in loss record 1,282 of 1,325
==7269==    at 0x4005BDC: malloc (vg_replace_malloc.c:195)
==7269==    by 0x4056B74: g_malloc (gmem.c:164)
==7269==    by 0x406EDB6: g_slice_alloc (gslice.c:842)
==7269==    by 0x406EDFB: g_slice_alloc0 (gslice.c:854)
==7269==    by 0x413C627: g_type_create_instance (gtype.c:1867)
==7269==    by 0x412276A: g_object_constructor (gobject.c:1480)
==7269==    by 0x4121E5D: g_object_newv (gobject.c:1264)
==7269==    by 0x4121BD3: g_object_new (gobject.c:1176)
==7269==    by 0x417CFB9: g_credentials_new (gcredentials.c:156)
==7269==    by 0x41D9DBC: g_unix_credentials_message_deserialize (gunixcredentialsmessage.c:149)
==7269==    by 0x41C422C: g_socket_control_message_deserialize (gsocketcontrolmessage.c:198)
==7269==    by 0x41BFCE3: g_socket_receive_message (gsocket.c:3289)
==7269==    by 0x41D99CE: g_unix_connection_receive_credentials (gunixconnection.c:476)
==7269==    by 0x41FA829: _g_dbus_auth_run_server (gdbusauth.c:987)
==7269==    by 0x4205DDB: initable_init (gdbusconnection.c:2196)

Bug #629689.
2010-09-14 22:22:35 +02:00
David Zeuthen
c3371efcaa Bug 624546 – Modification of GDBusMessage in filter function
Rework filter functions as per

 https://bugzilla.gnome.org/show_bug.cgi?id=624546#c8

This commit breaks ABI. However, this ABI break affects only
applications using filter functions. The only known user of is dconf.

Signed-off-by: David Zeuthen <davidz@redhat.com>
2010-09-09 13:21:35 -04:00
Christian Persch
e8fc3ba3d0 Plug a mem leak
Don't leak the ptr arrays in the map_sender_unique_name_to_signal_data_array
hash table.

==23440== 84 (20 direct, 64 indirect) bytes in 1 blocks are definitely lost in loss record 920 of 993
==23440==    at 0x4005BDC: malloc (vg_replace_malloc.c:195)
==23440==    by 0x4057094: g_malloc (gmem.c:134)
==23440==    by 0x406F2D6: g_slice_alloc (gslice.c:836)
==23440==    by 0x401D2D0: g_ptr_array_sized_new (garray.c:799)
==23440==    by 0x401D2AC: g_ptr_array_new (garray.c:783)
==23440==    by 0x420834A: g_dbus_connection_signal_subscribe (gdbusconnection.c:3084)

Bug #628436.
2010-09-03 15:19:22 -04:00
Christian Persch
8795f52aae Plug a mem leak
==31063== 98 (24 direct, 74 indirect) bytes in 1 blocks are definitely lost in loss record 946 of 1,136
==31063==    at 0x4005BDC: malloc (vg_replace_malloc.c:195)
==31063==    by 0x4057094: g_malloc (gmem.c:134)
==31063==    by 0x406F2D6: g_slice_alloc (gslice.c:836)
==31063==    by 0x4092383: g_variant_get_child_value (gvariant-core.c:847)
==31063==    by 0x408BE9E: g_variant_get_variant (gvariant.c:709)
==31063==    by 0x40903F5: g_variant_valist_get_nnp (gvariant.c:3767)
==31063==    by 0x40907A9: g_variant_valist_get_leaf (gvariant.c:3884)
==31063==    by 0x4090D10: g_variant_valist_get (gvariant.c:4065)
==31063==    by 0x4090E59: g_variant_valist_get (gvariant.c:4100)
==31063==    by 0x40911B6: g_variant_get_va (gvariant.c:4296)
==31063==    by 0x40910BC: g_variant_get (gvariant.c:4248)
==31063==    by 0x4208DAF: invoke_set_property_in_idle_cb (gdbusconnection.c:3676)

Bug #628346.
2010-09-03 15:16:47 -04:00
David Zeuthen
0d0a9bb448 GDBusConnection: Document memory management semantics for get_property()
Turns out we are leaking non-floating GVariant instances returned by
get_property() functions.

Also avoid imprecise language such as "newly-allocated GVariant" as
this doesn't specify whether the variant can be floating or not.

Also see https://bugzilla.gnome.org/show_bug.cgi?id=627974 as it is
very related to this change.

Signed-off-by: David Zeuthen <davidz@redhat.com>
2010-08-25 14:49:05 -04:00
David Zeuthen
847e4dfe7d GDBusMethodInvocation: nuke constructor
... that is, make it private. This makes sense because users are never
expected to create such objects themselves - only the GDBus core will
need this.

Signed-off-by: David Zeuthen <davidz@redhat.com>
2010-08-22 22:58:29 -04:00
David Zeuthen
3ff9894826 Bug 624546 – Modification of GDBusMessage in filter function
Allow modifying a GDBusMessage in a filter function and also add tests
for this. This breaks API but leaves ABI (almost) intact - at least
dconf's GSettings backend (the only big user I know of) will keep
working.

https://bugzilla.gnome.org/show_bug.cgi?id=624546

Signed-off-by: David Zeuthen <davidz@redhat.com>
2010-08-05 20:37:27 -04:00
David Zeuthen
d52e1c33f7 GDBus: Add `return' debug option
This prints all GDBusMethodInvocation API usage and is normally used
with the `incoming' option. Example:

 # G_DBUS_DEBUG=incoming,return ./polkitd --replace
 Entering main event loop
 Connected to the system bus
 Registering null backend at priority -10
 [...]
 Acquired the name org.freedesktop.PolicyKit1
 [...]

 ========================================================================
 GDBus-debug:Incoming:
  <<<< METHOD INVOCATION org.freedesktop.PolicyKit1.Authority.RegisterAuthenticationAgent()
       on object /org/freedesktop/PolicyKit1/Authority
       invoked by name :1.26
       serial 299
 ========================================================================
 GDBus-debug:Return:
  >>>> METHOD ERROR org.freedesktop.PolicyKit1.Error.Failed
       message `Cannot determine session the caller is in'
       in response to org.freedesktop.PolicyKit1.Authority.RegisterAuthenticationAgent()
       on object /org/freedesktop/PolicyKit1/Authority
       to name :1.26
       reply-serial 299

 [...]

 ========================================================================
 GDBus-debug:Incoming:
  <<<< METHOD INVOCATION org.freedesktop.PolicyKit1.Authority.RegisterAuthenticationAgent()
       on object /org/freedesktop/PolicyKit1/Authority
       invoked by name :1.2402
       serial 25
 ========================================================================
 GDBus-debug:Return:
  >>>> METHOD RETURN
       in response to org.freedesktop.PolicyKit1.Authority.RegisterAuthenticationAgent()
       on object /org/freedesktop/PolicyKit1/Authority
       to name :1.2402
       reply-serial 25

Signed-off-by: David Zeuthen <davidz@redhat.com>
2010-08-04 16:59:26 -04:00
David Zeuthen
89a1b571ad GDBusMessage: Validate header fields when serializing/deserializing
The D-Bus spec mentions exactly what header fields are required for
various message types. Add tests for this as well.

Also disallow empty interfaces for signals since the D-Bus spec says
this is Verboten already.

Signed-off-by: David Zeuthen <davidz@redhat.com>
2010-08-04 14:38:51 -04:00
David Zeuthen
f5cd8ddeaa GDBusConnection: Debug messages when receiving signals and method invocations
Spell out "RECEIVED SIGNAL" instead of "SIGNAL" to emphasize this is
about receiving a signal, not emitting one (which is "SIGNAL
EMISSION"). Also make the "arrows" point in the "right" direction
("<<<<" vs ">>>>") - like this:

 ========================================================================
 GDBus-debug:Signal:
  <<<< RECEIVED SIGNAL org.freedesktop.DBus.NameOwnerChanged
       on object /org/freedesktop/DBus
       sent by name org.freedesktop.DBus

and

 ========================================================================
 GDBus-debug:Incoming:
  <<<< METHOD INVOCATION org.freedesktop.PolicyKit1.Authority.EnumerateTemporaryAuthorizations()
       on object /org/freedesktop/PolicyKit1/Authority
       invoked by name :1.2176

Signed-off-by: David Zeuthen <davidz@redhat.com>
2010-08-03 15:36:16 -04:00
David Zeuthen
6a492a4519 GDBus: If exiting b/c remote peer disconnected and error is set, print it
This should make things easier to debug:

  g_dbus_connection_real_closed: Remote peer vanished with error:
  Underlying GIOStream returned 0 bytes on an async read
  (g-io-error-quark, 0). Exiting.

Signed-off-by: David Zeuthen <davidz@redhat.com>
2010-08-03 12:24:48 -04:00
Carlos Garcia Campos
892012b951 GDBusConnection: fix message flags in g_dbus_connection_call_sync()
GDBusCallFlags were used instead of GDBusSendMessageFlags for
g_dbus_connection_send_message_with_reply_sync(). Fixes bug #625753.
2010-08-01 17:27:58 +02:00
Matthias Clasen
116b945c94 Fix a typo
Its credentials, not crendentials
2010-07-30 23:44:30 -04:00
David Zeuthen
d2d97a214d Bug 625584 – Crashes application on unref with signal subscription
Don't do too much work in the finalizer - in particular, there's no
need to send RemoveMatch() messages to the bus daemon since we're
going to sever the connection and the bus will garbage collect
anyway. In this case it crashed the process.

Also add a test case that checks that the appropriate GDestroyNotify
callbacks are called when unreffing a connection with either 1)
exported objects; 2) signal subscriptions or 3) filter functions
.. yes, ideally apps would unregister such callbacks before giving up
their ref but that's not how things work :-)

Signed-off-by: David Zeuthen <davidz@redhat.com>
2010-07-30 16:06:18 -04:00
David Zeuthen
14f17c1388 GDBusConnection: Fix up debug output when completing calls
Signed-off-by: David Zeuthen <davidz@redhat.com>
2010-07-30 11:40:00 -04:00
David Zeuthen
133e87ca87 GDBusConnection: Pass the GObject to g_simple_async_result_new()
Signed-off-by: David Zeuthen <davidz@redhat.com>
2010-07-28 12:51:09 -04:00
David Zeuthen
493d8cb292 GDBus: Introduce G_DBUS_SEND_MESSAGE_FLAGS_PRESERVE_SERIAL
This is preferable to the current magical solution whereby the serial
is only rewritten if non-zero. In particular, it makes it easier to
send the same message on multiple connections without having to reset
the serial number.

Signed-off-by: David Zeuthen <davidz@redhat.com>
2010-07-19 17:05:28 -04:00
David Zeuthen
0b2b4deac5 GDBus: Add GDBusSendMessageFlags
This is currently unused but might be useful in the future. For
example, it might be nice with a way to bypass the current queue of
outgoing messages - having a flag enumeration allows us to add a
G_DBUS_SEND_MESSAGE_FLAGS_BYPASS_QUEUE etc. etc.

This commit breaks ABI and API. Users of the (rarely used) API to send
messages will have to port to this new API.

Signed-off-by: David Zeuthen <davidz@redhat.com>
2010-07-19 16:07:57 -04:00
David Zeuthen
7190af4394 GDBus: Remove constness from introspection data structures
Signed-off-by: David Zeuthen <davidz@redhat.com>
2010-07-19 15:45:27 -04:00
David Zeuthen
4a1c5a1b98 GDBus: Add GDBusSignalFlags and use it in g_dbus_connection_signal_subscribe()
This is currently unused but will probably be useful in the
future. For example, we could have a _ARG0_IS_PATH to specify that
arg0 should be used for arg0path.

This commit breaks API and ABI. Users of
g_dbus_connection_signal_subscribe() will need to port to this new
version.

Signed-off-by: David Zeuthen <davidz@redhat.com>
2010-07-19 15:05:10 -04:00