2002-12-16 Anders Carlsson <andersca@codefactory.se>
* Makefile.am:
* configure.in:
Add GLib checks and fixup .pc files
* glib/Makefile.am:
* glib/dbus-glib.h:
* glib/dbus-gmain.c: (gdbus_connection_prepare),
(gdbus_connection_check), (gdbus_connection_dispatch),
(gdbus_add_connection_watch), (gdbus_remove_connection_watch),
(dbus_connection_gsource_new):
* glib/dbus-gthread.c: (dbus_gmutex_new), (dbus_gmutex_free),
(dbus_gmutex_lock), (dbus_gmutex_unlock), (dbus_gthread_init):
* glib/test-dbus-glib.c: (message_handler), (main):
Add GLib support.
2002-12-16 00:26:05 +00:00
|
|
|
/* -*- mode: C; c-file-style: "gnu" -*- */
|
|
|
|
|
/* dbus-gmain.c GLib main loop integration
|
|
|
|
|
*
|
2004-06-20 15:28:15 +00:00
|
|
|
* Copyright (C) 2002, 2003 CodeFactory AB
|
2005-01-30 18:25:14 +00:00
|
|
|
* Copyright (C) 2005 Red Hat, Inc.
|
2002-12-16 Anders Carlsson <andersca@codefactory.se>
* Makefile.am:
* configure.in:
Add GLib checks and fixup .pc files
* glib/Makefile.am:
* glib/dbus-glib.h:
* glib/dbus-gmain.c: (gdbus_connection_prepare),
(gdbus_connection_check), (gdbus_connection_dispatch),
(gdbus_add_connection_watch), (gdbus_remove_connection_watch),
(dbus_connection_gsource_new):
* glib/dbus-gthread.c: (dbus_gmutex_new), (dbus_gmutex_free),
(dbus_gmutex_lock), (dbus_gmutex_unlock), (dbus_gthread_init):
* glib/test-dbus-glib.c: (message_handler), (main):
Add GLib support.
2002-12-16 00:26:05 +00:00
|
|
|
*
|
2004-08-10 03:07:01 +00:00
|
|
|
* Licensed under the Academic Free License version 2.1
|
2002-12-16 Anders Carlsson <andersca@codefactory.se>
* Makefile.am:
* configure.in:
Add GLib checks and fixup .pc files
* glib/Makefile.am:
* glib/dbus-glib.h:
* glib/dbus-gmain.c: (gdbus_connection_prepare),
(gdbus_connection_check), (gdbus_connection_dispatch),
(gdbus_add_connection_watch), (gdbus_remove_connection_watch),
(dbus_connection_gsource_new):
* glib/dbus-gthread.c: (dbus_gmutex_new), (dbus_gmutex_free),
(dbus_gmutex_lock), (dbus_gmutex_unlock), (dbus_gthread_init):
* glib/test-dbus-glib.c: (message_handler), (main):
Add GLib support.
2002-12-16 00:26:05 +00:00
|
|
|
*
|
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
|
* (at your option) any later version.
|
|
|
|
|
*
|
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
|
*
|
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
|
|
|
*
|
|
|
|
|
*/
|
|
|
|
|
|
2003-09-01 18:02:06 +00:00
|
|
|
#include <config.h>
|
2004-06-20 15:28:15 +00:00
|
|
|
#include <dbus/dbus-glib.h>
|
|
|
|
|
#include <dbus/dbus-glib-lowlevel.h>
|
2003-09-01 18:02:06 +00:00
|
|
|
#include "dbus-gtest.h"
|
2004-06-20 15:28:15 +00:00
|
|
|
#include "dbus-gutils.h"
|
2005-06-12 Colin Walters <walters@verbum.org>
Async signals and various bugfixes and testing by
Ross Burton <ross@burtonini.com>.
* glib/dbus-gvalue.h: (struct DBusBasicGValue): Delete.
(dbus_gvalue_genmarshal_name_from_type)
(dbus_gvalue_ctype_from_type): Moved to dbus-binding-tool-glib.c.
(dbus_gtype_to_dbus_type): Renamed to dbus_gtype_from_signature.
(dbus_g_value_types_init, dbus_gtype_from_signature)
(dbus_gtype_from_signature_iter, dbus_gtype_to_signature)
(dbus_gtypes_from_arg_signature): New function prototypes.
(dbus_gvalue_demarshal): Take context and error arguments.
(dbus_gvalue_demarshal_variant): New function.
(dbus_gvalue_demarshal_message): New function.
(dbus_gvalue_store): Delete.
* glib/dbus-gvalue.c:
File has been almost entirely rewritten; now we special-case
more types such as DBUS_TYPE_SIGNATURE, handle arrays and
hash tables correctly, etc. Full support for recursive values
is not yet complete.
* glib/dbus-gproxy.c (dbus_g_proxy_class_init): Change last
argument of signal to G_TYPE_POINTER since we now pass a
structure.
(lookup_g_marshaller): Delete in favor of
_dbus_gobject_lookup_marshaller.
(marshal_dbus_message_to_g_marshaller): Use
_dbus_gobject_lookup_marshaller and dbus_gvalue_demarshal_message
to handle remote signal callbacks.
(dbus_g_proxy_new_from_proxy): New function; creates a new
DBusGProxy by copying an existing one.
(dbus_g_proxy_get_interface, dbus_g_proxy_set_interface)
(dbus_g_proxy_get_path): New functions.
(dbus_g_proxy_marshal_args_to_message): New function;
factored out of existing code.
(DBUS_G_VALUE_ARRAY_COLLECT_ALL): Collect all arguments
from a varargs array.
(dbus_g_proxy_begin_call_internal): New function.
(dbus_g_proxy_end_call_internal): New function.
(dbus_g_proxy_begin_call): Take GTypes instead of DBus types
as arguments; simply invoke dbus_g_proxy_begin_call_internal
after collecting args into value array.
(dbus_g_proxy_end_call): Take GTypes instead of DBus types;
invoke dbus_g_proxy_end_call_internal.
(dbus_g_proxy_invoke): Simply invoke begin_call_interanl and
end_call_internal.
(dbus_g_proxy_call_no_reply): Take GTypes instead of DBus
types.
(array_free_all): New function.
(dbus_g_proxy_add_signal): Take GTypes.
* glib/dbus-gobject.h:
(_dbus_glib_marshal_dbus_message_to_gvalue_array): Delete.
(_dbus_gobject_get_path, _dbus_gobject_lookup_marshaller):
Prototype.
* glib/dbus-gobject.c: Add a global marshal_table hash which
stores mappings from type signatures to marshallers. Change lots
of invocations of dbus_gtype_to_dbus_type to
dbus_gtype_to_signature.
(_dbus_glib_marshal_dbus_message_to_gvalue_array): Delete.
(introspect_signals): Fix test for query.return_type.
(set_object_property): Update invocation of dbus_gvalue_demarshal.
(invoke_object_method): Many changes. Handle asynchronous
invocations. Convert arguments with
dbus_gvalue_demarshal_message. Handle errors. Use
DBusSignatureIter instead of strlen on args. Handle all arguments
generically. Special-case variants.
(dbus_g_method_return, dbus_g_method_return_error): New function.
(DBusGSignalClosure): New structure, closes over signal
information.
(dbus_g_signal_closure_new): New function.
(dbus_g_signal_closure_finalize): New function.
(signal_emitter_marshaller): New function; is special marshaller
which emits signals on bus.
(export_signals): New function; introspects object signals and
connects to them.
(dbus_g_object_type_install_info): Take GType instead of
GObjectClass.
(dbus_g_connection_register_g_object): Invoke export_signals.
(dbus_g_connection_lookup_g_object): New function.
(DBusGFuncSignature) New structure; used for mapping type
signatures to marshallers.
(funcsig_hash): New function; hashes DBusGFuncSignature.
(funcsig_equal): New function; compares DBusGFuncSignature.
(_dbus_gobject_lookup_marshaller): New function.
(dbus_g_object_register_marshaller): New function; used to
register a marshaller at runtime for a particular signature.
* glib/dbus-gmain.c (_dbus_gmain_test): Add various tests.
* glib/dbus-binding-tool-glib.h: Add DBUS_GLIB_ANNOTATION_ASYNC
which notes a server method implementation should be
asynchronous.
* glib/dbus-binding-tool-glib.c
(dbus_binding_tool_output_glib_server): Call
dbus_g_value_types_init.
(write_formal_parameters): Use dbus_gtype_from_signature. Handle
variants specially.
(dbus_g_type_get_lookup_function): Turn GType into an invocation
of a lookup function.
(write_args_for_direction): Use dbus_g_type_get_lookup_function.
(write_untyped_out_args): New method; write output arguments.
(write_formal_declarations_for_direction): Function for
writing prototypes.
(write_formal_parameters_for_direction): Function for
writing implementations.
(write_typed_args_for_direction): Function for writing
arguments prefixed with GTypes.
(write_async_method_client): Write out async version
of method.
* glib/dbus-binding-tool-glib.c: Include dbus-gvalue-utils.h.
(dbus_g_type_get_marshal_name): Move mapping from GType
to marshal name into here.
(dbus_g_type_get_c_name): Move into here.
(compute_marshaller): Convert signature to type with
dbus_gtype_from_signature, use dbus_g_type_get_marshal_name.
(compute_marshaller_name): Ditto.
(compute_marshaller): Handle async signal annotations.
(gather_marshallers): Return if we don't have a known
prefix.
(generate_glue): Collect introspection blob here, and
write all of the blob at the end. This allows an object
with multiple interfaces to work.
Mark async methods in introspection blob.
* glib/Makefile.am (libdbus_glib_1_la_SOURCES): Add
dbus-gtype-specialized.c, dbus-gtype-specialized.h,
dbus-gvalue-utils.h, dbus-gvalue-utils.c.
* dbus/dbus-glib.h: Don't include dbus-protocol.h; this
avoids people accidentally using DBUS_TYPE_* which should
not be necessary anymore.
Do include dbus-gtype-specialized.h, which are utilities
for GLib container types.
Add various #defines for types such as
DBUS_TYPE_G_BOOLEAN_ARRAY.
(DBusGValueIterator, DBusGValue): Define, not fully used
yet.
(dbus_g_value_get_g_type): Type for recursive value.
(dbus_g_value_open, dbus_g_value_iterator_get_value)
(dbus_g_value_iterator_get_values, dbus_g_value_iterator_recurse)
(dbus_g_value_free): Prototypes.
(dbus_g_object_register_marshaller, dbus_g_proxy_new_from_proxy): Prototype.
(dbus_g_proxy_set_interface): Prototype.
(dbus_g_proxy_begin_call, dbus_g_proxy_end_call)
(dbus_g_proxy_call_no_reply): Take GLib types instead of DBus
types.
(dbus_g_proxy_get_path, dbus_g_proxy_get_interface):
Accessors.
(DBusGAsyncData, DBusGMethodInvocation): Structures for
doing async invocations.
(dbus_g_method_return, dbus_g_method_return_error):
Prototypes.
* doc/dbus-tutorial.xml: Update GLib section.
* tools/dbus-viewer.c (load_child_nodes): Update
for new invocation type of dbus_g_proxy_end_call.
(load_from_service_thread_func): Ditto.
* tools/print-introspect.c (main): Ditto.
* tools/dbus-names-model.c (have_names_notify)
(names_model_reload, names_model_set_connection)
Use GTypes.
* python/Makefile.am (INCLUDES): Define DBUS_COMPILATION,
needed since Python bindings use GLib bindings.
* test/glib/Makefile.am (INCLUDES): Define DBUS_COMPILATION.
Add --prefix argument.
* tools/Makefile.am: Define DBUS_COMPILATION. Remove
unneeded --ignore-unsupported arg.
* test/glib/test-service-glib.c:
* test/glib/test-service-glib.xml:
* test/glib/test-dbus-glib.c: Add many more tests.
2005-06-13 03:01:30 +00:00
|
|
|
#include "dbus-gvalue.h"
|
|
|
|
|
#include "dbus-gvalue-utils.h"
|
|
|
|
|
#include <string.h>
|
2002-12-16 Anders Carlsson <andersca@codefactory.se>
* Makefile.am:
* configure.in:
Add GLib checks and fixup .pc files
* glib/Makefile.am:
* glib/dbus-glib.h:
* glib/dbus-gmain.c: (gdbus_connection_prepare),
(gdbus_connection_check), (gdbus_connection_dispatch),
(gdbus_add_connection_watch), (gdbus_remove_connection_watch),
(dbus_connection_gsource_new):
* glib/dbus-gthread.c: (dbus_gmutex_new), (dbus_gmutex_free),
(dbus_gmutex_lock), (dbus_gmutex_unlock), (dbus_gthread_init):
* glib/test-dbus-glib.c: (message_handler), (main):
Add GLib support.
2002-12-16 00:26:05 +00:00
|
|
|
|
2003-09-17 03:52:07 +00:00
|
|
|
#include <libintl.h>
|
|
|
|
|
#define _(x) dgettext (GETTEXT_PACKAGE, x)
|
|
|
|
|
#define N_(x) x
|
2002-12-16 Anders Carlsson <andersca@codefactory.se>
* Makefile.am:
* configure.in:
Add GLib checks and fixup .pc files
* glib/Makefile.am:
* glib/dbus-glib.h:
* glib/dbus-gmain.c: (gdbus_connection_prepare),
(gdbus_connection_check), (gdbus_connection_dispatch),
(gdbus_add_connection_watch), (gdbus_remove_connection_watch),
(dbus_connection_gsource_new):
* glib/dbus-gthread.c: (dbus_gmutex_new), (dbus_gmutex_free),
(dbus_gmutex_lock), (dbus_gmutex_unlock), (dbus_gthread_init):
* glib/test-dbus-glib.c: (message_handler), (main):
Add GLib support.
2002-12-16 00:26:05 +00:00
|
|
|
|
2003-02-26 06:42:57 +00:00
|
|
|
/**
|
|
|
|
|
* @defgroup DBusGLib GLib bindings
|
|
|
|
|
* @brief API for using D-BUS with GLib
|
|
|
|
|
*
|
2005-01-21 05:06:10 +00:00
|
|
|
* libdbus proper is a low-level API, these GLib bindings wrap libdbus
|
|
|
|
|
* with a much higher-level approach. The higher level approach is
|
|
|
|
|
* possible because GLib defines a main loop, an object/type system,
|
|
|
|
|
* and an out-of-memory handling policy (it exits the program).
|
|
|
|
|
* See http://www.gtk.org for GLib information.
|
|
|
|
|
*
|
|
|
|
|
* To manipulate remote objects, use #DBusGProxy.
|
2003-02-26 06:42:57 +00:00
|
|
|
*/
|
2003-01-25 21:22:57 +00:00
|
|
|
|
2003-02-26 06:42:57 +00:00
|
|
|
/**
|
|
|
|
|
* @defgroup DBusGLibInternals GLib bindings implementation details
|
|
|
|
|
* @ingroup DBusInternals
|
|
|
|
|
* @brief Implementation details of GLib bindings
|
|
|
|
|
*
|
|
|
|
|
* @{
|
|
|
|
|
*/
|
|
|
|
|
|
2005-01-30 20:06:52 +00:00
|
|
|
/**
|
|
|
|
|
* A GSource subclass for dispatching DBusConnection messages.
|
|
|
|
|
* We need this on top of the IO handlers, because sometimes
|
|
|
|
|
* there are messages to dispatch queued up but no IO pending.
|
|
|
|
|
*/
|
|
|
|
|
typedef struct
|
|
|
|
|
{
|
|
|
|
|
GSource source; /**< the parent GSource */
|
|
|
|
|
DBusConnection *connection; /**< the connection to dispatch */
|
|
|
|
|
} DBusGMessageQueue;
|
|
|
|
|
|
|
|
|
|
static gboolean message_queue_prepare (GSource *source,
|
|
|
|
|
gint *timeout);
|
|
|
|
|
static gboolean message_queue_check (GSource *source);
|
|
|
|
|
static gboolean message_queue_dispatch (GSource *source,
|
|
|
|
|
GSourceFunc callback,
|
|
|
|
|
gpointer user_data);
|
|
|
|
|
|
|
|
|
|
static GSourceFuncs message_queue_funcs = {
|
|
|
|
|
message_queue_prepare,
|
|
|
|
|
message_queue_check,
|
|
|
|
|
message_queue_dispatch,
|
|
|
|
|
NULL
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
|
message_queue_prepare (GSource *source,
|
|
|
|
|
gint *timeout)
|
|
|
|
|
{
|
|
|
|
|
DBusConnection *connection = ((DBusGMessageQueue *)source)->connection;
|
|
|
|
|
|
|
|
|
|
*timeout = -1;
|
|
|
|
|
|
|
|
|
|
return (dbus_connection_get_dispatch_status (connection) == DBUS_DISPATCH_DATA_REMAINS);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
|
message_queue_check (GSource *source)
|
|
|
|
|
{
|
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
|
message_queue_dispatch (GSource *source,
|
|
|
|
|
GSourceFunc callback,
|
|
|
|
|
gpointer user_data)
|
|
|
|
|
{
|
|
|
|
|
DBusConnection *connection = ((DBusGMessageQueue *)source)->connection;
|
|
|
|
|
|
|
|
|
|
dbus_connection_ref (connection);
|
2005-04-13 14:10:21 +00:00
|
|
|
|
|
|
|
|
/* Only dispatch once - we don't want to starve other GSource */
|
|
|
|
|
dbus_connection_dispatch (connection);
|
2005-01-30 20:06:52 +00:00
|
|
|
|
|
|
|
|
dbus_connection_unref (connection);
|
|
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
|
}
|
|
|
|
|
|
2005-01-30 19:33:29 +00:00
|
|
|
typedef struct
|
2002-12-16 Anders Carlsson <andersca@codefactory.se>
* Makefile.am:
* configure.in:
Add GLib checks and fixup .pc files
* glib/Makefile.am:
* glib/dbus-glib.h:
* glib/dbus-gmain.c: (gdbus_connection_prepare),
(gdbus_connection_check), (gdbus_connection_dispatch),
(gdbus_add_connection_watch), (gdbus_remove_connection_watch),
(dbus_connection_gsource_new):
* glib/dbus-gthread.c: (dbus_gmutex_new), (dbus_gmutex_free),
(dbus_gmutex_lock), (dbus_gmutex_unlock), (dbus_gthread_init):
* glib/test-dbus-glib.c: (message_handler), (main):
Add GLib support.
2002-12-16 00:26:05 +00:00
|
|
|
{
|
2005-01-30 19:33:29 +00:00
|
|
|
GMainContext *context; /**< the main context */
|
|
|
|
|
GSList *ios; /**< all IOHandler */
|
|
|
|
|
GSList *timeouts; /**< all TimeoutHandler */
|
|
|
|
|
DBusConnection *connection; /**< NULL if this is really for a server not a connection */
|
2005-01-30 20:06:52 +00:00
|
|
|
GSource *message_queue_source; /**< DBusGMessageQueue */
|
2005-01-30 19:33:29 +00:00
|
|
|
} ConnectionSetup;
|
2002-12-16 Anders Carlsson <andersca@codefactory.se>
* Makefile.am:
* configure.in:
Add GLib checks and fixup .pc files
* glib/Makefile.am:
* glib/dbus-glib.h:
* glib/dbus-gmain.c: (gdbus_connection_prepare),
(gdbus_connection_check), (gdbus_connection_dispatch),
(gdbus_add_connection_watch), (gdbus_remove_connection_watch),
(dbus_connection_gsource_new):
* glib/dbus-gthread.c: (dbus_gmutex_new), (dbus_gmutex_free),
(dbus_gmutex_lock), (dbus_gmutex_unlock), (dbus_gthread_init):
* glib/test-dbus-glib.c: (message_handler), (main):
Add GLib support.
2002-12-16 00:26:05 +00:00
|
|
|
|
2003-04-24 02:22:49 +00:00
|
|
|
|
2005-01-30 19:33:29 +00:00
|
|
|
typedef struct
|
|
|
|
|
{
|
|
|
|
|
ConnectionSetup *cs;
|
|
|
|
|
GSource *source;
|
|
|
|
|
DBusWatch *watch;
|
|
|
|
|
} IOHandler;
|
2003-01-25 21:22:57 +00:00
|
|
|
|
2003-08-05 13:57:20 +00:00
|
|
|
typedef struct
|
|
|
|
|
{
|
2005-01-30 19:33:29 +00:00
|
|
|
ConnectionSetup *cs;
|
|
|
|
|
GSource *source;
|
|
|
|
|
DBusTimeout *timeout;
|
|
|
|
|
} TimeoutHandler;
|
2003-08-05 13:57:20 +00:00
|
|
|
|
2005-01-30 19:33:29 +00:00
|
|
|
static dbus_int32_t connection_slot = -1;
|
|
|
|
|
static dbus_int32_t server_slot = -1;
|
2003-08-05 13:57:20 +00:00
|
|
|
|
2005-01-30 19:33:29 +00:00
|
|
|
static ConnectionSetup*
|
2005-01-30 20:06:52 +00:00
|
|
|
connection_setup_new (GMainContext *context,
|
|
|
|
|
DBusConnection *connection)
|
2003-08-05 13:57:20 +00:00
|
|
|
{
|
2005-01-30 19:33:29 +00:00
|
|
|
ConnectionSetup *cs;
|
2003-08-05 13:57:20 +00:00
|
|
|
|
2005-01-30 19:33:29 +00:00
|
|
|
cs = g_new0 (ConnectionSetup, 1);
|
2003-08-05 13:57:20 +00:00
|
|
|
|
2005-01-30 19:33:29 +00:00
|
|
|
g_assert (context != NULL);
|
|
|
|
|
|
|
|
|
|
cs->context = context;
|
2005-01-30 20:06:52 +00:00
|
|
|
g_main_context_ref (cs->context);
|
|
|
|
|
|
|
|
|
|
if (connection)
|
|
|
|
|
{
|
|
|
|
|
cs->connection = connection;
|
|
|
|
|
|
|
|
|
|
cs->message_queue_source = g_source_new (&message_queue_funcs,
|
|
|
|
|
sizeof (DBusGMessageQueue));
|
|
|
|
|
((DBusGMessageQueue*)cs->message_queue_source)->connection = connection;
|
|
|
|
|
g_source_attach (cs->message_queue_source, cs->context);
|
|
|
|
|
}
|
2005-01-30 19:33:29 +00:00
|
|
|
|
|
|
|
|
return cs;
|
2003-08-05 13:57:20 +00:00
|
|
|
}
|
|
|
|
|
|
2005-01-30 19:33:29 +00:00
|
|
|
static void
|
2005-04-06 17:36:47 +00:00
|
|
|
io_handler_source_finalized (gpointer data)
|
2003-08-05 13:57:20 +00:00
|
|
|
{
|
2005-01-30 19:33:29 +00:00
|
|
|
IOHandler *handler;
|
|
|
|
|
|
|
|
|
|
handler = data;
|
|
|
|
|
|
|
|
|
|
if (handler->watch)
|
|
|
|
|
dbus_watch_set_data (handler->watch, NULL, NULL);
|
|
|
|
|
|
|
|
|
|
g_free (handler);
|
2003-08-05 13:57:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
2005-01-30 19:33:29 +00:00
|
|
|
io_handler_destroy_source (void *data)
|
2003-08-05 13:57:20 +00:00
|
|
|
{
|
2005-01-30 19:33:29 +00:00
|
|
|
IOHandler *handler;
|
2003-08-05 13:57:20 +00:00
|
|
|
|
2005-01-30 19:33:29 +00:00
|
|
|
handler = data;
|
|
|
|
|
|
|
|
|
|
if (handler->source)
|
2003-08-05 13:57:20 +00:00
|
|
|
{
|
2005-01-30 19:33:29 +00:00
|
|
|
GSource *source = handler->source;
|
|
|
|
|
handler->source = NULL;
|
2005-04-06 17:36:47 +00:00
|
|
|
handler->cs->ios = g_slist_remove (handler->cs->ios, handler);
|
2005-01-30 19:33:29 +00:00
|
|
|
g_source_destroy (source);
|
2005-04-19 03:35:26 +00:00
|
|
|
g_source_unref (source);
|
2003-08-05 13:57:20 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2005-01-30 19:33:29 +00:00
|
|
|
static void
|
|
|
|
|
io_handler_watch_freed (void *data)
|
2002-12-16 Anders Carlsson <andersca@codefactory.se>
* Makefile.am:
* configure.in:
Add GLib checks and fixup .pc files
* glib/Makefile.am:
* glib/dbus-glib.h:
* glib/dbus-gmain.c: (gdbus_connection_prepare),
(gdbus_connection_check), (gdbus_connection_dispatch),
(gdbus_add_connection_watch), (gdbus_remove_connection_watch),
(dbus_connection_gsource_new):
* glib/dbus-gthread.c: (dbus_gmutex_new), (dbus_gmutex_free),
(dbus_gmutex_lock), (dbus_gmutex_unlock), (dbus_gthread_init):
* glib/test-dbus-glib.c: (message_handler), (main):
Add GLib support.
2002-12-16 00:26:05 +00:00
|
|
|
{
|
2005-01-30 19:33:29 +00:00
|
|
|
IOHandler *handler;
|
2003-01-25 21:22:57 +00:00
|
|
|
|
2005-01-30 19:33:29 +00:00
|
|
|
handler = data;
|
2002-12-16 Anders Carlsson <andersca@codefactory.se>
* Makefile.am:
* configure.in:
Add GLib checks and fixup .pc files
* glib/Makefile.am:
* glib/dbus-glib.h:
* glib/dbus-gmain.c: (gdbus_connection_prepare),
(gdbus_connection_check), (gdbus_connection_dispatch),
(gdbus_add_connection_watch), (gdbus_remove_connection_watch),
(dbus_connection_gsource_new):
* glib/dbus-gthread.c: (dbus_gmutex_new), (dbus_gmutex_free),
(dbus_gmutex_lock), (dbus_gmutex_unlock), (dbus_gthread_init):
* glib/test-dbus-glib.c: (message_handler), (main):
Add GLib support.
2002-12-16 00:26:05 +00:00
|
|
|
|
2005-01-30 19:33:29 +00:00
|
|
|
handler->watch = NULL;
|
2003-02-26 06:42:57 +00:00
|
|
|
|
2005-01-30 19:33:29 +00:00
|
|
|
io_handler_destroy_source (handler);
|
2003-02-26 06:42:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static gboolean
|
2005-01-30 19:33:29 +00:00
|
|
|
io_handler_dispatch (GIOChannel *source,
|
|
|
|
|
GIOCondition condition,
|
|
|
|
|
gpointer data)
|
2003-01-25 21:22:57 +00:00
|
|
|
{
|
2005-01-30 19:33:29 +00:00
|
|
|
IOHandler *handler;
|
|
|
|
|
guint dbus_condition = 0;
|
|
|
|
|
DBusConnection *connection;
|
|
|
|
|
|
|
|
|
|
handler = data;
|
2003-01-25 21:22:57 +00:00
|
|
|
|
2005-01-30 19:33:29 +00:00
|
|
|
connection = handler->cs->connection;
|
|
|
|
|
|
|
|
|
|
if (connection)
|
|
|
|
|
dbus_connection_ref (connection);
|
|
|
|
|
|
|
|
|
|
if (condition & G_IO_IN)
|
|
|
|
|
dbus_condition |= DBUS_WATCH_READABLE;
|
|
|
|
|
if (condition & G_IO_OUT)
|
|
|
|
|
dbus_condition |= DBUS_WATCH_WRITABLE;
|
|
|
|
|
if (condition & G_IO_ERR)
|
|
|
|
|
dbus_condition |= DBUS_WATCH_ERROR;
|
|
|
|
|
if (condition & G_IO_HUP)
|
|
|
|
|
dbus_condition |= DBUS_WATCH_HANGUP;
|
|
|
|
|
|
|
|
|
|
/* Note that we don't touch the handler after this, because
|
|
|
|
|
* dbus may have disabled the watch and thus killed the
|
|
|
|
|
* handler.
|
|
|
|
|
*/
|
|
|
|
|
dbus_watch_handle (handler->watch, dbus_condition);
|
|
|
|
|
handler = NULL;
|
2003-01-25 21:22:57 +00:00
|
|
|
|
2005-01-30 19:33:29 +00:00
|
|
|
if (connection)
|
2005-05-16 21:27:04 +00:00
|
|
|
dbus_connection_unref (connection);
|
2005-01-30 19:33:29 +00:00
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
connection_setup_add_watch (ConnectionSetup *cs,
|
|
|
|
|
DBusWatch *watch)
|
|
|
|
|
{
|
|
|
|
|
guint flags;
|
|
|
|
|
GIOCondition condition;
|
|
|
|
|
GIOChannel *channel;
|
|
|
|
|
IOHandler *handler;
|
|
|
|
|
|
|
|
|
|
if (!dbus_watch_get_enabled (watch))
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
g_assert (dbus_watch_get_data (watch) == NULL);
|
|
|
|
|
|
|
|
|
|
flags = dbus_watch_get_flags (watch);
|
2003-01-25 21:22:57 +00:00
|
|
|
|
2005-01-30 19:33:29 +00:00
|
|
|
condition = G_IO_ERR | G_IO_HUP;
|
|
|
|
|
if (flags & DBUS_WATCH_READABLE)
|
|
|
|
|
condition |= G_IO_IN;
|
|
|
|
|
if (flags & DBUS_WATCH_WRITABLE)
|
|
|
|
|
condition |= G_IO_OUT;
|
2003-01-25 21:22:57 +00:00
|
|
|
|
2005-01-30 19:33:29 +00:00
|
|
|
handler = g_new0 (IOHandler, 1);
|
|
|
|
|
handler->cs = cs;
|
|
|
|
|
handler->watch = watch;
|
|
|
|
|
|
|
|
|
|
channel = g_io_channel_unix_new (dbus_watch_get_fd (watch));
|
|
|
|
|
|
|
|
|
|
handler->source = g_io_create_watch (channel, condition);
|
|
|
|
|
g_source_set_callback (handler->source, (GSourceFunc) io_handler_dispatch, handler,
|
2005-04-06 17:36:47 +00:00
|
|
|
io_handler_source_finalized);
|
2005-01-30 19:33:29 +00:00
|
|
|
g_source_attach (handler->source, cs->context);
|
2003-01-25 21:22:57 +00:00
|
|
|
|
2005-01-30 19:33:29 +00:00
|
|
|
cs->ios = g_slist_prepend (cs->ios, handler);
|
|
|
|
|
|
|
|
|
|
dbus_watch_set_data (watch, handler, io_handler_watch_freed);
|
2003-01-25 21:22:57 +00:00
|
|
|
}
|
|
|
|
|
|
2005-01-30 19:33:29 +00:00
|
|
|
static void
|
|
|
|
|
connection_setup_remove_watch (ConnectionSetup *cs,
|
|
|
|
|
DBusWatch *watch)
|
2003-02-26 06:42:57 +00:00
|
|
|
{
|
2005-01-30 19:33:29 +00:00
|
|
|
IOHandler *handler;
|
|
|
|
|
|
|
|
|
|
handler = dbus_watch_get_data (watch);
|
|
|
|
|
|
|
|
|
|
if (handler == NULL)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
io_handler_destroy_source (handler);
|
2003-02-26 06:42:57 +00:00
|
|
|
}
|
|
|
|
|
|
2005-01-30 19:33:29 +00:00
|
|
|
static void
|
2005-04-06 17:36:47 +00:00
|
|
|
timeout_handler_source_finalized (gpointer data)
|
2003-02-26 06:42:57 +00:00
|
|
|
{
|
2005-01-30 19:33:29 +00:00
|
|
|
TimeoutHandler *handler;
|
|
|
|
|
|
|
|
|
|
handler = data;
|
|
|
|
|
|
|
|
|
|
if (handler->timeout)
|
|
|
|
|
dbus_timeout_set_data (handler->timeout, NULL, NULL);
|
|
|
|
|
|
|
|
|
|
g_free (handler);
|
2003-02-26 06:42:57 +00:00
|
|
|
}
|
|
|
|
|
|
2005-01-30 19:33:29 +00:00
|
|
|
static void
|
|
|
|
|
timeout_handler_destroy_source (void *data)
|
2002-12-16 Anders Carlsson <andersca@codefactory.se>
* Makefile.am:
* configure.in:
Add GLib checks and fixup .pc files
* glib/Makefile.am:
* glib/dbus-glib.h:
* glib/dbus-gmain.c: (gdbus_connection_prepare),
(gdbus_connection_check), (gdbus_connection_dispatch),
(gdbus_add_connection_watch), (gdbus_remove_connection_watch),
(dbus_connection_gsource_new):
* glib/dbus-gthread.c: (dbus_gmutex_new), (dbus_gmutex_free),
(dbus_gmutex_lock), (dbus_gmutex_unlock), (dbus_gthread_init):
* glib/test-dbus-glib.c: (message_handler), (main):
Add GLib support.
2002-12-16 00:26:05 +00:00
|
|
|
{
|
2005-01-30 19:33:29 +00:00
|
|
|
TimeoutHandler *handler;
|
|
|
|
|
|
|
|
|
|
handler = data;
|
|
|
|
|
|
|
|
|
|
if (handler->source)
|
|
|
|
|
{
|
|
|
|
|
GSource *source = handler->source;
|
|
|
|
|
handler->source = NULL;
|
2005-04-06 17:36:47 +00:00
|
|
|
handler->cs->timeouts = g_slist_remove (handler->cs->timeouts, handler);
|
2005-01-30 19:33:29 +00:00
|
|
|
g_source_destroy (source);
|
2005-04-19 03:35:26 +00:00
|
|
|
g_source_unref (source);
|
2005-01-30 19:33:29 +00:00
|
|
|
}
|
2002-12-16 Anders Carlsson <andersca@codefactory.se>
* Makefile.am:
* configure.in:
Add GLib checks and fixup .pc files
* glib/Makefile.am:
* glib/dbus-glib.h:
* glib/dbus-gmain.c: (gdbus_connection_prepare),
(gdbus_connection_check), (gdbus_connection_dispatch),
(gdbus_add_connection_watch), (gdbus_remove_connection_watch),
(dbus_connection_gsource_new):
* glib/dbus-gthread.c: (dbus_gmutex_new), (dbus_gmutex_free),
(dbus_gmutex_lock), (dbus_gmutex_unlock), (dbus_gthread_init):
* glib/test-dbus-glib.c: (message_handler), (main):
Add GLib support.
2002-12-16 00:26:05 +00:00
|
|
|
}
|
|
|
|
|
|
2005-01-30 19:33:29 +00:00
|
|
|
static void
|
|
|
|
|
timeout_handler_timeout_freed (void *data)
|
2003-02-26 06:42:57 +00:00
|
|
|
{
|
2005-01-30 19:33:29 +00:00
|
|
|
TimeoutHandler *handler;
|
2003-02-26 06:42:57 +00:00
|
|
|
|
2005-01-30 19:33:29 +00:00
|
|
|
handler = data;
|
2003-02-26 06:42:57 +00:00
|
|
|
|
2005-01-30 19:33:29 +00:00
|
|
|
handler->timeout = NULL;
|
2003-02-26 06:42:57 +00:00
|
|
|
|
2005-01-30 19:33:29 +00:00
|
|
|
timeout_handler_destroy_source (handler);
|
2003-02-26 06:42:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static gboolean
|
2005-01-30 19:33:29 +00:00
|
|
|
timeout_handler_dispatch (gpointer data)
|
2003-02-26 06:42:57 +00:00
|
|
|
{
|
2005-01-30 19:33:29 +00:00
|
|
|
TimeoutHandler *handler;
|
2003-02-26 06:42:57 +00:00
|
|
|
|
2005-01-30 19:33:29 +00:00
|
|
|
handler = data;
|
2003-02-26 06:42:57 +00:00
|
|
|
|
2005-01-30 19:33:29 +00:00
|
|
|
dbus_timeout_handle (handler->timeout);
|
|
|
|
|
|
2003-02-26 06:42:57 +00:00
|
|
|
return TRUE;
|
|
|
|
|
}
|
2005-01-30 19:33:29 +00:00
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
connection_setup_add_timeout (ConnectionSetup *cs,
|
|
|
|
|
DBusTimeout *timeout)
|
2002-12-16 Anders Carlsson <andersca@codefactory.se>
* Makefile.am:
* configure.in:
Add GLib checks and fixup .pc files
* glib/Makefile.am:
* glib/dbus-glib.h:
* glib/dbus-gmain.c: (gdbus_connection_prepare),
(gdbus_connection_check), (gdbus_connection_dispatch),
(gdbus_add_connection_watch), (gdbus_remove_connection_watch),
(dbus_connection_gsource_new):
* glib/dbus-gthread.c: (dbus_gmutex_new), (dbus_gmutex_free),
(dbus_gmutex_lock), (dbus_gmutex_unlock), (dbus_gthread_init):
* glib/test-dbus-glib.c: (message_handler), (main):
Add GLib support.
2002-12-16 00:26:05 +00:00
|
|
|
{
|
2005-01-30 19:33:29 +00:00
|
|
|
TimeoutHandler *handler;
|
|
|
|
|
|
|
|
|
|
if (!dbus_timeout_get_enabled (timeout))
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
g_assert (dbus_timeout_get_data (timeout) == NULL);
|
2003-03-15 20:47:16 +00:00
|
|
|
|
2005-01-30 19:33:29 +00:00
|
|
|
handler = g_new0 (TimeoutHandler, 1);
|
|
|
|
|
handler->cs = cs;
|
|
|
|
|
handler->timeout = timeout;
|
2005-01-30 18:25:14 +00:00
|
|
|
|
2005-01-30 19:33:29 +00:00
|
|
|
handler->source = g_timeout_source_new (dbus_timeout_get_interval (timeout));
|
|
|
|
|
g_source_set_callback (handler->source, timeout_handler_dispatch, handler,
|
2005-04-06 17:36:47 +00:00
|
|
|
timeout_handler_source_finalized);
|
2005-01-30 19:33:29 +00:00
|
|
|
g_source_attach (handler->source, handler->cs->context);
|
2003-08-05 13:57:20 +00:00
|
|
|
|
2005-01-30 19:33:29 +00:00
|
|
|
cs->timeouts = g_slist_prepend (cs->timeouts, handler);
|
2003-01-25 21:22:57 +00:00
|
|
|
|
2005-01-30 19:33:29 +00:00
|
|
|
dbus_timeout_set_data (timeout, handler, timeout_handler_timeout_freed);
|
|
|
|
|
}
|
2003-01-25 21:22:57 +00:00
|
|
|
|
2005-01-30 19:33:29 +00:00
|
|
|
static void
|
|
|
|
|
connection_setup_remove_timeout (ConnectionSetup *cs,
|
|
|
|
|
DBusTimeout *timeout)
|
|
|
|
|
{
|
|
|
|
|
TimeoutHandler *handler;
|
2003-08-05 13:57:20 +00:00
|
|
|
|
2005-01-30 19:33:29 +00:00
|
|
|
handler = dbus_timeout_get_data (timeout);
|
2003-03-14 01:27:58 +00:00
|
|
|
|
2005-01-30 19:33:29 +00:00
|
|
|
if (handler == NULL)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
timeout_handler_destroy_source (handler);
|
2002-12-16 Anders Carlsson <andersca@codefactory.se>
* Makefile.am:
* configure.in:
Add GLib checks and fixup .pc files
* glib/Makefile.am:
* glib/dbus-glib.h:
* glib/dbus-gmain.c: (gdbus_connection_prepare),
(gdbus_connection_check), (gdbus_connection_dispatch),
(gdbus_add_connection_watch), (gdbus_remove_connection_watch),
(dbus_connection_gsource_new):
* glib/dbus-gthread.c: (dbus_gmutex_new), (dbus_gmutex_free),
(dbus_gmutex_lock), (dbus_gmutex_unlock), (dbus_gthread_init):
* glib/test-dbus-glib.c: (message_handler), (main):
Add GLib support.
2002-12-16 00:26:05 +00:00
|
|
|
}
|
|
|
|
|
|
2005-01-30 18:25:14 +00:00
|
|
|
static void
|
2005-01-30 19:33:29 +00:00
|
|
|
connection_setup_free (ConnectionSetup *cs)
|
2005-01-30 18:25:14 +00:00
|
|
|
{
|
2005-01-30 19:33:29 +00:00
|
|
|
while (cs->ios)
|
|
|
|
|
io_handler_destroy_source (cs->ios->data);
|
2005-01-30 18:25:14 +00:00
|
|
|
|
2005-01-30 19:33:29 +00:00
|
|
|
while (cs->timeouts)
|
|
|
|
|
timeout_handler_destroy_source (cs->timeouts->data);
|
2005-01-30 20:06:52 +00:00
|
|
|
|
|
|
|
|
if (cs->message_queue_source)
|
|
|
|
|
{
|
|
|
|
|
GSource *source;
|
|
|
|
|
|
|
|
|
|
source = cs->message_queue_source;
|
|
|
|
|
cs->message_queue_source = NULL;
|
|
|
|
|
|
|
|
|
|
g_source_destroy (source);
|
2005-04-19 03:35:26 +00:00
|
|
|
g_source_unref (source);
|
2005-01-30 20:06:52 +00:00
|
|
|
}
|
2005-01-30 18:25:14 +00:00
|
|
|
|
2005-01-30 19:33:29 +00:00
|
|
|
g_main_context_unref (cs->context);
|
|
|
|
|
g_free (cs);
|
|
|
|
|
}
|
2005-01-30 18:25:14 +00:00
|
|
|
|
2005-01-30 19:33:29 +00:00
|
|
|
static dbus_bool_t
|
|
|
|
|
add_watch (DBusWatch *watch,
|
|
|
|
|
gpointer data)
|
|
|
|
|
{
|
|
|
|
|
ConnectionSetup *cs;
|
2005-01-30 18:25:14 +00:00
|
|
|
|
2005-01-30 19:33:29 +00:00
|
|
|
cs = data;
|
2005-01-30 18:25:14 +00:00
|
|
|
|
2005-01-30 19:33:29 +00:00
|
|
|
connection_setup_add_watch (cs, watch);
|
|
|
|
|
|
|
|
|
|
return TRUE;
|
2005-01-30 18:25:14 +00:00
|
|
|
}
|
|
|
|
|
|
2002-12-16 Anders Carlsson <andersca@codefactory.se>
* Makefile.am:
* configure.in:
Add GLib checks and fixup .pc files
* glib/Makefile.am:
* glib/dbus-glib.h:
* glib/dbus-gmain.c: (gdbus_connection_prepare),
(gdbus_connection_check), (gdbus_connection_dispatch),
(gdbus_add_connection_watch), (gdbus_remove_connection_watch),
(dbus_connection_gsource_new):
* glib/dbus-gthread.c: (dbus_gmutex_new), (dbus_gmutex_free),
(dbus_gmutex_lock), (dbus_gmutex_unlock), (dbus_gthread_init):
* glib/test-dbus-glib.c: (message_handler), (main):
Add GLib support.
2002-12-16 00:26:05 +00:00
|
|
|
static void
|
2003-01-21 Anders Carlsson <andersca@codefactory.se>
* dbus/dbus-connection.c: (dbus_connection_send_message):
Add a new client_serial parameter.
(dbus_connection_send_message_with_reply):
Remove a @todo since we've implemented the blocking function.
(dbus_connection_send_message_with_reply_and_block):
New function that sends a message and waits for a reply and
then returns the reply.
* dbus/dbus-connection.h:
Add new functions.
* dbus/dbus-errors.c: (dbus_result_to_string):
* dbus/dbus-errors.h:
Add new DBUS_RESULT.
* dbus/dbus-message-internal.h:
* dbus/dbus-message.c: (_dbus_message_get_reply_serial),
(_dbus_message_set_sender), (dbus_message_write_header),
(dbus_message_new_reply), (decode_header_data),
(_dbus_message_loader_return_buffer), (_dbus_message_test):
* dbus/dbus-message.h:
Add new functions that set the reply serial and sender.
Also marshal and demarshal them correctly and add test.
* dbus/dbus-protocol.h:
Add new DBUS_MESSAGE_TYPE_SENDER.
* glib/dbus-glib.h:
* glib/dbus-gmain.c: (watch_callback), (free_callback_data),
(add_watch), (remove_watch), (add_timeout), (remove_timeout),
(dbus_connection_hookup_with_g_main):
* glib/test-dbus-glib.c: (main):
Rewrite to use GIOChannel and remove the GSource crack.
* test/echo-client.c: (main):
* test/watch.c: (check_messages):
Update for changed APIs
2003-01-21 09:23:18 +00:00
|
|
|
remove_watch (DBusWatch *watch,
|
|
|
|
|
gpointer data)
|
2002-12-16 Anders Carlsson <andersca@codefactory.se>
* Makefile.am:
* configure.in:
Add GLib checks and fixup .pc files
* glib/Makefile.am:
* glib/dbus-glib.h:
* glib/dbus-gmain.c: (gdbus_connection_prepare),
(gdbus_connection_check), (gdbus_connection_dispatch),
(gdbus_add_connection_watch), (gdbus_remove_connection_watch),
(dbus_connection_gsource_new):
* glib/dbus-gthread.c: (dbus_gmutex_new), (dbus_gmutex_free),
(dbus_gmutex_lock), (dbus_gmutex_unlock), (dbus_gthread_init):
* glib/test-dbus-glib.c: (message_handler), (main):
Add GLib support.
2002-12-16 00:26:05 +00:00
|
|
|
{
|
2005-01-30 19:33:29 +00:00
|
|
|
ConnectionSetup *cs;
|
2003-08-05 13:57:20 +00:00
|
|
|
|
2005-01-30 19:33:29 +00:00
|
|
|
cs = data;
|
2003-04-25 20:41:49 +00:00
|
|
|
|
2005-01-30 19:33:29 +00:00
|
|
|
connection_setup_remove_watch (cs, watch);
|
2002-12-16 Anders Carlsson <andersca@codefactory.se>
* Makefile.am:
* configure.in:
Add GLib checks and fixup .pc files
* glib/Makefile.am:
* glib/dbus-glib.h:
* glib/dbus-gmain.c: (gdbus_connection_prepare),
(gdbus_connection_check), (gdbus_connection_dispatch),
(gdbus_add_connection_watch), (gdbus_remove_connection_watch),
(dbus_connection_gsource_new):
* glib/dbus-gthread.c: (dbus_gmutex_new), (dbus_gmutex_free),
(dbus_gmutex_lock), (dbus_gmutex_unlock), (dbus_gthread_init):
* glib/test-dbus-glib.c: (message_handler), (main):
Add GLib support.
2002-12-16 00:26:05 +00:00
|
|
|
}
|
|
|
|
|
|
2003-03-15 20:47:16 +00:00
|
|
|
static void
|
|
|
|
|
watch_toggled (DBusWatch *watch,
|
|
|
|
|
void *data)
|
|
|
|
|
{
|
|
|
|
|
/* Because we just exit on OOM, enable/disable is
|
|
|
|
|
* no different from add/remove
|
|
|
|
|
*/
|
|
|
|
|
if (dbus_watch_get_enabled (watch))
|
|
|
|
|
add_watch (watch, data);
|
|
|
|
|
else
|
|
|
|
|
remove_watch (watch, data);
|
|
|
|
|
}
|
|
|
|
|
|
2003-03-14 01:27:58 +00:00
|
|
|
static dbus_bool_t
|
2003-01-21 Anders Carlsson <andersca@codefactory.se>
* dbus/dbus-connection.c: (dbus_connection_send_message):
Add a new client_serial parameter.
(dbus_connection_send_message_with_reply):
Remove a @todo since we've implemented the blocking function.
(dbus_connection_send_message_with_reply_and_block):
New function that sends a message and waits for a reply and
then returns the reply.
* dbus/dbus-connection.h:
Add new functions.
* dbus/dbus-errors.c: (dbus_result_to_string):
* dbus/dbus-errors.h:
Add new DBUS_RESULT.
* dbus/dbus-message-internal.h:
* dbus/dbus-message.c: (_dbus_message_get_reply_serial),
(_dbus_message_set_sender), (dbus_message_write_header),
(dbus_message_new_reply), (decode_header_data),
(_dbus_message_loader_return_buffer), (_dbus_message_test):
* dbus/dbus-message.h:
Add new functions that set the reply serial and sender.
Also marshal and demarshal them correctly and add test.
* dbus/dbus-protocol.h:
Add new DBUS_MESSAGE_TYPE_SENDER.
* glib/dbus-glib.h:
* glib/dbus-gmain.c: (watch_callback), (free_callback_data),
(add_watch), (remove_watch), (add_timeout), (remove_timeout),
(dbus_connection_hookup_with_g_main):
* glib/test-dbus-glib.c: (main):
Rewrite to use GIOChannel and remove the GSource crack.
* test/echo-client.c: (main):
* test/watch.c: (check_messages):
Update for changed APIs
2003-01-21 09:23:18 +00:00
|
|
|
add_timeout (DBusTimeout *timeout,
|
|
|
|
|
void *data)
|
2002-12-16 Anders Carlsson <andersca@codefactory.se>
* Makefile.am:
* configure.in:
Add GLib checks and fixup .pc files
* glib/Makefile.am:
* glib/dbus-glib.h:
* glib/dbus-gmain.c: (gdbus_connection_prepare),
(gdbus_connection_check), (gdbus_connection_dispatch),
(gdbus_add_connection_watch), (gdbus_remove_connection_watch),
(dbus_connection_gsource_new):
* glib/dbus-gthread.c: (dbus_gmutex_new), (dbus_gmutex_free),
(dbus_gmutex_lock), (dbus_gmutex_unlock), (dbus_gthread_init):
* glib/test-dbus-glib.c: (message_handler), (main):
Add GLib support.
2002-12-16 00:26:05 +00:00
|
|
|
{
|
2005-01-30 19:33:29 +00:00
|
|
|
ConnectionSetup *cs;
|
2003-02-13 20:37:07 +00:00
|
|
|
|
2005-01-30 19:33:29 +00:00
|
|
|
cs = data;
|
2005-01-30 18:25:14 +00:00
|
|
|
|
2003-03-15 20:47:16 +00:00
|
|
|
if (!dbus_timeout_get_enabled (timeout))
|
|
|
|
|
return TRUE;
|
2005-01-30 19:33:29 +00:00
|
|
|
|
|
|
|
|
connection_setup_add_timeout (cs, timeout);
|
2003-03-14 01:27:58 +00:00
|
|
|
|
|
|
|
|
return TRUE;
|
2003-01-21 Anders Carlsson <andersca@codefactory.se>
* dbus/dbus-connection.c: (dbus_connection_send_message):
Add a new client_serial parameter.
(dbus_connection_send_message_with_reply):
Remove a @todo since we've implemented the blocking function.
(dbus_connection_send_message_with_reply_and_block):
New function that sends a message and waits for a reply and
then returns the reply.
* dbus/dbus-connection.h:
Add new functions.
* dbus/dbus-errors.c: (dbus_result_to_string):
* dbus/dbus-errors.h:
Add new DBUS_RESULT.
* dbus/dbus-message-internal.h:
* dbus/dbus-message.c: (_dbus_message_get_reply_serial),
(_dbus_message_set_sender), (dbus_message_write_header),
(dbus_message_new_reply), (decode_header_data),
(_dbus_message_loader_return_buffer), (_dbus_message_test):
* dbus/dbus-message.h:
Add new functions that set the reply serial and sender.
Also marshal and demarshal them correctly and add test.
* dbus/dbus-protocol.h:
Add new DBUS_MESSAGE_TYPE_SENDER.
* glib/dbus-glib.h:
* glib/dbus-gmain.c: (watch_callback), (free_callback_data),
(add_watch), (remove_watch), (add_timeout), (remove_timeout),
(dbus_connection_hookup_with_g_main):
* glib/test-dbus-glib.c: (main):
Rewrite to use GIOChannel and remove the GSource crack.
* test/echo-client.c: (main):
* test/watch.c: (check_messages):
Update for changed APIs
2003-01-21 09:23:18 +00:00
|
|
|
}
|
2002-12-16 Anders Carlsson <andersca@codefactory.se>
* Makefile.am:
* configure.in:
Add GLib checks and fixup .pc files
* glib/Makefile.am:
* glib/dbus-glib.h:
* glib/dbus-gmain.c: (gdbus_connection_prepare),
(gdbus_connection_check), (gdbus_connection_dispatch),
(gdbus_add_connection_watch), (gdbus_remove_connection_watch),
(dbus_connection_gsource_new):
* glib/dbus-gthread.c: (dbus_gmutex_new), (dbus_gmutex_free),
(dbus_gmutex_lock), (dbus_gmutex_unlock), (dbus_gthread_init):
* glib/test-dbus-glib.c: (message_handler), (main):
Add GLib support.
2002-12-16 00:26:05 +00:00
|
|
|
|
2003-01-21 Anders Carlsson <andersca@codefactory.se>
* dbus/dbus-connection.c: (dbus_connection_send_message):
Add a new client_serial parameter.
(dbus_connection_send_message_with_reply):
Remove a @todo since we've implemented the blocking function.
(dbus_connection_send_message_with_reply_and_block):
New function that sends a message and waits for a reply and
then returns the reply.
* dbus/dbus-connection.h:
Add new functions.
* dbus/dbus-errors.c: (dbus_result_to_string):
* dbus/dbus-errors.h:
Add new DBUS_RESULT.
* dbus/dbus-message-internal.h:
* dbus/dbus-message.c: (_dbus_message_get_reply_serial),
(_dbus_message_set_sender), (dbus_message_write_header),
(dbus_message_new_reply), (decode_header_data),
(_dbus_message_loader_return_buffer), (_dbus_message_test):
* dbus/dbus-message.h:
Add new functions that set the reply serial and sender.
Also marshal and demarshal them correctly and add test.
* dbus/dbus-protocol.h:
Add new DBUS_MESSAGE_TYPE_SENDER.
* glib/dbus-glib.h:
* glib/dbus-gmain.c: (watch_callback), (free_callback_data),
(add_watch), (remove_watch), (add_timeout), (remove_timeout),
(dbus_connection_hookup_with_g_main):
* glib/test-dbus-glib.c: (main):
Rewrite to use GIOChannel and remove the GSource crack.
* test/echo-client.c: (main):
* test/watch.c: (check_messages):
Update for changed APIs
2003-01-21 09:23:18 +00:00
|
|
|
static void
|
|
|
|
|
remove_timeout (DBusTimeout *timeout,
|
|
|
|
|
void *data)
|
|
|
|
|
{
|
2005-01-30 19:33:29 +00:00
|
|
|
ConnectionSetup *cs;
|
|
|
|
|
|
|
|
|
|
cs = data;
|
2003-03-15 20:47:16 +00:00
|
|
|
|
2005-01-30 19:33:29 +00:00
|
|
|
connection_setup_remove_timeout (cs, timeout);
|
2003-03-15 20:47:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
timeout_toggled (DBusTimeout *timeout,
|
|
|
|
|
void *data)
|
|
|
|
|
{
|
|
|
|
|
/* Because we just exit on OOM, enable/disable is
|
|
|
|
|
* no different from add/remove
|
|
|
|
|
*/
|
|
|
|
|
if (dbus_timeout_get_enabled (timeout))
|
|
|
|
|
add_timeout (timeout, data);
|
|
|
|
|
else
|
|
|
|
|
remove_timeout (timeout, data);
|
2003-01-21 Anders Carlsson <andersca@codefactory.se>
* dbus/dbus-connection.c: (dbus_connection_send_message):
Add a new client_serial parameter.
(dbus_connection_send_message_with_reply):
Remove a @todo since we've implemented the blocking function.
(dbus_connection_send_message_with_reply_and_block):
New function that sends a message and waits for a reply and
then returns the reply.
* dbus/dbus-connection.h:
Add new functions.
* dbus/dbus-errors.c: (dbus_result_to_string):
* dbus/dbus-errors.h:
Add new DBUS_RESULT.
* dbus/dbus-message-internal.h:
* dbus/dbus-message.c: (_dbus_message_get_reply_serial),
(_dbus_message_set_sender), (dbus_message_write_header),
(dbus_message_new_reply), (decode_header_data),
(_dbus_message_loader_return_buffer), (_dbus_message_test):
* dbus/dbus-message.h:
Add new functions that set the reply serial and sender.
Also marshal and demarshal them correctly and add test.
* dbus/dbus-protocol.h:
Add new DBUS_MESSAGE_TYPE_SENDER.
* glib/dbus-glib.h:
* glib/dbus-gmain.c: (watch_callback), (free_callback_data),
(add_watch), (remove_watch), (add_timeout), (remove_timeout),
(dbus_connection_hookup_with_g_main):
* glib/test-dbus-glib.c: (main):
Rewrite to use GIOChannel and remove the GSource crack.
* test/echo-client.c: (main):
* test/watch.c: (check_messages):
Update for changed APIs
2003-01-21 09:23:18 +00:00
|
|
|
}
|
2002-12-16 Anders Carlsson <andersca@codefactory.se>
* Makefile.am:
* configure.in:
Add GLib checks and fixup .pc files
* glib/Makefile.am:
* glib/dbus-glib.h:
* glib/dbus-gmain.c: (gdbus_connection_prepare),
(gdbus_connection_check), (gdbus_connection_dispatch),
(gdbus_add_connection_watch), (gdbus_remove_connection_watch),
(dbus_connection_gsource_new):
* glib/dbus-gthread.c: (dbus_gmutex_new), (dbus_gmutex_free),
(dbus_gmutex_lock), (dbus_gmutex_unlock), (dbus_gthread_init):
* glib/test-dbus-glib.c: (message_handler), (main):
Add GLib support.
2002-12-16 00:26:05 +00:00
|
|
|
|
2003-02-26 15:52:25 +00:00
|
|
|
static void
|
|
|
|
|
wakeup_main (void *data)
|
|
|
|
|
{
|
2005-01-30 19:33:29 +00:00
|
|
|
ConnectionSetup *cs = data;
|
2003-04-24 02:22:49 +00:00
|
|
|
|
2005-01-30 19:33:29 +00:00
|
|
|
g_main_context_wakeup (cs->context);
|
2003-02-26 15:52:25 +00:00
|
|
|
}
|
|
|
|
|
|
2005-01-30 19:33:29 +00:00
|
|
|
|
|
|
|
|
/* Move to a new context */
|
|
|
|
|
static ConnectionSetup*
|
|
|
|
|
connection_setup_new_from_old (GMainContext *context,
|
|
|
|
|
ConnectionSetup *old)
|
2005-01-30 18:25:14 +00:00
|
|
|
{
|
2005-01-30 19:33:29 +00:00
|
|
|
GSList *tmp;
|
|
|
|
|
ConnectionSetup *cs;
|
|
|
|
|
|
|
|
|
|
g_assert (old->context != context);
|
|
|
|
|
|
2005-01-30 20:06:52 +00:00
|
|
|
cs = connection_setup_new (context, old->connection);
|
2005-01-30 19:33:29 +00:00
|
|
|
|
|
|
|
|
tmp = old->ios;
|
|
|
|
|
while (tmp != NULL)
|
2005-01-30 18:25:14 +00:00
|
|
|
{
|
2005-01-30 19:33:29 +00:00
|
|
|
IOHandler *handler = tmp->data;
|
2005-01-30 18:25:14 +00:00
|
|
|
|
2005-01-30 19:33:29 +00:00
|
|
|
connection_setup_add_watch (cs, handler->watch);
|
|
|
|
|
|
|
|
|
|
tmp = tmp->next;
|
2005-01-30 18:25:14 +00:00
|
|
|
}
|
|
|
|
|
|
2005-01-30 19:33:29 +00:00
|
|
|
tmp = old->timeouts;
|
|
|
|
|
while (tmp != NULL)
|
|
|
|
|
{
|
|
|
|
|
TimeoutHandler *handler = tmp->data;
|
2005-01-30 18:25:14 +00:00
|
|
|
|
2005-01-30 19:33:29 +00:00
|
|
|
connection_setup_add_timeout (cs, handler->timeout);
|
|
|
|
|
|
|
|
|
|
tmp = tmp->next;
|
|
|
|
|
}
|
2005-01-30 18:25:14 +00:00
|
|
|
|
2005-01-30 19:33:29 +00:00
|
|
|
return cs;
|
2005-01-30 18:25:14 +00:00
|
|
|
}
|
2003-02-26 15:52:25 +00:00
|
|
|
|
2003-02-26 06:42:57 +00:00
|
|
|
/** @} */ /* End of GLib bindings internals */
|
|
|
|
|
|
|
|
|
|
/** @addtogroup DBusGLib
|
|
|
|
|
* @{
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Sets the watch and timeout functions of a #DBusConnection
|
|
|
|
|
* to integrate the connection with the GLib main loop.
|
2003-04-29 22:57:13 +00:00
|
|
|
* Pass in #NULL for the #GMainContext unless you're
|
|
|
|
|
* doing something specialized.
|
2003-02-26 06:42:57 +00:00
|
|
|
*
|
2003-10-03 03:55:35 +00:00
|
|
|
* If called twice for the same context, does nothing the second
|
|
|
|
|
* time. If called once with context A and once with context B,
|
|
|
|
|
* context B replaces context A as the context monitoring the
|
|
|
|
|
* connection.
|
|
|
|
|
*
|
2003-02-26 06:42:57 +00:00
|
|
|
* @param connection the connection
|
2003-04-29 22:57:13 +00:00
|
|
|
* @param context the #GMainContext or #NULL for default context
|
2003-02-26 06:42:57 +00:00
|
|
|
*/
|
|
|
|
|
void
|
2003-04-24 02:22:49 +00:00
|
|
|
dbus_connection_setup_with_g_main (DBusConnection *connection,
|
|
|
|
|
GMainContext *context)
|
2003-02-26 06:42:57 +00:00
|
|
|
{
|
2005-01-30 19:33:29 +00:00
|
|
|
ConnectionSetup *old_setup;
|
|
|
|
|
ConnectionSetup *cs;
|
2003-10-03 03:55:35 +00:00
|
|
|
|
|
|
|
|
/* FIXME we never free the slot, so its refcount just keeps growing,
|
|
|
|
|
* which is kind of broken.
|
|
|
|
|
*/
|
|
|
|
|
dbus_connection_allocate_data_slot (&connection_slot);
|
|
|
|
|
if (connection_slot < 0)
|
|
|
|
|
goto nomem;
|
|
|
|
|
|
|
|
|
|
if (context == NULL)
|
|
|
|
|
context = g_main_context_default ();
|
2005-01-30 19:33:29 +00:00
|
|
|
|
|
|
|
|
cs = NULL;
|
2003-10-03 03:55:35 +00:00
|
|
|
|
2005-01-30 19:33:29 +00:00
|
|
|
old_setup = dbus_connection_get_data (connection, connection_slot);
|
|
|
|
|
if (old_setup != NULL)
|
2003-10-03 03:55:35 +00:00
|
|
|
{
|
2005-01-30 19:33:29 +00:00
|
|
|
if (old_setup->context == context)
|
2003-10-03 03:55:35 +00:00
|
|
|
return; /* nothing to do */
|
2003-02-26 06:42:57 +00:00
|
|
|
|
2005-01-30 19:33:29 +00:00
|
|
|
cs = connection_setup_new_from_old (context, old_setup);
|
|
|
|
|
|
|
|
|
|
/* Nuke the old setup */
|
2003-10-03 03:55:35 +00:00
|
|
|
dbus_connection_set_data (connection, connection_slot, NULL, NULL);
|
2005-01-30 19:33:29 +00:00
|
|
|
old_setup = NULL;
|
2003-10-03 03:55:35 +00:00
|
|
|
}
|
2002-12-16 Anders Carlsson <andersca@codefactory.se>
* Makefile.am:
* configure.in:
Add GLib checks and fixup .pc files
* glib/Makefile.am:
* glib/dbus-glib.h:
* glib/dbus-gmain.c: (gdbus_connection_prepare),
(gdbus_connection_check), (gdbus_connection_dispatch),
(gdbus_add_connection_watch), (gdbus_remove_connection_watch),
(dbus_connection_gsource_new):
* glib/dbus-gthread.c: (dbus_gmutex_new), (dbus_gmutex_free),
(dbus_gmutex_lock), (dbus_gmutex_unlock), (dbus_gthread_init):
* glib/test-dbus-glib.c: (message_handler), (main):
Add GLib support.
2002-12-16 00:26:05 +00:00
|
|
|
|
2005-01-30 19:33:29 +00:00
|
|
|
if (cs == NULL)
|
2005-01-30 20:06:52 +00:00
|
|
|
cs = connection_setup_new (context, connection);
|
2005-01-30 19:33:29 +00:00
|
|
|
|
|
|
|
|
if (!dbus_connection_set_data (connection, connection_slot, cs,
|
|
|
|
|
(DBusFreeFunction)connection_setup_free))
|
|
|
|
|
goto nomem;
|
|
|
|
|
|
2003-03-14 01:27:58 +00:00
|
|
|
if (!dbus_connection_set_watch_functions (connection,
|
|
|
|
|
add_watch,
|
|
|
|
|
remove_watch,
|
2003-03-15 20:47:16 +00:00
|
|
|
watch_toggled,
|
2005-01-30 19:33:29 +00:00
|
|
|
cs, NULL))
|
2003-03-14 01:27:58 +00:00
|
|
|
goto nomem;
|
2003-01-25 21:22:57 +00:00
|
|
|
|
2003-03-14 01:27:58 +00:00
|
|
|
if (!dbus_connection_set_timeout_functions (connection,
|
|
|
|
|
add_timeout,
|
|
|
|
|
remove_timeout,
|
2003-03-15 20:47:16 +00:00
|
|
|
timeout_toggled,
|
2005-01-30 19:33:29 +00:00
|
|
|
cs, NULL))
|
2003-03-14 01:27:58 +00:00
|
|
|
goto nomem;
|
|
|
|
|
|
2003-02-26 15:52:25 +00:00
|
|
|
dbus_connection_set_wakeup_main_function (connection,
|
|
|
|
|
wakeup_main,
|
2005-01-30 19:33:29 +00:00
|
|
|
cs, NULL);
|
2003-02-26 15:52:25 +00:00
|
|
|
|
2003-02-26 06:42:57 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
nomem:
|
|
|
|
|
g_error ("Not enough memory to set up DBusConnection for use with GLib");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Sets the watch and timeout functions of a #DBusServer
|
|
|
|
|
* to integrate the server with the GLib main loop.
|
2003-04-29 22:57:13 +00:00
|
|
|
* In most cases the context argument should be #NULL.
|
2003-02-26 06:42:57 +00:00
|
|
|
*
|
2003-10-03 03:55:35 +00:00
|
|
|
* If called twice for the same context, does nothing the second
|
|
|
|
|
* time. If called once with context A and once with context B,
|
|
|
|
|
* context B replaces context A as the context monitoring the
|
|
|
|
|
* connection.
|
|
|
|
|
*
|
2003-02-26 06:42:57 +00:00
|
|
|
* @param server the server
|
2003-04-29 22:57:13 +00:00
|
|
|
* @param context the #GMainContext or #NULL for default
|
2003-02-26 06:42:57 +00:00
|
|
|
*/
|
|
|
|
|
void
|
2003-04-29 22:57:13 +00:00
|
|
|
dbus_server_setup_with_g_main (DBusServer *server,
|
|
|
|
|
GMainContext *context)
|
2003-02-26 06:42:57 +00:00
|
|
|
{
|
2005-01-30 19:33:29 +00:00
|
|
|
ConnectionSetup *old_setup;
|
|
|
|
|
ConnectionSetup *cs;
|
|
|
|
|
|
|
|
|
|
/* FIXME we never free the slot, so its refcount just keeps growing,
|
|
|
|
|
* which is kind of broken.
|
|
|
|
|
*/
|
2003-10-03 03:55:35 +00:00
|
|
|
dbus_server_allocate_data_slot (&server_slot);
|
|
|
|
|
if (server_slot < 0)
|
|
|
|
|
goto nomem;
|
|
|
|
|
|
|
|
|
|
if (context == NULL)
|
|
|
|
|
context = g_main_context_default ();
|
2005-01-30 19:33:29 +00:00
|
|
|
|
|
|
|
|
cs = NULL;
|
2003-10-03 03:55:35 +00:00
|
|
|
|
2005-01-30 19:33:29 +00:00
|
|
|
old_setup = dbus_server_get_data (server, server_slot);
|
|
|
|
|
if (old_setup != NULL)
|
2003-10-03 03:55:35 +00:00
|
|
|
{
|
2005-01-30 19:33:29 +00:00
|
|
|
if (old_setup->context == context)
|
2003-10-03 03:55:35 +00:00
|
|
|
return; /* nothing to do */
|
|
|
|
|
|
2005-01-30 19:33:29 +00:00
|
|
|
cs = connection_setup_new_from_old (context, old_setup);
|
|
|
|
|
|
|
|
|
|
/* Nuke the old setup */
|
2003-10-03 03:55:35 +00:00
|
|
|
dbus_server_set_data (server, server_slot, NULL, NULL);
|
2005-01-30 19:33:29 +00:00
|
|
|
old_setup = NULL;
|
2003-10-03 03:55:35 +00:00
|
|
|
}
|
2003-02-26 06:42:57 +00:00
|
|
|
|
2005-01-30 19:33:29 +00:00
|
|
|
if (cs == NULL)
|
2005-01-30 20:06:52 +00:00
|
|
|
cs = connection_setup_new (context, NULL);
|
2005-01-30 19:33:29 +00:00
|
|
|
|
|
|
|
|
if (!dbus_server_set_data (server, server_slot, cs,
|
|
|
|
|
(DBusFreeFunction)connection_setup_free))
|
|
|
|
|
goto nomem;
|
|
|
|
|
|
|
|
|
|
if (!dbus_server_set_watch_functions (server,
|
|
|
|
|
add_watch,
|
|
|
|
|
remove_watch,
|
|
|
|
|
watch_toggled,
|
|
|
|
|
cs, NULL))
|
2003-02-26 06:42:57 +00:00
|
|
|
goto nomem;
|
|
|
|
|
|
2005-01-30 19:33:29 +00:00
|
|
|
if (!dbus_server_set_timeout_functions (server,
|
|
|
|
|
add_timeout,
|
|
|
|
|
remove_timeout,
|
|
|
|
|
timeout_toggled,
|
|
|
|
|
cs, NULL))
|
|
|
|
|
goto nomem;
|
|
|
|
|
|
2003-02-26 06:42:57 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
nomem:
|
|
|
|
|
g_error ("Not enough memory to set up DBusServer for use with GLib");
|
2002-12-16 Anders Carlsson <andersca@codefactory.se>
* Makefile.am:
* configure.in:
Add GLib checks and fixup .pc files
* glib/Makefile.am:
* glib/dbus-glib.h:
* glib/dbus-gmain.c: (gdbus_connection_prepare),
(gdbus_connection_check), (gdbus_connection_dispatch),
(gdbus_add_connection_watch), (gdbus_remove_connection_watch),
(dbus_connection_gsource_new):
* glib/dbus-gthread.c: (dbus_gmutex_new), (dbus_gmutex_free),
(dbus_gmutex_lock), (dbus_gmutex_unlock), (dbus_gthread_init):
* glib/test-dbus-glib.c: (message_handler), (main):
Add GLib support.
2002-12-16 00:26:05 +00:00
|
|
|
}
|
2003-02-26 06:42:57 +00:00
|
|
|
|
2003-10-03 03:55:35 +00:00
|
|
|
/**
|
2004-06-20 15:28:15 +00:00
|
|
|
* Returns a connection to the given bus. The connection is a global variable
|
|
|
|
|
* shared with other callers of this function.
|
|
|
|
|
*
|
|
|
|
|
* (Internally, calls dbus_bus_get() then calls
|
|
|
|
|
* dbus_connection_setup_with_g_main() on the result.)
|
2003-10-03 03:55:35 +00:00
|
|
|
*
|
|
|
|
|
* @param type bus type
|
|
|
|
|
* @param error address where an error can be returned.
|
|
|
|
|
* @returns a DBusConnection
|
|
|
|
|
*/
|
2004-06-20 15:28:15 +00:00
|
|
|
DBusGConnection*
|
|
|
|
|
dbus_g_bus_get (DBusBusType type,
|
|
|
|
|
GError **error)
|
2003-10-03 03:55:35 +00:00
|
|
|
{
|
|
|
|
|
DBusConnection *connection;
|
|
|
|
|
DBusError derror;
|
|
|
|
|
|
|
|
|
|
g_return_val_if_fail (error == NULL || *error == NULL, NULL);
|
2005-06-12 Colin Walters <walters@verbum.org>
Async signals and various bugfixes and testing by
Ross Burton <ross@burtonini.com>.
* glib/dbus-gvalue.h: (struct DBusBasicGValue): Delete.
(dbus_gvalue_genmarshal_name_from_type)
(dbus_gvalue_ctype_from_type): Moved to dbus-binding-tool-glib.c.
(dbus_gtype_to_dbus_type): Renamed to dbus_gtype_from_signature.
(dbus_g_value_types_init, dbus_gtype_from_signature)
(dbus_gtype_from_signature_iter, dbus_gtype_to_signature)
(dbus_gtypes_from_arg_signature): New function prototypes.
(dbus_gvalue_demarshal): Take context and error arguments.
(dbus_gvalue_demarshal_variant): New function.
(dbus_gvalue_demarshal_message): New function.
(dbus_gvalue_store): Delete.
* glib/dbus-gvalue.c:
File has been almost entirely rewritten; now we special-case
more types such as DBUS_TYPE_SIGNATURE, handle arrays and
hash tables correctly, etc. Full support for recursive values
is not yet complete.
* glib/dbus-gproxy.c (dbus_g_proxy_class_init): Change last
argument of signal to G_TYPE_POINTER since we now pass a
structure.
(lookup_g_marshaller): Delete in favor of
_dbus_gobject_lookup_marshaller.
(marshal_dbus_message_to_g_marshaller): Use
_dbus_gobject_lookup_marshaller and dbus_gvalue_demarshal_message
to handle remote signal callbacks.
(dbus_g_proxy_new_from_proxy): New function; creates a new
DBusGProxy by copying an existing one.
(dbus_g_proxy_get_interface, dbus_g_proxy_set_interface)
(dbus_g_proxy_get_path): New functions.
(dbus_g_proxy_marshal_args_to_message): New function;
factored out of existing code.
(DBUS_G_VALUE_ARRAY_COLLECT_ALL): Collect all arguments
from a varargs array.
(dbus_g_proxy_begin_call_internal): New function.
(dbus_g_proxy_end_call_internal): New function.
(dbus_g_proxy_begin_call): Take GTypes instead of DBus types
as arguments; simply invoke dbus_g_proxy_begin_call_internal
after collecting args into value array.
(dbus_g_proxy_end_call): Take GTypes instead of DBus types;
invoke dbus_g_proxy_end_call_internal.
(dbus_g_proxy_invoke): Simply invoke begin_call_interanl and
end_call_internal.
(dbus_g_proxy_call_no_reply): Take GTypes instead of DBus
types.
(array_free_all): New function.
(dbus_g_proxy_add_signal): Take GTypes.
* glib/dbus-gobject.h:
(_dbus_glib_marshal_dbus_message_to_gvalue_array): Delete.
(_dbus_gobject_get_path, _dbus_gobject_lookup_marshaller):
Prototype.
* glib/dbus-gobject.c: Add a global marshal_table hash which
stores mappings from type signatures to marshallers. Change lots
of invocations of dbus_gtype_to_dbus_type to
dbus_gtype_to_signature.
(_dbus_glib_marshal_dbus_message_to_gvalue_array): Delete.
(introspect_signals): Fix test for query.return_type.
(set_object_property): Update invocation of dbus_gvalue_demarshal.
(invoke_object_method): Many changes. Handle asynchronous
invocations. Convert arguments with
dbus_gvalue_demarshal_message. Handle errors. Use
DBusSignatureIter instead of strlen on args. Handle all arguments
generically. Special-case variants.
(dbus_g_method_return, dbus_g_method_return_error): New function.
(DBusGSignalClosure): New structure, closes over signal
information.
(dbus_g_signal_closure_new): New function.
(dbus_g_signal_closure_finalize): New function.
(signal_emitter_marshaller): New function; is special marshaller
which emits signals on bus.
(export_signals): New function; introspects object signals and
connects to them.
(dbus_g_object_type_install_info): Take GType instead of
GObjectClass.
(dbus_g_connection_register_g_object): Invoke export_signals.
(dbus_g_connection_lookup_g_object): New function.
(DBusGFuncSignature) New structure; used for mapping type
signatures to marshallers.
(funcsig_hash): New function; hashes DBusGFuncSignature.
(funcsig_equal): New function; compares DBusGFuncSignature.
(_dbus_gobject_lookup_marshaller): New function.
(dbus_g_object_register_marshaller): New function; used to
register a marshaller at runtime for a particular signature.
* glib/dbus-gmain.c (_dbus_gmain_test): Add various tests.
* glib/dbus-binding-tool-glib.h: Add DBUS_GLIB_ANNOTATION_ASYNC
which notes a server method implementation should be
asynchronous.
* glib/dbus-binding-tool-glib.c
(dbus_binding_tool_output_glib_server): Call
dbus_g_value_types_init.
(write_formal_parameters): Use dbus_gtype_from_signature. Handle
variants specially.
(dbus_g_type_get_lookup_function): Turn GType into an invocation
of a lookup function.
(write_args_for_direction): Use dbus_g_type_get_lookup_function.
(write_untyped_out_args): New method; write output arguments.
(write_formal_declarations_for_direction): Function for
writing prototypes.
(write_formal_parameters_for_direction): Function for
writing implementations.
(write_typed_args_for_direction): Function for writing
arguments prefixed with GTypes.
(write_async_method_client): Write out async version
of method.
* glib/dbus-binding-tool-glib.c: Include dbus-gvalue-utils.h.
(dbus_g_type_get_marshal_name): Move mapping from GType
to marshal name into here.
(dbus_g_type_get_c_name): Move into here.
(compute_marshaller): Convert signature to type with
dbus_gtype_from_signature, use dbus_g_type_get_marshal_name.
(compute_marshaller_name): Ditto.
(compute_marshaller): Handle async signal annotations.
(gather_marshallers): Return if we don't have a known
prefix.
(generate_glue): Collect introspection blob here, and
write all of the blob at the end. This allows an object
with multiple interfaces to work.
Mark async methods in introspection blob.
* glib/Makefile.am (libdbus_glib_1_la_SOURCES): Add
dbus-gtype-specialized.c, dbus-gtype-specialized.h,
dbus-gvalue-utils.h, dbus-gvalue-utils.c.
* dbus/dbus-glib.h: Don't include dbus-protocol.h; this
avoids people accidentally using DBUS_TYPE_* which should
not be necessary anymore.
Do include dbus-gtype-specialized.h, which are utilities
for GLib container types.
Add various #defines for types such as
DBUS_TYPE_G_BOOLEAN_ARRAY.
(DBusGValueIterator, DBusGValue): Define, not fully used
yet.
(dbus_g_value_get_g_type): Type for recursive value.
(dbus_g_value_open, dbus_g_value_iterator_get_value)
(dbus_g_value_iterator_get_values, dbus_g_value_iterator_recurse)
(dbus_g_value_free): Prototypes.
(dbus_g_object_register_marshaller, dbus_g_proxy_new_from_proxy): Prototype.
(dbus_g_proxy_set_interface): Prototype.
(dbus_g_proxy_begin_call, dbus_g_proxy_end_call)
(dbus_g_proxy_call_no_reply): Take GLib types instead of DBus
types.
(dbus_g_proxy_get_path, dbus_g_proxy_get_interface):
Accessors.
(DBusGAsyncData, DBusGMethodInvocation): Structures for
doing async invocations.
(dbus_g_method_return, dbus_g_method_return_error):
Prototypes.
* doc/dbus-tutorial.xml: Update GLib section.
* tools/dbus-viewer.c (load_child_nodes): Update
for new invocation type of dbus_g_proxy_end_call.
(load_from_service_thread_func): Ditto.
* tools/print-introspect.c (main): Ditto.
* tools/dbus-names-model.c (have_names_notify)
(names_model_reload, names_model_set_connection)
Use GTypes.
* python/Makefile.am (INCLUDES): Define DBUS_COMPILATION,
needed since Python bindings use GLib bindings.
* test/glib/Makefile.am (INCLUDES): Define DBUS_COMPILATION.
Add --prefix argument.
* tools/Makefile.am: Define DBUS_COMPILATION. Remove
unneeded --ignore-unsupported arg.
* test/glib/test-service-glib.c:
* test/glib/test-service-glib.xml:
* test/glib/test-dbus-glib.c: Add many more tests.
2005-06-13 03:01:30 +00:00
|
|
|
|
|
|
|
|
dbus_g_value_types_init ();
|
2003-10-03 03:55:35 +00:00
|
|
|
|
|
|
|
|
dbus_error_init (&derror);
|
|
|
|
|
|
|
|
|
|
connection = dbus_bus_get (type, &derror);
|
|
|
|
|
if (connection == NULL)
|
|
|
|
|
{
|
2005-06-26 17:02:09 +00:00
|
|
|
dbus_g_error_set (error, derror.name, derror.message);
|
2003-10-03 03:55:35 +00:00
|
|
|
dbus_error_free (&derror);
|
2004-10-07 09:56:02 +00:00
|
|
|
return NULL;
|
2003-10-03 03:55:35 +00:00
|
|
|
}
|
2004-10-07 09:56:02 +00:00
|
|
|
|
|
|
|
|
/* does nothing if it's already been done */
|
|
|
|
|
dbus_connection_setup_with_g_main (connection, NULL);
|
2003-10-03 03:55:35 +00:00
|
|
|
|
2004-06-20 15:28:15 +00:00
|
|
|
return DBUS_G_CONNECTION_FROM_CONNECTION (connection);
|
2003-10-03 03:55:35 +00:00
|
|
|
}
|
|
|
|
|
|
2003-02-26 06:42:57 +00:00
|
|
|
/** @} */ /* end of public API */
|
2003-09-01 18:02:06 +00:00
|
|
|
|
|
|
|
|
#ifdef DBUS_BUILD_TESTS
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @ingroup DBusGLibInternals
|
|
|
|
|
* Unit test for GLib main loop integration
|
|
|
|
|
* @returns #TRUE on success.
|
|
|
|
|
*/
|
2004-06-20 15:28:15 +00:00
|
|
|
gboolean
|
2003-09-01 18:02:06 +00:00
|
|
|
_dbus_gmain_test (const char *test_data_dir)
|
|
|
|
|
{
|
2005-06-12 Colin Walters <walters@verbum.org>
Async signals and various bugfixes and testing by
Ross Burton <ross@burtonini.com>.
* glib/dbus-gvalue.h: (struct DBusBasicGValue): Delete.
(dbus_gvalue_genmarshal_name_from_type)
(dbus_gvalue_ctype_from_type): Moved to dbus-binding-tool-glib.c.
(dbus_gtype_to_dbus_type): Renamed to dbus_gtype_from_signature.
(dbus_g_value_types_init, dbus_gtype_from_signature)
(dbus_gtype_from_signature_iter, dbus_gtype_to_signature)
(dbus_gtypes_from_arg_signature): New function prototypes.
(dbus_gvalue_demarshal): Take context and error arguments.
(dbus_gvalue_demarshal_variant): New function.
(dbus_gvalue_demarshal_message): New function.
(dbus_gvalue_store): Delete.
* glib/dbus-gvalue.c:
File has been almost entirely rewritten; now we special-case
more types such as DBUS_TYPE_SIGNATURE, handle arrays and
hash tables correctly, etc. Full support for recursive values
is not yet complete.
* glib/dbus-gproxy.c (dbus_g_proxy_class_init): Change last
argument of signal to G_TYPE_POINTER since we now pass a
structure.
(lookup_g_marshaller): Delete in favor of
_dbus_gobject_lookup_marshaller.
(marshal_dbus_message_to_g_marshaller): Use
_dbus_gobject_lookup_marshaller and dbus_gvalue_demarshal_message
to handle remote signal callbacks.
(dbus_g_proxy_new_from_proxy): New function; creates a new
DBusGProxy by copying an existing one.
(dbus_g_proxy_get_interface, dbus_g_proxy_set_interface)
(dbus_g_proxy_get_path): New functions.
(dbus_g_proxy_marshal_args_to_message): New function;
factored out of existing code.
(DBUS_G_VALUE_ARRAY_COLLECT_ALL): Collect all arguments
from a varargs array.
(dbus_g_proxy_begin_call_internal): New function.
(dbus_g_proxy_end_call_internal): New function.
(dbus_g_proxy_begin_call): Take GTypes instead of DBus types
as arguments; simply invoke dbus_g_proxy_begin_call_internal
after collecting args into value array.
(dbus_g_proxy_end_call): Take GTypes instead of DBus types;
invoke dbus_g_proxy_end_call_internal.
(dbus_g_proxy_invoke): Simply invoke begin_call_interanl and
end_call_internal.
(dbus_g_proxy_call_no_reply): Take GTypes instead of DBus
types.
(array_free_all): New function.
(dbus_g_proxy_add_signal): Take GTypes.
* glib/dbus-gobject.h:
(_dbus_glib_marshal_dbus_message_to_gvalue_array): Delete.
(_dbus_gobject_get_path, _dbus_gobject_lookup_marshaller):
Prototype.
* glib/dbus-gobject.c: Add a global marshal_table hash which
stores mappings from type signatures to marshallers. Change lots
of invocations of dbus_gtype_to_dbus_type to
dbus_gtype_to_signature.
(_dbus_glib_marshal_dbus_message_to_gvalue_array): Delete.
(introspect_signals): Fix test for query.return_type.
(set_object_property): Update invocation of dbus_gvalue_demarshal.
(invoke_object_method): Many changes. Handle asynchronous
invocations. Convert arguments with
dbus_gvalue_demarshal_message. Handle errors. Use
DBusSignatureIter instead of strlen on args. Handle all arguments
generically. Special-case variants.
(dbus_g_method_return, dbus_g_method_return_error): New function.
(DBusGSignalClosure): New structure, closes over signal
information.
(dbus_g_signal_closure_new): New function.
(dbus_g_signal_closure_finalize): New function.
(signal_emitter_marshaller): New function; is special marshaller
which emits signals on bus.
(export_signals): New function; introspects object signals and
connects to them.
(dbus_g_object_type_install_info): Take GType instead of
GObjectClass.
(dbus_g_connection_register_g_object): Invoke export_signals.
(dbus_g_connection_lookup_g_object): New function.
(DBusGFuncSignature) New structure; used for mapping type
signatures to marshallers.
(funcsig_hash): New function; hashes DBusGFuncSignature.
(funcsig_equal): New function; compares DBusGFuncSignature.
(_dbus_gobject_lookup_marshaller): New function.
(dbus_g_object_register_marshaller): New function; used to
register a marshaller at runtime for a particular signature.
* glib/dbus-gmain.c (_dbus_gmain_test): Add various tests.
* glib/dbus-binding-tool-glib.h: Add DBUS_GLIB_ANNOTATION_ASYNC
which notes a server method implementation should be
asynchronous.
* glib/dbus-binding-tool-glib.c
(dbus_binding_tool_output_glib_server): Call
dbus_g_value_types_init.
(write_formal_parameters): Use dbus_gtype_from_signature. Handle
variants specially.
(dbus_g_type_get_lookup_function): Turn GType into an invocation
of a lookup function.
(write_args_for_direction): Use dbus_g_type_get_lookup_function.
(write_untyped_out_args): New method; write output arguments.
(write_formal_declarations_for_direction): Function for
writing prototypes.
(write_formal_parameters_for_direction): Function for
writing implementations.
(write_typed_args_for_direction): Function for writing
arguments prefixed with GTypes.
(write_async_method_client): Write out async version
of method.
* glib/dbus-binding-tool-glib.c: Include dbus-gvalue-utils.h.
(dbus_g_type_get_marshal_name): Move mapping from GType
to marshal name into here.
(dbus_g_type_get_c_name): Move into here.
(compute_marshaller): Convert signature to type with
dbus_gtype_from_signature, use dbus_g_type_get_marshal_name.
(compute_marshaller_name): Ditto.
(compute_marshaller): Handle async signal annotations.
(gather_marshallers): Return if we don't have a known
prefix.
(generate_glue): Collect introspection blob here, and
write all of the blob at the end. This allows an object
with multiple interfaces to work.
Mark async methods in introspection blob.
* glib/Makefile.am (libdbus_glib_1_la_SOURCES): Add
dbus-gtype-specialized.c, dbus-gtype-specialized.h,
dbus-gvalue-utils.h, dbus-gvalue-utils.c.
* dbus/dbus-glib.h: Don't include dbus-protocol.h; this
avoids people accidentally using DBUS_TYPE_* which should
not be necessary anymore.
Do include dbus-gtype-specialized.h, which are utilities
for GLib container types.
Add various #defines for types such as
DBUS_TYPE_G_BOOLEAN_ARRAY.
(DBusGValueIterator, DBusGValue): Define, not fully used
yet.
(dbus_g_value_get_g_type): Type for recursive value.
(dbus_g_value_open, dbus_g_value_iterator_get_value)
(dbus_g_value_iterator_get_values, dbus_g_value_iterator_recurse)
(dbus_g_value_free): Prototypes.
(dbus_g_object_register_marshaller, dbus_g_proxy_new_from_proxy): Prototype.
(dbus_g_proxy_set_interface): Prototype.
(dbus_g_proxy_begin_call, dbus_g_proxy_end_call)
(dbus_g_proxy_call_no_reply): Take GLib types instead of DBus
types.
(dbus_g_proxy_get_path, dbus_g_proxy_get_interface):
Accessors.
(DBusGAsyncData, DBusGMethodInvocation): Structures for
doing async invocations.
(dbus_g_method_return, dbus_g_method_return_error):
Prototypes.
* doc/dbus-tutorial.xml: Update GLib section.
* tools/dbus-viewer.c (load_child_nodes): Update
for new invocation type of dbus_g_proxy_end_call.
(load_from_service_thread_func): Ditto.
* tools/print-introspect.c (main): Ditto.
* tools/dbus-names-model.c (have_names_notify)
(names_model_reload, names_model_set_connection)
Use GTypes.
* python/Makefile.am (INCLUDES): Define DBUS_COMPILATION,
needed since Python bindings use GLib bindings.
* test/glib/Makefile.am (INCLUDES): Define DBUS_COMPILATION.
Add --prefix argument.
* tools/Makefile.am: Define DBUS_COMPILATION. Remove
unneeded --ignore-unsupported arg.
* test/glib/test-service-glib.c:
* test/glib/test-service-glib.xml:
* test/glib/test-dbus-glib.c: Add many more tests.
2005-06-13 03:01:30 +00:00
|
|
|
GType rectype;
|
|
|
|
|
GType gtype;
|
|
|
|
|
|
|
|
|
|
g_type_init ();
|
|
|
|
|
dbus_g_value_types_init ();
|
|
|
|
|
|
|
|
|
|
rectype = dbus_g_type_get_collection ("GArray", G_TYPE_UINT);
|
|
|
|
|
g_assert (rectype != G_TYPE_INVALID);
|
|
|
|
|
g_assert (!strcmp (g_type_name (rectype), "GArray+guint"));
|
|
|
|
|
|
|
|
|
|
gtype = dbus_gtype_from_signature ("au", TRUE);
|
|
|
|
|
g_assert (gtype == rectype);
|
|
|
|
|
|
|
|
|
|
rectype = dbus_g_type_get_map ("GHashTable", G_TYPE_STRING, G_TYPE_STRING);
|
|
|
|
|
g_assert (rectype != G_TYPE_INVALID);
|
|
|
|
|
g_assert (!strcmp (g_type_name (rectype), "GHashTable+gchararray+gchararray"));
|
|
|
|
|
|
|
|
|
|
gtype = dbus_gtype_from_signature ("a{ss}", TRUE);
|
|
|
|
|
g_assert (gtype == rectype);
|
|
|
|
|
|
|
|
|
|
gtype = dbus_gtype_from_signature ("o", FALSE);
|
|
|
|
|
g_assert (gtype == G_TYPE_OBJECT);
|
|
|
|
|
gtype = dbus_gtype_from_signature ("o", TRUE);
|
|
|
|
|
g_assert (gtype == DBUS_TYPE_G_PROXY);
|
2003-09-01 18:02:06 +00:00
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endif /* DBUS_BUILD_TESTS */
|