Add internal API for c++ 83/261183/4
authorjh9216.park <jh9216.park@samsung.com>
Tue, 13 Jul 2021 03:44:40 +0000 (23:44 -0400)
committerjh9216.park <jh9216.park@samsung.com>
Tue, 13 Jul 2021 06:14:54 +0000 (02:14 -0400)
Change-Id: Ibc1c2e6f687de5af8d5fa3140d9ebced2db6d846
Signed-off-by: jh9216.park <jh9216.park@samsung.com>
CMakeLists.txt
include/service_app.hpp [new file with mode: 0644]
packaging/appcore-agent.spec
unittests/service_app_cpp_test.cc [new file with mode: 0644]

index fa6c53c..dbf7f9e 100644 (file)
@@ -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 (file)
index 0000000..e421364
--- /dev/null
@@ -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
index 2544c71..c24172b 100644 (file)
@@ -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 (file)
index 0000000..26ec2a9
--- /dev/null
@@ -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