1 // Copyright (C) 2006-2024 CEA, EDF
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 "RuntimeSALOME.hxx"
21 #include "SessionCataLoader.hxx"
22 #include "ComponentDefinition.hxx"
23 #include "ServiceNode.hxx"
24 #include "TypeCode.hxx"
30 #include "YacsTrace.hxx"
34 using namespace YACS::ENGINE;
36 SessionCataLoader::SessionCataLoader(const std::string& path):CatalogLoader(path)
38 //path should be a CORBA URI like that : corbaname::machine:port/NameService#Kernel.dir/ModulCatalog.object
39 //or equivalent corbaname
43 In salome catalog, the type names for CALCIUM are : INTEGER, FLOAT,DOUBLE,STRING,BOOLEAN
54 std::map<SALOME_ModuleCatalog::DataStreamType,std::string> datastreamMap;
57 //! import a SALOME component definition in a YACS catalog
59 * SALOME components can have several interfaces.
60 * YACS for the moment allows only one interface by component, so if there is only one interface we import it.
61 * If we have more than one interface, we import the one with the same name as the component or the first one.
63 * \param cata : a YACS catalog
64 * \param compo : a CORBA reference on a component in a SALOME_ModuleCatalog
66 void SessionCataLoader::importComponent(Catalog* cata,SALOME_ModuleCatalog::Acomponent_ptr compo)
68 CORBA::String_var componame = compo->componentname();
70 DEBTRACE("Implementation type : " << compo->implementation_type());
72 SALOME_ModuleCatalog::ImplType imptyp=compo->implementation_type();
73 if(imptyp == SALOME_ModuleCatalog::SO)DEBTRACE("Dyn lib");
74 if(imptyp == SALOME_ModuleCatalog::PY)DEBTRACE("Python module");
75 if(imptyp == SALOME_ModuleCatalog::EXE)DEBTRACE("Executable");
76 DEBTRACE("Implementation name : " << compo->implementation_name());
79 SALOME_ModuleCatalog::ListOfInterfaces_var interfacename_list = compo->GetInterfaceList();
80 if(interfacename_list->length() == 0)
83 for (int j = 0; j < interfacename_list->length();j++)
85 DEBTRACE ("Interface : " << interfacename_list[j]);
86 if(strcmp(componame,interfacename_list[j]) == 0)
92 DEBTRACE ("Interface found : " << interfacename_list[found]);
93 ComponentDefinition* compodef=new ComponentDefinition((const char*)componame);
95 SALOME_ModuleCatalog::DefinitionInterface_var interface;
96 interface= compo->GetInterface(interfacename_list[found]);
97 SALOME_ModuleCatalog::ListOfInterfaceService services = interface->interfaceservicelist;
98 for (int k = 0; k < services.length(); k++)
100 DEBTRACE("Service : " << services[k].ServiceName);
101 const char* s=services[k].ServiceName;
102 //create a new service node (prototype)
103 ServiceNode* node=getRuntime()->createCompoNode("Salome",s);
104 node->setRef((const char*)componame);
106 for (int kk=0;kk< services[k].ServiceinParameter.length();kk++)
108 DEBTRACE("Parameter : " << services[k].ServiceinParameter[kk].Parametername);
109 DEBTRACE("Type : " << services[k].ServiceinParameter[kk].Parametertype);
110 const char* ty=services[k].ServiceinParameter[kk].Parametertype;
111 if(cata->_typeMap.count(ty)==0)
113 std::stringstream msg;
114 msg << "Type " <<ty <<" does not exist. Service " << s << " of component " << componame << " is not available";
115 _errors=_errors+"\n"+msg.str();
116 std::cerr << msg.str() << std::endl;
117 compodef->_serviceMap[s+std::string("_IS_INVALID")]=0;
122 const char* name=services[k].ServiceinParameter[kk].Parametername;
123 node->edAddInputPort(name,cata->_typeMap[ty]);
125 if(node == 0)continue;
127 for (int kk=0;kk< services[k].ServiceoutParameter.length();kk++)
129 DEBTRACE("Parameter : " << services[k].ServiceoutParameter[kk].Parametername);
130 DEBTRACE("Type : " << services[k].ServiceoutParameter[kk].Parametertype);
131 const char* ty=services[k].ServiceoutParameter[kk].Parametertype;
132 if(cata->_typeMap.count(ty)==0)
134 std::stringstream msg;
135 msg << "Type " <<ty <<" does not exist. Service " << s << " of component " << componame << " is not available";
136 _errors=_errors+"\n"+msg.str();
137 std::cerr << msg.str() << std::endl;
138 compodef->_serviceMap[s+std::string("_IS_INVALID")]=0;
143 const char* name=services[k].ServiceoutParameter[kk].Parametername;
144 node->edAddOutputPort(name,cata->_typeMap[ty]);
146 if(node == 0)continue;
148 for (int kk=0;kk< services[k].ServiceinDataStreamParameter.length();kk++)
150 DEBTRACE("Parameter : " << services[k].ServiceinDataStreamParameter[kk].Parametername);
151 DEBTRACE("Type : " << services[k].ServiceinDataStreamParameter[kk].Parametertype);
152 DEBTRACE("Dependency : " << services[k].ServiceinDataStreamParameter[kk].Parameterdependency);
154 const char* ty=services[k].ServiceinDataStreamParameter[kk].Parametertype;
156 std::string ty=datastreamMap[services[k].ServiceinDataStreamParameter[kk].Parametertype];
158 if(cata->_typeMap.count(ty)==0)
160 std::stringstream msg;
161 msg << "Type " <<ty <<" does not exist. Service " << s << " of component " << componame << " is not available";
162 _errors=_errors+"\n"+msg.str();
163 std::cerr << msg.str() << std::endl;
164 compodef->_serviceMap[s+std::string("_IS_INVALID")]=0;
169 const char* name=services[k].ServiceinDataStreamParameter[kk].Parametername;
170 InputDataStreamPort* port;
171 port=node->edAddInputDataStreamPort(name,cata->_typeMap[ty]);
173 if(node == 0)continue;
175 for (int kk=0;kk< services[k].ServiceoutDataStreamParameter.length();kk++)
177 DEBTRACE("Parameter : " << services[k].ServiceoutDataStreamParameter[kk].Parametername);
178 DEBTRACE("Type : " << services[k].ServiceoutDataStreamParameter[kk].Parametertype);
179 DEBTRACE("Dependency : " << services[k].ServiceoutDataStreamParameter[kk].Parameterdependency);
181 const char* ty=services[k].ServiceoutDataStreamParameter[kk].Parametertype;
183 std::string ty=datastreamMap[services[k].ServiceoutDataStreamParameter[kk].Parametertype];
185 if(cata->_typeMap.count(ty)==0)
187 std::stringstream msg;
188 msg << "Type " <<ty <<" does not exist. Service " << s << " of component " << componame << " is not available";
189 _errors=_errors+"\n"+msg.str();
190 std::cerr << msg.str() << std::endl;
191 compodef->_serviceMap[s+std::string("_IS_INVALID")]=0;
196 const char* name=services[k].ServiceoutDataStreamParameter[kk].Parametername;
197 OutputDataStreamPort* port;
198 port=node->edAddOutputDataStreamPort(name,cata->_typeMap[ty]);
199 // Set all properties for this port
201 std::map<std::string, std::string>::const_iterator pt;
202 for(pt=p._props.begin();pt!=p._props.end();pt++)
203 port->setProperty((*pt).first,(*pt).second);
206 if(node == 0)continue;
207 compodef->_serviceMap[s]=node;
210 /* Even if a component has no service, put it in the catalog
211 if(compodef->_serviceMap.size() > 0)
213 cata->_componentMap[(const char*)componame]=compodef;
220 cata->_componentMap[(const char*)componame]=compodef;
223 SessionCataLoader::~SessionCataLoader()
225 DEBTRACE ("SessionCataLoader::~SessionCataLoader");
228 void SessionCataLoader::loadTypes(Catalog* cata,SALOME_ModuleCatalog::ModuleCatalog_ptr catalog)
230 Runtime* r=getRuntime();
231 std::map<std::string,TypeCode*>& typeMap=cata->_typeMap;
233 SALOME_ModuleCatalog::ListOfTypeDefinition_var types_list=catalog->GetTypes();
234 for (int i=0; i< types_list->length(); i++)
236 const char* name=types_list[i].name;
237 DEBTRACE ("type : " << types_list[i].name << " " << types_list[i].kind);
238 if(types_list[i].kind == SALOME_ModuleCatalog::Dble)
240 r->_tc_double->incrRef();
241 typeMap[name]=r->_tc_double;
243 else if(types_list[i].kind == SALOME_ModuleCatalog::Int)
245 r->_tc_int->incrRef();
246 typeMap[name]=r->_tc_int;
248 else if(types_list[i].kind == SALOME_ModuleCatalog::Bool)
250 r->_tc_bool->incrRef();
251 typeMap[name]=r->_tc_bool;
253 else if(types_list[i].kind == SALOME_ModuleCatalog::Str)
255 r->_tc_string->incrRef();
256 typeMap[name]=r->_tc_string;
258 else if(types_list[i].kind == SALOME_ModuleCatalog::Seq)
260 const char* content=types_list[i].content;
261 if ( typeMap.find(content) != typeMap.end() )
262 typeMap[name]=r->createSequenceTc(name,name,typeMap[content]);
265 else if(types_list[i].kind == SALOME_ModuleCatalog::Array)
267 //ignored, for the moment !!
269 else if(types_list[i].kind == SALOME_ModuleCatalog::Objref)
271 std::list<TypeCodeObjref *> ltc;
272 const char* id=types_list[i].id;
273 for (int m=0; m< types_list[i].bases.length(); m++)
275 const char* b_name=types_list[i].bases[m];
276 if(typeMap.find(b_name) != typeMap.end())
277 ltc.push_back((TypeCodeObjref *)typeMap[b_name]);
280 typeMap[name]=r->createInterfaceTc(id,name,ltc);
282 else if(types_list[i].kind == SALOME_ModuleCatalog::Struc)
284 TypeCodeStruct* t=r->createStructTc("",name);
285 for (int m=0; m< types_list[i].members.length(); m++)
287 const char* m_name=types_list[i].members[m].name;
288 const char* m_type=types_list[i].members[m].type;
289 if(typeMap.find(m_type) != typeMap.end())
290 t->addMember(m_name,typeMap[m_type]);
297 std::cerr << "Unknown kind: " << types_list[i].kind << std::endl;
302 void SessionCataLoader::loadTypesOld(Catalog* cata)
304 // Fill the types map with built in types
305 Runtime* r=getRuntime();
306 std::map<std::string,TypeCode*>& typeMap=cata->_typeMap;
309 //Add old Calcium data types for KERNEL
310 if(typeMap.count("CALCIUM_double")!=0)
312 typeMap["DOUBLE"]=typeMap["CALCIUM_double"];
313 typeMap["DOUBLE"]->incrRef();
315 if(typeMap.count("CALCIUM_real")!=0)
317 typeMap["FLOAT"]=typeMap["CALCIUM_real"];
318 typeMap["FLOAT"]->incrRef();
320 if(typeMap.count("CALCIUM_integer")!=0)
322 typeMap["INTEGER"]=typeMap["CALCIUM_integer"];
323 typeMap["INTEGER"]->incrRef();
325 if(typeMap.count("CALCIUM_boolean")!=0)
327 typeMap["BOOLEAN"]=typeMap["CALCIUM_boolean"];
328 typeMap["BOOLEAN"]->incrRef();
330 if(typeMap.count("CALCIUM_string")!=0)
332 typeMap["STRING"]=typeMap["CALCIUM_string"];
333 typeMap["STRING"]->incrRef();
339 typeMap["GEOM_Object"]=TypeCode::interfaceTc("IDL:GEOM/GEOM_Object:1.0","GEOM_Object");
340 typeMap["ListOfLong"]=TypeCode::sequenceTc("ListOfLong","ListOfLong",r->_tc_int);
341 typeMap["GEOM_List"]=TypeCode::interfaceTc("IDL:GEOM/GEOM_List:1.0","GEOM_List");
342 typeMap["GEOM_Superv"]=TypeCode::interfaceTc("IDL:GEOM/GEOM_Superv:1.0","GEOM_Superv");
343 typeMap["ListOfGO"]=TypeCode::sequenceTc("ListOfGO","ListOfGO",cata->_typeMap["GEOM_Object"]);
344 typeMap["string_array"]=TypeCode::sequenceTc("string_array","string_array",r->_tc_string);
345 r->_tc_int->incrRef();
346 typeMap["BCErrorType"]=r->_tc_int;
347 typeMap["BCError"]=TypeCode::structTc("","BCError");
348 ((TypeCodeStruct*)typeMap["BCError"])->addMember("incriminated",typeMap["ListOfLong"]);
349 typeMap["BCErrors"]=TypeCode::sequenceTc("BCErrors","BCErrors",typeMap["BCError"]);
350 typeMap["GEOM_Gen"]=TypeCode::interfaceTc("IDL:GEOM/GEOM_Gen:1.0","GEOM_Gen");
351 typeMap["GEOM_Object"]->incrRef();
352 typeMap["GEOM_Shape"]=typeMap["GEOM_Object"];
357 typeMap["SMESH_Mesh"]=TypeCode::interfaceTc("IDL:Mesh/SMESH_Mesh:1.0","SMESH_Mesh");
358 typeMap["SMESH_Hypothesis"]=TypeCode::interfaceTc("IDL:SMESH/SMESH_Hypothesis:1.0","SMESH_Hypothesis");
363 typeMap["MED"]=TypeCode::interfaceTc("IDL:SALOME_MED/MED:1.0","MED");
364 typeMap["FIELD"]=TypeCode::interfaceTc("IDL:SALOME_MED/FIELD:1.0","FIELD");
365 // TODO : FIELDDOUBLE inherits FIELD
366 typeMap["FIELDDOUBLE"]=TypeCode::interfaceTc("IDL:SALOME_MED/FIELDDOUBLE:1.0","FIELDDOUBLE");
371 typeMap["AddComponent"]=TypeCode::interfaceTc("IDL:SuperVisionTest/AddComponent:1.0","AddComponent");
372 typeMap["AddComponent"]->incrRef();
373 typeMap["AddInterface"]=typeMap["AddComponent"];
374 typeMap["SuperVisionTest/Adder"]=TypeCode::interfaceTc("IDL:SuperVisionTest/Adder:1.0","SuperVisionTest/Adder");
375 typeMap["AdditionComponent/Adder"]=TypeCode::interfaceTc("IDL:AdditionComponent/Adder:1.0","AdditionComponent/Adder");
376 typeMap["Syr"]=TypeCode::interfaceTc("IDL:SuperVisionTest/Syr:1.0","Syr");
377 typeMap["ListOfSyr"]=TypeCode::interfaceTc("IDL:SuperVisionTest/ListOfSyr:1.0","ListOfSyr");
381 void SessionCataLoader::loadCata(Catalog* cata)
383 DEBTRACE("SessionCataLoader::load")
385 datastreamMap[SALOME_ModuleCatalog::DATASTREAM_UNKNOWN]="CALCIUM_unknown";
386 datastreamMap[SALOME_ModuleCatalog::DATASTREAM_INTEGER]="CALCIUM_integer";
387 datastreamMap[SALOME_ModuleCatalog::DATASTREAM_FLOAT]="CALCIUM_real";
388 datastreamMap[SALOME_ModuleCatalog::DATASTREAM_DOUBLE]="CALCIUM_double";
389 datastreamMap[SALOME_ModuleCatalog::DATASTREAM_BOOLEAN]="CALCIUM_boolean";
390 datastreamMap[SALOME_ModuleCatalog::DATASTREAM_STRING]="CALCIUM_string";
393 CORBA::ORB_ptr orb = getSALOMERuntime()->getOrb();
394 CORBA::Object_var obj;
395 SALOME_ModuleCatalog::ModuleCatalog_var catalog;
396 obj=orb->string_to_object(_path.c_str());
397 catalog= SALOME_ModuleCatalog::ModuleCatalog::_narrow(obj);
400 // Get types in catalog
401 loadTypes(cata,catalog);
405 // Get component list
406 SALOME_ModuleCatalog::ListOfComponents_var componentname_list;
407 componentname_list = catalog->GetComponentList();
408 for (int i=0; i<componentname_list->length(); i++)
410 DEBTRACE ("Component : " << componentname_list[i]);
411 SALOME_ModuleCatalog::Acomponent_var component = catalog->GetComponent(componentname_list[i]);
412 importComponent(cata,component);
414 cata->setErrors(_errors);