From: JinWang An Date: Thu, 1 Aug 2019 08:23:35 +0000 (+0900) Subject: Add AppFW Plugin X-Git-Tag: submit/tizen/20200406.072014~53 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=182b7642bef914b6c8ce26cd9c30045958d0456c;p=platform%2Fcore%2Fsystem%2Fmodes-plugins.git Add AppFW Plugin --- diff --git a/CMakeLists.txt b/CMakeLists.txt index 706e695..5775cfb 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -17,5 +17,6 @@ ENDIF(NOT DEFINED MODES_PLUGIN_DEFAULT_DIR) ADD_SUBDIRECTORY(wifi) ADD_SUBDIRECTORY(vconf) +ADD_SUBDIRECTORY(appfw) ADD_SUBDIRECTORY(bluetooth) ADD_SUBDIRECTORY(unittests) diff --git a/appfw/AppfwAction.cpp b/appfw/AppfwAction.cpp new file mode 100644 index 0000000..97a9c17 --- /dev/null +++ b/appfw/AppfwAction.cpp @@ -0,0 +1,42 @@ +/* + * 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 "AppfwAction.h" +#include + +MODES_NAMESPACE_USE; + +AppfwAction::AppfwAction() +{ +} + +AppfwAction::~AppfwAction() +{ +} + +int AppfwAction::set(const std::string &val) +{ + return MODES_ERROR_NOT_SUPPORTED; +} + +void AppfwAction::setName(std::string name) +{ + this->name = name; +} + +std::string AppfwAction::getName() +{ + return name; +} diff --git a/appfw/AppfwAction.h b/appfw/AppfwAction.h new file mode 100644 index 0000000..2719ca3 --- /dev/null +++ b/appfw/AppfwAction.h @@ -0,0 +1,39 @@ +/* + * 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 +#include "plugin-def.h" + +MODES_NAMESPACE_BEGIN + +class AppfwAction { +public: + AppfwAction(); + virtual ~AppfwAction(); + + std::string getName(); + virtual int set(const std::string &val); + +protected: + void setName(std::string name); + +private: + std::string name; +}; + +MODES_NAMESPACE_END + diff --git a/appfw/AppfwActionLaunch.cpp b/appfw/AppfwActionLaunch.cpp new file mode 100644 index 0000000..e6834bc --- /dev/null +++ b/appfw/AppfwActionLaunch.cpp @@ -0,0 +1,49 @@ +/* + * 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 "AppfwActionLaunch.h" + +#include +#include +#include "plugin-log.h" + +MODES_NAMESPACE_USE; + +const std::string AppfwActionLaunch::NAME = "launch"; + +AppfwActionLaunch::AppfwActionLaunch() +{ + setName(NAME); +} + +int AppfwActionLaunch::set(const std::string &val) +{ + DBG("id(%s)", val.c_str()); + + app_control_h service; + app_control_create(&service); + app_control_set_app_id(service, val.c_str()); + app_control_set_operation(service, APP_CONTROL_OPERATION_DEFAULT); + app_control_set_launch_mode(service, APP_CONTROL_LAUNCH_MODE_SINGLE); + + int ret = app_control_send_launch_request(service, NULL, NULL); + if (APP_CONTROL_ERROR_NONE != ret) { + ERR("app_control_send_launch_request() Fail(%s)", get_error_message(ret)); + return MODES_ERROR_IO_ERROR; + } + + app_control_destroy(service); + return MODES_ERROR_NONE; +} diff --git a/appfw/AppfwActionLaunch.h b/appfw/AppfwActionLaunch.h new file mode 100644 index 0000000..04eaf15 --- /dev/null +++ b/appfw/AppfwActionLaunch.h @@ -0,0 +1,32 @@ +/* + * 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 +#include "AppfwAction.h" + +MODES_NAMESPACE_BEGIN + +class AppfwActionLaunch : public AppfwAction { +public: + AppfwActionLaunch(); + + virtual int set(const std::string &val) override; + + static const std::string NAME; +}; + +MODES_NAMESPACE_END diff --git a/appfw/AppfwFactory.cpp b/appfw/AppfwFactory.cpp new file mode 100644 index 0000000..c6d1ac8 --- /dev/null +++ b/appfw/AppfwFactory.cpp @@ -0,0 +1,49 @@ +/* + * 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 "AppfwFactory.h" +#include +#include "plugin-log.h" +#include "AppfwActionLaunch.h" + +MODES_NAMESPACE_USE; + +AppfwFactory::AppfwFactory() +{ + actionMap[AppfwActionLaunch::NAME] = APPFW_ACT_LAUNCH; +} + +AppfwAction* AppfwFactory::createAction(const std::string &key) +{ + auto search = actionMap.find(key); + if (search == actionMap.end()) { + ERR("No AppfwAction(%s)", key.c_str()); + return nullptr; + } + + switch (search->second) { + case APPFW_ACT_LAUNCH: + AppfwActionLaunch *appfwActionLaunch = new AppfwActionLaunch(); + return appfwActionLaunch; + break; + } + + return nullptr; +} + +void AppfwFactory::destroyAction(AppfwAction *action) +{ + delete action; +} diff --git a/appfw/AppfwFactory.h b/appfw/AppfwFactory.h new file mode 100644 index 0000000..b65d7e5 --- /dev/null +++ b/appfw/AppfwFactory.h @@ -0,0 +1,39 @@ +/* + * 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 +#include +#include "AppfwAction.h" + +MODES_NAMESPACE_BEGIN + +class AppfwFactory { +public: + AppfwFactory(); + ~AppfwFactory() = default; + + AppfwAction* createAction(const std::string &key); + void destroyAction(AppfwAction *action); +private: + enum actionKey{ + APPFW_ACT_LAUNCH + }; + + std::map actionMap; +}; + +MODES_NAMESPACE_END diff --git a/appfw/AppfwPlugin.cpp b/appfw/AppfwPlugin.cpp new file mode 100644 index 0000000..a70de70 --- /dev/null +++ b/appfw/AppfwPlugin.cpp @@ -0,0 +1,65 @@ +/* + * 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 +#include +#include +#include +#include "plugin-log.h" +#include "AppfwFactory.h" + +MODES_NAMESPACE_USE; + +class AppfwPlugin : public Plugin { +public: + AppfwPlugin(); + ~AppfwPlugin(); + + int set(const std::string &key, const std::string &val, std::string *oldVal) override; +private: + AppfwFactory appfwFactory; +}; + +extern "C" API Plugin *objectCreate(void) +{ + return new AppfwPlugin; +} + +extern "C" API void objectDelete(Plugin *plugin) +{ + delete plugin; +} + +AppfwPlugin::AppfwPlugin() +{ + setName("appfw"); +} + +AppfwPlugin::~AppfwPlugin() +{ +} + +int AppfwPlugin::set(const std::string &key, const std::string &val, std::string *oldVal) +{ + AppfwAction *action = appfwFactory.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 appfwRet = action->set(val); + appfwFactory.destroyAction(action); + return appfwRet; +} + diff --git a/appfw/CMakeLists.txt b/appfw/CMakeLists.txt new file mode 100644 index 0000000..de7593f --- /dev/null +++ b/appfw/CMakeLists.txt @@ -0,0 +1,12 @@ +SET(APPFW_PLUGIN "modes-plugin-appfw") + +FILE(GLOB APPFW_SRCS *.cpp) + +pkg_check_modules(appfw_pkgs REQUIRED modes dlog capi-base-common capi-appfw-application) +INCLUDE_DIRECTORIES(${appfw_pkgs_INCLUDE_DIRS}) +LINK_DIRECTORIES(${appfw_pkgs_LIBRARY_DIRS}) + +ADD_LIBRARY(${APPFW_PLUGIN} SHARED ${APPFW_SRCS}) +TARGET_LINK_LIBRARIES(${APPFW_PLUGIN} ${appfw_pkgs_LIBRARIES}) +SET_TARGET_PROPERTIES(${APPFW_PLUGIN} PROPERTIES NO_SONAME 1 ) +INSTALL(TARGETS ${APPFW_PLUGIN} DESTINATION ${MODES_PLUGIN_DEFAULT_DIR}) diff --git a/bluetooth/BtPlugin.cpp b/bluetooth/BtPlugin.cpp index 450e5a6..03a6e6b 100644 --- a/bluetooth/BtPlugin.cpp +++ b/bluetooth/BtPlugin.cpp @@ -14,8 +14,6 @@ * limitations under the License. */ #include -#include -#include #include #include #include diff --git a/packaging/modes-plugins.spec b/packaging/modes-plugins.spec index 4528bac..9c9f7c8 100644 --- a/packaging/modes-plugins.spec +++ b/packaging/modes-plugins.spec @@ -13,7 +13,9 @@ BuildRequires: cmake BuildRequires: pkgconfig(modes) BuildRequires: modes-plugin-devel BuildRequires: pkgconfig(dlog) +BuildRequires: pkgconfig(capi-appfw-application) BuildRequires: pkgconfig(capi-base-common) +BuildRequires: pkgconfig(libxml-2.0) BuildRequires: pkgconfig(capi-network-wifi-manager) BuildRequires: pkgconfig(capi-network-bluetooth) BuildRequires: pkgconfig(vconf) @@ -31,6 +33,7 @@ The %{name}-unittests pacakge contains programs for checking quality the %{name} %define modes_plugin_dir %{_libdir}/modes-plugins %define modes_test_dir %{_bindir}/%{name} +%define modes_data_dir %{_datadir}/modes %prep %setup -q @@ -56,9 +59,13 @@ make %{?_smp_mflags} %install %make_install +mkdir -p %{buildroot}%{modes_data_dir}/rule +install -m 0644 xml/*_rule.xml %{buildroot}%{modes_data_dir}/rule/ %check -#TBD +pushd xml +xmllint --noout --schema %{modes_data_dir}/xsd/tizen_action_rule.xsd tizen_action_rule.xml +popd %post -p /sbin/ldconfig %postun -p /sbin/ldconfig @@ -66,6 +73,7 @@ make %{?_smp_mflags} %files %manifest %{name}.manifest %{modes_plugin_dir}/*.so +%{modes_data_dir}/rule/* %license LICENSE.APLv2 %files unittests diff --git a/unittests/CMakeLists.txt b/unittests/CMakeLists.txt index 5586836..425c352 100644 --- a/unittests/CMakeLists.txt +++ b/unittests/CMakeLists.txt @@ -2,7 +2,7 @@ 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 capi-network-bluetooth gmock) +pkg_check_modules(test_pkgs REQUIRED modes dlog capi-network-wifi-manager capi-network-bluetooth gmock capi-appfw-application) INCLUDE_DIRECTORIES(${test_pkgs_INCLUDE_DIRS}) LINK_DIRECTORIES(${test_pkgs_LIBRARY_DIRS}) @@ -21,3 +21,12 @@ SET(BT_SRCS ${BT_SRC_DIR}/BtAction.cpp "mdsp_bt_main.cpp") ADD_EXECUTABLE(${BT_PLUGIN_TEST} ${BT_SRCS}) TARGET_LINK_LIBRARIES(${BT_PLUGIN_TEST} ${test_pkgs_LIBRARIES} dl) INSTALL(TARGETS ${BT_PLUGIN_TEST} DESTINATION ${TEST_INSTALL_DIR}) +#===================================================================# +SET(APPFW_SRC_DIR "${CMAKE_SOURCE_DIR}/appfw" ) +SET(APPFW_PLUGIN_TEST "modes-gtest-appfw") +FILE(GLOB APPFW_SRCS ${APPFW_SRC_DIR}/*.cpp) +SET(APPFW_SRCS ${APPFW_SRCS} "mdsp_appfw_main.cpp") + +ADD_EXECUTABLE(${APPFW_PLUGIN_TEST} ${APPFW_SRCS}) +TARGET_LINK_LIBRARIES(${APPFW_PLUGIN_TEST} ${test_pkgs_LIBRARIES} dl) +INSTALL(TARGETS ${APPFW_PLUGIN_TEST} DESTINATION ${TEST_INSTALL_DIR}) diff --git a/unittests/mdsp_appfw_main.cpp b/unittests/mdsp_appfw_main.cpp new file mode 100644 index 0000000..a1f97b0 --- /dev/null +++ b/unittests/mdsp_appfw_main.cpp @@ -0,0 +1,44 @@ +/* + * 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 +#include +#include +#include +#include +#include +#include "plugin-log.h" +#include "plugin-def.h" + +MODES_NAMESPACE_USE; + +extern "C" API Plugin *objectCreate(void); +extern "C" API void objectDelete(Plugin *plugin); + +TEST(PluginTest, setPluginAppfw) +{ + int ret; + Plugin *plugin = objectCreate(); + + ret = plugin->set("launch", std::string("org.tizen.w-stopwatch"), nullptr); + EXPECT_EQ(ret, MODES_ERROR_NONE); + + objectDelete(plugin); +} + +int main(int argc, char **argv) { + testing::InitGoogleTest(&argc, argv); + return RUN_ALL_TESTS(); +} diff --git a/wifi/WifiPlugin.cpp b/wifi/WifiPlugin.cpp index f869917..39f0cfd 100644 --- a/wifi/WifiPlugin.cpp +++ b/wifi/WifiPlugin.cpp @@ -14,8 +14,6 @@ * limitations under the License. */ #include -#include -#include #include #include #include diff --git a/xml/tizen_action_rule.xml b/xml/tizen_action_rule.xml new file mode 100644 index 0000000..4b1b558 --- /dev/null +++ b/xml/tizen_action_rule.xml @@ -0,0 +1,85 @@ + + + + + 1 + 0 + 0 + wifi On/Off + Network & Connectivity + + + 1 + 0 + 0 + bluetooth On/Off + Network & Connectivity + + + 0:0:0:0:0:0 + bluetooth Audio Connect + Network & Connectivity + + + 100 + sensord.exactness + Sensor Accuracy + System + + + 100 + sensord.changeAccuracy + Sensor Exactness + System + + + 0 + 1 + 1 + 2 + 2 + 3 + 4 + 0 + 0 + sensord.changeAccuracy + test + System + + + 0 + 1 + 2 + 4 + 0 + test + Network & Connectivity + + + about:blank + browser + Web Framework + + + 70 + display.autoLight + It makes the screen color warmer. + System + + + 0 + Launch App + App Framework + + + 0 + It prints integerv value + System + + + 0 + It prints boolean value + System + + +