| 1 | #include "ORB_WRAP.h"
|
|---|
| 2 |
|
|---|
| 3 | ORB_WRAP::ORB_WRAP()
|
|---|
| 4 | {
|
|---|
| 5 | if( CORBA::is_nil( ORB_WRAP::orb ) )
|
|---|
| 6 | ORB_WRAP::orb = CORBA::ORB_init( ORB_WRAP::vars, NULL );
|
|---|
| 7 | init();
|
|---|
| 8 | }
|
|---|
| 9 |
|
|---|
| 10 | ORB_WRAP::ORB_WRAP( int argc, char** argv )
|
|---|
| 11 | {
|
|---|
| 12 | if( CORBA::is_nil( ORB_WRAP::orb ) )
|
|---|
| 13 | ORB_WRAP::orb = CORBA::ORB_init( argc, argv );
|
|---|
| 14 | init();
|
|---|
| 15 | }
|
|---|
| 16 |
|
|---|
| 17 | void ORB_WRAP::init()
|
|---|
| 18 | {
|
|---|
| 19 | try
|
|---|
| 20 | {
|
|---|
| 21 | CORBAOBJ _poaObj = CORBA::Object::_nil();
|
|---|
| 22 |
|
|---|
| 23 | while( CORBA::is_nil( _poaObj ) )
|
|---|
| 24 | _poaObj = orb->resolve_initial_references("RootPOA");
|
|---|
| 25 |
|
|---|
| 26 | root_poa = PortableServer::POA::_narrow( _poaObj.in() );
|
|---|
| 27 | assert(!CORBA::is_nil(root_poa));
|
|---|
| 28 | mgr = root_poa->the_POAManager();
|
|---|
| 29 | mgr->activate();
|
|---|
| 30 |
|
|---|
| 31 | //CORBA::PolicyList policy_list;
|
|---|
| 32 |
|
|---|
| 33 | CORBAOBJ _nameObj = CORBA::Object::_nil();
|
|---|
| 34 |
|
|---|
| 35 | while( CORBA::is_nil( _nameObj ) )
|
|---|
| 36 | _nameObj = orb->resolve_initial_references( "NameService" );
|
|---|
| 37 | nc = CosNaming::NamingContext::_narrow( _nameObj.in());
|
|---|
| 38 | assert(!CORBA::is_nil(nc));
|
|---|
| 39 |
|
|---|
| 40 | ACE_OS::printf( "ORB Initialization Successful\n" );
|
|---|
| 41 | vars += 1;
|
|---|
| 42 | } catch( CORBA::Exception & ) {
|
|---|
| 43 | ACE_OS::printf( "[ORB_DEV::CTOR] ORB Initialization Failed\n" );
|
|---|
| 44 | }
|
|---|
| 45 | }
|
|---|
| 46 |
|
|---|
| 47 | CORBAOBJ ORB_WRAP::lookup( const char* _name )
|
|---|
| 48 | {
|
|---|
| 49 | CosNaming::Name cosName;
|
|---|
| 50 |
|
|---|
| 51 | getCosName( cosName, _name );
|
|---|
| 52 |
|
|---|
| 53 | try
|
|---|
| 54 | {
|
|---|
| 55 | return nc->resolve( cosName );
|
|---|
| 56 | } catch( CORBA::Exception& ) {
|
|---|
| 57 | ACE_OS::printf( "[ORB_WRAP::lookup] Lookup for *s failed\n", _name );
|
|---|
| 58 | }
|
|---|
| 59 |
|
|---|
| 60 | return NULL;
|
|---|
| 61 | }
|
|---|
| 62 |
|
|---|
| 63 | void ORB_WRAP::bindObj( CORBAOBJ & _obj, const char* _name )
|
|---|
| 64 | {
|
|---|
| 65 | CosNaming::Name cosName;
|
|---|
| 66 |
|
|---|
| 67 | getCosName( cosName, _name );
|
|---|
| 68 |
|
|---|
| 69 | try
|
|---|
| 70 | {
|
|---|
| 71 | nc->rebind( cosName, _obj.in() );
|
|---|
| 72 | } catch( CORBA::Exception& ) {
|
|---|
| 73 | ACE_OS::printf( "[ORB_WRAP::bindObj] Bind for *s failed\n", _name );
|
|---|
| 74 | }
|
|---|
| 75 | }
|
|---|
| 76 |
|
|---|
| 77 | PortableServer::POA_var ORB_WRAP::getPOA() const { return this->root_poa; }
|
|---|
| 78 |
|
|---|
| 79 | CosNaming::NamingContext_var ORB_WRAP::getNamingContext() const { return this->nc; }
|
|---|
| 80 |
|
|---|
| 81 | void ORB_WRAP::anyType( const char* _type, const char* _value, CORBA::Any &myRtn )
|
|---|
| 82 | {
|
|---|
| 83 | CORBA::Any toRtn;
|
|---|
| 84 | char* ptr;
|
|---|
| 85 |
|
|---|
| 86 | // int argc = 0;
|
|---|
| 87 | // CORBA::ORB_var tmp = CORBA::ORB_init( argc, NULL );
|
|---|
| 88 |
|
|---|
| 89 | if( strcmp( _type, "double" ) == 0 ) {
|
|---|
| 90 | CORBA::Double val = strtod( _value, NULL );
|
|---|
| 91 | myRtn <<= val;
|
|---|
| 92 | } else if( strcmp( _type, "ulong" ) == 0 ) {
|
|---|
| 93 | CORBA::ULong val = strtoul( _value, &ptr, 0 );
|
|---|
| 94 | myRtn <<= val;
|
|---|
| 95 | } else if( strcmp( _type, "long" ) == 0 ) {
|
|---|
| 96 | CORBA::Long val = strtol( _value, &ptr, 0 );
|
|---|
| 97 | myRtn <<= val;
|
|---|
| 98 | } else if( strcmp( _type, "short" ) == 0 ) {
|
|---|
| 99 | CORBA::Short val = (short)atoi( _value );
|
|---|
| 100 | myRtn <<= val;
|
|---|
| 101 | } else if( strcmp( _type, "string" ) == 0 ) {
|
|---|
| 102 | myRtn <<= CORBA::string_dup( _value );
|
|---|
| 103 | } else { }
|
|---|
| 104 |
|
|---|
| 105 | //return toRtn;
|
|---|
| 106 | return;
|
|---|
| 107 | }
|
|---|
| 108 |
|
|---|
| 109 | bool ORB_WRAP::isValidType( CORBA::Any _val1, CORBA::Any _val2 )
|
|---|
| 110 | {
|
|---|
| 111 | CORBA::TypeCode_var tc1 = _val1.type();
|
|---|
| 112 | CORBA::TypeCode_var tc2 = _val2.type();
|
|---|
| 113 |
|
|---|
| 114 | if( tc1->equal( tc2 ) )
|
|---|
| 115 | return true;
|
|---|
| 116 | else return false;
|
|---|
| 117 | }
|
|---|
| 118 |
|
|---|
| 119 | void ORB_WRAP::getCosName( CosNaming::Name& cosName, const char* _name )
|
|---|
| 120 | {
|
|---|
| 121 | int _cnt = 0;
|
|---|
| 122 |
|
|---|
| 123 | string _context;
|
|---|
| 124 |
|
|---|
| 125 | char delim = '/';
|
|---|
| 126 |
|
|---|
| 127 | istringstream CNT( _name );
|
|---|
| 128 |
|
|---|
| 129 | getline( CNT, _context, delim );
|
|---|
| 130 |
|
|---|
| 131 | while( getline( CNT, _context, delim ) )
|
|---|
| 132 | _cnt++;
|
|---|
| 133 |
|
|---|
| 134 | // if( _cnt == 0 )
|
|---|
| 135 | // throw;
|
|---|
| 136 |
|
|---|
| 137 | // reset the streams get pointer to the beginning
|
|---|
| 138 | istringstream NAME( _name );
|
|---|
| 139 |
|
|---|
| 140 | // CosNaming::Name cosName;
|
|---|
| 141 |
|
|---|
| 142 | cosName.length(_cnt);
|
|---|
| 143 |
|
|---|
| 144 | getline( NAME, _context, delim );
|
|---|
| 145 |
|
|---|
| 146 | for( int i = 0; i < _cnt; i++ )
|
|---|
| 147 | {
|
|---|
| 148 | getline( NAME, _context, delim );
|
|---|
| 149 |
|
|---|
| 150 | if( _context != "" )
|
|---|
| 151 | cosName[ i ].id = CORBA::string_dup( _context.c_str() );
|
|---|
| 152 | }
|
|---|
| 153 | }
|
|---|
| 154 |
|
|---|
| 155 | bool ORB_WRAP::orbIsWorking = false;
|
|---|
| 156 |
|
|---|
| 157 | int ORB_WRAP::vars = 0;
|
|---|
| 158 |
|
|---|
| 159 | CORBA::ORB_var ORB_WRAP::orb = CORBA::ORB::_nil();
|
|---|
| 160 |
|
|---|