mirror of
https://gitlab.freedesktop.org/dbus/dbus.git
synced 2026-03-20 21:00:42 +01:00
* tools/Makefile.am: Kill of print-introspect in favor of using dbus-send --print-reply=literal. * tools/print-introspect.c: Deleted. * test/glib/test-service-glib.xml: * test/glib/test-service-glib.c (my_object_get_objs): New test for "ao". * test/glib/test-dbus-glib.c (echo_received_cb): Free echo data. (main): Test GetObjs. * glib/examples/statemachine/Makefile.am: * glib/examples/statemachine/sm-marshal.list: * glib/examples/statemachine/statemachine-client.c: * glib/examples/statemachine/statemachine-server.c: * glib/examples/statemachine/statemachine-server.xml: * glib/examples/statemachine/statemachine.c: * glib/examples/statemachine/statemachine.h: * glib/examples/statemachine/statemachine.xml: New example. * glib/examples/example-service.c (main): Move invocation of dbus_g_object_type_install_info earlier, to emphasize it should only be done once. * glib/examples/example-signal-emitter.c (main): Ditto. * glib/examples/Makefile.am (SUBDIRS): Include statemachine. * glib/dbus-gvalue.h (dbus_gtype_to_signature) (dbus_gvalue_marshal): Update prototypes. * glib/dbus-gvalue.c: Update all marshalling functions to take const GValue instead of GValue. (signature_iter_to_g_type_array): Return a GPtrArray for nonfixed types. (dbus_gvalue_to_signature): Update for dbus_gtype_to_signature change. (dbus_gtype_to_signature): Handle generic collecitons and maps. Return a newly-allocated string. (demarshal_proxy, demarshal_object_path, demarshal_object) (demarshal_strv, demarshal_ghashtable): Set error, don't assert if we get the wrong types from message. (get_type_demarshaller): New function, extracted from dbus_gvalue_demarshal. (demarshal_collection): New function, demarshals generic collection. (dbus_gvalue_demarshal): Just invoke result of get_type_demarshaller. Throw error if we don't have one. (marshal_garray_basic): Abort on OOM. (get_type_marshaller): New function, extracted from dbus_gvalue_marshal. (collection_marshal_iterator, marshal_collection): New functions; implements generic marshalling for an iteratable specialized collection. (dbus_gvalue_marshal): Just invoke result of get_type_marshaller. * glib/dbus-gvalue-utils.c (gvalue_from_ptrarray_value): Handle G_TYPE_STRING. (ptrarray_value_from_gvalue): Ditto. (ptrarray_append, ptrarray_free): New functions. (slist_constructor, slist_iterator, slist_copy_elt, slist_copy) (slist_append, slist_end_append, slist_free): New functions. (dbus_g_type_specialized_builtins_init): Add append fuctions for GPtrArray and GSList. Register GSList. (test_specialized_hash, _dbus_gvalue_utils_test): New functions. * glib/dbus-gtype-specialized.h (DBusGTypeSpecializedAppendContext): New. (dbus_g_type_specialized_collection_init_append) (dbus_g_type_specialized_collection_append) (dbus_g_type_specialized_collection_end_append): Prototype. (DBusGTypeSpecializedCollectionVtable): Add append_func and end_append_func. * glib/dbus-gtype-specialized.c (dbus_g_type_specialized_collection_init_append) (dbus_g_type_specialized_collection_append) (dbus_g_type_specialized_collection_end_append): New functions. (dbus_g_type_map_value_iterate): Take const GValue. (dbus_g_type_collection_value_iterate): Ditto. * glib/dbus-gtest.c (dbus_glib_internal_do_not_use_run_tests): Run _dbus_gvalue_utils_test. * glib/dbus-gtest.h: Prototype it. * glib/dbus-gproxy.c (dbus_g_proxy_manager_filter): Avoid using uninitialized owner_list. (dbus_g_proxy_begin_call_internal): Move return_if_fail to public API. (dbus_g_proxy_end_call_internal): Update to use error set from dbus_gvalue_demarshal instead of setting it here. (dbus_g_proxy_begin_call): Move return_if_fail here. * glib/dbus-gobject.c (write_interface): Update for dbus_gtype_to_signature returning new string. * configure.in: Add glib/examples/statemachine.
138 lines
3.5 KiB
C
138 lines
3.5 KiB
C
#include <dbus/dbus-glib.h>
|
|
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
|
|
static void lose (const char *fmt, ...) G_GNUC_NORETURN G_GNUC_PRINTF (1, 2);
|
|
static void lose_gerror (const char *prefix, GError *error) G_GNUC_NORETURN;
|
|
|
|
static void
|
|
lose (const char *str, ...)
|
|
{
|
|
va_list args;
|
|
|
|
va_start (args, str);
|
|
|
|
vfprintf (stderr, str, args);
|
|
fputc ('\n', stderr);
|
|
|
|
va_end (args);
|
|
|
|
exit (1);
|
|
}
|
|
|
|
static void
|
|
lose_gerror (const char *prefix, GError *error)
|
|
{
|
|
lose ("%s: %s", prefix, error->message);
|
|
}
|
|
|
|
typedef struct SomeObject SomeObject;
|
|
typedef struct SomeObjectClass SomeObjectClass;
|
|
|
|
GType some_object_get_type (void);
|
|
|
|
struct SomeObject
|
|
{
|
|
GObject parent;
|
|
};
|
|
|
|
struct SomeObjectClass
|
|
{
|
|
GObjectClass parent;
|
|
};
|
|
|
|
#define SOME_TYPE_OBJECT (some_object_get_type ())
|
|
#define SOME_OBJECT(object) (G_TYPE_CHECK_INSTANCE_CAST ((object), SOME_TYPE_OBJECT, SomeObject))
|
|
#define SOME_OBJECT_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), SOME_TYPE_OBJECT, SomeObjectClass))
|
|
#define SOME_IS_OBJECT(object) (G_TYPE_CHECK_INSTANCE_TYPE ((object), SOME_TYPE_OBJECT))
|
|
#define SOME_IS_OBJECT_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), SOME_TYPE_OBJECT))
|
|
#define SOME_OBJECT_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), SOME_TYPE_OBJECT, SomeObjectClass))
|
|
|
|
G_DEFINE_TYPE(SomeObject, some_object, G_TYPE_OBJECT)
|
|
|
|
gboolean some_object_hello_world (SomeObject *obj, const char *hello_message, char ***ret, GError **error);
|
|
gboolean some_object_get_tuple (SomeObject *obj, DBusGValue **ret, GError **error);
|
|
gboolean some_object_get_dict (SomeObject *obj, GHashTable **ret, GError **error);
|
|
|
|
#include "example-service-glue.h"
|
|
|
|
static void
|
|
some_object_init (SomeObject *obj)
|
|
{
|
|
}
|
|
|
|
static void
|
|
some_object_class_init (SomeObjectClass *klass)
|
|
{
|
|
}
|
|
|
|
gboolean
|
|
some_object_hello_world (SomeObject *obj, const char *hello_message, char ***ret, GError **error)
|
|
{
|
|
printf ("%s\n", hello_message);
|
|
*ret = g_new (char *, 3);
|
|
(*ret)[0] = g_strdup ("Hello");
|
|
(*ret)[1] = g_strdup (" from example-service.c");
|
|
(*ret)[2] = NULL;
|
|
|
|
return TRUE;
|
|
}
|
|
|
|
gboolean
|
|
some_object_get_tuple (SomeObject *obj, DBusGValue **ret, GError **error)
|
|
{
|
|
/* FIXME */
|
|
return TRUE;
|
|
}
|
|
|
|
gboolean
|
|
some_object_get_dict (SomeObject *obj, GHashTable **ret, GError **error)
|
|
{
|
|
*ret = g_hash_table_new (g_str_hash, g_str_equal);
|
|
g_hash_table_insert (*ret, "first", "Hello Dict");
|
|
g_hash_table_insert (*ret, "second", " from example-service.c");
|
|
return TRUE;
|
|
}
|
|
|
|
int
|
|
main (int argc, char **argv)
|
|
{
|
|
DBusGConnection *bus;
|
|
DBusGProxy *bus_proxy;
|
|
GError *error = NULL;
|
|
SomeObject *obj;
|
|
GMainLoop *mainloop;
|
|
guint request_name_result;
|
|
|
|
g_type_init ();
|
|
|
|
dbus_g_object_type_install_info (SOME_TYPE_OBJECT, &dbus_glib_some_object_object_info);
|
|
|
|
mainloop = g_main_loop_new (NULL, FALSE);
|
|
|
|
bus = dbus_g_bus_get (DBUS_BUS_SESSION, &error);
|
|
if (!bus)
|
|
lose_gerror ("Couldn't connect to session bus", error);
|
|
|
|
bus_proxy = dbus_g_proxy_new_for_name (bus, "org.freedesktop.DBus",
|
|
"/org/freedesktop/DBus",
|
|
"org.freedesktop.DBus");
|
|
|
|
if (!dbus_g_proxy_call (bus_proxy, "RequestName", &error,
|
|
G_TYPE_STRING, "org.designfu.SampleService",
|
|
G_TYPE_UINT, DBUS_NAME_FLAG_PROHIBIT_REPLACEMENT,
|
|
G_TYPE_INVALID,
|
|
G_TYPE_UINT, &request_name_result,
|
|
G_TYPE_INVALID))
|
|
lose_gerror ("Failed to acquire org.designfu.SampleService", error);
|
|
|
|
obj = g_object_new (SOME_TYPE_OBJECT, NULL);
|
|
|
|
dbus_g_connection_register_g_object (bus, "/SomeObject", G_OBJECT (obj));
|
|
|
|
printf ("service running\n");
|
|
|
|
g_main_loop_run (mainloop);
|
|
|
|
exit (0);
|
|
}
|