diff --git a/compiler2/ttcn3/Statement.cc b/compiler2/ttcn3/Statement.cc index a43df666a58fb7c0dfa67d048dcfe1ea096a72a8..37d0fbf2678c2db22ba804b2d4c2b87d6c82d111 100644 --- a/compiler2/ttcn3/Statement.cc +++ b/compiler2/ttcn3/Statement.cc @@ -7447,37 +7447,39 @@ error: expression_struct expr; Code::init_expr(&expr); bool warning = false; - if (!config_op.compref1->get_expr_governor(Type::EXPECTED_DYNAMIC_VALUE)) { - warning = true; - if (strcmp(opname, "map") == 0) { - config_op.compref2->warning( - "Cannot determine the type of the component in the first parameter." - "The port translation will not work."); + if (config_op.translate == true) { + if (!config_op.compref1->get_expr_governor(Type::EXPECTED_DYNAMIC_VALUE)) { + warning = true; + if (strcmp(opname, "map") == 0) { + config_op.compref2->warning( + "Cannot determine the type of the component in the first parameter." + "The port translation will not work."); + } } - } - if (!config_op.compref2->get_expr_governor(Type::EXPECTED_DYNAMIC_VALUE)) { - warning = true; - if (strcmp(opname, "map") == 0) { - config_op.compref2->warning( - "Cannot determine the type of the component in the second parameter." - "The port translation will not work."); + if (!config_op.compref2->get_expr_governor(Type::EXPECTED_DYNAMIC_VALUE)) { + warning = true; + if (strcmp(opname, "map") == 0) { + config_op.compref2->warning( + "Cannot determine the type of the component in the second parameter." + "The port translation will not work."); + } + } + if (warning == false) { + expr.expr = mputstr(expr.expr, "if (!("); + config_op.portref1->generate_code_portref(&expr, my_sb); + expr.expr = mputstr(expr.expr, ".port_is_started())) {\n"); + config_op.portref1->generate_code_portref(&expr, my_sb); + expr.expr = mputstr(expr.expr, ".activate_port(TRUE);\n"); + config_op.portref1->generate_code_portref(&expr, my_sb); + expr.expr = mputstr(expr.expr, ".start();\n}\n"); + expr.expr = mputstr(expr.expr, "if (!("); + config_op.portref2->generate_code_portref(&expr, my_sb); + expr.expr = mputstr(expr.expr, ".port_is_started())) {\n"); + config_op.portref2->generate_code_portref(&expr, my_sb); + expr.expr = mputstr(expr.expr, ".activate_port(TRUE);\n"); + config_op.portref2->generate_code_portref(&expr, my_sb); + expr.expr = mputstr(expr.expr, ".start();\n}\n"); } - } - if (config_op.translate == true && warning == false) { - expr.expr = mputstr(expr.expr, "if (!("); - config_op.portref1->generate_code_portref(&expr, my_sb); - expr.expr = mputstr(expr.expr, ".port_is_started())) {\n"); - config_op.portref1->generate_code_portref(&expr, my_sb); - expr.expr = mputstr(expr.expr, ".activate_port(TRUE);\n"); - config_op.portref1->generate_code_portref(&expr, my_sb); - expr.expr = mputstr(expr.expr, ".start();\n}\n"); - expr.expr = mputstr(expr.expr, "if (!("); - config_op.portref2->generate_code_portref(&expr, my_sb); - expr.expr = mputstr(expr.expr, ".port_is_started())) {\n"); - config_op.portref2->generate_code_portref(&expr, my_sb); - expr.expr = mputstr(expr.expr, ".activate_port(TRUE);\n"); - config_op.portref2->generate_code_portref(&expr, my_sb); - expr.expr = mputstr(expr.expr, ".start();\n}\n"); } expr.expr = mputprintf(expr.expr, "TTCN_Runtime::%s_port(", opname); config_op.compref1->generate_code_expr(&expr); diff --git a/compiler2/ttcn3/port.c b/compiler2/ttcn3/port.c index c6b9542acedabad331d4911aa856dfd0b75ff773..7eb70bce26d53ae3015bc62547c8fc86b8fb3f37 100644 --- a/compiler2/ttcn3/port.c +++ b/compiler2/ttcn3/port.c @@ -2243,8 +2243,7 @@ void defPortClass(const port_def* pdef, output_struct* output) if (pdef->testport_type != INTERNAL && (pdef->port_type == REGULAR || (pdef->port_type == USER && !pdef->legacy))) { /* virtual functions for transmission (implemented by the test port) */ - def = mputprintf(def, "%s:\n", - (pdef->port_type == USER && !pdef->legacy) ? "public" : "protected"); + def = mputstr(def, "protected:\n"); /* outgoing_send functions */ size_t n_used = 0; const char** used = NULL; @@ -2291,10 +2290,12 @@ void defPortClass(const port_def* pdef, output_struct* output) } } if (found) { + // Call outgoing_public_send so the outgoing_send can remain + // protected src = mputprintf(src, "for (size_t i = 0; i < n_%i; i++) {\n" "if (p_%i[i] != NULL) {\n" - "p_%i[i]->outgoing_send(send_par);\n" + "p_%i[i]->outgoing_public_send(send_par);\n" "return;\n}\n" "}\n", (int)j, (int)j, (int)j); } @@ -2354,10 +2355,12 @@ void defPortClass(const port_def* pdef, output_struct* output) } } if (found) { + // Call outgoing_public_send so the outgoing_send can remain + // protected src = mputprintf(src, "for (size_t i = 0; i < n_%i; i++) {\n" "if (p_%i[i] != NULL) {\n" - "p_%i[i]->outgoing_send(send_par);\n" + "p_%i[i]->outgoing_public_send(send_par);\n" "return;\n}\n" "}\n", (int)k, (int)k, (int)k); } @@ -2423,6 +2426,18 @@ void defPortClass(const port_def* pdef, output_struct* output) def = mputstr(def, "public:\n"); + // Generate new functions for provider types to avoid changing the visibility of outgoing_send + if (pdef->n_mapper_name > 0) { + for (i = 0; i < pdef->msg_out.nElements; i++) { + def = mputprintf(def, "void outgoing_public_send(" + "const %s& send_par);\n", pdef->msg_out.elements[i].name); + src = mputprintf(src, + "void %s::outgoing_public_send(const %s& send_par) {\n" + "outgoing_send(send_par);\n" + "}\n\n", class_name, pdef->msg_out.elements[i].name); + } + } + /* Generic receive routines (without message type) */ if (has_msg_queue) { /* generic receive function */ @@ -3308,9 +3323,6 @@ void generateTestPortSkeleton(const port_def *pdef) class_name, base_class_name, class_name, pdef->port_type == REGULAR || pdef->port_type == USER ? " = NULL" : "", class_name); - if (pdef->port_type == PROVIDER && pdef->n_mapper_name > 0) { - fprintf(fp, "public:\n"); - } for (i = 0; i < pdef->msg_out.nElements; i++) { fprintf(fp, "\tvoid outgoing_send(const %s& send_par", pdef->msg_out.elements[i].name); diff --git a/core/Port.cc b/core/Port.cc index e89ea5314769bab435e7ed5a5439ec1d99324167..7b73f9ffc0451283169d9112013728bd134076f4 100644 --- a/core/Port.cc +++ b/core/Port.cc @@ -2173,7 +2173,7 @@ void PORT::map(const char *system_port, boolean translation) TTCN_warning("Port %s is already mapped to system:%s." " Map operation was ignored.", port_name, system_port); } else { - TTCN_warning("Port %s is already mapped to system:%s." + TTCN_warning("System:%s is already mapped to port %s." " Map operation was ignored.", system_port, port_name); } return; @@ -2227,7 +2227,7 @@ void PORT::unmap(const char *system_port, boolean translation) TTCN_warning("Port %s is not mapped to system:%s. " "Unmap operation was ignored.", port_name, system_port); } else { - TTCN_warning("Porta %s is not mapped to system:%s. " + TTCN_warning("System:%s is not mapped to port %s. " "Unmap operation was ignored.", system_port, port_name); } return; @@ -2254,6 +2254,8 @@ void PORT::unmap(const char *system_port, boolean translation) // Currently the requirement is that the port needs to map only when mapped // to one port. If it would be mapped to more ports then this call would // remove all translation capability. + // This does not resets the 'port' variables in the port type definition, but + // the internal c++ port variables of the port type. if (n_system_mappings == 0) { reset_port_variables(); } diff --git a/core/Runtime.cc b/core/Runtime.cc index e08453d6a280a8bd5f01caa84a3e6882aaec52d7..23bae2dc2fce92c1b7a093e5483f8d2d5e1780df 100644 --- a/core/Runtime.cc +++ b/core/Runtime.cc @@ -1849,7 +1849,10 @@ void TTCN_Runtime::map_port( case SINGLE_TESTCASE: if (comp_reference != MTC_COMPREF) TTCN_error("Only the ports of mtc " "can be mapped in single mode."); - PORT::map_port(comp_port, system_port, translation); + PORT::map_port(comp_port, system_port, FALSE); + if (translation == TRUE) { + PORT::map_port(comp_port, system_port, TRUE); + } break; case MTC_TESTCASE: TTCN_Communication::send_map_req(comp_reference, comp_port, @@ -1927,7 +1930,10 @@ void TTCN_Runtime::unmap_port( case SINGLE_TESTCASE: if (comp_reference != MTC_COMPREF) TTCN_error("Only the ports of mtc " "can be unmapped in single mode."); - PORT::unmap_port(comp_port, system_port, translation); + PORT::unmap_port(comp_port, system_port, FALSE); + if (translation == TRUE) { + PORT::unmap_port(comp_port, system_port, TRUE); + } break; case MTC_TESTCASE: TTCN_Communication::send_unmap_req(comp_reference, comp_port, diff --git a/mctr2/mctr/MainController.cc b/mctr2/mctr/MainController.cc index 336944d6ffc5cd43d752604303be0273b4955272..acad299fba793a2c15ca5ce4973b32f270936766 100644 --- a/mctr2/mctr/MainController.cc +++ b/mctr2/mctr/MainController.cc @@ -5435,19 +5435,10 @@ void MainController::process_unmap_req(component_struct *tc) delete [] system_port; return; } - port_connection *conn = NULL; - if (translation == FALSE) { - conn = find_connection(src_compref, src_port, + port_connection *conn = find_connection(src_compref, src_port, SYSTEM_COMPREF, system_port); - } else { - conn = find_connection(SYSTEM_COMPREF, src_port, - src_compref, system_port); - } if (conn == NULL) { send_unmap_ack(tc); - if (translation == TRUE) { - send_unmap(components[src_compref], src_port, system_port, TRUE); - } } else { switch (conn->conn_state) { case CONN_MAPPED: diff --git a/regression_test/portTranslation/P1.hh b/regression_test/portTranslation/P1.hh index ddba114e0e00a59a30ac6208446dc89d64b0f34b..0a35c8c19bb8dabc8286ad1c292675ab7e87284d 100644 --- a/regression_test/portTranslation/P1.hh +++ b/regression_test/portTranslation/P1.hh @@ -49,7 +49,6 @@ protected: void user_start(); void user_stop(); -public: void outgoing_send(const MyRec& send_par); void outgoing_send(const OCTETSTRING& send_par); void outgoing_send(const BITSTRING& send_par); diff --git a/regression_test/portTranslation/P2.hh b/regression_test/portTranslation/P2.hh index bb66effe97ba7a892ab02a767caf14e323eff2ef..f14d90ff5a8312283e95abfcda67793500fc9ccb 100644 --- a/regression_test/portTranslation/P2.hh +++ b/regression_test/portTranslation/P2.hh @@ -45,7 +45,6 @@ protected: void user_start(); void user_stop(); -public: void outgoing_send(const OCTETSTRING& send_par); void outgoing_send(const MyRec& send_par); void outgoing_send(const BITSTRING& send_par); diff --git a/regression_test/portTranslation/VP1.hh b/regression_test/portTranslation/VP1.hh index fbafa34ad9e9c4da77b853d7c1e30173ae60bdc3..00b3282e0b77c8720bb3c9aa0f23ada2fd7d693c 100644 --- a/regression_test/portTranslation/VP1.hh +++ b/regression_test/portTranslation/VP1.hh @@ -45,7 +45,6 @@ protected: void user_start(); void user_stop(); -public: void outgoing_send(const INTEGER& send_par); void outgoing_send(const CHARSTRING& send_par); void outgoing_send(const RoI& send_par);