From 323d794df3f5846fabee1e4efad11e9232543df7 Mon Sep 17 00:00:00 2001 From: Ryan Pavlik Date: Tue, 7 Jul 2020 10:54:16 -0500 Subject: [PATCH] ipc: Add a json schema for the IPC description --- src/xrt/ipc/proto.json | 2 + src/xrt/ipc/proto.py | 4 +- src/xrt/ipc/proto.schema.json | 97 +++++++++++++++++++++++++++++++++++ 3 files changed, 102 insertions(+), 1 deletion(-) create mode 100644 src/xrt/ipc/proto.schema.json diff --git a/src/xrt/ipc/proto.json b/src/xrt/ipc/proto.json index b4f64bb9a..f60333197 100644 --- a/src/xrt/ipc/proto.json +++ b/src/xrt/ipc/proto.json @@ -1,4 +1,6 @@ { + "$schema": "./proto.schema.json", + "instance_get_shm_fd": { "out_fds": true }, diff --git a/src/xrt/ipc/proto.py b/src/xrt/ipc/proto.py index a5af0fffc..0a5540425 100755 --- a/src/xrt/ipc/proto.py +++ b/src/xrt/ipc/proto.py @@ -151,7 +151,9 @@ class Proto: def __init__(self, data): """Construct a protocol from a dictionary of calls.""" - self.calls = [Call(name, call) for name, call in data.items()] + self.calls = [Call(name, call) for name, call + in data.items() + if not name.startswith("$")] header = '''// Copyright 2020, Collabora, Ltd. diff --git a/src/xrt/ipc/proto.schema.json b/src/xrt/ipc/proto.schema.json new file mode 100644 index 000000000..dc4bc5d88 --- /dev/null +++ b/src/xrt/ipc/proto.schema.json @@ -0,0 +1,97 @@ +{ + "$schema": "http://json-schema.org/draft-07/schema", + "$id": "http://gitlab.freedesktop.org/monado/monado/src/xrt/ipc/proto.schema.json", + "type": "object", + "title": "Protocol schema", + "description": "The root schema for an entire protocol.", + "definitions": { + "scalar": { + "title": "Known scalar type", + "type": "string", + "enum": [ + "uint32_t", + "int64_t", + "uint64_t" + ] + }, + "aggregate": { + "title": "Struct or union type", + "type": "string", + "pattern": "(struct|union) xrt_[a-z_]+" + }, + "scalar_enum": { + "title": "Custom enum (scalar)", + "type": "string", + "pattern": "enum xrt_[a-z_]+" + }, + "param": { + "type": "object", + "title": "Parameter", + "required": [ + "name", + "type" + ], + "properties": { + "name": { + "title": "Parameter name", + "type": "string" + }, + "type": { + "title": "Parameter type", + "anyOf": [ + { + "$ref": "#/definitions/scalar" + }, + { + "$ref": "#/definitions/aggregate" + }, + { + "$ref": "#/definitions/scalar_enum" + } + ] + } + } + }, + "param_list": { + "title": "Parameter list", + "type": "array", + "additionalItems": { + "$ref": "#/definitions/param" + } + } + }, + "properties": { + "$schema": { + "type": "string" + } + }, + "additionalProperties": { + "$id": "#/call", + "type": "object", + "title": "IPC Call", + "properties": { + "id": { + "type": "string", + "title": "Call ID", + "description": "If left unspecified or empty, the ID will be constructed by prepending IPC_ to the call name in all upper-case." + }, + "out_fds": { + "$id": "#/call/properties/out_fds", + "type": "boolean", + "title": "Call returns fds?", + "default": false, + "examples": [ + true + ] + }, + "in": { + "title": "Input parameters", + "$ref": "#/definitions/param_list" + }, + "out": { + "title": "Output parameters", + "$ref": "#/definitions/param_list" + } + } + } +}