Beispiel #1
0
static void
bus_dbus_impl_destroy (BusDBusImpl *dbus)
{
    GList *p;

    for (p = dbus->rules; p != NULL; p = p->next) {
        BusMatchRule *rule = BUS_MATCH_RULE (p->data);
        g_signal_handlers_disconnect_by_func (rule, _rule_destroy_cb, dbus);
        ibus_object_destroy ((IBusObject *) rule);
        g_object_unref (rule);
    }
    g_list_free (dbus->rules);
    dbus->rules = NULL;
    
    for (p = dbus->connections; p != NULL; p = p->next) {
        BusConnection *connection = BUS_CONNECTION (p->data);
        g_signal_handlers_disconnect_by_func (connection, _connection_destroy_cb, dbus);
        ibus_connection_close ((IBusConnection *) connection);
        ibus_object_destroy ((IBusObject *) connection);
        g_object_unref (connection);
    }
    g_list_free (dbus->connections);
    dbus->connections = NULL;

    g_hash_table_remove_all (dbus->unique_names);
    g_hash_table_remove_all (dbus->names);
    g_hash_table_remove_all (dbus->objects);

    dbus->unique_names = NULL;
    dbus->names = NULL;
    dbus->objects = NULL;

    G_OBJECT_CLASS(parent_class)->dispose (G_OBJECT (dbus));
}
Beispiel #2
0
void
bus_server_run (void)
{
    g_return_if_fail (server);

    /* create and run main loop */
    mainloop = g_main_loop_new (NULL, FALSE);
    g_main_loop_run (mainloop);

    /* bus_server_quit is called. stop server */
    g_dbus_server_stop (server);

    ibus_object_destroy ((IBusObject *)dbus);
    ibus_object_destroy ((IBusObject *)ibus);

    /* release resources */
    g_object_unref (server);
    g_main_loop_unref (mainloop);
    mainloop = NULL;
    g_free (address);
    address = NULL;

    /* When _ibus_exit() is called, bus_ibus_impl_destroy() needs
     * to be called so that waitpid() prevents the processes from
     * becoming the daemons. So we run execv() after
     * ibus_object_destroy(ibus) is called here. */
    if (_restart) {
        _restart_server ();

        /* should not reach here */
        g_assert_not_reached ();
    }
}
Beispiel #3
0
static void
ibus_bus_destroy (IBusObject *object)
{
    IBusBus *bus;
    IBusBusPrivate *priv;

    bus = IBUS_BUS (object);
    priv = IBUS_BUS_GET_PRIVATE (bus);

    if (priv->monitor) {
        g_object_unref (priv->monitor);
        priv->monitor = NULL;
    }

    if (priv->config) {
        ibus_object_destroy ((IBusObject *) priv->config);
        priv->config = NULL;
    }

    if (priv->connection) {
        ibus_object_destroy ((IBusObject *) priv->connection);
        priv->connection = NULL;
    }

    IBUS_OBJECT_CLASS (ibus_bus_parent_class)->destroy (object);
}
Beispiel #4
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);
}
Beispiel #5
0
BusFactoryProxy *
bus_registry_name_owner_changed (BusRegistry *registry,
                                 const gchar *name,
                                 const gchar *old_name,
                                 const gchar *new_name)
{
    g_assert (BUS_IS_REGISTRY (registry));
    g_assert (name);
    g_assert (old_name);
    g_assert (new_name);

    IBusComponent *component;
    BusFactoryProxy *factory;

    component = bus_registry_lookup_component_by_name (registry, name);

    if (component == NULL) {
        return NULL;
    }

    if (g_strcmp0 (old_name, "") != 0) {
        factory = bus_factory_proxy_get_from_component (component);

        if (factory != NULL) {
            ibus_object_destroy ((IBusObject *)factory);
        }
    }

    if (g_strcmp0 (new_name, "") != 0) {
        factory = bus_factory_proxy_new (component, NULL);
        return factory;
    }

    return NULL;
}
Beispiel #6
0
static void
_free_ic (gpointer data, gpointer user_data)
{
    X11IC *x11ic = (X11IC *) data;

    g_return_if_fail (x11ic != NULL);

    g_free (x11ic->preedit_string);

    if (x11ic->preedit_attrs) {
        g_object_unref (x11ic->preedit_attrs);
        x11ic->preedit_attrs = NULL;
    }

    if (x11ic->context) {
        ibus_object_destroy ((IBusObject *)x11ic->context);
        g_object_unref (x11ic->context);
        x11ic->context = NULL;
    }

    /* Remove the IC from g_client dictionary */
    g_hash_table_remove (_x11_ic_table,
                         GINT_TO_POINTER (x11ic->icid));

    g_slice_free (X11IC, x11ic);
}
Beispiel #7
0
static int
xim_destroy_ic (XIMS xims, IMChangeICStruct *call_data)
{
    X11IC *x11ic;

    LOG (1, "XIM_DESTROY_IC ic=%d connect_id=%d",
                call_data->icid, call_data->connect_id);

    x11ic = (X11IC *)g_hash_table_lookup (_x11_ic_table,
                                          GINT_TO_POINTER ((gint) call_data->icid));
    g_return_val_if_fail (x11ic != NULL, 0);

    if (x11ic->context) {
        ibus_object_destroy ((IBusObject *)x11ic->context);
        g_object_unref (x11ic->context);
        x11ic->context = NULL;
    }

    g_hash_table_remove (_x11_ic_table,
                         GINT_TO_POINTER ((gint) call_data->icid));
    x11ic->conn->clients = g_list_remove (x11ic->conn->clients, (gconstpointer)x11ic);

    g_free (x11ic->preedit_string);
    x11ic->preedit_string = NULL;

    if (x11ic->preedit_attrs) {
        g_object_unref (x11ic->preedit_attrs);
        x11ic->preedit_attrs = NULL;
    }

    g_slice_free (X11IC, x11ic);

    return 1;
}
Beispiel #8
0
static void
bus_server_destroy (BusServer *server)
{
    g_assert (BUS_IS_SERVER (server));

    ibus_object_destroy ((IBusObject *) server->dbus);
    g_object_unref (server->dbus);
    ibus_object_destroy ((IBusObject *) server->ibus);
    g_object_unref (server->ibus);

    while (g_main_loop_is_running (server->loop)) {
        g_main_loop_quit (server->loop);
    }
    g_main_loop_unref (server->loop);

    IBUS_OBJECT_CLASS (bus_server_parent_class)->destroy (IBUS_OBJECT (server));
}
Beispiel #9
0
static void
_connection_destroy_cb (IBusConnection  *connection,
                        IBusProxy       *proxy)
{
    IBusProxyPrivate *priv;
    priv = IBUS_PROXY_GET_PRIVATE (proxy);

    g_assert (priv->connection == connection);

    g_object_unref (connection);
    priv->connection = NULL;

    ibus_object_destroy ((IBusObject *) proxy);
}
Beispiel #10
0
/**
 * bus_new_connection_cb:
 * @user_data: always NULL.
 * @returns: TRUE when the function can handle the connection.
 *
 * Handle incoming connections.
 */
static gboolean
bus_new_connection_cb (GDBusServer     *server,
                       GDBusConnection *dbus_connection,
                       gpointer         user_data)
{
    BusConnection *connection = bus_connection_new (dbus_connection);
    bus_dbus_impl_new_connection (dbus, connection);

    if (g_object_is_floating (connection)) {
        /* bus_dbus_impl_new_connection couldn't handle the connection. just delete the connection and return TRUE
         * (so that other connection handler will not handle the deleted connection.) */
        ibus_object_destroy ((IBusObject *)connection);
        g_object_unref (connection);
    }
    return TRUE;
}
Beispiel #11
0
static void
ibus_bus_connect (IBusBus *bus)
{
    IBusBusPrivate *priv;
    priv = IBUS_BUS_GET_PRIVATE (bus);

    /* destry old connection at first */
    if (priv->connection != NULL) {
        ibus_object_destroy ((IBusObject *)priv->connection);
        g_assert (priv->connection == NULL);
    }

    if (ibus_get_address () != NULL) {
        priv->connection = ibus_connection_open (ibus_get_address ());
    }

    if (priv->connection) {
        ibus_bus_hello (bus);

        g_signal_connect (priv->connection,
                          "destroy",
                          (GCallback) _connection_destroy_cb,
                          bus);
        g_signal_emit (bus, bus_signals[CONNECTED], 0);

        if (priv->watch_dbus_signal) {
            ibus_bus_watch_dbus_signal (bus);
        }

        /** Watch ibus signals. */
        const gchar *rule =
            "type='signal',"
            "path='" IBUS_PATH_IBUS "',"
            "interface='" IBUS_INTERFACE_IBUS "'";

        ibus_bus_add_match (bus, rule);
        g_signal_connect (priv->connection,
                          "ibus-signal",
                          (GCallback) _connection_ibus_signal_cb,
                          bus);
    }
}
Beispiel #12
0
static void
ibus_bus_connect (IBusBus *bus)
{
    IBusBusPrivate *priv;
    priv = IBUS_BUS_GET_PRIVATE (bus);

#if 0
    socket_path = ibus_get_socket_path ();

    if (stat (socket_path, &buf) != 0) {
        g_warning ("Can not get stat from %s!", socket_path);
        return;
    }
    if (buf.st_uid != ibus_get_daemon_uid ()) {
        g_warning ("The owner of %s is not %s!", socket_path, ibus_get_user_name ());
        return;
    }

    if (priv->connection != NULL) {
        ibus_object_destroy ((IBusObject *) priv->connection);
    }
#endif
    if (ibus_get_address () != NULL) {
        priv->connection = ibus_connection_open (ibus_get_address ());
    }

    if (priv->connection) {
        ibus_bus_hello (bus);
        g_signal_connect (priv->connection,
                          "destroy",
                          (GCallback) _connection_destroy_cb,
                          bus);
        g_signal_emit (bus, bus_signals[CONNECTED], 0);

        if (priv->watch_dbus_signal) {
            ibus_bus_watch_dbus_signal (bus);
        }
    }
}
Beispiel #13
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;
}
Beispiel #14
0
static void
ibus_connection_disconnected (IBusConnection         *connection)
{
    ibus_object_destroy (IBUS_OBJECT (connection));
}
Beispiel #15
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 #16
0
BusEngineProxy *
bus_factory_proxy_create_engine (BusFactoryProxy *factory,
                                 IBusEngineDesc  *desc)
{
    g_assert (BUS_IS_FACTORY_PROXY (factory));
    g_assert (IBUS_IS_ENGINE_DESC (desc));

    IBusPendingCall *pending = NULL;
    IBusMessage *reply_message;
    IBusError *error;
    BusEngineProxy *engine;
    gchar *object_path;
    gboolean retval;

    if (g_list_find (factory->component->engines, desc) == NULL) {
        return NULL;
    }

    retval = ibus_proxy_call_with_reply ((IBusProxy *) factory,
                                         "CreateEngine",
                                         &pending,
                                         g_dbus_timeout,
                                         &error,
                                         G_TYPE_STRING, &(desc->name),
                                         G_TYPE_INVALID);

    if (!retval) {
        g_warning ("%s: %s", error->name, error->message);
        ibus_error_free (error);
        return NULL;
    }

    ibus_pending_call_wait (pending);
    reply_message = ibus_pending_call_steal_reply (pending);
    ibus_pending_call_unref (pending);

    if (reply_message == NULL) {
        IBusObject *connection;
        connection = (IBusObject *) ibus_proxy_get_connection ((IBusProxy *)factory);
        ibus_object_destroy (connection);
        g_warning ("%s: %s", error->name, error->message);
        ibus_error_free (error);
        return NULL;
    }

    if ((error = ibus_error_new_from_message (reply_message)) != NULL) {
        if (g_strcmp0 (error->name, DBUS_ERROR_NO_REPLY) == 0) {
            IBusObject *connection;
            connection = (IBusObject *) ibus_proxy_get_connection ((IBusProxy *)factory);
            ibus_object_destroy (connection);
        }
        g_warning ("%s: %s", error->name, error->message);
        ibus_error_free (error);
        ibus_message_unref (reply_message);
        return NULL;
    }

    if (!ibus_message_get_args (reply_message,
                                &error,
                                IBUS_TYPE_OBJECT_PATH, &object_path,
                                G_TYPE_INVALID)) {
        g_warning ("%s: %s", error->name, error->message);
        ibus_error_free (error);
        ibus_message_unref (reply_message);

        return NULL;
    }

    IBusConnection *connection = ibus_proxy_get_connection ((IBusProxy *) factory);
    engine = bus_engine_proxy_new (object_path, desc, (BusConnection *) connection);
    ibus_message_unref (reply_message);

    return engine;
}