1 /* GSequencer - Advanced GTK Sequencer
2  * Copyright (C) 2005-2020 Joël Krähemann
3  *
4  * This file is part of GSequencer.
5  *
6  * GSequencer is free software: you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation, either version 3 of the License, or
9  * (at your option) any later version.
10  *
11  * GSequencer is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with GSequencer.  If not, see <http://www.gnu.org/licenses/>.
18  */
19 
20 #ifndef __AGS_TASK_H__
21 #define __AGS_TASK_H__
22 
23 #include <glib.h>
24 #include <glib-object.h>
25 
26 G_BEGIN_DECLS
27 
28 #define AGS_TYPE_TASK                (ags_task_get_type())
29 #define AGS_TYPE_TASK_FLAGS                (ags_task_flags_get_type())
30 #define AGS_TASK(obj)                (G_TYPE_CHECK_INSTANCE_CAST((obj), AGS_TYPE_TASK, AgsTask))
31 #define AGS_TASK_CLASS(class)        (G_TYPE_CHECK_CLASS_CAST((class), AGS_TYPE_TASK, AgsTaskClass))
32 #define AGS_IS_TASK(obj)             (G_TYPE_CHECK_INSTANCE_TYPE((obj), AGS_TYPE_TASK))
33 #define AGS_IS_TASK_CLASS(class)     (G_TYPE_CHECK_CLASS_TYPE((class), AGS_TYPE_TASK))
34 #define AGS_TASK_GET_CLASS(obj)      (G_TYPE_INSTANCE_GET_CLASS((obj), AGS_TYPE_TASK, AgsTaskClass))
35 
36 #define AGS_TASK_GET_OBJ_MUTEX(obj) (&(((AgsTask *) obj)->obj_mutex))
37 
38 typedef struct _AgsTask AgsTask;
39 typedef struct _AgsTaskClass AgsTaskClass;
40 
41 /**
42  * AgsTaskFlags:
43  * @AGS_TASK_LOCKED: the task is locked
44  * @AGS_TASK_CYCLIC: call task repeatedly
45  *
46  * Enum values to control the behavior or indicate internal state of #AgsTask by
47  * enable/disable as flags.
48  */
49 typedef enum{
50   AGS_TASK_LOCKED   = 1,
51   AGS_TASK_CYCLIC   = 1 <<  1,
52 }AgsTaskFlags;
53 
54 struct _AgsTask
55 {
56   GObject gobject;
57 
58   guint flags;
59 
60   GRecMutex obj_mutex;
61 
62   gchar *task_name;
63 
64   GObject *task_launcher;
65 };
66 
67 struct _AgsTaskClass
68 {
69   GObjectClass gobject;
70 
71   void (*launch)(AgsTask *task);
72 
73   void (*failure)(AgsTask *task, GError *error);
74 };
75 
76 GType ags_task_get_type();
77 
78 gboolean ags_task_test_flags(AgsTask *task, guint flags);
79 void ags_task_set_flags(AgsTask *task, guint flags);
80 void ags_task_unset_flags(AgsTask *task, guint flags);
81 
82 void ags_task_launch(AgsTask *task);
83 void ags_task_failure(AgsTask *task, GError *error);
84 
85 AgsTask* ags_task_new();
86 
87 G_END_DECLS
88 
89 #endif /*__AGS_TASK_H__*/
90