IBusInputContext * ibus_bus_create_input_context (IBusBus *bus, const gchar *client_name) { g_assert (IBUS_IS_BUS (bus)); g_assert (client_name != NULL); g_return_val_if_fail (ibus_bus_is_connected (bus), NULL); gchar *path; DBusMessage *call = NULL; DBusMessage *reply = NULL; IBusError *error; IBusInputContext *context = NULL; IBusBusPrivate *priv; priv = IBUS_BUS_GET_PRIVATE (bus); call = ibus_message_new_method_call (IBUS_SERVICE_IBUS, IBUS_PATH_IBUS, IBUS_INTERFACE_IBUS, "CreateInputContext"); ibus_message_append_args (call, G_TYPE_STRING, &client_name, G_TYPE_INVALID); reply = ibus_connection_send_with_reply_and_block (priv->connection, call, -1, &error); ibus_message_unref (call); if (reply == NULL) { g_warning ("%s: %s", error->name, error->message); ibus_error_free (error); return NULL; } if ((error = ibus_error_new_from_message (reply)) != NULL) { g_warning ("%s: %s", error->name, error->message); ibus_message_unref (reply); ibus_error_free (error); return NULL; } if (!ibus_message_get_args (reply, &error, IBUS_TYPE_OBJECT_PATH, &path, G_TYPE_INVALID)) { g_warning ("%s: %s", error->name, error->message); ibus_message_unref (reply); ibus_error_free (error); return NULL; } context = ibus_input_context_new (path, priv->connection); ibus_message_unref (reply); return context; }
static IBusMessage * ibus_connection_call_with_reply_valist (IBusConnection *connection, const gchar *name, const gchar *path, const gchar *interface, const gchar *member, IBusError **error, GType first_arg_type, va_list va_args) { g_assert (IBUS_IS_CONNECTION (connection)); g_assert (name != NULL); g_assert (path != NULL); g_assert (interface != NULL); g_assert (member != NULL); g_assert (ibus_connection_is_connected (connection)); IBusConnectionPrivate *priv; priv = IBUS_CONNECTION_GET_PRIVATE (connection); IBusMessage *message, *reply; IBusError *tmp_error; message = ibus_message_new_method_call (name, path, interface, member); ibus_message_append_args_valist (message, first_arg_type, va_args); reply = ibus_connection_send_with_reply_and_block ( connection, message, -1, error); ibus_message_unref (message); if (reply == NULL) { return NULL; } if ((tmp_error = ibus_error_new_from_message (reply)) != NULL) { if (error) { *error = tmp_error; } else { ibus_error_free (tmp_error); } ibus_message_unref (reply); return NULL; } return reply; }
IBusMessage * ibus_bus_call_with_reply_valist (IBusBus *bus, const gchar *name, const gchar *path, const gchar *interface, const gchar *member, GType first_arg_type, va_list va_args) { g_assert (IBUS_IS_BUS (bus)); g_assert (name != NULL); g_assert (path != NULL); g_assert (interface != NULL); g_assert (member); IBusMessage *message, *reply; IBusError *error; IBusBusPrivate *priv; g_return_val_if_fail (ibus_bus_is_connected (bus), FALSE); priv = IBUS_BUS_GET_PRIVATE (bus); message = ibus_message_new_method_call (name, path, interface, member); ibus_message_append_args_valist (message, first_arg_type, va_args); reply = ibus_connection_send_with_reply_and_block ( priv->connection, message, -1, &error); ibus_message_unref (message); if (reply == NULL) { g_warning ("%s : %s", error->name, error->message); ibus_error_free (error); return NULL; } if ((error = ibus_error_new_from_message (reply)) != NULL) { g_warning ("%s : %s", error->name, error->message); ibus_error_free (error); ibus_message_unref (reply); return NULL; } return reply; }
static void bus_engine_proxy_process_key_event_reply_cb (IBusPendingCall *pending, CallData *call_data) { IBusMessage *reply_message; IBusError *error; gboolean retval = FALSE; reply_message = dbus_pending_call_steal_reply (pending); if (reply_message == NULL) { /* reply timeout */ IBusObject *connection; connection = (IBusObject *) ibus_proxy_get_connection ((IBusProxy *)call_data->engine); ibus_object_destroy (connection); goto _out; } else if ((error = ibus_error_new_from_message (reply_message)) != NULL) { if (g_strcmp0 (error->name, DBUS_ERROR_NO_REPLY) == 0) { /* reply timeout */ IBusObject *connection; connection = (IBusObject *) ibus_proxy_get_connection ((IBusProxy *)call_data->engine); if (connection) { ibus_object_destroy (connection); } } g_warning ("%s: %s", error->name, error->message); ibus_error_free (error); goto _out; } if (!ibus_message_get_args (reply_message, &error, G_TYPE_BOOLEAN, &retval, G_TYPE_INVALID)) { g_warning ("%s: %s", error->name, error->message); ibus_error_free (error); goto _out; } _out: if (reply_message) { ibus_message_unref (reply_message); } g_object_unref (call_data->engine); call_data->func (GINT_TO_POINTER (retval), call_data->user_data); g_slice_free (CallData, call_data); }
gboolean ibus_config_get_value (IBusConfig *config, const gchar *section, const gchar *name, GValue *value) { g_assert (IBUS_IS_CONFIG (config)); g_assert (section != NULL); g_assert (name != NULL); g_assert (value != NULL); IBusMessage *reply; IBusError *error; gboolean retval; reply = ibus_proxy_call_with_reply_and_block ((IBusProxy *) config, "GetValue", -1, &error, G_TYPE_STRING, §ion, G_TYPE_STRING, &name, G_TYPE_INVALID); if (reply == NULL) { g_warning ("%s: %s", error->name, error->message); ibus_error_free (error); return FALSE; } if ((error = ibus_error_new_from_message (reply)) != NULL) { g_warning ("%s: %s", error->name, error->message); ibus_error_free (error); ibus_message_unref (reply); return FALSE; } retval = ibus_message_get_args (reply, &error, G_TYPE_VALUE, value, G_TYPE_INVALID); ibus_message_unref (reply); if (!retval) { g_warning ("%s: %s", error->name, error->message); return FALSE; } return TRUE; }
static GList * ibus_bus_do_list_engines (IBusBus *bus, gboolean active_engines_only) { g_assert (IBUS_IS_BUS (bus)); IBusMessage *message, *reply; IBusError *error; gboolean retval; IBusBusPrivate *priv; IBusMessageIter iter, subiter; GList *engines; const gchar* member = active_engines_only ? "ListActiveEngines" : "ListEngines"; priv = IBUS_BUS_GET_PRIVATE (bus); message = ibus_message_new_method_call (IBUS_SERVICE_IBUS, IBUS_PATH_IBUS, IBUS_INTERFACE_IBUS, member); reply = ibus_connection_send_with_reply_and_block (priv->connection, message, -1, &error); ibus_message_unref (message); if (reply == NULL) { g_warning ("%s : %s", error->name, error->message); ibus_error_free (error); return NULL; } if ((error = ibus_error_new_from_message (reply)) != NULL) { g_warning ("%s : %s", error->name, error->message); ibus_error_free (error); ibus_message_unref (reply); return NULL; } retval = ibus_message_iter_init (reply, &iter); if (!retval) { error = ibus_error_new_from_printf (DBUS_ERROR_INVALID_ARGS, "Message does not have arguments!"); g_warning ("%s : %s", error->name, error->message); ibus_error_free (error); ibus_message_unref (reply); return NULL; } if (!ibus_message_iter_recurse (&iter, IBUS_TYPE_ARRAY, &subiter)) { ibus_message_unref (reply); return NULL; } engines = NULL; while (ibus_message_iter_get_arg_type (&subiter) != G_TYPE_INVALID) { IBusSerializable *object = NULL; if (!ibus_message_iter_get (&subiter, IBUS_TYPE_ENGINE_DESC, &object) || !object) { g_warning ("Unexpected type is returned from %s", member); continue; } engines = g_list_append (engines, object); ibus_message_iter_next (&subiter); }; ibus_message_unref (reply); return engines; }
static gboolean ibus_bus_call (IBusBus *bus, const gchar *name, const gchar *path, const gchar *interface, const gchar *member, GType first_arg_type, ...) { g_assert (IBUS_IS_BUS (bus)); g_assert (name != NULL); g_assert (path != NULL); g_assert (interface != NULL); g_assert (member); IBusMessage *message, *reply; IBusError *error; va_list args; GType type; gboolean retval; IBusBusPrivate *priv; g_return_val_if_fail (ibus_bus_is_connected (bus), FALSE); priv = IBUS_BUS_GET_PRIVATE (bus); message = ibus_message_new_method_call (name, path, interface, member); va_start (args, first_arg_type); ibus_message_append_args_valist (message, first_arg_type, args); va_end (args); reply = ibus_connection_send_with_reply_and_block ( priv->connection, message, -1, &error); ibus_message_unref (message); if (reply == NULL) { g_warning ("%s : %s", error->name, error->message); ibus_error_free (error); return FALSE; } if ((error = ibus_error_new_from_message (reply)) != NULL) { g_warning ("%s : %s", error->name, error->message); ibus_error_free (error); ibus_message_unref (reply); return FALSE; } va_start (args, first_arg_type); type = first_arg_type; while (type != G_TYPE_INVALID) { va_arg (args, gpointer); type = va_arg (args, GType); } type = va_arg (args, GType); if (type != G_TYPE_INVALID) { retval = ibus_message_get_args_valist (reply, &error, type, args); } else { retval = TRUE; } va_end (args); ibus_message_unref (reply); if (!retval) { g_warning ("%s: %s", error->name, error->message); ibus_error_free (error); return FALSE; } return TRUE; }
gboolean ibus_connection_call (IBusConnection *connection, const gchar *name, const gchar *path, const gchar *interface, const gchar *member, IBusError **error, GType first_arg_type, ...) { g_assert (IBUS_IS_CONNECTION (connection)); g_assert (name != NULL); g_assert (path != NULL); g_assert (interface != NULL); g_assert (member != NULL); IBusConnectionPrivate *priv; priv = IBUS_CONNECTION_GET_PRIVATE (connection); g_assert (dbus_connection_get_is_connected (priv->connection)); IBusMessage *message, *reply; IBusError *tmp_error; va_list args; GType type; gboolean retval; message = ibus_message_new_method_call (name, path, interface, member); va_start (args, first_arg_type); ibus_message_append_args_valist (message, first_arg_type, args); va_end (args); reply = ibus_connection_send_with_reply_and_block ( connection, message, -1, error); ibus_message_unref (message); if (reply == NULL) { return FALSE; } if ((tmp_error = ibus_error_new_from_message (reply)) != NULL) { if (error) { *error = tmp_error; } else { ibus_error_free (tmp_error); } ibus_message_unref (reply); return FALSE; } va_start (args, first_arg_type); type = first_arg_type; while (type != G_TYPE_INVALID) { va_arg (args, gpointer); type = va_arg (args, GType); } type = va_arg (args, GType); if (type != G_TYPE_INVALID) { retval = ibus_message_get_args_valist (reply, error, type, args); } else { retval = TRUE; } va_end (args); ibus_message_unref (reply); return retval; }
BusEngineProxy * bus_factory_proxy_create_engine (BusFactoryProxy *factory, IBusEngineDesc *desc) { g_assert (BUS_IS_FACTORY_PROXY (factory)); g_assert (IBUS_IS_ENGINE_DESC (desc)); IBusPendingCall *pending = NULL; IBusMessage *reply_message; IBusError *error; BusEngineProxy *engine; gchar *object_path; gboolean retval; if (g_list_find (factory->component->engines, desc) == NULL) { return NULL; } retval = ibus_proxy_call_with_reply ((IBusProxy *) factory, "CreateEngine", &pending, g_dbus_timeout, &error, G_TYPE_STRING, &(desc->name), G_TYPE_INVALID); if (!retval) { g_warning ("%s: %s", error->name, error->message); ibus_error_free (error); return NULL; } ibus_pending_call_wait (pending); reply_message = ibus_pending_call_steal_reply (pending); ibus_pending_call_unref (pending); if (reply_message == NULL) { IBusObject *connection; connection = (IBusObject *) ibus_proxy_get_connection ((IBusProxy *)factory); ibus_object_destroy (connection); g_warning ("%s: %s", error->name, error->message); ibus_error_free (error); return NULL; } if ((error = ibus_error_new_from_message (reply_message)) != NULL) { if (g_strcmp0 (error->name, DBUS_ERROR_NO_REPLY) == 0) { IBusObject *connection; connection = (IBusObject *) ibus_proxy_get_connection ((IBusProxy *)factory); ibus_object_destroy (connection); } g_warning ("%s: %s", error->name, error->message); ibus_error_free (error); ibus_message_unref (reply_message); return NULL; } if (!ibus_message_get_args (reply_message, &error, IBUS_TYPE_OBJECT_PATH, &object_path, G_TYPE_INVALID)) { g_warning ("%s: %s", error->name, error->message); ibus_error_free (error); ibus_message_unref (reply_message); return NULL; } IBusConnection *connection = ibus_proxy_get_connection ((IBusProxy *) factory); engine = bus_engine_proxy_new (object_path, desc, (BusConnection *) connection); ibus_message_unref (reply_message); return engine; }
gboolean ibus_input_context_process_key_event (IBusInputContext *context, guint32 keyval, guint32 keycode, guint32 state) { g_assert (IBUS_IS_INPUT_CONTEXT (context)); IBusMessage *reply_message; IBusPendingCall *pending = NULL; IBusError *error = NULL; gboolean retval; if (state & IBUS_HANDLED_MASK) return TRUE; if (state & IBUS_IGNORED_MASK) return FALSE; retval = ibus_proxy_call_with_reply ((IBusProxy *) context, "ProcessKeyEvent", &pending, -1, &error, G_TYPE_UINT, &keyval, G_TYPE_UINT, &keycode, G_TYPE_UINT, &state, G_TYPE_INVALID); if (!retval) { g_debug ("%s: %s", error->name, error->message); ibus_error_free (error); return FALSE; } /* wait reply or timeout */ IBusConnection *connection = ibus_proxy_get_connection ((IBusProxy *) context); while (!ibus_pending_call_get_completed (pending)) { ibus_connection_read_write_dispatch (connection, -1); } reply_message = ibus_pending_call_steal_reply (pending); ibus_pending_call_unref (pending); if (reply_message == NULL) { g_debug ("%s: Do not recevie reply of ProcessKeyEvent", DBUS_ERROR_NO_REPLY); retval = FALSE; } else if ((error = ibus_error_new_from_message (reply_message)) != NULL) { g_debug ("%s: %s", error->name, error->message); ibus_message_unref (reply_message); ibus_error_free (error); retval = FALSE; } else { if (!ibus_message_get_args (reply_message, &error, G_TYPE_BOOLEAN, &retval, G_TYPE_INVALID)) { g_debug ("%s: %s", error->name, error->message); ibus_error_free (error); retval = FALSE; } ibus_message_unref (reply_message); } return retval; }