Repository navigation
feat(kernel): publish and receive objects of runtime classes - #536
Draft
EnriqueParodi wants to merge 10 commits into
Draft
EnriqueParodi wants to merge 10 commits into
EnriqueParodi wants to merge 10 commits into
Conversation
The runtime compatibility check refused a remote alias against the type it aliases. A generated subscriber holding a u8 refused a publisher whose class holds a FOM's Octet, an alias of u8, and the publication was rejected. Where the check compares what the remote side writes with a local type that is neither an alias nor an optional, a remote alias is now taken as the type it aliases. Only refusals can become acceptances: a class accepted before is accepted the same, with the same lossy conversions. A local alias or optional is checked as before, and so are method arguments, where the two sides are swapped. getRuntimeDifferences, used for a debug log, also lists a remote alias as the type it aliases, unless the local type is an alias. Release note: a remote class whose members are aliases of the local class's member types is now accepted instead of refused.
GenericRemoteObject's header moves from the kernel's private sources to sen/kernel/detail/ and is installed with the kernel's other detail headers, so that code outside the kernel can tell a GenericRemoteObject from a generated proxy. Only the include guard changes, and the two includes of the old path are updated. Release note: new installed detail header sen/kernel/detail/generic_remote_object.h.
When the writer's class differed from the reader's, GenericRemoteObject decoded a changed property or event argument with the reader's type, from bytes in the writer's layout. The value was misread, and so was the rest of the stream. A changed member is now decoded with the writer's type and converted to the reader's, as generated proxies do in RemoteObject::readOrAdapt. Members are matched by name, never by position, so a renamed field or argument counts as a different member. An event with an argument that has no match among the writer's is dropped with a warning. Members whose types agree, and identical classes, are read as before. The class is exported and documented now that its header is installed. Unit tests cover a widened property, an unchanged class, a reordered and widened event argument, and an event dropped for a missing argument.
A remote object whose class the local kernel knows but has no proxy makers for, such as a class built at runtime, was refused at discovery with a logic_error, and its subscribers never received it. It now gets a GenericRemoteObject of the local class, which startTrackingProxy already creates for a class without makers. Classes with makers are unaffected. Release note: a subscriber whose kernel knows a class only as a runtime definition now receives remote objects of that class as GenericRemoteObjects, instead of an exception at discovery.
sen::impl::EncodedFieldReader reads one field of a property directly from the property's Sen encoding. It lets query filters work on objects that hold their properties encoded and have no generated code, such as GenericLocalObject. resolve() works out once where the field sits in the encoding; read() then takes it from the current bytes without decoding the rest. It returns what a generated getter returns, so a filter gives the same answer on both kinds of object. The exception is an optional, which it reads as its value or as no value, where a generated getter cannot read one. Release note: new installed core detail header sen/core/obj/detail/encoded_field_reader.h.
NativeObject gains senImplMakeLocalProxy, which returns the proxy a subscriber in the same process holds for the object, already holding the object's current state. The default is what the proxy manager did: the class's generated local proxy, drained once; a null proxy is no longer drained. The proxy manager now calls it, so an object whose values a generated proxy cannot read can provide its own proxy. The choice is made per object, not per class. Release note: NativeObject has a new virtual function, senImplMakeLocalProxy, so components must be rebuilt.
GenericLocalObject is a NativeObject for a class with no generated code, such as one read from a FOM at runtime. It holds each property as its Sen encoding, so a gateway can publish what it decodes without building Vars. Values are set by index, or as a block of records keyed by property id, and become current at the next commit, as in a generated class. It writes the same updates a generated object of the same class writes. A class with generated proxy makers is rejected, and so is an empty value. Queries read it through EncodedFieldReader. Only property getters can be called on it. GenericLocalObjectProxy is the local proxy GenericLocalObject makes through senImplMakeLocalProxy. Like a generated proxy, it keeps its own copy of the values, updated at each drainInputs, and notifies the properties that changed. It reads the object through EncodedPropertyValues, comparing each encoding with its copy and copying only what differs. Given PropertyChangeTimes, it notifies a property whenever its change time moves, stamped with that time. Generated proxies and GenericRemoteObject are unaffected. Release note: new installed detail headers sen/kernel/detail/generic_local_object.h and sen/kernel/detail/generic_local_object_proxy.h.
One process publishes dummy_entities' generated aircraft. The other imports the FOM that dummy_fom is generated from at runtime, into its own registry, and subscribes with an interest built from that registry. The test passes when the aircraft arrives as a GenericRemoteObject of the imported class, with its entity type read as sent. It depends on the discovery fix and on reading in the writer's layout. runner.py now accepts any number of supporting instances before the tester, so a two-process test needs no third. Existing three-argument runs are unchanged.
One process imports the FOM at runtime into its own registry and publishes an aircraft as a GenericLocalObject. The other uses dummy_fom's generated classes and subscribes through the typed interface. The test passes when three changes arrive through the generated proxy as they were set, with the entity type intact. It depends on the alias fix in the compatibility check: the FOM's simple data types are aliases at runtime and native types in generated code.
The replayer installed its own local proxy maker on each recorded class, process-wide, and never removed it. A subscriber in the same process got a ReplayedObjectProxy, whose state writes and typed connection removal threw std::logic_error, so a recorder in the same process could not snapshot a replay. When the recorded class had generated code, the maker also served live objects of that class, and their local subscribers crashed on a null owner. ReplayedObject now implements EncodedPropertyValues and PropertyChangeTimes, and makes a GenericLocalObjectProxy as its local proxy. The maker injection and ReplayedObjectProxy are removed. Subscribers get the same notifications as before: each property whose recorded time moved, stamped with that time, statics and repeated values included. Reads come from the subscriber's copy as of its last update, as with generated proxies, so a value read always matches the last change notified; ReplayedObjectProxy read the replayed object live. The state writes give that copy, and removing a typed connection does nothing. Tests cover a subscriber in another component recording a replay, a live object of a replayed class keeping its generated proxy, the notified times, and a value changed without its time moving, which is read but not notified. Release note: a subscriber in the same process as a replay can snapshot and record replayed objects, and live objects of a replayed class keep their generated local proxies. Replayed objects are read as of the subscriber's last update.
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What and why
Sen fully supports only objects whose class has generated C++ code. A gateway that reads an from a different protocol at runtime has no generated code for the classes it finds, so it cannot publish objects of them, and a subscriber that knows a class only at runtime has its remote objects refused at discovery. This change closes the gap with Sen's existing mechanisms, without a new kernel registry.
GenericRemoteObject, the proxy for a remote object whose class has no generated proxy here, is now an installed detail header. A remote object of a class known only at runtime reaches its subscribers instead of throwing at discovery. When the writer's class differs from the reader's, members are decoded with the writer's types and converted, matched by name, as generated proxies do.GenericLocalObjectholds each property as its Sen encoding and otherwise behaves like a generated object: values take effect at the next commit, and it writes the same updates a generated object of the same class writes. Queries filter on it throughEncodedFieldReader, a new core class that reads one field straight from a property's encoding.NativeObject::senImplMakeLocalProxylets an object provide the proxy that subscribers in the same process hold. By default it returns the class's generated proxy, as before.GenericLocalObjectprovides aGenericLocalObjectProxy.Octetmatches a generatedu8instead of being refused.For users:
NativeObjectgains a virtual function, so components must be rebuilt. A subscriber in the same process as a replay reads replayed values as of its last update, like any generated proxy, instead of live.Tests: unit tests for each new class, including a comparison of
GenericLocalObjectwith a generated object of the same class (36 query paths, and every write mode byte for byte). Two integration tests run across processes: a subscriber that imports the FOM at runtime receives objects from generated code, and a runtime publisher reaches a generated subscriber. Replayer tests cover the operations that threw. The replayer benchmark is as fast as before or faster with subscribers in the same process.Checklist
type(scope): summaryand stays under 72 characters.conan/conan.lockwas regenerated ifconanfile.pychanged (it did not change)