コード例 #1
0
int main(int argc, char** argv)
{
  try {
    IDL::traits<CORBA::ORB>::ref_type orb = CORBA::ORB_init (argc, argv);
    IDL::traits<CORBA::Object>::ref_type obj = orb->resolve_initial_references ("RootPOA");
    IDL::traits<PortableServer::POA>::ref_type poa = IDL::traits<PortableServer::POA>::narrow (obj);

    CORBA::servant_traits<Example::Echo>::ref_type server = CORBA::make_reference<Server> ();

    PortableServer::ObjectId id = poa->activate_object (server);

    std::string sior(orb->object_to_string(server->_this()));
    std::cout << sior << std::endl;

    IDL::traits<PortableServer::POAManager>::ref_type pman = poa->the_POAManager ();

    pman->activate();

    orb->run();
    orb->destroy();
  }
  catch (CORBA::SystemException& ex) {
    std::cerr << "Caught CORBA::" << ex << std::endl;
  }
  catch (CORBA::Exception& ex) {
    std::cerr << "Caught CORBA::Exception: " << ex << std::endl;
  }
  catch (std::exception& ex) {
    std::cerr << "Caught std exception: " << ex.what() << std::endl;
  }
  return 0;
}
コード例 #2
0
ファイル: server.cpp プロジェクト: bergsteiger/rumtmarc
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);

    HelloWorld_i* myhello = new HelloWorld_i();
    PortableServer::ObjectId_var myhelloid = poa->activate_object(myhello);
    
    obj = myhello->_this();
    CORBA::String_var sior(orb->object_to_string(obj));
    
    const char* myRef = argv[1];
    ofstream out(myRef);
    if(out.fail())
    {
      cerr << argv[0] << ": can't open `" << myRef << "': "
           << strerror(errno) << endl;
      return EXIT_FAILURE;
    }
    out << sior << endl;
    out.close();
    
    myhello->_remove_ref();

    PortableServer::POAManager_var pman = poa->the_POAManager();
    pman->activate();

    orb->run();
    	
    orb->destroy();
  }
  catch(CORBA::COMM_FAILURE& ex) {
    cerr << "Caught system exception COMM_FAILURE -- unable to contact the "
         << "object." << endl;
  }
  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;
}
コード例 #3
0
ファイル: server.cpp プロジェクト: bluehavana/sword
int main (int argc, char** argv)
{
  try {

	for (int i = 1; i < argc; i++) {
		if (!strcmp(argv[i], "-sysConf")) {
			if ((i+1) < argc)
				sysConf = new SWConfig(argv[i+1]);
		}
	}

	swordMgr = new WebMgr(sysConf);


	const char* options[][2] = {
		{ "nativeCharCodeSet", "UTF-8" }
	   , { 0, 0 }
     };


    // Initialise the ORB.
    CORBA::ORB_var orb = CORBA::ORB_init(argc, argv, "omniORB4", options);

    // 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.
//    swordorb_SWModule_i* myswordorb_SWModule_i = new swordorb_SWModule_i();
    swordorb_SWMgr_i* myswordorb_SWMgr_i = new swordorb_SWMgr_i(swordMgr);


    // Activate the objects.  This tells the POA that the objects are
    // ready to accept requests.
 //   PortableServer::ObjectId_var myswordorb_SWModule_iid = poa->activate_object(myswordorb_SWModule_i);
    PortableServer::ObjectId_var myswordorb_SWMgr_iid = poa->activate_object(myswordorb_SWMgr_i);


    {
      // IDL interface: swordorb::SWMgr
      CORBA::Object_var ref = myswordorb_SWMgr_i->_this();
      CORBA::String_var sior(orb->object_to_string(ref));
      std::cout << (char*)sior << std::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&) {
    std::cerr << "Caught system exception TRANSIENT -- unable to contact the "
         << "server." << std::endl;
  }
  catch(CORBA::SystemException& ex) {
    std::cerr << "Caught a CORBA::" << ex._name() << std::endl;
  }
  catch(CORBA::Exception& ex) {
    std::cerr << "Caught CORBA::Exception: " << ex._name() << std::endl;
  }
  catch(omniORB::fatalException& fe) {
    std::cerr << "Caught omniORB::fatalException:" << std::endl;
    std::cerr << "  file: " << fe.file() << std::endl;
    std::cerr << "  line: " << fe.line() << std::endl;
    std::cerr << "  mesg: " << fe.errmsg() << std::endl;
  }
  return 0;
}