separate plugin libraries from modes repo
authorYoungjae Shin <yj99.shin@samsung.com>
Sun, 9 Jun 2019 23:12:32 +0000 (08:12 +0900)
committerYoungjae Shin <yj99.shin@samsung.com>
Thu, 19 Mar 2020 04:30:02 +0000 (13:30 +0900)
21 files changed:
CMakeLists.txt [new file with mode: 0644]
LICENSE.APLv2 [new file with mode: 0644]
NOTICE [new file with mode: 0644]
include/plugin-def.h [new file with mode: 0644]
include/plugin-log.h [new file with mode: 0644]
packaging/modes-plugins.manifest [new file with mode: 0644]
packaging/modes-plugins.spec [new file with mode: 0644]
unittests/CMakeLists.txt [new file with mode: 0644]
unittests/mdsp_wifi_main.cpp [new file with mode: 0644]
vconf/CMakeLists.txt [new file with mode: 0644]
vconf/VconfPlugin.cpp [new file with mode: 0644]
wifi/CMakeLists.txt [new file with mode: 0644]
wifi/WifiAction.cpp [new file with mode: 0644]
wifi/WifiAction.h [new file with mode: 0644]
wifi/WifiActionPower.cpp [new file with mode: 0644]
wifi/WifiActionPower.h [new file with mode: 0644]
wifi/WifiErrorMessage.h [new file with mode: 0644]
wifi/WifiErrorMessageGenerator.sh [new file with mode: 0644]
wifi/WifiFactory.cpp [new file with mode: 0644]
wifi/WifiFactory.h [new file with mode: 0644]
wifi/WifiPlugin.cpp [new file with mode: 0644]

diff --git a/CMakeLists.txt b/CMakeLists.txt
new file mode 100644 (file)
index 0000000..7c5b362
--- /dev/null
@@ -0,0 +1,20 @@
+CMAKE_MINIMUM_REQUIRED(VERSION 3.9)
+PROJECT(modes-plugins)
+
+INCLUDE(FindPkgConfig)
+INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/include)
+
+SET(EXTRA_FLAGS "-Wall -Werror -fvisibility=hidden")
+SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${EXTRA_CFLAGS}")
+SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${EXTRA_FLAGS} -std=c++11")
+
+ADD_DEFINITIONS("-DMDS_PLUGIN")
+
+IF(NOT DEFINED MODES_PLUGIN_DEFAULT_DIR)
+       MESSAGE("No MODES_PLUGIN_DEFAULT_DIR. Check build system")
+       SET(MODES_PLUGIN_DEFAULT_DIR "/usr/lib/modes-plugins/")
+ENDIF(NOT DEFINED MODES_PLUGIN_DEFAULT_DIR)
+
+ADD_SUBDIRECTORY(wifi)
+ADD_SUBDIRECTORY(vconf)
+ADD_SUBDIRECTORY(unittests)
diff --git a/LICENSE.APLv2 b/LICENSE.APLv2
new file mode 100644 (file)
index 0000000..c1f1938
--- /dev/null
@@ -0,0 +1,204 @@
+Copyright (c) 2019 Samsung Electronics Co., Ltd. All rights reserved.
+
+                                 Apache License
+                           Version 2.0, January 2004
+                        http://www.apache.org/licenses/
+
+   TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
+
+   1. Definitions.
+
+      "License" shall mean the terms and conditions for use, reproduction,
+      and distribution as defined by Sections 1 through 9 of this document.
+
+      "Licensor" shall mean the copyright owner or entity authorized by
+      the copyright owner that is granting the License.
+
+      "Legal Entity" shall mean the union of the acting entity and all
+      other entities that control, are controlled by, or are under common
+      control with that entity. For the purposes of this definition,
+      "control" means (i) the power, direct or indirect, to cause the
+      direction or management of such entity, whether by contract or
+      otherwise, or (ii) ownership of fifty percent (50%) or more of the
+      outstanding shares, or (iii) beneficial ownership of such entity.
+
+      "You" (or "Your") shall mean an individual or Legal Entity
+      exercising permissions granted by this License.
+
+      "Source" form shall mean the preferred form for making modifications,
+      including but not limited to software source code, documentation
+      source, and configuration files.
+
+      "Object" form shall mean any form resulting from mechanical
+      transformation or translation of a Source form, including but
+      not limited to compiled object code, generated documentation,
+      and conversions to other media types.
+
+      "Work" shall mean the work of authorship, whether in Source or
+      Object form, made available under the License, as indicated by a
+      copyright notice that is included in or attached to the work
+      (an example is provided in the Appendix below).
+
+      "Derivative Works" shall mean any work, whether in Source or Object
+      form, that is based on (or derived from) the Work and for which the
+      editorial revisions, annotations, elaborations, or other modifications
+      represent, as a whole, an original work of authorship. For the purposes
+      of this License, Derivative Works shall not include works that remain
+      separable from, or merely link (or bind by name) to the interfaces of,
+      the Work and Derivative Works thereof.
+
+      "Contribution" shall mean any work of authorship, including
+      the original version of the Work and any modifications or additions
+      to that Work or Derivative Works thereof, that is intentionally
+      submitted to Licensor for inclusion in the Work by the copyright owner
+      or by an individual or Legal Entity authorized to submit on behalf of
+      the copyright owner. For the purposes of this definition, "submitted"
+      means any form of electronic, verbal, or written communication sent
+      to the Licensor or its representatives, including but not limited to
+      communication on electronic mailing lists, source code control systems,
+      and issue tracking systems that are managed by, or on behalf of, the
+      Licensor for the purpose of discussing and improving the Work, but
+      excluding communication that is conspicuously marked or otherwise
+      designated in writing by the copyright owner as "Not a Contribution."
+
+      "Contributor" shall mean Licensor and any individual or Legal Entity
+      on behalf of whom a Contribution has been received by Licensor and
+      subsequently incorporated within the Work.
+
+   2. Grant of Copyright License. Subject to the terms and conditions of
+      this License, each Contributor hereby grants to You a perpetual,
+      worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+      copyright license to reproduce, prepare Derivative Works of,
+      publicly display, publicly perform, sublicense, and distribute the
+      Work and such Derivative Works in Source or Object form.
+
+   3. Grant of Patent License. Subject to the terms and conditions of
+      this License, each Contributor hereby grants to You a perpetual,
+      worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+      (except as stated in this section) patent license to make, have made,
+      use, offer to sell, sell, import, and otherwise transfer the Work,
+      where such license applies only to those patent claims licensable
+      by such Contributor that are necessarily infringed by their
+      Contribution(s) alone or by combination of their Contribution(s)
+      with the Work to which such Contribution(s) was submitted. If You
+      institute patent litigation against any entity (including a
+      cross-claim or counterclaim in a lawsuit) alleging that the Work
+      or a Contribution incorporated within the Work constitutes direct
+      or contributory patent infringement, then any patent licenses
+      granted to You under this License for that Work shall terminate
+      as of the date such litigation is filed.
+
+   4. Redistribution. You may reproduce and distribute copies of the
+      Work or Derivative Works thereof in any medium, with or without
+      modifications, and in Source or Object form, provided that You
+      meet the following conditions:
+
+      (a) You must give any other recipients of the Work or
+          Derivative Works a copy of this License; and
+
+      (b) You must cause any modified files to carry prominent notices
+          stating that You changed the files; and
+
+      (c) You must retain, in the Source form of any Derivative Works
+          that You distribute, all copyright, patent, trademark, and
+          attribution notices from the Source form of the Work,
+          excluding those notices that do not pertain to any part of
+          the Derivative Works; and
+
+      (d) If the Work includes a "NOTICE" text file as part of its
+          distribution, then any Derivative Works that You distribute must
+          include a readable copy of the attribution notices contained
+          within such NOTICE file, excluding those notices that do not
+          pertain to any part of the Derivative Works, in at least one
+          of the following places: within a NOTICE text file distributed
+          as part of the Derivative Works; within the Source form or
+          documentation, if provided along with the Derivative Works; or,
+          within a display generated by the Derivative Works, if and
+          wherever such third-party notices normally appear. The contents
+          of the NOTICE file are for informational purposes only and
+          do not modify the License. You may add Your own attribution
+          notices within Derivative Works that You distribute, alongside
+          or as an addendum to the NOTICE text from the Work, provided
+          that such additional attribution notices cannot be construed
+          as modifying the License.
+
+      You may add Your own copyright statement to Your modifications and
+      may provide additional or different license terms and conditions
+      for use, reproduction, or distribution of Your modifications, or
+      for any such Derivative Works as a whole, provided Your use,
+      reproduction, and distribution of the Work otherwise complies with
+      the conditions stated in this License.
+
+   5. Submission of Contributions. Unless You explicitly state otherwise,
+      any Contribution intentionally submitted for inclusion in the Work
+      by You to the Licensor shall be under the terms and conditions of
+      this License, without any additional terms or conditions.
+      Notwithstanding the above, nothing herein shall supersede or modify
+      the terms of any separate license agreement you may have executed
+      with Licensor regarding such Contributions.
+
+   6. Trademarks. This License does not grant permission to use the trade
+      names, trademarks, service marks, or product names of the Licensor,
+      except as required for reasonable and customary use in describing the
+      origin of the Work and reproducing the content of the NOTICE file.
+
+   7. Disclaimer of Warranty. Unless required by applicable law or
+      agreed to in writing, Licensor provides the Work (and each
+      Contributor provides its Contributions) on an "AS IS" BASIS,
+      WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+      implied, including, without limitation, any warranties or conditions
+      of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
+      PARTICULAR PURPOSE. You are solely responsible for determining the
+      appropriateness of using or redistributing the Work and assume any
+      risks associated with Your exercise of permissions under this License.
+
+   8. Limitation of Liability. In no event and under no legal theory,
+      whether in tort (including negligence), contract, or otherwise,
+      unless required by applicable law (such as deliberate and grossly
+      negligent acts) or agreed to in writing, shall any Contributor be
+      liable to You for damages, including any direct, indirect, special,
+      incidental, or consequential damages of any character arising as a
+      result of this License or out of the use or inability to use the
+      Work (including but not limited to damages for loss of goodwill,
+      work stoppage, computer failure or malfunction, or any and all
+      other commercial damages or losses), even if such Contributor
+      has been advised of the possibility of such damages.
+
+   9. Accepting Warranty or Additional Liability. While redistributing
+      the Work or Derivative Works thereof, You may choose to offer,
+      and charge a fee for, acceptance of support, warranty, indemnity,
+      or other liability obligations and/or rights consistent with this
+      License. However, in accepting such obligations, You may act only
+      on Your own behalf and on Your sole responsibility, not on behalf
+      of any other Contributor, and only if You agree to indemnify,
+      defend, and hold each Contributor harmless for any liability
+      incurred by, or claims asserted against, such Contributor by reason
+      of your accepting any such warranty or additional liability.
+
+   END OF TERMS AND CONDITIONS
+
+   APPENDIX: How to apply the Apache License to your work.
+
+      To apply the Apache License to your work, attach the following
+      boilerplate notice, with the fields enclosed by brackets "[]"
+      replaced with your own identifying information. (Don't include
+      the brackets!)  The text should be enclosed in the appropriate
+      comment syntax for the file format. We also recommend that a
+      file or class name and description of purpose be included on the
+      same "printed page" as the copyright notice for easier
+      identification within third-party archives.
+
+   Copyright [yyyy] [name of copyright owner]
+
+   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.
+
diff --git a/NOTICE b/NOTICE
new file mode 100644 (file)
index 0000000..2564dc4
--- /dev/null
+++ b/NOTICE
@@ -0,0 +1,3 @@
+Copyright (c) 2019 Samsung Electronics Co., Ltd. All rights reserved.
+Except as noted, this software is licensed under Apache License, Version 2.
+Please, see the LICENSE.APLv2 file for Apache license, version 2 terms and conditions.
diff --git a/include/plugin-def.h b/include/plugin-def.h
new file mode 100644 (file)
index 0000000..680c2b7
--- /dev/null
@@ -0,0 +1,29 @@
+/*
+ * 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 <modes_constants.h>
+
+#ifdef API
+#undef API
+#endif
+#define API __attribute__((visibility("default")))
+
+#define MDS_EQUAL 0
+
+#define MODES_NAMESPACE_BEGIN namespace ModeSupervisorNamespace {
+#define MODES_NAMESPACE_END }
+#define MODES_NAMESPACE_USE using namespace ModeSupervisorNamespace
diff --git a/include/plugin-log.h b/include/plugin-log.h
new file mode 100644 (file)
index 0000000..bb505b3
--- /dev/null
@@ -0,0 +1,146 @@
+/*
+ * 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
+
+#define MDS_LOG_RED "\033[31m"
+#define MDS_LOG_GREEN "\033[32m"
+#define MDS_LOG_BROWN "\033[33m"
+#define MDS_LOG_BLUE "\033[34m"
+#define MDS_LOG_END "\033[0m"
+
+#undef __DBG
+#undef __INFO
+#undef __WARN
+#undef __ERR
+
+#undef _DBG
+#undef _INFO
+#undef _WARN
+#undef _ERR
+
+#undef DBG
+#undef INFO
+#undef WARN
+#undef ERR
+
+#ifdef MDS_STDOUT
+#include <stdio.h>
+#include <string.h>
+#define __FILENAME__ (strrchr(__FILE__, '/') ? strrchr(__FILE__, '/') + 1 : __FILE__)
+#define __DBG(fmt, arg...) printf("[Modes]%s(%d):" fmt "\n", __FILENAME__, __LINE__, ##arg)
+#define __INFO(fmt, arg...) printf("[Modes]%s(%d):" fmt "\n", __FILENAME__, __LINE__, ##arg)
+#define __WARN(fmt, arg...) printf("[Modes]%s(%d):" fmt "\n", __FILENAME__, __LINE__, ##arg)
+#define __ERR(fmt, arg...) printf("[Modes]%s(%d):" fmt "\n", __FILENAME__, __LINE__, ##arg)
+#else
+#define LOG_TAG "MODES"
+#include <dlog.h>
+#define __DBG(fmt, arg...) SLOGD(fmt, ##arg)
+#define __INFO(fmt, arg...) SLOGI(fmt, ##arg)
+#define __WARN(fmt, arg...) SLOGW(fmt, ##arg)
+#define __ERR(fmt, arg...) SLOGE(fmt, ##arg)
+#endif /* MDS_STDOUT */
+
+
+#ifdef MDS_PLUGIN
+#define _DBG(fmt, arg...) __DBG(MDS_LOG_BROWN "<Plugin>" MDS_LOG_END fmt, ##arg)
+#define _INFO(fmt, arg...) __INFO(MDS_LOG_BLUE "<Plugin>" MDS_LOG_END fmt, ##arg)
+#define _WARN(fmt, arg...) __WARN(MDS_LOG_GREEN "<Plugin>" MDS_LOG_END fmt, ##arg)
+#define _ERR(fmt, arg...) __ERR(MDS_LOG_RED "<Plugin>" MDS_LOG_END fmt, ##arg)
+#elif defined(MDS_TEST)
+#define _DBG(fmt, arg...) __DBG(MDS_LOG_BROWN "<Plugin-Test>" MDS_LOG_END fmt, ##arg)
+#define _INFO(fmt, arg...) __INFO(MDS_LOG_BLUE "<Plugin-Test>" MDS_LOG_END fmt, ##arg)
+#define _WARN(fmt, arg...) __WARN(MDS_LOG_GREEN "<Plugin-Test>" MDS_LOG_END fmt, ##arg)
+#define _ERR(fmt, arg...) __ERR(MDS_LOG_RED "<Plugin-Test>" MDS_LOG_END fmt, ##arg)
+#else
+#define _DBG(fmt, arg...) __DBG(fmt, ##arg)
+#define _INFO(fmt, arg...) __INFO(fmt, ##arg)
+#define _WARN(fmt, arg...) __WARN(fmt, ##arg)
+#define _ERR(fmt, arg...) __ERR(fmt, ##arg)
+#endif /* MDS_PLUGIN */
+
+#define MDS_DEBUGGING
+
+#ifdef MDS_DEBUGGING
+#define API_CALL _DBG(">>>>>>>> API called")
+#define API_END _DBG(">>>>>>>> API ended")
+#define FN_CALL _DBG(">>>>>>>> called")
+#define FN_END _DBG("<<<<<<<< ended")
+#define DBG(fmt, arg...) _DBG(fmt, ##arg)
+#define WARN(fmt, arg...) _WARN(fmt, ##arg)
+#define ERR(fmt, arg...) _ERR(fmt, ##arg)
+#define INFO(fmt, arg...) _INFO(fmt, ##arg)
+#define SECURE_DBG(fmt, arg...) SECURE_SLOGI(fmt, ##arg)
+#define SECURE_ERR(fmt, arg...) SECURE_SLOGE(fmt, ##arg)
+
+#else /* MDS_DEBUGGING */
+#define API_CALL
+#define API_END
+#define FN_CALL
+#define FN_END
+#define DBG(fmt, arg...)
+#define WARN(fmt, arg...)
+#define ERR(fmt, arg...)
+#define INFO(fmt, arg...)
+#define SECURE_DBG(fmt, arg...)
+#define SECURE_ERR(fmt, arg...)
+
+#endif /* MDS_DEBUGGING */
+
+#define RET_IF(expr) \
+       do { \
+               if (expr) { \
+                       ERR("(%s)", #expr); \
+                       return; \
+               } \
+       } while (0)
+
+#define RETV_IF(expr, val) \
+       do { \
+               if (expr) { \
+                       ERR("(%s)", #expr); \
+                       return (val); \
+               } \
+       } while (0)
+
+#define RETM_IF(expr, fmt, arg...) \
+       do { \
+               if (expr) { \
+                       ERR(fmt, ##arg); \
+                       return; \
+               } \
+       } while (0)
+
+#define RETVM_IF(expr, val, fmt, arg...) \
+       do { \
+               if (expr) { \
+                       ERR(fmt, ##arg); \
+                       return (val); \
+               } \
+       } while (0)
+
+#define ERR_IF(expr) \
+       do { \
+               if (expr) { \
+                       ERR("(%s)", #expr); \
+               } \
+       } while (0)
+
+#define WARN_IF(expr, fmt, arg...) \
+       do { \
+               if (expr) { \
+                       WARN(fmt, ##arg); \
+               } \
+       } while (0)
diff --git a/packaging/modes-plugins.manifest b/packaging/modes-plugins.manifest
new file mode 100644 (file)
index 0000000..a76fdba
--- /dev/null
@@ -0,0 +1,5 @@
+<manifest>
+       <request>
+               <domain name="_" />
+       </request>
+</manifest>
diff --git a/packaging/modes-plugins.spec b/packaging/modes-plugins.spec
new file mode 100644 (file)
index 0000000..e82fbd2
--- /dev/null
@@ -0,0 +1,73 @@
+Name: modes-plugins
+Version: 0.0.1
+Release: 0
+Summary: Plugin Libraries for Mode Supervisor
+
+Group: System/Management
+License: Apache-2.0
+URL : https://review.tizen.org/gerrit
+Source0: %{name}-%{version}.tar.gz
+Source1001: %{name}.manifest
+
+BuildRequires: cmake
+BuildRequires: pkgconfig(modes)
+BuildRequires: modes-plugin-devel
+BuildRequires: pkgconfig(dlog)
+BuildRequires: pkgconfig(capi-base-common)
+BuildRequires: pkgconfig(capi-network-wifi-manager)
+BuildRequires: pkgconfig(vconf)
+BuildRequires: pkgconfig(gmock)
+
+%description
+Plugin Libraries for Mode Supervisor
+
+%package unittests
+Summary: Test Programs for %{name}
+Group: System/Testing
+
+%description unittests
+The %{name}-unittests pacakge contains programs for checking quality the %{name}.
+
+%define modes_plugin_dir %{_libdir}/modes-plugins
+%define modes_test_dir %{_bindir}/%{name}
+
+%prep
+%setup -q
+chmod g-w %_sourcedir/*
+cp %{SOURCE1001} ./%{name}.manifest
+
+%build
+%if 0%{?gcov:1}
+export CFLAGS+=" -fprofile-arcs -ftest-coverage"
+export CXXFLAGS+=" -fprofile-arcs -ftest-coverage"
+export FFLAGS+=" -fprofile-arcs -ftest-coverage"
+export LDFLAGS+=" -lgcov"
+%endif
+
+MAJORVER=`echo %{version} | awk 'BEGIN {FS="."}{print $1}'`
+%cmake . -DMAJORVER=${MAJORVER} -DFULLVER=%{version} \
+       -DCMAKE_VERBOSE_MAKEFILE=OFF \
+       -DTEST_INSTALL_DIR:PATH=%{modes_test_dir} \
+       -DMODES_PLUGIN_DEFAULT_DIR:PATH=%{modes_plugin_dir} \
+       -DBUILD_GCOV=%{?gcov:1}%{!?gcov:0} \
+       -DSTDOUT_LOG=%{?stdlog:1}%{!?stdlog:0}
+make %{?_smp_mflags}
+
+%install
+%make_install
+
+%check
+#TBD
+
+%post -p /sbin/ldconfig
+%postun -p /sbin/ldconfig
+
+%files
+%manifest %{name}.manifest
+%{modes_plugin_dir}/*.so
+%license LICENSE.APLv2
+
+%files unittests
+%manifest %{name}.manifest
+%{modes_test_dir}/*
+%license LICENSE.APLv2
diff --git a/unittests/CMakeLists.txt b/unittests/CMakeLists.txt
new file mode 100644 (file)
index 0000000..0721892
--- /dev/null
@@ -0,0 +1,16 @@
+SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fPIE")
+SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fPIE")
+ADD_DEFINITIONS("-DMDS_TEST")
+
+pkg_check_modules(test_pkgs REQUIRED modes dlog capi-network-wifi-manager gmock)
+INCLUDE_DIRECTORIES(${test_pkgs_INCLUDE_DIRS})
+LINK_DIRECTORIES(${test_pkgs_LIBRARY_DIRS})
+
+SET(WIFI_SRC_DIR "${CMAKE_SOURCE_DIR}/wifi" )
+
+SET(WIFI_PLUGIN_TEST "modes-gtest-modemgr")
+SET(SRCS ${WIFI_SRC_DIR}/WifiAction.cpp "mdsp_wifi_main.cpp")
+
+ADD_EXECUTABLE(${WIFI_PLUGIN_TEST} ${SRCS})
+TARGET_LINK_LIBRARIES(${WIFI_PLUGIN_TEST} ${test_pkgs_LIBRARIES} dl)
+INSTALL(TARGETS ${WIFI_PLUGIN_TEST} DESTINATION ${TEST_INSTALL_DIR})
diff --git a/unittests/mdsp_wifi_main.cpp b/unittests/mdsp_wifi_main.cpp
new file mode 100644 (file)
index 0000000..e083c6b
--- /dev/null
@@ -0,0 +1,21 @@
+/*
+ * 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 <gtest/gtest.h>
+
+int main(int argc, char **argv) {
+       testing::InitGoogleTest(&argc, argv);
+       return RUN_ALL_TESTS();
+}
diff --git a/vconf/CMakeLists.txt b/vconf/CMakeLists.txt
new file mode 100644 (file)
index 0000000..63e2411
--- /dev/null
@@ -0,0 +1,20 @@
+SET(VCONF_PLUGIN "modes-plugin-vconf")
+
+FILE(GLOB VCONF_SRCS *.cpp)
+
+pkg_check_modules(vconf_pkgs REQUIRED modes dlog capi-base-common vconf)
+INCLUDE_DIRECTORIES(${vconf_pkgs_INCLUDE_DIRS})
+LINK_DIRECTORIES(${vconf_pkgs_LIBRARY_DIRS})
+
+# ==== WifiErrorMessage Header genertor ====
+#ADD_CUSTOM_TARGET(
+#    genWifiErrorMessage
+#    COMMAND echo "Run WifiErrorMessage Generator"
+#    COMMAND tool/WifiErrorMessageGenerator.sh
+#)
+#ADD_DEPENDENCIES(${VCONF_PLUGIN} genWifiErrorMessage)
+
+ADD_LIBRARY(${VCONF_PLUGIN} SHARED ${VCONF_SRCS})
+TARGET_LINK_LIBRARIES(${VCONF_PLUGIN} ${vconf_pkgs_LIBRARIES})
+SET_TARGET_PROPERTIES(${VCONF_PLUGIN} PROPERTIES NO_SONAME 1 )
+INSTALL(TARGETS ${VCONF_PLUGIN} DESTINATION ${MODES_PLUGIN_DEFAULT_DIR})
diff --git a/vconf/VconfPlugin.cpp b/vconf/VconfPlugin.cpp
new file mode 100644 (file)
index 0000000..86aa9d6
--- /dev/null
@@ -0,0 +1,184 @@
+/*
+ * 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 <vconf.h>
+#include <modes_errors.h>
+#include <string>
+#include <algorithm>
+#include <Plugin.h>
+#include "plugin-log.h"
+#include "plugin-def.h"
+
+
+MODES_NAMESPACE_USE;
+
+class VconfPlugin : public Plugin {
+private:
+
+public:
+       VconfPlugin();
+
+       int set(const std::string &key, int val) override;
+       int set(const std::string &key, double val) override;
+       int set(const std::string &key, bool val) override;
+       int set(const std::string &key, const std::string &val) override;
+
+       int getInt(const std::string &key) override;
+       double getDouble(const std::string &key) override;
+       bool getBool(const std::string &key) override;
+       std::string getString(const std::string &key) override;
+};
+
+extern "C" API Plugin *objectCreate(void)
+{
+       return new VconfPlugin;
+}
+
+extern "C" API void objectDelete(Plugin *plugin)
+{
+       delete plugin;
+}
+
+VconfPlugin::VconfPlugin()
+{
+       setName("vconf");
+}
+
+int VconfPlugin::set(const std::string &key, int val)
+{
+       DBG("set<int>(%s, %d)", key.c_str(), val);
+
+       std::string newKey(key);
+       std::replace(newKey.begin(), newKey.end(), '.', '/');
+
+       int ret = vconf_set_int(newKey.c_str(), val);
+       if (0 != ret) {
+               ERR("vconf_set_int(%s, %d) Fail(%d)", newKey.c_str(), val, ret);
+               return MODES_ERROR_SYSTEM;
+       }
+       return MODES_ERROR_NONE;
+}
+
+int VconfPlugin::set(const std::string &key, double val)
+{
+       DBG("set<double>(%s, %lf)", key.c_str(), val);
+
+       std::string newKey(key);
+       std::replace(newKey.begin(), newKey.end(), '.', '/');
+
+       int ret = vconf_set_dbl(newKey.c_str(), val);
+       if (0 != ret) {
+               ERR("vconf_set_int(%s, %lf) Fail(%d)", newKey.c_str(), val, ret);
+               return MODES_ERROR_SYSTEM;
+       }
+       return MODES_ERROR_NONE;
+}
+int VconfPlugin::set(const std::string &key, bool val)
+{
+       DBG("set<bool>(%s, %d)", key.c_str(), val);
+
+       std::string newKey(key);
+       std::replace(newKey.begin(), newKey.end(), '.', '/');
+
+       int ret = vconf_set_bool(newKey.c_str(), val);
+       if (0 != ret) {
+               ERR("vconf_set_bool(%s, %d) Fail(%d)", newKey.c_str(), val, ret);
+               return MODES_ERROR_SYSTEM;
+       }
+       return MODES_ERROR_NONE;
+}
+
+int VconfPlugin::set(const std::string &key, const std::string &val)
+{
+       DBG("set<string>(%s, %s)", key.c_str(), val.c_str());
+
+       std::string newKey(key);
+       std::replace(newKey.begin(), newKey.end(), '.', '/');
+
+       int ret = vconf_set_str(newKey.c_str(), val.c_str());
+       if (0 != ret) {
+               ERR("vconf_set_str(%s, %s) Fail(%d)", newKey.c_str(), val.c_str(), ret);
+               return MODES_ERROR_SYSTEM;
+       }
+
+       return MODES_ERROR_NONE;
+}
+
+int VconfPlugin::getInt(const std::string &key)
+{
+       DBG("getInt(%s)", key.c_str());
+
+       std::string newKey(key);
+       std::replace(newKey.begin(), newKey.end(), '.', '/');
+
+       int value = 0;
+       int ret = vconf_get_int(newKey.c_str(), &value);
+       if (0 != ret) {
+               ERR("vconf_get_int(%s) Fail(%d)", newKey.c_str(), ret);
+               return MODES_ERROR_SYSTEM;
+       }
+       return value;
+}
+
+double VconfPlugin::getDouble(const std::string &key)
+{
+       DBG("getDouble(%s)", key.c_str());
+
+       std::string newKey(key);
+       std::replace(newKey.begin(), newKey.end(), '.', '/');
+
+       double value = 0.0;
+       int ret = vconf_get_dbl(newKey.c_str(), &value);
+       if (0 != ret) {
+               ERR("vconf_get_int(%s) Fail(%d)", newKey.c_str(), ret);
+               return MODES_ERROR_SYSTEM;
+       }
+       return value;
+}
+
+bool VconfPlugin::getBool(const std::string &key)
+{
+       DBG("getBool(%s)", key.c_str());
+
+       std::string newKey(key);
+       std::replace(newKey.begin(), newKey.end(), '.', '/');
+
+       int value = 0;
+       int ret = vconf_get_bool(newKey.c_str(), &value);
+       if (0 != ret) {
+               ERR("vconf_get_bool(%s) Fail(%d)", newKey.c_str(), ret);
+               return MODES_ERROR_SYSTEM;
+       }
+       return (value) ? true : false;
+}
+
+std::string VconfPlugin::getString(const std::string &key)
+{
+       DBG("getString(%s)", key.c_str());
+
+       std::string newKey(key);
+       std::replace(newKey.begin(), newKey.end(), '.', '/');
+
+       char *value = NULL;
+       value = vconf_get_str(newKey.c_str());
+       if (NULL == value) {
+               ERR("vconf_get_str(%s) Fail()", newKey.c_str());
+               return std::string();
+       }
+       std::string retStr = value;
+       free(value);
+
+       return retStr;
+}
diff --git a/wifi/CMakeLists.txt b/wifi/CMakeLists.txt
new file mode 100644 (file)
index 0000000..573375e
--- /dev/null
@@ -0,0 +1,20 @@
+SET(WIFI_PLUGIN "modes-plugin-wifi")
+
+FILE(GLOB WIFI_SRCS *.cpp)
+
+pkg_check_modules(wifi_pkgs REQUIRED modes dlog capi-base-common capi-network-wifi-manager)
+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 )
+INSTALL(TARGETS ${WIFI_PLUGIN} DESTINATION ${MODES_PLUGIN_DEFAULT_DIR})
diff --git a/wifi/WifiAction.cpp b/wifi/WifiAction.cpp
new file mode 100644 (file)
index 0000000..2a4d311
--- /dev/null
@@ -0,0 +1,89 @@
+/*
+ * 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 "WifiAction.h"
+
+#include <modes_errors.h>
+#include "plugin-log.h"
+#include "plugin-def.h"
+
+MODES_NAMESPACE_USE;
+
+WifiAction::WifiAction()
+{
+       int ret = wifi_manager_initialize(&wifiManagerHandle);
+       if (ret != WIFI_MANAGER_ERROR_NONE) {
+               ERR("wifi_manager_initialize() Fail(%s)", wifiErrorMessage.get(ret).c_str());
+               wifiManagerHandle = NULL;
+       }
+}
+
+WifiAction::~WifiAction()
+{
+       if (wifiManagerHandle) {
+               wifi_manager_deinitialize(wifiManagerHandle);
+       }
+}
+
+bool WifiAction::isWifiManagerEnable()
+{
+       return (wifiManagerHandle != NULL);
+}
+
+int WifiAction::set(int val)
+{
+       return MODES_ERROR_NOT_SUPPORTED;
+}
+
+int WifiAction::set(double val)
+{
+       return MODES_ERROR_NOT_SUPPORTED;
+}
+
+int WifiAction::set(bool val)
+{
+       return MODES_ERROR_NOT_SUPPORTED;
+}
+
+int WifiAction::set(const std::string &val)
+{
+       return MODES_ERROR_NOT_SUPPORTED;
+}
+
+bool WifiAction::isWifiActivate()
+{
+       RETV_IF(!isWifiManagerEnable(), false);
+
+       bool isActivated = false;
+
+       wifi_manager_is_activated(wifiManagerHandle, &isActivated);
+
+       return isActivated;
+}
+
+const std::string& WifiAction::strErr(int err)
+{
+       return wifiErrorMessage.get(err);
+}
+
+void WifiAction::setName(std::string name)
+{
+       this->name = name;
+}
+
+std::string WifiAction::getName()
+{
+       return name;
+}
diff --git a/wifi/WifiAction.h b/wifi/WifiAction.h
new file mode 100644 (file)
index 0000000..52d3691
--- /dev/null
@@ -0,0 +1,47 @@
+/*
+ * 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 "WifiErrorMessage.h"
+
+MODES_NAMESPACE_BEGIN
+
+class WifiAction {
+public:
+       WifiAction();
+       virtual ~WifiAction();
+
+       bool isWifiActivate();
+       std::string getName();
+       virtual int set(int val);
+       virtual int set(double val);
+       virtual int set(bool val);
+       virtual int set(const std::string &val);
+
+protected:
+       bool isWifiManagerEnable();
+       const std::string& strErr(int err);
+       void setName(std::string name);
+       wifi_manager_h wifiManagerHandle;
+       WifiErrorMessage wifiErrorMessage;
+private:
+       std::string name;
+};
+
+MODES_NAMESPACE_END
+
diff --git a/wifi/WifiActionPower.cpp b/wifi/WifiActionPower.cpp
new file mode 100644 (file)
index 0000000..25ae6c0
--- /dev/null
@@ -0,0 +1,70 @@
+/*
+ * 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 "WifiActionPower.h"
+
+#include <algorithm>
+#include <modes_errors.h>
+#include "plugin-log.h"
+
+MODES_NAMESPACE_USE;
+
+WifiActionPower::WifiActionPower()
+{
+       setName("power");
+}
+
+void WifiActionPower::activate_cb(wifi_manager_error_e result, void *user_data)
+{
+       if (WIFI_MANAGER_ERROR_NONE != result) {
+               const std::string &errStr = ((WifiActionPower*)user_data)->strErr(result);
+               ERR("activate_cb() Fail(%d, %s)", result, errStr.c_str());
+       }
+}
+
+void WifiActionPower::deactivate_cb(wifi_manager_error_e result, void *user_data)
+{
+       if (WIFI_MANAGER_ERROR_NONE != result) {
+               const std::string &errStr = ((WifiActionPower*)user_data)->strErr(result);
+               ERR("deactivate_cb() Fail(%d, %s)", result, errStr.c_str());
+       }
+}
+
+int WifiActionPower::set(bool val)
+{
+       RETV_IF(!isWifiManagerEnable(), MODES_ERROR_NOT_SUPPORTED);
+
+       if (isWifiActivate() == val) {
+               INFO("Already wifi is [%s]", val ? "On" : "Off");
+               return MODES_ERROR_NONE;
+       }
+
+       if (val) {
+               int wifiRet = wifi_manager_activate(wifiManagerHandle, activate_cb, this);
+               if (WIFI_MANAGER_ERROR_NONE != wifiRet) {
+                       ERR("wifi_manager_activate() Fail(%d, %s)", wifiRet, strErr(wifiRet).c_str());
+                       return MODES_ERROR_SYSTEM;
+               }
+       } else {
+               int wifiRet = wifi_manager_deactivate(wifiManagerHandle, deactivate_cb, this);
+               if (WIFI_MANAGER_ERROR_NONE != wifiRet) {
+                       ERR("wifi_manager_activate() Fail(%d, %s)", wifiRet, strErr(wifiRet).c_str());
+                       return MODES_ERROR_SYSTEM;
+               }
+       }
+
+       INFO("Wifi power [%s]", val ? "On" : "Off");
+       return MODES_ERROR_NONE;
+}
diff --git a/wifi/WifiActionPower.h b/wifi/WifiActionPower.h
new file mode 100644 (file)
index 0000000..d415ee0
--- /dev/null
@@ -0,0 +1,33 @@
+/*
+ * 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();
+
+       int set(bool val) override;
+private:
+       static void activate_cb(wifi_manager_error_e result, void *user_data);
+       static void deactivate_cb(wifi_manager_error_e result, void *user_data);
+};
+
+MODES_NAMESPACE_END
diff --git a/wifi/WifiErrorMessage.h b/wifi/WifiErrorMessage.h
new file mode 100644 (file)
index 0000000..06ef362
--- /dev/null
@@ -0,0 +1,84 @@
+/*
+ * 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
new file mode 100644 (file)
index 0000000..183dfe8
--- /dev/null
@@ -0,0 +1,77 @@
+#!/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 $@
diff --git a/wifi/WifiFactory.cpp b/wifi/WifiFactory.cpp
new file mode 100644 (file)
index 0000000..58c13b0
--- /dev/null
@@ -0,0 +1,57 @@
+/*
+ * 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 "WifiFactory.h"
+
+#include "modes_errors.h"
+#include "plugin-log.h"
+#include "WifiActionPower.h"
+
+MODES_NAMESPACE_USE;
+
+WifiFactory::WifiFactory()
+{
+       registerAction("power", WifiActionEnum::POWER);
+}
+
+WifiAction* WifiFactory::createAction(const std::string &key)
+{
+       auto search = actionMap.find(key);
+       if (search == actionMap.end()) {
+               ERR("No WifiAction(%s)", key.c_str());
+               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;
+}
diff --git a/wifi/WifiFactory.h b/wifi/WifiFactory.h
new file mode 100644 (file)
index 0000000..71bb2fe
--- /dev/null
@@ -0,0 +1,40 @@
+/*
+ * 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();
+       ~WifiFactory() = default;
+
+       WifiAction *createAction(const std::string &key);
+       void destroyAction(WifiAction *action);
+private:
+       enum class WifiActionEnum {
+               POWER
+       };
+
+       void registerAction(std::string key, WifiActionEnum action);
+       std::map<std::string, WifiActionEnum> actionMap;
+};
+
+MODES_NAMESPACE_END
diff --git a/wifi/WifiPlugin.cpp b/wifi/WifiPlugin.cpp
new file mode 100644 (file)
index 0000000..c56761c
--- /dev/null
@@ -0,0 +1,108 @@
+/*
+ * 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 <string>
+#include <map>
+#include <utility>
+#include <modes_errors.h>
+#include <wifi-manager.h>
+#include <Plugin.h>
+#include "plugin-log.h"
+#include "WifiErrorMessage.h"
+#include "WifiFactory.h"
+
+MODES_NAMESPACE_USE;
+
+class WifiOperation;
+class WifiPlugin : public Plugin {
+public:
+       WifiPlugin();
+       ~WifiPlugin();
+
+       int set(const std::string &key, int val) override;
+       int set(const std::string &key, double val) override;
+       int set(const std::string &key, bool val) override;
+       int set(const std::string &key, const std::string &val) override;
+private:
+       WifiFactory wifiFactory;
+};
+
+extern "C" API Plugin *objectCreate(void)
+{
+       return new WifiPlugin;
+}
+
+extern "C" API void objectDelete(Plugin *plugin)
+{
+       delete plugin;
+}
+
+WifiPlugin::WifiPlugin()
+{
+       setName("wifi");
+}
+
+WifiPlugin::~WifiPlugin()
+{
+}
+
+int WifiPlugin::set(const std::string &key, int val)
+{
+       WifiAction *action = wifiFactory.createAction(key);
+       RETVM_IF(nullptr == action, MODES_ERROR_INVALID_PARAMETER, "action(%s) is null", key.c_str());
+
+       DBG("set [%s, %d]", key.c_str(), val);
+
+       int ret = action->set(val);
+       wifiFactory.destroyAction(action);
+       return ret;
+}
+
+int WifiPlugin::set(const std::string &key, double val)
+{
+       WifiAction *action = wifiFactory.createAction(key);
+       RETVM_IF(nullptr == action, MODES_ERROR_INVALID_PARAMETER, "action(%s) is null", key.c_str());
+
+       DBG("set [%s, %f]", key.c_str(), val);
+
+       int ret = action->set(val);
+       wifiFactory.destroyAction(action);
+       return ret;
+}
+
+int WifiPlugin::set(const std::string &key, bool val)
+{
+       WifiAction *action = wifiFactory.createAction(key);
+       RETVM_IF(nullptr == action, MODES_ERROR_INVALID_PARAMETER, "action(%s) is null", key.c_str());
+
+       DBG("set [%s, %s]", key.c_str(), (val ? "on" : "off"));
+
+       int ret = action->set(val);
+       wifiFactory.destroyAction(action);
+       return ret;
+}
+
+int WifiPlugin::set(const std::string &key, const std::string &val)
+{
+       WifiAction *action = wifiFactory.createAction(key);
+       RETVM_IF(nullptr == action, MODES_ERROR_INVALID_PARAMETER, "action(%s) is null", key.c_str());
+
+       DBG("set [%s, %s]", key.c_str(), val.c_str());
+
+       int ret = action->set(val);
+       wifiFactory.destroyAction(action);
+       return ret;
+}
+