Repository navigation
Commit e5e5920
committed
hal: C++ API (hal.hh) and pybind11 bindings on the 64-bit HAL API
Reintroduce a C++ interface for HAL, replacing the old hal.hh that was removed ahead of the API break. It is built strictly on the public C API and the query API: no hal_priv.h, no direct shared memory access, no re-implemented library internals.
- hal.hh: type-safe, header-only C++ layer in linuxcnc::hal, exported to include/. Typed pin/param handles via traits<T> over rtapi_bool, rtapi_sint, rtapi_uint and rtapi_real (compile-time accessor selection, no 32-bit handles), a runtime-typed pin_t variant and anypin for name-based access, a component class with add_pin for the struct-member idiom, and ULAPI by-name query/set functions on hal_get_p/hal_set_p/hal_get_s/hal_set_s/hal_comp_by_name.
Handles re-read the shmem slot on every access so hal_link() slot rewrites stay visible (C pointer-variable semantics). Handles are move-only; HAL objects are unique. Query callback paths are exception-free; range errors are reported after the library releases the HAL mutex.
- Streams: linuxcnc::hal::stream, a move-only wrapper around hal_stream_t, created with a depth and a typestring or attached to an existing key. Element types drive the conversion of samples in both directions with the same range checks as the by-name setters. Library failures reported as a negative errno are thrown as std::system_error.
- halpybind.cc: pybind11 module (halpp.so) exposing component, Pin, stream and the by-name functions. Built alongside _hal/hal.py, replacing nothing. Type and direction tags are the _hal.Type/_hal.Dir IntEnum classes: arguments accept the members or plain ints, results come back as members. Importing _hal also initializes the HAL library. String set values go through setps_common_cb for halcmd-consistent parsing, std::system_error becomes OSError, and SIGTERM raises KeyboardInterrupt as it does in _hal.
- Ports: linuxcnc::hal::port, a move-only handle for HAL_PORT pins with all-or-nothing read/peek/peek_commit/write plus readable/writable/size/clear, created with component::newport() or runtime-typed newpin(). The buffer belongs to the linking signal and is sized with set_signal(); an unlinked port has no buffer and its reads and writes fail quietly. A port pin has no scalar value: get_value() and the runtime-typed get/set raise for it, leaving hal_get_p()/hal_set_p() semantics on port pins to the library. The size is read from the signal (get_value() on a port signal) or with port::size(). halpp exposes the same calls on Pin, with bytes in and out (str is written as UTF-8).
- tests/halpp: Python and native C++ smoke suites, plus a stream create/attach pair across two processes the way sampler and streamer are used. The C++ suite compiles against the tree, so the test is skipped for installed packages.
Based on the pybind11 branch by rene-dev, rebuilt on the new HAL API.1 parent 086258b commit e5e5920
13 files changed
Lines changed: 1776 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
399 | 399 | | |
400 | 400 | | |
401 | 401 | | |
| 402 | + | |
402 | 403 | | |
403 | 404 | | |
404 | 405 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
24 | 24 | | |
25 | 25 | | |
26 | 26 | | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
27 | 38 | | |
28 | 39 | | |
0 commit comments