SET(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_CURRENT_SOURCE_DIR}/cmake/Modules/")
## Targets
+SET(TARGET_TIZEN_ACTION "tizen-action")
SET(TARGET_TIZEN_ACTION_COMMON "tizen-action-common")
SET(TARGET_TIZEN_ACTION_PLUGIN "tizen-action-plugin")
SET(TARGET_TIZEN_ACTION_SERVICE "tizen-action-service")
+++ /dev/null
-#!/bin/bash
-
-# generate tidl code
-/bin/bash tidl/prebuild.sh
-
-# build service app
-cd src/service
-/bin/bash build.sh
+ADD_SUBDIRECTORY(action)
ADD_SUBDIRECTORY(common)
ADD_SUBDIRECTORY(pkgmgr_plugin_parser)
ADD_SUBDIRECTORY(service)
--- /dev/null
+AUX_SOURCE_DIRECTORY(${CMAKE_CURRENT_SOURCE_DIR} ACTION_SRCS)
+AUX_SOURCE_DIRECTORY(${CMAKE_CURRENT_SOURCE_DIR}/utils ACTION_UTILS_SRCS)
+ADD_LIBRARY(${TARGET_TIZEN_ACTION} ${ACTION_SRCS} ${ACTION_UTILS_SRCS})
+
+TARGET_INCLUDE_DIRECTORIES(${TARGET_TIZEN_ACTION} PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/../../)
+
+APPLY_PKG_CONFIG(${TARGET_TIZEN_ACTION} PUBLIC
+ CAPI_APPFW_APP_COMMON_DEPS
+ CAPI_APPFW_APP_MANAGER_DEPS
+ CAPI_APPFW_PACKAGE_MANAGER_DEPS
+ CAPI_APPFW_SERVICE_APPLICATION_DEPS
+ DLOG_DEPS
+ GLIB_DEPS
+ TIZEN_DATABASE_DEPS
+ RPC_PORT_DEPS
+)
+
+TARGET_LINK_LIBRARIES(${TARGET_TIZEN_ACTION} PRIVATE ${TARGET_TIZEN_ACTION_COMMON})
+
+INSTALL(TARGETS ${TARGET_TIZEN_ACTION} 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 COMMON_ACTION_LOADER_HH_
+#define COMMON_ACTION_LOADER_HH_
+
+namespace common {
+
+class IActionLoader {
+ public:
+ virtual ~IActionLoader() = default;
+ virtual void ListActions() = 0;
+ virtual void GetAction(const std::string& name) = 0;
+};
+
+} // namespace common
+
+#endif // COMMON_ACTION_LOADER_HH_
--- /dev/null
+/*
+ * Copyright (c) 2024 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 <string>
+
+#include "action_request_handler.h"
+#include "service.h"
+
+#include "action/sqlite_db.hh"
+
+namespace service {
+
+ActionRequestHandler::ActionRequestHandler() {
+}
+
+ActionRequestHandler::~ActionRequestHandler() {
+}
+
+void ActionRequestHandler::Init() {
+ service_.Listen(std::make_shared<service::Service::Factory>(*this));
+}
+
+void ActionRequestHandler::OnListActions() {
+ // TODO: db as member variable?
+ auto db = std::make_unique<common::SqliteDb>();
+ db->ListActions();
+}
+
+void ActionRequestHandler::OnGetAction(std::string id) {
+ auto db = std::make_unique<common::SqliteDb>();
+ db->GetAction(id);
+}
+
+void ActionRequestHandler::OnGetActionId(std::string user_description, int top_k,
+ float search_threshold) {
+}
+
+void ActionRequestHandler::OnExecute(std::string launch_req) {
+
+}
+
+} // namespace service
--- /dev/null
+/*
+ * Copyright (c) 2024 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 SRC_ACTION_MANAGER_H_
+#define SRC_ACTION_MANAGER_H_
+
+#include <vector>
+
+#include "irequest_handler.h"
+#include "tizen_action_service_stub.h"
+
+using Action = rpc_port::tizen_action_service_stub::Action;
+
+namespace service {
+
+class ActionRequestHandler : public IRequestHandler {
+ public:
+ ActionRequestHandler();
+ ~ActionRequestHandler();
+ void Init();
+
+ void OnListActions() override;
+ void OnGetAction(std::string id) override;
+ void OnGetActionId(std::string user_description, int top_k,
+ float search_threshold) override;
+ void OnExecute(std::string request) override;
+
+ private:
+ rpc_port::tizen_action_service_stub::stub::ActionService service_;
+};
+
+} // namespace service
+
+#endif // SRC_ACTION_MANAGER_H_
--- /dev/null
+/*
+ * Copyright (c) 2024 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 SRC_IREQUEST_HANDLER_H_
+#define SRC_IREQUEST_HANDLER_H_
+
+#include <string>
+
+namespace service {
+
+class IRequestHandler {
+ public:
+ virtual ~IRequestHandler() = default;
+ virtual void OnListActions() = 0;
+ virtual void OnGetAction(std::string id) = 0;
+ virtual void OnGetActionId(std::string user_description, int top_k,
+ float search_threshold) = 0;
+ virtual void OnExecute(std::string launch_req) = 0;
+};
+
+} // namespace service
+
+#endif // SRC_IREQUEST_HANDLER_H_
--- /dev/null
+/*
+ * Copyright (c) 2024 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 "irequest_handler.h"
+#include "service.h"
+#include "utils/logging.h"
+
+#include "utils/sqlite_db.h"
+#include "utils/json_parser.h"
+
+namespace service {
+
+Service::Service(std::string sender, std::string instance,
+ IRequestHandler& handler)
+ : rs::stub::ActionService::ServiceBase(std::move(sender),
+ std::move(instance)), handler_(handler) {
+}
+
+Service::~Service() {
+}
+
+std::vector<rs::Action> Service::ListActions() {
+ // return list of actions from db
+ // handler_->ListActions();
+ return {};
+}
+
+rs::Action Service::GetAction(std::string action_id) {
+ // return action by id
+ // handler_->GetAction(action_id);
+ LOG(DEBUG) << "GetAction : " << action_id;
+
+ std::string result;
+ utils::SqliteDb sqlite_db;
+
+ sqlite_db.Select(action_id, result);
+
+ LOG(DEBUG) << "GetAction result : " << result;
+
+ auto ps = new utils::JsonParser(result);
+
+ auto params = ps->GetParameters();
+
+ rs::Action action;
+ std::vector<rs::Parameter> actionparams;
+
+ action.Setapp_id(ps->GetAppId());
+ action.Setaction_id(ps->GetName());
+ action.Setlabel(ps->GetName());
+ action.Setdescription(ps->GetDescription());
+
+ for (auto const& iter : params) {
+ auto param_value = iter.second;
+
+ auto param = rs::Parameter(iter.first, param_value["type"], param_value["desc"],
+ param_value["isMandatory"].compare("true") == 0 ? true : false);
+
+ actionparams.push_back(param);
+ }
+
+ action.Setparameters(actionparams);
+
+ LOG(DEBUG) << "appid : " << action.Getapp_id();
+ LOG(DEBUG) << "actionid : " << action.Getaction_id();
+
+ // return {};
+ return action;
+}
+
+std::vector<rs::VectorDbResult> Service::GetActionId(
+ std::string user_description, int top_k, float search_threshold) {
+ // return result from db
+ // handler_->GetActionId(user_description, top_k, search_threshold);
+ return {};
+}
+
+int Service::Execute(std::string launch_req) {
+ // return action exetution result
+ // handler_->Execute(std::move(launch_req));
+ return 0;
+}
+
+} // namespace service
--- /dev/null
+/*
+ * Copyright (c) 2024 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 SRC_SERVICE_H_
+#define SRC_SERVICE_H_
+
+#include <memory>
+#include <string>
+#include <vector>
+
+#include "irequest_handler.h"
+#include "tizen_action_service_stub.h"
+
+namespace service {
+
+namespace rs = rpc_port::tizen_action_service_stub;
+
+class Service : public rs::stub::ActionService::ServiceBase {
+ public:
+ class Factory : public rs::stub::ActionService::ServiceBase::Factory {
+ public:
+ Factory(IRequestHandler& handler) : handler_(handler) {}
+ virtual ~Factory() = default;
+ std::unique_ptr<rs::stub::ActionService::ServiceBase> CreateService(
+ std::string sender, std::string instance) override {
+ return std::make_unique<Service>(sender, instance, handler_);
+ }
+
+ private:
+ IRequestHandler& handler_;
+ };
+
+ Service(std::string sender, std::string instance, IRequestHandler& handler);
+ ~Service();
+
+ void OnCreate() override {}
+ void OnTerminate() override {}
+ std::vector<rs::Action> ListActions() override;
+ rs::Action GetAction(std::string action_id) override;
+ std::vector<rs::VectorDbResult> GetActionId(std::string user_description,
+ int top_k, float search_threshold) override;
+ int Execute(std::string launch_req) override;
+
+ private:
+ IRequestHandler& handler_;
+};
+
+} // namespace service
+
+#endif // SRC_SERVICE_H_
--- /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/sqlite_db.hh"
+
+#include <database.hpp>
+
+#include "common/utils/logging.hh"
+
+namespace {
+
+constexpr char kDbPath[] = "/opt/dbspace/.tizen_action.db";
+constexpr char kGetActionQuery[] =
+ "SELECT pkgid, action_name, json_str FROM action WHERE name = ?";
+constexpr char kListActionQuery[] =
+ "SELECT json_str FROM action;";
+
+} // namespace
+
+namespace common {
+
+// TODO: check smack label of db file
+SqliteDb::SqliteDb() : conn_(kDbPath, SQLITE_OPEN_READONLY) {
+}
+
+void SqliteDb::ListActions() {
+ // TODO
+ Select();
+}
+
+void SqliteDb::GetAction(const std::string& name) {
+ // TODO
+ Select(name);
+}
+
+void SqliteDb::Select(const std::string& name) {
+ auto q = std::move(tizen_base::Database::Sql(kGetActionQuery)
+ .Bind(name));
+ auto r = conn_.Exec(q);
+ if (!static_cast<bool>(r)) {
+ LOG(ERROR) << "Failed to execute select query: "
+ << static_cast<const char*>(r);
+ return;
+ }
+
+ auto rec = r.GetFirstRecord();
+ if (!rec) {
+ LOG(ERROR) << "No record found";
+ return;
+ }
+
+ auto [pkgid, action_name, json_str] =
+ (*rec).Get<tizen_base::_, tizen_base::_, tizen_base::_>();
+ LOG(DEBUG) << "pkgid: " << static_cast<std::string>(pkgid)
+ << ", name: " << static_cast<std::string>(action_name)
+ << ", json_str: " << static_cast<std::string>(json_str);
+}
+
+void SqliteDb::Select() {
+ auto q = tizen_base::Database::Sql(kListActionQuery);
+ auto r = conn_.Exec(q);
+ if (!static_cast<bool>(r)) {
+ LOG(ERROR) << "Failed to execute select query: "
+ << static_cast<const char*>(r);
+ return;
+ }
+
+ for (const auto& i : r) {
+ auto [pkgid, action_name, json_str] =
+ i.Get<tizen_base::_, tizen_base::_, tizen_base::_>();
+ LOG(DEBUG) << "pkgid: " << static_cast<std::string>(pkgid)
+ << ", name: " << static_cast<std::string>(action_name)
+ << ", json_str: " << static_cast<std::string>(json_str);
+ }
+}
+
+} // 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_SQLITE_DB_HH_
+#define COMMON_SQLITE_DB_HH_
+
+#include <database.hpp>
+
+#include <string>
+
+#include "action/action_loader.hh"
+
+namespace common {
+
+class SqliteDb : public IActionLoader {
+ public:
+ SqliteDb();
+ ~SqliteDb() = default;
+
+ void ListActions() override;
+ void GetAction(const std::string& name) override;
+
+ void Select();
+ void Select(const std::string& name);
+
+ private:
+ tizen_base::Database conn_;
+};
+
+} // namespace common
+
+#endif // COMMON_SQLITE_DB_HH_
\ 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.
+ */
+
+#include <stdexcept>
+
+#include "json_parser.h"
+
+#include "logging.h"
+
+namespace utils {
+
+JsonParser::JsonParser(std::string json_str)
+ : json_str_(json_str) {
+ LOG(DEBUG) << "ParseStr const";
+
+ std::size_t pos = 0;
+ std::size_t lpos = 0;
+ std::string params;
+
+ // remove {}
+ pos = json_str_.find("{");
+ lpos = json_str_.rfind("}");
+ json_str_ = json_str_.substr(pos + 1, lpos - pos - 1);
+
+ // seperate params
+ pos = json_str_.find("{");
+ lpos = json_str_.rfind("}");
+ params = json_str_.substr(pos + 1, lpos - pos - 1);
+ json_str_.replace(pos + 1, lpos - pos - 1, " ");
+
+ // make nodes
+ while(true) {
+ pos = json_str_.find(",");
+
+ if (pos == std::string::npos)
+ break;
+
+ std::string sub_ = json_str_.substr(0, pos);
+ std::size_t spos = sub_.find(":");
+ std::string key = sub_.substr(1, spos - 2);
+ sub_ = sub_.substr(spos + 1);
+ std::string value = sub_.substr(1, sub_.length() - 2);
+
+ nodes_[key] = value;
+
+ // LOG(DEBUG) << key << " : " << value;
+
+ json_str_ = json_str_.substr(pos + 1);
+ }
+
+// LOG(DEBUG) << params;
+
+ std::size_t compos = 0;
+
+ // make params
+ while(true) {
+ pos = params.find("{");
+ lpos = params.find("}");
+
+ std::string key = params.substr(1, pos - 3);
+ std::string value = params.substr(pos + 1, lpos - pos - 1);
+
+ // LOG(DEBUG) << key << " : " << value;
+
+
+ std::size_t subpos = 0;
+ std::size_t nextpos = 0;
+ std::size_t compos_ = 0;
+ std::map<std::string, std::string> mvalue;
+
+ // make param value
+ while(true) {
+ // LOG(DEBUG) << value;
+
+ subpos = value.find("\"");
+ nextpos = value.find("\"", subpos + 1);
+
+ std::string subkey = value.substr(1, nextpos - 1);
+
+ subpos = value.find("\"", nextpos + 1);
+ nextpos = value.find("\"", subpos + 1);
+
+ std::string subval = value.substr(subpos + 1, nextpos - subpos - 1);
+
+ mvalue[subkey] = subval;
+
+ compos_ = value.find(",", nextpos);
+ if (compos_ == std::string::npos)
+ break;
+
+ value = value.substr(compos_ + 1);
+ }
+ params_[key] = mvalue;
+
+ compos = params.find(",", lpos);
+ if (compos == std::string::npos)
+ break;
+
+ params = params.substr(lpos + 2);
+ }
+
+ LOG(DEBUG) << "ParseStr const end";
+}
+
+std::string JsonParser::GetAppId() {
+ return nodes_["appId"];
+}
+
+std::string JsonParser::GetName() {
+ return nodes_["name"];
+}
+
+std::string JsonParser::GetDescription() {
+ return nodes_["desc"];
+}
+
+std::string JsonParser::GetType() {
+ return nodes_["type"];
+}
+
+std::string JsonParser::GetVersion() {
+ return nodes_["version"];
+}
+
+std::string JsonParser::GetRequiredPrivilege() {
+ return nodes_["required-privileges"];
+}
+
+std::string JsonParser::GetReturns() {
+ return nodes_["required-privileges"];
+}
+
+std::map<std::string, std::map<std::string, std::string>> JsonParser::GetParameters() {
+ return params_;
+}
+
+} // namespace utils
--- /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 JSON_PARSER_H_
+#define JSON_PARSER_H_
+
+// #include <json/json.h>
+
+#include <string>
+#include <map>
+
+namespace utils {
+
+/* temporary parser */
+/* need to be changed to use json */
+
+class JsonParser {
+ public:
+ JsonParser(std::string json_str);
+ ~JsonParser() = default;
+
+ std::string GetAppId();
+ std::string GetName();
+ std::string GetDescription();
+ std::string GetType();
+ std::string GetVersion();
+ std::string GetRequiredPrivilege();
+ std::string GetReturns();
+ std::map<std::string, std::map<std::string, std::string>> GetParameters();
+
+ private:
+ std::string json_str_;
+ std::map<std::string, std::string> nodes_;
+ std::map<std::string, std::map<std::string, std::string>> params_;
+};
+
+} // namespace utils
+
+#endif //
--- /dev/null
+// Copyright (c) 2024 Samsung Electronics Co., Ltd All Rights Reserved
+// Use of this source code is governed by a apache 2.0 license that can be
+// found in the LICENSE file.
+
+#include "action/utils/logging.h"
+
+namespace utils {
+
+log_priority LogLevelToPriority(LogLevel level) {
+ switch (level) {
+ case LogLevel::LOG_ERROR:
+ return log_priority::DLOG_ERROR;
+ case LogLevel::LOG_WARNING:
+ return log_priority::DLOG_WARN;
+ case LogLevel::LOG_INFO:
+ return log_priority::DLOG_INFO;
+ case LogLevel::LOG_DEBUG:
+ return log_priority::DLOG_DEBUG;
+ default:
+ return log_priority::DLOG_UNKNOWN;
+ }
+}
+
+} // namespace utils
--- /dev/null
+// Copyright (c) 2024 Samsung Electronics Co., Ltd All Rights Reserved
+// Use of this source code is governed by a apache 2.0 license that can be
+// found in the LICENSE file.
+
+#ifndef LOGGING_HH_
+#define LOGGING_HH_
+
+#include <dlog.h>
+
+#ifndef PROJECT_TAG
+#define PROJECT_TAG "TAF"
+#endif
+
+#ifdef LOG
+#undef LOG
+#endif
+
+#include <cassert>
+#include <cstring>
+#include <iomanip>
+#include <iostream>
+#include <sstream>
+#include <string>
+
+#ifndef __FILENAME__
+#define __FILENAME__ \
+ (strrchr(__FILE__, '/') ? strrchr(__FILE__, '/') + 1 : __FILE__)
+#endif
+
+namespace utils {
+
+enum class LogLevel {
+ LOG_ERROR,
+ LOG_WARNING,
+ LOG_INFO,
+ LOG_DEBUG,
+};
+
+log_priority LogLevelToPriority(LogLevel level);
+
+template <class charT, class traits = std::char_traits<charT>>
+class StringStream : private std::basic_ostringstream<charT, traits> {
+ public:
+ using std::basic_ostringstream<charT, traits>::str;
+
+ template <class T>
+ StringStream& operator<<(const T& value) {
+ static_cast<std::basic_ostringstream<charT, traits> &>(*this) << value;
+ return *this;
+ }
+};
+
+class LogCatcher {
+ public:
+ LogCatcher(LogLevel level, const char* tag)
+ : level_(level), tag_(tag) { }
+
+ void operator&(const StringStream<char>& str) const {
+ dlog_print(LogLevelToPriority(level_), tag_.c_str(), "%s",
+ Escape(str.str()).c_str());
+ }
+
+ private:
+ // Since LogCatcher passes input to dlog_print(), the input which contains
+ // format string(such as %d, %n) can cause unexpected result.
+ // This is simple function to escape '%'.
+ // NOTE: Is there any gorgeous way instead of this?
+ std::string Escape(const std::string& str) const {
+ std::string escaped = std::string(str);
+ size_t start_pos = 0;
+ std::string from = "%";
+ std::string to = "%%";
+ while ((start_pos = escaped.find(from, start_pos)) != std::string::npos) {
+ escaped.replace(start_pos, from.length(), to);
+ start_pos += to.length();
+ }
+ return escaped;
+ }
+ LogLevel level_;
+ std::string tag_;
+};
+
+} // namespace utils
+
+inline static const constexpr char* __tag_for_project() {
+ return PROJECT_TAG;
+}
+
+// Simple logging macro of following usage:
+// LOG(LEVEL) << object_1 << object_2 << object_n;
+// where:
+// LEVEL = ERROR | WARNING | INFO | DEBUG
+#define LOG(LEVEL) \
+ ::utils::LogCatcher( \
+ ::utils::LogLevel::LOG_ ## LEVEL, __tag_for_project()) \
+ & ::utils::StringStream<char>() \
+ << std::setw(50) << std::right \
+ << (std::string(__FILENAME__) + ": " + std::string(__FUNCTION__) + "(" + \
+ std::to_string(__LINE__) + ")").c_str() \
+ << std::setw(0) << " : " \
+
+#endif // LOGGING_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.
+ */
+
+#include "sqlite_db.h"
+
+#include "logging.h"
+
+namespace {
+
+constexpr char kDbPath[] = "/opt/dbspace/.tizen_action.db";
+constexpr char kSelectQuery[] =
+ "SELECT json_str FROM action WHERE action_name = ?";
+
+} // namespace
+
+namespace utils {
+
+bool SqliteDb::Select(std::string action_id, std::string& result) {
+ LOG(DEBUG) << "select : " << action_id;
+
+ int ret;
+ char *val;
+ sqlite3 *db;
+ sqlite3_stmt *stmt = nullptr;
+
+ ret = sqlite3_open_v2(kDbPath, &db, SQLITE_OPEN_READONLY, nullptr);
+ if (ret != SQLITE_OK) {
+ LOG(ERROR) << "failed to open db : " << kDbPath << " , : " << ret;
+ return false;
+ }
+
+ ret = sqlite3_prepare_v2(db, kSelectQuery, strlen(kSelectQuery), &stmt, nullptr);
+ if (ret != SQLITE_OK) {
+ LOG(ERROR) << "failed to prepare : " << ret;
+ return false;
+ }
+
+ sqlite3_bind_text(stmt, 1, action_id.c_str(), -1, SQLITE_STATIC);
+
+ ret = sqlite3_step(stmt);
+ if (ret != SQLITE_ROW) {
+ LOG(ERROR) << "failed to step : " << sqlite3_errmsg(db);
+ return false;
+ }
+
+ val = (char *)sqlite3_column_text(stmt, 0);
+ LOG(DEBUG) << "result : " << val;
+
+ result = val;
+
+ sqlite3_finalize(stmt);
+ sqlite3_close_v2(db);
+
+ return true;
+}
+
+} // namespace utils
--- /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 SQLITE_DB_H_
+#define SQLITE_DB_H_
+
+// #include <database.hpp>
+#include <sqlite3.h>
+
+#include <string>
+
+/* need to be changed to use cpp tizen-database */
+/* neec to be changed smack label for .tizen_action.db */
+
+namespace utils {
+
+class SqliteDb {
+ public:
+ SqliteDb() = default;
+ ~SqliteDb() = default;
+
+ bool Select(std::string action_id, std::string& result);
+
+};
+
+} // namespace utils
+
+#endif // SQLITE_DB_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 COMMON_ACTION_LOADER_HH_
-#define COMMON_ACTION_LOADER_HH_
-
-namespace common {
-
-class IActionLoader {
- public:
- virtual ~IActionLoader() = default;
- virtual void ListActions() = 0;
- virtual void GetAction(const std::string& name) = 0;
-};
-
-} // namespace common
-
-#endif // COMMON_ACTION_LOADER_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.
- */
-
-#include "common/sqlite_db.hh"
-
-#include <database.hpp>
-
-#include "common/utils/logging.hh"
-
-namespace {
-
-constexpr char kDbPath[] = "/opt/dbspace/.tizen_action.db";
-constexpr char kGetActionQuery[] =
- "SELECT pkgid, action_name, json_str FROM action WHERE name = ?";
-constexpr char kListActionQuery[] =
- "SELECT json_str FROM action;";
-
-} // namespace
-
-namespace common {
-
-// TODO: check smack label of db file
-SqliteDb::SqliteDb() : conn_(kDbPath, SQLITE_OPEN_READONLY) {
-}
-
-void SqliteDb::ListActions() {
- // TODO
- Select();
-}
-
-void SqliteDb::GetAction(const std::string& name) {
- // TODO
- Select(name);
-}
-
-void SqliteDb::Select(const std::string& name) {
- auto q = std::move(tizen_base::Database::Sql(kGetActionQuery)
- .Bind(name));
- auto r = conn_.Exec(q);
- if (!static_cast<bool>(r)) {
- LOG(ERROR) << "Failed to execute select query: "
- << static_cast<const char*>(r);
- return;
- }
-
- auto rec = r.GetFirstRecord();
- if (!rec) {
- LOG(ERROR) << "No record found";
- return;
- }
-
- auto [pkgid, action_name, json_str] =
- (*rec).Get<tizen_base::_, tizen_base::_, tizen_base::_>();
- LOG(DEBUG) << "pkgid: " << static_cast<std::string>(pkgid)
- << ", name: " << static_cast<std::string>(action_name)
- << ", json_str: " << static_cast<std::string>(json_str);
-}
-
-void SqliteDb::Select() {
- auto q = tizen_base::Database::Sql(kListActionQuery);
- auto r = conn_.Exec(q);
- if (!static_cast<bool>(r)) {
- LOG(ERROR) << "Failed to execute select query: "
- << static_cast<const char*>(r);
- return;
- }
-
- for (const auto& i : r) {
- auto [pkgid, action_name, json_str] =
- i.Get<tizen_base::_, tizen_base::_, tizen_base::_>();
- LOG(DEBUG) << "pkgid: " << static_cast<std::string>(pkgid)
- << ", name: " << static_cast<std::string>(action_name)
- << ", json_str: " << static_cast<std::string>(json_str);
- }
-}
-
-} // 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_SQLITE_DB_HH_
-#define COMMON_SQLITE_DB_HH_
-
-#include <database.hpp>
-
-#include <string>
-
-#include "common/action_loader.hh"
-
-namespace common {
-
-class SqliteDb : public IActionLoader {
- public:
- SqliteDb();
- ~SqliteDb() = default;
-
- void ListActions() override;
- void GetAction(const std::string& name) override;
-
- void Select();
- void Select(const std::string& name);
-
- private:
- tizen_base::Database conn_;
-};
-
-} // namespace common
-
-#endif // COMMON_SQLITE_DB_HH_
\ No newline at end of file
+++ /dev/null
-{
- global: main; _IO_*;
- local: *;
-};
-
+++ /dev/null
-<?xml version="1.0" encoding="UTF-8"?>
-<projectDescription>
- <name>TizenActionFrameworkService</name>
- <comment></comment>
- <projects>
- </projects>
- <buildSpec>
- <buildCommand>
- <name>org.eclipse.cdt.managedbuilder.core.genmakebuilder</name>
- <arguments>
- <dictionary>
- <key>?name?</key>
- <value></value>
- </dictionary>
- <dictionary>
- <key>org.eclipse.cdt.make.core.append_environment</key>
- <value>true</value>
- </dictionary>
- <dictionary>
- <key>org.eclipse.cdt.make.core.autoBuildTarget</key>
- <value>all</value>
- </dictionary>
- <dictionary>
- <key>org.eclipse.cdt.make.core.buildArguments</key>
- <value></value>
- </dictionary>
- <dictionary>
- <key>org.eclipse.cdt.make.core.buildCommand</key>
- <value>sbi-make</value>
- </dictionary>
- <dictionary>
- <key>org.eclipse.cdt.make.core.buildLocation</key>
- <value>${workspace_loc:/TizenActionFrameworkService/Debug}</value>
- </dictionary>
- <dictionary>
- <key>org.eclipse.cdt.make.core.cleanBuildTarget</key>
- <value>clean</value>
- </dictionary>
- <dictionary>
- <key>org.eclipse.cdt.make.core.contents</key>
- <value>org.eclipse.cdt.make.core.activeConfigSettings</value>
- </dictionary>
- <dictionary>
- <key>org.eclipse.cdt.make.core.enableAutoBuild</key>
- <value>true</value>
- </dictionary>
- <dictionary>
- <key>org.eclipse.cdt.make.core.enableCleanBuild</key>
- <value>true</value>
- </dictionary>
- <dictionary>
- <key>org.eclipse.cdt.make.core.enableFullBuild</key>
- <value>true</value>
- </dictionary>
- <dictionary>
- <key>org.eclipse.cdt.make.core.fullBuildTarget</key>
- <value>all</value>
- </dictionary>
- <dictionary>
- <key>org.eclipse.cdt.make.core.stopOnError</key>
- <value>true</value>
- </dictionary>
- <dictionary>
- <key>org.eclipse.cdt.make.core.useDefaultBuildCmd</key>
- <value>true</value>
- </dictionary>
- </arguments>
- </buildCommand>
- <buildCommand>
- <name>org.eclipse.cdt.managedbuilder.core.ScannerConfigBuilder</name>
- <triggers>full,incremental,</triggers>
- <arguments>
- </arguments>
- </buildCommand>
- </buildSpec>
- <natures>
- <nature>org.eclipse.cdt.core.cnature</nature>
- <nature>org.eclipse.cdt.core.ccnature</nature>
- <nature>org.eclipse.cdt.managedbuilder.core.managedBuildNature</nature>
- <nature>org.eclipse.cdt.managedbuilder.core.ScannerConfigNature</nature>
- </natures>
- <filteredResources>
- <filter>
- <id>1360216703005</id>
- <name></name>
- <type>26</type>
- <matcher>
- <id>org.eclipse.ui.ide.multiFilter</id>
- <arguments>1.0-projectRelativePath-matches-false-false-*/.tpk</arguments>
- </matcher>
- </filter>
- </filteredResources>
-</projectDescription>
-
-ADD_SUBDIRECTORY(src)
+AUX_SOURCE_DIRECTORY(${CMAKE_CURRENT_SOURCE_DIR} MAIN_SRCS)
+ADD_EXECUTABLE(${TARGET_TIZEN_ACTION_SERVICE} ${MAIN_SRCS})
+
+TARGET_INCLUDE_DIRECTORIES(${TARGET_TIZEN_ACTION_SERVICE} PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/../../)
+
+APPLY_PKG_CONFIG(${TARGET_TIZEN_ACTION_SERVICE} PUBLIC
+ CAPI_APPFW_APP_COMMON_DEPS
+ CAPI_APPFW_APP_MANAGER_DEPS
+ CAPI_APPFW_PACKAGE_MANAGER_DEPS
+ CAPI_APPFW_SERVICE_APPLICATION_DEPS
+ DLOG_DEPS
+ GLIB_DEPS
+ TIZEN_DATABASE_DEPS
+ RPC_PORT_DEPS
+)
+
+TARGET_LINK_LIBRARIES(${TARGET_TIZEN_ACTION_SERVICE} PRIVATE ${TARGET_TIZEN_ACTION} ${TARGET_TIZEN_ACTION_COMMON})
+
+SET(MANIFESTDIR "${PREFIX}/share/packages")
+
+INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/tizen-manifest.xml DESTINATION ${MANIFESTDIR} RENAME ${SERVICE_PKGID}.xml)
+INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/tizen-manifest.xml DESTINATION ${PREFIX}/apps/${SERVICE_PKGID})
+INSTALL(TARGETS ${TARGET_TIZEN_ACTION_SERVICE} DESTINATION ${PREFIX}/apps/${SERVICE_PKGID}/bin/)
+++ /dev/null
-#!/bin/bash
-
-tizen build-native -C Debug -a x86_64 -c gcc && tizen package -t tpk -- ./Debug
--- /dev/null
+/*
+ * Copyright (c) 2024 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 <tizen.h>
+#include <service_app.h>
+
+#include <memory>
+
+#include "action/action_request_handler.h"
+#include "common/utils/logging.hh"
+
+namespace {
+
+bool ServiceAppCreate(void* data) {
+ return true;
+}
+
+void ServiceAppTerminate(void* data) {
+ return;
+}
+
+void ServiceAppControl(app_control_h app_control, void* data) {
+ return;
+}
+
+void ServiceAppLangChanged(app_event_info_h event_info, void* user_data) {
+ /*APP_EVENT_LANGUAGE_CHANGED*/
+ return;
+}
+
+void ServiceAppRegionChanged(app_event_info_h event_info, void* user_data) {
+ /*APP_EVENT_REGION_FORMAT_CHANGED*/
+}
+
+void ServiceAppLowBattery(app_event_info_h event_info, void* user_data) {
+ /*APP_EVENT_LOW_BATTERY*/
+}
+
+void ServiceAppLowMemory(app_event_info_h event_info, void* user_data) {
+ /*APP_EVENT_LOW_MEMORY*/
+}
+
+} // namespace
+
+int main(int argc, char* argv[]) {
+ service_app_lifecycle_callback_s event_callback;
+ app_event_handler_h handlers[5] = { nullptr, };
+
+ event_callback.create = ServiceAppCreate;
+ event_callback.terminate = ServiceAppTerminate;
+ event_callback.app_control = ServiceAppControl;
+
+ service_app_add_event_handler(&handlers[APP_EVENT_LOW_BATTERY],
+ APP_EVENT_LOW_BATTERY, ServiceAppLowBattery, nullptr);
+ service_app_add_event_handler(&handlers[APP_EVENT_LOW_MEMORY],
+ APP_EVENT_LOW_MEMORY, ServiceAppLowMemory, nullptr);
+ service_app_add_event_handler(&handlers[APP_EVENT_LANGUAGE_CHANGED],
+ APP_EVENT_LANGUAGE_CHANGED, ServiceAppLangChanged, nullptr);
+ service_app_add_event_handler(&handlers[APP_EVENT_REGION_FORMAT_CHANGED],
+ APP_EVENT_REGION_FORMAT_CHANGED, ServiceAppRegionChanged, nullptr);
+
+ service::ActionRequestHandler manager;
+ manager.Init();
+
+ LOG(DEBUG) << "service_app_main start...";
+
+ return service_app_main(argc, argv, &event_callback, nullptr);
+}
+++ /dev/null
-APPNAME = TizenActionFrameworkService
-type = app
-profile = tizen-9.0
-
-USER_SRCS = src/*.cc \
- src/utils/*.cc
-
-USER_INC_DIRS = src
-
-USER_DEFS =
-USER_CPP_DEPS =
-
-USER_UNDEFS =
-USER_CPP_UNDEFS =
-
-USER_OBJS =
-
-USER_CPP_OPTS = -std=c++17
+++ /dev/null
-AUX_SOURCE_DIRECTORY(${CMAKE_CURRENT_SOURCE_DIR} SERVICE_SRCS)
-AUX_SOURCE_DIRECTORY(${CMAKE_CURRENT_SOURCE_DIR}/utils SERVICE_UTILS_SRCS)
-ADD_EXECUTABLE(${TARGET_TIZEN_ACTION_SERVICE} ${SERVICE_SRCS} ${SERVICE_UTILS_SRCS})
-
-TARGET_INCLUDE_DIRECTORIES(${TARGET_TIZEN_ACTION_SERVICE} PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/../../)
-
-APPLY_PKG_CONFIG(${TARGET_TIZEN_ACTION_SERVICE} PUBLIC
- CAPI_APPFW_APP_COMMON_DEPS
- CAPI_APPFW_APP_MANAGER_DEPS
- CAPI_APPFW_PACKAGE_MANAGER_DEPS
- CAPI_APPFW_SERVICE_APPLICATION_DEPS
- DLOG_DEPS
- GLIB_DEPS
- TIZEN_DATABASE_DEPS
- RPC_PORT_DEPS
-)
-
-TARGET_LINK_LIBRARIES(${TARGET_TIZEN_ACTION_SERVICE} PRIVATE ${TARGET_TIZEN_ACTION_COMMON})
-
-SET(MANIFESTDIR "${PREFIX}/share/packages")
-
-INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/../tizen-manifest.xml DESTINATION ${MANIFESTDIR} RENAME ${SERVICE_PKGID}.xml)
-INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/../tizen-manifest.xml DESTINATION ${PREFIX}/apps/${SERVICE_PKGID})
-INSTALL(TARGETS ${TARGET_TIZEN_ACTION_SERVICE} DESTINATION ${PREFIX}/apps/${SERVICE_PKGID}/bin/)
-#INSTALL(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/res DESTINATION ${PREFIX}/apps/${SERVICE_PKGID})
-#INSTALL(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/shared/res DESTINATION ${PREFIX}/apps/${SERVICE_PKGID}/shared)
+++ /dev/null
-/*
- * Copyright (c) 2024 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 <string>
-
-#include "action_request_handler.h"
-#include "service.h"
-
-#include "common/sqlite_db.hh"
-
-namespace service {
-
-ActionRequestHandler::ActionRequestHandler() {
-}
-
-ActionRequestHandler::~ActionRequestHandler() {
-}
-
-void ActionRequestHandler::Init() {
- service_.Listen(std::make_shared<service::Service::Factory>(*this));
-}
-
-void ActionRequestHandler::OnListActions() {
- // TODO: db as member variable?
- auto db = std::make_unique<common::SqliteDb>();
- db->ListActions();
-}
-
-void ActionRequestHandler::OnGetAction(std::string id) {
- auto db = std::make_unique<common::SqliteDb>();
- db->GetAction(id);
-}
-
-void ActionRequestHandler::OnGetActionId(std::string user_description, int top_k,
- float search_threshold) {
-}
-
-void ActionRequestHandler::OnExecute(std::string launch_req) {
-
-}
-
-} // namespace service
+++ /dev/null
-/*
- * Copyright (c) 2024 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 SRC_ACTION_MANAGER_H_
-#define SRC_ACTION_MANAGER_H_
-
-#include <vector>
-
-#include "irequest_handler.h"
-#include "tizen_action_service_stub.h"
-
-using Action = rpc_port::tizen_action_service_stub::Action;
-
-namespace service {
-
-class ActionRequestHandler : public IRequestHandler {
- public:
- ActionRequestHandler();
- ~ActionRequestHandler();
- void Init();
-
- void OnListActions() override;
- void OnGetAction(std::string id) override;
- void OnGetActionId(std::string user_description, int top_k,
- float search_threshold) override;
- void OnExecute(std::string request) override;
-
- private:
- rpc_port::tizen_action_service_stub::stub::ActionService service_;
-};
-
-} // namespace service
-
-#endif // SRC_ACTION_MANAGER_H_
+++ /dev/null
-/*
- * Copyright (c) 2024 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 SRC_IREQUEST_HANDLER_H_
-#define SRC_IREQUEST_HANDLER_H_
-
-#include <string>
-
-namespace service {
-
-class IRequestHandler {
- public:
- virtual ~IRequestHandler() = default;
- virtual void OnListActions() = 0;
- virtual void OnGetAction(std::string id) = 0;
- virtual void OnGetActionId(std::string user_description, int top_k,
- float search_threshold) = 0;
- virtual void OnExecute(std::string launch_req) = 0;
-};
-
-} // namespace service
-
-#endif // SRC_IREQUEST_HANDLER_H_
+++ /dev/null
-/*
- * Copyright (c) 2024 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 <tizen.h>
-#include <service_app.h>
-
-#include <memory>
-
-#include "action_request_handler.h"
-#include "utils/logging.h"
-
-namespace {
-
-bool ServiceAppCreate(void* data) {
- return true;
-}
-
-void ServiceAppTerminate(void* data) {
- return;
-}
-
-void ServiceAppControl(app_control_h app_control, void* data) {
- return;
-}
-
-void ServiceAppLangChanged(app_event_info_h event_info, void* user_data) {
- /*APP_EVENT_LANGUAGE_CHANGED*/
- return;
-}
-
-void ServiceAppRegionChanged(app_event_info_h event_info, void* user_data) {
- /*APP_EVENT_REGION_FORMAT_CHANGED*/
-}
-
-void ServiceAppLowBattery(app_event_info_h event_info, void* user_data) {
- /*APP_EVENT_LOW_BATTERY*/
-}
-
-void ServiceAppLowMemory(app_event_info_h event_info, void* user_data) {
- /*APP_EVENT_LOW_MEMORY*/
-}
-
-} // namespace
-
-int main(int argc, char* argv[]) {
- service_app_lifecycle_callback_s event_callback;
- app_event_handler_h handlers[5] = { nullptr, };
-
- event_callback.create = ServiceAppCreate;
- event_callback.terminate = ServiceAppTerminate;
- event_callback.app_control = ServiceAppControl;
-
- service_app_add_event_handler(&handlers[APP_EVENT_LOW_BATTERY],
- APP_EVENT_LOW_BATTERY, ServiceAppLowBattery, nullptr);
- service_app_add_event_handler(&handlers[APP_EVENT_LOW_MEMORY],
- APP_EVENT_LOW_MEMORY, ServiceAppLowMemory, nullptr);
- service_app_add_event_handler(&handlers[APP_EVENT_LANGUAGE_CHANGED],
- APP_EVENT_LANGUAGE_CHANGED, ServiceAppLangChanged, nullptr);
- service_app_add_event_handler(&handlers[APP_EVENT_REGION_FORMAT_CHANGED],
- APP_EVENT_REGION_FORMAT_CHANGED, ServiceAppRegionChanged, nullptr);
-
- service::ActionRequestHandler manager;
- manager.Init();
-
- LOG(DEBUG) << "service_app_main start...";
-
- return service_app_main(argc, argv, &event_callback, nullptr);
-}
+++ /dev/null
-/*
- * Copyright (c) 2024 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 "irequest_handler.h"
-#include "service.h"
-#include "utils/logging.h"
-
-#include "utils/sqlite_db.h"
-#include "utils/json_parser.h"
-
-namespace service {
-
-Service::Service(std::string sender, std::string instance,
- IRequestHandler& handler)
- : rs::stub::ActionService::ServiceBase(std::move(sender),
- std::move(instance)), handler_(handler) {
-}
-
-Service::~Service() {
-}
-
-std::vector<rs::Action> Service::ListActions() {
- // return list of actions from db
- // handler_->ListActions();
- return {};
-}
-
-rs::Action Service::GetAction(std::string action_id) {
- // return action by id
- // handler_->GetAction(action_id);
- LOG(DEBUG) << "GetAction : " << action_id;
-
- std::string result;
- utils::SqliteDb sqlite_db;
-
- sqlite_db.Select(action_id, result);
-
- LOG(DEBUG) << "GetAction result : " << result;
-
- auto ps = new utils::JsonParser(result);
-
- auto params = ps->GetParameters();
-
- rs::Action action;
- std::vector<rs::Parameter> actionparams;
-
- action.Setapp_id(ps->GetAppId());
- action.Setaction_id(ps->GetName());
- action.Setlabel(ps->GetName());
- action.Setdescription(ps->GetDescription());
-
- for (auto const& iter : params) {
- auto param_value = iter.second;
-
- auto param = rs::Parameter(iter.first, param_value["type"], param_value["desc"],
- param_value["isMandatory"].compare("true") == 0 ? true : false);
-
- actionparams.push_back(param);
- }
-
- action.Setparameters(actionparams);
-
- LOG(DEBUG) << "appid : " << action.Getapp_id();
- LOG(DEBUG) << "actionid : " << action.Getaction_id();
-
- // return {};
- return action;
-}
-
-std::vector<rs::VectorDbResult> Service::GetActionId(
- std::string user_description, int top_k, float search_threshold) {
- // return result from db
- // handler_->GetActionId(user_description, top_k, search_threshold);
- return {};
-}
-
-int Service::Execute(std::string launch_req) {
- // return action exetution result
- // handler_->Execute(std::move(launch_req));
- return 0;
-}
-
-} // namespace service
+++ /dev/null
-/*
- * Copyright (c) 2024 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 SRC_SERVICE_H_
-#define SRC_SERVICE_H_
-
-#include <memory>
-#include <string>
-#include <vector>
-
-#include "irequest_handler.h"
-#include "tizen_action_service_stub.h"
-
-namespace service {
-
-namespace rs = rpc_port::tizen_action_service_stub;
-
-class Service : public rs::stub::ActionService::ServiceBase {
- public:
- class Factory : public rs::stub::ActionService::ServiceBase::Factory {
- public:
- Factory(IRequestHandler& handler) : handler_(handler) {}
- virtual ~Factory() = default;
- std::unique_ptr<rs::stub::ActionService::ServiceBase> CreateService(
- std::string sender, std::string instance) override {
- return std::make_unique<Service>(sender, instance, handler_);
- }
-
- private:
- IRequestHandler& handler_;
- };
-
- Service(std::string sender, std::string instance, IRequestHandler& handler);
- ~Service();
-
- void OnCreate() override {}
- void OnTerminate() override {}
- std::vector<rs::Action> ListActions() override;
- rs::Action GetAction(std::string action_id) override;
- std::vector<rs::VectorDbResult> GetActionId(std::string user_description,
- int top_k, float search_threshold) override;
- int Execute(std::string launch_req) override;
-
- private:
- IRequestHandler& handler_;
-};
-
-} // namespace service
-
-#endif // SRC_SERVICE_H_
+++ /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 <stdexcept>
-
-#include "json_parser.h"
-
-#include "logging.h"
-
-namespace utils {
-
-JsonParser::JsonParser(std::string json_str)
- : json_str_(json_str) {
- LOG(DEBUG) << "ParseStr const";
-
- std::size_t pos = 0;
- std::size_t lpos = 0;
- std::string params;
-
- // remove {}
- pos = json_str_.find("{");
- lpos = json_str_.rfind("}");
- json_str_ = json_str_.substr(pos + 1, lpos - pos - 1);
-
- // seperate params
- pos = json_str_.find("{");
- lpos = json_str_.rfind("}");
- params = json_str_.substr(pos + 1, lpos - pos - 1);
- json_str_.replace(pos + 1, lpos - pos - 1, " ");
-
- // make nodes
- while(true) {
- pos = json_str_.find(",");
-
- if (pos == std::string::npos)
- break;
-
- std::string sub_ = json_str_.substr(0, pos);
- std::size_t spos = sub_.find(":");
- std::string key = sub_.substr(1, spos - 2);
- sub_ = sub_.substr(spos + 1);
- std::string value = sub_.substr(1, sub_.length() - 2);
-
- nodes_[key] = value;
-
- // LOG(DEBUG) << key << " : " << value;
-
- json_str_ = json_str_.substr(pos + 1);
- }
-
-// LOG(DEBUG) << params;
-
- std::size_t compos = 0;
-
- // make params
- while(true) {
- pos = params.find("{");
- lpos = params.find("}");
-
- std::string key = params.substr(1, pos - 3);
- std::string value = params.substr(pos + 1, lpos - pos - 1);
-
- // LOG(DEBUG) << key << " : " << value;
-
-
- std::size_t subpos = 0;
- std::size_t nextpos = 0;
- std::size_t compos_ = 0;
- std::map<std::string, std::string> mvalue;
-
- // make param value
- while(true) {
- // LOG(DEBUG) << value;
-
- subpos = value.find("\"");
- nextpos = value.find("\"", subpos + 1);
-
- std::string subkey = value.substr(1, nextpos - 1);
-
- subpos = value.find("\"", nextpos + 1);
- nextpos = value.find("\"", subpos + 1);
-
- std::string subval = value.substr(subpos + 1, nextpos - subpos - 1);
-
- mvalue[subkey] = subval;
-
- compos_ = value.find(",", nextpos);
- if (compos_ == std::string::npos)
- break;
-
- value = value.substr(compos_ + 1);
- }
- params_[key] = mvalue;
-
- compos = params.find(",", lpos);
- if (compos == std::string::npos)
- break;
-
- params = params.substr(lpos + 2);
- }
-
- LOG(DEBUG) << "ParseStr const end";
-}
-
-std::string JsonParser::GetAppId() {
- return nodes_["appId"];
-}
-
-std::string JsonParser::GetName() {
- return nodes_["name"];
-}
-
-std::string JsonParser::GetDescription() {
- return nodes_["desc"];
-}
-
-std::string JsonParser::GetType() {
- return nodes_["type"];
-}
-
-std::string JsonParser::GetVersion() {
- return nodes_["version"];
-}
-
-std::string JsonParser::GetRequiredPrivilege() {
- return nodes_["required-privileges"];
-}
-
-std::string JsonParser::GetReturns() {
- return nodes_["required-privileges"];
-}
-
-std::map<std::string, std::map<std::string, std::string>> JsonParser::GetParameters() {
- return params_;
-}
-
-} // namespace utils
+++ /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 JSON_PARSER_H_
-#define JSON_PARSER_H_
-
-// #include <json/json.h>
-
-#include <string>
-#include <map>
-
-namespace utils {
-
-/* temporary parser */
-/* need to be changed to use json */
-
-class JsonParser {
- public:
- JsonParser(std::string json_str);
- ~JsonParser() = default;
-
- std::string GetAppId();
- std::string GetName();
- std::string GetDescription();
- std::string GetType();
- std::string GetVersion();
- std::string GetRequiredPrivilege();
- std::string GetReturns();
- std::map<std::string, std::map<std::string, std::string>> GetParameters();
-
- private:
- std::string json_str_;
- std::map<std::string, std::string> nodes_;
- std::map<std::string, std::map<std::string, std::string>> params_;
-};
-
-} // namespace utils
-
-#endif //
+++ /dev/null
-// Copyright (c) 2024 Samsung Electronics Co., Ltd All Rights Reserved
-// Use of this source code is governed by a apache 2.0 license that can be
-// found in the LICENSE file.
-
-#include "service/src/utils/logging.h"
-
-namespace utils {
-
-log_priority LogLevelToPriority(LogLevel level) {
- switch (level) {
- case LogLevel::LOG_ERROR:
- return log_priority::DLOG_ERROR;
- case LogLevel::LOG_WARNING:
- return log_priority::DLOG_WARN;
- case LogLevel::LOG_INFO:
- return log_priority::DLOG_INFO;
- case LogLevel::LOG_DEBUG:
- return log_priority::DLOG_DEBUG;
- default:
- return log_priority::DLOG_UNKNOWN;
- }
-}
-
-} // namespace utils
+++ /dev/null
-// Copyright (c) 2024 Samsung Electronics Co., Ltd All Rights Reserved
-// Use of this source code is governed by a apache 2.0 license that can be
-// found in the LICENSE file.
-
-#ifndef LOGGING_HH_
-#define LOGGING_HH_
-
-#include <dlog.h>
-
-#ifndef PROJECT_TAG
-#define PROJECT_TAG "TAF"
-#endif
-
-#ifdef LOG
-#undef LOG
-#endif
-
-#include <cassert>
-#include <cstring>
-#include <iomanip>
-#include <iostream>
-#include <sstream>
-#include <string>
-
-#ifndef __FILENAME__
-#define __FILENAME__ \
- (strrchr(__FILE__, '/') ? strrchr(__FILE__, '/') + 1 : __FILE__)
-#endif
-
-namespace utils {
-
-enum class LogLevel {
- LOG_ERROR,
- LOG_WARNING,
- LOG_INFO,
- LOG_DEBUG,
-};
-
-log_priority LogLevelToPriority(LogLevel level);
-
-template <class charT, class traits = std::char_traits<charT>>
-class StringStream : private std::basic_ostringstream<charT, traits> {
- public:
- using std::basic_ostringstream<charT, traits>::str;
-
- template <class T>
- StringStream& operator<<(const T& value) {
- static_cast<std::basic_ostringstream<charT, traits> &>(*this) << value;
- return *this;
- }
-};
-
-class LogCatcher {
- public:
- LogCatcher(LogLevel level, const char* tag)
- : level_(level), tag_(tag) { }
-
- void operator&(const StringStream<char>& str) const {
- dlog_print(LogLevelToPriority(level_), tag_.c_str(), "%s",
- Escape(str.str()).c_str());
- }
-
- private:
- // Since LogCatcher passes input to dlog_print(), the input which contains
- // format string(such as %d, %n) can cause unexpected result.
- // This is simple function to escape '%'.
- // NOTE: Is there any gorgeous way instead of this?
- std::string Escape(const std::string& str) const {
- std::string escaped = std::string(str);
- size_t start_pos = 0;
- std::string from = "%";
- std::string to = "%%";
- while ((start_pos = escaped.find(from, start_pos)) != std::string::npos) {
- escaped.replace(start_pos, from.length(), to);
- start_pos += to.length();
- }
- return escaped;
- }
- LogLevel level_;
- std::string tag_;
-};
-
-} // namespace utils
-
-inline static const constexpr char* __tag_for_project() {
- return PROJECT_TAG;
-}
-
-// Simple logging macro of following usage:
-// LOG(LEVEL) << object_1 << object_2 << object_n;
-// where:
-// LEVEL = ERROR | WARNING | INFO | DEBUG
-#define LOG(LEVEL) \
- ::utils::LogCatcher( \
- ::utils::LogLevel::LOG_ ## LEVEL, __tag_for_project()) \
- & ::utils::StringStream<char>() \
- << std::setw(50) << std::right \
- << (std::string(__FILENAME__) + ": " + std::string(__FUNCTION__) + "(" + \
- std::to_string(__LINE__) + ")").c_str() \
- << std::setw(0) << " : " \
-
-#endif // LOGGING_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.
- */
-
-#include "sqlite_db.h"
-
-#include "logging.h"
-
-namespace {
-
-constexpr char kDbPath[] = "/opt/dbspace/.tizen_action.db";
-constexpr char kSelectQuery[] =
- "SELECT json_str FROM action WHERE action_name = ?";
-
-} // namespace
-
-namespace utils {
-
-bool SqliteDb::Select(std::string action_id, std::string& result) {
- LOG(DEBUG) << "select : " << action_id;
-
- int ret;
- char *val;
- sqlite3 *db;
- sqlite3_stmt *stmt = nullptr;
-
- ret = sqlite3_open_v2(kDbPath, &db, SQLITE_OPEN_READONLY, nullptr);
- if (ret != SQLITE_OK) {
- LOG(ERROR) << "failed to open db : " << kDbPath << " , : " << ret;
- return false;
- }
-
- ret = sqlite3_prepare_v2(db, kSelectQuery, strlen(kSelectQuery), &stmt, nullptr);
- if (ret != SQLITE_OK) {
- LOG(ERROR) << "failed to prepare : " << ret;
- return false;
- }
-
- sqlite3_bind_text(stmt, 1, action_id.c_str(), -1, SQLITE_STATIC);
-
- ret = sqlite3_step(stmt);
- if (ret != SQLITE_ROW) {
- LOG(ERROR) << "failed to step : " << sqlite3_errmsg(db);
- return false;
- }
-
- val = (char *)sqlite3_column_text(stmt, 0);
- LOG(DEBUG) << "result : " << val;
-
- result = val;
-
- sqlite3_finalize(stmt);
- sqlite3_close_v2(db);
-
- return true;
-}
-
-} // namespace utils
+++ /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 SQLITE_DB_H_
-#define SQLITE_DB_H_
-
-// #include <database.hpp>
-#include <sqlite3.h>
-
-#include <string>
-
-/* need to be changed to use cpp tizen-database */
-/* neec to be changed smack label for .tizen_action.db */
-
-namespace utils {
-
-class SqliteDb {
- public:
- SqliteDb() = default;
- ~SqliteDb() = default;
-
- bool Select(std::string action_id, std::string& result);
-
-};
-
-} // namespace utils
-
-#endif // SQLITE_DB_H_
\ No newline at end of file
fi
mv tizen_action_service_proxy.* $SCRIPT_DIR/../src/api/
-mv tizen_action_service_stub.* $SCRIPT_DIR/../src/service/src/
+mv tizen_action_service_stub.* $SCRIPT_DIR/../src/action/