Public Types | Public Member Functions | Static Public Member Functions | Static Public Attributes | Private Member Functions | Static Private Member Functions | Private Attributes | List of all members
uavcan_linux::MachineIDReader Class Reference

#include <system_utils.hpp>

Public Types

typedef std::array< std::uint8_t, MachineIDSizeMachineID
 

Public Member Functions

 MachineIDReader (const std::vector< std::string > &extra_search_locations={})
 
MachineID read () const
 
std::pair< MachineID, std::string > readAndGetLocation () const
 

Static Public Member Functions

static std::vector< std::string > getDefaultSearchLocations ()
 

Static Public Attributes

static constexpr int MachineIDSize = 16
 

Private Member Functions

bool tryRead (const std::string &location, MachineID &out_id) const
 

Static Private Member Functions

static std::vector< std::string > mergeLists (const std::vector< std::string > &a, const std::vector< std::string > &b)
 

Private Attributes

const std::vector< std::string > search_locations_
 

Detailed Description

This class can find and read machine ID from a text file, represented as 32-char (16-byte) long hexadecimal string, possibly with separators (like dashes or colons). If the available ID is more than 16 bytes, extra bytes will be ignored. A shorter ID will not be accepted as valid. In order to be read, the ID must be located on the first line of the file and must not contain any whitespace characters.

Examples of valid ID: 0123456789abcdef0123456789abcdef 20CE0b1E-8C03-07C8-13EC-00242C491652

Definition at line 32 of file system_utils.hpp.

Member Typedef Documentation

◆ MachineID

typedef std::array<std::uint8_t, MachineIDSize> uavcan_linux::MachineIDReader::MachineID

Definition at line 37 of file system_utils.hpp.

Constructor & Destructor Documentation

◆ MachineIDReader()

uavcan_linux::MachineIDReader::MachineIDReader ( const std::vector< std::string > &  extra_search_locations = {})
inline

This class can use extra seach locations. If provided, they will be checked first, before default ones.

Definition at line 108 of file system_utils.hpp.

Member Function Documentation

◆ getDefaultSearchLocations()

static std::vector<std::string> uavcan_linux::MachineIDReader::getDefaultSearchLocations ( )
inlinestatic

Definition at line 39 of file system_utils.hpp.

◆ mergeLists()

static std::vector<std::string> uavcan_linux::MachineIDReader::mergeLists ( const std::vector< std::string > &  a,
const std::vector< std::string > &  b 
)
inlinestaticprivate

Definition at line 52 of file system_utils.hpp.

◆ read()

MachineID uavcan_linux::MachineIDReader::read ( ) const
inline

Just like readAndGetLocation(), but this one doesn't return location where this ID was obtained from.

Definition at line 115 of file system_utils.hpp.

◆ readAndGetLocation()

std::pair<MachineID, std::string> uavcan_linux::MachineIDReader::readAndGetLocation ( ) const
inline

This function checks available search locations and reads the ID from the first valid location. It returns std::pair<> with ID and the file path where it was read from. In case if none of the search locations turned out to be valid, uavcan_linux::Exception will be thrown.

Definition at line 122 of file system_utils.hpp.

◆ tryRead()

bool uavcan_linux::MachineIDReader::tryRead ( const std::string &  location,
MachineID out_id 
) const
inlineprivate

Definition at line 61 of file system_utils.hpp.

Member Data Documentation

◆ MachineIDSize

constexpr int uavcan_linux::MachineIDReader::MachineIDSize = 16
staticconstexpr

Definition at line 35 of file system_utils.hpp.

◆ search_locations_

const std::vector<std::string> uavcan_linux::MachineIDReader::search_locations_
private

Definition at line 50 of file system_utils.hpp.


The documentation for this class was generated from the following file:


uavcan_communicator
Author(s):
autogenerated on Fri Dec 13 2024 03:10:05