summaryrefslogtreecommitdiff
path: root/examples
diff options
context:
space:
mode:
authorSeif Lotfy <seif@lotfy.com>2012-11-11 21:56:08 +0100
committerSeif Lotfy <seif@lotfy.com>2012-11-11 21:56:08 +0100
commitdbfef2fe720394b14984daf44ff59d63505c8cd7 (patch)
treef14c8a3ee35099d5d8369258c4e6075f2236a3b4 /examples
parent6db22ed3c0b351f873d3116ca56ab59ba6a555f8 (diff)
downloadzeitgeist-dbfef2fe720394b14984daf44ff59d63505c8cd7.tar.gz
Add C examples
Diffstat (limited to 'examples')
-rw-r--r--examples/Makefile.am46
-rw-r--r--examples/data-source-stuff.vala79
-rw-r--r--examples/get-events-with-id.vala28
-rw-r--r--examples/insert-events.vala38
-rw-r--r--examples/monitor-events.vala32
-rw-r--r--examples/most-recent-events.vala28
6 files changed, 3 insertions, 248 deletions
diff --git a/examples/Makefile.am b/examples/Makefile.am
index 5a6d7138..3474751b 100644
--- a/examples/Makefile.am
+++ b/examples/Makefile.am
@@ -1,45 +1,5 @@
-NULL =
+NULL =
-AM_CPPFLAGS = \
- $(ZEITGEIST_CFLAGS) \
- -include $(CONFIG_HEADER) \
- -I $(top_srcdir)/libzeitgeist/ \
- -w \
+SUBDIRS = \
+ vala \
$(NULL)
-
-AM_VALAFLAGS = \
- --target-glib=2.26 \
- --pkg gio-2.0 \
- $(top_srcdir)/libzeitgeist/zeitgeist-2.0.vapi \
- $(top_srcdir)/config.vapi \
- $(NULL)
-
-zeitgeist_libs = \
- $(top_builddir)/libzeitgeist/libzeitgeist-2.0.la \
- $(ZEITGEIST_LIBS)
-
-noinst_PROGRAMS = \
- data-source-stuff \
- get-events-with-id \
- monitor-events \
- most-recent-events \
- insert-events \
- $(NULL)
-
-data_source_stuff_SOURCES = data-source-stuff.vala
-data_source_stuff_LDADD = $(zeitgeist_libs)
-
-get_events_with_id_SOURCES = get-events-with-id.vala
-get_events_with_id_LDADD = $(zeitgeist_libs)
-
-monitor_events_SOURCES = monitor-events.vala
-monitor_events_LDADD = $(zeitgeist_libs)
-
-most_recent_events_SOURCES = most-recent-events.vala
-most_recent_events_LDADD = $(zeitgeist_libs)
-
-insert_events_SOURCES = insert-events.vala
-insert_events_LDADD = $(zeitgeist_libs)
-
-distclean-local:
- rm -f *.c *.o *.~[0-9]~
diff --git a/examples/data-source-stuff.vala b/examples/data-source-stuff.vala
deleted file mode 100644
index 6e744287..00000000
--- a/examples/data-source-stuff.vala
+++ /dev/null
@@ -1,79 +0,0 @@
-using Zeitgeist;
-
-MainLoop loop;
-
-async void do_stuff () throws Error
-{
- var registry = new Zeitgeist.DataSourceRegistry ();
-
- registry.source_registered.connect (on_source_registered);
- registry.source_enabled.connect (on_source_enabled);
-
- DataSource my_data_source = new DataSource.full (
- "com.example.test/my-ds", "Example Data-Source",
- "An example data-source for testing libzeitgeist2",
- new GenericArray<Event>());
-
- stdout.printf ("Registering with data-source registry...\n");
- bool enabled = yield registry.register_data_source (my_data_source);
- stdout.printf ("Done. The data-source is %s.\n\n",
- (enabled) ? "enabled" : "disabled");
-
- stdout.printf ("Disabling the data-source...\n");
- yield registry.set_data_source_enabled (my_data_source.unique_id, false);
-
- yield print_data_sources (registry);
-
- stdout.printf ("\nEnabling it again...\n");
- yield registry.set_data_source_enabled (my_data_source.unique_id, true);
-
- yield print_data_sources (registry);
-
- loop.quit ();
-}
-
-void on_source_registered (DataSource source)
-{
- stdout.printf("%s registered!\n", source.name);
-}
-
-async void on_source_enabled (string unique_id, bool enabled)
-{
- var registry = new Zeitgeist.DataSourceRegistry ();
- DataSource source;
- try
- {
- source = yield registry.get_data_source_from_id (unique_id);
- stdout.printf("%s has been %s!\n", source.name,
- (enabled) ? "enabled" : "disabled");
- }
- catch (Error e)
- {
- critical ("Error retrieving data-source information: %s", e.message);
- }
-}
-
-async void print_data_sources (DataSourceRegistry registry) throws Error
-{
- GenericArray<DataSource> datasources = null;
- datasources = yield registry.get_data_sources ();
-
- stdout.printf ("\nThe following data-sources are registered:\n");
- for (int i = 0; i < datasources.length; ++i)
- {
- DataSource datasource = datasources[i];
- stdout.printf (" - %s [%s]\n", datasource.name,
- (datasource.enabled) ? "enabled" : "disabled");
- }
-}
-
-int main ()
-{
- loop = new MainLoop();
-
- do_stuff();
-
- loop.run ();
-
- return 0;
-}
diff --git a/examples/get-events-with-id.vala b/examples/get-events-with-id.vala
deleted file mode 100644
index 32682372..00000000
--- a/examples/get-events-with-id.vala
+++ /dev/null
@@ -1,28 +0,0 @@
-int main ()
-{
- var ids = new Array<uint32>();
- uint32 id1 = 2100000;
- uint32 id2 = 222;
- ids.append_val(id1);
- ids.append_val(id2);
-
- var loop = new MainLoop();
-
- Zeitgeist.Log zg = new Zeitgeist.Log ();
- zg.get_events (ids, null, (obj, res) => {
- GenericArray<Zeitgeist.Event?> events = zg.get_events.end (res);
- for (int i = 0; i < events.length; ++i)
- {
- Zeitgeist.Event event = events[i];
- if (event != null)
- stdout.printf ("First subject: %s\n", event.subjects[0].uri);
- else
- stdout.printf ("Event %d doesn't exist.\n", (int) ids.index (i));
- }
- loop.quit();
- });
-
- loop.run ();
-
- return 0;
-}
diff --git a/examples/insert-events.vala b/examples/insert-events.vala
deleted file mode 100644
index aad9393d..00000000
--- a/examples/insert-events.vala
+++ /dev/null
@@ -1,38 +0,0 @@
-using Zeitgeist;
-
-int main ()
-{
- var mainloop = new MainLoop(MainContext.default ());
- var events = new GenericArray<Event> ();
- var ev = new Event ();
- var su = new Subject ();
- ev.add_subject (su);
- events.add (ev);
- ev.interpretation = "foo://Interp";
- ev.manifestation = "foo://Manif";
- ev.actor = "app://firefox.desktop";
-
- su.uri = "file:///tmp/bar.txt";
- su.interpretation = "foo://TextDoc";
- su.manifestation = "foo://File";
- su.mimetype = "text/plain";
- su.origin = "file:///tmp";
- su.text = "bar.txt";
- su.storage = "bfb486f6-f5f8-4296-8871-0cc749cf8ef7";
-
- Zeitgeist.Log.get_default ().insert_events (
- events, null, (log, res) => {
- Array<uint32> event_ids;
- Zeitgeist.Log zg = (Zeitgeist.Log) log;
- try {
- event_ids = zg.insert_events.end (res);
- }
- catch (Error error) {
- critical ("Failed to insert events: %s", error.message);
- return;
- }
- mainloop.quit ();
- });
- mainloop.run ();
- return 0;
-}
diff --git a/examples/monitor-events.vala b/examples/monitor-events.vala
deleted file mode 100644
index ed6feab4..00000000
--- a/examples/monitor-events.vala
+++ /dev/null
@@ -1,32 +0,0 @@
-void on_events_inserted (Zeitgeist.TimeRange tr, Zeitgeist.ResultSet events)
-{
- message ("%u events inserted", events.size ());
-
- foreach (Zeitgeist.Event event in events)
- {
- for (int i = 0; i < event.num_subjects (); ++i )
- {
- Zeitgeist.Subject subject = event.subjects[i];
- message (" * %s", subject.uri);
- }
- }
-}
-
-int main ()
-{
- var loop = new MainLoop();
-
- var time_range = new Zeitgeist.TimeRange.anytime ();
- var template = new GenericArray<Zeitgeist.Event> ();
-
- var monitor = new Zeitgeist.Monitor(time_range, template);
- Zeitgeist.Log log = new Zeitgeist.Log ();
-
- monitor.events_inserted.connect (on_events_inserted);
- //monitor.events_deleted.connect (on_events_deleted);
-
- log.install_monitor (monitor);
-
- loop.run ();
- return 0;
-}
diff --git a/examples/most-recent-events.vala b/examples/most-recent-events.vala
deleted file mode 100644
index 316e9f43..00000000
--- a/examples/most-recent-events.vala
+++ /dev/null
@@ -1,28 +0,0 @@
-using Zeitgeist;
-
-int main ()
-{
- var loop = new MainLoop();
- var log = new Zeitgeist.Log ();
-
- var time_range = new TimeRange.anytime ();
- var templates = new GenericArray<Event> ();
- int num_events = 20;
-
- log.find_events (time_range, templates, StorageState.ANY, num_events,
- ResultType.MOST_RECENT_SUBJECTS, null, (obj, res) =>
- {
- ResultSet events = log.find_events.end (res);
- stdout.printf ("%u most recent subjects:", events.size ());
- foreach (Event event in events)
- {
- stdout.printf (" - %s\n", event.subjects[0].uri);
- }
- loop.quit();
- }
- );
-
- loop.run ();
-
- return 0;
-}