#include #include "test2.hh" using namespace std; class test2Impl : public POA_bigobject, public PortableServer::RefCountServantBase { public: CORBA::Long f(CORBA::Long x) { return x*x*x; } char* g(char*& s) { char* t = (const char*)"hello from client"; s[1] = 'N'; return CORBA::string_dup(t); } }; // my version doesn't use a context static void bindToName(CORBA::ORB_ptr orb, const char* name, CORBA::Object_ptr objref) { CORBA::Object_var orbobj; CosNaming::NamingContext_var rootContext; try // use orb to locate root naming context. { orbobj = orb->resolve_initial_references("NameService"); rootContext = CosNaming::NamingContext::_narrow(orbobj); if (CORBA::is_nil(rootContext)) { cerr << "no root context\n"; return; } CosNaming::Name objname; objname.length(1); objname[0].id = name; objname[0].kind = (const char*)"Object"; try { rootContext->bind(objname,objref); } catch (CosNaming::NamingContext::AlreadyBound& ex) { rootContext->rebind(objname,objref); } } catch (CORBA::ORB::InvalidName& ex) { cerr << "this is weird: no name service, but then again, it's CORBA!\n"; } // catch invalidname catch (CORBA::COMM_FAILURE& ex2) { cerr << "can't contact naming service - uncommon orb architecture!\n"; } catch (CORBA::SystemException& ex3) { cerr << "system exception while using name service - flame omg\n"; } } // bindToName int main(int argc, char** argv) { // init orb: CORBA::ORB_var orb = CORBA::ORB_init(argc, argv, "omniORB4"); CORBA::Object_var obj = orb->resolve_initial_references("RootPOA"); PortableServer::POA_var poa = PortableServer::POA::_narrow(obj); poa->the_POAManager()->activate(); // create server object(s) test2Impl *servant = new test2Impl(); poa->activate_object(servant); // get special corba reference to servant object before registering it // _this() makes a CORBA object reference from an object: obj = servant->_this(); bindToName(orb,"test2server",obj); servant->_remove_ref(); // remove the reference, not the servant object! cout << orb->object_to_string(obj) << endl; cout << "ready for clients ...\n"; orb->run(); return 0; } // main /* 1. make sure the following environment variables LD_LIBRARY_PATH=/usr/local/lib # where omniorb libraries are installed OMNIORB_CONFIG=/home/cliang/csc290/corba/omniORB.cfg # where you want the cfg 2. copy my sample omniORB.cfg to the file above, editing it if you wish 3. compile the idl into c++ stubs: omniidl -bcxx test2.idl 4. compile this program with: g++ -o test2server -D__x86__ -D__linux__ -D__OSVERSION__=2 -I/usr/local/include/omniORB4 test2server.cpp test2SK.cc -lomniORB4 -lomnithread -lpthread 5. compile the java client with idlj -fall, and javac 6. start omniorb's name service omniNames & 7. start server: test2server & 8. start the java client: java test2client -ORBInitialPort 2809 */