Salome HOME
Change version name to 3.2.0b1
[modules/superv.git] / src / Supervision / SuperV_Server_omniORB4.cxx
1 // Copyright (C) 2005  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
2 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
3 // 
4 // This library is free software; you can redistribute it and/or
5 // modify it under the terms of the GNU Lesser General Public
6 // License as published by the Free Software Foundation; either 
7 // version 2.1 of the License.
8 // 
9 // This library is distributed in the hope that it will be useful 
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of 
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU 
12 // Lesser General Public License for more details.
13 //
14 // You should have received a copy of the GNU Lesser General Public  
15 // License along with this library; if not, write to the Free Software 
16 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
17 //
18 // See http://www.salome-platform.org/
19 //
20
21 #include <iostream>
22 #include <CORBA.h>
23 #include "ObjRef_omniORB4.hh"
24
25 using namespace std;
26
27 class ObjRef_i : public POA_ObjRef_omniORB4::ObjRef {
28
29 public:
30
31 ObjRef_i() {} ;
32 virtual ~ObjRef_i() {} ;
33
34 virtual ObjRef_omniORB4::ObjRef_ptr getObjRef( const ObjRef_omniORB4::ObjRef_ptr anObjRef ) ;
35
36 virtual bool ping() ;
37
38 } ;
39
40
41 ObjRef_omniORB4::ObjRef_ptr ObjRef_i::getObjRef( const ObjRef_omniORB4::ObjRef_ptr anObjRef ) {
42
43   cout << "ObjRef_i::getObjRef" << endl ;
44   anObjRef->ping() ;
45   cout << "ObjRef_i::getObjRef will return the same object reference" << endl ;
46   return ObjRef_omniORB4::ObjRef::_duplicate( anObjRef ) ;
47
48 } ;
49
50 bool ObjRef_i::ping() {
51   cout << "ping" << endl ;
52   return true ;
53 }
54
55 int main( int argc , char ** argv ) {
56
57   try {
58     CORBA::ORB_var orb = CORBA::ORB_init( argc , argv , "omniORB4" ) ;
59     CORBA::Object_var obj = orb->resolve_initial_references( "RootPOA" ) ;
60     PortableServer::POA_var poa = PortableServer::POA::_narrow( obj ) ;
61     ObjRef_i * myObjRef = new ObjRef_i() ;
62     PortableServer::ObjectId_var myObjectId = poa->activate_object( myObjRef ) ;
63     obj = myObjRef->_this() ;
64     CORBA::String_var myIOR = orb->object_to_string( obj ) ;
65     cout << "myIOR : '" << (char * ) myIOR << "'" << endl ;
66     myObjRef->_remove_ref() ;
67     PortableServer::POAManager_var pman = poa->the_POAManager() ;
68     pman->activate() ;
69     orb->run() ;
70     orb->destroy() ;
71   }
72   catch(CORBA::SystemException & ) {
73     cout << "Caught CORBA::SystemException" << endl ;
74   }
75   catch(CORBA::Exception & ) {
76     cout << "Caught CORBA::Exception" << endl ;
77   }
78   catch(omniORB::fatalException & fe ) {
79     cout << "Caught omniORB::fatalException" << endl ;
80     cout << "      file   " << fe.file() << endl ;
81     cout << "      line   " << fe.line() << endl ;
82     cout << "      errmsg " << fe.errmsg() << endl ;
83   }
84   catch( ... ) {
85     cout << "Caught unknown exception" << endl ;
86   }
87   return 0 ;
88 }