common: Add helper macros for D-Bus handlers 08/199808/3
authorKarol Lewandowski <k.lewandowsk@samsung.com>
Thu, 14 Feb 2019 13:45:36 +0000 (14:45 +0100)
committerKarol Lewandowski <k.lewandowsk@samsung.com>
Fri, 15 Feb 2019 11:12:26 +0000 (12:12 +0100)
Change-Id: Ic1364f9f26db759ac1a8949410d2a97303950d78

src/common/macro.h

index cad7aa9..bec65d4 100644 (file)
@@ -30,6 +30,7 @@
 #include <assert.h>
 #include <stdio.h>
 #include <config.h>
+#include <glib.h>
 
 #ifndef API
 #define API __attribute__((visibility("default")))
        }                                       \
 } while (0)
 
+#define ret_unless(val) \
+       do { \
+               if (!(val)) { \
+                       _E("Invalid parameter value (`" #val "` check failed)"); \
+                       return; \
+               } \
+       } while (0)
+
 #define ret_value_if(expr, val) do {                                   \
        if (expr) {                                                     \
                _E("(%s) -> %s():%d return", #expr, __FUNCTION__, __LINE__); \
        }                                                       \
 } while (0)
 
+#define ret_if_gvariant_type_mismatch(gvariant, type) \
+       do { \
+               if (g_variant_is_of_type(gvariant, G_VARIANT_TYPE(type))) { \
+                       _E("Invalid parameter type (expected: %s, got: %s)", \
+                          type, g_variant_get_type_string(gvariant)); \
+                       return; \
+               } \
+       } while (0)
+
+
 #define gslist_for_each_item(item, list)                               \
        for (item = list; item != NULL; item = g_slist_next(item))