Skip to content

Commit fedd5b6

Browse files
committed
Refactor tracker creation pattern
1 parent 9e815c0 commit fedd5b6

File tree

75 files changed

+2222
-1358
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

75 files changed

+2222
-1358
lines changed

docs/source/device/add_device.rst

Lines changed: 43 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,14 @@ The reference implementation is the **generic 3-axis foot pedal**:
1414
- :code-file:`src/core/schema/fbs/pedals.fbs`
1515
* - Device Plugin
1616
- :code-dir:`src/plugins/generic_3axis_pedal`
17-
* - Device Tracker
18-
- :code-file:`src/core/deviceio/cpp/generic_3axis_pedal_tracker.cpp`
17+
* - Tracker facade (``Generic3AxisPedalTracker``)
18+
- :code-file:`src/core/deviceio_trackers/cpp/generic_3axis_pedal_tracker.cpp` and
19+
:code-file:`src/core/deviceio_trackers/cpp/inc/deviceio/generic_3axis_pedal_tracker.hpp`
20+
* - Live backend (``LiveGeneric3AxisPedalTrackerImpl``)
21+
- :code-file:`src/core/deviceio_live_implementation/cpp/live_generic_3axis_pedal_tracker_impl.cpp` and
22+
:code-file:`src/core/deviceio_live_implementation/cpp/live_generic_3axis_pedal_tracker_impl.hpp`
23+
* - ``SchemaTracker`` / ``SampleResult``
24+
- :code-file:`src/core/deviceio_live_implementation/cpp/inc/deviceio_live_implementation/schema_tracker.hpp`
1925
* - Debug printer
2026
- :code-file:`examples/schemaio/pedal_printer.cpp`
2127

@@ -93,18 +99,26 @@ Step 3: Implement a tracker
9399
----------------------------
94100

95101
The tracker runs inside a consumer process (e.g. Teleop pipeline or a small reader app). It
96-
implements the **ITracker** interface and uses **SchemaTracker** (from the ``deviceio`` library)
97-
to read raw tensor samples from OpenXR. Implement a concrete tracker class (e.g.
102+
implements the **ITracker** interface (tracker **facade** in ``deviceio_trackers``); the
103+
**live backend** in ``deviceio_live_implementation`` composes **SchemaTracker** to read raw
104+
tensor samples from OpenXR. Implement a concrete tracker class (e.g.
98105
``Generic3AxisPedalTracker``) that:
99106

100107
- **Extends ITracker** — Override ``get_required_extensions()``, ``get_name()``,
101108
``get_schema_name()``, ``get_schema_text()``, and ``get_record_channels()``. Return
102109
``SchemaTracker::get_required_extensions()`` for extensions; return the Record type name
103110
and binary schema for MCAP; return at least one channel name.
104-
- **Holds SchemaTrackerConfig** — Same logical fields as the pusher: ``collection_id``,
105-
``max_flatbuffer_size``, ``tensor_identifier``, ``localized_name``. Must match the plugin.
106-
- **create_tracker()** — Return an ``ITrackerImpl`` that holds a ``SchemaTracker`` and
107-
implements ``update(XrTime)`` and ``serialize_all(channel_index, callback)``.
111+
- **Holds user configuration** — Same logical inputs as the pusher (e.g. ``collection_id``,
112+
``max_flatbuffer_size``). The live ``ITrackerImpl`` builds the internal tensor settings
113+
(``SchemaTrackerConfig``) so they match the plugin.
114+
- **create_tracker_impl(TrackerFactory&)** — Override this to delegate to the provided
115+
``TrackerFactory``. The implementation uses double dispatch: call the factory method
116+
specific to your tracker type (e.g.
117+
``factory.create_generic_3axis_pedal_tracker_impl(this)``) and return the resulting
118+
``std::unique_ptr<ITrackerImpl>``. The factory constructs an ``ITrackerImpl`` that holds
119+
a ``SchemaTracker``, builds a ``SchemaTrackerConfig`` from the tracker's stored
120+
configuration, and implements ``update(XrTime)`` and
121+
``serialize_all(channel_index, callback)``.
108122

109123
In the **Impl**:
110124

@@ -118,11 +132,19 @@ In the **Impl**:
118132
device disappeared and there are no samples, you may emit one record with null data and
119133
the update-tick timestamp so the MCAP stream marks absence.
120134

121-
Reference implementation: :code-file:`src/core/deviceio/cpp/generic_3axis_pedal_tracker.cpp`. It
122-
composes ``SchemaTracker``, implements ``Impl::update()`` and ``Impl::serialize_all()``,
123-
and exposes ``get_data(session)`` returning ``Generic3AxisPedalOutputTrackedT``. See also
124-
:code-file:`inc/deviceio/schema_tracker.hpp <src/core/deviceio/cpp/inc/deviceio/schema_tracker.hpp>` for ``SchemaTracker`` and ``SampleResult`` (buffer +
125-
timestamp).
135+
Reference implementation — split across facade and live backend:
136+
137+
- **Tracker facade** — :code-file:`src/core/deviceio_trackers/cpp/generic_3axis_pedal_tracker.cpp`
138+
(class ``Generic3AxisPedalTracker``): holds collection configuration, implements ``ITracker`` and
139+
``create_tracker_impl(TrackerFactory&)``, and exposes ``get_data(session)`` returning
140+
``Generic3AxisPedalOutputTrackedT`` by dispatching to the session’s
141+
``Generic3AxisPedalTrackerImpl`` (see :code-file:`src/core/deviceio_base/cpp/inc/deviceio_base/generic_3axis_pedal_tracker_impl.hpp`).
142+
- **Live backend** — :code-file:`src/core/deviceio_live_implementation/cpp/live_generic_3axis_pedal_tracker_impl.cpp`
143+
(``LiveGeneric3AxisPedalTrackerImpl``): composes ``SchemaTracker``, implements ``update()`` and
144+
``serialize_all()``, and uses ``SchemaTracker::read_all_samples()`` with
145+
``std::vector<SchemaTracker::SampleResult>`` for the pending batch. See
146+
:code-file:`src/core/deviceio_live_implementation/cpp/inc/deviceio_live_implementation/schema_tracker.hpp`
147+
for ``SchemaTracker`` and ``SampleResult`` (buffer + timestamp metadata).
126148

127149
Step 4: Implement a simple C++ printer (optional)
128150
-------------------------------------------------
@@ -182,13 +204,14 @@ Both exit after 100 samples, or press Ctrl+C to exit early.
182204
extensions: takes externally-provided OpenXR session handles, creates a tensor collection with
183205
the configured identifier, provides ``push_buffer()`` for raw serialized data. Use composition
184206
to create typed wrappers (e.g. ``Generic3AxisPedalPusher`` in :code-file:`examples/schemaio/pedal_pusher.cpp`).
185-
- **SchemaTracker** (``deviceio`` library) — Base for reading FlatBuffer schema data via OpenXR:
186-
implements ``ITracker`` for use with ``DeviceIOSession``, discovers collections by identifier,
187-
exposes ``read_all_samples()``; subclasses implement ``update()`` to deserialize and
188-
``serialize_all()`` to re-serialize typed data.
189-
- **Generic3AxisPedalTracker** — Concrete tracker for ``Generic3AxisPedalOutput``: extends
190-
``SchemaTracker`` with schema-specific deserialization and provides ``get_data()`` for the latest
191-
``Generic3AxisPedalOutputT``.
207+
- **SchemaTracker** (``deviceio_live_implementation``) — Helper for reading FlatBuffer schema data via
208+
OpenXR tensor collections: discovers collections by identifier, exposes ``read_all_samples()`` into
209+
``SampleResult`` values. Live tracker implementations (e.g. ``LiveGeneric3AxisPedalTrackerImpl``)
210+
compose a ``SchemaTracker`` and implement ``ITrackerImpl::update()`` / ``serialize_all()``.
211+
- **Generic3AxisPedalTracker** (tracker facade in ``deviceio_trackers``) — Concrete ``ITracker`` for
212+
``Generic3AxisPedalOutput``: holds configuration, implements ``create_tracker_impl()``, and
213+
``get_data(session)`` returning ``Generic3AxisPedalOutputTrackedT`` via the session’s
214+
``Generic3AxisPedalTrackerImpl``.
192215
- **DeviceIOSession** — Session manager: collects required OpenXR extensions from registered
193216
trackers, creates tracker implementations with session handles, and calls ``update()`` on all
194217
trackers during the update loop.

docs/source/device/trackers.rst

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
Device Trackers
22
===============
33

4-
Trackers (defined in :code-dir:`src/core/deviceio`) are the consumer-side API for reading device
5-
data from an active :code-file:`DeviceIOSession <src/core/deviceio/cpp/inc/deviceio/deviceio_session.hpp>`.
4+
Trackers (defined in :code-dir:`src/core/deviceio_trackers`) are the consumer-side API for reading device
5+
data from an active :code-file:`DeviceIOSession <src/core/deviceio_session/cpp/inc/deviceio/deviceio_session.hpp>`.
66
Each tracker manages one logical device, queries the OpenXR runtime every frame,
77
and exposes the latest sample through typed ``get_*()`` accessors.
88

@@ -11,17 +11,17 @@ There are two categories of trackers:
1111
**OpenXR-direct trackers** -- read pose and input data through standard OpenXR
1212
APIs (``xrLocateSpace``, ``xrSyncActions``, etc.):
1313

14-
- :code-file:`HeadTracker <src/core/deviceio/cpp/inc/deviceio/head_tracker.hpp>` -- HMD head pose
15-
- :code-file:`HandTracker <src/core/deviceio/cpp/inc/deviceio/hand_tracker.hpp>` -- articulated hand joints (left and right)
16-
- :code-file:`ControllerTracker <src/core/deviceio/cpp/inc/deviceio/controller_tracker.hpp>` -- controller poses and button/axis inputs (left and right)
17-
- :code-file:`FullBodyTrackerPico <src/core/deviceio/cpp/inc/deviceio/full_body_tracker_pico.hpp>` -- 24-joint full body pose (PICO ``XR_BD_body_tracking``)
14+
- :code-file:`HeadTracker <src/core/deviceio_trackers/cpp/inc/deviceio/head_tracker.hpp>` -- HMD head pose
15+
- :code-file:`HandTracker <src/core/deviceio_trackers/cpp/inc/deviceio/hand_tracker.hpp>` -- articulated hand joints (left and right)
16+
- :code-file:`ControllerTracker <src/core/deviceio_trackers/cpp/inc/deviceio/controller_tracker.hpp>` -- controller poses and button/axis inputs (left and right)
17+
- :code-file:`FullBodyTrackerPico <src/core/deviceio_trackers/cpp/inc/deviceio/full_body_tracker_pico.hpp>` -- 24-joint full body pose (PICO ``XR_BD_body_tracking``)
1818

1919
**SchemaTracker-based trackers** -- create new device type by defining a FlatBuffer schema and
2020
reading it from OpenXR tensor collections via the
21-
:code-file:`SchemaTracker <src/core/deviceio/cpp/inc/deviceio/schema_tracker.hpp>` utility.
21+
:code-file:`SchemaTracker <src/core/deviceio_live_implementation/cpp/inc/deviceio_live_implementation/schema_tracker.hpp>` utility.
2222

23-
- :code-file:`FrameMetadataTrackerOak <src/core/deviceio/cpp/inc/deviceio/frame_metadata_tracker_oak.hpp>` -- per-stream frame metadata from OAK cameras
24-
- :code-file:`Generic3AxisPedalTracker <src/core/deviceio/cpp/inc/deviceio/generic_3axis_pedal_tracker.hpp>` -- foot pedal axis values
23+
- :code-file:`FrameMetadataTrackerOak <src/core/deviceio_trackers/cpp/inc/deviceio/frame_metadata_tracker_oak.hpp>` -- per-stream frame metadata from OAK cameras
24+
- :code-file:`Generic3AxisPedalTracker <src/core/deviceio_trackers/cpp/inc/deviceio/generic_3axis_pedal_tracker.hpp>` -- foot pedal axis values
2525

2626
All trackers follow the same lifecycle:
2727

@@ -203,7 +203,7 @@ FrameMetadataTrackerOak
203203
~~~~~~~~~~~~~~~~~~~~~~~
204204

205205
Multi-channel tracker for per-frame metadata from OAK camera streams.
206-
Uses the :code-file:`SchemaTracker <src/core/deviceio/cpp/inc/deviceio/schema_tracker.hpp>`
206+
Uses the :code-file:`SchemaTracker <src/core/deviceio_live_implementation/cpp/inc/deviceio_live_implementation/schema_tracker.hpp>`
207207
utility internally.
208208

209209
- Schema: :code-file:`src/core/schema/fbs/oak.fbs`
@@ -224,7 +224,7 @@ Generic3AxisPedalTracker
224224
~~~~~~~~~~~~~~~~~~~~~~~~
225225

226226
Reads foot pedal axis values pushed by a device plugin through OpenXR tensor
227-
collections. Uses the :code-file:`SchemaTracker <src/core/deviceio/cpp/inc/deviceio/schema_tracker.hpp>`
227+
collections. Uses the :code-file:`SchemaTracker <src/core/deviceio_live_implementation/cpp/inc/deviceio_live_implementation/schema_tracker.hpp>`
228228
utility internally.
229229

230230
- Schema: :code-file:`src/core/schema/fbs/pedals.fbs`

src/core/CMakeLists.txt

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,15 @@ add_subdirectory(oxr)
2121
# Build PusherIO library (depends on oxr for session management)
2222
add_subdirectory(pusherio)
2323

24-
# Build DEVICEIO library first (depends on oxr_utils for types)
25-
add_subdirectory(deviceio)
24+
# DeviceIO: 4-module design
25+
# 1. deviceio_base — abstract interfaces (ITracker, TrackerFactory, typed impl bases)
26+
# 2. deviceio_trackers — public tracker classes (HeadTracker, HandTracker, etc.)
27+
# 3. deviceio_live_implementation — live OpenXR tracker impls (depends on trackers)
28+
# 4. deviceio_session — DeviceIOSession + backward-compat deviceio_core INTERFACE
29+
add_subdirectory(deviceio_base)
30+
add_subdirectory(deviceio_trackers)
31+
add_subdirectory(deviceio_live_implementation)
32+
add_subdirectory(deviceio_session)
2633

2734
# Build MCAP library (depends on deviceio for DeviceIOSession and tracker interfaces)
2835
add_subdirectory(mcap)

src/core/deviceio/cpp/CMakeLists.txt

Lines changed: 0 additions & 70 deletions
This file was deleted.

0 commit comments

Comments
 (0)