dbus: Remove unneeded gobjectness
Also removed the code linking dbus interface stop to application quit. DBus going missing was not handled, and isn't a fatal error anyway.
This commit is contained in:
@ -28,7 +28,6 @@
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#include "sm.puri.OSK0.h"
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
@ -36,135 +35,45 @@
|
||||
|
||||
#include "eekboard/eekboard-service.h"
|
||||
|
||||
enum {
|
||||
PROP_0,
|
||||
PROP_OBJECT_PATH,
|
||||
PROP_CONNECTION,
|
||||
PROP_LAST
|
||||
};
|
||||
|
||||
enum {
|
||||
DESTROYED,
|
||||
LAST_SIGNAL
|
||||
};
|
||||
|
||||
static guint signals[LAST_SIGNAL] = { 0, };
|
||||
|
||||
typedef struct _EekboardServicePrivate
|
||||
void
|
||||
eekboard_service_destroy(EekboardService *service)
|
||||
{
|
||||
GDBusConnection *connection;
|
||||
SmPuriOSK0 *dbus_interface;
|
||||
GDBusNodeInfo *introspection_data;
|
||||
guint registration_id;
|
||||
char *object_path;
|
||||
g_free (service->object_path);
|
||||
|
||||
ServerContextService *context; // unowned reference
|
||||
} EekboardServicePrivate;
|
||||
|
||||
G_DEFINE_TYPE_WITH_PRIVATE (EekboardService, eekboard_service, G_TYPE_OBJECT)
|
||||
|
||||
static void
|
||||
eekboard_service_set_property (GObject *object,
|
||||
guint prop_id,
|
||||
const GValue *value,
|
||||
GParamSpec *pspec)
|
||||
{
|
||||
EekboardService *service = EEKBOARD_SERVICE(object);
|
||||
EekboardServicePrivate *priv = eekboard_service_get_instance_private (service);
|
||||
GDBusConnection *connection;
|
||||
|
||||
switch (prop_id) {
|
||||
case PROP_OBJECT_PATH:
|
||||
if (priv->object_path)
|
||||
g_free (priv->object_path);
|
||||
priv->object_path = g_value_dup_string (value);
|
||||
break;
|
||||
case PROP_CONNECTION:
|
||||
connection = g_value_get_object (value);
|
||||
if (priv->connection)
|
||||
g_object_unref (priv->connection);
|
||||
priv->connection = g_object_ref (connection);
|
||||
break;
|
||||
default:
|
||||
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
eekboard_service_get_property (GObject *object,
|
||||
guint prop_id,
|
||||
GValue *value,
|
||||
GParamSpec *pspec)
|
||||
{
|
||||
EekboardService *service = EEKBOARD_SERVICE(object);
|
||||
EekboardServicePrivate *priv = eekboard_service_get_instance_private (service);
|
||||
|
||||
switch (prop_id) {
|
||||
case PROP_OBJECT_PATH:
|
||||
g_value_set_string (value, priv->object_path);
|
||||
break;
|
||||
case PROP_CONNECTION:
|
||||
g_value_set_object (value, priv->connection);
|
||||
break;
|
||||
default:
|
||||
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
eekboard_service_dispose (GObject *object)
|
||||
{
|
||||
EekboardService *service = EEKBOARD_SERVICE(object);
|
||||
EekboardServicePrivate *priv = eekboard_service_get_instance_private (service);
|
||||
|
||||
if (priv->connection) {
|
||||
if (priv->registration_id > 0) {
|
||||
g_dbus_connection_unregister_object (priv->connection,
|
||||
priv->registration_id);
|
||||
priv->registration_id = 0;
|
||||
if (service->connection) {
|
||||
if (service->registration_id > 0) {
|
||||
g_dbus_connection_unregister_object (service->connection,
|
||||
service->registration_id);
|
||||
service->registration_id = 0;
|
||||
}
|
||||
|
||||
g_object_unref (priv->connection);
|
||||
priv->connection = NULL;
|
||||
g_object_unref (service->connection);
|
||||
service->connection = NULL;
|
||||
}
|
||||
|
||||
if (priv->introspection_data) {
|
||||
g_dbus_node_info_unref (priv->introspection_data);
|
||||
priv->introspection_data = NULL;
|
||||
if (service->introspection_data) {
|
||||
g_dbus_node_info_unref (service->introspection_data);
|
||||
service->introspection_data = NULL;
|
||||
}
|
||||
|
||||
if (priv->context) {
|
||||
g_signal_handlers_disconnect_by_data (priv->context, service);
|
||||
priv->context = NULL;
|
||||
if (service->context) {
|
||||
g_signal_handlers_disconnect_by_data (service->context, service);
|
||||
service->context = NULL;
|
||||
}
|
||||
|
||||
G_OBJECT_CLASS (eekboard_service_parent_class)->dispose (object);
|
||||
}
|
||||
|
||||
static void
|
||||
eekboard_service_finalize (GObject *object)
|
||||
{
|
||||
EekboardService *service = EEKBOARD_SERVICE(object);
|
||||
EekboardServicePrivate *priv = eekboard_service_get_instance_private (service);
|
||||
|
||||
g_free (priv->object_path);
|
||||
|
||||
G_OBJECT_CLASS (eekboard_service_parent_class)->finalize (object);
|
||||
free(service);
|
||||
}
|
||||
|
||||
static gboolean
|
||||
handle_set_visible(SmPuriOSK0 *object, GDBusMethodInvocation *invocation,
|
||||
gboolean arg_visible, gpointer user_data) {
|
||||
EekboardService *service = user_data;
|
||||
EekboardServicePrivate *priv = eekboard_service_get_instance_private (service);
|
||||
|
||||
if (priv->context) {
|
||||
if (service->context) {
|
||||
if (arg_visible) {
|
||||
server_context_service_show_keyboard (priv->context);
|
||||
server_context_service_show_keyboard (service->context);
|
||||
} else {
|
||||
server_context_service_hide_keyboard (priv->context);
|
||||
server_context_service_hide_keyboard (service->context);
|
||||
}
|
||||
}
|
||||
sm_puri_osk0_complete_set_visible(object, invocation);
|
||||
@ -177,104 +86,12 @@ static void on_visible(EekboardService *service,
|
||||
{
|
||||
(void)pspec;
|
||||
gboolean visible;
|
||||
EekboardServicePrivate *priv;
|
||||
|
||||
g_return_if_fail (EEKBOARD_IS_SERVICE (service));
|
||||
g_return_if_fail (SERVER_IS_CONTEXT_SERVICE (context));
|
||||
|
||||
priv = eekboard_service_get_instance_private (service);
|
||||
g_object_get (context, "visible", &visible, NULL);
|
||||
|
||||
sm_puri_osk0_set_visible(priv->dbus_interface, visible);
|
||||
}
|
||||
|
||||
static void
|
||||
eekboard_service_constructed (GObject *object)
|
||||
{
|
||||
EekboardService *service = EEKBOARD_SERVICE(object);
|
||||
EekboardServicePrivate *priv = eekboard_service_get_instance_private (service);
|
||||
|
||||
priv->dbus_interface = sm_puri_osk0_skeleton_new();
|
||||
g_signal_connect(priv->dbus_interface, "handle-set-visible",
|
||||
G_CALLBACK(handle_set_visible), service);
|
||||
|
||||
if (priv->connection && priv->object_path) {
|
||||
GError *error = NULL;
|
||||
|
||||
if (!g_dbus_interface_skeleton_export(G_DBUS_INTERFACE_SKELETON(priv->dbus_interface),
|
||||
priv->connection,
|
||||
priv->object_path,
|
||||
&error)) {
|
||||
g_warning("Error registering dbus object: %s\n", error->message);
|
||||
g_clear_error(&error);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
eekboard_service_class_init (EekboardServiceClass *klass)
|
||||
{
|
||||
GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
|
||||
GParamSpec *pspec;
|
||||
|
||||
gobject_class->constructed = eekboard_service_constructed;
|
||||
gobject_class->set_property = eekboard_service_set_property;
|
||||
gobject_class->get_property = eekboard_service_get_property;
|
||||
gobject_class->dispose = eekboard_service_dispose;
|
||||
gobject_class->finalize = eekboard_service_finalize;
|
||||
|
||||
/**
|
||||
* EekboardService::destroyed:
|
||||
* @service: an #EekboardService
|
||||
*
|
||||
* The ::destroyed signal is emitted when the service is vanished.
|
||||
*/
|
||||
signals[DESTROYED] =
|
||||
g_signal_new (I_("destroyed"),
|
||||
G_TYPE_FROM_CLASS(gobject_class),
|
||||
G_SIGNAL_RUN_LAST,
|
||||
0,
|
||||
NULL,
|
||||
NULL,
|
||||
g_cclosure_marshal_VOID__VOID,
|
||||
G_TYPE_NONE,
|
||||
0);
|
||||
|
||||
/**
|
||||
* EekboardService:object-path:
|
||||
*
|
||||
* D-Bus object path.
|
||||
*/
|
||||
pspec = g_param_spec_string ("object-path",
|
||||
"Object-path",
|
||||
"Object-path",
|
||||
NULL,
|
||||
G_PARAM_CONSTRUCT | G_PARAM_READWRITE);
|
||||
g_object_class_install_property (gobject_class,
|
||||
PROP_OBJECT_PATH,
|
||||
pspec);
|
||||
|
||||
/**
|
||||
* EekboardService: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);
|
||||
}
|
||||
|
||||
static void
|
||||
eekboard_service_init (EekboardService *self)
|
||||
{
|
||||
EekboardServicePrivate *priv = eekboard_service_get_instance_private (self);
|
||||
|
||||
priv->context = NULL;
|
||||
sm_puri_osk0_set_visible(service->dbus_interface, visible);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -286,23 +103,38 @@ EekboardService *
|
||||
eekboard_service_new (GDBusConnection *connection,
|
||||
const gchar *object_path)
|
||||
{
|
||||
return g_object_new (EEKBOARD_TYPE_SERVICE,
|
||||
"object-path", object_path,
|
||||
"connection", connection,
|
||||
NULL);
|
||||
EekboardService *self = calloc(1, sizeof(EekboardService));
|
||||
self->object_path = g_strdup(object_path);
|
||||
self->connection = connection;
|
||||
|
||||
self->dbus_interface = sm_puri_osk0_skeleton_new();
|
||||
g_signal_connect(self->dbus_interface, "handle-set-visible",
|
||||
G_CALLBACK(handle_set_visible), self);
|
||||
|
||||
if (self->connection && self->object_path) {
|
||||
GError *error = NULL;
|
||||
|
||||
if (!g_dbus_interface_skeleton_export(G_DBUS_INTERFACE_SKELETON(self->dbus_interface),
|
||||
self->connection,
|
||||
self->object_path,
|
||||
&error)) {
|
||||
g_warning("Error registering dbus object: %s\n", error->message);
|
||||
g_clear_error(&error);
|
||||
// TODO: return an error
|
||||
}
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
void
|
||||
eekboard_service_set_context(EekboardService *service,
|
||||
ServerContextService *context)
|
||||
{
|
||||
EekboardServicePrivate *priv = eekboard_service_get_instance_private (service);
|
||||
g_return_if_fail (!service->context);
|
||||
|
||||
g_return_if_fail (!priv->context);
|
||||
service->context = context;
|
||||
|
||||
priv->context = context;
|
||||
|
||||
g_signal_connect_swapped (priv->context,
|
||||
g_signal_connect_swapped (service->context,
|
||||
"notify::visible",
|
||||
G_CALLBACK(on_visible),
|
||||
service);
|
||||
|
||||
@ -22,30 +22,31 @@
|
||||
|
||||
#include "server-context-service.h"
|
||||
|
||||
#include "sm.puri.OSK0.h"
|
||||
|
||||
G_BEGIN_DECLS
|
||||
|
||||
#define EEKBOARD_SERVICE_PATH "/sm/puri/OSK0"
|
||||
#define EEKBOARD_SERVICE_INTERFACE "sm.puri.OSK0"
|
||||
|
||||
#define EEKBOARD_TYPE_SERVICE (eekboard_service_get_type())
|
||||
G_DECLARE_DERIVABLE_TYPE (EekboardService, eekboard_service, EEKBOARD, SERVICE, GObject)
|
||||
|
||||
/**
|
||||
* EekboardServiceClass:
|
||||
* @create_context: virtual function for creating a context
|
||||
* EekboardService: DBus handling
|
||||
*/
|
||||
struct _EekboardServiceClass {
|
||||
/*< private >*/
|
||||
GObjectClass parent_class;
|
||||
/*< private >*/
|
||||
/* padding */
|
||||
gpointer pdummy[24];
|
||||
};
|
||||
typedef struct _EekboardService
|
||||
{
|
||||
GDBusConnection *connection;
|
||||
SmPuriOSK0 *dbus_interface;
|
||||
GDBusNodeInfo *introspection_data;
|
||||
guint registration_id;
|
||||
char *object_path;
|
||||
|
||||
ServerContextService *context; // unowned reference
|
||||
} EekboardService;
|
||||
|
||||
GType eekboard_service_get_type (void) G_GNUC_CONST;
|
||||
EekboardService * eekboard_service_new (GDBusConnection *connection,
|
||||
const gchar *object_path);
|
||||
void eekboard_service_set_context(EekboardService *service,
|
||||
ServerContextService *context);
|
||||
void eekboard_service_destroy(EekboardService*);
|
||||
G_END_DECLS
|
||||
#endif /* EEKBOARD_SERVICE_H */
|
||||
|
||||
@ -71,16 +71,6 @@ on_name_lost (GDBusConnection *connection,
|
||||
exit (1);
|
||||
}
|
||||
|
||||
static void
|
||||
on_destroyed (EekboardService *service,
|
||||
gpointer user_data)
|
||||
{
|
||||
(void)service;
|
||||
GMainLoop *loop = user_data;
|
||||
|
||||
g_main_loop_quit (loop);
|
||||
}
|
||||
|
||||
static ServerContextService *create_context() {
|
||||
ServerContextService *context = server_context_service_new ();
|
||||
g_object_set_data_full (G_OBJECT(context),
|
||||
@ -295,8 +285,6 @@ main (int argc, char **argv)
|
||||
|
||||
GMainLoop *loop = g_main_loop_new (NULL, FALSE);
|
||||
|
||||
g_signal_connect (service, "destroyed", G_CALLBACK(on_destroyed), loop);
|
||||
|
||||
g_main_loop_run (loop);
|
||||
|
||||
g_bus_unown_name (owner_id);
|
||||
|
||||
Reference in New Issue
Block a user