tracker r1280 - in branches/indexer-split: . data src/libtracker src/libtracker-common src/tracker-preferences src/trackerd
- From: mr svn gnome org
- To: svn-commits-list gnome org
- Subject: tracker r1280 - in branches/indexer-split: . data src/libtracker src/libtracker-common src/tracker-preferences src/trackerd
- Date: Mon, 21 Apr 2008 12:21:21 +0100 (BST)
Author: mr
Date: Mon Apr 21 11:21:20 2008
New Revision: 1280
URL: http://svn.gnome.org/viewvc/tracker?rev=1280&view=rev
Log:
* configure.ac: Added check for DBus bindings tool to create
server side and client side glue header files.
* data/Makefile.am:
* data/tracker-dbus-daemon.xml:
* data/tracker-dbus-files.xml:
* data/tracker-dbus-keywords.xml:
* data/tracker-dbus-metadata.xml:
* data/tracker-dbus-search.xml: Added to separate DBus interfaces
into their respective files.
* data/tracker-introspect.xml: Removed in favour of new DBus
interface files.
* src/libtracker-common/Makefile.am:
* src/libtracker-common/tracker-utils.[ch]:
* src/trackerd/tracker-db-sqlite.c: Added tracker-utils.[ch] to
handle some of the commonly shared utility functions which are
used across more than just the tracker daemon.
* src/libtracker/Makefile.am:
* src/libtracker/tracker.c: Fixed object paths for DBus
connectivity to the various interfaces we use.
* src/libtracker/tracker.h: For the typedef enum MetadataTypes,
use METADATA_ as the prefix to all these values so we don't cause
namespace issues elsewhere.
* src/tracker-preferences/tracker-preferences.c: Don't depend on
the tracker daemon DBus definitions for the various interfaces we
connect to, instead define them specifically ourselves.
* src/trackerd/Makefile.am:
* src/trackerd/tracker-dbus-daemon.[ch]: Added to handle daemon
specific DBus requests like shutting down and getting the current
status, etc.
* src/trackerd/tracker-cache.c:
* src/trackerd/tracker-email-evolution.c:
* src/trackerd/tracker-email-kmail.c:
* src/trackerd/tracker-email-modest.c:
* src/trackerd/tracker-email-utils.c:
* src/trackerd/tracker-indexer.c:
* src/trackerd/tracker-inotify.c:
* src/trackerd/tracker-process-files.c:
* src/trackerd/tracker-rdf-query.c:
* src/trackerd/trackerd.c: Updates reflecting the new DBus changes.
* src/trackerd/tracker-marshal.list:
* src/trackerd/tracker-marshal-main.c: Added to include generated
marshal files built for extended signalling with unique callback
signatures.
Added:
branches/indexer-split/data/tracker-dbus-daemon.xml
branches/indexer-split/data/tracker-dbus-files.xml
branches/indexer-split/data/tracker-dbus-keywords.xml
branches/indexer-split/data/tracker-dbus-metadata.xml
branches/indexer-split/data/tracker-dbus-search.xml
branches/indexer-split/src/libtracker-common/tracker-utils.c
branches/indexer-split/src/libtracker-common/tracker-utils.h
branches/indexer-split/src/trackerd/tracker-dbus-daemon.c
branches/indexer-split/src/trackerd/tracker-dbus-daemon.h
branches/indexer-split/src/trackerd/tracker-marshal-main.c
branches/indexer-split/src/trackerd/tracker-marshal.list
branches/indexer-split/src/trackerd/tracker-status.c
branches/indexer-split/src/trackerd/tracker-status.h
Removed:
branches/indexer-split/data/tracker-introspect.xml
branches/indexer-split/src/trackerd/tracker-dbus-methods.c
branches/indexer-split/src/trackerd/tracker-dbus-methods.h
branches/indexer-split/src/trackerd/tracker-process-requests.c
branches/indexer-split/src/trackerd/tracker-process-requests.h
Modified:
branches/indexer-split/ChangeLog
branches/indexer-split/configure.ac
branches/indexer-split/data/Makefile.am
branches/indexer-split/src/libtracker-common/Makefile.am
branches/indexer-split/src/libtracker-common/tracker-language.c
branches/indexer-split/src/libtracker-common/tracker-language.h
branches/indexer-split/src/libtracker-common/tracker-log.c
branches/indexer-split/src/libtracker-common/tracker-log.h
branches/indexer-split/src/libtracker/Makefile.am
branches/indexer-split/src/libtracker/tracker.c
branches/indexer-split/src/libtracker/tracker.h
branches/indexer-split/src/tracker-preferences/tracker-preferences.c
branches/indexer-split/src/trackerd/Makefile.am
branches/indexer-split/src/trackerd/tracker-cache.c
branches/indexer-split/src/trackerd/tracker-db-sqlite.c
branches/indexer-split/src/trackerd/tracker-dbus-files.c
branches/indexer-split/src/trackerd/tracker-dbus-files.h
branches/indexer-split/src/trackerd/tracker-dbus-keywords.c
branches/indexer-split/src/trackerd/tracker-dbus-keywords.h
branches/indexer-split/src/trackerd/tracker-dbus-metadata.c
branches/indexer-split/src/trackerd/tracker-dbus-metadata.h
branches/indexer-split/src/trackerd/tracker-dbus-search.c
branches/indexer-split/src/trackerd/tracker-dbus-search.h
branches/indexer-split/src/trackerd/tracker-dbus.c
branches/indexer-split/src/trackerd/tracker-dbus.h
branches/indexer-split/src/trackerd/tracker-email-evolution.c
branches/indexer-split/src/trackerd/tracker-email-kmail.c
branches/indexer-split/src/trackerd/tracker-email-modest.c
branches/indexer-split/src/trackerd/tracker-email-utils.c
branches/indexer-split/src/trackerd/tracker-indexer.c
branches/indexer-split/src/trackerd/tracker-inotify.c
branches/indexer-split/src/trackerd/tracker-process-files.c
branches/indexer-split/src/trackerd/tracker-rdf-query.c
branches/indexer-split/src/trackerd/tracker-utils.c
branches/indexer-split/src/trackerd/tracker-utils.h
branches/indexer-split/src/trackerd/trackerd.c
Modified: branches/indexer-split/configure.ac
==============================================================================
--- branches/indexer-split/configure.ac (original)
+++ branches/indexer-split/configure.ac Mon Apr 21 11:21:20 2008
@@ -211,7 +211,14 @@
AM_CONDITIONAL(HAVE_RECENT_GLIB, test "$have_recent_glib" = "yes")
+# Check we have the DBUS binding tool we need
+AC_PATH_PROG(DBUSBINDINGTOOL, dbus-binding-tool)
+if test -z $DBUSBINDINGTOOL; then
+ AC_MSG_ERROR([Could not find 'dbus-binding-tool'])
+fi
+GLIB_GENMARSHAL=`$PKG_CONFIG glib-2.0 --variable=glib_genmarshal`
+AC_SUBST(GLIB_GENMARSHAL)
####################################################################
# External QDBM check
Modified: branches/indexer-split/data/Makefile.am
==============================================================================
--- branches/indexer-split/data/Makefile.am (original)
+++ branches/indexer-split/data/Makefile.am Mon Apr 21 11:21:20 2008
@@ -2,7 +2,12 @@
configdir = $(datadir)/tracker
-config_DATA = tracker-introspect.xml \
+config_DATA = \
+ tracker-dbus-daemon.xml \
+ tracker-dbus-files.xml \
+ tracker-dbus-keywords.xml \
+ tracker-dbus-metadata.xml \
+ tracker-dbus-search.xml \
sqlite-tracker.sql \
sqlite-cache.sql \
sqlite-email.sql \
Added: branches/indexer-split/data/tracker-dbus-daemon.xml
==============================================================================
--- (empty file)
+++ branches/indexer-split/data/tracker-dbus-daemon.xml Mon Apr 21 11:21:20 2008
@@ -0,0 +1,173 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<!--
+ The "service" input parameters are a string representing the
+ service type. A list of service types can be obtained by calling
+ method GetServices and will *potentially* include the following:
+
+ "Files"
+ "Folders" *
+ "Documents" *
+ "Images" *
+ "Music" *
+ "Videos" *
+ "Text Files" *
+ "Development Files" *
+ "Other Files" *
+ "VFS Files"
+ "VFS Folders" **
+ "VFS Documents" **
+ "VFS Images" **
+ "VFS Music" **
+ "VFS Videos" **
+ "VFS Text Files" **
+ "VFS Development Files" **
+ "VFS Other Files" **
+ "Conversations"
+ "Playlists"
+ "Applications"
+ "Contacts"
+ "Emails"
+ "EmailAttachments"
+ "Notes"
+ "Appointments"
+ "Tasks"
+ "Bookmarks"
+ "History"
+ "Projects"
+
+
+ (*) - these services are a subset of "Files" service.
+ (**) - these services are a subset of "VFSFiles" service.
+
+ Services may also have a corresponding metadata class associated
+ with them (EG Files has "File" class, Documents "Doc" etc see the
+ spec at:
+
+ http://freedesktop.org/wiki/Standards/shared-filemetadata-spec
+
+ for more details on metadata classes).
+
+ The "id" input parameters can represent, in the case of a file, the
+ full path and name of the file. In other cases, "id" can also be a
+ unique name or URI for the specified service.
+
+ The "id" field uniquely identifies an entity in Tracker regardless
+ of its service type. The live_query_id parameters in some search
+ and retrieval methods is used to indicate whether the query should
+ be "live". Liveness means the query can receive signals in real
+ time to remove hits that are no longer valid and add new ones that
+ are. These signals are emitted in response to file or volume
+ notifications. A value of -1 should be passed if live query
+ functionality is not desired. A live_query_id can be obtained in
+ the future from the LiveQuery Interface.
+ -->
+
+<node name="/">
+ <interface name="org.freedesktop.Tracker">
+
+ <!-- Returns the version number of tracker as an integer as XXXXXX
+ where each XX pair represents part of the version (e.g. "100" is
+ returned for version 0.1.0 and "14523" would represent version
+ 1.45.23).
+ -->
+ <method name="GetVersion">
+ <arg type="i" name="version" direction="out" />
+ </method>
+
+ <!-- Return the status of tracker daemon - status is one of
+ "Initializing", "Watching", "Indexing", "Pending",
+ "Optimizing", "Idle", "Shutdown".
+ -->
+ <method name="GetStatus">
+ <arg type="s" name="status" direction="out" />
+ </method>
+
+ <!-- Gets all implemented services and also returns any
+ corresponding metadata type class for the service (i.e. "File",
+ "Doc", "Image" etc).
+ If main_services_only is set to true then only the major
+ services are returned.
+ Output is in dict format: (service -> description, parent).
+ -->
+ <method name="GetServices">
+ <arg type="b" name="main_services_only" direction="in" />
+ <arg type="a{sv}" name="result" direction="out" />
+ </method>
+
+ <!-- Get statistics for services that have been indexed. Output is
+ in string array format: [service, no of entities]
+ -->
+ <method name="GetStats">
+ <arg type="aas" name="service_stats" direction="out" />
+ </method>
+
+ <!-- Sets boolean options in tracker - option can be one of
+ "Pause", "EnableIndexing", "LowMemoryMode", "IndexFileContents",
+ "EnableEvolution".
+ -->
+ <method name="SetBoolOption">
+ <arg type="s" name="option" direction="in" />
+ <arg type="b" name="value" direction="in" />
+ </method>
+
+ <!-- Sets integer based option values in tracker - option can be
+ one of "Throttle", "IndexDelay".
+ -->
+ <method name="SetIntOption">
+ <arg type="s" name="option" direction="in" />
+ <arg type="i" name="value" direction="in" />
+ </method>
+
+ <!-- Shutdown tracker service with optional reindex. -->
+ <method name="Shutdown">
+ <arg type="b" name="reindex" direction="in" />
+ </method>
+
+ <!-- Prompts tracker to send progress/state signals -->
+ <method name="PromptIndexSignals"/>
+
+ <!-- Signal change in index status - states are:
+ "Initializing", "Watching", "Indexing", "Pending",
+ "Optimizing", "Idle", "Shutdown".
+
+ - is_initial_index indicates if this is the first time index
+ (or reindex).
+ - in_merge indicates merge indexing is taking place (or
+ reindex).
+ - is_manual_paused indicates if user has manually paused the
+ indexer.
+ - is_battery_paused indicates if indexer is paused whilst on
+ battery power.
+ - is_io_paused indicates if indexer has paused itself as it
+ has detected other apps writing to disk.
+ -->
+ <signal name="IndexStateChange">
+ <arg type="s" name="state" />
+ <arg type="b" name="initial_index" />
+ <arg type="b" name="in_merge" />
+ <arg type="b" name="is_manual_paused" />
+ <arg type="b" name="is_battery_paused" />
+ <arg type="b" name="is_io_paused" />
+ <arg type="b" name="is_indexing_enabled" />
+ </signal>
+
+ <!-- Signal when index has completed. -->
+ <signal name="IndexFinished">
+ <arg type="i" name="time_taken"/>
+ </signal>
+
+ <!-- Signal progress of indexing, returns current service
+ (Files/Conversations/Emails).
+ - folders_processed = number of folders/mail boxes indexed.
+ - folders_total = total number of folders/mail boxes.
+ -->
+ <signal name="IndexProgress">
+ <arg type="s" name="service"/>
+ <arg type="s" name="current_uri" />
+ <arg type="i" name="index_count"/>
+ <arg type="i" name="folders_processed"/>
+ <arg type="i" name="folders_total"/>
+ </signal>
+ </interface>
+</node>
Added: branches/indexer-split/data/tracker-dbus-files.xml
==============================================================================
--- (empty file)
+++ branches/indexer-split/data/tracker-dbus-files.xml Mon Apr 21 11:21:20 2008
@@ -0,0 +1,131 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<!-- File Specific calls -->
+<node name="/org/freedesktop/Tracker">
+ <interface name="org.freedesktop.Tracker.Files">
+ <!-- Determines if the file is in tracker's database. The option
+ auto_create if set to TRUE will register the file in the
+ database if not already present.
+ -->
+ <method name="Exist">
+ <arg type="s" name="uri" direction="in" />
+ <arg type="b" name="auto_create" direction="in" />
+ <arg type="b" name="result" direction="out" />
+ </method>
+
+ <!-- Creates a new entry for a file in tracker's database. This
+ method is ueful when you want to tell Tracker about a file
+ which it cannot see (EG a VFS file) or the file is located
+ outside the watch/crawl path.
+ -->
+ <method name="Create">
+ <arg type="s" name="uri" direction="in" />
+ <arg type="b" name="is_directory" direction="in" />
+ <arg type="s" name="mime" direction="in" />
+ <arg type="i" name="size" direction="in" />
+ <arg type="i" name="mtime" direction="in" />
+ </method>
+
+ <!-- Removes the file entry from tracker's database. -->
+ <method name="Delete">
+ <arg type="s" name="uri" direction="in" />
+ </method>
+
+ <!-- Get the Service subtype for the file. -->
+ <method name="GetServiceType">
+ <arg type="s" name="uri" direction="in" />
+ <arg type="s" name="result" direction="out" />
+ </method>
+
+ <!-- Get the "File.Content" field for a file and allows you to
+ specify the offset and amount of text to retrieve.
+ -->
+ <method name="GetTextContents">
+ <arg type="s" name="uri" direction="in" />
+ <arg type="i" name="offset" direction="in" />
+ <arg type="i" name="max_length" direction="in" />
+ <arg type="s" name="result" direction="out" />
+ </method>
+
+ <!-- Retrieves a chunk of matching text of specified length that
+ contains the search text in the File.Content field.
+ -->
+ <method name="SearchTextContents">
+ <arg type="s" name="uri" direction="in" />
+ <arg type="s" name="text" direction="in" />
+ <arg type="i" name="length" direction="in" />
+ <arg type="s" name="result" direction="out" />
+ </method>
+
+ <!-- Retrieves all files that match a service description. -->
+ <method name="GetByServiceType">
+ <arg type="i" name="live_query_id" direction="in" />
+ <arg type="s" name="file_service" direction="in" />
+ <arg type="i" name="offset" direction="in" />
+ <arg type="i" name="max_hits" direction="in" />
+ <arg type="as" name="result" direction="out" />
+ </method>
+
+ <!-- Retrieves all non-vfs files of the specified mime type(s). -->
+ <method name="GetByMimeType">
+ <arg type="i" name="live_query_id" direction="in" />
+ <arg type="as" name="mime_types" direction="in" />
+ <arg type="i" name="offset" direction="in" />
+ <arg type="i" name="max_hits" direction="in" />
+ <arg type="as" name="result" direction="out" />
+ </method>
+
+ <!-- Retrieves all vfs files of the specified mime type(s). -->
+ <method name="GetByMimeTypeVfs">
+ <arg type="i" name="live_query_id" direction="in" />
+ <arg type="as" name="mime_types" direction="in" />
+ <arg type="i" name="offset" direction="in" />
+ <arg type="i" name="max_hits" direction="in" />
+ <arg type="as" name="result" direction="out" />
+ </method>
+
+ <!-- returns mtime of file in seconds since epoch -->
+ <method name="GetMTime">
+ <arg type="s" name="uri" direction="in" />
+ <arg type="i" name="result" direction="out" />
+ </method>
+
+ <!-- Retrieves all non-vfs files in a folder complete with all
+ requested metadata fields. StringArray output is [uri,
+ field1, field2...].
+ -->
+ <method name="GetMetadataForFilesInFolder">
+ <arg type="i" name="live_query_id" direction="in" />
+ <arg type="s" name="uri" direction="in" />
+ <arg type="as" name="fields" direction="in" />
+ <arg type="aas" name="values" direction="out" />
+ </method>
+
+ <!-- Deprecated file specific calls.
+ (mostly used by Nautilus search).
+ -->
+
+<!--
+ <method name="SearchByTextAndMime">
+ <annotation name="org.freedesktop.DBus.Deprecated" value="true"/>
+ <arg type="s" name="text" direction="in" />
+ <arg type="as" name="mimes" direction="in" />
+ <arg type="as" name="result" direction="out" />
+ </method>
+ <method name="SearchByTextAndMimeAndLocation">
+ <annotation name="org.freedesktop.DBus.Deprecated" value="true"/>
+ <arg type="s" name="text" direction="in" />
+ <arg type="as" name="mimes" direction="in" />
+ <arg type="s" name="location" direction="in" />
+ <arg type="as" name="result" direction="out" />
+ </method>
+ <method name="SearchByTextAndLocation">
+ <annotation name="org.freedesktop.DBus.Deprecated" value="true"/>
+ <arg type="s" name="text" direction="in" />
+ <arg type="s" name="location" direction="in" />
+ <arg type="as" name="result" direction="out" />
+ </method>
+-->
+ <!-- End deprecated calls section. -->
+ </interface>
+</node>
Added: branches/indexer-split/data/tracker-dbus-keywords.xml
==============================================================================
--- (empty file)
+++ branches/indexer-split/data/tracker-dbus-keywords.xml Mon Apr 21 11:21:20 2008
@@ -0,0 +1,71 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<node name="/">
+ <!-- Calls for tags/keywords for any service object or file. -->
+ <interface name="org.freedesktop.Tracker.Keywords">
+
+ <!-- Gets a list of all unique keywords/tags that are in use by
+ the specified service irrespective of the uri or id of the
+ entity. Returns an array of string arrays in format [Keyword,
+ KeywordCount].
+ -->
+ <method name="GetList">
+ <arg type="s" name="service" direction="in" />
+ <arg type="aas" name="value" direction="out" />
+ </method>
+
+ <!-- Gets all unique keywords/tags for specified service and id. -->
+ <method name="Get">
+ <arg type="s" name="service" direction="in" />
+ <arg type="s" name="id" direction="in" />
+ <arg type="as" name="value" direction="out" />
+ </method>
+
+ <!-- Adds new keywords/tags for specified service and id -->
+ <method name="Add">
+ <arg type="s" name="service" direction="in" />
+ <arg type="s" name="id" direction="in" />
+ <arg type="as" name="values" direction="in" />
+ </method>
+
+ <!-- Removes all specified keywords/tags for specified service and
+ id.
+ -->
+ <method name="Remove">
+ <arg type="s" name="service" direction="in" />
+ <arg type="s" name="id" direction="in" />
+ <arg type="as" name="keywords" direction="in" />
+ </method>
+
+ <!-- Removes all keywords/tags for specified service and id. -->
+ <method name="RemoveAll">
+ <arg type="s" name="service" direction="in" />
+ <arg type="s" name="id" direction="in" />
+ </method>
+
+ <!-- Searches specified service for matching keyword/tag and
+ returns an array of matching id values for the service.
+ -->
+ <method name="Search">
+ <arg type="i" name="live_query_id" direction="in" />
+ <arg type="s" name="service" direction="in" />
+ <arg type="as" name="keywords" direction="in" />
+ <arg type="i" name="offset" direction="in" />
+ <arg type="i" name="max_hits" direction="in" />
+ <arg type="as" name="result" direction="out" />
+ </method>
+
+ <!-- emitted whenever tags on an entity change -->
+ <signal name="KeywordAdded">
+ <arg type="s" name="service"/>
+ <arg type="s" name="uri" />
+ <arg type="s" name="keyword" />
+ </signal>
+
+ <signal name="KeywordRemoved">
+ <arg type="s" name="service"/>
+ <arg type="s" name="uri" />
+ <arg type="s" name="keyword" />
+ </signal>
+ </interface>
+</node>
Added: branches/indexer-split/data/tracker-dbus-metadata.xml
==============================================================================
--- (empty file)
+++ branches/indexer-split/data/tracker-dbus-metadata.xml Mon Apr 21 11:21:20 2008
@@ -0,0 +1,77 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<node name="/org/freedesktop/Tracker">
+ <interface name="org.freedesktop.Tracker.Metadata">
+ <!-- Retrieves an array of metadata values for the specified array
+ of metadata keys for a service and id pair.
+ -->
+ <method name="Get">
+ <arg type="s" name="service" direction="in" />
+ <arg type="s" name="id" direction="in" />
+ <arg type="as" name="keys" direction="in" />
+ <arg type="as" name="values" direction="out" />
+ </method>
+
+ <!-- Sets specified metadata keys to the specified metadata values
+ for a service and id pair.
+ -->
+ <method name="Set">
+ <arg type="s" name="service" direction="in" />
+ <arg type="s" name="id" direction="in" />
+ <arg type="as" name="keys" direction="in" />
+ <arg type="as" name="values" direction="in" />
+ </method>
+
+ <!--
+ Registers a new metadata type. The metadata name must be
+ namespaced with an appropriate class in the format
+ "class.name".
+
+ The datatype argument for RegisterType should be one of the
+ following:
+ "index" (a string which is stored in a full text index for searching)
+ "string" (a non-indexable string which will not show up in searches)
+ "numeric" (a signed number which can be either an integer or a float)
+ "date" (format should be "yyyy-mm-dd hh:mm:ss")
+
+ Metadata defined here is considered non-embeddable and writable.
+ -->
+ <method name="RegisterType">
+ <arg type="s" name="name" direction="in" />
+ <arg type="s" name="datatype" direction="in" />
+ </method>
+
+ <!-- Gets all details of a named metadata type. -->
+ <method name="GetTypeDetails">
+ <arg type="s" name="name" direction="in" />
+ <arg type="s" name="data_type" direction="out" />
+ <arg type="b" name="is_embedded" direction="out" />
+ <arg type="b" name="is_writable" direction="out" />
+ </method>
+
+ <!-- Returns an array of all metadata types that are registered
+ for a certain class. You can enter "*" as the class to get all
+ metadat types for all classes.
+ -->
+ <method name="GetRegisteredTypes">
+ <arg type="s" name="metadata_class" direction="in" />
+ <arg type="as" name="result" direction="out" />
+ </method>
+
+ <!-- Returns an array of all metadata types that are writeable and
+ registered for a certain class. You can enter "*" as the class
+ to get all metadat types for all classes that are writeable.
+ -->
+ <method name="GetWritableTypes">
+ <arg type="s" name="metadata_class" direction="in" />
+ <arg type="as" name="result" direction="out" />
+ </method>
+
+ <!-- Returns an array of all metadata type classes that are
+ registered.
+ -->
+ <method name="GetRegisteredClasses">
+ <arg type="as" name="result" direction="out" />
+ </method>
+ </interface>
+</node>
Added: branches/indexer-split/data/tracker-dbus-search.xml
==============================================================================
--- (empty file)
+++ branches/indexer-split/data/tracker-dbus-search.xml Mon Apr 21 11:21:20 2008
@@ -0,0 +1,112 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<!-- Generic search interface (see other interfaces for file/keyword
+ specific searches).
+ -->
+<node name="/org/freedesktop/Tracker">
+ <interface name="org.freedesktop.Tracker.Search">
+ <!-- Returns no of hits for the search_text on the servce. -->
+ <method name="GetHitCount">
+ <arg type="s" name="service" direction="in" />
+ <arg type="s" name="search_text" direction="in" />
+ <arg type="i" name="result" direction="out" />
+ </method>
+
+ <!-- returns [service name, no. of hits] for the search_text -->
+ <method name="GetHitCountAll">
+ <arg type="s" name="search_text" direction="in" />
+ <arg type="aas" name="result" direction="out" />
+ </method>
+
+ <!-- searches specified service for entities that match the
+ specified search_text. Returns uri of all hits.
+ -->
+ <method name="Text">
+ <arg type="i" name="live_query_id" direction="in" />
+ <arg type="s" name="service" direction="in" />
+ <arg type="s" name="search_text" direction="in" />
+ <arg type="i" name="offset" direction="in" />
+ <arg type="i" name="max_hits" direction="in" />
+ <arg type="as" name="result" direction="out" />
+ </method>
+
+ <!-- More detailed version of above. Searches specified service
+ for entities that match the specified search_text. Returns
+ hits in array format [uri, service, mime].
+ -->
+ <method name="TextDetailed">
+ <arg type="i" name="live_query_id" direction="in" />
+ <arg type="s" name="service" direction="in" />
+ <arg type="s" name="search_text" direction="in" />
+ <arg type="i" name="offset" direction="in" />
+ <arg type="i" name="max_hits" direction="in" />
+ <arg type="aas" name="result" direction="out" />
+ </method>
+
+ <!-- Returns a search snippet of text with matchinhg text enclosed
+ in bold tags.
+ -->
+ <method name="GetSnippet">
+ <arg type="s" name="service" direction="in" />
+ <arg type="s" name="id" direction="in" />
+ <arg type="s" name="search_text" direction="in" />
+ <arg type="s" name="result" direction="out" />
+ </method>
+
+ <!-- searches a specific metadata field (field parameter) for a
+ search term (search_text). The result is an array of uri/id's.
+ -->
+ <method name="Metadata">
+ <arg type="s" name="service" direction="in" />
+ <arg type="s" name="field" direction="in" />
+ <arg type="s" name="search_text" direction="in" />
+ <arg type="i" name="offset" direction="in" />
+ <arg type="i" name="max_hits" direction="in" />
+ <arg type="as" name="result" direction="out" />
+ </method>
+
+ <!-- Searches specified service for matching entities.
+ - The service parameter specifies the service which the query
+ will be performed on.
+ - The fields parameter specifies an array of aditional metadata
+ fields to return in addition to the id field (which is
+ returned as the "key" in the resultant dict/hashtable) and
+ the service category. This can be null.
+ - The optional search_text paramter specifies the text to
+ search for in a full text search of all indexed fields.
+ - The optional keyword search, a single keyword may be used
+ here to filter the results.
+ - The optional query_condition parameter specifies an
+ xml-based rdf query condition which is used to filter out the
+ results.
+ - The Offset parameter sets the start row of the returned
+ result set (useful for paging/cursors). A value of 0 should
+ be passed to get rows from the beginning.
+ - The max_hits parameter limits the size of the result set.
+ - The sort_by_service parameter optionally sorts results by
+ their service category (if FALSE no service sorting is done).
+ - The result is a array of stringarrays in format [uri,
+ service, field1, field2...] where field1 is the first
+ specified field in the fields paramter and so on.
+ -->
+ <method name="Query">
+ <arg type="i" name="live_query_id" direction="in" />
+ <arg type="s" name="service" direction="in" />
+ <arg type="as" name="fields" direction="in" />
+ <arg type="s" name="search_text" direction="in" />
+ <arg type="s" name="keyword" direction="in" />
+ <arg type="s" name="query_condition" direction="in" />
+ <arg type="b" name="sort_by_service" direction="in" />
+ <arg type="i" name="offset" direction="in" />
+ <arg type="i" name="max_hits" direction="in" />
+ <arg type="aas" name="result" direction="out" />
+ </method>
+
+ <!-- Suggests an alternate spelling based on the word index. -->
+ <method name="Suggest">
+ <arg type="s" name="search_text" direction="in" />
+ <arg type="i" name="maxdist" direction="in" />
+ <arg type="s" name="result" direction="out" />
+ </method>
+ </interface>
+</node>
Modified: branches/indexer-split/src/libtracker-common/Makefile.am
==============================================================================
--- branches/indexer-split/src/libtracker-common/Makefile.am (original)
+++ branches/indexer-split/src/libtracker-common/Makefile.am Mon Apr 21 11:21:20 2008
@@ -12,7 +12,9 @@
tracker-language.c \
tracker-language.h \
tracker-log.c \
- tracker-log.h
+ tracker-log.h \
+ tracker-utils.c \
+ tracker-utils.h
libtracker_common_la_LDFLAGS = -version-info 0:0:0
libtracker_common_la_LIBADD = $(GLIB2_LIBS)
Modified: branches/indexer-split/src/libtracker-common/tracker-language.c
==============================================================================
--- branches/indexer-split/src/libtracker-common/tracker-language.c (original)
+++ branches/indexer-split/src/libtracker-common/tracker-language.c Mon Apr 21 11:21:20 2008
@@ -1,6 +1,7 @@
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
/*
- * Copyright (C) 2008, Nokia (urho konttori nokia com)
+ * Copyright (C) 2006, Mr Jamie McCracken (jamiemcc gnome org)
+ * Copyright (C) 2008, Nokia
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public
Modified: branches/indexer-split/src/libtracker-common/tracker-language.h
==============================================================================
--- branches/indexer-split/src/libtracker-common/tracker-language.h (original)
+++ branches/indexer-split/src/libtracker-common/tracker-language.h Mon Apr 21 11:21:20 2008
@@ -1,6 +1,7 @@
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
/*
- * Copyright (C) 2008, Nokia (urho konttori nokia com)
+ * Copyright (C) 2006, Mr Jamie McCracken (jamiemcc gnome org)
+ * Copyright (C) 2008, Nokia
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public
Modified: branches/indexer-split/src/libtracker-common/tracker-log.c
==============================================================================
--- branches/indexer-split/src/libtracker-common/tracker-log.c (original)
+++ branches/indexer-split/src/libtracker-common/tracker-log.c Mon Apr 21 11:21:20 2008
@@ -1,7 +1,7 @@
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
/*
* Copyright (C) 2006, Mr Jamie McCracken (jamiemcc gnome org)
- * Copyright (C) 2008, Nokia (urho konttori nokia com)
+ * Copyright (C) 2008, Nokia
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public
Modified: branches/indexer-split/src/libtracker-common/tracker-log.h
==============================================================================
--- branches/indexer-split/src/libtracker-common/tracker-log.h (original)
+++ branches/indexer-split/src/libtracker-common/tracker-log.h Mon Apr 21 11:21:20 2008
@@ -1,7 +1,7 @@
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
/*
* Copyright (C) 2006, Mr Jamie McCracken (jamiemcc gnome org)
- * Copyright (C) 2008, Nokia (urho konttori nokia com)
+ * Copyright (C) 2008, Nokia
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public
Added: branches/indexer-split/src/libtracker-common/tracker-utils.c
==============================================================================
--- (empty file)
+++ branches/indexer-split/src/libtracker-common/tracker-utils.c Mon Apr 21 11:21:20 2008
@@ -0,0 +1,28 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
+/*
+ * Copyright (C) 2006, Mr Jamie McCracken (jamiemcc gnome org)
+ * Copyright (C) 2008, Nokia
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public
+ * License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ */
+
+#include <glib.h>
+
+inline gboolean
+tracker_is_empty_string (const char *str)
+{
+ return str == NULL || str[0] == '\0';
+}
Added: branches/indexer-split/src/libtracker-common/tracker-utils.h
==============================================================================
--- (empty file)
+++ branches/indexer-split/src/libtracker-common/tracker-utils.h Mon Apr 21 11:21:20 2008
@@ -0,0 +1,27 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
+/*
+ * Copyright (C) 2006, Mr Jamie McCracken (jamiemcc gnome org)
+ * Copyright (C) 2008, Nokia
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public
+ * License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ */
+
+#ifndef __TRACKER_UTILS_H__
+#define __TRACKER_UTILS_H__
+
+gboolean tracker_is_empty_string (const char *str);
+
+#endif /* __TRACKER_DBUS_UTILS_H__ */
Modified: branches/indexer-split/src/libtracker/Makefile.am
==============================================================================
--- branches/indexer-split/src/libtracker/Makefile.am (original)
+++ branches/indexer-split/src/libtracker/Makefile.am Mon Apr 21 11:21:20 2008
@@ -4,72 +4,65 @@
$(GLIB2_CFLAGS) \
$(DBUS_CFLAGS)
-BUILT_SOURCES = tracker-client.h
-
-lib_LTLIBRARIES = libtrackerclient.la
-
-libtrackerclient_la_LIBADD = $(GLIB2_LIBS) \
+# Common linking
+libs = \
+ $(GLIB2_LIBS) \
$(DBUS_LIBS) \
$(GOBJECT_LIBS)
+# Libraries
+lib_LTLIBRARIES = libtrackerclient.la
+
libtrackerclient_la_SOURCES = tracker.c
libtrackerclient_la_LDFLAGS = -version-info 0:0:0
+libtrackerclient_la_LIBADD = $(libs)
-tracker-client.h: $(top_srcdir)/data/tracker-introspect.xml Makefile.am
- dbus-binding-tool --prefix=client_object --mode=glib-client --output=tracker-client.h $(top_srcdir)/data/tracker-introspect.xml
-
-include_HEADERS = tracker.h tracker-client.h
-
-bin_PROGRAMS = tracker-search tracker-query tracker-meta-folder tracker-stats tracker-tag tracker-files tracker-status
+include_HEADERS = \
+ tracker.h \
+ $(BUILT_SOURCES)
+
+# Applications
+bin_PROGRAMS = \
+ tracker-search \
+ tracker-query \
+ tracker-meta-folder \
+ tracker-stats \
+ tracker-tag \
+ tracker-files \
+ tracker-status
tracker_search_SOURCES = tracker-search.c
-
-tracker_search_LDADD = $(GLIB2_LIBS) \
- $(DBUS_LIBS) \
- $(GOBJECT_LIBS) \
- libtrackerclient.la
+tracker_search_LDADD = $(libs) libtrackerclient.la
tracker_query_SOURCES = tracker-query.c
-
-tracker_query_LDADD = $(GLIB2_LIBS) \
- $(DBUS_LIBS) \
- $(GOBJECT_LIBS) \
- libtrackerclient.la
+tracker_query_LDADD = $(libs) libtrackerclient.la
tracker_meta_folder_SOURCES = tracker-get-meta-for-folder.c
-
-tracker_meta_folder_LDADD = $(GLIB2_LIBS) \
- $(DBUS_LIBS) \
- $(GOBJECT_LIBS) \
- libtrackerclient.la
+tracker_meta_folder_LDADD = $(libs) libtrackerclient.la
tracker_stats_SOURCES = tracker-stats.c
+tracker_stats_LDADD = $(libs) libtrackerclient.la
-tracker_stats_LDADD = $(GLIB2_LIBS) \
- $(DBUS_LIBS) \
- $(GOBJECT_LIBS) \
- libtrackerclient.la
-
-tracker_status_SOURCES = tracker-status.c
-
-tracker_status_LDADD = $(GLIB2_LIBS) \
- $(DBUS_LIBS) \
- $(GOBJECT_LIBS) \
- libtrackerclient.la
+tracker_tag_SOURCES = tracker-tag.c
+tracker_tag_LDADD = $(libs) libtrackerclient.la
+tracker_files_SOURCES = tracker-files.c
+tracker_files_LDADD = $(libs) libtrackerclient.la
-tracker_tag_SOURCES = tracker-tag.c
+tracker_status_SOURCES = tracker-status.c
+tracker_status_LDADD = $(libs) libtrackerclient.la
-tracker_tag_LDADD = $(GLIB2_LIBS) \
- $(DBUS_LIBS) \
- $(GOBJECT_LIBS) \
- libtrackerclient.la
+# Generate DBus files from XML data.
+dbus_sources = \
+ tracker-dbus-daemon-glue.h \
+ tracker-dbus-files-glue.h \
+ tracker-dbus-keywords-glue.h \
+ tracker-dbus-metadata-glue.h \
+ tracker-dbus-search-glue.h
-tracker_files_SOURCES = tracker-files.c
+%-glue.h: $(top_builddir)/data/%.xml
+ $(DBUSBINDINGTOOL) --mode=glib-client --output=$@ --prefix=$(subst -,_,$*) $^
-tracker_files_LDADD = $(GLIB2_LIBS) \
- $(DBUS_LIBS) \
- $(GOBJECT_LIBS) \
- libtrackerclient.la
+BUILT_SOURCES = $(dbus_sources)
CLEANFILES = $(BUILT_SOURCES)
Modified: branches/indexer-split/src/libtracker/tracker.c
==============================================================================
--- branches/indexer-split/src/libtracker/tracker.c (original)
+++ branches/indexer-split/src/libtracker/tracker.c Mon Apr 21 11:21:20 2008
@@ -20,8 +20,14 @@
#include "tracker.h"
#include <string.h>
+#include "tracker-dbus-daemon-glue.h"
+#include "tracker-dbus-files-glue.h"
+#include "tracker-dbus-keywords-glue.h"
+#include "tracker-dbus-metadata-glue.h"
+#include "tracker-dbus-search-glue.h"
+
#define TRACKER_SERVICE "org.freedesktop.Tracker"
-#define TRACKER_OBJECT "/org/freedesktop/tracker"
+#define TRACKER_OBJECT "/org/freedesktop/Tracker"
#define TRACKER_INTERFACE "org.freedesktop.Tracker"
#define TRACKER_INTERFACE_METADATA "org.freedesktop.Tracker.Metadata"
#define TRACKER_INTERFACE_KEYWORDS "org.freedesktop.Tracker.Keywords"
@@ -280,28 +286,28 @@
proxy = dbus_g_proxy_new_for_name (connection,
TRACKER_SERVICE,
- TRACKER_OBJECT,
+ TRACKER_OBJECT "/Metadata",
TRACKER_INTERFACE_METADATA);
client->proxy_metadata = proxy;
proxy = dbus_g_proxy_new_for_name (connection,
TRACKER_SERVICE,
- TRACKER_OBJECT,
+ TRACKER_OBJECT "/Keywords",
TRACKER_INTERFACE_KEYWORDS);
client->proxy_keywords = proxy;
proxy = dbus_g_proxy_new_for_name (connection,
TRACKER_SERVICE,
- TRACKER_OBJECT,
+ TRACKER_OBJECT "/Search",
TRACKER_INTERFACE_SEARCH);
client->proxy_search = proxy;
proxy = dbus_g_proxy_new_for_name (connection,
TRACKER_SERVICE,
- TRACKER_OBJECT,
+ TRACKER_OBJECT "/Files",
TRACKER_INTERFACE_FILES);
client->proxy_files = proxy;
Modified: branches/indexer-split/src/libtracker/tracker.h
==============================================================================
--- branches/indexer-split/src/libtracker/tracker.h (original)
+++ branches/indexer-split/src/libtracker/tracker.h Mon Apr 21 11:21:20 2008
@@ -35,10 +35,10 @@
typedef enum {
- DATA_STRING_INDEXABLE,
- DATA_STRING,
- DATA_NUMERIC,
- DATA_DATE
+ METADATA_STRING_INDEXABLE,
+ METADATA_STRING,
+ METADATA_NUMERIC,
+ METADATA_DATE
} MetadataTypes;
typedef enum {
Modified: branches/indexer-split/src/tracker-preferences/tracker-preferences.c
==============================================================================
--- branches/indexer-split/src/tracker-preferences/tracker-preferences.c (original)
+++ branches/indexer-split/src/tracker-preferences/tracker-preferences.c Mon Apr 21 11:21:20 2008
@@ -27,12 +27,16 @@
#include <stdlib.h>
#include "../libtracker/tracker.h"
-#include "../trackerd/tracker-dbus.h"
+/* #include "../trackerd/tracker-dbus.h" */
#include "../libtracker-common/tracker-configuration.h"
#include "tracker-preferences.h"
#include "tracker-preferences-dialogs.h"
+#define TRACKER_DBUS_SERVICE "org.freedesktop.Tracker"
+#define TRACKER_DBUS_PATH "/org/freedesktop/Tracker"
+#define TRACKER_DBUS_INTERFACE "org.freedesktop.Tracker"
+
#define TRACKER_PREFERENCES_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE((obj), TRACKER_TYPE_PREFERENCES, TrackerPreferencesPrivate))
typedef struct _TrackerPreferencesPrivate {
@@ -207,8 +211,8 @@
priv->tracker_proxy = dbus_g_proxy_new_for_name (priv->connection,
TRACKER_DBUS_SERVICE,
- TRACKER_OBJECT,
- TRACKER_INTERFACE);
+ TRACKER_DBUS_PATH,
+ TRACKER_DBUS_INTERFACE);
if (!priv->tracker_proxy) {
g_warning ("could not create proxy");
Modified: branches/indexer-split/src/trackerd/Makefile.am
==============================================================================
--- branches/indexer-split/src/trackerd/Makefile.am (original)
+++ branches/indexer-split/src/trackerd/Makefile.am Mon Apr 21 11:21:20 2008
@@ -1,11 +1,9 @@
-module_flags = -module -avoid-version -no-undefined
-mail_modulesdir = $(libdir)/tracker/mail-modules
-
INCLUDES = \
-g \
-DSHAREDIR=\""$(datadir)"\" \
-DLIBDIR=\""$(libdir)"\" \
-DLOCALEDIR=\""$(localedir)"\" \
+ -DMAIL_MODULES_DIR=\""$(libdir)"/tracker/mail-modules\" \
$(GLIB2_CFLAGS) \
$(GMODULE_CFLAGS) \
$(PANGO_CFLAGS) \
@@ -16,7 +14,6 @@
$(SQLITE3_CFLAGS) \
$(QDBM_CFLAGS) \
$(UNAC_CFLAGS) \
- -DMAIL_MODULES_DIR=\"$(mail_modulesdir)\" \
-I$(top_srcdir)/src
if HAVE_INOTIFY
@@ -63,6 +60,31 @@
tracker-db-email.c \
tracker-db-email.h
+mail_modulesdir = $(libdir)/tracker/mail-modules
+mail_modules_LTLIBRARIES = \
+ libemail-evolution.la \
+ libemail-thunderbird.la \
+ libemail-kmail.la \
+ libemail-modest.la
+
+module_flags = -module -avoid-version -no-undefined
+
+libemail_modest_la_SOURCES = tracker-email-modest.c
+libemail_modest_la_LDFLAGS = $(module_flags)
+libemail_modest_la_LIBADD = $(GLIB2_LIBS)
+
+libemail_evolution_la_SOURCES = tracker-email-evolution.c
+libemail_evolution_la_LDFLAGS = $(module_flags)
+libemail_evolution_la_LIBADD = $(GLIB2_LIBS)
+
+libemail_thunderbird_la_SOURCES = tracker-email-thunderbird.c
+libemail_thunderbird_la_LDFLAGS = $(module_flags)
+libemail_thunderbird_la_LIBADD = $(GLIB2_LIBS)
+
+libemail_kmail_la_SOURCES = tracker-email-kmail.c
+libemail_kmail_la_LDFLAGS = $(module_flags)
+libemail_kmail_la_LIBADD = $(GLIB2_LIBS)
+
bin_PROGRAMS = trackerd
@@ -73,20 +95,21 @@
$(unix_sources) \
$(hal_sources) \
$(db_sources) \
+ $(foo_sources) \
tracker-apps.c \
tracker-apps.h \
tracker-db.c \
tracker-db.h \
tracker-dbus.c \
tracker-dbus.h \
+ tracker-dbus-daemon.c \
+ tracker-dbus-daemon.h \
tracker-dbus-files.c \
tracker-dbus-files.h \
- tracker-dbus-methods.c \
- tracker-dbus-methods.h \
- tracker-dbus-metadata.c \
- tracker-dbus-metadata.h \
tracker-dbus-keywords.c \
tracker-dbus-keywords.h \
+ tracker-dbus-metadata.c \
+ tracker-dbus-metadata.h \
tracker-dbus-search.c \
tracker-dbus-search.h \
tracker-email.c \
@@ -97,8 +120,6 @@
tracker-metadata.h \
tracker-process-files.c \
tracker-process-files.h \
- tracker-process-requests.c \
- tracker-process-requests.h \
tracker-query-tree.c \
tracker-query-tree.h \
tracker-rdf-query.c \
@@ -112,7 +133,10 @@
tracker-ioprio.c \
tracker-ioprio.h \
tracker-os-dependant.h \
- tracker-watch.h
+ tracker-watch.h \
+ tracker-status.c \
+ tracker-status.h \
+ tracker-marshal-main.c
if OS_WIN32
trackerd_win_libs = -lws2_32 -lkernel32
@@ -137,24 +161,38 @@
$(top_builddir)/src/xdgmime/libxdgmime.la \
$(trackerd_win_libs)
-mail_modules_LTLIBRARIES = \
- libemail-evolution.la \
- libemail-thunderbird.la \
- libemail-kmail.la \
- libemail-modest.la
+tracker-marshal.h: tracker-marshal.list
+ ($(GLIB_GENMARSHAL) --prefix=tracker_marshal tracker-marshal.list --header) > xgen-gmh \
+ && (cmp -s xgen-gmh tracker-marshal.h || cp xgen-gmh tracker-marshal.h) \
+ && rm -f xgen-gmh xgen-gmh~
+
+tracker-marshal.c: tracker-marshal.list
+ ($(GLIB_GENMARSHAL) --prefix=tracker_marshal tracker-marshal.list --body) > xgen-gmc \
+ && cp xgen-gmc tracker-marshal.c \
+ && rm -f xgen-gmc xgen-gmc~
+
+tracker-marshal-main.c: tracker-marshal.c tracker-marshal.h
+
+marshal_sources = \
+ tracker-marshal.h \
+ tracker-marshal.c
+
+dbus_sources = \
+ tracker-dbus-daemon-glue.h \
+ tracker-dbus-files-glue.h \
+ tracker-dbus-keywords-glue.h \
+ tracker-dbus-metadata-glue.h \
+ tracker-dbus-search-glue.h
+
+%-glue.h: $(top_builddir)/data/%.xml
+ $(DBUSBINDINGTOOL) --mode=glib-server --output=$@ --prefix=$(subst -,_,$*) $^
+
+BUILT_SOURCES = \
+ $(dbus_sources) \
+ $(marshal_sources)
-libemail_modest_la_SOURCES = tracker-email-modest.c
-libemail_modest_la_LDFLAGS = $(module_flags)
-libemail_modest_la_LIBADD = $(GLIB2_LIBS)
-
-libemail_evolution_la_SOURCES = tracker-email-evolution.c
-libemail_evolution_la_LDFLAGS = $(module_flags)
-libemail_evolution_la_LIBADD = $(GLIB2_LIBS)
+CLEANFILES = $(BUILT_SOURCES)
-libemail_thunderbird_la_SOURCES = tracker-email-thunderbird.c
-libemail_thunderbird_la_LDFLAGS = $(module_flags)
-libemail_thunderbird_la_LIBADD = $(GLIB2_LIBS)
+EXTRA_DIST = \
+ tracker-marshal.list
-libemail_kmail_la_SOURCES = tracker-email-kmail.c
-libemail_kmail_la_LDFLAGS = $(module_flags)
-libemail_kmail_la_LIBADD = $(GLIB2_LIBS)
Modified: branches/indexer-split/src/trackerd/tracker-cache.c
==============================================================================
--- branches/indexer-split/src/trackerd/tracker-cache.c (original)
+++ branches/indexer-split/src/trackerd/tracker-cache.c Mon Apr 21 11:21:20 2008
@@ -27,8 +27,11 @@
#include <libtracker-common/tracker-log.h>
#include "tracker-utils.h"
+#include "tracker-db-sqlite.h"
#include "tracker-dbus.h"
+#include "tracker-dbus-daemon.h"
#include "tracker-cache.h"
+#include "tracker-status.h"
#define USE_SLICE
@@ -305,8 +308,11 @@
gboolean
tracker_cache_process_events (DBConnection *db_con, gboolean check_flush)
{
+ GObject *object;
gboolean stopped_trans = FALSE;
+ object = tracker_dbus_get_object (TRACKER_TYPE_DBUS_DAEMON);
+
while (TRUE) {
gboolean sleep = FALSE;
@@ -334,11 +340,20 @@
if (db_con) tracker_db_end_index_transaction (db_con);
- tracker_dbus_send_index_status_change_signal ();
-
+ /* Signal state change */
+ g_signal_emit_by_name (object,
+ "index-state-change",
+ tracker_status_get_as_string (),
+ tracker->first_time_index,
+ tracker->in_merge,
+ tracker->pause_manual,
+ tracker_pause_on_battery (),
+ tracker->pause_io,
+ tracker_config_get_enable_indexing (tracker->config));
if (tracker_pause ()) {
- g_cond_wait (tracker->file_thread_signal, tracker->files_signal_mutex);
+ g_cond_wait (tracker->files_signal_cond,
+ tracker->files_signal_mutex);
} else {
/* set mutex to indicate we are in "check" state to prevent race conditions from other threads resetting gloabl vars */
@@ -347,7 +362,8 @@
if ((!tracker->is_running ||
!tracker_config_get_enable_indexing (tracker->config)) &&
(!tracker->shutdown)) {
- g_cond_wait (tracker->file_thread_signal, tracker->files_signal_mutex);
+ g_cond_wait (tracker->files_signal_cond,
+ tracker->files_signal_mutex);
}
g_mutex_unlock (tracker->files_check_mutex);
@@ -358,7 +374,16 @@
if (check_flush) tracker_cache_flush_all ();
return FALSE;
} else {
- tracker_dbus_send_index_status_change_signal ();
+ /* Signal state change */
+ g_signal_emit_by_name (object,
+ "index-state-change",
+ tracker_status_get_as_string (),
+ tracker->first_time_index,
+ tracker->in_merge,
+ tracker->pause_manual,
+ tracker_pause_on_battery (),
+ tracker->pause_io,
+ tracker_config_get_enable_indexing (tracker->config));
continue;
}
@@ -377,7 +402,16 @@
tracker->pause_io = TRUE;
- tracker_dbus_send_index_status_change_signal ();
+ /* Signal state change */
+ g_signal_emit_by_name (object,
+ "index-state-change",
+ tracker_status_get_as_string (),
+ tracker->first_time_index,
+ tracker->in_merge,
+ tracker->pause_manual,
+ tracker_pause_on_battery (),
+ tracker->pause_io,
+ tracker_config_get_enable_indexing (tracker->config));
g_usleep (1000 * 1000);
@@ -390,7 +424,17 @@
} else {
if (tracker->pause_io) {
tracker->pause_io = FALSE;
- tracker_dbus_send_index_status_change_signal ();
+
+ /* Signal state change */
+ g_signal_emit_by_name (object,
+ "index-state-change",
+ tracker_status_get_as_string (),
+ tracker->first_time_index,
+ tracker->in_merge,
+ tracker->pause_manual,
+ tracker_pause_on_battery (),
+ tracker->pause_io,
+ tracker_config_get_enable_indexing (tracker->config));
}
}
Modified: branches/indexer-split/src/trackerd/tracker-db-sqlite.c
==============================================================================
--- branches/indexer-split/src/trackerd/tracker-db-sqlite.c (original)
+++ branches/indexer-split/src/trackerd/tracker-db-sqlite.c Mon Apr 21 11:21:20 2008
@@ -45,6 +45,7 @@
#include <libtracker-common/tracker-log.h>
#include <libtracker-common/tracker-config.h>
+#include <libtracker-common/tracker-utils.h>
#include "tracker-db-interface-sqlite.h"
#include "tracker-db-sqlite.h"
Added: branches/indexer-split/src/trackerd/tracker-dbus-daemon.c
==============================================================================
--- (empty file)
+++ branches/indexer-split/src/trackerd/tracker-dbus-daemon.c Mon Apr 21 11:21:20 2008
@@ -0,0 +1,589 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
+/*
+ * Copyright (C) 2006, Mr Jamie McCracken (jamiemcc gnome org)
+ * Copyright (C) 2008, Nokia
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public
+ * License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ */
+
+#include <config.h>
+
+#include <stdlib.h>
+#include <string.h>
+
+#include <libtracker-common/tracker-log.h>
+#include <libtracker-common/tracker-config.h>
+
+#include "tracker-dbus.h"
+#include "tracker-dbus-daemon.h"
+#include "tracker-db.h"
+#include "tracker-status.h"
+#include "tracker-marshal.h"
+
+#define GET_PRIV(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), TRACKER_TYPE_DBUS_DAEMON, TrackerDBusDaemonPriv))
+
+typedef struct {
+ DBusGProxy *fd_proxy;
+ DBConnection *db_con;
+ TrackerConfig *config;
+ Tracker *tracker;
+} TrackerDBusDaemonPriv;
+
+enum {
+ PROP_0,
+ PROP_DB_CONNECTION,
+ PROP_CONFIG,
+ PROP_TRACKER
+};
+
+enum {
+ DAEMON_INDEX_STATE_CHANGE,
+ DAEMON_INDEX_FINISHED,
+ DAEMON_INDEX_PROGRESS,
+ LAST_SIGNAL
+};
+
+static void dbus_daemon_finalize (GObject *object);
+static void dbus_daemon_set_property (GObject *object,
+ guint param_id,
+ const GValue *value,
+ GParamSpec *pspec);
+
+static guint signals[LAST_SIGNAL] = {0};
+
+G_DEFINE_TYPE(TrackerDBusDaemon, tracker_dbus_daemon, G_TYPE_OBJECT)
+
+static void
+tracker_dbus_daemon_class_init (TrackerDBusDaemonClass *klass)
+{
+ GObjectClass *object_class;
+
+ object_class = G_OBJECT_CLASS (klass);
+
+ object_class->finalize = dbus_daemon_finalize;
+ object_class->set_property = dbus_daemon_set_property;
+
+ g_object_class_install_property (object_class,
+ PROP_DB_CONNECTION,
+ g_param_spec_pointer ("db-connection",
+ "DB connection",
+ "DBConnection object use for transactions",
+ G_PARAM_WRITABLE));
+ g_object_class_install_property (object_class,
+ PROP_CONFIG,
+ g_param_spec_pointer ("config",
+ "Config",
+ "TrackerConfig object",
+ G_PARAM_WRITABLE));
+ g_object_class_install_property (object_class,
+ PROP_TRACKER,
+ g_param_spec_pointer ("tracker",
+ "Tracker",
+ "Tracker object",
+ G_PARAM_WRITABLE));
+
+ signals[DAEMON_INDEX_STATE_CHANGE] =
+ g_signal_new ("index-state-change",
+ G_TYPE_FROM_CLASS (klass),
+ G_SIGNAL_RUN_LAST,
+ 0,
+ NULL, NULL,
+ tracker_marshal_VOID__STRING_BOOLEAN_BOOLEAN_BOOLEAN_BOOLEAN_BOOLEAN_BOOLEAN,
+ G_TYPE_NONE,
+ 7,
+ G_TYPE_STRING,
+ G_TYPE_BOOLEAN,
+ G_TYPE_BOOLEAN,
+ G_TYPE_BOOLEAN,
+ G_TYPE_BOOLEAN,
+ G_TYPE_BOOLEAN,
+ G_TYPE_BOOLEAN);
+ signals[DAEMON_INDEX_FINISHED] =
+ g_signal_new ("index-finished",
+ G_TYPE_FROM_CLASS (klass),
+ G_SIGNAL_RUN_LAST,
+ 0,
+ NULL, NULL,
+ g_cclosure_marshal_VOID__INT,
+ G_TYPE_NONE,
+ 1,
+ G_TYPE_INT);
+ signals[DAEMON_INDEX_PROGRESS] =
+ g_signal_new ("index-progress",
+ G_TYPE_FROM_CLASS (klass),
+ G_SIGNAL_RUN_LAST,
+ 0,
+ NULL, NULL,
+ tracker_marshal_VOID__STRING_STRING_INT_INT_INT,
+ G_TYPE_NONE,
+ 5,
+ G_TYPE_STRING,
+ G_TYPE_STRING,
+ G_TYPE_INT,
+ G_TYPE_INT,
+ G_TYPE_INT);
+
+ g_type_class_add_private (object_class, sizeof (TrackerDBusDaemonPriv));
+}
+
+static void
+tracker_dbus_daemon_init (TrackerDBusDaemon *object)
+{
+}
+
+static void
+dbus_daemon_finalize (GObject *object)
+{
+ TrackerDBusDaemonPriv *priv;
+
+ priv = GET_PRIV (object);
+
+ if (priv->fd_proxy) {
+ g_object_unref (priv->fd_proxy);
+ }
+
+ if (priv->config) {
+ g_object_unref (priv->config);
+ }
+
+ G_OBJECT_CLASS (tracker_dbus_daemon_parent_class)->finalize (object);
+}
+
+static void
+dbus_daemon_set_property (GObject *object,
+ guint param_id,
+ const GValue *value,
+ GParamSpec *pspec)
+{
+ TrackerDBusDaemonPriv *priv;
+
+ priv = GET_PRIV (object);
+
+ switch (param_id) {
+ case PROP_DB_CONNECTION:
+ tracker_dbus_daemon_set_db_connection (TRACKER_DBUS_DAEMON (object),
+ g_value_get_pointer (value));
+ break;
+ case PROP_CONFIG:
+ tracker_dbus_daemon_set_config (TRACKER_DBUS_DAEMON (object),
+ g_value_get_pointer (value));
+ break;
+ case PROP_TRACKER:
+ tracker_dbus_daemon_set_tracker (TRACKER_DBUS_DAEMON (object),
+ g_value_get_pointer (value));
+ break;
+
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
+ break;
+ };
+}
+
+TrackerDBusDaemon *
+tracker_dbus_daemon_new (DBConnection *db_con,
+ TrackerConfig *config,
+ Tracker *tracker)
+{
+ TrackerDBusDaemon *object;
+
+ g_return_val_if_fail (db_con != NULL, NULL);
+ g_return_val_if_fail (TRACKER_IS_CONFIG (config), NULL);
+
+ object = g_object_new (TRACKER_TYPE_DBUS_DAEMON,
+ "db-connection", db_con,
+ "config", config,
+ "tracker", tracker,
+ NULL);
+
+ return object;
+}
+
+void
+tracker_dbus_daemon_set_db_connection (TrackerDBusDaemon *object,
+ DBConnection *db_con)
+{
+ TrackerDBusDaemonPriv *priv;
+
+ g_return_if_fail (TRACKER_IS_DBUS_DAEMON (object));
+ g_return_if_fail (db_con != NULL);
+
+ priv = GET_PRIV (object);
+
+ priv->db_con = db_con;
+
+ g_object_notify (G_OBJECT (object), "db-connection");
+}
+
+void
+tracker_dbus_daemon_set_config (TrackerDBusDaemon *object,
+ TrackerConfig *config)
+{
+ TrackerDBusDaemonPriv *priv;
+
+ g_return_if_fail (TRACKER_IS_DBUS_DAEMON (object));
+ g_return_if_fail (TRACKER_IS_CONFIG (config));
+
+ priv = GET_PRIV (object);
+
+ if (priv->config) {
+ g_object_unref (priv->config);
+ }
+
+ priv->config = g_object_ref (config);
+
+ g_object_notify (G_OBJECT (object), "config");
+}
+
+void
+tracker_dbus_daemon_set_tracker (TrackerDBusDaemon *object,
+ Tracker *tracker)
+{
+ TrackerDBusDaemonPriv *priv;
+
+ g_return_if_fail (TRACKER_IS_DBUS_DAEMON (object));
+ g_return_if_fail (tracker != NULL);
+
+ priv = GET_PRIV (object);
+
+ priv->tracker = tracker;
+
+ g_object_notify (G_OBJECT (object), "tracker");
+}
+
+/*
+ * Functions
+ */
+gboolean
+tracker_dbus_daemon_get_version (TrackerDBusDaemon *object,
+ gint *version,
+ GError **error)
+{
+ guint request_id;
+
+ request_id = tracker_dbus_get_next_request_id ();
+
+ tracker_dbus_return_val_if_fail (version != NULL, FALSE, error);
+
+ tracker_dbus_request_new (request_id,
+ "DBus request to get daemon version");
+
+ *version = TRACKER_VERSION_INT;
+
+ tracker_dbus_request_success (request_id);
+
+ return TRUE;
+}
+
+gboolean
+tracker_dbus_daemon_get_status (TrackerDBusDaemon *object,
+ gchar **status,
+ GError **error)
+{
+ TrackerDBusDaemonPriv *priv;
+ guint request_id;
+
+ request_id = tracker_dbus_get_next_request_id ();
+
+ tracker_dbus_return_val_if_fail (status != NULL, FALSE, error);
+
+ priv = GET_PRIV (object);
+
+ tracker_dbus_request_new (request_id,
+ "DBus request to get daemon status");
+
+ *status = g_strdup (tracker_status_get_as_string ());
+
+ tracker_dbus_request_success (request_id);
+
+ return TRUE;
+}
+
+gboolean
+tracker_dbus_daemon_get_services (TrackerDBusDaemon *object,
+ gboolean main_services_only,
+ GHashTable **values,
+ GError **error)
+{
+ TrackerDBusDaemonPriv *priv;
+ TrackerDBResultSet *result_set;
+ guint request_id;
+ DBConnection *db_con;
+
+ /* FIXME: Note, the main_services_only variable is redundant */
+
+ request_id = tracker_dbus_get_next_request_id ();
+
+ tracker_dbus_return_val_if_fail (values != NULL, FALSE, error);
+
+ priv = GET_PRIV (object);
+
+ db_con = priv->db_con;
+
+ tracker_dbus_request_new (request_id,
+ "DBus request to get daemon services");
+
+ result_set = tracker_exec_proc (db_con, "GetServices", 0);
+ *values = tracker_dbus_query_result_to_hash_table (result_set);
+
+ if (result_set) {
+ g_object_unref (result_set);
+ }
+
+ tracker_dbus_request_success (request_id);
+
+ return TRUE;
+}
+
+gboolean
+tracker_dbus_daemon_get_stats (TrackerDBusDaemon *object,
+ GPtrArray **values,
+ GError **error)
+{
+ TrackerDBusDaemonPriv *priv;
+ TrackerDBResultSet *result_set;
+ guint request_id;
+ DBConnection *db_con;
+
+ request_id = tracker_dbus_get_next_request_id ();
+
+ tracker_dbus_return_val_if_fail (values != NULL, FALSE, error);
+
+ priv = GET_PRIV (object);
+
+ db_con = priv->db_con;
+
+ tracker_dbus_request_new (request_id,
+ "DBus request to get daemon service stats");
+
+ result_set = tracker_exec_proc (db_con, "GetStats", 0);
+ *values = tracker_dbus_query_result_to_ptr_array (result_set);
+
+ if (result_set) {
+ g_object_unref (result_set);
+ }
+
+ tracker_dbus_request_success (request_id);
+
+ return TRUE;
+}
+
+gboolean
+tracker_dbus_daemon_set_bool_option (TrackerDBusDaemon *object,
+ const gchar *option,
+ gboolean value,
+ GError **error)
+{
+ TrackerDBusDaemonPriv *priv;
+ guint request_id;
+ gboolean signal_state_change = FALSE;
+
+ /* FIXME: Shouldn't we just make the TrackerConfig module a
+ * DBus object instead so values can be tweaked in real time
+ * over the bus?
+ */
+
+ request_id = tracker_dbus_get_next_request_id ();
+
+ tracker_dbus_return_val_if_fail (option != NULL, FALSE, error);
+
+ priv = GET_PRIV (object);
+
+ tracker_dbus_request_new (request_id,
+ "DBus request to set daemon boolean option, "
+ "key:'%s', value:%s",
+ option,
+ value ? "true" : "false");
+
+ if (strcasecmp (option, "Pause") == 0) {
+ signal_state_change = TRUE;
+ priv->tracker->pause_manual = value;
+
+ if (value) {
+ tracker_log ("Tracker daemon has been paused by user");
+ } else {
+ tracker_log ("Tracker daemon has been resumed by user");
+ }
+ } else if (strcasecmp (option, "FastMerges") == 0) {
+ tracker_config_set_fast_merges (priv->config, value);
+ tracker_log ("Fast merges set to %d", value);
+ } else if (strcasecmp (option, "EnableIndexing") == 0) {
+ signal_state_change = TRUE;
+ tracker_config_set_enable_indexing (priv->config, value);
+ tracker_log ("Enable indexing set to %d", value);
+ } else if (strcasecmp (option, "EnableWatching") == 0) {
+ tracker_config_set_enable_watches (priv->config, value);
+ tracker_log ("Enable Watching set to %d", value);
+ } else if (strcasecmp (option, "LowMemoryMode") == 0) {
+ tracker_config_set_low_memory_mode (priv->config, value);
+ tracker_log ("Extra memory usage set to %d", !value);
+ } else if (strcasecmp (option, "IndexFileContents") == 0) {
+ tracker_config_set_enable_content_indexing (priv->config, value);
+ tracker_log ("Index file contents set to %d", value);
+ } else if (strcasecmp (option, "GenerateThumbs") == 0) {
+ tracker_config_set_enable_thumbnails (priv->config, value);
+ tracker_log ("Generate thumbnails set to %d", value);
+ } else if (strcasecmp (option, "IndexMountedDirectories") == 0) {
+ tracker_config_set_index_mounted_directories (priv->config, value);
+ tracker_log ("Indexing mounted directories set to %d", value);
+ } else if (strcasecmp (option, "IndexRemovableDevices") == 0) {
+ tracker_config_set_index_removable_devices (priv->config, value);
+ tracker_log ("Indexing removable devices set to %d", value);
+ } else if (strcasecmp (option, "BatteryIndex") == 0) {
+ tracker_config_set_disable_indexing_on_battery (priv->config, !value);
+ tracker_log ("Disable index on battery set to %d", !value);
+ } else if (strcasecmp (option, "BatteryIndexInitial") == 0) {
+ tracker_config_set_disable_indexing_on_battery_init (priv->config, !value);
+ tracker_log ("Disable initial index sweep on battery set to %d", !value);
+ }
+
+ if (signal_state_change) {
+ /* Signal state change */
+ g_signal_emit_by_name (object,
+ "index-state-change",
+ tracker_status_get_as_string (),
+ priv->tracker->first_time_index,
+ priv->tracker->in_merge,
+ priv->tracker->pause_manual,
+ tracker_pause_on_battery (),
+ priv->tracker->pause_io,
+ tracker_config_get_enable_indexing (priv->config));
+ }
+
+ tracker_notify_file_data_available ();
+
+ tracker_dbus_request_success (request_id);
+
+ return TRUE;
+}
+
+gboolean
+tracker_dbus_daemon_set_int_option (TrackerDBusDaemon *object,
+ const gchar *option,
+ gint value,
+ GError **error)
+{
+ TrackerDBusDaemonPriv *priv;
+ guint request_id;
+
+ /* FIXME: Shouldn't we just make the TrackerConfig module a
+ * DBus object instead so values can be tweaked in real time
+ * over the bus?
+ */
+
+ request_id = tracker_dbus_get_next_request_id ();
+
+ tracker_dbus_return_val_if_fail (option != NULL, FALSE, error);
+
+ priv = GET_PRIV (object);
+
+ tracker_dbus_request_new (request_id,
+ "DBus request to set daemon integer option, "
+ "key:'%s', value:%d",
+ option,
+ value);
+
+ if (strcasecmp (option, "Throttle") == 0) {
+ tracker_config_set_throttle (priv->config, value);
+ tracker_log ("throttle set to %d", value);
+ } else if (strcasecmp (option, "MaxText") == 0) {
+ tracker_config_set_max_text_to_index (priv->config, value);
+ tracker_log ("Maxinum amount of text set to %d", value);
+ } else if (strcasecmp (option, "MaxWords") == 0) {
+ tracker_config_set_max_words_to_index (priv->config, value);
+ tracker_log ("Maxinum number of unique words set to %d", value);
+ }
+
+ tracker_notify_file_data_available ();
+
+ tracker_dbus_request_success (request_id);
+
+ return TRUE;
+}
+
+gboolean
+tracker_dbus_daemon_shutdown (TrackerDBusDaemon *object,
+ gboolean reindex,
+ GError **error)
+{
+ TrackerDBusDaemonPriv *priv;
+ guint request_id;
+
+ request_id = tracker_dbus_get_next_request_id ();
+
+ tracker_dbus_request_new (request_id,
+ "DBus request to shutdown daemon, "
+ "reindex:%s",
+ reindex ? "yes" : "no");
+
+ priv = GET_PRIV (object);
+
+ tracker_log ("Tracker daemon attempting to restart");
+
+ priv->tracker->reindex = reindex;
+
+ g_timeout_add (500, (GSourceFunc) tracker_do_cleanup, NULL);
+
+ tracker_dbus_request_success (request_id);
+
+ return TRUE;
+}
+
+gboolean
+tracker_dbus_daemon_prompt_index_signals (TrackerDBusDaemon *object,
+ GError **error)
+{
+ TrackerDBusDaemonPriv *priv;
+ guint request_id;
+
+ request_id = tracker_dbus_get_next_request_id ();
+
+ tracker_dbus_request_new (request_id,
+ "DBus request to daemon to signal progress/state");
+
+ priv = GET_PRIV (object);
+
+ /* Signal state change */
+ g_signal_emit_by_name (object,
+ "index-state-change",
+ tracker_status_get_as_string (),
+ priv->tracker->first_time_index,
+ priv->tracker->in_merge,
+ priv->tracker->pause_manual,
+ tracker_pause_on_battery (),
+ priv->tracker->pause_io,
+ tracker_config_get_enable_indexing (priv->config));
+
+ /* Signal progress */
+ g_signal_emit_by_name (object,
+ "index-progress",
+ "Files",
+ "",
+ priv->tracker->index_count,
+ priv->tracker->folders_processed,
+ priv->tracker->folders_count);
+
+ g_signal_emit_by_name (object,
+ "index-progress",
+ "Emails",
+ "",
+ priv->tracker->index_count,
+ priv->tracker->mbox_processed,
+ priv->tracker->mbox_count);
+
+ tracker_dbus_request_success (request_id);
+
+ return TRUE;
+}
Added: branches/indexer-split/src/trackerd/tracker-dbus-daemon.h
==============================================================================
--- (empty file)
+++ branches/indexer-split/src/trackerd/tracker-dbus-daemon.h Mon Apr 21 11:21:20 2008
@@ -0,0 +1,99 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
+/*
+ * Copyright (C) 2006, Mr Jamie McCracken (jamiemcc gnome org)
+ * Copyright (C) 2008, Nokia
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public
+ * License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ */
+
+#ifndef __TRACKER_DBUS_DAEMON_H__
+#define __TRACKER_DBUS_DAEMON_H__
+
+#include <dbus/dbus-glib.h>
+#include <dbus/dbus-glib-bindings.h>
+#include <dbus/dbus-glib-lowlevel.h>
+
+#include <libtracker-common/tracker-config.h>
+
+#include "tracker-db-sqlite.h"
+
+#define TRACKER_DBUS_DAEMON_SERVICE "org.freedesktop.Tracker"
+#define TRACKER_DBUS_DAEMON_PATH "/org/freedesktop/Tracker"
+#define TRACKER_DBUS_DAEMON_INTERFACE "org.freedesktop.Tracker"
+
+G_BEGIN_DECLS
+
+#define TRACKER_TYPE_DBUS_DAEMON (tracker_dbus_daemon_get_type ())
+#define TRACKER_DBUS_DAEMON(object) (G_TYPE_CHECK_INSTANCE_CAST ((object), TRACKER_TYPE_DBUS_DAEMON, TrackerDBusDaemon))
+#define TRACKER_DBUS_DAEMON_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), TRACKER_TYPE_DBUS_DAEMON, TrackerDBusDaemonClass))
+#define TRACKER_IS_DBUS_DAEMON(object) (G_TYPE_CHECK_INSTANCE_TYPE ((object), TRACKER_TYPE_DBUS_DAEMON))
+#define TRACKER_IS_DBUS_DAEMON_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), TRACKER_TYPE_DBUS_DAEMON))
+#define TRACKER_DBUS_DAEMON_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), TRACKER_TYPE_DBUS_DAEMON, TrackerDBusDaemonClass))
+
+typedef struct TrackerDBusDaemon TrackerDBusDaemon;
+typedef struct TrackerDBusDaemonClass TrackerDBusDaemonClass;
+
+struct TrackerDBusDaemon {
+ GObject parent;
+};
+
+struct TrackerDBusDaemonClass {
+ GObjectClass parent;
+};
+
+GType tracker_dbus_daemon_get_type (void);
+
+TrackerDBusDaemon *tracker_dbus_daemon_new (DBConnection *db_con,
+ TrackerConfig *config,
+ Tracker *tracker);
+
+void tracker_dbus_daemon_set_db_connection (TrackerDBusDaemon *object,
+ DBConnection *db_con);
+void tracker_dbus_daemon_set_config (TrackerDBusDaemon *object,
+ TrackerConfig *config);
+void tracker_dbus_daemon_set_tracker (TrackerDBusDaemon *object,
+ Tracker *tracker);
+
+gboolean tracker_dbus_daemon_get_version (TrackerDBusDaemon *object,
+ gint *version,
+ GError **error);
+gboolean tracker_dbus_daemon_get_status (TrackerDBusDaemon *object,
+ gchar **status,
+ GError **error);
+gboolean tracker_dbus_daemon_get_services (TrackerDBusDaemon *object,
+ gboolean main_services_only,
+ GHashTable **values,
+ GError **error);
+gboolean tracker_dbus_daemon_get_stats (TrackerDBusDaemon *object,
+ GPtrArray **values,
+ GError **error);
+gboolean tracker_dbus_daemon_set_bool_option (TrackerDBusDaemon *object,
+ const gchar *option,
+ gboolean value,
+ GError **error);
+gboolean tracker_dbus_daemon_set_int_option (TrackerDBusDaemon *object,
+ const gchar *option,
+ gint value,
+ GError **error);
+gboolean tracker_dbus_daemon_shutdown (TrackerDBusDaemon *object,
+ gboolean reindex,
+ GError **error);
+gboolean tracker_dbus_daemon_prompt_index_signals (TrackerDBusDaemon *object,
+ GError **error);
+
+G_END_DECLS
+
+#endif /* __TRACKER_DBUS_DAEMON_H__ */
Modified: branches/indexer-split/src/trackerd/tracker-dbus-files.c
==============================================================================
--- branches/indexer-split/src/trackerd/tracker-dbus-files.c (original)
+++ branches/indexer-split/src/trackerd/tracker-dbus-files.c Mon Apr 21 11:21:20 2008
@@ -1,5 +1,7 @@
-/* Tracker - indexer and metadata database engine
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
+/*
* Copyright (C) 2006, Mr Jamie McCracken (jamiemcc gnome org)
+ * Copyright (C) 2008, Nokia
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public
@@ -16,72 +18,166 @@
* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301, USA.
*/
+
+#include <config.h>
+
#include <stdlib.h>
#include <string.h>
#include <libtracker-common/tracker-log.h>
+#include <libtracker-common/tracker-utils.h>
-#include "tracker-dbus-methods.h"
-#include "tracker-metadata.h"
+#include "tracker-dbus.h"
#include "tracker-dbus-files.h"
+#include "tracker-db.h"
+#include "tracker-metadata.h"
#include "tracker-service-manager.h"
+#include "tracker-marshal.h"
+
+#define GET_PRIV(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), TRACKER_TYPE_DBUS_FILES, TrackerDBusFilesPriv))
+
+typedef struct {
+ DBConnection *db_con;
+} TrackerDBusFilesPriv;
+
+enum {
+ PROP_0,
+ PROP_DB_CONNECTION
+};
+
+static void dbus_files_finalize (GObject *object);
+static void dbus_files_set_property (GObject *object,
+ guint param_id,
+ const GValue *value,
+ GParamSpec *pspec);
+
+G_DEFINE_TYPE(TrackerDBusFiles, tracker_dbus_files, G_TYPE_OBJECT)
+
+static void
+tracker_dbus_files_class_init (TrackerDBusFilesClass *klass)
+{
+ GObjectClass *object_class;
+
+ object_class = G_OBJECT_CLASS (klass);
+
+ object_class->finalize = dbus_files_finalize;
+ object_class->set_property = dbus_files_set_property;
+
+ g_object_class_install_property (object_class,
+ PROP_DB_CONNECTION,
+ g_param_spec_pointer ("db-connection",
+ "DB connection",
+ "Database connection to use in transactions",
+ G_PARAM_WRITABLE));
+
+ g_type_class_add_private (object_class, sizeof (TrackerDBusFilesPriv));
+}
+
+static void
+tracker_dbus_files_init (TrackerDBusFiles *object)
+{
+}
+
+static void
+dbus_files_finalize (GObject *object)
+{
+ TrackerDBusFilesPriv *priv;
+
+ priv = GET_PRIV (object);
+
+ G_OBJECT_CLASS (tracker_dbus_files_parent_class)->finalize (object);
+}
+
+static void
+dbus_files_set_property (GObject *object,
+ guint param_id,
+ const GValue *value,
+ GParamSpec *pspec)
+{
+ TrackerDBusFilesPriv *priv;
+
+ priv = GET_PRIV (object);
+
+ switch (param_id) {
+ case PROP_DB_CONNECTION:
+ tracker_dbus_files_set_db_connection (TRACKER_DBUS_FILES (object),
+ g_value_get_pointer (value));
+ break;
+
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
+ break;
+ };
+}
+
+TrackerDBusFiles *
+tracker_dbus_files_new (DBConnection *db_con)
+{
+ TrackerDBusFiles *object;
+
+ object = g_object_new (TRACKER_TYPE_DBUS_FILES,
+ "db-connection", db_con,
+ NULL);
+
+ return object;
+}
void
-tracker_dbus_method_files_exists (DBusRec *rec)
+tracker_dbus_files_set_db_connection (TrackerDBusFiles *object,
+ DBConnection *db_con)
{
- DBusMessage *reply;
- DBConnection *db_con;
- DBusError dbus_error;
- char *uri;
- gboolean auto_create;
- gboolean file_valid;
- gboolean result;
- guint32 file_id;
+ TrackerDBusFilesPriv *priv;
- g_return_if_fail (rec && rec->user_data);
+ g_return_if_fail (TRACKER_IS_DBUS_FILES (object));
+ g_return_if_fail (db_con != NULL);
- db_con = rec->user_data;
+ priv = GET_PRIV (object);
+
+ priv->db_con = db_con;
+
+ g_object_notify (G_OBJECT (object), "db-connection");
+}
/*
- <!-- Determines if the file is in tracker's database. The option auto_create if set to TRUE will register the file in the database if not already present -->
- <method name="Exists">
- <arg type="s" name="uri" direction="in" />
- <arg type="b" name="auto_create" direction="in" />
- <arg type="b" name="result" direction="out" />
- </method>
-*/
-
- dbus_error_init(&dbus_error);
- if (!dbus_message_get_args (rec->message, &dbus_error,
- DBUS_TYPE_STRING, &uri,
- DBUS_TYPE_BOOLEAN, &auto_create,
- DBUS_TYPE_INVALID)) {
- tracker_set_error(rec, "DBusError: %s;%s", dbus_error.name, dbus_error.message);
- dbus_error_free(&dbus_error);
- return;
- }
+ * Functions
+ */
+gboolean
+tracker_dbus_files_exist (TrackerDBusFiles *object,
+ const gchar *uri,
+ gboolean auto_create,
+ gboolean *value,
+ GError **error)
+{
+ TrackerDBusFilesPriv *priv;
+ guint request_id;
+ DBConnection *db_con;
+ guint32 file_id;
+ gboolean exists;
+ request_id = tracker_dbus_get_next_request_id ();
- if (!uri) {
- tracker_set_error (rec, "No file was specified");
- return;
- }
+ tracker_dbus_return_val_if_fail (uri != NULL, FALSE, error);
+ tracker_dbus_return_val_if_fail (value != NULL, FALSE, error);
- file_id = tracker_db_get_file_id (db_con, uri);
- result = (file_id > 0);
+ priv = GET_PRIV (object);
- if (!result && auto_create) {
- char *str_file_id, *service;
- FileInfo *info;
+ db_con = priv->db_con;
- info = NULL;
- service = NULL;
- str_file_id = NULL;
+ tracker_dbus_request_new (request_id,
+ "DBus request to see if files exist, "
+ "uri:'%s'",
+ uri);
- info = tracker_create_file_info (uri, 1, 0, 0);
+ file_id = tracker_db_get_file_id (db_con, uri);
+ exists = file_id > 0;
+ if (!exists && auto_create) {
+ FileInfo *info;
+ gchar *service;
+
+ info = tracker_create_file_info (uri, 1, 0, 0);
+
if (!tracker_file_is_valid (uri)) {
- file_valid = FALSE;
info->mime = g_strdup ("unknown");
service = g_strdup ("Files");
} else {
@@ -89,88 +185,67 @@
service = tracker_service_manager_get_service_type_for_mime (info->mime);
info = tracker_get_file_info (info);
}
-
- file_id = tracker_db_create_service (db_con, "Files", info);
+
+ tracker_db_create_service (db_con, "Files", info);
tracker_free_file_info (info);
g_free (service);
-
}
- reply = dbus_message_new_method_return (rec->message);
-
- dbus_message_append_args (reply,
- DBUS_TYPE_BOOLEAN, &result,
- DBUS_TYPE_INVALID);
+ *value = exists;
+
+ tracker_dbus_request_success (request_id);
- dbus_connection_send (rec->connection, reply, NULL);
- dbus_message_unref (reply);
+ return TRUE;
}
+gboolean
+tracker_dbus_files_create (TrackerDBusFiles *object,
+ const gchar *uri,
+ gboolean is_directory,
+ const gchar *mime,
+ gint size,
+ gint mtime,
+ GError **error)
+{
+ TrackerDBusFilesPriv *priv;
+ guint request_id;
+ DBConnection *db_con;
+ FileInfo *info;
+ gchar *name;
+ gchar *path;
+ gchar *service;
+ guint32 file_id;
+ gboolean created;
+
+ request_id = tracker_dbus_get_next_request_id ();
+
+ tracker_dbus_return_val_if_fail (uri != NULL, FALSE, error);
+ tracker_dbus_return_val_if_fail (mime != NULL, FALSE, error);
+ tracker_dbus_return_val_if_fail (size >= 0, FALSE, error);
+ tracker_dbus_return_val_if_fail (mtime >= 0, FALSE, error);
-void
-tracker_dbus_method_files_create (DBusRec *rec)
-{
- DBConnection *db_con;
- DBusMessage *reply;
- DBusError dbus_error;
- char *uri, *name, *path, *mime, *service, *str_mtime, *str_size, *str_file_id;
- gboolean is_dir;
- int size, mtime;
- guint32 file_id;
-
- g_return_if_fail (rec && rec->user_data);
-
- db_con = rec->user_data;
-
-/*
- <!-- searches specified service for entities that match the specified search_text.
- Returns id field of all hits. sort_by_relevance returns results sorted with the biggest hits first (as sorting is slower, you might want to disable this for fast queries) -->
- <method name="Create">
- <arg type="s" name="uri" direction="in" />
- <arg type="b" name="is_directory" direction="in" />
- <arg type="s" name="mime" direction="in" />
- <arg type="i" name="size" direction="in" />
- <arg type="i" name="mtime" direction="in" />
- </method>
-*/
-
- dbus_error_init(&dbus_error);
- if (!dbus_message_get_args (rec->message, &dbus_error,
- DBUS_TYPE_STRING, &uri,
- DBUS_TYPE_BOOLEAN, &is_dir,
- DBUS_TYPE_STRING, &mime,
- DBUS_TYPE_INT32, &size,
- DBUS_TYPE_INT32, &mtime,
- DBUS_TYPE_INVALID)) {
- tracker_set_error(rec, "DBusError: %s;%s", dbus_error.name, dbus_error.message);
- dbus_error_free(&dbus_error);
- return;
- }
-
- if (!uri) {
- tracker_set_error (rec, "No file was specified");
- return;
- }
+ priv = GET_PRIV (object);
+ db_con = priv->db_con;
- FileInfo *info;
-
- info = NULL;
- service = NULL;
- str_file_id = NULL;
+ tracker_dbus_request_new (request_id,
+ "DBus request to create file, "
+ "uri:'%s', is directory:%s, mime:'%s', "
+ "size:%d, mtime:%d",
+ uri,
+ is_directory ? "yes" : "no",
+ mime,
+ size,
+ mtime);
+ /* Create structure */
info = tracker_create_file_info (uri, 1, 0, 0);
info->mime = g_strdup (mime);
- service = tracker_service_manager_get_service_type_for_mime (mime);
- info->is_directory = is_dir;
+ info->is_directory = is_directory;
info->file_size = size;
info->mtime = mtime;
- str_mtime = tracker_int_to_str (mtime);
- str_size = tracker_int_to_str (size);
- name = NULL;
-
if (info->uri[0] == G_DIR_SEPARATOR) {
name = g_path_get_basename (info->uri);
path = g_path_get_dirname (info->uri);
@@ -179,69 +254,110 @@
path = tracker_get_vfs_path (info->uri);
}
-
+ service = tracker_service_manager_get_service_type_for_mime (mime);
file_id = tracker_db_create_service (db_con, service, info);
tracker_free_file_info (info);
- str_file_id = tracker_uint_to_str (file_id);
- if (file_id != 0) {
- tracker_db_set_single_metadata (db_con, service, str_file_id, "File:Modified", str_mtime, FALSE);
- tracker_db_set_single_metadata (db_con, service, str_file_id, "File:Size", str_size, FALSE);
- tracker_db_set_single_metadata (db_con, service, str_file_id, "File:Name", name, FALSE);
- tracker_db_set_single_metadata (db_con, service, str_file_id, "File:Path", path, FALSE);
- tracker_db_set_single_metadata (db_con, service, str_file_id, "File:Format", mime, FALSE);
+ created = file_id != 0;
+
+ if (created) {
+ gchar *file_id_str;
+ gchar *mtime_str;
+ gchar *size_str;
+
+ tracker_dbus_request_comment (request_id,
+ "File or directory has been created in database, uri:'%s'",
+ uri);
+
+ file_id_str = tracker_uint_to_str (file_id);
+ mtime_str = tracker_int_to_str (mtime);
+ size_str = tracker_int_to_str (size);
+
+ tracker_db_set_single_metadata (db_con,
+ service,
+ file_id_str,
+ "File:Modified",
+ mtime_str,
+ FALSE);
+ tracker_db_set_single_metadata (db_con,
+ service,
+ file_id_str,
+ "File:Size",
+ size_str,
+ FALSE);
+ tracker_db_set_single_metadata (db_con,
+ service,
+ file_id_str,
+ "File:Name",
+ name,
+ FALSE);
+ tracker_db_set_single_metadata (db_con,
+ service,
+ file_id_str,
+ "File:Path",
+ path,
+ FALSE);
+ tracker_db_set_single_metadata (db_con,
+ service,
+ file_id_str,
+ "File:Format",
+ mime,
+ FALSE);
tracker_notify_file_data_available ();
+
+ g_free (size_str);
+ g_free (mtime_str);
+ g_free (file_id_str);
+
+ tracker_dbus_request_success (request_id);
+ } else {
+ tracker_dbus_request_comment (request_id,
+ "File/directory was already in the database, uri:'%s'",
+ uri);
}
- g_free (service);
- g_free (str_mtime);
- g_free (str_size);
- g_free (name);
g_free (path);
- g_free (str_file_id);
+ g_free (name);
+ g_free (service);
- reply = dbus_message_new_method_return (rec->message);
- dbus_message_append_args (reply, DBUS_TYPE_INVALID);
- dbus_connection_send (rec->connection, reply, NULL);
- dbus_message_unref (reply);
-
+ return created;
}
-
-void
-tracker_dbus_method_files_delete (DBusRec *rec)
+gboolean
+tracker_dbus_files_delete (TrackerDBusFiles *object,
+ const gchar *uri,
+ GError **error)
{
- TrackerDBResultSet *result_set;
- DBConnection *db_con;
- DBusMessage *reply;
- DBusError dbus_error;
- char *uri, *name, *path, *str_file_id;
- guint32 file_id;
- gboolean is_dir;
+ TrackerDBusFilesPriv *priv;
+ TrackerDBResultSet *result_set;
+ guint request_id;
+ DBConnection *db_con;
+ guint32 file_id;
+ gchar *name;
+ gchar *path;
+ gboolean is_directory;
+ TrackerChangeAction action;
- g_return_if_fail (rec && rec->user_data);
+ request_id = tracker_dbus_get_next_request_id ();
- db_con = rec->user_data;
+ tracker_dbus_return_val_if_fail (uri != NULL, FALSE, error);
-/*
- <!-- Removes the file entry from tracker's database-->
- <method name="Delete">
- <arg type="s" name="uri" direction="in" />
- </method>
-*/
-
- dbus_error_init(&dbus_error);
- if (!dbus_message_get_args (rec->message, &dbus_error,
- DBUS_TYPE_STRING, &uri,
- DBUS_TYPE_INVALID)) {
- tracker_set_error(rec, "DBusError: %s;%s", dbus_error.name, dbus_error.message);
- dbus_error_free(&dbus_error);
- return;
- }
-
- if (!uri) {
- tracker_set_error (rec, "No file was specified");
- return;
+ priv = GET_PRIV (object);
+
+ db_con = priv->db_con;
+
+ tracker_dbus_request_new (request_id,
+ "DBus request to delete file, "
+ "uri:'%s'",
+ uri);
+
+ file_id = tracker_db_get_file_id (db_con, uri);
+ if (file_id == 0) {
+ tracker_dbus_request_comment (request_id,
+ "File or directory was not in database to delete, uri:'%s'",
+ uri);
+ tracker_dbus_request_success (request_id);
+ return TRUE;
}
if (uri[0] == G_DIR_SEPARATOR) {
@@ -252,885 +368,639 @@
path = tracker_get_vfs_path (uri);
}
- file_id = tracker_db_get_file_id (db_con, uri);
- str_file_id = tracker_uint_to_str (file_id);
- is_dir = FALSE;
-
+ is_directory = FALSE;
+
result_set = tracker_exec_proc (db_con, "GetServiceID", path, name, NULL);
-
if (result_set) {
- tracker_db_result_set_get (result_set, 2, &is_dir, -1);
+ tracker_db_result_set_get (result_set, 2, &is_directory, -1);
g_object_unref (result_set);
}
- if (file_id != 0) {
- if (is_dir) {
- tracker_db_insert_pending_file (db_con, file_id, uri, NULL, g_strdup ("unknown"), 0, TRACKER_ACTION_DIRECTORY_DELETED, TRUE, FALSE, -1);
- } else {
- tracker_db_insert_pending_file (db_con, file_id, uri, NULL, g_strdup ("unknown"), 0, TRACKER_ACTION_FILE_DELETED, FALSE, FALSE, -1);
- }
+ if (is_directory) {
+ action = TRACKER_ACTION_DIRECTORY_DELETED;
+ } else {
+ action = TRACKER_ACTION_FILE_DELETED;
}
+
+ tracker_db_insert_pending_file (db_con,
+ file_id,
+ uri,
+ NULL,
+ g_strdup ("unknown"),
+ 0,
+ action,
+ is_directory,
+ FALSE,
+ -1);
- g_free (name);
g_free (path);
- g_free (str_file_id);
+ g_free (name);
- reply = dbus_message_new_method_return (rec->message);
- dbus_message_append_args (reply, DBUS_TYPE_INVALID);
- dbus_connection_send (rec->connection, reply, NULL);
- dbus_message_unref (reply);
-}
+ tracker_dbus_request_success (request_id);
+ return TRUE;
+}
-void
-tracker_dbus_method_files_get_service_type (DBusRec *rec)
+gboolean
+tracker_dbus_files_get_service_type (TrackerDBusFiles *object,
+ const gchar *uri,
+ gchar **value,
+ GError **error)
{
- DBConnection *db_con;
- DBusError dbus_error;
- DBusMessage *reply;
- char *uri, *str_id, *mime, *result;
- guint32 file_id;
-
-/*
- <!-- Get the Service subtype for the file -->
- <method name="GetServiceType">
- <arg type="s" name="uri" direction="in" />
- <arg type="s" name="result" direction="out" />
- </method>
-*/
-
- g_return_if_fail (rec && rec->user_data);
-
- db_con = rec->user_data;
-
- dbus_error_init(&dbus_error);
- if (!dbus_message_get_args (rec->message, &dbus_error,
- DBUS_TYPE_STRING, &uri,
- DBUS_TYPE_INVALID)) {
- tracker_set_error(rec, "DBusError: %s;%s", dbus_error.name, dbus_error.message);
- dbus_error_free(&dbus_error);
- return;
- }
-
- if (!uri) {
- tracker_set_error (rec, "No file was specified");
- return;
- }
-
- file_id = tracker_db_get_file_id (db_con, uri);
-
- if (file_id < 1) {
- tracker_set_error (rec, "File %s was not found in Tracker's database", uri);
- return;
- }
-
- str_id = tracker_uint_to_str (file_id);
-
- mime = tracker_get_metadata (db_con, "Files", str_id, "File:Mime");
+ TrackerDBusFilesPriv *priv;
+ TrackerDBResultSet *result_set;
+ guint request_id;
+ DBConnection *db_con;
+ guint32 file_id;
+ gchar *file_id_str;
+ const gchar *mime = NULL;
+ gchar ***result;
- result = tracker_service_manager_get_service_type_for_mime (mime);
+ request_id = tracker_dbus_get_next_request_id ();
- tracker_log ("Info for file %s is : id=%u, mime=%s, service=%s", uri, file_id, mime, result);
+ tracker_dbus_return_val_if_fail (uri != NULL, FALSE, error);
+ tracker_dbus_return_val_if_fail (value != NULL, FALSE, error);
- g_free (mime);
+ priv = GET_PRIV (object);
- g_free (str_id);
-
- reply = dbus_message_new_method_return (rec->message);
+ db_con = priv->db_con;
+
+ tracker_dbus_request_new (request_id,
+ "DBus request to get service type ",
+ "uri:'%s'",
+ uri);
- dbus_message_append_args (reply,
- DBUS_TYPE_STRING, &result,
- DBUS_TYPE_INVALID);
+ file_id = tracker_db_get_file_id (db_con, uri);
- g_free (result);
+ if (file_id < 1) {
+ tracker_dbus_request_failed (request_id,
+ error,
+ "File '%s' was not found in the database",
+ uri);
+ return FALSE;
+ }
- dbus_connection_send (rec->connection, reply, NULL);
+ /* Get mime */
+ file_id_str = tracker_uint_to_str (file_id);
+
+ mime = NULL;
+ result_set = tracker_db_get_metadata (db_con,
+ "Files",
+ file_id_str,
+ "File:Mime");
- dbus_message_unref (reply);
-}
+ if (result_set) {
+ tracker_db_result_set_get (result_set, 0, &mime, -1);
+ g_object_unref (result_set);
+ }
+ g_free (file_id_str);
-void
-tracker_dbus_method_files_get_text_contents (DBusRec *rec)
-{
- TrackerDBResultSet *result_set;
- DBConnection *db_con;
- DBusError dbus_error;
- char *uri, *service_id;
- int offset, max_length;
- char *str_offset, *str_max_length;
+ if (!mime) {
+ tracker_dbus_request_failed (request_id,
+ error,
+ "Metadata 'File:Mime' for '%s' doesn't exist",
+ uri);
+ return FALSE;
+ }
+
+ tracker_dbus_request_comment (request_id,
+ "Metadata 'File:Mime' is '%s'",
+ mime);
+
+ /* Get service from mime */
+ *value = tracker_service_manager_get_service_type_for_mime (mime);
+
+ tracker_dbus_request_comment (request_id,
+ "Info for file '%s', "
+ "id:%d, mime:'%s', service:'%s'",
+ uri,
+ file_id,
+ mime,
+ *value);
+ tracker_db_free_result (result);
+
+ tracker_dbus_request_success (request_id);
+
+ return TRUE;
+}
+
+gboolean
+tracker_dbus_files_get_text_contents (TrackerDBusFiles *object,
+ const gchar *uri,
+ gint offset,
+ gint max_length,
+ gchar **value,
+ GError **error)
+{
+ TrackerDBusFilesPriv *priv;
+ TrackerDBResultSet *result_set;
+ guint request_id;
+ DBConnection *db_con;
+ gchar *service_id;
+ gchar *offset_str;
+ gchar *max_length_str;
+
+ request_id = tracker_dbus_get_next_request_id ();
+
+ tracker_dbus_return_val_if_fail (uri != NULL, FALSE, error);
+ tracker_dbus_return_val_if_fail (offset >= 0, FALSE, error);
+ tracker_dbus_return_val_if_fail (max_length >= 0, FALSE, error);
+ tracker_dbus_return_val_if_fail (value != NULL, FALSE, error);
-/*
- <!-- Get the "File.Content" field for a file and allows you to specify the offset and amount of text to retrieve -->
- <method name="GetTextContents">
- <arg type="s" name="uri" direction="in" />
- <arg type="i" name="offset" direction="in" />
- <arg type="i" name="max_length" direction="in" />
- <arg type="s" name="result" direction="out" />
- </method>
-*/
-
- g_return_if_fail (rec && rec->user_data);
-
- db_con = rec->user_data;
-
- dbus_error_init(&dbus_error);
- if (!dbus_message_get_args (rec->message, &dbus_error,
- DBUS_TYPE_STRING, &uri,
- DBUS_TYPE_INT32, &offset,
- DBUS_TYPE_INT32, &max_length,
- DBUS_TYPE_INVALID)) {
- tracker_set_error(rec, "DBusError: %s;%s", dbus_error.name, dbus_error.message);
- dbus_error_free(&dbus_error);
- return;
- }
-
- if (!uri) {
- tracker_set_error (rec, "No uri was specified");
- return;
- }
-
- if (offset < 0) {
- tracker_set_error (rec, "Offset must be positive");
- return;
- }
-
- if (max_length < 0) {
- tracker_set_error (rec, "Length of content must be positive");
- return;
- }
+ priv = GET_PRIV (object);
+ db_con = priv->db_con;
+
+ tracker_dbus_request_new (request_id,
+ "DBus request to get text contents, "
+ "uri:'%s', offset:%d, max length:%d",
+ uri,
+ offset,
+ max_length);
service_id = tracker_db_get_id (db_con, "Files", uri);
-
if (!service_id) {
service_id = tracker_db_get_id (db_con, "Emails", uri);
- }
- if (!service_id) {
- g_free (service_id);
- tracker_set_error (rec, "Unable to retrieve serviceID for uri %s", uri);
- return;
- }
+ if (!service_id) {
+ tracker_dbus_request_failed (request_id,
+ error,
+ "Unable to retrieve service ID for uri '%s'",
+ uri);
+ return FALSE;
+ }
+ }
+
+ offset_str = tracker_int_to_str (offset);
+ max_length_str = tracker_int_to_str (max_length);
+
+ result_set = tracker_exec_proc (db_con->blob,
+ "GetFileContents",
+ offset_str,
+ max_length_str,
+ service_id,
+ NULL);
- str_offset = tracker_int_to_str (offset);
- str_max_length = tracker_int_to_str (max_length);
- result_set = tracker_exec_proc (db_con->blob, "GetFileContents",
- str_offset, str_max_length, service_id, NULL);
- g_free (str_offset);
- g_free (str_max_length);
+ g_free (max_length_str);
+ g_free (offset_str);
g_free (service_id);
-
- const gchar *txt;
-
+
if (result_set) {
- DBusMessage *reply;
-
- tracker_db_result_set_get (result_set, 0, &txt, -1);
- reply = dbus_message_new_method_return (rec->message);
-
- dbus_message_append_args (reply,
- DBUS_TYPE_STRING, &txt,
- DBUS_TYPE_INVALID);
-
- dbus_connection_send (rec->connection, reply, NULL);
- dbus_message_unref (reply);
+ tracker_db_result_set_get (result_set, 0, value, -1);
g_object_unref (result_set);
- } else {
- tracker_set_error (rec, "Contents of the URI not stored");
- }
-}
-
-
-void
-tracker_dbus_method_files_search_text_contents (DBusRec *rec)
-{
- DBConnection *db_con;
- DBusError dbus_error;
- char *uri, *text;
- int max_length;
-/*
- <!-- Retrieves a chunk of matching text of specified length that contains the search text in the File.Content field -->
- <method name="SearchTextContents">
- <arg type="s" name="uri" direction="in" />
- <arg type="s" name="text" direction="in" />
- <arg type="i" name="length" direction="in" />
- <arg type="s" name="result" direction="out" />
- </method>
-*/
-
- g_return_if_fail (rec && rec->user_data);
-
- db_con = rec->user_data;
-
- tracker_set_error (rec, "Method not implemented yet");
- return;
-
- /* ******************************************************************** */
-
- dbus_error_init(&dbus_error);
- if (!dbus_message_get_args (rec->message, &dbus_error,
- DBUS_TYPE_STRING, &uri,
- DBUS_TYPE_STRING, &text,
- DBUS_TYPE_INT32, &max_length,
- DBUS_TYPE_INVALID)) {
- tracker_set_error(rec, "DBusError: %s;%s", dbus_error.name, dbus_error.message);
- dbus_error_free(&dbus_error);
- return;
- }
-
- if (uri) {
- TrackerDBResultSet *result_set = NULL;
- char *path, *name, *str_max_length;
-
-
- if (uri[0] == G_DIR_SEPARATOR) {
- name = g_path_get_basename (uri);
- path = g_path_get_dirname (uri);
- } else {
- name = tracker_get_vfs_name (uri);
- path = tracker_get_vfs_path (uri);
+ if (*value == NULL) {
+ *value = g_strdup ("");
}
+ } else {
+ tracker_dbus_request_failed (request_id,
+ error,
+ "The contents of the uri '%s' are not stored",
+ uri);
+ return FALSE;
+ }
- str_max_length = tracker_int_to_str (max_length);
-
- //tracker_exec_proc (db_con, "SearchFileContents", 4, path, name, text, str_max_length);
-
- g_free (str_max_length);
- g_free (path);
- g_free (name);
-
- if (result_set) {
- char *result;
-
- tracker_db_result_set_get (result_set, 0, &result, -1);
-
- if (result) {
- DBusMessage *reply;
-
- reply = dbus_message_new_method_return (rec->message);
-
- dbus_message_append_args (reply,
- DBUS_TYPE_STRING, &result,
- DBUS_TYPE_INVALID);
-
- dbus_connection_send (rec->connection, reply, NULL);
- dbus_message_unref (reply);
- g_free (result);
- }
+ tracker_dbus_request_success (request_id);
- g_object_unref (result_set);
- }
- }
+ return TRUE;
}
-
-void
-tracker_dbus_method_files_get_mtime (DBusRec *rec)
+gboolean
+tracker_dbus_files_search_text_contents (TrackerDBusFiles *object,
+ const gchar *uri,
+ const gchar *text,
+ gint max_length,
+ gchar **value,
+ GError **error)
{
- DBConnection *db_con;
- DBusError dbus_error;
- char *uri;
-
-/*
- <!-- returns mtime of file in seconds since epoch -->
- <method name="GetMTime">
- <arg type="s" name="uri" direction="in" />
- <arg type="i" name="result" direction="out" />
- </method>
-*/
-
- g_return_if_fail (rec && rec->user_data);
-
- db_con = rec->user_data;
-
- dbus_error_init(&dbus_error);
- if (!dbus_message_get_args (rec->message, &dbus_error,
- DBUS_TYPE_STRING, &uri,
- DBUS_TYPE_INVALID)) {
- tracker_set_error(rec, "DBusError: %s;%s", dbus_error.name, dbus_error.message);
- dbus_error_free(&dbus_error);
- return;
- }
-
- if (uri) {
- TrackerDBResultSet *result_set;
- char *path, *name;
-
- if (uri[0] == G_DIR_SEPARATOR) {
- name = g_path_get_basename (uri);
- path = g_path_get_dirname (uri);
- } else {
- name = tracker_get_vfs_name (uri);
- path = tracker_get_vfs_path (uri);
- }
-
- result_set = tracker_exec_proc (db_con, "GetFileMTime", path, name, NULL);
-
- g_free (path);
- g_free (name);
+ TrackerDBusFilesPriv *priv;
+ TrackerDBResultSet *result_set = NULL;
+ guint request_id;
+ DBConnection *db_con;
+ gchar *name;
+ gchar *path;
+ gchar *max_length_str;
- if (result_set) {
- DBusMessage *reply;
- int result;
+ request_id = tracker_dbus_get_next_request_id ();
- tracker_db_result_set_get (result_set, 0, &result, -1);
+ tracker_dbus_return_val_if_fail (uri != NULL, FALSE, error);
+ tracker_dbus_return_val_if_fail (text != NULL, FALSE, error);
+ tracker_dbus_return_val_if_fail (value != NULL, FALSE, error);
- reply = dbus_message_new_method_return (rec->message);
+ priv = GET_PRIV (object);
- dbus_message_append_args (reply,
- DBUS_TYPE_INT32, &result,
- DBUS_TYPE_INVALID);
-
- dbus_connection_send (rec->connection, reply, NULL);
- dbus_message_unref (reply);
+ db_con = priv->db_con;
+
+ tracker_dbus_request_new (request_id,
+ "DBus request to search text contents, "
+ "in uri:'%s' for text:'%s' with max length:%d",
+ uri,
+ text,
+ max_length);
- g_object_unref (result_set);
- }
+ if (uri[0] == G_DIR_SEPARATOR) {
+ name = g_path_get_basename (uri);
+ path = g_path_get_dirname (uri);
+ } else {
+ name = tracker_get_vfs_name (uri);
+ path = tracker_get_vfs_path (uri);
}
-}
-
+
+ max_length_str = tracker_int_to_str (max_length);
-void
-tracker_dbus_method_files_get_by_service_type (DBusRec *rec)
-{
- TrackerDBResultSet *result_set;
- DBConnection *db_con;
- DBusError dbus_error;
- DBusMessage *reply;
- int query_id, limit, offset, row_count;
- char *service;
- char **array;
+ /* result_set = tracker_exec_proc (db_con, */
+ /* "SearchFileContents", */
+ /* 4, */
+ /* path, */
+ /* name, */
+ /* text, */
+ /* max_length_str); */
- g_return_if_fail (rec && rec->user_data);
- db_con = rec->user_data;
+ g_free (max_length_str);
+ g_free (path);
+ g_free (name);
-/*
- <!--
- Retrieves all files that match a service description
- -->
- <method name="GetByServiceType">
- <arg type="i" name="live_query_id" direction="in" />
- <arg type="s" name="file_service" direction="in" />
- <arg type="i" name="offset" direction="in" />
- <arg type="i" name="max_hits" direction="in" />
- <arg type="as" name="result" direction="out" />
- </method>
-*/
-
- dbus_error_init(&dbus_error);
- if (!dbus_message_get_args (rec->message, &dbus_error,
- DBUS_TYPE_INT32, &query_id,
- DBUS_TYPE_STRING, &service,
- DBUS_TYPE_INT32, &offset,
- DBUS_TYPE_INT32, &limit,
- DBUS_TYPE_INVALID)) {
- tracker_set_error(rec, "DBusError: %s;%s", dbus_error.name, dbus_error.message);
- dbus_error_free(&dbus_error);
- return;
+ if (result_set) {
+ tracker_db_result_set_get (result_set, 0, value, -1);
+ g_object_unref (result_set);
+ } else {
+ *value = g_strdup ("");
}
+ /* Fixme: when this is implemented, we should return TRUE and
+ * change this function to the success variant.
+ */
+ tracker_dbus_request_failed (request_id,
+ error,
+ "%s not implemented yet",
+ __PRETTY_FUNCTION__);
+
+ return FALSE;
+}
+
+gboolean
+tracker_dbus_files_get_by_service_type (TrackerDBusFiles *object,
+ gint live_query_id,
+ const gchar *service,
+ gint offset,
+ gint max_hits,
+ gchar ***values,
+ GError **error)
+{
+ TrackerDBusFilesPriv *priv;
+ TrackerDBResultSet *result_set;
+ guint request_id;
+ DBConnection *db_con;
+
+ request_id = tracker_dbus_get_next_request_id ();
+
+ tracker_dbus_return_val_if_fail (service != NULL, FALSE, error);
+ tracker_dbus_return_val_if_fail (offset >= 0, FALSE, error);
+ tracker_dbus_return_val_if_fail (max_hits >= 0, FALSE, error);
+ tracker_dbus_return_val_if_fail (values != NULL, FALSE, error);
+
+ priv = GET_PRIV (object);
+
+ db_con = priv->db_con;
+
+ tracker_dbus_request_new (request_id,
+ "DBus request to get files by service type, "
+ "query id:%d, service:'%s', offset:%d, max hits:%d, ",
+ live_query_id,
+ service,
+ offset,
+ max_hits);
+
if (!tracker_service_manager_is_valid_service (service)) {
- tracker_set_error (rec, "Invalid service %s or service has not been implemented yet", service);
- return;
+ tracker_dbus_request_failed (request_id,
+ error,
+ "Service '%s' is invalid or has not been implemented yet",
+ service);
+ return FALSE;
}
+
+ result_set = tracker_db_get_files_by_service (db_con,
+ service,
+ offset,
+ max_hits);
-
- result_set = tracker_db_get_files_by_service (db_con, service, offset, limit);
-
- array = NULL;
- row_count = 0;
+ *values = tracker_dbus_query_result_to_strv (result_set, NULL);
if (result_set) {
- array = tracker_get_query_result_as_array (result_set, &row_count);
g_object_unref (result_set);
}
- reply = dbus_message_new_method_return (rec->message);
+ tracker_dbus_request_success (request_id);
- dbus_message_append_args (reply,
- DBUS_TYPE_ARRAY, DBUS_TYPE_STRING, &array, row_count,
- DBUS_TYPE_INVALID);
-
- tracker_free_array (array, row_count);
-
- dbus_connection_send (rec->connection, reply, NULL);
- dbus_message_unref (reply);
+ return TRUE;
}
-
-void
-tracker_dbus_method_files_get_by_mime_type (DBusRec *rec)
+gboolean
+tracker_dbus_files_get_by_mime_type (TrackerDBusFiles *object,
+ gint live_query_id,
+ gchar **mime_types,
+ gint offset,
+ gint max_hits,
+ gchar ***values,
+ GError **error)
{
- TrackerDBResultSet *result_set;
- DBConnection *db_con;
- DBusError dbus_error;
- DBusMessage *reply;
- int query_id, n, offset, limit, row_count;
- char **array, **mimes;
+ TrackerDBusFilesPriv *priv;
+ TrackerDBResultSet *result_set;
+ guint request_id;
+ DBConnection *db_con;
- g_return_if_fail (rec && rec->user_data);
+ request_id = tracker_dbus_get_next_request_id ();
- db_con = rec->user_data;
+ tracker_dbus_return_val_if_fail (mime_types != NULL, FALSE, error);
+ tracker_dbus_return_val_if_fail (g_strv_length (mime_types) > 0, FALSE, error);
+ tracker_dbus_return_val_if_fail (offset >= 0, FALSE, error);
+ tracker_dbus_return_val_if_fail (max_hits >= 0, FALSE, error);
+ tracker_dbus_return_val_if_fail (values != NULL, FALSE, error);
-/*
- <!-- Retrieves all non-vfs files of the specified mime type(s) -->
- <method name="GetByMimeType">
- <arg type="i" name="live_query_id" direction="in" />
- <arg type="as" name="mime_types" direction="in" />
- <arg type="i" name="offset" direction="in" />
- <arg type="i" name="max_hits" direction="in" />
- <arg type="as" name="result" direction="out" />
- </method>
-*/
-
- dbus_error_init(&dbus_error);
- if (!dbus_message_get_args (rec->message, &dbus_error,
- DBUS_TYPE_INT32, &query_id,
- DBUS_TYPE_ARRAY, DBUS_TYPE_STRING, &mimes, &n,
- DBUS_TYPE_INT32, &offset,
- DBUS_TYPE_INT32, &limit,
- DBUS_TYPE_INVALID)) {
- tracker_set_error(rec, "DBusError: %s;%s", dbus_error.name, dbus_error.message);
- dbus_error_free(&dbus_error);
- return;
- }
-
- if (n < 1) {
- tracker_set_error (rec, "No mimes specified");
- return;
- }
+ priv = GET_PRIV (object);
- result_set = tracker_db_get_files_by_mime (db_con, mimes, n, offset, limit, FALSE);
+ db_con = priv->db_con;
+
+ tracker_dbus_request_new (request_id,
+ "DBus request to get files by mime types, "
+ "query id:%d, mime types:%d, offset:%d, max hits:%d, ",
+ live_query_id,
+ g_strv_length (mime_types),
+ offset,
+ max_hits);
+
+ result_set = tracker_db_get_files_by_mime (db_con,
+ mime_types,
+ g_strv_length (mime_types),
+ offset,
+ max_hits,
+ FALSE);
- array = NULL;
- row_count = 0;
+ *values = tracker_dbus_query_result_to_strv (result_set, NULL);
if (result_set) {
- array = tracker_get_query_result_as_array (result_set, &row_count);
g_object_unref (result_set);
}
- reply = dbus_message_new_method_return (rec->message);
-
- dbus_message_append_args (reply,
- DBUS_TYPE_ARRAY, DBUS_TYPE_STRING, &array, row_count,
- DBUS_TYPE_INVALID);
-
- tracker_free_array (array, row_count);
+ tracker_dbus_request_success (request_id);
- dbus_connection_send (rec->connection, reply, NULL);
- dbus_message_unref (reply);
+ return TRUE;
}
-
-void
-tracker_dbus_method_files_get_by_mime_type_vfs (DBusRec *rec)
+gboolean
+tracker_dbus_files_get_by_mime_type_vfs (TrackerDBusFiles *object,
+ gint live_query_id,
+ gchar **mime_types,
+ gint offset,
+ gint max_hits,
+ gchar ***values,
+ GError **error)
{
- TrackerDBResultSet *result_set;
- DBConnection *db_con;
- DBusError dbus_error;
- DBusMessage *reply;
- int query_id, n, offset, limit, row_count;
- char **array, **mimes;
+ TrackerDBusFilesPriv *priv;
+ TrackerDBResultSet *result_set;
+ guint request_id;
+ DBConnection *db_con;
- g_return_if_fail (rec && rec->user_data);
+ request_id = tracker_dbus_get_next_request_id ();
- db_con = rec->user_data;
-
-/*
- <!-- Retrieves all vfs files of the specified mime type(s) -->
- <method name="GetByMimeTypeVfs">
- <arg type="i" name="live_query_id" direction="in" />
- <arg type="as" name="mime_types" direction="in" />
- <arg type="i" name="offset" direction="in" />
- <arg type="i" name="max_hits" direction="in" />
- <arg type="as" name="result" direction="out" />
- </method>
-*/
-
- dbus_error_init(&dbus_error);
- if (!dbus_message_get_args (rec->message, &dbus_error,
- DBUS_TYPE_INT32, &query_id,
- DBUS_TYPE_ARRAY, DBUS_TYPE_STRING, &mimes, &n,
- DBUS_TYPE_INT32, &offset,
- DBUS_TYPE_INT32, &limit,
- DBUS_TYPE_INVALID)) {
- tracker_set_error(rec, "DBusError: %s;%s", dbus_error.name, dbus_error.message);
- dbus_error_free(&dbus_error);
- return;
- }
+ tracker_dbus_return_val_if_fail (mime_types != NULL, FALSE, error);
+ tracker_dbus_return_val_if_fail (g_strv_length (mime_types) > 0, FALSE, error);
+ tracker_dbus_return_val_if_fail (offset >= 0, FALSE, error);
+ tracker_dbus_return_val_if_fail (max_hits >= 0, FALSE, error);
+ tracker_dbus_return_val_if_fail (values != NULL, FALSE, error);
- result_set = tracker_db_get_files_by_mime (db_con, mimes, n, offset, limit, TRUE);
+ priv = GET_PRIV (object);
- array = NULL;
- row_count = 0;
+ db_con = priv->db_con;
+
+ tracker_dbus_request_new (request_id,
+ "DBus request to get files by mime types (VFS), "
+ "query id:%d, mime types:%d, offset:%d, max hits:%d, ",
+ live_query_id,
+ g_strv_length (mime_types),
+ offset,
+ max_hits);
+
+ /* NOTE: The only difference between this function and the
+ * non-VFS version is the boolean in this function call:
+ */
+ result_set = tracker_db_get_files_by_mime (db_con,
+ mime_types,
+ g_strv_length (mime_types),
+ offset,
+ max_hits,
+ TRUE);
+ *values = tracker_dbus_query_result_to_strv (result_set, NULL);
+
if (result_set) {
- array = tracker_get_query_result_as_array (result_set, &row_count);
g_object_unref (result_set);
}
- reply = dbus_message_new_method_return (rec->message);
-
- dbus_message_append_args (reply,
- DBUS_TYPE_ARRAY, DBUS_TYPE_STRING, &array, row_count,
- DBUS_TYPE_INVALID);
-
- tracker_free_array (array, row_count);
+ tracker_dbus_request_success (request_id);
- dbus_connection_send (rec->connection, reply, NULL);
- dbus_message_unref (reply);
+ return TRUE;
}
-
-void
-tracker_dbus_method_files_get_metadata_for_files_in_folder (DBusRec *rec)
+gboolean
+tracker_dbus_files_get_mtime (TrackerDBusFiles *object,
+ const gchar *uri,
+ gint *value,
+ GError **error)
{
- TrackerDBResultSet *result_set;
- DBConnection *db_con;
- DBusError dbus_error;
- int i, query_id, folder_name_len, file_id, n;
- char *tmp_folder, *folder, *str;
- char **array;
- GString *sql;
- FieldDef *defs[255];
- gboolean needs_join[255];
-
- g_return_if_fail (rec && rec->user_data);
-
- db_con = rec->user_data;
-
-/*
- <!-- Retrieves all non-vfs files in a folder complete with all requested metadata fields. An array of stringarrays is outpout with uri and field metadata as part of the array -->
- <method name="GetMetadataForFilesInFolder">
- <arg type="i" name="live_query_id" direction="in" />
- <arg type="s" name="uri" direction="in" />
- <arg type="as" name="fields" direction="in" />
- <arg type="aas" name="values" direction="out" />
- </method>
-*/
-
-
- dbus_error_init(&dbus_error);
- if (!dbus_message_get_args (rec->message, &dbus_error,
- DBUS_TYPE_INT32, &query_id,
- DBUS_TYPE_STRING, &tmp_folder,
- DBUS_TYPE_ARRAY, DBUS_TYPE_STRING, &array, &n,
- DBUS_TYPE_INVALID)) {
- tracker_set_error(rec, "DBusError: %s;%s", dbus_error.name, dbus_error.message);
- dbus_error_free(&dbus_error);
- return;
- }
-
-
- for (i = 0; i < n; i++) {
- defs[i] = tracker_db_get_field_def (db_con, array[i]);
-
- if (!defs[i]) {
- tracker_set_error(rec, "Error: Metadata field %s was not found", array[i]);
- dbus_error_free(&dbus_error);
- }
+ TrackerDBusFilesPriv *priv;
+ TrackerDBResultSet *result_set;
+ guint request_id;
+ DBConnection *db_con;
+ gchar *path;
+ gchar *name;
- }
+ request_id = tracker_dbus_get_next_request_id ();
+ tracker_dbus_return_val_if_fail (uri != NULL, FALSE, error);
+ tracker_dbus_return_val_if_fail (value != NULL, FALSE, error);
- folder_name_len = strlen (tmp_folder);
+ priv = GET_PRIV (object);
- folder_name_len--;
+ db_con = priv->db_con;
+
+ tracker_dbus_request_new (request_id,
+ "DBus request for mtime, "
+ "uri:'%s'",
+ uri);
- if (folder_name_len != 0 && tmp_folder[folder_name_len] == G_DIR_SEPARATOR) {
- /* remove trailing 'G_DIR_SEPARATOR' */
- folder = g_strndup (tmp_folder, folder_name_len);
+ if (uri[0] == G_DIR_SEPARATOR) {
+ name = g_path_get_basename (uri);
+ path = g_path_get_dirname (uri);
} else {
- folder = g_strdup (tmp_folder);
- }
-
- file_id = tracker_get_file_id (db_con, folder, FALSE);
-
- if (file_id == 0) {
- tracker_set_error (rec, "Cannot find folder %s in Tracker database", folder);
- return;
- }
-
- /* build SELECT clause */
- sql = g_string_new (" SELECT (F.Path || ");
-
- g_string_append_printf (sql, "'%s' || F.Name) as PathName ", G_DIR_SEPARATOR_S);
-
- for (i = 1; i <= n; i++) {
-
- char *my_field = tracker_db_get_field_name ("Files", array[i-1]);
-
- if (my_field) {
- g_string_append_printf (sql, ", F.%s ", my_field);
- g_free (my_field);
- needs_join[i-1] = FALSE;
- } else {
- char *disp_field = tracker_db_get_display_field (defs[i]);
- g_string_append_printf (sql, ", M%d.%s ", i, disp_field);
- g_free (disp_field);
- needs_join[i-1] = TRUE;
- }
+ name = tracker_get_vfs_name (uri);
+ path = tracker_get_vfs_path (uri);
}
+ result_set = tracker_exec_proc (db_con,
+ "GetFileMTime",
+ path,
+ name,
+ NULL);
+ g_free (path);
+ g_free (name);
- /* build FROM clause */
- g_string_append (sql, " FROM Services F ");
-
- for (i = 0; i < n; i++) {
-
- char *table;
-
- if (!needs_join[i]) {
- continue;
- }
-
- table = tracker_get_metadata_table (defs[i]->type);
-
- g_string_append_printf (sql, " LEFT OUTER JOIN %s M%d ON F.ID = M%d.ServiceID AND M%d.MetaDataID = %s ", table, i+1, i+1, i+1, defs[i]->id);
-
- g_free (table);
-
+ if (!result_set) {
+ tracker_dbus_request_failed (request_id,
+ error,
+ "There is no file mtime in the database for '%s'",
+ uri);
+ return FALSE;
}
- dbus_free_string_array(array);
-
- /* build WHERE clause */
-
- g_string_append_printf (sql, " WHERE F.Path = '%s' ", folder);
-
- str = g_string_free (sql, FALSE);
-
- tracker_debug (str);
-
- result_set = tracker_db_interface_execute_query (db_con->db, str);
-
- g_free (str);
-
- tracker_dbus_reply_with_query_result (rec, result_set);
-
+ tracker_db_result_set_get (result_set, 0, value, -1);
g_object_unref (result_set);
-}
-
-void
-tracker_dbus_method_files_search_by_text_mime (DBusRec *rec)
-{
- TrackerDBResultSet *result_set;
- DBConnection *db_con;
- DBusError dbus_error;
- DBusMessage *reply;
- char *str;
- char **array;
- int n, row_count;
-
- g_return_if_fail (rec && rec->user_data);
-
- db_con = rec->user_data;
-
- dbus_error_init(&dbus_error);
- if (!dbus_message_get_args (rec->message, &dbus_error,
- DBUS_TYPE_STRING, &str,
- DBUS_TYPE_ARRAY, DBUS_TYPE_STRING, &array, &n,
- DBUS_TYPE_INVALID)) {
- tracker_set_error(rec, "DBusError: %s;%s", dbus_error.name, dbus_error.message);
- dbus_error_free(&dbus_error);
- return;
- }
-
- result_set = tracker_db_search_text_mime (db_con, str, array);
+ tracker_dbus_request_success (request_id);
+
+ return TRUE;
+}
+
+gboolean
+tracker_dbus_files_get_metadata_for_files_in_folder (TrackerDBusFiles *object,
+ gint live_query_id,
+ const gchar *uri,
+ gchar **fields,
+ GPtrArray **values,
+ GError **error)
+{
+ TrackerDBusFilesPriv *priv;
+ TrackerDBResultSet *result_set;
+ guint request_id;
+ DBConnection *db_con;
+ FieldDef *defs[255];
+ guint i;
+ gchar *uri_filtered;
+ guint32 file_id;
+ GString *sql;
+ gboolean needs_join[255];
+ gchar *query;
+
+ request_id = tracker_dbus_get_next_request_id ();
+
+ tracker_dbus_return_val_if_fail (uri != NULL, FALSE, error);
+ tracker_dbus_return_val_if_fail (fields != NULL, FALSE, error);
+ tracker_dbus_return_val_if_fail (g_strv_length (fields) > 0, FALSE, error);
+ tracker_dbus_return_val_if_fail (values != NULL, FALSE, error);
- array = NULL;
- row_count = 0;
+ priv = GET_PRIV (object);
- if (result_set) {
- gboolean valid = TRUE;
- gchar *prefix, *name;
- gint i = 0;
-
- row_count = tracker_db_result_set_get_n_rows (result_set);
- array = g_new (gchar *, row_count);
-
- while (valid) {
- tracker_db_result_set_get (result_set,
- 0, &prefix,
- 1, &name,
- -1);
-
- array[i] = g_build_filename (prefix, name, NULL);
- valid = tracker_db_result_set_iter_next (result_set);
- i++;
+ db_con = priv->db_con;
+
+ tracker_dbus_request_new (request_id,
+ "DBus request for metadata for files in folder, "
+ "query id:%d, uri:'%s', fields:%d",
+ live_query_id,
+ uri,
+ g_strv_length (fields));
+
+ /* Get fields for metadata list provided */
+ for (i = 0; i < g_strv_length (fields); i++) {
+ defs[i] = tracker_db_get_field_def (db_con, fields[i]);
- g_free (prefix);
- g_free (name);
+ if (!defs[i]) {
+ tracker_dbus_request_failed (request_id,
+ error,
+ "Metadata field '%s' was not found",
+ fields[i]);
+ return FALSE;
}
- g_object_unref (result_set);
- } else {
- array = g_new (char *, 1);
-
- array[0] = NULL;
}
-
- reply = dbus_message_new_method_return (rec->message);
-
- dbus_message_append_args (reply,
- DBUS_TYPE_ARRAY, DBUS_TYPE_STRING, &array, row_count,
- DBUS_TYPE_INVALID);
-
- tracker_free_array (array, row_count);
-
- dbus_connection_send (rec->connection, reply, NULL);
- dbus_message_unref (reply);
-}
-
-
-void
-tracker_dbus_method_files_search_by_text_location (DBusRec *rec)
-{
- TrackerDBResultSet *result_set;
- DBConnection *db_con;
- DBusError dbus_error;
- DBusMessage *reply;
- char *str, *location;
- char **array;
- int row_count;
-
- g_return_if_fail (rec && rec->user_data);
-
- db_con = rec->user_data;
-
- dbus_error_init(&dbus_error);
- if (!dbus_message_get_args (rec->message, &dbus_error,
- DBUS_TYPE_STRING, &str,
- DBUS_TYPE_STRING, &location,
- DBUS_TYPE_INVALID)) {
- tracker_set_error(rec, "DBusError: %s;%s", dbus_error.name, dbus_error.message);
- dbus_error_free(&dbus_error);
- return;
+ if (g_str_has_suffix (uri, G_DIR_SEPARATOR_S)) {
+ /* Remove trailing 'G_DIR_SEPARATOR' */
+ uri_filtered = g_strndup (uri, strlen (uri) - 1);
+ } else {
+ uri_filtered = g_strdup (uri);
}
- result_set = tracker_db_search_text_location (db_con, str, location);
-
- array = NULL;
- row_count = 0;
-
- if (result_set) {
- gboolean valid = TRUE;
- gchar *prefix, *name;
- gint i = 0;
-
- row_count = tracker_db_result_set_get_n_rows (result_set);
- array = g_new (char *, row_count);
-
- while (valid) {
- tracker_db_result_set_get (result_set,
- 0, &prefix,
- 1, &name,
- -1);
-
- array[i] = g_build_filename (prefix, name, NULL);
- valid = tracker_db_result_set_iter_next (result_set);
- i++;
+ /* Get file ID in database */
+ file_id = tracker_db_get_file_id (db_con, uri_filtered);
+ if (file_id == 0) {
+ g_free (uri_filtered);
+ tracker_dbus_request_failed (request_id,
+ error,
+ "File or directory was not in database, uri:'%s'",
+ uri);
+ return FALSE;
+ }
+
+ /* Build SELECT clause */
+ sql = g_string_new (" ");
+ g_string_append_printf (sql,
+ "SELECT (F.Path || '%s' || F.Name) as PathName ",
+ G_DIR_SEPARATOR_S);
+
+ for (i = 1; i <= g_strv_length (fields); i++) {
+ gchar *field;
+
+ field = tracker_db_get_field_name ("Files", fields[i-1]);
+
+ if (field) {
+ g_string_append_printf (sql, ", F.%s ", field);
+ g_free (field);
+ needs_join[i - 1] = FALSE;
+ } else {
+ gchar *display_field;
- g_free (prefix);
- g_free (name);
+ display_field = tracker_db_get_display_field (defs[i]);
+ g_string_append_printf (sql, ", M%d.%s ", i, display_field);
+ g_free (display_field);
+ needs_join[i - 1] = TRUE;
}
-
- g_object_unref (result_set);
- } else {
- array = g_new (char *, 1);
-
- array[0] = NULL;
}
+ /* Build FROM clause */
+ g_string_append (sql,
+ " FROM Services F ");
- reply = dbus_message_new_method_return (rec->message);
-
- dbus_message_append_args (reply,
- DBUS_TYPE_ARRAY, DBUS_TYPE_STRING, &array, row_count,
- DBUS_TYPE_INVALID);
+ for (i = 0; i < g_strv_length (fields); i++) {
+ gchar *table;
- tracker_free_array (array, row_count);
+ if (!needs_join[i]) {
+ continue;
+ }
- dbus_connection_send (rec->connection, reply, NULL);
- dbus_message_unref (reply);
-}
+ table = tracker_get_metadata_table (defs[i]->type);
+ g_string_append_printf (sql,
+ " LEFT OUTER JOIN %s M%d ON "
+ "F.ID = M%d.ServiceID AND "
+ "M%d.MetaDataID = %s ",
+ table,
+ i+1,
+ i+1,
+ i+1,
+ defs[i]->id);
-void
-tracker_dbus_method_files_search_by_text_mime_location (DBusRec *rec)
-{
- TrackerDBResultSet *result_set;
- DBConnection *db_con;
- DBusError dbus_error;
- DBusMessage *reply;
- char *str, *location;
- char **array;
- int n, row_count;
-
- g_return_if_fail (rec && rec->user_data);
-
- db_con = rec->user_data;
-
- dbus_error_init(&dbus_error);
- if (!dbus_message_get_args (rec->message, &dbus_error,
- DBUS_TYPE_STRING, &str,
- DBUS_TYPE_ARRAY, DBUS_TYPE_STRING, &array, &n,
- DBUS_TYPE_STRING, &location,
- DBUS_TYPE_INVALID)) {
- tracker_set_error(rec, "DBusError: %s;%s", dbus_error.name, dbus_error.message);
- dbus_error_free(&dbus_error);
- return;
+ g_free (table);
}
- result_set = tracker_db_search_text_mime_location (db_con, str, array, location);
-
- array = NULL;
- row_count = 0;
+ /* Build WHERE clause */
+ g_string_append_printf (sql,
+ " WHERE F.Path = '%s' ",
+ uri_filtered);
+ g_free (uri_filtered);
+
+ query = g_string_free (sql, FALSE);
+ result_set = tracker_db_interface_execute_query (db_con->db, query);
+ *values = tracker_dbus_query_result_to_ptr_array (result_set);
if (result_set) {
- gboolean valid = TRUE;
- gchar *prefix, *name;
- gint i = 0;
-
- row_count = tracker_db_result_set_get_n_rows (result_set);
- array = g_new (char *, row_count);
-
- while (valid) {
- tracker_db_result_set_get (result_set,
- 0, &prefix,
- 1, &name,
- -1);
-
- array[i] = g_build_filename (prefix, name, NULL);
- valid = tracker_db_result_set_iter_next (result_set);
- i++;
-
- g_free (prefix);
- g_free (name);
- }
-
g_object_unref (result_set);
- } else {
- array = g_new (char *, 1);
-
- array[0] = NULL;
}
+ g_free (query);
- reply = dbus_message_new_method_return (rec->message);
-
- dbus_message_append_args (reply,
- DBUS_TYPE_ARRAY, DBUS_TYPE_STRING, &array, row_count,
- DBUS_TYPE_INVALID);
-
- tracker_free_array (array, row_count);
+ tracker_dbus_request_success (request_id);
- dbus_connection_send (rec->connection, reply, NULL);
- dbus_message_unref (reply);
+ return TRUE;
}
Modified: branches/indexer-split/src/trackerd/tracker-dbus-files.h
==============================================================================
--- branches/indexer-split/src/trackerd/tracker-dbus-files.h (original)
+++ branches/indexer-split/src/trackerd/tracker-dbus-files.h Mon Apr 21 11:21:20 2008
@@ -1,5 +1,7 @@
-/* Tracker - indexer and metadata database engine
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
+/*
* Copyright (C) 2006, Mr Jamie McCracken (jamiemcc gnome org)
+ * Copyright (C) 2008, Nokia
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public
@@ -17,27 +19,109 @@
* Boston, MA 02110-1301, USA.
*/
+#ifndef __TRACKER_DBUS_FILES_H__
+#define __TRACKER_DBUS_FILES_H__
+#include <dbus/dbus-glib.h>
+#include <dbus/dbus-glib-bindings.h>
+#include <dbus/dbus-glib-lowlevel.h>
+
+#include "tracker-db-sqlite.h"
+
+#define TRACKER_DBUS_FILES_SERVICE "org.freedesktop.Tracker"
+#define TRACKER_DBUS_FILES_PATH "/org/freedesktop/Tracker/Files"
+#define TRACKER_DBUS_FILES_INTERFACE "org.freedesktop.Tracker.Files"
+
+G_BEGIN_DECLS
+
+#define TRACKER_TYPE_DBUS_FILES (tracker_dbus_files_get_type ())
+#define TRACKER_DBUS_FILES(object) (G_TYPE_CHECK_INSTANCE_CAST ((object), TRACKER_TYPE_DBUS_FILES, TrackerDBusFiles))
+#define TRACKER_DBUS_FILES_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), TRACKER_TYPE_DBUS_FILES, TrackerDBusFilesClass))
+#define TRACKER_IS_DBUS_FILES(object) (G_TYPE_CHECK_INSTANCE_TYPE ((object), TRACKER_TYPE_DBUS_FILES))
+#define TRACKER_IS_DBUS_FILES_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), TRACKER_TYPE_DBUS_FILES))
+#define TRACKER_DBUS_FILES_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), TRACKER_TYPE_DBUS_FILES, TrackerDBusFilesClass))
+
+typedef struct TrackerDBusFiles TrackerDBusFiles;
+typedef struct TrackerDBusFilesClass TrackerDBusFilesClass;
+
+struct TrackerDBusFiles {
+ GObject parent;
+};
+
+struct TrackerDBusFilesClass {
+ GObjectClass parent;
+};
+
+GType tracker_dbus_files_get_type (void);
+
+TrackerDBusFiles *
+ tracker_dbus_files_new (DBConnection *db_con);
+void tracker_dbus_files_set_db_connection (TrackerDBusFiles *object,
+ DBConnection *db_con);
+
+gboolean tracker_dbus_files_exist (TrackerDBusFiles *object,
+ const gchar *uri,
+ gboolean auto_create,
+ gboolean *value,
+ GError **error);
+gboolean tracker_dbus_files_create (TrackerDBusFiles *object,
+ const gchar *uri,
+ gboolean is_directory,
+ const gchar *mime,
+ gint size,
+ gint mtime,
+ GError **error);
+gboolean tracker_dbus_files_delete (TrackerDBusFiles *object,
+ const gchar *uri,
+ GError **error);
+gboolean tracker_dbus_files_get_service_type (TrackerDBusFiles *object,
+ const gchar *uri,
+ gchar **value,
+ GError **error);
+gboolean tracker_dbus_files_get_text_contents (TrackerDBusFiles *object,
+ const gchar *uri,
+ gint offset,
+ gint max_length,
+ gchar **value,
+ GError **error);
+gboolean tracker_dbus_files_search_text_contents (TrackerDBusFiles *object,
+ const gchar *uri,
+ const gchar *text,
+ gint max_length,
+ gchar **value,
+ GError **error);
+gboolean tracker_dbus_files_get_by_service_type (TrackerDBusFiles *object,
+ gint live_query_id,
+ const gchar *service,
+ gint offset,
+ gint max_hits,
+ gchar ***values,
+ GError **error);
+gboolean tracker_dbus_files_get_by_mime_type (TrackerDBusFiles *object,
+ gint live_query_id,
+ gchar **mime_types,
+ gint offset,
+ gint max_hits,
+ gchar ***values,
+ GError **error);
+gboolean tracker_dbus_files_get_by_mime_type_vfs (TrackerDBusFiles *object,
+ gint live_query_id,
+ gchar **mime_types,
+ gint offset,
+ gint max_hits,
+ gchar ***values,
+ GError **error);
+gboolean tracker_dbus_files_get_mtime (TrackerDBusFiles *object,
+ const gchar *uri,
+ gint *value,
+ GError **error);
+gboolean tracker_dbus_files_get_metadata_for_files_in_folder (TrackerDBusFiles *object,
+ gint live_query_id,
+ const gchar *uri,
+ gchar **fields,
+ GPtrArray **values,
+ GError **error);
-#ifndef _TRACKER_DBUS_FILES_H_
-#define _TRACKER_DBUS_FILES_H_
+G_END_DECLS
-#include "tracker-dbus.h"
-
-void tracker_dbus_method_files_exists (DBusRec *rec);
-void tracker_dbus_method_files_create (DBusRec *rec);
-void tracker_dbus_method_files_delete (DBusRec *rec);
-void tracker_dbus_method_files_get_service_type (DBusRec *rec);
-void tracker_dbus_method_files_get_text_contents (DBusRec *rec);
-void tracker_dbus_method_files_search_text_contents (DBusRec *rec);
-void tracker_dbus_method_files_get_mtime (DBusRec *rec);
-void tracker_dbus_method_files_get_by_service_type (DBusRec *rec);
-void tracker_dbus_method_files_get_by_mime_type (DBusRec *rec);
-void tracker_dbus_method_files_get_by_mime_type_vfs (DBusRec *rec);
-
-void tracker_dbus_method_files_get_metadata_for_files_in_folder (DBusRec *rec);
-void tracker_dbus_method_files_search_by_text_mime (DBusRec *rec);
-void tracker_dbus_method_files_search_by_text_location (DBusRec *rec);
-void tracker_dbus_method_files_search_by_text_mime_location (DBusRec *rec);
-
-#endif
+#endif /* __TRACKER_DBUS_FILES_H__ */
Modified: branches/indexer-split/src/trackerd/tracker-dbus-keywords.c
==============================================================================
--- branches/indexer-split/src/trackerd/tracker-dbus-keywords.c (original)
+++ branches/indexer-split/src/trackerd/tracker-dbus-keywords.c Mon Apr 21 11:21:20 2008
@@ -1,5 +1,7 @@
-/* Tracker - indexer and metadata database engine
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
+/*
* Copyright (C) 2006, Mr Jamie McCracken (jamiemcc gnome org)
+ * Copyright (C) 2008, Nokia
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public
@@ -17,643 +19,600 @@
* Boston, MA 02110-1301, USA.
*/
+#include <config.h>
+
+#include <stdlib.h>
#include <string.h>
#include <libtracker-common/tracker-log.h>
+#include <libtracker-common/tracker-utils.h>
-#include "tracker-dbus-methods.h"
+#include "tracker-dbus.h"
#include "tracker-dbus-keywords.h"
+#include "tracker-db.h"
+#include "tracker-marshal.h"
-extern Tracker *tracker;
-
-/*
-static void
-update_keywords_metadata (DBConnection *db_con, const char* service, const char *path, const char *name)
-{
- char ***res;
- char *tmp;
- char *id;
- char *keywords;
-
- tmp = g_build_filename (path, name, NULL);
- id = tracker_db_get_id (db_con, service, tmp);
-
- g_free (tmp);
+#define GET_PRIV(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), TRACKER_TYPE_DBUS_KEYWORDS, TrackerDBusKeywordsPriv))
- if (!id) {
- return;
- }
+typedef struct {
+ DBusGProxy *fd_proxy;
+ DBConnection *db_con;
+} TrackerDBusKeywordsPriv;
+
+enum {
+ PROP_0,
+ PROP_DB_CONNECTION
+};
+
+enum {
+ KEYWORD_ADDED,
+ KEYWORD_REMOVED,
+ LAST_SIGNAL
+};
+
+static void dbus_keywords_finalize (GObject *object);
+static void dbus_keywords_set_property (GObject *object,
+ guint param_id,
+ const GValue *value,
+ GParamSpec *pspec);
- res = tracker_exec_proc (db_con, "GetKeywords", 2, path, name);
+static guint signals[LAST_SIGNAL] = {0};
- if (res) {
- GString *words;
- char **row;
- int i;
+G_DEFINE_TYPE(TrackerDBusKeywords, tracker_dbus_keywords, G_TYPE_OBJECT)
- words = g_string_new (" ");
- i = 0;
-
- while ((row = tracker_db_get_row (res, i))) {
- if (row[0]) {
-
- if (i != 0) {
- words = g_string_append (words, ",");
- }
+static void
+tracker_dbus_keywords_class_init (TrackerDBusKeywordsClass *klass)
+{
+ GObjectClass *object_class;
- words = g_string_append (words, row[0]);
- i++;
- }
- }
+ object_class = G_OBJECT_CLASS (klass);
- tracker_db_free_result (res);
+ object_class->finalize = dbus_keywords_finalize;
+ object_class->set_property = dbus_keywords_set_property;
- keywords = g_string_free (words, FALSE);
+ g_object_class_install_property (object_class,
+ PROP_DB_CONNECTION,
+ g_param_spec_pointer ("db-connection",
+ "DB connection",
+ "Database connection to use in transactions",
+ G_PARAM_WRITABLE));
+
+ signals[KEYWORD_ADDED] =
+ g_signal_new ("keyword-added",
+ G_TYPE_FROM_CLASS (klass),
+ G_SIGNAL_RUN_LAST,
+ 0,
+ NULL, NULL,
+ tracker_marshal_VOID__STRING_STRING_STRING,
+ G_TYPE_NONE,
+ 3, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING);
+ signals[KEYWORD_ADDED] =
+ g_signal_new ("keyword-removed",
+ G_TYPE_FROM_CLASS (klass),
+ G_SIGNAL_RUN_LAST,
+ 0,
+ NULL, NULL,
+ tracker_marshal_VOID__STRING_STRING_STRING,
+ G_TYPE_NONE,
+ 3, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING);
+ g_type_class_add_private (object_class, sizeof (TrackerDBusKeywordsPriv));
+}
- tracker_db_update_keywords (db_con, service, id, keywords);
+static void
+tracker_dbus_keywords_init (TrackerDBusKeywords *object)
+{
+}
- g_free (keywords);
+static void
+dbus_keywords_finalize (GObject *object)
+{
+ TrackerDBusKeywordsPriv *priv;
+
+ priv = GET_PRIV (object);
- } else {
- tracker_db_update_keywords (db_con, service, id, " ");
+ if (priv->fd_proxy) {
+ g_object_unref (priv->fd_proxy);
}
- g_free (id);
+ G_OBJECT_CLASS (tracker_dbus_keywords_parent_class)->finalize (object);
}
-*/
-void
-tracker_dbus_signal_keywords_added (const char *service, const char *uri, const char *keyword)
+static void
+dbus_keywords_set_property (GObject *object,
+ guint param_id,
+ const GValue *value,
+ GParamSpec *pspec)
{
- DBusMessage *msg;
- dbus_uint32_t serial = 0;
+ TrackerDBusKeywordsPriv *priv;
- msg = dbus_message_new_signal (TRACKER_OBJECT,
- TRACKER_INTERFACE_KEYWORDS,
- TRACKER_SIGNAL_KEYWORD_ADDED);
-
- if (!msg || !tracker->dbus_con) {
- return;
- }
+ priv = GET_PRIV (object);
- /*
-
- <signal name="KeywordAdded">
- <arg type="s" name="service"/>
- <arg type="s" name="uri" />
- <arg type="s" name="keyword" />
- </signal>
- */
-
- dbus_message_append_args (msg,
- DBUS_TYPE_STRING, &service,
- DBUS_TYPE_STRING, &uri,
- DBUS_TYPE_STRING, &keyword,
- DBUS_TYPE_INVALID);
-
- dbus_message_set_no_reply (msg, TRUE);
-
- if (!dbus_connection_send (tracker->dbus_con, msg, &serial)) {
- tracker_error ("Raising the keyword added signal failed");
- return;
- }
-
- dbus_connection_flush (tracker->dbus_con);
+ switch (param_id) {
+ case PROP_DB_CONNECTION:
+ tracker_dbus_keywords_set_db_connection (TRACKER_DBUS_KEYWORDS (object),
+ g_value_get_pointer (value));
+ break;
+
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
+ break;
+ };
+}
- dbus_message_unref (msg);
-
+TrackerDBusKeywords *
+tracker_dbus_keywords_new (DBConnection *db_con)
+{
+ TrackerDBusKeywords *object;
+ object = g_object_new (TRACKER_TYPE_DBUS_KEYWORDS,
+ "db-connection", db_con,
+ NULL);
+
+ return object;
}
-
void
-tracker_dbus_signal_keywords_removed (const char *service, const char *uri, const char *keyword)
+tracker_dbus_keywords_set_db_connection (TrackerDBusKeywords *object,
+ DBConnection *db_con)
{
- DBusMessage *msg;
- dbus_uint32_t serial = 0;
+ TrackerDBusKeywordsPriv *priv;
- msg = dbus_message_new_signal (TRACKER_OBJECT,
- TRACKER_INTERFACE_KEYWORDS,
- TRACKER_SIGNAL_KEYWORD_REMOVED);
-
- if (!msg || !tracker->dbus_con) {
- return;
- }
+ g_return_if_fail (TRACKER_IS_DBUS_KEYWORDS (object));
+ g_return_if_fail (db_con != NULL);
- /*
-
- <signal name="KeywordRemoved">
- <arg type="s" name="service"/>
- <arg type="s" name="uri" />
- <arg type="s" name="keyword" />
- </signal>
- */
-
- dbus_message_append_args (msg,
- DBUS_TYPE_STRING, &service,
- DBUS_TYPE_STRING, &uri,
- DBUS_TYPE_STRING, &keyword,
- DBUS_TYPE_INVALID);
-
- dbus_message_set_no_reply (msg, TRUE);
-
- if (!dbus_connection_send (tracker->dbus_con, msg, &serial)) {
- tracker_error ("Raising the keyword removed signal failed");
- return;
- }
-
- dbus_connection_flush (tracker->dbus_con);
-
- dbus_message_unref (msg);
-
+ priv = GET_PRIV (object);
+ priv->db_con = db_con;
+
+ g_object_notify (G_OBJECT (object), "db-connection");
}
-
-
-void
-tracker_dbus_method_keywords_get_list (DBusRec *rec)
+/*
+ * Functions
+ */
+gboolean
+tracker_dbus_keywords_get_list (TrackerDBusKeywords *object,
+ const gchar *service,
+ GPtrArray **values,
+ GError **error)
{
- TrackerDBResultSet *result_set;
- DBConnection *db_con;
- DBusError dbus_error;
- char *service;
+ TrackerDBusKeywordsPriv *priv;
+ TrackerDBResultSet *result_set;
+ guint request_id;
+ DBConnection *db_con;
- g_return_if_fail (rec && rec->user_data);
+ request_id = tracker_dbus_get_next_request_id ();
- db_con = rec->user_data;
+ tracker_dbus_return_val_if_fail (service != NULL, FALSE, error);
+ tracker_dbus_return_val_if_fail (values != NULL, FALSE, error);
-/*
- <!-- gets a list of all unique keywords/tags that are in use by the specified service irrespective of the uri or id of the entity
- Returns an array of string arrays with the keyword and the total usage count of the keyword as the string array
- -->
- <method name="GetList">
- <arg type="s" name="service" direction="in" />
- <arg type="aas" name="value" direction="out" />
- </method>
-
-*/
-
- dbus_error_init(&dbus_error);
- if (!dbus_message_get_args (rec->message, NULL,
- DBUS_TYPE_STRING, &service,
- DBUS_TYPE_INVALID)) {
- tracker_set_error (rec, "DBusError: %s;%s", dbus_error.name, dbus_error.message);
- dbus_error_free (&dbus_error);
- return;
- }
+ priv = GET_PRIV (object);
+
+ db_con = priv->db_con;
+
+ tracker_dbus_request_new (request_id,
+ "DBus request to get keywords list, "
+ "service:'%s'",
+ service);
if (!tracker_service_manager_is_valid_service (service)) {
- tracker_set_error (rec, "Invalid service %s or service has not been implemented yet", service);
- return;
+ tracker_dbus_request_failed (request_id,
+ error,
+ "Service '%s' is invalid or has not been implemented yet",
+ service);
+ return FALSE;
}
+ /* Check we have the right database connection */
db_con = tracker_db_get_service_connection (db_con, service);
result_set = tracker_db_get_keyword_list (db_con, service);
+ *values = tracker_dbus_query_result_to_ptr_array (result_set);
- tracker_dbus_reply_with_query_result (rec, result_set);
+ if (result_set) {
+ g_object_unref (result_set);
+ }
- g_object_unref (result_set);
-}
+ tracker_dbus_request_success (request_id);
+ return TRUE;
+}
-void
-tracker_dbus_method_keywords_get (DBusRec *rec)
+gboolean
+tracker_dbus_keywords_get (TrackerDBusKeywords *object,
+ const gchar *service,
+ const gchar *uri,
+ gchar ***values,
+ GError **error)
{
- TrackerDBResultSet *result_set;
- DBConnection *db_con;
- DBusError dbus_error;
- DBusMessage *reply;
- char *id, *uri, *service;
- char **array;
- int row_count;
+ TrackerDBusKeywordsPriv *priv;
+ TrackerDBResultSet *result_set;
+ DBConnection *db_con;
+ guint request_id;
+ gchar *id;
- g_return_if_fail (rec && rec->user_data);
+ request_id = tracker_dbus_get_next_request_id ();
- db_con = rec->user_data;
+ tracker_dbus_return_val_if_fail (service != NULL, FALSE, error);
+ tracker_dbus_return_val_if_fail (values != NULL, FALSE, error);
-/*
- <!-- gets all unique keywords/tags for specified service and id -->
- <method name="Get">
- <arg type="s" name="service" direction="in" />
- <arg type="s" name="id" direction="in" />
- <arg type="as" name="value" direction="out" />
- </method>
-*/
-
- dbus_error_init(&dbus_error);
- if (!dbus_message_get_args (rec->message, NULL,
- DBUS_TYPE_STRING, &service,
- DBUS_TYPE_STRING, &uri,
- DBUS_TYPE_INVALID)) {
- tracker_set_error (rec, "DBusError: %s;%s", dbus_error.name, dbus_error.message);
- dbus_error_free (&dbus_error);
- return;
- }
+ priv = GET_PRIV (object);
+
+ db_con = priv->db_con;
+
+ tracker_dbus_request_new (request_id,
+ "DBus request to get keywords, "
+ "service:'%s', uri:'%s'",
+ service,
+ uri);
if (!tracker_service_manager_is_valid_service (service)) {
- tracker_set_error (rec, "Invalid service %s or service has not been implemented yet", service);
- return;
+ tracker_dbus_request_failed (request_id,
+ error,
+ "Service '%s' is invalid or has not been implemented yet",
+ service);
+ return FALSE;
}
- if (tracker_is_empty_string (uri)) {
- tracker_set_error (rec, "Uri is invalid");
- return;
- }
+ if (tracker_is_empty_string (uri)) {
+ tracker_dbus_request_failed (request_id,
+ error,
+ "URI is empty");
+ return FALSE;
+ }
- db_con = tracker_db_get_service_connection (db_con, service);
+ /* Check we have the right database connection */
+ db_con = tracker_db_get_service_connection (db_con, service);
id = tracker_db_get_id (db_con, service, uri);
-
if (!id) {
- tracker_set_error (rec, "[keywords_get] Entity %s not found in database", uri);
- return;
+ tracker_dbus_request_failed (request_id,
+ error,
+ "Entity '%s' was not found",
+ uri);
+ return FALSE;
}
-
-
- result_set = tracker_db_get_metadata (db_con, service, id, "User:Keywords");
-
- g_free (id);
-
- row_count = 0;
- array = NULL;
+ result_set = tracker_db_get_metadata (db_con,
+ service,
+ id,
+ "User:Keywords");
+ *values = tracker_dbus_query_result_to_strv (result_set, NULL);
if (result_set) {
- array = tracker_get_query_result_as_array (result_set, &row_count);
g_object_unref (result_set);
}
- reply = dbus_message_new_method_return (rec->message);
-
- dbus_message_append_args (reply,
- DBUS_TYPE_ARRAY, DBUS_TYPE_STRING, &array, row_count,
- DBUS_TYPE_INVALID);
+ g_free (id);
- tracker_free_array (array, row_count);
+ tracker_dbus_request_success (request_id);
- dbus_connection_send (rec->connection, reply, NULL);
- dbus_message_unref (reply);
+ return TRUE;
}
-
-void
-tracker_dbus_method_keywords_add (DBusRec *rec)
+gboolean
+tracker_dbus_keywords_add (TrackerDBusKeywords *object,
+ const gchar *service,
+ const gchar *uri,
+ gchar **values,
+ GError **error)
{
- DBConnection *db_con;
- DBusError dbus_error;
- DBusMessage *reply;
- char *id, *uri, *service;
- char **array = NULL;
- int row_count = 0;
+ TrackerDBusKeywordsPriv *priv;
+ DBConnection *db_con;
+ guint request_id;
+ gchar *id;
+ gchar **p;
- g_return_if_fail (rec && rec->user_data);
+ request_id = tracker_dbus_get_next_request_id ();
- db_con = rec->user_data;
+ tracker_dbus_return_val_if_fail (service != NULL, FALSE, error);
+ tracker_dbus_return_val_if_fail (uri != NULL, FALSE, error);
+ tracker_dbus_return_val_if_fail (values != NULL, FALSE, error);
-/*
- <!-- Adds new keywords/tags for specified service and id -->
- <method name="Add">
- <arg type="s" name="service" direction="in" />
- <arg type="s" name="id" direction="in" />
- <arg type="as" name="values" direction="in" />
- </method>
-*/
-
- dbus_error_init (&dbus_error);
-
- if (!dbus_message_get_args (rec->message, NULL,
- DBUS_TYPE_STRING, &service,
- DBUS_TYPE_STRING, &uri,
- DBUS_TYPE_ARRAY, DBUS_TYPE_STRING, &array, &row_count,
- DBUS_TYPE_INVALID)) {
- tracker_set_error (rec, "DBusError: %s;%s", dbus_error.name, dbus_error.message);
- dbus_error_free (&dbus_error);
- return;
- }
+ priv = GET_PRIV (object);
+
+ db_con = priv->db_con;
+
+ tracker_dbus_request_new (request_id,
+ "DBus request to add keywords, "
+ "service:'%s', uri:'%s'",
+ service,
+ uri);
if (!tracker_service_manager_is_valid_service (service)) {
- tracker_set_error (rec, "Invalid service %s or service has not been implemented yet", service);
- return;
+ tracker_dbus_request_failed (request_id,
+ error,
+ "Service '%s' is invalid or has not been implemented yet",
+ service);
+ return FALSE;
}
- if (tracker_is_empty_string (uri)) {
- tracker_set_error (rec, "URI is invalid");
- return;
- }
+ if (tracker_is_empty_string (uri)) {
+ tracker_dbus_request_failed (request_id,
+ error,
+ "URI is empty");
+ return FALSE;
+ }
+ /* Check we have the right database connection */
db_con = tracker_db_get_service_connection (db_con, service);
+
id = tracker_db_get_id (db_con, service, uri);
+ tracker_dbus_return_val_if_fail (id != NULL, FALSE, error);
- if (!id) {
- tracker_set_error (rec, "Entity %s not found in database", uri);
- return;
- }
+ tracker_db_set_metadata (db_con,
+ service,
+ id,
+ "User:Keywords",
+ values,
+ g_strv_length (values),
+ TRUE);
+ g_free (id);
-
- if (array && (row_count > 0)) {
- tracker_db_set_metadata (db_con, service, id, "User:Keywords", array, row_count, TRUE);
- tracker_notify_file_data_available ();
+ tracker_notify_file_data_available ();
- int i;
- for (i=0; i<row_count; i++) {
- tracker_dbus_signal_keywords_added (service, uri, array[i]);
- tracker_log ("adding keyword %s to %s", array[i], uri);
- }
+ for (p = values; *p; p++) {
+ tracker_log ("Added keyword %s to %s with ID %s", *p, uri, id);
+ g_signal_emit (object, signals[KEYWORD_ADDED], 0, service, uri, *p);
}
- dbus_free_string_array (array);
-
- g_free (id);
-
- reply = dbus_message_new_method_return (rec->message);
-
- dbus_connection_send (rec->connection, reply, NULL);
+ tracker_dbus_request_success (request_id);
- dbus_message_unref (reply);
+ return TRUE;
}
-
-void
-tracker_dbus_method_keywords_remove (DBusRec *rec)
+gboolean
+tracker_dbus_keywords_remove (TrackerDBusKeywords *object,
+ const gchar *service,
+ const gchar *uri,
+ gchar **values,
+ GError **error)
{
- DBConnection *db_con;
- DBusError dbus_error;
- DBusMessage *reply;
- char *id, *uri, *service;
- char **array;
- int row_count = 0;
+ TrackerDBusKeywordsPriv *priv;
+ DBConnection *db_con;
+ guint request_id;
+ gchar *id;
+ gchar **p;
- g_return_if_fail (rec && rec->user_data);
+ request_id = tracker_dbus_get_next_request_id ();
- db_con = rec->user_data;
+ tracker_dbus_return_val_if_fail (service != NULL, FALSE, error);
+ tracker_dbus_return_val_if_fail (uri != NULL, FALSE, error);
+ tracker_dbus_return_val_if_fail (values != NULL, FALSE, error);
- array = NULL;
+ priv = GET_PRIV (object);
-/*
- <!-- removes all specified keywords/tags for specified service and id -->
- <method name="Remove">
- <arg type="s" name="service" direction="in" />
- <arg type="s" name="id" direction="in" />
- <arg type="as" name="keywords" direction="in" />
- </method>
-*/
-
- dbus_error_init(&dbus_error);
- if (!dbus_message_get_args (rec->message, NULL,
- DBUS_TYPE_STRING, &service,
- DBUS_TYPE_STRING, &uri,
- DBUS_TYPE_ARRAY, DBUS_TYPE_STRING, &array, &row_count,
- DBUS_TYPE_INVALID)) {
- tracker_set_error (rec, "DBusError: %s;%s", dbus_error.name, dbus_error.message);
- dbus_error_free (&dbus_error);
- return;
- }
+ db_con = priv->db_con;
+
+ tracker_dbus_request_new (request_id,
+ "DBus request to remove keywords, "
+ "service:'%s', uri:'%s'",
+ service,
+ uri);
if (!tracker_service_manager_is_valid_service (service)) {
- tracker_set_error (rec, "Invalid service %s or service has not been implemented yet", service);
- return;
+ tracker_dbus_request_failed (request_id,
+ error,
+ "Service '%s' is invalid or has not been implemented yet",
+ service);
+ return FALSE;
}
- if (tracker_is_empty_string (uri)) {
- tracker_set_error (rec, "ID is invalid");
- return;
- }
+ if (tracker_is_empty_string (uri)) {
+ tracker_dbus_request_failed (request_id,
+ error,
+ "URI is empty");
+ return FALSE;
+ }
+ /* Check we have the right database connection */
db_con = tracker_db_get_service_connection (db_con, service);
id = tracker_db_get_id (db_con, service, uri);
-
if (!id) {
- tracker_set_error (rec, "Entity %s not found in database", uri);
- return;
+ tracker_dbus_request_failed (request_id,
+ error,
+ "Entity '%s' was not found",
+ uri);
+ return FALSE;
}
- if (array && (row_count > 0)) {
- int i;
+ tracker_notify_file_data_available ();
- for (i = 0; i < row_count; i++) {
- if (array[i]) {
- tracker_log ("deleting keyword %s from %s with ID %s", array[i], uri, id);
- tracker_db_delete_metadata_value (db_con, service, id, "User:Keywords", array[i]);
- tracker_notify_file_data_available ();
- tracker_dbus_signal_keywords_removed (service, uri, array[i]);
- }
- }
- }
+ for (p = values; *p; p++) {
+ tracker_log ("Removed keyword %s from %s with ID %s", *p, uri, id);
+ tracker_db_delete_metadata_value (db_con, service, id, "User:Keywords", *p);
- dbus_free_string_array (array);
+ /* FIXME: Should we be doing this for EACH keyword? */
+ tracker_notify_file_data_available ();
- g_free (id);
+ g_signal_emit (object, signals[KEYWORD_REMOVED], 0, service, uri, *p);
+ }
- reply = dbus_message_new_method_return (rec->message);
+ g_free (id);
- dbus_connection_send (rec->connection, reply, NULL);
+ tracker_dbus_request_success (request_id);
- dbus_message_unref (reply);
+ return TRUE;
}
-
-void
-tracker_dbus_method_keywords_remove_all (DBusRec *rec)
+gboolean
+tracker_dbus_keywords_remove_all (TrackerDBusKeywords *object,
+ const gchar *service,
+ const gchar *uri,
+ GError **error)
{
- DBConnection *db_con;
- DBusError dbus_error;
- DBusMessage *reply;
- char *id, *uri, *service;
+ TrackerDBusKeywordsPriv *priv;
+ DBConnection *db_con;
+ guint request_id;
+ gchar *id;
- g_return_if_fail (rec && rec->user_data);
+ request_id = tracker_dbus_get_next_request_id ();
- db_con = rec->user_data;
+ tracker_dbus_return_val_if_fail (service != NULL, FALSE, error);
+ tracker_dbus_return_val_if_fail (uri != NULL, FALSE, error);
-/*
+ priv = GET_PRIV (object);
- <!-- removes all keywords/tags for specified service and id -->
- <method name="RemoveAll">
- <arg type="s" name="service" direction="in" />
- <arg type="s" name="id" direction="in" />
- </method>
-*/
-
- dbus_error_init(&dbus_error);
- if (!dbus_message_get_args (rec->message, NULL,
- DBUS_TYPE_STRING, &service,
- DBUS_TYPE_STRING, &uri,
- DBUS_TYPE_INVALID)) {
- tracker_set_error (rec, "DBusError: %s;%s", dbus_error.name, dbus_error.message);
- dbus_error_free (&dbus_error);
- return;
- }
+ db_con = priv->db_con;
+
+ tracker_dbus_request_new (request_id,
+ "DBus request to remove all keywords, "
+ "service:'%s', uri:'%s'",
+ service,
+ uri);
if (!tracker_service_manager_is_valid_service (service)) {
- tracker_set_error (rec, "Invalid service %s or service has not been implemented yet", service);
- return;
+ tracker_dbus_request_failed (request_id,
+ error,
+ "Service '%s' is invalid or has not been implemented yet",
+ service);
+ return FALSE;
}
- if (tracker_is_empty_string (uri)) {
- tracker_set_error (rec, "URI is invalid");
- return;
- }
+ if (tracker_is_empty_string (uri)) {
+ tracker_dbus_request_failed (request_id,
+ error,
+ "URI is empty");
+ return FALSE;
+ }
+ /* Check we have the right database connection */
db_con = tracker_db_get_service_connection (db_con, service);
- id = tracker_db_get_id (db_con, service, uri);
+ id = tracker_db_get_id (db_con, service, uri);
if (!id) {
- tracker_set_error (rec, "Entity %s not found in database", uri);
- return;
+ tracker_dbus_request_failed (request_id,
+ error,
+ "Entity '%s' was not found",
+ uri);
+ return FALSE;
}
tracker_db_delete_metadata (db_con, service, id, "User:Keywords", TRUE);
- tracker_notify_file_data_available ();
-
g_free (id);
-
- reply = dbus_message_new_method_return (rec->message);
- dbus_connection_send (rec->connection, reply, NULL);
+ tracker_notify_file_data_available ();
- dbus_message_unref (reply);
-}
+ tracker_dbus_request_success (request_id);
+ return TRUE;
+}
-void
-tracker_dbus_method_keywords_search (DBusRec *rec)
+gboolean
+tracker_dbus_keywords_search (TrackerDBusKeywords *object,
+ gint live_query_id,
+ const gchar *service,
+ const gchar **keywords,
+ gint offset,
+ gint max_hits,
+ gchar ***values,
+ GError **error)
{
- TrackerDBResultSet *result_set;
- DBConnection *db_con;
- DBusError dbus_error;
- DBusMessage *reply;
- char *service;
- char **array;
- int row_count, limit, query_id, offset;
- GString *str_words, *str_select, *str_where;
- char *query_sel, *query_where, *query;
- int i;
-
- g_return_if_fail (rec && rec->user_data);
-
- db_con = rec->user_data;
-
-/*
- <!-- searches specified service for matching keyword/tag and returns an array of matching id values for the service-->
- <method name="Search">
- <arg type="i" name="live_query_id" direction="in" />
- <arg type="s" name="service" direction="in" />
- <arg type="as" name="keywords" direction="in" />
- <arg type="i" name="max_hits" direction="in" />
- <arg type="as" name="result" direction="out" />
- </method>
-*/
-
- dbus_error_init(&dbus_error);
- if (!dbus_message_get_args (rec->message, NULL,
- DBUS_TYPE_INT32, &query_id,
- DBUS_TYPE_STRING, &service,
- DBUS_TYPE_ARRAY, DBUS_TYPE_STRING, &array, &row_count,
- DBUS_TYPE_INT32, &offset,
- DBUS_TYPE_INT32, &limit,
- DBUS_TYPE_INVALID)) {
- tracker_set_error (rec, "DBusError: %s;%s", dbus_error.name, dbus_error.message);
- dbus_error_free (&dbus_error);
- return;
- }
+ TrackerDBusKeywordsPriv *priv;
+ TrackerDBResultSet *result_set;
+ DBConnection *db_con;
+ guint request_id;
+ const gchar **p;
+ GString *search;
+ GString *select;
+ GString *where;
+ gchar *related_metadata;
+ gchar *query;
+
+ request_id = tracker_dbus_get_next_request_id ();
+
+ tracker_dbus_return_val_if_fail (service != NULL, FALSE, error);
+ tracker_dbus_return_val_if_fail (keywords != NULL, FALSE, error);
+ tracker_dbus_return_val_if_fail (values != NULL, FALSE, error);
+
+ priv = GET_PRIV (object);
+
+ db_con = priv->db_con;
+
+ tracker_dbus_request_new (request_id,
+ "DBus request to search keywords, "
+ "query id:%d, service:'%s', offset:%d, "
+ "max hits:%d",
+ live_query_id,
+ service,
+ offset,
+ max_hits);
if (!tracker_service_manager_is_valid_service (service)) {
- tracker_set_error (rec, "Invalid service %s or service has not been implemented yet", service);
- return;
- }
-
- if (offset < 0) {
- offset = 0;
- }
-
- if (row_count < 1) {
-
- tracker_set_error (rec, "No keywords supplied");
- return;
+ tracker_dbus_request_failed (request_id,
+ error,
+ "Service '%s' is invalid or has not been implemented yet",
+ service);
+ return FALSE;
}
+ /* Check we have the right database connection */
db_con = tracker_db_get_service_connection (db_con, service);
- str_words = g_string_new ("");
- g_string_append_printf (str_words, "'%s'", array[0]);
-
- for (i = 1; i < row_count; i++) {
- g_string_append_printf (str_words, ", '%s'", array[i]);
- }
-
- tracker_log ("executing keyword search on %s", str_words->str);
-
- str_select = g_string_new (" Select distinct S.Path || '");
-
- str_select = g_string_append (str_select, G_DIR_SEPARATOR_S);
-
- str_select = g_string_append (str_select, "' || S.Name as EntityName from Services S, ServiceKeywordMetaData M ");
-
- char *related_metadata = tracker_get_related_metadata_names (db_con, "User:Keywords");
-
- str_where = g_string_new ("");
-
- g_string_append_printf (str_where, " where S.ID = M.ServiceID and M.MetaDataID in (%s) and M.MetaDataValue in (%s) ", related_metadata, str_words->str);
-
- g_free (related_metadata);
-
- g_string_free (str_words, TRUE);
-
- gint smin, smax;
- char *str_min, *str_max;
+ /* Sanity check values */
+ offset = MAX (offset, 0);
- smin = tracker_service_manager_get_id_for_service (service);
-
- if (smin == 0) {
- smax = 8;
- } else {
- smax = smin;
- }
-
- str_min = tracker_int_to_str (smin);
- str_max = tracker_int_to_str (smax);
-
-
- g_string_append_printf (str_where, " and (S.ServiceTypeID in (select TypeId from ServiceTypes where TypeName = '%s' or Parent = '%s')) ", service, service);
-
-
- g_free (str_min);
- g_free (str_max);
-
- g_string_append_printf (str_where, " Limit %d,%d", offset, limit);
+ /* Create keyword search string */
+ search = g_string_new ("");
+ g_string_append_printf (search,
+ "'%s'",
+ keywords[0]);
+
+ for (p = keywords + 1; *p; p++) {
+ g_string_append_printf (search, ", '%s'", *p);
+ }
+
+ tracker_dbus_request_comment (request_id,
+ "Executing keyword search on %s",
+ search->str);
+
+ /* Create select string */
+ select = g_string_new (" Select distinct S.Path || '");
+ select = g_string_append (select, G_DIR_SEPARATOR_S);
+ select = g_string_append (select,
+ "' || S.Name as EntityName from Services S, ServiceKeywordMetaData M ");
+
+ /* Create where string */
+ related_metadata = tracker_get_related_metadata_names (db_con, "User:Keywords");
+
+ where = g_string_new ("");
+ g_string_append_printf (where,
+ " where S.ID = M.ServiceID and M.MetaDataID in (%s) and M.MetaDataValue in (%s) ",
+ related_metadata,
+ search->str);
+ g_free (related_metadata);
+ g_string_free (search, TRUE);
+ g_string_append_printf (where,
+ " and (S.ServiceTypeID in (select TypeId from ServiceTypes where TypeName = '%s' or Parent = '%s')) ",
+ service,
+ service);
+
+ /* Add offset and max_hits */
+ g_string_append_printf (where,
+ " Limit %d,%d",
+ offset,
+ max_hits);
+
+ /* Finalize query */
+ query = g_strconcat (select->str, where->str, NULL);
+ g_string_free (select, TRUE);
+ g_string_free (where, TRUE);
- query_sel = g_string_free (str_select, FALSE);
- query_where = g_string_free (str_where, FALSE);
- query = g_strconcat (query_sel, query_where, NULL);
+ tracker_debug (query);
- tracker_log (query);
result_set = tracker_db_interface_execute_query (db_con->db, query);
+ *values = tracker_dbus_query_result_to_strv (result_set, NULL);
- g_free (query_sel);
- g_free (query_where);
- g_free (query);
-
- dbus_free_string_array (array);
- row_count = 0;
- array = NULL;
-
if (result_set) {
- array = tracker_get_query_result_as_array (result_set, &row_count);
g_object_unref (result_set);
}
- reply = dbus_message_new_method_return (rec->message);
-
- dbus_message_append_args (reply,
- DBUS_TYPE_ARRAY, DBUS_TYPE_STRING, &array, row_count,
- DBUS_TYPE_INVALID);
+ g_free (query);
- tracker_free_array (array, row_count);
+ tracker_dbus_request_success (request_id);
- dbus_connection_send (rec->connection, reply, NULL);
- dbus_message_unref (reply);
+ return TRUE;
}
Modified: branches/indexer-split/src/trackerd/tracker-dbus-keywords.h
==============================================================================
--- branches/indexer-split/src/trackerd/tracker-dbus-keywords.h (original)
+++ branches/indexer-split/src/trackerd/tracker-dbus-keywords.h Mon Apr 21 11:21:20 2008
@@ -1,5 +1,7 @@
-/* Tracker - indexer and metadata database engine
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
+/*
* Copyright (C) 2006, Mr Jamie McCracken (jamiemcc gnome org)
+ * Copyright (C) 2008, Nokia
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public
@@ -17,18 +19,77 @@
* Boston, MA 02110-1301, USA.
*/
+#ifndef __TRACKER_DBUS_KEYWORDS_H__
+#define __TRACKER_DBUS_KEYWORDS_H__
+#include <dbus/dbus-glib.h>
+#include <dbus/dbus-glib-bindings.h>
+#include <dbus/dbus-glib-lowlevel.h>
+
+#include "tracker-db-sqlite.h"
+
+#define TRACKER_DBUS_KEYWORDS_SERVICE "org.freedesktop.Tracker"
+#define TRACKER_DBUS_KEYWORDS_PATH "/org/freedesktop/Tracker/Keywords"
+#define TRACKER_DBUS_KEYWORDS_INTERFACE "org.freedesktop.Tracker.Keywords"
+
+G_BEGIN_DECLS
+
+#define TRACKER_TYPE_DBUS_KEYWORDS (tracker_dbus_keywords_get_type ())
+#define TRACKER_DBUS_KEYWORDS(object) (G_TYPE_CHECK_INSTANCE_CAST ((object), TRACKER_TYPE_DBUS_KEYWORDS, TrackerDBusKeywords))
+#define TRACKER_DBUS_KEYWORDS_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), TRACKER_TYPE_DBUS_KEYWORDS, TrackerDBusKeywordsClass))
+#define TRACKER_IS_DBUS_KEYWORDS(object) (G_TYPE_CHECK_INSTANCE_TYPE ((object), TRACKER_TYPE_DBUS_KEYWORDS))
+#define TRACKER_IS_DBUS_KEYWORDS_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), TRACKER_TYPE_DBUS_KEYWORDS))
+#define TRACKER_DBUS_KEYWORDS_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), TRACKER_TYPE_DBUS_KEYWORDS, TrackerDBusKeywordsClass))
+
+typedef struct TrackerDBusKeywords TrackerDBusKeywords;
+typedef struct TrackerDBusKeywordsClass TrackerDBusKeywordsClass;
+
+struct TrackerDBusKeywords {
+ GObject parent;
+};
+
+struct TrackerDBusKeywordsClass {
+ GObjectClass parent;
+};
+
+GType tracker_dbus_keywords_get_type (void);
+
+TrackerDBusKeywords *
+ tracker_dbus_keywords_new (DBConnection *db_con);
+void tracker_dbus_keywords_set_db_connection (TrackerDBusKeywords *object,
+ DBConnection *db_con);
+gboolean tracker_dbus_keywords_get_list (TrackerDBusKeywords *object,
+ const gchar *service,
+ GPtrArray **values,
+ GError **error);
+gboolean tracker_dbus_keywords_get (TrackerDBusKeywords *object,
+ const gchar *service,
+ const gchar *uri,
+ gchar ***values,
+ GError **error);
+gboolean tracker_dbus_keywords_add (TrackerDBusKeywords *object,
+ const gchar *service,
+ const gchar *uri,
+ gchar **values,
+ GError **error);
+gboolean tracker_dbus_keywords_remove (TrackerDBusKeywords *object,
+ const gchar *service,
+ const gchar *uri,
+ gchar **values,
+ GError **error);
+gboolean tracker_dbus_keywords_remove_all (TrackerDBusKeywords *object,
+ const gchar *service,
+ const gchar *uri,
+ GError **error);
+gboolean tracker_dbus_keywords_search (TrackerDBusKeywords *object,
+ gint live_query_id,
+ const gchar *service,
+ const gchar **keywords,
+ gint offset,
+ gint max_hits,
+ gchar ***result,
+ GError **error);
-#ifndef _TRACKER_DBUS_KEYWORDS_H_
-#define _TRACKER_DBUS_KEYWORDS_H_
+G_END_DECLS
-#include "tracker-dbus.h"
-
-void tracker_dbus_method_keywords_get_list (DBusRec *rec);
-void tracker_dbus_method_keywords_get (DBusRec *rec);
-void tracker_dbus_method_keywords_add (DBusRec *rec);
-void tracker_dbus_method_keywords_remove (DBusRec *rec);
-void tracker_dbus_method_keywords_remove_all (DBusRec *rec);
-void tracker_dbus_method_keywords_search (DBusRec *rec);
-
-#endif
+#endif /* __TRACKER_DBUS_KEYWORDS_H__ */
Modified: branches/indexer-split/src/trackerd/tracker-dbus-metadata.c
==============================================================================
--- branches/indexer-split/src/trackerd/tracker-dbus-metadata.c (original)
+++ branches/indexer-split/src/trackerd/tracker-dbus-metadata.c Mon Apr 21 11:21:20 2008
@@ -1,5 +1,7 @@
-/* Tracker - indexer and metadata database engine
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
+/*
* Copyright (C) 2006, Mr Jamie McCracken (jamiemcc gnome org)
+ * Copyright (C) 2008, Nokia
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public
@@ -17,554 +19,593 @@
* Boston, MA 02110-1301, USA.
*/
+#include <config.h>
+
#include <stdlib.h>
#include <string.h>
#include <libtracker-common/tracker-log.h>
+#include <libtracker-common/tracker-utils.h>
-#include "tracker-dbus-methods.h"
+#include "tracker-dbus.h"
#include "tracker-dbus-metadata.h"
+#include "tracker-db.h"
+#include "tracker-marshal.h"
-void
-tracker_dbus_method_metadata_set (DBusRec *rec)
-{
- DBConnection *db_con;
- DBusError dbus_error;
- DBusMessage *reply;
- int i, key_count, value_count;
- char *uri, *service, *id;
- char **keys, **values;
- gboolean is_local_file;
-
- g_return_if_fail (rec && rec->user_data);
+#define GET_PRIV(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), TRACKER_TYPE_DBUS_METADATA, TrackerDBusMetadataPriv))
- db_con = rec->user_data;
+typedef struct {
+ DBConnection *db_con;
+} TrackerDBusMetadataPriv;
-/*
- <method name="Set">
- <arg type="s" name="service" direction="in" />
- <arg type="s" name="id" direction="in" />
- <arg type="as" name="keys" direction="in" />
- <arg type="as" name="values" direction="in" />
- </method>
-*/
-
- dbus_error_init (&dbus_error);
- if (!dbus_message_get_args (rec->message, NULL,
- DBUS_TYPE_STRING, &service,
- DBUS_TYPE_STRING, &uri,
- DBUS_TYPE_ARRAY, DBUS_TYPE_STRING, &keys, &key_count,
- DBUS_TYPE_ARRAY, DBUS_TYPE_STRING, &values, &value_count,
- DBUS_TYPE_INVALID)) {
- tracker_set_error (rec, "DBusError: %s;%s", dbus_error.name, dbus_error.message);
- dbus_error_free (&dbus_error);
- return;
- }
+enum {
+ PROP_0,
+ PROP_DB_CONNECTION
+};
+
+static void dbus_metadata_finalize (GObject *object);
+static void dbus_metadata_set_property (GObject *object,
+ guint param_id,
+ const GValue *value,
+ GParamSpec *pspec);
+
+static const gchar *types[] = {
+ "index",
+ "string",
+ "numeric",
+ "date",
+ NULL
+};
- if (!tracker_service_manager_is_valid_service (service)) {
- tracker_set_error (rec, "Invalid service %s or service has not been implemented yet", service);
- return;
- }
+G_DEFINE_TYPE(TrackerDBusMetadata, tracker_dbus_metadata, G_TYPE_OBJECT)
- db_con = tracker_db_get_service_connection (db_con, service);
+static void
+tracker_dbus_metadata_class_init (TrackerDBusMetadataClass *klass)
+{
+ GObjectClass *object_class;
- if (tracker_is_empty_string (uri)) {
- tracker_set_error (rec, "ID is invalid");
- return;
- }
+ object_class = G_OBJECT_CLASS (klass);
- if (key_count == 0 || value_count == 0) {
- tracker_set_error (rec, "No metadata types or metadata values specified");
- return;
- }
+ object_class->finalize = dbus_metadata_finalize;
+ object_class->set_property = dbus_metadata_set_property;
- if (key_count != value_count ) {
- tracker_set_error (rec, "The number of specified keys does not match the supplied values");
- return;
- }
+ g_object_class_install_property (object_class,
+ PROP_DB_CONNECTION,
+ g_param_spec_pointer ("db-connection",
+ "DB connection",
+ "Database connection to use in transactions",
+ G_PARAM_WRITABLE));
- id = tracker_db_get_id (db_con, service, uri);
+ g_type_class_add_private (object_class, sizeof (TrackerDBusMetadataPriv));
+}
- if (!id) {
- tracker_set_error (rec, "Entity with ID %s not found in database", uri);
- return;
- }
+static void
+tracker_dbus_metadata_init (TrackerDBusMetadata *object)
+{
+}
+static void
+dbus_metadata_finalize (GObject *object)
+{
+ TrackerDBusMetadataPriv *priv;
+ priv = GET_PRIV (object);
- is_local_file = (uri[0] == G_DIR_SEPARATOR);
-
- for (i = 0; i < key_count; i++) {
- char *meta, *value;
-
- meta = keys[i];
- value = values[i];
-
- if (!meta || strlen (meta) < 3 || (strchr (meta, ':') == NULL) ) {
- tracker_set_error (rec, "Metadata type name %s is invalid. All names must be registered in tracker", meta);
- g_free (id);
- return;
- }
-
- tracker_db_set_single_metadata (db_con, service, id, meta, value, TRUE);
- tracker_notify_file_data_available ();
- }
-
- g_free (id);
- dbus_free_string_array (keys);
- dbus_free_string_array (values);
+ G_OBJECT_CLASS (tracker_dbus_metadata_parent_class)->finalize (object);
+}
- reply = dbus_message_new_method_return (rec->message);
+static void
+dbus_metadata_set_property (GObject *object,
+ guint param_id,
+ const GValue *value,
+ GParamSpec *pspec)
+{
+ TrackerDBusMetadataPriv *priv;
- dbus_connection_send (rec->connection, reply, NULL);
+ priv = GET_PRIV (object);
- dbus_message_unref (reply);
+ switch (param_id) {
+ case PROP_DB_CONNECTION:
+ tracker_dbus_metadata_set_db_connection (TRACKER_DBUS_METADATA (object),
+ g_value_get_pointer (value));
+ break;
+
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
+ break;
+ };
}
+TrackerDBusMetadata *
+tracker_dbus_metadata_new (DBConnection *db_con)
+{
+ TrackerDBusMetadata *object;
+ object = g_object_new (TRACKER_TYPE_DBUS_METADATA,
+ "db-connection", db_con,
+ NULL);
+
+ return object;
+}
void
-tracker_dbus_method_metadata_get (DBusRec *rec)
+tracker_dbus_metadata_set_db_connection (TrackerDBusMetadata *object,
+ DBConnection *db_con)
{
- TrackerDBResultSet *result_set;
- DBConnection *db_con;
- DBusError dbus_error;
- DBusMessage *reply;
- int i, key_count, row_count;
- char **keys, **array;
- char *uri, *id, *str, *service, *res_service;
- GString *sql, *sql_join;
-
-
- g_return_if_fail (rec && rec->user_data);
-
- db_con = rec->user_data;
-
- /* <method name="Get">
- <arg type="s" name="service" direction="in" />
- <arg type="s" name="id" direction="in" />
- <arg type="as" name="keys" direction="in" />
- <arg type="as" name="values" direction="out" />
- </method>
- */
-
- dbus_error_init (&dbus_error);
- if (!dbus_message_get_args (rec->message, NULL,
- DBUS_TYPE_STRING, &service,
- DBUS_TYPE_STRING, &uri,
- DBUS_TYPE_ARRAY, DBUS_TYPE_STRING, &keys, &key_count,
- DBUS_TYPE_INVALID)) {
- tracker_set_error (rec, "DBusError: %s;%s", dbus_error.name, dbus_error.message);
- dbus_error_free (&dbus_error);
- return;
- }
+ TrackerDBusMetadataPriv *priv;
- if (!tracker_service_manager_is_valid_service (service)) {
- tracker_set_error (rec, "Invalid service %s or service has not been implemented yet", service);
- return;
- }
+ g_return_if_fail (TRACKER_IS_DBUS_METADATA (object));
+ g_return_if_fail (db_con != NULL);
- if (key_count == 0) {
- tracker_set_error (rec, "No Metadata was specified");
- return;
- }
+ priv = GET_PRIV (object);
+ priv->db_con = db_con;
+ g_object_notify (G_OBJECT (object), "db-connection");
+}
- db_con = tracker_db_get_service_connection (db_con, service);
+/*
+ * Functions
+ */
+gboolean
+tracker_dbus_metadata_get (TrackerDBusMetadata *object,
+ const gchar *service,
+ const gchar *id,
+ gchar **keys,
+ gchar ***values,
+ GError **error)
+{
+ TrackerDBusMetadataPriv *priv;
+ TrackerDBResultSet *result_set;
+ guint request_id;
+ DBConnection *db_con;
+ gchar *service_result;
+ gchar *service_id;
+ guint i;
+ GString *sql;
+ GString *sql_join;
+ gchar *query;
+
+ request_id = tracker_dbus_get_next_request_id ();
+
+ tracker_dbus_return_val_if_fail (service != NULL, FALSE, error);
+ tracker_dbus_return_val_if_fail (keys != NULL, FALSE, error);
+ tracker_dbus_return_val_if_fail (g_strv_length (keys) > 0, FALSE, error);
+ tracker_dbus_return_val_if_fail (values != NULL, FALSE, error);
+
+ priv = GET_PRIV (object);
- id = tracker_db_get_id (db_con, service, uri);
+ db_con = priv->db_con;
- if (!id) {
- tracker_set_error (rec, "Entity with ID %s and service %s was not found in database", uri, service);
- return;
+ if (!tracker_service_manager_is_valid_service (service)) {
+ tracker_dbus_request_failed (request_id,
+ error,
+ "Service '%s' is invalid or has not been implemented yet",
+ service);
+ return FALSE;
}
+ tracker_dbus_request_new (request_id,
+ "DBus request to get metadata values, "
+ "service:'%s'",
+ service);
- res_service = tracker_db_get_service_for_entity (db_con, id);
-
- if (!res_service) {
- tracker_set_error (rec, "Service info cannot be found for entity %s", uri);
- return;
+ /* Check we have the right database connection */
+ db_con = tracker_db_get_service_connection (db_con, service);
+
+ service_id = tracker_db_get_id (db_con, service, id);
+ if (!service_id) {
+ tracker_dbus_request_failed (request_id,
+ error,
+ "Service URI '%s' not found",
+ id);
+ return FALSE;
+ }
+
+ service_result = tracker_db_get_service_for_entity (db_con, service_id);
+ if (!service_result) {
+ g_free (service_id);
+ tracker_dbus_request_failed (request_id,
+ error,
+ "Service information can not be found for entity '%s'",
+ id);
+ return FALSE;
}
- /* build SELECT clause */
+ /* Build SQL select clause */
sql = g_string_new (" SELECT DISTINCT ");
+ sql_join = g_string_new (" FROM Services S ");
- sql_join = g_string_new (" FROM Services S ");
+ for (i = 0; i < g_strv_length (keys); i++) {
+ FieldData *field;
-
- for (i = 0; i < key_count; i++) {
-
- FieldData *field = tracker_db_get_metadata_field (db_con, res_service, keys[i], i, TRUE, FALSE);
+ field = tracker_db_get_metadata_field (db_con,
+ service_result,
+ keys[i],
+ i,
+ TRUE,
+ FALSE);
if (!field) {
- tracker_set_error (rec, "Invalid or non-existant metadata type %s was specified", keys[i]);
+ g_string_free (sql_join, TRUE);
g_string_free (sql, TRUE);
- return;
-
+ g_free (service_result);
+ g_free (service_id);
+
+ tracker_dbus_request_failed (request_id,
+ error,
+ "Invalid or non-existant metadata type '%s' specified",
+ keys[i]);
+ return FALSE;
}
- if (i==0) {
+ if (i == 0) {
g_string_append_printf (sql, " %s", field->select_field);
} else {
g_string_append_printf (sql, ", %s", field->select_field);
}
+
if (field->needs_join) {
- g_string_append_printf (sql_join, "\n LEFT OUTER JOIN %s %s ON (S.ID = %s.ServiceID and %s.MetaDataID = %s) ", field->table_name, field->alias, field->alias, field->alias, field->id_field);
+ g_string_append_printf (sql_join,
+ "\n LEFT OUTER JOIN %s %s ON (S.ID = %s.ServiceID and %s.MetaDataID = %s) ",
+ field->table_name,
+ field->alias,
+ field->alias,
+ field->alias,
+ field->id_field);
}
tracker_free_metadata_field (field);
}
g_string_append (sql, sql_join->str);
-
g_string_free (sql_join, TRUE);
+ g_free (service_result);
- dbus_free_string_array (keys);
- g_free (res_service);
+ /* Build SQL where clause */
+ g_string_append_printf (sql, " WHERE S.ID = %s", id);
+ g_free (service_id);
- /* build WHERE clause */
+ query = g_string_free (sql, FALSE);
- g_string_append_printf (sql, " WHERE S.ID = %s", id );
+ tracker_debug (query);
- str = g_string_free (sql, FALSE);
+ result_set = tracker_db_interface_execute_query (db_con->db, query);
+ *values = tracker_dbus_query_result_to_strv (result_set, NULL);
+ g_free (query);
- tracker_log (str);
+ if (result_set) {
+ g_object_unref (result_set);
+ }
- result_set = tracker_db_interface_execute_query (db_con->db, str);
+ if (!*values) {
+ tracker_dbus_request_failed (request_id,
+ error,
+ "No metadata information was available");
+ return FALSE;
+ }
- g_free (str);
- g_free (id);
+ tracker_dbus_request_success (request_id);
+ return TRUE;
+}
- reply = dbus_message_new_method_return (rec->message);
+gboolean
+tracker_dbus_metadata_set (TrackerDBusMetadata *object,
+ const gchar *service,
+ const gchar *id,
+ gchar **keys,
+ gchar **values,
+ GError **error)
+{
+ TrackerDBusMetadataPriv *priv;
+ guint request_id;
+ DBConnection *db_con;
+ gchar *service_id;
+ guint i;
+
+ request_id = tracker_dbus_get_next_request_id ();
+
+ tracker_dbus_return_val_if_fail (service != NULL, FALSE, error);
+ tracker_dbus_return_val_if_fail (keys != NULL, FALSE, error);
+ tracker_dbus_return_val_if_fail (values != NULL, FALSE, error);
+ tracker_dbus_return_val_if_fail (g_strv_length (keys) > 0, FALSE, error);
+ tracker_dbus_return_val_if_fail (g_strv_length (values) > 0, FALSE, error);
+ tracker_dbus_return_val_if_fail (g_strv_length (keys) != g_strv_length (values), FALSE, error);
- row_count = 0;
+ priv = GET_PRIV (object);
- if (result_set) {
- GValue transform = { 0, };
+ db_con = priv->db_con;
+
+ tracker_dbus_request_new (request_id,
+ "DBus request to set metadata keys, "
+ "service:'%s'",
+ service);
- row_count = key_count;
- array = g_new (char *, key_count);
+ if (!tracker_service_manager_is_valid_service (service)) {
+ tracker_dbus_request_failed (request_id,
+ error,
+ "Service '%s' is invalid or has not been implemented yet",
+ service);
+ return FALSE;
+ }
- g_value_init (&transform, G_TYPE_STRING);
+ /* Check we have the right database connection */
+ db_con = tracker_db_get_service_connection (db_con, service);
- for (i = 0; i < key_count; i++) {
- GValue value = { 0, };
+ service_id = tracker_db_get_id (db_con, service, id);
+ if (!service_id) {
+ tracker_dbus_request_failed (request_id,
+ error,
+ "Service URI '%s' not found",
+ id);
+ return FALSE;
+ }
+
+ for (i = 0; i < g_strv_length (keys); i++) {
+ const gchar *key;
+ const gchar *value;
- _tracker_db_result_set_get_value (result_set, i, &value);
+ key = keys[i];
+ value = values[i];
- if (g_value_transform (&value, &transform)) {
- array[i] = g_value_dup_string (&transform);
- } else {
- array[i] = g_strdup ("");
- }
+ if (!key || strlen (key) < 3 || strchr (key, ':') == NULL) {
+ g_free (service_id);
- g_value_unset (&value);
- g_value_reset (&transform);
+ tracker_dbus_request_failed (request_id,
+ error,
+ "Metadata type name '%s' is invalid, all names must be registered",
+ key);
+ return FALSE;
}
- g_object_unref (result_set);
- } else {
- row_count = 1;
- array = g_new (char *, 1);
- array[0] = g_strdup ("");
-
+ tracker_db_set_single_metadata (db_con,
+ service,
+ service_id,
+ key,
+ value,
+ TRUE);
+ tracker_notify_file_data_available ();
}
+
+ g_free (service_id);
- dbus_message_append_args (reply,
- DBUS_TYPE_ARRAY, DBUS_TYPE_STRING, &array, key_count,
- DBUS_TYPE_INVALID);
-
- tracker_free_array (array, row_count);
+ /* FIXME: Check return value? */
- dbus_connection_send (rec->connection, reply, NULL);
+ tracker_dbus_request_success (request_id);
- dbus_message_unref (reply);
+ return TRUE;
}
-
-void
-tracker_dbus_method_metadata_register_type (DBusRec *rec)
+gboolean
+tracker_dbus_metadata_register_type (TrackerDBusMetadata *object,
+ const gchar *metadata,
+ const gchar *type,
+ GError **error)
{
- DBConnection *db_con;
- DBusError dbus_error;
- DBusMessage *reply;
- char *meta, *type_id;
- char *type;
+ TrackerDBusMetadataPriv *priv;
+ guint request_id;
+ DBConnection *db_con;
+ const gchar *type_id;
- g_return_if_fail (rec && rec->user_data);
+ request_id = tracker_dbus_get_next_request_id ();
- db_con = rec->user_data;
+ tracker_dbus_return_val_if_fail (metadata != NULL, FALSE, error);
+ tracker_dbus_return_val_if_fail (type != NULL, FALSE, error);
- dbus_error_init (&dbus_error);
- if (!dbus_message_get_args (rec->message, NULL,
- DBUS_TYPE_STRING, &meta,
- DBUS_TYPE_STRING, &type,
- DBUS_TYPE_INVALID)) {
- tracker_set_error (rec, "DBusError: %s;%s", dbus_error.name, dbus_error.message);
- dbus_error_free (&dbus_error);
- return;
- }
+ priv = GET_PRIV (object);
- if (!meta || strlen (meta) < 3 || (strchr (meta, ':') == NULL) ) {
- tracker_set_error (rec, "Metadata name is invalid. All names must be in the format 'class.name' ");
- return;
+ db_con = priv->db_con;
+
+ tracker_dbus_request_new (request_id,
+ "DBus request to register metadata type, "
+ "type:'%s', name:'%s'",
+ type,
+ metadata);
+
+ if (!metadata || strlen (metadata) < 3 || strchr (metadata, ':') == NULL) {
+ tracker_dbus_request_failed (request_id,
+ error,
+ "Metadata name '%s' is invalid, all names must be in "
+ "the format 'class:name'",
+ metadata);
+ return FALSE;
}
- if (strcmp ("index", type) == 0) {
+ if (strcmp (type, "index") == 0) {
type_id = "0";
- } else if (strcmp ("string", type) == 0) {
+ } else if (strcmp (type, "string") == 0) {
type_id = "1";
- } else if (strcmp ("numeric", type) == 0) {
+ } else if (strcmp (type, "numeric") == 0) {
type_id = "2";
- } else if (strcmp ("date", type) == 0) {
+ } else if (strcmp (type, "date") == 0) {
type_id = "3";
} else {
- tracker_set_error (rec, "Invalid Metadata Type specified");
- return;
- }
-
- tracker_exec_proc (db_con, "InsertMetadataType", meta, type_id, "0", "1", NULL);
+ tracker_dbus_request_failed (request_id,
+ error,
+ "Metadata type '%s' is invalid, types include 'index', "
+ "'string', 'numeric' and 'date'",
+ metadata);
+ return FALSE;
+ }
+
+ /* FIXME: Check return value? */
+ tracker_exec_proc (db_con,
+ "InsertMetadataType",
+ 4,
+ metadata,
+ type_id,
+ "0",
+ "1");
- reply = dbus_message_new_method_return (rec->message);
+ tracker_dbus_request_success (request_id);
- dbus_connection_send (rec->connection, reply, NULL);
-
- dbus_message_unref (reply);
+ return TRUE;
}
-
-void
-tracker_dbus_method_metadata_get_type_details (DBusRec *rec)
+gboolean
+tracker_dbus_metadata_get_type_details (TrackerDBusMetadata *object,
+ const gchar *metadata,
+ gchar **type,
+ gboolean *is_embedded,
+ gboolean *is_writable,
+ GError **error)
{
- TrackerDBResultSet *result_set;
- DBConnection *db_con;
- DBusError dbus_error;
- DBusMessage *reply;
- char *meta, *data_type;
- gboolean is_embedded, is_writable;
- gint id;
+ TrackerDBusMetadataPriv *priv;
+ TrackerDBResultSet *result_set;
+ guint request_id;
+ DBConnection *db_con;
+ gint i;
+
+ request_id = tracker_dbus_get_next_request_id ();
+
+ tracker_dbus_return_val_if_fail (metadata != NULL, FALSE, error);
+ tracker_dbus_return_val_if_fail (type != NULL, FALSE, error);
+ tracker_dbus_return_val_if_fail (is_embedded != NULL, FALSE, error);
+ tracker_dbus_return_val_if_fail (is_writable != NULL, FALSE, error);
-/*
- <method name="GetTypeDetails">
- <arg type="s" name="name" direction="in" />
- <arg type="s" name="data_type" direction="out" />
- <arg type="b" name="is_embedded" direction="out" />
- <arg type="b" name="is_writable" direction="out" />
- </method>
-*/
-
- g_return_if_fail (rec && rec->user_data);
-
- db_con = rec->user_data;
-
- dbus_error_init (&dbus_error);
- if (!dbus_message_get_args (rec->message, NULL,
- DBUS_TYPE_STRING, &meta,
- DBUS_TYPE_INVALID)) {
- tracker_set_error (rec, "DBusError: %s;%s", dbus_error.name, dbus_error.message);
- dbus_error_free (&dbus_error);
- return;
- }
+ priv = GET_PRIV (object);
- data_type = NULL;
- is_embedded = FALSE;
- is_writable = FALSE;
-
- if (!meta) {
- tracker_set_error (rec, "Unknown metadata type %s", meta);
- return;
- }
+ db_con = priv->db_con;
+
+ tracker_dbus_request_new (request_id,
+ "DBus request to get metadata details, "
+ "name:'%s'",
+ metadata);
- result_set = tracker_exec_proc (db_con, "GetMetadataTypeInfo", meta, NULL);
+ result_set = tracker_exec_proc (db_con, "GetMetadataTypeInfo", metadata, NULL);
if (!result_set) {
- tracker_set_error (rec, "Unknown metadata type %s", meta);
- return;
+ tracker_dbus_request_failed (request_id,
+ error,
+ "Metadata name '%s' is invalid or unrecognized",
+ metadata);
+ return FALSE;
}
tracker_db_result_set_get (result_set,
- 1, &id,
- 2, &is_embedded,
- 3, &is_writable,
+ 1, &i,
+ 2, is_embedded,
+ 3, is_writable,
-1);
- data_type = type_array[id];
+ *type = g_strdup (types[i]);
g_object_unref (result_set);
- reply = dbus_message_new_method_return (rec->message);
-
- dbus_message_append_args (reply,
- DBUS_TYPE_STRING, &data_type,
- DBUS_TYPE_BOOLEAN, &is_embedded,
- DBUS_TYPE_BOOLEAN, &is_writable,
- DBUS_TYPE_INVALID);
-
- dbus_connection_send (rec->connection, reply, NULL);
- dbus_message_unref (reply);
+ tracker_dbus_request_success (request_id);
+
+ return TRUE;
}
-
-void
-tracker_dbus_method_metadata_get_registered_types (DBusRec *rec)
+gboolean
+tracker_dbus_metadata_get_registered_types (TrackerDBusMetadata *object,
+ const gchar *class,
+ gchar ***values,
+ GError **error)
{
- DBConnection *db_con;
- DBusError dbus_error;
- DBusMessage *reply;
- char *class, **array;
- int row_count;
+ TrackerDBusMetadataPriv *priv;
+ TrackerDBResultSet *result_set;
+ guint request_id;
+ DBConnection *db_con;
-/*
- <!-- returns an array of all metadata types that are registered for a certain class -->
- <method name="GetRegisteredTypes">
- <arg type="s" name="metadata_class" direction="in" />
- <arg type="as" name="result" direction="out" />
- </method>
-*/
-
- g_return_if_fail (rec && rec->user_data);
-
- db_con = rec->user_data;
-
- dbus_error_init (&dbus_error);
- if (!dbus_message_get_args (rec->message, NULL,
- DBUS_TYPE_STRING, &class,
- DBUS_TYPE_INVALID)) {
- tracker_set_error (rec, "DBusError: %s;%s", dbus_error.name, dbus_error.message);
- dbus_error_free (&dbus_error);
- return;
- }
+ request_id = tracker_dbus_get_next_request_id ();
- array = NULL;
- row_count = 0;
+ tracker_dbus_return_val_if_fail (class != NULL, FALSE, error);
+ tracker_dbus_return_val_if_fail (values != NULL, FALSE, error);
- if (class) {
- TrackerDBResultSet *result_set;
+ priv = GET_PRIV (object);
- result_set = tracker_db_get_metadata_types (db_con, class, TRUE);
+ db_con = priv->db_con;
+
+ tracker_dbus_request_new (request_id,
+ "DBus request to get registered metadata types, "
+ "class:'%s'",
+ class);
- if (result_set) {
- array = tracker_get_query_result_as_array (result_set, &row_count);
- g_object_unref (result_set);
- }
+ result_set = tracker_db_get_metadata_types (db_con, class, TRUE);
+ if (result_set) {
+ *values = tracker_dbus_query_result_to_strv (result_set, NULL);
+ g_object_unref (result_set);
}
- reply = dbus_message_new_method_return (rec->message);
-
- dbus_message_append_args (reply,
- DBUS_TYPE_ARRAY, DBUS_TYPE_STRING, &array, row_count,
- DBUS_TYPE_INVALID);
-
- tracker_free_array (array, row_count);
-
- dbus_connection_send (rec->connection, reply, NULL);
- dbus_message_unref (reply);
+ tracker_dbus_request_success (request_id);
+
+ return TRUE;
}
-
-void
-tracker_dbus_method_metadata_get_writeable_types (DBusRec *rec)
+gboolean
+tracker_dbus_metadata_get_writable_types (TrackerDBusMetadata *object,
+ const gchar *class,
+ gchar ***values,
+ GError **error)
{
- DBConnection *db_con;
- DBusError dbus_error;
- DBusMessage *reply;
- char *class, *class_formatted, **array;
- int row_count;
+ TrackerDBusMetadataPriv *priv;
+ TrackerDBResultSet *result_set;
+ guint request_id;
+ DBConnection *db_con;
+ gchar *class_formatted;
-/*
- <!-- returns an array of all metadata types that are writeable and registered for a certain class
- You can enter "*" as the class to get all metadat types for all classes that are writeable
- -->
- <method name="GetWriteableTypes">
- <arg type="s" name="metadata_class" direction="in" />
- <arg type="as" name="result" direction="out" />
- </method>
-*/
+ request_id = tracker_dbus_get_next_request_id ();
- g_return_if_fail (rec && rec->user_data);
+ tracker_dbus_return_val_if_fail (class != NULL, FALSE, error);
+ tracker_dbus_return_val_if_fail (values != NULL, FALSE, error);
- db_con = rec->user_data;
+ priv = GET_PRIV (object);
- dbus_error_init (&dbus_error);
- if (!dbus_message_get_args (rec->message, NULL,
- DBUS_TYPE_STRING, &class,
- DBUS_TYPE_INVALID)) {
- tracker_set_error (rec, "DBusError: %s;%s", dbus_error.name, dbus_error.message);
- dbus_error_free (&dbus_error);
- return;
- }
-
- array = NULL;
- row_count = 0;
-
- if (class) {
- TrackerDBResultSet *result_set;
-
- class_formatted = g_strconcat (class, ".*", NULL);
-
- result_set = tracker_db_get_metadata_types (db_con, class_formatted, TRUE);
-
- g_free (class_formatted);
-
- if (result_set) {
- array = tracker_get_query_result_as_array (result_set, &row_count);
- g_object_unref (result_set);
- }
+ db_con = priv->db_con;
+
+ tracker_dbus_request_new (request_id,
+ "DBus request to get writable metadata types, "
+ "class:'%s'",
+ class);
+
+ class_formatted = g_strconcat (class, ".*", NULL);
+ result_set = tracker_db_get_metadata_types (db_con,
+ class_formatted,
+ TRUE);
+ if (result_set) {
+ *values = tracker_dbus_query_result_to_strv (result_set, NULL);
+ g_object_unref (result_set);
}
- reply = dbus_message_new_method_return (rec->message);
-
- dbus_message_append_args (reply,
- DBUS_TYPE_ARRAY, DBUS_TYPE_STRING, &array, row_count,
- DBUS_TYPE_INVALID);
-
- tracker_free_array (array, row_count);
+ g_free (class_formatted);
- dbus_connection_send (rec->connection, reply, NULL);
- dbus_message_unref (reply);
+ tracker_dbus_request_success (request_id);
+
+ return TRUE;
}
-
-void
-tracker_dbus_method_metadata_get_registered_classes (DBusRec *rec)
+gboolean
+tracker_dbus_metadata_get_registered_classes (TrackerDBusMetadata *object,
+ gchar ***values,
+ GError **error)
{
- TrackerDBResultSet *result_set;
- DBConnection *db_con;
- DBusMessage *reply;
- char **array;
- int row_count;
+ TrackerDBusMetadataPriv *priv;
+ TrackerDBResultSet *result_set;
+ guint request_id;
+ DBConnection *db_con;
-/*
- <!-- returns an array of all metadata type classes that are registered -->
- <method name="GetRegisteredClasses">
- <arg type="as" name="result" direction="out" />
- </method>
-*/
-
- g_return_if_fail (rec && rec->user_data);
+ request_id = tracker_dbus_get_next_request_id ();
- db_con = rec->user_data;
+ tracker_dbus_return_val_if_fail (values != NULL, FALSE, error);
- result_set = tracker_exec_proc (db_con, "SelectMetadataClasses", NULL);
+ priv = GET_PRIV (object);
- array = NULL;
- row_count = 0;
+ db_con = priv->db_con;
+
+ tracker_dbus_request_new (request_id,
+ "DBus request to get registered classes");
+ result_set = tracker_exec_proc (db_con,
+ "SelectMetadataClasses",
+ NULL);
+
if (result_set) {
- array = tracker_get_query_result_as_array (result_set, &row_count);
+ *values = tracker_dbus_query_result_to_strv (result_set, NULL);
g_object_unref (result_set);
}
- reply = dbus_message_new_method_return (rec->message);
-
- dbus_message_append_args (reply,
- DBUS_TYPE_ARRAY, DBUS_TYPE_STRING, &array, row_count,
- DBUS_TYPE_INVALID);
-
- tracker_free_array (array, row_count);
-
- dbus_connection_send (rec->connection, reply, NULL);
- dbus_message_unref (reply);
+ tracker_dbus_request_success (request_id);
+
+ return TRUE;
}
Modified: branches/indexer-split/src/trackerd/tracker-dbus-metadata.h
==============================================================================
--- branches/indexer-split/src/trackerd/tracker-dbus-metadata.h (original)
+++ branches/indexer-split/src/trackerd/tracker-dbus-metadata.h Mon Apr 21 11:21:20 2008
@@ -1,5 +1,7 @@
-/* Tracker - indexer and metadata database engine
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
+/*
* Copyright (C) 2006, Mr Jamie McCracken (jamiemcc gnome org)
+ * Copyright (C) 2008, Nokia
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public
@@ -17,20 +19,78 @@
* Boston, MA 02110-1301, USA.
*/
+#ifndef __TRACKER_DBUS_METADATA_H__
+#define __TRACKER_DBUS_METADATA_H__
-#ifndef _TRACKER_DBUS_METADATA_H_
-#define _TRACKER_DBUS_METADATA_H_
+#include <dbus/dbus-glib.h>
+#include <dbus/dbus-glib-bindings.h>
+#include <dbus/dbus-glib-lowlevel.h>
+
+#include "tracker-db-sqlite.h"
+#include "tracker-indexer.h"
+
+#define TRACKER_DBUS_METADATA_SERVICE "org.freedesktop.Tracker"
+#define TRACKER_DBUS_METADATA_PATH "/org/freedesktop/Tracker/Metadata"
+#define TRACKER_DBUS_METADATA_INTERFACE "org.freedesktop.Tracker.Metadata"
+
+G_BEGIN_DECLS
+
+#define TRACKER_TYPE_DBUS_METADATA (tracker_dbus_metadata_get_type ())
+#define TRACKER_DBUS_METADATA(object) (G_TYPE_CHECK_INSTANCE_CAST ((object), TRACKER_TYPE_DBUS_METADATA, TrackerDBusMetadata))
+#define TRACKER_DBUS_METADATA_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), TRACKER_TYPE_DBUS_METADATA, TrackerDBusMetadataClass))
+#define TRACKER_IS_DBUS_METADATA(object) (G_TYPE_CHECK_INSTANCE_TYPE ((object), TRACKER_TYPE_DBUS_METADATA))
+#define TRACKER_IS_DBUS_METADATA_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), TRACKER_TYPE_DBUS_METADATA))
+#define TRACKER_DBUS_METADATA_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), TRACKER_TYPE_DBUS_METADATA, TrackerDBusMetadataClass))
+
+typedef struct TrackerDBusMetadata TrackerDBusMetadata;
+typedef struct TrackerDBusMetadataClass TrackerDBusMetadataClass;
+
+struct TrackerDBusMetadata {
+ GObject parent;
+};
+
+struct TrackerDBusMetadataClass {
+ GObjectClass parent;
+};
+
+GType tracker_dbus_metadata_get_type (void);
+TrackerDBusMetadata *
+ tracker_dbus_metadata_new (DBConnection *db_con);
+void tracker_dbus_metadata_set_db_connection (TrackerDBusMetadata *object,
+ DBConnection *db_con);
+gboolean tracker_dbus_metadata_get (TrackerDBusMetadata *object,
+ const gchar *service,
+ const gchar *id,
+ gchar **keys,
+ gchar ***values,
+ GError **error);
+gboolean tracker_dbus_metadata_set (TrackerDBusMetadata *object,
+ const gchar *service,
+ const gchar *id,
+ gchar **keys,
+ gchar **values,
+ GError **error);
+gboolean tracker_dbus_metadata_register_type (TrackerDBusMetadata *object,
+ const gchar *metadata,
+ const gchar *type,
+ GError **error);
+gboolean tracker_dbus_metadata_get_type_details (TrackerDBusMetadata *object,
+ const gchar *metadata,
+ gchar **type,
+ gboolean *is_embedded,
+ gboolean *is_writable,
+ GError **error);
+gboolean tracker_dbus_metadata_get_registered_types (TrackerDBusMetadata *object,
+ const gchar *metadata,
+ gchar ***values,
+ GError **error);
+gboolean tracker_dbus_metadata_get_writable_types (TrackerDBusMetadata *object,
+ const gchar *class,
+ gchar ***values,
+ GError **error);
+gboolean tracker_dbus_metadata_get_registered_classes (TrackerDBusMetadata *object,
+ gchar ***values,
+ GError **error);
-#include "tracker-dbus.h"
-
-void tracker_dbus_method_metadata_get (DBusRec *rec);
-void tracker_dbus_method_metadata_set (DBusRec *rec);
-
-void tracker_dbus_method_metadata_register_type (DBusRec *rec);
-
-void tracker_dbus_method_metadata_get_type_details (DBusRec *rec);
-void tracker_dbus_method_metadata_get_registered_types (DBusRec *rec);
-void tracker_dbus_method_metadata_get_writeable_types (DBusRec *rec);
-void tracker_dbus_method_metadata_get_registered_classes (DBusRec *rec);
#endif
Modified: branches/indexer-split/src/trackerd/tracker-dbus-search.c
==============================================================================
--- branches/indexer-split/src/trackerd/tracker-dbus-search.c (original)
+++ branches/indexer-split/src/trackerd/tracker-dbus-search.c Mon Apr 21 11:21:20 2008
@@ -1,5 +1,7 @@
-/* Tracker - indexer and metadata database engine
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
+/*
* Copyright (C) 2006, Mr Jamie McCracken (jamiemcc gnome org)
+ * Copyright (C) 2008, Nokia
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public
@@ -20,170 +22,327 @@
#include <string.h>
#include <libtracker-common/tracker-log.h>
+
+#include <libtracker-common/tracker-log.h>
#include <libtracker-common/tracker-config.h>
+#include <libtracker-common/tracker-utils.h>
-#include "tracker-dbus-methods.h"
+#include "tracker-dbus.h"
+#include "tracker-dbus-search.h"
#include "tracker-rdf-query.h"
#include "tracker-query-tree.h"
#include "tracker-indexer.h"
#include "tracker-service-manager.h"
+#include "tracker-marshal.h"
-extern Tracker *tracker;
+#define DEFAULT_SEARCH_MAX_HITS 1024
-void
-tracker_dbus_method_search_get_hit_count (DBusRec *rec)
-{
- TrackerQueryTree *tree;
+#define GET_PRIV(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), TRACKER_TYPE_DBUS_SEARCH, TrackerDBusSearchPriv))
+
+typedef struct {
+ DBusGProxy *fd_proxy;
DBConnection *db_con;
- DBusError dbus_error;
- gchar *service;
- gchar *str;
+ Indexer *file_index;
+ Indexer *email_index;
+} TrackerDBusSearchPriv;
+
+enum {
+ PROP_0,
+ PROP_DB_CONNECTION,
+ PROP_FILE_INDEX,
+ PROP_EMAIL_INDEX
+};
+
+static void dbus_search_finalize (GObject *object);
+static void dbus_search_set_property (GObject *object,
+ guint param_id,
+ const GValue *value,
+ GParamSpec *pspec);
- g_return_if_fail (rec);
- g_return_if_fail (rec->user_data);
+G_DEFINE_TYPE(TrackerDBusSearch, tracker_dbus_search, G_TYPE_OBJECT)
- db_con = rec->user_data;
+static void
+tracker_dbus_search_class_init (TrackerDBusSearchClass *klass)
+{
+ GObjectClass *object_class;
-/*
- <!-- returns no of hits for the search_text on the servce -->
- <method name="GetHitCount">
- <arg type="s" name="service" direction="in" />
- <arg type="s" name="search_text" direction="in" />
- <arg type="i" name="result" direction="out" />
- </method>
-
-
-*/
-
- dbus_error_init (&dbus_error);
- if (!dbus_message_get_args (rec->message, NULL,
- DBUS_TYPE_STRING, &service,
- DBUS_TYPE_STRING, &str,
- DBUS_TYPE_INVALID)) {
- tracker_set_error (rec, "DBusError: %s;%s", dbus_error.name, dbus_error.message);
- dbus_error_free (&dbus_error);
- return;
- }
-
- if (!service) {
- tracker_set_error (rec, "No service was specified");
- return;
- }
+ object_class = G_OBJECT_CLASS (klass);
- if (!tracker_service_manager_is_valid_service (service)) {
- tracker_set_error (rec, "Invalid service %s or service has not been implemented yet", service);
- return;
- }
+ object_class->finalize = dbus_search_finalize;
+ object_class->set_property = dbus_search_set_property;
- if (tracker_is_empty_string (str)) {
- tracker_set_error (rec, "No search term was specified");
- return;
- }
+ g_object_class_install_property (object_class,
+ PROP_DB_CONNECTION,
+ g_param_spec_pointer ("db-connection",
+ "DB connection",
+ "Database connection to use in transactions",
+ G_PARAM_WRITABLE));
+ g_object_class_install_property (object_class,
+ PROP_FILE_INDEX,
+ g_param_spec_pointer ("file-index",
+ "File index",
+ "File index",
+ G_PARAM_WRITABLE));
+ g_object_class_install_property (object_class,
+ PROP_EMAIL_INDEX,
+ g_param_spec_pointer ("email-index",
+ "Email index",
+ "Email index",
+ G_PARAM_WRITABLE));
- //tracker_log ("Executing GetHitCount with params %s, %s", service, str);
+ g_type_class_add_private (object_class, sizeof (TrackerDBusSearchPriv));
+}
- gint service_array[12];
- GArray *services;
- gint result;
- DBusMessage *reply;
+static void
+tracker_dbus_search_init (TrackerDBusSearch *object)
+{
+}
- service_array[0] = tracker_service_manager_get_id_for_service (service);
+static void
+dbus_search_finalize (GObject *object)
+{
+ TrackerDBusSearchPriv *priv;
+
+ priv = GET_PRIV (object);
- if (strcmp (service, "Files") == 0) {
- service_array[1] = tracker_service_manager_get_id_for_service ("Folders");
- service_array[2] = tracker_service_manager_get_id_for_service ("Documents");
- service_array[3] = tracker_service_manager_get_id_for_service ("Images");
- service_array[4] = tracker_service_manager_get_id_for_service ("Videos");
- service_array[5] = tracker_service_manager_get_id_for_service ("Music");
- service_array[6] = tracker_service_manager_get_id_for_service ("Text");
- service_array[7] = tracker_service_manager_get_id_for_service ("Development");
- service_array[8] = tracker_service_manager_get_id_for_service ("Other");
- service_array[9] = 0;
- } else if (strcmp (service, "Emails") == 0) {
- service_array[1] = tracker_service_manager_get_id_for_service ("EvolutionEmails");
- service_array[2] = tracker_service_manager_get_id_for_service ("KMailEmails");
- service_array[3] = tracker_service_manager_get_id_for_service ("ThunderbirdEmails");
- service_array[4] = tracker_service_manager_get_id_for_service ("ModestEmails");
- service_array[5] = 0;
- } else if (strcmp (service, "Conversations") == 0) {
- service_array[1] = tracker_service_manager_get_id_for_service ("GaimConversations");
- service_array[2] = 0;
+ if (priv->fd_proxy) {
+ g_object_unref (priv->fd_proxy);
}
- services = g_array_new (TRUE, TRUE, sizeof (gint));
- g_array_append_vals (services, service_array, G_N_ELEMENTS (service_array));
+ G_OBJECT_CLASS (tracker_dbus_search_parent_class)->finalize (object);
+}
- db_con = tracker_db_get_service_connection (db_con, service);
- tree = tracker_query_tree_new (str, db_con->word_index, services);
- result = tracker_query_tree_get_hit_count (tree);
+static void
+dbus_search_set_property (GObject *object,
+ guint param_id,
+ const GValue *value,
+ GParamSpec *pspec)
+{
+ TrackerDBusSearchPriv *priv;
- reply = dbus_message_new_method_return (rec->message);
+ priv = GET_PRIV (object);
- dbus_message_append_args (reply,
- DBUS_TYPE_INT32,
- &result,
- DBUS_TYPE_INVALID);
+ switch (param_id) {
+ case PROP_DB_CONNECTION:
+ tracker_dbus_search_set_db_connection (TRACKER_DBUS_SEARCH (object),
+ g_value_get_pointer (value));
+ break;
+ case PROP_FILE_INDEX:
+ tracker_dbus_search_set_file_index (TRACKER_DBUS_SEARCH (object),
+ g_value_get_pointer (value));
+ break;
+ case PROP_EMAIL_INDEX:
+ tracker_dbus_search_set_email_index (TRACKER_DBUS_SEARCH (object),
+ g_value_get_pointer (value));
+ break;
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
+ break;
+ };
+}
- dbus_connection_send (rec->connection, reply, NULL);
+TrackerDBusSearch *
+tracker_dbus_search_new (DBConnection *db_con)
+{
+ TrackerDBusSearch *object;
- dbus_message_unref (reply);
- g_object_unref (tree);
- g_array_free (services, TRUE);
+ object = g_object_new (TRACKER_TYPE_DBUS_SEARCH,
+ "db-connection", db_con,
+ NULL);
+
+ return object;
}
+void
+tracker_dbus_search_set_db_connection (TrackerDBusSearch *object,
+ DBConnection *db_con)
+{
+ TrackerDBusSearchPriv *priv;
+
+ g_return_if_fail (TRACKER_IS_DBUS_SEARCH (object));
+ g_return_if_fail (db_con != NULL);
+
+ priv = GET_PRIV (object);
+
+ priv->db_con = db_con;
+
+ g_object_notify (G_OBJECT (object), "db-connection");
+}
void
-tracker_dbus_method_search_get_hit_count_all (DBusRec *rec)
+tracker_dbus_search_set_file_index (TrackerDBusSearch *object,
+ Indexer *file_index)
{
- TrackerDBResultSet *result_set = NULL;
- TrackerQueryTree *tree;
- GArray *hit_counts, *mail_hit_counts;
- DBConnection *db_con;
- DBusError dbus_error;
- gchar *str;
- guint i;
+ TrackerDBusSearchPriv *priv;
- g_return_if_fail (rec);
- g_return_if_fail (rec->user_data);
+ g_return_if_fail (TRACKER_IS_DBUS_SEARCH (object));
+ g_return_if_fail (file_index != NULL);
- db_con = rec->user_data;
+ priv = GET_PRIV (object);
+
+ priv->file_index = file_index;
+
+ g_object_notify (G_OBJECT (object), "file-index");
+}
+
+void
+tracker_dbus_search_set_email_index (TrackerDBusSearch *object,
+ Indexer *email_index)
+{
+ TrackerDBusSearchPriv *priv;
+
+ g_return_if_fail (TRACKER_IS_DBUS_SEARCH (object));
+ g_return_if_fail (email_index != NULL);
+
+ priv = GET_PRIV (object);
+
+ priv->email_index = email_index;
+
+ g_object_notify (G_OBJECT (object), "email-index");
+}
/*
- <!-- returns [service name, no. of hits] for the search_text -->
- <method name="GetHitCountAll">
- <arg type="s" name="search_text" direction="in" />
- <arg type="aas" name="result" direction="out" />
- </method>
+ * Functions
+ */
+static gint
+dbus_search_sanity_check_max_hits (gint max_hits)
+{
+ if (max_hits < 1) {
+ return DEFAULT_SEARCH_MAX_HITS;
+ }
+
+ return max_hits;
+}
+
+gboolean
+tracker_dbus_search_get_hit_count (TrackerDBusSearch *object,
+ const gchar *service,
+ const gchar *search_text,
+ gint *value,
+ GError **error)
+{
+ TrackerDBusSearchPriv *priv;
+ TrackerQueryTree *tree;
+ GArray *array;
+ guint request_id;
+ DBConnection *db_con;
+ gint services[12];
+ gint count = 0;
+
+ request_id = tracker_dbus_get_next_request_id ();
+
+ tracker_dbus_return_val_if_fail (service != NULL, FALSE, error);
+ tracker_dbus_return_val_if_fail (search_text != NULL, FALSE, error);
+ tracker_dbus_return_val_if_fail (value != NULL, FALSE, error);
+
+ priv = GET_PRIV (object);
+
+ db_con = priv->db_con;
-*/
+ tracker_dbus_request_new (request_id,
+ "DBus request to get hit count, "
+ "service:'%s', search text:'%s'",
+ service,
+ search_text);
- dbus_error_init (&dbus_error);
- if (!dbus_message_get_args (rec->message, NULL,
- DBUS_TYPE_STRING, &str,
- DBUS_TYPE_INVALID)) {
- tracker_set_error (rec, "DBusError: %s;%s", dbus_error.name, dbus_error.message);
- dbus_error_free (&dbus_error);
- return;
+ if (!tracker_service_manager_is_valid_service (service)) {
+ tracker_dbus_request_failed (request_id,
+ error,
+ "Service '%s' is invalid or has not been implemented yet",
+ service);
+ return FALSE;
}
- if (tracker_is_empty_string (str)) {
- tracker_set_error (rec, "No search term was specified");
- return;
+ if (tracker_is_empty_string (search_text)) {
+ tracker_dbus_request_failed (request_id,
+ error,
+ "No search term was specified");
+ return FALSE;
+ }
+
+ /* Check we have the right database connection */
+ db_con = tracker_db_get_service_connection (db_con, service);
+
+ services[count++] = tracker_service_manager_get_id_for_service (service);
+
+ if (strcmp (service, "Files") == 0) {
+ services[count++] = tracker_service_manager_get_id_for_service ("Folders");
+ services[count++] = tracker_service_manager_get_id_for_service ("Documents");
+ services[count++] = tracker_service_manager_get_id_for_service ("Images");
+ services[count++] = tracker_service_manager_get_id_for_service ("Videos");
+ services[count++] = tracker_service_manager_get_id_for_service ("Music");
+ services[count++] = tracker_service_manager_get_id_for_service ("Text");
+ services[count++] = tracker_service_manager_get_id_for_service ("Development");
+ services[count++] = tracker_service_manager_get_id_for_service ("Other");
+ } else if (strcmp (service, "Emails") == 0) {
+ services[count++] = tracker_service_manager_get_id_for_service ("EvolutionEmails");
+ services[count++] = tracker_service_manager_get_id_for_service ("KMailEmails");
+ services[count++] = tracker_service_manager_get_id_for_service ("ThunderbirdEmails");
+ } else if (strcmp (service, "Conversations") == 0) {
+ services[count++] = tracker_service_manager_get_id_for_service ("GaimConversations");
}
- //tracker_log ("Executing detailed search with params %s, %s, %d, %d", service, str, offset, limit);
+ services[count] = 0;
+
+ array = g_array_new (TRUE, TRUE, sizeof (gint));
+ g_array_append_vals (array, services, G_N_ELEMENTS (services));
+ tree = tracker_query_tree_new (search_text, db_con->word_index, array);
+ *value = tracker_query_tree_get_hit_count (tree);
+ g_object_unref (tree);
+ g_array_free (array, TRUE);
+
+ tracker_dbus_request_success (request_id);
+
+ return TRUE;
+}
+
+gboolean
+tracker_dbus_search_get_hit_count_all (TrackerDBusSearch *object,
+ const gchar *search_text,
+ GPtrArray **values,
+ GError **error)
+{
+ TrackerDBusSearchPriv *priv;
+ TrackerDBResultSet *result_set = NULL;
+ TrackerQueryTree *tree;
+ GArray *hit_counts;
+ GArray *mail_hit_counts;
+ guint request_id;
+ DBConnection *db_con;
+ guint i;
+
+ request_id = tracker_dbus_get_next_request_id ();
- tree = tracker_query_tree_new (str, db_con->word_index, NULL);
- hit_counts = tracker_query_tree_get_hit_counts (tree);
+ tracker_dbus_return_val_if_fail (search_text != NULL, FALSE, error);
+ tracker_dbus_return_val_if_fail (values != NULL, FALSE, error);
- tracker_query_tree_set_indexer (tree, tracker->email_index);
- mail_hit_counts = tracker_query_tree_get_hit_counts (tree);
- g_array_append_vals (hit_counts, mail_hit_counts->data, mail_hit_counts->len);
- g_array_free (mail_hit_counts, TRUE);
+ priv = GET_PRIV (object);
+
+ db_con = priv->db_con;
+
+ tracker_dbus_request_new (request_id,
+ "DBus request to get search hit count for all, "
+ "search text:'%s'",
+ search_text);
+
+ if (tracker_is_empty_string (search_text)) {
+ tracker_dbus_request_failed (request_id,
+ error,
+ "No search term was specified");
+ return FALSE;
+ }
+
+ tree = tracker_query_tree_new (search_text, db_con->word_index, NULL);
+
+ hit_counts = tracker_query_tree_get_hit_counts (tree);
+ tracker_query_tree_set_indexer (tree, priv->email_index);
+ mail_hit_counts = tracker_query_tree_get_hit_counts (tree);
+ g_array_append_vals (hit_counts, mail_hit_counts->data, mail_hit_counts->len);
+ g_array_free (mail_hit_counts, TRUE);
for (i = 0; i < hit_counts->len; i++) {
TrackerHitCount count;
- GValue value = { 0, };
+ GValue value = { 0, };
if (G_UNLIKELY (!result_set)) {
result_set = _tracker_db_result_set_new (2);
@@ -193,7 +352,8 @@
_tracker_db_result_set_append (result_set);
g_value_init (&value, G_TYPE_STRING);
- g_value_take_string (&value, tracker_service_manager_get_service_by_id (count.service_type_id));
+ g_value_take_string (&value,
+ tracker_service_manager_get_service_by_id (count.service_type_id));
_tracker_db_result_set_set_value (result_set, 0, &value);
g_value_unset (&value);
@@ -205,96 +365,88 @@
if (result_set) {
tracker_db_result_set_rewind (result_set);
+ *values = tracker_dbus_query_result_to_ptr_array (result_set);
+ g_object_unref (result_set);
}
- tracker_dbus_reply_with_query_result (rec, result_set);
+ g_array_free (hit_counts, TRUE);
+ g_object_unref (tree);
- g_array_free (hit_counts, TRUE);
- g_object_unref (tree);
+ tracker_dbus_request_success (request_id);
- if (result_set) {
- g_object_unref (result_set);
- }
+ return TRUE;
}
-
-void
-tracker_dbus_method_search_text (DBusRec *rec)
+gboolean
+tracker_dbus_search_text (TrackerDBusSearch *object,
+ gint live_query_id,
+ const gchar *service,
+ const gchar *search_text,
+ gint offset,
+ gint max_hits,
+ gchar ***values,
+ GError **error)
{
- TrackerDBResultSet *result_set;
- DBConnection *db_con;
- DBusError dbus_error;
- DBusMessage *reply;
- gchar **array;
- gint row_count, i;
- gint limit, query_id, offset;
- gchar *service;
- gchar *str;
-
- g_return_if_fail (rec);
- g_return_if_fail (rec->user_data);
+ TrackerDBusSearchPriv *priv;
+ TrackerDBResultSet *result_set;
+ guint request_id;
+ DBConnection *db_con;
+ gchar **strv = NULL;
- db_con = rec->user_data;
+ request_id = tracker_dbus_get_next_request_id ();
-/*
- <!-- searches specified service for entities that match the specified search_text.
- Returns uri of all hits. -->
- <method name="Text">
- <arg type="i" name="live_query_id" direction="in" />
- <arg type="s" name="service" direction="in" />
- <arg type="s" name="search_text" direction="in" />
- <arg type="i" name="offset" direction="in" />
- <arg type="i" name="max_hits" direction="in" />
- <arg type="as" name="result" direction="out" />
- </method>
-*/
-
- dbus_error_init (&dbus_error);
- if (!dbus_message_get_args (rec->message, NULL, DBUS_TYPE_INT32, &query_id,
- DBUS_TYPE_STRING, &service,
- DBUS_TYPE_STRING, &str,
- DBUS_TYPE_INT32, &offset,
- DBUS_TYPE_INT32, &limit,
- DBUS_TYPE_INVALID)) {
- tracker_set_error (rec, "DBusError: %s;%s", dbus_error.name, dbus_error.message);
- dbus_error_free (&dbus_error);
- return;
- }
-
- if (!service) {
- tracker_set_error (rec, "No service was specified");
- return;
- }
+ tracker_dbus_return_val_if_fail (service != NULL, FALSE, error);
+ tracker_dbus_return_val_if_fail (search_text != NULL, FALSE, error);
+ tracker_dbus_return_val_if_fail (values != NULL, FALSE, error);
- if (!tracker_service_manager_is_valid_service (service)) {
- tracker_set_error (rec, "Invalid service %s or service has not been implemented yet", service);
- return;
- }
+ priv = GET_PRIV (object);
- if (tracker_is_empty_string (str)) {
- tracker_set_error (rec, "No search term was specified");
- return;
- }
+ db_con = priv->db_con;
+
+ tracker_dbus_request_new (request_id,
+ "DBus request to search text, "
+ "query id:%d, service:'%s', search text:'%s', "
+ "offset:%d, max hits:%d",
+ live_query_id,
+ service,
+ search_text,
+ offset,
+ max_hits);
- if (limit < 1) {
- limit = 1024;
+ if (!tracker_service_manager_is_valid_service (service)) {
+ tracker_dbus_request_failed (request_id,
+ error,
+ "Service '%s' is invalid or has not been implemented yet",
+ service);
+ return FALSE;
}
- tracker_log ("Executing search with params %s, %s", service, str);
+ if (tracker_is_empty_string (search_text)) {
+ tracker_dbus_request_failed (request_id,
+ error,
+ "No search term was specified");
+ return FALSE;
+ }
+ /* Check we have the right database connection */
db_con = tracker_db_get_service_connection (db_con, service);
- result_set = tracker_db_search_text (db_con, service, str, offset, limit, FALSE, FALSE);
-
- row_count = 0;
- array = NULL;
+ result_set = tracker_db_search_text (db_con,
+ service,
+ search_text,
+ offset,
+ dbus_search_sanity_check_max_hits (max_hits),
+ FALSE,
+ FALSE);
if (result_set) {
- gboolean valid = TRUE;
- gchar *prefix, *name;
+ gchar *prefix, *name;
+ gboolean valid = TRUE;
+ gint row_count;
+ gint i;
- row_count = tracker_db_result_set_get_n_rows (result_set);
- array = g_new (gchar *, row_count);
+ row_count = tracker_db_result_set_get_n_rows (result_set) + 1;
+ strv = g_new (gchar*, row_count);
i = 0;
while (valid) {
@@ -303,619 +455,542 @@
1, &name,
-1);
- array[i] = g_build_filename (prefix, name, NULL);
+ strv[i++] = g_build_filename (prefix, name, NULL);
valid = tracker_db_result_set_iter_next (result_set);
- i++;
g_free (prefix);
g_free (name);
}
+ strv[i] = NULL;
+
g_object_unref (result_set);
- } else {
- array = g_new (gchar *, 1);
- array[0] = NULL;
}
+
+ if (!strv) {
+ strv = g_new (gchar*, 1);
+ strv[0] = NULL;
- reply = dbus_message_new_method_return (rec->message);
-
- dbus_message_append_args (reply,
- DBUS_TYPE_ARRAY, DBUS_TYPE_STRING, &array, row_count,
- DBUS_TYPE_INVALID);
-
- for (i = 0; i < row_count; i++) {
- if (array[i]) {
- g_free (array[i]);
- }
+ tracker_dbus_request_comment (request_id,
+ "Search found no results");
}
- g_free (array);
+ *values = strv;
- dbus_connection_send (rec->connection, reply, NULL);
- dbus_message_unref (reply);
-}
+ tracker_dbus_request_success (request_id);
+ return TRUE;
+}
-void
-tracker_dbus_method_search_text_detailed (DBusRec *rec)
+gboolean
+tracker_dbus_search_text_detailed (TrackerDBusSearch *object,
+ gint live_query_id,
+ const gchar *service,
+ const gchar *search_text,
+ gint offset,
+ gint max_hits,
+ GPtrArray **values,
+ GError **error)
{
- TrackerDBResultSet *result_set;
- DBConnection *db_con;
- DBusError dbus_error;
- gint limit, query_id, offset;
- gchar *service;
- gchar *str;
-
- g_return_if_fail (rec);
- g_return_if_fail (rec->user_data);
+ TrackerDBusSearchPriv *priv;
+ TrackerDBResultSet *result_set;
+ guint request_id;
+ DBConnection *db_con;
- db_con = rec->user_data;
+ request_id = tracker_dbus_get_next_request_id ();
-/*
- More detailed version of above. Searches specified service for entities that match the specified search_text.
- Returns hits in array format [uri, service, mime] -->
- <method name="TextDetailed">
- <arg type="i" name="live_query_id" direction="in" />
- <arg type="s" name="service" direction="in" />
- <arg type="s" name="search_text" direction="in" />
- <arg type="i" name="offset" direction="in" />
- <arg type="i" name="max_hits" direction="in" />
- <arg type="aas" name="result" direction="out" />
- </method>
-*/
-
- dbus_error_init (&dbus_error);
- if (!dbus_message_get_args (rec->message, NULL, DBUS_TYPE_INT32, &query_id,
- DBUS_TYPE_STRING, &service,
- DBUS_TYPE_STRING, &str,
- DBUS_TYPE_INT32, &offset,
- DBUS_TYPE_INT32, &limit,
- DBUS_TYPE_INVALID)) {
- tracker_set_error (rec, "DBusError: %s;%s", dbus_error.name, dbus_error.message);
- dbus_error_free (&dbus_error);
- return;
- }
-
- if (!service) {
- tracker_set_error (rec, "No service was specified");
- return;
- }
+ tracker_dbus_return_val_if_fail (service != NULL, FALSE, error);
+ tracker_dbus_return_val_if_fail (search_text != NULL, FALSE, error);
+ tracker_dbus_return_val_if_fail (values != NULL, FALSE, error);
- if (!tracker_service_manager_is_valid_service (service)) {
- tracker_set_error (rec, "Invalid service %s or service has not been implemented yet", service);
- return;
- }
+ priv = GET_PRIV (object);
- if (tracker_is_empty_string (str)) {
- tracker_set_error (rec, "No search term was specified");
- return;
- }
+ db_con = priv->db_con;
+
+ tracker_dbus_request_new (request_id,
+ "DBus request to search text detailed, "
+ "query id:%d, service:'%s', search text:'%s', "
+ "offset:%d, max hits:%d",
+ live_query_id,
+ service,
+ search_text,
+ offset,
+ max_hits);
- if (limit < 1) {
- limit = 1024;
+ if (!tracker_service_manager_is_valid_service (service)) {
+ tracker_dbus_request_failed (request_id,
+ error,
+ "Service '%s' is invalid or has not been implemented yet",
+ service);
+ return FALSE;
}
- tracker_log ("Executing detailed search with params %s, %s, %d, %d", service, str, offset, limit);
+ if (tracker_is_empty_string (search_text)) {
+ tracker_dbus_request_failed (request_id,
+ error,
+ "No search term was specified");
+ return FALSE;
+ }
+ /* Check we have the right database connection */
db_con = tracker_db_get_service_connection (db_con, service);
- result_set = tracker_db_search_text (db_con, service, str, offset, limit, FALSE, TRUE);
-
- /*
- if (tracker_config_get_verbosity (tracker->config) > 0) {
- tracker_db_log_result (res);
- }
- */
+ result_set = tracker_db_search_text (db_con,
+ service,
+ search_text,
+ offset,
+ dbus_search_sanity_check_max_hits (max_hits),
+ FALSE,
+ TRUE);
- tracker_dbus_reply_with_query_result (rec, result_set);
+ *values = tracker_dbus_query_result_to_ptr_array (result_set);
if (result_set) {
g_object_unref (result_set);
}
-}
+ tracker_dbus_request_success (request_id);
-void
-tracker_dbus_method_search_get_snippet (DBusRec *rec)
-{
- TrackerDBResultSet *result_set;
- DBConnection *db_con;
- DBusError dbus_error;
- DBusMessage *reply;
- gchar *service, *uri, *str;
- gchar *snippet, *service_id;
+ return TRUE;
+}
- g_return_if_fail (rec);
- g_return_if_fail (rec->user_data);
+gboolean
+tracker_dbus_search_get_snippet (TrackerDBusSearch *object,
+ const gchar *service,
+ const gchar *id,
+ const gchar *search_text,
+ gchar **values,
+ GError **error)
+{
+ TrackerDBusSearchPriv *priv;
+ TrackerDBResultSet *result_set;
+ guint request_id;
+ DBConnection *db_con;
+ gchar *snippet = NULL;
+ gchar *service_id;
+
+ request_id = tracker_dbus_get_next_request_id ();
+
+ tracker_dbus_return_val_if_fail (service != NULL, FALSE, error);
+ tracker_dbus_return_val_if_fail (id != NULL, FALSE, error);
+ tracker_dbus_return_val_if_fail (search_text != NULL, FALSE, error);
+ tracker_dbus_return_val_if_fail (values != NULL, FALSE, error);
- db_con = rec->user_data;
+ priv = GET_PRIV (object);
-/*
- <!-- Returns a search snippet of text with matchinhg text enclosed in bold tags -->
- <method name="GetSnippet">
- <arg type="s" name="service" direction="in" />
- <arg type="s" name="id" direction="in" />
- <arg type="s" name="search_text" direction="in" />
- <arg type="s" name="result" direction="out" />
- </method>
-
-*/
-
- dbus_error_init (&dbus_error);
- if (!dbus_message_get_args (rec->message, NULL,
- DBUS_TYPE_STRING, &service,
- DBUS_TYPE_STRING, &uri,
- DBUS_TYPE_STRING, &str,
- DBUS_TYPE_INVALID)) {
- tracker_set_error (rec, "DBusError: %s;%s", dbus_error.name, dbus_error.message);
- dbus_error_free (&dbus_error);
- return;
- }
-
- if (!service) {
- tracker_set_error (rec, "No service was specified");
- return;
- }
+ db_con = priv->db_con;
+
+ tracker_dbus_request_new (request_id,
+ "DBus request to get snippet, "
+ "service:'%s', search text:'%s', id:'%s'",
+ service,
+ search_text,
+ id);
if (!tracker_service_manager_is_valid_service (service)) {
- tracker_set_error (rec, "Invalid service %s or service has not been implemented yet", service);
- return;
+ tracker_dbus_request_failed (request_id,
+ error,
+ "Service '%s' is invalid or has not been implemented yet",
+ service);
+ return FALSE;
}
- if (tracker_is_empty_string (str)) {
- tracker_set_error (rec, "No search term was specified");
- return;
- }
+ if (tracker_is_empty_string (search_text)) {
+ tracker_dbus_request_failed (request_id,
+ error,
+ "No search term was specified");
+ return FALSE;
+ }
- //tracker_log ("Getting snippet with params %s, %s, %s", service, uri, str);
+ /* Check we have the right database connection */
db_con = tracker_db_get_service_connection (db_con, service);
- service_id = tracker_db_get_id (db_con, service, uri);
- if (!service_id) {
- g_free (service_id);
- tracker_set_error (rec, "Service uri %s not found", uri);
- return;
- }
-
- snippet = NULL;
+ service_id = tracker_db_get_id (db_con, service, id);
+ if (!service_id) {
+ tracker_dbus_request_failed (request_id,
+ error,
+ "Service URI '%s' not found",
+ id);
+ return FALSE;
+ }
+
+ result_set = tracker_exec_proc (db_con->blob,
+ "GetAllContents",
+ service_id,
+ NULL);
+ g_free (service_id);
- result_set = tracker_exec_proc (db_con->blob, "GetAllContents", service_id, NULL);
- g_free (service_id);
-
if (result_set) {
- gchar **array, *text;
+ gchar **strv;
+ gchar *text;
tracker_db_result_set_get (result_set, 0, &text, -1);
- array = tracker_parse_text_into_array (str);
+ strv = tracker_parse_text_into_array (text);
- if (array && array[0]) {
- snippet = tracker_get_snippet (text, array, 120);
+ if (strv && strv[0]) {
+ snippet = tracker_get_snippet (text, strv, 120);
}
- g_strfreev (array);
+ g_strfreev (strv);
g_free (text);
g_object_unref (result_set);
}
- /* do not pass NULL to dbus or it will crash */
+ /* Sanity check snippet, using NULL will crash */
if (!snippet || !g_utf8_validate (snippet, -1, NULL) ) {
snippet = g_strdup (" ");
}
-// tracker_debug ("snippet is %s", snippet);
-
- reply = dbus_message_new_method_return (rec->message);
-
- dbus_message_append_args (reply,
- DBUS_TYPE_STRING, &snippet,
- DBUS_TYPE_INVALID);
+ *values = snippet;
- dbus_connection_send (rec->connection, reply, NULL);
- dbus_message_unref (reply);
+ tracker_dbus_request_success (request_id);
- g_free (snippet);
+ return TRUE;
}
-
-void
-tracker_dbus_method_search_files_by_text (DBusRec *rec)
+gboolean
+tracker_dbus_search_files_by_text (TrackerDBusSearch *object,
+ gint live_query_id,
+ const gchar *search_text,
+ gint offset,
+ gint max_hits,
+ gboolean group_results,
+ GHashTable **values,
+ GError **error)
{
- TrackerDBResultSet *result_set;
- DBConnection *db_con;
- DBusError dbus_error;
- DBusMessage *reply;
- DBusMessageIter iter;
- DBusMessageIter iter_dict;
- gchar *text;
- gint limit, query_id, offset;
- gboolean sort;
+ TrackerDBusSearchPriv *priv;
+ TrackerDBResultSet *result_set;
+ guint request_id;
+ DBConnection *db_con;
+
+ request_id = tracker_dbus_get_next_request_id ();
+
+ tracker_dbus_return_val_if_fail (search_text != NULL, FALSE, error);
+ tracker_dbus_return_val_if_fail (values != NULL, FALSE, error);
+
+ priv = GET_PRIV (object);
+
+ db_con = priv->db_con;
+
+ tracker_dbus_request_new (request_id,
+ "DBus request to search files by text, "
+ "query id:%d, search text:'%s', offset:%d"
+ "max hits:%d, group results:'%s'",
+ live_query_id,
+ search_text,
+ offset,
+ max_hits,
+ group_results ? "yes" : "no");
+
+ result_set = tracker_db_search_files_by_text (db_con,
+ search_text,
+ offset,
+ dbus_search_sanity_check_max_hits (max_hits),
+ group_results);
- g_return_if_fail (rec);
- g_return_if_fail (rec->user_data);
+ *values = tracker_dbus_query_result_to_hash_table (result_set);
- db_con = rec->user_data;
+ if (result_set) {
+ g_object_unref (result_set);
+ }
- sort = FALSE;
+ tracker_dbus_request_success (request_id);
-/*
- <!-- searches all file based entities that match the specified search_text.
- Returns dict/hashtable with the uri as key and the following fields as the variant part in order: file service category, File:Format, File:Size, File:Rank, File:Modified
- If group_results is True then results are sorted and grouped by service type.
- -->
- <method name="FilesByText">
- <arg type="i" name="live_query_id" direction="in" />
- <arg type="s" name="search_text" direction="in" />
- <arg type="i" name="max_hits" direction="in" />
- <arg type="b" name="group_results" direction="in" />
- <arg type="a{sv}" name="result" direction="out" />
- </method>
-
-*/
-
- dbus_error_init (&dbus_error);
- if (!dbus_message_get_args (rec->message, NULL,
- DBUS_TYPE_INT32, &query_id,
- DBUS_TYPE_STRING, &text,
- DBUS_TYPE_INT32, &offset,
- DBUS_TYPE_INT32, &limit,
- DBUS_TYPE_BOOLEAN, &sort,
- DBUS_TYPE_INVALID)) {
- tracker_set_error (rec, "DBusError: %s;%s", dbus_error.name, dbus_error.message);
- dbus_error_free (&dbus_error);
- return;
- }
-
- result_set = tracker_db_search_files_by_text (db_con, text, offset, limit, sort);
-
- if (!result_set)
- return;
-
- reply = dbus_message_new_method_return (rec->message);
-
- dbus_message_iter_init_append (reply, &iter);
-
- dbus_message_iter_open_container (&iter,
- DBUS_TYPE_ARRAY,
- DBUS_DICT_ENTRY_BEGIN_CHAR_AS_STRING
- DBUS_TYPE_STRING_AS_STRING
- DBUS_TYPE_VARIANT_AS_STRING
- DBUS_DICT_ENTRY_END_CHAR_AS_STRING,
- &iter_dict);
-
- tracker_add_query_result_to_dict (result_set, &iter_dict);
- g_object_unref (result_set);
-
- dbus_message_iter_close_container (&iter, &iter_dict);
- dbus_connection_send (rec->connection, reply, NULL);
- dbus_message_unref (reply);
+ return TRUE;
}
-
-void
-tracker_dbus_method_search_metadata (DBusRec *rec)
+gboolean
+tracker_dbus_search_metadata (TrackerDBusSearch *object,
+ const gchar *service,
+ const gchar *field,
+ const gchar *search_text,
+ gint offset,
+ gint max_hits,
+ gchar ***values,
+ GError **error)
{
- TrackerDBResultSet *result_set;
- DBConnection *db_con;
- DBusError dbus_error;
- DBusMessage *reply;
- gchar *service, *field, *text;
- gchar **array;
- gint limit, row_count = 0, offset;
-
- g_return_if_fail (rec);
- g_return_if_fail (rec->user_data);
-
- db_con = rec->user_data;
-
-/*
- <!-- searches a specific metadata field (field parameter) for a search term (search_text).
- The result is an array of uri/id's
- -->
- <method name="Metadata">
- <arg type="s" name="service" direction="in" />
- <arg type="s" name="field" direction="in" />
- <arg type="s" name="search_text" direction="in" />
- <arg type="i" name="max_hits" direction="in" />
- <arg type="as" name="result" direction="out" />
- </method>
-*/
-
- dbus_error_init (&dbus_error);
- if (!dbus_message_get_args (rec->message, NULL,
- DBUS_TYPE_STRING, &service,
- DBUS_TYPE_STRING, &field,
- DBUS_TYPE_STRING, &text,
- DBUS_TYPE_INT32, &offset,
- DBUS_TYPE_INT32, &limit,
- DBUS_TYPE_INVALID)) {
- tracker_set_error (rec, "DBusError: %s;%s", dbus_error.name, dbus_error.message);
- dbus_error_free (&dbus_error);
- return;
- }
+ TrackerDBusSearchPriv *priv;
+ TrackerDBResultSet *result_set;
+ guint request_id;
+ DBConnection *db_con;
+
+ /* FIXME: This function is completely redundant */
+
+ request_id = tracker_dbus_get_next_request_id ();
+
+ tracker_dbus_return_val_if_fail (service != NULL, FALSE, error);
+ tracker_dbus_return_val_if_fail (field != NULL, FALSE, error);
+ tracker_dbus_return_val_if_fail (search_text != NULL, FALSE, error);
+ tracker_dbus_return_val_if_fail (values != NULL, FALSE, error);
+
+ priv = GET_PRIV (object);
+
+ db_con = priv->db_con;
+
+ tracker_dbus_request_new (request_id,
+ "DBus request to search metadata, "
+ "service:'%s', search text:'%s', field:'%s', "
+ "offset:%d, max hits:%d",
+ service,
+ search_text,
+ field,
+ offset,
+ max_hits);
if (!tracker_service_manager_is_valid_service (service)) {
- tracker_set_error (rec, "Invalid service %s or service has not been implemented yet", service);
- return;
- }
+ tracker_dbus_request_failed (request_id,
+ error,
+ "Service '%s' is invalid or has not been implemented yet",
+ service);
+ return FALSE;
+ }
+
+ /* result_set = tracker_db_search_metadata (db_con, */
+ /* service, */
+ /* field, */
+ /* text, */
+ /* offset, */
+ /* dbus_search_sanity_check_max_hits (max_hits)); */
-// result_set = tracker_db_search_metadata (db_con, service, field, text, offset, limit);
- result_set = NULL;
+ result_set = NULL;
- array = NULL;
+ *values = tracker_dbus_query_result_to_strv (result_set, NULL);
if (result_set) {
- array = tracker_get_query_result_as_array (result_set, &row_count);
g_object_unref (result_set);
}
- reply = dbus_message_new_method_return (rec->message);
-
- dbus_message_append_args (reply,
- DBUS_TYPE_ARRAY, DBUS_TYPE_STRING, &array, row_count,
- DBUS_TYPE_INVALID);
+ tracker_dbus_request_success (request_id);
- tracker_free_array (array, row_count);
-
- dbus_connection_send (rec->connection, reply, NULL);
- dbus_message_unref (reply);
+ return TRUE;
}
-
-void
-tracker_dbus_method_search_matching_fields (DBusRec *rec)
+gboolean
+tracker_dbus_search_matching_fields (TrackerDBusSearch *object,
+ const gchar *service,
+ const gchar *id,
+ const gchar *search_text,
+ GHashTable **values,
+ GError **error)
{
- TrackerDBResultSet *result_set;
- DBConnection *db_con;
- DBusError dbus_error;
- gchar *text, *service, *id;
+ TrackerDBusSearchPriv *priv;
+ TrackerDBResultSet *result_set;
+ guint request_id;
+ DBConnection *db_con;
- g_return_if_fail (rec);
- g_return_if_fail (rec->user_data);
+ request_id = tracker_dbus_get_next_request_id ();
- db_con = rec->user_data;
+ tracker_dbus_return_val_if_fail (service != NULL, FALSE, error);
+ tracker_dbus_return_val_if_fail (id != NULL, FALSE, error);
+ tracker_dbus_return_val_if_fail (search_text != NULL, FALSE, error);
+ tracker_dbus_return_val_if_fail (values != NULL, FALSE, error);
-/*
- <!-- Retrieves matching metadata fields for a search term on a specific service and entity.
- The result is a dict/hashtable with the metadata name as the key and the corresponding metadata value as the variant
- If the metadata result is a large field (like File.Content) then only a small chunk of the matching text is returned
- Only indexable metadata fields are searched and returned.
- -->
- <method name="MatchingFields">
- <arg type="s" name="service" direction="in" />
- <arg type="s" name="id" direction="in" />
- <arg type="s" name="search_text" direction="in" />
- <arg type="a{sv}" name="result" direction="out" />
- </method>
-
-*/
-
- dbus_error_init (&dbus_error);
- if (!dbus_message_get_args (rec->message, NULL,
- DBUS_TYPE_STRING, &service,
- DBUS_TYPE_STRING, &id,
- DBUS_TYPE_STRING, &text,
- DBUS_TYPE_INVALID)) {
- tracker_set_error (rec, "DBusError: %s;%s", dbus_error.name, dbus_error.message);
- dbus_error_free (&dbus_error);
- return;
- }
+ priv = GET_PRIV (object);
+
+ db_con = priv->db_con;
+
+ tracker_dbus_request_new (request_id,
+ "DBus request to search matching fields, "
+ "service:'%s', search text:'%s', id:'%s'",
+ service,
+ search_text,
+ id);
if (!tracker_service_manager_is_valid_service (service)) {
- tracker_set_error (rec, "Invalid service %s or service has not been implemented yet", service);
- return;
+ tracker_dbus_request_failed (request_id,
+ error,
+ "Service '%s' is invalid or has not been implemented yet",
+ service);
+ return FALSE;
}
- if (tracker_is_empty_string (id)) {
- tracker_set_error (rec, "Id field must have a value");
- return;
- }
+ if (tracker_is_empty_string (id)) {
+ tracker_dbus_request_failed (request_id,
+ error,
+ "ID field must have a value");
+ return FALSE;
+ }
+
+ /* Check we have the right database connection */
db_con = tracker_db_get_service_connection (db_con, service);
- result_set = tracker_db_search_matching_metadata (db_con, service, id, text);
- if (result_set) {
- DBusMessage *reply;
- DBusMessageIter iter;
- DBusMessageIter iter_dict;
-
- reply = dbus_message_new_method_return (rec->message);
-
- dbus_message_iter_init_append (reply, &iter);
-
- dbus_message_iter_open_container (&iter,
- DBUS_TYPE_ARRAY,
- DBUS_DICT_ENTRY_BEGIN_CHAR_AS_STRING
- DBUS_TYPE_STRING_AS_STRING
- DBUS_TYPE_VARIANT_AS_STRING
- DBUS_DICT_ENTRY_END_CHAR_AS_STRING,
- &iter_dict);
+ result_set = tracker_db_search_matching_metadata (db_con,
+ service,
+ id,
+ search_text);
+ *values = tracker_dbus_query_result_to_hash_table (result_set);
- tracker_add_query_result_to_dict (result_set, &iter_dict);
+ if (result_set) {
g_object_unref (result_set);
-
- dbus_message_iter_close_container (&iter, &iter_dict);
- dbus_connection_send (rec->connection, reply, NULL);
- dbus_message_unref (reply);
}
-}
-
-
-void
-tracker_dbus_method_search_query (DBusRec *rec)
-{
- TrackerDBResultSet *result_set;
- DBConnection *db_con;
- DBusError dbus_error;
- gchar **fields;
- gint limit, row_count, query_id, offset;
- gchar *query, *search_text, *service, *keyword;
- gboolean sort_results;
-
- g_return_if_fail (rec);
- g_return_if_fail (rec->user_data);
- db_con = rec->user_data;
+ tracker_dbus_request_success (request_id);
- sort_results = FALSE;
-/*
- <!-- searches specified service for matching entities.
- The service parameter specifies the service which the query will be performed on
- The fields parameter specifies an array of aditional metadata fields to return in addition to the id field (which is returned as the "key" in the resultant dict/hashtable) and the service category. This can be null
- The optional search_text paramter specifies the text to search for in a full text search of all indexed fields - this parameter can be null if the query_condition is not null (in which case only the query condition is used to find matches)
- The optional keyword search - a single keyword may be used here to filter the results.
- The optional query_condition parameter specifies an xml-based rdf query condition which is used to filter out the results - this parameter can be null if the search_text is not null (in which case only the search_text parameter is used to find matches)
- The Offset parameter sets the start row of the returned result set (useful for paging/cursors). A value of 0 should be passed to get rows from the beginning.
- The max_hits parameter limits the size of the result set.
- The sort_by_service parameter optionally sorts results by their service category (if FALSE no service sorting is done)
- The result is a hashtable/dict with the id of the matching entity as the key fields.
- The variant part of the result is the service category followed by list of supplied fields as specified in the fields parameter
- -->
- <method name="Query">
- <arg type="i" name="live_query_id" direction="in" />
- <arg type="s" name="service" direction="in" />
- <arg type="as" name="fields" direction="in" />
- <arg type="s" name="search_text" direction="in" />
- <arg type="s" name="keyword" direction="in" />
- <arg type="s" name="query_condition" direction="in" />
- <arg type="b" name="sort_by_service" direction="in" />
- <arg type="i" name="offset" direction="in" />
- <arg type="i" name="max_hits" direction="in" />
- <arg type="aas" name="result" direction="out" />
- </method>
-*/
- dbus_error_init (&dbus_error);
- if (!dbus_message_get_args (rec->message, NULL,
- DBUS_TYPE_INT32, &query_id,
- DBUS_TYPE_STRING, &service,
- DBUS_TYPE_ARRAY, DBUS_TYPE_STRING, &fields, &row_count,
- DBUS_TYPE_STRING, &search_text,
- DBUS_TYPE_STRING, &keyword,
- DBUS_TYPE_STRING, &query,
- DBUS_TYPE_BOOLEAN, &sort_results,
- DBUS_TYPE_INT32, &offset,
- DBUS_TYPE_INT32, &limit,
- DBUS_TYPE_INVALID)) {
- tracker_set_error (rec, "DBusError: %s;%s", dbus_error.name, dbus_error.message);
- dbus_error_free (&dbus_error);
- return;
- }
+ return TRUE;
+}
+gboolean
+tracker_dbus_search_query (TrackerDBusSearch *object,
+ gint live_query_id,
+ const gchar *service,
+ gchar **fields,
+ const gchar *search_text,
+ const gchar *keyword,
+ const gchar *query_condition,
+ gboolean sort_by_service,
+ gint offset,
+ gint max_hits,
+ GPtrArray **values,
+ GError **error)
+{
+ TrackerDBusSearchPriv *priv;
+ TrackerDBResultSet *result_set;
+ guint request_id;
+ DBConnection *db_con;
+
+ request_id = tracker_dbus_get_next_request_id ();
+
+ tracker_dbus_return_val_if_fail (service != NULL, FALSE, error);
+ tracker_dbus_return_val_if_fail (fields != NULL, FALSE, error);
+ tracker_dbus_return_val_if_fail (search_text != NULL, FALSE, error);
+ tracker_dbus_return_val_if_fail (keyword != NULL, FALSE, error);
+ tracker_dbus_return_val_if_fail (query_condition != NULL, FALSE, error);
+ tracker_dbus_return_val_if_fail (values != NULL, FALSE, error);
+
+ priv = GET_PRIV (object);
+
+ db_con = priv->db_con;
+
+ tracker_dbus_request_new (request_id,
+ "DBus request to search query, "
+ "query id:%d, service:'%s', search text '%s', "
+ "keyword:'%s', query condition:'%s', offset:%d, "
+ "max hits:%d, sort by service:'%s'",
+ live_query_id,
+ service,
+ search_text,
+ keyword,
+ query_condition,
+ offset,
+ max_hits,
+ sort_by_service ? "yes" : "no");
+
if (!tracker_service_manager_is_valid_service (service)) {
- tracker_set_error (rec, "Invalid service %s or service has not been implemented yet", service);
- return;
- }
-
- if (limit < 1) {
- limit = 1024;
+ tracker_dbus_request_failed (request_id,
+ error,
+ "Service '%s' is invalid or has not been implemented yet",
+ service);
+ return FALSE;
}
result_set = NULL;
- if (query) {
- gchar *str;
- GError *error = NULL;
-
- tracker_log ("executing rdf query %s\n with search term %s and keyword %s", query, search_text, keyword);
-
- str = tracker_rdf_query_to_sql (db_con, query, service, fields, row_count, search_text, keyword, sort_results, offset, limit, error);
-
- if (error || !str) {
- if (error) {
- tracker_set_error (rec, "Invalid rdf query produced following error: %s", error->message);
- g_error_free (error);
- } else {
- tracker_set_error (rec, "Invalid rdf query");
- }
- return;
+ if (query_condition) {
+ GError *query_error = NULL;
+ gchar *query_translated;
+
+ tracker_dbus_request_comment (request_id,
+ "Executing RDF query:'%s' with search "
+ "term:'%s' and keyword:'%s'",
+ query_condition,
+ search_text,
+ keyword);
+
+ query_translated = tracker_rdf_query_to_sql (db_con,
+ query_condition,
+ service,
+ fields,
+ g_strv_length (fields),
+ search_text,
+ keyword,
+ sort_by_service,
+ offset,
+ dbus_search_sanity_check_max_hits (max_hits),
+ query_error);
+
+ if (query_error) {
+ tracker_dbus_request_failed (request_id,
+ error,
+ "Invalid rdf query produced following error: %s",
+ query_error->message);
+ g_error_free (query_error);
+
+ return FALSE;
+ } else if (!query_translated) {
+ tracker_dbus_request_failed (request_id,
+ error,
+ "Invalid rdf query, no error given");
+ return FALSE;
}
- /*if (!str) {
- g_free (search_term);
- reply = dbus_message_new_method_return (rec->message);
- dbus_message_iter_init_append (reply, &iter);
-
- dbus_message_iter_open_container (&iter,
- DBUS_TYPE_ARRAY,
- DBUS_DICT_ENTRY_BEGIN_CHAR_AS_STRING
- DBUS_TYPE_STRING_AS_STRING
- DBUS_TYPE_VARIANT_AS_STRING
- DBUS_DICT_ENTRY_END_CHAR_AS_STRING,
- &iter_dict);
- dbus_message_iter_close_container (&iter, &iter_dict);
-
- dbus_connection_send (rec->connection, reply, NULL);
- dbus_message_unref (reply);
- g_return_if_fail (str);
- }*/
+ tracker_dbus_request_comment (request_id,
+ "Translated RDF query:'%s'",
+ query_translated);
- tracker_log ("translated rdf query is \n%s\n", str);
db_con = tracker_db_get_service_connection (db_con, service);
+
if (!tracker_is_empty_string (search_text)) {
- tracker_db_search_text (db_con, service, search_text, 0, 999999, TRUE, FALSE);
+ tracker_db_search_text (db_con,
+ service,
+ search_text,
+ 0,
+ 999999,
+ TRUE,
+ FALSE);
}
- result_set = tracker_db_interface_execute_query (db_con->db, str);
+ result_set = tracker_db_interface_execute_query (db_con->db, query_translated);
+ g_free (query_translated);
+ }
- g_free (str);
+ *values = tracker_dbus_query_result_to_ptr_array (result_set);
- } else {
- return;
+ if (result_set) {
+ g_object_unref (result_set);
}
- tracker_dbus_reply_with_query_result (rec, result_set);
+ tracker_dbus_request_success (request_id);
- g_object_unref (result_set);
+ return TRUE;
}
-
-
-
-void
-tracker_dbus_method_search_suggest (DBusRec *rec)
+gboolean
+tracker_dbus_search_suggest (TrackerDBusSearch *object,
+ const gchar *search_text,
+ gint max_dist,
+ gchar **value,
+ GError **error)
{
- DBusError dbus_error;
- DBusMessage *reply;
- gchar *term;
- gint maxdist;
- gchar *winner_str;
-
- /*
- <method name="Suggest">
- <arg type="s" name="search_text" direction="in" />
- <arg type="i" name="maxdist" direction="in" />
- <arg type="s" name="result" direction="out" />
- </method>
- */
-
- dbus_error_init (&dbus_error);
- if (!dbus_message_get_args (rec->message, NULL,
- DBUS_TYPE_STRING, &term,
- DBUS_TYPE_INT32, &maxdist,
- DBUS_TYPE_INVALID)) {
- tracker_set_error (rec, "DBusError: %s;%s", dbus_error.name, dbus_error.message);
- dbus_error_free (&dbus_error);
- return;
- }
-
- Indexer *index = tracker->file_index;
-
- winner_str = tracker_indexer_get_suggestion (index, term, maxdist);
-
- if (!winner_str) {
- tracker_set_error (rec, "Possible data error in index. Aborting tracker_dbus_method_search_suggest.");
- return;
- }
-
- tracker_log ("Suggested spelling for %s is %s.", term, winner_str);
+ TrackerDBusSearchPriv *priv;
+ guint request_id;
- reply = dbus_message_new_method_return (rec->message);
+ request_id = tracker_dbus_get_next_request_id ();
- dbus_message_append_args (reply,
- DBUS_TYPE_STRING, &winner_str,
- DBUS_TYPE_INVALID);
- free (winner_str);
+ tracker_dbus_return_val_if_fail (search_text != NULL, FALSE, error);
+ tracker_dbus_return_val_if_fail (value != NULL, FALSE, error);
- dbus_connection_send (rec->connection, reply, NULL);
+ priv = GET_PRIV (object);
+
+ tracker_dbus_request_new (request_id,
+ "DBus request to for suggested words, "
+ "term:'%s', max dist:%d",
+ search_text,
+ max_dist);
+
+ *value = tracker_indexer_get_suggestion (priv->file_index, search_text, max_dist);
+
+ if (!(*value)) {
+ tracker_dbus_request_failed (request_id,
+ error,
+ "Possible data error in index, no suggestions given for '%s'",
+ search_text);
+ return FALSE;
+ }
+
+ tracker_dbus_request_comment (request_id,
+ "Suggested spelling for '%s' is '%s'",
+ search_text, *value);
- dbus_message_unref (reply);
+ return TRUE;
}
Modified: branches/indexer-split/src/trackerd/tracker-dbus-search.h
==============================================================================
--- branches/indexer-split/src/trackerd/tracker-dbus-search.h (original)
+++ branches/indexer-split/src/trackerd/tracker-dbus-search.h Mon Apr 21 11:21:20 2008
@@ -1,5 +1,7 @@
-/* Tracker - indexer and metadata database engine
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
+/*
* Copyright (C) 2006, Mr Jamie McCracken (jamiemcc gnome org)
+ * Copyright (C) 2008, Nokia
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public
@@ -17,20 +19,121 @@
* Boston, MA 02110-1301, USA.
*/
+#ifndef __TRACKER_DBUS_SEARCH_H__
+#define __TRACKER_DBUS_SEARCH_H__
-#ifndef _TRACKER_DBUS_SEARCH_H_
-#define _TRACKER_DBUS_SEARCH_H_
+#include <dbus/dbus-glib.h>
+#include <dbus/dbus-glib-bindings.h>
+#include <dbus/dbus-glib-lowlevel.h>
-#include "tracker-dbus.h"
-void tracker_dbus_method_search_get_hit_count (DBusRec *rec);
-void tracker_dbus_method_search_get_hit_count_all (DBusRec *rec);
-void tracker_dbus_method_search_text (DBusRec *rec);
-void tracker_dbus_method_search_text_detailed (DBusRec *rec);
-void tracker_dbus_method_search_get_snippet (DBusRec *rec);
-void tracker_dbus_method_search_files_by_text (DBusRec *rec);
-void tracker_dbus_method_search_metadata (DBusRec *rec);
-void tracker_dbus_method_search_matching_fields (DBusRec *rec);
-void tracker_dbus_method_search_query (DBusRec *rec);
-void tracker_dbus_method_search_suggest (DBusRec *rec);
+#include "tracker-db-sqlite.h"
+#include "tracker-indexer.h"
-#endif
+#define TRACKER_DBUS_SEARCH_SERVICE "org.freedesktop.Tracker"
+#define TRACKER_DBUS_SEARCH_PATH "/org/freedesktop/Tracker/Search"
+#define TRACKER_DBUS_SEARCH_INTERFACE "org.freedesktop.Tracker.Search"
+
+G_BEGIN_DECLS
+
+#define TRACKER_TYPE_DBUS_SEARCH (tracker_dbus_search_get_type ())
+#define TRACKER_DBUS_SEARCH(object) (G_TYPE_CHECK_INSTANCE_CAST ((object), TRACKER_TYPE_DBUS_SEARCH, TrackerDBusSearch))
+#define TRACKER_DBUS_SEARCH_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), TRACKER_TYPE_DBUS_SEARCH, TrackerDBusSearchClass))
+#define TRACKER_IS_DBUS_SEARCH(object) (G_TYPE_CHECK_INSTANCE_TYPE ((object), TRACKER_TYPE_DBUS_SEARCH))
+#define TRACKER_IS_DBUS_SEARCH_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), TRACKER_TYPE_DBUS_SEARCH))
+#define TRACKER_DBUS_SEARCH_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), TRACKER_TYPE_DBUS_SEARCH, TrackerDBusSearchClass))
+
+typedef struct TrackerDBusSearch TrackerDBusSearch;
+typedef struct TrackerDBusSearchClass TrackerDBusSearchClass;
+
+struct TrackerDBusSearch {
+ GObject parent;
+};
+
+struct TrackerDBusSearchClass {
+ GObjectClass parent;
+};
+
+GType tracker_dbus_search_get_type (void);
+
+TrackerDBusSearch *
+ tracker_dbus_search_new (DBConnection *db_con);
+void tracker_dbus_search_set_db_connection (TrackerDBusSearch *object,
+ DBConnection *db_con);
+void tracker_dbus_search_set_file_index (TrackerDBusSearch *object,
+ Indexer *file_index);
+void tracker_dbus_search_set_email_index (TrackerDBusSearch *object,
+ Indexer *email_index);
+gboolean tracker_dbus_search_get_hit_count (TrackerDBusSearch *object,
+ const gchar *service,
+ const gchar *search_text,
+ gint *result,
+ GError **error);
+gboolean tracker_dbus_search_get_hit_count_all (TrackerDBusSearch *object,
+ const gchar *search_text,
+ GPtrArray **values,
+ GError **error);
+gboolean tracker_dbus_search_text (TrackerDBusSearch *object,
+ gint live_query_id,
+ const gchar *service,
+ const gchar *search_text,
+ gint offset,
+ gint max_hits,
+ gchar ***values,
+ GError **error);
+gboolean tracker_dbus_search_text_detailed (TrackerDBusSearch *object,
+ gint live_query_id,
+ const gchar *service,
+ const gchar *search_text,
+ gint offset,
+ gint max_hits,
+ GPtrArray **values,
+ GError **error);
+gboolean tracker_dbus_search_get_snippet (TrackerDBusSearch *object,
+ const gchar *service,
+ const gchar *id,
+ const gchar *search_text,
+ gchar **result,
+ GError **error);
+gboolean tracker_dbus_search_files_by_text (TrackerDBusSearch *object,
+ gint live_query_id,
+ const gchar *search_text,
+ gint offset,
+ gint max_hits,
+ gboolean group_results,
+ GHashTable **values,
+ GError **error);
+gboolean tracker_dbus_search_metadata (TrackerDBusSearch *object,
+ const gchar *service,
+ const gchar *field,
+ const gchar *search_text,
+ gint offset,
+ gint max_hits,
+ gchar ***values,
+ GError **error);
+gboolean tracker_dbus_search_matching_fields (TrackerDBusSearch *object,
+ const gchar *service,
+ const gchar *id,
+ const gchar *search_text,
+ GHashTable **values,
+ GError **error);
+gboolean tracker_dbus_search_query (TrackerDBusSearch *object,
+ gint live_query_id,
+ const gchar *service,
+ gchar **fields,
+ const gchar *search_text,
+ const gchar *keyword,
+ const gchar *query_condition,
+ gboolean sort_by_service,
+ gint offset,
+ gint max_hits,
+ GPtrArray **values,
+ GError **error);
+gboolean tracker_dbus_search_suggest (TrackerDBusSearch *object,
+ const gchar *search_text,
+ gint max_dist,
+ gchar **value,
+ GError **error);
+
+G_END_DECLS
+
+#endif /* __TRACKER_DBUS_SEARCH_H__ */
Modified: branches/indexer-split/src/trackerd/tracker-dbus.c
==============================================================================
--- branches/indexer-split/src/trackerd/tracker-dbus.c (original)
+++ branches/indexer-split/src/trackerd/tracker-dbus.c Mon Apr 21 11:21:20 2008
@@ -1,5 +1,7 @@
-/* Tracker - indexer and metadata database engine
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
+/*
* Copyright (C) 2006, Mr Jamie McCracken (jamiemcc gnome org)
+ * Copyright (C) 2008, Nokia
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public
@@ -22,643 +24,482 @@
#include <libtracker-common/tracker-log.h>
#include <libtracker-common/tracker-config.h>
+#include <libtracker-common/tracker-utils.h>
+#include "tracker-db-sqlite.h"
#include "tracker-dbus.h"
+#include "tracker-dbus-daemon.h"
+#include "tracker-dbus-daemon-glue.h"
+#include "tracker-dbus-files.h"
+#include "tracker-dbus-files-glue.h"
+#include "tracker-dbus-keywords.h"
+#include "tracker-dbus-keywords-glue.h"
+#include "tracker-dbus-metadata.h"
+#include "tracker-dbus-metadata-glue.h"
+#include "tracker-dbus-search.h"
+#include "tracker-dbus-search-glue.h"
#include "tracker-utils.h"
#include "tracker-watch.h"
-extern Tracker *tracker;
+static GSList *objects;
-
-static void unregistered_func (DBusConnection *conn, gpointer data);
-
-static DBusHandlerResult message_func (DBusConnection *conn, DBusMessage *message, gpointer data);
-
-static DBusObjectPathVTable tracker_vtable = {
- unregistered_func,
- message_func,
- NULL,
- NULL,
- NULL,
- NULL
-};
-
-DBusConnection *
-tracker_dbus_init (void)
+gboolean
+static dbus_register_service (DBusGProxy *proxy,
+ const gchar *name)
{
- DBusError error;
- DBusConnection *connection;
- int ret;
+ GError *error = NULL;
+ guint result;
- dbus_error_init (&error);
+ tracker_log ("Registering DBus service...\n"
+ " Name '%s'",
+ name);
+
+ if (!org_freedesktop_DBus_request_name (proxy,
+ name,
+ DBUS_NAME_FLAG_DO_NOT_QUEUE,
+ &result, &error)) {
+ tracker_error ("Could not aquire name: %s, %s",
+ name,
+ error ? error->message : "no error given");
- connection = dbus_bus_get (DBUS_BUS_SESSION, &error);
-
- if ((connection == NULL) || dbus_error_is_set (&error)) {
- if (dbus_error_is_set (&error)) {
- tracker_error ("DBUS ERROR: %s occurred with message %s", error.name, error.message);
- dbus_error_free (&error);
+ g_error_free (error);
+ return FALSE;
}
- tracker_error ("ERROR: could not get the dbus session bus - exiting");
- exit (EXIT_FAILURE);
-
+ if (result != DBUS_REQUEST_NAME_REPLY_PRIMARY_OWNER) {
+ tracker_error ("DBus service name %s is already taken, "
+ "perhaps the daemon is already running?",
+ name);
+ return FALSE;
}
- dbus_connection_setup_with_g_main (connection, NULL);
-
- dbus_error_init (&error);
-
- ret = dbus_bus_request_name (connection,
- TRACKER_DBUS_SERVICE,
- DBUS_NAME_FLAG_DO_NOT_QUEUE,
- &error);
-
- if (dbus_error_is_set (&error)) {
- tracker_error ("ERROR: could not acquire service name due to '%s'", error.message);
- exit (EXIT_FAILURE);
- }
+ return TRUE;
+}
- if (ret != DBUS_REQUEST_NAME_REPLY_PRIMARY_OWNER) {
- tracker_error ("ERROR: trackerd already running on your session dbus - exiting...");
- exit (EXIT_FAILURE);
- }
+static gpointer
+dbus_register_object (DBusGConnection *connection,
+ DBusGProxy *proxy,
+ GType object_type,
+ const DBusGObjectInfo *info,
+ const gchar *path)
+{
+ GObject *object;
- if (!dbus_connection_register_object_path (connection,
- TRACKER_OBJECT,
- &tracker_vtable,
- NULL)) {
- tracker_error ("ERROR: could not register D-BUS handlers");
- connection = NULL;
- }
+ tracker_log ("Registering DBus object...");
+ tracker_log (" Path '%s'", path);
+ tracker_log (" Type '%s'", g_type_name (object_type));
+ object = g_object_new (object_type, NULL);
- if (connection != NULL) {
- dbus_connection_set_exit_on_disconnect (connection, FALSE);
- }
+ dbus_g_object_type_install_info (object_type, info);
+ dbus_g_connection_register_g_object (connection, path, object);
- return connection;
+ return object;
}
-
-void
-tracker_dbus_shutdown (DBusConnection *conn)
+static GValue *
+tracker_dbus_g_value_slice_new (GType type)
{
- if (!conn) {
- return;
- }
+ GValue *value;
- dbus_connection_close (conn);
- dbus_connection_unref (conn);
-}
+ value = g_slice_new0 (GValue);
+ g_value_init (value, type);
+ return value;
+}
-void
-tracker_dbus_send_index_status_change_signal ()
+static void
+tracker_dbus_g_value_slice_free (GValue *value)
{
- DBusMessage *msg;
- dbus_uint32_t serial = 0;
- gchar *status;
- gboolean battery_pause;
- gboolean enable_indexing;
-
- msg = dbus_message_new_signal (TRACKER_OBJECT,
- TRACKER_INTERFACE,
- TRACKER_SIGNAL_INDEX_STATUS_CHANGE);
-
- if (!msg || !tracker->dbus_con) {
- return;
- }
-
- status = tracker_get_status ();
- battery_pause = tracker_pause_on_battery ();
-
- enable_indexing = tracker_config_get_enable_indexing (tracker->config);
-
- /*
- <signal name="IndexStateChange">
- <arg type="s" name="state" />
- <arg type="b" name="initial_index" />
- <arg type="b" name="in_merge" />
- <arg type="b" name="is_manual_paused" />
- <arg type="b" name="is_battery_paused" />
- <arg type="b" name="is_io_paused" />
- <arg type="b" name="is_indexing_enabled" />
- </signal>
- */
-
- dbus_message_append_args (msg,
- DBUS_TYPE_STRING, &status,
- DBUS_TYPE_BOOLEAN, &tracker->first_time_index,
- DBUS_TYPE_BOOLEAN, &tracker->in_merge,
- DBUS_TYPE_BOOLEAN, &tracker->pause_manual,
- DBUS_TYPE_BOOLEAN, &battery_pause,
- DBUS_TYPE_BOOLEAN, &tracker->pause_io,
- DBUS_TYPE_BOOLEAN, &enable_indexing,
- DBUS_TYPE_INVALID);
-
- g_free (status);
-
- dbus_message_set_no_reply (msg, TRUE);
-
- if (!dbus_connection_send (tracker->dbus_con, msg, &serial)) {
- tracker_error ("Raising the index status changed signal failed");
- return;
- }
+ g_value_unset (value);
+ g_slice_free (GValue, value);
+}
- dbus_connection_flush (tracker->dbus_con);
+gboolean
+tracker_dbus_init (gpointer tracker_pointer)
+{
+ Tracker *tracker;
+ DBusGConnection *connection;
+ DBusGProxy *proxy;
+ GObject *object;
+ GError *error = NULL;
+
+ g_return_val_if_fail (tracker_pointer != NULL, FALSE);
+
+ tracker = (Tracker*) tracker_pointer;
+
+ connection = dbus_g_bus_get (DBUS_BUS_SESSION, &error);
+
+ if (!connection) {
+ tracker_error ("Could not connect to the DBus session bus, %s",
+ error ? error->message : "no error given.");
+ return FALSE;
+ }
+
+ /* Don't reinitialize */
+ if (objects) {
+ return TRUE;
+ }
+
+ /* The definitions below (DBUS_SERVICE_DBUS, etc) are
+ * predefined for us to just use.
+ */
+ proxy = dbus_g_proxy_new_for_name (connection,
+ DBUS_SERVICE_DBUS,
+ DBUS_PATH_DBUS,
+ DBUS_INTERFACE_DBUS);
+
+ /* Set up the main tracker service */
+ if (!dbus_register_service (proxy, TRACKER_DBUS_DAEMON_SERVICE)) {
+ return FALSE;
+ }
+
+ /* Add org.freedesktop.Tracker */
+ if (!(object = dbus_register_object (connection,
+ proxy,
+ TRACKER_TYPE_DBUS_DAEMON,
+ &dbus_glib_tracker_dbus_daemon_object_info,
+ TRACKER_DBUS_DAEMON_PATH))) {
+ return FALSE;
+ }
+
+ g_object_set (object, "db-connection", tracker->index_db, NULL);
+ g_object_set (object, "config", tracker->config, NULL);
+ g_object_set (object, "tracker", tracker, NULL);
+ objects = g_slist_prepend (objects, object);
+
+ /* Add org.freedesktop.Tracker.Files */
+ if (!(object = dbus_register_object (connection,
+ proxy,
+ TRACKER_TYPE_DBUS_FILES,
+ &dbus_glib_tracker_dbus_files_object_info,
+ TRACKER_DBUS_FILES_PATH))) {
+ return FALSE;
+ }
+
+ g_object_set (object, "db-connection", tracker->index_db, NULL);
+ objects = g_slist_prepend (objects, object);
+
+ /* Add org.freedesktop.Tracker.Keywords */
+ if (!(object = dbus_register_object (connection,
+ proxy,
+ TRACKER_TYPE_DBUS_KEYWORDS,
+ &dbus_glib_tracker_dbus_keywords_object_info,
+ TRACKER_DBUS_KEYWORDS_PATH))) {
+ return FALSE;
+ }
+
+ g_object_set (object, "db-connection", tracker->index_db, NULL);
+ objects = g_slist_prepend (objects, object);
+
+ /* Add org.freedesktop.Tracker.Metadata */
+ if (!(object = dbus_register_object (connection,
+ proxy,
+ TRACKER_TYPE_DBUS_METADATA,
+ &dbus_glib_tracker_dbus_metadata_object_info,
+ TRACKER_DBUS_METADATA_PATH))) {
+ return FALSE;
+ }
+
+ g_object_set (object, "db-connection", tracker->index_db, NULL);
+ objects = g_slist_prepend (objects, object);
+
+ /* Add org.freedesktop.Tracker.Search */
+ if (!(object = dbus_register_object (connection,
+ proxy,
+ TRACKER_TYPE_DBUS_SEARCH,
+ &dbus_glib_tracker_dbus_search_object_info,
+ TRACKER_DBUS_SEARCH_PATH))) {
+ return FALSE;
+ }
+
+ g_object_set (object, "db-connection", tracker->index_db, NULL);
+ g_object_set (object, "file-index", tracker->file_index, NULL);
+ g_object_set (object, "email-index", tracker->email_index, NULL);
+ objects = g_slist_prepend (objects, object);
- dbus_message_unref (msg);
+ /* Reverse list since we added objects at the top each time */
+ objects = g_slist_reverse (objects);
+ /* Clean up */
+ g_object_unref (proxy);
+ return TRUE;
}
void
-tracker_dbus_send_index_progress_signal (const char *service, const char *uri)
+tracker_dbus_shutdown (void)
{
- DBusMessage *msg;
- dbus_uint32_t serial = 0;
- int count, processed;
-
- msg = dbus_message_new_signal (TRACKER_OBJECT,
- TRACKER_INTERFACE,
- TRACKER_SIGNAL_INDEX_PROGRESS);
-
- if (!msg || !tracker->dbus_con) {
+ if (!objects) {
return;
}
+ g_slist_foreach (objects, (GFunc) g_object_unref, NULL);
+ g_slist_free (objects);
+ objects = NULL;
+}
- if (strcmp (service, "Emails") == 0) {
- count = tracker->mbox_count;
- processed = tracker->mbox_processed;
-
- } else if (strcmp (service, "Merging") == 0) {
+guint
+tracker_dbus_get_next_request_id (void)
+{
+ static guint request_id = 1;
- count = tracker->merge_count;
- processed = tracker->merge_processed;
+ return request_id++;
+}
- } else {
+GObject *
+tracker_dbus_get_object (GType type)
+{
+ GSList *l;
- count = tracker->folders_count;
- processed = tracker->folders_processed;
+ for (l = objects; l; l = l->next) {
+ if (G_OBJECT_TYPE (l->data) == type) {
+ return l->data;
}
-
-
- /*
-
- <signal name="IndexProgress">
- <arg type="s" name="service"/>
- <arg type="s" name="current_uri" />
- <arg type="i" name="index_count"/>
- <arg type="i" name="folders_processed"/>
- <arg type="i" name="folders_total"/>
- </signal>
- */
-
- dbus_message_append_args (msg,
- DBUS_TYPE_STRING, &service,
- DBUS_TYPE_STRING, &uri,
- DBUS_TYPE_INT32, &tracker->index_count,
- DBUS_TYPE_INT32, &processed,
- DBUS_TYPE_INT32, &count,
- DBUS_TYPE_INVALID);
-
- dbus_message_set_no_reply (msg, TRUE);
-
- if (!dbus_connection_send (tracker->dbus_con, msg, &serial)) {
- tracker_error ("Raising the index status changed signal failed");
- return;
}
- dbus_connection_flush (tracker->dbus_con);
-
- dbus_message_unref (msg);
-
+ return NULL;
+}
+GQuark
+tracker_dbus_error_quark (void)
+{
+ return g_quark_from_static_string (TRACKER_DBUS_ERROR_DOMAIN);
}
+TrackerDBusData *
+tracker_dbus_data_new (const gpointer arg1,
+ const gpointer arg2)
+{
+ TrackerDBusData *data;
+ data = g_new0 (TrackerDBusData, 1);
+ data->id = tracker_dbus_get_next_request_id ();
+ data->data1 = arg1;
+ data->data2 = arg2;
+ return data;
+}
-void
-tracker_dbus_send_index_finished_signal ()
+gchar **
+tracker_dbus_slist_to_strv (GSList *list)
{
- DBusMessage *msg;
- dbus_uint32_t serial = 0;
- int i = time (NULL) - tracker->index_time_start;
-
- msg = dbus_message_new_signal (TRACKER_OBJECT,
- TRACKER_INTERFACE,
- TRACKER_SIGNAL_INDEX_FINISHED);
-
- if (!msg || !tracker->dbus_con) {
- return;
- }
-
- /*
- <signal name="IndexFinished">
- <arg type="i" name="time_taken"/>
- </signal>
- */
-
- dbus_message_append_args (msg,
- DBUS_TYPE_INT32, &i,
- DBUS_TYPE_INVALID);
+ GSList *l;
+ gchar **strv;
+ gint i = 0;
- dbus_message_set_no_reply (msg, TRUE);
-
- if (!dbus_connection_send (tracker->dbus_con, msg, &serial)) {
- tracker_error ("Raising the index status changed signal failed");
- return;
+ strv = g_new0 (gchar*, g_slist_length (list) + 1);
+
+ for (l = list; l != NULL; l = l->next) {
+ strv[i++] = g_strdup (l->data);
}
- dbus_connection_flush (tracker->dbus_con);
-
- dbus_message_unref (msg);
-
+ strv[i] = NULL;
+ return strv;
}
-
-static void
-unregistered_func (DBusConnection *conn,
- gpointer data)
-{
-}
-
-
-static DBusHandlerResult
-message_func (DBusConnection *conn,
- DBusMessage *message,
- gpointer data)
+gchar **
+tracker_dbus_query_result_to_strv (TrackerDBResultSet *result_set,
+ gint *count)
{
- DBusRec *rec;
-
- rec = g_new (DBusRec, 1);
- rec->connection = conn;
- rec->message = message;
-
- if (!tracker->is_running) {
- dbus_message_ref (message);
- rec->action = DBUS_ACTION_NONE;
-
- return DBUS_HANDLER_RESULT_HANDLED;
- }
-
- /* process shutdown calls in this thread */
- if (dbus_message_is_method_call (message,
- TRACKER_INTERFACE,
- TRACKER_METHOD_SHUTDOWN)) {
-
- DBusMessage *reply;
- DBusError dbus_error;
- gboolean reindex = FALSE;
-
- if (!dbus_message_get_args (message, NULL, DBUS_TYPE_BOOLEAN, &reindex, DBUS_TYPE_INVALID)) {
- //tracker_set_error (rec, "DBusError: %s;%s", dbus_error.name, dbus_error.message);
- dbus_error_free (&dbus_error);
- return 0;
- }
+ gchar **strv = NULL;
+ gint rows = 0;
- tracker_log ("attempting restart");
+ if (result_set) {
+ gboolean valid = TRUE;
+ gint i = 0;
- tracker->reindex = reindex;
+ rows = tracker_db_result_set_get_n_rows (result_set);
+ strv = g_new (gchar*, rows);
- tracker->is_running = FALSE;
- tracker_end_watching ();
-
- g_timeout_add_full (G_PRIORITY_LOW,
- 1,
- (GSourceFunc) tracker_do_cleanup,
- g_strdup ("dbus shutdown"), NULL
- );
-
-
- reply = dbus_message_new_method_return (message);
-
- dbus_connection_send (conn, reply, NULL);
-
- dbus_message_unref (reply);
-
- return DBUS_HANDLER_RESULT_HANDLED;
-
+ while (valid) {
+ tracker_db_result_set_get (result_set, 0, &strv[i], -1);
+ valid = tracker_db_result_set_iter_next (result_set);
+ i++;
+ }
}
-
-
-
- if (dbus_message_is_method_call (message, TRACKER_INTERFACE, TRACKER_METHOD_PING)) {
- /* ref the message here because we are going to reply to it in a different thread */
- dbus_message_ref (message);
- rec->action = DBUS_ACTION_PING;
-
-
- } else if (dbus_message_is_method_call (message, TRACKER_INTERFACE, TRACKER_METHOD_GET_STATS)) {
-
- dbus_message_ref (message);
- rec->action = DBUS_ACTION_GET_STATS;
-
-
- } else if (dbus_message_is_method_call (message, TRACKER_INTERFACE, TRACKER_METHOD_GET_SERVICES)) {
-
- dbus_message_ref (message);
- rec->action = DBUS_ACTION_GET_SERVICES;
-
-
- } else if (dbus_message_is_method_call (message, TRACKER_INTERFACE, TRACKER_METHOD_GET_VERSION)) {
-
- dbus_message_ref (message);
- rec->action = DBUS_ACTION_GET_VERSION;
-
-
- } else if (dbus_message_is_method_call (message, TRACKER_INTERFACE, TRACKER_METHOD_GET_STATUS)) {
-
- dbus_message_ref (message);
- rec->action = DBUS_ACTION_GET_STATUS;
-
-
- } else if (dbus_message_is_method_call (message, TRACKER_INTERFACE, TRACKER_METHOD_SET_BOOL_OPTION)) {
-
- dbus_message_ref (message);
- rec->action = DBUS_ACTION_SET_BOOL_OPTION;
-
-
- } else if (dbus_message_is_method_call (message, TRACKER_INTERFACE, TRACKER_METHOD_SET_INT_OPTION)) {
-
- dbus_message_ref (message);
- rec->action = DBUS_ACTION_SET_INT_OPTION;
-
- } else if (dbus_message_is_method_call (message, TRACKER_INTERFACE, TRACKER_METHOD_SHUTDOWN)) {
-
- dbus_message_ref (message);
- rec->action = DBUS_ACTION_SHUTDOWN;
-
- } else if (dbus_message_is_method_call (message, TRACKER_INTERFACE, TRACKER_METHOD_PROMPT_INDEX_SIGNALS)) {
-
- dbus_message_ref (message);
- rec->action = DBUS_ACTION_PROMPT_INDEX_SIGNALS;
-
- } else if (dbus_message_is_method_call (message, TRACKER_INTERFACE_METADATA, TRACKER_METHOD_METADATA_GET)) {
-
- dbus_message_ref (message);
- rec->action = DBUS_ACTION_METADATA_GET;
-
-
- } else if (dbus_message_is_method_call (message, TRACKER_INTERFACE_METADATA, TRACKER_METHOD_METADATA_SET)) {
-
- dbus_message_ref (message);
- rec->action = DBUS_ACTION_METADATA_SET;
-
-
- } else if (dbus_message_is_method_call (message, TRACKER_INTERFACE_METADATA, TRACKER_METHOD_METADATA_REGISTER_TYPE)) {
-
- dbus_message_ref (message);
- rec->action = DBUS_ACTION_METADATA_REGISTER_TYPE;
-
-
- } else if (dbus_message_is_method_call (message, TRACKER_INTERFACE_METADATA, TRACKER_METHOD_METADATA_GET_TYPE_DETAILS )) {
-
- dbus_message_ref (message);
- rec->action = DBUS_ACTION_METADATA_GET_TYPE_DETAILS;
-
-
- } else if (dbus_message_is_method_call (message, TRACKER_INTERFACE_METADATA, TRACKER_METHOD_METADATA_GET_REGISTERED_TYPES)) {
-
- dbus_message_ref (message);
- rec->action = DBUS_ACTION_METADATA_GET_REGISTERED_TYPES;
-
-
-
- } else if (dbus_message_is_method_call (message, TRACKER_INTERFACE_METADATA, TRACKER_METHOD_METADATA_GET_WRITEABLE_TYPES)) {
-
- dbus_message_ref (message);
- rec->action = DBUS_ACTION_METADATA_GET_WRITEABLE_TYPES;
-
-
-
- } else if (dbus_message_is_method_call (message, TRACKER_INTERFACE_METADATA, TRACKER_METHOD_METADATA_GET_REGISTERED_CLASSES)) {
-
- dbus_message_ref (message);
- rec->action = DBUS_ACTION_METADATA_GET_REGISTERED_CLASSES;
-
-
-
- } else if (dbus_message_is_method_call (message, TRACKER_INTERFACE_KEYWORDS, TRACKER_METHOD_KEYWORDS_GET_LIST)) {
-
- dbus_message_ref (message);
- rec->action = DBUS_ACTION_KEYWORDS_GET_LIST;
-
-
-
- } else if (dbus_message_is_method_call (message, TRACKER_INTERFACE_KEYWORDS, TRACKER_METHOD_KEYWORDS_GET)) {
-
- dbus_message_ref (message);
- rec->action = DBUS_ACTION_KEYWORDS_GET;
-
-
-
- } else if (dbus_message_is_method_call (message, TRACKER_INTERFACE_KEYWORDS, TRACKER_METHOD_KEYWORDS_ADD)) {
-
- dbus_message_ref (message);
- rec->action = DBUS_ACTION_KEYWORDS_ADD;
-
-
- } else if (dbus_message_is_method_call (message, TRACKER_INTERFACE_KEYWORDS, TRACKER_METHOD_KEYWORDS_REMOVE)) {
-
- dbus_message_ref (message);
- rec->action = DBUS_ACTION_KEYWORDS_REMOVE;
-
-
- } else if (dbus_message_is_method_call (message, TRACKER_INTERFACE_KEYWORDS, TRACKER_METHOD_KEYWORDS_REMOVE_ALL)) {
-
- dbus_message_ref (message);
- rec->action = DBUS_ACTION_KEYWORDS_REMOVE_ALL;
-
-
- } else if (dbus_message_is_method_call (message, TRACKER_INTERFACE_KEYWORDS, TRACKER_METHOD_KEYWORDS_SEARCH)) {
-
- dbus_message_ref (message);
- rec->action = DBUS_ACTION_KEYWORDS_SEARCH;
-
-
-
-
- } else if (dbus_message_is_method_call (message, TRACKER_INTERFACE_SEARCH, TRACKER_METHOD_SEARCH_GET_HIT_COUNT)) {
-
- dbus_message_ref (message);
- rec->action = DBUS_ACTION_SEARCH_GET_HIT_COUNT;
-
-
- } else if (dbus_message_is_method_call (message, TRACKER_INTERFACE_SEARCH, TRACKER_METHOD_SEARCH_GET_HIT_COUNT_ALL)) {
-
- dbus_message_ref (message);
- rec->action = DBUS_ACTION_SEARCH_GET_HIT_COUNT_ALL;
-
-
- } else if (dbus_message_is_method_call (message, TRACKER_INTERFACE_SEARCH, TRACKER_METHOD_SEARCH_TEXT)) {
-
- dbus_message_ref (message);
- rec->action = DBUS_ACTION_SEARCH_TEXT;
-
- } else if (dbus_message_is_method_call (message, TRACKER_INTERFACE_SEARCH, TRACKER_METHOD_SEARCH_TEXT_DETAILED)) {
-
- dbus_message_ref (message);
- rec->action = DBUS_ACTION_SEARCH_TEXT_DETAILED;
-
-
- } else if (dbus_message_is_method_call (message, TRACKER_INTERFACE_SEARCH, TRACKER_METHOD_SEARCH_GET_SNIPPET)) {
-
- dbus_message_ref (message);
- rec->action = DBUS_ACTION_SEARCH_GET_SNIPPET;
-
-
-
-
- } else if (dbus_message_is_method_call (message, TRACKER_INTERFACE_SEARCH, TRACKER_METHOD_SEARCH_FILES_BY_TEXT )) {
-
- dbus_message_ref (message);
- rec->action = DBUS_ACTION_SEARCH_FILES_BY_TEXT;
-
-
-
- } else if (dbus_message_is_method_call (message, TRACKER_INTERFACE_SEARCH, TRACKER_METHOD_SEARCH_METADATA)) {
-
- dbus_message_ref (message);
- rec->action = DBUS_ACTION_SEARCH_METADATA;
-
-
-
- } else if (dbus_message_is_method_call (message, TRACKER_INTERFACE_SEARCH, TRACKER_METHOD_SEARCH_MATCHING_FIELDS)) {
-
- dbus_message_ref (message);
- rec->action = DBUS_ACTION_SEARCH_MATCHING_FIELDS;
-
-
-
- } else if (dbus_message_is_method_call (message, TRACKER_INTERFACE_SEARCH, TRACKER_METHOD_SEARCH_QUERY)) {
-
- dbus_message_ref (message);
- rec->action = DBUS_ACTION_SEARCH_QUERY;
-
-
-
- } else if (dbus_message_is_method_call (message, TRACKER_INTERFACE_SEARCH, TRACKER_METHOD_SEARCH_SUGGEST)) {
-
- dbus_message_ref (message);
- rec->action = DBUS_ACTION_SEARCH_SUGGEST;
-
-
-
-
- } else if (dbus_message_is_method_call (message, TRACKER_INTERFACE_FILES, TRACKER_METHOD_FILES_EXISTS)) {
-
- dbus_message_ref (message);
- rec->action = DBUS_ACTION_FILES_EXISTS;
-
-
- } else if (dbus_message_is_method_call (message, TRACKER_INTERFACE_FILES, TRACKER_METHOD_FILES_CREATE)) {
-
- dbus_message_ref (message);
- rec->action = DBUS_ACTION_FILES_CREATE;
-
-
-
- } else if (dbus_message_is_method_call (message, TRACKER_INTERFACE_FILES, TRACKER_METHOD_FILES_DELETE)) {
-
- dbus_message_ref (message);
- rec->action = DBUS_ACTION_FILES_DELETE;
-
-
- } else if (dbus_message_is_method_call (message, TRACKER_INTERFACE_FILES, TRACKER_METHOD_FILES_GET_SERVICE_TYPE)) {
-
- dbus_message_ref (message);
- rec->action = DBUS_ACTION_FILES_GET_SERVICE_TYPE;
-
-
- } else if (dbus_message_is_method_call (message, TRACKER_INTERFACE_FILES, TRACKER_METHOD_FILES_GET_TEXT_CONTENTS )) {
-
- dbus_message_ref (message);
- rec->action = DBUS_ACTION_FILES_GET_TEXT_CONTENTS ;
-
-
-
- } else if (dbus_message_is_method_call (message, TRACKER_INTERFACE_FILES, TRACKER_METHOD_FILES_SEARCH_TEXT_CONTENTS)) {
-
- dbus_message_ref (message);
- rec->action = DBUS_ACTION_FILES_SEARCH_TEXT_CONTENTS;
-
-
-
- } else if (dbus_message_is_method_call (message, TRACKER_INTERFACE_FILES, TRACKER_METHOD_FILES_GET_BY_SERVICE_TYPE)) {
-
- dbus_message_ref (message);
- rec->action = DBUS_ACTION_FILES_GET_BY_SERVICE_TYPE;
-
-
-
- } else if (dbus_message_is_method_call (message, TRACKER_INTERFACE_FILES, TRACKER_METHOD_FILES_GET_BY_MIME_TYPE)) {
-
- dbus_message_ref (message);
- rec->action = DBUS_ACTION_FILES_GET_BY_MIME_TYPE;
-
-
-
- } else if (dbus_message_is_method_call (message, TRACKER_INTERFACE_FILES, TRACKER_METHOD_FILES_GET_BY_MIME_TYPE_VFS)) {
-
- dbus_message_ref (message);
- rec->action = DBUS_ACTION_FILES_GET_BY_MIME_TYPE_VFS;
-
-
-
- } else if (dbus_message_is_method_call (message, TRACKER_INTERFACE_FILES, TRACKER_METHOD_FILES_REFRESH_METADATA)) {
-
- dbus_message_ref (message);
- rec->action = DBUS_ACTION_FILES_REFRESH_METADATA;
-
-
- } else if (dbus_message_is_method_call (message, TRACKER_INTERFACE_FILES, TRACKER_METHOD_FILES_GET_MTIME)) {
-
- dbus_message_ref (message);
- rec->action = DBUS_ACTION_FILES_GET_MTIME;
+ if (count) {
+ *count = rows;
+ }
+ return strv;
+}
- } else if (dbus_message_is_method_call (message, TRACKER_INTERFACE_FILES, TRACKER_METHOD_FILES_GET_METADATA_FOLDER_FILES)) {
+GHashTable *
+tracker_dbus_query_result_to_hash_table (TrackerDBResultSet *result_set)
+{
+ GHashTable *hash_table;
+ gint field_count;
+ gboolean valid = FALSE;
+
+ hash_table = g_hash_table_new_full (g_str_hash,
+ g_str_equal,
+ (GDestroyNotify) g_free,
+ (GDestroyNotify) tracker_dbus_g_value_slice_free);
+
+ if (result_set) {
+ valid = TRUE;
+ field_count = tracker_db_result_set_get_n_columns (result_set);
+ }
+
+ while (valid) {
+ GValue transform;
+ GValue *values;
+ gchar **p;
+ gint field_count;
+ gint i = 0;
+ gchar *key;
+ GSList *list = NULL;
+
+ g_value_init (&transform, G_TYPE_STRING);
+
+ tracker_db_result_set_get (result_set, 0, &key, -1);
+ values = tracker_dbus_g_value_slice_new (G_TYPE_STRV);
+
+ for (i = 1; i < field_count; i++) {
+ GValue value;
+ const gchar *str;
+
+ _tracker_db_result_set_get_value (result_set, i, &value);
+
+ if (g_value_transform (&value, &transform)) {
+ str = g_value_dup_string (&transform);
+ } else {
+ str = g_strdup ("");
+ }
- dbus_message_ref (message);
- rec->action = DBUS_ACTION_FILES_GET_METADATA_FOLDER_FILES;
+ list = g_slist_prepend (list, (gchar*) str);
+ }
+ list = g_slist_reverse (list);
+ p = tracker_dbus_slist_to_strv (list);
+ g_slist_free (list);
+ g_value_take_boxed (values, p);
+ g_hash_table_insert (hash_table, key, values);
+ valid = tracker_db_result_set_iter_next (result_set);
+ }
- } else if (dbus_message_is_method_call (message, TRACKER_INTERFACE_FILES, TRACKER_METHOD_FILES_SEARCH_BY_TEXT_MIME)) {
+ return hash_table;
+}
- dbus_message_ref (message);
- rec->action = DBUS_ACTION_FILES_SEARCH_BY_TEXT_MIME;
+GPtrArray *
+tracker_dbus_query_result_to_ptr_array (TrackerDBResultSet *result_set)
+{
+ GPtrArray *ptr_array;
+ gboolean valid = FALSE;
+ gint columns;
+ gint i;
+
+ ptr_array = g_ptr_array_new ();
+
+ if (result_set) {
+ valid = TRUE;
+ columns = tracker_db_result_set_get_n_columns (result_set);
+ }
+
+ while (valid) {
+ GSList *list = NULL;
+ GValue transform = { 0, };
+ gchar **p;
+
+ g_value_init (&transform, G_TYPE_STRING);
+
+ /* Append fields to the array */
+ for (i = 0; i < columns; i++) {
+ GValue value = { 0, };
+ const gchar *str;
+
+ _tracker_db_result_set_get_value (result_set, i, &value);
+
+ if (g_value_transform (&value, &transform)) {
+ str = g_value_dup_string (&transform);
+ } else {
+ str = g_strdup ("");
+ }
+ list = g_slist_prepend (list, (gchar*) str);
- } else if (dbus_message_is_method_call (message, TRACKER_INTERFACE_FILES, TRACKER_METHOD_FILES_SEARCH_BY_TEXT_MIME_LOCATION)) {
+ g_value_unset (&value);
+ g_value_reset (&transform);
+ }
+
+ list = g_slist_reverse (list);
+ p = tracker_dbus_slist_to_strv (list);
+ g_slist_free (list);
+ g_ptr_array_add (ptr_array, p);
- dbus_message_ref (message);
- rec->action = DBUS_ACTION_FILES_SEARCH_BY_TEXT_MIME_LOCATION;
+ valid = tracker_db_result_set_iter_next (result_set);
+ }
+ return ptr_array;
+}
- } else if (dbus_message_is_method_call (message, TRACKER_INTERFACE_FILES, TRACKER_METHOD_FILES_SEARCH_BY_TEXT_LOCATION)) {
+void
+tracker_dbus_request_new (gint request_id,
+ const gchar *format,
+ ...)
+{
+ gchar *str;
+ va_list args;
- dbus_message_ref (message);
- rec->action = DBUS_ACTION_FILES_SEARCH_BY_TEXT_LOCATION;
+ va_start (args, format);
+ str = g_strdup_vprintf (format, args);
+ va_end (args);
+
+ tracker_log ("<--- [%d] %s",
+ request_id,
+ str);
+ g_free (str);
+}
- } else {
- g_free (rec);
- return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
- }
+void
+tracker_dbus_request_success (gint request_id)
+{
+ tracker_log ("---> [%d] Success, no error given",
+ request_id);
+}
+void
+tracker_dbus_request_failed (gint request_id,
+ GError **error,
+ const gchar *format,
+ ...)
+{
+ gchar *str;
+ va_list args;
- g_async_queue_push (tracker->user_request_queue, rec);
+ va_start (args, format);
+ str = g_strdup_vprintf (format, args);
+ va_end (args);
+
+ g_set_error (error, TRACKER_DBUS_ERROR, 0, str);
+
+ tracker_log ("---> [%d] Failed, %s",
+ request_id,
+ str);
+ g_free (str);
+}
- tracker_notify_request_data_available ();
+void
+tracker_dbus_request_comment (gint request_id,
+ const gchar *format,
+ ...)
+{
+ gchar *str;
+ va_list args;
- return DBUS_HANDLER_RESULT_HANDLED;
+ va_start (args, format);
+ str = g_strdup_vprintf (format, args);
+ va_end (args);
+
+ tracker_log ("---- [%d] %s",
+ request_id,
+ str);
+ g_free (str);
}
Modified: branches/indexer-split/src/trackerd/tracker-dbus.h
==============================================================================
--- branches/indexer-split/src/trackerd/tracker-dbus.h (original)
+++ branches/indexer-split/src/trackerd/tracker-dbus.h Mon Apr 21 11:21:20 2008
@@ -1,5 +1,7 @@
-/* Tracker - indexer and metadata database engine
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
+/*
* Copyright (C) 2006, Mr Jamie McCracken (jamiemcc gnome org)
+ * Copyright (C) 2008, Nokia
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public
@@ -17,173 +19,86 @@
* Boston, MA 02110-1301, USA.
*/
-#ifndef _TRACKER_DBUS_H_
-#define _TRACKER_DBUS_H_
+#ifndef __TRACKER_DBUS_H__
+#define __TRACKER_DBUS_H__
#ifndef DBUS_API_SUBJECT_TO_CHANGE
#define DBUS_API_SUBJECT_TO_CHANGE
#endif
+#include <glib/gi18n.h>
#include <dbus/dbus.h>
#include <dbus/dbus-glib-lowlevel.h>
#include <dbus/dbus-glib.h>
+#include "tracker-db-interface.h"
-#define TRACKER_DBUS_SERVICE "org.freedesktop.Tracker"
-#define TRACKER_OBJECT "/org/freedesktop/tracker"
-#define TRACKER_INTERFACE "org.freedesktop.Tracker"
-#define TRACKER_INTERFACE_METADATA "org.freedesktop.Tracker.Metadata"
-#define TRACKER_INTERFACE_KEYWORDS "org.freedesktop.Tracker.Keywords"
-#define TRACKER_INTERFACE_SEARCH "org.freedesktop.Tracker.Search"
-#define TRACKER_INTERFACE_FILES "org.freedesktop.Tracker.Files"
-#define TRACKER_INTERFACE_MUSIC "org.freedesktop.Tracker.Music"
-#define TRACKER_INTERFACE_PLAYLISTS "org.freedesktop.Tracker.PlayLists"
-
-/* main service interface */
-#define TRACKER_METHOD_PING "Ping"
-#define TRACKER_METHOD_GET_STATS "GetStats"
-#define TRACKER_METHOD_GET_SERVICES "GetServices"
-#define TRACKER_METHOD_GET_VERSION "GetVersion"
-#define TRACKER_METHOD_GET_STATUS "GetStatus"
-#define TRACKER_METHOD_SET_BOOL_OPTION "SetBoolOption"
-#define TRACKER_METHOD_SET_INT_OPTION "SetIntOption"
-#define TRACKER_METHOD_SHUTDOWN "Shutdown"
-#define TRACKER_METHOD_PROMPT_INDEX_SIGNALS "PromptIndexSignals"
-
-/* metadata interface */
-#define TRACKER_METHOD_METADATA_GET "Get"
-#define TRACKER_METHOD_METADATA_SET "Set"
-#define TRACKER_METHOD_METADATA_REGISTER_TYPE "RegisterType"
-#define TRACKER_METHOD_METADATA_GET_TYPE_DETAILS "GetTypeDetails"
-#define TRACKER_METHOD_METADATA_GET_REGISTERED_TYPES "GetRegisteredTypes"
-#define TRACKER_METHOD_METADATA_GET_WRITEABLE_TYPES "GetWriteableTypes"
-#define TRACKER_METHOD_METADATA_GET_REGISTERED_CLASSES "GetRegisteredClasses"
-
-/* keywords interface */
-#define TRACKER_METHOD_KEYWORDS_GET_LIST "GetList"
-#define TRACKER_METHOD_KEYWORDS_GET "Get"
-#define TRACKER_METHOD_KEYWORDS_ADD "Add"
-#define TRACKER_METHOD_KEYWORDS_REMOVE "Remove"
-#define TRACKER_METHOD_KEYWORDS_REMOVE_ALL "RemoveAll"
-#define TRACKER_METHOD_KEYWORDS_SEARCH "Search"
-
-/* Search interface */
-#define TRACKER_METHOD_SEARCH_GET_HIT_COUNT "GetHitCount"
-#define TRACKER_METHOD_SEARCH_GET_HIT_COUNT_ALL "GetHitCountAll"
-#define TRACKER_METHOD_SEARCH_TEXT "Text"
-#define TRACKER_METHOD_SEARCH_TEXT_DETAILED "TextDetailed"
-#define TRACKER_METHOD_SEARCH_GET_SNIPPET "GetSnippet"
-#define TRACKER_METHOD_SEARCH_FILES_BY_TEXT "FilesByText"
-#define TRACKER_METHOD_SEARCH_METADATA "Metadata"
-#define TRACKER_METHOD_SEARCH_MATCHING_FIELDS "MatchingFields"
-#define TRACKER_METHOD_SEARCH_QUERY "Query"
-#define TRACKER_METHOD_SEARCH_SUGGEST "Suggest"
-
-/* File Interface */
-#define TRACKER_METHOD_FILES_EXISTS "Exists"
-#define TRACKER_METHOD_FILES_CREATE "Create"
-#define TRACKER_METHOD_FILES_DELETE "Delete"
-#define TRACKER_METHOD_FILES_GET_SERVICE_TYPE "GetServiceType"
-#define TRACKER_METHOD_FILES_GET_TEXT_CONTENTS "GetTextContents"
-#define TRACKER_METHOD_FILES_SEARCH_TEXT_CONTENTS "SearchTextContents"
-#define TRACKER_METHOD_FILES_GET_BY_SERVICE_TYPE "GetByServiceType"
-#define TRACKER_METHOD_FILES_GET_BY_MIME_TYPE "GetByMimeType"
-#define TRACKER_METHOD_FILES_GET_BY_MIME_TYPE_VFS "GetByMimeTypeVFS"
-#define TRACKER_METHOD_FILES_REFRESH_METADATA "RefreshMetadata"
-#define TRACKER_METHOD_FILES_GET_MTIME "GetMTime"
-#define TRACKER_METHOD_FILES_GET_METADATA_FOLDER_FILES "GetMetadataForFilesInFolder"
-
-/* Deprecated calls */
-#define TRACKER_METHOD_FILES_SEARCH_BY_TEXT_MIME "SearchByTextAndMime"
-#define TRACKER_METHOD_FILES_SEARCH_BY_TEXT_MIME_LOCATION "SearchByTextAndMimeAndLocation"
-#define TRACKER_METHOD_FILES_SEARCH_BY_TEXT_LOCATION "SearchByTextAndLocation"
-
-
-/* signals */
-#define TRACKER_SIGNAL_INDEX_STATUS_CHANGE "IndexStateChange"
-#define TRACKER_SIGNAL_INDEX_FINISHED "IndexFinished"
-#define TRACKER_SIGNAL_INDEX_PROGRESS "IndexProgress"
-
-#define TRACKER_SIGNAL_KEYWORD_ADDED "KeywordAdded"
-#define TRACKER_SIGNAL_KEYWORD_REMOVED "KeywordRemoved"
-
-typedef enum {
-
- DBUS_ACTION_NONE,
-
- DBUS_ACTION_PING,
- DBUS_ACTION_GET_SERVICES,
- DBUS_ACTION_GET_STATS,
- DBUS_ACTION_GET_VERSION,
- DBUS_ACTION_GET_STATUS,
-
- DBUS_ACTION_SET_BOOL_OPTION,
- DBUS_ACTION_SET_INT_OPTION,
- DBUS_ACTION_SHUTDOWN,
- DBUS_ACTION_PROMPT_INDEX_SIGNALS,
-
- DBUS_ACTION_METADATA_GET,
- DBUS_ACTION_METADATA_SET,
- DBUS_ACTION_METADATA_REGISTER_TYPE,
- DBUS_ACTION_METADATA_GET_TYPE_DETAILS,
- DBUS_ACTION_METADATA_GET_REGISTERED_TYPES,
- DBUS_ACTION_METADATA_GET_WRITEABLE_TYPES,
- DBUS_ACTION_METADATA_GET_REGISTERED_CLASSES,
-
- DBUS_ACTION_KEYWORDS_GET_LIST,
- DBUS_ACTION_KEYWORDS_GET,
- DBUS_ACTION_KEYWORDS_ADD,
- DBUS_ACTION_KEYWORDS_REMOVE,
- DBUS_ACTION_KEYWORDS_REMOVE_ALL,
- DBUS_ACTION_KEYWORDS_SEARCH,
-
- DBUS_ACTION_SEARCH_GET_HIT_COUNT,
- DBUS_ACTION_SEARCH_GET_HIT_COUNT_ALL,
- DBUS_ACTION_SEARCH_TEXT,
- DBUS_ACTION_SEARCH_TEXT_DETAILED,
- DBUS_ACTION_SEARCH_GET_SNIPPET,
- DBUS_ACTION_SEARCH_FILES_BY_TEXT,
- DBUS_ACTION_SEARCH_METADATA,
- DBUS_ACTION_SEARCH_MATCHING_FIELDS,
- DBUS_ACTION_SEARCH_QUERY,
- DBUS_ACTION_SEARCH_SUGGEST,
-
- DBUS_ACTION_FILES_EXISTS,
- DBUS_ACTION_FILES_CREATE,
- DBUS_ACTION_FILES_DELETE,
- DBUS_ACTION_FILES_GET_SERVICE_TYPE,
- DBUS_ACTION_FILES_GET_TEXT_CONTENTS,
- DBUS_ACTION_FILES_SEARCH_TEXT_CONTENTS,
- DBUS_ACTION_FILES_GET_BY_SERVICE_TYPE,
- DBUS_ACTION_FILES_GET_BY_MIME_TYPE,
- DBUS_ACTION_FILES_GET_BY_MIME_TYPE_VFS,
- DBUS_ACTION_FILES_REFRESH_METADATA,
- DBUS_ACTION_FILES_GET_MTIME,
- DBUS_ACTION_FILES_GET_METADATA_FOLDER_FILES,
-
- DBUS_ACTION_FILES_SEARCH_BY_TEXT_MIME,
- DBUS_ACTION_FILES_SEARCH_BY_TEXT_MIME_LOCATION,
- DBUS_ACTION_FILES_SEARCH_BY_TEXT_LOCATION
-
-} DBusAction;
+#define TRACKER_DBUS_ERROR_DOMAIN "TrackerDBus"
+#define TRACKER_DBUS_ERROR tracker_dbus_error_quark()
+#define tracker_dbus_async_return_if_fail(expr,context) \
+ G_STMT_START { \
+ if G_LIKELY(expr) { } else { \
+ GError *error = NULL; \
+ \
+ g_set_error (&error, \
+ TRACKER_DBUS_ERROR, \
+ 0, \
+ _("Assertion `%s' failed"), \
+ #expr); \
+ \
+ dbus_g_method_return_error (context, error); \
+ g_clear_error (&error); \
+ \
+ return; \
+ }; \
+ } G_STMT_END
+
+#define tracker_dbus_return_val_if_fail(expr,val,error) \
+ G_STMT_START { \
+ if G_LIKELY(expr) { } else { \
+ g_set_error (error, \
+ TRACKER_DBUS_ERROR, \
+ 0, \
+ _("Assertion `%s' failed"), \
+ #expr); \
+ \
+ return val; \
+ }; \
+ } G_STMT_END
typedef struct {
- DBusConnection *connection;
- DBusMessage *message;
- DBusAction action;
- gpointer user_data;
-} DBusRec;
-
-
-DBusConnection* tracker_dbus_init (void);
-void tracker_dbus_shutdown (DBusConnection *conn);
-void tracker_dbus_send_index_status_change_signal ();
-void tracker_dbus_send_index_finished_signal ();
-void tracker_dbus_send_index_progress_signal (const char *service, const char *uri);
-
-
-
+ guint id;
+ gpointer data1;
+ gpointer data2;
+} TrackerDBusData;
+
+gboolean tracker_dbus_init (gpointer tracker);
+void tracker_dbus_shutdown (void);
+guint tracker_dbus_get_next_request_id (void);
+GObject * tracker_dbus_get_object (GType type);
+GQuark tracker_dbus_error_quark (void);
+
+
+/* Utils */
+TrackerDBusData *tracker_dbus_data_new (const gpointer arg1,
+ const gpointer arg2);
+gchar ** tracker_dbus_slist_to_strv (GSList *list);
+gchar ** tracker_dbus_query_result_to_strv (TrackerDBResultSet *result_set,
+ gint *count);
+GHashTable * tracker_dbus_query_result_to_hash_table (TrackerDBResultSet *result_set);
+GPtrArray * tracker_dbus_query_result_to_ptr_array (TrackerDBResultSet *result_set);
+void tracker_dbus_request_new (gint request_id,
+ const gchar *format,
+ ...);
+void tracker_dbus_request_success (gint request_id);
+void tracker_dbus_request_failed (gint request_id,
+ GError **error,
+ const gchar *format,
+ ...);
+void tracker_dbus_request_comment (gint request_id,
+ const gchar *format,
+ ...);
-#endif
+#endif /* __TRACKER_DBUS_H__ */
Modified: branches/indexer-split/src/trackerd/tracker-email-evolution.c
==============================================================================
--- branches/indexer-split/src/trackerd/tracker-email-evolution.c (original)
+++ branches/indexer-split/src/trackerd/tracker-email-evolution.c Mon Apr 21 11:21:20 2008
@@ -38,7 +38,9 @@
#include "tracker-db-email.h"
#include "tracker-cache.h"
#include "tracker-dbus.h"
+#include "tracker-dbus-daemon.h"
#include "tracker-watch.h"
+#include "tracker-status.h"
#define EVOLUTION_MAIL_DIR_S ".evolution/mail"
@@ -1265,6 +1267,7 @@
SkipMailMessageFct skip_mail,
SaveOnDiskMailMessageFct save_ondisk_mail)
{
+ GObject *object;
SummaryFile *summary = NULL;
if (!tracker->is_running) {
@@ -1275,6 +1278,8 @@
return;
}
+ object = tracker_dbus_get_object (TRACKER_TYPE_DBUS_DAEMON);
+
if (open_summary_file (summary_file_path, &summary)) {
SummaryFileHeader *header;
gint32 mail_count, junk_count, delete_count;
@@ -1354,7 +1359,15 @@
store->mail_count, store->junk_count, store->delete_count, header->saved_count, header->junk_count, header->deleted_count);
tracker->mbox_count++;
- tracker_dbus_send_index_progress_signal ("Emails", dir);
+
+ /* Signal progress */
+ g_signal_emit_by_name (object,
+ "index-progress",
+ "Emails",
+ dir,
+ tracker->index_count,
+ tracker->mbox_processed,
+ tracker->mbox_count);
if (header->saved_count > store->mail_count) {
/* assume new emails received */
@@ -1425,8 +1438,14 @@
email_free_mail_message (mail_msg);
if (!tracker_cache_process_events (db_con->data, TRUE)) {
- tracker_set_status (tracker, STATUS_SHUTDOWN, 0, TRUE);
tracker->shutdown = TRUE;
+ tracker_status_set_and_signal (TRACKER_STATUS_SHUTDOWN,
+ tracker->first_time_index,
+ tracker->in_merge,
+ tracker->pause_manual,
+ tracker_pause_on_battery (),
+ tracker->pause_io,
+ tracker_config_get_enable_indexing (tracker->config));
return;
}
@@ -1441,8 +1460,14 @@
tracker_db_start_index_transaction (db_con->data);
}
- tracker_dbus_send_index_progress_signal ("Emails", dir);
-
+ /* Signal progress */
+ g_signal_emit_by_name (object,
+ "index-progress",
+ "Emails",
+ dir,
+ tracker->index_count,
+ tracker->mbox_processed,
+ tracker->mbox_count);
}
@@ -1458,7 +1483,14 @@
}
tracker->mbox_processed++;
- tracker_dbus_send_index_progress_signal ("Emails", dir);
+
+ g_signal_emit_by_name (object,
+ "index-progress",
+ "Emails",
+ dir,
+ tracker->index_count,
+ tracker->mbox_processed,
+ tracker->mbox_count);
tracker_db_email_free_mail_store (store);
free_summary_file (summary);
Modified: branches/indexer-split/src/trackerd/tracker-email-kmail.c
==============================================================================
--- branches/indexer-split/src/trackerd/tracker-email-kmail.c (original)
+++ branches/indexer-split/src/trackerd/tracker-email-kmail.c Mon Apr 21 11:21:20 2008
@@ -26,6 +26,7 @@
#include <glib/gstdio.h>
#include <libtracker-common/tracker-log.h>
+#include <libtracker-common/tracker-utils.h>
#include "tracker-email-utils.h"
#include "tracker-db-email.h"
Modified: branches/indexer-split/src/trackerd/tracker-email-modest.c
==============================================================================
--- branches/indexer-split/src/trackerd/tracker-email-modest.c (original)
+++ branches/indexer-split/src/trackerd/tracker-email-modest.c Mon Apr 21 11:21:20 2008
@@ -37,8 +37,10 @@
#include "tracker-email-modest.h"
#include "tracker-email-utils.h"
#include "tracker-db-email.h"
-#include "tracker-cache.h"
#include "tracker-dbus.h"
+#include "tracker-dbus-daemon.h"
+#include "tracker-cache.h"
+#include "tracker-status.h"
#include "tracker-watch.h"
@@ -702,10 +704,13 @@
SaveOnDiskMailMessageFct save_ondisk_mail)
{
SummaryFile *summary = NULL;
+ GObject *object;
if (!tracker->is_running)
return;
+ object = tracker_dbus_get_object (TRACKER_TYPE_DBUS_DAEMON);
+
if (open_summary_file (summary_file_path, &summary)) {
SummaryFileHeader *header;
gint32 mail_count, junk_count, delete_count;
@@ -838,7 +843,15 @@
store->mail_count, store->junk_count, store->delete_count, header->saved_count, header->junk_count, header->deleted_count);
tracker->mbox_count++;
- tracker_dbus_send_index_progress_signal ("Emails", dir);
+
+ /* Signal progress */
+ g_signal_emit_by_name (object,
+ "index-progress",
+ "Emails",
+ dir,
+ tracker->index_count,
+ tracker->mbox_processed,
+ tracker->mbox_count);
if (header->saved_count > store->mail_count) {
/* assume new emails received */
@@ -918,8 +931,14 @@
email_free_mail_message (mail_msg);
if (!tracker_cache_process_events (db_con->data, TRUE)) {
- tracker_set_status (tracker, STATUS_SHUTDOWN, 0, TRUE);
tracker->shutdown = TRUE;
+ tracker_status_set_and_signal (TRACKER_STATUS_SHUTDOWN,
+ tracker->first_time_index,
+ tracker->in_merge,
+ tracker->pause_manual,
+ tracker_pause_on_battery (),
+ tracker->pause_io,
+ tracker_config_get_enable_indexing (tracker->config));
return;
}
@@ -931,8 +950,14 @@
tracker_db_start_index_transaction (db_con->data);
}
- tracker_dbus_send_index_progress_signal ("Emails", dir);
-
+ /* Signal progress */
+ g_signal_emit_by_name (object,
+ "index-progress",
+ "Emails",
+ dir,
+ tracker->index_count,
+ tracker->mbox_processed,
+ tracker->mbox_count);
}
@@ -948,7 +973,15 @@
}
tracker->mbox_processed++;
- tracker_dbus_send_index_progress_signal ("Emails", dir);
+
+ /* Signal progress */
+ g_signal_emit_by_name (object,
+ "index-progress",
+ "Emails",
+ dir,
+ tracker->index_count,
+ tracker->mbox_processed,
+ tracker->mbox_count);
tracker_db_email_free_mail_store (store);
free_summary_file (summary);
Modified: branches/indexer-split/src/trackerd/tracker-email-utils.c
==============================================================================
--- branches/indexer-split/src/trackerd/tracker-email-utils.c (original)
+++ branches/indexer-split/src/trackerd/tracker-email-utils.c Mon Apr 21 11:21:20 2008
@@ -32,10 +32,12 @@
#include <libtracker-common/tracker-log.h>
#include <libtracker-common/tracker-config.h>
+#include <libtracker-common/tracker-utils.h>
#include "tracker-cache.h"
#include "tracker-db-email.h"
#include "tracker-dbus.h"
+#include "tracker-dbus-daemon.h"
#include "tracker-email-utils.h"
#include "tracker-watch.h"
@@ -113,6 +115,7 @@
MakeURIHelperFct uri_helper, gpointer make_uri_user_data,
MailStore *store)
{
+ GObject *object;
MailFile *mf;
MailMessage *mail_msg;
gint indexed = 0, junk = 0, deleted = 0;
@@ -128,7 +131,16 @@
mf = email_open_mail_file_at_offset (mail_app, path, store->offset, TRUE);
tracker->mbox_count++;
- tracker_dbus_send_index_progress_signal ("Emails", path);
+
+ /* Signal progress */
+ object = tracker_dbus_get_object (TRACKER_TYPE_DBUS_DAEMON);
+ g_signal_emit_by_name (object,
+ "index-progress",
+ "Emails",
+ path,
+ tracker->index_count,
+ tracker->mbox_processed,
+ tracker->mbox_count);
while ((mail_msg = email_mail_file_parse_next (mf, read_mail_helper, read_mail_user_data, NULL))) {
@@ -172,6 +184,7 @@
}
if (tracker_db_regulate_transactions (db_con->data, 500)) {
+ GObject *object;
if (tracker_config_get_verbosity (tracker->config) == 1) {
tracker_log ("indexing #%d - Emails in %s", tracker->index_count, path);
@@ -182,8 +195,16 @@
tracker_db_refresh_all (db_con->data);
tracker_db_start_index_transaction (db_con->data);
}
- tracker_dbus_send_index_progress_signal ("Emails", path);
+ /* Signal progress */
+ object = tracker_dbus_get_object (TRACKER_TYPE_DBUS_DAEMON);
+ g_signal_emit_by_name (object,
+ "index-progress",
+ "Emails",
+ path,
+ tracker->index_count,
+ tracker->mbox_processed,
+ tracker->mbox_count);
}
@@ -191,7 +212,16 @@
email_free_mail_file (mf);
tracker->mbox_processed++;
- tracker_dbus_send_index_progress_signal ("Emails", path);
+
+ /* Signal progress */
+ object = tracker_dbus_get_object (TRACKER_TYPE_DBUS_DAEMON);
+ g_signal_emit_by_name (object,
+ "index-progress",
+ "Emails",
+ path,
+ tracker->index_count,
+ tracker->mbox_processed,
+ tracker->mbox_count);
if (indexed > 0) {
tracker_info ("Indexed %d emails in email store %s and ignored %d junk and %d deleted emails",
Modified: branches/indexer-split/src/trackerd/tracker-indexer.c
==============================================================================
--- branches/indexer-split/src/trackerd/tracker-indexer.c (original)
+++ branches/indexer-split/src/trackerd/tracker-indexer.c Mon Apr 21 11:21:20 2008
@@ -54,10 +54,12 @@
#include "tracker-indexer.h"
#include "tracker-cache.h"
#include "tracker-dbus.h"
-#include "tracker-service-manager.h"
-#include "tracker-query-tree.h"
+#include "tracker-dbus-daemon.h"
#include "tracker-hal.h"
#include "tracker-process-files.h"
+#include "tracker-query-tree.h"
+#include "tracker-service-manager.h"
+#include "tracker-status.h"
extern Tracker *tracker;
@@ -366,6 +368,7 @@
void
tracker_indexer_apply_changes (Indexer *dest, Indexer *src, gboolean update)
{
+ GObject *object;
char *str;
char buffer[MAX_HIT_BUFFER];
int bytes;
@@ -401,8 +404,16 @@
tracker->in_merge = TRUE;
tracker->merge_count = 1;
tracker->merge_processed = 0;
- tracker_dbus_send_index_progress_signal ("Merging", "");
+ /* Signal progress */
+ object = tracker_dbus_get_object (TRACKER_TYPE_DBUS_DAEMON);
+ g_signal_emit_by_name (object,
+ "index-progress",
+ "Merging",
+ "",
+ tracker->index_count,
+ tracker->merge_processed,
+ tracker->merge_count);
while ((str = dpiternext (src->word_index, NULL))) {
@@ -453,8 +464,16 @@
tracker->in_merge = FALSE;
tracker->merge_count = 1;
tracker->merge_processed = 1;
- tracker_dbus_send_index_progress_signal ("Merging", "");
+ /* Signal progress */
+ object = tracker_dbus_get_object (TRACKER_TYPE_DBUS_DAEMON);
+ g_signal_emit_by_name (object,
+ "index-progress",
+ "Merging",
+ "",
+ tracker->index_count,
+ tracker->merge_processed,
+ tracker->merge_count);
}
gboolean
@@ -555,6 +574,7 @@
void
tracker_indexer_merge_indexes (IndexType type)
{
+ GObject *object;
GSList *lst;
Indexer *final_index;
GSList *file_list = NULL, *index_list = NULL;
@@ -562,7 +582,11 @@
gint i = 0, index_count, interval = 5000;
gboolean final_exists;
- if (tracker->shutdown) return;
+ if (tracker->shutdown) {
+ return;
+ }
+
+ object = tracker_dbus_get_object (TRACKER_TYPE_DBUS_DAEMON);
if (type == INDEX_TYPE_FILES) {
@@ -639,8 +663,15 @@
tracker->in_merge = TRUE;
tracker->merge_count = index_count;
tracker->merge_processed = 0;
- tracker_dbus_send_index_progress_signal ("Merging", "");
+ /* Signal progress */
+ g_signal_emit_by_name (object,
+ "index-progress",
+ "Merging",
+ "",
+ tracker->index_count,
+ tracker->merge_processed,
+ tracker->merge_count);
if (index_count == 2 && !final_exists) {
@@ -657,7 +688,16 @@
}
}
- tracker_dbus_send_index_status_change_signal ();
+ /* Signal state change */
+ g_signal_emit_by_name (object,
+ "index-state-change",
+ tracker_status_get_as_string (),
+ tracker->first_time_index,
+ tracker->in_merge,
+ tracker->pause_manual,
+ tracker_pause_on_battery (),
+ tracker->pause_io,
+ tracker_config_get_enable_indexing (tracker->config));
if (type == INDEX_TYPE_FILES) {
final_index = tracker_indexer_open ("file-index-final", TRUE);
@@ -690,7 +730,13 @@
if (i > 101 && (i % 100 == 0)) {
if (!tracker_cache_process_events (NULL, FALSE)) {
- tracker_set_status (tracker, STATUS_SHUTDOWN, 0, TRUE);
+ tracker_status_set_and_signal (TRACKER_STATUS_SHUTDOWN,
+ tracker->first_time_index,
+ tracker->in_merge,
+ tracker->pause_manual,
+ tracker_pause_on_battery (),
+ tracker->pause_io,
+ tracker_config_get_enable_indexing (tracker->config));
return;
}
}
@@ -774,9 +820,20 @@
if (lst->next) {
if (index != tracker->file_index && index != tracker->email_index) {
+ GObject *object;
+
tracker_indexer_free (index, TRUE);
tracker->merge_processed++;
- tracker_dbus_send_index_progress_signal ("Merging", "");
+
+ /* Signal progress */
+ object = tracker_dbus_get_object (TRACKER_TYPE_DBUS_DAEMON);
+ g_signal_emit_by_name (object,
+ "index-progress",
+ "Merging",
+ "",
+ tracker->index_count,
+ tracker->merge_processed,
+ tracker->merge_count);
}
@@ -801,8 +858,17 @@
end_of_merging:
tracker->in_merge = FALSE;
- tracker_dbus_send_index_status_change_signal ();
+ /* Signal state change */
+ g_signal_emit_by_name (object,
+ "index-state-change",
+ tracker_status_get_as_string (),
+ tracker->first_time_index,
+ tracker->in_merge,
+ tracker->pause_manual,
+ tracker_pause_on_battery (),
+ tracker->pause_io,
+ tracker_config_get_enable_indexing (tracker->config));
}
Modified: branches/indexer-split/src/trackerd/tracker-inotify.c
==============================================================================
--- branches/indexer-split/src/trackerd/tracker-inotify.c (original)
+++ branches/indexer-split/src/trackerd/tracker-inotify.c Mon Apr 21 11:21:20 2008
@@ -34,6 +34,7 @@
#include <glib/gstdio.h>
#include <libtracker-common/tracker-log.h>
+#include <libtracker-common/tracker-utils.h>
#include "tracker-watch.h"
#include "tracker-process-files.h"
Added: branches/indexer-split/src/trackerd/tracker-marshal-main.c
==============================================================================
--- (empty file)
+++ branches/indexer-split/src/trackerd/tracker-marshal-main.c Mon Apr 21 11:21:20 2008
@@ -0,0 +1,2 @@
+#include "tracker-marshal.h"
+#include "tracker-marshal.c"
Added: branches/indexer-split/src/trackerd/tracker-marshal.list
==============================================================================
--- (empty file)
+++ branches/indexer-split/src/trackerd/tracker-marshal.list Mon Apr 21 11:21:20 2008
@@ -0,0 +1,3 @@
+VOID:STRING,STRING,INT,INT,INT
+VOID:STRING,STRING,STRING
+VOID:STRING,BOOLEAN,BOOLEAN,BOOLEAN,BOOLEAN,BOOLEAN,BOOLEAN
Modified: branches/indexer-split/src/trackerd/tracker-process-files.c
==============================================================================
--- branches/indexer-split/src/trackerd/tracker-process-files.c (original)
+++ branches/indexer-split/src/trackerd/tracker-process-files.c Mon Apr 21 11:21:20 2008
@@ -32,20 +32,22 @@
#include <libtracker-common/tracker-config.h>
#include <libtracker-common/tracker-log.h>
+#include <libtracker-common/tracker-utils.h>
+
#include "../xdgmime/xdgmime.h"
#include "tracker-apps.h"
#include "tracker-db.h"
#include "tracker-dbus.h"
-#include "tracker-dbus-methods.h"
+#include "tracker-dbus-daemon.h"
#include "tracker-cache.h"
#include "tracker-email.h"
#include "tracker-hal.h"
#include "tracker-indexer.h"
#include "tracker-os-dependant.h"
-#include "tracker-utils.h"
#include "tracker-watch.h"
#include "tracker-service.h"
+#include "tracker-status.h"
#include "tracker-process-files.h"
static GSList *ignore_pattern_list;
@@ -74,12 +76,22 @@
};
static void
+process_iter_main_context (void)
+{
+ GMainContext *context;
+
+ context = g_main_context_default ();
+
+ while (g_main_context_pending (context)) {
+ g_main_context_iteration (context, FALSE);
+ }
+}
+
+static void
process_my_yield (void)
{
#ifndef OS_WIN32
- while (g_main_context_iteration (NULL, FALSE)) {
- /* FIXME: do something here? */
- }
+ process_iter_main_context ();
#endif
}
@@ -748,36 +760,29 @@
process_index_files (Tracker *tracker)
{
DBConnection *db_con;
+ GObject *object;
GSList *index_include;
GSList *index_exclude;
- gint initial_sleep;
tracker_log ("Starting file indexing...");
db_con = tracker->index_db;
+ object = tracker_dbus_get_object (TRACKER_TYPE_DBUS_DAEMON);
- initial_sleep = tracker_config_get_initial_sleep (tracker->config);
-
- tracker->pause_io = TRUE;
-
- tracker_dbus_send_index_status_change_signal ();
tracker_db_end_index_transaction (db_con);
- /* Sleep for N secs before watching/indexing any of the major services */
- tracker_log ("Sleeping for %d secs before starting...", initial_sleep);
-
- while (initial_sleep > 0) {
- g_usleep (G_USEC_PER_SEC);
-
- initial_sleep --;
-
- if (!tracker->is_running || tracker->shutdown) {
- return;
- }
- }
-
tracker->pause_io = FALSE;
- tracker_dbus_send_index_status_change_signal ();
+
+ /* Signal state change */
+ g_signal_emit_by_name (object,
+ "index-state-change",
+ tracker_status_get_as_string (),
+ tracker->first_time_index,
+ tracker->in_merge,
+ tracker->pause_manual,
+ tracker_pause_on_battery (),
+ tracker->pause_io,
+ tracker_config_get_enable_indexing (tracker->config));
/* FIXME: Is this safe? shouldn't we free first? */
crawl_directories = NULL;
@@ -841,7 +846,14 @@
}
tracker_db_end_transaction (db_con->cache);
- tracker_dbus_send_index_progress_signal ("Files", "");
+
+ /* Signal progress */
+ g_signal_emit_by_name (object, "index-progress",
+ "Files",
+ "",
+ tracker->index_count,
+ tracker->folders_processed,
+ tracker->folders_count);
g_slist_free (index_include);
}
@@ -1007,6 +1019,7 @@
{
DBConnection *db_con;
TrackerConfig *config;
+ GObject *daemon;
db_con = tracker->index_db;
config = tracker->config;
@@ -1022,7 +1035,14 @@
tracker->index_status = INDEX_EMAILS;
- tracker_dbus_send_index_progress_signal ("Emails", "");
+ /* Signal progress */
+ daemon = tracker_dbus_get_object (TRACKER_TYPE_DBUS_DAEMON);
+ g_signal_emit_by_name (daemon, "index-progress",
+ "Emails",
+ "",
+ tracker->index_count,
+ tracker->mbox_processed,
+ tracker->mbox_count);
if (tracker->word_update_count > 0) {
tracker_indexer_apply_changes (tracker->file_index, tracker->file_update_index, TRUE);
@@ -1056,8 +1076,10 @@
process_files (Tracker *tracker)
{
DBConnection *db_con;
+ GObject *object;
db_con = tracker->index_db;
+ object = tracker_dbus_get_object (TRACKER_TYPE_DBUS_DAEMON);
/* Check dir_queue in case there are
* directories waiting to be indexed.
@@ -1139,16 +1161,31 @@
}
tracker->index_status = INDEX_FILES;
- tracker_dbus_send_index_progress_signal ("Files","");
+
+ /* Signal progress */
+ g_signal_emit_by_name (object,
+ "index-progress",
+ "Files",
+ "",
+ tracker->index_count,
+ tracker->folders_processed,
+ tracker->folders_count);
+
tracker->index_status = INDEX_FINISHED;
if (tracker->is_running && tracker->first_time_index) {
- tracker_set_status (tracker, STATUS_OPTIMIZING, 0, FALSE);
+ gint time_taken;
+
+ tracker_status_set (TRACKER_STATUS_OPTIMIZING);
tracker->do_optimize = FALSE;
tracker->first_time_index = FALSE;
- tracker_dbus_send_index_finished_signal ();
+ time_taken = time (NULL) - tracker->index_time_start;
+ g_signal_emit_by_name (object,
+ "index-finished",
+ time_taken);
+
tracker_db_set_option_int (db_con, "InitialIndex", 0);
tracker->update_count = 0;
@@ -1166,13 +1203,29 @@
tracker_log ("Finished optimizing, waiting for new events...");
}
- /* We have no stuff to process so
- * sleep until awoken by a new
+ /* We have no stuff to process so sleep until awoken by a new
* signal.
*/
- tracker_set_status (tracker, STATUS_IDLE, 0, TRUE);
+ tracker_status_set_and_signal (TRACKER_STATUS_IDLE,
+ tracker->first_time_index,
+ tracker->in_merge,
+ tracker->pause_manual,
+ tracker_pause_on_battery (),
+ tracker->pause_io,
+ tracker_config_get_enable_indexing (tracker->config));
+
+ /* Signal state change */
+ g_signal_emit_by_name (object,
+ "index-state-change",
+ tracker_status_get_as_string (),
+ tracker->first_time_index,
+ tracker->in_merge,
+ tracker->pause_manual,
+ tracker_pause_on_battery (),
+ tracker->pause_io,
+ tracker_config_get_enable_indexing (tracker->config));
- g_cond_wait (tracker->file_thread_signal,
+ g_cond_wait (tracker->files_signal_cond,
tracker->files_signal_mutex);
tracker->grace_period = 0;
@@ -1427,17 +1480,24 @@
tracker_process_files (gpointer data)
{
Tracker *tracker;
- DBConnection *db_con;
+ GObject *object;
GSList *moved_from_list; /* List to hold moved_from
* events whilst waiting for a
* matching moved_to event.
*/
gboolean pushed_events;
gboolean first_run;
+ gint initial_sleep;
+
+ process_block_signals ();
+
+ object = tracker_dbus_get_object (TRACKER_TYPE_DBUS_DAEMON);
tracker = (Tracker*) data;
- process_block_signals ();
+ g_mutex_lock (tracker->files_signal_mutex);
+
+ tracker->pause_io = TRUE;
/* When initially run, we set up variables */
if (!ignore_pattern_list) {
@@ -1469,14 +1529,39 @@
/* Start processing */
g_mutex_lock (tracker->files_signal_mutex);
- g_mutex_lock (tracker->files_stopped_mutex);
- /* Set thread safe DB connection */
- tracker_db_thread_init ();
+ /* Signal state change */
+ g_signal_emit_by_name (object,
+ "index-state-change",
+ tracker_status_get_as_string (),
+ tracker->first_time_index,
+ tracker->in_merge,
+ tracker->pause_manual,
+ tracker_pause_on_battery (),
+ tracker->pause_io,
+ tracker_config_get_enable_indexing (tracker->config));
+
+ /* Sleep for N secs before watching/indexing any of the major services */
+ initial_sleep = tracker_config_get_initial_sleep (tracker->config);
+ tracker_log ("Sleeping for %d secs before starting...", initial_sleep);
+
+ while (initial_sleep > 0) {
+ g_usleep (G_USEC_PER_SEC);
+
+ initial_sleep --;
+
+ if (!tracker->is_running || tracker->shutdown) {
+ g_mutex_unlock (tracker->files_signal_mutex);
+ return NULL;
+ }
+ }
+
+ tracker_log ("Proceeding with indexing...");
- tracker->index_db = tracker_db_connect_all (TRUE);
tracker->index_status = INDEX_CONFIG;
+ object = tracker_dbus_get_object (TRACKER_TYPE_DBUS_DAEMON);
+
pushed_events = FALSE;
first_run = TRUE;
moved_from_list = NULL;
@@ -1489,14 +1574,24 @@
FileInfo *info;
gboolean need_index;
- db_con = tracker->index_db;
-
if (!tracker_cache_process_events (tracker->index_db, TRUE) ) {
- tracker_set_status (tracker, STATUS_SHUTDOWN, 0, TRUE);
+ tracker_status_set_and_signal (TRACKER_STATUS_SHUTDOWN,
+ tracker->first_time_index,
+ tracker->in_merge,
+ tracker->pause_manual,
+ tracker_pause_on_battery (),
+ tracker->pause_io,
+ tracker_config_get_enable_indexing (tracker->config));
break;
}
- tracker_set_status (tracker, STATUS_INDEXING, 0, TRUE);
+ tracker_status_set_and_signal (TRACKER_STATUS_INDEXING,
+ tracker->first_time_index,
+ tracker->in_merge,
+ tracker->pause_manual,
+ tracker_pause_on_battery (),
+ tracker->pause_io,
+ tracker_config_get_enable_indexing (tracker->config));
info = g_async_queue_try_pop (tracker->file_process_queue);
@@ -1530,7 +1625,7 @@
if (result_set) {
gboolean valid = TRUE;
- tracker_set_status (tracker, STATUS_PENDING, 0, FALSE);
+ tracker_status_set (TRACKER_STATUS_PENDING);
while (valid) {
FileInfo *info_tmp;
@@ -1576,7 +1671,13 @@
continue;
}
- tracker_set_status (tracker, STATUS_INDEXING, 0, TRUE);
+ tracker_status_set_and_signal (TRACKER_STATUS_INDEXING,
+ tracker->first_time_index,
+ tracker->in_merge,
+ tracker->pause_manual,
+ tracker_pause_on_battery (),
+ tracker->pause_io,
+ tracker_config_get_enable_indexing (tracker->config));
if (process_action_prechecks (tracker, info)) {
continue;
@@ -1591,11 +1692,18 @@
tracker_log ("indexing #%d - %s", tracker->index_count, info->uri);
}
- tracker_dbus_send_index_progress_signal ("Files", info->uri);
+ /* Signal progress */
+ object = tracker_dbus_get_object (TRACKER_TYPE_DBUS_DAEMON);
+ g_signal_emit_by_name (object,
+ "index-progress",
+ "Files",
+ info->uri,
+ tracker->index_count,
+ tracker->folders_processed,
+ tracker->folders_count);
}
process_index_entity (tracker, info);
- tracker->index_db = tracker->index_db;
}
tracker_dec_info_ref (info);
@@ -1612,7 +1720,7 @@
tracker_db_close_all (tracker->index_db);
- g_mutex_unlock (tracker->files_stopped_mutex);
+ g_mutex_unlock (tracker->files_signal_mutex);
return NULL;
}
Modified: branches/indexer-split/src/trackerd/tracker-rdf-query.c
==============================================================================
--- branches/indexer-split/src/trackerd/tracker-rdf-query.c (original)
+++ branches/indexer-split/src/trackerd/tracker-rdf-query.c Mon Apr 21 11:21:20 2008
@@ -20,6 +20,7 @@
#include <string.h>
#include <libtracker-common/tracker-log.h>
+#include <libtracker-common/tracker-utils.h>
#include "tracker-rdf-query.h"
Added: branches/indexer-split/src/trackerd/tracker-status.c
==============================================================================
--- (empty file)
+++ branches/indexer-split/src/trackerd/tracker-status.c Mon Apr 21 11:21:20 2008
@@ -0,0 +1,145 @@
+/* Tracker - indexer and metadata database engine
+ * Copyright (C) 2008, Mr Jamie McCracken (jamiemcc gnome org)
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public
+ * License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ */
+
+#include "config.h"
+
+#include "tracker-status.h"
+#include "tracker-dbus.h"
+#include "tracker-dbus-daemon.h"
+
+static TrackerStatus status = TRACKER_STATUS_INITIALIZING;
+
+GType
+tracker_status_get_type (void)
+{
+ static GType etype = 0;
+
+ if (etype == 0) {
+ static const GEnumValue values[] = {
+ { TRACKER_STATUS_INITIALIZING,
+ "TRACKER_STATUS_INITIALIZING",
+ "Initializing" },
+ { TRACKER_STATUS_WATCHING,
+ "TRACKER_STATUS_WATCHING",
+ "Watching" },
+ { TRACKER_STATUS_INDEXING,
+ "TRACKER_STATUS_INDEXING",
+ "Indexing" },
+ { TRACKER_STATUS_PENDING,
+ "TRACKER_STATUS_PENDING",
+ "Pending" },
+ { TRACKER_STATUS_OPTIMIZING,
+ "TRACKER_STATUS_OPTIMIZING",
+ "Optimizing" },
+ { TRACKER_STATUS_IDLE,
+ "TRACKER_STATUS_IDLE",
+ "Idle" },
+ { TRACKER_STATUS_SHUTDOWN,
+ "TRACKER_STATUS_SHUTDOWN",
+ "Shutdown" },
+ { 0, NULL, NULL }
+ };
+
+ etype = g_enum_register_static ("TrackerStatus", values);
+
+ /* Since we don't reference this enum anywhere, we do
+ * it here to make sure it exists when we call
+ * g_type_class_peek(). This wouldn't be necessary if
+ * it was a param in a GObject for example.
+ *
+ * This does mean that we are leaking by 1 reference
+ * here and should clean it up, but it doesn't grow so
+ * this is acceptable.
+ */
+
+ g_type_class_ref (etype);
+ }
+
+ return etype;
+}
+
+const gchar *
+tracker_status_to_string (TrackerStatus status)
+{
+ GType type;
+ GEnumClass *enum_class;
+ GEnumValue *enum_value;
+
+ type = tracker_status_get_type ();
+ enum_class = G_ENUM_CLASS (g_type_class_peek (type));
+ enum_value = g_enum_get_value (enum_class, status);
+
+ if (!enum_value) {
+ enum_value = g_enum_get_value (enum_class, TRACKER_STATUS_IDLE);
+ }
+
+ return enum_value->value_nick;
+}
+
+TrackerStatus
+tracker_status_get (void)
+{
+ return status;
+}
+
+const gchar *
+tracker_status_get_as_string (void)
+{
+ return tracker_status_to_string (status);
+}
+
+void
+tracker_status_set (TrackerStatus new_status)
+{
+ status = new_status;
+}
+
+void
+tracker_status_set_and_signal (TrackerStatus new_status,
+ gboolean first_time_index,
+ gboolean in_merge,
+ gboolean pause_manual,
+ gboolean pause_on_battery,
+ gboolean pause_io,
+ gboolean enable_indexing)
+{
+ GObject *object;
+ gboolean emit;
+
+ emit = new_status != status;
+
+ tracker_status_set (new_status);
+
+ if (!emit) {
+ return;
+ }
+
+ object = tracker_dbus_get_object (TRACKER_TYPE_DBUS_DAEMON);
+
+ g_signal_emit_by_name (object,
+ "index-state-change",
+ tracker_status_to_string (status),
+ first_time_index,
+ in_merge,
+ pause_manual,
+ pause_on_battery,
+ pause_io,
+ enable_indexing);
+}
+
Added: branches/indexer-split/src/trackerd/tracker-status.h
==============================================================================
--- (empty file)
+++ branches/indexer-split/src/trackerd/tracker-status.h Mon Apr 21 11:21:20 2008
@@ -0,0 +1,51 @@
+/* Tracker - indexer and metadata database engine
+ * Copyright (C) 2008, Mr Jamie McCracken (jamiemcc gnome org)
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public
+ * License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ */
+
+#ifndef __TRACKER_STATUS_H__
+#define __TRACKER_STATUS_H__
+
+#include <glib-object.h>
+
+#define TRACKER_TYPE_STATUS (tracker_status_get_type ())
+
+typedef enum {
+ TRACKER_STATUS_INITIALIZING,
+ TRACKER_STATUS_WATCHING,
+ TRACKER_STATUS_INDEXING,
+ TRACKER_STATUS_PENDING,
+ TRACKER_STATUS_OPTIMIZING,
+ TRACKER_STATUS_IDLE,
+ TRACKER_STATUS_SHUTDOWN
+} TrackerStatus;
+
+GType tracker_status_get_type (void) G_GNUC_CONST;
+
+const gchar * tracker_status_to_string (TrackerStatus status);
+TrackerStatus tracker_status_get (void);
+const gchar * tracker_status_get_as_string (void);
+void tracker_status_set (TrackerStatus new_status);
+void tracker_status_set_and_signal (TrackerStatus new_status,
+ gboolean first_time_index,
+ gboolean in_merge,
+ gboolean pause_manual,
+ gboolean pause_on_battery,
+ gboolean pause_io,
+ gboolean enable_indexing);
+
+#endif /* __TRACKER_STATUS_H__ */
Modified: branches/indexer-split/src/trackerd/tracker-utils.c
==============================================================================
--- branches/indexer-split/src/trackerd/tracker-utils.c (original)
+++ branches/indexer-split/src/trackerd/tracker-utils.c Mon Apr 21 11:21:20 2008
@@ -52,6 +52,7 @@
#include <libtracker-common/tracker-log.h>
#include <libtracker-common/tracker-config.h>
+#include <libtracker-common/tracker-utils.h>
#include "../xdgmime/xdgmime.h"
#include "tracker-dbus.h"
@@ -633,14 +634,6 @@
return (count > 0) ? g_strdup (buffer) : NULL;
}
-
-inline gboolean
-tracker_is_empty_string (const char *s)
-{
- return s == NULL || s[0] == '\0';
-}
-
-
gchar *
tracker_long_to_str (glong i)
{
@@ -1656,7 +1649,7 @@
/* if file thread is asleep then we just need to wake it up! */
if (g_mutex_trylock (tracker->files_signal_mutex)) {
- g_cond_signal (tracker->file_thread_signal);
+ g_cond_signal (tracker->files_signal_cond);
g_mutex_unlock (tracker->files_signal_mutex);
return;
}
@@ -1683,7 +1676,7 @@
}
if (g_mutex_trylock (tracker->files_signal_mutex)) {
- g_cond_signal (tracker->file_thread_signal);
+ g_cond_signal (tracker->files_signal_cond);
g_mutex_unlock (tracker->files_signal_mutex);
return;
}
@@ -1704,7 +1697,7 @@
/* if metadata thread is asleep then we just need to wake it up! */
if (g_mutex_trylock (tracker->metadata_signal_mutex)) {
- g_cond_signal (tracker->metadata_thread_signal);
+ g_cond_signal (tracker->metadata_signal_cond);
g_mutex_unlock (tracker->metadata_signal_mutex);
return;
}
@@ -1729,7 +1722,7 @@
}
if (g_mutex_trylock (tracker->metadata_signal_mutex)) {
- g_cond_signal (tracker->metadata_thread_signal);
+ g_cond_signal (tracker->metadata_signal_cond);
g_mutex_unlock (tracker->metadata_signal_mutex);
return;
}
@@ -1740,43 +1733,6 @@
}
}
-
-void
-tracker_notify_request_data_available (void)
-{
- /* if thread is asleep then we just need to wake it up! */
- if (g_mutex_trylock (tracker->request_signal_mutex)) {
- g_cond_signal (tracker->request_thread_signal);
- g_mutex_unlock (tracker->request_signal_mutex);
- return;
- }
-
- /* if thread not in check phase then we need do nothing */
- if (g_mutex_trylock (tracker->request_check_mutex)) {
- g_mutex_unlock (tracker->request_check_mutex);
- return;
- }
-
- /* we are in check phase - we need to wait until either check_mutex is unlocked or thread is asleep then awaken it */
- while (TRUE) {
-
- if (g_mutex_trylock (tracker->request_check_mutex)) {
- g_mutex_unlock (tracker->request_check_mutex);
- return;
- }
-
- if (g_mutex_trylock (tracker->request_signal_mutex)) {
- g_cond_signal (tracker->request_thread_signal);
- g_mutex_unlock (tracker->request_signal_mutex);
- return;
- }
-
- g_thread_yield ();
- g_usleep (10);
- }
-}
-
-
GTimeVal *
tracker_timer_start (void)
{
@@ -2519,19 +2475,6 @@
tracker->grace_period++;
}
-
-gchar *
-tracker_get_status (void)
-{
- if (tracker->status < 7) {
- gchar *tracker_status[] = {"Initializing", "Watching", "Indexing", "Pending", "Optimizing", "Idle", "Shutdown"};
- return g_strdup (tracker_status[tracker->status]);
- } else {
- return g_strdup ("Idle");
- }
-}
-
-
gboolean
tracker_pause_on_battery (void)
{
@@ -2621,17 +2564,6 @@
}
-void
-tracker_set_status (Tracker *tracker, TrackerStatus status, gdouble percentage, gboolean signal)
-{
- TrackerStatus old = tracker->status;
-
- tracker->status = status;
-
- if (signal && old != status)
- tracker_dbus_send_index_status_change_signal ();
-}
-
gboolean
tracker_pause (void)
{
Modified: branches/indexer-split/src/trackerd/tracker-utils.h
==============================================================================
--- branches/indexer-split/src/trackerd/tracker-utils.h (original)
+++ branches/indexer-split/src/trackerd/tracker-utils.h Mon Apr 21 11:21:20 2008
@@ -83,17 +83,6 @@
typedef enum {
- STATUS_INIT, /* tracker is initializing */
- STATUS_WATCHING, /* tracker is setting up watches for directories */
- STATUS_INDEXING, /* tracker is indexing stuff */
- STATUS_PENDING, /* tracker has entities awaiting index */
- STATUS_OPTIMIZING, /* tracker is optimizing its databases */
- STATUS_IDLE, /* tracker is idle and awaiting new events or requests */
- STATUS_SHUTDOWN /* tracker is in the shutdown process */
-} TrackerStatus;
-
-
-typedef enum {
INDEX_CONFIG,
INDEX_APPLICATIONS,
INDEX_FILES,
@@ -164,10 +153,8 @@
gboolean readonly;
- TrackerStatus status;
int pid;
- gpointer dbus_con;
gpointer hal;
gboolean reindex;
@@ -292,8 +279,6 @@
int file_update_count;
int email_update_count;
- GMutex *scheduler_mutex;
-
gboolean is_running;
gboolean is_dir_scan;
GMainLoop *loop;
@@ -303,27 +288,16 @@
GAsyncQueue *file_process_queue;
GAsyncQueue *file_metadata_queue;
- GAsyncQueue *user_request_queue;
GAsyncQueue *dir_queue;
GMutex *files_check_mutex;
- GMutex *metadata_check_mutex;
- GMutex *request_check_mutex;
-
- GMutex *files_stopped_mutex;
- GMutex *metadata_stopped_mutex;
- GMutex *request_stopped_mutex;
-
- GThread *file_metadata_thread;
-
- GCond *file_thread_signal;
- GCond *metadata_thread_signal;
- GCond *request_thread_signal;
+ GMutex *files_signal_mutex;
+ GCond *files_signal_cond;
+ GMutex *metadata_check_mutex;
GMutex *metadata_signal_mutex;
- GMutex *files_signal_mutex;
- GMutex *request_signal_mutex;
+ GCond *metadata_signal_cond;
} Tracker;
@@ -439,7 +413,6 @@
gchar ** tracker_make_array_null_terminated (gchar **array, gint length);
void tracker_free_array (char **array, int row_count);
-gboolean tracker_is_empty_string (const char *s);
gchar * tracker_long_to_str (glong i);
gchar * tracker_int_to_str (gint i);
gchar * tracker_uint_to_str (guint i);
@@ -528,8 +501,6 @@
void tracker_add_io_grace (const char *uri);
-char * tracker_get_status (void);
-
void free_file_change (FileChange **user_data);
gboolean tracker_do_cleanup (const gchar *sig_msg);
gboolean tracker_watch_dir (const gchar *uri);
@@ -539,6 +510,4 @@
gboolean tracker_low_diskspace (void);
gboolean tracker_pause (void);
-void tracker_set_status (Tracker *tracker, TrackerStatus status, gdouble percentage, gboolean signal);
-
#endif
Modified: branches/indexer-split/src/trackerd/trackerd.c
==============================================================================
--- branches/indexer-split/src/trackerd/trackerd.c (original)
+++ branches/indexer-split/src/trackerd/trackerd.c Mon Apr 21 11:21:20 2008
@@ -1,6 +1,8 @@
-/* Tracker - indexer and metadata database engine
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
+/*
* Copyright (C) 2006, Mr Jamie McCracken (jamiemcc gnome org)
- *
+ * Copyright (C) 2008, Nokia
+
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public
* License as published by the Free Software Foundation; either
@@ -48,11 +50,10 @@
#include "tracker-email.h"
#include "tracker-indexer.h"
#include "tracker-process-files.h"
-#include "tracker-process-requests.h"
#include "tracker-watch.h"
#include "tracker-hal.h"
-
#include "tracker-service-manager.h"
+#include "tracker-status.h"
#ifdef OS_WIN32
#include <windows.h>
@@ -102,8 +103,6 @@
*/
-gchar *type_array[] = {"index", "string", "numeric", "date", NULL};
-
static gchar **no_watch_dirs = NULL;
static gchar **watch_dirs = NULL;
static gchar **crawl_dirs = NULL;
@@ -210,7 +209,10 @@
{
GSList *black_list;
- tracker_set_status (tracker, STATUS_SHUTDOWN, 0, FALSE);
+ tracker->shutdown = TRUE;
+ tracker->in_flush = TRUE;
+
+ tracker_status_set (TRACKER_STATUS_SHUTDOWN);
if (sig_msg) {
tracker_log ("Received signal '%s' so now shutting down", sig_msg);
@@ -228,8 +230,6 @@
/* stop threads from further processing of events if possible */
- tracker->in_flush = TRUE;
-
//set_update_count (main_thread_db_con, tracker->update_count);
/* wait for files thread to sleep */
@@ -245,39 +245,24 @@
g_mutex_unlock (tracker->metadata_signal_mutex);
- tracker_log ("shutting down threads");
+ tracker_log ("Shutting down threads");
/* send signals to each thread to wake them up and then stop them */
-
-
- tracker->shutdown = TRUE;
-
- g_mutex_lock (tracker->request_signal_mutex);
- g_cond_signal (tracker->request_thread_signal);
- g_mutex_unlock (tracker->request_signal_mutex);
-
g_mutex_lock (tracker->metadata_signal_mutex);
- g_cond_signal (tracker->metadata_thread_signal);
+ g_cond_signal (tracker->metadata_signal_cond);
g_mutex_unlock (tracker->metadata_signal_mutex);
g_mutex_unlock (tracker->files_check_mutex);
g_mutex_lock (tracker->files_signal_mutex);
- g_cond_signal (tracker->file_thread_signal);
+ g_cond_signal (tracker->files_signal_cond);
g_mutex_unlock (tracker->files_signal_mutex);
-
/* wait for threads to exit and unlock check mutexes to prevent any deadlocks*/
- g_mutex_unlock (tracker->request_check_mutex);
- g_mutex_lock (tracker->request_stopped_mutex);
-
g_mutex_unlock (tracker->metadata_check_mutex);
- g_mutex_lock (tracker->metadata_stopped_mutex);
g_mutex_unlock (tracker->files_check_mutex);
- g_mutex_lock (tracker->files_stopped_mutex);
-
tracker_indexer_close (tracker->file_index);
tracker_indexer_close (tracker->file_update_index);
@@ -398,52 +383,6 @@
static void
-unregistered_func (DBusConnection *connection, gpointer data)
-{
-}
-
-
-static DBusHandlerResult
-local_dbus_connection_monitoring_message_func (DBusConnection *connection, DBusMessage *message, gpointer data)
-{
- /* DBus connection has been lost! */
- if (dbus_message_is_signal (message, DBUS_INTERFACE_LOCAL, "Disconnected")) {
- dbus_message_ref (message);
-
- tracker_error ("DBus connection has been lost, trackerd will now shutdown");
-
- tracker->is_running = FALSE;
- tracker_end_watching ();
- tracker_do_cleanup ("DBus connection lost");
- }
-
- return DBUS_HANDLER_RESULT_HANDLED;
-}
-
-
-static gboolean
-add_local_dbus_connection_monitoring (DBusConnection *connection)
-{
- DBusObjectPathVTable dbus_daemon_vtable = {
- unregistered_func,
- local_dbus_connection_monitoring_message_func,
- NULL,
- NULL,
- NULL,
- NULL
- };
-
- if (!dbus_connection_register_object_path (connection, DBUS_PATH_LOCAL, &dbus_daemon_vtable, NULL)) {
- tracker_log ("could not register local D-BUS connection handler");
- return FALSE;
-
- } else {
- return TRUE;
- }
-}
-
-
-static void
set_defaults (void)
{
tracker->grace_period = 0;
@@ -643,7 +582,8 @@
GOptionContext *context = NULL;
GError *error = NULL;
gchar *example;
- gboolean need_index, need_data;
+ gboolean need_index = FALSE;
+ gboolean need_data;
DBConnection *db_con;
gchar *tmp_dir;
gchar *old_tracker_dir;
@@ -738,35 +678,17 @@
fatal_errors);
tracker_log ("Starting log");
- /* Set up the DBus IPC */
- tracker->dbus_con = tracker_dbus_init ();
-
- add_local_dbus_connection_monitoring (tracker->dbus_con);
-
- tracker_set_status (tracker, STATUS_INIT, 0, FALSE);
-
+ /* Set up mutexes and intitial state */
tracker->is_running = FALSE;
tracker->shutdown = FALSE;
tracker->files_check_mutex = g_mutex_new ();
- tracker->metadata_check_mutex = g_mutex_new ();
- tracker->request_check_mutex = g_mutex_new ();
-
- tracker->files_stopped_mutex = g_mutex_new ();
- tracker->metadata_stopped_mutex = g_mutex_new ();
- tracker->request_stopped_mutex = g_mutex_new ();
-
- tracker->file_metadata_thread = NULL;
-
- tracker->file_thread_signal = g_cond_new ();
- tracker->metadata_thread_signal = g_cond_new ();
- tracker->request_thread_signal = g_cond_new ();
-
- tracker->metadata_signal_mutex = g_mutex_new ();
tracker->files_signal_mutex = g_mutex_new ();
- tracker->request_signal_mutex = g_mutex_new ();
+ tracker->files_signal_cond = g_cond_new ();
- tracker->scheduler_mutex = g_mutex_new ();
+ tracker->metadata_check_mutex = g_mutex_new ();
+ tracker->metadata_signal_mutex = g_mutex_new ();
+ tracker->metadata_signal_cond = g_cond_new ();
/* Remove an existing one */
if (g_file_test (tracker->sys_tmp_root_dir, G_FILE_TEST_EXISTS)) {
@@ -795,11 +717,6 @@
g_mkdir_with_parents (tracker->email_attachements_dir, 00700);
tracker_log ("Made email attachments directory %s\n", tracker->email_attachements_dir);
- need_index = FALSE;
- need_data = FALSE;
-
- //tracker->cached_word_table_mutex = g_mutex_new ();
-
tracker->dir_queue = g_async_queue_new ();
tracker->xesam_dir = g_build_filename (g_get_home_dir (), ".xesam", NULL);
@@ -810,15 +727,10 @@
need_index = TRUE;
}
-
- need_data = tracker_db_needs_data ();
-
umask (077);
str = g_strconcat (g_get_user_name (), "_tracker_lock", NULL);
-
-
/* check if setup for NFS usage (and enable atomic NFS safe locking) */
//lock_str = tracker_get_config_option ("NFSLocking");
lock_str = NULL;
@@ -925,28 +837,33 @@
/* Initialize the service manager */
tracker_service_manager_init ();
- /* set thread safe DB connection */
+ /* Set thread safe DB connection */
tracker_db_thread_init ();
- /* create cache db */
- DBConnection *db2 = tracker_db_connect_cache ();
- tracker_db_close (db2);
+#if 0
+ if (!tracker_db_initialize (tracker->data_dir)) {
+ tracker_error ("Could not initialize database engine!");
+ return EXIT_FAILURE;
+ }
+#endif
+
+ /* FIXME: is this actually necessary? */
+ db_con = tracker_db_connect_cache ();
+ tracker_db_close (db_con);
+ need_data = tracker_db_needs_data ();
if (need_data) {
tracker_create_db ();
}
- /* create database if needed */
if (!tracker->readonly && need_index) {
-
create_index (need_data);
-
} else {
tracker->first_time_index = FALSE;
}
-
+ /* Set up main database connection */
db_con = tracker_db_connect ();
db_con->thread = "main";
@@ -1042,12 +959,10 @@
tracker->file_process_queue = g_async_queue_new ();
}
- tracker->user_request_queue = g_async_queue_new ();
+ tracker->loop = g_main_loop_new (NULL, FALSE);
tracker_email_init ();
- tracker->loop = g_main_loop_new (NULL, TRUE);
-
#ifdef HAVE_HAL
/* Create tracker HAL object */
tracker->hal = tracker_hal_new ();
@@ -1056,19 +971,20 @@
/* this var is used to tell the threads when to quit */
tracker->is_running = TRUE;
- g_thread_create_full ((GThreadFunc) tracker_process_requests,
- tracker,
- (gulong) tracker_config_get_thread_stack_size (tracker->config),
- FALSE,
- FALSE,
- G_THREAD_PRIORITY_NORMAL,
- NULL);
+ tracker->index_db = tracker_db_connect_all (TRUE);
+
+ /* If we are already running, this should return some
+ * indication.
+ */
+ if (!tracker_dbus_init (tracker)) {
+ return EXIT_FAILURE;
+ }
if (!tracker->readonly) {
if (!tracker_start_watching ()) {
tracker_error ("ERROR: file monitoring failed to start");
tracker_do_cleanup ("File watching failure");
- exit (1);
+ return EXIT_FAILURE;
}
g_thread_create_full ((GThreadFunc) tracker_process_files,
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]