int Fault_Detector_Loader::init (int argc, ACE_TCHAR* argv[]) { static int initialized = 0; // Only allow initialization once. if (initialized) return 0; initialized = 1; Fault_Detector* detector = 0; // Parse any service configurator parameters. if (argc > 0 && ACE_OS::strcasecmp (argv[0], ACE_TEXT("sctp")) == 0) { #if (TAO_HAS_SCIOP == 1) ACE_auto_ptr_reset(detector_, detector); #else ORBSVCS_DEBUG ((LM_DEBUG, "(%P|%t) SCTP not enabled. ", " Enable SCTP and rebuild ACE+TAO\n")); #endif /* TAO_HAS_SCIOP */ argc--; argv++; } else { ACE_NEW_RETURN(detector, TCP_Fault_Detector, -1); ACE_auto_ptr_reset(detector_, detector); } return detector_->init(argc, argv); }
RTServer_Setup::RTServer_Setup (int use_rt_corba, CORBA::ORB_ptr orb, const RT_Class &rt_class, int nthreads) : RTClient_Setup (use_rt_corba, orb, rt_class, nthreads) { if (use_rt_corba) { ACE_auto_ptr_reset (this->rtpoa_setup_, new RTPOA_Setup (orb, *this->rtcorba_setup ())); this->poa_ = this->rtpoa_setup_->poa (); } else { this->poa_ = RIR_Narrow<RTPortableServer::POA>::resolve (orb, "RootPOA"); } }
static MALLOC * myallocator (const void *base_addr = 0) { static auto_ptr<MALLOC> static_allocator; if (static_allocator.get () == 0) { #if defined (ACE_HAS_WINCE) || defined (ACE_OPENVMS) // WinCE cannot do fixed base, ever. ACE_UNUSED_ARG (base_addr); ACE_MMAP_Memory_Pool_Options options (0, ACE_MMAP_Memory_Pool_Options::NEVER_FIXED); #else ACE_MMAP_Memory_Pool_Options options (base_addr); #endif /* ACE_HAS_WINCE */ #if !defined (ACE_TEST_REMAP_ON_FAULT) options.minimum_bytes_ = 512 * 1024; #endif /* ACE_TEST_REMAP_ON_FAULT */ MALLOC *ptr = new MALLOC (MMAP_FILENAME, MUTEX_NAME, &options); ACE_auto_ptr_reset (static_allocator, ptr); } return static_allocator.get (); }
void ServantRetentionStrategyRetain::strategy_init (TAO_Root_POA *poa) { poa_ = poa; // Create the active object map to be used TAO_Active_Object_Map *active_object_map = 0; ACE_NEW_THROW_EX (active_object_map, TAO_Active_Object_Map (!poa->system_id (), !poa->allow_multiple_activations (), poa->is_persistent (), poa->orb_core().server_factory ()->active_object_map_creation_parameters () ), CORBA::NO_MEMORY ()); ACE_auto_ptr_reset (this->active_object_map_, active_object_map); #if defined (TAO_HAS_MONITOR_POINTS) && (TAO_HAS_MONITOR_POINTS == 1) ACE_CString name_str ("Active_Object_Map_"); name_str += poa->orb_core ().orbid (); name_str += '_'; name_str += poa->the_name (); active_object_map->monitor_->name (name_str.c_str ()); active_object_map->monitor_->add_to_registry (); #endif /* TAO_HAS_MONITOR_POINTS */ }
int Replication_Service::init (int argc, ACE_TCHAR* argv[]) { static int initialized = 0; // Only allow initialization once. if (initialized) return 0; initialized = 1; bool ami = false; // Parse any service configurator parameters. while (argc > 0) { if (ACE_OS::strcasecmp (argv[0], ACE_TEXT("AMI")) ==0 ) ami = true; if (ACE_OS::strcasecmp (argv[0], ACE_TEXT("-threads")) ==0 && argc > 1) { FTRTEC::threads = ACE_OS::atoi(argv[1]); if (FTRTEC::threads ==0 ) FTRTEC::threads = 1; ++argv; --argc; } ++argv; --argc; } Replication_Strategy* strategy; if (ami) { ACE_NEW_RETURN (strategy, AMI_Replication_Strategy(threads() > 1), -1); TAO_FTRTEC::Log(3, ACE_TEXT("AMI replication strategy\n")); } else { ACE_NEW_RETURN (strategy, Basic_Replication_Strategy(threads() > 1), -1); TAO_FTRTEC::Log(3, ACE_TEXT("Basic replication strategy\n")); } ACE_auto_ptr_reset (replication_strategy, strategy); try { PortableInterceptor::ORBInitializer_ptr temp_orb_initializer = PortableInterceptor::ORBInitializer::_nil (); PortableInterceptor::ORBInitializer_var orb_initializer; /// Register the RTCORBA ORBInitializer. ACE_NEW_THROW_EX (temp_orb_initializer, FTEC_ORBInitializer, CORBA::NO_MEMORY ()); orb_initializer = temp_orb_initializer; PortableInterceptor::register_orb_initializer (orb_initializer.in ()); } catch (const CORBA::Exception& ex) { ex._tao_print_exception ( "Unexpected exception caught while ""initializing the TransactionDepth"); return -1; } return 0; }
void Replication_Service::become_primary() { TAO_FTRTEC::Log(3, ACE_TEXT("become_primary\n")); Replication_Strategy* strategy = replication_strategy->make_primary_strategy(); ACE_ASSERT(strategy); if (replication_strategy.get() != strategy) { ACE_auto_ptr_reset(replication_strategy, strategy); } }
RTClient_Setup::RTClient_Setup (int use_rt_corba, CORBA::ORB_ptr orb, const RT_Class &rt_class, int nthreads) : use_rt_corba_ (use_rt_corba) , syncscope_setup_ (orb) { if (use_rt_corba) { ACE_auto_ptr_reset (this->rtcorba_setup_, new RTCORBA_Setup (orb, rt_class, nthreads)); #if 0 ACE_auto_ptr_reset (this->priorityband_setup_, new PriorityBand_Setup (orb, *this->rtcorba_setup_)); #endif /* 0 */ } }
bool MyMain::init_client (const ACE_TCHAR* args) { std::string my_args (ACE_TEXT_ALWAYS_CHAR(args)); int thread_pool = 1; ACE_auto_ptr_reset (client_task_, new Client_Task (my_args)); ACE_ASSERT (client_task_.get() != 0); client_task_->activate (THR_NEW_LWP | THR_JOINABLE |THR_INHERIT_SCHED , thread_pool); return true; }
bool MyMain::init_server (const ACE_TCHAR* args) { std::string my_args (ACE_TEXT_ALWAYS_CHAR(args)); // main thread and extra thread for backdoor operations int thread_pool = 2; ACE_auto_ptr_reset (server_task_, new Server_Task (my_args)); ACE_ASSERT (server_task_.get() != 0); server_task_->activate (THR_NEW_LWP | THR_JOINABLE |THR_INHERIT_SCHED , thread_pool); int duration = 4; //wait 3 seconds for initialization ACE_Time_Value current = ACE_High_Res_Timer::gettimeofday_hr (); ACE_Time_Value timeout = current + ACE_Time_Value(duration); while (current < timeout) { if (server_task_->ready()) { break; } ACE_Time_Value sleep_time; sleep_time.msec (10); ACE_OS::sleep (sleep_time); current += sleep_time; } if (!server_task_->ready()) { server_task_->force_shutdown (); server_task_->wait (); ACE_auto_ptr_reset (server_task_, (Server_Task*)0); return false; } return true; }
int DllOrb::fini (void) { try { mv_poaManager_->deactivate (1, 1); mv_poaManager_ = PortableServer::POAManager::_nil (); // attempt to protect against sporadic BAD_INV_ORDER exceptions ACE_OS::sleep (ACE_Time_Value (0, 500)); mv_rootPOA_->destroy (1, 1); mv_rootPOA_ = PortableServer::POA::_nil (); mv_orb_->shutdown (1); ACE_DEBUG ((LM_ERROR, ACE_TEXT ("wait() ...\n"))); // wait for our threads to finish wait(); ACE_DEBUG ((LM_ERROR, ACE_TEXT ("wait() done\n"))); ACE_auto_ptr_reset (ma_barrier_, static_cast<ACE_Thread_Barrier *> (0)); } catch (...) { ACE_DEBUG ((LM_ERROR, ACE_TEXT ("ERROR: exception\n"))); return -1; } try { mv_orb_->destroy (); mv_orb_ = CORBA::ORB::_nil (); } catch (const CORBA::Exception& ex) { ex._tao_print_exception ("Exception caught:"); return -1; } return 0; }
ReplicaController:: ReplicaController (CORBA::ORB_ptr orb) : orb_ (CORBA::ORB::_duplicate (orb)) { try { CORBA::Object_var poa_object = orb_->resolve_initial_references ("RootPOA"); root_poa_ = PortableServer::POA::_narrow ( poa_object.in ()); } catch (const CORBA::Exception& ex) { ex._tao_print_exception ("Caught exception:"); ACE_OS::abort (); } // Generate member id ACE_Utils::UUID uuid; ACE_Utils::UUID_GENERATOR::instance ()->init (); ACE_Utils::UUID_GENERATOR::instance ()->generate_UUID (uuid); ACE_INET_Addr address (10000, "239.255.0.1"); ACE_DEBUG ((LM_DEBUG, "Becoming a member with id %s\n", uuid.to_string ()->c_str ())); ACE_auto_ptr_reset (group_, new ACE_TMCast::Group (address, uuid.to_string ()->c_str ())); int r = ACE_Thread_Manager::instance ()->spawn ( &ReplicaController::listener_thunk, this); if (r < 0) { orb_->shutdown (0); } }
template<class Client_Type> Low_Priority_Setup<Client_Type>:: Low_Priority_Setup (int consumer_count, int iterations, int use_different_types, CORBA::Long experiment_id, CORBA::Long base_event_type, int workload, ACE_High_Res_Timer::global_scale_factor_type gsf, int nthreads, int thread_priority, int thread_sched_class, int per_thread_period, PortableServer::POA_ptr supplier_poa, PortableServer::POA_ptr consumer_poa, RtecEventChannelAdmin::EventChannel_ptr ec, ACE_Barrier *barrier) : consumer_count_ (consumer_count) , clients_ (consumer_count ? new Client_Type[consumer_count] : 0) , disconnect_ (consumer_count ? new Client_Auto_Disconnect[consumer_count] : 0) , nthreads_ (nthreads) , tasks_ (nthreads ? new Send_Task[nthreads] : 0) , stoppers_ (nthreads ? new Auto_Send_Task_Stopper[nthreads] : 0) { for (int i = 0; i != consumer_count; ++i) { int per_consumer_workload = workload / this->consumer_count_; if (workload != 0 && per_consumer_workload == 0) per_consumer_workload = 1; CORBA::Long event_type = base_event_type; if (use_different_types) event_type = base_event_type + 2 * i; this->clients_[i].init (experiment_id, event_type, iterations, per_consumer_workload, gsf, supplier_poa, consumer_poa); this->clients_[i].connect (ec); // Automatically disconnect the group if the connection was // successful this->disconnect_[i] = &this->clients_[i]; } for (int j = 0; j != nthreads; ++j) { CORBA::Long event_type = base_event_type; if (use_different_types) event_type = base_event_type + 2 * j; this->tasks_[j].init (0, per_thread_period, j * per_thread_period, event_type, experiment_id, this->clients_[j].supplier (), barrier); this->tasks_[j].thr_mgr (&this->thr_mgr_); ACE_auto_ptr_reset (this->stoppers_[j], new Send_Task_Stopper (thread_priority, thread_sched_class, &this->tasks_[j])); } }
int ACE_TMAIN (int argc, ACE_TCHAR *argv[]) { try { // Initialize the EC Factory so we can customize the EC TAO_EC_Default_Factory::init_svcs (); // Initialize the ORB. CORBA::ORB_var orb = CORBA::ORB_init (argc, argv); const ACE_TCHAR *ecname = ACE_TEXT ("EventService"); const ACE_TCHAR *address = ACE_TEXT ("localhost"); const ACE_TCHAR *iorfile = 0; u_short port = 12345; u_short listenport = 12345; int mcast = 1; for (int i = 0; argv[i] != 0; i++) { if (ACE_OS::strcasecmp(argv[i], ACE_TEXT ("-ecname")) == 0) { if (argv[i+1] != 0) ecname = argv[++i]; else ACE_ERROR_RETURN ((LM_ERROR, "Missing Event channel name\n"),0); } else if (ACE_OS::strcasecmp(argv[i], ACE_TEXT ("-address")) == 0) { if (argv[i+1] != 0) address = argv[++i]; else ACE_ERROR_RETURN ((LM_ERROR, "Missing address\n"),0); } else if (ACE_OS::strcasecmp(argv[i], ACE_TEXT ("-port")) == 0) { if (argv[i+1] != 0) port = ACE_OS::atoi(argv[++i]); else ACE_ERROR_RETURN ((LM_ERROR, "Missing port\n"),0); } else if (ACE_OS::strcasecmp(argv[i], ACE_TEXT ("-listenport")) == 0) { if (argv[i+1] != 0) listenport = ACE_OS::atoi(argv[++i]); else ACE_ERROR_RETURN ((LM_ERROR, "Missing port\n"), 0); } else if (ACE_OS::strcasecmp(argv[i], ACE_TEXT ("-iorfile")) == 0) { if (argv[i+1] != 0) iorfile = argv[++i]; else ACE_ERROR_RETURN ((LM_ERROR, "Missing ior file\n"), 0); } else if (ACE_OS::strcasecmp(argv[i], ACE_TEXT ("-udp")) == 0) mcast = 0; } // Get the POA CORBA::Object_var tmpobj = orb->resolve_initial_references ("RootPOA"); PortableServer::POA_var poa = PortableServer::POA::_narrow (tmpobj.in ()); PortableServer::POAManager_var poa_manager = poa->the_POAManager (); poa_manager->activate (); // Create a local event channel and register it TAO_EC_Event_Channel_Attributes attributes (poa.in (), poa.in ()); TAO_EC_Event_Channel ec_impl (attributes); ec_impl.activate (); PortableServer::ObjectId_var oid = poa->activate_object(&ec_impl); tmpobj = poa->id_to_reference(oid.in()); RtecEventChannelAdmin::EventChannel_var ec = RtecEventChannelAdmin::EventChannel::_narrow(tmpobj.in()); // Find the Naming Service. tmpobj = orb->resolve_initial_references("NameService"); CosNaming::NamingContextExt_var root_context = CosNaming::NamingContextExt::_narrow(tmpobj.in()); // Bind the Event Channel using Naming Services CosNaming::Name_var name = root_context->to_name (ACE_TEXT_ALWAYS_CHAR (ecname)); root_context->rebind(name.in(), ec.in()); // Get a proxy push consumer from the EventChannel. RtecEventChannelAdmin::SupplierAdmin_var admin = ec->for_suppliers(); RtecEventChannelAdmin::ProxyPushConsumer_var consumer = admin->obtain_push_consumer(); // Instantiate an EchoEventSupplier_i servant. EchoEventSupplier_i servant(orb.in()); // Register it with the RootPOA. oid = poa->activate_object(&servant); tmpobj = poa->id_to_reference(oid.in()); RtecEventComm::PushSupplier_var supplier = RtecEventComm::PushSupplier::_narrow(tmpobj.in()); // Connect to the EC. ACE_SupplierQOS_Factory qos; qos.insert (MY_SOURCE_ID, MY_EVENT_TYPE, 0, 1); consumer->connect_push_supplier (supplier.in (), qos.get_SupplierQOS ()); // Initialize the address server with the desired address. This will // be used by the sender object and the multicast receiver only if // one is not otherwise available via the naming service. ACE_INET_Addr send_addr (port, address); SimpleAddressServer addr_srv_impl (send_addr); // Create an instance of the addr server for local use PortableServer::ObjectId_var addr_srv_oid = poa->activate_object(&addr_srv_impl); tmpobj = poa->id_to_reference(addr_srv_oid.in()); RtecUDPAdmin::AddrServer_var addr_srv = RtecUDPAdmin::AddrServer::_narrow(tmpobj.in()); // Create and initialize the sender object PortableServer::Servant_var<TAO_ECG_UDP_Sender> sender = TAO_ECG_UDP_Sender::create(); TAO_ECG_UDP_Out_Endpoint endpoint; // need to be explicit about the address type when built with // IPv6 support, otherwise SOCK_DGram::open defaults to ipv6 when // given a sap_any address. This causes trouble on at least solaris // and windows, or at most on not-linux. if (endpoint.dgram ().open (ACE_Addr::sap_any, send_addr.get_type()) == -1) { ACE_ERROR_RETURN ((LM_ERROR, "Cannot open send endpoint\n"), 1); } // TAO_ECG_UDP_Sender::init() takes a TAO_ECG_Refcounted_Endpoint. // If we don't clone our endpoint and pass &endpoint, the sender will // attempt to delete endpoint during shutdown. TAO_ECG_Refcounted_Endpoint clone (new TAO_ECG_UDP_Out_Endpoint (endpoint)); sender->init (ec.in (), addr_srv.in (), clone); // Setup the subscription and connect to the EC ACE_ConsumerQOS_Factory cons_qos_fact; cons_qos_fact.start_disjunction_group (); cons_qos_fact.insert (ACE_ES_EVENT_SOURCE_ANY, ACE_ES_EVENT_ANY, 0); RtecEventChannelAdmin::ConsumerQOS sub = cons_qos_fact.get_ConsumerQOS (); sender->connect (sub); // Create and initialize the receiver PortableServer::Servant_var<TAO_ECG_UDP_Receiver> receiver = TAO_ECG_UDP_Receiver::create(); // TAO_ECG_UDP_Receiver::init() takes a TAO_ECG_Refcounted_Endpoint. // If we don't clone our endpoint and pass &endpoint, the receiver will // attempt to delete endpoint during shutdown. TAO_ECG_Refcounted_Endpoint clone2 (new TAO_ECG_UDP_Out_Endpoint (endpoint)); receiver->init (ec.in (), clone2, addr_srv.in ()); // Setup the registration and connect to the event channel ACE_SupplierQOS_Factory supp_qos_fact; supp_qos_fact.insert (MY_SOURCE_ID, MY_EVENT_TYPE, 0, 1); RtecEventChannelAdmin::SupplierQOS pub = supp_qos_fact.get_SupplierQOS (); receiver->connect (pub); // Create the appropriate event handler and register it with the reactor auto_ptr<ACE_Event_Handler> eh; if (mcast) { auto_ptr<TAO_ECG_Mcast_EH> mcast_eh(new TAO_ECG_Mcast_EH (receiver.in())); mcast_eh->reactor (orb->orb_core ()->reactor ()); mcast_eh->open (ec.in()); ACE_auto_ptr_reset(eh,mcast_eh.release()); //eh.reset(mcast_eh.release()); } else { auto_ptr<TAO_ECG_UDP_EH> udp_eh (new TAO_ECG_UDP_EH (receiver.in())); udp_eh->reactor (orb->orb_core ()->reactor ()); ACE_INET_Addr local_addr (listenport); if (udp_eh->open (local_addr) == -1) ACE_ERROR ((LM_ERROR,"Cannot open EH\n")); ACE_auto_ptr_reset(eh,udp_eh.release()); //eh.reset(udp_eh.release()); } // Create an event (just a string in this case). // Create an event set for one event RtecEventComm::EventSet event (1); event.length (1); // Initialize event header. event[0].header.source = MY_SOURCE_ID; event[0].header.ttl = 1; event[0].header.type = MY_EVENT_TYPE; #if !defined (TAO_LACKS_EVENT_CHANNEL_ANY) // Initialize data fields in event. const CORBA::String_var eventData = CORBA::string_dup (ACE_TEXT_ALWAYS_CHAR (ecname)); event[0].data.any_value <<= eventData; #else // Use the octet sequence payload instead char *tmpstr = const_cast<char *>(ACE_TEXT_ALWAYS_CHAR (ecname)); size_t len = ACE_OS::strlen(tmpstr) +1; event[0].data.payload.replace ( len, len, reinterpret_cast<CORBA::Octet *> (tmpstr)); #endif /* !TAO_LACKS_EVENT_CHANNEL_ANY */ if (iorfile != 0) { CORBA::String_var str = orb->object_to_string( ec.in() ); std::ofstream iorFile( ACE_TEXT_ALWAYS_CHAR(iorfile) ); iorFile << str.in() << std::endl; iorFile.close(); } ACE_DEBUG ((LM_DEBUG, "Starting main loop\n")); const int EVENT_DELAY_MS = 1000; while (1) { consumer->push (event); ACE_Time_Value tv(0, 1000 * EVENT_DELAY_MS); orb->run(tv); } orb->destroy(); return 0; } catch (const CORBA::Exception& exc) { ACE_ERROR ((LM_ERROR, "Caught CORBA::Exception\n%C (%C)\n", exc._name (), exc._rep_id () )); } return 1; }
void Control::join (Federated_Test::Peer_ptr peer) { { ACE_GUARD (TAO_SYNCH_MUTEX, ace_mon, this->mutex_); if (this->peers_count_ == this->peers_expected_) return; this->peers_[this->peers_count_++] = Federated_Test::Peer::_duplicate (peer); if (this->peers_count_ < this->peers_expected_) return; } /// Automatically shutdown the ORB ACE_Utils::Auto_Functor<CORBA::ORB,ORB_Shutdown> orb_shutdown (this->orb_.in ()); /// Automatically shutdown the peers typedef ACE_Utils::Auto_Functor<Federated_Test::Peer,Shutdown<Federated_Test::Peer> > Peer_Shutdown; ACE_Auto_Basic_Array_Ptr<Peer_Shutdown> peer_shutdown ( new Peer_Shutdown[this->peers_count_] ); size_t i; for (i = 0; i != this->peers_count_; ++i) { peer_shutdown[i].reset(this->peers_[i].in()); } ACE_DEBUG ((LM_DEBUG, "Control (%P|%t) Building the federation\n")); /// Build the EC federation for (i = 0; i != this->peers_count_; ++i) { for (size_t j = 0; j != this->peers_count_; ++j) { if (i != j) { this->peers_[j]->connect (this->peers_[i].in ()); } } } /// ... run the test(s) ... for (i = 0; i != this->peers_count_; ++i) { /// ... automatically release the object references ... ACE_Auto_Basic_Array_Ptr<Federated_Test::Loopback_var> loopbacks ( new Federated_Test::Loopback_var[2*this->peers_count_] ); /// ... and automatically disconnect the loopbacks ... typedef Auto_Disconnect<Federated_Test::Loopback> Loopback_Disconnect; ACE_Auto_Basic_Array_Ptr<auto_ptr<Loopback_Disconnect> > disconnects ( new auto_ptr<Loopback_Disconnect>[2*this->peers_count_] ); ACE_DEBUG ((LM_DEBUG, "Control (%P|%t) Running test for peer %d\n", i)); CORBA::Long experiment_id = 128 + i; CORBA::Long base_event_type = ACE_ES_EVENT_UNDEFINED; size_t lcount = 0; size_t j; for (j = 0; j != this->peers_count_; ++j) { if (j != i) { loopbacks[lcount] = this->peers_[j]->setup_loopback (experiment_id, base_event_type); ACE_auto_ptr_reset (disconnects[lcount], new Loopback_Disconnect ( loopbacks[lcount].in ())); lcount++; loopbacks[lcount] = this->peers_[j]->setup_loopback (experiment_id, base_event_type + 2); ACE_auto_ptr_reset (disconnects[lcount], new Loopback_Disconnect ( loopbacks[lcount].in ())); lcount++; } } Federated_Test::Experiment_Results_var results = this->peers_[i]->run_experiment (experiment_id, this->iterations_); ACE_Sample_History history (results->length ()); for (CORBA::ULong k = 0; k != results->length (); ++k) history.sample (results[k]); // We use a fake scale factor because the peer already converted // to microseconds... const ACE_UINT32 fake_scale_factor = 1; ACE_Basic_Stats stats; history.collect_basic_stats (stats); stats.dump_results (ACE_TEXT("Total"), fake_scale_factor); if (this->do_dump_history_) { history.dump_samples (ACE_TEXT("HISTORY"), fake_scale_factor); } } }
void TAO::PG_FactoryRegistry::register_factory ( const char * role, const char * type_id, const PortableGroup::FactoryInfo & factory_info) { METHOD_ENTRY(TAO::PG_FactoryRegistry::register_factory); RoleInfo * role_info = 0; auto_ptr<RoleInfo> safe_entry; if (this->registry_.find(role, role_info) != 0) { ORBSVCS_DEBUG(( LM_DEBUG, "%s: adding new role: %s:%s\n", this->identity_.c_str(), role, type_id)); // Note the 5. It's a guess about the number of factories // that might exist for any particular role object. // todo: make it a parameter. ACE_NEW_THROW_EX (role_info, RoleInfo(5), CORBA::NO_MEMORY()); ACE_auto_ptr_reset (safe_entry, role_info); role_info->type_id_ = type_id; } else { if (role_info->type_id_ != type_id) { throw PortableGroup::TypeConflict(); } } PortableGroup::FactoryInfos & infos = role_info->infos_;; CORBA::ULong length = infos.length(); for (CORBA::ULong nInfo = 0u; nInfo < length; ++nInfo) { PortableGroup::FactoryInfo & info = infos[nInfo]; if (info.the_location == factory_info.the_location) { ORBSVCS_ERROR(( LM_ERROR, "%s: Attempt to register duplicate location %s for role: %s\n" , this->identity_.c_str(), static_cast<const char *> (info.the_location[0].id), role)); throw PortableGroup::MemberAlreadyPresent(); } } infos.length(length + 1); infos[length] = factory_info; if (safe_entry.get() != 0) { this->registry_.bind(role, safe_entry.release()); } ORBSVCS_DEBUG(( LM_DEBUG, "%s: Added factory: [%d] %s@%s\n", this->identity_.c_str(), static_cast<int> (length + 1), role, static_cast<const char *> (factory_info.the_location[0].id) )); METHOD_RETURN(TAO::PG_FactoryRegistry::register_factory); }
int ACE_TMAIN (int argc, ACE_TCHAR *argv[]) { try { // Initialize the EC Factory so we can customize the EC TAO_EC_Default_Factory::init_svcs (); // Initialize the ORB. CORBA::ORB_var orb = CORBA::ORB_init(argc, argv); const ACE_TCHAR* ecname = ACE_TEXT ("EventService"); const ACE_TCHAR* address = ACE_TEXT ("localhost"); const ACE_TCHAR* iorfile = 0; u_short port = 12345; u_short listenport = 12345; int mcast = 1; for (int i = 0; argv[i] != 0; i++) { if (ACE_OS::strcmp(argv[i], ACE_TEXT("-ecname")) == 0) { if (argv[i+1] != 0) { i++; ecname = argv[i]; } else { std::cerr << "Missing Event channel name" << std::endl; } } else if (ACE_OS::strcmp(argv[i], ACE_TEXT("-address")) == 0) { if (argv[i+1] != 0) { i++; address = argv[i]; } else { std::cerr << "Missing address" << std::endl; } } else if (ACE_OS::strcmp(argv[i], ACE_TEXT("-port")) == 0) { if (argv[i+1] != 0) { i++; port = ACE_OS::atoi(argv[i]); } else { std::cerr << "Missing port" << std::endl; } } else if (ACE_OS::strcmp(argv[i], ACE_TEXT("-listenport")) == 0) { if (argv[i+1] != 0) { i++; listenport = ACE_OS::atoi(argv[i]); } else { std::cerr << "Missing port" << std::endl; } } else if (ACE_OS::strcmp(argv[i], ACE_TEXT("-iorfile")) == 0) { if (argv[i+1] != 0) { i++; iorfile = argv[i]; } } else if (ACE_OS::strcmp(argv[i], ACE_TEXT("-udp")) == 0) { mcast = 0; } } // Get the POA CORBA::Object_var object = orb->resolve_initial_references ("RootPOA"); PortableServer::POA_var poa = PortableServer::POA::_narrow (object.in ()); PortableServer::POAManager_var poa_manager = poa->the_POAManager (); poa_manager->activate (); // Create a local event channel and register it TAO_EC_Event_Channel_Attributes attributes (poa.in (), poa.in ()); PortableServer::Servant_var<TAO_EC_Event_Channel> ec_impl = new TAO_EC_Event_Channel(attributes); ec_impl->activate (); PortableServer::ObjectId_var oid = poa->activate_object(ec_impl.in()); CORBA::Object_var ec_obj = poa->id_to_reference(oid.in()); RtecEventChannelAdmin::EventChannel_var ec = RtecEventChannelAdmin::EventChannel::_narrow(ec_obj.in()); // Find the Naming Service. CORBA::Object_var obj = orb->resolve_initial_references("NameService"); CosNaming::NamingContextExt_var root_context = CosNaming::NamingContextExt::_narrow(obj.in()); // Bind the Event Channel using Naming Services CosNaming::Name_var name = root_context->to_name (ACE_TEXT_ALWAYS_CHAR (ecname)); root_context->rebind(name.in(), ec.in()); // Get a proxy push consumer from the EventChannel. RtecEventChannelAdmin::SupplierAdmin_var admin = ec->for_suppliers(); RtecEventChannelAdmin::ProxyPushConsumer_var consumer = admin->obtain_push_consumer(); // Instantiate an EchoEventSupplier_i servant. PortableServer::Servant_var<EchoEventSupplier_i> servant = new EchoEventSupplier_i(orb.in()); // Register it with the RootPOA. oid = poa->activate_object(servant.in()); CORBA::Object_var supplier_obj = poa->id_to_reference(oid.in()); RtecEventComm::PushSupplier_var supplier = RtecEventComm::PushSupplier::_narrow(supplier_obj.in()); // Connect to the EC. ACE_SupplierQOS_Factory qos; qos.insert (MY_SOURCE_ID, MY_EVENT_TYPE, 0, 1); consumer->connect_push_supplier (supplier.in (), qos.get_SupplierQOS ()); // Initialize the address server with the desired address. // This will be used by the sender object and the multicast // receiver. ACE_INET_Addr send_addr (port, address); PortableServer::Servant_var<SimpleAddressServer> addr_srv_impl = new SimpleAddressServer(send_addr); PortableServer::ObjectId_var addr_srv_oid = poa->activate_object(addr_srv_impl.in()); CORBA::Object_var addr_srv_obj = poa->id_to_reference(addr_srv_oid.in()); RtecUDPAdmin::AddrServer_var addr_srv = RtecUDPAdmin::AddrServer::_narrow(addr_srv_obj.in()); // Create and initialize the sender object PortableServer::Servant_var<TAO_ECG_UDP_Sender> sender = TAO_ECG_UDP_Sender::create(); TAO_ECG_UDP_Out_Endpoint endpoint; if (endpoint.dgram ().open (ACE_Addr::sap_any) == -1) { std::cerr << "Cannot open send endpoint" << std::endl; return 1; } // TAO_ECG_UDP_Sender::init() takes a TAO_ECG_Refcounted_Endpoint. // If we don't clone our endpoint and pass &endpoint, the sender will // attempt to delete endpoint during shutdown. TAO_ECG_Refcounted_Endpoint clone (new TAO_ECG_UDP_Out_Endpoint (endpoint)); sender->init (ec.in (), addr_srv.in (), clone); // Setup the subscription and connect to the EC ACE_ConsumerQOS_Factory cons_qos_fact; cons_qos_fact.start_disjunction_group (); cons_qos_fact.insert (ACE_ES_EVENT_SOURCE_ANY, ACE_ES_EVENT_ANY, 0); RtecEventChannelAdmin::ConsumerQOS sub = cons_qos_fact.get_ConsumerQOS (); sender->connect (sub); // Create and initialize the receiver PortableServer::Servant_var<TAO_ECG_UDP_Receiver> receiver = TAO_ECG_UDP_Receiver::create(); // TAO_ECG_UDP_Receiver::init() takes a TAO_ECG_Refcounted_Endpoint. // If we don't clone our endpoint and pass &endpoint, the receiver will // attempt to delete endpoint during shutdown. TAO_ECG_Refcounted_Endpoint clone2 (new TAO_ECG_UDP_Out_Endpoint (endpoint)); receiver->init (ec.in (), clone2, addr_srv.in ()); // Setup the registration and connect to the event channel ACE_SupplierQOS_Factory supp_qos_fact; supp_qos_fact.insert (MY_SOURCE_ID, MY_EVENT_TYPE, 0, 1); RtecEventChannelAdmin::SupplierQOS pub = supp_qos_fact.get_SupplierQOS (); receiver->connect (pub); // Create the appropriate event handler and register it with the reactor auto_ptr<ACE_Event_Handler> eh; if (mcast) { auto_ptr<TAO_ECG_Mcast_EH> mcast_eh(new TAO_ECG_Mcast_EH (receiver.in())); mcast_eh->reactor (orb->orb_core ()->reactor ()); mcast_eh->open (ec.in()); ACE_auto_ptr_reset(eh,mcast_eh.release()); //eh.reset(mcast_eh.release()); } else { auto_ptr<TAO_ECG_UDP_EH> udp_eh (new TAO_ECG_UDP_EH (receiver.in())); udp_eh->reactor (orb->orb_core ()->reactor ()); ACE_INET_Addr local_addr (listenport); if (udp_eh->open (local_addr) == -1) { std::cerr << "Cannot open EH" << std::endl; } ACE_auto_ptr_reset(eh,udp_eh.release()); //eh.reset(udp_eh.release()); } // Create an event (just a string in this case). const CORBA::String_var eventData = CORBA::string_dup (ACE_TEXT_ALWAYS_CHAR (ecname)); // Create an event set for one event RtecEventComm::EventSet event (1); event.length (1); // Initialize event header. event[0].header.source = MY_SOURCE_ID; event[0].header.ttl = 1; event[0].header.type = MY_EVENT_TYPE; // Initialize data fields in event. event[0].data.any_value <<= eventData; if (iorfile != 0) { CORBA::String_var str = orb->object_to_string( ec.in() ); std::ofstream iorFile( ACE_TEXT_ALWAYS_CHAR(iorfile) ); iorFile << str.in() << std::endl; iorFile.close(); } std::cout << "Starting main loop" << std::endl; const int EVENT_DELAY_MS = 10; while (1) { consumer->push (event); ACE_Time_Value tv(0, 1000 * EVENT_DELAY_MS); orb->run(tv); } orb->destroy(); return 0; } catch(const CORBA::Exception& exc) { std::cerr << "Caught CORBA::Exception" << std::endl << exc << std::endl; } return 1; }
int run_main (int, ACE_TCHAR *[]) { ACE_START_TEST (ACE_TEXT ("Bug_2820_Regression_Test")); int result = 0; auto_ptr<ACE_Reactor> reactor( new ACE_Reactor(new ACE_Select_Reactor, 1)); ACE_Event_Handler_var v( new Simple_Handler(reactor.get())); ACE_Event_Handler::Reference_Count pre_notify_count = v->add_reference(); int const notify_count = 4; for(int i = 0; i != notify_count; ++i) { reactor->notify(v.handler()); } ACE_Event_Handler::Reference_Count pos_notify_count = v->add_reference(); if(pos_notify_count != pre_notify_count + notify_count + 1) { result = -1; ACE_ERROR((LM_ERROR, ACE_TEXT("Reference count should increase by %d.") ACE_TEXT(" Initial count=%d, final count = %d\n"), notify_count, pre_notify_count, pos_notify_count)); } ACE_auto_ptr_reset(reactor, (ACE_Reactor*)0); // Reset the reactor in the event handler, since it is gone.p v->reactor(0); ACE_Event_Handler::Reference_Count pos_release_count = v->add_reference(); // Only our explicit calls to add_reference() should be reflected in // the refence_count... if (pos_release_count != pre_notify_count + 2) { result = -1; ACE_ERROR((LM_ERROR, ACE_TEXT("Reference count should have increased by 2.") ACE_TEXT(" Initial count=%d, final count = %d\n"), pre_notify_count, pos_release_count)); } ACE_DEBUG ((LM_INFO, ACE_TEXT("Ref count results. pre_notify refcount=%d,") ACE_TEXT(" pos_notify=%d, pos_delete=%d\n"), pre_notify_count, pos_notify_count, pos_release_count)); // Remove a reference for each time we explicitly increased it. v->remove_reference(); v->remove_reference(); ACE_Event_Handler::Reference_Count pos_remove_count = v->remove_reference(); ACE_DEBUG ((LM_INFO, ACE_TEXT("Ref count results. pre_notify refcount=%d,") ACE_TEXT(" pos_notify=%d, pos_delete=%d, pos_remove=%d\n"), pre_notify_count, pos_notify_count, pos_release_count, pos_remove_count)); ACE_END_TEST; return result; }
RtecEventChannelAdmin::EventChannel_ptr get_event_channel(int argc, ACE_TCHAR** argv) { FtRtecEventChannelAdmin::EventChannel_var channel; ACE_Get_Opt get_opt (argc, argv, ACE_TEXT("hi:nt:?")); int opt; int use_gateway = 1; while ((opt = get_opt ()) != EOF) { switch (opt) { case 'i': { CORBA::Object_var obj = orb->string_to_object(get_opt.opt_arg ()); channel = FtRtecEventChannelAdmin::EventChannel::_narrow(obj.in()); } break; case 'n': use_gateway = 0; break; case 't': timer_interval.set(ACE_OS::atof(get_opt.opt_arg ())); case 'h': case '?': ACE_DEBUG((LM_DEBUG, ACE_TEXT("Usage: %s ") ACE_TEXT("-i ftrt_eventchannel_ior\n") ACE_TEXT("-n do not use gateway\n") ACE_TEXT("-t time Time interval in seconds between events (default 1.0)\n") ACE_TEXT("\n"), argv[0])); return 0; } } if (CORBA::is_nil(channel.in())) { /// Find the FTRTEC from the Naming Service CosNaming::Name name(1); name.length(1); name[0].id = CORBA::string_dup("FT_EventService"); CosNaming::NamingContext_var naming_context = resolve_init<CosNaming::NamingContext>(orb.in(), "NameService"); channel = resolve<FtRtecEventChannelAdmin::EventChannel> (naming_context.in (), name); } if (use_gateway) { // use local gateway to communicate with FTRTEC ACE_auto_ptr_reset (gateway, new TAO_FTRTEC::FTEC_Gateway (orb.in (), channel.in ())); return gateway->_this (); } else return channel._retn (); }
int DllOrb::init (int argc, ACE_TCHAR *argv[]) { int threadCnt = 1; try { ACE_Arg_Shifter as (argc, argv); const ACE_TCHAR *currentArg = 0; while (as.is_anything_left ()) { if (0 != (currentArg = as.get_the_parameter (ACE_TEXT ("-NumThreads")))) { int num = ACE_OS::atoi (currentArg); if (num >= 1) threadCnt = num; as.consume_arg (); } else as.ignore_arg (); } // Initialize the ORB mv_orb_ = CORBA::ORB_init (argc, argv); if (CORBA::is_nil (mv_orb_.in ())) { ACE_DEBUG ((LM_ERROR, ACE_TEXT ("nil ORB\n"))); return -1; } CORBA::Object_var v_poa = mv_orb_->resolve_initial_references ("RootPOA"); mv_rootPOA_ = PortableServer::POA::_narrow (v_poa.in ()); if (CORBA::is_nil (mv_rootPOA_.in ())) { ACE_DEBUG ((LM_ERROR, ACE_TEXT ("nil RootPOA\n"))); return -1; } mv_poaManager_ = mv_rootPOA_->the_POAManager (); if (CORBA::is_nil (mv_poaManager_.in ())) { ACE_DEBUG ((LM_ERROR, ACE_TEXT ("nil POAManager\n"))); return -1; } mv_poaManager_->activate (); } catch (...) { ACE_DEBUG ((LM_ERROR, ACE_TEXT ("ERROR: exception\n"))); return -1; } ACE_auto_ptr_reset (ma_barrier_, new ACE_Thread_Barrier (threadCnt + 1)); this->activate( THR_NEW_LWP|THR_JOINABLE|THR_INHERIT_SCHED, threadCnt ); ACE_DEBUG ((LM_INFO, ACE_TEXT ("init mp_barrier->wait() ...\n"))); ma_barrier_->wait(); ACE_DEBUG ((LM_INFO, ACE_TEXT ("init mp_barrier->wait() done\n"))); return 0; }
void TAO_FTEC_Group_Manager::add_member ( const FTRT::ManagerInfo & info, CORBA::ULong object_group_ref_version) { TAO_FTRTEC::Log(1, ACE_TEXT("add_member location = <%s>\n"), (const char*)info.the_location[0].id); auto_ptr<TAO_FTEC_Group_Manager_Impl> new_impl(new TAO_FTEC_Group_Manager_Impl); new_impl->my_position = impl_->my_position; size_t pos = impl_->info_list.length(); new_impl->info_list.length(pos+1); for (size_t i = 0; i < pos; ++i) { new_impl->info_list[i] = impl_->info_list[i]; } new_impl->info_list[pos] = info; GroupInfoPublisherBase* publisher = GroupInfoPublisher::instance(); GroupInfoPublisherBase::Info_ptr group_info ( publisher->setup_info(new_impl->info_list, new_impl->my_position, object_group_ref_version)); int last_one = (impl_->my_position == impl_->info_list.length()-1); if (!last_one) { // I am not the last of replica, tell my successor that // a new member has joined in. try{ FTRTEC::Replication_Service::instance()->add_member(info, object_group_ref_version); } catch (const CORBA::Exception&){ // Unable to send request to all the successors. // Now this node become the last replica of the object group. // update the info list again new_impl->info_list.length(new_impl->my_position+2); new_impl->info_list[new_impl->my_position+1] = info; /// group_info = publisher->set_info(..) should be enough. /// However, GCC 2.96 is not happy with that. GroupInfoPublisherBase::Info_ptr group_info1 ( publisher->setup_info(new_impl->info_list, new_impl->my_position, object_group_ref_version)); ACE_auto_ptr_reset(group_info, group_info1.release()); last_one = true; } } if (last_one) { // this is the last replica in the list // synchornize the state with the newly joined replica. FtRtecEventChannelAdmin::EventChannelState state; get_state(state); TAO_OutputCDR cdr; cdr << state; FTRT::State s; if (cdr.begin()->cont()) { ACE_Message_Block* blk; ACE_NEW_THROW_EX(blk, ACE_Message_Block, CORBA::NO_MEMORY()); ACE_CDR::consolidate(blk, cdr.begin()); #if (TAO_NO_COPY_OCTET_SEQUENCES == 1) s.replace(blk->length(), blk); #else // If the replace method is not available, we will need // to do the copy manually. First, set the octet sequence length. CORBA::ULong length = blk->length (); s.length (length); // Now copy over each byte. char* base = blk->data_block ()->base (); for(CORBA::ULong i = 0; i < length; i++) { s[i] = base[i]; } #endif /* TAO_NO_COPY_OCTET_SEQUENCES == 1 */ blk->release(); } else { #if (TAO_NO_COPY_OCTET_SEQUENCES == 1) s.replace(cdr.begin()->length(), cdr.begin()); #else // If the replace method is not available, we will need // to do the copy manually. First, set the octet sequence length. CORBA::ULong length = cdr.begin ()->length (); s.length (length); // Now copy over each byte. char* base = cdr.begin()->data_block ()->base (); for(CORBA::ULong i = 0; i < length; i++) { s[i] = base[i]; } #endif /* TAO_NO_COPY_OCTET_SEQUENCES == 1 */ } TAO_FTRTEC::Log(2, ACE_TEXT("Setting state\n")); info.ior->set_state(s); info.ior->create_group(new_impl->info_list, object_group_ref_version); TAO_FTRTEC::Log(2, ACE_TEXT("After create_group\n")); } // commit the changes IOGR_Maker::instance()->set_ref_version( object_group_ref_version ); publisher->update_info(group_info); delete impl_; impl_ = new_impl.release(); }