pez-globo / pufferfish-software

All software for the Pufferfish ventilator.
Apache License 2.0
0 stars 1 forks source link

Refactor backend state store #319

Open ethanjli opened 3 years ago

ethanjli commented 3 years ago

Currently the backend's state store is a dict associating protobuf message types as keys to protobuf message instances as values. This leads to an awkward type system (as accessing state segments in the store requires a typecast). We should instead make the backend state store more like the firmware state store, where state segment objects are statically typed, but still are accessed by indexing on a value (either a protobuf message type, or as will be done in #313, a StateSegment enum; this might also require moving state input from the StateSynchronizer protocol into the Backend protocol, like what we do in the firmware).

One option might be to define a Store class (or dataclass) with members, and to define a custom way of accessing members by passing in an enum.

ethanjli commented 3 years ago

A first pass of refactoring was done in #313, but it only partially addresses this issue. Now we have a StateSegment enum, and we're accessing segments in all_states using it, but we still have an awkward type system where we have to cast every state segment we access. We should add strong typing to the store, as described above.