Commit Graph

39 Commits

Author SHA1 Message Date
Abhishek Verma
e24b1cb8bb host/mpm: replace mpRPC with gRPC transport
host:
Replace the msgpack-RPC (rpclib) client with a gRPC-based
implementation. Add auto-generated C++ client and Python bindings
from protobuf definitions. Remove rpclib dependency and integrate
FindgRPC into CMake.

mpm:
Replace the msgpack-RPC server with a gRPC server generated from
protobuf definitions. Add pb_utils.py for type conversion between
Python and protobuf. Update rpc_server.py to dispatch calls via
gRPC stubs. Update mpm_shell to use gRPC. Replace pyudev with sysfs
scan in uio device discovery.

Bump MPM compatibility number to 7.0 and RPC version to 2.

This change requires new depedencies. E.g. for Ubuntu 24.04 or 25.10:
libgrpc++-dev, libprotobuf-dev, protobuf-compiler-grpc, python3-grpcio
2026-07-09 12:12:04 +02:00
Lars Amsel
699cff5941 uhd: Surround all open() calls with with-statement
In addition to commit ab8ec99733
this adds `with` statements to remaining files in the UHD code base.
2026-02-20 12:20:10 +01:00
Aki Tomita
52ee565f26 rpc: Fix operators in object class
This commit makes it explicit which assignment operators
and constructors are available on the object class.
Furthermore the copy constructor and assignment operator
make deep copies of the object. This prevents double free
operations with the rpc_error class.
2026-02-05 13:46:17 +01:00
Aki Tomita
b72cbb14e3 rpc: Use perfect forwarding in rpc code
Some instances of RPC code had rvalue reference arguments but did
not use std::forward wenn passing these arguments (or the other
way around). This harmonizes arguments and parameter forwarding to
always use rvalue ref and std::forward in pairs.
2026-02-05 13:46:17 +01:00
Lars Amsel
12eae2d365 Host: RPC: Fix double free in rpclib call function
During tests with the reinitialization of the MPM, we discovered that the
USRP session sometimes ended with an access violation. The root cause was
a call to reset_timer_and_mgr, which was sent using notify_with_token
from the rpclib. This function internally performs a notify, which
itself makes a call. The call invokes the function as an async_call and
subsequently attempts to retrieve the result of the future from the
async_call, provided no timeout occurs.

The issue arose because the call did not use rvalue references for the
variadic array. As a result, the variadic array values were copied during
the call and then deallocated afterward. However, the rpclib also retained
a pointer to the variadic array, which led to a double free after the
async_call completed. The problem became evident when the memory
management code enabled heap protection (e.g., the ucrtd.dll on Windows,
which writes hex-D into unallocated memory). In most other cases, these
regions are initialized to 0, and freeing a 0 pointer is effectively a
no-op.

The fix introduces lvalue passing of the variadic array in the call
function, which prevents double free errors. This change ensures that the
callee no longer frees the array. The fix has also been applied to
async_call and send.
2025-12-10 13:14:58 +01:00
Lars Amsel
230be28208 Host: format rpc client files before applying changes to it 2025-12-10 13:14:58 +01:00
Aki Tomita
4706e33232 host: include chrono to files using chrono_literals and other components 2025-11-07 14:56:42 +01:00
Martin Braun
b58808fecf uhd: Add asio abstraction header
This adds uhdlib/asio.hpp, which makes it possible for UHD to use either
Boost.Asio or regular asio. Note that for using regular asio, additional
CMake changes are required, which are not part of this changeset, and
all C++ sources would need to reference namespace asio:: instead of
boost::asio::, which is also not part of this changeset.

However, the boost/asio.hpp include statement is now limited to a single
location, which makes it possible to set custom include preferences for
this file. Here, we allow gcc builds to allow some warnings when
including Boost.Asio.
2025-07-30 01:59:01 +02:00
Martin Braun
2f5136c9e9 deps: Remove BOOST_VERSION checks
The checks are all covered by our CMake Boost checkery.
2025-04-15 08:29:36 +02:00
Martin Braun
3fb9555bee deps: rpclib: Remove dependency on __cplusplus value
In some cases, rpclib uses the value of the `__cplusplus` macro to
determine implementation details. We remove these, as UHD requires C++17
anyway now and the value of __cplusplus may be broken depending on
compilers.
2025-04-15 08:29:36 +02:00
Martin Braun
adfe953d96 uhd: Update ASIO usage to modern style, compatible with Boost 1.87
Starting with Boost 1.66 and the corresponding ASIO version, there were
some changes introduced based on the C++ Networking TS. This includes
changes like replacing io_service with io_context, deprecating some
functions, etc. Starting with Boost 1.87, the old style is no longer
supported.

This commit updates all usage of ASIO in a way that makes UHD compatible
with future versions of ASIO. However, this makes UHD no longer
compatible with Boost 1.65 and below.

Summary of changes:
- Replace asio::io_service with asio::io_context
- Replace asio::io_service::strand with
  asio::strand<asio::io_context::executor_type>
  - This implies using asio::post() instead of asio::strand::post()
- Replace asio::buffer_cast<T>(buf) with static_cast<T>(buf.data())
- Update resolve(query) with new API
- Replace references to endpoint_iterator with resolver::results_type
- Replace ip::address::from_string() with ip::make_address()

Co-authored-by: Jörg Hofrichter <joerg.hofrichter@emerson.com>
2024-12-11 14:37:26 +01:00
Joerg Hofrichter
84f270a3dd deps: rpclib: support detection of arm64 architecture for Windows
Fixes #785 Cannot build for Windows on ARM64
2024-11-29 11:01:02 +01:00
Martin Braun
ceeadd4704 deps: rpclib: Silence comments on unused constexpr lambda captures
Different compilers are not in agreement how to handle captures for
constexprs. On recent clang versions, a warning such as this is produced:

 warning: lambda capture 'max_read_bytes' is not required to be captured
 for this use [-Wunused-lambda-capture]

However, some versions of MSVC *require* the capture, so we have to
leave it in and live with the warnings. We therefore disable the
warnings as they have no value for us.
2024-10-29 17:59:59 +01:00
Martin Braun
2dc7b3e572 lib: deps: rpclib: Fix future C++ compatibility
In C++20, copy-capture of `this` must be made explicit, which we fix
with this commit. In C++17, auto_ptr is deprecated so we replace it with
unique_ptr.
2024-10-21 17:42:57 +02:00
Marian Koop
1d1226f768 python: pybind: Bump min pybind11 version to 2.7 (default on Ubuntu 22)
This will result into use of the in-tree version on Ubuntu 20,
and address an observed crash during object cleanup at program
shutdown that was only observed on Ubuntu 20. This restores the
behavior earlier UHD version to use the in-tree pybind11 module
for Ubuntu 20.
Also corrected some logic determining when the in-tree module
was used to avoid that both a public and our in-tree modules are
part of the INCLUDE_DIRS.
2024-06-11 10:20:08 +02:00
Steven Koo
ed1da9aa78 python: update to pybind11 for Python 3.11
Python 3.11 did not build correctly with previous versions of pybind11.
This updates the headers to pybind 2.10.0, which does.

Signed-off-by: Steven Koo <steven.koo@ni.com>
2022-08-22 12:45:38 -05:00
Aaron Rossetto
1716a31e73 deps: rpclib: Replace distutils.dir_util with shutil
This commit replaces the use of distutils.dir_util.copy_tree() with the
equivalent function shutil.copytree().
2022-01-14 14:36:39 -06:00
Martin Braun
0c5c2e39f9 lib: deps: Upgrade vendor version of Pybind11 to 2.6.1
- Copied include/pybind11 directory over from source repo
- Also re-ran remove_comments.py as before

This fixes this warning on newer Python libraries:

.../internals.h: 200:9: warning: 'PyEval_InitThreads' is deprecated
    [-Wdeprecated-declarations]
    PyEval_InitThreads();
    ^
    /usr/include/python3.9/ceval.h:130:1: note: 'PyEval_InitThreads' has
    been explicitly marked deprecated here
    Py_DEPRECATED(3.9) PyAPI_FUNC(void) PyEval_InitThreads(void);
    ^
    /usr/include/python3.9/pyport.h:508:54: note: expanded from macro
    'Py_DEPRECATED'
    #define Py_DEPRECATED(VERSION_UNUSED) __attribute__((__deprecated__))

It also obviates the need for patches to Pybind11 to silence clang
warnings.
2021-06-23 07:14:12 -05:00
Aaron Rossetto
7a9ec29dbc rpclib: Fix warning on ARM build 2021-03-04 12:09:17 -06:00
Martin Braun
681713aaae lib: deps: Ignore more warnings in our versions of rpclib, pybind11
This modifies the UHD versions of those libraries to turn off warnings
that appear with Clang.
2021-03-04 08:24:28 -06:00
Gwenhael Goavec-Merou
16b38ff6c6 msgpack/predef: add riscV support 2021-01-21 12:55:03 -06:00
Martin Braun
e760e5372b deps: rpclib: Fix issue on socket closing
The rpclib server session closes its socket, which can fail. In our
case, we only use the server for some tests, and we close the server on
process exit, so we let the error slide. Since we close servers in
dtors, not doing so would occasionally cause SIGABRT.
2020-10-09 12:31:33 -05:00
Martin Braun
1bba62a75a Remove remaining Python 2 references
This changes two things in all applicable files:
- Remove imports from __future__
- Change default shebangs from /usr/bin/env python to /usr/bin/env
  python3
2020-05-07 15:10:41 -05:00
Martin Braun
a80ec7c58a rpclib: Remove some warnings from object.hpp
This removes -Wmaybe-uninitialized and -Wclass-memaccess from this file
when using gcc.
2020-04-14 10:29:29 -05:00
Martin Braun
c755531eac lib: deps: Add FlatBuffers 1.11.0 header files
FlatBuffers is used to (de-)serialize calibration data. For most use
cases, only a few headers are required, so we provide them with UHD
instead of requiring all UHD users to install their own version of
FlatBuffers.

This adds the headers to host/lib/deps, and updates the Debian copyright
file appropriately.
2020-03-18 12:53:00 -05:00
Martin Braun
1fe98e8701 uhd: Replace usage of boost smart pointers with C++11 counterparts
This removes the following Boost constructs:
- boost::shared_ptr, boost::weak_ptr
- boost::enable_shared_from_this
- boost::static_pointer_cast, boost::dynamic_pointer_cast

The appropriate includes were also removed. All C++11 versions of these
require #include <memory>.
Note that the stdlib and Boost versions have the exact same syntax, they
only differ in the namespace (boost vs. std). The modifications were all
done using sed, with the exception of boost::scoped_ptr, which was
replaced by std::unique_ptr.

References to boost::smart_ptr were also removed.

boost::intrusive_ptr is not removed in this commit, since it does not
have a 1:1 mapping to a C++11 construct.
2019-11-26 12:21:32 -08:00
Mark Meserve
c6eeef3722 rpclib: add patch file for constructor hang 2019-10-15 08:13:45 -07:00
Mark Meserve
931595b012 rpclib: fix hang on connection error during construction 2019-10-15 08:13:45 -07:00
Brent Stapleton
431deb855b uhd: mpm: update all license header w/ "-or-later"
Updating all SPDX license identifiers to include "-or-later"
2019-03-08 00:43:07 +01:00
Martin Braun
51bbf548c9 deps: Add PyBind11 2019-02-22 16:56:52 -08:00
Martin Braun
a69ab0c23a cmake: Update coding style to use lowercase commands
Also updates our coding style file.

Ancient CMake versions required upper-case commands.  Later command
names became case-insensitive.  Now the preferred style is lower-case.

Run the following shell code (with GNU compliant sed):

cmake --help-command-list | grep -v "cmake version" | while read c; do
  echo 's/\b'"$(echo $c | tr '[:lower:]' '[:upper:]')"'\(\s*\)(/'"$c"'\1(/g'
done > convert.sed \
&& git ls-files -z -- bootstrap '*.cmake' '*.cmake.in' \
'*CMakeLists.txt' | xargs -0 gsed -i -f convert.sed && rm convert.sed

(Make sure the backslashes don't get mangled!)
2018-11-14 14:10:09 -08:00
Martin Braun
ae5211d71d uhd: Update license headers
All copyright is now attributed to "Ettus Research, a National
Instruments company".

SPDX headers were also updated to latest version 3.0.
2018-02-19 16:54:52 -08:00
Martin Braun
40f8617348 fixup! rpclib: fix use of "boost::asio::strand" -> "boost::asio::io_service::strand" 2018-01-22 16:07:53 -08:00
Michael Dickens
c4080003f5 rpclib: fix use of "boost::asio::strand" -> "boost::asio::io_service::strand"
The former was marked as deprecated numerous Boost versions ago and
finally was actually removed & replaced in 1.66.0 with a new one with a
template API. The version in rpclib need to be updated, and Boost docs
say to use the latter. Moving to this usage takes care of this issue.

Reviewed-by: Martin Braun <martin.braun@ettus.com>
2018-01-22 15:34:28 -08:00
Martin Braun
b0dc9fd677 Move all headers to SPDX format, harmonize license headers 2017-12-22 15:47:10 -08:00
Martin Braun
ba287c272a rpclib: Add more Windows compile definitions 2017-12-22 15:03:59 -08:00
Martin Braun
65713fa6f5 Rename netd to mpmd 2017-12-22 15:03:53 -08:00
Andrej Rode
c8ae32253b usrp: add netd find and impl, add uhd rpc client wrapper 2017-12-22 15:03:45 -08:00
Andrej Rode
53795c74ae uhd: add cut-down rpclib source tree and import tool 2017-12-22 15:03:45 -08:00