From 84dec8ce97e3627160f8ce3631f00470a1661381 Mon Sep 17 00:00:00 2001 From: dbera Date: Mon, 4 Dec 2006 03:32:24 +0000 Subject: [PATCH] Add example code to use beagle as a service provider. Set (correct) timezone info in BeagleTimestamp struct in libbeagle. --- BeagleClient/IndexingService.cs | 2 +- BeagleClient/Message.cs | 8 +-- libbeagle/beagle/beagle-timestamp.c | 24 +++++++- libbeagle/examples/.cvsignore | 1 + libbeagle/examples/Makefile.am | 10 +-- libbeagle/examples/beagle-search-provider.c | 94 +++++++++++++++++++++++++++++ 6 files changed, 129 insertions(+), 10 deletions(-) create mode 100644 libbeagle/examples/beagle-search-provider.c diff --git a/BeagleClient/IndexingService.cs b/BeagleClient/IndexingService.cs index 80c9da47..1a877a93 100644 --- a/BeagleClient/IndexingService.cs +++ b/BeagleClient/IndexingService.cs @@ -42,7 +42,7 @@ namespace Beagle { } - [XmlArray (ElementName="Indexables")] + [XmlArray (ElementName="ToAdd")] [XmlArrayItem (ElementName="Indexable", Type=typeof (Indexable))] public ArrayList ToAdd { get { return to_add; } diff --git a/BeagleClient/Message.cs b/BeagleClient/Message.cs index 70ee301b..1837ebdc 100644 --- a/BeagleClient/Message.cs +++ b/BeagleClient/Message.cs @@ -242,7 +242,7 @@ namespace Beagle { public class EmptyResponse : ResponseMessage { } public class ErrorResponse : ResponseMessage { - public string Message; + public string ErrorMessage; public string Details; // Needed by the XmlSerializer for deserialization @@ -250,13 +250,13 @@ namespace Beagle { public ErrorResponse (Exception e) { - this.Message = e.Message; + this.ErrorMessage = e.Message; this.Details = e.ToString (); } public ErrorResponse (string message) { - this.Message = message; + this.ErrorMessage = message; } } @@ -264,7 +264,7 @@ namespace Beagle { private string details; - internal ResponseMessageException (ErrorResponse response) : base (response.Message) + internal ResponseMessageException (ErrorResponse response) : base (response.ErrorMessage) { Log.Debug ("Creating a ResponseMessageException from an ErrorResponse"); details = response.Details; diff --git a/libbeagle/beagle/beagle-timestamp.c b/libbeagle/beagle/beagle-timestamp.c index 69c521e2..7616f788 100644 --- a/libbeagle/beagle/beagle-timestamp.c +++ b/libbeagle/beagle/beagle-timestamp.c @@ -94,8 +94,13 @@ beagle_timestamp_new_from_unix_time (time_t time) { BeagleTimestamp *timestamp; struct tm *result; + gboolean before_utc; + int offset_mins, tz_hour, tz_min; - result = gmtime (&time); + /* Send everything in localtime since XmlSerializer .Net-1.0 likes that. + * FIXED: To be changed back to gmtime() in .Net-2.0 era. + */ + result = localtime (&time); timestamp = beagle_timestamp_new (); @@ -107,6 +112,23 @@ beagle_timestamp_new_from_unix_time (time_t time) timestamp->minute = result->tm_min; timestamp->second = result->tm_sec; + /* Compute timezone offset. */ + time = 0; + result = localtime (&time); + before_utc = (result->tm_mday == 1); + + offset_mins = 60 * result->tm_hour + result->tm_min; + if (before_utc == FALSE) + offset_mins = 1440 - offset_mins; /* 1440 = mins in 1 day */ + + tz_hour = offset_mins/60; + tz_min = offset_mins % 60; + if (before_utc == FALSE) + tz_hour = -tz_hour; + + timestamp->tz_hour = tz_hour; + timestamp->tz_minute = tz_min; + return timestamp; } diff --git a/libbeagle/examples/.cvsignore b/libbeagle/examples/.cvsignore index 6f07a269..232a7aff 100644 --- a/libbeagle/examples/.cvsignore +++ b/libbeagle/examples/.cvsignore @@ -8,3 +8,4 @@ Makefile.in beagle-search beagle-shutdown beagle-info +beagle-search-provider diff --git a/libbeagle/examples/Makefile.am b/libbeagle/examples/Makefile.am index ad88ccb1..3e233158 100644 --- a/libbeagle/examples/Makefile.am +++ b/libbeagle/examples/Makefile.am @@ -8,9 +8,11 @@ LDADD = $(top_builddir)/libbeagle/beagle/libbeagle.la noinst_PROGRAMS = \ beagle-search \ beagle-shutdown \ - beagle-info + beagle-info \ + beagle-search-provider -beagle_search_SOURCES = beagle-search.c -beagle_shutdown_SOURCES = beagle-shutdown.c -beagle_info_SOURCES = beagle-info.c +beagle_search_SOURCES = beagle-search.c +beagle_shutdown_SOURCES = beagle-shutdown.c +beagle_info_SOURCES = beagle-info.c +beagle_search_provider SOURCES = beagle-search-provider.c diff --git a/libbeagle/examples/beagle-search-provider.c b/libbeagle/examples/beagle-search-provider.c new file mode 100644 index 00000000..25fc807d --- /dev/null +++ b/libbeagle/examples/beagle-search-provider.c @@ -0,0 +1,94 @@ +#include +#include +#include + +static void +test_indexer (BeagleClient *client) +{ + BeagleIndexable *indexable; + BeagleProperty *prop1, *prop2, *prop3; + BeagleIndexingServiceRequest *request; + BeagleTimestamp *timestamp; + + /* Use a unique URI for this indexable. + */ + indexable = beagle_indexable_new ("mybackend:///foobar1"); + + /* We are adding an indexable. + * The other possibilities are + * Removing indexable - BEAGLE_INDEXABLE_TYPE_REMOVE + * Changing property of an indexable - BEAGLE_INDEXABLE_TYPE_PROPERTY_CHANGE + */ + beagle_indexable_set_type (indexable, BEAGLE_INDEXABLE_TYPE_ADD); + + /* No content means only properties will be indexed. + * No data is present for this indexable. + */ + beagle_indexable_set_no_content (indexable, TRUE); + + /* Set the source of this indexable. + * Use this to define the "backend" for this data. + */ + beagle_indexable_set_source (indexable, "MyBackend"); + + /* Type of this indexable. + * One backend can produce indexables of various types. + * Different backends can generate indexables of same type + * e.g., different IM backends create indexables of type "Conversation" + */ + beagle_indexable_set_hit_type (indexable, "MyType"); + + /* This indexable does not have any content, so do not try to filter its data. + */ + beagle_indexable_set_filtering (indexable, BEAGLE_INDEXABLE_FILTERING_NEVER); + + /* Create a custom property. + */ + prop1 = beagle_property_new (BEAGLE_PROPERTY_TYPE_TEXT, "dc:title", "foo bar"); + beagle_indexable_add_property (indexable, prop1); + + prop2 = beagle_property_new (BEAGLE_PROPERTY_TYPE_TEXT, "dc:rights", "GPL"); + beagle_indexable_add_property (indexable, prop2); + + prop3 = beagle_property_new (BEAGLE_PROPERTY_TYPE_KEYWORD, "fixme:foo", "1234-4567-8900"); + beagle_indexable_add_property (indexable, prop3); + + /* Set timestamp. + */ + timestamp = beagle_timestamp_new_from_unix_time (time (NULL)); + beagle_indexable_set_timestamp (indexable, timestamp); + + request = beagle_indexing_service_request_new_for_service ("IndexingServiceRequest"); + beagle_indexing_service_request_add (request, indexable); + + beagle_client_send_request (client, BEAGLE_REQUEST (request), NULL); + g_print ("Data sent to beagle search service.\n"); + + beagle_timestamp_free (timestamp); + beagle_property_free (prop1); + beagle_property_free (prop2); + beagle_property_free (prop3); +} + + +int +main () +{ + BeagleClient *client; + + g_type_init (); + + if (! beagle_util_daemon_is_running ()) { + g_print ("beagle search service is not running.\n"); + return 1; + } + + client = beagle_client_new (NULL); + + g_print ("Sending data to beagle search service\n"); + test_indexer (client); + + return 0; +} + + -- 2.11.4.GIT