summaryrefslogtreecommitdiffstats
path: root/src/ck-seat.c
diff options
context:
space:
mode:
authorDavid Zeuthen <davidz@redhat.com>2007-10-10 13:39:15 -0400
committerWilliam Jon McCann <mccann@jhu.edu>2007-10-10 13:39:15 -0400
commitb2be103bd606291319dc312f07d1f3fcbfdf634c (patch)
tree54e295f2e273b6d2a6451ac5eec537d762d1d814 /src/ck-seat.c
parentbd43c78b3ab2ec7f85b17cca46d4b46f8671cd29 (diff)
maintain a file with the dump of the local database
This feature is useful for programs wanting to read the database without going through the D-Bus interface. This is sometimes desirable when both performance and runtime dependencies are important. For security reasons the file is only readable for the super user.
Diffstat (limited to 'src/ck-seat.c')
-rw-r--r--src/ck-seat.c86
1 files changed, 84 insertions, 2 deletions
diff --git a/src/ck-seat.c b/src/ck-seat.c
index 66bf728..526640e 100644
--- a/src/ck-seat.c
+++ b/src/ck-seat.c
@@ -656,7 +656,6 @@ ck_seat_add_device (CkSeat *seat,
g_ptr_array_add (seat->priv->devices, g_boxed_copy (CK_TYPE_DEVICE, device));
g_debug ("Emitting device added signal");
-
g_signal_emit (seat, signals [DEVICE_ADDED], 0, device);
return TRUE;
@@ -672,7 +671,6 @@ ck_seat_remove_device (CkSeat *seat,
/* FIXME: check if already present */
if (0) {
g_debug ("Emitting device removed signal");
-
g_signal_emit (seat, signals [DEVICE_REMOVED], 0, device);
}
@@ -1122,3 +1120,87 @@ ck_seat_new_from_file (const char *sid,
return seat;
}
+
+static void
+dump_seat_session_iter (char *id,
+ CkSession *session,
+ GString *str)
+{
+ char *session_id;
+ GError *error;
+
+ error = NULL;
+ if (! ck_session_get_id (session, &session_id, &error)) {
+ g_warning ("Cannot get session id from seat: %s", error->message);
+ g_error_free (error);
+ } else {
+ if (str->len > 0) {
+ g_string_append_c (str, ' ');
+ }
+ g_string_append (str, session_id);
+ g_free (session_id);
+ }
+}
+
+void
+ck_seat_dump (CkSeat *seat,
+ GKeyFile *key_file)
+{
+ char *group_name;
+ GString *str;
+ char *s;
+ int n;
+
+ group_name = g_strdup_printf ("Seat %s", seat->priv->id);
+
+ g_key_file_set_integer (key_file, group_name, "kind", seat->priv->kind);
+
+ str = g_string_new (NULL);
+ g_hash_table_foreach (seat->priv->sessions, (GHFunc) dump_seat_session_iter, str);
+ s = g_string_free (str, FALSE);
+ g_key_file_set_string (key_file, group_name, "sessions", s);
+ g_free (s);
+
+ str = g_string_new (NULL);
+ if (seat->priv->devices != NULL) {
+ for (n = 0; n < seat->priv->devices->len; n++) {
+ int m;
+ GValueArray *va;
+
+ va = seat->priv->devices->pdata[n];
+
+ if (str->len > 0)
+ g_string_append_c (str, ' ');
+ for (m = 0; m < va->n_values; m++) {
+ if (m > 0)
+ g_string_append_c (str, ':');
+ g_string_append (str, g_value_get_string ((const GValue *) &((va->values)[m])));
+ }
+
+ g_debug ("foo %d", va->n_values);
+ }
+ }
+ s = g_string_free (str, FALSE);
+ g_key_file_set_string (key_file, group_name, "devices", s);
+ g_free (s);
+
+
+ if (seat->priv->active_session != NULL) {
+ char *session_id;
+ GError *error;
+
+ error = NULL;
+ if (! ck_session_get_id (seat->priv->active_session, &session_id, &error)) {
+ g_warning ("Cannot get session id for active session on seat %s: %s",
+ seat->priv->id,
+ error->message);
+ g_error_free (error);
+ } else {
+ g_key_file_set_string (key_file, group_name, "active_session", session_id);
+ g_free (session_id);
+ }
+ }
+
+ g_free (group_name);
+}
+