diff mbox series

[RFC,v2,4/7] libxl: add DeviceFunction classes to IDL

Message ID 5eba989c046387c17549d634841f8215c2fc5893.1614734296.git.rosbrookn@ainfosec.com (mailing list archive)
State New
Headers show
Series add function support to IDL | expand

Commit Message

Nick Rosbrook March 3, 2021, 1:46 a.m. UTC
Add a DeviceFunction base class, and Device{Add,Remove,Destroy}Function
classes to idl.py. These classes will allow the device functions to be
generated later in gentypes.py.

The base class, DeviceFunction, extends CtxFunction and adds a domid
parameter to the function's parameter list. When creating a DeviceFunction,
the device parameter must be specified, and extra parameters can be specified
if necessary.

Rather than indicating specific device actions in the DeviceFunction
class, child classes are created for each device function type. Right
now, DeviceAddFunction does not extend the base class. DeviceRemoveFunction
adds the option of specifying 'custom_remove' parameter when custom remove
functions are needed. DeviceDestroyFunction is a child of DeviceRemoveFunction
to inherit the custom_remove attribute.

Signed-off-by: Nick Rosbrook <rosbrookn@ainfosec.com>
---
 tools/libs/light/idl.py | 23 +++++++++++++++++++++++
 1 file changed, 23 insertions(+)
diff mbox series

Patch

diff --git a/tools/libs/light/idl.py b/tools/libs/light/idl.py
index a8a4768efc..570b168079 100644
--- a/tools/libs/light/idl.py
+++ b/tools/libs/light/idl.py
@@ -379,6 +379,29 @@  class CtxFunction(Function):
 
         Function.__init__(self, name, params, return_type)
 
+class DeviceFunction(CtxFunction):
+    """ A function that modifies a domain's devices. """
+    def __init__(self, name=None, device_param=None, extra_params=None,
+                 return_type=None):
+        self.device_param = device_param
+
+        params = [ ("domid", uint32), device_param ] + extra_params
+
+        CtxFunction.__init__(self, name, params, return_type)
+
+class DeviceAddFunction(DeviceFunction):
+    pass
+
+class DeviceRemoveFunction(DeviceFunction):
+    def __init__(self, name=None, device_param=None, extra_params=None,
+                 return_type=None, custom_remove=None):
+        self.custom_remove = custom_remove
+
+        DeviceFunction.__init__(self, name, device_param, extra_params, return_type)
+
+class DeviceDestroyFunction(DeviceRemoveFunction):
+    pass
+
 def parse(f):
     print("Parsing %s" % f, file=sys.stderr)