Skip to content

Conversation

@rneswold
Copy link
Contributor

This pull request modifies the driver API so that hardware types can be defined and shared between drivers.

The registration method and the associated type have been moved into
their own trait, `driver::Registrator`. The `driver::API` trait is a
super trait, so all drivers must also implement this new trait.

Having the registration separate allows us to create common sets of
devices for hardware types. For instance, we can make a `Switch` trait
which registers the devices common to switches.
@rneswold rneswold linked an issue Jul 18, 2025 that may be closed by this pull request
rneswold added 6 commits July 17, 2025 21:18
In the device registration function, the `RequestChan` param was a
move. The problem with this is the driver could save the channel in
the associated type and use it during the life of the driver. The
channel is only intended to be used to register the set of devices.

In this commit, we make the `RequestChan` parameter a mutable borrow
which means it can't save it. (Hmmm. can it make a clone()? Gotta
check.)
Drivers can no longer clone or keep the request channel they are
given. This limits device registration to only when the drivers are
first started.
I originally got some of the traits to compile by returning pinning
trait objects (i.e. Pin<Box<Future<>>>.) And then the driver manager
also wrapped its `Future` with `Pin<Box<>>`. Those were rookie
mistakes of mine. Now I find I can return `impl Future<>` for those
APIs.

This commit corrects that mistake and now there's two levels of
indirection and allocation that have been removed.
The `Store` trait methods no longer return `Pin<Box<Future<>>>`. Now
they just return `impl Future<>`. This reuired a change in the state
of the `core` module since it was storing a `Box<dyn Store>`, which
isn't compatible with `impl Future<>`.

So instead of storing a pointer to a heap-allocated `Store` object, we
now place the `impl Store` directly in the state. This means less use
of the heap and no indirect calls to the methods.
@rneswold
Copy link
Contributor Author

Since making these driver traits will require a version bump for the drmem-api crate, I'm also doing some API clean-up. Many of the traits now have impl Future<> as return values instead of Pin<Box<dyn Future<>>>.

rneswold added 13 commits July 29, 2025 00:21
Commit ea238f5 didn't meet the goals I set for it. After some
research and help from Gemini, this commit comes closer to the goal.
It's still a bit wordy, so future commits may clean it up even more.

But this is the first release in which a driver can specify one of a
set of standard device naming schemes.
This is the first driver to use the common hardware types.
This is a further iteration on the driver API. I think this one hits a
lot of good points:

- Drivers need a type that implements the Registrator trait
- Removed blanket trait (which caused some problems with drivers that
  were trying to merge the driver API and Registrator traits)
- This version has less `dyn`s, less `impl`s, and less associated
  types.
This driver now uses the common `WeatherDevices` type instead of
defining its own.
- Use latest crate.
- Turn on `tcp_nodelay` to decrease write latencies.
We can get the timestamp from the reading instead of saving it twice.
@rneswold rneswold merged commit 717dbc5 into DrMemCS:main Aug 10, 2025
3 checks passed
@rneswold rneswold deleted the pr-issue154 branch August 10, 2025 20:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

✨ Add Driver Class traits

1 participant