No issues found
1 /*
2 * Copyright (C) 2011, 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 * Author: Carlos Garnacho <carlos@lanedo.com>
20 */
21
22 #include "tracker-extract-info.h"
23
24 /**
25 * SECTION:tracker-extract-info
26 * @title: TrackerExtractInfo
27 * @short_description: struct used to pass information to and from
28 * a Tracker extract module
29 * @stability: Stable
30 * @include: libtracker-extract/tracker-extract.h
31 *
32 * The #TrackerExtractInfo structure is used to pass information
33 * on the file being extracted to an extractor module and contains
34 * objects to hold the SPARQL updates generated by the extractor.
35 **/
36
37
38 struct _TrackerExtractInfo
39 {
40 TrackerSparqlBuilder *preupdate;
41 TrackerSparqlBuilder *postupdate;
42 TrackerSparqlBuilder *metadata;
43 gchar *where_clause;
44
45 GFile *file;
46 gchar *mimetype;
47 gchar *graph;
48
49 gint ref_count;
50 };
51
52 G_DEFINE_BOXED_TYPE (TrackerExtractInfo, tracker_extract_info,
53 tracker_extract_info_ref, tracker_extract_info_unref)
54
55 /**
56 * tracker_extract_info_new:
57 * @file: a #GFile
58 * @mimetype: mimetype for @file
59 * @graph: SPARQL graph used for inserting data
60 *
61 * Returns a newly created #TrackerExtractInfo
62 *
63 * Returns: (transfer full): (boxed): A newly allocated #TrackerExtractInfo
64 *
65 * Since: 0.12
66 **/
67 TrackerExtractInfo *
68 tracker_extract_info_new (GFile *file,
69 const gchar *mimetype,
70 const gchar *graph)
71 {
72 TrackerExtractInfo *info;
73
74 g_return_val_if_fail (G_IS_FILE (file), NULL);
75
76 info = g_slice_new0 (TrackerExtractInfo);
77 info->file = g_object_ref (file);
78 info->mimetype = g_strdup (mimetype);
79 info->graph = g_strdup (graph);
80
81 info->preupdate = tracker_sparql_builder_new_update ();
82 info->postupdate = tracker_sparql_builder_new_update ();
83 info->metadata = tracker_sparql_builder_new_embedded_insert ();
84
85 info->where_clause = NULL;
86
87 info->ref_count = 1;
88
89 return info;
90 }
91
92 /**
93 * tracker_extract_info_ref:
94 * @info: a #TrackerExtractInfo
95 *
96 * Increases the reference count of @info
97 *
98 * Returns: A new reference to @info
99 *
100 * Since: 0.12
101 **/
102 TrackerExtractInfo *
103 tracker_extract_info_ref (TrackerExtractInfo *info)
104 {
105 g_return_val_if_fail (info != NULL, NULL);
106
107 g_atomic_int_inc (&info->ref_count);
108
109 return info;
110 }
111
112 /**
113 * tracker_extract_info_unref:
114 * @info: a #TrackerExtractInfo
115 *
116 * Decreases the reference count of @info, freeing all its associated resources
117 * if it reaches 0.
118 *
119 * Since: 0.12
120 **/
121 void
122 tracker_extract_info_unref (TrackerExtractInfo *info)
123 {
124 g_return_if_fail (info != NULL);
125
126 if (g_atomic_int_dec_and_test (&info->ref_count)) {
127 g_object_unref (info->file);
128 g_free (info->mimetype);
129 g_free (info->graph);
130
131 g_object_unref (info->preupdate);
132 g_object_unref (info->postupdate);
133 g_object_unref (info->metadata);
134 g_free (info->where_clause);
135
136 g_slice_free (TrackerExtractInfo, info);
137 }
138 }
139
140 /**
141 * tracker_extract_info_get_file:
142 * @info: a #TrackerExtractInfo
143 *
144 * Returns a #GFile pointing to the file being affected
145 * by the metadata extraction represented by @info
146 *
147 * Returns: (transfer none): The file being inspected
148 *
149 * Since: 0.12
150 **/
151 GFile *
152 tracker_extract_info_get_file (TrackerExtractInfo *info)
153 {
154 g_return_val_if_fail (info != NULL, NULL);
155
156 return info->file;
157 }
158
159 /**
160 * tracker_extract_info_get_mimetype:
161 * @info: a #TrackerExtractInfo
162 *
163 * Returns the mimetype being used for the file
164 * metadata extraction.
165 *
166 * Returns: (transfer none): the mimetype being used
167 * for extraction.
168 *
169 * Since: 0.12
170 **/
171 const gchar *
172 tracker_extract_info_get_mimetype (TrackerExtractInfo *info)
173 {
174 g_return_val_if_fail (info != NULL, NULL);
175
176 return info->mimetype;
177 }
178
179 /**
180 * tracker_extract_info_get_graph:
181 * @info: a #TrackerExtractInfo
182 *
183 * Returns the SPARQL graph that will be used when
184 * inserting metadata.
185 *
186 * Returns: (transfer none): The SPARQL graph the extract
187 * operation belongs to.
188 *
189 * Since: 0.12
190 **/
191 const gchar *
192 tracker_extract_info_get_graph (TrackerExtractInfo *info)
193 {
194 g_return_val_if_fail (info != NULL, NULL);
195
196 return info->graph;
197 }
198
199 /**
200 * tracker_extract_info_get_preupdate_builder:
201 * @info: a #TrackerExtractInfo
202 *
203 * Returns a #TrackerSparqlBuilder containing any
204 * separate updates that could apply to the file,
205 * such as author/band information in audio files,
206 * and so on.
207 *
208 * Returns: (transfer none): miscellaneous metadata
209 *
210 * Since: 0.12
211 **/
212 TrackerSparqlBuilder *
213 tracker_extract_info_get_preupdate_builder (TrackerExtractInfo *info)
214 {
215 g_return_val_if_fail (info != NULL, NULL);
216
217 return info->preupdate;
218 }
219
220 /**
221 * tracker_extract_info_get_postupdate_builder:
222 * @info: a #TrackerExtractInfo
223 *
224 * Returns a #TrackerSparqlBuilder containing separate
225 * updates for resources that are contained within the file
226 * and need to refer to it.
227 *
228 * Returns: (transfer none): #TrackerSparqlBuilder for
229 * resources that need inserting after the file resource.
230 *
231 * Since: 0.12.4
232 **/
233 TrackerSparqlBuilder *
234 tracker_extract_info_get_postupdate_builder (TrackerExtractInfo *info)
235 {
236 g_return_val_if_fail (info != NULL, NULL);
237
238 return info->postupdate;
239 }
240
241 /**
242 * tracker_extract_info_get_metadata_builder:
243 * @info: a #TrackerExtractInfo
244 *
245 * Returns a #TrackerSparqlBuilder containing the
246 * file metadata.
247 *
248 * Returns: (transfer none): the file metadata
249 *
250 * Since: 0.12
251 **/
252 TrackerSparqlBuilder *
253 tracker_extract_info_get_metadata_builder (TrackerExtractInfo *info)
254 {
255 g_return_val_if_fail (info != NULL, NULL);
256
257 return info->metadata;
258 }
259
260 /**
261 * tracker_extract_info_get_where_clause:
262 * @info: a #TrackerExtractInfo
263 *
264 * Returns the where clause that will apply to the
265 * other metadata contained in @info.
266 *
267 * Returns: (transfer none): The where clause
268 *
269 * Since: 0.12
270 **/
271 const gchar *
272 tracker_extract_info_get_where_clause (TrackerExtractInfo *info)
273 {
274 g_return_val_if_fail (info != NULL, NULL);
275
276 return info->where_clause;
277 }
278
279 /**
280 * tracker_extract_info_set_where_clause:
281 * @info: a #TrackerExtractInfo
282 * @where: Where clause for the file update.
283 *
284 * Sets the where clause for the returned metadata.
285 *
286 * Since: 0.12
287 **/
288 void
289 tracker_extract_info_set_where_clause (TrackerExtractInfo *info,
290 const gchar *where)
291 {
292 g_return_if_fail (info != NULL);
293
294 g_free (info->where_clause);
295 info->where_clause = g_strdup (where);
296 }