This file is indexed.

/usr/include/libgda-5.0/libgda/thread-wrapper/gda-thread-wrapper.h is in libgda-5.0-dev 5.0.3-1.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
/*
 * Copyright (C) 2009 - 2011 Vivien Malerba <malerba@gnome-db.org>
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser 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
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the
 * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
 * Boston, MA  02110-1301, USA.
 */

#ifndef __GDA_THREAD_WRAPPER_H__
#define __GDA_THREAD_WRAPPER_H__

#include <glib-object.h>

G_BEGIN_DECLS

#define GDA_TYPE_THREAD_WRAPPER            (gda_thread_wrapper_get_type())
#define GDA_THREAD_WRAPPER(obj)            (G_TYPE_CHECK_INSTANCE_CAST (obj, GDA_TYPE_THREAD_WRAPPER, GdaThreadWrapper))
#define GDA_THREAD_WRAPPER_CLASS(klass)    (G_TYPE_CHECK_CLASS_CAST (klass, GDA_TYPE_THREAD_WRAPPER, GdaThreadWrapperClass))
#define GDA_IS_THREAD_WRAPPER(obj)         (G_TYPE_CHECK_INSTANCE_TYPE(obj, GDA_TYPE_THREAD_WRAPPER))
#define GDA_IS_THREAD_WRAPPER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass), GDA_TYPE_THREAD_WRAPPER))
#define GDA_THREAD_WRAPPER_GET_CLASS(o)    (G_TYPE_INSTANCE_GET_CLASS ((o), GDA_TYPE_THREAD_WRAPPER, GdaThreadWrapperClass))

typedef struct _GdaThreadWrapper GdaThreadWrapper;
typedef struct _GdaThreadWrapperClass GdaThreadWrapperClass;
typedef struct _GdaThreadWrapperPrivate GdaThreadWrapperPrivate;

/* error reporting */
extern GQuark gda_thread_wrapper_error_quark (void);
#define GDA_THREAD_WRAPPER_ERROR gda_thread_wrapper_error_quark ()

typedef enum {
	GDA_THREAD_WRAPPER_UNKNOWN_ERROR
} GdaThreadWrapperError;

struct _GdaThreadWrapper {
	GObject            object;
	GdaThreadWrapperPrivate *priv;
};

struct _GdaThreadWrapperClass {
	GObjectClass       object_class;

	/*< private >*/
	/* Padding for future expansion */
	void (*_gda_reserved1) (void);
	void (*_gda_reserved2) (void);
	void (*_gda_reserved3) (void);
	void (*_gda_reserved4) (void);
};

/**
 * GdaThreadNotificationType:
 * @GDA_THREAD_NOTIFICATION_SIGNAL: the notification regards a signal
 * @GDA_THREAD_NOTIFICATION_JOB: the notification regards a job finished
 *
 * Defines the kind of notification which can be obtained when reading from te #GIOChannel
 * returned by gda_thread_wrapper_get_io_channel().
 */
typedef enum {
	GDA_THREAD_NOTIFICATION_JOB    = 0x01,
	GDA_THREAD_NOTIFICATION_SIGNAL = 0x02
} GdaThreadNotificationType;

/**
 * GdaThreadNotification:
 * @type: the notification type
 * @job_id: the job ID, if @type is a #GDA_THREAD_NOTIFICATION_JOB
 *
 * A notification to be read through the #GIOChannel which is returned by gda_thread_wrapper_get_io_channel(),
 * for example:
 * <programlisting><![CDATA[
 * gboolean
 * wrapper_ioc_cb (GIOChannel *source, GIOCondition condition, gpointer data)
 * {
 *     GIOStatus status;
 *     gsize nread;
 *     GdaThreadNotification notif;
 *     if (condition & G_IO_IN) {
 *	   status = g_io_channel_read_chars (source, (gchar*) &notif, sizeof (notif), &nread, NULL);
 *         if ((status != G_IO_STATUS_NORMAL) || (nread != sizeof (notif)))
 *             goto onerror;
 *	   switch (notif.type) {
 *	   case GDA_THREAD_NOTIFICATION_JOB:
 *             check_for_wrapper_result (bcnc);
 *             break;
 *         case GDA_THREAD_NOTIFICATION_SIGNAL:
 *             gda_thread_wrapper_iterate (bcnc->priv->wrapper, FALSE);
 *             break;
 *         default:
 *             goto onerror;
 *             break;
 *	   }
 *   }
 *   if (condition & (G_IO_ERR | G_IO_HUP | G_IO_NVAL))
 *             goto onerror;
 *   return TRUE; // keep callback
 *
 * onerror:
 *   g_io_channel_shutdown (bcnc->priv->ioc, FALSE, NULL);
 *   return FALSE; // removed callback
 * }
 *
 * {
 * [...]
 *     GIOChannel *ioc;
 *     ioc = gda_thread_wrapper_get_io_channel (wrapper);
 *     if (!ioc)
 *         [handle error]
 *     else {
 *         guint watch_id;
 *         watch_id = g_io_add_watch (ioc, G_IO_IN | G_IO_HUP | G_IO_ERR | G_IO_NVAL,
 *                                    (GIOFunc) wrapper_ioc_cb, NULL);
 *     }
 * }
 * ]]></programlisting>
 */
typedef struct {
	GdaThreadNotificationType type;
	guint                     job_id;
} GdaThreadNotification;

/**
 * GdaThreadWrapperFunc:
 * @arg: pointer to the data (which is the @arg argument passed to gda_thread_wrapper_execute_void())
 * @error: a place to store errors
 * @Returns: a pointer to some data which will be returned by gda_thread_wrapper_fetch_result()
 *
 * Specifies the type of function to be passed to gda_thread_wrapper_execute().
 */
typedef gpointer (*GdaThreadWrapperFunc) (gpointer arg, GError **error);

/**
 * GdaThreadWrapperVoidFunc:
 * @arg: a pointer to the data (which is the @arg argument passed to gda_thread_wrapper_execute_void())
 * @error: a place to store errors
 *
 * Specifies the type of function to be passed to gda_thread_wrapper_execute_void().
 */
typedef void (*GdaThreadWrapperVoidFunc) (gpointer arg, GError **error);

/**
 * GdaThreadWrapperCallback:
 * @wrapper: the #GdaThreadWrapper
 * @instance: a pointer to the instance which emitted the signal
 * @signame: the name of the signal being emitted
 * @n_param_values: number of GValue in @param_values
 * @param_values: array of @n_param_values GValue
 * @gda_reserved: reserved
 * @data: a pointer to the data (which is the @data argument passed to gda_thread_wrapper_connect_raw())
 *
 * Specifies the type of function to be passed to gda_thread_wrapper_connect_raw()
 */
typedef void (*GdaThreadWrapperCallback) (GdaThreadWrapper *wrapper, gpointer instance, const gchar *signame,
					  gint n_param_values, const GValue *param_values, gpointer gda_reserved,
					  gpointer data);

/**
 * SECTION:gda-thread-wrapper
 * @short_description: Execute functions in a sub thread
 * @title: GdaThreadWrapper
 * @stability: Stable
 * @see_also:
 *
 * The purpose of the #GdaThreadWrapper object is to execute functions in an isolated sub thread. As the
 * #GdaThreadWrapper is thread safe, one is able to isolate some code's execution is a <emphasis>private</emphasis>
 * <emphasis>worker</emphasis> thread, and make a non thread safe code thread safe.
 *
 * The downside of this is that the actual execution of the code will be slower as it requires
 * threads to be synchronized.
 *
 * The #GdaThreadWrapper implements its own locking mechanism and can safely be used from multiple
 * threads at once without needing further locking.
 *
 * Each thread using a #GdaThreadWrapper object can use it as if it was the only user: the #GdaThreadWrapper will
 * simply dispatch all the execution requests to its private <emphasis>worker</emphasis> thread and report the
 * execution's status only to the thread which made the request.
 *
 * The user can also specify a callback function to be called when an object exmits a signal while being
 * used by the worker thread, see the gda_thread_wrapper_connect_raw() method.
 *
 * The following diagram illustrates the conceptual working of the #GdaThreadWrapper object: here two user threads
 * are represented (assigned a red and green colors), both using a single #GdaThreadWrapper, so in this diagram, 3 threads
 * are present. The communication between the threads are handled by some #GAsyncQueue objects (in a transparent way for
 * the user, presented here only for illustration purposes). The queue represented in yellow is where jobs are
 * pushed by each user thread (step 1), and popped by the worker thread (step 2). Once the worker thread has finished
 * with a job, it stores the result along with the job and pushes it to the queue dedicated to the user thread
 * (step 3) in this example the red queue (because the job was issued from the thread represented in red). The last
 * step is when the user fetches the result (in its user thread), step 4.
 *
 * If, when the worker thread is busy with a job, a signal is emitted, and if the user has set up a signal handler
 * using gda_thread_wrapper_connect_raw(),
 * then a "job as signal" is created by the worker thread and pushed to the user thread as illustrated
 * at the bottom of the diagram.
 * <mediaobject>
 *   <imageobject role="html">
 *     <imagedata fileref="thread-wrapper.png" format="PNG" contentwidth="170mm"/>
 *   </imageobject>
 *   <textobject>
 *     <phrase>GdaThreadWrapper's conceptual working</phrase>
 *   </textobject>
 * </mediaobject>
 *
 * It's the user's responsability to regularly check if a submitted job has completed
 * (using gda_thread_wrapper_fetch_result()) or if a signal
 * has been emitted by an object while in the worker thread and needs to be handled by the #GdaThreadWrapper
 * to call the associated callback (using gda_thread_wrapper_iterate() or automatically done when
 * calling gda_thread_wrapper_fetch_result()).
 *
 * However, when a main loop is available, the #GdaThreadWrapper can emit notifications through a
 * #GIOChannel which can be intregated in the main loop. The #GIOChannel can be created
 * using gda_thread_wrapper_get_io_channel().
 */

GType                  gda_thread_wrapper_get_type          (void) G_GNUC_CONST;
GdaThreadWrapper      *gda_thread_wrapper_new               (void);
GIOChannel            *gda_thread_wrapper_get_io_channel    (GdaThreadWrapper *wrapper);
void                   gda_thread_wrapper_unset_io_channel  (GdaThreadWrapper *wrapper);

guint                  gda_thread_wrapper_execute           (GdaThreadWrapper *wrapper, GdaThreadWrapperFunc func,
							     gpointer arg, GDestroyNotify arg_destroy_func, GError **error);
guint                  gda_thread_wrapper_execute_void      (GdaThreadWrapper *wrapper, GdaThreadWrapperVoidFunc func,
							     gpointer arg, GDestroyNotify arg_destroy_func, GError **error);
gboolean               gda_thread_wrapper_cancel            (GdaThreadWrapper *wrapper, guint id);
void                   gda_thread_wrapper_iterate           (GdaThreadWrapper *wrapper, gboolean may_block);
gpointer               gda_thread_wrapper_fetch_result      (GdaThreadWrapper *wrapper, gboolean may_lock, 
							     guint exp_id, GError **error);

gint                   gda_thread_wrapper_get_waiting_size (GdaThreadWrapper *wrapper);

gulong                 gda_thread_wrapper_connect_raw       (GdaThreadWrapper *wrapper,
							     gpointer instance,
							     const gchar *sig_name,
							     gboolean private_thread, gboolean private_job,
							     GdaThreadWrapperCallback callback,
							     gpointer data);
void                   gda_thread_wrapper_disconnect       (GdaThreadWrapper *wrapper, gulong id);
void                   gda_thread_wrapper_steal_signal     (GdaThreadWrapper *wrapper, gulong id);
G_END_DECLS

#endif