From b1030d281dc575742d4e033a89a83a4bc9a4a1b5 Mon Sep 17 00:00:00 2001 From: Daniel Wagner Date: Tue, 20 Dec 2011 15:09:18 +0100 Subject: [PATCH] dundee: Add callback helpers --- dundee/dundee.h | 44 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) diff --git a/dundee/dundee.h b/dundee/dundee.h index 4f8aa10..366938e 100644 --- a/dundee/dundee.h +++ b/dundee/dundee.h @@ -28,6 +28,50 @@ void __dundee_exit(void); +enum dundee_error_type { + DUNDEE_ERROR_TYPE_NO_ERROR = 0, + DUNDEE_ERROR_TYPE_FAILURE, +}; + +struct dundee_error { + enum dundee_error_type type; + int error; +}; + +struct cb_data { + void *cb; + void *data; + void *user; +}; + +static inline struct cb_data *cb_data_new(void *cb, void *data) +{ + struct cb_data *ret; + + ret = g_new0(struct cb_data, 1); + ret->cb = cb; + ret->data = data; + + return ret; +} + +#define CALLBACK_WITH_FAILURE(cb, args...) \ + do { \ + struct dundee_error cb_e; \ + cb_e.type = DUNDEE_ERROR_TYPE_FAILURE; \ + cb_e.error = 0; \ + \ + cb(&cb_e, ##args); \ + } while (0) \ + +#define CALLBACK_WITH_SUCCESS(f, args...) \ + do { \ + struct dundee_error e; \ + e.type = DUNDEE_ERROR_TYPE_NO_ERROR; \ + e.error = 0; \ + f(&e, ##args); \ + } while(0) \ + #include int __ofono_log_init(const char *program, const char *debug, -- 2.7.4