Add exception wrapper for async API functions 61/28861/1
authorKrzysztof Jackiewicz <k.jackiewicz@samsung.com>
Tue, 16 Sep 2014 07:58:39 +0000 (09:58 +0200)
committerBartlomiej Grzelewski <b.grzelewski@samsung.com>
Thu, 16 Oct 2014 13:44:31 +0000 (15:44 +0200)
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
src/manager/client/client-common.h

index a7a183f..f4782c1 100644 (file)
@@ -213,6 +213,22 @@ int try_catch(const std::function<int()>& func)
     return CKM_API_ERROR_UNKNOWN;
 }
 
+void try_catch_async(const std::function<void()>& func, const std::function<void(int)>& 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));
index ae25a62..af88031 100644 (file)
@@ -76,6 +76,8 @@ private:
  */
 int try_catch(const std::function<int()>& func);
 
+void try_catch_async(const std::function<void()>& func, const std::function<void(int)>& error);
+
 } // namespace CKM
 
 #endif // _KEY_MANAGER_CLIENT_