From a2da17c8608d25f64239047d0ff497adb015e411 Mon Sep 17 00:00:00 2001 From: Szczepan Zalega Date: Mon, 8 Aug 2016 17:51:34 +0200 Subject: Moving to shared ptr for device Signed-off-by: Szczepan Zalega --- NitrokeyManager.cc | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) (limited to 'NitrokeyManager.cc') diff --git a/NitrokeyManager.cc b/NitrokeyManager.cc index 93b11fa..c6eb51b 100644 --- a/NitrokeyManager.cc +++ b/NitrokeyManager.cc @@ -24,7 +24,7 @@ namespace nitrokey{ // package type to auth, auth type [Authorize,UserAuthorize] template - void auth_package(T& package, const char* admin_temporary_password, Device * device){ + void auth_package(T& package, const char* admin_temporary_password, shared_ptr device){ auto auth = get_payload(); strcpyT(auth.temporary_password, admin_temporary_password); auth.crc_to_authorize = S::CommandTransaction::getCRC(package); @@ -33,22 +33,18 @@ namespace nitrokey{ NitrokeyManager * NitrokeyManager::_instance = nullptr; - NitrokeyManager::NitrokeyManager(): device(nullptr) { + NitrokeyManager::NitrokeyManager() { set_debug(true); } NitrokeyManager::~NitrokeyManager() { - delete device; } bool NitrokeyManager::connect() { device = nullptr; - vector devices = { new Stick10(), new Stick20() }; + vector< shared_ptr > devices = { make_shared(), make_shared() }; for( auto d : devices ){ - if (device != nullptr){ - delete d; - } - if (device == nullptr && d->connect()){ - device = d; + if (d->connect()){ + device = std::shared_ptr(d); } } return device != nullptr; @@ -58,10 +54,10 @@ namespace nitrokey{ bool NitrokeyManager::connect(const char *device_model) { switch (device_model[0]){ case 'P': - device = new Stick10(); + device = make_shared(); break; case 'S': - device = new Stick20(); + device = make_shared(); break; default: throw std::runtime_error("Unknown model"); -- cgit v1.2.1