int TAO_MonitorManager::ORBTask::svc (void) { try { if (CORBA::is_nil (this->orb_.in ())) { ORBSVCS_ERROR_RETURN ((LM_ERROR, "(%P|%t) TAO_MonitorManager: Unable to " "initialize the ORB\n"), 1); } PortableServer::POA_var poa; { ACE_GUARD_RETURN (TAO_SYNCH_MUTEX, guard, this->mutex_, -1); CORBA::Object_var obj = this->orb_->resolve_initial_references ("RootPOA"); poa = PortableServer::POA::_narrow (obj.in ()); if (CORBA::is_nil (poa.in ())) { ORBSVCS_ERROR_RETURN ((LM_ERROR, "(%P|%t) TAO_MonitorManager: Unable to " "resolve the RootPOA\n"), 1); } PortableServer::POAManager_var poa_manager = poa->the_POAManager (); poa_manager->activate (); // Activate the object NotificationServiceMonitor_i* servant; ACE_NEW_RETURN (servant, NotificationServiceMonitor_i (this->orb_.in ()), 1); PortableServer::ServantBase_var owner_transfer(servant); PortableServer::ObjectId_var id = poa->activate_object (servant); // Register the object with the IORTable obj = poa->id_to_reference (id.in ()); CosNotification::NotificationServiceMonitorControl_var monitor = CosNotification::NotificationServiceMonitorControl::_narrow (obj.in ()); CORBA::String_var ior = this->orb_->object_to_string (monitor.in ()); obj = this->orb_->resolve_initial_references ("IORTable"); IORTable::Table_var iortable = IORTable::Table::_narrow (obj.in ()); if (CORBA::is_nil (iortable.in ())) { ORBSVCS_ERROR_RETURN ((LM_ERROR, "(%P|%t) TAO_MonitorManager: Unable to " "resolve the IORTable\n"), 1); } iortable->bind(ACE_TEXT_ALWAYS_CHAR(mc_orb_name_.c_str()), ior.in ()); if (this->use_name_svc_) { TAO_Naming_Client nc; nc.init (this->orb_.in ()); CosNaming::Name name (1); name.length (1); name[0].id = CORBA::string_dup (ACE_TEXT_ALWAYS_CHAR(mc_orb_name_.c_str())); nc->rebind (name, monitor.in ()); } if (this->ior_output_.length () > 0) { FILE* fp = ACE_OS::fopen (this->ior_output_.c_str (), "w"); if (fp == 0) { ORBSVCS_ERROR_RETURN ((LM_ERROR, ACE_TEXT ("(%P|%t) TAO_MonitorManager: " ACE_TEXT ("Unable to write to %s\n")), this->ior_output_.c_str ()), 1); } else { ACE_OS::fprintf (fp, "%s", ior.in ()); ACE_OS::fclose (fp); } } } // R1: race condition (partially fixed): // TAO_MonitorManager::fini() is called directly after // TAO_MonitorManager::run(), the shutdown call on the ORB could // happen but the ORB::run() loop won't exit. startup_barrier_.wait (); this->orb_->run (); ACE_GUARD_RETURN (TAO_SYNCH_MUTEX, guard, this->mutex_, -1); // Destroy the POA and ORB if (!CORBA::is_nil (poa.in ())) { poa->destroy (true, true); } this->orb_->destroy (); // Set to nil to avoid double shutdown in TAO_MonitorManager::fini() this->orb_ = CORBA::ORB::_nil (); } catch (const CORBA::Exception& ex) { if (!CORBA::is_nil (this->orb_.in ())) { try { this->orb_->shutdown (); } catch (...) { } this->orb_ = CORBA::ORB::_nil (); } ex._tao_print_exception ("Caught in " "TAO_MonitorManager::ORBTask::svc"); } catch (...) { if (!CORBA::is_nil (this->orb_.in ())) { try { this->orb_->shutdown (); } catch (...) { } this->orb_ = CORBA::ORB::_nil (); } ORBSVCS_ERROR ((LM_ERROR, "Unexpected exception type caught " "in TAO_MonitorManager::ORBTask::svc")); } 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"); 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 (); poa_manager->activate (); if (parse_args (argc, argv) != 0) { return 1; } CORBA::Object_var object = orb->string_to_object (ior); DSI_Simple_Server server_impl (orb.in (), object.in (), root_poa.in ()); PortableServer::ObjectId_var oid = root_poa->activate_object (&server_impl); CORBA::Object_var server = root_poa->id_to_reference (oid.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); } orb->run (); ACE_DEBUG ((LM_DEBUG, "event loop finished\n")); } catch (const CORBA::Exception& ex) { ex._tao_print_exception ("Gateway: exception caught - "); return 1; } 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 (); if (parse_args (argc, argv) != 0) return 1; PortableServer::Servant_var<Simple_C> simple_c_impl( new Simple_C(orb.in())); PortableServer::ObjectId_var id = root_poa->activate_object (simple_c_impl.in ()); CORBA::Object_var object = root_poa->id_to_reference (id.in ()); Baz::C_var simple_c = Baz::C::_narrow (object.in ()); CORBA::String_var ior = orb->object_to_string (simple_c.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", ior_output_file), 1); ACE_OS::fprintf (output_file, "%s", ior.in ()); ACE_OS::fclose (output_file); poa_manager->activate (); orb->run (); ACE_DEBUG ((LM_DEBUG, "(%P|%t) server - event loop finished\n")); root_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); CORBA::Object_var naming_obj = orb->resolve_initial_references ("NameService"); CosNaming::NamingContext_var naming_context = CosNaming::NamingContext::_narrow(naming_obj.in()); CosNaming::Name name; name.length (1); name[0].id = CORBA::string_dup("MyEventChannel"); CORBA::Object_var ecObj = naming_context->resolve(name); CosNotifyChannelAdmin::EventChannel_var ec = CosNotifyChannelAdmin::EventChannel::_narrow(ecObj.in()); CosNotifyChannelAdmin::AdminID adminid; CosNotifyChannelAdmin::InterFilterGroupOperator ifgop = CosNotifyChannelAdmin::AND_OP; CosNotifyChannelAdmin::ConsumerAdmin_var consumer_admin = ec->new_for_consumers(ifgop, adminid); CORBA::Object_var poa_object = orb->resolve_initial_references("RootPOA"); PortableServer::POA_var poa = PortableServer::POA::_narrow (poa_object.in()); PortableServer::Servant_var<StructuredEventConsumer_i> servant = new StructuredEventConsumer_i(orb.in()); PortableServer::ObjectId_var objectId = poa->activate_object (servant.in()); CORBA::Object_var consumer_obj = poa->id_to_reference (objectId.in ()); CosNotifyComm::StructuredPushConsumer_var consumer = CosNotifyComm::StructuredPushConsumer::_narrow (consumer_obj.in ()); CosNotifyChannelAdmin::ProxyID consumeradmin_proxy_id; CosNotifyChannelAdmin::ProxySupplier_var proxy_supplier = consumer_admin->obtain_notification_push_supplier( CosNotifyChannelAdmin::STRUCTURED_EVENT, consumeradmin_proxy_id); CosNotifyChannelAdmin::StructuredProxyPushSupplier_var supplier_proxy; supplier_proxy = CosNotifyChannelAdmin::StructuredProxyPushSupplier::_narrow(proxy_supplier.in()); CosNotification::QoSProperties properties (1); properties.length (1); properties[0].name = CORBA::string_dup (CosNotification::OrderPolicy); properties[0].value <<= CosNotification::FifoOrder; supplier_proxy->set_qos (properties); supplier_proxy->connect_structured_push_consumer(consumer.in()); CosNotification::EventTypeSeq added (1); CosNotification::EventTypeSeq removed (1); added.length (1); removed.length (1); added[0].domain_name = CORBA::string_dup ("OCI_TAO"); added[0].type_name = CORBA::string_dup ("examples"); removed[0].domain_name = CORBA::string_dup ("*"); removed[0].type_name = CORBA::string_dup ("*"); supplier_proxy->subscription_change(added, removed); PortableServer::POAManager_var poa_manager = poa->the_POAManager(); poa_manager->activate(); orb->run(); } catch(const CORBA::Exception& ex) { std::cerr << "Caught exception: " << ex << std::endl; return 1; } return 0; }
int ACE_TMAIN(int argc, ACE_TCHAR *argv[]) { PortableServer::POA_var oa_ptr; Alt_Mapping_i *svnt = 0; try { const char *orb_name = ""; CORBA::ORB_var orb_ptr = CORBA::ORB_init (argc, argv, orb_name); CORBA::Object_var temp; // holder for the myriad of times we get // an object which we then have to narrow. // Get the Root POA temp = orb_ptr->resolve_initial_references ("RootPOA"); if (CORBA::is_nil (temp.in())) ACE_ERROR_RETURN ((LM_ERROR, "(%P|%t) Unable to get root poa reference.\n"), 1); oa_ptr = PortableServer::POA::_narrow (temp.in()); PortableServer::POAManager_var poa_manager = oa_ptr->the_POAManager (); // Parse remaining command line and verify parameters. parse_args (argc, argv); // initialize a param_test target object and register it with the object // adapter // Create the implementation object ACE_NEW_RETURN (svnt, Alt_Mapping_i (orb_ptr.in ()), -1); // Register with GoodPOA with a specific name PortableServer::ObjectId_var id = PortableServer::string_to_ObjectId ("alt_mapping"); oa_ptr->activate_object_with_id (id.in (), svnt); // Stringify the objref we'll be implementing, and print it to // stdout. Someone will take that string and give it to a // client. Then release the object. temp = oa_ptr->id_to_reference (id.in ()); CORBA::String_var str = orb_ptr->object_to_string (temp.in ()); if (TAO_debug_level > 0) { ACE_DEBUG ((LM_DEBUG, "(%P|%t) The IOR is <%s>\n", str.in ())); } ior_output_file = ACE_OS::fopen (ior_output_filename, "w"); if (ior_output_file == 0) { ACE_ERROR_RETURN ((LM_ERROR, "Unable to open %s for writing: %p\n", ior_output_filename), -1); } ACE_OS::fprintf (ior_output_file, "%s", str.in ()); ACE_OS::fclose (ior_output_file); // Make the POAs controlled by this manager active poa_manager->activate (); orb_ptr->run (); oa_ptr->destroy (true, true); } catch (const CORBA::SystemException& sysex) { sysex._tao_print_exception ("System Exception"); return -1; } catch (const CORBA::UserException& userex) { userex._tao_print_exception ("User Exception"); return -1; } /// Free resources. delete svnt; 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"); 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 (); // Policies for the childPOA to be created. CORBA::PolicyList policies (1); policies.length (1); CORBA::Any pol; pol <<= BiDirPolicy::BOTH; policies[0] = orb->create_policy (BiDirPolicy::BIDIRECTIONAL_POLICY_TYPE, pol); // Create POA as child of RootPOA with the above policies. This POA // will receive request in the same connection in which it sent // the request PortableServer::POA_var child_poa = root_poa->create_POA ("childPOA", poa_manager.in (), policies); // Creation of childPOA is over. Destroy the Policy objects. for (CORBA::ULong i = 0; i < policies.length (); ++i) { policies[i]->destroy (); } poa_manager->activate (); if (parse_args (argc, argv) != 0) return 1; Simple_Server_i server_impl (orb.in (), no_iterations); PortableServer::ObjectId_var id = PortableServer::string_to_ObjectId ("simple_server"); child_poa->activate_object_with_id (id.in (), &server_impl); CORBA::Object_var obj = child_poa->id_to_reference (id.in ()); CORBA::String_var ior = orb->object_to_string (obj.in ()); ACE_DEBUG ((LM_DEBUG, "(%P|%t) Server activated as <%s>\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); } int retval = 0; while (retval == 0) { // Just process one upcall. We know that we would get the // clients IOR in that call. CORBA::Boolean pending = orb->work_pending(); if (pending) { orb->perform_work(); } // Now that hopefully we have the clients IOR, just start // making remote calls to the client. retval = server_impl.call_client (); } ACE_DEBUG ((LM_DEBUG, "event loop finished\n")); root_poa->destroy (1, 1); orb->destroy (); } catch (const CORBA::Exception& ex) { ex._tao_print_exception ("Caught exception:"); return 1; } return 0; }
int ACE_TMAIN(int argc, ACE_TCHAR *argv[]) { try { ACE_DEBUG ((LM_DEBUG, "(%P|%t) server - ORB_init\n")); CORBA::ORB_var orb = CORBA::ORB_init (argc, argv); ACE_DEBUG ((LM_DEBUG, "(%P|%t) server - Obtain RootPOA\n")); 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 (); ACE_DEBUG ((LM_DEBUG, "(%P|%t) server - parse args\n")); if (parse_args (argc, argv) != 0) return 1; ACE_DEBUG ((LM_DEBUG, "(%P|%t) server - init hello\n")); Hello *hello_impl = 0; ACE_NEW_RETURN (hello_impl, Hello (orb.in ()), 1); PortableServer::ServantBase_var owner_transfer(hello_impl); PortableServer::ObjectId_var id = root_poa->activate_object (hello_impl); CORBA::Object_var object = root_poa->id_to_reference (id.in ()); Test::Hello_var hello = Test::Hello::_narrow (object.in ()); CORBA::String_var ior = orb->object_to_string (hello.in ()); ACE_DEBUG ((LM_DEBUG, "(%P|%t) server - Create the forwarding loop\n")); CORBA::Object_var iorTableObj = orb->resolve_initial_references ("IORTable"); IORTable::Table_var iorTable = IORTable::Table::_narrow (iorTableObj.in ()); // We are using this test with ObjRefStyle == URL ... or at // least we better be. The IOR is therefore a corbaloc ACE_CString full_corbaloc (ior.in (), 0, 1); // Create a corbaloc for an IOR table binding that points to // itself. Acessing this will make the server reply with LOCATION_FORWARD // indefinitely. ACE_DEBUG ((LM_DEBUG, "(%P|%t) server - Corbaloc is\n \"%C\"\n", full_corbaloc.c_str())); // Get the endpoint info only... CORBA::ULong first_slash = full_corbaloc.find ("/", 0); ACE_CString forward_forever = full_corbaloc.substring (0, first_slash); // .. add the string we are going to bind against and then bind forward_forever += "/hello"; iorTable->bind("hello", forward_forever.c_str ()); ACE_DEBUG ((LM_DEBUG, "(%P|%t) server - Forward forever is\n \"%C\"\n", forward_forever.c_str())); // Output the IORs 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", ior.in ()); ACE_OS::fclose (output_file); output_file = ACE_OS::fopen (ior_output_file2, "w"); if (output_file == 0) ACE_ERROR_RETURN ((LM_ERROR, "Cannot open output file for writing IOR: %s\n", ior_output_file2), 1); ACE_OS::fprintf (output_file, "%s", forward_forever.c_str ()); ACE_OS::fclose (output_file); poa_manager->activate (); ACE_DEBUG ((LM_DEBUG, "(%P|%t) server - orb->run()\n")); orb->run (); ACE_DEBUG ((LM_DEBUG, "(%P|%t) server - event loop finished\n")); root_poa->destroy (1, 1); orb->destroy (); } catch (const CORBA::Exception& ex) { ex._tao_print_exception ("Exception caught:"); return 1; } return 0; }
int Server_Task::svc (void) { try { CORBA::Object_var poa_object = this->sorb_->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 (); Hello *hello_impl; ACE_NEW_RETURN (hello_impl, Hello (this->sorb_.in (), ACE_Thread::self ()), 1); PortableServer::ServantBase_var owner_transfer(hello_impl); PortableServer::ObjectId_var id = root_poa->activate_object (hello_impl); CORBA::Object_var object = root_poa->id_to_reference (id.in ()); Test::Hello_var hello = Test::Hello::_narrow (object.in ()); CORBA::String_var ior = this->sorb_->object_to_string (hello.in ()); // Output the IOR to the <this->output_> FILE *output_file= ACE_OS::fopen (this->output_, "w"); if (output_file == 0) ACE_ERROR_RETURN ((LM_ERROR, "Cannot open output file for writing IOR: %s", this->output_), 1); ACE_OS::fprintf (output_file, "%s", ior.in ()); ACE_OS::fclose (output_file); poa_manager->activate (); // Signal the main thread before we call orb->run (); this->me_.signal (); this->sorb_->run (); ACE_DEBUG ((LM_DEBUG, "(%P|%t) server - event loop finished\n")); root_poa->destroy (1, 1); this->sorb_->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); 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 (); CORBA::Object_var object = orb->resolve_initial_references ("PolicyCurrent"); CORBA::PolicyCurrent_var policy_current = CORBA::PolicyCurrent::_narrow (object.in ()); if (CORBA::is_nil (policy_current.in ())) { ACE_ERROR ((LM_ERROR, "ERROR: Nil policy current\n")); return 1; } CORBA::Any scope_as_any; scope_as_any <<= Messaging::SYNC_NONE; CORBA::PolicyList policies(1); policies.length (1); policies[0] = orb->create_policy (Messaging::SYNC_SCOPE_POLICY_TYPE, scope_as_any); policy_current->set_policy_overrides (policies, CORBA::ADD_OVERRIDE); policies[0]->destroy (); if (parse_args (argc, argv) != 0) return 1; PortableServer::Servant_var<Echo_Caller> impl; { Echo_Caller * tmp; // ACE_NEW_RETURN is the worst possible way to handle // exceptions (think: what if the constructor allocates memory // and fails?), but I'm not in the mood to fight for a more // reasonable way to handle allocation errors in ACE. ACE_NEW_RETURN (tmp, Echo_Caller(orb.in()), 1); impl = tmp; } PortableServer::ObjectId_var id = root_poa->activate_object (impl.in ()); CORBA::Object_var object_act = root_poa->id_to_reference (id.in ()); Test::Echo_Caller_var server = Test::Echo_Caller::_narrow (object_act.in ()); CORBA::String_var ior = orb->object_to_string (server.in ()); // If the ior_output_file exists, output the ior to it 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(); ACE_DEBUG ((LM_DEBUG, "(%P|%t) server - event loop finished\n")); root_poa->destroy (1, 1); orb->destroy (); } catch (const CORBA::Exception& ex) { ex._tao_print_exception ("Exception caught in server:"); return 1; } return 0; }
int LocalityManager_Task::svc (void) { DANCE_TRACE ("LocalityManager_Task::svc"); DANCE_DEBUG (DANCE_LOG_TRACE, (LM_TRACE, DLINFO ACE_TEXT ("LocalityManager_Task::svc - ") ACE_TEXT ("Activating the root POA\n"))); CORBA::Object_var object = this->orb_->resolve_initial_references ("RootPOA"); PortableServer::POA_var root_poa = PortableServer::POA::_narrow (object.in ()); { PortableServer::POAManager_var poa_manager = root_poa->the_POAManager (); poa_manager->activate (); DANCE_DEBUG (DANCE_LOG_TRACE, (LM_TRACE, DLINFO ACE_TEXT ("LocalityManager_Task::svc - ") ACE_TEXT ("Creating server implementation object\n"))); DAnCE::LocalityManager_i *lm_srv = 0; ACE_NEW_NORETURN (lm_srv, LocalityManager_i (this->uuid_, this->plugin_config_, this->orb_.in (), root_poa.in ())); if (lm_srv == 0) { DANCE_ERROR (DANCE_LOG_TERMINAL_ERROR, (LM_CRITICAL, ACE_TEXT ("LocalityManager_Task::run - ") ACE_TEXT ("Out of memory error while allocating servant."))); throw Error ("Out of memory whilst allocating servant."); } PortableServer::ServantBase_var safe_config = lm_srv; PortableServer::ObjectId_var id = root_poa->activate_object (lm_srv); CORBA::Object_var lm_object = root_poa->id_to_reference (id.in ()); DAnCE::LocalityManager_var lm = DAnCE::LocalityManager::_narrow (lm_object.in ()); if (this->output_file_ != ACE_TEXT("")) { CORBA::String_var ior = this->orb_->object_to_string (lm.in ()); ::DAnCE::Utility::write_IOR (this->output_file_.c_str (), ior.in ()); } if (this->callback_ior_str_ != ACE_TEXT("")) { DANCE_DEBUG (DANCE_LOG_TRACE, (LM_TRACE, DLINFO ACE_TEXT ("LocalityManager_Task::run - ") ACE_TEXT ("Resolving callback IOR\n"))); CORBA::Object_var obj = this->orb_->string_to_object (this->callback_ior_str_.c_str ()); LocalityManagerActivator_var sa (LocalityManagerActivator::_narrow (obj)); if (CORBA::is_nil (sa.in ())) { DANCE_DEBUG (DANCE_LOG_ERROR, (LM_ERROR, DLINFO ACE_TEXT ("LocalityManager_Task::svc - ") ACE_TEXT ("Failed to narrow callback IOR [%s]\n"), this->callback_ior_str_.c_str ())); throw Error ("Failed to narrow callback IOR"); } { Deployment::Properties *cf = 0; ACE_NEW_NORETURN (cf, Deployment::Properties (0)); if (cf == 0) { DANCE_ERROR (DANCE_LOG_ERROR, (LM_CRITICAL, ACE_TEXT ("LocalityManager_Task::run - ") ACE_TEXT ("Out of memory error while allocating config ") ACE_TEXT ("values."))); } else { this->config_ = cf; } } // Make callback. DANCE_DEBUG (DANCE_LOG_EVENT_TRACE, (LM_TRACE, DLINFO ACE_TEXT ("LocalityManager_Task::svc - ") ACE_TEXT ("Making callback on my Activator\n"))); try { // Callback to NodeApplication to get configuration sa->locality_manager_callback (lm.in (), ACE_TEXT_ALWAYS_CHAR (this->uuid_.c_str ()), this->config_.out ()); DANCE_DEBUG (DANCE_LOG_EVENT_TRACE, (LM_TRACE, DLINFO ACE_TEXT ("LocalityManager_Task::svc - ") ACE_TEXT ("Configuration received, got %u values\n"), this->config_->length ())); lm_srv->init (this->config_.in ()); DANCE_DEBUG (DANCE_LOG_MINOR_EVENT, (LM_NOTICE, DLINFO ACE_TEXT ("LocalityManager_Task::svc - ") ACE_TEXT ("Configuration complete for component server %C\n"), this->uuid_.c_str ())); sa->configuration_complete (ACE_TEXT_ALWAYS_CHAR (this->uuid_.c_str ())); } catch (const CORBA::BAD_PARAM &) { DANCE_ERROR (DANCE_LOG_ERROR, (LM_ERROR, DLINFO ACE_TEXT ("LocalityManager_Task::svc - ") ACE_TEXT ("The Callback IOR provided pointed to the ") ACE_TEXT ("wrong Activator\n"))); throw Error ("Bad callback IOR"); } catch (const CORBA::Exception &ex) { DANCE_ERROR (DANCE_LOG_ERROR, (LM_ERROR, DLINFO ACE_TEXT ("LocalityManager_Task::svc - ") ACE_TEXT ("Caught CORBA Exception while ") ACE_TEXT ("calling back: %C\n"), ex._info ().c_str ())); throw Error (ex._info ().c_str ()); } catch (...) { DANCE_ERROR (DANCE_LOG_ERROR, (LM_ERROR, DLINFO ACE_TEXT ("LocalityManager_Task::svc - ") ACE_TEXT ("Caught exception while calling back\n"))); throw Error ("Caught exception while calling back"); } } else { DANCE_DEBUG (DANCE_LOG_WARNING, (LM_WARNING, DLINFO ACE_TEXT ("LocalityManager_Task::svc - ") ACE_TEXT ("Initializing ComponentServer without ServantActivator ") ACE_TEXT ("callback\n"))); lm_srv->init (0); } this->orb_->run (); DANCE_DEBUG (DANCE_LOG_EVENT_TRACE, (LM_TRACE, DLINFO ACE_TEXT ("LocalityManager_Task::svc - ") ACE_TEXT ("ORB Event loop completed.\n"))); } root_poa->destroy (1, 1); root_poa = ::PortableServer::POA::_nil (); this->orb_->destroy (); this->orb_ = ::CORBA::ORB::_nil (); return 0; }
int Server_Task::svc (void) { try { CORBA::Object_var poa_object = sorb_->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 (); poa_manager->activate (); Visual_i * server_impl = 0; ACE_NEW_RETURN (server_impl, Visual_i (sorb_.in ()), 1); PortableServer::ObjectId_var id = root_poa->activate_object (server_impl); CORBA::Object_var test_obj = root_poa->id_to_reference (id.in ()); Test_Interceptors::Visual_var server = Test_Interceptors::Visual::_narrow (test_obj.in ()); CORBA::String_var ior = this->sorb_->object_to_string (server.in ()); ACE_DEBUG ((LM_DEBUG, "Test_Interceptors::Visual: <%C>\n", ior.in ())); // If the ior_output_file exists, output the ior to it if (output_ != 0) { FILE *output_file= ACE_OS::fopen (this->output_, "w"); if (output_file == 0) ACE_ERROR_RETURN ((LM_ERROR, "Cannot open output file for writing IOR: %s", this->output_), 1); ACE_OS::fprintf (output_file, "%s", ior.in ()); ACE_OS::fclose (output_file); } // Signal the main thread before we call orb->run (); this->me_.signal (); this->sorb_->run (); ACE_DEBUG ((LM_DEBUG, "event loop finished\n")); root_poa->destroy (1, 1); } catch (const CORBA::Exception& ex) { ex._tao_print_exception ("Exception caught in server task:"); return 1; } return 0; }
void AsyncListManager::final_state (void) { if (ImR_Locator_i::debug() > 4) { ORBSVCS_DEBUG ((LM_DEBUG, ACE_TEXT ("(%P|%t) AsyncListManager::final_state, ") ACE_TEXT ("waiters count = %d, pinger not null? %d\n"), this->waiters_, (this->pinger_ != 0))); } if (this->pinger_ != 0 && this->waiters_ > 0) { return; } bool excepted = false; CORBA::ULong len = this->server_list_.length (); if (!CORBA::is_nil (this->primary_.in())) { ImplementationRepository::ServerInformationIterator_var server_iterator; if (len < this->repo_->servers ().current_size()) { try { ImR_AsyncIterator* imr_iter = 0; ACE_NEW_THROW_EX (imr_iter, ImR_AsyncIterator (len, this), CORBA::NO_MEMORY ()); PortableServer::ServantBase_var tmp (imr_iter); PortableServer::ObjectId_var id = this->poa_->activate_object (imr_iter); CORBA::Object_var obj = this->poa_->id_to_reference (id.in ()); server_iterator = ImplementationRepository:: ServerInformationIterator::_unchecked_narrow (obj.in ()); } catch (CORBA::Exception& ex) { ImplementationRepository::AMH_AdministrationExceptionHolder h (ex._tao_duplicate()); this->primary_->list_excep (&h); excepted = true; } } else { server_iterator = ImplementationRepository::ServerInformationIterator::_nil (); } if (!excepted) { try { this->primary_->list (this->server_list_, server_iterator.in ()); } catch (CORBA::Exception &ex) { ex._tao_print_exception ("ALM:final state sending list\n"); ImplementationRepository::AMH_AdministrationExceptionHolder h (ex._tao_duplicate()); this->primary_->list_excep (&h); } } this->primary_ = ImplementationRepository::AMH_AdministrationResponseHandler::_nil (); } else if (!CORBA::is_nil (this->secondary_.in())) { CORBA::Boolean done = this->first_ + this->server_list_.length () >= this->repo_->servers ().current_size (); this->secondary_->next_n (done, this->server_list_); this->secondary_ = ImplementationRepository::AMH_ServerInformationIteratorResponseHandler::_nil (); } }
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 object = orb->string_to_object (ior); UDP_var udp_var = UDP::_narrow (object.in ()); if (CORBA::is_nil (udp_var.in ())) ACE_ERROR_RETURN ((LM_ERROR, "Object reference <%s> is nil.\n", ior), 1); // Activate POA to handle the call back. 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 (); poa_manager->activate (); // Instantiate reply handler UDP_i udp_i (orb.in ()); PortableServer::ObjectId_var id = root_poa->activate_object (&udp_i); CORBA::Object_var object_act = root_poa->id_to_reference (id.in ()); UDP_var udpHandler_var = UDP::_narrow (object_act.in ()); // Instantiate client UDP_Client_i *client = new UDP_Client_i (orb.in (), udp_var.in (), udpHandler_var.in (), msec, iterations); // let the client run in a separate thread client->activate (); // ORB loop, will be shut down by our client thread orb->run (); ACE_DEBUG ((LM_DEBUG, "event loop finished\n")); root_poa->destroy (1, // ethernalize objects 0); // wait for completion orb->destroy (); client->wait (); // it is save to delete the client, because the client was actually // the one calling orb->shutdown () triggering the end of the ORB // event loop. delete client; } catch (const CORBA::Exception& ex) { ex._tao_print_exception ("Caught exception:"); return 1; } return 0; }
int ACE_TMAIN(int argc, ACE_TCHAR *argv[]) { try { CORBA::ORB_var orb = CORBA::ORB_init (argc, argv); CORBA::Object_var obj = orb->resolve_initial_references ("RootPOA"); PortableServer::POA_var root_poa = PortableServer::POA::_narrow (obj.in ()); PortableServer::POAManager_var poa_manager = root_poa->the_POAManager (); poa_manager->activate (); CORBA::PolicyList policies; CORBA::ULong current_length = 0; policies.length (current_length + 1); policies[current_length++] = root_poa->create_request_processing_policy (PortableServer::USE_SERVANT_MANAGER); policies.length (current_length + 1); policies[current_length++] = root_poa->create_servant_retention_policy (PortableServer::NON_RETAIN); policies.length (current_length + 1); policies[current_length++] = root_poa->create_id_assignment_policy (PortableServer::USER_ID); PortableServer::POA_var child_poa = root_poa->create_POA ("child", poa_manager.in (), policies); Servant_Locator servant_locator (child_poa.in ()); child_poa->set_servant_manager (&servant_locator); PortableServer::ObjectId_var objectID = PortableServer::string_to_ObjectId ("object"); CORBA::Object_var objectREF = child_poa->create_reference_with_id (objectID.in (), "IDL:test:1.0"); test_var testObject = test::_narrow (objectREF.in ()); testObject->normal(); bool caught = false; try { testObject->exceptional(); } catch (const CORBA::Exception&) { ACE_DEBUG ((LM_DEBUG, "exceptional() yielded exception\n")); caught = true; } if (!caught) ++errorCount; caught = false; try { testObject->notexisting(); } catch (const CORBA::Exception&) { ACE_DEBUG ((LM_DEBUG, "notexisting() yielded exception\n")); caught = true; } if (!caught) ++errorCount; orb->destroy (); } catch (const CORBA::Exception& ex) { ex._tao_print_exception ("Exception caught"); ++errorCount; } if (!errorCount) { ACE_DEBUG ((LM_DEBUG,"test successful\n")); } else { ACE_DEBUG ((LM_DEBUG,"unsuccessfull: %d errors\n", errorCount )); } return errorCount; }
Messenger_i::Messenger_i (CORBA::ORB_ptr orb) : orb_ (CORBA::ORB::_duplicate (orb)) { CORBA::Object_var naming_obj = orb_->resolve_initial_references ("NameService"); CosNaming::NamingContext_var naming_context = CosNaming::NamingContext::_narrow (naming_obj.in()); CosNaming::Name name; name.length (1); name[0].id = CORBA::string_dup ("NotifyEventChannelFactory"); CORBA::Object_var obj = naming_context->resolve (name); CosNotifyChannelAdmin::EventChannelFactory_var notify_factory = CosNotifyChannelAdmin::EventChannelFactory::_narrow (obj.in ()); CosNotifyChannelAdmin::ChannelID id; CosNotification::QoSProperties initial_qos; CosNotification::AdminProperties initial_admin; CosNotifyChannelAdmin::EventChannel_var ec = notify_factory->create_channel (initial_qos, initial_admin, id); name[0].id = CORBA::string_dup ("MyEventChannel"); naming_context->rebind (name, ec.in()); CosNotifyChannelAdmin::AdminID adminid; CosNotifyChannelAdmin::InterFilterGroupOperator ifgop = CosNotifyChannelAdmin::AND_OP; CosNotifyChannelAdmin::SupplierAdmin_var supplier_admin = ec->new_for_suppliers (ifgop, adminid); CosNotifyChannelAdmin::ProxyID supplieradmin_proxy_id; CosNotifyChannelAdmin::ProxyConsumer_var proxy_consumer = supplier_admin->obtain_notification_push_consumer( CosNotifyChannelAdmin::STRUCTURED_EVENT, supplieradmin_proxy_id); StructuredEventSupplier_i *servant = new StructuredEventSupplier_i(orb_.in()); CORBA::Object_var poa_obj = orb_->resolve_initial_references ("RootPOA"); PortableServer::POA_var poa = PortableServer::POA::_narrow (poa_obj.in ()); PortableServer::POAManager_var mgr = poa->the_POAManager (); mgr->activate (); PortableServer::ObjectId_var objectId = poa->activate_object (servant); CORBA::Object_var supplier_obj = poa->id_to_reference (objectId.in ()); CosNotifyComm::StructuredPushSupplier_var supplier = CosNotifyComm::StructuredPushSupplier::_narrow (supplier_obj.in ()); consumer_proxy_ = CosNotifyChannelAdmin::StructuredProxyPushConsumer::_narrow (proxy_consumer.in()); consumer_proxy_-> connect_structured_push_supplier (supplier.in()); }
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 (); if (parse_args (argc, argv) != 0) return 1; // Create client callback CORBA object TestCallback *test_impl = 0; ACE_NEW_RETURN (test_impl, TestCallback (orb.in()), 1); PortableServer::ServantBase_var owner_transfer(test_impl); PortableServer::ObjectId_var id = root_poa->activate_object (test_impl); CORBA::Object_var object = root_poa->id_to_reference (id.in ()); Test::TestCallback_var client = Test::TestCallback::_narrow (object.in ()); poa_manager->activate (); // Get server CORBA object and call it CORBA::Object_var tmp = orb->string_to_object(ior); Test::TestServer_var server = Test::TestServer::_narrow(tmp.in ()); if (CORBA::is_nil (server.in ())) { ACE_ERROR_RETURN ((LM_DEBUG, "Nil Test::TestServer reference <%s>\n", ior), 1); } ACE_DEBUG ((LM_DEBUG, "(%P|%t) client - calling server\n")); server->pass_callback (client.in()); ACE_DEBUG ((LM_DEBUG, "(%P|%t) client - call failed to block\n")); } catch (const CORBA::Exception& ex) { ex._tao_print_exception ("Exception caught:"); return 1; } ACE_DEBUG ((LM_DEBUG, "(%P|%t) client - not stopped by server\n")); return 1; }
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 (); Foo_Bar *foobar_impl; ACE_NEW_RETURN (foobar_impl, Foo_Bar (orb.in ()), 1); PortableServer::ObjectId_var id = root_poa->activate_object (foobar_impl); CORBA::Object_var object = root_poa->id_to_reference (id.in ()); Test::Foo_var foo = Test::Foo::_narrow (object.in ()); poa_manager->activate (); // Dont unscope it or move it elsewhere.. It is here with a // purpose. If you dont understand this, please re-read the // README file. { PortableServer::ServantBase_var owner_transfer (foobar_impl); } ACE_Time_Value tv (10, 0); // Just run the ORB for a minute.. orb->run (tv); ACE_DEBUG ((LM_DEBUG, "(%P|%t) server - shutting down the ORB\n")); orb->shutdown (1); ACE_DEBUG ((LM_DEBUG, "(%P|%t) Finished shutting down the ORB\n")); root_poa->destroy (1, 1); orb->destroy (); } catch (const CORBA::Exception& ex) { ex._tao_print_exception ("Exception caught:"); return 1; } ACE_DEBUG ((LM_DEBUG, "(%P|%t) Test successful..\n")); return 0; }
int ACE_TMAIN (int argc, ACE_TCHAR *argv[]) { try { // initialize the ORB _orb = CORBA::ORB_init (argc, argv); // Get the "RootPOA" CORBA::Object_var obj = _orb->resolve_initial_references("RootPOA"); PortableServer::POA_var poa = PortableServer::POA::_narrow(obj.in ()); // activate its managers so it can handle incoming requests poa->the_POAManager()->activate(); // get a thread going to handle incoming requests ACE_Thread::spawn(RunFunc); // we could also use the c_orbaloc syntax to get a reference to the // object. This will cause the _orb to talk directly to the other // _orb with no name service or common file involved. obj = _orb->string_to_object("c_orbaloc::localhost:9999/Simple"); if (CORBA::is_nil(obj.in ())) { ACE_ERROR ((LM_ERROR, "could not get reference\n")); return 1; } // narrow the reference to the particular type we wish to deal with Simple_var simple = Simple::_narrow(obj.in ()); if (CORBA::is_nil(simple.in ())) { ACE_ERROR ((LM_ERROR, "could not get reference\n")); return 1; } // create an object reference that has a bogus value for the first // profile obj = _orb->resolve_initial_references("IORManipulation"); TAO_IOP::TAO_IOR_Manipulation_var iorm = TAO_IOP::TAO_IOR_Manipulation::_narrow(obj.in()); // Status: The following scenarios appear to work: // - first profile invalid host name, second profile valid. // - first profile invalid ip number, second profiel valid. // - first profiel invalid port number, second profile valid. // // The following causes a core dump of the server: // - first and second invalid // // Note that he iormanip is being used since it is not practical // to have a test case that depends on a VPN being present. // CORBA::Object_var name1 = _orb->string_to_object ("c_orbaloc:iiop:10.0.2.3:6060/xyz"); CORBA::Object_var name2 = _orb->string_to_object ("c_orbaloc:iiop:daisnot:7070/xyz"); CORBA::String_var name1_ior = _orb->object_to_string(name1.in()); CORBA::String_var name2_ior = _orb->object_to_string(name2.in()); // create a callback object Callee_i * callee_i = new Callee_i; // get the CORBA reference PortableServer::ObjectId_var id = poa->activate_object (callee_i); CORBA::Object_var object_act = poa->id_to_reference (id.in ()); Callee_var callee = Callee::_narrow (object_act.in ()); if (CORBA::is_nil(callee.in ())) { ACE_ERROR ((LM_ERROR, "could not get callback object\n")); return 1; } else { CORBA::String_var str = _orb->object_to_string(callee.in ()); FILE *output_file= ACE_OS::fopen ("ior", "w"); if (output_file == 0) ACE_ERROR_RETURN ((LM_ERROR, "Cannot open output file for writing IOR: ior\n"), 1); ACE_OS::fprintf (output_file, "%s", str.in ()); ACE_OS::fclose (output_file); } // create a reference with two profiles with the first on being // bogus. If things work as they should the callback should be // succesful with the ORB trying the second profile. TAO_IOP::TAO_IOR_Manipulation::IORList iors (2); iors.length (2); iors [0] = name1; iors [1] = name2; CORBA::Object_var merged = iorm->merge_iors(iors); Callee_var doubleCallee = Callee::_unchecked_narrow(merged.in()); ACE_DEBUG ((LM_DEBUG, "Profile count is %d\n", iorm->get_profile_count(merged.in()))); simple->registerCallee(doubleCallee.in ()); ACE_OS::sleep(120); ACE_DEBUG ((LM_DEBUG, "done sleeping\n")); _orb->shutdown(1); } catch (const ::CORBA::Exception &ex) { ex._tao_print_exception("Caught unexpected CORBA exception :"); } 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 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 (); Hello *hello_impl; ACE_NEW_RETURN (hello_impl, Hello (orb.in ()), 1); PortableServer::ServantBase_var owner_transfer(hello_impl); PortableServer::ObjectId_var id = root_poa->activate_object (hello_impl); CORBA::Object_var object = root_poa->id_to_reference (id.in ()); Test::Hello_var hello = Test::Hello::_narrow (object.in ()); CORBA::String_var ior = orb->object_to_string (hello.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", ior_output_file), 1); ACE_OS::fprintf (output_file, "%s", ior.in ()); ACE_OS::fclose (output_file); poa_manager->activate (); CORBA::Object_var tmp = orb->string_to_object(server_ior); Test::Hello_var server = Test::Hello::_narrow(tmp.in ()); if (CORBA::is_nil (server.in ())) { ACE_ERROR_RETURN ((LM_DEBUG, "Nil Test::Hello reference <%s>\n", ior.in ()), 1); } ACE_DEBUG ((LM_DEBUG, "(%P|%t) - Sending client obj ref to the server and requesting a callback.\n")); server->request_callback (hello.in ()); ACE_DEBUG ((LM_DEBUG, "(%P|%t) - Test (client) Succeeded !!!\n")); orb->destroy (); } catch (const CORBA::Exception& ex) { ACE_DEBUG ((LM_ERROR, "(%P|%t) - Test (client) Failed !!!\n")); 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); 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 (); if (parse_args (argc, argv) != 0) return 1; Simple_Server_i *server_impl = 0; ACE_NEW_RETURN (server_impl, Simple_Server_i (orb.in ()), -1); PortableServer::ServantBase_var owner_transfer(server_impl); PortableServer::ObjectId_var id = root_poa->activate_object (server_impl); CORBA::Object_var object = root_poa->id_to_reference (id.in ()); Simple_Server_var server = Simple_Server::_narrow (object.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, "(%P|%t) 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 (); Worker worker (orb.in ()); if (worker.activate (THR_NEW_LWP | THR_JOINABLE, nthreads) != 0) ACE_ERROR_RETURN ((LM_ERROR, "(%P|%t) Cannot activate client threads\n"), 1); SelfClient selfabuse (orb.in(), server.in(), niterations); if (selfabuse.activate (THR_NEW_LWP | THR_JOINABLE, nclient_threads) != 0) ACE_ERROR_RETURN ((LM_ERROR, "(%P|%t) Cannot activate abusive threads\n"), 1); selfabuse.thr_mgr()->wait(); worker.thr_mgr ()->wait (); ACE_DEBUG ((LM_DEBUG, "(%P|%t) event loop finished\n")); } 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); 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 (); if (parse_args (argc, argv) != 0) return 1; Blocking_Sync_None *blocking_sync_none_impl; ACE_NEW_RETURN (blocking_sync_none_impl, Blocking_Sync_None (orb.in ()), 1); PortableServer::ServantBase_var owner_transfer(blocking_sync_none_impl); PortableServer::ObjectId_var id = root_poa->activate_object (blocking_sync_none_impl); CORBA::Object_var object = root_poa->id_to_reference (id.in ()); Test::Blocking_Sync_None_var blocking_sync_none = Test::Blocking_Sync_None::_narrow (object.in ()); CORBA::String_var ior = orb->object_to_string (blocking_sync_none.in ()); // If the ior_output_file exists, output the ior to it 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 (); ACE_DEBUG ((LM_DEBUG, "(%P|%t) server - event loop finished\n")); root_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); 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 (); // Make all oneways "reliable." { CORBA::Object_var manager_object = orb->resolve_initial_references("ORBPolicyManager"); CORBA::PolicyManager_var policy_manager = CORBA::PolicyManager::_narrow(manager_object.in()); if (CORBA::is_nil (policy_manager.in ())) ACE_ERROR_RETURN ((LM_ERROR, " (%P|%t) Panic: nil PolicyManager\n"), 1); CORBA::Any policy_value; policy_value <<= Messaging::SYNC_WITH_SERVER; CORBA::PolicyList policies(1); policies.length(1); policies[0] = orb->create_policy (Messaging::SYNC_SCOPE_POLICY_TYPE, policy_value); policy_manager->set_policy_overrides (policies, CORBA::ADD_OVERRIDE); policies[0]->destroy (); } if (parse_args (argc, argv) != 0) return 1; Service *service_impl; ACE_NEW_RETURN (service_impl, Service(orb.in ()), 1); PortableServer::ServantBase_var owner_transfer(service_impl); PortableServer::ObjectId_var id = root_poa->activate_object (service_impl); CORBA::Object_var object = root_poa->id_to_reference (id.in ()); Test::Service_var service = Test::Service::_narrow (object.in ()); CORBA::String_var ior = orb->object_to_string (service.in ()); // If the ior_output_file exists, output the ior to it 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 (); ACE_DEBUG ((LM_DEBUG, "Event loop finished\n")); service_impl->dump_results (); root_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); 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 (poa_object.in ())) ACE_ERROR_RETURN ((LM_ERROR, " (%P|%t) Panic got a nil RootPOA\n"), 1); PortableServer::POAManager_var poa_manager = root_poa->the_POAManager (); if (parse_args (argc, argv) != 0) return 1; Coordinator *coordinator_impl = 0; ACE_NEW_RETURN (coordinator_impl, Coordinator (peer_count), 1); PortableServer::ServantBase_var coordinator_owner (coordinator_impl); PortableServer::ObjectId_var id = root_poa->activate_object (coordinator_impl); CORBA::Object_var object = root_poa->id_to_reference (id.in ()); Test::Coordinator_var coordinator = Test::Coordinator::_narrow (object.in ()); poa_manager->activate (); CORBA::String_var ior = orb->object_to_string (coordinator.in ()); // If the ior_output_file exists, output the ior to it 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); ACE_DEBUG ((LM_DEBUG, "Waiting for peers . . . ")); for (int i = 0; i != 60 && !coordinator_impl->has_all_peers (); ++i) { ACE_Time_Value tv (1, 0); orb->run (tv); } ACE_DEBUG ((LM_DEBUG, "done.\n")); if (!coordinator_impl->has_all_peers ()) { ACE_ERROR ((LM_DEBUG, "ERROR: timeout, some peers failed to register\n")); return 1; } ACE_DEBUG ((LM_DEBUG, "Building session list . . . ")); Session_Control *session_control_impl = 0; ACE_NEW_RETURN (session_control_impl, Session_Control (peer_count), 1); PortableServer::ServantBase_var session_control_owner (session_control_impl); PortableServer::ObjectId_var idu = root_poa->activate_object (session_control_impl); CORBA::Object_var objectu = root_poa->id_to_reference (idu.in ()); Test::Session_Control_var session_control = Test::Session_Control::_narrow (objectu.in ()); Test::Session_List session_list; coordinator_impl->create_session_list (session_control.in (), payload_size, thread_count, message_count, session_list); ACE_ASSERT (session_list.length () == peer_count); ACE_DEBUG ((LM_DEBUG, "done.\n")); ACE_DEBUG ((LM_DEBUG, "Giving start signal . . . ")); CORBA::ULong j; for (j = 0; j != peer_count; ++j) { // Make a copy of the sessions, excluding the j-th element Test::Session_List other_sessions (peer_count - 1); other_sessions.length (peer_count - 1); CORBA::ULong count = 0; for (CORBA::ULong k = 0; k != peer_count; ++k) { if (k == j) continue; other_sessions[count++] = Test::Session::_duplicate (session_list[k]); } session_list[j]->start (other_sessions); } ACE_DEBUG ((LM_DEBUG ,"done\n")); ACE_DEBUG ((LM_DEBUG, "Waiting for sessions to finish. . .\n")); for (int k = 0; k != 300 && !session_control_impl->all_sessions_finished (); ++k) { ACE_Time_Value tv (1, 0); orb->run (tv); } if (!session_control_impl->all_sessions_finished ()) { ACE_ERROR ((LM_ERROR, "ERROR: timeout waiting for sessions\n")); return 1; } ACE_DEBUG ((LM_DEBUG, "All sessions finished, destroy session list . . .\n")); for (j = 0; j != peer_count; ++j) { session_list[j]->destroy (); } ACE_DEBUG ((LM_DEBUG, "Shutdown all peers . . .\n")); coordinator_impl->shutdown_all_peers (); ACE_OS::sleep (5); // Allow the shutdown message to be processed. ACE_DEBUG ((LM_DEBUG, "Shutdown poa and orb . . .\n")); root_poa->destroy (1, 1); orb->destroy (); } catch (const CORBA::Exception& ex) { ex._tao_print_exception ("Exception caught:"); return 1; } return 0; }
void TAO_Storable_Naming_Context_ReaderWriter::write (TAO_Storable_Naming_Context & context) { TAO_NS_Persistence_Header header; header.size (static_cast<unsigned int> (context.storable_context_->current_size())); header.destroyed (context.destroyed_); this->write_header(header); if (0u == header.size ()) return; ACE_Hash_Map_Iterator<TAO_Storable_ExtId,TAO_Storable_IntId, ACE_Null_Mutex> it = context.storable_context_->map().begin(); ACE_Hash_Map_Iterator<TAO_Storable_ExtId,TAO_Storable_IntId, ACE_Null_Mutex> itend = context.storable_context_->map().end(); ACE_Hash_Map_Entry<TAO_Storable_ExtId,TAO_Storable_IntId> ent = *it; while (!(it == itend)) { TAO_NS_Persistence_Record record; ACE_CString name; CosNaming::BindingType bt = (*it).int_id_.type_; if (bt == CosNaming::ncontext) { CORBA::Object_var obj = context.orb_->string_to_object ((*it).int_id_.ref_.in ()); if (obj->_is_collocated ()) { // This is a local (i.e. non federated context) we therefore // store only the ObjectID (persistence filename) for the object. // The driving force behind storing ObjectIDs rather than IORs for // local contexts is to provide for a redundant naming service. // That is, a naming service that runs simultaneously on multiple // machines sharing a file system. It allows multiple redundant // copies to be started and stopped independently. // The original target platform was Tru64 Clusters where there was // a cluster address. In that scenario, clients may get different // servers on each request, hence the requirement to keep // synchronized to the disk. It also works on non-cluster system // where the client picks one of the redundant servers and uses it, // while other systems can pick different servers. (However in this // scenario, if a server fails and a client must pick a new server, // that client may not use any saved context IORs, instead starting // from the root to resolve names. So this latter mode is not quite // transparent to clients.) [Rich Seibel (seibel_r) of ociweb.com] PortableServer::ObjectId_var oid = context.poa_->reference_to_id (obj.in ()); CORBA::String_var nm = PortableServer::ObjectId_to_string (oid.in ()); const char *newname = nm.in (); name.set (newname); // The local ObjectID (persistance filename) record.type (TAO_NS_Persistence_Record::LOCAL_NCONTEXT); } else { // Since this is a foreign (federated) context, we can not store // the objectID (because it isn't in our storage), if we did, when // we restore, we would end up either not finding a permanent // record (and thus ending up incorrectly assuming the context was // destroyed) or loading another context altogether (just because // the contexts shares its objectID filename which is very likely). // [Simon Massey (sma) of prismtech.com] name.set ((*it).int_id_.ref_.in ()); // The federated context IOR record.type (TAO_NS_Persistence_Record::REMOTE_NCONTEXT); } } else // if (bt == CosNaming::nobject) // shouldn't be any other, can there? { name.set ((*it).int_id_.ref_.in ()); // The non-context object IOR record.type (TAO_NS_Persistence_Record::OBJREF); } record.ref(name); const char *myid = (*it).ext_id_.id(); ACE_CString id(myid); record.id(id); const char *mykind = (*it).ext_id_.kind(); ACE_CString kind(mykind); record.kind(kind); write_record (record); it.advance(); } context.write_occurred_ = 1; }
int TAO_Persistent_Context_Index::recreate_all (void) { CONTEXT_INDEX::ITERATOR *index_iter = 0; ACE_NEW_RETURN (index_iter, (CONTEXT_INDEX::ITERATOR) (*index_), -1); ACE_Auto_Basic_Ptr<CONTEXT_INDEX::ITERATOR> it (index_iter); // Because of broken old g++!!! typedef ACE_Hash_Map_With_Allocator<TAO_Persistent_Index_ExtId, TAO_Persistent_Index_IntId> IND_DEF; IND_DEF::ENTRY *entry = 0; if (TAO_debug_level > 0) ORBSVCS_DEBUG ((LM_DEBUG, "Starting to recreate Naming Contexts from the file...\n")); // For each entry in <index_>, create a Naming Context servant. do { index_iter->next (entry); // Put together a servant for the new Naming Context // Using the naming context factory to create a naming context of the appropriate type TAO_Persistent_Naming_Context *context_impl = this->context_impl_factory_->create_naming_context_impl (poa_.in (), entry->ext_id_.poa_id_, this, entry->int_id_.hash_map_, entry->int_id_.counter_); // Put <context_impl> into the auto pointer temporarily, in case next // allocation fails. ACE_Auto_Basic_Ptr<TAO_Persistent_Naming_Context> temp (context_impl); TAO_Naming_Context *context = 0; ACE_NEW_RETURN (context, TAO_Naming_Context (context_impl), -1); // Let <implementation> know about it's <interface>. context_impl->interface (context); // Release auto pointer and start using reference counting to // control our servant. temp.release (); PortableServer::ServantBase_var s = context; // Register with the POA. PortableServer::ObjectId_var id = PortableServer::string_to_ObjectId (entry->ext_id_.poa_id_); this->poa_->activate_object_with_id (id.in (), context); CosNaming::NamingContext_var result = context->_this (); // If this is the root Naming Context, take a note of it. if (context_impl->root ()) this->root_context_= result._retn (); } while (index_iter->advance ()); 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 (); // Make all oneways "reliable." { CORBA::Object_var manager_object = orb->resolve_initial_references("ORBPolicyManager"); CORBA::PolicyManager_var policy_manager = CORBA::PolicyManager::_narrow(manager_object.in()); if (CORBA::is_nil (policy_manager.in ())) ACE_ERROR_RETURN ((LM_ERROR, " (%P|%t) Panic: nil PolicyManager\n"), 1); CORBA::Any policy_value; policy_value <<= Messaging::SYNC_WITH_SERVER; CORBA::PolicyList policies(1); policies.length(1); policies[0] = orb->create_policy (Messaging::SYNC_SCOPE_POLICY_TYPE, policy_value); policy_manager->set_policy_overrides (policies, CORBA::ADD_OVERRIDE); policies[0]->destroy (); } if (parse_args (argc, argv) != 0) return 1; CORBA::Object_var tmp = orb->string_to_object(ior); Test::Service_var service = Test::Service::_narrow(tmp.in ()); if (CORBA::is_nil (service.in ())) { ACE_ERROR_RETURN ((LM_DEBUG, "Nil service reference <%s>\n", ior), 1); } Callback *callback_impl; ACE_NEW_RETURN (callback_impl, Callback(orb.in ()), 1); PortableServer::ServantBase_var owner_transfer(callback_impl); PortableServer::ObjectId_var id = root_poa->activate_object (callback_impl); CORBA::Object_var object = root_poa->id_to_reference (id.in ()); Test::Callback_var callback = Test::Callback::_narrow (object.in ()); poa_manager->activate (); ACE_DEBUG ((LM_DEBUG, "(%P|%t) client - starting test\n")); service->run_test (callback.in ()); ACE_DEBUG ((LM_DEBUG, "(%P|%t) client - running ORB\n")); orb->run (); root_poa->destroy (1, 1); orb->destroy (); } catch (const CORBA::Exception& ex) { ex._tao_print_exception ("Exception caught:"); return 1; } return 0; }
int EC::run (int argc, ACE_TCHAR* argv[]) { TAO_EC_Default_Factory::init_svcs (); try { // First parse our command line options if (this->parse_args(argc, argv) != 0) { return -1; } // ORB initialization boiler plate... CORBA::ORB_var orb = CORBA::ORB_init (argc, argv); CORBA::Object_var object = orb->resolve_initial_references ("RootPOA"); PortableServer::POA_var rootpoa = PortableServer::POA::_narrow (object.in ()); PortableServer::POAManager_var root_poa_manager = rootpoa->the_POAManager (); // Create persistent POA CORBA::PolicyList policies (2); policies.length (2); policies[0] = rootpoa->create_id_assignment_policy (PortableServer::USER_ID); policies[1] = rootpoa->create_lifespan_policy (PortableServer::PERSISTENT); ACE_CString poaname = "POA"; PortableServer::POA_var child_poa_ = rootpoa->create_POA (poaname.c_str (), root_poa_manager.in (), policies); // Create a local event channel and register it with the RootPOA. TAO_EC_Event_Channel_Attributes attributes (rootpoa.in (), rootpoa.in ()); attributes.consumer_reconnect = 1; attributes.supplier_reconnect = 1; TAO_EC_Event_Channel ec_impl (attributes); ec_impl.activate (); PortableServer::ObjectId_var ecId = PortableServer::string_to_ObjectId(ACE_TEXT_ALWAYS_CHAR(ecname)); child_poa_->activate_object_with_id(ecId.in(), &ec_impl); CORBA::Object_var ec_obj = child_poa_->id_to_reference(ecId.in()); RtecEventChannelAdmin::EventChannel_var ec = RtecEventChannelAdmin::EventChannel::_narrow(ec_obj.in()); // Find the Naming Service. object = orb->resolve_initial_references("NameService"); CosNaming::NamingContextExt_var naming_context = CosNaming::NamingContextExt::_narrow(object.in()); // Create a name. CosNaming::Name name; name.length (1); name[0].id = CORBA::string_dup (ACE_TEXT_ALWAYS_CHAR(ecname)); name[0].kind = CORBA::string_dup (""); // Register with the name server naming_context->rebind (name, ec.in ()); root_poa_manager->activate (); // Wait for events, using work_pending()/perform_work() may help // or using another thread, this example is too simple for that. orb->run (); } catch (const CORBA::Exception& ex) { ex._tao_print_exception ("EC::run"); return 1; } return 0; }
int main(int argc, char* argv[]){ char aux1[1000]; try{ // // Inicializacion del ORB // CORBA::ORB_var orb = CORBA::ORB_init(argc, argv, ""); CORBA::Object_var obj = orb->resolve_initial_references("RootPOA"); PortableServer::POA_var root_poa = PortableServer::POA::_narrow(obj); PortableServer::POAManager_var manager = root_poa->the_POAManager(); // // Obtain NamincContext reference ... // CORBA::Object_var naming_context_object; CosNaming::NamingContext_ptr naming_context; try { naming_context_object = orb->string_to_object("corbaloc:iiop:[email protected]:2809/NameService"); naming_context = CosNaming::NamingContext::_narrow (naming_context_object.in ()); } catch (...) { cerr << "Error: cannot obtain naming service initial reference" << endl; throw; } // // Crea un POA para el supplier: PERSISTENT LifespanPolicy, USER_ID policy // PortableServer::LifespanPolicy_var lifespan = root_poa->create_lifespan_policy(PortableServer::PERSISTENT); PortableServer::IdAssignmentPolicy_var idAssignment = root_poa->create_id_assignment_policy(PortableServer::USER_ID); CORBA::PolicyList policies(2); policies.length(2); policies[0] = PortableServer::IdAssignmentPolicy::_duplicate(idAssignment); policies[1] = PortableServer::LifespanPolicy::_duplicate(lifespan); PortableServer::POA_var consumer_poa = root_poa->create_POA("consumerPOA", manager.in(), policies); PortableServer::POAManager_var consumer_poa_manager = consumer_poa->the_POAManager(); idAssignment->destroy(); lifespan->destroy(); // Activa el POAManager manager->activate(); // // Crea y activa el servant del consumer // PortableServer::ObjectId_var oid = PortableServer::string_to_ObjectId("MyConsumer"); MyConsumerImpl servant_consumer; try{ consumer_poa->activate_object_with_id(oid.in(), &servant_consumer); } catch(...){ cerr << "[supplier] ERROR: activating servant_supplier " << endl; } CORBA::Object_var consumer_obj = consumer_poa->id_to_reference(oid.in()); CosEventComm::PushConsumer_var consumer = CosEventComm::PushConsumer::_narrow(consumer_obj); // // Recoge la referencia al canal // // readChannelIOR(); // obj = orb->string_to_object(ChannelIOR); CosNaming::NamingContext_var naming_context_notif = NULL; CosNaming::Name name_notif(2); name_notif.length (2); name_notif[0].id = CORBA::string_dup ("MyNotif"); name_notif[0].kind = CORBA::string_dup (""); name_notif[1].id = CORBA::string_dup ("channel"); name_notif[1].kind = CORBA::string_dup (""); obj = naming_context->resolve(name_notif); CosNotifyChannelAdmin::EventChannel_var channel; channel = CosNotifyChannelAdmin::EventChannel::_narrow(obj); if (CORBA::is_nil(channel)) { cerr << "[consumer] ERROR: canal nulo " << endl; return -1; } // cerr << "[consumer] ChannelId " << channel->get_channelID() << endl; // // Obtenemos el manager // CosNotifyChannelAdmin::ConsumerAdmin_var consumerAdmin; CosNotifyChannelAdmin::AdminID adminid; try{ consumerAdmin = channel->default_consumer_admin(); } catch(CORBA::Exception &ce){ fprintf(stderr,"(%s)%i CORBA::Exception - %s\n", __FILE__,__LINE__,ce._name()); } catch(...){ fprintf(stderr,"(%s)%i - Unexpected exception!", __FILE__,__LINE__); } // // Obtenemos el proxy // CosNotifyChannelAdmin::ProxyPushSupplier_var pushSupplier; CosNotifyChannelAdmin::ProxyID proxy_id; CosNotifyChannelAdmin::ClientType ctype = CosNotifyChannelAdmin::ANY_EVENT; try{ CosNotifyChannelAdmin::ProxySupplier_var obj = consumerAdmin->obtain_notification_push_supplier(ctype, proxy_id); pushSupplier = CosNotifyChannelAdmin::ProxyPushSupplier::_narrow(obj); // Conecta proxy pushSupplier->connect_any_push_consumer(consumer); } catch(CosEventChannelAdmin::AlreadyConnected &ac){ fprintf(stderr,"(%s)%i CosEventChannelAdmin::AlreadyConnected\n", __FILE__,__LINE__); } catch(CORBA::SystemException& se){ fprintf(stderr,"(%s)%i CORBA::SystemException\n", __FILE__,__LINE__); } catch(CosNotifyChannelAdmin::AdminLimitExceeded err){ fprintf(stderr,"(%s)%i CosNotifyChannelAdmin::AdminLimitExceeded\n", __FILE__,__LINE__); } catch(CORBA::Exception &ce){ fprintf(stderr,"(%s)%i CORBA::Exception - %s\n", __FILE__,__LINE__,ce._name()); } catch(...){ fprintf(stderr,"Unexpected exception!\n"); } // // // // Guarda la referencia en el Servicio de Nombres // // // CosNaming::NamingContext_var naming_context_notif = NULL; // CosNaming::Name name_notif(1); // name_notif.length (1); // name_notif[0].id = CORBA::string_dup ("MyNotif"); // name_notif[0].kind = CORBA::string_dup (""); // naming_context_notif = naming_context->bind_new_context(name_notif); // CosNaming::Name name_consumer(1); // name_consumer.length (1); // name_consumer[0].id = CORBA::string_dup ("consumer"); // name_consumer[0].kind = CORBA::string_dup (""); // naming_context_notif->bind(name_consumer, consumer_obj); cerr << "[consumer] Esperando eventos.... " << endl; orb->run(); cerr << "[consumer] disconnect .... " << endl; // supplier->disconnect_push_supplier(); // consumeradmin->destroy(); cerr << "[consumer] Terminando " << endl; orb->shutdown(true); orb->destroy(); } catch(CORBA::Exception& exc) { cerr << "[consumer] Excepcion: " << exc << endl; return 1; } }
int ACE_TMAIN (int argc, ACE_TCHAR *argv[]) { try { // Initialize the ORB. CORBA::ORB_var orb = CORBA::ORB_init(argc, argv); // Find the Naming Service. CORBA::Object_var obj = orb->resolve_initial_references("NameService"); CosNaming::NamingContextExt_var root_context = CosNaming::NamingContextExt::_narrow(obj.in()); // Find the EchoEventChannel. obj = root_context->resolve_str("CosEventService"); // Downcast the object reference to an EventChannel reference. CosEventChannelAdmin::EventChannel_var echoEC = CosEventChannelAdmin::EventChannel::_narrow(obj.in()); if (CORBA::is_nil(echoEC.in())) { std::cerr << "Could not narrow EchoEventChannel." << std::endl; return 1; } std::cout << "Found the EchoEventChannel." << std::endl; // Get a ConsumerAdmin object from the EventChannel. CosEventChannelAdmin::ConsumerAdmin_var consumerAdmin = echoEC->for_consumers(); // Get a ProxyPushSupplier from the ConsumerAdmin. CosEventChannelAdmin::ProxyPushSupplier_var supplier = consumerAdmin->obtain_push_supplier(); // Instantiate an EchoEventConsumer_i servant. PortableServer::Servant_var<EchoEventConsumer_i> servant = new EchoEventConsumer_i(orb.in(), supplier.in(), EVENTS_TILL_SHUTDOWN); // Register it with the RootPOA. obj = orb->resolve_initial_references("RootPOA"); PortableServer::POA_var poa = PortableServer::POA::_narrow(obj.in()); PortableServer::ObjectId_var oid = poa->activate_object(servant.in()); CORBA::Object_var consumer_obj = poa->id_to_reference(oid.in()); CosEventComm::PushConsumer_var consumer = CosEventComm::PushConsumer::_narrow(consumer_obj.in()); // Connect to the ProxyPushSupplier, passing our PushConsumer object // reference to it. supplier->connect_push_consumer(consumer.in()); // Activate the POA via its POAManager. PortableServer::POAManager_var poa_manager = poa->the_POAManager(); poa_manager->activate(); std::cout << "Ready to receive events..." << std::endl; // Enter the ORB event loop. orb->run(); // If we have reached this, we must be shutting down... orb->destroy(); std::cout << "Test complete." << std::endl; return 0; } catch(const CORBA::Exception& ex) { std::cerr << "Consumer: Caught CORBA::Exception: " << ex << std::endl; } return 1; }
int ECT_Throughput::run (int argc, ACE_TCHAR* argv[]) { try { // Calibrate the high resolution timer *before* starting the // test. ACE_High_Res_Timer::calibrate (); this->orb_ = CORBA::ORB_init (argc, argv); CORBA::Object_var poa_object = this->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 (); poa_manager->activate (); if (this->parse_args (argc, argv)) return 1; if (TAO_debug_level > 0) { ACE_DEBUG ((LM_DEBUG, "Execution parameters:\n" " consumers = <%d>\n" " suppliers = <%d>\n" " burst count = <%d>\n" " burst size = <%d>\n" " event size = <%d>\n" " burst pause = <%d>\n" " consumer type start = <%d>\n" " consumer type count = <%d>\n" " consumer type shift = <%d>\n" " supplier type start = <%d>\n" " supplier type count = <%d>\n" " supplier type shift = <%d>\n" " pid file name = <%s>\n" " concurrency HWM = <%d>\n", this->n_consumers_, this->n_suppliers_, this->burst_count_, this->burst_size_, this->event_size_, this->burst_pause_, this->consumer_type_start_, this->consumer_type_count_, this->consumer_type_shift_, this->supplier_type_start_, this->supplier_type_count_, this->supplier_type_shift_, this->pid_file_name_?this->pid_file_name_:ACE_TEXT("nil"), this->ec_concurrency_hwm_ ) ); } if (this->pid_file_name_ != 0) { FILE* pid = ACE_OS::fopen (this->pid_file_name_, "w"); if (pid != 0) { ACE_OS::fprintf (pid, "%ld\n", static_cast<long> (ACE_OS::getpid ())); ACE_OS::fclose (pid); } } int priority = (ACE_Sched_Params::priority_min (ACE_SCHED_FIFO) + ACE_Sched_Params::priority_max (ACE_SCHED_FIFO)) / 2; priority = ACE_Sched_Params::next_priority (ACE_SCHED_FIFO, priority); // Enable FIFO scheduling, e.g., RT scheduling class on Solaris. if (ACE_OS::sched_params (ACE_Sched_Params (ACE_SCHED_FIFO, priority, ACE_SCOPE_PROCESS)) != 0) { if (ACE_OS::last_error () == EPERM) { ACE_DEBUG ((LM_DEBUG, "%s: user is not superuser, " "so remain in time-sharing class\n", argv[0])); this->thr_create_flags_ = THR_NEW_LWP; } else ACE_ERROR ((LM_ERROR, "%s: ACE_OS::sched_params failed\n", argv[0])); } if (ACE_OS::thr_setprio (priority) == -1) { ACE_ERROR ((LM_ERROR, "(%P|%t) main thr_setprio failed," "no real-time features\n")); } #if 1 ACE_Config_Scheduler scheduler_impl; #else #include "ECT_Scheduler_Info.h" ACE_Runtime_Scheduler scheduler_impl ( runtime_configs_size, runtime_configs, runtime_infos_size, runtime_infos); #endif RtecScheduler::Scheduler_var scheduler = scheduler_impl._this (); #if 0 CORBA::Object_var naming_obj = this->orb_->resolve_initial_references ("NameService"); if (CORBA::is_nil (naming_obj.in ())) ACE_ERROR_RETURN ((LM_ERROR, " (%P|%t) Unable to get the Naming Service.\n"), 1); CosNaming::NamingContext_var naming_context = CosNaming::NamingContext::_narrow (naming_obj.in ()); // This is the name we (potentially) register the Scheduling // Service in the Naming Service. CosNaming::Name schedule_name (1); schedule_name.length (1); schedule_name[0].id = CORBA::string_dup ("ScheduleService"); CORBA::String_var str = this->orb_->object_to_string (scheduler.in ()); ACE_DEBUG ((LM_DEBUG, "The (local) scheduler IOR is <%s>\n", str.in ())); // Register the servant with the Naming Context.... naming_context->rebind (schedule_name, scheduler.in ()); ACE_Scheduler_Factory::use_config (naming_context.in ()); #endif /* 0 */ auto_ptr<POA_RtecEventChannelAdmin::EventChannel> ec_impl; TAO_EC_Event_Channel_Attributes attr (root_poa.in (), root_poa.in ()); TAO_EC_Event_Channel *ec = new TAO_EC_Event_Channel (attr); ec->activate (); auto_ptr<POA_RtecEventChannelAdmin::EventChannel> auto_ec_impl (ec); ec_impl = auto_ec_impl; RtecEventChannelAdmin::EventChannel_var channel = ec_impl->_this (); this->connect_consumers (scheduler.in (), channel.in ()); ACE_DEBUG ((LM_DEBUG, "connected consumer(s)\n")); this->connect_suppliers (scheduler.in (), channel.in ()); ACE_DEBUG ((LM_DEBUG, "connected supplier(s)\n")); this->activate_suppliers (); ACE_DEBUG ((LM_DEBUG, "suppliers are active\n")); // Wait for the supplier threads... if (ACE_Thread_Manager::instance ()->wait () == -1) { ACE_ERROR ((LM_ERROR, "Thread_Manager wait failed\n")); return 1; } ACE_DEBUG ((LM_DEBUG, "suppliers finished\n")); this->dump_results (); this->disconnect_consumers (); ACE_DEBUG ((LM_DEBUG, "consumers disconnected\n")); this->disconnect_suppliers (); ACE_DEBUG ((LM_DEBUG, "suppliers disconnected\n")); channel->destroy (); ACE_DEBUG ((LM_DEBUG, "channel destroyed\n")); { // Deactivate the EC PortableServer::POA_var poa = ec_impl->_default_POA (); PortableServer::ObjectId_var id = poa->servant_to_id (ec_impl.get ()); poa->deactivate_object (id.in ()); ACE_DEBUG ((LM_DEBUG, "EC deactivated\n")); } { // Deactivate the Scheduler PortableServer::POA_var poa = scheduler_impl._default_POA (); PortableServer::ObjectId_var id = poa->servant_to_id (&scheduler_impl); poa->deactivate_object (id.in ()); ACE_DEBUG ((LM_DEBUG, "scheduler deactivated\n")); } } catch (const CORBA::Exception& ex) { ex._tao_print_exception ("ECT_Throughput::run"); } catch (...) { ACE_ERROR ((LM_ERROR, "non-corba exception raised\n")); } return 0; }