1 /*
2  * Copyright (C) 2009, Nokia <ivan.frade@nokia.com>
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Lesser General Public
6  * License as published by the Free Software Foundation; either
7  * version 2.1 of the License, or (at your option) any later version.
8  *
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12  * Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public
15  * License along with this library; if not, write to the
16  * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17  * Boston, MA  02110-1301, USA.
18  */
19 
20 #ifndef __LIBTRACKER_MINER_MINER_FS_H__
21 #define __LIBTRACKER_MINER_MINER_FS_H__
22 
23 #if !defined (__LIBTRACKER_MINER_H_INSIDE__) && !defined (TRACKER_COMPILATION)
24 #error "Only <libtracker-miner/tracker-miner.h> can be included directly."
25 #endif
26 
27 #include <glib-object.h>
28 #include <gio/gio.h>
29 
30 #include <libtracker-sparql/tracker-sparql.h>
31 
32 #include "tracker-miner-object.h"
33 #include "tracker-data-provider.h"
34 #include "tracker-indexing-tree.h"
35 
36 G_BEGIN_DECLS
37 
38 #define TRACKER_TYPE_MINER_FS         (tracker_miner_fs_get_type())
39 #define TRACKER_MINER_FS(o)           (G_TYPE_CHECK_INSTANCE_CAST ((o), TRACKER_TYPE_MINER_FS, TrackerMinerFS))
40 #define TRACKER_MINER_FS_CLASS(c)     (G_TYPE_CHECK_CLASS_CAST ((c), TRACKER_TYPE_MINER_FS, TrackerMinerFSClass))
41 #define TRACKER_IS_MINER_FS(o)        (G_TYPE_CHECK_INSTANCE_TYPE ((o), TRACKER_TYPE_MINER_FS))
42 #define TRACKER_IS_MINER_FS_CLASS(c)  (G_TYPE_CHECK_CLASS_TYPE ((c),  TRACKER_TYPE_MINER_FS))
43 #define TRACKER_MINER_FS_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), TRACKER_TYPE_MINER_FS, TrackerMinerFSClass))
44 
45 typedef enum {
46 	TRACKER_MINER_FS_EVENT_CREATED,
47 	TRACKER_MINER_FS_EVENT_UPDATED,
48 	TRACKER_MINER_FS_EVENT_DELETED,
49 	TRACKER_MINER_FS_EVENT_MOVED,
50 } TrackerMinerFSEventType;
51 
52 typedef struct _TrackerMinerFS        TrackerMinerFS;
53 typedef struct _TrackerMinerFSPrivate TrackerMinerFSPrivate;
54 
55 /**
56  * TrackerMinerFS:
57  *
58  * Abstract miner implementation to get data from the filesystem.
59  **/
60 struct _TrackerMinerFS {
61 	TrackerMiner parent;
62 	TrackerMinerFSPrivate *priv;
63 };
64 
65 /**
66  * TrackerMinerFSClass:
67  * @parent: parent object class
68  * @process_file: Called when the metadata associated to a file is
69  * requested.
70  * @finished: Called when all processing has been performed.
71  * @process_file_attributes: Called when the metadata associated with
72  * a file's attributes changes, for example, the mtime.
73  * @finished_root: Called when all resources on a particular root URI
74  * have been processed.
75  * @remove_file: Called when a file is removed.
76  * @remove_children: Called when children have been removed.
77  * @move_file: Called when a file has moved.
78  * @filter_event: Called to filter the event happening to a file.
79  * @padding: Reserved for future API improvements.
80  *
81  * Prototype for the abstract class, @process_file must be implemented
82  * in the deriving class in order to actually extract data.
83  **/
84 typedef struct {
85 	TrackerMinerClass parent;
86 
87 	gboolean (* process_file)             (TrackerMinerFS       *fs,
88 	                                       GFile                *file,
89 					       GTask                *task);
90 	void     (* finished)                 (TrackerMinerFS       *fs,
91 	                                       gdouble               elapsed,
92 	                                       gint                  directories_found,
93 	                                       gint                  directories_ignored,
94 	                                       gint                  files_found,
95 	                                       gint                  files_ignored);
96 	gboolean (* process_file_attributes)  (TrackerMinerFS       *fs,
97 	                                       GFile                *file,
98 					       GTask                *task);
99 	void     (* finished_root)            (TrackerMinerFS       *fs,
100 	                                       GFile                *root,
101 	                                       gint                  directories_found,
102 	                                       gint                  directories_ignored,
103 	                                       gint                  files_found,
104 	                                       gint                  files_ignored);
105 	gchar *  (* remove_file)              (TrackerMinerFS       *fs,
106 	                                       GFile                *file);
107 	gchar *  (* remove_children)          (TrackerMinerFS       *fs,
108 	                                       GFile                *file);
109 	gchar *  (* move_file)                (TrackerMinerFS       *fs,
110 					       GFile                *dest,
111 	                                       GFile                *source,
112 	                                       gboolean              recursive);
113 
114 	gboolean (* filter_event)             (TrackerMinerFS          *fs,
115 	                                       TrackerMinerFSEventType  type,
116 	                                       GFile                   *file,
117 	                                       GFile                   *source_file);
118 
119 	/* <Private> */
120 	gpointer padding[20];
121 } TrackerMinerFSClass;
122 
123 /**
124  * TrackerMinerFSError:
125  * @TRACKER_MINER_FS_ERROR_INIT: There was an error during
126  * initialization of the object. The specific details are in the
127  * message.
128  *
129  * Possible errors returned when calling creating new objects based on
130  * the #TrackerMinerFS type and other APIs available with this class.
131  *
132  * Since: 1.2
133  **/
134 typedef enum {
135 	TRACKER_MINER_FS_ERROR_INIT,
136 } TrackerMinerFSError;
137 
138 GType                 tracker_miner_fs_get_type              (void) G_GNUC_CONST;
139 GQuark                tracker_miner_fs_error_quark           (void);
140 
141 /* Properties */
142 TrackerIndexingTree * tracker_miner_fs_get_indexing_tree     (TrackerMinerFS  *fs);
143 TrackerDataProvider * tracker_miner_fs_get_data_provider     (TrackerMinerFS  *fs);
144 gdouble               tracker_miner_fs_get_throttle          (TrackerMinerFS  *fs);
145 void                  tracker_miner_fs_set_throttle          (TrackerMinerFS  *fs,
146                                                               gdouble          throttle);
147 
148 /* Queueing files to be processed AFTER checking rules in IndexingTree */
149 void                  tracker_miner_fs_check_file            (TrackerMinerFS  *fs,
150                                                               GFile           *file,
151                                                               gint             priority,
152                                                               gboolean         check_parents);
153 
154 /* Continuation for async vmethods */
155 void                  tracker_miner_fs_notify_finish         (TrackerMinerFS  *fs,
156 							      GTask           *task,
157 							      const gchar     *sparql,
158 							      GError          *error);
159 
160 /* URNs */
161 const gchar          *tracker_miner_fs_get_urn               (TrackerMinerFS  *fs,
162                                                               GFile           *file);
163 gchar                *tracker_miner_fs_query_urn             (TrackerMinerFS  *fs,
164                                                               GFile           *file);
165 
166 
167 /* Progress */
168 gboolean              tracker_miner_fs_has_items_to_process  (TrackerMinerFS  *fs);
169 
170 G_END_DECLS
171 
172 #endif /* __LIBTRACKER_MINER_MINER_FS_H__ */
173