Electroneum
hw::device_registry Class Reference

#include <device.hpp>

Public Member Functions

 device_registry ()
 
bool register_device (const std::string &device_name, device *hw_device)
 
deviceget_device (const std::string &device_descriptor)
 

Detailed Description

Definition at line 260 of file device.hpp.

Constructor & Destructor Documentation

◆ device_registry()

hw::device_registry::device_registry ( )

Definition at line 58 of file device.cpp.

58  {
59  hw::core::register_all(registry);
60  #ifdef WITH_DEVICE_LEDGER
61  hw::ledger::register_all(registry);
62  #endif
63  atexit(clear_device_registry);
64  }
void register_all(std::map< std::string, std::unique_ptr< device >> &registry)
void register_all(std::map< std::string, std::unique_ptr< device >> &registry)
Here is the call graph for this function:

Member Function Documentation

◆ get_device()

device & hw::device_registry::get_device ( const std::string &  device_descriptor)

Definition at line 76 of file device.cpp.

76  {
77  // Device descriptor can contain further specs after first :
78  auto delim = device_descriptor.find(':');
79  auto device_descriptor_lookup = device_descriptor;
80  if (delim != std::string::npos) {
81  device_descriptor_lookup = device_descriptor.substr(0, delim);
82  }
83 
84  auto device = registry.find(device_descriptor_lookup);
85  if (device == registry.end()) {
86  MERROR("Device not found in registry: '" << device_descriptor << "'. Known devices: ");
87  for( const auto& sm_pair : registry ) {
88  MERROR(" - " << sm_pair.first);
89  }
90  throw std::runtime_error("device not found: " + device_descriptor);
91  }
92  return *device->second;
93  }
#define MERROR(x)
Definition: misc_log_ex.h:73
Here is the caller graph for this function:

◆ register_device()

bool hw::device_registry::register_device ( const std::string &  device_name,
device hw_device 
)

Definition at line 66 of file device.cpp.

66  {
67  auto search = registry.find(device_name);
68  if (search != registry.end()){
69  return false;
70  }
71 
72  registry.insert(std::make_pair(device_name, std::unique_ptr<device>(hw_device)));
73  return true;
74  }
Here is the caller graph for this function:

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