From d15f87aa7ed169f236d1b0b8880606533240e2b6 Mon Sep 17 00:00:00 2001 From: Krzysztof Jackiewicz Date: Tue, 16 Sep 2014 09:58:39 +0200 Subject: [PATCH] Add exception wrapper for async API functions Function will execute API function logic surruded with try catch block and call supported error function if necessary. Change-Id: I51295060edf531814b7498c1fd3ecf1156a94ec4 --- src/manager/client/client-common.cpp | 16 ++++++++++++++++ src/manager/client/client-common.h | 2 ++ 2 files changed, 18 insertions(+) diff --git a/src/manager/client/client-common.cpp b/src/manager/client/client-common.cpp index a7a183f..f4782c1 100644 --- a/src/manager/client/client-common.cpp +++ b/src/manager/client/client-common.cpp @@ -213,6 +213,22 @@ int try_catch(const std::function& func) return CKM_API_ERROR_UNKNOWN; } +void try_catch_async(const std::function& func, const std::function& error) +{ + try { + func(); + } catch (const MessageBuffer::Exception::Base& e) { + LogError("CKM::MessageBuffer::Exception " << e.DumpToString()); + error(CKM_API_ERROR_BAD_REQUEST); + } catch (const std::exception& e) { + LogError("STD exception " << e.what()); + error(CKM_API_ERROR_UNKNOWN); + } catch (...) { + LogError("Unknown exception occured"); + error(CKM_API_ERROR_UNKNOWN); + } +} + } // namespace CKM static void init_lib(void) __attribute__ ((constructor)); diff --git a/src/manager/client/client-common.h b/src/manager/client/client-common.h index ae25a62..af88031 100644 --- a/src/manager/client/client-common.h +++ b/src/manager/client/client-common.h @@ -76,6 +76,8 @@ private: */ int try_catch(const std::function& func); +void try_catch_async(const std::function& func, const std::function& error); + } // namespace CKM #endif // _KEY_MANAGER_CLIENT_ -- 2.7.4