[Service App] Error handling has been reworked
authorDmytro Logachev <d.logachev@samsung.com>
Thu, 18 May 2017 09:36:19 +0000 (12:36 +0300)
committerDmytro Logachev <d.logachev@samsung.com>
Thu, 18 May 2017 09:36:19 +0000 (12:36 +0300)
15 files changed:
control_app/iot-manager-service/inc/common_types.h
control_app/iot-manager-service/inc/i_presenter.h
control_app/iot-manager-service/inc/model.h
control_app/iot-manager-service/inc/network/i_network_manager.h
control_app/iot-manager-service/inc/network/network_manager.h
control_app/iot-manager-service/inc/network/nm_types.h
control_app/iot-manager-service/inc/presenter.h
control_app/iot-manager-service/inc/web_view.h
control_app/iot-manager-service/src/model.cpp
control_app/iot-manager-service/src/network/network_manager.cpp
control_app/iot-manager-service/src/presenter.cpp
control_app/iot-manager-service/src/service.cpp
control_app/iot-manager-service/src/web_view.cpp
control_app/iot-manager-service/tests/network_manager_test/network_manager_test.cpp
control_app/iot-manager-service/tests/web_view_test/web_view_tests.cpp

index df4050b..8ab1ed7 100644 (file)
@@ -26,13 +26,43 @@ enum class ErrorCode
 {
     Success = 0,                   ///< Success.
     Error,                         ///< Some error occurred.
-    SessionExpired,                ///< Session is expired.
-    NotLoggedIn,                   ///< Not logged in.
-    IncorrectIdOrPsswd,            ///< Incorrect id or password.
     LibNotFound,                   ///< Library isn't found.
-    FunctionNotFound               ///< Function isn't found.
+    FunctionNotFound,              ///< Function isn't found.
+    UnregisteredCommand,           ///< Can`t process message, unregistered command.
+    InvalidArgument,               ///< Invalid argument value.
+    BadMessageFormat,              ///< Can`t process message, wrong message format.
+    ProcessingFailed,              ///< Can`t process message, internal message handler error.
+    InternalConnectionFailed,      ///< Can`t process message, internal service configuration error.
+    NoConnection,                  ///< There is no internet connection.
+    ConnectionTimedOut,            ///< Connection is timed out.
+    SessionExpired,                ///< Session is expired.
+    NotAuthorized,                 ///< Not logged in.
+    AuthError                      ///< Incorrect id or password.
 };
 
+inline std::string GetErrorDescription(ErrorCode code)
+{
+    switch (code)
+    {
+    case ErrorCode::NoConnection: case ErrorCode::ConnectionTimedOut:
+    {
+        return std::string("An error occurred while loading the data. Please, check the connection.");
+    }
+    case ErrorCode::AuthError:
+    {
+        return std::string("Wrong credentials");
+    }
+    case ErrorCode::SessionExpired:
+    {
+        return std::string("Session expired. Please, sign in again");
+    }
+    default:
+    {
+        return std::string();
+    }
+    }
+}
+
 enum class SessionState
 {
     Open = 0,
@@ -40,21 +70,6 @@ enum class SessionState
     Expired
 };
 
-/**
-    @brief Message processing results for UI communication.
- */
-enum class MessageProcessResult: int
-{
-    Success = 0,                     ///< Message processing succeed.
-    Error,                           ///< In case of any other error.
-    ErrorUnregisteredCommand,        ///< Can`t process message, unregistered command.
-    ErrorBadMessageFormat,           ///< Can`t process message, wrong message format.
-    ErrorProcessingFailed,           ///< Can`t process message, internal message handler error.
-    ErrorInternalConnectionFailed,   ///< Can`t process message, internal service configuration error.
-    IncorrectIdOrPsswd,              ///< Invalid used id or password.
-    NotLoggedIn
-};
-
 }
 
 #endif /* IOTSWC_COMMON_TYPES_H_ */
index 71eb9b1..337ce64 100644 (file)
@@ -30,11 +30,11 @@ public:
 
     virtual ErrorCode LogOut() = 0;
 
-    virtual SessionState GetSessionState() = 0;
+    virtual ErrorCode GetSessionState(SessionState& state) = 0;
 
-    virtual DeviceList GetOwnedDeviceList() = 0;
+    virtual ErrorCode GetOwnedDeviceList(DeviceList& deviceList) = 0;
 
-    virtual DeviceList GetUnownedDeviceList() = 0;
+    virtual ErrorCode GetUnownedDeviceList(DeviceList& deviceList) = 0;
 
     virtual ErrorCode UnownDevice(const std::string& deviceId) = 0;
 
index 748a1ee..c8f3cb6 100644 (file)
@@ -38,11 +38,11 @@ public:
 
     virtual ErrorCode LogOut();
 
-    virtual SessionState GetSessionState();
+    virtual ErrorCode GetSessionState(SessionState&);
 
-    virtual DeviceList GetOwnedDeviceList();
+    virtual ErrorCode GetOwnedDeviceList(DeviceList&);
 
-    virtual DeviceList GetUnownedDeviceList();
+    virtual ErrorCode GetUnownedDeviceList(DeviceList&);
 
     virtual ErrorCode UnownDevice(const std::string& deviceId);
 
@@ -52,6 +52,8 @@ public:
 
     virtual void AddObserver(IModelObserverWPtr observer);
 
+    virtual void NotificationCallback(const std::string& title, const std::string& message);
+
 private:
     ModelObserversList m_observers;
     INetworkManagerUPtr m_networkManager;
index c3df345..c95a6d7 100644 (file)
 namespace iotswsec
 {
 
+using NotificationCallback = std::function<void(const std::string& title, const std::string& body)>;
+
+
 class INetworkManager
 {
 public:
 
-    using NotificationCallback = std::function<void(const std::string& title, const std::string& body)>;
-
     virtual ~INetworkManager() = default;
 
-    //TODO: define interface.
-
     virtual ErrorCode LogIn(const UserInfo& userInfo, const std::string& psswd) = 0;
 
     virtual ErrorCode LogOut() = 0;
 
-    virtual SessionState GetSessionState() = 0;
+    virtual ErrorCode GetSessionState(SessionState&) = 0;
 
-    virtual DeviceList GetOwnedDeviceList() = 0;
+    virtual ErrorCode GetOwnedDeviceList(DeviceList&) = 0;
 
-    virtual DeviceList GetUnownedDeviceList() = 0;
+    virtual ErrorCode GetUnownedDeviceList(DeviceList&) = 0;
 
     virtual ErrorCode UnownDevice(const std::string& deviceId) = 0;
 
     virtual ErrorCode OwnDevice(const std::string& deviceId) = 0;
 
-//    virtual ErrorCode AddNotificationCallback(const NotificationCallback&) = 0;
+    virtual ErrorCode RegisterNotificationCallback(const NotificationCallback&) = 0;
 };
 
 using INetworkManagerPtr = std::shared_ptr<INetworkManager>;
index d2b3282..164d86e 100644 (file)
@@ -25,7 +25,7 @@ public:
 
     typedef void (*DeviceStateChangedCallback)(const char* devId, DeviceState state, void* userDefined);
     typedef void (*DeviceEnumCallback)(NM_hDeviceList, const char* devId, void* userDefined);
-    typedef void (*NotificationCallback)(NM_NotificationData,void*);
+    typedef void (*NmNotificationCallback)(NM_NotificationData,void*);
 
     typedef NM_ErrorCode (*InitFunc)(NM_hContext*);
     typedef void (*CleanUpFunc)(NM_hContext*);
@@ -45,7 +45,8 @@ public:
     typedef void (*FreeDeviceInfoFunc)(NM_DeviceInfo*);
     typedef NM_ErrorCode (*OwnDeviceFunc)(NM_hDeviceList, const char* devId);
     typedef NM_ErrorCode (*UnownDeviceFunc)(NM_hDeviceList dev_list, const char* devId);
-    typedef NM_ErrorCode (*SubsOnNotificationsFunc)(NM_hContext, NotificationCallback, void*);
+    typedef NM_ErrorCode (*SubsOnNotificationsFunc)(NM_hContext, NmNotificationCallback, void*);
+    typedef void (*UnsubsOnNotificationsFunc)(NM_hContext);
 
 public:
 
@@ -60,17 +61,19 @@ public:
 
     ErrorCode LogOut() override;
 
-    SessionState GetSessionState() override;
+    ErrorCode GetSessionState(SessionState&) override;
 
-    DeviceList GetOwnedDeviceList() override;
+    ErrorCode GetOwnedDeviceList(DeviceList&) override;
 
-    DeviceList GetUnownedDeviceList() override;
+    ErrorCode GetUnownedDeviceList(DeviceList&) override;
 
     ErrorCode UnownDevice(const std::string& deviceId) override;
 
     ErrorCode OwnDevice(const std::string& deviceId) override;
 
-//    ErrorCode AddNotificationCallback(const NotificationCallback&) override;
+    ErrorCode RegisterNotificationCallback(const NotificationCallback&) override;
+
+    ErrorCode NotifySubscribers(const std::string& title, const std::string& message);
 
     struct ModuleSymbols
     {
@@ -103,6 +106,7 @@ public:
         OwnDeviceFunc                           m_nmOwnDeviceFunc;
         UnownDeviceFunc                         m_nmUnownDeviceFunc;
         SubsOnNotificationsFunc                 m_nmSubsOnNotifFunc;
+        UnsubsOnNotificationsFunc               m_nmUnsubsOnNotifFunc;
 
     };
 
@@ -113,12 +117,14 @@ private:
     void FreeCache();
     void FreeDeviceList(NM_hDeviceList* nmList);
     ErrorCode SubscribeOnNotifications();
+    ErrorCode UnsubscribeOnNotifications();
 
 private:
-    ModuleSymbols   m_moduleSymbols;
-    NM_hContext     m_context;
-    NM_hDeviceList  m_ownedDevices;
-    NM_hDeviceList  m_unownedDevices;
+    ModuleSymbols                           m_moduleSymbols;
+    NM_hContext                             m_context;
+    NM_hDeviceList                          m_ownedDevices;
+    NM_hDeviceList                          m_unownedDevices;
+    std::vector<NotificationCallback>       m_notificationCallbackList;
 };
 
 } //namespace iotswsec
index d773f5d..69f6c23 100644 (file)
@@ -12,6 +12,8 @@
 #ifndef NETWORK_NM_TYPES_H_
 #define NETWORK_NM_TYPES_H_
 
+#include "common_types.h"
+
 namespace iotswsec
 {
 
@@ -31,6 +33,29 @@ typedef enum  {
     // ...
 } NM_ErrorCode;
 
+inline ErrorCode GetCorrespondingErrorCode(NM_ErrorCode code)
+{
+    switch (code)
+    {
+    case NM_ErrorCode::EC_AUTH_ERROR:
+    {
+        return ErrorCode::AuthError;
+    }
+    case NM_ErrorCode::EC_TIMEOUT_ERROR:
+    {
+        return ErrorCode::ConnectionTimedOut;
+    }
+    case NM_ErrorCode::EC_IOTIVITY_ERROR:
+    {
+        return ErrorCode::NoConnection; //TODO: no eto ne tochno
+    }
+    default:
+    {
+        return ErrorCode::Error;
+    }
+    }
+}
+
 typedef enum
 {
     DS_Offline = 0,
index b043536..7fcd7c4 100644 (file)
@@ -44,13 +44,13 @@ public:
 
     ErrorCode LogOut() override;
 
-    SessionState GetSessionState() override;
+    ErrorCode GetSessionState(SessionState& state) override;
 
     void UpdateSessionState(SessionState) override;
 
-    DeviceList GetOwnedDeviceList() override;
+    ErrorCode GetOwnedDeviceList(DeviceList& deviceList) override;
 
-    DeviceList GetUnownedDeviceList() override;
+    ErrorCode GetUnownedDeviceList(DeviceList& deviceList) override;
 
     ErrorCode UnownDevice(const std::string& deviceId) override;
 
index bb642d1..b6a9120 100644 (file)
@@ -48,7 +48,7 @@ public:
      */
     std::string ProcessRequest(const std::string& command, const JSONNode& attachedObject);
 
-    typedef std::function<MessageProcessResult(const JSONNode&, JSONNode&, std::string&)> Callback;
+    typedef std::function<ErrorCode(const JSONNode&, JSONNode&, std::string&)> Callback;
 
     /**
         @brief Registers a callback for requests.
@@ -57,28 +57,28 @@ public:
        */
     void RegisterCallback(const std::string& command, const Callback& callback);
 
-    MessageProcessResult LogIn(const JSONNode& request, JSONNode& response,
+    ErrorCode LogIn(const JSONNode& request, JSONNode& response,
             std::string& errDescription) const;
 
-    MessageProcessResult LogOut(const JSONNode& request, JSONNode& response,
+    ErrorCode LogOut(const JSONNode& request, JSONNode& response,
             std::string& errDescription) const;
 
-    MessageProcessResult GetSessionState(const JSONNode& request, JSONNode& response,
+    ErrorCode GetSessionState(const JSONNode& request, JSONNode& response,
             std::string& errDescription) const;
 
-    MessageProcessResult GetOwnedDevices(const JSONNode& request, JSONNode& response,
+    ErrorCode GetOwnedDevices(const JSONNode& request, JSONNode& response,
             std::string& errDescription) const;
 
-    MessageProcessResult GetUnownedDevices(const JSONNode& request, JSONNode& response,
+    ErrorCode GetUnownedDevices(const JSONNode& request, JSONNode& response,
             std::string& errDescription) const;
 
-    MessageProcessResult OwnDevice(const JSONNode& request, JSONNode& response,
+    ErrorCode OwnDevice(const JSONNode& request, JSONNode& response,
             std::string& errDescription) const;
 
-    MessageProcessResult UnownDevice(const JSONNode& request, JSONNode& response,
+    ErrorCode UnownDevice(const JSONNode& request, JSONNode& response,
             std::string& errDescription) const;
 
-    MessageProcessResult GetDashboard(const JSONNode& request, JSONNode& response,
+    ErrorCode GetDashboard(const JSONNode& request, JSONNode& response,
             std::string& errDescription) const;
 
 private:
index 71324bf..290fdee 100644 (file)
@@ -10,6 +10,7 @@
 **/
 
 #include "model.h"
+#include "push_notification.h"
 
 namespace iotswsec
 {
@@ -18,6 +19,8 @@ Model::Model():
     m_observers(),
     m_networkManager(new NetworkManager())
 {
+    m_networkManager->RegisterNotificationCallback(std::bind(&Model::NotificationCallback, this,
+            std::placeholders::_1, std::placeholders::_2));
 }
 
 ErrorCode Model::LogIn(const UserInfo& userInfo, const std::string& psswd)
@@ -30,9 +33,9 @@ ErrorCode Model::LogOut()
     return m_networkManager->LogOut();
 }
 
-SessionState Model::GetSessionState()
+ErrorCode Model::GetSessionState(SessionState& state)
 {
-    return m_networkManager->GetSessionState();
+    return m_networkManager->GetSessionState(state);
 }
 
 void Model::AddObserver(IModelObserverWPtr observer)
@@ -40,14 +43,14 @@ void Model::AddObserver(IModelObserverWPtr observer)
     m_observers.push_back(observer);
 }
 
-DeviceList Model::GetOwnedDeviceList()
+ErrorCode Model::GetOwnedDeviceList(DeviceList& deviceList)
 {
-    return m_networkManager->GetOwnedDeviceList();
+    return m_networkManager->GetOwnedDeviceList(deviceList);
 }
 
-DeviceList Model::GetUnownedDeviceList()
+ErrorCode Model::GetUnownedDeviceList(DeviceList& deviceList)
 {
-    return m_networkManager->GetUnownedDeviceList();
+    return m_networkManager->GetUnownedDeviceList(deviceList);
 }
 
 ErrorCode Model::UnownDevice(const std::string& deviceId)
@@ -60,5 +63,11 @@ ErrorCode Model::OwnDevice(const std::string& deviceId)
     return m_networkManager->OwnDevice(deviceId);
 }
 
+void Model::NotificationCallback(const std::string& title,
+        const std::string& message)
+{
+    PushNotification::GetInstance().Push(title, message);
+}
+
 }
 
index 5201ef2..cb4e4a8 100644 (file)
@@ -13,7 +13,7 @@
 #include "utils/log.h"
 #include "utils/to_string.h"
 #include "utils/assert_return.h"
-#include "push_notification.h"
+#include "push_notification.h" //TODO: remove
 
 #include <dlfcn.h>
 
@@ -39,6 +39,7 @@
 #define NM_OWN_DEV_FUNC_NAME                "NM_ownDevice"
 #define NM_UNOWN_DEV_FUNC_NAME              "NM_unOwnDevice"
 #define NM_SUBS_NOTIFICATIONS_FUNC_NAME     "NM_subscribeNotifications"
+#define NM_UNSUBS_NOTIF_FUNC_NAME            "NM_unsubscribeNotifications"
 
 namespace iotswsec
 {
@@ -64,7 +65,8 @@ NetworkManager::ModuleSymbols::ModuleSymbols():
     m_nmFreeDeviceInfoFunc(nullptr),
     m_nmOwnDeviceFunc(nullptr),
     m_nmUnownDeviceFunc(nullptr),
-    m_nmSubsOnNotifFunc(nullptr)
+    m_nmSubsOnNotifFunc(nullptr),
+    m_nmUnsubsOnNotifFunc(nullptr)
 {
     if (LoadModule() != ErrorCode::Success)
     {
@@ -124,6 +126,8 @@ ErrorCode NetworkManager::ModuleSymbols::LoadModule()
                                                      dlsym(this->m_module, NM_UNOWN_DEV_FUNC_NAME));
     m_nmSubsOnNotifFunc            = reinterpret_cast<SubsOnNotificationsFunc>(
                                                      dlsym(this->m_module, NM_SUBS_NOTIFICATIONS_FUNC_NAME));
+    m_nmUnsubsOnNotifFunc          = reinterpret_cast<UnsubsOnNotificationsFunc>(
+                                                     dlsym(this->m_module, NM_UNSUBS_NOTIF_FUNC_NAME));
 
     if (!m_nmInitFunc ||
         !m_nmCleanUpFunc ||
@@ -143,7 +147,8 @@ ErrorCode NetworkManager::ModuleSymbols::LoadModule()
         !m_nmFreeDeviceInfoFunc ||
         !m_nmOwnDeviceFunc ||
         !m_nmUnownDeviceFunc ||
-        !m_nmSubsOnNotifFunc)
+        !m_nmSubsOnNotifFunc ||
+        !m_nmUnsubsOnNotifFunc)
     {
         LOG_ERR("Couldn't load one of the functions due to error: %s", dlerror());
 
@@ -191,6 +196,7 @@ ErrorCode NetworkManager::ModuleSymbols::UnloadModule()
         m_nmOwnDeviceFunc               = nullptr;
         m_nmUnownDeviceFunc             = nullptr;
         m_nmSubsOnNotifFunc             = nullptr;
+        m_nmUnsubsOnNotifFunc           = nullptr;
 
         if (dlclose(m_module) == 0)
          {
@@ -212,7 +218,8 @@ NetworkManager::NetworkManager():
     m_moduleSymbols(),
     m_context(nullptr),
     m_ownedDevices(nullptr),
-    m_unownedDevices(nullptr)
+    m_unownedDevices(nullptr),
+    m_notificationCallbackList()
 {
     NM_ErrorCode res;
 
@@ -223,13 +230,17 @@ NetworkManager::NetworkManager():
     };
 }
 
-static void PushNotificationCallback(NM_NotificationData data, void*)
+static void PushNotificationCallback(NM_NotificationData data, void* userData)
 {
     LOG_DBG("BEGIN");
 
     if (data.message && data.title)
     {
+        //TODO: remove this line and uncomment the next two when "subscribe on notification" function is fixed.
         PushNotification::GetInstance().Push(data.title, data.message);
+
+        /*NetworkManager* nm = reinterpret_cast<NetworkManager*>(userData);
+        nm->NotifySubscribers(data.message, data.title);*/
     }
     else
     {
@@ -238,11 +249,36 @@ static void PushNotificationCallback(NM_NotificationData data, void*)
     LOG_DBG("END");
 }
 
-//ErrorCode NetworkManager::AddNotificationCallback(
-//        const NotificationCallback& callback)
-//{
-//    return ErrorCode::Success;
-//}
+ErrorCode NetworkManager::RegisterNotificationCallback(
+        const NotificationCallback& callback)
+{
+    if (callback)
+    {
+        m_notificationCallbackList.push_back(callback);
+        LOG_DBG("callback was registered successfully");
+
+        return ErrorCode::Success;
+    }
+
+    return ErrorCode::InvalidArgument;
+}
+
+ErrorCode NetworkManager::NotifySubscribers(const std::string& title, const std::string& message)
+{
+    for (auto callback : m_notificationCallbackList)
+    {
+        try
+        {
+            callback(title, message);
+        }
+        catch (...)
+        {
+            LOG_ERR("Caught exception");
+        }
+    }
+
+    return ErrorCode::Success;
+}
 
 ErrorCode NetworkManager::SubscribeOnNotifications()
 {
@@ -259,7 +295,14 @@ ErrorCode NetworkManager::SubscribeOnNotifications()
     return ErrorCode::Success;
 }
 
+ErrorCode NetworkManager::UnsubscribeOnNotifications()
+{
+    ASSERT_RETURN(m_moduleSymbols.m_nmUnsubsOnNotifFunc, "function isn't loaded", ErrorCode::FunctionNotFound);
+
+    m_moduleSymbols.m_nmUnsubsOnNotifFunc(m_context);
 
+    return ErrorCode::Success;
+}
 
 void NetworkManager::FreeCache()
 {
@@ -272,6 +315,7 @@ NetworkManager::~NetworkManager()
     if (m_context)
     {
         FreeCache();
+        UnsubscribeOnNotifications();
         m_moduleSymbols.m_nmCleanUpFunc(&m_context);
     }
 }
@@ -287,18 +331,8 @@ ErrorCode NetworkManager::LogIn(const UserInfo& userInfo,
         != NM_ErrorCode::EC_OK)
     {
         LOG_INFO("nnlib returned: %s", std::to_string(res).c_str());
-        switch (res)
-        {
-        case NM_ErrorCode::EC_AUTH_ERROR:
-        {
-            return ErrorCode::IncorrectIdOrPsswd;
-        }
-        default:
-        {
-            //TODO: define what we should do in case of no internet connection
-            return ErrorCode::Error;
-        }
-        }
+
+        return GetCorrespondingErrorCode(res);
     }
 
     SubscribeOnNotifications();
@@ -310,29 +344,32 @@ ErrorCode NetworkManager::LogOut()
 {
     ASSERT_RETURN(m_moduleSymbols.m_nmSignOutFunc, "function isn't loaded", ErrorCode::FunctionNotFound);
     FreeCache();
+    UnsubscribeOnNotifications();
     m_moduleSymbols.m_nmSignOutFunc(m_context);
 
     return ErrorCode::Success;
 }
 
-SessionState NetworkManager::GetSessionState()
+ErrorCode NetworkManager::GetSessionState(SessionState& sessionState)
 {
-    ASSERT_RETURN(m_moduleSymbols.m_nmGetSessionStateFunc, "function isn't loaded", SessionState::Closed);
+    ASSERT_RETURN(m_moduleSymbols.m_nmGetSessionStateFunc, "function isn't loaded", ErrorCode::FunctionNotFound);
     SignInState state = m_moduleSymbols.m_nmGetSessionStateFunc(m_context);
 
     switch (state)
     {
-        case SignInState::SIGNED_IN:
-        {
-            return SessionState::Open;
-        }
-        default:
-        {
-            return SessionState::Closed;
-        }
+    case SignInState::SIGNED_IN:
+    {
+        sessionState = SessionState::Open;
+        break;
+    }
+    default:
+    {
+        sessionState = SessionState::Closed;
+        break;
+    }
     }
 
-    return SessionState::Closed;
+    return ErrorCode::Success;
 }
 
 DevicePtr NetworkManager::ToDevice(const NM_DeviceInfo* device)
@@ -411,9 +448,9 @@ void NetworkManager::FreeDeviceList(NM_hDeviceList* nmList)
     nmList = nullptr;
 }
 
-DeviceList NetworkManager::GetOwnedDeviceList()
+ErrorCode NetworkManager::GetOwnedDeviceList(DeviceList& deviceList)
 {
-    ASSERT_RETURN(m_moduleSymbols.m_nmGetOwnedDevFunc, "function isn't loaded", DeviceList());
+    ASSERT_RETURN(m_moduleSymbols.m_nmGetOwnedDevFunc, "function isn't loaded", ErrorCode::FunctionNotFound);
     NM_ErrorCode res;
 
     if (m_ownedDevices)
@@ -425,15 +462,17 @@ DeviceList NetworkManager::GetOwnedDeviceList()
     {
         LOG_ERR("network manager returned: %s", std::to_string(res).c_str());
 
-        return DeviceList();
+        return GetCorrespondingErrorCode(res);
     }
 
-    return ToDeviceList(m_ownedDevices);
+    deviceList = ToDeviceList(m_ownedDevices);
+
+    return ErrorCode::Success;
 }
 
-DeviceList NetworkManager::GetUnownedDeviceList()
+ErrorCode NetworkManager::GetUnownedDeviceList(DeviceList& deviceList)
 {
-    ASSERT_RETURN(m_moduleSymbols.m_nmGetUnownedDevFunc, "function isn't loaded", DeviceList());
+    ASSERT_RETURN(m_moduleSymbols.m_nmGetUnownedDevFunc, "function isn't loaded", ErrorCode::FunctionNotFound);
     NM_ErrorCode res;
 
     FreeDeviceList(&m_unownedDevices);
@@ -442,10 +481,12 @@ DeviceList NetworkManager::GetUnownedDeviceList()
     {
         LOG_ERR("network manager returned: %s", std::to_string(res).c_str());
 
-        return DeviceList();
+        return GetCorrespondingErrorCode(res);
     }
 
-    return ToDeviceList(m_unownedDevices);
+    deviceList = ToDeviceList(m_unownedDevices);
+
+    return ErrorCode::Success;
 }
 
 ErrorCode NetworkManager::UnownDevice(const std::string& deviceId)
@@ -457,7 +498,7 @@ ErrorCode NetworkManager::UnownDevice(const std::string& deviceId)
     {
         LOG_ERR("network manager returned: %s", std::to_string(res).c_str());
 
-        return ErrorCode::Error;
+        return GetCorrespondingErrorCode(res);
     }
 
     return ErrorCode::Success;
@@ -472,7 +513,7 @@ ErrorCode NetworkManager::OwnDevice(const std::string& deviceId)
     {
         LOG_ERR("network manager returned: %s", std::to_string(res).c_str());
 
-        return ErrorCode::Error;
+        return GetCorrespondingErrorCode(res);
     }
 
     return ErrorCode::Success;
index 8185049..ba4b10d 100644 (file)
@@ -38,23 +38,23 @@ ErrorCode Presenter::LogOut()
     return m_model->LogOut();
 }
 
-SessionState Presenter::GetSessionState()
+ErrorCode Presenter::GetSessionState(SessionState& state)
 {
-    return m_model->GetSessionState();
+    return m_model->GetSessionState(state);
 }
 
 void Presenter::UpdateSessionState(SessionState sessionState)
 {
 }
 
-DeviceList Presenter::GetOwnedDeviceList()
+ErrorCode Presenter::GetOwnedDeviceList(DeviceList& deviceList)
 {
-    return m_model->GetOwnedDeviceList();
+    return m_model->GetOwnedDeviceList(deviceList);
 }
 
-DeviceList Presenter::GetUnownedDeviceList()
+ErrorCode Presenter::GetUnownedDeviceList(DeviceList& deviceList)
 {
-    return m_model->GetUnownedDeviceList();
+    return m_model->GetUnownedDeviceList(deviceList);
 }
 
 ErrorCode Presenter::UnownDevice(const std::string& deviceId)
index a7d49f1..ae14a10 100644 (file)
@@ -43,7 +43,7 @@ void UIConnectorWebViewCallback(const iotswsec::UIRemotePort& port, const std::s
         if (!webViewPtr)
         {
             LOG_ERR("Error:connector error");
-            response = std::to_string(iotswsec::MessageProcessResult::ErrorInternalConnectionFailed);
+            response = std::to_string(iotswsec::ErrorCode::InternalConnectionFailed);
             throw std::runtime_error("WebView instance is uninitialized");
         }
 
@@ -54,7 +54,7 @@ void UIConnectorWebViewCallback(const iotswsec::UIRemotePort& port, const std::s
     catch (const std::invalid_argument& e)
     {
         LOG_ERR("failed to parse JSON: %s", e.what());
-        response = std::to_string(iotswsec::MessageProcessResult::ErrorBadMessageFormat);
+        response = std::to_string(iotswsec::ErrorCode::BadMessageFormat);
     }
     catch (const std::exception& ex)
     {
@@ -111,7 +111,7 @@ bool service_app_create(void *data)
         return false;
     }
 
-    // Bind model to presenter.;
+    // Bind model to presenter.
     presenterPtr->SetModel(modelPtr);
     // Initialize view.
     webViewPtr = std::make_shared<iotswsec::WebView>(presenterPtr, WebViewCallback);
@@ -129,7 +129,8 @@ bool service_app_create(void *data)
 
 void service_app_terminate(void *data)
 {
-    // Todo: add your code here.
+    LOG_DBG("BEGIN");
+    LOG_DBG("END");
     return;
 }
 
index 94c159c..b12b4b4 100644 (file)
@@ -77,8 +77,8 @@ void WebView::Update(const std::string& command, const std::string& message)
 
 std::string WebView::ProcessRequest(const std::string& command, const JSONNode& attachedObject)
 {
-    LOG_INFO("command: %s", command.c_str());
-    LOG_INFO("attached object: %s", attachedObject.write().c_str());
+    LOG_DBG("command: %s", command.c_str());
+    LOG_DBG("attached object: %s", attachedObject.write().c_str());
 
     JSONNode response(JSON_NODE);
 
@@ -87,20 +87,20 @@ std::string WebView::ProcessRequest(const std::string& command, const JSONNode&
     if (callbackIterator == m_callbackMap.end())
     {
         LOG_ERR("Command %s, has no according callback", command.c_str());
-        response.push_back(JSONNode(ErrorCodeNodeName,  std::to_string(MessageProcessResult::ErrorUnregisteredCommand)));
+        response.push_back(JSONNode(ErrorCodeNodeName,  std::stoi(std::to_string(ErrorCode::UnregisteredCommand))));
     }
     else
     {
         JSONNode data = SetJSONNodeName(DataNodeName, JSONNode(JSON_NODE));
         std::string errDescription;
 
-        MessageProcessResult result = callbackIterator->second(attachedObject, data, errDescription);
+        ErrorCode result = callbackIterator->second(attachedObject, data, errDescription);
 
         response.push_back(JSONNode(ErrorCodeNodeName, std::stoi(std::to_string(result))));
 
-        if (result != MessageProcessResult::Success)
+        if (result != ErrorCode::Success)
         {
-            response.push_back(JSONNode(ErrDescNodeName, errDescription));
+            response.push_back(JSONNode(ErrDescNodeName, GetErrorDescription(result)));
         }
 
         response.push_back(data);
@@ -114,7 +114,7 @@ void WebView::RegisterCallback(const std::string& command, const Callback& callb
     m_callbackMap.insert(CallbackMap::value_type(command, callback));
 }
 
-MessageProcessResult WebView::LogIn(const JSONNode& request, JSONNode& response, std::string& errDescription) const
+ErrorCode WebView::LogIn(const JSONNode& request, JSONNode& response, std::string& errDescription) const
 {
     //Expected JSON:
     // "data" : {"login" : login, "password" : password}
@@ -123,7 +123,7 @@ MessageProcessResult WebView::LogIn(const JSONNode& request, JSONNode& response,
 
     if (!presenter)
     {
-        return MessageProcessResult::ErrorInternalConnectionFailed;
+        return ErrorCode::InternalConnectionFailed;
     }
 
     auto iteratorLogin = request.find("login");
@@ -135,19 +135,13 @@ MessageProcessResult WebView::LogIn(const JSONNode& request, JSONNode& response,
         UserInfo userInfo;
         userInfo.SetUserLogin(iteratorLogin->as_string());
 
-        if (presenter->LogIn(userInfo, iteratorPsswd->as_string()) != ErrorCode::Success)
-        {
-            errDescription = "Wrong credentials";
-            return MessageProcessResult::IncorrectIdOrPsswd;
-        }
-
-        return MessageProcessResult::Success;
+        return presenter->LogIn(userInfo, iteratorPsswd->as_string());
     }
 
-    return MessageProcessResult::ErrorBadMessageFormat;
+    return ErrorCode::BadMessageFormat;
 }
 
-MessageProcessResult WebView::LogOut(const JSONNode& request, JSONNode& response, std::string& errDescription) const
+ErrorCode WebView::LogOut(const JSONNode& request, JSONNode& response, std::string& errDescription) const
 {
     //Expected JSON:
     // "data" : {}
@@ -155,18 +149,13 @@ MessageProcessResult WebView::LogOut(const JSONNode& request, JSONNode& response
 
     if (!presenter)
     {
-        return MessageProcessResult::ErrorInternalConnectionFailed;
-    }
-
-    if (presenter->LogOut() != ErrorCode::Success)
-    {
-        return MessageProcessResult::NotLoggedIn;
+        return ErrorCode::InternalConnectionFailed;
     }
 
-    return MessageProcessResult::Success;
+    return presenter->LogOut();
 }
 
-MessageProcessResult WebView::GetSessionState(const JSONNode& request, JSONNode& response, std::string& errDescription) const
+ErrorCode WebView::GetSessionState(const JSONNode& request, JSONNode& response, std::string& errDescription) const
 {
     //Expected JSON:
     // "data" : {}
@@ -176,12 +165,18 @@ MessageProcessResult WebView::GetSessionState(const JSONNode& request, JSONNode&
 
     if (!presenter)
     {
-        return MessageProcessResult::ErrorInternalConnectionFailed;
+        return ErrorCode::InternalConnectionFailed;
     }
 
-    SessionState state = presenter->GetSessionState();
+    SessionState state = SessionState::Closed;
+    ErrorCode res;
     int webState = 1;
 
+    if ((res = presenter->GetSessionState(state)) != ErrorCode::Success)
+    {
+        return res;
+    }
+
     switch (state)
     {
     case SessionState::Open:
@@ -202,10 +197,10 @@ MessageProcessResult WebView::GetSessionState(const JSONNode& request, JSONNode&
 
     response.push_back(JSONNode("state", webState));
 
-    return MessageProcessResult::Success;
+    return ErrorCode::Success;
 }
 
-MessageProcessResult WebView::GetOwnedDevices(const JSONNode& request,
+ErrorCode WebView::GetOwnedDevices(const JSONNode& request,
         JSONNode& response, std::string& errDescription) const
 {
     //Expected JSON:
@@ -218,15 +213,23 @@ MessageProcessResult WebView::GetOwnedDevices(const JSONNode& request,
 
     if (!presenter)
     {
-        return MessageProcessResult::ErrorInternalConnectionFailed;
+        return ErrorCode::InternalConnectionFailed;
     }
 
-    response.push_back(SetJSONNodeName("devices", ToJson(presenter->GetOwnedDeviceList())));
+    DeviceList deviceList;
+    ErrorCode res;
+
+    if ((res = presenter->GetOwnedDeviceList(deviceList)) != ErrorCode::Success)
+    {
+        return res;
+    }
 
-    return MessageProcessResult::Success;
+    response.push_back(SetJSONNodeName("devices", ToJson(deviceList)));
+
+    return ErrorCode::Success;
 }
 
-MessageProcessResult WebView::GetUnownedDevices(const JSONNode& request,
+ErrorCode WebView::GetUnownedDevices(const JSONNode& request,
         JSONNode& response, std::string& errDescription) const
 {
     //Expected JSON:
@@ -239,15 +242,23 @@ MessageProcessResult WebView::GetUnownedDevices(const JSONNode& request,
 
     if (!presenter)
     {
-        return MessageProcessResult::ErrorInternalConnectionFailed;
+        return ErrorCode::InternalConnectionFailed;
+    }
+
+    DeviceList deviceList;
+    ErrorCode res;
+
+    if ((res = presenter->GetUnownedDeviceList(deviceList)) != ErrorCode::Success)
+    {
+        return res;
     }
 
-    response.push_back(SetJSONNodeName("devices", ToJson(presenter->GetUnownedDeviceList())));
+    response.push_back(SetJSONNodeName("devices", ToJson(deviceList)));
 
-    return MessageProcessResult::Success;
+    return ErrorCode::Success;
 }
 
-MessageProcessResult WebView::OwnDevice(const JSONNode& request,
+ErrorCode WebView::OwnDevice(const JSONNode& request,
         JSONNode& response, std::string& errDescription) const
 {
     //Expected JSON:
@@ -258,27 +269,29 @@ MessageProcessResult WebView::OwnDevice(const JSONNode& request,
 
     if (!presenter)
     {
-        return MessageProcessResult::ErrorInternalConnectionFailed;
+        return ErrorCode::InternalConnectionFailed;
     }
 
     auto iteratorId = request.find("id");
 
     if (iteratorId == request.end())
     {
-        return MessageProcessResult::ErrorBadMessageFormat;
+        return ErrorCode::BadMessageFormat;
     }
 
-    if (presenter->OwnDevice(iteratorId->as_string()) == ErrorCode::Success)
-    {
-        response.push_back(JSONNode("id", iteratorId->as_string()));
+    ErrorCode res;
 
-        return MessageProcessResult::Success;
+    if ((res = presenter->OwnDevice(iteratorId->as_string())) != ErrorCode::Success)
+    {
+        return res;
     }
 
-    return MessageProcessResult::Error;
+    response.push_back(JSONNode("id", iteratorId->as_string()));
+
+    return ErrorCode::Success;
 }
 
-MessageProcessResult WebView::UnownDevice(const JSONNode& request,
+ErrorCode WebView::UnownDevice(const JSONNode& request,
         JSONNode& response, std::string& errDescription) const
 {
     //Expected JSON:
@@ -289,32 +302,34 @@ MessageProcessResult WebView::UnownDevice(const JSONNode& request,
 
     if (!presenter)
     {
-        return MessageProcessResult::ErrorInternalConnectionFailed;
+        return ErrorCode::InternalConnectionFailed;
     }
 
     auto iteratorId = request.find("id");
 
     if (iteratorId == request.end())
     {
-        return MessageProcessResult::ErrorBadMessageFormat;
+        return ErrorCode::BadMessageFormat;
     }
 
-    if (presenter->UnownDevice(iteratorId->as_string()) == ErrorCode::Success)
-    {
-        response.push_back(JSONNode("id", iteratorId->as_string()));
+    ErrorCode res;
 
-        return MessageProcessResult::Success;
+    if ((res = presenter->UnownDevice(iteratorId->as_string())) != ErrorCode::Success)
+    {
+        return res;
     }
 
-    return MessageProcessResult::Error;
+    response.push_back(JSONNode("id", iteratorId->as_string()));
+
+    return ErrorCode::Success;
 }
 
-MessageProcessResult WebView::GetDashboard(const JSONNode& request,
+ErrorCode WebView::GetDashboard(const JSONNode& request,
         JSONNode& response, std::string& errDescription) const
 {
 
 
-    return MessageProcessResult::Error;
+    return ErrorCode::Error;
 }
 
 } //namespace iotswsec
index b4f784d..7bdd6b1 100644 (file)
@@ -39,14 +39,18 @@ TEST_F(NetworkManagerTest, SignInOutTest)
 
 TEST_F(NetworkManagerTest, GetSessionStateTest2)
 {
-    ASSERT_EQ(SessionState::Closed, m_nm.GetSessionState());
+    SessionState state;
+    ASSERT_EQ(ErrorCode::Success, m_nm.GetSessionState(state));
+    ASSERT_EQ(SessionState::Closed, state);
 }
 
 TEST_F(NetworkManagerTest, GetSessionStateTest)
 {
     ASSERT_EQ(ErrorCode::Success, m_nm.LogIn(m_usrInf, m_pass));
 
-    ASSERT_EQ(SessionState::Open, m_nm.GetSessionState());
+    SessionState state;
+    EXPECT_EQ(ErrorCode::Success, m_nm.GetSessionState(state));
+    EXPECT_EQ(SessionState::Open, state);
 
     EXPECT_EQ(ErrorCode::Success, m_nm.LogOut());
 }
@@ -73,9 +77,13 @@ TEST_F(NetworkManagerTest, GetOwnedDevicesTest)
 {
     ASSERT_EQ(ErrorCode::Success, m_nm.LogIn(m_usrInf, m_pass));
 
-    ASSERT_EQ(SessionState::Open, m_nm.GetSessionState());
+    SessionState state;
+    EXPECT_EQ(ErrorCode::Success, m_nm.GetSessionState(state));
+    EXPECT_EQ(SessionState::Open, state);
 
-    DeviceList devList = m_nm.GetOwnedDeviceList();
+    DeviceList devList;
+
+    EXPECT_EQ(ErrorCode::Success, m_nm.GetOwnedDeviceList(devList));
 
     std::cout << "Number of found owned diveces: " << devList.size() << std::endl;
 
@@ -86,9 +94,13 @@ TEST_F(NetworkManagerTest, GetUnownedDevicesTest)
 {
     ASSERT_EQ(ErrorCode::Success, m_nm.LogIn(m_usrInf, m_pass));
 
-    ASSERT_EQ(SessionState::Open, m_nm.GetSessionState());
+    SessionState state;
+    EXPECT_EQ(ErrorCode::Success, m_nm.GetSessionState(state));
+    EXPECT_EQ(SessionState::Open, state);
+
+    DeviceList devList;
 
-    DeviceList devList = m_nm.GetUnownedDeviceList();
+    EXPECT_EQ(ErrorCode::Success, m_nm.GetUnownedDeviceList(devList));
 
     std::cout << "Number of found unowned diveces: " << devList.size() << std::endl;
 
@@ -99,9 +111,13 @@ TEST_F(NetworkManagerTest, OwnDeviceTest)
 {
     ASSERT_EQ(ErrorCode::Success, m_nm.LogIn(m_usrInf, m_pass));
 
-    ASSERT_EQ(SessionState::Open, m_nm.GetSessionState());
+    SessionState state;
+    EXPECT_EQ(ErrorCode::Success, m_nm.GetSessionState(state));
+    EXPECT_EQ(SessionState::Open, state);
 
-    DeviceList devList = m_nm.GetUnownedDeviceList();
+    DeviceList devList;
+
+    EXPECT_EQ(ErrorCode::Success, m_nm.GetUnownedDeviceList(devList));
 
     std::cout << "Number of found unowned diveces: " << devList.size() << std::endl;
 
@@ -117,9 +133,13 @@ TEST_F(NetworkManagerTest, UnownDeviceTest)
 {
     ASSERT_EQ(ErrorCode::Success, m_nm.LogIn(m_usrInf, m_pass));
 
-    ASSERT_EQ(SessionState::Open, m_nm.GetSessionState());
+    SessionState state;
+    EXPECT_EQ(ErrorCode::Success, m_nm.GetSessionState(state));
+    EXPECT_EQ(SessionState::Open, state);
+
+    DeviceList devList;
 
-    DeviceList devList = m_nm.GetOwnedDeviceList();
+    EXPECT_EQ(ErrorCode::Success, m_nm.GetUnownedDeviceList(devList));
 
     std::cout << "Number of found owned diveces: " << devList.size() << std::endl;
 
index 88c7ec2..feab17a 100644 (file)
@@ -26,7 +26,7 @@ public:
         if (userInfo.GetUserLogin().compare("iotgod")
             || psswd.compare("iotivity"))
         {
-            return ErrorCode::IncorrectIdOrPsswd;
+            return ErrorCode::AuthError;
         }
         m_sessionState = true;
 
@@ -37,32 +37,34 @@ public:
     {
         if (!m_sessionState)
         {
-            return ErrorCode::NotLoggedIn;
+            return ErrorCode::NotAuthorized;
         }
 
         m_sessionState = false;
         return ErrorCode::Success;
     }
 
-    SessionState GetSessionState() override
+    ErrorCode GetSessionState(SessionState& state) override
     {
-        return m_sessionState ? SessionState::Open : SessionState::Closed;
+        state = (m_sessionState) ? SessionState::Open : SessionState::Closed;
+
+        return ErrorCode::Success;
     }
 
-    DeviceList GetOwnedDeviceList() override
+    ErrorCode GetOwnedDeviceList(DeviceList& deviceList) override
     {
-        DeviceList list({std::make_shared<Device>("123456789", "My TV", "smart-tv", "TV device", 0),
-                        std::make_shared<Device>("1234567890", "My Smartphone", "smartphone", "Smartphone device", 1)});
+        deviceList = {std::make_shared<Device>("123456789", "My TV", "smart-tv", "TV device", 0),
+                      std::make_shared<Device>("1234567890", "My Smartphone", "smartphone", "Smartphone device", 1)};
 
-        return list;
+        return ErrorCode::Success;
     }
 
-    DeviceList GetUnownedDeviceList() override
+    ErrorCode GetUnownedDeviceList(DeviceList& deviceList) override
     {
-        DeviceList list({std::make_shared<Device>("123456789", "My TV", "smart-tv", "TV device", 0),
-                        std::make_shared<Device>("1234567890", "My Smartphone", "smartphone", "Smartphone device", 1)});
+        deviceList = {std::make_shared<Device>("123456789", "My TV", "smart-tv", "TV device", 0),
+                      std::make_shared<Device>("1234567890", "My Smartphone", "smartphone", "Smartphone device", 1)};
 
-        return list;
+        return ErrorCode::Success;
     }
 
     ErrorCode UnownDevice(const std::string& deviceId) override
@@ -124,9 +126,9 @@ TEST_F(WebViewTest, LogInTest1)
     request.push_back(JSONNode("password", "iotivity"));
     JSONNode response;
     std::string errDesc;
-    MessageProcessResult result = webViewPtr->LogIn(request, response, errDesc);
+    ErrorCode result = webViewPtr->LogIn(request, response, errDesc);
 
-    EXPECT_EQ(MessageProcessResult::Success, result);
+    EXPECT_EQ(ErrorCode::Success, result);
 }
 
 TEST_F(WebViewTest, LogInTest2)
@@ -136,9 +138,9 @@ TEST_F(WebViewTest, LogInTest2)
     request.push_back(JSONNode("password", "smth_else"));
     JSONNode response;
     std::string errDesc;
-    MessageProcessResult result = webViewPtr->LogIn(request, response, errDesc);
+    ErrorCode result = webViewPtr->LogIn(request, response, errDesc);
 
-    EXPECT_EQ(MessageProcessResult::IncorrectIdOrPsswd, result);
+    EXPECT_EQ(ErrorCode::AuthError, result);
 }
 
 TEST_F(WebViewTest, LogOutTest1)
@@ -146,9 +148,9 @@ TEST_F(WebViewTest, LogOutTest1)
     JSONNode request(JSON_NODE);
     JSONNode response;
     std::string errDesc;
-    MessageProcessResult result = webViewPtr->LogOut(request, response, errDesc);
+    ErrorCode result = webViewPtr->LogOut(request, response, errDesc);
 
-    EXPECT_EQ(MessageProcessResult::NotLoggedIn, result);
+    EXPECT_EQ(ErrorCode::NotAuthorized, result);
 }
 
 TEST_F(WebViewTest, LogOutTest2)
@@ -160,9 +162,9 @@ TEST_F(WebViewTest, LogOutTest2)
     std::string errDesc;
     webViewPtr->LogIn(request, response, errDesc);
 
-    MessageProcessResult result = webViewPtr->LogOut(request, response, errDesc);
+    ErrorCode result = webViewPtr->LogOut(request, response, errDesc);
 
-    EXPECT_EQ(MessageProcessResult::Success, result);
+    EXPECT_EQ(ErrorCode::Success, result);
 }
 
 TEST_F(WebViewTest, GetSessionState1)
@@ -174,9 +176,9 @@ TEST_F(WebViewTest, GetSessionState1)
     std::string errDesc;
     webViewPtr->LogIn(request, response, errDesc);
 
-    MessageProcessResult result = webViewPtr->GetSessionState(request, response, errDesc);
+    ErrorCode result = webViewPtr->GetSessionState(request, response, errDesc);
 
-    EXPECT_EQ(MessageProcessResult::Success, result);
+    EXPECT_EQ(ErrorCode::Success, result);
 }
 
 TEST_F(WebViewTest, GetSessionState2)
@@ -190,9 +192,9 @@ TEST_F(WebViewTest, GetSessionState2)
 
     JSONNode stateRequest;
     JSONNode stateResponse;
-    MessageProcessResult result = webViewPtr->GetSessionState(stateRequest, stateResponse, errDesc);
+    ErrorCode result = webViewPtr->GetSessionState(stateRequest, stateResponse, errDesc);
 
-    EXPECT_EQ(MessageProcessResult::Success, result);
+    EXPECT_EQ(ErrorCode::Success, result);
     EXPECT_EQ(std::string("{\"state\":0}"), stateResponse.write());
 }
 
@@ -201,9 +203,9 @@ TEST_F(WebViewTest, GetOwnedDevicesTest1)
     JSONNode ownedGetRequest;
     JSONNode ownedGetResponse;
     std::string errDesc;
-    MessageProcessResult result = webViewPtr->GetOwnedDevices(ownedGetRequest, ownedGetResponse, errDesc);
+    ErrorCode result = webViewPtr->GetOwnedDevices(ownedGetRequest, ownedGetResponse, errDesc);
 
-    EXPECT_EQ(MessageProcessResult::Success, result);
+    EXPECT_EQ(ErrorCode::Success, result);
     EXPECT_EQ(std::string(R"({"devices":[{"id":"123456789","name":"My TV","type":"smart-tv","status":0,)"
                              R"("description":"TV device"},)"
                              R"({"id":"1234567890","name":"My Smartphone","type":"smartphone","status":1,)"
@@ -215,9 +217,9 @@ TEST_F(WebViewTest, GetUnownedDevicesTest1)
     JSONNode unownedGetRequest;
     JSONNode unownedGetResponse;
     std::string errDesc;
-    MessageProcessResult result = webViewPtr->GetUnownedDevices(unownedGetRequest, unownedGetResponse, errDesc);
+    ErrorCode result = webViewPtr->GetUnownedDevices(unownedGetRequest, unownedGetResponse, errDesc);
 
-    EXPECT_EQ(MessageProcessResult::Success, result);
+    EXPECT_EQ(ErrorCode::Success, result);
     EXPECT_EQ(std::string(R"({"devices":[{"id":"123456789","name":"My TV","type":"smart-tv","status":0,)"
                              R"("description":"TV device"},)"
                              R"({"id":"1234567890","name":"My Smartphone","type":"smartphone","status":1,)"
@@ -231,9 +233,9 @@ TEST_F(WebViewTest, OwnDeviceTest1)
     std::string errDesc;
     const std::string id("123");
     ownRequest.push_back(JSONNode("id", id));
-    MessageProcessResult result = webViewPtr->OwnDevice(ownRequest, ownResponse, errDesc);
+    ErrorCode result = webViewPtr->OwnDevice(ownRequest, ownResponse, errDesc);
 
-    EXPECT_EQ(MessageProcessResult::Success, result);
+    EXPECT_EQ(ErrorCode::Success, result);
     EXPECT_EQ(std::string(R"({"id":")" + id + R"("})"), ownResponse.write());
 }
 
@@ -244,9 +246,9 @@ TEST_F(WebViewTest, UnownDeviceTest1)
     std::string errDesc;
     const std::string id("123");
     unownRequest.push_back(JSONNode("id", id));
-    MessageProcessResult result = webViewPtr->UnownDevice(unownRequest, unownResponse, errDesc);
+    ErrorCode result = webViewPtr->UnownDevice(unownRequest, unownResponse, errDesc);
 
-    EXPECT_EQ(MessageProcessResult::Success, result);
+    EXPECT_EQ(ErrorCode::Success, result);
     EXPECT_EQ(std::string(R"({"id":")" + id + R"("})"), unownResponse.write());
 }
 
@@ -257,9 +259,9 @@ TEST_F(WebViewTest, GetDashboardTest1)
     std::string errDesc;
     const std::string id("123");
     getDashboardRequest.push_back(JSONNode("id", id));
-    MessageProcessResult result = webViewPtr->GetDashboard(getDashboardRequest, getDashboardResponse, errDesc);
+    ErrorCode result = webViewPtr->GetDashboard(getDashboardRequest, getDashboardResponse, errDesc);
 
-    EXPECT_EQ(MessageProcessResult::Success, result);
+    EXPECT_EQ(ErrorCode::Success, result);
 }
 
 } //namespace iotswsec