// // Example code for implementing IDL interfaces in file echo.idl // #include #include using namespace std; // // Example class implementing IDL interface Echo // class Echo_i: public POA_Echo { private: // Make sure all instances are built on the heap by making the // destructor non-public //virtual ~Echo_i(); public: // standard constructor Echo_i(); virtual ~Echo_i(); // methods corresponding to defined IDL attributes and operations void st_fi(st_fi_t& p1); }; // // Example implementational code for IDL interface Echo // Echo_i::Echo_i(){ // add extra constructor code here } Echo_i::~Echo_i(){ // add extra destructor code here } // Methods corresponding to IDL attributes and operations void Echo_i::st_fi(st_fi_t& p1){ cerr << "st_fi called" << endl; } // End of example implementational code int main(int argc, char** argv) { try { // Initialise the ORB. CORBA::ORB_var orb = CORBA::ORB_init(argc, argv); // Obtain a reference to the root POA. CORBA::Object_var obj = orb->resolve_initial_references("RootPOA"); PortableServer::POA_var poa = PortableServer::POA::_narrow(obj); // We allocate the objects on the heap. Since these are reference // counted objects, they will be deleted by the POA when they are no // longer needed. Echo_i* myEcho_i = new Echo_i(); // Activate the objects. This tells the POA that the objects are // ready to accept requests. PortableServer::ObjectId_var myEcho_iid = poa->activate_object(myEcho_i); // Obtain a reference to each object and output the stringified // IOR to stdout { // IDL interface: Echo CORBA::Object_var ref = myEcho_i->_this(); CORBA::String_var sior(orb->object_to_string(ref)); cout << (char*)sior << endl; } // Obtain a POAManager, and tell the POA to start accepting // requests on its objects. PortableServer::POAManager_var pman = poa->the_POAManager(); pman->activate(); orb->run(); orb->destroy(); } catch(CORBA::TRANSIENT&) { cerr << "Caught system exception TRANSIENT -- unable to contact the " << "server." << endl; } catch(CORBA::SystemException& ex) { cerr << "Caught a CORBA::" << ex._name() << endl; } catch(CORBA::Exception& ex) { cerr << "Caught CORBA::Exception: " << ex._name() << 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; } return 0; }