diff options
author | jh9216.park <jh9216.park@samsung.com> | 2021-07-12 23:44:40 -0400 |
---|---|---|
committer | jh9216.park <jh9216.park@samsung.com> | 2021-07-13 02:14:54 -0400 |
commit | e60b5d455266b103e9066ac8f9f2b0f9027ee68e (patch) | |
tree | 1b88c45d9f5eb69aedbbe5d2a2e0c22f83cc110c | |
parent | 928561d5724d2a92993b5844ceceed8d1497cd75 (diff) | |
download | appcore-agent-e60b5d455266b103e9066ac8f9f2b0f9027ee68e.tar.gz appcore-agent-e60b5d455266b103e9066ac8f9f2b0f9027ee68e.tar.bz2 appcore-agent-e60b5d455266b103e9066ac8f9f2b0f9027ee68e.zip |
Add internal API for c++
Change-Id: Ibc1c2e6f687de5af8d5fa3140d9ebced2db6d846
Signed-off-by: jh9216.park <jh9216.park@samsung.com>
-rw-r--r-- | CMakeLists.txt | 2 | ||||
-rw-r--r-- | include/service_app.hpp | 67 | ||||
-rw-r--r-- | packaging/appcore-agent.spec | 1 | ||||
-rw-r--r-- | unittests/service_app_cpp_test.cc | 41 |
4 files changed, 110 insertions, 1 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt index fa6c53c..dbf7f9e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -40,7 +40,7 @@ INSTALL(FILES ${CMAKE_CURRENT_BINARY_DIR}/capi-appfw-service-application.pc DEST INSTALL(DIRECTORY ${CMAKE_SOURCE_DIR}/include/ DESTINATION include/appcore-agent/ FILES_MATCHING - PATTERN "*.h" + PATTERN "*.h*" ) ADD_SUBDIRECTORY(unittests)
\ No newline at end of file diff --git a/include/service_app.hpp b/include/service_app.hpp new file mode 100644 index 0000000..e421364 --- /dev/null +++ b/include/service_app.hpp @@ -0,0 +1,67 @@ +/* + * Copyright (c) 2021 Samsung Electronics Co., Ltd. + * + * 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. + */ + +#ifndef TIZEN_APPFW_SERVICE_APP_HPP_ +#define TIZEN_APPFW_SERVICE_APP_HPP_ + +#include <service_app.h> + +#include <app_control.hpp> +#include <app_common.hpp> + +namespace tizen_appfw { + +class ServiceAppBase : public app_common::AppBase< + decltype(service_app_add_event_handler)*, + decltype(service_app_remove_event_handler)*> { + public: + using Remover = decltype(service_app_remove_event_handler)*; + + ServiceAppBase() + : AppBase(service_app_add_event_handler, + service_app_remove_event_handler) {} + + virtual bool OnCreate() { return true; } + virtual void OnTerminate() {} + virtual void OnAppControl(const ReceivedAppControl& ctrl) {} + + int Run(int argc, char** argv) { + service_app_lifecycle_callback_s callback = { + create : [](void* user_data) -> bool { + ServiceAppBase* b = static_cast<ServiceAppBase*>(user_data); + return b->OnCreate(); + }, + terminate : [](void* user_data) { + ServiceAppBase* b = static_cast<ServiceAppBase*>(user_data); + b->OnTerminate(); + }, + app_control : [](app_control_h app_control, void* user_data) { + ServiceAppBase* b = static_cast<ServiceAppBase*>(user_data); + b->OnAppControl(ReceivedAppControl(app_control)); + } + }; + + return service_app_main(argc, argv, &callback, this); + } + + void Exit() noexcept { + service_app_exit(); + } +}; + +} // namespace tizen_appfw + +#endif // TIZEN_APPFW_SERVICE_APP_HPP_
\ No newline at end of file diff --git a/packaging/appcore-agent.spec b/packaging/appcore-agent.spec index 2544c71..c24172b 100644 --- a/packaging/appcore-agent.spec +++ b/packaging/appcore-agent.spec @@ -100,6 +100,7 @@ LD_LIBRARY_PATH=../ ctest -V %files -n capi-appfw-service-application-devel %{_includedir}/appcore-agent/service_app.h +%{_includedir}/appcore-agent/service_app.hpp %{_includedir}/appcore-agent/service_app_extension.h %{_includedir}/appcore-agent/service_app_internal.h %{_libdir}/pkgconfig/capi-appfw-service-application.pc diff --git a/unittests/service_app_cpp_test.cc b/unittests/service_app_cpp_test.cc new file mode 100644 index 0000000..26ec2a9 --- /dev/null +++ b/unittests/service_app_cpp_test.cc @@ -0,0 +1,41 @@ +/* + * Copyright (c) 2021 Samsung Electronics Co., Ltd. + * + * 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 <gmock/gmock.h> +#include <service_app.hpp> + +namespace { + +class ServiceApp : public tizen_appfw::ServiceAppBase { + public: + ServiceApp() {} + + bool OnCreate() override { + return true; + } + + void OnTerminate() override {} + void OnAppControl(const tizen_appfw::ReceivedAppControl& ctrl) override {} +}; + +} // namespace + +TEST(ServiceAppCppTest, Run_InvalidParameter) { + ServiceApp app; + + int ret = app.Run(0, nullptr); + EXPECT_EQ(ret, APP_ERROR_INVALID_PARAMETER); +}
\ No newline at end of file |