Add a brei-proto.h generated header file

This will be needed to have access to the various disconnect reasons in
brei-shared.c.
This commit is contained in:
Peter Hutterer 2023-02-16 13:13:19 +10:00
parent 5631b54b96
commit 579f0d07d2
3 changed files with 57 additions and 5 deletions

View file

@ -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,

View file

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

46
src/brei-proto.h.tmpl Normal file
View file

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