1 /* GIMP - The GNU Image Manipulation Program
2 * Copyright (C) 1995 Spencer Kimball and Peter Mattis
3 *
4 * gimpwaitable.c
5 * Copyright (C) 2018 Ell
6 *
7 * This program is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 3 of the License, or
10 * (at your option) any later version.
11 *
12 * This program 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
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program. If not, see <https://www.gnu.org/licenses/>.
19 */
20
21
22 #include "config.h"
23
24 #include <gdk-pixbuf/gdk-pixbuf.h>
25 #include <gegl.h>
26
27 #include "core-types.h"
28
29 #include "gimpwaitable.h"
30
31
G_DEFINE_INTERFACE(GimpWaitable,gimp_waitable,G_TYPE_OBJECT)32 G_DEFINE_INTERFACE (GimpWaitable, gimp_waitable, G_TYPE_OBJECT)
33
34
35 /* private functions */
36
37
38 static void
39 gimp_waitable_default_init (GimpWaitableInterface *iface)
40 {
41 }
42
43
44 /* public functions */
45
46
47 void
gimp_waitable_wait(GimpWaitable * waitable)48 gimp_waitable_wait (GimpWaitable *waitable)
49 {
50 GimpWaitableInterface *iface;
51
52 g_return_if_fail (GIMP_IS_WAITABLE (waitable));
53
54 iface = GIMP_WAITABLE_GET_INTERFACE (waitable);
55
56 if (iface->wait)
57 iface->wait (waitable);
58 }
59
60 gboolean
gimp_waitable_try_wait(GimpWaitable * waitable)61 gimp_waitable_try_wait (GimpWaitable *waitable)
62 {
63 GimpWaitableInterface *iface;
64
65 g_return_val_if_fail (GIMP_IS_WAITABLE (waitable), FALSE);
66
67 iface = GIMP_WAITABLE_GET_INTERFACE (waitable);
68
69 if (iface->try_wait)
70 {
71 return iface->try_wait (waitable);
72 }
73 else
74 {
75 gimp_waitable_wait (waitable);
76
77 return TRUE;
78 }
79 }
80
81 gboolean
gimp_waitable_wait_until(GimpWaitable * waitable,gint64 end_time)82 gimp_waitable_wait_until (GimpWaitable *waitable,
83 gint64 end_time)
84 {
85 GimpWaitableInterface *iface;
86
87 g_return_val_if_fail (GIMP_IS_WAITABLE (waitable), FALSE);
88
89 iface = GIMP_WAITABLE_GET_INTERFACE (waitable);
90
91 if (iface->wait_until)
92 {
93 return iface->wait_until (waitable, end_time);
94 }
95 else
96 {
97 gimp_waitable_wait (waitable);
98
99 return TRUE;
100 }
101 }
102
103 gboolean
gimp_waitable_wait_for(GimpWaitable * waitable,gint64 wait_duration)104 gimp_waitable_wait_for (GimpWaitable *waitable,
105 gint64 wait_duration)
106 {
107 g_return_val_if_fail (GIMP_IS_WAITABLE (waitable), FALSE);
108
109 if (wait_duration <= 0)
110 {
111 return gimp_waitable_try_wait (waitable);
112 }
113 else
114 {
115 return gimp_waitable_wait_until (waitable,
116 g_get_monotonic_time () + wait_duration);
117 }
118 }
119