diff options
author | Szczepan Zalega <szczepan@nitrokey.com> | 2017-12-11 10:51:53 +0100 |
---|---|---|
committer | Szczepan Zalega <szczepan@nitrokey.com> | 2017-12-11 10:51:53 +0100 |
commit | 17309629889269e99d14b4e880675682d8b6435f (patch) | |
tree | ab37c07e186315410d0187b52c4d5b5492555662 /include | |
parent | 7797c8fb5fa69068dd659c369bc774ca74f592fe (diff) | |
download | libnitrokey-wip-retry_function.tar.gz libnitrokey-wip-retry_function.tar.bz2 |
Allow to execute client-supplied function on each retry and cancel with itwip-retry_function
Signed-off-by: Szczepan Zalega <szczepan@nitrokey.com>
Diffstat (limited to 'include')
-rw-r--r-- | include/NitrokeyManager.h | 2 | ||||
-rw-r--r-- | include/device_proto.h | 5 |
2 files changed, 6 insertions, 1 deletions
diff --git a/include/NitrokeyManager.h b/include/NitrokeyManager.h index de14fbc..e4842c2 100644 --- a/include/NitrokeyManager.h +++ b/include/NitrokeyManager.h @@ -179,8 +179,8 @@ char * strndup(const char* str, size_t maxlen); public: bool set_current_device_speed(int retry_delay, int send_receive_delay); void set_loglevel(Loglevel loglevel); - void set_loglevel(int loglevel); + void set_retry_function(const retry_type retry_func); }; } diff --git a/include/device_proto.h b/include/device_proto.h index 388c721..89fed12 100644 --- a/include/device_proto.h +++ b/include/device_proto.h @@ -1,6 +1,7 @@ #ifndef DEVICE_PROTO_H #define DEVICE_PROTO_H +#include <functional> #include <utility> #include <thread> #include <type_traits> @@ -38,6 +39,8 @@ namespace nitrokey { namespace proto { extern std::mutex send_receive_mtx; + using retry_type = std::function <int(int)>; + extern retry_type on_retry; /* @@ -362,6 +365,8 @@ namespace nitrokey { dev->m_counters.total_retries++; LOG(".", Loglevel::DEBUG_L1); std::this_thread::sleep_for(retry_timeout); + if (on_retry(receiving_retry_counter) == -1) + throw DeviceReceivingFailure("User canceled"); continue; } if (successful_communication) break; |