int FT_EventService::report_factory(CORBA::ORB_ptr orb, FtRtecEventChannelAdmin::EventChannel_ptr ec) { try{ char* addr = ACE_OS::getenv("EventChannelFactoryAddr"); if (addr != 0) { // instaniated by object factory, report my ior back to the factory ACE_INET_Addr factory_addr(addr); ACE_SOCK_Connector connector; ACE_SOCK_Stream stream; ORBSVCS_DEBUG((LM_DEBUG,"connecting to %s\n",addr)); if (connector.connect(stream, factory_addr) == -1) ORBSVCS_ERROR_RETURN((LM_ERROR, "(%P|%t) Invalid Factory Address\n"), -1); ORBSVCS_DEBUG((LM_DEBUG,"Factory connected\n")); CORBA::String_var my_ior_string = orb->object_to_string(ec); int len = ACE_OS::strlen(my_ior_string.in()) ; if (stream.send_n(my_ior_string.in(), len) != len) ORBSVCS_ERROR_RETURN((LM_ERROR, "(%P|%t) IOR Transmission Error\n"), -1); stream.close(); } } catch (...){ return -1; } return 0; }
int make_ior (CORBA::ORB_ptr orb, PortableServer::POA_ptr poa, Hello * servant, const ACE_TCHAR *ior_file) { CORBA::String_var poa_name = poa->the_name(); ACE_DEBUG ((LM_DEBUG, "Creating IOR from %C\n", poa_name.in())); PortableServer::ObjectId_var oid = poa->activate_object (servant); CORBA::Object_var o = poa->id_to_reference (oid.in ()); if (host_form == from_hostname || host_form == use_localhost) { CORBA::String_var ior = orb->object_to_string (o.in ()); FILE *output_file= ACE_OS::fopen (ior_file, "w"); if (output_file == 0) ACE_ERROR_RETURN ((LM_ERROR, "Cannot open output file %s for writing IOR: %C", ior_file, ior.in ()), 1); ACE_OS::fprintf (output_file, "%s", ior.in ()); ACE_OS::fclose (output_file); } return 0; }
int write_ior_to_file (CORBA::ORB_ptr orb, test_ptr test) { CORBA::String_var ior = orb->object_to_string (test); char filename[BUFSIZ]; ACE_OS::sprintf (filename, "%s_%d", ACE_TEXT_ALWAYS_CHAR (ior_output_file), ior_count++); FILE *output_file = ACE_OS::fopen (filename, "w"); if (output_file == 0) ACE_ERROR_RETURN ((LM_ERROR, "Cannot open output file for writing IOR: %s", filename), -1); ACE_OS::fprintf (output_file, "%s", ior.in ()); ACE_OS::fclose (output_file); return 0; }
int TAO_Naming_Server::init (CORBA::ORB_ptr orb, PortableServer::POA_ptr poa, size_t context_size, ACE_Time_Value *timeout, bool resolve_for_existing_naming_service, const ACE_TCHAR *persistence_location, void *base_addr, int enable_multicast, int use_storable_context, int round_trip_timeout, int use_round_trip_timeout) { if (resolve_for_existing_naming_service) { try { // Try to find an existing Naming Service. CORBA::Object_var naming_obj = orb->resolve_initial_references ("NameService", timeout); if (!CORBA::is_nil (naming_obj.in ())) { // // Success in finding a Naming Service. // if (TAO_debug_level > 0) ORBSVCS_DEBUG ((LM_DEBUG, "\nNameService found!\n")); this->naming_context_ = CosNaming::NamingContext::_narrow (naming_obj.in ()); this->naming_service_ior_ = orb->object_to_string (naming_obj.in ()); return 0; } } catch (const CORBA::Exception& ex) { ex._tao_print_exception ("TAO_Naming_Server::init"); } } if (TAO_debug_level > 0) ORBSVCS_DEBUG ((LM_DEBUG, "\nWe'll become a NameService\n")); // Become a Naming Service. return this->init_new_naming (orb, poa, persistence_location, base_addr, context_size, enable_multicast, use_storable_context, round_trip_timeout, use_round_trip_timeout); }
int create_object (PortableServer::POA_ptr poa, CORBA::ORB_ptr orb, Test_i *server_impl, const ACE_TCHAR *filename) { // Register with poa. PortableServer::ObjectId_var id = poa->activate_object (server_impl); CORBA::Object_var server = poa->id_to_reference (id.in ()); // Print out the IOR. CORBA::String_var ior = orb->object_to_string (server.in ()); ACE_DEBUG ((LM_DEBUG, "<%C>\n\n", ior.in ())); // Print ior to the file. if (filename != 0) { FILE *output_file= ACE_OS::fopen (filename, "w"); if (output_file == 0) ACE_ERROR_RETURN ((LM_ERROR, "Cannot open output file for writing IOR: %s", filename), -1); ACE_OS::fprintf (output_file, "%s", ior.in ()); ACE_OS::fclose (output_file); } return 0; }
int write_ior_to_file (const ACE_TCHAR *ior_file, CORBA::ORB_ptr orb, CORBA::Object_ptr object) { CORBA::String_var ior = orb->object_to_string (object); FILE *output_file = ACE_OS::fopen (ior_file, "w"); if (output_file == 0) ACE_ERROR_RETURN ((LM_ERROR, "Cannot open output file for writing IOR: %s", ior_file), -1); ACE_OS::fprintf (output_file, "%s", ior.in ()); ACE_OS::fclose (output_file); return 0; }
int run(CORBA::ORB_ptr orb, int argc, char* argv[]) { // // Resolve Root POA // CORBA::Object_var poaObj = orb -> resolve_initial_references("RootPOA"); PortableServer::POA_var rootPOA = PortableServer::POA::_narrow(poaObj); // // Get a reference to the POA manager // PortableServer::POAManager_var manager = rootPOA -> the_POAManager(); // // Create implementation object // Testing_impl* testingImpl = new Testing_impl(rootPOA); PortableServer::ServantBase_var servant = testingImpl; Testing_var testing = testingImpl->_this(); // // Save reference // CORBA::String_var s = orb->object_to_string(testing); const char* refFile = "testing.ref"; ofstream out(refFile); if(out.fail()) { cerr << argv[0] << ": can't open `" << refFile << "': " << strerror(errno) << endl; return EXIT_FAILURE; } out << s << endl; out.close(); // // Run implementation // manager->activate(); orb->run(); return EXIT_SUCCESS; }
void AppHelper::ref_to_file(CORBA::ORB_ptr orb, CORBA::Object_ptr obj, const ACE_TCHAR* filename) { CORBA::String_var ior = orb->object_to_string(obj); FILE* ior_file = ACE_OS::fopen(filename, ACE_TEXT("w")); if (ior_file == 0) { ACE_ERROR((LM_ERROR, "(%P|%t) Cannot open output file [%s] to write IOR.\n", filename)); throw TestAppException(); } ACE_OS::fprintf(ior_file, "%s", ior.in()); ACE_OS::fclose(ior_file); }
void create_object (PortableServer::POA_ptr poa, CORBA::ORB_ptr orb, PortableServer::Servant servant, const ACE_TCHAR *filename) { // Register with poa. PortableServer::ObjectId_var id = poa->activate_object (servant); CORBA::Object_var object = poa->id_to_reference (id.in ()); CORBA::String_var ior = orb->object_to_string (object.in ()); FILE *output_file= ACE_OS::fopen (filename, "w"); ACE_OS::fprintf (output_file, "%s", ior.in ()); ACE_OS::fclose (output_file); }
static void write_iors_to_file (CORBA::Object_ptr object, CORBA::ORB_ptr orb, const ACE_TCHAR *filename) { FILE *file = ACE_OS::fopen (filename, "w"); ACE_ASSERT (file != 0); CORBA::String_var ior = orb->object_to_string (object); u_int result = 0; result = ACE_OS::fprintf (file, "%s", ior.in ()); ACE_ASSERT (result == ACE_OS::strlen (ior.in ())); ACE_UNUSED_ARG (result); ACE_OS::fclose (file); }
static bool marshaled_equal_to_other (CORBA::ORB_ptr orb, CORBA::Object_ptr obj, TAO_MProfile *other_mprofile) { CORBA::String_var str = orb->object_to_string (obj); CORBA::Object_var obj_copy = orb->string_to_object (str.in ()); TAO_Stub *stub_copy = obj_copy->_stubobj (); TAO_MProfile *copy_mprofile = &(stub_copy->base_profiles ()); if ( copy_mprofile->size() != other_mprofile->size()) return false; for (size_t i=0; i<copy_mprofile->size(); ++i) { TAO_Profile *copy_profile = copy_mprofile->get_profile (i); TAO_Profile *other_profile = other_mprofile->get_profile (i); if ( ! equal_endpoint (copy_profile, other_profile) ) return false; } return true; }
int ACE_TMAIN (int argc, ACE_TCHAR *argv[]) { ACE_Auto_Ptr< sig_i > sig_impl; int status = 0; try { Supplier_Client client; status = client.init (argc, argv); if (status == 0) { CosNotifyChannelAdmin::EventChannel_var ec = client.create_event_channel ("MyEventChannel", 0); CORBA::ORB_ptr orb = client.orb (); sig_impl.reset( new sig_i( orb ) ); sig_var sig = sig_impl->_this (); CORBA::String_var ior = orb->object_to_string (sig.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 %s for " "writing IOR: %C", ior_output_file, ior.in ()), 1); ACE_OS::fprintf (output_file, "%s", ior.in ()); ACE_OS::fclose (output_file); } CosNotifyChannelAdmin::SupplierAdmin_var admin = create_supplieradmin (ec.in ()); if (!CORBA::is_nil (admin.in ())) { create_suppliers(admin.in (), client.root_poa ()); sig_impl->wait_for_startup(); ACE_DEBUG((LM_DEBUG, " 1 supplier sending %d batches of %d events...\n", num_batches, PER_BATCH)); for (int i = 0; i < num_batches; ++i) { ACE_DEBUG((LM_DEBUG, "+")); SendEvents (i); } ACE_DEBUG((LM_DEBUG, "\nSupplier waiting for consumer completion...\n")); sig_impl->wait_for_completion(); ACE_DEBUG((LM_DEBUG, "\nSupplier finished.\n")); ACE_OS::unlink (ior_output_file); ec->destroy(); } } } catch (const CORBA::Exception& e) { e._tao_print_exception ("Error: Supplier exception: "); status = 1; } return status; }
int ACE_TMAIN (int argc, ACE_TCHAR *argv[]) { ACE_Auto_Ptr< sig_i > sig_impl; try { Supplier_Client client; int status = client.init (argc, argv); ACE_UNUSED_ARG(status); ACE_ASSERT(status == 0); CosNotifyChannelAdmin::EventChannel_var ec = client.create_event_channel ("MyEventChannel", 0); CosNotification::QoSProperties qos (1); qos.length (1); qos[0].name = CORBA::string_dup (CosNotification::OrderPolicy); qos[0].value <<= order_policy; ec->set_qos (qos); CORBA::ORB_ptr orb = client.orb (); sig_impl.reset( new sig_i( orb ) ); sig_var sig = sig_impl->_this (); CORBA::String_var ior = orb->object_to_string (sig.in ()); 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 %s for " "writing IOR: %C", ior_output_file, ior.in ()), 1); ACE_OS::fprintf (output_file, "%s", ior.in ()); ACE_OS::fclose (output_file); } CosNotifyChannelAdmin::SupplierAdmin_var admin = create_supplieradmin (ec.in ()); ACE_ASSERT(!CORBA::is_nil (admin.in ())); create_suppliers (admin.in (), client.root_poa ()); sig_impl->wait_for_startup(); ACE_DEBUG((LM_DEBUG, "1 supplier sending %d events...\n", num_events)); for (int i = 0; i < num_events / BATCH_SIZE; ++i) { ACE_DEBUG((LM_DEBUG, "+")); SendBatch (i); } ACE_DEBUG((LM_DEBUG, "\nSupplier sent %d events.\n", num_events)); sig_impl->wait_for_completion(); ACE_OS::unlink (ior_output_file); supplier_1->disconnect(); ec->destroy(); return 0; } catch (const CORBA::Exception& e) { e._tao_print_exception ("Error: "); } return 1; }
int launch_plan (const Options &opts, DAnCE::Plan_Launcher_Base *pl_base, const ::Deployment::DeploymentPlan *plan, CORBA::ORB_ptr orb) { DANCE_TRACE ("launch_plan"); try { CORBA::Object_var app_mgr, app; CORBA::String_var uuid_safe (pl_base->launch_plan (*plan, app_mgr.out () , app.out ())); ACE_CString uuid = uuid_safe.in (); DANCE_DEBUG (DANCE_LOG_MAJOR_EVENT, (LM_NOTICE, DLINFO ACE_TEXT ("Plan_Launcher::launch_plan - ") ACE_TEXT ("Successfully deployed plan ") ACE_TEXT ("with UUID: <%C>\n"), uuid.c_str ())); if (!opts.output_) return 0; ACE_TString am_output, app_output; if (opts.output_prefix_) am_output = app_output = opts.output_prefix_; else am_output = app_output = ACE_TEXT_CHAR_TO_TCHAR (uuid.c_str ()); am_output += ACE_TEXT ("_AM.ior"); app_output += ACE_TEXT ("_APP.ior"); DANCE_DEBUG (DANCE_LOG_MINOR_EVENT, (LM_DEBUG, DLINFO ACE_TEXT ("Plan_Launcher::launch_plan - ") ACE_TEXT ("Writing Application Manager IOR to <%s>\n"), am_output.c_str ())); CORBA::String_var tmp = orb->object_to_string (app_mgr.in ()); write_IOR (am_output.c_str (), tmp.in ()); DANCE_DEBUG (DANCE_LOG_MINOR_EVENT, (LM_DEBUG, DLINFO ACE_TEXT ("Plan_Launcher::launch_plan - ") ACE_TEXT ("Writing Application IOR to <%s>\n"), am_output.c_str ())); tmp = orb->object_to_string (app.in ()); write_IOR (app_output.c_str (), tmp.in ()); } catch (const DAnCE::Deployment_Failure &ex) { if (!opts.quiet_) { DANCE_ERROR (DANCE_LOG_EMERGENCY, (LM_ERROR, DLINFO ACE_TEXT ("Plan_Launcher::launch_plan - ") ACE_TEXT ("Deployment failed, exception: %C\n"), ex.ex_.c_str ())); } return 1; } catch (const Deployment::PlanError &ex) { if (!opts.quiet_) { DANCE_ERROR (DANCE_LOG_EMERGENCY, (LM_ERROR, DLINFO ACE_TEXT ("Plan_Launcher::launch_plan - ") ACE_TEXT ("Caught PlanError exception: %C, %C\n"), ex.name.in (), ex.reason.in () )); } return 1; } catch (const Deployment::StartError &ex) { if (!opts.quiet_) { DANCE_ERROR (DANCE_LOG_EMERGENCY, (LM_ERROR, DLINFO ACE_TEXT ("Plan_Launcher::launch_plan - ") ACE_TEXT ("Caught PlanError exception: %C, %C\n"), ex.name.in (), ex.reason.in () )); } return 1; } catch (const Deployment::StopError &ex) { if (!opts.quiet_) { DANCE_ERROR (DANCE_LOG_EMERGENCY, (LM_ERROR, DLINFO ACE_TEXT ("Plan_Launcher::launch_plan - ") ACE_TEXT ("Caught PlanError exception: %C, %C\n"), ex.name.in (), ex.reason.in () )); } return 1; } catch (const CORBA::Exception &ex) { if (!opts.quiet_) { DANCE_ERROR (DANCE_LOG_EMERGENCY, (LM_ERROR, DLINFO ACE_TEXT ("Plan_Launcher::launch_plan - ") ACE_TEXT ("Deployment failed, caught CORBA exception %C\n"), ex._info ().c_str ())); } return 1; } catch (...) { if (!opts.quiet_) { DANCE_ERROR (DANCE_LOG_EMERGENCY, (LM_ERROR, DLINFO ACE_TEXT ("Plan_Launcher::launch_plan - ") ACE_TEXT ("Deployment failed, ") ACE_TEXT ("caught unknown C++ exception\n"))); } return 1; } return 0; }
CORBA::Object_ptr DAnCE_NodeManager_Module::init (CORBA::ORB_ptr orb, int argc, ACE_TCHAR *argv[]) { try { if (CORBA::is_nil(orb)) { DANCE_ERROR (DANCE_LOG_EMERGENCY, (LM_ERROR, DLINFO ACE_TEXT("DAnCE_NodeManager_Module::init - ") ACE_TEXT("Attempted to create Node Manager with a nil orb.\n"))); return CORBA::Object::_nil(); } if (CORBA::is_nil(this->orb_.in())) { DANCE_TRACE_LOG (DANCE_LOG_DETAILED_TRACE, (LM_TRACE, DLINFO ACE_TEXT("DAnCE_NodeManager_Module::init - ") ACE_TEXT("NM's orb is nil.\n"))); this->orb_ = CORBA::ORB::_duplicate (orb); } else if (ACE_OS::strcmp(orb->id(), this->orb_->id()) != 0) { DANCE_DEBUG (DANCE_LOG_DETAILED_TRACE, (LM_TRACE, DLINFO ACE_TEXT("DAnCE_NodeManager_Module::init - ") ACE_TEXT("Resetting NM's orb.\n"))); this->orb_ = CORBA::ORB::_duplicate (orb); this->domain_nc_ = CosNaming::NamingContext::_nil(); } if (!this->parse_args (argc, argv)) { DANCE_ERROR (DANCE_LOG_EMERGENCY, (LM_ERROR, DLINFO ACE_TEXT("DAnCE_NodeManager_Module::init - ") ACE_TEXT("Unable to parse the commandline arguments.\n"))); return CORBA::Object::_nil (); } this->register_value_factories (); this->create_poas (); if (this->options_.domain_nc_) { try { DANCE_TRACE_LOG (DANCE_LOG_TRACE, (LM_TRACE, DLINFO ACE_TEXT("DAnCE_NodeManager_Module::init - ") ACE_TEXT("Resolving DomainNC.\n"))); CORBA::Object_var domain_obj = this->orb_->string_to_object (this->options_.domain_nc_); if (!CORBA::is_nil (domain_obj.in ())) { this->domain_nc_ = CosNaming::NamingContext::_narrow (domain_obj.in()); if (CORBA::is_nil (this->domain_nc_.in ())) { DANCE_ERROR (DANCE_LOG_EMERGENCY, (LM_ERROR, DLINFO ACE_TEXT("DAnCE_NodeManager_Module::init - ") ACE_TEXT("Narrow to NamingContext return nil for DomainNC.\n"))); return CORBA::Object::_nil (); } } } catch (const CORBA::Exception&) { DANCE_ERROR (DANCE_LOG_WARNING, (LM_WARNING, DLINFO ACE_TEXT("DAnCE_NodeManager_Module::init - ") ACE_TEXT("DomainNC context not found!\n"))); } } DANCE_TRACE_LOG (DANCE_LOG_TRACE, (LM_TRACE, DLINFO ACE_TEXT("DAnCE_NodeManager_Module::init - ") ACE_TEXT("Resolving plan NS naming context.\n"))); CosNaming::NamingContext_var rebind_nc; if (this->options_.rebind_plan_ns_) { if (!this->options_.create_plan_ns_) { DANCE_ERROR (DANCE_LOG_EMERGENCY, (LM_ERROR, DLINFO ACE_TEXT ("DAnCE_NodeManager_Module::init - ") ACE_TEXT ("Rebind_plan_ns option is enabled but Create_plan_ns is not.\n"))); return CORBA::Object::_nil(); } CORBA::Object_var tmp_obj; if (0 != this->options_.rebind_plan_ns_ior_) { tmp_obj = orb->string_to_object (this->options_.rebind_plan_ns_ior_); rebind_nc = CosNaming::NamingContext::_narrow (tmp_obj); } else { if (CORBA::is_nil (this->domain_nc_.in ())) { DANCE_ERROR (DANCE_LOG_EMERGENCY, (LM_ERROR, DLINFO ACE_TEXT ("DAnCE_NodeManager_Module::init - ") ACE_TEXT ("The rebind plan is enabled but neither NC ") ACE_TEXT ("nor DomainNC are not supplied. No rebinding will be done.\n") ACE_TEXT ("Use the \"-rebind-plan-ns NC ior\" ") ACE_TEXT ("or \"-ORBInitRef DomainNC\" option.\n"))); return CORBA::Object::_nil (); } rebind_nc = CosNaming::NamingContext::_duplicate (this->domain_nc_.in ()); } } // Initialize IOR table CORBA::Object_var table_object = orb->resolve_initial_references ("IORTable"); IORTable::Table_var adapter = IORTable::Table::_narrow (table_object.in ()); if (CORBA::is_nil (adapter.in ())) { DANCE_ERROR (DANCE_LOG_EMERGENCY, (LM_ERROR, DLINFO ACE_TEXT ("DAnCE_NodeManager_Module::init - ") ACE_TEXT ("Unable to RIR the IORTable.\n"))); return CORBA::Object::_nil (); } // Creating in process nameservice CosNaming::NamingContext_var plan_nc; if (this->options_.create_plan_ns_) { DANCE_DEBUG (DANCE_LOG_TRACE, (LM_TRACE, DLINFO ACE_TEXT ("DAnCE_NodeManager_Module::init - ") ACE_TEXT ("Resolving plan-specific naming context.\n"))); CORBA::Object_var naming_obj; if (0 != this->options_.create_plan_ns_ior_) { naming_obj = orb->string_to_object (this->options_.create_plan_ns_ior_); plan_nc = CosNaming::NamingContext::_narrow (naming_obj.in()); if (CORBA::is_nil (plan_nc.in())) { DANCE_ERROR (DANCE_LOG_EMERGENCY, (LM_ERROR, DLINFO ACE_TEXT ("DAnCE_NodeManager_Module::init - ") ACE_TEXT ("Failed trying to narrow naming context ") ACE_TEXT ("for dance creating plan NC.\n") ACE_TEXT ("Use the \"--create-plan-ns NC ior\" ") ACE_TEXT ("or \"--process-ns\" option.\n"))); return CORBA::Object::_nil (); } } else if (this->options_.process_ns_) { naming_obj = orb->resolve_initial_references ("NameService"); if (0 != this->options_.process_ns_file_) { CORBA::String_var ior = orb->object_to_string (naming_obj.in ()); DAnCE::Node_Manager::write_IOR (this->options_.process_ns_file_, ior.in ()); } plan_nc = CosNaming::NamingContext::_narrow (naming_obj.in ()); if (CORBA::is_nil (plan_nc.in ())) { DANCE_ERROR (DANCE_LOG_EMERGENCY, (LM_ERROR, DLINFO ACE_TEXT ("DAnCE_NodeManager_Module::init - ") ACE_TEXT ("Fails trying to narrow naming context ") ACE_TEXT ("for dance creating plan NC.\n") ACE_TEXT ("Use the \"--create-plan-ns NC ior\" ") ACE_TEXT ("or \"--process-ns\" option.\n"))); return CORBA::Object::_nil (); } } else if (CORBA::is_nil (this->domain_nc_.in ())) { DANCE_ERROR (DANCE_LOG_EMERGENCY, (LM_ERROR, DLINFO ACE_TEXT ("DAnCE_NodeManager_Module::init - ") ACE_TEXT ("The create plan is enabled but neither NC ior ") ACE_TEXT ("nor --process-ns or DomainNC option are not supplied.\n") ACE_TEXT ("Use the \"--create-plan-ns NC ior\", \"--process-ns\" ") ACE_TEXT ("or \"-ORBInitRef DomainNC\" option.\n"))); return CORBA::Object::_nil (); } else { plan_nc = CosNaming::NamingContext::_duplicate (this->domain_nc_.in ()); } } // Parsing Node name and node manager ior file name ACE_TString node_name = this->options_.node_managers_[0].c_str (); ACE_TString node_file; size_t npos = node_name.find ('='); if (ACE_CString::npos != npos) { node_file = node_name.substring (npos + 1, node_name.length() - npos + 1); node_name = node_name.substring (0, npos); } // load service modules for artifact installation service load_artifact_installation_modules (argc, argv); // Creating in process artifact installation service DAnCE::ArtifactInstallation_Impl* installer = 0; ACE_NEW_RETURN (installer, DAnCE::ArtifactInstallation_Impl (), CORBA::Object::_nil ()); PortableServer::Servant_var<DAnCE::ArtifactInstallation_Impl> safe_installer (installer); ACE_CString installer_oid_str = ACE_TEXT_ALWAYS_CHAR ((node_name + ACE_TEXT (".ArtifactInstaller")).c_str ()); // Registering servant in poa PortableServer::ObjectId_var installer_oid = PortableServer::string_to_ObjectId (installer_oid_str.c_str()); this->nm_poa_->activate_object_with_id (installer_oid, safe_installer._retn ()); CORBA::Object_var installer_object = this->nm_poa_->id_to_reference (installer_oid.in ()); this->installer_ = DAnCE::ArtifactInstallation::_narrow (installer_object.in ()); // Getting node manager ior CORBA::String_var installer_ior = orb->object_to_string (installer_object.in ()); // Binding ior to IOR Table adapter->bind (installer_oid_str.c_str (), installer_ior.in ()); // Make sure that we have only one Node Manager if (this->options_.node_managers_.size () != 1) { DANCE_ERROR (DANCE_LOG_EMERGENCY, (LM_ERROR, DLINFO ACE_TEXT ("DAnCE_NodeManager_Module::init - ") ACE_TEXT ("For now only one node manager creation is supported.\n"))); return CORBA::Object::_nil (); } DANCE_DEBUG (DANCE_LOG_MINOR_EVENT, (LM_DEBUG, DLINFO ACE_TEXT ("DAnCE_NodeManager_Module::init - ") ACE_TEXT ("DAnCE_NodeManager::run_main - creating NodeManager for node %C\n"), this->options_.node_managers_[0].c_str())); //Creating node manager servant DAnCE::NodeManager_Impl * nm = 0; if (this->nm_map_.find (node_name, nm) == -1) { DANCE_DEBUG (DANCE_LOG_EVENT_TRACE, (LM_TRACE, DLINFO ACE_TEXT ("DAnCE_NodeManager_Module::init - ") ACE_TEXT ("Allocating new NodeManager servant instance for NodeManager\n"))); int size = 64; DAnCE::Utility::PROPERTY_MAP properties (size); this->create_nm_properties (properties); ACE_NEW_RETURN (nm, DAnCE::NodeManager_Impl (orb, this->root_poa_.in (), this->installer_.in (), ACE_TEXT_ALWAYS_CHAR (node_name.c_str()), this->options_.node_config_, properties), CORBA::Object::_nil ()); DANCE_TRACE_LOG (DANCE_LOG_TRACE, (LM_TRACE, DLINFO ACE_TEXT ("DAnCE_NodeManager_Module::init - ") ACE_TEXT ("New NodeManager servant instance for NodeManager allocated.\n"))); this->nm_map_.bind (node_name, nm); } ACE_CString node_manager_oid = ACE_TEXT_ALWAYS_CHAR ((node_name + ACE_TEXT (".NodeManager")).c_str ()); // Registering servant in poa PortableServer::ObjectId_var oid = PortableServer::string_to_ObjectId (node_manager_oid.c_str()); this->nm_poa_->activate_object_with_id (oid, nm); // Getting node manager ior CORBA::Object_var nm_obj = this->nm_poa_->id_to_reference (oid.in ()); CORBA::String_var ior = orb->object_to_string (nm_obj.in ()); // Binding ior to IOR Table adapter->bind (node_manager_oid.c_str (), ior.in ()); // Binding node manager to DomainNC if (!CORBA::is_nil (this->domain_nc_.in ())) { DANCE_DEBUG (DANCE_LOG_MAJOR_DEBUG_INFO, (LM_TRACE, DLINFO ACE_TEXT ("DAnCE_NodeManager_Module::init - ") ACE_TEXT ("Registering NM in NC as \"%C.NodeManager\".\n"), node_name.c_str ())); CosNaming::Name name (1); name.length (1); name[0].id = CORBA::string_dup (ACE_TEXT_ALWAYS_CHAR (node_name.c_str ())); name[0].kind = CORBA::string_dup ("NodeManager"); this->domain_nc_->rebind (name, nm_obj.in ()); } // Writing ior to file if (0 != node_file.length ()) { DANCE_DEBUG (DANCE_LOG_EVENT_TRACE, (LM_TRACE, DLINFO ACE_TEXT ("DAnCE_NodeManager_Module::init - ") ACE_TEXT ("Writing node IOR %C to file %C.\n"), node_file.c_str (), ior.in ())); if (!DAnCE::Node_Manager::write_IOR (node_file.c_str (), ior.in ())) DANCE_ERROR (DANCE_LOG_NONFATAL_ERROR, (LM_ERROR, DLINFO ACE_TEXT ("DAnCE_NodeManager_Module::init - ") ACE_TEXT ("Error: Unable to write IOR to file %C\n"), node_file.c_str ())); } // Activate POA manager PortableServer::POAManager_var mgr = this->root_poa_->the_POAManager (); mgr->activate (); // Finishing Deployment part DANCE_DEBUG (DANCE_LOG_MAJOR_EVENT, (LM_NOTICE, DLINFO ACE_TEXT ("DAnCE_NodeManager_Module::init - ") ACE_TEXT ("DAnCE_NodeManager is running...\n"))); DANCE_DEBUG (DANCE_LOG_MAJOR_DEBUG_INFO, (LM_DEBUG, DLINFO ACE_TEXT ("DAnCE_NodeManager_Module::init - ") ACE_TEXT ("NodeManager IOR: %C\n"), ior.in ())); return nm_obj._retn (); } catch (const CORBA::Exception& ex) { ex._tao_print_exception ("DAnCE_NodeManager::main\t\n"); return CORBA::Object::_nil (); } }
void test_poas (CORBA::ORB_ptr orb, PortableServer::POA_ptr root_poa, PortableServer::POA_ptr first_poa, PortableServer::POA_ptr second_poa, PortableServer::POA_ptr third_poa, PortableServer::POA_ptr forth_poa, int perform_deactivation_test) { { test_i servant (root_poa); CORBA::Object_var obj = root_poa->create_reference ("IDL:test:1.0"); CORBA::String_var string = orb->object_to_string (obj.in ()); ACE_DEBUG ((LM_DEBUG, "%C\n", string.in ())); PortableServer::ObjectId_var id = root_poa->reference_to_id (obj.in ()); root_poa->activate_object_with_id (id.in (), &servant); obj = root_poa->id_to_reference (id.in ()); string = orb->object_to_string (obj.in ()); ACE_DEBUG ((LM_DEBUG, "%C\n", string.in ())); PortableServer::ServantBase_var servant_from_reference = root_poa->reference_to_servant (obj.in ()); PortableServer::ServantBase_var servant_from_id = root_poa->id_to_servant (id.in ()); if (servant_from_reference.in () != servant_from_id.in () || servant_from_reference.in () != &servant) { ACE_ERROR ((LM_ERROR, "Mismatched servant_from_reference, " "servant_from_id and &servant\n")); } obj = root_poa->servant_to_reference (&servant); string = orb->object_to_string (obj.in ()); ACE_DEBUG ((LM_DEBUG, "%C\n", string.in ())); obj = servant._this (); string = orb->object_to_string (obj.in ()); ACE_DEBUG ((LM_DEBUG, "%C\n", string.in ())); PortableServer::ObjectId_var id_from_servant = root_poa->servant_to_id (&servant); ACE_ASSERT (id_from_servant.in () == id.in ()); root_poa->deactivate_object (id.in ()); if (perform_deactivation_test) { root_poa->activate_object_with_id (id.in (), &servant); servant_from_reference = root_poa->reference_to_servant (obj.in ()); ACE_ASSERT (servant_from_reference.in () == &servant); root_poa->deactivate_object (id.in ()); } } { test_i servant (root_poa); PortableServer::ObjectId_var id = root_poa->activate_object (&servant); CORBA::Object_var obj = root_poa->id_to_reference (id.in ()); CORBA::String_var string = orb->object_to_string (obj.in ()); ACE_DEBUG ((LM_DEBUG, "%C\n", string.in ())); obj = root_poa->create_reference_with_id (id.in (), "IDL:test:1.0"); string = orb->object_to_string (obj.in ()); ACE_DEBUG ((LM_DEBUG, "%C\n", string.in ())); root_poa->deactivate_object (id.in ()); } { test_i servant (first_poa); CORBA::Object_var obj = first_poa->create_reference ("IDL:test:1.0"); CORBA::String_var string = orb->object_to_string (obj.in ()); ACE_DEBUG ((LM_DEBUG, "%C\n", string.in ())); PortableServer::ObjectId_var id = first_poa->reference_to_id (obj.in ()); first_poa->activate_object_with_id (id.in (), &servant); obj = first_poa->id_to_reference (id.in ()); string = orb->object_to_string (obj.in ()); ACE_DEBUG ((LM_DEBUG, "%C\n", string.in ())); PortableServer::ServantBase_var servant_from_reference = first_poa->reference_to_servant (obj.in ()); PortableServer::ServantBase_var servant_from_id = first_poa->id_to_servant (id.in ()); if (servant_from_reference .in () != servant_from_id.in () || servant_from_reference.in () != &servant) { ACE_ERROR ((LM_ERROR, "Mismatched servant_from_reference, " "servant_from_id and &servant\n")); } first_poa->deactivate_object (id.in ()); if (perform_deactivation_test) { first_poa->activate_object_with_id (id.in (), &servant); servant_from_reference = first_poa->reference_to_servant (obj.in ()); ACE_ASSERT (servant_from_reference.in () == &servant); first_poa->deactivate_object (id.in ()); } } { test_i servant (first_poa); PortableServer::ObjectId_var id = first_poa->activate_object (&servant); CORBA::Object_var obj = first_poa->id_to_reference (id.in ()); CORBA::String_var string = orb->object_to_string (obj.in ()); ACE_DEBUG ((LM_DEBUG, "%C\n", string.in ())); obj = first_poa->create_reference_with_id (id.in (), "IDL:test:1.0"); string = orb->object_to_string (obj.in ()); ACE_DEBUG ((LM_DEBUG, "%C\n", string.in ())); first_poa->deactivate_object (id.in ()); } { test_i servant (second_poa); CORBA::Object_var obj = second_poa->create_reference ("IDL:test:1.0"); CORBA::String_var string = orb->object_to_string (obj.in ()); ACE_DEBUG ((LM_DEBUG, "%C\n", string.in ())); PortableServer::ObjectId_var id = second_poa->reference_to_id (obj.in ()); second_poa->activate_object_with_id (id.in (), &servant); obj = second_poa->id_to_reference (id.in ()); string = orb->object_to_string (obj.in ()); ACE_DEBUG ((LM_DEBUG, "%C\n", string.in ())); PortableServer::ServantBase_var servant_from_reference = second_poa->reference_to_servant (obj.in ()); PortableServer::ServantBase_var servant_from_id = second_poa->id_to_servant (id.in ()); if (servant_from_reference.in () != servant_from_id.in () || servant_from_reference.in () != &servant) { ACE_ERROR ((LM_ERROR, "Mismatched servant_from_reference, " "servant_from_id and &servant\n")); } obj = second_poa->servant_to_reference (&servant); string = orb->object_to_string (obj.in ()); ACE_DEBUG ((LM_DEBUG, "%C\n", string.in ())); obj = servant._this (); string = orb->object_to_string (obj.in ()); ACE_DEBUG ((LM_DEBUG, "%C\n", string.in ())); PortableServer::ObjectId_var id_from_servant = second_poa->servant_to_id (&servant); ACE_ASSERT (id_from_servant.in () == id.in ()); second_poa->deactivate_object (id.in ()); if (perform_deactivation_test) { second_poa->activate_object_with_id (id.in (), &servant); servant_from_reference = second_poa->reference_to_servant (obj.in ()); ACE_ASSERT (servant_from_reference.in () == &servant); second_poa->deactivate_object (id.in ()); } } { test_i servant (second_poa); PortableServer::ObjectId_var id = second_poa->activate_object (&servant); CORBA::Object_var obj = second_poa->id_to_reference (id.in ()); CORBA::String_var string = orb->object_to_string (obj.in ()); ACE_DEBUG ((LM_DEBUG, "%C\n", string.in ())); obj = second_poa->create_reference_with_id (id.in (), "IDL:test:1.0"); string = orb->object_to_string (obj.in ()); ACE_DEBUG ((LM_DEBUG, "%C\n", string.in ())); second_poa->deactivate_object (id.in ()); } { test_i servant (third_poa); PortableServer::ObjectId_var id = PortableServer::string_to_ObjectId ("hello"); CORBA::Object_var obj = third_poa->create_reference_with_id (id.in (), "IDL:test:1.0"); CORBA::String_var string = orb->object_to_string (obj.in ()); ACE_DEBUG ((LM_DEBUG, "%C\n", string.in ())); PortableServer::ObjectId_var id_from_reference = third_poa->reference_to_id (obj.in ()); string = PortableServer::ObjectId_to_string (id_from_reference.in ()); ACE_DEBUG ((LM_DEBUG, "%C\n", string.in ())); ACE_ASSERT (id_from_reference.in () == id.in ()); third_poa->activate_object_with_id (id.in (), &servant); obj = third_poa->id_to_reference (id.in ()); string = orb->object_to_string (obj.in ()); ACE_DEBUG ((LM_DEBUG, "%C\n", string.in ())); PortableServer::ServantBase_var servant_from_reference = third_poa->reference_to_servant (obj.in ()); PortableServer::ServantBase_var servant_from_id = third_poa->id_to_servant (id.in ()); if (servant_from_reference.in () != servant_from_id.in () || servant_from_reference.in () != &servant) { ACE_ERROR ((LM_ERROR, "Mismatched servant_from_reference, " "servant_from_id and &servant\n")); } obj = third_poa->servant_to_reference (&servant); string = orb->object_to_string (obj.in ()); ACE_DEBUG ((LM_DEBUG, "%C\n", string.in ())); obj = servant._this (); string = orb->object_to_string (obj.in ()); ACE_DEBUG ((LM_DEBUG, "%C\n", string.in ())); PortableServer::ObjectId_var id_from_servant = third_poa->servant_to_id (&servant); string = PortableServer::ObjectId_to_string (id_from_servant.in ()); ACE_DEBUG ((LM_DEBUG, "%C\n", string.in ())); ACE_ASSERT (id_from_servant.in () == id.in ()); third_poa->deactivate_object (id.in ()); if (perform_deactivation_test) { third_poa->activate_object_with_id (id.in (), &servant); servant_from_reference = third_poa->reference_to_servant (obj.in ()); ACE_ASSERT (servant_from_reference.in () == &servant); third_poa->deactivate_object (id.in ()); } } { test_i servant (forth_poa); PortableServer::ObjectId_var id = PortableServer::string_to_ObjectId ("hello"); CORBA::Object_var obj = forth_poa->create_reference_with_id (id.in (), "IDL:test:1.0"); CORBA::String_var string = orb->object_to_string (obj.in ()); ACE_DEBUG ((LM_DEBUG, "%C\n", string.in ())); PortableServer::ObjectId_var id_from_reference = forth_poa->reference_to_id (obj.in ()); string = PortableServer::ObjectId_to_string (id_from_reference.in ()); ACE_DEBUG ((LM_DEBUG, "%C\n", string.in ())); ACE_ASSERT (id_from_reference.in () == id.in ()); forth_poa->activate_object_with_id (id.in (), &servant); obj = forth_poa->id_to_reference (id.in ()); string = orb->object_to_string (obj.in ()); ACE_DEBUG ((LM_DEBUG, "%C\n", string.in ())); PortableServer::ServantBase_var servant_from_reference = forth_poa->reference_to_servant (obj.in ()); PortableServer::ServantBase_var servant_from_id = forth_poa->id_to_servant (id.in ()); if (servant_from_reference.in () != servant_from_id.in () || servant_from_reference.in () != &servant) { ACE_ERROR ((LM_ERROR, "Mismatched servant_from_reference, " "servant_from_id and &servant\n")); } forth_poa->deactivate_object (id.in ()); if (perform_deactivation_test) { forth_poa->activate_object_with_id (id.in (), &servant); servant_from_reference = forth_poa->reference_to_servant (obj.in ()); ACE_ASSERT (servant_from_reference.in () == &servant); forth_poa->deactivate_object (id.in ()); } } }
int main(int argc, char* argv[]) { // parse command line options string dmdFile; string sdrRoot; string logfile_uri; string db_uri; string domainName; int debugLevel = 3; // If "--nopersist" is asserted, turn off persistent IORs. bool enablePersistence = true; // If "--force-rebind" is asserted, this instance will replace any existing name binding // for the DomainManager. bool forceRebind = false; std::map<std::string, char*>execparams; for (int ii = 1; ii < argc; ++ii) { std::string param = argv[ii]; if (++ii >= argc) { std::cerr << "ERROR: No value given for " << param << std::endl; exit(EXIT_FAILURE); } if (param == "DMD_FILE") { dmdFile = argv[ii]; } else if (param == "SDRROOT") { sdrRoot = argv[ii]; } else if (param == "DOMAIN_NAME") { domainName = argv[ii]; } else if (param == "LOGGING_CONFIG_URI") { logfile_uri = argv[ii]; } else if (param == "DB_URL") { db_uri = argv[ii]; } else if (param == "DEBUG_LEVEL") { debugLevel = atoi(argv[ii]); } else if (param == "PERSISTENCE") { string value = argv[ii]; std::transform(value.begin(), value.begin(), value.end(), ::tolower); enablePersistence = (value == "true"); } else if (param == "FORCE_REBIND") { string value = argv[ii]; std::transform(value.begin(), value.begin(), value.end(), ::tolower); forceRebind = (value == "true"); } else if (param == "-ORBendPoint") { } else if ( ii > 0 ) { // any other argument besides the first one is part of the execparams execparams[param] = argv[ii]; } } if (dmdFile.empty() || domainName.empty()) { std::cerr << "ERROR: DMD_FILE and DOMAIN_NAME must be provided" << std::endl; exit(EXIT_FAILURE); } // We have to have a real SDRROOT fs::path sdrRootPath; if (!sdrRoot.empty()) { sdrRootPath = sdrRoot; } else if (getenv("SDRROOT") != NULL) { sdrRootPath = getenv("SDRROOT"); } else { // Fall back to CWD sdrRootPath = fs::initial_path(); } // Verify the path exists if (!fs::is_directory(sdrRootPath)) { std::cerr << "ERROR: Invalid SDRROOT " << sdrRootPath << std::endl; exit(EXIT_FAILURE); } fs::path domRootPath = sdrRootPath / "dom"; if (!fs::is_directory(domRootPath)) { std::cerr << "ERROR: Invalid Domain Manager File System Root " << domRootPath << std::endl; exit(EXIT_FAILURE); } // Take care of the logfile URI if (logfile_uri.empty()) { LoggingConfigurator::configure(debugLevel); } else { // Determine the scheme, if any. This isn't a full fledged URI parser so we can // get tripped up on complex URIs. We should probably incorporate a URI parser // library for this sooner rather than later std::string scheme; fs::path path; std::string::size_type colonIdx = logfile_uri.find(":"); // Find the scheme separator if (colonIdx == std::string::npos) { scheme = "file"; path = logfile_uri; // Make the path absolute fs::path logfile_path(path); if (! logfile_path.is_complete()) { // Get the root path so we can resolve relative paths fs::path root = fs::initial_path(); logfile_path = fs::path(root / path); } path = logfile_path; logfile_uri = "file://" + path.string(); } else { scheme = logfile_uri.substr(0, colonIdx); colonIdx += 1; if ((logfile_uri.at(colonIdx + 1) == '/') && (logfile_uri.at(colonIdx + 2) == '/')) { colonIdx += 2; } path = logfile_uri.substr(colonIdx, logfile_uri.length() - colonIdx); } if (scheme == "file") { LoggingConfigurator::configure((char*)path.string().c_str()); } else if (scheme == "sca") { LoggingConfigurator::configure((char*)fs::path(domRootPath / path).string().c_str()); } LOG_INFO(DomainManager, "Loading log configuration from " << logfile_uri); } /////////////////////////////////////////////////////////////////////////// // NO LOG_ STATEMENTS ABOVE THIS POINT /////////////////////////////////////////////////////////////////////////// // Create signal handler to catch system interrupts SIGINT and SIGQUIT struct sigaction sa; sa.sa_handler = signal_catcher; sa.sa_flags = 0; sigemptyset(&sa.sa_mask); // Associate SIGINT to signal_catcher interrupt handler if (sigaction(SIGINT, &sa, NULL) == -1) { LOG_ERROR(DomainManager, "sigaction(SIGINT): " << strerror(errno)); exit(EXIT_FAILURE); } // Associate SIGQUIT to signal_catcher interrupt handler if (sigaction(SIGQUIT, &sa, NULL) == -1) { LOG_ERROR(DomainManager, "sigaction(SIGQUIT): " << strerror(errno)); exit(EXIT_FAILURE); } // Associate SIGTERM to signal_catcher interrupt handler if (sigaction(SIGTERM, &sa, NULL) == -1) { LOG_ERROR(DomainManager, "sigaction(SIGTERM): " << strerror(errno)); exit(EXIT_FAILURE); } // Start CORBA. Only ask for persistence if "--nopersist" was not asserted, which implies // using the same port. CORBA::ORB_ptr orb = ossie::corba::OrbInit(argc, argv, enablePersistence); PortableServer::POA_ptr root_poa = PortableServer::POA::_nil(); try { // Install an adaptor to automatically create our own POAs. root_poa = ossie::corba::RootPOA(); } catch ( CORBA::INITIALIZE& ex ) { LOG_FATAL(DomainManager, "Failed to initialize the POA. Is there a Domain Manager already running?"); exit(EXIT_FAILURE); } ossie::corba::POACreator activator_servant; PortableServer::AdapterActivator_var activator = activator_servant._this(); root_poa->the_activator(activator); // Activate the root POA manager. PortableServer::POAManager_var mgr = root_poa->the_POAManager(); mgr->activate(); // Figure out what architecture we are on // Map i686 to SCA x86 struct utsname un; if (uname(&un) != 0) { LOG_FATAL(DomainManager, "Unable to determine system information: " << strerror(errno)); exit(EXIT_FAILURE); } if (strcmp("i686", un.machine) == 0) { strcpy(un.machine, "x86"); } LOG_DEBUG(DomainManager, "Machine " << un.machine); LOG_DEBUG(DomainManager, "Version " << un.release); LOG_DEBUG(DomainManager, "OS " << un.sysname); try { // Create Domain Manager servant and object LOG_INFO(DomainManager, "Starting Domain Manager"); LOG_DEBUG(DomainManager, "Root of DomainManager FileSystem set to " << domRootPath); LOG_DEBUG(DomainManager, "DMD path set to " << dmdFile); LOG_DEBUG(DomainManager, "Domain Name set to " << domainName); try { DomainManager_servant = new DomainManager_impl(dmdFile.c_str(), domRootPath.string().c_str(), domainName.c_str(), (logfile_uri.empty()) ? NULL : logfile_uri.c_str() ); DomainManager_servant->setExecparamProperties(execparams); } catch (const CORBA::Exception& ex) { LOG_ERROR(DomainManager, "Terminated with CORBA::" << ex._name() << " exception"); exit(-1); } catch (const std::exception& ex) { LOG_ERROR(DomainManager, "Terminated with exception: " << ex.what()); exit(-1); } catch( ... ) { LOG_ERROR(DomainManager, "Terminated with unknown exception"); exit(EXIT_FAILURE); } // Activate the DomainManager servant into its own POA, giving the POA responsibility // for its deletion. LOG_DEBUG(DomainManager, "Activating DomainManager into POA"); PortableServer::POA_var dommgr_poa = root_poa->find_POA("DomainManager", 1); PortableServer::ObjectId_var oid = ossie::corba::activatePersistentObject(dommgr_poa, DomainManager_servant, DomainManager_servant->getFullDomainManagerName()); // If a database URI was given, attempt to restore the state. Most common errors should // be handled gracefully, so any exception that escapes to this level probably indicates // a severe problem. // TODO: Determine whether this step can occur before activating the servant. Because this // is almost exclusively used with persistent IORs, a client might already hold (or be able // to get) a reference to the DomainManager, but calls may fail due to the unpredictable // state. if (!db_uri.empty()) { try { DomainManager_servant->restoreState(db_uri); } CATCH_RETHROW_LOG_ERROR(DomainManager, "Unrecoverable error restoring state"); } // Bind the DomainManager object to its full name (e.g. "DomainName/DomainName") in the NameService. LOG_DEBUG(DomainManager, "Binding DomainManager to NamingService name " << DomainManager_servant->getFullDomainManagerName()); CF::DomainManager_var DomainManager_obj = DomainManager_servant->_this(); CosNaming::Name_var name = ossie::corba::stringToName(DomainManager_servant->getFullDomainManagerName()); try { // Attempt to bind the name. The DomainManager_impl constructor cleans up any non-existing entries, so // this will only fail if there is an active object already bound to the name. ossie::corba::InitialNamingContext()->bind(name, DomainManager_obj); } catch (const CosNaming::NamingContext::AlreadyBound&) { if (forceRebind) { // Forcibly replace the existing name binding. LOG_INFO(DomainManager, "Replacing existing name binding " << DomainManager_servant->getFullDomainManagerName()); ossie::corba::InitialNamingContext()->rebind(name, DomainManager_obj); } else { LOG_FATAL(DomainManager, "A DomainManager is already running as " << DomainManager_servant->getFullDomainManagerName()); exit(-1); } } CORBA::String_var ior_str = orb->object_to_string(DomainManager_obj); LOG_DEBUG(DomainManager, ior_str); DomainManager_servant->_remove_ref(); LOG_INFO(DomainManager, "Starting ORB!"); DomainManager_servant->run(); LOG_DEBUG(DomainManager, "Shutting down DomainManager"); DomainManager_servant->shutdown(received_signal); LOG_INFO(DomainManager, "Requesting ORB shutdown"); ossie::corba::OrbShutdown(true); LOG_INFO(DomainManager, "Goodbye!"); } catch (const CORBA::Exception& ex) { LOG_FATAL(DomainManager, "Terminated with CORBA::" << ex._name() << " exception"); exit(-1); } catch (const std::exception& ex) { LOG_FATAL(DomainManager, "Terminated with exception: " << ex.what()); exit(-1); } catch (...) { LOG_FATAL(DomainManager, "Terminated with unknown exception"); exit(-1); } LOG_DEBUG(DomainManager, "Farewell!") }
int ACE_TMAIN (int argc, ACE_TCHAR *argv[]) { int status = 0; ACE_Auto_Ptr< sig_i > sig_impl; try { Supplier_Client client; status = client.init (argc, argv); if (status == 0) { static const char* ec_name = "MyEventChannel"; CosNotifyChannelAdmin::EventChannel_var ec = client.create_event_channel (ec_name, 0); static const int max = 20; int count = 0; while(ACE_OS::access(ACE_TEXT_ALWAYS_CHAR(notify2ior), R_OK) == -1 && count < max) { ACE_OS::sleep (1); count++; } if (count >= max) { ACE_ERROR_RETURN ((LM_ERROR, "ERROR: Timed out waiting for the " "second notify service\n"), 1); } ACE_OS::sleep (2); // Due to the way that connections are handled, we need to // perform the new event channel creation twice to flush out // the connection to the first notification service try { ec = client.create_event_channel (ec_name, 0); } catch (const CORBA::TRANSIENT&) { } catch (const CORBA::COMM_FAILURE&) { } ec = client.create_event_channel (ec_name, 0); CORBA::ORB_ptr orb = client.orb (); // Activate the signaler with the POA sig_impl.reset( new sig_i( orb ) ); sig_var sig = sig_impl->_this (); CORBA::String_var ior = orb->object_to_string (sig.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 %s for " "writing IOR: %C", ior_output_file, ior.in ()), 1); ACE_OS::fprintf (output_file, "%s", ior.in ()); ACE_OS::fclose (output_file); } CosNotifyChannelAdmin::SupplierAdmin_var admin = create_supplieradmin (ec.in ()); if (!CORBA::is_nil (admin.in ())) { create_suppliers (admin.in (), client.root_poa ()); sig_impl->wait_for_startup(); ACE_DEBUG((LM_DEBUG, "1 supplier sending %d events...\n", max_events)); for (int i = 0; i < max_events; ++i) { ACE_DEBUG((LM_DEBUG, "+")); SendEvent (i); } ACE_DEBUG((LM_DEBUG, "\nSupplier sent %d events.\n", max_events)); sig_impl->wait_for_completion(); ACE_OS::unlink (ior_output_file); supplier_1->disconnect(); ec->destroy(); } } } catch (const CORBA::Exception& e) { e._tao_print_exception ("Error: "); status = 1; } return status; }
int TAO_Naming_Server::init_new_naming (CORBA::ORB_ptr orb, PortableServer::POA_ptr poa, const ACE_TCHAR *persistence_location, void *base_addr, size_t context_size, int enable_multicast, int use_storable_context, int round_trip_timeout, int use_round_trip_timeout) { try { #if defined (CORBA_E_MICRO) ACE_UNUSED_ARG (persistence_location); ACE_UNUSED_ARG (base_addr); ACE_UNUSED_ARG (use_storable_context); #else if (use_storable_context) { // In lieu of a fully implemented service configurator version // of this Reader and Writer, let's just take something off the // command line for now. TAO::Storable_Factory* pf = 0; ACE_CString directory (ACE_TEXT_ALWAYS_CHAR (persistence_location)); ACE_NEW_RETURN (pf, TAO::Storable_FlatFileFactory (directory), -1); auto_ptr<TAO::Storable_Factory> persFactory(pf); // Use an auto_ptr to ensure that we clean up the factory in the case // of a failure in creating and registering the Activator. TAO_Storable_Naming_Context_Factory* cf = this->storable_naming_context_factory (context_size); // Make sure we got a factory if (cf == 0) return -1; auto_ptr<TAO_Storable_Naming_Context_Factory> contextFactory (cf); // This instance will either get deleted after recreate all or, // in the case of a servant activator's use, on destruction of the // activator. // Was a location specified? if (persistence_location == 0) { // No, assign the default location "NameService" persistence_location = ACE_TEXT ("NameService"); } // Now make sure this directory exists if (ACE_OS::access (persistence_location, W_OK|X_OK)) { ORBSVCS_ERROR_RETURN ((LM_ERROR, "Invalid persistence directory\n"), -1); } #if (TAO_HAS_MINIMUM_POA == 0) && !defined (CORBA_E_COMPACT) if (this->use_servant_activator_) { ACE_NEW_THROW_EX (this->servant_activator_, TAO_Storable_Naming_Context_Activator (orb, persFactory.get(), contextFactory.get (), persistence_location), CORBA::NO_MEMORY ()); this->ns_poa_->set_servant_manager(this->servant_activator_); } #endif /* TAO_HAS_MINIMUM_POA */ try { // The following might throw an exception. this->naming_context_ = TAO_Storable_Naming_Context::recreate_all (orb, poa, TAO_ROOT_NAMING_CONTEXT, context_size, 0, contextFactory.get (), persFactory.get (), use_redundancy_); } catch (const CORBA::Exception& ex) { // The activator already took over the factories so we need to release the auto_ptr if (this->use_servant_activator_) { // The context factory is now owned by the activator // so we should release it contextFactory.release (); // If using a servant activator, the activator now owns the // factory, so we should release it persFactory.release (); } // Print out the exception and return failure ex._tao_print_exception ( "TAO_Naming_Server::init_new_naming"); return -1; } // Kind of a duplicate of the above here, but we must also release the // factory autoptrs in the good case as well. if (this->use_servant_activator_) { // The context factory is now owned by the activator // so we should release it contextFactory.release (); // If using a servant activator, the activator now owns the // factory, so we should release it persFactory.release (); } } else if (persistence_location != 0) // // Initialize Persistent Naming Service. // { // Create Naming Context Implementation Factory to be used for the creation of // naming contexts by the TAO_Persistent_Context_Index TAO_Persistent_Naming_Context_Factory *naming_context_factory = this->persistent_naming_context_factory (); // Make sure we got a factory. if (naming_context_factory == 0) return -1; // Allocate and initialize Persistent Context Index. ACE_NEW_RETURN (this->context_index_, TAO_Persistent_Context_Index (orb, poa, naming_context_factory), -1); if (this->context_index_->open (persistence_location, base_addr) == -1 || this->context_index_->init (context_size) == -1) { if (TAO_debug_level >0) ORBSVCS_DEBUG ((LM_DEBUG, "TAO_Naming_Server: context_index initialization failed\n")); return -1; } // Set the root Naming Context reference. this->naming_context_ = this->context_index_->root_context (); } else #endif /* CORBA_E_MICRO */ { // // Initialize Transient Naming Service. // this->naming_context_ = TAO_Transient_Naming_Context::make_new_context (poa, TAO_ROOT_NAMING_CONTEXT, context_size); } #if !defined (CORBA_E_MICRO) // Register with the ORB's resolve_initial_references() // mechanism. Primarily useful for dynamically loaded Name // Services. orb->register_initial_reference ("NameService", this->naming_context_.in ()); #endif /* CORBA_E_MICRO */ // Set the ior of the root Naming Context. this->naming_service_ior_= orb->object_to_string (this->naming_context_.in ()); CORBA::Object_var table_object = orb->resolve_initial_references ("IORTable"); IORTable::Table_var adapter = IORTable::Table::_narrow (table_object.in ()); if (CORBA::is_nil (adapter.in ())) { ORBSVCS_ERROR ((LM_ERROR, "Nil IORTable\n")); } else { CORBA::String_var ior = orb->object_to_string (this->naming_context_.in ()); adapter->bind ("NameService", ior.in ()); } #if defined (ACE_HAS_IP_MULTICAST) if (enable_multicast) { // @@ Marina: is there anyway to implement this stuff // without using ORB_Core_instance()? For example can you // pass the ORB as an argument? // // Install ior multicast handler. // // Get reactor instance from TAO. ACE_Reactor *reactor = orb->orb_core()->reactor (); // See if the -ORBMulticastDiscoveryEndpoint option was specified. ACE_CString mde (orb->orb_core ()->orb_params ()->mcast_discovery_endpoint ()); // First, see if the user has given us a multicast port number // on the command-line; u_short port = orb->orb_core ()->orb_params ()->service_port (TAO::MCAST_NAMESERVICE); if (port == 0) { // Check environment var. for multicast port. const char *port_number = ACE_OS::getenv ("NameServicePort"); if (port_number != 0) port = static_cast<u_short> (ACE_OS::atoi (port_number)); } // Port wasn't specified on the command-line or in environment - // use the default. if (port == 0) port = TAO_DEFAULT_NAME_SERVER_REQUEST_PORT; // Instantiate a handler which will handle client requests for // the root Naming Context ior, received on the multicast port. ACE_NEW_RETURN (this->ior_multicast_, TAO_IOR_Multicast (), -1); if (mde.length () != 0) { if (this->ior_multicast_->init (this->naming_service_ior_.in (), mde.c_str (), TAO_SERVICEID_NAMESERVICE) == -1) return -1; } else { if (this->ior_multicast_->init (this->naming_service_ior_.in (), port, #if defined (ACE_HAS_IPV6) ACE_DEFAULT_MULTICASTV6_ADDR, #else ACE_DEFAULT_MULTICAST_ADDR, #endif /* ACE_HAS_IPV6 */ TAO_SERVICEID_NAMESERVICE) == -1) return -1; } // Register event handler for the ior multicast. if (reactor->register_handler (this->ior_multicast_, ACE_Event_Handler::READ_MASK) == -1) { if (TAO_debug_level > 0) ORBSVCS_DEBUG ((LM_DEBUG, "TAO_Naming_Server: cannot register Event handler\n")); return -1; } if (TAO_debug_level > 0) ORBSVCS_DEBUG ((LM_DEBUG, "TAO_Naming_Server: The multicast server setup is done.\n")); } #else ACE_UNUSED_ARG (enable_multicast); #endif /* ACE_HAS_IP_MULTICAST */ #if defined (TAO_HAS_CORBA_MESSAGING) && TAO_HAS_CORBA_MESSAGING != 0 if (use_round_trip_timeout == 1) { TimeBase::TimeT roundTripTimeoutVal = round_trip_timeout; CORBA::Any anyObjectVal; anyObjectVal <<= roundTripTimeoutVal; CORBA::PolicyList polList (1); polList.length (1); polList[0] = orb->create_policy (Messaging::RELATIVE_RT_TIMEOUT_POLICY_TYPE, anyObjectVal); // set a timeout on the orb // CORBA::Object_var orbPolicyManagerObj = orb->resolve_initial_references ("ORBPolicyManager"); CORBA::PolicyManager_var orbPolicyManager = CORBA::PolicyManager::_narrow (orbPolicyManagerObj.in ()); orbPolicyManager->set_policy_overrides (polList, CORBA::SET_OVERRIDE); polList[0]->destroy (); polList[0] = CORBA::Policy::_nil (); } #else ACE_UNUSED_ARG (use_round_trip_timeout); ACE_UNUSED_ARG (round_trip_timeout); #endif /* TAO_HAS_CORBA_MESSAGING */ } catch (const CORBA::Exception& ex) { ex._tao_print_exception ( "TAO_Naming_Server::init_new_naming"); return -1; } return 0; }
CORBA::Object_ptr DAnCE_TargetManager_Module::init (CORBA::ORB_ptr orb, int argc, ACE_TCHAR *argv[]) { DANCE_TRACE ("DAnCE_TargetManager_Module::init"); try { if (CORBA::is_nil(orb)) { DANCE_ERROR (DANCE_LOG_TERMINAL_ERROR, (LM_ERROR, DLINFO ACE_TEXT ("DAnCE_TargetManager_Module::init - ") ACE_TEXT ("Attempted to create Target Manager with a nil orb.\n"))); return CORBA::Object::_nil(); } else { this->orb_ = CORBA::ORB::_duplicate (orb); } if (ACE_OS::strcmp(orb->id(), this->orb_->id()) != 0) { DANCE_TRACE_LOG (DANCE_LOG_TRACE, (LM_TRACE, DLINFO ACE_TEXT ("DAnCE_TargetManager_Module::init - ") ACE_TEXT ("Resetting TM's orb.\n"))); this->orb_ = CORBA::ORB::_duplicate (orb); this->domain_nc_ = CosNaming::NamingContext::_nil(); } if (!this->parse_args (argc, argv)) { return CORBA::Object::_nil (); } this->create_poas (); if (this->options_.domain_nc_) { try { DANCE_TRACE_LOG (DANCE_LOG_TRACE, (LM_TRACE, DLINFO ACE_TEXT ("DAnCE_TargetManager_Module::init - ") ACE_TEXT ("Resolving DomainNC.\n"))); CORBA::Object_var domain_obj = this->orb_->string_to_object (this->options_.domain_nc_); if (!CORBA::is_nil (domain_obj.in ())) { this->domain_nc_ = CosNaming::NamingContext::_narrow (domain_obj.in()); if (CORBA::is_nil (this->domain_nc_.in ())) { DANCE_ERROR (DANCE_LOG_TERMINAL_ERROR, (LM_ERROR,DLINFO ACE_TEXT ("DAnCE_TargetManager_Module::init - ") ACE_TEXT ("Narrow to NamingContext return nil for DomainNC.\n"))); return CORBA::Object::_nil (); } } } catch (CORBA::Exception&) { DANCE_DEBUG (DANCE_LOG_ERROR, (LM_WARNING, DLINFO ACE_TEXT ("DAnCE_TargetManager_Module::init - ") ACE_TEXT ("DomainNC context not found!\n"))); } } DANCE_TRACE_LOG (DANCE_LOG_TRACE, (LM_TRACE, DLINFO ACE_TEXT ("DAnCE_TargetManager_Module::init - ") ACE_TEXT ("Initializing the IOR Table\n"))); // Initialize IOR table CORBA::Object_var table_object = orb->resolve_initial_references ("IORTable"); IORTable::Table_var adapter = IORTable::Table::_narrow (table_object.in ()); if (CORBA::is_nil (adapter.in ())) { DANCE_ERROR (DANCE_LOG_TERMINAL_ERROR, (LM_ERROR, DLINFO ACE_TEXT ("DAnCE_TargetManager_Module::init - ") ACE_TEXT ("Unable to RIR the IORTable.\n"))); return CORBA::Object::_nil (); } //Creating repository manager servant DAnCE::TargetManagerDaemon_i * rm = new DAnCE::TargetManagerDaemon_i (orb); PortableServer::ServantBase_var safe_svt (rm); ACE_CString repository_manager_oid; if (this->options_.name_ == 0) { repository_manager_oid = "TargetManager"; } else { repository_manager_oid = ACE_TEXT_ALWAYS_CHAR (this->options_.name_); repository_manager_oid += ".TargetManager"; } // Registering servant in poa PortableServer::ObjectId_var oid = PortableServer::string_to_ObjectId (repository_manager_oid.c_str()); this->rm_poa_->activate_object_with_id (oid, rm); // Getting repository manager ior CORBA::Object_var nm_obj = this->rm_poa_->id_to_reference (oid.in ()); CORBA::String_var ior = orb->object_to_string (nm_obj.in ()); // Binding ior to IOR Table adapter->bind (repository_manager_oid.c_str (), ior.in ()); // Binding repository manager to DomainNC if (!CORBA::is_nil (this->domain_nc_.in ())) { ACE_CString ns_name; if (this->options_.name_ == 0) { ns_name = "TargetManager"; } else { ns_name = ACE_TEXT_ALWAYS_CHAR (this->options_.name_); } DANCE_DEBUG (DANCE_LOG_MINOR_EVENT, (LM_TRACE, DLINFO ACE_TEXT ("DAnCE_TargetManager_Module::init - ") ACE_TEXT ("Registering NM in NC as \"%C\".\n"), ns_name.c_str ())); CosNaming::Name name (1); name.length (1); name[0].id = CORBA::string_dup (ns_name.c_str ()); name[0].kind = CORBA::string_dup ("TargetManager"); this->domain_nc_->rebind (name, nm_obj.in ()); } // Writing ior to file if (0 != this->options_.ior_file_) { DANCE_DEBUG (DANCE_LOG_MINOR_EVENT, (LM_TRACE, DLINFO ACE_TEXT ("DAnCE_TargetManager_Module::init - ") ACE_TEXT ("Writing RM IOR %C to file %C.\n"), this->options_.ior_file_, ior.in ())); if (!DAnCE::Target_Manager::write_IOR (this->options_.ior_file_, ior.in ())) DANCE_ERROR (DANCE_LOG_ERROR, (LM_ERROR, DLINFO ACE_TEXT ("DAnCE_TargetManager_Module::init - ") ACE_TEXT ("Error: Unable to write IOR to file %C\n"), this->options_.ior_file_)); } // Activate POA manager PortableServer::POAManager_var mgr = this->root_poa_->the_POAManager (); mgr->activate (); // Finishing Deployment part DANCE_DEBUG (DANCE_LOG_MAJOR_EVENT, (LM_NOTICE, DLINFO ACE_TEXT ("DAnCE_TargetManager_Module::init - ") ACE_TEXT ("DAnCE_TargetManager is running...\n"))); DANCE_DEBUG (DANCE_LOG_MAJOR_DEBUG_INFO, (LM_DEBUG, DLINFO ACE_TEXT ("DAnCE_TargetManager_Module::init - ") ACE_TEXT ("TargetManager IOR: %s\n"), ior.in ())); return nm_obj._retn (); } catch (const CORBA::Exception& ex) { DANCE_ERROR (DANCE_LOG_TERMINAL_ERROR, (LM_EMERGENCY, ACE_TEXT ("Caught CORBA Exception: %C\n"), ex._info ().c_str ())); return CORBA::Object::_nil (); } }
void ImR_Client_Adapter_Impl::imr_notify_startup (TAO_Root_POA* poa ) { CORBA::Object_var imr = poa->orb_core ().implrepo_service (); if (CORBA::is_nil (imr.in ())) { if (TAO_debug_level > 0) { TAOLIB_ERROR ((LM_ERROR, ACE_TEXT ("TAO_ImR_Client (%P|%t) - ERROR: No usable IMR initial reference ") ACE_TEXT ("available but use IMR has been specified.\n"))); } throw ::CORBA::TRANSIENT ( CORBA::SystemException::_tao_minor_code (TAO_IMPLREPO_MINOR_CODE, 0), CORBA::COMPLETED_NO); } if (TAO_debug_level > 0) { if (TAO_debug_level > 1) { CORBA::ORB_ptr orb = poa->orb_core ().orb (); CORBA::String_var ior = orb->object_to_string (imr.in ()); TAOLIB_DEBUG ((LM_DEBUG, ACE_TEXT ("TAO_ImR_Client (%P|%t) - Notifying ImR of startup IMR IOR <%C>\n"), ior.in ())); } } ImplementationRepository::Administration_var imr_locator; { // ATTENTION: Trick locking here, see class header for details TAO::Portable_Server::Non_Servant_Upcall non_servant_upcall (*poa); ACE_UNUSED_ARG (non_servant_upcall); imr_locator = ImplementationRepository::Administration::_narrow (imr.in ()); } if (CORBA::is_nil (imr_locator.in ())) { if (TAO_debug_level > 0) { TAOLIB_ERROR ((LM_ERROR, ACE_TEXT ("TAO_ImR_Client (%P|%t) - ERROR: Narrowed IMR initial reference ") ACE_TEXT ("is nil but use IMR has been specified.\n"))); } throw ::CORBA::TRANSIENT ( CORBA::SystemException::_tao_minor_code (TAO_IMPLREPO_MINOR_CODE, 0), CORBA::COMPLETED_NO); } TAO_Root_POA *root_poa = poa->object_adapter ().root_poa (); ACE_NEW_THROW_EX (this->server_object_, ServerObject_i (poa->orb_core ().orb (), root_poa), CORBA::NO_MEMORY ()); PortableServer::ServantBase_var safe_servant (this->server_object_); ACE_UNUSED_ARG (safe_servant); // Since this method is called from the POA constructor, there // shouldn't be any waiting required. Therefore, // <wait_occurred_restart_call_ignored> can be ignored. bool wait_occurred_restart_call_ignored = false; // Activate the servant in the root poa. PortableServer::ObjectId_var id = root_poa->activate_object_i (this->server_object_, poa->server_priority (), wait_occurred_restart_call_ignored); CORBA::Object_var obj = root_poa->id_to_reference_i (id.in (), false); ImplementationRepository::ServerObject_var svr = ImplementationRepository::ServerObject::_narrow (obj.in ()); if (!svr->_stubobj () || !svr->_stubobj ()->profile_in_use ()) { if (TAO_debug_level > 0) { TAOLIB_ERROR ((LM_ERROR, "TAO_ImR_Client (%P|%t) - Invalid ImR ServerObject, bailing out.\n")); } return; } CORBA::ORB_var orb = root_poa->_get_orb (); CORBA::String_var full_ior = orb->object_to_string (obj.in ()); TAO_Profile& profile = *(svr->_stubobj ()->profile_in_use ()); CORBA::String_var ior = profile.to_string(); if (TAO_debug_level > 0) { TAOLIB_DEBUG((LM_INFO, "TAO_ImR_Client (%P|%t) - full_ior <%C>\nior <%C>\n", full_ior.in(), ior.in())); } char* const pos = find_delimiter (ior.inout (), profile.object_key_delimiter ()); const ACE_CString partial_ior (ior.in (), (pos - ior.in ()) + 1); if (TAO_debug_level > 0) { CORBA::String_var poaname = poa->the_name (); TAOLIB_DEBUG ((LM_DEBUG, ACE_TEXT ("TAO_ImR_Client (%P|%t) - Informing IMR that <%C> is running at <%C>\n"), poaname.in(), partial_ior.c_str ())); } try { // ATTENTION: Trick locking here, see class header for details TAO::Portable_Server::Non_Servant_Upcall non_servant_upcall (*poa); ACE_UNUSED_ARG (non_servant_upcall); ACE_CString const serverId = poa->orb_core ().server_id (); ACE_CString name; if (serverId.empty ()) { name = poa->name (); } else { name = serverId + ":" + poa->name (); } imr_locator->server_is_running (name.c_str (), partial_ior.c_str (), svr.in ()); } catch (const ::CORBA::SystemException&) { throw; } catch (const ::CORBA::Exception&) { throw ::CORBA::TRANSIENT ( CORBA::SystemException::_tao_minor_code (TAO_IMPLREPO_MINOR_CODE, 0), CORBA::COMPLETED_NO); } if (TAO_debug_level > 0) { TAOLIB_DEBUG ((LM_DEBUG, ACE_TEXT ("TAO_ImR_Client (%P|%t) - Successfully notified ImR of Startup\n"))); } }
int ACE_TMAIN (int argc, ACE_TCHAR* argv[]) { int status = 0; try { Supplier_Client client; status = client.init (argc, argv); if (status == 0) { CosNotifyChannelAdmin::EventChannel_var ec = client.create_event_channel ("MyEventChannel", 0); CORBA::ORB_ptr orb = client.orb (); sig_i* sig_impl; ACE_NEW_RETURN (sig_impl, sig_i (orb), 1); PortableServer::ServantBase_var owner_transfer(sig_impl); CORBA::Object_var object = orb->resolve_initial_references ("RootPOA"); PortableServer::POA_var root_poa = PortableServer::POA::_narrow (object.in ()); PortableServer::ObjectId_var id = root_poa->activate_object (sig_impl); object = root_poa->id_to_reference (id.in ()); sig_var sig = sig::_narrow (object.in ()); CORBA::String_var ior = orb->object_to_string (sig.in ()); // Output the IOR to the <ior_output_file> FILE *output_file= ACE_OS::fopen (ior_output_file, "w"); if (output_file != 0) { ACE_OS::fprintf (output_file, "%s", ior.in ()); ACE_OS::fclose (output_file); } CosNotifyChannelAdmin::SupplierAdmin_var admin = create_supplieradmin (ec.in ()); if (!CORBA::is_nil (admin.in ())) { create_suppliers (admin.in (), client.root_poa ()); sig_impl->wait_for_startup(); ACE_DEBUG ((LM_DEBUG, "1 supplier sending %d events...\n", max_events)); for (int i = 0; i < max_events; ++i) { ACE_DEBUG ((LM_DEBUG, "+")); SendEvent (i); } ACE_DEBUG ((LM_DEBUG, "\nSupplier sent %d events.\n", max_events)); ACE_OS::unlink (ior_output_file); supplier_1->disconnect (); ec->destroy (); } } } catch (const CORBA::Exception& e) { e._tao_print_exception ("Supplier Error: "); status = 1; } return status; }
int ACE_TMAIN (int argc, ACE_TCHAR *argv[]) { ACE_Auto_Ptr< sig_i > sig_impl; try { Consumer_Client client; int status = client.init (argc, argv); ACE_UNUSED_ARG(status); ACE_ASSERT(status == 0); CosNotifyChannelAdmin::EventChannel_var ec = client.create_event_channel ("MyEventChannel", 0); CORBA::ORB_ptr orb = client.orb (); sig_impl.reset( new sig_i( orb ) ); sig_var sig = sig_impl->_this (); CORBA::String_var ior = orb->object_to_string (sig.in ()); 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 %s for " "writing IOR: %C", ior_output_file, ior.in ()), 1); ACE_OS::fprintf (output_file, "%s", ior.in ()); ACE_OS::fclose (output_file); } CosNotifyChannelAdmin::SupplierAdmin_var admin = create_supplieradmin (ec.in ()); ACE_ASSERT(!CORBA::is_nil (admin.in ())); create_suppliers (admin.in (), &client); sig_impl->wait_for_startup(); ACE_DEBUG((LM_DEBUG, "%i supplier(s) sending %d events...\n", supplier_count, event_count)); for (int i = 0; i < event_count; ++i) { ACE_DEBUG((LM_DEBUG, "+")); SendEvent (i); } ACE_DEBUG((LM_DEBUG, "\nEach Supplier sent %d events.\n", event_count)); sig_impl->wait_for_completion(); ACE_OS::unlink (ior_output_file); disconnect_suppliers(); ec->destroy(); return 0; } catch (const CORBA::Exception& e) { e._tao_print_exception ("Error: "); } return 1; }
bool ServiceOptions::bindServiceObject(CORBA::ORB_ptr orb, CORBA::Object_ptr object, PortableServer::Servant p_servant, const char* objName, bool rebind) { if(is_set("with-naming")) { CosNaming::Name name; name.length(1); name[0].id=CORBA::string_dup(objName); name[0].kind=CORBA::string_dup(""); CORBA::Object_var obj ; try { obj = orb->resolve_initial_references("NameService"); }catch(const CORBA::ORB::InvalidName& ex){ std::cerr << argv()[0] << ": can't resolve `NameService'" << std::endl; return false; } CosNaming::NamingContext_var nc; try { nc = CosNaming::NamingContext::_narrow(obj.in()); }catch(const CORBA::SystemException& ex){ std::cerr << argv()[0] << ": can't narrow naming service" << std::endl; return false; } try { if(rebind){ nc->rebind(name,object); }else{ try{ nc->bind(name,object); }catch(const CosNaming::NamingContext::AlreadyBound&){ std::cerr<<argv()[0]<<":can't bind "<<objName<<" (AlreadyBound)"<< std::endl; return false; } } }catch(const CosNaming::NamingContext::CannotProceed&){ std::cerr<<argv()[0]<<": can't bind "<<objName<<" (CannotProceed)"<< std::endl; return false; }catch(const CosNaming::NamingContext::InvalidName&){ std::cerr<<argv()[0]<<":can't bind "<<objName<<" (InvalidName)"<< std::endl; return false; } std::cout<<argv()[0]<<": binding completed successfully"<<std::endl; } CORBA::String_var ior ; try { ior = orb->object_to_string(object); }catch(const CORBA::SystemException& ex){ #ifdef CORBA_SYSTEM_EXCEPTION_IS_STREAMBLE std::cerr << ex << std::endl; #else std::cerr << "CORBA::SystemException" << std::endl; #endif return false; } const char* fname = get_ior_fname(objName); if (fname!=NULL && strcmp(fname,"")!=0) { std::ofstream ofs (fname); if (ofs.bad()) { std::cerr << argv()[0] << ": can't open file " << fname << std::endl; perror(argv()[0]); return false; } ofs << ior.in(); ofs.close(); } if (is_set("ior-stdout")) { std::cout << ior << std::flush; } #ifdef ORBACUS CORBA::Object_var bmgrObj = orb->resolve_initial_references("BootManager"); OB::BootManager_var bootManager = OB::BootManager::_narrow(bmgrObj); PortableServer::ObjectId_var oid = PortableServer::string_to_ObjectId(objName); bootManager -> add_binding(oid.in(),object); #elif defined(OMNIORB) PortableServer::POA_var objPOA = p_servant->_default_POA(); CORBA::String_var objPOAName = objPOA->the_name(); if (strcmp(objPOAName.in(),"omniINSPOA")!=0) { CORBA::Object_var insPOAObj = orb->resolve_initial_references("omniINSPOA"); PortableServer::POA_var insPOA = PortableServer::POA::_narrow(insPOAObj); PortableServer::POAManager_var insPOAManager=insPOA->the_POAManager(); insPOAManager->activate(); PortableServer::ObjectId_var oid = PortableServer::string_to_ObjectId(objName); insPOA->activate_object_with_id(oid.in(),p_servant); } #elif defined(RSSH_TAO) #ifdef TAO_HAVE_IORTABLE_ADAPTER CORBA::Object_var table = orb->resolve_initial_references ("IORTable"); IORTable::Table_var adapter = IORTable::Table::_narrow (table.in()); if (CORBA::is_nil(adapter.in())) { cerr<<argv()[0]<<": nil IORTable reference"<<endl; } else { adapter->bind (objName, ior.in ()); } #else ACE_CString ins(objName); if (orb->_tao_add_to_IOR_table(ins,object)!=0) { return false; } #endif #elif defined(MICO) // create persistent POA with name as service name if we have no one. PortableServer::POA_var objPOA = p_servant->_default_POA(); CORBA::String_var objPOAName = objPOA->the_name(); std::cerr << "existent OBJPOAName=" << objPOAName.in() << std::endl; std::cerr << "objName=" << objName << std::endl; if (strcmp(objPOAName.in(),objName)!=0) { CORBA::Object_var rootPOAObj = orb->resolve_initial_references ("RootPOA"); PortableServer::POA_var rootPOA = PortableServer::POA::_narrow(rootPOAObj); CORBA::PolicyList pl; pl.length (2); pl[0] = rootPOA->create_lifespan_policy (PortableServer::PERSISTENT); pl[1] = rootPOA->create_id_assignment_policy (PortableServer::USER_ID); PortableServer::POA_var objPOA = rootPOA->create_POA(objName, PortableServer::POAManager::_nil (), pl); PortableServer::POAManager_var objPOAManager = objPOA->the_POAManager (); PortableServer::ObjectId_var objId = PortableServer::string_to_ObjectId (objName); objPOA->activate_object_with_id (objId.in(), p_servant); objPOAManager->activate(); }else{ //PortbaobjPOA } #endif return true; }