Added security_manager_strerror function. 25/31125/2
authorSebastian Grabowski <s.grabowski@samsung.com>
Mon, 1 Dec 2014 15:26:56 +0000 (16:26 +0100)
committerSebastian Grabowski <s.grabowski@samsung.com>
Tue, 2 Dec 2014 08:56:24 +0000 (09:56 +0100)
This function translates lib_retcode(s) to a string describing given
error that occured in security-manager.

Change-Id: Ied57ff8c27a972123b28714ebc25efe143c6d64c
Signed-off-by: Sebastian Grabowski <s.grabowski@samsung.com>
src/client/client-security-manager.cpp
src/cmd/security-manager-cmd.cpp
src/include/security-manager.h

index a4fa36a..1e03d36 100644 (file)
 
 #include <security-manager.h>
 
+/**
+ * Mapping of lib_retcode error codes to theirs strings equivalents
+ */
+static std::map<enum lib_retcode, std::string> lib_retcode_string_map = {
+    {SECURITY_MANAGER_SUCCESS, "Success"},
+    {SECURITY_MANAGER_ERROR_UNKNOWN, "Unknown error"},
+    {SECURITY_MANAGER_ERROR_INPUT_PARAM, "Invalid function parameter was given"},
+    {SECURITY_MANAGER_ERROR_MEMORY, "Memory allocation error"},
+    {SECURITY_MANAGER_ERROR_REQ_NOT_COMPLETE, "Incomplete data in application request"},
+    {SECURITY_MANAGER_ERROR_AUTHENTICATION_FAILED, "User does not have sufficient "
+                                                   "rigths to perform an operation"}
+};
 
+SECURITY_MANAGER_API
+const char *security_manager_strerror(enum lib_retcode rc)
+{
+    try {
+        return lib_retcode_string_map.at(rc).c_str();
+    } catch (const std::out_of_range &e) {
+        return "Unknown error code";
+    }
+}
 
 SECURITY_MANAGER_API
 int security_manager_app_inst_req_new(app_inst_req **pp_req)
index ec7b680..c615d12 100644 (file)
@@ -248,11 +248,12 @@ static int installApp(const struct app_inst_req &req)
         LogDebug("Application " << req.appId <<
                  " installed successfully.");
     } else {
-        std::cout << "Failed to install " << req.appId <<
-                  " application. Return code: " << ret <<
-                  std::endl;
-        LogDebug("Failed to install " << req.appId <<
-                 " application. Return code: " << ret);
+        std::cout << "Failed to install " << req.appId << " application: " <<
+                  security_manager_strerror(static_cast<lib_retcode>(ret)) <<
+                  " (" << ret << ")." << std::endl;
+        LogError("Failed to install " << req.appId << " application: " <<
+                 security_manager_strerror(static_cast<lib_retcode>(ret)) <<
+                 " (" << ret << ")." << std::endl);
     }
     return ret;
 }
index c06b2fb..36028c2 100644 (file)
@@ -60,6 +60,14 @@ enum app_install_path_type {
 struct app_inst_req;
 typedef struct app_inst_req app_inst_req;
 
+/**
+ * This function translates lib_retcode error codes to strings describing
+ * errors.
+ * @param[in] rc error code of lib_retcode type
+ * @return string describing error for error code
+ */
+const char *security_manager_strerror(enum lib_retcode rc);
+
 /*
  * This function is responsible for initialize app_inst_req data structure
  * It uses dynamic allocation inside and user responsibility is to call