diff options
author | Rico Tzschichholz <ricotz@ubuntu.com> | 2021-05-23 17:50:12 +0200 |
---|---|---|
committer | Rico Tzschichholz <ricotz@ubuntu.com> | 2021-07-16 16:59:57 +0200 |
commit | 366590a71672106d8f8a820e79431df7f0c39337 (patch) | |
tree | af530265b03db60f5a9d5f39e7d9f4d098aa12f3 /tests/dbus | |
parent | 7c4a957606f5a5b2afc8078228f228c8f87ccce5 (diff) | |
download | vala-366590a71672106d8f8a820e79431df7f0c39337.tar.gz |
tests: Add expected generated C sources
Diffstat (limited to 'tests/dbus')
51 files changed, 34605 insertions, 0 deletions
diff --git a/tests/dbus/arrays_client.c-expected b/tests/dbus/arrays_client.c-expected new file mode 100644 index 000000000..8c17358f0 --- /dev/null +++ b/tests/dbus/arrays_client.c-expected @@ -0,0 +1,1153 @@ +/* dbus_arrays_client.c generated by valac, the Vala compiler + * generated from dbus_arrays_client.vala, do not modify */ + +#include <glib-object.h> +#include <gio/gio.h> +#include <glib.h> +#include <stdlib.h> +#include <string.h> + +#if !defined(VALA_EXTERN) +#if defined(_MSC_VER) +#define VALA_EXTERN __declspec(dllexport) extern +#elif __GNUC__ >= 4 +#define VALA_EXTERN __attribute__((visibility("default"))) extern +#else +#define VALA_EXTERN extern +#endif +#endif + +#define TYPE_TEST (test_get_type ()) +#define TEST(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TYPE_TEST, Test)) +#define IS_TEST(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TYPE_TEST)) +#define TEST_GET_INTERFACE(obj) (G_TYPE_INSTANCE_GET_INTERFACE ((obj), TYPE_TEST, TestIface)) + +typedef struct _Test Test; +typedef struct _TestIface TestIface; + +#define TYPE_TEST_PROXY (test_proxy_get_type ()) +typedef GDBusProxy TestProxy; +typedef GDBusProxyClass TestProxyClass; +#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL))) +#define _vala_assert(expr, msg) if G_LIKELY (expr) ; else g_assertion_message_expr (G_LOG_DOMAIN, __FILE__, __LINE__, G_STRFUNC, msg); +#define _vala_return_if_fail(expr, msg) if G_LIKELY (expr) ; else { g_return_if_fail_warning (G_LOG_DOMAIN, G_STRFUNC, msg); return; } +#define _vala_return_val_if_fail(expr, msg, val) if G_LIKELY (expr) ; else { g_return_if_fail_warning (G_LOG_DOMAIN, G_STRFUNC, msg); return val; } +#define _vala_warn_if_fail(expr, msg) if G_LIKELY (expr) ; else g_warn_message (G_LOG_DOMAIN, __FILE__, __LINE__, G_STRFUNC, msg); + +struct _TestIface { + GTypeInterface parent_iface; + gint* (*test_int) (Test* self, gint* i, gint i_length1, gint** j, gint* j_length1, gint* result_length1, GError** error); + gchar** (*test_string) (Test* self, gchar** s, gint s_length1, gchar*** t, gint* t_length1, gint* result_length1, GError** error); + gchar** (*get_test_property) (Test* self, gint* result_length1); + void (*set_test_property) (Test* self, gchar** value, gint value_length1); +}; + +VALA_EXTERN GType test_proxy_get_type (void) G_GNUC_CONST ; +VALA_EXTERN guint test_register_object (void* object, + GDBusConnection* connection, + const gchar* path, + GError** error); +VALA_EXTERN GType test_get_type (void) G_GNUC_CONST ; +VALA_EXTERN gint* test_test_int (Test* self, + gint* i, + gint i_length1, + gint** j, + gint* j_length1, + gint* result_length1, + GError** error); +VALA_EXTERN gchar** test_test_string (Test* self, + gchar** s, + gint s_length1, + gchar*** t, + gint* t_length1, + gint* result_length1, + GError** error); +VALA_EXTERN gchar** test_get_test_property (Test* self, + gint* result_length1); +VALA_EXTERN void test_set_test_property (Test* self, + gchar** value, + gint value_length1); +static GType test_get_type_once (void); +static void test_proxy_g_signal (GDBusProxy* proxy, + const gchar* sender_name, + const gchar* signal_name, + GVariant* parameters); +static gint* test_proxy_test_int (Test* self, + gint* i, + gint i_length1, + gint** j, + gint* j_length1, + gint* result_length1, + GError** error); +static gchar** test_proxy_test_string (Test* self, + gchar** s, + gint s_length1, + gchar*** t, + gint* t_length1, + gint* result_length1, + GError** error); +static gchar** test_dbus_proxy_get_test_property (Test* self, + gint* result_length1); +static void test_dbus_proxy_set_test_property (Test* self, + gchar** value, + gint value_length1); +static void test_proxy_test_interface_init (TestIface* iface); +static void _dbus_test_test_int (Test* self, + GVariant* _parameters_, + GDBusMethodInvocation* invocation); +static void _dbus_test_test_string (Test* self, + GVariant* _parameters_, + GDBusMethodInvocation* invocation); +static void test_dbus_interface_method_call (GDBusConnection* connection, + const gchar* sender, + const gchar* object_path, + const gchar* interface_name, + const gchar* method_name, + GVariant* parameters, + GDBusMethodInvocation* invocation, + gpointer user_data); +static GVariant* test_dbus_interface_get_property (GDBusConnection* connection, + const gchar* sender, + const gchar* object_path, + const gchar* interface_name, + const gchar* property_name, + GError** error, + gpointer user_data); +static GVariant* _dbus_test_get_test_property (Test* self); +static gboolean test_dbus_interface_set_property (GDBusConnection* connection, + const gchar* sender, + const gchar* object_path, + const gchar* interface_name, + const gchar* property_name, + GVariant* value, + GError** error, + gpointer user_data); +static void _dbus_test_set_test_property (Test* self, + GVariant* _value); +static void _test_unregister_object (gpointer user_data); +static void _vala_main (void); +static void _vala_array_destroy (gpointer array, + gssize array_length, + GDestroyNotify destroy_func); +static void _vala_array_free (gpointer array, + gssize array_length, + GDestroyNotify destroy_func); + +static const GDBusArgInfo _test_dbus_arg_info_test_int_i = {-1, "i", "ai", NULL}; +static const GDBusArgInfo _test_dbus_arg_info_test_int_j = {-1, "j", "ai", NULL}; +static const GDBusArgInfo _test_dbus_arg_info_test_int_result = {-1, "result", "ai", NULL}; +static const GDBusArgInfo * const _test_dbus_arg_info_test_int_in[] = {&_test_dbus_arg_info_test_int_i, NULL}; +static const GDBusArgInfo * const _test_dbus_arg_info_test_int_out[] = {&_test_dbus_arg_info_test_int_j, &_test_dbus_arg_info_test_int_result, NULL}; +static const GDBusMethodInfo _test_dbus_method_info_test_int = {-1, "TestInt", (GDBusArgInfo **) (&_test_dbus_arg_info_test_int_in), (GDBusArgInfo **) (&_test_dbus_arg_info_test_int_out), NULL}; +static const GDBusArgInfo _test_dbus_arg_info_test_string_s = {-1, "s", "as", NULL}; +static const GDBusArgInfo _test_dbus_arg_info_test_string_t = {-1, "t", "as", NULL}; +static const GDBusArgInfo _test_dbus_arg_info_test_string_result = {-1, "result", "as", NULL}; +static const GDBusArgInfo * const _test_dbus_arg_info_test_string_in[] = {&_test_dbus_arg_info_test_string_s, NULL}; +static const GDBusArgInfo * const _test_dbus_arg_info_test_string_out[] = {&_test_dbus_arg_info_test_string_t, &_test_dbus_arg_info_test_string_result, NULL}; +static const GDBusMethodInfo _test_dbus_method_info_test_string = {-1, "TestString", (GDBusArgInfo **) (&_test_dbus_arg_info_test_string_in), (GDBusArgInfo **) (&_test_dbus_arg_info_test_string_out), NULL}; +static const GDBusMethodInfo * const _test_dbus_method_info[] = {&_test_dbus_method_info_test_int, &_test_dbus_method_info_test_string, NULL}; +static const GDBusSignalInfo * const _test_dbus_signal_info[] = {NULL}; +static const GDBusPropertyInfo _test_dbus_property_info_test_property = {-1, "TestProperty", "as", G_DBUS_PROPERTY_INFO_FLAGS_READABLE | G_DBUS_PROPERTY_INFO_FLAGS_WRITABLE, NULL}; +static const GDBusPropertyInfo * const _test_dbus_property_info[] = {&_test_dbus_property_info_test_property, NULL}; +static const GDBusInterfaceInfo _test_dbus_interface_info = {-1, "org.example.Test", (GDBusMethodInfo **) (&_test_dbus_method_info), (GDBusSignalInfo **) (&_test_dbus_signal_info), (GDBusPropertyInfo **) (&_test_dbus_property_info), NULL}; +static const GDBusInterfaceVTable _test_dbus_interface_vtable = {test_dbus_interface_method_call, test_dbus_interface_get_property, test_dbus_interface_set_property}; + +gint* +test_test_int (Test* self, + gint* i, + gint i_length1, + gint** j, + gint* j_length1, + gint* result_length1, + GError** error) +{ + TestIface* _iface_; + g_return_val_if_fail (IS_TEST (self), NULL); + _iface_ = TEST_GET_INTERFACE (self); + if (_iface_->test_int) { + return _iface_->test_int (self, i, i_length1, j, j_length1, result_length1, error); + } + return NULL; +} + +gchar** +test_test_string (Test* self, + gchar** s, + gint s_length1, + gchar*** t, + gint* t_length1, + gint* result_length1, + GError** error) +{ + TestIface* _iface_; + g_return_val_if_fail (IS_TEST (self), NULL); + _iface_ = TEST_GET_INTERFACE (self); + if (_iface_->test_string) { + return _iface_->test_string (self, s, s_length1, t, t_length1, result_length1, error); + } + return NULL; +} + +gchar** +test_get_test_property (Test* self, + gint* result_length1) +{ + TestIface* _iface_; + g_return_val_if_fail (IS_TEST (self), NULL); + _iface_ = TEST_GET_INTERFACE (self); + if (_iface_->get_test_property) { + return _iface_->get_test_property (self, result_length1); + } + return NULL; +} + +void +test_set_test_property (Test* self, + gchar** value, + gint value_length1) +{ + TestIface* _iface_; + g_return_if_fail (IS_TEST (self)); + _iface_ = TEST_GET_INTERFACE (self); + if (_iface_->set_test_property) { + _iface_->set_test_property (self, value, value_length1); + } +} + +static void +test_default_init (TestIface * iface, + gpointer iface_data) +{ +} + +static GType +test_get_type_once (void) +{ + static const GTypeInfo g_define_type_info = { sizeof (TestIface), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) test_default_init, (GClassFinalizeFunc) NULL, NULL, 0, 0, (GInstanceInitFunc) NULL, NULL }; + GType test_type_id; + test_type_id = g_type_register_static (G_TYPE_INTERFACE, "Test", &g_define_type_info, 0); + g_type_interface_add_prerequisite (test_type_id, G_TYPE_OBJECT); + g_type_set_qdata (test_type_id, g_quark_from_static_string ("vala-dbus-proxy-type"), (void*) test_proxy_get_type); + g_type_set_qdata (test_type_id, g_quark_from_static_string ("vala-dbus-interface-name"), "org.example.Test"); + g_type_set_qdata (test_type_id, g_quark_from_static_string ("vala-dbus-interface-info"), (void*) (&_test_dbus_interface_info)); + g_type_set_qdata (test_type_id, g_quark_from_static_string ("vala-dbus-register-object"), (void*) test_register_object); + return test_type_id; +} + +GType +test_get_type (void) +{ + static volatile gsize test_type_id__volatile = 0; + if (g_once_init_enter (&test_type_id__volatile)) { + GType test_type_id; + test_type_id = test_get_type_once (); + g_once_init_leave (&test_type_id__volatile, test_type_id); + } + return test_type_id__volatile; +} + +G_DEFINE_TYPE_EXTENDED (TestProxy, test_proxy, G_TYPE_DBUS_PROXY, 0, G_IMPLEMENT_INTERFACE (TYPE_TEST, test_proxy_test_interface_init) ) +static void +test_proxy_class_init (TestProxyClass* klass) +{ + G_DBUS_PROXY_CLASS (klass)->g_signal = test_proxy_g_signal; +} + +static void +test_proxy_g_signal (GDBusProxy* proxy, + const gchar* sender_name, + const gchar* signal_name, + GVariant* parameters) +{ +} + +static void +test_proxy_init (TestProxy* self) +{ + g_dbus_proxy_set_interface_info (G_DBUS_PROXY (self), (GDBusInterfaceInfo *) (&_test_dbus_interface_info)); +} + +static gint* +test_proxy_test_int (Test* self, + gint* i, + gint i_length1, + gint** j, + gint* j_length1, + gint* result_length1, + GError** error) +{ + GDBusMessage *_message; + GVariant *_arguments; + GVariantBuilder _arguments_builder; + gint* _tmp0_; + GVariantBuilder _tmp1_; + gint _tmp2_; + GDBusMessage *_reply_message; + GVariant *_reply; + GVariantIter _reply_iter; + gint* _vala_j = NULL; + gint _vala_j_length1; + GVariant* _tmp3_; + gint* _tmp4_; + gint _tmp4__length; + gint _tmp4__size; + gint _tmp4__length1; + GVariantIter _tmp5_; + GVariant* _tmp6_; + gint* _result = NULL; + gint _result_length1; + GVariant* _tmp7_; + gint* _tmp8_; + gint _tmp8__length; + gint _tmp8__size; + gint _tmp8__length1; + GVariantIter _tmp9_; + GVariant* _tmp10_; + G_IO_ERROR; + _message = g_dbus_message_new_method_call (g_dbus_proxy_get_name ((GDBusProxy *) self), g_dbus_proxy_get_object_path ((GDBusProxy *) self), "org.example.Test", "TestInt"); + g_variant_builder_init (&_arguments_builder, G_VARIANT_TYPE_TUPLE); + _tmp0_ = i; + g_variant_builder_init (&_tmp1_, G_VARIANT_TYPE ("ai")); + for (_tmp2_ = 0; _tmp2_ < i_length1; _tmp2_++) { + g_variant_builder_add_value (&_tmp1_, g_variant_new_int32 (*_tmp0_)); + _tmp0_++; + } + g_variant_builder_add_value (&_arguments_builder, g_variant_builder_end (&_tmp1_)); + _arguments = g_variant_builder_end (&_arguments_builder); + g_dbus_message_set_body (_message, _arguments); + _reply_message = g_dbus_connection_send_message_with_reply_sync (g_dbus_proxy_get_connection ((GDBusProxy *) self), _message, G_DBUS_SEND_MESSAGE_FLAGS_NONE, g_dbus_proxy_get_default_timeout ((GDBusProxy *) self), NULL, NULL, error); + g_object_unref (_message); + if (!_reply_message) { + return NULL; + } + if (g_dbus_message_to_gerror (_reply_message, error)) { + g_object_unref (_reply_message); + return NULL; + } + _reply = g_dbus_message_get_body (_reply_message); + g_variant_iter_init (&_reply_iter, _reply); + _vala_j_length1 = 0; + _tmp3_ = g_variant_iter_next_value (&_reply_iter); + _tmp4_ = g_new (gint, 5); + _tmp4__length = 0; + _tmp4__size = 4; + _tmp4__length1 = 0; + g_variant_iter_init (&_tmp5_, _tmp3_); + for (; (_tmp6_ = g_variant_iter_next_value (&_tmp5_)) != NULL; _tmp4__length1++) { + if (_tmp4__size == _tmp4__length) { + _tmp4__size = 2 * _tmp4__size; + _tmp4_ = g_renew (gint, _tmp4_, _tmp4__size + 1); + } + _tmp4_[_tmp4__length++] = g_variant_get_int32 (_tmp6_); + g_variant_unref (_tmp6_); + } + _vala_j_length1 = _tmp4__length1; + _vala_j = _tmp4_; + g_variant_unref (_tmp3_); + *j = _vala_j; + *j_length1 = _vala_j_length1; + _result_length1 = 0; + _tmp7_ = g_variant_iter_next_value (&_reply_iter); + _tmp8_ = g_new (gint, 5); + _tmp8__length = 0; + _tmp8__size = 4; + _tmp8__length1 = 0; + g_variant_iter_init (&_tmp9_, _tmp7_); + for (; (_tmp10_ = g_variant_iter_next_value (&_tmp9_)) != NULL; _tmp8__length1++) { + if (_tmp8__size == _tmp8__length) { + _tmp8__size = 2 * _tmp8__size; + _tmp8_ = g_renew (gint, _tmp8_, _tmp8__size + 1); + } + _tmp8_[_tmp8__length++] = g_variant_get_int32 (_tmp10_); + g_variant_unref (_tmp10_); + } + _result_length1 = _tmp8__length1; + _result = _tmp8_; + g_variant_unref (_tmp7_); + *result_length1 = _result_length1; + g_object_unref (_reply_message); + return _result; +} + +static gchar** +test_proxy_test_string (Test* self, + gchar** s, + gint s_length1, + gchar*** t, + gint* t_length1, + gint* result_length1, + GError** error) +{ + GDBusMessage *_message; + GVariant *_arguments; + GVariantBuilder _arguments_builder; + gchar** _tmp11_; + GVariantBuilder _tmp12_; + gint _tmp13_; + GDBusMessage *_reply_message; + GVariant *_reply; + GVariantIter _reply_iter; + gchar** _vala_t = NULL; + gint _vala_t_length1; + GVariant* _tmp14_; + gchar** _tmp15_; + gint _tmp15__length; + gint _tmp15__size; + gint _tmp15__length1; + GVariantIter _tmp16_; + GVariant* _tmp17_; + gchar** _result = NULL; + gint _result_length1; + GVariant* _tmp18_; + gchar** _tmp19_; + gint _tmp19__length; + gint _tmp19__size; + gint _tmp19__length1; + GVariantIter _tmp20_; + GVariant* _tmp21_; + G_IO_ERROR; + _message = g_dbus_message_new_method_call (g_dbus_proxy_get_name ((GDBusProxy *) self), g_dbus_proxy_get_object_path ((GDBusProxy *) self), "org.example.Test", "TestString"); + g_variant_builder_init (&_arguments_builder, G_VARIANT_TYPE_TUPLE); + _tmp11_ = s; + g_variant_builder_init (&_tmp12_, G_VARIANT_TYPE ("as")); + for (_tmp13_ = 0; _tmp13_ < s_length1; _tmp13_++) { + g_variant_builder_add_value (&_tmp12_, g_variant_new_string (*_tmp11_)); + _tmp11_++; + } + g_variant_builder_add_value (&_arguments_builder, g_variant_builder_end (&_tmp12_)); + _arguments = g_variant_builder_end (&_arguments_builder); + g_dbus_message_set_body (_message, _arguments); + _reply_message = g_dbus_connection_send_message_with_reply_sync (g_dbus_proxy_get_connection ((GDBusProxy *) self), _message, G_DBUS_SEND_MESSAGE_FLAGS_NONE, g_dbus_proxy_get_default_timeout ((GDBusProxy *) self), NULL, NULL, error); + g_object_unref (_message); + if (!_reply_message) { + return NULL; + } + if (g_dbus_message_to_gerror (_reply_message, error)) { + g_object_unref (_reply_message); + return NULL; + } + _reply = g_dbus_message_get_body (_reply_message); + g_variant_iter_init (&_reply_iter, _reply); + _vala_t_length1 = 0; + _tmp14_ = g_variant_iter_next_value (&_reply_iter); + _tmp15_ = g_new (gchar*, 5); + _tmp15__length = 0; + _tmp15__size = 4; + _tmp15__length1 = 0; + g_variant_iter_init (&_tmp16_, _tmp14_); + for (; (_tmp17_ = g_variant_iter_next_value (&_tmp16_)) != NULL; _tmp15__length1++) { + if (_tmp15__size == _tmp15__length) { + _tmp15__size = 2 * _tmp15__size; + _tmp15_ = g_renew (gchar*, _tmp15_, _tmp15__size + 1); + } + _tmp15_[_tmp15__length++] = g_variant_dup_string (_tmp17_, NULL); + g_variant_unref (_tmp17_); + } + _vala_t_length1 = _tmp15__length1; + _tmp15_[_tmp15__length] = NULL; + _vala_t = _tmp15_; + g_variant_unref (_tmp14_); + *t = _vala_t; + *t_length1 = _vala_t_length1; + _result_length1 = 0; + _tmp18_ = g_variant_iter_next_value (&_reply_iter); + _tmp19_ = g_new (gchar*, 5); + _tmp19__length = 0; + _tmp19__size = 4; + _tmp19__length1 = 0; + g_variant_iter_init (&_tmp20_, _tmp18_); + for (; (_tmp21_ = g_variant_iter_next_value (&_tmp20_)) != NULL; _tmp19__length1++) { + if (_tmp19__size == _tmp19__length) { + _tmp19__size = 2 * _tmp19__size; + _tmp19_ = g_renew (gchar*, _tmp19_, _tmp19__size + 1); + } + _tmp19_[_tmp19__length++] = g_variant_dup_string (_tmp21_, NULL); + g_variant_unref (_tmp21_); + } + _result_length1 = _tmp19__length1; + _tmp19_[_tmp19__length] = NULL; + _result = _tmp19_; + g_variant_unref (_tmp18_); + *result_length1 = _result_length1; + g_object_unref (_reply_message); + return _result; +} + +static gchar** +test_dbus_proxy_get_test_property (Test* self, + gint* result_length1) +{ + GVariant *_inner_reply; + gchar** _result; + gint _result_length1; + gchar** _tmp22_; + gint _tmp22__length; + gint _tmp22__size; + gint _tmp22__length1; + GVariantIter _tmp23_; + GVariant* _tmp24_; + _inner_reply = g_dbus_proxy_get_cached_property ((GDBusProxy *) self, "TestProperty"); + if (!_inner_reply) { + GVariant *_arguments; + GVariant *_reply; + GVariantBuilder _arguments_builder; + g_variant_builder_init (&_arguments_builder, G_VARIANT_TYPE_TUPLE); + g_variant_builder_add_value (&_arguments_builder, g_variant_new_string ("org.example.Test")); + g_variant_builder_add_value (&_arguments_builder, g_variant_new_string ("TestProperty")); + _arguments = g_variant_builder_end (&_arguments_builder); + _reply = g_dbus_proxy_call_sync ((GDBusProxy *) self, "org.freedesktop.DBus.Properties.Get", _arguments, G_DBUS_CALL_FLAGS_NONE, -1, NULL, NULL); + if (!_reply) { + return NULL; + } + g_variant_get (_reply, "(v)", &_inner_reply); + g_variant_unref (_reply); + } + _result_length1 = 0; + _tmp22_ = g_new (gchar*, 5); + _tmp22__length = 0; + _tmp22__size = 4; + _tmp22__length1 = 0; + g_variant_iter_init (&_tmp23_, _inner_reply); + for (; (_tmp24_ = g_variant_iter_next_value (&_tmp23_)) != NULL; _tmp22__length1++) { + if (_tmp22__size == _tmp22__length) { + _tmp22__size = 2 * _tmp22__size; + _tmp22_ = g_renew (gchar*, _tmp22_, _tmp22__size + 1); + } + _tmp22_[_tmp22__length++] = g_variant_dup_string (_tmp24_, NULL); + g_variant_unref (_tmp24_); + } + _result_length1 = _tmp22__length1; + _tmp22_[_tmp22__length] = NULL; + _result = _tmp22_; + *result_length1 = _result_length1; + g_variant_unref (_inner_reply); + return _result; +} + +static void +test_dbus_proxy_set_test_property (Test* self, + gchar** value, + gint value_length1) +{ + GVariant *_arguments; + GVariant *_reply; + GVariantBuilder _arguments_builder; + gchar** _tmp25_; + GVariantBuilder _tmp26_; + gint _tmp27_; + g_variant_builder_init (&_arguments_builder, G_VARIANT_TYPE_TUPLE); + g_variant_builder_add_value (&_arguments_builder, g_variant_new_string ("org.example.Test")); + g_variant_builder_add_value (&_arguments_builder, g_variant_new_string ("TestProperty")); + g_variant_builder_open (&_arguments_builder, G_VARIANT_TYPE_VARIANT); + _tmp25_ = value; + g_variant_builder_init (&_tmp26_, G_VARIANT_TYPE ("as")); + for (_tmp27_ = 0; _tmp27_ < value_length1; _tmp27_++) { + g_variant_builder_add_value (&_tmp26_, g_variant_new_string (*_tmp25_)); + _tmp25_++; + } + g_variant_builder_add_value (&_arguments_builder, g_variant_builder_end (&_tmp26_)); + g_variant_builder_close (&_arguments_builder); + _arguments = g_variant_builder_end (&_arguments_builder); + _reply = g_dbus_proxy_call_sync ((GDBusProxy *) self, "org.freedesktop.DBus.Properties.Set", _arguments, G_DBUS_CALL_FLAGS_NONE, -1, NULL, NULL); + if (!_reply) { + return; + } + g_variant_unref (_reply); +} + +static void +test_proxy_test_interface_init (TestIface* iface) +{ + iface->test_int = test_proxy_test_int; + iface->test_string = test_proxy_test_string; + iface->get_test_property = test_dbus_proxy_get_test_property; + iface->set_test_property = test_dbus_proxy_set_test_property; +} + +static void +_dbus_test_test_int (Test* self, + GVariant* _parameters_, + GDBusMethodInvocation* invocation) +{ + GError* error = NULL; + GVariantIter _arguments_iter; + gint* i = NULL; + gint i_length1 = 0; + GVariant* _tmp28_; + gint* _tmp29_; + gint _tmp29__length; + gint _tmp29__size; + gint _tmp29__length1; + GVariantIter _tmp30_; + GVariant* _tmp31_; + GDBusMessage* _reply_message = NULL; + GVariant* _reply; + GVariantBuilder _reply_builder; + gint* j = NULL; + gint j_length1 = 0; + gint* _tmp32_; + GVariantBuilder _tmp33_; + gint _tmp34_; + gint* result; + gint result_length1 = 0; + gint* _tmp35_; + GVariantBuilder _tmp36_; + gint _tmp37_; + g_variant_iter_init (&_arguments_iter, _parameters_); + _tmp28_ = g_variant_iter_next_value (&_arguments_iter); + _tmp29_ = g_new (gint, 5); + _tmp29__length = 0; + _tmp29__size = 4; + _tmp29__length1 = 0; + g_variant_iter_init (&_tmp30_, _tmp28_); + for (; (_tmp31_ = g_variant_iter_next_value (&_tmp30_)) != NULL; _tmp29__length1++) { + if (_tmp29__size == _tmp29__length) { + _tmp29__size = 2 * _tmp29__size; + _tmp29_ = g_renew (gint, _tmp29_, _tmp29__size + 1); + } + _tmp29_[_tmp29__length++] = g_variant_get_int32 (_tmp31_); + g_variant_unref (_tmp31_); + } + i_length1 = _tmp29__length1; + i = _tmp29_; + g_variant_unref (_tmp28_); + result = test_test_int (self, i, i_length1, &j, &j_length1, &result_length1, &error); + if (error) { + g_dbus_method_invocation_return_gerror (invocation, error); + g_error_free (error); + goto _error; + } + _reply_message = g_dbus_message_new_method_reply (g_dbus_method_invocation_get_message (invocation)); + g_variant_builder_init (&_reply_builder, G_VARIANT_TYPE_TUPLE); + _tmp32_ = j; + g_variant_builder_init (&_tmp33_, G_VARIANT_TYPE ("ai")); + for (_tmp34_ = 0; _tmp34_ < j_length1; _tmp34_++) { + g_variant_builder_add_value (&_tmp33_, g_variant_new_int32 (*_tmp32_)); + _tmp32_++; + } + g_variant_builder_add_value (&_reply_builder, g_variant_builder_end (&_tmp33_)); + _tmp35_ = result; + g_variant_builder_init (&_tmp36_, G_VARIANT_TYPE ("ai")); + for (_tmp37_ = 0; _tmp37_ < result_length1; _tmp37_++) { + g_variant_builder_add_value (&_tmp36_, g_variant_new_int32 (*_tmp35_)); + _tmp35_++; + } + g_variant_builder_add_value (&_reply_builder, g_variant_builder_end (&_tmp36_)); + result = (g_free (result), NULL); + _reply = g_variant_builder_end (&_reply_builder); + g_dbus_message_set_body (_reply_message, _reply); + g_dbus_connection_send_message (g_dbus_method_invocation_get_connection (invocation), _reply_message, G_DBUS_SEND_MESSAGE_FLAGS_NONE, NULL, NULL); + g_object_unref (invocation); + g_object_unref (_reply_message); + _error: + i = (g_free (i), NULL); + j = (g_free (j), NULL); + ; +} + +static void +_dbus_test_test_string (Test* self, + GVariant* _parameters_, + GDBusMethodInvocation* invocation) +{ + GError* error = NULL; + GVariantIter _arguments_iter; + gchar** s = NULL; + gint s_length1 = 0; + GVariant* _tmp38_; + gchar** _tmp39_; + gint _tmp39__length; + gint _tmp39__size; + gint _tmp39__length1; + GVariantIter _tmp40_; + GVariant* _tmp41_; + GDBusMessage* _reply_message = NULL; + GVariant* _reply; + GVariantBuilder _reply_builder; + gchar** t = NULL; + gint t_length1 = 0; + gchar** _tmp42_; + GVariantBuilder _tmp43_; + gint _tmp44_; + gchar** result; + gint result_length1 = 0; + gchar** _tmp45_; + GVariantBuilder _tmp46_; + gint _tmp47_; + g_variant_iter_init (&_arguments_iter, _parameters_); + _tmp38_ = g_variant_iter_next_value (&_arguments_iter); + _tmp39_ = g_new (gchar*, 5); + _tmp39__length = 0; + _tmp39__size = 4; + _tmp39__length1 = 0; + g_variant_iter_init (&_tmp40_, _tmp38_); + for (; (_tmp41_ = g_variant_iter_next_value (&_tmp40_)) != NULL; _tmp39__length1++) { + if (_tmp39__size == _tmp39__length) { + _tmp39__size = 2 * _tmp39__size; + _tmp39_ = g_renew (gchar*, _tmp39_, _tmp39__size + 1); + } + _tmp39_[_tmp39__length++] = g_variant_dup_string (_tmp41_, NULL); + g_variant_unref (_tmp41_); + } + s_length1 = _tmp39__length1; + _tmp39_[_tmp39__length] = NULL; + s = _tmp39_; + g_variant_unref (_tmp38_); + result = test_test_string (self, s, s_length1, &t, &t_length1, &result_length1, &error); + if (error) { + g_dbus_method_invocation_return_gerror (invocation, error); + g_error_free (error); + goto _error; + } + _reply_message = g_dbus_message_new_method_reply (g_dbus_method_invocation_get_message (invocation)); + g_variant_builder_init (&_reply_builder, G_VARIANT_TYPE_TUPLE); + _tmp42_ = t; + g_variant_builder_init (&_tmp43_, G_VARIANT_TYPE ("as")); + for (_tmp44_ = 0; _tmp44_ < t_length1; _tmp44_++) { + g_variant_builder_add_value (&_tmp43_, g_variant_new_string (*_tmp42_)); + _tmp42_++; + } + g_variant_builder_add_value (&_reply_builder, g_variant_builder_end (&_tmp43_)); + _tmp45_ = result; + g_variant_builder_init (&_tmp46_, G_VARIANT_TYPE ("as")); + for (_tmp47_ = 0; _tmp47_ < result_length1; _tmp47_++) { + g_variant_builder_add_value (&_tmp46_, g_variant_new_string (*_tmp45_)); + _tmp45_++; + } + g_variant_builder_add_value (&_reply_builder, g_variant_builder_end (&_tmp46_)); + result = (_vala_array_free (result, result_length1, (GDestroyNotify) g_free), NULL); + _reply = g_variant_builder_end (&_reply_builder); + g_dbus_message_set_body (_reply_message, _reply); + g_dbus_connection_send_message (g_dbus_method_invocation_get_connection (invocation), _reply_message, G_DBUS_SEND_MESSAGE_FLAGS_NONE, NULL, NULL); + g_object_unref (invocation); + g_object_unref (_reply_message); + _error: + s = (_vala_array_free (s, s_length1, (GDestroyNotify) g_free), NULL); + t = (_vala_array_free (t, t_length1, (GDestroyNotify) g_free), NULL); + ; +} + +static void +test_dbus_interface_method_call (GDBusConnection* connection, + const gchar* sender, + const gchar* object_path, + const gchar* interface_name, + const gchar* method_name, + GVariant* parameters, + GDBusMethodInvocation* invocation, + gpointer user_data) +{ + gpointer* data; + gpointer object; + data = user_data; + object = data[0]; + if (strcmp (method_name, "TestInt") == 0) { + _dbus_test_test_int (object, parameters, invocation); + } else if (strcmp (method_name, "TestString") == 0) { + _dbus_test_test_string (object, parameters, invocation); + } else { + g_object_unref (invocation); + } +} + +static GVariant* +_dbus_test_get_test_property (Test* self) +{ + gchar** result; + gint result_length1 = 0; + GVariant* _reply; + gchar** _tmp48_; + GVariantBuilder _tmp49_; + gint _tmp50_; + result = test_get_test_property (self, &result_length1); + _tmp48_ = result; + g_variant_builder_init (&_tmp49_, G_VARIANT_TYPE ("as")); + for (_tmp50_ = 0; _tmp50_ < result_length1; _tmp50_++) { + g_variant_builder_add_value (&_tmp49_, g_variant_new_string (*_tmp48_)); + _tmp48_++; + } + _reply = g_variant_builder_end (&_tmp49_); + result = (_vala_array_free (result, result_length1, (GDestroyNotify) g_free), NULL); + return _reply; +} + +static GVariant* +test_dbus_interface_get_property (GDBusConnection* connection, + const gchar* sender, + const gchar* object_path, + const gchar* interface_name, + const gchar* property_name, + GError** error, + gpointer user_data) +{ + gpointer* data; + gpointer object; + data = user_data; + object = data[0]; + if (strcmp (property_name, "TestProperty") == 0) { + return _dbus_test_get_test_property (object); + } + return NULL; +} + +static void +_dbus_test_set_test_property (Test* self, + GVariant* _value) +{ + gchar** value = NULL; + gint value_length1; + gchar** _tmp51_; + gint _tmp51__length; + gint _tmp51__size; + gint _tmp51__length1; + GVariantIter _tmp52_; + GVariant* _tmp53_; + _tmp51_ = g_new (gchar*, 5); + _tmp51__length = 0; + _tmp51__size = 4; + _tmp51__length1 = 0; + g_variant_iter_init (&_tmp52_, _value); + for (; (_tmp53_ = g_variant_iter_next_value (&_tmp52_)) != NULL; _tmp51__length1++) { + if (_tmp51__size == _tmp51__length) { + _tmp51__size = 2 * _tmp51__size; + _tmp51_ = g_renew (gchar*, _tmp51_, _tmp51__size + 1); + } + _tmp51_[_tmp51__length++] = g_variant_dup_string (_tmp53_, NULL); + g_variant_unref (_tmp53_); + } + value_length1 = _tmp51__length1; + _tmp51_[_tmp51__length] = NULL; + value = _tmp51_; + test_set_test_property (self, value, value_length1); + value = (_vala_array_free (value, value_length1, (GDestroyNotify) g_free), NULL); +} + +static gboolean +test_dbus_interface_set_property (GDBusConnection* connection, + const gchar* sender, + const gchar* object_path, + const gchar* interface_name, + const gchar* property_name, + GVariant* value, + GError** error, + gpointer user_data) +{ + gpointer* data; + gpointer object; + data = user_data; + object = data[0]; + if (strcmp (property_name, "TestProperty") == 0) { + _dbus_test_set_test_property (object, value); + return TRUE; + } + return FALSE; +} + +guint +test_register_object (gpointer object, + GDBusConnection* connection, + const gchar* path, + GError** error) +{ + guint result; + gpointer *data; + data = g_new (gpointer, 3); + data[0] = g_object_ref (object); + data[1] = g_object_ref (connection); + data[2] = g_strdup (path); + result = g_dbus_connection_register_object (connection, path, (GDBusInterfaceInfo *) (&_test_dbus_interface_info), &_test_dbus_interface_vtable, data, _test_unregister_object, error); + if (!result) { + return 0; + } + return result; +} + +static void +_test_unregister_object (gpointer user_data) +{ + gpointer* data; + data = user_data; + g_object_unref (data[0]); + g_object_unref (data[1]); + g_free (data[2]); + g_free (data); +} + +static void +_vala_main (void) +{ + Test* test = NULL; + Test* _tmp0_; + gint* j = NULL; + gint j_length1 = 0; + gint _j_size_ = 0; + gint* k = NULL; + gint k_length1 = 0; + gint _k_size_ = 0; + gint* _tmp1_ = NULL; + Test* _tmp2_; + gint* _tmp3_; + gint* _tmp4_; + gint _tmp4__length1; + gint* _tmp5_ = NULL; + gint _tmp6_ = 0; + gint _tmp7_ = 0; + gint* _tmp8_; + gint* _tmp9_; + gint _tmp9__length1; + gint _tmp1__length1; + gint __tmp1__size_; + gint* _tmp10_; + gint _tmp10__length1; + gboolean _tmp11_ = FALSE; + gint* _tmp12_; + gint _tmp12__length1; + gboolean _tmp15_ = FALSE; + gint* _tmp16_; + gint _tmp16__length1; + gchar** t = NULL; + gint t_length1 = 0; + gint _t_size_ = 0; + gchar** u = NULL; + gint u_length1 = 0; + gint _u_size_ = 0; + gchar** _tmp19_ = NULL; + Test* _tmp20_; + gchar* _tmp21_; + gchar** _tmp22_; + gchar** _tmp23_; + gint _tmp23__length1; + gchar** _tmp24_ = NULL; + gint _tmp25_ = 0; + gint _tmp26_ = 0; + gchar** _tmp27_; + gchar** _tmp28_; + gint _tmp28__length1; + gint _tmp19__length1; + gint __tmp19__size_; + gchar** _tmp29_; + gint _tmp29__length1; + gboolean _tmp30_ = FALSE; + gchar** _tmp31_; + gint _tmp31__length1; + gboolean _tmp34_ = FALSE; + gchar** _tmp35_; + gint _tmp35__length1; + Test* _tmp38_; + gchar* _tmp39_; + gchar** _tmp40_; + gchar** _tmp41_; + gint _tmp41__length1; + Test* _tmp42_; + gchar** _tmp43_; + gint _tmp43__length1; + gint _tmp44_ = 0; + gchar** _tmp45_; + gint _tmp45__length1; + gboolean _tmp46_ = FALSE; + gchar** _tmp47_; + gint _tmp47__length1; + GError* _inner_error0_ = NULL; + _tmp0_ = (Test*) g_initable_new (TYPE_TEST_PROXY, NULL, &_inner_error0_, "g-flags", G_DBUS_PROXY_FLAGS_DO_NOT_LOAD_PROPERTIES, "g-name", "org.example.Test", "g-bus-type", G_BUS_TYPE_SESSION, "g-object-path", "/org/example/test", "g-interface-name", "org.example.Test", NULL); + test = (Test*) _tmp0_; + if (G_UNLIKELY (_inner_error0_ != NULL)) { + g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error0_->message, g_quark_to_string (_inner_error0_->domain), _inner_error0_->code); + g_clear_error (&_inner_error0_); + return; + } + _tmp2_ = test; + _tmp3_ = g_new0 (gint, 1); + _tmp3_[0] = 42; + _tmp4_ = _tmp3_; + _tmp4__length1 = 1; + _tmp8_ = test_test_int (_tmp2_, _tmp4_, (gint) 1, &_tmp5_, &_tmp6_, &_tmp7_, &_inner_error0_); + j = (g_free (j), NULL); + j = _tmp5_; + j_length1 = _tmp6_; + _j_size_ = j_length1; + _tmp9_ = _tmp8_; + _tmp9__length1 = _tmp7_; + _tmp4_ = (g_free (_tmp4_), NULL); + _tmp1_ = _tmp9_; + _tmp1__length1 = _tmp9__length1; + __tmp1__size_ = _tmp1__length1; + if (G_UNLIKELY (_inner_error0_ != NULL)) { + k = (g_free (k), NULL); + j = (g_free (j), NULL); + _g_object_unref0 (test); + g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error0_->message, g_quark_to_string (_inner_error0_->domain), _inner_error0_->code); + g_clear_error (&_inner_error0_); + return; + } + _tmp10_ = _tmp1_; + _tmp10__length1 = _tmp1__length1; + _tmp1_ = NULL; + _tmp1__length1 = 0; + k = (g_free (k), NULL); + k = _tmp10_; + k_length1 = _tmp10__length1; + _k_size_ = k_length1; + _tmp12_ = j; + _tmp12__length1 = j_length1; + if (_tmp12__length1 == 1) { + gint* _tmp13_; + gint _tmp13__length1; + gint _tmp14_; + _tmp13_ = j; + _tmp13__length1 = j_length1; + _tmp14_ = _tmp13_[0]; + _tmp11_ = _tmp14_ == 23; + } else { + _tmp11_ = FALSE; + } + _vala_assert (_tmp11_, "j.length == 1 && j[0] == 23"); + _tmp16_ = k; + _tmp16__length1 = k_length1; + if (_tmp16__length1 == 1) { + gint* _tmp17_; + gint _tmp17__length1; + gint _tmp18_; + _tmp17_ = k; + _tmp17__length1 = k_length1; + _tmp18_ = _tmp17_[0]; + _tmp15_ = _tmp18_ == 11; + } else { + _tmp15_ = FALSE; + } + _vala_assert (_tmp15_, "k.length == 1 && k[0] == 11"); + _tmp20_ = test; + _tmp21_ = g_strdup ("hello"); + _tmp22_ = g_new0 (gchar*, 1 + 1); + _tmp22_[0] = _tmp21_; + _tmp23_ = _tmp22_; + _tmp23__length1 = 1; + _tmp27_ = test_test_string (_tmp20_, _tmp23_, (gint) 1, &_tmp24_, &_tmp25_, &_tmp26_, &_inner_error0_); + t = (_vala_array_free (t, t_length1, (GDestroyNotify) g_free), NULL); + t = _tmp24_; + t_length1 = _tmp25_; + _t_size_ = t_length1; + _tmp28_ = _tmp27_; + _tmp28__length1 = _tmp26_; + _tmp23_ = (_vala_array_free (_tmp23_, _tmp23__length1, (GDestroyNotify) g_free), NULL); + _tmp19_ = _tmp28_; + _tmp19__length1 = _tmp28__length1; + __tmp19__size_ = _tmp19__length1; + if (G_UNLIKELY (_inner_error0_ != NULL)) { + u = (_vala_array_free (u, u_length1, (GDestroyNotify) g_free), NULL); + t = (_vala_array_free (t, t_length1, (GDestroyNotify) g_free), NULL); + _tmp1_ = (g_free (_tmp1_), NULL); + k = (g_free (k), NULL); + j = (g_free (j), NULL); + _g_object_unref0 (test); + g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error0_->message, g_quark_to_string (_inner_error0_->domain), _inner_error0_->code); + g_clear_error (&_inner_error0_); + return; + } + _tmp29_ = _tmp19_; + _tmp29__length1 = _tmp19__length1; + _tmp19_ = NULL; + _tmp19__length1 = 0; + u = (_vala_array_free (u, u_length1, (GDestroyNotify) g_free), NULL); + u = _tmp29_; + u_length1 = _tmp29__length1; + _u_size_ = u_length1; + _tmp31_ = t; + _tmp31__length1 = t_length1; + if (_tmp31__length1 == 1) { + gchar** _tmp32_; + gint _tmp32__length1; + const gchar* _tmp33_; + _tmp32_ = t; + _tmp32__length1 = t_length1; + _tmp33_ = _tmp32_[0]; + _tmp30_ = g_strcmp0 (_tmp33_, "world") == 0; + } else { + _tmp30_ = FALSE; + } + _vala_assert (_tmp30_, "t.length == 1 && t[0] == \"world\""); + _tmp35_ = u; + _tmp35__length1 = u_length1; + if (_tmp35__length1 == 1) { + gchar** _tmp36_; + gint _tmp36__length1; + const gchar* _tmp37_; + _tmp36_ = u; + _tmp36__length1 = u_length1; + _tmp37_ = _tmp36_[0]; + _tmp34_ = g_strcmp0 (_tmp37_, "vala") == 0; + } else { + _tmp34_ = FALSE; + } + _vala_assert (_tmp34_, "u.length == 1 && u[0] == \"vala\""); + _tmp38_ = test; + _tmp39_ = g_strdup ("hello"); + _tmp40_ = g_new0 (gchar*, 1 + 1); + _tmp40_[0] = _tmp39_; + _tmp41_ = _tmp40_; + _tmp41__length1 = 1; + test_set_test_property (_tmp38_, _tmp41_, 1); + _tmp41_ = (_vala_array_free (_tmp41_, _tmp41__length1, (GDestroyNotify) g_free), NULL); + _tmp42_ = test; + _tmp43_ = test_get_test_property (_tmp42_, &_tmp44_); + _tmp43__length1 = _tmp44_; + _tmp45_ = _tmp43_; + _tmp45__length1 = _tmp43__length1; + t = (_vala_array_free (t, t_length1, (GDestroyNotify) g_free), NULL); + t = _tmp45_; + t_length1 = _tmp45__length1; + _t_size_ = t_length1; + _tmp47_ = t; + _tmp47__length1 = t_length1; + if (_tmp47__length1 == 1) { + gchar** _tmp48_; + gint _tmp48__length1; + const gchar* _tmp49_; + _tmp48_ = t; + _tmp48__length1 = t_length1; + _tmp49_ = _tmp48_[0]; + _tmp46_ = g_strcmp0 (_tmp49_, "hello") == 0; + } else { + _tmp46_ = FALSE; + } + _vala_assert (_tmp46_, "t.length == 1 && t[0] == \"hello\""); + _tmp19_ = (_vala_array_free (_tmp19_, _tmp19__length1, (GDestroyNotify) g_free), NULL); + u = (_vala_array_free (u, u_length1, (GDestroyNotify) g_free), NULL); + t = (_vala_array_free (t, t_length1, (GDestroyNotify) g_free), NULL); + _tmp1_ = (g_free (_tmp1_), NULL); + k = (g_free (k), NULL); + j = (g_free (j), NULL); + _g_object_unref0 (test); +} + +int +main (int argc, + char ** argv) +{ + _vala_main (); + return 0; +} + +static void +_vala_array_destroy (gpointer array, + gssize array_length, + GDestroyNotify destroy_func) +{ + if ((array != NULL) && (destroy_func != NULL)) { + gssize i; + for (i = 0; i < array_length; i = i + 1) { + if (((gpointer*) array)[i] != NULL) { + destroy_func (((gpointer*) array)[i]); + } + } + } +} + +static void +_vala_array_free (gpointer array, + gssize array_length, + GDestroyNotify destroy_func) +{ + _vala_array_destroy (array, array_length, destroy_func); + g_free (array); +} + diff --git a/tests/dbus/arrays_server.c-expected b/tests/dbus/arrays_server.c-expected new file mode 100644 index 000000000..7cae17ed0 --- /dev/null +++ b/tests/dbus/arrays_server.c-expected @@ -0,0 +1,909 @@ +/* dbus_arrays_server.c generated by valac, the Vala compiler + * generated from dbus_arrays_server.vala, do not modify */ + +#include <glib-object.h> +#include <gio/gio.h> +#include <stdlib.h> +#include <string.h> +#include <glib.h> + +#if !defined(VALA_EXTERN) +#if defined(_MSC_VER) +#define VALA_EXTERN __declspec(dllexport) extern +#elif __GNUC__ >= 4 +#define VALA_EXTERN __attribute__((visibility("default"))) extern +#else +#define VALA_EXTERN extern +#endif +#endif + +#define TYPE_TEST (test_get_type ()) +#define TEST(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TYPE_TEST, Test)) +#define TEST_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), TYPE_TEST, TestClass)) +#define IS_TEST(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TYPE_TEST)) +#define IS_TEST_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), TYPE_TEST)) +#define TEST_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), TYPE_TEST, TestClass)) + +typedef struct _Test Test; +typedef struct _TestClass TestClass; +typedef struct _TestPrivate TestPrivate; +enum { + TEST_0_PROPERTY, + TEST_TEST_PROPERTY_PROPERTY, + TEST_NUM_PROPERTIES +}; +static GParamSpec* test_properties[TEST_NUM_PROPERTIES]; +#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL))) +#define _g_variant_unref0(var) ((var == NULL) ? NULL : (var = (g_variant_unref (var), NULL))) +#define _g_main_loop_unref0(var) ((var == NULL) ? NULL : (var = (g_main_loop_unref (var), NULL))) +#define _vala_assert(expr, msg) if G_LIKELY (expr) ; else g_assertion_message_expr (G_LOG_DOMAIN, __FILE__, __LINE__, G_STRFUNC, msg); +#define _vala_return_if_fail(expr, msg) if G_LIKELY (expr) ; else { g_return_if_fail_warning (G_LOG_DOMAIN, G_STRFUNC, msg); return; } +#define _vala_return_val_if_fail(expr, msg, val) if G_LIKELY (expr) ; else { g_return_if_fail_warning (G_LOG_DOMAIN, G_STRFUNC, msg); return val; } +#define _vala_warn_if_fail(expr, msg) if G_LIKELY (expr) ; else g_warn_message (G_LOG_DOMAIN, __FILE__, __LINE__, G_STRFUNC, msg); + +struct _Test { + GObject parent_instance; + TestPrivate * priv; +}; + +struct _TestClass { + GObjectClass parent_class; +}; + +struct _TestPrivate { + gchar** _test_property; + gint _test_property_length1; + gint __test_property_size_; +}; + +static gint Test_private_offset; +static gpointer test_parent_class = NULL; +VALA_EXTERN GMainLoop* main_loop; +GMainLoop* main_loop = NULL; + +VALA_EXTERN GType test_get_type (void) G_GNUC_CONST ; +G_DEFINE_AUTOPTR_CLEANUP_FUNC (Test, g_object_unref) +VALA_EXTERN guint test_register_object (void* object, + GDBusConnection* connection, + const gchar* path, + GError** error); +VALA_EXTERN gint* test_test_int (Test* self, + gint* i, + gint i_length1, + gint** j, + gint* j_length1, + gint* result_length1); +VALA_EXTERN gchar** test_test_string (Test* self, + gchar** s, + gint s_length1, + gchar*** t, + gint* t_length1, + gint* result_length1); +VALA_EXTERN Test* test_new (void); +VALA_EXTERN Test* test_construct (GType object_type); +VALA_EXTERN gchar** test_get_test_property (Test* self, + gint* result_length1); +static gchar** _vala_array_dup1 (gchar** self, + gssize length); +VALA_EXTERN void test_set_test_property (Test* self, + gchar** value, + gint value_length1); +static gchar** _vala_array_dup2 (gchar** self, + gssize length); +static void test_finalize (GObject * obj); +static GType test_get_type_once (void); +static void _vala_test_get_property (GObject * object, + guint property_id, + GValue * value, + GParamSpec * pspec); +static void _vala_test_set_property (GObject * object, + guint property_id, + const GValue * value, + GParamSpec * pspec); +static void _dbus_test_test_int (Test* self, + GVariant* _parameters_, + GDBusMethodInvocation* invocation); +static void _dbus_test_test_string (Test* self, + GVariant* _parameters_, + GDBusMethodInvocation* invocation); +static void test_dbus_interface_method_call (GDBusConnection* connection, + const gchar* sender, + const gchar* object_path, + const gchar* interface_name, + const gchar* method_name, + GVariant* parameters, + GDBusMethodInvocation* invocation, + gpointer user_data); +static GVariant* test_dbus_interface_get_property (GDBusConnection* connection, + const gchar* sender, + const gchar* object_path, + const gchar* interface_name, + const gchar* property_name, + GError** error, + gpointer user_data); +static GVariant* _dbus_test_get_test_property (Test* self); +static gboolean test_dbus_interface_set_property (GDBusConnection* connection, + const gchar* sender, + const gchar* object_path, + const gchar* interface_name, + const gchar* property_name, + GVariant* value, + GError** error, + gpointer user_data); +static void _dbus_test_set_test_property (Test* self, + GVariant* _value); +static void _test_unregister_object (gpointer user_data); +VALA_EXTERN void client_exit (GPid pid, + gint status); +static void _vala_main (void); +static guint _variant_get1 (GVariant* value); +static void _client_exit_gchild_watch_func (GPid pid, + gint wait_status, + gpointer self); +static void _vala_array_destroy (gpointer array, + gssize array_length, + GDestroyNotify destroy_func); +static void _vala_array_free (gpointer array, + gssize array_length, + GDestroyNotify destroy_func); + +static const GDBusArgInfo _test_dbus_arg_info_test_int_i = {-1, "i", "ai", NULL}; +static const GDBusArgInfo _test_dbus_arg_info_test_int_j = {-1, "j", "ai", NULL}; +static const GDBusArgInfo _test_dbus_arg_info_test_int_result = {-1, "result", "ai", NULL}; +static const GDBusArgInfo * const _test_dbus_arg_info_test_int_in[] = {&_test_dbus_arg_info_test_int_i, NULL}; +static const GDBusArgInfo * const _test_dbus_arg_info_test_int_out[] = {&_test_dbus_arg_info_test_int_j, &_test_dbus_arg_info_test_int_result, NULL}; +static const GDBusMethodInfo _test_dbus_method_info_test_int = {-1, "TestInt", (GDBusArgInfo **) (&_test_dbus_arg_info_test_int_in), (GDBusArgInfo **) (&_test_dbus_arg_info_test_int_out), NULL}; +static const GDBusArgInfo _test_dbus_arg_info_test_string_s = {-1, "s", "as", NULL}; +static const GDBusArgInfo _test_dbus_arg_info_test_string_t = {-1, "t", "as", NULL}; +static const GDBusArgInfo _test_dbus_arg_info_test_string_result = {-1, "result", "as", NULL}; +static const GDBusArgInfo * const _test_dbus_arg_info_test_string_in[] = {&_test_dbus_arg_info_test_string_s, NULL}; +static const GDBusArgInfo * const _test_dbus_arg_info_test_string_out[] = {&_test_dbus_arg_info_test_string_t, &_test_dbus_arg_info_test_string_result, NULL}; +static const GDBusMethodInfo _test_dbus_method_info_test_string = {-1, "TestString", (GDBusArgInfo **) (&_test_dbus_arg_info_test_string_in), (GDBusArgInfo **) (&_test_dbus_arg_info_test_string_out), NULL}; +static const GDBusMethodInfo * const _test_dbus_method_info[] = {&_test_dbus_method_info_test_int, &_test_dbus_method_info_test_string, NULL}; +static const GDBusSignalInfo * const _test_dbus_signal_info[] = {NULL}; +static const GDBusPropertyInfo _test_dbus_property_info_test_property = {-1, "TestProperty", "as", G_DBUS_PROPERTY_INFO_FLAGS_READABLE | G_DBUS_PROPERTY_INFO_FLAGS_WRITABLE, NULL}; +static const GDBusPropertyInfo * const _test_dbus_property_info[] = {&_test_dbus_property_info_test_property, NULL}; +static const GDBusInterfaceInfo _test_dbus_interface_info = {-1, "org.example.Test", (GDBusMethodInfo **) (&_test_dbus_method_info), (GDBusSignalInfo **) (&_test_dbus_signal_info), (GDBusPropertyInfo **) (&_test_dbus_property_info), NULL}; +static const GDBusInterfaceVTable _test_dbus_interface_vtable = {test_dbus_interface_method_call, test_dbus_interface_get_property, test_dbus_interface_set_property}; + +static inline gpointer +test_get_instance_private (Test* self) +{ + return G_STRUCT_MEMBER_P (self, Test_private_offset); +} + +gint* +test_test_int (Test* self, + gint* i, + gint i_length1, + gint** j, + gint* j_length1, + gint* result_length1) +{ + gint* _vala_j = NULL; + gint _vala_j_length1 = 0; + gboolean _tmp0_ = FALSE; + gint* _tmp2_; + gint* _tmp3_; + gint* _tmp4_; + gint _tmp4__length1; + gint* result = NULL; + g_return_val_if_fail (IS_TEST (self), NULL); + if (i_length1 == 1) { + gint _tmp1_; + _tmp1_ = i[0]; + _tmp0_ = _tmp1_ == 42; + } else { + _tmp0_ = FALSE; + } + _vala_assert (_tmp0_, "i.length == 1 && i[0] == 42"); + _tmp2_ = g_new0 (gint, 1); + _tmp2_[0] = 23; + _vala_j = (g_free (_vala_j), NULL); + _vala_j = _tmp2_; + _vala_j_length1 = 1; + _tmp3_ = g_new0 (gint, 1); + _tmp3_[0] = 11; + _tmp4_ = _tmp3_; + _tmp4__length1 = 1; + if (result_length1) { + *result_length1 = _tmp4__length1; + } + result = _tmp4_; + if (j) { + *j = _vala_j; + } else { + _vala_j = (g_free (_vala_j), NULL); + } + if (j_length1) { + *j_length1 = _vala_j_length1; + } + return result; +} + +gchar** +test_test_string (Test* self, + gchar** s, + gint s_length1, + gchar*** t, + gint* t_length1, + gint* result_length1) +{ + gchar** _vala_t = NULL; + gint _vala_t_length1 = 0; + gboolean _tmp0_ = FALSE; + gchar* _tmp2_; + gchar** _tmp3_; + gchar* _tmp4_; + gchar** _tmp5_; + gchar** _tmp6_; + gint _tmp6__length1; + gchar** result = NULL; + g_return_val_if_fail (IS_TEST (self), NULL); + if (s_length1 == 1) { + const gchar* _tmp1_; + _tmp1_ = s[0]; + _tmp0_ = g_strcmp0 (_tmp1_, "hello") == 0; + } else { + _tmp0_ = FALSE; + } + _vala_assert (_tmp0_, "s.length == 1 && s[0] == \"hello\""); + _tmp2_ = g_strdup ("world"); + _tmp3_ = g_new0 (gchar*, 1 + 1); + _tmp3_[0] = _tmp2_; + _vala_t = (_vala_array_free (_vala_t, _vala_t_length1, (GDestroyNotify) g_free), NULL); + _vala_t = _tmp3_; + _vala_t_length1 = 1; + _tmp4_ = g_strdup ("vala"); + _tmp5_ = g_new0 (gchar*, 1 + 1); + _tmp5_[0] = _tmp4_; + _tmp6_ = _tmp5_; + _tmp6__length1 = 1; + if (result_length1) { + *result_length1 = _tmp6__length1; + } + result = _tmp6_; + if (t) { + *t = _vala_t; + } else { + _vala_t = (_vala_array_free (_vala_t, _vala_t_length1, (GDestroyNotify) g_free), NULL); + } + if (t_length1) { + *t_length1 = _vala_t_length1; + } + return result; +} + +Test* +test_construct (GType object_type) +{ + Test * self = NULL; + self = (Test*) g_object_new (object_type, NULL); + return self; +} + +Test* +test_new (void) +{ + return test_construct (TYPE_TEST); +} + +static gchar** +_vala_array_dup1 (gchar** self, + gssize length) +{ + if (length >= 0) { + gchar** result; + gssize i; + result = g_new0 (gchar*, length + 1); + for (i = 0; i < length; i++) { + gchar* _tmp0_; + _tmp0_ = g_strdup (self[i]); + result[i] = _tmp0_; + } + return result; + } + return NULL; +} + +gchar** +test_get_test_property (Test* self, + gint* result_length1) +{ + gchar** result; + gchar** _tmp0_; + gint _tmp0__length1; + gchar** _tmp1_; + gint _tmp1__length1; + gchar** _tmp2_; + gint _tmp2__length1; + g_return_val_if_fail (IS_TEST (self), NULL); + _tmp0_ = self->priv->_test_property; + _tmp0__length1 = self->priv->_test_property_length1; + _tmp1_ = (_tmp0_ != NULL) ? _vala_array_dup1 (_tmp0_, _tmp0__length1) : _tmp0_; + _tmp1__length1 = _tmp0__length1; + _tmp2_ = _tmp1_; + _tmp2__length1 = _tmp1__length1; + if (result_length1) { + *result_length1 = _tmp2__length1; + } + result = _tmp2_; + return result; +} + +static gchar** +_vala_array_dup2 (gchar** self, + gssize length) +{ + if (length >= 0) { + gchar** result; + gssize i; + result = g_new0 (gchar*, length + 1); + for (i = 0; i < length; i++) { + gchar* _tmp0_; + _tmp0_ = g_strdup (self[i]); + result[i] = _tmp0_; + } + return result; + } + return NULL; +} + +void +test_set_test_property (Test* self, + gchar** value, + gint value_length1) +{ + gchar** old_value; + gint old_value_length; + g_return_if_fail (IS_TEST (self)); + old_value = test_get_test_property (self, &old_value_length); + if (old_value != value) { + gchar** _tmp0_; + gint _tmp0__length1; + _tmp0_ = (value != NULL) ? _vala_array_dup2 (value, value_length1) : value; + _tmp0__length1 = value_length1; + self->priv->_test_property = (_vala_array_free (self->priv->_test_property, self->priv->_test_property_length1, (GDestroyNotify) g_free), NULL); + self->priv->_test_property = _tmp0_; + self->priv->_test_property_length1 = _tmp0__length1; + self->priv->__test_property_size_ = self->priv->_test_property_length1; + g_object_notify_by_pspec ((GObject *) self, test_properties[TEST_TEST_PROPERTY_PROPERTY]); + } + old_value = (_vala_array_free (old_value, old_value_length, (GDestroyNotify) g_free), NULL); +} + +static void +test_class_init (TestClass * klass, + gpointer klass_data) +{ + test_parent_class = g_type_class_peek_parent (klass); + g_type_class_adjust_private_offset (klass, &Test_private_offset); + G_OBJECT_CLASS (klass)->get_property = _vala_test_get_property; + G_OBJECT_CLASS (klass)->set_property = _vala_test_set_property; + G_OBJECT_CLASS (klass)->finalize = test_finalize; + g_object_class_install_property (G_OBJECT_CLASS (klass), TEST_TEST_PROPERTY_PROPERTY, test_properties[TEST_TEST_PROPERTY_PROPERTY] = g_param_spec_boxed ("test-property", "test-property", "test-property", G_TYPE_STRV, G_PARAM_STATIC_STRINGS | G_PARAM_READABLE | G_PARAM_WRITABLE)); +} + +static void +test_instance_init (Test * self, + gpointer klass) +{ + self->priv = test_get_instance_private (self); +} + +static void +test_finalize (GObject * obj) +{ + Test * self; + self = G_TYPE_CHECK_INSTANCE_CAST (obj, TYPE_TEST, Test); + self->priv->_test_property = (_vala_array_free (self->priv->_test_property, self->priv->_test_property_length1, (GDestroyNotify) g_free), NULL); + G_OBJECT_CLASS (test_parent_class)->finalize (obj); +} + +static GType +test_get_type_once (void) +{ + static const GTypeInfo g_define_type_info = { sizeof (TestClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) test_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (Test), 0, (GInstanceInitFunc) test_instance_init, NULL }; + GType test_type_id; + test_type_id = g_type_register_static (G_TYPE_OBJECT, "Test", &g_define_type_info, 0); + g_type_set_qdata (test_type_id, g_quark_from_static_string ("vala-dbus-register-object"), (void*) test_register_object); + Test_private_offset = g_type_add_instance_private (test_type_id, sizeof (TestPrivate)); + return test_type_id; +} + +GType +test_get_type (void) +{ + static volatile gsize test_type_id__volatile = 0; + if (g_once_init_enter (&test_type_id__volatile)) { + GType test_type_id; + test_type_id = test_get_type_once (); + g_once_init_leave (&test_type_id__volatile, test_type_id); + } + return test_type_id__volatile; +} + +static void +_vala_test_get_property (GObject * object, + guint property_id, + GValue * value, + GParamSpec * pspec) +{ + Test * self; + self = G_TYPE_CHECK_INSTANCE_CAST (object, TYPE_TEST, Test); + switch (property_id) { + case TEST_TEST_PROPERTY_PROPERTY: + { + int length; + g_value_take_boxed (value, test_get_test_property (self, &length)); + } + break; + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); + break; + } +} + +static void +_vala_test_set_property (GObject * object, + guint property_id, + const GValue * value, + GParamSpec * pspec) +{ + Test * self; + self = G_TYPE_CHECK_INSTANCE_CAST (object, TYPE_TEST, Test); + switch (property_id) { + case TEST_TEST_PROPERTY_PROPERTY: + { + gpointer boxed; + boxed = g_value_get_boxed (value); + test_set_test_property (self, boxed, (boxed == NULL) ? 0 : g_strv_length (boxed)); + } + break; + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); + break; + } +} + +static void +_dbus_test_test_int (Test* self, + GVariant* _parameters_, + GDBusMethodInvocation* invocation) +{ + GError* error = NULL; + GVariantIter _arguments_iter; + gint* i = NULL; + gint i_length1 = 0; + GVariant* _tmp0_; + gint* _tmp1_; + gint _tmp1__length; + gint _tmp1__size; + gint _tmp1__length1; + GVariantIter _tmp2_; + GVariant* _tmp3_; + GDBusMessage* _reply_message = NULL; + GVariant* _reply; + GVariantBuilder _reply_builder; + gint* j = NULL; + gint j_length1 = 0; + gint* _tmp4_; + GVariantBuilder _tmp5_; + gint _tmp6_; + gint* result; + gint result_length1 = 0; + gint* _tmp7_; + GVariantBuilder _tmp8_; + gint _tmp9_; + g_variant_iter_init (&_arguments_iter, _parameters_); + _tmp0_ = g_variant_iter_next_value (&_arguments_iter); + _tmp1_ = g_new (gint, 5); + _tmp1__length = 0; + _tmp1__size = 4; + _tmp1__length1 = 0; + g_variant_iter_init (&_tmp2_, _tmp0_); + for (; (_tmp3_ = g_variant_iter_next_value (&_tmp2_)) != NULL; _tmp1__length1++) { + if (_tmp1__size == _tmp1__length) { + _tmp1__size = 2 * _tmp1__size; + _tmp1_ = g_renew (gint, _tmp1_, _tmp1__size + 1); + } + _tmp1_[_tmp1__length++] = g_variant_get_int32 (_tmp3_); + g_variant_unref (_tmp3_); + } + i_length1 = _tmp1__length1; + i = _tmp1_; + g_variant_unref (_tmp0_); + result = test_test_int (self, i, i_length1, &j, &j_length1, &result_length1); + _reply_message = g_dbus_message_new_method_reply (g_dbus_method_invocation_get_message (invocation)); + g_variant_builder_init (&_reply_builder, G_VARIANT_TYPE_TUPLE); + _tmp4_ = j; + g_variant_builder_init (&_tmp5_, G_VARIANT_TYPE ("ai")); + for (_tmp6_ = 0; _tmp6_ < j_length1; _tmp6_++) { + g_variant_builder_add_value (&_tmp5_, g_variant_new_int32 (*_tmp4_)); + _tmp4_++; + } + g_variant_builder_add_value (&_reply_builder, g_variant_builder_end (&_tmp5_)); + _tmp7_ = result; + g_variant_builder_init (&_tmp8_, G_VARIANT_TYPE ("ai")); + for (_tmp9_ = 0; _tmp9_ < result_length1; _tmp9_++) { + g_variant_builder_add_value (&_tmp8_, g_variant_new_int32 (*_tmp7_)); + _tmp7_++; + } + g_variant_builder_add_value (&_reply_builder, g_variant_builder_end (&_tmp8_)); + result = (g_free (result), NULL); + _reply = g_variant_builder_end (&_reply_builder); + g_dbus_message_set_body (_reply_message, _reply); + g_dbus_connection_send_message (g_dbus_method_invocation_get_connection (invocation), _reply_message, G_DBUS_SEND_MESSAGE_FLAGS_NONE, NULL, NULL); + g_object_unref (invocation); + g_object_unref (_reply_message); + i = (g_free (i), NULL); + j = (g_free (j), NULL); +} + +static void +_dbus_test_test_string (Test* self, + GVariant* _parameters_, + GDBusMethodInvocation* invocation) +{ + GError* error = NULL; + GVariantIter _arguments_iter; + gchar** s = NULL; + gint s_length1 = 0; + GVariant* _tmp10_; + gchar** _tmp11_; + gint _tmp11__length; + gint _tmp11__size; + gint _tmp11__length1; + GVariantIter _tmp12_; + GVariant* _tmp13_; + GDBusMessage* _reply_message = NULL; + GVariant* _reply; + GVariantBuilder _reply_builder; + gchar** t = NULL; + gint t_length1 = 0; + gchar** _tmp14_; + GVariantBuilder _tmp15_; + gint _tmp16_; + gchar** result; + gint result_length1 = 0; + gchar** _tmp17_; + GVariantBuilder _tmp18_; + gint _tmp19_; + g_variant_iter_init (&_arguments_iter, _parameters_); + _tmp10_ = g_variant_iter_next_value (&_arguments_iter); + _tmp11_ = g_new (gchar*, 5); + _tmp11__length = 0; + _tmp11__size = 4; + _tmp11__length1 = 0; + g_variant_iter_init (&_tmp12_, _tmp10_); + for (; (_tmp13_ = g_variant_iter_next_value (&_tmp12_)) != NULL; _tmp11__length1++) { + if (_tmp11__size == _tmp11__length) { + _tmp11__size = 2 * _tmp11__size; + _tmp11_ = g_renew (gchar*, _tmp11_, _tmp11__size + 1); + } + _tmp11_[_tmp11__length++] = g_variant_dup_string (_tmp13_, NULL); + g_variant_unref (_tmp13_); + } + s_length1 = _tmp11__length1; + _tmp11_[_tmp11__length] = NULL; + s = _tmp11_; + g_variant_unref (_tmp10_); + result = test_test_string (self, s, s_length1, &t, &t_length1, &result_length1); + _reply_message = g_dbus_message_new_method_reply (g_dbus_method_invocation_get_message (invocation)); + g_variant_builder_init (&_reply_builder, G_VARIANT_TYPE_TUPLE); + _tmp14_ = t; + g_variant_builder_init (&_tmp15_, G_VARIANT_TYPE ("as")); + for (_tmp16_ = 0; _tmp16_ < t_length1; _tmp16_++) { + g_variant_builder_add_value (&_tmp15_, g_variant_new_string (*_tmp14_)); + _tmp14_++; + } + g_variant_builder_add_value (&_reply_builder, g_variant_builder_end (&_tmp15_)); + _tmp17_ = result; + g_variant_builder_init (&_tmp18_, G_VARIANT_TYPE ("as")); + for (_tmp19_ = 0; _tmp19_ < result_length1; _tmp19_++) { + g_variant_builder_add_value (&_tmp18_, g_variant_new_string (*_tmp17_)); + _tmp17_++; + } + g_variant_builder_add_value (&_reply_builder, g_variant_builder_end (&_tmp18_)); + result = (_vala_array_free (result, result_length1, (GDestroyNotify) g_free), NULL); + _reply = g_variant_builder_end (&_reply_builder); + g_dbus_message_set_body (_reply_message, _reply); + g_dbus_connection_send_message (g_dbus_method_invocation_get_connection (invocation), _reply_message, G_DBUS_SEND_MESSAGE_FLAGS_NONE, NULL, NULL); + g_object_unref (invocation); + g_object_unref (_reply_message); + s = (_vala_array_free (s, s_length1, (GDestroyNotify) g_free), NULL); + t = (_vala_array_free (t, t_length1, (GDestroyNotify) g_free), NULL); +} + +static void +test_dbus_interface_method_call (GDBusConnection* connection, + const gchar* sender, + const gchar* object_path, + const gchar* interface_name, + const gchar* method_name, + GVariant* parameters, + GDBusMethodInvocation* invocation, + gpointer user_data) +{ + gpointer* data; + gpointer object; + data = user_data; + object = data[0]; + if (strcmp (method_name, "TestInt") == 0) { + _dbus_test_test_int (object, parameters, invocation); + } else if (strcmp (method_name, "TestString") == 0) { + _dbus_test_test_string (object, parameters, invocation); + } else { + g_object_unref (invocation); + } +} + +static GVariant* +_dbus_test_get_test_property (Test* self) +{ + gchar** result; + gint result_length1 = 0; + GVariant* _reply; + gchar** _tmp20_; + GVariantBuilder _tmp21_; + gint _tmp22_; + result = test_get_test_property (self, &result_length1); + _tmp20_ = result; + g_variant_builder_init (&_tmp21_, G_VARIANT_TYPE ("as")); + for (_tmp22_ = 0; _tmp22_ < result_length1; _tmp22_++) { + g_variant_builder_add_value (&_tmp21_, g_variant_new_string (*_tmp20_)); + _tmp20_++; + } + _reply = g_variant_builder_end (&_tmp21_); + result = (_vala_array_free (result, result_length1, (GDestroyNotify) g_free), NULL); + return _reply; +} + +static GVariant* +test_dbus_interface_get_property (GDBusConnection* connection, + const gchar* sender, + const gchar* object_path, + const gchar* interface_name, + const gchar* property_name, + GError** error, + gpointer user_data) +{ + gpointer* data; + gpointer object; + data = user_data; + object = data[0]; + if (strcmp (property_name, "TestProperty") == 0) { + return _dbus_test_get_test_property (object); + } + return NULL; +} + +static void +_dbus_test_set_test_property (Test* self, + GVariant* _value) +{ + gchar** value = NULL; + gint value_length1; + gchar** _tmp23_; + gint _tmp23__length; + gint _tmp23__size; + gint _tmp23__length1; + GVariantIter _tmp24_; + GVariant* _tmp25_; + _tmp23_ = g_new (gchar*, 5); + _tmp23__length = 0; + _tmp23__size = 4; + _tmp23__length1 = 0; + g_variant_iter_init (&_tmp24_, _value); + for (; (_tmp25_ = g_variant_iter_next_value (&_tmp24_)) != NULL; _tmp23__length1++) { + if (_tmp23__size == _tmp23__length) { + _tmp23__size = 2 * _tmp23__size; + _tmp23_ = g_renew (gchar*, _tmp23_, _tmp23__size + 1); + } + _tmp23_[_tmp23__length++] = g_variant_dup_string (_tmp25_, NULL); + g_variant_unref (_tmp25_); + } + value_length1 = _tmp23__length1; + _tmp23_[_tmp23__length] = NULL; + value = _tmp23_; + test_set_test_property (self, value, value_length1); + value = (_vala_array_free (value, value_length1, (GDestroyNotify) g_free), NULL); +} + +static gboolean +test_dbus_interface_set_property (GDBusConnection* connection, + const gchar* sender, + const gchar* object_path, + const gchar* interface_name, + const gchar* property_name, + GVariant* value, + GError** error, + gpointer user_data) +{ + gpointer* data; + gpointer object; + data = user_data; + object = data[0]; + if (strcmp (property_name, "TestProperty") == 0) { + _dbus_test_set_test_property (object, value); + return TRUE; + } + return FALSE; +} + +guint +test_register_object (gpointer object, + GDBusConnection* connection, + const gchar* path, + GError** error) +{ + guint result; + gpointer *data; + data = g_new (gpointer, 3); + data[0] = g_object_ref (object); + data[1] = g_object_ref (connection); + data[2] = g_strdup (path); + result = g_dbus_connection_register_object (connection, path, (GDBusInterfaceInfo *) (&_test_dbus_interface_info), &_test_dbus_interface_vtable, data, _test_unregister_object, error); + if (!result) { + return 0; + } + return result; +} + +static void +_test_unregister_object (gpointer user_data) +{ + gpointer* data; + data = user_data; + g_object_unref (data[0]); + g_object_unref (data[1]); + g_free (data[2]); + g_free (data); +} + +void +client_exit (GPid pid, + gint status) +{ + GMainLoop* _tmp0_; + _vala_assert (status == 0, "status == 0"); + _tmp0_ = main_loop; + g_main_loop_quit (_tmp0_); +} + +static guint +_variant_get1 (GVariant* value) +{ + return g_variant_get_uint32 (value); +} + +static void +_client_exit_gchild_watch_func (GPid pid, + gint wait_status, + gpointer self) +{ + client_exit (pid, wait_status); +} + +static void +_vala_main (void) +{ + GDBusConnection* conn = NULL; + GDBusConnection* _tmp0_; + GDBusConnection* _tmp1_; + Test* _tmp2_; + Test* _tmp3_; + GVariant* request_result = NULL; + GDBusConnection* _tmp4_; + GVariant* _tmp5_; + GVariant* _tmp6_; + GVariant* _tmp7_; + GVariant* _tmp8_; + GVariant* _tmp9_; + GVariant* _tmp10_; + GVariant* _tmp11_; + guint _tmp12_; + GPid client_pid = 0; + gchar* _tmp13_; + gchar** _tmp14_; + gchar** _tmp15_; + gint _tmp15__length1; + GPid _tmp16_ = 0; + GMainLoop* _tmp17_; + GMainLoop* _tmp18_; + GError* _inner_error0_ = NULL; + _tmp0_ = g_bus_get_sync (G_BUS_TYPE_SESSION, NULL, &_inner_error0_); + conn = _tmp0_; + if (G_UNLIKELY (_inner_error0_ != NULL)) { + g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error0_->message, g_quark_to_string (_inner_error0_->domain), _inner_error0_->code); + g_clear_error (&_inner_error0_); + return; + } + _tmp1_ = conn; + _tmp2_ = test_new (); + _tmp3_ = _tmp2_; + test_register_object (_tmp3_, _tmp1_, "/org/example/test", &_inner_error0_); + _g_object_unref0 (_tmp3_); + if (G_UNLIKELY (_inner_error0_ != NULL)) { + _g_object_unref0 (conn); + g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error0_->message, g_quark_to_string (_inner_error0_->domain), _inner_error0_->code); + g_clear_error (&_inner_error0_); + return; + } + _tmp4_ = conn; + _tmp5_ = g_variant_new ("(su)", "org.example.Test", 0x4, NULL); + g_variant_ref_sink (_tmp5_); + _tmp6_ = _tmp5_; + _tmp7_ = g_dbus_connection_call_sync (_tmp4_, "org.freedesktop.DBus", "/org/freedesktop/DBus", "org.freedesktop.DBus", "RequestName", _tmp6_, NULL, 0, -1, NULL, &_inner_error0_); + _tmp8_ = _tmp7_; + _g_variant_unref0 (_tmp6_); + request_result = _tmp8_; + if (G_UNLIKELY (_inner_error0_ != NULL)) { + _g_object_unref0 (conn); + g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error0_->message, g_quark_to_string (_inner_error0_->domain), _inner_error0_->code); + g_clear_error (&_inner_error0_); + return; + } + _tmp9_ = request_result; + _tmp10_ = g_variant_get_child_value (_tmp9_, (gsize) 0); + _tmp11_ = _tmp10_; + _tmp12_ = _variant_get1 (_tmp11_); + _vala_assert (_tmp12_ == ((guint) 1), "(uint) request_result.get_child_value (0) == 1"); + _g_variant_unref0 (_tmp11_); + _tmp13_ = g_strdup ("dbus_arrays_client"); + _tmp14_ = g_new0 (gchar*, 1 + 1); + _tmp14_[0] = _tmp13_; + _tmp15_ = _tmp14_; + _tmp15__length1 = 1; + g_spawn_async (NULL, _tmp15_, NULL, G_SPAWN_DO_NOT_REAP_CHILD, NULL, NULL, &_tmp16_, &_inner_error0_); + client_pid = _tmp16_; + _tmp15_ = (_vala_array_free (_tmp15_, _tmp15__length1, (GDestroyNotify) g_free), NULL); + if (G_UNLIKELY (_inner_error0_ != NULL)) { + _g_variant_unref0 (request_result); + _g_object_unref0 (conn); + g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error0_->message, g_quark_to_string (_inner_error0_->domain), _inner_error0_->code); + g_clear_error (&_inner_error0_); + return; + } + g_child_watch_add_full (G_PRIORITY_DEFAULT_IDLE, client_pid, _client_exit_gchild_watch_func, NULL, NULL); + _tmp17_ = g_main_loop_new (NULL, FALSE); + _g_main_loop_unref0 (main_loop); + main_loop = _tmp17_; + _tmp18_ = main_loop; + g_main_loop_run (_tmp18_); + _g_variant_unref0 (request_result); + _g_object_unref0 (conn); +} + +int +main (int argc, + char ** argv) +{ + _vala_main (); + return 0; +} + +static void +_vala_array_destroy (gpointer array, + gssize array_length, + GDestroyNotify destroy_func) +{ + if ((array != NULL) && (destroy_func != NULL)) { + gssize i; + for (i = 0; i < array_length; i = i + 1) { + if (((gpointer*) array)[i] != NULL) { + destroy_func (((gpointer*) array)[i]); + } + } + } +} + +static void +_vala_array_free (gpointer array, + gssize array_length, + GDestroyNotify destroy_func) +{ + _vala_array_destroy (array, array_length, destroy_func); + g_free (array); +} + diff --git a/tests/dbus/async-bus_client.c-expected b/tests/dbus/async-bus_client.c-expected new file mode 100644 index 000000000..5bc147231 --- /dev/null +++ b/tests/dbus/async-bus_client.c-expected @@ -0,0 +1,404 @@ +/* dbus_async_bus_client.c generated by valac, the Vala compiler + * generated from dbus_async_bus_client.vala, do not modify */ + +#include <glib-object.h> +#include <gio/gio.h> +#include <glib.h> +#include <string.h> + +#if !defined(VALA_EXTERN) +#if defined(_MSC_VER) +#define VALA_EXTERN __declspec(dllexport) extern +#elif __GNUC__ >= 4 +#define VALA_EXTERN __attribute__((visibility("default"))) extern +#else +#define VALA_EXTERN extern +#endif +#endif + +#define TYPE_TEST (test_get_type ()) +#define TEST(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TYPE_TEST, Test)) +#define IS_TEST(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TYPE_TEST)) +#define TEST_GET_INTERFACE(obj) (G_TYPE_INSTANCE_GET_INTERFACE ((obj), TYPE_TEST, TestIface)) + +typedef struct _Test Test; +typedef struct _TestIface TestIface; + +#define TYPE_TEST_PROXY (test_proxy_get_type ()) +typedef GDBusProxy TestProxy; +typedef GDBusProxyClass TestProxyClass; +#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL))) +#define _g_main_loop_unref0(var) ((var == NULL) ? NULL : (var = (g_main_loop_unref (var), NULL))) +#define _vala_assert(expr, msg) if G_LIKELY (expr) ; else g_assertion_message_expr (G_LOG_DOMAIN, __FILE__, __LINE__, G_STRFUNC, msg); +#define _vala_return_if_fail(expr, msg) if G_LIKELY (expr) ; else { g_return_if_fail_warning (G_LOG_DOMAIN, G_STRFUNC, msg); return; } +#define _vala_return_val_if_fail(expr, msg, val) if G_LIKELY (expr) ; else { g_return_if_fail_warning (G_LOG_DOMAIN, G_STRFUNC, msg); return val; } +#define _vala_warn_if_fail(expr, msg) if G_LIKELY (expr) ; else g_warn_message (G_LOG_DOMAIN, __FILE__, __LINE__, G_STRFUNC, msg); + +struct _TestIface { + GTypeInterface parent_iface; + gint (*get_test) (Test* self, GError** error); +}; + +VALA_EXTERN GMainLoop* main_loop; +GMainLoop* main_loop = NULL; + +VALA_EXTERN GType test_proxy_get_type (void) G_GNUC_CONST ; +VALA_EXTERN guint test_register_object (void* object, + GDBusConnection* connection, + const gchar* path, + GError** error); +VALA_EXTERN GType test_get_type (void) G_GNUC_CONST ; +VALA_EXTERN gint test_get_test (Test* self, + GError** error); +static GType test_get_type_once (void); +static void test_proxy_g_signal (GDBusProxy* proxy, + const gchar* sender_name, + const gchar* signal_name, + GVariant* parameters); +static gint test_proxy_get_test (Test* self, + GError** error); +static void test_proxy_test_interface_init (TestIface* iface); +static void _dbus_test_get_test (Test* self, + GVariant* _parameters_, + GDBusMethodInvocation* invocation); +static void test_dbus_interface_method_call (GDBusConnection* connection, + const gchar* sender, + const gchar* object_path, + const gchar* interface_name, + const gchar* method_name, + GVariant* parameters, + GDBusMethodInvocation* invocation, + gpointer user_data); +static GVariant* test_dbus_interface_get_property (GDBusConnection* connection, + const gchar* sender, + const gchar* object_path, + const gchar* interface_name, + const gchar* property_name, + GError** error, + gpointer user_data); +static gboolean test_dbus_interface_set_property (GDBusConnection* connection, + const gchar* sender, + const gchar* object_path, + const gchar* interface_name, + const gchar* property_name, + GVariant* value, + GError** error, + gpointer user_data); +static void _test_unregister_object (gpointer user_data); +static void _vala_main (void); +static void __lambda4_ (GObject* o, + GAsyncResult* r); +static void ___lambda4__gasync_ready_callback (GObject* source_object, + GAsyncResult* res, + gpointer self); + +static const GDBusArgInfo _test_dbus_arg_info_get_test_result = {-1, "result", "i", NULL}; +static const GDBusArgInfo * const _test_dbus_arg_info_get_test_in[] = {NULL}; +static const GDBusArgInfo * const _test_dbus_arg_info_get_test_out[] = {&_test_dbus_arg_info_get_test_result, NULL}; +static const GDBusMethodInfo _test_dbus_method_info_get_test = {-1, "GetTest", (GDBusArgInfo **) (&_test_dbus_arg_info_get_test_in), (GDBusArgInfo **) (&_test_dbus_arg_info_get_test_out), NULL}; +static const GDBusMethodInfo * const _test_dbus_method_info[] = {&_test_dbus_method_info_get_test, NULL}; +static const GDBusSignalInfo * const _test_dbus_signal_info[] = {NULL}; +static const GDBusPropertyInfo * const _test_dbus_property_info[] = {NULL}; +static const GDBusInterfaceInfo _test_dbus_interface_info = {-1, "org.example.Test", (GDBusMethodInfo **) (&_test_dbus_method_info), (GDBusSignalInfo **) (&_test_dbus_signal_info), (GDBusPropertyInfo **) (&_test_dbus_property_info), NULL}; +static const GDBusInterfaceVTable _test_dbus_interface_vtable = {test_dbus_interface_method_call, test_dbus_interface_get_property, test_dbus_interface_set_property}; + +gint +test_get_test (Test* self, + GError** error) +{ + TestIface* _iface_; + g_return_val_if_fail (IS_TEST (self), 0); + _iface_ = TEST_GET_INTERFACE (self); + if (_iface_->get_test) { + return _iface_->get_test (self, error); + } + return -1; +} + +static void +test_default_init (TestIface * iface, + gpointer iface_data) +{ +} + +static GType +test_get_type_once (void) +{ + static const GTypeInfo g_define_type_info = { sizeof (TestIface), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) test_default_init, (GClassFinalizeFunc) NULL, NULL, 0, 0, (GInstanceInitFunc) NULL, NULL }; + GType test_type_id; + test_type_id = g_type_register_static (G_TYPE_INTERFACE, "Test", &g_define_type_info, 0); + g_type_interface_add_prerequisite (test_type_id, G_TYPE_OBJECT); + g_type_set_qdata (test_type_id, g_quark_from_static_string ("vala-dbus-proxy-type"), (void*) test_proxy_get_type); + g_type_set_qdata (test_type_id, g_quark_from_static_string ("vala-dbus-interface-name"), "org.example.Test"); + g_type_set_qdata (test_type_id, g_quark_from_static_string ("vala-dbus-interface-info"), (void*) (&_test_dbus_interface_info)); + g_type_set_qdata (test_type_id, g_quark_from_static_string ("vala-dbus-register-object"), (void*) test_register_object); + return test_type_id; +} + +GType +test_get_type (void) +{ + static volatile gsize test_type_id__volatile = 0; + if (g_once_init_enter (&test_type_id__volatile)) { + GType test_type_id; + test_type_id = test_get_type_once (); + g_once_init_leave (&test_type_id__volatile, test_type_id); + } + return test_type_id__volatile; +} + +G_DEFINE_TYPE_EXTENDED (TestProxy, test_proxy, G_TYPE_DBUS_PROXY, 0, G_IMPLEMENT_INTERFACE (TYPE_TEST, test_proxy_test_interface_init) ) +static void +test_proxy_class_init (TestProxyClass* klass) +{ + G_DBUS_PROXY_CLASS (klass)->g_signal = test_proxy_g_signal; +} + +static void +test_proxy_g_signal (GDBusProxy* proxy, + const gchar* sender_name, + const gchar* signal_name, + GVariant* parameters) +{ +} + +static void +test_proxy_init (TestProxy* self) +{ + g_dbus_proxy_set_interface_info (G_DBUS_PROXY (self), (GDBusInterfaceInfo *) (&_test_dbus_interface_info)); +} + +static gint +test_proxy_get_test (Test* self, + GError** error) +{ + GDBusMessage *_message; + GVariant *_arguments; + GVariantBuilder _arguments_builder; + GDBusMessage *_reply_message; + GVariant *_reply; + GVariantIter _reply_iter; + gint _result = 0; + GVariant* _tmp2_; + G_DBUS_ERROR; + G_IO_ERROR; + _message = g_dbus_message_new_method_call (g_dbus_proxy_get_name ((GDBusProxy *) self), g_dbus_proxy_get_object_path ((GDBusProxy *) self), "org.example.Test", "GetTest"); + g_variant_builder_init (&_arguments_builder, G_VARIANT_TYPE_TUPLE); + _arguments = g_variant_builder_end (&_arguments_builder); + g_dbus_message_set_body (_message, _arguments); + _reply_message = g_dbus_connection_send_message_with_reply_sync (g_dbus_proxy_get_connection ((GDBusProxy *) self), _message, G_DBUS_SEND_MESSAGE_FLAGS_NONE, g_dbus_proxy_get_default_timeout ((GDBusProxy *) self), NULL, NULL, error); + g_object_unref (_message); + if (!_reply_message) { + gint _tmp0_ = 0; + return _tmp0_; + } + if (g_dbus_message_to_gerror (_reply_message, error)) { + gint _tmp1_ = 0; + g_object_unref (_reply_message); + return _tmp1_; + } + _reply = g_dbus_message_get_body (_reply_message); + g_variant_iter_init (&_reply_iter, _reply); + _tmp2_ = g_variant_iter_next_value (&_reply_iter); + _result = g_variant_get_int32 (_tmp2_); + g_variant_unref (_tmp2_); + g_object_unref (_reply_message); + return _result; +} + +static void +test_proxy_test_interface_init (TestIface* iface) +{ + iface->get_test = test_proxy_get_test; +} + +static void +_dbus_test_get_test (Test* self, + GVariant* _parameters_, + GDBusMethodInvocation* invocation) +{ + GError* error = NULL; + GVariantIter _arguments_iter; + GDBusMessage* _reply_message = NULL; + GVariant* _reply; + GVariantBuilder _reply_builder; + gint result; + g_variant_iter_init (&_arguments_iter, _parameters_); + result = test_get_test (self, &error); + if (error) { + g_dbus_method_invocation_return_gerror (invocation, error); + g_error_free (error); + return; + } + _reply_message = g_dbus_message_new_method_reply (g_dbus_method_invocation_get_message (invocation)); + g_variant_builder_init (&_reply_builder, G_VARIANT_TYPE_TUPLE); + g_variant_builder_add_value (&_reply_builder, g_variant_new_int32 (result)); + _reply = g_variant_builder_end (&_reply_builder); + g_dbus_message_set_body (_reply_message, _reply); + g_dbus_connection_send_message (g_dbus_method_invocation_get_connection (invocation), _reply_message, G_DBUS_SEND_MESSAGE_FLAGS_NONE, NULL, NULL); + g_object_unref (invocation); + g_object_unref (_reply_message); +} + +static void +test_dbus_interface_method_call (GDBusConnection* connection, + const gchar* sender, + const gchar* object_path, + const gchar* interface_name, + const gchar* method_name, + GVariant* parameters, + GDBusMethodInvocation* invocation, + gpointer user_data) +{ + gpointer* data; + gpointer object; + data = user_data; + object = data[0]; + if (strcmp (method_name, "GetTest") == 0) { + _dbus_test_get_test (object, parameters, invocation); + } else { + g_object_unref (invocation); + } +} + +static GVariant* +test_dbus_interface_get_property (GDBusConnection* connection, + const gchar* sender, + const gchar* object_path, + const gchar* interface_name, + const gchar* property_name, + GError** error, + gpointer user_data) +{ + gpointer* data; + gpointer object; + data = user_data; + object = data[0]; + return NULL; +} + +static gboolean +test_dbus_interface_set_property (GDBusConnection* connection, + const gchar* sender, + const gchar* object_path, + const gchar* interface_name, + const gchar* property_name, + GVariant* value, + GError** error, + gpointer user_data) +{ + gpointer* data; + gpointer object; + data = user_data; + object = data[0]; + return FALSE; +} + +guint +test_register_object (gpointer object, + GDBusConnection* connection, + const gchar* path, + GError** error) +{ + guint result; + gpointer *data; + data = g_new (gpointer, 3); + data[0] = g_object_ref (object); + data[1] = g_object_ref (connection); + data[2] = g_strdup (path); + result = g_dbus_connection_register_object (connection, path, (GDBusInterfaceInfo *) (&_test_dbus_interface_info), &_test_dbus_interface_vtable, data, _test_unregister_object, error); + if (!result) { + return 0; + } + return result; +} + +static void +_test_unregister_object (gpointer user_data) +{ + gpointer* data; + data = user_data; + g_object_unref (data[0]); + g_object_unref (data[1]); + g_free (data[2]); + g_free (data); +} + +static void +__lambda4_ (GObject* o, + GAsyncResult* r) +{ + GError* _inner_error0_ = NULL; + g_return_if_fail ((o == NULL) || G_TYPE_CHECK_INSTANCE_TYPE (o, G_TYPE_OBJECT)); + g_return_if_fail (G_TYPE_CHECK_INSTANCE_TYPE (r, g_async_result_get_type ())); + { + Test* test = NULL; + Test* _tmp0_; + Test* _tmp1_; + gint _tmp2_ = 0; + Test* _tmp3_; + _tmp0_ = g_async_result_get_source_object (r); + _tmp1_ = (Test*) g_async_initable_new_finish ((GAsyncInitable *) _tmp0_, r, &_inner_error0_); + g_object_unref (_tmp0_); + test = (Test*) _tmp1_; + if (G_UNLIKELY (_inner_error0_ != NULL)) { + goto __catch0_g_error; + } + _tmp3_ = test; + _tmp2_ = test_get_test (_tmp3_, &_inner_error0_); + if (G_UNLIKELY (_inner_error0_ != NULL)) { + _g_object_unref0 (test); + goto __catch0_g_error; + } + _vala_assert (_tmp2_ == 4711, "test.get_test () == 4711"); + _g_object_unref0 (test); + } + goto __finally0; + __catch0_g_error: + { + g_clear_error (&_inner_error0_); + } + __finally0: + { + GError* _inner_error1_ = NULL; + GMainLoop* _tmp4_; + _tmp4_ = main_loop; + g_main_loop_quit (_tmp4_); + } + if (G_UNLIKELY (_inner_error0_ != NULL)) { + g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error0_->message, g_quark_to_string (_inner_error0_->domain), _inner_error0_->code); + g_clear_error (&_inner_error0_); + return; + } +} + +static void +___lambda4__gasync_ready_callback (GObject* source_object, + GAsyncResult* res, + gpointer self) +{ + __lambda4_ (source_object, res); +} + +static void +_vala_main (void) +{ + GMainLoop* _tmp0_; + GMainLoop* _tmp1_; + GError* _inner_error0_ = NULL; + g_async_initable_new_async (TYPE_TEST_PROXY, 0, NULL, ___lambda4__gasync_ready_callback, NULL, "g-flags", 0, "g-name", "org.example.Test", "g-bus-type", G_BUS_TYPE_SESSION, "g-object-path", "/org/example/test", "g-interface-name", "org.example.Test", NULL); + _tmp0_ = g_main_loop_new (NULL, FALSE); + _g_main_loop_unref0 (main_loop); + main_loop = _tmp0_; + _tmp1_ = main_loop; + g_main_loop_run (_tmp1_); +} + +int +main (int argc, + char ** argv) +{ + _vala_main (); + return 0; +} + diff --git a/tests/dbus/async-bus_server.c-expected b/tests/dbus/async-bus_server.c-expected new file mode 100644 index 000000000..2986ba176 --- /dev/null +++ b/tests/dbus/async-bus_server.c-expected @@ -0,0 +1,434 @@ +/* dbus_async_bus_server.c generated by valac, the Vala compiler + * generated from dbus_async_bus_server.vala, do not modify */ + +#include <glib-object.h> +#include <gio/gio.h> +#include <glib.h> +#include <string.h> +#include <stdlib.h> + +#if !defined(VALA_EXTERN) +#if defined(_MSC_VER) +#define VALA_EXTERN __declspec(dllexport) extern +#elif __GNUC__ >= 4 +#define VALA_EXTERN __attribute__((visibility("default"))) extern +#else +#define VALA_EXTERN extern +#endif +#endif + +#define TYPE_TEST (test_get_type ()) +#define TEST(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TYPE_TEST, Test)) +#define TEST_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), TYPE_TEST, TestClass)) +#define IS_TEST(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TYPE_TEST)) +#define IS_TEST_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), TYPE_TEST)) +#define TEST_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), TYPE_TEST, TestClass)) + +typedef struct _Test Test; +typedef struct _TestClass TestClass; +typedef struct _TestPrivate TestPrivate; +enum { + TEST_0_PROPERTY, + TEST_NUM_PROPERTIES +}; +static GParamSpec* test_properties[TEST_NUM_PROPERTIES]; +#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL))) +#define _g_variant_unref0(var) ((var == NULL) ? NULL : (var = (g_variant_unref (var), NULL))) +#define _g_main_loop_unref0(var) ((var == NULL) ? NULL : (var = (g_main_loop_unref (var), NULL))) +#define _vala_assert(expr, msg) if G_LIKELY (expr) ; else g_assertion_message_expr (G_LOG_DOMAIN, __FILE__, __LINE__, G_STRFUNC, msg); +#define _vala_return_if_fail(expr, msg) if G_LIKELY (expr) ; else { g_return_if_fail_warning (G_LOG_DOMAIN, G_STRFUNC, msg); return; } +#define _vala_return_val_if_fail(expr, msg, val) if G_LIKELY (expr) ; else { g_return_if_fail_warning (G_LOG_DOMAIN, G_STRFUNC, msg); return val; } +#define _vala_warn_if_fail(expr, msg) if G_LIKELY (expr) ; else g_warn_message (G_LOG_DOMAIN, __FILE__, __LINE__, G_STRFUNC, msg); + +struct _Test { + GObject parent_instance; + TestPrivate * priv; +}; + +struct _TestClass { + GObjectClass parent_class; +}; + +static gpointer test_parent_class = NULL; +VALA_EXTERN GMainLoop* main_loop; +GMainLoop* main_loop = NULL; + +VALA_EXTERN GType test_get_type (void) G_GNUC_CONST ; +G_DEFINE_AUTOPTR_CLEANUP_FUNC (Test, g_object_unref) +VALA_EXTERN guint test_register_object (void* object, + GDBusConnection* connection, + const gchar* path, + GError** error); +VALA_EXTERN gint test_get_test (Test* self, + GError** error); +VALA_EXTERN Test* test_new (void); +VALA_EXTERN Test* test_construct (GType object_type); +static GType test_get_type_once (void); +static void _dbus_test_get_test (Test* self, + GVariant* _parameters_, + GDBusMethodInvocation* invocation); +static void test_dbus_interface_method_call (GDBusConnection* connection, + const gchar* sender, + const gchar* object_path, + const gchar* interface_name, + const gchar* method_name, + GVariant* parameters, + GDBusMethodInvocation* invocation, + gpointer user_data); +static GVariant* test_dbus_interface_get_property (GDBusConnection* connection, + const gchar* sender, + const gchar* object_path, + const gchar* interface_name, + const gchar* property_name, + GError** error, + gpointer user_data); +static gboolean test_dbus_interface_set_property (GDBusConnection* connection, + const gchar* sender, + const gchar* object_path, + const gchar* interface_name, + const gchar* property_name, + GVariant* value, + GError** error, + gpointer user_data); +static void _test_unregister_object (gpointer user_data); +VALA_EXTERN void client_exit (GPid pid, + gint status); +static void _vala_main (void); +static guint _variant_get1 (GVariant* value); +static void _client_exit_gchild_watch_func (GPid pid, + gint wait_status, + gpointer self); +static void _vala_array_destroy (gpointer array, + gssize array_length, + GDestroyNotify destroy_func); +static void _vala_array_free (gpointer array, + gssize array_length, + GDestroyNotify destroy_func); + +static const GDBusArgInfo _test_dbus_arg_info_get_test_result = {-1, "result", "i", NULL}; +static const GDBusArgInfo * const _test_dbus_arg_info_get_test_in[] = {NULL}; +static const GDBusArgInfo * const _test_dbus_arg_info_get_test_out[] = {&_test_dbus_arg_info_get_test_result, NULL}; +static const GDBusMethodInfo _test_dbus_method_info_get_test = {-1, "GetTest", (GDBusArgInfo **) (&_test_dbus_arg_info_get_test_in), (GDBusArgInfo **) (&_test_dbus_arg_info_get_test_out), NULL}; +static const GDBusMethodInfo * const _test_dbus_method_info[] = {&_test_dbus_method_info_get_test, NULL}; +static const GDBusSignalInfo * const _test_dbus_signal_info[] = {NULL}; +static const GDBusPropertyInfo * const _test_dbus_property_info[] = {NULL}; +static const GDBusInterfaceInfo _test_dbus_interface_info = {-1, "org.example.Test", (GDBusMethodInfo **) (&_test_dbus_method_info), (GDBusSignalInfo **) (&_test_dbus_signal_info), (GDBusPropertyInfo **) (&_test_dbus_property_info), NULL}; +static const GDBusInterfaceVTable _test_dbus_interface_vtable = {test_dbus_interface_method_call, test_dbus_interface_get_property, test_dbus_interface_set_property}; + +gint +test_get_test (Test* self, + GError** error) +{ + gint result = 0; + g_return_val_if_fail (IS_TEST (self), 0); + result = 4711; + return result; +} + +Test* +test_construct (GType object_type) +{ + Test * self = NULL; + self = (Test*) g_object_new (object_type, NULL); + return self; +} + +Test* +test_new (void) +{ + return test_construct (TYPE_TEST); +} + +static void +test_class_init (TestClass * klass, + gpointer klass_data) +{ + test_parent_class = g_type_class_peek_parent (klass); +} + +static void +test_instance_init (Test * self, + gpointer klass) +{ +} + +static GType +test_get_type_once (void) +{ + static const GTypeInfo g_define_type_info = { sizeof (TestClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) test_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (Test), 0, (GInstanceInitFunc) test_instance_init, NULL }; + GType test_type_id; + test_type_id = g_type_register_static (G_TYPE_OBJECT, "Test", &g_define_type_info, 0); + g_type_set_qdata (test_type_id, g_quark_from_static_string ("vala-dbus-register-object"), (void*) test_register_object); + return test_type_id; +} + +GType +test_get_type (void) +{ + static volatile gsize test_type_id__volatile = 0; + if (g_once_init_enter (&test_type_id__volatile)) { + GType test_type_id; + test_type_id = test_get_type_once (); + g_once_init_leave (&test_type_id__volatile, test_type_id); + } + return test_type_id__volatile; +} + +static void +_dbus_test_get_test (Test* self, + GVariant* _parameters_, + GDBusMethodInvocation* invocation) +{ + GError* error = NULL; + GVariantIter _arguments_iter; + GDBusMessage* _reply_message = NULL; + GVariant* _reply; + GVariantBuilder _reply_builder; + gint result; + g_variant_iter_init (&_arguments_iter, _parameters_); + result = test_get_test (self, &error); + if (error) { + g_dbus_method_invocation_return_gerror (invocation, error); + g_error_free (error); + return; + } + _reply_message = g_dbus_message_new_method_reply (g_dbus_method_invocation_get_message (invocation)); + g_variant_builder_init (&_reply_builder, G_VARIANT_TYPE_TUPLE); + g_variant_builder_add_value (&_reply_builder, g_variant_new_int32 (result)); + _reply = g_variant_builder_end (&_reply_builder); + g_dbus_message_set_body (_reply_message, _reply); + g_dbus_connection_send_message (g_dbus_method_invocation_get_connection (invocation), _reply_message, G_DBUS_SEND_MESSAGE_FLAGS_NONE, NULL, NULL); + g_object_unref (invocation); + g_object_unref (_reply_message); +} + +static void +test_dbus_interface_method_call (GDBusConnection* connection, + const gchar* sender, + const gchar* object_path, + const gchar* interface_name, + const gchar* method_name, + GVariant* parameters, + GDBusMethodInvocation* invocation, + gpointer user_data) +{ + gpointer* data; + gpointer object; + data = user_data; + object = data[0]; + if (strcmp (method_name, "GetTest") == 0) { + _dbus_test_get_test (object, parameters, invocation); + } else { + g_object_unref (invocation); + } +} + +static GVariant* +test_dbus_interface_get_property (GDBusConnection* connection, + const gchar* sender, + const gchar* object_path, + const gchar* interface_name, + const gchar* property_name, + GError** error, + gpointer user_data) +{ + gpointer* data; + gpointer object; + data = user_data; + object = data[0]; + return NULL; +} + +static gboolean +test_dbus_interface_set_property (GDBusConnection* connection, + const gchar* sender, + const gchar* object_path, + const gchar* interface_name, + const gchar* property_name, + GVariant* value, + GError** error, + gpointer user_data) +{ + gpointer* data; + gpointer object; + data = user_data; + object = data[0]; + return FALSE; +} + +guint +test_register_object (gpointer object, + GDBusConnection* connection, + const gchar* path, + GError** error) +{ + guint result; + gpointer *data; + data = g_new (gpointer, 3); + data[0] = g_object_ref (object); + data[1] = g_object_ref (connection); + data[2] = g_strdup (path); + result = g_dbus_connection_register_object (connection, path, (GDBusInterfaceInfo *) (&_test_dbus_interface_info), &_test_dbus_interface_vtable, data, _test_unregister_object, error); + if (!result) { + return 0; + } + return result; +} + +static void +_test_unregister_object (gpointer user_data) +{ + gpointer* data; + data = user_data; + g_object_unref (data[0]); + g_object_unref (data[1]); + g_free (data[2]); + g_free (data); +} + +void +client_exit (GPid pid, + gint status) +{ + GMainLoop* _tmp0_; + _vala_assert (status == 0, "status == 0"); + _tmp0_ = main_loop; + g_main_loop_quit (_tmp0_); +} + +static guint +_variant_get1 (GVariant* value) +{ + return g_variant_get_uint32 (value); +} + +static void +_client_exit_gchild_watch_func (GPid pid, + gint wait_status, + gpointer self) +{ + client_exit (pid, wait_status); +} + +static void +_vala_main (void) +{ + GDBusConnection* conn = NULL; + GDBusConnection* _tmp0_; + GDBusConnection* _tmp1_; + Test* _tmp2_; + Test* _tmp3_; + GVariant* request_result = NULL; + GDBusConnection* _tmp4_; + GVariant* _tmp5_; + GVariant* _tmp6_; + GVariant* _tmp7_; + GVariant* _tmp8_; + GVariant* _tmp9_; + GVariant* _tmp10_; + GVariant* _tmp11_; + guint _tmp12_; + GPid client_pid = 0; + gchar* _tmp13_; + gchar** _tmp14_; + gchar** _tmp15_; + gint _tmp15__length1; + GPid _tmp16_ = 0; + GMainLoop* _tmp17_; + GMainLoop* _tmp18_; + GError* _inner_error0_ = NULL; + _tmp0_ = g_bus_get_sync (G_BUS_TYPE_SESSION, NULL, &_inner_error0_); + conn = _tmp0_; + if (G_UNLIKELY (_inner_error0_ != NULL)) { + g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error0_->message, g_quark_to_string (_inner_error0_->domain), _inner_error0_->code); + g_clear_error (&_inner_error0_); + return; + } + _tmp1_ = conn; + _tmp2_ = test_new (); + _tmp3_ = _tmp2_; + test_register_object (_tmp3_, _tmp1_, "/org/example/test", &_inner_error0_); + _g_object_unref0 (_tmp3_); + if (G_UNLIKELY (_inner_error0_ != NULL)) { + _g_object_unref0 (conn); + g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error0_->message, g_quark_to_string (_inner_error0_->domain), _inner_error0_->code); + g_clear_error (&_inner_error0_); + return; + } + _tmp4_ = conn; + _tmp5_ = g_variant_new ("(su)", "org.example.Test", 0x4, NULL); + g_variant_ref_sink (_tmp5_); + _tmp6_ = _tmp5_; + _tmp7_ = g_dbus_connection_call_sync (_tmp4_, "org.freedesktop.DBus", "/org/freedesktop/DBus", "org.freedesktop.DBus", "RequestName", _tmp6_, NULL, 0, -1, NULL, &_inner_error0_); + _tmp8_ = _tmp7_; + _g_variant_unref0 (_tmp6_); + request_result = _tmp8_; + if (G_UNLIKELY (_inner_error0_ != NULL)) { + _g_object_unref0 (conn); + g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error0_->message, g_quark_to_string (_inner_error0_->domain), _inner_error0_->code); + g_clear_error (&_inner_error0_); + return; + } + _tmp9_ = request_result; + _tmp10_ = g_variant_get_child_value (_tmp9_, (gsize) 0); + _tmp11_ = _tmp10_; + _tmp12_ = _variant_get1 (_tmp11_); + _vala_assert (_tmp12_ == ((guint) 1), "(uint) request_result.get_child_value (0) == 1"); + _g_variant_unref0 (_tmp11_); + _tmp13_ = g_strdup ("dbus_async_bus_client"); + _tmp14_ = g_new0 (gchar*, 1 + 1); + _tmp14_[0] = _tmp13_; + _tmp15_ = _tmp14_; + _tmp15__length1 = 1; + g_spawn_async (NULL, _tmp15_, NULL, G_SPAWN_DO_NOT_REAP_CHILD, NULL, NULL, &_tmp16_, &_inner_error0_); + client_pid = _tmp16_; + _tmp15_ = (_vala_array_free (_tmp15_, _tmp15__length1, (GDestroyNotify) g_free), NULL); + if (G_UNLIKELY (_inner_error0_ != NULL)) { + _g_variant_unref0 (request_result); + _g_object_unref0 (conn); + g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error0_->message, g_quark_to_string (_inner_error0_->domain), _inner_error0_->code); + g_clear_error (&_inner_error0_); + return; + } + g_child_watch_add_full (G_PRIORITY_DEFAULT_IDLE, client_pid, _client_exit_gchild_watch_func, NULL, NULL); + _tmp17_ = g_main_loop_new (NULL, FALSE); + _g_main_loop_unref0 (main_loop); + main_loop = _tmp17_; + _tmp18_ = main_loop; + g_main_loop_run (_tmp18_); + _g_variant_unref0 (request_result); + _g_object_unref0 (conn); +} + +int +main (int argc, + char ** argv) +{ + _vala_main (); + return 0; +} + +static void +_vala_array_destroy (gpointer array, + gssize array_length, + GDestroyNotify destroy_func) +{ + if ((array != NULL) && (destroy_func != NULL)) { + gssize i; + for (i = 0; i < array_length; i = i + 1) { + if (((gpointer*) array)[i] != NULL) { + destroy_func (((gpointer*) array)[i]); + } + } + } +} + +static void +_vala_array_free (gpointer array, + gssize array_length, + GDestroyNotify destroy_func) +{ + _vala_array_destroy (array, array_length, destroy_func); + g_free (array); +} + diff --git a/tests/dbus/async-connection_client.c-expected b/tests/dbus/async-connection_client.c-expected new file mode 100644 index 000000000..30ee60393 --- /dev/null +++ b/tests/dbus/async-connection_client.c-expected @@ -0,0 +1,414 @@ +/* dbus_async_connection_client.c generated by valac, the Vala compiler + * generated from dbus_async_connection_client.vala, do not modify */ + +#include <glib-object.h> +#include <gio/gio.h> +#include <glib.h> +#include <string.h> + +#if !defined(VALA_EXTERN) +#if defined(_MSC_VER) +#define VALA_EXTERN __declspec(dllexport) extern +#elif __GNUC__ >= 4 +#define VALA_EXTERN __attribute__((visibility("default"))) extern +#else +#define VALA_EXTERN extern +#endif +#endif + +#define TYPE_TEST (test_get_type ()) +#define TEST(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TYPE_TEST, Test)) +#define IS_TEST(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TYPE_TEST)) +#define TEST_GET_INTERFACE(obj) (G_TYPE_INSTANCE_GET_INTERFACE ((obj), TYPE_TEST, TestIface)) + +typedef struct _Test Test; +typedef struct _TestIface TestIface; + +#define TYPE_TEST_PROXY (test_proxy_get_type ()) +typedef GDBusProxy TestProxy; +typedef GDBusProxyClass TestProxyClass; +#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL))) +#define _g_main_loop_unref0(var) ((var == NULL) ? NULL : (var = (g_main_loop_unref (var), NULL))) +#define _vala_assert(expr, msg) if G_LIKELY (expr) ; else g_assertion_message_expr (G_LOG_DOMAIN, __FILE__, __LINE__, G_STRFUNC, msg); +#define _vala_return_if_fail(expr, msg) if G_LIKELY (expr) ; else { g_return_if_fail_warning (G_LOG_DOMAIN, G_STRFUNC, msg); return; } +#define _vala_return_val_if_fail(expr, msg, val) if G_LIKELY (expr) ; else { g_return_if_fail_warning (G_LOG_DOMAIN, G_STRFUNC, msg); return val; } +#define _vala_warn_if_fail(expr, msg) if G_LIKELY (expr) ; else g_warn_message (G_LOG_DOMAIN, __FILE__, __LINE__, G_STRFUNC, msg); + +struct _TestIface { + GTypeInterface parent_iface; + gint (*get_test) (Test* self, GError** error); +}; + +VALA_EXTERN GMainLoop* main_loop; +GMainLoop* main_loop = NULL; + +VALA_EXTERN GType test_proxy_get_type (void) G_GNUC_CONST ; +VALA_EXTERN guint test_register_object (void* object, + GDBusConnection* connection, + const gchar* path, + GError** error); +VALA_EXTERN GType test_get_type (void) G_GNUC_CONST ; +VALA_EXTERN gint test_get_test (Test* self, + GError** error); +static GType test_get_type_once (void); +static void test_proxy_g_signal (GDBusProxy* proxy, + const gchar* sender_name, + const gchar* signal_name, + GVariant* parameters); +static gint test_proxy_get_test (Test* self, + GError** error); +static void test_proxy_test_interface_init (TestIface* iface); +static void _dbus_test_get_test (Test* self, + GVariant* _parameters_, + GDBusMethodInvocation* invocation); +static void test_dbus_interface_method_call (GDBusConnection* connection, + const gchar* sender, + const gchar* object_path, + const gchar* interface_name, + const gchar* method_name, + GVariant* parameters, + GDBusMethodInvocation* invocation, + gpointer user_data); +static GVariant* test_dbus_interface_get_property (GDBusConnection* connection, + const gchar* sender, + const gchar* object_path, + const gchar* interface_name, + const gchar* property_name, + GError** error, + gpointer user_data); +static gboolean test_dbus_interface_set_property (GDBusConnection* connection, + const gchar* sender, + const gchar* object_path, + const gchar* interface_name, + const gchar* property_name, + GVariant* value, + GError** error, + gpointer user_data); +static void _test_unregister_object (gpointer user_data); +static void _vala_main (void); +static void __lambda4_ (GObject* o, + GAsyncResult* r); +static void ___lambda4__gasync_ready_callback (GObject* source_object, + GAsyncResult* res, + gpointer self); + +static const GDBusArgInfo _test_dbus_arg_info_get_test_result = {-1, "result", "i", NULL}; +static const GDBusArgInfo * const _test_dbus_arg_info_get_test_in[] = {NULL}; +static const GDBusArgInfo * const _test_dbus_arg_info_get_test_out[] = {&_test_dbus_arg_info_get_test_result, NULL}; +static const GDBusMethodInfo _test_dbus_method_info_get_test = {-1, "GetTest", (GDBusArgInfo **) (&_test_dbus_arg_info_get_test_in), (GDBusArgInfo **) (&_test_dbus_arg_info_get_test_out), NULL}; +static const GDBusMethodInfo * const _test_dbus_method_info[] = {&_test_dbus_method_info_get_test, NULL}; +static const GDBusSignalInfo * const _test_dbus_signal_info[] = {NULL}; +static const GDBusPropertyInfo * const _test_dbus_property_info[] = {NULL}; +static const GDBusInterfaceInfo _test_dbus_interface_info = {-1, "org.example.Test", (GDBusMethodInfo **) (&_test_dbus_method_info), (GDBusSignalInfo **) (&_test_dbus_signal_info), (GDBusPropertyInfo **) (&_test_dbus_property_info), NULL}; +static const GDBusInterfaceVTable _test_dbus_interface_vtable = {test_dbus_interface_method_call, test_dbus_interface_get_property, test_dbus_interface_set_property}; + +gint +test_get_test (Test* self, + GError** error) +{ + TestIface* _iface_; + g_return_val_if_fail (IS_TEST (self), 0); + _iface_ = TEST_GET_INTERFACE (self); + if (_iface_->get_test) { + return _iface_->get_test (self, error); + } + return -1; +} + +static void +test_default_init (TestIface * iface, + gpointer iface_data) +{ +} + +static GType +test_get_type_once (void) +{ + static const GTypeInfo g_define_type_info = { sizeof (TestIface), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) test_default_init, (GClassFinalizeFunc) NULL, NULL, 0, 0, (GInstanceInitFunc) NULL, NULL }; + GType test_type_id; + test_type_id = g_type_register_static (G_TYPE_INTERFACE, "Test", &g_define_type_info, 0); + g_type_interface_add_prerequisite (test_type_id, G_TYPE_OBJECT); + g_type_set_qdata (test_type_id, g_quark_from_static_string ("vala-dbus-proxy-type"), (void*) test_proxy_get_type); + g_type_set_qdata (test_type_id, g_quark_from_static_string ("vala-dbus-interface-name"), "org.example.Test"); + g_type_set_qdata (test_type_id, g_quark_from_static_string ("vala-dbus-interface-info"), (void*) (&_test_dbus_interface_info)); + g_type_set_qdata (test_type_id, g_quark_from_static_string ("vala-dbus-register-object"), (void*) test_register_object); + return test_type_id; +} + +GType +test_get_type (void) +{ + static volatile gsize test_type_id__volatile = 0; + if (g_once_init_enter (&test_type_id__volatile)) { + GType test_type_id; + test_type_id = test_get_type_once (); + g_once_init_leave (&test_type_id__volatile, test_type_id); + } + return test_type_id__volatile; +} + +G_DEFINE_TYPE_EXTENDED (TestProxy, test_proxy, G_TYPE_DBUS_PROXY, 0, G_IMPLEMENT_INTERFACE (TYPE_TEST, test_proxy_test_interface_init) ) +static void +test_proxy_class_init (TestProxyClass* klass) +{ + G_DBUS_PROXY_CLASS (klass)->g_signal = test_proxy_g_signal; +} + +static void +test_proxy_g_signal (GDBusProxy* proxy, + const gchar* sender_name, + const gchar* signal_name, + GVariant* parameters) +{ +} + +static void +test_proxy_init (TestProxy* self) +{ + g_dbus_proxy_set_interface_info (G_DBUS_PROXY (self), (GDBusInterfaceInfo *) (&_test_dbus_interface_info)); +} + +static gint +test_proxy_get_test (Test* self, + GError** error) +{ + GDBusMessage *_message; + GVariant *_arguments; + GVariantBuilder _arguments_builder; + GDBusMessage *_reply_message; + GVariant *_reply; + GVariantIter _reply_iter; + gint _result = 0; + GVariant* _tmp2_; + G_DBUS_ERROR; + G_IO_ERROR; + _message = g_dbus_message_new_method_call (g_dbus_proxy_get_name ((GDBusProxy *) self), g_dbus_proxy_get_object_path ((GDBusProxy *) self), "org.example.Test", "GetTest"); + g_variant_builder_init (&_arguments_builder, G_VARIANT_TYPE_TUPLE); + _arguments = g_variant_builder_end (&_arguments_builder); + g_dbus_message_set_body (_message, _arguments); + _reply_message = g_dbus_connection_send_message_with_reply_sync (g_dbus_proxy_get_connection ((GDBusProxy *) self), _message, G_DBUS_SEND_MESSAGE_FLAGS_NONE, g_dbus_proxy_get_default_timeout ((GDBusProxy *) self), NULL, NULL, error); + g_object_unref (_message); + if (!_reply_message) { + gint _tmp0_ = 0; + return _tmp0_; + } + if (g_dbus_message_to_gerror (_reply_message, error)) { + gint _tmp1_ = 0; + g_object_unref (_reply_message); + return _tmp1_; + } + _reply = g_dbus_message_get_body (_reply_message); + g_variant_iter_init (&_reply_iter, _reply); + _tmp2_ = g_variant_iter_next_value (&_reply_iter); + _result = g_variant_get_int32 (_tmp2_); + g_variant_unref (_tmp2_); + g_object_unref (_reply_message); + return _result; +} + +static void +test_proxy_test_interface_init (TestIface* iface) +{ + iface->get_test = test_proxy_get_test; +} + +static void +_dbus_test_get_test (Test* self, + GVariant* _parameters_, + GDBusMethodInvocation* invocation) +{ + GError* error = NULL; + GVariantIter _arguments_iter; + GDBusMessage* _reply_message = NULL; + GVariant* _reply; + GVariantBuilder _reply_builder; + gint result; + g_variant_iter_init (&_arguments_iter, _parameters_); + result = test_get_test (self, &error); + if (error) { + g_dbus_method_invocation_return_gerror (invocation, error); + g_error_free (error); + return; + } + _reply_message = g_dbus_message_new_method_reply (g_dbus_method_invocation_get_message (invocation)); + g_variant_builder_init (&_reply_builder, G_VARIANT_TYPE_TUPLE); + g_variant_builder_add_value (&_reply_builder, g_variant_new_int32 (result)); + _reply = g_variant_builder_end (&_reply_builder); + g_dbus_message_set_body (_reply_message, _reply); + g_dbus_connection_send_message (g_dbus_method_invocation_get_connection (invocation), _reply_message, G_DBUS_SEND_MESSAGE_FLAGS_NONE, NULL, NULL); + g_object_unref (invocation); + g_object_unref (_reply_message); +} + +static void +test_dbus_interface_method_call (GDBusConnection* connection, + const gchar* sender, + const gchar* object_path, + const gchar* interface_name, + const gchar* method_name, + GVariant* parameters, + GDBusMethodInvocation* invocation, + gpointer user_data) +{ + gpointer* data; + gpointer object; + data = user_data; + object = data[0]; + if (strcmp (method_name, "GetTest") == 0) { + _dbus_test_get_test (object, parameters, invocation); + } else { + g_object_unref (invocation); + } +} + +static GVariant* +test_dbus_interface_get_property (GDBusConnection* connection, + const gchar* sender, + const gchar* object_path, + const gchar* interface_name, + const gchar* property_name, + GError** error, + gpointer user_data) +{ + gpointer* data; + gpointer object; + data = user_data; + object = data[0]; + return NULL; +} + +static gboolean +test_dbus_interface_set_property (GDBusConnection* connection, + const gchar* sender, + const gchar* object_path, + const gchar* interface_name, + const gchar* property_name, + GVariant* value, + GError** error, + gpointer user_data) +{ + gpointer* data; + gpointer object; + data = user_data; + object = data[0]; + return FALSE; +} + +guint +test_register_object (gpointer object, + GDBusConnection* connection, + const gchar* path, + GError** error) +{ + guint result; + gpointer *data; + data = g_new (gpointer, 3); + data[0] = g_object_ref (object); + data[1] = g_object_ref (connection); + data[2] = g_strdup (path); + result = g_dbus_connection_register_object (connection, path, (GDBusInterfaceInfo *) (&_test_dbus_interface_info), &_test_dbus_interface_vtable, data, _test_unregister_object, error); + if (!result) { + return 0; + } + return result; +} + +static void +_test_unregister_object (gpointer user_data) +{ + gpointer* data; + data = user_data; + g_object_unref (data[0]); + g_object_unref (data[1]); + g_free (data[2]); + g_free (data); +} + +static void +__lambda4_ (GObject* o, + GAsyncResult* r) +{ + GError* _inner_error0_ = NULL; + g_return_if_fail ((o == NULL) || G_TYPE_CHECK_INSTANCE_TYPE (o, G_TYPE_OBJECT)); + g_return_if_fail (G_TYPE_CHECK_INSTANCE_TYPE (r, g_async_result_get_type ())); + { + Test* test = NULL; + Test* _tmp0_; + Test* _tmp1_; + gint _tmp2_ = 0; + Test* _tmp3_; + _tmp0_ = g_async_result_get_source_object (r); + _tmp1_ = (Test*) g_async_initable_new_finish ((GAsyncInitable *) _tmp0_, r, &_inner_error0_); + g_object_unref (_tmp0_); + test = (Test*) _tmp1_; + if (G_UNLIKELY (_inner_error0_ != NULL)) { + goto __catch0_g_error; + } + _tmp3_ = test; + _tmp2_ = test_get_test (_tmp3_, &_inner_error0_); + if (G_UNLIKELY (_inner_error0_ != NULL)) { + _g_object_unref0 (test); + goto __catch0_g_error; + } + _vala_assert (_tmp2_ == 4711, "test.get_test () == 4711"); + _g_object_unref0 (test); + } + goto __finally0; + __catch0_g_error: + { + g_clear_error (&_inner_error0_); + } + __finally0: + { + GError* _inner_error1_ = NULL; + GMainLoop* _tmp4_; + _tmp4_ = main_loop; + g_main_loop_quit (_tmp4_); + } + if (G_UNLIKELY (_inner_error0_ != NULL)) { + g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error0_->message, g_quark_to_string (_inner_error0_->domain), _inner_error0_->code); + g_clear_error (&_inner_error0_); + return; + } +} + +static void +___lambda4__gasync_ready_callback (GObject* source_object, + GAsyncResult* res, + gpointer self) +{ + __lambda4_ (source_object, res); +} + +static void +_vala_main (void) +{ + GDBusConnection* conn = NULL; + GDBusConnection* _tmp0_; + GMainLoop* _tmp1_; + GMainLoop* _tmp2_; + GError* _inner_error0_ = NULL; + _tmp0_ = g_bus_get_sync (G_BUS_TYPE_SESSION, NULL, &_inner_error0_); + conn = _tmp0_; + if (G_UNLIKELY (_inner_error0_ != NULL)) { + g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error0_->message, g_quark_to_string (_inner_error0_->domain), _inner_error0_->code); + g_clear_error (&_inner_error0_); + return; + } + g_async_initable_new_async (TYPE_TEST_PROXY, 0, NULL, ___lambda4__gasync_ready_callback, NULL, "g-flags", 0, "g-name", "org.example.Test", "g-connection", conn, "g-object-path", "/org/example/test", "g-interface-name", "org.example.Test", NULL); + _tmp1_ = g_main_loop_new (NULL, FALSE); + _g_main_loop_unref0 (main_loop); + main_loop = _tmp1_; + _tmp2_ = main_loop; + g_main_loop_run (_tmp2_); + _g_object_unref0 (conn); +} + +int +main (int argc, + char ** argv) +{ + _vala_main (); + return 0; +} + diff --git a/tests/dbus/async-connection_server.c-expected b/tests/dbus/async-connection_server.c-expected new file mode 100644 index 000000000..ef52a336d --- /dev/null +++ b/tests/dbus/async-connection_server.c-expected @@ -0,0 +1,434 @@ +/* dbus_async_connection_server.c generated by valac, the Vala compiler + * generated from dbus_async_connection_server.vala, do not modify */ + +#include <glib-object.h> +#include <gio/gio.h> +#include <glib.h> +#include <string.h> +#include <stdlib.h> + +#if !defined(VALA_EXTERN) +#if defined(_MSC_VER) +#define VALA_EXTERN __declspec(dllexport) extern +#elif __GNUC__ >= 4 +#define VALA_EXTERN __attribute__((visibility("default"))) extern +#else +#define VALA_EXTERN extern +#endif +#endif + +#define TYPE_TEST (test_get_type ()) +#define TEST(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TYPE_TEST, Test)) +#define TEST_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), TYPE_TEST, TestClass)) +#define IS_TEST(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TYPE_TEST)) +#define IS_TEST_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), TYPE_TEST)) +#define TEST_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), TYPE_TEST, TestClass)) + +typedef struct _Test Test; +typedef struct _TestClass TestClass; +typedef struct _TestPrivate TestPrivate; +enum { + TEST_0_PROPERTY, + TEST_NUM_PROPERTIES +}; +static GParamSpec* test_properties[TEST_NUM_PROPERTIES]; +#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL))) +#define _g_variant_unref0(var) ((var == NULL) ? NULL : (var = (g_variant_unref (var), NULL))) +#define _g_main_loop_unref0(var) ((var == NULL) ? NULL : (var = (g_main_loop_unref (var), NULL))) +#define _vala_assert(expr, msg) if G_LIKELY (expr) ; else g_assertion_message_expr (G_LOG_DOMAIN, __FILE__, __LINE__, G_STRFUNC, msg); +#define _vala_return_if_fail(expr, msg) if G_LIKELY (expr) ; else { g_return_if_fail_warning (G_LOG_DOMAIN, G_STRFUNC, msg); return; } +#define _vala_return_val_if_fail(expr, msg, val) if G_LIKELY (expr) ; else { g_return_if_fail_warning (G_LOG_DOMAIN, G_STRFUNC, msg); return val; } +#define _vala_warn_if_fail(expr, msg) if G_LIKELY (expr) ; else g_warn_message (G_LOG_DOMAIN, __FILE__, __LINE__, G_STRFUNC, msg); + +struct _Test { + GObject parent_instance; + TestPrivate * priv; +}; + +struct _TestClass { + GObjectClass parent_class; +}; + +static gpointer test_parent_class = NULL; +VALA_EXTERN GMainLoop* main_loop; +GMainLoop* main_loop = NULL; + +VALA_EXTERN GType test_get_type (void) G_GNUC_CONST ; +G_DEFINE_AUTOPTR_CLEANUP_FUNC (Test, g_object_unref) +VALA_EXTERN guint test_register_object (void* object, + GDBusConnection* connection, + const gchar* path, + GError** error); +VALA_EXTERN gint test_get_test (Test* self, + GError** error); +VALA_EXTERN Test* test_new (void); +VALA_EXTERN Test* test_construct (GType object_type); +static GType test_get_type_once (void); +static void _dbus_test_get_test (Test* self, + GVariant* _parameters_, + GDBusMethodInvocation* invocation); +static void test_dbus_interface_method_call (GDBusConnection* connection, + const gchar* sender, + const gchar* object_path, + const gchar* interface_name, + const gchar* method_name, + GVariant* parameters, + GDBusMethodInvocation* invocation, + gpointer user_data); +static GVariant* test_dbus_interface_get_property (GDBusConnection* connection, + const gchar* sender, + const gchar* object_path, + const gchar* interface_name, + const gchar* property_name, + GError** error, + gpointer user_data); +static gboolean test_dbus_interface_set_property (GDBusConnection* connection, + const gchar* sender, + const gchar* object_path, + const gchar* interface_name, + const gchar* property_name, + GVariant* value, + GError** error, + gpointer user_data); +static void _test_unregister_object (gpointer user_data); +VALA_EXTERN void client_exit (GPid pid, + gint status); +static void _vala_main (void); +static guint _variant_get1 (GVariant* value); +static void _client_exit_gchild_watch_func (GPid pid, + gint wait_status, + gpointer self); +static void _vala_array_destroy (gpointer array, + gssize array_length, + GDestroyNotify destroy_func); +static void _vala_array_free (gpointer array, + gssize array_length, + GDestroyNotify destroy_func); + +static const GDBusArgInfo _test_dbus_arg_info_get_test_result = {-1, "result", "i", NULL}; +static const GDBusArgInfo * const _test_dbus_arg_info_get_test_in[] = {NULL}; +static const GDBusArgInfo * const _test_dbus_arg_info_get_test_out[] = {&_test_dbus_arg_info_get_test_result, NULL}; +static const GDBusMethodInfo _test_dbus_method_info_get_test = {-1, "GetTest", (GDBusArgInfo **) (&_test_dbus_arg_info_get_test_in), (GDBusArgInfo **) (&_test_dbus_arg_info_get_test_out), NULL}; +static const GDBusMethodInfo * const _test_dbus_method_info[] = {&_test_dbus_method_info_get_test, NULL}; +static const GDBusSignalInfo * const _test_dbus_signal_info[] = {NULL}; +static const GDBusPropertyInfo * const _test_dbus_property_info[] = {NULL}; +static const GDBusInterfaceInfo _test_dbus_interface_info = {-1, "org.example.Test", (GDBusMethodInfo **) (&_test_dbus_method_info), (GDBusSignalInfo **) (&_test_dbus_signal_info), (GDBusPropertyInfo **) (&_test_dbus_property_info), NULL}; +static const GDBusInterfaceVTable _test_dbus_interface_vtable = {test_dbus_interface_method_call, test_dbus_interface_get_property, test_dbus_interface_set_property}; + +gint +test_get_test (Test* self, + GError** error) +{ + gint result = 0; + g_return_val_if_fail (IS_TEST (self), 0); + result = 4711; + return result; +} + +Test* +test_construct (GType object_type) +{ + Test * self = NULL; + self = (Test*) g_object_new (object_type, NULL); + return self; +} + +Test* +test_new (void) +{ + return test_construct (TYPE_TEST); +} + +static void +test_class_init (TestClass * klass, + gpointer klass_data) +{ + test_parent_class = g_type_class_peek_parent (klass); +} + +static void +test_instance_init (Test * self, + gpointer klass) +{ +} + +static GType +test_get_type_once (void) +{ + static const GTypeInfo g_define_type_info = { sizeof (TestClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) test_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (Test), 0, (GInstanceInitFunc) test_instance_init, NULL }; + GType test_type_id; + test_type_id = g_type_register_static (G_TYPE_OBJECT, "Test", &g_define_type_info, 0); + g_type_set_qdata (test_type_id, g_quark_from_static_string ("vala-dbus-register-object"), (void*) test_register_object); + return test_type_id; +} + +GType +test_get_type (void) +{ + static volatile gsize test_type_id__volatile = 0; + if (g_once_init_enter (&test_type_id__volatile)) { + GType test_type_id; + test_type_id = test_get_type_once (); + g_once_init_leave (&test_type_id__volatile, test_type_id); + } + return test_type_id__volatile; +} + +static void +_dbus_test_get_test (Test* self, + GVariant* _parameters_, + GDBusMethodInvocation* invocation) +{ + GError* error = NULL; + GVariantIter _arguments_iter; + GDBusMessage* _reply_message = NULL; + GVariant* _reply; + GVariantBuilder _reply_builder; + gint result; + g_variant_iter_init (&_arguments_iter, _parameters_); + result = test_get_test (self, &error); + if (error) { + g_dbus_method_invocation_return_gerror (invocation, error); + g_error_free (error); + return; + } + _reply_message = g_dbus_message_new_method_reply (g_dbus_method_invocation_get_message (invocation)); + g_variant_builder_init (&_reply_builder, G_VARIANT_TYPE_TUPLE); + g_variant_builder_add_value (&_reply_builder, g_variant_new_int32 (result)); + _reply = g_variant_builder_end (&_reply_builder); + g_dbus_message_set_body (_reply_message, _reply); + g_dbus_connection_send_message (g_dbus_method_invocation_get_connection (invocation), _reply_message, G_DBUS_SEND_MESSAGE_FLAGS_NONE, NULL, NULL); + g_object_unref (invocation); + g_object_unref (_reply_message); +} + +static void +test_dbus_interface_method_call (GDBusConnection* connection, + const gchar* sender, + const gchar* object_path, + const gchar* interface_name, + const gchar* method_name, + GVariant* parameters, + GDBusMethodInvocation* invocation, + gpointer user_data) +{ + gpointer* data; + gpointer object; + data = user_data; + object = data[0]; + if (strcmp (method_name, "GetTest") == 0) { + _dbus_test_get_test (object, parameters, invocation); + } else { + g_object_unref (invocation); + } +} + +static GVariant* +test_dbus_interface_get_property (GDBusConnection* connection, + const gchar* sender, + const gchar* object_path, + const gchar* interface_name, + const gchar* property_name, + GError** error, + gpointer user_data) +{ + gpointer* data; + gpointer object; + data = user_data; + object = data[0]; + return NULL; +} + +static gboolean +test_dbus_interface_set_property (GDBusConnection* connection, + const gchar* sender, + const gchar* object_path, + const gchar* interface_name, + const gchar* property_name, + GVariant* value, + GError** error, + gpointer user_data) +{ + gpointer* data; + gpointer object; + data = user_data; + object = data[0]; + return FALSE; +} + +guint +test_register_object (gpointer object, + GDBusConnection* connection, + const gchar* path, + GError** error) +{ + guint result; + gpointer *data; + data = g_new (gpointer, 3); + data[0] = g_object_ref (object); + data[1] = g_object_ref (connection); + data[2] = g_strdup (path); + result = g_dbus_connection_register_object (connection, path, (GDBusInterfaceInfo *) (&_test_dbus_interface_info), &_test_dbus_interface_vtable, data, _test_unregister_object, error); + if (!result) { + return 0; + } + return result; +} + +static void +_test_unregister_object (gpointer user_data) +{ + gpointer* data; + data = user_data; + g_object_unref (data[0]); + g_object_unref (data[1]); + g_free (data[2]); + g_free (data); +} + +void +client_exit (GPid pid, + gint status) +{ + GMainLoop* _tmp0_; + _vala_assert (status == 0, "status == 0"); + _tmp0_ = main_loop; + g_main_loop_quit (_tmp0_); +} + +static guint +_variant_get1 (GVariant* value) +{ + return g_variant_get_uint32 (value); +} + +static void +_client_exit_gchild_watch_func (GPid pid, + gint wait_status, + gpointer self) +{ + client_exit (pid, wait_status); +} + +static void +_vala_main (void) +{ + GDBusConnection* conn = NULL; + GDBusConnection* _tmp0_; + GDBusConnection* _tmp1_; + Test* _tmp2_; + Test* _tmp3_; + GVariant* request_result = NULL; + GDBusConnection* _tmp4_; + GVariant* _tmp5_; + GVariant* _tmp6_; + GVariant* _tmp7_; + GVariant* _tmp8_; + GVariant* _tmp9_; + GVariant* _tmp10_; + GVariant* _tmp11_; + guint _tmp12_; + GPid client_pid = 0; + gchar* _tmp13_; + gchar** _tmp14_; + gchar** _tmp15_; + gint _tmp15__length1; + GPid _tmp16_ = 0; + GMainLoop* _tmp17_; + GMainLoop* _tmp18_; + GError* _inner_error0_ = NULL; + _tmp0_ = g_bus_get_sync (G_BUS_TYPE_SESSION, NULL, &_inner_error0_); + conn = _tmp0_; + if (G_UNLIKELY (_inner_error0_ != NULL)) { + g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error0_->message, g_quark_to_string (_inner_error0_->domain), _inner_error0_->code); + g_clear_error (&_inner_error0_); + return; + } + _tmp1_ = conn; + _tmp2_ = test_new (); + _tmp3_ = _tmp2_; + test_register_object (_tmp3_, _tmp1_, "/org/example/test", &_inner_error0_); + _g_object_unref0 (_tmp3_); + if (G_UNLIKELY (_inner_error0_ != NULL)) { + _g_object_unref0 (conn); + g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error0_->message, g_quark_to_string (_inner_error0_->domain), _inner_error0_->code); + g_clear_error (&_inner_error0_); + return; + } + _tmp4_ = conn; + _tmp5_ = g_variant_new ("(su)", "org.example.Test", 0x4, NULL); + g_variant_ref_sink (_tmp5_); + _tmp6_ = _tmp5_; + _tmp7_ = g_dbus_connection_call_sync (_tmp4_, "org.freedesktop.DBus", "/org/freedesktop/DBus", "org.freedesktop.DBus", "RequestName", _tmp6_, NULL, 0, -1, NULL, &_inner_error0_); + _tmp8_ = _tmp7_; + _g_variant_unref0 (_tmp6_); + request_result = _tmp8_; + if (G_UNLIKELY (_inner_error0_ != NULL)) { + _g_object_unref0 (conn); + g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error0_->message, g_quark_to_string (_inner_error0_->domain), _inner_error0_->code); + g_clear_error (&_inner_error0_); + return; + } + _tmp9_ = request_result; + _tmp10_ = g_variant_get_child_value (_tmp9_, (gsize) 0); + _tmp11_ = _tmp10_; + _tmp12_ = _variant_get1 (_tmp11_); + _vala_assert (_tmp12_ == ((guint) 1), "(uint) request_result.get_child_value (0) == 1"); + _g_variant_unref0 (_tmp11_); + _tmp13_ = g_strdup ("dbus_async_connection_client"); + _tmp14_ = g_new0 (gchar*, 1 + 1); + _tmp14_[0] = _tmp13_; + _tmp15_ = _tmp14_; + _tmp15__length1 = 1; + g_spawn_async (NULL, _tmp15_, NULL, G_SPAWN_DO_NOT_REAP_CHILD, NULL, NULL, &_tmp16_, &_inner_error0_); + client_pid = _tmp16_; + _tmp15_ = (_vala_array_free (_tmp15_, _tmp15__length1, (GDestroyNotify) g_free), NULL); + if (G_UNLIKELY (_inner_error0_ != NULL)) { + _g_variant_unref0 (request_result); + _g_object_unref0 (conn); + g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error0_->message, g_quark_to_string (_inner_error0_->domain), _inner_error0_->code); + g_clear_error (&_inner_error0_); + return; + } + g_child_watch_add_full (G_PRIORITY_DEFAULT_IDLE, client_pid, _client_exit_gchild_watch_func, NULL, NULL); + _tmp17_ = g_main_loop_new (NULL, FALSE); + _g_main_loop_unref0 (main_loop); + main_loop = _tmp17_; + _tmp18_ = main_loop; + g_main_loop_run (_tmp18_); + _g_variant_unref0 (request_result); + _g_object_unref0 (conn); +} + +int +main (int argc, + char ** argv) +{ + _vala_main (); + return 0; +} + +static void +_vala_array_destroy (gpointer array, + gssize array_length, + GDestroyNotify destroy_func) +{ + if ((array != NULL) && (destroy_func != NULL)) { + gssize i; + for (i = 0; i < array_length; i = i + 1) { + if (((gpointer*) array)[i] != NULL) { + destroy_func (((gpointer*) array)[i]); + } + } + } +} + +static void +_vala_array_free (gpointer array, + gssize array_length, + GDestroyNotify destroy_func) +{ + _vala_array_destroy (array, array_length, destroy_func); + g_free (array); +} + diff --git a/tests/dbus/async-errors_client.c-expected b/tests/dbus/async-errors_client.c-expected new file mode 100644 index 000000000..4f9a12a28 --- /dev/null +++ b/tests/dbus/async-errors_client.c-expected @@ -0,0 +1,1143 @@ +/* dbus_async_errors_client.c generated by valac, the Vala compiler + * generated from dbus_async_errors_client.vala, do not modify */ + +#include <glib-object.h> +#include <gio/gio.h> +#include <glib.h> +#include <stdlib.h> +#include <string.h> + +#if !defined(VALA_EXTERN) +#if defined(_MSC_VER) +#define VALA_EXTERN __declspec(dllexport) extern +#elif __GNUC__ >= 4 +#define VALA_EXTERN __attribute__((visibility("default"))) extern +#else +#define VALA_EXTERN extern +#endif +#endif + +#define TYPE_TEST (test_get_type ()) +#define TEST(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TYPE_TEST, Test)) +#define IS_TEST(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TYPE_TEST)) +#define TEST_GET_INTERFACE(obj) (G_TYPE_INSTANCE_GET_INTERFACE ((obj), TYPE_TEST, TestIface)) + +typedef struct _Test Test; +typedef struct _TestIface TestIface; + +#define TYPE_TEST_PROXY (test_proxy_get_type ()) +typedef GDBusProxy TestProxy; +typedef GDBusProxyClass TestProxyClass; +typedef struct _TestTestVoidReadyData TestTestVoidReadyData; +typedef struct _TestTestIntReadyData TestTestIntReadyData; +typedef struct _TestTestStringReadyData TestTestStringReadyData; +#define _g_free0(var) (var = (g_free (var), NULL)) +typedef struct _TestTestCancellableReadyData TestTestCancellableReadyData; +#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL))) +typedef struct _RunData RunData; +#define _g_main_loop_unref0(var) ((var == NULL) ? NULL : (var = (g_main_loop_unref (var), NULL))) + +struct _TestIface { + GTypeInterface parent_iface; + void (*test_void) (Test* self, GAsyncReadyCallback _callback_, gpointer _user_data_); + void (*test_void_finish) (Test* self, GAsyncResult* _res_, GError** error); + void (*test_int) (Test* self, gint i, GAsyncReadyCallback _callback_, gpointer _user_data_); + gint (*test_int_finish) (Test* self, GAsyncResult* _res_, gint* j, GError** error); + void (*test_string) (Test* self, const gchar* s, GAsyncReadyCallback _callback_, gpointer _user_data_); + gchar* (*test_string_finish) (Test* self, GAsyncResult* _res_, gchar* * t, GError** error); + void (*test_cancellable) (Test* self, GCancellable* cancellable, GAsyncReadyCallback _callback_, gpointer _user_data_); + void (*test_cancellable_finish) (Test* self, GAsyncResult* _res_, GError** error); +}; + +struct _TestTestVoidReadyData { + GDBusMethodInvocation* _invocation_; +}; + +struct _TestTestIntReadyData { + GDBusMethodInvocation* _invocation_; + gint i; +}; + +struct _TestTestStringReadyData { + GDBusMethodInvocation* _invocation_; + gchar* s; +}; + +struct _TestTestCancellableReadyData { + GDBusMethodInvocation* _invocation_; +}; + +struct _RunData { + int _state_; + GObject* _source_object_; + GAsyncResult* _res_; + GTask* _async_result; + Test* test; + Test* _tmp0_; + gint j; + gint k; + gint _tmp1_; + gint _tmp2_; + gint _tmp3_; + gchar* t; + gchar* u; + gchar* _tmp4_; + gchar* _tmp5_; + gchar* _tmp6_; + gchar* _tmp7_; + GCancellable* cancellable; + GCancellable* _tmp8_; + GCancellable* _tmp9_; + GCancellable* _tmp10_; + GMainLoop* _tmp11_; + GError* _inner_error0_; +}; + +VALA_EXTERN GMainLoop* main_loop; +GMainLoop* main_loop = NULL; + +VALA_EXTERN GType test_proxy_get_type (void) G_GNUC_CONST ; +VALA_EXTERN guint test_register_object (void* object, + GDBusConnection* connection, + const gchar* path, + GError** error); +VALA_EXTERN GType test_get_type (void) G_GNUC_CONST ; +VALA_EXTERN void test_test_void (Test* self, + GAsyncReadyCallback _callback_, + gpointer _user_data_); +VALA_EXTERN void test_test_void_finish (Test* self, + GAsyncResult* _res_, + GError** error); +VALA_EXTERN void test_test_int (Test* self, + gint i, + GAsyncReadyCallback _callback_, + gpointer _user_data_); +VALA_EXTERN gint test_test_int_finish (Test* self, + GAsyncResult* _res_, + gint* j, + GError** error); +VALA_EXTERN void test_test_string (Test* self, + const gchar* s, + GAsyncReadyCallback _callback_, + gpointer _user_data_); +VALA_EXTERN gchar* test_test_string_finish (Test* self, + GAsyncResult* _res_, + gchar* * t, + GError** error); +VALA_EXTERN void test_test_cancellable (Test* self, + GCancellable* cancellable, + GAsyncReadyCallback _callback_, + gpointer _user_data_); +VALA_EXTERN void test_test_cancellable_finish (Test* self, + GAsyncResult* _res_, + GError** error); +static GType test_get_type_once (void); +static void test_proxy_g_signal (GDBusProxy* proxy, + const gchar* sender_name, + const gchar* signal_name, + GVariant* parameters); +static void _vala_g_async_ready_callback (GObject *source_object, + GAsyncResult *res, + void *user_data); +static void test_proxy_test_void_async (Test* self, + GAsyncReadyCallback _callback_, + gpointer _user_data_); +static void test_proxy_test_void_finish (Test* self, + GAsyncResult* _res_, + GError** error); +static void test_proxy_test_int_async (Test* self, + gint i, + GAsyncReadyCallback _callback_, + gpointer _user_data_); +static gint test_proxy_test_int_finish (Test* self, + GAsyncResult* _res_, + gint* j, + GError** error); +static void test_proxy_test_string_async (Test* self, + const gchar* s, + GAsyncReadyCallback _callback_, + gpointer _user_data_); +static gchar* test_proxy_test_string_finish (Test* self, + GAsyncResult* _res_, + gchar* * t, + GError** error); +static void test_proxy_test_cancellable_async (Test* self, + GCancellable* cancellable, + GAsyncReadyCallback _callback_, + gpointer _user_data_); +static void test_proxy_test_cancellable_finish (Test* self, + GAsyncResult* _res_, + GError** error); +static void test_proxy_test_interface_init (TestIface* iface); +static void _dbus_test_test_void (Test* self, + GVariant* _parameters_, + GDBusMethodInvocation* invocation); +static void _dbus_test_test_void_ready (GObject * source_object, + GAsyncResult * _res_, + gpointer _user_data_); +static void _dbus_test_test_int (Test* self, + GVariant* _parameters_, + GDBusMethodInvocation* invocation); +static void _dbus_test_test_int_ready (GObject * source_object, + GAsyncResult * _res_, + gpointer _user_data_); +static void _dbus_test_test_string (Test* self, + GVariant* _parameters_, + GDBusMethodInvocation* invocation); +static void _dbus_test_test_string_ready (GObject * source_object, + GAsyncResult * _res_, + gpointer _user_data_); +static void _dbus_test_test_cancellable (Test* self, + GVariant* _parameters_, + GDBusMethodInvocation* invocation); +static void _dbus_test_test_cancellable_ready (GObject * source_object, + GAsyncResult * _res_, + gpointer _user_data_); +static void test_dbus_interface_method_call (GDBusConnection* connection, + const gchar* sender, + const gchar* object_path, + const gchar* interface_name, + const gchar* method_name, + GVariant* parameters, + GDBusMethodInvocation* invocation, + gpointer user_data); +static GVariant* test_dbus_interface_get_property (GDBusConnection* connection, + const gchar* sender, + const gchar* object_path, + const gchar* interface_name, + const gchar* property_name, + GError** error, + gpointer user_data); +static gboolean test_dbus_interface_set_property (GDBusConnection* connection, + const gchar* sender, + const gchar* object_path, + const gchar* interface_name, + const gchar* property_name, + GVariant* value, + GError** error, + gpointer user_data); +static void _test_unregister_object (gpointer user_data); +static void run_data_free (gpointer _data); +VALA_EXTERN void run (GAsyncReadyCallback _callback_, + gpointer _user_data_); +VALA_EXTERN void run_finish (GAsyncResult* _res_); +static gboolean run_co (RunData* _data_); +static void run_ready (GObject* source_object, + GAsyncResult* _res_, + gpointer _user_data_); +static void _vala_main (void); + +static const GDBusArgInfo * const _test_dbus_arg_info_test_void_in[] = {NULL}; +static const GDBusArgInfo * const _test_dbus_arg_info_test_void_out[] = {NULL}; +static const GDBusMethodInfo _test_dbus_method_info_test_void = {-1, "TestVoid", (GDBusArgInfo **) (&_test_dbus_arg_info_test_void_in), (GDBusArgInfo **) (&_test_dbus_arg_info_test_void_out), NULL}; +static const GDBusArgInfo _test_dbus_arg_info_test_int_i = {-1, "i", "i", NULL}; +static const GDBusArgInfo _test_dbus_arg_info_test_int_j = {-1, "j", "i", NULL}; +static const GDBusArgInfo _test_dbus_arg_info_test_int_result = {-1, "result", "i", NULL}; +static const GDBusArgInfo * const _test_dbus_arg_info_test_int_in[] = {&_test_dbus_arg_info_test_int_i, NULL}; +static const GDBusArgInfo * const _test_dbus_arg_info_test_int_out[] = {&_test_dbus_arg_info_test_int_j, &_test_dbus_arg_info_test_int_result, NULL}; +static const GDBusMethodInfo _test_dbus_method_info_test_int = {-1, "TestInt", (GDBusArgInfo **) (&_test_dbus_arg_info_test_int_in), (GDBusArgInfo **) (&_test_dbus_arg_info_test_int_out), NULL}; +static const GDBusArgInfo _test_dbus_arg_info_test_string_s = {-1, "s", "s", NULL}; +static const GDBusArgInfo _test_dbus_arg_info_test_string_t = {-1, "t", "s", NULL}; +static const GDBusArgInfo _test_dbus_arg_info_test_string_result = {-1, "result", "s", NULL}; +static const GDBusArgInfo * const _test_dbus_arg_info_test_string_in[] = {&_test_dbus_arg_info_test_string_s, NULL}; +static const GDBusArgInfo * const _test_dbus_arg_info_test_string_out[] = {&_test_dbus_arg_info_test_string_t, &_test_dbus_arg_info_test_string_result, NULL}; +static const GDBusMethodInfo _test_dbus_method_info_test_string = {-1, "TestString", (GDBusArgInfo **) (&_test_dbus_arg_info_test_string_in), (GDBusArgInfo **) (&_test_dbus_arg_info_test_string_out), NULL}; +static const GDBusArgInfo * const _test_dbus_arg_info_test_cancellable_in[] = {NULL}; +static const GDBusArgInfo * const _test_dbus_arg_info_test_cancellable_out[] = {NULL}; +static const GDBusMethodInfo _test_dbus_method_info_test_cancellable = {-1, "TestCancellable", (GDBusArgInfo **) (&_test_dbus_arg_info_test_cancellable_in), (GDBusArgInfo **) (&_test_dbus_arg_info_test_cancellable_out), NULL}; +static const GDBusMethodInfo * const _test_dbus_method_info[] = {&_test_dbus_method_info_test_void, &_test_dbus_method_info_test_int, &_test_dbus_method_info_test_string, &_test_dbus_method_info_test_cancellable, NULL}; +static const GDBusSignalInfo * const _test_dbus_signal_info[] = {NULL}; +static const GDBusPropertyInfo * const _test_dbus_property_info[] = {NULL}; +static const GDBusInterfaceInfo _test_dbus_interface_info = {-1, "org.example.Test", (GDBusMethodInfo **) (&_test_dbus_method_info), (GDBusSignalInfo **) (&_test_dbus_signal_info), (GDBusPropertyInfo **) (&_test_dbus_property_info), NULL}; +static const GDBusInterfaceVTable _test_dbus_interface_vtable = {test_dbus_interface_method_call, test_dbus_interface_get_property, test_dbus_interface_set_property}; + +void +test_test_void (Test* self, + GAsyncReadyCallback _callback_, + gpointer _user_data_) +{ + TestIface* _iface_; + _iface_ = TEST_GET_INTERFACE (self); + if (_iface_->test_void) { + _iface_->test_void (self, _callback_, _user_data_); + } +} + +void +test_test_void_finish (Test* self, + GAsyncResult* _res_, + GError** error) +{ + TestIface* _iface_; + _iface_ = TEST_GET_INTERFACE (self); + if (_iface_->test_void_finish) { + _iface_->test_void_finish (self, _res_, error); + } +} + +void +test_test_int (Test* self, + gint i, + GAsyncReadyCallback _callback_, + gpointer _user_data_) +{ + TestIface* _iface_; + _iface_ = TEST_GET_INTERFACE (self); + if (_iface_->test_int) { + _iface_->test_int (self, i, _callback_, _user_data_); + } +} + +gint +test_test_int_finish (Test* self, + GAsyncResult* _res_, + gint* j, + GError** error) +{ + TestIface* _iface_; + _iface_ = TEST_GET_INTERFACE (self); + if (_iface_->test_int_finish) { + return _iface_->test_int_finish (self, _res_, j, error); + } + return -1; +} + +void +test_test_string (Test* self, + const gchar* s, + GAsyncReadyCallback _callback_, + gpointer _user_data_) +{ + TestIface* _iface_; + _iface_ = TEST_GET_INTERFACE (self); + if (_iface_->test_string) { + _iface_->test_string (self, s, _callback_, _user_data_); + } +} + +gchar* +test_test_string_finish (Test* self, + GAsyncResult* _res_, + gchar* * t, + GError** error) +{ + TestIface* _iface_; + _iface_ = TEST_GET_INTERFACE (self); + if (_iface_->test_string_finish) { + return _iface_->test_string_finish (self, _res_, t, error); + } + return NULL; +} + +void +test_test_cancellable (Test* self, + GCancellable* cancellable, + GAsyncReadyCallback _callback_, + gpointer _user_data_) +{ + TestIface* _iface_; + _iface_ = TEST_GET_INTERFACE (self); + if (_iface_->test_cancellable) { + _iface_->test_cancellable (self, cancellable, _callback_, _user_data_); + } +} + +void +test_test_cancellable_finish (Test* self, + GAsyncResult* _res_, + GError** error) +{ + TestIface* _iface_; + _iface_ = TEST_GET_INTERFACE (self); + if (_iface_->test_cancellable_finish) { + _iface_->test_cancellable_finish (self, _res_, error); + } +} + +static void +test_default_init (TestIface * iface, + gpointer iface_data) +{ +} + +static GType +test_get_type_once (void) +{ + static const GTypeInfo g_define_type_info = { sizeof (TestIface), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) test_default_init, (GClassFinalizeFunc) NULL, NULL, 0, 0, (GInstanceInitFunc) NULL, NULL }; + GType test_type_id; + test_type_id = g_type_register_static (G_TYPE_INTERFACE, "Test", &g_define_type_info, 0); + g_type_interface_add_prerequisite (test_type_id, G_TYPE_OBJECT); + g_type_set_qdata (test_type_id, g_quark_from_static_string ("vala-dbus-proxy-type"), (void*) test_proxy_get_type); + g_type_set_qdata (test_type_id, g_quark_from_static_string ("vala-dbus-interface-name"), "org.example.Test"); + g_type_set_qdata (test_type_id, g_quark_from_static_string ("vala-dbus-interface-info"), (void*) (&_test_dbus_interface_info)); + g_type_set_qdata (test_type_id, g_quark_from_static_string ("vala-dbus-register-object"), (void*) test_register_object); + return test_type_id; +} + +GType +test_get_type (void) +{ + static volatile gsize test_type_id__volatile = 0; + if (g_once_init_enter (&test_type_id__volatile)) { + GType test_type_id; + test_type_id = test_get_type_once (); + g_once_init_leave (&test_type_id__volatile, test_type_id); + } + return test_type_id__volatile; +} + +G_DEFINE_TYPE_EXTENDED (TestProxy, test_proxy, G_TYPE_DBUS_PROXY, 0, G_IMPLEMENT_INTERFACE (TYPE_TEST, test_proxy_test_interface_init) ) +static void +test_proxy_class_init (TestProxyClass* klass) +{ + G_DBUS_PROXY_CLASS (klass)->g_signal = test_proxy_g_signal; +} + +static void +test_proxy_g_signal (GDBusProxy* proxy, + const gchar* sender_name, + const gchar* signal_name, + GVariant* parameters) +{ +} + +static void +test_proxy_init (TestProxy* self) +{ + g_dbus_proxy_set_interface_info (G_DBUS_PROXY (self), (GDBusInterfaceInfo *) (&_test_dbus_interface_info)); +} + +static void +_vala_g_async_ready_callback (GObject *source_object, + GAsyncResult *res, + void *user_data) +{ + g_task_return_pointer (user_data, g_object_ref (res), g_object_unref); + g_object_unref (user_data); +} + +static void +test_proxy_test_void_async (Test* self, + GAsyncReadyCallback _callback_, + gpointer _user_data_) +{ + GDBusMessage *_message; + GVariant *_arguments; + GVariantBuilder _arguments_builder; + _message = g_dbus_message_new_method_call (g_dbus_proxy_get_name ((GDBusProxy *) self), g_dbus_proxy_get_object_path ((GDBusProxy *) self), "org.example.Test", "TestVoid"); + g_variant_builder_init (&_arguments_builder, G_VARIANT_TYPE_TUPLE); + _arguments = g_variant_builder_end (&_arguments_builder); + g_dbus_message_set_body (_message, _arguments); + if (_callback_ != NULL) { + g_dbus_connection_send_message_with_reply (g_dbus_proxy_get_connection ((GDBusProxy *) self), _message, G_DBUS_SEND_MESSAGE_FLAGS_NONE, g_dbus_proxy_get_default_timeout ((GDBusProxy *) self), NULL, NULL, _vala_g_async_ready_callback, g_task_new ((GObject *) self, NULL, _callback_, _user_data_)); + } else { + g_dbus_message_set_flags (_message, G_DBUS_MESSAGE_FLAGS_NO_REPLY_EXPECTED); + g_dbus_connection_send_message (g_dbus_proxy_get_connection ((GDBusProxy *) self), _message, G_DBUS_SEND_MESSAGE_FLAGS_NONE, NULL, NULL); + } + g_object_unref (_message); +} + +static void +test_proxy_test_void_finish (Test* self, + GAsyncResult* _res_, + GError** error) +{ + GAsyncResult *_inner_res; + GDBusMessage *_reply_message; + _inner_res = g_task_propagate_pointer ((GTask *) _res_, NULL); + _reply_message = g_dbus_connection_send_message_with_reply_finish (g_dbus_proxy_get_connection ((GDBusProxy *) self), _inner_res, error); + g_object_unref (_inner_res); + if (!_reply_message) { + return; + } + if (g_dbus_message_to_gerror (_reply_message, error)) { + g_object_unref (_reply_message); + return; + } + g_object_unref (_reply_message); +} + +static void +test_proxy_test_int_async (Test* self, + gint i, + GAsyncReadyCallback _callback_, + gpointer _user_data_) +{ + GDBusMessage *_message; + GVariant *_arguments; + GVariantBuilder _arguments_builder; + _message = g_dbus_message_new_method_call (g_dbus_proxy_get_name ((GDBusProxy *) self), g_dbus_proxy_get_object_path ((GDBusProxy *) self), "org.example.Test", "TestInt"); + g_variant_builder_init (&_arguments_builder, G_VARIANT_TYPE_TUPLE); + g_variant_builder_add_value (&_arguments_builder, g_variant_new_int32 (i)); + _arguments = g_variant_builder_end (&_arguments_builder); + g_dbus_message_set_body (_message, _arguments); + if (_callback_ != NULL) { + g_dbus_connection_send_message_with_reply (g_dbus_proxy_get_connection ((GDBusProxy *) self), _message, G_DBUS_SEND_MESSAGE_FLAGS_NONE, g_dbus_proxy_get_default_timeout ((GDBusProxy *) self), NULL, NULL, _vala_g_async_ready_callback, g_task_new ((GObject *) self, NULL, _callback_, _user_data_)); + } else { + g_dbus_message_set_flags (_message, G_DBUS_MESSAGE_FLAGS_NO_REPLY_EXPECTED); + g_dbus_connection_send_message (g_dbus_proxy_get_connection ((GDBusProxy *) self), _message, G_DBUS_SEND_MESSAGE_FLAGS_NONE, NULL, NULL); + } + g_object_unref (_message); +} + +static gint +test_proxy_test_int_finish (Test* self, + GAsyncResult* _res_, + gint* j, + GError** error) +{ + GAsyncResult *_inner_res; + GDBusMessage *_reply_message; + GVariant *_reply; + GVariantIter _reply_iter; + gint _vala_j = 0; + GVariant* _tmp2_; + gint _result = 0; + GVariant* _tmp3_; + _inner_res = g_task_propagate_pointer ((GTask *) _res_, NULL); + _reply_message = g_dbus_connection_send_message_with_reply_finish (g_dbus_proxy_get_connection ((GDBusProxy *) self), _inner_res, error); + g_object_unref (_inner_res); + if (!_reply_message) { + gint _tmp0_ = 0; + return _tmp0_; + } + if (g_dbus_message_to_gerror (_reply_message, error)) { + gint _tmp1_ = 0; + g_object_unref (_reply_message); + return _tmp1_; + } + _reply = g_dbus_message_get_body (_reply_message); + g_variant_iter_init (&_reply_iter, _reply); + _tmp2_ = g_variant_iter_next_value (&_reply_iter); + _vala_j = g_variant_get_int32 (_tmp2_); + g_variant_unref (_tmp2_); + *j = _vala_j; + _tmp3_ = g_variant_iter_next_value (&_reply_iter); + _result = g_variant_get_int32 (_tmp3_); + g_variant_unref (_tmp3_); + g_object_unref (_reply_message); + return _result; +} + +static void +test_proxy_test_string_async (Test* self, + const gchar* s, + GAsyncReadyCallback _callback_, + gpointer _user_data_) +{ + GDBusMessage *_message; + GVariant *_arguments; + GVariantBuilder _arguments_builder; + _message = g_dbus_message_new_method_call (g_dbus_proxy_get_name ((GDBusProxy *) self), g_dbus_proxy_get_object_path ((GDBusProxy *) self), "org.example.Test", "TestString"); + g_variant_builder_init (&_arguments_builder, G_VARIANT_TYPE_TUPLE); + g_variant_builder_add_value (&_arguments_builder, g_variant_new_string (s)); + _arguments = g_variant_builder_end (&_arguments_builder); + g_dbus_message_set_body (_message, _arguments); + if (_callback_ != NULL) { + g_dbus_connection_send_message_with_reply (g_dbus_proxy_get_connection ((GDBusProxy *) self), _message, G_DBUS_SEND_MESSAGE_FLAGS_NONE, g_dbus_proxy_get_default_timeout ((GDBusProxy *) self), NULL, NULL, _vala_g_async_ready_callback, g_task_new ((GObject *) self, NULL, _callback_, _user_data_)); + } else { + g_dbus_message_set_flags (_message, G_DBUS_MESSAGE_FLAGS_NO_REPLY_EXPECTED); + g_dbus_connection_send_message (g_dbus_proxy_get_connection ((GDBusProxy *) self), _message, G_DBUS_SEND_MESSAGE_FLAGS_NONE, NULL, NULL); + } + g_object_unref (_message); +} + +static gchar* +test_proxy_test_string_finish (Test* self, + GAsyncResult* _res_, + gchar* * t, + GError** error) +{ + GAsyncResult *_inner_res; + GDBusMessage *_reply_message; + GVariant *_reply; + GVariantIter _reply_iter; + gchar* _vala_t = NULL; + GVariant* _tmp4_; + gchar* _result = NULL; + GVariant* _tmp5_; + _inner_res = g_task_propagate_pointer ((GTask *) _res_, NULL); + _reply_message = g_dbus_connection_send_message_with_reply_finish (g_dbus_proxy_get_connection ((GDBusProxy *) self), _inner_res, error); + g_object_unref (_inner_res); + if (!_reply_message) { + return NULL; + } + if (g_dbus_message_to_gerror (_reply_message, error)) { + g_object_unref (_reply_message); + return NULL; + } + _reply = g_dbus_message_get_body (_reply_message); + g_variant_iter_init (&_reply_iter, _reply); + _tmp4_ = g_variant_iter_next_value (&_reply_iter); + _vala_t = g_variant_dup_string (_tmp4_, NULL); + g_variant_unref (_tmp4_); + *t = _vala_t; + _tmp5_ = g_variant_iter_next_value (&_reply_iter); + _result = g_variant_dup_string (_tmp5_, NULL); + g_variant_unref (_tmp5_); + g_object_unref (_reply_message); + return _result; +} + +static void +test_proxy_test_cancellable_async (Test* self, + GCancellable* cancellable, + GAsyncReadyCallback _callback_, + gpointer _user_data_) +{ + GDBusMessage *_message; + GVariant *_arguments; + GVariantBuilder _arguments_builder; + _message = g_dbus_message_new_method_call (g_dbus_proxy_get_name ((GDBusProxy *) self), g_dbus_proxy_get_object_path ((GDBusProxy *) self), "org.example.Test", "TestCancellable"); + g_variant_builder_init (&_arguments_builder, G_VARIANT_TYPE_TUPLE); + _arguments = g_variant_builder_end (&_arguments_builder); + g_dbus_message_set_body (_message, _arguments); + if (_callback_ != NULL) { + g_dbus_connection_send_message_with_reply (g_dbus_proxy_get_connection ((GDBusProxy *) self), _message, G_DBUS_SEND_MESSAGE_FLAGS_NONE, g_dbus_proxy_get_default_timeout ((GDBusProxy *) self), NULL, cancellable, _vala_g_async_ready_callback, g_task_new ((GObject *) self, NULL, _callback_, _user_data_)); + } else { + g_dbus_message_set_flags (_message, G_DBUS_MESSAGE_FLAGS_NO_REPLY_EXPECTED); + g_dbus_connection_send_message (g_dbus_proxy_get_connection ((GDBusProxy *) self), _message, G_DBUS_SEND_MESSAGE_FLAGS_NONE, NULL, NULL); + } + g_object_unref (_message); +} + +static void +test_proxy_test_cancellable_finish (Test* self, + GAsyncResult* _res_, + GError** error) +{ + GAsyncResult *_inner_res; + GDBusMessage *_reply_message; + _inner_res = g_task_propagate_pointer ((GTask *) _res_, NULL); + _reply_message = g_dbus_connection_send_message_with_reply_finish (g_dbus_proxy_get_connection ((GDBusProxy *) self), _inner_res, error); + g_object_unref (_inner_res); + if (!_reply_message) { + return; + } + if (g_dbus_message_to_gerror (_reply_message, error)) { + g_object_unref (_reply_message); + return; + } + g_object_unref (_reply_message); +} + +static void +test_proxy_test_interface_init (TestIface* iface) +{ + iface->test_void = test_proxy_test_void_async; + iface->test_void_finish = test_proxy_test_void_finish; + iface->test_int = test_proxy_test_int_async; + iface->test_int_finish = test_proxy_test_int_finish; + iface->test_string = test_proxy_test_string_async; + iface->test_string_finish = test_proxy_test_string_finish; + iface->test_cancellable = test_proxy_test_cancellable_async; + iface->test_cancellable_finish = test_proxy_test_cancellable_finish; +} + +static void +_dbus_test_test_void (Test* self, + GVariant* _parameters_, + GDBusMethodInvocation* invocation) +{ + GVariantIter _arguments_iter; + TestTestVoidReadyData* _ready_data; + g_variant_iter_init (&_arguments_iter, _parameters_); + _ready_data = g_slice_new0 (TestTestVoidReadyData); + _ready_data->_invocation_ = invocation; + test_test_void (self, (GAsyncReadyCallback) _dbus_test_test_void_ready, _ready_data); +} + +static void +_dbus_test_test_void_ready (GObject * source_object, + GAsyncResult * _res_, + gpointer _user_data_) +{ + TestTestVoidReadyData* _ready_data; + GDBusMethodInvocation* invocation; + GError* error = NULL; + GDBusMessage* _reply_message = NULL; + GVariant* _reply; + GVariantBuilder _reply_builder; + _ready_data = _user_data_; + invocation = _ready_data->_invocation_; + test_test_void_finish ((Test*) source_object, _res_, &error); + if (error) { + g_dbus_method_invocation_return_gerror (invocation, error); + g_error_free (error); + goto _error; + } + _reply_message = g_dbus_message_new_method_reply (g_dbus_method_invocation_get_message (invocation)); + g_variant_builder_init (&_reply_builder, G_VARIANT_TYPE_TUPLE); + _reply = g_variant_builder_end (&_reply_builder); + g_dbus_message_set_body (_reply_message, _reply); + g_dbus_connection_send_message (g_dbus_method_invocation_get_connection (invocation), _reply_message, G_DBUS_SEND_MESSAGE_FLAGS_NONE, NULL, NULL); + g_object_unref (invocation); + g_object_unref (_reply_message); + _error: + g_slice_free (TestTestVoidReadyData, _ready_data); +} + +static void +_dbus_test_test_int (Test* self, + GVariant* _parameters_, + GDBusMethodInvocation* invocation) +{ + GVariantIter _arguments_iter; + TestTestIntReadyData* _ready_data; + GVariant* _tmp6_; + g_variant_iter_init (&_arguments_iter, _parameters_); + _ready_data = g_slice_new0 (TestTestIntReadyData); + _ready_data->_invocation_ = invocation; + _tmp6_ = g_variant_iter_next_value (&_arguments_iter); + _ready_data->i = g_variant_get_int32 (_tmp6_); + g_variant_unref (_tmp6_); + test_test_int (self, _ready_data->i, (GAsyncReadyCallback) _dbus_test_test_int_ready, _ready_data); +} + +static void +_dbus_test_test_int_ready (GObject * source_object, + GAsyncResult * _res_, + gpointer _user_data_) +{ + TestTestIntReadyData* _ready_data; + GDBusMethodInvocation* invocation; + GError* error = NULL; + GDBusMessage* _reply_message = NULL; + GVariant* _reply; + GVariantBuilder _reply_builder; + gint j = 0; + gint result; + _ready_data = _user_data_; + invocation = _ready_data->_invocation_; + result = test_test_int_finish ((Test*) source_object, _res_, &j, &error); + if (error) { + g_dbus_method_invocation_return_gerror (invocation, error); + g_error_free (error); + goto _error; + } + _reply_message = g_dbus_message_new_method_reply (g_dbus_method_invocation_get_message (invocation)); + g_variant_builder_init (&_reply_builder, G_VARIANT_TYPE_TUPLE); + g_variant_builder_add_value (&_reply_builder, g_variant_new_int32 (j)); + g_variant_builder_add_value (&_reply_builder, g_variant_new_int32 (result)); + _reply = g_variant_builder_end (&_reply_builder); + g_dbus_message_set_body (_reply_message, _reply); + g_dbus_connection_send_message (g_dbus_method_invocation_get_connection (invocation), _reply_message, G_DBUS_SEND_MESSAGE_FLAGS_NONE, NULL, NULL); + g_object_unref (invocation); + g_object_unref (_reply_message); + _error: + g_slice_free (TestTestIntReadyData, _ready_data); +} + +static void +_dbus_test_test_string (Test* self, + GVariant* _parameters_, + GDBusMethodInvocation* invocation) +{ + GVariantIter _arguments_iter; + TestTestStringReadyData* _ready_data; + GVariant* _tmp7_; + g_variant_iter_init (&_arguments_iter, _parameters_); + _ready_data = g_slice_new0 (TestTestStringReadyData); + _ready_data->_invocation_ = invocation; + _tmp7_ = g_variant_iter_next_value (&_arguments_iter); + _ready_data->s = g_variant_dup_string (_tmp7_, NULL); + g_variant_unref (_tmp7_); + test_test_string (self, _ready_data->s, (GAsyncReadyCallback) _dbus_test_test_string_ready, _ready_data); + _error: + ; +} + +static void +_dbus_test_test_string_ready (GObject * source_object, + GAsyncResult * _res_, + gpointer _user_data_) +{ + TestTestStringReadyData* _ready_data; + GDBusMethodInvocation* invocation; + GError* error = NULL; + GDBusMessage* _reply_message = NULL; + GVariant* _reply; + GVariantBuilder _reply_builder; + gchar* t = NULL; + gchar* result; + _ready_data = _user_data_; + invocation = _ready_data->_invocation_; + result = test_test_string_finish ((Test*) source_object, _res_, &t, &error); + if (error) { + g_dbus_method_invocation_return_gerror (invocation, error); + g_error_free (error); + goto _error; + } + _reply_message = g_dbus_message_new_method_reply (g_dbus_method_invocation_get_message (invocation)); + g_variant_builder_init (&_reply_builder, G_VARIANT_TYPE_TUPLE); + g_variant_builder_add_value (&_reply_builder, g_variant_new_string (t)); + g_variant_builder_add_value (&_reply_builder, g_variant_new_string (result)); + _g_free0 (result); + _reply = g_variant_builder_end (&_reply_builder); + g_dbus_message_set_body (_reply_message, _reply); + g_dbus_connection_send_message (g_dbus_method_invocation_get_connection (invocation), _reply_message, G_DBUS_SEND_MESSAGE_FLAGS_NONE, NULL, NULL); + g_object_unref (invocation); + g_object_unref (_reply_message); + _error: + _g_free0 (_ready_data->s); + _g_free0 (t); + g_slice_free (TestTestStringReadyData, _ready_data); +} + +static void +_dbus_test_test_cancellable (Test* self, + GVariant* _parameters_, + GDBusMethodInvocation* invocation) +{ + GVariantIter _arguments_iter; + TestTestCancellableReadyData* _ready_data; + g_variant_iter_init (&_arguments_iter, _parameters_); + _ready_data = g_slice_new0 (TestTestCancellableReadyData); + _ready_data->_invocation_ = invocation; + test_test_cancellable (self, NULL, (GAsyncReadyCallback) _dbus_test_test_cancellable_ready, _ready_data); +} + +static void +_dbus_test_test_cancellable_ready (GObject * source_object, + GAsyncResult * _res_, + gpointer _user_data_) +{ + TestTestCancellableReadyData* _ready_data; + GDBusMethodInvocation* invocation; + GError* error = NULL; + GDBusMessage* _reply_message = NULL; + GVariant* _reply; + GVariantBuilder _reply_builder; + _ready_data = _user_data_; + invocation = _ready_data->_invocation_; + test_test_cancellable_finish ((Test*) source_object, _res_, &error); + if (error) { + g_dbus_method_invocation_return_gerror (invocation, error); + g_error_free (error); + goto _error; + } + _reply_message = g_dbus_message_new_method_reply (g_dbus_method_invocation_get_message (invocation)); + g_variant_builder_init (&_reply_builder, G_VARIANT_TYPE_TUPLE); + _reply = g_variant_builder_end (&_reply_builder); + g_dbus_message_set_body (_reply_message, _reply); + g_dbus_connection_send_message (g_dbus_method_invocation_get_connection (invocation), _reply_message, G_DBUS_SEND_MESSAGE_FLAGS_NONE, NULL, NULL); + g_object_unref (invocation); + g_object_unref (_reply_message); + _error: + g_slice_free (TestTestCancellableReadyData, _ready_data); +} + +static void +test_dbus_interface_method_call (GDBusConnection* connection, + const gchar* sender, + const gchar* object_path, + const gchar* interface_name, + const gchar* method_name, + GVariant* parameters, + GDBusMethodInvocation* invocation, + gpointer user_data) +{ + gpointer* data; + gpointer object; + data = user_data; + object = data[0]; + if (strcmp (method_name, "TestVoid") == 0) { + _dbus_test_test_void (object, parameters, invocation); + } else if (strcmp (method_name, "TestInt") == 0) { + _dbus_test_test_int (object, parameters, invocation); + } else if (strcmp (method_name, "TestString") == 0) { + _dbus_test_test_string (object, parameters, invocation); + } else if (strcmp (method_name, "TestCancellable") == 0) { + _dbus_test_test_cancellable (object, parameters, invocation); + } else { + g_object_unref (invocation); + } +} + +static GVariant* +test_dbus_interface_get_property (GDBusConnection* connection, + const gchar* sender, + const gchar* object_path, + const gchar* interface_name, + const gchar* property_name, + GError** error, + gpointer user_data) +{ + gpointer* data; + gpointer object; + data = user_data; + object = data[0]; + return NULL; +} + +static gboolean +test_dbus_interface_set_property (GDBusConnection* connection, + const gchar* sender, + const gchar* object_path, + const gchar* interface_name, + const gchar* property_name, + GVariant* value, + GError** error, + gpointer user_data) +{ + gpointer* data; + gpointer object; + data = user_data; + object = data[0]; + return FALSE; +} + +guint +test_register_object (gpointer object, + GDBusConnection* connection, + const gchar* path, + GError** error) +{ + guint result; + gpointer *data; + data = g_new (gpointer, 3); + data[0] = g_object_ref (object); + data[1] = g_object_ref (connection); + data[2] = g_strdup (path); + result = g_dbus_connection_register_object (connection, path, (GDBusInterfaceInfo *) (&_test_dbus_interface_info), &_test_dbus_interface_vtable, data, _test_unregister_object, error); + if (!result) { + return 0; + } + return result; +} + +static void +_test_unregister_object (gpointer user_data) +{ + gpointer* data; + data = user_data; + g_object_unref (data[0]); + g_object_unref (data[1]); + g_free (data[2]); + g_free (data); +} + +static void +run_data_free (gpointer _data) +{ + RunData* _data_; + _data_ = _data; + g_slice_free (RunData, _data_); +} + +void +run (GAsyncReadyCallback _callback_, + gpointer _user_data_) +{ + RunData* _data_; + _data_ = g_slice_new0 (RunData); + _data_->_async_result = g_task_new (NULL, NULL, _callback_, _user_data_); + g_task_set_task_data (_data_->_async_result, _data_, run_data_free); + run_co (_data_); +} + +void +run_finish (GAsyncResult* _res_) +{ + RunData* _data_; + _data_ = g_task_propagate_pointer (G_TASK (_res_), NULL); +} + +static void +run_ready (GObject* source_object, + GAsyncResult* _res_, + gpointer _user_data_) +{ + RunData* _data_; + _data_ = _user_data_; + _data_->_source_object_ = source_object; + _data_->_res_ = _res_; + run_co (_data_); +} + +static gboolean +run_co (RunData* _data_) +{ + switch (_data_->_state_) { + case 0: + goto _state_0; + case 1: + goto _state_1; + case 2: + goto _state_2; + case 3: + goto _state_3; + case 4: + goto _state_4; + case 5: + goto _state_5; + default: + g_assert_not_reached (); + } + _state_0: + _data_->_state_ = 1; + g_async_initable_new_async (TYPE_TEST_PROXY, 0, NULL, run_ready, _data_, "g-flags", 0, "g-name", "org.example.Test", "g-bus-type", G_BUS_TYPE_SESSION, "g-object-path", "/org/example/test", "g-interface-name", "org.example.Test", NULL); + return FALSE; + _state_1: + _data_->_tmp0_ = (Test*) g_async_initable_new_finish ((GAsyncInitable *) _data_->_source_object_, _data_->_res_, &_data_->_inner_error0_); + _data_->test = (Test*) _data_->_tmp0_; + if (G_UNLIKELY (_data_->_inner_error0_ != NULL)) { + g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _data_->_inner_error0_->message, g_quark_to_string (_data_->_inner_error0_->domain), _data_->_inner_error0_->code); + g_clear_error (&_data_->_inner_error0_); + g_object_unref (_data_->_async_result); + return FALSE; + } + { + _data_->_state_ = 2; + test_test_void (_data_->test, run_ready, _data_); + return FALSE; + _state_2: + test_test_void_finish (_data_->test, _data_->_res_, &_data_->_inner_error0_); + if (G_UNLIKELY (_data_->_inner_error0_ != NULL)) { + goto __catch0_g_error; + } + g_assert_not_reached (); + } + goto __finally0; + __catch0_g_error: + { + g_clear_error (&_data_->_inner_error0_); + } + __finally0: + if (G_UNLIKELY (_data_->_inner_error0_ != NULL)) { + _g_object_unref0 (_data_->test); + g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _data_->_inner_error0_->message, g_quark_to_string (_data_->_inner_error0_->domain), _data_->_inner_error0_->code); + g_clear_error (&_data_->_inner_error0_); + g_object_unref (_data_->_async_result); + return FALSE; + } + { + _data_->_tmp2_ = 0; + _data_->_state_ = 3; + test_test_int (_data_->test, 42, run_ready, _data_); + return FALSE; + _state_3: + _data_->_tmp3_ = test_test_int_finish (_data_->test, _data_->_res_, &_data_->_tmp2_, &_data_->_inner_error0_); + _data_->j = _data_->_tmp2_; + _data_->_tmp1_ = _data_->_tmp3_; + if (G_UNLIKELY (_data_->_inner_error0_ != NULL)) { + goto __catch1_g_error; + } + _data_->k = _data_->_tmp1_; + g_assert_not_reached (); + } + goto __finally1; + __catch1_g_error: + { + g_clear_error (&_data_->_inner_error0_); + } + __finally1: + if (G_UNLIKELY (_data_->_inner_error0_ != NULL)) { + _g_object_unref0 (_data_->test); + g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _data_->_inner_error0_->message, g_quark_to_string (_data_->_inner_error0_->domain), _data_->_inner_error0_->code); + g_clear_error (&_data_->_inner_error0_); + g_object_unref (_data_->_async_result); + return FALSE; + } + { + _data_->_tmp5_ = NULL; + _data_->_state_ = 4; + test_test_string (_data_->test, "hello", run_ready, _data_); + return FALSE; + _state_4: + _data_->_tmp6_ = test_test_string_finish (_data_->test, _data_->_res_, &_data_->_tmp5_, &_data_->_inner_error0_); + _g_free0 (_data_->t); + _data_->t = _data_->_tmp5_; + _data_->_tmp4_ = _data_->_tmp6_; + if (G_UNLIKELY (_data_->_inner_error0_ != NULL)) { + _g_free0 (_data_->u); + _g_free0 (_data_->t); + goto __catch2_g_error; + } + _data_->_tmp7_ = _data_->_tmp4_; + _data_->_tmp4_ = NULL; + _g_free0 (_data_->u); + _data_->u = _data_->_tmp7_; + g_assert_not_reached (); + _g_free0 (_data_->_tmp4_); + _g_free0 (_data_->u); + _g_free0 (_data_->t); + } + goto __finally2; + __catch2_g_error: + { + g_clear_error (&_data_->_inner_error0_); + } + __finally2: + if (G_UNLIKELY (_data_->_inner_error0_ != NULL)) { + _g_object_unref0 (_data_->test); + g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _data_->_inner_error0_->message, g_quark_to_string (_data_->_inner_error0_->domain), _data_->_inner_error0_->code); + g_clear_error (&_data_->_inner_error0_); + g_object_unref (_data_->_async_result); + return FALSE; + } + { + _data_->_tmp8_ = g_cancellable_new (); + _data_->cancellable = _data_->_tmp8_; + _data_->_tmp9_ = _data_->cancellable; + g_cancellable_cancel (_data_->_tmp9_); + _data_->_tmp10_ = _data_->cancellable; + _data_->_state_ = 5; + test_test_cancellable (_data_->test, _data_->_tmp10_, run_ready, _data_); + return FALSE; + _state_5: + test_test_cancellable_finish (_data_->test, _data_->_res_, &_data_->_inner_error0_); + if (G_UNLIKELY (_data_->_inner_error0_ != NULL)) { + _g_object_unref0 (_data_->cancellable); + goto __catch3_g_error; + } + g_assert_not_reached (); + _g_object_unref0 (_data_->cancellable); + } + goto __finally3; + __catch3_g_error: + { + g_clear_error (&_data_->_inner_error0_); + } + __finally3: + if (G_UNLIKELY (_data_->_inner_error0_ != NULL)) { + _g_object_unref0 (_data_->test); + g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _data_->_inner_error0_->message, g_quark_to_string (_data_->_inner_error0_->domain), _data_->_inner_error0_->code); + g_clear_error (&_data_->_inner_error0_); + g_object_unref (_data_->_async_result); + return FALSE; + } + _data_->_tmp11_ = main_loop; + g_main_loop_quit (_data_->_tmp11_); + _g_object_unref0 (_data_->test); + g_task_return_pointer (_data_->_async_result, _data_, NULL); + if (_data_->_state_ != 0) { + while (!g_task_get_completed (_data_->_async_result)) { + g_main_context_iteration (g_task_get_context (_data_->_async_result), TRUE); + } + } + g_object_unref (_data_->_async_result); + return FALSE; +} + +static void +_vala_main (void) +{ + GMainLoop* _tmp0_; + GMainLoop* _tmp1_; + run (NULL, NULL); + _tmp0_ = g_main_loop_new (NULL, FALSE); + _g_main_loop_unref0 (main_loop); + main_loop = _tmp0_; + _tmp1_ = main_loop; + g_main_loop_run (_tmp1_); +} + +int +main (int argc, + char ** argv) +{ + _vala_main (); + return 0; +} + diff --git a/tests/dbus/async-errors_server.c-expected b/tests/dbus/async-errors_server.c-expected new file mode 100644 index 000000000..819beebe7 --- /dev/null +++ b/tests/dbus/async-errors_server.c-expected @@ -0,0 +1,1071 @@ +/* dbus_async_errors_server.c generated by valac, the Vala compiler + * generated from dbus_async_errors_server.vala, do not modify */ + +#include <glib-object.h> +#include <gio/gio.h> +#include <glib.h> +#include <stdlib.h> +#include <string.h> + +#if !defined(VALA_EXTERN) +#if defined(_MSC_VER) +#define VALA_EXTERN __declspec(dllexport) extern +#elif __GNUC__ >= 4 +#define VALA_EXTERN __attribute__((visibility("default"))) extern +#else +#define VALA_EXTERN extern +#endif +#endif + +#define TYPE_TEST (test_get_type ()) +#define TEST(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TYPE_TEST, Test)) +#define TEST_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), TYPE_TEST, TestClass)) +#define IS_TEST(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TYPE_TEST)) +#define IS_TEST_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), TYPE_TEST)) +#define TEST_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), TYPE_TEST, TestClass)) + +typedef struct _Test Test; +typedef struct _TestClass TestClass; +typedef struct _TestPrivate TestPrivate; +enum { + TEST_0_PROPERTY, + TEST_NUM_PROPERTIES +}; +static GParamSpec* test_properties[TEST_NUM_PROPERTIES]; +#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL))) +typedef struct _TestTestVoidData TestTestVoidData; +typedef struct _TestTestIntData TestTestIntData; +#define _g_free0(var) (var = (g_free (var), NULL)) +typedef struct _TestTestStringData TestTestStringData; +typedef struct _TestTestCancellableData TestTestCancellableData; +typedef struct _TestTestVoidReadyData TestTestVoidReadyData; +typedef struct _TestTestIntReadyData TestTestIntReadyData; +typedef struct _TestTestStringReadyData TestTestStringReadyData; +typedef struct _TestTestCancellableReadyData TestTestCancellableReadyData; +#define _g_variant_unref0(var) ((var == NULL) ? NULL : (var = (g_variant_unref (var), NULL))) +#define _g_main_loop_unref0(var) ((var == NULL) ? NULL : (var = (g_main_loop_unref (var), NULL))) +#define _vala_assert(expr, msg) if G_LIKELY (expr) ; else g_assertion_message_expr (G_LOG_DOMAIN, __FILE__, __LINE__, G_STRFUNC, msg); +#define _vala_return_if_fail(expr, msg) if G_LIKELY (expr) ; else { g_return_if_fail_warning (G_LOG_DOMAIN, G_STRFUNC, msg); return; } +#define _vala_return_val_if_fail(expr, msg, val) if G_LIKELY (expr) ; else { g_return_if_fail_warning (G_LOG_DOMAIN, G_STRFUNC, msg); return val; } +#define _vala_warn_if_fail(expr, msg) if G_LIKELY (expr) ; else g_warn_message (G_LOG_DOMAIN, __FILE__, __LINE__, G_STRFUNC, msg); + +struct _Test { + GObject parent_instance; + TestPrivate * priv; +}; + +struct _TestClass { + GObjectClass parent_class; +}; + +struct _TestTestVoidData { + int _state_; + GObject* _source_object_; + GAsyncResult* _res_; + GTask* _async_result; + Test* self; + GError* _tmp0_; + GError* _inner_error0_; +}; + +struct _TestTestIntData { + int _state_; + GObject* _source_object_; + GAsyncResult* _res_; + GTask* _async_result; + Test* self; + gint i; + gint j; + gint result; + GError* _tmp0_; + GError* _inner_error0_; +}; + +struct _TestTestStringData { + int _state_; + GObject* _source_object_; + GAsyncResult* _res_; + GTask* _async_result; + Test* self; + gchar* s; + gchar* t; + gchar* result; + GError* _tmp0_; + GError* _inner_error0_; +}; + +struct _TestTestCancellableData { + int _state_; + GObject* _source_object_; + GAsyncResult* _res_; + GTask* _async_result; + Test* self; + GCancellable* cancellable; +}; + +struct _TestTestVoidReadyData { + GDBusMethodInvocation* _invocation_; +}; + +struct _TestTestIntReadyData { + GDBusMethodInvocation* _invocation_; + gint i; +}; + +struct _TestTestStringReadyData { + GDBusMethodInvocation* _invocation_; + gchar* s; +}; + +struct _TestTestCancellableReadyData { + GDBusMethodInvocation* _invocation_; +}; + +static gpointer test_parent_class = NULL; +VALA_EXTERN GMainLoop* main_loop; +GMainLoop* main_loop = NULL; + +VALA_EXTERN GType test_get_type (void) G_GNUC_CONST ; +G_DEFINE_AUTOPTR_CLEANUP_FUNC (Test, g_object_unref) +VALA_EXTERN guint test_register_object (void* object, + GDBusConnection* connection, + const gchar* path, + GError** error); +static void test_test_void_data_free (gpointer _data); +VALA_EXTERN void test_test_void (Test* self, + GAsyncReadyCallback _callback_, + gpointer _user_data_); +VALA_EXTERN void test_test_void_finish (Test* self, + GAsyncResult* _res_, + GError** error); +static gboolean test_test_void_co (TestTestVoidData* _data_); +static gboolean _test_test_void_co_gsource_func (gpointer self); +static void test_test_int_data_free (gpointer _data); +VALA_EXTERN void test_test_int (Test* self, + gint i, + GAsyncReadyCallback _callback_, + gpointer _user_data_); +VALA_EXTERN gint test_test_int_finish (Test* self, + GAsyncResult* _res_, + gint* j, + GError** error); +static gboolean test_test_int_co (TestTestIntData* _data_); +static gboolean _test_test_int_co_gsource_func (gpointer self); +static void test_test_string_data_free (gpointer _data); +VALA_EXTERN void test_test_string (Test* self, + const gchar* s, + GAsyncReadyCallback _callback_, + gpointer _user_data_); +VALA_EXTERN gchar* test_test_string_finish (Test* self, + GAsyncResult* _res_, + gchar* * t, + GError** error); +static gboolean test_test_string_co (TestTestStringData* _data_); +static gboolean _test_test_string_co_gsource_func (gpointer self); +static void test_test_cancellable_data_free (gpointer _data); +VALA_EXTERN void test_test_cancellable (Test* self, + GCancellable* cancellable, + GAsyncReadyCallback _callback_, + gpointer _user_data_); +VALA_EXTERN void test_test_cancellable_finish (Test* self, + GAsyncResult* _res_, + GError** error); +static gboolean test_test_cancellable_co (TestTestCancellableData* _data_); +static gboolean _test_test_cancellable_co_gsource_func (gpointer self); +VALA_EXTERN Test* test_new (void); +VALA_EXTERN Test* test_construct (GType object_type); +static GType test_get_type_once (void); +static void _dbus_test_test_void (Test* self, + GVariant* _parameters_, + GDBusMethodInvocation* invocation); +static void _dbus_test_test_void_ready (GObject * source_object, + GAsyncResult * _res_, + gpointer _user_data_); +static void _dbus_test_test_int (Test* self, + GVariant* _parameters_, + GDBusMethodInvocation* invocation); +static void _dbus_test_test_int_ready (GObject * source_object, + GAsyncResult * _res_, + gpointer _user_data_); +static void _dbus_test_test_string (Test* self, + GVariant* _parameters_, + GDBusMethodInvocation* invocation); +static void _dbus_test_test_string_ready (GObject * source_object, + GAsyncResult * _res_, + gpointer _user_data_); +static void _dbus_test_test_cancellable (Test* self, + GVariant* _parameters_, + GDBusMethodInvocation* invocation); +static void _dbus_test_test_cancellable_ready (GObject * source_object, + GAsyncResult * _res_, + gpointer _user_data_); +static void test_dbus_interface_method_call (GDBusConnection* connection, + const gchar* sender, + const gchar* object_path, + const gchar* interface_name, + const gchar* method_name, + GVariant* parameters, + GDBusMethodInvocation* invocation, + gpointer user_data); +static GVariant* test_dbus_interface_get_property (GDBusConnection* connection, + const gchar* sender, + const gchar* object_path, + const gchar* interface_name, + const gchar* property_name, + GError** error, + gpointer user_data); +static gboolean test_dbus_interface_set_property (GDBusConnection* connection, + const gchar* sender, + const gchar* object_path, + const gchar* interface_name, + const gchar* property_name, + GVariant* value, + GError** error, + gpointer user_data); +static void _test_unregister_object (gpointer user_data); +VALA_EXTERN void client_exit (GPid pid, + gint status); +static void _vala_main (void); +static guint _variant_get1 (GVariant* value); +static void _client_exit_gchild_watch_func (GPid pid, + gint wait_status, + gpointer self); +static void _vala_array_destroy (gpointer array, + gssize array_length, + GDestroyNotify destroy_func); +static void _vala_array_free (gpointer array, + gssize array_length, + GDestroyNotify destroy_func); + +static const GDBusArgInfo * const _test_dbus_arg_info_test_void_in[] = {NULL}; +static const GDBusArgInfo * const _test_dbus_arg_info_test_void_out[] = {NULL}; +static const GDBusMethodInfo _test_dbus_method_info_test_void = {-1, "TestVoid", (GDBusArgInfo **) (&_test_dbus_arg_info_test_void_in), (GDBusArgInfo **) (&_test_dbus_arg_info_test_void_out), NULL}; +static const GDBusArgInfo _test_dbus_arg_info_test_int_i = {-1, "i", "i", NULL}; +static const GDBusArgInfo _test_dbus_arg_info_test_int_j = {-1, "j", "i", NULL}; +static const GDBusArgInfo _test_dbus_arg_info_test_int_result = {-1, "result", "i", NULL}; +static const GDBusArgInfo * const _test_dbus_arg_info_test_int_in[] = {&_test_dbus_arg_info_test_int_i, NULL}; +static const GDBusArgInfo * const _test_dbus_arg_info_test_int_out[] = {&_test_dbus_arg_info_test_int_j, &_test_dbus_arg_info_test_int_result, NULL}; +static const GDBusMethodInfo _test_dbus_method_info_test_int = {-1, "TestInt", (GDBusArgInfo **) (&_test_dbus_arg_info_test_int_in), (GDBusArgInfo **) (&_test_dbus_arg_info_test_int_out), NULL}; +static const GDBusArgInfo _test_dbus_arg_info_test_string_s = {-1, "s", "s", NULL}; +static const GDBusArgInfo _test_dbus_arg_info_test_string_t = {-1, "t", "s", NULL}; +static const GDBusArgInfo _test_dbus_arg_info_test_string_result = {-1, "result", "s", NULL}; +static const GDBusArgInfo * const _test_dbus_arg_info_test_string_in[] = {&_test_dbus_arg_info_test_string_s, NULL}; +static const GDBusArgInfo * const _test_dbus_arg_info_test_string_out[] = {&_test_dbus_arg_info_test_string_t, &_test_dbus_arg_info_test_string_result, NULL}; +static const GDBusMethodInfo _test_dbus_method_info_test_string = {-1, "TestString", (GDBusArgInfo **) (&_test_dbus_arg_info_test_string_in), (GDBusArgInfo **) (&_test_dbus_arg_info_test_string_out), NULL}; +static const GDBusArgInfo * const _test_dbus_arg_info_test_cancellable_in[] = {NULL}; +static const GDBusArgInfo * const _test_dbus_arg_info_test_cancellable_out[] = {NULL}; +static const GDBusMethodInfo _test_dbus_method_info_test_cancellable = {-1, "TestCancellable", (GDBusArgInfo **) (&_test_dbus_arg_info_test_cancellable_in), (GDBusArgInfo **) (&_test_dbus_arg_info_test_cancellable_out), NULL}; +static const GDBusMethodInfo * const _test_dbus_method_info[] = {&_test_dbus_method_info_test_void, &_test_dbus_method_info_test_int, &_test_dbus_method_info_test_string, &_test_dbus_method_info_test_cancellable, NULL}; +static const GDBusSignalInfo * const _test_dbus_signal_info[] = {NULL}; +static const GDBusPropertyInfo * const _test_dbus_property_info[] = {NULL}; +static const GDBusInterfaceInfo _test_dbus_interface_info = {-1, "org.example.Test", (GDBusMethodInfo **) (&_test_dbus_method_info), (GDBusSignalInfo **) (&_test_dbus_signal_info), (GDBusPropertyInfo **) (&_test_dbus_property_info), NULL}; +static const GDBusInterfaceVTable _test_dbus_interface_vtable = {test_dbus_interface_method_call, test_dbus_interface_get_property, test_dbus_interface_set_property}; + +static void +test_test_void_data_free (gpointer _data) +{ + TestTestVoidData* _data_; + _data_ = _data; + _g_object_unref0 (_data_->self); + g_slice_free (TestTestVoidData, _data_); +} + +static gpointer +_g_object_ref0 (gpointer self) +{ + return self ? g_object_ref (self) : NULL; +} + +void +test_test_void (Test* self, + GAsyncReadyCallback _callback_, + gpointer _user_data_) +{ + TestTestVoidData* _data_; + Test* _tmp0_; + g_return_if_fail (IS_TEST (self)); + _data_ = g_slice_new0 (TestTestVoidData); + _data_->_async_result = g_task_new (G_OBJECT (self), NULL, _callback_, _user_data_); + g_task_set_task_data (_data_->_async_result, _data_, test_test_void_data_free); + _tmp0_ = _g_object_ref0 (self); + _data_->self = _tmp0_; + test_test_void_co (_data_); +} + +void +test_test_void_finish (Test* self, + GAsyncResult* _res_, + GError** error) +{ + TestTestVoidData* _data_; + _data_ = g_task_propagate_pointer (G_TASK (_res_), error); + if (NULL == _data_) { + return; + } +} + +static gboolean +_test_test_void_co_gsource_func (gpointer self) +{ + gboolean result; + result = test_test_void_co (self); + return result; +} + +static gboolean +test_test_void_co (TestTestVoidData* _data_) +{ + switch (_data_->_state_) { + case 0: + goto _state_0; + case 1: + goto _state_1; + default: + g_assert_not_reached (); + } + _state_0: + g_idle_add_full (G_PRIORITY_DEFAULT_IDLE, _test_test_void_co_gsource_func, _data_, NULL); + _data_->_state_ = 1; + return FALSE; + _state_1: + ; + _data_->_tmp0_ = g_error_new_literal (G_IO_ERROR, G_IO_ERROR_FAILED, "Operation failed"); + _data_->_inner_error0_ = _data_->_tmp0_; + g_task_return_error (_data_->_async_result, _data_->_inner_error0_); + g_object_unref (_data_->_async_result); + return FALSE; + g_task_return_pointer (_data_->_async_result, _data_, NULL); + if (_data_->_state_ != 0) { + while (!g_task_get_completed (_data_->_async_result)) { + g_main_context_iteration (g_task_get_context (_data_->_async_result), TRUE); + } + } + g_object_unref (_data_->_async_result); + return FALSE; +} + +static void +test_test_int_data_free (gpointer _data) +{ + TestTestIntData* _data_; + _data_ = _data; + _g_object_unref0 (_data_->self); + g_slice_free (TestTestIntData, _data_); +} + +void +test_test_int (Test* self, + gint i, + GAsyncReadyCallback _callback_, + gpointer _user_data_) +{ + TestTestIntData* _data_; + Test* _tmp0_; + g_return_if_fail (IS_TEST (self)); + _data_ = g_slice_new0 (TestTestIntData); + _data_->_async_result = g_task_new (G_OBJECT (self), NULL, _callback_, _user_data_); + g_task_set_task_data (_data_->_async_result, _data_, test_test_int_data_free); + _tmp0_ = _g_object_ref0 (self); + _data_->self = _tmp0_; + _data_->i = i; + test_test_int_co (_data_); +} + +gint +test_test_int_finish (Test* self, + GAsyncResult* _res_, + gint* j, + GError** error) +{ + gint result; + TestTestIntData* _data_; + _data_ = g_task_propagate_pointer (G_TASK (_res_), error); + if (NULL == _data_) { + gint _tmp0_ = 0; + return _tmp0_; + } + if (j) { + *j = _data_->j; + } + result = _data_->result; + return result; +} + +static gboolean +_test_test_int_co_gsource_func (gpointer self) +{ + gboolean result; + result = test_test_int_co (self); + return result; +} + +static gboolean +test_test_int_co (TestTestIntData* _data_) +{ + switch (_data_->_state_) { + case 0: + goto _state_0; + case 1: + goto _state_1; + default: + g_assert_not_reached (); + } + _state_0: + g_idle_add_full (G_PRIORITY_DEFAULT_IDLE, _test_test_int_co_gsource_func, _data_, NULL); + _data_->_state_ = 1; + return FALSE; + _state_1: + ; + _data_->_tmp0_ = g_error_new_literal (G_IO_ERROR, G_IO_ERROR_FAILED, "Operation failed"); + _data_->_inner_error0_ = _data_->_tmp0_; + g_task_return_error (_data_->_async_result, _data_->_inner_error0_); + g_object_unref (_data_->_async_result); + return FALSE; +} + +static void +test_test_string_data_free (gpointer _data) +{ + TestTestStringData* _data_; + _data_ = _data; + _g_free0 (_data_->s); + _g_free0 (_data_->result); + _g_object_unref0 (_data_->self); + g_slice_free (TestTestStringData, _data_); +} + +void +test_test_string (Test* self, + const gchar* s, + GAsyncReadyCallback _callback_, + gpointer _user_data_) +{ + TestTestStringData* _data_; + Test* _tmp0_; + gchar* _tmp1_; + g_return_if_fail (IS_TEST (self)); + g_return_if_fail (s != NULL); + _data_ = g_slice_new0 (TestTestStringData); + _data_->_async_result = g_task_new (G_OBJECT (self), NULL, _callback_, _user_data_); + g_task_set_task_data (_data_->_async_result, _data_, test_test_string_data_free); + _tmp0_ = _g_object_ref0 (self); + _data_->self = _tmp0_; + _tmp1_ = g_strdup (s); + _g_free0 (_data_->s); + _data_->s = _tmp1_; + test_test_string_co (_data_); +} + +gchar* +test_test_string_finish (Test* self, + GAsyncResult* _res_, + gchar* * t, + GError** error) +{ + gchar* result; + TestTestStringData* _data_; + _data_ = g_task_propagate_pointer (G_TASK (_res_), error); + if (NULL == _data_) { + return NULL; + } + if (t) { + *t = _data_->t; + } else { + _g_free0 (_data_->t); + } + _data_->t = NULL; + result = _data_->result; + _data_->result = NULL; + return result; +} + +static gboolean +_test_test_string_co_gsource_func (gpointer self) +{ + gboolean result; + result = test_test_string_co (self); + return result; +} + +static gboolean +test_test_string_co (TestTestStringData* _data_) +{ + switch (_data_->_state_) { + case 0: + goto _state_0; + case 1: + goto _state_1; + default: + g_assert_not_reached (); + } + _state_0: + g_idle_add_full (G_PRIORITY_DEFAULT_IDLE, _test_test_string_co_gsource_func, _data_, NULL); + _data_->_state_ = 1; + return FALSE; + _state_1: + ; + _data_->_tmp0_ = g_error_new_literal (G_IO_ERROR, G_IO_ERROR_FAILED, "Operation failed"); + _data_->_inner_error0_ = _data_->_tmp0_; + g_task_return_error (_data_->_async_result, _data_->_inner_error0_); + _g_free0 (_data_->t); + g_object_unref (_data_->_async_result); + return FALSE; +} + +static void +test_test_cancellable_data_free (gpointer _data) +{ + TestTestCancellableData* _data_; + _data_ = _data; + _g_object_unref0 (_data_->cancellable); + _g_object_unref0 (_data_->self); + g_slice_free (TestTestCancellableData, _data_); +} + +void +test_test_cancellable (Test* self, + GCancellable* cancellable, + GAsyncReadyCallback _callback_, + gpointer _user_data_) +{ + TestTestCancellableData* _data_; + Test* _tmp0_; + GCancellable* _tmp1_; + g_return_if_fail (IS_TEST (self)); + g_return_if_fail ((cancellable == NULL) || G_TYPE_CHECK_INSTANCE_TYPE (cancellable, g_cancellable_get_type ())); + _data_ = g_slice_new0 (TestTestCancellableData); + _data_->_async_result = g_task_new (G_OBJECT (self), cancellable, _callback_, _user_data_); + g_task_set_task_data (_data_->_async_result, _data_, test_test_cancellable_data_free); + _tmp0_ = _g_object_ref0 (self); + _data_->self = _tmp0_; + _tmp1_ = _g_object_ref0 (cancellable); + _g_object_unref0 (_data_->cancellable); + _data_->cancellable = _tmp1_; + test_test_cancellable_co (_data_); +} + +void +test_test_cancellable_finish (Test* self, + GAsyncResult* _res_, + GError** error) +{ + TestTestCancellableData* _data_; + _data_ = g_task_propagate_pointer (G_TASK (_res_), error); + if (NULL == _data_) { + return; + } +} + +static gboolean +_test_test_cancellable_co_gsource_func (gpointer self) +{ + gboolean result; + result = test_test_cancellable_co (self); + return result; +} + +static gboolean +test_test_cancellable_co (TestTestCancellableData* _data_) +{ + switch (_data_->_state_) { + case 0: + goto _state_0; + case 1: + goto _state_1; + default: + g_assert_not_reached (); + } + _state_0: + g_idle_add_full (G_PRIORITY_DEFAULT_IDLE, _test_test_cancellable_co_gsource_func, _data_, NULL); + _data_->_state_ = 1; + return FALSE; + _state_1: + ; + g_task_return_pointer (_data_->_async_result, _data_, NULL); + if (_data_->_state_ != 0) { + while (!g_task_get_completed (_data_->_async_result)) { + g_main_context_iteration (g_task_get_context (_data_->_async_result), TRUE); + } + } + g_object_unref (_data_->_async_result); + return FALSE; +} + +Test* +test_construct (GType object_type) +{ + Test * self = NULL; + self = (Test*) g_object_new (object_type, NULL); + return self; +} + +Test* +test_new (void) +{ + return test_construct (TYPE_TEST); +} + +static void +test_class_init (TestClass * klass, + gpointer klass_data) +{ + test_parent_class = g_type_class_peek_parent (klass); +} + +static void +test_instance_init (Test * self, + gpointer klass) +{ +} + +static GType +test_get_type_once (void) +{ + static const GTypeInfo g_define_type_info = { sizeof (TestClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) test_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (Test), 0, (GInstanceInitFunc) test_instance_init, NULL }; + GType test_type_id; + test_type_id = g_type_register_static (G_TYPE_OBJECT, "Test", &g_define_type_info, 0); + g_type_set_qdata (test_type_id, g_quark_from_static_string ("vala-dbus-register-object"), (void*) test_register_object); + return test_type_id; +} + +GType +test_get_type (void) +{ + static volatile gsize test_type_id__volatile = 0; + if (g_once_init_enter (&test_type_id__volatile)) { + GType test_type_id; + test_type_id = test_get_type_once (); + g_once_init_leave (&test_type_id__volatile, test_type_id); + } + return test_type_id__volatile; +} + +static void +_dbus_test_test_void (Test* self, + GVariant* _parameters_, + GDBusMethodInvocation* invocation) +{ + GVariantIter _arguments_iter; + TestTestVoidReadyData* _ready_data; + g_variant_iter_init (&_arguments_iter, _parameters_); + _ready_data = g_slice_new0 (TestTestVoidReadyData); + _ready_data->_invocation_ = invocation; + test_test_void (self, (GAsyncReadyCallback) _dbus_test_test_void_ready, _ready_data); +} + +static void +_dbus_test_test_void_ready (GObject * source_object, + GAsyncResult * _res_, + gpointer _user_data_) +{ + TestTestVoidReadyData* _ready_data; + GDBusMethodInvocation* invocation; + GError* error = NULL; + GDBusMessage* _reply_message = NULL; + GVariant* _reply; + GVariantBuilder _reply_builder; + _ready_data = _user_data_; + invocation = _ready_data->_invocation_; + test_test_void_finish ((Test*) source_object, _res_, &error); + if (error) { + g_dbus_method_invocation_return_gerror (invocation, error); + g_error_free (error); + goto _error; + } + _reply_message = g_dbus_message_new_method_reply (g_dbus_method_invocation_get_message (invocation)); + g_variant_builder_init (&_reply_builder, G_VARIANT_TYPE_TUPLE); + _reply = g_variant_builder_end (&_reply_builder); + g_dbus_message_set_body (_reply_message, _reply); + g_dbus_connection_send_message (g_dbus_method_invocation_get_connection (invocation), _reply_message, G_DBUS_SEND_MESSAGE_FLAGS_NONE, NULL, NULL); + g_object_unref (invocation); + g_object_unref (_reply_message); + _error: + g_slice_free (TestTestVoidReadyData, _ready_data); +} + +static void +_dbus_test_test_int (Test* self, + GVariant* _parameters_, + GDBusMethodInvocation* invocation) +{ + GVariantIter _arguments_iter; + TestTestIntReadyData* _ready_data; + GVariant* _tmp0_; + g_variant_iter_init (&_arguments_iter, _parameters_); + _ready_data = g_slice_new0 (TestTestIntReadyData); + _ready_data->_invocation_ = invocation; + _tmp0_ = g_variant_iter_next_value (&_arguments_iter); + _ready_data->i = g_variant_get_int32 (_tmp0_); + g_variant_unref (_tmp0_); + test_test_int (self, _ready_data->i, (GAsyncReadyCallback) _dbus_test_test_int_ready, _ready_data); +} + +static void +_dbus_test_test_int_ready (GObject * source_object, + GAsyncResult * _res_, + gpointer _user_data_) +{ + TestTestIntReadyData* _ready_data; + GDBusMethodInvocation* invocation; + GError* error = NULL; + GDBusMessage* _reply_message = NULL; + GVariant* _reply; + GVariantBuilder _reply_builder; + gint j = 0; + gint result; + _ready_data = _user_data_; + invocation = _ready_data->_invocation_; + result = test_test_int_finish ((Test*) source_object, _res_, &j, &error); + if (error) { + g_dbus_method_invocation_return_gerror (invocation, error); + g_error_free (error); + goto _error; + } + _reply_message = g_dbus_message_new_method_reply (g_dbus_method_invocation_get_message (invocation)); + g_variant_builder_init (&_reply_builder, G_VARIANT_TYPE_TUPLE); + g_variant_builder_add_value (&_reply_builder, g_variant_new_int32 (j)); + g_variant_builder_add_value (&_reply_builder, g_variant_new_int32 (result)); + _reply = g_variant_builder_end (&_reply_builder); + g_dbus_message_set_body (_reply_message, _reply); + g_dbus_connection_send_message (g_dbus_method_invocation_get_connection (invocation), _reply_message, G_DBUS_SEND_MESSAGE_FLAGS_NONE, NULL, NULL); + g_object_unref (invocation); + g_object_unref (_reply_message); + _error: + g_slice_free (TestTestIntReadyData, _ready_data); +} + +static void +_dbus_test_test_string (Test* self, + GVariant* _parameters_, + GDBusMethodInvocation* invocation) +{ + GVariantIter _arguments_iter; + TestTestStringReadyData* _ready_data; + GVariant* _tmp1_; + g_variant_iter_init (&_arguments_iter, _parameters_); + _ready_data = g_slice_new0 (TestTestStringReadyData); + _ready_data->_invocation_ = invocation; + _tmp1_ = g_variant_iter_next_value (&_arguments_iter); + _ready_data->s = g_variant_dup_string (_tmp1_, NULL); + g_variant_unref (_tmp1_); + test_test_string (self, _ready_data->s, (GAsyncReadyCallback) _dbus_test_test_string_ready, _ready_data); + _error: + ; +} + +static void +_dbus_test_test_string_ready (GObject * source_object, + GAsyncResult * _res_, + gpointer _user_data_) +{ + TestTestStringReadyData* _ready_data; + GDBusMethodInvocation* invocation; + GError* error = NULL; + GDBusMessage* _reply_message = NULL; + GVariant* _reply; + GVariantBuilder _reply_builder; + gchar* t = NULL; + gchar* result; + _ready_data = _user_data_; + invocation = _ready_data->_invocation_; + result = test_test_string_finish ((Test*) source_object, _res_, &t, &error); + if (error) { + g_dbus_method_invocation_return_gerror (invocation, error); + g_error_free (error); + goto _error; + } + _reply_message = g_dbus_message_new_method_reply (g_dbus_method_invocation_get_message (invocation)); + g_variant_builder_init (&_reply_builder, G_VARIANT_TYPE_TUPLE); + g_variant_builder_add_value (&_reply_builder, g_variant_new_string (t)); + g_variant_builder_add_value (&_reply_builder, g_variant_new_string (result)); + _g_free0 (result); + _reply = g_variant_builder_end (&_reply_builder); + g_dbus_message_set_body (_reply_message, _reply); + g_dbus_connection_send_message (g_dbus_method_invocation_get_connection (invocation), _reply_message, G_DBUS_SEND_MESSAGE_FLAGS_NONE, NULL, NULL); + g_object_unref (invocation); + g_object_unref (_reply_message); + _error: + _g_free0 (_ready_data->s); + _g_free0 (t); + g_slice_free (TestTestStringReadyData, _ready_data); +} + +static void +_dbus_test_test_cancellable (Test* self, + GVariant* _parameters_, + GDBusMethodInvocation* invocation) +{ + GVariantIter _arguments_iter; + TestTestCancellableReadyData* _ready_data; + g_variant_iter_init (&_arguments_iter, _parameters_); + _ready_data = g_slice_new0 (TestTestCancellableReadyData); + _ready_data->_invocation_ = invocation; + test_test_cancellable (self, NULL, (GAsyncReadyCallback) _dbus_test_test_cancellable_ready, _ready_data); +} + +static void +_dbus_test_test_cancellable_ready (GObject * source_object, + GAsyncResult * _res_, + gpointer _user_data_) +{ + TestTestCancellableReadyData* _ready_data; + GDBusMethodInvocation* invocation; + GError* error = NULL; + GDBusMessage* _reply_message = NULL; + GVariant* _reply; + GVariantBuilder _reply_builder; + _ready_data = _user_data_; + invocation = _ready_data->_invocation_; + test_test_cancellable_finish ((Test*) source_object, _res_, &error); + if (error) { + g_dbus_method_invocation_return_gerror (invocation, error); + g_error_free (error); + goto _error; + } + _reply_message = g_dbus_message_new_method_reply (g_dbus_method_invocation_get_message (invocation)); + g_variant_builder_init (&_reply_builder, G_VARIANT_TYPE_TUPLE); + _reply = g_variant_builder_end (&_reply_builder); + g_dbus_message_set_body (_reply_message, _reply); + g_dbus_connection_send_message (g_dbus_method_invocation_get_connection (invocation), _reply_message, G_DBUS_SEND_MESSAGE_FLAGS_NONE, NULL, NULL); + g_object_unref (invocation); + g_object_unref (_reply_message); + _error: + g_slice_free (TestTestCancellableReadyData, _ready_data); +} + +static void +test_dbus_interface_method_call (GDBusConnection* connection, + const gchar* sender, + const gchar* object_path, + const gchar* interface_name, + const gchar* method_name, + GVariant* parameters, + GDBusMethodInvocation* invocation, + gpointer user_data) +{ + gpointer* data; + gpointer object; + data = user_data; + object = data[0]; + if (strcmp (method_name, "TestVoid") == 0) { + _dbus_test_test_void (object, parameters, invocation); + } else if (strcmp (method_name, "TestInt") == 0) { + _dbus_test_test_int (object, parameters, invocation); + } else if (strcmp (method_name, "TestString") == 0) { + _dbus_test_test_string (object, parameters, invocation); + } else if (strcmp (method_name, "TestCancellable") == 0) { + _dbus_test_test_cancellable (object, parameters, invocation); + } else { + g_object_unref (invocation); + } +} + +static GVariant* +test_dbus_interface_get_property (GDBusConnection* connection, + const gchar* sender, + const gchar* object_path, + const gchar* interface_name, + const gchar* property_name, + GError** error, + gpointer user_data) +{ + gpointer* data; + gpointer object; + data = user_data; + object = data[0]; + return NULL; +} + +static gboolean +test_dbus_interface_set_property (GDBusConnection* connection, + const gchar* sender, + const gchar* object_path, + const gchar* interface_name, + const gchar* property_name, + GVariant* value, + GError** error, + gpointer user_data) +{ + gpointer* data; + gpointer object; + data = user_data; + object = data[0]; + return FALSE; +} + +guint +test_register_object (gpointer object, + GDBusConnection* connection, + const gchar* path, + GError** error) +{ + guint result; + gpointer *data; + data = g_new (gpointer, 3); + data[0] = g_object_ref (object); + data[1] = g_object_ref (connection); + data[2] = g_strdup (path); + result = g_dbus_connection_register_object (connection, path, (GDBusInterfaceInfo *) (&_test_dbus_interface_info), &_test_dbus_interface_vtable, data, _test_unregister_object, error); + if (!result) { + return 0; + } + return result; +} + +static void +_test_unregister_object (gpointer user_data) +{ + gpointer* data; + data = user_data; + g_object_unref (data[0]); + g_object_unref (data[1]); + g_free (data[2]); + g_free (data); +} + +void +client_exit (GPid pid, + gint status) +{ + GMainLoop* _tmp0_; + _vala_assert (status == 0, "status == 0"); + _tmp0_ = main_loop; + g_main_loop_quit (_tmp0_); +} + +static guint +_variant_get1 (GVariant* value) +{ + return g_variant_get_uint32 (value); +} + +static void +_client_exit_gchild_watch_func (GPid pid, + gint wait_status, + gpointer self) +{ + client_exit (pid, wait_status); +} + +static void +_vala_main (void) +{ + GDBusConnection* conn = NULL; + GDBusConnection* _tmp0_; + GDBusConnection* _tmp1_; + Test* _tmp2_; + Test* _tmp3_; + GVariant* request_result = NULL; + GDBusConnection* _tmp4_; + GVariant* _tmp5_; + GVariant* _tmp6_; + GVariant* _tmp7_; + GVariant* _tmp8_; + GVariant* _tmp9_; + GVariant* _tmp10_; + GVariant* _tmp11_; + guint _tmp12_; + GPid client_pid = 0; + gchar* _tmp13_; + gchar** _tmp14_; + gchar** _tmp15_; + gint _tmp15__length1; + GPid _tmp16_ = 0; + GMainLoop* _tmp17_; + GMainLoop* _tmp18_; + GError* _inner_error0_ = NULL; + _tmp0_ = g_bus_get_sync (G_BUS_TYPE_SESSION, NULL, &_inner_error0_); + conn = _tmp0_; + if (G_UNLIKELY (_inner_error0_ != NULL)) { + g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error0_->message, g_quark_to_string (_inner_error0_->domain), _inner_error0_->code); + g_clear_error (&_inner_error0_); + return; + } + _tmp1_ = conn; + _tmp2_ = test_new (); + _tmp3_ = _tmp2_; + test_register_object (_tmp3_, _tmp1_, "/org/example/test", &_inner_error0_); + _g_object_unref0 (_tmp3_); + if (G_UNLIKELY (_inner_error0_ != NULL)) { + _g_object_unref0 (conn); + g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error0_->message, g_quark_to_string (_inner_error0_->domain), _inner_error0_->code); + g_clear_error (&_inner_error0_); + return; + } + _tmp4_ = conn; + _tmp5_ = g_variant_new ("(su)", "org.example.Test", 0x4, NULL); + g_variant_ref_sink (_tmp5_); + _tmp6_ = _tmp5_; + _tmp7_ = g_dbus_connection_call_sync (_tmp4_, "org.freedesktop.DBus", "/org/freedesktop/DBus", "org.freedesktop.DBus", "RequestName", _tmp6_, NULL, 0, -1, NULL, &_inner_error0_); + _tmp8_ = _tmp7_; + _g_variant_unref0 (_tmp6_); + request_result = _tmp8_; + if (G_UNLIKELY (_inner_error0_ != NULL)) { + _g_object_unref0 (conn); + g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error0_->message, g_quark_to_string (_inner_error0_->domain), _inner_error0_->code); + g_clear_error (&_inner_error0_); + return; + } + _tmp9_ = request_result; + _tmp10_ = g_variant_get_child_value (_tmp9_, (gsize) 0); + _tmp11_ = _tmp10_; + _tmp12_ = _variant_get1 (_tmp11_); + _vala_assert (_tmp12_ == ((guint) 1), "(uint) request_result.get_child_value (0) == 1"); + _g_variant_unref0 (_tmp11_); + _tmp13_ = g_strdup ("dbus_async_errors_client"); + _tmp14_ = g_new0 (gchar*, 1 + 1); + _tmp14_[0] = _tmp13_; + _tmp15_ = _tmp14_; + _tmp15__length1 = 1; + g_spawn_async (NULL, _tmp15_, NULL, G_SPAWN_DO_NOT_REAP_CHILD, NULL, NULL, &_tmp16_, &_inner_error0_); + client_pid = _tmp16_; + _tmp15_ = (_vala_array_free (_tmp15_, _tmp15__length1, (GDestroyNotify) g_free), NULL); + if (G_UNLIKELY (_inner_error0_ != NULL)) { + _g_variant_unref0 (request_result); + _g_object_unref0 (conn); + g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error0_->message, g_quark_to_string (_inner_error0_->domain), _inner_error0_->code); + g_clear_error (&_inner_error0_); + return; + } + g_child_watch_add_full (G_PRIORITY_DEFAULT_IDLE, client_pid, _client_exit_gchild_watch_func, NULL, NULL); + _tmp17_ = g_main_loop_new (NULL, FALSE); + _g_main_loop_unref0 (main_loop); + main_loop = _tmp17_; + _tmp18_ = main_loop; + g_main_loop_run (_tmp18_); + _g_variant_unref0 (request_result); + _g_object_unref0 (conn); +} + +int +main (int argc, + char ** argv) +{ + _vala_main (); + return 0; +} + +static void +_vala_array_destroy (gpointer array, + gssize array_length, + GDestroyNotify destroy_func) +{ + if ((array != NULL) && (destroy_func != NULL)) { + gssize i; + for (i = 0; i < array_length; i = i + 1) { + if (((gpointer*) array)[i] != NULL) { + destroy_func (((gpointer*) array)[i]); + } + } + } +} + +static void +_vala_array_free (gpointer array, + gssize array_length, + GDestroyNotify destroy_func) +{ + _vala_array_destroy (array, array_length, destroy_func); + g_free (array); +} + diff --git a/tests/dbus/async-no-reply_client.c-expected b/tests/dbus/async-no-reply_client.c-expected new file mode 100644 index 000000000..abb397e7d --- /dev/null +++ b/tests/dbus/async-no-reply_client.c-expected @@ -0,0 +1,1012 @@ +/* dbus_async_no_reply_client.c generated by valac, the Vala compiler + * generated from dbus_async_no_reply_client.vala, do not modify */ + +#include <glib-object.h> +#include <gio/gio.h> +#include <stdlib.h> +#include <string.h> +#include <glib.h> + +#if !defined(VALA_EXTERN) +#if defined(_MSC_VER) +#define VALA_EXTERN __declspec(dllexport) extern +#elif __GNUC__ >= 4 +#define VALA_EXTERN __attribute__((visibility("default"))) extern +#else +#define VALA_EXTERN extern +#endif +#endif + +#define TYPE_TEST (test_get_type ()) +#define TEST(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TYPE_TEST, Test)) +#define IS_TEST(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TYPE_TEST)) +#define TEST_GET_INTERFACE(obj) (G_TYPE_INSTANCE_GET_INTERFACE ((obj), TYPE_TEST, TestIface)) + +typedef struct _Test Test; +typedef struct _TestIface TestIface; + +#define TYPE_TEST_PROXY (test_proxy_get_type ()) +typedef GDBusProxy TestProxy; +typedef GDBusProxyClass TestProxyClass; +typedef struct _TestListMessagesReadyData TestListMessagesReadyData; +typedef struct _TestPostMessageReadyData TestPostMessageReadyData; +#define _g_free0(var) (var = (g_free (var), NULL)) +typedef struct _Block1Data Block1Data; +#define _g_async_queue_unref0(var) ((var == NULL) ? NULL : (var = (g_async_queue_unref (var), NULL))) +#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL))) +typedef struct _RunData RunData; +#define _g_main_loop_unref0(var) ((var == NULL) ? NULL : (var = (g_main_loop_unref (var), NULL))) +#define _vala_assert(expr, msg) if G_LIKELY (expr) ; else g_assertion_message_expr (G_LOG_DOMAIN, __FILE__, __LINE__, G_STRFUNC, msg); +#define _vala_return_if_fail(expr, msg) if G_LIKELY (expr) ; else { g_return_if_fail_warning (G_LOG_DOMAIN, G_STRFUNC, msg); return; } +#define _vala_return_val_if_fail(expr, msg, val) if G_LIKELY (expr) ; else { g_return_if_fail_warning (G_LOG_DOMAIN, G_STRFUNC, msg); return val; } +#define _vala_warn_if_fail(expr, msg) if G_LIKELY (expr) ; else g_warn_message (G_LOG_DOMAIN, __FILE__, __LINE__, G_STRFUNC, msg); + +struct _TestIface { + GTypeInterface parent_iface; + void (*list_messages) (Test* self, GAsyncReadyCallback _callback_, gpointer _user_data_); + gchar** (*list_messages_finish) (Test* self, GAsyncResult* _res_, gint* result_length1, GError** error); + void (*post_message) (Test* self, const gchar* message, GAsyncReadyCallback _callback_, gpointer _user_data_); + void (*post_message_finish) (Test* self, GAsyncResult* _res_, GError** error); +}; + +struct _TestListMessagesReadyData { + GDBusMethodInvocation* _invocation_; +}; + +struct _TestPostMessageReadyData { + GDBusMethodInvocation* _invocation_; + gchar* message; +}; + +struct _Block1Data { + int _ref_count_; + GAsyncQueue* events; + gpointer _async_data_; +}; + +struct _RunData { + int _state_; + GObject* _source_object_; + GAsyncResult* _res_; + GTask* _async_result; + Block1Data* _data1_; + Test* test; + Test* _tmp0_; + GAsyncQueue* _tmp1_; + GDBusConnection* connection; + Test* _tmp2_; + GDBusConnection* _tmp3_; + GDBusConnection* _tmp4_; + GDBusConnection* _tmp5_; + gchar** messages; + Test* _tmp6_; + gint _tmp7_; + gchar** _tmp8_; + gint messages_length1; + gint _messages_size_; + gchar** _tmp9_; + gint _tmp9__length1; + Test* _tmp10_; + GAsyncQueue* _tmp11_; + gpointer _tmp12_; + gchar* _tmp13_; + GAsyncQueue* _tmp14_; + gpointer _tmp15_; + gchar* _tmp16_; + Test* _tmp17_; + GAsyncQueue* _tmp18_; + gpointer _tmp19_; + gchar* _tmp20_; + GAsyncQueue* _tmp21_; + gpointer _tmp22_; + gchar* _tmp23_; + gchar** _tmp24_; + Test* _tmp25_; + gint _tmp26_; + gchar** _tmp27_; + gint _tmp24__length1; + gint __tmp24__size_; + gchar** _tmp28_; + gint _tmp28__length1; + gchar** _tmp29_; + gint _tmp29__length1; + gchar** _tmp30_; + gint _tmp30__length1; + const gchar* _tmp31_; + gchar** _tmp32_; + gint _tmp32__length1; + const gchar* _tmp33_; + GMainLoop* _tmp34_; + GError* _inner_error0_; +}; + +VALA_EXTERN GMainLoop* main_loop; +GMainLoop* main_loop = NULL; + +VALA_EXTERN GType test_proxy_get_type (void) G_GNUC_CONST ; +VALA_EXTERN guint test_register_object (void* object, + GDBusConnection* connection, + const gchar* path, + GError** error); +VALA_EXTERN GType test_get_type (void) G_GNUC_CONST ; +VALA_EXTERN void test_list_messages (Test* self, + GAsyncReadyCallback _callback_, + gpointer _user_data_); +VALA_EXTERN gchar** test_list_messages_finish (Test* self, + GAsyncResult* _res_, + gint* result_length1, + GError** error); +VALA_EXTERN void test_post_message (Test* self, + const gchar* message, + GAsyncReadyCallback _callback_, + gpointer _user_data_); +VALA_EXTERN void test_post_message_finish (Test* self, + GAsyncResult* _res_, + GError** error); +static GType test_get_type_once (void); +static void test_proxy_g_signal (GDBusProxy* proxy, + const gchar* sender_name, + const gchar* signal_name, + GVariant* parameters); +static void _vala_g_async_ready_callback (GObject *source_object, + GAsyncResult *res, + void *user_data); +static void test_proxy_list_messages_async (Test* self, + GAsyncReadyCallback _callback_, + gpointer _user_data_); +static gchar** test_proxy_list_messages_finish (Test* self, + GAsyncResult* _res_, + gint* result_length1, + GError** error); +static void test_proxy_post_message_async (Test* self, + const gchar* message, + GAsyncReadyCallback _callback_, + gpointer _user_data_); +static void test_proxy_post_message_finish (Test* self, + GAsyncResult* _res_, + GError** error); +static void test_proxy_test_interface_init (TestIface* iface); +static void _dbus_test_list_messages (Test* self, + GVariant* _parameters_, + GDBusMethodInvocation* invocation); +static void _dbus_test_list_messages_ready (GObject * source_object, + GAsyncResult * _res_, + gpointer _user_data_); +static void _dbus_test_post_message (Test* self, + GVariant* _parameters_, + GDBusMethodInvocation* invocation); +static void _dbus_test_post_message_ready (GObject * source_object, + GAsyncResult * _res_, + gpointer _user_data_); +static void test_dbus_interface_method_call (GDBusConnection* connection, + const gchar* sender, + const gchar* object_path, + const gchar* interface_name, + const gchar* method_name, + GVariant* parameters, + GDBusMethodInvocation* invocation, + gpointer user_data); +static GVariant* test_dbus_interface_get_property (GDBusConnection* connection, + const gchar* sender, + const gchar* object_path, + const gchar* interface_name, + const gchar* property_name, + GError** error, + gpointer user_data); +static gboolean test_dbus_interface_set_property (GDBusConnection* connection, + const gchar* sender, + const gchar* object_path, + const gchar* interface_name, + const gchar* property_name, + GVariant* value, + GError** error, + gpointer user_data); +static void _test_unregister_object (gpointer user_data); +static void run_data_free (gpointer _data); +VALA_EXTERN void run (GAsyncReadyCallback _callback_, + gpointer _user_data_); +VALA_EXTERN void run_finish (GAsyncResult* _res_); +static gboolean run_co (RunData* _data_); +static Block1Data* block1_data_ref (Block1Data* _data1_); +static void block1_data_unref (void * _userdata_); +static void run_ready (GObject* source_object, + GAsyncResult* _res_, + gpointer _user_data_); +static void _g_free0_ (gpointer var); +static GDBusMessage* __lambda4_ (Block1Data* _data1_, + GDBusConnection* conn, + GDBusMessage* message, + gboolean incoming); +static GDBusMessage* ___lambda4__gd_bus_message_filter_function (GDBusConnection* connection, + GDBusMessage* message, + gboolean incoming, + gpointer self); +static void _vala_main (void); +static void _vala_array_destroy (gpointer array, + gssize array_length, + GDestroyNotify destroy_func); +static void _vala_array_free (gpointer array, + gssize array_length, + GDestroyNotify destroy_func); + +static const GDBusArgInfo _test_dbus_arg_info_list_messages_result = {-1, "result", "as", NULL}; +static const GDBusArgInfo * const _test_dbus_arg_info_list_messages_in[] = {NULL}; +static const GDBusArgInfo * const _test_dbus_arg_info_list_messages_out[] = {&_test_dbus_arg_info_list_messages_result, NULL}; +static const GDBusMethodInfo _test_dbus_method_info_list_messages = {-1, "ListMessages", (GDBusArgInfo **) (&_test_dbus_arg_info_list_messages_in), (GDBusArgInfo **) (&_test_dbus_arg_info_list_messages_out), NULL}; +static const GDBusArgInfo _test_dbus_arg_info_post_message_message = {-1, "message", "s", NULL}; +static const GDBusArgInfo * const _test_dbus_arg_info_post_message_in[] = {&_test_dbus_arg_info_post_message_message, NULL}; +static const GDBusArgInfo * const _test_dbus_arg_info_post_message_out[] = {NULL}; +static const GDBusMethodInfo _test_dbus_method_info_post_message = {-1, "PostMessage", (GDBusArgInfo **) (&_test_dbus_arg_info_post_message_in), (GDBusArgInfo **) (&_test_dbus_arg_info_post_message_out), NULL}; +static const GDBusMethodInfo * const _test_dbus_method_info[] = {&_test_dbus_method_info_list_messages, &_test_dbus_method_info_post_message, NULL}; +static const GDBusSignalInfo * const _test_dbus_signal_info[] = {NULL}; +static const GDBusPropertyInfo * const _test_dbus_property_info[] = {NULL}; +static const GDBusInterfaceInfo _test_dbus_interface_info = {-1, "org.example.Test", (GDBusMethodInfo **) (&_test_dbus_method_info), (GDBusSignalInfo **) (&_test_dbus_signal_info), (GDBusPropertyInfo **) (&_test_dbus_property_info), NULL}; +static const GDBusInterfaceVTable _test_dbus_interface_vtable = {test_dbus_interface_method_call, test_dbus_interface_get_property, test_dbus_interface_set_property}; + +void +test_list_messages (Test* self, + GAsyncReadyCallback _callback_, + gpointer _user_data_) +{ + TestIface* _iface_; + _iface_ = TEST_GET_INTERFACE (self); + if (_iface_->list_messages) { + _iface_->list_messages (self, _callback_, _user_data_); + } +} + +gchar** +test_list_messages_finish (Test* self, + GAsyncResult* _res_, + gint* result_length1, + GError** error) +{ + TestIface* _iface_; + _iface_ = TEST_GET_INTERFACE (self); + if (_iface_->list_messages_finish) { + return _iface_->list_messages_finish (self, _res_, result_length1, error); + } + return NULL; +} + +void +test_post_message (Test* self, + const gchar* message, + GAsyncReadyCallback _callback_, + gpointer _user_data_) +{ + TestIface* _iface_; + _iface_ = TEST_GET_INTERFACE (self); + if (_iface_->post_message) { + _iface_->post_message (self, message, _callback_, _user_data_); + } +} + +void +test_post_message_finish (Test* self, + GAsyncResult* _res_, + GError** error) +{ + TestIface* _iface_; + _iface_ = TEST_GET_INTERFACE (self); + if (_iface_->post_message_finish) { + _iface_->post_message_finish (self, _res_, error); + } +} + +static void +test_default_init (TestIface * iface, + gpointer iface_data) +{ +} + +static GType +test_get_type_once (void) +{ + static const GTypeInfo g_define_type_info = { sizeof (TestIface), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) test_default_init, (GClassFinalizeFunc) NULL, NULL, 0, 0, (GInstanceInitFunc) NULL, NULL }; + GType test_type_id; + test_type_id = g_type_register_static (G_TYPE_INTERFACE, "Test", &g_define_type_info, 0); + g_type_interface_add_prerequisite (test_type_id, G_TYPE_OBJECT); + g_type_set_qdata (test_type_id, g_quark_from_static_string ("vala-dbus-proxy-type"), (void*) test_proxy_get_type); + g_type_set_qdata (test_type_id, g_quark_from_static_string ("vala-dbus-interface-name"), "org.example.Test"); + g_type_set_qdata (test_type_id, g_quark_from_static_string ("vala-dbus-interface-info"), (void*) (&_test_dbus_interface_info)); + g_type_set_qdata (test_type_id, g_quark_from_static_string ("vala-dbus-register-object"), (void*) test_register_object); + return test_type_id; +} + +GType +test_get_type (void) +{ + static volatile gsize test_type_id__volatile = 0; + if (g_once_init_enter (&test_type_id__volatile)) { + GType test_type_id; + test_type_id = test_get_type_once (); + g_once_init_leave (&test_type_id__volatile, test_type_id); + } + return test_type_id__volatile; +} + +G_DEFINE_TYPE_EXTENDED (TestProxy, test_proxy, G_TYPE_DBUS_PROXY, 0, G_IMPLEMENT_INTERFACE (TYPE_TEST, test_proxy_test_interface_init) ) +static void +test_proxy_class_init (TestProxyClass* klass) +{ + G_DBUS_PROXY_CLASS (klass)->g_signal = test_proxy_g_signal; +} + +static void +test_proxy_g_signal (GDBusProxy* proxy, + const gchar* sender_name, + const gchar* signal_name, + GVariant* parameters) +{ +} + +static void +test_proxy_init (TestProxy* self) +{ + g_dbus_proxy_set_interface_info (G_DBUS_PROXY (self), (GDBusInterfaceInfo *) (&_test_dbus_interface_info)); +} + +static void +_vala_g_async_ready_callback (GObject *source_object, + GAsyncResult *res, + void *user_data) +{ + g_task_return_pointer (user_data, g_object_ref (res), g_object_unref); + g_object_unref (user_data); +} + +static void +test_proxy_list_messages_async (Test* self, + GAsyncReadyCallback _callback_, + gpointer _user_data_) +{ + GDBusMessage *_message; + GVariant *_arguments; + GVariantBuilder _arguments_builder; + G_IO_ERROR; + _message = g_dbus_message_new_method_call (g_dbus_proxy_get_name ((GDBusProxy *) self), g_dbus_proxy_get_object_path ((GDBusProxy *) self), "org.example.Test", "ListMessages"); + g_variant_builder_init (&_arguments_builder, G_VARIANT_TYPE_TUPLE); + _arguments = g_variant_builder_end (&_arguments_builder); + g_dbus_message_set_body (_message, _arguments); + if (_callback_ != NULL) { + g_dbus_connection_send_message_with_reply (g_dbus_proxy_get_connection ((GDBusProxy *) self), _message, G_DBUS_SEND_MESSAGE_FLAGS_NONE, g_dbus_proxy_get_default_timeout ((GDBusProxy *) self), NULL, NULL, _vala_g_async_ready_callback, g_task_new ((GObject *) self, NULL, _callback_, _user_data_)); + } else { + g_dbus_message_set_flags (_message, G_DBUS_MESSAGE_FLAGS_NO_REPLY_EXPECTED); + g_dbus_connection_send_message (g_dbus_proxy_get_connection ((GDBusProxy *) self), _message, G_DBUS_SEND_MESSAGE_FLAGS_NONE, NULL, NULL); + } + g_object_unref (_message); +} + +static gchar** +test_proxy_list_messages_finish (Test* self, + GAsyncResult* _res_, + gint* result_length1, + GError** error) +{ + GAsyncResult *_inner_res; + GDBusMessage *_reply_message; + GVariant *_reply; + GVariantIter _reply_iter; + gchar** _result = NULL; + gint _result_length1; + GVariant* _tmp0_; + gchar** _tmp1_; + gint _tmp1__length; + gint _tmp1__size; + gint _tmp1__length1; + GVariantIter _tmp2_; + GVariant* _tmp3_; + _inner_res = g_task_propagate_pointer ((GTask *) _res_, NULL); + _reply_message = g_dbus_connection_send_message_with_reply_finish (g_dbus_proxy_get_connection ((GDBusProxy *) self), _inner_res, error); + g_object_unref (_inner_res); + if (!_reply_message) { + return NULL; + } + if (g_dbus_message_to_gerror (_reply_message, error)) { + g_object_unref (_reply_message); + return NULL; + } + _reply = g_dbus_message_get_body (_reply_message); + g_variant_iter_init (&_reply_iter, _reply); + _result_length1 = 0; + _tmp0_ = g_variant_iter_next_value (&_reply_iter); + _tmp1_ = g_new (gchar*, 5); + _tmp1__length = 0; + _tmp1__size = 4; + _tmp1__length1 = 0; + g_variant_iter_init (&_tmp2_, _tmp0_); + for (; (_tmp3_ = g_variant_iter_next_value (&_tmp2_)) != NULL; _tmp1__length1++) { + if (_tmp1__size == _tmp1__length) { + _tmp1__size = 2 * _tmp1__size; + _tmp1_ = g_renew (gchar*, _tmp1_, _tmp1__size + 1); + } + _tmp1_[_tmp1__length++] = g_variant_dup_string (_tmp3_, NULL); + g_variant_unref (_tmp3_); + } + _result_length1 = _tmp1__length1; + _tmp1_[_tmp1__length] = NULL; + _result = _tmp1_; + g_variant_unref (_tmp0_); + *result_length1 = _result_length1; + g_object_unref (_reply_message); + return _result; +} + +static void +test_proxy_post_message_async (Test* self, + const gchar* message, + GAsyncReadyCallback _callback_, + gpointer _user_data_) +{ + GDBusMessage *_message; + GVariant *_arguments; + GVariantBuilder _arguments_builder; + G_IO_ERROR; + _message = g_dbus_message_new_method_call (g_dbus_proxy_get_name ((GDBusProxy *) self), g_dbus_proxy_get_object_path ((GDBusProxy *) self), "org.example.Test", "PostMessage"); + g_variant_builder_init (&_arguments_builder, G_VARIANT_TYPE_TUPLE); + g_variant_builder_add_value (&_arguments_builder, g_variant_new_string (message)); + _arguments = g_variant_builder_end (&_arguments_builder); + g_dbus_message_set_body (_message, _arguments); + if (_callback_ != NULL) { + g_dbus_connection_send_message_with_reply (g_dbus_proxy_get_connection ((GDBusProxy *) self), _message, G_DBUS_SEND_MESSAGE_FLAGS_NONE, g_dbus_proxy_get_default_timeout ((GDBusProxy *) self), NULL, NULL, _vala_g_async_ready_callback, g_task_new ((GObject *) self, NULL, _callback_, _user_data_)); + } else { + g_dbus_message_set_flags (_message, G_DBUS_MESSAGE_FLAGS_NO_REPLY_EXPECTED); + g_dbus_connection_send_message (g_dbus_proxy_get_connection ((GDBusProxy *) self), _message, G_DBUS_SEND_MESSAGE_FLAGS_NONE, NULL, NULL); + } + g_object_unref (_message); +} + +static void +test_proxy_post_message_finish (Test* self, + GAsyncResult* _res_, + GError** error) +{ + GAsyncResult *_inner_res; + GDBusMessage *_reply_message; + _inner_res = g_task_propagate_pointer ((GTask *) _res_, NULL); + _reply_message = g_dbus_connection_send_message_with_reply_finish (g_dbus_proxy_get_connection ((GDBusProxy *) self), _inner_res, error); + g_object_unref (_inner_res); + if (!_reply_message) { + return; + } + if (g_dbus_message_to_gerror (_reply_message, error)) { + g_object_unref (_reply_message); + return; + } + g_object_unref (_reply_message); +} + +static void +test_proxy_test_interface_init (TestIface* iface) +{ + iface->list_messages = test_proxy_list_messages_async; + iface->list_messages_finish = test_proxy_list_messages_finish; + iface->post_message = test_proxy_post_message_async; + iface->post_message_finish = test_proxy_post_message_finish; +} + +static void +_dbus_test_list_messages (Test* self, + GVariant* _parameters_, + GDBusMethodInvocation* invocation) +{ + GVariantIter _arguments_iter; + TestListMessagesReadyData* _ready_data; + g_variant_iter_init (&_arguments_iter, _parameters_); + _ready_data = g_slice_new0 (TestListMessagesReadyData); + _ready_data->_invocation_ = invocation; + test_list_messages (self, (GAsyncReadyCallback) _dbus_test_list_messages_ready, _ready_data); +} + +static void +_dbus_test_list_messages_ready (GObject * source_object, + GAsyncResult * _res_, + gpointer _user_data_) +{ + TestListMessagesReadyData* _ready_data; + GDBusMethodInvocation* invocation; + GError* error = NULL; + GDBusMessage* _reply_message = NULL; + GVariant* _reply; + GVariantBuilder _reply_builder; + gchar** result; + gint result_length1 = 0; + gchar** _tmp4_; + GVariantBuilder _tmp5_; + gint _tmp6_; + _ready_data = _user_data_; + invocation = _ready_data->_invocation_; + result = test_list_messages_finish ((Test*) source_object, _res_, &result_length1, &error); + if (error) { + g_dbus_method_invocation_return_gerror (invocation, error); + g_error_free (error); + goto _error; + } + _reply_message = g_dbus_message_new_method_reply (g_dbus_method_invocation_get_message (invocation)); + g_variant_builder_init (&_reply_builder, G_VARIANT_TYPE_TUPLE); + _tmp4_ = result; + g_variant_builder_init (&_tmp5_, G_VARIANT_TYPE ("as")); + for (_tmp6_ = 0; _tmp6_ < result_length1; _tmp6_++) { + g_variant_builder_add_value (&_tmp5_, g_variant_new_string (*_tmp4_)); + _tmp4_++; + } + g_variant_builder_add_value (&_reply_builder, g_variant_builder_end (&_tmp5_)); + result = (_vala_array_free (result, result_length1, (GDestroyNotify) g_free), NULL); + _reply = g_variant_builder_end (&_reply_builder); + g_dbus_message_set_body (_reply_message, _reply); + g_dbus_connection_send_message (g_dbus_method_invocation_get_connection (invocation), _reply_message, G_DBUS_SEND_MESSAGE_FLAGS_NONE, NULL, NULL); + g_object_unref (invocation); + g_object_unref (_reply_message); + _error: + g_slice_free (TestListMessagesReadyData, _ready_data); +} + +static void +_dbus_test_post_message (Test* self, + GVariant* _parameters_, + GDBusMethodInvocation* invocation) +{ + GVariantIter _arguments_iter; + TestPostMessageReadyData* _ready_data; + GVariant* _tmp7_; + g_variant_iter_init (&_arguments_iter, _parameters_); + _ready_data = g_slice_new0 (TestPostMessageReadyData); + _ready_data->_invocation_ = invocation; + _tmp7_ = g_variant_iter_next_value (&_arguments_iter); + _ready_data->message = g_variant_dup_string (_tmp7_, NULL); + g_variant_unref (_tmp7_); + test_post_message (self, _ready_data->message, (GAsyncReadyCallback) _dbus_test_post_message_ready, _ready_data); + _error: + ; +} + +static void +_dbus_test_post_message_ready (GObject * source_object, + GAsyncResult * _res_, + gpointer _user_data_) +{ + TestPostMessageReadyData* _ready_data; + GDBusMethodInvocation* invocation; + GError* error = NULL; + GDBusMessage* _reply_message = NULL; + GVariant* _reply; + GVariantBuilder _reply_builder; + _ready_data = _user_data_; + invocation = _ready_data->_invocation_; + test_post_message_finish ((Test*) source_object, _res_, &error); + if (error) { + g_dbus_method_invocation_return_gerror (invocation, error); + g_error_free (error); + goto _error; + } + _reply_message = g_dbus_message_new_method_reply (g_dbus_method_invocation_get_message (invocation)); + g_variant_builder_init (&_reply_builder, G_VARIANT_TYPE_TUPLE); + _reply = g_variant_builder_end (&_reply_builder); + g_dbus_message_set_body (_reply_message, _reply); + g_dbus_connection_send_message (g_dbus_method_invocation_get_connection (invocation), _reply_message, G_DBUS_SEND_MESSAGE_FLAGS_NONE, NULL, NULL); + g_object_unref (invocation); + g_object_unref (_reply_message); + _error: + _g_free0 (_ready_data->message); + g_slice_free (TestPostMessageReadyData, _ready_data); +} + +static void +test_dbus_interface_method_call (GDBusConnection* connection, + const gchar* sender, + const gchar* object_path, + const gchar* interface_name, + const gchar* method_name, + GVariant* parameters, + GDBusMethodInvocation* invocation, + gpointer user_data) +{ + gpointer* data; + gpointer object; + data = user_data; + object = data[0]; + if (strcmp (method_name, "ListMessages") == 0) { + _dbus_test_list_messages (object, parameters, invocation); + } else if (strcmp (method_name, "PostMessage") == 0) { + _dbus_test_post_message (object, parameters, invocation); + } else { + g_object_unref (invocation); + } +} + +static GVariant* +test_dbus_interface_get_property (GDBusConnection* connection, + const gchar* sender, + const gchar* object_path, + const gchar* interface_name, + const gchar* property_name, + GError** error, + gpointer user_data) +{ + gpointer* data; + gpointer object; + data = user_data; + object = data[0]; + return NULL; +} + +static gboolean +test_dbus_interface_set_property (GDBusConnection* connection, + const gchar* sender, + const gchar* object_path, + const gchar* interface_name, + const gchar* property_name, + GVariant* value, + GError** error, + gpointer user_data) +{ + gpointer* data; + gpointer object; + data = user_data; + object = data[0]; + return FALSE; +} + +guint +test_register_object (gpointer object, + GDBusConnection* connection, + const gchar* path, + GError** error) +{ + guint result; + gpointer *data; + data = g_new (gpointer, 3); + data[0] = g_object_ref (object); + data[1] = g_object_ref (connection); + data[2] = g_strdup (path); + result = g_dbus_connection_register_object (connection, path, (GDBusInterfaceInfo *) (&_test_dbus_interface_info), &_test_dbus_interface_vtable, data, _test_unregister_object, error); + if (!result) { + return 0; + } + return result; +} + +static void +_test_unregister_object (gpointer user_data) +{ + gpointer* data; + data = user_data; + g_object_unref (data[0]); + g_object_unref (data[1]); + g_free (data[2]); + g_free (data); +} + +static void +run_data_free (gpointer _data) +{ + RunData* _data_; + _data_ = _data; + g_slice_free (RunData, _data_); +} + +void +run (GAsyncReadyCallback _callback_, + gpointer _user_data_) +{ + RunData* _data_; + _data_ = g_slice_new0 (RunData); + _data_->_async_result = g_task_new (NULL, NULL, _callback_, _user_data_); + g_task_set_task_data (_data_->_async_result, _data_, run_data_free); + run_co (_data_); +} + +void +run_finish (GAsyncResult* _res_) +{ + RunData* _data_; + _data_ = g_task_propagate_pointer (G_TASK (_res_), NULL); +} + +static Block1Data* +block1_data_ref (Block1Data* _data1_) +{ + g_atomic_int_inc (&_data1_->_ref_count_); + return _data1_; +} + +static void +block1_data_unref (void * _userdata_) +{ + Block1Data* _data1_; + _data1_ = (Block1Data*) _userdata_; + if (g_atomic_int_dec_and_test (&_data1_->_ref_count_)) { + _g_async_queue_unref0 (_data1_->events); + g_slice_free (Block1Data, _data1_); + } +} + +static void +run_ready (GObject* source_object, + GAsyncResult* _res_, + gpointer _user_data_) +{ + RunData* _data_; + _data_ = _user_data_; + _data_->_source_object_ = source_object; + _data_->_res_ = _res_; + run_co (_data_); +} + +static void +_g_free0_ (gpointer var) +{ + var = (g_free (var), NULL); +} + +static gpointer +_g_object_ref0 (gpointer self) +{ + return self ? g_object_ref (self) : NULL; +} + +static GDBusMessage* +__lambda4_ (Block1Data* _data1_, + GDBusConnection* conn, + GDBusMessage* message, + gboolean incoming) +{ + gboolean _tmp0_ = FALSE; + const gchar* _tmp1_; + GDBusMessage* _tmp6_; + GDBusMessage* result = NULL; + g_return_val_if_fail (G_TYPE_CHECK_INSTANCE_TYPE (conn, g_dbus_connection_get_type ()), NULL); + g_return_val_if_fail (G_TYPE_CHECK_INSTANCE_TYPE (message, g_dbus_message_get_type ()), NULL); + _tmp1_ = g_dbus_message_get_interface (message); + if (g_strcmp0 (_tmp1_, "org.example.Test") == 0) { + const gchar* _tmp2_; + _tmp2_ = g_dbus_message_get_member (message); + _tmp0_ = g_strcmp0 (_tmp2_, "ListMessages") != 0; + } else { + _tmp0_ = FALSE; + } + if (_tmp0_) { + switch (g_dbus_message_get_message_type (message)) { + case G_DBUS_MESSAGE_TYPE_METHOD_CALL: + { + GAsyncQueue* _tmp3_; + GFlagsValue* _tmp4_; + gchar* _tmp5_; + _tmp3_ = _data1_->events; + _tmp4_ = g_flags_get_first_value (g_type_class_ref (g_dbus_message_flags_get_type ()), g_dbus_message_get_flags (message)); + _tmp5_ = g_strdup ((_tmp4_ != NULL) ? _tmp4_->value_name : NULL); + g_async_queue_push (_tmp3_, _tmp5_); + break; + } + default: + { + g_assert_not_reached (); + } + } + } + _tmp6_ = _g_object_ref0 (message); + result = _tmp6_; + _g_object_unref0 (message); + return result; +} + +static GDBusMessage* +___lambda4__gd_bus_message_filter_function (GDBusConnection* connection, + GDBusMessage* message, + gboolean incoming, + gpointer self) +{ + GDBusMessage* result; + result = __lambda4_ (self, connection, message, incoming); + return result; +} + +static gboolean +run_co (RunData* _data_) +{ + switch (_data_->_state_) { + case 0: + goto _state_0; + case 1: + goto _state_1; + case 2: + goto _state_2; + case 3: + goto _state_3; + case 4: + goto _state_4; + default: + g_assert_not_reached (); + } + _state_0: + _data_->_data1_ = g_slice_new0 (Block1Data); + _data_->_data1_->_ref_count_ = 1; + _data_->_data1_->_async_data_ = _data_; + _data_->_state_ = 1; + g_async_initable_new_async (TYPE_TEST_PROXY, 0, NULL, run_ready, _data_, "g-flags", 0, "g-name", "org.example.Test", "g-bus-type", G_BUS_TYPE_SESSION, "g-object-path", "/org/example/Test", "g-interface-name", "org.example.Test", NULL); + return FALSE; + _state_1: + _data_->_tmp0_ = (Test*) g_async_initable_new_finish ((GAsyncInitable *) _data_->_source_object_, _data_->_res_, &_data_->_inner_error0_); + _data_->test = (Test*) _data_->_tmp0_; + if (G_UNLIKELY (_data_->_inner_error0_ != NULL)) { + block1_data_unref (_data_->_data1_); + _data_->_data1_ = NULL; + g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _data_->_inner_error0_->message, g_quark_to_string (_data_->_inner_error0_->domain), _data_->_inner_error0_->code); + g_clear_error (&_data_->_inner_error0_); + g_object_unref (_data_->_async_result); + return FALSE; + } + _data_->_tmp1_ = g_async_queue_new_full (_g_free0_); + _data_->_data1_->events = _data_->_tmp1_; + _data_->_tmp2_ = _data_->test; + g_object_get (G_TYPE_CHECK_INSTANCE_CAST (_data_->_tmp2_, g_dbus_proxy_get_type (), GDBusProxy), "g-connection", &_data_->_tmp3_, NULL); + _data_->_tmp4_ = _data_->_tmp3_; + _data_->connection = _data_->_tmp4_; + _data_->_tmp5_ = _data_->connection; + g_dbus_connection_add_filter (_data_->_tmp5_, ___lambda4__gd_bus_message_filter_function, block1_data_ref (_data_->_data1_), block1_data_unref); + _data_->_tmp6_ = _data_->test; + _data_->_tmp7_ = 0; + _data_->_state_ = 2; + test_list_messages (_data_->_tmp6_, run_ready, _data_); + return FALSE; + _state_2: + _data_->_tmp8_ = test_list_messages_finish (_data_->_tmp6_, _data_->_res_, &_data_->_tmp7_, &_data_->_inner_error0_); + _data_->messages = _data_->_tmp8_; + _data_->messages_length1 = _data_->_tmp7_; + _data_->_messages_size_ = _data_->messages_length1; + if (G_UNLIKELY (_data_->_inner_error0_ != NULL)) { + _g_object_unref0 (_data_->connection); + _g_object_unref0 (_data_->test); + block1_data_unref (_data_->_data1_); + _data_->_data1_ = NULL; + g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _data_->_inner_error0_->message, g_quark_to_string (_data_->_inner_error0_->domain), _data_->_inner_error0_->code); + g_clear_error (&_data_->_inner_error0_); + g_object_unref (_data_->_async_result); + return FALSE; + } + _data_->_tmp9_ = _data_->messages; + _data_->_tmp9__length1 = _data_->messages_length1; + _vala_assert (_data_->_tmp9__length1 == 0, "messages.length == 0"); + _data_->_tmp10_ = _data_->test; + _data_->_state_ = 3; + test_post_message (_data_->_tmp10_, "round-trip", run_ready, _data_); + return FALSE; + _state_3: + test_post_message_finish (_data_->_tmp10_, _data_->_res_, &_data_->_inner_error0_); + if (G_UNLIKELY (_data_->_inner_error0_ != NULL)) { + _data_->messages = (_vala_array_free (_data_->messages, _data_->messages_length1, (GDestroyNotify) g_free), NULL); + _g_object_unref0 (_data_->connection); + _g_object_unref0 (_data_->test); + block1_data_unref (_data_->_data1_); + _data_->_data1_ = NULL; + g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _data_->_inner_error0_->message, g_quark_to_string (_data_->_inner_error0_->domain), _data_->_inner_error0_->code); + g_clear_error (&_data_->_inner_error0_); + g_object_unref (_data_->_async_result); + return FALSE; + } + _data_->_tmp11_ = _data_->_data1_->events; + _data_->_tmp12_ = g_async_queue_pop (_data_->_tmp11_); + _data_->_tmp13_ = (gchar*) _data_->_tmp12_; + _vala_assert (g_strcmp0 (_data_->_tmp13_, "G_DBUS_MESSAGE_FLAGS_NONE") == 0, "events.pop () == \"G_DBUS_MESSAGE_FLAGS_NONE\""); + _g_free0 (_data_->_tmp13_); + _data_->_tmp14_ = _data_->_data1_->events; + _data_->_tmp15_ = g_async_queue_try_pop (_data_->_tmp14_); + _data_->_tmp16_ = (gchar*) _data_->_tmp15_; + _vala_assert (_data_->_tmp16_ == NULL, "events.try_pop () == null"); + _g_free0 (_data_->_tmp16_); + _data_->_tmp17_ = _data_->test; + test_post_message (_data_->_tmp17_, "fire-and-forget", NULL, NULL); + _data_->_tmp18_ = _data_->_data1_->events; + _data_->_tmp19_ = g_async_queue_pop (_data_->_tmp18_); + _data_->_tmp20_ = (gchar*) _data_->_tmp19_; + _vala_assert (g_strcmp0 (_data_->_tmp20_, "G_DBUS_MESSAGE_FLAGS_NO_REPLY_EXPECTED") == 0, "events.pop () == \"G_DBUS_MESSAGE_FLAGS_NO_REPLY_EXPECTED\""); + _g_free0 (_data_->_tmp20_); + _data_->_tmp21_ = _data_->_data1_->events; + _data_->_tmp22_ = g_async_queue_try_pop (_data_->_tmp21_); + _data_->_tmp23_ = (gchar*) _data_->_tmp22_; + _vala_assert (_data_->_tmp23_ == NULL, "events.try_pop () == null"); + _g_free0 (_data_->_tmp23_); + _data_->_tmp25_ = _data_->test; + _data_->_tmp26_ = 0; + _data_->_state_ = 4; + test_list_messages (_data_->_tmp25_, run_ready, _data_); + return FALSE; + _state_4: + _data_->_tmp27_ = test_list_messages_finish (_data_->_tmp25_, _data_->_res_, &_data_->_tmp26_, &_data_->_inner_error0_); + _data_->_tmp24_ = _data_->_tmp27_; + _data_->_tmp24__length1 = _data_->_tmp26_; + _data_->__tmp24__size_ = _data_->_tmp24__length1; + if (G_UNLIKELY (_data_->_inner_error0_ != NULL)) { + _data_->messages = (_vala_array_free (_data_->messages, _data_->messages_length1, (GDestroyNotify) g_free), NULL); + _g_object_unref0 (_data_->connection); + _g_object_unref0 (_data_->test); + block1_data_unref (_data_->_data1_); + _data_->_data1_ = NULL; + g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _data_->_inner_error0_->message, g_quark_to_string (_data_->_inner_error0_->domain), _data_->_inner_error0_->code); + g_clear_error (&_data_->_inner_error0_); + g_object_unref (_data_->_async_result); + return FALSE; + } + _data_->_tmp28_ = _data_->_tmp24_; + _data_->_tmp28__length1 = _data_->_tmp24__length1; + _data_->_tmp24_ = NULL; + _data_->_tmp24__length1 = 0; + _data_->messages = (_vala_array_free (_data_->messages, _data_->messages_length1, (GDestroyNotify) g_free), NULL); + _data_->messages = _data_->_tmp28_; + _data_->messages_length1 = _data_->_tmp28__length1; + _data_->_messages_size_ = _data_->messages_length1; + _data_->_tmp29_ = _data_->messages; + _data_->_tmp29__length1 = _data_->messages_length1; + _vala_assert (_data_->_tmp29__length1 == 2, "messages.length == 2"); + _data_->_tmp30_ = _data_->messages; + _data_->_tmp30__length1 = _data_->messages_length1; + _data_->_tmp31_ = _data_->_tmp30_[0]; + _vala_assert (g_strcmp0 (_data_->_tmp31_, "round-trip") == 0, "messages[0] == \"round-trip\""); + _data_->_tmp32_ = _data_->messages; + _data_->_tmp32__length1 = _data_->messages_length1; + _data_->_tmp33_ = _data_->_tmp32_[1]; + _vala_assert (g_strcmp0 (_data_->_tmp33_, "fire-and-forget") == 0, "messages[1] == \"fire-and-forget\""); + _data_->_tmp34_ = main_loop; + g_main_loop_quit (_data_->_tmp34_); + _data_->_tmp24_ = (_vala_array_free (_data_->_tmp24_, _data_->_tmp24__length1, (GDestroyNotify) g_free), NULL); + _data_->messages = (_vala_array_free (_data_->messages, _data_->messages_length1, (GDestroyNotify) g_free), NULL); + _g_object_unref0 (_data_->connection); + _g_object_unref0 (_data_->test); + block1_data_unref (_data_->_data1_); + _data_->_data1_ = NULL; + g_task_return_pointer (_data_->_async_result, _data_, NULL); + if (_data_->_state_ != 0) { + while (!g_task_get_completed (_data_->_async_result)) { + g_main_context_iteration (g_task_get_context (_data_->_async_result), TRUE); + } + } + g_object_unref (_data_->_async_result); + return FALSE; +} + +static void +_vala_main (void) +{ + GMainLoop* _tmp0_; + GMainLoop* _tmp1_; + run (NULL, NULL); + _tmp0_ = g_main_loop_new (NULL, FALSE); + _g_main_loop_unref0 (main_loop); + main_loop = _tmp0_; + _tmp1_ = main_loop; + g_main_loop_run (_tmp1_); +} + +int +main (int argc, + char ** argv) +{ + _vala_main (); + return 0; +} + +static void +_vala_array_destroy (gpointer array, + gssize array_length, + GDestroyNotify destroy_func) +{ + if ((array != NULL) && (destroy_func != NULL)) { + gssize i; + for (i = 0; i < array_length; i = i + 1) { + if (((gpointer*) array)[i] != NULL) { + destroy_func (((gpointer*) array)[i]); + } + } + } +} + +static void +_vala_array_free (gpointer array, + gssize array_length, + GDestroyNotify destroy_func) +{ + _vala_array_destroy (array, array_length, destroy_func); + g_free (array); +} + diff --git a/tests/dbus/async-no-reply_server.c-expected b/tests/dbus/async-no-reply_server.c-expected new file mode 100644 index 000000000..f01b56937 --- /dev/null +++ b/tests/dbus/async-no-reply_server.c-expected @@ -0,0 +1,765 @@ +/* dbus_async_no_reply_server.c generated by valac, the Vala compiler + * generated from dbus_async_no_reply_server.vala, do not modify */ + +#include <glib-object.h> +#include <gio/gio.h> +#include <stdlib.h> +#include <string.h> +#include <glib.h> + +#if !defined(VALA_EXTERN) +#if defined(_MSC_VER) +#define VALA_EXTERN __declspec(dllexport) extern +#elif __GNUC__ >= 4 +#define VALA_EXTERN __attribute__((visibility("default"))) extern +#else +#define VALA_EXTERN extern +#endif +#endif + +#define TYPE_TEST (test_get_type ()) +#define TEST(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TYPE_TEST, Test)) +#define TEST_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), TYPE_TEST, TestClass)) +#define IS_TEST(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TYPE_TEST)) +#define IS_TEST_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), TYPE_TEST)) +#define TEST_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), TYPE_TEST, TestClass)) + +typedef struct _Test Test; +typedef struct _TestClass TestClass; +typedef struct _TestPrivate TestPrivate; +enum { + TEST_0_PROPERTY, + TEST_NUM_PROPERTIES +}; +static GParamSpec* test_properties[TEST_NUM_PROPERTIES]; +#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL))) +typedef struct _TestListMessagesData TestListMessagesData; +#define _g_free0(var) (var = (g_free (var), NULL)) +typedef struct _TestPostMessageData TestPostMessageData; +typedef struct _TestListMessagesReadyData TestListMessagesReadyData; +typedef struct _TestPostMessageReadyData TestPostMessageReadyData; +#define _g_variant_unref0(var) ((var == NULL) ? NULL : (var = (g_variant_unref (var), NULL))) +#define _g_main_loop_unref0(var) ((var == NULL) ? NULL : (var = (g_main_loop_unref (var), NULL))) +#define _vala_assert(expr, msg) if G_LIKELY (expr) ; else g_assertion_message_expr (G_LOG_DOMAIN, __FILE__, __LINE__, G_STRFUNC, msg); +#define _vala_return_if_fail(expr, msg) if G_LIKELY (expr) ; else { g_return_if_fail_warning (G_LOG_DOMAIN, G_STRFUNC, msg); return; } +#define _vala_return_val_if_fail(expr, msg, val) if G_LIKELY (expr) ; else { g_return_if_fail_warning (G_LOG_DOMAIN, G_STRFUNC, msg); return val; } +#define _vala_warn_if_fail(expr, msg) if G_LIKELY (expr) ; else g_warn_message (G_LOG_DOMAIN, __FILE__, __LINE__, G_STRFUNC, msg); + +struct _Test { + GObject parent_instance; + TestPrivate * priv; +}; + +struct _TestClass { + GObjectClass parent_class; +}; + +struct _TestPrivate { + gchar** messages; + gint messages_length1; + gint _messages_size_; +}; + +struct _TestListMessagesData { + int _state_; + GObject* _source_object_; + GAsyncResult* _res_; + GTask* _async_result; + Test* self; + gchar** result; + gint result_length1; + gchar** _tmp0_; + gint _tmp0__length1; + gchar** _tmp1_; + gint _tmp1__length1; + gchar** _tmp2_; + gint _tmp2__length1; +}; + +struct _TestPostMessageData { + int _state_; + GObject* _source_object_; + GAsyncResult* _res_; + GTask* _async_result; + Test* self; + gchar* message; + gchar* _tmp0_; +}; + +struct _TestListMessagesReadyData { + GDBusMethodInvocation* _invocation_; +}; + +struct _TestPostMessageReadyData { + GDBusMethodInvocation* _invocation_; + gchar* message; +}; + +static gint Test_private_offset; +static gpointer test_parent_class = NULL; +VALA_EXTERN GMainLoop* main_loop; +GMainLoop* main_loop = NULL; + +VALA_EXTERN GType test_get_type (void) G_GNUC_CONST ; +G_DEFINE_AUTOPTR_CLEANUP_FUNC (Test, g_object_unref) +VALA_EXTERN guint test_register_object (void* object, + GDBusConnection* connection, + const gchar* path, + GError** error); +static void test_list_messages_data_free (gpointer _data); +VALA_EXTERN void test_list_messages (Test* self, + GAsyncReadyCallback _callback_, + gpointer _user_data_); +VALA_EXTERN gchar** test_list_messages_finish (Test* self, + GAsyncResult* _res_, + gint* result_length1); +static gboolean test_list_messages_co (TestListMessagesData* _data_); +static gchar** _vala_array_dup1 (gchar** self, + gssize length); +static void test_post_message_data_free (gpointer _data); +VALA_EXTERN void test_post_message (Test* self, + const gchar* message, + GAsyncReadyCallback _callback_, + gpointer _user_data_); +VALA_EXTERN void test_post_message_finish (Test* self, + GAsyncResult* _res_); +static gboolean test_post_message_co (TestPostMessageData* _data_); +static void _vala_array_add1 (gchar** * array, + gint* length, + gint* size, + gchar* value); +VALA_EXTERN Test* test_new (void); +VALA_EXTERN Test* test_construct (GType object_type); +static void test_finalize (GObject * obj); +static GType test_get_type_once (void); +static void _dbus_test_list_messages (Test* self, + GVariant* _parameters_, + GDBusMethodInvocation* invocation); +static void _dbus_test_list_messages_ready (GObject * source_object, + GAsyncResult * _res_, + gpointer _user_data_); +static void _dbus_test_post_message (Test* self, + GVariant* _parameters_, + GDBusMethodInvocation* invocation); +static void _dbus_test_post_message_ready (GObject * source_object, + GAsyncResult * _res_, + gpointer _user_data_); +static void test_dbus_interface_method_call (GDBusConnection* connection, + const gchar* sender, + const gchar* object_path, + const gchar* interface_name, + const gchar* method_name, + GVariant* parameters, + GDBusMethodInvocation* invocation, + gpointer user_data); +static GVariant* test_dbus_interface_get_property (GDBusConnection* connection, + const gchar* sender, + const gchar* object_path, + const gchar* interface_name, + const gchar* property_name, + GError** error, + gpointer user_data); +static gboolean test_dbus_interface_set_property (GDBusConnection* connection, + const gchar* sender, + const gchar* object_path, + const gchar* interface_name, + const gchar* property_name, + GVariant* value, + GError** error, + gpointer user_data); +static void _test_unregister_object (gpointer user_data); +VALA_EXTERN void client_exit (GPid pid, + gint status); +static void _vala_main (void); +static guint _variant_get1 (GVariant* value); +static void _client_exit_gchild_watch_func (GPid pid, + gint wait_status, + gpointer self); +static void _vala_array_destroy (gpointer array, + gssize array_length, + GDestroyNotify destroy_func); +static void _vala_array_free (gpointer array, + gssize array_length, + GDestroyNotify destroy_func); + +static const GDBusArgInfo _test_dbus_arg_info_list_messages_result = {-1, "result", "as", NULL}; +static const GDBusArgInfo * const _test_dbus_arg_info_list_messages_in[] = {NULL}; +static const GDBusArgInfo * const _test_dbus_arg_info_list_messages_out[] = {&_test_dbus_arg_info_list_messages_result, NULL}; +static const GDBusMethodInfo _test_dbus_method_info_list_messages = {-1, "ListMessages", (GDBusArgInfo **) (&_test_dbus_arg_info_list_messages_in), (GDBusArgInfo **) (&_test_dbus_arg_info_list_messages_out), NULL}; +static const GDBusArgInfo _test_dbus_arg_info_post_message_message = {-1, "message", "s", NULL}; +static const GDBusArgInfo * const _test_dbus_arg_info_post_message_in[] = {&_test_dbus_arg_info_post_message_message, NULL}; +static const GDBusArgInfo * const _test_dbus_arg_info_post_message_out[] = {NULL}; +static const GDBusMethodInfo _test_dbus_method_info_post_message = {-1, "PostMessage", (GDBusArgInfo **) (&_test_dbus_arg_info_post_message_in), (GDBusArgInfo **) (&_test_dbus_arg_info_post_message_out), NULL}; +static const GDBusMethodInfo * const _test_dbus_method_info[] = {&_test_dbus_method_info_list_messages, &_test_dbus_method_info_post_message, NULL}; +static const GDBusSignalInfo * const _test_dbus_signal_info[] = {NULL}; +static const GDBusPropertyInfo * const _test_dbus_property_info[] = {NULL}; +static const GDBusInterfaceInfo _test_dbus_interface_info = {-1, "org.example.Test", (GDBusMethodInfo **) (&_test_dbus_method_info), (GDBusSignalInfo **) (&_test_dbus_signal_info), (GDBusPropertyInfo **) (&_test_dbus_property_info), NULL}; +static const GDBusInterfaceVTable _test_dbus_interface_vtable = {test_dbus_interface_method_call, test_dbus_interface_get_property, test_dbus_interface_set_property}; + +static inline gpointer +test_get_instance_private (Test* self) +{ + return G_STRUCT_MEMBER_P (self, Test_private_offset); +} + +static void +test_list_messages_data_free (gpointer _data) +{ + TestListMessagesData* _data_; + _data_ = _data; + _data_->result = (_vala_array_free (_data_->result, _data_->result_length1, (GDestroyNotify) g_free), NULL); + _g_object_unref0 (_data_->self); + g_slice_free (TestListMessagesData, _data_); +} + +static gpointer +_g_object_ref0 (gpointer self) +{ + return self ? g_object_ref (self) : NULL; +} + +void +test_list_messages (Test* self, + GAsyncReadyCallback _callback_, + gpointer _user_data_) +{ + TestListMessagesData* _data_; + Test* _tmp0_; + g_return_if_fail (IS_TEST (self)); + _data_ = g_slice_new0 (TestListMessagesData); + _data_->_async_result = g_task_new (G_OBJECT (self), NULL, _callback_, _user_data_); + g_task_set_task_data (_data_->_async_result, _data_, test_list_messages_data_free); + _tmp0_ = _g_object_ref0 (self); + _data_->self = _tmp0_; + test_list_messages_co (_data_); +} + +gchar** +test_list_messages_finish (Test* self, + GAsyncResult* _res_, + gint* result_length1) +{ + gchar** result; + TestListMessagesData* _data_; + _data_ = g_task_propagate_pointer (G_TASK (_res_), NULL); + result = _data_->result; + *result_length1 = _data_->result_length1; + _data_->result = NULL; + return result; +} + +static gchar** +_vala_array_dup1 (gchar** self, + gssize length) +{ + if (length >= 0) { + gchar** result; + gssize i; + result = g_new0 (gchar*, length + 1); + for (i = 0; i < length; i++) { + gchar* _tmp0_; + _tmp0_ = g_strdup (self[i]); + result[i] = _tmp0_; + } + return result; + } + return NULL; +} + +static gboolean +test_list_messages_co (TestListMessagesData* _data_) +{ + switch (_data_->_state_) { + case 0: + goto _state_0; + default: + g_assert_not_reached (); + } + _state_0: + _data_->_tmp0_ = _data_->self->priv->messages; + _data_->_tmp0__length1 = _data_->self->priv->messages_length1; + _data_->_tmp1_ = (_data_->_tmp0_ != NULL) ? _vala_array_dup1 (_data_->_tmp0_, _data_->_tmp0__length1) : _data_->_tmp0_; + _data_->_tmp1__length1 = _data_->_tmp0__length1; + _data_->_tmp2_ = _data_->_tmp1_; + _data_->_tmp2__length1 = _data_->_tmp1__length1; + _data_->result_length1 = _data_->_tmp2__length1; + _data_->result = _data_->_tmp2_; + g_task_return_pointer (_data_->_async_result, _data_, NULL); + if (_data_->_state_ != 0) { + while (!g_task_get_completed (_data_->_async_result)) { + g_main_context_iteration (g_task_get_context (_data_->_async_result), TRUE); + } + } + g_object_unref (_data_->_async_result); + return FALSE; +} + +static void +test_post_message_data_free (gpointer _data) +{ + TestPostMessageData* _data_; + _data_ = _data; + _g_free0 (_data_->message); + _g_object_unref0 (_data_->self); + g_slice_free (TestPostMessageData, _data_); +} + +void +test_post_message (Test* self, + const gchar* message, + GAsyncReadyCallback _callback_, + gpointer _user_data_) +{ + TestPostMessageData* _data_; + Test* _tmp0_; + gchar* _tmp1_; + g_return_if_fail (IS_TEST (self)); + g_return_if_fail (message != NULL); + _data_ = g_slice_new0 (TestPostMessageData); + _data_->_async_result = g_task_new (G_OBJECT (self), NULL, _callback_, _user_data_); + g_task_set_task_data (_data_->_async_result, _data_, test_post_message_data_free); + _tmp0_ = _g_object_ref0 (self); + _data_->self = _tmp0_; + _tmp1_ = g_strdup (message); + _g_free0 (_data_->message); + _data_->message = _tmp1_; + test_post_message_co (_data_); +} + +void +test_post_message_finish (Test* self, + GAsyncResult* _res_) +{ + TestPostMessageData* _data_; + _data_ = g_task_propagate_pointer (G_TASK (_res_), NULL); +} + +static void +_vala_array_add1 (gchar** * array, + gint* length, + gint* size, + gchar* value) +{ + if ((*length) == (*size)) { + *size = (*size) ? (2 * (*size)) : 4; + *array = g_renew (gchar*, *array, (*size) + 1); + } + (*array)[(*length)++] = value; + (*array)[*length] = NULL; +} + +static gboolean +test_post_message_co (TestPostMessageData* _data_) +{ + switch (_data_->_state_) { + case 0: + goto _state_0; + default: + g_assert_not_reached (); + } + _state_0: + _data_->_tmp0_ = g_strdup (_data_->message); + _vala_array_add1 (&_data_->self->priv->messages, &_data_->self->priv->messages_length1, &_data_->self->priv->_messages_size_, _data_->_tmp0_); + g_task_return_pointer (_data_->_async_result, _data_, NULL); + if (_data_->_state_ != 0) { + while (!g_task_get_completed (_data_->_async_result)) { + g_main_context_iteration (g_task_get_context (_data_->_async_result), TRUE); + } + } + g_object_unref (_data_->_async_result); + return FALSE; +} + +Test* +test_construct (GType object_type) +{ + Test * self = NULL; + self = (Test*) g_object_new (object_type, NULL); + return self; +} + +Test* +test_new (void) +{ + return test_construct (TYPE_TEST); +} + +static void +test_class_init (TestClass * klass, + gpointer klass_data) +{ + test_parent_class = g_type_class_peek_parent (klass); + g_type_class_adjust_private_offset (klass, &Test_private_offset); + G_OBJECT_CLASS (klass)->finalize = test_finalize; +} + +static void +test_instance_init (Test * self, + gpointer klass) +{ + gchar** _tmp0_; + self->priv = test_get_instance_private (self); + _tmp0_ = g_new0 (gchar*, 0 + 1); + self->priv->messages = _tmp0_; + self->priv->messages_length1 = 0; + self->priv->_messages_size_ = self->priv->messages_length1; +} + +static void +test_finalize (GObject * obj) +{ + Test * self; + self = G_TYPE_CHECK_INSTANCE_CAST (obj, TYPE_TEST, Test); + self->priv->messages = (_vala_array_free (self->priv->messages, self->priv->messages_length1, (GDestroyNotify) g_free), NULL); + G_OBJECT_CLASS (test_parent_class)->finalize (obj); +} + +static GType +test_get_type_once (void) +{ + static const GTypeInfo g_define_type_info = { sizeof (TestClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) test_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (Test), 0, (GInstanceInitFunc) test_instance_init, NULL }; + GType test_type_id; + test_type_id = g_type_register_static (G_TYPE_OBJECT, "Test", &g_define_type_info, 0); + g_type_set_qdata (test_type_id, g_quark_from_static_string ("vala-dbus-register-object"), (void*) test_register_object); + Test_private_offset = g_type_add_instance_private (test_type_id, sizeof (TestPrivate)); + return test_type_id; +} + +GType +test_get_type (void) +{ + static volatile gsize test_type_id__volatile = 0; + if (g_once_init_enter (&test_type_id__volatile)) { + GType test_type_id; + test_type_id = test_get_type_once (); + g_once_init_leave (&test_type_id__volatile, test_type_id); + } + return test_type_id__volatile; +} + +static void +_dbus_test_list_messages (Test* self, + GVariant* _parameters_, + GDBusMethodInvocation* invocation) +{ + GVariantIter _arguments_iter; + TestListMessagesReadyData* _ready_data; + g_variant_iter_init (&_arguments_iter, _parameters_); + _ready_data = g_slice_new0 (TestListMessagesReadyData); + _ready_data->_invocation_ = invocation; + test_list_messages (self, (GAsyncReadyCallback) _dbus_test_list_messages_ready, _ready_data); +} + +static void +_dbus_test_list_messages_ready (GObject * source_object, + GAsyncResult * _res_, + gpointer _user_data_) +{ + TestListMessagesReadyData* _ready_data; + GDBusMethodInvocation* invocation; + GError* error = NULL; + GDBusMessage* _reply_message = NULL; + GVariant* _reply; + GVariantBuilder _reply_builder; + gchar** result; + gint result_length1 = 0; + gchar** _tmp0_; + GVariantBuilder _tmp1_; + gint _tmp2_; + _ready_data = _user_data_; + invocation = _ready_data->_invocation_; + result = test_list_messages_finish ((Test*) source_object, _res_, &result_length1); + _reply_message = g_dbus_message_new_method_reply (g_dbus_method_invocation_get_message (invocation)); + g_variant_builder_init (&_reply_builder, G_VARIANT_TYPE_TUPLE); + _tmp0_ = result; + g_variant_builder_init (&_tmp1_, G_VARIANT_TYPE ("as")); + for (_tmp2_ = 0; _tmp2_ < result_length1; _tmp2_++) { + g_variant_builder_add_value (&_tmp1_, g_variant_new_string (*_tmp0_)); + _tmp0_++; + } + g_variant_builder_add_value (&_reply_builder, g_variant_builder_end (&_tmp1_)); + result = (_vala_array_free (result, result_length1, (GDestroyNotify) g_free), NULL); + _reply = g_variant_builder_end (&_reply_builder); + g_dbus_message_set_body (_reply_message, _reply); + g_dbus_connection_send_message (g_dbus_method_invocation_get_connection (invocation), _reply_message, G_DBUS_SEND_MESSAGE_FLAGS_NONE, NULL, NULL); + g_object_unref (invocation); + g_object_unref (_reply_message); + _error: + g_slice_free (TestListMessagesReadyData, _ready_data); +} + +static void +_dbus_test_post_message (Test* self, + GVariant* _parameters_, + GDBusMethodInvocation* invocation) +{ + GVariantIter _arguments_iter; + TestPostMessageReadyData* _ready_data; + GVariant* _tmp3_; + g_variant_iter_init (&_arguments_iter, _parameters_); + _ready_data = g_slice_new0 (TestPostMessageReadyData); + _ready_data->_invocation_ = invocation; + _tmp3_ = g_variant_iter_next_value (&_arguments_iter); + _ready_data->message = g_variant_dup_string (_tmp3_, NULL); + g_variant_unref (_tmp3_); + test_post_message (self, _ready_data->message, (GAsyncReadyCallback) _dbus_test_post_message_ready, _ready_data); +} + +static void +_dbus_test_post_message_ready (GObject * source_object, + GAsyncResult * _res_, + gpointer _user_data_) +{ + TestPostMessageReadyData* _ready_data; + GDBusMethodInvocation* invocation; + GError* error = NULL; + GDBusMessage* _reply_message = NULL; + GVariant* _reply; + GVariantBuilder _reply_builder; + _ready_data = _user_data_; + invocation = _ready_data->_invocation_; + test_post_message_finish ((Test*) source_object, _res_); + _reply_message = g_dbus_message_new_method_reply (g_dbus_method_invocation_get_message (invocation)); + g_variant_builder_init (&_reply_builder, G_VARIANT_TYPE_TUPLE); + _reply = g_variant_builder_end (&_reply_builder); + g_dbus_message_set_body (_reply_message, _reply); + g_dbus_connection_send_message (g_dbus_method_invocation_get_connection (invocation), _reply_message, G_DBUS_SEND_MESSAGE_FLAGS_NONE, NULL, NULL); + g_object_unref (invocation); + g_object_unref (_reply_message); + _error: + _g_free0 (_ready_data->message); + g_slice_free (TestPostMessageReadyData, _ready_data); +} + +static void +test_dbus_interface_method_call (GDBusConnection* connection, + const gchar* sender, + const gchar* object_path, + const gchar* interface_name, + const gchar* method_name, + GVariant* parameters, + GDBusMethodInvocation* invocation, + gpointer user_data) +{ + gpointer* data; + gpointer object; + data = user_data; + object = data[0]; + if (strcmp (method_name, "ListMessages") == 0) { + _dbus_test_list_messages (object, parameters, invocation); + } else if (strcmp (method_name, "PostMessage") == 0) { + _dbus_test_post_message (object, parameters, invocation); + } else { + g_object_unref (invocation); + } +} + +static GVariant* +test_dbus_interface_get_property (GDBusConnection* connection, + const gchar* sender, + const gchar* object_path, + const gchar* interface_name, + const gchar* property_name, + GError** error, + gpointer user_data) +{ + gpointer* data; + gpointer object; + data = user_data; + object = data[0]; + return NULL; +} + +static gboolean +test_dbus_interface_set_property (GDBusConnection* connection, + const gchar* sender, + const gchar* object_path, + const gchar* interface_name, + const gchar* property_name, + GVariant* value, + GError** error, + gpointer user_data) +{ + gpointer* data; + gpointer object; + data = user_data; + object = data[0]; + return FALSE; +} + +guint +test_register_object (gpointer object, + GDBusConnection* connection, + const gchar* path, + GError** error) +{ + guint result; + gpointer *data; + data = g_new (gpointer, 3); + data[0] = g_object_ref (object); + data[1] = g_object_ref (connection); + data[2] = g_strdup (path); + result = g_dbus_connection_register_object (connection, path, (GDBusInterfaceInfo *) (&_test_dbus_interface_info), &_test_dbus_interface_vtable, data, _test_unregister_object, error); + if (!result) { + return 0; + } + return result; +} + +static void +_test_unregister_object (gpointer user_data) +{ + gpointer* data; + data = user_data; + g_object_unref (data[0]); + g_object_unref (data[1]); + g_free (data[2]); + g_free (data); +} + +void +client_exit (GPid pid, + gint status) +{ + GMainLoop* _tmp0_; + _vala_assert (status == 0, "status == 0"); + _tmp0_ = main_loop; + g_main_loop_quit (_tmp0_); +} + +static guint +_variant_get1 (GVariant* value) +{ + return g_variant_get_uint32 (value); +} + +static void +_client_exit_gchild_watch_func (GPid pid, + gint wait_status, + gpointer self) +{ + client_exit (pid, wait_status); +} + +static void +_vala_main (void) +{ + GDBusConnection* conn = NULL; + GDBusConnection* _tmp0_; + GDBusConnection* _tmp1_; + Test* _tmp2_; + Test* _tmp3_; + GVariant* request_result = NULL; + GDBusConnection* _tmp4_; + GVariant* _tmp5_; + GVariant* _tmp6_; + GVariant* _tmp7_; + GVariant* _tmp8_; + GVariant* _tmp9_; + GVariant* _tmp10_; + GVariant* _tmp11_; + guint _tmp12_; + GPid client_pid = 0; + gchar* _tmp13_; + gchar** _tmp14_; + gchar** _tmp15_; + gint _tmp15__length1; + GPid _tmp16_ = 0; + GMainLoop* _tmp17_; + GMainLoop* _tmp18_; + GError* _inner_error0_ = NULL; + _tmp0_ = g_bus_get_sync (G_BUS_TYPE_SESSION, NULL, &_inner_error0_); + conn = _tmp0_; + if (G_UNLIKELY (_inner_error0_ != NULL)) { + g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error0_->message, g_quark_to_string (_inner_error0_->domain), _inner_error0_->code); + g_clear_error (&_inner_error0_); + return; + } + _tmp1_ = conn; + _tmp2_ = test_new (); + _tmp3_ = _tmp2_; + test_register_object (_tmp3_, _tmp1_, "/org/example/Test", &_inner_error0_); + _g_object_unref0 (_tmp3_); + if (G_UNLIKELY (_inner_error0_ != NULL)) { + _g_object_unref0 (conn); + g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error0_->message, g_quark_to_string (_inner_error0_->domain), _inner_error0_->code); + g_clear_error (&_inner_error0_); + return; + } + _tmp4_ = conn; + _tmp5_ = g_variant_new ("(su)", "org.example.Test", 0x4, NULL); + g_variant_ref_sink (_tmp5_); + _tmp6_ = _tmp5_; + _tmp7_ = g_dbus_connection_call_sync (_tmp4_, "org.freedesktop.DBus", "/org/freedesktop/DBus", "org.freedesktop.DBus", "RequestName", _tmp6_, NULL, 0, -1, NULL, &_inner_error0_); + _tmp8_ = _tmp7_; + _g_variant_unref0 (_tmp6_); + request_result = _tmp8_; + if (G_UNLIKELY (_inner_error0_ != NULL)) { + _g_object_unref0 (conn); + g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error0_->message, g_quark_to_string (_inner_error0_->domain), _inner_error0_->code); + g_clear_error (&_inner_error0_); + return; + } + _tmp9_ = request_result; + _tmp10_ = g_variant_get_child_value (_tmp9_, (gsize) 0); + _tmp11_ = _tmp10_; + _tmp12_ = _variant_get1 (_tmp11_); + _vala_assert (_tmp12_ == ((guint) 1), "(uint) request_result.get_child_value (0) == 1"); + _g_variant_unref0 (_tmp11_); + _tmp13_ = g_strdup ("dbus_async_no_reply_client"); + _tmp14_ = g_new0 (gchar*, 1 + 1); + _tmp14_[0] = _tmp13_; + _tmp15_ = _tmp14_; + _tmp15__length1 = 1; + g_spawn_async (NULL, _tmp15_, NULL, G_SPAWN_DO_NOT_REAP_CHILD, NULL, NULL, &_tmp16_, &_inner_error0_); + client_pid = _tmp16_; + _tmp15_ = (_vala_array_free (_tmp15_, _tmp15__length1, (GDestroyNotify) g_free), NULL); + if (G_UNLIKELY (_inner_error0_ != NULL)) { + _g_variant_unref0 (request_result); + _g_object_unref0 (conn); + g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error0_->message, g_quark_to_string (_inner_error0_->domain), _inner_error0_->code); + g_clear_error (&_inner_error0_); + return; + } + g_child_watch_add_full (G_PRIORITY_DEFAULT_IDLE, client_pid, _client_exit_gchild_watch_func, NULL, NULL); + _tmp17_ = g_main_loop_new (NULL, FALSE); + _g_main_loop_unref0 (main_loop); + main_loop = _tmp17_; + _tmp18_ = main_loop; + g_main_loop_run (_tmp18_); + _g_variant_unref0 (request_result); + _g_object_unref0 (conn); +} + +int +main (int argc, + char ** argv) +{ + _vala_main (); + return 0; +} + +static void +_vala_array_destroy (gpointer array, + gssize array_length, + GDestroyNotify destroy_func) +{ + if ((array != NULL) && (destroy_func != NULL)) { + gssize i; + for (i = 0; i < array_length; i = i + 1) { + if (((gpointer*) array)[i] != NULL) { + destroy_func (((gpointer*) array)[i]); + } + } + } +} + +static void +_vala_array_free (gpointer array, + gssize array_length, + GDestroyNotify destroy_func) +{ + _vala_array_destroy (array, array_length, destroy_func); + g_free (array); +} + diff --git a/tests/dbus/async_client.c-expected b/tests/dbus/async_client.c-expected new file mode 100644 index 000000000..659449fc2 --- /dev/null +++ b/tests/dbus/async_client.c-expected @@ -0,0 +1,947 @@ +/* dbus_async_client.c generated by valac, the Vala compiler + * generated from dbus_async_client.vala, do not modify */ + +#include <glib-object.h> +#include <gio/gio.h> +#include <glib.h> +#include <stdlib.h> +#include <string.h> + +#if !defined(VALA_EXTERN) +#if defined(_MSC_VER) +#define VALA_EXTERN __declspec(dllexport) extern +#elif __GNUC__ >= 4 +#define VALA_EXTERN __attribute__((visibility("default"))) extern +#else +#define VALA_EXTERN extern +#endif +#endif + +#define TYPE_TEST (test_get_type ()) +#define TEST(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TYPE_TEST, Test)) +#define IS_TEST(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TYPE_TEST)) +#define TEST_GET_INTERFACE(obj) (G_TYPE_INSTANCE_GET_INTERFACE ((obj), TYPE_TEST, TestIface)) + +typedef struct _Test Test; +typedef struct _TestIface TestIface; + +#define TYPE_TEST_PROXY (test_proxy_get_type ()) +typedef GDBusProxy TestProxy; +typedef GDBusProxyClass TestProxyClass; +typedef struct _TestTestVoidReadyData TestTestVoidReadyData; +typedef struct _TestTestIntReadyData TestTestIntReadyData; +typedef struct _TestTestStringReadyData TestTestStringReadyData; +#define _g_free0(var) (var = (g_free (var), NULL)) +#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL))) +typedef struct _RunData RunData; +#define _g_main_loop_unref0(var) ((var == NULL) ? NULL : (var = (g_main_loop_unref (var), NULL))) +#define _vala_assert(expr, msg) if G_LIKELY (expr) ; else g_assertion_message_expr (G_LOG_DOMAIN, __FILE__, __LINE__, G_STRFUNC, msg); +#define _vala_return_if_fail(expr, msg) if G_LIKELY (expr) ; else { g_return_if_fail_warning (G_LOG_DOMAIN, G_STRFUNC, msg); return; } +#define _vala_return_val_if_fail(expr, msg, val) if G_LIKELY (expr) ; else { g_return_if_fail_warning (G_LOG_DOMAIN, G_STRFUNC, msg); return val; } +#define _vala_warn_if_fail(expr, msg) if G_LIKELY (expr) ; else g_warn_message (G_LOG_DOMAIN, __FILE__, __LINE__, G_STRFUNC, msg); + +struct _TestIface { + GTypeInterface parent_iface; + void (*test_void) (Test* self, GAsyncReadyCallback _callback_, gpointer _user_data_); + void (*test_void_finish) (Test* self, GAsyncResult* _res_, GError** error); + void (*test_int) (Test* self, gint i, GAsyncReadyCallback _callback_, gpointer _user_data_); + gint (*test_int_finish) (Test* self, GAsyncResult* _res_, gint* j, GError** error); + void (*test_string) (Test* self, const gchar* s, GAsyncReadyCallback _callback_, gpointer _user_data_); + gchar* (*test_string_finish) (Test* self, GAsyncResult* _res_, gchar* * t, GError** error); +}; + +struct _TestTestVoidReadyData { + GDBusMethodInvocation* _invocation_; +}; + +struct _TestTestIntReadyData { + GDBusMethodInvocation* _invocation_; + gint i; +}; + +struct _TestTestStringReadyData { + GDBusMethodInvocation* _invocation_; + gchar* s; +}; + +struct _RunData { + int _state_; + GObject* _source_object_; + GAsyncResult* _res_; + GTask* _async_result; + Test* test; + Test* _tmp0_; + Test* _tmp1_; + gint j; + gint k; + gint _tmp2_; + Test* _tmp3_; + gint _tmp4_; + gint _tmp5_; + gchar* t; + gchar* u; + gchar* _tmp6_; + Test* _tmp7_; + gchar* _tmp8_; + gchar* _tmp9_; + gchar* _tmp10_; + const gchar* _tmp11_; + const gchar* _tmp12_; + GMainLoop* _tmp13_; + GError* _inner_error0_; +}; + +VALA_EXTERN GMainLoop* main_loop; +GMainLoop* main_loop = NULL; + +VALA_EXTERN GType test_proxy_get_type (void) G_GNUC_CONST ; +VALA_EXTERN guint test_register_object (void* object, + GDBusConnection* connection, + const gchar* path, + GError** error); +VALA_EXTERN GType test_get_type (void) G_GNUC_CONST ; +VALA_EXTERN void test_test_void (Test* self, + GAsyncReadyCallback _callback_, + gpointer _user_data_); +VALA_EXTERN void test_test_void_finish (Test* self, + GAsyncResult* _res_, + GError** error); +VALA_EXTERN void test_test_int (Test* self, + gint i, + GAsyncReadyCallback _callback_, + gpointer _user_data_); +VALA_EXTERN gint test_test_int_finish (Test* self, + GAsyncResult* _res_, + gint* j, + GError** error); +VALA_EXTERN void test_test_string (Test* self, + const gchar* s, + GAsyncReadyCallback _callback_, + gpointer _user_data_); +VALA_EXTERN gchar* test_test_string_finish (Test* self, + GAsyncResult* _res_, + gchar* * t, + GError** error); +static GType test_get_type_once (void); +static void test_proxy_g_signal (GDBusProxy* proxy, + const gchar* sender_name, + const gchar* signal_name, + GVariant* parameters); +static void _vala_g_async_ready_callback (GObject *source_object, + GAsyncResult *res, + void *user_data); +static void test_proxy_test_void_async (Test* self, + GAsyncReadyCallback _callback_, + gpointer _user_data_); +static void test_proxy_test_void_finish (Test* self, + GAsyncResult* _res_, + GError** error); +static void test_proxy_test_int_async (Test* self, + gint i, + GAsyncReadyCallback _callback_, + gpointer _user_data_); +static gint test_proxy_test_int_finish (Test* self, + GAsyncResult* _res_, + gint* j, + GError** error); +static void test_proxy_test_string_async (Test* self, + const gchar* s, + GAsyncReadyCallback _callback_, + gpointer _user_data_); +static gchar* test_proxy_test_string_finish (Test* self, + GAsyncResult* _res_, + gchar* * t, + GError** error); +static void test_proxy_test_interface_init (TestIface* iface); +static void _dbus_test_test_void (Test* self, + GVariant* _parameters_, + GDBusMethodInvocation* invocation); +static void _dbus_test_test_void_ready (GObject * source_object, + GAsyncResult * _res_, + gpointer _user_data_); +static void _dbus_test_test_int (Test* self, + GVariant* _parameters_, + GDBusMethodInvocation* invocation); +static void _dbus_test_test_int_ready (GObject * source_object, + GAsyncResult * _res_, + gpointer _user_data_); +static void _dbus_test_test_string (Test* self, + GVariant* _parameters_, + GDBusMethodInvocation* invocation); +static void _dbus_test_test_string_ready (GObject * source_object, + GAsyncResult * _res_, + gpointer _user_data_); +static void test_dbus_interface_method_call (GDBusConnection* connection, + const gchar* sender, + const gchar* object_path, + const gchar* interface_name, + const gchar* method_name, + GVariant* parameters, + GDBusMethodInvocation* invocation, + gpointer user_data); +static GVariant* test_dbus_interface_get_property (GDBusConnection* connection, + const gchar* sender, + const gchar* object_path, + const gchar* interface_name, + const gchar* property_name, + GError** error, + gpointer user_data); +static gboolean test_dbus_interface_set_property (GDBusConnection* connection, + const gchar* sender, + const gchar* object_path, + const gchar* interface_name, + const gchar* property_name, + GVariant* value, + GError** error, + gpointer user_data); +static void _test_unregister_object (gpointer user_data); +static void run_data_free (gpointer _data); +VALA_EXTERN void run (GAsyncReadyCallback _callback_, + gpointer _user_data_); +VALA_EXTERN void run_finish (GAsyncResult* _res_); +static gboolean run_co (RunData* _data_); +static void run_ready (GObject* source_object, + GAsyncResult* _res_, + gpointer _user_data_); +static void _vala_main (void); + +static const GDBusArgInfo * const _test_dbus_arg_info_test_void_in[] = {NULL}; +static const GDBusArgInfo * const _test_dbus_arg_info_test_void_out[] = {NULL}; +static const GDBusMethodInfo _test_dbus_method_info_test_void = {-1, "TestVoid", (GDBusArgInfo **) (&_test_dbus_arg_info_test_void_in), (GDBusArgInfo **) (&_test_dbus_arg_info_test_void_out), NULL}; +static const GDBusArgInfo _test_dbus_arg_info_test_int_i = {-1, "i", "i", NULL}; +static const GDBusArgInfo _test_dbus_arg_info_test_int_j = {-1, "j", "i", NULL}; +static const GDBusArgInfo _test_dbus_arg_info_test_int_result = {-1, "result", "i", NULL}; +static const GDBusArgInfo * const _test_dbus_arg_info_test_int_in[] = {&_test_dbus_arg_info_test_int_i, NULL}; +static const GDBusArgInfo * const _test_dbus_arg_info_test_int_out[] = {&_test_dbus_arg_info_test_int_j, &_test_dbus_arg_info_test_int_result, NULL}; +static const GDBusMethodInfo _test_dbus_method_info_test_int = {-1, "TestInt", (GDBusArgInfo **) (&_test_dbus_arg_info_test_int_in), (GDBusArgInfo **) (&_test_dbus_arg_info_test_int_out), NULL}; +static const GDBusArgInfo _test_dbus_arg_info_test_string_s = {-1, "s", "s", NULL}; +static const GDBusArgInfo _test_dbus_arg_info_test_string_t = {-1, "t", "s", NULL}; +static const GDBusArgInfo _test_dbus_arg_info_test_string_result = {-1, "result", "s", NULL}; +static const GDBusArgInfo * const _test_dbus_arg_info_test_string_in[] = {&_test_dbus_arg_info_test_string_s, NULL}; +static const GDBusArgInfo * const _test_dbus_arg_info_test_string_out[] = {&_test_dbus_arg_info_test_string_t, &_test_dbus_arg_info_test_string_result, NULL}; +static const GDBusMethodInfo _test_dbus_method_info_test_string = {-1, "TestString", (GDBusArgInfo **) (&_test_dbus_arg_info_test_string_in), (GDBusArgInfo **) (&_test_dbus_arg_info_test_string_out), NULL}; +static const GDBusMethodInfo * const _test_dbus_method_info[] = {&_test_dbus_method_info_test_void, &_test_dbus_method_info_test_int, &_test_dbus_method_info_test_string, NULL}; +static const GDBusSignalInfo * const _test_dbus_signal_info[] = {NULL}; +static const GDBusPropertyInfo * const _test_dbus_property_info[] = {NULL}; +static const GDBusInterfaceInfo _test_dbus_interface_info = {-1, "org.example.Test", (GDBusMethodInfo **) (&_test_dbus_method_info), (GDBusSignalInfo **) (&_test_dbus_signal_info), (GDBusPropertyInfo **) (&_test_dbus_property_info), NULL}; +static const GDBusInterfaceVTable _test_dbus_interface_vtable = {test_dbus_interface_method_call, test_dbus_interface_get_property, test_dbus_interface_set_property}; + +void +test_test_void (Test* self, + GAsyncReadyCallback _callback_, + gpointer _user_data_) +{ + TestIface* _iface_; + _iface_ = TEST_GET_INTERFACE (self); + if (_iface_->test_void) { + _iface_->test_void (self, _callback_, _user_data_); + } +} + +void +test_test_void_finish (Test* self, + GAsyncResult* _res_, + GError** error) +{ + TestIface* _iface_; + _iface_ = TEST_GET_INTERFACE (self); + if (_iface_->test_void_finish) { + _iface_->test_void_finish (self, _res_, error); + } +} + +void +test_test_int (Test* self, + gint i, + GAsyncReadyCallback _callback_, + gpointer _user_data_) +{ + TestIface* _iface_; + _iface_ = TEST_GET_INTERFACE (self); + if (_iface_->test_int) { + _iface_->test_int (self, i, _callback_, _user_data_); + } +} + +gint +test_test_int_finish (Test* self, + GAsyncResult* _res_, + gint* j, + GError** error) +{ + TestIface* _iface_; + _iface_ = TEST_GET_INTERFACE (self); + if (_iface_->test_int_finish) { + return _iface_->test_int_finish (self, _res_, j, error); + } + return -1; +} + +void +test_test_string (Test* self, + const gchar* s, + GAsyncReadyCallback _callback_, + gpointer _user_data_) +{ + TestIface* _iface_; + _iface_ = TEST_GET_INTERFACE (self); + if (_iface_->test_string) { + _iface_->test_string (self, s, _callback_, _user_data_); + } +} + +gchar* +test_test_string_finish (Test* self, + GAsyncResult* _res_, + gchar* * t, + GError** error) +{ + TestIface* _iface_; + _iface_ = TEST_GET_INTERFACE (self); + if (_iface_->test_string_finish) { + return _iface_->test_string_finish (self, _res_, t, error); + } + return NULL; +} + +static void +test_default_init (TestIface * iface, + gpointer iface_data) +{ +} + +static GType +test_get_type_once (void) +{ + static const GTypeInfo g_define_type_info = { sizeof (TestIface), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) test_default_init, (GClassFinalizeFunc) NULL, NULL, 0, 0, (GInstanceInitFunc) NULL, NULL }; + GType test_type_id; + test_type_id = g_type_register_static (G_TYPE_INTERFACE, "Test", &g_define_type_info, 0); + g_type_interface_add_prerequisite (test_type_id, G_TYPE_OBJECT); + g_type_set_qdata (test_type_id, g_quark_from_static_string ("vala-dbus-proxy-type"), (void*) test_proxy_get_type); + g_type_set_qdata (test_type_id, g_quark_from_static_string ("vala-dbus-interface-name"), "org.example.Test"); + g_type_set_qdata (test_type_id, g_quark_from_static_string ("vala-dbus-interface-info"), (void*) (&_test_dbus_interface_info)); + g_type_set_qdata (test_type_id, g_quark_from_static_string ("vala-dbus-register-object"), (void*) test_register_object); + return test_type_id; +} + +GType +test_get_type (void) +{ + static volatile gsize test_type_id__volatile = 0; + if (g_once_init_enter (&test_type_id__volatile)) { + GType test_type_id; + test_type_id = test_get_type_once (); + g_once_init_leave (&test_type_id__volatile, test_type_id); + } + return test_type_id__volatile; +} + +G_DEFINE_TYPE_EXTENDED (TestProxy, test_proxy, G_TYPE_DBUS_PROXY, 0, G_IMPLEMENT_INTERFACE (TYPE_TEST, test_proxy_test_interface_init) ) +static void +test_proxy_class_init (TestProxyClass* klass) +{ + G_DBUS_PROXY_CLASS (klass)->g_signal = test_proxy_g_signal; +} + +static void +test_proxy_g_signal (GDBusProxy* proxy, + const gchar* sender_name, + const gchar* signal_name, + GVariant* parameters) +{ +} + +static void +test_proxy_init (TestProxy* self) +{ + g_dbus_proxy_set_interface_info (G_DBUS_PROXY (self), (GDBusInterfaceInfo *) (&_test_dbus_interface_info)); +} + +static void +_vala_g_async_ready_callback (GObject *source_object, + GAsyncResult *res, + void *user_data) +{ + g_task_return_pointer (user_data, g_object_ref (res), g_object_unref); + g_object_unref (user_data); +} + +static void +test_proxy_test_void_async (Test* self, + GAsyncReadyCallback _callback_, + gpointer _user_data_) +{ + GDBusMessage *_message; + GVariant *_arguments; + GVariantBuilder _arguments_builder; + G_IO_ERROR; + _message = g_dbus_message_new_method_call (g_dbus_proxy_get_name ((GDBusProxy *) self), g_dbus_proxy_get_object_path ((GDBusProxy *) self), "org.example.Test", "TestVoid"); + g_variant_builder_init (&_arguments_builder, G_VARIANT_TYPE_TUPLE); + _arguments = g_variant_builder_end (&_arguments_builder); + g_dbus_message_set_body (_message, _arguments); + if (_callback_ != NULL) { + g_dbus_connection_send_message_with_reply (g_dbus_proxy_get_connection ((GDBusProxy *) self), _message, G_DBUS_SEND_MESSAGE_FLAGS_NONE, g_dbus_proxy_get_default_timeout ((GDBusProxy *) self), NULL, NULL, _vala_g_async_ready_callback, g_task_new ((GObject *) self, NULL, _callback_, _user_data_)); + } else { + g_dbus_message_set_flags (_message, G_DBUS_MESSAGE_FLAGS_NO_REPLY_EXPECTED); + g_dbus_connection_send_message (g_dbus_proxy_get_connection ((GDBusProxy *) self), _message, G_DBUS_SEND_MESSAGE_FLAGS_NONE, NULL, NULL); + } + g_object_unref (_message); +} + +static void +test_proxy_test_void_finish (Test* self, + GAsyncResult* _res_, + GError** error) +{ + GAsyncResult *_inner_res; + GDBusMessage *_reply_message; + _inner_res = g_task_propagate_pointer ((GTask *) _res_, NULL); + _reply_message = g_dbus_connection_send_message_with_reply_finish (g_dbus_proxy_get_connection ((GDBusProxy *) self), _inner_res, error); + g_object_unref (_inner_res); + if (!_reply_message) { + return; + } + if (g_dbus_message_to_gerror (_reply_message, error)) { + g_object_unref (_reply_message); + return; + } + g_object_unref (_reply_message); +} + +static void +test_proxy_test_int_async (Test* self, + gint i, + GAsyncReadyCallback _callback_, + gpointer _user_data_) +{ + GDBusMessage *_message; + GVariant *_arguments; + GVariantBuilder _arguments_builder; + G_IO_ERROR; + _message = g_dbus_message_new_method_call (g_dbus_proxy_get_name ((GDBusProxy *) self), g_dbus_proxy_get_object_path ((GDBusProxy *) self), "org.example.Test", "TestInt"); + g_variant_builder_init (&_arguments_builder, G_VARIANT_TYPE_TUPLE); + g_variant_builder_add_value (&_arguments_builder, g_variant_new_int32 (i)); + _arguments = g_variant_builder_end (&_arguments_builder); + g_dbus_message_set_body (_message, _arguments); + if (_callback_ != NULL) { + g_dbus_connection_send_message_with_reply (g_dbus_proxy_get_connection ((GDBusProxy *) self), _message, G_DBUS_SEND_MESSAGE_FLAGS_NONE, g_dbus_proxy_get_default_timeout ((GDBusProxy *) self), NULL, NULL, _vala_g_async_ready_callback, g_task_new ((GObject *) self, NULL, _callback_, _user_data_)); + } else { + g_dbus_message_set_flags (_message, G_DBUS_MESSAGE_FLAGS_NO_REPLY_EXPECTED); + g_dbus_connection_send_message (g_dbus_proxy_get_connection ((GDBusProxy *) self), _message, G_DBUS_SEND_MESSAGE_FLAGS_NONE, NULL, NULL); + } + g_object_unref (_message); +} + +static gint +test_proxy_test_int_finish (Test* self, + GAsyncResult* _res_, + gint* j, + GError** error) +{ + GAsyncResult *_inner_res; + GDBusMessage *_reply_message; + GVariant *_reply; + GVariantIter _reply_iter; + gint _vala_j = 0; + GVariant* _tmp2_; + gint _result = 0; + GVariant* _tmp3_; + _inner_res = g_task_propagate_pointer ((GTask *) _res_, NULL); + _reply_message = g_dbus_connection_send_message_with_reply_finish (g_dbus_proxy_get_connection ((GDBusProxy *) self), _inner_res, error); + g_object_unref (_inner_res); + if (!_reply_message) { + gint _tmp0_ = 0; + return _tmp0_; + } + if (g_dbus_message_to_gerror (_reply_message, error)) { + gint _tmp1_ = 0; + g_object_unref (_reply_message); + return _tmp1_; + } + _reply = g_dbus_message_get_body (_reply_message); + g_variant_iter_init (&_reply_iter, _reply); + _tmp2_ = g_variant_iter_next_value (&_reply_iter); + _vala_j = g_variant_get_int32 (_tmp2_); + g_variant_unref (_tmp2_); + *j = _vala_j; + _tmp3_ = g_variant_iter_next_value (&_reply_iter); + _result = g_variant_get_int32 (_tmp3_); + g_variant_unref (_tmp3_); + g_object_unref (_reply_message); + return _result; +} + +static void +test_proxy_test_string_async (Test* self, + const gchar* s, + GAsyncReadyCallback _callback_, + gpointer _user_data_) +{ + GDBusMessage *_message; + GVariant *_arguments; + GVariantBuilder _arguments_builder; + G_IO_ERROR; + _message = g_dbus_message_new_method_call (g_dbus_proxy_get_name ((GDBusProxy *) self), g_dbus_proxy_get_object_path ((GDBusProxy *) self), "org.example.Test", "TestString"); + g_variant_builder_init (&_arguments_builder, G_VARIANT_TYPE_TUPLE); + g_variant_builder_add_value (&_arguments_builder, g_variant_new_string (s)); + _arguments = g_variant_builder_end (&_arguments_builder); + g_dbus_message_set_body (_message, _arguments); + if (_callback_ != NULL) { + g_dbus_connection_send_message_with_reply (g_dbus_proxy_get_connection ((GDBusProxy *) self), _message, G_DBUS_SEND_MESSAGE_FLAGS_NONE, g_dbus_proxy_get_default_timeout ((GDBusProxy *) self), NULL, NULL, _vala_g_async_ready_callback, g_task_new ((GObject *) self, NULL, _callback_, _user_data_)); + } else { + g_dbus_message_set_flags (_message, G_DBUS_MESSAGE_FLAGS_NO_REPLY_EXPECTED); + g_dbus_connection_send_message (g_dbus_proxy_get_connection ((GDBusProxy *) self), _message, G_DBUS_SEND_MESSAGE_FLAGS_NONE, NULL, NULL); + } + g_object_unref (_message); +} + +static gchar* +test_proxy_test_string_finish (Test* self, + GAsyncResult* _res_, + gchar* * t, + GError** error) +{ + GAsyncResult *_inner_res; + GDBusMessage *_reply_message; + GVariant *_reply; + GVariantIter _reply_iter; + gchar* _vala_t = NULL; + GVariant* _tmp4_; + gchar* _result = NULL; + GVariant* _tmp5_; + _inner_res = g_task_propagate_pointer ((GTask *) _res_, NULL); + _reply_message = g_dbus_connection_send_message_with_reply_finish (g_dbus_proxy_get_connection ((GDBusProxy *) self), _inner_res, error); + g_object_unref (_inner_res); + if (!_reply_message) { + return NULL; + } + if (g_dbus_message_to_gerror (_reply_message, error)) { + g_object_unref (_reply_message); + return NULL; + } + _reply = g_dbus_message_get_body (_reply_message); + g_variant_iter_init (&_reply_iter, _reply); + _tmp4_ = g_variant_iter_next_value (&_reply_iter); + _vala_t = g_variant_dup_string (_tmp4_, NULL); + g_variant_unref (_tmp4_); + *t = _vala_t; + _tmp5_ = g_variant_iter_next_value (&_reply_iter); + _result = g_variant_dup_string (_tmp5_, NULL); + g_variant_unref (_tmp5_); + g_object_unref (_reply_message); + return _result; +} + +static void +test_proxy_test_interface_init (TestIface* iface) +{ + iface->test_void = test_proxy_test_void_async; + iface->test_void_finish = test_proxy_test_void_finish; + iface->test_int = test_proxy_test_int_async; + iface->test_int_finish = test_proxy_test_int_finish; + iface->test_string = test_proxy_test_string_async; + iface->test_string_finish = test_proxy_test_string_finish; +} + +static void +_dbus_test_test_void (Test* self, + GVariant* _parameters_, + GDBusMethodInvocation* invocation) +{ + GVariantIter _arguments_iter; + TestTestVoidReadyData* _ready_data; + g_variant_iter_init (&_arguments_iter, _parameters_); + _ready_data = g_slice_new0 (TestTestVoidReadyData); + _ready_data->_invocation_ = invocation; + test_test_void (self, (GAsyncReadyCallback) _dbus_test_test_void_ready, _ready_data); +} + +static void +_dbus_test_test_void_ready (GObject * source_object, + GAsyncResult * _res_, + gpointer _user_data_) +{ + TestTestVoidReadyData* _ready_data; + GDBusMethodInvocation* invocation; + GError* error = NULL; + GDBusMessage* _reply_message = NULL; + GVariant* _reply; + GVariantBuilder _reply_builder; + _ready_data = _user_data_; + invocation = _ready_data->_invocation_; + test_test_void_finish ((Test*) source_object, _res_, &error); + if (error) { + g_dbus_method_invocation_return_gerror (invocation, error); + g_error_free (error); + goto _error; + } + _reply_message = g_dbus_message_new_method_reply (g_dbus_method_invocation_get_message (invocation)); + g_variant_builder_init (&_reply_builder, G_VARIANT_TYPE_TUPLE); + _reply = g_variant_builder_end (&_reply_builder); + g_dbus_message_set_body (_reply_message, _reply); + g_dbus_connection_send_message (g_dbus_method_invocation_get_connection (invocation), _reply_message, G_DBUS_SEND_MESSAGE_FLAGS_NONE, NULL, NULL); + g_object_unref (invocation); + g_object_unref (_reply_message); + _error: + g_slice_free (TestTestVoidReadyData, _ready_data); +} + +static void +_dbus_test_test_int (Test* self, + GVariant* _parameters_, + GDBusMethodInvocation* invocation) +{ + GVariantIter _arguments_iter; + TestTestIntReadyData* _ready_data; + GVariant* _tmp6_; + g_variant_iter_init (&_arguments_iter, _parameters_); + _ready_data = g_slice_new0 (TestTestIntReadyData); + _ready_data->_invocation_ = invocation; + _tmp6_ = g_variant_iter_next_value (&_arguments_iter); + _ready_data->i = g_variant_get_int32 (_tmp6_); + g_variant_unref (_tmp6_); + test_test_int (self, _ready_data->i, (GAsyncReadyCallback) _dbus_test_test_int_ready, _ready_data); +} + +static void +_dbus_test_test_int_ready (GObject * source_object, + GAsyncResult * _res_, + gpointer _user_data_) +{ + TestTestIntReadyData* _ready_data; + GDBusMethodInvocation* invocation; + GError* error = NULL; + GDBusMessage* _reply_message = NULL; + GVariant* _reply; + GVariantBuilder _reply_builder; + gint j = 0; + gint result; + _ready_data = _user_data_; + invocation = _ready_data->_invocation_; + result = test_test_int_finish ((Test*) source_object, _res_, &j, &error); + if (error) { + g_dbus_method_invocation_return_gerror (invocation, error); + g_error_free (error); + goto _error; + } + _reply_message = g_dbus_message_new_method_reply (g_dbus_method_invocation_get_message (invocation)); + g_variant_builder_init (&_reply_builder, G_VARIANT_TYPE_TUPLE); + g_variant_builder_add_value (&_reply_builder, g_variant_new_int32 (j)); + g_variant_builder_add_value (&_reply_builder, g_variant_new_int32 (result)); + _reply = g_variant_builder_end (&_reply_builder); + g_dbus_message_set_body (_reply_message, _reply); + g_dbus_connection_send_message (g_dbus_method_invocation_get_connection (invocation), _reply_message, G_DBUS_SEND_MESSAGE_FLAGS_NONE, NULL, NULL); + g_object_unref (invocation); + g_object_unref (_reply_message); + _error: + g_slice_free (TestTestIntReadyData, _ready_data); +} + +static void +_dbus_test_test_string (Test* self, + GVariant* _parameters_, + GDBusMethodInvocation* invocation) +{ + GVariantIter _arguments_iter; + TestTestStringReadyData* _ready_data; + GVariant* _tmp7_; + g_variant_iter_init (&_arguments_iter, _parameters_); + _ready_data = g_slice_new0 (TestTestStringReadyData); + _ready_data->_invocation_ = invocation; + _tmp7_ = g_variant_iter_next_value (&_arguments_iter); + _ready_data->s = g_variant_dup_string (_tmp7_, NULL); + g_variant_unref (_tmp7_); + test_test_string (self, _ready_data->s, (GAsyncReadyCallback) _dbus_test_test_string_ready, _ready_data); + _error: + ; +} + +static void +_dbus_test_test_string_ready (GObject * source_object, + GAsyncResult * _res_, + gpointer _user_data_) +{ + TestTestStringReadyData* _ready_data; + GDBusMethodInvocation* invocation; + GError* error = NULL; + GDBusMessage* _reply_message = NULL; + GVariant* _reply; + GVariantBuilder _reply_builder; + gchar* t = NULL; + gchar* result; + _ready_data = _user_data_; + invocation = _ready_data->_invocation_; + result = test_test_string_finish ((Test*) source_object, _res_, &t, &error); + if (error) { + g_dbus_method_invocation_return_gerror (invocation, error); + g_error_free (error); + goto _error; + } + _reply_message = g_dbus_message_new_method_reply (g_dbus_method_invocation_get_message (invocation)); + g_variant_builder_init (&_reply_builder, G_VARIANT_TYPE_TUPLE); + g_variant_builder_add_value (&_reply_builder, g_variant_new_string (t)); + g_variant_builder_add_value (&_reply_builder, g_variant_new_string (result)); + _g_free0 (result); + _reply = g_variant_builder_end (&_reply_builder); + g_dbus_message_set_body (_reply_message, _reply); + g_dbus_connection_send_message (g_dbus_method_invocation_get_connection (invocation), _reply_message, G_DBUS_SEND_MESSAGE_FLAGS_NONE, NULL, NULL); + g_object_unref (invocation); + g_object_unref (_reply_message); + _error: + _g_free0 (_ready_data->s); + _g_free0 (t); + g_slice_free (TestTestStringReadyData, _ready_data); +} + +static void +test_dbus_interface_method_call (GDBusConnection* connection, + const gchar* sender, + const gchar* object_path, + const gchar* interface_name, + const gchar* method_name, + GVariant* parameters, + GDBusMethodInvocation* invocation, + gpointer user_data) +{ + gpointer* data; + gpointer object; + data = user_data; + object = data[0]; + if (strcmp (method_name, "TestVoid") == 0) { + _dbus_test_test_void (object, parameters, invocation); + } else if (strcmp (method_name, "TestInt") == 0) { + _dbus_test_test_int (object, parameters, invocation); + } else if (strcmp (method_name, "TestString") == 0) { + _dbus_test_test_string (object, parameters, invocation); + } else { + g_object_unref (invocation); + } +} + +static GVariant* +test_dbus_interface_get_property (GDBusConnection* connection, + const gchar* sender, + const gchar* object_path, + const gchar* interface_name, + const gchar* property_name, + GError** error, + gpointer user_data) +{ + gpointer* data; + gpointer object; + data = user_data; + object = data[0]; + return NULL; +} + +static gboolean +test_dbus_interface_set_property (GDBusConnection* connection, + const gchar* sender, + const gchar* object_path, + const gchar* interface_name, + const gchar* property_name, + GVariant* value, + GError** error, + gpointer user_data) +{ + gpointer* data; + gpointer object; + data = user_data; + object = data[0]; + return FALSE; +} + +guint +test_register_object (gpointer object, + GDBusConnection* connection, + const gchar* path, + GError** error) +{ + guint result; + gpointer *data; + data = g_new (gpointer, 3); + data[0] = g_object_ref (object); + data[1] = g_object_ref (connection); + data[2] = g_strdup (path); + result = g_dbus_connection_register_object (connection, path, (GDBusInterfaceInfo *) (&_test_dbus_interface_info), &_test_dbus_interface_vtable, data, _test_unregister_object, error); + if (!result) { + return 0; + } + return result; +} + +static void +_test_unregister_object (gpointer user_data) +{ + gpointer* data; + data = user_data; + g_object_unref (data[0]); + g_object_unref (data[1]); + g_free (data[2]); + g_free (data); +} + +static void +run_data_free (gpointer _data) +{ + RunData* _data_; + _data_ = _data; + g_slice_free (RunData, _data_); +} + +void +run (GAsyncReadyCallback _callback_, + gpointer _user_data_) +{ + RunData* _data_; + _data_ = g_slice_new0 (RunData); + _data_->_async_result = g_task_new (NULL, NULL, _callback_, _user_data_); + g_task_set_task_data (_data_->_async_result, _data_, run_data_free); + run_co (_data_); +} + +void +run_finish (GAsyncResult* _res_) +{ + RunData* _data_; + _data_ = g_task_propagate_pointer (G_TASK (_res_), NULL); +} + +static void +run_ready (GObject* source_object, + GAsyncResult* _res_, + gpointer _user_data_) +{ + RunData* _data_; + _data_ = _user_data_; + _data_->_source_object_ = source_object; + _data_->_res_ = _res_; + run_co (_data_); +} + +static gboolean +run_co (RunData* _data_) +{ + switch (_data_->_state_) { + case 0: + goto _state_0; + case 1: + goto _state_1; + case 2: + goto _state_2; + case 3: + goto _state_3; + case 4: + goto _state_4; + default: + g_assert_not_reached (); + } + _state_0: + _data_->_state_ = 1; + g_async_initable_new_async (TYPE_TEST_PROXY, 0, NULL, run_ready, _data_, "g-flags", 0, "g-name", "org.example.Test", "g-bus-type", G_BUS_TYPE_SESSION, "g-object-path", "/org/example/test", "g-interface-name", "org.example.Test", NULL); + return FALSE; + _state_1: + _data_->_tmp0_ = (Test*) g_async_initable_new_finish ((GAsyncInitable *) _data_->_source_object_, _data_->_res_, &_data_->_inner_error0_); + _data_->test = (Test*) _data_->_tmp0_; + if (G_UNLIKELY (_data_->_inner_error0_ != NULL)) { + g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _data_->_inner_error0_->message, g_quark_to_string (_data_->_inner_error0_->domain), _data_->_inner_error0_->code); + g_clear_error (&_data_->_inner_error0_); + g_object_unref (_data_->_async_result); + return FALSE; + } + _data_->_tmp1_ = _data_->test; + _data_->_state_ = 2; + test_test_void (_data_->_tmp1_, run_ready, _data_); + return FALSE; + _state_2: + test_test_void_finish (_data_->_tmp1_, _data_->_res_, &_data_->_inner_error0_); + if (G_UNLIKELY (_data_->_inner_error0_ != NULL)) { + _g_object_unref0 (_data_->test); + g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _data_->_inner_error0_->message, g_quark_to_string (_data_->_inner_error0_->domain), _data_->_inner_error0_->code); + g_clear_error (&_data_->_inner_error0_); + g_object_unref (_data_->_async_result); + return FALSE; + } + _data_->_tmp3_ = _data_->test; + _data_->_tmp4_ = 0; + _data_->_state_ = 3; + test_test_int (_data_->_tmp3_, 42, run_ready, _data_); + return FALSE; + _state_3: + _data_->_tmp5_ = test_test_int_finish (_data_->_tmp3_, _data_->_res_, &_data_->_tmp4_, &_data_->_inner_error0_); + _data_->j = _data_->_tmp4_; + _data_->_tmp2_ = _data_->_tmp5_; + if (G_UNLIKELY (_data_->_inner_error0_ != NULL)) { + _g_object_unref0 (_data_->test); + g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _data_->_inner_error0_->message, g_quark_to_string (_data_->_inner_error0_->domain), _data_->_inner_error0_->code); + g_clear_error (&_data_->_inner_error0_); + g_object_unref (_data_->_async_result); + return FALSE; + } + _data_->k = _data_->_tmp2_; + _vala_assert (_data_->j == 23, "j == 23"); + _vala_assert (_data_->k == 11, "k == 11"); + _data_->_tmp7_ = _data_->test; + _data_->_tmp8_ = NULL; + _data_->_state_ = 4; + test_test_string (_data_->_tmp7_, "hello", run_ready, _data_); + return FALSE; + _state_4: + _data_->_tmp9_ = test_test_string_finish (_data_->_tmp7_, _data_->_res_, &_data_->_tmp8_, &_data_->_inner_error0_); + _g_free0 (_data_->t); + _data_->t = _data_->_tmp8_; + _data_->_tmp6_ = _data_->_tmp9_; + if (G_UNLIKELY (_data_->_inner_error0_ != NULL)) { + _g_free0 (_data_->u); + _g_free0 (_data_->t); + _g_object_unref0 (_data_->test); + g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _data_->_inner_error0_->message, g_quark_to_string (_data_->_inner_error0_->domain), _data_->_inner_error0_->code); + g_clear_error (&_data_->_inner_error0_); + g_object_unref (_data_->_async_result); + return FALSE; + } + _data_->_tmp10_ = _data_->_tmp6_; + _data_->_tmp6_ = NULL; + _g_free0 (_data_->u); + _data_->u = _data_->_tmp10_; + _data_->_tmp11_ = _data_->t; + _vala_assert (g_strcmp0 (_data_->_tmp11_, "world") == 0, "t == \"world\""); + _data_->_tmp12_ = _data_->u; + _vala_assert (g_strcmp0 (_data_->_tmp12_, "vala") == 0, "u == \"vala\""); + _data_->_tmp13_ = main_loop; + g_main_loop_quit (_data_->_tmp13_); + _g_free0 (_data_->_tmp6_); + _g_free0 (_data_->u); + _g_free0 (_data_->t); + _g_object_unref0 (_data_->test); + g_task_return_pointer (_data_->_async_result, _data_, NULL); + if (_data_->_state_ != 0) { + while (!g_task_get_completed (_data_->_async_result)) { + g_main_context_iteration (g_task_get_context (_data_->_async_result), TRUE); + } + } + g_object_unref (_data_->_async_result); + return FALSE; +} + +static void +_vala_main (void) +{ + GMainLoop* _tmp0_; + GMainLoop* _tmp1_; + run (NULL, NULL); + _tmp0_ = g_main_loop_new (NULL, FALSE); + _g_main_loop_unref0 (main_loop); + main_loop = _tmp0_; + _tmp1_ = main_loop; + g_main_loop_run (_tmp1_); +} + +int +main (int argc, + char ** argv) +{ + _vala_main (); + return 0; +} + diff --git a/tests/dbus/async_server.c-expected b/tests/dbus/async_server.c-expected new file mode 100644 index 000000000..dae62a88f --- /dev/null +++ b/tests/dbus/async_server.c-expected @@ -0,0 +1,885 @@ +/* dbus_async_server.c generated by valac, the Vala compiler + * generated from dbus_async_server.vala, do not modify */ + +#include <glib-object.h> +#include <gio/gio.h> +#include <glib.h> +#include <stdlib.h> +#include <string.h> + +#if !defined(VALA_EXTERN) +#if defined(_MSC_VER) +#define VALA_EXTERN __declspec(dllexport) extern +#elif __GNUC__ >= 4 +#define VALA_EXTERN __attribute__((visibility("default"))) extern +#else +#define VALA_EXTERN extern +#endif +#endif + +#define TYPE_TEST (test_get_type ()) +#define TEST(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TYPE_TEST, Test)) +#define TEST_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), TYPE_TEST, TestClass)) +#define IS_TEST(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TYPE_TEST)) +#define IS_TEST_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), TYPE_TEST)) +#define TEST_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), TYPE_TEST, TestClass)) + +typedef struct _Test Test; +typedef struct _TestClass TestClass; +typedef struct _TestPrivate TestPrivate; +enum { + TEST_0_PROPERTY, + TEST_NUM_PROPERTIES +}; +static GParamSpec* test_properties[TEST_NUM_PROPERTIES]; +#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL))) +typedef struct _TestTestVoidData TestTestVoidData; +typedef struct _TestTestIntData TestTestIntData; +#define _g_free0(var) (var = (g_free (var), NULL)) +typedef struct _TestTestStringData TestTestStringData; +typedef struct _TestTestVoidReadyData TestTestVoidReadyData; +typedef struct _TestTestIntReadyData TestTestIntReadyData; +typedef struct _TestTestStringReadyData TestTestStringReadyData; +#define _g_variant_unref0(var) ((var == NULL) ? NULL : (var = (g_variant_unref (var), NULL))) +#define _g_main_loop_unref0(var) ((var == NULL) ? NULL : (var = (g_main_loop_unref (var), NULL))) +#define _vala_assert(expr, msg) if G_LIKELY (expr) ; else g_assertion_message_expr (G_LOG_DOMAIN, __FILE__, __LINE__, G_STRFUNC, msg); +#define _vala_return_if_fail(expr, msg) if G_LIKELY (expr) ; else { g_return_if_fail_warning (G_LOG_DOMAIN, G_STRFUNC, msg); return; } +#define _vala_return_val_if_fail(expr, msg, val) if G_LIKELY (expr) ; else { g_return_if_fail_warning (G_LOG_DOMAIN, G_STRFUNC, msg); return val; } +#define _vala_warn_if_fail(expr, msg) if G_LIKELY (expr) ; else g_warn_message (G_LOG_DOMAIN, __FILE__, __LINE__, G_STRFUNC, msg); + +struct _Test { + GObject parent_instance; + TestPrivate * priv; +}; + +struct _TestClass { + GObjectClass parent_class; +}; + +struct _TestTestVoidData { + int _state_; + GObject* _source_object_; + GAsyncResult* _res_; + GTask* _async_result; + Test* self; +}; + +struct _TestTestIntData { + int _state_; + GObject* _source_object_; + GAsyncResult* _res_; + GTask* _async_result; + Test* self; + gint i; + gint j; + gint result; +}; + +struct _TestTestStringData { + int _state_; + GObject* _source_object_; + GAsyncResult* _res_; + GTask* _async_result; + Test* self; + gchar* s; + gchar* t; + gchar* result; + gchar* _tmp0_; + gchar* _tmp1_; +}; + +struct _TestTestVoidReadyData { + GDBusMethodInvocation* _invocation_; +}; + +struct _TestTestIntReadyData { + GDBusMethodInvocation* _invocation_; + gint i; +}; + +struct _TestTestStringReadyData { + GDBusMethodInvocation* _invocation_; + gchar* s; +}; + +static gpointer test_parent_class = NULL; +VALA_EXTERN GMainLoop* main_loop; +GMainLoop* main_loop = NULL; + +VALA_EXTERN GType test_get_type (void) G_GNUC_CONST ; +G_DEFINE_AUTOPTR_CLEANUP_FUNC (Test, g_object_unref) +VALA_EXTERN guint test_register_object (void* object, + GDBusConnection* connection, + const gchar* path, + GError** error); +static void test_test_void_data_free (gpointer _data); +VALA_EXTERN void test_test_void (Test* self, + GAsyncReadyCallback _callback_, + gpointer _user_data_); +VALA_EXTERN void test_test_void_finish (Test* self, + GAsyncResult* _res_); +static gboolean test_test_void_co (TestTestVoidData* _data_); +static gboolean _test_test_void_co_gsource_func (gpointer self); +static void test_test_int_data_free (gpointer _data); +VALA_EXTERN void test_test_int (Test* self, + gint i, + GAsyncReadyCallback _callback_, + gpointer _user_data_); +VALA_EXTERN gint test_test_int_finish (Test* self, + GAsyncResult* _res_, + gint* j); +static gboolean test_test_int_co (TestTestIntData* _data_); +static gboolean _test_test_int_co_gsource_func (gpointer self); +static void test_test_string_data_free (gpointer _data); +VALA_EXTERN void test_test_string (Test* self, + const gchar* s, + GAsyncReadyCallback _callback_, + gpointer _user_data_); +VALA_EXTERN gchar* test_test_string_finish (Test* self, + GAsyncResult* _res_, + gchar* * t); +static gboolean test_test_string_co (TestTestStringData* _data_); +static gboolean _test_test_string_co_gsource_func (gpointer self); +VALA_EXTERN Test* test_new (void); +VALA_EXTERN Test* test_construct (GType object_type); +static GType test_get_type_once (void); +static void _dbus_test_test_void (Test* self, + GVariant* _parameters_, + GDBusMethodInvocation* invocation); +static void _dbus_test_test_void_ready (GObject * source_object, + GAsyncResult * _res_, + gpointer _user_data_); +static void _dbus_test_test_int (Test* self, + GVariant* _parameters_, + GDBusMethodInvocation* invocation); +static void _dbus_test_test_int_ready (GObject * source_object, + GAsyncResult * _res_, + gpointer _user_data_); +static void _dbus_test_test_string (Test* self, + GVariant* _parameters_, + GDBusMethodInvocation* invocation); +static void _dbus_test_test_string_ready (GObject * source_object, + GAsyncResult * _res_, + gpointer _user_data_); +static void test_dbus_interface_method_call (GDBusConnection* connection, + const gchar* sender, + const gchar* object_path, + const gchar* interface_name, + const gchar* method_name, + GVariant* parameters, + GDBusMethodInvocation* invocation, + gpointer user_data); +static GVariant* test_dbus_interface_get_property (GDBusConnection* connection, + const gchar* sender, + const gchar* object_path, + const gchar* interface_name, + const gchar* property_name, + GError** error, + gpointer user_data); +static gboolean test_dbus_interface_set_property (GDBusConnection* connection, + const gchar* sender, + const gchar* object_path, + const gchar* interface_name, + const gchar* property_name, + GVariant* value, + GError** error, + gpointer user_data); +static void _test_unregister_object (gpointer user_data); +VALA_EXTERN void client_exit (GPid pid, + gint status); +static void _vala_main (void); +static guint _variant_get1 (GVariant* value); +static void _client_exit_gchild_watch_func (GPid pid, + gint wait_status, + gpointer self); +static void _vala_array_destroy (gpointer array, + gssize array_length, + GDestroyNotify destroy_func); +static void _vala_array_free (gpointer array, + gssize array_length, + GDestroyNotify destroy_func); + +static const GDBusArgInfo * const _test_dbus_arg_info_test_void_in[] = {NULL}; +static const GDBusArgInfo * const _test_dbus_arg_info_test_void_out[] = {NULL}; +static const GDBusMethodInfo _test_dbus_method_info_test_void = {-1, "TestVoid", (GDBusArgInfo **) (&_test_dbus_arg_info_test_void_in), (GDBusArgInfo **) (&_test_dbus_arg_info_test_void_out), NULL}; +static const GDBusArgInfo _test_dbus_arg_info_test_int_i = {-1, "i", "i", NULL}; +static const GDBusArgInfo _test_dbus_arg_info_test_int_j = {-1, "j", "i", NULL}; +static const GDBusArgInfo _test_dbus_arg_info_test_int_result = {-1, "result", "i", NULL}; +static const GDBusArgInfo * const _test_dbus_arg_info_test_int_in[] = {&_test_dbus_arg_info_test_int_i, NULL}; +static const GDBusArgInfo * const _test_dbus_arg_info_test_int_out[] = {&_test_dbus_arg_info_test_int_j, &_test_dbus_arg_info_test_int_result, NULL}; +static const GDBusMethodInfo _test_dbus_method_info_test_int = {-1, "TestInt", (GDBusArgInfo **) (&_test_dbus_arg_info_test_int_in), (GDBusArgInfo **) (&_test_dbus_arg_info_test_int_out), NULL}; +static const GDBusArgInfo _test_dbus_arg_info_test_string_s = {-1, "s", "s", NULL}; +static const GDBusArgInfo _test_dbus_arg_info_test_string_t = {-1, "t", "s", NULL}; +static const GDBusArgInfo _test_dbus_arg_info_test_string_result = {-1, "result", "s", NULL}; +static const GDBusArgInfo * const _test_dbus_arg_info_test_string_in[] = {&_test_dbus_arg_info_test_string_s, NULL}; +static const GDBusArgInfo * const _test_dbus_arg_info_test_string_out[] = {&_test_dbus_arg_info_test_string_t, &_test_dbus_arg_info_test_string_result, NULL}; +static const GDBusMethodInfo _test_dbus_method_info_test_string = {-1, "TestString", (GDBusArgInfo **) (&_test_dbus_arg_info_test_string_in), (GDBusArgInfo **) (&_test_dbus_arg_info_test_string_out), NULL}; +static const GDBusMethodInfo * const _test_dbus_method_info[] = {&_test_dbus_method_info_test_void, &_test_dbus_method_info_test_int, &_test_dbus_method_info_test_string, NULL}; +static const GDBusSignalInfo * const _test_dbus_signal_info[] = {NULL}; +static const GDBusPropertyInfo * const _test_dbus_property_info[] = {NULL}; +static const GDBusInterfaceInfo _test_dbus_interface_info = {-1, "org.example.Test", (GDBusMethodInfo **) (&_test_dbus_method_info), (GDBusSignalInfo **) (&_test_dbus_signal_info), (GDBusPropertyInfo **) (&_test_dbus_property_info), NULL}; +static const GDBusInterfaceVTable _test_dbus_interface_vtable = {test_dbus_interface_method_call, test_dbus_interface_get_property, test_dbus_interface_set_property}; + +static void +test_test_void_data_free (gpointer _data) +{ + TestTestVoidData* _data_; + _data_ = _data; + _g_object_unref0 (_data_->self); + g_slice_free (TestTestVoidData, _data_); +} + +static gpointer +_g_object_ref0 (gpointer self) +{ + return self ? g_object_ref (self) : NULL; +} + +void +test_test_void (Test* self, + GAsyncReadyCallback _callback_, + gpointer _user_data_) +{ + TestTestVoidData* _data_; + Test* _tmp0_; + g_return_if_fail (IS_TEST (self)); + _data_ = g_slice_new0 (TestTestVoidData); + _data_->_async_result = g_task_new (G_OBJECT (self), NULL, _callback_, _user_data_); + g_task_set_task_data (_data_->_async_result, _data_, test_test_void_data_free); + _tmp0_ = _g_object_ref0 (self); + _data_->self = _tmp0_; + test_test_void_co (_data_); +} + +void +test_test_void_finish (Test* self, + GAsyncResult* _res_) +{ + TestTestVoidData* _data_; + _data_ = g_task_propagate_pointer (G_TASK (_res_), NULL); +} + +static gboolean +_test_test_void_co_gsource_func (gpointer self) +{ + gboolean result; + result = test_test_void_co (self); + return result; +} + +static gboolean +test_test_void_co (TestTestVoidData* _data_) +{ + switch (_data_->_state_) { + case 0: + goto _state_0; + case 1: + goto _state_1; + default: + g_assert_not_reached (); + } + _state_0: + g_idle_add_full (G_PRIORITY_DEFAULT_IDLE, _test_test_void_co_gsource_func, _data_, NULL); + _data_->_state_ = 1; + return FALSE; + _state_1: + ; + g_task_return_pointer (_data_->_async_result, _data_, NULL); + if (_data_->_state_ != 0) { + while (!g_task_get_completed (_data_->_async_result)) { + g_main_context_iteration (g_task_get_context (_data_->_async_result), TRUE); + } + } + g_object_unref (_data_->_async_result); + return FALSE; +} + +static void +test_test_int_data_free (gpointer _data) +{ + TestTestIntData* _data_; + _data_ = _data; + _g_object_unref0 (_data_->self); + g_slice_free (TestTestIntData, _data_); +} + +void +test_test_int (Test* self, + gint i, + GAsyncReadyCallback _callback_, + gpointer _user_data_) +{ + TestTestIntData* _data_; + Test* _tmp0_; + g_return_if_fail (IS_TEST (self)); + _data_ = g_slice_new0 (TestTestIntData); + _data_->_async_result = g_task_new (G_OBJECT (self), NULL, _callback_, _user_data_); + g_task_set_task_data (_data_->_async_result, _data_, test_test_int_data_free); + _tmp0_ = _g_object_ref0 (self); + _data_->self = _tmp0_; + _data_->i = i; + test_test_int_co (_data_); +} + +gint +test_test_int_finish (Test* self, + GAsyncResult* _res_, + gint* j) +{ + gint result; + TestTestIntData* _data_; + _data_ = g_task_propagate_pointer (G_TASK (_res_), NULL); + if (j) { + *j = _data_->j; + } + result = _data_->result; + return result; +} + +static gboolean +_test_test_int_co_gsource_func (gpointer self) +{ + gboolean result; + result = test_test_int_co (self); + return result; +} + +static gboolean +test_test_int_co (TestTestIntData* _data_) +{ + switch (_data_->_state_) { + case 0: + goto _state_0; + case 1: + goto _state_1; + default: + g_assert_not_reached (); + } + _state_0: + _vala_assert (_data_->i == 42, "i == 42"); + g_idle_add_full (G_PRIORITY_DEFAULT_IDLE, _test_test_int_co_gsource_func, _data_, NULL); + _data_->_state_ = 1; + return FALSE; + _state_1: + ; + _data_->j = 23; + _data_->result = 11; + g_task_return_pointer (_data_->_async_result, _data_, NULL); + if (_data_->_state_ != 0) { + while (!g_task_get_completed (_data_->_async_result)) { + g_main_context_iteration (g_task_get_context (_data_->_async_result), TRUE); + } + } + g_object_unref (_data_->_async_result); + return FALSE; +} + +static void +test_test_string_data_free (gpointer _data) +{ + TestTestStringData* _data_; + _data_ = _data; + _g_free0 (_data_->s); + _g_free0 (_data_->result); + _g_object_unref0 (_data_->self); + g_slice_free (TestTestStringData, _data_); +} + +void +test_test_string (Test* self, + const gchar* s, + GAsyncReadyCallback _callback_, + gpointer _user_data_) +{ + TestTestStringData* _data_; + Test* _tmp0_; + gchar* _tmp1_; + g_return_if_fail (IS_TEST (self)); + g_return_if_fail (s != NULL); + _data_ = g_slice_new0 (TestTestStringData); + _data_->_async_result = g_task_new (G_OBJECT (self), NULL, _callback_, _user_data_); + g_task_set_task_data (_data_->_async_result, _data_, test_test_string_data_free); + _tmp0_ = _g_object_ref0 (self); + _data_->self = _tmp0_; + _tmp1_ = g_strdup (s); + _g_free0 (_data_->s); + _data_->s = _tmp1_; + test_test_string_co (_data_); +} + +gchar* +test_test_string_finish (Test* self, + GAsyncResult* _res_, + gchar* * t) +{ + gchar* result; + TestTestStringData* _data_; + _data_ = g_task_propagate_pointer (G_TASK (_res_), NULL); + if (t) { + *t = _data_->t; + } else { + _g_free0 (_data_->t); + } + _data_->t = NULL; + result = _data_->result; + _data_->result = NULL; + return result; +} + +static gboolean +_test_test_string_co_gsource_func (gpointer self) +{ + gboolean result; + result = test_test_string_co (self); + return result; +} + +static gboolean +test_test_string_co (TestTestStringData* _data_) +{ + switch (_data_->_state_) { + case 0: + goto _state_0; + case 1: + goto _state_1; + default: + g_assert_not_reached (); + } + _state_0: + _vala_assert (g_strcmp0 (_data_->s, "hello") == 0, "s == \"hello\""); + g_idle_add_full (G_PRIORITY_DEFAULT_IDLE, _test_test_string_co_gsource_func, _data_, NULL); + _data_->_state_ = 1; + return FALSE; + _state_1: + ; + _data_->_tmp0_ = g_strdup ("world"); + _g_free0 (_data_->t); + _data_->t = _data_->_tmp0_; + _data_->_tmp1_ = g_strdup ("vala"); + _data_->result = _data_->_tmp1_; + g_task_return_pointer (_data_->_async_result, _data_, NULL); + if (_data_->_state_ != 0) { + while (!g_task_get_completed (_data_->_async_result)) { + g_main_context_iteration (g_task_get_context (_data_->_async_result), TRUE); + } + } + g_object_unref (_data_->_async_result); + return FALSE; +} + +Test* +test_construct (GType object_type) +{ + Test * self = NULL; + self = (Test*) g_object_new (object_type, NULL); + return self; +} + +Test* +test_new (void) +{ + return test_construct (TYPE_TEST); +} + +static void +test_class_init (TestClass * klass, + gpointer klass_data) +{ + test_parent_class = g_type_class_peek_parent (klass); +} + +static void +test_instance_init (Test * self, + gpointer klass) +{ +} + +static GType +test_get_type_once (void) +{ + static const GTypeInfo g_define_type_info = { sizeof (TestClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) test_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (Test), 0, (GInstanceInitFunc) test_instance_init, NULL }; + GType test_type_id; + test_type_id = g_type_register_static (G_TYPE_OBJECT, "Test", &g_define_type_info, 0); + g_type_set_qdata (test_type_id, g_quark_from_static_string ("vala-dbus-register-object"), (void*) test_register_object); + return test_type_id; +} + +GType +test_get_type (void) +{ + static volatile gsize test_type_id__volatile = 0; + if (g_once_init_enter (&test_type_id__volatile)) { + GType test_type_id; + test_type_id = test_get_type_once (); + g_once_init_leave (&test_type_id__volatile, test_type_id); + } + return test_type_id__volatile; +} + +static void +_dbus_test_test_void (Test* self, + GVariant* _parameters_, + GDBusMethodInvocation* invocation) +{ + GVariantIter _arguments_iter; + TestTestVoidReadyData* _ready_data; + g_variant_iter_init (&_arguments_iter, _parameters_); + _ready_data = g_slice_new0 (TestTestVoidReadyData); + _ready_data->_invocation_ = invocation; + test_test_void (self, (GAsyncReadyCallback) _dbus_test_test_void_ready, _ready_data); +} + +static void +_dbus_test_test_void_ready (GObject * source_object, + GAsyncResult * _res_, + gpointer _user_data_) +{ + TestTestVoidReadyData* _ready_data; + GDBusMethodInvocation* invocation; + GError* error = NULL; + GDBusMessage* _reply_message = NULL; + GVariant* _reply; + GVariantBuilder _reply_builder; + _ready_data = _user_data_; + invocation = _ready_data->_invocation_; + test_test_void_finish ((Test*) source_object, _res_); + _reply_message = g_dbus_message_new_method_reply (g_dbus_method_invocation_get_message (invocation)); + g_variant_builder_init (&_reply_builder, G_VARIANT_TYPE_TUPLE); + _reply = g_variant_builder_end (&_reply_builder); + g_dbus_message_set_body (_reply_message, _reply); + g_dbus_connection_send_message (g_dbus_method_invocation_get_connection (invocation), _reply_message, G_DBUS_SEND_MESSAGE_FLAGS_NONE, NULL, NULL); + g_object_unref (invocation); + g_object_unref (_reply_message); + _error: + g_slice_free (TestTestVoidReadyData, _ready_data); +} + +static void +_dbus_test_test_int (Test* self, + GVariant* _parameters_, + GDBusMethodInvocation* invocation) +{ + GVariantIter _arguments_iter; + TestTestIntReadyData* _ready_data; + GVariant* _tmp0_; + g_variant_iter_init (&_arguments_iter, _parameters_); + _ready_data = g_slice_new0 (TestTestIntReadyData); + _ready_data->_invocation_ = invocation; + _tmp0_ = g_variant_iter_next_value (&_arguments_iter); + _ready_data->i = g_variant_get_int32 (_tmp0_); + g_variant_unref (_tmp0_); + test_test_int (self, _ready_data->i, (GAsyncReadyCallback) _dbus_test_test_int_ready, _ready_data); +} + +static void +_dbus_test_test_int_ready (GObject * source_object, + GAsyncResult * _res_, + gpointer _user_data_) +{ + TestTestIntReadyData* _ready_data; + GDBusMethodInvocation* invocation; + GError* error = NULL; + GDBusMessage* _reply_message = NULL; + GVariant* _reply; + GVariantBuilder _reply_builder; + gint j = 0; + gint result; + _ready_data = _user_data_; + invocation = _ready_data->_invocation_; + result = test_test_int_finish ((Test*) source_object, _res_, &j); + _reply_message = g_dbus_message_new_method_reply (g_dbus_method_invocation_get_message (invocation)); + g_variant_builder_init (&_reply_builder, G_VARIANT_TYPE_TUPLE); + g_variant_builder_add_value (&_reply_builder, g_variant_new_int32 (j)); + g_variant_builder_add_value (&_reply_builder, g_variant_new_int32 (result)); + _reply = g_variant_builder_end (&_reply_builder); + g_dbus_message_set_body (_reply_message, _reply); + g_dbus_connection_send_message (g_dbus_method_invocation_get_connection (invocation), _reply_message, G_DBUS_SEND_MESSAGE_FLAGS_NONE, NULL, NULL); + g_object_unref (invocation); + g_object_unref (_reply_message); + _error: + g_slice_free (TestTestIntReadyData, _ready_data); +} + +static void +_dbus_test_test_string (Test* self, + GVariant* _parameters_, + GDBusMethodInvocation* invocation) +{ + GVariantIter _arguments_iter; + TestTestStringReadyData* _ready_data; + GVariant* _tmp1_; + g_variant_iter_init (&_arguments_iter, _parameters_); + _ready_data = g_slice_new0 (TestTestStringReadyData); + _ready_data->_invocation_ = invocation; + _tmp1_ = g_variant_iter_next_value (&_arguments_iter); + _ready_data->s = g_variant_dup_string (_tmp1_, NULL); + g_variant_unref (_tmp1_); + test_test_string (self, _ready_data->s, (GAsyncReadyCallback) _dbus_test_test_string_ready, _ready_data); +} + +static void +_dbus_test_test_string_ready (GObject * source_object, + GAsyncResult * _res_, + gpointer _user_data_) +{ + TestTestStringReadyData* _ready_data; + GDBusMethodInvocation* invocation; + GError* error = NULL; + GDBusMessage* _reply_message = NULL; + GVariant* _reply; + GVariantBuilder _reply_builder; + gchar* t = NULL; + gchar* result; + _ready_data = _user_data_; + invocation = _ready_data->_invocation_; + result = test_test_string_finish ((Test*) source_object, _res_, &t); + _reply_message = g_dbus_message_new_method_reply (g_dbus_method_invocation_get_message (invocation)); + g_variant_builder_init (&_reply_builder, G_VARIANT_TYPE_TUPLE); + g_variant_builder_add_value (&_reply_builder, g_variant_new_string (t)); + g_variant_builder_add_value (&_reply_builder, g_variant_new_string (result)); + _g_free0 (result); + _reply = g_variant_builder_end (&_reply_builder); + g_dbus_message_set_body (_reply_message, _reply); + g_dbus_connection_send_message (g_dbus_method_invocation_get_connection (invocation), _reply_message, G_DBUS_SEND_MESSAGE_FLAGS_NONE, NULL, NULL); + g_object_unref (invocation); + g_object_unref (_reply_message); + _error: + _g_free0 (_ready_data->s); + _g_free0 (t); + g_slice_free (TestTestStringReadyData, _ready_data); +} + +static void +test_dbus_interface_method_call (GDBusConnection* connection, + const gchar* sender, + const gchar* object_path, + const gchar* interface_name, + const gchar* method_name, + GVariant* parameters, + GDBusMethodInvocation* invocation, + gpointer user_data) +{ + gpointer* data; + gpointer object; + data = user_data; + object = data[0]; + if (strcmp (method_name, "TestVoid") == 0) { + _dbus_test_test_void (object, parameters, invocation); + } else if (strcmp (method_name, "TestInt") == 0) { + _dbus_test_test_int (object, parameters, invocation); + } else if (strcmp (method_name, "TestString") == 0) { + _dbus_test_test_string (object, parameters, invocation); + } else { + g_object_unref (invocation); + } +} + +static GVariant* +test_dbus_interface_get_property (GDBusConnection* connection, + const gchar* sender, + const gchar* object_path, + const gchar* interface_name, + const gchar* property_name, + GError** error, + gpointer user_data) +{ + gpointer* data; + gpointer object; + data = user_data; + object = data[0]; + return NULL; +} + +static gboolean +test_dbus_interface_set_property (GDBusConnection* connection, + const gchar* sender, + const gchar* object_path, + const gchar* interface_name, + const gchar* property_name, + GVariant* value, + GError** error, + gpointer user_data) +{ + gpointer* data; + gpointer object; + data = user_data; + object = data[0]; + return FALSE; +} + +guint +test_register_object (gpointer object, + GDBusConnection* connection, + const gchar* path, + GError** error) +{ + guint result; + gpointer *data; + data = g_new (gpointer, 3); + data[0] = g_object_ref (object); + data[1] = g_object_ref (connection); + data[2] = g_strdup (path); + result = g_dbus_connection_register_object (connection, path, (GDBusInterfaceInfo *) (&_test_dbus_interface_info), &_test_dbus_interface_vtable, data, _test_unregister_object, error); + if (!result) { + return 0; + } + return result; +} + +static void +_test_unregister_object (gpointer user_data) +{ + gpointer* data; + data = user_data; + g_object_unref (data[0]); + g_object_unref (data[1]); + g_free (data[2]); + g_free (data); +} + +void +client_exit (GPid pid, + gint status) +{ + GMainLoop* _tmp0_; + _vala_assert (status == 0, "status == 0"); + _tmp0_ = main_loop; + g_main_loop_quit (_tmp0_); +} + +static guint +_variant_get1 (GVariant* value) +{ + return g_variant_get_uint32 (value); +} + +static void +_client_exit_gchild_watch_func (GPid pid, + gint wait_status, + gpointer self) +{ + client_exit (pid, wait_status); +} + +static void +_vala_main (void) +{ + GDBusConnection* conn = NULL; + GDBusConnection* _tmp0_; + GDBusConnection* _tmp1_; + Test* _tmp2_; + Test* _tmp3_; + GVariant* request_result = NULL; + GDBusConnection* _tmp4_; + GVariant* _tmp5_; + GVariant* _tmp6_; + GVariant* _tmp7_; + GVariant* _tmp8_; + GVariant* _tmp9_; + GVariant* _tmp10_; + GVariant* _tmp11_; + guint _tmp12_; + GPid client_pid = 0; + gchar* _tmp13_; + gchar** _tmp14_; + gchar** _tmp15_; + gint _tmp15__length1; + GPid _tmp16_ = 0; + GMainLoop* _tmp17_; + GMainLoop* _tmp18_; + GError* _inner_error0_ = NULL; + _tmp0_ = g_bus_get_sync (G_BUS_TYPE_SESSION, NULL, &_inner_error0_); + conn = _tmp0_; + if (G_UNLIKELY (_inner_error0_ != NULL)) { + g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error0_->message, g_quark_to_string (_inner_error0_->domain), _inner_error0_->code); + g_clear_error (&_inner_error0_); + return; + } + _tmp1_ = conn; + _tmp2_ = test_new (); + _tmp3_ = _tmp2_; + test_register_object (_tmp3_, _tmp1_, "/org/example/test", &_inner_error0_); + _g_object_unref0 (_tmp3_); + if (G_UNLIKELY (_inner_error0_ != NULL)) { + _g_object_unref0 (conn); + g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error0_->message, g_quark_to_string (_inner_error0_->domain), _inner_error0_->code); + g_clear_error (&_inner_error0_); + return; + } + _tmp4_ = conn; + _tmp5_ = g_variant_new ("(su)", "org.example.Test", 0x4, NULL); + g_variant_ref_sink (_tmp5_); + _tmp6_ = _tmp5_; + _tmp7_ = g_dbus_connection_call_sync (_tmp4_, "org.freedesktop.DBus", "/org/freedesktop/DBus", "org.freedesktop.DBus", "RequestName", _tmp6_, NULL, 0, -1, NULL, &_inner_error0_); + _tmp8_ = _tmp7_; + _g_variant_unref0 (_tmp6_); + request_result = _tmp8_; + if (G_UNLIKELY (_inner_error0_ != NULL)) { + _g_object_unref0 (conn); + g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error0_->message, g_quark_to_string (_inner_error0_->domain), _inner_error0_->code); + g_clear_error (&_inner_error0_); + return; + } + _tmp9_ = request_result; + _tmp10_ = g_variant_get_child_value (_tmp9_, (gsize) 0); + _tmp11_ = _tmp10_; + _tmp12_ = _variant_get1 (_tmp11_); + _vala_assert (_tmp12_ == ((guint) 1), "(uint) request_result.get_child_value (0) == 1"); + _g_variant_unref0 (_tmp11_); + _tmp13_ = g_strdup ("dbus_async_client"); + _tmp14_ = g_new0 (gchar*, 1 + 1); + _tmp14_[0] = _tmp13_; + _tmp15_ = _tmp14_; + _tmp15__length1 = 1; + g_spawn_async (NULL, _tmp15_, NULL, G_SPAWN_DO_NOT_REAP_CHILD, NULL, NULL, &_tmp16_, &_inner_error0_); + client_pid = _tmp16_; + _tmp15_ = (_vala_array_free (_tmp15_, _tmp15__length1, (GDestroyNotify) g_free), NULL); + if (G_UNLIKELY (_inner_error0_ != NULL)) { + _g_variant_unref0 (request_result); + _g_object_unref0 (conn); + g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error0_->message, g_quark_to_string (_inner_error0_->domain), _inner_error0_->code); + g_clear_error (&_inner_error0_); + return; + } + g_child_watch_add_full (G_PRIORITY_DEFAULT_IDLE, client_pid, _client_exit_gchild_watch_func, NULL, NULL); + _tmp17_ = g_main_loop_new (NULL, FALSE); + _g_main_loop_unref0 (main_loop); + main_loop = _tmp17_; + _tmp18_ = main_loop; + g_main_loop_run (_tmp18_); + _g_variant_unref0 (request_result); + _g_object_unref0 (conn); +} + +int +main (int argc, + char ** argv) +{ + _vala_main (); + return 0; +} + +static void +_vala_array_destroy (gpointer array, + gssize array_length, + GDestroyNotify destroy_func) +{ + if ((array != NULL) && (destroy_func != NULL)) { + gssize i; + for (i = 0; i < array_length; i = i + 1) { + if (((gpointer*) array)[i] != NULL) { + destroy_func (((gpointer*) array)[i]); + } + } + } +} + +static void +_vala_array_free (gpointer array, + gssize array_length, + GDestroyNotify destroy_func) +{ + _vala_array_destroy (array, array_length, destroy_func); + g_free (array); +} + diff --git a/tests/dbus/basic-types_client.c-expected b/tests/dbus/basic-types_client.c-expected new file mode 100644 index 000000000..6d1d4b65c --- /dev/null +++ b/tests/dbus/basic-types_client.c-expected @@ -0,0 +1,872 @@ +/* dbus_basic_types_client.c generated by valac, the Vala compiler + * generated from dbus_basic_types_client.vala, do not modify */ + +#include <glib-object.h> +#include <gio/gio.h> +#include <glib.h> +#include <stdlib.h> +#include <string.h> + +#if !defined(VALA_EXTERN) +#if defined(_MSC_VER) +#define VALA_EXTERN __declspec(dllexport) extern +#elif __GNUC__ >= 4 +#define VALA_EXTERN __attribute__((visibility("default"))) extern +#else +#define VALA_EXTERN extern +#endif +#endif + +#define TYPE_TEST (test_get_type ()) +#define TEST(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TYPE_TEST, Test)) +#define IS_TEST(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TYPE_TEST)) +#define TEST_GET_INTERFACE(obj) (G_TYPE_INSTANCE_GET_INTERFACE ((obj), TYPE_TEST, TestIface)) + +typedef struct _Test Test; +typedef struct _TestIface TestIface; + +#define TYPE_TEST_PROXY (test_proxy_get_type ()) +typedef GDBusProxy TestProxy; +typedef GDBusProxyClass TestProxyClass; +#define _g_free0(var) (var = (g_free (var), NULL)) +#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL))) +#define _vala_assert(expr, msg) if G_LIKELY (expr) ; else g_assertion_message_expr (G_LOG_DOMAIN, __FILE__, __LINE__, G_STRFUNC, msg); +#define _vala_return_if_fail(expr, msg) if G_LIKELY (expr) ; else { g_return_if_fail_warning (G_LOG_DOMAIN, G_STRFUNC, msg); return; } +#define _vala_return_val_if_fail(expr, msg, val) if G_LIKELY (expr) ; else { g_return_if_fail_warning (G_LOG_DOMAIN, G_STRFUNC, msg); return val; } +#define _vala_warn_if_fail(expr, msg) if G_LIKELY (expr) ; else g_warn_message (G_LOG_DOMAIN, __FILE__, __LINE__, G_STRFUNC, msg); + +struct _TestIface { + GTypeInterface parent_iface; + void (*test_void) (Test* self, GError** error); + gint (*test_int) (Test* self, gint i, gint* j, GError** error); + gchar* (*test_string) (Test* self, const gchar* s, gchar* * t, GError** error); + gchar* (*get_test_property) (Test* self); + void (*set_test_property) (Test* self, const gchar* value); + gint (*get_test_int_property) (Test* self); + void (*set_test_int_property) (Test* self, gint value); +}; + +VALA_EXTERN GType test_proxy_get_type (void) G_GNUC_CONST ; +VALA_EXTERN guint test_register_object (void* object, + GDBusConnection* connection, + const gchar* path, + GError** error); +VALA_EXTERN GType test_get_type (void) G_GNUC_CONST ; +VALA_EXTERN void test_test_void (Test* self, + GError** error); +VALA_EXTERN gint test_test_int (Test* self, + gint i, + gint* j, + GError** error); +VALA_EXTERN gchar* test_test_string (Test* self, + const gchar* s, + gchar* * t, + GError** error); +VALA_EXTERN gchar* test_get_test_property (Test* self); +VALA_EXTERN void test_set_test_property (Test* self, + const gchar* value); +VALA_EXTERN gint test_get_test_int_property (Test* self); +VALA_EXTERN void test_set_test_int_property (Test* self, + gint value); +static GType test_get_type_once (void); +static void test_proxy_g_signal (GDBusProxy* proxy, + const gchar* sender_name, + const gchar* signal_name, + GVariant* parameters); +static void test_proxy_test_void (Test* self, + GError** error); +static gint test_proxy_test_int (Test* self, + gint i, + gint* j, + GError** error); +static gchar* test_proxy_test_string (Test* self, + const gchar* s, + gchar* * t, + GError** error); +static gchar* test_dbus_proxy_get_test_property (Test* self); +static void test_dbus_proxy_set_test_property (Test* self, + const gchar* value); +static gint test_dbus_proxy_get_test_int_property (Test* self); +static void test_dbus_proxy_set_test_int_property (Test* self, + gint value); +static void test_proxy_test_interface_init (TestIface* iface); +static void _dbus_test_test_void (Test* self, + GVariant* _parameters_, + GDBusMethodInvocation* invocation); +static void _dbus_test_test_int (Test* self, + GVariant* _parameters_, + GDBusMethodInvocation* invocation); +static void _dbus_test_test_string (Test* self, + GVariant* _parameters_, + GDBusMethodInvocation* invocation); +static void test_dbus_interface_method_call (GDBusConnection* connection, + const gchar* sender, + const gchar* object_path, + const gchar* interface_name, + const gchar* method_name, + GVariant* parameters, + GDBusMethodInvocation* invocation, + gpointer user_data); +static GVariant* test_dbus_interface_get_property (GDBusConnection* connection, + const gchar* sender, + const gchar* object_path, + const gchar* interface_name, + const gchar* property_name, + GError** error, + gpointer user_data); +static GVariant* _dbus_test_get_test_property (Test* self); +static GVariant* _dbus_test_get_test_int_property (Test* self); +static gboolean test_dbus_interface_set_property (GDBusConnection* connection, + const gchar* sender, + const gchar* object_path, + const gchar* interface_name, + const gchar* property_name, + GVariant* value, + GError** error, + gpointer user_data); +static void _dbus_test_set_test_property (Test* self, + GVariant* _value); +static void _dbus_test_set_test_int_property (Test* self, + GVariant* _value); +static void _test_unregister_object (gpointer user_data); +static void _vala_main (void); + +static const GDBusArgInfo * const _test_dbus_arg_info_test_void_in[] = {NULL}; +static const GDBusArgInfo * const _test_dbus_arg_info_test_void_out[] = {NULL}; +static const GDBusMethodInfo _test_dbus_method_info_test_void = {-1, "TestVoid", (GDBusArgInfo **) (&_test_dbus_arg_info_test_void_in), (GDBusArgInfo **) (&_test_dbus_arg_info_test_void_out), NULL}; +static const GDBusArgInfo _test_dbus_arg_info_test_int_i = {-1, "i", "i", NULL}; +static const GDBusArgInfo _test_dbus_arg_info_test_int_j = {-1, "j", "i", NULL}; +static const GDBusArgInfo _test_dbus_arg_info_test_int_result = {-1, "result", "i", NULL}; +static const GDBusArgInfo * const _test_dbus_arg_info_test_int_in[] = {&_test_dbus_arg_info_test_int_i, NULL}; +static const GDBusArgInfo * const _test_dbus_arg_info_test_int_out[] = {&_test_dbus_arg_info_test_int_j, &_test_dbus_arg_info_test_int_result, NULL}; +static const GDBusMethodInfo _test_dbus_method_info_test_int = {-1, "TestInt", (GDBusArgInfo **) (&_test_dbus_arg_info_test_int_in), (GDBusArgInfo **) (&_test_dbus_arg_info_test_int_out), NULL}; +static const GDBusArgInfo _test_dbus_arg_info_test_string_s = {-1, "s", "s", NULL}; +static const GDBusArgInfo _test_dbus_arg_info_test_string_t = {-1, "t", "s", NULL}; +static const GDBusArgInfo _test_dbus_arg_info_test_string_result = {-1, "result", "s", NULL}; +static const GDBusArgInfo * const _test_dbus_arg_info_test_string_in[] = {&_test_dbus_arg_info_test_string_s, NULL}; +static const GDBusArgInfo * const _test_dbus_arg_info_test_string_out[] = {&_test_dbus_arg_info_test_string_t, &_test_dbus_arg_info_test_string_result, NULL}; +static const GDBusMethodInfo _test_dbus_method_info_test_string = {-1, "TestString", (GDBusArgInfo **) (&_test_dbus_arg_info_test_string_in), (GDBusArgInfo **) (&_test_dbus_arg_info_test_string_out), NULL}; +static const GDBusMethodInfo * const _test_dbus_method_info[] = {&_test_dbus_method_info_test_void, &_test_dbus_method_info_test_int, &_test_dbus_method_info_test_string, NULL}; +static const GDBusSignalInfo * const _test_dbus_signal_info[] = {NULL}; +static const GDBusPropertyInfo _test_dbus_property_info_test_property = {-1, "TestProperty", "s", G_DBUS_PROPERTY_INFO_FLAGS_READABLE | G_DBUS_PROPERTY_INFO_FLAGS_WRITABLE, NULL}; +static const GDBusPropertyInfo _test_dbus_property_info_test_int_property = {-1, "TestIntProperty", "i", G_DBUS_PROPERTY_INFO_FLAGS_READABLE | G_DBUS_PROPERTY_INFO_FLAGS_WRITABLE, NULL}; +static const GDBusPropertyInfo * const _test_dbus_property_info[] = {&_test_dbus_property_info_test_property, &_test_dbus_property_info_test_int_property, NULL}; +static const GDBusInterfaceInfo _test_dbus_interface_info = {-1, "org.example.Test", (GDBusMethodInfo **) (&_test_dbus_method_info), (GDBusSignalInfo **) (&_test_dbus_signal_info), (GDBusPropertyInfo **) (&_test_dbus_property_info), NULL}; +static const GDBusInterfaceVTable _test_dbus_interface_vtable = {test_dbus_interface_method_call, test_dbus_interface_get_property, test_dbus_interface_set_property}; + +void +test_test_void (Test* self, + GError** error) +{ + TestIface* _iface_; + g_return_if_fail (IS_TEST (self)); + _iface_ = TEST_GET_INTERFACE (self); + if (_iface_->test_void) { + _iface_->test_void (self, error); + } +} + +gint +test_test_int (Test* self, + gint i, + gint* j, + GError** error) +{ + TestIface* _iface_; + g_return_val_if_fail (IS_TEST (self), 0); + _iface_ = TEST_GET_INTERFACE (self); + if (_iface_->test_int) { + return _iface_->test_int (self, i, j, error); + } + return -1; +} + +gchar* +test_test_string (Test* self, + const gchar* s, + gchar* * t, + GError** error) +{ + TestIface* _iface_; + g_return_val_if_fail (IS_TEST (self), NULL); + _iface_ = TEST_GET_INTERFACE (self); + if (_iface_->test_string) { + return _iface_->test_string (self, s, t, error); + } + return NULL; +} + +gchar* +test_get_test_property (Test* self) +{ + TestIface* _iface_; + g_return_val_if_fail (IS_TEST (self), NULL); + _iface_ = TEST_GET_INTERFACE (self); + if (_iface_->get_test_property) { + return _iface_->get_test_property (self); + } + return NULL; +} + +void +test_set_test_property (Test* self, + const gchar* value) +{ + TestIface* _iface_; + g_return_if_fail (IS_TEST (self)); + _iface_ = TEST_GET_INTERFACE (self); + if (_iface_->set_test_property) { + _iface_->set_test_property (self, value); + } +} + +gint +test_get_test_int_property (Test* self) +{ + TestIface* _iface_; + g_return_val_if_fail (IS_TEST (self), 0); + _iface_ = TEST_GET_INTERFACE (self); + if (_iface_->get_test_int_property) { + return _iface_->get_test_int_property (self); + } + return -1; +} + +void +test_set_test_int_property (Test* self, + gint value) +{ + TestIface* _iface_; + g_return_if_fail (IS_TEST (self)); + _iface_ = TEST_GET_INTERFACE (self); + if (_iface_->set_test_int_property) { + _iface_->set_test_int_property (self, value); + } +} + +static void +test_default_init (TestIface * iface, + gpointer iface_data) +{ +} + +static GType +test_get_type_once (void) +{ + static const GTypeInfo g_define_type_info = { sizeof (TestIface), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) test_default_init, (GClassFinalizeFunc) NULL, NULL, 0, 0, (GInstanceInitFunc) NULL, NULL }; + GType test_type_id; + test_type_id = g_type_register_static (G_TYPE_INTERFACE, "Test", &g_define_type_info, 0); + g_type_interface_add_prerequisite (test_type_id, G_TYPE_OBJECT); + g_type_set_qdata (test_type_id, g_quark_from_static_string ("vala-dbus-proxy-type"), (void*) test_proxy_get_type); + g_type_set_qdata (test_type_id, g_quark_from_static_string ("vala-dbus-interface-name"), "org.example.Test"); + g_type_set_qdata (test_type_id, g_quark_from_static_string ("vala-dbus-interface-info"), (void*) (&_test_dbus_interface_info)); + g_type_set_qdata (test_type_id, g_quark_from_static_string ("vala-dbus-register-object"), (void*) test_register_object); + return test_type_id; +} + +GType +test_get_type (void) +{ + static volatile gsize test_type_id__volatile = 0; + if (g_once_init_enter (&test_type_id__volatile)) { + GType test_type_id; + test_type_id = test_get_type_once (); + g_once_init_leave (&test_type_id__volatile, test_type_id); + } + return test_type_id__volatile; +} + +G_DEFINE_TYPE_EXTENDED (TestProxy, test_proxy, G_TYPE_DBUS_PROXY, 0, G_IMPLEMENT_INTERFACE (TYPE_TEST, test_proxy_test_interface_init) ) +static void +test_proxy_class_init (TestProxyClass* klass) +{ + G_DBUS_PROXY_CLASS (klass)->g_signal = test_proxy_g_signal; +} + +static void +test_proxy_g_signal (GDBusProxy* proxy, + const gchar* sender_name, + const gchar* signal_name, + GVariant* parameters) +{ +} + +static void +test_proxy_init (TestProxy* self) +{ + g_dbus_proxy_set_interface_info (G_DBUS_PROXY (self), (GDBusInterfaceInfo *) (&_test_dbus_interface_info)); +} + +static void +test_proxy_test_void (Test* self, + GError** error) +{ + GDBusMessage *_message; + GVariant *_arguments; + GVariantBuilder _arguments_builder; + GDBusMessage *_reply_message; + G_IO_ERROR; + _message = g_dbus_message_new_method_call (g_dbus_proxy_get_name ((GDBusProxy *) self), g_dbus_proxy_get_object_path ((GDBusProxy *) self), "org.example.Test", "TestVoid"); + g_variant_builder_init (&_arguments_builder, G_VARIANT_TYPE_TUPLE); + _arguments = g_variant_builder_end (&_arguments_builder); + g_dbus_message_set_body (_message, _arguments); + _reply_message = g_dbus_connection_send_message_with_reply_sync (g_dbus_proxy_get_connection ((GDBusProxy *) self), _message, G_DBUS_SEND_MESSAGE_FLAGS_NONE, g_dbus_proxy_get_default_timeout ((GDBusProxy *) self), NULL, NULL, error); + g_object_unref (_message); + if (!_reply_message) { + return; + } + if (g_dbus_message_to_gerror (_reply_message, error)) { + g_object_unref (_reply_message); + return; + } + g_object_unref (_reply_message); +} + +static gint +test_proxy_test_int (Test* self, + gint i, + gint* j, + GError** error) +{ + GDBusMessage *_message; + GVariant *_arguments; + GVariantBuilder _arguments_builder; + GDBusMessage *_reply_message; + GVariant *_reply; + GVariantIter _reply_iter; + gint _vala_j = 0; + GVariant* _tmp2_; + gint _result = 0; + GVariant* _tmp3_; + G_IO_ERROR; + _message = g_dbus_message_new_method_call (g_dbus_proxy_get_name ((GDBusProxy *) self), g_dbus_proxy_get_object_path ((GDBusProxy *) self), "org.example.Test", "TestInt"); + g_variant_builder_init (&_arguments_builder, G_VARIANT_TYPE_TUPLE); + g_variant_builder_add_value (&_arguments_builder, g_variant_new_int32 (i)); + _arguments = g_variant_builder_end (&_arguments_builder); + g_dbus_message_set_body (_message, _arguments); + _reply_message = g_dbus_connection_send_message_with_reply_sync (g_dbus_proxy_get_connection ((GDBusProxy *) self), _message, G_DBUS_SEND_MESSAGE_FLAGS_NONE, g_dbus_proxy_get_default_timeout ((GDBusProxy *) self), NULL, NULL, error); + g_object_unref (_message); + if (!_reply_message) { + gint _tmp0_ = 0; + return _tmp0_; + } + if (g_dbus_message_to_gerror (_reply_message, error)) { + gint _tmp1_ = 0; + g_object_unref (_reply_message); + return _tmp1_; + } + _reply = g_dbus_message_get_body (_reply_message); + g_variant_iter_init (&_reply_iter, _reply); + _tmp2_ = g_variant_iter_next_value (&_reply_iter); + _vala_j = g_variant_get_int32 (_tmp2_); + g_variant_unref (_tmp2_); + *j = _vala_j; + _tmp3_ = g_variant_iter_next_value (&_reply_iter); + _result = g_variant_get_int32 (_tmp3_); + g_variant_unref (_tmp3_); + g_object_unref (_reply_message); + return _result; +} + +static gchar* +test_proxy_test_string (Test* self, + const gchar* s, + gchar* * t, + GError** error) +{ + GDBusMessage *_message; + GVariant *_arguments; + GVariantBuilder _arguments_builder; + GDBusMessage *_reply_message; + GVariant *_reply; + GVariantIter _reply_iter; + gchar* _vala_t = NULL; + GVariant* _tmp4_; + gchar* _result = NULL; + GVariant* _tmp5_; + G_IO_ERROR; + _message = g_dbus_message_new_method_call (g_dbus_proxy_get_name ((GDBusProxy *) self), g_dbus_proxy_get_object_path ((GDBusProxy *) self), "org.example.Test", "TestString"); + g_variant_builder_init (&_arguments_builder, G_VARIANT_TYPE_TUPLE); + g_variant_builder_add_value (&_arguments_builder, g_variant_new_string (s)); + _arguments = g_variant_builder_end (&_arguments_builder); + g_dbus_message_set_body (_message, _arguments); + _reply_message = g_dbus_connection_send_message_with_reply_sync (g_dbus_proxy_get_connection ((GDBusProxy *) self), _message, G_DBUS_SEND_MESSAGE_FLAGS_NONE, g_dbus_proxy_get_default_timeout ((GDBusProxy *) self), NULL, NULL, error); + g_object_unref (_message); + if (!_reply_message) { + return NULL; + } + if (g_dbus_message_to_gerror (_reply_message, error)) { + g_object_unref (_reply_message); + return NULL; + } + _reply = g_dbus_message_get_body (_reply_message); + g_variant_iter_init (&_reply_iter, _reply); + _tmp4_ = g_variant_iter_next_value (&_reply_iter); + _vala_t = g_variant_dup_string (_tmp4_, NULL); + g_variant_unref (_tmp4_); + *t = _vala_t; + _tmp5_ = g_variant_iter_next_value (&_reply_iter); + _result = g_variant_dup_string (_tmp5_, NULL); + g_variant_unref (_tmp5_); + g_object_unref (_reply_message); + return _result; +} + +static gchar* +test_dbus_proxy_get_test_property (Test* self) +{ + GVariant *_inner_reply; + gchar* _result; + _inner_reply = g_dbus_proxy_get_cached_property ((GDBusProxy *) self, "TestProperty"); + if (!_inner_reply) { + GVariant *_arguments; + GVariant *_reply; + GVariantBuilder _arguments_builder; + g_variant_builder_init (&_arguments_builder, G_VARIANT_TYPE_TUPLE); + g_variant_builder_add_value (&_arguments_builder, g_variant_new_string ("org.example.Test")); + g_variant_builder_add_value (&_arguments_builder, g_variant_new_string ("TestProperty")); + _arguments = g_variant_builder_end (&_arguments_builder); + _reply = g_dbus_proxy_call_sync ((GDBusProxy *) self, "org.freedesktop.DBus.Properties.Get", _arguments, G_DBUS_CALL_FLAGS_NONE, -1, NULL, NULL); + if (!_reply) { + return NULL; + } + g_variant_get (_reply, "(v)", &_inner_reply); + g_variant_unref (_reply); + } + _result = g_variant_dup_string (_inner_reply, NULL); + g_variant_unref (_inner_reply); + return _result; +} + +static void +test_dbus_proxy_set_test_property (Test* self, + const gchar* value) +{ + GVariant *_arguments; + GVariant *_reply; + GVariantBuilder _arguments_builder; + g_variant_builder_init (&_arguments_builder, G_VARIANT_TYPE_TUPLE); + g_variant_builder_add_value (&_arguments_builder, g_variant_new_string ("org.example.Test")); + g_variant_builder_add_value (&_arguments_builder, g_variant_new_string ("TestProperty")); + g_variant_builder_open (&_arguments_builder, G_VARIANT_TYPE_VARIANT); + g_variant_builder_add_value (&_arguments_builder, g_variant_new_string (value)); + g_variant_builder_close (&_arguments_builder); + _arguments = g_variant_builder_end (&_arguments_builder); + _reply = g_dbus_proxy_call_sync ((GDBusProxy *) self, "org.freedesktop.DBus.Properties.Set", _arguments, G_DBUS_CALL_FLAGS_NONE, -1, NULL, NULL); + if (!_reply) { + return; + } + g_variant_unref (_reply); +} + +static gint +test_dbus_proxy_get_test_int_property (Test* self) +{ + GVariant *_inner_reply; + gint _result; + _inner_reply = g_dbus_proxy_get_cached_property ((GDBusProxy *) self, "TestIntProperty"); + if (!_inner_reply) { + GVariant *_arguments; + GVariant *_reply; + GVariantBuilder _arguments_builder; + g_variant_builder_init (&_arguments_builder, G_VARIANT_TYPE_TUPLE); + g_variant_builder_add_value (&_arguments_builder, g_variant_new_string ("org.example.Test")); + g_variant_builder_add_value (&_arguments_builder, g_variant_new_string ("TestIntProperty")); + _arguments = g_variant_builder_end (&_arguments_builder); + _reply = g_dbus_proxy_call_sync ((GDBusProxy *) self, "org.freedesktop.DBus.Properties.Get", _arguments, G_DBUS_CALL_FLAGS_NONE, -1, NULL, NULL); + if (!_reply) { + gint _tmp6_ = 0; + return _tmp6_; + } + g_variant_get (_reply, "(v)", &_inner_reply); + g_variant_unref (_reply); + } + _result = g_variant_get_int32 (_inner_reply); + g_variant_unref (_inner_reply); + return _result; +} + +static void +test_dbus_proxy_set_test_int_property (Test* self, + gint value) +{ + GVariant *_arguments; + GVariant *_reply; + GVariantBuilder _arguments_builder; + g_variant_builder_init (&_arguments_builder, G_VARIANT_TYPE_TUPLE); + g_variant_builder_add_value (&_arguments_builder, g_variant_new_string ("org.example.Test")); + g_variant_builder_add_value (&_arguments_builder, g_variant_new_string ("TestIntProperty")); + g_variant_builder_open (&_arguments_builder, G_VARIANT_TYPE_VARIANT); + g_variant_builder_add_value (&_arguments_builder, g_variant_new_int32 (value)); + g_variant_builder_close (&_arguments_builder); + _arguments = g_variant_builder_end (&_arguments_builder); + _reply = g_dbus_proxy_call_sync ((GDBusProxy *) self, "org.freedesktop.DBus.Properties.Set", _arguments, G_DBUS_CALL_FLAGS_NONE, -1, NULL, NULL); + if (!_reply) { + return; + } + g_variant_unref (_reply); +} + +static void +test_proxy_test_interface_init (TestIface* iface) +{ + iface->test_void = test_proxy_test_void; + iface->test_int = test_proxy_test_int; + iface->test_string = test_proxy_test_string; + iface->get_test_property = test_dbus_proxy_get_test_property; + iface->set_test_property = test_dbus_proxy_set_test_property; + iface->get_test_int_property = test_dbus_proxy_get_test_int_property; + iface->set_test_int_property = test_dbus_proxy_set_test_int_property; +} + +static void +_dbus_test_test_void (Test* self, + GVariant* _parameters_, + GDBusMethodInvocation* invocation) +{ + GError* error = NULL; + GVariantIter _arguments_iter; + GDBusMessage* _reply_message = NULL; + GVariant* _reply; + GVariantBuilder _reply_builder; + g_variant_iter_init (&_arguments_iter, _parameters_); + test_test_void (self, &error); + if (error) { + g_dbus_method_invocation_return_gerror (invocation, error); + g_error_free (error); + return; + } + _reply_message = g_dbus_message_new_method_reply (g_dbus_method_invocation_get_message (invocation)); + g_variant_builder_init (&_reply_builder, G_VARIANT_TYPE_TUPLE); + _reply = g_variant_builder_end (&_reply_builder); + g_dbus_message_set_body (_reply_message, _reply); + g_dbus_connection_send_message (g_dbus_method_invocation_get_connection (invocation), _reply_message, G_DBUS_SEND_MESSAGE_FLAGS_NONE, NULL, NULL); + g_object_unref (invocation); + g_object_unref (_reply_message); +} + +static void +_dbus_test_test_int (Test* self, + GVariant* _parameters_, + GDBusMethodInvocation* invocation) +{ + GError* error = NULL; + GVariantIter _arguments_iter; + gint i = 0; + GVariant* _tmp7_; + GDBusMessage* _reply_message = NULL; + GVariant* _reply; + GVariantBuilder _reply_builder; + gint j = 0; + gint result; + g_variant_iter_init (&_arguments_iter, _parameters_); + _tmp7_ = g_variant_iter_next_value (&_arguments_iter); + i = g_variant_get_int32 (_tmp7_); + g_variant_unref (_tmp7_); + result = test_test_int (self, i, &j, &error); + if (error) { + g_dbus_method_invocation_return_gerror (invocation, error); + g_error_free (error); + return; + } + _reply_message = g_dbus_message_new_method_reply (g_dbus_method_invocation_get_message (invocation)); + g_variant_builder_init (&_reply_builder, G_VARIANT_TYPE_TUPLE); + g_variant_builder_add_value (&_reply_builder, g_variant_new_int32 (j)); + g_variant_builder_add_value (&_reply_builder, g_variant_new_int32 (result)); + _reply = g_variant_builder_end (&_reply_builder); + g_dbus_message_set_body (_reply_message, _reply); + g_dbus_connection_send_message (g_dbus_method_invocation_get_connection (invocation), _reply_message, G_DBUS_SEND_MESSAGE_FLAGS_NONE, NULL, NULL); + g_object_unref (invocation); + g_object_unref (_reply_message); +} + +static void +_dbus_test_test_string (Test* self, + GVariant* _parameters_, + GDBusMethodInvocation* invocation) +{ + GError* error = NULL; + GVariantIter _arguments_iter; + gchar* s = NULL; + GVariant* _tmp8_; + GDBusMessage* _reply_message = NULL; + GVariant* _reply; + GVariantBuilder _reply_builder; + gchar* t = NULL; + gchar* result; + g_variant_iter_init (&_arguments_iter, _parameters_); + _tmp8_ = g_variant_iter_next_value (&_arguments_iter); + s = g_variant_dup_string (_tmp8_, NULL); + g_variant_unref (_tmp8_); + result = test_test_string (self, s, &t, &error); + if (error) { + g_dbus_method_invocation_return_gerror (invocation, error); + g_error_free (error); + goto _error; + } + _reply_message = g_dbus_message_new_method_reply (g_dbus_method_invocation_get_message (invocation)); + g_variant_builder_init (&_reply_builder, G_VARIANT_TYPE_TUPLE); + g_variant_builder_add_value (&_reply_builder, g_variant_new_string (t)); + g_variant_builder_add_value (&_reply_builder, g_variant_new_string (result)); + _g_free0 (result); + _reply = g_variant_builder_end (&_reply_builder); + g_dbus_message_set_body (_reply_message, _reply); + g_dbus_connection_send_message (g_dbus_method_invocation_get_connection (invocation), _reply_message, G_DBUS_SEND_MESSAGE_FLAGS_NONE, NULL, NULL); + g_object_unref (invocation); + g_object_unref (_reply_message); + _error: + _g_free0 (s); + _g_free0 (t); + ; +} + +static void +test_dbus_interface_method_call (GDBusConnection* connection, + const gchar* sender, + const gchar* object_path, + const gchar* interface_name, + const gchar* method_name, + GVariant* parameters, + GDBusMethodInvocation* invocation, + gpointer user_data) +{ + gpointer* data; + gpointer object; + data = user_data; + object = data[0]; + if (strcmp (method_name, "TestVoid") == 0) { + _dbus_test_test_void (object, parameters, invocation); + } else if (strcmp (method_name, "TestInt") == 0) { + _dbus_test_test_int (object, parameters, invocation); + } else if (strcmp (method_name, "TestString") == 0) { + _dbus_test_test_string (object, parameters, invocation); + } else { + g_object_unref (invocation); + } +} + +static GVariant* +_dbus_test_get_test_property (Test* self) +{ + gchar* result; + GVariant* _reply; + result = test_get_test_property (self); + _reply = g_variant_new_string (result); + _g_free0 (result); + return _reply; +} + +static GVariant* +_dbus_test_get_test_int_property (Test* self) +{ + gint result; + GVariant* _reply; + result = test_get_test_int_property (self); + _reply = g_variant_new_int32 (result); + return _reply; +} + +static GVariant* +test_dbus_interface_get_property (GDBusConnection* connection, + const gchar* sender, + const gchar* object_path, + const gchar* interface_name, + const gchar* property_name, + GError** error, + gpointer user_data) +{ + gpointer* data; + gpointer object; + data = user_data; + object = data[0]; + if (strcmp (property_name, "TestProperty") == 0) { + return _dbus_test_get_test_property (object); + } else if (strcmp (property_name, "TestIntProperty") == 0) { + return _dbus_test_get_test_int_property (object); + } + return NULL; +} + +static void +_dbus_test_set_test_property (Test* self, + GVariant* _value) +{ + gchar* value = NULL; + value = g_variant_dup_string (_value, NULL); + test_set_test_property (self, value); + _g_free0 (value); +} + +static void +_dbus_test_set_test_int_property (Test* self, + GVariant* _value) +{ + gint value = 0; + value = g_variant_get_int32 (_value); + test_set_test_int_property (self, value); +} + +static gboolean +test_dbus_interface_set_property (GDBusConnection* connection, + const gchar* sender, + const gchar* object_path, + const gchar* interface_name, + const gchar* property_name, + GVariant* value, + GError** error, + gpointer user_data) +{ + gpointer* data; + gpointer object; + data = user_data; + object = data[0]; + if (strcmp (property_name, "TestProperty") == 0) { + _dbus_test_set_test_property (object, value); + return TRUE; + } else if (strcmp (property_name, "TestIntProperty") == 0) { + _dbus_test_set_test_int_property (object, value); + return TRUE; + } + return FALSE; +} + +guint +test_register_object (gpointer object, + GDBusConnection* connection, + const gchar* path, + GError** error) +{ + guint result; + gpointer *data; + data = g_new (gpointer, 3); + data[0] = g_object_ref (object); + data[1] = g_object_ref (connection); + data[2] = g_strdup (path); + result = g_dbus_connection_register_object (connection, path, (GDBusInterfaceInfo *) (&_test_dbus_interface_info), &_test_dbus_interface_vtable, data, _test_unregister_object, error); + if (!result) { + return 0; + } + return result; +} + +static void +_test_unregister_object (gpointer user_data) +{ + gpointer* data; + data = user_data; + g_object_unref (data[0]); + g_object_unref (data[1]); + g_free (data[2]); + g_free (data); +} + +static void +_vala_main (void) +{ + Test* test = NULL; + Test* _tmp0_; + Test* _tmp1_; + gint j = 0; + gint k = 0; + gint _tmp2_ = 0; + Test* _tmp3_; + gint _tmp4_ = 0; + gint _tmp5_; + gchar* t = NULL; + gchar* u = NULL; + gchar* _tmp6_ = NULL; + Test* _tmp7_; + gchar* _tmp8_ = NULL; + gchar* _tmp9_; + gchar* _tmp10_; + const gchar* _tmp11_; + const gchar* _tmp12_; + Test* _tmp13_; + Test* _tmp14_; + gchar* _tmp15_; + gchar* _tmp16_; + const gchar* _tmp17_; + Test* _tmp18_; + Test* _tmp19_; + gint _tmp20_; + gint _tmp21_; + GError* _inner_error0_ = NULL; + _tmp0_ = (Test*) g_initable_new (TYPE_TEST_PROXY, NULL, &_inner_error0_, "g-flags", G_DBUS_PROXY_FLAGS_DO_NOT_LOAD_PROPERTIES, "g-name", "org.example.Test", "g-bus-type", G_BUS_TYPE_SESSION, "g-object-path", "/org/example/test", "g-interface-name", "org.example.Test", NULL); + test = (Test*) _tmp0_; + if (G_UNLIKELY (_inner_error0_ != NULL)) { + g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error0_->message, g_quark_to_string (_inner_error0_->domain), _inner_error0_->code); + g_clear_error (&_inner_error0_); + return; + } + _tmp1_ = test; + test_test_void (_tmp1_, &_inner_error0_); + if (G_UNLIKELY (_inner_error0_ != NULL)) { + _g_object_unref0 (test); + g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error0_->message, g_quark_to_string (_inner_error0_->domain), _inner_error0_->code); + g_clear_error (&_inner_error0_); + return; + } + _tmp3_ = test; + _tmp5_ = test_test_int (_tmp3_, 42, &_tmp4_, &_inner_error0_); + j = _tmp4_; + _tmp2_ = _tmp5_; + if (G_UNLIKELY (_inner_error0_ != NULL)) { + _g_object_unref0 (test); + g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error0_->message, g_quark_to_string (_inner_error0_->domain), _inner_error0_->code); + g_clear_error (&_inner_error0_); + return; + } + k = _tmp2_; + _vala_assert (j == 23, "j == 23"); + _vala_assert (k == 11, "k == 11"); + _tmp7_ = test; + _tmp9_ = test_test_string (_tmp7_, "hello", &_tmp8_, &_inner_error0_); + _g_free0 (t); + t = _tmp8_; + _tmp6_ = _tmp9_; + if (G_UNLIKELY (_inner_error0_ != NULL)) { + _g_free0 (u); + _g_free0 (t); + _g_object_unref0 (test); + g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error0_->message, g_quark_to_string (_inner_error0_->domain), _inner_error0_->code); + g_clear_error (&_inner_error0_); + return; + } + _tmp10_ = _tmp6_; + _tmp6_ = NULL; + _g_free0 (u); + u = _tmp10_; + _tmp11_ = t; + _vala_assert (g_strcmp0 (_tmp11_, "world") == 0, "t == \"world\""); + _tmp12_ = u; + _vala_assert (g_strcmp0 (_tmp12_, "vala") == 0, "u == \"vala\""); + _tmp13_ = test; + test_set_test_property (_tmp13_, "hello"); + _tmp14_ = test; + _tmp15_ = test_get_test_property (_tmp14_); + _tmp16_ = _tmp15_; + _g_free0 (t); + t = _tmp16_; + _tmp17_ = t; + _vala_assert (g_strcmp0 (_tmp17_, "hello") == 0, "t == \"hello\""); + _tmp18_ = test; + test_set_test_int_property (_tmp18_, 42); + _tmp19_ = test; + _tmp20_ = test_get_test_int_property (_tmp19_); + _tmp21_ = _tmp20_; + j = _tmp21_; + _vala_assert (j == 42, "j == 42"); + _g_free0 (_tmp6_); + _g_free0 (u); + _g_free0 (t); + _g_object_unref0 (test); +} + +int +main (int argc, + char ** argv) +{ + _vala_main (); + return 0; +} + diff --git a/tests/dbus/basic-types_server.c-expected b/tests/dbus/basic-types_server.c-expected new file mode 100644 index 000000000..f0731f71b --- /dev/null +++ b/tests/dbus/basic-types_server.c-expected @@ -0,0 +1,755 @@ +/* dbus_basic_types_server.c generated by valac, the Vala compiler + * generated from dbus_basic_types_server.vala, do not modify */ + +#include <glib-object.h> +#include <gio/gio.h> +#include <stdlib.h> +#include <string.h> +#include <glib.h> + +#if !defined(VALA_EXTERN) +#if defined(_MSC_VER) +#define VALA_EXTERN __declspec(dllexport) extern +#elif __GNUC__ >= 4 +#define VALA_EXTERN __attribute__((visibility("default"))) extern +#else +#define VALA_EXTERN extern +#endif +#endif + +#define TYPE_TEST (test_get_type ()) +#define TEST(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TYPE_TEST, Test)) +#define TEST_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), TYPE_TEST, TestClass)) +#define IS_TEST(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TYPE_TEST)) +#define IS_TEST_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), TYPE_TEST)) +#define TEST_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), TYPE_TEST, TestClass)) + +typedef struct _Test Test; +typedef struct _TestClass TestClass; +typedef struct _TestPrivate TestPrivate; +enum { + TEST_0_PROPERTY, + TEST_TEST_PROPERTY_PROPERTY, + TEST_TEST_INT_PROPERTY_PROPERTY, + TEST_NUM_PROPERTIES +}; +static GParamSpec* test_properties[TEST_NUM_PROPERTIES]; +#define _g_free0(var) (var = (g_free (var), NULL)) +#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL))) +#define _g_variant_unref0(var) ((var == NULL) ? NULL : (var = (g_variant_unref (var), NULL))) +#define _g_main_loop_unref0(var) ((var == NULL) ? NULL : (var = (g_main_loop_unref (var), NULL))) +#define _vala_assert(expr, msg) if G_LIKELY (expr) ; else g_assertion_message_expr (G_LOG_DOMAIN, __FILE__, __LINE__, G_STRFUNC, msg); +#define _vala_return_if_fail(expr, msg) if G_LIKELY (expr) ; else { g_return_if_fail_warning (G_LOG_DOMAIN, G_STRFUNC, msg); return; } +#define _vala_return_val_if_fail(expr, msg, val) if G_LIKELY (expr) ; else { g_return_if_fail_warning (G_LOG_DOMAIN, G_STRFUNC, msg); return val; } +#define _vala_warn_if_fail(expr, msg) if G_LIKELY (expr) ; else g_warn_message (G_LOG_DOMAIN, __FILE__, __LINE__, G_STRFUNC, msg); + +struct _Test { + GObject parent_instance; + TestPrivate * priv; +}; + +struct _TestClass { + GObjectClass parent_class; +}; + +struct _TestPrivate { + gchar* _test_property; + gint _test_int_property; +}; + +static gint Test_private_offset; +static gpointer test_parent_class = NULL; +VALA_EXTERN GMainLoop* main_loop; +GMainLoop* main_loop = NULL; + +VALA_EXTERN GType test_get_type (void) G_GNUC_CONST ; +G_DEFINE_AUTOPTR_CLEANUP_FUNC (Test, g_object_unref) +VALA_EXTERN guint test_register_object (void* object, + GDBusConnection* connection, + const gchar* path, + GError** error); +VALA_EXTERN void test_test_void (Test* self); +VALA_EXTERN gint test_test_int (Test* self, + gint i, + gint* j); +VALA_EXTERN gchar* test_test_string (Test* self, + const gchar* s, + gchar* * t); +VALA_EXTERN Test* test_new (void); +VALA_EXTERN Test* test_construct (GType object_type); +VALA_EXTERN gchar* test_get_test_property (Test* self); +VALA_EXTERN void test_set_test_property (Test* self, + const gchar* value); +VALA_EXTERN gint test_get_test_int_property (Test* self); +VALA_EXTERN void test_set_test_int_property (Test* self, + gint value); +static void test_finalize (GObject * obj); +static GType test_get_type_once (void); +static void _vala_test_get_property (GObject * object, + guint property_id, + GValue * value, + GParamSpec * pspec); +static void _vala_test_set_property (GObject * object, + guint property_id, + const GValue * value, + GParamSpec * pspec); +static void _dbus_test_test_void (Test* self, + GVariant* _parameters_, + GDBusMethodInvocation* invocation); +static void _dbus_test_test_int (Test* self, + GVariant* _parameters_, + GDBusMethodInvocation* invocation); +static void _dbus_test_test_string (Test* self, + GVariant* _parameters_, + GDBusMethodInvocation* invocation); +static void test_dbus_interface_method_call (GDBusConnection* connection, + const gchar* sender, + const gchar* object_path, + const gchar* interface_name, + const gchar* method_name, + GVariant* parameters, + GDBusMethodInvocation* invocation, + gpointer user_data); +static GVariant* test_dbus_interface_get_property (GDBusConnection* connection, + const gchar* sender, + const gchar* object_path, + const gchar* interface_name, + const gchar* property_name, + GError** error, + gpointer user_data); +static GVariant* _dbus_test_get_test_property (Test* self); +static GVariant* _dbus_test_get_test_int_property (Test* self); +static gboolean test_dbus_interface_set_property (GDBusConnection* connection, + const gchar* sender, + const gchar* object_path, + const gchar* interface_name, + const gchar* property_name, + GVariant* value, + GError** error, + gpointer user_data); +static void _dbus_test_set_test_property (Test* self, + GVariant* _value); +static void _dbus_test_set_test_int_property (Test* self, + GVariant* _value); +static void _test_unregister_object (gpointer user_data); +VALA_EXTERN void client_exit (GPid pid, + gint status); +static void _vala_main (void); +static guint _variant_get1 (GVariant* value); +static void _client_exit_gchild_watch_func (GPid pid, + gint wait_status, + gpointer self); +static void _vala_array_destroy (gpointer array, + gssize array_length, + GDestroyNotify destroy_func); +static void _vala_array_free (gpointer array, + gssize array_length, + GDestroyNotify destroy_func); + +static const GDBusArgInfo * const _test_dbus_arg_info_test_void_in[] = {NULL}; +static const GDBusArgInfo * const _test_dbus_arg_info_test_void_out[] = {NULL}; +static const GDBusMethodInfo _test_dbus_method_info_test_void = {-1, "TestVoid", (GDBusArgInfo **) (&_test_dbus_arg_info_test_void_in), (GDBusArgInfo **) (&_test_dbus_arg_info_test_void_out), NULL}; +static const GDBusArgInfo _test_dbus_arg_info_test_int_i = {-1, "i", "i", NULL}; +static const GDBusArgInfo _test_dbus_arg_info_test_int_j = {-1, "j", "i", NULL}; +static const GDBusArgInfo _test_dbus_arg_info_test_int_result = {-1, "result", "i", NULL}; +static const GDBusArgInfo * const _test_dbus_arg_info_test_int_in[] = {&_test_dbus_arg_info_test_int_i, NULL}; +static const GDBusArgInfo * const _test_dbus_arg_info_test_int_out[] = {&_test_dbus_arg_info_test_int_j, &_test_dbus_arg_info_test_int_result, NULL}; +static const GDBusMethodInfo _test_dbus_method_info_test_int = {-1, "TestInt", (GDBusArgInfo **) (&_test_dbus_arg_info_test_int_in), (GDBusArgInfo **) (&_test_dbus_arg_info_test_int_out), NULL}; +static const GDBusArgInfo _test_dbus_arg_info_test_string_s = {-1, "s", "s", NULL}; +static const GDBusArgInfo _test_dbus_arg_info_test_string_t = {-1, "t", "s", NULL}; +static const GDBusArgInfo _test_dbus_arg_info_test_string_result = {-1, "result", "s", NULL}; +static const GDBusArgInfo * const _test_dbus_arg_info_test_string_in[] = {&_test_dbus_arg_info_test_string_s, NULL}; +static const GDBusArgInfo * const _test_dbus_arg_info_test_string_out[] = {&_test_dbus_arg_info_test_string_t, &_test_dbus_arg_info_test_string_result, NULL}; +static const GDBusMethodInfo _test_dbus_method_info_test_string = {-1, "TestString", (GDBusArgInfo **) (&_test_dbus_arg_info_test_string_in), (GDBusArgInfo **) (&_test_dbus_arg_info_test_string_out), NULL}; +static const GDBusMethodInfo * const _test_dbus_method_info[] = {&_test_dbus_method_info_test_void, &_test_dbus_method_info_test_int, &_test_dbus_method_info_test_string, NULL}; +static const GDBusSignalInfo * const _test_dbus_signal_info[] = {NULL}; +static const GDBusPropertyInfo _test_dbus_property_info_test_property = {-1, "TestProperty", "s", G_DBUS_PROPERTY_INFO_FLAGS_READABLE | G_DBUS_PROPERTY_INFO_FLAGS_WRITABLE, NULL}; +static const GDBusPropertyInfo _test_dbus_property_info_test_int_property = {-1, "TestIntProperty", "i", G_DBUS_PROPERTY_INFO_FLAGS_READABLE | G_DBUS_PROPERTY_INFO_FLAGS_WRITABLE, NULL}; +static const GDBusPropertyInfo * const _test_dbus_property_info[] = {&_test_dbus_property_info_test_property, &_test_dbus_property_info_test_int_property, NULL}; +static const GDBusInterfaceInfo _test_dbus_interface_info = {-1, "org.example.Test", (GDBusMethodInfo **) (&_test_dbus_method_info), (GDBusSignalInfo **) (&_test_dbus_signal_info), (GDBusPropertyInfo **) (&_test_dbus_property_info), NULL}; +static const GDBusInterfaceVTable _test_dbus_interface_vtable = {test_dbus_interface_method_call, test_dbus_interface_get_property, test_dbus_interface_set_property}; + +static inline gpointer +test_get_instance_private (Test* self) +{ + return G_STRUCT_MEMBER_P (self, Test_private_offset); +} + +void +test_test_void (Test* self) +{ + g_return_if_fail (IS_TEST (self)); +} + +gint +test_test_int (Test* self, + gint i, + gint* j) +{ + gint _vala_j = 0; + gint result = 0; + g_return_val_if_fail (IS_TEST (self), 0); + _vala_assert (i == 42, "i == 42"); + _vala_j = 23; + result = 11; + if (j) { + *j = _vala_j; + } + return result; +} + +gchar* +test_test_string (Test* self, + const gchar* s, + gchar* * t) +{ + gchar* _vala_t = NULL; + gchar* _tmp0_; + gchar* _tmp1_; + gchar* result = NULL; + g_return_val_if_fail (IS_TEST (self), NULL); + g_return_val_if_fail (s != NULL, NULL); + _vala_assert (g_strcmp0 (s, "hello") == 0, "s == \"hello\""); + _tmp0_ = g_strdup ("world"); + _g_free0 (_vala_t); + _vala_t = _tmp0_; + _tmp1_ = g_strdup ("vala"); + result = _tmp1_; + if (t) { + *t = _vala_t; + } else { + _g_free0 (_vala_t); + } + return result; +} + +Test* +test_construct (GType object_type) +{ + Test * self = NULL; + self = (Test*) g_object_new (object_type, NULL); + return self; +} + +Test* +test_new (void) +{ + return test_construct (TYPE_TEST); +} + +gchar* +test_get_test_property (Test* self) +{ + gchar* result; + const gchar* _tmp0_; + gchar* _tmp1_; + g_return_val_if_fail (IS_TEST (self), NULL); + _tmp0_ = self->priv->_test_property; + _tmp1_ = g_strdup (_tmp0_); + result = _tmp1_; + return result; +} + +void +test_set_test_property (Test* self, + const gchar* value) +{ + gchar* old_value; + g_return_if_fail (IS_TEST (self)); + old_value = test_get_test_property (self); + if (g_strcmp0 (value, old_value) != 0) { + gchar* _tmp0_; + _tmp0_ = g_strdup (value); + _g_free0 (self->priv->_test_property); + self->priv->_test_property = _tmp0_; + g_object_notify_by_pspec ((GObject *) self, test_properties[TEST_TEST_PROPERTY_PROPERTY]); + } + _g_free0 (old_value); +} + +gint +test_get_test_int_property (Test* self) +{ + gint result; + g_return_val_if_fail (IS_TEST (self), 0); + result = self->priv->_test_int_property; + return result; +} + +void +test_set_test_int_property (Test* self, + gint value) +{ + gint old_value; + g_return_if_fail (IS_TEST (self)); + old_value = test_get_test_int_property (self); + if (old_value != value) { + self->priv->_test_int_property = value; + g_object_notify_by_pspec ((GObject *) self, test_properties[TEST_TEST_INT_PROPERTY_PROPERTY]); + } +} + +static void +test_class_init (TestClass * klass, + gpointer klass_data) +{ + test_parent_class = g_type_class_peek_parent (klass); + g_type_class_adjust_private_offset (klass, &Test_private_offset); + G_OBJECT_CLASS (klass)->get_property = _vala_test_get_property; + G_OBJECT_CLASS (klass)->set_property = _vala_test_set_property; + G_OBJECT_CLASS (klass)->finalize = test_finalize; + g_object_class_install_property (G_OBJECT_CLASS (klass), TEST_TEST_PROPERTY_PROPERTY, test_properties[TEST_TEST_PROPERTY_PROPERTY] = g_param_spec_string ("test-property", "test-property", "test-property", NULL, G_PARAM_STATIC_STRINGS | G_PARAM_READABLE | G_PARAM_WRITABLE)); + g_object_class_install_property (G_OBJECT_CLASS (klass), TEST_TEST_INT_PROPERTY_PROPERTY, test_properties[TEST_TEST_INT_PROPERTY_PROPERTY] = g_param_spec_int ("test-int-property", "test-int-property", "test-int-property", G_MININT, G_MAXINT, 0, G_PARAM_STATIC_STRINGS | G_PARAM_READABLE | G_PARAM_WRITABLE)); +} + +static void +test_instance_init (Test * self, + gpointer klass) +{ + self->priv = test_get_instance_private (self); +} + +static void +test_finalize (GObject * obj) +{ + Test * self; + self = G_TYPE_CHECK_INSTANCE_CAST (obj, TYPE_TEST, Test); + _g_free0 (self->priv->_test_property); + G_OBJECT_CLASS (test_parent_class)->finalize (obj); +} + +static GType +test_get_type_once (void) +{ + static const GTypeInfo g_define_type_info = { sizeof (TestClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) test_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (Test), 0, (GInstanceInitFunc) test_instance_init, NULL }; + GType test_type_id; + test_type_id = g_type_register_static (G_TYPE_OBJECT, "Test", &g_define_type_info, 0); + g_type_set_qdata (test_type_id, g_quark_from_static_string ("vala-dbus-register-object"), (void*) test_register_object); + Test_private_offset = g_type_add_instance_private (test_type_id, sizeof (TestPrivate)); + return test_type_id; +} + +GType +test_get_type (void) +{ + static volatile gsize test_type_id__volatile = 0; + if (g_once_init_enter (&test_type_id__volatile)) { + GType test_type_id; + test_type_id = test_get_type_once (); + g_once_init_leave (&test_type_id__volatile, test_type_id); + } + return test_type_id__volatile; +} + +static void +_vala_test_get_property (GObject * object, + guint property_id, + GValue * value, + GParamSpec * pspec) +{ + Test * self; + self = G_TYPE_CHECK_INSTANCE_CAST (object, TYPE_TEST, Test); + switch (property_id) { + case TEST_TEST_PROPERTY_PROPERTY: + g_value_take_string (value, test_get_test_property (self)); + break; + case TEST_TEST_INT_PROPERTY_PROPERTY: + g_value_set_int (value, test_get_test_int_property (self)); + break; + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); + break; + } +} + +static void +_vala_test_set_property (GObject * object, + guint property_id, + const GValue * value, + GParamSpec * pspec) +{ + Test * self; + self = G_TYPE_CHECK_INSTANCE_CAST (object, TYPE_TEST, Test); + switch (property_id) { + case TEST_TEST_PROPERTY_PROPERTY: + test_set_test_property (self, g_value_get_string (value)); + break; + case TEST_TEST_INT_PROPERTY_PROPERTY: + test_set_test_int_property (self, g_value_get_int (value)); + break; + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); + break; + } +} + +static void +_dbus_test_test_void (Test* self, + GVariant* _parameters_, + GDBusMethodInvocation* invocation) +{ + GError* error = NULL; + GVariantIter _arguments_iter; + GDBusMessage* _reply_message = NULL; + GVariant* _reply; + GVariantBuilder _reply_builder; + g_variant_iter_init (&_arguments_iter, _parameters_); + test_test_void (self); + _reply_message = g_dbus_message_new_method_reply (g_dbus_method_invocation_get_message (invocation)); + g_variant_builder_init (&_reply_builder, G_VARIANT_TYPE_TUPLE); + _reply = g_variant_builder_end (&_reply_builder); + g_dbus_message_set_body (_reply_message, _reply); + g_dbus_connection_send_message (g_dbus_method_invocation_get_connection (invocation), _reply_message, G_DBUS_SEND_MESSAGE_FLAGS_NONE, NULL, NULL); + g_object_unref (invocation); + g_object_unref (_reply_message); +} + +static void +_dbus_test_test_int (Test* self, + GVariant* _parameters_, + GDBusMethodInvocation* invocation) +{ + GError* error = NULL; + GVariantIter _arguments_iter; + gint i = 0; + GVariant* _tmp0_; + GDBusMessage* _reply_message = NULL; + GVariant* _reply; + GVariantBuilder _reply_builder; + gint j = 0; + gint result; + g_variant_iter_init (&_arguments_iter, _parameters_); + _tmp0_ = g_variant_iter_next_value (&_arguments_iter); + i = g_variant_get_int32 (_tmp0_); + g_variant_unref (_tmp0_); + result = test_test_int (self, i, &j); + _reply_message = g_dbus_message_new_method_reply (g_dbus_method_invocation_get_message (invocation)); + g_variant_builder_init (&_reply_builder, G_VARIANT_TYPE_TUPLE); + g_variant_builder_add_value (&_reply_builder, g_variant_new_int32 (j)); + g_variant_builder_add_value (&_reply_builder, g_variant_new_int32 (result)); + _reply = g_variant_builder_end (&_reply_builder); + g_dbus_message_set_body (_reply_message, _reply); + g_dbus_connection_send_message (g_dbus_method_invocation_get_connection (invocation), _reply_message, G_DBUS_SEND_MESSAGE_FLAGS_NONE, NULL, NULL); + g_object_unref (invocation); + g_object_unref (_reply_message); +} + +static void +_dbus_test_test_string (Test* self, + GVariant* _parameters_, + GDBusMethodInvocation* invocation) +{ + GError* error = NULL; + GVariantIter _arguments_iter; + gchar* s = NULL; + GVariant* _tmp1_; + GDBusMessage* _reply_message = NULL; + GVariant* _reply; + GVariantBuilder _reply_builder; + gchar* t = NULL; + gchar* result; + g_variant_iter_init (&_arguments_iter, _parameters_); + _tmp1_ = g_variant_iter_next_value (&_arguments_iter); + s = g_variant_dup_string (_tmp1_, NULL); + g_variant_unref (_tmp1_); + result = test_test_string (self, s, &t); + _reply_message = g_dbus_message_new_method_reply (g_dbus_method_invocation_get_message (invocation)); + g_variant_builder_init (&_reply_builder, G_VARIANT_TYPE_TUPLE); + g_variant_builder_add_value (&_reply_builder, g_variant_new_string (t)); + g_variant_builder_add_value (&_reply_builder, g_variant_new_string (result)); + _g_free0 (result); + _reply = g_variant_builder_end (&_reply_builder); + g_dbus_message_set_body (_reply_message, _reply); + g_dbus_connection_send_message (g_dbus_method_invocation_get_connection (invocation), _reply_message, G_DBUS_SEND_MESSAGE_FLAGS_NONE, NULL, NULL); + g_object_unref (invocation); + g_object_unref (_reply_message); + _g_free0 (s); + _g_free0 (t); +} + +static void +test_dbus_interface_method_call (GDBusConnection* connection, + const gchar* sender, + const gchar* object_path, + const gchar* interface_name, + const gchar* method_name, + GVariant* parameters, + GDBusMethodInvocation* invocation, + gpointer user_data) +{ + gpointer* data; + gpointer object; + data = user_data; + object = data[0]; + if (strcmp (method_name, "TestVoid") == 0) { + _dbus_test_test_void (object, parameters, invocation); + } else if (strcmp (method_name, "TestInt") == 0) { + _dbus_test_test_int (object, parameters, invocation); + } else if (strcmp (method_name, "TestString") == 0) { + _dbus_test_test_string (object, parameters, invocation); + } else { + g_object_unref (invocation); + } +} + +static GVariant* +_dbus_test_get_test_property (Test* self) +{ + gchar* result; + GVariant* _reply; + result = test_get_test_property (self); + _reply = g_variant_new_string (result); + _g_free0 (result); + return _reply; +} + +static GVariant* +_dbus_test_get_test_int_property (Test* self) +{ + gint result; + GVariant* _reply; + result = test_get_test_int_property (self); + _reply = g_variant_new_int32 (result); + return _reply; +} + +static GVariant* +test_dbus_interface_get_property (GDBusConnection* connection, + const gchar* sender, + const gchar* object_path, + const gchar* interface_name, + const gchar* property_name, + GError** error, + gpointer user_data) +{ + gpointer* data; + gpointer object; + data = user_data; + object = data[0]; + if (strcmp (property_name, "TestProperty") == 0) { + return _dbus_test_get_test_property (object); + } else if (strcmp (property_name, "TestIntProperty") == 0) { + return _dbus_test_get_test_int_property (object); + } + return NULL; +} + +static void +_dbus_test_set_test_property (Test* self, + GVariant* _value) +{ + gchar* value = NULL; + value = g_variant_dup_string (_value, NULL); + test_set_test_property (self, value); + _g_free0 (value); +} + +static void +_dbus_test_set_test_int_property (Test* self, + GVariant* _value) +{ + gint value = 0; + value = g_variant_get_int32 (_value); + test_set_test_int_property (self, value); +} + +static gboolean +test_dbus_interface_set_property (GDBusConnection* connection, + const gchar* sender, + const gchar* object_path, + const gchar* interface_name, + const gchar* property_name, + GVariant* value, + GError** error, + gpointer user_data) +{ + gpointer* data; + gpointer object; + data = user_data; + object = data[0]; + if (strcmp (property_name, "TestProperty") == 0) { + _dbus_test_set_test_property (object, value); + return TRUE; + } else if (strcmp (property_name, "TestIntProperty") == 0) { + _dbus_test_set_test_int_property (object, value); + return TRUE; + } + return FALSE; +} + +guint +test_register_object (gpointer object, + GDBusConnection* connection, + const gchar* path, + GError** error) +{ + guint result; + gpointer *data; + data = g_new (gpointer, 3); + data[0] = g_object_ref (object); + data[1] = g_object_ref (connection); + data[2] = g_strdup (path); + result = g_dbus_connection_register_object (connection, path, (GDBusInterfaceInfo *) (&_test_dbus_interface_info), &_test_dbus_interface_vtable, data, _test_unregister_object, error); + if (!result) { + return 0; + } + return result; +} + +static void +_test_unregister_object (gpointer user_data) +{ + gpointer* data; + data = user_data; + g_object_unref (data[0]); + g_object_unref (data[1]); + g_free (data[2]); + g_free (data); +} + +void +client_exit (GPid pid, + gint status) +{ + GMainLoop* _tmp0_; + _vala_assert (status == 0, "status == 0"); + _tmp0_ = main_loop; + g_main_loop_quit (_tmp0_); +} + +static guint +_variant_get1 (GVariant* value) +{ + return g_variant_get_uint32 (value); +} + +static void +_client_exit_gchild_watch_func (GPid pid, + gint wait_status, + gpointer self) +{ + client_exit (pid, wait_status); +} + +static void +_vala_main (void) +{ + GDBusConnection* conn = NULL; + GDBusConnection* _tmp0_; + GDBusConnection* _tmp1_; + Test* _tmp2_; + Test* _tmp3_; + GVariant* request_result = NULL; + GDBusConnection* _tmp4_; + GVariant* _tmp5_; + GVariant* _tmp6_; + GVariant* _tmp7_; + GVariant* _tmp8_; + GVariant* _tmp9_; + GVariant* _tmp10_; + GVariant* _tmp11_; + guint _tmp12_; + GPid client_pid = 0; + gchar* _tmp13_; + gchar** _tmp14_; + gchar** _tmp15_; + gint _tmp15__length1; + GPid _tmp16_ = 0; + GMainLoop* _tmp17_; + GMainLoop* _tmp18_; + GError* _inner_error0_ = NULL; + _tmp0_ = g_bus_get_sync (G_BUS_TYPE_SESSION, NULL, &_inner_error0_); + conn = _tmp0_; + if (G_UNLIKELY (_inner_error0_ != NULL)) { + g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error0_->message, g_quark_to_string (_inner_error0_->domain), _inner_error0_->code); + g_clear_error (&_inner_error0_); + return; + } + _tmp1_ = conn; + _tmp2_ = test_new (); + _tmp3_ = _tmp2_; + test_register_object (_tmp3_, _tmp1_, "/org/example/test", &_inner_error0_); + _g_object_unref0 (_tmp3_); + if (G_UNLIKELY (_inner_error0_ != NULL)) { + _g_object_unref0 (conn); + g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error0_->message, g_quark_to_string (_inner_error0_->domain), _inner_error0_->code); + g_clear_error (&_inner_error0_); + return; + } + _tmp4_ = conn; + _tmp5_ = g_variant_new ("(su)", "org.example.Test", 0x4, NULL); + g_variant_ref_sink (_tmp5_); + _tmp6_ = _tmp5_; + _tmp7_ = g_dbus_connection_call_sync (_tmp4_, "org.freedesktop.DBus", "/org/freedesktop/DBus", "org.freedesktop.DBus", "RequestName", _tmp6_, NULL, 0, -1, NULL, &_inner_error0_); + _tmp8_ = _tmp7_; + _g_variant_unref0 (_tmp6_); + request_result = _tmp8_; + if (G_UNLIKELY (_inner_error0_ != NULL)) { + _g_object_unref0 (conn); + g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error0_->message, g_quark_to_string (_inner_error0_->domain), _inner_error0_->code); + g_clear_error (&_inner_error0_); + return; + } + _tmp9_ = request_result; + _tmp10_ = g_variant_get_child_value (_tmp9_, (gsize) 0); + _tmp11_ = _tmp10_; + _tmp12_ = _variant_get1 (_tmp11_); + _vala_assert (_tmp12_ == ((guint) 1), "(uint) request_result.get_child_value (0) == 1"); + _g_variant_unref0 (_tmp11_); + _tmp13_ = g_strdup ("dbus_basic_types_client"); + _tmp14_ = g_new0 (gchar*, 1 + 1); + _tmp14_[0] = _tmp13_; + _tmp15_ = _tmp14_; + _tmp15__length1 = 1; + g_spawn_async (NULL, _tmp15_, NULL, G_SPAWN_DO_NOT_REAP_CHILD, NULL, NULL, &_tmp16_, &_inner_error0_); + client_pid = _tmp16_; + _tmp15_ = (_vala_array_free (_tmp15_, _tmp15__length1, (GDestroyNotify) g_free), NULL); + if (G_UNLIKELY (_inner_error0_ != NULL)) { + _g_variant_unref0 (request_result); + _g_object_unref0 (conn); + g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error0_->message, g_quark_to_string (_inner_error0_->domain), _inner_error0_->code); + g_clear_error (&_inner_error0_); + return; + } + g_child_watch_add_full (G_PRIORITY_DEFAULT_IDLE, client_pid, _client_exit_gchild_watch_func, NULL, NULL); + _tmp17_ = g_main_loop_new (NULL, FALSE); + _g_main_loop_unref0 (main_loop); + main_loop = _tmp17_; + _tmp18_ = main_loop; + g_main_loop_run (_tmp18_); + _g_variant_unref0 (request_result); + _g_object_unref0 (conn); +} + +int +main (int argc, + char ** argv) +{ + _vala_main (); + return 0; +} + +static void +_vala_array_destroy (gpointer array, + gssize array_length, + GDestroyNotify destroy_func) +{ + if ((array != NULL) && (destroy_func != NULL)) { + gssize i; + for (i = 0; i < array_length; i = i + 1) { + if (((gpointer*) array)[i] != NULL) { + destroy_func (((gpointer*) array)[i]); + } + } + } +} + +static void +_vala_array_free (gpointer array, + gssize array_length, + GDestroyNotify destroy_func) +{ + _vala_array_destroy (array, array_length, destroy_func); + g_free (array); +} + diff --git a/tests/dbus/bug596862.c-expected b/tests/dbus/bug596862.c-expected new file mode 100644 index 000000000..e85b58e66 --- /dev/null +++ b/tests/dbus/bug596862.c-expected @@ -0,0 +1,277 @@ +/* dbus_bug596862.c generated by valac, the Vala compiler + * generated from dbus_bug596862.vala, do not modify */ + +#include <glib-object.h> +#include <gio/gio.h> +#include <glib.h> +#include <string.h> + +#if !defined(VALA_EXTERN) +#if defined(_MSC_VER) +#define VALA_EXTERN __declspec(dllexport) extern +#elif __GNUC__ >= 4 +#define VALA_EXTERN __attribute__((visibility("default"))) extern +#else +#define VALA_EXTERN extern +#endif +#endif + +#define TYPE_FOO (foo_get_type ()) +#define FOO(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TYPE_FOO, Foo)) +#define FOO_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), TYPE_FOO, FooClass)) +#define IS_FOO(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TYPE_FOO)) +#define IS_FOO_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), TYPE_FOO)) +#define FOO_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), TYPE_FOO, FooClass)) + +typedef struct _Foo Foo; +typedef struct _FooClass FooClass; +typedef struct _FooPrivate FooPrivate; +enum { + FOO_0_PROPERTY, + FOO_NUM_PROPERTIES +}; +static GParamSpec* foo_properties[FOO_NUM_PROPERTIES]; +#define _g_variant_unref0(var) ((var == NULL) ? NULL : (var = (g_variant_unref (var), NULL))) + +struct _Foo { + GObject parent_instance; + FooPrivate * priv; +}; + +struct _FooClass { + GObjectClass parent_class; +}; + +static gpointer foo_parent_class = NULL; + +VALA_EXTERN GType foo_get_type (void) G_GNUC_CONST ; +G_DEFINE_AUTOPTR_CLEANUP_FUNC (Foo, g_object_unref) +VALA_EXTERN guint foo_register_object (void* object, + GDBusConnection* connection, + const gchar* path, + GError** error); +VALA_EXTERN void foo_do_foo (Foo* self, + GVariant* value); +VALA_EXTERN Foo* foo_new (void); +VALA_EXTERN Foo* foo_construct (GType object_type); +static GType foo_get_type_once (void); +static void _dbus_foo_do_foo (Foo* self, + GVariant* _parameters_, + GDBusMethodInvocation* invocation); +static void foo_dbus_interface_method_call (GDBusConnection* connection, + const gchar* sender, + const gchar* object_path, + const gchar* interface_name, + const gchar* method_name, + GVariant* parameters, + GDBusMethodInvocation* invocation, + gpointer user_data); +static GVariant* foo_dbus_interface_get_property (GDBusConnection* connection, + const gchar* sender, + const gchar* object_path, + const gchar* interface_name, + const gchar* property_name, + GError** error, + gpointer user_data); +static gboolean foo_dbus_interface_set_property (GDBusConnection* connection, + const gchar* sender, + const gchar* object_path, + const gchar* interface_name, + const gchar* property_name, + GVariant* value, + GError** error, + gpointer user_data); +static void _foo_unregister_object (gpointer user_data); +static void _vala_main (void); + +static const GDBusArgInfo _foo_dbus_arg_info_do_foo_value = {-1, "value", "v", NULL}; +static const GDBusArgInfo * const _foo_dbus_arg_info_do_foo_in[] = {&_foo_dbus_arg_info_do_foo_value, NULL}; +static const GDBusArgInfo * const _foo_dbus_arg_info_do_foo_out[] = {NULL}; +static const GDBusMethodInfo _foo_dbus_method_info_do_foo = {-1, "DoFoo", (GDBusArgInfo **) (&_foo_dbus_arg_info_do_foo_in), (GDBusArgInfo **) (&_foo_dbus_arg_info_do_foo_out), NULL}; +static const GDBusMethodInfo * const _foo_dbus_method_info[] = {&_foo_dbus_method_info_do_foo, NULL}; +static const GDBusSignalInfo * const _foo_dbus_signal_info[] = {NULL}; +static const GDBusPropertyInfo * const _foo_dbus_property_info[] = {NULL}; +static const GDBusInterfaceInfo _foo_dbus_interface_info = {-1, "org.example.Test", (GDBusMethodInfo **) (&_foo_dbus_method_info), (GDBusSignalInfo **) (&_foo_dbus_signal_info), (GDBusPropertyInfo **) (&_foo_dbus_property_info), NULL}; +static const GDBusInterfaceVTable _foo_dbus_interface_vtable = {foo_dbus_interface_method_call, foo_dbus_interface_get_property, foo_dbus_interface_set_property}; + +void +foo_do_foo (Foo* self, + GVariant* value) +{ + g_return_if_fail (IS_FOO (self)); + g_return_if_fail (value != NULL); +} + +Foo* +foo_construct (GType object_type) +{ + Foo * self = NULL; + self = (Foo*) g_object_new (object_type, NULL); + return self; +} + +Foo* +foo_new (void) +{ + return foo_construct (TYPE_FOO); +} + +static void +foo_class_init (FooClass * klass, + gpointer klass_data) +{ + foo_parent_class = g_type_class_peek_parent (klass); +} + +static void +foo_instance_init (Foo * self, + gpointer klass) +{ +} + +static GType +foo_get_type_once (void) +{ + static const GTypeInfo g_define_type_info = { sizeof (FooClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) foo_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (Foo), 0, (GInstanceInitFunc) foo_instance_init, NULL }; + GType foo_type_id; + foo_type_id = g_type_register_static (G_TYPE_OBJECT, "Foo", &g_define_type_info, 0); + g_type_set_qdata (foo_type_id, g_quark_from_static_string ("vala-dbus-register-object"), (void*) foo_register_object); + return foo_type_id; +} + +GType +foo_get_type (void) +{ + static volatile gsize foo_type_id__volatile = 0; + if (g_once_init_enter (&foo_type_id__volatile)) { + GType foo_type_id; + foo_type_id = foo_get_type_once (); + g_once_init_leave (&foo_type_id__volatile, foo_type_id); + } + return foo_type_id__volatile; +} + +static void +_dbus_foo_do_foo (Foo* self, + GVariant* _parameters_, + GDBusMethodInvocation* invocation) +{ + GError* error = NULL; + GVariantIter _arguments_iter; + GVariant* value = NULL; + GVariant* _tmp0_; + GDBusMessage* _reply_message = NULL; + GVariant* _reply; + GVariantBuilder _reply_builder; + g_variant_iter_init (&_arguments_iter, _parameters_); + _tmp0_ = g_variant_iter_next_value (&_arguments_iter); + value = g_variant_get_variant (_tmp0_); + g_variant_unref (_tmp0_); + foo_do_foo (self, value); + _reply_message = g_dbus_message_new_method_reply (g_dbus_method_invocation_get_message (invocation)); + g_variant_builder_init (&_reply_builder, G_VARIANT_TYPE_TUPLE); + _reply = g_variant_builder_end (&_reply_builder); + g_dbus_message_set_body (_reply_message, _reply); + g_dbus_connection_send_message (g_dbus_method_invocation_get_connection (invocation), _reply_message, G_DBUS_SEND_MESSAGE_FLAGS_NONE, NULL, NULL); + g_object_unref (invocation); + g_object_unref (_reply_message); + _g_variant_unref0 (value); +} + +static void +foo_dbus_interface_method_call (GDBusConnection* connection, + const gchar* sender, + const gchar* object_path, + const gchar* interface_name, + const gchar* method_name, + GVariant* parameters, + GDBusMethodInvocation* invocation, + gpointer user_data) +{ + gpointer* data; + gpointer object; + data = user_data; + object = data[0]; + if (strcmp (method_name, "DoFoo") == 0) { + _dbus_foo_do_foo (object, parameters, invocation); + } else { + g_object_unref (invocation); + } +} + +static GVariant* +foo_dbus_interface_get_property (GDBusConnection* connection, + const gchar* sender, + const gchar* object_path, + const gchar* interface_name, + const gchar* property_name, + GError** error, + gpointer user_data) +{ + gpointer* data; + gpointer object; + data = user_data; + object = data[0]; + return NULL; +} + +static gboolean +foo_dbus_interface_set_property (GDBusConnection* connection, + const gchar* sender, + const gchar* object_path, + const gchar* interface_name, + const gchar* property_name, + GVariant* value, + GError** error, + gpointer user_data) +{ + gpointer* data; + gpointer object; + data = user_data; + object = data[0]; + return FALSE; +} + +guint +foo_register_object (gpointer object, + GDBusConnection* connection, + const gchar* path, + GError** error) +{ + guint result; + gpointer *data; + data = g_new (gpointer, 3); + data[0] = g_object_ref (object); + data[1] = g_object_ref (connection); + data[2] = g_strdup (path); + result = g_dbus_connection_register_object (connection, path, (GDBusInterfaceInfo *) (&_foo_dbus_interface_info), &_foo_dbus_interface_vtable, data, _foo_unregister_object, error); + if (!result) { + return 0; + } + return result; +} + +static void +_foo_unregister_object (gpointer user_data) +{ + gpointer* data; + data = user_data; + g_object_unref (data[0]); + g_object_unref (data[1]); + g_free (data[2]); + g_free (data); +} + +static void +_vala_main (void) +{ +} + +int +main (int argc, + char ** argv) +{ + _vala_main (); + return 0; +} + diff --git a/tests/dbus/bug602003_client.c-expected b/tests/dbus/bug602003_client.c-expected new file mode 100644 index 000000000..38836347a --- /dev/null +++ b/tests/dbus/bug602003_client.c-expected @@ -0,0 +1,443 @@ +/* dbus_bug602003_client.c generated by valac, the Vala compiler + * generated from dbus_bug602003_client.vala, do not modify */ + +#include <glib-object.h> +#include <gio/gio.h> +#include <glib.h> +#include <string.h> +#include <stdlib.h> + +#if !defined(VALA_EXTERN) +#if defined(_MSC_VER) +#define VALA_EXTERN __declspec(dllexport) extern +#elif __GNUC__ >= 4 +#define VALA_EXTERN __attribute__((visibility("default"))) extern +#else +#define VALA_EXTERN extern +#endif +#endif + +#define TYPE_TEST (test_get_type ()) +#define TEST(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TYPE_TEST, Test)) +#define IS_TEST(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TYPE_TEST)) +#define TEST_GET_INTERFACE(obj) (G_TYPE_INSTANCE_GET_INTERFACE ((obj), TYPE_TEST, TestIface)) + +typedef struct _Test Test; +typedef struct _TestIface TestIface; + +#define TYPE_TEST_PROXY (test_proxy_get_type ()) +typedef GDBusProxy TestProxy; +typedef GDBusProxyClass TestProxyClass; +#define _g_variant_unref0(var) ((var == NULL) ? NULL : (var = (g_variant_unref (var), NULL))) +#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL))) +#define _vala_assert(expr, msg) if G_LIKELY (expr) ; else g_assertion_message_expr (G_LOG_DOMAIN, __FILE__, __LINE__, G_STRFUNC, msg); +#define _vala_return_if_fail(expr, msg) if G_LIKELY (expr) ; else { g_return_if_fail_warning (G_LOG_DOMAIN, G_STRFUNC, msg); return; } +#define _vala_return_val_if_fail(expr, msg, val) if G_LIKELY (expr) ; else { g_return_if_fail_warning (G_LOG_DOMAIN, G_STRFUNC, msg); return val; } +#define _vala_warn_if_fail(expr, msg) if G_LIKELY (expr) ; else g_warn_message (G_LOG_DOMAIN, __FILE__, __LINE__, G_STRFUNC, msg); + +struct _TestIface { + GTypeInterface parent_iface; + GVariant* (*test_string) (Test* self, GError** error); +}; + +VALA_EXTERN GType test_proxy_get_type (void) G_GNUC_CONST ; +VALA_EXTERN guint test_register_object (void* object, + GDBusConnection* connection, + const gchar* path, + GError** error); +VALA_EXTERN GType test_get_type (void) G_GNUC_CONST ; +VALA_EXTERN GVariant* test_test_string (Test* self, + GError** error); +static GType test_get_type_once (void); +static void test_proxy_g_signal (GDBusProxy* proxy, + const gchar* sender_name, + const gchar* signal_name, + GVariant* parameters); +static GVariant* test_proxy_test_string (Test* self, + GError** error); +static void test_proxy_test_interface_init (TestIface* iface); +static void _dbus_test_test_string (Test* self, + GVariant* _parameters_, + GDBusMethodInvocation* invocation); +static void test_dbus_interface_method_call (GDBusConnection* connection, + const gchar* sender, + const gchar* object_path, + const gchar* interface_name, + const gchar* method_name, + GVariant* parameters, + GDBusMethodInvocation* invocation, + gpointer user_data); +static GVariant* test_dbus_interface_get_property (GDBusConnection* connection, + const gchar* sender, + const gchar* object_path, + const gchar* interface_name, + const gchar* property_name, + GError** error, + gpointer user_data); +static gboolean test_dbus_interface_set_property (GDBusConnection* connection, + const gchar* sender, + const gchar* object_path, + const gchar* interface_name, + const gchar* property_name, + GVariant* value, + GError** error, + gpointer user_data); +static void _test_unregister_object (gpointer user_data); +static void _vala_main (void); +static gchar** _variant_get1 (GVariant* value, + gint* result_length1); +static void _vala_array_destroy (gpointer array, + gssize array_length, + GDestroyNotify destroy_func); +static void _vala_array_free (gpointer array, + gssize array_length, + GDestroyNotify destroy_func); + +static const GDBusArgInfo _test_dbus_arg_info_test_string_result = {-1, "result", "v", NULL}; +static const GDBusArgInfo * const _test_dbus_arg_info_test_string_in[] = {NULL}; +static const GDBusArgInfo * const _test_dbus_arg_info_test_string_out[] = {&_test_dbus_arg_info_test_string_result, NULL}; +static const GDBusMethodInfo _test_dbus_method_info_test_string = {-1, "TestString", (GDBusArgInfo **) (&_test_dbus_arg_info_test_string_in), (GDBusArgInfo **) (&_test_dbus_arg_info_test_string_out), NULL}; +static const GDBusMethodInfo * const _test_dbus_method_info[] = {&_test_dbus_method_info_test_string, NULL}; +static const GDBusSignalInfo * const _test_dbus_signal_info[] = {NULL}; +static const GDBusPropertyInfo * const _test_dbus_property_info[] = {NULL}; +static const GDBusInterfaceInfo _test_dbus_interface_info = {-1, "org.example.Test", (GDBusMethodInfo **) (&_test_dbus_method_info), (GDBusSignalInfo **) (&_test_dbus_signal_info), (GDBusPropertyInfo **) (&_test_dbus_property_info), NULL}; +static const GDBusInterfaceVTable _test_dbus_interface_vtable = {test_dbus_interface_method_call, test_dbus_interface_get_property, test_dbus_interface_set_property}; + +GVariant* +test_test_string (Test* self, + GError** error) +{ + TestIface* _iface_; + g_return_val_if_fail (IS_TEST (self), NULL); + _iface_ = TEST_GET_INTERFACE (self); + if (_iface_->test_string) { + return _iface_->test_string (self, error); + } + return NULL; +} + +static void +test_default_init (TestIface * iface, + gpointer iface_data) +{ +} + +static GType +test_get_type_once (void) +{ + static const GTypeInfo g_define_type_info = { sizeof (TestIface), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) test_default_init, (GClassFinalizeFunc) NULL, NULL, 0, 0, (GInstanceInitFunc) NULL, NULL }; + GType test_type_id; + test_type_id = g_type_register_static (G_TYPE_INTERFACE, "Test", &g_define_type_info, 0); + g_type_interface_add_prerequisite (test_type_id, G_TYPE_OBJECT); + g_type_set_qdata (test_type_id, g_quark_from_static_string ("vala-dbus-proxy-type"), (void*) test_proxy_get_type); + g_type_set_qdata (test_type_id, g_quark_from_static_string ("vala-dbus-interface-name"), "org.example.Test"); + g_type_set_qdata (test_type_id, g_quark_from_static_string ("vala-dbus-interface-info"), (void*) (&_test_dbus_interface_info)); + g_type_set_qdata (test_type_id, g_quark_from_static_string ("vala-dbus-register-object"), (void*) test_register_object); + return test_type_id; +} + +GType +test_get_type (void) +{ + static volatile gsize test_type_id__volatile = 0; + if (g_once_init_enter (&test_type_id__volatile)) { + GType test_type_id; + test_type_id = test_get_type_once (); + g_once_init_leave (&test_type_id__volatile, test_type_id); + } + return test_type_id__volatile; +} + +G_DEFINE_TYPE_EXTENDED (TestProxy, test_proxy, G_TYPE_DBUS_PROXY, 0, G_IMPLEMENT_INTERFACE (TYPE_TEST, test_proxy_test_interface_init) ) +static void +test_proxy_class_init (TestProxyClass* klass) +{ + G_DBUS_PROXY_CLASS (klass)->g_signal = test_proxy_g_signal; +} + +static void +test_proxy_g_signal (GDBusProxy* proxy, + const gchar* sender_name, + const gchar* signal_name, + GVariant* parameters) +{ +} + +static void +test_proxy_init (TestProxy* self) +{ + g_dbus_proxy_set_interface_info (G_DBUS_PROXY (self), (GDBusInterfaceInfo *) (&_test_dbus_interface_info)); +} + +static GVariant* +test_proxy_test_string (Test* self, + GError** error) +{ + GDBusMessage *_message; + GVariant *_arguments; + GVariantBuilder _arguments_builder; + GDBusMessage *_reply_message; + GVariant *_reply; + GVariantIter _reply_iter; + GVariant* _result = NULL; + GVariant* _tmp0_; + G_IO_ERROR; + _message = g_dbus_message_new_method_call (g_dbus_proxy_get_name ((GDBusProxy *) self), g_dbus_proxy_get_object_path ((GDBusProxy *) self), "org.example.Test", "TestString"); + g_variant_builder_init (&_arguments_builder, G_VARIANT_TYPE_TUPLE); + _arguments = g_variant_builder_end (&_arguments_builder); + g_dbus_message_set_body (_message, _arguments); + _reply_message = g_dbus_connection_send_message_with_reply_sync (g_dbus_proxy_get_connection ((GDBusProxy *) self), _message, G_DBUS_SEND_MESSAGE_FLAGS_NONE, g_dbus_proxy_get_default_timeout ((GDBusProxy *) self), NULL, NULL, error); + g_object_unref (_message); + if (!_reply_message) { + return NULL; + } + if (g_dbus_message_to_gerror (_reply_message, error)) { + g_object_unref (_reply_message); + return NULL; + } + _reply = g_dbus_message_get_body (_reply_message); + g_variant_iter_init (&_reply_iter, _reply); + _tmp0_ = g_variant_iter_next_value (&_reply_iter); + _result = g_variant_get_variant (_tmp0_); + g_variant_unref (_tmp0_); + g_object_unref (_reply_message); + return _result; +} + +static void +test_proxy_test_interface_init (TestIface* iface) +{ + iface->test_string = test_proxy_test_string; +} + +static void +_dbus_test_test_string (Test* self, + GVariant* _parameters_, + GDBusMethodInvocation* invocation) +{ + GError* error = NULL; + GVariantIter _arguments_iter; + GDBusMessage* _reply_message = NULL; + GVariant* _reply; + GVariantBuilder _reply_builder; + GVariant* result; + g_variant_iter_init (&_arguments_iter, _parameters_); + result = test_test_string (self, &error); + if (error) { + g_dbus_method_invocation_return_gerror (invocation, error); + g_error_free (error); + return; + } + _reply_message = g_dbus_message_new_method_reply (g_dbus_method_invocation_get_message (invocation)); + g_variant_builder_init (&_reply_builder, G_VARIANT_TYPE_TUPLE); + g_variant_builder_add_value (&_reply_builder, g_variant_new_variant (result)); + _g_variant_unref0 (result); + _reply = g_variant_builder_end (&_reply_builder); + g_dbus_message_set_body (_reply_message, _reply); + g_dbus_connection_send_message (g_dbus_method_invocation_get_connection (invocation), _reply_message, G_DBUS_SEND_MESSAGE_FLAGS_NONE, NULL, NULL); + g_object_unref (invocation); + g_object_unref (_reply_message); +} + +static void +test_dbus_interface_method_call (GDBusConnection* connection, + const gchar* sender, + const gchar* object_path, + const gchar* interface_name, + const gchar* method_name, + GVariant* parameters, + GDBusMethodInvocation* invocation, + gpointer user_data) +{ + gpointer* data; + gpointer object; + data = user_data; + object = data[0]; + if (strcmp (method_name, "TestString") == 0) { + _dbus_test_test_string (object, parameters, invocation); + } else { + g_object_unref (invocation); + } +} + +static GVariant* +test_dbus_interface_get_property (GDBusConnection* connection, + const gchar* sender, + const gchar* object_path, + const gchar* interface_name, + const gchar* property_name, + GError** error, + gpointer user_data) +{ + gpointer* data; + gpointer object; + data = user_data; + object = data[0]; + return NULL; +} + +static gboolean +test_dbus_interface_set_property (GDBusConnection* connection, + const gchar* sender, + const gchar* object_path, + const gchar* interface_name, + const gchar* property_name, + GVariant* value, + GError** error, + gpointer user_data) +{ + gpointer* data; + gpointer object; + data = user_data; + object = data[0]; + return FALSE; +} + +guint +test_register_object (gpointer object, + GDBusConnection* connection, + const gchar* path, + GError** error) +{ + guint result; + gpointer *data; + data = g_new (gpointer, 3); + data[0] = g_object_ref (object); + data[1] = g_object_ref (connection); + data[2] = g_strdup (path); + result = g_dbus_connection_register_object (connection, path, (GDBusInterfaceInfo *) (&_test_dbus_interface_info), &_test_dbus_interface_vtable, data, _test_unregister_object, error); + if (!result) { + return 0; + } + return result; +} + +static void +_test_unregister_object (gpointer user_data) +{ + gpointer* data; + data = user_data; + g_object_unref (data[0]); + g_object_unref (data[1]); + g_free (data[2]); + g_free (data); +} + +static gchar** +_variant_get1 (GVariant* value, + gint* result_length1) +{ + gchar** _tmp5_; + gint _tmp5__length; + gint _tmp5__size; + gint _tmp5__length1; + GVariantIter _tmp6_; + GVariant* _tmp7_; + _tmp5_ = g_new (gchar*, 5); + _tmp5__length = 0; + _tmp5__size = 4; + _tmp5__length1 = 0; + g_variant_iter_init (&_tmp6_, value); + for (; (_tmp7_ = g_variant_iter_next_value (&_tmp6_)) != NULL; _tmp5__length1++) { + if (_tmp5__size == _tmp5__length) { + _tmp5__size = 2 * _tmp5__size; + _tmp5_ = g_renew (gchar*, _tmp5_, _tmp5__size + 1); + } + _tmp5_[_tmp5__length++] = g_variant_dup_string (_tmp7_, NULL); + g_variant_unref (_tmp7_); + } + *result_length1 = _tmp5__length1; + _tmp5_[_tmp5__length] = NULL; + return _tmp5_; +} + +static void +_vala_main (void) +{ + Test* test = NULL; + Test* _tmp0_; + GVariant* v = NULL; + Test* _tmp1_; + GVariant* _tmp2_; + gchar** s = NULL; + GVariant* _tmp3_; + gchar** _tmp4_ = NULL; + gint _tmp4__length1 = 0; + gint s_length1; + gint _s_size_; + gboolean _tmp8_ = FALSE; + gchar** _tmp9_; + gint _tmp9__length1; + GError* _inner_error0_ = NULL; + _tmp0_ = (Test*) g_initable_new (TYPE_TEST_PROXY, NULL, &_inner_error0_, "g-flags", 0, "g-name", "org.example.Test", "g-bus-type", G_BUS_TYPE_SESSION, "g-object-path", "/org/example/test", "g-interface-name", "org.example.Test", NULL); + test = (Test*) _tmp0_; + if (G_UNLIKELY (_inner_error0_ != NULL)) { + g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error0_->message, g_quark_to_string (_inner_error0_->domain), _inner_error0_->code); + g_clear_error (&_inner_error0_); + return; + } + _tmp1_ = test; + _tmp2_ = test_test_string (_tmp1_, &_inner_error0_); + v = _tmp2_; + if (G_UNLIKELY (_inner_error0_ != NULL)) { + _g_object_unref0 (test); + g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error0_->message, g_quark_to_string (_inner_error0_->domain), _inner_error0_->code); + g_clear_error (&_inner_error0_); + return; + } + _tmp3_ = v; + _tmp4_ = _variant_get1 (_tmp3_, &_tmp4__length1); + s = _tmp4_; + s_length1 = _tmp4__length1; + _s_size_ = s_length1; + _tmp9_ = s; + _tmp9__length1 = s_length1; + if (_tmp9__length1 == 1) { + gchar** _tmp10_; + gint _tmp10__length1; + const gchar* _tmp11_; + _tmp10_ = s; + _tmp10__length1 = s_length1; + _tmp11_ = _tmp10_[0]; + _tmp8_ = g_strcmp0 (_tmp11_, "hello") == 0; + } else { + _tmp8_ = FALSE; + } + _vala_assert (_tmp8_, "s.length == 1 && s[0] == \"hello\""); + s = (_vala_array_free (s, s_length1, (GDestroyNotify) g_free), NULL); + _g_variant_unref0 (v); + _g_object_unref0 (test); +} + +int +main (int argc, + char ** argv) +{ + _vala_main (); + return 0; +} + +static void +_vala_array_destroy (gpointer array, + gssize array_length, + GDestroyNotify destroy_func) +{ + if ((array != NULL) && (destroy_func != NULL)) { + gssize i; + for (i = 0; i < array_length; i = i + 1) { + if (((gpointer*) array)[i] != NULL) { + destroy_func (((gpointer*) array)[i]); + } + } + } +} + +static void +_vala_array_free (gpointer array, + gssize array_length, + GDestroyNotify destroy_func) +{ + _vala_array_destroy (array, array_length, destroy_func); + g_free (array); +} + diff --git a/tests/dbus/bug602003_server.c-expected b/tests/dbus/bug602003_server.c-expected new file mode 100644 index 000000000..d3801ff78 --- /dev/null +++ b/tests/dbus/bug602003_server.c-expected @@ -0,0 +1,466 @@ +/* dbus_bug602003_server.c generated by valac, the Vala compiler + * generated from dbus_bug602003_server.vala, do not modify */ + +#include <glib-object.h> +#include <gio/gio.h> +#include <glib.h> +#include <stdlib.h> +#include <string.h> + +#if !defined(VALA_EXTERN) +#if defined(_MSC_VER) +#define VALA_EXTERN __declspec(dllexport) extern +#elif __GNUC__ >= 4 +#define VALA_EXTERN __attribute__((visibility("default"))) extern +#else +#define VALA_EXTERN extern +#endif +#endif + +#define TYPE_TEST (test_get_type ()) +#define TEST(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TYPE_TEST, Test)) +#define TEST_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), TYPE_TEST, TestClass)) +#define IS_TEST(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TYPE_TEST)) +#define IS_TEST_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), TYPE_TEST)) +#define TEST_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), TYPE_TEST, TestClass)) + +typedef struct _Test Test; +typedef struct _TestClass TestClass; +typedef struct _TestPrivate TestPrivate; +enum { + TEST_0_PROPERTY, + TEST_NUM_PROPERTIES +}; +static GParamSpec* test_properties[TEST_NUM_PROPERTIES]; +#define _g_variant_unref0(var) ((var == NULL) ? NULL : (var = (g_variant_unref (var), NULL))) +#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL))) +#define _g_main_loop_unref0(var) ((var == NULL) ? NULL : (var = (g_main_loop_unref (var), NULL))) +#define _vala_assert(expr, msg) if G_LIKELY (expr) ; else g_assertion_message_expr (G_LOG_DOMAIN, __FILE__, __LINE__, G_STRFUNC, msg); +#define _vala_return_if_fail(expr, msg) if G_LIKELY (expr) ; else { g_return_if_fail_warning (G_LOG_DOMAIN, G_STRFUNC, msg); return; } +#define _vala_return_val_if_fail(expr, msg, val) if G_LIKELY (expr) ; else { g_return_if_fail_warning (G_LOG_DOMAIN, G_STRFUNC, msg); return val; } +#define _vala_warn_if_fail(expr, msg) if G_LIKELY (expr) ; else g_warn_message (G_LOG_DOMAIN, __FILE__, __LINE__, G_STRFUNC, msg); + +struct _Test { + GObject parent_instance; + TestPrivate * priv; +}; + +struct _TestClass { + GObjectClass parent_class; +}; + +static gpointer test_parent_class = NULL; +VALA_EXTERN GMainLoop* main_loop; +GMainLoop* main_loop = NULL; + +VALA_EXTERN GType test_get_type (void) G_GNUC_CONST ; +G_DEFINE_AUTOPTR_CLEANUP_FUNC (Test, g_object_unref) +VALA_EXTERN guint test_register_object (void* object, + GDBusConnection* connection, + const gchar* path, + GError** error); +VALA_EXTERN GVariant* test_test_string (Test* self); +static GVariant* _variant_new1 (gchar** value, + gint value_length1); +VALA_EXTERN Test* test_new (void); +VALA_EXTERN Test* test_construct (GType object_type); +static GType test_get_type_once (void); +static void _dbus_test_test_string (Test* self, + GVariant* _parameters_, + GDBusMethodInvocation* invocation); +static void test_dbus_interface_method_call (GDBusConnection* connection, + const gchar* sender, + const gchar* object_path, + const gchar* interface_name, + const gchar* method_name, + GVariant* parameters, + GDBusMethodInvocation* invocation, + gpointer user_data); +static GVariant* test_dbus_interface_get_property (GDBusConnection* connection, + const gchar* sender, + const gchar* object_path, + const gchar* interface_name, + const gchar* property_name, + GError** error, + gpointer user_data); +static gboolean test_dbus_interface_set_property (GDBusConnection* connection, + const gchar* sender, + const gchar* object_path, + const gchar* interface_name, + const gchar* property_name, + GVariant* value, + GError** error, + gpointer user_data); +static void _test_unregister_object (gpointer user_data); +VALA_EXTERN void client_exit (GPid pid, + gint status); +static void _vala_main (void); +static guint _variant_get1 (GVariant* value); +static void _client_exit_gchild_watch_func (GPid pid, + gint wait_status, + gpointer self); +static void _vala_array_destroy (gpointer array, + gssize array_length, + GDestroyNotify destroy_func); +static void _vala_array_free (gpointer array, + gssize array_length, + GDestroyNotify destroy_func); + +static const GDBusArgInfo _test_dbus_arg_info_test_string_result = {-1, "result", "v", NULL}; +static const GDBusArgInfo * const _test_dbus_arg_info_test_string_in[] = {NULL}; +static const GDBusArgInfo * const _test_dbus_arg_info_test_string_out[] = {&_test_dbus_arg_info_test_string_result, NULL}; +static const GDBusMethodInfo _test_dbus_method_info_test_string = {-1, "TestString", (GDBusArgInfo **) (&_test_dbus_arg_info_test_string_in), (GDBusArgInfo **) (&_test_dbus_arg_info_test_string_out), NULL}; +static const GDBusMethodInfo * const _test_dbus_method_info[] = {&_test_dbus_method_info_test_string, NULL}; +static const GDBusSignalInfo * const _test_dbus_signal_info[] = {NULL}; +static const GDBusPropertyInfo * const _test_dbus_property_info[] = {NULL}; +static const GDBusInterfaceInfo _test_dbus_interface_info = {-1, "org.example.Test", (GDBusMethodInfo **) (&_test_dbus_method_info), (GDBusSignalInfo **) (&_test_dbus_signal_info), (GDBusPropertyInfo **) (&_test_dbus_property_info), NULL}; +static const GDBusInterfaceVTable _test_dbus_interface_vtable = {test_dbus_interface_method_call, test_dbus_interface_get_property, test_dbus_interface_set_property}; + +static GVariant* +_variant_new1 (gchar** value, + gint value_length1) +{ + gchar** _tmp3_; + GVariantBuilder _tmp4_; + gint _tmp5_; + _tmp3_ = value; + g_variant_builder_init (&_tmp4_, G_VARIANT_TYPE ("as")); + for (_tmp5_ = 0; _tmp5_ < value_length1; _tmp5_++) { + g_variant_builder_add_value (&_tmp4_, g_variant_new_string (*_tmp3_)); + _tmp3_++; + } + return g_variant_ref_sink (g_variant_builder_end (&_tmp4_)); +} + +GVariant* +test_test_string (Test* self) +{ + gchar** s = NULL; + gchar* _tmp0_; + gchar** _tmp1_; + gint s_length1; + gint _s_size_; + gchar** _tmp2_; + gint _tmp2__length1; + GVariant* _tmp6_; + GVariant* _tmp7_; + GVariant* result = NULL; + g_return_val_if_fail (IS_TEST (self), NULL); + _tmp0_ = g_strdup ("hello"); + _tmp1_ = g_new0 (gchar*, 1 + 1); + _tmp1_[0] = _tmp0_; + s = _tmp1_; + s_length1 = 1; + _s_size_ = s_length1; + _tmp2_ = s; + _tmp2__length1 = s_length1; + _tmp6_ = _variant_new1 (_tmp2_, s_length1); + _tmp7_ = _tmp6_; + _tmp2_ = (_vala_array_free (_tmp2_, _tmp2__length1, (GDestroyNotify) g_free), NULL); + result = _tmp7_; + return result; +} + +Test* +test_construct (GType object_type) +{ + Test * self = NULL; + self = (Test*) g_object_new (object_type, NULL); + return self; +} + +Test* +test_new (void) +{ + return test_construct (TYPE_TEST); +} + +static void +test_class_init (TestClass * klass, + gpointer klass_data) +{ + test_parent_class = g_type_class_peek_parent (klass); +} + +static void +test_instance_init (Test * self, + gpointer klass) +{ +} + +static GType +test_get_type_once (void) +{ + static const GTypeInfo g_define_type_info = { sizeof (TestClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) test_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (Test), 0, (GInstanceInitFunc) test_instance_init, NULL }; + GType test_type_id; + test_type_id = g_type_register_static (G_TYPE_OBJECT, "Test", &g_define_type_info, 0); + g_type_set_qdata (test_type_id, g_quark_from_static_string ("vala-dbus-register-object"), (void*) test_register_object); + return test_type_id; +} + +GType +test_get_type (void) +{ + static volatile gsize test_type_id__volatile = 0; + if (g_once_init_enter (&test_type_id__volatile)) { + GType test_type_id; + test_type_id = test_get_type_once (); + g_once_init_leave (&test_type_id__volatile, test_type_id); + } + return test_type_id__volatile; +} + +static void +_dbus_test_test_string (Test* self, + GVariant* _parameters_, + GDBusMethodInvocation* invocation) +{ + GError* error = NULL; + GVariantIter _arguments_iter; + GDBusMessage* _reply_message = NULL; + GVariant* _reply; + GVariantBuilder _reply_builder; + GVariant* result; + g_variant_iter_init (&_arguments_iter, _parameters_); + result = test_test_string (self); + _reply_message = g_dbus_message_new_method_reply (g_dbus_method_invocation_get_message (invocation)); + g_variant_builder_init (&_reply_builder, G_VARIANT_TYPE_TUPLE); + g_variant_builder_add_value (&_reply_builder, g_variant_new_variant (result)); + _g_variant_unref0 (result); + _reply = g_variant_builder_end (&_reply_builder); + g_dbus_message_set_body (_reply_message, _reply); + g_dbus_connection_send_message (g_dbus_method_invocation_get_connection (invocation), _reply_message, G_DBUS_SEND_MESSAGE_FLAGS_NONE, NULL, NULL); + g_object_unref (invocation); + g_object_unref (_reply_message); +} + +static void +test_dbus_interface_method_call (GDBusConnection* connection, + const gchar* sender, + const gchar* object_path, + const gchar* interface_name, + const gchar* method_name, + GVariant* parameters, + GDBusMethodInvocation* invocation, + gpointer user_data) +{ + gpointer* data; + gpointer object; + data = user_data; + object = data[0]; + if (strcmp (method_name, "TestString") == 0) { + _dbus_test_test_string (object, parameters, invocation); + } else { + g_object_unref (invocation); + } +} + +static GVariant* +test_dbus_interface_get_property (GDBusConnection* connection, + const gchar* sender, + const gchar* object_path, + const gchar* interface_name, + const gchar* property_name, + GError** error, + gpointer user_data) +{ + gpointer* data; + gpointer object; + data = user_data; + object = data[0]; + return NULL; +} + +static gboolean +test_dbus_interface_set_property (GDBusConnection* connection, + const gchar* sender, + const gchar* object_path, + const gchar* interface_name, + const gchar* property_name, + GVariant* value, + GError** error, + gpointer user_data) +{ + gpointer* data; + gpointer object; + data = user_data; + object = data[0]; + return FALSE; +} + +guint +test_register_object (gpointer object, + GDBusConnection* connection, + const gchar* path, + GError** error) +{ + guint result; + gpointer *data; + data = g_new (gpointer, 3); + data[0] = g_object_ref (object); + data[1] = g_object_ref (connection); + data[2] = g_strdup (path); + result = g_dbus_connection_register_object (connection, path, (GDBusInterfaceInfo *) (&_test_dbus_interface_info), &_test_dbus_interface_vtable, data, _test_unregister_object, error); + if (!result) { + return 0; + } + return result; +} + +static void +_test_unregister_object (gpointer user_data) +{ + gpointer* data; + data = user_data; + g_object_unref (data[0]); + g_object_unref (data[1]); + g_free (data[2]); + g_free (data); +} + +void +client_exit (GPid pid, + gint status) +{ + GMainLoop* _tmp0_; + _vala_assert (status == 0, "status == 0"); + _tmp0_ = main_loop; + g_main_loop_quit (_tmp0_); +} + +static guint +_variant_get1 (GVariant* value) +{ + return g_variant_get_uint32 (value); +} + +static void +_client_exit_gchild_watch_func (GPid pid, + gint wait_status, + gpointer self) +{ + client_exit (pid, wait_status); +} + +static void +_vala_main (void) +{ + GDBusConnection* conn = NULL; + GDBusConnection* _tmp0_; + GDBusConnection* _tmp1_; + Test* _tmp2_; + Test* _tmp3_; + GVariant* request_result = NULL; + GDBusConnection* _tmp4_; + GVariant* _tmp5_; + GVariant* _tmp6_; + GVariant* _tmp7_; + GVariant* _tmp8_; + GVariant* _tmp9_; + GVariant* _tmp10_; + GVariant* _tmp11_; + guint _tmp12_; + GPid client_pid = 0; + gchar* _tmp13_; + gchar** _tmp14_; + gchar** _tmp15_; + gint _tmp15__length1; + GPid _tmp16_ = 0; + GMainLoop* _tmp17_; + GMainLoop* _tmp18_; + GError* _inner_error0_ = NULL; + _tmp0_ = g_bus_get_sync (G_BUS_TYPE_SESSION, NULL, &_inner_error0_); + conn = _tmp0_; + if (G_UNLIKELY (_inner_error0_ != NULL)) { + g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error0_->message, g_quark_to_string (_inner_error0_->domain), _inner_error0_->code); + g_clear_error (&_inner_error0_); + return; + } + _tmp1_ = conn; + _tmp2_ = test_new (); + _tmp3_ = _tmp2_; + test_register_object (_tmp3_, _tmp1_, "/org/example/test", &_inner_error0_); + _g_object_unref0 (_tmp3_); + if (G_UNLIKELY (_inner_error0_ != NULL)) { + _g_object_unref0 (conn); + g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error0_->message, g_quark_to_string (_inner_error0_->domain), _inner_error0_->code); + g_clear_error (&_inner_error0_); + return; + } + _tmp4_ = conn; + _tmp5_ = g_variant_new ("(su)", "org.example.Test", 0x4, NULL); + g_variant_ref_sink (_tmp5_); + _tmp6_ = _tmp5_; + _tmp7_ = g_dbus_connection_call_sync (_tmp4_, "org.freedesktop.DBus", "/org/freedesktop/DBus", "org.freedesktop.DBus", "RequestName", _tmp6_, NULL, 0, -1, NULL, &_inner_error0_); + _tmp8_ = _tmp7_; + _g_variant_unref0 (_tmp6_); + request_result = _tmp8_; + if (G_UNLIKELY (_inner_error0_ != NULL)) { + _g_object_unref0 (conn); + g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error0_->message, g_quark_to_string (_inner_error0_->domain), _inner_error0_->code); + g_clear_error (&_inner_error0_); + return; + } + _tmp9_ = request_result; + _tmp10_ = g_variant_get_child_value (_tmp9_, (gsize) 0); + _tmp11_ = _tmp10_; + _tmp12_ = _variant_get1 (_tmp11_); + _vala_assert (_tmp12_ == ((guint) 1), "(uint) request_result.get_child_value (0) == 1"); + _g_variant_unref0 (_tmp11_); + _tmp13_ = g_strdup ("dbus_bug602003_client"); + _tmp14_ = g_new0 (gchar*, 1 + 1); + _tmp14_[0] = _tmp13_; + _tmp15_ = _tmp14_; + _tmp15__length1 = 1; + g_spawn_async (NULL, _tmp15_, NULL, G_SPAWN_DO_NOT_REAP_CHILD, NULL, NULL, &_tmp16_, &_inner_error0_); + client_pid = _tmp16_; + _tmp15_ = (_vala_array_free (_tmp15_, _tmp15__length1, (GDestroyNotify) g_free), NULL); + if (G_UNLIKELY (_inner_error0_ != NULL)) { + _g_variant_unref0 (request_result); + _g_object_unref0 (conn); + g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error0_->message, g_quark_to_string (_inner_error0_->domain), _inner_error0_->code); + g_clear_error (&_inner_error0_); + return; + } + g_child_watch_add_full (G_PRIORITY_DEFAULT_IDLE, client_pid, _client_exit_gchild_watch_func, NULL, NULL); + _tmp17_ = g_main_loop_new (NULL, FALSE); + _g_main_loop_unref0 (main_loop); + main_loop = _tmp17_; + _tmp18_ = main_loop; + g_main_loop_run (_tmp18_); + _g_variant_unref0 (request_result); + _g_object_unref0 (conn); +} + +int +main (int argc, + char ** argv) +{ + _vala_main (); + return 0; +} + +static void +_vala_array_destroy (gpointer array, + gssize array_length, + GDestroyNotify destroy_func) +{ + if ((array != NULL) && (destroy_func != NULL)) { + gssize i; + for (i = 0; i < array_length; i = i + 1) { + if (((gpointer*) array)[i] != NULL) { + destroy_func (((gpointer*) array)[i]); + } + } + } +} + +static void +_vala_array_free (gpointer array, + gssize array_length, + GDestroyNotify destroy_func) +{ + _vala_array_destroy (array, array_length, destroy_func); + g_free (array); +} + diff --git a/tests/dbus/bug735437_client.c-expected b/tests/dbus/bug735437_client.c-expected new file mode 100644 index 000000000..dae32bff8 --- /dev/null +++ b/tests/dbus/bug735437_client.c-expected @@ -0,0 +1,1017 @@ +/* dbus_bug735437_client.c generated by valac, the Vala compiler + * generated from dbus_bug735437_client.vala, do not modify */ + +#include <glib-object.h> +#include <gio/gio.h> +#include <glib.h> +#include <float.h> +#include <math.h> +#include <stdlib.h> +#include <string.h> + +#if !defined(VALA_EXTERN) +#if defined(_MSC_VER) +#define VALA_EXTERN __declspec(dllexport) extern +#elif __GNUC__ >= 4 +#define VALA_EXTERN __attribute__((visibility("default"))) extern +#else +#define VALA_EXTERN extern +#endif +#endif + +#define TYPE_TEST (test_get_type ()) +#define TEST(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TYPE_TEST, Test)) +#define IS_TEST(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TYPE_TEST)) +#define TEST_GET_INTERFACE(obj) (G_TYPE_INSTANCE_GET_INTERFACE ((obj), TYPE_TEST, TestIface)) + +typedef struct _Test Test; +typedef struct _TestIface TestIface; + +#define TYPE_TEST_PROXY (test_proxy_get_type ()) +typedef GDBusProxy TestProxy; +typedef GDBusProxyClass TestProxyClass; +#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL))) +#define _vala_assert(expr, msg) if G_LIKELY (expr) ; else g_assertion_message_expr (G_LOG_DOMAIN, __FILE__, __LINE__, G_STRFUNC, msg); +#define _vala_return_if_fail(expr, msg) if G_LIKELY (expr) ; else { g_return_if_fail_warning (G_LOG_DOMAIN, G_STRFUNC, msg); return; } +#define _vala_return_val_if_fail(expr, msg, val) if G_LIKELY (expr) ; else { g_return_if_fail_warning (G_LOG_DOMAIN, G_STRFUNC, msg); return val; } +#define _vala_warn_if_fail(expr, msg) if G_LIKELY (expr) ; else g_warn_message (G_LOG_DOMAIN, __FILE__, __LINE__, G_STRFUNC, msg); + +struct _TestIface { + GTypeInterface parent_iface; + gdouble* (*array) (Test* self, gint* result_length1, GError** error); + gdouble* (*multi_array) (Test* self, gint* result_length1, gint* result_length2, GError** error); + gchar** (*multi_array2) (Test* self, gint* result_length1, gint* result_length2, gint* result_length3, GError** error); +}; + +VALA_EXTERN GType test_proxy_get_type (void) G_GNUC_CONST ; +VALA_EXTERN guint test_register_object (void* object, + GDBusConnection* connection, + const gchar* path, + GError** error); +VALA_EXTERN GType test_get_type (void) G_GNUC_CONST ; +VALA_EXTERN gdouble* test_array (Test* self, + gint* result_length1, + GError** error); +VALA_EXTERN gdouble* test_multi_array (Test* self, + gint* result_length1, + gint* result_length2, + GError** error); +VALA_EXTERN gchar** test_multi_array2 (Test* self, + gint* result_length1, + gint* result_length2, + gint* result_length3, + GError** error); +static GType test_get_type_once (void); +static void test_proxy_g_signal (GDBusProxy* proxy, + const gchar* sender_name, + const gchar* signal_name, + GVariant* parameters); +static gdouble* test_proxy_array (Test* self, + gint* result_length1, + GError** error); +static gdouble* test_proxy_multi_array (Test* self, + gint* result_length1, + gint* result_length2, + GError** error); +static gchar** test_proxy_multi_array2 (Test* self, + gint* result_length1, + gint* result_length2, + gint* result_length3, + GError** error); +static void test_proxy_test_interface_init (TestIface* iface); +static void _dbus_test_array (Test* self, + GVariant* _parameters_, + GDBusMethodInvocation* invocation); +static void _dbus_test_multi_array (Test* self, + GVariant* _parameters_, + GDBusMethodInvocation* invocation); +static void _dbus_test_multi_array2 (Test* self, + GVariant* _parameters_, + GDBusMethodInvocation* invocation); +static void test_dbus_interface_method_call (GDBusConnection* connection, + const gchar* sender, + const gchar* object_path, + const gchar* interface_name, + const gchar* method_name, + GVariant* parameters, + GDBusMethodInvocation* invocation, + gpointer user_data); +static GVariant* test_dbus_interface_get_property (GDBusConnection* connection, + const gchar* sender, + const gchar* object_path, + const gchar* interface_name, + const gchar* property_name, + GError** error, + gpointer user_data); +static gboolean test_dbus_interface_set_property (GDBusConnection* connection, + const gchar* sender, + const gchar* object_path, + const gchar* interface_name, + const gchar* property_name, + GVariant* value, + GError** error, + gpointer user_data); +static void _test_unregister_object (gpointer user_data); +static void _vala_main (void); +static void _vala_array_destroy (gpointer array, + gssize array_length, + GDestroyNotify destroy_func); +static void _vala_array_free (gpointer array, + gssize array_length, + GDestroyNotify destroy_func); + +static const GDBusArgInfo _test_dbus_arg_info_array_result = {-1, "result", "ad", NULL}; +static const GDBusArgInfo * const _test_dbus_arg_info_array_in[] = {NULL}; +static const GDBusArgInfo * const _test_dbus_arg_info_array_out[] = {&_test_dbus_arg_info_array_result, NULL}; +static const GDBusMethodInfo _test_dbus_method_info_array = {-1, "Array", (GDBusArgInfo **) (&_test_dbus_arg_info_array_in), (GDBusArgInfo **) (&_test_dbus_arg_info_array_out), NULL}; +static const GDBusArgInfo _test_dbus_arg_info_multi_array_result = {-1, "result", "aad", NULL}; +static const GDBusArgInfo * const _test_dbus_arg_info_multi_array_in[] = {NULL}; +static const GDBusArgInfo * const _test_dbus_arg_info_multi_array_out[] = {&_test_dbus_arg_info_multi_array_result, NULL}; +static const GDBusMethodInfo _test_dbus_method_info_multi_array = {-1, "MultiArray", (GDBusArgInfo **) (&_test_dbus_arg_info_multi_array_in), (GDBusArgInfo **) (&_test_dbus_arg_info_multi_array_out), NULL}; +static const GDBusArgInfo _test_dbus_arg_info_multi_array2_result = {-1, "result", "aaas", NULL}; +static const GDBusArgInfo * const _test_dbus_arg_info_multi_array2_in[] = {NULL}; +static const GDBusArgInfo * const _test_dbus_arg_info_multi_array2_out[] = {&_test_dbus_arg_info_multi_array2_result, NULL}; +static const GDBusMethodInfo _test_dbus_method_info_multi_array2 = {-1, "MultiArray2", (GDBusArgInfo **) (&_test_dbus_arg_info_multi_array2_in), (GDBusArgInfo **) (&_test_dbus_arg_info_multi_array2_out), NULL}; +static const GDBusMethodInfo * const _test_dbus_method_info[] = {&_test_dbus_method_info_array, &_test_dbus_method_info_multi_array, &_test_dbus_method_info_multi_array2, NULL}; +static const GDBusSignalInfo * const _test_dbus_signal_info[] = {NULL}; +static const GDBusPropertyInfo * const _test_dbus_property_info[] = {NULL}; +static const GDBusInterfaceInfo _test_dbus_interface_info = {-1, "org.example.Test", (GDBusMethodInfo **) (&_test_dbus_method_info), (GDBusSignalInfo **) (&_test_dbus_signal_info), (GDBusPropertyInfo **) (&_test_dbus_property_info), NULL}; +static const GDBusInterfaceVTable _test_dbus_interface_vtable = {test_dbus_interface_method_call, test_dbus_interface_get_property, test_dbus_interface_set_property}; + +gdouble* +test_array (Test* self, + gint* result_length1, + GError** error) +{ + TestIface* _iface_; + g_return_val_if_fail (IS_TEST (self), NULL); + _iface_ = TEST_GET_INTERFACE (self); + if (_iface_->array) { + return _iface_->array (self, result_length1, error); + } + return NULL; +} + +gdouble* +test_multi_array (Test* self, + gint* result_length1, + gint* result_length2, + GError** error) +{ + TestIface* _iface_; + g_return_val_if_fail (IS_TEST (self), NULL); + _iface_ = TEST_GET_INTERFACE (self); + if (_iface_->multi_array) { + return _iface_->multi_array (self, result_length1, result_length2, error); + } + return NULL; +} + +gchar** +test_multi_array2 (Test* self, + gint* result_length1, + gint* result_length2, + gint* result_length3, + GError** error) +{ + TestIface* _iface_; + g_return_val_if_fail (IS_TEST (self), NULL); + _iface_ = TEST_GET_INTERFACE (self); + if (_iface_->multi_array2) { + return _iface_->multi_array2 (self, result_length1, result_length2, result_length3, error); + } + return NULL; +} + +static void +test_default_init (TestIface * iface, + gpointer iface_data) +{ +} + +static GType +test_get_type_once (void) +{ + static const GTypeInfo g_define_type_info = { sizeof (TestIface), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) test_default_init, (GClassFinalizeFunc) NULL, NULL, 0, 0, (GInstanceInitFunc) NULL, NULL }; + GType test_type_id; + test_type_id = g_type_register_static (G_TYPE_INTERFACE, "Test", &g_define_type_info, 0); + g_type_interface_add_prerequisite (test_type_id, G_TYPE_OBJECT); + g_type_set_qdata (test_type_id, g_quark_from_static_string ("vala-dbus-proxy-type"), (void*) test_proxy_get_type); + g_type_set_qdata (test_type_id, g_quark_from_static_string ("vala-dbus-interface-name"), "org.example.Test"); + g_type_set_qdata (test_type_id, g_quark_from_static_string ("vala-dbus-interface-info"), (void*) (&_test_dbus_interface_info)); + g_type_set_qdata (test_type_id, g_quark_from_static_string ("vala-dbus-register-object"), (void*) test_register_object); + return test_type_id; +} + +GType +test_get_type (void) +{ + static volatile gsize test_type_id__volatile = 0; + if (g_once_init_enter (&test_type_id__volatile)) { + GType test_type_id; + test_type_id = test_get_type_once (); + g_once_init_leave (&test_type_id__volatile, test_type_id); + } + return test_type_id__volatile; +} + +G_DEFINE_TYPE_EXTENDED (TestProxy, test_proxy, G_TYPE_DBUS_PROXY, 0, G_IMPLEMENT_INTERFACE (TYPE_TEST, test_proxy_test_interface_init) ) +static void +test_proxy_class_init (TestProxyClass* klass) +{ + G_DBUS_PROXY_CLASS (klass)->g_signal = test_proxy_g_signal; +} + +static void +test_proxy_g_signal (GDBusProxy* proxy, + const gchar* sender_name, + const gchar* signal_name, + GVariant* parameters) +{ +} + +static void +test_proxy_init (TestProxy* self) +{ + g_dbus_proxy_set_interface_info (G_DBUS_PROXY (self), (GDBusInterfaceInfo *) (&_test_dbus_interface_info)); +} + +static gdouble* +test_proxy_array (Test* self, + gint* result_length1, + GError** error) +{ + GDBusMessage *_message; + GVariant *_arguments; + GVariantBuilder _arguments_builder; + GDBusMessage *_reply_message; + GVariant *_reply; + GVariantIter _reply_iter; + gdouble* _result = NULL; + gint _result_length1; + GVariant* _tmp0_; + gdouble* _tmp1_; + gint _tmp1__length; + gint _tmp1__size; + gint _tmp1__length1; + GVariantIter _tmp2_; + GVariant* _tmp3_; + G_DBUS_ERROR; + G_IO_ERROR; + _message = g_dbus_message_new_method_call (g_dbus_proxy_get_name ((GDBusProxy *) self), g_dbus_proxy_get_object_path ((GDBusProxy *) self), "org.example.Test", "Array"); + g_variant_builder_init (&_arguments_builder, G_VARIANT_TYPE_TUPLE); + _arguments = g_variant_builder_end (&_arguments_builder); + g_dbus_message_set_body (_message, _arguments); + _reply_message = g_dbus_connection_send_message_with_reply_sync (g_dbus_proxy_get_connection ((GDBusProxy *) self), _message, G_DBUS_SEND_MESSAGE_FLAGS_NONE, g_dbus_proxy_get_default_timeout ((GDBusProxy *) self), NULL, NULL, error); + g_object_unref (_message); + if (!_reply_message) { + return NULL; + } + if (g_dbus_message_to_gerror (_reply_message, error)) { + g_object_unref (_reply_message); + return NULL; + } + _reply = g_dbus_message_get_body (_reply_message); + g_variant_iter_init (&_reply_iter, _reply); + _result_length1 = 0; + _tmp0_ = g_variant_iter_next_value (&_reply_iter); + _tmp1_ = g_new (gdouble, 5); + _tmp1__length = 0; + _tmp1__size = 4; + _tmp1__length1 = 0; + g_variant_iter_init (&_tmp2_, _tmp0_); + for (; (_tmp3_ = g_variant_iter_next_value (&_tmp2_)) != NULL; _tmp1__length1++) { + if (_tmp1__size == _tmp1__length) { + _tmp1__size = 2 * _tmp1__size; + _tmp1_ = g_renew (gdouble, _tmp1_, _tmp1__size + 1); + } + _tmp1_[_tmp1__length++] = g_variant_get_double (_tmp3_); + g_variant_unref (_tmp3_); + } + _result_length1 = _tmp1__length1; + _result = _tmp1_; + g_variant_unref (_tmp0_); + *result_length1 = _result_length1; + g_object_unref (_reply_message); + return _result; +} + +static gdouble* +test_proxy_multi_array (Test* self, + gint* result_length1, + gint* result_length2, + GError** error) +{ + GDBusMessage *_message; + GVariant *_arguments; + GVariantBuilder _arguments_builder; + GDBusMessage *_reply_message; + GVariant *_reply; + GVariantIter _reply_iter; + gdouble* _result = NULL; + gint _result_length1; + gint _result_length2; + GVariant* _tmp4_; + gdouble* _tmp5_; + gint _tmp5__length; + gint _tmp5__size; + gint _tmp5__length1; + GVariantIter _tmp6_; + GVariant* _tmp7_; + G_DBUS_ERROR; + G_IO_ERROR; + _message = g_dbus_message_new_method_call (g_dbus_proxy_get_name ((GDBusProxy *) self), g_dbus_proxy_get_object_path ((GDBusProxy *) self), "org.example.Test", "MultiArray"); + g_variant_builder_init (&_arguments_builder, G_VARIANT_TYPE_TUPLE); + _arguments = g_variant_builder_end (&_arguments_builder); + g_dbus_message_set_body (_message, _arguments); + _reply_message = g_dbus_connection_send_message_with_reply_sync (g_dbus_proxy_get_connection ((GDBusProxy *) self), _message, G_DBUS_SEND_MESSAGE_FLAGS_NONE, g_dbus_proxy_get_default_timeout ((GDBusProxy *) self), NULL, NULL, error); + g_object_unref (_message); + if (!_reply_message) { + return NULL; + } + if (g_dbus_message_to_gerror (_reply_message, error)) { + g_object_unref (_reply_message); + return NULL; + } + _reply = g_dbus_message_get_body (_reply_message); + g_variant_iter_init (&_reply_iter, _reply); + _result_length1 = 0; + _result_length2 = 0; + _tmp4_ = g_variant_iter_next_value (&_reply_iter); + _tmp5_ = g_new (gdouble, 5); + _tmp5__length = 0; + _tmp5__size = 4; + _tmp5__length1 = 0; + g_variant_iter_init (&_tmp6_, _tmp4_); + for (; (_tmp7_ = g_variant_iter_next_value (&_tmp6_)) != NULL; _tmp5__length1++) { + gint _tmp5__length2; + GVariantIter _tmp8_; + GVariant* _tmp9_; + _tmp5__length2 = 0; + g_variant_iter_init (&_tmp8_, _tmp7_); + for (; (_tmp9_ = g_variant_iter_next_value (&_tmp8_)) != NULL; _tmp5__length2++) { + if (_tmp5__size == _tmp5__length) { + _tmp5__size = 2 * _tmp5__size; + _tmp5_ = g_renew (gdouble, _tmp5_, _tmp5__size + 1); + } + _tmp5_[_tmp5__length++] = g_variant_get_double (_tmp9_); + g_variant_unref (_tmp9_); + } + _result_length2 = _tmp5__length2; + g_variant_unref (_tmp7_); + } + _result_length1 = _tmp5__length1; + _result = _tmp5_; + g_variant_unref (_tmp4_); + *result_length1 = _result_length1; + *result_length2 = _result_length2; + g_object_unref (_reply_message); + return _result; +} + +static gchar** +test_proxy_multi_array2 (Test* self, + gint* result_length1, + gint* result_length2, + gint* result_length3, + GError** error) +{ + GDBusMessage *_message; + GVariant *_arguments; + GVariantBuilder _arguments_builder; + GDBusMessage *_reply_message; + GVariant *_reply; + GVariantIter _reply_iter; + gchar** _result = NULL; + gint _result_length1; + gint _result_length2; + gint _result_length3; + GVariant* _tmp10_; + gchar** _tmp11_; + gint _tmp11__length; + gint _tmp11__size; + gint _tmp11__length1; + GVariantIter _tmp12_; + GVariant* _tmp13_; + G_DBUS_ERROR; + G_IO_ERROR; + _message = g_dbus_message_new_method_call (g_dbus_proxy_get_name ((GDBusProxy *) self), g_dbus_proxy_get_object_path ((GDBusProxy *) self), "org.example.Test", "MultiArray2"); + g_variant_builder_init (&_arguments_builder, G_VARIANT_TYPE_TUPLE); + _arguments = g_variant_builder_end (&_arguments_builder); + g_dbus_message_set_body (_message, _arguments); + _reply_message = g_dbus_connection_send_message_with_reply_sync (g_dbus_proxy_get_connection ((GDBusProxy *) self), _message, G_DBUS_SEND_MESSAGE_FLAGS_NONE, g_dbus_proxy_get_default_timeout ((GDBusProxy *) self), NULL, NULL, error); + g_object_unref (_message); + if (!_reply_message) { + return NULL; + } + if (g_dbus_message_to_gerror (_reply_message, error)) { + g_object_unref (_reply_message); + return NULL; + } + _reply = g_dbus_message_get_body (_reply_message); + g_variant_iter_init (&_reply_iter, _reply); + _result_length1 = 0; + _result_length2 = 0; + _result_length3 = 0; + _tmp10_ = g_variant_iter_next_value (&_reply_iter); + _tmp11_ = g_new (gchar*, 5); + _tmp11__length = 0; + _tmp11__size = 4; + _tmp11__length1 = 0; + g_variant_iter_init (&_tmp12_, _tmp10_); + for (; (_tmp13_ = g_variant_iter_next_value (&_tmp12_)) != NULL; _tmp11__length1++) { + gint _tmp11__length2; + GVariantIter _tmp14_; + GVariant* _tmp15_; + _tmp11__length2 = 0; + g_variant_iter_init (&_tmp14_, _tmp13_); + for (; (_tmp15_ = g_variant_iter_next_value (&_tmp14_)) != NULL; _tmp11__length2++) { + gint _tmp11__length3; + GVariantIter _tmp16_; + GVariant* _tmp17_; + _tmp11__length3 = 0; + g_variant_iter_init (&_tmp16_, _tmp15_); + for (; (_tmp17_ = g_variant_iter_next_value (&_tmp16_)) != NULL; _tmp11__length3++) { + if (_tmp11__size == _tmp11__length) { + _tmp11__size = 2 * _tmp11__size; + _tmp11_ = g_renew (gchar*, _tmp11_, _tmp11__size + 1); + } + _tmp11_[_tmp11__length++] = g_variant_dup_string (_tmp17_, NULL); + g_variant_unref (_tmp17_); + } + _result_length3 = _tmp11__length3; + g_variant_unref (_tmp15_); + } + _result_length2 = _tmp11__length2; + g_variant_unref (_tmp13_); + } + _result_length1 = _tmp11__length1; + _tmp11_[_tmp11__length] = NULL; + _result = _tmp11_; + g_variant_unref (_tmp10_); + *result_length1 = _result_length1; + *result_length2 = _result_length2; + *result_length3 = _result_length3; + g_object_unref (_reply_message); + return _result; +} + +static void +test_proxy_test_interface_init (TestIface* iface) +{ + iface->array = test_proxy_array; + iface->multi_array = test_proxy_multi_array; + iface->multi_array2 = test_proxy_multi_array2; +} + +static void +_dbus_test_array (Test* self, + GVariant* _parameters_, + GDBusMethodInvocation* invocation) +{ + GError* error = NULL; + GVariantIter _arguments_iter; + GDBusMessage* _reply_message = NULL; + GVariant* _reply; + GVariantBuilder _reply_builder; + gdouble* result; + gint result_length1 = 0; + gdouble* _tmp18_; + GVariantBuilder _tmp19_; + gint _tmp20_; + g_variant_iter_init (&_arguments_iter, _parameters_); + result = test_array (self, &result_length1, &error); + if (error) { + g_dbus_method_invocation_return_gerror (invocation, error); + g_error_free (error); + return; + } + _reply_message = g_dbus_message_new_method_reply (g_dbus_method_invocation_get_message (invocation)); + g_variant_builder_init (&_reply_builder, G_VARIANT_TYPE_TUPLE); + _tmp18_ = result; + g_variant_builder_init (&_tmp19_, G_VARIANT_TYPE ("ad")); + for (_tmp20_ = 0; _tmp20_ < result_length1; _tmp20_++) { + g_variant_builder_add_value (&_tmp19_, g_variant_new_double (*_tmp18_)); + _tmp18_++; + } + g_variant_builder_add_value (&_reply_builder, g_variant_builder_end (&_tmp19_)); + result = (g_free (result), NULL); + _reply = g_variant_builder_end (&_reply_builder); + g_dbus_message_set_body (_reply_message, _reply); + g_dbus_connection_send_message (g_dbus_method_invocation_get_connection (invocation), _reply_message, G_DBUS_SEND_MESSAGE_FLAGS_NONE, NULL, NULL); + g_object_unref (invocation); + g_object_unref (_reply_message); +} + +static void +_dbus_test_multi_array (Test* self, + GVariant* _parameters_, + GDBusMethodInvocation* invocation) +{ + GError* error = NULL; + GVariantIter _arguments_iter; + GDBusMessage* _reply_message = NULL; + GVariant* _reply; + GVariantBuilder _reply_builder; + gdouble* result; + gint result_length1 = 0; + gint result_length2 = 0; + gdouble* _tmp21_; + GVariantBuilder _tmp22_; + gint _tmp23_; + g_variant_iter_init (&_arguments_iter, _parameters_); + result = test_multi_array (self, &result_length1, &result_length2, &error); + if (error) { + g_dbus_method_invocation_return_gerror (invocation, error); + g_error_free (error); + return; + } + _reply_message = g_dbus_message_new_method_reply (g_dbus_method_invocation_get_message (invocation)); + g_variant_builder_init (&_reply_builder, G_VARIANT_TYPE_TUPLE); + _tmp21_ = result; + g_variant_builder_init (&_tmp22_, G_VARIANT_TYPE ("aad")); + for (_tmp23_ = 0; _tmp23_ < result_length1; _tmp23_++) { + GVariantBuilder _tmp24_; + gint _tmp25_; + g_variant_builder_init (&_tmp24_, G_VARIANT_TYPE ("ad")); + for (_tmp25_ = 0; _tmp25_ < result_length2; _tmp25_++) { + g_variant_builder_add_value (&_tmp24_, g_variant_new_double (*_tmp21_)); + _tmp21_++; + } + g_variant_builder_add_value (&_tmp22_, g_variant_builder_end (&_tmp24_)); + } + g_variant_builder_add_value (&_reply_builder, g_variant_builder_end (&_tmp22_)); + result = (g_free (result), NULL); + _reply = g_variant_builder_end (&_reply_builder); + g_dbus_message_set_body (_reply_message, _reply); + g_dbus_connection_send_message (g_dbus_method_invocation_get_connection (invocation), _reply_message, G_DBUS_SEND_MESSAGE_FLAGS_NONE, NULL, NULL); + g_object_unref (invocation); + g_object_unref (_reply_message); +} + +static void +_dbus_test_multi_array2 (Test* self, + GVariant* _parameters_, + GDBusMethodInvocation* invocation) +{ + GError* error = NULL; + GVariantIter _arguments_iter; + GDBusMessage* _reply_message = NULL; + GVariant* _reply; + GVariantBuilder _reply_builder; + gchar** result; + gint result_length1 = 0; + gint result_length2 = 0; + gint result_length3 = 0; + gchar** _tmp26_; + GVariantBuilder _tmp27_; + gint _tmp28_; + g_variant_iter_init (&_arguments_iter, _parameters_); + result = test_multi_array2 (self, &result_length1, &result_length2, &result_length3, &error); + if (error) { + g_dbus_method_invocation_return_gerror (invocation, error); + g_error_free (error); + return; + } + _reply_message = g_dbus_message_new_method_reply (g_dbus_method_invocation_get_message (invocation)); + g_variant_builder_init (&_reply_builder, G_VARIANT_TYPE_TUPLE); + _tmp26_ = result; + g_variant_builder_init (&_tmp27_, G_VARIANT_TYPE ("aaas")); + for (_tmp28_ = 0; _tmp28_ < result_length1; _tmp28_++) { + GVariantBuilder _tmp29_; + gint _tmp30_; + g_variant_builder_init (&_tmp29_, G_VARIANT_TYPE ("aas")); + for (_tmp30_ = 0; _tmp30_ < result_length2; _tmp30_++) { + GVariantBuilder _tmp31_; + gint _tmp32_; + g_variant_builder_init (&_tmp31_, G_VARIANT_TYPE ("as")); + for (_tmp32_ = 0; _tmp32_ < result_length3; _tmp32_++) { + g_variant_builder_add_value (&_tmp31_, g_variant_new_string (*_tmp26_)); + _tmp26_++; + } + g_variant_builder_add_value (&_tmp29_, g_variant_builder_end (&_tmp31_)); + } + g_variant_builder_add_value (&_tmp27_, g_variant_builder_end (&_tmp29_)); + } + g_variant_builder_add_value (&_reply_builder, g_variant_builder_end (&_tmp27_)); + result = (_vala_array_free (result, (result_length1 * result_length2) * result_length3, (GDestroyNotify) g_free), NULL); + _reply = g_variant_builder_end (&_reply_builder); + g_dbus_message_set_body (_reply_message, _reply); + g_dbus_connection_send_message (g_dbus_method_invocation_get_connection (invocation), _reply_message, G_DBUS_SEND_MESSAGE_FLAGS_NONE, NULL, NULL); + g_object_unref (invocation); + g_object_unref (_reply_message); +} + +static void +test_dbus_interface_method_call (GDBusConnection* connection, + const gchar* sender, + const gchar* object_path, + const gchar* interface_name, + const gchar* method_name, + GVariant* parameters, + GDBusMethodInvocation* invocation, + gpointer user_data) +{ + gpointer* data; + gpointer object; + data = user_data; + object = data[0]; + if (strcmp (method_name, "Array") == 0) { + _dbus_test_array (object, parameters, invocation); + } else if (strcmp (method_name, "MultiArray") == 0) { + _dbus_test_multi_array (object, parameters, invocation); + } else if (strcmp (method_name, "MultiArray2") == 0) { + _dbus_test_multi_array2 (object, parameters, invocation); + } else { + g_object_unref (invocation); + } +} + +static GVariant* +test_dbus_interface_get_property (GDBusConnection* connection, + const gchar* sender, + const gchar* object_path, + const gchar* interface_name, + const gchar* property_name, + GError** error, + gpointer user_data) +{ + gpointer* data; + gpointer object; + data = user_data; + object = data[0]; + return NULL; +} + +static gboolean +test_dbus_interface_set_property (GDBusConnection* connection, + const gchar* sender, + const gchar* object_path, + const gchar* interface_name, + const gchar* property_name, + GVariant* value, + GError** error, + gpointer user_data) +{ + gpointer* data; + gpointer object; + data = user_data; + object = data[0]; + return FALSE; +} + +guint +test_register_object (gpointer object, + GDBusConnection* connection, + const gchar* path, + GError** error) +{ + guint result; + gpointer *data; + data = g_new (gpointer, 3); + data[0] = g_object_ref (object); + data[1] = g_object_ref (connection); + data[2] = g_strdup (path); + result = g_dbus_connection_register_object (connection, path, (GDBusInterfaceInfo *) (&_test_dbus_interface_info), &_test_dbus_interface_vtable, data, _test_unregister_object, error); + if (!result) { + return 0; + } + return result; +} + +static void +_test_unregister_object (gpointer user_data) +{ + gpointer* data; + data = user_data; + g_object_unref (data[0]); + g_object_unref (data[1]); + g_free (data[2]); + g_free (data); +} + +static void +_vala_main (void) +{ + Test* test = NULL; + Test* _tmp0_; + gdouble* a = NULL; + Test* _tmp1_; + gint _tmp2_ = 0; + gdouble* _tmp3_; + gint a_length1; + gint _a_size_; + gboolean _tmp4_ = FALSE; + gboolean _tmp5_ = FALSE; + gdouble* _tmp6_; + gint _tmp6__length1; + gdouble* b = NULL; + Test* _tmp11_; + gint _tmp12_ = 0; + gint _tmp13_ = 0; + gdouble* _tmp14_; + gint b_length1; + gint b_length2; + gboolean _tmp15_ = FALSE; + gboolean _tmp16_ = FALSE; + gboolean _tmp17_ = FALSE; + gboolean _tmp18_ = FALSE; + gboolean _tmp19_ = FALSE; + gdouble* _tmp20_; + gint _tmp20__length1; + gint _tmp20__length2; + gint _tmp21_; + gchar** c = NULL; + Test* _tmp32_; + gint _tmp33_ = 0; + gint _tmp34_ = 0; + gint _tmp35_ = 0; + gchar** _tmp36_; + gint c_length1; + gint c_length2; + gint c_length3; + gboolean _tmp37_ = FALSE; + gboolean _tmp38_ = FALSE; + gboolean _tmp39_ = FALSE; + gboolean _tmp40_ = FALSE; + gboolean _tmp41_ = FALSE; + gboolean _tmp42_ = FALSE; + gchar** _tmp43_; + gint _tmp43__length1; + gint _tmp43__length2; + gint _tmp43__length3; + gint _tmp44_; + GError* _inner_error0_ = NULL; + _tmp0_ = (Test*) g_initable_new (TYPE_TEST_PROXY, NULL, &_inner_error0_, "g-flags", 0, "g-name", "org.example.Test", "g-bus-type", G_BUS_TYPE_SESSION, "g-object-path", "/org/example/test", "g-interface-name", "org.example.Test", NULL); + test = (Test*) _tmp0_; + if (G_UNLIKELY (_inner_error0_ != NULL)) { + g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error0_->message, g_quark_to_string (_inner_error0_->domain), _inner_error0_->code); + g_clear_error (&_inner_error0_); + return; + } + _tmp1_ = test; + _tmp3_ = test_array (_tmp1_, &_tmp2_, &_inner_error0_); + a = _tmp3_; + a_length1 = _tmp2_; + _a_size_ = a_length1; + if (G_UNLIKELY (_inner_error0_ != NULL)) { + _g_object_unref0 (test); + g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error0_->message, g_quark_to_string (_inner_error0_->domain), _inner_error0_->code); + g_clear_error (&_inner_error0_); + return; + } + _tmp6_ = a; + _tmp6__length1 = a_length1; + if (_tmp6__length1 == 2) { + gdouble* _tmp7_; + gint _tmp7__length1; + gdouble _tmp8_; + _tmp7_ = a; + _tmp7__length1 = a_length1; + _tmp8_ = _tmp7_[0]; + _tmp5_ = _tmp8_ == 2.0; + } else { + _tmp5_ = FALSE; + } + if (_tmp5_) { + gdouble* _tmp9_; + gint _tmp9__length1; + gdouble _tmp10_; + _tmp9_ = a; + _tmp9__length1 = a_length1; + _tmp10_ = _tmp9_[1]; + _tmp4_ = _tmp10_ == 3.0; + } else { + _tmp4_ = FALSE; + } + _vala_assert (_tmp4_, "a.length == 2 && a[0] == 2.0 && a[1] == 3.0"); + _tmp11_ = test; + _tmp14_ = test_multi_array (_tmp11_, &_tmp12_, &_tmp13_, &_inner_error0_); + b = _tmp14_; + b_length1 = _tmp12_; + b_length2 = _tmp13_; + if (G_UNLIKELY (_inner_error0_ != NULL)) { + a = (g_free (a), NULL); + _g_object_unref0 (test); + g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error0_->message, g_quark_to_string (_inner_error0_->domain), _inner_error0_->code); + g_clear_error (&_inner_error0_); + return; + } + _tmp20_ = b; + _tmp20__length1 = b_length1; + _tmp20__length2 = b_length2; + _tmp21_ = _tmp20__length1; + if (_tmp21_ == 2) { + gdouble* _tmp22_; + gint _tmp22__length1; + gint _tmp22__length2; + gint _tmp23_; + _tmp22_ = b; + _tmp22__length1 = b_length1; + _tmp22__length2 = b_length2; + _tmp23_ = _tmp22__length2; + _tmp19_ = _tmp23_ == 2; + } else { + _tmp19_ = FALSE; + } + if (_tmp19_) { + gdouble* _tmp24_; + gint _tmp24__length1; + gint _tmp24__length2; + gdouble _tmp25_; + _tmp24_ = b; + _tmp24__length1 = b_length1; + _tmp24__length2 = b_length2; + _tmp25_ = _tmp24_[(0 * _tmp24__length2) + 0]; + _tmp18_ = _tmp25_ == 2.0; + } else { + _tmp18_ = FALSE; + } + if (_tmp18_) { + gdouble* _tmp26_; + gint _tmp26__length1; + gint _tmp26__length2; + gdouble _tmp27_; + _tmp26_ = b; + _tmp26__length1 = b_length1; + _tmp26__length2 = b_length2; + _tmp27_ = _tmp26_[(0 * _tmp26__length2) + 1]; + _tmp17_ = _tmp27_ == 3.0; + } else { + _tmp17_ = FALSE; + } + if (_tmp17_) { + gdouble* _tmp28_; + gint _tmp28__length1; + gint _tmp28__length2; + gdouble _tmp29_; + _tmp28_ = b; + _tmp28__length1 = b_length1; + _tmp28__length2 = b_length2; + _tmp29_ = _tmp28_[(1 * _tmp28__length2) + 0]; + _tmp16_ = _tmp29_ == 4.0; + } else { + _tmp16_ = FALSE; + } + if (_tmp16_) { + gdouble* _tmp30_; + gint _tmp30__length1; + gint _tmp30__length2; + gdouble _tmp31_; + _tmp30_ = b; + _tmp30__length1 = b_length1; + _tmp30__length2 = b_length2; + _tmp31_ = _tmp30_[(1 * _tmp30__length2) + 1]; + _tmp15_ = _tmp31_ == 5.0; + } else { + _tmp15_ = FALSE; + } + _vala_assert (_tmp15_, "b.length[0] == 2 && b.length[1] == 2 && b[0,0] == 2.0 && b[0,1] == 3.0 && b[1,0] == 4.0 && b[1,1] == 5.0"); + _tmp32_ = test; + _tmp36_ = test_multi_array2 (_tmp32_, &_tmp33_, &_tmp34_, &_tmp35_, &_inner_error0_); + c = _tmp36_; + c_length1 = _tmp33_; + c_length2 = _tmp34_; + c_length3 = _tmp35_; + if (G_UNLIKELY (_inner_error0_ != NULL)) { + b = (g_free (b), NULL); + a = (g_free (a), NULL); + _g_object_unref0 (test); + g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error0_->message, g_quark_to_string (_inner_error0_->domain), _inner_error0_->code); + g_clear_error (&_inner_error0_); + return; + } + _tmp43_ = c; + _tmp43__length1 = c_length1; + _tmp43__length2 = c_length2; + _tmp43__length3 = c_length3; + _tmp44_ = _tmp43__length1; + if (_tmp44_ == 2) { + gchar** _tmp45_; + gint _tmp45__length1; + gint _tmp45__length2; + gint _tmp45__length3; + gint _tmp46_; + _tmp45_ = c; + _tmp45__length1 = c_length1; + _tmp45__length2 = c_length2; + _tmp45__length3 = c_length3; + _tmp46_ = _tmp45__length2; + _tmp42_ = _tmp46_ == 2; + } else { + _tmp42_ = FALSE; + } + if (_tmp42_) { + gchar** _tmp47_; + gint _tmp47__length1; + gint _tmp47__length2; + gint _tmp47__length3; + gint _tmp48_; + _tmp47_ = c; + _tmp47__length1 = c_length1; + _tmp47__length2 = c_length2; + _tmp47__length3 = c_length3; + _tmp48_ = _tmp47__length3; + _tmp41_ = _tmp48_ == 2; + } else { + _tmp41_ = FALSE; + } + if (_tmp41_) { + gchar** _tmp49_; + gint _tmp49__length1; + gint _tmp49__length2; + gint _tmp49__length3; + const gchar* _tmp50_; + _tmp49_ = c; + _tmp49__length1 = c_length1; + _tmp49__length2 = c_length2; + _tmp49__length3 = c_length3; + _tmp50_ = _tmp49_[(((0 * _tmp49__length2) + 0) * _tmp49__length3) + 0]; + _tmp40_ = g_strcmp0 (_tmp50_, "foo") == 0; + } else { + _tmp40_ = FALSE; + } + if (_tmp40_) { + gchar** _tmp51_; + gint _tmp51__length1; + gint _tmp51__length2; + gint _tmp51__length3; + const gchar* _tmp52_; + _tmp51_ = c; + _tmp51__length1 = c_length1; + _tmp51__length2 = c_length2; + _tmp51__length3 = c_length3; + _tmp52_ = _tmp51_[(((0 * _tmp51__length2) + 0) * _tmp51__length3) + 1]; + _tmp39_ = g_strcmp0 (_tmp52_, "bar") == 0; + } else { + _tmp39_ = FALSE; + } + if (_tmp39_) { + gchar** _tmp53_; + gint _tmp53__length1; + gint _tmp53__length2; + gint _tmp53__length3; + const gchar* _tmp54_; + _tmp53_ = c; + _tmp53__length1 = c_length1; + _tmp53__length2 = c_length2; + _tmp53__length3 = c_length3; + _tmp54_ = _tmp53_[(((1 * _tmp53__length2) + 1) * _tmp53__length3) + 0]; + _tmp38_ = g_strcmp0 (_tmp54_, "baz2") == 0; + } else { + _tmp38_ = FALSE; + } + if (_tmp38_) { + gchar** _tmp55_; + gint _tmp55__length1; + gint _tmp55__length2; + gint _tmp55__length3; + const gchar* _tmp56_; + _tmp55_ = c; + _tmp55__length1 = c_length1; + _tmp55__length2 = c_length2; + _tmp55__length3 = c_length3; + _tmp56_ = _tmp55_[(((1 * _tmp55__length2) + 1) * _tmp55__length3) + 1]; + _tmp37_ = g_strcmp0 (_tmp56_, "man2") == 0; + } else { + _tmp37_ = FALSE; + } + _vala_assert (_tmp37_, "c.length[0] == 2 && c.length[1] == 2 && c.length[2] == 2 && c[0,0,0] == \"foo\" && c[0,0,1] == \"bar\" && c[1,1,0] == \"baz2\" && c[1,1,1] == \"man2\""); + c = (_vala_array_free (c, (c_length1 * c_length2) * c_length3, (GDestroyNotify) g_free), NULL); + b = (g_free (b), NULL); + a = (g_free (a), NULL); + _g_object_unref0 (test); +} + +int +main (int argc, + char ** argv) +{ + _vala_main (); + return 0; +} + +static void +_vala_array_destroy (gpointer array, + gssize array_length, + GDestroyNotify destroy_func) +{ + if ((array != NULL) && (destroy_func != NULL)) { + gssize i; + for (i = 0; i < array_length; i = i + 1) { + if (((gpointer*) array)[i] != NULL) { + destroy_func (((gpointer*) array)[i]); + } + } + } +} + +static void +_vala_array_free (gpointer array, + gssize array_length, + GDestroyNotify destroy_func) +{ + _vala_array_destroy (array, array_length, destroy_func); + g_free (array); +} + diff --git a/tests/dbus/bug735437_server.c-expected b/tests/dbus/bug735437_server.c-expected new file mode 100644 index 000000000..536be463a --- /dev/null +++ b/tests/dbus/bug735437_server.c-expected @@ -0,0 +1,651 @@ +/* dbus_bug735437_server.c generated by valac, the Vala compiler + * generated from dbus_bug735437_server.vala, do not modify */ + +#include <glib-object.h> +#include <gio/gio.h> +#include <glib.h> +#include <float.h> +#include <math.h> +#include <stdlib.h> +#include <string.h> + +#if !defined(VALA_EXTERN) +#if defined(_MSC_VER) +#define VALA_EXTERN __declspec(dllexport) extern +#elif __GNUC__ >= 4 +#define VALA_EXTERN __attribute__((visibility("default"))) extern +#else +#define VALA_EXTERN extern +#endif +#endif + +#define TYPE_TEST (test_get_type ()) +#define TEST(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TYPE_TEST, Test)) +#define TEST_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), TYPE_TEST, TestClass)) +#define IS_TEST(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TYPE_TEST)) +#define IS_TEST_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), TYPE_TEST)) +#define TEST_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), TYPE_TEST, TestClass)) + +typedef struct _Test Test; +typedef struct _TestClass TestClass; +typedef struct _TestPrivate TestPrivate; +enum { + TEST_0_PROPERTY, + TEST_NUM_PROPERTIES +}; +static GParamSpec* test_properties[TEST_NUM_PROPERTIES]; +#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL))) +#define _g_variant_unref0(var) ((var == NULL) ? NULL : (var = (g_variant_unref (var), NULL))) +#define _g_main_loop_unref0(var) ((var == NULL) ? NULL : (var = (g_main_loop_unref (var), NULL))) +#define _vala_assert(expr, msg) if G_LIKELY (expr) ; else g_assertion_message_expr (G_LOG_DOMAIN, __FILE__, __LINE__, G_STRFUNC, msg); +#define _vala_return_if_fail(expr, msg) if G_LIKELY (expr) ; else { g_return_if_fail_warning (G_LOG_DOMAIN, G_STRFUNC, msg); return; } +#define _vala_return_val_if_fail(expr, msg, val) if G_LIKELY (expr) ; else { g_return_if_fail_warning (G_LOG_DOMAIN, G_STRFUNC, msg); return val; } +#define _vala_warn_if_fail(expr, msg) if G_LIKELY (expr) ; else g_warn_message (G_LOG_DOMAIN, __FILE__, __LINE__, G_STRFUNC, msg); + +struct _Test { + GObject parent_instance; + TestPrivate * priv; +}; + +struct _TestClass { + GObjectClass parent_class; +}; + +static gpointer test_parent_class = NULL; +VALA_EXTERN GMainLoop* main_loop; +GMainLoop* main_loop = NULL; + +VALA_EXTERN GType test_get_type (void) G_GNUC_CONST ; +G_DEFINE_AUTOPTR_CLEANUP_FUNC (Test, g_object_unref) +VALA_EXTERN guint test_register_object (void* object, + GDBusConnection* connection, + const gchar* path, + GError** error); +VALA_EXTERN gdouble* test_array (Test* self, + gint* result_length1); +VALA_EXTERN gdouble* test_multi_array (Test* self, + gint* result_length1, + gint* result_length2); +VALA_EXTERN gchar** test_multi_array2 (Test* self, + gint* result_length1, + gint* result_length2, + gint* result_length3); +VALA_EXTERN Test* test_new (void); +VALA_EXTERN Test* test_construct (GType object_type); +static GType test_get_type_once (void); +static void _dbus_test_array (Test* self, + GVariant* _parameters_, + GDBusMethodInvocation* invocation); +static void _dbus_test_multi_array (Test* self, + GVariant* _parameters_, + GDBusMethodInvocation* invocation); +static void _dbus_test_multi_array2 (Test* self, + GVariant* _parameters_, + GDBusMethodInvocation* invocation); +static void test_dbus_interface_method_call (GDBusConnection* connection, + const gchar* sender, + const gchar* object_path, + const gchar* interface_name, + const gchar* method_name, + GVariant* parameters, + GDBusMethodInvocation* invocation, + gpointer user_data); +static GVariant* test_dbus_interface_get_property (GDBusConnection* connection, + const gchar* sender, + const gchar* object_path, + const gchar* interface_name, + const gchar* property_name, + GError** error, + gpointer user_data); +static gboolean test_dbus_interface_set_property (GDBusConnection* connection, + const gchar* sender, + const gchar* object_path, + const gchar* interface_name, + const gchar* property_name, + GVariant* value, + GError** error, + gpointer user_data); +static void _test_unregister_object (gpointer user_data); +VALA_EXTERN void client_exit (GPid pid, + gint status); +static void _vala_main (void); +static guint _variant_get1 (GVariant* value); +static void _client_exit_gchild_watch_func (GPid pid, + gint wait_status, + gpointer self); +static void _vala_array_destroy (gpointer array, + gssize array_length, + GDestroyNotify destroy_func); +static void _vala_array_free (gpointer array, + gssize array_length, + GDestroyNotify destroy_func); + +static const GDBusArgInfo _test_dbus_arg_info_array_result = {-1, "result", "ad", NULL}; +static const GDBusArgInfo * const _test_dbus_arg_info_array_in[] = {NULL}; +static const GDBusArgInfo * const _test_dbus_arg_info_array_out[] = {&_test_dbus_arg_info_array_result, NULL}; +static const GDBusMethodInfo _test_dbus_method_info_array = {-1, "Array", (GDBusArgInfo **) (&_test_dbus_arg_info_array_in), (GDBusArgInfo **) (&_test_dbus_arg_info_array_out), NULL}; +static const GDBusArgInfo _test_dbus_arg_info_multi_array_result = {-1, "result", "aad", NULL}; +static const GDBusArgInfo * const _test_dbus_arg_info_multi_array_in[] = {NULL}; +static const GDBusArgInfo * const _test_dbus_arg_info_multi_array_out[] = {&_test_dbus_arg_info_multi_array_result, NULL}; +static const GDBusMethodInfo _test_dbus_method_info_multi_array = {-1, "MultiArray", (GDBusArgInfo **) (&_test_dbus_arg_info_multi_array_in), (GDBusArgInfo **) (&_test_dbus_arg_info_multi_array_out), NULL}; +static const GDBusArgInfo _test_dbus_arg_info_multi_array2_result = {-1, "result", "aaas", NULL}; +static const GDBusArgInfo * const _test_dbus_arg_info_multi_array2_in[] = {NULL}; +static const GDBusArgInfo * const _test_dbus_arg_info_multi_array2_out[] = {&_test_dbus_arg_info_multi_array2_result, NULL}; +static const GDBusMethodInfo _test_dbus_method_info_multi_array2 = {-1, "MultiArray2", (GDBusArgInfo **) (&_test_dbus_arg_info_multi_array2_in), (GDBusArgInfo **) (&_test_dbus_arg_info_multi_array2_out), NULL}; +static const GDBusMethodInfo * const _test_dbus_method_info[] = {&_test_dbus_method_info_array, &_test_dbus_method_info_multi_array, &_test_dbus_method_info_multi_array2, NULL}; +static const GDBusSignalInfo * const _test_dbus_signal_info[] = {NULL}; +static const GDBusPropertyInfo * const _test_dbus_property_info[] = {NULL}; +static const GDBusInterfaceInfo _test_dbus_interface_info = {-1, "org.example.Test", (GDBusMethodInfo **) (&_test_dbus_method_info), (GDBusSignalInfo **) (&_test_dbus_signal_info), (GDBusPropertyInfo **) (&_test_dbus_property_info), NULL}; +static const GDBusInterfaceVTable _test_dbus_interface_vtable = {test_dbus_interface_method_call, test_dbus_interface_get_property, test_dbus_interface_set_property}; + +gdouble* +test_array (Test* self, + gint* result_length1) +{ + gdouble* _tmp0_; + gdouble* _tmp1_; + gint _tmp1__length1; + gdouble* result = NULL; + g_return_val_if_fail (IS_TEST (self), NULL); + _tmp0_ = g_new0 (gdouble, 2); + _tmp0_[0] = 2.0; + _tmp0_[1] = 3.0; + _tmp1_ = _tmp0_; + _tmp1__length1 = 2; + if (result_length1) { + *result_length1 = _tmp1__length1; + } + result = _tmp1_; + return result; +} + +gdouble* +test_multi_array (Test* self, + gint* result_length1, + gint* result_length2) +{ + gdouble* _tmp0_; + gdouble* _tmp1_; + gint _tmp1__length1; + gint _tmp1__length2; + gdouble* result = NULL; + g_return_val_if_fail (IS_TEST (self), NULL); + _tmp0_ = g_new0 (gdouble, 2 * 2); + _tmp0_[0] = 2.0; + _tmp0_[1] = 3.0; + _tmp0_[2] = 4.0; + _tmp0_[3] = 5.0; + _tmp1_ = _tmp0_; + _tmp1__length1 = 2; + _tmp1__length2 = 2; + if (result_length1) { + *result_length1 = _tmp1__length1; + } + if (result_length2) { + *result_length2 = _tmp1__length2; + } + result = _tmp1_; + return result; +} + +gchar** +test_multi_array2 (Test* self, + gint* result_length1, + gint* result_length2, + gint* result_length3) +{ + gchar* _tmp0_; + gchar* _tmp1_; + gchar* _tmp2_; + gchar* _tmp3_; + gchar* _tmp4_; + gchar* _tmp5_; + gchar* _tmp6_; + gchar* _tmp7_; + gchar** _tmp8_; + gchar** _tmp9_; + gint _tmp9__length1; + gint _tmp9__length2; + gint _tmp9__length3; + gchar** result = NULL; + g_return_val_if_fail (IS_TEST (self), NULL); + _tmp0_ = g_strdup ("foo"); + _tmp1_ = g_strdup ("bar"); + _tmp2_ = g_strdup ("baz"); + _tmp3_ = g_strdup ("man"); + _tmp4_ = g_strdup ("foo2"); + _tmp5_ = g_strdup ("bar2"); + _tmp6_ = g_strdup ("baz2"); + _tmp7_ = g_strdup ("man2"); + _tmp8_ = g_new0 (gchar*, ((2 * 2) * 2) + 1); + _tmp8_[0] = _tmp0_; + _tmp8_[1] = _tmp1_; + _tmp8_[2] = _tmp2_; + _tmp8_[3] = _tmp3_; + _tmp8_[4] = _tmp4_; + _tmp8_[5] = _tmp5_; + _tmp8_[6] = _tmp6_; + _tmp8_[7] = _tmp7_; + _tmp9_ = _tmp8_; + _tmp9__length1 = 2; + _tmp9__length2 = 2; + _tmp9__length3 = 2; + if (result_length1) { + *result_length1 = _tmp9__length1; + } + if (result_length2) { + *result_length2 = _tmp9__length2; + } + if (result_length3) { + *result_length3 = _tmp9__length3; + } + result = _tmp9_; + return result; +} + +Test* +test_construct (GType object_type) +{ + Test * self = NULL; + self = (Test*) g_object_new (object_type, NULL); + return self; +} + +Test* +test_new (void) +{ + return test_construct (TYPE_TEST); +} + +static void +test_class_init (TestClass * klass, + gpointer klass_data) +{ + test_parent_class = g_type_class_peek_parent (klass); +} + +static void +test_instance_init (Test * self, + gpointer klass) +{ +} + +static GType +test_get_type_once (void) +{ + static const GTypeInfo g_define_type_info = { sizeof (TestClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) test_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (Test), 0, (GInstanceInitFunc) test_instance_init, NULL }; + GType test_type_id; + test_type_id = g_type_register_static (G_TYPE_OBJECT, "Test", &g_define_type_info, 0); + g_type_set_qdata (test_type_id, g_quark_from_static_string ("vala-dbus-register-object"), (void*) test_register_object); + return test_type_id; +} + +GType +test_get_type (void) +{ + static volatile gsize test_type_id__volatile = 0; + if (g_once_init_enter (&test_type_id__volatile)) { + GType test_type_id; + test_type_id = test_get_type_once (); + g_once_init_leave (&test_type_id__volatile, test_type_id); + } + return test_type_id__volatile; +} + +static void +_dbus_test_array (Test* self, + GVariant* _parameters_, + GDBusMethodInvocation* invocation) +{ + GError* error = NULL; + GVariantIter _arguments_iter; + GDBusMessage* _reply_message = NULL; + GVariant* _reply; + GVariantBuilder _reply_builder; + gdouble* result; + gint result_length1 = 0; + gdouble* _tmp0_; + GVariantBuilder _tmp1_; + gint _tmp2_; + g_variant_iter_init (&_arguments_iter, _parameters_); + result = test_array (self, &result_length1); + _reply_message = g_dbus_message_new_method_reply (g_dbus_method_invocation_get_message (invocation)); + g_variant_builder_init (&_reply_builder, G_VARIANT_TYPE_TUPLE); + _tmp0_ = result; + g_variant_builder_init (&_tmp1_, G_VARIANT_TYPE ("ad")); + for (_tmp2_ = 0; _tmp2_ < result_length1; _tmp2_++) { + g_variant_builder_add_value (&_tmp1_, g_variant_new_double (*_tmp0_)); + _tmp0_++; + } + g_variant_builder_add_value (&_reply_builder, g_variant_builder_end (&_tmp1_)); + result = (g_free (result), NULL); + _reply = g_variant_builder_end (&_reply_builder); + g_dbus_message_set_body (_reply_message, _reply); + g_dbus_connection_send_message (g_dbus_method_invocation_get_connection (invocation), _reply_message, G_DBUS_SEND_MESSAGE_FLAGS_NONE, NULL, NULL); + g_object_unref (invocation); + g_object_unref (_reply_message); +} + +static void +_dbus_test_multi_array (Test* self, + GVariant* _parameters_, + GDBusMethodInvocation* invocation) +{ + GError* error = NULL; + GVariantIter _arguments_iter; + GDBusMessage* _reply_message = NULL; + GVariant* _reply; + GVariantBuilder _reply_builder; + gdouble* result; + gint result_length1 = 0; + gint result_length2 = 0; + gdouble* _tmp3_; + GVariantBuilder _tmp4_; + gint _tmp5_; + g_variant_iter_init (&_arguments_iter, _parameters_); + result = test_multi_array (self, &result_length1, &result_length2); + _reply_message = g_dbus_message_new_method_reply (g_dbus_method_invocation_get_message (invocation)); + g_variant_builder_init (&_reply_builder, G_VARIANT_TYPE_TUPLE); + _tmp3_ = result; + g_variant_builder_init (&_tmp4_, G_VARIANT_TYPE ("aad")); + for (_tmp5_ = 0; _tmp5_ < result_length1; _tmp5_++) { + GVariantBuilder _tmp6_; + gint _tmp7_; + g_variant_builder_init (&_tmp6_, G_VARIANT_TYPE ("ad")); + for (_tmp7_ = 0; _tmp7_ < result_length2; _tmp7_++) { + g_variant_builder_add_value (&_tmp6_, g_variant_new_double (*_tmp3_)); + _tmp3_++; + } + g_variant_builder_add_value (&_tmp4_, g_variant_builder_end (&_tmp6_)); + } + g_variant_builder_add_value (&_reply_builder, g_variant_builder_end (&_tmp4_)); + result = (g_free (result), NULL); + _reply = g_variant_builder_end (&_reply_builder); + g_dbus_message_set_body (_reply_message, _reply); + g_dbus_connection_send_message (g_dbus_method_invocation_get_connection (invocation), _reply_message, G_DBUS_SEND_MESSAGE_FLAGS_NONE, NULL, NULL); + g_object_unref (invocation); + g_object_unref (_reply_message); +} + +static void +_dbus_test_multi_array2 (Test* self, + GVariant* _parameters_, + GDBusMethodInvocation* invocation) +{ + GError* error = NULL; + GVariantIter _arguments_iter; + GDBusMessage* _reply_message = NULL; + GVariant* _reply; + GVariantBuilder _reply_builder; + gchar** result; + gint result_length1 = 0; + gint result_length2 = 0; + gint result_length3 = 0; + gchar** _tmp8_; + GVariantBuilder _tmp9_; + gint _tmp10_; + g_variant_iter_init (&_arguments_iter, _parameters_); + result = test_multi_array2 (self, &result_length1, &result_length2, &result_length3); + _reply_message = g_dbus_message_new_method_reply (g_dbus_method_invocation_get_message (invocation)); + g_variant_builder_init (&_reply_builder, G_VARIANT_TYPE_TUPLE); + _tmp8_ = result; + g_variant_builder_init (&_tmp9_, G_VARIANT_TYPE ("aaas")); + for (_tmp10_ = 0; _tmp10_ < result_length1; _tmp10_++) { + GVariantBuilder _tmp11_; + gint _tmp12_; + g_variant_builder_init (&_tmp11_, G_VARIANT_TYPE ("aas")); + for (_tmp12_ = 0; _tmp12_ < result_length2; _tmp12_++) { + GVariantBuilder _tmp13_; + gint _tmp14_; + g_variant_builder_init (&_tmp13_, G_VARIANT_TYPE ("as")); + for (_tmp14_ = 0; _tmp14_ < result_length3; _tmp14_++) { + g_variant_builder_add_value (&_tmp13_, g_variant_new_string (*_tmp8_)); + _tmp8_++; + } + g_variant_builder_add_value (&_tmp11_, g_variant_builder_end (&_tmp13_)); + } + g_variant_builder_add_value (&_tmp9_, g_variant_builder_end (&_tmp11_)); + } + g_variant_builder_add_value (&_reply_builder, g_variant_builder_end (&_tmp9_)); + result = (_vala_array_free (result, (result_length1 * result_length2) * result_length3, (GDestroyNotify) g_free), NULL); + _reply = g_variant_builder_end (&_reply_builder); + g_dbus_message_set_body (_reply_message, _reply); + g_dbus_connection_send_message (g_dbus_method_invocation_get_connection (invocation), _reply_message, G_DBUS_SEND_MESSAGE_FLAGS_NONE, NULL, NULL); + g_object_unref (invocation); + g_object_unref (_reply_message); +} + +static void +test_dbus_interface_method_call (GDBusConnection* connection, + const gchar* sender, + const gchar* object_path, + const gchar* interface_name, + const gchar* method_name, + GVariant* parameters, + GDBusMethodInvocation* invocation, + gpointer user_data) +{ + gpointer* data; + gpointer object; + data = user_data; + object = data[0]; + if (strcmp (method_name, "Array") == 0) { + _dbus_test_array (object, parameters, invocation); + } else if (strcmp (method_name, "MultiArray") == 0) { + _dbus_test_multi_array (object, parameters, invocation); + } else if (strcmp (method_name, "MultiArray2") == 0) { + _dbus_test_multi_array2 (object, parameters, invocation); + } else { + g_object_unref (invocation); + } +} + +static GVariant* +test_dbus_interface_get_property (GDBusConnection* connection, + const gchar* sender, + const gchar* object_path, + const gchar* interface_name, + const gchar* property_name, + GError** error, + gpointer user_data) +{ + gpointer* data; + gpointer object; + data = user_data; + object = data[0]; + return NULL; +} + +static gboolean +test_dbus_interface_set_property (GDBusConnection* connection, + const gchar* sender, + const gchar* object_path, + const gchar* interface_name, + const gchar* property_name, + GVariant* value, + GError** error, + gpointer user_data) +{ + gpointer* data; + gpointer object; + data = user_data; + object = data[0]; + return FALSE; +} + +guint +test_register_object (gpointer object, + GDBusConnection* connection, + const gchar* path, + GError** error) +{ + guint result; + gpointer *data; + data = g_new (gpointer, 3); + data[0] = g_object_ref (object); + data[1] = g_object_ref (connection); + data[2] = g_strdup (path); + result = g_dbus_connection_register_object (connection, path, (GDBusInterfaceInfo *) (&_test_dbus_interface_info), &_test_dbus_interface_vtable, data, _test_unregister_object, error); + if (!result) { + return 0; + } + return result; +} + +static void +_test_unregister_object (gpointer user_data) +{ + gpointer* data; + data = user_data; + g_object_unref (data[0]); + g_object_unref (data[1]); + g_free (data[2]); + g_free (data); +} + +void +client_exit (GPid pid, + gint status) +{ + GMainLoop* _tmp0_; + _vala_assert (status == 0, "status == 0"); + _tmp0_ = main_loop; + g_main_loop_quit (_tmp0_); +} + +static guint +_variant_get1 (GVariant* value) +{ + return g_variant_get_uint32 (value); +} + +static void +_client_exit_gchild_watch_func (GPid pid, + gint wait_status, + gpointer self) +{ + client_exit (pid, wait_status); +} + +static void +_vala_main (void) +{ + GDBusConnection* conn = NULL; + GDBusConnection* _tmp0_; + GDBusConnection* _tmp1_; + Test* _tmp2_; + Test* _tmp3_; + GVariant* request_result = NULL; + GDBusConnection* _tmp4_; + GVariant* _tmp5_; + GVariant* _tmp6_; + GVariant* _tmp7_; + GVariant* _tmp8_; + GVariant* _tmp9_; + GVariant* _tmp10_; + GVariant* _tmp11_; + guint _tmp12_; + GPid client_pid = 0; + gchar* _tmp13_; + gchar** _tmp14_; + gchar** _tmp15_; + gint _tmp15__length1; + GPid _tmp16_ = 0; + GMainLoop* _tmp17_; + GMainLoop* _tmp18_; + GError* _inner_error0_ = NULL; + _tmp0_ = g_bus_get_sync (G_BUS_TYPE_SESSION, NULL, &_inner_error0_); + conn = _tmp0_; + if (G_UNLIKELY (_inner_error0_ != NULL)) { + g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error0_->message, g_quark_to_string (_inner_error0_->domain), _inner_error0_->code); + g_clear_error (&_inner_error0_); + return; + } + _tmp1_ = conn; + _tmp2_ = test_new (); + _tmp3_ = _tmp2_; + test_register_object (_tmp3_, _tmp1_, "/org/example/test", &_inner_error0_); + _g_object_unref0 (_tmp3_); + if (G_UNLIKELY (_inner_error0_ != NULL)) { + _g_object_unref0 (conn); + g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error0_->message, g_quark_to_string (_inner_error0_->domain), _inner_error0_->code); + g_clear_error (&_inner_error0_); + return; + } + _tmp4_ = conn; + _tmp5_ = g_variant_new ("(su)", "org.example.Test", 0x4, NULL); + g_variant_ref_sink (_tmp5_); + _tmp6_ = _tmp5_; + _tmp7_ = g_dbus_connection_call_sync (_tmp4_, "org.freedesktop.DBus", "/org/freedesktop/DBus", "org.freedesktop.DBus", "RequestName", _tmp6_, NULL, 0, -1, NULL, &_inner_error0_); + _tmp8_ = _tmp7_; + _g_variant_unref0 (_tmp6_); + request_result = _tmp8_; + if (G_UNLIKELY (_inner_error0_ != NULL)) { + _g_object_unref0 (conn); + g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error0_->message, g_quark_to_string (_inner_error0_->domain), _inner_error0_->code); + g_clear_error (&_inner_error0_); + return; + } + _tmp9_ = request_result; + _tmp10_ = g_variant_get_child_value (_tmp9_, (gsize) 0); + _tmp11_ = _tmp10_; + _tmp12_ = _variant_get1 (_tmp11_); + _vala_assert (_tmp12_ == ((guint) 1), "(uint) request_result.get_child_value (0) == 1"); + _g_variant_unref0 (_tmp11_); + _tmp13_ = g_strdup ("dbus_bug735437_client"); + _tmp14_ = g_new0 (gchar*, 1 + 1); + _tmp14_[0] = _tmp13_; + _tmp15_ = _tmp14_; + _tmp15__length1 = 1; + g_spawn_async (NULL, _tmp15_, NULL, G_SPAWN_DO_NOT_REAP_CHILD, NULL, NULL, &_tmp16_, &_inner_error0_); + client_pid = _tmp16_; + _tmp15_ = (_vala_array_free (_tmp15_, _tmp15__length1, (GDestroyNotify) g_free), NULL); + if (G_UNLIKELY (_inner_error0_ != NULL)) { + _g_variant_unref0 (request_result); + _g_object_unref0 (conn); + g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error0_->message, g_quark_to_string (_inner_error0_->domain), _inner_error0_->code); + g_clear_error (&_inner_error0_); + return; + } + g_child_watch_add_full (G_PRIORITY_DEFAULT_IDLE, client_pid, _client_exit_gchild_watch_func, NULL, NULL); + _tmp17_ = g_main_loop_new (NULL, FALSE); + _g_main_loop_unref0 (main_loop); + main_loop = _tmp17_; + _tmp18_ = main_loop; + g_main_loop_run (_tmp18_); + _g_variant_unref0 (request_result); + _g_object_unref0 (conn); +} + +int +main (int argc, + char ** argv) +{ + _vala_main (); + return 0; +} + +static void +_vala_array_destroy (gpointer array, + gssize array_length, + GDestroyNotify destroy_func) +{ + if ((array != NULL) && (destroy_func != NULL)) { + gssize i; + for (i = 0; i < array_length; i = i + 1) { + if (((gpointer*) array)[i] != NULL) { + destroy_func (((gpointer*) array)[i]); + } + } + } +} + +static void +_vala_array_free (gpointer array, + gssize array_length, + GDestroyNotify destroy_func) +{ + _vala_array_destroy (array, array_length, destroy_func); + g_free (array); +} + diff --git a/tests/dbus/bug782719_client.c-expected b/tests/dbus/bug782719_client.c-expected new file mode 100644 index 000000000..a5883c89f --- /dev/null +++ b/tests/dbus/bug782719_client.c-expected @@ -0,0 +1,527 @@ +/* dbus_bug782719_client.c generated by valac, the Vala compiler + * generated from dbus_bug782719_client.vala, do not modify */ + +#include <glib-object.h> +#include <gio/gio.h> +#include <glib.h> +#include <stdlib.h> +#include <string.h> + +#if !defined(VALA_EXTERN) +#if defined(_MSC_VER) +#define VALA_EXTERN __declspec(dllexport) extern +#elif __GNUC__ >= 4 +#define VALA_EXTERN __attribute__((visibility("default"))) extern +#else +#define VALA_EXTERN extern +#endif +#endif + +#define TYPE_TEST (test_get_type ()) +#define TEST(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TYPE_TEST, Test)) +#define IS_TEST(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TYPE_TEST)) +#define TEST_GET_INTERFACE(obj) (G_TYPE_INSTANCE_GET_INTERFACE ((obj), TYPE_TEST, TestIface)) + +typedef struct _Test Test; +typedef struct _TestIface TestIface; + +#define TYPE_TEST_PROXY (test_proxy_get_type ()) +typedef GDBusProxy TestProxy; +typedef GDBusProxyClass TestProxyClass; +#define _g_hash_table_unref0(var) ((var == NULL) ? NULL : (var = (g_hash_table_unref (var), NULL))) +#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL))) +#define _g_variant_unref0(var) ((var == NULL) ? NULL : (var = (g_variant_unref (var), NULL))) +#define _vala_assert(expr, msg) if G_LIKELY (expr) ; else g_assertion_message_expr (G_LOG_DOMAIN, __FILE__, __LINE__, G_STRFUNC, msg); +#define _vala_return_if_fail(expr, msg) if G_LIKELY (expr) ; else { g_return_if_fail_warning (G_LOG_DOMAIN, G_STRFUNC, msg); return; } +#define _vala_return_val_if_fail(expr, msg, val) if G_LIKELY (expr) ; else { g_return_if_fail_warning (G_LOG_DOMAIN, G_STRFUNC, msg); return val; } +#define _vala_warn_if_fail(expr, msg) if G_LIKELY (expr) ; else g_warn_message (G_LOG_DOMAIN, __FILE__, __LINE__, G_STRFUNC, msg); + +struct _TestIface { + GTypeInterface parent_iface; + GHashTable* (*test_nested_dict) (Test* self, GError** error); +}; + +VALA_EXTERN GType test_proxy_get_type (void) G_GNUC_CONST ; +VALA_EXTERN guint test_register_object (void* object, + GDBusConnection* connection, + const gchar* path, + GError** error); +VALA_EXTERN GType test_get_type (void) G_GNUC_CONST ; +VALA_EXTERN GHashTable* test_test_nested_dict (Test* self, + GError** error); +static GType test_get_type_once (void); +static void test_proxy_g_signal (GDBusProxy* proxy, + const gchar* sender_name, + const gchar* signal_name, + GVariant* parameters); +static GHashTable* test_proxy_test_nested_dict (Test* self, + GError** error); +static void test_proxy_test_interface_init (TestIface* iface); +static void _dbus_test_test_nested_dict (Test* self, + GVariant* _parameters_, + GDBusMethodInvocation* invocation); +static void test_dbus_interface_method_call (GDBusConnection* connection, + const gchar* sender, + const gchar* object_path, + const gchar* interface_name, + const gchar* method_name, + GVariant* parameters, + GDBusMethodInvocation* invocation, + gpointer user_data); +static GVariant* test_dbus_interface_get_property (GDBusConnection* connection, + const gchar* sender, + const gchar* object_path, + const gchar* interface_name, + const gchar* property_name, + GError** error, + gpointer user_data); +static gboolean test_dbus_interface_set_property (GDBusConnection* connection, + const gchar* sender, + const gchar* object_path, + const gchar* interface_name, + const gchar* property_name, + GVariant* value, + GError** error, + gpointer user_data); +static void _test_unregister_object (gpointer user_data); +static void _vala_main (void); +static gchar** _variant_get1 (GVariant* value, + gint* result_length1); +static void _vala_array_destroy (gpointer array, + gssize array_length, + GDestroyNotify destroy_func); +static void _vala_array_free (gpointer array, + gssize array_length, + GDestroyNotify destroy_func); + +static const GDBusArgInfo _test_dbus_arg_info_test_nested_dict_result = {-1, "result", "a{sa{sv}}", NULL}; +static const GDBusArgInfo * const _test_dbus_arg_info_test_nested_dict_in[] = {NULL}; +static const GDBusArgInfo * const _test_dbus_arg_info_test_nested_dict_out[] = {&_test_dbus_arg_info_test_nested_dict_result, NULL}; +static const GDBusMethodInfo _test_dbus_method_info_test_nested_dict = {-1, "TestNestedDict", (GDBusArgInfo **) (&_test_dbus_arg_info_test_nested_dict_in), (GDBusArgInfo **) (&_test_dbus_arg_info_test_nested_dict_out), NULL}; +static const GDBusMethodInfo * const _test_dbus_method_info[] = {&_test_dbus_method_info_test_nested_dict, NULL}; +static const GDBusSignalInfo * const _test_dbus_signal_info[] = {NULL}; +static const GDBusPropertyInfo * const _test_dbus_property_info[] = {NULL}; +static const GDBusInterfaceInfo _test_dbus_interface_info = {-1, "org.example.Test", (GDBusMethodInfo **) (&_test_dbus_method_info), (GDBusSignalInfo **) (&_test_dbus_signal_info), (GDBusPropertyInfo **) (&_test_dbus_property_info), NULL}; +static const GDBusInterfaceVTable _test_dbus_interface_vtable = {test_dbus_interface_method_call, test_dbus_interface_get_property, test_dbus_interface_set_property}; + +GHashTable* +test_test_nested_dict (Test* self, + GError** error) +{ + TestIface* _iface_; + g_return_val_if_fail (IS_TEST (self), NULL); + _iface_ = TEST_GET_INTERFACE (self); + if (_iface_->test_nested_dict) { + return _iface_->test_nested_dict (self, error); + } + return NULL; +} + +static void +test_default_init (TestIface * iface, + gpointer iface_data) +{ +} + +static GType +test_get_type_once (void) +{ + static const GTypeInfo g_define_type_info = { sizeof (TestIface), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) test_default_init, (GClassFinalizeFunc) NULL, NULL, 0, 0, (GInstanceInitFunc) NULL, NULL }; + GType test_type_id; + test_type_id = g_type_register_static (G_TYPE_INTERFACE, "Test", &g_define_type_info, 0); + g_type_interface_add_prerequisite (test_type_id, G_TYPE_OBJECT); + g_type_set_qdata (test_type_id, g_quark_from_static_string ("vala-dbus-proxy-type"), (void*) test_proxy_get_type); + g_type_set_qdata (test_type_id, g_quark_from_static_string ("vala-dbus-interface-name"), "org.example.Test"); + g_type_set_qdata (test_type_id, g_quark_from_static_string ("vala-dbus-interface-info"), (void*) (&_test_dbus_interface_info)); + g_type_set_qdata (test_type_id, g_quark_from_static_string ("vala-dbus-register-object"), (void*) test_register_object); + return test_type_id; +} + +GType +test_get_type (void) +{ + static volatile gsize test_type_id__volatile = 0; + if (g_once_init_enter (&test_type_id__volatile)) { + GType test_type_id; + test_type_id = test_get_type_once (); + g_once_init_leave (&test_type_id__volatile, test_type_id); + } + return test_type_id__volatile; +} + +G_DEFINE_TYPE_EXTENDED (TestProxy, test_proxy, G_TYPE_DBUS_PROXY, 0, G_IMPLEMENT_INTERFACE (TYPE_TEST, test_proxy_test_interface_init) ) +static void +test_proxy_class_init (TestProxyClass* klass) +{ + G_DBUS_PROXY_CLASS (klass)->g_signal = test_proxy_g_signal; +} + +static void +test_proxy_g_signal (GDBusProxy* proxy, + const gchar* sender_name, + const gchar* signal_name, + GVariant* parameters) +{ +} + +static void +test_proxy_init (TestProxy* self) +{ + g_dbus_proxy_set_interface_info (G_DBUS_PROXY (self), (GDBusInterfaceInfo *) (&_test_dbus_interface_info)); +} + +static GHashTable* +test_proxy_test_nested_dict (Test* self, + GError** error) +{ + GDBusMessage *_message; + GVariant *_arguments; + GVariantBuilder _arguments_builder; + GDBusMessage *_reply_message; + GVariant *_reply; + GVariantIter _reply_iter; + GHashTable* _result = NULL; + GVariant* _tmp0_; + GHashTable* _tmp1_; + GVariantIter _tmp2_; + GVariant* _tmp3_; + GVariant* _tmp4_; + G_IO_ERROR; + _message = g_dbus_message_new_method_call (g_dbus_proxy_get_name ((GDBusProxy *) self), g_dbus_proxy_get_object_path ((GDBusProxy *) self), "org.example.Test", "TestNestedDict"); + g_variant_builder_init (&_arguments_builder, G_VARIANT_TYPE_TUPLE); + _arguments = g_variant_builder_end (&_arguments_builder); + g_dbus_message_set_body (_message, _arguments); + _reply_message = g_dbus_connection_send_message_with_reply_sync (g_dbus_proxy_get_connection ((GDBusProxy *) self), _message, G_DBUS_SEND_MESSAGE_FLAGS_NONE, g_dbus_proxy_get_default_timeout ((GDBusProxy *) self), NULL, NULL, error); + g_object_unref (_message); + if (!_reply_message) { + return NULL; + } + if (g_dbus_message_to_gerror (_reply_message, error)) { + g_object_unref (_reply_message); + return NULL; + } + _reply = g_dbus_message_get_body (_reply_message); + g_variant_iter_init (&_reply_iter, _reply); + _tmp0_ = g_variant_iter_next_value (&_reply_iter); + _tmp1_ = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, (GDestroyNotify) g_hash_table_unref); + g_variant_iter_init (&_tmp2_, _tmp0_); + while (g_variant_iter_loop (&_tmp2_, "{?*}", &_tmp3_, &_tmp4_)) { + GHashTable* _tmp5_; + GVariantIter _tmp6_; + GVariant* _tmp7_; + GVariant* _tmp8_; + _tmp5_ = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, (GDestroyNotify) g_variant_unref); + g_variant_iter_init (&_tmp6_, _tmp4_); + while (g_variant_iter_loop (&_tmp6_, "{?*}", &_tmp7_, &_tmp8_)) { + g_hash_table_insert (_tmp5_, g_variant_dup_string (_tmp7_, NULL), g_variant_get_variant (_tmp8_)); + } + g_hash_table_insert (_tmp1_, g_variant_dup_string (_tmp3_, NULL), _tmp5_); + } + _result = _tmp1_; + g_variant_unref (_tmp0_); + g_object_unref (_reply_message); + return _result; +} + +static void +test_proxy_test_interface_init (TestIface* iface) +{ + iface->test_nested_dict = test_proxy_test_nested_dict; +} + +static void +_dbus_test_test_nested_dict (Test* self, + GVariant* _parameters_, + GDBusMethodInvocation* invocation) +{ + GError* error = NULL; + GVariantIter _arguments_iter; + GDBusMessage* _reply_message = NULL; + GVariant* _reply; + GVariantBuilder _reply_builder; + GHashTable* result; + GVariantBuilder _tmp9_; + GHashTableIter _tmp10_; + gpointer _tmp11_; + gpointer _tmp12_; + g_variant_iter_init (&_arguments_iter, _parameters_); + result = test_test_nested_dict (self, &error); + if (error) { + g_dbus_method_invocation_return_gerror (invocation, error); + g_error_free (error); + return; + } + _reply_message = g_dbus_message_new_method_reply (g_dbus_method_invocation_get_message (invocation)); + g_variant_builder_init (&_reply_builder, G_VARIANT_TYPE_TUPLE); + g_hash_table_iter_init (&_tmp10_, result); + g_variant_builder_init (&_tmp9_, G_VARIANT_TYPE ("a{sa{sv}}")); + while (g_hash_table_iter_next (&_tmp10_, &_tmp11_, &_tmp12_)) { + gchar* _key; + GHashTable* _value; + GVariantBuilder _tmp13_; + GHashTableIter _tmp14_; + gpointer _tmp15_; + gpointer _tmp16_; + _key = (gchar*) _tmp11_; + _value = (GHashTable*) _tmp12_; + g_hash_table_iter_init (&_tmp14_, _value); + g_variant_builder_init (&_tmp13_, G_VARIANT_TYPE ("a{sv}")); + while (g_hash_table_iter_next (&_tmp14_, &_tmp15_, &_tmp16_)) { + gchar* _key; + GVariant* _value; + _key = (gchar*) _tmp15_; + _value = (GVariant*) _tmp16_; + g_variant_builder_add (&_tmp13_, "{?*}", g_variant_new_string (_key), g_variant_new_variant (_value)); + } + g_variant_builder_add (&_tmp9_, "{?*}", g_variant_new_string (_key), g_variant_builder_end (&_tmp13_)); + } + g_variant_builder_add_value (&_reply_builder, g_variant_builder_end (&_tmp9_)); + _g_hash_table_unref0 (result); + _reply = g_variant_builder_end (&_reply_builder); + g_dbus_message_set_body (_reply_message, _reply); + g_dbus_connection_send_message (g_dbus_method_invocation_get_connection (invocation), _reply_message, G_DBUS_SEND_MESSAGE_FLAGS_NONE, NULL, NULL); + g_object_unref (invocation); + g_object_unref (_reply_message); +} + +static void +test_dbus_interface_method_call (GDBusConnection* connection, + const gchar* sender, + const gchar* object_path, + const gchar* interface_name, + const gchar* method_name, + GVariant* parameters, + GDBusMethodInvocation* invocation, + gpointer user_data) +{ + gpointer* data; + gpointer object; + data = user_data; + object = data[0]; + if (strcmp (method_name, "TestNestedDict") == 0) { + _dbus_test_test_nested_dict (object, parameters, invocation); + } else { + g_object_unref (invocation); + } +} + +static GVariant* +test_dbus_interface_get_property (GDBusConnection* connection, + const gchar* sender, + const gchar* object_path, + const gchar* interface_name, + const gchar* property_name, + GError** error, + gpointer user_data) +{ + gpointer* data; + gpointer object; + data = user_data; + object = data[0]; + return NULL; +} + +static gboolean +test_dbus_interface_set_property (GDBusConnection* connection, + const gchar* sender, + const gchar* object_path, + const gchar* interface_name, + const gchar* property_name, + GVariant* value, + GError** error, + gpointer user_data) +{ + gpointer* data; + gpointer object; + data = user_data; + object = data[0]; + return FALSE; +} + +guint +test_register_object (gpointer object, + GDBusConnection* connection, + const gchar* path, + GError** error) +{ + guint result; + gpointer *data; + data = g_new (gpointer, 3); + data[0] = g_object_ref (object); + data[1] = g_object_ref (connection); + data[2] = g_strdup (path); + result = g_dbus_connection_register_object (connection, path, (GDBusInterfaceInfo *) (&_test_dbus_interface_info), &_test_dbus_interface_vtable, data, _test_unregister_object, error); + if (!result) { + return 0; + } + return result; +} + +static void +_test_unregister_object (gpointer user_data) +{ + gpointer* data; + data = user_data; + g_object_unref (data[0]); + g_object_unref (data[1]); + g_free (data[2]); + g_free (data); +} + +static gpointer +_g_hash_table_ref0 (gpointer self) +{ + return self ? g_hash_table_ref (self) : NULL; +} + +static gpointer +_g_variant_ref0 (gpointer self) +{ + return self ? g_variant_ref (self) : NULL; +} + +static gchar** +_variant_get1 (GVariant* value, + gint* result_length1) +{ + gchar** _tmp14_; + gint _tmp14__length; + gint _tmp14__size; + gint _tmp14__length1; + GVariantIter _tmp15_; + GVariant* _tmp16_; + _tmp14_ = g_new (gchar*, 5); + _tmp14__length = 0; + _tmp14__size = 4; + _tmp14__length1 = 0; + g_variant_iter_init (&_tmp15_, value); + for (; (_tmp16_ = g_variant_iter_next_value (&_tmp15_)) != NULL; _tmp14__length1++) { + if (_tmp14__size == _tmp14__length) { + _tmp14__size = 2 * _tmp14__size; + _tmp14_ = g_renew (gchar*, _tmp14_, _tmp14__size + 1); + } + _tmp14_[_tmp14__length++] = g_variant_dup_string (_tmp16_, NULL); + g_variant_unref (_tmp16_); + } + *result_length1 = _tmp14__length1; + _tmp14_[_tmp14__length] = NULL; + return _tmp14_; +} + +static void +_vala_main (void) +{ + Test* test = NULL; + Test* _tmp0_; + GHashTable* dict = NULL; + Test* _tmp1_; + GHashTable* _tmp2_; + GHashTable* _tmp3_; + GHashTable* nested_dict = NULL; + GHashTable* _tmp4_; + gconstpointer _tmp5_; + GHashTable* _tmp6_; + GHashTable* _tmp7_; + GVariant* v = NULL; + GHashTable* _tmp8_; + gconstpointer _tmp9_; + GVariant* _tmp10_; + GVariant* _tmp11_; + gchar** s = NULL; + GVariant* _tmp12_; + gchar** _tmp13_ = NULL; + gint _tmp13__length1 = 0; + gint s_length1; + gint _s_size_; + gboolean _tmp17_ = FALSE; + gchar** _tmp18_; + gint _tmp18__length1; + GError* _inner_error0_ = NULL; + _tmp0_ = (Test*) g_initable_new (TYPE_TEST_PROXY, NULL, &_inner_error0_, "g-flags", 0, "g-name", "org.example.Test", "g-bus-type", G_BUS_TYPE_SESSION, "g-object-path", "/org/example/test", "g-interface-name", "org.example.Test", NULL); + test = (Test*) _tmp0_; + if (G_UNLIKELY (_inner_error0_ != NULL)) { + g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error0_->message, g_quark_to_string (_inner_error0_->domain), _inner_error0_->code); + g_clear_error (&_inner_error0_); + return; + } + _tmp1_ = test; + _tmp2_ = test_test_nested_dict (_tmp1_, &_inner_error0_); + dict = _tmp2_; + if (G_UNLIKELY (_inner_error0_ != NULL)) { + _g_object_unref0 (test); + g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error0_->message, g_quark_to_string (_inner_error0_->domain), _inner_error0_->code); + g_clear_error (&_inner_error0_); + return; + } + _tmp3_ = dict; + _vala_assert (g_hash_table_size (_tmp3_) == ((guint) 1), "dict.size () == 1"); + _tmp4_ = dict; + _tmp5_ = g_hash_table_lookup (_tmp4_, "hello"); + _tmp6_ = _g_hash_table_ref0 ((GHashTable*) _tmp5_); + nested_dict = _tmp6_; + _tmp7_ = nested_dict; + _vala_assert (_tmp7_ != NULL, "nested_dict != null"); + _tmp8_ = nested_dict; + _tmp9_ = g_hash_table_lookup (_tmp8_, "hello"); + _tmp10_ = _g_variant_ref0 ((GVariant*) _tmp9_); + v = _tmp10_; + _tmp11_ = v; + _vala_assert (_tmp11_ != NULL, "v != null"); + _tmp12_ = v; + _tmp13_ = _variant_get1 (_tmp12_, &_tmp13__length1); + s = _tmp13_; + s_length1 = _tmp13__length1; + _s_size_ = s_length1; + _tmp18_ = s; + _tmp18__length1 = s_length1; + if (_tmp18__length1 == 1) { + gchar** _tmp19_; + gint _tmp19__length1; + const gchar* _tmp20_; + _tmp19_ = s; + _tmp19__length1 = s_length1; + _tmp20_ = _tmp19_[0]; + _tmp17_ = g_strcmp0 (_tmp20_, "hello") == 0; + } else { + _tmp17_ = FALSE; + } + _vala_assert (_tmp17_, "s.length == 1 && s[0] == \"hello\""); + s = (_vala_array_free (s, s_length1, (GDestroyNotify) g_free), NULL); + _g_variant_unref0 (v); + _g_hash_table_unref0 (nested_dict); + _g_hash_table_unref0 (dict); + _g_object_unref0 (test); +} + +int +main (int argc, + char ** argv) +{ + _vala_main (); + return 0; +} + +static void +_vala_array_destroy (gpointer array, + gssize array_length, + GDestroyNotify destroy_func) +{ + if ((array != NULL) && (destroy_func != NULL)) { + gssize i; + for (i = 0; i < array_length; i = i + 1) { + if (((gpointer*) array)[i] != NULL) { + destroy_func (((gpointer*) array)[i]); + } + } + } +} + +static void +_vala_array_free (gpointer array, + gssize array_length, + GDestroyNotify destroy_func) +{ + _vala_array_destroy (array, array_length, destroy_func); + g_free (array); +} + diff --git a/tests/dbus/bug782719_server.c-expected b/tests/dbus/bug782719_server.c-expected new file mode 100644 index 000000000..1022c606e --- /dev/null +++ b/tests/dbus/bug782719_server.c-expected @@ -0,0 +1,535 @@ +/* dbus_bug782719_server.c generated by valac, the Vala compiler + * generated from dbus_bug782719_server.vala, do not modify */ + +#include <glib-object.h> +#include <gio/gio.h> +#include <glib.h> +#include <stdlib.h> +#include <string.h> + +#if !defined(VALA_EXTERN) +#if defined(_MSC_VER) +#define VALA_EXTERN __declspec(dllexport) extern +#elif __GNUC__ >= 4 +#define VALA_EXTERN __attribute__((visibility("default"))) extern +#else +#define VALA_EXTERN extern +#endif +#endif + +#define TYPE_TEST (test_get_type ()) +#define TEST(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TYPE_TEST, Test)) +#define TEST_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), TYPE_TEST, TestClass)) +#define IS_TEST(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TYPE_TEST)) +#define IS_TEST_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), TYPE_TEST)) +#define TEST_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), TYPE_TEST, TestClass)) + +typedef struct _Test Test; +typedef struct _TestClass TestClass; +typedef struct _TestPrivate TestPrivate; +enum { + TEST_0_PROPERTY, + TEST_NUM_PROPERTIES +}; +static GParamSpec* test_properties[TEST_NUM_PROPERTIES]; +#define _g_hash_table_unref0(var) ((var == NULL) ? NULL : (var = (g_hash_table_unref (var), NULL))) +#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL))) +#define _g_variant_unref0(var) ((var == NULL) ? NULL : (var = (g_variant_unref (var), NULL))) +#define _g_main_loop_unref0(var) ((var == NULL) ? NULL : (var = (g_main_loop_unref (var), NULL))) +#define _vala_assert(expr, msg) if G_LIKELY (expr) ; else g_assertion_message_expr (G_LOG_DOMAIN, __FILE__, __LINE__, G_STRFUNC, msg); +#define _vala_return_if_fail(expr, msg) if G_LIKELY (expr) ; else { g_return_if_fail_warning (G_LOG_DOMAIN, G_STRFUNC, msg); return; } +#define _vala_return_val_if_fail(expr, msg, val) if G_LIKELY (expr) ; else { g_return_if_fail_warning (G_LOG_DOMAIN, G_STRFUNC, msg); return val; } +#define _vala_warn_if_fail(expr, msg) if G_LIKELY (expr) ; else g_warn_message (G_LOG_DOMAIN, __FILE__, __LINE__, G_STRFUNC, msg); + +struct _Test { + GObject parent_instance; + TestPrivate * priv; +}; + +struct _TestClass { + GObjectClass parent_class; +}; + +static gpointer test_parent_class = NULL; +VALA_EXTERN GMainLoop* main_loop; +GMainLoop* main_loop = NULL; + +VALA_EXTERN GType test_get_type (void) G_GNUC_CONST ; +G_DEFINE_AUTOPTR_CLEANUP_FUNC (Test, g_object_unref) +VALA_EXTERN guint test_register_object (void* object, + GDBusConnection* connection, + const gchar* path, + GError** error); +VALA_EXTERN GHashTable* test_test_nested_dict (Test* self); +static void _g_free0_ (gpointer var); +static void _g_variant_unref0_ (gpointer var); +static GVariant* _variant_new1 (gchar** value, + gint value_length1); +static void _g_hash_table_unref0_ (gpointer var); +VALA_EXTERN Test* test_new (void); +VALA_EXTERN Test* test_construct (GType object_type); +static GType test_get_type_once (void); +static void _dbus_test_test_nested_dict (Test* self, + GVariant* _parameters_, + GDBusMethodInvocation* invocation); +static void test_dbus_interface_method_call (GDBusConnection* connection, + const gchar* sender, + const gchar* object_path, + const gchar* interface_name, + const gchar* method_name, + GVariant* parameters, + GDBusMethodInvocation* invocation, + gpointer user_data); +static GVariant* test_dbus_interface_get_property (GDBusConnection* connection, + const gchar* sender, + const gchar* object_path, + const gchar* interface_name, + const gchar* property_name, + GError** error, + gpointer user_data); +static gboolean test_dbus_interface_set_property (GDBusConnection* connection, + const gchar* sender, + const gchar* object_path, + const gchar* interface_name, + const gchar* property_name, + GVariant* value, + GError** error, + gpointer user_data); +static void _test_unregister_object (gpointer user_data); +VALA_EXTERN void client_exit (GPid pid, + gint status); +static void _vala_main (void); +static guint _variant_get1 (GVariant* value); +static void _client_exit_gchild_watch_func (GPid pid, + gint wait_status, + gpointer self); +static void _vala_array_destroy (gpointer array, + gssize array_length, + GDestroyNotify destroy_func); +static void _vala_array_free (gpointer array, + gssize array_length, + GDestroyNotify destroy_func); + +static const GDBusArgInfo _test_dbus_arg_info_test_nested_dict_result = {-1, "result", "a{sa{sv}}", NULL}; +static const GDBusArgInfo * const _test_dbus_arg_info_test_nested_dict_in[] = {NULL}; +static const GDBusArgInfo * const _test_dbus_arg_info_test_nested_dict_out[] = {&_test_dbus_arg_info_test_nested_dict_result, NULL}; +static const GDBusMethodInfo _test_dbus_method_info_test_nested_dict = {-1, "TestNestedDict", (GDBusArgInfo **) (&_test_dbus_arg_info_test_nested_dict_in), (GDBusArgInfo **) (&_test_dbus_arg_info_test_nested_dict_out), NULL}; +static const GDBusMethodInfo * const _test_dbus_method_info[] = {&_test_dbus_method_info_test_nested_dict, NULL}; +static const GDBusSignalInfo * const _test_dbus_signal_info[] = {NULL}; +static const GDBusPropertyInfo * const _test_dbus_property_info[] = {NULL}; +static const GDBusInterfaceInfo _test_dbus_interface_info = {-1, "org.example.Test", (GDBusMethodInfo **) (&_test_dbus_method_info), (GDBusSignalInfo **) (&_test_dbus_signal_info), (GDBusPropertyInfo **) (&_test_dbus_property_info), NULL}; +static const GDBusInterfaceVTable _test_dbus_interface_vtable = {test_dbus_interface_method_call, test_dbus_interface_get_property, test_dbus_interface_set_property}; + +static void +_g_free0_ (gpointer var) +{ + var = (g_free (var), NULL); +} + +static void +_g_variant_unref0_ (gpointer var) +{ + (var == NULL) ? NULL : (var = (g_variant_unref (var), NULL)); +} + +static GVariant* +_variant_new1 (gchar** value, + gint value_length1) +{ + gchar** _tmp5_; + GVariantBuilder _tmp6_; + gint _tmp7_; + _tmp5_ = value; + g_variant_builder_init (&_tmp6_, G_VARIANT_TYPE ("as")); + for (_tmp7_ = 0; _tmp7_ < value_length1; _tmp7_++) { + g_variant_builder_add_value (&_tmp6_, g_variant_new_string (*_tmp5_)); + _tmp5_++; + } + return g_variant_ref_sink (g_variant_builder_end (&_tmp6_)); +} + +static void +_g_hash_table_unref0_ (gpointer var) +{ + (var == NULL) ? NULL : (var = (g_hash_table_unref (var), NULL)); +} + +static gpointer +_g_hash_table_ref0 (gpointer self) +{ + return self ? g_hash_table_ref (self) : NULL; +} + +GHashTable* +test_test_nested_dict (Test* self) +{ + gchar** s = NULL; + gchar* _tmp0_; + gchar** _tmp1_; + gint s_length1; + gint _s_size_; + GHashTable* nested_dict = NULL; + GHashFunc _tmp2_; + GHashTable* _tmp3_; + gchar* _tmp4_; + GVariant* _tmp8_; + GHashTable* dict = NULL; + GHashFunc _tmp9_; + GHashTable* _tmp10_; + gchar* _tmp11_; + GHashTable* _tmp12_; + GHashTable* result = NULL; + g_return_val_if_fail (IS_TEST (self), NULL); + _tmp0_ = g_strdup ("hello"); + _tmp1_ = g_new0 (gchar*, 1 + 1); + _tmp1_[0] = _tmp0_; + s = _tmp1_; + s_length1 = 1; + _s_size_ = s_length1; + _tmp2_ = g_str_hash; + _tmp3_ = g_hash_table_new_full (_tmp2_, NULL, _g_free0_, _g_variant_unref0_); + nested_dict = _tmp3_; + _tmp4_ = g_strdup ("hello"); + _tmp8_ = _variant_new1 (s, s_length1); + g_hash_table_insert (nested_dict, _tmp4_, _tmp8_); + _tmp9_ = g_str_hash; + _tmp10_ = g_hash_table_new_full (_tmp9_, NULL, _g_free0_, _g_hash_table_unref0_); + dict = _tmp10_; + _tmp11_ = g_strdup ("hello"); + _tmp12_ = _g_hash_table_ref0 (nested_dict); + g_hash_table_insert (dict, _tmp11_, _tmp12_); + result = dict; + _g_hash_table_unref0 (nested_dict); + s = (_vala_array_free (s, s_length1, (GDestroyNotify) g_free), NULL); + return result; +} + +Test* +test_construct (GType object_type) +{ + Test * self = NULL; + self = (Test*) g_object_new (object_type, NULL); + return self; +} + +Test* +test_new (void) +{ + return test_construct (TYPE_TEST); +} + +static void +test_class_init (TestClass * klass, + gpointer klass_data) +{ + test_parent_class = g_type_class_peek_parent (klass); +} + +static void +test_instance_init (Test * self, + gpointer klass) +{ +} + +static GType +test_get_type_once (void) +{ + static const GTypeInfo g_define_type_info = { sizeof (TestClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) test_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (Test), 0, (GInstanceInitFunc) test_instance_init, NULL }; + GType test_type_id; + test_type_id = g_type_register_static (G_TYPE_OBJECT, "Test", &g_define_type_info, 0); + g_type_set_qdata (test_type_id, g_quark_from_static_string ("vala-dbus-register-object"), (void*) test_register_object); + return test_type_id; +} + +GType +test_get_type (void) +{ + static volatile gsize test_type_id__volatile = 0; + if (g_once_init_enter (&test_type_id__volatile)) { + GType test_type_id; + test_type_id = test_get_type_once (); + g_once_init_leave (&test_type_id__volatile, test_type_id); + } + return test_type_id__volatile; +} + +static void +_dbus_test_test_nested_dict (Test* self, + GVariant* _parameters_, + GDBusMethodInvocation* invocation) +{ + GError* error = NULL; + GVariantIter _arguments_iter; + GDBusMessage* _reply_message = NULL; + GVariant* _reply; + GVariantBuilder _reply_builder; + GHashTable* result; + GVariantBuilder _tmp0_; + GHashTableIter _tmp1_; + gpointer _tmp2_; + gpointer _tmp3_; + g_variant_iter_init (&_arguments_iter, _parameters_); + result = test_test_nested_dict (self); + _reply_message = g_dbus_message_new_method_reply (g_dbus_method_invocation_get_message (invocation)); + g_variant_builder_init (&_reply_builder, G_VARIANT_TYPE_TUPLE); + g_hash_table_iter_init (&_tmp1_, result); + g_variant_builder_init (&_tmp0_, G_VARIANT_TYPE ("a{sa{sv}}")); + while (g_hash_table_iter_next (&_tmp1_, &_tmp2_, &_tmp3_)) { + gchar* _key; + GHashTable* _value; + GVariantBuilder _tmp4_; + GHashTableIter _tmp5_; + gpointer _tmp6_; + gpointer _tmp7_; + _key = (gchar*) _tmp2_; + _value = (GHashTable*) _tmp3_; + g_hash_table_iter_init (&_tmp5_, _value); + g_variant_builder_init (&_tmp4_, G_VARIANT_TYPE ("a{sv}")); + while (g_hash_table_iter_next (&_tmp5_, &_tmp6_, &_tmp7_)) { + gchar* _key; + GVariant* _value; + _key = (gchar*) _tmp6_; + _value = (GVariant*) _tmp7_; + g_variant_builder_add (&_tmp4_, "{?*}", g_variant_new_string (_key), g_variant_new_variant (_value)); + } + g_variant_builder_add (&_tmp0_, "{?*}", g_variant_new_string (_key), g_variant_builder_end (&_tmp4_)); + } + g_variant_builder_add_value (&_reply_builder, g_variant_builder_end (&_tmp0_)); + _g_hash_table_unref0 (result); + _reply = g_variant_builder_end (&_reply_builder); + g_dbus_message_set_body (_reply_message, _reply); + g_dbus_connection_send_message (g_dbus_method_invocation_get_connection (invocation), _reply_message, G_DBUS_SEND_MESSAGE_FLAGS_NONE, NULL, NULL); + g_object_unref (invocation); + g_object_unref (_reply_message); +} + +static void +test_dbus_interface_method_call (GDBusConnection* connection, + const gchar* sender, + const gchar* object_path, + const gchar* interface_name, + const gchar* method_name, + GVariant* parameters, + GDBusMethodInvocation* invocation, + gpointer user_data) +{ + gpointer* data; + gpointer object; + data = user_data; + object = data[0]; + if (strcmp (method_name, "TestNestedDict") == 0) { + _dbus_test_test_nested_dict (object, parameters, invocation); + } else { + g_object_unref (invocation); + } +} + +static GVariant* +test_dbus_interface_get_property (GDBusConnection* connection, + const gchar* sender, + const gchar* object_path, + const gchar* interface_name, + const gchar* property_name, + GError** error, + gpointer user_data) +{ + gpointer* data; + gpointer object; + data = user_data; + object = data[0]; + return NULL; +} + +static gboolean +test_dbus_interface_set_property (GDBusConnection* connection, + const gchar* sender, + const gchar* object_path, + const gchar* interface_name, + const gchar* property_name, + GVariant* value, + GError** error, + gpointer user_data) +{ + gpointer* data; + gpointer object; + data = user_data; + object = data[0]; + return FALSE; +} + +guint +test_register_object (gpointer object, + GDBusConnection* connection, + const gchar* path, + GError** error) +{ + guint result; + gpointer *data; + data = g_new (gpointer, 3); + data[0] = g_object_ref (object); + data[1] = g_object_ref (connection); + data[2] = g_strdup (path); + result = g_dbus_connection_register_object (connection, path, (GDBusInterfaceInfo *) (&_test_dbus_interface_info), &_test_dbus_interface_vtable, data, _test_unregister_object, error); + if (!result) { + return 0; + } + return result; +} + +static void +_test_unregister_object (gpointer user_data) +{ + gpointer* data; + data = user_data; + g_object_unref (data[0]); + g_object_unref (data[1]); + g_free (data[2]); + g_free (data); +} + +void +client_exit (GPid pid, + gint status) +{ + GMainLoop* _tmp0_; + _vala_assert (status == 0, "status == 0"); + _tmp0_ = main_loop; + g_main_loop_quit (_tmp0_); +} + +static guint +_variant_get1 (GVariant* value) +{ + return g_variant_get_uint32 (value); +} + +static void +_client_exit_gchild_watch_func (GPid pid, + gint wait_status, + gpointer self) +{ + client_exit (pid, wait_status); +} + +static void +_vala_main (void) +{ + GDBusConnection* conn = NULL; + GDBusConnection* _tmp0_; + GDBusConnection* _tmp1_; + Test* _tmp2_; + Test* _tmp3_; + GVariant* request_result = NULL; + GDBusConnection* _tmp4_; + GVariant* _tmp5_; + GVariant* _tmp6_; + GVariant* _tmp7_; + GVariant* _tmp8_; + GVariant* _tmp9_; + GVariant* _tmp10_; + GVariant* _tmp11_; + guint _tmp12_; + GPid client_pid = 0; + gchar* _tmp13_; + gchar** _tmp14_; + gchar** _tmp15_; + gint _tmp15__length1; + GPid _tmp16_ = 0; + GMainLoop* _tmp17_; + GMainLoop* _tmp18_; + GError* _inner_error0_ = NULL; + _tmp0_ = g_bus_get_sync (G_BUS_TYPE_SESSION, NULL, &_inner_error0_); + conn = _tmp0_; + if (G_UNLIKELY (_inner_error0_ != NULL)) { + g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error0_->message, g_quark_to_string (_inner_error0_->domain), _inner_error0_->code); + g_clear_error (&_inner_error0_); + return; + } + _tmp1_ = conn; + _tmp2_ = test_new (); + _tmp3_ = _tmp2_; + test_register_object (_tmp3_, _tmp1_, "/org/example/test", &_inner_error0_); + _g_object_unref0 (_tmp3_); + if (G_UNLIKELY (_inner_error0_ != NULL)) { + _g_object_unref0 (conn); + g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error0_->message, g_quark_to_string (_inner_error0_->domain), _inner_error0_->code); + g_clear_error (&_inner_error0_); + return; + } + _tmp4_ = conn; + _tmp5_ = g_variant_new ("(su)", "org.example.Test", 0x4, NULL); + g_variant_ref_sink (_tmp5_); + _tmp6_ = _tmp5_; + _tmp7_ = g_dbus_connection_call_sync (_tmp4_, "org.freedesktop.DBus", "/org/freedesktop/DBus", "org.freedesktop.DBus", "RequestName", _tmp6_, NULL, 0, -1, NULL, &_inner_error0_); + _tmp8_ = _tmp7_; + _g_variant_unref0 (_tmp6_); + request_result = _tmp8_; + if (G_UNLIKELY (_inner_error0_ != NULL)) { + _g_object_unref0 (conn); + g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error0_->message, g_quark_to_string (_inner_error0_->domain), _inner_error0_->code); + g_clear_error (&_inner_error0_); + return; + } + _tmp9_ = request_result; + _tmp10_ = g_variant_get_child_value (_tmp9_, (gsize) 0); + _tmp11_ = _tmp10_; + _tmp12_ = _variant_get1 (_tmp11_); + _vala_assert (_tmp12_ == ((guint) 1), "(uint) request_result.get_child_value (0) == 1"); + _g_variant_unref0 (_tmp11_); + _tmp13_ = g_strdup ("dbus_bug782719_client"); + _tmp14_ = g_new0 (gchar*, 1 + 1); + _tmp14_[0] = _tmp13_; + _tmp15_ = _tmp14_; + _tmp15__length1 = 1; + g_spawn_async (NULL, _tmp15_, NULL, G_SPAWN_DO_NOT_REAP_CHILD, NULL, NULL, &_tmp16_, &_inner_error0_); + client_pid = _tmp16_; + _tmp15_ = (_vala_array_free (_tmp15_, _tmp15__length1, (GDestroyNotify) g_free), NULL); + if (G_UNLIKELY (_inner_error0_ != NULL)) { + _g_variant_unref0 (request_result); + _g_object_unref0 (conn); + g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error0_->message, g_quark_to_string (_inner_error0_->domain), _inner_error0_->code); + g_clear_error (&_inner_error0_); + return; + } + g_child_watch_add_full (G_PRIORITY_DEFAULT_IDLE, client_pid, _client_exit_gchild_watch_func, NULL, NULL); + _tmp17_ = g_main_loop_new (NULL, FALSE); + _g_main_loop_unref0 (main_loop); + main_loop = _tmp17_; + _tmp18_ = main_loop; + g_main_loop_run (_tmp18_); + _g_variant_unref0 (request_result); + _g_object_unref0 (conn); +} + +int +main (int argc, + char ** argv) +{ + _vala_main (); + return 0; +} + +static void +_vala_array_destroy (gpointer array, + gssize array_length, + GDestroyNotify destroy_func) +{ + if ((array != NULL) && (destroy_func != NULL)) { + gssize i; + for (i = 0; i < array_length; i = i + 1) { + if (((gpointer*) array)[i] != NULL) { + destroy_func (((gpointer*) array)[i]); + } + } + } +} + +static void +_vala_array_free (gpointer array, + gssize array_length, + GDestroyNotify destroy_func) +{ + _vala_array_destroy (array, array_length, destroy_func); + g_free (array); +} + diff --git a/tests/dbus/bug783002_client.c-expected b/tests/dbus/bug783002_client.c-expected new file mode 100644 index 000000000..f87ad4c6a --- /dev/null +++ b/tests/dbus/bug783002_client.c-expected @@ -0,0 +1,633 @@ +/* dbus_bug783002_client.c generated by valac, the Vala compiler + * generated from dbus_bug783002_client.vala, do not modify */ + +#include <glib-object.h> +#include <gio/gio.h> +#include <stdlib.h> +#include <string.h> +#include <glib.h> + +#if !defined(VALA_EXTERN) +#if defined(_MSC_VER) +#define VALA_EXTERN __declspec(dllexport) extern +#elif __GNUC__ >= 4 +#define VALA_EXTERN __attribute__((visibility("default"))) extern +#else +#define VALA_EXTERN extern +#endif +#endif + +#define TYPE_TEST (test_get_type ()) +#define TEST(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TYPE_TEST, Test)) +#define IS_TEST(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TYPE_TEST)) +#define TEST_GET_INTERFACE(obj) (G_TYPE_INSTANCE_GET_INTERFACE ((obj), TYPE_TEST, TestIface)) + +typedef struct _Test Test; +typedef struct _TestIface TestIface; + +#define TYPE_TEST_PROXY (test_proxy_get_type ()) +typedef GDBusProxy TestProxy; +typedef GDBusProxyClass TestProxyClass; +typedef struct _TestTestArrayLifetimeReadyData TestTestArrayLifetimeReadyData; +#define _g_free0(var) (var = (g_free (var), NULL)) +#define _g_main_loop_unref0(var) ((var == NULL) ? NULL : (var = (g_main_loop_unref (var), NULL))) +#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL))) +typedef struct _RunData RunData; +#define _vala_assert(expr, msg) if G_LIKELY (expr) ; else g_assertion_message_expr (G_LOG_DOMAIN, __FILE__, __LINE__, G_STRFUNC, msg); +#define _vala_return_if_fail(expr, msg) if G_LIKELY (expr) ; else { g_return_if_fail_warning (G_LOG_DOMAIN, G_STRFUNC, msg); return; } +#define _vala_return_val_if_fail(expr, msg, val) if G_LIKELY (expr) ; else { g_return_if_fail_warning (G_LOG_DOMAIN, G_STRFUNC, msg); return val; } +#define _vala_warn_if_fail(expr, msg) if G_LIKELY (expr) ; else g_warn_message (G_LOG_DOMAIN, __FILE__, __LINE__, G_STRFUNC, msg); + +struct _TestIface { + GTypeInterface parent_iface; + void (*test_array_lifetime) (Test* self, gchar** items, gint items_length1, GAsyncReadyCallback _callback_, gpointer _user_data_); + gchar* (*test_array_lifetime_finish) (Test* self, GAsyncResult* _res_, GError** error); +}; + +struct _TestTestArrayLifetimeReadyData { + GDBusMethodInvocation* _invocation_; + gchar** items; + gint items_length1; +}; + +struct _RunData { + int _state_; + GObject* _source_object_; + GAsyncResult* _res_; + GTask* _async_result; + Test* test; + Test* _tmp0_; + gchar* _result_; + Test* _tmp1_; + gchar* _tmp2_; + gchar* _tmp3_; + gchar* _tmp4_; + gchar** _tmp5_; + gchar** _tmp6_; + gint _tmp6__length1; + gchar* _tmp7_; + gchar* _tmp8_; + const gchar* _tmp9_; + GMainLoop* _tmp10_; + GError* _inner_error0_; +}; + +VALA_EXTERN GMainLoop* main_loop; +GMainLoop* main_loop = NULL; + +VALA_EXTERN GType test_proxy_get_type (void) G_GNUC_CONST ; +VALA_EXTERN guint test_register_object (void* object, + GDBusConnection* connection, + const gchar* path, + GError** error); +VALA_EXTERN GType test_get_type (void) G_GNUC_CONST ; +VALA_EXTERN void test_test_array_lifetime (Test* self, + gchar** items, + gint items_length1, + GAsyncReadyCallback _callback_, + gpointer _user_data_); +VALA_EXTERN gchar* test_test_array_lifetime_finish (Test* self, + GAsyncResult* _res_, + GError** error); +static GType test_get_type_once (void); +static void test_proxy_g_signal (GDBusProxy* proxy, + const gchar* sender_name, + const gchar* signal_name, + GVariant* parameters); +static void _vala_g_async_ready_callback (GObject *source_object, + GAsyncResult *res, + void *user_data); +static void test_proxy_test_array_lifetime_async (Test* self, + gchar** items, + gint items_length1, + GAsyncReadyCallback _callback_, + gpointer _user_data_); +static gchar* test_proxy_test_array_lifetime_finish (Test* self, + GAsyncResult* _res_, + GError** error); +static void test_proxy_test_interface_init (TestIface* iface); +static void _dbus_test_test_array_lifetime (Test* self, + GVariant* _parameters_, + GDBusMethodInvocation* invocation); +static void _dbus_test_test_array_lifetime_ready (GObject * source_object, + GAsyncResult * _res_, + gpointer _user_data_); +static void test_dbus_interface_method_call (GDBusConnection* connection, + const gchar* sender, + const gchar* object_path, + const gchar* interface_name, + const gchar* method_name, + GVariant* parameters, + GDBusMethodInvocation* invocation, + gpointer user_data); +static GVariant* test_dbus_interface_get_property (GDBusConnection* connection, + const gchar* sender, + const gchar* object_path, + const gchar* interface_name, + const gchar* property_name, + GError** error, + gpointer user_data); +static gboolean test_dbus_interface_set_property (GDBusConnection* connection, + const gchar* sender, + const gchar* object_path, + const gchar* interface_name, + const gchar* property_name, + GVariant* value, + GError** error, + gpointer user_data); +static void _test_unregister_object (gpointer user_data); +static void _vala_main (void); +VALA_EXTERN void run (GAsyncReadyCallback _callback_, + gpointer _user_data_); +VALA_EXTERN void run_finish (GAsyncResult* _res_); +static void run_data_free (gpointer _data); +static gboolean run_co (RunData* _data_); +static void run_ready (GObject* source_object, + GAsyncResult* _res_, + gpointer _user_data_); +static void _vala_array_destroy (gpointer array, + gssize array_length, + GDestroyNotify destroy_func); +static void _vala_array_free (gpointer array, + gssize array_length, + GDestroyNotify destroy_func); + +static const GDBusArgInfo _test_dbus_arg_info_test_array_lifetime_items = {-1, "items", "as", NULL}; +static const GDBusArgInfo _test_dbus_arg_info_test_array_lifetime_result = {-1, "result", "s", NULL}; +static const GDBusArgInfo * const _test_dbus_arg_info_test_array_lifetime_in[] = {&_test_dbus_arg_info_test_array_lifetime_items, NULL}; +static const GDBusArgInfo * const _test_dbus_arg_info_test_array_lifetime_out[] = {&_test_dbus_arg_info_test_array_lifetime_result, NULL}; +static const GDBusMethodInfo _test_dbus_method_info_test_array_lifetime = {-1, "TestArrayLifetime", (GDBusArgInfo **) (&_test_dbus_arg_info_test_array_lifetime_in), (GDBusArgInfo **) (&_test_dbus_arg_info_test_array_lifetime_out), NULL}; +static const GDBusMethodInfo * const _test_dbus_method_info[] = {&_test_dbus_method_info_test_array_lifetime, NULL}; +static const GDBusSignalInfo * const _test_dbus_signal_info[] = {NULL}; +static const GDBusPropertyInfo * const _test_dbus_property_info[] = {NULL}; +static const GDBusInterfaceInfo _test_dbus_interface_info = {-1, "org.example.Test", (GDBusMethodInfo **) (&_test_dbus_method_info), (GDBusSignalInfo **) (&_test_dbus_signal_info), (GDBusPropertyInfo **) (&_test_dbus_property_info), NULL}; +static const GDBusInterfaceVTable _test_dbus_interface_vtable = {test_dbus_interface_method_call, test_dbus_interface_get_property, test_dbus_interface_set_property}; + +void +test_test_array_lifetime (Test* self, + gchar** items, + gint items_length1, + GAsyncReadyCallback _callback_, + gpointer _user_data_) +{ + TestIface* _iface_; + _iface_ = TEST_GET_INTERFACE (self); + if (_iface_->test_array_lifetime) { + _iface_->test_array_lifetime (self, items, items_length1, _callback_, _user_data_); + } +} + +gchar* +test_test_array_lifetime_finish (Test* self, + GAsyncResult* _res_, + GError** error) +{ + TestIface* _iface_; + _iface_ = TEST_GET_INTERFACE (self); + if (_iface_->test_array_lifetime_finish) { + return _iface_->test_array_lifetime_finish (self, _res_, error); + } + return NULL; +} + +static void +test_default_init (TestIface * iface, + gpointer iface_data) +{ +} + +static GType +test_get_type_once (void) +{ + static const GTypeInfo g_define_type_info = { sizeof (TestIface), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) test_default_init, (GClassFinalizeFunc) NULL, NULL, 0, 0, (GInstanceInitFunc) NULL, NULL }; + GType test_type_id; + test_type_id = g_type_register_static (G_TYPE_INTERFACE, "Test", &g_define_type_info, 0); + g_type_interface_add_prerequisite (test_type_id, G_TYPE_OBJECT); + g_type_set_qdata (test_type_id, g_quark_from_static_string ("vala-dbus-proxy-type"), (void*) test_proxy_get_type); + g_type_set_qdata (test_type_id, g_quark_from_static_string ("vala-dbus-interface-name"), "org.example.Test"); + g_type_set_qdata (test_type_id, g_quark_from_static_string ("vala-dbus-interface-info"), (void*) (&_test_dbus_interface_info)); + g_type_set_qdata (test_type_id, g_quark_from_static_string ("vala-dbus-register-object"), (void*) test_register_object); + return test_type_id; +} + +GType +test_get_type (void) +{ + static volatile gsize test_type_id__volatile = 0; + if (g_once_init_enter (&test_type_id__volatile)) { + GType test_type_id; + test_type_id = test_get_type_once (); + g_once_init_leave (&test_type_id__volatile, test_type_id); + } + return test_type_id__volatile; +} + +G_DEFINE_TYPE_EXTENDED (TestProxy, test_proxy, G_TYPE_DBUS_PROXY, 0, G_IMPLEMENT_INTERFACE (TYPE_TEST, test_proxy_test_interface_init) ) +static void +test_proxy_class_init (TestProxyClass* klass) +{ + G_DBUS_PROXY_CLASS (klass)->g_signal = test_proxy_g_signal; +} + +static void +test_proxy_g_signal (GDBusProxy* proxy, + const gchar* sender_name, + const gchar* signal_name, + GVariant* parameters) +{ +} + +static void +test_proxy_init (TestProxy* self) +{ + g_dbus_proxy_set_interface_info (G_DBUS_PROXY (self), (GDBusInterfaceInfo *) (&_test_dbus_interface_info)); +} + +static void +_vala_g_async_ready_callback (GObject *source_object, + GAsyncResult *res, + void *user_data) +{ + g_task_return_pointer (user_data, g_object_ref (res), g_object_unref); + g_object_unref (user_data); +} + +static void +test_proxy_test_array_lifetime_async (Test* self, + gchar** items, + gint items_length1, + GAsyncReadyCallback _callback_, + gpointer _user_data_) +{ + GDBusMessage *_message; + GVariant *_arguments; + GVariantBuilder _arguments_builder; + gchar** _tmp0_; + GVariantBuilder _tmp1_; + gint _tmp2_; + G_IO_ERROR; + _message = g_dbus_message_new_method_call (g_dbus_proxy_get_name ((GDBusProxy *) self), g_dbus_proxy_get_object_path ((GDBusProxy *) self), "org.example.Test", "TestArrayLifetime"); + g_variant_builder_init (&_arguments_builder, G_VARIANT_TYPE_TUPLE); + _tmp0_ = items; + g_variant_builder_init (&_tmp1_, G_VARIANT_TYPE ("as")); + for (_tmp2_ = 0; _tmp2_ < items_length1; _tmp2_++) { + g_variant_builder_add_value (&_tmp1_, g_variant_new_string (*_tmp0_)); + _tmp0_++; + } + g_variant_builder_add_value (&_arguments_builder, g_variant_builder_end (&_tmp1_)); + _arguments = g_variant_builder_end (&_arguments_builder); + g_dbus_message_set_body (_message, _arguments); + if (_callback_ != NULL) { + g_dbus_connection_send_message_with_reply (g_dbus_proxy_get_connection ((GDBusProxy *) self), _message, G_DBUS_SEND_MESSAGE_FLAGS_NONE, g_dbus_proxy_get_default_timeout ((GDBusProxy *) self), NULL, NULL, _vala_g_async_ready_callback, g_task_new ((GObject *) self, NULL, _callback_, _user_data_)); + } else { + g_dbus_message_set_flags (_message, G_DBUS_MESSAGE_FLAGS_NO_REPLY_EXPECTED); + g_dbus_connection_send_message (g_dbus_proxy_get_connection ((GDBusProxy *) self), _message, G_DBUS_SEND_MESSAGE_FLAGS_NONE, NULL, NULL); + } + g_object_unref (_message); +} + +static gchar* +test_proxy_test_array_lifetime_finish (Test* self, + GAsyncResult* _res_, + GError** error) +{ + GAsyncResult *_inner_res; + GDBusMessage *_reply_message; + GVariant *_reply; + GVariantIter _reply_iter; + gchar* _result = NULL; + GVariant* _tmp3_; + _inner_res = g_task_propagate_pointer ((GTask *) _res_, NULL); + _reply_message = g_dbus_connection_send_message_with_reply_finish (g_dbus_proxy_get_connection ((GDBusProxy *) self), _inner_res, error); + g_object_unref (_inner_res); + if (!_reply_message) { + return NULL; + } + if (g_dbus_message_to_gerror (_reply_message, error)) { + g_object_unref (_reply_message); + return NULL; + } + _reply = g_dbus_message_get_body (_reply_message); + g_variant_iter_init (&_reply_iter, _reply); + _tmp3_ = g_variant_iter_next_value (&_reply_iter); + _result = g_variant_dup_string (_tmp3_, NULL); + g_variant_unref (_tmp3_); + g_object_unref (_reply_message); + return _result; +} + +static void +test_proxy_test_interface_init (TestIface* iface) +{ + iface->test_array_lifetime = test_proxy_test_array_lifetime_async; + iface->test_array_lifetime_finish = test_proxy_test_array_lifetime_finish; +} + +static void +_dbus_test_test_array_lifetime (Test* self, + GVariant* _parameters_, + GDBusMethodInvocation* invocation) +{ + GVariantIter _arguments_iter; + TestTestArrayLifetimeReadyData* _ready_data; + GVariant* _tmp4_; + gchar** _tmp5_; + gint _tmp5__length; + gint _tmp5__size; + gint _tmp5__length1; + GVariantIter _tmp6_; + GVariant* _tmp7_; + g_variant_iter_init (&_arguments_iter, _parameters_); + _ready_data = g_slice_new0 (TestTestArrayLifetimeReadyData); + _ready_data->_invocation_ = invocation; + _tmp4_ = g_variant_iter_next_value (&_arguments_iter); + _tmp5_ = g_new (gchar*, 5); + _tmp5__length = 0; + _tmp5__size = 4; + _tmp5__length1 = 0; + g_variant_iter_init (&_tmp6_, _tmp4_); + for (; (_tmp7_ = g_variant_iter_next_value (&_tmp6_)) != NULL; _tmp5__length1++) { + if (_tmp5__size == _tmp5__length) { + _tmp5__size = 2 * _tmp5__size; + _tmp5_ = g_renew (gchar*, _tmp5_, _tmp5__size + 1); + } + _tmp5_[_tmp5__length++] = g_variant_dup_string (_tmp7_, NULL); + g_variant_unref (_tmp7_); + } + _ready_data->items_length1 = _tmp5__length1; + _tmp5_[_tmp5__length] = NULL; + _ready_data->items = _tmp5_; + g_variant_unref (_tmp4_); + test_test_array_lifetime (self, _ready_data->items, _ready_data->items_length1, (GAsyncReadyCallback) _dbus_test_test_array_lifetime_ready, _ready_data); + _error: + ; +} + +static void +_dbus_test_test_array_lifetime_ready (GObject * source_object, + GAsyncResult * _res_, + gpointer _user_data_) +{ + TestTestArrayLifetimeReadyData* _ready_data; + GDBusMethodInvocation* invocation; + GError* error = NULL; + GDBusMessage* _reply_message = NULL; + GVariant* _reply; + GVariantBuilder _reply_builder; + gchar* result; + _ready_data = _user_data_; + invocation = _ready_data->_invocation_; + result = test_test_array_lifetime_finish ((Test*) source_object, _res_, &error); + if (error) { + g_dbus_method_invocation_return_gerror (invocation, error); + g_error_free (error); + goto _error; + } + _reply_message = g_dbus_message_new_method_reply (g_dbus_method_invocation_get_message (invocation)); + g_variant_builder_init (&_reply_builder, G_VARIANT_TYPE_TUPLE); + g_variant_builder_add_value (&_reply_builder, g_variant_new_string (result)); + _g_free0 (result); + _reply = g_variant_builder_end (&_reply_builder); + g_dbus_message_set_body (_reply_message, _reply); + g_dbus_connection_send_message (g_dbus_method_invocation_get_connection (invocation), _reply_message, G_DBUS_SEND_MESSAGE_FLAGS_NONE, NULL, NULL); + g_object_unref (invocation); + g_object_unref (_reply_message); + _error: + _ready_data->items = (_vala_array_free (_ready_data->items, _ready_data->items_length1, (GDestroyNotify) g_free), NULL); + g_slice_free (TestTestArrayLifetimeReadyData, _ready_data); +} + +static void +test_dbus_interface_method_call (GDBusConnection* connection, + const gchar* sender, + const gchar* object_path, + const gchar* interface_name, + const gchar* method_name, + GVariant* parameters, + GDBusMethodInvocation* invocation, + gpointer user_data) +{ + gpointer* data; + gpointer object; + data = user_data; + object = data[0]; + if (strcmp (method_name, "TestArrayLifetime") == 0) { + _dbus_test_test_array_lifetime (object, parameters, invocation); + } else { + g_object_unref (invocation); + } +} + +static GVariant* +test_dbus_interface_get_property (GDBusConnection* connection, + const gchar* sender, + const gchar* object_path, + const gchar* interface_name, + const gchar* property_name, + GError** error, + gpointer user_data) +{ + gpointer* data; + gpointer object; + data = user_data; + object = data[0]; + return NULL; +} + +static gboolean +test_dbus_interface_set_property (GDBusConnection* connection, + const gchar* sender, + const gchar* object_path, + const gchar* interface_name, + const gchar* property_name, + GVariant* value, + GError** error, + gpointer user_data) +{ + gpointer* data; + gpointer object; + data = user_data; + object = data[0]; + return FALSE; +} + +guint +test_register_object (gpointer object, + GDBusConnection* connection, + const gchar* path, + GError** error) +{ + guint result; + gpointer *data; + data = g_new (gpointer, 3); + data[0] = g_object_ref (object); + data[1] = g_object_ref (connection); + data[2] = g_strdup (path); + result = g_dbus_connection_register_object (connection, path, (GDBusInterfaceInfo *) (&_test_dbus_interface_info), &_test_dbus_interface_vtable, data, _test_unregister_object, error); + if (!result) { + return 0; + } + return result; +} + +static void +_test_unregister_object (gpointer user_data) +{ + gpointer* data; + data = user_data; + g_object_unref (data[0]); + g_object_unref (data[1]); + g_free (data[2]); + g_free (data); +} + +static void +_vala_main (void) +{ + GMainLoop* _tmp0_; + GMainLoop* _tmp1_; + _tmp0_ = g_main_loop_new (NULL, FALSE); + _g_main_loop_unref0 (main_loop); + main_loop = _tmp0_; + run (NULL, NULL); + _tmp1_ = main_loop; + g_main_loop_run (_tmp1_); +} + +int +main (int argc, + char ** argv) +{ + _vala_main (); + return 0; +} + +static void +run_data_free (gpointer _data) +{ + RunData* _data_; + _data_ = _data; + g_slice_free (RunData, _data_); +} + +void +run (GAsyncReadyCallback _callback_, + gpointer _user_data_) +{ + RunData* _data_; + _data_ = g_slice_new0 (RunData); + _data_->_async_result = g_task_new (NULL, NULL, _callback_, _user_data_); + g_task_set_task_data (_data_->_async_result, _data_, run_data_free); + run_co (_data_); +} + +void +run_finish (GAsyncResult* _res_) +{ + RunData* _data_; + _data_ = g_task_propagate_pointer (G_TASK (_res_), NULL); +} + +static void +run_ready (GObject* source_object, + GAsyncResult* _res_, + gpointer _user_data_) +{ + RunData* _data_; + _data_ = _user_data_; + _data_->_source_object_ = source_object; + _data_->_res_ = _res_; + run_co (_data_); +} + +static gboolean +run_co (RunData* _data_) +{ + switch (_data_->_state_) { + case 0: + goto _state_0; + case 1: + goto _state_1; + case 2: + goto _state_2; + default: + g_assert_not_reached (); + } + _state_0: + _data_->_state_ = 1; + g_async_initable_new_async (TYPE_TEST_PROXY, 0, NULL, run_ready, _data_, "g-flags", 0, "g-name", "org.example.Test", "g-bus-type", G_BUS_TYPE_SESSION, "g-object-path", "/org/example/test", "g-interface-name", "org.example.Test", NULL); + return FALSE; + _state_1: + _data_->_tmp0_ = (Test*) g_async_initable_new_finish ((GAsyncInitable *) _data_->_source_object_, _data_->_res_, &_data_->_inner_error0_); + _data_->test = (Test*) _data_->_tmp0_; + if (G_UNLIKELY (_data_->_inner_error0_ != NULL)) { + g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _data_->_inner_error0_->message, g_quark_to_string (_data_->_inner_error0_->domain), _data_->_inner_error0_->code); + g_clear_error (&_data_->_inner_error0_); + g_object_unref (_data_->_async_result); + return FALSE; + } + _data_->_tmp1_ = _data_->test; + _data_->_tmp2_ = g_strdup ("Badger"); + _data_->_tmp3_ = g_strdup ("Snake"); + _data_->_tmp4_ = g_strdup ("Mushroom"); + _data_->_tmp5_ = g_new0 (gchar*, 3 + 1); + _data_->_tmp5_[0] = _data_->_tmp2_; + _data_->_tmp5_[1] = _data_->_tmp3_; + _data_->_tmp5_[2] = _data_->_tmp4_; + _data_->_tmp6_ = _data_->_tmp5_; + _data_->_tmp6__length1 = 3; + _data_->_state_ = 2; + test_test_array_lifetime (_data_->_tmp1_, _data_->_tmp6_, (gint) 3, run_ready, _data_); + return FALSE; + _state_2: + _data_->_tmp7_ = test_test_array_lifetime_finish (_data_->_tmp1_, _data_->_res_, &_data_->_inner_error0_); + _data_->_tmp8_ = _data_->_tmp7_; + _data_->_tmp6_ = (_vala_array_free (_data_->_tmp6_, _data_->_tmp6__length1, (GDestroyNotify) g_free), NULL); + _data_->_result_ = _data_->_tmp8_; + if (G_UNLIKELY (_data_->_inner_error0_ != NULL)) { + _g_object_unref0 (_data_->test); + g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _data_->_inner_error0_->message, g_quark_to_string (_data_->_inner_error0_->domain), _data_->_inner_error0_->code); + g_clear_error (&_data_->_inner_error0_); + g_object_unref (_data_->_async_result); + return FALSE; + } + _data_->_tmp9_ = _data_->_result_; + _vala_assert (g_strcmp0 (_data_->_tmp9_, "BadgerSnakeMushroom") == 0, "result == \"BadgerSnakeMushroom\""); + _data_->_tmp10_ = main_loop; + g_main_loop_quit (_data_->_tmp10_); + _g_free0 (_data_->_result_); + _g_object_unref0 (_data_->test); + g_task_return_pointer (_data_->_async_result, _data_, NULL); + if (_data_->_state_ != 0) { + while (!g_task_get_completed (_data_->_async_result)) { + g_main_context_iteration (g_task_get_context (_data_->_async_result), TRUE); + } + } + g_object_unref (_data_->_async_result); + return FALSE; +} + +static void +_vala_array_destroy (gpointer array, + gssize array_length, + GDestroyNotify destroy_func) +{ + if ((array != NULL) && (destroy_func != NULL)) { + gssize i; + for (i = 0; i < array_length; i = i + 1) { + if (((gpointer*) array)[i] != NULL) { + destroy_func (((gpointer*) array)[i]); + } + } + } +} + +static void +_vala_array_free (gpointer array, + gssize array_length, + GDestroyNotify destroy_func) +{ + _vala_array_destroy (array, array_length, destroy_func); + g_free (array); +} + diff --git a/tests/dbus/bug783002_server.c-expected b/tests/dbus/bug783002_server.c-expected new file mode 100644 index 000000000..3b2a6e4a0 --- /dev/null +++ b/tests/dbus/bug783002_server.c-expected @@ -0,0 +1,680 @@ +/* dbus_bug783002_server.c generated by valac, the Vala compiler + * generated from dbus_bug783002_server.vala, do not modify */ + +#include <glib-object.h> +#include <gio/gio.h> +#include <stdlib.h> +#include <string.h> +#include <glib.h> + +#if !defined(VALA_EXTERN) +#if defined(_MSC_VER) +#define VALA_EXTERN __declspec(dllexport) extern +#elif __GNUC__ >= 4 +#define VALA_EXTERN __attribute__((visibility("default"))) extern +#else +#define VALA_EXTERN extern +#endif +#endif + +#define TYPE_TEST (test_get_type ()) +#define TEST(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TYPE_TEST, Test)) +#define TEST_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), TYPE_TEST, TestClass)) +#define IS_TEST(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TYPE_TEST)) +#define IS_TEST_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), TYPE_TEST)) +#define TEST_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), TYPE_TEST, TestClass)) + +typedef struct _Test Test; +typedef struct _TestClass TestClass; +typedef struct _TestPrivate TestPrivate; +enum { + TEST_0_PROPERTY, + TEST_NUM_PROPERTIES +}; +static GParamSpec* test_properties[TEST_NUM_PROPERTIES]; +#define _g_free0(var) (var = (g_free (var), NULL)) +#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL))) +typedef struct _Block1Data Block1Data; +#define _g_string_free0(var) ((var == NULL) ? NULL : (var = (g_string_free (var, TRUE), NULL))) +typedef struct _TestTestArrayLifetimeData TestTestArrayLifetimeData; +typedef struct _TestTestArrayLifetimeReadyData TestTestArrayLifetimeReadyData; +#define _g_variant_unref0(var) ((var == NULL) ? NULL : (var = (g_variant_unref (var), NULL))) +#define _g_main_loop_unref0(var) ((var == NULL) ? NULL : (var = (g_main_loop_unref (var), NULL))) +#define _vala_assert(expr, msg) if G_LIKELY (expr) ; else g_assertion_message_expr (G_LOG_DOMAIN, __FILE__, __LINE__, G_STRFUNC, msg); +#define _vala_return_if_fail(expr, msg) if G_LIKELY (expr) ; else { g_return_if_fail_warning (G_LOG_DOMAIN, G_STRFUNC, msg); return; } +#define _vala_return_val_if_fail(expr, msg, val) if G_LIKELY (expr) ; else { g_return_if_fail_warning (G_LOG_DOMAIN, G_STRFUNC, msg); return val; } +#define _vala_warn_if_fail(expr, msg) if G_LIKELY (expr) ; else g_warn_message (G_LOG_DOMAIN, __FILE__, __LINE__, G_STRFUNC, msg); + +struct _Test { + GObject parent_instance; + TestPrivate * priv; +}; + +struct _TestClass { + GObjectClass parent_class; +}; + +struct _Block1Data { + int _ref_count_; + Test* self; + gpointer _async_data_; +}; + +struct _TestTestArrayLifetimeData { + int _state_; + GObject* _source_object_; + GAsyncResult* _res_; + GTask* _async_result; + Test* self; + gchar** items; + gint items_length1; + gchar* result; + Block1Data* _data1_; + GString* _result_; + GString* _tmp0_; + gchar** item_collection; + gint item_collection_length1; + gint _item_collection_size_; + gint item_it; + gchar* _tmp1_; + gchar* item; + GString* _tmp2_; + const gchar* _tmp3_; + GString* _tmp4_; + const gchar* _tmp5_; + GString* _tmp6_; + const gchar* _tmp7_; + gchar* _tmp8_; +}; + +struct _TestTestArrayLifetimeReadyData { + GDBusMethodInvocation* _invocation_; + gchar** items; + gint items_length1; +}; + +static gpointer test_parent_class = NULL; +VALA_EXTERN GMainLoop* main_loop; +GMainLoop* main_loop = NULL; + +VALA_EXTERN GType test_get_type (void) G_GNUC_CONST ; +G_DEFINE_AUTOPTR_CLEANUP_FUNC (Test, g_object_unref) +VALA_EXTERN guint test_register_object (void* object, + GDBusConnection* connection, + const gchar* path, + GError** error); +static void test_test_array_lifetime_data_free (gpointer _data); +VALA_EXTERN void test_test_array_lifetime (Test* self, + gchar** items, + gint items_length1, + GAsyncReadyCallback _callback_, + gpointer _user_data_); +VALA_EXTERN gchar* test_test_array_lifetime_finish (Test* self, + GAsyncResult* _res_, + GError** error); +static gboolean test_test_array_lifetime_co (TestTestArrayLifetimeData* _data_); +static Block1Data* block1_data_ref (Block1Data* _data1_); +static void block1_data_unref (void * _userdata_); +static gboolean __lambda4_ (Block1Data* _data1_); +static gboolean ___lambda4__gsource_func (gpointer self); +VALA_EXTERN Test* test_new (void); +VALA_EXTERN Test* test_construct (GType object_type); +static GType test_get_type_once (void); +static void _dbus_test_test_array_lifetime (Test* self, + GVariant* _parameters_, + GDBusMethodInvocation* invocation); +static void _dbus_test_test_array_lifetime_ready (GObject * source_object, + GAsyncResult * _res_, + gpointer _user_data_); +static void test_dbus_interface_method_call (GDBusConnection* connection, + const gchar* sender, + const gchar* object_path, + const gchar* interface_name, + const gchar* method_name, + GVariant* parameters, + GDBusMethodInvocation* invocation, + gpointer user_data); +static GVariant* test_dbus_interface_get_property (GDBusConnection* connection, + const gchar* sender, + const gchar* object_path, + const gchar* interface_name, + const gchar* property_name, + GError** error, + gpointer user_data); +static gboolean test_dbus_interface_set_property (GDBusConnection* connection, + const gchar* sender, + const gchar* object_path, + const gchar* interface_name, + const gchar* property_name, + GVariant* value, + GError** error, + gpointer user_data); +static void _test_unregister_object (gpointer user_data); +VALA_EXTERN void on_client_exit (GPid pid, + gint status); +static void _vala_main (void); +static guint _variant_get1 (GVariant* value); +static void _on_client_exit_gchild_watch_func (GPid pid, + gint wait_status, + gpointer self); +static void _vala_array_destroy (gpointer array, + gssize array_length, + GDestroyNotify destroy_func); +static void _vala_array_free (gpointer array, + gssize array_length, + GDestroyNotify destroy_func); + +static const GDBusArgInfo _test_dbus_arg_info_test_array_lifetime_items = {-1, "items", "as", NULL}; +static const GDBusArgInfo _test_dbus_arg_info_test_array_lifetime_result = {-1, "result", "s", NULL}; +static const GDBusArgInfo * const _test_dbus_arg_info_test_array_lifetime_in[] = {&_test_dbus_arg_info_test_array_lifetime_items, NULL}; +static const GDBusArgInfo * const _test_dbus_arg_info_test_array_lifetime_out[] = {&_test_dbus_arg_info_test_array_lifetime_result, NULL}; +static const GDBusMethodInfo _test_dbus_method_info_test_array_lifetime = {-1, "TestArrayLifetime", (GDBusArgInfo **) (&_test_dbus_arg_info_test_array_lifetime_in), (GDBusArgInfo **) (&_test_dbus_arg_info_test_array_lifetime_out), NULL}; +static const GDBusMethodInfo * const _test_dbus_method_info[] = {&_test_dbus_method_info_test_array_lifetime, NULL}; +static const GDBusSignalInfo * const _test_dbus_signal_info[] = {NULL}; +static const GDBusPropertyInfo * const _test_dbus_property_info[] = {NULL}; +static const GDBusInterfaceInfo _test_dbus_interface_info = {-1, "org.example.Test", (GDBusMethodInfo **) (&_test_dbus_method_info), (GDBusSignalInfo **) (&_test_dbus_signal_info), (GDBusPropertyInfo **) (&_test_dbus_property_info), NULL}; +static const GDBusInterfaceVTable _test_dbus_interface_vtable = {test_dbus_interface_method_call, test_dbus_interface_get_property, test_dbus_interface_set_property}; + +static void +test_test_array_lifetime_data_free (gpointer _data) +{ + TestTestArrayLifetimeData* _data_; + _data_ = _data; + _g_free0 (_data_->result); + _g_object_unref0 (_data_->self); + g_slice_free (TestTestArrayLifetimeData, _data_); +} + +static gpointer +_g_object_ref0 (gpointer self) +{ + return self ? g_object_ref (self) : NULL; +} + +void +test_test_array_lifetime (Test* self, + gchar** items, + gint items_length1, + GAsyncReadyCallback _callback_, + gpointer _user_data_) +{ + TestTestArrayLifetimeData* _data_; + Test* _tmp0_; + g_return_if_fail (IS_TEST (self)); + _data_ = g_slice_new0 (TestTestArrayLifetimeData); + _data_->_async_result = g_task_new (G_OBJECT (self), NULL, _callback_, _user_data_); + g_task_set_task_data (_data_->_async_result, _data_, test_test_array_lifetime_data_free); + _tmp0_ = _g_object_ref0 (self); + _data_->self = _tmp0_; + _data_->items = items; + _data_->items_length1 = items_length1; + test_test_array_lifetime_co (_data_); +} + +gchar* +test_test_array_lifetime_finish (Test* self, + GAsyncResult* _res_, + GError** error) +{ + gchar* result; + TestTestArrayLifetimeData* _data_; + _data_ = g_task_propagate_pointer (G_TASK (_res_), error); + if (NULL == _data_) { + return NULL; + } + result = _data_->result; + _data_->result = NULL; + return result; +} + +static Block1Data* +block1_data_ref (Block1Data* _data1_) +{ + g_atomic_int_inc (&_data1_->_ref_count_); + return _data1_; +} + +static void +block1_data_unref (void * _userdata_) +{ + Block1Data* _data1_; + _data1_ = (Block1Data*) _userdata_; + if (g_atomic_int_dec_and_test (&_data1_->_ref_count_)) { + Test* self; + self = _data1_->self; + _g_object_unref0 (self); + g_slice_free (Block1Data, _data1_); + } +} + +static gboolean +__lambda4_ (Block1Data* _data1_) +{ + Test* self; + gboolean result = FALSE; + self = _data1_->self; + test_test_array_lifetime_co (_data1_->_async_data_); + result = FALSE; + return result; +} + +static gboolean +___lambda4__gsource_func (gpointer self) +{ + gboolean result; + result = __lambda4_ (self); + return result; +} + +static gboolean +test_test_array_lifetime_co (TestTestArrayLifetimeData* _data_) +{ + switch (_data_->_state_) { + case 0: + goto _state_0; + case 1: + goto _state_1; + default: + g_assert_not_reached (); + } + _state_0: + _data_->_data1_ = g_slice_new0 (Block1Data); + _data_->_data1_->_ref_count_ = 1; + _data_->_data1_->self = g_object_ref (_data_->self); + _data_->_data1_->_async_data_ = _data_; + g_idle_add_full (G_PRIORITY_DEFAULT_IDLE, ___lambda4__gsource_func, block1_data_ref (_data_->_data1_), block1_data_unref); + _data_->_state_ = 1; + return FALSE; + _state_1: + ; + _data_->_tmp0_ = g_string_new (""); + _data_->_result_ = _data_->_tmp0_; + { + _data_->item_collection_length1 = 0; + _data_->_item_collection_size_ = 0; + _data_->item_collection = _data_->items; + _data_->item_collection_length1 = _data_->items_length1; + for (_data_->item_it = 0; _data_->item_it < _data_->item_collection_length1; _data_->item_it = _data_->item_it + 1) { + _data_->_tmp1_ = g_strdup (_data_->item_collection[_data_->item_it]); + _data_->item = _data_->_tmp1_; + { + _data_->_tmp2_ = _data_->_result_; + _data_->_tmp3_ = _data_->item; + g_string_append (_data_->_tmp2_, _data_->_tmp3_); + _g_free0 (_data_->item); + } + } + } + _data_->_tmp4_ = _data_->_result_; + _data_->_tmp5_ = _data_->_tmp4_->str; + _vala_assert (g_strcmp0 (_data_->_tmp5_, "BadgerSnakeMushroom") == 0, "result.str == \"BadgerSnakeMushroom\""); + _data_->_tmp6_ = _data_->_result_; + _data_->_tmp7_ = _data_->_tmp6_->str; + _data_->_tmp8_ = g_strdup (_data_->_tmp7_); + _data_->result = _data_->_tmp8_; + _g_string_free0 (_data_->_result_); + block1_data_unref (_data_->_data1_); + _data_->_data1_ = NULL; + g_task_return_pointer (_data_->_async_result, _data_, NULL); + if (_data_->_state_ != 0) { + while (!g_task_get_completed (_data_->_async_result)) { + g_main_context_iteration (g_task_get_context (_data_->_async_result), TRUE); + } + } + g_object_unref (_data_->_async_result); + return FALSE; +} + +Test* +test_construct (GType object_type) +{ + Test * self = NULL; + self = (Test*) g_object_new (object_type, NULL); + return self; +} + +Test* +test_new (void) +{ + return test_construct (TYPE_TEST); +} + +static void +test_class_init (TestClass * klass, + gpointer klass_data) +{ + test_parent_class = g_type_class_peek_parent (klass); +} + +static void +test_instance_init (Test * self, + gpointer klass) +{ +} + +static GType +test_get_type_once (void) +{ + static const GTypeInfo g_define_type_info = { sizeof (TestClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) test_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (Test), 0, (GInstanceInitFunc) test_instance_init, NULL }; + GType test_type_id; + test_type_id = g_type_register_static (G_TYPE_OBJECT, "Test", &g_define_type_info, 0); + g_type_set_qdata (test_type_id, g_quark_from_static_string ("vala-dbus-register-object"), (void*) test_register_object); + return test_type_id; +} + +GType +test_get_type (void) +{ + static volatile gsize test_type_id__volatile = 0; + if (g_once_init_enter (&test_type_id__volatile)) { + GType test_type_id; + test_type_id = test_get_type_once (); + g_once_init_leave (&test_type_id__volatile, test_type_id); + } + return test_type_id__volatile; +} + +static void +_dbus_test_test_array_lifetime (Test* self, + GVariant* _parameters_, + GDBusMethodInvocation* invocation) +{ + GVariantIter _arguments_iter; + TestTestArrayLifetimeReadyData* _ready_data; + GVariant* _tmp0_; + gchar** _tmp1_; + gint _tmp1__length; + gint _tmp1__size; + gint _tmp1__length1; + GVariantIter _tmp2_; + GVariant* _tmp3_; + g_variant_iter_init (&_arguments_iter, _parameters_); + _ready_data = g_slice_new0 (TestTestArrayLifetimeReadyData); + _ready_data->_invocation_ = invocation; + _tmp0_ = g_variant_iter_next_value (&_arguments_iter); + _tmp1_ = g_new (gchar*, 5); + _tmp1__length = 0; + _tmp1__size = 4; + _tmp1__length1 = 0; + g_variant_iter_init (&_tmp2_, _tmp0_); + for (; (_tmp3_ = g_variant_iter_next_value (&_tmp2_)) != NULL; _tmp1__length1++) { + if (_tmp1__size == _tmp1__length) { + _tmp1__size = 2 * _tmp1__size; + _tmp1_ = g_renew (gchar*, _tmp1_, _tmp1__size + 1); + } + _tmp1_[_tmp1__length++] = g_variant_dup_string (_tmp3_, NULL); + g_variant_unref (_tmp3_); + } + _ready_data->items_length1 = _tmp1__length1; + _tmp1_[_tmp1__length] = NULL; + _ready_data->items = _tmp1_; + g_variant_unref (_tmp0_); + test_test_array_lifetime (self, _ready_data->items, _ready_data->items_length1, (GAsyncReadyCallback) _dbus_test_test_array_lifetime_ready, _ready_data); + _error: + ; +} + +static void +_dbus_test_test_array_lifetime_ready (GObject * source_object, + GAsyncResult * _res_, + gpointer _user_data_) +{ + TestTestArrayLifetimeReadyData* _ready_data; + GDBusMethodInvocation* invocation; + GError* error = NULL; + GDBusMessage* _reply_message = NULL; + GVariant* _reply; + GVariantBuilder _reply_builder; + gchar* result; + _ready_data = _user_data_; + invocation = _ready_data->_invocation_; + result = test_test_array_lifetime_finish ((Test*) source_object, _res_, &error); + if (error) { + g_dbus_method_invocation_return_gerror (invocation, error); + g_error_free (error); + goto _error; + } + _reply_message = g_dbus_message_new_method_reply (g_dbus_method_invocation_get_message (invocation)); + g_variant_builder_init (&_reply_builder, G_VARIANT_TYPE_TUPLE); + g_variant_builder_add_value (&_reply_builder, g_variant_new_string (result)); + _g_free0 (result); + _reply = g_variant_builder_end (&_reply_builder); + g_dbus_message_set_body (_reply_message, _reply); + g_dbus_connection_send_message (g_dbus_method_invocation_get_connection (invocation), _reply_message, G_DBUS_SEND_MESSAGE_FLAGS_NONE, NULL, NULL); + g_object_unref (invocation); + g_object_unref (_reply_message); + _error: + _ready_data->items = (_vala_array_free (_ready_data->items, _ready_data->items_length1, (GDestroyNotify) g_free), NULL); + g_slice_free (TestTestArrayLifetimeReadyData, _ready_data); +} + +static void +test_dbus_interface_method_call (GDBusConnection* connection, + const gchar* sender, + const gchar* object_path, + const gchar* interface_name, + const gchar* method_name, + GVariant* parameters, + GDBusMethodInvocation* invocation, + gpointer user_data) +{ + gpointer* data; + gpointer object; + data = user_data; + object = data[0]; + if (strcmp (method_name, "TestArrayLifetime") == 0) { + _dbus_test_test_array_lifetime (object, parameters, invocation); + } else { + g_object_unref (invocation); + } +} + +static GVariant* +test_dbus_interface_get_property (GDBusConnection* connection, + const gchar* sender, + const gchar* object_path, + const gchar* interface_name, + const gchar* property_name, + GError** error, + gpointer user_data) +{ + gpointer* data; + gpointer object; + data = user_data; + object = data[0]; + return NULL; +} + +static gboolean +test_dbus_interface_set_property (GDBusConnection* connection, + const gchar* sender, + const gchar* object_path, + const gchar* interface_name, + const gchar* property_name, + GVariant* value, + GError** error, + gpointer user_data) +{ + gpointer* data; + gpointer object; + data = user_data; + object = data[0]; + return FALSE; +} + +guint +test_register_object (gpointer object, + GDBusConnection* connection, + const gchar* path, + GError** error) +{ + guint result; + gpointer *data; + data = g_new (gpointer, 3); + data[0] = g_object_ref (object); + data[1] = g_object_ref (connection); + data[2] = g_strdup (path); + result = g_dbus_connection_register_object (connection, path, (GDBusInterfaceInfo *) (&_test_dbus_interface_info), &_test_dbus_interface_vtable, data, _test_unregister_object, error); + if (!result) { + return 0; + } + return result; +} + +static void +_test_unregister_object (gpointer user_data) +{ + gpointer* data; + data = user_data; + g_object_unref (data[0]); + g_object_unref (data[1]); + g_free (data[2]); + g_free (data); +} + +void +on_client_exit (GPid pid, + gint status) +{ + GMainLoop* _tmp0_; + _vala_assert (status == 0, "status == 0"); + _tmp0_ = main_loop; + g_main_loop_quit (_tmp0_); +} + +static guint +_variant_get1 (GVariant* value) +{ + return g_variant_get_uint32 (value); +} + +static void +_on_client_exit_gchild_watch_func (GPid pid, + gint wait_status, + gpointer self) +{ + on_client_exit (pid, wait_status); +} + +static void +_vala_main (void) +{ + GDBusConnection* conn = NULL; + GDBusConnection* _tmp0_; + GDBusConnection* _tmp1_; + Test* _tmp2_; + Test* _tmp3_; + GVariant* request_result = NULL; + GDBusConnection* _tmp4_; + GVariant* _tmp5_; + GVariant* _tmp6_; + GVariant* _tmp7_; + GVariant* _tmp8_; + GVariant* _tmp9_; + GVariant* _tmp10_; + GVariant* _tmp11_; + guint _tmp12_; + GPid client_pid = 0; + gchar* _tmp13_; + gchar** _tmp14_; + gchar** _tmp15_; + gint _tmp15__length1; + GPid _tmp16_ = 0; + GMainLoop* _tmp17_; + GMainLoop* _tmp18_; + GError* _inner_error0_ = NULL; + _tmp0_ = g_bus_get_sync (G_BUS_TYPE_SESSION, NULL, &_inner_error0_); + conn = _tmp0_; + if (G_UNLIKELY (_inner_error0_ != NULL)) { + g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error0_->message, g_quark_to_string (_inner_error0_->domain), _inner_error0_->code); + g_clear_error (&_inner_error0_); + return; + } + _tmp1_ = conn; + _tmp2_ = test_new (); + _tmp3_ = _tmp2_; + test_register_object (_tmp3_, _tmp1_, "/org/example/test", &_inner_error0_); + _g_object_unref0 (_tmp3_); + if (G_UNLIKELY (_inner_error0_ != NULL)) { + _g_object_unref0 (conn); + g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error0_->message, g_quark_to_string (_inner_error0_->domain), _inner_error0_->code); + g_clear_error (&_inner_error0_); + return; + } + _tmp4_ = conn; + _tmp5_ = g_variant_new ("(su)", "org.example.Test", 0x4, NULL); + g_variant_ref_sink (_tmp5_); + _tmp6_ = _tmp5_; + _tmp7_ = g_dbus_connection_call_sync (_tmp4_, "org.freedesktop.DBus", "/org/freedesktop/DBus", "org.freedesktop.DBus", "RequestName", _tmp6_, NULL, 0, -1, NULL, &_inner_error0_); + _tmp8_ = _tmp7_; + _g_variant_unref0 (_tmp6_); + request_result = _tmp8_; + if (G_UNLIKELY (_inner_error0_ != NULL)) { + _g_object_unref0 (conn); + g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error0_->message, g_quark_to_string (_inner_error0_->domain), _inner_error0_->code); + g_clear_error (&_inner_error0_); + return; + } + _tmp9_ = request_result; + _tmp10_ = g_variant_get_child_value (_tmp9_, (gsize) 0); + _tmp11_ = _tmp10_; + _tmp12_ = _variant_get1 (_tmp11_); + _vala_assert (_tmp12_ == ((guint) 1), "(uint) request_result.get_child_value (0) == 1"); + _g_variant_unref0 (_tmp11_); + _tmp13_ = g_strdup ("dbus_bug783002_client"); + _tmp14_ = g_new0 (gchar*, 1 + 1); + _tmp14_[0] = _tmp13_; + _tmp15_ = _tmp14_; + _tmp15__length1 = 1; + g_spawn_async (NULL, _tmp15_, NULL, G_SPAWN_DO_NOT_REAP_CHILD, NULL, NULL, &_tmp16_, &_inner_error0_); + client_pid = _tmp16_; + _tmp15_ = (_vala_array_free (_tmp15_, _tmp15__length1, (GDestroyNotify) g_free), NULL); + if (G_UNLIKELY (_inner_error0_ != NULL)) { + _g_variant_unref0 (request_result); + _g_object_unref0 (conn); + g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error0_->message, g_quark_to_string (_inner_error0_->domain), _inner_error0_->code); + g_clear_error (&_inner_error0_); + return; + } + g_child_watch_add_full (G_PRIORITY_DEFAULT_IDLE, client_pid, _on_client_exit_gchild_watch_func, NULL, NULL); + _tmp17_ = g_main_loop_new (NULL, FALSE); + _g_main_loop_unref0 (main_loop); + main_loop = _tmp17_; + _tmp18_ = main_loop; + g_main_loop_run (_tmp18_); + _g_variant_unref0 (request_result); + _g_object_unref0 (conn); +} + +int +main (int argc, + char ** argv) +{ + _vala_main (); + return 0; +} + +static void +_vala_array_destroy (gpointer array, + gssize array_length, + GDestroyNotify destroy_func) +{ + if ((array != NULL) && (destroy_func != NULL)) { + gssize i; + for (i = 0; i < array_length; i = i + 1) { + if (((gpointer*) array)[i] != NULL) { + destroy_func (((gpointer*) array)[i]); + } + } + } +} + +static void +_vala_array_free (gpointer array, + gssize array_length, + GDestroyNotify destroy_func) +{ + _vala_array_destroy (array, array_length, destroy_func); + g_free (array); +} + diff --git a/tests/dbus/bug792277.c-expected b/tests/dbus/bug792277.c-expected new file mode 100644 index 000000000..63cea38d3 --- /dev/null +++ b/tests/dbus/bug792277.c-expected @@ -0,0 +1,712 @@ +/* dbus_bug792277.c generated by valac, the Vala compiler + * generated from dbus_bug792277.vala, do not modify */ + +#include <glib-object.h> +#include <gio/gio.h> +#include <glib.h> +#include <string.h> + +#if !defined(VALA_EXTERN) +#if defined(_MSC_VER) +#define VALA_EXTERN __declspec(dllexport) extern +#elif __GNUC__ >= 4 +#define VALA_EXTERN __attribute__((visibility("default"))) extern +#else +#define VALA_EXTERN extern +#endif +#endif + +#define TYPE_IFOO (ifoo_get_type ()) +#define IFOO(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TYPE_IFOO, IFoo)) +#define IS_IFOO(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TYPE_IFOO)) +#define IFOO_GET_INTERFACE(obj) (G_TYPE_INSTANCE_GET_INTERFACE ((obj), TYPE_IFOO, IFooIface)) + +typedef struct _IFoo IFoo; +typedef struct _IFooIface IFooIface; + +#define TYPE_IFOO_PROXY (ifoo_proxy_get_type ()) +typedef GDBusProxy IFooProxy; +typedef GDBusProxyClass IFooProxyClass; + +#define TYPE_FOO (foo_get_type ()) +#define FOO(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TYPE_FOO, Foo)) +#define FOO_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), TYPE_FOO, FooClass)) +#define IS_FOO(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TYPE_FOO)) +#define IS_FOO_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), TYPE_FOO)) +#define FOO_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), TYPE_FOO, FooClass)) + +typedef struct _Foo Foo; +typedef struct _FooClass FooClass; +typedef struct _FooPrivate FooPrivate; +enum { + FOO_0_PROPERTY, + FOO_NUM_PROPERTIES +}; +static GParamSpec* foo_properties[FOO_NUM_PROPERTIES]; + +struct _IFooIface { + GTypeInterface parent_iface; + void (*method0) (IFoo* self, GError** error); + void (*method1) (IFoo* self, GError** error); + void (*method2) (IFoo* self); +}; + +struct _Foo { + GObject parent_instance; + FooPrivate * priv; +}; + +struct _FooClass { + GObjectClass parent_class; +}; + +static gpointer foo_parent_class = NULL; + +VALA_EXTERN GType ifoo_proxy_get_type (void) G_GNUC_CONST ; +VALA_EXTERN guint ifoo_register_object (void* object, + GDBusConnection* connection, + const gchar* path, + GError** error); +VALA_EXTERN GType ifoo_get_type (void) G_GNUC_CONST ; +VALA_EXTERN void ifoo_method0 (IFoo* self, + GError** error); +VALA_EXTERN void ifoo_method1 (IFoo* self, + GError** error); +VALA_EXTERN void ifoo_method2 (IFoo* self); +static GType ifoo_get_type_once (void); +static void ifoo_proxy_g_signal (GDBusProxy* proxy, + const gchar* sender_name, + const gchar* signal_name, + GVariant* parameters); +static void ifoo_proxy_method0 (IFoo* self, + GError** error); +static void ifoo_proxy_method1 (IFoo* self, + GError** error); +static void ifoo_proxy_method2 (IFoo* self); +static void ifoo_proxy_ifoo_interface_init (IFooIface* iface); +static void _dbus_ifoo_method0 (IFoo* self, + GVariant* _parameters_, + GDBusMethodInvocation* invocation); +static void _dbus_ifoo_method1 (IFoo* self, + GVariant* _parameters_, + GDBusMethodInvocation* invocation); +static void ifoo_dbus_interface_method_call (GDBusConnection* connection, + const gchar* sender, + const gchar* object_path, + const gchar* interface_name, + const gchar* method_name, + GVariant* parameters, + GDBusMethodInvocation* invocation, + gpointer user_data); +static GVariant* ifoo_dbus_interface_get_property (GDBusConnection* connection, + const gchar* sender, + const gchar* object_path, + const gchar* interface_name, + const gchar* property_name, + GError** error, + gpointer user_data); +static gboolean ifoo_dbus_interface_set_property (GDBusConnection* connection, + const gchar* sender, + const gchar* object_path, + const gchar* interface_name, + const gchar* property_name, + GVariant* value, + GError** error, + gpointer user_data); +static void _ifoo_unregister_object (gpointer user_data); +VALA_EXTERN GType foo_get_type (void) G_GNUC_CONST ; +G_DEFINE_AUTOPTR_CLEANUP_FUNC (Foo, g_object_unref) +VALA_EXTERN guint foo_register_object (void* object, + GDBusConnection* connection, + const gchar* path, + GError** error); +VALA_EXTERN void foo_method0 (Foo* self, + GError** error); +VALA_EXTERN void foo_method1 (Foo* self, + GError** error); +VALA_EXTERN void foo_method2 (Foo* self); +VALA_EXTERN Foo* foo_new (void); +VALA_EXTERN Foo* foo_construct (GType object_type); +static GType foo_get_type_once (void); +static void _dbus_foo_method0 (Foo* self, + GVariant* _parameters_, + GDBusMethodInvocation* invocation); +static void _dbus_foo_method1 (Foo* self, + GVariant* _parameters_, + GDBusMethodInvocation* invocation); +static void foo_dbus_interface_method_call (GDBusConnection* connection, + const gchar* sender, + const gchar* object_path, + const gchar* interface_name, + const gchar* method_name, + GVariant* parameters, + GDBusMethodInvocation* invocation, + gpointer user_data); +static GVariant* foo_dbus_interface_get_property (GDBusConnection* connection, + const gchar* sender, + const gchar* object_path, + const gchar* interface_name, + const gchar* property_name, + GError** error, + gpointer user_data); +static gboolean foo_dbus_interface_set_property (GDBusConnection* connection, + const gchar* sender, + const gchar* object_path, + const gchar* interface_name, + const gchar* property_name, + GVariant* value, + GError** error, + gpointer user_data); +static void _foo_unregister_object (gpointer user_data); +static void _vala_main (void); + +static const GDBusArgInfo * const _ifoo_dbus_arg_info_method0_in[] = {NULL}; +static const GDBusArgInfo * const _ifoo_dbus_arg_info_method0_out[] = {NULL}; +static const GDBusMethodInfo _ifoo_dbus_method_info_method0 = {-1, "Method0", (GDBusArgInfo **) (&_ifoo_dbus_arg_info_method0_in), (GDBusArgInfo **) (&_ifoo_dbus_arg_info_method0_out), NULL}; +static const GDBusArgInfo * const _ifoo_dbus_arg_info_method1_in[] = {NULL}; +static const GDBusArgInfo * const _ifoo_dbus_arg_info_method1_out[] = {NULL}; +static const GDBusMethodInfo _ifoo_dbus_method_info_method1 = {-1, "Method1", (GDBusArgInfo **) (&_ifoo_dbus_arg_info_method1_in), (GDBusArgInfo **) (&_ifoo_dbus_arg_info_method1_out), NULL}; +static const GDBusMethodInfo * const _ifoo_dbus_method_info[] = {&_ifoo_dbus_method_info_method0, &_ifoo_dbus_method_info_method1, NULL}; +static const GDBusSignalInfo * const _ifoo_dbus_signal_info[] = {NULL}; +static const GDBusPropertyInfo * const _ifoo_dbus_property_info[] = {NULL}; +static const GDBusInterfaceInfo _ifoo_dbus_interface_info = {-1, "org.example.IFoo", (GDBusMethodInfo **) (&_ifoo_dbus_method_info), (GDBusSignalInfo **) (&_ifoo_dbus_signal_info), (GDBusPropertyInfo **) (&_ifoo_dbus_property_info), NULL}; +static const GDBusInterfaceVTable _ifoo_dbus_interface_vtable = {ifoo_dbus_interface_method_call, ifoo_dbus_interface_get_property, ifoo_dbus_interface_set_property}; +static const GDBusArgInfo * const _foo_dbus_arg_info_method0_in[] = {NULL}; +static const GDBusArgInfo * const _foo_dbus_arg_info_method0_out[] = {NULL}; +static const GDBusMethodInfo _foo_dbus_method_info_method0 = {-1, "Method0", (GDBusArgInfo **) (&_foo_dbus_arg_info_method0_in), (GDBusArgInfo **) (&_foo_dbus_arg_info_method0_out), NULL}; +static const GDBusArgInfo * const _foo_dbus_arg_info_method1_in[] = {NULL}; +static const GDBusArgInfo * const _foo_dbus_arg_info_method1_out[] = {NULL}; +static const GDBusMethodInfo _foo_dbus_method_info_method1 = {-1, "Method1", (GDBusArgInfo **) (&_foo_dbus_arg_info_method1_in), (GDBusArgInfo **) (&_foo_dbus_arg_info_method1_out), NULL}; +static const GDBusMethodInfo * const _foo_dbus_method_info[] = {&_foo_dbus_method_info_method0, &_foo_dbus_method_info_method1, NULL}; +static const GDBusSignalInfo * const _foo_dbus_signal_info[] = {NULL}; +static const GDBusPropertyInfo * const _foo_dbus_property_info[] = {NULL}; +static const GDBusInterfaceInfo _foo_dbus_interface_info = {-1, "org.example.Foo", (GDBusMethodInfo **) (&_foo_dbus_method_info), (GDBusSignalInfo **) (&_foo_dbus_signal_info), (GDBusPropertyInfo **) (&_foo_dbus_property_info), NULL}; +static const GDBusInterfaceVTable _foo_dbus_interface_vtable = {foo_dbus_interface_method_call, foo_dbus_interface_get_property, foo_dbus_interface_set_property}; + +void +ifoo_method0 (IFoo* self, + GError** error) +{ + IFooIface* _iface_; + g_return_if_fail (IS_IFOO (self)); + _iface_ = IFOO_GET_INTERFACE (self); + if (_iface_->method0) { + _iface_->method0 (self, error); + } +} + +void +ifoo_method1 (IFoo* self, + GError** error) +{ + IFooIface* _iface_; + g_return_if_fail (IS_IFOO (self)); + _iface_ = IFOO_GET_INTERFACE (self); + if (_iface_->method1) { + _iface_->method1 (self, error); + } +} + +void +ifoo_method2 (IFoo* self) +{ + IFooIface* _iface_; + g_return_if_fail (IS_IFOO (self)); + _iface_ = IFOO_GET_INTERFACE (self); + if (_iface_->method2) { + _iface_->method2 (self); + } +} + +static void +ifoo_default_init (IFooIface * iface, + gpointer iface_data) +{ +} + +static GType +ifoo_get_type_once (void) +{ + static const GTypeInfo g_define_type_info = { sizeof (IFooIface), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) ifoo_default_init, (GClassFinalizeFunc) NULL, NULL, 0, 0, (GInstanceInitFunc) NULL, NULL }; + GType ifoo_type_id; + ifoo_type_id = g_type_register_static (G_TYPE_INTERFACE, "IFoo", &g_define_type_info, 0); + g_type_interface_add_prerequisite (ifoo_type_id, G_TYPE_OBJECT); + g_type_set_qdata (ifoo_type_id, g_quark_from_static_string ("vala-dbus-proxy-type"), (void*) ifoo_proxy_get_type); + g_type_set_qdata (ifoo_type_id, g_quark_from_static_string ("vala-dbus-interface-name"), "org.example.IFoo"); + g_type_set_qdata (ifoo_type_id, g_quark_from_static_string ("vala-dbus-interface-info"), (void*) (&_ifoo_dbus_interface_info)); + g_type_set_qdata (ifoo_type_id, g_quark_from_static_string ("vala-dbus-register-object"), (void*) ifoo_register_object); + return ifoo_type_id; +} + +GType +ifoo_get_type (void) +{ + static volatile gsize ifoo_type_id__volatile = 0; + if (g_once_init_enter (&ifoo_type_id__volatile)) { + GType ifoo_type_id; + ifoo_type_id = ifoo_get_type_once (); + g_once_init_leave (&ifoo_type_id__volatile, ifoo_type_id); + } + return ifoo_type_id__volatile; +} + +G_DEFINE_TYPE_EXTENDED (IFooProxy, ifoo_proxy, G_TYPE_DBUS_PROXY, 0, G_IMPLEMENT_INTERFACE (TYPE_IFOO, ifoo_proxy_ifoo_interface_init) ) +static void +ifoo_proxy_class_init (IFooProxyClass* klass) +{ + G_DBUS_PROXY_CLASS (klass)->g_signal = ifoo_proxy_g_signal; +} + +static void +ifoo_proxy_g_signal (GDBusProxy* proxy, + const gchar* sender_name, + const gchar* signal_name, + GVariant* parameters) +{ +} + +static void +ifoo_proxy_init (IFooProxy* self) +{ + g_dbus_proxy_set_interface_info (G_DBUS_PROXY (self), (GDBusInterfaceInfo *) (&_ifoo_dbus_interface_info)); +} + +static void +ifoo_proxy_method0 (IFoo* self, + GError** error) +{ + GDBusMessage *_message; + GVariant *_arguments; + GVariantBuilder _arguments_builder; + GDBusMessage *_reply_message; + _message = g_dbus_message_new_method_call (g_dbus_proxy_get_name ((GDBusProxy *) self), g_dbus_proxy_get_object_path ((GDBusProxy *) self), "org.example.IFoo", "Method0"); + g_variant_builder_init (&_arguments_builder, G_VARIANT_TYPE_TUPLE); + _arguments = g_variant_builder_end (&_arguments_builder); + g_dbus_message_set_body (_message, _arguments); + _reply_message = g_dbus_connection_send_message_with_reply_sync (g_dbus_proxy_get_connection ((GDBusProxy *) self), _message, G_DBUS_SEND_MESSAGE_FLAGS_NONE, g_dbus_proxy_get_default_timeout ((GDBusProxy *) self), NULL, NULL, error); + g_object_unref (_message); + if (!_reply_message) { + return; + } + if (g_dbus_message_to_gerror (_reply_message, error)) { + g_object_unref (_reply_message); + return; + } + g_object_unref (_reply_message); +} + +static void +ifoo_proxy_method1 (IFoo* self, + GError** error) +{ + GDBusMessage *_message; + GVariant *_arguments; + GVariantBuilder _arguments_builder; + GDBusMessage *_reply_message; + G_DBUS_ERROR; + G_IO_ERROR; + _message = g_dbus_message_new_method_call (g_dbus_proxy_get_name ((GDBusProxy *) self), g_dbus_proxy_get_object_path ((GDBusProxy *) self), "org.example.IFoo", "Method1"); + g_variant_builder_init (&_arguments_builder, G_VARIANT_TYPE_TUPLE); + _arguments = g_variant_builder_end (&_arguments_builder); + g_dbus_message_set_body (_message, _arguments); + _reply_message = g_dbus_connection_send_message_with_reply_sync (g_dbus_proxy_get_connection ((GDBusProxy *) self), _message, G_DBUS_SEND_MESSAGE_FLAGS_NONE, g_dbus_proxy_get_default_timeout ((GDBusProxy *) self), NULL, NULL, error); + g_object_unref (_message); + if (!_reply_message) { + return; + } + if (g_dbus_message_to_gerror (_reply_message, error)) { + g_object_unref (_reply_message); + return; + } + g_object_unref (_reply_message); +} + +static void +ifoo_proxy_method2 (IFoo* self) +{ + GDBusMessage *_message; + GVariant *_arguments; + GVariantBuilder _arguments_builder; + GDBusMessage *_reply_message; + _message = g_dbus_message_new_method_call (g_dbus_proxy_get_name ((GDBusProxy *) self), g_dbus_proxy_get_object_path ((GDBusProxy *) self), "org.example.IFoo", "Method2"); + g_variant_builder_init (&_arguments_builder, G_VARIANT_TYPE_TUPLE); + _arguments = g_variant_builder_end (&_arguments_builder); + g_dbus_message_set_body (_message, _arguments); + _reply_message = g_dbus_connection_send_message_with_reply_sync (g_dbus_proxy_get_connection ((GDBusProxy *) self), _message, G_DBUS_SEND_MESSAGE_FLAGS_NONE, g_dbus_proxy_get_default_timeout ((GDBusProxy *) self), NULL, NULL, NULL); + g_object_unref (_message); + if (!_reply_message) { + return; + } + if (g_dbus_message_to_gerror (_reply_message, NULL)) { + g_object_unref (_reply_message); + return; + } + g_object_unref (_reply_message); +} + +static void +ifoo_proxy_ifoo_interface_init (IFooIface* iface) +{ + iface->method0 = ifoo_proxy_method0; + iface->method1 = ifoo_proxy_method1; + iface->method2 = ifoo_proxy_method2; +} + +static void +_dbus_ifoo_method0 (IFoo* self, + GVariant* _parameters_, + GDBusMethodInvocation* invocation) +{ + GError* error = NULL; + GVariantIter _arguments_iter; + GDBusMessage* _reply_message = NULL; + GVariant* _reply; + GVariantBuilder _reply_builder; + g_variant_iter_init (&_arguments_iter, _parameters_); + ifoo_method0 (self, &error); + if (error) { + g_dbus_method_invocation_return_gerror (invocation, error); + g_error_free (error); + return; + } + _reply_message = g_dbus_message_new_method_reply (g_dbus_method_invocation_get_message (invocation)); + g_variant_builder_init (&_reply_builder, G_VARIANT_TYPE_TUPLE); + _reply = g_variant_builder_end (&_reply_builder); + g_dbus_message_set_body (_reply_message, _reply); + g_dbus_connection_send_message (g_dbus_method_invocation_get_connection (invocation), _reply_message, G_DBUS_SEND_MESSAGE_FLAGS_NONE, NULL, NULL); + g_object_unref (invocation); + g_object_unref (_reply_message); +} + +static void +_dbus_ifoo_method1 (IFoo* self, + GVariant* _parameters_, + GDBusMethodInvocation* invocation) +{ + GError* error = NULL; + GVariantIter _arguments_iter; + GDBusMessage* _reply_message = NULL; + GVariant* _reply; + GVariantBuilder _reply_builder; + g_variant_iter_init (&_arguments_iter, _parameters_); + ifoo_method1 (self, &error); + if (error) { + g_dbus_method_invocation_return_gerror (invocation, error); + g_error_free (error); + return; + } + _reply_message = g_dbus_message_new_method_reply (g_dbus_method_invocation_get_message (invocation)); + g_variant_builder_init (&_reply_builder, G_VARIANT_TYPE_TUPLE); + _reply = g_variant_builder_end (&_reply_builder); + g_dbus_message_set_body (_reply_message, _reply); + g_dbus_connection_send_message (g_dbus_method_invocation_get_connection (invocation), _reply_message, G_DBUS_SEND_MESSAGE_FLAGS_NONE, NULL, NULL); + g_object_unref (invocation); + g_object_unref (_reply_message); +} + +static void +ifoo_dbus_interface_method_call (GDBusConnection* connection, + const gchar* sender, + const gchar* object_path, + const gchar* interface_name, + const gchar* method_name, + GVariant* parameters, + GDBusMethodInvocation* invocation, + gpointer user_data) +{ + gpointer* data; + gpointer object; + data = user_data; + object = data[0]; + if (strcmp (method_name, "Method0") == 0) { + _dbus_ifoo_method0 (object, parameters, invocation); + } else if (strcmp (method_name, "Method1") == 0) { + _dbus_ifoo_method1 (object, parameters, invocation); + } else { + g_object_unref (invocation); + } +} + +static GVariant* +ifoo_dbus_interface_get_property (GDBusConnection* connection, + const gchar* sender, + const gchar* object_path, + const gchar* interface_name, + const gchar* property_name, + GError** error, + gpointer user_data) +{ + gpointer* data; + gpointer object; + data = user_data; + object = data[0]; + return NULL; +} + +static gboolean +ifoo_dbus_interface_set_property (GDBusConnection* connection, + const gchar* sender, + const gchar* object_path, + const gchar* interface_name, + const gchar* property_name, + GVariant* value, + GError** error, + gpointer user_data) +{ + gpointer* data; + gpointer object; + data = user_data; + object = data[0]; + return FALSE; +} + +guint +ifoo_register_object (gpointer object, + GDBusConnection* connection, + const gchar* path, + GError** error) +{ + guint result; + gpointer *data; + data = g_new (gpointer, 3); + data[0] = g_object_ref (object); + data[1] = g_object_ref (connection); + data[2] = g_strdup (path); + result = g_dbus_connection_register_object (connection, path, (GDBusInterfaceInfo *) (&_ifoo_dbus_interface_info), &_ifoo_dbus_interface_vtable, data, _ifoo_unregister_object, error); + if (!result) { + return 0; + } + return result; +} + +static void +_ifoo_unregister_object (gpointer user_data) +{ + gpointer* data; + data = user_data; + g_object_unref (data[0]); + g_object_unref (data[1]); + g_free (data[2]); + g_free (data); +} + +void +foo_method0 (Foo* self, + GError** error) +{ + g_return_if_fail (IS_FOO (self)); +} + +void +foo_method1 (Foo* self, + GError** error) +{ + g_return_if_fail (IS_FOO (self)); +} + +void +foo_method2 (Foo* self) +{ + g_return_if_fail (IS_FOO (self)); +} + +Foo* +foo_construct (GType object_type) +{ + Foo * self = NULL; + self = (Foo*) g_object_new (object_type, NULL); + return self; +} + +Foo* +foo_new (void) +{ + return foo_construct (TYPE_FOO); +} + +static void +foo_class_init (FooClass * klass, + gpointer klass_data) +{ + foo_parent_class = g_type_class_peek_parent (klass); +} + +static void +foo_instance_init (Foo * self, + gpointer klass) +{ +} + +static GType +foo_get_type_once (void) +{ + static const GTypeInfo g_define_type_info = { sizeof (FooClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) foo_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (Foo), 0, (GInstanceInitFunc) foo_instance_init, NULL }; + GType foo_type_id; + foo_type_id = g_type_register_static (G_TYPE_OBJECT, "Foo", &g_define_type_info, 0); + g_type_set_qdata (foo_type_id, g_quark_from_static_string ("vala-dbus-register-object"), (void*) foo_register_object); + return foo_type_id; +} + +GType +foo_get_type (void) +{ + static volatile gsize foo_type_id__volatile = 0; + if (g_once_init_enter (&foo_type_id__volatile)) { + GType foo_type_id; + foo_type_id = foo_get_type_once (); + g_once_init_leave (&foo_type_id__volatile, foo_type_id); + } + return foo_type_id__volatile; +} + +static void +_dbus_foo_method0 (Foo* self, + GVariant* _parameters_, + GDBusMethodInvocation* invocation) +{ + GError* error = NULL; + GVariantIter _arguments_iter; + GDBusMessage* _reply_message = NULL; + GVariant* _reply; + GVariantBuilder _reply_builder; + g_variant_iter_init (&_arguments_iter, _parameters_); + foo_method0 (self, &error); + if (error) { + g_dbus_method_invocation_return_gerror (invocation, error); + g_error_free (error); + return; + } + _reply_message = g_dbus_message_new_method_reply (g_dbus_method_invocation_get_message (invocation)); + g_variant_builder_init (&_reply_builder, G_VARIANT_TYPE_TUPLE); + _reply = g_variant_builder_end (&_reply_builder); + g_dbus_message_set_body (_reply_message, _reply); + g_dbus_connection_send_message (g_dbus_method_invocation_get_connection (invocation), _reply_message, G_DBUS_SEND_MESSAGE_FLAGS_NONE, NULL, NULL); + g_object_unref (invocation); + g_object_unref (_reply_message); +} + +static void +_dbus_foo_method1 (Foo* self, + GVariant* _parameters_, + GDBusMethodInvocation* invocation) +{ + GError* error = NULL; + GVariantIter _arguments_iter; + GDBusMessage* _reply_message = NULL; + GVariant* _reply; + GVariantBuilder _reply_builder; + g_variant_iter_init (&_arguments_iter, _parameters_); + foo_method1 (self, &error); + if (error) { + g_dbus_method_invocation_return_gerror (invocation, error); + g_error_free (error); + return; + } + _reply_message = g_dbus_message_new_method_reply (g_dbus_method_invocation_get_message (invocation)); + g_variant_builder_init (&_reply_builder, G_VARIANT_TYPE_TUPLE); + _reply = g_variant_builder_end (&_reply_builder); + g_dbus_message_set_body (_reply_message, _reply); + g_dbus_connection_send_message (g_dbus_method_invocation_get_connection (invocation), _reply_message, G_DBUS_SEND_MESSAGE_FLAGS_NONE, NULL, NULL); + g_object_unref (invocation); + g_object_unref (_reply_message); +} + +static void +foo_dbus_interface_method_call (GDBusConnection* connection, + const gchar* sender, + const gchar* object_path, + const gchar* interface_name, + const gchar* method_name, + GVariant* parameters, + GDBusMethodInvocation* invocation, + gpointer user_data) +{ + gpointer* data; + gpointer object; + data = user_data; + object = data[0]; + if (strcmp (method_name, "Method0") == 0) { + _dbus_foo_method0 (object, parameters, invocation); + } else if (strcmp (method_name, "Method1") == 0) { + _dbus_foo_method1 (object, parameters, invocation); + } else { + g_object_unref (invocation); + } +} + +static GVariant* +foo_dbus_interface_get_property (GDBusConnection* connection, + const gchar* sender, + const gchar* object_path, + const gchar* interface_name, + const gchar* property_name, + GError** error, + gpointer user_data) +{ + gpointer* data; + gpointer object; + data = user_data; + object = data[0]; + return NULL; +} + +static gboolean +foo_dbus_interface_set_property (GDBusConnection* connection, + const gchar* sender, + const gchar* object_path, + const gchar* interface_name, + const gchar* property_name, + GVariant* value, + GError** error, + gpointer user_data) +{ + gpointer* data; + gpointer object; + data = user_data; + object = data[0]; + return FALSE; +} + +guint +foo_register_object (gpointer object, + GDBusConnection* connection, + const gchar* path, + GError** error) +{ + guint result; + gpointer *data; + data = g_new (gpointer, 3); + data[0] = g_object_ref (object); + data[1] = g_object_ref (connection); + data[2] = g_strdup (path); + result = g_dbus_connection_register_object (connection, path, (GDBusInterfaceInfo *) (&_foo_dbus_interface_info), &_foo_dbus_interface_vtable, data, _foo_unregister_object, error); + if (!result) { + return 0; + } + return result; +} + +static void +_foo_unregister_object (gpointer user_data) +{ + gpointer* data; + data = user_data; + g_object_unref (data[0]); + g_object_unref (data[1]); + g_free (data[2]); + g_free (data); +} + +static void +_vala_main (void) +{ +} + +int +main (int argc, + char ** argv) +{ + _vala_main (); + return 0; +} + diff --git a/tests/dbus/connection_client.c-expected b/tests/dbus/connection_client.c-expected new file mode 100644 index 000000000..d25dbb971 --- /dev/null +++ b/tests/dbus/connection_client.c-expected @@ -0,0 +1,366 @@ +/* dbus_connection_client.c generated by valac, the Vala compiler + * generated from dbus_connection_client.vala, do not modify */ + +#include <glib-object.h> +#include <gio/gio.h> +#include <glib.h> +#include <string.h> + +#if !defined(VALA_EXTERN) +#if defined(_MSC_VER) +#define VALA_EXTERN __declspec(dllexport) extern +#elif __GNUC__ >= 4 +#define VALA_EXTERN __attribute__((visibility("default"))) extern +#else +#define VALA_EXTERN extern +#endif +#endif + +#define TYPE_TEST (test_get_type ()) +#define TEST(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TYPE_TEST, Test)) +#define IS_TEST(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TYPE_TEST)) +#define TEST_GET_INTERFACE(obj) (G_TYPE_INSTANCE_GET_INTERFACE ((obj), TYPE_TEST, TestIface)) + +typedef struct _Test Test; +typedef struct _TestIface TestIface; + +#define TYPE_TEST_PROXY (test_proxy_get_type ()) +typedef GDBusProxy TestProxy; +typedef GDBusProxyClass TestProxyClass; +#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL))) +#define _vala_assert(expr, msg) if G_LIKELY (expr) ; else g_assertion_message_expr (G_LOG_DOMAIN, __FILE__, __LINE__, G_STRFUNC, msg); +#define _vala_return_if_fail(expr, msg) if G_LIKELY (expr) ; else { g_return_if_fail_warning (G_LOG_DOMAIN, G_STRFUNC, msg); return; } +#define _vala_return_val_if_fail(expr, msg, val) if G_LIKELY (expr) ; else { g_return_if_fail_warning (G_LOG_DOMAIN, G_STRFUNC, msg); return val; } +#define _vala_warn_if_fail(expr, msg) if G_LIKELY (expr) ; else g_warn_message (G_LOG_DOMAIN, __FILE__, __LINE__, G_STRFUNC, msg); + +struct _TestIface { + GTypeInterface parent_iface; + gint (*get_test) (Test* self, GError** error); +}; + +VALA_EXTERN GType test_proxy_get_type (void) G_GNUC_CONST ; +VALA_EXTERN guint test_register_object (void* object, + GDBusConnection* connection, + const gchar* path, + GError** error); +VALA_EXTERN GType test_get_type (void) G_GNUC_CONST ; +VALA_EXTERN gint test_get_test (Test* self, + GError** error); +static GType test_get_type_once (void); +static void test_proxy_g_signal (GDBusProxy* proxy, + const gchar* sender_name, + const gchar* signal_name, + GVariant* parameters); +static gint test_proxy_get_test (Test* self, + GError** error); +static void test_proxy_test_interface_init (TestIface* iface); +static void _dbus_test_get_test (Test* self, + GVariant* _parameters_, + GDBusMethodInvocation* invocation); +static void test_dbus_interface_method_call (GDBusConnection* connection, + const gchar* sender, + const gchar* object_path, + const gchar* interface_name, + const gchar* method_name, + GVariant* parameters, + GDBusMethodInvocation* invocation, + gpointer user_data); +static GVariant* test_dbus_interface_get_property (GDBusConnection* connection, + const gchar* sender, + const gchar* object_path, + const gchar* interface_name, + const gchar* property_name, + GError** error, + gpointer user_data); +static gboolean test_dbus_interface_set_property (GDBusConnection* connection, + const gchar* sender, + const gchar* object_path, + const gchar* interface_name, + const gchar* property_name, + GVariant* value, + GError** error, + gpointer user_data); +static void _test_unregister_object (gpointer user_data); +static void _vala_main (void); + +static const GDBusArgInfo _test_dbus_arg_info_get_test_result = {-1, "result", "i", NULL}; +static const GDBusArgInfo * const _test_dbus_arg_info_get_test_in[] = {NULL}; +static const GDBusArgInfo * const _test_dbus_arg_info_get_test_out[] = {&_test_dbus_arg_info_get_test_result, NULL}; +static const GDBusMethodInfo _test_dbus_method_info_get_test = {-1, "GetTest", (GDBusArgInfo **) (&_test_dbus_arg_info_get_test_in), (GDBusArgInfo **) (&_test_dbus_arg_info_get_test_out), NULL}; +static const GDBusMethodInfo * const _test_dbus_method_info[] = {&_test_dbus_method_info_get_test, NULL}; +static const GDBusSignalInfo * const _test_dbus_signal_info[] = {NULL}; +static const GDBusPropertyInfo * const _test_dbus_property_info[] = {NULL}; +static const GDBusInterfaceInfo _test_dbus_interface_info = {-1, "org.example.Test", (GDBusMethodInfo **) (&_test_dbus_method_info), (GDBusSignalInfo **) (&_test_dbus_signal_info), (GDBusPropertyInfo **) (&_test_dbus_property_info), NULL}; +static const GDBusInterfaceVTable _test_dbus_interface_vtable = {test_dbus_interface_method_call, test_dbus_interface_get_property, test_dbus_interface_set_property}; + +gint +test_get_test (Test* self, + GError** error) +{ + TestIface* _iface_; + g_return_val_if_fail (IS_TEST (self), 0); + _iface_ = TEST_GET_INTERFACE (self); + if (_iface_->get_test) { + return _iface_->get_test (self, error); + } + return -1; +} + +static void +test_default_init (TestIface * iface, + gpointer iface_data) +{ +} + +static GType +test_get_type_once (void) +{ + static const GTypeInfo g_define_type_info = { sizeof (TestIface), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) test_default_init, (GClassFinalizeFunc) NULL, NULL, 0, 0, (GInstanceInitFunc) NULL, NULL }; + GType test_type_id; + test_type_id = g_type_register_static (G_TYPE_INTERFACE, "Test", &g_define_type_info, 0); + g_type_interface_add_prerequisite (test_type_id, G_TYPE_OBJECT); + g_type_set_qdata (test_type_id, g_quark_from_static_string ("vala-dbus-proxy-type"), (void*) test_proxy_get_type); + g_type_set_qdata (test_type_id, g_quark_from_static_string ("vala-dbus-interface-name"), "org.example.Test"); + g_type_set_qdata (test_type_id, g_quark_from_static_string ("vala-dbus-interface-info"), (void*) (&_test_dbus_interface_info)); + g_type_set_qdata (test_type_id, g_quark_from_static_string ("vala-dbus-register-object"), (void*) test_register_object); + return test_type_id; +} + +GType +test_get_type (void) +{ + static volatile gsize test_type_id__volatile = 0; + if (g_once_init_enter (&test_type_id__volatile)) { + GType test_type_id; + test_type_id = test_get_type_once (); + g_once_init_leave (&test_type_id__volatile, test_type_id); + } + return test_type_id__volatile; +} + +G_DEFINE_TYPE_EXTENDED (TestProxy, test_proxy, G_TYPE_DBUS_PROXY, 0, G_IMPLEMENT_INTERFACE (TYPE_TEST, test_proxy_test_interface_init) ) +static void +test_proxy_class_init (TestProxyClass* klass) +{ + G_DBUS_PROXY_CLASS (klass)->g_signal = test_proxy_g_signal; +} + +static void +test_proxy_g_signal (GDBusProxy* proxy, + const gchar* sender_name, + const gchar* signal_name, + GVariant* parameters) +{ +} + +static void +test_proxy_init (TestProxy* self) +{ + g_dbus_proxy_set_interface_info (G_DBUS_PROXY (self), (GDBusInterfaceInfo *) (&_test_dbus_interface_info)); +} + +static gint +test_proxy_get_test (Test* self, + GError** error) +{ + GDBusMessage *_message; + GVariant *_arguments; + GVariantBuilder _arguments_builder; + GDBusMessage *_reply_message; + GVariant *_reply; + GVariantIter _reply_iter; + gint _result = 0; + GVariant* _tmp2_; + G_DBUS_ERROR; + G_IO_ERROR; + _message = g_dbus_message_new_method_call (g_dbus_proxy_get_name ((GDBusProxy *) self), g_dbus_proxy_get_object_path ((GDBusProxy *) self), "org.example.Test", "GetTest"); + g_variant_builder_init (&_arguments_builder, G_VARIANT_TYPE_TUPLE); + _arguments = g_variant_builder_end (&_arguments_builder); + g_dbus_message_set_body (_message, _arguments); + _reply_message = g_dbus_connection_send_message_with_reply_sync (g_dbus_proxy_get_connection ((GDBusProxy *) self), _message, G_DBUS_SEND_MESSAGE_FLAGS_NONE, g_dbus_proxy_get_default_timeout ((GDBusProxy *) self), NULL, NULL, error); + g_object_unref (_message); + if (!_reply_message) { + gint _tmp0_ = 0; + return _tmp0_; + } + if (g_dbus_message_to_gerror (_reply_message, error)) { + gint _tmp1_ = 0; + g_object_unref (_reply_message); + return _tmp1_; + } + _reply = g_dbus_message_get_body (_reply_message); + g_variant_iter_init (&_reply_iter, _reply); + _tmp2_ = g_variant_iter_next_value (&_reply_iter); + _result = g_variant_get_int32 (_tmp2_); + g_variant_unref (_tmp2_); + g_object_unref (_reply_message); + return _result; +} + +static void +test_proxy_test_interface_init (TestIface* iface) +{ + iface->get_test = test_proxy_get_test; +} + +static void +_dbus_test_get_test (Test* self, + GVariant* _parameters_, + GDBusMethodInvocation* invocation) +{ + GError* error = NULL; + GVariantIter _arguments_iter; + GDBusMessage* _reply_message = NULL; + GVariant* _reply; + GVariantBuilder _reply_builder; + gint result; + g_variant_iter_init (&_arguments_iter, _parameters_); + result = test_get_test (self, &error); + if (error) { + g_dbus_method_invocation_return_gerror (invocation, error); + g_error_free (error); + return; + } + _reply_message = g_dbus_message_new_method_reply (g_dbus_method_invocation_get_message (invocation)); + g_variant_builder_init (&_reply_builder, G_VARIANT_TYPE_TUPLE); + g_variant_builder_add_value (&_reply_builder, g_variant_new_int32 (result)); + _reply = g_variant_builder_end (&_reply_builder); + g_dbus_message_set_body (_reply_message, _reply); + g_dbus_connection_send_message (g_dbus_method_invocation_get_connection (invocation), _reply_message, G_DBUS_SEND_MESSAGE_FLAGS_NONE, NULL, NULL); + g_object_unref (invocation); + g_object_unref (_reply_message); +} + +static void +test_dbus_interface_method_call (GDBusConnection* connection, + const gchar* sender, + const gchar* object_path, + const gchar* interface_name, + const gchar* method_name, + GVariant* parameters, + GDBusMethodInvocation* invocation, + gpointer user_data) +{ + gpointer* data; + gpointer object; + data = user_data; + object = data[0]; + if (strcmp (method_name, "GetTest") == 0) { + _dbus_test_get_test (object, parameters, invocation); + } else { + g_object_unref (invocation); + } +} + +static GVariant* +test_dbus_interface_get_property (GDBusConnection* connection, + const gchar* sender, + const gchar* object_path, + const gchar* interface_name, + const gchar* property_name, + GError** error, + gpointer user_data) +{ + gpointer* data; + gpointer object; + data = user_data; + object = data[0]; + return NULL; +} + +static gboolean +test_dbus_interface_set_property (GDBusConnection* connection, + const gchar* sender, + const gchar* object_path, + const gchar* interface_name, + const gchar* property_name, + GVariant* value, + GError** error, + gpointer user_data) +{ + gpointer* data; + gpointer object; + data = user_data; + object = data[0]; + return FALSE; +} + +guint +test_register_object (gpointer object, + GDBusConnection* connection, + const gchar* path, + GError** error) +{ + guint result; + gpointer *data; + data = g_new (gpointer, 3); + data[0] = g_object_ref (object); + data[1] = g_object_ref (connection); + data[2] = g_strdup (path); + result = g_dbus_connection_register_object (connection, path, (GDBusInterfaceInfo *) (&_test_dbus_interface_info), &_test_dbus_interface_vtable, data, _test_unregister_object, error); + if (!result) { + return 0; + } + return result; +} + +static void +_test_unregister_object (gpointer user_data) +{ + gpointer* data; + data = user_data; + g_object_unref (data[0]); + g_object_unref (data[1]); + g_free (data[2]); + g_free (data); +} + +static void +_vala_main (void) +{ + GDBusConnection* conn = NULL; + GDBusConnection* _tmp0_; + Test* test = NULL; + GDBusConnection* _tmp1_; + Test* _tmp2_; + gint _tmp3_ = 0; + Test* _tmp4_; + GError* _inner_error0_ = NULL; + _tmp0_ = g_bus_get_sync (G_BUS_TYPE_SESSION, NULL, &_inner_error0_); + conn = _tmp0_; + if (G_UNLIKELY (_inner_error0_ != NULL)) { + g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error0_->message, g_quark_to_string (_inner_error0_->domain), _inner_error0_->code); + g_clear_error (&_inner_error0_); + return; + } + _tmp1_ = conn; + _tmp2_ = (Test*) g_initable_new (TYPE_TEST_PROXY, NULL, &_inner_error0_, "g-flags", 0, "g-name", "org.example.Test", "g-connection", _tmp1_, "g-object-path", "/org/example/test", "g-interface-name", "org.example.Test", NULL); + test = (Test*) _tmp2_; + if (G_UNLIKELY (_inner_error0_ != NULL)) { + _g_object_unref0 (conn); + g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error0_->message, g_quark_to_string (_inner_error0_->domain), _inner_error0_->code); + g_clear_error (&_inner_error0_); + return; + } + _tmp4_ = test; + _tmp3_ = test_get_test (_tmp4_, &_inner_error0_); + if (G_UNLIKELY (_inner_error0_ != NULL)) { + _g_object_unref0 (test); + _g_object_unref0 (conn); + g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error0_->message, g_quark_to_string (_inner_error0_->domain), _inner_error0_->code); + g_clear_error (&_inner_error0_); + return; + } + _vala_assert (_tmp3_ == 4711, "test.get_test () == 4711"); + _g_object_unref0 (test); + _g_object_unref0 (conn); +} + +int +main (int argc, + char ** argv) +{ + _vala_main (); + return 0; +} + diff --git a/tests/dbus/connection_server.c-expected b/tests/dbus/connection_server.c-expected new file mode 100644 index 000000000..3dabf4b27 --- /dev/null +++ b/tests/dbus/connection_server.c-expected @@ -0,0 +1,434 @@ +/* dbus_connection_server.c generated by valac, the Vala compiler + * generated from dbus_connection_server.vala, do not modify */ + +#include <glib-object.h> +#include <gio/gio.h> +#include <glib.h> +#include <string.h> +#include <stdlib.h> + +#if !defined(VALA_EXTERN) +#if defined(_MSC_VER) +#define VALA_EXTERN __declspec(dllexport) extern +#elif __GNUC__ >= 4 +#define VALA_EXTERN __attribute__((visibility("default"))) extern +#else +#define VALA_EXTERN extern +#endif +#endif + +#define TYPE_TEST (test_get_type ()) +#define TEST(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TYPE_TEST, Test)) +#define TEST_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), TYPE_TEST, TestClass)) +#define IS_TEST(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TYPE_TEST)) +#define IS_TEST_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), TYPE_TEST)) +#define TEST_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), TYPE_TEST, TestClass)) + +typedef struct _Test Test; +typedef struct _TestClass TestClass; +typedef struct _TestPrivate TestPrivate; +enum { + TEST_0_PROPERTY, + TEST_NUM_PROPERTIES +}; +static GParamSpec* test_properties[TEST_NUM_PROPERTIES]; +#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL))) +#define _g_variant_unref0(var) ((var == NULL) ? NULL : (var = (g_variant_unref (var), NULL))) +#define _g_main_loop_unref0(var) ((var == NULL) ? NULL : (var = (g_main_loop_unref (var), NULL))) +#define _vala_assert(expr, msg) if G_LIKELY (expr) ; else g_assertion_message_expr (G_LOG_DOMAIN, __FILE__, __LINE__, G_STRFUNC, msg); +#define _vala_return_if_fail(expr, msg) if G_LIKELY (expr) ; else { g_return_if_fail_warning (G_LOG_DOMAIN, G_STRFUNC, msg); return; } +#define _vala_return_val_if_fail(expr, msg, val) if G_LIKELY (expr) ; else { g_return_if_fail_warning (G_LOG_DOMAIN, G_STRFUNC, msg); return val; } +#define _vala_warn_if_fail(expr, msg) if G_LIKELY (expr) ; else g_warn_message (G_LOG_DOMAIN, __FILE__, __LINE__, G_STRFUNC, msg); + +struct _Test { + GObject parent_instance; + TestPrivate * priv; +}; + +struct _TestClass { + GObjectClass parent_class; +}; + +static gpointer test_parent_class = NULL; +VALA_EXTERN GMainLoop* main_loop; +GMainLoop* main_loop = NULL; + +VALA_EXTERN GType test_get_type (void) G_GNUC_CONST ; +G_DEFINE_AUTOPTR_CLEANUP_FUNC (Test, g_object_unref) +VALA_EXTERN guint test_register_object (void* object, + GDBusConnection* connection, + const gchar* path, + GError** error); +VALA_EXTERN gint test_get_test (Test* self, + GError** error); +VALA_EXTERN Test* test_new (void); +VALA_EXTERN Test* test_construct (GType object_type); +static GType test_get_type_once (void); +static void _dbus_test_get_test (Test* self, + GVariant* _parameters_, + GDBusMethodInvocation* invocation); +static void test_dbus_interface_method_call (GDBusConnection* connection, + const gchar* sender, + const gchar* object_path, + const gchar* interface_name, + const gchar* method_name, + GVariant* parameters, + GDBusMethodInvocation* invocation, + gpointer user_data); +static GVariant* test_dbus_interface_get_property (GDBusConnection* connection, + const gchar* sender, + const gchar* object_path, + const gchar* interface_name, + const gchar* property_name, + GError** error, + gpointer user_data); +static gboolean test_dbus_interface_set_property (GDBusConnection* connection, + const gchar* sender, + const gchar* object_path, + const gchar* interface_name, + const gchar* property_name, + GVariant* value, + GError** error, + gpointer user_data); +static void _test_unregister_object (gpointer user_data); +VALA_EXTERN void client_exit (GPid pid, + gint status); +static void _vala_main (void); +static guint _variant_get1 (GVariant* value); +static void _client_exit_gchild_watch_func (GPid pid, + gint wait_status, + gpointer self); +static void _vala_array_destroy (gpointer array, + gssize array_length, + GDestroyNotify destroy_func); +static void _vala_array_free (gpointer array, + gssize array_length, + GDestroyNotify destroy_func); + +static const GDBusArgInfo _test_dbus_arg_info_get_test_result = {-1, "result", "i", NULL}; +static const GDBusArgInfo * const _test_dbus_arg_info_get_test_in[] = {NULL}; +static const GDBusArgInfo * const _test_dbus_arg_info_get_test_out[] = {&_test_dbus_arg_info_get_test_result, NULL}; +static const GDBusMethodInfo _test_dbus_method_info_get_test = {-1, "GetTest", (GDBusArgInfo **) (&_test_dbus_arg_info_get_test_in), (GDBusArgInfo **) (&_test_dbus_arg_info_get_test_out), NULL}; +static const GDBusMethodInfo * const _test_dbus_method_info[] = {&_test_dbus_method_info_get_test, NULL}; +static const GDBusSignalInfo * const _test_dbus_signal_info[] = {NULL}; +static const GDBusPropertyInfo * const _test_dbus_property_info[] = {NULL}; +static const GDBusInterfaceInfo _test_dbus_interface_info = {-1, "org.example.Test", (GDBusMethodInfo **) (&_test_dbus_method_info), (GDBusSignalInfo **) (&_test_dbus_signal_info), (GDBusPropertyInfo **) (&_test_dbus_property_info), NULL}; +static const GDBusInterfaceVTable _test_dbus_interface_vtable = {test_dbus_interface_method_call, test_dbus_interface_get_property, test_dbus_interface_set_property}; + +gint +test_get_test (Test* self, + GError** error) +{ + gint result = 0; + g_return_val_if_fail (IS_TEST (self), 0); + result = 4711; + return result; +} + +Test* +test_construct (GType object_type) +{ + Test * self = NULL; + self = (Test*) g_object_new (object_type, NULL); + return self; +} + +Test* +test_new (void) +{ + return test_construct (TYPE_TEST); +} + +static void +test_class_init (TestClass * klass, + gpointer klass_data) +{ + test_parent_class = g_type_class_peek_parent (klass); +} + +static void +test_instance_init (Test * self, + gpointer klass) +{ +} + +static GType +test_get_type_once (void) +{ + static const GTypeInfo g_define_type_info = { sizeof (TestClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) test_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (Test), 0, (GInstanceInitFunc) test_instance_init, NULL }; + GType test_type_id; + test_type_id = g_type_register_static (G_TYPE_OBJECT, "Test", &g_define_type_info, 0); + g_type_set_qdata (test_type_id, g_quark_from_static_string ("vala-dbus-register-object"), (void*) test_register_object); + return test_type_id; +} + +GType +test_get_type (void) +{ + static volatile gsize test_type_id__volatile = 0; + if (g_once_init_enter (&test_type_id__volatile)) { + GType test_type_id; + test_type_id = test_get_type_once (); + g_once_init_leave (&test_type_id__volatile, test_type_id); + } + return test_type_id__volatile; +} + +static void +_dbus_test_get_test (Test* self, + GVariant* _parameters_, + GDBusMethodInvocation* invocation) +{ + GError* error = NULL; + GVariantIter _arguments_iter; + GDBusMessage* _reply_message = NULL; + GVariant* _reply; + GVariantBuilder _reply_builder; + gint result; + g_variant_iter_init (&_arguments_iter, _parameters_); + result = test_get_test (self, &error); + if (error) { + g_dbus_method_invocation_return_gerror (invocation, error); + g_error_free (error); + return; + } + _reply_message = g_dbus_message_new_method_reply (g_dbus_method_invocation_get_message (invocation)); + g_variant_builder_init (&_reply_builder, G_VARIANT_TYPE_TUPLE); + g_variant_builder_add_value (&_reply_builder, g_variant_new_int32 (result)); + _reply = g_variant_builder_end (&_reply_builder); + g_dbus_message_set_body (_reply_message, _reply); + g_dbus_connection_send_message (g_dbus_method_invocation_get_connection (invocation), _reply_message, G_DBUS_SEND_MESSAGE_FLAGS_NONE, NULL, NULL); + g_object_unref (invocation); + g_object_unref (_reply_message); +} + +static void +test_dbus_interface_method_call (GDBusConnection* connection, + const gchar* sender, + const gchar* object_path, + const gchar* interface_name, + const gchar* method_name, + GVariant* parameters, + GDBusMethodInvocation* invocation, + gpointer user_data) +{ + gpointer* data; + gpointer object; + data = user_data; + object = data[0]; + if (strcmp (method_name, "GetTest") == 0) { + _dbus_test_get_test (object, parameters, invocation); + } else { + g_object_unref (invocation); + } +} + +static GVariant* +test_dbus_interface_get_property (GDBusConnection* connection, + const gchar* sender, + const gchar* object_path, + const gchar* interface_name, + const gchar* property_name, + GError** error, + gpointer user_data) +{ + gpointer* data; + gpointer object; + data = user_data; + object = data[0]; + return NULL; +} + +static gboolean +test_dbus_interface_set_property (GDBusConnection* connection, + const gchar* sender, + const gchar* object_path, + const gchar* interface_name, + const gchar* property_name, + GVariant* value, + GError** error, + gpointer user_data) +{ + gpointer* data; + gpointer object; + data = user_data; + object = data[0]; + return FALSE; +} + +guint +test_register_object (gpointer object, + GDBusConnection* connection, + const gchar* path, + GError** error) +{ + guint result; + gpointer *data; + data = g_new (gpointer, 3); + data[0] = g_object_ref (object); + data[1] = g_object_ref (connection); + data[2] = g_strdup (path); + result = g_dbus_connection_register_object (connection, path, (GDBusInterfaceInfo *) (&_test_dbus_interface_info), &_test_dbus_interface_vtable, data, _test_unregister_object, error); + if (!result) { + return 0; + } + return result; +} + +static void +_test_unregister_object (gpointer user_data) +{ + gpointer* data; + data = user_data; + g_object_unref (data[0]); + g_object_unref (data[1]); + g_free (data[2]); + g_free (data); +} + +void +client_exit (GPid pid, + gint status) +{ + GMainLoop* _tmp0_; + _vala_assert (status == 0, "status == 0"); + _tmp0_ = main_loop; + g_main_loop_quit (_tmp0_); +} + +static guint +_variant_get1 (GVariant* value) +{ + return g_variant_get_uint32 (value); +} + +static void +_client_exit_gchild_watch_func (GPid pid, + gint wait_status, + gpointer self) +{ + client_exit (pid, wait_status); +} + +static void +_vala_main (void) +{ + GDBusConnection* conn = NULL; + GDBusConnection* _tmp0_; + GDBusConnection* _tmp1_; + Test* _tmp2_; + Test* _tmp3_; + GVariant* request_result = NULL; + GDBusConnection* _tmp4_; + GVariant* _tmp5_; + GVariant* _tmp6_; + GVariant* _tmp7_; + GVariant* _tmp8_; + GVariant* _tmp9_; + GVariant* _tmp10_; + GVariant* _tmp11_; + guint _tmp12_; + GPid client_pid = 0; + gchar* _tmp13_; + gchar** _tmp14_; + gchar** _tmp15_; + gint _tmp15__length1; + GPid _tmp16_ = 0; + GMainLoop* _tmp17_; + GMainLoop* _tmp18_; + GError* _inner_error0_ = NULL; + _tmp0_ = g_bus_get_sync (G_BUS_TYPE_SESSION, NULL, &_inner_error0_); + conn = _tmp0_; + if (G_UNLIKELY (_inner_error0_ != NULL)) { + g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error0_->message, g_quark_to_string (_inner_error0_->domain), _inner_error0_->code); + g_clear_error (&_inner_error0_); + return; + } + _tmp1_ = conn; + _tmp2_ = test_new (); + _tmp3_ = _tmp2_; + test_register_object (_tmp3_, _tmp1_, "/org/example/test", &_inner_error0_); + _g_object_unref0 (_tmp3_); + if (G_UNLIKELY (_inner_error0_ != NULL)) { + _g_object_unref0 (conn); + g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error0_->message, g_quark_to_string (_inner_error0_->domain), _inner_error0_->code); + g_clear_error (&_inner_error0_); + return; + } + _tmp4_ = conn; + _tmp5_ = g_variant_new ("(su)", "org.example.Test", 0x4, NULL); + g_variant_ref_sink (_tmp5_); + _tmp6_ = _tmp5_; + _tmp7_ = g_dbus_connection_call_sync (_tmp4_, "org.freedesktop.DBus", "/org/freedesktop/DBus", "org.freedesktop.DBus", "RequestName", _tmp6_, NULL, 0, -1, NULL, &_inner_error0_); + _tmp8_ = _tmp7_; + _g_variant_unref0 (_tmp6_); + request_result = _tmp8_; + if (G_UNLIKELY (_inner_error0_ != NULL)) { + _g_object_unref0 (conn); + g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error0_->message, g_quark_to_string (_inner_error0_->domain), _inner_error0_->code); + g_clear_error (&_inner_error0_); + return; + } + _tmp9_ = request_result; + _tmp10_ = g_variant_get_child_value (_tmp9_, (gsize) 0); + _tmp11_ = _tmp10_; + _tmp12_ = _variant_get1 (_tmp11_); + _vala_assert (_tmp12_ == ((guint) 1), "(uint) request_result.get_child_value (0) == 1"); + _g_variant_unref0 (_tmp11_); + _tmp13_ = g_strdup ("dbus_connection_client"); + _tmp14_ = g_new0 (gchar*, 1 + 1); + _tmp14_[0] = _tmp13_; + _tmp15_ = _tmp14_; + _tmp15__length1 = 1; + g_spawn_async (NULL, _tmp15_, NULL, G_SPAWN_DO_NOT_REAP_CHILD, NULL, NULL, &_tmp16_, &_inner_error0_); + client_pid = _tmp16_; + _tmp15_ = (_vala_array_free (_tmp15_, _tmp15__length1, (GDestroyNotify) g_free), NULL); + if (G_UNLIKELY (_inner_error0_ != NULL)) { + _g_variant_unref0 (request_result); + _g_object_unref0 (conn); + g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error0_->message, g_quark_to_string (_inner_error0_->domain), _inner_error0_->code); + g_clear_error (&_inner_error0_); + return; + } + g_child_watch_add_full (G_PRIORITY_DEFAULT_IDLE, client_pid, _client_exit_gchild_watch_func, NULL, NULL); + _tmp17_ = g_main_loop_new (NULL, FALSE); + _g_main_loop_unref0 (main_loop); + main_loop = _tmp17_; + _tmp18_ = main_loop; + g_main_loop_run (_tmp18_); + _g_variant_unref0 (request_result); + _g_object_unref0 (conn); +} + +int +main (int argc, + char ** argv) +{ + _vala_main (); + return 0; +} + +static void +_vala_array_destroy (gpointer array, + gssize array_length, + GDestroyNotify destroy_func) +{ + if ((array != NULL) && (destroy_func != NULL)) { + gssize i; + for (i = 0; i < array_length; i = i + 1) { + if (((gpointer*) array)[i] != NULL) { + destroy_func (((gpointer*) array)[i]); + } + } + } +} + +static void +_vala_array_free (gpointer array, + gssize array_length, + GDestroyNotify destroy_func) +{ + _vala_array_destroy (array, array_length, destroy_func); + g_free (array); +} + diff --git a/tests/dbus/dicts_client.c-expected b/tests/dbus/dicts_client.c-expected new file mode 100644 index 000000000..d7de6e2fc --- /dev/null +++ b/tests/dbus/dicts_client.c-expected @@ -0,0 +1,487 @@ +/* dbus_dicts_client.c generated by valac, the Vala compiler + * generated from dbus_dicts_client.vala, do not modify */ + +#include <glib-object.h> +#include <gio/gio.h> +#include <glib.h> +#include <stdlib.h> +#include <string.h> + +#if !defined(VALA_EXTERN) +#if defined(_MSC_VER) +#define VALA_EXTERN __declspec(dllexport) extern +#elif __GNUC__ >= 4 +#define VALA_EXTERN __attribute__((visibility("default"))) extern +#else +#define VALA_EXTERN extern +#endif +#endif + +#define TYPE_TEST (test_get_type ()) +#define TEST(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TYPE_TEST, Test)) +#define IS_TEST(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TYPE_TEST)) +#define TEST_GET_INTERFACE(obj) (G_TYPE_INSTANCE_GET_INTERFACE ((obj), TYPE_TEST, TestIface)) + +typedef struct _Test Test; +typedef struct _TestIface TestIface; + +#define TYPE_TEST_PROXY (test_proxy_get_type ()) +typedef GDBusProxy TestProxy; +typedef GDBusProxyClass TestProxyClass; +#define _g_hash_table_unref0(var) ((var == NULL) ? NULL : (var = (g_hash_table_unref (var), NULL))) +#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL))) +#define _g_variant_unref0(var) ((var == NULL) ? NULL : (var = (g_variant_unref (var), NULL))) +#define _vala_assert(expr, msg) if G_LIKELY (expr) ; else g_assertion_message_expr (G_LOG_DOMAIN, __FILE__, __LINE__, G_STRFUNC, msg); +#define _vala_return_if_fail(expr, msg) if G_LIKELY (expr) ; else { g_return_if_fail_warning (G_LOG_DOMAIN, G_STRFUNC, msg); return; } +#define _vala_return_val_if_fail(expr, msg, val) if G_LIKELY (expr) ; else { g_return_if_fail_warning (G_LOG_DOMAIN, G_STRFUNC, msg); return val; } +#define _vala_warn_if_fail(expr, msg) if G_LIKELY (expr) ; else g_warn_message (G_LOG_DOMAIN, __FILE__, __LINE__, G_STRFUNC, msg); + +struct _TestIface { + GTypeInterface parent_iface; + GHashTable* (*test_dict) (Test* self, GError** error); +}; + +VALA_EXTERN GType test_proxy_get_type (void) G_GNUC_CONST ; +VALA_EXTERN guint test_register_object (void* object, + GDBusConnection* connection, + const gchar* path, + GError** error); +VALA_EXTERN GType test_get_type (void) G_GNUC_CONST ; +VALA_EXTERN GHashTable* test_test_dict (Test* self, + GError** error); +static GType test_get_type_once (void); +static void test_proxy_g_signal (GDBusProxy* proxy, + const gchar* sender_name, + const gchar* signal_name, + GVariant* parameters); +static GHashTable* test_proxy_test_dict (Test* self, + GError** error); +static void test_proxy_test_interface_init (TestIface* iface); +static void _dbus_test_test_dict (Test* self, + GVariant* _parameters_, + GDBusMethodInvocation* invocation); +static void test_dbus_interface_method_call (GDBusConnection* connection, + const gchar* sender, + const gchar* object_path, + const gchar* interface_name, + const gchar* method_name, + GVariant* parameters, + GDBusMethodInvocation* invocation, + gpointer user_data); +static GVariant* test_dbus_interface_get_property (GDBusConnection* connection, + const gchar* sender, + const gchar* object_path, + const gchar* interface_name, + const gchar* property_name, + GError** error, + gpointer user_data); +static gboolean test_dbus_interface_set_property (GDBusConnection* connection, + const gchar* sender, + const gchar* object_path, + const gchar* interface_name, + const gchar* property_name, + GVariant* value, + GError** error, + gpointer user_data); +static void _test_unregister_object (gpointer user_data); +static void _vala_main (void); +static gchar** _variant_get1 (GVariant* value, + gint* result_length1); +static void _vala_array_destroy (gpointer array, + gssize array_length, + GDestroyNotify destroy_func); +static void _vala_array_free (gpointer array, + gssize array_length, + GDestroyNotify destroy_func); + +static const GDBusArgInfo _test_dbus_arg_info_test_dict_result = {-1, "result", "a{sv}", NULL}; +static const GDBusArgInfo * const _test_dbus_arg_info_test_dict_in[] = {NULL}; +static const GDBusArgInfo * const _test_dbus_arg_info_test_dict_out[] = {&_test_dbus_arg_info_test_dict_result, NULL}; +static const GDBusMethodInfo _test_dbus_method_info_test_dict = {-1, "TestDict", (GDBusArgInfo **) (&_test_dbus_arg_info_test_dict_in), (GDBusArgInfo **) (&_test_dbus_arg_info_test_dict_out), NULL}; +static const GDBusMethodInfo * const _test_dbus_method_info[] = {&_test_dbus_method_info_test_dict, NULL}; +static const GDBusSignalInfo * const _test_dbus_signal_info[] = {NULL}; +static const GDBusPropertyInfo * const _test_dbus_property_info[] = {NULL}; +static const GDBusInterfaceInfo _test_dbus_interface_info = {-1, "org.example.Test", (GDBusMethodInfo **) (&_test_dbus_method_info), (GDBusSignalInfo **) (&_test_dbus_signal_info), (GDBusPropertyInfo **) (&_test_dbus_property_info), NULL}; +static const GDBusInterfaceVTable _test_dbus_interface_vtable = {test_dbus_interface_method_call, test_dbus_interface_get_property, test_dbus_interface_set_property}; + +GHashTable* +test_test_dict (Test* self, + GError** error) +{ + TestIface* _iface_; + g_return_val_if_fail (IS_TEST (self), NULL); + _iface_ = TEST_GET_INTERFACE (self); + if (_iface_->test_dict) { + return _iface_->test_dict (self, error); + } + return NULL; +} + +static void +test_default_init (TestIface * iface, + gpointer iface_data) +{ +} + +static GType +test_get_type_once (void) +{ + static const GTypeInfo g_define_type_info = { sizeof (TestIface), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) test_default_init, (GClassFinalizeFunc) NULL, NULL, 0, 0, (GInstanceInitFunc) NULL, NULL }; + GType test_type_id; + test_type_id = g_type_register_static (G_TYPE_INTERFACE, "Test", &g_define_type_info, 0); + g_type_interface_add_prerequisite (test_type_id, G_TYPE_OBJECT); + g_type_set_qdata (test_type_id, g_quark_from_static_string ("vala-dbus-proxy-type"), (void*) test_proxy_get_type); + g_type_set_qdata (test_type_id, g_quark_from_static_string ("vala-dbus-interface-name"), "org.example.Test"); + g_type_set_qdata (test_type_id, g_quark_from_static_string ("vala-dbus-interface-info"), (void*) (&_test_dbus_interface_info)); + g_type_set_qdata (test_type_id, g_quark_from_static_string ("vala-dbus-register-object"), (void*) test_register_object); + return test_type_id; +} + +GType +test_get_type (void) +{ + static volatile gsize test_type_id__volatile = 0; + if (g_once_init_enter (&test_type_id__volatile)) { + GType test_type_id; + test_type_id = test_get_type_once (); + g_once_init_leave (&test_type_id__volatile, test_type_id); + } + return test_type_id__volatile; +} + +G_DEFINE_TYPE_EXTENDED (TestProxy, test_proxy, G_TYPE_DBUS_PROXY, 0, G_IMPLEMENT_INTERFACE (TYPE_TEST, test_proxy_test_interface_init) ) +static void +test_proxy_class_init (TestProxyClass* klass) +{ + G_DBUS_PROXY_CLASS (klass)->g_signal = test_proxy_g_signal; +} + +static void +test_proxy_g_signal (GDBusProxy* proxy, + const gchar* sender_name, + const gchar* signal_name, + GVariant* parameters) +{ +} + +static void +test_proxy_init (TestProxy* self) +{ + g_dbus_proxy_set_interface_info (G_DBUS_PROXY (self), (GDBusInterfaceInfo *) (&_test_dbus_interface_info)); +} + +static GHashTable* +test_proxy_test_dict (Test* self, + GError** error) +{ + GDBusMessage *_message; + GVariant *_arguments; + GVariantBuilder _arguments_builder; + GDBusMessage *_reply_message; + GVariant *_reply; + GVariantIter _reply_iter; + GHashTable* _result = NULL; + GVariant* _tmp0_; + GHashTable* _tmp1_; + GVariantIter _tmp2_; + GVariant* _tmp3_; + GVariant* _tmp4_; + G_IO_ERROR; + _message = g_dbus_message_new_method_call (g_dbus_proxy_get_name ((GDBusProxy *) self), g_dbus_proxy_get_object_path ((GDBusProxy *) self), "org.example.Test", "TestDict"); + g_variant_builder_init (&_arguments_builder, G_VARIANT_TYPE_TUPLE); + _arguments = g_variant_builder_end (&_arguments_builder); + g_dbus_message_set_body (_message, _arguments); + _reply_message = g_dbus_connection_send_message_with_reply_sync (g_dbus_proxy_get_connection ((GDBusProxy *) self), _message, G_DBUS_SEND_MESSAGE_FLAGS_NONE, g_dbus_proxy_get_default_timeout ((GDBusProxy *) self), NULL, NULL, error); + g_object_unref (_message); + if (!_reply_message) { + return NULL; + } + if (g_dbus_message_to_gerror (_reply_message, error)) { + g_object_unref (_reply_message); + return NULL; + } + _reply = g_dbus_message_get_body (_reply_message); + g_variant_iter_init (&_reply_iter, _reply); + _tmp0_ = g_variant_iter_next_value (&_reply_iter); + _tmp1_ = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, (GDestroyNotify) g_variant_unref); + g_variant_iter_init (&_tmp2_, _tmp0_); + while (g_variant_iter_loop (&_tmp2_, "{?*}", &_tmp3_, &_tmp4_)) { + g_hash_table_insert (_tmp1_, g_variant_dup_string (_tmp3_, NULL), g_variant_get_variant (_tmp4_)); + } + _result = _tmp1_; + g_variant_unref (_tmp0_); + g_object_unref (_reply_message); + return _result; +} + +static void +test_proxy_test_interface_init (TestIface* iface) +{ + iface->test_dict = test_proxy_test_dict; +} + +static void +_dbus_test_test_dict (Test* self, + GVariant* _parameters_, + GDBusMethodInvocation* invocation) +{ + GError* error = NULL; + GVariantIter _arguments_iter; + GDBusMessage* _reply_message = NULL; + GVariant* _reply; + GVariantBuilder _reply_builder; + GHashTable* result; + GVariantBuilder _tmp5_; + GHashTableIter _tmp6_; + gpointer _tmp7_; + gpointer _tmp8_; + g_variant_iter_init (&_arguments_iter, _parameters_); + result = test_test_dict (self, &error); + if (error) { + g_dbus_method_invocation_return_gerror (invocation, error); + g_error_free (error); + return; + } + _reply_message = g_dbus_message_new_method_reply (g_dbus_method_invocation_get_message (invocation)); + g_variant_builder_init (&_reply_builder, G_VARIANT_TYPE_TUPLE); + g_hash_table_iter_init (&_tmp6_, result); + g_variant_builder_init (&_tmp5_, G_VARIANT_TYPE ("a{sv}")); + while (g_hash_table_iter_next (&_tmp6_, &_tmp7_, &_tmp8_)) { + gchar* _key; + GVariant* _value; + _key = (gchar*) _tmp7_; + _value = (GVariant*) _tmp8_; + g_variant_builder_add (&_tmp5_, "{?*}", g_variant_new_string (_key), g_variant_new_variant (_value)); + } + g_variant_builder_add_value (&_reply_builder, g_variant_builder_end (&_tmp5_)); + _g_hash_table_unref0 (result); + _reply = g_variant_builder_end (&_reply_builder); + g_dbus_message_set_body (_reply_message, _reply); + g_dbus_connection_send_message (g_dbus_method_invocation_get_connection (invocation), _reply_message, G_DBUS_SEND_MESSAGE_FLAGS_NONE, NULL, NULL); + g_object_unref (invocation); + g_object_unref (_reply_message); +} + +static void +test_dbus_interface_method_call (GDBusConnection* connection, + const gchar* sender, + const gchar* object_path, + const gchar* interface_name, + const gchar* method_name, + GVariant* parameters, + GDBusMethodInvocation* invocation, + gpointer user_data) +{ + gpointer* data; + gpointer object; + data = user_data; + object = data[0]; + if (strcmp (method_name, "TestDict") == 0) { + _dbus_test_test_dict (object, parameters, invocation); + } else { + g_object_unref (invocation); + } +} + +static GVariant* +test_dbus_interface_get_property (GDBusConnection* connection, + const gchar* sender, + const gchar* object_path, + const gchar* interface_name, + const gchar* property_name, + GError** error, + gpointer user_data) +{ + gpointer* data; + gpointer object; + data = user_data; + object = data[0]; + return NULL; +} + +static gboolean +test_dbus_interface_set_property (GDBusConnection* connection, + const gchar* sender, + const gchar* object_path, + const gchar* interface_name, + const gchar* property_name, + GVariant* value, + GError** error, + gpointer user_data) +{ + gpointer* data; + gpointer object; + data = user_data; + object = data[0]; + return FALSE; +} + +guint +test_register_object (gpointer object, + GDBusConnection* connection, + const gchar* path, + GError** error) +{ + guint result; + gpointer *data; + data = g_new (gpointer, 3); + data[0] = g_object_ref (object); + data[1] = g_object_ref (connection); + data[2] = g_strdup (path); + result = g_dbus_connection_register_object (connection, path, (GDBusInterfaceInfo *) (&_test_dbus_interface_info), &_test_dbus_interface_vtable, data, _test_unregister_object, error); + if (!result) { + return 0; + } + return result; +} + +static void +_test_unregister_object (gpointer user_data) +{ + gpointer* data; + data = user_data; + g_object_unref (data[0]); + g_object_unref (data[1]); + g_free (data[2]); + g_free (data); +} + +static gpointer +_g_variant_ref0 (gpointer self) +{ + return self ? g_variant_ref (self) : NULL; +} + +static gchar** +_variant_get1 (GVariant* value, + gint* result_length1) +{ + gchar** _tmp10_; + gint _tmp10__length; + gint _tmp10__size; + gint _tmp10__length1; + GVariantIter _tmp11_; + GVariant* _tmp12_; + _tmp10_ = g_new (gchar*, 5); + _tmp10__length = 0; + _tmp10__size = 4; + _tmp10__length1 = 0; + g_variant_iter_init (&_tmp11_, value); + for (; (_tmp12_ = g_variant_iter_next_value (&_tmp11_)) != NULL; _tmp10__length1++) { + if (_tmp10__size == _tmp10__length) { + _tmp10__size = 2 * _tmp10__size; + _tmp10_ = g_renew (gchar*, _tmp10_, _tmp10__size + 1); + } + _tmp10_[_tmp10__length++] = g_variant_dup_string (_tmp12_, NULL); + g_variant_unref (_tmp12_); + } + *result_length1 = _tmp10__length1; + _tmp10_[_tmp10__length] = NULL; + return _tmp10_; +} + +static void +_vala_main (void) +{ + Test* test = NULL; + Test* _tmp0_; + GHashTable* dict = NULL; + Test* _tmp1_; + GHashTable* _tmp2_; + GHashTable* _tmp3_; + GVariant* v = NULL; + GHashTable* _tmp4_; + gconstpointer _tmp5_; + GVariant* _tmp6_; + GVariant* _tmp7_; + gchar** s = NULL; + GVariant* _tmp8_; + gchar** _tmp9_ = NULL; + gint _tmp9__length1 = 0; + gint s_length1; + gint _s_size_; + gboolean _tmp13_ = FALSE; + gchar** _tmp14_; + gint _tmp14__length1; + GError* _inner_error0_ = NULL; + _tmp0_ = (Test*) g_initable_new (TYPE_TEST_PROXY, NULL, &_inner_error0_, "g-flags", 0, "g-name", "org.example.Test", "g-bus-type", G_BUS_TYPE_SESSION, "g-object-path", "/org/example/test", "g-interface-name", "org.example.Test", NULL); + test = (Test*) _tmp0_; + if (G_UNLIKELY (_inner_error0_ != NULL)) { + g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error0_->message, g_quark_to_string (_inner_error0_->domain), _inner_error0_->code); + g_clear_error (&_inner_error0_); + return; + } + _tmp1_ = test; + _tmp2_ = test_test_dict (_tmp1_, &_inner_error0_); + dict = _tmp2_; + if (G_UNLIKELY (_inner_error0_ != NULL)) { + _g_object_unref0 (test); + g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error0_->message, g_quark_to_string (_inner_error0_->domain), _inner_error0_->code); + g_clear_error (&_inner_error0_); + return; + } + _tmp3_ = dict; + _vala_assert (g_hash_table_size (_tmp3_) == ((guint) 1), "dict.size () == 1"); + _tmp4_ = dict; + _tmp5_ = g_hash_table_lookup (_tmp4_, "hello"); + _tmp6_ = _g_variant_ref0 ((GVariant*) _tmp5_); + v = _tmp6_; + _tmp7_ = v; + _vala_assert (_tmp7_ != NULL, "v != null"); + _tmp8_ = v; + _tmp9_ = _variant_get1 (_tmp8_, &_tmp9__length1); + s = _tmp9_; + s_length1 = _tmp9__length1; + _s_size_ = s_length1; + _tmp14_ = s; + _tmp14__length1 = s_length1; + if (_tmp14__length1 == 1) { + gchar** _tmp15_; + gint _tmp15__length1; + const gchar* _tmp16_; + _tmp15_ = s; + _tmp15__length1 = s_length1; + _tmp16_ = _tmp15_[0]; + _tmp13_ = g_strcmp0 (_tmp16_, "hello") == 0; + } else { + _tmp13_ = FALSE; + } + _vala_assert (_tmp13_, "s.length == 1 && s[0] == \"hello\""); + s = (_vala_array_free (s, s_length1, (GDestroyNotify) g_free), NULL); + _g_variant_unref0 (v); + _g_hash_table_unref0 (dict); + _g_object_unref0 (test); +} + +int +main (int argc, + char ** argv) +{ + _vala_main (); + return 0; +} + +static void +_vala_array_destroy (gpointer array, + gssize array_length, + GDestroyNotify destroy_func) +{ + if ((array != NULL) && (destroy_func != NULL)) { + gssize i; + for (i = 0; i < array_length; i = i + 1) { + if (((gpointer*) array)[i] != NULL) { + destroy_func (((gpointer*) array)[i]); + } + } + } +} + +static void +_vala_array_free (gpointer array, + gssize array_length, + GDestroyNotify destroy_func) +{ + _vala_array_destroy (array, array_length, destroy_func); + g_free (array); +} + diff --git a/tests/dbus/dicts_server.c-expected b/tests/dbus/dicts_server.c-expected new file mode 100644 index 000000000..90cafa765 --- /dev/null +++ b/tests/dbus/dicts_server.c-expected @@ -0,0 +1,917 @@ +/* dbus_dicts_server.c generated by valac, the Vala compiler + * generated from dbus_dicts_server.vala, do not modify */ + +#include <glib-object.h> +#include <gio/gio.h> +#include <glib.h> +#include <stdlib.h> +#include <string.h> + +#if !defined(VALA_EXTERN) +#if defined(_MSC_VER) +#define VALA_EXTERN __declspec(dllexport) extern +#elif __GNUC__ >= 4 +#define VALA_EXTERN __attribute__((visibility("default"))) extern +#else +#define VALA_EXTERN extern +#endif +#endif + +#define TYPE_TEST (test_get_type ()) +#define TEST(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TYPE_TEST, Test)) +#define TEST_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), TYPE_TEST, TestClass)) +#define IS_TEST(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TYPE_TEST)) +#define IS_TEST_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), TYPE_TEST)) +#define TEST_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), TYPE_TEST, TestClass)) + +typedef struct _Test Test; +typedef struct _TestClass TestClass; +typedef struct _TestPrivate TestPrivate; +enum { + TEST_0_PROPERTY, + TEST_NUM_PROPERTIES +}; +static GParamSpec* test_properties[TEST_NUM_PROPERTIES]; +#define _g_hash_table_unref0(var) ((var == NULL) ? NULL : (var = (g_hash_table_unref (var), NULL))) + +#define TEST_INTERFACE_TYPE_BAR (test_interface_bar_get_type ()) +#define TEST_INTERFACE_BAR(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TEST_INTERFACE_TYPE_BAR, TestInterfaceBar)) +#define TEST_INTERFACE_IS_BAR(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TEST_INTERFACE_TYPE_BAR)) +#define TEST_INTERFACE_BAR_GET_INTERFACE(obj) (G_TYPE_INSTANCE_GET_INTERFACE ((obj), TEST_INTERFACE_TYPE_BAR, TestInterfaceBarIface)) + +typedef struct _TestInterfaceBar TestInterfaceBar; +typedef struct _TestInterfaceBarIface TestInterfaceBarIface; + +#define TEST_INTERFACE_TYPE_BAR_PROXY (test_interface_bar_proxy_get_type ()) +typedef GDBusProxy TestInterfaceBarProxy; +typedef GDBusProxyClass TestInterfaceBarProxyClass; + +#define TEST_INTERFACE_TYPE_FOO (test_interface_foo_get_type ()) +#define TEST_INTERFACE_FOO(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TEST_INTERFACE_TYPE_FOO, TestInterfaceFoo)) +#define TEST_INTERFACE_FOO_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), TEST_INTERFACE_TYPE_FOO, TestInterfaceFooClass)) +#define TEST_INTERFACE_IS_FOO(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TEST_INTERFACE_TYPE_FOO)) +#define TEST_INTERFACE_IS_FOO_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), TEST_INTERFACE_TYPE_FOO)) +#define TEST_INTERFACE_FOO_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), TEST_INTERFACE_TYPE_FOO, TestInterfaceFooClass)) + +typedef struct _TestInterfaceFoo TestInterfaceFoo; +typedef struct _TestInterfaceFooClass TestInterfaceFooClass; +typedef struct _TestInterfaceFooPrivate TestInterfaceFooPrivate; +enum { + TEST_INTERFACE_FOO_0_PROPERTY, + TEST_INTERFACE_FOO_NUM_PROPERTIES +}; +static GParamSpec* test_interface_foo_properties[TEST_INTERFACE_FOO_NUM_PROPERTIES]; +#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL))) +#define _g_variant_unref0(var) ((var == NULL) ? NULL : (var = (g_variant_unref (var), NULL))) +#define _g_main_loop_unref0(var) ((var == NULL) ? NULL : (var = (g_main_loop_unref (var), NULL))) +#define _vala_assert(expr, msg) if G_LIKELY (expr) ; else g_assertion_message_expr (G_LOG_DOMAIN, __FILE__, __LINE__, G_STRFUNC, msg); +#define _vala_return_if_fail(expr, msg) if G_LIKELY (expr) ; else { g_return_if_fail_warning (G_LOG_DOMAIN, G_STRFUNC, msg); return; } +#define _vala_return_val_if_fail(expr, msg, val) if G_LIKELY (expr) ; else { g_return_if_fail_warning (G_LOG_DOMAIN, G_STRFUNC, msg); return val; } +#define _vala_warn_if_fail(expr, msg) if G_LIKELY (expr) ; else g_warn_message (G_LOG_DOMAIN, __FILE__, __LINE__, G_STRFUNC, msg); + +struct _Test { + GObject parent_instance; + TestPrivate * priv; +}; + +struct _TestClass { + GObjectClass parent_class; +}; + +struct _TestInterfaceBarIface { + GTypeInterface parent_iface; + GHashTable* (*foo) (TestInterfaceBar* self, GError** error); +}; + +struct _TestInterfaceFoo { + GDBusProxy parent_instance; + TestInterfaceFooPrivate * priv; +}; + +struct _TestInterfaceFooClass { + GDBusProxyClass parent_class; +}; + +static gpointer test_parent_class = NULL; +static gpointer test_interface_foo_parent_class = NULL; +static TestInterfaceBarIface * test_interface_foo_test_interface_bar_parent_iface = NULL; +VALA_EXTERN GMainLoop* main_loop; +GMainLoop* main_loop = NULL; + +VALA_EXTERN GType test_get_type (void) G_GNUC_CONST ; +G_DEFINE_AUTOPTR_CLEANUP_FUNC (Test, g_object_unref) +VALA_EXTERN guint test_register_object (void* object, + GDBusConnection* connection, + const gchar* path, + GError** error); +VALA_EXTERN GHashTable* test_test_dict (Test* self); +static void _g_free0_ (gpointer var); +static void _g_variant_unref0_ (gpointer var); +static GVariant* _variant_new1 (gchar** value, + gint value_length1); +VALA_EXTERN Test* test_new (void); +VALA_EXTERN Test* test_construct (GType object_type); +static GType test_get_type_once (void); +static void _dbus_test_test_dict (Test* self, + GVariant* _parameters_, + GDBusMethodInvocation* invocation); +static void test_dbus_interface_method_call (GDBusConnection* connection, + const gchar* sender, + const gchar* object_path, + const gchar* interface_name, + const gchar* method_name, + GVariant* parameters, + GDBusMethodInvocation* invocation, + gpointer user_data); +static GVariant* test_dbus_interface_get_property (GDBusConnection* connection, + const gchar* sender, + const gchar* object_path, + const gchar* interface_name, + const gchar* property_name, + GError** error, + gpointer user_data); +static gboolean test_dbus_interface_set_property (GDBusConnection* connection, + const gchar* sender, + const gchar* object_path, + const gchar* interface_name, + const gchar* property_name, + GVariant* value, + GError** error, + gpointer user_data); +static void _test_unregister_object (gpointer user_data); +VALA_EXTERN GType test_interface_bar_proxy_get_type (void) G_GNUC_CONST ; +VALA_EXTERN guint test_interface_bar_register_object (void* object, + GDBusConnection* connection, + const gchar* path, + GError** error); +VALA_EXTERN GType test_interface_bar_get_type (void) G_GNUC_CONST ; +VALA_EXTERN GHashTable* test_interface_bar_foo (TestInterfaceBar* self, + GError** error); +static GType test_interface_bar_get_type_once (void); +static void test_interface_bar_proxy_g_signal (GDBusProxy* proxy, + const gchar* sender_name, + const gchar* signal_name, + GVariant* parameters); +static GHashTable* test_interface_bar_proxy_foo (TestInterfaceBar* self, + GError** error); +static void test_interface_bar_proxy_test_interface_bar_interface_init (TestInterfaceBarIface* iface); +static void _dbus_test_interface_bar_foo (TestInterfaceBar* self, + GVariant* _parameters_, + GDBusMethodInvocation* invocation); +static void test_interface_bar_dbus_interface_method_call (GDBusConnection* connection, + const gchar* sender, + const gchar* object_path, + const gchar* interface_name, + const gchar* method_name, + GVariant* parameters, + GDBusMethodInvocation* invocation, + gpointer user_data); +static GVariant* test_interface_bar_dbus_interface_get_property (GDBusConnection* connection, + const gchar* sender, + const gchar* object_path, + const gchar* interface_name, + const gchar* property_name, + GError** error, + gpointer user_data); +static gboolean test_interface_bar_dbus_interface_set_property (GDBusConnection* connection, + const gchar* sender, + const gchar* object_path, + const gchar* interface_name, + const gchar* property_name, + GVariant* value, + GError** error, + gpointer user_data); +static void _test_interface_bar_unregister_object (gpointer user_data); +VALA_EXTERN GType test_interface_foo_get_type (void) G_GNUC_CONST ; +G_DEFINE_AUTOPTR_CLEANUP_FUNC (TestInterfaceFoo, g_object_unref) +static GHashTable* test_interface_foo_real_foo (TestInterfaceBar* base, + GError** error); +VALA_EXTERN TestInterfaceFoo* test_interface_foo_new (void); +VALA_EXTERN TestInterfaceFoo* test_interface_foo_construct (GType object_type); +static GType test_interface_foo_get_type_once (void); +VALA_EXTERN void client_exit (GPid pid, + gint status); +static void _vala_main (void); +static guint _variant_get1 (GVariant* value); +static void _client_exit_gchild_watch_func (GPid pid, + gint wait_status, + gpointer self); +static void _vala_array_destroy (gpointer array, + gssize array_length, + GDestroyNotify destroy_func); +static void _vala_array_free (gpointer array, + gssize array_length, + GDestroyNotify destroy_func); + +static const GDBusArgInfo _test_dbus_arg_info_test_dict_result = {-1, "result", "a{sv}", NULL}; +static const GDBusArgInfo * const _test_dbus_arg_info_test_dict_in[] = {NULL}; +static const GDBusArgInfo * const _test_dbus_arg_info_test_dict_out[] = {&_test_dbus_arg_info_test_dict_result, NULL}; +static const GDBusMethodInfo _test_dbus_method_info_test_dict = {-1, "TestDict", (GDBusArgInfo **) (&_test_dbus_arg_info_test_dict_in), (GDBusArgInfo **) (&_test_dbus_arg_info_test_dict_out), NULL}; +static const GDBusMethodInfo * const _test_dbus_method_info[] = {&_test_dbus_method_info_test_dict, NULL}; +static const GDBusSignalInfo * const _test_dbus_signal_info[] = {NULL}; +static const GDBusPropertyInfo * const _test_dbus_property_info[] = {NULL}; +static const GDBusInterfaceInfo _test_dbus_interface_info = {-1, "org.example.Test", (GDBusMethodInfo **) (&_test_dbus_method_info), (GDBusSignalInfo **) (&_test_dbus_signal_info), (GDBusPropertyInfo **) (&_test_dbus_property_info), NULL}; +static const GDBusInterfaceVTable _test_dbus_interface_vtable = {test_dbus_interface_method_call, test_dbus_interface_get_property, test_dbus_interface_set_property}; +static const GDBusArgInfo _test_interface_bar_dbus_arg_info_foo_result = {-1, "result", "a{sv}", NULL}; +static const GDBusArgInfo * const _test_interface_bar_dbus_arg_info_foo_in[] = {NULL}; +static const GDBusArgInfo * const _test_interface_bar_dbus_arg_info_foo_out[] = {&_test_interface_bar_dbus_arg_info_foo_result, NULL}; +static const GDBusMethodInfo _test_interface_bar_dbus_method_info_foo = {-1, "Foo", (GDBusArgInfo **) (&_test_interface_bar_dbus_arg_info_foo_in), (GDBusArgInfo **) (&_test_interface_bar_dbus_arg_info_foo_out), NULL}; +static const GDBusMethodInfo * const _test_interface_bar_dbus_method_info[] = {&_test_interface_bar_dbus_method_info_foo, NULL}; +static const GDBusSignalInfo * const _test_interface_bar_dbus_signal_info[] = {NULL}; +static const GDBusPropertyInfo * const _test_interface_bar_dbus_property_info[] = {NULL}; +static const GDBusInterfaceInfo _test_interface_bar_dbus_interface_info = {-1, "org.vala.Test.Bar", (GDBusMethodInfo **) (&_test_interface_bar_dbus_method_info), (GDBusSignalInfo **) (&_test_interface_bar_dbus_signal_info), (GDBusPropertyInfo **) (&_test_interface_bar_dbus_property_info), NULL}; +static const GDBusInterfaceVTable _test_interface_bar_dbus_interface_vtable = {test_interface_bar_dbus_interface_method_call, test_interface_bar_dbus_interface_get_property, test_interface_bar_dbus_interface_set_property}; + +static void +_g_free0_ (gpointer var) +{ + var = (g_free (var), NULL); +} + +static void +_g_variant_unref0_ (gpointer var) +{ + (var == NULL) ? NULL : (var = (g_variant_unref (var), NULL)); +} + +static GVariant* +_variant_new1 (gchar** value, + gint value_length1) +{ + gchar** _tmp5_; + GVariantBuilder _tmp6_; + gint _tmp7_; + _tmp5_ = value; + g_variant_builder_init (&_tmp6_, G_VARIANT_TYPE ("as")); + for (_tmp7_ = 0; _tmp7_ < value_length1; _tmp7_++) { + g_variant_builder_add_value (&_tmp6_, g_variant_new_string (*_tmp5_)); + _tmp5_++; + } + return g_variant_ref_sink (g_variant_builder_end (&_tmp6_)); +} + +GHashTable* +test_test_dict (Test* self) +{ + gchar** s = NULL; + gchar* _tmp0_; + gchar** _tmp1_; + gint s_length1; + gint _s_size_; + GHashTable* dict = NULL; + GHashFunc _tmp2_; + GHashTable* _tmp3_; + gchar* _tmp4_; + GVariant* _tmp8_; + GHashTable* result = NULL; + g_return_val_if_fail (IS_TEST (self), NULL); + _tmp0_ = g_strdup ("hello"); + _tmp1_ = g_new0 (gchar*, 1 + 1); + _tmp1_[0] = _tmp0_; + s = _tmp1_; + s_length1 = 1; + _s_size_ = s_length1; + _tmp2_ = g_str_hash; + _tmp3_ = g_hash_table_new_full (_tmp2_, NULL, _g_free0_, _g_variant_unref0_); + dict = _tmp3_; + _tmp4_ = g_strdup ("hello"); + _tmp8_ = _variant_new1 (s, s_length1); + g_hash_table_insert (dict, _tmp4_, _tmp8_); + result = dict; + s = (_vala_array_free (s, s_length1, (GDestroyNotify) g_free), NULL); + return result; +} + +Test* +test_construct (GType object_type) +{ + Test * self = NULL; + self = (Test*) g_object_new (object_type, NULL); + return self; +} + +Test* +test_new (void) +{ + return test_construct (TYPE_TEST); +} + +static void +test_class_init (TestClass * klass, + gpointer klass_data) +{ + test_parent_class = g_type_class_peek_parent (klass); +} + +static void +test_instance_init (Test * self, + gpointer klass) +{ +} + +static GType +test_get_type_once (void) +{ + static const GTypeInfo g_define_type_info = { sizeof (TestClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) test_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (Test), 0, (GInstanceInitFunc) test_instance_init, NULL }; + GType test_type_id; + test_type_id = g_type_register_static (G_TYPE_OBJECT, "Test", &g_define_type_info, 0); + g_type_set_qdata (test_type_id, g_quark_from_static_string ("vala-dbus-register-object"), (void*) test_register_object); + return test_type_id; +} + +GType +test_get_type (void) +{ + static volatile gsize test_type_id__volatile = 0; + if (g_once_init_enter (&test_type_id__volatile)) { + GType test_type_id; + test_type_id = test_get_type_once (); + g_once_init_leave (&test_type_id__volatile, test_type_id); + } + return test_type_id__volatile; +} + +static void +_dbus_test_test_dict (Test* self, + GVariant* _parameters_, + GDBusMethodInvocation* invocation) +{ + GError* error = NULL; + GVariantIter _arguments_iter; + GDBusMessage* _reply_message = NULL; + GVariant* _reply; + GVariantBuilder _reply_builder; + GHashTable* result; + GVariantBuilder _tmp0_; + GHashTableIter _tmp1_; + gpointer _tmp2_; + gpointer _tmp3_; + g_variant_iter_init (&_arguments_iter, _parameters_); + result = test_test_dict (self); + _reply_message = g_dbus_message_new_method_reply (g_dbus_method_invocation_get_message (invocation)); + g_variant_builder_init (&_reply_builder, G_VARIANT_TYPE_TUPLE); + g_hash_table_iter_init (&_tmp1_, result); + g_variant_builder_init (&_tmp0_, G_VARIANT_TYPE ("a{sv}")); + while (g_hash_table_iter_next (&_tmp1_, &_tmp2_, &_tmp3_)) { + gchar* _key; + GVariant* _value; + _key = (gchar*) _tmp2_; + _value = (GVariant*) _tmp3_; + g_variant_builder_add (&_tmp0_, "{?*}", g_variant_new_string (_key), g_variant_new_variant (_value)); + } + g_variant_builder_add_value (&_reply_builder, g_variant_builder_end (&_tmp0_)); + _g_hash_table_unref0 (result); + _reply = g_variant_builder_end (&_reply_builder); + g_dbus_message_set_body (_reply_message, _reply); + g_dbus_connection_send_message (g_dbus_method_invocation_get_connection (invocation), _reply_message, G_DBUS_SEND_MESSAGE_FLAGS_NONE, NULL, NULL); + g_object_unref (invocation); + g_object_unref (_reply_message); +} + +static void +test_dbus_interface_method_call (GDBusConnection* connection, + const gchar* sender, + const gchar* object_path, + const gchar* interface_name, + const gchar* method_name, + GVariant* parameters, + GDBusMethodInvocation* invocation, + gpointer user_data) +{ + gpointer* data; + gpointer object; + data = user_data; + object = data[0]; + if (strcmp (method_name, "TestDict") == 0) { + _dbus_test_test_dict (object, parameters, invocation); + } else { + g_object_unref (invocation); + } +} + +static GVariant* +test_dbus_interface_get_property (GDBusConnection* connection, + const gchar* sender, + const gchar* object_path, + const gchar* interface_name, + const gchar* property_name, + GError** error, + gpointer user_data) +{ + gpointer* data; + gpointer object; + data = user_data; + object = data[0]; + return NULL; +} + +static gboolean +test_dbus_interface_set_property (GDBusConnection* connection, + const gchar* sender, + const gchar* object_path, + const gchar* interface_name, + const gchar* property_name, + GVariant* value, + GError** error, + gpointer user_data) +{ + gpointer* data; + gpointer object; + data = user_data; + object = data[0]; + return FALSE; +} + +guint +test_register_object (gpointer object, + GDBusConnection* connection, + const gchar* path, + GError** error) +{ + guint result; + gpointer *data; + data = g_new (gpointer, 3); + data[0] = g_object_ref (object); + data[1] = g_object_ref (connection); + data[2] = g_strdup (path); + result = g_dbus_connection_register_object (connection, path, (GDBusInterfaceInfo *) (&_test_dbus_interface_info), &_test_dbus_interface_vtable, data, _test_unregister_object, error); + if (!result) { + return 0; + } + return result; +} + +static void +_test_unregister_object (gpointer user_data) +{ + gpointer* data; + data = user_data; + g_object_unref (data[0]); + g_object_unref (data[1]); + g_free (data[2]); + g_free (data); +} + +GHashTable* +test_interface_bar_foo (TestInterfaceBar* self, + GError** error) +{ + TestInterfaceBarIface* _iface_; + g_return_val_if_fail (TEST_INTERFACE_IS_BAR (self), NULL); + _iface_ = TEST_INTERFACE_BAR_GET_INTERFACE (self); + if (_iface_->foo) { + return _iface_->foo (self, error); + } + return NULL; +} + +static void +test_interface_bar_default_init (TestInterfaceBarIface * iface, + gpointer iface_data) +{ +} + +static GType +test_interface_bar_get_type_once (void) +{ + static const GTypeInfo g_define_type_info = { sizeof (TestInterfaceBarIface), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) test_interface_bar_default_init, (GClassFinalizeFunc) NULL, NULL, 0, 0, (GInstanceInitFunc) NULL, NULL }; + GType test_interface_bar_type_id; + test_interface_bar_type_id = g_type_register_static (G_TYPE_INTERFACE, "TestInterfaceBar", &g_define_type_info, 0); + g_type_interface_add_prerequisite (test_interface_bar_type_id, G_TYPE_OBJECT); + g_type_set_qdata (test_interface_bar_type_id, g_quark_from_static_string ("vala-dbus-proxy-type"), (void*) test_interface_bar_proxy_get_type); + g_type_set_qdata (test_interface_bar_type_id, g_quark_from_static_string ("vala-dbus-interface-name"), "org.vala.Test.Bar"); + g_type_set_qdata (test_interface_bar_type_id, g_quark_from_static_string ("vala-dbus-interface-info"), (void*) (&_test_interface_bar_dbus_interface_info)); + g_type_set_qdata (test_interface_bar_type_id, g_quark_from_static_string ("vala-dbus-register-object"), (void*) test_interface_bar_register_object); + return test_interface_bar_type_id; +} + +GType +test_interface_bar_get_type (void) +{ + static volatile gsize test_interface_bar_type_id__volatile = 0; + if (g_once_init_enter (&test_interface_bar_type_id__volatile)) { + GType test_interface_bar_type_id; + test_interface_bar_type_id = test_interface_bar_get_type_once (); + g_once_init_leave (&test_interface_bar_type_id__volatile, test_interface_bar_type_id); + } + return test_interface_bar_type_id__volatile; +} + +G_DEFINE_TYPE_EXTENDED (TestInterfaceBarProxy, test_interface_bar_proxy, G_TYPE_DBUS_PROXY, 0, G_IMPLEMENT_INTERFACE (TEST_INTERFACE_TYPE_BAR, test_interface_bar_proxy_test_interface_bar_interface_init) ) +static void +test_interface_bar_proxy_class_init (TestInterfaceBarProxyClass* klass) +{ + G_DBUS_PROXY_CLASS (klass)->g_signal = test_interface_bar_proxy_g_signal; +} + +static void +test_interface_bar_proxy_g_signal (GDBusProxy* proxy, + const gchar* sender_name, + const gchar* signal_name, + GVariant* parameters) +{ +} + +static void +test_interface_bar_proxy_init (TestInterfaceBarProxy* self) +{ + g_dbus_proxy_set_interface_info (G_DBUS_PROXY (self), (GDBusInterfaceInfo *) (&_test_interface_bar_dbus_interface_info)); +} + +static GHashTable* +test_interface_bar_proxy_foo (TestInterfaceBar* self, + GError** error) +{ + GDBusMessage *_message; + GVariant *_arguments; + GVariantBuilder _arguments_builder; + GDBusMessage *_reply_message; + GVariant *_reply; + GVariantIter _reply_iter; + GHashTable* _result = NULL; + GVariant* _tmp4_; + GHashTable* _tmp5_; + GVariantIter _tmp6_; + GVariant* _tmp7_; + GVariant* _tmp8_; + G_IO_ERROR; + _message = g_dbus_message_new_method_call (g_dbus_proxy_get_name ((GDBusProxy *) self), g_dbus_proxy_get_object_path ((GDBusProxy *) self), "org.vala.Test.Bar", "Foo"); + g_variant_builder_init (&_arguments_builder, G_VARIANT_TYPE_TUPLE); + _arguments = g_variant_builder_end (&_arguments_builder); + g_dbus_message_set_body (_message, _arguments); + _reply_message = g_dbus_connection_send_message_with_reply_sync (g_dbus_proxy_get_connection ((GDBusProxy *) self), _message, G_DBUS_SEND_MESSAGE_FLAGS_NONE, g_dbus_proxy_get_default_timeout ((GDBusProxy *) self), NULL, NULL, error); + g_object_unref (_message); + if (!_reply_message) { + return NULL; + } + if (g_dbus_message_to_gerror (_reply_message, error)) { + g_object_unref (_reply_message); + return NULL; + } + _reply = g_dbus_message_get_body (_reply_message); + g_variant_iter_init (&_reply_iter, _reply); + _tmp4_ = g_variant_iter_next_value (&_reply_iter); + _tmp5_ = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, (GDestroyNotify) g_variant_unref); + g_variant_iter_init (&_tmp6_, _tmp4_); + while (g_variant_iter_loop (&_tmp6_, "{?*}", &_tmp7_, &_tmp8_)) { + g_hash_table_insert (_tmp5_, g_variant_dup_string (_tmp7_, NULL), g_variant_get_variant (_tmp8_)); + } + _result = _tmp5_; + g_variant_unref (_tmp4_); + g_object_unref (_reply_message); + return _result; +} + +static void +test_interface_bar_proxy_test_interface_bar_interface_init (TestInterfaceBarIface* iface) +{ + iface->foo = test_interface_bar_proxy_foo; +} + +static void +_dbus_test_interface_bar_foo (TestInterfaceBar* self, + GVariant* _parameters_, + GDBusMethodInvocation* invocation) +{ + GError* error = NULL; + GVariantIter _arguments_iter; + GDBusMessage* _reply_message = NULL; + GVariant* _reply; + GVariantBuilder _reply_builder; + GHashTable* result; + GVariantBuilder _tmp9_; + GHashTableIter _tmp10_; + gpointer _tmp11_; + gpointer _tmp12_; + g_variant_iter_init (&_arguments_iter, _parameters_); + result = test_interface_bar_foo (self, &error); + if (error) { + g_dbus_method_invocation_return_gerror (invocation, error); + g_error_free (error); + return; + } + _reply_message = g_dbus_message_new_method_reply (g_dbus_method_invocation_get_message (invocation)); + g_variant_builder_init (&_reply_builder, G_VARIANT_TYPE_TUPLE); + g_hash_table_iter_init (&_tmp10_, result); + g_variant_builder_init (&_tmp9_, G_VARIANT_TYPE ("a{sv}")); + while (g_hash_table_iter_next (&_tmp10_, &_tmp11_, &_tmp12_)) { + gchar* _key; + GVariant* _value; + _key = (gchar*) _tmp11_; + _value = (GVariant*) _tmp12_; + g_variant_builder_add (&_tmp9_, "{?*}", g_variant_new_string (_key), g_variant_new_variant (_value)); + } + g_variant_builder_add_value (&_reply_builder, g_variant_builder_end (&_tmp9_)); + _g_hash_table_unref0 (result); + _reply = g_variant_builder_end (&_reply_builder); + g_dbus_message_set_body (_reply_message, _reply); + g_dbus_connection_send_message (g_dbus_method_invocation_get_connection (invocation), _reply_message, G_DBUS_SEND_MESSAGE_FLAGS_NONE, NULL, NULL); + g_object_unref (invocation); + g_object_unref (_reply_message); +} + +static void +test_interface_bar_dbus_interface_method_call (GDBusConnection* connection, + const gchar* sender, + const gchar* object_path, + const gchar* interface_name, + const gchar* method_name, + GVariant* parameters, + GDBusMethodInvocation* invocation, + gpointer user_data) +{ + gpointer* data; + gpointer object; + data = user_data; + object = data[0]; + if (strcmp (method_name, "Foo") == 0) { + _dbus_test_interface_bar_foo (object, parameters, invocation); + } else { + g_object_unref (invocation); + } +} + +static GVariant* +test_interface_bar_dbus_interface_get_property (GDBusConnection* connection, + const gchar* sender, + const gchar* object_path, + const gchar* interface_name, + const gchar* property_name, + GError** error, + gpointer user_data) +{ + gpointer* data; + gpointer object; + data = user_data; + object = data[0]; + return NULL; +} + +static gboolean +test_interface_bar_dbus_interface_set_property (GDBusConnection* connection, + const gchar* sender, + const gchar* object_path, + const gchar* interface_name, + const gchar* property_name, + GVariant* value, + GError** error, + gpointer user_data) +{ + gpointer* data; + gpointer object; + data = user_data; + object = data[0]; + return FALSE; +} + +guint +test_interface_bar_register_object (gpointer object, + GDBusConnection* connection, + const gchar* path, + GError** error) +{ + guint result; + gpointer *data; + data = g_new (gpointer, 3); + data[0] = g_object_ref (object); + data[1] = g_object_ref (connection); + data[2] = g_strdup (path); + result = g_dbus_connection_register_object (connection, path, (GDBusInterfaceInfo *) (&_test_interface_bar_dbus_interface_info), &_test_interface_bar_dbus_interface_vtable, data, _test_interface_bar_unregister_object, error); + if (!result) { + return 0; + } + return result; +} + +static void +_test_interface_bar_unregister_object (gpointer user_data) +{ + gpointer* data; + data = user_data; + g_object_unref (data[0]); + g_object_unref (data[1]); + g_free (data[2]); + g_free (data); +} + +static GHashTable* +test_interface_foo_real_foo (TestInterfaceBar* base, + GError** error) +{ + TestInterfaceFoo * self; + GHashFunc _tmp0_; + GEqualFunc _tmp1_; + GHashTable* _tmp2_; + GHashTable* result = NULL; + self = G_TYPE_CHECK_INSTANCE_CAST (base, TEST_INTERFACE_TYPE_FOO, TestInterfaceFoo); + _tmp0_ = g_str_hash; + _tmp1_ = g_str_equal; + _tmp2_ = g_hash_table_new_full (_tmp0_, _tmp1_, _g_free0_, _g_variant_unref0_); + result = _tmp2_; + return result; +} + +TestInterfaceFoo* +test_interface_foo_construct (GType object_type) +{ + TestInterfaceFoo * self = NULL; + self = (TestInterfaceFoo*) g_object_new (object_type, NULL); + return self; +} + +TestInterfaceFoo* +test_interface_foo_new (void) +{ + return test_interface_foo_construct (TEST_INTERFACE_TYPE_FOO); +} + +static void +test_interface_foo_class_init (TestInterfaceFooClass * klass, + gpointer klass_data) +{ + test_interface_foo_parent_class = g_type_class_peek_parent (klass); +} + +static void +test_interface_foo_test_interface_bar_interface_init (TestInterfaceBarIface * iface, + gpointer iface_data) +{ + test_interface_foo_test_interface_bar_parent_iface = g_type_interface_peek_parent (iface); + iface->foo = (GHashTable* (*) (TestInterfaceBar*, GError**)) test_interface_foo_real_foo; +} + +static void +test_interface_foo_instance_init (TestInterfaceFoo * self, + gpointer klass) +{ +} + +static GType +test_interface_foo_get_type_once (void) +{ + static const GTypeInfo g_define_type_info = { sizeof (TestInterfaceFooClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) test_interface_foo_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (TestInterfaceFoo), 0, (GInstanceInitFunc) test_interface_foo_instance_init, NULL }; + static const GInterfaceInfo test_interface_bar_info = { (GInterfaceInitFunc) test_interface_foo_test_interface_bar_interface_init, (GInterfaceFinalizeFunc) NULL, NULL}; + GType test_interface_foo_type_id; + test_interface_foo_type_id = g_type_register_static (g_dbus_proxy_get_type (), "TestInterfaceFoo", &g_define_type_info, 0); + g_type_add_interface_static (test_interface_foo_type_id, TEST_INTERFACE_TYPE_BAR, &test_interface_bar_info); + return test_interface_foo_type_id; +} + +GType +test_interface_foo_get_type (void) +{ + static volatile gsize test_interface_foo_type_id__volatile = 0; + if (g_once_init_enter (&test_interface_foo_type_id__volatile)) { + GType test_interface_foo_type_id; + test_interface_foo_type_id = test_interface_foo_get_type_once (); + g_once_init_leave (&test_interface_foo_type_id__volatile, test_interface_foo_type_id); + } + return test_interface_foo_type_id__volatile; +} + +void +client_exit (GPid pid, + gint status) +{ + GMainLoop* _tmp0_; + _vala_assert (status == 0, "status == 0"); + _tmp0_ = main_loop; + g_main_loop_quit (_tmp0_); +} + +static guint +_variant_get1 (GVariant* value) +{ + return g_variant_get_uint32 (value); +} + +static void +_client_exit_gchild_watch_func (GPid pid, + gint wait_status, + gpointer self) +{ + client_exit (pid, wait_status); +} + +static void +_vala_main (void) +{ + GDBusConnection* conn = NULL; + GDBusConnection* _tmp0_; + GDBusConnection* _tmp1_; + Test* _tmp2_; + Test* _tmp3_; + GVariant* request_result = NULL; + GDBusConnection* _tmp4_; + GVariant* _tmp5_; + GVariant* _tmp6_; + GVariant* _tmp7_; + GVariant* _tmp8_; + GVariant* _tmp9_; + GVariant* _tmp10_; + GVariant* _tmp11_; + guint _tmp12_; + GPid client_pid = 0; + gchar* _tmp13_; + gchar** _tmp14_; + gchar** _tmp15_; + gint _tmp15__length1; + GPid _tmp16_ = 0; + GMainLoop* _tmp17_; + GMainLoop* _tmp18_; + GError* _inner_error0_ = NULL; + _tmp0_ = g_bus_get_sync (G_BUS_TYPE_SESSION, NULL, &_inner_error0_); + conn = _tmp0_; + if (G_UNLIKELY (_inner_error0_ != NULL)) { + g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error0_->message, g_quark_to_string (_inner_error0_->domain), _inner_error0_->code); + g_clear_error (&_inner_error0_); + return; + } + _tmp1_ = conn; + _tmp2_ = test_new (); + _tmp3_ = _tmp2_; + test_register_object (_tmp3_, _tmp1_, "/org/example/test", &_inner_error0_); + _g_object_unref0 (_tmp3_); + if (G_UNLIKELY (_inner_error0_ != NULL)) { + _g_object_unref0 (conn); + g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error0_->message, g_quark_to_string (_inner_error0_->domain), _inner_error0_->code); + g_clear_error (&_inner_error0_); + return; + } + _tmp4_ = conn; + _tmp5_ = g_variant_new ("(su)", "org.example.Test", 0x4, NULL); + g_variant_ref_sink (_tmp5_); + _tmp6_ = _tmp5_; + _tmp7_ = g_dbus_connection_call_sync (_tmp4_, "org.freedesktop.DBus", "/org/freedesktop/DBus", "org.freedesktop.DBus", "RequestName", _tmp6_, NULL, 0, -1, NULL, &_inner_error0_); + _tmp8_ = _tmp7_; + _g_variant_unref0 (_tmp6_); + request_result = _tmp8_; + if (G_UNLIKELY (_inner_error0_ != NULL)) { + _g_object_unref0 (conn); + g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error0_->message, g_quark_to_string (_inner_error0_->domain), _inner_error0_->code); + g_clear_error (&_inner_error0_); + return; + } + _tmp9_ = request_result; + _tmp10_ = g_variant_get_child_value (_tmp9_, (gsize) 0); + _tmp11_ = _tmp10_; + _tmp12_ = _variant_get1 (_tmp11_); + _vala_assert (_tmp12_ == ((guint) 1), "(uint) request_result.get_child_value (0) == 1"); + _g_variant_unref0 (_tmp11_); + _tmp13_ = g_strdup ("dbus_dicts_client"); + _tmp14_ = g_new0 (gchar*, 1 + 1); + _tmp14_[0] = _tmp13_; + _tmp15_ = _tmp14_; + _tmp15__length1 = 1; + g_spawn_async (NULL, _tmp15_, NULL, G_SPAWN_DO_NOT_REAP_CHILD, NULL, NULL, &_tmp16_, &_inner_error0_); + client_pid = _tmp16_; + _tmp15_ = (_vala_array_free (_tmp15_, _tmp15__length1, (GDestroyNotify) g_free), NULL); + if (G_UNLIKELY (_inner_error0_ != NULL)) { + _g_variant_unref0 (request_result); + _g_object_unref0 (conn); + g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error0_->message, g_quark_to_string (_inner_error0_->domain), _inner_error0_->code); + g_clear_error (&_inner_error0_); + return; + } + g_child_watch_add_full (G_PRIORITY_DEFAULT_IDLE, client_pid, _client_exit_gchild_watch_func, NULL, NULL); + _tmp17_ = g_main_loop_new (NULL, FALSE); + _g_main_loop_unref0 (main_loop); + main_loop = _tmp17_; + _tmp18_ = main_loop; + g_main_loop_run (_tmp18_); + _g_variant_unref0 (request_result); + _g_object_unref0 (conn); +} + +int +main (int argc, + char ** argv) +{ + _vala_main (); + return 0; +} + +static void +_vala_array_destroy (gpointer array, + gssize array_length, + GDestroyNotify destroy_func) +{ + if ((array != NULL) && (destroy_func != NULL)) { + gssize i; + for (i = 0; i < array_length; i = i + 1) { + if (((gpointer*) array)[i] != NULL) { + destroy_func (((gpointer*) array)[i]); + } + } + } +} + +static void +_vala_array_free (gpointer array, + gssize array_length, + GDestroyNotify destroy_func) +{ + _vala_array_destroy (array, array_length, destroy_func); + g_free (array); +} + diff --git a/tests/dbus/dynamic-method_client.c-expected b/tests/dbus/dynamic-method_client.c-expected new file mode 100644 index 000000000..92af699b4 --- /dev/null +++ b/tests/dbus/dynamic-method_client.c-expected @@ -0,0 +1,250 @@ +/* dbus_dynamic_method_client.c generated by valac, the Vala compiler + * generated from dbus_dynamic_method_client.vala, do not modify */ + +#include <gio/gio.h> +#include <glib.h> +#include <stdlib.h> +#include <string.h> + +#if !defined(VALA_EXTERN) +#if defined(_MSC_VER) +#define VALA_EXTERN __declspec(dllexport) extern +#elif __GNUC__ >= 4 +#define VALA_EXTERN __attribute__((visibility("default"))) extern +#else +#define VALA_EXTERN extern +#endif +#endif + +#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL))) +#define _g_free0(var) (var = (g_free (var), NULL)) +typedef struct _RunData RunData; +#define _g_main_loop_unref0(var) ((var == NULL) ? NULL : (var = (g_main_loop_unref (var), NULL))) +#define _vala_assert(expr, msg) if G_LIKELY (expr) ; else g_assertion_message_expr (G_LOG_DOMAIN, __FILE__, __LINE__, G_STRFUNC, msg); +#define _vala_return_if_fail(expr, msg) if G_LIKELY (expr) ; else { g_return_if_fail_warning (G_LOG_DOMAIN, G_STRFUNC, msg); return; } +#define _vala_return_val_if_fail(expr, msg, val) if G_LIKELY (expr) ; else { g_return_if_fail_warning (G_LOG_DOMAIN, G_STRFUNC, msg); return val; } +#define _vala_warn_if_fail(expr, msg) if G_LIKELY (expr) ; else g_warn_message (G_LOG_DOMAIN, __FILE__, __LINE__, G_STRFUNC, msg); + +struct _RunData { + int _state_; + GObject* _source_object_; + GAsyncResult* _res_; + GTask* _async_result; + GDBusConnection* bus; + GDBusConnection* _tmp0_; + GDBusProxy* test; + GDBusConnection* _tmp1_; + GDBusConnection* _tmp2_; + const gchar* _tmp3_; + GDBusProxy* _tmp4_; + gchar* s; + gint i; + GDBusProxy* _tmp5_; + gchar* _tmp10_; + gint _tmp11_; + const gchar* _tmp12_; + GMainLoop* _tmp13_; + GError* _inner_error0_; +}; + +VALA_EXTERN GMainLoop* main_loop; +GMainLoop* main_loop = NULL; + +static void run_data_free (gpointer _data); +VALA_EXTERN void run (GAsyncReadyCallback _callback_, + gpointer _user_data_); +VALA_EXTERN void run_finish (GAsyncResult* _res_); +static gboolean run_co (RunData* _data_); +static void run_ready (GObject* source_object, + GAsyncResult* _res_, + gpointer _user_data_); +static gint _dynamic_do_foo0 (GDBusProxy* self, + gint param1, + gchar* * param2, + GError** error); +static void _vala_main (void); + +static void +run_data_free (gpointer _data) +{ + RunData* _data_; + _data_ = _data; + g_slice_free (RunData, _data_); +} + +void +run (GAsyncReadyCallback _callback_, + gpointer _user_data_) +{ + RunData* _data_; + _data_ = g_slice_new0 (RunData); + _data_->_async_result = g_task_new (NULL, NULL, _callback_, _user_data_); + g_task_set_task_data (_data_->_async_result, _data_, run_data_free); + run_co (_data_); +} + +void +run_finish (GAsyncResult* _res_) +{ + RunData* _data_; + _data_ = g_task_propagate_pointer (G_TASK (_res_), NULL); +} + +static void +run_ready (GObject* source_object, + GAsyncResult* _res_, + gpointer _user_data_) +{ + RunData* _data_; + _data_ = _user_data_; + _data_->_source_object_ = source_object; + _data_->_res_ = _res_; + run_co (_data_); +} + +static gint +_dynamic_do_foo0 (GDBusProxy* self, + gint param1, + gchar* * param2, + GError** error) +{ + GDBusMessage *_message; + GVariant *_arguments; + GVariantBuilder _arguments_builder; + GDBusMessage *_reply_message; + GVariant *_reply; + GVariantIter _reply_iter; + gchar* _vala_param2 = NULL; + GVariant* _tmp8_; + gint _result = 0; + GVariant* _tmp9_; + _message = g_dbus_message_new_method_call (g_dbus_proxy_get_name ((GDBusProxy *) self), g_dbus_proxy_get_object_path ((GDBusProxy *) self), g_dbus_proxy_get_interface_name ((GDBusProxy *) self), "do_foo"); + g_variant_builder_init (&_arguments_builder, G_VARIANT_TYPE_TUPLE); + g_variant_builder_add_value (&_arguments_builder, g_variant_new_int32 (param1)); + _arguments = g_variant_builder_end (&_arguments_builder); + g_dbus_message_set_body (_message, _arguments); + _reply_message = g_dbus_connection_send_message_with_reply_sync (g_dbus_proxy_get_connection ((GDBusProxy *) self), _message, G_DBUS_SEND_MESSAGE_FLAGS_NONE, g_dbus_proxy_get_default_timeout ((GDBusProxy *) self), NULL, NULL, error); + g_object_unref (_message); + if (!_reply_message) { + gint _tmp6_ = 0; + return _tmp6_; + } + if (g_dbus_message_to_gerror (_reply_message, error)) { + gint _tmp7_ = 0; + g_object_unref (_reply_message); + return _tmp7_; + } + _reply = g_dbus_message_get_body (_reply_message); + g_variant_iter_init (&_reply_iter, _reply); + _tmp8_ = g_variant_iter_next_value (&_reply_iter); + _vala_param2 = g_variant_dup_string (_tmp8_, NULL); + g_variant_unref (_tmp8_); + *param2 = _vala_param2; + _tmp9_ = g_variant_iter_next_value (&_reply_iter); + _result = g_variant_get_int32 (_tmp9_); + g_variant_unref (_tmp9_); + g_object_unref (_reply_message); + return _result; +} + +static gboolean +run_co (RunData* _data_) +{ + switch (_data_->_state_) { + case 0: + goto _state_0; + case 1: + goto _state_1; + case 2: + goto _state_2; + default: + g_assert_not_reached (); + } + _state_0: + { + _data_->_state_ = 1; + g_bus_get (G_BUS_TYPE_SESSION, NULL, run_ready, _data_); + return FALSE; + _state_1: + _data_->_tmp0_ = g_bus_get_finish (_data_->_res_, &_data_->_inner_error0_); + _data_->bus = _data_->_tmp0_; + if (G_UNLIKELY (_data_->_inner_error0_ != NULL)) { + goto __catch0_g_error; + } + _data_->_tmp1_ = _data_->bus; + _data_->_tmp2_ = _data_->bus; + _data_->_tmp3_ = g_dbus_connection_get_unique_name (_data_->_tmp2_); + _data_->_state_ = 2; + g_dbus_proxy_new (_data_->_tmp1_, G_DBUS_PROXY_FLAGS_NONE, NULL, _data_->_tmp3_, "/org/example/test", "org.example.Test", NULL, run_ready, _data_); + return FALSE; + _state_2: + _data_->_tmp4_ = g_dbus_proxy_new_finish (_data_->_res_, &_data_->_inner_error0_); + _data_->test = _data_->_tmp4_; + if (G_UNLIKELY (_data_->_inner_error0_ != NULL)) { + _g_object_unref0 (_data_->bus); + goto __catch0_g_error; + } + _data_->_tmp5_ = _data_->test; + _data_->_tmp10_ = NULL; + _data_->_tmp11_ = _dynamic_do_foo0 (_data_->_tmp5_, 42, &_data_->_tmp10_, &_data_->_inner_error0_); + _g_free0 (_data_->s); + _data_->s = _data_->_tmp10_; + _data_->i = _data_->_tmp11_; + if (G_UNLIKELY (_data_->_inner_error0_ != NULL)) { + _g_free0 (_data_->s); + _g_object_unref0 (_data_->test); + _g_object_unref0 (_data_->bus); + goto __catch0_g_error; + } + _vala_assert (_data_->i == 23, "i == 23"); + _data_->_tmp12_ = _data_->s; + _vala_assert (g_strcmp0 (_data_->_tmp12_, "foo") == 0, "s == \"foo\""); + _g_free0 (_data_->s); + _g_object_unref0 (_data_->test); + _g_object_unref0 (_data_->bus); + } + goto __finally0; + __catch0_g_error: + { + g_clear_error (&_data_->_inner_error0_); + } + __finally0: + if (G_UNLIKELY (_data_->_inner_error0_ != NULL)) { + g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _data_->_inner_error0_->message, g_quark_to_string (_data_->_inner_error0_->domain), _data_->_inner_error0_->code); + g_clear_error (&_data_->_inner_error0_); + g_object_unref (_data_->_async_result); + return FALSE; + } + _data_->_tmp13_ = main_loop; + g_main_loop_quit (_data_->_tmp13_); + g_task_return_pointer (_data_->_async_result, _data_, NULL); + if (_data_->_state_ != 0) { + while (!g_task_get_completed (_data_->_async_result)) { + g_main_context_iteration (g_task_get_context (_data_->_async_result), TRUE); + } + } + g_object_unref (_data_->_async_result); + return FALSE; +} + +static void +_vala_main (void) +{ + GMainLoop* _tmp0_; + GMainLoop* _tmp1_; + _tmp0_ = g_main_loop_new (NULL, FALSE); + _g_main_loop_unref0 (main_loop); + main_loop = _tmp0_; + run (NULL, NULL); + _tmp1_ = main_loop; + g_main_loop_run (_tmp1_); +} + +int +main (int argc, + char ** argv) +{ + _vala_main (); + return 0; +} + diff --git a/tests/dbus/dynamic-method_server.c-expected b/tests/dbus/dynamic-method_server.c-expected new file mode 100644 index 000000000..f8864be40 --- /dev/null +++ b/tests/dbus/dynamic-method_server.c-expected @@ -0,0 +1,460 @@ +/* dbus_dynamic_method_server.c generated by valac, the Vala compiler + * generated from dbus_dynamic_method_server.vala, do not modify */ + +#include <glib-object.h> +#include <gio/gio.h> +#include <glib.h> +#include <stdlib.h> +#include <string.h> + +#if !defined(VALA_EXTERN) +#if defined(_MSC_VER) +#define VALA_EXTERN __declspec(dllexport) extern +#elif __GNUC__ >= 4 +#define VALA_EXTERN __attribute__((visibility("default"))) extern +#else +#define VALA_EXTERN extern +#endif +#endif + +#define TYPE_TEST (test_get_type ()) +#define TEST(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TYPE_TEST, Test)) +#define TEST_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), TYPE_TEST, TestClass)) +#define IS_TEST(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TYPE_TEST)) +#define IS_TEST_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), TYPE_TEST)) +#define TEST_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), TYPE_TEST, TestClass)) + +typedef struct _Test Test; +typedef struct _TestClass TestClass; +typedef struct _TestPrivate TestPrivate; +enum { + TEST_0_PROPERTY, + TEST_NUM_PROPERTIES +}; +static GParamSpec* test_properties[TEST_NUM_PROPERTIES]; +#define _g_free0(var) (var = (g_free (var), NULL)) +#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL))) +#define _g_variant_unref0(var) ((var == NULL) ? NULL : (var = (g_variant_unref (var), NULL))) +#define _g_main_loop_unref0(var) ((var == NULL) ? NULL : (var = (g_main_loop_unref (var), NULL))) +#define _vala_assert(expr, msg) if G_LIKELY (expr) ; else g_assertion_message_expr (G_LOG_DOMAIN, __FILE__, __LINE__, G_STRFUNC, msg); +#define _vala_return_if_fail(expr, msg) if G_LIKELY (expr) ; else { g_return_if_fail_warning (G_LOG_DOMAIN, G_STRFUNC, msg); return; } +#define _vala_return_val_if_fail(expr, msg, val) if G_LIKELY (expr) ; else { g_return_if_fail_warning (G_LOG_DOMAIN, G_STRFUNC, msg); return val; } +#define _vala_warn_if_fail(expr, msg) if G_LIKELY (expr) ; else g_warn_message (G_LOG_DOMAIN, __FILE__, __LINE__, G_STRFUNC, msg); + +struct _Test { + GObject parent_instance; + TestPrivate * priv; +}; + +struct _TestClass { + GObjectClass parent_class; +}; + +static gpointer test_parent_class = NULL; +VALA_EXTERN GMainLoop* main_loop; +GMainLoop* main_loop = NULL; + +VALA_EXTERN GType test_get_type (void) G_GNUC_CONST ; +G_DEFINE_AUTOPTR_CLEANUP_FUNC (Test, g_object_unref) +VALA_EXTERN guint test_register_object (void* object, + GDBusConnection* connection, + const gchar* path, + GError** error); +VALA_EXTERN gint test_do_foo (Test* self, + gint i, + gchar* * s, + GError** error); +VALA_EXTERN Test* test_new (void); +VALA_EXTERN Test* test_construct (GType object_type); +static GType test_get_type_once (void); +static void _dbus_test_do_foo (Test* self, + GVariant* _parameters_, + GDBusMethodInvocation* invocation); +static void test_dbus_interface_method_call (GDBusConnection* connection, + const gchar* sender, + const gchar* object_path, + const gchar* interface_name, + const gchar* method_name, + GVariant* parameters, + GDBusMethodInvocation* invocation, + gpointer user_data); +static GVariant* test_dbus_interface_get_property (GDBusConnection* connection, + const gchar* sender, + const gchar* object_path, + const gchar* interface_name, + const gchar* property_name, + GError** error, + gpointer user_data); +static gboolean test_dbus_interface_set_property (GDBusConnection* connection, + const gchar* sender, + const gchar* object_path, + const gchar* interface_name, + const gchar* property_name, + GVariant* value, + GError** error, + gpointer user_data); +static void _test_unregister_object (gpointer user_data); +VALA_EXTERN void client_exit (GPid pid, + gint status); +static void _vala_main (void); +static guint _variant_get1 (GVariant* value); +static void _client_exit_gchild_watch_func (GPid pid, + gint wait_status, + gpointer self); +static void _vala_array_destroy (gpointer array, + gssize array_length, + GDestroyNotify destroy_func); +static void _vala_array_free (gpointer array, + gssize array_length, + GDestroyNotify destroy_func); + +static const GDBusArgInfo _test_dbus_arg_info_do_foo_i = {-1, "i", "i", NULL}; +static const GDBusArgInfo _test_dbus_arg_info_do_foo_s = {-1, "s", "s", NULL}; +static const GDBusArgInfo _test_dbus_arg_info_do_foo_result = {-1, "result", "i", NULL}; +static const GDBusArgInfo * const _test_dbus_arg_info_do_foo_in[] = {&_test_dbus_arg_info_do_foo_i, NULL}; +static const GDBusArgInfo * const _test_dbus_arg_info_do_foo_out[] = {&_test_dbus_arg_info_do_foo_s, &_test_dbus_arg_info_do_foo_result, NULL}; +static const GDBusMethodInfo _test_dbus_method_info_do_foo = {-1, "DoFoo", (GDBusArgInfo **) (&_test_dbus_arg_info_do_foo_in), (GDBusArgInfo **) (&_test_dbus_arg_info_do_foo_out), NULL}; +static const GDBusMethodInfo * const _test_dbus_method_info[] = {&_test_dbus_method_info_do_foo, NULL}; +static const GDBusSignalInfo * const _test_dbus_signal_info[] = {NULL}; +static const GDBusPropertyInfo * const _test_dbus_property_info[] = {NULL}; +static const GDBusInterfaceInfo _test_dbus_interface_info = {-1, "org.example.Test", (GDBusMethodInfo **) (&_test_dbus_method_info), (GDBusSignalInfo **) (&_test_dbus_signal_info), (GDBusPropertyInfo **) (&_test_dbus_property_info), NULL}; +static const GDBusInterfaceVTable _test_dbus_interface_vtable = {test_dbus_interface_method_call, test_dbus_interface_get_property, test_dbus_interface_set_property}; + +gint +test_do_foo (Test* self, + gint i, + gchar* * s, + GError** error) +{ + gchar* _vala_s = NULL; + gchar* _tmp0_; + gint result = 0; + g_return_val_if_fail (IS_TEST (self), 0); + _vala_assert (i == 42, "i == 42"); + _tmp0_ = g_strdup ("foo"); + _g_free0 (_vala_s); + _vala_s = _tmp0_; + result = 23; + if (s) { + *s = _vala_s; + } else { + _g_free0 (_vala_s); + } + return result; +} + +Test* +test_construct (GType object_type) +{ + Test * self = NULL; + self = (Test*) g_object_new (object_type, NULL); + return self; +} + +Test* +test_new (void) +{ + return test_construct (TYPE_TEST); +} + +static void +test_class_init (TestClass * klass, + gpointer klass_data) +{ + test_parent_class = g_type_class_peek_parent (klass); +} + +static void +test_instance_init (Test * self, + gpointer klass) +{ +} + +static GType +test_get_type_once (void) +{ + static const GTypeInfo g_define_type_info = { sizeof (TestClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) test_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (Test), 0, (GInstanceInitFunc) test_instance_init, NULL }; + GType test_type_id; + test_type_id = g_type_register_static (G_TYPE_OBJECT, "Test", &g_define_type_info, 0); + g_type_set_qdata (test_type_id, g_quark_from_static_string ("vala-dbus-register-object"), (void*) test_register_object); + return test_type_id; +} + +GType +test_get_type (void) +{ + static volatile gsize test_type_id__volatile = 0; + if (g_once_init_enter (&test_type_id__volatile)) { + GType test_type_id; + test_type_id = test_get_type_once (); + g_once_init_leave (&test_type_id__volatile, test_type_id); + } + return test_type_id__volatile; +} + +static void +_dbus_test_do_foo (Test* self, + GVariant* _parameters_, + GDBusMethodInvocation* invocation) +{ + GError* error = NULL; + GVariantIter _arguments_iter; + gint i = 0; + GVariant* _tmp0_; + GDBusMessage* _reply_message = NULL; + GVariant* _reply; + GVariantBuilder _reply_builder; + gchar* s = NULL; + gint result; + g_variant_iter_init (&_arguments_iter, _parameters_); + _tmp0_ = g_variant_iter_next_value (&_arguments_iter); + i = g_variant_get_int32 (_tmp0_); + g_variant_unref (_tmp0_); + result = test_do_foo (self, i, &s, &error); + if (error) { + g_dbus_method_invocation_return_gerror (invocation, error); + g_error_free (error); + return; + } + _reply_message = g_dbus_message_new_method_reply (g_dbus_method_invocation_get_message (invocation)); + g_variant_builder_init (&_reply_builder, G_VARIANT_TYPE_TUPLE); + g_variant_builder_add_value (&_reply_builder, g_variant_new_string (s)); + g_variant_builder_add_value (&_reply_builder, g_variant_new_int32 (result)); + _reply = g_variant_builder_end (&_reply_builder); + g_dbus_message_set_body (_reply_message, _reply); + g_dbus_connection_send_message (g_dbus_method_invocation_get_connection (invocation), _reply_message, G_DBUS_SEND_MESSAGE_FLAGS_NONE, NULL, NULL); + g_object_unref (invocation); + g_object_unref (_reply_message); + _g_free0 (s); +} + +static void +test_dbus_interface_method_call (GDBusConnection* connection, + const gchar* sender, + const gchar* object_path, + const gchar* interface_name, + const gchar* method_name, + GVariant* parameters, + GDBusMethodInvocation* invocation, + gpointer user_data) +{ + gpointer* data; + gpointer object; + data = user_data; + object = data[0]; + if (strcmp (method_name, "DoFoo") == 0) { + _dbus_test_do_foo (object, parameters, invocation); + } else { + g_object_unref (invocation); + } +} + +static GVariant* +test_dbus_interface_get_property (GDBusConnection* connection, + const gchar* sender, + const gchar* object_path, + const gchar* interface_name, + const gchar* property_name, + GError** error, + gpointer user_data) +{ + gpointer* data; + gpointer object; + data = user_data; + object = data[0]; + return NULL; +} + +static gboolean +test_dbus_interface_set_property (GDBusConnection* connection, + const gchar* sender, + const gchar* object_path, + const gchar* interface_name, + const gchar* property_name, + GVariant* value, + GError** error, + gpointer user_data) +{ + gpointer* data; + gpointer object; + data = user_data; + object = data[0]; + return FALSE; +} + +guint +test_register_object (gpointer object, + GDBusConnection* connection, + const gchar* path, + GError** error) +{ + guint result; + gpointer *data; + data = g_new (gpointer, 3); + data[0] = g_object_ref (object); + data[1] = g_object_ref (connection); + data[2] = g_strdup (path); + result = g_dbus_connection_register_object (connection, path, (GDBusInterfaceInfo *) (&_test_dbus_interface_info), &_test_dbus_interface_vtable, data, _test_unregister_object, error); + if (!result) { + return 0; + } + return result; +} + +static void +_test_unregister_object (gpointer user_data) +{ + gpointer* data; + data = user_data; + g_object_unref (data[0]); + g_object_unref (data[1]); + g_free (data[2]); + g_free (data); +} + +void +client_exit (GPid pid, + gint status) +{ + GMainLoop* _tmp0_; + _vala_assert (status == 0, "status == 0"); + _tmp0_ = main_loop; + g_main_loop_quit (_tmp0_); +} + +static guint +_variant_get1 (GVariant* value) +{ + return g_variant_get_uint32 (value); +} + +static void +_client_exit_gchild_watch_func (GPid pid, + gint wait_status, + gpointer self) +{ + client_exit (pid, wait_status); +} + +static void +_vala_main (void) +{ + GDBusConnection* conn = NULL; + GDBusConnection* _tmp0_; + GDBusConnection* _tmp1_; + Test* _tmp2_; + Test* _tmp3_; + GVariant* request_result = NULL; + GDBusConnection* _tmp4_; + GVariant* _tmp5_; + GVariant* _tmp6_; + GVariant* _tmp7_; + GVariant* _tmp8_; + GVariant* _tmp9_; + GVariant* _tmp10_; + GVariant* _tmp11_; + guint _tmp12_; + GPid client_pid = 0; + gchar* _tmp13_; + gchar** _tmp14_; + gchar** _tmp15_; + gint _tmp15__length1; + GPid _tmp16_ = 0; + GMainLoop* _tmp17_; + GMainLoop* _tmp18_; + GError* _inner_error0_ = NULL; + _tmp0_ = g_bus_get_sync (G_BUS_TYPE_SESSION, NULL, &_inner_error0_); + conn = _tmp0_; + if (G_UNLIKELY (_inner_error0_ != NULL)) { + g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error0_->message, g_quark_to_string (_inner_error0_->domain), _inner_error0_->code); + g_clear_error (&_inner_error0_); + return; + } + _tmp1_ = conn; + _tmp2_ = test_new (); + _tmp3_ = _tmp2_; + test_register_object (_tmp3_, _tmp1_, "/org/example/test", &_inner_error0_); + _g_object_unref0 (_tmp3_); + if (G_UNLIKELY (_inner_error0_ != NULL)) { + _g_object_unref0 (conn); + g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error0_->message, g_quark_to_string (_inner_error0_->domain), _inner_error0_->code); + g_clear_error (&_inner_error0_); + return; + } + _tmp4_ = conn; + _tmp5_ = g_variant_new ("(su)", "org.example.Test", 0x4, NULL); + g_variant_ref_sink (_tmp5_); + _tmp6_ = _tmp5_; + _tmp7_ = g_dbus_connection_call_sync (_tmp4_, "org.freedesktop.DBus", "/org/freedesktop/DBus", "org.freedesktop.DBus", "RequestName", _tmp6_, NULL, 0, -1, NULL, &_inner_error0_); + _tmp8_ = _tmp7_; + _g_variant_unref0 (_tmp6_); + request_result = _tmp8_; + if (G_UNLIKELY (_inner_error0_ != NULL)) { + _g_object_unref0 (conn); + g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error0_->message, g_quark_to_string (_inner_error0_->domain), _inner_error0_->code); + g_clear_error (&_inner_error0_); + return; + } + _tmp9_ = request_result; + _tmp10_ = g_variant_get_child_value (_tmp9_, (gsize) 0); + _tmp11_ = _tmp10_; + _tmp12_ = _variant_get1 (_tmp11_); + _vala_assert (_tmp12_ == ((guint) 1), "(uint) request_result.get_child_value (0) == 1"); + _g_variant_unref0 (_tmp11_); + _tmp13_ = g_strdup ("dbus_dynamic_method_client"); + _tmp14_ = g_new0 (gchar*, 1 + 1); + _tmp14_[0] = _tmp13_; + _tmp15_ = _tmp14_; + _tmp15__length1 = 1; + g_spawn_async (NULL, _tmp15_, NULL, G_SPAWN_DO_NOT_REAP_CHILD, NULL, NULL, &_tmp16_, &_inner_error0_); + client_pid = _tmp16_; + _tmp15_ = (_vala_array_free (_tmp15_, _tmp15__length1, (GDestroyNotify) g_free), NULL); + if (G_UNLIKELY (_inner_error0_ != NULL)) { + _g_variant_unref0 (request_result); + _g_object_unref0 (conn); + g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error0_->message, g_quark_to_string (_inner_error0_->domain), _inner_error0_->code); + g_clear_error (&_inner_error0_); + return; + } + g_child_watch_add_full (G_PRIORITY_DEFAULT_IDLE, client_pid, _client_exit_gchild_watch_func, NULL, NULL); + _tmp17_ = g_main_loop_new (NULL, FALSE); + _g_main_loop_unref0 (main_loop); + main_loop = _tmp17_; + _tmp18_ = main_loop; + g_main_loop_run (_tmp18_); + _g_variant_unref0 (request_result); + _g_object_unref0 (conn); +} + +int +main (int argc, + char ** argv) +{ + _vala_main (); + return 0; +} + +static void +_vala_array_destroy (gpointer array, + gssize array_length, + GDestroyNotify destroy_func) +{ + if ((array != NULL) && (destroy_func != NULL)) { + gssize i; + for (i = 0; i < array_length; i = i + 1) { + if (((gpointer*) array)[i] != NULL) { + destroy_func (((gpointer*) array)[i]); + } + } + } +} + +static void +_vala_array_free (gpointer array, + gssize array_length, + GDestroyNotify destroy_func) +{ + _vala_array_destroy (array, array_length, destroy_func); + g_free (array); +} + diff --git a/tests/dbus/enum-string-marshalling.c-expected b/tests/dbus/enum-string-marshalling.c-expected new file mode 100644 index 000000000..bf75b7b5a --- /dev/null +++ b/tests/dbus/enum-string-marshalling.c-expected @@ -0,0 +1,901 @@ +/* dbus_enum_string_marshalling.c generated by valac, the Vala compiler + * generated from dbus_enum_string_marshalling.vala, do not modify */ + +#include <glib-object.h> +#include <string.h> +#include <gio/gio.h> +#include <glib.h> + +#if !defined(VALA_EXTERN) +#if defined(_MSC_VER) +#define VALA_EXTERN __declspec(dllexport) extern +#elif __GNUC__ >= 4 +#define VALA_EXTERN __attribute__((visibility("default"))) extern +#else +#define VALA_EXTERN extern +#endif +#endif + +typedef enum { + FOO_ENUM_BAR +} FooEnum; + +#define TYPE_FOO_ENUM (foo_enum_get_type ()) + +#define TYPE_TEST (test_get_type ()) +#define TEST(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TYPE_TEST, Test)) +#define IS_TEST(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TYPE_TEST)) +#define TEST_GET_INTERFACE(obj) (G_TYPE_INSTANCE_GET_INTERFACE ((obj), TYPE_TEST, TestIface)) + +typedef struct _Test Test; +typedef struct _TestIface TestIface; + +#define TYPE_TEST_PROXY (test_proxy_get_type ()) +typedef GDBusProxy TestProxy; +typedef GDBusProxyClass TestProxyClass; +typedef struct _TestTest1ReadyData TestTest1ReadyData; +typedef struct _TestTest5ReadyData TestTest5ReadyData; + +struct _TestIface { + GTypeInterface parent_iface; + void (*test1) (Test* self, FooEnum e, GAsyncReadyCallback _callback_, gpointer _user_data_); + void (*test1_finish) (Test* self, GAsyncResult* _res_, GError** error); + void (*test2) (Test* self, FooEnum e, GError** error); + void (*test3) (Test* self, FooEnum e1, gint fd, FooEnum e2, GError** error); + void (*test4) (Test* self, FooEnum e); + void (*test5) (Test* self, FooEnum e, GAsyncReadyCallback _callback_, gpointer _user_data_); + void (*test5_finish) (Test* self, GAsyncResult* _res_); +}; + +struct _TestTest1ReadyData { + GDBusMethodInvocation* _invocation_; + FooEnum e; +}; + +struct _TestTest5ReadyData { + GDBusMethodInvocation* _invocation_; + FooEnum e; +}; + +VALA_EXTERN GType foo_enum_get_type (void) G_GNUC_CONST ; +VALA_EXTERN FooEnum foo_enum_from_string (const char* str, + GError** error); +VALA_EXTERN const char* foo_enum_to_string (FooEnum value); +VALA_EXTERN GType test_proxy_get_type (void) G_GNUC_CONST ; +VALA_EXTERN guint test_register_object (void* object, + GDBusConnection* connection, + const gchar* path, + GError** error); +VALA_EXTERN GType test_get_type (void) G_GNUC_CONST ; +VALA_EXTERN void test_test1 (Test* self, + FooEnum e, + GAsyncReadyCallback _callback_, + gpointer _user_data_); +VALA_EXTERN void test_test1_finish (Test* self, + GAsyncResult* _res_, + GError** error); +VALA_EXTERN void test_test2 (Test* self, + FooEnum e, + GError** error); +VALA_EXTERN void test_test3 (Test* self, + FooEnum e1, + gint fd, + FooEnum e2, + GError** error); +VALA_EXTERN void test_test4 (Test* self, + FooEnum e); +VALA_EXTERN void test_test5 (Test* self, + FooEnum e, + GAsyncReadyCallback _callback_, + gpointer _user_data_); +VALA_EXTERN void test_test5_finish (Test* self, + GAsyncResult* _res_); +static GType test_get_type_once (void); +static void test_proxy_g_signal (GDBusProxy* proxy, + const gchar* sender_name, + const gchar* signal_name, + GVariant* parameters); +static void _vala_g_async_ready_callback (GObject *source_object, + GAsyncResult *res, + void *user_data); +static void test_proxy_test1_async (Test* self, + FooEnum e, + GAsyncReadyCallback _callback_, + gpointer _user_data_); +static void test_proxy_test1_finish (Test* self, + GAsyncResult* _res_, + GError** error); +static void test_proxy_test2 (Test* self, + FooEnum e, + GError** error); +static void test_proxy_test3 (Test* self, + FooEnum e1, + gint fd, + FooEnum e2, + GError** error); +static void test_proxy_test4 (Test* self, + FooEnum e); +static void test_proxy_test5_async (Test* self, + FooEnum e, + GAsyncReadyCallback _callback_, + gpointer _user_data_); +static void test_proxy_test5_finish (Test* self, + GAsyncResult* _res_); +static void test_proxy_test_interface_init (TestIface* iface); +static void _dbus_test_test1 (Test* self, + GVariant* _parameters_, + GDBusMethodInvocation* invocation); +static void _dbus_test_test1_ready (GObject * source_object, + GAsyncResult * _res_, + gpointer _user_data_); +static void _dbus_test_test2 (Test* self, + GVariant* _parameters_, + GDBusMethodInvocation* invocation); +static void _dbus_test_test3 (Test* self, + GVariant* _parameters_, + GDBusMethodInvocation* invocation); +static void _dbus_test_test4 (Test* self, + GVariant* _parameters_, + GDBusMethodInvocation* invocation); +static void _dbus_test_test5 (Test* self, + GVariant* _parameters_, + GDBusMethodInvocation* invocation); +static void _dbus_test_test5_ready (GObject * source_object, + GAsyncResult * _res_, + gpointer _user_data_); +static void test_dbus_interface_method_call (GDBusConnection* connection, + const gchar* sender, + const gchar* object_path, + const gchar* interface_name, + const gchar* method_name, + GVariant* parameters, + GDBusMethodInvocation* invocation, + gpointer user_data); +static GVariant* test_dbus_interface_get_property (GDBusConnection* connection, + const gchar* sender, + const gchar* object_path, + const gchar* interface_name, + const gchar* property_name, + GError** error, + gpointer user_data); +static gboolean test_dbus_interface_set_property (GDBusConnection* connection, + const gchar* sender, + const gchar* object_path, + const gchar* interface_name, + const gchar* property_name, + GVariant* value, + GError** error, + gpointer user_data); +static void _test_unregister_object (gpointer user_data); +static void _vala_main (void); + +static const GDBusArgInfo _test_dbus_arg_info_test1_e = {-1, "e", "s", NULL}; +static const GDBusArgInfo * const _test_dbus_arg_info_test1_in[] = {&_test_dbus_arg_info_test1_e, NULL}; +static const GDBusArgInfo * const _test_dbus_arg_info_test1_out[] = {NULL}; +static const GDBusMethodInfo _test_dbus_method_info_test1 = {-1, "Test1", (GDBusArgInfo **) (&_test_dbus_arg_info_test1_in), (GDBusArgInfo **) (&_test_dbus_arg_info_test1_out), NULL}; +static const GDBusArgInfo _test_dbus_arg_info_test2_e = {-1, "e", "s", NULL}; +static const GDBusArgInfo * const _test_dbus_arg_info_test2_in[] = {&_test_dbus_arg_info_test2_e, NULL}; +static const GDBusArgInfo * const _test_dbus_arg_info_test2_out[] = {NULL}; +static const GDBusMethodInfo _test_dbus_method_info_test2 = {-1, "Test2", (GDBusArgInfo **) (&_test_dbus_arg_info_test2_in), (GDBusArgInfo **) (&_test_dbus_arg_info_test2_out), NULL}; +static const GDBusArgInfo _test_dbus_arg_info_test3_e1 = {-1, "e1", "s", NULL}; +static const GDBusArgInfo _test_dbus_arg_info_test3_fd = {-1, "fd", "i", NULL}; +static const GDBusArgInfo _test_dbus_arg_info_test3_e2 = {-1, "e2", "s", NULL}; +static const GDBusArgInfo * const _test_dbus_arg_info_test3_in[] = {&_test_dbus_arg_info_test3_e1, &_test_dbus_arg_info_test3_fd, &_test_dbus_arg_info_test3_e2, NULL}; +static const GDBusArgInfo * const _test_dbus_arg_info_test3_out[] = {NULL}; +static const GDBusMethodInfo _test_dbus_method_info_test3 = {-1, "Test3", (GDBusArgInfo **) (&_test_dbus_arg_info_test3_in), (GDBusArgInfo **) (&_test_dbus_arg_info_test3_out), NULL}; +static const GDBusArgInfo _test_dbus_arg_info_test4_e = {-1, "e", "s", NULL}; +static const GDBusArgInfo * const _test_dbus_arg_info_test4_in[] = {&_test_dbus_arg_info_test4_e, NULL}; +static const GDBusArgInfo * const _test_dbus_arg_info_test4_out[] = {NULL}; +static const GDBusMethodInfo _test_dbus_method_info_test4 = {-1, "Test4", (GDBusArgInfo **) (&_test_dbus_arg_info_test4_in), (GDBusArgInfo **) (&_test_dbus_arg_info_test4_out), NULL}; +static const GDBusArgInfo _test_dbus_arg_info_test5_e = {-1, "e", "s", NULL}; +static const GDBusArgInfo * const _test_dbus_arg_info_test5_in[] = {&_test_dbus_arg_info_test5_e, NULL}; +static const GDBusArgInfo * const _test_dbus_arg_info_test5_out[] = {NULL}; +static const GDBusMethodInfo _test_dbus_method_info_test5 = {-1, "Test5", (GDBusArgInfo **) (&_test_dbus_arg_info_test5_in), (GDBusArgInfo **) (&_test_dbus_arg_info_test5_out), NULL}; +static const GDBusMethodInfo * const _test_dbus_method_info[] = {&_test_dbus_method_info_test1, &_test_dbus_method_info_test2, &_test_dbus_method_info_test3, &_test_dbus_method_info_test4, &_test_dbus_method_info_test5, NULL}; +static const GDBusSignalInfo * const _test_dbus_signal_info[] = {NULL}; +static const GDBusPropertyInfo * const _test_dbus_property_info[] = {NULL}; +static const GDBusInterfaceInfo _test_dbus_interface_info = {-1, "org.example.Test", (GDBusMethodInfo **) (&_test_dbus_method_info), (GDBusSignalInfo **) (&_test_dbus_signal_info), (GDBusPropertyInfo **) (&_test_dbus_property_info), NULL}; +static const GDBusInterfaceVTable _test_dbus_interface_vtable = {test_dbus_interface_method_call, test_dbus_interface_get_property, test_dbus_interface_set_property}; + +static GType +foo_enum_get_type_once (void) +{ + static const GEnumValue values[] = {{FOO_ENUM_BAR, "FOO_ENUM_BAR", "bar"}, {0, NULL, NULL}}; + GType foo_enum_type_id; + foo_enum_type_id = g_enum_register_static ("FooEnum", values); + return foo_enum_type_id; +} + +GType +foo_enum_get_type (void) +{ + static volatile gsize foo_enum_type_id__volatile = 0; + if (g_once_init_enter (&foo_enum_type_id__volatile)) { + GType foo_enum_type_id; + foo_enum_type_id = foo_enum_get_type_once (); + g_once_init_leave (&foo_enum_type_id__volatile, foo_enum_type_id); + } + return foo_enum_type_id__volatile; +} + +FooEnum +foo_enum_from_string (const char* str, + GError** error) +{ + FooEnum value = 0; + if (strcmp (str, "BAR") == 0) { + value = FOO_ENUM_BAR; + } else { + g_set_error (error, G_DBUS_ERROR, G_DBUS_ERROR_INVALID_ARGS, "Invalid value for enum `FooEnum'"); + } + return value; +} + +const char* +foo_enum_to_string (FooEnum value) +{ + const char * str; + switch (value) { + case FOO_ENUM_BAR: + str = "BAR"; + break; + } + return str; +} + +void +test_test1 (Test* self, + FooEnum e, + GAsyncReadyCallback _callback_, + gpointer _user_data_) +{ + TestIface* _iface_; + _iface_ = TEST_GET_INTERFACE (self); + if (_iface_->test1) { + _iface_->test1 (self, e, _callback_, _user_data_); + } +} + +void +test_test1_finish (Test* self, + GAsyncResult* _res_, + GError** error) +{ + TestIface* _iface_; + _iface_ = TEST_GET_INTERFACE (self); + if (_iface_->test1_finish) { + _iface_->test1_finish (self, _res_, error); + } +} + +void +test_test2 (Test* self, + FooEnum e, + GError** error) +{ + TestIface* _iface_; + g_return_if_fail (IS_TEST (self)); + _iface_ = TEST_GET_INTERFACE (self); + if (_iface_->test2) { + _iface_->test2 (self, e, error); + } +} + +void +test_test3 (Test* self, + FooEnum e1, + gint fd, + FooEnum e2, + GError** error) +{ + TestIface* _iface_; + g_return_if_fail (IS_TEST (self)); + _iface_ = TEST_GET_INTERFACE (self); + if (_iface_->test3) { + _iface_->test3 (self, e1, fd, e2, error); + } +} + +void +test_test4 (Test* self, + FooEnum e) +{ + TestIface* _iface_; + g_return_if_fail (IS_TEST (self)); + _iface_ = TEST_GET_INTERFACE (self); + if (_iface_->test4) { + _iface_->test4 (self, e); + } +} + +void +test_test5 (Test* self, + FooEnum e, + GAsyncReadyCallback _callback_, + gpointer _user_data_) +{ + TestIface* _iface_; + _iface_ = TEST_GET_INTERFACE (self); + if (_iface_->test5) { + _iface_->test5 (self, e, _callback_, _user_data_); + } +} + +void +test_test5_finish (Test* self, + GAsyncResult* _res_) +{ + TestIface* _iface_; + _iface_ = TEST_GET_INTERFACE (self); + if (_iface_->test5_finish) { + _iface_->test5_finish (self, _res_); + } +} + +static void +test_default_init (TestIface * iface, + gpointer iface_data) +{ +} + +static GType +test_get_type_once (void) +{ + static const GTypeInfo g_define_type_info = { sizeof (TestIface), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) test_default_init, (GClassFinalizeFunc) NULL, NULL, 0, 0, (GInstanceInitFunc) NULL, NULL }; + GType test_type_id; + test_type_id = g_type_register_static (G_TYPE_INTERFACE, "Test", &g_define_type_info, 0); + g_type_interface_add_prerequisite (test_type_id, G_TYPE_OBJECT); + g_type_set_qdata (test_type_id, g_quark_from_static_string ("vala-dbus-proxy-type"), (void*) test_proxy_get_type); + g_type_set_qdata (test_type_id, g_quark_from_static_string ("vala-dbus-interface-name"), "org.example.Test"); + g_type_set_qdata (test_type_id, g_quark_from_static_string ("vala-dbus-interface-info"), (void*) (&_test_dbus_interface_info)); + g_type_set_qdata (test_type_id, g_quark_from_static_string ("vala-dbus-register-object"), (void*) test_register_object); + return test_type_id; +} + +GType +test_get_type (void) +{ + static volatile gsize test_type_id__volatile = 0; + if (g_once_init_enter (&test_type_id__volatile)) { + GType test_type_id; + test_type_id = test_get_type_once (); + g_once_init_leave (&test_type_id__volatile, test_type_id); + } + return test_type_id__volatile; +} + +G_DEFINE_TYPE_EXTENDED (TestProxy, test_proxy, G_TYPE_DBUS_PROXY, 0, G_IMPLEMENT_INTERFACE (TYPE_TEST, test_proxy_test_interface_init) ) +static void +test_proxy_class_init (TestProxyClass* klass) +{ + G_DBUS_PROXY_CLASS (klass)->g_signal = test_proxy_g_signal; +} + +static void +test_proxy_g_signal (GDBusProxy* proxy, + const gchar* sender_name, + const gchar* signal_name, + GVariant* parameters) +{ +} + +static void +test_proxy_init (TestProxy* self) +{ + g_dbus_proxy_set_interface_info (G_DBUS_PROXY (self), (GDBusInterfaceInfo *) (&_test_dbus_interface_info)); +} + +static void +_vala_g_async_ready_callback (GObject *source_object, + GAsyncResult *res, + void *user_data) +{ + g_task_return_pointer (user_data, g_object_ref (res), g_object_unref); + g_object_unref (user_data); +} + +static void +test_proxy_test1_async (Test* self, + FooEnum e, + GAsyncReadyCallback _callback_, + gpointer _user_data_) +{ + GDBusMessage *_message; + GVariant *_arguments; + GVariantBuilder _arguments_builder; + G_DBUS_ERROR; + _message = g_dbus_message_new_method_call (g_dbus_proxy_get_name ((GDBusProxy *) self), g_dbus_proxy_get_object_path ((GDBusProxy *) self), "org.example.Test", "Test1"); + g_variant_builder_init (&_arguments_builder, G_VARIANT_TYPE_TUPLE); + g_variant_builder_add_value (&_arguments_builder, g_variant_new_string (foo_enum_to_string (e))); + _arguments = g_variant_builder_end (&_arguments_builder); + g_dbus_message_set_body (_message, _arguments); + if (_callback_ != NULL) { + g_dbus_connection_send_message_with_reply (g_dbus_proxy_get_connection ((GDBusProxy *) self), _message, G_DBUS_SEND_MESSAGE_FLAGS_NONE, g_dbus_proxy_get_default_timeout ((GDBusProxy *) self), NULL, NULL, _vala_g_async_ready_callback, g_task_new ((GObject *) self, NULL, _callback_, _user_data_)); + } else { + g_dbus_message_set_flags (_message, G_DBUS_MESSAGE_FLAGS_NO_REPLY_EXPECTED); + g_dbus_connection_send_message (g_dbus_proxy_get_connection ((GDBusProxy *) self), _message, G_DBUS_SEND_MESSAGE_FLAGS_NONE, NULL, NULL); + } + g_object_unref (_message); +} + +static void +test_proxy_test1_finish (Test* self, + GAsyncResult* _res_, + GError** error) +{ + GAsyncResult *_inner_res; + GDBusMessage *_reply_message; + _inner_res = g_task_propagate_pointer ((GTask *) _res_, NULL); + _reply_message = g_dbus_connection_send_message_with_reply_finish (g_dbus_proxy_get_connection ((GDBusProxy *) self), _inner_res, error); + g_object_unref (_inner_res); + if (!_reply_message) { + return; + } + if (g_dbus_message_to_gerror (_reply_message, error)) { + g_object_unref (_reply_message); + return; + } + g_object_unref (_reply_message); +} + +static void +test_proxy_test2 (Test* self, + FooEnum e, + GError** error) +{ + GDBusMessage *_message; + GVariant *_arguments; + GVariantBuilder _arguments_builder; + GDBusMessage *_reply_message; + G_DBUS_ERROR; + _message = g_dbus_message_new_method_call (g_dbus_proxy_get_name ((GDBusProxy *) self), g_dbus_proxy_get_object_path ((GDBusProxy *) self), "org.example.Test", "Test2"); + g_variant_builder_init (&_arguments_builder, G_VARIANT_TYPE_TUPLE); + g_variant_builder_add_value (&_arguments_builder, g_variant_new_string (foo_enum_to_string (e))); + _arguments = g_variant_builder_end (&_arguments_builder); + g_dbus_message_set_body (_message, _arguments); + _reply_message = g_dbus_connection_send_message_with_reply_sync (g_dbus_proxy_get_connection ((GDBusProxy *) self), _message, G_DBUS_SEND_MESSAGE_FLAGS_NONE, g_dbus_proxy_get_default_timeout ((GDBusProxy *) self), NULL, NULL, error); + g_object_unref (_message); + if (!_reply_message) { + return; + } + if (g_dbus_message_to_gerror (_reply_message, error)) { + g_object_unref (_reply_message); + return; + } + g_object_unref (_reply_message); +} + +static void +test_proxy_test3 (Test* self, + FooEnum e1, + gint fd, + FooEnum e2, + GError** error) +{ + GDBusMessage *_message; + GVariant *_arguments; + GVariantBuilder _arguments_builder; + GDBusMessage *_reply_message; + G_DBUS_ERROR; + _message = g_dbus_message_new_method_call (g_dbus_proxy_get_name ((GDBusProxy *) self), g_dbus_proxy_get_object_path ((GDBusProxy *) self), "org.example.Test", "Test3"); + g_variant_builder_init (&_arguments_builder, G_VARIANT_TYPE_TUPLE); + g_variant_builder_add_value (&_arguments_builder, g_variant_new_string (foo_enum_to_string (e1))); + g_variant_builder_add_value (&_arguments_builder, g_variant_new_int32 (fd)); + g_variant_builder_add_value (&_arguments_builder, g_variant_new_string (foo_enum_to_string (e2))); + _arguments = g_variant_builder_end (&_arguments_builder); + g_dbus_message_set_body (_message, _arguments); + _reply_message = g_dbus_connection_send_message_with_reply_sync (g_dbus_proxy_get_connection ((GDBusProxy *) self), _message, G_DBUS_SEND_MESSAGE_FLAGS_NONE, g_dbus_proxy_get_default_timeout ((GDBusProxy *) self), NULL, NULL, error); + g_object_unref (_message); + if (!_reply_message) { + return; + } + if (g_dbus_message_to_gerror (_reply_message, error)) { + g_object_unref (_reply_message); + return; + } + g_object_unref (_reply_message); +} + +static void +test_proxy_test4 (Test* self, + FooEnum e) +{ + GDBusMessage *_message; + GVariant *_arguments; + GVariantBuilder _arguments_builder; + GDBusMessage *_reply_message; + _message = g_dbus_message_new_method_call (g_dbus_proxy_get_name ((GDBusProxy *) self), g_dbus_proxy_get_object_path ((GDBusProxy *) self), "org.example.Test", "Test4"); + g_variant_builder_init (&_arguments_builder, G_VARIANT_TYPE_TUPLE); + g_variant_builder_add_value (&_arguments_builder, g_variant_new_string (foo_enum_to_string (e))); + _arguments = g_variant_builder_end (&_arguments_builder); + g_dbus_message_set_body (_message, _arguments); + _reply_message = g_dbus_connection_send_message_with_reply_sync (g_dbus_proxy_get_connection ((GDBusProxy *) self), _message, G_DBUS_SEND_MESSAGE_FLAGS_NONE, g_dbus_proxy_get_default_timeout ((GDBusProxy *) self), NULL, NULL, NULL); + g_object_unref (_message); + if (!_reply_message) { + return; + } + if (g_dbus_message_to_gerror (_reply_message, NULL)) { + g_object_unref (_reply_message); + return; + } + g_object_unref (_reply_message); +} + +static void +test_proxy_test5_async (Test* self, + FooEnum e, + GAsyncReadyCallback _callback_, + gpointer _user_data_) +{ + GDBusMessage *_message; + GVariant *_arguments; + GVariantBuilder _arguments_builder; + _message = g_dbus_message_new_method_call (g_dbus_proxy_get_name ((GDBusProxy *) self), g_dbus_proxy_get_object_path ((GDBusProxy *) self), "org.example.Test", "Test5"); + g_variant_builder_init (&_arguments_builder, G_VARIANT_TYPE_TUPLE); + g_variant_builder_add_value (&_arguments_builder, g_variant_new_string (foo_enum_to_string (e))); + _arguments = g_variant_builder_end (&_arguments_builder); + g_dbus_message_set_body (_message, _arguments); + if (_callback_ != NULL) { + g_dbus_connection_send_message_with_reply (g_dbus_proxy_get_connection ((GDBusProxy *) self), _message, G_DBUS_SEND_MESSAGE_FLAGS_NONE, g_dbus_proxy_get_default_timeout ((GDBusProxy *) self), NULL, NULL, _vala_g_async_ready_callback, g_task_new ((GObject *) self, NULL, _callback_, _user_data_)); + } else { + g_dbus_message_set_flags (_message, G_DBUS_MESSAGE_FLAGS_NO_REPLY_EXPECTED); + g_dbus_connection_send_message (g_dbus_proxy_get_connection ((GDBusProxy *) self), _message, G_DBUS_SEND_MESSAGE_FLAGS_NONE, NULL, NULL); + } + g_object_unref (_message); +} + +static void +test_proxy_test5_finish (Test* self, + GAsyncResult* _res_) +{ + GAsyncResult *_inner_res; + GDBusMessage *_reply_message; + _inner_res = g_task_propagate_pointer ((GTask *) _res_, NULL); + _reply_message = g_dbus_connection_send_message_with_reply_finish (g_dbus_proxy_get_connection ((GDBusProxy *) self), _inner_res, NULL); + g_object_unref (_inner_res); + if (!_reply_message) { + return; + } + if (g_dbus_message_to_gerror (_reply_message, NULL)) { + g_object_unref (_reply_message); + return; + } + g_object_unref (_reply_message); +} + +static void +test_proxy_test_interface_init (TestIface* iface) +{ + iface->test1 = test_proxy_test1_async; + iface->test1_finish = test_proxy_test1_finish; + iface->test2 = test_proxy_test2; + iface->test3 = test_proxy_test3; + iface->test4 = test_proxy_test4; + iface->test5 = test_proxy_test5_async; + iface->test5_finish = test_proxy_test5_finish; +} + +static void +_dbus_test_test1 (Test* self, + GVariant* _parameters_, + GDBusMethodInvocation* invocation) +{ + GVariantIter _arguments_iter; + TestTest1ReadyData* _ready_data; + GVariant* _tmp0_; + GError* error = NULL; + g_variant_iter_init (&_arguments_iter, _parameters_); + _ready_data = g_slice_new0 (TestTest1ReadyData); + _ready_data->_invocation_ = invocation; + _tmp0_ = g_variant_iter_next_value (&_arguments_iter); + _ready_data->e = foo_enum_from_string (g_variant_get_string (_tmp0_, NULL), &error); + g_variant_unref (_tmp0_); + if (error) { + g_dbus_method_invocation_return_gerror (invocation, error); + g_error_free (error); + return; + } + test_test1 (self, _ready_data->e, (GAsyncReadyCallback) _dbus_test_test1_ready, _ready_data); +} + +static void +_dbus_test_test1_ready (GObject * source_object, + GAsyncResult * _res_, + gpointer _user_data_) +{ + TestTest1ReadyData* _ready_data; + GDBusMethodInvocation* invocation; + GError* error = NULL; + GDBusMessage* _reply_message = NULL; + GVariant* _reply; + GVariantBuilder _reply_builder; + _ready_data = _user_data_; + invocation = _ready_data->_invocation_; + test_test1_finish ((Test*) source_object, _res_, &error); + if (error) { + g_dbus_method_invocation_return_gerror (invocation, error); + g_error_free (error); + goto _error; + } + _reply_message = g_dbus_message_new_method_reply (g_dbus_method_invocation_get_message (invocation)); + g_variant_builder_init (&_reply_builder, G_VARIANT_TYPE_TUPLE); + _reply = g_variant_builder_end (&_reply_builder); + g_dbus_message_set_body (_reply_message, _reply); + g_dbus_connection_send_message (g_dbus_method_invocation_get_connection (invocation), _reply_message, G_DBUS_SEND_MESSAGE_FLAGS_NONE, NULL, NULL); + g_object_unref (invocation); + g_object_unref (_reply_message); + _error: + g_slice_free (TestTest1ReadyData, _ready_data); +} + +static void +_dbus_test_test2 (Test* self, + GVariant* _parameters_, + GDBusMethodInvocation* invocation) +{ + GError* error = NULL; + GVariantIter _arguments_iter; + FooEnum e = 0; + GVariant* _tmp1_; + GDBusMessage* _reply_message = NULL; + GVariant* _reply; + GVariantBuilder _reply_builder; + g_variant_iter_init (&_arguments_iter, _parameters_); + _tmp1_ = g_variant_iter_next_value (&_arguments_iter); + e = foo_enum_from_string (g_variant_get_string (_tmp1_, NULL), &error); + g_variant_unref (_tmp1_); + if (error) { + g_dbus_method_invocation_return_gerror (invocation, error); + g_error_free (error); + return; + } + test_test2 (self, e, &error); + if (error) { + g_dbus_method_invocation_return_gerror (invocation, error); + g_error_free (error); + return; + } + _reply_message = g_dbus_message_new_method_reply (g_dbus_method_invocation_get_message (invocation)); + g_variant_builder_init (&_reply_builder, G_VARIANT_TYPE_TUPLE); + _reply = g_variant_builder_end (&_reply_builder); + g_dbus_message_set_body (_reply_message, _reply); + g_dbus_connection_send_message (g_dbus_method_invocation_get_connection (invocation), _reply_message, G_DBUS_SEND_MESSAGE_FLAGS_NONE, NULL, NULL); + g_object_unref (invocation); + g_object_unref (_reply_message); +} + +static void +_dbus_test_test3 (Test* self, + GVariant* _parameters_, + GDBusMethodInvocation* invocation) +{ + GError* error = NULL; + GVariantIter _arguments_iter; + FooEnum e1 = 0; + GVariant* _tmp2_; + gint fd = 0; + GVariant* _tmp3_; + FooEnum e2 = 0; + GVariant* _tmp4_; + GDBusMessage* _reply_message = NULL; + GVariant* _reply; + GVariantBuilder _reply_builder; + g_variant_iter_init (&_arguments_iter, _parameters_); + _tmp2_ = g_variant_iter_next_value (&_arguments_iter); + e1 = foo_enum_from_string (g_variant_get_string (_tmp2_, NULL), &error); + g_variant_unref (_tmp2_); + if (error) { + g_dbus_method_invocation_return_gerror (invocation, error); + g_error_free (error); + return; + } + _tmp3_ = g_variant_iter_next_value (&_arguments_iter); + fd = g_variant_get_int32 (_tmp3_); + g_variant_unref (_tmp3_); + _tmp4_ = g_variant_iter_next_value (&_arguments_iter); + e2 = foo_enum_from_string (g_variant_get_string (_tmp4_, NULL), &error); + g_variant_unref (_tmp4_); + if (error) { + g_dbus_method_invocation_return_gerror (invocation, error); + g_error_free (error); + return; + } + test_test3 (self, e1, fd, e2, &error); + if (error) { + g_dbus_method_invocation_return_gerror (invocation, error); + g_error_free (error); + return; + } + _reply_message = g_dbus_message_new_method_reply (g_dbus_method_invocation_get_message (invocation)); + g_variant_builder_init (&_reply_builder, G_VARIANT_TYPE_TUPLE); + _reply = g_variant_builder_end (&_reply_builder); + g_dbus_message_set_body (_reply_message, _reply); + g_dbus_connection_send_message (g_dbus_method_invocation_get_connection (invocation), _reply_message, G_DBUS_SEND_MESSAGE_FLAGS_NONE, NULL, NULL); + g_object_unref (invocation); + g_object_unref (_reply_message); +} + +static void +_dbus_test_test4 (Test* self, + GVariant* _parameters_, + GDBusMethodInvocation* invocation) +{ + GError* error = NULL; + GVariantIter _arguments_iter; + FooEnum e = 0; + GVariant* _tmp5_; + GDBusMessage* _reply_message = NULL; + GVariant* _reply; + GVariantBuilder _reply_builder; + g_variant_iter_init (&_arguments_iter, _parameters_); + _tmp5_ = g_variant_iter_next_value (&_arguments_iter); + e = foo_enum_from_string (g_variant_get_string (_tmp5_, NULL), &error); + g_variant_unref (_tmp5_); + if (error) { + g_dbus_method_invocation_return_gerror (invocation, error); + g_error_free (error); + return; + } + test_test4 (self, e); + _reply_message = g_dbus_message_new_method_reply (g_dbus_method_invocation_get_message (invocation)); + g_variant_builder_init (&_reply_builder, G_VARIANT_TYPE_TUPLE); + _reply = g_variant_builder_end (&_reply_builder); + g_dbus_message_set_body (_reply_message, _reply); + g_dbus_connection_send_message (g_dbus_method_invocation_get_connection (invocation), _reply_message, G_DBUS_SEND_MESSAGE_FLAGS_NONE, NULL, NULL); + g_object_unref (invocation); + g_object_unref (_reply_message); +} + +static void +_dbus_test_test5 (Test* self, + GVariant* _parameters_, + GDBusMethodInvocation* invocation) +{ + GVariantIter _arguments_iter; + TestTest5ReadyData* _ready_data; + GVariant* _tmp6_; + GError* error = NULL; + g_variant_iter_init (&_arguments_iter, _parameters_); + _ready_data = g_slice_new0 (TestTest5ReadyData); + _ready_data->_invocation_ = invocation; + _tmp6_ = g_variant_iter_next_value (&_arguments_iter); + _ready_data->e = foo_enum_from_string (g_variant_get_string (_tmp6_, NULL), &error); + g_variant_unref (_tmp6_); + if (error) { + g_dbus_method_invocation_return_gerror (invocation, error); + g_error_free (error); + return; + } + test_test5 (self, _ready_data->e, (GAsyncReadyCallback) _dbus_test_test5_ready, _ready_data); +} + +static void +_dbus_test_test5_ready (GObject * source_object, + GAsyncResult * _res_, + gpointer _user_data_) +{ + TestTest5ReadyData* _ready_data; + GDBusMethodInvocation* invocation; + GError* error = NULL; + GDBusMessage* _reply_message = NULL; + GVariant* _reply; + GVariantBuilder _reply_builder; + _ready_data = _user_data_; + invocation = _ready_data->_invocation_; + test_test5_finish ((Test*) source_object, _res_); + _reply_message = g_dbus_message_new_method_reply (g_dbus_method_invocation_get_message (invocation)); + g_variant_builder_init (&_reply_builder, G_VARIANT_TYPE_TUPLE); + _reply = g_variant_builder_end (&_reply_builder); + g_dbus_message_set_body (_reply_message, _reply); + g_dbus_connection_send_message (g_dbus_method_invocation_get_connection (invocation), _reply_message, G_DBUS_SEND_MESSAGE_FLAGS_NONE, NULL, NULL); + g_object_unref (invocation); + g_object_unref (_reply_message); + _error: + g_slice_free (TestTest5ReadyData, _ready_data); +} + +static void +test_dbus_interface_method_call (GDBusConnection* connection, + const gchar* sender, + const gchar* object_path, + const gchar* interface_name, + const gchar* method_name, + GVariant* parameters, + GDBusMethodInvocation* invocation, + gpointer user_data) +{ + gpointer* data; + gpointer object; + data = user_data; + object = data[0]; + if (strcmp (method_name, "Test1") == 0) { + _dbus_test_test1 (object, parameters, invocation); + } else if (strcmp (method_name, "Test2") == 0) { + _dbus_test_test2 (object, parameters, invocation); + } else if (strcmp (method_name, "Test3") == 0) { + _dbus_test_test3 (object, parameters, invocation); + } else if (strcmp (method_name, "Test4") == 0) { + _dbus_test_test4 (object, parameters, invocation); + } else if (strcmp (method_name, "Test5") == 0) { + _dbus_test_test5 (object, parameters, invocation); + } else { + g_object_unref (invocation); + } +} + +static GVariant* +test_dbus_interface_get_property (GDBusConnection* connection, + const gchar* sender, + const gchar* object_path, + const gchar* interface_name, + const gchar* property_name, + GError** error, + gpointer user_data) +{ + gpointer* data; + gpointer object; + data = user_data; + object = data[0]; + return NULL; +} + +static gboolean +test_dbus_interface_set_property (GDBusConnection* connection, + const gchar* sender, + const gchar* object_path, + const gchar* interface_name, + const gchar* property_name, + GVariant* value, + GError** error, + gpointer user_data) +{ + gpointer* data; + gpointer object; + data = user_data; + object = data[0]; + return FALSE; +} + +guint +test_register_object (gpointer object, + GDBusConnection* connection, + const gchar* path, + GError** error) +{ + guint result; + gpointer *data; + data = g_new (gpointer, 3); + data[0] = g_object_ref (object); + data[1] = g_object_ref (connection); + data[2] = g_strdup (path); + result = g_dbus_connection_register_object (connection, path, (GDBusInterfaceInfo *) (&_test_dbus_interface_info), &_test_dbus_interface_vtable, data, _test_unregister_object, error); + if (!result) { + return 0; + } + return result; +} + +static void +_test_unregister_object (gpointer user_data) +{ + gpointer* data; + data = user_data; + g_object_unref (data[0]); + g_object_unref (data[1]); + g_free (data[2]); + g_free (data); +} + +static void +_vala_main (void) +{ +} + +int +main (int argc, + char ** argv) +{ + _vala_main (); + return 0; +} + diff --git a/tests/dbus/errors_client.c-expected b/tests/dbus/errors_client.c-expected new file mode 100644 index 000000000..f8f2acc04 --- /dev/null +++ b/tests/dbus/errors_client.c-expected @@ -0,0 +1,890 @@ +/* dbus_errors_client.c generated by valac, the Vala compiler + * generated from dbus_errors_client.vala, do not modify */ + +#include <gio/gio.h> +#include <glib.h> +#include <glib-object.h> +#include <stdlib.h> +#include <string.h> + +#if !defined(VALA_EXTERN) +#if defined(_MSC_VER) +#define VALA_EXTERN __declspec(dllexport) extern +#elif __GNUC__ >= 4 +#define VALA_EXTERN __attribute__((visibility("default"))) extern +#else +#define VALA_EXTERN extern +#endif +#endif + +#define TYPE_TEST (test_get_type ()) +#define TEST(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TYPE_TEST, Test)) +#define IS_TEST(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TYPE_TEST)) +#define TEST_GET_INTERFACE(obj) (G_TYPE_INSTANCE_GET_INTERFACE ((obj), TYPE_TEST, TestIface)) + +typedef struct _Test Test; +typedef struct _TestIface TestIface; + +#define TYPE_TEST_PROXY (test_proxy_get_type ()) +typedef GDBusProxy TestProxy; +typedef GDBusProxyClass TestProxyClass; +#define _g_free0(var) (var = (g_free (var), NULL)) +#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL))) +#define _g_error_free0(var) ((var == NULL) ? NULL : (var = (g_error_free (var), NULL))) +#define _vala_assert(expr, msg) if G_LIKELY (expr) ; else g_assertion_message_expr (G_LOG_DOMAIN, __FILE__, __LINE__, G_STRFUNC, msg); +#define _vala_return_if_fail(expr, msg) if G_LIKELY (expr) ; else { g_return_if_fail_warning (G_LOG_DOMAIN, G_STRFUNC, msg); return; } +#define _vala_return_val_if_fail(expr, msg, val) if G_LIKELY (expr) ; else { g_return_if_fail_warning (G_LOG_DOMAIN, G_STRFUNC, msg); return val; } +#define _vala_warn_if_fail(expr, msg) if G_LIKELY (expr) ; else g_warn_message (G_LOG_DOMAIN, __FILE__, __LINE__, G_STRFUNC, msg); + +typedef enum { + TEST_ERROR_NOT_SO_GOOD, + TEST_ERROR_BAD, + TEST_ERROR_WORSE +} TestError; +#define TEST_ERROR test_error_quark () +struct _TestIface { + GTypeInterface parent_iface; + void (*test_void) (Test* self, GError** error); + gint (*test_int) (Test* self, gint i, gint* j, GError** error); + gchar* (*test_string) (Test* self, const gchar* s, gchar* * t, GError** error); + void (*test_cancellable) (Test* self, GCancellable* cancellable, GError** error); + void (*test_custom_error) (Test* self, GError** error); +}; + +VALA_EXTERN GQuark test_error_quark (void); +VALA_EXTERN GType test_proxy_get_type (void) G_GNUC_CONST ; +VALA_EXTERN guint test_register_object (void* object, + GDBusConnection* connection, + const gchar* path, + GError** error); +VALA_EXTERN GType test_get_type (void) G_GNUC_CONST ; +VALA_EXTERN void test_test_void (Test* self, + GError** error); +VALA_EXTERN gint test_test_int (Test* self, + gint i, + gint* j, + GError** error); +VALA_EXTERN gchar* test_test_string (Test* self, + const gchar* s, + gchar* * t, + GError** error); +VALA_EXTERN void test_test_cancellable (Test* self, + GCancellable* cancellable, + GError** error); +VALA_EXTERN void test_test_custom_error (Test* self, + GError** error); +static GType test_get_type_once (void); +static void test_proxy_g_signal (GDBusProxy* proxy, + const gchar* sender_name, + const gchar* signal_name, + GVariant* parameters); +static void test_proxy_test_void (Test* self, + GError** error); +static gint test_proxy_test_int (Test* self, + gint i, + gint* j, + GError** error); +static gchar* test_proxy_test_string (Test* self, + const gchar* s, + gchar* * t, + GError** error); +static void test_proxy_test_cancellable (Test* self, + GCancellable* cancellable, + GError** error); +static void test_proxy_test_custom_error (Test* self, + GError** error); +static void test_proxy_test_interface_init (TestIface* iface); +static void _dbus_test_test_void (Test* self, + GVariant* _parameters_, + GDBusMethodInvocation* invocation); +static void _dbus_test_test_int (Test* self, + GVariant* _parameters_, + GDBusMethodInvocation* invocation); +static void _dbus_test_test_string (Test* self, + GVariant* _parameters_, + GDBusMethodInvocation* invocation); +static void _dbus_test_test_cancellable (Test* self, + GVariant* _parameters_, + GDBusMethodInvocation* invocation); +static void _dbus_test_test_custom_error (Test* self, + GVariant* _parameters_, + GDBusMethodInvocation* invocation); +static void test_dbus_interface_method_call (GDBusConnection* connection, + const gchar* sender, + const gchar* object_path, + const gchar* interface_name, + const gchar* method_name, + GVariant* parameters, + GDBusMethodInvocation* invocation, + gpointer user_data); +static GVariant* test_dbus_interface_get_property (GDBusConnection* connection, + const gchar* sender, + const gchar* object_path, + const gchar* interface_name, + const gchar* property_name, + GError** error, + gpointer user_data); +static gboolean test_dbus_interface_set_property (GDBusConnection* connection, + const gchar* sender, + const gchar* object_path, + const gchar* interface_name, + const gchar* property_name, + GVariant* value, + GError** error, + gpointer user_data); +static void _test_unregister_object (gpointer user_data); +static void _vala_main (void); + +static const GDBusErrorEntry test_error_entries[] = {{TEST_ERROR_NOT_SO_GOOD, "org.example.TestError.NotSoGood"}, {TEST_ERROR_BAD, "org.example.TestError.Bad"}, {TEST_ERROR_WORSE, "org.example.TestError.Worse"}}; +static const GDBusArgInfo * const _test_dbus_arg_info_test_void_in[] = {NULL}; +static const GDBusArgInfo * const _test_dbus_arg_info_test_void_out[] = {NULL}; +static const GDBusMethodInfo _test_dbus_method_info_test_void = {-1, "TestVoid", (GDBusArgInfo **) (&_test_dbus_arg_info_test_void_in), (GDBusArgInfo **) (&_test_dbus_arg_info_test_void_out), NULL}; +static const GDBusArgInfo _test_dbus_arg_info_test_int_i = {-1, "i", "i", NULL}; +static const GDBusArgInfo _test_dbus_arg_info_test_int_j = {-1, "j", "i", NULL}; +static const GDBusArgInfo _test_dbus_arg_info_test_int_result = {-1, "result", "i", NULL}; +static const GDBusArgInfo * const _test_dbus_arg_info_test_int_in[] = {&_test_dbus_arg_info_test_int_i, NULL}; +static const GDBusArgInfo * const _test_dbus_arg_info_test_int_out[] = {&_test_dbus_arg_info_test_int_j, &_test_dbus_arg_info_test_int_result, NULL}; +static const GDBusMethodInfo _test_dbus_method_info_test_int = {-1, "TestInt", (GDBusArgInfo **) (&_test_dbus_arg_info_test_int_in), (GDBusArgInfo **) (&_test_dbus_arg_info_test_int_out), NULL}; +static const GDBusArgInfo _test_dbus_arg_info_test_string_s = {-1, "s", "s", NULL}; +static const GDBusArgInfo _test_dbus_arg_info_test_string_t = {-1, "t", "s", NULL}; +static const GDBusArgInfo _test_dbus_arg_info_test_string_result = {-1, "result", "s", NULL}; +static const GDBusArgInfo * const _test_dbus_arg_info_test_string_in[] = {&_test_dbus_arg_info_test_string_s, NULL}; +static const GDBusArgInfo * const _test_dbus_arg_info_test_string_out[] = {&_test_dbus_arg_info_test_string_t, &_test_dbus_arg_info_test_string_result, NULL}; +static const GDBusMethodInfo _test_dbus_method_info_test_string = {-1, "TestString", (GDBusArgInfo **) (&_test_dbus_arg_info_test_string_in), (GDBusArgInfo **) (&_test_dbus_arg_info_test_string_out), NULL}; +static const GDBusArgInfo * const _test_dbus_arg_info_test_cancellable_in[] = {NULL}; +static const GDBusArgInfo * const _test_dbus_arg_info_test_cancellable_out[] = {NULL}; +static const GDBusMethodInfo _test_dbus_method_info_test_cancellable = {-1, "TestCancellable", (GDBusArgInfo **) (&_test_dbus_arg_info_test_cancellable_in), (GDBusArgInfo **) (&_test_dbus_arg_info_test_cancellable_out), NULL}; +static const GDBusArgInfo * const _test_dbus_arg_info_test_custom_error_in[] = {NULL}; +static const GDBusArgInfo * const _test_dbus_arg_info_test_custom_error_out[] = {NULL}; +static const GDBusMethodInfo _test_dbus_method_info_test_custom_error = {-1, "TestCustomError", (GDBusArgInfo **) (&_test_dbus_arg_info_test_custom_error_in), (GDBusArgInfo **) (&_test_dbus_arg_info_test_custom_error_out), NULL}; +static const GDBusMethodInfo * const _test_dbus_method_info[] = {&_test_dbus_method_info_test_void, &_test_dbus_method_info_test_int, &_test_dbus_method_info_test_string, &_test_dbus_method_info_test_cancellable, &_test_dbus_method_info_test_custom_error, NULL}; +static const GDBusSignalInfo * const _test_dbus_signal_info[] = {NULL}; +static const GDBusPropertyInfo * const _test_dbus_property_info[] = {NULL}; +static const GDBusInterfaceInfo _test_dbus_interface_info = {-1, "org.example.Test", (GDBusMethodInfo **) (&_test_dbus_method_info), (GDBusSignalInfo **) (&_test_dbus_signal_info), (GDBusPropertyInfo **) (&_test_dbus_property_info), NULL}; +static const GDBusInterfaceVTable _test_dbus_interface_vtable = {test_dbus_interface_method_call, test_dbus_interface_get_property, test_dbus_interface_set_property}; + +GQuark +test_error_quark (void) +{ + static volatile gsize test_error_quark_volatile = 0; + g_dbus_error_register_error_domain ("test-error-quark", &test_error_quark_volatile, test_error_entries, G_N_ELEMENTS (test_error_entries)); + return (GQuark) test_error_quark_volatile; +} + +void +test_test_void (Test* self, + GError** error) +{ + TestIface* _iface_; + g_return_if_fail (IS_TEST (self)); + _iface_ = TEST_GET_INTERFACE (self); + if (_iface_->test_void) { + _iface_->test_void (self, error); + } +} + +gint +test_test_int (Test* self, + gint i, + gint* j, + GError** error) +{ + TestIface* _iface_; + g_return_val_if_fail (IS_TEST (self), 0); + _iface_ = TEST_GET_INTERFACE (self); + if (_iface_->test_int) { + return _iface_->test_int (self, i, j, error); + } + return -1; +} + +gchar* +test_test_string (Test* self, + const gchar* s, + gchar* * t, + GError** error) +{ + TestIface* _iface_; + g_return_val_if_fail (IS_TEST (self), NULL); + _iface_ = TEST_GET_INTERFACE (self); + if (_iface_->test_string) { + return _iface_->test_string (self, s, t, error); + } + return NULL; +} + +void +test_test_cancellable (Test* self, + GCancellable* cancellable, + GError** error) +{ + TestIface* _iface_; + g_return_if_fail (IS_TEST (self)); + _iface_ = TEST_GET_INTERFACE (self); + if (_iface_->test_cancellable) { + _iface_->test_cancellable (self, cancellable, error); + } +} + +void +test_test_custom_error (Test* self, + GError** error) +{ + TestIface* _iface_; + g_return_if_fail (IS_TEST (self)); + _iface_ = TEST_GET_INTERFACE (self); + if (_iface_->test_custom_error) { + _iface_->test_custom_error (self, error); + } +} + +static void +test_default_init (TestIface * iface, + gpointer iface_data) +{ +} + +static GType +test_get_type_once (void) +{ + static const GTypeInfo g_define_type_info = { sizeof (TestIface), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) test_default_init, (GClassFinalizeFunc) NULL, NULL, 0, 0, (GInstanceInitFunc) NULL, NULL }; + GType test_type_id; + test_type_id = g_type_register_static (G_TYPE_INTERFACE, "Test", &g_define_type_info, 0); + g_type_interface_add_prerequisite (test_type_id, G_TYPE_OBJECT); + g_type_set_qdata (test_type_id, g_quark_from_static_string ("vala-dbus-proxy-type"), (void*) test_proxy_get_type); + g_type_set_qdata (test_type_id, g_quark_from_static_string ("vala-dbus-interface-name"), "org.example.Test"); + g_type_set_qdata (test_type_id, g_quark_from_static_string ("vala-dbus-interface-info"), (void*) (&_test_dbus_interface_info)); + g_type_set_qdata (test_type_id, g_quark_from_static_string ("vala-dbus-register-object"), (void*) test_register_object); + return test_type_id; +} + +GType +test_get_type (void) +{ + static volatile gsize test_type_id__volatile = 0; + if (g_once_init_enter (&test_type_id__volatile)) { + GType test_type_id; + test_type_id = test_get_type_once (); + g_once_init_leave (&test_type_id__volatile, test_type_id); + } + return test_type_id__volatile; +} + +G_DEFINE_TYPE_EXTENDED (TestProxy, test_proxy, G_TYPE_DBUS_PROXY, 0, G_IMPLEMENT_INTERFACE (TYPE_TEST, test_proxy_test_interface_init) ) +static void +test_proxy_class_init (TestProxyClass* klass) +{ + G_DBUS_PROXY_CLASS (klass)->g_signal = test_proxy_g_signal; +} + +static void +test_proxy_g_signal (GDBusProxy* proxy, + const gchar* sender_name, + const gchar* signal_name, + GVariant* parameters) +{ +} + +static void +test_proxy_init (TestProxy* self) +{ + g_dbus_proxy_set_interface_info (G_DBUS_PROXY (self), (GDBusInterfaceInfo *) (&_test_dbus_interface_info)); +} + +static void +test_proxy_test_void (Test* self, + GError** error) +{ + GDBusMessage *_message; + GVariant *_arguments; + GVariantBuilder _arguments_builder; + GDBusMessage *_reply_message; + _message = g_dbus_message_new_method_call (g_dbus_proxy_get_name ((GDBusProxy *) self), g_dbus_proxy_get_object_path ((GDBusProxy *) self), "org.example.Test", "TestVoid"); + g_variant_builder_init (&_arguments_builder, G_VARIANT_TYPE_TUPLE); + _arguments = g_variant_builder_end (&_arguments_builder); + g_dbus_message_set_body (_message, _arguments); + _reply_message = g_dbus_connection_send_message_with_reply_sync (g_dbus_proxy_get_connection ((GDBusProxy *) self), _message, G_DBUS_SEND_MESSAGE_FLAGS_NONE, g_dbus_proxy_get_default_timeout ((GDBusProxy *) self), NULL, NULL, error); + g_object_unref (_message); + if (!_reply_message) { + return; + } + if (g_dbus_message_to_gerror (_reply_message, error)) { + g_object_unref (_reply_message); + return; + } + g_object_unref (_reply_message); +} + +static gint +test_proxy_test_int (Test* self, + gint i, + gint* j, + GError** error) +{ + GDBusMessage *_message; + GVariant *_arguments; + GVariantBuilder _arguments_builder; + GDBusMessage *_reply_message; + GVariant *_reply; + GVariantIter _reply_iter; + gint _vala_j = 0; + GVariant* _tmp2_; + gint _result = 0; + GVariant* _tmp3_; + _message = g_dbus_message_new_method_call (g_dbus_proxy_get_name ((GDBusProxy *) self), g_dbus_proxy_get_object_path ((GDBusProxy *) self), "org.example.Test", "TestInt"); + g_variant_builder_init (&_arguments_builder, G_VARIANT_TYPE_TUPLE); + g_variant_builder_add_value (&_arguments_builder, g_variant_new_int32 (i)); + _arguments = g_variant_builder_end (&_arguments_builder); + g_dbus_message_set_body (_message, _arguments); + _reply_message = g_dbus_connection_send_message_with_reply_sync (g_dbus_proxy_get_connection ((GDBusProxy *) self), _message, G_DBUS_SEND_MESSAGE_FLAGS_NONE, g_dbus_proxy_get_default_timeout ((GDBusProxy *) self), NULL, NULL, error); + g_object_unref (_message); + if (!_reply_message) { + gint _tmp0_ = 0; + return _tmp0_; + } + if (g_dbus_message_to_gerror (_reply_message, error)) { + gint _tmp1_ = 0; + g_object_unref (_reply_message); + return _tmp1_; + } + _reply = g_dbus_message_get_body (_reply_message); + g_variant_iter_init (&_reply_iter, _reply); + _tmp2_ = g_variant_iter_next_value (&_reply_iter); + _vala_j = g_variant_get_int32 (_tmp2_); + g_variant_unref (_tmp2_); + *j = _vala_j; + _tmp3_ = g_variant_iter_next_value (&_reply_iter); + _result = g_variant_get_int32 (_tmp3_); + g_variant_unref (_tmp3_); + g_object_unref (_reply_message); + return _result; +} + +static gchar* +test_proxy_test_string (Test* self, + const gchar* s, + gchar* * t, + GError** error) +{ + GDBusMessage *_message; + GVariant *_arguments; + GVariantBuilder _arguments_builder; + GDBusMessage *_reply_message; + GVariant *_reply; + GVariantIter _reply_iter; + gchar* _vala_t = NULL; + GVariant* _tmp4_; + gchar* _result = NULL; + GVariant* _tmp5_; + _message = g_dbus_message_new_method_call (g_dbus_proxy_get_name ((GDBusProxy *) self), g_dbus_proxy_get_object_path ((GDBusProxy *) self), "org.example.Test", "TestString"); + g_variant_builder_init (&_arguments_builder, G_VARIANT_TYPE_TUPLE); + g_variant_builder_add_value (&_arguments_builder, g_variant_new_string (s)); + _arguments = g_variant_builder_end (&_arguments_builder); + g_dbus_message_set_body (_message, _arguments); + _reply_message = g_dbus_connection_send_message_with_reply_sync (g_dbus_proxy_get_connection ((GDBusProxy *) self), _message, G_DBUS_SEND_MESSAGE_FLAGS_NONE, g_dbus_proxy_get_default_timeout ((GDBusProxy *) self), NULL, NULL, error); + g_object_unref (_message); + if (!_reply_message) { + return NULL; + } + if (g_dbus_message_to_gerror (_reply_message, error)) { + g_object_unref (_reply_message); + return NULL; + } + _reply = g_dbus_message_get_body (_reply_message); + g_variant_iter_init (&_reply_iter, _reply); + _tmp4_ = g_variant_iter_next_value (&_reply_iter); + _vala_t = g_variant_dup_string (_tmp4_, NULL); + g_variant_unref (_tmp4_); + *t = _vala_t; + _tmp5_ = g_variant_iter_next_value (&_reply_iter); + _result = g_variant_dup_string (_tmp5_, NULL); + g_variant_unref (_tmp5_); + g_object_unref (_reply_message); + return _result; +} + +static void +test_proxy_test_cancellable (Test* self, + GCancellable* cancellable, + GError** error) +{ + GDBusMessage *_message; + GVariant *_arguments; + GVariantBuilder _arguments_builder; + GDBusMessage *_reply_message; + _message = g_dbus_message_new_method_call (g_dbus_proxy_get_name ((GDBusProxy *) self), g_dbus_proxy_get_object_path ((GDBusProxy *) self), "org.example.Test", "TestCancellable"); + g_variant_builder_init (&_arguments_builder, G_VARIANT_TYPE_TUPLE); + _arguments = g_variant_builder_end (&_arguments_builder); + g_dbus_message_set_body (_message, _arguments); + _reply_message = g_dbus_connection_send_message_with_reply_sync (g_dbus_proxy_get_connection ((GDBusProxy *) self), _message, G_DBUS_SEND_MESSAGE_FLAGS_NONE, g_dbus_proxy_get_default_timeout ((GDBusProxy *) self), NULL, cancellable, error); + g_object_unref (_message); + if (!_reply_message) { + return; + } + if (g_dbus_message_to_gerror (_reply_message, error)) { + g_object_unref (_reply_message); + return; + } + g_object_unref (_reply_message); +} + +static void +test_proxy_test_custom_error (Test* self, + GError** error) +{ + GDBusMessage *_message; + GVariant *_arguments; + GVariantBuilder _arguments_builder; + GDBusMessage *_reply_message; + TEST_ERROR; + _message = g_dbus_message_new_method_call (g_dbus_proxy_get_name ((GDBusProxy *) self), g_dbus_proxy_get_object_path ((GDBusProxy *) self), "org.example.Test", "TestCustomError"); + g_variant_builder_init (&_arguments_builder, G_VARIANT_TYPE_TUPLE); + _arguments = g_variant_builder_end (&_arguments_builder); + g_dbus_message_set_body (_message, _arguments); + _reply_message = g_dbus_connection_send_message_with_reply_sync (g_dbus_proxy_get_connection ((GDBusProxy *) self), _message, G_DBUS_SEND_MESSAGE_FLAGS_NONE, g_dbus_proxy_get_default_timeout ((GDBusProxy *) self), NULL, NULL, error); + g_object_unref (_message); + if (!_reply_message) { + return; + } + if (g_dbus_message_to_gerror (_reply_message, error)) { + g_object_unref (_reply_message); + return; + } + g_object_unref (_reply_message); +} + +static void +test_proxy_test_interface_init (TestIface* iface) +{ + iface->test_void = test_proxy_test_void; + iface->test_int = test_proxy_test_int; + iface->test_string = test_proxy_test_string; + iface->test_cancellable = test_proxy_test_cancellable; + iface->test_custom_error = test_proxy_test_custom_error; +} + +static void +_dbus_test_test_void (Test* self, + GVariant* _parameters_, + GDBusMethodInvocation* invocation) +{ + GError* error = NULL; + GVariantIter _arguments_iter; + GDBusMessage* _reply_message = NULL; + GVariant* _reply; + GVariantBuilder _reply_builder; + g_variant_iter_init (&_arguments_iter, _parameters_); + test_test_void (self, &error); + if (error) { + g_dbus_method_invocation_return_gerror (invocation, error); + g_error_free (error); + return; + } + _reply_message = g_dbus_message_new_method_reply (g_dbus_method_invocation_get_message (invocation)); + g_variant_builder_init (&_reply_builder, G_VARIANT_TYPE_TUPLE); + _reply = g_variant_builder_end (&_reply_builder); + g_dbus_message_set_body (_reply_message, _reply); + g_dbus_connection_send_message (g_dbus_method_invocation_get_connection (invocation), _reply_message, G_DBUS_SEND_MESSAGE_FLAGS_NONE, NULL, NULL); + g_object_unref (invocation); + g_object_unref (_reply_message); +} + +static void +_dbus_test_test_int (Test* self, + GVariant* _parameters_, + GDBusMethodInvocation* invocation) +{ + GError* error = NULL; + GVariantIter _arguments_iter; + gint i = 0; + GVariant* _tmp6_; + GDBusMessage* _reply_message = NULL; + GVariant* _reply; + GVariantBuilder _reply_builder; + gint j = 0; + gint result; + g_variant_iter_init (&_arguments_iter, _parameters_); + _tmp6_ = g_variant_iter_next_value (&_arguments_iter); + i = g_variant_get_int32 (_tmp6_); + g_variant_unref (_tmp6_); + result = test_test_int (self, i, &j, &error); + if (error) { + g_dbus_method_invocation_return_gerror (invocation, error); + g_error_free (error); + return; + } + _reply_message = g_dbus_message_new_method_reply (g_dbus_method_invocation_get_message (invocation)); + g_variant_builder_init (&_reply_builder, G_VARIANT_TYPE_TUPLE); + g_variant_builder_add_value (&_reply_builder, g_variant_new_int32 (j)); + g_variant_builder_add_value (&_reply_builder, g_variant_new_int32 (result)); + _reply = g_variant_builder_end (&_reply_builder); + g_dbus_message_set_body (_reply_message, _reply); + g_dbus_connection_send_message (g_dbus_method_invocation_get_connection (invocation), _reply_message, G_DBUS_SEND_MESSAGE_FLAGS_NONE, NULL, NULL); + g_object_unref (invocation); + g_object_unref (_reply_message); +} + +static void +_dbus_test_test_string (Test* self, + GVariant* _parameters_, + GDBusMethodInvocation* invocation) +{ + GError* error = NULL; + GVariantIter _arguments_iter; + gchar* s = NULL; + GVariant* _tmp7_; + GDBusMessage* _reply_message = NULL; + GVariant* _reply; + GVariantBuilder _reply_builder; + gchar* t = NULL; + gchar* result; + g_variant_iter_init (&_arguments_iter, _parameters_); + _tmp7_ = g_variant_iter_next_value (&_arguments_iter); + s = g_variant_dup_string (_tmp7_, NULL); + g_variant_unref (_tmp7_); + result = test_test_string (self, s, &t, &error); + if (error) { + g_dbus_method_invocation_return_gerror (invocation, error); + g_error_free (error); + goto _error; + } + _reply_message = g_dbus_message_new_method_reply (g_dbus_method_invocation_get_message (invocation)); + g_variant_builder_init (&_reply_builder, G_VARIANT_TYPE_TUPLE); + g_variant_builder_add_value (&_reply_builder, g_variant_new_string (t)); + g_variant_builder_add_value (&_reply_builder, g_variant_new_string (result)); + _g_free0 (result); + _reply = g_variant_builder_end (&_reply_builder); + g_dbus_message_set_body (_reply_message, _reply); + g_dbus_connection_send_message (g_dbus_method_invocation_get_connection (invocation), _reply_message, G_DBUS_SEND_MESSAGE_FLAGS_NONE, NULL, NULL); + g_object_unref (invocation); + g_object_unref (_reply_message); + _error: + _g_free0 (s); + _g_free0 (t); + ; +} + +static void +_dbus_test_test_cancellable (Test* self, + GVariant* _parameters_, + GDBusMethodInvocation* invocation) +{ + GError* error = NULL; + GVariantIter _arguments_iter; + GDBusMessage* _reply_message = NULL; + GVariant* _reply; + GVariantBuilder _reply_builder; + g_variant_iter_init (&_arguments_iter, _parameters_); + test_test_cancellable (self, NULL, &error); + if (error) { + g_dbus_method_invocation_return_gerror (invocation, error); + g_error_free (error); + return; + } + _reply_message = g_dbus_message_new_method_reply (g_dbus_method_invocation_get_message (invocation)); + g_variant_builder_init (&_reply_builder, G_VARIANT_TYPE_TUPLE); + _reply = g_variant_builder_end (&_reply_builder); + g_dbus_message_set_body (_reply_message, _reply); + g_dbus_connection_send_message (g_dbus_method_invocation_get_connection (invocation), _reply_message, G_DBUS_SEND_MESSAGE_FLAGS_NONE, NULL, NULL); + g_object_unref (invocation); + g_object_unref (_reply_message); +} + +static void +_dbus_test_test_custom_error (Test* self, + GVariant* _parameters_, + GDBusMethodInvocation* invocation) +{ + GError* error = NULL; + GVariantIter _arguments_iter; + GDBusMessage* _reply_message = NULL; + GVariant* _reply; + GVariantBuilder _reply_builder; + g_variant_iter_init (&_arguments_iter, _parameters_); + test_test_custom_error (self, &error); + if (error) { + g_dbus_method_invocation_return_gerror (invocation, error); + g_error_free (error); + return; + } + _reply_message = g_dbus_message_new_method_reply (g_dbus_method_invocation_get_message (invocation)); + g_variant_builder_init (&_reply_builder, G_VARIANT_TYPE_TUPLE); + _reply = g_variant_builder_end (&_reply_builder); + g_dbus_message_set_body (_reply_message, _reply); + g_dbus_connection_send_message (g_dbus_method_invocation_get_connection (invocation), _reply_message, G_DBUS_SEND_MESSAGE_FLAGS_NONE, NULL, NULL); + g_object_unref (invocation); + g_object_unref (_reply_message); +} + +static void +test_dbus_interface_method_call (GDBusConnection* connection, + const gchar* sender, + const gchar* object_path, + const gchar* interface_name, + const gchar* method_name, + GVariant* parameters, + GDBusMethodInvocation* invocation, + gpointer user_data) +{ + gpointer* data; + gpointer object; + data = user_data; + object = data[0]; + if (strcmp (method_name, "TestVoid") == 0) { + _dbus_test_test_void (object, parameters, invocation); + } else if (strcmp (method_name, "TestInt") == 0) { + _dbus_test_test_int (object, parameters, invocation); + } else if (strcmp (method_name, "TestString") == 0) { + _dbus_test_test_string (object, parameters, invocation); + } else if (strcmp (method_name, "TestCancellable") == 0) { + _dbus_test_test_cancellable (object, parameters, invocation); + } else if (strcmp (method_name, "TestCustomError") == 0) { + _dbus_test_test_custom_error (object, parameters, invocation); + } else { + g_object_unref (invocation); + } +} + +static GVariant* +test_dbus_interface_get_property (GDBusConnection* connection, + const gchar* sender, + const gchar* object_path, + const gchar* interface_name, + const gchar* property_name, + GError** error, + gpointer user_data) +{ + gpointer* data; + gpointer object; + data = user_data; + object = data[0]; + return NULL; +} + +static gboolean +test_dbus_interface_set_property (GDBusConnection* connection, + const gchar* sender, + const gchar* object_path, + const gchar* interface_name, + const gchar* property_name, + GVariant* value, + GError** error, + gpointer user_data) +{ + gpointer* data; + gpointer object; + data = user_data; + object = data[0]; + return FALSE; +} + +guint +test_register_object (gpointer object, + GDBusConnection* connection, + const gchar* path, + GError** error) +{ + guint result; + gpointer *data; + data = g_new (gpointer, 3); + data[0] = g_object_ref (object); + data[1] = g_object_ref (connection); + data[2] = g_strdup (path); + result = g_dbus_connection_register_object (connection, path, (GDBusInterfaceInfo *) (&_test_dbus_interface_info), &_test_dbus_interface_vtable, data, _test_unregister_object, error); + if (!result) { + return 0; + } + return result; +} + +static void +_test_unregister_object (gpointer user_data) +{ + gpointer* data; + data = user_data; + g_object_unref (data[0]); + g_object_unref (data[1]); + g_free (data[2]); + g_free (data); +} + +static void +_vala_main (void) +{ + Test* test = NULL; + Test* _tmp0_; + GError* _inner_error0_ = NULL; + _tmp0_ = (Test*) g_initable_new (TYPE_TEST_PROXY, NULL, &_inner_error0_, "g-flags", 0, "g-name", "org.example.Test", "g-bus-type", G_BUS_TYPE_SESSION, "g-object-path", "/org/example/test", "g-interface-name", "org.example.Test", NULL); + test = (Test*) _tmp0_; + if (G_UNLIKELY (_inner_error0_ != NULL)) { + g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error0_->message, g_quark_to_string (_inner_error0_->domain), _inner_error0_->code); + g_clear_error (&_inner_error0_); + return; + } + { + test_test_void (test, &_inner_error0_); + if (G_UNLIKELY (_inner_error0_ != NULL)) { + goto __catch0_g_error; + } + g_assert_not_reached (); + } + goto __finally0; + __catch0_g_error: + { + g_clear_error (&_inner_error0_); + } + __finally0: + if (G_UNLIKELY (_inner_error0_ != NULL)) { + _g_object_unref0 (test); + g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error0_->message, g_quark_to_string (_inner_error0_->domain), _inner_error0_->code); + g_clear_error (&_inner_error0_); + return; + } + { + gint j = 0; + gint k = 0; + gint _tmp1_ = 0; + gint _tmp2_ = 0; + gint _tmp3_; + _tmp3_ = test_test_int (test, 42, &_tmp2_, &_inner_error0_); + j = _tmp2_; + _tmp1_ = _tmp3_; + if (G_UNLIKELY (_inner_error0_ != NULL)) { + goto __catch1_g_error; + } + k = _tmp1_; + g_assert_not_reached (); + } + goto __finally1; + __catch1_g_error: + { + g_clear_error (&_inner_error0_); + } + __finally1: + if (G_UNLIKELY (_inner_error0_ != NULL)) { + _g_object_unref0 (test); + g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error0_->message, g_quark_to_string (_inner_error0_->domain), _inner_error0_->code); + g_clear_error (&_inner_error0_); + return; + } + { + gchar* t = NULL; + gchar* u = NULL; + gchar* _tmp4_ = NULL; + gchar* _tmp5_ = NULL; + gchar* _tmp6_; + gchar* _tmp7_; + const gchar* _tmp8_; + _tmp6_ = test_test_string (test, "hello", &_tmp5_, &_inner_error0_); + _g_free0 (t); + t = _tmp5_; + _tmp4_ = _tmp6_; + if (G_UNLIKELY (_inner_error0_ != NULL)) { + _g_free0 (u); + _g_free0 (t); + goto __catch2_g_error; + } + _tmp7_ = _tmp4_; + _tmp4_ = NULL; + _g_free0 (u); + u = _tmp7_; + _tmp8_ = t; + _vala_assert (g_strcmp0 (_tmp8_, "world") == 0, "t == \"world\""); + _vala_assert (g_strcmp0 (u, "vala") == 0, "u == \"vala\""); + g_assert_not_reached (); + _g_free0 (_tmp4_); + _g_free0 (u); + _g_free0 (t); + } + goto __finally2; + __catch2_g_error: + { + g_clear_error (&_inner_error0_); + } + __finally2: + if (G_UNLIKELY (_inner_error0_ != NULL)) { + _g_object_unref0 (test); + g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error0_->message, g_quark_to_string (_inner_error0_->domain), _inner_error0_->code); + g_clear_error (&_inner_error0_); + return; + } + { + GCancellable* cancellable = NULL; + GCancellable* _tmp9_; + GCancellable* _tmp10_; + GCancellable* _tmp11_; + _tmp9_ = g_cancellable_new (); + cancellable = _tmp9_; + _tmp10_ = cancellable; + g_cancellable_cancel (_tmp10_); + _tmp11_ = cancellable; + test_test_cancellable (test, _tmp11_, &_inner_error0_); + if (G_UNLIKELY (_inner_error0_ != NULL)) { + _g_object_unref0 (cancellable); + goto __catch3_g_error; + } + g_assert_not_reached (); + _g_object_unref0 (cancellable); + } + goto __finally3; + __catch3_g_error: + { + g_clear_error (&_inner_error0_); + } + __finally3: + if (G_UNLIKELY (_inner_error0_ != NULL)) { + _g_object_unref0 (test); + g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error0_->message, g_quark_to_string (_inner_error0_->domain), _inner_error0_->code); + g_clear_error (&_inner_error0_); + return; + } + { + test_test_custom_error (test, &_inner_error0_); + if (G_UNLIKELY (_inner_error0_ != NULL)) { + if (_inner_error0_->domain == TEST_ERROR) { + goto __catch4_test_error; + } + goto __catch4_g_error; + } + g_assert_not_reached (); + } + goto __finally4; + __catch4_test_error: + { + GError* e = NULL; + GError* _tmp12_; + GError* _tmp13_; + const gchar* _tmp14_; + e = _inner_error0_; + _inner_error0_ = NULL; + _tmp12_ = e; + _vala_assert (g_error_matches (_tmp12_, TEST_ERROR, TEST_ERROR_BAD), "e is TestError.BAD"); + _tmp13_ = e; + _tmp14_ = _tmp13_->message; + _vala_assert (g_strcmp0 (_tmp14_, "GDBus.Error:org.example.TestError.Bad: Something failed badly") == 0, "e.message == \"GDBus.Error:org.example.TestError.Bad: Something failed badly\""); + _g_error_free0 (e); + } + goto __finally4; + __catch4_g_error: + { + g_clear_error (&_inner_error0_); + g_assert_not_reached (); + } + __finally4: + if (G_UNLIKELY (_inner_error0_ != NULL)) { + _g_object_unref0 (test); + g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error0_->message, g_quark_to_string (_inner_error0_->domain), _inner_error0_->code); + g_clear_error (&_inner_error0_); + return; + } + _g_object_unref0 (test); +} + +int +main (int argc, + char ** argv) +{ + _vala_main (); + return 0; +} + diff --git a/tests/dbus/errors_server.c-expected b/tests/dbus/errors_server.c-expected new file mode 100644 index 000000000..805cf6aae --- /dev/null +++ b/tests/dbus/errors_server.c-expected @@ -0,0 +1,692 @@ +/* dbus_errors_server.c generated by valac, the Vala compiler + * generated from dbus_errors_server.vala, do not modify */ + +#include <gio/gio.h> +#include <glib.h> +#include <glib-object.h> +#include <stdlib.h> +#include <string.h> + +#if !defined(VALA_EXTERN) +#if defined(_MSC_VER) +#define VALA_EXTERN __declspec(dllexport) extern +#elif __GNUC__ >= 4 +#define VALA_EXTERN __attribute__((visibility("default"))) extern +#else +#define VALA_EXTERN extern +#endif +#endif + +#define TYPE_TEST (test_get_type ()) +#define TEST(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TYPE_TEST, Test)) +#define TEST_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), TYPE_TEST, TestClass)) +#define IS_TEST(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TYPE_TEST)) +#define IS_TEST_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), TYPE_TEST)) +#define TEST_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), TYPE_TEST, TestClass)) + +typedef struct _Test Test; +typedef struct _TestClass TestClass; +typedef struct _TestPrivate TestPrivate; +enum { + TEST_0_PROPERTY, + TEST_NUM_PROPERTIES +}; +static GParamSpec* test_properties[TEST_NUM_PROPERTIES]; +#define _g_free0(var) (var = (g_free (var), NULL)) +#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL))) +#define _g_variant_unref0(var) ((var == NULL) ? NULL : (var = (g_variant_unref (var), NULL))) +#define _g_main_loop_unref0(var) ((var == NULL) ? NULL : (var = (g_main_loop_unref (var), NULL))) +#define _vala_assert(expr, msg) if G_LIKELY (expr) ; else g_assertion_message_expr (G_LOG_DOMAIN, __FILE__, __LINE__, G_STRFUNC, msg); +#define _vala_return_if_fail(expr, msg) if G_LIKELY (expr) ; else { g_return_if_fail_warning (G_LOG_DOMAIN, G_STRFUNC, msg); return; } +#define _vala_return_val_if_fail(expr, msg, val) if G_LIKELY (expr) ; else { g_return_if_fail_warning (G_LOG_DOMAIN, G_STRFUNC, msg); return val; } +#define _vala_warn_if_fail(expr, msg) if G_LIKELY (expr) ; else g_warn_message (G_LOG_DOMAIN, __FILE__, __LINE__, G_STRFUNC, msg); + +typedef enum { + TEST_ERROR_NOT_SO_GOOD, + TEST_ERROR_BAD, + TEST_ERROR_WORSE +} TestError; +#define TEST_ERROR test_error_quark () +struct _Test { + GObject parent_instance; + TestPrivate * priv; +}; + +struct _TestClass { + GObjectClass parent_class; +}; + +static gpointer test_parent_class = NULL; +VALA_EXTERN GMainLoop* main_loop; +GMainLoop* main_loop = NULL; + +VALA_EXTERN GQuark test_error_quark (void); +VALA_EXTERN GType test_get_type (void) G_GNUC_CONST ; +G_DEFINE_AUTOPTR_CLEANUP_FUNC (Test, g_object_unref) +VALA_EXTERN guint test_register_object (void* object, + GDBusConnection* connection, + const gchar* path, + GError** error); +VALA_EXTERN void test_test_void (Test* self, + GError** error); +VALA_EXTERN gint test_test_int (Test* self, + gint i, + gint* j, + GError** error); +VALA_EXTERN gchar* test_test_string (Test* self, + const gchar* s, + gchar* * t, + GError** error); +VALA_EXTERN void test_test_cancellable (Test* self, + GCancellable* cancellable, + GError** error); +VALA_EXTERN void test_test_custom_error (Test* self, + GError** error); +VALA_EXTERN Test* test_new (void); +VALA_EXTERN Test* test_construct (GType object_type); +static GType test_get_type_once (void); +static void _dbus_test_test_void (Test* self, + GVariant* _parameters_, + GDBusMethodInvocation* invocation); +static void _dbus_test_test_int (Test* self, + GVariant* _parameters_, + GDBusMethodInvocation* invocation); +static void _dbus_test_test_string (Test* self, + GVariant* _parameters_, + GDBusMethodInvocation* invocation); +static void _dbus_test_test_cancellable (Test* self, + GVariant* _parameters_, + GDBusMethodInvocation* invocation); +static void _dbus_test_test_custom_error (Test* self, + GVariant* _parameters_, + GDBusMethodInvocation* invocation); +static void test_dbus_interface_method_call (GDBusConnection* connection, + const gchar* sender, + const gchar* object_path, + const gchar* interface_name, + const gchar* method_name, + GVariant* parameters, + GDBusMethodInvocation* invocation, + gpointer user_data); +static GVariant* test_dbus_interface_get_property (GDBusConnection* connection, + const gchar* sender, + const gchar* object_path, + const gchar* interface_name, + const gchar* property_name, + GError** error, + gpointer user_data); +static gboolean test_dbus_interface_set_property (GDBusConnection* connection, + const gchar* sender, + const gchar* object_path, + const gchar* interface_name, + const gchar* property_name, + GVariant* value, + GError** error, + gpointer user_data); +static void _test_unregister_object (gpointer user_data); +VALA_EXTERN void client_exit (GPid pid, + gint status); +static void _vala_main (void); +static guint _variant_get1 (GVariant* value); +static void _client_exit_gchild_watch_func (GPid pid, + gint wait_status, + gpointer self); +static void _vala_array_destroy (gpointer array, + gssize array_length, + GDestroyNotify destroy_func); +static void _vala_array_free (gpointer array, + gssize array_length, + GDestroyNotify destroy_func); + +static const GDBusErrorEntry test_error_entries[] = {{TEST_ERROR_NOT_SO_GOOD, "org.example.TestError.NotSoGood"}, {TEST_ERROR_BAD, "org.example.TestError.Bad"}, {TEST_ERROR_WORSE, "org.example.TestError.Worse"}}; +static const GDBusArgInfo * const _test_dbus_arg_info_test_void_in[] = {NULL}; +static const GDBusArgInfo * const _test_dbus_arg_info_test_void_out[] = {NULL}; +static const GDBusMethodInfo _test_dbus_method_info_test_void = {-1, "TestVoid", (GDBusArgInfo **) (&_test_dbus_arg_info_test_void_in), (GDBusArgInfo **) (&_test_dbus_arg_info_test_void_out), NULL}; +static const GDBusArgInfo _test_dbus_arg_info_test_int_i = {-1, "i", "i", NULL}; +static const GDBusArgInfo _test_dbus_arg_info_test_int_j = {-1, "j", "i", NULL}; +static const GDBusArgInfo _test_dbus_arg_info_test_int_result = {-1, "result", "i", NULL}; +static const GDBusArgInfo * const _test_dbus_arg_info_test_int_in[] = {&_test_dbus_arg_info_test_int_i, NULL}; +static const GDBusArgInfo * const _test_dbus_arg_info_test_int_out[] = {&_test_dbus_arg_info_test_int_j, &_test_dbus_arg_info_test_int_result, NULL}; +static const GDBusMethodInfo _test_dbus_method_info_test_int = {-1, "TestInt", (GDBusArgInfo **) (&_test_dbus_arg_info_test_int_in), (GDBusArgInfo **) (&_test_dbus_arg_info_test_int_out), NULL}; +static const GDBusArgInfo _test_dbus_arg_info_test_string_s = {-1, "s", "s", NULL}; +static const GDBusArgInfo _test_dbus_arg_info_test_string_t = {-1, "t", "s", NULL}; +static const GDBusArgInfo _test_dbus_arg_info_test_string_result = {-1, "result", "s", NULL}; +static const GDBusArgInfo * const _test_dbus_arg_info_test_string_in[] = {&_test_dbus_arg_info_test_string_s, NULL}; +static const GDBusArgInfo * const _test_dbus_arg_info_test_string_out[] = {&_test_dbus_arg_info_test_string_t, &_test_dbus_arg_info_test_string_result, NULL}; +static const GDBusMethodInfo _test_dbus_method_info_test_string = {-1, "TestString", (GDBusArgInfo **) (&_test_dbus_arg_info_test_string_in), (GDBusArgInfo **) (&_test_dbus_arg_info_test_string_out), NULL}; +static const GDBusArgInfo * const _test_dbus_arg_info_test_cancellable_in[] = {NULL}; +static const GDBusArgInfo * const _test_dbus_arg_info_test_cancellable_out[] = {NULL}; +static const GDBusMethodInfo _test_dbus_method_info_test_cancellable = {-1, "TestCancellable", (GDBusArgInfo **) (&_test_dbus_arg_info_test_cancellable_in), (GDBusArgInfo **) (&_test_dbus_arg_info_test_cancellable_out), NULL}; +static const GDBusArgInfo * const _test_dbus_arg_info_test_custom_error_in[] = {NULL}; +static const GDBusArgInfo * const _test_dbus_arg_info_test_custom_error_out[] = {NULL}; +static const GDBusMethodInfo _test_dbus_method_info_test_custom_error = {-1, "TestCustomError", (GDBusArgInfo **) (&_test_dbus_arg_info_test_custom_error_in), (GDBusArgInfo **) (&_test_dbus_arg_info_test_custom_error_out), NULL}; +static const GDBusMethodInfo * const _test_dbus_method_info[] = {&_test_dbus_method_info_test_void, &_test_dbus_method_info_test_int, &_test_dbus_method_info_test_string, &_test_dbus_method_info_test_cancellable, &_test_dbus_method_info_test_custom_error, NULL}; +static const GDBusSignalInfo * const _test_dbus_signal_info[] = {NULL}; +static const GDBusPropertyInfo * const _test_dbus_property_info[] = {NULL}; +static const GDBusInterfaceInfo _test_dbus_interface_info = {-1, "org.example.Test", (GDBusMethodInfo **) (&_test_dbus_method_info), (GDBusSignalInfo **) (&_test_dbus_signal_info), (GDBusPropertyInfo **) (&_test_dbus_property_info), NULL}; +static const GDBusInterfaceVTable _test_dbus_interface_vtable = {test_dbus_interface_method_call, test_dbus_interface_get_property, test_dbus_interface_set_property}; + +GQuark +test_error_quark (void) +{ + static volatile gsize test_error_quark_volatile = 0; + g_dbus_error_register_error_domain ("test-error-quark", &test_error_quark_volatile, test_error_entries, G_N_ELEMENTS (test_error_entries)); + return (GQuark) test_error_quark_volatile; +} + +void +test_test_void (Test* self, + GError** error) +{ + GError* _tmp0_; + GError* _inner_error0_ = NULL; + g_return_if_fail (IS_TEST (self)); + _tmp0_ = g_error_new_literal (G_IO_ERROR, G_IO_ERROR_FAILED, "Operation failed"); + _inner_error0_ = _tmp0_; + g_propagate_error (error, _inner_error0_); + return; +} + +gint +test_test_int (Test* self, + gint i, + gint* j, + GError** error) +{ + gint _vala_j = 0; + GError* _tmp0_; + gint _tmp1_ = -1; + GError* _inner_error0_ = NULL; + g_return_val_if_fail (IS_TEST (self), 0); + _tmp0_ = g_error_new_literal (G_IO_ERROR, G_IO_ERROR_FAILED, "Operation failed"); + _inner_error0_ = _tmp0_; + g_propagate_error (error, _inner_error0_); + return _tmp1_; +} + +gchar* +test_test_string (Test* self, + const gchar* s, + gchar* * t, + GError** error) +{ + gchar* _vala_t = NULL; + GError* _tmp0_; + GError* _inner_error0_ = NULL; + g_return_val_if_fail (IS_TEST (self), NULL); + g_return_val_if_fail (s != NULL, NULL); + _tmp0_ = g_error_new_literal (G_IO_ERROR, G_IO_ERROR_FAILED, "Operation failed"); + _inner_error0_ = _tmp0_; + g_propagate_error (error, _inner_error0_); + _g_free0 (_vala_t); + return NULL; +} + +void +test_test_cancellable (Test* self, + GCancellable* cancellable, + GError** error) +{ + g_return_if_fail (IS_TEST (self)); + g_return_if_fail ((cancellable == NULL) || G_TYPE_CHECK_INSTANCE_TYPE (cancellable, g_cancellable_get_type ())); +} + +void +test_test_custom_error (Test* self, + GError** error) +{ + GError* _tmp0_; + GError* _inner_error0_ = NULL; + g_return_if_fail (IS_TEST (self)); + _tmp0_ = g_error_new_literal (TEST_ERROR, TEST_ERROR_BAD, "Something failed badly"); + _inner_error0_ = _tmp0_; + if (_inner_error0_->domain == TEST_ERROR) { + g_propagate_error (error, _inner_error0_); + return; + } else { + g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error0_->message, g_quark_to_string (_inner_error0_->domain), _inner_error0_->code); + g_clear_error (&_inner_error0_); + return; + } +} + +Test* +test_construct (GType object_type) +{ + Test * self = NULL; + self = (Test*) g_object_new (object_type, NULL); + return self; +} + +Test* +test_new (void) +{ + return test_construct (TYPE_TEST); +} + +static void +test_class_init (TestClass * klass, + gpointer klass_data) +{ + test_parent_class = g_type_class_peek_parent (klass); +} + +static void +test_instance_init (Test * self, + gpointer klass) +{ +} + +static GType +test_get_type_once (void) +{ + static const GTypeInfo g_define_type_info = { sizeof (TestClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) test_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (Test), 0, (GInstanceInitFunc) test_instance_init, NULL }; + GType test_type_id; + test_type_id = g_type_register_static (G_TYPE_OBJECT, "Test", &g_define_type_info, 0); + g_type_set_qdata (test_type_id, g_quark_from_static_string ("vala-dbus-register-object"), (void*) test_register_object); + return test_type_id; +} + +GType +test_get_type (void) +{ + static volatile gsize test_type_id__volatile = 0; + if (g_once_init_enter (&test_type_id__volatile)) { + GType test_type_id; + test_type_id = test_get_type_once (); + g_once_init_leave (&test_type_id__volatile, test_type_id); + } + return test_type_id__volatile; +} + +static void +_dbus_test_test_void (Test* self, + GVariant* _parameters_, + GDBusMethodInvocation* invocation) +{ + GError* error = NULL; + GVariantIter _arguments_iter; + GDBusMessage* _reply_message = NULL; + GVariant* _reply; + GVariantBuilder _reply_builder; + g_variant_iter_init (&_arguments_iter, _parameters_); + test_test_void (self, &error); + if (error) { + g_dbus_method_invocation_return_gerror (invocation, error); + g_error_free (error); + return; + } + _reply_message = g_dbus_message_new_method_reply (g_dbus_method_invocation_get_message (invocation)); + g_variant_builder_init (&_reply_builder, G_VARIANT_TYPE_TUPLE); + _reply = g_variant_builder_end (&_reply_builder); + g_dbus_message_set_body (_reply_message, _reply); + g_dbus_connection_send_message (g_dbus_method_invocation_get_connection (invocation), _reply_message, G_DBUS_SEND_MESSAGE_FLAGS_NONE, NULL, NULL); + g_object_unref (invocation); + g_object_unref (_reply_message); +} + +static void +_dbus_test_test_int (Test* self, + GVariant* _parameters_, + GDBusMethodInvocation* invocation) +{ + GError* error = NULL; + GVariantIter _arguments_iter; + gint i = 0; + GVariant* _tmp0_; + GDBusMessage* _reply_message = NULL; + GVariant* _reply; + GVariantBuilder _reply_builder; + gint j = 0; + gint result; + g_variant_iter_init (&_arguments_iter, _parameters_); + _tmp0_ = g_variant_iter_next_value (&_arguments_iter); + i = g_variant_get_int32 (_tmp0_); + g_variant_unref (_tmp0_); + result = test_test_int (self, i, &j, &error); + if (error) { + g_dbus_method_invocation_return_gerror (invocation, error); + g_error_free (error); + return; + } + _reply_message = g_dbus_message_new_method_reply (g_dbus_method_invocation_get_message (invocation)); + g_variant_builder_init (&_reply_builder, G_VARIANT_TYPE_TUPLE); + g_variant_builder_add_value (&_reply_builder, g_variant_new_int32 (j)); + g_variant_builder_add_value (&_reply_builder, g_variant_new_int32 (result)); + _reply = g_variant_builder_end (&_reply_builder); + g_dbus_message_set_body (_reply_message, _reply); + g_dbus_connection_send_message (g_dbus_method_invocation_get_connection (invocation), _reply_message, G_DBUS_SEND_MESSAGE_FLAGS_NONE, NULL, NULL); + g_object_unref (invocation); + g_object_unref (_reply_message); +} + +static void +_dbus_test_test_string (Test* self, + GVariant* _parameters_, + GDBusMethodInvocation* invocation) +{ + GError* error = NULL; + GVariantIter _arguments_iter; + gchar* s = NULL; + GVariant* _tmp1_; + GDBusMessage* _reply_message = NULL; + GVariant* _reply; + GVariantBuilder _reply_builder; + gchar* t = NULL; + gchar* result; + g_variant_iter_init (&_arguments_iter, _parameters_); + _tmp1_ = g_variant_iter_next_value (&_arguments_iter); + s = g_variant_dup_string (_tmp1_, NULL); + g_variant_unref (_tmp1_); + result = test_test_string (self, s, &t, &error); + if (error) { + g_dbus_method_invocation_return_gerror (invocation, error); + g_error_free (error); + goto _error; + } + _reply_message = g_dbus_message_new_method_reply (g_dbus_method_invocation_get_message (invocation)); + g_variant_builder_init (&_reply_builder, G_VARIANT_TYPE_TUPLE); + g_variant_builder_add_value (&_reply_builder, g_variant_new_string (t)); + g_variant_builder_add_value (&_reply_builder, g_variant_new_string (result)); + _g_free0 (result); + _reply = g_variant_builder_end (&_reply_builder); + g_dbus_message_set_body (_reply_message, _reply); + g_dbus_connection_send_message (g_dbus_method_invocation_get_connection (invocation), _reply_message, G_DBUS_SEND_MESSAGE_FLAGS_NONE, NULL, NULL); + g_object_unref (invocation); + g_object_unref (_reply_message); + _error: + _g_free0 (s); + _g_free0 (t); + ; +} + +static void +_dbus_test_test_cancellable (Test* self, + GVariant* _parameters_, + GDBusMethodInvocation* invocation) +{ + GError* error = NULL; + GVariantIter _arguments_iter; + GDBusMessage* _reply_message = NULL; + GVariant* _reply; + GVariantBuilder _reply_builder; + g_variant_iter_init (&_arguments_iter, _parameters_); + test_test_cancellable (self, NULL, &error); + if (error) { + g_dbus_method_invocation_return_gerror (invocation, error); + g_error_free (error); + return; + } + _reply_message = g_dbus_message_new_method_reply (g_dbus_method_invocation_get_message (invocation)); + g_variant_builder_init (&_reply_builder, G_VARIANT_TYPE_TUPLE); + _reply = g_variant_builder_end (&_reply_builder); + g_dbus_message_set_body (_reply_message, _reply); + g_dbus_connection_send_message (g_dbus_method_invocation_get_connection (invocation), _reply_message, G_DBUS_SEND_MESSAGE_FLAGS_NONE, NULL, NULL); + g_object_unref (invocation); + g_object_unref (_reply_message); +} + +static void +_dbus_test_test_custom_error (Test* self, + GVariant* _parameters_, + GDBusMethodInvocation* invocation) +{ + GError* error = NULL; + GVariantIter _arguments_iter; + GDBusMessage* _reply_message = NULL; + GVariant* _reply; + GVariantBuilder _reply_builder; + g_variant_iter_init (&_arguments_iter, _parameters_); + test_test_custom_error (self, &error); + if (error) { + g_dbus_method_invocation_return_gerror (invocation, error); + g_error_free (error); + return; + } + _reply_message = g_dbus_message_new_method_reply (g_dbus_method_invocation_get_message (invocation)); + g_variant_builder_init (&_reply_builder, G_VARIANT_TYPE_TUPLE); + _reply = g_variant_builder_end (&_reply_builder); + g_dbus_message_set_body (_reply_message, _reply); + g_dbus_connection_send_message (g_dbus_method_invocation_get_connection (invocation), _reply_message, G_DBUS_SEND_MESSAGE_FLAGS_NONE, NULL, NULL); + g_object_unref (invocation); + g_object_unref (_reply_message); +} + +static void +test_dbus_interface_method_call (GDBusConnection* connection, + const gchar* sender, + const gchar* object_path, + const gchar* interface_name, + const gchar* method_name, + GVariant* parameters, + GDBusMethodInvocation* invocation, + gpointer user_data) +{ + gpointer* data; + gpointer object; + data = user_data; + object = data[0]; + if (strcmp (method_name, "TestVoid") == 0) { + _dbus_test_test_void (object, parameters, invocation); + } else if (strcmp (method_name, "TestInt") == 0) { + _dbus_test_test_int (object, parameters, invocation); + } else if (strcmp (method_name, "TestString") == 0) { + _dbus_test_test_string (object, parameters, invocation); + } else if (strcmp (method_name, "TestCancellable") == 0) { + _dbus_test_test_cancellable (object, parameters, invocation); + } else if (strcmp (method_name, "TestCustomError") == 0) { + _dbus_test_test_custom_error (object, parameters, invocation); + } else { + g_object_unref (invocation); + } +} + +static GVariant* +test_dbus_interface_get_property (GDBusConnection* connection, + const gchar* sender, + const gchar* object_path, + const gchar* interface_name, + const gchar* property_name, + GError** error, + gpointer user_data) +{ + gpointer* data; + gpointer object; + data = user_data; + object = data[0]; + return NULL; +} + +static gboolean +test_dbus_interface_set_property (GDBusConnection* connection, + const gchar* sender, + const gchar* object_path, + const gchar* interface_name, + const gchar* property_name, + GVariant* value, + GError** error, + gpointer user_data) +{ + gpointer* data; + gpointer object; + data = user_data; + object = data[0]; + return FALSE; +} + +guint +test_register_object (gpointer object, + GDBusConnection* connection, + const gchar* path, + GError** error) +{ + guint result; + gpointer *data; + data = g_new (gpointer, 3); + data[0] = g_object_ref (object); + data[1] = g_object_ref (connection); + data[2] = g_strdup (path); + result = g_dbus_connection_register_object (connection, path, (GDBusInterfaceInfo *) (&_test_dbus_interface_info), &_test_dbus_interface_vtable, data, _test_unregister_object, error); + if (!result) { + return 0; + } + return result; +} + +static void +_test_unregister_object (gpointer user_data) +{ + gpointer* data; + data = user_data; + g_object_unref (data[0]); + g_object_unref (data[1]); + g_free (data[2]); + g_free (data); +} + +void +client_exit (GPid pid, + gint status) +{ + GMainLoop* _tmp0_; + _vala_assert (status == 0, "status == 0"); + _tmp0_ = main_loop; + g_main_loop_quit (_tmp0_); +} + +static guint +_variant_get1 (GVariant* value) +{ + return g_variant_get_uint32 (value); +} + +static void +_client_exit_gchild_watch_func (GPid pid, + gint wait_status, + gpointer self) +{ + client_exit (pid, wait_status); +} + +static void +_vala_main (void) +{ + GDBusConnection* conn = NULL; + GDBusConnection* _tmp0_; + GDBusConnection* _tmp1_; + Test* _tmp2_; + Test* _tmp3_; + GVariant* request_result = NULL; + GDBusConnection* _tmp4_; + GVariant* _tmp5_; + GVariant* _tmp6_; + GVariant* _tmp7_; + GVariant* _tmp8_; + GVariant* _tmp9_; + GVariant* _tmp10_; + GVariant* _tmp11_; + guint _tmp12_; + GPid client_pid = 0; + gchar* _tmp13_; + gchar** _tmp14_; + gchar** _tmp15_; + gint _tmp15__length1; + GPid _tmp16_ = 0; + GMainLoop* _tmp17_; + GMainLoop* _tmp18_; + GError* _inner_error0_ = NULL; + _tmp0_ = g_bus_get_sync (G_BUS_TYPE_SESSION, NULL, &_inner_error0_); + conn = _tmp0_; + if (G_UNLIKELY (_inner_error0_ != NULL)) { + g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error0_->message, g_quark_to_string (_inner_error0_->domain), _inner_error0_->code); + g_clear_error (&_inner_error0_); + return; + } + _tmp1_ = conn; + _tmp2_ = test_new (); + _tmp3_ = _tmp2_; + test_register_object (_tmp3_, _tmp1_, "/org/example/test", &_inner_error0_); + _g_object_unref0 (_tmp3_); + if (G_UNLIKELY (_inner_error0_ != NULL)) { + _g_object_unref0 (conn); + g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error0_->message, g_quark_to_string (_inner_error0_->domain), _inner_error0_->code); + g_clear_error (&_inner_error0_); + return; + } + _tmp4_ = conn; + _tmp5_ = g_variant_new ("(su)", "org.example.Test", 0x4, NULL); + g_variant_ref_sink (_tmp5_); + _tmp6_ = _tmp5_; + _tmp7_ = g_dbus_connection_call_sync (_tmp4_, "org.freedesktop.DBus", "/org/freedesktop/DBus", "org.freedesktop.DBus", "RequestName", _tmp6_, NULL, 0, -1, NULL, &_inner_error0_); + _tmp8_ = _tmp7_; + _g_variant_unref0 (_tmp6_); + request_result = _tmp8_; + if (G_UNLIKELY (_inner_error0_ != NULL)) { + _g_object_unref0 (conn); + g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error0_->message, g_quark_to_string (_inner_error0_->domain), _inner_error0_->code); + g_clear_error (&_inner_error0_); + return; + } + _tmp9_ = request_result; + _tmp10_ = g_variant_get_child_value (_tmp9_, (gsize) 0); + _tmp11_ = _tmp10_; + _tmp12_ = _variant_get1 (_tmp11_); + _vala_assert (_tmp12_ == ((guint) 1), "(uint) request_result.get_child_value (0) == 1"); + _g_variant_unref0 (_tmp11_); + _tmp13_ = g_strdup ("dbus_errors_client"); + _tmp14_ = g_new0 (gchar*, 1 + 1); + _tmp14_[0] = _tmp13_; + _tmp15_ = _tmp14_; + _tmp15__length1 = 1; + g_spawn_async (NULL, _tmp15_, NULL, G_SPAWN_DO_NOT_REAP_CHILD, NULL, NULL, &_tmp16_, &_inner_error0_); + client_pid = _tmp16_; + _tmp15_ = (_vala_array_free (_tmp15_, _tmp15__length1, (GDestroyNotify) g_free), NULL); + if (G_UNLIKELY (_inner_error0_ != NULL)) { + _g_variant_unref0 (request_result); + _g_object_unref0 (conn); + g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error0_->message, g_quark_to_string (_inner_error0_->domain), _inner_error0_->code); + g_clear_error (&_inner_error0_); + return; + } + g_child_watch_add_full (G_PRIORITY_DEFAULT_IDLE, client_pid, _client_exit_gchild_watch_func, NULL, NULL); + _tmp17_ = g_main_loop_new (NULL, FALSE); + _g_main_loop_unref0 (main_loop); + main_loop = _tmp17_; + _tmp18_ = main_loop; + g_main_loop_run (_tmp18_); + _g_variant_unref0 (request_result); + _g_object_unref0 (conn); +} + +int +main (int argc, + char ** argv) +{ + _vala_main (); + return 0; +} + +static void +_vala_array_destroy (gpointer array, + gssize array_length, + GDestroyNotify destroy_func) +{ + if ((array != NULL) && (destroy_func != NULL)) { + gssize i; + for (i = 0; i < array_length; i = i + 1) { + if (((gpointer*) array)[i] != NULL) { + destroy_func (((gpointer*) array)[i]); + } + } + } +} + +static void +_vala_array_free (gpointer array, + gssize array_length, + GDestroyNotify destroy_func) +{ + _vala_array_destroy (array, array_length, destroy_func); + g_free (array); +} + diff --git a/tests/dbus/filedescriptor-async_client.c-expected b/tests/dbus/filedescriptor-async_client.c-expected new file mode 100644 index 000000000..0c6bcb8d0 --- /dev/null +++ b/tests/dbus/filedescriptor-async_client.c-expected @@ -0,0 +1,740 @@ +/* dbus_filedescriptor_async_client.c generated by valac, the Vala compiler + * generated from dbus_filedescriptor_async_client.vala, do not modify */ + +#include <glib-object.h> +#include <gio/gio.h> +#include <gio/gunixinputstream.h> +#include <gio/gunixfdlist.h> +#include <string.h> +#include <glib.h> +#include <unistd.h> + +#if !defined(VALA_EXTERN) +#if defined(_MSC_VER) +#define VALA_EXTERN __declspec(dllexport) extern +#elif __GNUC__ >= 4 +#define VALA_EXTERN __attribute__((visibility("default"))) extern +#else +#define VALA_EXTERN extern +#endif +#endif + +#define TYPE_TEST (test_get_type ()) +#define TEST(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TYPE_TEST, Test)) +#define IS_TEST(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TYPE_TEST)) +#define TEST_GET_INTERFACE(obj) (G_TYPE_INSTANCE_GET_INTERFACE ((obj), TYPE_TEST, TestIface)) + +typedef struct _Test Test; +typedef struct _TestIface TestIface; + +#define TYPE_TEST_PROXY (test_proxy_get_type ()) +typedef GDBusProxy TestProxy; +typedef GDBusProxyClass TestProxyClass; +typedef struct _TestTestInReadyData TestTestInReadyData; +#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL))) +typedef struct _RunData RunData; +#define _g_main_loop_unref0(var) ((var == NULL) ? NULL : (var = (g_main_loop_unref (var), NULL))) +#define _vala_assert(expr, msg) if G_LIKELY (expr) ; else g_assertion_message_expr (G_LOG_DOMAIN, __FILE__, __LINE__, G_STRFUNC, msg); +#define _vala_return_if_fail(expr, msg) if G_LIKELY (expr) ; else { g_return_if_fail_warning (G_LOG_DOMAIN, G_STRFUNC, msg); return; } +#define _vala_return_val_if_fail(expr, msg, val) if G_LIKELY (expr) ; else { g_return_if_fail_warning (G_LOG_DOMAIN, G_STRFUNC, msg); return val; } +#define _vala_warn_if_fail(expr, msg) if G_LIKELY (expr) ; else g_warn_message (G_LOG_DOMAIN, __FILE__, __LINE__, G_STRFUNC, msg); + +struct _TestIface { + GTypeInterface parent_iface; + void (*test_in) (Test* self, GUnixInputStream* i, GAsyncReadyCallback _callback_, gpointer _user_data_); + GUnixInputStream* (*test_in_finish) (Test* self, GAsyncResult* _res_, GUnixInputStream* * j, GError** error); +}; + +struct _TestTestInReadyData { + GDBusMethodInvocation* _invocation_; + GUnixInputStream* i; +}; + +struct _RunData { + int _state_; + GObject* _source_object_; + GAsyncResult* _res_; + GTask* _async_result; + Test* test; + Test* _tmp0_; + guint8* buffer; + guint8* _tmp1_; + gint buffer_length1; + gint _buffer_size_; + gint* pipe1; + gint* _tmp2_; + gint pipe1_length1; + gint _pipe1_size_; + gint* _tmp3_; + gint _tmp3__length1; + guint8* _tmp4_; + gint _tmp4__length1; + gint* _tmp5_; + gint _tmp5__length1; + gint _tmp6_; + guint8* _tmp7_; + gint _tmp7__length1; + gint* _tmp8_; + gint _tmp8__length1; + gint _tmp9_; + GUnixInputStream* j; + GUnixInputStream* k; + GUnixInputStream* _tmp10_; + Test* _tmp11_; + gint* _tmp12_; + gint _tmp12__length1; + gint _tmp13_; + GUnixInputStream* _tmp14_; + GUnixInputStream* _tmp15_; + GUnixInputStream* _tmp16_; + GUnixInputStream* _tmp17_; + GUnixInputStream* _tmp18_; + GUnixInputStream* _tmp19_; + gssize _tmp20_; + GUnixInputStream* _tmp21_; + guint8* _tmp22_; + gint _tmp22__length1; + guint8* _tmp23_; + gint _tmp23__length1; + guint8 _tmp24_; + gssize _tmp25_; + GUnixInputStream* _tmp26_; + guint8* _tmp27_; + gint _tmp27__length1; + guint8* _tmp28_; + gint _tmp28__length1; + guint8 _tmp29_; + GMainLoop* _tmp30_; + GError* _inner_error0_; +}; + +VALA_EXTERN GMainLoop* main_loop; +GMainLoop* main_loop = NULL; + +VALA_EXTERN GType test_proxy_get_type (void) G_GNUC_CONST ; +VALA_EXTERN guint test_register_object (void* object, + GDBusConnection* connection, + const gchar* path, + GError** error); +VALA_EXTERN GType test_get_type (void) G_GNUC_CONST ; +VALA_EXTERN void test_test_in (Test* self, + GUnixInputStream* i, + GAsyncReadyCallback _callback_, + gpointer _user_data_); +VALA_EXTERN GUnixInputStream* test_test_in_finish (Test* self, + GAsyncResult* _res_, + GUnixInputStream* * j, + GError** error); +static GType test_get_type_once (void); +static void test_proxy_g_signal (GDBusProxy* proxy, + const gchar* sender_name, + const gchar* signal_name, + GVariant* parameters); +static void _vala_g_async_ready_callback (GObject *source_object, + GAsyncResult *res, + void *user_data); +static void test_proxy_test_in_async (Test* self, + GUnixInputStream* i, + GAsyncReadyCallback _callback_, + gpointer _user_data_); +static GUnixInputStream* test_proxy_test_in_finish (Test* self, + GAsyncResult* _res_, + GUnixInputStream* * j, + GError** error); +static void test_proxy_test_interface_init (TestIface* iface); +static void _dbus_test_test_in (Test* self, + GVariant* _parameters_, + GDBusMethodInvocation* invocation); +static void _dbus_test_test_in_ready (GObject * source_object, + GAsyncResult * _res_, + gpointer _user_data_); +static void test_dbus_interface_method_call (GDBusConnection* connection, + const gchar* sender, + const gchar* object_path, + const gchar* interface_name, + const gchar* method_name, + GVariant* parameters, + GDBusMethodInvocation* invocation, + gpointer user_data); +static GVariant* test_dbus_interface_get_property (GDBusConnection* connection, + const gchar* sender, + const gchar* object_path, + const gchar* interface_name, + const gchar* property_name, + GError** error, + gpointer user_data); +static gboolean test_dbus_interface_set_property (GDBusConnection* connection, + const gchar* sender, + const gchar* object_path, + const gchar* interface_name, + const gchar* property_name, + GVariant* value, + GError** error, + gpointer user_data); +static void _test_unregister_object (gpointer user_data); +static void run_data_free (gpointer _data); +VALA_EXTERN void run (GAsyncReadyCallback _callback_, + gpointer _user_data_); +VALA_EXTERN void run_finish (GAsyncResult* _res_); +static gboolean run_co (RunData* _data_); +static void run_ready (GObject* source_object, + GAsyncResult* _res_, + gpointer _user_data_); +static void _vala_main (void); + +static const GDBusArgInfo _test_dbus_arg_info_test_in_i = {-1, "i", "h", NULL}; +static const GDBusArgInfo _test_dbus_arg_info_test_in_j = {-1, "j", "h", NULL}; +static const GDBusArgInfo _test_dbus_arg_info_test_in_result = {-1, "result", "h", NULL}; +static const GDBusArgInfo * const _test_dbus_arg_info_test_in_in[] = {&_test_dbus_arg_info_test_in_i, NULL}; +static const GDBusArgInfo * const _test_dbus_arg_info_test_in_out[] = {&_test_dbus_arg_info_test_in_j, &_test_dbus_arg_info_test_in_result, NULL}; +static const GDBusMethodInfo _test_dbus_method_info_test_in = {-1, "TestIn", (GDBusArgInfo **) (&_test_dbus_arg_info_test_in_in), (GDBusArgInfo **) (&_test_dbus_arg_info_test_in_out), NULL}; +static const GDBusMethodInfo * const _test_dbus_method_info[] = {&_test_dbus_method_info_test_in, NULL}; +static const GDBusSignalInfo * const _test_dbus_signal_info[] = {NULL}; +static const GDBusPropertyInfo * const _test_dbus_property_info[] = {NULL}; +static const GDBusInterfaceInfo _test_dbus_interface_info = {-1, "org.example.Test", (GDBusMethodInfo **) (&_test_dbus_method_info), (GDBusSignalInfo **) (&_test_dbus_signal_info), (GDBusPropertyInfo **) (&_test_dbus_property_info), NULL}; +static const GDBusInterfaceVTable _test_dbus_interface_vtable = {test_dbus_interface_method_call, test_dbus_interface_get_property, test_dbus_interface_set_property}; + +void +test_test_in (Test* self, + GUnixInputStream* i, + GAsyncReadyCallback _callback_, + gpointer _user_data_) +{ + TestIface* _iface_; + _iface_ = TEST_GET_INTERFACE (self); + if (_iface_->test_in) { + _iface_->test_in (self, i, _callback_, _user_data_); + } +} + +GUnixInputStream* +test_test_in_finish (Test* self, + GAsyncResult* _res_, + GUnixInputStream* * j, + GError** error) +{ + TestIface* _iface_; + _iface_ = TEST_GET_INTERFACE (self); + if (_iface_->test_in_finish) { + return _iface_->test_in_finish (self, _res_, j, error); + } + return NULL; +} + +static void +test_default_init (TestIface * iface, + gpointer iface_data) +{ +} + +static GType +test_get_type_once (void) +{ + static const GTypeInfo g_define_type_info = { sizeof (TestIface), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) test_default_init, (GClassFinalizeFunc) NULL, NULL, 0, 0, (GInstanceInitFunc) NULL, NULL }; + GType test_type_id; + test_type_id = g_type_register_static (G_TYPE_INTERFACE, "Test", &g_define_type_info, 0); + g_type_interface_add_prerequisite (test_type_id, G_TYPE_OBJECT); + g_type_set_qdata (test_type_id, g_quark_from_static_string ("vala-dbus-proxy-type"), (void*) test_proxy_get_type); + g_type_set_qdata (test_type_id, g_quark_from_static_string ("vala-dbus-interface-name"), "org.example.Test"); + g_type_set_qdata (test_type_id, g_quark_from_static_string ("vala-dbus-interface-info"), (void*) (&_test_dbus_interface_info)); + g_type_set_qdata (test_type_id, g_quark_from_static_string ("vala-dbus-register-object"), (void*) test_register_object); + return test_type_id; +} + +GType +test_get_type (void) +{ + static volatile gsize test_type_id__volatile = 0; + if (g_once_init_enter (&test_type_id__volatile)) { + GType test_type_id; + test_type_id = test_get_type_once (); + g_once_init_leave (&test_type_id__volatile, test_type_id); + } + return test_type_id__volatile; +} + +G_DEFINE_TYPE_EXTENDED (TestProxy, test_proxy, G_TYPE_DBUS_PROXY, 0, G_IMPLEMENT_INTERFACE (TYPE_TEST, test_proxy_test_interface_init) ) +static void +test_proxy_class_init (TestProxyClass* klass) +{ + G_DBUS_PROXY_CLASS (klass)->g_signal = test_proxy_g_signal; +} + +static void +test_proxy_g_signal (GDBusProxy* proxy, + const gchar* sender_name, + const gchar* signal_name, + GVariant* parameters) +{ +} + +static void +test_proxy_init (TestProxy* self) +{ + g_dbus_proxy_set_interface_info (G_DBUS_PROXY (self), (GDBusInterfaceInfo *) (&_test_dbus_interface_info)); +} + +static void +_vala_g_async_ready_callback (GObject *source_object, + GAsyncResult *res, + void *user_data) +{ + g_task_return_pointer (user_data, g_object_ref (res), g_object_unref); + g_object_unref (user_data); +} + +static void +test_proxy_test_in_async (Test* self, + GUnixInputStream* i, + GAsyncReadyCallback _callback_, + gpointer _user_data_) +{ + GUnixFDList* _fd_list; + GDBusMessage *_message; + GVariant *_arguments; + GVariantBuilder _arguments_builder; + G_IO_ERROR; + _message = g_dbus_message_new_method_call (g_dbus_proxy_get_name ((GDBusProxy *) self), g_dbus_proxy_get_object_path ((GDBusProxy *) self), "org.example.Test", "TestIn"); + g_variant_builder_init (&_arguments_builder, G_VARIANT_TYPE_TUPLE); + _fd_list = g_unix_fd_list_new (); + g_variant_builder_add (&_arguments_builder, "h", g_unix_fd_list_append (_fd_list, g_unix_input_stream_get_fd (i), NULL)); + _arguments = g_variant_builder_end (&_arguments_builder); + g_dbus_message_set_body (_message, _arguments); + g_dbus_message_set_unix_fd_list (_message, _fd_list); + g_object_unref (_fd_list); + if (_callback_ != NULL) { + g_dbus_connection_send_message_with_reply (g_dbus_proxy_get_connection ((GDBusProxy *) self), _message, G_DBUS_SEND_MESSAGE_FLAGS_NONE, g_dbus_proxy_get_default_timeout ((GDBusProxy *) self), NULL, NULL, _vala_g_async_ready_callback, g_task_new ((GObject *) self, NULL, _callback_, _user_data_)); + } else { + g_dbus_message_set_flags (_message, G_DBUS_MESSAGE_FLAGS_NO_REPLY_EXPECTED); + g_dbus_connection_send_message (g_dbus_proxy_get_connection ((GDBusProxy *) self), _message, G_DBUS_SEND_MESSAGE_FLAGS_NONE, NULL, NULL); + } + g_object_unref (_message); +} + +static GUnixInputStream* +test_proxy_test_in_finish (Test* self, + GAsyncResult* _res_, + GUnixInputStream* * j, + GError** error) +{ + GUnixFDList* _fd_list; + GAsyncResult *_inner_res; + GDBusMessage *_reply_message; + gint _fd_index = 0; + gint _fd; + GVariant *_reply; + GVariantIter _reply_iter; + GUnixInputStream* _vala_j = NULL; + GUnixInputStream* _result = NULL; + _inner_res = g_task_propagate_pointer ((GTask *) _res_, NULL); + _reply_message = g_dbus_connection_send_message_with_reply_finish (g_dbus_proxy_get_connection ((GDBusProxy *) self), _inner_res, error); + g_object_unref (_inner_res); + if (!_reply_message) { + return NULL; + } + if (g_dbus_message_to_gerror (_reply_message, error)) { + g_object_unref (_reply_message); + return NULL; + } + _reply = g_dbus_message_get_body (_reply_message); + g_variant_iter_init (&_reply_iter, _reply); + _fd_list = g_dbus_message_get_unix_fd_list (_reply_message); + if (_fd_list) { + g_variant_iter_next (&_reply_iter, "h", &_fd_index); + _fd = g_unix_fd_list_get (_fd_list, _fd_index, error); + if (_fd >= 0) { + _vala_j = (GUnixInputStream *) g_unix_input_stream_new (_fd, TRUE); + } + } else { + g_set_error_literal (error, G_IO_ERROR, G_IO_ERROR_FAILED, "FD List is NULL"); + } + *j = _vala_j; + if (error && (*error)) { + g_object_unref (_reply_message); + return NULL; + } + _fd_list = g_dbus_message_get_unix_fd_list (_reply_message); + if (_fd_list) { + g_variant_iter_next (&_reply_iter, "h", &_fd_index); + _fd = g_unix_fd_list_get (_fd_list, _fd_index, error); + if (_fd >= 0) { + _result = (GUnixInputStream *) g_unix_input_stream_new (_fd, TRUE); + } + } else { + g_set_error_literal (error, G_IO_ERROR, G_IO_ERROR_FAILED, "FD List is NULL"); + } + if (error && (*error)) { + g_object_unref (_reply_message); + return NULL; + } + g_object_unref (_reply_message); + return _result; +} + +static void +test_proxy_test_interface_init (TestIface* iface) +{ + iface->test_in = test_proxy_test_in_async; + iface->test_in_finish = test_proxy_test_in_finish; +} + +static void +_dbus_test_test_in (Test* self, + GVariant* _parameters_, + GDBusMethodInvocation* invocation) +{ + GUnixFDList* _fd_list; + GVariantIter _arguments_iter; + gint _fd_index = 0; + gint _fd; + TestTestInReadyData* _ready_data; + GError* error = NULL; + g_variant_iter_init (&_arguments_iter, _parameters_); + _ready_data = g_slice_new0 (TestTestInReadyData); + _ready_data->_invocation_ = invocation; + _fd_list = g_dbus_message_get_unix_fd_list (g_dbus_method_invocation_get_message (invocation)); + if (_fd_list) { + g_variant_iter_next (&_arguments_iter, "h", &_fd_index); + _fd = g_unix_fd_list_get (_fd_list, _fd_index, &error); + if (_fd >= 0) { + _ready_data->i = (GUnixInputStream *) g_unix_input_stream_new (_fd, TRUE); + } + } else { + g_set_error_literal (&error, G_IO_ERROR, G_IO_ERROR_FAILED, "FD List is NULL"); + } + if (error) { + g_dbus_method_invocation_return_gerror (invocation, error); + g_error_free (error); + goto _error; + } + test_test_in (self, _ready_data->i, (GAsyncReadyCallback) _dbus_test_test_in_ready, _ready_data); + _error: + ; +} + +static void +_dbus_test_test_in_ready (GObject * source_object, + GAsyncResult * _res_, + gpointer _user_data_) +{ + TestTestInReadyData* _ready_data; + GDBusMethodInvocation* invocation; + GUnixFDList* _fd_list; + GError* error = NULL; + GDBusMessage* _reply_message = NULL; + GVariant* _reply; + GVariantBuilder _reply_builder; + GUnixInputStream* j = NULL; + GUnixInputStream* result; + _ready_data = _user_data_; + invocation = _ready_data->_invocation_; + result = test_test_in_finish ((Test*) source_object, _res_, &j, &error); + if (error) { + g_dbus_method_invocation_return_gerror (invocation, error); + g_error_free (error); + goto _error; + } + _reply_message = g_dbus_message_new_method_reply (g_dbus_method_invocation_get_message (invocation)); + g_variant_builder_init (&_reply_builder, G_VARIANT_TYPE_TUPLE); + _fd_list = g_unix_fd_list_new (); + g_variant_builder_add (&_reply_builder, "h", g_unix_fd_list_append (_fd_list, g_unix_input_stream_get_fd (j), NULL)); + g_variant_builder_add (&_reply_builder, "h", g_unix_fd_list_append (_fd_list, g_unix_input_stream_get_fd (result), NULL)); + _g_object_unref0 (result); + _reply = g_variant_builder_end (&_reply_builder); + g_dbus_message_set_body (_reply_message, _reply); + g_dbus_message_set_unix_fd_list (_reply_message, _fd_list); + g_object_unref (_fd_list); + g_dbus_connection_send_message (g_dbus_method_invocation_get_connection (invocation), _reply_message, G_DBUS_SEND_MESSAGE_FLAGS_NONE, NULL, NULL); + g_object_unref (invocation); + g_object_unref (_reply_message); + _error: + _g_object_unref0 (_ready_data->i); + _g_object_unref0 (j); + g_slice_free (TestTestInReadyData, _ready_data); +} + +static void +test_dbus_interface_method_call (GDBusConnection* connection, + const gchar* sender, + const gchar* object_path, + const gchar* interface_name, + const gchar* method_name, + GVariant* parameters, + GDBusMethodInvocation* invocation, + gpointer user_data) +{ + gpointer* data; + gpointer object; + data = user_data; + object = data[0]; + if (strcmp (method_name, "TestIn") == 0) { + _dbus_test_test_in (object, parameters, invocation); + } else { + g_object_unref (invocation); + } +} + +static GVariant* +test_dbus_interface_get_property (GDBusConnection* connection, + const gchar* sender, + const gchar* object_path, + const gchar* interface_name, + const gchar* property_name, + GError** error, + gpointer user_data) +{ + gpointer* data; + gpointer object; + data = user_data; + object = data[0]; + return NULL; +} + +static gboolean +test_dbus_interface_set_property (GDBusConnection* connection, + const gchar* sender, + const gchar* object_path, + const gchar* interface_name, + const gchar* property_name, + GVariant* value, + GError** error, + gpointer user_data) +{ + gpointer* data; + gpointer object; + data = user_data; + object = data[0]; + return FALSE; +} + +guint +test_register_object (gpointer object, + GDBusConnection* connection, + const gchar* path, + GError** error) +{ + guint result; + gpointer *data; + data = g_new (gpointer, 3); + data[0] = g_object_ref (object); + data[1] = g_object_ref (connection); + data[2] = g_strdup (path); + result = g_dbus_connection_register_object (connection, path, (GDBusInterfaceInfo *) (&_test_dbus_interface_info), &_test_dbus_interface_vtable, data, _test_unregister_object, error); + if (!result) { + return 0; + } + return result; +} + +static void +_test_unregister_object (gpointer user_data) +{ + gpointer* data; + data = user_data; + g_object_unref (data[0]); + g_object_unref (data[1]); + g_free (data[2]); + g_free (data); +} + +static void +run_data_free (gpointer _data) +{ + RunData* _data_; + _data_ = _data; + g_slice_free (RunData, _data_); +} + +void +run (GAsyncReadyCallback _callback_, + gpointer _user_data_) +{ + RunData* _data_; + _data_ = g_slice_new0 (RunData); + _data_->_async_result = g_task_new (NULL, NULL, _callback_, _user_data_); + g_task_set_task_data (_data_->_async_result, _data_, run_data_free); + run_co (_data_); +} + +void +run_finish (GAsyncResult* _res_) +{ + RunData* _data_; + _data_ = g_task_propagate_pointer (G_TASK (_res_), NULL); +} + +static void +run_ready (GObject* source_object, + GAsyncResult* _res_, + gpointer _user_data_) +{ + RunData* _data_; + _data_ = _user_data_; + _data_->_source_object_ = source_object; + _data_->_res_ = _res_; + run_co (_data_); +} + +static gboolean +run_co (RunData* _data_) +{ + switch (_data_->_state_) { + case 0: + goto _state_0; + case 1: + goto _state_1; + case 2: + goto _state_2; + default: + g_assert_not_reached (); + } + _state_0: + _data_->_state_ = 1; + g_async_initable_new_async (TYPE_TEST_PROXY, 0, NULL, run_ready, _data_, "g-flags", 0, "g-name", "org.example.Test", "g-bus-type", G_BUS_TYPE_SESSION, "g-object-path", "/org/example/test", "g-interface-name", "org.example.Test", NULL); + return FALSE; + _state_1: + _data_->_tmp0_ = (Test*) g_async_initable_new_finish ((GAsyncInitable *) _data_->_source_object_, _data_->_res_, &_data_->_inner_error0_); + _data_->test = (Test*) _data_->_tmp0_; + if (G_UNLIKELY (_data_->_inner_error0_ != NULL)) { + g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _data_->_inner_error0_->message, g_quark_to_string (_data_->_inner_error0_->domain), _data_->_inner_error0_->code); + g_clear_error (&_data_->_inner_error0_); + g_object_unref (_data_->_async_result); + return FALSE; + } + _data_->_tmp1_ = g_new0 (guint8, 1); + _data_->buffer = _data_->_tmp1_; + _data_->buffer_length1 = 1; + _data_->_buffer_size_ = _data_->buffer_length1; + _data_->_tmp2_ = g_new0 (gint, 2); + _data_->pipe1 = _data_->_tmp2_; + _data_->pipe1_length1 = 2; + _data_->_pipe1_size_ = _data_->pipe1_length1; + _data_->_tmp3_ = _data_->pipe1; + _data_->_tmp3__length1 = _data_->pipe1_length1; + _vala_assert (pipe (_data_->_tmp3_) == 0, "Posix.pipe (pipe1) == 0"); + _data_->_tmp4_ = _data_->buffer; + _data_->_tmp4__length1 = _data_->buffer_length1; + _data_->_tmp4_[0] = (guint8) 42; + _data_->_tmp5_ = _data_->pipe1; + _data_->_tmp5__length1 = _data_->pipe1_length1; + _data_->_tmp6_ = _data_->_tmp5_[1]; + _data_->_tmp7_ = _data_->buffer; + _data_->_tmp7__length1 = _data_->buffer_length1; + _vala_assert (write (_data_->_tmp6_, _data_->_tmp7_, (gsize) 1) == ((gssize) 1), "Posix.write (pipe1[1], buffer, 1) == 1"); + _data_->_tmp8_ = _data_->pipe1; + _data_->_tmp8__length1 = _data_->pipe1_length1; + _data_->_tmp9_ = _data_->_tmp8_[1]; + close (_data_->_tmp9_); + _data_->_tmp11_ = _data_->test; + _data_->_tmp12_ = _data_->pipe1; + _data_->_tmp12__length1 = _data_->pipe1_length1; + _data_->_tmp13_ = _data_->_tmp12_[0]; + _data_->_tmp14_ = (GUnixInputStream*) g_unix_input_stream_new (_data_->_tmp13_, TRUE); + _data_->_tmp15_ = _data_->_tmp14_; + _data_->_tmp16_ = NULL; + _data_->_state_ = 2; + test_test_in (_data_->_tmp11_, _data_->_tmp15_, run_ready, _data_); + return FALSE; + _state_2: + _data_->_tmp17_ = test_test_in_finish (_data_->_tmp11_, _data_->_res_, &_data_->_tmp16_, &_data_->_inner_error0_); + _g_object_unref0 (_data_->j); + _data_->j = _data_->_tmp16_; + _data_->_tmp18_ = _data_->_tmp17_; + _g_object_unref0 (_data_->_tmp15_); + _data_->_tmp10_ = _data_->_tmp18_; + if (G_UNLIKELY (_data_->_inner_error0_ != NULL)) { + _g_object_unref0 (_data_->k); + _g_object_unref0 (_data_->j); + _data_->pipe1 = (g_free (_data_->pipe1), NULL); + _data_->buffer = (g_free (_data_->buffer), NULL); + _g_object_unref0 (_data_->test); + g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _data_->_inner_error0_->message, g_quark_to_string (_data_->_inner_error0_->domain), _data_->_inner_error0_->code); + g_clear_error (&_data_->_inner_error0_); + g_object_unref (_data_->_async_result); + return FALSE; + } + _data_->_tmp19_ = _data_->_tmp10_; + _data_->_tmp10_ = NULL; + _g_object_unref0 (_data_->k); + _data_->k = _data_->_tmp19_; + _data_->_tmp21_ = _data_->j; + _data_->_tmp22_ = _data_->buffer; + _data_->_tmp22__length1 = _data_->buffer_length1; + _data_->_tmp20_ = g_input_stream_read (G_TYPE_CHECK_INSTANCE_CAST (_data_->_tmp21_, g_input_stream_get_type (), GInputStream), _data_->_tmp22_, (gsize) _data_->_tmp22__length1, NULL, &_data_->_inner_error0_); + if (G_UNLIKELY (_data_->_inner_error0_ != NULL)) { + _g_object_unref0 (_data_->_tmp10_); + _g_object_unref0 (_data_->k); + _g_object_unref0 (_data_->j); + _data_->pipe1 = (g_free (_data_->pipe1), NULL); + _data_->buffer = (g_free (_data_->buffer), NULL); + _g_object_unref0 (_data_->test); + g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _data_->_inner_error0_->message, g_quark_to_string (_data_->_inner_error0_->domain), _data_->_inner_error0_->code); + g_clear_error (&_data_->_inner_error0_); + g_object_unref (_data_->_async_result); + return FALSE; + } + _vala_assert (_data_->_tmp20_ == ((gssize) 1), "j.read (buffer) == 1"); + _data_->_tmp23_ = _data_->buffer; + _data_->_tmp23__length1 = _data_->buffer_length1; + _data_->_tmp24_ = _data_->_tmp23_[0]; + _vala_assert (((gint) _data_->_tmp24_) == 23, "buffer[0] == 23"); + _data_->_tmp26_ = _data_->k; + _data_->_tmp27_ = _data_->buffer; + _data_->_tmp27__length1 = _data_->buffer_length1; + _data_->_tmp25_ = g_input_stream_read (G_TYPE_CHECK_INSTANCE_CAST (_data_->_tmp26_, g_input_stream_get_type (), GInputStream), _data_->_tmp27_, (gsize) _data_->_tmp27__length1, NULL, &_data_->_inner_error0_); + if (G_UNLIKELY (_data_->_inner_error0_ != NULL)) { + _g_object_unref0 (_data_->_tmp10_); + _g_object_unref0 (_data_->k); + _g_object_unref0 (_data_->j); + _data_->pipe1 = (g_free (_data_->pipe1), NULL); + _data_->buffer = (g_free (_data_->buffer), NULL); + _g_object_unref0 (_data_->test); + g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _data_->_inner_error0_->message, g_quark_to_string (_data_->_inner_error0_->domain), _data_->_inner_error0_->code); + g_clear_error (&_data_->_inner_error0_); + g_object_unref (_data_->_async_result); + return FALSE; + } + _vala_assert (_data_->_tmp25_ == ((gssize) 1), "k.read (buffer) == 1"); + _data_->_tmp28_ = _data_->buffer; + _data_->_tmp28__length1 = _data_->buffer_length1; + _data_->_tmp29_ = _data_->_tmp28_[0]; + _vala_assert (((gint) _data_->_tmp29_) == 11, "buffer[0] == 11"); + _data_->_tmp30_ = main_loop; + g_main_loop_quit (_data_->_tmp30_); + _g_object_unref0 (_data_->_tmp10_); + _g_object_unref0 (_data_->k); + _g_object_unref0 (_data_->j); + _data_->pipe1 = (g_free (_data_->pipe1), NULL); + _data_->buffer = (g_free (_data_->buffer), NULL); + _g_object_unref0 (_data_->test); + g_task_return_pointer (_data_->_async_result, _data_, NULL); + if (_data_->_state_ != 0) { + while (!g_task_get_completed (_data_->_async_result)) { + g_main_context_iteration (g_task_get_context (_data_->_async_result), TRUE); + } + } + g_object_unref (_data_->_async_result); + return FALSE; +} + +static void +_vala_main (void) +{ + GMainLoop* _tmp0_; + GMainLoop* _tmp1_; + run (NULL, NULL); + _tmp0_ = g_main_loop_new (NULL, FALSE); + _g_main_loop_unref0 (main_loop); + main_loop = _tmp0_; + _tmp1_ = main_loop; + g_main_loop_run (_tmp1_); +} + +int +main (int argc, + char ** argv) +{ + _vala_main (); + return 0; +} + diff --git a/tests/dbus/filedescriptor-async_server.c-expected b/tests/dbus/filedescriptor-async_server.c-expected new file mode 100644 index 000000000..33898dab0 --- /dev/null +++ b/tests/dbus/filedescriptor-async_server.c-expected @@ -0,0 +1,712 @@ +/* dbus_filedescriptor_async_server.c generated by valac, the Vala compiler + * generated from dbus_filedescriptor_async_server.vala, do not modify */ + +#include <glib-object.h> +#include <gio/gio.h> +#include <gio/gunixinputstream.h> +#include <glib.h> +#include <unistd.h> +#include <string.h> +#include <gio/gunixfdlist.h> +#include <stdlib.h> + +#if !defined(VALA_EXTERN) +#if defined(_MSC_VER) +#define VALA_EXTERN __declspec(dllexport) extern +#elif __GNUC__ >= 4 +#define VALA_EXTERN __attribute__((visibility("default"))) extern +#else +#define VALA_EXTERN extern +#endif +#endif + +#define TYPE_TEST (test_get_type ()) +#define TEST(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TYPE_TEST, Test)) +#define TEST_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), TYPE_TEST, TestClass)) +#define IS_TEST(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TYPE_TEST)) +#define IS_TEST_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), TYPE_TEST)) +#define TEST_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), TYPE_TEST, TestClass)) + +typedef struct _Test Test; +typedef struct _TestClass TestClass; +typedef struct _TestPrivate TestPrivate; +enum { + TEST_0_PROPERTY, + TEST_NUM_PROPERTIES +}; +static GParamSpec* test_properties[TEST_NUM_PROPERTIES]; +#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL))) +typedef struct _TestTestInData TestTestInData; +typedef struct _TestTestInReadyData TestTestInReadyData; +#define _g_variant_unref0(var) ((var == NULL) ? NULL : (var = (g_variant_unref (var), NULL))) +#define _g_main_loop_unref0(var) ((var == NULL) ? NULL : (var = (g_main_loop_unref (var), NULL))) +#define _vala_assert(expr, msg) if G_LIKELY (expr) ; else g_assertion_message_expr (G_LOG_DOMAIN, __FILE__, __LINE__, G_STRFUNC, msg); +#define _vala_return_if_fail(expr, msg) if G_LIKELY (expr) ; else { g_return_if_fail_warning (G_LOG_DOMAIN, G_STRFUNC, msg); return; } +#define _vala_return_val_if_fail(expr, msg, val) if G_LIKELY (expr) ; else { g_return_if_fail_warning (G_LOG_DOMAIN, G_STRFUNC, msg); return val; } +#define _vala_warn_if_fail(expr, msg) if G_LIKELY (expr) ; else g_warn_message (G_LOG_DOMAIN, __FILE__, __LINE__, G_STRFUNC, msg); + +struct _Test { + GObject parent_instance; + TestPrivate * priv; +}; + +struct _TestClass { + GObjectClass parent_class; +}; + +struct _TestTestInData { + int _state_; + GObject* _source_object_; + GAsyncResult* _res_; + GTask* _async_result; + Test* self; + GUnixInputStream* i; + GUnixInputStream* j; + GUnixInputStream* result; + guint8* buffer; + guint8* _tmp0_; + gint buffer_length1; + gint _buffer_size_; + gssize _tmp1_; + guint8 _tmp2_; + gint* pipe1; + gint* _tmp3_; + gint pipe1_length1; + gint _pipe1_size_; + gint* _tmp4_; + gint _tmp4__length1; + gint* _tmp5_; + gint _tmp5__length1; + gint _tmp6_; + gint* _tmp7_; + gint _tmp7__length1; + gint _tmp8_; + gint* pipe2; + gint* _tmp9_; + gint pipe2_length1; + gint _pipe2_size_; + gint* _tmp10_; + gint _tmp10__length1; + gint* _tmp11_; + gint _tmp11__length1; + gint _tmp12_; + gint* _tmp13_; + gint _tmp13__length1; + gint _tmp14_; + gint* _tmp15_; + gint _tmp15__length1; + gint _tmp16_; + GUnixInputStream* _tmp17_; + gint* _tmp18_; + gint _tmp18__length1; + gint _tmp19_; + GUnixInputStream* _tmp20_; + GError* _inner_error0_; +}; + +struct _TestTestInReadyData { + GDBusMethodInvocation* _invocation_; + GUnixInputStream* i; +}; + +static gpointer test_parent_class = NULL; +VALA_EXTERN GMainLoop* main_loop; +GMainLoop* main_loop = NULL; + +VALA_EXTERN GType test_get_type (void) G_GNUC_CONST ; +G_DEFINE_AUTOPTR_CLEANUP_FUNC (Test, g_object_unref) +VALA_EXTERN guint test_register_object (void* object, + GDBusConnection* connection, + const gchar* path, + GError** error); +static void test_test_in_data_free (gpointer _data); +VALA_EXTERN void test_test_in (Test* self, + GUnixInputStream* i, + GAsyncReadyCallback _callback_, + gpointer _user_data_); +VALA_EXTERN GUnixInputStream* test_test_in_finish (Test* self, + GAsyncResult* _res_, + GUnixInputStream* * j, + GError** error); +static gboolean test_test_in_co (TestTestInData* _data_); +static gboolean _test_test_in_co_gsource_func (gpointer self); +VALA_EXTERN Test* test_new (void); +VALA_EXTERN Test* test_construct (GType object_type); +static GType test_get_type_once (void); +static void _dbus_test_test_in (Test* self, + GVariant* _parameters_, + GDBusMethodInvocation* invocation); +static void _dbus_test_test_in_ready (GObject * source_object, + GAsyncResult * _res_, + gpointer _user_data_); +static void test_dbus_interface_method_call (GDBusConnection* connection, + const gchar* sender, + const gchar* object_path, + const gchar* interface_name, + const gchar* method_name, + GVariant* parameters, + GDBusMethodInvocation* invocation, + gpointer user_data); +static GVariant* test_dbus_interface_get_property (GDBusConnection* connection, + const gchar* sender, + const gchar* object_path, + const gchar* interface_name, + const gchar* property_name, + GError** error, + gpointer user_data); +static gboolean test_dbus_interface_set_property (GDBusConnection* connection, + const gchar* sender, + const gchar* object_path, + const gchar* interface_name, + const gchar* property_name, + GVariant* value, + GError** error, + gpointer user_data); +static void _test_unregister_object (gpointer user_data); +VALA_EXTERN void client_exit (GPid pid, + gint status); +static void _vala_main (void); +static guint _variant_get1 (GVariant* value); +static void _client_exit_gchild_watch_func (GPid pid, + gint wait_status, + gpointer self); +static void _vala_array_destroy (gpointer array, + gssize array_length, + GDestroyNotify destroy_func); +static void _vala_array_free (gpointer array, + gssize array_length, + GDestroyNotify destroy_func); + +static const GDBusArgInfo _test_dbus_arg_info_test_in_i = {-1, "i", "h", NULL}; +static const GDBusArgInfo _test_dbus_arg_info_test_in_j = {-1, "j", "h", NULL}; +static const GDBusArgInfo _test_dbus_arg_info_test_in_result = {-1, "result", "h", NULL}; +static const GDBusArgInfo * const _test_dbus_arg_info_test_in_in[] = {&_test_dbus_arg_info_test_in_i, NULL}; +static const GDBusArgInfo * const _test_dbus_arg_info_test_in_out[] = {&_test_dbus_arg_info_test_in_j, &_test_dbus_arg_info_test_in_result, NULL}; +static const GDBusMethodInfo _test_dbus_method_info_test_in = {-1, "TestIn", (GDBusArgInfo **) (&_test_dbus_arg_info_test_in_in), (GDBusArgInfo **) (&_test_dbus_arg_info_test_in_out), NULL}; +static const GDBusMethodInfo * const _test_dbus_method_info[] = {&_test_dbus_method_info_test_in, NULL}; +static const GDBusSignalInfo * const _test_dbus_signal_info[] = {NULL}; +static const GDBusPropertyInfo * const _test_dbus_property_info[] = {NULL}; +static const GDBusInterfaceInfo _test_dbus_interface_info = {-1, "org.example.Test", (GDBusMethodInfo **) (&_test_dbus_method_info), (GDBusSignalInfo **) (&_test_dbus_signal_info), (GDBusPropertyInfo **) (&_test_dbus_property_info), NULL}; +static const GDBusInterfaceVTable _test_dbus_interface_vtable = {test_dbus_interface_method_call, test_dbus_interface_get_property, test_dbus_interface_set_property}; + +static void +test_test_in_data_free (gpointer _data) +{ + TestTestInData* _data_; + _data_ = _data; + _g_object_unref0 (_data_->i); + _g_object_unref0 (_data_->result); + _g_object_unref0 (_data_->self); + g_slice_free (TestTestInData, _data_); +} + +static gpointer +_g_object_ref0 (gpointer self) +{ + return self ? g_object_ref (self) : NULL; +} + +void +test_test_in (Test* self, + GUnixInputStream* i, + GAsyncReadyCallback _callback_, + gpointer _user_data_) +{ + TestTestInData* _data_; + Test* _tmp0_; + GUnixInputStream* _tmp1_; + g_return_if_fail (IS_TEST (self)); + g_return_if_fail (G_TYPE_CHECK_INSTANCE_TYPE (i, G_TYPE_UNIX_INPUT_STREAM)); + _data_ = g_slice_new0 (TestTestInData); + _data_->_async_result = g_task_new (G_OBJECT (self), NULL, _callback_, _user_data_); + g_task_set_task_data (_data_->_async_result, _data_, test_test_in_data_free); + _tmp0_ = _g_object_ref0 (self); + _data_->self = _tmp0_; + _tmp1_ = _g_object_ref0 (i); + _g_object_unref0 (_data_->i); + _data_->i = _tmp1_; + test_test_in_co (_data_); +} + +GUnixInputStream* +test_test_in_finish (Test* self, + GAsyncResult* _res_, + GUnixInputStream* * j, + GError** error) +{ + GUnixInputStream* result; + TestTestInData* _data_; + _data_ = g_task_propagate_pointer (G_TASK (_res_), error); + if (NULL == _data_) { + return NULL; + } + if (j) { + *j = _data_->j; + } else { + _g_object_unref0 (_data_->j); + } + _data_->j = NULL; + result = _data_->result; + _data_->result = NULL; + return result; +} + +static gboolean +_test_test_in_co_gsource_func (gpointer self) +{ + gboolean result; + result = test_test_in_co (self); + return result; +} + +static gboolean +test_test_in_co (TestTestInData* _data_) +{ + switch (_data_->_state_) { + case 0: + goto _state_0; + case 1: + goto _state_1; + default: + g_assert_not_reached (); + } + _state_0: + _data_->_tmp0_ = g_new0 (guint8, 1); + _data_->buffer = _data_->_tmp0_; + _data_->buffer_length1 = 1; + _data_->_buffer_size_ = _data_->buffer_length1; + _data_->_tmp1_ = g_input_stream_read (G_TYPE_CHECK_INSTANCE_CAST (_data_->i, g_input_stream_get_type (), GInputStream), _data_->buffer, (gsize) _data_->buffer_length1, NULL, &_data_->_inner_error0_); + if (G_UNLIKELY (_data_->_inner_error0_ != NULL)) { + if (_data_->_inner_error0_->domain == G_IO_ERROR) { + g_task_return_error (_data_->_async_result, _data_->_inner_error0_); + _data_->buffer = (g_free (_data_->buffer), NULL); + _g_object_unref0 (_data_->j); + g_object_unref (_data_->_async_result); + return FALSE; + } else { + _data_->buffer = (g_free (_data_->buffer), NULL); + _g_object_unref0 (_data_->j); + g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _data_->_inner_error0_->message, g_quark_to_string (_data_->_inner_error0_->domain), _data_->_inner_error0_->code); + g_clear_error (&_data_->_inner_error0_); + g_object_unref (_data_->_async_result); + return FALSE; + } + } + _vala_assert (_data_->_tmp1_ == ((gssize) 1), "i.read (buffer) == 1"); + _data_->_tmp2_ = _data_->buffer[0]; + _vala_assert (((gint) _data_->_tmp2_) == 42, "buffer[0] == 42"); + _data_->_tmp3_ = g_new0 (gint, 2); + _data_->pipe1 = _data_->_tmp3_; + _data_->pipe1_length1 = 2; + _data_->_pipe1_size_ = _data_->pipe1_length1; + _data_->_tmp4_ = _data_->pipe1; + _data_->_tmp4__length1 = _data_->pipe1_length1; + _vala_assert (pipe (_data_->_tmp4_) == 0, "Posix.pipe (pipe1) == 0"); + _data_->buffer[0] = (guint8) 23; + _data_->_tmp5_ = _data_->pipe1; + _data_->_tmp5__length1 = _data_->pipe1_length1; + _data_->_tmp6_ = _data_->_tmp5_[1]; + _vala_assert (write (_data_->_tmp6_, _data_->buffer, (gsize) 1) == ((gssize) 1), "Posix.write (pipe1[1], buffer, 1) == 1"); + _data_->_tmp7_ = _data_->pipe1; + _data_->_tmp7__length1 = _data_->pipe1_length1; + _data_->_tmp8_ = _data_->_tmp7_[1]; + close (_data_->_tmp8_); + _data_->_tmp9_ = g_new0 (gint, 2); + _data_->pipe2 = _data_->_tmp9_; + _data_->pipe2_length1 = 2; + _data_->_pipe2_size_ = _data_->pipe2_length1; + _data_->_tmp10_ = _data_->pipe2; + _data_->_tmp10__length1 = _data_->pipe2_length1; + _vala_assert (pipe (_data_->_tmp10_) == 0, "Posix.pipe (pipe2) == 0"); + _data_->buffer[0] = (guint8) 11; + _data_->_tmp11_ = _data_->pipe2; + _data_->_tmp11__length1 = _data_->pipe2_length1; + _data_->_tmp12_ = _data_->_tmp11_[1]; + _vala_assert (write (_data_->_tmp12_, _data_->buffer, (gsize) 1) == ((gssize) 1), "Posix.write (pipe2[1], buffer, 1) == 1"); + _data_->_tmp13_ = _data_->pipe2; + _data_->_tmp13__length1 = _data_->pipe2_length1; + _data_->_tmp14_ = _data_->_tmp13_[1]; + close (_data_->_tmp14_); + g_idle_add_full (G_PRIORITY_DEFAULT_IDLE, _test_test_in_co_gsource_func, _data_, NULL); + _data_->_state_ = 1; + return FALSE; + _state_1: + ; + _data_->_tmp15_ = _data_->pipe1; + _data_->_tmp15__length1 = _data_->pipe1_length1; + _data_->_tmp16_ = _data_->_tmp15_[0]; + _data_->_tmp17_ = (GUnixInputStream*) g_unix_input_stream_new (_data_->_tmp16_, TRUE); + _g_object_unref0 (_data_->j); + _data_->j = _data_->_tmp17_; + _data_->_tmp18_ = _data_->pipe2; + _data_->_tmp18__length1 = _data_->pipe2_length1; + _data_->_tmp19_ = _data_->_tmp18_[0]; + _data_->_tmp20_ = (GUnixInputStream*) g_unix_input_stream_new (_data_->_tmp19_, TRUE); + _data_->result = _data_->_tmp20_; + _data_->pipe2 = (g_free (_data_->pipe2), NULL); + _data_->pipe1 = (g_free (_data_->pipe1), NULL); + _data_->buffer = (g_free (_data_->buffer), NULL); + g_task_return_pointer (_data_->_async_result, _data_, NULL); + if (_data_->_state_ != 0) { + while (!g_task_get_completed (_data_->_async_result)) { + g_main_context_iteration (g_task_get_context (_data_->_async_result), TRUE); + } + } + g_object_unref (_data_->_async_result); + return FALSE; +} + +Test* +test_construct (GType object_type) +{ + Test * self = NULL; + self = (Test*) g_object_new (object_type, NULL); + return self; +} + +Test* +test_new (void) +{ + return test_construct (TYPE_TEST); +} + +static void +test_class_init (TestClass * klass, + gpointer klass_data) +{ + test_parent_class = g_type_class_peek_parent (klass); +} + +static void +test_instance_init (Test * self, + gpointer klass) +{ +} + +static GType +test_get_type_once (void) +{ + static const GTypeInfo g_define_type_info = { sizeof (TestClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) test_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (Test), 0, (GInstanceInitFunc) test_instance_init, NULL }; + GType test_type_id; + test_type_id = g_type_register_static (G_TYPE_OBJECT, "Test", &g_define_type_info, 0); + g_type_set_qdata (test_type_id, g_quark_from_static_string ("vala-dbus-register-object"), (void*) test_register_object); + return test_type_id; +} + +GType +test_get_type (void) +{ + static volatile gsize test_type_id__volatile = 0; + if (g_once_init_enter (&test_type_id__volatile)) { + GType test_type_id; + test_type_id = test_get_type_once (); + g_once_init_leave (&test_type_id__volatile, test_type_id); + } + return test_type_id__volatile; +} + +static void +_dbus_test_test_in (Test* self, + GVariant* _parameters_, + GDBusMethodInvocation* invocation) +{ + GUnixFDList* _fd_list; + GVariantIter _arguments_iter; + gint _fd_index = 0; + gint _fd; + TestTestInReadyData* _ready_data; + GError* error = NULL; + g_variant_iter_init (&_arguments_iter, _parameters_); + _ready_data = g_slice_new0 (TestTestInReadyData); + _ready_data->_invocation_ = invocation; + _fd_list = g_dbus_message_get_unix_fd_list (g_dbus_method_invocation_get_message (invocation)); + if (_fd_list) { + g_variant_iter_next (&_arguments_iter, "h", &_fd_index); + _fd = g_unix_fd_list_get (_fd_list, _fd_index, &error); + if (_fd >= 0) { + _ready_data->i = (GUnixInputStream *) g_unix_input_stream_new (_fd, TRUE); + } + } else { + g_set_error_literal (&error, G_IO_ERROR, G_IO_ERROR_FAILED, "FD List is NULL"); + } + if (error) { + g_dbus_method_invocation_return_gerror (invocation, error); + g_error_free (error); + goto _error; + } + test_test_in (self, _ready_data->i, (GAsyncReadyCallback) _dbus_test_test_in_ready, _ready_data); + _error: + ; +} + +static void +_dbus_test_test_in_ready (GObject * source_object, + GAsyncResult * _res_, + gpointer _user_data_) +{ + TestTestInReadyData* _ready_data; + GDBusMethodInvocation* invocation; + GUnixFDList* _fd_list; + GError* error = NULL; + GDBusMessage* _reply_message = NULL; + GVariant* _reply; + GVariantBuilder _reply_builder; + GUnixInputStream* j = NULL; + GUnixInputStream* result; + _ready_data = _user_data_; + invocation = _ready_data->_invocation_; + result = test_test_in_finish ((Test*) source_object, _res_, &j, &error); + if (error) { + g_dbus_method_invocation_return_gerror (invocation, error); + g_error_free (error); + goto _error; + } + _reply_message = g_dbus_message_new_method_reply (g_dbus_method_invocation_get_message (invocation)); + g_variant_builder_init (&_reply_builder, G_VARIANT_TYPE_TUPLE); + _fd_list = g_unix_fd_list_new (); + g_variant_builder_add (&_reply_builder, "h", g_unix_fd_list_append (_fd_list, g_unix_input_stream_get_fd (j), NULL)); + g_variant_builder_add (&_reply_builder, "h", g_unix_fd_list_append (_fd_list, g_unix_input_stream_get_fd (result), NULL)); + _g_object_unref0 (result); + _reply = g_variant_builder_end (&_reply_builder); + g_dbus_message_set_body (_reply_message, _reply); + g_dbus_message_set_unix_fd_list (_reply_message, _fd_list); + g_object_unref (_fd_list); + g_dbus_connection_send_message (g_dbus_method_invocation_get_connection (invocation), _reply_message, G_DBUS_SEND_MESSAGE_FLAGS_NONE, NULL, NULL); + g_object_unref (invocation); + g_object_unref (_reply_message); + _error: + _g_object_unref0 (_ready_data->i); + _g_object_unref0 (j); + g_slice_free (TestTestInReadyData, _ready_data); +} + +static void +test_dbus_interface_method_call (GDBusConnection* connection, + const gchar* sender, + const gchar* object_path, + const gchar* interface_name, + const gchar* method_name, + GVariant* parameters, + GDBusMethodInvocation* invocation, + gpointer user_data) +{ + gpointer* data; + gpointer object; + data = user_data; + object = data[0]; + if (strcmp (method_name, "TestIn") == 0) { + _dbus_test_test_in (object, parameters, invocation); + } else { + g_object_unref (invocation); + } +} + +static GVariant* +test_dbus_interface_get_property (GDBusConnection* connection, + const gchar* sender, + const gchar* object_path, + const gchar* interface_name, + const gchar* property_name, + GError** error, + gpointer user_data) +{ + gpointer* data; + gpointer object; + data = user_data; + object = data[0]; + return NULL; +} + +static gboolean +test_dbus_interface_set_property (GDBusConnection* connection, + const gchar* sender, + const gchar* object_path, + const gchar* interface_name, + const gchar* property_name, + GVariant* value, + GError** error, + gpointer user_data) +{ + gpointer* data; + gpointer object; + data = user_data; + object = data[0]; + return FALSE; +} + +guint +test_register_object (gpointer object, + GDBusConnection* connection, + const gchar* path, + GError** error) +{ + guint result; + gpointer *data; + data = g_new (gpointer, 3); + data[0] = g_object_ref (object); + data[1] = g_object_ref (connection); + data[2] = g_strdup (path); + result = g_dbus_connection_register_object (connection, path, (GDBusInterfaceInfo *) (&_test_dbus_interface_info), &_test_dbus_interface_vtable, data, _test_unregister_object, error); + if (!result) { + return 0; + } + return result; +} + +static void +_test_unregister_object (gpointer user_data) +{ + gpointer* data; + data = user_data; + g_object_unref (data[0]); + g_object_unref (data[1]); + g_free (data[2]); + g_free (data); +} + +void +client_exit (GPid pid, + gint status) +{ + GMainLoop* _tmp0_; + _vala_assert (status == 0, "status == 0"); + _tmp0_ = main_loop; + g_main_loop_quit (_tmp0_); +} + +static guint +_variant_get1 (GVariant* value) +{ + return g_variant_get_uint32 (value); +} + +static void +_client_exit_gchild_watch_func (GPid pid, + gint wait_status, + gpointer self) +{ + client_exit (pid, wait_status); +} + +static void +_vala_main (void) +{ + GDBusConnection* conn = NULL; + GDBusConnection* _tmp0_; + GDBusConnection* _tmp1_; + Test* _tmp2_; + Test* _tmp3_; + GVariant* request_result = NULL; + GDBusConnection* _tmp4_; + GVariant* _tmp5_; + GVariant* _tmp6_; + GVariant* _tmp7_; + GVariant* _tmp8_; + GVariant* _tmp9_; + GVariant* _tmp10_; + GVariant* _tmp11_; + guint _tmp12_; + GPid client_pid = 0; + gchar* _tmp13_; + gchar** _tmp14_; + gchar** _tmp15_; + gint _tmp15__length1; + GPid _tmp16_ = 0; + GMainLoop* _tmp17_; + GMainLoop* _tmp18_; + GError* _inner_error0_ = NULL; + _tmp0_ = g_bus_get_sync (G_BUS_TYPE_SESSION, NULL, &_inner_error0_); + conn = _tmp0_; + if (G_UNLIKELY (_inner_error0_ != NULL)) { + g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error0_->message, g_quark_to_string (_inner_error0_->domain), _inner_error0_->code); + g_clear_error (&_inner_error0_); + return; + } + _tmp1_ = conn; + _tmp2_ = test_new (); + _tmp3_ = _tmp2_; + test_register_object (_tmp3_, _tmp1_, "/org/example/test", &_inner_error0_); + _g_object_unref0 (_tmp3_); + if (G_UNLIKELY (_inner_error0_ != NULL)) { + _g_object_unref0 (conn); + g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error0_->message, g_quark_to_string (_inner_error0_->domain), _inner_error0_->code); + g_clear_error (&_inner_error0_); + return; + } + _tmp4_ = conn; + _tmp5_ = g_variant_new ("(su)", "org.example.Test", 0x4, NULL); + g_variant_ref_sink (_tmp5_); + _tmp6_ = _tmp5_; + _tmp7_ = g_dbus_connection_call_sync (_tmp4_, "org.freedesktop.DBus", "/org/freedesktop/DBus", "org.freedesktop.DBus", "RequestName", _tmp6_, NULL, 0, -1, NULL, &_inner_error0_); + _tmp8_ = _tmp7_; + _g_variant_unref0 (_tmp6_); + request_result = _tmp8_; + if (G_UNLIKELY (_inner_error0_ != NULL)) { + _g_object_unref0 (conn); + g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error0_->message, g_quark_to_string (_inner_error0_->domain), _inner_error0_->code); + g_clear_error (&_inner_error0_); + return; + } + _tmp9_ = request_result; + _tmp10_ = g_variant_get_child_value (_tmp9_, (gsize) 0); + _tmp11_ = _tmp10_; + _tmp12_ = _variant_get1 (_tmp11_); + _vala_assert (_tmp12_ == ((guint) 1), "(uint) request_result.get_child_value (0) == 1"); + _g_variant_unref0 (_tmp11_); + _tmp13_ = g_strdup ("dbus_filedescriptor_async_client"); + _tmp14_ = g_new0 (gchar*, 1 + 1); + _tmp14_[0] = _tmp13_; + _tmp15_ = _tmp14_; + _tmp15__length1 = 1; + g_spawn_async (NULL, _tmp15_, NULL, G_SPAWN_DO_NOT_REAP_CHILD, NULL, NULL, &_tmp16_, &_inner_error0_); + client_pid = _tmp16_; + _tmp15_ = (_vala_array_free (_tmp15_, _tmp15__length1, (GDestroyNotify) g_free), NULL); + if (G_UNLIKELY (_inner_error0_ != NULL)) { + _g_variant_unref0 (request_result); + _g_object_unref0 (conn); + g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error0_->message, g_quark_to_string (_inner_error0_->domain), _inner_error0_->code); + g_clear_error (&_inner_error0_); + return; + } + g_child_watch_add_full (G_PRIORITY_DEFAULT_IDLE, client_pid, _client_exit_gchild_watch_func, NULL, NULL); + _tmp17_ = g_main_loop_new (NULL, FALSE); + _g_main_loop_unref0 (main_loop); + main_loop = _tmp17_; + _tmp18_ = main_loop; + g_main_loop_run (_tmp18_); + _g_variant_unref0 (request_result); + _g_object_unref0 (conn); +} + +int +main (int argc, + char ** argv) +{ + _vala_main (); + return 0; +} + +static void +_vala_array_destroy (gpointer array, + gssize array_length, + GDestroyNotify destroy_func) +{ + if ((array != NULL) && (destroy_func != NULL)) { + gssize i; + for (i = 0; i < array_length; i = i + 1) { + if (((gpointer*) array)[i] != NULL) { + destroy_func (((gpointer*) array)[i]); + } + } + } +} + +static void +_vala_array_free (gpointer array, + gssize array_length, + GDestroyNotify destroy_func) +{ + _vala_array_destroy (array, array_length, destroy_func); + g_free (array); +} + diff --git a/tests/dbus/filedescriptor-errors_client.c-expected b/tests/dbus/filedescriptor-errors_client.c-expected new file mode 100644 index 000000000..dde04e5dd --- /dev/null +++ b/tests/dbus/filedescriptor-errors_client.c-expected @@ -0,0 +1,479 @@ +/* dbus_filedescriptor_errors_client.c generated by valac, the Vala compiler + * generated from dbus_filedescriptor_errors_client.vala, do not modify */ + +#include <glib-object.h> +#include <gio/gio.h> +#include <gio/gunixoutputstream.h> +#include <stdlib.h> +#include <string.h> +#include <glib.h> +#include <gio/gunixfdlist.h> +#include <gio/gunixinputstream.h> +#include <unistd.h> + +#if !defined(VALA_EXTERN) +#if defined(_MSC_VER) +#define VALA_EXTERN __declspec(dllexport) extern +#elif __GNUC__ >= 4 +#define VALA_EXTERN __attribute__((visibility("default"))) extern +#else +#define VALA_EXTERN extern +#endif +#endif + +#define TYPE_TEST (test_get_type ()) +#define TEST(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TYPE_TEST, Test)) +#define IS_TEST(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TYPE_TEST)) +#define TEST_GET_INTERFACE(obj) (G_TYPE_INSTANCE_GET_INTERFACE ((obj), TYPE_TEST, TestIface)) + +typedef struct _Test Test; +typedef struct _TestIface TestIface; + +#define TYPE_TEST_PROXY (test_proxy_get_type ()) +typedef GDBusProxy TestProxy; +typedef GDBusProxyClass TestProxyClass; +#define _g_free0(var) (var = (g_free (var), NULL)) +#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL))) + +struct _TestIface { + GTypeInterface parent_iface; + gchar* (*test) (Test* self, GUnixOutputStream* output_stream, GError** error); +}; + +VALA_EXTERN GType test_proxy_get_type (void) G_GNUC_CONST ; +VALA_EXTERN guint test_register_object (void* object, + GDBusConnection* connection, + const gchar* path, + GError** error); +VALA_EXTERN GType test_get_type (void) G_GNUC_CONST ; +VALA_EXTERN gchar* test_test (Test* self, + GUnixOutputStream* output_stream, + GError** error); +static GType test_get_type_once (void); +static void test_proxy_g_signal (GDBusProxy* proxy, + const gchar* sender_name, + const gchar* signal_name, + GVariant* parameters); +static gchar* test_proxy_test (Test* self, + GUnixOutputStream* output_stream, + GError** error); +static void test_proxy_test_interface_init (TestIface* iface); +static void _dbus_test_test (Test* self, + GVariant* _parameters_, + GDBusMethodInvocation* invocation); +static void test_dbus_interface_method_call (GDBusConnection* connection, + const gchar* sender, + const gchar* object_path, + const gchar* interface_name, + const gchar* method_name, + GVariant* parameters, + GDBusMethodInvocation* invocation, + gpointer user_data); +static GVariant* test_dbus_interface_get_property (GDBusConnection* connection, + const gchar* sender, + const gchar* object_path, + const gchar* interface_name, + const gchar* property_name, + GError** error, + gpointer user_data); +static gboolean test_dbus_interface_set_property (GDBusConnection* connection, + const gchar* sender, + const gchar* object_path, + const gchar* interface_name, + const gchar* property_name, + GVariant* value, + GError** error, + gpointer user_data); +static void _test_unregister_object (gpointer user_data); +VALA_EXTERN void create_streams (GUnixInputStream* * input, + GUnixOutputStream* * output, + GError** error); +static void _vala_main (void); + +static const GDBusArgInfo _test_dbus_arg_info_test_output_stream = {-1, "output_stream", "h", NULL}; +static const GDBusArgInfo _test_dbus_arg_info_test_result = {-1, "result", "s", NULL}; +static const GDBusArgInfo * const _test_dbus_arg_info_test_in[] = {&_test_dbus_arg_info_test_output_stream, NULL}; +static const GDBusArgInfo * const _test_dbus_arg_info_test_out[] = {&_test_dbus_arg_info_test_result, NULL}; +static const GDBusMethodInfo _test_dbus_method_info_test = {-1, "Test", (GDBusArgInfo **) (&_test_dbus_arg_info_test_in), (GDBusArgInfo **) (&_test_dbus_arg_info_test_out), NULL}; +static const GDBusMethodInfo * const _test_dbus_method_info[] = {&_test_dbus_method_info_test, NULL}; +static const GDBusSignalInfo * const _test_dbus_signal_info[] = {NULL}; +static const GDBusPropertyInfo * const _test_dbus_property_info[] = {NULL}; +static const GDBusInterfaceInfo _test_dbus_interface_info = {-1, "org.example.Test", (GDBusMethodInfo **) (&_test_dbus_method_info), (GDBusSignalInfo **) (&_test_dbus_signal_info), (GDBusPropertyInfo **) (&_test_dbus_property_info), NULL}; +static const GDBusInterfaceVTable _test_dbus_interface_vtable = {test_dbus_interface_method_call, test_dbus_interface_get_property, test_dbus_interface_set_property}; + +gchar* +test_test (Test* self, + GUnixOutputStream* output_stream, + GError** error) +{ + TestIface* _iface_; + g_return_val_if_fail (IS_TEST (self), NULL); + _iface_ = TEST_GET_INTERFACE (self); + if (_iface_->test) { + return _iface_->test (self, output_stream, error); + } + return NULL; +} + +static void +test_default_init (TestIface * iface, + gpointer iface_data) +{ +} + +static GType +test_get_type_once (void) +{ + static const GTypeInfo g_define_type_info = { sizeof (TestIface), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) test_default_init, (GClassFinalizeFunc) NULL, NULL, 0, 0, (GInstanceInitFunc) NULL, NULL }; + GType test_type_id; + test_type_id = g_type_register_static (G_TYPE_INTERFACE, "Test", &g_define_type_info, 0); + g_type_interface_add_prerequisite (test_type_id, G_TYPE_OBJECT); + g_type_set_qdata (test_type_id, g_quark_from_static_string ("vala-dbus-proxy-type"), (void*) test_proxy_get_type); + g_type_set_qdata (test_type_id, g_quark_from_static_string ("vala-dbus-interface-name"), "org.example.Test"); + g_type_set_qdata (test_type_id, g_quark_from_static_string ("vala-dbus-interface-info"), (void*) (&_test_dbus_interface_info)); + g_type_set_qdata (test_type_id, g_quark_from_static_string ("vala-dbus-register-object"), (void*) test_register_object); + return test_type_id; +} + +GType +test_get_type (void) +{ + static volatile gsize test_type_id__volatile = 0; + if (g_once_init_enter (&test_type_id__volatile)) { + GType test_type_id; + test_type_id = test_get_type_once (); + g_once_init_leave (&test_type_id__volatile, test_type_id); + } + return test_type_id__volatile; +} + +G_DEFINE_TYPE_EXTENDED (TestProxy, test_proxy, G_TYPE_DBUS_PROXY, 0, G_IMPLEMENT_INTERFACE (TYPE_TEST, test_proxy_test_interface_init) ) +static void +test_proxy_class_init (TestProxyClass* klass) +{ + G_DBUS_PROXY_CLASS (klass)->g_signal = test_proxy_g_signal; +} + +static void +test_proxy_g_signal (GDBusProxy* proxy, + const gchar* sender_name, + const gchar* signal_name, + GVariant* parameters) +{ +} + +static void +test_proxy_init (TestProxy* self) +{ + g_dbus_proxy_set_interface_info (G_DBUS_PROXY (self), (GDBusInterfaceInfo *) (&_test_dbus_interface_info)); +} + +static gchar* +test_proxy_test (Test* self, + GUnixOutputStream* output_stream, + GError** error) +{ + GUnixFDList* _fd_list; + GDBusMessage *_message; + GVariant *_arguments; + GVariantBuilder _arguments_builder; + GDBusMessage *_reply_message; + gint _fd_index = 0; + gint _fd; + GVariant *_reply; + GVariantIter _reply_iter; + gchar* _result = NULL; + GVariant* _tmp0_; + G_IO_ERROR; + _message = g_dbus_message_new_method_call (g_dbus_proxy_get_name ((GDBusProxy *) self), g_dbus_proxy_get_object_path ((GDBusProxy *) self), "org.example.Test", "Test"); + g_variant_builder_init (&_arguments_builder, G_VARIANT_TYPE_TUPLE); + _fd_list = g_unix_fd_list_new (); + g_variant_builder_add (&_arguments_builder, "h", g_unix_fd_list_append (_fd_list, g_unix_output_stream_get_fd (output_stream), NULL)); + _arguments = g_variant_builder_end (&_arguments_builder); + g_dbus_message_set_body (_message, _arguments); + g_dbus_message_set_unix_fd_list (_message, _fd_list); + g_object_unref (_fd_list); + _reply_message = g_dbus_connection_send_message_with_reply_sync (g_dbus_proxy_get_connection ((GDBusProxy *) self), _message, G_DBUS_SEND_MESSAGE_FLAGS_NONE, g_dbus_proxy_get_default_timeout ((GDBusProxy *) self), NULL, NULL, error); + g_object_unref (_message); + if (!_reply_message) { + return NULL; + } + if (g_dbus_message_to_gerror (_reply_message, error)) { + g_object_unref (_reply_message); + return NULL; + } + _reply = g_dbus_message_get_body (_reply_message); + g_variant_iter_init (&_reply_iter, _reply); + _tmp0_ = g_variant_iter_next_value (&_reply_iter); + _result = g_variant_dup_string (_tmp0_, NULL); + g_variant_unref (_tmp0_); + g_object_unref (_reply_message); + return _result; +} + +static void +test_proxy_test_interface_init (TestIface* iface) +{ + iface->test = test_proxy_test; +} + +static void +_dbus_test_test (Test* self, + GVariant* _parameters_, + GDBusMethodInvocation* invocation) +{ + GUnixFDList* _fd_list; + GError* error = NULL; + GVariantIter _arguments_iter; + gint _fd_index = 0; + gint _fd; + GUnixOutputStream* output_stream = NULL; + GDBusMessage* _reply_message = NULL; + GVariant* _reply; + GVariantBuilder _reply_builder; + gchar* result; + g_variant_iter_init (&_arguments_iter, _parameters_); + _fd_list = g_dbus_message_get_unix_fd_list (g_dbus_method_invocation_get_message (invocation)); + if (_fd_list) { + g_variant_iter_next (&_arguments_iter, "h", &_fd_index); + _fd = g_unix_fd_list_get (_fd_list, _fd_index, &error); + if (_fd >= 0) { + output_stream = (GUnixOutputStream *) g_unix_output_stream_new (_fd, TRUE); + } + } else { + g_set_error_literal (&error, G_IO_ERROR, G_IO_ERROR_FAILED, "FD List is NULL"); + } + if (error) { + g_dbus_method_invocation_return_gerror (invocation, error); + g_error_free (error); + goto _error; + } + result = test_test (self, output_stream, &error); + if (error) { + g_dbus_method_invocation_return_gerror (invocation, error); + g_error_free (error); + goto _error; + } + _reply_message = g_dbus_message_new_method_reply (g_dbus_method_invocation_get_message (invocation)); + g_variant_builder_init (&_reply_builder, G_VARIANT_TYPE_TUPLE); + _fd_list = g_unix_fd_list_new (); + g_variant_builder_add_value (&_reply_builder, g_variant_new_string (result)); + _g_free0 (result); + _reply = g_variant_builder_end (&_reply_builder); + g_dbus_message_set_body (_reply_message, _reply); + g_dbus_message_set_unix_fd_list (_reply_message, _fd_list); + g_object_unref (_fd_list); + g_dbus_connection_send_message (g_dbus_method_invocation_get_connection (invocation), _reply_message, G_DBUS_SEND_MESSAGE_FLAGS_NONE, NULL, NULL); + g_object_unref (invocation); + g_object_unref (_reply_message); + _error: + _g_object_unref0 (output_stream); + ; +} + +static void +test_dbus_interface_method_call (GDBusConnection* connection, + const gchar* sender, + const gchar* object_path, + const gchar* interface_name, + const gchar* method_name, + GVariant* parameters, + GDBusMethodInvocation* invocation, + gpointer user_data) +{ + gpointer* data; + gpointer object; + data = user_data; + object = data[0]; + if (strcmp (method_name, "Test") == 0) { + _dbus_test_test (object, parameters, invocation); + } else { + g_object_unref (invocation); + } +} + +static GVariant* +test_dbus_interface_get_property (GDBusConnection* connection, + const gchar* sender, + const gchar* object_path, + const gchar* interface_name, + const gchar* property_name, + GError** error, + gpointer user_data) +{ + gpointer* data; + gpointer object; + data = user_data; + object = data[0]; + return NULL; +} + +static gboolean +test_dbus_interface_set_property (GDBusConnection* connection, + const gchar* sender, + const gchar* object_path, + const gchar* interface_name, + const gchar* property_name, + GVariant* value, + GError** error, + gpointer user_data) +{ + gpointer* data; + gpointer object; + data = user_data; + object = data[0]; + return FALSE; +} + +guint +test_register_object (gpointer object, + GDBusConnection* connection, + const gchar* path, + GError** error) +{ + guint result; + gpointer *data; + data = g_new (gpointer, 3); + data[0] = g_object_ref (object); + data[1] = g_object_ref (connection); + data[2] = g_strdup (path); + result = g_dbus_connection_register_object (connection, path, (GDBusInterfaceInfo *) (&_test_dbus_interface_info), &_test_dbus_interface_vtable, data, _test_unregister_object, error); + if (!result) { + return 0; + } + return result; +} + +static void +_test_unregister_object (gpointer user_data) +{ + gpointer* data; + data = user_data; + g_object_unref (data[0]); + g_object_unref (data[1]); + g_free (data[2]); + g_free (data); +} + +void +create_streams (GUnixInputStream* * input, + GUnixOutputStream* * output, + GError** error) +{ + GUnixInputStream* _vala_input = NULL; + GUnixOutputStream* _vala_output = NULL; + gint pipefd[2] = {0}; + gint _tmp1_; + GUnixInputStream* _tmp2_; + gint _tmp3_; + GUnixOutputStream* _tmp4_; + GError* _inner_error0_ = NULL; + if (pipe (pipefd) < 0) { + GError* _tmp0_; + _tmp0_ = g_error_new_literal (G_IO_ERROR, G_IO_ERROR_FAILED, "Pipe creation failed"); + _inner_error0_ = _tmp0_; + if (_inner_error0_->domain == G_IO_ERROR) { + g_propagate_error (error, _inner_error0_); + _g_object_unref0 (_vala_input); + _g_object_unref0 (_vala_output); + return; + } else { + _g_object_unref0 (_vala_input); + _g_object_unref0 (_vala_output); + g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error0_->message, g_quark_to_string (_inner_error0_->domain), _inner_error0_->code); + g_clear_error (&_inner_error0_); + return; + } + } + _tmp1_ = pipefd[0]; + _tmp2_ = (GUnixInputStream*) g_unix_input_stream_new (_tmp1_, TRUE); + _g_object_unref0 (_vala_input); + _vala_input = _tmp2_; + _tmp3_ = pipefd[1]; + _tmp4_ = (GUnixOutputStream*) g_unix_output_stream_new (_tmp3_, TRUE); + _g_object_unref0 (_vala_output); + _vala_output = _tmp4_; + if (input) { + *input = _vala_input; + } else { + _g_object_unref0 (_vala_input); + } + if (output) { + *output = _vala_output; + } else { + _g_object_unref0 (_vala_output); + } +} + +static void +_vala_main (void) +{ + Test* test = NULL; + Test* _tmp0_; + GUnixInputStream* i = NULL; + GUnixOutputStream* o = NULL; + GUnixInputStream* _tmp1_ = NULL; + GUnixOutputStream* _tmp2_ = NULL; + GError* _inner_error0_ = NULL; + _tmp0_ = (Test*) g_initable_new (TYPE_TEST_PROXY, NULL, &_inner_error0_, "g-flags", 0, "g-name", "org.example.Test", "g-bus-type", G_BUS_TYPE_SESSION, "g-object-path", "/org/example/test", "g-interface-name", "org.example.Test", NULL); + test = (Test*) _tmp0_; + if (G_UNLIKELY (_inner_error0_ != NULL)) { + g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error0_->message, g_quark_to_string (_inner_error0_->domain), _inner_error0_->code); + g_clear_error (&_inner_error0_); + return; + } + create_streams (&_tmp1_, &_tmp2_, &_inner_error0_); + _g_object_unref0 (i); + i = _tmp1_; + _g_object_unref0 (o); + o = _tmp2_; + if (G_UNLIKELY (_inner_error0_ != NULL)) { + _g_object_unref0 (o); + _g_object_unref0 (i); + _g_object_unref0 (test); + g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error0_->message, g_quark_to_string (_inner_error0_->domain), _inner_error0_->code); + g_clear_error (&_inner_error0_); + return; + } + { + Test* _tmp3_; + GUnixOutputStream* _tmp4_; + gchar* _tmp5_; + gchar* _tmp6_; + _tmp3_ = test; + _tmp4_ = o; + _tmp5_ = test_test (_tmp3_, _tmp4_, &_inner_error0_); + _tmp6_ = _tmp5_; + _g_free0 (_tmp6_); + if (G_UNLIKELY (_inner_error0_ != NULL)) { + goto __catch0_g_error; + } + g_assert_not_reached (); + } + goto __finally0; + __catch0_g_error: + { + g_clear_error (&_inner_error0_); + } + __finally0: + if (G_UNLIKELY (_inner_error0_ != NULL)) { + _g_object_unref0 (o); + _g_object_unref0 (i); + _g_object_unref0 (test); + g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error0_->message, g_quark_to_string (_inner_error0_->domain), _inner_error0_->code); + g_clear_error (&_inner_error0_); + return; + } + _g_object_unref0 (o); + _g_object_unref0 (i); + _g_object_unref0 (test); +} + +int +main (int argc, + char ** argv) +{ + _vala_main (); + return 0; +} + diff --git a/tests/dbus/filedescriptor-errors_server.c-expected b/tests/dbus/filedescriptor-errors_server.c-expected new file mode 100644 index 000000000..6067ff0bb --- /dev/null +++ b/tests/dbus/filedescriptor-errors_server.c-expected @@ -0,0 +1,493 @@ +/* dbus_filedescriptor_errors_server.c generated by valac, the Vala compiler + * generated from dbus_filedescriptor_errors_server.vala, do not modify */ + +#include <glib-object.h> +#include <gio/gio.h> +#include <gio/gunixoutputstream.h> +#include <glib.h> +#include <string.h> +#include <gio/gunixfdlist.h> +#include <stdlib.h> +#include <fcntl.h> +#include <sys/types.h> + +#if !defined(VALA_EXTERN) +#if defined(_MSC_VER) +#define VALA_EXTERN __declspec(dllexport) extern +#elif __GNUC__ >= 4 +#define VALA_EXTERN __attribute__((visibility("default"))) extern +#else +#define VALA_EXTERN extern +#endif +#endif + +#define TYPE_TEST (test_get_type ()) +#define TEST(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TYPE_TEST, Test)) +#define TEST_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), TYPE_TEST, TestClass)) +#define IS_TEST(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TYPE_TEST)) +#define IS_TEST_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), TYPE_TEST)) +#define TEST_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), TYPE_TEST, TestClass)) + +typedef struct _Test Test; +typedef struct _TestClass TestClass; +typedef struct _TestPrivate TestPrivate; +enum { + TEST_0_PROPERTY, + TEST_NUM_PROPERTIES +}; +static GParamSpec* test_properties[TEST_NUM_PROPERTIES]; +#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL))) +#define _g_variant_unref0(var) ((var == NULL) ? NULL : (var = (g_variant_unref (var), NULL))) +#define _g_main_loop_unref0(var) ((var == NULL) ? NULL : (var = (g_main_loop_unref (var), NULL))) +#define _vala_assert(expr, msg) if G_LIKELY (expr) ; else g_assertion_message_expr (G_LOG_DOMAIN, __FILE__, __LINE__, G_STRFUNC, msg); +#define _vala_return_if_fail(expr, msg) if G_LIKELY (expr) ; else { g_return_if_fail_warning (G_LOG_DOMAIN, G_STRFUNC, msg); return; } +#define _vala_return_val_if_fail(expr, msg, val) if G_LIKELY (expr) ; else { g_return_if_fail_warning (G_LOG_DOMAIN, G_STRFUNC, msg); return val; } +#define _vala_warn_if_fail(expr, msg) if G_LIKELY (expr) ; else g_warn_message (G_LOG_DOMAIN, __FILE__, __LINE__, G_STRFUNC, msg); + +struct _Test { + GObject parent_instance; + TestPrivate * priv; +}; + +struct _TestClass { + GObjectClass parent_class; +}; + +static gpointer test_parent_class = NULL; +VALA_EXTERN GMainLoop* main_loop; +GMainLoop* main_loop = NULL; + +VALA_EXTERN GType test_get_type (void) G_GNUC_CONST ; +G_DEFINE_AUTOPTR_CLEANUP_FUNC (Test, g_object_unref) +VALA_EXTERN guint test_register_object (void* object, + GDBusConnection* connection, + const gchar* path, + GError** error); +VALA_EXTERN void test_test (Test* self, + GUnixOutputStream* output_stream, + GError** error); +VALA_EXTERN Test* test_new (void); +VALA_EXTERN Test* test_construct (GType object_type); +static GType test_get_type_once (void); +static void _dbus_test_test (Test* self, + GVariant* _parameters_, + GDBusMethodInvocation* invocation); +static void test_dbus_interface_method_call (GDBusConnection* connection, + const gchar* sender, + const gchar* object_path, + const gchar* interface_name, + const gchar* method_name, + GVariant* parameters, + GDBusMethodInvocation* invocation, + gpointer user_data); +static GVariant* test_dbus_interface_get_property (GDBusConnection* connection, + const gchar* sender, + const gchar* object_path, + const gchar* interface_name, + const gchar* property_name, + GError** error, + gpointer user_data); +static gboolean test_dbus_interface_set_property (GDBusConnection* connection, + const gchar* sender, + const gchar* object_path, + const gchar* interface_name, + const gchar* property_name, + GVariant* value, + GError** error, + gpointer user_data); +static void _test_unregister_object (gpointer user_data); +VALA_EXTERN void client_exit (GPid pid, + gint status); +static void _vala_main (void); +static guint _variant_get1 (GVariant* value); +static void _client_exit_gchild_watch_func (GPid pid, + gint wait_status, + gpointer self); +static void _vala_array_destroy (gpointer array, + gssize array_length, + GDestroyNotify destroy_func); +static void _vala_array_free (gpointer array, + gssize array_length, + GDestroyNotify destroy_func); + +static const GDBusArgInfo _test_dbus_arg_info_test_output_stream = {-1, "output_stream", "h", NULL}; +static const GDBusArgInfo * const _test_dbus_arg_info_test_in[] = {&_test_dbus_arg_info_test_output_stream, NULL}; +static const GDBusArgInfo * const _test_dbus_arg_info_test_out[] = {NULL}; +static const GDBusMethodInfo _test_dbus_method_info_test = {-1, "Test", (GDBusArgInfo **) (&_test_dbus_arg_info_test_in), (GDBusArgInfo **) (&_test_dbus_arg_info_test_out), NULL}; +static const GDBusMethodInfo * const _test_dbus_method_info[] = {&_test_dbus_method_info_test, NULL}; +static const GDBusSignalInfo * const _test_dbus_signal_info[] = {NULL}; +static const GDBusPropertyInfo * const _test_dbus_property_info[] = {NULL}; +static const GDBusInterfaceInfo _test_dbus_interface_info = {-1, "org.example.Test", (GDBusMethodInfo **) (&_test_dbus_method_info), (GDBusSignalInfo **) (&_test_dbus_signal_info), (GDBusPropertyInfo **) (&_test_dbus_property_info), NULL}; +static const GDBusInterfaceVTable _test_dbus_interface_vtable = {test_dbus_interface_method_call, test_dbus_interface_get_property, test_dbus_interface_set_property}; + +void +test_test (Test* self, + GUnixOutputStream* output_stream, + GError** error) +{ + guint8* buffer = NULL; + guint8* _tmp0_; + gint buffer_length1; + gint _buffer_size_; + GError* _inner_error0_ = NULL; + g_return_if_fail (IS_TEST (self)); + g_return_if_fail (G_TYPE_CHECK_INSTANCE_TYPE (output_stream, G_TYPE_UNIX_OUTPUT_STREAM)); + _tmp0_ = g_new0 (guint8, 1); + buffer = _tmp0_; + buffer_length1 = 1; + _buffer_size_ = buffer_length1; + buffer[0] = (guint8) 42; + g_output_stream_write (G_TYPE_CHECK_INSTANCE_CAST (output_stream, g_output_stream_get_type (), GOutputStream), buffer, (gsize) buffer_length1, NULL, &_inner_error0_); + if (G_UNLIKELY (_inner_error0_ != NULL)) { + if (_inner_error0_->domain == G_IO_ERROR) { + g_propagate_error (error, _inner_error0_); + buffer = (g_free (buffer), NULL); + return; + } else { + buffer = (g_free (buffer), NULL); + g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error0_->message, g_quark_to_string (_inner_error0_->domain), _inner_error0_->code); + g_clear_error (&_inner_error0_); + return; + } + } + buffer = (g_free (buffer), NULL); +} + +Test* +test_construct (GType object_type) +{ + Test * self = NULL; + self = (Test*) g_object_new (object_type, NULL); + return self; +} + +Test* +test_new (void) +{ + return test_construct (TYPE_TEST); +} + +static void +test_class_init (TestClass * klass, + gpointer klass_data) +{ + test_parent_class = g_type_class_peek_parent (klass); +} + +static void +test_instance_init (Test * self, + gpointer klass) +{ +} + +static GType +test_get_type_once (void) +{ + static const GTypeInfo g_define_type_info = { sizeof (TestClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) test_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (Test), 0, (GInstanceInitFunc) test_instance_init, NULL }; + GType test_type_id; + test_type_id = g_type_register_static (G_TYPE_OBJECT, "Test", &g_define_type_info, 0); + g_type_set_qdata (test_type_id, g_quark_from_static_string ("vala-dbus-register-object"), (void*) test_register_object); + return test_type_id; +} + +GType +test_get_type (void) +{ + static volatile gsize test_type_id__volatile = 0; + if (g_once_init_enter (&test_type_id__volatile)) { + GType test_type_id; + test_type_id = test_get_type_once (); + g_once_init_leave (&test_type_id__volatile, test_type_id); + } + return test_type_id__volatile; +} + +static void +_dbus_test_test (Test* self, + GVariant* _parameters_, + GDBusMethodInvocation* invocation) +{ + GUnixFDList* _fd_list; + GError* error = NULL; + GVariantIter _arguments_iter; + gint _fd_index = 0; + gint _fd; + GUnixOutputStream* output_stream = NULL; + GDBusMessage* _reply_message = NULL; + GVariant* _reply; + GVariantBuilder _reply_builder; + g_variant_iter_init (&_arguments_iter, _parameters_); + _fd_list = g_dbus_message_get_unix_fd_list (g_dbus_method_invocation_get_message (invocation)); + if (_fd_list) { + g_variant_iter_next (&_arguments_iter, "h", &_fd_index); + _fd = g_unix_fd_list_get (_fd_list, _fd_index, &error); + if (_fd >= 0) { + output_stream = (GUnixOutputStream *) g_unix_output_stream_new (_fd, TRUE); + } + } else { + g_set_error_literal (&error, G_IO_ERROR, G_IO_ERROR_FAILED, "FD List is NULL"); + } + if (error) { + g_dbus_method_invocation_return_gerror (invocation, error); + g_error_free (error); + goto _error; + } + test_test (self, output_stream, &error); + if (error) { + g_dbus_method_invocation_return_gerror (invocation, error); + g_error_free (error); + goto _error; + } + _reply_message = g_dbus_message_new_method_reply (g_dbus_method_invocation_get_message (invocation)); + g_variant_builder_init (&_reply_builder, G_VARIANT_TYPE_TUPLE); + _fd_list = g_unix_fd_list_new (); + _reply = g_variant_builder_end (&_reply_builder); + g_dbus_message_set_body (_reply_message, _reply); + g_dbus_message_set_unix_fd_list (_reply_message, _fd_list); + g_object_unref (_fd_list); + g_dbus_connection_send_message (g_dbus_method_invocation_get_connection (invocation), _reply_message, G_DBUS_SEND_MESSAGE_FLAGS_NONE, NULL, NULL); + g_object_unref (invocation); + g_object_unref (_reply_message); + _error: + _g_object_unref0 (output_stream); + ; +} + +static void +test_dbus_interface_method_call (GDBusConnection* connection, + const gchar* sender, + const gchar* object_path, + const gchar* interface_name, + const gchar* method_name, + GVariant* parameters, + GDBusMethodInvocation* invocation, + gpointer user_data) +{ + gpointer* data; + gpointer object; + data = user_data; + object = data[0]; + if (strcmp (method_name, "Test") == 0) { + _dbus_test_test (object, parameters, invocation); + } else { + g_object_unref (invocation); + } +} + +static GVariant* +test_dbus_interface_get_property (GDBusConnection* connection, + const gchar* sender, + const gchar* object_path, + const gchar* interface_name, + const gchar* property_name, + GError** error, + gpointer user_data) +{ + gpointer* data; + gpointer object; + data = user_data; + object = data[0]; + return NULL; +} + +static gboolean +test_dbus_interface_set_property (GDBusConnection* connection, + const gchar* sender, + const gchar* object_path, + const gchar* interface_name, + const gchar* property_name, + GVariant* value, + GError** error, + gpointer user_data) +{ + gpointer* data; + gpointer object; + data = user_data; + object = data[0]; + return FALSE; +} + +guint +test_register_object (gpointer object, + GDBusConnection* connection, + const gchar* path, + GError** error) +{ + guint result; + gpointer *data; + data = g_new (gpointer, 3); + data[0] = g_object_ref (object); + data[1] = g_object_ref (connection); + data[2] = g_strdup (path); + result = g_dbus_connection_register_object (connection, path, (GDBusInterfaceInfo *) (&_test_dbus_interface_info), &_test_dbus_interface_vtable, data, _test_unregister_object, error); + if (!result) { + return 0; + } + return result; +} + +static void +_test_unregister_object (gpointer user_data) +{ + gpointer* data; + data = user_data; + g_object_unref (data[0]); + g_object_unref (data[1]); + g_free (data[2]); + g_free (data); +} + +void +client_exit (GPid pid, + gint status) +{ + GMainLoop* _tmp0_; + _vala_assert (status == 0, "status == 0"); + _tmp0_ = main_loop; + g_main_loop_quit (_tmp0_); +} + +static guint +_variant_get1 (GVariant* value) +{ + return g_variant_get_uint32 (value); +} + +static void +_client_exit_gchild_watch_func (GPid pid, + gint wait_status, + gpointer self) +{ + client_exit (pid, wait_status); +} + +static void +_vala_main (void) +{ + GDBusConnection* conn = NULL; + GDBusConnection* _tmp0_; + GDBusConnection* _tmp1_; + Test* _tmp2_; + Test* _tmp3_; + GVariant* request_result = NULL; + GDBusConnection* _tmp4_; + GVariant* _tmp5_; + GVariant* _tmp6_; + GVariant* _tmp7_; + GVariant* _tmp8_; + GVariant* _tmp9_; + GVariant* _tmp10_; + GVariant* _tmp11_; + guint _tmp12_; + GPid client_pid = 0; + gchar* _tmp13_; + gchar** _tmp14_; + gchar** _tmp15_; + gint _tmp15__length1; + GPid _tmp16_ = 0; + GMainLoop* _tmp17_; + gint fd = 0; + GMainLoop* _tmp18_; + GError* _inner_error0_ = NULL; + _tmp0_ = g_bus_get_sync (G_BUS_TYPE_SESSION, NULL, &_inner_error0_); + conn = _tmp0_; + if (G_UNLIKELY (_inner_error0_ != NULL)) { + g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error0_->message, g_quark_to_string (_inner_error0_->domain), _inner_error0_->code); + g_clear_error (&_inner_error0_); + return; + } + _tmp1_ = conn; + _tmp2_ = test_new (); + _tmp3_ = _tmp2_; + test_register_object (_tmp3_, _tmp1_, "/org/example/test", &_inner_error0_); + _g_object_unref0 (_tmp3_); + if (G_UNLIKELY (_inner_error0_ != NULL)) { + _g_object_unref0 (conn); + g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error0_->message, g_quark_to_string (_inner_error0_->domain), _inner_error0_->code); + g_clear_error (&_inner_error0_); + return; + } + _tmp4_ = conn; + _tmp5_ = g_variant_new ("(su)", "org.example.Test", 0x4, NULL); + g_variant_ref_sink (_tmp5_); + _tmp6_ = _tmp5_; + _tmp7_ = g_dbus_connection_call_sync (_tmp4_, "org.freedesktop.DBus", "/org/freedesktop/DBus", "org.freedesktop.DBus", "RequestName", _tmp6_, NULL, 0, -1, NULL, &_inner_error0_); + _tmp8_ = _tmp7_; + _g_variant_unref0 (_tmp6_); + request_result = _tmp8_; + if (G_UNLIKELY (_inner_error0_ != NULL)) { + _g_object_unref0 (conn); + g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error0_->message, g_quark_to_string (_inner_error0_->domain), _inner_error0_->code); + g_clear_error (&_inner_error0_); + return; + } + _tmp9_ = request_result; + _tmp10_ = g_variant_get_child_value (_tmp9_, (gsize) 0); + _tmp11_ = _tmp10_; + _tmp12_ = _variant_get1 (_tmp11_); + _vala_assert (_tmp12_ == ((guint) 1), "(uint) request_result.get_child_value (0) == 1"); + _g_variant_unref0 (_tmp11_); + _tmp13_ = g_strdup ("dbus_filedescriptor_errors_client"); + _tmp14_ = g_new0 (gchar*, 1 + 1); + _tmp14_[0] = _tmp13_; + _tmp15_ = _tmp14_; + _tmp15__length1 = 1; + g_spawn_async (NULL, _tmp15_, NULL, G_SPAWN_DO_NOT_REAP_CHILD, NULL, NULL, &_tmp16_, &_inner_error0_); + client_pid = _tmp16_; + _tmp15_ = (_vala_array_free (_tmp15_, _tmp15__length1, (GDestroyNotify) g_free), NULL); + if (G_UNLIKELY (_inner_error0_ != NULL)) { + _g_variant_unref0 (request_result); + _g_object_unref0 (conn); + g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error0_->message, g_quark_to_string (_inner_error0_->domain), _inner_error0_->code); + g_clear_error (&_inner_error0_); + return; + } + g_child_watch_add_full (G_PRIORITY_DEFAULT_IDLE, client_pid, _client_exit_gchild_watch_func, NULL, NULL); + _tmp17_ = g_main_loop_new (NULL, FALSE); + _g_main_loop_unref0 (main_loop); + main_loop = _tmp17_; + fd = 0; + while (TRUE) { + if (!(fd >= 0)) { + break; + } + fd = open ("/", 0, (mode_t) 0); + } + _tmp18_ = main_loop; + g_main_loop_run (_tmp18_); + _g_variant_unref0 (request_result); + _g_object_unref0 (conn); +} + +int +main (int argc, + char ** argv) +{ + _vala_main (); + return 0; +} + +static void +_vala_array_destroy (gpointer array, + gssize array_length, + GDestroyNotify destroy_func) +{ + if ((array != NULL) && (destroy_func != NULL)) { + gssize i; + for (i = 0; i < array_length; i = i + 1) { + if (((gpointer*) array)[i] != NULL) { + destroy_func (((gpointer*) array)[i]); + } + } + } +} + +static void +_vala_array_free (gpointer array, + gssize array_length, + GDestroyNotify destroy_func) +{ + _vala_array_destroy (array, array_length, destroy_func); + g_free (array); +} + diff --git a/tests/dbus/filedescriptor_client.c-expected b/tests/dbus/filedescriptor_client.c-expected new file mode 100644 index 000000000..d22be7c38 --- /dev/null +++ b/tests/dbus/filedescriptor_client.c-expected @@ -0,0 +1,555 @@ +/* dbus_filedescriptor_client.c generated by valac, the Vala compiler + * generated from dbus_filedescriptor_client.vala, do not modify */ + +#include <glib-object.h> +#include <gio/gio.h> +#include <gio/gunixinputstream.h> +#include <glib.h> +#include <gio/gunixfdlist.h> +#include <string.h> +#include <unistd.h> + +#if !defined(VALA_EXTERN) +#if defined(_MSC_VER) +#define VALA_EXTERN __declspec(dllexport) extern +#elif __GNUC__ >= 4 +#define VALA_EXTERN __attribute__((visibility("default"))) extern +#else +#define VALA_EXTERN extern +#endif +#endif + +#define TYPE_TEST (test_get_type ()) +#define TEST(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TYPE_TEST, Test)) +#define IS_TEST(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TYPE_TEST)) +#define TEST_GET_INTERFACE(obj) (G_TYPE_INSTANCE_GET_INTERFACE ((obj), TYPE_TEST, TestIface)) + +typedef struct _Test Test; +typedef struct _TestIface TestIface; + +#define TYPE_TEST_PROXY (test_proxy_get_type ()) +typedef GDBusProxy TestProxy; +typedef GDBusProxyClass TestProxyClass; +#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL))) +#define _vala_assert(expr, msg) if G_LIKELY (expr) ; else g_assertion_message_expr (G_LOG_DOMAIN, __FILE__, __LINE__, G_STRFUNC, msg); +#define _vala_return_if_fail(expr, msg) if G_LIKELY (expr) ; else { g_return_if_fail_warning (G_LOG_DOMAIN, G_STRFUNC, msg); return; } +#define _vala_return_val_if_fail(expr, msg, val) if G_LIKELY (expr) ; else { g_return_if_fail_warning (G_LOG_DOMAIN, G_STRFUNC, msg); return val; } +#define _vala_warn_if_fail(expr, msg) if G_LIKELY (expr) ; else g_warn_message (G_LOG_DOMAIN, __FILE__, __LINE__, G_STRFUNC, msg); + +struct _TestIface { + GTypeInterface parent_iface; + GUnixInputStream* (*test_in) (Test* self, GUnixInputStream* i, GUnixInputStream* * j, GError** error); +}; + +VALA_EXTERN GType test_proxy_get_type (void) G_GNUC_CONST ; +VALA_EXTERN guint test_register_object (void* object, + GDBusConnection* connection, + const gchar* path, + GError** error); +VALA_EXTERN GType test_get_type (void) G_GNUC_CONST ; +VALA_EXTERN GUnixInputStream* test_test_in (Test* self, + GUnixInputStream* i, + GUnixInputStream* * j, + GError** error); +static GType test_get_type_once (void); +static void test_proxy_g_signal (GDBusProxy* proxy, + const gchar* sender_name, + const gchar* signal_name, + GVariant* parameters); +static GUnixInputStream* test_proxy_test_in (Test* self, + GUnixInputStream* i, + GUnixInputStream* * j, + GError** error); +static void test_proxy_test_interface_init (TestIface* iface); +static void _dbus_test_test_in (Test* self, + GVariant* _parameters_, + GDBusMethodInvocation* invocation); +static void test_dbus_interface_method_call (GDBusConnection* connection, + const gchar* sender, + const gchar* object_path, + const gchar* interface_name, + const gchar* method_name, + GVariant* parameters, + GDBusMethodInvocation* invocation, + gpointer user_data); +static GVariant* test_dbus_interface_get_property (GDBusConnection* connection, + const gchar* sender, + const gchar* object_path, + const gchar* interface_name, + const gchar* property_name, + GError** error, + gpointer user_data); +static gboolean test_dbus_interface_set_property (GDBusConnection* connection, + const gchar* sender, + const gchar* object_path, + const gchar* interface_name, + const gchar* property_name, + GVariant* value, + GError** error, + gpointer user_data); +static void _test_unregister_object (gpointer user_data); +static void _vala_main (void); + +static const GDBusArgInfo _test_dbus_arg_info_test_in_i = {-1, "i", "h", NULL}; +static const GDBusArgInfo _test_dbus_arg_info_test_in_j = {-1, "j", "h", NULL}; +static const GDBusArgInfo _test_dbus_arg_info_test_in_result = {-1, "result", "h", NULL}; +static const GDBusArgInfo * const _test_dbus_arg_info_test_in_in[] = {&_test_dbus_arg_info_test_in_i, NULL}; +static const GDBusArgInfo * const _test_dbus_arg_info_test_in_out[] = {&_test_dbus_arg_info_test_in_j, &_test_dbus_arg_info_test_in_result, NULL}; +static const GDBusMethodInfo _test_dbus_method_info_test_in = {-1, "TestIn", (GDBusArgInfo **) (&_test_dbus_arg_info_test_in_in), (GDBusArgInfo **) (&_test_dbus_arg_info_test_in_out), NULL}; +static const GDBusMethodInfo * const _test_dbus_method_info[] = {&_test_dbus_method_info_test_in, NULL}; +static const GDBusSignalInfo * const _test_dbus_signal_info[] = {NULL}; +static const GDBusPropertyInfo * const _test_dbus_property_info[] = {NULL}; +static const GDBusInterfaceInfo _test_dbus_interface_info = {-1, "org.example.Test", (GDBusMethodInfo **) (&_test_dbus_method_info), (GDBusSignalInfo **) (&_test_dbus_signal_info), (GDBusPropertyInfo **) (&_test_dbus_property_info), NULL}; +static const GDBusInterfaceVTable _test_dbus_interface_vtable = {test_dbus_interface_method_call, test_dbus_interface_get_property, test_dbus_interface_set_property}; + +GUnixInputStream* +test_test_in (Test* self, + GUnixInputStream* i, + GUnixInputStream* * j, + GError** error) +{ + TestIface* _iface_; + g_return_val_if_fail (IS_TEST (self), NULL); + _iface_ = TEST_GET_INTERFACE (self); + if (_iface_->test_in) { + return _iface_->test_in (self, i, j, error); + } + return NULL; +} + +static void +test_default_init (TestIface * iface, + gpointer iface_data) +{ +} + +static GType +test_get_type_once (void) +{ + static const GTypeInfo g_define_type_info = { sizeof (TestIface), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) test_default_init, (GClassFinalizeFunc) NULL, NULL, 0, 0, (GInstanceInitFunc) NULL, NULL }; + GType test_type_id; + test_type_id = g_type_register_static (G_TYPE_INTERFACE, "Test", &g_define_type_info, 0); + g_type_interface_add_prerequisite (test_type_id, G_TYPE_OBJECT); + g_type_set_qdata (test_type_id, g_quark_from_static_string ("vala-dbus-proxy-type"), (void*) test_proxy_get_type); + g_type_set_qdata (test_type_id, g_quark_from_static_string ("vala-dbus-interface-name"), "org.example.Test"); + g_type_set_qdata (test_type_id, g_quark_from_static_string ("vala-dbus-interface-info"), (void*) (&_test_dbus_interface_info)); + g_type_set_qdata (test_type_id, g_quark_from_static_string ("vala-dbus-register-object"), (void*) test_register_object); + return test_type_id; +} + +GType +test_get_type (void) +{ + static volatile gsize test_type_id__volatile = 0; + if (g_once_init_enter (&test_type_id__volatile)) { + GType test_type_id; + test_type_id = test_get_type_once (); + g_once_init_leave (&test_type_id__volatile, test_type_id); + } + return test_type_id__volatile; +} + +G_DEFINE_TYPE_EXTENDED (TestProxy, test_proxy, G_TYPE_DBUS_PROXY, 0, G_IMPLEMENT_INTERFACE (TYPE_TEST, test_proxy_test_interface_init) ) +static void +test_proxy_class_init (TestProxyClass* klass) +{ + G_DBUS_PROXY_CLASS (klass)->g_signal = test_proxy_g_signal; +} + +static void +test_proxy_g_signal (GDBusProxy* proxy, + const gchar* sender_name, + const gchar* signal_name, + GVariant* parameters) +{ +} + +static void +test_proxy_init (TestProxy* self) +{ + g_dbus_proxy_set_interface_info (G_DBUS_PROXY (self), (GDBusInterfaceInfo *) (&_test_dbus_interface_info)); +} + +static GUnixInputStream* +test_proxy_test_in (Test* self, + GUnixInputStream* i, + GUnixInputStream* * j, + GError** error) +{ + GUnixFDList* _fd_list; + GDBusMessage *_message; + GVariant *_arguments; + GVariantBuilder _arguments_builder; + GDBusMessage *_reply_message; + gint _fd_index = 0; + gint _fd; + GVariant *_reply; + GVariantIter _reply_iter; + GUnixInputStream* _vala_j = NULL; + GUnixInputStream* _result = NULL; + G_IO_ERROR; + _message = g_dbus_message_new_method_call (g_dbus_proxy_get_name ((GDBusProxy *) self), g_dbus_proxy_get_object_path ((GDBusProxy *) self), "org.example.Test", "TestIn"); + g_variant_builder_init (&_arguments_builder, G_VARIANT_TYPE_TUPLE); + _fd_list = g_unix_fd_list_new (); + g_variant_builder_add (&_arguments_builder, "h", g_unix_fd_list_append (_fd_list, g_unix_input_stream_get_fd (i), NULL)); + _arguments = g_variant_builder_end (&_arguments_builder); + g_dbus_message_set_body (_message, _arguments); + g_dbus_message_set_unix_fd_list (_message, _fd_list); + g_object_unref (_fd_list); + _reply_message = g_dbus_connection_send_message_with_reply_sync (g_dbus_proxy_get_connection ((GDBusProxy *) self), _message, G_DBUS_SEND_MESSAGE_FLAGS_NONE, g_dbus_proxy_get_default_timeout ((GDBusProxy *) self), NULL, NULL, error); + g_object_unref (_message); + if (!_reply_message) { + return NULL; + } + if (g_dbus_message_to_gerror (_reply_message, error)) { + g_object_unref (_reply_message); + return NULL; + } + _reply = g_dbus_message_get_body (_reply_message); + g_variant_iter_init (&_reply_iter, _reply); + _fd_list = g_dbus_message_get_unix_fd_list (_reply_message); + if (_fd_list) { + g_variant_iter_next (&_reply_iter, "h", &_fd_index); + _fd = g_unix_fd_list_get (_fd_list, _fd_index, error); + if (_fd >= 0) { + _vala_j = (GUnixInputStream *) g_unix_input_stream_new (_fd, TRUE); + } + } else { + g_set_error_literal (error, G_IO_ERROR, G_IO_ERROR_FAILED, "FD List is NULL"); + } + *j = _vala_j; + if (error && (*error)) { + g_object_unref (_reply_message); + return NULL; + } + _fd_list = g_dbus_message_get_unix_fd_list (_reply_message); + if (_fd_list) { + g_variant_iter_next (&_reply_iter, "h", &_fd_index); + _fd = g_unix_fd_list_get (_fd_list, _fd_index, error); + if (_fd >= 0) { + _result = (GUnixInputStream *) g_unix_input_stream_new (_fd, TRUE); + } + } else { + g_set_error_literal (error, G_IO_ERROR, G_IO_ERROR_FAILED, "FD List is NULL"); + } + if (error && (*error)) { + g_object_unref (_reply_message); + return NULL; + } + g_object_unref (_reply_message); + return _result; +} + +static void +test_proxy_test_interface_init (TestIface* iface) +{ + iface->test_in = test_proxy_test_in; +} + +static void +_dbus_test_test_in (Test* self, + GVariant* _parameters_, + GDBusMethodInvocation* invocation) +{ + GUnixFDList* _fd_list; + GError* error = NULL; + GVariantIter _arguments_iter; + gint _fd_index = 0; + gint _fd; + GUnixInputStream* i = NULL; + GDBusMessage* _reply_message = NULL; + GVariant* _reply; + GVariantBuilder _reply_builder; + GUnixInputStream* j = NULL; + GUnixInputStream* result; + g_variant_iter_init (&_arguments_iter, _parameters_); + _fd_list = g_dbus_message_get_unix_fd_list (g_dbus_method_invocation_get_message (invocation)); + if (_fd_list) { + g_variant_iter_next (&_arguments_iter, "h", &_fd_index); + _fd = g_unix_fd_list_get (_fd_list, _fd_index, &error); + if (_fd >= 0) { + i = (GUnixInputStream *) g_unix_input_stream_new (_fd, TRUE); + } + } else { + g_set_error_literal (&error, G_IO_ERROR, G_IO_ERROR_FAILED, "FD List is NULL"); + } + if (error) { + g_dbus_method_invocation_return_gerror (invocation, error); + g_error_free (error); + goto _error; + } + result = test_test_in (self, i, &j, &error); + if (error) { + g_dbus_method_invocation_return_gerror (invocation, error); + g_error_free (error); + goto _error; + } + _reply_message = g_dbus_message_new_method_reply (g_dbus_method_invocation_get_message (invocation)); + g_variant_builder_init (&_reply_builder, G_VARIANT_TYPE_TUPLE); + _fd_list = g_unix_fd_list_new (); + g_variant_builder_add (&_reply_builder, "h", g_unix_fd_list_append (_fd_list, g_unix_input_stream_get_fd (j), NULL)); + g_variant_builder_add (&_reply_builder, "h", g_unix_fd_list_append (_fd_list, g_unix_input_stream_get_fd (result), NULL)); + _g_object_unref0 (result); + _reply = g_variant_builder_end (&_reply_builder); + g_dbus_message_set_body (_reply_message, _reply); + g_dbus_message_set_unix_fd_list (_reply_message, _fd_list); + g_object_unref (_fd_list); + g_dbus_connection_send_message (g_dbus_method_invocation_get_connection (invocation), _reply_message, G_DBUS_SEND_MESSAGE_FLAGS_NONE, NULL, NULL); + g_object_unref (invocation); + g_object_unref (_reply_message); + _error: + _g_object_unref0 (i); + _g_object_unref0 (j); + ; +} + +static void +test_dbus_interface_method_call (GDBusConnection* connection, + const gchar* sender, + const gchar* object_path, + const gchar* interface_name, + const gchar* method_name, + GVariant* parameters, + GDBusMethodInvocation* invocation, + gpointer user_data) +{ + gpointer* data; + gpointer object; + data = user_data; + object = data[0]; + if (strcmp (method_name, "TestIn") == 0) { + _dbus_test_test_in (object, parameters, invocation); + } else { + g_object_unref (invocation); + } +} + +static GVariant* +test_dbus_interface_get_property (GDBusConnection* connection, + const gchar* sender, + const gchar* object_path, + const gchar* interface_name, + const gchar* property_name, + GError** error, + gpointer user_data) +{ + gpointer* data; + gpointer object; + data = user_data; + object = data[0]; + return NULL; +} + +static gboolean +test_dbus_interface_set_property (GDBusConnection* connection, + const gchar* sender, + const gchar* object_path, + const gchar* interface_name, + const gchar* property_name, + GVariant* value, + GError** error, + gpointer user_data) +{ + gpointer* data; + gpointer object; + data = user_data; + object = data[0]; + return FALSE; +} + +guint +test_register_object (gpointer object, + GDBusConnection* connection, + const gchar* path, + GError** error) +{ + guint result; + gpointer *data; + data = g_new (gpointer, 3); + data[0] = g_object_ref (object); + data[1] = g_object_ref (connection); + data[2] = g_strdup (path); + result = g_dbus_connection_register_object (connection, path, (GDBusInterfaceInfo *) (&_test_dbus_interface_info), &_test_dbus_interface_vtable, data, _test_unregister_object, error); + if (!result) { + return 0; + } + return result; +} + +static void +_test_unregister_object (gpointer user_data) +{ + gpointer* data; + data = user_data; + g_object_unref (data[0]); + g_object_unref (data[1]); + g_free (data[2]); + g_free (data); +} + +static void +_vala_main (void) +{ + Test* test = NULL; + Test* _tmp0_; + guint8* buffer = NULL; + guint8* _tmp1_; + gint buffer_length1; + gint _buffer_size_; + gint* pipe1 = NULL; + gint* _tmp2_; + gint pipe1_length1; + gint _pipe1_size_; + gint* _tmp3_; + gint _tmp3__length1; + guint8* _tmp4_; + gint _tmp4__length1; + gint* _tmp5_; + gint _tmp5__length1; + gint _tmp6_; + guint8* _tmp7_; + gint _tmp7__length1; + gint* _tmp8_; + gint _tmp8__length1; + gint _tmp9_; + GUnixInputStream* j = NULL; + GUnixInputStream* k = NULL; + GUnixInputStream* _tmp10_ = NULL; + Test* _tmp11_; + gint* _tmp12_; + gint _tmp12__length1; + gint _tmp13_; + GUnixInputStream* _tmp14_; + GUnixInputStream* _tmp15_; + GUnixInputStream* _tmp16_ = NULL; + GUnixInputStream* _tmp17_; + GUnixInputStream* _tmp18_; + GUnixInputStream* _tmp19_; + gssize _tmp20_ = 0L; + GUnixInputStream* _tmp21_; + guint8* _tmp22_; + gint _tmp22__length1; + guint8* _tmp23_; + gint _tmp23__length1; + guint8 _tmp24_; + gssize _tmp25_ = 0L; + GUnixInputStream* _tmp26_; + guint8* _tmp27_; + gint _tmp27__length1; + guint8* _tmp28_; + gint _tmp28__length1; + guint8 _tmp29_; + GError* _inner_error0_ = NULL; + _tmp0_ = (Test*) g_initable_new (TYPE_TEST_PROXY, NULL, &_inner_error0_, "g-flags", 0, "g-name", "org.example.Test", "g-bus-type", G_BUS_TYPE_SESSION, "g-object-path", "/org/example/test", "g-interface-name", "org.example.Test", NULL); + test = (Test*) _tmp0_; + if (G_UNLIKELY (_inner_error0_ != NULL)) { + g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error0_->message, g_quark_to_string (_inner_error0_->domain), _inner_error0_->code); + g_clear_error (&_inner_error0_); + return; + } + _tmp1_ = g_new0 (guint8, 1); + buffer = _tmp1_; + buffer_length1 = 1; + _buffer_size_ = buffer_length1; + _tmp2_ = g_new0 (gint, 2); + pipe1 = _tmp2_; + pipe1_length1 = 2; + _pipe1_size_ = pipe1_length1; + _tmp3_ = pipe1; + _tmp3__length1 = pipe1_length1; + _vala_assert (pipe (_tmp3_) == 0, "Posix.pipe (pipe1) == 0"); + _tmp4_ = buffer; + _tmp4__length1 = buffer_length1; + _tmp4_[0] = (guint8) 42; + _tmp5_ = pipe1; + _tmp5__length1 = pipe1_length1; + _tmp6_ = _tmp5_[1]; + _tmp7_ = buffer; + _tmp7__length1 = buffer_length1; + _vala_assert (write (_tmp6_, _tmp7_, (gsize) 1) == ((gssize) 1), "Posix.write (pipe1[1], buffer, 1) == 1"); + _tmp8_ = pipe1; + _tmp8__length1 = pipe1_length1; + _tmp9_ = _tmp8_[1]; + close (_tmp9_); + _tmp11_ = test; + _tmp12_ = pipe1; + _tmp12__length1 = pipe1_length1; + _tmp13_ = _tmp12_[0]; + _tmp14_ = (GUnixInputStream*) g_unix_input_stream_new (_tmp13_, TRUE); + _tmp15_ = _tmp14_; + _tmp17_ = test_test_in (_tmp11_, _tmp15_, &_tmp16_, &_inner_error0_); + _g_object_unref0 (j); + j = _tmp16_; + _tmp18_ = _tmp17_; + _g_object_unref0 (_tmp15_); + _tmp10_ = _tmp18_; + if (G_UNLIKELY (_inner_error0_ != NULL)) { + _g_object_unref0 (k); + _g_object_unref0 (j); + pipe1 = (g_free (pipe1), NULL); + buffer = (g_free (buffer), NULL); + _g_object_unref0 (test); + g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error0_->message, g_quark_to_string (_inner_error0_->domain), _inner_error0_->code); + g_clear_error (&_inner_error0_); + return; + } + _tmp19_ = _tmp10_; + _tmp10_ = NULL; + _g_object_unref0 (k); + k = _tmp19_; + _tmp21_ = j; + _tmp22_ = buffer; + _tmp22__length1 = buffer_length1; + _tmp20_ = g_input_stream_read (G_TYPE_CHECK_INSTANCE_CAST (_tmp21_, g_input_stream_get_type (), GInputStream), _tmp22_, (gsize) _tmp22__length1, NULL, &_inner_error0_); + if (G_UNLIKELY (_inner_error0_ != NULL)) { + _g_object_unref0 (_tmp10_); + _g_object_unref0 (k); + _g_object_unref0 (j); + pipe1 = (g_free (pipe1), NULL); + buffer = (g_free (buffer), NULL); + _g_object_unref0 (test); + g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error0_->message, g_quark_to_string (_inner_error0_->domain), _inner_error0_->code); + g_clear_error (&_inner_error0_); + return; + } + _vala_assert (_tmp20_ == ((gssize) 1), "j.read (buffer) == 1"); + _tmp23_ = buffer; + _tmp23__length1 = buffer_length1; + _tmp24_ = _tmp23_[0]; + _vala_assert (((gint) _tmp24_) == 23, "buffer[0] == 23"); + _tmp26_ = k; + _tmp27_ = buffer; + _tmp27__length1 = buffer_length1; + _tmp25_ = g_input_stream_read (G_TYPE_CHECK_INSTANCE_CAST (_tmp26_, g_input_stream_get_type (), GInputStream), _tmp27_, (gsize) _tmp27__length1, NULL, &_inner_error0_); + if (G_UNLIKELY (_inner_error0_ != NULL)) { + _g_object_unref0 (_tmp10_); + _g_object_unref0 (k); + _g_object_unref0 (j); + pipe1 = (g_free (pipe1), NULL); + buffer = (g_free (buffer), NULL); + _g_object_unref0 (test); + g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error0_->message, g_quark_to_string (_inner_error0_->domain), _inner_error0_->code); + g_clear_error (&_inner_error0_); + return; + } + _vala_assert (_tmp25_ == ((gssize) 1), "k.read (buffer) == 1"); + _tmp28_ = buffer; + _tmp28__length1 = buffer_length1; + _tmp29_ = _tmp28_[0]; + _vala_assert (((gint) _tmp29_) == 11, "buffer[0] == 11"); + _g_object_unref0 (_tmp10_); + _g_object_unref0 (k); + _g_object_unref0 (j); + pipe1 = (g_free (pipe1), NULL); + buffer = (g_free (buffer), NULL); + _g_object_unref0 (test); +} + +int +main (int argc, + char ** argv) +{ + _vala_main (); + return 0; +} + diff --git a/tests/dbus/filedescriptor_server.c-expected b/tests/dbus/filedescriptor_server.c-expected new file mode 100644 index 000000000..86a6b71c3 --- /dev/null +++ b/tests/dbus/filedescriptor_server.c-expected @@ -0,0 +1,585 @@ +/* dbus_filedescriptor_server.c generated by valac, the Vala compiler + * generated from dbus_filedescriptor_server.vala, do not modify */ + +#include <glib-object.h> +#include <gio/gio.h> +#include <gio/gunixinputstream.h> +#include <glib.h> +#include <unistd.h> +#include <string.h> +#include <gio/gunixfdlist.h> +#include <stdlib.h> + +#if !defined(VALA_EXTERN) +#if defined(_MSC_VER) +#define VALA_EXTERN __declspec(dllexport) extern +#elif __GNUC__ >= 4 +#define VALA_EXTERN __attribute__((visibility("default"))) extern +#else +#define VALA_EXTERN extern +#endif +#endif + +#define TYPE_TEST (test_get_type ()) +#define TEST(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TYPE_TEST, Test)) +#define TEST_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), TYPE_TEST, TestClass)) +#define IS_TEST(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TYPE_TEST)) +#define IS_TEST_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), TYPE_TEST)) +#define TEST_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), TYPE_TEST, TestClass)) + +typedef struct _Test Test; +typedef struct _TestClass TestClass; +typedef struct _TestPrivate TestPrivate; +enum { + TEST_0_PROPERTY, + TEST_NUM_PROPERTIES +}; +static GParamSpec* test_properties[TEST_NUM_PROPERTIES]; +#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL))) +#define _g_variant_unref0(var) ((var == NULL) ? NULL : (var = (g_variant_unref (var), NULL))) +#define _g_main_loop_unref0(var) ((var == NULL) ? NULL : (var = (g_main_loop_unref (var), NULL))) +#define _vala_assert(expr, msg) if G_LIKELY (expr) ; else g_assertion_message_expr (G_LOG_DOMAIN, __FILE__, __LINE__, G_STRFUNC, msg); +#define _vala_return_if_fail(expr, msg) if G_LIKELY (expr) ; else { g_return_if_fail_warning (G_LOG_DOMAIN, G_STRFUNC, msg); return; } +#define _vala_return_val_if_fail(expr, msg, val) if G_LIKELY (expr) ; else { g_return_if_fail_warning (G_LOG_DOMAIN, G_STRFUNC, msg); return val; } +#define _vala_warn_if_fail(expr, msg) if G_LIKELY (expr) ; else g_warn_message (G_LOG_DOMAIN, __FILE__, __LINE__, G_STRFUNC, msg); + +struct _Test { + GObject parent_instance; + TestPrivate * priv; +}; + +struct _TestClass { + GObjectClass parent_class; +}; + +static gpointer test_parent_class = NULL; +VALA_EXTERN GMainLoop* main_loop; +GMainLoop* main_loop = NULL; + +VALA_EXTERN GType test_get_type (void) G_GNUC_CONST ; +G_DEFINE_AUTOPTR_CLEANUP_FUNC (Test, g_object_unref) +VALA_EXTERN guint test_register_object (void* object, + GDBusConnection* connection, + const gchar* path, + GError** error); +VALA_EXTERN GUnixInputStream* test_test_in (Test* self, + GUnixInputStream* i, + GUnixInputStream* * j, + GError** error); +VALA_EXTERN Test* test_new (void); +VALA_EXTERN Test* test_construct (GType object_type); +static GType test_get_type_once (void); +static void _dbus_test_test_in (Test* self, + GVariant* _parameters_, + GDBusMethodInvocation* invocation); +static void test_dbus_interface_method_call (GDBusConnection* connection, + const gchar* sender, + const gchar* object_path, + const gchar* interface_name, + const gchar* method_name, + GVariant* parameters, + GDBusMethodInvocation* invocation, + gpointer user_data); +static GVariant* test_dbus_interface_get_property (GDBusConnection* connection, + const gchar* sender, + const gchar* object_path, + const gchar* interface_name, + const gchar* property_name, + GError** error, + gpointer user_data); +static gboolean test_dbus_interface_set_property (GDBusConnection* connection, + const gchar* sender, + const gchar* object_path, + const gchar* interface_name, + const gchar* property_name, + GVariant* value, + GError** error, + gpointer user_data); +static void _test_unregister_object (gpointer user_data); +VALA_EXTERN void client_exit (GPid pid, + gint status); +static void _vala_main (void); +static guint _variant_get1 (GVariant* value); +static void _client_exit_gchild_watch_func (GPid pid, + gint wait_status, + gpointer self); +static void _vala_array_destroy (gpointer array, + gssize array_length, + GDestroyNotify destroy_func); +static void _vala_array_free (gpointer array, + gssize array_length, + GDestroyNotify destroy_func); + +static const GDBusArgInfo _test_dbus_arg_info_test_in_i = {-1, "i", "h", NULL}; +static const GDBusArgInfo _test_dbus_arg_info_test_in_j = {-1, "j", "h", NULL}; +static const GDBusArgInfo _test_dbus_arg_info_test_in_result = {-1, "result", "h", NULL}; +static const GDBusArgInfo * const _test_dbus_arg_info_test_in_in[] = {&_test_dbus_arg_info_test_in_i, NULL}; +static const GDBusArgInfo * const _test_dbus_arg_info_test_in_out[] = {&_test_dbus_arg_info_test_in_j, &_test_dbus_arg_info_test_in_result, NULL}; +static const GDBusMethodInfo _test_dbus_method_info_test_in = {-1, "TestIn", (GDBusArgInfo **) (&_test_dbus_arg_info_test_in_in), (GDBusArgInfo **) (&_test_dbus_arg_info_test_in_out), NULL}; +static const GDBusMethodInfo * const _test_dbus_method_info[] = {&_test_dbus_method_info_test_in, NULL}; +static const GDBusSignalInfo * const _test_dbus_signal_info[] = {NULL}; +static const GDBusPropertyInfo * const _test_dbus_property_info[] = {NULL}; +static const GDBusInterfaceInfo _test_dbus_interface_info = {-1, "org.example.Test", (GDBusMethodInfo **) (&_test_dbus_method_info), (GDBusSignalInfo **) (&_test_dbus_signal_info), (GDBusPropertyInfo **) (&_test_dbus_property_info), NULL}; +static const GDBusInterfaceVTable _test_dbus_interface_vtable = {test_dbus_interface_method_call, test_dbus_interface_get_property, test_dbus_interface_set_property}; + +GUnixInputStream* +test_test_in (Test* self, + GUnixInputStream* i, + GUnixInputStream* * j, + GError** error) +{ + GUnixInputStream* _vala_j = NULL; + guint8* buffer = NULL; + guint8* _tmp0_; + gint buffer_length1; + gint _buffer_size_; + gssize _tmp1_ = 0L; + guint8 _tmp2_; + gint* pipe1 = NULL; + gint* _tmp3_; + gint pipe1_length1; + gint _pipe1_size_; + gint* _tmp4_; + gint _tmp4__length1; + gint* _tmp5_; + gint _tmp5__length1; + gint _tmp6_; + gint* _tmp7_; + gint _tmp7__length1; + gint _tmp8_; + gint* pipe2 = NULL; + gint* _tmp9_; + gint pipe2_length1; + gint _pipe2_size_; + gint* _tmp10_; + gint _tmp10__length1; + gint* _tmp11_; + gint _tmp11__length1; + gint _tmp12_; + gint* _tmp13_; + gint _tmp13__length1; + gint _tmp14_; + gint* _tmp15_; + gint _tmp15__length1; + gint _tmp16_; + GUnixInputStream* _tmp17_; + gint* _tmp18_; + gint _tmp18__length1; + gint _tmp19_; + GUnixInputStream* _tmp20_; + GError* _inner_error0_ = NULL; + GUnixInputStream* result = NULL; + g_return_val_if_fail (IS_TEST (self), NULL); + g_return_val_if_fail (G_TYPE_CHECK_INSTANCE_TYPE (i, G_TYPE_UNIX_INPUT_STREAM), NULL); + _tmp0_ = g_new0 (guint8, 1); + buffer = _tmp0_; + buffer_length1 = 1; + _buffer_size_ = buffer_length1; + _tmp1_ = g_input_stream_read (G_TYPE_CHECK_INSTANCE_CAST (i, g_input_stream_get_type (), GInputStream), buffer, (gsize) buffer_length1, NULL, &_inner_error0_); + if (G_UNLIKELY (_inner_error0_ != NULL)) { + if (_inner_error0_->domain == G_IO_ERROR) { + g_propagate_error (error, _inner_error0_); + buffer = (g_free (buffer), NULL); + _g_object_unref0 (_vala_j); + return NULL; + } else { + buffer = (g_free (buffer), NULL); + _g_object_unref0 (_vala_j); + g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error0_->message, g_quark_to_string (_inner_error0_->domain), _inner_error0_->code); + g_clear_error (&_inner_error0_); + return NULL; + } + } + _vala_assert (_tmp1_ == ((gssize) 1), "i.read (buffer) == 1"); + _tmp2_ = buffer[0]; + _vala_assert (((gint) _tmp2_) == 42, "buffer[0] == 42"); + _tmp3_ = g_new0 (gint, 2); + pipe1 = _tmp3_; + pipe1_length1 = 2; + _pipe1_size_ = pipe1_length1; + _tmp4_ = pipe1; + _tmp4__length1 = pipe1_length1; + _vala_assert (pipe (_tmp4_) == 0, "Posix.pipe (pipe1) == 0"); + buffer[0] = (guint8) 23; + _tmp5_ = pipe1; + _tmp5__length1 = pipe1_length1; + _tmp6_ = _tmp5_[1]; + _vala_assert (write (_tmp6_, buffer, (gsize) 1) == ((gssize) 1), "Posix.write (pipe1[1], buffer, 1) == 1"); + _tmp7_ = pipe1; + _tmp7__length1 = pipe1_length1; + _tmp8_ = _tmp7_[1]; + close (_tmp8_); + _tmp9_ = g_new0 (gint, 2); + pipe2 = _tmp9_; + pipe2_length1 = 2; + _pipe2_size_ = pipe2_length1; + _tmp10_ = pipe2; + _tmp10__length1 = pipe2_length1; + _vala_assert (pipe (_tmp10_) == 0, "Posix.pipe (pipe2) == 0"); + buffer[0] = (guint8) 11; + _tmp11_ = pipe2; + _tmp11__length1 = pipe2_length1; + _tmp12_ = _tmp11_[1]; + _vala_assert (write (_tmp12_, buffer, (gsize) 1) == ((gssize) 1), "Posix.write (pipe2[1], buffer, 1) == 1"); + _tmp13_ = pipe2; + _tmp13__length1 = pipe2_length1; + _tmp14_ = _tmp13_[1]; + close (_tmp14_); + _tmp15_ = pipe1; + _tmp15__length1 = pipe1_length1; + _tmp16_ = _tmp15_[0]; + _tmp17_ = (GUnixInputStream*) g_unix_input_stream_new (_tmp16_, TRUE); + _g_object_unref0 (_vala_j); + _vala_j = _tmp17_; + _tmp18_ = pipe2; + _tmp18__length1 = pipe2_length1; + _tmp19_ = _tmp18_[0]; + _tmp20_ = (GUnixInputStream*) g_unix_input_stream_new (_tmp19_, TRUE); + result = _tmp20_; + pipe2 = (g_free (pipe2), NULL); + pipe1 = (g_free (pipe1), NULL); + buffer = (g_free (buffer), NULL); + if (j) { + *j = _vala_j; + } else { + _g_object_unref0 (_vala_j); + } + return result; +} + +Test* +test_construct (GType object_type) +{ + Test * self = NULL; + self = (Test*) g_object_new (object_type, NULL); + return self; +} + +Test* +test_new (void) +{ + return test_construct (TYPE_TEST); +} + +static void +test_class_init (TestClass * klass, + gpointer klass_data) +{ + test_parent_class = g_type_class_peek_parent (klass); +} + +static void +test_instance_init (Test * self, + gpointer klass) +{ +} + +static GType +test_get_type_once (void) +{ + static const GTypeInfo g_define_type_info = { sizeof (TestClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) test_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (Test), 0, (GInstanceInitFunc) test_instance_init, NULL }; + GType test_type_id; + test_type_id = g_type_register_static (G_TYPE_OBJECT, "Test", &g_define_type_info, 0); + g_type_set_qdata (test_type_id, g_quark_from_static_string ("vala-dbus-register-object"), (void*) test_register_object); + return test_type_id; +} + +GType +test_get_type (void) +{ + static volatile gsize test_type_id__volatile = 0; + if (g_once_init_enter (&test_type_id__volatile)) { + GType test_type_id; + test_type_id = test_get_type_once (); + g_once_init_leave (&test_type_id__volatile, test_type_id); + } + return test_type_id__volatile; +} + +static void +_dbus_test_test_in (Test* self, + GVariant* _parameters_, + GDBusMethodInvocation* invocation) +{ + GUnixFDList* _fd_list; + GError* error = NULL; + GVariantIter _arguments_iter; + gint _fd_index = 0; + gint _fd; + GUnixInputStream* i = NULL; + GDBusMessage* _reply_message = NULL; + GVariant* _reply; + GVariantBuilder _reply_builder; + GUnixInputStream* j = NULL; + GUnixInputStream* result; + g_variant_iter_init (&_arguments_iter, _parameters_); + _fd_list = g_dbus_message_get_unix_fd_list (g_dbus_method_invocation_get_message (invocation)); + if (_fd_list) { + g_variant_iter_next (&_arguments_iter, "h", &_fd_index); + _fd = g_unix_fd_list_get (_fd_list, _fd_index, &error); + if (_fd >= 0) { + i = (GUnixInputStream *) g_unix_input_stream_new (_fd, TRUE); + } + } else { + g_set_error_literal (&error, G_IO_ERROR, G_IO_ERROR_FAILED, "FD List is NULL"); + } + if (error) { + g_dbus_method_invocation_return_gerror (invocation, error); + g_error_free (error); + goto _error; + } + result = test_test_in (self, i, &j, &error); + if (error) { + g_dbus_method_invocation_return_gerror (invocation, error); + g_error_free (error); + goto _error; + } + _reply_message = g_dbus_message_new_method_reply (g_dbus_method_invocation_get_message (invocation)); + g_variant_builder_init (&_reply_builder, G_VARIANT_TYPE_TUPLE); + _fd_list = g_unix_fd_list_new (); + g_variant_builder_add (&_reply_builder, "h", g_unix_fd_list_append (_fd_list, g_unix_input_stream_get_fd (j), NULL)); + g_variant_builder_add (&_reply_builder, "h", g_unix_fd_list_append (_fd_list, g_unix_input_stream_get_fd (result), NULL)); + _g_object_unref0 (result); + _reply = g_variant_builder_end (&_reply_builder); + g_dbus_message_set_body (_reply_message, _reply); + g_dbus_message_set_unix_fd_list (_reply_message, _fd_list); + g_object_unref (_fd_list); + g_dbus_connection_send_message (g_dbus_method_invocation_get_connection (invocation), _reply_message, G_DBUS_SEND_MESSAGE_FLAGS_NONE, NULL, NULL); + g_object_unref (invocation); + g_object_unref (_reply_message); + _error: + _g_object_unref0 (i); + _g_object_unref0 (j); + ; +} + +static void +test_dbus_interface_method_call (GDBusConnection* connection, + const gchar* sender, + const gchar* object_path, + const gchar* interface_name, + const gchar* method_name, + GVariant* parameters, + GDBusMethodInvocation* invocation, + gpointer user_data) +{ + gpointer* data; + gpointer object; + data = user_data; + object = data[0]; + if (strcmp (method_name, "TestIn") == 0) { + _dbus_test_test_in (object, parameters, invocation); + } else { + g_object_unref (invocation); + } +} + +static GVariant* +test_dbus_interface_get_property (GDBusConnection* connection, + const gchar* sender, + const gchar* object_path, + const gchar* interface_name, + const gchar* property_name, + GError** error, + gpointer user_data) +{ + gpointer* data; + gpointer object; + data = user_data; + object = data[0]; + return NULL; +} + +static gboolean +test_dbus_interface_set_property (GDBusConnection* connection, + const gchar* sender, + const gchar* object_path, + const gchar* interface_name, + const gchar* property_name, + GVariant* value, + GError** error, + gpointer user_data) +{ + gpointer* data; + gpointer object; + data = user_data; + object = data[0]; + return FALSE; +} + +guint +test_register_object (gpointer object, + GDBusConnection* connection, + const gchar* path, + GError** error) +{ + guint result; + gpointer *data; + data = g_new (gpointer, 3); + data[0] = g_object_ref (object); + data[1] = g_object_ref (connection); + data[2] = g_strdup (path); + result = g_dbus_connection_register_object (connection, path, (GDBusInterfaceInfo *) (&_test_dbus_interface_info), &_test_dbus_interface_vtable, data, _test_unregister_object, error); + if (!result) { + return 0; + } + return result; +} + +static void +_test_unregister_object (gpointer user_data) +{ + gpointer* data; + data = user_data; + g_object_unref (data[0]); + g_object_unref (data[1]); + g_free (data[2]); + g_free (data); +} + +void +client_exit (GPid pid, + gint status) +{ + GMainLoop* _tmp0_; + _vala_assert (status == 0, "status == 0"); + _tmp0_ = main_loop; + g_main_loop_quit (_tmp0_); +} + +static guint +_variant_get1 (GVariant* value) +{ + return g_variant_get_uint32 (value); +} + +static void +_client_exit_gchild_watch_func (GPid pid, + gint wait_status, + gpointer self) +{ + client_exit (pid, wait_status); +} + +static void +_vala_main (void) +{ + GDBusConnection* conn = NULL; + GDBusConnection* _tmp0_; + GDBusConnection* _tmp1_; + Test* _tmp2_; + Test* _tmp3_; + GVariant* request_result = NULL; + GDBusConnection* _tmp4_; + GVariant* _tmp5_; + GVariant* _tmp6_; + GVariant* _tmp7_; + GVariant* _tmp8_; + GVariant* _tmp9_; + GVariant* _tmp10_; + GVariant* _tmp11_; + guint _tmp12_; + GPid client_pid = 0; + gchar* _tmp13_; + gchar** _tmp14_; + gchar** _tmp15_; + gint _tmp15__length1; + GPid _tmp16_ = 0; + GMainLoop* _tmp17_; + GMainLoop* _tmp18_; + GError* _inner_error0_ = NULL; + _tmp0_ = g_bus_get_sync (G_BUS_TYPE_SESSION, NULL, &_inner_error0_); + conn = _tmp0_; + if (G_UNLIKELY (_inner_error0_ != NULL)) { + g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error0_->message, g_quark_to_string (_inner_error0_->domain), _inner_error0_->code); + g_clear_error (&_inner_error0_); + return; + } + _tmp1_ = conn; + _tmp2_ = test_new (); + _tmp3_ = _tmp2_; + test_register_object (_tmp3_, _tmp1_, "/org/example/test", &_inner_error0_); + _g_object_unref0 (_tmp3_); + if (G_UNLIKELY (_inner_error0_ != NULL)) { + _g_object_unref0 (conn); + g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error0_->message, g_quark_to_string (_inner_error0_->domain), _inner_error0_->code); + g_clear_error (&_inner_error0_); + return; + } + _tmp4_ = conn; + _tmp5_ = g_variant_new ("(su)", "org.example.Test", 0x4, NULL); + g_variant_ref_sink (_tmp5_); + _tmp6_ = _tmp5_; + _tmp7_ = g_dbus_connection_call_sync (_tmp4_, "org.freedesktop.DBus", "/org/freedesktop/DBus", "org.freedesktop.DBus", "RequestName", _tmp6_, NULL, 0, -1, NULL, &_inner_error0_); + _tmp8_ = _tmp7_; + _g_variant_unref0 (_tmp6_); + request_result = _tmp8_; + if (G_UNLIKELY (_inner_error0_ != NULL)) { + _g_object_unref0 (conn); + g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error0_->message, g_quark_to_string (_inner_error0_->domain), _inner_error0_->code); + g_clear_error (&_inner_error0_); + return; + } + _tmp9_ = request_result; + _tmp10_ = g_variant_get_child_value (_tmp9_, (gsize) 0); + _tmp11_ = _tmp10_; + _tmp12_ = _variant_get1 (_tmp11_); + _vala_assert (_tmp12_ == ((guint) 1), "(uint) request_result.get_child_value (0) == 1"); + _g_variant_unref0 (_tmp11_); + _tmp13_ = g_strdup ("dbus_filedescriptor_client"); + _tmp14_ = g_new0 (gchar*, 1 + 1); + _tmp14_[0] = _tmp13_; + _tmp15_ = _tmp14_; + _tmp15__length1 = 1; + g_spawn_async (NULL, _tmp15_, NULL, G_SPAWN_DO_NOT_REAP_CHILD, NULL, NULL, &_tmp16_, &_inner_error0_); + client_pid = _tmp16_; + _tmp15_ = (_vala_array_free (_tmp15_, _tmp15__length1, (GDestroyNotify) g_free), NULL); + if (G_UNLIKELY (_inner_error0_ != NULL)) { + _g_variant_unref0 (request_result); + _g_object_unref0 (conn); + g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error0_->message, g_quark_to_string (_inner_error0_->domain), _inner_error0_->code); + g_clear_error (&_inner_error0_); + return; + } + g_child_watch_add_full (G_PRIORITY_DEFAULT_IDLE, client_pid, _client_exit_gchild_watch_func, NULL, NULL); + _tmp17_ = g_main_loop_new (NULL, FALSE); + _g_main_loop_unref0 (main_loop); + main_loop = _tmp17_; + _tmp18_ = main_loop; + g_main_loop_run (_tmp18_); + _g_variant_unref0 (request_result); + _g_object_unref0 (conn); +} + +int +main (int argc, + char ** argv) +{ + _vala_main (); + return 0; +} + +static void +_vala_array_destroy (gpointer array, + gssize array_length, + GDestroyNotify destroy_func) +{ + if ((array != NULL) && (destroy_func != NULL)) { + gssize i; + for (i = 0; i < array_length; i = i + 1) { + if (((gpointer*) array)[i] != NULL) { + destroy_func (((gpointer*) array)[i]); + } + } + } +} + +static void +_vala_array_free (gpointer array, + gssize array_length, + GDestroyNotify destroy_func) +{ + _vala_array_destroy (array, array_length, destroy_func); + g_free (array); +} + diff --git a/tests/dbus/generics_client.c-expected b/tests/dbus/generics_client.c-expected new file mode 100644 index 000000000..eaada2f07 --- /dev/null +++ b/tests/dbus/generics_client.c-expected @@ -0,0 +1,397 @@ +/* dbus_generics_client.c generated by valac, the Vala compiler + * generated from dbus_generics_client.vala, do not modify */ + +#include <glib-object.h> +#include <gio/gio.h> +#include <glib.h> +#include <string.h> +#include <stdlib.h> + +#if !defined(VALA_EXTERN) +#if defined(_MSC_VER) +#define VALA_EXTERN __declspec(dllexport) extern +#elif __GNUC__ >= 4 +#define VALA_EXTERN __attribute__((visibility("default"))) extern +#else +#define VALA_EXTERN extern +#endif +#endif + +#define TYPE_TEST (test_get_type ()) +#define TEST(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TYPE_TEST, Test)) +#define IS_TEST(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TYPE_TEST)) +#define TEST_GET_INTERFACE(obj) (G_TYPE_INSTANCE_GET_INTERFACE ((obj), TYPE_TEST, TestIface)) + +typedef struct _Test Test; +typedef struct _TestIface TestIface; + +#define TYPE_TEST_PROXY (test_proxy_get_type ()) +typedef GDBusProxy TestProxy; +typedef GDBusProxyClass TestProxyClass; +#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL))) +#define _vala_assert(expr, msg) if G_LIKELY (expr) ; else g_assertion_message_expr (G_LOG_DOMAIN, __FILE__, __LINE__, G_STRFUNC, msg); +#define _vala_return_if_fail(expr, msg) if G_LIKELY (expr) ; else { g_return_if_fail_warning (G_LOG_DOMAIN, G_STRFUNC, msg); return; } +#define _vala_return_val_if_fail(expr, msg, val) if G_LIKELY (expr) ; else { g_return_if_fail_warning (G_LOG_DOMAIN, G_STRFUNC, msg); return val; } +#define _vala_warn_if_fail(expr, msg) if G_LIKELY (expr) ; else g_warn_message (G_LOG_DOMAIN, __FILE__, __LINE__, G_STRFUNC, msg); + +struct _TestIface { + GTypeInterface parent_iface; + gint (*get_test) (Test* self, GError** error); +}; + +VALA_EXTERN GType test_proxy_get_type (void) G_GNUC_CONST ; +VALA_EXTERN guint test_register_object (void* object, + GDBusConnection* connection, + const gchar* path, + GError** error); +VALA_EXTERN GType test_get_type (void) G_GNUC_CONST ; +VALA_EXTERN gint test_get_test (Test* self, + GError** error); +static GType test_get_type_once (void); +static void test_proxy_g_signal (GDBusProxy* proxy, + const gchar* sender_name, + const gchar* signal_name, + GVariant* parameters); +static gint test_proxy_get_test (Test* self, + GError** error); +static void test_proxy_test_interface_init (TestIface* iface); +static void _dbus_test_get_test (Test* self, + GVariant* _parameters_, + GDBusMethodInvocation* invocation); +static void test_dbus_interface_method_call (GDBusConnection* connection, + const gchar* sender, + const gchar* object_path, + const gchar* interface_name, + const gchar* method_name, + GVariant* parameters, + GDBusMethodInvocation* invocation, + gpointer user_data); +static GVariant* test_dbus_interface_get_property (GDBusConnection* connection, + const gchar* sender, + const gchar* object_path, + const gchar* interface_name, + const gchar* property_name, + GError** error, + gpointer user_data); +static gboolean test_dbus_interface_set_property (GDBusConnection* connection, + const gchar* sender, + const gchar* object_path, + const gchar* interface_name, + const gchar* property_name, + GVariant* value, + GError** error, + gpointer user_data); +static void _test_unregister_object (gpointer user_data); +VALA_EXTERN gpointer call (GType t_type, + GBoxedCopyFunc t_dup_func, + GDestroyNotify t_destroy_func, + GDBusConnection* conn, + const gchar* name, + const gchar* object_path); +static void _vala_main (void); + +static const GDBusArgInfo _test_dbus_arg_info_get_test_result = {-1, "result", "i", NULL}; +static const GDBusArgInfo * const _test_dbus_arg_info_get_test_in[] = {NULL}; +static const GDBusArgInfo * const _test_dbus_arg_info_get_test_out[] = {&_test_dbus_arg_info_get_test_result, NULL}; +static const GDBusMethodInfo _test_dbus_method_info_get_test = {-1, "GetTest", (GDBusArgInfo **) (&_test_dbus_arg_info_get_test_in), (GDBusArgInfo **) (&_test_dbus_arg_info_get_test_out), NULL}; +static const GDBusMethodInfo * const _test_dbus_method_info[] = {&_test_dbus_method_info_get_test, NULL}; +static const GDBusSignalInfo * const _test_dbus_signal_info[] = {NULL}; +static const GDBusPropertyInfo * const _test_dbus_property_info[] = {NULL}; +static const GDBusInterfaceInfo _test_dbus_interface_info = {-1, "org.example.Test", (GDBusMethodInfo **) (&_test_dbus_method_info), (GDBusSignalInfo **) (&_test_dbus_signal_info), (GDBusPropertyInfo **) (&_test_dbus_property_info), NULL}; +static const GDBusInterfaceVTable _test_dbus_interface_vtable = {test_dbus_interface_method_call, test_dbus_interface_get_property, test_dbus_interface_set_property}; + +gint +test_get_test (Test* self, + GError** error) +{ + TestIface* _iface_; + g_return_val_if_fail (IS_TEST (self), 0); + _iface_ = TEST_GET_INTERFACE (self); + if (_iface_->get_test) { + return _iface_->get_test (self, error); + } + return -1; +} + +static void +test_default_init (TestIface * iface, + gpointer iface_data) +{ +} + +static GType +test_get_type_once (void) +{ + static const GTypeInfo g_define_type_info = { sizeof (TestIface), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) test_default_init, (GClassFinalizeFunc) NULL, NULL, 0, 0, (GInstanceInitFunc) NULL, NULL }; + GType test_type_id; + test_type_id = g_type_register_static (G_TYPE_INTERFACE, "Test", &g_define_type_info, 0); + g_type_interface_add_prerequisite (test_type_id, G_TYPE_OBJECT); + g_type_set_qdata (test_type_id, g_quark_from_static_string ("vala-dbus-proxy-type"), (void*) test_proxy_get_type); + g_type_set_qdata (test_type_id, g_quark_from_static_string ("vala-dbus-interface-name"), "org.example.Test"); + g_type_set_qdata (test_type_id, g_quark_from_static_string ("vala-dbus-interface-info"), (void*) (&_test_dbus_interface_info)); + g_type_set_qdata (test_type_id, g_quark_from_static_string ("vala-dbus-register-object"), (void*) test_register_object); + return test_type_id; +} + +GType +test_get_type (void) +{ + static volatile gsize test_type_id__volatile = 0; + if (g_once_init_enter (&test_type_id__volatile)) { + GType test_type_id; + test_type_id = test_get_type_once (); + g_once_init_leave (&test_type_id__volatile, test_type_id); + } + return test_type_id__volatile; +} + +G_DEFINE_TYPE_EXTENDED (TestProxy, test_proxy, G_TYPE_DBUS_PROXY, 0, G_IMPLEMENT_INTERFACE (TYPE_TEST, test_proxy_test_interface_init) ) +static void +test_proxy_class_init (TestProxyClass* klass) +{ + G_DBUS_PROXY_CLASS (klass)->g_signal = test_proxy_g_signal; +} + +static void +test_proxy_g_signal (GDBusProxy* proxy, + const gchar* sender_name, + const gchar* signal_name, + GVariant* parameters) +{ +} + +static void +test_proxy_init (TestProxy* self) +{ + g_dbus_proxy_set_interface_info (G_DBUS_PROXY (self), (GDBusInterfaceInfo *) (&_test_dbus_interface_info)); +} + +static gint +test_proxy_get_test (Test* self, + GError** error) +{ + GDBusMessage *_message; + GVariant *_arguments; + GVariantBuilder _arguments_builder; + GDBusMessage *_reply_message; + GVariant *_reply; + GVariantIter _reply_iter; + gint _result = 0; + GVariant* _tmp2_; + G_DBUS_ERROR; + G_IO_ERROR; + _message = g_dbus_message_new_method_call (g_dbus_proxy_get_name ((GDBusProxy *) self), g_dbus_proxy_get_object_path ((GDBusProxy *) self), "org.example.Test", "GetTest"); + g_variant_builder_init (&_arguments_builder, G_VARIANT_TYPE_TUPLE); + _arguments = g_variant_builder_end (&_arguments_builder); + g_dbus_message_set_body (_message, _arguments); + _reply_message = g_dbus_connection_send_message_with_reply_sync (g_dbus_proxy_get_connection ((GDBusProxy *) self), _message, G_DBUS_SEND_MESSAGE_FLAGS_NONE, g_dbus_proxy_get_default_timeout ((GDBusProxy *) self), NULL, NULL, error); + g_object_unref (_message); + if (!_reply_message) { + gint _tmp0_ = 0; + return _tmp0_; + } + if (g_dbus_message_to_gerror (_reply_message, error)) { + gint _tmp1_ = 0; + g_object_unref (_reply_message); + return _tmp1_; + } + _reply = g_dbus_message_get_body (_reply_message); + g_variant_iter_init (&_reply_iter, _reply); + _tmp2_ = g_variant_iter_next_value (&_reply_iter); + _result = g_variant_get_int32 (_tmp2_); + g_variant_unref (_tmp2_); + g_object_unref (_reply_message); + return _result; +} + +static void +test_proxy_test_interface_init (TestIface* iface) +{ + iface->get_test = test_proxy_get_test; +} + +static void +_dbus_test_get_test (Test* self, + GVariant* _parameters_, + GDBusMethodInvocation* invocation) +{ + GError* error = NULL; + GVariantIter _arguments_iter; + GDBusMessage* _reply_message = NULL; + GVariant* _reply; + GVariantBuilder _reply_builder; + gint result; + g_variant_iter_init (&_arguments_iter, _parameters_); + result = test_get_test (self, &error); + if (error) { + g_dbus_method_invocation_return_gerror (invocation, error); + g_error_free (error); + return; + } + _reply_message = g_dbus_message_new_method_reply (g_dbus_method_invocation_get_message (invocation)); + g_variant_builder_init (&_reply_builder, G_VARIANT_TYPE_TUPLE); + g_variant_builder_add_value (&_reply_builder, g_variant_new_int32 (result)); + _reply = g_variant_builder_end (&_reply_builder); + g_dbus_message_set_body (_reply_message, _reply); + g_dbus_connection_send_message (g_dbus_method_invocation_get_connection (invocation), _reply_message, G_DBUS_SEND_MESSAGE_FLAGS_NONE, NULL, NULL); + g_object_unref (invocation); + g_object_unref (_reply_message); +} + +static void +test_dbus_interface_method_call (GDBusConnection* connection, + const gchar* sender, + const gchar* object_path, + const gchar* interface_name, + const gchar* method_name, + GVariant* parameters, + GDBusMethodInvocation* invocation, + gpointer user_data) +{ + gpointer* data; + gpointer object; + data = user_data; + object = data[0]; + if (strcmp (method_name, "GetTest") == 0) { + _dbus_test_get_test (object, parameters, invocation); + } else { + g_object_unref (invocation); + } +} + +static GVariant* +test_dbus_interface_get_property (GDBusConnection* connection, + const gchar* sender, + const gchar* object_path, + const gchar* interface_name, + const gchar* property_name, + GError** error, + gpointer user_data) +{ + gpointer* data; + gpointer object; + data = user_data; + object = data[0]; + return NULL; +} + +static gboolean +test_dbus_interface_set_property (GDBusConnection* connection, + const gchar* sender, + const gchar* object_path, + const gchar* interface_name, + const gchar* property_name, + GVariant* value, + GError** error, + gpointer user_data) +{ + gpointer* data; + gpointer object; + data = user_data; + object = data[0]; + return FALSE; +} + +guint +test_register_object (gpointer object, + GDBusConnection* connection, + const gchar* path, + GError** error) +{ + guint result; + gpointer *data; + data = g_new (gpointer, 3); + data[0] = g_object_ref (object); + data[1] = g_object_ref (connection); + data[2] = g_strdup (path); + result = g_dbus_connection_register_object (connection, path, (GDBusInterfaceInfo *) (&_test_dbus_interface_info), &_test_dbus_interface_vtable, data, _test_unregister_object, error); + if (!result) { + return 0; + } + return result; +} + +static void +_test_unregister_object (gpointer user_data) +{ + gpointer* data; + data = user_data; + g_object_unref (data[0]); + g_object_unref (data[1]); + g_free (data[2]); + g_free (data); +} + +gpointer +call (GType t_type, + GBoxedCopyFunc t_dup_func, + GDestroyNotify t_destroy_func, + GDBusConnection* conn, + const gchar* name, + const gchar* object_path) +{ + gpointer _tmp0_ = NULL; + gpointer _tmp1_; + gpointer _tmp2_; + GError* _inner_error0_ = NULL; + gpointer result = NULL; + g_return_val_if_fail (G_TYPE_CHECK_INSTANCE_TYPE (conn, g_dbus_connection_get_type ()), NULL); + g_return_val_if_fail (name != NULL, NULL); + g_return_val_if_fail (object_path != NULL, NULL); + _tmp1_ = (gpointer) g_initable_new (((GType (*) (void)) g_type_get_qdata (t_type, g_quark_from_static_string ("vala-dbus-proxy-type"))) (), NULL, &_inner_error0_, "g-flags", 0, "g-name", name, "g-connection", conn, "g-object-path", object_path, "g-interface-name", g_type_get_qdata (t_type, g_quark_from_static_string ("vala-dbus-interface-name")), NULL); + _tmp0_ = _tmp1_; + if (G_UNLIKELY (_inner_error0_ != NULL)) { + g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error0_->message, g_quark_to_string (_inner_error0_->domain), _inner_error0_->code); + g_clear_error (&_inner_error0_); + return NULL; + } + _tmp2_ = _tmp0_; + _tmp0_ = NULL; + result = _tmp2_; + ((_tmp0_ == NULL) || (t_destroy_func == NULL)) ? NULL : (_tmp0_ = (t_destroy_func (_tmp0_), NULL)); + return result; +} + +static void +_vala_main (void) +{ + GDBusConnection* conn = NULL; + GDBusConnection* _tmp0_; + Test* test = NULL; + GDBusConnection* _tmp1_; + gpointer _tmp2_; + gint i = 0; + Test* _tmp3_; + GError* _inner_error0_ = NULL; + _tmp0_ = g_bus_get_sync (G_BUS_TYPE_SESSION, NULL, &_inner_error0_); + conn = _tmp0_; + if (G_UNLIKELY (_inner_error0_ != NULL)) { + g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error0_->message, g_quark_to_string (_inner_error0_->domain), _inner_error0_->code); + g_clear_error (&_inner_error0_); + return; + } + _tmp1_ = conn; + _tmp2_ = call (TYPE_TEST, (GBoxedCopyFunc) g_object_ref, (GDestroyNotify) g_object_unref, _tmp1_, "org.example.Test", "/org/example/test"); + test = (Test*) _tmp2_; + _tmp3_ = test; + i = test_get_test (_tmp3_, &_inner_error0_); + if (G_UNLIKELY (_inner_error0_ != NULL)) { + _g_object_unref0 (test); + _g_object_unref0 (conn); + g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error0_->message, g_quark_to_string (_inner_error0_->domain), _inner_error0_->code); + g_clear_error (&_inner_error0_); + return; + } + _vala_assert (i == 23, "i == 23"); + _g_object_unref0 (test); + _g_object_unref0 (conn); +} + +int +main (int argc, + char ** argv) +{ + _vala_main (); + return 0; +} + diff --git a/tests/dbus/generics_server.c-expected b/tests/dbus/generics_server.c-expected new file mode 100644 index 000000000..92346b30d --- /dev/null +++ b/tests/dbus/generics_server.c-expected @@ -0,0 +1,478 @@ +/* dbus_generics_server.c generated by valac, the Vala compiler + * generated from dbus_generics_server.vala, do not modify */ + +#include <glib-object.h> +#include <gio/gio.h> +#include <glib.h> +#include <string.h> +#include <stdlib.h> + +#if !defined(VALA_EXTERN) +#if defined(_MSC_VER) +#define VALA_EXTERN __declspec(dllexport) extern +#elif __GNUC__ >= 4 +#define VALA_EXTERN __attribute__((visibility("default"))) extern +#else +#define VALA_EXTERN extern +#endif +#endif + +#define TYPE_TEST (test_get_type ()) +#define TEST(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TYPE_TEST, Test)) +#define TEST_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), TYPE_TEST, TestClass)) +#define IS_TEST(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TYPE_TEST)) +#define IS_TEST_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), TYPE_TEST)) +#define TEST_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), TYPE_TEST, TestClass)) + +typedef struct _Test Test; +typedef struct _TestClass TestClass; +typedef struct _TestPrivate TestPrivate; +enum { + TEST_0_PROPERTY, + TEST_NUM_PROPERTIES +}; +static GParamSpec* test_properties[TEST_NUM_PROPERTIES]; +#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL))) +#define _g_variant_unref0(var) ((var == NULL) ? NULL : (var = (g_variant_unref (var), NULL))) +#define _g_main_loop_unref0(var) ((var == NULL) ? NULL : (var = (g_main_loop_unref (var), NULL))) +#define _vala_assert(expr, msg) if G_LIKELY (expr) ; else g_assertion_message_expr (G_LOG_DOMAIN, __FILE__, __LINE__, G_STRFUNC, msg); +#define _vala_return_if_fail(expr, msg) if G_LIKELY (expr) ; else { g_return_if_fail_warning (G_LOG_DOMAIN, G_STRFUNC, msg); return; } +#define _vala_return_val_if_fail(expr, msg, val) if G_LIKELY (expr) ; else { g_return_if_fail_warning (G_LOG_DOMAIN, G_STRFUNC, msg); return val; } +#define _vala_warn_if_fail(expr, msg) if G_LIKELY (expr) ; else g_warn_message (G_LOG_DOMAIN, __FILE__, __LINE__, G_STRFUNC, msg); + +struct _Test { + GObject parent_instance; + TestPrivate * priv; +}; + +struct _TestClass { + GObjectClass parent_class; +}; + +static gpointer test_parent_class = NULL; +VALA_EXTERN GMainLoop* main_loop; +GMainLoop* main_loop = NULL; + +VALA_EXTERN GType test_get_type (void) G_GNUC_CONST ; +G_DEFINE_AUTOPTR_CLEANUP_FUNC (Test, g_object_unref) +VALA_EXTERN guint test_register_object (void* object, + GDBusConnection* connection, + const gchar* path, + GError** error); +VALA_EXTERN gint test_get_test (Test* self, + GError** error); +VALA_EXTERN Test* test_new (void); +VALA_EXTERN Test* test_construct (GType object_type); +static GType test_get_type_once (void); +static void _dbus_test_get_test (Test* self, + GVariant* _parameters_, + GDBusMethodInvocation* invocation); +static void test_dbus_interface_method_call (GDBusConnection* connection, + const gchar* sender, + const gchar* object_path, + const gchar* interface_name, + const gchar* method_name, + GVariant* parameters, + GDBusMethodInvocation* invocation, + gpointer user_data); +static GVariant* test_dbus_interface_get_property (GDBusConnection* connection, + const gchar* sender, + const gchar* object_path, + const gchar* interface_name, + const gchar* property_name, + GError** error, + gpointer user_data); +static gboolean test_dbus_interface_set_property (GDBusConnection* connection, + const gchar* sender, + const gchar* object_path, + const gchar* interface_name, + const gchar* property_name, + GVariant* value, + GError** error, + gpointer user_data); +static void _test_unregister_object (gpointer user_data); +VALA_EXTERN void client_exit (GPid pid, + gint status); +VALA_EXTERN void reg (GType t_type, + GBoxedCopyFunc t_dup_func, + GDestroyNotify t_destroy_func, + GDBusConnection* conn, + gconstpointer t, + GError** error); +static guint _vala_g_dbus_connection_register_object (GType type, + void* object, + GDBusConnection* connection, + const gchar* path, + GError** error); +static void _vala_main (void); +static guint _variant_get1 (GVariant* value); +static void _client_exit_gchild_watch_func (GPid pid, + gint wait_status, + gpointer self); +static void _vala_array_destroy (gpointer array, + gssize array_length, + GDestroyNotify destroy_func); +static void _vala_array_free (gpointer array, + gssize array_length, + GDestroyNotify destroy_func); + +static const GDBusArgInfo _test_dbus_arg_info_get_test_result = {-1, "result", "i", NULL}; +static const GDBusArgInfo * const _test_dbus_arg_info_get_test_in[] = {NULL}; +static const GDBusArgInfo * const _test_dbus_arg_info_get_test_out[] = {&_test_dbus_arg_info_get_test_result, NULL}; +static const GDBusMethodInfo _test_dbus_method_info_get_test = {-1, "GetTest", (GDBusArgInfo **) (&_test_dbus_arg_info_get_test_in), (GDBusArgInfo **) (&_test_dbus_arg_info_get_test_out), NULL}; +static const GDBusMethodInfo * const _test_dbus_method_info[] = {&_test_dbus_method_info_get_test, NULL}; +static const GDBusSignalInfo * const _test_dbus_signal_info[] = {NULL}; +static const GDBusPropertyInfo * const _test_dbus_property_info[] = {NULL}; +static const GDBusInterfaceInfo _test_dbus_interface_info = {-1, "org.example.Test", (GDBusMethodInfo **) (&_test_dbus_method_info), (GDBusSignalInfo **) (&_test_dbus_signal_info), (GDBusPropertyInfo **) (&_test_dbus_property_info), NULL}; +static const GDBusInterfaceVTable _test_dbus_interface_vtable = {test_dbus_interface_method_call, test_dbus_interface_get_property, test_dbus_interface_set_property}; + +gint +test_get_test (Test* self, + GError** error) +{ + gint result = 0; + g_return_val_if_fail (IS_TEST (self), 0); + result = 23; + return result; +} + +Test* +test_construct (GType object_type) +{ + Test * self = NULL; + self = (Test*) g_object_new (object_type, NULL); + return self; +} + +Test* +test_new (void) +{ + return test_construct (TYPE_TEST); +} + +static void +test_class_init (TestClass * klass, + gpointer klass_data) +{ + test_parent_class = g_type_class_peek_parent (klass); +} + +static void +test_instance_init (Test * self, + gpointer klass) +{ +} + +static GType +test_get_type_once (void) +{ + static const GTypeInfo g_define_type_info = { sizeof (TestClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) test_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (Test), 0, (GInstanceInitFunc) test_instance_init, NULL }; + GType test_type_id; + test_type_id = g_type_register_static (G_TYPE_OBJECT, "Test", &g_define_type_info, 0); + g_type_set_qdata (test_type_id, g_quark_from_static_string ("vala-dbus-register-object"), (void*) test_register_object); + return test_type_id; +} + +GType +test_get_type (void) +{ + static volatile gsize test_type_id__volatile = 0; + if (g_once_init_enter (&test_type_id__volatile)) { + GType test_type_id; + test_type_id = test_get_type_once (); + g_once_init_leave (&test_type_id__volatile, test_type_id); + } + return test_type_id__volatile; +} + +static void +_dbus_test_get_test (Test* self, + GVariant* _parameters_, + GDBusMethodInvocation* invocation) +{ + GError* error = NULL; + GVariantIter _arguments_iter; + GDBusMessage* _reply_message = NULL; + GVariant* _reply; + GVariantBuilder _reply_builder; + gint result; + g_variant_iter_init (&_arguments_iter, _parameters_); + result = test_get_test (self, &error); + if (error) { + g_dbus_method_invocation_return_gerror (invocation, error); + g_error_free (error); + return; + } + _reply_message = g_dbus_message_new_method_reply (g_dbus_method_invocation_get_message (invocation)); + g_variant_builder_init (&_reply_builder, G_VARIANT_TYPE_TUPLE); + g_variant_builder_add_value (&_reply_builder, g_variant_new_int32 (result)); + _reply = g_variant_builder_end (&_reply_builder); + g_dbus_message_set_body (_reply_message, _reply); + g_dbus_connection_send_message (g_dbus_method_invocation_get_connection (invocation), _reply_message, G_DBUS_SEND_MESSAGE_FLAGS_NONE, NULL, NULL); + g_object_unref (invocation); + g_object_unref (_reply_message); +} + +static void +test_dbus_interface_method_call (GDBusConnection* connection, + const gchar* sender, + const gchar* object_path, + const gchar* interface_name, + const gchar* method_name, + GVariant* parameters, + GDBusMethodInvocation* invocation, + gpointer user_data) +{ + gpointer* data; + gpointer object; + data = user_data; + object = data[0]; + if (strcmp (method_name, "GetTest") == 0) { + _dbus_test_get_test (object, parameters, invocation); + } else { + g_object_unref (invocation); + } +} + +static GVariant* +test_dbus_interface_get_property (GDBusConnection* connection, + const gchar* sender, + const gchar* object_path, + const gchar* interface_name, + const gchar* property_name, + GError** error, + gpointer user_data) +{ + gpointer* data; + gpointer object; + data = user_data; + object = data[0]; + return NULL; +} + +static gboolean +test_dbus_interface_set_property (GDBusConnection* connection, + const gchar* sender, + const gchar* object_path, + const gchar* interface_name, + const gchar* property_name, + GVariant* value, + GError** error, + gpointer user_data) +{ + gpointer* data; + gpointer object; + data = user_data; + object = data[0]; + return FALSE; +} + +guint +test_register_object (gpointer object, + GDBusConnection* connection, + const gchar* path, + GError** error) +{ + guint result; + gpointer *data; + data = g_new (gpointer, 3); + data[0] = g_object_ref (object); + data[1] = g_object_ref (connection); + data[2] = g_strdup (path); + result = g_dbus_connection_register_object (connection, path, (GDBusInterfaceInfo *) (&_test_dbus_interface_info), &_test_dbus_interface_vtable, data, _test_unregister_object, error); + if (!result) { + return 0; + } + return result; +} + +static void +_test_unregister_object (gpointer user_data) +{ + gpointer* data; + data = user_data; + g_object_unref (data[0]); + g_object_unref (data[1]); + g_free (data[2]); + g_free (data); +} + +void +client_exit (GPid pid, + gint status) +{ + GMainLoop* _tmp0_; + _vala_assert (status == 0, "status == 0"); + _tmp0_ = main_loop; + g_main_loop_quit (_tmp0_); +} + +static guint +_vala_g_dbus_connection_register_object (GType type, + void* object, + GDBusConnection* connection, + const gchar* path, + GError** error) +{ + void *func; + func = g_type_get_qdata (type, g_quark_from_static_string ("vala-dbus-register-object")); + if (!func) { + g_set_error_literal (error, G_IO_ERROR, G_IO_ERROR_FAILED, "The specified type does not support D-Bus registration"); + return 0; + } + return ((guint (*) (void *, GDBusConnection *, const gchar *, GError **)) func) (object, connection, path, error); +} + +void +reg (GType t_type, + GBoxedCopyFunc t_dup_func, + GDestroyNotify t_destroy_func, + GDBusConnection* conn, + gconstpointer t, + GError** error) +{ + GError* _inner_error0_ = NULL; + g_return_if_fail (G_TYPE_CHECK_INSTANCE_TYPE (conn, g_dbus_connection_get_type ())); + _vala_g_dbus_connection_register_object (t_type, t, conn, "/org/example/test", &_inner_error0_); + if (G_UNLIKELY (_inner_error0_ != NULL)) { + g_propagate_error (error, _inner_error0_); + return; + } +} + +static guint +_variant_get1 (GVariant* value) +{ + return g_variant_get_uint32 (value); +} + +static void +_client_exit_gchild_watch_func (GPid pid, + gint wait_status, + gpointer self) +{ + client_exit (pid, wait_status); +} + +static void +_vala_main (void) +{ + GDBusConnection* conn = NULL; + GDBusConnection* _tmp0_; + GDBusConnection* _tmp1_; + Test* _tmp2_; + Test* _tmp3_; + GVariant* request_result = NULL; + GDBusConnection* _tmp4_; + GVariant* _tmp5_; + GVariant* _tmp6_; + GVariant* _tmp7_; + GVariant* _tmp8_; + GVariant* _tmp9_; + GVariant* _tmp10_; + GVariant* _tmp11_; + guint _tmp12_; + GPid client_pid = 0; + gchar* _tmp13_; + gchar** _tmp14_; + gchar** _tmp15_; + gint _tmp15__length1; + GPid _tmp16_ = 0; + GMainLoop* _tmp17_; + GMainLoop* _tmp18_; + GError* _inner_error0_ = NULL; + _tmp0_ = g_bus_get_sync (G_BUS_TYPE_SESSION, NULL, &_inner_error0_); + conn = _tmp0_; + if (G_UNLIKELY (_inner_error0_ != NULL)) { + g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error0_->message, g_quark_to_string (_inner_error0_->domain), _inner_error0_->code); + g_clear_error (&_inner_error0_); + return; + } + _tmp1_ = conn; + _tmp2_ = test_new (); + _tmp3_ = _tmp2_; + reg (TYPE_TEST, (GBoxedCopyFunc) g_object_ref, (GDestroyNotify) g_object_unref, _tmp1_, _tmp3_, &_inner_error0_); + _g_object_unref0 (_tmp3_); + if (G_UNLIKELY (_inner_error0_ != NULL)) { + _g_object_unref0 (conn); + g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error0_->message, g_quark_to_string (_inner_error0_->domain), _inner_error0_->code); + g_clear_error (&_inner_error0_); + return; + } + _tmp4_ = conn; + _tmp5_ = g_variant_new ("(su)", "org.example.Test", 0x4, NULL); + g_variant_ref_sink (_tmp5_); + _tmp6_ = _tmp5_; + _tmp7_ = g_dbus_connection_call_sync (_tmp4_, "org.freedesktop.DBus", "/org/freedesktop/DBus", "org.freedesktop.DBus", "RequestName", _tmp6_, NULL, 0, -1, NULL, &_inner_error0_); + _tmp8_ = _tmp7_; + _g_variant_unref0 (_tmp6_); + request_result = _tmp8_; + if (G_UNLIKELY (_inner_error0_ != NULL)) { + _g_object_unref0 (conn); + g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error0_->message, g_quark_to_string (_inner_error0_->domain), _inner_error0_->code); + g_clear_error (&_inner_error0_); + return; + } + _tmp9_ = request_result; + _tmp10_ = g_variant_get_child_value (_tmp9_, (gsize) 0); + _tmp11_ = _tmp10_; + _tmp12_ = _variant_get1 (_tmp11_); + _vala_assert (_tmp12_ == ((guint) 1), "(uint) request_result.get_child_value (0) == 1"); + _g_variant_unref0 (_tmp11_); + _tmp13_ = g_strdup ("dbus_generics_client"); + _tmp14_ = g_new0 (gchar*, 1 + 1); + _tmp14_[0] = _tmp13_; + _tmp15_ = _tmp14_; + _tmp15__length1 = 1; + g_spawn_async (NULL, _tmp15_, NULL, G_SPAWN_DO_NOT_REAP_CHILD, NULL, NULL, &_tmp16_, &_inner_error0_); + client_pid = _tmp16_; + _tmp15_ = (_vala_array_free (_tmp15_, _tmp15__length1, (GDestroyNotify) g_free), NULL); + if (G_UNLIKELY (_inner_error0_ != NULL)) { + _g_variant_unref0 (request_result); + _g_object_unref0 (conn); + g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error0_->message, g_quark_to_string (_inner_error0_->domain), _inner_error0_->code); + g_clear_error (&_inner_error0_); + return; + } + g_child_watch_add_full (G_PRIORITY_DEFAULT_IDLE, client_pid, _client_exit_gchild_watch_func, NULL, NULL); + _tmp17_ = g_main_loop_new (NULL, FALSE); + _g_main_loop_unref0 (main_loop); + main_loop = _tmp17_; + _tmp18_ = main_loop; + g_main_loop_run (_tmp18_); + _g_variant_unref0 (request_result); + _g_object_unref0 (conn); +} + +int +main (int argc, + char ** argv) +{ + _vala_main (); + return 0; +} + +static void +_vala_array_destroy (gpointer array, + gssize array_length, + GDestroyNotify destroy_func) +{ + if ((array != NULL) && (destroy_func != NULL)) { + gssize i; + for (i = 0; i < array_length; i = i + 1) { + if (((gpointer*) array)[i] != NULL) { + destroy_func (((gpointer*) array)[i]); + } + } + } +} + +static void +_vala_array_free (gpointer array, + gssize array_length, + GDestroyNotify destroy_func) +{ + _vala_array_destroy (array, array_length, destroy_func); + g_free (array); +} + diff --git a/tests/dbus/interface-info_client.c-expected b/tests/dbus/interface-info_client.c-expected new file mode 100644 index 000000000..9ae2ff2b7 --- /dev/null +++ b/tests/dbus/interface-info_client.c-expected @@ -0,0 +1,403 @@ +/* dbus_interface_info_client.c generated by valac, the Vala compiler + * generated from dbus_interface_info_client.vala, do not modify */ + +#include <glib-object.h> +#include <gio/gio.h> +#include <stdlib.h> +#include <string.h> +#include <glib.h> + +#if !defined(VALA_EXTERN) +#if defined(_MSC_VER) +#define VALA_EXTERN __declspec(dllexport) extern +#elif __GNUC__ >= 4 +#define VALA_EXTERN __attribute__((visibility("default"))) extern +#else +#define VALA_EXTERN extern +#endif +#endif + +#define TYPE_TEST (test_get_type ()) +#define TEST(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TYPE_TEST, Test)) +#define IS_TEST(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TYPE_TEST)) +#define TEST_GET_INTERFACE(obj) (G_TYPE_INSTANCE_GET_INTERFACE ((obj), TYPE_TEST, TestIface)) + +typedef struct _Test Test; +typedef struct _TestIface TestIface; + +#define TYPE_TEST_PROXY (test_proxy_get_type ()) +enum { + TEST_BAR_SIGNAL, + TEST_NUM_SIGNALS +}; +static guint test_signals[TEST_NUM_SIGNALS] = {0}; +typedef GDBusProxy TestProxy; +typedef GDBusProxyClass TestProxyClass; +#define _g_free0(var) (var = (g_free (var), NULL)) +#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL))) +#define _vala_assert(expr, msg) if G_LIKELY (expr) ; else g_assertion_message_expr (G_LOG_DOMAIN, __FILE__, __LINE__, G_STRFUNC, msg); +#define _vala_return_if_fail(expr, msg) if G_LIKELY (expr) ; else { g_return_if_fail_warning (G_LOG_DOMAIN, G_STRFUNC, msg); return; } +#define _vala_return_val_if_fail(expr, msg, val) if G_LIKELY (expr) ; else { g_return_if_fail_warning (G_LOG_DOMAIN, G_STRFUNC, msg); return val; } +#define _vala_warn_if_fail(expr, msg) if G_LIKELY (expr) ; else g_warn_message (G_LOG_DOMAIN, __FILE__, __LINE__, G_STRFUNC, msg); + +struct _TestIface { + GTypeInterface parent_iface; +}; + +VALA_EXTERN GMainLoop* main_loop; +GMainLoop* main_loop = NULL; + +VALA_EXTERN GType test_get_type (void) G_GNUC_CONST ; +VALA_EXTERN GType test_proxy_get_type (void) G_GNUC_CONST ; +VALA_EXTERN guint test_register_object (void* object, + GDBusConnection* connection, + const gchar* path, + GError** error); +static GType test_get_type_once (void); +static void test_proxy_g_signal (GDBusProxy* proxy, + const gchar* sender_name, + const gchar* signal_name, + GVariant* parameters); +static void _dbus_handle_test_bar (Test* self, + GVariant* parameters); +static void test_proxy_test_interface_init (TestIface* iface); +static void test_dbus_interface_method_call (GDBusConnection* connection, + const gchar* sender, + const gchar* object_path, + const gchar* interface_name, + const gchar* method_name, + GVariant* parameters, + GDBusMethodInvocation* invocation, + gpointer user_data); +static GVariant* test_dbus_interface_get_property (GDBusConnection* connection, + const gchar* sender, + const gchar* object_path, + const gchar* interface_name, + const gchar* property_name, + GError** error, + gpointer user_data); +static gboolean test_dbus_interface_set_property (GDBusConnection* connection, + const gchar* sender, + const gchar* object_path, + const gchar* interface_name, + const gchar* property_name, + GVariant* value, + GError** error, + gpointer user_data); +static void _dbus_test_bar (GObject* _sender, + const gchar* j, + gpointer* _data); +static void _test_unregister_object (gpointer user_data); +static void _vala_main (void); +static gssize _vala_array_length (gpointer array); + +static const GDBusMethodInfo * const _test_dbus_method_info[] = {NULL}; +static const GDBusArgInfo _test_dbus_arg_info_bar_j = {-1, "j", "s", NULL}; +static const GDBusArgInfo * const _test_dbus_arg_info_bar[] = {&_test_dbus_arg_info_bar_j, NULL}; +static const GDBusSignalInfo _test_dbus_signal_info_bar = {-1, "Baz", (GDBusArgInfo **) (&_test_dbus_arg_info_bar), NULL}; +static const GDBusSignalInfo * const _test_dbus_signal_info[] = {&_test_dbus_signal_info_bar, NULL}; +static const GDBusPropertyInfo * const _test_dbus_property_info[] = {NULL}; +static const GDBusInterfaceInfo _test_dbus_interface_info = {-1, "org.example.Test", (GDBusMethodInfo **) (&_test_dbus_method_info), (GDBusSignalInfo **) (&_test_dbus_signal_info), (GDBusPropertyInfo **) (&_test_dbus_property_info), NULL}; +static const GDBusInterfaceVTable _test_dbus_interface_vtable = {test_dbus_interface_method_call, test_dbus_interface_get_property, test_dbus_interface_set_property}; + +static void +test_default_init (TestIface * iface, + gpointer iface_data) +{ + test_signals[TEST_BAR_SIGNAL] = g_signal_new ("bar", TYPE_TEST, G_SIGNAL_RUN_LAST, 0, NULL, NULL, g_cclosure_marshal_VOID__STRING, G_TYPE_NONE, 1, G_TYPE_STRING); +} + +static GType +test_get_type_once (void) +{ + static const GTypeInfo g_define_type_info = { sizeof (TestIface), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) test_default_init, (GClassFinalizeFunc) NULL, NULL, 0, 0, (GInstanceInitFunc) NULL, NULL }; + GType test_type_id; + test_type_id = g_type_register_static (G_TYPE_INTERFACE, "Test", &g_define_type_info, 0); + g_type_interface_add_prerequisite (test_type_id, G_TYPE_OBJECT); + g_type_set_qdata (test_type_id, g_quark_from_static_string ("vala-dbus-proxy-type"), (void*) test_proxy_get_type); + g_type_set_qdata (test_type_id, g_quark_from_static_string ("vala-dbus-interface-name"), "org.example.Test"); + g_type_set_qdata (test_type_id, g_quark_from_static_string ("vala-dbus-interface-info"), (void*) (&_test_dbus_interface_info)); + g_type_set_qdata (test_type_id, g_quark_from_static_string ("vala-dbus-register-object"), (void*) test_register_object); + return test_type_id; +} + +GType +test_get_type (void) +{ + static volatile gsize test_type_id__volatile = 0; + if (g_once_init_enter (&test_type_id__volatile)) { + GType test_type_id; + test_type_id = test_get_type_once (); + g_once_init_leave (&test_type_id__volatile, test_type_id); + } + return test_type_id__volatile; +} + +G_DEFINE_TYPE_EXTENDED (TestProxy, test_proxy, G_TYPE_DBUS_PROXY, 0, G_IMPLEMENT_INTERFACE (TYPE_TEST, test_proxy_test_interface_init) ) +static void +test_proxy_class_init (TestProxyClass* klass) +{ + G_DBUS_PROXY_CLASS (klass)->g_signal = test_proxy_g_signal; +} + +static void +_dbus_handle_test_bar (Test* self, + GVariant* parameters) +{ + GVariantIter _arguments_iter; + gchar* j = NULL; + GVariant* _tmp0_; + g_variant_iter_init (&_arguments_iter, parameters); + _tmp0_ = g_variant_iter_next_value (&_arguments_iter); + j = g_variant_dup_string (_tmp0_, NULL); + g_variant_unref (_tmp0_); + g_signal_emit_by_name (self, "bar", j); + _g_free0 (j); +} + +static void +test_proxy_g_signal (GDBusProxy* proxy, + const gchar* sender_name, + const gchar* signal_name, + GVariant* parameters) +{ + if (strcmp (signal_name, "Baz") == 0) { + _dbus_handle_test_bar ((Test*) proxy, parameters); + } +} + +static void +test_proxy_init (TestProxy* self) +{ + g_dbus_proxy_set_interface_info (G_DBUS_PROXY (self), (GDBusInterfaceInfo *) (&_test_dbus_interface_info)); +} + +static void +test_proxy_test_interface_init (TestIface* iface) +{ +} + +static void +test_dbus_interface_method_call (GDBusConnection* connection, + const gchar* sender, + const gchar* object_path, + const gchar* interface_name, + const gchar* method_name, + GVariant* parameters, + GDBusMethodInvocation* invocation, + gpointer user_data) +{ + gpointer* data; + gpointer object; + data = user_data; + object = data[0]; + g_object_unref (invocation); +} + +static GVariant* +test_dbus_interface_get_property (GDBusConnection* connection, + const gchar* sender, + const gchar* object_path, + const gchar* interface_name, + const gchar* property_name, + GError** error, + gpointer user_data) +{ + gpointer* data; + gpointer object; + data = user_data; + object = data[0]; + return NULL; +} + +static gboolean +test_dbus_interface_set_property (GDBusConnection* connection, + const gchar* sender, + const gchar* object_path, + const gchar* interface_name, + const gchar* property_name, + GVariant* value, + GError** error, + gpointer user_data) +{ + gpointer* data; + gpointer object; + data = user_data; + object = data[0]; + return FALSE; +} + +static void +_dbus_test_bar (GObject* _sender, + const gchar* j, + gpointer* _data) +{ + GDBusConnection * _connection; + const gchar * _path; + GVariant *_arguments; + GVariantBuilder _arguments_builder; + _connection = _data[1]; + _path = _data[2]; + g_variant_builder_init (&_arguments_builder, G_VARIANT_TYPE_TUPLE); + g_variant_builder_add_value (&_arguments_builder, g_variant_new_string (j)); + _arguments = g_variant_builder_end (&_arguments_builder); + g_dbus_connection_emit_signal (_connection, NULL, _path, "org.example.Test", "Baz", _arguments, NULL); +} + +guint +test_register_object (gpointer object, + GDBusConnection* connection, + const gchar* path, + GError** error) +{ + guint result; + gpointer *data; + data = g_new (gpointer, 3); + data[0] = g_object_ref (object); + data[1] = g_object_ref (connection); + data[2] = g_strdup (path); + result = g_dbus_connection_register_object (connection, path, (GDBusInterfaceInfo *) (&_test_dbus_interface_info), &_test_dbus_interface_vtable, data, _test_unregister_object, error); + if (!result) { + return 0; + } + g_signal_connect (object, "bar", (GCallback) _dbus_test_bar, data); + return result; +} + +static void +_test_unregister_object (gpointer user_data) +{ + gpointer* data; + data = user_data; + g_signal_handlers_disconnect_by_func (data[0], _dbus_test_bar, data); + g_object_unref (data[0]); + g_object_unref (data[1]); + g_free (data[2]); + g_free (data); +} + +static void +_vala_main (void) +{ + Test* test = NULL; + Test* _tmp0_; + GDBusProxy* proxy = NULL; + GDBusInterfaceInfo* iface_info = NULL; + GDBusProxy* _tmp1_; + GDBusInterfaceInfo* _tmp2_; + GDBusInterfaceInfo* _tmp3_; + GDBusInterfaceInfo* _tmp4_; + GDBusSignalInfo** _tmp5_; + gint _tmp5__length1; + GDBusInterfaceInfo* _tmp6_; + GDBusSignalInfo** _tmp7_; + gint _tmp7__length1; + GDBusSignalInfo* _tmp8_; + GDBusInterfaceInfo* _tmp9_; + GDBusSignalInfo** _tmp10_; + gint _tmp10__length1; + GDBusSignalInfo* _tmp11_; + const gchar* _tmp12_; + GDBusInterfaceInfo* _tmp13_; + GDBusSignalInfo** _tmp14_; + gint _tmp14__length1; + GDBusSignalInfo* _tmp15_; + GDBusArgInfo** _tmp16_; + gint _tmp16__length1; + GDBusInterfaceInfo* _tmp17_; + GDBusSignalInfo** _tmp18_; + gint _tmp18__length1; + GDBusSignalInfo* _tmp19_; + GDBusArgInfo** _tmp20_; + gint _tmp20__length1; + GDBusArgInfo* _tmp21_; + GDBusInterfaceInfo* _tmp22_; + GDBusSignalInfo** _tmp23_; + gint _tmp23__length1; + GDBusSignalInfo* _tmp24_; + GDBusArgInfo** _tmp25_; + gint _tmp25__length1; + GDBusArgInfo* _tmp26_; + const gchar* _tmp27_; + GDBusInterfaceInfo* _tmp28_; + void* _tmp29_; + GError* _inner_error0_ = NULL; + _tmp0_ = (Test*) g_initable_new (TYPE_TEST_PROXY, NULL, &_inner_error0_, "g-flags", 0, "g-name", "org.example.Test", "g-bus-type", G_BUS_TYPE_SESSION, "g-object-path", "/org/example/test", "g-interface-name", "org.example.Test", NULL); + test = (Test*) _tmp0_; + if (G_UNLIKELY (_inner_error0_ != NULL)) { + g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error0_->message, g_quark_to_string (_inner_error0_->domain), _inner_error0_->code); + g_clear_error (&_inner_error0_); + return; + } + proxy = G_TYPE_CHECK_INSTANCE_CAST (test, g_dbus_proxy_get_type (), GDBusProxy); + _tmp1_ = proxy; + _tmp2_ = g_dbus_proxy_get_interface_info (_tmp1_); + iface_info = _tmp2_; + _tmp3_ = iface_info; + _vala_assert (_tmp3_ != NULL, "iface_info != null"); + _tmp4_ = iface_info; + _tmp5_ = _tmp4_->signals; + _tmp5__length1 = _vala_array_length (_tmp4_->signals); + _vala_assert (_tmp5_ != NULL, "iface_info.signals != null"); + _tmp6_ = iface_info; + _tmp7_ = _tmp6_->signals; + _tmp7__length1 = _vala_array_length (_tmp6_->signals); + _tmp8_ = _tmp7_[0]; + _vala_assert (_tmp8_ != NULL, "iface_info.signals[0] != null"); + _tmp9_ = iface_info; + _tmp10_ = _tmp9_->signals; + _tmp10__length1 = _vala_array_length (_tmp9_->signals); + _tmp11_ = _tmp10_[0]; + _tmp12_ = _tmp11_->name; + _vala_assert (g_strcmp0 (_tmp12_, "Baz") == 0, "iface_info.signals[0].name == \"Baz\""); + _tmp13_ = iface_info; + _tmp14_ = _tmp13_->signals; + _tmp14__length1 = _vala_array_length (_tmp13_->signals); + _tmp15_ = _tmp14_[0]; + _tmp16_ = _tmp15_->args; + _tmp16__length1 = _vala_array_length (_tmp15_->args); + _vala_assert (_tmp16_ != NULL, "iface_info.signals[0].args != null"); + _tmp17_ = iface_info; + _tmp18_ = _tmp17_->signals; + _tmp18__length1 = _vala_array_length (_tmp17_->signals); + _tmp19_ = _tmp18_[0]; + _tmp20_ = _tmp19_->args; + _tmp20__length1 = _vala_array_length (_tmp19_->args); + _tmp21_ = _tmp20_[0]; + _vala_assert (_tmp21_ != NULL, "iface_info.signals[0].args[0] != null"); + _tmp22_ = iface_info; + _tmp23_ = _tmp22_->signals; + _tmp23__length1 = _vala_array_length (_tmp22_->signals); + _tmp24_ = _tmp23_[0]; + _tmp25_ = _tmp24_->args; + _tmp25__length1 = _vala_array_length (_tmp24_->args); + _tmp26_ = _tmp25_[0]; + _tmp27_ = _tmp26_->signature; + _vala_assert (g_strcmp0 (_tmp27_, "s") == 0, "iface_info.signals[0].args[0].signature == \"s\""); + _tmp28_ = iface_info; + _tmp29_ = g_type_get_qdata (TYPE_TEST, g_quark_from_string ("vala-dbus-interface-info")); + _vala_assert (_tmp28_ == ((GDBusInterfaceInfo*) _tmp29_), "iface_info == (DBusInterfaceInfo?) typeof (Test).get_qdata (Quark.from_string (\"vala-dbus-interface-info\"))"); + _g_object_unref0 (test); +} + +int +main (int argc, + char ** argv) +{ + _vala_main (); + return 0; +} + +static gssize +_vala_array_length (gpointer array) +{ + gssize length; + length = 0; + if (array) { + while (((gpointer*) array)[length]) { + length++; + } + } + return length; +} + diff --git a/tests/dbus/interface-info_server.c-expected b/tests/dbus/interface-info_server.c-expected new file mode 100644 index 000000000..21a0c03c7 --- /dev/null +++ b/tests/dbus/interface-info_server.c-expected @@ -0,0 +1,414 @@ +/* dbus_interface_info_server.c generated by valac, the Vala compiler + * generated from dbus_interface_info_server.vala, do not modify */ + +#include <glib-object.h> +#include <gio/gio.h> +#include <glib.h> +#include <stdlib.h> +#include <string.h> + +#if !defined(VALA_EXTERN) +#if defined(_MSC_VER) +#define VALA_EXTERN __declspec(dllexport) extern +#elif __GNUC__ >= 4 +#define VALA_EXTERN __attribute__((visibility("default"))) extern +#else +#define VALA_EXTERN extern +#endif +#endif + +#define TYPE_TEST (test_get_type ()) +#define TEST(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TYPE_TEST, Test)) +#define TEST_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), TYPE_TEST, TestClass)) +#define IS_TEST(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TYPE_TEST)) +#define IS_TEST_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), TYPE_TEST)) +#define TEST_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), TYPE_TEST, TestClass)) + +typedef struct _Test Test; +typedef struct _TestClass TestClass; +typedef struct _TestPrivate TestPrivate; +enum { + TEST_0_PROPERTY, + TEST_NUM_PROPERTIES +}; +static GParamSpec* test_properties[TEST_NUM_PROPERTIES]; +enum { + TEST_FOO_SIGNAL, + TEST_NUM_SIGNALS +}; +static guint test_signals[TEST_NUM_SIGNALS] = {0}; +#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL))) +#define _g_variant_unref0(var) ((var == NULL) ? NULL : (var = (g_variant_unref (var), NULL))) +#define _g_main_loop_unref0(var) ((var == NULL) ? NULL : (var = (g_main_loop_unref (var), NULL))) +#define _vala_assert(expr, msg) if G_LIKELY (expr) ; else g_assertion_message_expr (G_LOG_DOMAIN, __FILE__, __LINE__, G_STRFUNC, msg); +#define _vala_return_if_fail(expr, msg) if G_LIKELY (expr) ; else { g_return_if_fail_warning (G_LOG_DOMAIN, G_STRFUNC, msg); return; } +#define _vala_return_val_if_fail(expr, msg, val) if G_LIKELY (expr) ; else { g_return_if_fail_warning (G_LOG_DOMAIN, G_STRFUNC, msg); return val; } +#define _vala_warn_if_fail(expr, msg) if G_LIKELY (expr) ; else g_warn_message (G_LOG_DOMAIN, __FILE__, __LINE__, G_STRFUNC, msg); + +struct _Test { + GObject parent_instance; + TestPrivate * priv; +}; + +struct _TestClass { + GObjectClass parent_class; +}; + +static gpointer test_parent_class = NULL; +VALA_EXTERN GMainLoop* main_loop; +GMainLoop* main_loop = NULL; + +VALA_EXTERN GType test_get_type (void) G_GNUC_CONST ; +G_DEFINE_AUTOPTR_CLEANUP_FUNC (Test, g_object_unref) +VALA_EXTERN guint test_register_object (void* object, + GDBusConnection* connection, + const gchar* path, + GError** error); +VALA_EXTERN Test* test_new (void); +VALA_EXTERN Test* test_construct (GType object_type); +static GType test_get_type_once (void); +static void test_dbus_interface_method_call (GDBusConnection* connection, + const gchar* sender, + const gchar* object_path, + const gchar* interface_name, + const gchar* method_name, + GVariant* parameters, + GDBusMethodInvocation* invocation, + gpointer user_data); +static GVariant* test_dbus_interface_get_property (GDBusConnection* connection, + const gchar* sender, + const gchar* object_path, + const gchar* interface_name, + const gchar* property_name, + GError** error, + gpointer user_data); +static gboolean test_dbus_interface_set_property (GDBusConnection* connection, + const gchar* sender, + const gchar* object_path, + const gchar* interface_name, + const gchar* property_name, + GVariant* value, + GError** error, + gpointer user_data); +static void _dbus_test_foo (GObject* _sender, + gint i, + gpointer* _data); +static void _test_unregister_object (gpointer user_data); +VALA_EXTERN void client_exit (GPid pid, + gint status); +static void _vala_main (void); +static guint _variant_get1 (GVariant* value); +static void _client_exit_gchild_watch_func (GPid pid, + gint wait_status, + gpointer self); +static void _vala_array_destroy (gpointer array, + gssize array_length, + GDestroyNotify destroy_func); +static void _vala_array_free (gpointer array, + gssize array_length, + GDestroyNotify destroy_func); + +static const GDBusMethodInfo * const _test_dbus_method_info[] = {NULL}; +static const GDBusArgInfo _test_dbus_arg_info_foo_i = {-1, "i", "i", NULL}; +static const GDBusArgInfo * const _test_dbus_arg_info_foo[] = {&_test_dbus_arg_info_foo_i, NULL}; +static const GDBusSignalInfo _test_dbus_signal_info_foo = {-1, "Foo", (GDBusArgInfo **) (&_test_dbus_arg_info_foo), NULL}; +static const GDBusSignalInfo * const _test_dbus_signal_info[] = {&_test_dbus_signal_info_foo, NULL}; +static const GDBusPropertyInfo * const _test_dbus_property_info[] = {NULL}; +static const GDBusInterfaceInfo _test_dbus_interface_info = {-1, "org.example.Test", (GDBusMethodInfo **) (&_test_dbus_method_info), (GDBusSignalInfo **) (&_test_dbus_signal_info), (GDBusPropertyInfo **) (&_test_dbus_property_info), NULL}; +static const GDBusInterfaceVTable _test_dbus_interface_vtable = {test_dbus_interface_method_call, test_dbus_interface_get_property, test_dbus_interface_set_property}; + +Test* +test_construct (GType object_type) +{ + Test * self = NULL; + self = (Test*) g_object_new (object_type, NULL); + return self; +} + +Test* +test_new (void) +{ + return test_construct (TYPE_TEST); +} + +static void +test_class_init (TestClass * klass, + gpointer klass_data) +{ + test_parent_class = g_type_class_peek_parent (klass); + test_signals[TEST_FOO_SIGNAL] = g_signal_new ("foo", TYPE_TEST, G_SIGNAL_RUN_LAST, 0, NULL, NULL, g_cclosure_marshal_VOID__INT, G_TYPE_NONE, 1, G_TYPE_INT); +} + +static void +test_instance_init (Test * self, + gpointer klass) +{ +} + +static GType +test_get_type_once (void) +{ + static const GTypeInfo g_define_type_info = { sizeof (TestClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) test_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (Test), 0, (GInstanceInitFunc) test_instance_init, NULL }; + GType test_type_id; + test_type_id = g_type_register_static (G_TYPE_OBJECT, "Test", &g_define_type_info, 0); + g_type_set_qdata (test_type_id, g_quark_from_static_string ("vala-dbus-register-object"), (void*) test_register_object); + return test_type_id; +} + +GType +test_get_type (void) +{ + static volatile gsize test_type_id__volatile = 0; + if (g_once_init_enter (&test_type_id__volatile)) { + GType test_type_id; + test_type_id = test_get_type_once (); + g_once_init_leave (&test_type_id__volatile, test_type_id); + } + return test_type_id__volatile; +} + +static void +test_dbus_interface_method_call (GDBusConnection* connection, + const gchar* sender, + const gchar* object_path, + const gchar* interface_name, + const gchar* method_name, + GVariant* parameters, + GDBusMethodInvocation* invocation, + gpointer user_data) +{ + gpointer* data; + gpointer object; + data = user_data; + object = data[0]; + g_object_unref (invocation); +} + +static GVariant* +test_dbus_interface_get_property (GDBusConnection* connection, + const gchar* sender, + const gchar* object_path, + const gchar* interface_name, + const gchar* property_name, + GError** error, + gpointer user_data) +{ + gpointer* data; + gpointer object; + data = user_data; + object = data[0]; + return NULL; +} + +static gboolean +test_dbus_interface_set_property (GDBusConnection* connection, + const gchar* sender, + const gchar* object_path, + const gchar* interface_name, + const gchar* property_name, + GVariant* value, + GError** error, + gpointer user_data) +{ + gpointer* data; + gpointer object; + data = user_data; + object = data[0]; + return FALSE; +} + +static void +_dbus_test_foo (GObject* _sender, + gint i, + gpointer* _data) +{ + GDBusConnection * _connection; + const gchar * _path; + GVariant *_arguments; + GVariantBuilder _arguments_builder; + _connection = _data[1]; + _path = _data[2]; + g_variant_builder_init (&_arguments_builder, G_VARIANT_TYPE_TUPLE); + g_variant_builder_add_value (&_arguments_builder, g_variant_new_int32 (i)); + _arguments = g_variant_builder_end (&_arguments_builder); + g_dbus_connection_emit_signal (_connection, NULL, _path, "org.example.Test", "Foo", _arguments, NULL); +} + +guint +test_register_object (gpointer object, + GDBusConnection* connection, + const gchar* path, + GError** error) +{ + guint result; + gpointer *data; + data = g_new (gpointer, 3); + data[0] = g_object_ref (object); + data[1] = g_object_ref (connection); + data[2] = g_strdup (path); + result = g_dbus_connection_register_object (connection, path, (GDBusInterfaceInfo *) (&_test_dbus_interface_info), &_test_dbus_interface_vtable, data, _test_unregister_object, error); + if (!result) { + return 0; + } + g_signal_connect (object, "foo", (GCallback) _dbus_test_foo, data); + return result; +} + +static void +_test_unregister_object (gpointer user_data) +{ + gpointer* data; + data = user_data; + g_signal_handlers_disconnect_by_func (data[0], _dbus_test_foo, data); + g_object_unref (data[0]); + g_object_unref (data[1]); + g_free (data[2]); + g_free (data); +} + +void +client_exit (GPid pid, + gint status) +{ + GMainLoop* _tmp0_; + _vala_assert (status == 0, "status == 0"); + _tmp0_ = main_loop; + g_main_loop_quit (_tmp0_); +} + +static guint +_variant_get1 (GVariant* value) +{ + return g_variant_get_uint32 (value); +} + +static void +_client_exit_gchild_watch_func (GPid pid, + gint wait_status, + gpointer self) +{ + client_exit (pid, wait_status); +} + +static void +_vala_main (void) +{ + GDBusConnection* conn = NULL; + GDBusConnection* _tmp0_; + GDBusConnection* _tmp1_; + Test* _tmp2_; + Test* _tmp3_; + GVariant* request_result = NULL; + GDBusConnection* _tmp4_; + GVariant* _tmp5_; + GVariant* _tmp6_; + GVariant* _tmp7_; + GVariant* _tmp8_; + GVariant* _tmp9_; + GVariant* _tmp10_; + GVariant* _tmp11_; + guint _tmp12_; + GPid client_pid = 0; + gchar* _tmp13_; + gchar** _tmp14_; + gchar** _tmp15_; + gint _tmp15__length1; + GPid _tmp16_ = 0; + GMainLoop* _tmp17_; + GMainLoop* _tmp18_; + GError* _inner_error0_ = NULL; + _tmp0_ = g_bus_get_sync (G_BUS_TYPE_SESSION, NULL, &_inner_error0_); + conn = _tmp0_; + if (G_UNLIKELY (_inner_error0_ != NULL)) { + g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error0_->message, g_quark_to_string (_inner_error0_->domain), _inner_error0_->code); + g_clear_error (&_inner_error0_); + return; + } + _tmp1_ = conn; + _tmp2_ = test_new (); + _tmp3_ = _tmp2_; + test_register_object (_tmp3_, _tmp1_, "/org/example/test", &_inner_error0_); + _g_object_unref0 (_tmp3_); + if (G_UNLIKELY (_inner_error0_ != NULL)) { + _g_object_unref0 (conn); + g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error0_->message, g_quark_to_string (_inner_error0_->domain), _inner_error0_->code); + g_clear_error (&_inner_error0_); + return; + } + _tmp4_ = conn; + _tmp5_ = g_variant_new ("(su)", "org.example.Test", 0x4, NULL); + g_variant_ref_sink (_tmp5_); + _tmp6_ = _tmp5_; + _tmp7_ = g_dbus_connection_call_sync (_tmp4_, "org.freedesktop.DBus", "/org/freedesktop/DBus", "org.freedesktop.DBus", "RequestName", _tmp6_, NULL, 0, -1, NULL, &_inner_error0_); + _tmp8_ = _tmp7_; + _g_variant_unref0 (_tmp6_); + request_result = _tmp8_; + if (G_UNLIKELY (_inner_error0_ != NULL)) { + _g_object_unref0 (conn); + g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error0_->message, g_quark_to_string (_inner_error0_->domain), _inner_error0_->code); + g_clear_error (&_inner_error0_); + return; + } + _tmp9_ = request_result; + _tmp10_ = g_variant_get_child_value (_tmp9_, (gsize) 0); + _tmp11_ = _tmp10_; + _tmp12_ = _variant_get1 (_tmp11_); + _vala_assert (_tmp12_ == ((guint) 1), "(uint) request_result.get_child_value (0) == 1"); + _g_variant_unref0 (_tmp11_); + _tmp13_ = g_strdup ("dbus_interface_info_client"); + _tmp14_ = g_new0 (gchar*, 1 + 1); + _tmp14_[0] = _tmp13_; + _tmp15_ = _tmp14_; + _tmp15__length1 = 1; + g_spawn_async (NULL, _tmp15_, NULL, G_SPAWN_DO_NOT_REAP_CHILD, NULL, NULL, &_tmp16_, &_inner_error0_); + client_pid = _tmp16_; + _tmp15_ = (_vala_array_free (_tmp15_, _tmp15__length1, (GDestroyNotify) g_free), NULL); + if (G_UNLIKELY (_inner_error0_ != NULL)) { + _g_variant_unref0 (request_result); + _g_object_unref0 (conn); + g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error0_->message, g_quark_to_string (_inner_error0_->domain), _inner_error0_->code); + g_clear_error (&_inner_error0_); + return; + } + g_child_watch_add_full (G_PRIORITY_DEFAULT_IDLE, client_pid, _client_exit_gchild_watch_func, NULL, NULL); + _tmp17_ = g_main_loop_new (NULL, FALSE); + _g_main_loop_unref0 (main_loop); + main_loop = _tmp17_; + _tmp18_ = main_loop; + g_main_loop_run (_tmp18_); + _g_variant_unref0 (request_result); + _g_object_unref0 (conn); +} + +int +main (int argc, + char ** argv) +{ + _vala_main (); + return 0; +} + +static void +_vala_array_destroy (gpointer array, + gssize array_length, + GDestroyNotify destroy_func) +{ + if ((array != NULL) && (destroy_func != NULL)) { + gssize i; + for (i = 0; i < array_length; i = i + 1) { + if (((gpointer*) array)[i] != NULL) { + destroy_func (((gpointer*) array)[i]); + } + } + } +} + +static void +_vala_array_free (gpointer array, + gssize array_length, + GDestroyNotify destroy_func) +{ + _vala_array_destroy (array, array_length, destroy_func); + g_free (array); +} + diff --git a/tests/dbus/no-reply_client.c-expected b/tests/dbus/no-reply_client.c-expected new file mode 100644 index 000000000..106c9a2b2 --- /dev/null +++ b/tests/dbus/no-reply_client.c-expected @@ -0,0 +1,933 @@ +/* dbus_no_reply_client.c generated by valac, the Vala compiler + * generated from dbus_no_reply_client.vala, do not modify */ + +#include <glib-object.h> +#include <gio/gio.h> +#include <stdlib.h> +#include <string.h> +#include <glib.h> + +#if !defined(VALA_EXTERN) +#if defined(_MSC_VER) +#define VALA_EXTERN __declspec(dllexport) extern +#elif __GNUC__ >= 4 +#define VALA_EXTERN __attribute__((visibility("default"))) extern +#else +#define VALA_EXTERN extern +#endif +#endif + +#define TYPE_TEST (test_get_type ()) +#define TEST(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TYPE_TEST, Test)) +#define IS_TEST(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TYPE_TEST)) +#define TEST_GET_INTERFACE(obj) (G_TYPE_INSTANCE_GET_INTERFACE ((obj), TYPE_TEST, TestIface)) + +typedef struct _Test Test; +typedef struct _TestIface TestIface; + +#define TYPE_TEST_PROXY (test_proxy_get_type ()) +typedef GDBusProxy TestProxy; +typedef GDBusProxyClass TestProxyClass; +#define _g_free0(var) (var = (g_free (var), NULL)) +typedef struct _Block1Data Block1Data; +#define _g_async_queue_unref0(var) ((var == NULL) ? NULL : (var = (g_async_queue_unref (var), NULL))) +#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL))) +typedef struct _RunData RunData; +#define _g_main_loop_unref0(var) ((var == NULL) ? NULL : (var = (g_main_loop_unref (var), NULL))) +#define _vala_assert(expr, msg) if G_LIKELY (expr) ; else g_assertion_message_expr (G_LOG_DOMAIN, __FILE__, __LINE__, G_STRFUNC, msg); +#define _vala_return_if_fail(expr, msg) if G_LIKELY (expr) ; else { g_return_if_fail_warning (G_LOG_DOMAIN, G_STRFUNC, msg); return; } +#define _vala_return_val_if_fail(expr, msg, val) if G_LIKELY (expr) ; else { g_return_if_fail_warning (G_LOG_DOMAIN, G_STRFUNC, msg); return val; } +#define _vala_warn_if_fail(expr, msg) if G_LIKELY (expr) ; else g_warn_message (G_LOG_DOMAIN, __FILE__, __LINE__, G_STRFUNC, msg); + +struct _TestIface { + GTypeInterface parent_iface; + gchar** (*list_messages) (Test* self, gint* result_length1, GError** error); + void (*post_message) (Test* self, const gchar* message, GError** error); + void (*post_message_no_reply) (Test* self, const gchar* message, GError** error); +}; + +struct _Block1Data { + int _ref_count_; + GAsyncQueue* events; + gpointer _async_data_; +}; + +struct _RunData { + int _state_; + GObject* _source_object_; + GAsyncResult* _res_; + GTask* _async_result; + Block1Data* _data1_; + Test* test; + Test* _tmp0_; + GAsyncQueue* _tmp1_; + GDBusConnection* connection; + Test* _tmp2_; + GDBusConnection* _tmp3_; + GDBusConnection* _tmp4_; + GDBusConnection* _tmp5_; + gchar** messages; + Test* _tmp6_; + gint _tmp7_; + gchar** _tmp8_; + gint messages_length1; + gint _messages_size_; + gchar** _tmp9_; + gint _tmp9__length1; + Test* _tmp10_; + GAsyncQueue* _tmp11_; + gpointer _tmp12_; + gchar* _tmp13_; + GAsyncQueue* _tmp14_; + gpointer _tmp15_; + gchar* _tmp16_; + Test* _tmp17_; + GAsyncQueue* _tmp18_; + gpointer _tmp19_; + gchar* _tmp20_; + GAsyncQueue* _tmp21_; + gpointer _tmp22_; + gchar* _tmp23_; + gchar** _tmp24_; + Test* _tmp25_; + gint _tmp26_; + gchar** _tmp27_; + gint _tmp24__length1; + gint __tmp24__size_; + gchar** _tmp28_; + gint _tmp28__length1; + gchar** _tmp29_; + gint _tmp29__length1; + gchar** _tmp30_; + gint _tmp30__length1; + const gchar* _tmp31_; + gchar** _tmp32_; + gint _tmp32__length1; + const gchar* _tmp33_; + GMainLoop* _tmp34_; + GError* _inner_error0_; +}; + +VALA_EXTERN GMainLoop* main_loop; +GMainLoop* main_loop = NULL; + +VALA_EXTERN GType test_proxy_get_type (void) G_GNUC_CONST ; +VALA_EXTERN guint test_register_object (void* object, + GDBusConnection* connection, + const gchar* path, + GError** error); +VALA_EXTERN GType test_get_type (void) G_GNUC_CONST ; +VALA_EXTERN gchar** test_list_messages (Test* self, + gint* result_length1, + GError** error); +VALA_EXTERN void test_post_message (Test* self, + const gchar* message, + GError** error); +VALA_EXTERN void test_post_message_no_reply (Test* self, + const gchar* message, + GError** error); +static GType test_get_type_once (void); +static void test_proxy_g_signal (GDBusProxy* proxy, + const gchar* sender_name, + const gchar* signal_name, + GVariant* parameters); +static gchar** test_proxy_list_messages (Test* self, + gint* result_length1, + GError** error); +static void test_proxy_post_message (Test* self, + const gchar* message, + GError** error); +static void test_proxy_post_message_no_reply (Test* self, + const gchar* message, + GError** error); +static void test_proxy_test_interface_init (TestIface* iface); +static void _dbus_test_list_messages (Test* self, + GVariant* _parameters_, + GDBusMethodInvocation* invocation); +static void _dbus_test_post_message (Test* self, + GVariant* _parameters_, + GDBusMethodInvocation* invocation); +static void _dbus_test_post_message_no_reply (Test* self, + GVariant* _parameters_, + GDBusMethodInvocation* invocation); +static void test_dbus_interface_method_call (GDBusConnection* connection, + const gchar* sender, + const gchar* object_path, + const gchar* interface_name, + const gchar* method_name, + GVariant* parameters, + GDBusMethodInvocation* invocation, + gpointer user_data); +static GVariant* test_dbus_interface_get_property (GDBusConnection* connection, + const gchar* sender, + const gchar* object_path, + const gchar* interface_name, + const gchar* property_name, + GError** error, + gpointer user_data); +static gboolean test_dbus_interface_set_property (GDBusConnection* connection, + const gchar* sender, + const gchar* object_path, + const gchar* interface_name, + const gchar* property_name, + GVariant* value, + GError** error, + gpointer user_data); +static void _test_unregister_object (gpointer user_data); +static void run_data_free (gpointer _data); +VALA_EXTERN void run (GAsyncReadyCallback _callback_, + gpointer _user_data_); +VALA_EXTERN void run_finish (GAsyncResult* _res_); +static gboolean run_co (RunData* _data_); +static Block1Data* block1_data_ref (Block1Data* _data1_); +static void block1_data_unref (void * _userdata_); +static void run_ready (GObject* source_object, + GAsyncResult* _res_, + gpointer _user_data_); +static void _g_free0_ (gpointer var); +static GDBusMessage* __lambda4_ (Block1Data* _data1_, + GDBusConnection* conn, + GDBusMessage* message, + gboolean incoming); +static GDBusMessage* ___lambda4__gd_bus_message_filter_function (GDBusConnection* connection, + GDBusMessage* message, + gboolean incoming, + gpointer self); +static void _vala_main (void); +static void _vala_array_destroy (gpointer array, + gssize array_length, + GDestroyNotify destroy_func); +static void _vala_array_free (gpointer array, + gssize array_length, + GDestroyNotify destroy_func); + +static const GDBusArgInfo _test_dbus_arg_info_list_messages_result = {-1, "result", "as", NULL}; +static const GDBusArgInfo * const _test_dbus_arg_info_list_messages_in[] = {NULL}; +static const GDBusArgInfo * const _test_dbus_arg_info_list_messages_out[] = {&_test_dbus_arg_info_list_messages_result, NULL}; +static const GDBusMethodInfo _test_dbus_method_info_list_messages = {-1, "ListMessages", (GDBusArgInfo **) (&_test_dbus_arg_info_list_messages_in), (GDBusArgInfo **) (&_test_dbus_arg_info_list_messages_out), NULL}; +static const GDBusArgInfo _test_dbus_arg_info_post_message_message = {-1, "message", "s", NULL}; +static const GDBusArgInfo * const _test_dbus_arg_info_post_message_in[] = {&_test_dbus_arg_info_post_message_message, NULL}; +static const GDBusArgInfo * const _test_dbus_arg_info_post_message_out[] = {NULL}; +static const GDBusMethodInfo _test_dbus_method_info_post_message = {-1, "PostMessage", (GDBusArgInfo **) (&_test_dbus_arg_info_post_message_in), (GDBusArgInfo **) (&_test_dbus_arg_info_post_message_out), NULL}; +static const GDBusArgInfo _test_dbus_arg_info_post_message_no_reply_message = {-1, "message", "s", NULL}; +static const GDBusArgInfo * const _test_dbus_arg_info_post_message_no_reply_in[] = {&_test_dbus_arg_info_post_message_no_reply_message, NULL}; +static const GDBusArgInfo * const _test_dbus_arg_info_post_message_no_reply_out[] = {NULL}; +static const GDBusMethodInfo _test_dbus_method_info_post_message_no_reply = {-1, "PostMessageNoReply", (GDBusArgInfo **) (&_test_dbus_arg_info_post_message_no_reply_in), (GDBusArgInfo **) (&_test_dbus_arg_info_post_message_no_reply_out), NULL}; +static const GDBusMethodInfo * const _test_dbus_method_info[] = {&_test_dbus_method_info_list_messages, &_test_dbus_method_info_post_message, &_test_dbus_method_info_post_message_no_reply, NULL}; +static const GDBusSignalInfo * const _test_dbus_signal_info[] = {NULL}; +static const GDBusPropertyInfo * const _test_dbus_property_info[] = {NULL}; +static const GDBusInterfaceInfo _test_dbus_interface_info = {-1, "org.example.Test", (GDBusMethodInfo **) (&_test_dbus_method_info), (GDBusSignalInfo **) (&_test_dbus_signal_info), (GDBusPropertyInfo **) (&_test_dbus_property_info), NULL}; +static const GDBusInterfaceVTable _test_dbus_interface_vtable = {test_dbus_interface_method_call, test_dbus_interface_get_property, test_dbus_interface_set_property}; + +gchar** +test_list_messages (Test* self, + gint* result_length1, + GError** error) +{ + TestIface* _iface_; + g_return_val_if_fail (IS_TEST (self), NULL); + _iface_ = TEST_GET_INTERFACE (self); + if (_iface_->list_messages) { + return _iface_->list_messages (self, result_length1, error); + } + return NULL; +} + +void +test_post_message (Test* self, + const gchar* message, + GError** error) +{ + TestIface* _iface_; + g_return_if_fail (IS_TEST (self)); + _iface_ = TEST_GET_INTERFACE (self); + if (_iface_->post_message) { + _iface_->post_message (self, message, error); + } +} + +void +test_post_message_no_reply (Test* self, + const gchar* message, + GError** error) +{ + TestIface* _iface_; + g_return_if_fail (IS_TEST (self)); + _iface_ = TEST_GET_INTERFACE (self); + if (_iface_->post_message_no_reply) { + _iface_->post_message_no_reply (self, message, error); + } +} + +static void +test_default_init (TestIface * iface, + gpointer iface_data) +{ +} + +static GType +test_get_type_once (void) +{ + static const GTypeInfo g_define_type_info = { sizeof (TestIface), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) test_default_init, (GClassFinalizeFunc) NULL, NULL, 0, 0, (GInstanceInitFunc) NULL, NULL }; + GType test_type_id; + test_type_id = g_type_register_static (G_TYPE_INTERFACE, "Test", &g_define_type_info, 0); + g_type_interface_add_prerequisite (test_type_id, G_TYPE_OBJECT); + g_type_set_qdata (test_type_id, g_quark_from_static_string ("vala-dbus-proxy-type"), (void*) test_proxy_get_type); + g_type_set_qdata (test_type_id, g_quark_from_static_string ("vala-dbus-interface-name"), "org.example.Test"); + g_type_set_qdata (test_type_id, g_quark_from_static_string ("vala-dbus-interface-info"), (void*) (&_test_dbus_interface_info)); + g_type_set_qdata (test_type_id, g_quark_from_static_string ("vala-dbus-register-object"), (void*) test_register_object); + return test_type_id; +} + +GType +test_get_type (void) +{ + static volatile gsize test_type_id__volatile = 0; + if (g_once_init_enter (&test_type_id__volatile)) { + GType test_type_id; + test_type_id = test_get_type_once (); + g_once_init_leave (&test_type_id__volatile, test_type_id); + } + return test_type_id__volatile; +} + +G_DEFINE_TYPE_EXTENDED (TestProxy, test_proxy, G_TYPE_DBUS_PROXY, 0, G_IMPLEMENT_INTERFACE (TYPE_TEST, test_proxy_test_interface_init) ) +static void +test_proxy_class_init (TestProxyClass* klass) +{ + G_DBUS_PROXY_CLASS (klass)->g_signal = test_proxy_g_signal; +} + +static void +test_proxy_g_signal (GDBusProxy* proxy, + const gchar* sender_name, + const gchar* signal_name, + GVariant* parameters) +{ +} + +static void +test_proxy_init (TestProxy* self) +{ + g_dbus_proxy_set_interface_info (G_DBUS_PROXY (self), (GDBusInterfaceInfo *) (&_test_dbus_interface_info)); +} + +static gchar** +test_proxy_list_messages (Test* self, + gint* result_length1, + GError** error) +{ + GDBusMessage *_message; + GVariant *_arguments; + GVariantBuilder _arguments_builder; + GDBusMessage *_reply_message; + GVariant *_reply; + GVariantIter _reply_iter; + gchar** _result = NULL; + gint _result_length1; + GVariant* _tmp0_; + gchar** _tmp1_; + gint _tmp1__length; + gint _tmp1__size; + gint _tmp1__length1; + GVariantIter _tmp2_; + GVariant* _tmp3_; + G_IO_ERROR; + _message = g_dbus_message_new_method_call (g_dbus_proxy_get_name ((GDBusProxy *) self), g_dbus_proxy_get_object_path ((GDBusProxy *) self), "org.example.Test", "ListMessages"); + g_variant_builder_init (&_arguments_builder, G_VARIANT_TYPE_TUPLE); + _arguments = g_variant_builder_end (&_arguments_builder); + g_dbus_message_set_body (_message, _arguments); + _reply_message = g_dbus_connection_send_message_with_reply_sync (g_dbus_proxy_get_connection ((GDBusProxy *) self), _message, G_DBUS_SEND_MESSAGE_FLAGS_NONE, g_dbus_proxy_get_default_timeout ((GDBusProxy *) self), NULL, NULL, error); + g_object_unref (_message); + if (!_reply_message) { + return NULL; + } + if (g_dbus_message_to_gerror (_reply_message, error)) { + g_object_unref (_reply_message); + return NULL; + } + _reply = g_dbus_message_get_body (_reply_message); + g_variant_iter_init (&_reply_iter, _reply); + _result_length1 = 0; + _tmp0_ = g_variant_iter_next_value (&_reply_iter); + _tmp1_ = g_new (gchar*, 5); + _tmp1__length = 0; + _tmp1__size = 4; + _tmp1__length1 = 0; + g_variant_iter_init (&_tmp2_, _tmp0_); + for (; (_tmp3_ = g_variant_iter_next_value (&_tmp2_)) != NULL; _tmp1__length1++) { + if (_tmp1__size == _tmp1__length) { + _tmp1__size = 2 * _tmp1__size; + _tmp1_ = g_renew (gchar*, _tmp1_, _tmp1__size + 1); + } + _tmp1_[_tmp1__length++] = g_variant_dup_string (_tmp3_, NULL); + g_variant_unref (_tmp3_); + } + _result_length1 = _tmp1__length1; + _tmp1_[_tmp1__length] = NULL; + _result = _tmp1_; + g_variant_unref (_tmp0_); + *result_length1 = _result_length1; + g_object_unref (_reply_message); + return _result; +} + +static void +test_proxy_post_message (Test* self, + const gchar* message, + GError** error) +{ + GDBusMessage *_message; + GVariant *_arguments; + GVariantBuilder _arguments_builder; + GDBusMessage *_reply_message; + G_IO_ERROR; + _message = g_dbus_message_new_method_call (g_dbus_proxy_get_name ((GDBusProxy *) self), g_dbus_proxy_get_object_path ((GDBusProxy *) self), "org.example.Test", "PostMessage"); + g_variant_builder_init (&_arguments_builder, G_VARIANT_TYPE_TUPLE); + g_variant_builder_add_value (&_arguments_builder, g_variant_new_string (message)); + _arguments = g_variant_builder_end (&_arguments_builder); + g_dbus_message_set_body (_message, _arguments); + _reply_message = g_dbus_connection_send_message_with_reply_sync (g_dbus_proxy_get_connection ((GDBusProxy *) self), _message, G_DBUS_SEND_MESSAGE_FLAGS_NONE, g_dbus_proxy_get_default_timeout ((GDBusProxy *) self), NULL, NULL, error); + g_object_unref (_message); + if (!_reply_message) { + return; + } + if (g_dbus_message_to_gerror (_reply_message, error)) { + g_object_unref (_reply_message); + return; + } + g_object_unref (_reply_message); +} + +static void +test_proxy_post_message_no_reply (Test* self, + const gchar* message, + GError** error) +{ + GDBusMessage *_message; + GVariant *_arguments; + GVariantBuilder _arguments_builder; + G_IO_ERROR; + _message = g_dbus_message_new_method_call (g_dbus_proxy_get_name ((GDBusProxy *) self), g_dbus_proxy_get_object_path ((GDBusProxy *) self), "org.example.Test", "PostMessageNoReply"); + g_variant_builder_init (&_arguments_builder, G_VARIANT_TYPE_TUPLE); + g_variant_builder_add_value (&_arguments_builder, g_variant_new_string (message)); + _arguments = g_variant_builder_end (&_arguments_builder); + g_dbus_message_set_body (_message, _arguments); + g_dbus_message_set_flags (_message, G_DBUS_MESSAGE_FLAGS_NO_REPLY_EXPECTED); + g_dbus_connection_send_message (g_dbus_proxy_get_connection ((GDBusProxy *) self), _message, G_DBUS_SEND_MESSAGE_FLAGS_NONE, NULL, error); + g_object_unref (_message); +} + +static void +test_proxy_test_interface_init (TestIface* iface) +{ + iface->list_messages = test_proxy_list_messages; + iface->post_message = test_proxy_post_message; + iface->post_message_no_reply = test_proxy_post_message_no_reply; +} + +static void +_dbus_test_list_messages (Test* self, + GVariant* _parameters_, + GDBusMethodInvocation* invocation) +{ + GError* error = NULL; + GVariantIter _arguments_iter; + GDBusMessage* _reply_message = NULL; + GVariant* _reply; + GVariantBuilder _reply_builder; + gchar** result; + gint result_length1 = 0; + gchar** _tmp4_; + GVariantBuilder _tmp5_; + gint _tmp6_; + g_variant_iter_init (&_arguments_iter, _parameters_); + result = test_list_messages (self, &result_length1, &error); + if (error) { + g_dbus_method_invocation_return_gerror (invocation, error); + g_error_free (error); + return; + } + _reply_message = g_dbus_message_new_method_reply (g_dbus_method_invocation_get_message (invocation)); + g_variant_builder_init (&_reply_builder, G_VARIANT_TYPE_TUPLE); + _tmp4_ = result; + g_variant_builder_init (&_tmp5_, G_VARIANT_TYPE ("as")); + for (_tmp6_ = 0; _tmp6_ < result_length1; _tmp6_++) { + g_variant_builder_add_value (&_tmp5_, g_variant_new_string (*_tmp4_)); + _tmp4_++; + } + g_variant_builder_add_value (&_reply_builder, g_variant_builder_end (&_tmp5_)); + result = (_vala_array_free (result, result_length1, (GDestroyNotify) g_free), NULL); + _reply = g_variant_builder_end (&_reply_builder); + g_dbus_message_set_body (_reply_message, _reply); + g_dbus_connection_send_message (g_dbus_method_invocation_get_connection (invocation), _reply_message, G_DBUS_SEND_MESSAGE_FLAGS_NONE, NULL, NULL); + g_object_unref (invocation); + g_object_unref (_reply_message); +} + +static void +_dbus_test_post_message (Test* self, + GVariant* _parameters_, + GDBusMethodInvocation* invocation) +{ + GError* error = NULL; + GVariantIter _arguments_iter; + gchar* message = NULL; + GVariant* _tmp7_; + GDBusMessage* _reply_message = NULL; + GVariant* _reply; + GVariantBuilder _reply_builder; + g_variant_iter_init (&_arguments_iter, _parameters_); + _tmp7_ = g_variant_iter_next_value (&_arguments_iter); + message = g_variant_dup_string (_tmp7_, NULL); + g_variant_unref (_tmp7_); + test_post_message (self, message, &error); + if (error) { + g_dbus_method_invocation_return_gerror (invocation, error); + g_error_free (error); + goto _error; + } + _reply_message = g_dbus_message_new_method_reply (g_dbus_method_invocation_get_message (invocation)); + g_variant_builder_init (&_reply_builder, G_VARIANT_TYPE_TUPLE); + _reply = g_variant_builder_end (&_reply_builder); + g_dbus_message_set_body (_reply_message, _reply); + g_dbus_connection_send_message (g_dbus_method_invocation_get_connection (invocation), _reply_message, G_DBUS_SEND_MESSAGE_FLAGS_NONE, NULL, NULL); + g_object_unref (invocation); + g_object_unref (_reply_message); + _error: + _g_free0 (message); + ; +} + +static void +_dbus_test_post_message_no_reply (Test* self, + GVariant* _parameters_, + GDBusMethodInvocation* invocation) +{ + GError* error = NULL; + GVariantIter _arguments_iter; + gchar* message = NULL; + GVariant* _tmp8_; + g_variant_iter_init (&_arguments_iter, _parameters_); + _tmp8_ = g_variant_iter_next_value (&_arguments_iter); + message = g_variant_dup_string (_tmp8_, NULL); + g_variant_unref (_tmp8_); + test_post_message_no_reply (self, message, &error); + _error: + _g_free0 (message); + ; +} + +static void +test_dbus_interface_method_call (GDBusConnection* connection, + const gchar* sender, + const gchar* object_path, + const gchar* interface_name, + const gchar* method_name, + GVariant* parameters, + GDBusMethodInvocation* invocation, + gpointer user_data) +{ + gpointer* data; + gpointer object; + data = user_data; + object = data[0]; + if (strcmp (method_name, "ListMessages") == 0) { + _dbus_test_list_messages (object, parameters, invocation); + } else if (strcmp (method_name, "PostMessage") == 0) { + _dbus_test_post_message (object, parameters, invocation); + } else if (strcmp (method_name, "PostMessageNoReply") == 0) { + _dbus_test_post_message_no_reply (object, parameters, invocation); + } else { + g_object_unref (invocation); + } +} + +static GVariant* +test_dbus_interface_get_property (GDBusConnection* connection, + const gchar* sender, + const gchar* object_path, + const gchar* interface_name, + const gchar* property_name, + GError** error, + gpointer user_data) +{ + gpointer* data; + gpointer object; + data = user_data; + object = data[0]; + return NULL; +} + +static gboolean +test_dbus_interface_set_property (GDBusConnection* connection, + const gchar* sender, + const gchar* object_path, + const gchar* interface_name, + const gchar* property_name, + GVariant* value, + GError** error, + gpointer user_data) +{ + gpointer* data; + gpointer object; + data = user_data; + object = data[0]; + return FALSE; +} + +guint +test_register_object (gpointer object, + GDBusConnection* connection, + const gchar* path, + GError** error) +{ + guint result; + gpointer *data; + data = g_new (gpointer, 3); + data[0] = g_object_ref (object); + data[1] = g_object_ref (connection); + data[2] = g_strdup (path); + result = g_dbus_connection_register_object (connection, path, (GDBusInterfaceInfo *) (&_test_dbus_interface_info), &_test_dbus_interface_vtable, data, _test_unregister_object, error); + if (!result) { + return 0; + } + return result; +} + +static void +_test_unregister_object (gpointer user_data) +{ + gpointer* data; + data = user_data; + g_object_unref (data[0]); + g_object_unref (data[1]); + g_free (data[2]); + g_free (data); +} + +static void +run_data_free (gpointer _data) +{ + RunData* _data_; + _data_ = _data; + g_slice_free (RunData, _data_); +} + +void +run (GAsyncReadyCallback _callback_, + gpointer _user_data_) +{ + RunData* _data_; + _data_ = g_slice_new0 (RunData); + _data_->_async_result = g_task_new (NULL, NULL, _callback_, _user_data_); + g_task_set_task_data (_data_->_async_result, _data_, run_data_free); + run_co (_data_); +} + +void +run_finish (GAsyncResult* _res_) +{ + RunData* _data_; + _data_ = g_task_propagate_pointer (G_TASK (_res_), NULL); +} + +static Block1Data* +block1_data_ref (Block1Data* _data1_) +{ + g_atomic_int_inc (&_data1_->_ref_count_); + return _data1_; +} + +static void +block1_data_unref (void * _userdata_) +{ + Block1Data* _data1_; + _data1_ = (Block1Data*) _userdata_; + if (g_atomic_int_dec_and_test (&_data1_->_ref_count_)) { + _g_async_queue_unref0 (_data1_->events); + g_slice_free (Block1Data, _data1_); + } +} + +static void +run_ready (GObject* source_object, + GAsyncResult* _res_, + gpointer _user_data_) +{ + RunData* _data_; + _data_ = _user_data_; + _data_->_source_object_ = source_object; + _data_->_res_ = _res_; + run_co (_data_); +} + +static void +_g_free0_ (gpointer var) +{ + var = (g_free (var), NULL); +} + +static gpointer +_g_object_ref0 (gpointer self) +{ + return self ? g_object_ref (self) : NULL; +} + +static GDBusMessage* +__lambda4_ (Block1Data* _data1_, + GDBusConnection* conn, + GDBusMessage* message, + gboolean incoming) +{ + gboolean _tmp0_ = FALSE; + const gchar* _tmp1_; + GDBusMessage* _tmp6_; + GDBusMessage* result = NULL; + g_return_val_if_fail (G_TYPE_CHECK_INSTANCE_TYPE (conn, g_dbus_connection_get_type ()), NULL); + g_return_val_if_fail (G_TYPE_CHECK_INSTANCE_TYPE (message, g_dbus_message_get_type ()), NULL); + _tmp1_ = g_dbus_message_get_interface (message); + if (g_strcmp0 (_tmp1_, "org.example.Test") == 0) { + const gchar* _tmp2_; + _tmp2_ = g_dbus_message_get_member (message); + _tmp0_ = g_strcmp0 (_tmp2_, "ListMessages") != 0; + } else { + _tmp0_ = FALSE; + } + if (_tmp0_) { + switch (g_dbus_message_get_message_type (message)) { + case G_DBUS_MESSAGE_TYPE_METHOD_CALL: + { + GAsyncQueue* _tmp3_; + GFlagsValue* _tmp4_; + gchar* _tmp5_; + _tmp3_ = _data1_->events; + _tmp4_ = g_flags_get_first_value (g_type_class_ref (g_dbus_message_flags_get_type ()), g_dbus_message_get_flags (message)); + _tmp5_ = g_strdup ((_tmp4_ != NULL) ? _tmp4_->value_name : NULL); + g_async_queue_push (_tmp3_, _tmp5_); + break; + } + default: + { + g_assert_not_reached (); + } + } + } + _tmp6_ = _g_object_ref0 (message); + result = _tmp6_; + _g_object_unref0 (message); + return result; +} + +static GDBusMessage* +___lambda4__gd_bus_message_filter_function (GDBusConnection* connection, + GDBusMessage* message, + gboolean incoming, + gpointer self) +{ + GDBusMessage* result; + result = __lambda4_ (self, connection, message, incoming); + return result; +} + +static gboolean +run_co (RunData* _data_) +{ + switch (_data_->_state_) { + case 0: + goto _state_0; + case 1: + goto _state_1; + default: + g_assert_not_reached (); + } + _state_0: + _data_->_data1_ = g_slice_new0 (Block1Data); + _data_->_data1_->_ref_count_ = 1; + _data_->_data1_->_async_data_ = _data_; + _data_->_state_ = 1; + g_async_initable_new_async (TYPE_TEST_PROXY, 0, NULL, run_ready, _data_, "g-flags", 0, "g-name", "org.example.Test", "g-bus-type", G_BUS_TYPE_SESSION, "g-object-path", "/org/example/Test", "g-interface-name", "org.example.Test", NULL); + return FALSE; + _state_1: + _data_->_tmp0_ = (Test*) g_async_initable_new_finish ((GAsyncInitable *) _data_->_source_object_, _data_->_res_, &_data_->_inner_error0_); + _data_->test = (Test*) _data_->_tmp0_; + if (G_UNLIKELY (_data_->_inner_error0_ != NULL)) { + block1_data_unref (_data_->_data1_); + _data_->_data1_ = NULL; + g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _data_->_inner_error0_->message, g_quark_to_string (_data_->_inner_error0_->domain), _data_->_inner_error0_->code); + g_clear_error (&_data_->_inner_error0_); + g_object_unref (_data_->_async_result); + return FALSE; + } + _data_->_tmp1_ = g_async_queue_new_full (_g_free0_); + _data_->_data1_->events = _data_->_tmp1_; + _data_->_tmp2_ = _data_->test; + g_object_get (G_TYPE_CHECK_INSTANCE_CAST (_data_->_tmp2_, g_dbus_proxy_get_type (), GDBusProxy), "g-connection", &_data_->_tmp3_, NULL); + _data_->_tmp4_ = _data_->_tmp3_; + _data_->connection = _data_->_tmp4_; + _data_->_tmp5_ = _data_->connection; + g_dbus_connection_add_filter (_data_->_tmp5_, ___lambda4__gd_bus_message_filter_function, block1_data_ref (_data_->_data1_), block1_data_unref); + _data_->_tmp6_ = _data_->test; + _data_->_tmp7_ = 0; + _data_->_tmp8_ = test_list_messages (_data_->_tmp6_, &_data_->_tmp7_, &_data_->_inner_error0_); + _data_->messages = _data_->_tmp8_; + _data_->messages_length1 = _data_->_tmp7_; + _data_->_messages_size_ = _data_->messages_length1; + if (G_UNLIKELY (_data_->_inner_error0_ != NULL)) { + _g_object_unref0 (_data_->connection); + _g_object_unref0 (_data_->test); + block1_data_unref (_data_->_data1_); + _data_->_data1_ = NULL; + g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _data_->_inner_error0_->message, g_quark_to_string (_data_->_inner_error0_->domain), _data_->_inner_error0_->code); + g_clear_error (&_data_->_inner_error0_); + g_object_unref (_data_->_async_result); + return FALSE; + } + _data_->_tmp9_ = _data_->messages; + _data_->_tmp9__length1 = _data_->messages_length1; + _vala_assert (_data_->_tmp9__length1 == 0, "messages.length == 0"); + _data_->_tmp10_ = _data_->test; + test_post_message (_data_->_tmp10_, "round-trip", &_data_->_inner_error0_); + if (G_UNLIKELY (_data_->_inner_error0_ != NULL)) { + _data_->messages = (_vala_array_free (_data_->messages, _data_->messages_length1, (GDestroyNotify) g_free), NULL); + _g_object_unref0 (_data_->connection); + _g_object_unref0 (_data_->test); + block1_data_unref (_data_->_data1_); + _data_->_data1_ = NULL; + g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _data_->_inner_error0_->message, g_quark_to_string (_data_->_inner_error0_->domain), _data_->_inner_error0_->code); + g_clear_error (&_data_->_inner_error0_); + g_object_unref (_data_->_async_result); + return FALSE; + } + _data_->_tmp11_ = _data_->_data1_->events; + _data_->_tmp12_ = g_async_queue_pop (_data_->_tmp11_); + _data_->_tmp13_ = (gchar*) _data_->_tmp12_; + _vala_assert (g_strcmp0 (_data_->_tmp13_, "G_DBUS_MESSAGE_FLAGS_NONE") == 0, "events.pop () == \"G_DBUS_MESSAGE_FLAGS_NONE\""); + _g_free0 (_data_->_tmp13_); + _data_->_tmp14_ = _data_->_data1_->events; + _data_->_tmp15_ = g_async_queue_try_pop (_data_->_tmp14_); + _data_->_tmp16_ = (gchar*) _data_->_tmp15_; + _vala_assert (_data_->_tmp16_ == NULL, "events.try_pop () == null"); + _g_free0 (_data_->_tmp16_); + _data_->_tmp17_ = _data_->test; + test_post_message_no_reply (_data_->_tmp17_, "fire-and-forget", &_data_->_inner_error0_); + if (G_UNLIKELY (_data_->_inner_error0_ != NULL)) { + _data_->messages = (_vala_array_free (_data_->messages, _data_->messages_length1, (GDestroyNotify) g_free), NULL); + _g_object_unref0 (_data_->connection); + _g_object_unref0 (_data_->test); + block1_data_unref (_data_->_data1_); + _data_->_data1_ = NULL; + g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _data_->_inner_error0_->message, g_quark_to_string (_data_->_inner_error0_->domain), _data_->_inner_error0_->code); + g_clear_error (&_data_->_inner_error0_); + g_object_unref (_data_->_async_result); + return FALSE; + } + _data_->_tmp18_ = _data_->_data1_->events; + _data_->_tmp19_ = g_async_queue_pop (_data_->_tmp18_); + _data_->_tmp20_ = (gchar*) _data_->_tmp19_; + _vala_assert (g_strcmp0 (_data_->_tmp20_, "G_DBUS_MESSAGE_FLAGS_NO_REPLY_EXPECTED") == 0, "events.pop () == \"G_DBUS_MESSAGE_FLAGS_NO_REPLY_EXPECTED\""); + _g_free0 (_data_->_tmp20_); + _data_->_tmp21_ = _data_->_data1_->events; + _data_->_tmp22_ = g_async_queue_try_pop (_data_->_tmp21_); + _data_->_tmp23_ = (gchar*) _data_->_tmp22_; + _vala_assert (_data_->_tmp23_ == NULL, "events.try_pop () == null"); + _g_free0 (_data_->_tmp23_); + _data_->_tmp25_ = _data_->test; + _data_->_tmp26_ = 0; + _data_->_tmp27_ = test_list_messages (_data_->_tmp25_, &_data_->_tmp26_, &_data_->_inner_error0_); + _data_->_tmp24_ = _data_->_tmp27_; + _data_->_tmp24__length1 = _data_->_tmp26_; + _data_->__tmp24__size_ = _data_->_tmp24__length1; + if (G_UNLIKELY (_data_->_inner_error0_ != NULL)) { + _data_->messages = (_vala_array_free (_data_->messages, _data_->messages_length1, (GDestroyNotify) g_free), NULL); + _g_object_unref0 (_data_->connection); + _g_object_unref0 (_data_->test); + block1_data_unref (_data_->_data1_); + _data_->_data1_ = NULL; + g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _data_->_inner_error0_->message, g_quark_to_string (_data_->_inner_error0_->domain), _data_->_inner_error0_->code); + g_clear_error (&_data_->_inner_error0_); + g_object_unref (_data_->_async_result); + return FALSE; + } + _data_->_tmp28_ = _data_->_tmp24_; + _data_->_tmp28__length1 = _data_->_tmp24__length1; + _data_->_tmp24_ = NULL; + _data_->_tmp24__length1 = 0; + _data_->messages = (_vala_array_free (_data_->messages, _data_->messages_length1, (GDestroyNotify) g_free), NULL); + _data_->messages = _data_->_tmp28_; + _data_->messages_length1 = _data_->_tmp28__length1; + _data_->_messages_size_ = _data_->messages_length1; + _data_->_tmp29_ = _data_->messages; + _data_->_tmp29__length1 = _data_->messages_length1; + _vala_assert (_data_->_tmp29__length1 == 2, "messages.length == 2"); + _data_->_tmp30_ = _data_->messages; + _data_->_tmp30__length1 = _data_->messages_length1; + _data_->_tmp31_ = _data_->_tmp30_[0]; + _vala_assert (g_strcmp0 (_data_->_tmp31_, "round-trip") == 0, "messages[0] == \"round-trip\""); + _data_->_tmp32_ = _data_->messages; + _data_->_tmp32__length1 = _data_->messages_length1; + _data_->_tmp33_ = _data_->_tmp32_[1]; + _vala_assert (g_strcmp0 (_data_->_tmp33_, "fire-and-forget") == 0, "messages[1] == \"fire-and-forget\""); + _data_->_tmp34_ = main_loop; + g_main_loop_quit (_data_->_tmp34_); + _data_->_tmp24_ = (_vala_array_free (_data_->_tmp24_, _data_->_tmp24__length1, (GDestroyNotify) g_free), NULL); + _data_->messages = (_vala_array_free (_data_->messages, _data_->messages_length1, (GDestroyNotify) g_free), NULL); + _g_object_unref0 (_data_->connection); + _g_object_unref0 (_data_->test); + block1_data_unref (_data_->_data1_); + _data_->_data1_ = NULL; + g_task_return_pointer (_data_->_async_result, _data_, NULL); + if (_data_->_state_ != 0) { + while (!g_task_get_completed (_data_->_async_result)) { + g_main_context_iteration (g_task_get_context (_data_->_async_result), TRUE); + } + } + g_object_unref (_data_->_async_result); + return FALSE; +} + +static void +_vala_main (void) +{ + GMainLoop* _tmp0_; + GMainLoop* _tmp1_; + run (NULL, NULL); + _tmp0_ = g_main_loop_new (NULL, FALSE); + _g_main_loop_unref0 (main_loop); + main_loop = _tmp0_; + _tmp1_ = main_loop; + g_main_loop_run (_tmp1_); +} + +int +main (int argc, + char ** argv) +{ + _vala_main (); + return 0; +} + +static void +_vala_array_destroy (gpointer array, + gssize array_length, + GDestroyNotify destroy_func) +{ + if ((array != NULL) && (destroy_func != NULL)) { + gssize i; + for (i = 0; i < array_length; i = i + 1) { + if (((gpointer*) array)[i] != NULL) { + destroy_func (((gpointer*) array)[i]); + } + } + } +} + +static void +_vala_array_free (gpointer array, + gssize array_length, + GDestroyNotify destroy_func) +{ + _vala_array_destroy (array, array_length, destroy_func); + g_free (array); +} + diff --git a/tests/dbus/no-reply_server.c-expected b/tests/dbus/no-reply_server.c-expected new file mode 100644 index 000000000..1d719cde6 --- /dev/null +++ b/tests/dbus/no-reply_server.c-expected @@ -0,0 +1,632 @@ +/* dbus_no_reply_server.c generated by valac, the Vala compiler + * generated from dbus_no_reply_server.vala, do not modify */ + +#include <glib-object.h> +#include <gio/gio.h> +#include <stdlib.h> +#include <string.h> +#include <glib.h> + +#if !defined(VALA_EXTERN) +#if defined(_MSC_VER) +#define VALA_EXTERN __declspec(dllexport) extern +#elif __GNUC__ >= 4 +#define VALA_EXTERN __attribute__((visibility("default"))) extern +#else +#define VALA_EXTERN extern +#endif +#endif + +#define TYPE_TEST (test_get_type ()) +#define TEST(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TYPE_TEST, Test)) +#define TEST_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), TYPE_TEST, TestClass)) +#define IS_TEST(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TYPE_TEST)) +#define IS_TEST_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), TYPE_TEST)) +#define TEST_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), TYPE_TEST, TestClass)) + +typedef struct _Test Test; +typedef struct _TestClass TestClass; +typedef struct _TestPrivate TestPrivate; +enum { + TEST_0_PROPERTY, + TEST_NUM_PROPERTIES +}; +static GParamSpec* test_properties[TEST_NUM_PROPERTIES]; +#define _g_free0(var) (var = (g_free (var), NULL)) +#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL))) +#define _g_variant_unref0(var) ((var == NULL) ? NULL : (var = (g_variant_unref (var), NULL))) +#define _g_main_loop_unref0(var) ((var == NULL) ? NULL : (var = (g_main_loop_unref (var), NULL))) +#define _vala_assert(expr, msg) if G_LIKELY (expr) ; else g_assertion_message_expr (G_LOG_DOMAIN, __FILE__, __LINE__, G_STRFUNC, msg); +#define _vala_return_if_fail(expr, msg) if G_LIKELY (expr) ; else { g_return_if_fail_warning (G_LOG_DOMAIN, G_STRFUNC, msg); return; } +#define _vala_return_val_if_fail(expr, msg, val) if G_LIKELY (expr) ; else { g_return_if_fail_warning (G_LOG_DOMAIN, G_STRFUNC, msg); return val; } +#define _vala_warn_if_fail(expr, msg) if G_LIKELY (expr) ; else g_warn_message (G_LOG_DOMAIN, __FILE__, __LINE__, G_STRFUNC, msg); + +struct _Test { + GObject parent_instance; + TestPrivate * priv; +}; + +struct _TestClass { + GObjectClass parent_class; +}; + +struct _TestPrivate { + gchar** messages; + gint messages_length1; + gint _messages_size_; +}; + +static gint Test_private_offset; +static gpointer test_parent_class = NULL; +VALA_EXTERN GMainLoop* main_loop; +GMainLoop* main_loop = NULL; + +VALA_EXTERN GType test_get_type (void) G_GNUC_CONST ; +G_DEFINE_AUTOPTR_CLEANUP_FUNC (Test, g_object_unref) +VALA_EXTERN guint test_register_object (void* object, + GDBusConnection* connection, + const gchar* path, + GError** error); +VALA_EXTERN gchar** test_list_messages (Test* self, + gint* result_length1); +static gchar** _vala_array_dup1 (gchar** self, + gssize length); +VALA_EXTERN void test_post_message (Test* self, + const gchar* message); +static void _vala_array_add1 (gchar** * array, + gint* length, + gint* size, + gchar* value); +VALA_EXTERN void test_post_message_no_reply (Test* self, + const gchar* message); +static void _vala_array_add2 (gchar** * array, + gint* length, + gint* size, + gchar* value); +VALA_EXTERN Test* test_new (void); +VALA_EXTERN Test* test_construct (GType object_type); +static void test_finalize (GObject * obj); +static GType test_get_type_once (void); +static void _dbus_test_list_messages (Test* self, + GVariant* _parameters_, + GDBusMethodInvocation* invocation); +static void _dbus_test_post_message (Test* self, + GVariant* _parameters_, + GDBusMethodInvocation* invocation); +static void _dbus_test_post_message_no_reply (Test* self, + GVariant* _parameters_, + GDBusMethodInvocation* invocation); +static void test_dbus_interface_method_call (GDBusConnection* connection, + const gchar* sender, + const gchar* object_path, + const gchar* interface_name, + const gchar* method_name, + GVariant* parameters, + GDBusMethodInvocation* invocation, + gpointer user_data); +static GVariant* test_dbus_interface_get_property (GDBusConnection* connection, + const gchar* sender, + const gchar* object_path, + const gchar* interface_name, + const gchar* property_name, + GError** error, + gpointer user_data); +static gboolean test_dbus_interface_set_property (GDBusConnection* connection, + const gchar* sender, + const gchar* object_path, + const gchar* interface_name, + const gchar* property_name, + GVariant* value, + GError** error, + gpointer user_data); +static void _test_unregister_object (gpointer user_data); +VALA_EXTERN void client_exit (GPid pid, + gint status); +static void _vala_main (void); +static guint _variant_get1 (GVariant* value); +static void _client_exit_gchild_watch_func (GPid pid, + gint wait_status, + gpointer self); +static void _vala_array_destroy (gpointer array, + gssize array_length, + GDestroyNotify destroy_func); +static void _vala_array_free (gpointer array, + gssize array_length, + GDestroyNotify destroy_func); + +static const GDBusArgInfo _test_dbus_arg_info_list_messages_result = {-1, "result", "as", NULL}; +static const GDBusArgInfo * const _test_dbus_arg_info_list_messages_in[] = {NULL}; +static const GDBusArgInfo * const _test_dbus_arg_info_list_messages_out[] = {&_test_dbus_arg_info_list_messages_result, NULL}; +static const GDBusMethodInfo _test_dbus_method_info_list_messages = {-1, "ListMessages", (GDBusArgInfo **) (&_test_dbus_arg_info_list_messages_in), (GDBusArgInfo **) (&_test_dbus_arg_info_list_messages_out), NULL}; +static const GDBusArgInfo _test_dbus_arg_info_post_message_message = {-1, "message", "s", NULL}; +static const GDBusArgInfo * const _test_dbus_arg_info_post_message_in[] = {&_test_dbus_arg_info_post_message_message, NULL}; +static const GDBusArgInfo * const _test_dbus_arg_info_post_message_out[] = {NULL}; +static const GDBusMethodInfo _test_dbus_method_info_post_message = {-1, "PostMessage", (GDBusArgInfo **) (&_test_dbus_arg_info_post_message_in), (GDBusArgInfo **) (&_test_dbus_arg_info_post_message_out), NULL}; +static const GDBusArgInfo _test_dbus_arg_info_post_message_no_reply_message = {-1, "message", "s", NULL}; +static const GDBusArgInfo * const _test_dbus_arg_info_post_message_no_reply_in[] = {&_test_dbus_arg_info_post_message_no_reply_message, NULL}; +static const GDBusArgInfo * const _test_dbus_arg_info_post_message_no_reply_out[] = {NULL}; +static const GDBusMethodInfo _test_dbus_method_info_post_message_no_reply = {-1, "PostMessageNoReply", (GDBusArgInfo **) (&_test_dbus_arg_info_post_message_no_reply_in), (GDBusArgInfo **) (&_test_dbus_arg_info_post_message_no_reply_out), NULL}; +static const GDBusMethodInfo * const _test_dbus_method_info[] = {&_test_dbus_method_info_list_messages, &_test_dbus_method_info_post_message, &_test_dbus_method_info_post_message_no_reply, NULL}; +static const GDBusSignalInfo * const _test_dbus_signal_info[] = {NULL}; +static const GDBusPropertyInfo * const _test_dbus_property_info[] = {NULL}; +static const GDBusInterfaceInfo _test_dbus_interface_info = {-1, "org.example.Test", (GDBusMethodInfo **) (&_test_dbus_method_info), (GDBusSignalInfo **) (&_test_dbus_signal_info), (GDBusPropertyInfo **) (&_test_dbus_property_info), NULL}; +static const GDBusInterfaceVTable _test_dbus_interface_vtable = {test_dbus_interface_method_call, test_dbus_interface_get_property, test_dbus_interface_set_property}; + +static inline gpointer +test_get_instance_private (Test* self) +{ + return G_STRUCT_MEMBER_P (self, Test_private_offset); +} + +static gchar** +_vala_array_dup1 (gchar** self, + gssize length) +{ + if (length >= 0) { + gchar** result; + gssize i; + result = g_new0 (gchar*, length + 1); + for (i = 0; i < length; i++) { + gchar* _tmp0_; + _tmp0_ = g_strdup (self[i]); + result[i] = _tmp0_; + } + return result; + } + return NULL; +} + +gchar** +test_list_messages (Test* self, + gint* result_length1) +{ + gchar** _tmp0_; + gint _tmp0__length1; + gchar** _tmp1_; + gint _tmp1__length1; + gchar** _tmp2_; + gint _tmp2__length1; + gchar** result = NULL; + g_return_val_if_fail (IS_TEST (self), NULL); + _tmp0_ = self->priv->messages; + _tmp0__length1 = self->priv->messages_length1; + _tmp1_ = (_tmp0_ != NULL) ? _vala_array_dup1 (_tmp0_, _tmp0__length1) : _tmp0_; + _tmp1__length1 = _tmp0__length1; + _tmp2_ = _tmp1_; + _tmp2__length1 = _tmp1__length1; + if (result_length1) { + *result_length1 = _tmp2__length1; + } + result = _tmp2_; + return result; +} + +static void +_vala_array_add1 (gchar** * array, + gint* length, + gint* size, + gchar* value) +{ + if ((*length) == (*size)) { + *size = (*size) ? (2 * (*size)) : 4; + *array = g_renew (gchar*, *array, (*size) + 1); + } + (*array)[(*length)++] = value; + (*array)[*length] = NULL; +} + +void +test_post_message (Test* self, + const gchar* message) +{ + gchar* _tmp0_; + g_return_if_fail (IS_TEST (self)); + g_return_if_fail (message != NULL); + _tmp0_ = g_strdup (message); + _vala_array_add1 (&self->priv->messages, &self->priv->messages_length1, &self->priv->_messages_size_, _tmp0_); +} + +static void +_vala_array_add2 (gchar** * array, + gint* length, + gint* size, + gchar* value) +{ + if ((*length) == (*size)) { + *size = (*size) ? (2 * (*size)) : 4; + *array = g_renew (gchar*, *array, (*size) + 1); + } + (*array)[(*length)++] = value; + (*array)[*length] = NULL; +} + +void +test_post_message_no_reply (Test* self, + const gchar* message) +{ + gchar* _tmp0_; + g_return_if_fail (IS_TEST (self)); + g_return_if_fail (message != NULL); + _tmp0_ = g_strdup (message); + _vala_array_add2 (&self->priv->messages, &self->priv->messages_length1, &self->priv->_messages_size_, _tmp0_); +} + +Test* +test_construct (GType object_type) +{ + Test * self = NULL; + self = (Test*) g_object_new (object_type, NULL); + return self; +} + +Test* +test_new (void) +{ + return test_construct (TYPE_TEST); +} + +static void +test_class_init (TestClass * klass, + gpointer klass_data) +{ + test_parent_class = g_type_class_peek_parent (klass); + g_type_class_adjust_private_offset (klass, &Test_private_offset); + G_OBJECT_CLASS (klass)->finalize = test_finalize; +} + +static void +test_instance_init (Test * self, + gpointer klass) +{ + gchar** _tmp0_; + self->priv = test_get_instance_private (self); + _tmp0_ = g_new0 (gchar*, 0 + 1); + self->priv->messages = _tmp0_; + self->priv->messages_length1 = 0; + self->priv->_messages_size_ = self->priv->messages_length1; +} + +static void +test_finalize (GObject * obj) +{ + Test * self; + self = G_TYPE_CHECK_INSTANCE_CAST (obj, TYPE_TEST, Test); + self->priv->messages = (_vala_array_free (self->priv->messages, self->priv->messages_length1, (GDestroyNotify) g_free), NULL); + G_OBJECT_CLASS (test_parent_class)->finalize (obj); +} + +static GType +test_get_type_once (void) +{ + static const GTypeInfo g_define_type_info = { sizeof (TestClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) test_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (Test), 0, (GInstanceInitFunc) test_instance_init, NULL }; + GType test_type_id; + test_type_id = g_type_register_static (G_TYPE_OBJECT, "Test", &g_define_type_info, 0); + g_type_set_qdata (test_type_id, g_quark_from_static_string ("vala-dbus-register-object"), (void*) test_register_object); + Test_private_offset = g_type_add_instance_private (test_type_id, sizeof (TestPrivate)); + return test_type_id; +} + +GType +test_get_type (void) +{ + static volatile gsize test_type_id__volatile = 0; + if (g_once_init_enter (&test_type_id__volatile)) { + GType test_type_id; + test_type_id = test_get_type_once (); + g_once_init_leave (&test_type_id__volatile, test_type_id); + } + return test_type_id__volatile; +} + +static void +_dbus_test_list_messages (Test* self, + GVariant* _parameters_, + GDBusMethodInvocation* invocation) +{ + GError* error = NULL; + GVariantIter _arguments_iter; + GDBusMessage* _reply_message = NULL; + GVariant* _reply; + GVariantBuilder _reply_builder; + gchar** result; + gint result_length1 = 0; + gchar** _tmp0_; + GVariantBuilder _tmp1_; + gint _tmp2_; + g_variant_iter_init (&_arguments_iter, _parameters_); + result = test_list_messages (self, &result_length1); + _reply_message = g_dbus_message_new_method_reply (g_dbus_method_invocation_get_message (invocation)); + g_variant_builder_init (&_reply_builder, G_VARIANT_TYPE_TUPLE); + _tmp0_ = result; + g_variant_builder_init (&_tmp1_, G_VARIANT_TYPE ("as")); + for (_tmp2_ = 0; _tmp2_ < result_length1; _tmp2_++) { + g_variant_builder_add_value (&_tmp1_, g_variant_new_string (*_tmp0_)); + _tmp0_++; + } + g_variant_builder_add_value (&_reply_builder, g_variant_builder_end (&_tmp1_)); + result = (_vala_array_free (result, result_length1, (GDestroyNotify) g_free), NULL); + _reply = g_variant_builder_end (&_reply_builder); + g_dbus_message_set_body (_reply_message, _reply); + g_dbus_connection_send_message (g_dbus_method_invocation_get_connection (invocation), _reply_message, G_DBUS_SEND_MESSAGE_FLAGS_NONE, NULL, NULL); + g_object_unref (invocation); + g_object_unref (_reply_message); +} + +static void +_dbus_test_post_message (Test* self, + GVariant* _parameters_, + GDBusMethodInvocation* invocation) +{ + GError* error = NULL; + GVariantIter _arguments_iter; + gchar* message = NULL; + GVariant* _tmp3_; + GDBusMessage* _reply_message = NULL; + GVariant* _reply; + GVariantBuilder _reply_builder; + g_variant_iter_init (&_arguments_iter, _parameters_); + _tmp3_ = g_variant_iter_next_value (&_arguments_iter); + message = g_variant_dup_string (_tmp3_, NULL); + g_variant_unref (_tmp3_); + test_post_message (self, message); + _reply_message = g_dbus_message_new_method_reply (g_dbus_method_invocation_get_message (invocation)); + g_variant_builder_init (&_reply_builder, G_VARIANT_TYPE_TUPLE); + _reply = g_variant_builder_end (&_reply_builder); + g_dbus_message_set_body (_reply_message, _reply); + g_dbus_connection_send_message (g_dbus_method_invocation_get_connection (invocation), _reply_message, G_DBUS_SEND_MESSAGE_FLAGS_NONE, NULL, NULL); + g_object_unref (invocation); + g_object_unref (_reply_message); + _g_free0 (message); +} + +static void +_dbus_test_post_message_no_reply (Test* self, + GVariant* _parameters_, + GDBusMethodInvocation* invocation) +{ + GError* error = NULL; + GVariantIter _arguments_iter; + gchar* message = NULL; + GVariant* _tmp4_; + g_variant_iter_init (&_arguments_iter, _parameters_); + _tmp4_ = g_variant_iter_next_value (&_arguments_iter); + message = g_variant_dup_string (_tmp4_, NULL); + g_variant_unref (_tmp4_); + test_post_message_no_reply (self, message); + _g_free0 (message); +} + +static void +test_dbus_interface_method_call (GDBusConnection* connection, + const gchar* sender, + const gchar* object_path, + const gchar* interface_name, + const gchar* method_name, + GVariant* parameters, + GDBusMethodInvocation* invocation, + gpointer user_data) +{ + gpointer* data; + gpointer object; + data = user_data; + object = data[0]; + if (strcmp (method_name, "ListMessages") == 0) { + _dbus_test_list_messages (object, parameters, invocation); + } else if (strcmp (method_name, "PostMessage") == 0) { + _dbus_test_post_message (object, parameters, invocation); + } else if (strcmp (method_name, "PostMessageNoReply") == 0) { + _dbus_test_post_message_no_reply (object, parameters, invocation); + } else { + g_object_unref (invocation); + } +} + +static GVariant* +test_dbus_interface_get_property (GDBusConnection* connection, + const gchar* sender, + const gchar* object_path, + const gchar* interface_name, + const gchar* property_name, + GError** error, + gpointer user_data) +{ + gpointer* data; + gpointer object; + data = user_data; + object = data[0]; + return NULL; +} + +static gboolean +test_dbus_interface_set_property (GDBusConnection* connection, + const gchar* sender, + const gchar* object_path, + const gchar* interface_name, + const gchar* property_name, + GVariant* value, + GError** error, + gpointer user_data) +{ + gpointer* data; + gpointer object; + data = user_data; + object = data[0]; + return FALSE; +} + +guint +test_register_object (gpointer object, + GDBusConnection* connection, + const gchar* path, + GError** error) +{ + guint result; + gpointer *data; + data = g_new (gpointer, 3); + data[0] = g_object_ref (object); + data[1] = g_object_ref (connection); + data[2] = g_strdup (path); + result = g_dbus_connection_register_object (connection, path, (GDBusInterfaceInfo *) (&_test_dbus_interface_info), &_test_dbus_interface_vtable, data, _test_unregister_object, error); + if (!result) { + return 0; + } + return result; +} + +static void +_test_unregister_object (gpointer user_data) +{ + gpointer* data; + data = user_data; + g_object_unref (data[0]); + g_object_unref (data[1]); + g_free (data[2]); + g_free (data); +} + +void +client_exit (GPid pid, + gint status) +{ + GMainLoop* _tmp0_; + _vala_assert (status == 0, "status == 0"); + _tmp0_ = main_loop; + g_main_loop_quit (_tmp0_); +} + +static guint +_variant_get1 (GVariant* value) +{ + return g_variant_get_uint32 (value); +} + +static void +_client_exit_gchild_watch_func (GPid pid, + gint wait_status, + gpointer self) +{ + client_exit (pid, wait_status); +} + +static void +_vala_main (void) +{ + GDBusConnection* conn = NULL; + GDBusConnection* _tmp0_; + GDBusConnection* _tmp1_; + Test* _tmp2_; + Test* _tmp3_; + GVariant* request_result = NULL; + GDBusConnection* _tmp4_; + GVariant* _tmp5_; + GVariant* _tmp6_; + GVariant* _tmp7_; + GVariant* _tmp8_; + GVariant* _tmp9_; + GVariant* _tmp10_; + GVariant* _tmp11_; + guint _tmp12_; + GPid client_pid = 0; + gchar* _tmp13_; + gchar** _tmp14_; + gchar** _tmp15_; + gint _tmp15__length1; + GPid _tmp16_ = 0; + GMainLoop* _tmp17_; + GMainLoop* _tmp18_; + GError* _inner_error0_ = NULL; + _tmp0_ = g_bus_get_sync (G_BUS_TYPE_SESSION, NULL, &_inner_error0_); + conn = _tmp0_; + if (G_UNLIKELY (_inner_error0_ != NULL)) { + g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error0_->message, g_quark_to_string (_inner_error0_->domain), _inner_error0_->code); + g_clear_error (&_inner_error0_); + return; + } + _tmp1_ = conn; + _tmp2_ = test_new (); + _tmp3_ = _tmp2_; + test_register_object (_tmp3_, _tmp1_, "/org/example/Test", &_inner_error0_); + _g_object_unref0 (_tmp3_); + if (G_UNLIKELY (_inner_error0_ != NULL)) { + _g_object_unref0 (conn); + g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error0_->message, g_quark_to_string (_inner_error0_->domain), _inner_error0_->code); + g_clear_error (&_inner_error0_); + return; + } + _tmp4_ = conn; + _tmp5_ = g_variant_new ("(su)", "org.example.Test", 0x4, NULL); + g_variant_ref_sink (_tmp5_); + _tmp6_ = _tmp5_; + _tmp7_ = g_dbus_connection_call_sync (_tmp4_, "org.freedesktop.DBus", "/org/freedesktop/DBus", "org.freedesktop.DBus", "RequestName", _tmp6_, NULL, 0, -1, NULL, &_inner_error0_); + _tmp8_ = _tmp7_; + _g_variant_unref0 (_tmp6_); + request_result = _tmp8_; + if (G_UNLIKELY (_inner_error0_ != NULL)) { + _g_object_unref0 (conn); + g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error0_->message, g_quark_to_string (_inner_error0_->domain), _inner_error0_->code); + g_clear_error (&_inner_error0_); + return; + } + _tmp9_ = request_result; + _tmp10_ = g_variant_get_child_value (_tmp9_, (gsize) 0); + _tmp11_ = _tmp10_; + _tmp12_ = _variant_get1 (_tmp11_); + _vala_assert (_tmp12_ == ((guint) 1), "(uint) request_result.get_child_value (0) == 1"); + _g_variant_unref0 (_tmp11_); + _tmp13_ = g_strdup ("dbus_no_reply_client"); + _tmp14_ = g_new0 (gchar*, 1 + 1); + _tmp14_[0] = _tmp13_; + _tmp15_ = _tmp14_; + _tmp15__length1 = 1; + g_spawn_async (NULL, _tmp15_, NULL, G_SPAWN_DO_NOT_REAP_CHILD, NULL, NULL, &_tmp16_, &_inner_error0_); + client_pid = _tmp16_; + _tmp15_ = (_vala_array_free (_tmp15_, _tmp15__length1, (GDestroyNotify) g_free), NULL); + if (G_UNLIKELY (_inner_error0_ != NULL)) { + _g_variant_unref0 (request_result); + _g_object_unref0 (conn); + g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error0_->message, g_quark_to_string (_inner_error0_->domain), _inner_error0_->code); + g_clear_error (&_inner_error0_); + return; + } + g_child_watch_add_full (G_PRIORITY_DEFAULT_IDLE, client_pid, _client_exit_gchild_watch_func, NULL, NULL); + _tmp17_ = g_main_loop_new (NULL, FALSE); + _g_main_loop_unref0 (main_loop); + main_loop = _tmp17_; + _tmp18_ = main_loop; + g_main_loop_run (_tmp18_); + _g_variant_unref0 (request_result); + _g_object_unref0 (conn); +} + +int +main (int argc, + char ** argv) +{ + _vala_main (); + return 0; +} + +static void +_vala_array_destroy (gpointer array, + gssize array_length, + GDestroyNotify destroy_func) +{ + if ((array != NULL) && (destroy_func != NULL)) { + gssize i; + for (i = 0; i < array_length; i = i + 1) { + if (((gpointer*) array)[i] != NULL) { + destroy_func (((gpointer*) array)[i]); + } + } + } +} + +static void +_vala_array_free (gpointer array, + gssize array_length, + GDestroyNotify destroy_func) +{ + _vala_array_destroy (array, array_length, destroy_func); + g_free (array); +} + diff --git a/tests/dbus/rawvariants_client.c-expected b/tests/dbus/rawvariants_client.c-expected new file mode 100644 index 000000000..287614547 --- /dev/null +++ b/tests/dbus/rawvariants_client.c-expected @@ -0,0 +1,1277 @@ +/* dbus_rawvariants_client.c generated by valac, the Vala compiler + * generated from dbus_rawvariants_client.vala, do not modify */ + +#include <glib-object.h> +#include <gio/gio.h> +#include <glib.h> +#include <stdlib.h> +#include <string.h> + +#if !defined(VALA_EXTERN) +#if defined(_MSC_VER) +#define VALA_EXTERN __declspec(dllexport) extern +#elif __GNUC__ >= 4 +#define VALA_EXTERN __attribute__((visibility("default"))) extern +#else +#define VALA_EXTERN extern +#endif +#endif + +#define TYPE_TEST (test_get_type ()) +#define TEST(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TYPE_TEST, Test)) +#define IS_TEST(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TYPE_TEST)) +#define TEST_GET_INTERFACE(obj) (G_TYPE_INSTANCE_GET_INTERFACE ((obj), TYPE_TEST, TestIface)) + +typedef struct _Test Test; +typedef struct _TestIface TestIface; + +#define TYPE_TEST_PROXY (test_proxy_get_type ()) +enum { + TEST_TEST_SIGNAL_SIGNAL, + TEST_NUM_SIGNALS +}; +static guint test_signals[TEST_NUM_SIGNALS] = {0}; +typedef GDBusProxy TestProxy; +typedef GDBusProxyClass TestProxyClass; +#define _g_free0(var) (var = (g_free (var), NULL)) + +#define TYPE_TEST_RAW (test_raw_get_type ()) +#define TEST_RAW(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TYPE_TEST_RAW, TestRaw)) +#define IS_TEST_RAW(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TYPE_TEST_RAW)) +#define TEST_RAW_GET_INTERFACE(obj) (G_TYPE_INSTANCE_GET_INTERFACE ((obj), TYPE_TEST_RAW, TestRawIface)) + +typedef struct _TestRaw TestRaw; +typedef struct _TestRawIface TestRawIface; + +#define TYPE_TEST_RAW_PROXY (test_raw_proxy_get_type ()) +enum { + TEST_RAW_TEST_SIGNAL_SIGNAL, + TEST_RAW_NUM_SIGNALS +}; +static guint test_raw_signals[TEST_RAW_NUM_SIGNALS] = {0}; +typedef GDBusProxy TestRawProxy; +typedef GDBusProxyClass TestRawProxyClass; +#define _g_variant_unref0(var) ((var == NULL) ? NULL : (var = (g_variant_unref (var), NULL))) +typedef struct _Block1Data Block1Data; +#define _g_main_loop_unref0(var) ((var == NULL) ? NULL : (var = (g_main_loop_unref (var), NULL))) +typedef struct _Block2Data Block2Data; +#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL))) +#define _vala_assert(expr, msg) if G_LIKELY (expr) ; else g_assertion_message_expr (G_LOG_DOMAIN, __FILE__, __LINE__, G_STRFUNC, msg); +#define _vala_return_if_fail(expr, msg) if G_LIKELY (expr) ; else { g_return_if_fail_warning (G_LOG_DOMAIN, G_STRFUNC, msg); return; } +#define _vala_return_val_if_fail(expr, msg, val) if G_LIKELY (expr) ; else { g_return_if_fail_warning (G_LOG_DOMAIN, G_STRFUNC, msg); return val; } +#define _vala_warn_if_fail(expr, msg) if G_LIKELY (expr) ; else g_warn_message (G_LOG_DOMAIN, __FILE__, __LINE__, G_STRFUNC, msg); + +struct _TestIface { + GTypeInterface parent_iface; + gint (*test_method) (Test* self, gint j, gint k, GError** error); + gchar* (*get_test_property) (Test* self); + void (*set_test_property) (Test* self, const gchar* value); +}; + +struct _TestRawIface { + GTypeInterface parent_iface; + GVariant* (*test_method) (TestRaw* self, GVariant* j, GVariant* k, GError** error); + GVariant* (*get_test_property) (TestRaw* self); + void (*set_test_property) (TestRaw* self, GVariant* value); +}; + +struct _Block1Data { + int _ref_count_; + GMainLoop* main_loop; +}; + +struct _Block2Data { + int _ref_count_; + GMainLoop* main_loop; +}; + +VALA_EXTERN GType test_proxy_get_type (void) G_GNUC_CONST ; +VALA_EXTERN guint test_register_object (void* object, + GDBusConnection* connection, + const gchar* path, + GError** error); +VALA_EXTERN GType test_get_type (void) G_GNUC_CONST ; +VALA_EXTERN gint test_test_method (Test* self, + gint j, + gint k, + GError** error); +VALA_EXTERN gchar* test_get_test_property (Test* self); +VALA_EXTERN void test_set_test_property (Test* self, + const gchar* value); +static GType test_get_type_once (void); +static void test_proxy_g_signal (GDBusProxy* proxy, + const gchar* sender_name, + const gchar* signal_name, + GVariant* parameters); +static void _dbus_handle_test_test_signal (Test* self, + GVariant* parameters); +static gint test_proxy_test_method (Test* self, + gint j, + gint k, + GError** error); +static gchar* test_dbus_proxy_get_test_property (Test* self); +static void test_dbus_proxy_set_test_property (Test* self, + const gchar* value); +static void test_proxy_test_interface_init (TestIface* iface); +static void _dbus_test_test_method (Test* self, + GVariant* _parameters_, + GDBusMethodInvocation* invocation); +static void test_dbus_interface_method_call (GDBusConnection* connection, + const gchar* sender, + const gchar* object_path, + const gchar* interface_name, + const gchar* method_name, + GVariant* parameters, + GDBusMethodInvocation* invocation, + gpointer user_data); +static GVariant* test_dbus_interface_get_property (GDBusConnection* connection, + const gchar* sender, + const gchar* object_path, + const gchar* interface_name, + const gchar* property_name, + GError** error, + gpointer user_data); +static GVariant* _dbus_test_get_test_property (Test* self); +static gboolean test_dbus_interface_set_property (GDBusConnection* connection, + const gchar* sender, + const gchar* object_path, + const gchar* interface_name, + const gchar* property_name, + GVariant* value, + GError** error, + gpointer user_data); +static void _dbus_test_set_test_property (Test* self, + GVariant* _value); +static void _dbus_test_test_signal (GObject* _sender, + gint i, + gpointer* _data); +static void _test_unregister_object (gpointer user_data); +VALA_EXTERN GType test_raw_proxy_get_type (void) G_GNUC_CONST ; +VALA_EXTERN guint test_raw_register_object (void* object, + GDBusConnection* connection, + const gchar* path, + GError** error); +VALA_EXTERN GType test_raw_get_type (void) G_GNUC_CONST ; +VALA_EXTERN GVariant* test_raw_test_method (TestRaw* self, + GVariant* j, + GVariant* k, + GError** error); +VALA_EXTERN GVariant* test_raw_get_test_property (TestRaw* self); +VALA_EXTERN void test_raw_set_test_property (TestRaw* self, + GVariant* value); +static GType test_raw_get_type_once (void); +static void test_raw_proxy_g_signal (GDBusProxy* proxy, + const gchar* sender_name, + const gchar* signal_name, + GVariant* parameters); +static void _dbus_handle_test_raw_test_signal (TestRaw* self, + GVariant* parameters); +static GVariant* test_raw_proxy_test_method (TestRaw* self, + GVariant* j, + GVariant* k, + GError** error); +static GVariant* test_raw_dbus_proxy_get_test_property (TestRaw* self); +static void test_raw_dbus_proxy_set_test_property (TestRaw* self, + GVariant* value); +static void test_raw_proxy_test_raw_interface_init (TestRawIface* iface); +static void _dbus_test_raw_test_method (TestRaw* self, + GVariant* _parameters_, + GDBusMethodInvocation* invocation); +static void test_raw_dbus_interface_method_call (GDBusConnection* connection, + const gchar* sender, + const gchar* object_path, + const gchar* interface_name, + const gchar* method_name, + GVariant* parameters, + GDBusMethodInvocation* invocation, + gpointer user_data); +static GVariant* test_raw_dbus_interface_get_property (GDBusConnection* connection, + const gchar* sender, + const gchar* object_path, + const gchar* interface_name, + const gchar* property_name, + GError** error, + gpointer user_data); +static GVariant* _dbus_test_raw_get_test_property (TestRaw* self); +static gboolean test_raw_dbus_interface_set_property (GDBusConnection* connection, + const gchar* sender, + const gchar* object_path, + const gchar* interface_name, + const gchar* property_name, + GVariant* value, + GError** error, + gpointer user_data); +static void _dbus_test_raw_set_test_property (TestRaw* self, + GVariant* _value); +static void _dbus_test_raw_test_signal (GObject* _sender, + GVariant* i, + gpointer* _data); +static void _test_raw_unregister_object (gpointer user_data); +VALA_EXTERN void test_raw (TestRaw* test); +static Block1Data* block1_data_ref (Block1Data* _data1_); +static void block1_data_unref (void * _userdata_); +static void __lambda4_ (Block1Data* _data1_, + GVariant* var_i); +static gint _variant_get1 (GVariant* value); +static void ___lambda4__test_raw_test_signal (TestRaw* _sender, + GVariant* i, + gpointer self); +static GVariant* _variant_new1 (gint value); +static GVariant* _variant_new2 (gint value); +static gint _variant_get2 (GVariant* value); +static GVariant* _variant_new3 (const gchar* value); +static gchar* _variant_get3 (GVariant* value); +VALA_EXTERN void test (Test* test); +static Block2Data* block2_data_ref (Block2Data* _data2_); +static void block2_data_unref (void * _userdata_); +static void __lambda5_ (Block2Data* _data2_, + gint i); +static void ___lambda5__test_test_signal (Test* _sender, + gint i, + gpointer self); +static void _vala_main (void); + +static const GDBusArgInfo _test_dbus_arg_info_test_method_j = {-1, "j", "i", NULL}; +static const GDBusArgInfo _test_dbus_arg_info_test_method_k = {-1, "k", "i", NULL}; +static const GDBusArgInfo _test_dbus_arg_info_test_method_result = {-1, "result", "i", NULL}; +static const GDBusArgInfo * const _test_dbus_arg_info_test_method_in[] = {&_test_dbus_arg_info_test_method_j, &_test_dbus_arg_info_test_method_k, NULL}; +static const GDBusArgInfo * const _test_dbus_arg_info_test_method_out[] = {&_test_dbus_arg_info_test_method_result, NULL}; +static const GDBusMethodInfo _test_dbus_method_info_test_method = {-1, "TestMethod", (GDBusArgInfo **) (&_test_dbus_arg_info_test_method_in), (GDBusArgInfo **) (&_test_dbus_arg_info_test_method_out), NULL}; +static const GDBusMethodInfo * const _test_dbus_method_info[] = {&_test_dbus_method_info_test_method, NULL}; +static const GDBusArgInfo _test_dbus_arg_info_test_signal_i = {-1, "i", "i", NULL}; +static const GDBusArgInfo * const _test_dbus_arg_info_test_signal[] = {&_test_dbus_arg_info_test_signal_i, NULL}; +static const GDBusSignalInfo _test_dbus_signal_info_test_signal = {-1, "TestSignal", (GDBusArgInfo **) (&_test_dbus_arg_info_test_signal), NULL}; +static const GDBusSignalInfo * const _test_dbus_signal_info[] = {&_test_dbus_signal_info_test_signal, NULL}; +static const GDBusPropertyInfo _test_dbus_property_info_test_property = {-1, "TestProperty", "s", G_DBUS_PROPERTY_INFO_FLAGS_READABLE | G_DBUS_PROPERTY_INFO_FLAGS_WRITABLE, NULL}; +static const GDBusPropertyInfo * const _test_dbus_property_info[] = {&_test_dbus_property_info_test_property, NULL}; +static const GDBusInterfaceInfo _test_dbus_interface_info = {-1, "org.example.Test", (GDBusMethodInfo **) (&_test_dbus_method_info), (GDBusSignalInfo **) (&_test_dbus_signal_info), (GDBusPropertyInfo **) (&_test_dbus_property_info), NULL}; +static const GDBusInterfaceVTable _test_dbus_interface_vtable = {test_dbus_interface_method_call, test_dbus_interface_get_property, test_dbus_interface_set_property}; +static const GDBusArgInfo _test_raw_dbus_arg_info_test_method_j = {-1, "j", "i", NULL}; +static const GDBusArgInfo _test_raw_dbus_arg_info_test_method_k = {-1, "k", "i", NULL}; +static const GDBusArgInfo _test_raw_dbus_arg_info_test_method_result = {-1, "result", "i", NULL}; +static const GDBusArgInfo * const _test_raw_dbus_arg_info_test_method_in[] = {&_test_raw_dbus_arg_info_test_method_j, &_test_raw_dbus_arg_info_test_method_k, NULL}; +static const GDBusArgInfo * const _test_raw_dbus_arg_info_test_method_out[] = {&_test_raw_dbus_arg_info_test_method_result, NULL}; +static const GDBusMethodInfo _test_raw_dbus_method_info_test_method = {-1, "TestMethod", (GDBusArgInfo **) (&_test_raw_dbus_arg_info_test_method_in), (GDBusArgInfo **) (&_test_raw_dbus_arg_info_test_method_out), NULL}; +static const GDBusMethodInfo * const _test_raw_dbus_method_info[] = {&_test_raw_dbus_method_info_test_method, NULL}; +static const GDBusArgInfo _test_raw_dbus_arg_info_test_signal_i = {-1, "i", "i", NULL}; +static const GDBusArgInfo * const _test_raw_dbus_arg_info_test_signal[] = {&_test_raw_dbus_arg_info_test_signal_i, NULL}; +static const GDBusSignalInfo _test_raw_dbus_signal_info_test_signal = {-1, "TestSignal", (GDBusArgInfo **) (&_test_raw_dbus_arg_info_test_signal), NULL}; +static const GDBusSignalInfo * const _test_raw_dbus_signal_info[] = {&_test_raw_dbus_signal_info_test_signal, NULL}; +static const GDBusPropertyInfo _test_raw_dbus_property_info_test_property = {-1, "TestProperty", "s", G_DBUS_PROPERTY_INFO_FLAGS_READABLE | G_DBUS_PROPERTY_INFO_FLAGS_WRITABLE, NULL}; +static const GDBusPropertyInfo * const _test_raw_dbus_property_info[] = {&_test_raw_dbus_property_info_test_property, NULL}; +static const GDBusInterfaceInfo _test_raw_dbus_interface_info = {-1, "org.example.Test", (GDBusMethodInfo **) (&_test_raw_dbus_method_info), (GDBusSignalInfo **) (&_test_raw_dbus_signal_info), (GDBusPropertyInfo **) (&_test_raw_dbus_property_info), NULL}; +static const GDBusInterfaceVTable _test_raw_dbus_interface_vtable = {test_raw_dbus_interface_method_call, test_raw_dbus_interface_get_property, test_raw_dbus_interface_set_property}; + +gint +test_test_method (Test* self, + gint j, + gint k, + GError** error) +{ + TestIface* _iface_; + g_return_val_if_fail (IS_TEST (self), 0); + _iface_ = TEST_GET_INTERFACE (self); + if (_iface_->test_method) { + return _iface_->test_method (self, j, k, error); + } + return -1; +} + +gchar* +test_get_test_property (Test* self) +{ + TestIface* _iface_; + g_return_val_if_fail (IS_TEST (self), NULL); + _iface_ = TEST_GET_INTERFACE (self); + if (_iface_->get_test_property) { + return _iface_->get_test_property (self); + } + return NULL; +} + +void +test_set_test_property (Test* self, + const gchar* value) +{ + TestIface* _iface_; + g_return_if_fail (IS_TEST (self)); + _iface_ = TEST_GET_INTERFACE (self); + if (_iface_->set_test_property) { + _iface_->set_test_property (self, value); + } +} + +static void +test_default_init (TestIface * iface, + gpointer iface_data) +{ + test_signals[TEST_TEST_SIGNAL_SIGNAL] = g_signal_new ("test-signal", TYPE_TEST, G_SIGNAL_RUN_LAST, 0, NULL, NULL, g_cclosure_marshal_VOID__INT, G_TYPE_NONE, 1, G_TYPE_INT); +} + +static GType +test_get_type_once (void) +{ + static const GTypeInfo g_define_type_info = { sizeof (TestIface), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) test_default_init, (GClassFinalizeFunc) NULL, NULL, 0, 0, (GInstanceInitFunc) NULL, NULL }; + GType test_type_id; + test_type_id = g_type_register_static (G_TYPE_INTERFACE, "Test", &g_define_type_info, 0); + g_type_interface_add_prerequisite (test_type_id, G_TYPE_OBJECT); + g_type_set_qdata (test_type_id, g_quark_from_static_string ("vala-dbus-proxy-type"), (void*) test_proxy_get_type); + g_type_set_qdata (test_type_id, g_quark_from_static_string ("vala-dbus-interface-name"), "org.example.Test"); + g_type_set_qdata (test_type_id, g_quark_from_static_string ("vala-dbus-interface-info"), (void*) (&_test_dbus_interface_info)); + g_type_set_qdata (test_type_id, g_quark_from_static_string ("vala-dbus-register-object"), (void*) test_register_object); + return test_type_id; +} + +GType +test_get_type (void) +{ + static volatile gsize test_type_id__volatile = 0; + if (g_once_init_enter (&test_type_id__volatile)) { + GType test_type_id; + test_type_id = test_get_type_once (); + g_once_init_leave (&test_type_id__volatile, test_type_id); + } + return test_type_id__volatile; +} + +G_DEFINE_TYPE_EXTENDED (TestProxy, test_proxy, G_TYPE_DBUS_PROXY, 0, G_IMPLEMENT_INTERFACE (TYPE_TEST, test_proxy_test_interface_init) ) +static void +test_proxy_class_init (TestProxyClass* klass) +{ + G_DBUS_PROXY_CLASS (klass)->g_signal = test_proxy_g_signal; +} + +static void +_dbus_handle_test_test_signal (Test* self, + GVariant* parameters) +{ + GVariantIter _arguments_iter; + gint i = 0; + GVariant* _tmp0_; + g_variant_iter_init (&_arguments_iter, parameters); + _tmp0_ = g_variant_iter_next_value (&_arguments_iter); + i = g_variant_get_int32 (_tmp0_); + g_variant_unref (_tmp0_); + g_signal_emit_by_name (self, "test-signal", i); +} + +static void +test_proxy_g_signal (GDBusProxy* proxy, + const gchar* sender_name, + const gchar* signal_name, + GVariant* parameters) +{ + if (strcmp (signal_name, "TestSignal") == 0) { + _dbus_handle_test_test_signal ((Test*) proxy, parameters); + } +} + +static void +test_proxy_init (TestProxy* self) +{ + g_dbus_proxy_set_interface_info (G_DBUS_PROXY (self), (GDBusInterfaceInfo *) (&_test_dbus_interface_info)); +} + +static gint +test_proxy_test_method (Test* self, + gint j, + gint k, + GError** error) +{ + GDBusMessage *_message; + GVariant *_arguments; + GVariantBuilder _arguments_builder; + GDBusMessage *_reply_message; + GVariant *_reply; + GVariantIter _reply_iter; + gint _result = 0; + GVariant* _tmp3_; + G_IO_ERROR; + _message = g_dbus_message_new_method_call (g_dbus_proxy_get_name ((GDBusProxy *) self), g_dbus_proxy_get_object_path ((GDBusProxy *) self), "org.example.Test", "TestMethod"); + g_variant_builder_init (&_arguments_builder, G_VARIANT_TYPE_TUPLE); + g_variant_builder_add_value (&_arguments_builder, g_variant_new_int32 (j)); + g_variant_builder_add_value (&_arguments_builder, g_variant_new_int32 (k)); + _arguments = g_variant_builder_end (&_arguments_builder); + g_dbus_message_set_body (_message, _arguments); + _reply_message = g_dbus_connection_send_message_with_reply_sync (g_dbus_proxy_get_connection ((GDBusProxy *) self), _message, G_DBUS_SEND_MESSAGE_FLAGS_NONE, g_dbus_proxy_get_default_timeout ((GDBusProxy *) self), NULL, NULL, error); + g_object_unref (_message); + if (!_reply_message) { + gint _tmp1_ = 0; + return _tmp1_; + } + if (g_dbus_message_to_gerror (_reply_message, error)) { + gint _tmp2_ = 0; + g_object_unref (_reply_message); + return _tmp2_; + } + _reply = g_dbus_message_get_body (_reply_message); + g_variant_iter_init (&_reply_iter, _reply); + _tmp3_ = g_variant_iter_next_value (&_reply_iter); + _result = g_variant_get_int32 (_tmp3_); + g_variant_unref (_tmp3_); + g_object_unref (_reply_message); + return _result; +} + +static gchar* +test_dbus_proxy_get_test_property (Test* self) +{ + GVariant *_inner_reply; + gchar* _result; + _inner_reply = g_dbus_proxy_get_cached_property ((GDBusProxy *) self, "TestProperty"); + if (!_inner_reply) { + GVariant *_arguments; + GVariant *_reply; + GVariantBuilder _arguments_builder; + g_variant_builder_init (&_arguments_builder, G_VARIANT_TYPE_TUPLE); + g_variant_builder_add_value (&_arguments_builder, g_variant_new_string ("org.example.Test")); + g_variant_builder_add_value (&_arguments_builder, g_variant_new_string ("TestProperty")); + _arguments = g_variant_builder_end (&_arguments_builder); + _reply = g_dbus_proxy_call_sync ((GDBusProxy *) self, "org.freedesktop.DBus.Properties.Get", _arguments, G_DBUS_CALL_FLAGS_NONE, -1, NULL, NULL); + if (!_reply) { + return NULL; + } + g_variant_get (_reply, "(v)", &_inner_reply); + g_variant_unref (_reply); + } + _result = g_variant_dup_string (_inner_reply, NULL); + g_variant_unref (_inner_reply); + return _result; +} + +static void +test_dbus_proxy_set_test_property (Test* self, + const gchar* value) +{ + GVariant *_arguments; + GVariant *_reply; + GVariantBuilder _arguments_builder; + g_variant_builder_init (&_arguments_builder, G_VARIANT_TYPE_TUPLE); + g_variant_builder_add_value (&_arguments_builder, g_variant_new_string ("org.example.Test")); + g_variant_builder_add_value (&_arguments_builder, g_variant_new_string ("TestProperty")); + g_variant_builder_open (&_arguments_builder, G_VARIANT_TYPE_VARIANT); + g_variant_builder_add_value (&_arguments_builder, g_variant_new_string (value)); + g_variant_builder_close (&_arguments_builder); + _arguments = g_variant_builder_end (&_arguments_builder); + _reply = g_dbus_proxy_call_sync ((GDBusProxy *) self, "org.freedesktop.DBus.Properties.Set", _arguments, G_DBUS_CALL_FLAGS_NONE, -1, NULL, NULL); + if (!_reply) { + return; + } + g_variant_unref (_reply); +} + +static void +test_proxy_test_interface_init (TestIface* iface) +{ + iface->test_method = test_proxy_test_method; + iface->get_test_property = test_dbus_proxy_get_test_property; + iface->set_test_property = test_dbus_proxy_set_test_property; +} + +static void +_dbus_test_test_method (Test* self, + GVariant* _parameters_, + GDBusMethodInvocation* invocation) +{ + GError* error = NULL; + GVariantIter _arguments_iter; + gint j = 0; + GVariant* _tmp4_; + gint k = 0; + GVariant* _tmp5_; + GDBusMessage* _reply_message = NULL; + GVariant* _reply; + GVariantBuilder _reply_builder; + gint result; + g_variant_iter_init (&_arguments_iter, _parameters_); + _tmp4_ = g_variant_iter_next_value (&_arguments_iter); + j = g_variant_get_int32 (_tmp4_); + g_variant_unref (_tmp4_); + _tmp5_ = g_variant_iter_next_value (&_arguments_iter); + k = g_variant_get_int32 (_tmp5_); + g_variant_unref (_tmp5_); + result = test_test_method (self, j, k, &error); + if (error) { + g_dbus_method_invocation_return_gerror (invocation, error); + g_error_free (error); + return; + } + _reply_message = g_dbus_message_new_method_reply (g_dbus_method_invocation_get_message (invocation)); + g_variant_builder_init (&_reply_builder, G_VARIANT_TYPE_TUPLE); + g_variant_builder_add_value (&_reply_builder, g_variant_new_int32 (result)); + _reply = g_variant_builder_end (&_reply_builder); + g_dbus_message_set_body (_reply_message, _reply); + g_dbus_connection_send_message (g_dbus_method_invocation_get_connection (invocation), _reply_message, G_DBUS_SEND_MESSAGE_FLAGS_NONE, NULL, NULL); + g_object_unref (invocation); + g_object_unref (_reply_message); +} + +static void +test_dbus_interface_method_call (GDBusConnection* connection, + const gchar* sender, + const gchar* object_path, + const gchar* interface_name, + const gchar* method_name, + GVariant* parameters, + GDBusMethodInvocation* invocation, + gpointer user_data) +{ + gpointer* data; + gpointer object; + data = user_data; + object = data[0]; + if (strcmp (method_name, "TestMethod") == 0) { + _dbus_test_test_method (object, parameters, invocation); + } else { + g_object_unref (invocation); + } +} + +static GVariant* +_dbus_test_get_test_property (Test* self) +{ + gchar* result; + GVariant* _reply; + result = test_get_test_property (self); + _reply = g_variant_new_string (result); + _g_free0 (result); + return _reply; +} + +static GVariant* +test_dbus_interface_get_property (GDBusConnection* connection, + const gchar* sender, + const gchar* object_path, + const gchar* interface_name, + const gchar* property_name, + GError** error, + gpointer user_data) +{ + gpointer* data; + gpointer object; + data = user_data; + object = data[0]; + if (strcmp (property_name, "TestProperty") == 0) { + return _dbus_test_get_test_property (object); + } + return NULL; +} + +static void +_dbus_test_set_test_property (Test* self, + GVariant* _value) +{ + gchar* value = NULL; + value = g_variant_dup_string (_value, NULL); + test_set_test_property (self, value); + _g_free0 (value); +} + +static gboolean +test_dbus_interface_set_property (GDBusConnection* connection, + const gchar* sender, + const gchar* object_path, + const gchar* interface_name, + const gchar* property_name, + GVariant* value, + GError** error, + gpointer user_data) +{ + gpointer* data; + gpointer object; + data = user_data; + object = data[0]; + if (strcmp (property_name, "TestProperty") == 0) { + _dbus_test_set_test_property (object, value); + return TRUE; + } + return FALSE; +} + +static void +_dbus_test_test_signal (GObject* _sender, + gint i, + gpointer* _data) +{ + GDBusConnection * _connection; + const gchar * _path; + GVariant *_arguments; + GVariantBuilder _arguments_builder; + _connection = _data[1]; + _path = _data[2]; + g_variant_builder_init (&_arguments_builder, G_VARIANT_TYPE_TUPLE); + g_variant_builder_add_value (&_arguments_builder, g_variant_new_int32 (i)); + _arguments = g_variant_builder_end (&_arguments_builder); + g_dbus_connection_emit_signal (_connection, NULL, _path, "org.example.Test", "TestSignal", _arguments, NULL); +} + +guint +test_register_object (gpointer object, + GDBusConnection* connection, + const gchar* path, + GError** error) +{ + guint result; + gpointer *data; + data = g_new (gpointer, 3); + data[0] = g_object_ref (object); + data[1] = g_object_ref (connection); + data[2] = g_strdup (path); + result = g_dbus_connection_register_object (connection, path, (GDBusInterfaceInfo *) (&_test_dbus_interface_info), &_test_dbus_interface_vtable, data, _test_unregister_object, error); + if (!result) { + return 0; + } + g_signal_connect (object, "test-signal", (GCallback) _dbus_test_test_signal, data); + return result; +} + +static void +_test_unregister_object (gpointer user_data) +{ + gpointer* data; + data = user_data; + g_signal_handlers_disconnect_by_func (data[0], _dbus_test_test_signal, data); + g_object_unref (data[0]); + g_object_unref (data[1]); + g_free (data[2]); + g_free (data); +} + +GVariant* +test_raw_test_method (TestRaw* self, + GVariant* j, + GVariant* k, + GError** error) +{ + TestRawIface* _iface_; + g_return_val_if_fail (IS_TEST_RAW (self), NULL); + _iface_ = TEST_RAW_GET_INTERFACE (self); + if (_iface_->test_method) { + return _iface_->test_method (self, j, k, error); + } + return NULL; +} + +GVariant* +test_raw_get_test_property (TestRaw* self) +{ + TestRawIface* _iface_; + g_return_val_if_fail (IS_TEST_RAW (self), NULL); + _iface_ = TEST_RAW_GET_INTERFACE (self); + if (_iface_->get_test_property) { + return _iface_->get_test_property (self); + } + return NULL; +} + +void +test_raw_set_test_property (TestRaw* self, + GVariant* value) +{ + TestRawIface* _iface_; + g_return_if_fail (IS_TEST_RAW (self)); + _iface_ = TEST_RAW_GET_INTERFACE (self); + if (_iface_->set_test_property) { + _iface_->set_test_property (self, value); + } +} + +static void +test_raw_default_init (TestRawIface * iface, + gpointer iface_data) +{ + test_raw_signals[TEST_RAW_TEST_SIGNAL_SIGNAL] = g_signal_new ("test-signal", TYPE_TEST_RAW, G_SIGNAL_RUN_LAST, 0, NULL, NULL, g_cclosure_marshal_VOID__VARIANT, G_TYPE_NONE, 1, G_TYPE_VARIANT); +} + +static GType +test_raw_get_type_once (void) +{ + static const GTypeInfo g_define_type_info = { sizeof (TestRawIface), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) test_raw_default_init, (GClassFinalizeFunc) NULL, NULL, 0, 0, (GInstanceInitFunc) NULL, NULL }; + GType test_raw_type_id; + test_raw_type_id = g_type_register_static (G_TYPE_INTERFACE, "TestRaw", &g_define_type_info, 0); + g_type_interface_add_prerequisite (test_raw_type_id, G_TYPE_OBJECT); + g_type_set_qdata (test_raw_type_id, g_quark_from_static_string ("vala-dbus-proxy-type"), (void*) test_raw_proxy_get_type); + g_type_set_qdata (test_raw_type_id, g_quark_from_static_string ("vala-dbus-interface-name"), "org.example.Test"); + g_type_set_qdata (test_raw_type_id, g_quark_from_static_string ("vala-dbus-interface-info"), (void*) (&_test_raw_dbus_interface_info)); + g_type_set_qdata (test_raw_type_id, g_quark_from_static_string ("vala-dbus-register-object"), (void*) test_raw_register_object); + return test_raw_type_id; +} + +GType +test_raw_get_type (void) +{ + static volatile gsize test_raw_type_id__volatile = 0; + if (g_once_init_enter (&test_raw_type_id__volatile)) { + GType test_raw_type_id; + test_raw_type_id = test_raw_get_type_once (); + g_once_init_leave (&test_raw_type_id__volatile, test_raw_type_id); + } + return test_raw_type_id__volatile; +} + +G_DEFINE_TYPE_EXTENDED (TestRawProxy, test_raw_proxy, G_TYPE_DBUS_PROXY, 0, G_IMPLEMENT_INTERFACE (TYPE_TEST_RAW, test_raw_proxy_test_raw_interface_init) ) +static void +test_raw_proxy_class_init (TestRawProxyClass* klass) +{ + G_DBUS_PROXY_CLASS (klass)->g_signal = test_raw_proxy_g_signal; +} + +static void +_dbus_handle_test_raw_test_signal (TestRaw* self, + GVariant* parameters) +{ + GVariantIter _arguments_iter; + GVariant* i = NULL; + g_variant_iter_init (&_arguments_iter, parameters); + i = g_variant_iter_next_value (&_arguments_iter); + g_signal_emit_by_name (self, "test-signal", i); + _g_variant_unref0 (i); +} + +static void +test_raw_proxy_g_signal (GDBusProxy* proxy, + const gchar* sender_name, + const gchar* signal_name, + GVariant* parameters) +{ + if (strcmp (signal_name, "TestSignal") == 0) { + _dbus_handle_test_raw_test_signal ((TestRaw*) proxy, parameters); + } +} + +static void +test_raw_proxy_init (TestRawProxy* self) +{ + g_dbus_proxy_set_interface_info (G_DBUS_PROXY (self), (GDBusInterfaceInfo *) (&_test_raw_dbus_interface_info)); +} + +static GVariant* +test_raw_proxy_test_method (TestRaw* self, + GVariant* j, + GVariant* k, + GError** error) +{ + GDBusMessage *_message; + GVariant *_arguments; + GVariantBuilder _arguments_builder; + GDBusMessage *_reply_message; + GVariant *_reply; + GVariantIter _reply_iter; + GVariant* _result = NULL; + G_IO_ERROR; + _message = g_dbus_message_new_method_call (g_dbus_proxy_get_name ((GDBusProxy *) self), g_dbus_proxy_get_object_path ((GDBusProxy *) self), "org.example.Test", "TestMethod"); + g_variant_builder_init (&_arguments_builder, G_VARIANT_TYPE_TUPLE); + g_variant_builder_add_value (&_arguments_builder, j); + g_variant_builder_add_value (&_arguments_builder, k); + _arguments = g_variant_builder_end (&_arguments_builder); + g_dbus_message_set_body (_message, _arguments); + _reply_message = g_dbus_connection_send_message_with_reply_sync (g_dbus_proxy_get_connection ((GDBusProxy *) self), _message, G_DBUS_SEND_MESSAGE_FLAGS_NONE, g_dbus_proxy_get_default_timeout ((GDBusProxy *) self), NULL, NULL, error); + g_object_unref (_message); + if (!_reply_message) { + return NULL; + } + if (g_dbus_message_to_gerror (_reply_message, error)) { + g_object_unref (_reply_message); + return NULL; + } + _reply = g_dbus_message_get_body (_reply_message); + g_variant_iter_init (&_reply_iter, _reply); + _result = g_variant_iter_next_value (&_reply_iter); + g_object_unref (_reply_message); + return _result; +} + +static GVariant* +test_raw_dbus_proxy_get_test_property (TestRaw* self) +{ + GVariant *_inner_reply; + GVariant* _result; + _inner_reply = g_dbus_proxy_get_cached_property ((GDBusProxy *) self, "TestProperty"); + if (!_inner_reply) { + GVariant *_arguments; + GVariant *_reply; + GVariantBuilder _arguments_builder; + g_variant_builder_init (&_arguments_builder, G_VARIANT_TYPE_TUPLE); + g_variant_builder_add_value (&_arguments_builder, g_variant_new_string ("org.example.Test")); + g_variant_builder_add_value (&_arguments_builder, g_variant_new_string ("TestProperty")); + _arguments = g_variant_builder_end (&_arguments_builder); + _reply = g_dbus_proxy_call_sync ((GDBusProxy *) self, "org.freedesktop.DBus.Properties.Get", _arguments, G_DBUS_CALL_FLAGS_NONE, -1, NULL, NULL); + if (!_reply) { + return NULL; + } + g_variant_get (_reply, "(v)", &_inner_reply); + g_variant_unref (_reply); + } + _result = _inner_reply; + return _result; +} + +static void +test_raw_dbus_proxy_set_test_property (TestRaw* self, + GVariant* value) +{ + GVariant *_arguments; + GVariant *_reply; + GVariantBuilder _arguments_builder; + g_variant_builder_init (&_arguments_builder, G_VARIANT_TYPE_TUPLE); + g_variant_builder_add_value (&_arguments_builder, g_variant_new_string ("org.example.Test")); + g_variant_builder_add_value (&_arguments_builder, g_variant_new_string ("TestProperty")); + g_variant_builder_open (&_arguments_builder, G_VARIANT_TYPE_VARIANT); + g_variant_builder_add_value (&_arguments_builder, value); + g_variant_builder_close (&_arguments_builder); + _arguments = g_variant_builder_end (&_arguments_builder); + _reply = g_dbus_proxy_call_sync ((GDBusProxy *) self, "org.freedesktop.DBus.Properties.Set", _arguments, G_DBUS_CALL_FLAGS_NONE, -1, NULL, NULL); + if (!_reply) { + return; + } + g_variant_unref (_reply); +} + +static void +test_raw_proxy_test_raw_interface_init (TestRawIface* iface) +{ + iface->test_method = test_raw_proxy_test_method; + iface->get_test_property = test_raw_dbus_proxy_get_test_property; + iface->set_test_property = test_raw_dbus_proxy_set_test_property; +} + +static void +_dbus_test_raw_test_method (TestRaw* self, + GVariant* _parameters_, + GDBusMethodInvocation* invocation) +{ + GError* error = NULL; + GVariantIter _arguments_iter; + GVariant* j = NULL; + GVariant* k = NULL; + GDBusMessage* _reply_message = NULL; + GVariant* _reply; + GVariantBuilder _reply_builder; + GVariant* result; + g_variant_iter_init (&_arguments_iter, _parameters_); + j = g_variant_iter_next_value (&_arguments_iter); + k = g_variant_iter_next_value (&_arguments_iter); + result = test_raw_test_method (self, j, k, &error); + if (error) { + g_dbus_method_invocation_return_gerror (invocation, error); + g_error_free (error); + goto _error; + } + _reply_message = g_dbus_message_new_method_reply (g_dbus_method_invocation_get_message (invocation)); + g_variant_builder_init (&_reply_builder, G_VARIANT_TYPE_TUPLE); + g_variant_builder_add_value (&_reply_builder, result); + _g_variant_unref0 (result); + _reply = g_variant_builder_end (&_reply_builder); + g_dbus_message_set_body (_reply_message, _reply); + g_dbus_connection_send_message (g_dbus_method_invocation_get_connection (invocation), _reply_message, G_DBUS_SEND_MESSAGE_FLAGS_NONE, NULL, NULL); + g_object_unref (invocation); + g_object_unref (_reply_message); + _error: + _g_variant_unref0 (j); + _g_variant_unref0 (k); + ; +} + +static void +test_raw_dbus_interface_method_call (GDBusConnection* connection, + const gchar* sender, + const gchar* object_path, + const gchar* interface_name, + const gchar* method_name, + GVariant* parameters, + GDBusMethodInvocation* invocation, + gpointer user_data) +{ + gpointer* data; + gpointer object; + data = user_data; + object = data[0]; + if (strcmp (method_name, "TestMethod") == 0) { + _dbus_test_raw_test_method (object, parameters, invocation); + } else { + g_object_unref (invocation); + } +} + +static GVariant* +_dbus_test_raw_get_test_property (TestRaw* self) +{ + GVariant* result; + GVariant* _reply; + result = test_raw_get_test_property (self); + _reply = result; + return _reply; +} + +static GVariant* +test_raw_dbus_interface_get_property (GDBusConnection* connection, + const gchar* sender, + const gchar* object_path, + const gchar* interface_name, + const gchar* property_name, + GError** error, + gpointer user_data) +{ + gpointer* data; + gpointer object; + data = user_data; + object = data[0]; + if (strcmp (property_name, "TestProperty") == 0) { + return _dbus_test_raw_get_test_property (object); + } + return NULL; +} + +static void +_dbus_test_raw_set_test_property (TestRaw* self, + GVariant* _value) +{ + GVariant* value = NULL; + value = _value; + test_raw_set_test_property (self, value); +} + +static gboolean +test_raw_dbus_interface_set_property (GDBusConnection* connection, + const gchar* sender, + const gchar* object_path, + const gchar* interface_name, + const gchar* property_name, + GVariant* value, + GError** error, + gpointer user_data) +{ + gpointer* data; + gpointer object; + data = user_data; + object = data[0]; + if (strcmp (property_name, "TestProperty") == 0) { + _dbus_test_raw_set_test_property (object, value); + return TRUE; + } + return FALSE; +} + +static void +_dbus_test_raw_test_signal (GObject* _sender, + GVariant* i, + gpointer* _data) +{ + GDBusConnection * _connection; + const gchar * _path; + GVariant *_arguments; + GVariantBuilder _arguments_builder; + _connection = _data[1]; + _path = _data[2]; + g_variant_builder_init (&_arguments_builder, G_VARIANT_TYPE_TUPLE); + g_variant_builder_add_value (&_arguments_builder, i); + _arguments = g_variant_builder_end (&_arguments_builder); + g_dbus_connection_emit_signal (_connection, NULL, _path, "org.example.Test", "TestSignal", _arguments, NULL); +} + +guint +test_raw_register_object (gpointer object, + GDBusConnection* connection, + const gchar* path, + GError** error) +{ + guint result; + gpointer *data; + data = g_new (gpointer, 3); + data[0] = g_object_ref (object); + data[1] = g_object_ref (connection); + data[2] = g_strdup (path); + result = g_dbus_connection_register_object (connection, path, (GDBusInterfaceInfo *) (&_test_raw_dbus_interface_info), &_test_raw_dbus_interface_vtable, data, _test_raw_unregister_object, error); + if (!result) { + return 0; + } + g_signal_connect (object, "test-signal", (GCallback) _dbus_test_raw_test_signal, data); + return result; +} + +static void +_test_raw_unregister_object (gpointer user_data) +{ + gpointer* data; + data = user_data; + g_signal_handlers_disconnect_by_func (data[0], _dbus_test_raw_test_signal, data); + g_object_unref (data[0]); + g_object_unref (data[1]); + g_free (data[2]); + g_free (data); +} + +static Block1Data* +block1_data_ref (Block1Data* _data1_) +{ + g_atomic_int_inc (&_data1_->_ref_count_); + return _data1_; +} + +static void +block1_data_unref (void * _userdata_) +{ + Block1Data* _data1_; + _data1_ = (Block1Data*) _userdata_; + if (g_atomic_int_dec_and_test (&_data1_->_ref_count_)) { + _g_main_loop_unref0 (_data1_->main_loop); + g_slice_free (Block1Data, _data1_); + } +} + +static gint +_variant_get1 (GVariant* value) +{ + return g_variant_get_int32 (value); +} + +static void +__lambda4_ (Block1Data* _data1_, + GVariant* var_i) +{ + gint i = 0; + gint _tmp0_; + g_return_if_fail (var_i != NULL); + _tmp0_ = _variant_get1 (var_i); + i = _tmp0_; + _vala_assert (i == 46, "i == 46"); + g_main_loop_quit (_data1_->main_loop); +} + +static void +___lambda4__test_raw_test_signal (TestRaw* _sender, + GVariant* i, + gpointer self) +{ + __lambda4_ (self, i); +} + +static GVariant* +_variant_new1 (gint value) +{ + return g_variant_ref_sink (g_variant_new_int32 (value)); +} + +static GVariant* +_variant_new2 (gint value) +{ + return g_variant_ref_sink (g_variant_new_int32 (value)); +} + +static gint +_variant_get2 (GVariant* value) +{ + return g_variant_get_int32 (value); +} + +static GVariant* +_variant_new3 (const gchar* value) +{ + return g_variant_ref_sink (g_variant_new_string (value)); +} + +static gchar* +_variant_get3 (GVariant* value) +{ + return g_variant_dup_string (value, NULL); +} + +void +test_raw (TestRaw* test) +{ + Block1Data* _data1_; + GMainLoop* _tmp0_; + gulong id = 0UL; + gulong _tmp1_; + GVariant* _tmp2_ = NULL; + GVariant* _tmp3_; + GVariant* _tmp4_; + GVariant* _tmp5_; + GVariant* _tmp6_; + gint j = 0; + gint _tmp7_; + GVariant* _tmp8_; + gchar* s = NULL; + GVariant* _tmp9_; + GVariant* _tmp10_; + GVariant* _tmp11_; + gchar* _tmp12_; + gchar* _tmp13_; + const gchar* _tmp14_; + GError* _inner_error0_ = NULL; + g_return_if_fail (IS_TEST_RAW (test)); + _data1_ = g_slice_new0 (Block1Data); + _data1_->_ref_count_ = 1; + _tmp0_ = g_main_loop_new (NULL, FALSE); + _data1_->main_loop = _tmp0_; + _tmp1_ = g_signal_connect_data (test, "test-signal", (GCallback) ___lambda4__test_raw_test_signal, block1_data_ref (_data1_), (GClosureNotify) block1_data_unref, 0); + id = _tmp1_; + _tmp3_ = _variant_new1 (23); + _tmp4_ = _variant_new2 (11); + _tmp5_ = test_raw_test_method (test, _tmp3_, _tmp4_, &_inner_error0_); + _tmp6_ = _tmp5_; + _g_variant_unref0 (_tmp4_); + _g_variant_unref0 (_tmp3_); + _tmp2_ = _tmp6_; + if (G_UNLIKELY (_inner_error0_ != NULL)) { + block1_data_unref (_data1_); + _data1_ = NULL; + g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error0_->message, g_quark_to_string (_inner_error0_->domain), _inner_error0_->code); + g_clear_error (&_inner_error0_); + return; + } + _tmp7_ = _variant_get2 (_tmp2_); + j = _tmp7_; + _vala_assert (j == 42, "j == 42"); + g_main_loop_run (_data1_->main_loop); + g_signal_handler_disconnect (G_TYPE_CHECK_INSTANCE_CAST (test, G_TYPE_OBJECT, GObject), id); + _tmp8_ = _variant_new3 ("hello"); + test_raw_set_test_property (test, _tmp8_); + _g_variant_unref0 (_tmp8_); + _tmp9_ = test_raw_get_test_property (test); + _tmp10_ = _tmp9_; + _tmp11_ = _tmp10_; + _tmp12_ = _variant_get3 (_tmp11_); + _tmp13_ = _tmp12_; + _g_variant_unref0 (_tmp11_); + s = _tmp13_; + _tmp14_ = s; + _vala_assert (g_strcmp0 (_tmp14_, "hello") == 0, "s == \"hello\""); + _g_free0 (s); + _g_variant_unref0 (_tmp2_); + block1_data_unref (_data1_); + _data1_ = NULL; +} + +static Block2Data* +block2_data_ref (Block2Data* _data2_) +{ + g_atomic_int_inc (&_data2_->_ref_count_); + return _data2_; +} + +static void +block2_data_unref (void * _userdata_) +{ + Block2Data* _data2_; + _data2_ = (Block2Data*) _userdata_; + if (g_atomic_int_dec_and_test (&_data2_->_ref_count_)) { + _g_main_loop_unref0 (_data2_->main_loop); + g_slice_free (Block2Data, _data2_); + } +} + +static void +__lambda5_ (Block2Data* _data2_, + gint i) +{ + _vala_assert (i == 46, "i == 46"); + g_main_loop_quit (_data2_->main_loop); +} + +static void +___lambda5__test_test_signal (Test* _sender, + gint i, + gpointer self) +{ + __lambda5_ (self, i); +} + +void +test (Test* test) +{ + Block2Data* _data2_; + GMainLoop* _tmp0_; + gulong id = 0UL; + gulong _tmp1_; + gint j = 0; + gchar* s = NULL; + gchar* _tmp2_; + gchar* _tmp3_; + const gchar* _tmp4_; + GError* _inner_error0_ = NULL; + g_return_if_fail (IS_TEST (test)); + _data2_ = g_slice_new0 (Block2Data); + _data2_->_ref_count_ = 1; + _tmp0_ = g_main_loop_new (NULL, FALSE); + _data2_->main_loop = _tmp0_; + _tmp1_ = g_signal_connect_data (test, "test-signal", (GCallback) ___lambda5__test_test_signal, block2_data_ref (_data2_), (GClosureNotify) block2_data_unref, 0); + id = _tmp1_; + j = test_test_method (test, 23, 11, &_inner_error0_); + if (G_UNLIKELY (_inner_error0_ != NULL)) { + block2_data_unref (_data2_); + _data2_ = NULL; + g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error0_->message, g_quark_to_string (_inner_error0_->domain), _inner_error0_->code); + g_clear_error (&_inner_error0_); + return; + } + _vala_assert (j == 42, "j == 42"); + g_main_loop_run (_data2_->main_loop); + g_signal_handler_disconnect (G_TYPE_CHECK_INSTANCE_CAST (test, G_TYPE_OBJECT, GObject), id); + test_set_test_property (test, "hello"); + _tmp2_ = test_get_test_property (test); + _tmp3_ = _tmp2_; + s = _tmp3_; + _tmp4_ = s; + _vala_assert (g_strcmp0 (_tmp4_, "hello") == 0, "s == \"hello\""); + _g_free0 (s); + block2_data_unref (_data2_); + _data2_ = NULL; +} + +static void +_vala_main (void) +{ + Test* test1 = NULL; + Test* _tmp0_; + Test* _tmp1_; + TestRaw* test2 = NULL; + TestRaw* _tmp2_; + TestRaw* _tmp3_; + TestRaw* test3 = NULL; + TestRaw* _tmp4_; + TestRaw* _tmp5_; + GError* _inner_error0_ = NULL; + _tmp0_ = (Test*) g_initable_new (TYPE_TEST_PROXY, NULL, &_inner_error0_, "g-flags", G_DBUS_PROXY_FLAGS_DO_NOT_LOAD_PROPERTIES, "g-name", "org.example.Test", "g-bus-type", G_BUS_TYPE_SESSION, "g-object-path", "/org/example/testraw", "g-interface-name", "org.example.Test", NULL); + test1 = (Test*) _tmp0_; + if (G_UNLIKELY (_inner_error0_ != NULL)) { + g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error0_->message, g_quark_to_string (_inner_error0_->domain), _inner_error0_->code); + g_clear_error (&_inner_error0_); + return; + } + _tmp1_ = test1; + test (_tmp1_); + _tmp2_ = (TestRaw*) g_initable_new (TYPE_TEST_RAW_PROXY, NULL, &_inner_error0_, "g-flags", G_DBUS_PROXY_FLAGS_DO_NOT_LOAD_PROPERTIES, "g-name", "org.example.Test", "g-bus-type", G_BUS_TYPE_SESSION, "g-object-path", "/org/example/test", "g-interface-name", "org.example.Test", NULL); + test2 = (TestRaw*) _tmp2_; + if (G_UNLIKELY (_inner_error0_ != NULL)) { + _g_object_unref0 (test1); + g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error0_->message, g_quark_to_string (_inner_error0_->domain), _inner_error0_->code); + g_clear_error (&_inner_error0_); + return; + } + _tmp3_ = test2; + test_raw (_tmp3_); + _tmp4_ = (TestRaw*) g_initable_new (TYPE_TEST_RAW_PROXY, NULL, &_inner_error0_, "g-flags", G_DBUS_PROXY_FLAGS_DO_NOT_LOAD_PROPERTIES, "g-name", "org.example.Test", "g-bus-type", G_BUS_TYPE_SESSION, "g-object-path", "/org/example/testraw", "g-interface-name", "org.example.Test", NULL); + test3 = (TestRaw*) _tmp4_; + if (G_UNLIKELY (_inner_error0_ != NULL)) { + _g_object_unref0 (test2); + _g_object_unref0 (test1); + g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error0_->message, g_quark_to_string (_inner_error0_->domain), _inner_error0_->code); + g_clear_error (&_inner_error0_); + return; + } + _tmp5_ = test3; + test_raw (_tmp5_); + _g_object_unref0 (test3); + _g_object_unref0 (test2); + _g_object_unref0 (test1); +} + +int +main (int argc, + char ** argv) +{ + _vala_main (); + return 0; +} + diff --git a/tests/dbus/rawvariants_server.c-expected b/tests/dbus/rawvariants_server.c-expected new file mode 100644 index 000000000..f1e88b5cf --- /dev/null +++ b/tests/dbus/rawvariants_server.c-expected @@ -0,0 +1,1095 @@ +/* dbus_rawvariants_server.c generated by valac, the Vala compiler + * generated from dbus_rawvariants_server.vala, do not modify */ + +#include <glib-object.h> +#include <gio/gio.h> +#include <stdlib.h> +#include <string.h> +#include <glib.h> + +#if !defined(VALA_EXTERN) +#if defined(_MSC_VER) +#define VALA_EXTERN __declspec(dllexport) extern +#elif __GNUC__ >= 4 +#define VALA_EXTERN __attribute__((visibility("default"))) extern +#else +#define VALA_EXTERN extern +#endif +#endif + +#define TYPE_TEST (test_get_type ()) +#define TEST(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TYPE_TEST, Test)) +#define TEST_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), TYPE_TEST, TestClass)) +#define IS_TEST(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TYPE_TEST)) +#define IS_TEST_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), TYPE_TEST)) +#define TEST_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), TYPE_TEST, TestClass)) + +typedef struct _Test Test; +typedef struct _TestClass TestClass; +typedef struct _TestPrivate TestPrivate; +enum { + TEST_0_PROPERTY, + TEST_TEST_PROPERTY_PROPERTY, + TEST_NUM_PROPERTIES +}; +static GParamSpec* test_properties[TEST_NUM_PROPERTIES]; +#define _g_free0(var) (var = (g_free (var), NULL)) +enum { + TEST_TEST_SIGNAL_SIGNAL, + TEST_NUM_SIGNALS +}; +static guint test_signals[TEST_NUM_SIGNALS] = {0}; + +#define TYPE_TEST_RAW (test_raw_get_type ()) +#define TEST_RAW(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TYPE_TEST_RAW, TestRaw)) +#define TEST_RAW_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), TYPE_TEST_RAW, TestRawClass)) +#define IS_TEST_RAW(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TYPE_TEST_RAW)) +#define IS_TEST_RAW_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), TYPE_TEST_RAW)) +#define TEST_RAW_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), TYPE_TEST_RAW, TestRawClass)) + +typedef struct _TestRaw TestRaw; +typedef struct _TestRawClass TestRawClass; +typedef struct _TestRawPrivate TestRawPrivate; +enum { + TEST_RAW_0_PROPERTY, + TEST_RAW_TEST_PROPERTY_PROPERTY, + TEST_RAW_NUM_PROPERTIES +}; +static GParamSpec* test_raw_properties[TEST_RAW_NUM_PROPERTIES]; +#define _g_variant_unref0(var) ((var == NULL) ? NULL : (var = (g_variant_unref (var), NULL))) +enum { + TEST_RAW_TEST_SIGNAL_SIGNAL, + TEST_RAW_NUM_SIGNALS +}; +static guint test_raw_signals[TEST_RAW_NUM_SIGNALS] = {0}; +#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL))) +#define _g_main_loop_unref0(var) ((var == NULL) ? NULL : (var = (g_main_loop_unref (var), NULL))) +#define _vala_assert(expr, msg) if G_LIKELY (expr) ; else g_assertion_message_expr (G_LOG_DOMAIN, __FILE__, __LINE__, G_STRFUNC, msg); +#define _vala_return_if_fail(expr, msg) if G_LIKELY (expr) ; else { g_return_if_fail_warning (G_LOG_DOMAIN, G_STRFUNC, msg); return; } +#define _vala_return_val_if_fail(expr, msg, val) if G_LIKELY (expr) ; else { g_return_if_fail_warning (G_LOG_DOMAIN, G_STRFUNC, msg); return val; } +#define _vala_warn_if_fail(expr, msg) if G_LIKELY (expr) ; else g_warn_message (G_LOG_DOMAIN, __FILE__, __LINE__, G_STRFUNC, msg); + +struct _Test { + GObject parent_instance; + TestPrivate * priv; +}; + +struct _TestClass { + GObjectClass parent_class; +}; + +struct _TestPrivate { + gchar* _test_property; +}; + +struct _TestRaw { + GObject parent_instance; + TestRawPrivate * priv; +}; + +struct _TestRawClass { + GObjectClass parent_class; +}; + +struct _TestRawPrivate { + GVariant* _test_property; +}; + +static gint Test_private_offset; +static gpointer test_parent_class = NULL; +static gint TestRaw_private_offset; +static gpointer test_raw_parent_class = NULL; +VALA_EXTERN GMainLoop* main_loop; +GMainLoop* main_loop = NULL; + +VALA_EXTERN GType test_get_type (void) G_GNUC_CONST ; +G_DEFINE_AUTOPTR_CLEANUP_FUNC (Test, g_object_unref) +VALA_EXTERN guint test_register_object (void* object, + GDBusConnection* connection, + const gchar* path, + GError** error); +VALA_EXTERN gint test_test_method (Test* self, + gint j, + gint k); +VALA_EXTERN Test* test_new (void); +VALA_EXTERN Test* test_construct (GType object_type); +VALA_EXTERN gchar* test_get_test_property (Test* self); +VALA_EXTERN void test_set_test_property (Test* self, + const gchar* value); +static void test_finalize (GObject * obj); +static GType test_get_type_once (void); +static void _vala_test_get_property (GObject * object, + guint property_id, + GValue * value, + GParamSpec * pspec); +static void _vala_test_set_property (GObject * object, + guint property_id, + const GValue * value, + GParamSpec * pspec); +static void _dbus_test_test_method (Test* self, + GVariant* _parameters_, + GDBusMethodInvocation* invocation); +static void test_dbus_interface_method_call (GDBusConnection* connection, + const gchar* sender, + const gchar* object_path, + const gchar* interface_name, + const gchar* method_name, + GVariant* parameters, + GDBusMethodInvocation* invocation, + gpointer user_data); +static GVariant* test_dbus_interface_get_property (GDBusConnection* connection, + const gchar* sender, + const gchar* object_path, + const gchar* interface_name, + const gchar* property_name, + GError** error, + gpointer user_data); +static GVariant* _dbus_test_get_test_property (Test* self); +static gboolean test_dbus_interface_set_property (GDBusConnection* connection, + const gchar* sender, + const gchar* object_path, + const gchar* interface_name, + const gchar* property_name, + GVariant* value, + GError** error, + gpointer user_data); +static void _dbus_test_set_test_property (Test* self, + GVariant* _value); +static void _dbus_test_test_signal (GObject* _sender, + gint i, + gpointer* _data); +static void _test_unregister_object (gpointer user_data); +VALA_EXTERN GType test_raw_get_type (void) G_GNUC_CONST ; +G_DEFINE_AUTOPTR_CLEANUP_FUNC (TestRaw, g_object_unref) +VALA_EXTERN guint test_raw_register_object (void* object, + GDBusConnection* connection, + const gchar* path, + GError** error); +VALA_EXTERN GVariant* test_raw_test_method (TestRaw* self, + GVariant* j, + GVariant* k); +static gint _variant_get1 (GVariant* value); +static gint _variant_get2 (GVariant* value); +static GVariant* _variant_new1 (gint value); +static GVariant* _variant_new2 (gint value); +VALA_EXTERN TestRaw* test_raw_new (void); +VALA_EXTERN TestRaw* test_raw_construct (GType object_type); +VALA_EXTERN GVariant* test_raw_get_test_property (TestRaw* self); +VALA_EXTERN void test_raw_set_test_property (TestRaw* self, + GVariant* value); +static void test_raw_finalize (GObject * obj); +static GType test_raw_get_type_once (void); +static void _vala_test_raw_get_property (GObject * object, + guint property_id, + GValue * value, + GParamSpec * pspec); +static void _vala_test_raw_set_property (GObject * object, + guint property_id, + const GValue * value, + GParamSpec * pspec); +static void _dbus_test_raw_test_method (TestRaw* self, + GVariant* _parameters_, + GDBusMethodInvocation* invocation); +static void test_raw_dbus_interface_method_call (GDBusConnection* connection, + const gchar* sender, + const gchar* object_path, + const gchar* interface_name, + const gchar* method_name, + GVariant* parameters, + GDBusMethodInvocation* invocation, + gpointer user_data); +static GVariant* test_raw_dbus_interface_get_property (GDBusConnection* connection, + const gchar* sender, + const gchar* object_path, + const gchar* interface_name, + const gchar* property_name, + GError** error, + gpointer user_data); +static GVariant* _dbus_test_raw_get_test_property (TestRaw* self); +static gboolean test_raw_dbus_interface_set_property (GDBusConnection* connection, + const gchar* sender, + const gchar* object_path, + const gchar* interface_name, + const gchar* property_name, + GVariant* value, + GError** error, + gpointer user_data); +static void _dbus_test_raw_set_test_property (TestRaw* self, + GVariant* _value); +static void _dbus_test_raw_test_signal (GObject* _sender, + GVariant* i, + gpointer* _data); +static void _test_raw_unregister_object (gpointer user_data); +VALA_EXTERN void client_exit (GPid pid, + gint status); +static void _vala_main (void); +static guint _variant_get3 (GVariant* value); +static void _client_exit_gchild_watch_func (GPid pid, + gint wait_status, + gpointer self); +static void _vala_array_destroy (gpointer array, + gssize array_length, + GDestroyNotify destroy_func); +static void _vala_array_free (gpointer array, + gssize array_length, + GDestroyNotify destroy_func); + +static const GDBusArgInfo _test_dbus_arg_info_test_method_j = {-1, "j", "i", NULL}; +static const GDBusArgInfo _test_dbus_arg_info_test_method_k = {-1, "k", "i", NULL}; +static const GDBusArgInfo _test_dbus_arg_info_test_method_result = {-1, "result", "i", NULL}; +static const GDBusArgInfo * const _test_dbus_arg_info_test_method_in[] = {&_test_dbus_arg_info_test_method_j, &_test_dbus_arg_info_test_method_k, NULL}; +static const GDBusArgInfo * const _test_dbus_arg_info_test_method_out[] = {&_test_dbus_arg_info_test_method_result, NULL}; +static const GDBusMethodInfo _test_dbus_method_info_test_method = {-1, "TestMethod", (GDBusArgInfo **) (&_test_dbus_arg_info_test_method_in), (GDBusArgInfo **) (&_test_dbus_arg_info_test_method_out), NULL}; +static const GDBusMethodInfo * const _test_dbus_method_info[] = {&_test_dbus_method_info_test_method, NULL}; +static const GDBusArgInfo _test_dbus_arg_info_test_signal_i = {-1, "i", "i", NULL}; +static const GDBusArgInfo * const _test_dbus_arg_info_test_signal[] = {&_test_dbus_arg_info_test_signal_i, NULL}; +static const GDBusSignalInfo _test_dbus_signal_info_test_signal = {-1, "TestSignal", (GDBusArgInfo **) (&_test_dbus_arg_info_test_signal), NULL}; +static const GDBusSignalInfo * const _test_dbus_signal_info[] = {&_test_dbus_signal_info_test_signal, NULL}; +static const GDBusPropertyInfo _test_dbus_property_info_test_property = {-1, "TestProperty", "s", G_DBUS_PROPERTY_INFO_FLAGS_READABLE | G_DBUS_PROPERTY_INFO_FLAGS_WRITABLE, NULL}; +static const GDBusPropertyInfo * const _test_dbus_property_info[] = {&_test_dbus_property_info_test_property, NULL}; +static const GDBusInterfaceInfo _test_dbus_interface_info = {-1, "org.example.Test", (GDBusMethodInfo **) (&_test_dbus_method_info), (GDBusSignalInfo **) (&_test_dbus_signal_info), (GDBusPropertyInfo **) (&_test_dbus_property_info), NULL}; +static const GDBusInterfaceVTable _test_dbus_interface_vtable = {test_dbus_interface_method_call, test_dbus_interface_get_property, test_dbus_interface_set_property}; +static const GDBusArgInfo _test_raw_dbus_arg_info_test_method_j = {-1, "j", "i", NULL}; +static const GDBusArgInfo _test_raw_dbus_arg_info_test_method_k = {-1, "k", "i", NULL}; +static const GDBusArgInfo _test_raw_dbus_arg_info_test_method_result = {-1, "result", "i", NULL}; +static const GDBusArgInfo * const _test_raw_dbus_arg_info_test_method_in[] = {&_test_raw_dbus_arg_info_test_method_j, &_test_raw_dbus_arg_info_test_method_k, NULL}; +static const GDBusArgInfo * const _test_raw_dbus_arg_info_test_method_out[] = {&_test_raw_dbus_arg_info_test_method_result, NULL}; +static const GDBusMethodInfo _test_raw_dbus_method_info_test_method = {-1, "TestMethod", (GDBusArgInfo **) (&_test_raw_dbus_arg_info_test_method_in), (GDBusArgInfo **) (&_test_raw_dbus_arg_info_test_method_out), NULL}; +static const GDBusMethodInfo * const _test_raw_dbus_method_info[] = {&_test_raw_dbus_method_info_test_method, NULL}; +static const GDBusArgInfo _test_raw_dbus_arg_info_test_signal_i = {-1, "i", "i", NULL}; +static const GDBusArgInfo * const _test_raw_dbus_arg_info_test_signal[] = {&_test_raw_dbus_arg_info_test_signal_i, NULL}; +static const GDBusSignalInfo _test_raw_dbus_signal_info_test_signal = {-1, "TestSignal", (GDBusArgInfo **) (&_test_raw_dbus_arg_info_test_signal), NULL}; +static const GDBusSignalInfo * const _test_raw_dbus_signal_info[] = {&_test_raw_dbus_signal_info_test_signal, NULL}; +static const GDBusPropertyInfo _test_raw_dbus_property_info_test_property = {-1, "TestProperty", "s", G_DBUS_PROPERTY_INFO_FLAGS_READABLE | G_DBUS_PROPERTY_INFO_FLAGS_WRITABLE, NULL}; +static const GDBusPropertyInfo * const _test_raw_dbus_property_info[] = {&_test_raw_dbus_property_info_test_property, NULL}; +static const GDBusInterfaceInfo _test_raw_dbus_interface_info = {-1, "org.example.Test", (GDBusMethodInfo **) (&_test_raw_dbus_method_info), (GDBusSignalInfo **) (&_test_raw_dbus_signal_info), (GDBusPropertyInfo **) (&_test_raw_dbus_property_info), NULL}; +static const GDBusInterfaceVTable _test_raw_dbus_interface_vtable = {test_raw_dbus_interface_method_call, test_raw_dbus_interface_get_property, test_raw_dbus_interface_set_property}; + +static inline gpointer +test_get_instance_private (Test* self) +{ + return G_STRUCT_MEMBER_P (self, Test_private_offset); +} + +gint +test_test_method (Test* self, + gint j, + gint k) +{ + gint result = 0; + g_return_val_if_fail (IS_TEST (self), 0); + _vala_assert (j == 23, "j == 23"); + _vala_assert (k == 11, "k == 11"); + g_signal_emit (self, test_signals[TEST_TEST_SIGNAL_SIGNAL], 0, 46); + result = 42; + return result; +} + +Test* +test_construct (GType object_type) +{ + Test * self = NULL; + self = (Test*) g_object_new (object_type, NULL); + return self; +} + +Test* +test_new (void) +{ + return test_construct (TYPE_TEST); +} + +gchar* +test_get_test_property (Test* self) +{ + gchar* result; + const gchar* _tmp0_; + gchar* _tmp1_; + g_return_val_if_fail (IS_TEST (self), NULL); + _tmp0_ = self->priv->_test_property; + _tmp1_ = g_strdup (_tmp0_); + result = _tmp1_; + return result; +} + +void +test_set_test_property (Test* self, + const gchar* value) +{ + gchar* old_value; + g_return_if_fail (IS_TEST (self)); + old_value = test_get_test_property (self); + if (g_strcmp0 (value, old_value) != 0) { + gchar* _tmp0_; + _tmp0_ = g_strdup (value); + _g_free0 (self->priv->_test_property); + self->priv->_test_property = _tmp0_; + g_object_notify_by_pspec ((GObject *) self, test_properties[TEST_TEST_PROPERTY_PROPERTY]); + } + _g_free0 (old_value); +} + +static void +test_class_init (TestClass * klass, + gpointer klass_data) +{ + test_parent_class = g_type_class_peek_parent (klass); + g_type_class_adjust_private_offset (klass, &Test_private_offset); + G_OBJECT_CLASS (klass)->get_property = _vala_test_get_property; + G_OBJECT_CLASS (klass)->set_property = _vala_test_set_property; + G_OBJECT_CLASS (klass)->finalize = test_finalize; + g_object_class_install_property (G_OBJECT_CLASS (klass), TEST_TEST_PROPERTY_PROPERTY, test_properties[TEST_TEST_PROPERTY_PROPERTY] = g_param_spec_string ("test-property", "test-property", "test-property", NULL, G_PARAM_STATIC_STRINGS | G_PARAM_READABLE | G_PARAM_WRITABLE)); + test_signals[TEST_TEST_SIGNAL_SIGNAL] = g_signal_new ("test-signal", TYPE_TEST, G_SIGNAL_RUN_LAST, 0, NULL, NULL, g_cclosure_marshal_VOID__INT, G_TYPE_NONE, 1, G_TYPE_INT); +} + +static void +test_instance_init (Test * self, + gpointer klass) +{ + self->priv = test_get_instance_private (self); +} + +static void +test_finalize (GObject * obj) +{ + Test * self; + self = G_TYPE_CHECK_INSTANCE_CAST (obj, TYPE_TEST, Test); + _g_free0 (self->priv->_test_property); + G_OBJECT_CLASS (test_parent_class)->finalize (obj); +} + +static GType +test_get_type_once (void) +{ + static const GTypeInfo g_define_type_info = { sizeof (TestClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) test_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (Test), 0, (GInstanceInitFunc) test_instance_init, NULL }; + GType test_type_id; + test_type_id = g_type_register_static (G_TYPE_OBJECT, "Test", &g_define_type_info, 0); + g_type_set_qdata (test_type_id, g_quark_from_static_string ("vala-dbus-register-object"), (void*) test_register_object); + Test_private_offset = g_type_add_instance_private (test_type_id, sizeof (TestPrivate)); + return test_type_id; +} + +GType +test_get_type (void) +{ + static volatile gsize test_type_id__volatile = 0; + if (g_once_init_enter (&test_type_id__volatile)) { + GType test_type_id; + test_type_id = test_get_type_once (); + g_once_init_leave (&test_type_id__volatile, test_type_id); + } + return test_type_id__volatile; +} + +static void +_vala_test_get_property (GObject * object, + guint property_id, + GValue * value, + GParamSpec * pspec) +{ + Test * self; + self = G_TYPE_CHECK_INSTANCE_CAST (object, TYPE_TEST, Test); + switch (property_id) { + case TEST_TEST_PROPERTY_PROPERTY: + g_value_take_string (value, test_get_test_property (self)); + break; + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); + break; + } +} + +static void +_vala_test_set_property (GObject * object, + guint property_id, + const GValue * value, + GParamSpec * pspec) +{ + Test * self; + self = G_TYPE_CHECK_INSTANCE_CAST (object, TYPE_TEST, Test); + switch (property_id) { + case TEST_TEST_PROPERTY_PROPERTY: + test_set_test_property (self, g_value_get_string (value)); + break; + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); + break; + } +} + +static void +_dbus_test_test_method (Test* self, + GVariant* _parameters_, + GDBusMethodInvocation* invocation) +{ + GError* error = NULL; + GVariantIter _arguments_iter; + gint j = 0; + GVariant* _tmp0_; + gint k = 0; + GVariant* _tmp1_; + GDBusMessage* _reply_message = NULL; + GVariant* _reply; + GVariantBuilder _reply_builder; + gint result; + g_variant_iter_init (&_arguments_iter, _parameters_); + _tmp0_ = g_variant_iter_next_value (&_arguments_iter); + j = g_variant_get_int32 (_tmp0_); + g_variant_unref (_tmp0_); + _tmp1_ = g_variant_iter_next_value (&_arguments_iter); + k = g_variant_get_int32 (_tmp1_); + g_variant_unref (_tmp1_); + result = test_test_method (self, j, k); + _reply_message = g_dbus_message_new_method_reply (g_dbus_method_invocation_get_message (invocation)); + g_variant_builder_init (&_reply_builder, G_VARIANT_TYPE_TUPLE); + g_variant_builder_add_value (&_reply_builder, g_variant_new_int32 (result)); + _reply = g_variant_builder_end (&_reply_builder); + g_dbus_message_set_body (_reply_message, _reply); + g_dbus_connection_send_message (g_dbus_method_invocation_get_connection (invocation), _reply_message, G_DBUS_SEND_MESSAGE_FLAGS_NONE, NULL, NULL); + g_object_unref (invocation); + g_object_unref (_reply_message); +} + +static void +test_dbus_interface_method_call (GDBusConnection* connection, + const gchar* sender, + const gchar* object_path, + const gchar* interface_name, + const gchar* method_name, + GVariant* parameters, + GDBusMethodInvocation* invocation, + gpointer user_data) +{ + gpointer* data; + gpointer object; + data = user_data; + object = data[0]; + if (strcmp (method_name, "TestMethod") == 0) { + _dbus_test_test_method (object, parameters, invocation); + } else { + g_object_unref (invocation); + } +} + +static GVariant* +_dbus_test_get_test_property (Test* self) +{ + gchar* result; + GVariant* _reply; + result = test_get_test_property (self); + _reply = g_variant_new_string (result); + _g_free0 (result); + return _reply; +} + +static GVariant* +test_dbus_interface_get_property (GDBusConnection* connection, + const gchar* sender, + const gchar* object_path, + const gchar* interface_name, + const gchar* property_name, + GError** error, + gpointer user_data) +{ + gpointer* data; + gpointer object; + data = user_data; + object = data[0]; + if (strcmp (property_name, "TestProperty") == 0) { + return _dbus_test_get_test_property (object); + } + return NULL; +} + +static void +_dbus_test_set_test_property (Test* self, + GVariant* _value) +{ + gchar* value = NULL; + value = g_variant_dup_string (_value, NULL); + test_set_test_property (self, value); + _g_free0 (value); +} + +static gboolean +test_dbus_interface_set_property (GDBusConnection* connection, + const gchar* sender, + const gchar* object_path, + const gchar* interface_name, + const gchar* property_name, + GVariant* value, + GError** error, + gpointer user_data) +{ + gpointer* data; + gpointer object; + data = user_data; + object = data[0]; + if (strcmp (property_name, "TestProperty") == 0) { + _dbus_test_set_test_property (object, value); + return TRUE; + } + return FALSE; +} + +static void +_dbus_test_test_signal (GObject* _sender, + gint i, + gpointer* _data) +{ + GDBusConnection * _connection; + const gchar * _path; + GVariant *_arguments; + GVariantBuilder _arguments_builder; + _connection = _data[1]; + _path = _data[2]; + g_variant_builder_init (&_arguments_builder, G_VARIANT_TYPE_TUPLE); + g_variant_builder_add_value (&_arguments_builder, g_variant_new_int32 (i)); + _arguments = g_variant_builder_end (&_arguments_builder); + g_dbus_connection_emit_signal (_connection, NULL, _path, "org.example.Test", "TestSignal", _arguments, NULL); +} + +guint +test_register_object (gpointer object, + GDBusConnection* connection, + const gchar* path, + GError** error) +{ + guint result; + gpointer *data; + data = g_new (gpointer, 3); + data[0] = g_object_ref (object); + data[1] = g_object_ref (connection); + data[2] = g_strdup (path); + result = g_dbus_connection_register_object (connection, path, (GDBusInterfaceInfo *) (&_test_dbus_interface_info), &_test_dbus_interface_vtable, data, _test_unregister_object, error); + if (!result) { + return 0; + } + g_signal_connect (object, "test-signal", (GCallback) _dbus_test_test_signal, data); + return result; +} + +static void +_test_unregister_object (gpointer user_data) +{ + gpointer* data; + data = user_data; + g_signal_handlers_disconnect_by_func (data[0], _dbus_test_test_signal, data); + g_object_unref (data[0]); + g_object_unref (data[1]); + g_free (data[2]); + g_free (data); +} + +static inline gpointer +test_raw_get_instance_private (TestRaw* self) +{ + return G_STRUCT_MEMBER_P (self, TestRaw_private_offset); +} + +static gint +_variant_get1 (GVariant* value) +{ + return g_variant_get_int32 (value); +} + +static gint +_variant_get2 (GVariant* value) +{ + return g_variant_get_int32 (value); +} + +static GVariant* +_variant_new1 (gint value) +{ + return g_variant_ref_sink (g_variant_new_int32 (value)); +} + +static GVariant* +_variant_new2 (gint value) +{ + return g_variant_ref_sink (g_variant_new_int32 (value)); +} + +GVariant* +test_raw_test_method (TestRaw* self, + GVariant* j, + GVariant* k) +{ + gint _tmp0_; + gint _tmp1_; + GVariant* _tmp2_; + GVariant* _tmp3_; + GVariant* result = NULL; + g_return_val_if_fail (IS_TEST_RAW (self), NULL); + g_return_val_if_fail (j != NULL, NULL); + g_return_val_if_fail (k != NULL, NULL); + _tmp0_ = _variant_get1 (j); + _vala_assert (_tmp0_ == 23, "(int) j == 23"); + _tmp1_ = _variant_get2 (k); + _vala_assert (_tmp1_ == 11, "(int) k == 11"); + _tmp2_ = _variant_new1 (46); + g_signal_emit (self, test_raw_signals[TEST_RAW_TEST_SIGNAL_SIGNAL], 0, _tmp2_); + _g_variant_unref0 (_tmp2_); + _tmp3_ = _variant_new2 (42); + result = _tmp3_; + return result; +} + +TestRaw* +test_raw_construct (GType object_type) +{ + TestRaw * self = NULL; + self = (TestRaw*) g_object_new (object_type, NULL); + return self; +} + +TestRaw* +test_raw_new (void) +{ + return test_raw_construct (TYPE_TEST_RAW); +} + +static gpointer +_g_variant_ref0 (gpointer self) +{ + return self ? g_variant_ref (self) : NULL; +} + +GVariant* +test_raw_get_test_property (TestRaw* self) +{ + GVariant* result; + GVariant* _tmp0_; + GVariant* _tmp1_; + g_return_val_if_fail (IS_TEST_RAW (self), NULL); + _tmp0_ = self->priv->_test_property; + _tmp1_ = _g_variant_ref0 (_tmp0_); + result = _tmp1_; + return result; +} + +void +test_raw_set_test_property (TestRaw* self, + GVariant* value) +{ + GVariant* old_value; + g_return_if_fail (IS_TEST_RAW (self)); + old_value = test_raw_get_test_property (self); + if (old_value != value) { + GVariant* _tmp0_; + _tmp0_ = _g_variant_ref0 (value); + _g_variant_unref0 (self->priv->_test_property); + self->priv->_test_property = _tmp0_; + g_object_notify_by_pspec ((GObject *) self, test_raw_properties[TEST_RAW_TEST_PROPERTY_PROPERTY]); + } + _g_variant_unref0 (old_value); +} + +static void +test_raw_class_init (TestRawClass * klass, + gpointer klass_data) +{ + test_raw_parent_class = g_type_class_peek_parent (klass); + g_type_class_adjust_private_offset (klass, &TestRaw_private_offset); + G_OBJECT_CLASS (klass)->get_property = _vala_test_raw_get_property; + G_OBJECT_CLASS (klass)->set_property = _vala_test_raw_set_property; + G_OBJECT_CLASS (klass)->finalize = test_raw_finalize; + g_object_class_install_property (G_OBJECT_CLASS (klass), TEST_RAW_TEST_PROPERTY_PROPERTY, test_raw_properties[TEST_RAW_TEST_PROPERTY_PROPERTY] = g_param_spec_variant ("test-property", "test-property", "test-property", G_VARIANT_TYPE_ANY, NULL, G_PARAM_STATIC_STRINGS | G_PARAM_READABLE | G_PARAM_WRITABLE)); + test_raw_signals[TEST_RAW_TEST_SIGNAL_SIGNAL] = g_signal_new ("test-signal", TYPE_TEST_RAW, G_SIGNAL_RUN_LAST, 0, NULL, NULL, g_cclosure_marshal_VOID__VARIANT, G_TYPE_NONE, 1, G_TYPE_VARIANT); +} + +static void +test_raw_instance_init (TestRaw * self, + gpointer klass) +{ + self->priv = test_raw_get_instance_private (self); +} + +static void +test_raw_finalize (GObject * obj) +{ + TestRaw * self; + self = G_TYPE_CHECK_INSTANCE_CAST (obj, TYPE_TEST_RAW, TestRaw); + _g_variant_unref0 (self->priv->_test_property); + G_OBJECT_CLASS (test_raw_parent_class)->finalize (obj); +} + +static GType +test_raw_get_type_once (void) +{ + static const GTypeInfo g_define_type_info = { sizeof (TestRawClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) test_raw_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (TestRaw), 0, (GInstanceInitFunc) test_raw_instance_init, NULL }; + GType test_raw_type_id; + test_raw_type_id = g_type_register_static (G_TYPE_OBJECT, "TestRaw", &g_define_type_info, 0); + g_type_set_qdata (test_raw_type_id, g_quark_from_static_string ("vala-dbus-register-object"), (void*) test_raw_register_object); + TestRaw_private_offset = g_type_add_instance_private (test_raw_type_id, sizeof (TestRawPrivate)); + return test_raw_type_id; +} + +GType +test_raw_get_type (void) +{ + static volatile gsize test_raw_type_id__volatile = 0; + if (g_once_init_enter (&test_raw_type_id__volatile)) { + GType test_raw_type_id; + test_raw_type_id = test_raw_get_type_once (); + g_once_init_leave (&test_raw_type_id__volatile, test_raw_type_id); + } + return test_raw_type_id__volatile; +} + +static void +_vala_test_raw_get_property (GObject * object, + guint property_id, + GValue * value, + GParamSpec * pspec) +{ + TestRaw * self; + self = G_TYPE_CHECK_INSTANCE_CAST (object, TYPE_TEST_RAW, TestRaw); + switch (property_id) { + case TEST_RAW_TEST_PROPERTY_PROPERTY: + g_value_take_variant (value, test_raw_get_test_property (self)); + break; + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); + break; + } +} + +static void +_vala_test_raw_set_property (GObject * object, + guint property_id, + const GValue * value, + GParamSpec * pspec) +{ + TestRaw * self; + self = G_TYPE_CHECK_INSTANCE_CAST (object, TYPE_TEST_RAW, TestRaw); + switch (property_id) { + case TEST_RAW_TEST_PROPERTY_PROPERTY: + test_raw_set_test_property (self, g_value_get_variant (value)); + break; + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); + break; + } +} + +static void +_dbus_test_raw_test_method (TestRaw* self, + GVariant* _parameters_, + GDBusMethodInvocation* invocation) +{ + GError* error = NULL; + GVariantIter _arguments_iter; + GVariant* j = NULL; + GVariant* k = NULL; + GDBusMessage* _reply_message = NULL; + GVariant* _reply; + GVariantBuilder _reply_builder; + GVariant* result; + g_variant_iter_init (&_arguments_iter, _parameters_); + j = g_variant_iter_next_value (&_arguments_iter); + k = g_variant_iter_next_value (&_arguments_iter); + result = test_raw_test_method (self, j, k); + _reply_message = g_dbus_message_new_method_reply (g_dbus_method_invocation_get_message (invocation)); + g_variant_builder_init (&_reply_builder, G_VARIANT_TYPE_TUPLE); + g_variant_builder_add_value (&_reply_builder, result); + _g_variant_unref0 (result); + _reply = g_variant_builder_end (&_reply_builder); + g_dbus_message_set_body (_reply_message, _reply); + g_dbus_connection_send_message (g_dbus_method_invocation_get_connection (invocation), _reply_message, G_DBUS_SEND_MESSAGE_FLAGS_NONE, NULL, NULL); + g_object_unref (invocation); + g_object_unref (_reply_message); + _g_variant_unref0 (j); + _g_variant_unref0 (k); +} + +static void +test_raw_dbus_interface_method_call (GDBusConnection* connection, + const gchar* sender, + const gchar* object_path, + const gchar* interface_name, + const gchar* method_name, + GVariant* parameters, + GDBusMethodInvocation* invocation, + gpointer user_data) +{ + gpointer* data; + gpointer object; + data = user_data; + object = data[0]; + if (strcmp (method_name, "TestMethod") == 0) { + _dbus_test_raw_test_method (object, parameters, invocation); + } else { + g_object_unref (invocation); + } +} + +static GVariant* +_dbus_test_raw_get_test_property (TestRaw* self) +{ + GVariant* result; + GVariant* _reply; + result = test_raw_get_test_property (self); + _reply = result; + return _reply; +} + +static GVariant* +test_raw_dbus_interface_get_property (GDBusConnection* connection, + const gchar* sender, + const gchar* object_path, + const gchar* interface_name, + const gchar* property_name, + GError** error, + gpointer user_data) +{ + gpointer* data; + gpointer object; + data = user_data; + object = data[0]; + if (strcmp (property_name, "TestProperty") == 0) { + return _dbus_test_raw_get_test_property (object); + } + return NULL; +} + +static void +_dbus_test_raw_set_test_property (TestRaw* self, + GVariant* _value) +{ + GVariant* value = NULL; + value = _value; + test_raw_set_test_property (self, value); +} + +static gboolean +test_raw_dbus_interface_set_property (GDBusConnection* connection, + const gchar* sender, + const gchar* object_path, + const gchar* interface_name, + const gchar* property_name, + GVariant* value, + GError** error, + gpointer user_data) +{ + gpointer* data; + gpointer object; + data = user_data; + object = data[0]; + if (strcmp (property_name, "TestProperty") == 0) { + _dbus_test_raw_set_test_property (object, value); + return TRUE; + } + return FALSE; +} + +static void +_dbus_test_raw_test_signal (GObject* _sender, + GVariant* i, + gpointer* _data) +{ + GDBusConnection * _connection; + const gchar * _path; + GVariant *_arguments; + GVariantBuilder _arguments_builder; + _connection = _data[1]; + _path = _data[2]; + g_variant_builder_init (&_arguments_builder, G_VARIANT_TYPE_TUPLE); + g_variant_builder_add_value (&_arguments_builder, i); + _arguments = g_variant_builder_end (&_arguments_builder); + g_dbus_connection_emit_signal (_connection, NULL, _path, "org.example.Test", "TestSignal", _arguments, NULL); +} + +guint +test_raw_register_object (gpointer object, + GDBusConnection* connection, + const gchar* path, + GError** error) +{ + guint result; + gpointer *data; + data = g_new (gpointer, 3); + data[0] = g_object_ref (object); + data[1] = g_object_ref (connection); + data[2] = g_strdup (path); + result = g_dbus_connection_register_object (connection, path, (GDBusInterfaceInfo *) (&_test_raw_dbus_interface_info), &_test_raw_dbus_interface_vtable, data, _test_raw_unregister_object, error); + if (!result) { + return 0; + } + g_signal_connect (object, "test-signal", (GCallback) _dbus_test_raw_test_signal, data); + return result; +} + +static void +_test_raw_unregister_object (gpointer user_data) +{ + gpointer* data; + data = user_data; + g_signal_handlers_disconnect_by_func (data[0], _dbus_test_raw_test_signal, data); + g_object_unref (data[0]); + g_object_unref (data[1]); + g_free (data[2]); + g_free (data); +} + +void +client_exit (GPid pid, + gint status) +{ + GMainLoop* _tmp0_; + _vala_assert (status == 0, "status == 0"); + _tmp0_ = main_loop; + g_main_loop_quit (_tmp0_); +} + +static guint +_variant_get3 (GVariant* value) +{ + return g_variant_get_uint32 (value); +} + +static void +_client_exit_gchild_watch_func (GPid pid, + gint wait_status, + gpointer self) +{ + client_exit (pid, wait_status); +} + +static void +_vala_main (void) +{ + GDBusConnection* conn = NULL; + GDBusConnection* _tmp0_; + GDBusConnection* _tmp1_; + Test* _tmp2_; + Test* _tmp3_; + GDBusConnection* _tmp4_; + TestRaw* _tmp5_; + TestRaw* _tmp6_; + GVariant* request_result = NULL; + GDBusConnection* _tmp7_; + GVariant* _tmp8_; + GVariant* _tmp9_; + GVariant* _tmp10_; + GVariant* _tmp11_; + GVariant* _tmp12_; + GVariant* _tmp13_; + GVariant* _tmp14_; + guint _tmp15_; + GPid client_pid = 0; + gchar* _tmp16_; + gchar** _tmp17_; + gchar** _tmp18_; + gint _tmp18__length1; + GPid _tmp19_ = 0; + GMainLoop* _tmp20_; + GMainLoop* _tmp21_; + GError* _inner_error0_ = NULL; + _tmp0_ = g_bus_get_sync (G_BUS_TYPE_SESSION, NULL, &_inner_error0_); + conn = _tmp0_; + if (G_UNLIKELY (_inner_error0_ != NULL)) { + g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error0_->message, g_quark_to_string (_inner_error0_->domain), _inner_error0_->code); + g_clear_error (&_inner_error0_); + return; + } + _tmp1_ = conn; + _tmp2_ = test_new (); + _tmp3_ = _tmp2_; + test_register_object (_tmp3_, _tmp1_, "/org/example/test", &_inner_error0_); + _g_object_unref0 (_tmp3_); + if (G_UNLIKELY (_inner_error0_ != NULL)) { + _g_object_unref0 (conn); + g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error0_->message, g_quark_to_string (_inner_error0_->domain), _inner_error0_->code); + g_clear_error (&_inner_error0_); + return; + } + _tmp4_ = conn; + _tmp5_ = test_raw_new (); + _tmp6_ = _tmp5_; + test_raw_register_object (_tmp6_, _tmp4_, "/org/example/testraw", &_inner_error0_); + _g_object_unref0 (_tmp6_); + if (G_UNLIKELY (_inner_error0_ != NULL)) { + _g_object_unref0 (conn); + g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error0_->message, g_quark_to_string (_inner_error0_->domain), _inner_error0_->code); + g_clear_error (&_inner_error0_); + return; + } + _tmp7_ = conn; + _tmp8_ = g_variant_new ("(su)", "org.example.Test", 0x4, NULL); + g_variant_ref_sink (_tmp8_); + _tmp9_ = _tmp8_; + _tmp10_ = g_dbus_connection_call_sync (_tmp7_, "org.freedesktop.DBus", "/org/freedesktop/DBus", "org.freedesktop.DBus", "RequestName", _tmp9_, NULL, 0, -1, NULL, &_inner_error0_); + _tmp11_ = _tmp10_; + _g_variant_unref0 (_tmp9_); + request_result = _tmp11_; + if (G_UNLIKELY (_inner_error0_ != NULL)) { + _g_object_unref0 (conn); + g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error0_->message, g_quark_to_string (_inner_error0_->domain), _inner_error0_->code); + g_clear_error (&_inner_error0_); + return; + } + _tmp12_ = request_result; + _tmp13_ = g_variant_get_child_value (_tmp12_, (gsize) 0); + _tmp14_ = _tmp13_; + _tmp15_ = _variant_get3 (_tmp14_); + _vala_assert (_tmp15_ == ((guint) 1), "(uint) request_result.get_child_value (0) == 1"); + _g_variant_unref0 (_tmp14_); + _tmp16_ = g_strdup ("dbus_rawvariants_client"); + _tmp17_ = g_new0 (gchar*, 1 + 1); + _tmp17_[0] = _tmp16_; + _tmp18_ = _tmp17_; + _tmp18__length1 = 1; + g_spawn_async (NULL, _tmp18_, NULL, G_SPAWN_DO_NOT_REAP_CHILD, NULL, NULL, &_tmp19_, &_inner_error0_); + client_pid = _tmp19_; + _tmp18_ = (_vala_array_free (_tmp18_, _tmp18__length1, (GDestroyNotify) g_free), NULL); + if (G_UNLIKELY (_inner_error0_ != NULL)) { + _g_variant_unref0 (request_result); + _g_object_unref0 (conn); + g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error0_->message, g_quark_to_string (_inner_error0_->domain), _inner_error0_->code); + g_clear_error (&_inner_error0_); + return; + } + g_child_watch_add_full (G_PRIORITY_DEFAULT_IDLE, client_pid, _client_exit_gchild_watch_func, NULL, NULL); + _tmp20_ = g_main_loop_new (NULL, FALSE); + _g_main_loop_unref0 (main_loop); + main_loop = _tmp20_; + _tmp21_ = main_loop; + g_main_loop_run (_tmp21_); + _g_variant_unref0 (request_result); + _g_object_unref0 (conn); +} + +int +main (int argc, + char ** argv) +{ + _vala_main (); + return 0; +} + +static void +_vala_array_destroy (gpointer array, + gssize array_length, + GDestroyNotify destroy_func) +{ + if ((array != NULL) && (destroy_func != NULL)) { + gssize i; + for (i = 0; i < array_length; i = i + 1) { + if (((gpointer*) array)[i] != NULL) { + destroy_func (((gpointer*) array)[i]); + } + } + } +} + +static void +_vala_array_free (gpointer array, + gssize array_length, + GDestroyNotify destroy_func) +{ + _vala_array_destroy (array, array_length, destroy_func); + g_free (array); +} + diff --git a/tests/dbus/signals_client.c-expected b/tests/dbus/signals_client.c-expected new file mode 100644 index 000000000..b172477d0 --- /dev/null +++ b/tests/dbus/signals_client.c-expected @@ -0,0 +1,780 @@ +/* dbus_signals_client.c generated by valac, the Vala compiler + * generated from dbus_signals_client.vala, do not modify */ + +#include <glib-object.h> +#include <gio/gio.h> +#include <glib.h> +#include <stdlib.h> +#include <string.h> + +#if !defined(VALA_EXTERN) +#if defined(_MSC_VER) +#define VALA_EXTERN __declspec(dllexport) extern +#elif __GNUC__ >= 4 +#define VALA_EXTERN __attribute__((visibility("default"))) extern +#else +#define VALA_EXTERN extern +#endif +#endif + +#define TYPE_TEST (test_get_type ()) +#define TEST(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TYPE_TEST, Test)) +#define IS_TEST(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TYPE_TEST)) +#define TEST_GET_INTERFACE(obj) (G_TYPE_INSTANCE_GET_INTERFACE ((obj), TYPE_TEST, TestIface)) + +typedef struct _Test Test; +typedef struct _TestIface TestIface; + +#define TYPE_TEST_PROXY (test_proxy_get_type ()) +enum { + TEST_FOO_SIGNAL, + TEST_BAR_SIGNAL, + TEST_FINISH_SIGNAL, + TEST_NUM_SIGNALS +}; +static guint test_signals[TEST_NUM_SIGNALS] = {0}; +typedef GDBusProxy TestProxy; +typedef GDBusProxyClass TestProxyClass; +#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL))) +#define _g_main_loop_unref0(var) ((var == NULL) ? NULL : (var = (g_main_loop_unref (var), NULL))) +#define _vala_assert(expr, msg) if G_LIKELY (expr) ; else g_assertion_message_expr (G_LOG_DOMAIN, __FILE__, __LINE__, G_STRFUNC, msg); +#define _vala_return_if_fail(expr, msg) if G_LIKELY (expr) ; else { g_return_if_fail_warning (G_LOG_DOMAIN, G_STRFUNC, msg); return; } +#define _vala_return_val_if_fail(expr, msg, val) if G_LIKELY (expr) ; else { g_return_if_fail_warning (G_LOG_DOMAIN, G_STRFUNC, msg); return val; } +#define _vala_warn_if_fail(expr, msg) if G_LIKELY (expr) ; else g_warn_message (G_LOG_DOMAIN, __FILE__, __LINE__, G_STRFUNC, msg); + +struct _TestIface { + GTypeInterface parent_iface; + void (*do_foo) (Test* self, gint i, GError** error); + void (*do_bar) (Test* self, gchar** baz, gint baz_length1, GError** error); +}; + +VALA_EXTERN GMainLoop* main_loop; +GMainLoop* main_loop = NULL; + +VALA_EXTERN GType test_proxy_get_type (void) G_GNUC_CONST ; +VALA_EXTERN guint test_register_object (void* object, + GDBusConnection* connection, + const gchar* path, + GError** error); +VALA_EXTERN GType test_get_type (void) G_GNUC_CONST ; +VALA_EXTERN void test_do_foo (Test* self, + gint i, + GError** error); +VALA_EXTERN void test_do_bar (Test* self, + gchar** baz, + gint baz_length1, + GError** error); +static void g_cclosure_user_marshal_VOID__BOXED_INT (GClosure * closure, + GValue * return_value, + guint n_param_values, + const GValue * param_values, + gpointer invocation_hint, + gpointer marshal_data); +static GType test_get_type_once (void); +static void test_proxy_g_signal (GDBusProxy* proxy, + const gchar* sender_name, + const gchar* signal_name, + GVariant* parameters); +static void _dbus_handle_test_foo (Test* self, + GVariant* parameters); +static void _dbus_handle_test_bar (Test* self, + GVariant* parameters); +static void test_proxy_do_foo (Test* self, + gint i, + GError** error); +static void test_proxy_do_bar (Test* self, + gchar** baz, + gint baz_length1, + GError** error); +static void test_proxy_test_interface_init (TestIface* iface); +static void _dbus_test_do_foo (Test* self, + GVariant* _parameters_, + GDBusMethodInvocation* invocation); +static void _dbus_test_do_bar (Test* self, + GVariant* _parameters_, + GDBusMethodInvocation* invocation); +static void test_dbus_interface_method_call (GDBusConnection* connection, + const gchar* sender, + const gchar* object_path, + const gchar* interface_name, + const gchar* method_name, + GVariant* parameters, + GDBusMethodInvocation* invocation, + gpointer user_data); +static GVariant* test_dbus_interface_get_property (GDBusConnection* connection, + const gchar* sender, + const gchar* object_path, + const gchar* interface_name, + const gchar* property_name, + GError** error, + gpointer user_data); +static gboolean test_dbus_interface_set_property (GDBusConnection* connection, + const gchar* sender, + const gchar* object_path, + const gchar* interface_name, + const gchar* property_name, + GVariant* value, + GError** error, + gpointer user_data); +static void _dbus_test_foo (GObject* _sender, + gint i, + gpointer* _data); +static void _dbus_test_bar (GObject* _sender, + gchar** baz, + gint baz_length1, + gpointer* _data); +static void _test_unregister_object (gpointer user_data); +static void _vala_main (void); +static void __lambda4_ (gint i); +static void ___lambda4__test_foo (Test* _sender, + gint i, + gpointer self); +static void __lambda5_ (gchar** baz, + gint baz_length1); +static void ___lambda5__test_bar (Test* _sender, + gchar** baz, + gint baz_length1, + gpointer self); +static void __lambda6_ (void); +static void ___lambda6__test_finish (Test* _sender, + gpointer self); +static void _vala_array_destroy (gpointer array, + gssize array_length, + GDestroyNotify destroy_func); +static void _vala_array_free (gpointer array, + gssize array_length, + GDestroyNotify destroy_func); + +static const GDBusArgInfo _test_dbus_arg_info_do_foo_i = {-1, "i", "i", NULL}; +static const GDBusArgInfo * const _test_dbus_arg_info_do_foo_in[] = {&_test_dbus_arg_info_do_foo_i, NULL}; +static const GDBusArgInfo * const _test_dbus_arg_info_do_foo_out[] = {NULL}; +static const GDBusMethodInfo _test_dbus_method_info_do_foo = {-1, "DoFoo", (GDBusArgInfo **) (&_test_dbus_arg_info_do_foo_in), (GDBusArgInfo **) (&_test_dbus_arg_info_do_foo_out), NULL}; +static const GDBusArgInfo _test_dbus_arg_info_do_bar_baz = {-1, "baz", "as", NULL}; +static const GDBusArgInfo * const _test_dbus_arg_info_do_bar_in[] = {&_test_dbus_arg_info_do_bar_baz, NULL}; +static const GDBusArgInfo * const _test_dbus_arg_info_do_bar_out[] = {NULL}; +static const GDBusMethodInfo _test_dbus_method_info_do_bar = {-1, "DoBar", (GDBusArgInfo **) (&_test_dbus_arg_info_do_bar_in), (GDBusArgInfo **) (&_test_dbus_arg_info_do_bar_out), NULL}; +static const GDBusMethodInfo * const _test_dbus_method_info[] = {&_test_dbus_method_info_do_foo, &_test_dbus_method_info_do_bar, NULL}; +static const GDBusArgInfo _test_dbus_arg_info_foo_i = {-1, "i", "i", NULL}; +static const GDBusArgInfo * const _test_dbus_arg_info_foo[] = {&_test_dbus_arg_info_foo_i, NULL}; +static const GDBusSignalInfo _test_dbus_signal_info_foo = {-1, "Foo", (GDBusArgInfo **) (&_test_dbus_arg_info_foo), NULL}; +static const GDBusArgInfo _test_dbus_arg_info_bar_baz = {-1, "baz", "as", NULL}; +static const GDBusArgInfo * const _test_dbus_arg_info_bar[] = {&_test_dbus_arg_info_bar_baz, NULL}; +static const GDBusSignalInfo _test_dbus_signal_info_bar = {-1, "Bar", (GDBusArgInfo **) (&_test_dbus_arg_info_bar), NULL}; +static const GDBusSignalInfo * const _test_dbus_signal_info[] = {&_test_dbus_signal_info_foo, &_test_dbus_signal_info_bar, NULL}; +static const GDBusPropertyInfo * const _test_dbus_property_info[] = {NULL}; +static const GDBusInterfaceInfo _test_dbus_interface_info = {-1, "org.example.Test", (GDBusMethodInfo **) (&_test_dbus_method_info), (GDBusSignalInfo **) (&_test_dbus_signal_info), (GDBusPropertyInfo **) (&_test_dbus_property_info), NULL}; +static const GDBusInterfaceVTable _test_dbus_interface_vtable = {test_dbus_interface_method_call, test_dbus_interface_get_property, test_dbus_interface_set_property}; + +void +test_do_foo (Test* self, + gint i, + GError** error) +{ + TestIface* _iface_; + g_return_if_fail (IS_TEST (self)); + _iface_ = TEST_GET_INTERFACE (self); + if (_iface_->do_foo) { + _iface_->do_foo (self, i, error); + } +} + +void +test_do_bar (Test* self, + gchar** baz, + gint baz_length1, + GError** error) +{ + TestIface* _iface_; + g_return_if_fail (IS_TEST (self)); + _iface_ = TEST_GET_INTERFACE (self); + if (_iface_->do_bar) { + _iface_->do_bar (self, baz, baz_length1, error); + } +} + +static void +g_cclosure_user_marshal_VOID__BOXED_INT (GClosure * closure, + GValue * return_value, + guint n_param_values, + const GValue * param_values, + gpointer invocation_hint, + gpointer marshal_data) +{ + typedef void (*GMarshalFunc_VOID__BOXED_INT) (gpointer data1, gpointer arg_1, gint arg_2, gpointer data2); + register GMarshalFunc_VOID__BOXED_INT callback; + register GCClosure * cc; + register gpointer data1; + register gpointer data2; + cc = (GCClosure *) closure; + g_return_if_fail (n_param_values == 3); + if (G_CCLOSURE_SWAP_DATA (closure)) { + data1 = closure->data; + data2 = param_values->data[0].v_pointer; + } else { + data1 = param_values->data[0].v_pointer; + data2 = closure->data; + } + callback = (GMarshalFunc_VOID__BOXED_INT) (marshal_data ? marshal_data : cc->callback); + callback (data1, g_value_get_boxed (param_values + 1), g_value_get_int (param_values + 2), data2); +} + +static void +test_default_init (TestIface * iface, + gpointer iface_data) +{ + test_signals[TEST_FOO_SIGNAL] = g_signal_new ("foo", TYPE_TEST, G_SIGNAL_RUN_LAST, 0, NULL, NULL, g_cclosure_marshal_VOID__INT, G_TYPE_NONE, 1, G_TYPE_INT); + test_signals[TEST_BAR_SIGNAL] = g_signal_new ("bar", TYPE_TEST, G_SIGNAL_RUN_LAST, 0, NULL, NULL, g_cclosure_user_marshal_VOID__BOXED_INT, G_TYPE_NONE, 2, G_TYPE_STRV, G_TYPE_INT); + test_signals[TEST_FINISH_SIGNAL] = g_signal_new ("finish", TYPE_TEST, G_SIGNAL_RUN_LAST, 0, NULL, NULL, g_cclosure_marshal_VOID__VOID, G_TYPE_NONE, 0); +} + +static GType +test_get_type_once (void) +{ + static const GTypeInfo g_define_type_info = { sizeof (TestIface), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) test_default_init, (GClassFinalizeFunc) NULL, NULL, 0, 0, (GInstanceInitFunc) NULL, NULL }; + GType test_type_id; + test_type_id = g_type_register_static (G_TYPE_INTERFACE, "Test", &g_define_type_info, 0); + g_type_interface_add_prerequisite (test_type_id, G_TYPE_OBJECT); + g_type_set_qdata (test_type_id, g_quark_from_static_string ("vala-dbus-proxy-type"), (void*) test_proxy_get_type); + g_type_set_qdata (test_type_id, g_quark_from_static_string ("vala-dbus-interface-name"), "org.example.Test"); + g_type_set_qdata (test_type_id, g_quark_from_static_string ("vala-dbus-interface-info"), (void*) (&_test_dbus_interface_info)); + g_type_set_qdata (test_type_id, g_quark_from_static_string ("vala-dbus-register-object"), (void*) test_register_object); + return test_type_id; +} + +GType +test_get_type (void) +{ + static volatile gsize test_type_id__volatile = 0; + if (g_once_init_enter (&test_type_id__volatile)) { + GType test_type_id; + test_type_id = test_get_type_once (); + g_once_init_leave (&test_type_id__volatile, test_type_id); + } + return test_type_id__volatile; +} + +G_DEFINE_TYPE_EXTENDED (TestProxy, test_proxy, G_TYPE_DBUS_PROXY, 0, G_IMPLEMENT_INTERFACE (TYPE_TEST, test_proxy_test_interface_init) ) +static void +test_proxy_class_init (TestProxyClass* klass) +{ + G_DBUS_PROXY_CLASS (klass)->g_signal = test_proxy_g_signal; +} + +static void +_dbus_handle_test_foo (Test* self, + GVariant* parameters) +{ + GVariantIter _arguments_iter; + gint i = 0; + GVariant* _tmp0_; + g_variant_iter_init (&_arguments_iter, parameters); + _tmp0_ = g_variant_iter_next_value (&_arguments_iter); + i = g_variant_get_int32 (_tmp0_); + g_variant_unref (_tmp0_); + g_signal_emit_by_name (self, "foo", i); +} + +static void +_dbus_handle_test_bar (Test* self, + GVariant* parameters) +{ + GVariantIter _arguments_iter; + gchar** baz = NULL; + gint baz_length1; + GVariant* _tmp1_; + gchar** _tmp2_; + gint _tmp2__length; + gint _tmp2__size; + gint _tmp2__length1; + GVariantIter _tmp3_; + GVariant* _tmp4_; + g_variant_iter_init (&_arguments_iter, parameters); + baz_length1 = 0; + _tmp1_ = g_variant_iter_next_value (&_arguments_iter); + _tmp2_ = g_new (gchar*, 5); + _tmp2__length = 0; + _tmp2__size = 4; + _tmp2__length1 = 0; + g_variant_iter_init (&_tmp3_, _tmp1_); + for (; (_tmp4_ = g_variant_iter_next_value (&_tmp3_)) != NULL; _tmp2__length1++) { + if (_tmp2__size == _tmp2__length) { + _tmp2__size = 2 * _tmp2__size; + _tmp2_ = g_renew (gchar*, _tmp2_, _tmp2__size + 1); + } + _tmp2_[_tmp2__length++] = g_variant_dup_string (_tmp4_, NULL); + g_variant_unref (_tmp4_); + } + baz_length1 = _tmp2__length1; + _tmp2_[_tmp2__length] = NULL; + baz = _tmp2_; + g_variant_unref (_tmp1_); + g_signal_emit_by_name (self, "bar", baz, baz_length1); + baz = (_vala_array_free (baz, baz_length1, (GDestroyNotify) g_free), NULL); +} + +static void +test_proxy_g_signal (GDBusProxy* proxy, + const gchar* sender_name, + const gchar* signal_name, + GVariant* parameters) +{ + if (strcmp (signal_name, "Foo") == 0) { + _dbus_handle_test_foo ((Test*) proxy, parameters); + } else if (strcmp (signal_name, "Bar") == 0) { + _dbus_handle_test_bar ((Test*) proxy, parameters); + } +} + +static void +test_proxy_init (TestProxy* self) +{ + g_dbus_proxy_set_interface_info (G_DBUS_PROXY (self), (GDBusInterfaceInfo *) (&_test_dbus_interface_info)); +} + +static void +test_proxy_do_foo (Test* self, + gint i, + GError** error) +{ + GDBusMessage *_message; + GVariant *_arguments; + GVariantBuilder _arguments_builder; + GDBusMessage *_reply_message; + G_DBUS_ERROR; + G_IO_ERROR; + _message = g_dbus_message_new_method_call (g_dbus_proxy_get_name ((GDBusProxy *) self), g_dbus_proxy_get_object_path ((GDBusProxy *) self), "org.example.Test", "DoFoo"); + g_variant_builder_init (&_arguments_builder, G_VARIANT_TYPE_TUPLE); + g_variant_builder_add_value (&_arguments_builder, g_variant_new_int32 (i)); + _arguments = g_variant_builder_end (&_arguments_builder); + g_dbus_message_set_body (_message, _arguments); + _reply_message = g_dbus_connection_send_message_with_reply_sync (g_dbus_proxy_get_connection ((GDBusProxy *) self), _message, G_DBUS_SEND_MESSAGE_FLAGS_NONE, g_dbus_proxy_get_default_timeout ((GDBusProxy *) self), NULL, NULL, error); + g_object_unref (_message); + if (!_reply_message) { + return; + } + if (g_dbus_message_to_gerror (_reply_message, error)) { + g_object_unref (_reply_message); + return; + } + g_object_unref (_reply_message); +} + +static void +test_proxy_do_bar (Test* self, + gchar** baz, + gint baz_length1, + GError** error) +{ + GDBusMessage *_message; + GVariant *_arguments; + GVariantBuilder _arguments_builder; + gchar** _tmp5_; + GVariantBuilder _tmp6_; + gint _tmp7_; + GDBusMessage *_reply_message; + G_DBUS_ERROR; + G_IO_ERROR; + _message = g_dbus_message_new_method_call (g_dbus_proxy_get_name ((GDBusProxy *) self), g_dbus_proxy_get_object_path ((GDBusProxy *) self), "org.example.Test", "DoBar"); + g_variant_builder_init (&_arguments_builder, G_VARIANT_TYPE_TUPLE); + _tmp5_ = baz; + g_variant_builder_init (&_tmp6_, G_VARIANT_TYPE ("as")); + for (_tmp7_ = 0; _tmp7_ < baz_length1; _tmp7_++) { + g_variant_builder_add_value (&_tmp6_, g_variant_new_string (*_tmp5_)); + _tmp5_++; + } + g_variant_builder_add_value (&_arguments_builder, g_variant_builder_end (&_tmp6_)); + _arguments = g_variant_builder_end (&_arguments_builder); + g_dbus_message_set_body (_message, _arguments); + _reply_message = g_dbus_connection_send_message_with_reply_sync (g_dbus_proxy_get_connection ((GDBusProxy *) self), _message, G_DBUS_SEND_MESSAGE_FLAGS_NONE, g_dbus_proxy_get_default_timeout ((GDBusProxy *) self), NULL, NULL, error); + g_object_unref (_message); + if (!_reply_message) { + return; + } + if (g_dbus_message_to_gerror (_reply_message, error)) { + g_object_unref (_reply_message); + return; + } + g_object_unref (_reply_message); +} + +static void +test_proxy_test_interface_init (TestIface* iface) +{ + iface->do_foo = test_proxy_do_foo; + iface->do_bar = test_proxy_do_bar; +} + +static void +_dbus_test_do_foo (Test* self, + GVariant* _parameters_, + GDBusMethodInvocation* invocation) +{ + GError* error = NULL; + GVariantIter _arguments_iter; + gint i = 0; + GVariant* _tmp8_; + GDBusMessage* _reply_message = NULL; + GVariant* _reply; + GVariantBuilder _reply_builder; + g_variant_iter_init (&_arguments_iter, _parameters_); + _tmp8_ = g_variant_iter_next_value (&_arguments_iter); + i = g_variant_get_int32 (_tmp8_); + g_variant_unref (_tmp8_); + test_do_foo (self, i, &error); + if (error) { + g_dbus_method_invocation_return_gerror (invocation, error); + g_error_free (error); + return; + } + _reply_message = g_dbus_message_new_method_reply (g_dbus_method_invocation_get_message (invocation)); + g_variant_builder_init (&_reply_builder, G_VARIANT_TYPE_TUPLE); + _reply = g_variant_builder_end (&_reply_builder); + g_dbus_message_set_body (_reply_message, _reply); + g_dbus_connection_send_message (g_dbus_method_invocation_get_connection (invocation), _reply_message, G_DBUS_SEND_MESSAGE_FLAGS_NONE, NULL, NULL); + g_object_unref (invocation); + g_object_unref (_reply_message); +} + +static void +_dbus_test_do_bar (Test* self, + GVariant* _parameters_, + GDBusMethodInvocation* invocation) +{ + GError* error = NULL; + GVariantIter _arguments_iter; + gchar** baz = NULL; + gint baz_length1 = 0; + GVariant* _tmp9_; + gchar** _tmp10_; + gint _tmp10__length; + gint _tmp10__size; + gint _tmp10__length1; + GVariantIter _tmp11_; + GVariant* _tmp12_; + GDBusMessage* _reply_message = NULL; + GVariant* _reply; + GVariantBuilder _reply_builder; + g_variant_iter_init (&_arguments_iter, _parameters_); + _tmp9_ = g_variant_iter_next_value (&_arguments_iter); + _tmp10_ = g_new (gchar*, 5); + _tmp10__length = 0; + _tmp10__size = 4; + _tmp10__length1 = 0; + g_variant_iter_init (&_tmp11_, _tmp9_); + for (; (_tmp12_ = g_variant_iter_next_value (&_tmp11_)) != NULL; _tmp10__length1++) { + if (_tmp10__size == _tmp10__length) { + _tmp10__size = 2 * _tmp10__size; + _tmp10_ = g_renew (gchar*, _tmp10_, _tmp10__size + 1); + } + _tmp10_[_tmp10__length++] = g_variant_dup_string (_tmp12_, NULL); + g_variant_unref (_tmp12_); + } + baz_length1 = _tmp10__length1; + _tmp10_[_tmp10__length] = NULL; + baz = _tmp10_; + g_variant_unref (_tmp9_); + test_do_bar (self, baz, baz_length1, &error); + if (error) { + g_dbus_method_invocation_return_gerror (invocation, error); + g_error_free (error); + goto _error; + } + _reply_message = g_dbus_message_new_method_reply (g_dbus_method_invocation_get_message (invocation)); + g_variant_builder_init (&_reply_builder, G_VARIANT_TYPE_TUPLE); + _reply = g_variant_builder_end (&_reply_builder); + g_dbus_message_set_body (_reply_message, _reply); + g_dbus_connection_send_message (g_dbus_method_invocation_get_connection (invocation), _reply_message, G_DBUS_SEND_MESSAGE_FLAGS_NONE, NULL, NULL); + g_object_unref (invocation); + g_object_unref (_reply_message); + _error: + baz = (_vala_array_free (baz, baz_length1, (GDestroyNotify) g_free), NULL); + ; +} + +static void +test_dbus_interface_method_call (GDBusConnection* connection, + const gchar* sender, + const gchar* object_path, + const gchar* interface_name, + const gchar* method_name, + GVariant* parameters, + GDBusMethodInvocation* invocation, + gpointer user_data) +{ + gpointer* data; + gpointer object; + data = user_data; + object = data[0]; + if (strcmp (method_name, "DoFoo") == 0) { + _dbus_test_do_foo (object, parameters, invocation); + } else if (strcmp (method_name, "DoBar") == 0) { + _dbus_test_do_bar (object, parameters, invocation); + } else { + g_object_unref (invocation); + } +} + +static GVariant* +test_dbus_interface_get_property (GDBusConnection* connection, + const gchar* sender, + const gchar* object_path, + const gchar* interface_name, + const gchar* property_name, + GError** error, + gpointer user_data) +{ + gpointer* data; + gpointer object; + data = user_data; + object = data[0]; + return NULL; +} + +static gboolean +test_dbus_interface_set_property (GDBusConnection* connection, + const gchar* sender, + const gchar* object_path, + const gchar* interface_name, + const gchar* property_name, + GVariant* value, + GError** error, + gpointer user_data) +{ + gpointer* data; + gpointer object; + data = user_data; + object = data[0]; + return FALSE; +} + +static void +_dbus_test_foo (GObject* _sender, + gint i, + gpointer* _data) +{ + GDBusConnection * _connection; + const gchar * _path; + GVariant *_arguments; + GVariantBuilder _arguments_builder; + _connection = _data[1]; + _path = _data[2]; + g_variant_builder_init (&_arguments_builder, G_VARIANT_TYPE_TUPLE); + g_variant_builder_add_value (&_arguments_builder, g_variant_new_int32 (i)); + _arguments = g_variant_builder_end (&_arguments_builder); + g_dbus_connection_emit_signal (_connection, NULL, _path, "org.example.Test", "Foo", _arguments, NULL); +} + +static void +_dbus_test_bar (GObject* _sender, + gchar** baz, + gint baz_length1, + gpointer* _data) +{ + GDBusConnection * _connection; + const gchar * _path; + GVariant *_arguments; + GVariantBuilder _arguments_builder; + gchar** _tmp13_; + GVariantBuilder _tmp14_; + gint _tmp15_; + _connection = _data[1]; + _path = _data[2]; + g_variant_builder_init (&_arguments_builder, G_VARIANT_TYPE_TUPLE); + _tmp13_ = baz; + g_variant_builder_init (&_tmp14_, G_VARIANT_TYPE ("as")); + for (_tmp15_ = 0; _tmp15_ < baz_length1; _tmp15_++) { + g_variant_builder_add_value (&_tmp14_, g_variant_new_string (*_tmp13_)); + _tmp13_++; + } + g_variant_builder_add_value (&_arguments_builder, g_variant_builder_end (&_tmp14_)); + _arguments = g_variant_builder_end (&_arguments_builder); + g_dbus_connection_emit_signal (_connection, NULL, _path, "org.example.Test", "Bar", _arguments, NULL); +} + +guint +test_register_object (gpointer object, + GDBusConnection* connection, + const gchar* path, + GError** error) +{ + guint result; + gpointer *data; + data = g_new (gpointer, 3); + data[0] = g_object_ref (object); + data[1] = g_object_ref (connection); + data[2] = g_strdup (path); + result = g_dbus_connection_register_object (connection, path, (GDBusInterfaceInfo *) (&_test_dbus_interface_info), &_test_dbus_interface_vtable, data, _test_unregister_object, error); + if (!result) { + return 0; + } + g_signal_connect (object, "foo", (GCallback) _dbus_test_foo, data); + g_signal_connect (object, "bar", (GCallback) _dbus_test_bar, data); + return result; +} + +static void +_test_unregister_object (gpointer user_data) +{ + gpointer* data; + data = user_data; + g_signal_handlers_disconnect_by_func (data[0], _dbus_test_foo, data); + g_signal_handlers_disconnect_by_func (data[0], _dbus_test_bar, data); + g_object_unref (data[0]); + g_object_unref (data[1]); + g_free (data[2]); + g_free (data); +} + +static void +__lambda4_ (gint i) +{ + _vala_assert (i == 42, "i == 42"); +} + +static void +___lambda4__test_foo (Test* _sender, + gint i, + gpointer self) +{ + __lambda4_ (i); +} + +static void +__lambda5_ (gchar** baz, + gint baz_length1) +{ + const gchar* _tmp0_; + const gchar* _tmp1_; + const gchar* _tmp2_; + GMainLoop* _tmp3_; + _vala_assert (baz_length1 == 3, "baz.length == 3"); + _tmp0_ = baz[0]; + _vala_assert (g_strcmp0 (_tmp0_, "zero") == 0, "baz[0] == \"zero\""); + _tmp1_ = baz[1]; + _vala_assert (g_strcmp0 (_tmp1_, "one") == 0, "baz[1] == \"one\""); + _tmp2_ = baz[2]; + _vala_assert (g_strcmp0 (_tmp2_, "two") == 0, "baz[2] == \"two\""); + _tmp3_ = main_loop; + g_main_loop_quit (_tmp3_); +} + +static void +___lambda5__test_bar (Test* _sender, + gchar** baz, + gint baz_length1, + gpointer self) +{ + __lambda5_ (baz, baz_length1); +} + +static void +__lambda6_ (void) +{ + g_assert_not_reached (); +} + +static void +___lambda6__test_finish (Test* _sender, + gpointer self) +{ + __lambda6_ (); +} + +static void +_vala_main (void) +{ + Test* test = NULL; + Test* _tmp0_; + Test* _tmp1_; + Test* _tmp2_; + Test* _tmp3_; + Test* _tmp4_; + Test* _tmp5_; + gchar* _tmp6_; + gchar* _tmp7_; + gchar* _tmp8_; + gchar** _tmp9_; + gchar** _tmp10_; + gint _tmp10__length1; + GMainLoop* _tmp11_; + GMainLoop* _tmp12_; + GError* _inner_error0_ = NULL; + _tmp0_ = (Test*) g_initable_new (TYPE_TEST_PROXY, NULL, &_inner_error0_, "g-flags", 0, "g-name", "org.example.Test", "g-bus-type", G_BUS_TYPE_SESSION, "g-object-path", "/org/example/test", "g-interface-name", "org.example.Test", NULL); + test = (Test*) _tmp0_; + if (G_UNLIKELY (_inner_error0_ != NULL)) { + g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error0_->message, g_quark_to_string (_inner_error0_->domain), _inner_error0_->code); + g_clear_error (&_inner_error0_); + return; + } + _tmp1_ = test; + g_signal_connect (_tmp1_, "foo", (GCallback) ___lambda4__test_foo, NULL); + _tmp2_ = test; + g_signal_connect (_tmp2_, "bar", (GCallback) ___lambda5__test_bar, NULL); + _tmp3_ = test; + g_signal_connect (_tmp3_, "finish", (GCallback) ___lambda6__test_finish, NULL); + _tmp4_ = test; + test_do_foo (_tmp4_, 42, &_inner_error0_); + if (G_UNLIKELY (_inner_error0_ != NULL)) { + _g_object_unref0 (test); + g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error0_->message, g_quark_to_string (_inner_error0_->domain), _inner_error0_->code); + g_clear_error (&_inner_error0_); + return; + } + _tmp5_ = test; + _tmp6_ = g_strdup ("zero"); + _tmp7_ = g_strdup ("one"); + _tmp8_ = g_strdup ("two"); + _tmp9_ = g_new0 (gchar*, 3 + 1); + _tmp9_[0] = _tmp6_; + _tmp9_[1] = _tmp7_; + _tmp9_[2] = _tmp8_; + _tmp10_ = _tmp9_; + _tmp10__length1 = 3; + test_do_bar (_tmp5_, _tmp10_, (gint) 3, &_inner_error0_); + _tmp10_ = (_vala_array_free (_tmp10_, _tmp10__length1, (GDestroyNotify) g_free), NULL); + if (G_UNLIKELY (_inner_error0_ != NULL)) { + _g_object_unref0 (test); + g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error0_->message, g_quark_to_string (_inner_error0_->domain), _inner_error0_->code); + g_clear_error (&_inner_error0_); + return; + } + _tmp11_ = g_main_loop_new (NULL, FALSE); + _g_main_loop_unref0 (main_loop); + main_loop = _tmp11_; + _tmp12_ = main_loop; + g_main_loop_run (_tmp12_); + _g_object_unref0 (test); +} + +int +main (int argc, + char ** argv) +{ + _vala_main (); + return 0; +} + +static void +_vala_array_destroy (gpointer array, + gssize array_length, + GDestroyNotify destroy_func) +{ + if ((array != NULL) && (destroy_func != NULL)) { + gssize i; + for (i = 0; i < array_length; i = i + 1) { + if (((gpointer*) array)[i] != NULL) { + destroy_func (((gpointer*) array)[i]); + } + } + } +} + +static void +_vala_array_free (gpointer array, + gssize array_length, + GDestroyNotify destroy_func) +{ + _vala_array_destroy (array, array_length, destroy_func); + g_free (array); +} + diff --git a/tests/dbus/signals_server.c-expected b/tests/dbus/signals_server.c-expected new file mode 100644 index 000000000..da9b02267 --- /dev/null +++ b/tests/dbus/signals_server.c-expected @@ -0,0 +1,620 @@ +/* dbus_signals_server.c generated by valac, the Vala compiler + * generated from dbus_signals_server.vala, do not modify */ + +#include <glib-object.h> +#include <gio/gio.h> +#include <glib.h> +#include <stdlib.h> +#include <string.h> + +#if !defined(VALA_EXTERN) +#if defined(_MSC_VER) +#define VALA_EXTERN __declspec(dllexport) extern +#elif __GNUC__ >= 4 +#define VALA_EXTERN __attribute__((visibility("default"))) extern +#else +#define VALA_EXTERN extern +#endif +#endif + +#define TYPE_TEST (test_get_type ()) +#define TEST(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TYPE_TEST, Test)) +#define TEST_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), TYPE_TEST, TestClass)) +#define IS_TEST(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TYPE_TEST)) +#define IS_TEST_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), TYPE_TEST)) +#define TEST_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), TYPE_TEST, TestClass)) + +typedef struct _Test Test; +typedef struct _TestClass TestClass; +typedef struct _TestPrivate TestPrivate; +enum { + TEST_0_PROPERTY, + TEST_NUM_PROPERTIES +}; +static GParamSpec* test_properties[TEST_NUM_PROPERTIES]; +enum { + TEST_FOO_SIGNAL, + TEST_BAR_SIGNAL, + TEST_FINISH_SIGNAL, + TEST_NUM_SIGNALS +}; +static guint test_signals[TEST_NUM_SIGNALS] = {0}; +#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL))) +#define _g_variant_unref0(var) ((var == NULL) ? NULL : (var = (g_variant_unref (var), NULL))) +#define _g_main_loop_unref0(var) ((var == NULL) ? NULL : (var = (g_main_loop_unref (var), NULL))) +#define _vala_assert(expr, msg) if G_LIKELY (expr) ; else g_assertion_message_expr (G_LOG_DOMAIN, __FILE__, __LINE__, G_STRFUNC, msg); +#define _vala_return_if_fail(expr, msg) if G_LIKELY (expr) ; else { g_return_if_fail_warning (G_LOG_DOMAIN, G_STRFUNC, msg); return; } +#define _vala_return_val_if_fail(expr, msg, val) if G_LIKELY (expr) ; else { g_return_if_fail_warning (G_LOG_DOMAIN, G_STRFUNC, msg); return val; } +#define _vala_warn_if_fail(expr, msg) if G_LIKELY (expr) ; else g_warn_message (G_LOG_DOMAIN, __FILE__, __LINE__, G_STRFUNC, msg); + +struct _Test { + GObject parent_instance; + TestPrivate * priv; +}; + +struct _TestClass { + GObjectClass parent_class; +}; + +static gpointer test_parent_class = NULL; +VALA_EXTERN GMainLoop* main_loop; +GMainLoop* main_loop = NULL; + +VALA_EXTERN GType test_get_type (void) G_GNUC_CONST ; +G_DEFINE_AUTOPTR_CLEANUP_FUNC (Test, g_object_unref) +VALA_EXTERN guint test_register_object (void* object, + GDBusConnection* connection, + const gchar* path, + GError** error); +VALA_EXTERN void test_do_foo (Test* self, + gint i, + GError** error); +VALA_EXTERN void test_do_bar (Test* self, + gchar** baz, + gint baz_length1, + GError** error); +VALA_EXTERN Test* test_new (void); +VALA_EXTERN Test* test_construct (GType object_type); +static void g_cclosure_user_marshal_VOID__BOXED_INT (GClosure * closure, + GValue * return_value, + guint n_param_values, + const GValue * param_values, + gpointer invocation_hint, + gpointer marshal_data); +static GType test_get_type_once (void); +static void _dbus_test_do_foo (Test* self, + GVariant* _parameters_, + GDBusMethodInvocation* invocation); +static void _dbus_test_do_bar (Test* self, + GVariant* _parameters_, + GDBusMethodInvocation* invocation); +static void test_dbus_interface_method_call (GDBusConnection* connection, + const gchar* sender, + const gchar* object_path, + const gchar* interface_name, + const gchar* method_name, + GVariant* parameters, + GDBusMethodInvocation* invocation, + gpointer user_data); +static GVariant* test_dbus_interface_get_property (GDBusConnection* connection, + const gchar* sender, + const gchar* object_path, + const gchar* interface_name, + const gchar* property_name, + GError** error, + gpointer user_data); +static gboolean test_dbus_interface_set_property (GDBusConnection* connection, + const gchar* sender, + const gchar* object_path, + const gchar* interface_name, + const gchar* property_name, + GVariant* value, + GError** error, + gpointer user_data); +static void _dbus_test_foo (GObject* _sender, + gint i, + gpointer* _data); +static void _dbus_test_bar (GObject* _sender, + gchar** baz, + gint baz_length1, + gpointer* _data); +static void _test_unregister_object (gpointer user_data); +VALA_EXTERN void client_exit (GPid pid, + gint status); +static void _vala_main (void); +static guint _variant_get1 (GVariant* value); +static void _client_exit_gchild_watch_func (GPid pid, + gint wait_status, + gpointer self); +static void _vala_array_destroy (gpointer array, + gssize array_length, + GDestroyNotify destroy_func); +static void _vala_array_free (gpointer array, + gssize array_length, + GDestroyNotify destroy_func); + +static const GDBusArgInfo _test_dbus_arg_info_do_foo_i = {-1, "i", "i", NULL}; +static const GDBusArgInfo * const _test_dbus_arg_info_do_foo_in[] = {&_test_dbus_arg_info_do_foo_i, NULL}; +static const GDBusArgInfo * const _test_dbus_arg_info_do_foo_out[] = {NULL}; +static const GDBusMethodInfo _test_dbus_method_info_do_foo = {-1, "DoFoo", (GDBusArgInfo **) (&_test_dbus_arg_info_do_foo_in), (GDBusArgInfo **) (&_test_dbus_arg_info_do_foo_out), NULL}; +static const GDBusArgInfo _test_dbus_arg_info_do_bar_baz = {-1, "baz", "as", NULL}; +static const GDBusArgInfo * const _test_dbus_arg_info_do_bar_in[] = {&_test_dbus_arg_info_do_bar_baz, NULL}; +static const GDBusArgInfo * const _test_dbus_arg_info_do_bar_out[] = {NULL}; +static const GDBusMethodInfo _test_dbus_method_info_do_bar = {-1, "DoBar", (GDBusArgInfo **) (&_test_dbus_arg_info_do_bar_in), (GDBusArgInfo **) (&_test_dbus_arg_info_do_bar_out), NULL}; +static const GDBusMethodInfo * const _test_dbus_method_info[] = {&_test_dbus_method_info_do_foo, &_test_dbus_method_info_do_bar, NULL}; +static const GDBusArgInfo _test_dbus_arg_info_foo_i = {-1, "i", "i", NULL}; +static const GDBusArgInfo * const _test_dbus_arg_info_foo[] = {&_test_dbus_arg_info_foo_i, NULL}; +static const GDBusSignalInfo _test_dbus_signal_info_foo = {-1, "Foo", (GDBusArgInfo **) (&_test_dbus_arg_info_foo), NULL}; +static const GDBusArgInfo _test_dbus_arg_info_bar_baz = {-1, "baz", "as", NULL}; +static const GDBusArgInfo * const _test_dbus_arg_info_bar[] = {&_test_dbus_arg_info_bar_baz, NULL}; +static const GDBusSignalInfo _test_dbus_signal_info_bar = {-1, "Bar", (GDBusArgInfo **) (&_test_dbus_arg_info_bar), NULL}; +static const GDBusSignalInfo * const _test_dbus_signal_info[] = {&_test_dbus_signal_info_foo, &_test_dbus_signal_info_bar, NULL}; +static const GDBusPropertyInfo * const _test_dbus_property_info[] = {NULL}; +static const GDBusInterfaceInfo _test_dbus_interface_info = {-1, "org.example.Test", (GDBusMethodInfo **) (&_test_dbus_method_info), (GDBusSignalInfo **) (&_test_dbus_signal_info), (GDBusPropertyInfo **) (&_test_dbus_property_info), NULL}; +static const GDBusInterfaceVTable _test_dbus_interface_vtable = {test_dbus_interface_method_call, test_dbus_interface_get_property, test_dbus_interface_set_property}; + +void +test_do_foo (Test* self, + gint i, + GError** error) +{ + g_return_if_fail (IS_TEST (self)); + g_signal_emit (self, test_signals[TEST_FOO_SIGNAL], 0, i); + g_signal_emit (self, test_signals[TEST_FINISH_SIGNAL], 0); +} + +void +test_do_bar (Test* self, + gchar** baz, + gint baz_length1, + GError** error) +{ + g_return_if_fail (IS_TEST (self)); + g_signal_emit (self, test_signals[TEST_BAR_SIGNAL], 0, baz, (gint) baz_length1); +} + +Test* +test_construct (GType object_type) +{ + Test * self = NULL; + self = (Test*) g_object_new (object_type, NULL); + return self; +} + +Test* +test_new (void) +{ + return test_construct (TYPE_TEST); +} + +static void +g_cclosure_user_marshal_VOID__BOXED_INT (GClosure * closure, + GValue * return_value, + guint n_param_values, + const GValue * param_values, + gpointer invocation_hint, + gpointer marshal_data) +{ + typedef void (*GMarshalFunc_VOID__BOXED_INT) (gpointer data1, gpointer arg_1, gint arg_2, gpointer data2); + register GMarshalFunc_VOID__BOXED_INT callback; + register GCClosure * cc; + register gpointer data1; + register gpointer data2; + cc = (GCClosure *) closure; + g_return_if_fail (n_param_values == 3); + if (G_CCLOSURE_SWAP_DATA (closure)) { + data1 = closure->data; + data2 = param_values->data[0].v_pointer; + } else { + data1 = param_values->data[0].v_pointer; + data2 = closure->data; + } + callback = (GMarshalFunc_VOID__BOXED_INT) (marshal_data ? marshal_data : cc->callback); + callback (data1, g_value_get_boxed (param_values + 1), g_value_get_int (param_values + 2), data2); +} + +static void +test_class_init (TestClass * klass, + gpointer klass_data) +{ + test_parent_class = g_type_class_peek_parent (klass); + test_signals[TEST_FOO_SIGNAL] = g_signal_new ("foo", TYPE_TEST, G_SIGNAL_RUN_LAST, 0, NULL, NULL, g_cclosure_marshal_VOID__INT, G_TYPE_NONE, 1, G_TYPE_INT); + test_signals[TEST_BAR_SIGNAL] = g_signal_new ("bar", TYPE_TEST, G_SIGNAL_RUN_LAST, 0, NULL, NULL, g_cclosure_user_marshal_VOID__BOXED_INT, G_TYPE_NONE, 2, G_TYPE_STRV, G_TYPE_INT); + test_signals[TEST_FINISH_SIGNAL] = g_signal_new ("finish", TYPE_TEST, G_SIGNAL_RUN_LAST, 0, NULL, NULL, g_cclosure_marshal_VOID__VOID, G_TYPE_NONE, 0); +} + +static void +test_instance_init (Test * self, + gpointer klass) +{ +} + +static GType +test_get_type_once (void) +{ + static const GTypeInfo g_define_type_info = { sizeof (TestClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) test_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (Test), 0, (GInstanceInitFunc) test_instance_init, NULL }; + GType test_type_id; + test_type_id = g_type_register_static (G_TYPE_OBJECT, "Test", &g_define_type_info, 0); + g_type_set_qdata (test_type_id, g_quark_from_static_string ("vala-dbus-register-object"), (void*) test_register_object); + return test_type_id; +} + +GType +test_get_type (void) +{ + static volatile gsize test_type_id__volatile = 0; + if (g_once_init_enter (&test_type_id__volatile)) { + GType test_type_id; + test_type_id = test_get_type_once (); + g_once_init_leave (&test_type_id__volatile, test_type_id); + } + return test_type_id__volatile; +} + +static void +_dbus_test_do_foo (Test* self, + GVariant* _parameters_, + GDBusMethodInvocation* invocation) +{ + GError* error = NULL; + GVariantIter _arguments_iter; + gint i = 0; + GVariant* _tmp0_; + GDBusMessage* _reply_message = NULL; + GVariant* _reply; + GVariantBuilder _reply_builder; + g_variant_iter_init (&_arguments_iter, _parameters_); + _tmp0_ = g_variant_iter_next_value (&_arguments_iter); + i = g_variant_get_int32 (_tmp0_); + g_variant_unref (_tmp0_); + test_do_foo (self, i, &error); + if (error) { + g_dbus_method_invocation_return_gerror (invocation, error); + g_error_free (error); + return; + } + _reply_message = g_dbus_message_new_method_reply (g_dbus_method_invocation_get_message (invocation)); + g_variant_builder_init (&_reply_builder, G_VARIANT_TYPE_TUPLE); + _reply = g_variant_builder_end (&_reply_builder); + g_dbus_message_set_body (_reply_message, _reply); + g_dbus_connection_send_message (g_dbus_method_invocation_get_connection (invocation), _reply_message, G_DBUS_SEND_MESSAGE_FLAGS_NONE, NULL, NULL); + g_object_unref (invocation); + g_object_unref (_reply_message); +} + +static void +_dbus_test_do_bar (Test* self, + GVariant* _parameters_, + GDBusMethodInvocation* invocation) +{ + GError* error = NULL; + GVariantIter _arguments_iter; + gchar** baz = NULL; + gint baz_length1 = 0; + GVariant* _tmp1_; + gchar** _tmp2_; + gint _tmp2__length; + gint _tmp2__size; + gint _tmp2__length1; + GVariantIter _tmp3_; + GVariant* _tmp4_; + GDBusMessage* _reply_message = NULL; + GVariant* _reply; + GVariantBuilder _reply_builder; + g_variant_iter_init (&_arguments_iter, _parameters_); + _tmp1_ = g_variant_iter_next_value (&_arguments_iter); + _tmp2_ = g_new (gchar*, 5); + _tmp2__length = 0; + _tmp2__size = 4; + _tmp2__length1 = 0; + g_variant_iter_init (&_tmp3_, _tmp1_); + for (; (_tmp4_ = g_variant_iter_next_value (&_tmp3_)) != NULL; _tmp2__length1++) { + if (_tmp2__size == _tmp2__length) { + _tmp2__size = 2 * _tmp2__size; + _tmp2_ = g_renew (gchar*, _tmp2_, _tmp2__size + 1); + } + _tmp2_[_tmp2__length++] = g_variant_dup_string (_tmp4_, NULL); + g_variant_unref (_tmp4_); + } + baz_length1 = _tmp2__length1; + _tmp2_[_tmp2__length] = NULL; + baz = _tmp2_; + g_variant_unref (_tmp1_); + test_do_bar (self, baz, baz_length1, &error); + if (error) { + g_dbus_method_invocation_return_gerror (invocation, error); + g_error_free (error); + goto _error; + } + _reply_message = g_dbus_message_new_method_reply (g_dbus_method_invocation_get_message (invocation)); + g_variant_builder_init (&_reply_builder, G_VARIANT_TYPE_TUPLE); + _reply = g_variant_builder_end (&_reply_builder); + g_dbus_message_set_body (_reply_message, _reply); + g_dbus_connection_send_message (g_dbus_method_invocation_get_connection (invocation), _reply_message, G_DBUS_SEND_MESSAGE_FLAGS_NONE, NULL, NULL); + g_object_unref (invocation); + g_object_unref (_reply_message); + _error: + baz = (_vala_array_free (baz, baz_length1, (GDestroyNotify) g_free), NULL); + ; +} + +static void +test_dbus_interface_method_call (GDBusConnection* connection, + const gchar* sender, + const gchar* object_path, + const gchar* interface_name, + const gchar* method_name, + GVariant* parameters, + GDBusMethodInvocation* invocation, + gpointer user_data) +{ + gpointer* data; + gpointer object; + data = user_data; + object = data[0]; + if (strcmp (method_name, "DoFoo") == 0) { + _dbus_test_do_foo (object, parameters, invocation); + } else if (strcmp (method_name, "DoBar") == 0) { + _dbus_test_do_bar (object, parameters, invocation); + } else { + g_object_unref (invocation); + } +} + +static GVariant* +test_dbus_interface_get_property (GDBusConnection* connection, + const gchar* sender, + const gchar* object_path, + const gchar* interface_name, + const gchar* property_name, + GError** error, + gpointer user_data) +{ + gpointer* data; + gpointer object; + data = user_data; + object = data[0]; + return NULL; +} + +static gboolean +test_dbus_interface_set_property (GDBusConnection* connection, + const gchar* sender, + const gchar* object_path, + const gchar* interface_name, + const gchar* property_name, + GVariant* value, + GError** error, + gpointer user_data) +{ + gpointer* data; + gpointer object; + data = user_data; + object = data[0]; + return FALSE; +} + +static void +_dbus_test_foo (GObject* _sender, + gint i, + gpointer* _data) +{ + GDBusConnection * _connection; + const gchar * _path; + GVariant *_arguments; + GVariantBuilder _arguments_builder; + _connection = _data[1]; + _path = _data[2]; + g_variant_builder_init (&_arguments_builder, G_VARIANT_TYPE_TUPLE); + g_variant_builder_add_value (&_arguments_builder, g_variant_new_int32 (i)); + _arguments = g_variant_builder_end (&_arguments_builder); + g_dbus_connection_emit_signal (_connection, NULL, _path, "org.example.Test", "Foo", _arguments, NULL); +} + +static void +_dbus_test_bar (GObject* _sender, + gchar** baz, + gint baz_length1, + gpointer* _data) +{ + GDBusConnection * _connection; + const gchar * _path; + GVariant *_arguments; + GVariantBuilder _arguments_builder; + gchar** _tmp5_; + GVariantBuilder _tmp6_; + gint _tmp7_; + _connection = _data[1]; + _path = _data[2]; + g_variant_builder_init (&_arguments_builder, G_VARIANT_TYPE_TUPLE); + _tmp5_ = baz; + g_variant_builder_init (&_tmp6_, G_VARIANT_TYPE ("as")); + for (_tmp7_ = 0; _tmp7_ < baz_length1; _tmp7_++) { + g_variant_builder_add_value (&_tmp6_, g_variant_new_string (*_tmp5_)); + _tmp5_++; + } + g_variant_builder_add_value (&_arguments_builder, g_variant_builder_end (&_tmp6_)); + _arguments = g_variant_builder_end (&_arguments_builder); + g_dbus_connection_emit_signal (_connection, NULL, _path, "org.example.Test", "Bar", _arguments, NULL); +} + +guint +test_register_object (gpointer object, + GDBusConnection* connection, + const gchar* path, + GError** error) +{ + guint result; + gpointer *data; + data = g_new (gpointer, 3); + data[0] = g_object_ref (object); + data[1] = g_object_ref (connection); + data[2] = g_strdup (path); + result = g_dbus_connection_register_object (connection, path, (GDBusInterfaceInfo *) (&_test_dbus_interface_info), &_test_dbus_interface_vtable, data, _test_unregister_object, error); + if (!result) { + return 0; + } + g_signal_connect (object, "foo", (GCallback) _dbus_test_foo, data); + g_signal_connect (object, "bar", (GCallback) _dbus_test_bar, data); + return result; +} + +static void +_test_unregister_object (gpointer user_data) +{ + gpointer* data; + data = user_data; + g_signal_handlers_disconnect_by_func (data[0], _dbus_test_foo, data); + g_signal_handlers_disconnect_by_func (data[0], _dbus_test_bar, data); + g_object_unref (data[0]); + g_object_unref (data[1]); + g_free (data[2]); + g_free (data); +} + +void +client_exit (GPid pid, + gint status) +{ + GMainLoop* _tmp0_; + _vala_assert (status == 0, "status == 0"); + _tmp0_ = main_loop; + g_main_loop_quit (_tmp0_); +} + +static guint +_variant_get1 (GVariant* value) +{ + return g_variant_get_uint32 (value); +} + +static void +_client_exit_gchild_watch_func (GPid pid, + gint wait_status, + gpointer self) +{ + client_exit (pid, wait_status); +} + +static void +_vala_main (void) +{ + GDBusConnection* conn = NULL; + GDBusConnection* _tmp0_; + GDBusConnection* _tmp1_; + Test* _tmp2_; + Test* _tmp3_; + GVariant* request_result = NULL; + GDBusConnection* _tmp4_; + GVariant* _tmp5_; + GVariant* _tmp6_; + GVariant* _tmp7_; + GVariant* _tmp8_; + GVariant* _tmp9_; + GVariant* _tmp10_; + GVariant* _tmp11_; + guint _tmp12_; + GPid client_pid = 0; + gchar* _tmp13_; + gchar** _tmp14_; + gchar** _tmp15_; + gint _tmp15__length1; + GPid _tmp16_ = 0; + GMainLoop* _tmp17_; + GMainLoop* _tmp18_; + GError* _inner_error0_ = NULL; + _tmp0_ = g_bus_get_sync (G_BUS_TYPE_SESSION, NULL, &_inner_error0_); + conn = _tmp0_; + if (G_UNLIKELY (_inner_error0_ != NULL)) { + g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error0_->message, g_quark_to_string (_inner_error0_->domain), _inner_error0_->code); + g_clear_error (&_inner_error0_); + return; + } + _tmp1_ = conn; + _tmp2_ = test_new (); + _tmp3_ = _tmp2_; + test_register_object (_tmp3_, _tmp1_, "/org/example/test", &_inner_error0_); + _g_object_unref0 (_tmp3_); + if (G_UNLIKELY (_inner_error0_ != NULL)) { + _g_object_unref0 (conn); + g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error0_->message, g_quark_to_string (_inner_error0_->domain), _inner_error0_->code); + g_clear_error (&_inner_error0_); + return; + } + _tmp4_ = conn; + _tmp5_ = g_variant_new ("(su)", "org.example.Test", 0x4, NULL); + g_variant_ref_sink (_tmp5_); + _tmp6_ = _tmp5_; + _tmp7_ = g_dbus_connection_call_sync (_tmp4_, "org.freedesktop.DBus", "/org/freedesktop/DBus", "org.freedesktop.DBus", "RequestName", _tmp6_, NULL, 0, -1, NULL, &_inner_error0_); + _tmp8_ = _tmp7_; + _g_variant_unref0 (_tmp6_); + request_result = _tmp8_; + if (G_UNLIKELY (_inner_error0_ != NULL)) { + _g_object_unref0 (conn); + g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error0_->message, g_quark_to_string (_inner_error0_->domain), _inner_error0_->code); + g_clear_error (&_inner_error0_); + return; + } + _tmp9_ = request_result; + _tmp10_ = g_variant_get_child_value (_tmp9_, (gsize) 0); + _tmp11_ = _tmp10_; + _tmp12_ = _variant_get1 (_tmp11_); + _vala_assert (_tmp12_ == ((guint) 1), "(uint) request_result.get_child_value (0) == 1"); + _g_variant_unref0 (_tmp11_); + _tmp13_ = g_strdup ("dbus_signals_client"); + _tmp14_ = g_new0 (gchar*, 1 + 1); + _tmp14_[0] = _tmp13_; + _tmp15_ = _tmp14_; + _tmp15__length1 = 1; + g_spawn_async (NULL, _tmp15_, NULL, G_SPAWN_DO_NOT_REAP_CHILD, NULL, NULL, &_tmp16_, &_inner_error0_); + client_pid = _tmp16_; + _tmp15_ = (_vala_array_free (_tmp15_, _tmp15__length1, (GDestroyNotify) g_free), NULL); + if (G_UNLIKELY (_inner_error0_ != NULL)) { + _g_variant_unref0 (request_result); + _g_object_unref0 (conn); + g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error0_->message, g_quark_to_string (_inner_error0_->domain), _inner_error0_->code); + g_clear_error (&_inner_error0_); + return; + } + g_child_watch_add_full (G_PRIORITY_DEFAULT_IDLE, client_pid, _client_exit_gchild_watch_func, NULL, NULL); + _tmp17_ = g_main_loop_new (NULL, FALSE); + _g_main_loop_unref0 (main_loop); + main_loop = _tmp17_; + _tmp18_ = main_loop; + g_main_loop_run (_tmp18_); + _g_variant_unref0 (request_result); + _g_object_unref0 (conn); +} + +int +main (int argc, + char ** argv) +{ + _vala_main (); + return 0; +} + +static void +_vala_array_destroy (gpointer array, + gssize array_length, + GDestroyNotify destroy_func) +{ + if ((array != NULL) && (destroy_func != NULL)) { + gssize i; + for (i = 0; i < array_length; i = i + 1) { + if (((gpointer*) array)[i] != NULL) { + destroy_func (((gpointer*) array)[i]); + } + } + } +} + +static void +_vala_array_free (gpointer array, + gssize array_length, + GDestroyNotify destroy_func) +{ + _vala_array_destroy (array, array_length, destroy_func); + g_free (array); +} + diff --git a/tests/dbus/structs_client.c-expected b/tests/dbus/structs_client.c-expected new file mode 100644 index 000000000..91c61053a --- /dev/null +++ b/tests/dbus/structs_client.c-expected @@ -0,0 +1,718 @@ +/* dbus_structs_client.c generated by valac, the Vala compiler + * generated from dbus_structs_client.vala, do not modify */ + +#include <glib-object.h> +#include <glib.h> +#include <stdlib.h> +#include <string.h> +#include <gio/gio.h> + +#if !defined(VALA_EXTERN) +#if defined(_MSC_VER) +#define VALA_EXTERN __declspec(dllexport) extern +#elif __GNUC__ >= 4 +#define VALA_EXTERN __attribute__((visibility("default"))) extern +#else +#define VALA_EXTERN extern +#endif +#endif + +#define TYPE_FOO_STRUCT (foo_struct_get_type ()) +typedef struct _FooStruct FooStruct; +#define _g_free0(var) (var = (g_free (var), NULL)) + +#define TYPE_TEST (test_get_type ()) +#define TEST(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TYPE_TEST, Test)) +#define IS_TEST(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TYPE_TEST)) +#define TEST_GET_INTERFACE(obj) (G_TYPE_INSTANCE_GET_INTERFACE ((obj), TYPE_TEST, TestIface)) + +typedef struct _Test Test; +typedef struct _TestIface TestIface; + +#define TYPE_TEST_PROXY (test_proxy_get_type ()) +typedef GDBusProxy TestProxy; +typedef GDBusProxyClass TestProxyClass; +#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL))) +#define _vala_assert(expr, msg) if G_LIKELY (expr) ; else g_assertion_message_expr (G_LOG_DOMAIN, __FILE__, __LINE__, G_STRFUNC, msg); +#define _vala_return_if_fail(expr, msg) if G_LIKELY (expr) ; else { g_return_if_fail_warning (G_LOG_DOMAIN, G_STRFUNC, msg); return; } +#define _vala_return_val_if_fail(expr, msg, val) if G_LIKELY (expr) ; else { g_return_if_fail_warning (G_LOG_DOMAIN, G_STRFUNC, msg); return val; } +#define _vala_warn_if_fail(expr, msg) if G_LIKELY (expr) ; else g_warn_message (G_LOG_DOMAIN, __FILE__, __LINE__, G_STRFUNC, msg); + +struct _FooStruct { + gint i; + gchar* s; +}; + +struct _TestIface { + GTypeInterface parent_iface; + void (*test_struct) (Test* self, FooStruct* f, FooStruct* g, FooStruct* result, GError** error); + void (*get_test_property) (Test* self, FooStruct * result); + void (*set_test_property) (Test* self, FooStruct * value); +}; + +VALA_EXTERN GType foo_struct_get_type (void) G_GNUC_CONST ; +VALA_EXTERN FooStruct* foo_struct_dup (const FooStruct* self); +VALA_EXTERN void foo_struct_free (FooStruct* self); +VALA_EXTERN void foo_struct_copy (const FooStruct* self, + FooStruct* dest); +VALA_EXTERN void foo_struct_destroy (FooStruct* self); +VALA_EXTERN void foo_struct_init (FooStruct *self, + gint i, + const gchar* s); +VALA_EXTERN GType test_proxy_get_type (void) G_GNUC_CONST ; +VALA_EXTERN guint test_register_object (void* object, + GDBusConnection* connection, + const gchar* path, + GError** error); +VALA_EXTERN GType test_get_type (void) G_GNUC_CONST ; +VALA_EXTERN void test_test_struct (Test* self, + FooStruct* f, + FooStruct* g, + FooStruct* result, + GError** error); +VALA_EXTERN void test_get_test_property (Test* self, + FooStruct * result); +VALA_EXTERN void test_set_test_property (Test* self, + FooStruct * value); +static GType test_get_type_once (void); +static void test_proxy_g_signal (GDBusProxy* proxy, + const gchar* sender_name, + const gchar* signal_name, + GVariant* parameters); +static void test_proxy_test_struct (Test* self, + FooStruct* f, + FooStruct* g, + FooStruct* result, + GError** error); +static void test_dbus_proxy_get_test_property (Test* self, + FooStruct* result); +static void test_dbus_proxy_set_test_property (Test* self, + FooStruct* value); +static void test_proxy_test_interface_init (TestIface* iface); +static void _dbus_test_test_struct (Test* self, + GVariant* _parameters_, + GDBusMethodInvocation* invocation); +static void test_dbus_interface_method_call (GDBusConnection* connection, + const gchar* sender, + const gchar* object_path, + const gchar* interface_name, + const gchar* method_name, + GVariant* parameters, + GDBusMethodInvocation* invocation, + gpointer user_data); +static GVariant* test_dbus_interface_get_property (GDBusConnection* connection, + const gchar* sender, + const gchar* object_path, + const gchar* interface_name, + const gchar* property_name, + GError** error, + gpointer user_data); +static GVariant* _dbus_test_get_test_property (Test* self); +static gboolean test_dbus_interface_set_property (GDBusConnection* connection, + const gchar* sender, + const gchar* object_path, + const gchar* interface_name, + const gchar* property_name, + GVariant* value, + GError** error, + gpointer user_data); +static void _dbus_test_set_test_property (Test* self, + GVariant* _value); +static void _test_unregister_object (gpointer user_data); +static void _vala_main (void); + +static const GDBusArgInfo _test_dbus_arg_info_test_struct_f = {-1, "f", "(is)", NULL}; +static const GDBusArgInfo _test_dbus_arg_info_test_struct_g = {-1, "g", "(is)", NULL}; +static const GDBusArgInfo _test_dbus_arg_info_test_struct_result = {-1, "result", "(is)", NULL}; +static const GDBusArgInfo * const _test_dbus_arg_info_test_struct_in[] = {&_test_dbus_arg_info_test_struct_f, NULL}; +static const GDBusArgInfo * const _test_dbus_arg_info_test_struct_out[] = {&_test_dbus_arg_info_test_struct_g, &_test_dbus_arg_info_test_struct_result, NULL}; +static const GDBusMethodInfo _test_dbus_method_info_test_struct = {-1, "TestStruct", (GDBusArgInfo **) (&_test_dbus_arg_info_test_struct_in), (GDBusArgInfo **) (&_test_dbus_arg_info_test_struct_out), NULL}; +static const GDBusMethodInfo * const _test_dbus_method_info[] = {&_test_dbus_method_info_test_struct, NULL}; +static const GDBusSignalInfo * const _test_dbus_signal_info[] = {NULL}; +static const GDBusPropertyInfo _test_dbus_property_info_test_property = {-1, "TestProperty", "(is)", G_DBUS_PROPERTY_INFO_FLAGS_READABLE | G_DBUS_PROPERTY_INFO_FLAGS_WRITABLE, NULL}; +static const GDBusPropertyInfo * const _test_dbus_property_info[] = {&_test_dbus_property_info_test_property, NULL}; +static const GDBusInterfaceInfo _test_dbus_interface_info = {-1, "org.example.Test", (GDBusMethodInfo **) (&_test_dbus_method_info), (GDBusSignalInfo **) (&_test_dbus_signal_info), (GDBusPropertyInfo **) (&_test_dbus_property_info), NULL}; +static const GDBusInterfaceVTable _test_dbus_interface_vtable = {test_dbus_interface_method_call, test_dbus_interface_get_property, test_dbus_interface_set_property}; + +void +foo_struct_init (FooStruct *self, + gint i, + const gchar* s) +{ + gchar* _tmp0_; + g_return_if_fail (s != NULL); + memset (self, 0, sizeof (FooStruct)); + (*self).i = i; + _tmp0_ = g_strdup (s); + _g_free0 ((*self).s); + (*self).s = _tmp0_; +} + +void +foo_struct_copy (const FooStruct* self, + FooStruct* dest) +{ + const gchar* _tmp0_; + gchar* _tmp1_; + (*dest).i = (*self).i; + _tmp0_ = (*self).s; + _tmp1_ = g_strdup (_tmp0_); + _g_free0 ((*dest).s); + (*dest).s = _tmp1_; +} + +void +foo_struct_destroy (FooStruct* self) +{ + _g_free0 ((*self).s); +} + +FooStruct* +foo_struct_dup (const FooStruct* self) +{ + FooStruct* dup; + dup = g_new0 (FooStruct, 1); + foo_struct_copy (self, dup); + return dup; +} + +void +foo_struct_free (FooStruct* self) +{ + foo_struct_destroy (self); + g_free (self); +} + +static GType +foo_struct_get_type_once (void) +{ + GType foo_struct_type_id; + foo_struct_type_id = g_boxed_type_register_static ("FooStruct", (GBoxedCopyFunc) foo_struct_dup, (GBoxedFreeFunc) foo_struct_free); + return foo_struct_type_id; +} + +GType +foo_struct_get_type (void) +{ + static volatile gsize foo_struct_type_id__volatile = 0; + if (g_once_init_enter (&foo_struct_type_id__volatile)) { + GType foo_struct_type_id; + foo_struct_type_id = foo_struct_get_type_once (); + g_once_init_leave (&foo_struct_type_id__volatile, foo_struct_type_id); + } + return foo_struct_type_id__volatile; +} + +void +test_test_struct (Test* self, + FooStruct* f, + FooStruct* g, + FooStruct* result, + GError** error) +{ + TestIface* _iface_; + g_return_if_fail (IS_TEST (self)); + _iface_ = TEST_GET_INTERFACE (self); + if (_iface_->test_struct) { + _iface_->test_struct (self, f, g, result, error); + } +} + +void +test_get_test_property (Test* self, + FooStruct * result) +{ + TestIface* _iface_; + g_return_if_fail (IS_TEST (self)); + _iface_ = TEST_GET_INTERFACE (self); + if (_iface_->get_test_property) { + _iface_->get_test_property (self, result); + } + return; +} + +void +test_set_test_property (Test* self, + FooStruct * value) +{ + TestIface* _iface_; + g_return_if_fail (IS_TEST (self)); + _iface_ = TEST_GET_INTERFACE (self); + if (_iface_->set_test_property) { + _iface_->set_test_property (self, value); + } +} + +static void +test_default_init (TestIface * iface, + gpointer iface_data) +{ +} + +static GType +test_get_type_once (void) +{ + static const GTypeInfo g_define_type_info = { sizeof (TestIface), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) test_default_init, (GClassFinalizeFunc) NULL, NULL, 0, 0, (GInstanceInitFunc) NULL, NULL }; + GType test_type_id; + test_type_id = g_type_register_static (G_TYPE_INTERFACE, "Test", &g_define_type_info, 0); + g_type_interface_add_prerequisite (test_type_id, G_TYPE_OBJECT); + g_type_set_qdata (test_type_id, g_quark_from_static_string ("vala-dbus-proxy-type"), (void*) test_proxy_get_type); + g_type_set_qdata (test_type_id, g_quark_from_static_string ("vala-dbus-interface-name"), "org.example.Test"); + g_type_set_qdata (test_type_id, g_quark_from_static_string ("vala-dbus-interface-info"), (void*) (&_test_dbus_interface_info)); + g_type_set_qdata (test_type_id, g_quark_from_static_string ("vala-dbus-register-object"), (void*) test_register_object); + return test_type_id; +} + +GType +test_get_type (void) +{ + static volatile gsize test_type_id__volatile = 0; + if (g_once_init_enter (&test_type_id__volatile)) { + GType test_type_id; + test_type_id = test_get_type_once (); + g_once_init_leave (&test_type_id__volatile, test_type_id); + } + return test_type_id__volatile; +} + +G_DEFINE_TYPE_EXTENDED (TestProxy, test_proxy, G_TYPE_DBUS_PROXY, 0, G_IMPLEMENT_INTERFACE (TYPE_TEST, test_proxy_test_interface_init) ) +static void +test_proxy_class_init (TestProxyClass* klass) +{ + G_DBUS_PROXY_CLASS (klass)->g_signal = test_proxy_g_signal; +} + +static void +test_proxy_g_signal (GDBusProxy* proxy, + const gchar* sender_name, + const gchar* signal_name, + GVariant* parameters) +{ +} + +static void +test_proxy_init (TestProxy* self) +{ + g_dbus_proxy_set_interface_info (G_DBUS_PROXY (self), (GDBusInterfaceInfo *) (&_test_dbus_interface_info)); +} + +static void +test_proxy_test_struct (Test* self, + FooStruct* f, + FooStruct* g, + FooStruct* result, + GError** error) +{ + GDBusMessage *_message; + GVariant *_arguments; + GVariantBuilder _arguments_builder; + GVariantBuilder _tmp0_; + GDBusMessage *_reply_message; + GVariant *_reply; + GVariantIter _reply_iter; + FooStruct _vala_g = {0}; + GVariant* _tmp1_; + FooStruct _tmp2_; + GVariantIter _tmp3_; + GVariant* _tmp4_; + GVariant* _tmp5_; + GVariant* _tmp6_; + FooStruct _tmp7_; + GVariantIter _tmp8_; + GVariant* _tmp9_; + GVariant* _tmp10_; + G_IO_ERROR; + _message = g_dbus_message_new_method_call (g_dbus_proxy_get_name ((GDBusProxy *) self), g_dbus_proxy_get_object_path ((GDBusProxy *) self), "org.example.Test", "TestStruct"); + g_variant_builder_init (&_arguments_builder, G_VARIANT_TYPE_TUPLE); + g_variant_builder_init (&_tmp0_, G_VARIANT_TYPE_TUPLE); + g_variant_builder_add_value (&_tmp0_, g_variant_new_int32 ((*f).i)); + g_variant_builder_add_value (&_tmp0_, g_variant_new_string ((*f).s)); + g_variant_builder_add_value (&_arguments_builder, g_variant_builder_end (&_tmp0_)); + _arguments = g_variant_builder_end (&_arguments_builder); + g_dbus_message_set_body (_message, _arguments); + _reply_message = g_dbus_connection_send_message_with_reply_sync (g_dbus_proxy_get_connection ((GDBusProxy *) self), _message, G_DBUS_SEND_MESSAGE_FLAGS_NONE, g_dbus_proxy_get_default_timeout ((GDBusProxy *) self), NULL, NULL, error); + g_object_unref (_message); + if (!_reply_message) { + return; + } + if (g_dbus_message_to_gerror (_reply_message, error)) { + g_object_unref (_reply_message); + return; + } + _reply = g_dbus_message_get_body (_reply_message); + g_variant_iter_init (&_reply_iter, _reply); + _tmp1_ = g_variant_iter_next_value (&_reply_iter); + g_variant_iter_init (&_tmp3_, _tmp1_); + _tmp4_ = g_variant_iter_next_value (&_tmp3_); + _tmp2_.i = g_variant_get_int32 (_tmp4_); + g_variant_unref (_tmp4_); + _tmp5_ = g_variant_iter_next_value (&_tmp3_); + _tmp2_.s = g_variant_dup_string (_tmp5_, NULL); + g_variant_unref (_tmp5_); + _vala_g = _tmp2_; + g_variant_unref (_tmp1_); + *g = _vala_g; + _tmp6_ = g_variant_iter_next_value (&_reply_iter); + g_variant_iter_init (&_tmp8_, _tmp6_); + _tmp9_ = g_variant_iter_next_value (&_tmp8_); + _tmp7_.i = g_variant_get_int32 (_tmp9_); + g_variant_unref (_tmp9_); + _tmp10_ = g_variant_iter_next_value (&_tmp8_); + _tmp7_.s = g_variant_dup_string (_tmp10_, NULL); + g_variant_unref (_tmp10_); + *result = _tmp7_; + g_variant_unref (_tmp6_); + g_object_unref (_reply_message); +} + +static void +test_dbus_proxy_get_test_property (Test* self, + FooStruct* result) +{ + GVariant *_inner_reply; + FooStruct _tmp11_; + GVariantIter _tmp12_; + GVariant* _tmp13_; + GVariant* _tmp14_; + _inner_reply = g_dbus_proxy_get_cached_property ((GDBusProxy *) self, "TestProperty"); + if (!_inner_reply) { + GVariant *_arguments; + GVariant *_reply; + GVariantBuilder _arguments_builder; + g_variant_builder_init (&_arguments_builder, G_VARIANT_TYPE_TUPLE); + g_variant_builder_add_value (&_arguments_builder, g_variant_new_string ("org.example.Test")); + g_variant_builder_add_value (&_arguments_builder, g_variant_new_string ("TestProperty")); + _arguments = g_variant_builder_end (&_arguments_builder); + _reply = g_dbus_proxy_call_sync ((GDBusProxy *) self, "org.freedesktop.DBus.Properties.Get", _arguments, G_DBUS_CALL_FLAGS_NONE, -1, NULL, NULL); + if (!_reply) { + return; + } + g_variant_get (_reply, "(v)", &_inner_reply); + g_variant_unref (_reply); + } + g_variant_iter_init (&_tmp12_, _inner_reply); + _tmp13_ = g_variant_iter_next_value (&_tmp12_); + _tmp11_.i = g_variant_get_int32 (_tmp13_); + g_variant_unref (_tmp13_); + _tmp14_ = g_variant_iter_next_value (&_tmp12_); + _tmp11_.s = g_variant_dup_string (_tmp14_, NULL); + g_variant_unref (_tmp14_); + *result = _tmp11_; + g_variant_unref (_inner_reply); + return; +} + +static void +test_dbus_proxy_set_test_property (Test* self, + FooStruct* value) +{ + GVariant *_arguments; + GVariant *_reply; + GVariantBuilder _arguments_builder; + GVariantBuilder _tmp15_; + g_variant_builder_init (&_arguments_builder, G_VARIANT_TYPE_TUPLE); + g_variant_builder_add_value (&_arguments_builder, g_variant_new_string ("org.example.Test")); + g_variant_builder_add_value (&_arguments_builder, g_variant_new_string ("TestProperty")); + g_variant_builder_open (&_arguments_builder, G_VARIANT_TYPE_VARIANT); + g_variant_builder_init (&_tmp15_, G_VARIANT_TYPE_TUPLE); + g_variant_builder_add_value (&_tmp15_, g_variant_new_int32 ((*value).i)); + g_variant_builder_add_value (&_tmp15_, g_variant_new_string ((*value).s)); + g_variant_builder_add_value (&_arguments_builder, g_variant_builder_end (&_tmp15_)); + g_variant_builder_close (&_arguments_builder); + _arguments = g_variant_builder_end (&_arguments_builder); + _reply = g_dbus_proxy_call_sync ((GDBusProxy *) self, "org.freedesktop.DBus.Properties.Set", _arguments, G_DBUS_CALL_FLAGS_NONE, -1, NULL, NULL); + if (!_reply) { + return; + } + g_variant_unref (_reply); +} + +static void +test_proxy_test_interface_init (TestIface* iface) +{ + iface->test_struct = test_proxy_test_struct; + iface->get_test_property = test_dbus_proxy_get_test_property; + iface->set_test_property = test_dbus_proxy_set_test_property; +} + +static void +_dbus_test_test_struct (Test* self, + GVariant* _parameters_, + GDBusMethodInvocation* invocation) +{ + GError* error = NULL; + GVariantIter _arguments_iter; + FooStruct f = {0}; + GVariant* _tmp16_; + FooStruct _tmp17_; + GVariantIter _tmp18_; + GVariant* _tmp19_; + GVariant* _tmp20_; + GDBusMessage* _reply_message = NULL; + GVariant* _reply; + GVariantBuilder _reply_builder; + FooStruct g = {0}; + GVariantBuilder _tmp21_; + FooStruct result = {0}; + GVariantBuilder _tmp22_; + g_variant_iter_init (&_arguments_iter, _parameters_); + _tmp16_ = g_variant_iter_next_value (&_arguments_iter); + g_variant_iter_init (&_tmp18_, _tmp16_); + _tmp19_ = g_variant_iter_next_value (&_tmp18_); + _tmp17_.i = g_variant_get_int32 (_tmp19_); + g_variant_unref (_tmp19_); + _tmp20_ = g_variant_iter_next_value (&_tmp18_); + _tmp17_.s = g_variant_dup_string (_tmp20_, NULL); + g_variant_unref (_tmp20_); + f = _tmp17_; + g_variant_unref (_tmp16_); + test_test_struct (self, &f, &g, &result, &error); + if (error) { + g_dbus_method_invocation_return_gerror (invocation, error); + g_error_free (error); + goto _error; + } + _reply_message = g_dbus_message_new_method_reply (g_dbus_method_invocation_get_message (invocation)); + g_variant_builder_init (&_reply_builder, G_VARIANT_TYPE_TUPLE); + g_variant_builder_init (&_tmp21_, G_VARIANT_TYPE_TUPLE); + g_variant_builder_add_value (&_tmp21_, g_variant_new_int32 (g.i)); + g_variant_builder_add_value (&_tmp21_, g_variant_new_string (g.s)); + g_variant_builder_add_value (&_reply_builder, g_variant_builder_end (&_tmp21_)); + g_variant_builder_init (&_tmp22_, G_VARIANT_TYPE_TUPLE); + g_variant_builder_add_value (&_tmp22_, g_variant_new_int32 (result.i)); + g_variant_builder_add_value (&_tmp22_, g_variant_new_string (result.s)); + g_variant_builder_add_value (&_reply_builder, g_variant_builder_end (&_tmp22_)); + foo_struct_destroy (&result); + _reply = g_variant_builder_end (&_reply_builder); + g_dbus_message_set_body (_reply_message, _reply); + g_dbus_connection_send_message (g_dbus_method_invocation_get_connection (invocation), _reply_message, G_DBUS_SEND_MESSAGE_FLAGS_NONE, NULL, NULL); + g_object_unref (invocation); + g_object_unref (_reply_message); + _error: + foo_struct_destroy (&f); + foo_struct_destroy (&g); + ; +} + +static void +test_dbus_interface_method_call (GDBusConnection* connection, + const gchar* sender, + const gchar* object_path, + const gchar* interface_name, + const gchar* method_name, + GVariant* parameters, + GDBusMethodInvocation* invocation, + gpointer user_data) +{ + gpointer* data; + gpointer object; + data = user_data; + object = data[0]; + if (strcmp (method_name, "TestStruct") == 0) { + _dbus_test_test_struct (object, parameters, invocation); + } else { + g_object_unref (invocation); + } +} + +static GVariant* +_dbus_test_get_test_property (Test* self) +{ + FooStruct result = {0}; + GVariant* _reply; + GVariantBuilder _tmp23_; + test_get_test_property (self, &result); + g_variant_builder_init (&_tmp23_, G_VARIANT_TYPE_TUPLE); + g_variant_builder_add_value (&_tmp23_, g_variant_new_int32 (result.i)); + g_variant_builder_add_value (&_tmp23_, g_variant_new_string (result.s)); + _reply = g_variant_builder_end (&_tmp23_); + foo_struct_destroy (&result); + return _reply; +} + +static GVariant* +test_dbus_interface_get_property (GDBusConnection* connection, + const gchar* sender, + const gchar* object_path, + const gchar* interface_name, + const gchar* property_name, + GError** error, + gpointer user_data) +{ + gpointer* data; + gpointer object; + data = user_data; + object = data[0]; + if (strcmp (property_name, "TestProperty") == 0) { + return _dbus_test_get_test_property (object); + } + return NULL; +} + +static void +_dbus_test_set_test_property (Test* self, + GVariant* _value) +{ + FooStruct value = {0}; + FooStruct _tmp24_; + GVariantIter _tmp25_; + GVariant* _tmp26_; + GVariant* _tmp27_; + g_variant_iter_init (&_tmp25_, _value); + _tmp26_ = g_variant_iter_next_value (&_tmp25_); + _tmp24_.i = g_variant_get_int32 (_tmp26_); + g_variant_unref (_tmp26_); + _tmp27_ = g_variant_iter_next_value (&_tmp25_); + _tmp24_.s = g_variant_dup_string (_tmp27_, NULL); + g_variant_unref (_tmp27_); + value = _tmp24_; + test_set_test_property (self, &value); + foo_struct_destroy (&value); +} + +static gboolean +test_dbus_interface_set_property (GDBusConnection* connection, + const gchar* sender, + const gchar* object_path, + const gchar* interface_name, + const gchar* property_name, + GVariant* value, + GError** error, + gpointer user_data) +{ + gpointer* data; + gpointer object; + data = user_data; + object = data[0]; + if (strcmp (property_name, "TestProperty") == 0) { + _dbus_test_set_test_property (object, value); + return TRUE; + } + return FALSE; +} + +guint +test_register_object (gpointer object, + GDBusConnection* connection, + const gchar* path, + GError** error) +{ + guint result; + gpointer *data; + data = g_new (gpointer, 3); + data[0] = g_object_ref (object); + data[1] = g_object_ref (connection); + data[2] = g_strdup (path); + result = g_dbus_connection_register_object (connection, path, (GDBusInterfaceInfo *) (&_test_dbus_interface_info), &_test_dbus_interface_vtable, data, _test_unregister_object, error); + if (!result) { + return 0; + } + return result; +} + +static void +_test_unregister_object (gpointer user_data) +{ + gpointer* data; + data = user_data; + g_object_unref (data[0]); + g_object_unref (data[1]); + g_free (data[2]); + g_free (data); +} + +static void +_vala_main (void) +{ + Test* test = NULL; + Test* _tmp0_; + FooStruct f = {0}; + FooStruct g = {0}; + FooStruct h = {0}; + FooStruct _tmp1_ = {0}; + Test* _tmp2_; + FooStruct _tmp3_; + FooStruct _tmp4_ = {0}; + FooStruct _tmp5_ = {0}; + FooStruct _tmp6_; + FooStruct _tmp7_; + FooStruct _tmp8_; + const gchar* _tmp9_; + FooStruct _tmp10_; + FooStruct _tmp11_; + const gchar* _tmp12_; + Test* _tmp13_; + FooStruct _tmp14_; + Test* _tmp15_; + FooStruct _tmp16_ = {0}; + FooStruct _tmp17_; + FooStruct _tmp18_; + FooStruct _tmp19_; + const gchar* _tmp20_; + GError* _inner_error0_ = NULL; + _tmp0_ = (Test*) g_initable_new (TYPE_TEST_PROXY, NULL, &_inner_error0_, "g-flags", G_DBUS_PROXY_FLAGS_DO_NOT_LOAD_PROPERTIES, "g-name", "org.example.Test", "g-bus-type", G_BUS_TYPE_SESSION, "g-object-path", "/org/example/test", "g-interface-name", "org.example.Test", NULL); + test = (Test*) _tmp0_; + if (G_UNLIKELY (_inner_error0_ != NULL)) { + g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error0_->message, g_quark_to_string (_inner_error0_->domain), _inner_error0_->code); + g_clear_error (&_inner_error0_); + return; + } + foo_struct_destroy (&f); + foo_struct_init (&f, 42, "hello"); + _tmp2_ = test; + _tmp3_ = f; + test_test_struct (_tmp2_, &_tmp3_, &_tmp4_, &_tmp5_, &_inner_error0_); + foo_struct_destroy (&g); + g = _tmp4_; + _tmp1_ = _tmp5_; + if (G_UNLIKELY (_inner_error0_ != NULL)) { + foo_struct_destroy (&h); + foo_struct_destroy (&g); + foo_struct_destroy (&f); + _g_object_unref0 (test); + g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error0_->message, g_quark_to_string (_inner_error0_->domain), _inner_error0_->code); + g_clear_error (&_inner_error0_); + return; + } + _tmp6_ = _tmp1_; + memset (&_tmp1_, 0, sizeof (FooStruct)); + foo_struct_destroy (&h); + h = _tmp6_; + _tmp7_ = g; + _vala_assert (_tmp7_.i == 23, "g.i == 23"); + _tmp8_ = g; + _tmp9_ = _tmp8_.s; + _vala_assert (g_strcmp0 (_tmp9_, "world") == 0, "g.s == \"world\""); + _tmp10_ = h; + _vala_assert (_tmp10_.i == 11, "h.i == 11"); + _tmp11_ = h; + _tmp12_ = _tmp11_.s; + _vala_assert (g_strcmp0 (_tmp12_, "vala") == 0, "h.s == \"vala\""); + _tmp13_ = test; + _tmp14_ = f; + test_set_test_property (_tmp13_, &_tmp14_); + _tmp15_ = test; + test_get_test_property (_tmp15_, &_tmp16_); + _tmp17_ = _tmp16_; + foo_struct_destroy (&g); + g = _tmp17_; + _tmp18_ = g; + _vala_assert (_tmp18_.i == 42, "g.i == 42"); + _tmp19_ = g; + _tmp20_ = _tmp19_.s; + _vala_assert (g_strcmp0 (_tmp20_, "hello") == 0, "g.s == \"hello\""); + foo_struct_destroy (&_tmp1_); + foo_struct_destroy (&h); + foo_struct_destroy (&g); + foo_struct_destroy (&f); + _g_object_unref0 (test); +} + +int +main (int argc, + char ** argv) +{ + _vala_main (); + return 0; +} + diff --git a/tests/dbus/structs_server.c-expected b/tests/dbus/structs_server.c-expected new file mode 100644 index 000000000..0840275f1 --- /dev/null +++ b/tests/dbus/structs_server.c-expected @@ -0,0 +1,758 @@ +/* dbus_structs_server.c generated by valac, the Vala compiler + * generated from dbus_structs_server.vala, do not modify */ + +#include <glib-object.h> +#include <glib.h> +#include <stdlib.h> +#include <string.h> +#include <gio/gio.h> + +#if !defined(VALA_EXTERN) +#if defined(_MSC_VER) +#define VALA_EXTERN __declspec(dllexport) extern +#elif __GNUC__ >= 4 +#define VALA_EXTERN __attribute__((visibility("default"))) extern +#else +#define VALA_EXTERN extern +#endif +#endif + +#define TYPE_FOO_STRUCT (foo_struct_get_type ()) +typedef struct _FooStruct FooStruct; +#define _g_free0(var) (var = (g_free (var), NULL)) + +#define TYPE_TEST (test_get_type ()) +#define TEST(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TYPE_TEST, Test)) +#define TEST_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), TYPE_TEST, TestClass)) +#define IS_TEST(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TYPE_TEST)) +#define IS_TEST_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), TYPE_TEST)) +#define TEST_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), TYPE_TEST, TestClass)) + +typedef struct _Test Test; +typedef struct _TestClass TestClass; +typedef struct _TestPrivate TestPrivate; +enum { + TEST_0_PROPERTY, + TEST_TEST_PROPERTY_PROPERTY, + TEST_NUM_PROPERTIES +}; +static GParamSpec* test_properties[TEST_NUM_PROPERTIES]; +#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL))) +#define _g_variant_unref0(var) ((var == NULL) ? NULL : (var = (g_variant_unref (var), NULL))) +#define _g_main_loop_unref0(var) ((var == NULL) ? NULL : (var = (g_main_loop_unref (var), NULL))) +#define _vala_assert(expr, msg) if G_LIKELY (expr) ; else g_assertion_message_expr (G_LOG_DOMAIN, __FILE__, __LINE__, G_STRFUNC, msg); +#define _vala_return_if_fail(expr, msg) if G_LIKELY (expr) ; else { g_return_if_fail_warning (G_LOG_DOMAIN, G_STRFUNC, msg); return; } +#define _vala_return_val_if_fail(expr, msg, val) if G_LIKELY (expr) ; else { g_return_if_fail_warning (G_LOG_DOMAIN, G_STRFUNC, msg); return val; } +#define _vala_warn_if_fail(expr, msg) if G_LIKELY (expr) ; else g_warn_message (G_LOG_DOMAIN, __FILE__, __LINE__, G_STRFUNC, msg); + +struct _FooStruct { + gint i; + gchar* s; +}; + +struct _Test { + GObject parent_instance; + TestPrivate * priv; +}; + +struct _TestClass { + GObjectClass parent_class; +}; + +struct _TestPrivate { + FooStruct _test_property; +}; + +static gint Test_private_offset; +static gpointer test_parent_class = NULL; +VALA_EXTERN GMainLoop* main_loop; +GMainLoop* main_loop = NULL; + +VALA_EXTERN GType foo_struct_get_type (void) G_GNUC_CONST ; +VALA_EXTERN FooStruct* foo_struct_dup (const FooStruct* self); +VALA_EXTERN void foo_struct_free (FooStruct* self); +VALA_EXTERN void foo_struct_copy (const FooStruct* self, + FooStruct* dest); +VALA_EXTERN void foo_struct_destroy (FooStruct* self); +VALA_EXTERN void foo_struct_init (FooStruct *self, + gint i, + const gchar* s); +VALA_EXTERN GType test_get_type (void) G_GNUC_CONST ; +G_DEFINE_AUTOPTR_CLEANUP_FUNC (Test, g_object_unref) +VALA_EXTERN guint test_register_object (void* object, + GDBusConnection* connection, + const gchar* path, + GError** error); +VALA_EXTERN void test_test_struct (Test* self, + FooStruct* f, + FooStruct* g, + FooStruct* result); +VALA_EXTERN Test* test_new (void); +VALA_EXTERN Test* test_construct (GType object_type); +VALA_EXTERN void test_get_test_property (Test* self, + FooStruct * result); +VALA_EXTERN void test_set_test_property (Test* self, + FooStruct * value); +static gboolean _foo_struct_equal (const FooStruct * s1, + const FooStruct * s2); +static void test_finalize (GObject * obj); +static GType test_get_type_once (void); +static void _vala_test_get_property (GObject * object, + guint property_id, + GValue * value, + GParamSpec * pspec); +static void _vala_test_set_property (GObject * object, + guint property_id, + const GValue * value, + GParamSpec * pspec); +static void _dbus_test_test_struct (Test* self, + GVariant* _parameters_, + GDBusMethodInvocation* invocation); +static void test_dbus_interface_method_call (GDBusConnection* connection, + const gchar* sender, + const gchar* object_path, + const gchar* interface_name, + const gchar* method_name, + GVariant* parameters, + GDBusMethodInvocation* invocation, + gpointer user_data); +static GVariant* test_dbus_interface_get_property (GDBusConnection* connection, + const gchar* sender, + const gchar* object_path, + const gchar* interface_name, + const gchar* property_name, + GError** error, + gpointer user_data); +static GVariant* _dbus_test_get_test_property (Test* self); +static gboolean test_dbus_interface_set_property (GDBusConnection* connection, + const gchar* sender, + const gchar* object_path, + const gchar* interface_name, + const gchar* property_name, + GVariant* value, + GError** error, + gpointer user_data); +static void _dbus_test_set_test_property (Test* self, + GVariant* _value); +static void _test_unregister_object (gpointer user_data); +VALA_EXTERN void client_exit (GPid pid, + gint status); +static void _vala_main (void); +static guint _variant_get1 (GVariant* value); +static void _client_exit_gchild_watch_func (GPid pid, + gint wait_status, + gpointer self); +static void _vala_array_destroy (gpointer array, + gssize array_length, + GDestroyNotify destroy_func); +static void _vala_array_free (gpointer array, + gssize array_length, + GDestroyNotify destroy_func); + +static const GDBusArgInfo _test_dbus_arg_info_test_struct_f = {-1, "f", "(is)", NULL}; +static const GDBusArgInfo _test_dbus_arg_info_test_struct_g = {-1, "g", "(is)", NULL}; +static const GDBusArgInfo _test_dbus_arg_info_test_struct_result = {-1, "result", "(is)", NULL}; +static const GDBusArgInfo * const _test_dbus_arg_info_test_struct_in[] = {&_test_dbus_arg_info_test_struct_f, NULL}; +static const GDBusArgInfo * const _test_dbus_arg_info_test_struct_out[] = {&_test_dbus_arg_info_test_struct_g, &_test_dbus_arg_info_test_struct_result, NULL}; +static const GDBusMethodInfo _test_dbus_method_info_test_struct = {-1, "TestStruct", (GDBusArgInfo **) (&_test_dbus_arg_info_test_struct_in), (GDBusArgInfo **) (&_test_dbus_arg_info_test_struct_out), NULL}; +static const GDBusMethodInfo * const _test_dbus_method_info[] = {&_test_dbus_method_info_test_struct, NULL}; +static const GDBusSignalInfo * const _test_dbus_signal_info[] = {NULL}; +static const GDBusPropertyInfo _test_dbus_property_info_test_property = {-1, "TestProperty", "(is)", G_DBUS_PROPERTY_INFO_FLAGS_READABLE | G_DBUS_PROPERTY_INFO_FLAGS_WRITABLE, NULL}; +static const GDBusPropertyInfo * const _test_dbus_property_info[] = {&_test_dbus_property_info_test_property, NULL}; +static const GDBusInterfaceInfo _test_dbus_interface_info = {-1, "org.example.Test", (GDBusMethodInfo **) (&_test_dbus_method_info), (GDBusSignalInfo **) (&_test_dbus_signal_info), (GDBusPropertyInfo **) (&_test_dbus_property_info), NULL}; +static const GDBusInterfaceVTable _test_dbus_interface_vtable = {test_dbus_interface_method_call, test_dbus_interface_get_property, test_dbus_interface_set_property}; + +void +foo_struct_init (FooStruct *self, + gint i, + const gchar* s) +{ + gchar* _tmp0_; + g_return_if_fail (s != NULL); + memset (self, 0, sizeof (FooStruct)); + (*self).i = i; + _tmp0_ = g_strdup (s); + _g_free0 ((*self).s); + (*self).s = _tmp0_; +} + +void +foo_struct_copy (const FooStruct* self, + FooStruct* dest) +{ + const gchar* _tmp0_; + gchar* _tmp1_; + (*dest).i = (*self).i; + _tmp0_ = (*self).s; + _tmp1_ = g_strdup (_tmp0_); + _g_free0 ((*dest).s); + (*dest).s = _tmp1_; +} + +void +foo_struct_destroy (FooStruct* self) +{ + _g_free0 ((*self).s); +} + +FooStruct* +foo_struct_dup (const FooStruct* self) +{ + FooStruct* dup; + dup = g_new0 (FooStruct, 1); + foo_struct_copy (self, dup); + return dup; +} + +void +foo_struct_free (FooStruct* self) +{ + foo_struct_destroy (self); + g_free (self); +} + +static GType +foo_struct_get_type_once (void) +{ + GType foo_struct_type_id; + foo_struct_type_id = g_boxed_type_register_static ("FooStruct", (GBoxedCopyFunc) foo_struct_dup, (GBoxedFreeFunc) foo_struct_free); + return foo_struct_type_id; +} + +GType +foo_struct_get_type (void) +{ + static volatile gsize foo_struct_type_id__volatile = 0; + if (g_once_init_enter (&foo_struct_type_id__volatile)) { + GType foo_struct_type_id; + foo_struct_type_id = foo_struct_get_type_once (); + g_once_init_leave (&foo_struct_type_id__volatile, foo_struct_type_id); + } + return foo_struct_type_id__volatile; +} + +static inline gpointer +test_get_instance_private (Test* self) +{ + return G_STRUCT_MEMBER_P (self, Test_private_offset); +} + +void +test_test_struct (Test* self, + FooStruct* f, + FooStruct* g, + FooStruct* result) +{ + FooStruct _vala_g = {0}; + FooStruct _tmp0_; + FooStruct _tmp1_; + const gchar* _tmp2_; + FooStruct _tmp3_ = {0}; + g_return_if_fail (IS_TEST (self)); + g_return_if_fail (f != NULL); + _tmp0_ = *f; + _vala_assert (_tmp0_.i == 42, "f.i == 42"); + _tmp1_ = *f; + _tmp2_ = _tmp1_.s; + _vala_assert (g_strcmp0 (_tmp2_, "hello") == 0, "f.s == \"hello\""); + foo_struct_destroy (&_vala_g); + foo_struct_init (&_vala_g, 23, "world"); + foo_struct_init (&_tmp3_, 11, "vala"); + *result = _tmp3_; + if (g) { + *g = _vala_g; + } else { + foo_struct_destroy (&_vala_g); + } + return; +} + +Test* +test_construct (GType object_type) +{ + Test * self = NULL; + self = (Test*) g_object_new (object_type, NULL); + return self; +} + +Test* +test_new (void) +{ + return test_construct (TYPE_TEST); +} + +void +test_get_test_property (Test* self, + FooStruct * result) +{ + FooStruct _tmp0_; + FooStruct _tmp1_; + FooStruct _tmp2_ = {0}; + g_return_if_fail (IS_TEST (self)); + _tmp0_ = self->priv->_test_property; + _tmp1_ = _tmp0_; + foo_struct_copy (&_tmp1_, &_tmp2_); + *result = _tmp2_; + return; +} + +static gboolean +_foo_struct_equal (const FooStruct * s1, + const FooStruct * s2) +{ + if (s1 == s2) { + return TRUE; + } + if (s1 == NULL) { + return FALSE; + } + if (s2 == NULL) { + return FALSE; + } + if (s1->i != s2->i) { + return FALSE; + } + if (g_strcmp0 (s1->s, s2->s)) { + return FALSE; + } + return TRUE; +} + +void +test_set_test_property (Test* self, + FooStruct * value) +{ + FooStruct old_value; + g_return_if_fail (IS_TEST (self)); + test_get_test_property (self, &old_value); + if (_foo_struct_equal (value, &old_value) != TRUE) { + FooStruct _tmp0_; + FooStruct _tmp1_; + FooStruct _tmp2_ = {0}; + _tmp0_ = *value; + _tmp1_ = _tmp0_; + foo_struct_copy (&_tmp1_, &_tmp2_); + foo_struct_destroy (&self->priv->_test_property); + self->priv->_test_property = _tmp2_; + g_object_notify_by_pspec ((GObject *) self, test_properties[TEST_TEST_PROPERTY_PROPERTY]); + } + foo_struct_destroy (&old_value); +} + +static void +test_class_init (TestClass * klass, + gpointer klass_data) +{ + test_parent_class = g_type_class_peek_parent (klass); + g_type_class_adjust_private_offset (klass, &Test_private_offset); + G_OBJECT_CLASS (klass)->get_property = _vala_test_get_property; + G_OBJECT_CLASS (klass)->set_property = _vala_test_set_property; + G_OBJECT_CLASS (klass)->finalize = test_finalize; + g_object_class_install_property (G_OBJECT_CLASS (klass), TEST_TEST_PROPERTY_PROPERTY, test_properties[TEST_TEST_PROPERTY_PROPERTY] = g_param_spec_boxed ("test-property", "test-property", "test-property", TYPE_FOO_STRUCT, G_PARAM_STATIC_STRINGS | G_PARAM_READABLE | G_PARAM_WRITABLE)); +} + +static void +test_instance_init (Test * self, + gpointer klass) +{ + self->priv = test_get_instance_private (self); +} + +static void +test_finalize (GObject * obj) +{ + Test * self; + self = G_TYPE_CHECK_INSTANCE_CAST (obj, TYPE_TEST, Test); + foo_struct_destroy (&self->priv->_test_property); + G_OBJECT_CLASS (test_parent_class)->finalize (obj); +} + +static GType +test_get_type_once (void) +{ + static const GTypeInfo g_define_type_info = { sizeof (TestClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) test_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (Test), 0, (GInstanceInitFunc) test_instance_init, NULL }; + GType test_type_id; + test_type_id = g_type_register_static (G_TYPE_OBJECT, "Test", &g_define_type_info, 0); + g_type_set_qdata (test_type_id, g_quark_from_static_string ("vala-dbus-register-object"), (void*) test_register_object); + Test_private_offset = g_type_add_instance_private (test_type_id, sizeof (TestPrivate)); + return test_type_id; +} + +GType +test_get_type (void) +{ + static volatile gsize test_type_id__volatile = 0; + if (g_once_init_enter (&test_type_id__volatile)) { + GType test_type_id; + test_type_id = test_get_type_once (); + g_once_init_leave (&test_type_id__volatile, test_type_id); + } + return test_type_id__volatile; +} + +static void +_vala_test_get_property (GObject * object, + guint property_id, + GValue * value, + GParamSpec * pspec) +{ + Test * self; + self = G_TYPE_CHECK_INSTANCE_CAST (object, TYPE_TEST, Test); + switch (property_id) { + case TEST_TEST_PROPERTY_PROPERTY: + { + FooStruct boxed; + test_get_test_property (self, &boxed); + g_value_set_boxed (value, &boxed); + foo_struct_destroy (&boxed); + } + break; + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); + break; + } +} + +static void +_vala_test_set_property (GObject * object, + guint property_id, + const GValue * value, + GParamSpec * pspec) +{ + Test * self; + self = G_TYPE_CHECK_INSTANCE_CAST (object, TYPE_TEST, Test); + switch (property_id) { + case TEST_TEST_PROPERTY_PROPERTY: + test_set_test_property (self, g_value_get_boxed (value)); + break; + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); + break; + } +} + +static void +_dbus_test_test_struct (Test* self, + GVariant* _parameters_, + GDBusMethodInvocation* invocation) +{ + GError* error = NULL; + GVariantIter _arguments_iter; + FooStruct f = {0}; + GVariant* _tmp0_; + FooStruct _tmp1_; + GVariantIter _tmp2_; + GVariant* _tmp3_; + GVariant* _tmp4_; + GDBusMessage* _reply_message = NULL; + GVariant* _reply; + GVariantBuilder _reply_builder; + FooStruct g = {0}; + GVariantBuilder _tmp5_; + FooStruct result = {0}; + GVariantBuilder _tmp6_; + g_variant_iter_init (&_arguments_iter, _parameters_); + _tmp0_ = g_variant_iter_next_value (&_arguments_iter); + g_variant_iter_init (&_tmp2_, _tmp0_); + _tmp3_ = g_variant_iter_next_value (&_tmp2_); + _tmp1_.i = g_variant_get_int32 (_tmp3_); + g_variant_unref (_tmp3_); + _tmp4_ = g_variant_iter_next_value (&_tmp2_); + _tmp1_.s = g_variant_dup_string (_tmp4_, NULL); + g_variant_unref (_tmp4_); + f = _tmp1_; + g_variant_unref (_tmp0_); + test_test_struct (self, &f, &g, &result); + _reply_message = g_dbus_message_new_method_reply (g_dbus_method_invocation_get_message (invocation)); + g_variant_builder_init (&_reply_builder, G_VARIANT_TYPE_TUPLE); + g_variant_builder_init (&_tmp5_, G_VARIANT_TYPE_TUPLE); + g_variant_builder_add_value (&_tmp5_, g_variant_new_int32 (g.i)); + g_variant_builder_add_value (&_tmp5_, g_variant_new_string (g.s)); + g_variant_builder_add_value (&_reply_builder, g_variant_builder_end (&_tmp5_)); + g_variant_builder_init (&_tmp6_, G_VARIANT_TYPE_TUPLE); + g_variant_builder_add_value (&_tmp6_, g_variant_new_int32 (result.i)); + g_variant_builder_add_value (&_tmp6_, g_variant_new_string (result.s)); + g_variant_builder_add_value (&_reply_builder, g_variant_builder_end (&_tmp6_)); + foo_struct_destroy (&result); + _reply = g_variant_builder_end (&_reply_builder); + g_dbus_message_set_body (_reply_message, _reply); + g_dbus_connection_send_message (g_dbus_method_invocation_get_connection (invocation), _reply_message, G_DBUS_SEND_MESSAGE_FLAGS_NONE, NULL, NULL); + g_object_unref (invocation); + g_object_unref (_reply_message); + foo_struct_destroy (&f); + foo_struct_destroy (&g); +} + +static void +test_dbus_interface_method_call (GDBusConnection* connection, + const gchar* sender, + const gchar* object_path, + const gchar* interface_name, + const gchar* method_name, + GVariant* parameters, + GDBusMethodInvocation* invocation, + gpointer user_data) +{ + gpointer* data; + gpointer object; + data = user_data; + object = data[0]; + if (strcmp (method_name, "TestStruct") == 0) { + _dbus_test_test_struct (object, parameters, invocation); + } else { + g_object_unref (invocation); + } +} + +static GVariant* +_dbus_test_get_test_property (Test* self) +{ + FooStruct result = {0}; + GVariant* _reply; + GVariantBuilder _tmp7_; + test_get_test_property (self, &result); + g_variant_builder_init (&_tmp7_, G_VARIANT_TYPE_TUPLE); + g_variant_builder_add_value (&_tmp7_, g_variant_new_int32 (result.i)); + g_variant_builder_add_value (&_tmp7_, g_variant_new_string (result.s)); + _reply = g_variant_builder_end (&_tmp7_); + foo_struct_destroy (&result); + return _reply; +} + +static GVariant* +test_dbus_interface_get_property (GDBusConnection* connection, + const gchar* sender, + const gchar* object_path, + const gchar* interface_name, + const gchar* property_name, + GError** error, + gpointer user_data) +{ + gpointer* data; + gpointer object; + data = user_data; + object = data[0]; + if (strcmp (property_name, "TestProperty") == 0) { + return _dbus_test_get_test_property (object); + } + return NULL; +} + +static void +_dbus_test_set_test_property (Test* self, + GVariant* _value) +{ + FooStruct value = {0}; + FooStruct _tmp8_; + GVariantIter _tmp9_; + GVariant* _tmp10_; + GVariant* _tmp11_; + g_variant_iter_init (&_tmp9_, _value); + _tmp10_ = g_variant_iter_next_value (&_tmp9_); + _tmp8_.i = g_variant_get_int32 (_tmp10_); + g_variant_unref (_tmp10_); + _tmp11_ = g_variant_iter_next_value (&_tmp9_); + _tmp8_.s = g_variant_dup_string (_tmp11_, NULL); + g_variant_unref (_tmp11_); + value = _tmp8_; + test_set_test_property (self, &value); + foo_struct_destroy (&value); +} + +static gboolean +test_dbus_interface_set_property (GDBusConnection* connection, + const gchar* sender, + const gchar* object_path, + const gchar* interface_name, + const gchar* property_name, + GVariant* value, + GError** error, + gpointer user_data) +{ + gpointer* data; + gpointer object; + data = user_data; + object = data[0]; + if (strcmp (property_name, "TestProperty") == 0) { + _dbus_test_set_test_property (object, value); + return TRUE; + } + return FALSE; +} + +guint +test_register_object (gpointer object, + GDBusConnection* connection, + const gchar* path, + GError** error) +{ + guint result; + gpointer *data; + data = g_new (gpointer, 3); + data[0] = g_object_ref (object); + data[1] = g_object_ref (connection); + data[2] = g_strdup (path); + result = g_dbus_connection_register_object (connection, path, (GDBusInterfaceInfo *) (&_test_dbus_interface_info), &_test_dbus_interface_vtable, data, _test_unregister_object, error); + if (!result) { + return 0; + } + return result; +} + +static void +_test_unregister_object (gpointer user_data) +{ + gpointer* data; + data = user_data; + g_object_unref (data[0]); + g_object_unref (data[1]); + g_free (data[2]); + g_free (data); +} + +void +client_exit (GPid pid, + gint status) +{ + GMainLoop* _tmp0_; + _vala_assert (status == 0, "status == 0"); + _tmp0_ = main_loop; + g_main_loop_quit (_tmp0_); +} + +static guint +_variant_get1 (GVariant* value) +{ + return g_variant_get_uint32 (value); +} + +static void +_client_exit_gchild_watch_func (GPid pid, + gint wait_status, + gpointer self) +{ + client_exit (pid, wait_status); +} + +static void +_vala_main (void) +{ + GDBusConnection* conn = NULL; + GDBusConnection* _tmp0_; + GDBusConnection* _tmp1_; + Test* _tmp2_; + Test* _tmp3_; + GVariant* request_result = NULL; + GDBusConnection* _tmp4_; + GVariant* _tmp5_; + GVariant* _tmp6_; + GVariant* _tmp7_; + GVariant* _tmp8_; + GVariant* _tmp9_; + GVariant* _tmp10_; + GVariant* _tmp11_; + guint _tmp12_; + GPid client_pid = 0; + gchar* _tmp13_; + gchar** _tmp14_; + gchar** _tmp15_; + gint _tmp15__length1; + GPid _tmp16_ = 0; + GMainLoop* _tmp17_; + GMainLoop* _tmp18_; + GError* _inner_error0_ = NULL; + _tmp0_ = g_bus_get_sync (G_BUS_TYPE_SESSION, NULL, &_inner_error0_); + conn = _tmp0_; + if (G_UNLIKELY (_inner_error0_ != NULL)) { + g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error0_->message, g_quark_to_string (_inner_error0_->domain), _inner_error0_->code); + g_clear_error (&_inner_error0_); + return; + } + _tmp1_ = conn; + _tmp2_ = test_new (); + _tmp3_ = _tmp2_; + test_register_object (_tmp3_, _tmp1_, "/org/example/test", &_inner_error0_); + _g_object_unref0 (_tmp3_); + if (G_UNLIKELY (_inner_error0_ != NULL)) { + _g_object_unref0 (conn); + g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error0_->message, g_quark_to_string (_inner_error0_->domain), _inner_error0_->code); + g_clear_error (&_inner_error0_); + return; + } + _tmp4_ = conn; + _tmp5_ = g_variant_new ("(su)", "org.example.Test", 0x4, NULL); + g_variant_ref_sink (_tmp5_); + _tmp6_ = _tmp5_; + _tmp7_ = g_dbus_connection_call_sync (_tmp4_, "org.freedesktop.DBus", "/org/freedesktop/DBus", "org.freedesktop.DBus", "RequestName", _tmp6_, NULL, 0, -1, NULL, &_inner_error0_); + _tmp8_ = _tmp7_; + _g_variant_unref0 (_tmp6_); + request_result = _tmp8_; + if (G_UNLIKELY (_inner_error0_ != NULL)) { + _g_object_unref0 (conn); + g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error0_->message, g_quark_to_string (_inner_error0_->domain), _inner_error0_->code); + g_clear_error (&_inner_error0_); + return; + } + _tmp9_ = request_result; + _tmp10_ = g_variant_get_child_value (_tmp9_, (gsize) 0); + _tmp11_ = _tmp10_; + _tmp12_ = _variant_get1 (_tmp11_); + _vala_assert (_tmp12_ == ((guint) 1), "(uint) request_result.get_child_value (0) == 1"); + _g_variant_unref0 (_tmp11_); + _tmp13_ = g_strdup ("dbus_structs_client"); + _tmp14_ = g_new0 (gchar*, 1 + 1); + _tmp14_[0] = _tmp13_; + _tmp15_ = _tmp14_; + _tmp15__length1 = 1; + g_spawn_async (NULL, _tmp15_, NULL, G_SPAWN_DO_NOT_REAP_CHILD, NULL, NULL, &_tmp16_, &_inner_error0_); + client_pid = _tmp16_; + _tmp15_ = (_vala_array_free (_tmp15_, _tmp15__length1, (GDestroyNotify) g_free), NULL); + if (G_UNLIKELY (_inner_error0_ != NULL)) { + _g_variant_unref0 (request_result); + _g_object_unref0 (conn); + g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error0_->message, g_quark_to_string (_inner_error0_->domain), _inner_error0_->code); + g_clear_error (&_inner_error0_); + return; + } + g_child_watch_add_full (G_PRIORITY_DEFAULT_IDLE, client_pid, _client_exit_gchild_watch_func, NULL, NULL); + _tmp17_ = g_main_loop_new (NULL, FALSE); + _g_main_loop_unref0 (main_loop); + main_loop = _tmp17_; + _tmp18_ = main_loop; + g_main_loop_run (_tmp18_); + _g_variant_unref0 (request_result); + _g_object_unref0 (conn); +} + +int +main (int argc, + char ** argv) +{ + _vala_main (); + return 0; +} + +static void +_vala_array_destroy (gpointer array, + gssize array_length, + GDestroyNotify destroy_func) +{ + if ((array != NULL) && (destroy_func != NULL)) { + gssize i; + for (i = 0; i < array_length; i = i + 1) { + if (((gpointer*) array)[i] != NULL) { + destroy_func (((gpointer*) array)[i]); + } + } + } +} + +static void +_vala_array_free (gpointer array, + gssize array_length, + GDestroyNotify destroy_func) +{ + _vala_array_destroy (array, array_length, destroy_func); + g_free (array); +} + |