Modify error messages in vconf and wifi plugins
authorJinWang An <jinwang.an@samsung.com>
Fri, 8 Nov 2019 01:18:22 +0000 (10:18 +0900)
committerYoungjae Shin <yj99.shin@samsung.com>
Thu, 19 Mar 2020 04:30:37 +0000 (13:30 +0900)
vconf/VconfAction.cpp
wifi/CMakeLists.txt
wifi/WifiAction.cpp
wifi/WifiAction.h
wifi/WifiActionPower.cpp
wifi/WifiErrorMessage.h [deleted file]
wifi/WifiErrorMessageGenerator.sh [deleted file]
wifi/WifiPlugin.cpp

index e31d745..66a080a 100644 (file)
@@ -35,8 +35,8 @@ int VconfAction::setChangedCallback(valueChangedCB callback, void *userData)
        callbackMap[key].callback = callback;
 
        int ret = vconf_notify_key_changed(key.c_str(), vconfChangedCallback, &callbackMap[key]);
-       if (VCONF_OK != ret) {
-               ERR("vconf_notify_key_changed(%s) Fail(%s)", key.c_str(), get_error_message(ret));
+       if (0 != ret) {
+               ERR("vconf_notify_key_changed(%s) Fail(%d)", key.c_str(), ret);
                return MODES_ERROR_SYSTEM;
        }
 
@@ -54,8 +54,8 @@ int VconfAction::unSetChangedCallback(valueChangedCB callback, void * userData)
 
        callbackMap.erase(found);
        int ret = vconf_ignore_key_changed(key.c_str(), vconfChangedCallback);
-       if (VCONF_OK != ret) {
-               ERR("vconf_ignore_key_changed(%s) Fail(%s)", key.c_str(), get_error_message(ret));
+       if (0 != ret) {
+               ERR("vconf_ignore_key_changed(%s) Fail(%d)", key.c_str(), ret);
                return MODES_ERROR_SYSTEM;
        }
 
@@ -72,8 +72,8 @@ int VconfAction::handleChange()
 
                callbackMap.erase(found);
                int ret = vconf_ignore_key_changed(key.c_str(), vconfChangedCallback);
-               if (VCONF_OK != ret) {
-                       ERR("vconf_ignore_key_changed(%s) Fail(%s)", key.c_str(), get_error_message(ret));
+               if (0 != ret) {
+                       ERR("vconf_ignore_key_changed(%s) Fail(%d)", key.c_str(), ret);
                        return MODES_ERROR_SYSTEM;
                }
        }
@@ -99,6 +99,6 @@ void VconfAction::vconfChangedCallback(keynode_t *node, void *userData)
 
        callbackMap.erase(found);
        int ret = vconf_ignore_key_changed(node->keyname, vconfChangedCallback);
-       if (VCONF_OK != ret)
-               ERR("vconf_ignore_key_changed(%s) Fail(%s)", node->keyname, get_error_message(ret));
+       if (0 != ret)
+               ERR("vconf_ignore_key_changed(%s) Fail(%d)", node->keyname, ret);
 }
index 8ab197e..8c94603 100644 (file)
@@ -6,14 +6,6 @@ pkg_check_modules(wifi_pkgs REQUIRED modes dlog capi-base-common capi-network-wi
 INCLUDE_DIRECTORIES(${wifi_pkgs_INCLUDE_DIRS})
 LINK_DIRECTORIES(${wifi_pkgs_LIBRARY_DIRS})
 
-# ==== WifiErrorMessage Header genertor ====
-#ADD_CUSTOM_TARGET(
-#    genWifiErrorMessage
-#    COMMAND echo "Run WifiErrorMessage Generator"
-#    COMMAND tool/WifiErrorMessageGenerator.sh
-#)
-#ADD_DEPENDENCIES(${WIFI_PLUGIN} genWifiErrorMessage)
-
 ADD_LIBRARY(${WIFI_PLUGIN} SHARED ${WIFI_SRCS})
 TARGET_LINK_LIBRARIES(${WIFI_PLUGIN} ${wifi_pkgs_LIBRARIES})
 SET_TARGET_PROPERTIES(${WIFI_PLUGIN} PROPERTIES NO_SONAME 1 )
index f70c00b..1f7b1fc 100644 (file)
@@ -25,16 +25,11 @@ WifiAction::WifiAction(const std::string &name)
        : PluginAction(name), handle(NULL)
 {
        int ret = wifi_manager_initialize(&handle);
-       if (ret != WIFI_MANAGER_ERROR_NONE)
-               ERR("wifi_manager_initialize() Fail(%d)", ret);
+       if (WIFI_MANAGER_ERROR_NONE != ret)
+               ERR("wifi_manager_initialize() Fail(%s)", get_error_message(ret));
 }
 
 WifiAction::~WifiAction()
 {
        wifi_manager_deinitialize(handle);
 }
-
-const std::string& WifiAction::strErr(int err)
-{
-       return wifiErrorMessage.get(err);
-}
index ed27dac..e7ddac3 100644 (file)
@@ -18,7 +18,7 @@
 #include <string>
 #include <wifi-manager.h>
 #include <PluginAction.h>
-#include "WifiErrorMessage.h"
+#include "plugin-def.h"
 
 MODES_NAMESPACE_BEGIN
 
@@ -29,8 +29,6 @@ public:
 
        virtual int set(bool val) = 0;
 protected:
-       const std::string& strErr(int err);
-       WifiErrorMessage wifiErrorMessage;
        wifi_manager_h handle;
 };
 
index 83a13c1..8993a4c 100644 (file)
@@ -39,13 +39,13 @@ int WifiActionPower::set(bool val)
        if (val) {
                int ret = wifi_manager_activate(handle, activateCB, this);
                if (WIFI_MANAGER_ERROR_NONE != ret) {
-                       ERR("wifi_manager_activate() Fail(%d, %s)", ret, strErr(ret).c_str());
+                       ERR("wifi_manager_activate() Fail(%s)", get_error_message(ret));
                        return MODES_ERROR_SYSTEM;
                }
        } else {
                int ret = wifi_manager_deactivate(handle, deactivateCB, this);
                if (WIFI_MANAGER_ERROR_NONE != ret) {
-                       ERR("wifi_manager_deactivate() Fail(%d, %s)", ret, strErr(ret).c_str());
+                       ERR("wifi_manager_deactivate() Fail(%s)", get_error_message(ret));
                        return MODES_ERROR_SYSTEM;
                }
        }
@@ -81,7 +81,7 @@ int WifiActionPower::setChangedCallback(valueChangedCB callback, void *userData)
 
        int ret = wifi_manager_set_device_state_changed_cb(handle, wifiStateChangedCB, this);
        if (WIFI_MANAGER_ERROR_NONE != ret) {
-               ERR("wifi_manager_set_device_state_changed_cb() Fail(%s)", strErr(ret).c_str());
+               ERR("wifi_manager_set_device_state_changed_cb() Fail(%s)", get_error_message(ret));
                return MODES_ERROR_SYSTEM;
        }
 
@@ -97,7 +97,7 @@ int WifiActionPower::unSetChangedCallback(valueChangedCB callback, void *userDat
 
        int ret = wifi_manager_unset_device_state_changed_cb(handle);
        if (WIFI_MANAGER_ERROR_NONE != ret) {
-               ERR("wifi_manager_unset_device_state_changed_cb() Fail(%s)", strErr(ret).c_str());
+               ERR("wifi_manager_unset_device_state_changed_cb() Fail(%s)", get_error_message(ret));
                return MODES_ERROR_SYSTEM;
        }
 
@@ -112,8 +112,7 @@ void WifiActionPower::activateCB(wifi_manager_error_e result, void *user_data)
 {
        INFO("wifi Activated");
        if (WIFI_MANAGER_ERROR_NONE != result) {
-               const std::string &errStr = ((WifiActionPower*)user_data)->strErr(result);
-               ERR("activateCB() Fail(%d, %s)", result, errStr.c_str());
+               ERR("activateCB() Fail(%s)", get_error_message(result));
        }
 }
 
@@ -121,8 +120,7 @@ void WifiActionPower::deactivateCB(wifi_manager_error_e result, void *user_data)
 {
        INFO("wifi Deactivated");
        if (WIFI_MANAGER_ERROR_NONE != result) {
-               const std::string &errStr = ((WifiActionPower*)user_data)->strErr(result);
-               ERR("deactivateCB() Fail(%d, %s)", result, errStr.c_str());
+               ERR("deactivateCB() Fail(%s)", get_error_message(result));
        }
 }
 
diff --git a/wifi/WifiErrorMessage.h b/wifi/WifiErrorMessage.h
deleted file mode 100644 (file)
index 06ef362..0000000
+++ /dev/null
@@ -1,84 +0,0 @@
-/*
- * Copyright (c) 2019 Samsung Electronics Co., Ltd All Rights Reserved
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-#pragma once
-
-#include <string>
-#include <map>
-#include <utility>
-#include <stdexcept>
-#include <wifi-manager.h>
-#include "plugin-def.h"
-
-MODES_NAMESPACE_BEGIN
-
-#define WIFI_ERROR_PAIR(err) std::pair<int, std::string>(WIFI_MANAGER_ERROR_##err, #err)
-#define CREATE_WIFI_ERROR_MESSAGE_MAP() \
-       do { \
-               wifiErrorMessageMap.clear(); \
-               wifiErrorMessageMap.insert(std::pair<int, std::string>(WIFI_MANAGER_ERROR_NONE, "Success")); \
-               wifiErrorMessageMap.insert(WIFI_ERROR_PAIR(INVALID_PARAMETER)); \
-               wifiErrorMessageMap.insert(WIFI_ERROR_PAIR(OUT_OF_MEMORY)); \
-               wifiErrorMessageMap.insert(WIFI_ERROR_PAIR(INVALID_OPERATION)); \
-               wifiErrorMessageMap.insert(WIFI_ERROR_PAIR(ADDRESS_FAMILY_NOT_SUPPORTED)); \
-               wifiErrorMessageMap.insert(WIFI_ERROR_PAIR(OPERATION_FAILED)); \
-               wifiErrorMessageMap.insert(WIFI_ERROR_PAIR(NO_CONNECTION)); \
-               wifiErrorMessageMap.insert(WIFI_ERROR_PAIR(NOW_IN_PROGRESS)); \
-               wifiErrorMessageMap.insert(WIFI_ERROR_PAIR(ALREADY_EXISTS)); \
-               wifiErrorMessageMap.insert(WIFI_ERROR_PAIR(OPERATION_ABORTED)); \
-               wifiErrorMessageMap.insert(WIFI_ERROR_PAIR(DHCP_FAILED)); \
-               wifiErrorMessageMap.insert(WIFI_ERROR_PAIR(INVALID_KEY)); \
-               wifiErrorMessageMap.insert(WIFI_ERROR_PAIR(NO_REPLY)); \
-               wifiErrorMessageMap.insert(WIFI_ERROR_PAIR(SECURITY_RESTRICTED)); \
-               wifiErrorMessageMap.insert(WIFI_ERROR_PAIR(ALREADY_INITIALIZED)); \
-               wifiErrorMessageMap.insert(WIFI_ERROR_PAIR(OUT_OF_RANGE)); \
-               wifiErrorMessageMap.insert(WIFI_ERROR_PAIR(CONNECT_FAILED)); \
-               wifiErrorMessageMap.insert(WIFI_ERROR_PAIR(LOGIN_FAILED)); \
-               wifiErrorMessageMap.insert(WIFI_ERROR_PAIR(AUTHENTICATION_FAILED)); \
-               wifiErrorMessageMap.insert(WIFI_ERROR_PAIR(PIN_MISSING)); \
-               wifiErrorMessageMap.insert(WIFI_ERROR_PAIR(WPS_OVERLAP)); \
-               wifiErrorMessageMap.insert(WIFI_ERROR_PAIR(WPS_TIMEOUT)); \
-               wifiErrorMessageMap.insert(WIFI_ERROR_PAIR(WPS_WEP_PROHIBITED)); \
-               wifiErrorMessageMap.insert(WIFI_ERROR_PAIR(PERMISSION_DENIED)); \
-               wifiErrorMessageMap.insert(WIFI_ERROR_PAIR(OFFLINE)); \
-               wifiErrorMessageMap.insert(WIFI_ERROR_PAIR(INVALID_GATEWAY)); \
-               wifiErrorMessageMap.insert(WIFI_ERROR_PAIR(NOT_SUPPORTED)); \
-               wifiErrorMessageMap.insert(WIFI_ERROR_PAIR(NOT_INITIALIZED)); \
-       } while (0)
-
-class WifiErrorMessage {
-public:
-       WifiErrorMessage()
-       {
-               CREATE_WIFI_ERROR_MESSAGE_MAP();
-       }
-       ~WifiErrorMessage()
-       {
-       }
-
-       const std::string& get(int key)
-       {
-               try {
-                       return wifiErrorMessageMap.at(key);
-               }
-               catch (const std::out_of_range& oor) {
-                       static const std::string empty = "";
-                       return empty;
-               }
-       }
-private:
-       std::map<int, std::string> wifiErrorMessageMap;
-};
-MODES_NAMESPACE_END
diff --git a/wifi/WifiErrorMessageGenerator.sh b/wifi/WifiErrorMessageGenerator.sh
deleted file mode 100644 (file)
index 183dfe8..0000000
+++ /dev/null
@@ -1,77 +0,0 @@
-#!/bin/sh
-
-sourceFileName="/usr/include/network/wifi-manager.h"
-targetFileName="WifiErrorMessage.h"
-
-main() {
-
-    if [ ! -f $sourceFileName ]
-    then
-        echo "wifi-manager.h not found!"
-        exit 1
-    fi
-cat > $targetFileName << EOL
-/*
- * Copyright (c) 2019 Samsung Electronics Co., Ltd All Rights Reserved
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#pragma once
-
-#include <string>
-#include <map>
-#include <utility>
-#include <wifi-manager.h>
-#include "common/definitions.h"
-
-MODES_NAMESPACE_BEGIN
-
-#define WIFI_ERROR_PAIR(err) std::pair<int, std::string>(WIFI_MANAGER_ERROR_##err, #err)
-EOL
-
-echo "#define CREATE_WIFI_ERROR_MESSAGE_MAP() \\
-    do { \\
-        wifiErrorMessageMap.clear(); \\
-        wifiErrorMessageMap.insert(std::pair<int, std::string>(WIFI_MANAGER_ERROR_NONE, \"Success\")); \\" >> $targetFileName
-
-cat $sourceFileName | grep -P "^\tWIFI_MANAGER_ERROR_" | grep -v "WIFI_MANAGER_ERROR_NONE" | sed 's/WIFI_MANAGER_ERROR_//g' | awk '{ print "\t\twifiErrorMessageMap.insert(WIFI_ERROR_PAIR(" $1 ")); \\" }' >> $targetFileName
-
-cat >> $targetFileName << EOL
-    } while (0)
-
-class WifiErrorMessage {
-public:
-    WifiErrorMessage(){
-        CREATE_WIFI_ERROR_MESSAGE_MAP();
-    }
-    ~WifiErrorMessage(){
-    }
-
-    std::string get( int key ){
-               if( wifiErrorMessageMap.count(key) <= 0 )
-                       return std::string();
-
-               return wifiErrorMessageMap[key];
-    }
-private:
-    std::map<int, std::string> wifiErrorMessageMap;
-};
-MODES_NAMESPACE_END
-EOL
-
-    echo "$targetFileName generate complete!"
-}
-
-
-main $@
index 78ce07a..cdb0245 100644 (file)
@@ -18,7 +18,6 @@
 #include <wifi-manager.h>
 #include <Plugin.h>
 #include "plugin-log.h"
-#include "WifiErrorMessage.h"
 #include "WifiFactory.h"
 
 MODES_NAMESPACE_USE;