gboolean ibus_service_remove_from_connection (IBusService *service, IBusConnection *connection) { g_return_val_if_fail (IBUS_IS_SERVICE (service), FALSE); g_return_val_if_fail (IBUS_IS_CONNECTION (connection), FALSE); IBusServicePrivate *priv; priv = IBUS_SERVICE_GET_PRIVATE (service); g_assert (priv->path != NULL); g_assert (g_list_find (priv->connections, connection) != NULL); gboolean retval; retval = ibus_connection_unregister_object_path (connection, priv->path); if (!retval) { return FALSE; } g_signal_handlers_disconnect_by_func (connection, (GCallback) _connection_destroy_cb, service); priv->connections = g_list_remove (priv->connections, connection); g_object_unref (connection); return TRUE; }
static void _connection_destroy_cb (IBusConnection *connection, IBusBus *bus) { g_assert (IBUS_IS_BUS (bus)); g_assert (IBUS_IS_CONNECTION (connection)); IBusBusPrivate *priv; priv = IBUS_BUS_GET_PRIVATE (bus); g_assert (priv->connection == connection); g_signal_handlers_disconnect_by_func (priv->connection, G_CALLBACK (_connection_destroy_cb), bus); g_signal_handlers_disconnect_by_func (priv->connection, G_CALLBACK (_connection_ibus_signal_cb), bus); g_object_unref (priv->connection); priv->connection = NULL; g_free (priv->unique_name); priv->unique_name = NULL; g_signal_emit (bus, bus_signals[DISCONNECTED], 0); }
gboolean ibus_connection_send_valist (IBusConnection *connection, gint message_type, const gchar *path, const gchar *interface, const gchar *name, GType first_arg_type, va_list args) { g_assert (IBUS_IS_CONNECTION (connection)); g_assert (interface != NULL); g_assert (name != NULL); gboolean retval; IBusMessage *message; message = ibus_message_new (message_type); ibus_message_set_path (message, path); ibus_message_set_interface (message, interface); ibus_message_set_member (message, name); ibus_message_append_args_valist (message, first_arg_type, args); retval = ibus_connection_send (connection, message); ibus_message_unref (message); return retval; }
gboolean ibus_service_add_to_connection (IBusService *service, IBusConnection *connection) { g_assert (IBUS_IS_SERVICE (service)); g_assert (IBUS_IS_CONNECTION (connection)); gboolean retval; IBusServicePrivate *priv; priv = IBUS_SERVICE_GET_PRIVATE (service); g_return_val_if_fail (priv->path != NULL, FALSE); g_return_val_if_fail (g_list_find (priv->connections, connection) == NULL, FALSE); g_object_ref (connection); retval = ibus_connection_register_object_path (connection, priv->path, (IBusMessageFunc) _service_message_function, service); if (!retval) { g_object_unref (connection); return FALSE; } priv->connections = g_list_append (priv->connections, connection); g_signal_connect (connection, "destroy", (GCallback) _connection_destroy_cb, service); return retval; }
void ibus_connection_set_connection (IBusConnection *connection, DBusConnection *dbus_connection, gboolean shared) { gboolean result; IBusConnectionPrivate *priv; g_assert (IBUS_IS_CONNECTION (connection)); g_assert (dbus_connection != NULL); g_assert (dbus_connection_get_is_connected (dbus_connection)); priv = IBUS_CONNECTION_GET_PRIVATE (connection); g_assert (priv->connection == NULL); priv->connection = dbus_connection_ref (dbus_connection); priv->shared = shared; dbus_connection_set_data (priv->connection, _get_slot(), connection, NULL); dbus_connection_set_unix_user_function (priv->connection, (DBusAllowUnixUserFunction) _connection_allow_unix_user_cb, connection, NULL); result = dbus_connection_add_filter (priv->connection, (DBusHandleMessageFunction) _connection_handle_message_cb, connection, NULL); ibus_dbus_connection_setup (priv->connection); g_warn_if_fail (result); }
gboolean ibus_connection_register_object_path (IBusConnection *connection, const gchar *path, IBusMessageFunc message_func, gpointer user_data) { g_assert (IBUS_IS_CONNECTION (connection)); g_assert (path != NULL); g_assert (message_func != NULL); IBusConnectionPrivate *priv; priv = IBUS_CONNECTION_GET_PRIVATE (connection); gboolean retval; DBusObjectPathVTable vtable = {0}; VTableCallData *data; vtable.unregister_function = (DBusObjectPathUnregisterFunction) _unregister_function; vtable.message_function = (DBusObjectPathMessageFunction) _message_function; data = g_slice_new (VTableCallData); data->message_func = message_func; data->user_data = user_data; retval = dbus_connection_register_object_path (priv->connection, path, &vtable, data); if (!retval) { g_warning ("Out of memory!"); return FALSE; } return TRUE; }
static void _connection_destroy_cb (IBusConnection *connection, IBusService *service) { g_assert (IBUS_IS_CONNECTION (connection)); g_assert (IBUS_IS_SERVICE (service)); ibus_service_remove_from_connection (service, connection); }
void ibus_connection_close (IBusConnection *connection) { g_assert (IBUS_IS_CONNECTION (connection)); IBusConnectionPrivate *priv; priv = IBUS_CONNECTION_GET_PRIVATE (connection); dbus_connection_close (priv->connection); }
void ibus_connection_flush (IBusConnection *connection) { g_assert (IBUS_IS_CONNECTION (connection)); g_assert (ibus_connection_is_connected (connection)); IBusConnectionPrivate *priv; priv = IBUS_CONNECTION_GET_PRIVATE (connection); dbus_connection_flush (priv->connection); }
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; }
IBusConfigService * ibus_config_service_new (IBusConnection *connection) { g_assert (IBUS_IS_CONNECTION (connection)); IBusConfigService *config; config = (IBusConfigService *) g_object_new (IBUS_TYPE_CONFIG_SERVICE, "path", IBUS_PATH_CONFIG, "connection", connection, NULL); return config; }
IBusConfig * ibus_config_new (IBusConnection *connection) { g_assert (IBUS_IS_CONNECTION (connection)); GObject *obj; obj = g_object_new (IBUS_TYPE_CONFIG, "name", IBUS_SERVICE_CONFIG, "path", IBUS_PATH_CONFIG, "connection", connection, NULL); return IBUS_CONFIG (obj); }
IBusPanelService * ibus_panel_service_new (IBusConnection *connection) { g_assert (IBUS_IS_CONNECTION (connection)); IBusPanelService *panel; panel = (IBusPanelService*) g_object_new (IBUS_TYPE_PANEL_SERVICE, "path", IBUS_PATH_PANEL, "connection", connection, NULL); return panel; }
IBusInputContext * ibus_input_context_new (const gchar *path, IBusConnection *connection) { g_assert (path != NULL); g_assert (IBUS_IS_CONNECTION (connection)); GObject *obj; obj = g_object_new (IBUS_TYPE_INPUT_CONTEXT, "name", IBUS_SERVICE_IBUS, "path", path, "connection", connection, NULL); return IBUS_INPUT_CONTEXT (obj); }
IBusFactory * ibus_factory_new (IBusConnection *connection) { g_assert (IBUS_IS_CONNECTION (connection)); IBusFactory *factory; IBusFactoryPrivate *priv; factory = (IBusFactory *) g_object_new (IBUS_TYPE_FACTORY, "path", IBUS_PATH_FACTORY, "connection", connection, NULL); priv = IBUS_FACTORY_GET_PRIVATE (factory); return factory; }
IBusFactory * ibus_factory_new (IBusConnection *connection) { g_assert (IBUS_IS_CONNECTION (connection)); IBusFactory *factory; IBusFactoryPrivate *priv; factory = (IBusFactory *) g_object_new (IBUS_TYPE_FACTORY, "path", IBUS_PATH_FACTORY, NULL); priv = IBUS_FACTORY_GET_PRIVATE (factory); priv->connection = g_object_ref (connection); ibus_service_add_to_connection ((IBusService *)factory, connection); return factory; }
IBusEngine * ibus_engine_new (const gchar *name, const gchar *path, IBusConnection *connection) { g_assert (path); g_assert (IBUS_IS_CONNECTION (connection)); IBusEngine *engine; engine = (IBusEngine *) g_object_new (IBUS_TYPE_ENGINE, "name", name, "path", path, "connection", connection, NULL); return engine; }
IBusProxy * ibus_proxy_new (const gchar *name, const gchar *path, IBusConnection *connection) { g_assert (name != NULL); g_assert (path != NULL); g_assert (IBUS_IS_CONNECTION (connection)); IBusProxy *proxy; proxy = IBUS_PROXY (g_object_new (IBUS_TYPE_PROXY, "name", name, "path", path, "connection", connection, NULL)); return proxy; }
gboolean ibus_connection_unregister_object_path (IBusConnection *connection, const gchar *path) { g_assert (IBUS_IS_CONNECTION (connection)); g_assert (path != NULL); IBusConnectionPrivate *priv; priv = IBUS_CONNECTION_GET_PRIVATE (connection); gboolean retval; retval = dbus_connection_unregister_object_path (priv->connection, path); if (!retval) { g_warning ("Out of memory!"); return FALSE; } return TRUE; }
IBusMessage * ibus_connection_send_with_reply_and_block (IBusConnection *connection, IBusMessage *message, gint timeout_milliseconds, IBusError **error) { g_assert (IBUS_IS_CONNECTION (connection)); g_assert (message != NULL); g_assert (timeout_milliseconds > 0 || timeout_milliseconds == -1); IBusError *_error; IBusMessage *reply; IBusConnectionPrivate *priv; priv = IBUS_CONNECTION_GET_PRIVATE (connection); _error = ibus_error_new (); reply = dbus_connection_send_with_reply_and_block (priv->connection, message, timeout_milliseconds, _error); if (reply != NULL) { g_signal_emit (connection, connection_signals[IBUS_MESSAGE_SENT], 0, message); ibus_error_free (_error); } else { if (error != NULL) { *error = _error; } else { ibus_error_free (_error); } } return reply; }
gboolean ibus_connection_send (IBusConnection *connection, IBusMessage *message) { g_assert (IBUS_IS_CONNECTION (connection)); g_assert (message != NULL); gboolean retval; IBusConnectionPrivate *priv; priv = IBUS_CONNECTION_GET_PRIVATE (connection); retval = dbus_connection_send (priv->connection, message, NULL); if (retval) { g_signal_emit (connection, connection_signals[IBUS_MESSAGE_SENT], 0, message); } return retval; }
gboolean ibus_connection_send_with_reply (IBusConnection *connection, IBusMessage *message, IBusPendingCall **pending_return, gint timeout_milliseconds) { g_assert (IBUS_IS_CONNECTION (connection)); g_assert (message != NULL); g_assert (pending_return != NULL); g_assert (timeout_milliseconds > 0 || timeout_milliseconds == -1); IBusConnectionPrivate *priv; priv = IBUS_CONNECTION_GET_PRIVATE (connection); gboolean retval; retval = dbus_connection_send_with_reply (priv->connection, message, pending_return, timeout_milliseconds); return retval; }
static gboolean ibus_config_service_ibus_message (IBusConfigService *config, IBusConnection *connection, IBusMessage *message) { g_assert (IBUS_IS_CONFIG_SERVICE (config)); g_assert (IBUS_IS_CONNECTION (connection)); g_assert (message != NULL); IBusMessage *reply = NULL; if (ibus_message_is_method_call (message, IBUS_INTERFACE_CONFIG, "SetValue")) { gchar *section; gchar *name; GValue value = { 0 }; IBusError *error = NULL; gboolean retval; retval = ibus_message_get_args (message, &error, G_TYPE_STRING, §ion, G_TYPE_STRING, &name, G_TYPE_VALUE, &value, G_TYPE_INVALID); if (!retval) { reply = ibus_message_new_error_printf (message, DBUS_ERROR_INVALID_ARGS, "Can not parse arguments 1 of SetValue"); ibus_error_free (error); } else if (!IBUS_CONFIG_SERVICE_GET_CLASS (config)->set_value (config, section, name, &value, &error)) { reply = ibus_message_new_error (message, error->name, error->message); ibus_error_free (error); } else { reply = ibus_message_new_method_return (message); } } else if (ibus_message_is_method_call (message, IBUS_INTERFACE_CONFIG, "GetValue")) { gchar *section; gchar *name; GValue value = { 0 }; IBusError *error = NULL; gboolean retval; retval = ibus_message_get_args (message, &error, G_TYPE_STRING, §ion, G_TYPE_STRING, &name, G_TYPE_INVALID); if (!retval) { reply = ibus_message_new_error (message, error->name, error->message); ibus_error_free (error); } else if (!IBUS_CONFIG_SERVICE_GET_CLASS (config)->get_value (config, section, name, &value, &error)) { reply = ibus_message_new_error (message, error->name, error->message); ibus_error_free (error); } else { reply = ibus_message_new_method_return (message); ibus_message_append_args (reply, G_TYPE_VALUE, &value, G_TYPE_INVALID); g_value_unset (&value); } } if (reply) { ibus_connection_send (connection, reply); ibus_message_unref (reply); return TRUE; } return parent_class->ibus_message ((IBusService *) config, connection, message); }
static gboolean ibus_panel_service_ibus_message (IBusPanelService *panel, IBusConnection *connection, IBusMessage *message) { g_assert (IBUS_IS_PANEL_SERVICE (panel)); g_assert (IBUS_IS_CONNECTION (connection)); g_assert (message != NULL); const static struct { const gchar *name; const gint offset; } no_arg_methods [] = { { "CursorUpLookupTable" , G_STRUCT_OFFSET (IBusPanelServiceClass, cursor_down_lookup_table) }, { "CursorDownLookupTable", G_STRUCT_OFFSET (IBusPanelServiceClass, cursor_up_lookup_table) }, { "Destroy", G_STRUCT_OFFSET (IBusPanelServiceClass, destroy) }, { "HideAuxiliaryText", G_STRUCT_OFFSET (IBusPanelServiceClass, hide_auxiliary_text) }, { "HideLanguageBar", G_STRUCT_OFFSET (IBusPanelServiceClass, hide_language_bar) }, { "HideLookupTable", G_STRUCT_OFFSET (IBusPanelServiceClass, hide_lookup_table) }, { "HidePreeditText", G_STRUCT_OFFSET (IBusPanelServiceClass, hide_preedit_text) }, { "PageDownLookupTable", G_STRUCT_OFFSET (IBusPanelServiceClass, page_down_lookup_table) }, { "PageUpLookupTable", G_STRUCT_OFFSET (IBusPanelServiceClass, page_up_lookup_table) }, { "Reset", G_STRUCT_OFFSET (IBusPanelServiceClass, reset) }, { "ShowAuxiliaryText", G_STRUCT_OFFSET (IBusPanelServiceClass, show_auxiliary_text) }, { "ShowLanguageBar", G_STRUCT_OFFSET (IBusPanelServiceClass, show_language_bar) }, { "ShowLookupTable", G_STRUCT_OFFSET (IBusPanelServiceClass, show_lookup_table) }, { "ShowPreeditText", G_STRUCT_OFFSET (IBusPanelServiceClass, show_preedit_text) }, { "StartSetup", G_STRUCT_OFFSET (IBusPanelServiceClass, start_setup) }, { "StateChanged", G_STRUCT_OFFSET (IBusPanelServiceClass, state_changed) }, }; IBusMessage *reply = NULL; gint i; for (i = 0; i < G_N_ELEMENTS (no_arg_methods); i++) { if (!ibus_message_is_method_call (message, IBUS_INTERFACE_PANEL, no_arg_methods[i].name)) continue; IBusMessageIter iter; ibus_message_iter_init (message, &iter); if (ibus_message_iter_has_next (&iter)) { reply = ibus_message_new_error_printf (message, DBUS_ERROR_INVALID_ARGS, "%s.%s: Method does not have arguments", IBUS_INTERFACE_PANEL, no_arg_methods[i].name); } else { IBusError *error = NULL; typedef gboolean (* NoArgFunc) (IBusPanelService *, IBusError **); NoArgFunc func; func = G_STRUCT_MEMBER (NoArgFunc, IBUS_PANEL_SERVICE_GET_CLASS (panel), no_arg_methods[i].offset); if (!func (panel, &error)) { reply = ibus_message_new_error (message, error->name, error->message); ibus_error_free (error); } else { reply = ibus_message_new_method_return (message); } } ibus_connection_send (connection, reply); ibus_message_unref (reply); return TRUE; } if (ibus_message_is_method_call (message, IBUS_INTERFACE_PANEL, "FocusIn")) { const gchar* input_context_path = NULL; IBusError *error = NULL; gboolean retval; retval = ibus_message_get_args (message, &error, IBUS_TYPE_OBJECT_PATH, &input_context_path, G_TYPE_INVALID); if (!retval || !IBUS_PANEL_SERVICE_GET_CLASS (panel)->focus_in (panel, input_context_path, &error)) { reply = ibus_message_new_error (message, error->name, error->message); ibus_error_free (error); } else { reply = ibus_message_new_method_return (message); } } else if (ibus_message_is_method_call (message, IBUS_INTERFACE_PANEL, "FocusOut")) { const gchar* input_context_path = NULL; gboolean retval; IBusError *error = NULL; retval = ibus_message_get_args (message, &error, IBUS_TYPE_OBJECT_PATH, &input_context_path, G_TYPE_INVALID); if (!retval || !IBUS_PANEL_SERVICE_GET_CLASS (panel)->focus_out (panel, input_context_path, &error)) { reply = ibus_message_new_error(message, error->name, error->message); ibus_error_free (error); } else { reply = ibus_message_new_method_return (message); } } else if (ibus_message_is_method_call (message, IBUS_INTERFACE_PANEL, "RegisterProperties")) { IBusPropList *prop_list = NULL; gboolean retval; IBusError *error = NULL; retval = ibus_message_get_args (message, &error, IBUS_TYPE_PROP_LIST, &prop_list, G_TYPE_INVALID); if (!retval || !IBUS_PANEL_SERVICE_GET_CLASS (panel)->register_properties (panel, prop_list, &error)) { reply = ibus_message_new_error(message, error->name, error->message); ibus_error_free (error); } else { reply = ibus_message_new_method_return (message); } if (prop_list != NULL && g_object_is_floating (prop_list)) g_object_unref (prop_list); } else if (ibus_message_is_method_call (message, IBUS_INTERFACE_PANEL, "UpdateAuxiliaryText")) { IBusText *text = NULL; gboolean visible; gboolean retval; IBusError *error = NULL; retval = ibus_message_get_args (message, &error, IBUS_TYPE_TEXT, &text, G_TYPE_BOOLEAN, &visible, G_TYPE_INVALID); if (!retval || !IBUS_PANEL_SERVICE_GET_CLASS (panel)->update_auxiliary_text (panel, text, visible, &error)) { reply = ibus_message_new_error(message, error->name, error->message); ibus_error_free (error); } else { reply = ibus_message_new_method_return (message); } if (text != NULL && g_object_is_floating (text)) g_object_unref (text); } else if (ibus_message_is_method_call (message, IBUS_INTERFACE_PANEL, "UpdateLookupTable")) { IBusLookupTable *table = NULL; gboolean visible = FALSE; gboolean retval; IBusError *error = NULL; retval = ibus_message_get_args (message, &error, IBUS_TYPE_LOOKUP_TABLE, &table, G_TYPE_BOOLEAN, &visible, G_TYPE_INVALID); if (!retval || !IBUS_PANEL_SERVICE_GET_CLASS (panel)->update_lookup_table (panel, table, visible, &error)) { reply = ibus_message_new_error(message, error->name, error->message); ibus_error_free (error); } else { reply = ibus_message_new_method_return (message); } if (table != NULL && g_object_is_floating (table)) g_object_unref (table); } else if (ibus_message_is_method_call (message, IBUS_INTERFACE_PANEL, "UpdatePreeditText")) { IBusText *text = NULL; guint cursor_pos; gboolean visible; gboolean retval; IBusError *error = NULL; retval = ibus_message_get_args (message, &error, IBUS_TYPE_TEXT, &text, G_TYPE_UINT, &cursor_pos, G_TYPE_BOOLEAN, &visible, G_TYPE_INVALID); if (!retval || !IBUS_PANEL_SERVICE_GET_CLASS (panel)->update_preedit_text (panel, text, cursor_pos, visible, &error)) { reply = ibus_message_new_error(message, error->name, error->message); ibus_error_free (error); } else { reply = ibus_message_new_method_return (message); } if (text != NULL && g_object_is_floating (text)) g_object_unref (text); } else if (ibus_message_is_method_call (message, IBUS_INTERFACE_PANEL, "UpdateProperty")) { IBusProperty *property = NULL; gboolean retval; IBusError *error = NULL; retval = ibus_message_get_args (message, &error, IBUS_TYPE_PROPERTY, &property, G_TYPE_INVALID); if (!retval || !IBUS_PANEL_SERVICE_GET_CLASS (panel)->update_property (panel, property, &error)) { reply = ibus_message_new_error(message, error->name, error->message); ibus_error_free (error); } else { reply = ibus_message_new_method_return (message); } if (property != NULL && g_object_is_floating (property)) g_object_unref (property); } else if (ibus_message_is_method_call (message, IBUS_INTERFACE_PANEL, "SetCursorLocation")) { guint x, y, w, h; gboolean retval; IBusError *error = NULL; retval = ibus_message_get_args (message, &error, G_TYPE_INT, &x, G_TYPE_INT, &y, G_TYPE_INT, &w, G_TYPE_INT, &h, G_TYPE_INVALID); if (!retval || !IBUS_PANEL_SERVICE_GET_CLASS (panel)->set_cursor_location (panel, x, y, w, h, &error)) { reply = ibus_message_new_error(message, error->name, error->message); ibus_error_free (error); } else { reply = ibus_message_new_method_return (message); } } if (reply) { ibus_connection_send (connection, reply); ibus_message_unref (reply); return TRUE; } 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; }
static gboolean ibus_factory_ibus_message (IBusFactory *factory, IBusConnection *connection, IBusMessage *message) { g_assert (IBUS_IS_FACTORY (factory)); g_assert (IBUS_IS_CONNECTION (connection)); g_assert (message != NULL); IBusMessage *reply_message; IBusFactoryPrivate *priv; priv = IBUS_FACTORY_GET_PRIVATE (factory); g_assert (priv->connection == connection); if (ibus_message_is_method_call (message, IBUS_INTERFACE_FACTORY, "CreateEngine")) { gchar *engine_name; gchar *path; IBusError *error; IBusEngine *engine; gboolean retval; GType engine_type; retval = ibus_message_get_args (message, &error, G_TYPE_STRING, &engine_name, G_TYPE_INVALID); if (!retval) { reply_message = ibus_message_new_error_printf (message, DBUS_ERROR_INVALID_ARGS, "The 1st arg should be engine name"); ibus_connection_send (connection, reply_message); ibus_message_unref (reply_message); return TRUE; } engine_type = (GType )g_hash_table_lookup (priv->engine_table, engine_name); if (engine_type == G_TYPE_INVALID) { reply_message = ibus_message_new_error_printf (message, DBUS_ERROR_FAILED, "Can not create engine %s", engine_name); ibus_connection_send (connection, reply_message); ibus_message_unref (reply_message); return TRUE; } path = g_strdup_printf ("/org/freedesktop/IBus/Engine/%d", ++priv->id); engine = g_object_new (engine_type, "name", engine_name, "path", path, "connection", priv->connection, NULL); priv->engine_list = g_list_append (priv->engine_list, engine); g_signal_connect (engine, "destroy", G_CALLBACK (_engine_destroy_cb), factory); reply_message = ibus_message_new_method_return (message); ibus_message_append_args (reply_message, IBUS_TYPE_OBJECT_PATH, &path, G_TYPE_INVALID); g_free (path); ibus_connection_send (connection, reply_message); ibus_message_unref (reply_message); return TRUE; } return IBUS_SERVICE_CLASS (ibus_factory_parent_class)->ibus_message ( (IBusService *)factory, connection, message); }
static gboolean ibus_engine_ibus_message (IBusEngine *engine, IBusConnection *connection, IBusMessage *message) { g_assert (IBUS_IS_ENGINE (engine)); g_assert (IBUS_IS_CONNECTION (connection)); g_assert (message != NULL); g_assert (ibus_message_get_type (message) == DBUS_MESSAGE_TYPE_METHOD_CALL); IBusEnginePrivate *priv; priv = IBUS_ENGINE_GET_PRIVATE (engine); g_assert (priv->connection == connection); IBusMessage *reply = NULL; IBusError *error = NULL; gboolean retval; gint i; const gchar *interface; const gchar *name; static const struct { gchar *member; guint signal_id; } no_arg_methods[] = { { "FocusIn", FOCUS_IN }, { "FocusOut", FOCUS_OUT }, { "Reset", RESET }, { "Enable", ENABLE }, { "Disable", DISABLE }, { "PageUp", PAGE_UP }, { "PageDown", PAGE_DOWN }, { "CursorUp", CURSOR_UP }, { "CursorDown", CURSOR_DOWN }, }; interface = ibus_message_get_interface (message); name = ibus_message_get_member (message); if (interface != NULL && g_strcmp0 (interface, IBUS_INTERFACE_ENGINE) != 0) return IBUS_SERVICE_CLASS (ibus_engine_parent_class)->ibus_message ( (IBusService *) engine, connection, message); do { if (g_strcmp0 (name, "ProcessKeyEvent") == 0) { guint keyval, keycode, state; retval = ibus_message_get_args (message, &error, G_TYPE_UINT, &keyval, G_TYPE_UINT, &keycode, G_TYPE_UINT, &state, G_TYPE_INVALID); if (!retval) { reply = ibus_message_new_error_printf (message, DBUS_ERROR_INVALID_ARGS, "%s.%s: Can not match signature (uuu) of method", IBUS_INTERFACE_ENGINE, "ProcessKeyEvent"); ibus_error_free (error); } else { retval = FALSE; g_signal_emit (engine, engine_signals[PROCESS_KEY_EVENT], 0, keyval, keycode, state, &retval); reply = ibus_message_new_method_return (message); ibus_message_append_args (reply, G_TYPE_BOOLEAN, &retval, G_TYPE_INVALID); } break; } for (i = 0; i < G_N_ELEMENTS (no_arg_methods) && g_strcmp0 (name, no_arg_methods[i].member) != 0; i++); if (i < G_N_ELEMENTS (no_arg_methods)) { IBusMessageIter iter; ibus_message_iter_init (message, &iter); if (ibus_message_iter_has_next (&iter)) { reply = ibus_message_new_error_printf (message, DBUS_ERROR_INVALID_ARGS, "%s.%s: Method does not have arguments", IBUS_INTERFACE_ENGINE, no_arg_methods[i].member); } else { g_signal_emit (engine, engine_signals[no_arg_methods[i].signal_id], 0); reply = ibus_message_new_method_return (message); } break; } if (g_strcmp0 (name, "CandidateClicked") == 0) { guint index, button, state; retval = ibus_message_get_args (message, &error, G_TYPE_UINT, &index, G_TYPE_UINT, &button, G_TYPE_UINT, &state, G_TYPE_INVALID); if (!retval) { reply = ibus_message_new_error_printf (message, DBUS_ERROR_INVALID_ARGS, "%s.%s: Can not match signature (uuu) of method", IBUS_INTERFACE_ENGINE, "CandidateClicked"); ibus_error_free (error); } else { g_signal_emit (engine, engine_signals[CANDIDATE_CLICKED], 0, index, button, state); reply = ibus_message_new_method_return (message); } } else if (g_strcmp0 (name, "PropertyActivate") == 0) { gchar *name; guint state; retval = ibus_message_get_args (message, &error, G_TYPE_STRING, &name, G_TYPE_UINT, &state, G_TYPE_INVALID); if (!retval) { reply = ibus_message_new_error_printf (message, DBUS_ERROR_INVALID_ARGS, "%s.%s: Can not match signature (si) of method", IBUS_INTERFACE_ENGINE, "PropertyActivate"); ibus_error_free (error); } else { g_signal_emit (engine, engine_signals[PROPERTY_ACTIVATE], 0, name, state); reply = ibus_message_new_method_return (message); } } else if (g_strcmp0 (name, "PropertyShow") == 0) { gchar *name; retval = ibus_message_get_args (message, &error, G_TYPE_STRING, &name, G_TYPE_INVALID); if (!retval) { reply = ibus_message_new_error_printf (message, DBUS_ERROR_INVALID_ARGS, "%s.%s: Can not match signature (s) of method", IBUS_INTERFACE_ENGINE, "PropertyShow"); ibus_error_free (error); } else { g_signal_emit (engine, engine_signals[PROPERTY_SHOW], 0, name); reply = ibus_message_new_method_return (message); } } else if (g_strcmp0 (name, "PropertyHide") == 0) { gchar *name; retval = ibus_message_get_args (message, &error, G_TYPE_STRING, &name, G_TYPE_INVALID); if (!retval) { reply = ibus_message_new_error_printf (message, DBUS_ERROR_INVALID_ARGS, "%s.%s: Can not match signature (s) of method", IBUS_INTERFACE_ENGINE, "PropertyHide"); ibus_error_free (error); } else { g_signal_emit (engine, engine_signals[PROPERTY_HIDE], 0, name); reply = ibus_message_new_method_return (message); } } else if (g_strcmp0 (name, "SetCursorLocation") == 0) { gint x, y, w, h; retval = ibus_message_get_args (message, &error, G_TYPE_INT, &x, G_TYPE_INT, &y, G_TYPE_INT, &w, G_TYPE_INT, &h, G_TYPE_INVALID); if (!retval) { reply = ibus_message_new_error_printf (message, DBUS_ERROR_INVALID_ARGS, "%s.%s: Can not match signature (iiii) of method", IBUS_INTERFACE_ENGINE, "SetCursorLocation"); ibus_error_free (error); } else { engine->cursor_area.x = x; engine->cursor_area.y = y; engine->cursor_area.width = w; engine->cursor_area.height = h; g_signal_emit (engine, engine_signals[SET_CURSOR_LOCATION], 0, x, y, w, h); reply = ibus_message_new_method_return (message); } } else if (g_strcmp0 (name, "SetCapabilities") == 0) { guint caps; retval = ibus_message_get_args (message, &error, G_TYPE_UINT, &caps, G_TYPE_INVALID); if (!retval) { reply = ibus_message_new_error_printf (message, DBUS_ERROR_INVALID_ARGS, "%s.%s: Can not match signature (u) of method", IBUS_INTERFACE_ENGINE, "SetCapabilities"); ibus_error_free (error); } else { engine->client_capabilities = caps; g_signal_emit (engine, engine_signals[SET_CAPABILITIES], 0, caps); reply = ibus_message_new_method_return (message); } } else if (g_strcmp0 (name, "Destroy") == 0) { reply = ibus_message_new_method_return (message); ibus_connection_send (connection, reply); ibus_message_unref (reply); ibus_object_destroy ((IBusObject *) engine); return TRUE; } else { reply = ibus_message_new_error_printf (message, DBUS_ERROR_UNKNOWN_METHOD, "%s.%s", IBUS_INTERFACE_ENGINE, name); g_warn_if_reached (); } } while (0); ibus_connection_send (connection, reply); ibus_message_unref (reply); return TRUE; }