Example #1
0
IBusEngineDesc *
ibus_input_context_get_engine (IBusInputContext *context)
{
    g_assert (IBUS_IS_INPUT_CONTEXT (context));
    IBusMessage *reply_message;
    IBusError *error = NULL;
    IBusSerializable *object = NULL;

    reply_message = ibus_proxy_call_with_reply_and_block ((IBusProxy *) context,
                                                          "GetEngine",
                                                          -1,
                                                          &error,
                                                          G_TYPE_INVALID);
    if (!reply_message) {
        g_debug ("%s: %s", error->name, error->message);
        ibus_error_free (error);
        return NULL;
    }

    if (!ibus_message_get_args (reply_message,
                                &error,
                                IBUS_TYPE_ENGINE_DESC, &object,
                                G_TYPE_INVALID)) {
        g_debug ("%s: %s", error->name, error->message);
        ibus_error_free (error);
        ibus_message_unref (reply_message);
        return NULL;
    }
    ibus_message_unref (reply_message);

    return IBUS_ENGINE_DESC (object);
}
Example #2
0
File: ibusbus.c Project: BBIO/ibus
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;
}
Example #3
0
File: ibusbus.c Project: BBIO/ibus
gboolean
ibus_bus_register_component (IBusBus       *bus,
                             IBusComponent *component)
{
    g_assert (IBUS_IS_BUS (bus));
    g_assert (IBUS_IS_COMPONENT (component));

    gboolean result;

    result = ibus_bus_call (bus,
                            IBUS_SERVICE_IBUS,
                            IBUS_PATH_IBUS,
                            IBUS_INTERFACE_IBUS,
                            "RegisterComponent",
                            IBUS_TYPE_COMPONENT, &component,
                            G_TYPE_INVALID,
                            G_TYPE_INVALID);

    return result;


#if 0
    IBusMessage *message, *reply;
    IBusError *error;

    IBusBusPrivate *priv;
    priv = IBUS_BUS_GET_PRIVATE (bus);

    message = ibus_message_new_method_call (IBUS_SERVICE_IBUS,
                                            IBUS_PATH_IBUS,
                                            IBUS_INTERFACE_IBUS,
                                            "RegisterComponent");

    ibus_message_append_args (message,
                              IBUS_TYPE_COMPONENT, &component,
                              G_TYPE_INVALID);

    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_from_message (reply)) != NULL) {
        g_warning ("%s : %s", error->name, error->message);
        ibus_error_free (error);
        ibus_message_unref (reply);
        return FALSE;
    }

    return TRUE;
#endif
}
Example #4
0
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;
}
Example #5
0
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;
}
Example #6
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);
}
Example #7
0
gboolean
ibus_bus_get_use_global_engine (IBusBus *bus)
{
    g_assert (IBUS_IS_BUS (bus));

    IBusMessage *reply = NULL;
    IBusError *error = NULL;
    gboolean use_global_engine = FALSE;

    reply = ibus_bus_call_with_reply (bus,
                                      IBUS_SERVICE_IBUS,
                                      IBUS_PATH_IBUS,
                                      IBUS_INTERFACE_IBUS,
                                      "GetUseGlobalEngine",
                                      G_TYPE_INVALID);
    if (reply) {
        if (!ibus_message_get_args (reply, &error, G_TYPE_BOOLEAN,
                                    &use_global_engine, G_TYPE_INVALID)) {
            g_warning ("%s: %s", error->name, error->message);
            ibus_error_free (error);
        }

        ibus_message_unref (reply);
    }

    return use_global_engine;
}
Example #8
0
gchar *
ibus_bus_get_name_owner (IBusBus        *bus,
                         const gchar    *name)
{
    g_assert (IBUS_IS_BUS (bus));

    gchar *owner = NULL;
    IBusMessage *reply = NULL;
    IBusError *error = NULL;

    reply = ibus_bus_call_with_reply (bus,
                                      DBUS_SERVICE_DBUS,
                                      DBUS_PATH_DBUS,
                                      DBUS_INTERFACE_DBUS,
                                      "GetNameOwner",
                                      G_TYPE_STRING, &name,
                                      G_TYPE_INVALID);

    if (reply) {
        if (ibus_message_get_args (reply, &error, G_TYPE_STRING, &owner,
                                   G_TYPE_INVALID)) {
            owner = g_strdup (owner);
        } else {
            g_warning ("%s: %s", error->name, error->message);
            ibus_error_free (error);
        }

        ibus_message_unref (reply);
    }

    return owner;
}
Example #9
0
gboolean
ibus_bus_name_has_owner (IBusBus        *bus,
                         const gchar    *name)
{
    g_assert (IBUS_IS_BUS (bus));

    IBusMessage *reply = NULL;
    IBusError *error = NULL;
    gboolean retval = FALSE;

    reply = ibus_bus_call_with_reply (bus,
                                      DBUS_SERVICE_DBUS,
                                      DBUS_PATH_DBUS,
                                      DBUS_INTERFACE_DBUS,
                                      "NameHasOwner",
                                      G_TYPE_STRING, &name,
                                      G_TYPE_INVALID);

    if (reply) {
        if (!ibus_message_get_args (reply, &error, G_TYPE_BOOLEAN, &retval,
                                    G_TYPE_INVALID)) {
            g_warning ("%s: %s", error->name, error->message);
            ibus_error_free (error);
        }

        ibus_message_unref (reply);
    }

    return retval;
}
Example #10
0
guint
ibus_bus_release_name (IBusBus      *bus,
                       const gchar  *name)
{
    g_assert (IBUS_IS_BUS (bus));

    IBusMessage *reply = NULL;
    IBusError *error = NULL;
    guint retval = 0;

    reply = ibus_bus_call_with_reply (bus,
                                      DBUS_SERVICE_DBUS,
                                      DBUS_PATH_DBUS,
                                      DBUS_INTERFACE_DBUS,
                                      "ReleaseName",
                                      G_TYPE_STRING, &name,
                                      G_TYPE_INVALID);

    if (reply) {
        if (!ibus_message_get_args (reply, &error, G_TYPE_UINT, &retval,
                                    G_TYPE_INVALID)) {
            g_warning ("%s: %s", error->name, error->message);
            ibus_error_free (error);
        }

        ibus_message_unref (reply);
    }

    return retval;
}
Example #11
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;
}
Example #12
0
gchar *
ibus_bus_current_input_context(IBusBus      *bus)
{
    g_assert (IBUS_IS_BUS (bus));
    g_return_val_if_fail (ibus_bus_is_connected (bus), NULL);

    gchar *path = NULL;
    IBusMessage *reply = NULL;
    IBusError *error = NULL;

    reply = ibus_bus_call_with_reply (bus,
                                      IBUS_SERVICE_IBUS,
                                      IBUS_PATH_IBUS,
                                      IBUS_INTERFACE_IBUS,
                                      "CurrentInputContext",
                                      G_TYPE_INVALID);

    if (reply) {
        if (ibus_message_get_args (reply, &error,
                                   IBUS_TYPE_OBJECT_PATH, &path,
                                   G_TYPE_INVALID)) {
            path = g_strdup (path);
        } else {
            g_warning ("%s: %s", error->name, error->message);
            ibus_error_free (error);
        }

        ibus_message_unref (reply);
    }

    return path;
}
Example #13
0
IBusEngineDesc *
ibus_bus_get_global_engine (IBusBus *bus)
{
    g_assert (IBUS_IS_BUS (bus));

    IBusMessage *reply = NULL;
    IBusError *error = NULL;
    IBusEngineDesc *global_engine = NULL;

    reply = ibus_bus_call_with_reply (bus,
                                      IBUS_SERVICE_IBUS,
                                      IBUS_PATH_IBUS,
                                      IBUS_INTERFACE_IBUS,
                                      "GetGlobalEngine",
                                      G_TYPE_INVALID);
    if (reply) {
        if (!ibus_message_get_args (reply, &error, IBUS_TYPE_ENGINE_DESC,
                                    &global_engine, G_TYPE_INVALID)) {
            g_warning ("%s: %s", error->name, error->message);
            ibus_error_free (error);
        }

        ibus_message_unref (reply);
    }

    return global_engine;
}
Example #14
0
gboolean
ibus_connection_call (IBusConnection     *connection,
                      const gchar        *name,
                      const gchar        *path,
                      const gchar        *interface,
                      const gchar        *member,
                      IBusError          **error,
                      GType              first_arg_type,
                      ...)
{
    IBusMessage *reply;
    va_list va_args;

    va_start (va_args, first_arg_type);
    reply = ibus_connection_call_with_reply_valist (
        connection, name, path, interface, member, error,
        first_arg_type, va_args);
    va_end (va_args);

    if (reply) {
      ibus_message_unref (reply);
      return TRUE;
    }

    return FALSE;
}
Example #15
0
static void
bus_dbus_impl_name_owner_changed (BusDBusImpl   *dbus,
                                  gchar         *name,
                                  gchar         *old_name,
                                  gchar         *new_name)
{
    g_assert (BUS_IS_DBUS_IMPL (dbus));
    g_assert (name != NULL);
    g_assert (old_name != NULL);
    g_assert (new_name != NULL);

    IBusMessage *message;

    message = ibus_message_new_signal (DBUS_PATH_DBUS,
                                       DBUS_INTERFACE_DBUS,
                                       "NameOwnerChanged");
    ibus_message_append_args (message,
                              G_TYPE_STRING, &name,
                              G_TYPE_STRING, &old_name,
                              G_TYPE_STRING, &new_name,
                              G_TYPE_INVALID);
    ibus_message_set_sender (message, DBUS_SERVICE_DBUS);

    bus_dbus_impl_dispatch_message_by_rule (dbus, message, NULL);

    ibus_message_unref (message);

}
Example #16
0
gboolean
ibus_input_context_is_enabled (IBusInputContext *context)
{
    g_assert (IBUS_IS_INPUT_CONTEXT (context));
    gboolean retval = FALSE;

    IBusMessage *reply_message;
    IBusError *error = NULL;

    reply_message = ibus_proxy_call_with_reply_and_block ((IBusProxy *) context,
                                                          "IsEnabled",
                                                          -1,
                                                          &error,
                                                          G_TYPE_INVALID);
    if (!reply_message) {
        g_debug ("%s: %s", error->name, error->message);
        ibus_error_free (error);
        return FALSE;
    }

    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;
}
Example #17
0
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, &section,
                                                  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;
}
Example #18
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;
}
Example #19
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;
}
Example #20
0
gboolean
ibus_proxy_call_with_reply (IBusProxy        *proxy,
                            const gchar      *method,
                            IBusPendingCall **pending,
                            gint              timeout_milliseconds,
                            IBusError       **error,
                            GType             first_arg_type,
                            ...)
{
    g_assert (IBUS_IS_PROXY (proxy));
    g_assert (pending != NULL);
    g_assert (method != NULL);

    va_list args;
    gboolean retval;
    DBusMessage *message;

    IBusProxyPrivate *priv;
    priv = IBUS_PROXY_GET_PRIVATE (proxy);

    if (priv->connection == NULL || !ibus_connection_is_connected (priv->connection)) {
        if (error) {
            *error = ibus_error_new_from_printf (DBUS_ERROR_DISCONNECTED,
                                                 "Connection of %s was disconnected.",
                                                 G_OBJECT_TYPE_NAME (proxy));
        }
        return 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);
    va_end (args);

    *pending = NULL;
    retval = ibus_connection_send_with_reply (priv->connection,
                                              message,
                                              pending,
                                              timeout_milliseconds);
    ibus_message_unref (message);

    if (!retval && error != NULL) {
        *error = ibus_error_new_from_printf (DBUS_ERROR_NO_MEMORY, "");
    }

    return retval;
}
Example #21
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;
}
Example #22
0
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);
}
Example #23
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;
}
Example #24
0
const gchar *
ibus_bus_hello (IBusBus *bus)
{
    g_assert (IBUS_IS_BUS (bus));

    gchar *unique_name = NULL;
    IBusMessage *reply = NULL;
    IBusError *error = NULL;
    IBusBusPrivate *priv;

    priv = IBUS_BUS_GET_PRIVATE (bus);

    g_free (priv->unique_name);
    priv->unique_name = NULL;

    reply = ibus_bus_call_with_reply (bus,
                                      DBUS_SERVICE_DBUS,
                                      DBUS_PATH_DBUS,
                                      DBUS_INTERFACE_DBUS,
                                      "Hello",
                                      G_TYPE_INVALID);

    if (reply) {
        if (ibus_message_get_args (reply, &error, G_TYPE_STRING, &unique_name,
                                   G_TYPE_INVALID)) {
            priv->unique_name = g_strdup (unique_name);
        } else {
            g_warning ("%s: %s", error->name, error->message);
            ibus_error_free (error);
        }

        ibus_message_unref (reply);
    }

    return priv->unique_name;
}
Example #25
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);
}
Example #26
0
File: ibusbus.c Project: BBIO/ibus
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;
}
Example #27
0
File: ibusbus.c Project: BBIO/ibus
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;
}
Example #28
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;
}
Example #29
0
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;
}
Example #30
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;
}