// and the pathes prefixes for all computers
//----------------------------------------------------------------------
SALOME_ModuleCatalog_AcomponentImpl::SALOME_ModuleCatalog_AcomponentImpl
-(SALOME_ModuleCatalog::Component &C) : _Component(C)
+(SALOME_ModuleCatalog::ComponentDef &C) : _Component(C)
{
if(MYDEBUG) BEGIN_OF("SALOME_ModuleCatalog_AcomponentImpl");
{
public:
//! standard constructor
- SALOME_ModuleCatalog_AcomponentImpl(SALOME_ModuleCatalog::Component &C);
+ SALOME_ModuleCatalog_AcomponentImpl(SALOME_ModuleCatalog::ComponentDef &C);
//! standard destructor
virtual ~SALOME_ModuleCatalog_AcomponentImpl();
private :
- SALOME_ModuleCatalog::Component _Component;
+ SALOME_ModuleCatalog::ComponentDef _Component;
//! method to duplicate an interface
/*!
void PrintComponent(SALOME_ModuleCatalog::Acomponent_ptr C)
{
- const char *_name = C->componentname();
-
MESSAGE("Name : " << C->componentname());
MESSAGE("Type : " << C->component_type() << " multistudy : " << C->multistudy());
MESSAGE("Constraint : " << C->constraint());
// Function : SALOME_ModuleCatalog_Handler
// Purpose : Constructor
//----------------------------------------------------------------------
-SALOME_ModuleCatalog_Handler::SALOME_ModuleCatalog_Handler()
+SALOME_ModuleCatalog_Handler::SALOME_ModuleCatalog_Handler(ParserPathPrefixes& pathList,
+ ParserComponents& moduleList,
+ ParserTypes& typeMap,
+ TypeList& typeList):_typeMap(typeMap),_typeList(typeList),
+ _pathList(pathList),_moduleList(moduleList)
+
{
if(MYDEBUG) BEGIN_OF("SALOME_ModuleCatalog_Handler");
// Processing the document nodes
while(aCurNode != NULL)
{
- // Process path prefix list (tag test_path_prefix_list)
+ // Part 1: Process path prefix list (tag test_path_prefix_list)
if ( !xmlStrcmp(aCurNode->name,(const xmlChar*)test_path_prefix_list) )
{
xmlNodePtr aCurSubNode = aCurNode->xmlChildrenNode;
}
}
- //@ Process list of components (tag test_component_list)
+ //Part 2: Process list of types
+ if ( !xmlStrcmp(aCurNode->name,(const xmlChar*)"type-list") )
+ {
+ xmlNodePtr aTypeNode = aCurNode->xmlChildrenNode;
+ while (aTypeNode != NULL)
+ {
+ // match "type"
+ if ( !xmlStrcmp(aTypeNode->name, (const xmlChar*)"type" ))
+ {
+ // Here is a basic type description
+ ParserType aType;
+ xmlChar * name=xmlGetProp(aTypeNode,(const xmlChar*)"name");
+ if(name)
+ {
+ aType.name = (const char*)name;
+ xmlFree(name);
+ }
+ xmlChar *kind=xmlGetProp(aTypeNode,(const xmlChar*)"kind");
+ if(kind)
+ {
+ aType.kind = (const char*)kind;
+ xmlFree(kind);
+ }
+ if(aType.kind == "double" ||
+ aType.kind == "int" ||
+ aType.kind == "bool" ||
+ aType.kind == "string")
+ {
+ if ( _typeMap.find(aType.name) == _typeMap.end() )
+ {
+ std::cerr << "Registered basic type: " << aType.name << " " << aType.kind << std::endl;
+ _typeMap[aType.name]=aType;
+ _typeList.push_back(aType);
+ }
+ else
+ std::cerr << "Warning: this type (" << aType.name << "," << aType.kind << ") already exists, it will be ignored." << std::endl;
+ }
+ else
+ std::cerr << "Warning: this type (" << aType.name << "," << aType.kind << ") has incorrect kind, it will be ignored." << std::endl;
+ }
+ else if ( !xmlStrcmp(aTypeNode->name, (const xmlChar*)"sequence" ))
+ {
+ // Here is a sequence type description
+ ParserSequence aType;
+ xmlChar * name=xmlGetProp(aTypeNode,(const xmlChar*)"name");
+ if(name)
+ {
+ aType.name = (const char*)name;
+ xmlFree(name);
+ }
+ xmlChar *content=xmlGetProp(aTypeNode,(const xmlChar*)"content");
+ if(content)
+ {
+ aType.content = (const char*)content;
+ xmlFree(content);
+ }
+ if ( _typeMap.find(aType.content) != _typeMap.end() )
+ {
+ if ( _typeMap.find(aType.name) == _typeMap.end() )
+ {
+ std::cerr << "Registered sequence type: " << aType.name << " " << aType.content << std::endl;
+ _typeMap[aType.name]=aType;
+ _typeList.push_back(aType);
+ }
+ else
+ std::cerr << "Warning: this type (" << aType.name << "," << aType.kind << ") already exists, it will be ignored." << std::endl;
+ }
+ else
+ {
+ std::cerr << "Warning: this sequence type (" << aType.name << "," << aType.content << ") has unknown content type, it will be ignored." << std::endl;
+ }
+ }
+ else if ( !xmlStrcmp(aTypeNode->name, (const xmlChar*)"objref" ))
+ {
+ // Here is an objref type description
+ ParserObjref aType;
+ int error=0;
+ xmlChar * name=xmlGetProp(aTypeNode,(const xmlChar*)"name");
+ if(name)
+ {
+ aType.name = (const char*)name;
+ xmlFree(name);
+ }
+ xmlChar *id=xmlGetProp(aTypeNode,(const xmlChar*)"id");
+ if(id)
+ {
+ aType.id = (const char*)id;
+ xmlFree(id);
+ }
+
+ xmlNodePtr aTypeSubNode = aTypeNode->xmlChildrenNode;
+ while (aTypeSubNode != NULL)
+ {
+ if ( !xmlStrcmp(aTypeSubNode->name, (const xmlChar*)"base" ))
+ {
+ //a base type
+ xmlChar* content = xmlNodeGetContent(aTypeSubNode);
+ if(content)
+ {
+ std::string base=(const char*)content;
+ xmlFree(content);
+ if ( _typeMap.find(base) != _typeMap.end() && _typeMap[base].kind == "objref")
+ {
+ aType.bases.push_back(base);
+ }
+ else
+ {
+ std::cerr << "Warning: this objref type (" << aType.name << ") has unknown base type (" << base << "), it will be ignored." << std::endl;
+ error=1;
+ break;
+ }
+ }
+ }
+ aTypeSubNode = aTypeSubNode->next;
+ }
+ if(!error)
+ {
+ if ( _typeMap.find(aType.name) == _typeMap.end() )
+ {
+ std::cerr << "Registered objref type: " << aType.name << " " << aType.id << std::endl;
+ _typeMap[aType.name]=aType;
+ _typeList.push_back(aType);
+ }
+ else
+ std::cerr << "Warning: this type (" << aType.name << "," << aType.kind << ") already exists, it will be ignored." << std::endl;
+ }
+ }
+ else if ( !xmlStrcmp(aTypeNode->name, (const xmlChar*)"struct" ))
+ {
+ // Here is a struct type description
+ ParserStruct aType;
+ int error=0;
+ xmlChar * name=xmlGetProp(aTypeNode,(const xmlChar*)"name");
+ if(name)
+ {
+ aType.name = (const char*)name;
+ xmlFree(name);
+ }
+ xmlChar *id=xmlGetProp(aTypeNode,(const xmlChar*)"id");
+ if(id)
+ {
+ aType.id = (const char*)id;
+ xmlFree(id);
+ }
+
+ xmlNodePtr aTypeSubNode = aTypeNode->xmlChildrenNode;
+ while (aTypeSubNode != NULL)
+ {
+ if ( !xmlStrcmp(aTypeSubNode->name, (const xmlChar*)"member" ))
+ {
+ std::pair<std::string,std::string> member;
+ xmlChar * m_name=xmlGetProp(aTypeSubNode,(const xmlChar*)"name");
+ if(m_name)
+ {
+ member.first=(const char*)m_name;
+ xmlFree(m_name);
+ }
+ xmlChar * m_type=xmlGetProp(aTypeSubNode,(const xmlChar*)"type");
+ if(m_type)
+ {
+ member.second=(const char*)m_type;
+ xmlFree(m_type);
+ }
+ if ( _typeMap.find(member.second) != _typeMap.end() )
+ {
+ aType.members.push_back(member);
+ }
+ else
+ {
+ std::cerr << "Warning: this struct type (" << aType.name << ") has unknown member type (" << member.first << "," << member.second << "), it will be ignored." << std::endl;
+ error=1;
+ break;
+ }
+ }
+ aTypeSubNode = aTypeSubNode->next;
+ }
+ if(!error)
+ {
+ if ( _typeMap.find(aType.name) == _typeMap.end() )
+ {
+ std::cerr << "Registered struct type: " << aType.name << " " << aType.id << std::endl;
+ _typeMap[aType.name]=aType;
+ _typeList.push_back(aType);
+ }
+ else
+ std::cerr << "Warning: this type (" << aType.name << "," << aType.kind << ") already exists, it will be ignored." << std::endl;
+ }
+ } // end of struct
+ aTypeNode = aTypeNode->next;
+ }
+ }
+
+ //Part 3: Process list of components (tag test_component_list)
if ( !xmlStrcmp(aCurNode->name,(const xmlChar*)test_component_list) )
{
xmlNodePtr aComponentNode = aCurNode->xmlChildrenNode;
xmlNodePtr aCompServiceNode = aSubNode->xmlChildrenNode;
while(aCompServiceNode != NULL) {
// Tag test_service
- if ( !xmlStrcmp(aCompServiceNode->name, (const xmlChar*)test_interface_name) ) {
+ if ( !xmlStrcmp(aCompServiceNode->name, (const xmlChar*)"component-service") ) {
xmlNodePtr aCompServiceSubNode = aCompServiceNode->xmlChildrenNode;
while(aCompServiceSubNode != NULL)
{
{
public:
//! standard constructor
- SALOME_ModuleCatalog_Handler();
+ SALOME_ModuleCatalog_Handler(ParserPathPrefixes& pathList,ParserComponents& moduleList,ParserTypes& typeMap,TypeList& typeList);
//! standard destructor
virtual ~SALOME_ModuleCatalog_Handler();
ParserComponent _aModule;
+ ParserPathPrefixes& _pathList;
+ ParserComponents& _moduleList;
ParserInterfaces _interfaceList;
ParserInterface _aInterface;
ParserDataStreamParameters _outDataStreamParamList;
ParserDataStreamParameter _outDataStreamParam;
+ ParserTypes& _typeMap;
+ TypeList& _typeList;
+
+ ParserSequences _sequenceMap;
+ ParserObjrefs _objrefMap;
+ ParserStructs _structMap;
};
#endif // SALOME_CATALOG_HANDLER_H
#include <string>
#include <vector>
+#include <map>
// Type Definitions
struct ParserPathPrefix
typedef std::vector<ParserComponent> ParserComponents ;
-#ifdef WRITE_CATA_COMPONENT
-// contains all the paths and the computers defined in the catalog
- ParserPathPrefixes _pathList;
-
-// contains all the modules defined in the catalog
- ParserComponents _moduleList;
-#else
-extern ParserPathPrefixes _pathList;
-extern ParserComponents _moduleList;
-#endif
+struct ParserType
+{
+ std::string name;
+ std::string kind;
+ std::string id;
+ std::string content;
+ std::vector<std::string> bases;
+ std::vector< std::pair<std::string,std::string> > members;
+};
+typedef std::map<std::string,ParserType> ParserTypes ;
+typedef std::map<std::string,ParserType&> RefTypes ;
+typedef std::vector<ParserType> TypeList ;
+
+struct ParserSequence:public ParserType
+{
+ ParserSequence(){kind="sequence";}
+};
+typedef std::map<std::string,ParserSequence> ParserSequences ;
+struct ParserObjref:public ParserType
+{
+ ParserObjref(){kind="objref";}
+};
+typedef std::map<std::string,ParserObjref> ParserObjrefs ;
+
+struct ParserStruct:public ParserType
+{
+ ParserStruct(){kind="struct";}
+};
+typedef std::map<std::string,ParserStruct> ParserStructs ;
#endif // SALOME_CATALOG_PARSER_H
int main(int argc,char **argv)
{
// initialize the ORB
- CORBA::ORB_ptr orb = CORBA::ORB_init (argc, argv);
+ CORBA::ORB_var orb = CORBA::ORB_init (argc, argv);
// LocalTraceCollector *myThreadTrace = SALOMETraceCollector::instance(orb);
try
{
// Active catalog
- SALOME_ModuleCatalogImpl Catalogue_i(argc, argv, orb);
- poa->activate_object (&Catalogue_i);
+ SALOME_ModuleCatalogImpl* Catalogue_i=new SALOME_ModuleCatalogImpl(argc, argv, orb);
+ PortableServer::ObjectId_var cataid = poa->activate_object (Catalogue_i);
+ //activate POA manager
mgr->activate();
-
- CORBA::Object_ptr myCata = Catalogue_i._this();
+ CORBA::Object_var myCata = Catalogue_i->_this();
+ Catalogue_i->_remove_ref();
// initialise Naming Service
- SALOME_NamingService *_NS;
- _NS = new SALOME_NamingService(orb);
+ SALOME_NamingService _NS(orb);
// register Catalog in Naming Service
- _NS->Register(myCata ,"/Kernel/ModulCatalog");
+ _NS.Register(myCata ,"/Kernel/ModulCatalog");
MESSAGE("Running CatalogServer.");
timer.ShowAbsolute();
#endif
orb->run();
+ std::cerr << "server returned from orb->run()" << std::endl;
+ orb->destroy();
// mgr->deactivate(true,true);
// poa->destroy(1,1);
int sepLen = theSeparator.length();
int startPos = 0, sepPos = theString.find(theSeparator, startPos);
- for ( ; (startPos < theString.length()) && (sepPos != string::npos); sepPos = theString.find(theSeparator, startPos))
+ while (1)
{
- string anItem = theString.substr(startPos, sepPos - startPos);
+ string anItem ;
+ if(sepPos != string::npos)
+ anItem = theString.substr(startPos, sepPos - startPos);
+ else
+ anItem = theString.substr(startPos);
if (anItem.length() > 0)
aList.push_back(anItem);
+ if(sepPos == string::npos)
+ break;
startPos = sepPos + sepLen;
+ sepPos = theString.find(theSeparator, startPos);
}
return aList;
_parse_xml_file(aPath.c_str(),
_general_module_list,
- _general_path_list);
+ _general_path_list,
+ _typeMap,
+ _typeList);
}
// Verification of _general_path_list content
// _personal_path_list members with the personal catalog files
_parse_xml_file(_personal_path,
_personal_module_list,
- _personal_path_list);
+ _personal_path_list,
+ _typeMap,
+ _typeList);
// Verification of _general_path_list content
if(!_verify_path_prefix(_personal_path_list)){
}
+//! Get the list of all types of the catalog
+/*!
+ * \return the list of types
+ */
+SALOME_ModuleCatalog::ListOfTypeDefinition* SALOME_ModuleCatalogImpl::GetTypes()
+{
+ SALOME_ModuleCatalog::ListOfTypeDefinition_var type_list = new SALOME_ModuleCatalog::ListOfTypeDefinition();
+ type_list->length(_typeList.size());
+
+ for (int ind = 0 ; ind < _typeList.size() ; ind++)
+ {
+ std::cerr << "name: " << _typeList[ind].name << std::endl;
+ //no real need to call string_dup, omniorb calls it on operator= (const char *) but it is safer
+ type_list[ind].name=CORBA::string_dup(_typeList[ind].name.c_str());
+ type_list[ind].kind=SALOME_ModuleCatalog::NONE;
+ if(_typeList[ind].kind=="double")
+ type_list[ind].kind=SALOME_ModuleCatalog::Dble;
+ else if(_typeList[ind].kind=="int")
+ type_list[ind].kind=SALOME_ModuleCatalog::Int;
+ else if(_typeList[ind].kind=="bool")
+ type_list[ind].kind=SALOME_ModuleCatalog::Bool;
+ else if(_typeList[ind].kind=="string")
+ type_list[ind].kind=SALOME_ModuleCatalog::Str;
+ else if(_typeList[ind].kind=="objref")
+ {
+ type_list[ind].kind=SALOME_ModuleCatalog::Objref;
+ type_list[ind].id=CORBA::string_dup(_typeList[ind].id.c_str());
+ //bases
+ type_list[ind].bases.length(_typeList[ind].bases.size());
+ std::vector<std::string>::const_iterator miter;
+ miter=_typeList[ind].bases.begin();
+ int n_memb=0;
+ while(miter != _typeList[ind].bases.end())
+ {
+ type_list[ind].bases[n_memb]=CORBA::string_dup(miter->c_str());
+ miter++;
+ n_memb++;
+ }
+ }
+ else if(_typeList[ind].kind=="sequence")
+ {
+ type_list[ind].kind=SALOME_ModuleCatalog::Seq;
+ type_list[ind].content=CORBA::string_dup(_typeList[ind].content.c_str());
+ }
+ else if(_typeList[ind].kind=="array")
+ {
+ type_list[ind].kind=SALOME_ModuleCatalog::Array;
+ type_list[ind].content=CORBA::string_dup(_typeList[ind].content.c_str());
+ }
+ else if(_typeList[ind].kind=="struct")
+ {
+ type_list[ind].kind=SALOME_ModuleCatalog::Struc;
+ //members
+ type_list[ind].members.length(_typeList[ind].members.size());
+
+ std::vector< std::pair<std::string,std::string> >::const_iterator miter;
+ miter=_typeList[ind].members.begin();
+ int n_memb=0;
+ while(miter != _typeList[ind].members.end())
+ {
+ type_list[ind].members[n_memb].name=CORBA::string_dup(miter->first.c_str());
+ type_list[ind].members[n_memb].type=CORBA::string_dup(miter->second.c_str());
+ n_memb++;
+ miter++;
+ }
+ }
+ }
+ return type_list._retn();
+}
+
//----------------------------------------------------------------------
// Function : GetComputerList
// Purpose : get a computer list
if (_personal_module_list[ind].type == _temp_component_type)
{
_list_typed_component->length(_j + 1);
+ /* Is it an error ?
+ * _list_typed_component[_j] = _personal_module_list[ind].name.c_str();
+ */
_list_typed_component[_j] = (_moduleList[ind].name).c_str();
//if(MYDEBUG) SCRUTE(_list_typed_component[_j]);
_j++;
// DebugParserComponent(*C_parser);
- SALOME_ModuleCatalog::Component C_corba;
+ SALOME_ModuleCatalog::ComponentDef C_corba;
duplicate(C_corba, *C_parser);
return compo;
}
-SALOME_ModuleCatalog::Component *
+SALOME_ModuleCatalog::ComponentDef *
SALOME_ModuleCatalogImpl::GetComponentInfo(const char *name)
{
std::string s(name);
if (C_parser) {
- SALOME_ModuleCatalog::Component * C_corba
- = new SALOME_ModuleCatalog::Component;
+ SALOME_ModuleCatalog::ComponentDef * C_corba
+ = new SALOME_ModuleCatalog::ComponentDef;
duplicate(*C_corba, *C_parser);
return C_corba;
}
void
SALOME_ModuleCatalogImpl::_parse_xml_file(const char* file,
ParserComponents& modulelist,
- ParserPathPrefixes& pathList)
+ ParserPathPrefixes& pathList,
+ ParserTypes& typeMap,
+ TypeList& typeList)
{
if(MYDEBUG) BEGIN_OF("_parse_xml_file");
if(MYDEBUG) SCRUTE(file);
- SALOME_ModuleCatalog_Handler* handler = new SALOME_ModuleCatalog_Handler();
+ //Local path and module list for the file to parse
+ ParserPathPrefixes _pathList;
+ ParserComponents _moduleList;
+
+ SALOME_ModuleCatalog_Handler* handler = new SALOME_ModuleCatalog_Handler(_pathList,_moduleList,typeMap,typeList);
FILE* aFile = fopen(file, "r");
void
SALOME_ModuleCatalogImpl::ImportXmlCatalogFile(const char* file)
{
- _parse_xml_file(file, _personal_module_list, _personal_path_list);
+ _parse_xml_file(file, _personal_module_list, _personal_path_list,_typeMap,_typeList);
}
// Purpose : create a component from the catalog parsing
//----------------------------------------------------------------------
void SALOME_ModuleCatalogImpl::duplicate
-(SALOME_ModuleCatalog::Component & C_corba,
+(SALOME_ModuleCatalog::ComponentDef & C_corba,
const ParserComponent & C_parser)
{
C_corba.name = CORBA::string_dup(C_parser.name.c_str());
*/
virtual SALOME_ModuleCatalog::ListOfComputers* GetComputerList();
+ //! method to get the list of all types of the catalog
+ /*!
+ * \return the types list
+ */
+ virtual SALOME_ModuleCatalog::ListOfTypeDefinition* GetTypes();
+
//! method to get the PathPrefix of a computer
/*! If the wanted computer doesn't exist, the Notfound exception is thrown
\param machinename const char* arguments
\param componentname const char* arguments
\return the wanted component description
*/
- virtual SALOME_ModuleCatalog::Component *
+ virtual SALOME_ModuleCatalog::ComponentDef *
GetComponentInfo(const char *name);
void ping(){};
\param file const char* arguments
\param modulelist ParserComponents arguments
\param pathlist ParserPathPrefixes arguments
+ \param typeMap ParserTypes arguments
*/
virtual void _parse_xml_file(const char* file,
ParserComponents & modulelist,
- ParserPathPrefixes & pathlist);
+ ParserPathPrefixes & pathlist,
+ ParserTypes& typeMap,
+ TypeList& typeList);
//! method to find component in the parser list
/*!
\param C_corba Component argument
\param C_parser const ParserComponent argument
*/
- void duplicate(SALOME_ModuleCatalog::Component & C_corba,
+ void duplicate(SALOME_ModuleCatalog::ComponentDef & C_corba,
const ParserComponent & C_parser);
//! method to create a CORBA interface description from parser
// These variables will contain the informations on the general common catalog
ParserComponents _general_module_list ;
ParserPathPrefixes _general_path_list ;
+ ParserTypes _typeMap;
+ TypeList _typeList;
// These variables will contain the informations on the personal catalog
ParserComponents _personal_module_list ;