Exemple #1
0
gchar *
ibus_message_to_string (IBusMessage *message)
{
    g_assert (message != NULL);

    GString *string = g_string_new ("");

    IBusMessageIter iter;
    GType type;
    gint i = 0;

    g_string_append_printf (string,
                            "message: %d\n"
                            "\tdestination = %s\n"
                            "\tpath = %s\n"
                            "\tinterface = %s\n"
                            "\tmember = %s\n",
                            ibus_message_get_type (message),
                            ibus_message_get_destination (message),
                            ibus_message_get_path (message),
                            ibus_message_get_interface (message),
                            ibus_message_get_member (message));

    ibus_message_iter_init (message, &iter);
    while ((type = ibus_message_iter_get_arg_type (&iter)) != G_TYPE_INVALID) {
        g_string_append_printf (string, "\t\targ%d is %s\n", i++, g_type_name (type));
        ibus_message_iter_next (&iter);
    }

    return g_string_free (string, FALSE);
}
Exemple #2
0
static gboolean
_connection_ibus_signal_cb (IBusConnection *connection,
                            IBusMessage    *message,
                            IBusProxy      *proxy)
{
    IBusProxyPrivate *priv;
    priv = IBUS_PROXY_GET_PRIVATE (proxy);

    if (g_strcmp0 (ibus_message_get_path (message), priv->path) != 0)
        return FALSE;

    if (ibus_proxy_handle_signal (proxy, message)) {
        g_signal_stop_emission_by_name (connection, "ibus-signal");
        return TRUE;
    }

    return FALSE;
}
Exemple #3
0
gboolean
ibus_proxy_handle_signal (IBusProxy     *proxy,
                          DBusMessage   *message)
{
    g_assert (IBUS_IS_PROXY (proxy));
    g_assert (message != NULL);

    gboolean retval = FALSE;
    IBusProxyPrivate *priv;
    priv = IBUS_PROXY_GET_PRIVATE (proxy);

    if (ibus_message_is_signal (message, DBUS_SERVICE_DBUS, "NameOwnerChanged")) {
        gchar *name, *old_name, *new_name;
        IBusError *error;

        if (!ibus_message_get_args (message,
                                    &error,
                                    G_TYPE_STRING, &name,
                                    G_TYPE_STRING, &old_name,
                                    G_TYPE_STRING, &new_name,
                                    G_TYPE_INVALID)) {
            g_warning ("%s :%s", error->name, error->message);
            ibus_error_free (error);
        }

        if (g_strcmp0 (priv->unique_name, old_name) == 0) {
            ibus_object_destroy (IBUS_OBJECT (proxy));
            return FALSE;
        }
    }

    if (g_strcmp0 (ibus_message_get_path (message), priv->path) == 0) {
        g_signal_emit (proxy, proxy_signals[IBUS_SIGNAL], 0, message, &retval);
    }

    return retval;
}
Exemple #4
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;
}