To comply with OCP, we implemented PluginExecutor as an abstraction of AbstractActionExecutor.
Signed-off-by: Changgyu Choi <changyu.choi@samsung.com>
--- /dev/null
+#include "action_executor_factory.hh"
+
+std::unique_ptr<common::AbstractActionExecutor>
+action::ActionExecutorFactory::CreateExecutor(common::ActionType type) {
+ return std::unique_ptr<common::AbstractActionExecutor>();
+}
--- /dev/null
+/*
+ * 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.
+ */
+
+#ifndef ACTION_ACTION_EXECUTOR_FACTORY_HH_
+#define ACTION_ACTION_EXECUTOR_FACTORY_HH_
+
+#include <memory>
+#include "common/action_executor.hh"
+
+namespace action {
+
+class ActionExecutorFactory {
+ public:
+ static std::unique_ptr<common::AbstractActionExecutor> CreateExecutor(
+ common::ActionType type);
+};
+
+} // namespace action
+
+#endif // ACTION_ACTION_EXECUTOR_FACTORY_HH_
#include <string>
+#include "action/action_executor_factory.hh"
#include "action/action_request_handler.hh"
-#include "action/app_control_executor.hh"
#include "action/service.hh"
#include "action/sqlite_db.hh"
#include "action_request_handler.hh"
-#include "common/action_executor.hh"
#include "common/utils/logging.hh"
#include "utils/action_model_converter.hh"
namespace action {
-ActionRequestHandler::ActionRequestHandler()
- : plugin_manager_(
- this,
- "d::org.tizen.appfw.service.tizen_action_plugin_manager") {}
+ActionRequestHandler::ActionRequestHandler() {}
ActionRequestHandler::~ActionRequestHandler() {}
void ActionRequestHandler::Init() {
service_.Listen(std::make_shared<action::Service::Factory>(*this));
- plugin_manager_.Connect();
}
void ActionRequestHandler::OnListActions() {
LOG(DEBUG) << "OnExecute action : " << model.GetActionId()
<< ", appid : " << model.GetAppId();
- if (model.GetType() == common::ActionType::AppControl) {
- LOG(DEBUG) << "execute appcontrol";
-
- auto executor = std::make_unique<AppControlExecutor>(requester, model);
- executor->SetResultHandler(this);
- executor->Execute(model);
- executors_.emplace_back(std::move(executor));
- } else if (model.GetType() == common::ActionType::Plugin) {
- LOG(DEBUG) << "execute plugin";
-
- auto action = ActionModelConverter().ConvertToAction(model);
- auto response = plugin_manager_.Execute(std::move(action));
- LOG(DEBUG) << "plugin execute done";
- }
+ LOG(DEBUG) << "execute action type: "
+ << (model.GetType() == common::ActionType::AppControl
+ ? "AppControl"
+ : "Plugin");
+ auto executor = ActionExecutorFactory::CreateExecutor(model.GetType());
+ executor->SetResultHandler(this);
+ executor->Execute(model);
+ executors_.emplace_back(std::move(executor));
}
void ActionRequestHandler::OnResult(const std::string& requester,
LOG(DEBUG) << "OnResult : " << result << ", from : " << requester;
}
-void ActionRequestHandler::OnConnected() {
- LOG(INFO) << "PluginManager connected";
-}
-
-void ActionRequestHandler::OnDisconnected() {
- LOG(INFO) << "PluginManager disconnected";
-}
-
-void ActionRequestHandler::OnRejected() {
- LOG(INFO) << "PluginManager rejected";
-}
-
} // namespace action
#include <memory>
#include <vector>
-#include "action/plugin_manager_proxy.h"
#include "action/request_handler.hh"
-#include "action/result_handler.hh"
#include "action/tizen_action_service_stub.h"
#include "common/action_executor.hh"
#include "common/action_model.h"
+#include "common/result_handler.hh"
namespace action {
-class ActionRequestHandler : public IRequestHandler,
- public IResultHandler,
- public rpc_port::plugin_manager_proxy::proxy::
- PluginManager::IEventListener {
+class ActionRequestHandler : public IRequestHandler, common::IResultHandler {
public:
ActionRequestHandler();
~ActionRequestHandler();
void OnResult(const std::string& requester,
const std::string& result) override;
- void OnConnected() override;
- void OnDisconnected() override;
- void OnRejected() override;
-
private:
rpc_port::tizen_action_service_stub::stub::ActionService service_;
std::vector<std::unique_ptr<common::AbstractActionExecutor>> executors_;
- rpc_port::plugin_manager_proxy::proxy::PluginManager plugin_manager_;
};
} // namespace action
return true;
}
-void AppControlExecutor::SetResultHandler(IResultHandler* handler) {
+void AppControlExecutor::SetResultHandler(common::IResultHandler* handler) {
result_handler_ = handler;
}
#include <app_control.h>
-#include "action/result_handler.hh"
#include "common/action_executor.hh"
#include "common/action_model.h"
int Execute(const common::ActionModel& model) override;
void OnAppControlReply(const std::string& reply);
- void SetResultHandler(IResultHandler* handler);
+ void SetResultHandler(common::IResultHandler* handler) override;
private:
void AddExtraData(const common::ActionModel& model);
common::ActionModel model_;
app_control_h app_control_;
- IResultHandler* result_handler_;
+ common::IResultHandler* result_handler_ = nullptr;
};
} // namespace action
--- /dev/null
+/*
+ * 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 "action/plugin_executor.hh"
+
+#include <memory>
+
+#include "common/action_model.h"
+#include "common/utils/logging.hh"
+#include "utils/action_model_converter.hh"
+#include "plugin_executor.hh"
+
+namespace action {
+
+class ResultHandler : public rpc_port::plugin_manager_proxy::proxy::
+ PluginManager::ResultHandler {
+ public:
+ ResultHandler(PluginExecutor* executor)
+ : rpc_port::plugin_manager_proxy::proxy::PluginManager::ResultHandler(
+ true),
+ executor_(executor) {
+ }
+
+ ~ResultHandler() = default;
+
+ void OnReceived(std::string result) override {
+ if (executor_)
+ executor_->OnResultReceived(result);
+ }
+
+ private:
+ PluginExecutor* executor_ = nullptr;
+};
+
+PluginExecutor::PluginExecutor(std::string id, const common::ActionModel& model)
+ : AbstractActionExecutor(std::move(id)),
+ plugin_manager_(
+ this,
+ "d::org.tizen.appfw.service.tizen_action_plugin_manager") {
+ model_ = model;
+}
+
+PluginExecutor::~PluginExecutor() {
+ if (connected_)
+ plugin_manager_.Disconnect();
+}
+
+int PluginExecutor::Execute(const common::ActionModel& model) {
+ LOG(ERROR) << "Plugin Execute : " << model.GetUri();
+
+ if (!Connect())
+ return -1;
+
+ auto action = ActionModelConverter().ConvertToAction(model);
+ auto result_cb = std::make_unique<ResultHandler>(this);
+ try {
+ plugin_manager_.Execute(std::move(action), std::move(result_cb));
+ } catch (const rpc_port::plugin_manager_proxy::proxy::Exception& e) {
+ LOG(ERROR) << "Failed to execute action";
+ return -1;
+ }
+
+ return 0;
+}
+
+void PluginExecutor::OnResultReceived(const std::string& result) {
+ // TODO: Handle result
+ LOG(DEBUG) << "result from instance: " << GetId() << ", result: " << result;
+ result_handler_->OnResult(GetId(), result);
+}
+
+void PluginExecutor::SetResultHandler(common::IResultHandler* handler) {
+ result_handler_ = handler;
+}
+
+bool PluginExecutor::Connect() {
+ if (connected_)
+ return true;
+
+ try {
+ plugin_manager_.Connect(true);
+ } catch (...) {
+ LOG(ERROR) << "Failed to connect to plugin manager";
+ return false;
+ }
+
+ connected_ = true;
+ return true;
+}
+
+void PluginExecutor::OnConnected() {
+ connected_ = true;
+ LOG(INFO) << "PluginManager connected";
+}
+
+void PluginExecutor::OnDisconnected() {
+ connected_ = false;
+ LOG(INFO) << "PluginManager disconnected";
+}
+
+void PluginExecutor::OnRejected() {
+ connected_ = false;
+ LOG(INFO) << "PluginManager rejected";
+}
+
+} // namespace action
--- /dev/null
+/*
+ * 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.
+ */
+
+#ifndef ACTION_PLUGIN_EXECUTOR_HH_
+#define ACTION_PLUGIN_EXECUTOR_HH_
+
+#include <app_control.h>
+
+#include "common/action_executor.hh"
+#include "common/action_model.h"
+#include "plugin_manager_proxy.h"
+
+namespace action {
+
+class PluginExecutor : public common::AbstractActionExecutor,
+ public rpc_port::plugin_manager_proxy::proxy::
+ PluginManager::IEventListener {
+ public:
+ explicit PluginExecutor(std::string id, const common::ActionModel& model);
+ ~PluginExecutor();
+ int Execute(const common::ActionModel& model) override;
+ void SetResultHandler(common::IResultHandler* handler) override;
+ void OnResultReceived(const std::string& result);
+
+ private:
+ bool Connect();
+
+ void OnConnected() override;
+ void OnDisconnected() override;
+ void OnRejected() override;
+
+ private:
+ common::ActionModel model_;
+ rpc_port::plugin_manager_proxy::proxy::PluginManager plugin_manager_;
+ common::IResultHandler* result_handler_ = nullptr;
+ bool connected_ = false;
+};
+
+} // namespace action
+
+#endif // ACTION_PLUGIN_EXECUTOR_HH_
+++ /dev/null
-/*
- * 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.
- */
-
-#ifndef ACTION_RESULT_HANDLER_HH_
-#define ACTION_RESULT_HANDLER_HH_
-
-#include <string>
-
-namespace action {
-
-class IResultHandler {
- public:
- virtual ~IResultHandler() = default;
- virtual void OnResult(const std::string& executor_id,
- const std::string& result) = 0;
-};
-
-} // namespace action
-
-#endif // ACTION_RESULT_HANDLER_HH_
#include <utility>
#include "common/action_model.h"
+#include "common/result_handler.hh"
namespace common {
virtual ~AbstractActionExecutor() = default;
virtual int Execute(const ActionModel& model) = 0;
virtual std::string GetId() { return id_; }
+ virtual void SetResultHandler(IResultHandler* handler) = 0;
private:
std::string id_;
--- /dev/null
+/*
+ * 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.
+ */
+
+#ifndef COMMON_RESULT_HANDLER_HH_
+#define COMMON_RESULT_HANDLER_HH_
+
+#include <string>
+
+namespace common {
+
+class IResultHandler {
+ public:
+ virtual ~IResultHandler() = default;
+ virtual void OnResult(const std::string& executor_id,
+ const std::string& result) = 0;
+};
+
+} // namespace common
+
+#endif // COMMON_RESULT_HANDLER_HH_
-#include <cstdio>
+/*
+ * 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 <rpc-port-internal.h>
+#include <algorithm>
+#include <cstdio>
#include <utility>
#include "common/utils/logging.hh"
#include "plugin_manager_stub.h"
-class PluginService : public rpc_port::plugin_manager_stub::stub::PluginManager::ServiceBase {
+class PluginService
+ : public rpc_port::plugin_manager_stub::stub::PluginManager::ServiceBase {
public:
- class Factory : public rpc_port::plugin_manager_stub::stub::PluginManager::ServiceBase::Factory {
+ class Factory : public rpc_port::plugin_manager_stub::stub::PluginManager::
+ ServiceBase::Factory {
public:
- std::unique_ptr<rpc_port::plugin_manager_stub::stub::PluginManager::ServiceBase> CreateService(
- std::string sender, std::string instance) override {
- return std::make_unique<PluginService>(std::move(sender), std::move(instance));
+ std::unique_ptr<
+ rpc_port::plugin_manager_stub::stub::PluginManager::ServiceBase>
+ CreateService(std::string sender, std::string instance) override {
+ return std::make_unique<PluginService>(std::move(sender),
+ std::move(instance));
}
};
- PluginService(std::string sender, std::string instance) : ServiceBase(sender, instance) {
-
- }
+ PluginService(std::string sender, std::string instance)
+ : ServiceBase(sender, instance) {}
void OnCreate() override {
std::string sender = GetSender();
std::string instance = GetInstance();
- LOG(INFO) << "PluginService created. sender: " << sender << ", instance: " << instance;
+ LOG(INFO) << "PluginService created. sender: " << sender
+ << ", instance: " << instance;
}
void OnTerminate() override {
std::string sender = GetSender();
std::string instance = GetInstance();
- LOG(INFO) << "PluginService terminated. sender: " << sender << ", instance: " << instance;
+ LOG(INFO) << "PluginService terminated. sender: " << sender
+ << ", instance: " << instance;
}
- rpc_port::plugin_manager_stub::Bundle Execute(rpc_port::plugin_manager_stub::Action action) {
+ void Execute(
+ rpc_port::plugin_manager_stub::Action action,
+ std::unique_ptr<
+ rpc_port::plugin_manager_stub::stub::PluginManager::ResultHandler>
+ result_cb) override {
std::string sender = GetSender();
std::string instance = GetInstance();
- LOG(INFO) << "PluginService execute. sender: " << sender << ", instance: " << instance;
+ LOG(INFO) << "PluginService execute. sender: " << sender
+ << ", instance: " << instance;
PrintAction(action);
- return rpc_port::plugin_manager_stub::Bundle();
+ auto parameters = action.Getparameters();
+ auto it = std::find_if(parameters.begin(), parameters.end(),
+ [](const auto& parameter) {
+ return parameter.Getkey() == "Executable";
+ });
+
+ if (it == parameters.end()) {
+ LOG(ERROR) << "Executable parameter not found";
+ result_cb->Invoke("Fail");
+ }
+
+ // TODO: implement action execution
+
+ result_cb->Invoke("Success");
}
private:
};
int main() {
- int ret =
- rpc_port_register_proc_info("d::org.tizen.appfw.service.tizen_action_plugin_manager", nullptr);
+ int ret = rpc_port_register_proc_info(
+ "d::org.tizen.appfw.service.tizen_action_plugin_manager", nullptr);
if (ret != 0) {
perror("Failed to register proc info");
return -1;
import <tizen_action_datatype.tidl>
interface PluginManager {
- bundle Execute(Action action);
+ void ResultHandler(string result) delegate;
+ void Execute(Action action, ResultHandler result_cb) async;
}