1 // Copyright (C) 2007-2020 CEA/DEN, EDF R&D, OPEN CASCADE
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License, or (at your option) any later version.
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 // Lesser General Public License for more details.
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
20 #include "Calcium.hxx"
21 #include "CalciumInterface.hxx"
29 PySupervCompo::PySupervCompo( CORBA::ORB_ptr orb,
30 PortableServer::POA_ptr poa,
31 Engines::Container_ptr contain,
32 const char *instanceName,
33 const char *interfaceName,
35 Superv_Component_i(orb, poa,contain, instanceName, interfaceName,false,false)
39 PySupervCompo::~PySupervCompo()
47 void setDependency(provides_port*, char*, CalciumTypes::DependencyType);
51 throw CalciumException(err,LOC("Abort coupling"));
54 void setDependency(provides_port * port,char* type,CalciumTypes::DependencyType depend)
56 if(std::string(type)=="CALCIUM_real")
58 dynamic_cast<calcium_real_port_provides *>(port)->setDependencyType(depend);
60 else if(std::string(type)=="CALCIUM_double")
62 dynamic_cast<calcium_double_port_provides *>(port)->setDependencyType(depend);
64 else if(std::string(type)=="CALCIUM_integer")
66 dynamic_cast<calcium_integer_port_provides *>(port)->setDependencyType(depend);
68 else if(std::string(type)=="CALCIUM_long")
70 dynamic_cast<calcium_long_port_provides *>(port)->setDependencyType(depend);
72 else if(std::string(type)=="CALCIUM_string")
74 dynamic_cast<calcium_string_port_provides *>(port)->setDependencyType(depend);
76 else if(std::string(type)=="CALCIUM_logical")
78 dynamic_cast<calcium_logical_port_provides *>(port)->setDependencyType(depend);
80 else if(std::string(type)=="CALCIUM_complex")
82 dynamic_cast<calcium_complex_port_provides *>(port)->setDependencyType(depend);
86 std::cerr << "unknown type:" << std::endl;
90 void create_calcium_port(Superv_Component_i* compo,char* name,char* type,char *mode,char* depend)
92 std::stringstream msg;
93 msg << type << " " << mode << " " << depend;
94 CORBA::String_var componentName=compo->instanceName();
95 std::string containerName=compo->getContainerName();
96 Engines_DSC_interface::writeEvent("create_calcium_port",containerName,componentName,name,"",msg.str().c_str());
98 if(std::string(mode) == "IN")
100 provides_port * port ;
104 port = compo->create_provides_data_port(type);
105 compo->add_port(port, name);
106 if(std::string(depend) == "I")
107 setDependency(port,type,CalciumTypes::ITERATION_DEPENDENCY);
108 else if(std::string(depend) == "T")
109 setDependency(port,type,CalciumTypes::TIME_DEPENDENCY);
112 std::cerr << "create_calcium_port:unknown dependency: " << depend << std::endl;
115 catch(const Superv_Component_i::PortAlreadyDefined& ex)
117 //Port already defined : we use the old one
119 std::cerr << "create_calcium_port: " << ex.what() << std::endl;
123 std::cerr << "create_calcium_port: unknown exception" << std::endl;
126 else if(std::string(mode) == "OUT")
131 uport = compo->create_uses_data_port(type);
132 compo->add_port(uport, name);
134 catch(const Superv_Component_i::PortAlreadyDefined& ex)
136 //Port already defined : we use the old one
138 std::cerr << "create_calcium_port: " << ex.what() << std::endl;
142 std::cerr << "create_calcium_port: unknown exception" << std::endl;
148 std::cerr << "create_calcium_port:Unknown mode: " << mode << std::endl;
152 char** create_multiple_calcium_port(Superv_Component_i* compo,char* name,char* type,char *mode,char* depend, int number)
156 std::cerr << "Cannot create a multiple calcium port with number <= 0, value is " << number << std::endl;
159 char** names = new char*[number];
160 for (int i = 0; i < number; i++)
162 std::ostringstream new_name;
163 new_name << name << "_" << i;
164 std::string cpp_name = new_name.str();
165 char * c_name = new char [cpp_name.size()+1];
166 strcpy(c_name, cpp_name.c_str());
171 for (int i = 0; i < number; i++)
173 create_calcium_port(compo, (char*)std::string(names[i]).c_str(), type, mode, depend);