diff mbox series

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

Message ID 20240604153242.251334-7-berrange@redhat.com (mailing list archive)
State New
Headers show
Series Improve mechanism for configuring allowed commands | expand

Commit Message

Daniel P. Berrangé June 4, 2024, 3:32 p.m. UTC
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 mbox series

Patch

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)))