diff options
author | Szczepan Zalega <szczepan@nitrokey.com> | 2017-01-13 10:50:20 +0100 |
---|---|---|
committer | Szczepan Zalega <szczepan@nitrokey.com> | 2017-03-11 15:41:37 +0100 |
commit | 5558c22eefb35dabb341b568b3f233fca51ff056 (patch) | |
tree | 5b605369eb7a94fc66692476fdbff90ed7a3d5c3 | |
parent | 8f2e6ad0673e2fe2e3407c895eecbd478885f2c5 (diff) | |
download | libnitrokey-5558c22eefb35dabb341b568b3f233fca51ff056.tar.gz libnitrokey-5558c22eefb35dabb341b568b3f233fca51ff056.tar.bz2 |
More debug log info during dev connection
Signed-off-by: Szczepan Zalega <szczepan@nitrokey.com>
-rw-r--r-- | device.cc | 20 |
1 files changed, 15 insertions, 5 deletions
@@ -29,27 +29,36 @@ Device::Device(const uint16_t vid, const uint16_t pid, const DeviceModel model, {} bool Device::disconnect() { - std::lock_guard<std::mutex> lock(mex_dev_com); + //called in object's destructor Log::instance()(__PRETTY_FUNCTION__, Loglevel::DEBUG_L2); + std::lock_guard<std::mutex> lock(mex_dev_com); + Log::instance()(std::string(__FUNCTION__) + std::string(m_model==DeviceModel::PRO?"PRO":"STORAGE"), Loglevel::DEBUG_L2); + Log::instance()(std::string(__FUNCTION__) + std::string(" *IN* "), Loglevel::DEBUG_L2); + Log::instance()(std::string("Disconnection success: ") + std::to_string(mp_devhandle == nullptr), Loglevel::DEBUG_L2); if(mp_devhandle == nullptr) return false; + hid_close(mp_devhandle); mp_devhandle = nullptr; hid_exit(); return true; } bool Device::connect() { - std::lock_guard<std::mutex> lock(mex_dev_com); Log::instance()(__PRETTY_FUNCTION__, Loglevel::DEBUG_L2); + std::lock_guard<std::mutex> lock(mex_dev_com); + Log::instance()(std::string(__FUNCTION__) + std::string(" *IN* "), Loglevel::DEBUG_L2); // hid_init(); // done automatically on hid_open mp_devhandle = hid_open(m_vid, m_pid, nullptr); - return mp_devhandle != nullptr; + const auto success = mp_devhandle != nullptr; + Log::instance()(std::string("Connection success: ") + std::to_string(success), Loglevel::DEBUG_L2); + return success; } int Device::send(const void *packet) { - std::lock_guard<std::mutex> lock(mex_dev_com); Log::instance()(__PRETTY_FUNCTION__, Loglevel::DEBUG_L2); + std::lock_guard<std::mutex> lock(mex_dev_com); + Log::instance()(std::string(__FUNCTION__) + std::string(" *IN* "), Loglevel::DEBUG_L2); if (mp_devhandle == nullptr) throw std::runtime_error("Attempted HID send on an invalid descriptor."); //TODO migrate except to library_error @@ -59,11 +68,12 @@ int Device::send(const void *packet) { } int Device::recv(void *packet) { + Log::instance()(__PRETTY_FUNCTION__, Loglevel::DEBUG_L2); std::lock_guard<std::mutex> lock(mex_dev_com); + Log::instance()(std::string(__FUNCTION__) + std::string(" *IN* "), Loglevel::DEBUG_L2); int status; int retry_count = 0; - Log::instance()(__PRETTY_FUNCTION__, Loglevel::DEBUG_L2); if (mp_devhandle == nullptr) throw std::runtime_error("Attempted HID receive on an invalid descriptor."); //TODO migrate except to library_error |