I’ve been working on some kind of binding generator. This is based on the OH2 thing definition xml files. Currently the thing xml files are not of any help for the developer, since there at source code level no dependency between the xml file and the source code. So any change in the xml doesn’t trigger anything for the developer something should change. It’s all runtime based.
However these xml files contain a lot of information that could be used to help the developer. I started working on a generator that would create a set of interface/classes based on these xml files. I have some very early minimal code because I wanted to reuse the parsing of the xml files from the core. My implementation takes the parsed output and generates some interface/classes using javapoet. However the xml files are parsed at runtime, not compile time. So this parsing is only available through an osgi service. To get access to the parser at compile time these classes need to be available to a binding at source code level, which is not the case. However, because the core has been moved to a pure maven build this should become easier I think, and I kind of hold off to wait for this maven build to become available to see how that could be used.
My idea is to first write out how a generated a binding would look like and from that build the generator.
I haven’t completely thought out how it should look, but my idea was to generate for each thing a class and an interface. The interface contains methods for each defined channel both refresh/onHandle calls and a class that calls the interface. The developer than should implement the interface and handle the binding specific logic in there. As mentioned, this is a rough idea how it might work. I haven’t completely thought out everything.
This is all based on what is currently possible. The next level might be to research common patterns and see if it would be possible to come to some kind of xml definition from which either code is generated or at runtime certain functionality becomes available. Think of discovery support, or like all bindings have background scheduled tasks, is this something that could be generalized? I don’t know what the possibilities are, or if it would even make sense because it’s so diverse it doesn’t add any help the developer because there would be to much exceptions.
(To relate to OH1: to make it work these thing xml files should be created, which would still take some effort).