aboutsummaryrefslogtreecommitdiff
path: root/device.cc
diff options
context:
space:
mode:
authorSzczepan Zalega <szczepan.zalega@gmail.com>2016-03-05 15:50:53 +0100
committerSzczepan Zalega <szczepan.zalega@gmail.com>2016-03-05 15:50:53 +0100
commit27434dc0e877845cbfb229c5154c342107866fd5 (patch)
tree7b0739b206ffcecb757083f16318326667b7c36c /device.cc
parent4c511bc53788ada875fd0221b1cc3d4f8b269f91 (diff)
downloadlibnitrokey-27434dc0e877845cbfb229c5154c342107866fd5.tar.gz
libnitrokey-27434dc0e877845cbfb229c5154c342107866fd5.tar.bz2
formatted code with clang-format-3.6 with style=google
Diffstat (limited to 'device.cc')
-rw-r--r--device.cc75
1 files changed, 37 insertions, 38 deletions
diff --git a/device.cc b/device.cc
index c13a020..f957223 100644
--- a/device.cc
+++ b/device.cc
@@ -11,66 +11,65 @@ using namespace nitrokey::device;
using namespace nitrokey::log;
Device::Device()
-: m_vid(0), m_pid(0),
- m_retry_count(4),
- m_retry_timeout(50),
- mp_devhandle(NULL) {}
+ : m_vid(0),
+ m_pid(0),
+ m_retry_count(4),
+ m_retry_timeout(50),
+ mp_devhandle(NULL) {}
bool Device::disconnect() {
- Log::instance()(__PRETTY_FUNCTION__, Loglevel::DEBUG_L2);
+ Log::instance()(__PRETTY_FUNCTION__, Loglevel::DEBUG_L2);
- hid_exit();
- mp_devhandle = NULL;
- return true;
+ hid_exit();
+ mp_devhandle = NULL;
+ return true;
}
bool Device::connect() {
- Log::instance()(__PRETTY_FUNCTION__, Loglevel::DEBUG_L2);
+ Log::instance()(__PRETTY_FUNCTION__, Loglevel::DEBUG_L2);
- //hid_init();
- mp_devhandle = hid_open(m_vid, m_pid, NULL);
- //hid_init();
- return mp_devhandle != NULL;
+ // hid_init();
+ mp_devhandle = hid_open(m_vid, m_pid, NULL);
+ // hid_init();
+ return mp_devhandle != NULL;
}
CommError Device::send(const void *packet) {
- Log::instance()(__PRETTY_FUNCTION__, Loglevel::DEBUG_L2);
+ Log::instance()(__PRETTY_FUNCTION__, Loglevel::DEBUG_L2);
- if (mp_devhandle == NULL)
- throw std::runtime_error("Attempted HID send on an invalid descriptor.");
+ if (mp_devhandle == NULL)
+ throw std::runtime_error("Attempted HID send on an invalid descriptor.");
- return (CommError)(
- hid_send_feature_report(mp_devhandle, (const unsigned char *)(packet),
- HID_REPORT_SIZE));
+ return (CommError)(hid_send_feature_report(
+ mp_devhandle, (const unsigned char *)(packet), HID_REPORT_SIZE));
}
CommError Device::recv(void *packet) {
- CommError status;
- int retry_count = 0;
+ CommError status;
+ int retry_count = 0;
- Log::instance()(__PRETTY_FUNCTION__, Loglevel::DEBUG_L2);
- std::this_thread::sleep_for( std::chrono::milliseconds(5000) ); //FIXME remove timeout in favor of sync communication
+ Log::instance()(__PRETTY_FUNCTION__, Loglevel::DEBUG_L2);
+ std::this_thread::sleep_for(std::chrono::milliseconds(
+ 5000)); // FIXME remove timeout in favor of sync communication
- if (mp_devhandle == NULL)
- throw std::runtime_error("Attempted HID receive on an invalid descriptor.");
+ if (mp_devhandle == NULL)
+ throw std::runtime_error("Attempted HID receive on an invalid descriptor.");
- for(;;) {
- status = (CommError)(
- hid_get_feature_report(mp_devhandle, (unsigned char *)(packet),
- HID_REPORT_SIZE));
- if ((int)status >0 || retry_count++ >= m_retry_count)
- break;
- std::this_thread::sleep_for(m_retry_timeout);
- }
+ for (;;) {
+ status = (CommError)(hid_get_feature_report(
+ mp_devhandle, (unsigned char *)(packet), HID_REPORT_SIZE));
+ if ((int)status > 0 || retry_count++ >= m_retry_count) break;
+ std::this_thread::sleep_for(m_retry_timeout);
+ }
- return status;
+ return status;
}
Stick10::Stick10() {
- m_vid = 0x20a0;
- m_pid = 0x4108;
+ m_vid = 0x20a0;
+ m_pid = 0x4108;
}
Stick20::Stick20() {
- m_vid = 0x20a0;
- m_pid = 0x4109;
+ m_vid = 0x20a0;
+ m_pid = 0x4109;
}