#include "action/app_control_executor.hh"
#include "action/service.hh"
#include "action/sqlite_db.hh"
+#include "common/action_executor.hh"
#include "common/utils/logging.hh"
namespace action {
db->GetAction(id);
}
-void ActionRequestHandler::OnGetActionId(std::string user_description, int top_k,
- float search_threshold) {
+void ActionRequestHandler::OnGetActionId(std::string user_description,
+ int top_k, float search_threshold) {
}
-void ActionRequestHandler::OnExecute(common::ActionModel& model) {
- LOG(DEBUG) << "OnExecute action : " << model.GetActionId() << ", appid : " << model.GetAppId();
+void ActionRequestHandler::OnExecute(std::string instance,
+ common::ActionModel& model) {
+ LOG(DEBUG) << "OnExecute action : " << model.GetActionId()
+ << ", appid : " << model.GetAppId();
if (model.GetType() == common::ActionType::AppControl) {
LOG(DEBUG) << "execute appcontrol";
- AppControlExecutor executor;
- executor.Execute(model);
+ auto executor = std::make_unique<AppControlExecutor>(instance, model);
+ executor->SetResultHandler(this);
+ executor->Execute(model);
+ executors_.emplace_back(std::move(executor));
} else if (model.GetType() == common::ActionType::Plugin) {
LOG(DEBUG) << "execute plugin";
}
}
+void ActionRequestHandler::OnResult(std::string executor_id,
+ std::string result) {
+ LOG(DEBUG) << "OnResult : " << result << ", from : " << executor_id;
+}
+
} // namespace action
#ifndef ACTION_ACTION_REQUEST_HANDLER_H_
#define ACTION_ACTION_REQUEST_HANDLER_H_
+#include <memory>
#include <vector>
#include "action/request_handler.hh"
#include "action/tizen_action_service_stub.h"
+#include "common/action_executor.hh"
#include "common/action_model.h"
-
-using Action = rpc_port::tizen_action_service_stub::Action;
+#include "common/action_result_handler.hh"
namespace action {
-class ActionRequestHandler : public IRequestHandler {
+class ActionRequestHandler : public IRequestHandler, public IActionResultHandler {
public:
ActionRequestHandler();
~ActionRequestHandler();
void OnGetAction(std::string id) override;
void OnGetActionId(std::string user_description, int top_k,
float search_threshold) override;
- void OnExecute(common::ActionModel& model) override;
+ void OnExecute(std::string instance, common::ActionModel& model) override;
+
+ void OnResult(std::string executor_id, std::string result) override;
private:
rpc_port::tizen_action_service_stub::stub::ActionService service_;
+ std::vector<std::unique_ptr<common::AbstractActionExecutor>> executors_;
};
} // namespace action
#include <memory>
-#include "action/app_control_sender.hh"
#include "common/action_model.h"
#include "common/utils/logging.hh"
auto params = action_model.GetParameters();
for (auto const& iter : params)
- LOG(DEBUG) << "param name : " << iter.GetName() << ", val : " << iter.GetValue() << ", type : " << static_cast<int>(iter.GetType());
+ LOG(DEBUG) << "param name : " << iter.GetName() << ", val : "
+ << iter.GetValue() << ", type : " << static_cast<int>(iter.GetType());
return handle;
}
+void ResultCb(app_control_h request, app_control_error_e result,
+ void* user_data) {
+ LOG(DEBUG) << "ResultCb: " << result;
+}
+
+void ReplyCb(app_control_h request, app_control_h reply,
+ app_control_result_e result, void* user_data) {
+ // TODO: return reply to caller
+ auto on_reply = static_cast<action::AppControlExecutor*>(user_data);
+
+ // TODO: return what
+ std::string result_str = "result";
+ on_reply->OnAppControlReply(result_str);
+}
+
} // namespace
namespace action {
-int AppControlExecutor::Execute(const common::ActionModel& model) {
- LOG(ERROR) << "AppControl Execute : " << model.GetAppId();
+AppControlExecutor::AppControlExecutor(std::string id,
+ const common::ActionModel& model)
+ : AbstractActionExecutor(std::move(id)) {
+ model_ = model;
+ app_control_ = ConvertToAppControl(model);
+}
- app_control_h app_control = ConvertToAppControl(model);
+AppControlExecutor::~AppControlExecutor() {
+ int ret = app_control_destroy(app_control_);
+ if (ret != APP_CONTROL_ERROR_NONE)
+ LOG(ERROR) << "Failed to destroy app_control: " << ret;
+}
- std::unique_ptr<AppControlSender> sender =
- std::make_unique<AppControlSender>(app_control, this);
+int AppControlExecutor::Execute(const common::ActionModel& model) {
+ LOG(ERROR) << "AppControl Execute : " << model.GetAppId();
- // TODO: handle result?
- sender->Send();
+ AddExtraData(model);
- senders_.emplace_back(std::move(sender));
+ if (!SendAppControl()) {
+ LOG(ERROR) << "Failed to send app control";
+ return -1;
+ }
return 0;
}
-void AppControlExecutor::OnReply(const std::string& reply) {
+void AppControlExecutor::OnAppControlReply(const std::string& reply) {
// TODO: Handle reply
- LOG(DEBUG) << reply;
+ LOG(DEBUG) << "reply from instance: " << GetId() << ", reply: " << reply;
+ result_handler_->OnResult(GetId(), reply);
+}
+
+void AppControlExecutor::AddExtraData(const common::ActionModel& model) {
+ for (auto const& iter : model.GetParameters()) {
+ auto key = iter.GetName();
+ auto val = iter.GetValue();
+ int ret = app_control_add_extra_data(app_control_, key.c_str(),
+ val.c_str());
+ if (ret != APP_CONTROL_ERROR_NONE)
+ LOG(ERROR) << "Failed to add extra data: " << ret;
+ }
+}
+
+bool AppControlExecutor::SendAppControl() {
+ int ret = app_control_send_launch_request_async(app_control_, ResultCb,
+ ReplyCb, static_cast<void*>(this));
+ if (ret != APP_CONTROL_ERROR_NONE) {
+ LOG(ERROR) << "Failed to send launch request: " << ret;
+ return false;
+ }
+ return true;
+}
+
+void AppControlExecutor::SetResultHandler(IActionResultHandler* handler) {
+ result_handler_ = handler;
}
} // namespace action
#ifndef ACTION_APP_CONTROL_EXECUTOR_HH_
#define ACTION_APP_CONTROL_EXECUTOR_HH_
-#include <memory>
+#include <app_control.h>
-#include "action/app_control_sender.hh"
#include "common/action_executor.hh"
#include "common/action_model.h"
+#include "common/action_result_handler.hh"
namespace action {
-class AppControlExecutor : public common::IActionExecutor {
+class AppControlExecutor : public common::AbstractActionExecutor {
public:
- AppControlExecutor() = default;
- ~AppControlExecutor() = default;
+ explicit AppControlExecutor(std::string id, const common::ActionModel& model);
+ ~AppControlExecutor();
int Execute(const common::ActionModel& model) override;
- void OnReply(const std::string& reply) override;
+
+ void OnAppControlReply(const std::string& reply);
+ void SetResultHandler(IActionResultHandler* result_handler);
private:
- std::vector<std::unique_ptr<AppControlSender>> senders_;
+ void AddExtraData(const common::ActionModel& model);
+ bool SendAppControl();
+
+ common::ActionModel model_;
+ app_control_h app_control_;
+ IActionResultHandler* result_handler_;
};
} // 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/app_control_sender.hh"
-
-#include <app_control.h>
-
-#include "common/utils/logging.hh"
-
-namespace {
-
-void ResultCb(app_control_h request, app_control_error_e result,
- void* user_data) {
- LOG(DEBUG) << "ResultCb: " << result;
-}
-
-void ReplyCb(app_control_h request, app_control_h reply,
- app_control_result_e result, void* user_data) {
- // TODO: return reply to caller
- common::IActionExecutor* on_reply =
- static_cast<common::IActionExecutor*>(user_data);
-
- // TODO: return what
- std::string result_str = "result";
- on_reply->OnReply(result_str);
-}
-
-} // namespace
-
-namespace action {
-
-AppControlSender::AppControlSender(app_control_h app_control,
- common::IActionExecutor* executor)
- : app_control_(app_control), executor_(executor) {
-}
-
-AppControlSender::~AppControlSender() {
- int ret = app_control_destroy(app_control_);
- if (ret != APP_CONTROL_ERROR_NONE)
- LOG(ERROR) << "Failed to destroy app_control: " << ret;
-}
-
-bool AppControlSender::Send() {
- int ret = app_control_send_launch_request_async(app_control_, ResultCb,
- ReplyCb, static_cast<void*>(executor_));
- if (ret != APP_CONTROL_ERROR_NONE) {
- LOG(ERROR) << "Failed to send launch request: " << ret;
- return false;
- }
-
- return true;
-}
-
-} // 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_EXECUTOR_APP_CONTROL_SENDER_HH_
-#define ACTION_EXECUTOR_APP_CONTROL_SENDER_HH_
-
-#include <app_control.h>
-
-#include "common/action_executor.hh"
-
-namespace action {
-
-class AppControlSender {
- public:
- AppControlSender(app_control_h app_control,
- common::IActionExecutor* executor);
- ~AppControlSender();
- bool Send();
-
- private:
- app_control_h app_control_;
- common::IActionExecutor* executor_;
-};
-
-} // action
-
-#endif // ACTION_EXECUTOR_APP_CONTROL_SENDER_HH_
#include "common/action_model.h"
+// TODO: dependency?
+#include "action/tizen_action_service_stub.h"
+
namespace action {
class IRequestHandler {
virtual void OnGetAction(std::string id) = 0;
virtual void OnGetActionId(std::string user_description, int top_k,
float search_threshold) = 0;
- virtual void OnExecute(common::ActionModel& model) = 0;
+ virtual void OnExecute(std::string instance, common::ActionModel& model) = 0;
};
} // namespace action
}
model.SetParameters(actionparams);
- handler_.OnExecute(model);
+ handler_.OnExecute(GetInstance(), model);
return 0;
}
#define COMMON_ACTION_EXECUTOR_HH_
#include <string>
+#include <utility>
#include "common/action_model.h"
namespace common {
-class IActionExecutor {
+class AbstractActionExecutor {
public:
- virtual ~IActionExecutor() = default;
+ explicit AbstractActionExecutor(std::string id) : id_(std::move(id)) {}
+ virtual ~AbstractActionExecutor() = default;
virtual int Execute(const ActionModel& model) = 0;
- virtual void OnReply(const std::string& result) = 0;
+ virtual std::string GetId() { return id_; }
+
+ private:
+ std::string id_;
};
} // namespace common
--- /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_ACTION_RESULT_HANDLER_HH_
+#define COMMON_ACTION_RESULT_HANDLER_HH_
+
+class IActionResultHandler {
+ public:
+ virtual ~IActionResultHandler() = default;
+ virtual void OnResult(std::string executor_id, std::string result) = 0;
+};
+
+#endif // COMMON_ACTION_RESULT_HANDLER_HH_