2023-02-09 02:06:08 +00:00
|
|
|
/*
|
|
|
|
* mks-device.c
|
|
|
|
*
|
|
|
|
* Copyright 2023 Christian Hergert <chergert@redhat.com>
|
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*
|
|
|
|
* SPDX-License-Identifier: GPL-3.0-or-later
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
|
|
|
|
#include "mks-device-private.h"
|
|
|
|
|
2023-02-09 10:23:18 +00:00
|
|
|
G_DEFINE_TYPE (MksDevice, mks_device, G_TYPE_OBJECT)
|
2023-02-09 02:06:08 +00:00
|
|
|
|
|
|
|
enum {
|
|
|
|
PROP_0,
|
|
|
|
PROP_NAME,
|
|
|
|
N_PROPS
|
|
|
|
};
|
|
|
|
|
|
|
|
static GParamSpec *properties [N_PROPS];
|
|
|
|
|
2023-02-09 10:23:18 +00:00
|
|
|
static gboolean
|
|
|
|
mks_device_real_setup (MksDevice *device,
|
|
|
|
MksQemuObject *object)
|
|
|
|
{
|
|
|
|
g_assert (MKS_IS_DEVICE (device));
|
|
|
|
g_assert (MKS_QEMU_IS_OBJECT (object));
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2023-02-09 02:06:08 +00:00
|
|
|
static void
|
2023-02-09 10:23:18 +00:00
|
|
|
mks_device_dispose (GObject *object)
|
2023-02-09 02:06:08 +00:00
|
|
|
{
|
|
|
|
MksDevice *self = (MksDevice *)object;
|
|
|
|
|
2023-02-09 20:54:48 +00:00
|
|
|
g_clear_weak_pointer (&self->session);
|
2023-02-09 10:23:18 +00:00
|
|
|
g_clear_pointer (&self->name, g_free);
|
|
|
|
g_clear_object (&self->object);
|
2023-02-09 02:06:08 +00:00
|
|
|
|
2023-02-09 10:23:18 +00:00
|
|
|
G_OBJECT_CLASS (mks_device_parent_class)->dispose (object);
|
2023-02-09 02:06:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
mks_device_get_property (GObject *object,
|
|
|
|
guint prop_id,
|
|
|
|
GValue *value,
|
|
|
|
GParamSpec *pspec)
|
|
|
|
{
|
|
|
|
MksDevice *self = MKS_DEVICE (object);
|
|
|
|
|
|
|
|
switch (prop_id)
|
|
|
|
{
|
|
|
|
case PROP_NAME:
|
|
|
|
g_value_set_string (value, mks_device_get_name (self));
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
mks_device_class_init (MksDeviceClass *klass)
|
|
|
|
{
|
|
|
|
GObjectClass *object_class = G_OBJECT_CLASS (klass);
|
|
|
|
|
2023-02-09 10:23:18 +00:00
|
|
|
object_class->dispose = mks_device_dispose;
|
2023-02-09 02:06:08 +00:00
|
|
|
object_class->get_property = mks_device_get_property;
|
|
|
|
|
2023-02-09 10:23:18 +00:00
|
|
|
klass->setup = mks_device_real_setup;
|
|
|
|
|
2023-02-09 02:06:08 +00:00
|
|
|
properties [PROP_NAME] =
|
|
|
|
g_param_spec_string ("name", NULL, NULL,
|
|
|
|
NULL,
|
|
|
|
(G_PARAM_READABLE | G_PARAM_STATIC_STRINGS));
|
|
|
|
|
|
|
|
g_object_class_install_properties (object_class, N_PROPS, properties);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
mks_device_init (MksDevice *self)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
const char *
|
|
|
|
mks_device_get_name (MksDevice *self)
|
|
|
|
{
|
|
|
|
g_return_val_if_fail (MKS_IS_DEVICE (self), NULL);
|
|
|
|
|
2023-02-09 10:23:18 +00:00
|
|
|
return self->name;
|
2023-02-09 02:06:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
_mks_device_set_name (MksDevice *self,
|
|
|
|
const char *name)
|
|
|
|
{
|
|
|
|
g_return_if_fail (MKS_IS_DEVICE (self));
|
|
|
|
|
2023-02-09 10:23:18 +00:00
|
|
|
if (g_set_str (&self->name, name))
|
2023-02-09 02:06:08 +00:00
|
|
|
g_object_notify_by_pspec (G_OBJECT (self), properties [PROP_NAME]);
|
|
|
|
}
|
2023-02-09 10:23:18 +00:00
|
|
|
|
|
|
|
gpointer
|
|
|
|
_mks_device_new (GType device_type,
|
2023-02-09 20:54:48 +00:00
|
|
|
MksSession *session,
|
2023-02-09 10:23:18 +00:00
|
|
|
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);
|
2023-02-09 20:54:48 +00:00
|
|
|
g_return_val_if_fail (MKS_IS_SESSION (session), NULL);
|
2023-02-09 10:23:18 +00:00
|
|
|
g_return_val_if_fail (MKS_QEMU_IS_OBJECT (object), NULL);
|
|
|
|
|
|
|
|
if (!(self = g_object_new (device_type, NULL)))
|
|
|
|
return NULL;
|
|
|
|
|
2023-02-09 20:54:48 +00:00
|
|
|
g_set_weak_pointer (&self->session, session);
|
2023-02-09 10:23:18 +00:00
|
|
|
self->object = g_object_ref (object);
|
|
|
|
|
|
|
|
if (!MKS_DEVICE_GET_CLASS (self)->setup (self, object))
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
return g_steal_pointer (&self);
|
|
|
|
}
|