1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138
|
/* plugin-deviced-device-info.c
*
* Copyright 2025 Christian Hergert <chergert@redhat.com>
*
* This library is free software; you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of the
* License, or (at your option) any later version.
*
* This library 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
* Lesser 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: LGPL-2.1-or-later
*/
#include "config.h"
#include "plugin-deviced-device-info.h"
struct _PluginDevicedDeviceInfo
{
FoundryDeviceInfo parent_instance;
DevdDevice *device;
DevdClient *client;
};
G_DEFINE_FINAL_TYPE (PluginDevicedDeviceInfo, plugin_deviced_device_info, FOUNDRY_TYPE_DEVICE_INFO)
G_GNUC_BEGIN_IGNORE_DEPRECATIONS
static char *
plugin_deviced_device_info_dup_id (FoundryDeviceInfo *device_info)
{
PluginDevicedDeviceInfo *self = (PluginDevicedDeviceInfo *)device_info;
char *id = NULL;
g_assert (PLUGIN_IS_DEVICED_DEVICE_INFO (self));
g_assert (DEVD_IS_DEVICE (self->device));
g_object_get (self->device, "id", &id, NULL);
return id;
}
static char *
plugin_deviced_device_info_dup_name (FoundryDeviceInfo *device_info)
{
PluginDevicedDeviceInfo *self = (PluginDevicedDeviceInfo *)device_info;
g_assert (PLUGIN_IS_DEVICED_DEVICE_INFO (self));
g_assert (DEVD_IS_CLIENT (self->client));
return devd_client_get_name (self->client);
}
static FoundryTriplet *
plugin_deviced_device_info_dup_triplet (FoundryDeviceInfo *device_info)
{
PluginDevicedDeviceInfo *self = (PluginDevicedDeviceInfo *)device_info;
g_autoptr(DevdTriplet) triplet = NULL;
g_assert (PLUGIN_IS_DEVICED_DEVICE_INFO (self));
g_assert (DEVD_IS_CLIENT (self->client));
triplet = devd_client_get_triplet (self->client);
return foundry_triplet_new_with_quadruplet (devd_triplet_get_arch (triplet),
devd_triplet_get_vendor (triplet),
devd_triplet_get_kernel (triplet),
devd_triplet_get_operating_system (triplet));
}
static void
plugin_deviced_device_info_finalize (GObject *object)
{
PluginDevicedDeviceInfo *self = (PluginDevicedDeviceInfo *)object;
g_clear_object (&self->client);
g_clear_object (&self->device);
G_OBJECT_CLASS (plugin_deviced_device_info_parent_class)->finalize (object);
}
static void
plugin_deviced_device_info_class_init (PluginDevicedDeviceInfoClass *klass)
{
GObjectClass *object_class = G_OBJECT_CLASS (klass);
FoundryDeviceInfoClass *device_info_class = FOUNDRY_DEVICE_INFO_CLASS (klass);
object_class->finalize = plugin_deviced_device_info_finalize;
device_info_class->dup_id = plugin_deviced_device_info_dup_id;
device_info_class->dup_name = plugin_deviced_device_info_dup_name;
device_info_class->dup_triplet = plugin_deviced_device_info_dup_triplet;
}
static void
plugin_deviced_device_info_init (PluginDevicedDeviceInfo *self)
{
}
static DexFuture *
plugin_deviced_device_info_new_fiber (gpointer data)
{
FoundryPair *pair = data;
DevdDevice *device = DEVD_DEVICE (pair->first);
DevdClient *client = DEVD_CLIENT (pair->second);
PluginDevicedDeviceInfo *self;
g_assert (DEVD_IS_DEVICE (device));
g_assert (DEVD_IS_CLIENT (client));
self = g_object_new (PLUGIN_TYPE_DEVICED_DEVICE_INFO, NULL);
self->device = g_object_ref (device);
self->client = g_object_ref (client);
return dex_future_new_take_object (g_steal_pointer (&self));
}
DexFuture *
plugin_deviced_device_info_new (DevdDevice *device,
DevdClient *client)
{
dex_return_error_if_fail (DEVD_IS_DEVICE (device));
dex_return_error_if_fail (DEVD_IS_CLIENT (client));
return dex_scheduler_spawn (NULL, 0,
plugin_deviced_device_info_new_fiber,
foundry_pair_new (device, client),
(GDestroyNotify) foundry_pair_free);
}
G_GNUC_END_IGNORE_DEPRECATIONS
|