| 1 |
/* sysprof-mount-device.c |
| 2 |
* |
| 3 |
* Copyright 2023 Christian Hergert <[email protected]> |
| 4 |
* |
| 5 |
* This program is free software: you can redistribute it and/or modify |
| 6 |
* it under the terms of the GNU General Public License as published by |
| 7 |
* the Free Software Foundation, either version 3 of the License, or |
| 8 |
* (at your option) any later version. |
| 9 |
* |
| 10 |
* This program is distributed in the hope that it will be useful, |
| 11 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 |
* GNU General Public License for more details. |
| 14 |
* |
| 15 |
* You should have received a copy of the GNU General Public License |
| 16 |
* along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 17 |
* |
| 18 |
* SPDX-License-Identifier: GPL-3.0-or-later |
| 19 |
*/ |
| 20 |
|
| 21 |
#include "config.h" |
| 22 |
|
| 23 |
#include "sysprof-mount-device-private.h" |
| 24 |
|
| 25 |
struct _SysprofMountDevice |
| 26 |
{ |
| 27 |
GObject parent_instance; |
| 28 |
GRefString *fs_spec; |
| 29 |
GRefString *mount_point; |
| 30 |
GRefString *subvolume; |
| 31 |
}; |
| 32 |
|
| 33 |
enum { |
| 34 |
PROP_0, |
| 35 |
PROP_FS_SPEC, |
| 36 |
PROP_MOUNT_POINT, |
| 37 |
PROP_SUBVOLUME, |
| 38 |
N_PROPS |
| 39 |
}; |
| 40 |
|
| 41 |
G_DEFINE_FINAL_TYPE (SysprofMountDevice, sysprof_mount_device, G_TYPE_OBJECT) |
| 42 |
|
| 43 |
static GParamSpec *properties [N_PROPS]; |
| 44 |
|
| 45 |
static void |
| 46 |
sysprof_mount_device_finalize (GObject *object) |
| 47 |
{ |
| 48 |
SysprofMountDevice *self = (SysprofMountDevice *)object; |
| 49 |
|
| 50 |
g_clear_pointer (&self->fs_spec, g_ref_string_release); |
| 51 |
g_clear_pointer (&self->mount_point, g_ref_string_release); |
| 52 |
g_clear_pointer (&self->subvolume, g_ref_string_release); |
| 53 |
|
| 54 |
G_OBJECT_CLASS (sysprof_mount_device_parent_class)->finalize (object); |
| 55 |
} |
| 56 |
|
| 57 |
static void |
| 58 |
sysprof_mount_device_get_property (GObject *object, |
| 59 |
guint prop_id, |
| 60 |
GValue *value, |
| 61 |
GParamSpec *pspec) |
| 62 |
{ |
| 63 |
SysprofMountDevice *self = SYSPROF_MOUNT_DEVICE (object); |
| 64 |
|
| 65 |
switch (prop_id) |
| 66 |
{ |
| 67 |
case PROP_FS_SPEC: |
| 68 |
g_value_set_string (value, sysprof_mount_device_get_fs_spec (self)); |
| 69 |
break; |
| 70 |
|
| 71 |
case PROP_MOUNT_POINT: |
| 72 |
g_value_set_string (value, sysprof_mount_device_get_mount_point (self)); |
| 73 |
break; |
| 74 |
|
| 75 |
case PROP_SUBVOLUME: |
| 76 |
g_value_set_string (value, sysprof_mount_device_get_subvolume (self)); |
| 77 |
break; |
| 78 |
|
| 79 |
default: |
| 80 |
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); |
| 81 |
} |
| 82 |
} |
| 83 |
|
| 84 |
static void |
| 85 |
sysprof_mount_device_class_init (SysprofMountDeviceClass *klass) |
| 86 |
{ |
| 87 |
GObjectClass *object_class = G_OBJECT_CLASS (klass); |
| 88 |
|
| 89 |
object_class->finalize = sysprof_mount_device_finalize; |
| 90 |
object_class->get_property = sysprof_mount_device_get_property; |
| 91 |
|
| 92 |
properties [PROP_FS_SPEC] = |
| 93 |
g_param_spec_string ("fs-spec", NULL, NULL, |
| 94 |
NULL, |
| 95 |
(G_PARAM_READABLE | G_PARAM_STATIC_STRINGS)); |
| 96 |
|
| 97 |
properties [PROP_MOUNT_POINT] = |
| 98 |
g_param_spec_string ("mount-point", NULL, NULL, |
| 99 |
NULL, |
| 100 |
(G_PARAM_READABLE | G_PARAM_STATIC_STRINGS)); |
| 101 |
|
| 102 |
properties [PROP_SUBVOLUME] = |
| 103 |
g_param_spec_string ("subvolume", NULL, NULL, |
| 104 |
NULL, |
| 105 |
(G_PARAM_READABLE | G_PARAM_STATIC_STRINGS)); |
| 106 |
|
| 107 |
g_object_class_install_properties (object_class, N_PROPS, properties); |
| 108 |
} |
| 109 |
|
| 110 |
static void |
| 111 |
sysprof_mount_device_init (SysprofMountDevice *self) |
| 112 |
{ |
| 113 |
} |
| 114 |
|
| 115 |
SysprofMountDevice * |
| 116 |
sysprof_mount_device_new (GRefString *fs_spec, |
| 117 |
GRefString *mount_point, |
| 118 |
GRefString *subvolume) |
| 119 |
{ |
| 120 |
SysprofMountDevice *self; |
| 121 |
|
| 122 |
self = g_object_new (SYSPROF_TYPE_MOUNT_DEVICE, NULL); |
| 123 |
self->fs_spec = fs_spec; |
| 124 |
self->mount_point = mount_point; |
| 125 |
self->subvolume = subvolume; |
| 126 |
|
| 127 |
return g_steal_pointer (&self); |
| 128 |
} |
| 129 |
|
| 130 |
const char * |
| 131 |
sysprof_mount_device_get_fs_spec (SysprofMountDevice *self) |
| 132 |
{ |
| 133 |
g_return_val_if_fail (SYSPROF_IS_MOUNT_DEVICE (self), NULL); |
| 134 |
|
| 135 |
return self->fs_spec; |
| 136 |
} |
| 137 |
|
| 138 |
const char * |
| 139 |
sysprof_mount_device_get_mount_point (SysprofMountDevice *self) |
| 140 |
{ |
| 141 |
g_return_val_if_fail (SYSPROF_IS_MOUNT_DEVICE (self), NULL); |
| 142 |
|
| 143 |
return self->mount_point; |
| 144 |
} |
| 145 |
|
| 146 |
const char * |
| 147 |
sysprof_mount_device_get_subvolume (SysprofMountDevice *self) |
| 148 |
{ |
| 149 |
g_return_val_if_fail (SYSPROF_IS_MOUNT_DEVICE (self), NULL); |
| 150 |
|
| 151 |
return self->subvolume; |
| 152 |
} |