From: Sejun Park Date: Fri, 29 Mar 2024 08:59:45 +0000 (+0900) Subject: Sync with latest code X-Git-Tag: accepted/tizen/unified/20240404.021353^0 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=80c93468119de2120d6d082ef1db51e59e4e1f3e;p=platform%2Fcore%2Fuifw%2Fmmi-framework.git Sync with latest code Sync Commit ID : a34b5458a5eff86f01ffd0d96248b545cbb21269 Change-Id: I5c49e9f75aa3cb89377ef6ff633c0d2bb322f27e --- diff --git a/capi/mmi-workflow.h b/capi/mmi-workflow.h index dfcf666..d4e97d1 100644 --- a/capi/mmi-workflow.h +++ b/capi/mmi-workflow.h @@ -154,6 +154,9 @@ int mmi_workflow_create_from_script(const char *script, mmi_workflow_h *workflow /* Create a workflow prototype from a script file */ int mmi_workflow_create_from_script_file(const char *script_path, mmi_workflow_h *workflow); +/* Generate a workflow script from a workflow prototype */ +int mmi_workflow_generate_script(mmi_workflow_h workflow, const char **script); + /* Destroy a workflow prototype */ int mmi_workflow_destroy(mmi_workflow_h workflow); @@ -170,11 +173,8 @@ typedef void (*mmi_workflow_output_cb)(mmi_workflow_instance_h instance, const c /* Instantiate a workflow from a workflow prototype */ int mmi_standard_workflow_instance_create(mmi_standard_workflow_type_e type, mmi_workflow_instance_h *instance); -/* Instantiate a workflow from a workflow script */ -int mmi_custom_workflow_instance_create_from_script(const char *workflow_script, mmi_workflow_instance_h *instance); - -/* Instantiate a workflow from a workflow script file */ -int mmi_custom_workflow_instance_create_from_script_file(const char *workflow_script_path, mmi_workflow_instance_h *instance); +/* Instantiate a workflow from a custom workflow prototype */ +int mmi_custom_workflow_instance_create(mmi_workflow_h workflow, mmi_workflow_instance_h *instance); /* Destroy a workflow instance */ int mmi_workflow_instance_destroy(mmi_workflow_instance_h instance); diff --git a/setup_linux_build.sh b/setup_linux_build.sh index bf10d42..b65bd0c 100755 --- a/setup_linux_build.sh +++ b/setup_linux_build.sh @@ -2,4 +2,5 @@ meson setup --prefix=/usr/local/mmi \ --bindir /usr/local/mmi/bin \ --libdir /usr/local/mmi/lib \ --datadir /usr/local/mmi/share \ + --buildtype debug \ ./linux_build diff --git a/src/common/mmi-communication-message.h b/src/common/mmi-communication-message.h index 12b83df..4f434c2 100644 --- a/src/common/mmi-communication-message.h +++ b/src/common/mmi-communication-message.h @@ -64,7 +64,6 @@ struct ClientMessage : public Message { struct ClientMessageWorkflowInstanceCreate : public ClientMessage { ClientMessageWorkflowInstanceCreate() : ClientMessage{CLIENT_MESSAGE_TYPE::WORKFLOW_INSTANCE_CREATE} {} mmi_standard_workflow_type_e workflow_type{MMI_STANDARD_WORKFLOW_NONE}; - bool script_from_file{false}; std::string script_info; int local_workflow_instance_id{0}; void *user_data{nullptr}; diff --git a/src/mmi-cli/mmi-cli-node-tester.cpp b/src/mmi-cli/mmi-cli-node-tester.cpp index c0d659e..b6cabd3 100644 --- a/src/mmi-cli/mmi-cli-node-tester.cpp +++ b/src/mmi-cli/mmi-cli-node-tester.cpp @@ -461,7 +461,7 @@ void Program::port_instance_output_handler(mmi_port_instance_h port, mmi_data_h } void Program::load_module(std::string path) { - mmi_plugin_module_event_handler_info_s module_event_handler_info{nullptr, }; + mmi_plugin_module_event_handler_info_s module_event_handler_info{{nullptr}, {nullptr}}; module_event_handler_info.port_instance_output_handler = port_instance_output_handler; mmi_plugin_storage_set_plugin_module_event_handler(module_event_handler_info, nullptr); diff --git a/src/mmi-cli/mmi-cli.cpp b/src/mmi-cli/mmi-cli.cpp index 80b5a14..c0b137f 100644 --- a/src/mmi-cli/mmi-cli.cpp +++ b/src/mmi-cli/mmi-cli.cpp @@ -66,7 +66,9 @@ MATCH.CANDIDATES as COMMANDS MATCH.COMMAND as MATCHED_CANDIDATE )"; std::cout << "Creating instance of script : " << std::endl << script << std::endl; - mmi_custom_workflow_instance_create_from_script(script.c_str(), &m_instance); + mmi_workflow_h workflow; + mmi_workflow_create_from_script(script.c_str(), &workflow); + mmi_custom_workflow_instance_create(workflow, &m_instance); mmi_workflow_instance_set_output_callback(m_instance, "COMMAND", [](mmi_workflow_instance_h instance, const char *name, mmi_data_h data, void *user_data) { std::cout << "OUTPUT data received : " << std::string(name ? name : "") << std::endl; @@ -80,7 +82,7 @@ MATCH.COMMAND as MATCHED_CANDIDATE } std::cout << "Creating instance of script with path : " << path << std::endl; - mmi_custom_workflow_instance_create_from_script_file(path.c_str(), &m_instance); + //mmi_custom_workflow_instance_create_from_script_file(path.c_str(), &m_instance); mmi_workflow_instance_set_output_callback(m_instance, "COMMAND", [](mmi_workflow_instance_h instance, const char *name, mmi_data_h data, void *user_data) { std::cout << "OUTPUT data received : " << std::string(name ? name : "") << std::endl; diff --git a/src/mmi-manager/mmi-ipc-ecore.cpp b/src/mmi-manager/mmi-ipc-ecore.cpp index 2119e62..90c9e99 100644 --- a/src/mmi-manager/mmi-ipc-ecore.cpp +++ b/src/mmi-manager/mmi-ipc-ecore.cpp @@ -188,7 +188,6 @@ void CommunicationChannelEcoreIPC::on_client_message(Ecore_Ipc_Client *client, v struct workflow_instance_create_payload { int local_workflow_instance_id; mmi_standard_workflow_type_e workflow_type; - bool script_from_file; size_t script_info_size; } payload; if (data_size < sizeof(CLIENT_MESSAGE_TYPE) + sizeof(payload)) { @@ -200,7 +199,6 @@ void CommunicationChannelEcoreIPC::on_client_message(Ecore_Ipc_Client *client, v message.sender = sender; message.local_workflow_instance_id = payload.local_workflow_instance_id; message.workflow_type = payload.workflow_type; - message.script_from_file = payload.script_from_file; message.script_info = std::string( (const char*)((unsigned char*)(data) + sizeof(CLIENT_MESSAGE_TYPE) + sizeof(payload)), diff --git a/src/mmi-manager/mmi-ipc-tidl.cpp b/src/mmi-manager/mmi-ipc-tidl.cpp index c66ae28..b17179d 100644 --- a/src/mmi-manager/mmi-ipc-tidl.cpp +++ b/src/mmi-manager/mmi-ipc-tidl.cpp @@ -178,7 +178,7 @@ void CommunicationChannelTIDL::on_terminate(rpc_port_stub_mmi_context_h context, } int CommunicationChannelTIDL::workflow_instance_create(rpc_port_stub_mmi_context_h context, - int local_workflow_instance_id, int workflow_type, bool script_from_file, + int local_workflow_instance_id, int workflow_type, const char *script_info, void *user_data) { CommunicationChannelTIDL *channel = static_cast(user_data); @@ -190,7 +190,6 @@ int CommunicationChannelTIDL::workflow_instance_create(rpc_port_stub_mmi_context msg.sender = sender; msg.local_workflow_instance_id = local_workflow_instance_id; msg.workflow_type = static_cast(workflow_type); - msg.script_from_file = script_from_file; msg.script_info = script_info ? std::string{script_info} : std::string(); return notify_message_received(channel, static_cast(&msg)); diff --git a/src/mmi-manager/mmi-ipc-tidl.h b/src/mmi-manager/mmi-ipc-tidl.h index c569c6b..0475793 100644 --- a/src/mmi-manager/mmi-ipc-tidl.h +++ b/src/mmi-manager/mmi-ipc-tidl.h @@ -50,7 +50,7 @@ private: static void on_terminate(rpc_port_stub_mmi_context_h context, void *user_data); static int workflow_instance_create(rpc_port_stub_mmi_context_h context, - int local_workflow_instance_id, int workflow_type, bool script_from_file, const char *script_info, void *user_data); + int local_workflow_instance_id, int workflow_type, const char *script_info, void *user_data); static int workflow_instance_destroy(rpc_port_stub_mmi_context_h context, int local_workflow_instance_id, void *user_data); static int workflow_instance_set_attribute(rpc_port_stub_mmi_context_h context, diff --git a/src/mmi-manager/mmi-node-prototype-manager.cpp b/src/mmi-manager/mmi-node-prototype-manager.cpp index 0b9f018..09c3bae 100644 --- a/src/mmi-manager/mmi-node-prototype-manager.cpp +++ b/src/mmi-manager/mmi-node-prototype-manager.cpp @@ -96,15 +96,15 @@ std::shared_ptr NodePrototypeHelper::create_node_prototype(mmi_no size_t name_length = 0; mmi_port_get_name(port, &name, &name_length); - mmi_port_type_e type; - mmi_port_get_type(port, &type); + mmi_port_type_e port_type; + mmi_port_get_type(port, &port_type); mmi_data_type_e data_type; mmi_port_get_data_type(port, &data_type); PortInfo port_info; port_info.name = name; - port_info.port_type = type; + port_info.port_type = port_type; port_info.data_type = data_type; prototype->add_port_info(port_info); } diff --git a/src/mmi-manager/mmi-plugin-module-proxy.cpp b/src/mmi-manager/mmi-plugin-module-proxy.cpp index 36afcb6..05c65aa 100644 --- a/src/mmi-manager/mmi-plugin-module-proxy.cpp +++ b/src/mmi-manager/mmi-plugin-module-proxy.cpp @@ -63,7 +63,7 @@ static void switch_node_event_handler(mmi_node_instance_h node, const char *cont PluginModuleProxySharedLibrary::PluginModuleProxySharedLibrary( const mmi_plugin_module_identifier plugin_module_identifier) : m_plugin_module_identifier(plugin_module_identifier) { - mmi_plugin_module_event_handler_info_s module_event_handler_info{nullptr, }; + mmi_plugin_module_event_handler_info_s module_event_handler_info{{nullptr}, {nullptr}}; module_event_handler_info.port_instance_output_handler = port_instance_output_handler; module_event_handler_info.switch_node_event_handler = switch_node_event_handler; @@ -176,10 +176,10 @@ mmi_plugin_module_workflow_list_s PluginModuleProxySharedLibrary::load_workflow_ _D("workflow_info[%zu].node_info_count: %zu", i, workflow_info->node_info_count); for (size_t j = 0;j < workflow_info->node_info_count;j++) { mmi_workflow_node_info_s *node_info = &(workflow_info->node_infos[j]); - mmi_node_type_e type; - mmi_node_get_type(workflow_info->node_infos[j].node, &type); + mmi_node_type_e node_type; + mmi_node_get_type(workflow_info->node_infos[j].node, &node_type); _D("workflow_info[%zu].node_info[%zu].name: %s", i, j, node_info->name); - _D("workflow_info[%zu].node_info[%zu].type: %d", i, j, type); + _D("workflow_info[%zu].node_info[%zu].type: %d", i, j, node_type); } _D("workflow_info[%zu].link_info_count: %zu", i, workflow_info->link_info_count); diff --git a/src/mmi-manager/mmi-workflow-instance-manager.cpp b/src/mmi-manager/mmi-workflow-instance-manager.cpp index 672f19e..a78b94f 100644 --- a/src/mmi-manager/mmi-workflow-instance-manager.cpp +++ b/src/mmi-manager/mmi-workflow-instance-manager.cpp @@ -195,11 +195,7 @@ void WorkflowInstanceManager::handle_create( if (message->workflow_type == MMI_STANDARD_WORKFLOW_NONE) { mmi_workflow_h workflow = nullptr; - if (message->script_from_file) { - mmi_workflow_create_from_script_file(message->script_info.c_str(), &workflow); - } else { - mmi_workflow_create_from_script(message->script_info.c_str(), &workflow); - } + mmi_workflow_create_from_script(message->script_info.c_str(), &workflow); std::shared_ptr prototype_store = std::make_shared(); diff --git a/src/mmi/meson.build b/src/mmi/meson.build index 8a83424..aee102e 100644 --- a/src/mmi/meson.build +++ b/src/mmi/meson.build @@ -48,6 +48,7 @@ mmi_include_dirs = include_directories( '.', '../common', '../../capi', + '../../external', mmi_extra_include_dir, ) diff --git a/src/mmi/mmi-attribute.cpp b/src/mmi/mmi-attribute.cpp index e230ce8..22d8176 100644 --- a/src/mmi/mmi-attribute.cpp +++ b/src/mmi/mmi-attribute.cpp @@ -269,7 +269,7 @@ int mmi_attribute_create_string_array(const char *name, const char *strings[], s for (size_t i = 0; i < count; i++) { mmi_primitive_value_h element = nullptr; - int ret = mmi_primitive_value_create_string(strings[i], &element); + ret = mmi_primitive_value_create_string(strings[i], &element); if (MMI_ERROR_NONE != ret) { _E("[ERROR] Fail to allocate memory for array attribute"); mmi_primitive_value_destroy(array); diff --git a/src/mmi/mmi-ipc-ecore.cpp b/src/mmi/mmi-ipc-ecore.cpp index ca7b9e8..3bfbcf3 100644 --- a/src/mmi/mmi-ipc-ecore.cpp +++ b/src/mmi/mmi-ipc-ecore.cpp @@ -53,12 +53,10 @@ int CommunicationChannelEcoreIPC::send(Message *message) { struct workflow_instance_create_payload { int local_workflow_instance_id; mmi_standard_workflow_type_e workflow_type; - bool script_from_file; size_t script_info_size; } payload; payload.local_workflow_instance_id = subclass->local_workflow_instance_id; payload.workflow_type = subclass->workflow_type; - payload.script_from_file = subclass->script_from_file; payload.script_info_size = subclass->script_info.size(); size_t byte_size = sizeof(CLIENT_MESSAGE_TYPE) + sizeof(payload); byte_size += payload.script_info_size; diff --git a/src/mmi/mmi-ipc-tidl.cpp b/src/mmi/mmi-ipc-tidl.cpp index 20c431c..c284226 100644 --- a/src/mmi/mmi-ipc-tidl.cpp +++ b/src/mmi/mmi-ipc-tidl.cpp @@ -158,7 +158,7 @@ int CommunicationChannelTIDL::send(Message *message) { case CLIENT_MESSAGE_TYPE::WORKFLOW_INSTANCE_CREATE: { auto subclass = static_cast(message); workflow_instance_create(subclass->local_workflow_instance_id, subclass->workflow_type, - subclass->script_from_file, subclass->script_info, subclass->user_data); + subclass->script_info, subclass->user_data); } break; case CLIENT_MESSAGE_TYPE::WORKFLOW_INSTANCE_DESTROY: { @@ -218,7 +218,7 @@ int CommunicationChannelTIDL::retry_connection(rpc_port_proxy_mmi_h h) { } int CommunicationChannelTIDL::workflow_instance_create(int local_workflow_instance_id, - mmi_standard_workflow_type_e workflow_type, bool script_from_file, std::string script_info, void *user_data) { + mmi_standard_workflow_type_e workflow_type, std::string script_info, void *user_data) { LOGI("Creating workflow instance of type (%d) for id (%d)", workflow_type, local_workflow_instance_id); @@ -238,7 +238,7 @@ int CommunicationChannelTIDL::workflow_instance_create(int local_workflow_instan } int ret = rpc_port_proxy_mmi_invoke_workflow_instance_create( - rpc_h, local_workflow_instance_id, workflow_type, script_from_file, script_info.c_str()); + rpc_h, local_workflow_instance_id, workflow_type, script_info.c_str()); if (RPC_PORT_ERROR_NONE != ret) { LOGE("Failed to create workflow instance(%d)\n", ret); return MMI_ERROR_OPERATION_FAILED; @@ -298,7 +298,7 @@ int CommunicationChannelTIDL::workflow_instance_set_attribute(int local_workflow if (false == is_connected()) { LOGE("Try to connect again"); - int ret = retry_connection(rpc_h); + ret = retry_connection(rpc_h); if (RPC_PORT_ERROR_NONE != ret) { LOGE("Fail to retry connection(%d)", ret); return MMI_ERROR_OPERATION_FAILED; @@ -313,7 +313,7 @@ int CommunicationChannelTIDL::workflow_instance_set_attribute(int local_workflow bundle_add_byte(encoded, "data", attribute_bytes, attribute_byte_size); if (encoded) { - int ret = rpc_port_proxy_mmi_invoke_workflow_instance_set_attribute(rpc_h, local_workflow_instance_id, encoded); + ret = rpc_port_proxy_mmi_invoke_workflow_instance_set_attribute(rpc_h, local_workflow_instance_id, encoded); bundle_free(encoded); if (RPC_PORT_ERROR_NONE != ret) { @@ -342,7 +342,7 @@ int CommunicationChannelTIDL::workflow_instance_emit_signal(int local_workflow_i if (false == is_connected()) { LOGE("Try to connect again"); - int ret = retry_connection(rpc_h); + ret = retry_connection(rpc_h); if (RPC_PORT_ERROR_NONE != ret) { LOGE("Fail to retry connection(%d)", ret); return MMI_ERROR_OPERATION_FAILED; @@ -389,7 +389,7 @@ int CommunicationChannelTIDL::workflow_instance_emit_signal(int local_workflow_i } if (encoded) { - int ret = rpc_port_proxy_mmi_invoke_workflow_instance_emit_signal(rpc_h, local_workflow_instance_id, encoded); + ret = rpc_port_proxy_mmi_invoke_workflow_instance_emit_signal(rpc_h, local_workflow_instance_id, encoded); bundle_free(encoded); if (RPC_PORT_ERROR_NONE != ret) { @@ -420,7 +420,7 @@ int CommunicationChannelTIDL::workflow_instance_feed_data( if (false == is_connected()) { LOGE("Try to connect again"); - int ret = retry_connection(rpc_h); + ret = retry_connection(rpc_h); if (RPC_PORT_ERROR_NONE != ret) { LOGE("Fail to retry connection(%d)", ret); return MMI_ERROR_OPERATION_FAILED; @@ -438,7 +438,7 @@ int CommunicationChannelTIDL::workflow_instance_feed_data( bundle_add_byte(encoded, "data", data_bytes, data_size); if (encoded) { - int ret = rpc_port_proxy_mmi_invoke_workflow_instance_feed_data(rpc_h, + ret = rpc_port_proxy_mmi_invoke_workflow_instance_feed_data(rpc_h, local_workflow_instance_id, node_name.c_str(), port_name.c_str(), encoded); bundle_free(encoded); diff --git a/src/mmi/mmi-ipc-tidl.h b/src/mmi/mmi-ipc-tidl.h index 9d24214..f1a061e 100644 --- a/src/mmi/mmi-ipc-tidl.h +++ b/src/mmi/mmi-ipc-tidl.h @@ -39,7 +39,7 @@ public: private: int workflow_instance_create(int local_workflow_instance_id, mmi_standard_workflow_type_e workflow_type, - bool script_from_file, std::string script_info, void *user_data); + std::string script_info, void *user_data); int workflow_instance_destroy(int local_workflow_instance_id); int workflow_instance_set_attribute(int local_workflow_instance_id, mmi_attribute_h attribute); int workflow_instance_emit_signal(int local_workflow_instance_id, mmi_signal_h signal); diff --git a/src/mmi/mmi-plugin-storage.cpp b/src/mmi/mmi-plugin-storage.cpp index b9aa92f..6b1002f 100644 --- a/src/mmi/mmi-plugin-storage.cpp +++ b/src/mmi/mmi-plugin-storage.cpp @@ -62,7 +62,7 @@ mmi_node_instance_h mmi_plugin_storage_find_node_instance_by_port_instance(mmi_p return g_plugin_storage_impl.find_node_instance_by_port_instance(port_instance); } -static mmi_plugin_module_event_handler_info_s g_event_handler_info{nullptr, }; +static mmi_plugin_module_event_handler_info_s g_event_handler_info{{nullptr}, {nullptr}}; static void* g_event_handler_user_data = nullptr; void mmi_plugin_storage_set_plugin_module_event_handler( diff --git a/src/mmi/mmi-primitive-value.cpp b/src/mmi/mmi-primitive-value.cpp index 645a3d1..0c2ddc9 100644 --- a/src/mmi/mmi-primitive-value.cpp +++ b/src/mmi/mmi-primitive-value.cpp @@ -507,10 +507,10 @@ int mmi_primitive_value_from_bytes(unsigned char *bytes, size_t size, mmi_primit if (failed) { /* Since we are in a while loop, value->data should also be freed */ - size_t num_elements = value->datalen / sizeof(mmi_primitive_value_h); + num_elements = value->datalen / sizeof(mmi_primitive_value_h); for (size_t i = 0; i < num_elements; i++) { - auto element = get_element_pointer_in_array(value, i); - mmi_primitive_value_destroy(*element); + auto element_ = get_element_pointer_in_array(value, i); + mmi_primitive_value_destroy(*element_); } free(value->data); free(value); diff --git a/src/mmi/mmi-workflow-instance.cpp b/src/mmi/mmi-workflow-instance.cpp index b434ebf..2c97e35 100644 --- a/src/mmi/mmi-workflow-instance.cpp +++ b/src/mmi/mmi-workflow-instance.cpp @@ -30,6 +30,8 @@ #include "mmi-log.h" #include "mmi-workflow-instance-manager.h" +#include "mmi-workflow-script-generator.h" + using namespace mmi; using namespace mmi::communication; @@ -68,45 +70,9 @@ MMI_API int mmi_standard_workflow_instance_create(mmi_standard_workflow_type_e t return MMI_ERROR_NONE; } -MMI_API int mmi_custom_workflow_instance_create_from_script(const char *workflow_script, mmi_workflow_instance_h *instance) -{ - if (nullptr == instance || nullptr == workflow_script) { - LOGE("[ERROR] parameter is null"); - return MMI_ERROR_INVALID_PARAMETER; - } - - WorkflowInstanceManager *workflow_instance_manager = g_mmi_client_manager.get_workflow_instance_manager(); - if (nullptr == workflow_instance_manager) { - LOGE("[ERROR] Failed to get workflow instance manager"); - return MMI_ERROR_OPERATION_FAILED; - } - - WorkflowInstance *workflow_instance = workflow_instance_manager->create(); - if (workflow_instance) { - *instance = static_cast(workflow_instance); - - std::shared_ptr channel = g_mmi_client_manager.get_communication_channel(); - if (channel) { - ClientMessageWorkflowInstanceCreate msg; - msg.local_workflow_instance_id = - workflow_instance->get_local_workflow_instance_id(); - msg.workflow_type = MMI_STANDARD_WORKFLOW_NONE; - msg.script_from_file = false; - msg.script_info = std::string{workflow_script}; - msg.user_data = workflow_instance; - - channel->send(&msg); - } - } else { - return MMI_ERROR_OUT_OF_MEMORY; - } - - return MMI_ERROR_NONE; -} - -MMI_API int mmi_custom_workflow_instance_create_from_script_file(const char *workflow_script_path, mmi_workflow_instance_h *instance) +MMI_API int mmi_custom_workflow_instance_create(mmi_workflow_h workflow, mmi_workflow_instance_h *instance) { - if (nullptr == instance || nullptr == workflow_script_path) { + if (nullptr == workflow || nullptr == instance) { LOGE("[ERROR] parameter is null"); return MMI_ERROR_INVALID_PARAMETER; } @@ -123,12 +89,12 @@ MMI_API int mmi_custom_workflow_instance_create_from_script_file(const char *wor std::shared_ptr channel = g_mmi_client_manager.get_communication_channel(); if (channel) { + WorkflowScriptGenerator generator; ClientMessageWorkflowInstanceCreate msg; msg.local_workflow_instance_id = workflow_instance->get_local_workflow_instance_id(); msg.workflow_type = MMI_STANDARD_WORKFLOW_NONE; - msg.script_from_file = true; - msg.script_info = std::string{workflow_script_path}; + msg.script_info = generator.generate(workflow); msg.user_data = workflow_instance; channel->send(&msg); diff --git a/src/mmi/mmi-workflow-script-common.h b/src/mmi/mmi-workflow-script-common.h new file mode 100755 index 0000000..81f3e42 --- /dev/null +++ b/src/mmi/mmi-workflow-script-common.h @@ -0,0 +1,48 @@ +/* + * Copyright (c) 2023 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 __MMI_WORKFLOW_SCRIPT_COMMON_H__ +#define __MMI_WORKFLOW_SCRIPT_COMMON_H__ + +#include +#include + +enum class WorkflowScriptSection { + NONE, + WORKFLOW_INFO, + NODE_LIST, + LINK_LIST, + ATTRIBUTE_LIST, + OUTPUT_LIST, +}; + +typedef struct { + WorkflowScriptSection section; + std::string name; +} WorkflowScriptSectionName; + +struct WorkflowScriptHelper { + std::vector section_names{ + {WorkflowScriptSection::WORKFLOW_INFO, "@workflow"}, + {WorkflowScriptSection::NODE_LIST, "@node-list"}, + {WorkflowScriptSection::LINK_LIST, "@link-list"}, + {WorkflowScriptSection::ATTRIBUTE_LIST, "@attribute-list"}, + {WorkflowScriptSection::OUTPUT_LIST, "@output-list"}, + }; +}; +#endif /* __MMI_WORKFLOW_SCRIPT_COMMON_H__ */ \ No newline at end of file diff --git a/src/mmi/mmi-workflow-script-generator.h b/src/mmi/mmi-workflow-script-generator.h new file mode 100755 index 0000000..6cdd272 --- /dev/null +++ b/src/mmi/mmi-workflow-script-generator.h @@ -0,0 +1,243 @@ +/* + * Copyright (c) 2023 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 __MMI_WORKFLOW_SCRIPT_GENERATOR_H__ +#define __MMI_WORKFLOW_SCRIPT_GENERATOR_H__ + +#include "mmi-log.h" +#include "mmi-node-source.h" +#include "mmi-node-processor.h" +#include "mmi-node-logic.h" +#include "mmi-node-controller.h" +#include "mmi-node-action.h" +#include "mmi-node-custom.h" +#include "mmi-workflow-script-common.h" + +#include "magic_enum/magic_enum.hpp" + +class WorkflowScriptGenerator { +public: + WorkflowScriptGenerator() { + } + virtual ~WorkflowScriptGenerator() { + } + + std::string generate_workflow_info_section(mmi_workflow_s *workflow) { + std::string section_script; + auto found_section_name = std::find_if( + m_workflow_script_helper.section_names.begin(), + m_workflow_script_helper.section_names.end(), + [](WorkflowScriptSectionName section_name) { return section_name.section == WorkflowScriptSection::WORKFLOW_INFO; }); + if (found_section_name != m_workflow_script_helper.section_names.end()) { + section_script += found_section_name->name + "\n"; + /* If the workflow type is NONE, leave the name part */ + if (workflow->type != MMI_STANDARD_WORKFLOW_NONE) { + section_script += "name : " + std::string(magic_enum::enum_name(workflow->type)) + "\n"; + } + } + return section_script; + } + std::string generate_node_list_section(mmi_workflow_s *workflow) { + std::string section_script; + auto found_section_name = std::find_if( + m_workflow_script_helper.section_names.begin(), + m_workflow_script_helper.section_names.end(), + [](WorkflowScriptSectionName section_name) { return section_name.section == WorkflowScriptSection::NODE_LIST; }); + if (found_section_name != m_workflow_script_helper.section_names.end()) { + section_script += found_section_name->name + "\n"; + for (size_t index = 0;index < workflow->node_info_count;index++) { + std::string name = std::string(workflow->node_infos[index].name); + mmi_node_h node = workflow->node_infos[index].node; + mmi_node_type_e node_type; + mmi_node_get_type(node, &node_type); + switch (node_type) { + case MMI_NODE_TYPE_NONE: { + _E("Error : Node Type is NONE"); + } + break; + case MMI_NODE_TYPE_SOURCE: { + mmi_node_source_type_e node_source_type; + mmi_node_get_source_type(node, &node_source_type); + auto type_name = std::string(magic_enum::enum_name(node_source_type)); + + const std::string node_source_prefix = "MMI_NODE_SOURCE_TYPE_"; + std::string::size_type pos = type_name.find(node_source_prefix); + if (pos!= std::string::npos) { + type_name.erase(pos, node_source_prefix.length()); + } + + section_script += "[Source] " + type_name + " as " + name + "\n"; + } + break; + case MMI_NODE_TYPE_PROCESSOR: { + mmi_node_processor_type_e node_process_type; + mmi_node_get_processor_type(node, &node_process_type); + auto type_name = std::string(magic_enum::enum_name(node_process_type)); + + const std::string node_processor_prefix = "MMI_NODE_PROCESSOR_TYPE_"; + std::string::size_type pos = type_name.find(node_processor_prefix); + if (pos!= std::string::npos) { + type_name.erase(pos, node_processor_prefix.length()); + } + + section_script += "[Processor] " + type_name + " as " + name + "\n"; + } + break; + case MMI_NODE_TYPE_LOGIC: { + mmi_node_logic_type_e node_logic_type; + mmi_node_get_logic_type(node, &node_logic_type); + auto type_name = std::string(magic_enum::enum_name(node_logic_type)); + + const std::string node_logic_prefix = "MMI_NODE_LOGIC_TYPE_"; + std::string::size_type pos = type_name.find(node_logic_prefix); + if (pos!= std::string::npos) { + type_name.erase(pos, node_logic_prefix.length()); + } + + section_script += "[Logic] " + type_name + " as " + name + "\n"; + } + break; + case MMI_NODE_TYPE_CONTROLLER: { + mmi_node_controller_type_e node_controller_type; + mmi_node_get_controller_type(node, &node_controller_type); + auto type_name = std::string(magic_enum::enum_name(node_controller_type)); + + const std::string node_controller_prefix = "MMI_NODE_CONTROLLER_TYPE_"; + std::string::size_type pos = type_name.find(node_controller_prefix); + if (pos!= std::string::npos) { + type_name.erase(pos, node_controller_prefix.length()); + } + + section_script += "[Controller] " + type_name + " as " + name + "\n"; + } + break; + case MMI_NODE_TYPE_ACTION: { + mmi_node_action_type_e node_action_type; + mmi_node_get_action_type(node, &node_action_type); + auto type_name = std::string(magic_enum::enum_name(node_action_type)); + + const std::string node_action_prefix = "MMI_NODE_ACTION_TYPE_"; + std::string::size_type pos = type_name.find(node_action_prefix); + if (pos!= std::string::npos) { + type_name.erase(pos, node_action_prefix.length()); + } + + section_script += "[Action] " + type_name + " as " + name + "\n"; + } + break; + case MMI_NODE_TYPE_CUSTOM: { + const char *custom_type_id = nullptr; + mmi_node_get_custom_type(node, &custom_type_id); + if (custom_type_id) { + section_script += "[Custom] " + std::string(custom_type_id) + " as " + name + "\n"; + } + } + break; + } + } + } + + return section_script; + } + std::string generate_link_list_section(mmi_workflow_s *workflow) { + std::string section_script; + auto found_section_name = std::find_if( + m_workflow_script_helper.section_names.begin(), + m_workflow_script_helper.section_names.end(), + [](WorkflowScriptSectionName section_name) { return section_name.section == WorkflowScriptSection::LINK_LIST; }); + if (found_section_name != m_workflow_script_helper.section_names.end()) { + section_script += found_section_name->name + "\n"; + for (size_t i = 0; i < workflow->link_info_count; i++) { + section_script += + std::string(workflow->link_infos[i].from_node_name) + + "." + + std::string(workflow->link_infos[i].from_port_name) + + " -> " + + std::string(workflow->link_infos[i].to_node_name) + + "." + + std::string(workflow->link_infos[i].to_port_name) + + "\n"; + } + } + return section_script; + } + std::string generate_attribute_list_section(mmi_workflow_s *workflow) { + std::string section_script; + auto found_section_name = std::find_if( + m_workflow_script_helper.section_names.begin(), + m_workflow_script_helper.section_names.end(), + [](WorkflowScriptSectionName section_name) { return section_name.section == WorkflowScriptSection::ATTRIBUTE_LIST; }); + if (found_section_name != m_workflow_script_helper.section_names.end()) { + section_script += found_section_name->name + "\n"; + for (size_t i = 0; i < workflow->attribute_assignment_info_count; i++) { + section_script += + std::string(workflow->attribute_assignment_infos[i].target_node_name) + + "." + + std::string(workflow->attribute_assignment_infos[i].target_attribute_name) + + " as " + + std::string(workflow->attribute_assignment_infos[i].attribute_name) + + "\n"; + } + } + return section_script; + } + std::string generate_output_list_section(mmi_workflow_s *workflow) { + std::string section_script; + auto found_section_name = std::find_if( + m_workflow_script_helper.section_names.begin(), + m_workflow_script_helper.section_names.end(), + [](WorkflowScriptSectionName section_name) { return section_name.section == WorkflowScriptSection::OUTPUT_LIST; }); + if (found_section_name != m_workflow_script_helper.section_names.end()) { + section_script += found_section_name->name + "\n"; + for (size_t i = 0; i < workflow->output_assignment_info_count; i++) { + section_script += + std::string(workflow->output_assignment_infos[i].from_node_name) + + "." + + std::string(workflow->output_assignment_infos[i].from_port_name) + + " as " + + std::string(workflow->output_assignment_infos[i].output_name) + + "\n"; + } + } + return section_script; + } + + std::string generate(mmi_workflow_h workflow) { + std::string script; + + mmi_workflow_s *workflow_ptr = static_cast(workflow); + + script += generate_workflow_info_section(workflow_ptr); + script += "\n"; + script += generate_node_list_section(workflow_ptr); + script += "\n"; + script += generate_link_list_section(workflow_ptr); + script += "\n"; + script += generate_attribute_list_section(workflow_ptr); + script += "\n"; + script += generate_output_list_section(workflow_ptr); + script += "\n"; + + return script; + } + +private: + WorkflowScriptHelper m_workflow_script_helper; +}; + +#endif //__MMI_WORKFLOW_SCRIPT_GENERATOR_H__ diff --git a/src/mmi/mmi-workflow-script-parser.h b/src/mmi/mmi-workflow-script-parser.h index 0f0b170..de58678 100644 --- a/src/mmi/mmi-workflow-script-parser.h +++ b/src/mmi/mmi-workflow-script-parser.h @@ -30,26 +30,15 @@ #include "mmi-node-controller.h" #include "mmi-node-action.h" #include "mmi-node-custom.h" +#include "mmi-workflow-script-common.h" -enum class WorkflowScriptSection { - NONE, - WORKFLOW_INFO, - NODE_LIST, - LINK_LIST, - ATTRIBUTE_LIST, - OUTPUT_LIST, -}; +#include "magic_enum/magic_enum.hpp" typedef struct { WorkflowScriptSection section; std::regex pattern; } WorkflowScriptSectionPattern; -typedef struct { - WorkflowScriptSection section; - std::string name; -} WorkflowScriptSectionName; - typedef struct { mmi_standard_workflow_type_e type; std::string name; @@ -103,40 +92,134 @@ static inline void trim(std::string &s) { class WorkflowScriptParser { public: WorkflowScriptParser() { - m_section_names.push_back({WorkflowScriptSection::WORKFLOW_INFO, "@workflow"}); - m_section_names.push_back({WorkflowScriptSection::NODE_LIST, "@node-list"}); - m_section_names.push_back({WorkflowScriptSection::LINK_LIST, "@link-list"}); - m_section_names.push_back({WorkflowScriptSection::ATTRIBUTE_LIST, "@attribute-list"}); - m_section_names.push_back({WorkflowScriptSection::OUTPUT_LIST, "@output-list"}); - m_section_patterns.push_back({WorkflowScriptSection::WORKFLOW_INFO, std::regex("^name : ([a-zA-Z_]+)$")}); m_section_patterns.push_back({WorkflowScriptSection::NODE_LIST, std::regex("^\\[([a-zA-Z]+)\\] ([a-zA-Z_\\-.]+) as ([a-zA-Z0-9_]+)$")}); m_section_patterns.push_back({WorkflowScriptSection::LINK_LIST, std::regex("^([a-zA-Z0-9_.]+) -> ([a-zA-Z0-9_.]+)$")}); m_section_patterns.push_back({WorkflowScriptSection::ATTRIBUTE_LIST, std::regex("^([a-zA-Z0-9_.]+) as ([a-zA-Z0-9_]+)$")}); m_section_patterns.push_back({WorkflowScriptSection::OUTPUT_LIST, std::regex("^([a-zA-Z0-9_.]+) as ([a-zA-Z0-9_]+)$")}); - m_standard_workflow_names.push_back({MMI_STANDARD_WORKFLOW_WAKEUPLESS_COMMAND, "WAKEUPLESS_COMMAND"}); - m_standard_workflow_names.push_back({MMI_STANDARD_WORKFLOW_VOICE_TOUCH, "VOICE_TOUCH"}); - m_standard_workflow_names.push_back({MMI_STANDARD_WORKFLOW_USER_RECOGNITION, "USER_RECOGNITION"}); - - m_node_source_names.push_back({MMI_NODE_SOURCE_TYPE_MIC_AMBIENT, "MIC_AMBIENT"}); - m_node_source_names.push_back({MMI_NODE_SOURCE_TYPE_CAMERA, "CAMERA"}); - - m_node_processor_names.push_back({MMI_NODE_PROCESSOR_TYPE_ASR, "ASR"}); - m_node_processor_names.push_back({MMI_NODE_PROCESSOR_TYPE_VIDEO_CONVERTER, "VIDEO_CONVERTER"}); - m_node_processor_names.push_back({MMI_NODE_PROCESSOR_TYPE_FACE_RECOGNITION, "FACE_RECOGNITION"}); - m_node_processor_names.push_back({MMI_NODE_PROCESSOR_TYPE_SPEAKER_RECOGNITION, "SPEAKER_RECOGNITION"}); - - m_node_logic_names.push_back({MMI_NODE_LOGIC_TYPE_FIXED_STRING_MATCH, "FIXED_STRING_MATCH"}); - m_node_logic_names.push_back({MMI_NODE_LOGIC_TYPE_USER_COMPARISON, "USER_COMPARISON"}); - - m_node_controller_names.push_back({MMI_NODE_CONTROLLER_TYPE_SWITCH, "SWITCH"}); + int loop; + bool found; + + loop = 0; + found = true; + const std::string standard_workflow_prefix = "MMI_STANDARD_WORKFLOW_"; + do { + auto workflow_type = magic_enum::enum_cast(loop); + if (workflow_type.has_value()) { + auto workflow_name = std::string(magic_enum::enum_name(workflow_type.value())); + std::string::size_type pos = workflow_name.find(standard_workflow_prefix); + if (pos!= std::string::npos) { + workflow_name.erase(pos, standard_workflow_prefix.length()); + } + m_standard_workflow_names.push_back( + {static_cast(loop), workflow_name}); + } else { + found = false; + } + loop++; + } while(found); + + loop = 0; + found = true; + const std::string node_source_prefix = "MMI_NODE_SOURCE_TYPE_"; + do { + auto node_type = magic_enum::enum_cast(loop); + if (node_type.has_value()) { + auto node_name = std::string(magic_enum::enum_name(node_type.value())); + std::string::size_type pos = node_name.find(node_source_prefix); + if (pos!= std::string::npos) { + node_name.erase(pos, node_source_prefix.length()); + } + m_node_source_names.push_back( + {static_cast(loop), node_name}); + } else { + found = false; + } + loop++; + } while(found); + + loop = 0; + found = true; + const std::string node_processor_prefix = "MMI_NODE_PROCESSOR_TYPE_"; + do { + auto node_type = magic_enum::enum_cast(loop); + if (node_type.has_value()) { + auto node_name = std::string(magic_enum::enum_name(node_type.value())); + std::string::size_type pos = node_name.find(node_processor_prefix); + if (pos!= std::string::npos) { + node_name.erase(pos, node_processor_prefix.length()); + } + m_node_processor_names.push_back( + {static_cast(loop), node_name}); + } else { + found = false; + } + loop++; + } while(found); + + loop = 0; + found = true; + const std::string node_logic_prefix = "MMI_NODE_LOGIC_TYPE_"; + do { + auto node_type = magic_enum::enum_cast(loop); + if (node_type.has_value()) { + auto node_name = std::string(magic_enum::enum_name(node_type.value())); + std::string::size_type pos = node_name.find(node_logic_prefix); + if (pos!= std::string::npos) { + node_name.erase(pos, node_logic_prefix.length()); + } + m_node_logic_names.push_back( + {static_cast(loop), node_name}); + } else { + found = false; + } + loop++; + } while(found); + + loop = 0; + found = true; + const std::string node_controller_prefix = "MMI_NODE_CONTROLLER_TYPE_"; + do { + auto node_type = magic_enum::enum_cast(loop); + if (node_type.has_value()) { + auto node_name = std::string(magic_enum::enum_name(node_type.value())); + std::string::size_type pos = node_name.find(node_controller_prefix); + if (pos!= std::string::npos) { + node_name.erase(pos, node_controller_prefix.length()); + } + m_node_controller_names.push_back( + {static_cast(loop), node_name}); + } else { + found = false; + } + loop++; + } while(found); + + loop = 0; + found = true; + const std::string node_action_prefix = "MMI_NODE_ACTION_TYPE_"; + do { + auto node_type = magic_enum::enum_cast(loop); + if (node_type.has_value()) { + auto node_name = std::string(magic_enum::enum_name(node_type.value())); + std::string::size_type pos = node_name.find(node_action_prefix); + if (pos!= std::string::npos) { + node_name.erase(pos, node_action_prefix.length()); + } + m_node_action_names.push_back( + {static_cast(loop), node_name}); + } else { + found = false; + } + loop++; + } while(found); } virtual ~WorkflowScriptParser() { } bool process_section_declaration(const std::string &line) { - for (auto §ion_name : m_section_names) { + for (auto §ion_name : m_workflow_script_helper.section_names) { if (line == section_name.name) { m_current_section = section_name.section; LOGD("section changed to %d, [%s]", static_cast(m_current_section), line.c_str()); @@ -480,11 +563,11 @@ private: delete workflow_s; } + WorkflowScriptHelper m_workflow_script_helper; WorkflowScriptSection m_current_section{WorkflowScriptSection::NONE}; std::regex m_section_declaration_regex{"^@[a-zA-Z0-9_-]+$"}; - std::vector m_section_names; std::vector m_section_patterns; std::vector m_standard_workflow_names; @@ -500,7 +583,6 @@ private: std::string m_node_action_identifier{"Action"}; std::vector m_node_action_names; std::string m_node_custom_identifier{"Custom"}; - }; -#endif /* __MMI_WORKFLOW_SCRIPT_PARSER_H__ */ +#endif /* __MMI_WORKFLOW_SCRIPT_PARSER_H__ */ \ No newline at end of file diff --git a/src/mmi/mmi-workflow-script.cpp b/src/mmi/mmi-workflow-script.cpp index b3de785..02c57c0 100644 --- a/src/mmi/mmi-workflow-script.cpp +++ b/src/mmi/mmi-workflow-script.cpp @@ -21,6 +21,7 @@ #include "mmi-workflow.h" #include "mmi-workflow-script-parser.h" +#include "mmi-workflow-script-generator.h" #include #include @@ -80,3 +81,16 @@ MMI_API int mmi_workflow_create_from_script_file(const char *script_path, mmi_wo return MMI_ERROR_NONE; } +MMI_API int mmi_workflow_generate_script(mmi_workflow_h workflow, const char **script) { + if (workflow == nullptr || script == nullptr) { + LOGE("[ERROR] Invalid parameter"); + return MMI_ERROR_INVALID_PARAMETER; + } + + WorkflowScriptGenerator generator; + std::string generated = generator.generate(workflow); + + *script = strdup(generated.c_str()); + + return MMI_ERROR_NONE; +} diff --git a/tests/mmi-manager/plugin-module-registry/mmi-plugin-module-registry-tests.cpp b/tests/mmi-manager/plugin-module-registry/mmi-plugin-module-registry-tests.cpp index 45093c4..dfdd760 100644 --- a/tests/mmi-manager/plugin-module-registry/mmi-plugin-module-registry-tests.cpp +++ b/tests/mmi-manager/plugin-module-registry/mmi-plugin-module-registry-tests.cpp @@ -171,10 +171,10 @@ TEST_F(PluginModuleRegistryTest, PluginModuleProxyProperlyDestroyedWhenGoesOutOf PluginModuleInfo{mmi_plugin_module_type_e::SHARED_LIBRARY, "dummy.so"}); ASSERT_NE(nullptr, plugin_module); - std::map>& plugin_modules = registry.get_plugin_modules(); - auto it = plugin_modules.find(std::make_pair(mmi_plugin_module_type_e::SHARED_LIBRARY, "dummy.so")); + std::map>& another_plugin_modules = registry.get_plugin_modules(); + auto it = another_plugin_modules.find(std::make_pair(mmi_plugin_module_type_e::SHARED_LIBRARY, "dummy.so")); - ASSERT_NE(plugin_modules.end(), it); + ASSERT_NE(another_plugin_modules.end(), it); ASSERT_EQ(1, it->second.use_count()); } diff --git a/tidl/mmi.tidl b/tidl/mmi.tidl index d3ec98e..07f7ea3 100644 --- a/tidl/mmi.tidl +++ b/tidl/mmi.tidl @@ -1,7 +1,7 @@ interface mmi { void result_cb(string source_name, bundle data) delegate; - int workflow_instance_create(in int local_workflow_instance_id, in int workflow_type, in bool script_from_file, in string script_info); + int workflow_instance_create(in int local_workflow_instance_id, in int workflow_type, in string script_info); int workflow_instance_destroy(in int local_workflow_instance_id); int workflow_instance_set_attribute(in int local_workflow_instance_id, in bundle attribute); int workflow_instance_emit_signal(in int local_workflow_instance_id, in bundle signal);