// anyExample_impl.cc - This is the source code of the example used in // Chapter 9 "Type Any and TypeCode" of the omniORB // users guide. // // This is the object implementation. // // Usage: anyExample_impl // // On startup, the object reference is printed to cerr as a // stringified IOR. This string should be used as the argument to // anyExample_clt. // #include #include class anyExample_i : public POA_anyExample { public: inline anyExample_i() {} virtual ~anyExample_i() {} virtual CORBA::Any* testOp(const CORBA::Any& a); }; CORBA::Any* anyExample_i::testOp(const CORBA::Any& a) { cout << "Any received, containing: " << endl; #ifndef NO_FLOAT CORBA::Double d; #endif CORBA::Long l; const char* str; testStruct* tp; if (a >>= l) { cout << "Long: " << l << endl; } #ifndef NO_FLOAT else if (a >>= d) { cout << "Double: " << d << endl; } #endif else if (a >>= str) { cout << "String: " << str << endl; } else if (a >>= tp) { cout << "testStruct: l: " << tp->l << endl; cout << " s: " << tp->s << endl; } else { cout << "Unknown value." << endl; } CORBA::Any* ap = new CORBA::Any; *ap <<= (CORBA::ULong) 314; cout << "Returning Any containing: ULong: 314\n" << endl; return ap; } ////////////////////////////////////////////////////////////////////// int main(int argc, char** argv) { try { CORBA::ORB_var orb = CORBA::ORB_init(argc, argv, "omniORB3"); CORBA::Object_var obj = orb->resolve_initial_references("RootPOA"); PortableServer::POA_var poa = PortableServer::POA::_narrow(obj); anyExample_i* myobj = new anyExample_i(); PortableServer::ObjectId_var myobjid = poa->activate_object(myobj); obj = myobj->_this(); CORBA::String_var sior(orb->object_to_string(obj)); cerr << "'" << (char*)sior << "'" << endl; myobj->_remove_ref(); PortableServer::POAManager_var pman = poa->the_POAManager(); pman->activate(); orb->run(); orb->destroy(); } catch(CORBA::SystemException&) { cerr << "Caught CORBA::SystemException." << endl; } catch(CORBA::Exception&) { cerr << "Caught CORBA::Exception." << endl; } catch(omniORB::fatalException& fe) { cerr << "Caught omniORB::fatalException:" << endl; cerr << " file: " << fe.file() << endl; cerr << " line: " << fe.line() << endl; cerr << " mesg: " << fe.errmsg() << endl; } catch(...) { cerr << "Caught unknown exception." << endl; } return 0; }