Kill connection in context service
This commit is contained in:
		@ -40,7 +40,6 @@
 | 
				
			|||||||
enum {
 | 
					enum {
 | 
				
			||||||
    PROP_0,
 | 
					    PROP_0,
 | 
				
			||||||
    PROP_OBJECT_PATH,
 | 
					    PROP_OBJECT_PATH,
 | 
				
			||||||
    PROP_CONNECTION,
 | 
					 | 
				
			||||||
    PROP_CLIENT_NAME,
 | 
					    PROP_CLIENT_NAME,
 | 
				
			||||||
    PROP_KEYBOARD,
 | 
					    PROP_KEYBOARD,
 | 
				
			||||||
    PROP_VISIBLE,
 | 
					    PROP_VISIBLE,
 | 
				
			||||||
@ -61,7 +60,6 @@ static guint signals[LAST_SIGNAL] = { 0, };
 | 
				
			|||||||
    (G_TYPE_INSTANCE_GET_PRIVATE ((obj), EEKBOARD_TYPE_CONTEXT_SERVICE, EekboardContextServicePrivate))
 | 
					    (G_TYPE_INSTANCE_GET_PRIVATE ((obj), EEKBOARD_TYPE_CONTEXT_SERVICE, EekboardContextServicePrivate))
 | 
				
			||||||
 | 
					
 | 
				
			||||||
struct _EekboardContextServicePrivate {
 | 
					struct _EekboardContextServicePrivate {
 | 
				
			||||||
    GDBusConnection *connection;
 | 
					 | 
				
			||||||
    GDBusNodeInfo *introspection_data;
 | 
					    GDBusNodeInfo *introspection_data;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    guint registration_id;
 | 
					    guint registration_id;
 | 
				
			||||||
@ -204,9 +202,6 @@ eekboard_context_service_real_show_keyboard (EekboardContextService *self)
 | 
				
			|||||||
{
 | 
					{
 | 
				
			||||||
    gboolean visible = self->priv->visible;
 | 
					    gboolean visible = self->priv->visible;
 | 
				
			||||||
    self->priv->visible = TRUE;
 | 
					    self->priv->visible = TRUE;
 | 
				
			||||||
    if (visible != self->priv->visible)
 | 
					 | 
				
			||||||
        emit_visibility_changed_signal (self,
 | 
					 | 
				
			||||||
                                        self->priv->visible);
 | 
					 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
static void
 | 
					static void
 | 
				
			||||||
@ -214,9 +209,6 @@ eekboard_context_service_real_hide_keyboard (EekboardContextService *self)
 | 
				
			|||||||
{
 | 
					{
 | 
				
			||||||
    gboolean visible = self->priv->visible;
 | 
					    gboolean visible = self->priv->visible;
 | 
				
			||||||
    self->priv->visible = FALSE;
 | 
					    self->priv->visible = FALSE;
 | 
				
			||||||
    if (visible != self->priv->visible)
 | 
					 | 
				
			||||||
        emit_visibility_changed_signal (self,
 | 
					 | 
				
			||||||
                                        self->priv->visible);
 | 
					 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
static void
 | 
					static void
 | 
				
			||||||
@ -226,7 +218,6 @@ eekboard_context_service_set_property (GObject      *object,
 | 
				
			|||||||
                                       GParamSpec   *pspec)
 | 
					                                       GParamSpec   *pspec)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    EekboardContextService *context = EEKBOARD_CONTEXT_SERVICE(object);
 | 
					    EekboardContextService *context = EEKBOARD_CONTEXT_SERVICE(object);
 | 
				
			||||||
    GDBusConnection *connection;
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
    switch (prop_id) {
 | 
					    switch (prop_id) {
 | 
				
			||||||
    case PROP_OBJECT_PATH:
 | 
					    case PROP_OBJECT_PATH:
 | 
				
			||||||
@ -234,12 +225,6 @@ eekboard_context_service_set_property (GObject      *object,
 | 
				
			|||||||
            g_free (context->priv->object_path);
 | 
					            g_free (context->priv->object_path);
 | 
				
			||||||
        context->priv->object_path = g_value_dup_string (value);
 | 
					        context->priv->object_path = g_value_dup_string (value);
 | 
				
			||||||
        break;
 | 
					        break;
 | 
				
			||||||
    case PROP_CONNECTION:
 | 
					 | 
				
			||||||
        connection = g_value_get_object (value);
 | 
					 | 
				
			||||||
        if (context->priv->connection)
 | 
					 | 
				
			||||||
            g_object_unref (context->priv->connection);
 | 
					 | 
				
			||||||
        context->priv->connection = g_object_ref (connection);
 | 
					 | 
				
			||||||
        break;
 | 
					 | 
				
			||||||
    case PROP_CLIENT_NAME:
 | 
					    case PROP_CLIENT_NAME:
 | 
				
			||||||
        if (context->priv->client_name)
 | 
					        if (context->priv->client_name)
 | 
				
			||||||
            g_free (context->priv->client_name);
 | 
					            g_free (context->priv->client_name);
 | 
				
			||||||
@ -279,9 +264,6 @@ eekboard_context_service_get_property (GObject    *object,
 | 
				
			|||||||
    case PROP_OBJECT_PATH:
 | 
					    case PROP_OBJECT_PATH:
 | 
				
			||||||
        g_value_set_string (value, context->priv->object_path);
 | 
					        g_value_set_string (value, context->priv->object_path);
 | 
				
			||||||
        break;
 | 
					        break;
 | 
				
			||||||
    case PROP_CONNECTION:
 | 
					 | 
				
			||||||
        g_value_set_object (value, context->priv->connection);
 | 
					 | 
				
			||||||
        break;
 | 
					 | 
				
			||||||
    case PROP_CLIENT_NAME:
 | 
					    case PROP_CLIENT_NAME:
 | 
				
			||||||
        g_value_set_string (value, context->priv->client_name);
 | 
					        g_value_set_string (value, context->priv->client_name);
 | 
				
			||||||
        break;
 | 
					        break;
 | 
				
			||||||
@ -310,17 +292,6 @@ eekboard_context_service_dispose (GObject *object)
 | 
				
			|||||||
        context->priv->keyboard_hash = NULL;
 | 
					        context->priv->keyboard_hash = NULL;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    if (context->priv->connection) {
 | 
					 | 
				
			||||||
        if (context->priv->registration_id > 0) {
 | 
					 | 
				
			||||||
            g_dbus_connection_unregister_object (context->priv->connection,
 | 
					 | 
				
			||||||
                                                 context->priv->registration_id);
 | 
					 | 
				
			||||||
            context->priv->registration_id = 0;
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        g_object_unref (context->priv->connection);
 | 
					 | 
				
			||||||
        context->priv->connection = NULL;
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    if (context->priv->introspection_data) {
 | 
					    if (context->priv->introspection_data) {
 | 
				
			||||||
        g_dbus_node_info_unref (context->priv->introspection_data);
 | 
					        g_dbus_node_info_unref (context->priv->introspection_data);
 | 
				
			||||||
        context->priv->introspection_data = NULL;
 | 
					        context->priv->introspection_data = NULL;
 | 
				
			||||||
@ -509,20 +480,6 @@ eekboard_context_service_class_init (EekboardContextServiceClass *klass)
 | 
				
			|||||||
                                     PROP_OBJECT_PATH,
 | 
					                                     PROP_OBJECT_PATH,
 | 
				
			||||||
                                     pspec);
 | 
					                                     pspec);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    /**
 | 
					 | 
				
			||||||
     * EekboardContextService:connection:
 | 
					 | 
				
			||||||
     *
 | 
					 | 
				
			||||||
     * D-Bus connection.
 | 
					 | 
				
			||||||
     */
 | 
					 | 
				
			||||||
    pspec = g_param_spec_object ("connection",
 | 
					 | 
				
			||||||
                                 "Connection",
 | 
					 | 
				
			||||||
                                 "Connection",
 | 
					 | 
				
			||||||
                                 G_TYPE_DBUS_CONNECTION,
 | 
					 | 
				
			||||||
                                 G_PARAM_CONSTRUCT | G_PARAM_READWRITE);
 | 
					 | 
				
			||||||
    g_object_class_install_property (gobject_class,
 | 
					 | 
				
			||||||
                                     PROP_CONNECTION,
 | 
					 | 
				
			||||||
                                     pspec);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    /**
 | 
					    /**
 | 
				
			||||||
     * EekboardContextService:client-name:
 | 
					     * EekboardContextService:client-name:
 | 
				
			||||||
     *
 | 
					     *
 | 
				
			||||||
@ -630,31 +587,6 @@ disconnect_keyboard_signals (EekboardContextService *context)
 | 
				
			|||||||
    }
 | 
					    }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
static void
 | 
					 | 
				
			||||||
emit_visibility_changed_signal (EekboardContextService *context,
 | 
					 | 
				
			||||||
                                gboolean                visible)
 | 
					 | 
				
			||||||
{
 | 
					 | 
				
			||||||
    return; // FIXME: update Visible property
 | 
					 | 
				
			||||||
    if (context->priv->connection && context->priv->enabled) {
 | 
					 | 
				
			||||||
        GError *error = NULL;
 | 
					 | 
				
			||||||
        gboolean retval;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        retval = g_dbus_connection_emit_signal (context->priv->connection,
 | 
					 | 
				
			||||||
                                                NULL,
 | 
					 | 
				
			||||||
                                                context->priv->object_path,
 | 
					 | 
				
			||||||
                                                EEKBOARD_CONTEXT_SERVICE_INTERFACE,
 | 
					 | 
				
			||||||
                                                "VisibilityChanged",
 | 
					 | 
				
			||||||
                                                g_variant_new ("(b)", visible),
 | 
					 | 
				
			||||||
                                                &error);
 | 
					 | 
				
			||||||
        if (!retval) {
 | 
					 | 
				
			||||||
            g_warning ("failed to emit VisibilityChanged signal: %s",
 | 
					 | 
				
			||||||
                       error->message);
 | 
					 | 
				
			||||||
            g_error_free (error);
 | 
					 | 
				
			||||||
            g_assert_not_reached ();
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
static gboolean on_repeat_timeout (EekboardContextService *context);
 | 
					static gboolean on_repeat_timeout (EekboardContextService *context);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
static gboolean
 | 
					static gboolean
 | 
				
			||||||
@ -716,7 +648,6 @@ void
 | 
				
			|||||||
eekboard_context_service_enable (EekboardContextService *context)
 | 
					eekboard_context_service_enable (EekboardContextService *context)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    g_return_if_fail (EEKBOARD_IS_CONTEXT_SERVICE(context));
 | 
					    g_return_if_fail (EEKBOARD_IS_CONTEXT_SERVICE(context));
 | 
				
			||||||
    g_return_if_fail (context->priv->connection);
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
    if (!context->priv->enabled) {
 | 
					    if (!context->priv->enabled) {
 | 
				
			||||||
        context->priv->enabled = TRUE;
 | 
					        context->priv->enabled = TRUE;
 | 
				
			||||||
@ -737,27 +668,12 @@ eekboard_context_service_disable (EekboardContextService *context)
 | 
				
			|||||||
    GError *error;
 | 
					    GError *error;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    g_return_if_fail (EEKBOARD_IS_CONTEXT_SERVICE(context));
 | 
					    g_return_if_fail (EEKBOARD_IS_CONTEXT_SERVICE(context));
 | 
				
			||||||
    g_return_if_fail (context->priv->connection);
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
    if (context->priv->enabled) {
 | 
					    if (context->priv->enabled) {
 | 
				
			||||||
        gboolean retval;
 | 
					        gboolean retval;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        context->priv->enabled = FALSE;
 | 
					        context->priv->enabled = FALSE;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        error = NULL;
 | 
					 | 
				
			||||||
        retval = g_dbus_connection_emit_signal (context->priv->connection,
 | 
					 | 
				
			||||||
                                                NULL,
 | 
					 | 
				
			||||||
                                                context->priv->object_path,
 | 
					 | 
				
			||||||
                                                EEKBOARD_CONTEXT_SERVICE_INTERFACE,
 | 
					 | 
				
			||||||
                                                "Disabled",
 | 
					 | 
				
			||||||
                                                NULL,
 | 
					 | 
				
			||||||
                                                &error);
 | 
					 | 
				
			||||||
        if (!retval) {
 | 
					 | 
				
			||||||
            g_warning ("failed to emit Disabled signal: %s",
 | 
					 | 
				
			||||||
                       error->message);
 | 
					 | 
				
			||||||
            g_error_free (error);
 | 
					 | 
				
			||||||
            g_assert_not_reached ();
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
        g_signal_emit (context, signals[DISABLED], 0);
 | 
					        g_signal_emit (context, signals[DISABLED], 0);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
@ -766,7 +682,6 @@ void
 | 
				
			|||||||
eekboard_context_service_show_keyboard (EekboardContextService *context)
 | 
					eekboard_context_service_show_keyboard (EekboardContextService *context)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    g_return_if_fail (EEKBOARD_IS_CONTEXT_SERVICE(context));
 | 
					    g_return_if_fail (EEKBOARD_IS_CONTEXT_SERVICE(context));
 | 
				
			||||||
    g_return_if_fail (context->priv->connection);
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
    EEKBOARD_CONTEXT_SERVICE_GET_CLASS(context)->show_keyboard (context);
 | 
					    EEKBOARD_CONTEXT_SERVICE_GET_CLASS(context)->show_keyboard (context);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
@ -775,7 +690,6 @@ void
 | 
				
			|||||||
eekboard_context_service_hide_keyboard (EekboardContextService *context)
 | 
					eekboard_context_service_hide_keyboard (EekboardContextService *context)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    g_return_if_fail (EEKBOARD_IS_CONTEXT_SERVICE(context));
 | 
					    g_return_if_fail (EEKBOARD_IS_CONTEXT_SERVICE(context));
 | 
				
			||||||
    g_return_if_fail (context->priv->connection);
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
    EEKBOARD_CONTEXT_SERVICE_GET_CLASS(context)->hide_keyboard (context);
 | 
					    EEKBOARD_CONTEXT_SERVICE_GET_CLASS(context)->hide_keyboard (context);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
@ -793,26 +707,10 @@ eekboard_context_service_destroy (EekboardContextService *context)
 | 
				
			|||||||
    GError *error;
 | 
					    GError *error;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    g_return_if_fail (EEKBOARD_IS_CONTEXT_SERVICE(context));
 | 
					    g_return_if_fail (EEKBOARD_IS_CONTEXT_SERVICE(context));
 | 
				
			||||||
    g_return_if_fail (context->priv->connection);
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
    if (context->priv->enabled) {
 | 
					    if (context->priv->enabled) {
 | 
				
			||||||
        eekboard_context_service_disable (context);
 | 
					        eekboard_context_service_disable (context);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					 | 
				
			||||||
    error = NULL;
 | 
					 | 
				
			||||||
    retval = g_dbus_connection_emit_signal (context->priv->connection,
 | 
					 | 
				
			||||||
                                            NULL,
 | 
					 | 
				
			||||||
                                            context->priv->object_path,
 | 
					 | 
				
			||||||
                                            EEKBOARD_CONTEXT_SERVICE_INTERFACE,
 | 
					 | 
				
			||||||
                                            "Destroyed",
 | 
					 | 
				
			||||||
                                            NULL,
 | 
					 | 
				
			||||||
                                            &error);
 | 
					 | 
				
			||||||
    if (!retval) {
 | 
					 | 
				
			||||||
        g_warning ("failed to emit Destroyed signal: %s",
 | 
					 | 
				
			||||||
                   error->message);
 | 
					 | 
				
			||||||
        g_error_free (error);
 | 
					 | 
				
			||||||
        g_assert_not_reached ();
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
    g_signal_emit (context, signals[DESTROYED], 0);
 | 
					    g_signal_emit (context, signals[DESTROYED], 0);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
				
			|||||||
@ -492,12 +492,10 @@ server_context_service_init (ServerContextService *context)
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
ServerContextService *
 | 
					ServerContextService *
 | 
				
			||||||
server_context_service_new (const gchar     *client_name,
 | 
					server_context_service_new (const gchar     *client_name,
 | 
				
			||||||
                            const gchar     *object_path,
 | 
					                            const gchar     *object_path)
 | 
				
			||||||
                            GDBusConnection *connection)
 | 
					 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    return g_object_new (SERVER_TYPE_CONTEXT_SERVICE,
 | 
					    return g_object_new (SERVER_TYPE_CONTEXT_SERVICE,
 | 
				
			||||||
                         "client-name", client_name,
 | 
					                         "client-name", client_name,
 | 
				
			||||||
                         "object-path", object_path,
 | 
					                         "object-path", object_path,
 | 
				
			||||||
                         "connection", connection,
 | 
					 | 
				
			||||||
                         NULL);
 | 
					                         NULL);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
				
			|||||||
@ -32,8 +32,7 @@ G_BEGIN_DECLS
 | 
				
			|||||||
typedef struct _ServerContextService ServerContextService;
 | 
					typedef struct _ServerContextService ServerContextService;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
ServerContextService *server_context_service_new (const gchar     *client_name,
 | 
					ServerContextService *server_context_service_new (const gchar     *client_name,
 | 
				
			||||||
                                                  const gchar     *object_path,
 | 
					                                                  const gchar     *object_path);
 | 
				
			||||||
                                                  GDBusConnection *connection);
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
G_END_DECLS
 | 
					G_END_DECLS
 | 
				
			||||||
#endif  /* SERVER_CONTEXT_SERVICE_H */
 | 
					#endif  /* SERVER_CONTEXT_SERVICE_H */
 | 
				
			||||||
 | 
				
			|||||||
@ -42,9 +42,7 @@ server_service_real_create_context (EekboardService *self,
 | 
				
			|||||||
    GDBusConnection *connection;
 | 
					    GDBusConnection *connection;
 | 
				
			||||||
    ServerContextService *context;
 | 
					    ServerContextService *context;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    g_object_get (G_OBJECT(self), "connection", &connection, NULL);
 | 
					    context = server_context_service_new (client_name, object_path);
 | 
				
			||||||
    context = server_context_service_new (client_name, object_path, connection);
 | 
					 | 
				
			||||||
    g_object_unref (connection);
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
    return EEKBOARD_CONTEXT_SERVICE(context);
 | 
					    return EEKBOARD_CONTEXT_SERVICE(context);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user