/* 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);
/* 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);
--bindir /usr/local/mmi/bin \
--libdir /usr/local/mmi/lib \
--datadir /usr/local/mmi/share \
+ --buildtype debug \
./linux_build
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};
}
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);
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;
}
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;
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)) {
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)),
}
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<CommunicationChannelTIDL*>(user_data);
msg.sender = sender;
msg.local_workflow_instance_id = local_workflow_instance_id;
msg.workflow_type = static_cast<mmi_standard_workflow_type_e>(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<Message*>(&msg));
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,
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);
}
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;
_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);
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<IWorkflowPrototypeStore> prototype_store =
std::make_shared<WorkflowPrototypeScriptStore>();
'.',
'../common',
'../../capi',
+ '../../external',
mmi_extra_include_dir,
)
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);
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;
case CLIENT_MESSAGE_TYPE::WORKFLOW_INSTANCE_CREATE: {
auto subclass = static_cast<ClientMessageWorkflowInstanceCreate*>(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: {
}
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);
}
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;
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;
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) {
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;
}
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) {
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;
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);
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);
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(
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);
#include "mmi-log.h"
#include "mmi-workflow-instance-manager.h"
+#include "mmi-workflow-script-generator.h"
+
using namespace mmi;
using namespace mmi::communication;
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<void*>(workflow_instance);
-
- std::shared_ptr<CommunicationChannelClient> 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;
}
std::shared_ptr<CommunicationChannelClient> 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);
--- /dev/null
+/*
+ * 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 <string>
+#include <vector>
+
+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<WorkflowScriptSectionName> 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
--- /dev/null
+/*
+ * 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<mmi_workflow_s*>(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__
#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;
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<mmi_standard_workflow_type_e>(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<mmi_standard_workflow_type_e>(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<mmi_node_source_type_e>(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<mmi_node_source_type_e>(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<mmi_node_processor_type_e>(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<mmi_node_processor_type_e>(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<mmi_node_logic_type_e>(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<mmi_node_logic_type_e>(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<mmi_node_controller_type_e>(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<mmi_node_controller_type_e>(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<mmi_node_action_type_e>(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<mmi_node_action_type_e>(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<int>(m_current_section), line.c_str());
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<WorkflowScriptSectionName> m_section_names;
std::vector<WorkflowScriptSectionPattern> m_section_patterns;
std::vector<StandardWorkflowName> m_standard_workflow_names;
std::string m_node_action_identifier{"Action"};
std::vector<StandardNodeActionName> 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
#include "mmi-workflow.h"
#include "mmi-workflow-script-parser.h"
+#include "mmi-workflow-script-generator.h"
#include <fstream>
#include <sstream>
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;
+}
PluginModuleInfo{mmi_plugin_module_type_e::SHARED_LIBRARY, "dummy.so"});
ASSERT_NE(nullptr, plugin_module);
- std::map<PluginModuleRegistry_Derived::plugin_module_map_key, std::weak_ptr<IPluginModuleProxy>>& 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<PluginModuleRegistry_Derived::plugin_module_map_key, std::weak_ptr<IPluginModuleProxy>>& 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());
}
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);