]> xenbits.xensource.com Git - people/liuw/libxenctrl-split/libvirt.git/commitdiff
internal: introduce macro helpers to check flag requirements
authorPavel Hrdina <phrdina@redhat.com>
Wed, 25 Mar 2015 12:11:38 +0000 (13:11 +0100)
committerPavel Hrdina <phrdina@redhat.com>
Mon, 4 May 2015 07:20:00 +0000 (09:20 +0200)
Similar to VIR_EXLUSIVE_FLAGS, it will error out if flag requirement is
not met.

Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
src/internal.h

index b47ea60ac6e32c1c91be39ab4d95c6fd747a686b..52e40d1facedac13f2125eede24c7aeaa2c7d56c 100644 (file)
         }                                                                   \
     } while (0)
 
+/* Macros to help dealing with flag requirements. */
+
+/**
+ * VIR_REQUIRE_FLAG_RET:
+ *
+ * @FLAG1: First flag to be checked.
+ * @FLAG2: Second flag that is required by first flag.
+ * @RET: Return value.
+ *
+ * Check whether required flag is set.  The checked flags are compared
+ * with flags variable.
+ *
+ * This helper does an early return and therefore it has to be called
+ * before anything that would require cleanup.
+ */
+# define VIR_REQUIRE_FLAG_RET(FLAG1, FLAG2, RET)                            \
+    do {                                                                    \
+        if ((flags & FLAG1) && !(flags & FLAG2)) {                          \
+            virReportInvalidArg(ctl,                                        \
+                                _("Flag '%s' is required by flag '%s'"),    \
+                                #FLAG2, #FLAG1);                            \
+            return RET;                                                     \
+        }                                                                   \
+    } while (0)
+
+/**
+ * VIR_REQUIRE_FLAG_GOTO:
+ *
+ * @FLAG1: First flag to be checked.
+ * @FLAG2: Second flag that is required by first flag.
+ * @LABEL: Label to jump to.
+ *
+ * Check whether required flag is set.  The checked flags are compared
+ * with flags variable.
+ *
+ * Returns nothing.  Jumps to a label if required flag is not set.
+ */
+# define VIR_REQUIRE_FLAG_GOTO(FLAG1, FLAG2, LABEL)                         \
+    do {                                                                    \
+        if ((flags & FLAG1) && !(flags & FLAG2)) {                          \
+            virReportInvalidArg(ctl,                                        \
+                                _("Flag '%s' is required by flag '%s'"),    \
+                                #FLAG2, #FLAG1);                            \
+            goto LABEL;                                                     \
+        }                                                                   \
+    } while (0)
+
 # define virCheckNonNullArgReturn(argname, retval)  \
     do {                                            \
         if (argname == NULL) {                      \