diff options
author | Felipe Magno de Almeida <felipe@expertisesolutions.com.br> | 2016-04-17 15:47:33 -0300 |
---|---|---|
committer | Felipe Magno de Almeida <felipe@expertisesolutions.com.br> | 2016-05-06 12:41:42 -0300 |
commit | 236c13df34576c51473463d9f0ef5247810e89e3 (patch) | |
tree | 758791ba77606a9097b4a492f2eaf46ccb69bd68 | |
parent | 8df2686d9023cac7420fbad0f1d0db105c344d85 (diff) |
eina: Add progress notify callback feature for Promise Owners
Add a way for users of the promise owner to get notified when a
promise progress is registered. Also added a convenience composition
function that creates a promise which is fulfilled when another
promise has a progress notification.
-rw-r--r-- | src/lib/eina/eina_main.c | 3 | ||||
-rw-r--r-- | src/lib/eina/eina_promise.c | 101 | ||||
-rw-r--r-- | src/lib/eina/eina_promise.h | 44 | ||||
-rw-r--r-- | src/tests/eina/eina_test_promise.c | 87 |
4 files changed, 235 insertions, 0 deletions
diff --git a/src/lib/eina/eina_main.c b/src/lib/eina/eina_main.c index 8c084dbdab..ffa9c9845c 100644 --- a/src/lib/eina/eina_main.c +++ b/src/lib/eina/eina_main.c | |||
@@ -87,6 +87,7 @@ static int _eina_main_count = 0; | |||
87 | static int _eina_main_thread_count = 0; | 87 | static int _eina_main_thread_count = 0; |
88 | #endif | 88 | #endif |
89 | static int _eina_log_dom = -1; | 89 | static int _eina_log_dom = -1; |
90 | void _eina_promise_init(void); | ||
90 | 91 | ||
91 | #ifdef ERR | 92 | #ifdef ERR |
92 | #undef ERR | 93 | #undef ERR |
@@ -299,6 +300,8 @@ eina_init(void) | |||
299 | } | 300 | } |
300 | } | 301 | } |
301 | 302 | ||
303 | _eina_promise_init(); | ||
304 | |||
302 | eina_cpu_count_internal(); | 305 | eina_cpu_count_internal(); |
303 | 306 | ||
304 | eina_log_timing(_eina_log_dom, EINA_LOG_STATE_STOP, EINA_LOG_STATE_INIT); | 307 | eina_log_timing(_eina_log_dom, EINA_LOG_STATE_STOP, EINA_LOG_STATE_INIT); |
diff --git a/src/lib/eina/eina_promise.c b/src/lib/eina/eina_promise.c index 459f686e84..2f83dc44d5 100644 --- a/src/lib/eina/eina_promise.c +++ b/src/lib/eina/eina_promise.c | |||
@@ -9,6 +9,7 @@ | |||
9 | typedef struct _Eina_Promise_Then_Cb _Eina_Promise_Then_Cb; | 9 | typedef struct _Eina_Promise_Then_Cb _Eina_Promise_Then_Cb; |
10 | typedef struct _Eina_Promise_Progress_Cb _Eina_Promise_Progress_Cb; | 10 | typedef struct _Eina_Promise_Progress_Cb _Eina_Promise_Progress_Cb; |
11 | typedef struct _Eina_Promise_Cancel_Cb _Eina_Promise_Cancel_Cb; | 11 | typedef struct _Eina_Promise_Cancel_Cb _Eina_Promise_Cancel_Cb; |
12 | typedef struct _Eina_Promise_Owner_Progress_Notify_Data _Eina_Promise_Owner_Progress_Notify_Data; | ||
12 | typedef struct _Eina_Promise_Default _Eina_Promise_Default; | 13 | typedef struct _Eina_Promise_Default _Eina_Promise_Default; |
13 | typedef struct _Eina_Promise_Default_Owner _Eina_Promise_Default_Owner; | 14 | typedef struct _Eina_Promise_Default_Owner _Eina_Promise_Default_Owner; |
14 | typedef struct _Eina_Promise_Iterator _Eina_Promise_Iterator; | 15 | typedef struct _Eina_Promise_Iterator _Eina_Promise_Iterator; |
@@ -40,6 +41,15 @@ struct _Eina_Promise_Cancel_Cb | |||
40 | void* data; | 41 | void* data; |
41 | }; | 42 | }; |
42 | 43 | ||
44 | struct _Eina_Promise_Owner_Progress_Notify_Data | ||
45 | { | ||
46 | EINA_INLIST; | ||
47 | |||
48 | Eina_Promise_Progress_Notify_Cb callback; | ||
49 | Eina_Promise_Free_Cb free_cb; | ||
50 | void* data; | ||
51 | }; | ||
52 | |||
43 | struct _Eina_Promise_Default | 53 | struct _Eina_Promise_Default |
44 | { | 54 | { |
45 | Eina_Promise vtable; | 55 | Eina_Promise vtable; |
@@ -49,6 +59,7 @@ struct _Eina_Promise_Default | |||
49 | Eina_Inlist *then_callbacks; | 59 | Eina_Inlist *then_callbacks; |
50 | Eina_Inlist *progress_callbacks; | 60 | Eina_Inlist *progress_callbacks; |
51 | Eina_Inlist *cancel_callbacks; | 61 | Eina_Inlist *cancel_callbacks; |
62 | Eina_Inlist *progress_notify_callbacks; | ||
52 | Eina_Promise_Free_Cb value_free_cb; | 63 | Eina_Promise_Free_Cb value_free_cb; |
53 | 64 | ||
54 | int ref; | 65 | int ref; |
@@ -89,6 +100,21 @@ static void _eina_promise_unref(_Eina_Promise_Default* promise); | |||
89 | 100 | ||
90 | static void _eina_promise_iterator_setup(_Eina_Promise_Iterator* iterator, Eina_Array* promises); | 101 | static void _eina_promise_iterator_setup(_Eina_Promise_Iterator* iterator, Eina_Array* promises); |
91 | 102 | ||
103 | static void _eina_promise_free_callback_list(Eina_Inlist** list, void(*free_cb)(void* node)) | ||
104 | { | ||
105 | struct node | ||
106 | { | ||
107 | EINA_INLIST; | ||
108 | } *node; | ||
109 | Eina_Inlist *list2; | ||
110 | |||
111 | EINA_INLIST_FOREACH_SAFE(*list, list2, node) | ||
112 | { | ||
113 | free_cb(node); | ||
114 | } | ||
115 | *list = NULL; | ||
116 | } | ||
117 | |||
92 | static void | 118 | static void |
93 | _eina_promise_then_calls(_Eina_Promise_Default_Owner* promise) | 119 | _eina_promise_then_calls(_Eina_Promise_Default_Owner* promise) |
94 | { | 120 | { |
@@ -188,6 +214,7 @@ _eina_promise_then(_Eina_Promise_Default* p, Eina_Promise_Cb callback, | |||
188 | { | 214 | { |
189 | _Eina_Promise_Default_Owner* promise; | 215 | _Eina_Promise_Default_Owner* promise; |
190 | _Eina_Promise_Then_Cb* cb; | 216 | _Eina_Promise_Then_Cb* cb; |
217 | _Eina_Promise_Owner_Progress_Notify_Data* notify_data; | ||
191 | 218 | ||
192 | promise = EINA_PROMISE_GET_OWNER(p); | 219 | promise = EINA_PROMISE_GET_OWNER(p); |
193 | 220 | ||
@@ -198,6 +225,12 @@ _eina_promise_then(_Eina_Promise_Default* p, Eina_Promise_Cb callback, | |||
198 | cb->data = data; | 225 | cb->data = data; |
199 | promise->promise.then_callbacks = eina_inlist_append(promise->promise.then_callbacks, EINA_INLIST_GET(cb)); | 226 | promise->promise.then_callbacks = eina_inlist_append(promise->promise.then_callbacks, EINA_INLIST_GET(cb)); |
200 | 227 | ||
228 | EINA_INLIST_FOREACH(promise->promise.progress_notify_callbacks, notify_data) | ||
229 | { | ||
230 | (*notify_data->callback)(notify_data->data, &promise->owner_vtable); | ||
231 | } | ||
232 | _eina_promise_free_callback_list(&promise->promise.progress_notify_callbacks, &free); | ||
233 | |||
201 | if (!promise->promise.is_first_then) | 234 | if (!promise->promise.is_first_then) |
202 | { | 235 | { |
203 | _eina_promise_ref(p); | 236 | _eina_promise_ref(p); |
@@ -263,11 +296,19 @@ static void | |||
263 | _eina_promise_progress_cb_add(_Eina_Promise_Default* promise, Eina_Promise_Progress_Cb callback, void* data) | 296 | _eina_promise_progress_cb_add(_Eina_Promise_Default* promise, Eina_Promise_Progress_Cb callback, void* data) |
264 | { | 297 | { |
265 | _Eina_Promise_Progress_Cb* cb; | 298 | _Eina_Promise_Progress_Cb* cb; |
299 | _Eina_Promise_Owner_Progress_Notify_Data* notify_data; | ||
300 | _Eina_Promise_Default_Owner* owner = EINA_PROMISE_GET_OWNER(promise); | ||
266 | 301 | ||
267 | cb = malloc(sizeof(struct _Eina_Promise_Progress_Cb)); | 302 | cb = malloc(sizeof(struct _Eina_Promise_Progress_Cb)); |
268 | cb->callback = callback; | 303 | cb->callback = callback; |
269 | cb->data = data; | 304 | cb->data = data; |
270 | promise->progress_callbacks = eina_inlist_append(promise->progress_callbacks, EINA_INLIST_GET(cb)); | 305 | promise->progress_callbacks = eina_inlist_append(promise->progress_callbacks, EINA_INLIST_GET(cb)); |
306 | |||
307 | EINA_INLIST_FOREACH(owner->promise.progress_notify_callbacks, notify_data) | ||
308 | { | ||
309 | (*notify_data->callback)(notify_data->data, &owner->owner_vtable); | ||
310 | } | ||
311 | _eina_promise_free_callback_list(&owner->promise.progress_notify_callbacks, &free); | ||
271 | } | 312 | } |
272 | 313 | ||
273 | static void | 314 | static void |
@@ -356,6 +397,20 @@ _eina_promise_owner_progress(_Eina_Promise_Default_Owner* promise, void* data) | |||
356 | } | 397 | } |
357 | } | 398 | } |
358 | 399 | ||
400 | static void | ||
401 | _eina_promise_owner_progress_notify(_Eina_Promise_Default_Owner* promise, Eina_Promise_Progress_Notify_Cb notify, | ||
402 | void* data, Eina_Promise_Free_Cb free_cb) | ||
403 | { | ||
404 | _Eina_Promise_Owner_Progress_Notify_Data* cb | ||
405 | = malloc(sizeof(struct _Eina_Promise_Owner_Progress_Notify_Data)); | ||
406 | |||
407 | cb->callback = notify; | ||
408 | cb->free_cb = free_cb; | ||
409 | cb->data = data; | ||
410 | promise->promise.progress_notify_callbacks = | ||
411 | eina_inlist_append(promise->promise.progress_notify_callbacks, EINA_INLIST_GET(cb)); | ||
412 | } | ||
413 | |||
359 | Eina_Promise_Owner * | 414 | Eina_Promise_Owner * |
360 | eina_promise_default_add(int value_size) | 415 | eina_promise_default_add(int value_size) |
361 | { | 416 | { |
@@ -378,6 +433,7 @@ eina_promise_default_add(int value_size) | |||
378 | p->promise.ref = 1; | 433 | p->promise.ref = 1; |
379 | memset(&p->promise.then_callbacks, 0, sizeof(p->promise.then_callbacks)); | 434 | memset(&p->promise.then_callbacks, 0, sizeof(p->promise.then_callbacks)); |
380 | memset(&p->promise.progress_callbacks, 0, sizeof(p->promise.progress_callbacks)); | 435 | memset(&p->promise.progress_callbacks, 0, sizeof(p->promise.progress_callbacks)); |
436 | memset(&p->promise.progress_notify_callbacks, 0, sizeof(p->promise.progress_notify_callbacks)); | ||
381 | memset(&p->promise.cancel_callbacks, 0, sizeof(p->promise.cancel_callbacks)); | 437 | memset(&p->promise.cancel_callbacks, 0, sizeof(p->promise.cancel_callbacks)); |
382 | p->promise.value_size = value_size; | 438 | p->promise.value_size = value_size; |
383 | p->promise.value_free_cb = NULL; | 439 | p->promise.value_free_cb = NULL; |
@@ -392,6 +448,7 @@ eina_promise_default_add(int value_size) | |||
392 | p->owner_vtable.pending_is = EINA_FUNC_PROMISE_OWNER_PENDING_IS(_eina_promise_owner_pending_is); | 448 | p->owner_vtable.pending_is = EINA_FUNC_PROMISE_OWNER_PENDING_IS(_eina_promise_owner_pending_is); |
393 | p->owner_vtable.cancelled_is = EINA_FUNC_PROMISE_OWNER_CANCELLED_IS(_eina_promise_owner_cancelled_is); | 449 | p->owner_vtable.cancelled_is = EINA_FUNC_PROMISE_OWNER_CANCELLED_IS(_eina_promise_owner_cancelled_is); |
394 | p->owner_vtable.progress = EINA_FUNC_PROMISE_OWNER_PROGRESS(_eina_promise_owner_progress); | 450 | p->owner_vtable.progress = EINA_FUNC_PROMISE_OWNER_PROGRESS(_eina_promise_owner_progress); |
451 | p->owner_vtable.progress_notify = EINA_FUNC_PROMISE_OWNER_PROGRESS_NOTIFY(_eina_promise_owner_progress_notify); | ||
395 | 452 | ||
396 | return &p->owner_vtable; | 453 | return &p->owner_vtable; |
397 | } | 454 | } |
@@ -540,6 +597,36 @@ _eina_promise_iterator_setup(_Eina_Promise_Iterator* it, Eina_Array* promises_ar | |||
540 | it->data.success_iterator_impl.free = FUNC_ITERATOR_FREE(_eina_promise_iterator_free); | 597 | it->data.success_iterator_impl.free = FUNC_ITERATOR_FREE(_eina_promise_iterator_free); |
541 | } | 598 | } |
542 | 599 | ||
600 | static void | ||
601 | _eina_promise_progress_notify_fulfilled(void* data, Eina_Promise_Owner* p EINA_UNUSED) | ||
602 | { | ||
603 | Eina_Promise_Owner* owner = data; | ||
604 | eina_promise_owner_value_set(owner, NULL, NULL); | ||
605 | } | ||
606 | |||
607 | EAPI Eina_Error EINA_ERROR_PROMISE_NO_NOTIFY; | ||
608 | |||
609 | static void | ||
610 | _eina_promise_progress_notify_failed(void* data) | ||
611 | { | ||
612 | Eina_Promise_Owner* owner = data; | ||
613 | if(eina_promise_owner_pending_is(owner)) | ||
614 | eina_promise_owner_error_set(owner, EINA_ERROR_PROMISE_NO_NOTIFY); | ||
615 | } | ||
616 | |||
617 | EAPI Eina_Promise* | ||
618 | eina_promise_progress_notification(Eina_Promise_Owner* promise) | ||
619 | { | ||
620 | Eina_Promise_Owner* owner; | ||
621 | |||
622 | owner = eina_promise_default_add(0); | ||
623 | |||
624 | eina_promise_owner_progress_notify(promise, &_eina_promise_progress_notify_fulfilled, owner, | ||
625 | &_eina_promise_progress_notify_failed); | ||
626 | |||
627 | return eina_promise_owner_promise_get(owner); | ||
628 | } | ||
629 | |||
543 | // API functions | 630 | // API functions |
544 | EAPI void | 631 | EAPI void |
545 | eina_promise_then(Eina_Promise* promise, Eina_Promise_Cb callback, | 632 | eina_promise_then(Eina_Promise* promise, Eina_Promise_Cb callback, |
@@ -643,3 +730,17 @@ eina_promise_owner_progress(Eina_Promise_Owner const* promise, void* progress) | |||
643 | { | 730 | { |
644 | promise->progress(promise, progress); | 731 | promise->progress(promise, progress); |
645 | } | 732 | } |
733 | |||
734 | EAPI void | ||
735 | eina_promise_owner_progress_notify(Eina_Promise_Owner* promise, Eina_Promise_Progress_Notify_Cb progress_cb, | ||
736 | void* data, Eina_Promise_Free_Cb free_cb) | ||
737 | { | ||
738 | promise->progress_notify(promise, progress_cb, data, free_cb); | ||
739 | } | ||
740 | |||
741 | static const char EINA_ERROR_PROMISE_NO_NOTIFY_STR[] = "Out of memory"; | ||
742 | |||
743 | void _eina_promise_init() | ||
744 | { | ||
745 | EINA_ERROR_PROMISE_NO_NOTIFY = eina_error_msg_static_register(EINA_ERROR_PROMISE_NO_NOTIFY_STR); | ||
746 | } | ||
diff --git a/src/lib/eina/eina_promise.h b/src/lib/eina/eina_promise.h index 9093b92767..75508beafe 100644 --- a/src/lib/eina/eina_promise.h +++ b/src/lib/eina/eina_promise.h | |||
@@ -20,6 +20,11 @@ typedef struct _Eina_Promise_Owner Eina_Promise_Owner; | |||
20 | typedef void(*Eina_Promise_Free_Cb)(void* value); | 20 | typedef void(*Eina_Promise_Free_Cb)(void* value); |
21 | 21 | ||
22 | /* | 22 | /* |
23 | * @brief Callback type for Promise_Owner to get notified of when someone registered a progress and/or then callback | ||
24 | */ | ||
25 | typedef void(*Eina_Promise_Progress_Notify_Cb)(void* data, Eina_Promise_Owner* promise); | ||
26 | |||
27 | /* | ||
23 | * @brief Function callback type for when using eina_promise_then | 28 | * @brief Function callback type for when using eina_promise_then |
24 | */ | 29 | */ |
25 | typedef void(*Eina_Promise_Cb)(void* data, void* value); | 30 | typedef void(*Eina_Promise_Cb)(void* data, void* value); |
@@ -162,6 +167,14 @@ typedef Eina_Bool(*Eina_Promise_Owner_Progress_Cb)(Eina_Promise_Owner const* pro | |||
162 | 167 | ||
163 | #define EINA_FUNC_PROMISE_OWNER_PROGRESS(Function) ((Eina_Promise_Owner_Progress_Cb)Function) | 168 | #define EINA_FUNC_PROMISE_OWNER_PROGRESS(Function) ((Eina_Promise_Owner_Progress_Cb)Function) |
164 | 169 | ||
170 | /* | ||
171 | * @brief Function callback type for promise owner's progress notify registration function override | ||
172 | */ | ||
173 | typedef Eina_Bool(*Eina_Promise_Owner_Progress_Notify_Cb)(Eina_Promise_Owner* promise, | ||
174 | Eina_Promise_Progress_Notify_Cb progress_cb, void* data, Eina_Promise_Free_Cb free_cb); | ||
175 | |||
176 | #define EINA_FUNC_PROMISE_OWNER_PROGRESS_NOTIFY(Function) ((Eina_Promise_Owner_Progress_Notify_Cb)Function) | ||
177 | |||
165 | 178 | ||
166 | #define EINA_PROMISE_VERSION 1 | 179 | #define EINA_PROMISE_VERSION 1 |
167 | 180 | ||
@@ -193,6 +206,7 @@ struct _Eina_Promise_Owner | |||
193 | Eina_Promise_Owner_Pending_Is_Cb pending_is; | 206 | Eina_Promise_Owner_Pending_Is_Cb pending_is; |
194 | Eina_Promise_Owner_Cancelled_Is_Cb cancelled_is; | 207 | Eina_Promise_Owner_Cancelled_Is_Cb cancelled_is; |
195 | Eina_Promise_Owner_Progress_Cb progress; | 208 | Eina_Promise_Owner_Progress_Cb progress; |
209 | Eina_Promise_Owner_Progress_Notify_Cb progress_notify; | ||
196 | #define EINA_MAGIC_PROMISE_OWNER 0x07932A5C | 210 | #define EINA_MAGIC_PROMISE_OWNER 0x07932A5C |
197 | EINA_MAGIC; | 211 | EINA_MAGIC; |
198 | }; | 212 | }; |
@@ -217,6 +231,15 @@ EAPI void eina_promise_then(Eina_Promise* promise, Eina_Promise_Cb callback, | |||
217 | EAPI Eina_Promise* eina_promise_all(Eina_Iterator* promises); | 231 | EAPI Eina_Promise* eina_promise_all(Eina_Iterator* promises); |
218 | 232 | ||
219 | /* | 233 | /* |
234 | * @brief Creates a new @Eina_Promise from another @Eina_Promise_Owner which | ||
235 | * is fulfilled when @promise has a progress callback registered | ||
236 | * | ||
237 | * @param promise Promise Owner which to be waited for a progress callback register | ||
238 | * @return Returns a new Eina_Promise | ||
239 | */ | ||
240 | EAPI Eina_Promise* eina_promise_progress_notification(Eina_Promise_Owner* promise); | ||
241 | |||
242 | /* | ||
220 | * @brief Sets value for Eina_Promise_Owner | 243 | * @brief Sets value for Eina_Promise_Owner |
221 | * | 244 | * |
222 | * This finishes the Promise and calls all eina_promise_then callbacks | 245 | * This finishes the Promise and calls all eina_promise_then callbacks |
@@ -379,6 +402,20 @@ EAPI Eina_Bool eina_promise_owner_cancelled_is(Eina_Promise_Owner const* promise | |||
379 | EAPI void eina_promise_owner_progress(Eina_Promise_Owner const* promise, void* progress); | 402 | EAPI void eina_promise_owner_progress(Eina_Promise_Owner const* promise, void* progress); |
380 | 403 | ||
381 | /* | 404 | /* |
405 | * @brief Registers a progress notify callbacks in promise owner. | ||
406 | * | ||
407 | * Registers a callback to be called for when a progress callback is | ||
408 | * registered by the linked @Eina_Promise. | ||
409 | * | ||
410 | * @param promise The promise for which to get the cancelled status | ||
411 | * @param notify_cb The callback to be called | ||
412 | * @param data The data to be passed to progress notify callback | ||
413 | * @param free_cb The free function that is called for the data param | ||
414 | */ | ||
415 | EAPI void eina_promise_owner_progress_notify(Eina_Promise_Owner* promise, | ||
416 | Eina_Promise_Progress_Notify_Cb notify_cb, void* data, Eina_Promise_Free_Cb free_cb); | ||
417 | |||
418 | /* | ||
382 | * @brief Decrement the reference count for the Eina_Promise. | 419 | * @brief Decrement the reference count for the Eina_Promise. |
383 | 420 | ||
384 | * The Eina_Promise, if its reference count drops to zero and is not | 421 | * The Eina_Promise, if its reference count drops to zero and is not |
@@ -438,6 +475,13 @@ EAPI void eina_promise_owner_default_manual_then_set(Eina_Promise_Owner* promise | |||
438 | */ | 475 | */ |
439 | EAPI void eina_promise_owner_default_call_then(Eina_Promise_Owner* promise); | 476 | EAPI void eina_promise_owner_default_call_then(Eina_Promise_Owner* promise); |
440 | 477 | ||
478 | /** | ||
479 | * @var EINA_ERROR_PROMISE_NO_NOTIFY | ||
480 | * | ||
481 | * @brief The error identifier corresponding to when a promise was | ||
482 | * free'd before any progress callback was registered | ||
483 | */ | ||
484 | EAPI extern Eina_Error EINA_ERROR_PROMISE_NO_NOTIFY; | ||
441 | 485 | ||
442 | /* | 486 | /* |
443 | * @internal | 487 | * @internal |
diff --git a/src/tests/eina/eina_test_promise.c b/src/tests/eina/eina_test_promise.c index 59ed7d7b0f..f21f5ffff9 100644 --- a/src/tests/eina/eina_test_promise.c +++ b/src/tests/eina/eina_test_promise.c | |||
@@ -236,6 +236,90 @@ START_TEST(eina_test_promise_progress) | |||
236 | } | 236 | } |
237 | END_TEST | 237 | END_TEST |
238 | 238 | ||
239 | static void progress_notify(void* data, Eina_Promise_Owner* promise EINA_UNUSED) | ||
240 | { | ||
241 | ck_assert(!*(Eina_Bool*)data); | ||
242 | *(Eina_Bool*)data = EINA_TRUE; | ||
243 | } | ||
244 | |||
245 | START_TEST(eina_test_promise_progress_notify1) | ||
246 | { | ||
247 | Eina_Bool progress_notify_ran = EINA_FALSE; | ||
248 | Eina_Promise_Owner* owner; | ||
249 | Eina_Promise* promise; | ||
250 | |||
251 | eina_init(); | ||
252 | |||
253 | owner = eina_promise_default_add(0); | ||
254 | eina_promise_owner_progress_notify(owner, &progress_notify, &progress_notify_ran, NULL); | ||
255 | |||
256 | promise = eina_promise_owner_promise_get(owner); | ||
257 | eina_promise_progress_cb_add(promise, &progress_callback, NULL); // never run | ||
258 | eina_promise_progress_cb_add(promise, &progress_callback, NULL); // never run | ||
259 | |||
260 | ck_assert(progress_notify_ran); | ||
261 | |||
262 | eina_shutdown(); | ||
263 | } | ||
264 | END_TEST | ||
265 | |||
266 | START_TEST(eina_test_promise_progress_notify2) | ||
267 | { | ||
268 | Eina_Bool progress_notify_ran = EINA_FALSE; | ||
269 | Eina_Promise_Owner* owner; | ||
270 | Eina_Promise* promise; | ||
271 | |||
272 | eina_init(); | ||
273 | |||
274 | owner = eina_promise_default_add(0); | ||
275 | eina_promise_owner_progress_notify(owner, &progress_notify, &progress_notify_ran, NULL); | ||
276 | |||
277 | promise = eina_promise_owner_promise_get(owner); | ||
278 | eina_promise_then(promise, NULL, &_cancel_promise_callback, NULL); // never run | ||
279 | eina_promise_then(promise, NULL, &_cancel_promise_callback, NULL); // never run | ||
280 | |||
281 | ck_assert(progress_notify_ran); | ||
282 | |||
283 | eina_shutdown(); | ||
284 | } | ||
285 | END_TEST | ||
286 | |||
287 | static void | ||
288 | _eina_promise_progress_notify_fulfilled(void* data, void* value EINA_UNUSED) | ||
289 | { | ||
290 | *(Eina_Bool*)data = EINA_TRUE; | ||
291 | } | ||
292 | |||
293 | static void | ||
294 | _eina_promise_progress_notify_error(void* data EINA_UNUSED, Eina_Error const* error EINA_UNUSED) | ||
295 | { | ||
296 | ck_assert(EINA_FALSE); | ||
297 | } | ||
298 | |||
299 | START_TEST(eina_test_promise_progress_notify3) | ||
300 | { | ||
301 | Eina_Bool progress_notify_ran = EINA_FALSE; | ||
302 | Eina_Promise_Owner* owner; | ||
303 | Eina_Promise* promise; | ||
304 | Eina_Promise* promise_progress; | ||
305 | |||
306 | eina_init(); | ||
307 | |||
308 | owner = eina_promise_default_add(0); | ||
309 | promise_progress = eina_promise_progress_notification(owner); | ||
310 | eina_promise_then(promise_progress, &_eina_promise_progress_notify_fulfilled, | ||
311 | &_eina_promise_progress_notify_error, &progress_notify_ran); | ||
312 | |||
313 | promise = eina_promise_owner_promise_get(owner); | ||
314 | eina_promise_progress_cb_add(promise, &progress_callback, NULL); // never run | ||
315 | eina_promise_progress_cb_add(promise, &progress_callback, NULL); // never run | ||
316 | |||
317 | ck_assert(progress_notify_ran); | ||
318 | |||
319 | eina_shutdown(); | ||
320 | } | ||
321 | END_TEST | ||
322 | |||
239 | void | 323 | void |
240 | eina_test_promise(TCase *tc) | 324 | eina_test_promise(TCase *tc) |
241 | { | 325 | { |
@@ -246,4 +330,7 @@ eina_test_promise(TCase *tc) | |||
246 | tcase_add_test(tc, eina_test_promise_values_all); | 330 | tcase_add_test(tc, eina_test_promise_values_all); |
247 | tcase_add_test(tc, eina_test_promise_cancel_promise); | 331 | tcase_add_test(tc, eina_test_promise_cancel_promise); |
248 | tcase_add_test(tc, eina_test_promise_progress); | 332 | tcase_add_test(tc, eina_test_promise_progress); |
333 | tcase_add_test(tc, eina_test_promise_progress_notify1); | ||
334 | tcase_add_test(tc, eina_test_promise_progress_notify2); | ||
335 | tcase_add_test(tc, eina_test_promise_progress_notify3); | ||
249 | } | 336 | } |