Electroneum
hw::trezor::DebugLink Class Reference

#include <debug_link.hpp>

Public Member Functions

 DebugLink ()
 
virtual ~DebugLink ()
 
void init (std::shared_ptr< Transport > &transport)
 
void close ()
 
std::shared_ptr< messages::debug::DebugLinkState > state ()
 
void input_word (const std::string &word)
 
void input_button (bool button)
 
void input_swipe (bool swipe)
 
void press_yes ()
 
void press_no ()
 
void stop ()
 
template<class t_message = messages::debug::DebugLinkState>
std::shared_ptr< t_message > call (const google::protobuf::Message &req, const boost::optional< messages::MessageType > &resp_type=boost::none, bool no_wait=false)
 

Detailed Description

Definition at line 40 of file debug_link.hpp.

Constructor & Destructor Documentation

◆ DebugLink()

hw::trezor::DebugLink::DebugLink ( )

Definition at line 35 of file debug_link.cpp.

35  {
36 
37  }

◆ ~DebugLink()

hw::trezor::DebugLink::~DebugLink ( )
virtual

Definition at line 39 of file debug_link.cpp.

39  {
40  if (m_transport){
41  close();
42  }
43  }
Here is the call graph for this function:

Member Function Documentation

◆ call()

template<class t_message = messages::debug::DebugLinkState>
std::shared_ptr<t_message> hw::trezor::DebugLink::call ( const google::protobuf::Message &  req,
const boost::optional< messages::MessageType > &  resp_type = boost::none,
bool  no_wait = false 
)
inline

Definition at line 58 of file debug_link.hpp.

62  {
64 
65  m_transport->write(req);
66  if (no_wait){
67  return nullptr;
68  }
69 
70  // Read the response
71  std::shared_ptr<google::protobuf::Message> msg_resp;
72  hw::trezor::messages::MessageType msg_resp_type;
73  m_transport->read(msg_resp, &msg_resp_type);
74 
75  messages::MessageType required_type = resp_type ? resp_type.get() : MessageMapper::get_message_wire_number<t_message>();
76  if (msg_resp_type == required_type) {
77  return message_ptr_retype<t_message>(msg_resp);
78  } else if (msg_resp_type == messages::MessageType_Failure){
79  throw_failure_exception(dynamic_cast<messages::common::Failure*>(msg_resp.get()));
80  } else {
81  throw exc::UnexpectedMessageException(msg_resp_type, msg_resp);
82  }
83  };
void throw_failure_exception(const messages::common::Failure *failure)
Definition: transport.cpp:1217
const GenericPointer< typename T::ValueType > T2 value
Definition: pointer.h:1225
Here is the call graph for this function:
Here is the caller graph for this function:

◆ close()

void hw::trezor::DebugLink::close ( )

Definition at line 51 of file debug_link.cpp.

51  {
52  CHECK_AND_ASSERT_THROW_MES(m_transport, "Not initialized");
53  if (m_transport) m_transport->close();
54  }
#define CHECK_AND_ASSERT_THROW_MES(expr, message)
Definition: misc_log_ex.h:173
Here is the caller graph for this function:

◆ init()

void hw::trezor::DebugLink::init ( std::shared_ptr< Transport > &  transport)

Definition at line 45 of file debug_link.cpp.

45  {
46  CHECK_AND_ASSERT_THROW_MES(!m_transport, "Already initialized");
47  m_transport = transport;
48  m_transport->open();
49  }
#define CHECK_AND_ASSERT_THROW_MES(expr, message)
Definition: misc_log_ex.h:173
std::shared_ptr< Transport > transport(const std::string &path)
Definition: transport.cpp:1204
Here is the call graph for this function:

◆ input_button()

void hw::trezor::DebugLink::input_button ( bool  button)

Definition at line 68 of file debug_link.cpp.

68  {
69  messages::debug::DebugLinkDecision decision;
70  decision.set_yes_no(button);
71  call(decision, boost::none, true);
72  }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ input_swipe()

void hw::trezor::DebugLink::input_swipe ( bool  swipe)

Definition at line 74 of file debug_link.cpp.

74  {
75  messages::debug::DebugLinkDecision decision;
76  decision.set_up_down(swipe);
77  call(decision, boost::none, true);
78  }
Here is the call graph for this function:

◆ input_word()

void hw::trezor::DebugLink::input_word ( const std::string &  word)

Definition at line 62 of file debug_link.cpp.

62  {
63  messages::debug::DebugLinkDecision decision;
64  decision.set_input(word);
65  call(decision, boost::none, true);
66  }
Here is the call graph for this function:

◆ press_no()

void hw::trezor::DebugLink::press_no ( )
inline

Definition at line 54 of file debug_link.hpp.

54 { input_button(false); }
Here is the call graph for this function:

◆ press_yes()

void hw::trezor::DebugLink::press_yes ( )
inline

Definition at line 53 of file debug_link.hpp.

53 { input_button(true); }
Here is the call graph for this function:

◆ state()

std::shared_ptr< messages::debug::DebugLinkState > hw::trezor::DebugLink::state ( )

Definition at line 56 of file debug_link.cpp.

56  {
57  return call<messages::debug::DebugLinkState>(
58  messages::debug::DebugLinkGetState(),
59  boost::make_optional(messages::MessageType_DebugLinkGetState));
60  }

◆ stop()

void hw::trezor::DebugLink::stop ( )

Definition at line 80 of file debug_link.cpp.

80  {
81  messages::debug::DebugLinkStop msg;
82  call(msg, boost::none, true);
83  }
Here is the call graph for this function:

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