diff options
Diffstat (limited to 'src/reducer/anastasis_api_redux.c')
-rw-r--r-- | src/reducer/anastasis_api_redux.c | 61 |
1 files changed, 55 insertions, 6 deletions
diff --git a/src/reducer/anastasis_api_redux.c b/src/reducer/anastasis_api_redux.c index 796e60d..92801f4 100644 --- a/src/reducer/anastasis_api_redux.c +++ b/src/reducer/anastasis_api_redux.c | |||
@@ -1491,6 +1491,31 @@ dummy_cleanup (void *cls) | |||
1491 | 1491 | ||
1492 | 1492 | ||
1493 | /** | 1493 | /** |
1494 | * Closure for external_redux_done. | ||
1495 | */ | ||
1496 | struct ExternalReduxCls | ||
1497 | { | ||
1498 | ANASTASIS_ActionCallback cb; | ||
1499 | void *cb_cls; | ||
1500 | json_t *new_state; | ||
1501 | }; | ||
1502 | |||
1503 | |||
1504 | /** | ||
1505 | * Callback called when the redux action has been processed by | ||
1506 | * the external reducer. | ||
1507 | */ | ||
1508 | static void | ||
1509 | external_redux_done (void *cls) | ||
1510 | { | ||
1511 | struct ExternalReduxCls *erc = cls; | ||
1512 | erc->cb (erc->cb_cls, | ||
1513 | TALER_EC_NONE, | ||
1514 | erc->new_state); | ||
1515 | } | ||
1516 | |||
1517 | |||
1518 | /** | ||
1494 | * Handle an action using an external reducer, i.e. | 1519 | * Handle an action using an external reducer, i.e. |
1495 | * by shelling out to another process. | 1520 | * by shelling out to another process. |
1496 | */ | 1521 | */ |
@@ -1563,9 +1588,26 @@ redux_action_external (const char *ext_reducer, | |||
1563 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 1588 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, |
1564 | "Wrote old state to reducer stdin.\n"); | 1589 | "Wrote old state to reducer stdin.\n"); |
1565 | 1590 | ||
1566 | next_state = json_loadf (reducer_stdout, | 1591 | { |
1567 | 0, | 1592 | json_error_t err; |
1568 | NULL); | 1593 | |
1594 | next_state = json_loadf (reducer_stdout, | ||
1595 | 0, | ||
1596 | &err); | ||
1597 | |||
1598 | if (NULL == next_state) | ||
1599 | { | ||
1600 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
1601 | "External reducer did not output valid JSON: %s:%d:%d %s\n", | ||
1602 | err.source, | ||
1603 | err.line, | ||
1604 | err.column, | ||
1605 | err.text); | ||
1606 | GNUNET_assert (0 == fclose (reducer_stdout)); | ||
1607 | waitpid (pid, &status, 0); | ||
1608 | return NULL; | ||
1609 | } | ||
1610 | } | ||
1569 | 1611 | ||
1570 | /* FIXME: report error instead! */ | 1612 | /* FIXME: report error instead! */ |
1571 | GNUNET_assert (NULL != next_state); | 1613 | GNUNET_assert (NULL != next_state); |
@@ -1584,9 +1626,16 @@ redux_action_external (const char *ext_reducer, | |||
1584 | /* Callback is called immediately, cleanup must never be called */ | 1626 | /* Callback is called immediately, cleanup must never be called */ |
1585 | act->cleanup = &dummy_cleanup; | 1627 | act->cleanup = &dummy_cleanup; |
1586 | 1628 | ||
1587 | cb (cb_cls, | 1629 | { |
1588 | TALER_EC_NONE, | 1630 | struct ExternalReduxCls *sched_cls = GNUNET_new (struct ExternalReduxCls); |
1589 | next_state); | 1631 | |
1632 | sched_cls->cb = cb; | ||
1633 | sched_cls->cb_cls = cb_cls; | ||
1634 | sched_cls->new_state = next_state; | ||
1635 | GNUNET_SCHEDULER_add_now (external_redux_done, | ||
1636 | sched_cls); | ||
1637 | } | ||
1638 | |||
1590 | return act; | 1639 | return act; |
1591 | } | 1640 | } |
1592 | 1641 | ||