cpp.hint
*.cd
+# project config
+.cproject
+.project
+.settings/*
+
# Prerequisites
*.d
{
return MODES_ERROR_NOT_SUPPORTED;
}
- virtual int set(std::string key, float data)
+ virtual int set(std::string key, double data)
{
return MODES_ERROR_NOT_SUPPORTED;
}
return MODES_ERROR_NOT_SUPPORTED;
}
- virtual int getInt(std::string key) = 0;
- virtual bool getBool(std::string key) = 0;
- virtual std::string getString(std::string key) = 0;
+ virtual int getInt(std::string key)
+ {
+ return 0;
+ }
+ virtual double getDouble(std::string key)
+ {
+ return 0;
+ }
+ virtual bool getBool(std::string key)
+ {
+ return false;
+ }
+ virtual std::string getString(std::string key)
+ {
+ return std::string();
+ }
private:
std::string name; /* plugin key */
BuildRequires: pkgconfig(capi-base-common)
BuildRequires: pkgconfig(libxml-2.0)
BuildRequires: pkgconfig(vconf)
+BuildRequires: pkgconfig(capi-network-wifi-manager)
BuildRequires: pkgconfig(gmock)
%description
%files plugins
%manifest %{name}.manifest
-%{_libdir}/modes/plugin/lib*.so.*
+%{_libdir}/modes/plugin/lib*.so
%license LICENSE.APLv2
%files devel
%{_libdir}/lib%{name}*.so
-%{_libdir}/modes/plugin/lib*.so
%{_libdir}/pkgconfig/%{name}*.pc
%{_includedir}/%{name}/*.h
BtPlugin();
~BtPlugin();
- int set(std::string key, std::string data);
int set(std::string key, int data);
+ int set(std::string key, double data);
int set(std::string key, bool data);
+ int set(std::string key, std::string data);
- std::string getString(std::string key);
int getInt(std::string key);
+ double getDouble(std::string key);
bool getBool(std::string key);
+ std::string getString(std::string key);
};
extern "C" API PluginAbstract *objectCreate(void)
{
}
-int BtPlugin::set(std::string key, std::string data)
+int BtPlugin::set(std::string key, int data)
{
- DBG("BtPlugin::set string ( %s, %s )", key.c_str(), data.c_str());
-
+ DBG("BtPlugin::set int ( %s, %d )", key.c_str(), data);
return MODES_ERROR_NONE;
}
-int BtPlugin::set(std::string key, int data)
+int BtPlugin::set(std::string key, double data)
{
- DBG("BtPlugin::set int ( %s, %d )", key.c_str(), data);
-
+ DBG("BtPlugin::set double ( %s, %lf )", key.c_str(), data);
return MODES_ERROR_NONE;
}
int BtPlugin::set(std::string key, bool data)
{
DBG("BtPlugin::set bool ( %s, %d )", key.c_str(), data);
-
return MODES_ERROR_NONE;
}
-std::string BtPlugin::getString(std::string key)
+int BtPlugin::set(std::string key, std::string data)
{
- DBG("BtPlugin::getString( string )\n");
-
- return "Happy";
+ DBG("BtPlugin::set string ( %s, %s )", key.c_str(), data.c_str());
+ return MODES_ERROR_NONE;
}
int BtPlugin::getInt(std::string key)
{
DBG("BtPlugin::getInt( string )\n");
+ return 0;
+}
- return 1004;
+double BtPlugin::getDouble(std::string key)
+{
+ DBG("BtPlugin::getDouble( string )\n");
+ return 0;
}
bool BtPlugin::getBool(std::string key)
{
DBG("BtPlugin::getBool( string )\n");
+ return false;
+}
- return true;
+std::string BtPlugin::getString(std::string key)
+{
+ DBG("BtPlugin::getString( string )\n");
+ return std::string();
}
+
-pkg_check_modules(plugin_pkgs REQUIRED dlog capi-base-common vconf)
+pkg_check_modules(plugin_pkgs REQUIRED dlog capi-base-common vconf capi-network-wifi-manager)
INCLUDE_DIRECTORIES(${plugin_pkgs_INCLUDE_DIRS})
LINK_DIRECTORIES(${plugin_pkgs_LIBRARY_DIRS})
ADD_DEFINITIONS("-DMDS_PLUGIN")
#==================================================================================================#
SET(LIB_NAME mdsp-WifiPlugin)
-FILE(GLOB WIFI_PLUGIN_SRCS WifiPlugin.cpp )
-
+FILE(GLOB WIFI_PLUGIN_SRCS WifiPlugin.cpp WifiFactory.cpp WifiAction.cpp WifiActionPower.cpp )
ADD_LIBRARY(${LIB_NAME} SHARED ${WIFI_PLUGIN_SRCS})
TARGET_LINK_LIBRARIES(${LIB_NAME} ${plugin_pkgs_LIBRARIES})
-SET_TARGET_PROPERTIES(${LIB_NAME} PROPERTIES VERSION ${FULLVER} SOVERSION ${MAJORVER})
+SET_TARGET_PROPERTIES(${LIB_NAME} PROPERTIES NO_SONAME 1 )
INSTALL(TARGETS ${LIB_NAME} DESTINATION ${LIB_PLUGIN_DIR})
#==================================================================================================#
+# ==== WifiErrorMessage Header genertor ====
+#ADD_CUSTOM_TARGET(
+# genWifiErrorMessage
+# COMMAND echo "Run WifiErrorMessage Generator"
+# COMMAND ./WifiErrorMessageGenerator.sh
+#)
+#ADD_DEPENDENCIES( mdsp-WifiPlugin genWifiErrorMessage)
+#==================================================================================================#
SET(LIB_NAME mdsp-BtPlugin )
FILE(GLOB BT_PLUGIN_SRCS BtPlugin.cpp )
ADD_LIBRARY(${LIB_NAME} SHARED ${BT_PLUGIN_SRCS})
TARGET_LINK_LIBRARIES(${LIB_NAME} ${plugin_pkgs_LIBRARIES})
-SET_TARGET_PROPERTIES(${LIB_NAME} PROPERTIES VERSION ${FULLVER} SOVERSION ${MAJORVER})
+SET_TARGET_PROPERTIES(${LIB_NAME} PROPERTIES NO_SONAME 1 )
INSTALL(TARGETS ${LIB_NAME} DESTINATION ${LIB_PLUGIN_DIR})
#==================================================================================================#
SET(LIB_NAME mdsp-VconfPlugin )
ADD_LIBRARY(${LIB_NAME} SHARED ${VCONF_PLUGIN_SRCS})
TARGET_LINK_LIBRARIES(${LIB_NAME} ${plugin_pkgs_LIBRARIES})
-SET_TARGET_PROPERTIES(${LIB_NAME} PROPERTIES VERSION ${FULLVER} SOVERSION ${MAJORVER})
+SET_TARGET_PROPERTIES(${LIB_NAME} PROPERTIES NO_SONAME 1 )
INSTALL(TARGETS ${LIB_NAME} DESTINATION ${LIB_PLUGIN_DIR})
#==================================================================================================#
VconfPlugin();
~VconfPlugin();
- int set(std::string key, std::string data);
int set(std::string key, int data);
+ int set(std::string key, double data);
int set(std::string key, bool data);
+ int set(std::string key, std::string data);
- std::string getString(std::string key);
int getInt(std::string key);
+ double getDouble(std::string key);
bool getBool(std::string key);
+ std::string getString(std::string key);
};
extern "C" API PluginAbstract *objectCreate(void)
{
}
-int VconfPlugin::set(std::string key, std::string data)
+int VconfPlugin::set(std::string key, int data)
{
- DBG("VconfPlugin::set string ( %s, %s )", key.c_str(), data.c_str());
+ DBG("VconfPlugin::set int ( %s, %d )", key.c_str(), data);
int ret;
std::replace(key.begin(), key.end(), '.', '/');
- ret = vconf_set_str(key.c_str(), data.c_str());
+ ret = vconf_set_int(key.c_str(), data);
if (0 != ret) {
- ERR("vconf_set_str(%s, %s) Failed(%d)", key.c_str(), data.c_str(), ret);
+ ERR("vconf_set_int(%s, %d) Failed(%d)", key.c_str(), data, ret);
return MODES_ERROR_SYSTEM;
}
-
return MODES_ERROR_NONE;
}
-int VconfPlugin::set(std::string key, int data)
+int VconfPlugin::set(std::string key, double data)
{
- DBG("VconfPlugin::set int ( %s, %d )", key.c_str(), data);
+ DBG("VconfPlugin::set int ( %s, %lf )", key.c_str(), data);
int ret;
std::replace(key.begin(), key.end(), '.', '/');
- ret = vconf_set_int(key.c_str(), data);
+ ret = vconf_set_dbl(key.c_str(), data);
if (0 != ret) {
- ERR("vconf_set_int(%s, %d) Failed(%d)", key.c_str(), data, ret);
+ ERR("vconf_set_int(%s, %lf) Failed(%d)", key.c_str(), data, ret);
return MODES_ERROR_SYSTEM;
}
return MODES_ERROR_NONE;
}
-
int VconfPlugin::set(std::string key, bool data)
{
DBG("VconfPlugin::set bool ( %s, %d )", key.c_str(), data);
return MODES_ERROR_NONE;
}
-std::string VconfPlugin::getString(std::string key)
+int VconfPlugin::set(std::string key, std::string data)
{
- DBG("VconfPlugin::getString( string )\n");
- char* value = NULL;
- std::string retStr;
-
+ DBG("VconfPlugin::set string ( %s, %s )", key.c_str(), data.c_str());
+ int ret;
std::replace(key.begin(), key.end(), '.', '/');
- value = vconf_get_str(key.c_str());
- if (NULL == value) {
- ERR("vconf_get_str(%s) Failed()", key.c_str());
- return retStr;
+ ret = vconf_set_str(key.c_str(), data.c_str());
+ if (0 != ret) {
+ ERR("vconf_set_str(%s, %s) Failed(%d)", key.c_str(), data.c_str(), ret);
+ return MODES_ERROR_SYSTEM;
}
- retStr = value;
- if (value) free(value);
- return retStr;
+
+ return MODES_ERROR_NONE;
}
int VconfPlugin::getInt(std::string key)
return value;
}
+double VconfPlugin::getDouble(std::string key)
+{
+ DBG("VconfPlugin::getInt( string )\n");
+ double value = 0;
+ int ret;
+
+ std::replace(key.begin(), key.end(), '.', '/');
+ ret = vconf_get_dbl(key.c_str(), &value);
+ if (0 != ret) {
+ ERR("vconf_get_int(%s) Failed(%d)", key.c_str(), ret);
+ return MODES_ERROR_SYSTEM;
+ }
+ return value;
+}
+
bool VconfPlugin::getBool(std::string key)
{
DBG("VconfPlugin::getBool( string )\n");
ERR("vconf_get_bool(%s) Failed(%d)", key.c_str(), ret);
return MODES_ERROR_SYSTEM;
}
- return (value == 1)? true: false;
+ return (value == 1) ? true : false;
+}
+
+std::string VconfPlugin::getString(std::string key)
+{
+ DBG("VconfPlugin::getString( string )\n");
+ char *value = NULL;
+ std::string retStr;
+
+ std::replace(key.begin(), key.end(), '.', '/');
+ value = vconf_get_str(key.c_str());
+ if (NULL == value) {
+ ERR("vconf_get_str(%s) Failed()", key.c_str());
+ return retStr;
+ }
+ retStr = value;
+ if (value)
+ free(value);
+ return retStr;
}
--- /dev/null
+/*
+ * 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.
+ */
+
+#include "modes_errors.h"
+#include "common/log.h"
+#include "WifiAction.h"
+
+MODES_NAMESPACE_USE;
+
+WifiAction::WifiAction()
+{
+ int ret = wifi_manager_initialize(&wifiManagerHandle);
+ if (ret != WIFI_MANAGER_ERROR_NONE) {
+ ERR("wifi_manager_initialize error [%s]", wifiErrorMessage.get(ret).c_str());
+ wifiManagerHandle = NULL;
+ }
+}
+
+WifiAction::~WifiAction()
+{
+ if (wifiManagerHandle != NULL) {
+ wifi_manager_deinitialize(wifiManagerHandle);
+ }
+}
+
+bool WifiAction::isWifiManagerEnable()
+{
+ return (wifiManagerHandle != NULL);
+}
+
+bool WifiAction::isWifiActivate()
+{
+ RETVM_IF(!isWifiManagerEnable(), false, "wifiManagerHandle is null!");
+
+ bool wifiManagerActivated = false;
+ wifi_manager_is_activated(wifiManagerHandle, &wifiManagerActivated);
+ return wifiManagerActivated;
+}
+
+void WifiAction::printErr(int err)
+{
+ ERR("result:%s [%d]", wifiErrorMessage.get(err).c_str(), err);
+}
+
+void WifiAction::setName(std::string name)
+{
+ this->name = name;
+}
+
+std::string WifiAction::getName()
+{
+ return name;
+}
--- /dev/null
+/*
+ * 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 <wifi-manager.h>
+#include "modes_errors.h"
+#include "WifiErrorMessage.h"
+
+MODES_NAMESPACE_BEGIN
+
+class WifiAction {
+public:
+ WifiAction();
+ virtual ~WifiAction();
+ bool isWifiActivate();
+
+ std::string getName();
+
+ virtual int set(int data)
+ {
+ return MODES_ERROR_NOT_SUPPORTED;
+ }
+ virtual int set(double data)
+ {
+ return MODES_ERROR_NOT_SUPPORTED;
+ }
+ virtual int set(bool data)
+ {
+ return MODES_ERROR_NOT_SUPPORTED;
+ }
+ virtual int set(std::string data)
+ {
+ return MODES_ERROR_NOT_SUPPORTED;
+ }
+
+protected:
+ bool isWifiManagerEnable();
+ void printErr(int err);
+ void setName(std::string name);
+ wifi_manager_h wifiManagerHandle;
+ WifiErrorMessage wifiErrorMessage;
+private:
+ std::string name;
+};
+
+MODES_NAMESPACE_END
+
--- /dev/null
+/*
+ * 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.
+ */
+
+#include <algorithm>
+#include "modes_errors.h"
+#include "common/log.h"
+#include "WifiActionPower.h"
+
+MODES_NAMESPACE_USE;
+
+WifiActionPower::WifiActionPower()
+{
+ setName("power");
+}
+
+WifiActionPower::~WifiActionPower()
+{
+}
+
+
+void WifiActionPower::wifi_activate_cb(wifi_manager_error_e result, void *user_data)
+{
+ if (result == WIFI_MANAGER_ERROR_NONE)
+ return;
+
+ ((WifiActionPower *)user_data)->printErr(result);
+}
+
+void WifiActionPower::wifi_deactivate_cb(wifi_manager_error_e result, void *user_data)
+{
+ if (result == WIFI_MANAGER_ERROR_NONE)
+ return;
+
+ ((WifiActionPower *)user_data)->printErr(result);
+}
+
+int WifiActionPower::set(int data)
+{
+ //DBG("set int [%d]", data);
+ return (data == 0 ? set(false) : set(true));
+}
+
+int WifiActionPower::set(double data)
+{
+ //DBG("set float [%f]", data);
+ return (data == 0 ? set(false) : set(true));
+}
+
+int WifiActionPower::set(bool requestPowerOn)
+{
+ //DBG("set bool [%s]", (requestPowerOn ? "on" : "off") );
+ int ret = MODES_ERROR_NONE;
+ RETVM_IF(!isWifiManagerEnable(), MODES_ERROR_NOT_SUPPORTED, "wifiManagerHandle is null!");
+
+ if (requestPowerOn == isWifiActivate()) {
+ INFO("Already wifi is [%s]", requestPowerOn ? "On" : "Off");
+ return MODES_ERROR_NONE;
+ }
+
+ if (requestPowerOn) {
+ ret = wifi_manager_activate(wifiManagerHandle, wifi_activate_cb, this);
+ if (ret != WIFI_MANAGER_ERROR_NONE) {
+ WifiAction::printErr(ret);
+ return MODES_ERROR_SYSTEM;
+ }
+ } else {
+ ret = wifi_manager_deactivate(wifiManagerHandle, wifi_deactivate_cb, this);
+ if (ret != WIFI_MANAGER_ERROR_NONE) {
+ WifiAction::printErr(ret);
+ return MODES_ERROR_SYSTEM;
+ }
+ }
+
+ INFO("Wifi power [%s]", requestPowerOn ? "On" : "Off");
+ return MODES_ERROR_NONE;
+}
+
+int WifiActionPower::set(std::string data)
+{
+ //DBG("set string [%s]", data.c_str());
+ std::transform(data.begin(), data.end(), data.begin(), ::tolower);
+
+ if (data.compare("on") == 0 || data.compare("true") == 0) {
+ return set(true);
+ } else if (data.compare("off") == 0 || data.compare("false") == 0) {
+ return set(false);
+ }
+
+ return MODES_ERROR_NOT_SUPPORTED;
+}
+
--- /dev/null
+/*
+ * 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 "WifiAction.h"
+
+MODES_NAMESPACE_BEGIN
+
+class WifiActionPower : public WifiAction {
+public:
+ WifiActionPower();
+ virtual ~WifiActionPower();
+
+ int set(int data);
+ int set(double data);
+ int set(bool data);
+ int set(std::string data);
+private:
+ static void wifi_activate_cb(wifi_manager_error_e result, void *user_data);
+ static void wifi_deactivate_cb(wifi_manager_error_e result, void *user_data);
+};
+
+MODES_NAMESPACE_END
--- /dev/null
+/*
+ * 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)
+#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()
+ {
+ }
+
+ 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
--- /dev/null
+#!/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 $@
--- /dev/null
+/*
+ * 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.
+ */
+
+#include "modes_errors.h"
+#include "common/log.h"
+#include "WifiFactory.h"
+#include "WifiActionPower.h"
+
+MODES_NAMESPACE_USE;
+
+WifiFactory::WifiFactory()
+{
+ registerAction("power", WifiActionEnum::POWER);
+}
+
+WifiFactory::~WifiFactory()
+{
+}
+
+WifiAction *WifiFactory::createAction(std::string key)
+{
+ auto search = actionMap.find(key);
+ if (search == actionMap.end()) {
+ return nullptr;
+ }
+
+ switch (search->second) {
+ case WifiActionEnum::POWER:
+ WifiActionPower *wifiActionPower = new WifiActionPower();
+ return wifiActionPower;
+ break;
+ }
+
+ return nullptr;
+}
+
+void WifiFactory::destroyAction(WifiAction *action)
+{
+ RET_IF(action == NULL);
+ delete action;
+}
+
+void WifiFactory::registerAction(std::string key, WifiActionEnum action)
+{
+ DBG("Register Action key[%s]", key.c_str());
+ actionMap[key] = action;
+}
--- /dev/null
+/*
+ * 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 "WifiAction.h"
+
+MODES_NAMESPACE_BEGIN
+
+class WifiFactory {
+public:
+ WifiFactory();
+ virtual ~WifiFactory();
+
+ WifiAction *createAction(std::string key);
+ void destroyAction(WifiAction *action);
+private:
+ enum class WifiActionEnum {
+ POWER
+ };
+ typedef std::map<std::string, WifiActionEnum> WifiActionMap;
+
+ void registerAction(std::string key, WifiActionEnum action);
+ WifiActionMap actionMap;
+};
+
+MODES_NAMESPACE_END
* limitations under the License.
*/
#include <string>
+#include <map>
+#include <utility>
+#include <wifi-manager.h>
#include "modes_errors.h"
#include "common/log.h"
#include "common/PluginAbstract.h"
+#include "WifiErrorMessage.h"
+#include "WifiFactory.h"
MODES_NAMESPACE_USE;
+class WifiOperation;
class WifiPlugin : public PluginAbstract {
-private:
-
public:
WifiPlugin();
~WifiPlugin();
- int set(std::string key, std::string data);
int set(std::string key, int data);
+ int set(std::string key, double data);
int set(std::string key, bool data);
+ int set(std::string key, std::string data);
+
- std::string getString(std::string key);
int getInt(std::string key);
+ double getDouble(std::string key);
bool getBool(std::string key);
+ std::string getString(std::string key);
+private:
+ WifiFactory wifiFactory;
};
extern "C" API PluginAbstract *objectCreate(void)
delete plugin;
}
-
WifiPlugin::WifiPlugin()
{
setName("wifi");
{
}
-int WifiPlugin::set(std::string key, std::string data)
+int WifiPlugin::set(std::string key, int data)
{
- DBG("WifiPlugin::set string ( %s, %s )", key.c_str(), data.c_str());
+ DBG("set [%s, %d]", key.c_str(), data);
+ WifiAction *action = wifiFactory.createAction(key);
+ RETVM_IF(action == nullptr, MODES_ERROR_INVALID_PARAMETER, "key [%s], action is null", key.c_str());
- return MODES_ERROR_NONE;
+ int ret = action->set(data);
+ wifiFactory.destroyAction(action);
+ return ret;
}
-int WifiPlugin::set(std::string key, int data)
+int WifiPlugin::set(std::string key, double data)
{
- DBG("WifiPlugin::set int ( %s, %d )", key.c_str(), data);
+ DBG("set [%s, %f]", key.c_str(), data);
+ WifiAction *action = wifiFactory.createAction(key);
+ RETVM_IF(action == nullptr, MODES_ERROR_INVALID_PARAMETER, "key [%s], action is null", key.c_str());
- return MODES_ERROR_NONE;
+ int ret = action->set(data);
+ wifiFactory.destroyAction(action);
+ return ret;
}
int WifiPlugin::set(std::string key, bool data)
{
- DBG("WifiPlugin::set bool ( %s, %d )", key.c_str(), data);
+ DBG("set [%s, %s]", key.c_str(), (data ? "on" : "off"));
+ WifiAction *action = wifiFactory.createAction(key);
+ RETVM_IF(action == nullptr, MODES_ERROR_INVALID_PARAMETER, "key [%s], action is null", key.c_str());
- return MODES_ERROR_NONE;
+ int ret = action->set(data);
+ wifiFactory.destroyAction(action);
+ return ret;
}
-std::string WifiPlugin::getString(std::string key)
+int WifiPlugin::set(std::string key, std::string data)
{
- DBG("WifiPlugin::getString( string )\n");
+ DBG("set [%s, %s]", key.c_str(), data.c_str());
+ WifiAction *action = wifiFactory.createAction(key);
+ RETVM_IF(action == nullptr, MODES_ERROR_INVALID_PARAMETER, "key [%s], action is null", key.c_str());
- return "Happy";
+ int ret = action->set(data);
+ wifiFactory.destroyAction(action);
+ return ret;
}
int WifiPlugin::getInt(std::string key)
{
DBG("WifiPlugin::getInt( string )\n");
+ return 0;
+}
- return 1004;
+double WifiPlugin::getDouble(std::string key)
+{
+ DBG("WifiPlugin::getInt( string )\n");
+ return 0;
}
bool WifiPlugin::getBool(std::string key)
{
DBG("WifiPlugin::getBool( string )\n");
+ return false;
+}
- return true;
+std::string WifiPlugin::getString(std::string key)
+{
+ DBG("WifiPlugin::getString( string )\n");
+ return "";
}
+
MODES_NAMESPACE_BEGIN
class TestPluginManager {
public:
- PluginMap getPluginMap(PluginManager& p);
+ PluginMap getPluginMap(PluginManager &p);
};
MODES_NAMESPACE_END
-PluginMap TestPluginManager::getPluginMap(PluginManager& p){
+PluginMap TestPluginManager::getPluginMap(PluginManager &p)
+{
return p.pluginMap;
}
-TEST(pluginmanager, readLibraryList) {
+TEST(pluginmanager, readLibraryList)
+{
PluginManager pluginManager;
string path = "../plugin/";
}
}
-TEST(PluginManager, setPluginDir) {
+TEST(PluginManager, setPluginDir)
+{
PluginManager pluginManager;
string path = "../plugin/";
EXPECT_EQ(path, getPath);
}
-TEST(PluginManager, loadClassMap) {
+TEST(PluginManager, loadClassMap)
+{
PluginManager pluginManager;
std::string path = "../plugin";
pluginManager.setPluginDir(path);
EXPECT_EQ(ret, MODES_ERROR_NONE);
}
-TEST(PluginManager, unloadClassMap) {
+TEST(PluginManager, unloadClassMap)
+{
PluginManager pluginManager;
int ret = pluginManager.unloadClassMap();
EXPECT_EQ(ret, MODES_ERROR_NONE);
EXPECT_TRUE(pm.empty());
}
-TEST(PluginManager, getClassList) {
+TEST(PluginManager, getClassList)
+{
PluginManager pluginManager;
std::string path = "../plugin";
pluginManager.setPluginDir(path);
}
}
-TEST(PluginManager, getPlugin) {
+TEST(PluginManager, getPlugin)
+{
+ int ret;
PluginManager pluginManager;
+ PluginAbstract *plugin;
+
+ pluginManager.setPluginDir("/usr/lib/modes/plugin");
+ pluginManager.readLibraryList();
+ pluginManager.loadClassMap();
+
+ std::string path = "../plugin";
+ pluginManager.setPluginDir(path);
+ pluginManager.readLibraryList();
pluginManager.loadClassMap();
list<string> list = pluginManager.getClassList();
+ EXPECT_FALSE(list.empty());
- for (auto it = list.begin(); it != list.end(); ++it) {
- string key1 = "Happy";
- string key2 = "1004";
- string key3 = "true";
- bool b = (key3 == "true");
+ // wifi plugin test
+ plugin = pluginManager.getPlugin("wifi");
+ ASSERT_TRUE(plugin != NULL);
- /* Call plugin get */
- string value = pluginManager.getPlugin(*it)->getString(key1);
- EXPECT_EQ("Happy", value);
+ ret = plugin->set("power", 0);
+ EXPECT_TRUE(((ret == MODES_ERROR_NONE) || (ret == MODES_ERROR_NOT_SUPPORTED)));
- int valueInt = pluginManager.getPlugin(*it)->getInt(key2);
- EXPECT_EQ(stoi(key2), valueInt);
+ ret = plugin->set("power", 1);
+ EXPECT_TRUE(((ret == MODES_ERROR_NONE) || (ret == MODES_ERROR_NOT_SUPPORTED)));
- bool valueBool = pluginManager.getPlugin(*it)->getBool(key3);
- EXPECT_EQ(b, valueBool);
- }
+ ret = plugin->set("power", 0.0);
+ EXPECT_TRUE(((ret == MODES_ERROR_NONE) || (ret == MODES_ERROR_NOT_SUPPORTED)));
+
+ ret = plugin->set("power", 1.0);
+ EXPECT_TRUE(((ret == MODES_ERROR_NONE) || (ret == MODES_ERROR_NOT_SUPPORTED)));
+
+ ret = plugin->set("power", false);
+ EXPECT_TRUE(((ret == MODES_ERROR_NONE) || (ret == MODES_ERROR_NOT_SUPPORTED)));
+
+ ret = plugin->set("power", true);
+ EXPECT_TRUE(((ret == MODES_ERROR_NONE) || (ret == MODES_ERROR_NOT_SUPPORTED)));
+
+ ret = plugin->set("power", std::string("off"));
+ EXPECT_TRUE(((ret == MODES_ERROR_NONE) || (ret == MODES_ERROR_NOT_SUPPORTED)));
+
+ ret = plugin->set("power", std::string("on"));
+ EXPECT_TRUE(((ret == MODES_ERROR_NONE) || (ret == MODES_ERROR_NOT_SUPPORTED)));
+
+ ret = plugin->set("power", std::string("Off"));
+ EXPECT_TRUE(((ret == MODES_ERROR_NONE) || (ret == MODES_ERROR_NOT_SUPPORTED)));
+
+ ret = plugin->set("power", std::string("On"));
+ EXPECT_TRUE(((ret == MODES_ERROR_NONE) || (ret == MODES_ERROR_NOT_SUPPORTED)));
+
+ ret = plugin->set("power", std::string("OFF"));
+ EXPECT_TRUE(((ret == MODES_ERROR_NONE) || (ret == MODES_ERROR_NOT_SUPPORTED)));
+
+ ret = plugin->set("power", std::string("ON"));
+ EXPECT_TRUE(((ret == MODES_ERROR_NONE) || (ret == MODES_ERROR_NOT_SUPPORTED)));
+
+ ret = plugin->set("power", std::string("false"));
+ EXPECT_TRUE(((ret == MODES_ERROR_NONE) || (ret == MODES_ERROR_NOT_SUPPORTED)));
+
+ ret = plugin->set("power", std::string("true"));
+ EXPECT_TRUE(((ret == MODES_ERROR_NONE) || (ret == MODES_ERROR_NOT_SUPPORTED)));
+
+ ret = plugin->set("power", std::string("False"));
+ EXPECT_TRUE(((ret == MODES_ERROR_NONE) || (ret == MODES_ERROR_NOT_SUPPORTED)));
+
+ ret = plugin->set("power", std::string("True"));
+ EXPECT_TRUE(((ret == MODES_ERROR_NONE) || (ret == MODES_ERROR_NOT_SUPPORTED)));
+
+ ret = plugin->set("power", std::string("FALSE"));
+ EXPECT_TRUE(((ret == MODES_ERROR_NONE) || (ret == MODES_ERROR_NOT_SUPPORTED)));
+
+ ret = plugin->set("power", std::string("TRUE"));
+ EXPECT_TRUE(((ret == MODES_ERROR_NONE) || (ret == MODES_ERROR_NOT_SUPPORTED)));
+
+ ret = plugin->set("abcdefg", true);
+ EXPECT_EQ(ret, MODES_ERROR_INVALID_PARAMETER);
+
+#if 0
+ bool boolRet;
+
+ // vconf plugin test
+ plugin = pluginManager.getPlugin("vconf");
+ ASSERT_TRUE(plugin != NULL);
+
+ ret = plugin->set("db/setting/auto_display_adjustment", true);
+ EXPECT_TRUE(((ret == MODES_ERROR_NONE) || (ret == MODES_ERROR_NOT_SUPPORTED)));
+
+ boolRet = plugin->getBool("db/setting/auto_display_adjustment");
+ EXPECT_EQ(boolRet, true);
+
+
+ ret = plugin->set("db/setting/lcd_backlight_normal", 11);
+ EXPECT_TRUE(((ret == MODES_ERROR_NONE) || (ret == MODES_ERROR_NOT_SUPPORTED)));
+
+ ret = plugin->getInt("db/setting/lcd_backlight_normal");
+ EXPECT_EQ(ret, 11);
+#endif
}