No issues found
1 /*
2 * Copyright (C) 2008, 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 General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 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 * General Public License for more details.
13 *
14 * You should have received a copy of the GNU 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 * Authors:
20 * Philip Van Hoof <philip@codeminded.be>
21 */
22
23 #include "config.h"
24
25 #include <libtracker-data/tracker-data.h>
26
27 #include "tracker-events.h"
28
29 typedef struct {
30 gboolean frozen;
31 guint total;
32 GPtrArray *notify_classes;
33 } EventsPrivate;
34
35 static EventsPrivate *private;
36
37 guint
38 tracker_events_get_total (gboolean and_reset)
39 {
40 guint total;
41
42 g_return_val_if_fail (private != NULL, 0);
43
44 total = private->total;
45
46 if (and_reset) {
47 private->total = 0;
48 }
49
50 return total;
51 }
52
53 void
54 tracker_events_add_insert (gint graph_id,
55 gint subject_id,
56 const gchar *subject,
57 gint pred_id,
58 gint object_id,
59 const gchar *object,
60 GPtrArray *rdf_types)
61 {
62 guint i;
63
64 g_return_if_fail (rdf_types != NULL);
65 g_return_if_fail (private != NULL);
66
67 if (private->frozen) {
68 return;
69 }
70
71 for (i = 0; i < rdf_types->len; i++) {
72 if (tracker_class_get_notify (rdf_types->pdata[i])) {
73 tracker_class_add_insert_event (rdf_types->pdata[i],
74 graph_id,
75 subject_id,
76 pred_id,
77 object_id);
78 private->total++;
79 }
80 }
81 }
82
83 void
84 tracker_events_add_delete (gint graph_id,
85 gint subject_id,
86 const gchar *subject,
87 gint pred_id,
88 gint object_id,
89 const gchar *object,
90 GPtrArray *rdf_types)
91 {
92 guint i;
93
94 g_return_if_fail (rdf_types != NULL);
95 g_return_if_fail (private != NULL);
96
97 if (private->frozen) {
98 return;
99 }
100
101 for (i = 0; i < rdf_types->len; i++) {
102 if (tracker_class_get_notify (rdf_types->pdata[i])) {
103 tracker_class_add_delete_event (rdf_types->pdata[i],
104 graph_id,
105 subject_id,
106 pred_id,
107 object_id);
108 private->total++;
109 }
110 }
111 }
112
113 void
114 tracker_events_reset_pending (void)
115 {
116 guint i;
117
118 g_return_if_fail (private != NULL);
119
120 for (i = 0; i < private->notify_classes->len; i++) {
121 TrackerClass *class = g_ptr_array_index (private->notify_classes, i);
122
123 tracker_class_reset_pending_events (class);
124 }
125
126 private->frozen = FALSE;
127 }
128
129 void
130 tracker_events_freeze (void)
131 {
132 g_return_if_fail (private != NULL);
133
134 private->frozen = TRUE;
135 }
136
137 static void
138 free_private (EventsPrivate *private)
139 {
140 guint i;
141
142 for (i = 0; i < private->notify_classes->len; i++) {
143 TrackerClass *class = g_ptr_array_index (private->notify_classes, i);
144
145 tracker_class_reset_pending_events (class);
146
147 /* Perhaps hurry an emit of the ready events here? We're shutting down,
148 * so I guess we're not required to do that here ... ? */
149 tracker_class_reset_ready_events (class);
150 }
151
152 g_ptr_array_unref (private->notify_classes);
153
154 g_free (private);
155 }
156
157 TrackerClass **
158 tracker_events_get_classes (guint *length)
159 {
160 g_return_val_if_fail (private != NULL, NULL);
161
162 *length = private->notify_classes->len;
163
164 return (TrackerClass **) (private->notify_classes->pdata);
165 }
166
167 void
168 tracker_events_init (void)
169 {
170 TrackerClass **classes;
171 guint length = 0, i;
172
173 private = g_new0 (EventsPrivate, 1);
174
175 classes = tracker_ontologies_get_classes (&length);
176
177 private->notify_classes = g_ptr_array_sized_new (length);
178 g_ptr_array_set_free_func (private->notify_classes, (GDestroyNotify) g_object_unref);
179
180 for (i = 0; i < length; i++) {
181 TrackerClass *class = classes[i];
182
183 if (tracker_class_get_notify (class)) {
184 g_ptr_array_add (private->notify_classes, g_object_ref (class));
185 }
186 }
187
188 }
189
190 void
191 tracker_events_shutdown (void)
192 {
193 if (private != NULL) {
194 free_private (private);
195 private = NULL;
196 } else {
197 g_warning ("tracker_events already shutdown");
198 }
199 }