26
28
namespace Zeitgeist
28
[DBus (name = "org.gnome.zeitgeist.DataSourceRegistry")]
29
public interface RemoteRegistry: Object
31
[DBus (signature = "a(sssa(asaasay)bxb)")]
32
public abstract Variant get_data_sources () throws Error;
33
public abstract bool register_data_source (string unique_id,
34
string name, string description,
35
[DBus (signature = "a(asaasay)")] Variant event_templates, BusName? sender)
37
public abstract void set_data_source_enabled (string unique_id,
38
bool enabled) throws Error;
39
[DBus (signature = "(sssa(asaasay)bxb)")]
40
public abstract Variant get_data_source_from_id (string id) throws Error;
42
public signal void data_source_disconnected (
43
[DBus (signature = "(sssa(asaasay)bxb)")] Variant data_source);
44
public signal void data_source_enabled (string unique_id,
46
public signal void data_source_registered (
47
[DBus (signature = "(sssa(asaasay)bxb)")] Variant data_source);
50
class DataSource: Object
52
public string unique_id { get; set; }
53
public string name { get; set; }
54
public string description { get; set; }
56
public GenericArray<Event>? event_templates { get; set; }
58
public bool enabled { get; set; }
59
public bool running { get; set; }
60
public int64 timestamp { get; set; }
67
public DataSource.full (string unique_id, string name,
68
string description, GenericArray<Event> templates)
70
Object (unique_id: unique_id, name: name, description: description,
71
event_templates: templates);
74
public DataSource.from_variant (Variant variant,
75
bool reset_running=false) throws EngineError
78
variant.get_type_string () == "(sssa("+Utils.SIG_EVENT+")bxb)"
79
|| variant.get_type_string () == "sssa("+Utils.SIG_EVENT+")");
80
var iter = variant.iterator ();
82
assert (iter.n_children () >= 4);
83
unique_id = iter.next_value ().get_string ();
84
name = iter.next_value ().get_string ();
85
description = iter.next_value ().get_string ();
86
event_templates = Events.from_variant (iter.next_value ());
88
if (iter.n_children () > 4)
90
running = iter.next_value ().get_boolean ();
93
timestamp = iter.next_value ().get_int64 ();
94
enabled = iter.next_value ().get_boolean ();
98
public Variant to_variant ()
100
var vb = new VariantBuilder (new VariantType (
101
"(sssa("+Utils.SIG_EVENT+")bxb)"));
103
vb.add ("s", unique_id);
105
vb.add ("s", description);
106
if (event_templates != null && event_templates.length > 0)
108
vb.add_value (Events.to_variant (event_templates));
112
vb.open (new VariantType ("a("+Utils.SIG_EVENT+")"));
116
vb.add ("b", running);
117
vb.add ("x", timestamp);
118
vb.add ("b", enabled);
124
31
namespace DataSources
126
private const string SIG_DATASOURCES =
127
"a(sssa("+Utils.SIG_EVENT+")bxb)";
129
private static HashTable<string, DataSource> from_variant (
130
Variant sources_variant, bool reset_running=false) throws EngineError
33
private static HashTable<string, DataSource> registry_from_variant (
34
Variant sources_variant, bool reset_running=false) throws DataModelError
132
36
var registry = new HashTable<string, DataSource> (
133
37
str_hash, str_equal);
136
sources_variant.get_type_string() == SIG_DATASOURCES);
40
sources_variant.get_type_string() == DataSources.SIG_DATASOURCES);
137
41
foreach (Variant ds_variant in sources_variant)
139
43
DataSource ds = new DataSource.from_variant (ds_variant,
147
private static Variant to_variant (
148
HashTable<string, DataSource> sources)
150
var vb = new VariantBuilder (new VariantType (SIG_DATASOURCES));
152
List<unowned DataSource> data_sources = sources.get_values ();
153
data_sources.sort ((a, b) =>
155
return strcmp (a.unique_id, b.unique_id);
158
foreach (unowned DataSource ds in data_sources)
160
vb.add_value (ds.to_variant ());
167
class DataSourceRegistry: Extension, RemoteRegistry
52
public class DataSourceRegistryExtension: Extension, RemoteRegistry
169
54
private const string MULTIPLE_MARKER = "<multiple>";
170
55
private HashTable<string, DataSource> sources;
267
public bool register_data_source (string unique_id, string name,
268
string description, Variant event_templates, BusName? sender) throws EngineError
152
public async bool register_data_source (string unique_id,
153
string name, string description, Variant event_templates,
154
Cancellable? cancellable=null, BusName? sender)
155
throws DataModelError
270
debug ("%s: %s, %s, %s", Log.METHOD, unique_id, name, description);
157
debug ("%s: %s, %s, %s", GLib.Log.METHOD, unique_id,
271
159
if (sender == null)
273
warning ("%s: sender == null, ignoring request", Log.METHOD);
161
warning ("%s: sender == null, ignoring request", GLib.Log.METHOD);
333
public void set_data_source_enabled (string unique_id, bool enabled)
222
public async void set_data_source_enabled (string unique_id, bool enabled,
223
Cancellable? cancellable=null)
335
debug ("%s: %s, %d", Log.METHOD, unique_id, (int) enabled);
225
debug ("%s: %s, %d", GLib.Log.METHOD, unique_id, (int) enabled);
336
226
unowned DataSource? ds = sources.lookup (unique_id);