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 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225
|
/*
* Copyright © 2018 Red Hat, Inc
*
* This program 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 Lesser General Public
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
*
* Authors:
* Christian J. Kellner <christian@kellner.me>
*/
#include "config.h"
#include "bolt-domain.h"
#include <gio/gio.h>
struct _BoltDomain
{
BoltProxy parent;
};
enum {
PROP_0,
/* D-Bus Props */
PROP_UID,
PROP_ID,
PROP_SYSPATH,
PROP_SECURITY,
PROP_BOOTACL,
PROP_LAST
};
static GParamSpec *props[PROP_LAST] = {NULL, };
G_DEFINE_TYPE (BoltDomain,
bolt_domain,
BOLT_TYPE_PROXY);
static void
bolt_domain_get_property (GObject *object,
guint prop_id,
GValue *value,
GParamSpec *pspec)
{
if (bolt_proxy_get_dbus_property (object, pspec, value))
return;
}
static void
bolt_domain_class_init (BoltDomainClass *klass)
{
GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
gobject_class->get_property = bolt_domain_get_property;
props[PROP_UID] =
g_param_spec_string ("uid",
"Uid", NULL,
"unknown",
G_PARAM_READABLE |
G_PARAM_STATIC_NICK);
props[PROP_ID] =
g_param_spec_string ("id",
"Id", NULL,
"unknown",
G_PARAM_READABLE |
G_PARAM_STATIC_NICK);
props[PROP_SYSPATH] =
g_param_spec_string ("syspath",
"SysfsPath", NULL,
"unknown",
G_PARAM_READABLE |
G_PARAM_STATIC_NICK);
props[PROP_SECURITY]
= g_param_spec_enum ("security",
"SecurityLevel", NULL,
BOLT_TYPE_SECURITY,
BOLT_SECURITY_UNKNOWN,
G_PARAM_READABLE |
G_PARAM_STATIC_NAME);
props[PROP_BOOTACL] =
g_param_spec_boxed ("bootacl",
"BootACL", NULL,
G_TYPE_STRV,
G_PARAM_READABLE |
G_PARAM_STATIC_NAME);
g_object_class_install_properties (gobject_class,
PROP_LAST,
props);
}
static void
bolt_domain_init (BoltDomain *domain)
{
}
/* public methods */
BoltDomain *
bolt_domain_new_for_object_path (GDBusConnection *bus,
const char *path,
GCancellable *cancel,
GError **error)
{
BoltDomain *dom;
g_return_val_if_fail (G_IS_DBUS_CONNECTION (bus), NULL);
g_return_val_if_fail (path != NULL, NULL);
g_return_val_if_fail (!cancel || G_IS_CANCELLABLE (cancel), NULL);
g_return_val_if_fail (error == NULL || *error == NULL, NULL);
dom = g_initable_new (BOLT_TYPE_DOMAIN,
cancel, error,
"g-flags", G_DBUS_PROXY_FLAGS_NONE,
"g-connection", bus,
"g-name", BOLT_DBUS_NAME,
"g-object-path", path,
"g-interface-name", BOLT_DBUS_DOMAIN_INTERFACE,
NULL);
return dom;
}
const char *
bolt_domain_get_uid (BoltDomain *domain)
{
const char *key;
const char *str;
g_return_val_if_fail (BOLT_IS_DOMAIN (domain), NULL);
key = g_param_spec_get_name (props[PROP_UID]);
str = bolt_proxy_get_property_string (BOLT_PROXY (domain), key);
return str;
}
const char *
bolt_domain_get_id (BoltDomain *domain)
{
const char *key;
const char *str;
g_return_val_if_fail (BOLT_IS_DOMAIN (domain), NULL);
key = g_param_spec_get_name (props[PROP_ID]);
str = bolt_proxy_get_property_string (BOLT_PROXY (domain), key);
return str;
}
const char *
bolt_domain_get_syspath (BoltDomain *domain)
{
const char *key;
const char *str;
g_return_val_if_fail (BOLT_IS_DOMAIN (domain), NULL);
key = g_param_spec_get_name (props[PROP_SYSPATH]);
str = bolt_proxy_get_property_string (BOLT_PROXY (domain), key);
return str;
}
BoltSecurity
bolt_domain_get_security (BoltDomain *domain)
{
const char *key;
gboolean ok;
gint val = BOLT_SECURITY_UNKNOWN;
g_return_val_if_fail (BOLT_IS_DOMAIN (domain), val);
key = g_param_spec_get_name (props[PROP_SECURITY]);
ok = bolt_proxy_get_property_enum (BOLT_PROXY (domain), key, &val);
if (!ok)
g_warning ("failed to get enum property '%s'", key);
return val;
}
char **
bolt_domain_get_bootacl (BoltDomain *domain)
{
const char *key;
char **strv;
g_return_val_if_fail (BOLT_IS_DOMAIN (domain), NULL);
key = g_param_spec_get_name (props[PROP_BOOTACL]);
strv = bolt_proxy_get_property_strv (BOLT_PROXY (domain), key);
return strv;
}
gboolean
bolt_domain_is_online (BoltDomain *domain)
{
const char *syspath;
syspath = bolt_domain_get_syspath (domain);
return syspath != NULL;
}
|