summaryrefslogtreecommitdiff
path: root/taler_wallet_core_lib.h
blob: ad7d8017e4ba4f91dc5e32fa16d9af30cae23186 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
/*
   This file is part of GNU Taler
   Copyright (C) 2014-2022 Taler Systems SA

   GNU Taler is free software; you can redistribute it and/or modify it under the
   terms of the GNU Affero General Public License as published by the Free Software
   Foundation; either version 3, or (at your option) any later version.

   GNU Taler is distributed in the hope that it will be useful, but WITHOUT ANY
   WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
   A PARTICULAR PURPOSE.  See the GNU Affero General Public License for more details.

   You should have received a copy of the GNU Affero General Public License along with
   GNU Taler; see the file COPYING.  If not, see <http://www.gnu.org/licenses/>
 */

/**
 * C interface to the functionality of wallet-core.
 *
 * Currently, the underlying implementation uses the JS implementation of
 * wallet-core, but this may (or may not) change in the future.
 *
 * @author Florian Dold
 */
#ifndef _TALER_WALLET_LIB_H
#define _TALER_WALLET_LIB_H

/**
 * Opaque handle to a Taler wallet-core instance.
 */
struct TALER_WALLET_Instance;

/**
 * Handler for messages from the wallet.
 *
 * @param handler_p opaque closure for the message handler
 * @param message message from wallet-core as a JSON string
 */
typedef void (*TALER_WALLET_MessageHandlerFn)(void *handler_p, const char *message);

/**
 * Create a new wallet-core instance..
 */
struct TALER_WALLET_Instance *
TALER_WALLET_create(void);

/**
 * Set a handler for notification and response messages.
 * Must be called before the wallet runs.
 *
 * Caution: The handler will be called from a different thread.
 */
void
TALER_WALLET_set_message_handler(struct TALER_WALLET_Instance *twi,
                                 TALER_WALLET_MessageHandlerFn handler_f,
                                 void *handler_p);


/**
 * Set/override the JS file with the wallet-core implementation.
 * Must be called before the wallet runs.
 */
// FIXME: Not implemented!
//void
//TALER_WALLET_set_jsfile(struct TALER_WALLET_Instance *twi,
//                        const char *filename);

/**
 * Send a message to wallet-core.
 *
 * Responses will be sent asynchronously to the message handler
 * set with #TALER_WALLET_set_message_handler.
 */
int
TALER_WALLET_send_request(struct TALER_WALLET_Instance *twi,
                          const char *request);

/**
 * Run wallet-core in a thread.
 *
 * This function creates a new thread and returns immediately.
 *
 * Returns 0 on success or a non-zero error code otherwise.
 */
int
TALER_WALLET_run(struct TALER_WALLET_Instance *twi);

/**
 * Block until the wallet returns.
 */
void
TALER_WALLET_join(struct TALER_WALLET_Instance *twi);

/**
 * Destroy the wallet handle and free resources associated with it.
 *
 * Note that for a graceful shutdown of the wallet,
 * an appropriate shutdown message should be sent first,
 * and destroy() should only be called after the wallet has
 * sent a response to the shutdown message.
 */
//void
//TALER_WALLET_destroy(struct TALER_WALLET_Instance *twi);

/**
 * Handler for messages that should be logged.
 * 
 * @param stream NOT YET IMPLEMENTED: indicator for the stream that
 *               the message is coming from,
 */
typedef void (*TALER_LogFn)(void *cls, int stream, const char *msg);

/**
 * Redirect stderr and stdout to a function.
 * 
 * Workaround for platforms where stderr is not visible in logs.
 * 
 * @return 0 on success, error code otherwise
 */
int
TALER_start_redirect_std(TALER_LogFn logfn, void *cls);

#endif /*_TALER_WALLET_LIB_H */