dundee: Add callback helpers
authorDaniel Wagner <daniel.wagner@bmw-carit.de>
Tue, 20 Dec 2011 14:09:18 +0000 (15:09 +0100)
committerDaniel Wagner <daniel.wagner@bmw-carit.de>
Tue, 22 May 2012 16:44:46 +0000 (18:44 +0200)
dundee/dundee.h

index 4f8aa10..366938e 100644 (file)
 
 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 <ofono/log.h>
 
 int __ofono_log_init(const char *program, const char *debug,