[PATCH 06/14] qapi: define enum for custom special features on commands

Daniel P. Berrangé posted 14 patches 5 months, 3 weeks ago
[PATCH 06/14] qapi: define enum for custom special features on commands
Posted by Daniel P. Berrangé 5 months, 3 weeks ago
In order to register custom special features against a command,
they have to have enum constants defined. The defined constant
values start where the last built-in special feature stops.

Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
---
 include/qapi/util.h      |  2 ++
 scripts/qapi/commands.py | 20 ++++++++++++++++++++
 2 files changed, 22 insertions(+)

diff --git a/include/qapi/util.h b/include/qapi/util.h
index 7698e789a9..3c3c9e401c 100644
--- a/include/qapi/util.h
+++ b/include/qapi/util.h
@@ -14,6 +14,8 @@
 typedef enum {
     QAPI_FEATURE_DEPRECATED,
     QAPI_FEATURE_UNSTABLE,
+
+    QAPI_FEATURE_BUILT_IN_LAST,
 } QapiSpecialFeature;
 
 typedef struct QEnumLookup {
diff --git a/scripts/qapi/commands.py b/scripts/qapi/commands.py
index 79951a841f..50a60968d4 100644
--- a/scripts/qapi/commands.py
+++ b/scripts/qapi/commands.py
@@ -347,7 +347,27 @@ def visit_begin(self, schema: QAPISchema) -> None:
         self._add_module('./init', ' * QAPI Commands initialization')
         self._genh.add(mcgen('''
 #include "qapi/qmp/dispatch.h"
+'''))
+
+        features = schema._custom_special_features['command']
+        if len(features) > 0:
+            self._genh.add(mcgen('''
+
+typedef enum {
+'''))
+            suffix = " = QAPI_FEATURE_BUILT_IN_LAST"
+            for f in features:
+                self._genh.add(mcgen('''
+    QAPI_FEATURE_%(name)s%(suffix)s,
+''', suffix=suffix, name=f.upper().replace('-', '_')))
+                suffix = ""
 
+            self._genh.add(mcgen('''
+} QapiSpecialFeatureCustom;
+
+'''))
+
+        self._genh.add(mcgen('''
 void %(c_prefix)sqmp_init_marshal(QmpCommandList *cmds);
 ''',
                              c_prefix=c_name(self._prefix, protect=False)))
-- 
2.45.1