gst/gsttask.*: More docs.
[platform/upstream/gstreamer.git] / gst / gsttask.h
1 /* GStreamer
2  * Copyright (C) <1999> Erik Walthinsen <omega@cse.ogi.edu>
3  *               <2005> Wim Taymans <wim@fluendo.com>
4  *
5  * gsttask.h: Streaming tasks
6  *
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.
11  *
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.
16  *
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.
21  */
22
23 #ifndef __GST_TASK_H__
24 #define __GST_TASK_H__
25
26 #include <gst/gstobject.h>
27
28 G_BEGIN_DECLS
29
30 typedef void         (*GstTaskFunction)          (void *data);
31
32 /* --- standard type macros --- */
33 #define GST_TYPE_TASK                   (gst_task_get_type ())
34 #define GST_TASK(task)                  (G_TYPE_CHECK_INSTANCE_CAST ((task), GST_TYPE_TASK, GstTask))
35 #define GST_IS_TASK(task)               (G_TYPE_CHECK_INSTANCE_TYPE ((task), GST_TYPE_TASK))
36 #define GST_TASK_CLASS(tclass)          (G_TYPE_CHECK_CLASS_CAST ((tclass), GST_TYPE_TASK, GstTaskClass))
37 #define GST_IS_TASK_CLASS(tclass)       (G_TYPE_CHECK_CLASS_TYPE ((tclass), GST_TYPE_TASK))
38 #define GST_TASK_GET_CLASS(task)        (G_TYPE_INSTANCE_GET_CLASS ((task), GST_TYPE_TASK, GstTaskClass))
39 #define GST_TASK_CAST(task)             ((GstTask*)(task))
40
41 typedef struct _GstTask GstTask;
42 typedef struct _GstTaskClass GstTaskClass;
43
44 /**
45  * GstTaskState:
46  * @GST_TASK_STARTED: the task is started and running
47  * @GST_TASK_STOPPED:  the task is stopped
48  * @GST_TASK_PAUSED: the task is paused
49  *
50  * The different states a task can be in
51  */
52 typedef enum {
53   GST_TASK_STARTED,
54   GST_TASK_STOPPED,
55   GST_TASK_PAUSED,
56 } GstTaskState;
57
58 /**
59  * GST_TASK_STATE:
60  * @task: Task to get the state of
61  *
62  * Get access to the state of the task.
63  */
64 #define GST_TASK_STATE(task)            (GST_TASK_CAST(task)->state)
65
66 #define GST_TASK_GET_COND(task)         (GST_TASK_CAST(task)->cond)
67 #define GST_TASK_WAIT(task)             g_cond_wait(GST_TASK_GET_COND (task), GST_GET_LOCK (task))
68 #define GST_TASK_SIGNAL(task)           g_cond_signal(GST_TASK_GET_COND (task))
69 #define GST_TASK_BROADCAST(task)        g_cond_breadcast(GST_TASK_GET_COND (task))
70
71 #define GST_TASK_GET_LOCK(task)         (GST_TASK_CAST(task)->lock)
72
73 /**
74  * GstTask:
75  * @state: the state of the task
76  * @cond: used to pause/resume the task
77  * @lock: The lock taken when iterating the taskfunction
78  * @func: the function executed by this task
79  * @data: data passed to the task function
80  * @running: a flag indicating that the task is running.
81  *
82  * The GstTask object.
83  */
84 struct _GstTask {
85   GstObject      object;
86
87   /*< public >*/ /* with LOCK */
88   GstTaskState     state;
89   GCond           *cond;
90
91   GStaticRecMutex *lock;
92
93   GstTaskFunction  func;
94   gpointer         data;
95
96   gboolean         running;
97
98   /*< private >*/
99   gpointer _gst_reserved[GST_PADDING];
100 };
101
102 struct _GstTaskClass {
103   GstObjectClass parent_class;
104
105   /*< private >*/
106   GThreadPool *pool;
107
108   /*< private >*/
109   gpointer _gst_reserved[GST_PADDING];
110 };
111
112 void            gst_task_cleanup_all    (void);
113
114 GType           gst_task_get_type       (void);
115
116 GstTask*        gst_task_create         (GstTaskFunction func, gpointer data);
117 void            gst_task_set_lock       (GstTask *task, GStaticRecMutex *mutex);
118
119 GstTaskState    gst_task_get_state      (GstTask *task);
120
121 gboolean        gst_task_start          (GstTask *task);
122 gboolean        gst_task_stop           (GstTask *task);
123 gboolean        gst_task_pause          (GstTask *task);
124
125 gboolean        gst_task_join           (GstTask *task);
126
127 G_END_DECLS
128
129 #endif /* __GST_TASK_H__ */
130