int ACE_TMAIN (int argc, ACE_TCHAR *argv[]) { try { CORBA::ORB_var orb = CORBA::ORB_init(argc, argv); if (parse_args (argc, argv) != 0) return 1; CORBA::Object_var obj = orb->resolve_initial_references("RootPOA"); PortableServer::POA_var root_poa = PortableServer::POA::_narrow(obj.in()); PortableServer::POAManager_var mgr = root_poa->the_POAManager(); const char* poa_name = "MessengerService"; PortableServer::POA_var poa = createPersistentPOA(root_poa.in(), poa_name); PortableServer::Servant_var<Messenger_i> servant1 = new Messenger_i; PortableServer::Servant_var<Messenger_i> servant2 = new Messenger_i; PortableServer::ObjectId_var id1 = PortableServer::string_to_ObjectId("Object1"); poa->activate_object_with_id(id1.in(), servant1.in()); PortableServer::ObjectId_var id2 = PortableServer::string_to_ObjectId("Object2"); poa->activate_object_with_id(id2.in(), servant2.in()); obj = poa->id_to_reference(id1.in()); CORBA::String_var ior1 = orb->object_to_string(obj.in()); obj = poa->id_to_reference(id2.in()); CORBA::String_var ior2 = orb->object_to_string(obj.in()); TAO_Root_POA* tpoa = dynamic_cast<TAO_Root_POA*>(poa.in()); obj = tpoa->id_to_reference_i(id1.in(), false); CORBA::String_var direct_ior1 = orb->object_to_string(obj.in()); obj = orb->resolve_initial_references("IORTable"); IORTable::Table_var ior_table = IORTable::Table::_narrow(obj.in()); ior_table->bind("MessengerService/Object1", direct_ior1.in()); ior_table->bind("MessengerService/Object2", ior2.in()); writeIORFile(ior1.in(), ior_output_file1); writeIORFile(ior2.in(), ior_output_file2); mgr->activate(); std::cout << "Messenger server ready." << std::endl; orb->run(); std::cout << "Messenger server shutting down." << std::endl; root_poa->destroy(1,1); orb->destroy(); return 0; } catch(const CORBA::Exception& ex) { std::cerr << "Server main() Caught Exception" << ex << std::endl; } return 1; }
void AccessCorbaDef_Impl::setServantKey(PortableServer::ServantBase* theServant, const std::string& key) { try { // Resolve the omnibootstrapping POA and activate it CORBA::Object_var obj = getOrb().resolve_initial_references("omniINSPOA"); PortableServer::POA_var poa = PortableServer::POA::_narrow(obj); PortableServer::POAManager_var mgr = poa->the_POAManager(); mgr->activate(); // Activate the servant with the bootstrapping POA PortableServer::ObjectId_var oid = PortableServer::string_to_ObjectId(key.c_str()); poa->activate_object_with_id(oid, theServant); // Add the bootstrapping POA to the list of POAs the // servant is activated with. //theServant->addPOA(poa); } catch(...)//(const CORBA::SystemException& ex) { printf("SystemException\n"); throw 222; } }
CORBA::Object_ptr VOmniORBHelper::poaActivateObject(PortableServer::Servant p_servant, const char* program, const char* object, int telescopenumber) throw(CORBA::SystemException) { PortableServer::ObjectId_var oid = poaPathToObjectId(program,object,telescopenumber); PortableServer::POA_var poa = poaGetOrCreatePoa(program,object,telescopenumber); poa->activate_object_with_id(oid,p_servant); return poa->id_to_reference(oid); }
int ACE_TMAIN (int argc, ACE_TCHAR *argv[]) { try { // Initialize orb CORBA::ORB_var orb = CORBA::ORB_init (argc, argv); // Get reference to Root POA. CORBA::Object_var obj = orb->resolve_initial_references ("RootPOA"); PortableServer::POA_var rootpoa = PortableServer::POA::_narrow (obj.in ()); // Activate POA manager PortableServer::POAManager_var mgr = rootpoa->the_POAManager (); mgr->activate (); PortableServer::POA_var poa; TAO::Utils::PolicyList_Destroyer PolicyList (3); PolicyList.length (3); PolicyList [0] = rootpoa->create_lifespan_policy (PortableServer::PERSISTENT); PolicyList [1] = rootpoa->create_id_assignment_policy (PortableServer::USER_ID); CORBA::Any CallbackPolicy; CallbackPolicy <<= BiDirPolicy::BOTH; const char* sServerPoaName = "TelemetryServer"; PolicyList [2] = orb->create_policy (BiDirPolicy::BIDIRECTIONAL_POLICY_TYPE, CallbackPolicy); poa = rootpoa->create_POA (sServerPoaName, mgr.in(), PolicyList); PortableServer::ObjectId_var ServerId = PortableServer::string_to_ObjectId ("TimeServer"); // Create an object Time_impl *time_servant = new Time_impl; PortableServer::ServantBase_var self_manage (time_servant); poa->activate_object_with_id (ServerId.in (), time_servant); // Get a reference after activating the object CORBA::Object_var object = poa->id_to_reference (ServerId.in ()); TimeModule::Time_var tm = TimeModule::Time::_narrow (object.in ()); // Get reference to initial naming context CORBA::Object_var name_obj = orb->resolve_initial_references ("NameService"); CosNaming::NamingContext_var inc = CosNaming::NamingContext::_narrow (name_obj.in ()); if (CORBA::is_nil (inc.in ())) { ACE_ERROR ((LM_ERROR, "(%P|%t) Error fetching naming context\n")); } CosNaming::Name service_name; service_name.length(1); service_name[0].id = CORBA::string_dup ("Time"); inc->rebind (service_name, tm.in ()); // Run the event loop for fun ACE_Time_Value tv (3, 0); // Accept requests orb->run (&tv); rootpoa->destroy (0 , 0); orb->destroy (); } catch (const CORBA::Exception& ex) { ex._tao_print_exception ("Caught an exception\n"); return -1; } return 0; }
int ACE_TMAIN(int argc, ACE_TCHAR *argv[]) { try { CORBA::ORB_var orb = CORBA::ORB_init (argc, argv); if (parse_args (argc, argv) != 0) return 1; CORBA::Object_var poa_object = orb->resolve_initial_references ("RootPOA"); PortableServer::POA_var rootPOA = PortableServer::POA::_narrow (poa_object.in ()); PortableServer::POAManager_var poa_manager = rootPOA->the_POAManager (); // Policies for the firstPOA to be created. CORBA::PolicyList policies (5); policies.length (5); // Lifespan policy policies[0] = rootPOA->create_lifespan_policy (PortableServer::PERSISTENT ); // Servant Retention Policy policies[1] = rootPOA->create_servant_retention_policy (PortableServer::RETAIN ); // ID Assignment Policy policies[2] = rootPOA->create_id_assignment_policy (PortableServer::USER_ID ); // Request Processing Policy policies[3] = rootPOA->create_request_processing_policy (PortableServer::USE_ACTIVE_OBJECT_MAP_ONLY ); // Threading policy policies[4] = rootPOA->create_thread_policy (PortableServer::ORB_CTRL_MODEL ); PortableServer::POA_var demoPOA = rootPOA->create_POA ("HelloWorldServer", poa_manager.in (), policies ); for (CORBA::ULong i = 0; i < policies.length (); ++i) { CORBA::Policy_ptr policy = policies[i]; policy->destroy (); } // Create object for shutdown commanded by client. { // create the object Demo_HelloWorld_i * hello = new Demo_HelloWorld_i(orb.in()); // Get the Object ID. PortableServer::ObjectId_var oid = PortableServer::string_to_ObjectId ("shutdown"); demoPOA->activate_object_with_id (oid.in (), hello); // Create an object reference. CORBA::Object_var myhello = demoPOA->id_to_reference(oid.in()); // Put the object reference as an IOR string ofstream out(ACE_TEXT_ALWAYS_CHAR (shutdown_ior_output_file)); CORBA::String_var ior = orb->object_to_string (myhello.in ()); out << ior.in(); // save the reference into a file out.close(); } // Create object to handle client sayHello requests. { // create the object Demo_HelloWorld_i * hello = new Demo_HelloWorld_i(orb.in()); // Get the Object ID. PortableServer::ObjectId_var oid = PortableServer::string_to_ObjectId ("hello"); demoPOA->activate_object_with_id (oid.in (), hello); // Create an object reference. CORBA::Object_var myhello = demoPOA->id_to_reference(oid.in()); // Put the object reference as an IOR string ofstream out(ACE_TEXT_ALWAYS_CHAR (ior_output_file)); CORBA::String_var ior = orb->object_to_string (myhello.in ()); out << ior.in(); // save the reference into a file out.close(); } ////////////////////////////////////////////////////////////////////////////////////////////////// poa_manager->activate (); std::cout << ior_output_file << " is ready " << std::endl; orb->run (); // Destroy the POA, waiting until the destruction terminates rootPOA->destroy (1, 1); orb->destroy (); } catch (const CORBA::Exception &e) { std::cerr << "Unexpected exception: " << e << std::endl; return 1; } return 0; }
int ACE_TMAIN (int argc, ACE_TCHAR *argv[]) { try { //init the orb CORBA::ORB_var orb=CORBA::ORB_init(argc, argv); //get the root poa CORBA::Object_var poa_object = orb->resolve_initial_references ("RootPOA"); PortableServer::POA_var poa = PortableServer::POA::_narrow (poa_object.in ()); PortableServer::POAManager_var poa_manager = poa->the_POAManager (); if (parse_args (argc, argv) != 0) return 1; poa_manager->activate (); // Get a reference to the IOR Table CORBA::Object_var tobj = orb->resolve_initial_references("IORTable"); IORTable::Table_var table = IORTable::Table::_narrow(tobj.in()); //get an object id for the name PortableServer::ObjectId_var oid = PortableServer::string_to_ObjectId ("Messenger"); //activate the object for the given id Messenger_i messenger (orb.in ()); poa->activate_object_with_id(oid.in (), &messenger); CORBA::Object_var messenger_obj = poa->id_to_reference (oid.in ()); //bind the ior string to the name CORBA::String_var messenger_ior_string = orb->object_to_string(messenger_obj.in()); table->bind("Messenger", messenger_ior_string.in()); // Output the IOR to the <ior_output_file> FILE *output_file= ACE_OS::fopen (ior_output_file, "w"); if (output_file == 0) ACE_ERROR_RETURN ((LM_ERROR, "Cannot open output file for writing IOR: %s\n", ior_output_file), 1); ACE_OS::fprintf (output_file, "%s", messenger_ior_string.in ()); ACE_OS::fclose (output_file); orb->run (); ACE_DEBUG ((LM_DEBUG, "(%P|%t) server - event loop finished\n")); poa->destroy (1, 1); orb->destroy (); } catch (const CORBA::Exception& ex) { ex._tao_print_exception ("Exception caught:"); return 1; } return 0; }
int ACE_TMAIN (int argc, ACE_TCHAR *argv[]) { try { CORBA::ORB_var orb = CORBA::ORB_init(argc, argv); const ACE_TCHAR *iorfile = ACE_TEXT (""); ACE_Get_Opt get_opts (argc, argv, ACE_TEXT ("o:?")); int c; while ((c = get_opts ()) != -1) switch (c) { case 'o': iorfile = get_opts.opt_arg (); break; case '?': ACE_DEBUG ((LM_DEBUG, "usage: %s " "-d <seconds to delay before initializing POA> " "-n Number of the server\n", argv[0])); return 1; break; } CORBA::Object_var obj = orb->resolve_initial_references ("RootPOA"); root_poa = PortableServer::POA::_narrow (obj.in ()); // TAO_Root_POA::imr_client_adapter_name ("Test_Imr_Adapter"); ACE_CString base = ACE_CString ("TestObject"); createPOAs (base); PortableServer::Servant_var<Test_i> test_servant = new Test_i (); PortableServer::ObjectId_var object_id = PortableServer::string_to_ObjectId (base.c_str()); poa_a->activate_object_with_id (object_id.in(), test_servant.in ()); obj = poa_a->id_to_reference (object_id.in()); Test_var tva = Test::_narrow (obj.in()); if (ACE_OS::strlen (iorfile) > 0) { CORBA::String_var ior = orb->object_to_string (obj.in()); FILE *output_file= ACE_OS::fopen (iorfile, "w"); if (output_file == 0) ACE_ERROR_RETURN ((LM_ERROR, "Cannot open output file for writing IOR: %s\n", iorfile), 1); ACE_OS::fprintf (output_file, "%s", ior.in ()); ACE_OS::fclose (output_file); } poa_b->activate_object_with_id (object_id.in(), test_servant.in ()); obj = poa_b->id_to_reference (object_id.in()); Test_var tvb = Test::_narrow (obj.in()); // object_id = root_poa->activate_object (test_servant.in()); // // This server is now ready to run. // This version does not create an IOR // file as demonstrated in the // Developer's Guide. It assumes that // users create IORs for the client using // the tao_imr utility. // // // Stop discarding requests. // activatePOAs (); // // Create binding between "TestService" and // the test object reference in the IOR Table. // Use a TAO extension to get the non imrified poa // to avoid forwarding requests back to the ImR. TAO_Root_POA* tpoa = dynamic_cast<TAO_Root_POA*> (poa_a.in ()); ACE_ASSERT (tpoa != 0); obj = tpoa->id_to_reference_i (object_id.in (), false); CORBA::String_var test_ior = orb->object_to_string (obj.in ()); obj = orb->resolve_initial_references("IORTable"); IORTable::Table_var table = IORTable::Table::_narrow (obj.in ()); table->bind(base.c_str (), test_ior.in ()); { ACE_CString status_file = base + ACE_CString(".status"); ofstream out(status_file.c_str ()); out << "started" << endl; } test_ior = orb->object_to_string (tva.in()); base += "_a"; ACE_DEBUG ((LM_DEBUG, "%s:\n%s\n", base.c_str(), test_ior.in())); table->bind (base.c_str (), test_ior.in ()); base[base.length()-1] = 'b'; test_ior = orb->object_to_string (tvb.in()); ACE_DEBUG ((LM_DEBUG, "%s:\n%s\n", base.c_str(), test_ior.in())); table->bind (base.c_str (), test_ior.in ()); ACE_DEBUG ((LM_DEBUG, "Started Server %s \n", base.c_str())); orb->run(); root_poa->destroy(1,1); orb->destroy(); } catch(const CORBA::Exception& ex) { ex._tao_print_exception ("Server main()"); return 1; } return 0; }
CORBA::Boolean Adapter_Activator::unknown_adapter (PortableServer::POA_ptr parent, const char *name) { if (ACE_OS::strcmp (name, "firstPOA") == 0) { PortableServer::POA_var child = parent->create_POA (name, this->poa_manager_.in (), this->first_poa_policies_); // Creation of firstPOA is over. Destroy the Policy objects. for (CORBA::ULong i = 0; i < this->first_poa_policies_.length (); ++i) { this->first_poa_policies_[i]->destroy (); } child->the_activator (this); reference_counted_test_i *servant = new reference_counted_test_i (this->orb_.in (), child.in ()); child->set_servant (servant); // This means that the ownership of <servant> now belongs to the // POA. servant->_remove_ref (); // Finally everything is fine return 1; } else if (ACE_OS::strcmp (name, "secondPOA") == 0) { PortableServer::POA_var child = parent->create_POA (name, this->poa_manager_.in (), this->second_poa_policies_); // Creation of secondPOA is over. Destroy the Policy objects. for (CORBA::ULong i = 0; i < this->second_poa_policies_.length (); ++i) { this->second_poa_policies_[i]->destroy (); } reference_counted_test_i *servant = new reference_counted_test_i (this->orb_.in (), child.in ()); PortableServer::ObjectId_var oid = PortableServer::string_to_ObjectId ("third test"); child->activate_object_with_id (oid.in (), servant); // This means that the ownership of <servant> now belongs to the // POA. servant->_remove_ref (); // Finally everything is fine return 1; } else { // Unknown POA. return 0; } }
int ACE_TMAIN (int argc, ACE_TCHAR *argv[]) { try { CORBA::ORB_var orb = CORBA::ORB_init (argc, argv); CORBA::Object_var poa_object = orb->resolve_initial_references ("RootPOA"); PortableServer::POA_var root_poa = PortableServer::POA::_narrow (poa_object.in ()); if (CORBA::is_nil (root_poa.in ())) ACE_ERROR_RETURN ((LM_ERROR, " (%P|%t) Panic: nil RootPOA\n"), 1); PortableServer::POAManager_var poa_manager = root_poa->the_POAManager (); PortableServer::LifespanPolicy_var life = root_poa->create_lifespan_policy (PortableServer::PERSISTENT); PortableServer::IdAssignmentPolicy_var assign = root_poa->create_id_assignment_policy (PortableServer::USER_ID); CORBA::PolicyList pols; pols.length (2); pols[0] = PortableServer::LifespanPolicy::_duplicate (life.in ()); pols[1] = PortableServer::IdAssignmentPolicy::_duplicate (assign.in ()); PortableServer::POA_var poa = root_poa->create_POA ("ImRified POA", poa_manager.in (), pols); life->destroy (); assign->destroy (); Hello *hello_impl = 0; ACE_NEW_RETURN (hello_impl, Hello, 1); PortableServer::ServantBase_var owner_transfer (hello_impl); PortableServer::ObjectId_var id = PortableServer::string_to_ObjectId ("Test 3891 Object"); poa->activate_object_with_id (id.in (), hello_impl); CORBA::Object_var obj = poa->id_to_reference (id.in ()); if (!obj->_stubobj ()->type_id.in () || ACE_OS::strcmp (obj->_stubobj ()->type_id.in (), hello_impl->_repository_id ())) { ACE_ERROR_RETURN ((LM_ERROR, "ERROR: type_id is incorrect\n"), 1); } root_poa->destroy (1, 1); orb->destroy (); } catch (const CORBA::Exception& ex) { ex._tao_print_exception ("Exception caught:"); return 1; } return 0; }
bool ServiceOptions::bindServiceObject(CORBA::ORB_ptr orb, CORBA::Object_ptr object, PortableServer::Servant p_servant, const char* objName, bool rebind) { if(is_set("with-naming")) { CosNaming::Name name; name.length(1); name[0].id=CORBA::string_dup(objName); name[0].kind=CORBA::string_dup(""); CORBA::Object_var obj ; try { obj = orb->resolve_initial_references("NameService"); }catch(const CORBA::ORB::InvalidName& ex){ std::cerr << argv()[0] << ": can't resolve `NameService'" << std::endl; return false; } CosNaming::NamingContext_var nc; try { nc = CosNaming::NamingContext::_narrow(obj.in()); }catch(const CORBA::SystemException& ex){ std::cerr << argv()[0] << ": can't narrow naming service" << std::endl; return false; } try { if(rebind){ nc->rebind(name,object); }else{ try{ nc->bind(name,object); }catch(const CosNaming::NamingContext::AlreadyBound&){ std::cerr<<argv()[0]<<":can't bind "<<objName<<" (AlreadyBound)"<< std::endl; return false; } } }catch(const CosNaming::NamingContext::CannotProceed&){ std::cerr<<argv()[0]<<": can't bind "<<objName<<" (CannotProceed)"<< std::endl; return false; }catch(const CosNaming::NamingContext::InvalidName&){ std::cerr<<argv()[0]<<":can't bind "<<objName<<" (InvalidName)"<< std::endl; return false; } std::cout<<argv()[0]<<": binding completed successfully"<<std::endl; } CORBA::String_var ior ; try { ior = orb->object_to_string(object); }catch(const CORBA::SystemException& ex){ #ifdef CORBA_SYSTEM_EXCEPTION_IS_STREAMBLE std::cerr << ex << std::endl; #else std::cerr << "CORBA::SystemException" << std::endl; #endif return false; } const char* fname = get_ior_fname(objName); if (fname!=NULL && strcmp(fname,"")!=0) { std::ofstream ofs (fname); if (ofs.bad()) { std::cerr << argv()[0] << ": can't open file " << fname << std::endl; perror(argv()[0]); return false; } ofs << ior.in(); ofs.close(); } if (is_set("ior-stdout")) { std::cout << ior << std::flush; } #ifdef ORBACUS CORBA::Object_var bmgrObj = orb->resolve_initial_references("BootManager"); OB::BootManager_var bootManager = OB::BootManager::_narrow(bmgrObj); PortableServer::ObjectId_var oid = PortableServer::string_to_ObjectId(objName); bootManager -> add_binding(oid.in(),object); #elif defined(OMNIORB) PortableServer::POA_var objPOA = p_servant->_default_POA(); CORBA::String_var objPOAName = objPOA->the_name(); if (strcmp(objPOAName.in(),"omniINSPOA")!=0) { CORBA::Object_var insPOAObj = orb->resolve_initial_references("omniINSPOA"); PortableServer::POA_var insPOA = PortableServer::POA::_narrow(insPOAObj); PortableServer::POAManager_var insPOAManager=insPOA->the_POAManager(); insPOAManager->activate(); PortableServer::ObjectId_var oid = PortableServer::string_to_ObjectId(objName); insPOA->activate_object_with_id(oid.in(),p_servant); } #elif defined(RSSH_TAO) #ifdef TAO_HAVE_IORTABLE_ADAPTER CORBA::Object_var table = orb->resolve_initial_references ("IORTable"); IORTable::Table_var adapter = IORTable::Table::_narrow (table.in()); if (CORBA::is_nil(adapter.in())) { cerr<<argv()[0]<<": nil IORTable reference"<<endl; } else { adapter->bind (objName, ior.in ()); } #else ACE_CString ins(objName); if (orb->_tao_add_to_IOR_table(ins,object)!=0) { return false; } #endif #elif defined(MICO) // create persistent POA with name as service name if we have no one. PortableServer::POA_var objPOA = p_servant->_default_POA(); CORBA::String_var objPOAName = objPOA->the_name(); std::cerr << "existent OBJPOAName=" << objPOAName.in() << std::endl; std::cerr << "objName=" << objName << std::endl; if (strcmp(objPOAName.in(),objName)!=0) { CORBA::Object_var rootPOAObj = orb->resolve_initial_references ("RootPOA"); PortableServer::POA_var rootPOA = PortableServer::POA::_narrow(rootPOAObj); CORBA::PolicyList pl; pl.length (2); pl[0] = rootPOA->create_lifespan_policy (PortableServer::PERSISTENT); pl[1] = rootPOA->create_id_assignment_policy (PortableServer::USER_ID); PortableServer::POA_var objPOA = rootPOA->create_POA(objName, PortableServer::POAManager::_nil (), pl); PortableServer::POAManager_var objPOAManager = objPOA->the_POAManager (); PortableServer::ObjectId_var objId = PortableServer::string_to_ObjectId (objName); objPOA->activate_object_with_id (objId.in(), p_servant); objPOAManager->activate(); }else{ //PortbaobjPOA } #endif return true; }
int ACE_TMAIN(int argc, ACE_TCHAR *argv[]) { try { CORBA::ORB_var orb = CORBA::ORB_init (argc, argv); // We do the command line parsing first if (parse_args (argc, argv) != 0) return 1; CORBA::Object_var poa_object = orb->resolve_initial_references("RootPOA"); if (CORBA::is_nil (poa_object.in ())) ACE_ERROR_RETURN ((LM_ERROR, " (%P|%t) Unable to initialize the POA.\n"), 1); PortableServer::POA_var root_poa = PortableServer::POA::_narrow (poa_object.in ()); PortableServer::POAManager_var poa_manager = root_poa->the_POAManager (); CORBA::PolicyList policies; policies.length (3); policies[0] = root_poa->create_id_assignment_policy ( PortableServer::USER_ID); policies[1] = root_poa->create_implicit_activation_policy ( PortableServer::NO_IMPLICIT_ACTIVATION); policies[2] = root_poa->create_lifespan_policy ( PortableServer::PERSISTENT); PortableServer::POA_var poa = root_poa->create_POA ( "PERS_POA", poa_manager.in (), policies); for (CORBA::ULong i = 0; i < policies.length (); ++i) { policies[i]->destroy (); } // Instantiate the LCD_Display implementation class Simple_Server_i display_impl (orb.in (), ACE_TEXT_ALWAYS_CHAR(key)); PortableServer::ObjectId_var id = PortableServer::string_to_ObjectId ("IOGR_OID"); poa->activate_object_with_id (id.in(), &display_impl); CORBA::Object_var server = poa->id_to_reference (id.in ()); CORBA::String_var ior = orb->object_to_string (server.in ()); ACE_DEBUG ((LM_DEBUG, "Activated as <%C>\n", ior.in ())); // If the ior_output_file exists, output the ior to it if (ior_output_file != 0) { FILE *output_file= ACE_OS::fopen (ior_output_file, "w"); if (output_file == 0) ACE_ERROR_RETURN ((LM_ERROR, "Cannot open output file for writing IOR: %s", ior_output_file), 1); ACE_OS::fprintf (output_file, "%s", ior.in ()); ACE_OS::fclose (output_file); } poa_manager->activate (); orb->run (); } catch (const CORBA::Exception& ex) { ex._tao_print_exception ("Caught exception:"); return 1; } return 0; }
int main(int argc,char *argv []) { CORBA::ORB_ptr orb_ptr; try { /************************************************************************/ /* INICIALIZAMOS LA PARTE DEL ORB */ /************************************************************************/ int alt_argc = 0; char ** alt_argv; const char * orb_id="Test_TIDNotification"; orb_ptr=CORBA::ORB_init(argc, argv, orb_id); if (!orb_ptr) { cerr<<"El ORB es null"<<endl; return -1; } CORBA::Object_ptr delegado_POA; PortableServer::POA_ptr rootPOA; try { delegado_POA = orb_ptr->resolve_initial_references("RootPOA"); } catch ( CORBA::ORB::InvalidName ex ) { ex._name(); return -1; } rootPOA = PortableServer::_POAHelper::narrow( delegado_POA,true ); PortableServer::POAManager_var poa_manager = rootPOA->the_POAManager(); CORBA::PolicyList_var policies = NULL; policies = new CORBA::PolicyList(2); policies->length(2); // Valores cambiados (*policies)[0] = rootPOA->create_lifespan_policy ( PortableServer::PERSISTENT ); (*policies)[1] = rootPOA->create_id_assignment_policy ( PortableServer::USER_ID ); PortableServer::POA_var consumerPOA = rootPOA->create_POA("consumerPOA", poa_manager, *policies ); /***********************************************************************/ /* OBTENEMOS LA FACTORIA DEL CANAL DE EVENTOS Y CREAMOS EL CANAL */ /**********************************************************************/ CORBA::Object_ptr delegado_event_channel_factory; delegado_event_channel_factory=orb_ptr->string_to_object(argv[1]); CosNotifyChannelAdmin::EventChannelFactory_var factory; factory = CosNotifyChannelAdmin::EventChannelFactory::_narrow(delegado_event_channel_factory); if (CORBA::is_nil(factory)) { cerr << "[server] ERROR: factoria nula " << endl; return -1; } CosNotifyChannelAdmin::EventChannel_var channel; //CosNotifyChannelAdmin::EventChannel_var channelv[10]; CosNotification::QoSProperties initial_qos; CosNotification::AdminProperties initial_admin; CosNotifyChannelAdmin::ChannelID id; //CosNotifyChannelAdmin::ChannelID idv[10]; // // Politicas Soportadas: // initial_qos.length(9); // initial_qos[0].name = CORBA::string_dup("OrderPolicy"); // initial_qos[0].value <<= CosNotification::FifoOrder; // Any Fifo Priority Deadline // initial_qos[1].name = CORBA::string_dup("EventReliability"); // initial_qos[1].value <<= CosNotification::BestEffort; // Persistent // initial_qos[2].name = CORBA::string_dup("ConnectionReliability"); // initial_qos[2].value <<= CosNotification::BestEffort; // Persistent // initial_qos[3].name = CORBA::string_dup("Priority"); // initial_qos[3].value <<= CosNotification::HighestPriority; // Highest, Default // initial_qos[4].name = CORBA::string_dup("StartTime"); // initial_qos[4].value <<= *(new TimeBase::UtcT( // TIDorb::core::util::Time::currentTimeMillis(), // 0,0,0)); // initial_qos[5].name = CORBA::string_dup("StopTime"); // initial_qos[5].value <<= *(new TimeBase::UtcT( // TIDorb::core::util::Time::currentTimeMillis(), // 0,0,0)); // initial_qos[6].name = CORBA::string_dup("Timeout"); // initial_qos[6].value <<= (TimeBase::TimeT)TIDorb::core::util::Time::currentTimeMillis(); // initial_qos[7].name = CORBA::string_dup("StartTimeSupported"); // initial_qos[7].value <<= (CORBA::Boolean) 0; // initial_qos[8].name = CORBA::string_dup("StopTimeSupported"); // initial_qos[8].value <<= (CORBA::Boolean) 1; // // Politicas de QoS no soportadas // // initial_qos[0].name = CORBA::string_dup("DiscardPolicy"); // initial_qos[0].value <<= CosNotification::AnyOrder; // Any Fifo Priority Deadline // initial_qos[7].name = CORBA::string_dup("MaximumBatchSize"); // initial_qos[7].value <<= (CORBA::Long) 20; // initial_qos[0].name = CORBA::string_dup("PacingInterval"); // initial_qos[0].value <<= (TimeBase::TimeT)TIDorb::core::util::Time::currentTimeMillis(); // initial_qos[9].name = CORBA::string_dup("MaxEventsPerConsumer"); // initial_qos[9].value <<= (CORBA::Long) 20; try { // Crear el canal channel = factory->get_event_channel(0); // for(int i=0; i < 10; i++){ // channelv[i] = factory->create_channel(initial_qos, initial_admin, idv[i]); // } } catch (CosNotifyChannelAdmin::ChannelNotFound &ex) { cerr << "[server_consumer] CosNotifyChannelAdmin::ChannelNotFound: " << ex._name(); return -1; } /**************************************************************************/ /* OBTENEMOS EL CONSUMERADMIN POR DEFECTO */ /**************************************************************************/ CosNotifyChannelAdmin::ConsumerAdmin_ptr consumerAdmin; consumerAdmin = channel->default_consumer_admin(); //Metemos los filtros en el consumer admin CosNotifyFilter::Filter* filter_II = create_filter(channel,"GSyC","test","$domain_name != 'GSyC'"); //consumerAdmin->add_filter(filter_II); //CosNotifyFilter::Filter* filter_III = create_filter(channel,"GSyC","test","$.remainder_of_boy.campo_uno != 1"); //consumerAdmin->add_filter(filter_III); /**************************************************************************/ /* OBTENEMOS EL PROXYSUPPLIER APARTIR DEL CONSUMERADMIN */ /**************************************************************************/ //TODO_MORFEO: add new filters CosNotifyChannelAdmin::ProxySupplier_ptr proxySupplier; CosNotifyChannelAdmin::ProxyID proxySupplierID = 1; proxySupplier = consumerAdmin->obtain_notification_push_supplier(CosNotifyChannelAdmin::ANY_EVENT, proxySupplierID); /**************************************************************************/ /* OBTENEMOS EL PROXYPUSHSUPPLIER APARTIR DEL CONSUMERADMIN */ /**************************************************************************/ CosNotifyChannelAdmin::StructuredProxyPushSupplier_ptr proxyPushSupplier; proxyPushSupplier = CosNotifyChannelAdmin::StructuredProxyPushSupplier::_narrow(proxySupplier); /**************************************************************************/ /* INSTANCIAMOS LOS PROXYS Y LOS ACTIVAMOS EN EL POA */ /**************************************************************************/ my_push_consumer * my_consumer = new my_push_consumer(orb_ptr,proxyPushSupplier); PortableServer::ObjectId_ptr consumer_objectID = PortableServer::string_to_ObjectId("My_Consumer:1.0"); consumerPOA->activate_object_with_id(*consumer_objectID,my_consumer); poa_manager->activate(); CORBA::Object_ptr obj_consumer = consumerPOA->id_to_reference(*consumer_objectID); CosNotifyComm::StructuredPushConsumer_ptr my_pushConsumer = CosNotifyComm::StructuredPushConsumer::_narrow(obj_consumer); /***********************************************************************/ /* CONECTAMOS EL PUSHSUPPLIER Y EL PUSHCONSUMER */ /***********************************************************************/ proxyPushSupplier->connect_structured_push_consumer(my_pushConsumer); orb_ptr->run(); } catch (CORBA::Exception & e) { cerr<<"[Test_Filter] unknown error"<< typeid(e).name() << e._name(); return -1; } }
int run(CORBA::ORB_ptr orb, int /* argc */, char* argv[]) { // // Resolve Root POA // CORBA::Object_var poaObj = orb -> resolve_initial_references("RootPOA"); PortableServer::POA_var rootPOA = PortableServer::POA::_narrow(poaObj); // // Create Persistent POA // CORBA::PolicyList pl; pl.length (4); pl[0] = rootPOA->create_lifespan_policy(PortableServer::PERSISTENT); pl[1] = rootPOA->create_id_assignment_policy(PortableServer::USER_ID); pl[2] = rootPOA->create_thread_policy(PortableServer::SINGLE_THREAD_MODEL); pl[3] = rootPOA->create_implicit_activation_policy(PortableServer::NO_IMPLICIT_ACTIVATION); // // Get a reference to the POA manager // PortableServer::POAManager_var manager = rootPOA -> the_POAManager(); // // Create Persistent POA // PortableServer::POA_var stapoa = rootPOA->create_POA ("stapoa",manager,pl) ; // // Resolve the BootManager and register the server // CORBA::Object_var obj = orb -> resolve_initial_references("BootManager"); OB::BootManager_var bootManager = OB::BootManager::_narrow(obj); // // Create implementation object // Hello_impl* helloImpl = new Hello_impl(stapoa); PortableServer::ServantBase_var servant = helloImpl; PortableServer::ObjectId_var oid = PortableServer::string_to_ObjectId("Hello"); stapoa->activate_object_with_id(oid, servant); Hello_var hello = helloImpl -> _this(); // // add binding to BootManager // bootManager -> add_binding(oid, hello); // // Save reference // CORBA::String_var s = orb -> object_to_string(hello); const char* refFile = "Hello.ref"; ofstream out(refFile); if(out.fail()) { cerr << argv[0] << ": can't open `" << refFile << "': " << strerror(errno) << endl; return EXIT_FAILURE; } out << s << endl; out.close(); // // Run implementation // manager -> activate(); orb -> run(); return EXIT_SUCCESS; }
int Server_i::init (int argc, ACE_TCHAR** argv) { try { this->orb_ = CORBA::ORB_init (argc, argv); int retval = this->parse_args (argc, argv); if (retval != 0) return retval; CORBA::Object_var obj = this->orb_->resolve_initial_references ("RootPOA"); this->root_poa_ = PortableServer::POA::_narrow (obj.in ()); ACE_ASSERT(! CORBA::is_nil(this->root_poa_.in())); PortableServer::POAManager_var poa_manager = this->root_poa_->the_POAManager (); obj = this->orb_->resolve_initial_references ("IORTable"); IORTable::Table_var ior_table = IORTable::Table::_narrow (obj.in ()); ACE_ASSERT(! CORBA::is_nil(ior_table.in())); // If -orbuseimr 1 is specified then all persistent poas will be // registered with the imr. CORBA::PolicyList policies (2); policies.length (2); policies[0] = this->root_poa_->create_id_assignment_policy (PortableServer::USER_ID); policies[1] = this->root_poa_->create_lifespan_policy (PortableServer::PERSISTENT); test_i* test_svt; ACE_NEW_RETURN (test_svt, test_i(orb_.in()), -1); PortableServer::ServantBase_var scoped_svt(test_svt); PortableServer::ObjectId_var server_id = PortableServer::string_to_ObjectId ("Test"); // Create count_ POAs, activate an object in each, and register the object with // the IORTable. for (int i = 0; i < this->count_; ++i) { ACE_CString name = this->server_name_ + "_" + toStr(i); PortableServer::POA_var poa = this->root_poa_->create_POA (name.c_str(), poa_manager.in (), policies); poa->activate_object_with_id (server_id.in (), test_svt); TAO_Root_POA* tmp_poa = dynamic_cast<TAO_Root_POA*>(poa.in()); obj = tmp_poa->id_to_reference_i (server_id.in (), false); CORBA::String_var ior = this->orb_->object_to_string (obj.in ()); ior_table->bind (name.c_str(), ior.in ()); } policies[0]->destroy(); policies[1]->destroy(); } catch (const CORBA::Exception& ex) { ex._tao_print_exception ("Server_i::init"); throw; } return 0; }