%defattr(-,root,root,-)
%manifest %{name}.manifest
%{_libdir}/libcapi-appfw-tizen-action.so
-%{_includedir}/tizen-action/tizen_action.h
+%{_includedir}/tizen-action/action.h
+%{_includedir}/tizen-action/action_error.h
%{_libdir}/pkgconfig/capi-appfw-tizen-action.pc
%files tool
action.Settype(ActionModelConverter().ActionTypeToString(schema.GetType()));
// action.Setparameters();
// action.Setprivileges();
+ action.Setjson(schema.GetJsonString());
actions.push_back(action);
}
return actions;
rpc::ActionSchema ActionRequestHandler::OnGetAction(const std::string& id) {
auto db = std::make_unique<action::SqliteDb>();
std::string json_str = db->GetAction(id);
- common::ActionSchema schema(json_str);
+ common::ActionSchema schema(std::move(json_str));
rpc::ActionSchema action;
action.Setaction_id(schema.GetActionId());
actionparams.push_back(param);
}
- action.Setparameters(actionparams);
+ action.Setparameters(std::move(actionparams));
action.Setprivileges(schema.GetPrivileges());
+ action.Setjson(schema.GetJsonString());
+
return action;
}
uid_t uid, rpc::ActionModel& action) {
auto db = std::make_unique<action::SqliteDb>();
std::string schema_json = db->GetAction(action.Getaction_id());
- if (!ActionValidator().CheckModelValid(schema_json, action.Getjson()))
+ if (!ActionValidator().CheckModelValid(schema_json, action.Getjson())) {
+ LOG(DEBUG) << "OnExecute not valid : " << action.Getaction_id();
return;
+ }
try {
- common::ActionSchema schema(schema_json);
+ common::ActionSchema schema(std::move(schema_json));
LOG(DEBUG) << "OnExecute action : " << schema.GetActionId();
common::ActionModel model(action.Getjson());
}
std::vector<rpc::ActionSchema> Service::ListActions() {
+ LOG(DEBUG) << "ListActions";
return handler_.OnListActions();
}
rpc::ActionSchema Service::GetAction(std::string action_id) {
+ LOG(DEBUG) << "GetAction : " << action_id;
return handler_.OnGetAction(action_id);
}
CONFIGURE_FILE(capi-appfw-tizen-action.pc.in capi-appfw-tizen-action.pc @ONLY)
INSTALL(FILES capi-appfw-tizen-action.pc DESTINATION ${LIB_INSTALL_DIR}/pkgconfig)
-INSTALL(FILES tizen_action.h DESTINATION ${INCLUDEDIR}/tizen-action/)
+INSTALL(FILES action.h DESTINATION ${INCLUDEDIR}/tizen-action/)
+INSTALL(FILES action_error.h DESTINATION ${INCLUDEDIR}/tizen-action/)
INSTALL(TARGETS ${TARGET_TIZEN_ACTION_API} DESTINATION ${LIB_INSTALL_DIR})
--- /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 API_ACTION_H_
+#define API_ACTION_H_
+
+#include "action_error.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/**
+ * @brief The action client handle.
+ */
+typedef void* action_client_h;
+
+/**
+ * @brief The action handle.
+ */
+typedef void* action_h;
+
+/**
+ * @brief Called for each available action.
+ * @param[in] action The action handle.
+ * @param[in] user_data The user data passed from the foreach function.
+ * @return @c true to continue with the next iteration of the loop,
+ * otherwise @c false to break out of the loop.
+ * @see tizen_action_foreach_action()
+ */
+typedef bool (*action_foreach_action_cb)(const action_h action, void *user_data);
+
+/**
+ * @brief Called when the action is executed.
+ * @param[in] execution_id The ID of the action execution.
+ * @param[in] json_result The result of the action execution.
+ * @param[in] user_data The user data passed from the callback registration function.
+ * @return @c true to continue with the next iteration of the loop,
+ * otherwise @c false to break out of the loop.
+ * @see tizen_action_execute_action()
+ */
+typedef bool (*action_result_cb)(int execution_id, const char *json_result, void *user_data);
+
+/**
+ * @brief Creates a action client handle.
+ * @param[out] client The action handle.
+ * @retval #ACTION_ERROR_NONE Successful
+ * @retval #ACTION_ERROR_INVALID_PARAMETER Invalid parameter
+ */
+int action_client_create(action_client_h *client);
+
+/**
+ * @brief Destroys the action client handle.
+ * @param[in] action The action handle.
+ * @retval #ACTION_ERROR_NONE Successful
+ * @retval #ACTION_ERROR_INVALID_PARAMETER Invalid parameter
+ */
+int action_client_destroy(action_client_h client);
+
+/**
+ * @brief Retrieves all actions.
+ * @param[in] client The action client handle.
+ * @param[in] cb The callback function to get each action.
+ * @param[in] user_data The user data to be passed to the callback function.
+ * @retval #ACTION_ERROR_NONE Successful
+ * @retval #ACTION_ERROR_INVALID_PARAMETER Invalid parameter
+ */
+int action_client_foreach_action(action_client_h client, action_foreach_action_cb cb, void *user_data);
+
+/**
+ * @brief Gets the action handle
+ * @param[in] client The action client handle.
+ * @param[in] name The name of action.
+ * @param[in] action The action handle.
+ * @retval #ACTION_ERROR_NONE Successful
+ * @retval #ACTION_ERROR_INVALID_PARAMETER Invalid parameter
+ */
+int action_client_get_action(action_client_h client, const char *name, action_h *action);
+
+/**
+ * @brief Executes the action.
+ * @param[in] action The action handle.
+ * @param[in] param The parameter to execute the action.
+ * @param[in] cb The callback function to be invoked when the action is executed.
+ * @param[in] user_data The user data to be passed to the callback function.
+ * @param[out] execution_id The ID of the action execution. It should be released using free().
+ * @retval #ACTION_ERROR_NONE Successful
+ * @retval #ACTION_ERROR_INVALID_PARAMETER Invalid parameter
+ */
+int action_client_execute(action_client_h client, const char *param, action_result_cb cb, void *user_data, int *execution_id);
+
+/**
+ * @brief Gets the name of the action.
+ * @remarks If you no longer use @name, you must release it using free().
+ * @param[in] action The action handle.
+ * @param[out] name The name of the action.
+ * @retval #ACTION_ERROR_NONE Successful
+ * @retval #ACTION_ERROR_INVALID_PARAMETER Invalid parameter
+ */
+int action_get_name(action_h action, const char **name);
+
+/**
+ * @brief Gets the schema of the action.
+ * @remarks If you no longer use @schema, you must release it using free().
+ * @param[in] action The action handle.
+ * @param[out] json_schema The schema of the action.
+ * @retval #ACTION_ERROR_NONE Successful
+ * @retval #ACTION_ERROR_INVALID_PARAMETER Invalid parameter
+ */
+int action_get_schema(action_h action, const char **json_schema);
+
+/**
+ * @brief Destroys the action handle.
+ * @param[in] action The action handle.
+ * @retval #ACTION_ERROR_NONE Successful
+ * @retval #ACTION_ERROR_INVALID_PARAMETER Invalid parameter
+ */
+int action_destroy(action_h action);
+
+
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif // API_ACTION_H_
\ No newline at end of file
--- /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 API_ACTION_ERROR_H_
+#define API_ACTION_ERROR_H_
+
+#include <tizen.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/**
+ * @brief Enumeration for action framework errors.
+ * @since_tizen 10.0
+ */
+typedef enum _action_error {
+ ACTION_ERROR_NONE = TIZEN_ERROR_NONE, /**< Success */
+ ACTION_ERROR_INVALID_PARAMETER = TIZEN_ERROR_INVALID_PARAMETER, /**< Invalid parameter */
+ ACTION_ERROR_OUT_OF_MEMORY = TIZEN_ERROR_OUT_OF_MEMORY, /**< Out of memory */
+ ACTION_ERROR_IO_ERROR = TIZEN_ERROR_IO_ERROR, /**< I/O error */
+ ACTION_ERROR_PERMISSION_DENIED = TIZEN_ERROR_PERMISSION_DENIED, /**< Permission denied */
+ ACTION_ERROR_INVALID_OPERATION = TIZEN_ERROR_INVALID_OPERATION, /**< Function not implemented */
+ ACTION_ERROR_FROM_DB = TIZEN_ERROR_NOTIFICATION | 0x01, /**< Error from DB query */
+ ACTION_ERROR_ALREADY_EXIST_ID = TIZEN_ERROR_NOTIFICATION | 0x02, /**< Already exist private ID */
+ ACTION_ERROR_NOT_EXIST_ID = TIZEN_ERROR_NOTIFICATION | 0x03, /**< Not exist ID */
+ ACTION_ERROR_SERVICE_NOT_READY = TIZEN_ERROR_NOTIFICATION | 0x04, /**< No response from action framework service */
+} action_error_e;
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif // API_ACTION_ERROR_H_
* limitations under the License.
*/
-#include "api/tizen_action.h"
+#include "api/action.h"
-#include "api/tizen_action_service_proxy.h"
+#include "connector.hh"
+#include "common/action_model.h"
+#include "common/action_schema.h"
+#include "common/action_parameter.h"
+#include "common/utils/logging.hh"
#ifdef API
#undef API
namespace {
-} // namespace
+class Reply : public api::rpc::proxy::ActionService::ActionReplyCb {
+ public:
+ Reply(action_result_cb cb, void* user_data)
+ : cb_(cb), user_data_(user_data) {}
-API int tizen_action_get_action(const char* name, tizen_action_h* action) {
- return 0;
+ void OnReceived(std::string result) {
+ LOG(WARNING) << "@@@ reply OnReceived : " << result;
+
+ cb_(100, result.c_str(), user_data_);
+ }
+
+ private:
+ action_result_cb cb_;
+ void* user_data_;
+};
+
+class ActionClient {
+ public:
+ ActionClient(std::unique_ptr<api::Connector> connector)
+ : connector_(std::move(connector)) {}
+
+ api::rpc::ActionSchema GetAction(std::string name) {
+ LOG(WARNING) << "ActionClient GetAction";
+
+ auto* conn = connector_->GetConnection();
+ if (conn == nullptr) {
+ LOG(WARNING) << "get action conn null";
+ throw std::invalid_argument("connection is nullptr");
+ }
+
+ auto action_schema = conn->GetAction(name);
+
+ return action_schema;
+ }
+
+ std::vector<api::rpc::ActionSchema> ListActions() {
+ LOG(WARNING) << "ActionClient ListActions";
+
+ auto* conn = connector_->GetConnection();
+ if (conn == nullptr) {
+ LOG(WARNING) << "foreach action conn null";
+ throw std::invalid_argument("connection is nullptr");
+ }
+
+ auto actions = conn->ListActions();
+
+ return actions;
+ };
+
+ int Execute(std::string param, action_result_cb cb, void* user_data) {
+ LOG(WARNING) << "ActionClient Execute";
+
+ auto* conn = connector_->GetConnection();
+ if (conn == nullptr) {
+ LOG(WARNING) << "get action conn null";
+ throw std::invalid_argument("connection is nullptr");
+ }
+
+ common::ActionModel model_(std::move(param));
+ api::rpc::ActionModel action;
+ action.Setaction_id(model_.GetId());
+ action.Setjson(model_.GetJson());
+
+ cb_id_ = conn->RegisterActionReplyCb(std::make_unique<Reply>(cb, user_data));
+ int ret = conn->Execute(action);
+
+ LOG(WARNING) << "execute cb : " << std::to_string(cb_id_) << ", ret : " << std::to_string(ret);
+
+ return ret;
+ }
+
+ void Dispose() {
+ LOG(WARNING) << "ActionClient Dispose";
+
+ if (cb_id_ > 0) {
+ auto* conn = connector_->GetConnection();
+
+ if (conn == nullptr) {
+ LOG(WARNING) << "get action conn null";
+ throw std::invalid_argument("connection is nullptr");
+ }
+
+ conn->UnregisterActionReplyCb(cb_id_);
+ }
+ }
+
+ private:
+ std::unique_ptr<api::Connector> connector_;
+ int cb_id_ = -1;
+};
+
+}
+
+API int action_client_create(action_client_h* client) {
+ LOG(WARNING) << "action_client_create";
+
+ if (client == nullptr) {
+ LOG(WARNING) << "Invalid Parameter";
+ return ACTION_ERROR_INVALID_PARAMETER;
+ }
+
+ auto connector = std::make_unique<api::Connector>();
+ ActionClient* client_ = new (std::nothrow) ActionClient(std::move(connector));
+ if (client_ == nullptr) {
+ LOG(WARNING) << "Out-of-memory";
+ return ACTION_ERROR_OUT_OF_MEMORY;
+ }
+
+ *client = static_cast<action_client_h>(client_);
+
+ return ACTION_ERROR_NONE;
+}
+
+API int action_client_destroy(action_client_h client) {
+ LOG(WARNING) << "action_client_destroy";
+
+ if (client == nullptr) {
+ LOG(WARNING) << "Invalid Parameter";
+ return ACTION_ERROR_INVALID_PARAMETER;
+ }
+
+ ActionClient* client_ = static_cast<ActionClient*>(client);
+ client_->Dispose();
+ delete client_;
+
+ return ACTION_ERROR_NONE;
+}
+
+API int action_client_get_action(action_client_h client,
+ const char* name, action_h* action) {
+ LOG(WARNING) << "action_client_get_action";
+
+ if (client == nullptr || name == nullptr || action == nullptr) {
+ LOG(WARNING) << "Invalid Parameter";
+ return ACTION_ERROR_INVALID_PARAMETER;
+ }
+
+ ActionClient* client_ = static_cast<ActionClient*>(client);
+ try {
+ auto action_schema = client_->GetAction(name);
+
+ common::ActionSchema* schema = new (std::nothrow) common::ActionSchema(action_schema.Getjson());
+
+ *action = static_cast<action_h>(schema);
+ } catch (...) {
+ LOG(WARNING) << "get action exception";
+ return -1;
+ }
+
+ return ACTION_ERROR_NONE;
+}
+
+API int action_client_foreach_action(action_client_h client,
+ action_foreach_action_cb cb, void* user_data) {
+ LOG(WARNING) << "action_client_foreach_action";
+
+ if (client == nullptr || cb == nullptr) {
+ LOG(WARNING) << "Invalid Parameter";
+ return ACTION_ERROR_INVALID_PARAMETER;
+ }
+
+ ActionClient* client_ = static_cast<ActionClient*>(client);
+ try {
+ auto actions = client_->ListActions();
+
+ for (auto action : actions) {
+ common::ActionSchema schema(action.Getjson());
+
+ if (!cb(static_cast<action_h>(&schema), user_data)) {
+ LOG(WARNING) << "callback returns false";
+ break;
+ }
+ }
+ } catch (...) {
+ LOG(WARNING) << "exception foreach action";
+ return -1;
+ }
+
+ return ACTION_ERROR_NONE;
}
-API int tizen_action_destroy_action(tizen_action_h action) {
- return 0;
+API int action_client_execute(action_client_h client, const char* param,
+ action_result_cb cb, void* user_data, int* execution_id) {
+ LOG(WARNING) << "action_client_execute";
+ if (client == nullptr || param == nullptr) {
+ LOG(WARNING) << "Invalid Parameter";
+ return ACTION_ERROR_INVALID_PARAMETER;
+ }
+
+ ActionClient* client_ = static_cast<ActionClient*>(client);
+ try {
+ client_->Execute(param, cb, user_data);
+ } catch (...) {
+ LOG(WARNING) << "execute exception3";
+ return -1;
+ }
+
+ return ACTION_ERROR_NONE;
}
-API int tizen_action_foreach_actions(tizen_action_foreach_action_cb cb,
- void* user_data) {
- return 0;
+API int action_get_name(action_h action, const char** name) {
+ LOG(WARNING) << "action_get_name";
+ if (action == nullptr || name == nullptr) {
+ LOG(WARNING) << "Invalid Parameter";
+ return ACTION_ERROR_INVALID_PARAMETER;
+ }
+
+ common::ActionSchema* action_schema = static_cast<common::ActionSchema*>(action);
+ *name = strdup(action_schema->GetActionId().c_str());
+
+ return ACTION_ERROR_NONE;
}
-API int tizen_action_execute_action(tizen_action_h action, const char* param,
- tizen_action_reply_cb cb, void* user_data, char** execution_id) {
- return 0;
+API int action_get_schema(action_h action, const char** json_schema) {
+ LOG(WARNING) << "action_get_schema";
+ if (action == nullptr || json_schema == nullptr) {
+ LOG(WARNING) << "Invalid Parameter";
+ return ACTION_ERROR_INVALID_PARAMETER;
+ }
+
+ common::ActionSchema* action_schema = static_cast<common::ActionSchema*>(action);
+ *json_schema = strdup(action_schema->GetJsonString().c_str());
+
+ return ACTION_ERROR_NONE;
}
-API int tizen_action_get_name(tizen_action_h action, const char** name) {
- return 0;
+API int action_destroy(action_h action) {
+ LOG(WARNING) << "action_destroy";
+ if (action == nullptr) {
+ LOG(WARNING) << "Invalid Parameter";
+ return ACTION_ERROR_INVALID_PARAMETER;
+ }
+
+ common::ActionSchema* action_schema = static_cast<common::ActionSchema*>(action);
+ delete action_schema;
+
+ return ACTION_ERROR_NONE;
}
--- /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 "connector.hh"
+#include "common/utils/logging.hh"
+
+namespace {
+
+constexpr const char kStubAppId[] = "org.tizen.action-framework.service";
+
+}
+
+namespace api {
+
+Connector::Connector() {}
+Connector::~Connector() {
+ LOG(ERROR) << "Connect dtor";
+ Disconnect();
+}
+
+bool Connector::Connect(bool sync) {
+ LOG(ERROR) << "Connect";
+ if (!proxy_) {
+ LOG(ERROR) << "new proxy";
+ proxy_.reset(new rpc::proxy::ActionService(this, kStubAppId));
+ }
+
+ if (connected_) {
+ LOG(ERROR) << "already Connected";
+ return true;
+ }
+
+ try {
+ proxy_->Connect(sync);
+ } catch (const rpc::proxy::InvalidIDException& e) {
+ LOG(ERROR) << "InvalidIDException";
+ return false;
+ } catch (const rpc::proxy::InvalidIOException& e) {
+ LOG(ERROR) << "InvalidIOException";
+ return false;
+ } catch (const rpc::proxy::PermissionDeniedException& e) {
+ LOG(ERROR) << "PermissionDeniedException";
+ return false;
+ } catch (...) {
+ LOG(ERROR) << "Unknown exception";
+ return false;
+ }
+ LOG(ERROR) << "Connected";
+
+ return true;
+}
+
+void Connector::Disconnect() {
+ LOG(ERROR) << "Disconnect";
+
+ if (connected_) {
+ proxy_->Disconnect();
+ }
+}
+
+void Connector::OnConnected() {
+ connected_ = true;
+ LOG(WARNING) << "connected";
+}
+
+void Connector::OnDisconnected() {
+ connected_ = false;
+ LOG(WARNING) << "disconnected";
+}
+
+void Connector::OnRejected() {
+ connected_ = false;
+ LOG(WARNING) << "Rejected";
+}
+
+rpc::proxy::ActionService* Connector::GetConnection() {
+ if (!Connect(true))
+ return nullptr;
+
+ return proxy_.get();
+}
+
+} // namespace
--- /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 API_CONNECTOR_HH_
+#define API_CONNECTOR_HH_
+
+#include "action.h"
+#include "tizen_action_service_proxy.h"
+
+namespace api {
+
+namespace rpc = rpc_port::tizen_action_service_proxy;
+
+class Connector : public rpc::proxy::ActionService::IEventListener {
+ public:
+ Connector();
+ virtual ~Connector();
+
+ rpc::proxy::ActionService* GetConnection();
+ void OnConnected() override;
+ void OnDisconnected() override;
+ void OnRejected() override;
+
+ private:
+ bool Connect(bool sync);
+ void Disconnect();
+
+ std::unique_ptr<rpc::proxy::ActionService> proxy_;
+ bool connected_ = false;
+};
+
+} // namespace api
+
+#endif // API_CONNECTOR_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 API_TIZEN_ACTION_H_
-#define API_TIZEN_ACTION_H_
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-/**
- * @brief The action handle.
- */
-typedef void* tizen_action_h;
-
-/**
- * @brief The action result handle.
- */
-typedef void* tizen_action_result_h;
-
-/**
- * @brief Called for each available action.
- * @param[in] action The action handle.
- * @param[in] user_data The user data passed from the foreach function.
- * @return @c true to continue with the next iteration of the loop,
- * otherwise @c false to break out of the loop.
- * @see tizen_action_foreach_action()
- */
-typedef bool (*tizen_action_foreach_action_cb)(const tizen_action_h action, void* user_data);
-
-/**
- * @brief Called when the action is executed.
- * @param[in] execution_id The ID of the action execution.
- * @param[in] result The result of the action execution.
- * @param[in] user_data The user data passed from the callback registration function.
- * @return @c true to continue with the next iteration of the loop,
- * otherwise @c false to break out of the loop.
- * @see tizen_action_execute_action()
- */
-typedef bool (*tizen_action_reply_cb)(const char* execution_id, tizen_action_result_h result, void* user_data);
-
-/**
- * @brief Creates a action handle.
- * @param[out] action The action handle.
- * @retval #TIZEN_ACTION_ERROR_NONE Successful
- * @retval #TIZEN_ACTION_ERROR_INVALID_PARAMETER Invalid parameter
- */
-int tizen_action_get_action(const char* name, tizen_action_h* action);
-
-/**
- * @brief Destroys the action handle.
- * @param[in] action The action handle.
- * @retval #TIZEN_ACTION_ERROR_NONE Successful
- * @retval #TIZEN_ACTION_ERROR_INVALID_PARAMETER Invalid parameter
- */
-int tizen_action_destroy_action(tizen_action_h action);
-
-/**
- * @brief Retrieves all actions.
- * @param[in] cb The callback function to get each action.
- * @param[in] user_data The user data to be passed to the callback function.
- * @retval #TIZEN_ACTION_ERROR_NONE Successful
- * @retval #TIZEN_ACTION_ERROR_INVALID_PARAMETER Invalid parameter
- */
-int tizen_action_foreach_action(tizen_action_foreach_action_cb cb, void* user_data);
-
-/**
- * @brief Executes the action.
- * @param[in] action The action handle.
- * @param[in] param The parameter to execute the action.
- * @param[in] cb The callback function to be invoked when the action is executed.
- * @param[in] user_data The user data to be passed to the callback function.
- * @param[out] execution_id The ID of the action execution. It should be released using free().
- * @retval #TIZEN_ACTION_ERROR_NONE Successful
- * @retval #TIZEN_ACTION_ERROR_INVALID_PARAMETER Invalid parameter
- */
-int tizen_action_execute_action(tizen_action_h action, const char* param, tizen_action_reply_cb cb, void* user_data, char** execution_id);
-
-/**
- * @brief Gets the name of the action.
- * @remarks If you no longer use @name, you must release it using free().
- * @param[in] action The action handle.
- * @param[out] name The name of the action.
- * @retval #TIZEN_ACTION_ERROR_NONE Successful
- * @retval #TIZEN_ACTION_ERROR_INVALID_PARAMETER Invalid parameter
- */
-int tizen_action_get_name(tizen_action_h action, char** name);
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif // API_TIZEN_ACTION_H_
\ No newline at end of file
ActionModel::ActionModel(std::string json_str)
: json_str_(std::move(json_str)) {
- SafeJson root(json_str_);
- action_id_ = root.get<std::string>("name");
- for (auto& [key, item] : root.members("params")) {
- std::string value = item->GetString();
- parameters_.emplace_back(key, std::move(value));
+ try {
+ SafeJson root(json_str_);
+ action_id_ = root.get<std::string>("name");
+ for (auto& [key, item] : root.members("params")) {
+ std::string value = item->GetString();
+ parameters_.emplace_back(key, std::move(value));
+ }
+ } catch (...) {
+ LOG(ERROR) << "ActionModel exception";
}
}
ActionSchema::ActionSchema() {}
-ActionSchema::ActionSchema(const std::string& json_str) {
+ActionSchema::ActionSchema(std::string json_str)
+ : json_str_(std::move(json_str)) {
try {
- SafeJson root(json_str);
+ SafeJson root(json_str_);
action_id_ = root.get<std::string>("name");
try {
category_ = root.get<std::string>("category");
std::string category,
std::string description,
std::vector<ActionParameter> parameters,
- std::vector<std::string> privileges)
+ std::vector<std::string> privileges,
+ std::string json_str)
: action_id_(std::move(action_id)),
appid_(std::move(appid)),
category_(std::move(category)),
description_(std::move(description)),
parameters_(std::move(parameters)),
- privileges_(std::move(privileges)) {}
+ privileges_(std::move(privileges)),
+ json_str_(std::move(json_str)) {}
const std::string& ActionSchema::GetActionId() const {
return action_id_;
privileges_ = std::move(privileges);
}
+const std::string& ActionSchema::GetJsonString() const {
+ return json_str_;
+}
+
+void ActionSchema::SetJsonString(std::string json_str) {
+ json_str_ = std::move(json_str);
+}
+
} // namespace common
class ActionSchema {
public:
ActionSchema();
- explicit ActionSchema(const std::string& json_str);
+ explicit ActionSchema(std::string json_str);
explicit ActionSchema(std::string action_id, std::string appid,
std::string category, std::string description,
std::vector<ActionParameter> parameters,
- std::vector<std::string> privileges);
+ std::vector<std::string> privileges,
+ std::string json_str);
const std::string& GetActionId() const;
void SetActionId(std::string action_id);
const std::vector<std::string>& GetPrivileges() const;
void SetPrivileges(std::vector<std::string> privileges);
+ const std::string& GetJsonString() const;
+ void SetJsonString(std::string app_id);
+
private:
std::string action_id_;
std::string appid_;
// std::vector<Result> results_;
std::vector<std::string> privileges_;
+
+ std::string json_str_;
};
} // namespace common