mirror of
https://github.com/EttusResearch/uhd.git
synced 2026-10-25 17:36:10 +00:00
mpm: avoid importing from rpc_server when importing usrp_mpm
Importing from usrp_mpm.rpc_server imports a lot of dependencies which are unnecessary if the rpc_server functionality is not actually needed. Move the decorator functions to a new file rpc_utils.py and import only from this file inside periph_manager. usrp_hwd.py needs additional dependencies which are specifically imported: - usrp_mpm.rpc_server.spawn_rpc_process - usrp_mpm.discovery.spawn_discovery_process
This commit is contained in:
parent
a94202a2b4
commit
ba5028cf57
@ -13,6 +13,8 @@ import time
|
||||
import argparse
|
||||
from gevent import signal
|
||||
import usrp_mpm as mpm
|
||||
import usrp_mpm.rpc_server
|
||||
import usrp_mpm.discovery
|
||||
from usrp_mpm.mpmtypes import SharedState
|
||||
from usrp_mpm.sys_utils import watchdog
|
||||
|
||||
@ -162,14 +164,14 @@ def spawn_processes(log, args):
|
||||
shared = SharedState()
|
||||
log.info("Spawning RPC process...")
|
||||
_PROCESSES.append(
|
||||
mpm.spawn_rpc_process(
|
||||
mpm.rpc_server.spawn_rpc_process(
|
||||
shared, mpm.mpmtypes.MPM_RPC_PORT, args.default_args))
|
||||
log.debug("RPC process has PID: %d", _PROCESSES[-1].pid)
|
||||
if watchdog.has_watchdog():
|
||||
watchdog.transfer_control(_PROCESSES[-1].pid)
|
||||
log.info("Spawning discovery process...")
|
||||
_PROCESSES.append(
|
||||
mpm.spawn_discovery_process(shared, args.discovery_addr)
|
||||
mpm.discovery.spawn_discovery_process(shared, args.discovery_addr)
|
||||
)
|
||||
log.debug("Discovery process has PID: %d", _PROCESSES[-1].pid)
|
||||
log.info("Processes launched. Registering signal handlers.")
|
||||
|
||||
@ -9,8 +9,6 @@ MPM Module
|
||||
|
||||
__simulated__ = ("${MPM_DEVICE}" == "sim")
|
||||
|
||||
from .discovery import spawn_discovery_process
|
||||
from .rpc_server import spawn_rpc_process
|
||||
from . import compat_num
|
||||
from . import mpmtypes
|
||||
from . import gpsd_iface
|
||||
|
||||
@ -10,7 +10,7 @@ import os
|
||||
import re
|
||||
import shutil
|
||||
import subprocess
|
||||
from usrp_mpm.rpc_server import no_rpc
|
||||
from usrp_mpm.rpc_utils import no_rpc
|
||||
|
||||
|
||||
class ZynqComponents:
|
||||
|
||||
@ -10,7 +10,7 @@ Mixin class for daughterboard classes that live on a X4xx motherboard
|
||||
from usrp_mpm.mpmlog import get_logger
|
||||
from usrp_mpm import tlv_eeprom
|
||||
from usrp_mpm.sys_utils.udev import get_eeprom_paths_by_symbol
|
||||
from usrp_mpm.rpc_server import no_rpc
|
||||
from usrp_mpm.rpc_utils import no_rpc
|
||||
|
||||
# pylint: disable=too-few-public-methods
|
||||
class EepromTagMap:
|
||||
|
||||
@ -22,7 +22,7 @@ from usrp_mpm.sys_utils.udev import get_spidev_nodes
|
||||
from usrp_mpm.sys_utils import dtoverlay
|
||||
from usrp_mpm.sys_utils import net
|
||||
from usrp_mpm.xports import XportAdapterMgr
|
||||
from usrp_mpm.rpc_server import no_claim, no_rpc
|
||||
from usrp_mpm.rpc_utils import no_claim, no_rpc
|
||||
from usrp_mpm.mpmutils import get_dboard_class_from_pid
|
||||
from usrp_mpm import eeprom
|
||||
from usrp_mpm import prefs
|
||||
|
||||
@ -16,7 +16,7 @@ from usrp_mpm.dboard_manager import E31x_db
|
||||
from usrp_mpm.gpsd_iface import GPSDIfaceExtension
|
||||
from usrp_mpm.mpmutils import assert_compat_number, str2bool
|
||||
from usrp_mpm.periph_manager import PeriphManagerBase
|
||||
from usrp_mpm.rpc_server import no_rpc, _get_map_for_rpc
|
||||
from usrp_mpm.rpc_utils import no_rpc, get_map_for_rpc
|
||||
from usrp_mpm.sys_utils import dtoverlay
|
||||
from usrp_mpm.sys_utils.sysfs_thermal import read_sysfs_sensors_value
|
||||
from usrp_mpm.sys_utils.udev import get_spidev_nodes
|
||||
@ -696,7 +696,7 @@ class e31x(ZynqComponents, PeriphManagerBase):
|
||||
mboard info again. This filters the EEPROM contents to what we think
|
||||
the user wants to know/see.
|
||||
"""
|
||||
return _get_map_for_rpc(self.mboard_info, self.log)
|
||||
return get_map_for_rpc(self.mboard_info, self.log)
|
||||
|
||||
def set_mb_eeprom(self, _eeprom_vals):
|
||||
"""
|
||||
|
||||
@ -18,7 +18,7 @@ from usrp_mpm.dboard_manager import Neon
|
||||
from usrp_mpm.gpsd_iface import GPSDIfaceExtension
|
||||
from usrp_mpm.mpmutils import assert_compat_number, str2bool
|
||||
from usrp_mpm.periph_manager import PeriphManagerBase
|
||||
from usrp_mpm.rpc_server import no_rpc, _get_map_for_rpc
|
||||
from usrp_mpm.rpc_utils import no_rpc, get_map_for_rpc
|
||||
from usrp_mpm.sys_utils import dtoverlay
|
||||
from usrp_mpm.sys_utils.sysfs_thermal import read_thermal_sensor_value, read_thermal_sensors_value
|
||||
from usrp_mpm.sys_utils.udev import get_spidev_nodes
|
||||
@ -647,7 +647,7 @@ class e320(ZynqComponents, PeriphManagerBase):
|
||||
mboard info again. This filters the EEPROM contents to what we think
|
||||
the user wants to know/see.
|
||||
"""
|
||||
return _get_map_for_rpc(self.mboard_info, self.log)
|
||||
return get_map_for_rpc(self.mboard_info, self.log)
|
||||
|
||||
def set_mb_eeprom(self, eeprom_vals):
|
||||
"""
|
||||
|
||||
@ -18,7 +18,7 @@ from usrp_mpm.components import ZynqComponents
|
||||
from usrp_mpm.gpsd_iface import GPSDIfaceExtension
|
||||
from usrp_mpm.periph_manager import PeriphManagerBase
|
||||
from usrp_mpm.mpmutils import assert_compat_number, str2bool, poll_with_timeout
|
||||
from usrp_mpm.rpc_server import no_rpc, _get_map_for_rpc
|
||||
from usrp_mpm.rpc_utils import no_rpc, get_map_for_rpc
|
||||
from usrp_mpm.sys_utils import dtoverlay
|
||||
from usrp_mpm.sys_utils import i2c_dev
|
||||
from usrp_mpm.sys_utils.sysfs_thermal import read_thermal_sensor_value
|
||||
@ -927,7 +927,7 @@ class n3xx(ZynqComponents, PeriphManagerBase):
|
||||
mboard info again. This filters the EEPROM contents to what we think
|
||||
the user wants to know/see.
|
||||
"""
|
||||
return _get_map_for_rpc(self.mboard_info, self.log)
|
||||
return get_map_for_rpc(self.mboard_info, self.log)
|
||||
|
||||
def get_db_eeprom(self, dboard_idx):
|
||||
"""
|
||||
|
||||
@ -13,7 +13,7 @@ configuration by using the cmake flag -DMPM_DEVICE=sim
|
||||
from pyroute2 import IPRoute
|
||||
from usrp_mpm.xports import XportMgrUDP
|
||||
from usrp_mpm.mpmlog import get_logger
|
||||
from usrp_mpm.rpc_server import no_claim
|
||||
from usrp_mpm.rpc_utils import no_claim
|
||||
from usrp_mpm.periph_manager import PeriphManagerBase
|
||||
from usrp_mpm.simulator.sim_dboard import registry as dboards
|
||||
from usrp_mpm.simulator.chdr_endpoint import ChdrEndpoint
|
||||
|
||||
@ -21,7 +21,7 @@ from usrp_mpm.sys_utils import ectool
|
||||
from usrp_mpm.sys_utils import i2c_dev
|
||||
from usrp_mpm.sys_utils.gpio import Gpio
|
||||
from usrp_mpm.sys_utils.udev import dt_symbol_get_spidev
|
||||
from usrp_mpm.rpc_server import no_claim, no_rpc
|
||||
from usrp_mpm.rpc_utils import no_claim, no_rpc
|
||||
from usrp_mpm.mpmutils import assert_compat_number, poll_with_timeout
|
||||
from usrp_mpm.periph_manager import PeriphManagerBase
|
||||
from usrp_mpm.xports import XportMgrUDP
|
||||
|
||||
@ -45,7 +45,7 @@ from usrp_mpm.mpmutils import parse_multi_device_arg, str2bool
|
||||
from usrp_mpm.periph_manager.x4xx_clk_aux import ClockingAuxBrdControl
|
||||
from usrp_mpm.periph_manager.x4xx_clock_types import RpllRefSel, BrcSource
|
||||
from usrp_mpm.periph_manager.x4xx_clock_ctrl import X4xxClockCtrl
|
||||
from usrp_mpm.rpc_server import no_rpc
|
||||
from usrp_mpm.rpc_utils import no_rpc
|
||||
|
||||
class X4xxClockManager:
|
||||
"""
|
||||
|
||||
@ -12,7 +12,7 @@ import itertools
|
||||
from dataclasses import dataclass
|
||||
from usrp_mpm import lib # Pulls in everything from C++-land
|
||||
from usrp_mpm.periph_manager.x4xx_rfdc_regs import RfdcRegsControl
|
||||
from usrp_mpm.rpc_server import no_rpc
|
||||
from usrp_mpm.rpc_utils import no_rpc
|
||||
from usrp_mpm.mpmutils import LogRuntimeError
|
||||
|
||||
RFDC_DEVICE_ID = 0
|
||||
|
||||
@ -29,6 +29,8 @@ from usrp_mpm.mpmlog import get_main_logger
|
||||
from usrp_mpm.mpmutils import to_binary_str
|
||||
from usrp_mpm.sys_utils import watchdog
|
||||
from usrp_mpm.sys_utils import net
|
||||
from usrp_mpm.rpc_utils import get_map_for_rpc
|
||||
|
||||
|
||||
TIMEOUT_INTERVAL = 5.0 # Seconds before claim expires (default value)
|
||||
LOCK_ACQ_TIMEOUT = 1 # Seconds to wait for acquiring shared lock (default value)
|
||||
@ -36,16 +38,6 @@ TOKEN_LEN = 16 # Length of the token string
|
||||
# Compatibility number for MPM
|
||||
MPM_COMPAT_NUM = (5, 3)
|
||||
|
||||
def no_claim(func):
|
||||
" Decorator for functions that require no token check "
|
||||
func._notok = True
|
||||
return func
|
||||
|
||||
def no_rpc(func):
|
||||
" Decorator for functions that should not be exposed via RPC "
|
||||
func._norpc = True
|
||||
return func
|
||||
|
||||
class MPMServer(RPCServer):
|
||||
"""
|
||||
Main MPM RPC class which holds the periph_manager object and translates
|
||||
@ -442,7 +434,7 @@ class MPMServer(RPCServer):
|
||||
get device information
|
||||
This is as safe method which can be called without a claim on the device
|
||||
"""
|
||||
info = _get_map_for_rpc(self.periph_manager.get_device_info(), self.log)
|
||||
info = get_map_for_rpc(self.periph_manager.get_device_info(), self.log)
|
||||
info["mpm_version"] = "{}.{}".format(*MPM_COMPAT_NUM)
|
||||
if _is_connection_local(self.client_host):
|
||||
info["connection"] = "local"
|
||||
@ -654,16 +646,3 @@ def spawn_rpc_process(state, udp_port, default_args):
|
||||
)
|
||||
proc.start()
|
||||
return proc
|
||||
|
||||
|
||||
def _get_map_for_rpc(map, log):
|
||||
"""
|
||||
ensure the map contains only string values otherwise it cannot be
|
||||
casted to std::map<string, string> in C++
|
||||
# TODO reconsider the workaround once we transition away from mprpc
|
||||
"""
|
||||
for key, value in map.items():
|
||||
if value is None:
|
||||
log.warning('casting parameter "{}" from None to "n/a"'.format(key))
|
||||
map[key] = "n/a"
|
||||
return map
|
||||
|
||||
31
mpm/python/usrp_mpm/rpc_utils.py
Normal file
31
mpm/python/usrp_mpm/rpc_utils.py
Normal file
@ -0,0 +1,31 @@
|
||||
#!/usr/bin/env python3
|
||||
#
|
||||
# Copyright 2018 Ettus Research, a National Instruments Company
|
||||
#
|
||||
# SPDX-License-Identifier: GPL-3.0-or-later
|
||||
#
|
||||
"""
|
||||
Implements decorators and utility functions to be used with the RPC server
|
||||
"""
|
||||
|
||||
def no_claim(func):
|
||||
" Decorator for functions that require no token check "
|
||||
func._notok = True
|
||||
return func
|
||||
|
||||
def no_rpc(func):
|
||||
" Decorator for functions that should not be exposed via RPC "
|
||||
func._norpc = True
|
||||
return func
|
||||
|
||||
def get_map_for_rpc(map, log):
|
||||
"""
|
||||
ensure the map contains only string values otherwise it cannot be
|
||||
casted to std::map<string, string> in C++
|
||||
# TODO reconsider the workaround once we transition away from mprpc
|
||||
"""
|
||||
for key, value in map.items():
|
||||
if value is None:
|
||||
log.warning('casting parameter "{}" from None to "n/a"'.format(key))
|
||||
map[key] = "n/a"
|
||||
return map
|
||||
Loading…
Reference in New Issue
Block a user