2 * Copyright (C) <1999> Erik Walthinsen <omega@cse.ogi.edu>
3 * <2005> Wim Taymans <wim@fluendo.com>
5 * gsttask.h: Streaming tasks
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Library General Public
9 * License as published by the Free Software Foundation; either
10 * version 2 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Library General Public License for more details.
17 * You should have received a copy of the GNU Library General Public
18 * License along with this library; if not, write to the
19 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
20 * Boston, MA 02111-1307, USA.
23 #ifndef __GST_TASK_H__
24 #define __GST_TASK_H__
26 #include <gst/gstobject.h>
27 #include <gst/gsttaskpool.h>
33 * @data: user data passed to the function
35 * A function that will repeatedly be called in the thread created by
38 typedef void (*GstTaskFunction) (void *data);
40 /* --- standard type macros --- */
41 #define GST_TYPE_TASK (gst_task_get_type ())
42 #define GST_TASK(task) (G_TYPE_CHECK_INSTANCE_CAST ((task), GST_TYPE_TASK, GstTask))
43 #define GST_IS_TASK(task) (G_TYPE_CHECK_INSTANCE_TYPE ((task), GST_TYPE_TASK))
44 #define GST_TASK_CLASS(tclass) (G_TYPE_CHECK_CLASS_CAST ((tclass), GST_TYPE_TASK, GstTaskClass))
45 #define GST_IS_TASK_CLASS(tclass) (G_TYPE_CHECK_CLASS_TYPE ((tclass), GST_TYPE_TASK))
46 #define GST_TASK_GET_CLASS(task) (G_TYPE_INSTANCE_GET_CLASS ((task), GST_TYPE_TASK, GstTaskClass))
47 #define GST_TASK_CAST(task) ((GstTask*)(task))
49 typedef struct _GstTask GstTask;
50 typedef struct _GstTaskClass GstTaskClass;
51 typedef struct _GstTaskPrivate GstTaskPrivate;
55 * @GST_TASK_STARTED: the task is started and running
56 * @GST_TASK_STOPPED: the task is stopped
57 * @GST_TASK_PAUSED: the task is paused
59 * The different states a task can be in
69 * @task: Task to get the state of
71 * Get access to the state of the task.
73 #define GST_TASK_STATE(task) (GST_TASK_CAST(task)->state)
77 * @task: Task to get the cond of
79 * Get access to the cond of the task.
81 #define GST_TASK_GET_COND(task) (GST_TASK_CAST(task)->cond)
84 * @task: Task to wait for
86 * Wait for the task cond to be signalled
88 #define GST_TASK_WAIT(task) g_cond_wait(GST_TASK_GET_COND (task), GST_OBJECT_GET_LOCK (task))
91 * @task: Task to signal
93 * Signal the task cond
95 #define GST_TASK_SIGNAL(task) g_cond_signal(GST_TASK_GET_COND (task))
98 * @task: Task to broadcast
100 * Send a broadcast signal to all waiting task conds
102 #define GST_TASK_BROADCAST(task) g_cond_breadcast(GST_TASK_GET_COND (task))
106 * @task: Task to get the lock of
108 * Get access to the task lock.
110 #define GST_TASK_GET_LOCK(task) (GST_TASK_CAST(task)->lock)
113 * GstTaskThreadCallbacks:
114 * @enter_thread: a thread is entered, this callback is called when the new
115 * thread enters its function.
116 * @leave_thread: a thread is exiting, this is called when the thread is about
117 * to leave its function
119 * Custom GstTask thread callback functions that can be installed.
124 /* manage the lifetime of the thread */
125 void (*enter_thread) (GstTask *task, GThread *thread, gpointer user_data);
126 void (*leave_thread) (GstTask *task, GThread *thread, gpointer user_data);
128 gpointer _gst_reserved[GST_PADDING];
129 } GstTaskThreadCallbacks;
133 * @state: the state of the task
134 * @cond: used to pause/resume the task
135 * @lock: The lock taken when iterating the task function
136 * @func: the function executed by this task
137 * @data: data passed to the task function
138 * @running: a flag indicating that the task is running
140 * The #GstTask object.
145 /*< public >*/ /* with LOCK */
149 GStaticRecMutex *lock;
151 GstTaskFunction func;
159 /* thread this task is currently running in */
162 gpointer _gst_reserved[GST_PADDING - 1];
165 GstTaskPrivate *priv;
168 struct _GstTaskClass {
169 GstObjectClass parent_class;
175 gpointer _gst_reserved[GST_PADDING];
178 void gst_task_cleanup_all (void);
180 GType gst_task_get_type (void);
182 GstTask* gst_task_create (GstTaskFunction func, gpointer data);
183 void gst_task_set_lock (GstTask *task, GStaticRecMutex *mutex);
184 void gst_task_set_priority (GstTask *task, GThreadPriority priority);
186 GstTaskPool * gst_task_get_pool (GstTask *task);
187 void gst_task_set_pool (GstTask *task, GstTaskPool *pool);
189 void gst_task_set_thread_callbacks (GstTask *task,
190 GstTaskThreadCallbacks *callbacks,
192 GDestroyNotify notify);
194 GstTaskState gst_task_get_state (GstTask *task);
195 gboolean gst_task_set_state (GstTask *task, GstTaskState state);
197 gboolean gst_task_start (GstTask *task);
198 gboolean gst_task_stop (GstTask *task);
199 gboolean gst_task_pause (GstTask *task);
201 gboolean gst_task_join (GstTask *task);
205 #endif /* __GST_TASK_H__ */