1 // SUPERV Supervision : contains the implementation of interfaces of SuperVision described in SUPERV.idl
3 // Copyright (C) 2003 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License.
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // Lesser General Public License for more details.
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 // See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org
24 // File : SuperV_Impl.cxx
25 // Author : Jean Rahuel
40 //#include "utilities.h"
42 #include "SALOME_Container_i.hxx"
44 #include "SuperV_Impl.hxx"
46 #include "SALOMEDS_Attributes.hh"
47 #include <TCollection_AsciiString.hxx>
48 #include <TColStd_SequenceOfAsciiString.hxx>
49 #include "SALOMEDS_Tool.hxx"
51 #include "Utils_CorbaException.hxx"
53 #define STUDY_SUPERVISION "SUPERV"
55 SuperV_Impl::SuperV_Impl( CORBA::ORB_ptr orb ,
56 PortableServer::POA_ptr poa ,
57 PortableServer::ObjectId * contId ,
58 const char *instanceName ,
59 const char *interfaceName
63 Engines_Component_i(orb, poa, contId, instanceName, interfaceName, false, false) {
64 MESSAGE("SuperV_Impl::SuperV_Impl activate object instanceName("
65 << instanceName << ") interfaceName(" << interfaceName << ") --> "
66 << hex << (void *) this << dec )
68 _id = _poa->activate_object(_thisObj);
69 _Orb = CORBA::ORB::_duplicate(orb);
74 SuperV_Impl::SuperV_Impl() {
77 SuperV_Impl::~SuperV_Impl() {
78 beginService( "SuperV_Impl::~SuperV_Impl" );
79 endService( "SuperV_Impl::~SuperV_Impl" );
82 void SuperV_Impl::Destroy() {
83 beginService( "SuperV_Impl::Destroy" );
84 _poa->deactivate_object(*_id) ;
85 CORBA::release(_poa) ;
87 _thisObj->_remove_ref();
89 endService( "SuperV_Impl::Destroy" );
92 // void SuperV_Impl::Save(const char *IORSComponent, const char *aUrlOfFile) {
93 SALOMEDS::TMPFile* SuperV_Impl::Save(SALOMEDS::SComponent_ptr theComponent,
96 SALOMEDS::TMPFile_var aStreamFile;
97 // Get a temporary directory to store a file
98 TCollection_AsciiString aTmpDir("");
99 // Create a list to store names of created files
100 SALOMEDS::ListOfFileNames_var aSeq = new SALOMEDS::ListOfFileNames;
102 TCollection_AsciiString myStudyName("");
103 if (isMultiFile) myStudyName = (char*)SALOMEDS_Tool::GetNameFromPath(theComponent->GetStudy()->URL()).c_str();
105 SALOMEDS::ChildIterator_var anIter = theComponent->GetStudy()->NewChildIterator(theComponent);
106 TColStd_SequenceOfAsciiString aFileNames;
107 TCollection_AsciiString aName;
109 for(; anIter->More(); anIter->Next()) {
110 SALOMEDS::SObject_var aSO = anIter->Value();
111 SALOMEDS::GenericAttribute_var anAttr;
112 if (aSO->FindAttribute(anAttr,"AttributeIOR")) {
113 aName = myStudyName +
114 TCollection_AsciiString("_SUPERVISION_") +
115 TCollection_AsciiString(aSO->Tag()) +
116 TCollection_AsciiString(".xml");
117 aFileNames.Append(aName);
120 CORBA::Object_var anObj = _orb->string_to_object(SALOMEDS::AttributeIOR::_narrow(anAttr)->Value()) ;
121 SUPERV::Graph_var graph = SUPERV::Graph::_narrow(anObj);
122 if (aTmpDir.Length() == 0)
123 aTmpDir = (isMultiFile)?TCollection_AsciiString((char*)theURL):(char*)SALOMEDS_Tool::GetTmpDir().c_str();
124 graph->Export((aTmpDir + aName).ToCString());
128 if (aFileNames.Length() == 0) return new SALOMEDS::TMPFile(0);
130 aSeq->length(aFileNames.Length());
132 for(aCounter = aFileNames.Length(); aCounter > 0; aCounter--)
133 aSeq[aCounter-1] = CORBA::string_dup(aFileNames.Value(aCounter).ToCString());
135 // Conver a file to the byte stream
136 aStreamFile = SALOMEDS_Tool::PutFilesToStream(aTmpDir.ToCString(), aSeq.in(), isMultiFile);
137 // Remove the created file and tmp directory
138 if (!isMultiFile) SALOMEDS_Tool::RemoveTemporaryFiles(aTmpDir.ToCString(), aSeq.in(), true);
140 // Add python files to the temporary files sequence
141 SALOMEDS::ListOfFileNames_var aPySeq = new SALOMEDS::ListOfFileNames;
142 aPySeq->length(aSeq->length());
143 for(aCounter = aSeq->length(); aCounter > 0; aCounter--) {
144 char* aCName = CORBA::string_dup(aSeq[aCounter-1]);
145 int a = strlen(aCName);
146 aCName[a-3] = 'p';aCName[a-2] = 'y';aCName[a-1] = 0;
147 aPySeq[aCounter-1] = aCName;
149 // Remove the created file and tmp directory
150 SALOMEDS_Tool::RemoveTemporaryFiles(aTmpDir.ToCString(), aPySeq.in(), true);
151 // Return the created byte stream
152 return aStreamFile._retn();
155 SALOMEDS::TMPFile* SuperV_Impl::SaveASCII(SALOMEDS::SComponent_ptr theComponent,
158 SALOMEDS::TMPFile_var aStreamFile = Save(theComponent, theURL, isMultiFile);
159 return aStreamFile._retn();
162 // void SuperV_Impl::Load(const char* IORSComponent, const char* aUrlOfFile) {
163 CORBA::Boolean SuperV_Impl::Load(SALOMEDS::SComponent_ptr theComponent,
164 const SALOMEDS::TMPFile& theStream,
167 // MESSAGE("SuperV_Impl::Load : IOR = " << IORSComponent << " , Url = " << aUrlOfFile);
168 // Get a temporary directory for a file
169 if (theStream.length() != 0) {
170 TCollection_AsciiString aTmpDir = (isMultiFile)?TCollection_AsciiString((char*)theURL):(char*)SALOMEDS_Tool::GetTmpDir().c_str();
171 myStrURL = strdup(aTmpDir.ToCString());
172 SALOMEDS_Tool::PutStreamToFiles(theStream, myStrURL, isMultiFile);
177 CORBA::Boolean SuperV_Impl::LoadASCII(SALOMEDS::SComponent_ptr theComponent,
178 const SALOMEDS::TMPFile& theStream,
181 return Load(theComponent, theStream, theURL, isMultiFile);
184 void SuperV_Impl::Close(SALOMEDS::SComponent_ptr theComponent) {
185 // mpv 06.03.2003: bug SAL1508 - graphs will be destructed at the GUI-level at the supervision frame closing
187 // SALOMEDS::ChildIterator_var anIter = theComponent->GetStudy()->NewChildIterator(theComponent);
188 // for(; anIter->More(); anIter->Next()) {
189 // SALOMEDS::SObject_var aSO = anIter->Value();
190 // SALOMEDS::GenericAttribute_var anAttr;
191 // if (aSO->FindAttribute(anAttr,"AttributeIOR")) {
192 // CORBA::Object_var anObj = _orb->string_to_object(SALOMEDS::AttributeIOR::_narrow(anAttr)->Value()) ;
193 // SUPERV::Graph_var graph = SUPERV::Graph::_narrow(anObj);
199 char* SuperV_Impl::ComponentDataType() {
200 return(strdup("SUPERV"));
203 char* SuperV_Impl::IORToLocalPersistentID(SALOMEDS::SObject_ptr theSObject,
204 const char* IORString,
205 CORBA::Boolean isMultiFile,
206 CORBA::Boolean isASCII) {
207 MESSAGE("SuperV_Impl::IORToLocalPersistentID: IOR:"<<IORString);
210 CORBA::Object_var anObj = _orb->string_to_object(IORString) ;
211 if (CORBA::is_nil(anObj)) return CORBA::string_dup(IORString);
212 SUPERV::Graph_var aGraph = SUPERV::Graph::_narrow(anObj);
213 if (aGraph->_is_nil()) return CORBA::string_dup(IORString);
215 return CORBA::string_dup(IORString);
218 // sprintf(aName, "%s_SUPERVISION_tmp_%d.xml",myStudyName,myCounter);
219 // CORBA::String_var myStudyName("");
220 // if (isMultiFile) myStudyName = strdup(SALOMEDS_Tool::GetNameFromPath(theSObject->GetStudy()->URL()));
221 TCollection_AsciiString aName = //TCollection_AsciiString(myStudyName) +
222 TCollection_AsciiString("_SUPERVISION_") +
223 TCollection_AsciiString(theSObject->Tag()) +
224 TCollection_AsciiString(".xml");
225 return CORBA::string_dup(aName.ToCString());
228 char* SuperV_Impl::LocalPersistentIDToIOR(SALOMEDS::SObject_ptr theSObject,
229 const char* aLocalPersistentID,
230 CORBA::Boolean isMultiFile,
231 CORBA::Boolean isASCII)
232 throw(SALOME::SALOME_Exception)
234 MESSAGE("SuperV_Impl::LocalPersistentIDToIOR : IOR = " << aLocalPersistentID);
235 CORBA::String_var aFatherID = theSObject->GetFather()->GetID();
236 CORBA::String_var aComponentID = theSObject->GetFatherComponent()->GetID();
237 if (strcmp(aFatherID, aComponentID)) return CORBA::string_dup(aLocalPersistentID);
239 string myStudyName("");
240 if (isMultiFile) myStudyName = SALOMEDS_Tool::GetNameFromPath(theSObject->GetStudy()->URL());
242 string aStr(myStrURL);
243 aStr += myStudyName + string(aLocalPersistentID);
244 SUPERV::StreamGraph_ptr graph = StreamGraph(aStr.c_str());
246 if (graph->_is_nil())
247 THROW_SALOME_CORBA_EXCEPTION("Unable to find graph in the file",SALOME::BAD_PARAM);
249 // mpv: remove IORs input ports on loading
250 MESSAGE("Remove IORs input ports on loading");
251 SUPERV::ListOfNodes_var aNodes = graph->Nodes();
252 SUPERV::CNode_var aNode;
253 const char* aStrIOR = "";
254 CORBA::Any * anAny = new CORBA::Any();
257 for(i = aNodes->CNodes.length() - 1; i >= 0; i--) {
258 aNode = aNodes->CNodes[i];
259 SUPERV::ListOfPorts_var aPorts = aNode->Ports();
260 for(j = aPorts->length() - 1; j >= 0; j--) {
261 SUPERV::Port_var aPort = aPorts[j];
262 if (aPort->IsIOR()) {
263 aPort->Input(AnyValue(*anAny));
267 for(i = aNodes->FNodes.length() - 1; i >= 0; i--) {
268 aNode = aNodes->FNodes[i];
269 SUPERV::ListOfPorts_var aPorts = aNode->Ports();
270 for(j = aPorts->length() - 1; j >= 0; j--) {
271 SUPERV::Port_var aPort = aPorts[j];
272 if (aPort->IsIOR()) {
273 //CORBA::Any * anAny = new CORBA::Any(CORBA::TypeCode::PR_null_tc(), (void*)NULL, 0) ;
274 aPort->Input(AnyValue(*anAny));
278 for(i = aNodes->INodes.length() - 1; i >= 0; i--) {
279 aNode = aNodes->INodes[i];
280 SUPERV::ListOfPorts_var aPorts = aNode->Ports();
281 for(j = aPorts->length() - 1; j >= 0; j--) {
282 SUPERV::Port_var aPort = aPorts[j];
283 if (aPort->IsIOR()) {
284 aPort->Input(AnyValue(*anAny));
288 for(i = aNodes->GNodes.length() - 1; i >= 0; i--) {
289 aNode = aNodes->GNodes[i];
290 SUPERV::ListOfPorts_var aPorts = aNode->Ports();
291 for(j = aPorts->length() - 1; j >= 0; j--) {
292 SUPERV::Port_var aPort = aPorts[j];
293 if (aPort->IsIOR()) {
294 aPort->Input(AnyValue(*anAny));
298 for(i = aNodes->GNodes.length() - 1; i >= 0; i--) {
299 aNode = aNodes->GNodes[i];
300 SUPERV::ListOfPorts_var aPorts = aNode->Ports();
301 for(j = aPorts->length() - 1; j >= 0; j--) {
302 SUPERV::Port_var aPort = aPorts[j];
303 if (aPort->IsIOR()) {
304 aPort->Input(AnyValue(*anAny));
308 for(i = aNodes->LNodes.length() - 1; i >= 0; i--) {
309 aNode = aNodes->LNodes[i];
310 SUPERV::ListOfPorts_var aPorts = aNode->Ports();
311 for(j = aPorts->length() - 1; j >= 0; j--) {
312 SUPERV::Port_var aPort = aPorts[j];
313 if (aPort->IsIOR()) {
314 aPort->Input(AnyValue(*anAny));
318 for(i = aNodes->ELNodes.length() - 1; i >= 0; i--) {
319 aNode = aNodes->ELNodes[i];
320 SUPERV::ListOfPorts_var aPorts = aNode->Ports();
321 for(j = aPorts->length() - 1; j >= 0; j--) {
322 SUPERV::Port_var aPort = aPorts[j];
323 if (aPort->IsIOR()) {
324 aPort->Input(AnyValue(*anAny));
328 for(i = aNodes->SNodes.length() - 1; i >= 0; i--) {
329 aNode = aNodes->SNodes[i];
330 SUPERV::ListOfPorts_var aPorts = aNode->Ports();
331 for(j = aPorts->length() - 1; j >= 0; j--) {
332 SUPERV::Port_var aPort = aPorts[j];
333 if (aPort->IsIOR()) {
334 aPort->Input(AnyValue(*anAny));
338 for(i = aNodes->ESNodes.length() - 1; i >= 0; i--) {
339 aNode = aNodes->ESNodes[i];
340 SUPERV::ListOfPorts_var aPorts = aNode->Ports();
341 for(j = aPorts->length() - 1; j >= 0; j--) {
342 SUPERV::Port_var aPort = aPorts[j];
343 if (aPort->IsIOR()) {
344 aPort->Input(AnyValue(*anAny));
350 SALOMEDS::ListOfFileNames_var aSeq = new SALOMEDS::ListOfFileNames;
352 aSeq[0]=aLocalPersistentID;
353 if (!isMultiFile) SALOMEDS_Tool::RemoveTemporaryFiles(myStrURL, aSeq.in(), true);
355 return _Orb->object_to_string(graph);
358 bool SuperV_Impl::CanPublishInStudy(CORBA::Object_ptr theIOR) {
359 SUPERV::Graph_var aGraph = SUPERV::Graph::_narrow(theIOR);
360 return !(aGraph->_is_nil());
363 SALOMEDS::SObject_ptr SuperV_Impl::PublishInStudy(SALOMEDS::Study_ptr theStudy,
364 SALOMEDS::SObject_ptr theSObject,
365 CORBA::Object_ptr theObject,
366 const char* theName) throw (SALOME::SALOME_Exception) {
367 SALOMEDS::SObject_var aResultSO;
369 if(CORBA::is_nil(theObject)) return aResultSO._retn();;
371 if(theStudy->_is_nil()) return aResultSO._retn();;
373 SALOMEDS::StudyBuilder_var aBuilder = theStudy->NewBuilder();
374 SALOMEDS::GenericAttribute_var anAttr;
375 SALOMEDS::AttributeName_var aName;
376 SALOMEDS::AttributeIOR_var anIOR;
377 SALOMEDS::AttributePixMap_var aPixmap;
378 SALOMEDS::SComponent_var aFather = theStudy->FindComponent(STUDY_SUPERVISION);
380 if (aFather->_is_nil()) {
381 aFather = aBuilder->NewComponent(STUDY_SUPERVISION);
382 anAttr = aBuilder->FindOrCreateAttribute(aFather, "AttributeName");
383 aName = SALOMEDS::AttributeName::_narrow(anAttr);
384 //NRI aName->SetValue(STUDY_SUPERVISION);
386 SALOME_NamingService *NamingService = new SALOME_NamingService(_Orb);
387 CORBA::Object_var objVarN = NamingService->Resolve("/Kernel/ModulCatalog");
388 SALOME_ModuleCatalog::ModuleCatalog_var Catalogue = SALOME_ModuleCatalog::ModuleCatalog::_narrow(objVarN);
389 SALOME_ModuleCatalog::Acomponent_var Comp = Catalogue->GetComponent( STUDY_SUPERVISION );
390 if ( !Comp->_is_nil() ) {
391 aName->SetValue( Comp->componentusername() );
393 anAttr = aBuilder->FindOrCreateAttribute(aFather, "AttributePixMap");
394 aPixmap = SALOMEDS::AttributePixMap::_narrow(anAttr);
395 aPixmap->SetPixMap( "ICON_OBJBROWSER_Supervision" );
397 aBuilder->DefineComponentInstance(aFather, SuperG::_this());
400 SALOMEDS::SObject_var dataflowI;
401 SALOMEDS::ChildIterator_var dataflowS = theStudy->NewChildIterator(aFather);
403 SUPERV::Graph_var aGraph = SUPERV::Graph::_narrow(theObject);
405 const char* name = aGraph->Name();
407 if (CORBA::is_nil(theSObject)) { // if SObject is null, then searching for exist graph SObject
408 for (; dataflowS->More(); dataflowS->Next()) {
409 dataflowI = dataflowS->Value();
410 if (dataflowI->FindAttribute(anAttr, "AttributeName")) {
411 aName = SALOMEDS::AttributeName::_narrow(anAttr);
412 if (strcmp(aName->Value(), name) == 0) {
413 aResultSO = dataflowI;
418 } else { // else searching for referenced SObject
419 if (!theSObject->ReferencedObject(aResultSO))
420 THROW_SALOME_CORBA_EXCEPTION("Publish in study supervision graph error",SALOME::BAD_PARAM);
423 if (strlen(theName) != 0) name = theName;
424 if (CORBA::is_nil(aResultSO)) aResultSO = aBuilder->NewObject(aFather);
426 aName = SALOMEDS::AttributeName::_narrow(aBuilder->FindOrCreateAttribute(aResultSO, "AttributeName"));
427 aName->SetValue(name);
428 anIOR = SALOMEDS::AttributeIOR::_narrow(aBuilder->FindOrCreateAttribute(aResultSO, "AttributeIOR"));
429 anIOR->SetValue(aGraph->getIOR());
430 // aBuilder->Addreference(theSObject, aResultSO);
431 return aResultSO._retn();
434 CORBA::Boolean SuperV_Impl::CanCopy(SALOMEDS::SObject_ptr theObject) {
435 // Try to retrieve known by SUPERVISION component Graph by given IOR
436 SALOMEDS::GenericAttribute_var anAttr;
437 if (!theObject->FindAttribute(anAttr, "AttributeIOR")) return false;
439 CORBA::Object_var anObj = _orb->string_to_object(SALOMEDS::AttributeIOR::_narrow(anAttr)->Value());
440 if (CORBA::is_nil(anObj)) return false;
442 SUPERV::Graph_var aGraph = SUPERV::Graph::_narrow(anObj);
443 if (aGraph->_is_nil()) return false;
451 SALOMEDS::TMPFile* SuperV_Impl::CopyFrom(SALOMEDS::SObject_ptr theObject, CORBA::Long& theObjectID) {
452 // Declare a sequence of the byte to store the copied object
453 SALOMEDS::TMPFile_var aStreamFile;
455 // Try to get GEOM_Shape object by given SObject
456 SALOMEDS::GenericAttribute_var anAttr;
457 if (!theObject->FindAttribute(anAttr, "AttributeIOR")) return aStreamFile._retn();
458 CORBA::String_var anIOR = strdup(SALOMEDS::AttributeIOR::_narrow(anAttr)->Value());
461 SUPERV::Graph_var aGraph;
463 CORBA::Object_var anObj = _orb->string_to_object(anIOR) ;
464 if (CORBA::is_nil(anObj)) isGraph = false;
466 aGraph = SUPERV::Graph::_narrow(anObj);
467 if (aGraph->_is_nil()) isGraph = false;
473 if (!isGraph) { // it's just a value, stored in the IOR attribute
474 int aLen = strlen(anIOR);
475 CORBA::Octet* anOctetBuf = (CORBA::Octet*)strdup(anIOR);
476 aStreamFile = SALOMEDS::TMPFile_var(new SALOMEDS::TMPFile(aLen, aLen, anOctetBuf, 1));
477 return aStreamFile._retn();
480 // Get a temporary directory to store a temporary file
481 CORBA::String_var aTmpDir = SALOMEDS_Tool::GetTmpDir().c_str();
482 // Create a list to store names of created files
483 SALOMEDS::ListOfFileNames_var aSeq = new SALOMEDS::ListOfFileNames;
485 aSeq[0] = strdup("_SUPERVISION_tmp.xml");
486 char* aFullName = new char[strlen(aTmpDir)+strlen(aSeq[0])+1];
487 strcpy(aFullName, aTmpDir);
488 strcpy(aFullName+strlen(aTmpDir), aSeq[0]);
489 aGraph->Export(strdup(aFullName));
492 aStreamFile = SALOMEDS_Tool::PutFilesToStream(aTmpDir.in(), aSeq.in(), false);
493 SALOMEDS_Tool::RemoveTemporaryFiles(aTmpDir.in(), aSeq.in(), true);
495 // Assign an ID = 1 the the type SUPERV::Graph
498 return aStreamFile._retn();
501 CORBA::Boolean SuperV_Impl::CanPaste(const char* theComponentName, CORBA::Long theObjectID) {
502 // The Supervision component can paste only objects copied by Supervision component
503 // and with the object type = 1
504 if (strcmp(theComponentName, ComponentDataType()) != 0 || theObjectID != 1) return false;
508 SALOMEDS::SObject_ptr SuperV_Impl::PasteInto(const SALOMEDS::TMPFile& theStream,
509 CORBA::Long theObjectID,
510 SALOMEDS::SObject_ptr theObject) {
511 SALOMEDS::SObject_var aResultSO;
512 if(CORBA::is_nil(theObject)) return aResultSO._retn();
513 SALOMEDS::StudyBuilder_var aBuilder = theObject->GetStudy()->NewBuilder();
515 aResultSO = SALOMEDS::SObject::_narrow(CORBA::Object::_duplicate(theObject));
517 bool isGraph = (strcmp(theObject->GetFatherComponent()->GetID(),theObject->GetID()) == 0);
521 SALOMEDS::AttributeIOR_var anIOR =
522 SALOMEDS::AttributeIOR::_narrow(aBuilder->FindOrCreateAttribute(theObject, "AttributeIOR"));
523 int aLen = theStream.length();
524 char* aVal = new char[aLen+1];
525 aVal[aLen] = (char)0;
526 memcpy((void*)aVal, (void*)theStream.NP_data(), aLen);
527 anIOR->SetValue(aVal);
528 return aResultSO._retn();
531 TCollection_AsciiString aTmpDir = (char*)SALOMEDS_Tool::GetTmpDir().c_str();
532 SALOMEDS::ListOfFileNames_var aSeq = SALOMEDS_Tool::PutStreamToFiles(theStream, aTmpDir.ToCString(), false);
533 TCollection_AsciiString aFullName;
534 aFullName = aTmpDir+aSeq[0];
535 SUPERV::Graph_var aGraph = Graph(aFullName.ToCString());
537 SALOMEDS_Tool::RemoveTemporaryFiles(aTmpDir.ToCString(), aSeq.in(), true);
540 aResultSO = aBuilder->NewObject(theObject);
543 SALOMEDS::AttributeIOR_var anIOR =
544 SALOMEDS::AttributeIOR::_narrow(aBuilder->FindOrCreateAttribute(aResultSO, "AttributeIOR"));
545 anIOR->SetValue(CORBA::string_dup(aGraph->getIOR()));
547 return aResultSO._retn();
550 SUPERV::Value_ptr SuperV_Impl::StringValue( const char * aStrIOR ) {
551 // beginService( "Super_Impl::StringValue" );
552 CORBA::Any * anAny = new CORBA::Any() ;
555 CORBA::Object_ptr obj = _Orb->string_to_object( aStrIOR ) ;
561 catch ( CORBA::BAD_PARAM ) {
563 // JR : objref or string only ==> the eventual convertion to long or double is done in
564 // the SuperVisionEngine with the real type of the argument
568 if ( strchr( aStrIOR , '.' ) != NULL &&
569 sscanf( aStrIOR , "%lf%*n", &d)) {
571 // MESSAGE( "Value( " << aStrIOR << " ) --> double " << d );
574 else if (sscanf( aStrIOR , "%ld%*n", &l)) {
576 // MESSAGE( "Value( " << aStrIOR << " ) --> long " << l );
582 // MESSAGE( "Value( " << aStrIOR << " ) --> string " << aStrIOR );
588 // endService( "SuperV_Impl::StringValue" );
589 return Value( anAny ) ;
592 SUPERV::Value_ptr SuperV_Impl::AnyValue( const CORBA::Any & anAny ) {
593 // beginService( "Super_Impl::AnyValue" );
594 CORBA::Any * aAny = new CORBA::Any( anAny ) ;
595 // endService( "SuperV_Impl::AnyValue" );
596 return Value( aAny ) ;
599 SUPERV::Value_ptr SuperV_Impl::Value( CORBA::Any * anAny ) {
600 // beginService( "Super_Impl::Value" );
601 Value_Impl * myValue = new Value_Impl( _Orb , _Poa , _ContId ,
602 instanceName() , interfaceName() ,
603 NULL , NULL , NULL , anAny , true ) ;
604 PortableServer::ObjectId * id = myValue->getId() ;
605 CORBA::Object_var obj = _poa->id_to_reference(*id);
606 SUPERV::Value_var iobject ;
607 iobject = SUPERV::Value::_narrow(obj) ;
608 // endService( "SuperV_Impl::Value" );
609 return SUPERV::Value::_duplicate( iobject ) ;
612 SUPERV::Graph_ptr SuperV_Impl::Graph(const char * aGraphName ) {
613 beginService( "SuperV_Impl::Graph" );
614 bool created = true ;
615 SUPERV::Graph_var iobject = SUPERV::Graph::_nil() ;
616 Graph_Impl * myGraph ;
617 myGraph = new Graph_Impl( _Orb , _Poa, _ContId, instanceName() , interfaceName() ,
618 aGraphName , SUPERV::DataFlowGraph ) ;
619 int lenname = strlen( aGraphName ) ;
620 if ( lenname > 4 && !strcmp( &aGraphName[ lenname - 4 ] , ".xml" ) ) {
621 created = myGraph->Import( aGraphName ) ;
624 myGraph->Import( (char * ) NULL ) ;
626 if ( !created && myGraph->IsStreamGraph() ) {
627 MESSAGE( "SuperV_Impl::Graph " << aGraphName << " IsStreamGraph !" ) ;
629 SUPERV::StreamGraph_var streamiobject = StreamGraph( aGraphName ) ;
630 iobject = SUPERV::Graph::_narrow( streamiobject ) ;
631 if ( CORBA::is_nil( iobject ) ) {
635 else if ( created ) {
636 PortableServer::ObjectId * id = myGraph->getId() ;
637 CORBA::Object_var obj = _poa->id_to_reference(*id);
638 iobject = SUPERV::Graph::_narrow(obj) ;
639 myGraph->SetObjRef( SUPERV::Graph::_duplicate( iobject ) ) ;
641 endService( "SuperV_Impl::Graph" );
642 return SUPERV::Graph::_duplicate(iobject) ;
645 SUPERV::Graph_ptr SuperV_Impl::GraphE(const char * aGraphName ) {
646 beginService( "SuperV_Impl::GraphE" );
647 bool created = true ;
648 SUPERV::Graph_var iobject = SUPERV::Graph::_nil() ;
649 Graph_Impl * myGraph ;
650 myGraph = new Graph_Impl( _Orb , _Poa, _ContId, instanceName() , interfaceName() ,
651 aGraphName , SUPERV::DataFlowGraph ) ;
652 int lenname = strlen( aGraphName ) ;
653 if ( lenname > 4 && !strcmp( &aGraphName[ lenname - 4 ] , ".xml" ) ) {
654 created = myGraph->Import( aGraphName ) ;
657 myGraph->Import( (char * ) NULL ) ;
659 if ( !created && myGraph->IsStreamGraph() ) {
661 SUPERV::StreamGraph_var streamiobject = StreamGraphE( aGraphName ) ;
662 iobject = SUPERV::Graph::_narrow( streamiobject ) ;
663 if ( CORBA::is_nil( iobject ) ) {
667 else if ( created ) {
668 PortableServer::ObjectId * id = myGraph->getId() ;
669 CORBA::Object_var obj = _poa->id_to_reference(*id);
670 iobject = SUPERV::Graph::_narrow(obj) ;
671 myGraph->SetObjRef( SUPERV::Graph::_duplicate( iobject ) ) ;
673 myGraph->ReadOnly() ;
674 endService( "SuperV_Impl::GraphE" );
675 return SUPERV::Graph::_duplicate(iobject) ;
678 SUPERV::StreamGraph_ptr SuperV_Impl::StreamGraph(const char * aGraphName ) {
679 beginService( "SuperV_Impl::StreamGraph" );
680 bool created = true ;
681 StreamGraph_Impl * myStreamGraph ;
682 myStreamGraph = new StreamGraph_Impl( _Orb , _Poa, _ContId, instanceName() ,
683 interfaceName() , aGraphName ) ;
684 int lenname = strlen( aGraphName ) ;
685 if ( lenname > 4 && !strcmp( &aGraphName[ lenname - 4 ] , ".xml" ) ) {
686 created = myStreamGraph->Import( aGraphName ) ;
689 myStreamGraph->Import( (char * ) NULL ) ;
691 SUPERV::StreamGraph_var iobject = SUPERV::StreamGraph::_nil() ;
693 PortableServer::ObjectId * id = myStreamGraph->getId() ;
694 CORBA::Object_var obj = _poa->id_to_reference(*id);
695 iobject = SUPERV::StreamGraph::_narrow(obj) ;
696 myStreamGraph->SetObjRef( SUPERV::StreamGraph::_duplicate( iobject ) ) ;
698 endService( "SuperV_Impl::StreamGraph" );
699 return SUPERV::StreamGraph::_duplicate(iobject) ;
702 SUPERV::StreamGraph_ptr SuperV_Impl::StreamGraphE(const char * aGraphName ) {
703 beginService( "SuperV_Impl::StreamGraphE" );
704 bool created = true ;
705 StreamGraph_Impl * myStreamGraph ;
706 myStreamGraph = new StreamGraph_Impl( _Orb , _Poa, _ContId, instanceName() ,
707 interfaceName() , aGraphName ) ;
708 int lenname = strlen( aGraphName ) ;
709 if ( lenname > 4 && !strcmp( &aGraphName[ lenname - 4 ] , ".xml" ) ) {
710 created = myStreamGraph->Import( aGraphName ) ;
713 myStreamGraph->Import( (char * ) NULL ) ;
715 SUPERV::StreamGraph_var iobject = SUPERV::StreamGraph::_nil() ;
717 PortableServer::ObjectId * id = myStreamGraph->getId() ;
718 CORBA::Object_var obj = _poa->id_to_reference(*id);
719 iobject = SUPERV::StreamGraph::_narrow(obj) ;
720 myStreamGraph->SetObjRef( SUPERV::StreamGraph::_duplicate( iobject ) ) ;
722 myStreamGraph->ReadOnly() ;
723 endService( "SuperV_Impl::StreamGraphE" );
724 return SUPERV::StreamGraph::_duplicate(iobject) ;
727 SUPERV::Graph_ptr SuperV_Impl::getGraph(const char* ior) {
728 SUPERV::Graph_var iobject = SUPERV::Graph::_nil();
730 CORBA::Object_ptr obj = _Orb->string_to_object(ior);
731 iobject = SUPERV::Graph::_narrow(obj);
733 return SUPERV::Graph::_nil();
734 // SUPERV::Graph_var iobject = (SUPERV::Graph_var)NULL;
736 return(SUPERV::Graph::_duplicate(iobject));
739 SUPERV::StreamGraph_ptr SuperV_Impl::getStreamGraph(const char* ior) {
740 SUPERV::StreamGraph_var iobject = SUPERV::StreamGraph::_nil();
742 CORBA::Object_ptr obj = _Orb->string_to_object(ior);
743 iobject = SUPERV::StreamGraph::_narrow(obj);
745 return SUPERV::StreamGraph::_nil();
746 // SUPERV::Graph_var iobject = (SUPERV::Graph_var)NULL;
748 return(SUPERV::StreamGraph::_duplicate(iobject));
751 PortableServer::ObjectId * SUPERVEngine_factory (
753 PortableServer::POA_ptr poa ,
754 PortableServer::ObjectId * contId ,
755 const char *instanceName ,
756 const char *interfaceName
760 MESSAGE("SuperV_factory SuperV ("
761 << instanceName << "," << interfaceName << ")");
762 SuperV_Impl * mySuperV = new SuperV_Impl( orb , poa , contId ,
763 instanceName, interfaceName
766 return mySuperV->getId() ;