using GLib;

/* 
public struct QueryHint {
	string query;
	Value value;
}
*/

[DBus (name = "org.freedesktop.xesam.Searcher")]
public class Searcher : Object {

	public void NewSearch (DBus.ObjectPath search_object_path, /* QueryHint[] query_hints, */ string query_xml, string[] fields_to_monitor, uint offset, uint count, bool is_live, DBus.ObjectPath search_to_close, out uint hit_count, out string[] field_map, out string[][] hit_data) {
	}

	public void NewSearchBySortKey (DBus.ObjectPath search_object_path, /* QueryHint[] query_hints, */ string query_xml, string[] fields_to_monitor, string start_sortkey, string end_sortkey, uint offset, uint count, bool is_live, DBus.ObjectPath search_to_close, out uint hit_count, out string[] field_map, out string[][] hit_data) {
	}
}

[DBus (name = "org.freedesktop.xesam.Search")]
public class Search : Object {

	signal void HitsAdded (out string[][] hits);
	signal void HitsModified (out string[][] oldhits);
	signal void HitsRemoved (out string[][] hits);

	public void GetHits (uint offset, uint count, out string[][] hits) {
	}

	public void GetHitsBySortKey (string start_sortkey, string end_sortkey, uint offset, uint count, out string[][] hits) {
	}

	public void Close () {
	}
}

void main () {
	var loop = new MainLoop (null, false);

	try {
		var conn = DBus.Bus.get (DBus.BusType. SESSION);
		dynamic DBus.Object bus = conn.get_object ("org.freedesktop.DBus",
							   "/org/freedesktop/DBus",
							   "org.freedesktop.DBus");       
		uint request_name_result = bus.request_name ("org.freedesktop.xesam", (uint) 0);

		if (request_name_result == DBus.RequestNameReply.PRIMARY_OWNER) {
			dynamic DBus.Object dbus_searcher;
			DBus.ObjectPath path;
			//string [] fields = new string[0];
			/* QueryHint[] hints = new QueryHint[0]; */
			//string [] field_map;
			//string[][] hit_data;
			//uint hit_count;

			var searcher = new Searcher ();
			var search = new Search ();

			path = new DBus.ObjectPath ("/my/application/xesam/Search");

			conn.register_object ("/org/freedesktop/xesam/Searcher", searcher);
			conn.register_object (path, search);

			dbus_searcher = conn.get_object ("org.freedesktop.xesam",
							 "/org/freedesktop/xesam/Searcher",
							 "org.freedesktop.xesam.Searcher");

			//dbus_searcher.NewSearch (path, /* hints, */ "query", fields, 0, 0, false, path, out hit_count, out field_map, out hit_data);

			loop.run ();
	        }
	} catch (Error e) {
		stderr.printf ("Oops: %s\n", e.message);
	}
}
