Beispiel #1
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;
}
Beispiel #2
0
void
bus_dbus_impl_dispatch_message (BusDBusImpl  *dbus,
                                IBusMessage  *message)
{
    g_assert (BUS_IS_DBUS_IMPL (dbus));
    g_assert (message != NULL);

    const gchar *destination;
    BusConnection *dest_connection = NULL;

    if (G_UNLIKELY (IBUS_OBJECT_DESTROYED (dbus))) {
        return;
    }

    destination = ibus_message_get_destination (message);

    if (destination != NULL) {
        dest_connection = bus_dbus_impl_get_connection_by_name (dbus, destination);

        if (dest_connection != NULL) {
            ibus_connection_send (IBUS_CONNECTION (dest_connection), message);
        }
        else {
            IBusMessage *reply_message;
            reply_message = ibus_message_new_error_printf (message,
                                                     DBUS_ERROR_SERVICE_UNKNOWN,
                                                     "Can not find service %s",
                                                     destination);
            bus_dbus_impl_dispatch_message (dbus, reply_message);
            ibus_message_unref (reply_message);
        }
    }

    bus_dbus_impl_dispatch_message_by_rule (dbus, message, dest_connection);
}
Beispiel #3
0
static IBusMessage *
_dbus_request_name (BusDBusImpl     *dbus,
                    IBusMessage     *message,
                    BusConnection   *connection)
{
    IBusMessage *reply_message;
    IBusError *error;
    gchar *name;
    guint flags;
    guint retval;

    if (!ibus_message_get_args (message,
                                &error,
                                G_TYPE_STRING, &name,
                                G_TYPE_UINT, &flags,
                                G_TYPE_INVALID)) {
        reply_message = ibus_message_new_error (message,
                                                error->name,
                                                error->message);
        ibus_error_free (error);
        return reply_message;
    }

    if (g_hash_table_lookup (dbus->names, name) != NULL) {
        reply_message = ibus_message_new_error_printf (message,
                                                       DBUS_ERROR_FAILED,
                                                       "Name %s has owner",
                                                       name);
        return reply_message;
    }

    retval = 1;
    g_hash_table_insert (dbus->names,
                         (gpointer )bus_connection_add_name (connection, name),
                         connection);
    reply_message = ibus_message_new_method_return (message);
    ibus_message_append_args (reply_message,
                              G_TYPE_UINT, &retval,
                              G_TYPE_INVALID);

    ibus_connection_send ((IBusConnection *) connection, reply_message);
    ibus_message_unref (reply_message);
    ibus_connection_flush ((IBusConnection *) connection);

    g_signal_emit (dbus,
                   dbus_signals[NAME_OWNER_CHANGED],
                   0,
                   name,
                   "",
                   bus_connection_get_unique_name (connection));

    return NULL;
}
Beispiel #4
0
static gboolean
ibus_service_ibus_message (IBusService    *service,
                           IBusConnection *connection,
                           IBusMessage    *message)
{
    if (ibus_message_is_method_call (message, "", "Destroy")) {
        IBusMessage *reply;
        reply = ibus_message_new_method_return (message);
        ibus_connection_send (connection, reply);
        ibus_message_unref (reply);
        return TRUE;
    }
    return FALSE;
}
Beispiel #5
0
void
bus_dbus_impl_dispatch_message_by_rule (BusDBusImpl     *dbus,
                                        IBusMessage     *message,
                                        BusConnection   *skip_connection)
{
    g_assert (BUS_IS_DBUS_IMPL (dbus));
    g_assert (message != NULL);
    g_assert (BUS_IS_CONNECTION (skip_connection) || skip_connection == NULL);

    GList *recipients = NULL;
    GList *link = NULL;

    static gint32 data_slot = -1;

    if (G_UNLIKELY (IBUS_OBJECT_DESTROYED (dbus))) {
        return;
    }

    if (data_slot == -1) {
        dbus_message_allocate_data_slot (&data_slot);
    }

    /* If this message has been dispatched by rule, it will be ignored. */
    if (dbus_message_get_data (message, data_slot) != NULL)
        return;

    dbus_message_set_data (message, data_slot, (gpointer) TRUE, NULL);

#if 0
    if (g_strcmp0 (ibus_message_get_member (message), "ValueChanged") == 0) {
        g_debug ("Dispatch ValueChanged");
    }
#endif

    for (link = dbus->rules; link != NULL; link = link->next) {
        GList *list = bus_match_rule_get_recipients (BUS_MATCH_RULE (link->data),
                                                     message);
        recipients = g_list_concat (recipients, list);
    }

    for (link = recipients; link != NULL; link = link->next) {
        BusConnection *connection = BUS_CONNECTION (link->data);
        if (connection != skip_connection) {
            ibus_connection_send (IBUS_CONNECTION (connection), message);
        }
        g_object_unref (connection);
    }
    g_list_free (recipients);
}
Beispiel #6
0
gboolean
ibus_proxy_send (IBusProxy      *proxy,
                 DBusMessage    *message)
{
    g_assert (IBUS_IS_PROXY (proxy));
    g_assert (message != NULL);

    IBusProxyPrivate *priv;
    priv = IBUS_PROXY_GET_PRIVATE (proxy);

    g_return_val_if_fail (priv->connection, FALSE);
    g_return_val_if_fail (ibus_connection_is_connected (priv->connection), FALSE);

    return ibus_connection_send (priv->connection, message);
}
Beispiel #7
0
static IBusMessage *
_dbus_hello (BusDBusImpl    *dbus,
             IBusMessage    *message,
             BusConnection  *connection)
{
    IBusMessage *reply_message;

    if (bus_connection_get_unique_name (connection) != NULL) {
        reply_message = ibus_message_new_error (message,
                                                DBUS_ERROR_FAILED,
                                                "Already handled an Hello message");
    }
    else {
        gchar *name;

        name = g_strdup_printf (":1.%d", dbus->id ++);
        bus_connection_set_unique_name (connection, name);
        g_free (name);

        name = (gchar *) bus_connection_get_unique_name (connection);
        g_hash_table_insert (dbus->unique_names, name, connection);

        reply_message = ibus_message_new_method_return (message);
        ibus_message_append_args (reply_message,
                                  G_TYPE_STRING, &name,
                                  G_TYPE_INVALID);

        ibus_connection_send ((IBusConnection *) connection, reply_message);
        ibus_message_unref (reply_message);
        ibus_connection_flush ((IBusConnection *) connection);
        reply_message = NULL;

        g_signal_emit (dbus,
                       dbus_signals[NAME_OWNER_CHANGED],
                       0,
                       name,
                       "",
                       name);

    }

    return reply_message;
}
Beispiel #8
0
gboolean
ibus_proxy_call (IBusProxy      *proxy,
                 const gchar    *method,
                 GType           first_arg_type,
                 ...)
{
    g_assert (IBUS_IS_PROXY (proxy));
    g_assert (method != NULL);

    va_list args;
    gboolean retval;
    DBusMessage *message;

    IBusProxyPrivate *priv;
    priv = IBUS_PROXY_GET_PRIVATE (proxy);

    g_return_val_if_fail (priv->connection, FALSE);
    g_return_val_if_fail (ibus_connection_is_connected (priv->connection), FALSE);

    message = ibus_message_new_method_call (priv->name,
                                            priv->path,
                                            priv->interface,
                                            method);
    va_start (args, first_arg_type);
    retval = ibus_message_append_args_valist (message,
                                              first_arg_type,
                                              args);
    if (!retval) {
        ibus_message_unref (message);
        g_return_val_if_reached (FALSE);
    }

    va_end (args);

    retval = ibus_connection_send (priv->connection, message);

    ibus_message_unref (message);

    return retval;
}
Beispiel #9
0
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, &section,
                                        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, &section,
                                        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);
}
Beispiel #10
0
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;
}
Beispiel #11
0
static gboolean
_connection_ibus_message_cb (BusConnection  *connection,
                             IBusMessage    *message,
                             BusDBusImpl    *dbus)
{
    g_assert (BUS_IS_CONNECTION (connection));
    g_assert (message != NULL);
    g_assert (BUS_IS_DBUS_IMPL (dbus));

    const gchar *dest;

    if (G_UNLIKELY (IBUS_OBJECT_DESTROYED (dbus))) {
        return;
    }
    
    if (ibus_message_is_signal (message,
                                DBUS_INTERFACE_LOCAL,
                                "Disconnected")) {
        /* ignore signal from local interface */
        return FALSE;
    }

    ibus_message_set_sender (message, bus_connection_get_unique_name (connection));

    switch (ibus_message_get_type (message)) {
#if 1
    case DBUS_MESSAGE_TYPE_ERROR:
        g_debug ("From :%s to %s, Error: %s : %s",
                 ibus_message_get_sender (message),
                 ibus_message_get_destination (message),
                 ibus_message_get_error_name (message),
                 ibus_message_get_error_message (message));
        break;
#endif
#if 0
    case DBUS_MESSAGE_TYPE_SIGNAL:
        g_debug ("From :%s to %s, Signal: %s @ %s",
                 ibus_message_get_sender (message),
                 ibus_message_get_destination (message),
                 ibus_message_get_member (message),
                 ibus_message_get_path (message)
                 );
        break;
#endif
#if 0
    case DBUS_MESSAGE_TYPE_METHOD_CALL:
        g_debug("From %s to %s, Method %s on %s",
                ibus_message_get_sender (message),
                ibus_message_get_destination (message),
                ibus_message_get_path (message),
                ibus_message_get_member (message));
        break;
#endif
    }

    dest = ibus_message_get_destination (message);

    if (dest == NULL ||
        strcmp ((gchar *)dest, IBUS_SERVICE_IBUS) == 0 ||
        strcmp ((gchar *)dest, DBUS_SERVICE_DBUS) == 0) {
        /* this message is sent to ibus-daemon */

        switch (ibus_message_get_type (message)) {
        case DBUS_MESSAGE_TYPE_SIGNAL:
        case DBUS_MESSAGE_TYPE_METHOD_RETURN:
        case DBUS_MESSAGE_TYPE_ERROR:
            bus_dbus_impl_dispatch_message_by_rule (dbus, message, NULL);
            return FALSE;
        case DBUS_MESSAGE_TYPE_METHOD_CALL:
            {
                const gchar *path;
                IBusService *object;

                path = ibus_message_get_path (message);

                object = g_hash_table_lookup (dbus->objects, path);

                if (object == NULL ||
                    ibus_service_handle_message (object,
                                                 (IBusConnection *) connection,
                                                 message) == FALSE) {
                    IBusMessage *error;
                    error = ibus_message_new_error_printf (message,
                                                           DBUS_ERROR_UNKNOWN_METHOD,
                                                           "Unknown method %s on %s",
                                                           ibus_message_get_member (message),
                                                           path);
                    ibus_connection_send ((IBusConnection *) connection, error);
                    ibus_message_unref (error);
                }

                /* dispatch message */
                bus_dbus_impl_dispatch_message_by_rule (dbus, message, NULL);
            }
            break;
        default:
            g_assert (FALSE);
        }
    }
    else {
        /* If the destination is not IBus or DBus, the message will be forwanded. */
        bus_dbus_impl_dispatch_message (dbus, message);
    }

    g_signal_stop_emission_by_name (connection, "ibus-message");
    return TRUE;
}
Beispiel #12
0
static gboolean
bus_dbus_impl_ibus_message (BusDBusImpl  *dbus,
                            BusConnection   *connection,
                            IBusMessage     *message)
{
    g_assert (BUS_IS_DBUS_IMPL (dbus));
    g_assert (BUS_IS_CONNECTION (connection));
    g_assert (message != NULL);

    gint i;
    IBusMessage *reply_message = NULL;

    static const struct {
        const gchar *interface;
        const gchar *name;
        IBusMessage *(* handler) (BusDBusImpl *, IBusMessage *, BusConnection *);
    } handlers[] =  {
        /* Introspectable interface */
        { DBUS_INTERFACE_INTROSPECTABLE,
                               "Introspect", _dbus_introspect },
        /* DBus interface */
        { DBUS_INTERFACE_DBUS, "Hello",     _dbus_hello },
        { DBUS_INTERFACE_DBUS, "ListNames", _dbus_list_names },
        { DBUS_INTERFACE_DBUS, "ListActivatableNames",
                                            _dbus_no_implement },
        { DBUS_INTERFACE_DBUS, "NameHasOwner",
                                            _dbus_name_has_owner },
        { DBUS_INTERFACE_DBUS, "StartServiceByName",
                                            _dbus_no_implement },
        { DBUS_INTERFACE_DBUS, "GetNameOwner",
                                            _dbus_get_name_owner },
        { DBUS_INTERFACE_DBUS, "GetConnectionUnixUser",
                                            _dbus_no_implement },
        { DBUS_INTERFACE_DBUS, "AddMatch",  _dbus_add_match },
        { DBUS_INTERFACE_DBUS, "RemoveMatch",
                                            _dbus_remove_match },
        { DBUS_INTERFACE_DBUS, "GetId",     _dbus_get_id },
        { DBUS_INTERFACE_DBUS, "RequestName", _dbus_request_name },
        { DBUS_INTERFACE_DBUS, "ReleaseName", _dbus_release_name },
        { NULL, NULL, NULL }
    };

    ibus_message_set_destination (message, DBUS_SERVICE_DBUS);

    for (i = 0; handlers[i].interface != NULL; i++) {
        if (ibus_message_is_method_call (message,
                                         handlers[i].interface,
                                         handlers[i].name)) {

            reply_message = handlers[i].handler (dbus, message, connection);
            if (reply_message) {

                ibus_message_set_sender (reply_message, DBUS_SERVICE_DBUS);
                ibus_message_set_destination (reply_message,
                                              bus_connection_get_unique_name (connection));
                ibus_message_set_no_reply (reply_message, TRUE);

                ibus_connection_send (IBUS_CONNECTION (connection), reply_message);
                ibus_message_unref (reply_message);
            }

            g_signal_stop_emission_by_name (dbus, "ibus-message");
            return TRUE;
        }
    }

    return parent_class->ibus_message ((IBusService *) dbus,
                                       (IBusConnection *) connection,
                                       message);
}
Beispiel #13
0
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;
}
Beispiel #14
0
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);
}