void ArrayDef_impl::element_type_def (IR__::IDLType_ptr type) throw(CORBA::SystemException) { DEBUG_OUTLINE ( "ArrayDef_impl::element_type_def(...) called " ); if ( CORBA::is_nil ( type ) ) { DEBUG_ERRLINE ( "nil object reference passed to ArrayDef_impl::element_type_def()" ); throw CORBA::BAD_PARAM(); } IDLType_impl* impl = 0; try { PortableServer::ServantBase_var servant = repository_ -> poa() -> reference_to_servant(type); impl = dynamic_cast<IDLType_impl*>(servant.in()); } catch(...) { } if(!impl) { // Must be in the same repository throw CORBA::BAD_PARAM(4, CORBA::COMPLETED_NO); } impl -> _add_ref(); if(element_type_) element_type_ -> _remove_ref(); element_type_ = impl; }
void AliasDef_impl::original_type_def (IR__::IDLType_ptr original_idl_type ) throw(CORBA::SystemException) { DEBUG_OUTLINE ( "AliasDef_impl::original_type_def(...) called" ); if ( CORBA::is_nil ( original_idl_type ) ) throw CORBA::BAD_PARAM(); // Is this exception correct? IDLType_impl* impl = 0; try { PortableServer::ServantBase_var servant = repository_ -> poa() -> reference_to_servant ( original_idl_type ); impl = dynamic_cast<IDLType_impl*>(servant.in()); } catch(...) { } if(!impl) { // Must be same repository throw CORBA::BAD_PARAM ( 4, CORBA::COMPLETED_NO ); } impl -> _add_ref(); if ( original_idl_type_impl_ ) original_idl_type_impl_ -> _remove_ref(); original_idl_type_impl_ = impl; }
void AttributeDef_impl::type_def (IR__::IDLType_ptr type ) throw(CORBA::SystemException) { if ( CORBA::is_nil ( type ) ) throw CORBA::BAD_PARAM(); // Is this exception correct? IDLType_impl* impl = 0; try { PortableServer::ServantBase_var servant = repository_ -> poa() -> reference_to_servant(type); impl = dynamic_cast<IDLType_impl*>(servant.in()); } catch(...) { } if(!impl) { // Must be same repository throw CORBA::BAD_PARAM ( 4, CORBA::COMPLETED_NO ); } impl -> _add_ref(); if ( idl_type_ ) idl_type_ -> _remove_ref(); idl_type_ = impl; }
void ConstantDef_impl::type_def (IR__::IDLType_ptr idl_type) throw(CORBA::SystemException) { if(CORBA::is_nil(idl_type)) throw CORBA::BAD_PARAM(); IDLType_impl* impl = 0; try { PortableServer::ServantBase_var servant = repository_ -> poa() -> reference_to_servant(idl_type); impl = dynamic_cast<IDLType_impl*>(servant.in()); } catch(...) { } if(!impl) { // The idl type object must be in the same repository throw CORBA::BAD_PARAM ( 4, CORBA::COMPLETED_NO ); } impl -> _add_ref(); if(idl_type_) idl_type_ -> _remove_ref(); idl_type_ = impl; }
Callback_ptr ServerApp::create_callback( PortableServer::POA_ptr poa, const char* servant_name) { PortableServer::ServantBase_var servant = new Callback_i(); PortableServer::ObjectId_var id = PortableServer::string_to_ObjectId("callback"); poa->activate_object_with_id(id.in(), servant.in()); CORBA::Object_var obj = poa->id_to_reference(id.in()); if (CORBA::is_nil(obj.in())) { ACE_ERROR((LM_ERROR, "(%P|%t) Failed to activate servant (%s).\n", servant_name)); throw TestException(); } Callback_var callback = Callback::_narrow (obj.in ()); return callback._retn (); }
int TAO_FT_Naming_Server::update_naming_context ( const FT_Naming::NamingContextUpdate & context_info) { ACE_GUARD_THROW_EX (ACE_SYNCH_RECURSIVE_MUTEX, ace_mon, this->lock_, CORBA::INTERNAL ()); PortableServer::ServantBase_var servant; // Lookup the servant for the identified context and see if it is // active here locally. try { // Get the servant if it exists in this process PortableServer::ObjectId_var context_id = PortableServer::string_to_ObjectId (context_info.context_name); servant = this->ns_poa_->id_to_servant (context_id); } catch (PortableServer::POA::ObjectNotActive&) { // No servant registered for this object reference so no need to create it. // It will be created on first access in incarnate function // This context is not currently active in this server so // there is nothing to be done, so return success. return 0; } TAO_Naming_Context* changed_context_servant = dynamic_cast<TAO_Naming_Context*> (servant.in ()); if (changed_context_servant == 0) { // Another type of class was used as the servant. Should not happen. ORBSVCS_ERROR ((LM_ERROR, ACE_TEXT ("(%P|%t) ERROR: Invalid servant type registered") ACE_TEXT (" with oid: %s"), context_info.context_name.in ())); return -1; } if (TAO_debug_level > 3) { ORBSVCS_DEBUG ((LM_DEBUG, ACE_TEXT ("%T %n (%P|%t) - ") ACE_TEXT ("An update of naming context with name %s ") ACE_TEXT ("has been made by the peer"), context_info.context_name.in () )); } // Mark the local context stale, so we will reload it next // time it is modified or accessed. changed_context_servant->stale (true); return 0; }
void Quoter_Stock_Factory_i::load_stock_objects ( PortableServer::POA_ptr poa, PortableServer::POAManager_ptr poa_manager, RtecEventChannelAdmin::SupplierAdmin_ptr supplier_admin) { if (!CORBA::is_nil (this->stock_factory_poa_.in ())) return; CORBA::PolicyList policies (2); policies.length (2); policies[0] = poa->create_id_assignment_policy (PortableServer::USER_ID); policies[1] = poa->create_implicit_activation_policy (PortableServer::NO_IMPLICIT_ACTIVATION); this->stock_factory_poa_ = poa->create_POA ("Stock_Factory_POA", poa_manager, policies); for (CORBA::ULong i = 0; i != policies.length (); ++i) { policies[i]->destroy (); } while (!cin.eof () && cin.peek () != EOF) { const int max_symbol_length = 8; char symbol[max_symbol_length]; const int max_full_name_length = 64; char full_name[max_full_name_length]; double price; cin.getline (symbol, max_symbol_length, '\n'); cin.getline (full_name, max_full_name_length, '\n'); cin >> price; cin.ignore (1, '\n'); Quoter_Stock_i *stock = new Quoter_Stock_i (symbol, full_name, price); PortableServer::ServantBase_var servant = stock; PortableServer::ObjectId_var oid = PortableServer::string_to_ObjectId (symbol); this->stock_factory_poa_->activate_object_with_id (oid.in (), servant.in ()); stock->connect (supplier_admin); } }
IR__::ComponentDef_ptr Container_impl::create_component (const char* id, const char* name, const char* version, IR__::ComponentDef_ptr base_component, const IR__::InterfaceDefSeq& supports_interfaces) throw(CORBA::SystemException) { DEBUG_OUTLINE ( "Container_impl::create_component() called" ); if ( repository_ -> check_for_id ( id ) ) throw CORBA::BAD_PARAM ( 2, CORBA::COMPLETED_NO ); if ( check_for_name ( name ) ) throw CORBA::BAD_PARAM ( 3, CORBA::COMPLETED_NO ); ComponentDef_impl* impl = 0; // Test the base component if there is one if ( !CORBA::is_nil ( base_component ) ) { try { PortableServer::ServantBase_var servant = repository_ -> poa() -> reference_to_servant ( base_component ); impl = dynamic_cast<ComponentDef_impl*>(servant.in()); } catch(...) { } if(!impl) { // Must be same repository throw CORBA::BAD_PARAM ( 4, CORBA::COMPLETED_NO ); } } ComponentDef_impl *new_component = new ComponentDef_impl ( this, repository_, impl ); new_component -> id ( id ); new_component -> name ( name ); new_component -> version ( version ); new_component -> supported_interfaces ( supports_interfaces ); repository_ -> _add_ref(); this -> _add_ref(); return new_component -> _this(); }
SegmentDef_impl::SegmentDef_impl ( Container_impl *container, Repository_impl *repository, IR__::ProvidesDefSeq provided_facets, IR__::StorageHomeDef_ptr stored_on) : IRObject_impl ( repository ), Contained_impl ( container, repository ) { DEBUG_OUTLINE ( "SegmentDef_impl::SegmentDef_impl() called" ); unsigned int i; vector < ProvidesDef_impl* > impl_seq; impl_seq.resize ( provided_facets.length(), NULL ); for ( i = 0; i < provided_facets.length(); i++ ) { if ( CORBA::is_nil ( provided_facets[i] ) ) throw CORBA::BAD_PARAM(); // Is this exception correct? impl_seq[i] = 0; try { PortableServer::ServantBase_var servant = repository_ -> poa() -> reference_to_servant(provided_facets[i]); impl_seq[i] = dynamic_cast<ProvidesDef_impl*>(servant.in()); } catch(...) { } if(!impl_seq[i]) { // Must be same repository throw CORBA::BAD_PARAM(4, CORBA::COMPLETED_NO); } } for ( i = 0; i < impl_seq.size(); i++ ) impl_seq[i] -> _add_ref(); for ( i = 0; i < provided_facet_impls_.size(); i++) provided_facet_impls_[i] -> _remove_ref(); provided_facet_impls_ = impl_seq; stored_on_ = stored_on; }
void AttributeDef_impl::put_exceptions (const IR__::ExceptionDefSeq& seq) throw(CORBA::SystemException) { vector < ExceptionDef_impl* > impl_seq; impl_seq.resize ( seq.length(), NULL ); unsigned int i; for ( i = 0; i < seq.length(); i++ ) { if ( CORBA::is_nil ( seq[i].in() ) ) throw CORBA::BAD_PARAM(); // Is this exception correct? impl_seq[i] = 0; try { PortableServer::ServantBase_var servant = repository_ -> poa() -> reference_to_servant(seq[i].in()); impl_seq[i] = dynamic_cast<ExceptionDef_impl*>(servant.in()); } catch(...) { } if(!impl_seq[i]) { // Must be same repository throw CORBA::BAD_PARAM(4, CORBA::COMPLETED_NO); } } for ( i = 0; i < impl_seq.size(); i++ ) impl_seq[i] -> _add_ref(); for ( i = 0; i < put_exceptions_.size(); i++) put_exceptions_[i] -> _remove_ref(); put_exceptions_ = impl_seq; }
void ReplicaController::send_reply ( PortableInterceptor::ServerRequestInfo_ptr ri) { FT::FTRequestServiceContext_var ftr ( extract_context (ri)); ACE_DEBUG ((LM_DEBUG, "(%P|%t) Sending reply for %s with rid %i\n", ftr->client_id.in (), ftr->retention_id)); // Prepare reply for logging. CORBA::Any_var result = ri->result (); TAO_OutputCDR cdr; result->impl ()->marshal_value (cdr); Dynamic::ParameterList_var pl = ri->arguments (); CORBA::ULong len = pl->length (); for (CORBA::ULong index = 0; index != len ; ++index) { //@@ No chance for PARAM_OUT if ((*pl)[index].mode == CORBA::PARAM_INOUT) { (*pl)[index].argument.impl ()->marshal_value (cdr); } } CORBA::OctetSeq_var reply; ACE_NEW (reply.out (), CORBA::OctetSeq (cdr.total_length ())); reply->length (cdr.total_length ()); CORBA::Octet* buf = reply->get_buffer (); // @@ What if this throws an exception?? We don't have any way to // check whether this succeeded for (ACE_Message_Block const* mb = cdr.begin (); mb != 0; mb = mb->cont ()) { ACE_OS::memcpy (buf, mb->rd_ptr (), mb->length ()); buf += mb->length (); } // Logging the reply and state update. // // First send message to members. // { // Extract state update. CORBA::OctetSeq_var oid = ri->object_id (); PortableInterceptor::AdapterName_var an = ri->adapter_name (); CORBA::Any_var state = ri->get_slot (state_slot_id ()); CORBA::TypeCode_var tc = state->type (); if (tc->kind () == CORBA::tk_null) { ACE_DEBUG ((LM_DEBUG, "Slot update is void\n")); PortableServer::POA_var poa = resolve_poa (an.in ()); PortableServer::ServantBase_var servant = poa->id_to_servant (oid.in ()); Checkpointable* target = dynamic_cast<Checkpointable*> (servant.in ()); if (target) { CORBA::Any_var tmp = target->get_state (); if (tmp.ptr () != 0) state = tmp._retn (); } } TAO_OutputCDR cdr; cdr << oid.in (); cdr << an.in (); cdr << ftr->client_id.in (); cdr << ftr->retention_id; cdr << reply.in (); cdr << state.in (); size_t size = cdr.total_length (); CORBA::OctetSeq_var msg; ACE_NEW (msg.out (), CORBA::OctetSeq (size)); msg->length (size); { CORBA::Octet* buf = msg->get_buffer (); for (ACE_Message_Block const* mb = cdr.begin (); mb != 0; mb = mb->cont ()) { ACE_OS::memcpy (buf, mb->rd_ptr (), mb->length ()); buf += mb->length (); } } CORBA::Octet* buf = msg->get_buffer (); // Crash point 1. // if (crash_point == 1 && ftr->retention_id > 2) ACE_OS::exit (1); try { while (true) { try { group_->send (buf, size); ACE_DEBUG ((LM_DEBUG, "Sent log record of length %i\n", size)); break; } catch (ACE_TMCast::Group::Aborted const&) { ACE_DEBUG ((LM_DEBUG, "Retrying to send log record.\n")); } } } catch (ACE_TMCast::Group::Failed const&) { ACE_DEBUG ((LM_DEBUG, "Group failure. Perhaps, I am alone in the group.\n")); } } // Now perform local logging. // RecordId rid (ftr->client_id.in (), ftr->retention_id); // This is slow but eh-safe ;-). // log_.insert (rid, reply); // Crash point 2. // if (crash_point == 2 && ftr->retention_id > 2) ACE_OS::exit (1); }
int ACE_TMAIN(int argc, ACE_TCHAR *argv[]) { try { // Initialize the ORB. CORBA::ORB_var orb = CORBA::ORB_init (argc, argv); // Obtain the RootPOA. CORBA::Object_var object = orb->resolve_initial_references ("RootPOA"); // Narrow to POA. PortableServer::POA_var root_poa = PortableServer::POA::_narrow (object.in ()); // Get the POAManager of the RootPOA. PortableServer::POAManager_var poa_manager = root_poa->the_POAManager (); // Policies for the new POA. CORBA::PolicyList policies (3); policies.length (3); // Request Processing Policy. policies[0] = root_poa->create_request_processing_policy (PortableServer::USE_DEFAULT_SERVANT); // Id Uniqueness Policy. policies[1] = root_poa->create_id_uniqueness_policy (PortableServer::MULTIPLE_ID); // Servant Retention Policy. policies[2] = root_poa->create_servant_retention_policy (PortableServer::NON_RETAIN); // Create POA to host default servant. ACE_CString name = "Default Servant"; PortableServer::POA_var default_servant_poa = root_poa->create_POA (name.c_str (), poa_manager.in (), policies); // Destroy policies. for (CORBA::ULong i = 0; i < policies.length (); ++i) { CORBA::Policy_ptr policy = policies[i]; policy->destroy (); } // Activate POA manager. poa_manager->activate (); test_reference_to_servant_active_object(root_poa.in ()); // Test servant. test_i test; CORBA::ULong expected_refcount = 1; (void) test_get_servant_with_no_set (default_servant_poa.in()); (void) test_get_servant_manager (default_servant_poa.in()); (void) test_set_servant_manager (default_servant_poa.in()); // Register default servant. default_servant_poa->set_servant (&test); expected_refcount++; // Create dummy id. PortableServer::ObjectId_var id = PortableServer::string_to_ObjectId ("id"); // Create dummy object. object = default_servant_poa->create_reference ("IDL:test:1.0"); // Invoke id_to_servant(). Should retrieve default servant. PortableServer::ServantBase_var servant = default_servant_poa->id_to_servant (id.in ()); expected_refcount++; // Assert correctness. ACE_ASSERT (&test == servant.in()); // Invoke reference_to_servant(). Should retrieve default servant. servant = default_servant_poa->reference_to_servant (object.in ()); expected_refcount++; // Assert correctness. ACE_ASSERT (&test == servant.in()); // Report success. ACE_DEBUG ((LM_DEBUG, "Default_Servant test successful\n")); CORBA::ULong refcount = test._refcount_value (); ACE_UNUSED_ARG (refcount); ACE_UNUSED_ARG (expected_refcount); ACE_ASSERT (expected_refcount == refcount); // Destroy the ORB. orb->destroy (); } catch (const CORBA::Exception& ex) { ex._tao_print_exception ("Exception caught"); return -1; } return 0; }
void Lorica::Proxy::configure(Config & config, const std::string &def_ior_file ) throw (InitError) { try { // This should be OK even if multiple copies of Proxy // get created as they all create the same ORB instance // and therefore the single ORB instance will get shutdown. Lorica::Proxy::this_ = this; std::auto_ptr<ACE_ARGV> arguments(config.get_orb_options()); // Create proxy ORB. int argc = arguments->argc(); if (Lorica_debug_level > 2) { ACE_DEBUG((LM_DEBUG, ACE_TEXT("(%T) %N:%l - passing %d args to ORB_init:\n"), argc)); for (int i = 0; i < argc; i++) ACE_DEBUG((LM_DEBUG, ACE_TEXT("%N:%l - %s\n"), arguments->argv()[i])); } orb_ = CORBA::ORB_init(argc, arguments->argv()); // test if we have any security functionality ACE_Service_Repository * repo = orb_->orb_core()->configuration()-> current_service_repository(); config.secure_available(repo->find("SSLIOP_Factory") == 0); int attempts = 3; CORBA::Object_var obj = CORBA::Object::_nil(); resolve_again: try { obj = orb_->resolve_initial_references("RootPOA"); } catch (CORBA::Exception & ex) { if (attempts--) { ACE_DEBUG((LM_INFO, ACE_TEXT("(%T) %N:%l - Exception trying to resolve initial references\n"))); ACE_OS::sleep(10); goto resolve_again; } ACE_DEBUG((LM_ERROR, ACE_TEXT("(%T) %N:%l - %s\n"), ex._info().c_str())); throw InitError(); } root_poa_ = PortableServer::POA::_narrow(obj.in()); if (CORBA::is_nil(root_poa_.in())) { ACE_ERROR((LM_ERROR, "(%T) %N:%l - could not get root POA\n")); throw InitError(); } pmf_ = root_poa_->the_POAManagerFactory(); if (CORBA::is_nil(pmf_.in())) { ACE_ERROR((LM_ERROR, "(%T) %N:%l - could not get PMF\n")); throw InitError(); } obj = orb_->resolve_initial_references("IORTable"); iorTable_ = IORTable::Table::_narrow(obj.in()); if (CORBA::is_nil(iorTable_.in())) { ACE_ERROR((LM_ERROR, "(%T) %N:%l - could not get IORTable\n")); throw InitError(); } CORBA::PolicyList policies; EndpointPolicy::EndpointList list; CORBA::Any policy_value; // Create external POA manager Config::Endpoints ex_points = config.get_endpoints(true); policies.length(1); list.length(ex_points.size()); if (Lorica_debug_level > 2) { ACE_DEBUG((LM_DEBUG, ACE_TEXT("(%T) %N:%l - setting up External POA manager with %d endpoints\n"), ex_points.size())); } for (size_t count = 0; count < ex_points.size(); count++) { std::string inter = ex_points[count].hostname_; if (!ex_points[count].alias_.empty()) inter = ex_points[count].alias_; list[count] = new IIOPEndpointValue_i(inter.c_str(), ex_points[count].port_); } policy_value <<= list; policies[0] = orb_->create_policy(EndpointPolicy::ENDPOINT_POLICY_TYPE, policy_value); outside_pm_ = pmf_->create_POAManager("OutsidePOAManager", policies); // Create internal POA manager. Config::Endpoints in_points = config.get_endpoints(false); policies.length(1); list.length(in_points.size()); if (Lorica_debug_level > 2) { ACE_DEBUG((LM_DEBUG, ACE_TEXT("(%T) %N:%l - setting up Internal POA manager with %d endpoints\n"), in_points.size())); } for (size_t count = 0; count < in_points.size(); count++) { std::string inter = in_points[count].hostname_; if (!in_points[count].alias_.empty()) inter = in_points[count].alias_; list[count] = new IIOPEndpointValue_i(inter.c_str(), in_points[count].port_); } policy_value <<= list; policies[0] = orb_->create_policy(EndpointPolicy::ENDPOINT_POLICY_TYPE, policy_value); inside_pm_ = pmf_->create_POAManager("InsidePOAManager", policies); if (Lorica_debug_level > 2) { ACE_DEBUG((LM_DEBUG, ACE_TEXT("(%T) %N:%l - creating admin POA with internal POA manager\n"))); } policies.length(0); admin_poa_ = root_poa_->create_POA("adminPOA", inside_pm_.in(), policies); try { ReferenceMapper_i *refMapper = new ReferenceMapper_i(orb_.in(), iorTable_.in(), config.secure_available()); PortableServer::ServantBase_var refMapperServant = refMapper; PortableServer::ObjectId_var oid = admin_poa_->activate_object(refMapperServant.in()); obj = admin_poa_->id_to_reference(oid.in()); // refMapper->allow_insecure_access (obj.in()); } catch (CORBA::Exception & ex) { ACE_DEBUG((LM_ERROR, ACE_TEXT("(%T) %N:%l - %s\n"), ex._info().c_str())); throw InitError(); } ReferenceMapper_var refMapper_obj = ReferenceMapper::_narrow(obj.in()); CORBA::String_var ior = orb_->object_to_string(refMapper_obj.in()); iorTable_->bind(Lorica::ReferenceMapper::IOR_TABLE_KEY, ior.in()); this->ior_file_ = config.get_value("IOR_FILE", def_ior_file); FILE *output_file = ACE_OS::fopen (ACE_TEXT_CHAR_TO_TCHAR (this->ior_file_.c_str()), ACE_TEXT("w")); if (!output_file) { ACE_ERROR((LM_ERROR, "(%T) %N:%l - cannot open output file for writing IOR: %s\n", this->ior_file_.c_str())); throw InitError(); } ACE_OS::fprintf(output_file, "%s", ior.in()); ACE_OS::fclose(output_file); if (!setup_shutdown_handler()) { ACE_ERROR ((LM_ERROR, "(%T) %N:%l - could not set up shutdown handler\n")); throw InitError(); } // Initialize the mapper registry Lorica_MapperRegistry *mreg = ACE_Dynamic_Service<Lorica_MapperRegistry>::instance (this->orb_->orb_core()->configuration(),"MapperRegistry"); std::string ne_ids = config.null_eval_type_ids(); if (!ne_ids.empty()) { if (Lorica_debug_level > 2) { ACE_DEBUG((LM_DEBUG, ACE_TEXT("(%T) %N:%l - adding type ids for null ") ACE_TEXT("evaluator: %s\n"), ne_ids.c_str())); } size_t space = ne_ids.find(' '); size_t start = 0; while (space != std::string::npos) { mreg->add_null_mapper_type(ne_ids.substr(start,space - start)); start = space+1; space = ne_ids.find(' ',start); } mreg->add_null_mapper_type(ne_ids.substr(start)); } else if (config.null_eval_any()) { if (Lorica_debug_level > 2) ACE_DEBUG((LM_DEBUG, ACE_TEXT("(%T) %N:%l - creating default null mapper\n"))); mreg->create_default_null_mapper(); } if (config.generic_evaluator()) { if (Lorica_debug_level > 0) { ACE_DEBUG((LM_DEBUG, ACE_TEXT("(%T) %N:%l - loading generic evaluator\n"))); } #ifdef ACE_WIN32 this->orb_->orb_core()->configuration()->process_directive (ACE_TEXT_ALWAYS_CHAR (ACE_DYNAMIC_SERVICE_DIRECTIVE("Lorica_GenericLoader", "lorica_GenericEvaluator", "_make_Lorica_GenericLoader", "") ) ); #else Lorica::GenericMapper *gen_eval = new Lorica::GenericMapper(debug_, *mreg); mreg->add_proxy_mapper(gen_eval); #endif } // add generic or other mappers... mreg->init_mappers(this->outside_pm_, this->inside_pm_, this->orb_, config.secure_available()); // last thing to do, put both POAs in the active state. outside_pm_->activate(); inside_pm_->activate(); } catch (CORBA::Exception & ex) { ACE_DEBUG((LM_ERROR, ACE_TEXT("(%T) %N:%l - %s\n"), ex._info().c_str())); throw InitError(); } catch (...) { ACE_ERROR((LM_ERROR, "%N:%l - Caught an otherwise unknown exception\n")); throw InitError(); } }
int main (int argc, char *argv[]) { try { orb = CORBA::ORB_init (argc, argv, ""); CORBA::Object_var poa_object = orb->resolve_initial_references("RootPOA"); PortableServer::POA_var root_poa = PortableServer::POA::_narrow (poa_object.in ()); if (CORBA::is_nil (root_poa.in ())) ACE_ERROR_RETURN ((LM_ERROR, " (%P|%t) Panic: nil RootPOA\n"), 1); PortableServer::POAManager_var poa_manager = root_poa->the_POAManager (); if (parse_args (argc, argv) != 0) return 1; CORBA::PolicyList policies(2); policies.length(2); policies[0] = root_poa->create_lifespan_policy(PortableServer::PERSISTENT); policies[1] = root_poa->create_id_assignment_policy(PortableServer::USER_ID); PortableServer::POA_var child_poa = root_poa->create_POA ("persistent", poa_manager.in(), policies); poa_manager->activate(); PortableServer::ServantBase_var servant (new Hello); PortableServer::ObjectId_var oid = PortableServer::string_to_ObjectId ("gctest"); child_poa->activate_object_with_id (oid.in(), servant.in() ); CORBA::Object_var obj = child_poa->id_to_reference (oid.in()); Test::Hello_var hello = Test::Hello::_narrow (obj.in()); if (!no_register) { obj = orb->string_to_object (lorica_ior); mapper = Lorica::ReferenceMapper::_narrow(obj.in()); if (CORBA::is_nil(mapper.in())) ACE_ERROR_RETURN ((LM_ERROR, "Cannot get reference to Lorica " "reference mapper\n"),1); obj = mapper->as_server(hello.in(),"Hello", Lorica::ServerAgent::_nil()); if (CORBA::is_nil (obj.in())) ACE_ERROR_RETURN ((LM_ERROR, "Lorica reference mapper returned a nil " "mapped reference.\n"),1); mapped_hello = Test::Hello::_narrow(obj.in()); if (CORBA::is_nil(mapped_hello.in())) ACE_ERROR_RETURN ((LM_ERROR, "Lorica reference mapper returned an " "incorrectly typed reference\n"),1); CORBA::String_var orig_ior = orb->object_to_string (hello.in ()); CORBA::String_var mapped_ior = orb->object_to_string (mapped_hello.in()); if (ACE_OS::strcmp (orig_ior.in(), mapped_ior.in()) == 0) ACE_ERROR_RETURN ((LM_ERROR, "Lorica reference mapper returned " "the original reference unmapped.\n"),1); ACE_DEBUG ((LM_DEBUG,"writing original IOR to file %s\n",orig_file)); ACE_DEBUG ((LM_DEBUG,"writing mapped IOR to file %s\n",mapped_file)); ACE_DEBUG ((LM_DEBUG,"Size of orig IOR = %d, size of mapped = %d\n", ACE_OS::strlen(orig_ior.in()), ACE_OS::strlen(mapped_ior.in()))); FILE *output_file= ACE_OS::fopen (mapped_file, "w"); if (output_file == 0) ACE_ERROR_RETURN ((LM_ERROR, "Cannot open output file for writing IOR: %s\n", mapped_file), 1); ACE_OS::fprintf (output_file, "%s", mapped_ior.in()); ACE_OS::fclose (output_file); output_file= ACE_OS::fopen (orig_file, "w"); if (output_file == 0) ACE_ERROR_RETURN ((LM_ERROR, "Cannot open output file for writing IOR: %s\n", orig_file), 1); ACE_OS::fprintf (output_file, "%s", orig_ior.in()); ACE_OS::fclose (output_file); } ACE_Time_Value delay(8,0); // run for 8 seconds, which gets past 1 gc // iterateion and gives client time for 2 // string gets. orb->run(delay); // No need to run the ORB the test only requires modifying an IOR orb->destroy (); } catch (const CORBA::Exception& ex) { ex._tao_print_exception ("Exception caught:"); return 1; } return 0; }
int ACE_TMAIN(int argc, ACE_TCHAR *argv[]) { try { CORBA::ORB_var orb = CORBA::ORB_init (argc, argv); CORBA::Object_var poa_object = orb->resolve_initial_references ("RootPOA"); PortableServer::POA_var root_poa = PortableServer::POA::_narrow (poa_object.in ()); if (CORBA::is_nil (root_poa.in ())) ACE_ERROR_RETURN ((LM_ERROR, " (%P|%t) Panic: nil RootPOA\n"), 1); PortableServer::POAManager_var poa_manager = root_poa->the_POAManager (); if (parse_args (argc, argv) != 0) return 1; PortableServer::ServantBase_var impl; { Echo * tmp = 0; // ACE_NEW_RETURN is the worst possible way to handle // exceptions (think: what if the constructor allocates memory // and fails?), but I'm not in the mood to fight for a more // reasonable way to handle allocation errors in ACE. ACE_NEW_RETURN (tmp, Echo(orb.in(), 1000 / serverthreads), 1); impl = tmp; } PortableServer::ObjectId_var id = root_poa->activate_object (impl.in ()); CORBA::Object_var object_act = root_poa->id_to_reference (id.in ()); Test::Echo_var echo = Test::Echo::_narrow (object_act.in ()); CORBA::Object_var tmp = orb->string_to_object(ior); Test::Echo_Caller_var server = Test::Echo_Caller::_narrow(tmp.in ()); if (CORBA::is_nil (server.in ())) { ACE_ERROR_RETURN ((LM_DEBUG, "Nil Test::Echo_Caller reference <%s>\n", ior), 1); } poa_manager->activate (); ORB_Task worker (orb.in()); worker.activate (THR_NEW_LWP | THR_JOINABLE, serverthreads); try { for(int i = serverthreads; i; --i) { server->start_task(echo.in()); } } catch (...) { } Client_Timer * task = new Client_Timer (orb->orb_core()->reactor()); task->activate (); task->remove_reference (); orb->run (); worker.wait (); ACE_DEBUG ((LM_DEBUG, "(%P|%t) client - event loop finished\n")); // Actually the code here should never be reached. root_poa->destroy (1, 1); orb->destroy (); } catch (const CORBA::Exception& ex) { ex._tao_print_exception ("Exception caught:"); return 1; } return 0; }
bool AsyncAccessManager::send_start_request (void) { if (ImR_Locator_i::debug () > 4) { ORBSVCS_DEBUG ((LM_DEBUG, ACE_TEXT ("(%P|%t) AsyncAccessManager::send_start_request, manual_start_ %d\n"), this->manual_start_)); } if ((this->locator_.opts ()->lockout () && !this->info_.edit ()->start_allowed ()) || (this->retries_ == 0)) { this->status (ImplementationRepository::AAM_RETRIES_EXCEEDED); return false; } --this->retries_; if (this->info_->is_mode (ImplementationRepository::MANUAL) && !this->manual_start_) { this->status (ImplementationRepository::AAM_NOT_MANUAL); return false; } const Server_Info *startup = this->info_->active_info (); if (startup->cmdline.length () == 0) { this->status (ImplementationRepository::AAM_NO_COMMANDLINE); return false; } Activator_Info_Ptr ainfo = this->locator_.get_activator (startup->activator); if (ainfo.null () || CORBA::is_nil (ainfo->activator.in ())) { this->status (ImplementationRepository::AAM_NO_ACTIVATOR); return false; } PortableServer::ServantBase_var callback = new ActivatorReceiver (this, this->poa_.in()); PortableServer::ObjectId_var oid = this->poa_->activate_object (callback.in()); CORBA::Object_var obj = this->poa_->id_to_reference (oid.in()); ImplementationRepository::AMI_ActivatorHandler_var cb = ImplementationRepository::AMI_ActivatorHandler::_narrow (obj.in()); ACE_CString servername; if (this->info_->is_mode (ImplementationRepository::PER_CLIENT)) { servername = startup->key_name_; } else { servername = unique_prefix + startup->key_name_; } ainfo->activator->sendc_start_server (cb.in(), servername.c_str (), startup->cmdline.c_str (), startup->dir.c_str (), startup->env_vars); this->update_status (ImplementationRepository::AAM_ACTIVATION_SENT); return true; }
void ReplicaController:: listener () { try { for (char buffer[1024];;) { size_t n = group_->recv (buffer, sizeof (buffer)); ACE_HEX_DUMP ((LM_DEBUG, buffer, n)); TAO_InputCDR cdr (buffer, n); CORBA::OctetSeq object_id; PortableInterceptor::AdapterName adapter_name; CORBA::String_var client_id; CORBA::Long retention_id; CORBA::OctetSeq reply; CORBA::Any state; cdr >> object_id; cdr >> adapter_name; cdr >> client_id.out (); cdr >> retention_id; cdr >> reply; cdr >> state; if (!cdr.good_bit ()) { ACE_DEBUG ((LM_DEBUG, "CDR failed\n")); //@@ what to do? } ACE_DEBUG ((LM_DEBUG, "Received log for %s with rid %i\n", client_id.in (), retention_id)); RecordId rid (client_id.in (), retention_id); CORBA::OctetSeq_var tmp (new CORBA::OctetSeq (reply)); log_.insert (rid, tmp); // Update state. CORBA::TypeCode_var tc = state.type (); if (tc->kind () != CORBA::tk_null) { PortableServer::POA_var poa = resolve_poa (adapter_name); PortableServer::ServantBase_var servant = poa->id_to_servant (object_id); Checkpointable* target = dynamic_cast<Checkpointable*> (servant.in ()); if (target) target->set_state (state); } } } catch (ACE_TMCast::Group::Failed const&) { ACE_DEBUG ((LM_DEBUG, "Group failure. Perhaps, I am alone in the group.\n")); } catch (ACE_TMCast::Group::InsufficienSpace const&) { ACE_DEBUG ((LM_DEBUG, "Group::InsufficienSpace\n")); } orb_->shutdown (0); }
int ACE_TMAIN(int argc, ACE_TCHAR *argv[]) { try { CORBA::ORB_var orb = CORBA::ORB_init (argc, argv); CORBA::Object_var poa_object = orb->resolve_initial_references("RootPOA"); PortableServer::POA_var poa = PortableServer::POA::_narrow (poa_object.in ()); if (CORBA::is_nil (poa.in ())) ACE_ERROR_RETURN ((LM_ERROR, " (%P|%t) Panic: nil RootPOA\n"), 1); Hello_impl * h = 0; ACE_NEW_RETURN (h,Hello_impl, 1); CORBA::ULong before_act = h->_refcount_value (); ACE_DEBUG ((LM_DEBUG, "Before activation: %d\n", before_act)); PortableServer::ObjectId_var oid = poa->activate_object (h); CORBA::ULong after_act = h->_refcount_value (); ACE_DEBUG ((LM_DEBUG, "After activation: %d\n", after_act)); { /* * C++ Language Mapping (formal/03-06-03), section 1.37.3 (Servant * Memory Management Considerations), first bullet on page 1-136: * * POA::id_to_servant returns a Servant. The POA invokes _add_ref * once on the Servant before returning it; the caller of * id_to_servant is responsible for invoking _remove_ref on the * returned servant when it is finished with it. */ CORBA::ULong refCountBeforeIdToServant = h->_refcount_value (); ACE_DEBUG ((LM_DEBUG, "Before id_to_servant: %d\n", refCountBeforeIdToServant)); PortableServer::ServantBase_var srv = poa->id_to_servant (oid.in()); CORBA::ULong refCountAfterIdToServant = srv->_refcount_value ();; ACE_DEBUG ((LM_DEBUG, "After id_to_servant: %d\n", refCountAfterIdToServant)); /* * According to the above quote, this assertion shall be true. */ ACE_ASSERT (refCountAfterIdToServant == refCountBeforeIdToServant + 1); /* * At the end of this scope, "srv" is destructed, which decrements * the servant's reference count. */ } CORBA::ULong before_deact = h->_refcount_value (); ACE_DEBUG ((LM_DEBUG, "Before deactivate_object: %d\n", before_deact)); poa->deactivate_object (oid.in()); /* * Because id_to_servant did not increment the reference count, but * the reference count was decremented by the "srv" destructor, the * reference count, using TAO 1.4.5, is now 0, and the servant has * been destructed. So the following will crash, despite being * correct. */ CORBA::ULong after_deact = h->_refcount_value (); ACE_DEBUG ((LM_DEBUG, "After deactivate_object: %d\n", after_deact)); h->_remove_ref (); orb->shutdown (1); orb->destroy (); } catch (const CORBA::Exception& ex) { ex._tao_print_exception ("Exception caught:"); return 1; } return 0; }
IR__::HomeDef_ptr Container_impl::create_home (const char* id, const char* name, const char* version, IR__::HomeDef_ptr base_home, IR__::ComponentDef_ptr managed_component, const IR__::InterfaceDefSeq& supports_interfaces, IR__::ValueDef_ptr primary_key) throw(CORBA::SystemException) { DEBUG_OUTLINE ( "Container_impl::create_home() called" ); if ( repository_ -> check_for_id ( id ) ) throw CORBA::BAD_PARAM ( 2, CORBA::COMPLETED_NO ); if ( check_for_name ( name ) ) throw CORBA::BAD_PARAM ( 3, CORBA::COMPLETED_NO ); HomeDef_impl* base_home_impl = 0; ComponentDef_impl* managed_component_impl = 0; ValueDef_impl* primary_key_impl = 0; // Test the base home if there is one if ( !CORBA::is_nil ( base_home ) ) { try { PortableServer::ServantBase_var servant = repository_ -> poa() -> reference_to_servant ( base_home ); base_home_impl = dynamic_cast<HomeDef_impl*>(servant.in()); } catch(...) { } if(!base_home_impl) { // Must be same repository throw CORBA::BAD_PARAM ( 4, CORBA::COMPLETED_NO ); } } // Test the managed component if ( CORBA::is_nil ( managed_component ) ) throw CORBA::BAD_PARAM(); // Is this exception corect? try { PortableServer::ServantBase_var servant = repository_ -> poa() -> reference_to_servant ( managed_component ); managed_component_impl = dynamic_cast<ComponentDef_impl*>(servant.in()); } catch(...) { } if(!managed_component_impl) { // Must be same repository throw CORBA::BAD_PARAM ( 4, CORBA::COMPLETED_NO ); } // Test the primary key if there is one if ( !CORBA::is_nil ( primary_key ) ) { try { PortableServer::ServantBase_var servant = repository_ -> poa() -> reference_to_servant ( primary_key ); primary_key_impl = dynamic_cast<ValueDef_impl*>(servant.in()); } catch(...) { } if(!primary_key_impl) { // Must be same repository throw CORBA::BAD_PARAM ( 4, CORBA::COMPLETED_NO ); } } HomeDef_impl *new_home = new HomeDef_impl ( this, repository_, base_home_impl, managed_component_impl, primary_key_impl ); new_home -> id ( id ); new_home -> name ( name ); new_home -> version ( version ); new_home -> supported_interfaces ( supports_interfaces ); repository_ -> _add_ref(); this -> _add_ref(); return new_home -> _this(); }