| 1 | /* GStreamer |
| 2 | * Copyright (C) 2017 Matthew Waters <matthew@centricular.com> |
| 3 | * |
| 4 | * This library is free software; you can redistribute it and/or |
| 5 | * modify it under the terms of the GNU Library General Public |
| 6 | * License as published by the Free Software Foundation; either |
| 7 | * version 2 of the License, or (at your option) any later version. |
| 8 | * |
| 9 | * This library is distributed in the hope that it will be useful, |
| 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 12 | * Library General Public License for more details. |
| 13 | * |
| 14 | * You should have received a copy of the GNU Library General Public |
| 15 | * License along with this library; if not, write to the |
| 16 | * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, |
| 17 | * Boston, MA 02110-1301, USA. |
| 18 | */ |
| 19 | |
| 20 | #ifndef __GST_PROMISE_H__ |
| 21 | #define __GST_PROMISE_H__ |
| 22 | |
| 23 | #include <gst/gst.h> |
| 24 | |
| 25 | G_BEGIN_DECLS |
| 26 | |
| 27 | GST_API |
| 28 | GType gst_promise_get_type(void); |
| 29 | #define GST_TYPE_PROMISE (gst_promise_get_type()) |
| 30 | #define GST_IS_PROMISE(obj) (GST_IS_MINI_OBJECT_TYPE (obj, GST_TYPE_PROMISE)) |
| 31 | #define GST_PROMISE(obj) ((GstPromise *) obj) |
| 32 | |
| 33 | typedef struct _GstPromise GstPromise; |
| 34 | |
| 35 | /** |
| 36 | * GstPromiseResult: |
| 37 | * @GST_PROMISE_RESULT_PENDING: Initial state. Waiting for transition to any |
| 38 | * other state. |
| 39 | * @GST_PROMISE_RESULT_INTERRUPTED: Interrupted by the consumer as it doesn't |
| 40 | * want the value anymore. |
| 41 | * @GST_PROMISE_RESULT_REPLIED: A producer marked a reply |
| 42 | * @GST_PROMISE_RESULT_EXPIRED: The promise expired (the carrying object |
| 43 | * lost all refs) and the promise will never be fulfilled. |
| 44 | * |
| 45 | * The result of a #GstPromise |
| 46 | * |
| 47 | * Since: 1.14 |
| 48 | */ |
| 49 | typedef enum |
| 50 | { |
| 51 | GST_PROMISE_RESULT_PENDING, |
| 52 | GST_PROMISE_RESULT_INTERRUPTED, |
| 53 | GST_PROMISE_RESULT_REPLIED, |
| 54 | GST_PROMISE_RESULT_EXPIRED, |
| 55 | } GstPromiseResult; |
| 56 | |
| 57 | /** |
| 58 | * GstPromiseChangeFunc: |
| 59 | * @promise: a #GstPromise |
| 60 | * @user_data: (closure): user data |
| 61 | * |
| 62 | * Since: 1.14 |
| 63 | */ |
| 64 | typedef void (*GstPromiseChangeFunc) (GstPromise * promise, gpointer user_data); |
| 65 | |
| 66 | /** |
| 67 | * GstPromise: |
| 68 | * @parent: parent #GstMiniObject |
| 69 | * |
| 70 | * Since: 1.14 |
| 71 | */ |
| 72 | struct _GstPromise |
| 73 | { |
| 74 | GstMiniObject parent; |
| 75 | }; |
| 76 | |
| 77 | GST_API |
| 78 | GstPromise * gst_promise_new (void); |
| 79 | GST_API |
| 80 | GstPromise * gst_promise_new_with_change_func (GstPromiseChangeFunc func, |
| 81 | gpointer user_data, |
| 82 | GDestroyNotify notify); |
| 83 | |
| 84 | GST_API |
| 85 | GstPromiseResult gst_promise_wait (GstPromise * promise); |
| 86 | GST_API |
| 87 | void gst_promise_reply (GstPromise * promise, |
| 88 | GstStructure * s); |
| 89 | GST_API |
| 90 | void gst_promise_interrupt (GstPromise * promise); |
| 91 | GST_API |
| 92 | void gst_promise_expire (GstPromise * promise); |
| 93 | |
| 94 | GST_API |
| 95 | const GstStructure * gst_promise_get_reply (GstPromise * promise); |
| 96 | |
| 97 | #ifndef GST_DISABLE_MINIOBJECT_INLINE_FUNCTIONS |
| 98 | static inline GstPromise * |
| 99 | gst_promise_ref (GstPromise * promise) |
| 100 | { |
| 101 | return (GstPromise *) gst_mini_object_ref (GST_MINI_OBJECT_CAST (promise)); |
| 102 | } |
| 103 | |
| 104 | static inline void |
| 105 | gst_promise_unref (GstPromise * promise) |
| 106 | { |
| 107 | gst_mini_object_unref (GST_MINI_OBJECT_CAST (promise)); |
| 108 | } |
| 109 | |
| 110 | static inline void |
| 111 | gst_clear_promise (GstPromise ** promise_ptr) |
| 112 | { |
| 113 | gst_clear_mini_object ((GstMiniObject **) promise_ptr); |
| 114 | } |
| 115 | #else /* GST_DISABLE_MINIOBJECT_INLINE_FUNCTIONS */ |
| 116 | GST_API |
| 117 | GstPromise * gst_promise_ref (GstPromise * promise); |
| 118 | |
| 119 | GST_API |
| 120 | void gst_promise_unref (GstPromise * promise); |
| 121 | |
| 122 | GST_API |
| 123 | void gst_clear_promise (GstPromise ** promise_ptr); |
| 124 | #endif /* GST_DISABLE_MINIOBJECT_INLINE_FUNCTIONS */ |
| 125 | |
| 126 | G_DEFINE_AUTOPTR_CLEANUP_FUNC(GstPromise, gst_promise_unref) |
| 127 | |
| 128 | G_END_DECLS |
| 129 | |
| 130 | #endif /* __GST_PROMISE_H__ */ |
| 131 | |