From fd4c27c1c8437648079ee6b12ebe1becb21bfe45 Mon Sep 17 00:00:00 2001 From: BenceJanosSzabo <bence.janos.szabo@ericsson.com> Date: Mon, 8 May 2017 07:38:34 +0200 Subject: [PATCH] Modified get_provider_port port API function Change-Id: If3e4eb76ffcbc7d408ae756dc7cde75d41d8f26f Signed-off-by: BenceJanosSzabo <bence.janos.szabo@ericsson.com> --- compiler2/ttcn3/port.c | 24 ++++++++++++++++++++++-- core/Port.cc | 7 +------ core/Port.hh | 11 ++++++++--- 3 files changed, 31 insertions(+), 11 deletions(-) diff --git a/compiler2/ttcn3/port.c b/compiler2/ttcn3/port.c index 7eb70bce2..d2b98bede 100644 --- a/compiler2/ttcn3/port.c +++ b/compiler2/ttcn3/port.c @@ -2112,9 +2112,29 @@ void defPortClass(const port_def* pdef, output_struct* output) "}\n\n", class_name, sig->name); } + if (pdef->port_type == USER) { + def = mputstr(def, "public:\n"); + def = mputstr(def, "PORT* get_provider_port();"); + src = mputprintf(src, + "PORT* %s::get_provider_port() {\n" + "(void)get_default_destination();\n", class_name); + if (pdef->legacy) { + src = mputstr(src, "return this;\n"); + } else { + for (i = 0; i < pdef->provider_msg_outlist.nElements; i++) { + src = mputprintf(src, + "for (size_t i = 0; i < n_%i; i++) {\n" + "if (p_%i[i] != NULL) {\n" + "return p_%i[i];\n" + "}\n" + "}\n", (int)i, (int)i, (int)i); + } + src = mputstr(src, "return NULL;\n"); + } + src = mputstr(src, "}\n\n"); + } if (pdef->port_type == USER && !pdef->legacy) { - def = mputstr(def, "public:\n"); // add_port and remove_port is called after the map and unmap statements. for (i = 0; i < pdef->provider_msg_outlist.nElements; i++) { def = mputprintf(def, "void add_port(%s* p);\n", pdef->provider_msg_outlist.elements[i].name); @@ -2170,7 +2190,7 @@ void defPortClass(const port_def* pdef, output_struct* output) "void %s::change_port_state(translation_port_state state) {\n" "port_state = state;\n" "}\n\n", class_name); - + def = mputstr(def, "private:\n"); // Resets all port type variables to NULL def = mputstr(def, "void reset_port_variables();\n"); diff --git a/core/Port.cc b/core/Port.cc index 276ac6c87..002893364 100644 --- a/core/Port.cc +++ b/core/Port.cc @@ -504,12 +504,7 @@ boolean PORT::port_is_started() { } PORT* PORT::get_provider_port() { - get_default_destination(); - PORT* p = lookup_by_name(system_mappings[0], TRUE); - if (p == NULL) { - p = lookup_by_name(system_mappings[0], FALSE); - } - return p; + return NULL; } alt_status PORT::receive(const COMPONENT_template&, COMPONENT *, Index_Redirect*) diff --git a/core/Port.hh b/core/Port.hh index b7dd4605c..115a6cf20 100644 --- a/core/Port.hh +++ b/core/Port.hh @@ -139,10 +139,15 @@ public: boolean port_is_started(); // Returns the outer message port it is mapped to - // when the port works in translation mode. Otherwise returns NULL. + // when the port works in translation mode. + // In the case of dual faced ports it returns the port object + // it is called on (this). + // Otherwise returns NULL. // Emits errors when the port is mapped to more than one port or - // has both connections or mappings. - PORT* get_provider_port(); + // has both connections and mappings. + // This function is overridden only in the class of a port with translation + // capability and dual faced ports. + virtual PORT* get_provider_port(); boolean check_port_state(const CHARSTRING& type) const; static boolean any_check_port_state(const CHARSTRING& type); -- GitLab