Add sample plugin so
authorChanggyu Choi <changyu.choi@samsung.com>
Mon, 28 Apr 2025 10:36:37 +0000 (19:36 +0900)
committerChanggyu Choi <changyu.choi@samsung.com>
Mon, 12 May 2025 05:11:18 +0000 (14:11 +0900)
libaction-plugin-sample.so has been added.

Signed-off-by: Changgyu Choi <changyu.choi@samsung.com>
packaging/tizen-action-framework.spec
src/action/plugin_executor.cc
src/plugin-daemon/CMakeLists.txt
src/plugin-daemon/plugin.cc
src/plugin-daemon/plugin_sample_so.cc [new file with mode: 0644]

index 467dc909b1c90db7e8b6b6aa62e99035597f2991..c97e962eb54c1d494363051a24cf3be756623a83 100644 (file)
@@ -154,6 +154,7 @@ fi
 %{_unitdir}/sockets.target.wants/tizen-action-plugin-daemon.socket
 %{_unitdir}/basic.target.wants/tizen-action-plugin-daemon.service
 %{_bindir}/tizen-action-plugin-daemon
+%{_libdir}/libaction-plugin-sample.so
 
 #Signing
 %define tizen_sign_base %{_prefix}/apps/%{service_pkgid};%{_prefix}/apps/%{service_pkgid}
index 6a02c0e6de461ee62aff9d4281d24830014147f9..1ac810f1cce02861a5f04856c0aac5a4e4023959 100644 (file)
@@ -56,10 +56,10 @@ PluginExecutor::~PluginExecutor() {
 }
 
 int PluginExecutor::Execute(const common::ActionModel& model) {
-  // if (model.GetType() != common::ActionType::Plugin) {
-  //   LOG(ERROR) << "Invalid action type";
-  //   return -1;
-  // }
+  if (model.GetType() != common::ActionType::Plugin) {
+    LOG(ERROR) << "Invalid action type";
+    return -1;
+  }
 
   LOG(ERROR) << "Plugin Execute : " << model.GetId();
 
index 230cd1f2c144a1fb5aec0624906c04cee96b4130..26a3560e092128a581109740a1127400263ccd39 100644 (file)
@@ -1,9 +1,13 @@
+
 AUX_SOURCE_DIRECTORY(${CMAKE_CURRENT_SOURCE_DIR} ACTION_PLUGIN_DAEMON_SRCS)
 
 ADD_EXECUTABLE(${TARGET_TIZEN_ACTION_PLUGIN_DAEMON}
   ${ACTION_PLUGIN_DAEMON_SRCS}
 )
 
+SET(TARGET_ACTION_PLUGIN_SAMPLE "action-plugin-sample")
+ADD_LIBRARY(${TARGET_ACTION_PLUGIN_SAMPLE} plugin_sample_so.cc)
+
 APPLY_PKG_CONFIG(${TARGET_TIZEN_ACTION_PLUGIN_DAEMON} PUBLIC
   CAPI_APPFW_APP_COMMON_DEPS
   CAPI_APPFW_APP_MANAGER_DEPS
@@ -15,8 +19,16 @@ APPLY_PKG_CONFIG(${TARGET_TIZEN_ACTION_PLUGIN_DAEMON} PUBLIC
   RPC_PORT_DEPS
 )
 
+APPLY_PKG_CONFIG(${TARGET_ACTION_PLUGIN_SAMPLE} PUBLIC
+  CAPI_APPFW_APP_COMMON_DEPS
+  DLOG_DEPS
+  GLIB_DEPS
+)
+
 TARGET_LINK_LIBRARIES(${TARGET_TIZEN_ACTION_PLUGIN_DAEMON} PRIVATE ${TARGET_TIZEN_ACTION} ${TARGET_TIZEN_ACTION_COMMON})
 TARGET_INCLUDE_DIRECTORIES(${TARGET_TIZEN_ACTION_PLUGIN_DAEMON} PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/../)
+TARGET_LINK_LIBRARIES(${TARGET_ACTION_PLUGIN_SAMPLE} PUBLIC ${TARGET_TIZEN_ACTION_COMMON})
+TARGET_INCLUDE_DIRECTORIES(${TARGET_ACTION_PLUGIN_SAMPLE} PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/../)
 
 INSTALL(TARGETS ${TARGET_TIZEN_ACTION_PLUGIN_DAEMON} DESTINATION bin)
-
+INSTALL(TARGETS ${TARGET_ACTION_PLUGIN_SAMPLE} DESTINATION ${LIB_INSTALL_DIR})
index 03c7ef303fa37389de58a3fe254fb99a4a5e64ea..99e7f81a2fdba5e160a93bbbc7639e96d703ba32 100644 (file)
@@ -31,5 +31,11 @@ Plugin::~Plugin() {
 }
 
 std::string Plugin::Execute(std::string action_model_json) {
-  return execute_function_(action_model_json.c_str());
+  const char* result_raw = execute_function_(action_model_json.c_str());
+  if (result_raw == nullptr)
+    return "";
+
+  std::string result(result_raw);
+  free(const_cast<char*>(result_raw));
+  return result;
 }
diff --git a/src/plugin-daemon/plugin_sample_so.cc b/src/plugin-daemon/plugin_sample_so.cc
new file mode 100644 (file)
index 0000000..96a53fe
--- /dev/null
@@ -0,0 +1,76 @@
+/*
+ * Copyright (c) 2025 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 <stdexcept>
+
+#include "common/utils/safe_json.hpp"
+#include "common/utils/logging.hh"
+
+
+#undef API
+#define API extern "C" __attribute__((visibility("default")))
+/*
+{
+  "version": "v2",
+  "name": "plugin-action-test",
+  "category": "test",
+  "desc": "Plugin test action",
+  "type": "plugin",
+  "params": {
+    "param1": {
+      "type": "string",
+      "desc": "String parameter.",
+      "isRequired": true
+    },
+    "param2": {
+      "type": "string",
+      "desc": "String parameter.",
+      "isRequired": true
+    }
+  },
+  "requiredPrivileges": [],
+  "returns": {
+       "result": {
+         "type": "string",
+      "desc": "The result string."
+       }
+  },
+  "details": {
+    "pluginPath": "/usr/lib64/libaction-plugin-sample.so"
+  }
+}
+*/
+API const char* PLUGIN_EXECUTE(const char* action_model_json) {
+  if (action_model_json == nullptr) {
+    LOG(ERROR) << "Invalid parameter";
+    return nullptr;
+  }
+
+  common::SafeJson result("{}");
+  try {
+    common::SafeJson json(action_model_json);
+    std::string param1 = json.get<std::string>("params.param1");
+    std::string param2 = json.get<std::string>("params.param2");
+    LOG(INFO) << "param1: " << param1 << ", param2: " << param2;
+    result.set("result", "success");
+  } catch (const std::runtime_error& e) {
+    common::SafeJson result("{}");
+    result.set("error", e.what());
+    return strdup(result.stringify().c_str());
+  }
+
+  return strdup(result.stringify().c_str());
+}