mirror of
https://gitlab.gnome.org/GNOME/libmks.git
synced 2024-12-22 05:35:21 +00:00
lib: add session weak pointer to devices
This is handy because it gives devices the ability to locate/coordinate with other subsystems.
This commit is contained in:
parent
dac3fc284a
commit
0478d202f8
@ -23,12 +23,14 @@
|
||||
|
||||
#include "mks-device.h"
|
||||
#include "mks-qemu.h"
|
||||
#include "mks-session.h"
|
||||
|
||||
G_BEGIN_DECLS
|
||||
|
||||
struct _MksDevice
|
||||
{
|
||||
GObject parent_instance;
|
||||
MksSession *session;
|
||||
MksQemuObject *object;
|
||||
char *name;
|
||||
};
|
||||
@ -42,6 +44,7 @@ struct _MksDeviceClass
|
||||
};
|
||||
|
||||
gpointer _mks_device_new (GType device_type,
|
||||
MksSession *session,
|
||||
MksQemuObject *object);
|
||||
void _mks_device_set_name (MksDevice *self,
|
||||
const char *name);
|
||||
|
@ -48,6 +48,7 @@ mks_device_dispose (GObject *object)
|
||||
{
|
||||
MksDevice *self = (MksDevice *)object;
|
||||
|
||||
g_clear_weak_pointer (&self->session);
|
||||
g_clear_pointer (&self->name, g_free);
|
||||
g_clear_object (&self->object);
|
||||
|
||||
@ -116,17 +117,20 @@ _mks_device_set_name (MksDevice *self,
|
||||
|
||||
gpointer
|
||||
_mks_device_new (GType device_type,
|
||||
MksSession *session,
|
||||
MksQemuObject *object)
|
||||
{
|
||||
g_autoptr(MksDevice) self = NULL;
|
||||
|
||||
g_return_val_if_fail (g_type_is_a (device_type, MKS_TYPE_DEVICE), NULL);
|
||||
g_return_val_if_fail (device_type != MKS_TYPE_DEVICE, NULL);
|
||||
g_return_val_if_fail (MKS_IS_SESSION (session), NULL);
|
||||
g_return_val_if_fail (MKS_QEMU_IS_OBJECT (object), NULL);
|
||||
|
||||
if (!(self = g_object_new (device_type, NULL)))
|
||||
return NULL;
|
||||
|
||||
g_set_weak_pointer (&self->session, session);
|
||||
self->object = g_object_ref (object);
|
||||
|
||||
if (!MKS_DEVICE_GET_CLASS (self)->setup (self, object))
|
||||
|
@ -178,9 +178,9 @@ mks_screen_setup (MksDevice *device,
|
||||
if (MKS_QEMU_IS_CONSOLE (iface))
|
||||
mks_screen_set_console (self, MKS_QEMU_CONSOLE (iface));
|
||||
else if (MKS_QEMU_IS_KEYBOARD (iface))
|
||||
self->keyboard = _mks_device_new (MKS_TYPE_KEYBOARD, object);
|
||||
self->keyboard = _mks_device_new (MKS_TYPE_KEYBOARD, device->session, object);
|
||||
else if (MKS_QEMU_IS_MOUSE (iface))
|
||||
self->mouse = _mks_device_new (MKS_TYPE_MOUSE, object);
|
||||
self->mouse = _mks_device_new (MKS_TYPE_MOUSE, device->session, object);
|
||||
}
|
||||
|
||||
return self->console != NULL &&
|
||||
|
@ -225,7 +225,7 @@ mks_session_object_manager_object_added_cb (MksSession *self,
|
||||
if (MKS_QEMU_IS_VM (iface))
|
||||
mks_session_set_vm (self, object, MKS_QEMU_VM (iface));
|
||||
else if (MKS_QEMU_IS_CONSOLE (iface))
|
||||
mks_session_add_device (self, _mks_device_new (MKS_TYPE_SCREEN, object));
|
||||
mks_session_add_device (self, _mks_device_new (MKS_TYPE_SCREEN, self, object));
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user