diff --git a/meson.build b/meson.build index c5003d6..f348f2f 100644 --- a/meson.build +++ b/meson.build @@ -70,6 +70,12 @@ dep_libutil = declare_dependency(link_with: lib_util) proto_c_template = files('src/ei-proto.c.tmpl') proto_h_template = files('src/ei-proto.h.tmpl') +brei_proto_h_template = files('src/brei-proto.h.tmpl') + +brei_proto_headers = custom_target('brei-proto-headers', + input: protocol_xml, + output: ['brei-proto.h'], + command: [scanner, '--component=brei', '--output=@OUTPUT@', '@INPUT@', brei_proto_h_template]) ei_proto_headers = custom_target('ei-proto-headers', input: protocol_xml, @@ -97,7 +103,7 @@ src_libei = files( 'src/libei-seat.c', 'src/libei-socket.c', 'src/libei-touchscreen.c', -) + [ei_proto_headers, ei_proto_sources] +) + [brei_proto_headers, ei_proto_headers, ei_proto_sources] deps_libei = [ dep_libutil, @@ -151,7 +157,7 @@ src_libeis = files( 'src/libeis-seat.c', 'src/libeis-socket.c', 'src/libeis-touchscreen.c', -) + [eis_proto_headers, eis_proto_sources] +) + [brei_proto_headers, eis_proto_headers, eis_proto_sources] lib_libeis = shared_library('eis', src_libeis, diff --git a/proto/ei-scanner b/proto/ei-scanner index e412a80..302efa8 100755 --- a/proto/ei-scanner +++ b/proto/ei-scanner @@ -299,7 +299,7 @@ class Interface: @classmethod def create(cls, name: str, version: int, mode: str = "ei") -> "Interface": - assert mode in ["ei", "eis"] + assert mode in ["ei", "eis", "brei"] return cls(name=name, version=version, mode=mode) @@ -577,7 +577,7 @@ def parse(protofile: Path, component: str) -> Protocol: def generate_source( proto: Protocol, headerfile: Optional[str], template: Path, component: str ) -> jinja2.environment.TemplateStream: - assert component in ["ei", "eis"] + assert component in ["ei", "eis", "brei"] data = {} data["component"] = component @@ -643,7 +643,7 @@ def main() -> None: formatter_class=argparse.RawDescriptionHelpFormatter ) - parser.add_argument("--component", type=str, choices=["ei", "eis"], default="ei") + parser.add_argument("--component", type=str, choices=["ei", "eis", "brei"], default="ei") parser.add_argument( "--output", type=str, default="-", help="Output file to write to" ) diff --git a/src/brei-proto.h.tmpl b/src/brei-proto.h.tmpl new file mode 100644 index 0000000..1663017 --- /dev/null +++ b/src/brei-proto.h.tmpl @@ -0,0 +1,46 @@ +/** + * GENERATED FILE, DO NOT EDIT + * + * SPDX-License-Identifier: MIT + */ + +{# this is a jinja template, warning above is for the generated file + + Non-obvious variables set by the scanner that are used in this template: + - request.fqdn/event.fqdn - the full name of a request/event with the + interface name prefixed, "ei_foo_request_bar" or "ei_foo_event_bar" + - incoming/outgoing: points to the list of requests or events, depending + which one is the outgoing one from the perspective of the file we're + generating (ei or eis) +#} + +{# target: because eis is actually eis_client in the code, the target points to + either "ei" or "eis_client" and we need the matching get_context or + get_client for those. This is specific to the libei/libeis implementation + so it's done here in the template only. #} +{% if component == "eis" %} +{% set target = { "name": "eis_client", "context": "client" } %} +{% else %} +{% set target = { "name": "ei", "context": "context" } %} +{% endif %} + +#pragma once + +#ifdef _cplusplus +extern "C" { +#endif + +{% for interface in interfaces %} +{% for enum in interface.enums %} +enum {{enum.fqdn}} { + {% for entry in enum.entries %} + {{enum.fqdn.upper()}}_{{entry.name.upper()}} = {{entry.value}}, + {% endfor %} +}; +{% endfor %} +{% endfor %} + +#ifdef _cplusplus +} +#endif +