// // initialize_poa // void Tao_Data_Channel_Service::initialize_poa (::PortableServer::POA_ptr poa) { // Construct the policy list for the LoggingServerPOA. ::CORBA::PolicyList policies (6); policies.length (6); policies[0] = poa->create_thread_policy (PortableServer::ORB_CTRL_MODEL); policies[1] = poa->create_servant_retention_policy (PortableServer::RETAIN); policies[2] = poa->create_id_assignment_policy (PortableServer::SYSTEM_ID); policies[3] = poa->create_id_uniqueness_policy (PortableServer::UNIQUE_ID); policies[4] = poa->create_lifespan_policy (PortableServer::TRANSIENT); policies[5] = poa->create_request_processing_policy (PortableServer::USE_ACTIVE_OBJECT_MAP_ONLY); // Create the child POA for the test logger factory servants. this->poa_ = poa->create_POA ("DataChannelPOA", ::PortableServer::POAManager::_nil (), policies); for (size_t i = 0; i < 6; ++ i) policies[i]->destroy (); // Activate this POA's manager. PortableServer::POAManager_var the_mgr = this->poa_->the_POAManager (); the_mgr->activate (); }
PortableServer::POA_ptr ServerApp::create_poa(CORBA::ORB_ptr orb, const char* poa_name) { // Get the Root POA. PortableServer::POA_var root_poa = RefHelper<PortableServer::POA>::resolve_initial_ref(orb, "RootPOA"); // Get the POAManager from the Root POA. PortableServer::POAManager_var poa_manager = root_poa->the_POAManager(); // Create the child POA Policies. CORBA::PolicyList policies(0); policies.length(0); // Create the child POA PortableServer::POA_var poa = AppHelper::create_poa(poa_name, root_poa.in(), poa_manager.in(), policies); // Give away the child POA_ptr from the POA_var variable. return poa._retn(); }
void def(std::string const &name, R (*f)(BOOST_PP_ENUM_PARAMS(n,T)), policies const &p = policies()) { add_function(name, boost::shared_ptr<details::callback_base>( new details::BOOST_PP_CAT(callback,n)<R BOOST_PP_COMMA_IF(n) BOOST_PP_ENUM_PARAMS(n,T)>(f)), p); }
Test::Hello_var prepare_tests (CORBA::ORB_ptr orb, PortableServer::POA_ptr root_poa) { register_factories(orb); CORBA::Object_var objectman = orb->resolve_initial_references ("ORBPolicyManager"); CORBA::PolicyManager_var policy_manager = CORBA::PolicyManager::_narrow (objectman.in ()); PortableServer::POA_var my_compress_poa = 0; CORBA::PolicyList policies(4); policies.length(4); try { policies[0] = create_compressor_id_level_list_policy (orb); policies[1] = create_low_value_policy (orb); policies[2] = create_compression_enabled_policy (orb); policies[3] = create_min_ratio_policy (orb); my_compress_poa = root_poa->create_POA("My_Compress_Poa", 0, policies); } catch(const CORBA::PolicyError&) { policies.length(0); my_compress_poa = root_poa->create_POA("My_Compress_Poa", 0, policies); } policy_manager->set_policy_overrides (policies, CORBA::ADD_OVERRIDE); CORBA::Object_var pcobject = orb->resolve_initial_references ("PolicyCurrent"); CORBA::PolicyCurrent_var policy_current = CORBA::PolicyCurrent::_narrow (pcobject.in ()); policy_current->set_policy_overrides (policies, CORBA::ADD_OVERRIDE); PortableServer::POAManager_var poa_manager = my_compress_poa->the_POAManager (); Hello *hello_impl = 0; ACE_NEW_RETURN (hello_impl, Hello (orb), 0); PortableServer::ServantBase_var owner_transfer(hello_impl); PortableServer::ObjectId_var id = my_compress_poa->activate_object (hello_impl); CORBA::Object_var object = my_compress_poa->id_to_reference (id.in ()); Test::Hello_var hello = Test::Hello::_narrow (object.in ()); poa_manager->activate (); return hello._retn (); }
// RFC5820 4.2.1.4. Certificate Policies // // "The user-initial-policy-set contains the special value any-policy if the // user is not concerned about certificate policy." Result CheckCertificatePolicies(BackCert& cert, EndEntityOrCA endEntityOrCA, bool isTrustAnchor, SECOidTag requiredPolicy) { if (requiredPolicy == SEC_OID_X509_ANY_POLICY) { return Success; } // It is likely some callers will pass SEC_OID_UNKNOWN when they don't care, // instead of passing SEC_OID_X509_ANY_POLICY. Help them out by failing hard. if (requiredPolicy == SEC_OID_UNKNOWN) { PR_SetError(SEC_ERROR_INVALID_ARGS, 0); return FatalError; } // Bug 989051. Until we handle inhibitAnyPolicy we will fail close when // inhibitAnyPolicy extension is present and we need to evaluate certificate // policies. if (cert.encodedInhibitAnyPolicy) { PR_SetError(SEC_ERROR_POLICY_VALIDATION_FAILED, 0); return RecoverableError; } // The root CA certificate may omit the policies that it has been // trusted for, so we cannot require the policies to be present in those // certificates. Instead, the determination of which roots are trusted for // which policies is made by the TrustDomain's GetCertTrust method. if (isTrustAnchor && endEntityOrCA == MustBeCA) { return Success; } if (!cert.encodedCertificatePolicies) { PR_SetError(SEC_ERROR_POLICY_VALIDATION_FAILED, 0); return RecoverableError; } ScopedPtr<CERTCertificatePolicies, CERT_DestroyCertificatePoliciesExtension> policies(CERT_DecodeCertificatePoliciesExtension( cert.encodedCertificatePolicies)); if (!policies) { return MapSECStatus(SECFailure); } for (const CERTPolicyInfo* const* policyInfos = policies->policyInfos; *policyInfos; ++policyInfos) { if ((*policyInfos)->oid == requiredPolicy) { return Success; } // Intermediate certs are allowed to have the anyPolicy OID if (endEntityOrCA == MustBeCA && (*policyInfos)->oid == SEC_OID_X509_ANY_POLICY) { return Success; } } PR_SetError(SEC_ERROR_POLICY_VALIDATION_FAILED, 0); return RecoverableError; }
class_definer & def(std::string const &name, R (C::*f)(BOOST_PP_ENUM_PARAMS(n,T)), policies const &p = policies()) { ch_->register_method(name, boost::shared_ptr<details::object_cmd_base>( new details::BOOST_PP_CAT(method,n)<C, R BOOST_PP_COMMA_IF(n) BOOST_PP_ENUM_PARAMS(n,T)>(f)), p); return *this; }
Test::Hello_var create_policies (CORBA::ORB_ptr orb, bool add_zlib_compressor) { CORBA::PolicyList policies(4); policies.length(4); policies[0] = create_compressor_id_level_list_policy (orb, add_zlib_compressor); policies[1] = create_low_value_policy (orb); policies[2] = create_compression_enabled_policy (orb); policies[3] = create_min_ratio_policy (orb); CORBA::Object_var tmp = orb->string_to_object(ior); CORBA::Object_var tmp2 = tmp->_set_policy_overrides (policies, CORBA::ADD_OVERRIDE); Test::Hello_var hello = Test::Hello::_narrow(tmp2.in ()); return hello._retn (); }
int ACE_TMAIN (int argc, ACE_TCHAR *argv[]) { // Put orb outside try scope since there will be an // exception and it will not be possible to call // orb->destroy() at the end, hence memory leak. CORBA::ORB_var orb = CORBA::ORB::_nil(); try { // Initialize the ORB. // orb = CORBA::ORB_init(argc, argv); CORBA::Object_var poa_obj = orb->resolve_initial_references("RootPOA"); PortableServer::POA_var root_poa = PortableServer::POA::_narrow(poa_obj.in ()); // Create a PERSISTENT POA // // Create the policy list 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); // create the poa. // for ORBUseIMR=1 -ORBDefaultInitRef corbaloc:iiop:<HOST>:<PORT> // this will cause an access violation if no IMR server is found. // The access violation WILL NOT HAPPEN if a POAManager is created and // given as a parameter to create_POA (instead of a nil POAManager) PortableServer::POA_var persistent_poa = root_poa->create_POA("myPoa", PortableServer::POAManager::_nil(), policies); return 0; } catch (const CORBA::Exception&) { // ... normally print an error here } orb->destroy (); return 0; }
TEST_FIXTURE(blob_test_base, container_stored_policy) { auto stored_permissions = m_container.download_permissions(azure::storage::access_condition(), azure::storage::blob_request_options(), m_context); CHECK(stored_permissions.policies().empty()); auto now = utility::datetime::utc_now(); auto aligned_now = now - (now.to_interval() % (10 * 1000 * 1000)); azure::storage::blob_shared_access_policy policy; policy.set_permissions(azure::storage::blob_shared_access_policy::permissions::write); policy.set_start(aligned_now - utility::datetime::from_minutes(5)); policy.set_expiry(aligned_now + utility::datetime::from_minutes(30)); azure::storage::blob_container_permissions permissions; permissions.policies()[_XPLATSTR("id1")] = policy; m_container.upload_permissions(permissions, azure::storage::access_condition(), azure::storage::blob_request_options(), m_context); std::this_thread::sleep_for(std::chrono::seconds(30)); auto blob = m_container.get_block_blob_reference(_XPLATSTR("blob")); blob.upload_text(_XPLATSTR("test"), azure::storage::access_condition(), azure::storage::blob_request_options(), m_context); auto sas_token = blob.get_shared_access_signature(azure::storage::blob_shared_access_policy(), _XPLATSTR("id1")); check_access(sas_token, azure::storage::blob_shared_access_policy::permissions::write, azure::storage::cloud_blob_shared_access_headers(), blob); stored_permissions = m_container.download_permissions(azure::storage::access_condition(), azure::storage::blob_request_options(), m_context); CHECK_EQUAL(1U, stored_permissions.policies().size()); auto stored_policy = stored_permissions.policies().find(_XPLATSTR("id1")); CHECK(stored_policy != stored_permissions.policies().end()); CHECK_EQUAL(policy.permission(), stored_policy->second.permission()); CHECK_EQUAL(policy.start().to_interval(), stored_policy->second.start().to_interval()); CHECK_EQUAL(policy.expiry().to_interval(), stored_policy->second.expiry().to_interval()); stored_permissions.policies().clear(); m_container.upload_permissions(stored_permissions, azure::storage::access_condition(), azure::storage::blob_request_options(), m_context); std::this_thread::sleep_for(std::chrono::seconds(30)); check_access(sas_token, azure::storage::blob_shared_access_policy::permissions::none, azure::storage::cloud_blob_shared_access_headers(), blob); stored_permissions = m_container.download_permissions(azure::storage::access_condition(), azure::storage::blob_request_options(), m_context); CHECK(stored_permissions.policies().empty()); }
int ClientApp::run (int argc, ACE_TCHAR* argv[]) { CORBA::ORB_var orb = CORBA::ORB_init (argc, argv); // Parse the command-line args for this application. // * Raises -1 if problems are encountered. // * Returns 1 if the usage statement was explicitly requested. // * Returns 0 otherwise. int result = this->parse_args (argc, argv); if (result != 0) { return result; } CORBA::Object_var obj = orb->string_to_object(this->ior_.c_str()); if (CORBA::is_nil(obj.in())) { ACE_ERROR((LM_ERROR, "(%P|%t) Failed to convert IOR string to obj ref.\n")); throw TestException(); } Foo_var foo = Foo::_narrow(obj.in()); if (CORBA::is_nil(foo.in())) { ACE_ERROR((LM_ERROR, "(%P|%t) Failed to narrow obj ref to Foo interface.\n")); throw TestException(); } // Create the callback object using the child poa with the custom // strategy. obj = orb->resolve_initial_references("RootPOA"); if (CORBA::is_nil(obj.in())) { ACE_ERROR((LM_ERROR, "(%P|%t) Failed to resolve initial ref for 'RootPOA'.\n")); throw TestException(); } PortableServer::POA_var root_poa = PortableServer::POA::_narrow(obj.in()); if (CORBA::is_nil(root_poa.in())) { ACE_ERROR((LM_ERROR, "(%P|%t) Failed to narrow obj ref to POA interface.\n")); throw TestException(); } PortableServer::POAManager_var poa_manager = root_poa->the_POAManager(); // Create the child POA. CORBA::PolicyList policies(0); policies.length(0); PortableServer::POA_var child_poa = root_poa->create_POA("ChildPoa", poa_manager.in(), policies); if (CORBA::is_nil(child_poa.in())) { ACE_ERROR((LM_ERROR, "(%P|%t) ERROR [ServerApp::run()]: " "Failed to create the child POA.\n")); throw TestException(); } // Create the thread pool servant dispatching strategy object, and // hold it in a (local) smart pointer variable. TAO_Intrusive_Ref_Count_Handle<TAO::CSD::TP_Strategy> csd_tp_strategy = new TAO::CSD::TP_Strategy(); csd_tp_strategy->set_num_threads(1); // Tell the strategy to apply itself to the child poa. if (csd_tp_strategy->apply_to(child_poa.in()) == false) { ACE_ERROR((LM_ERROR, "(%P|%t) ERROR [ServerApp::run()]: " "Failed to apply custom dispatching strategy to child poa.\n")); throw TestException(); } // Create the servant object. Callback_i* servant = new Callback_i (); // local smart pointer variable to deal with releasing the reference // to the servant object when the smart pointer object falls out of scope. PortableServer::ServantBase_var owner_transfer(servant); // Activate the servant using the Child POA. PortableServer::ObjectId_var oid = child_poa->activate_object(servant); // Obtain the object reference. obj = child_poa->servant_to_reference(servant); if (CORBA::is_nil(obj.in())) { ACE_ERROR((LM_ERROR, "(%P|%t) Failed to activate servant (Callback_i).\n")); throw TestException(); } Callback_var callback = Callback::_narrow (obj.in ()); ClientTask client_task(orb.in (), foo.in (), callback.in ()); if (client_task.open () != 0) { throw TestException(); } // Activate the POA Manager poa_manager->activate(); ACE_DEBUG((LM_DEBUG, "(%P|%t) ClientApp is ready.\n")); orb->run(); client_task.wait (); ACE_DEBUG((LM_DEBUG, "(%P|%t) ClientApp is destroying the Root POA.\n")); // Tear-down the root poa and orb. root_poa->destroy(1, 1); ACE_DEBUG((LM_DEBUG, "(%P|%t) ClientApp is destroying the ORB.\n")); orb->destroy(); ACE_DEBUG((LM_DEBUG, "(%P|%t) ClientApp has completed running successfully.\n")); return 0; }
ContainerT &get_unput_queue() { return policies().get_unput_queue(); }
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; }
void TAO_LogMgr_i::init (CORBA::ORB_ptr orb, PortableServer::POA_ptr poa) { this->orb_ = CORBA::ORB::_duplicate (orb); this->poa_ = PortableServer::POA::_duplicate (poa); PortableServer::POAManager_var poa_manager = this->poa_->the_POAManager (); { TAO::Utils::PolicyList_Destroyer policies(1); // Create Factory POA policies.length (1); policies[0] = this->poa_->create_lifespan_policy (PortableServer::PERSISTENT); this->factory_poa_ = this->poa_->create_POA ("factory_POA", poa_manager.in (), policies); } { TAO::Utils::PolicyList_Destroyer policies(2); // Create Log POA policies.length (2); policies[0] = this->poa_->create_lifespan_policy (PortableServer::PERSISTENT); policies[1] = this->poa_->create_id_assignment_policy (PortableServer::USER_ID); #if (TAO_HAS_MINIMUM_POA == 0) && !defined (CORBA_E_COMPACT) policies.length(4); policies[2] = this->poa_->create_servant_retention_policy (PortableServer::RETAIN); policies[3] = this->poa_->create_request_processing_policy (PortableServer::USE_SERVANT_MANAGER); #endif this->log_poa_ = this->factory_poa_->create_POA ("log_POA", poa_manager.in (), policies); } #if (TAO_HAS_MINIMUM_POA == 0) && !defined (CORBA_E_COMPACT) PortableServer::ServantActivator* servant_activator = 0; ACE_NEW_THROW_EX (servant_activator, TAO_LogActivator (*this), CORBA::NO_MEMORY ()); this->log_poa_->set_servant_manager(servant_activator); #endif // Load Log Strategy TAO_Log_Persistence_Strategy* strategy_ = 0; strategy_ = ACE_Dynamic_Service<TAO_Log_Persistence_Strategy>::instance ("Log_Persistence"); if (strategy_ == 0) { strategy_ = new TAO_Hash_Persistence_Strategy; } logstore_ = strategy_->create_log_store (this); }
int ServerApp::run (int argc, ACE_TCHAR* argv[]) { CORBA::ORB_var orb = CORBA::ORB_init (argc, argv); // Parse the command-line args for this application. // * Raises -1 if problems are encountered. // * Returns 1 if the usage statement was explicitly requested. // * Returns 0 otherwise. int result = this->parse_args (argc, argv); if (result != 0) { return result; } TheOrbShutdownTask::instance()->orb (orb.in ()); CORBA::Object_var obj = orb->resolve_initial_references("RootPOA"); if (CORBA::is_nil(obj.in())) { ACE_ERROR((LM_ERROR, "(%P|%t) Failed to resolve initial ref for 'RootPOA'.\n")); throw TestException(); } PortableServer::POA_var root_poa = PortableServer::POA::_narrow(obj.in()); if (CORBA::is_nil(root_poa.in())) { ACE_ERROR((LM_ERROR, "(%P|%t) Failed to narrow obj ref to POA interface.\n")); throw TestException(); } PortableServer::POAManager_var poa_manager = root_poa->the_POAManager(); // Create the child POA. CORBA::PolicyList policies(1); policies.length(1); policies[0] = root_poa->create_id_assignment_policy(PortableServer::USER_ID); PortableServer::POA_var child_poa = root_poa->create_POA("ChildPoa", poa_manager.in(), policies); if (CORBA::is_nil(child_poa.in())) { ACE_ERROR((LM_ERROR, "(%P|%t) ERROR [ServerApp::run()]: " "Failed to create the child POA.\n")); throw TestException(); } policies[0]->destroy (); // Create the thread pool servant dispatching strategy object, and // hold it in a (local) smart pointer variable. TAO_Intrusive_Ref_Count_Handle<TAO::CSD::TP_Strategy> csd_tp_strategy = new TAO::CSD::TP_Strategy(); csd_tp_strategy->set_num_threads(this->num_servants_); // Tell the strategy to apply itself to the child poa. if (csd_tp_strategy->apply_to(child_poa.in()) == false) { ACE_ERROR((LM_ERROR, "(%P|%t) ERROR [ServerApp::run()]: " "Failed to apply custom dispatching strategy to child poa.\n")); throw TestException(); } FooServantList servants(this->ior_filename_.c_str(), this->num_servants_, this->num_clients_, orb.in()); servants.create_and_activate(child_poa.in()); // Activate the POA Manager poa_manager->activate(); ACE_DEBUG((LM_DEBUG, "(%P|%t) ServerApp is ready. Running the ORB event loop.\n")); // Run the ORB event loop. orb->run(); ACE_DEBUG((LM_DEBUG, "(%P|%t) ServerApp ORB has stopped running. " "Stop the CSD strategy.\n")); // Sleep for 2 second to let the done() two-way call complete // before cleanup. ACE_OS::sleep (2); ACE_DEBUG((LM_DEBUG, "(%P|%t) ServerApp is waiting for OrbShutdownTask.\n")); TheOrbShutdownTask::instance()->wait (); ACE_DEBUG((LM_DEBUG, "(%P|%t) ServerApp is destroying the Root POA.\n")); // Tear-down the root poa and orb. root_poa->destroy(1, 1); ACE_DEBUG((LM_DEBUG, "(%P|%t) ServerApp is destroying the ORB.\n")); orb->destroy(); ACE_DEBUG((LM_DEBUG, "(%P|%t) ServerApp has completed running successfully.\n")); return 0; }
int ACE_TMAIN(int argc, ACE_TCHAR *argv[]) { int ret_val = 0; try { CORBA::ORB_var orb = CORBA::ORB_init (argc, argv); CORBA::Object_var object = orb->resolve_initial_references ("PolicyCurrent"); CORBA::PolicyCurrent_var policy_current = CORBA::PolicyCurrent::_narrow (object.in ()); if (CORBA::is_nil (policy_current.in ())) { ACE_ERROR ((LM_ERROR, "ERROR: Nil policy current\n")); return 1; } CORBA::Any scope_as_any; scope_as_any <<= Messaging::SYNC_WITH_SERVER; CORBA::PolicyList policies(1); policies.length (1); policies[0] = orb->create_policy (Messaging::SYNC_SCOPE_POLICY_TYPE, scope_as_any); policy_current->set_policy_overrides (policies, CORBA::ADD_OVERRIDE); policies[0]->destroy (); if (parse_args (argc, argv) != 0) return 1; CORBA::Object_var tmp = orb->string_to_object(ior); Test::Peer_var peer = Test::Peer::_narrow(tmp.in ()); if (CORBA::is_nil (peer.in ())) { ACE_ERROR_RETURN ((LM_DEBUG, "Nil Test::Peer reference <%s>\n", ior), 1); } while(1) { peer->noop (); } /* Warning with TRU 64 builds ACE_DEBUG ((LM_DEBUG, "(%P|%t) scavenger - event loop finished\n")); orb->destroy (); */ } catch (const CORBA::Exception& ex) { ex._tao_print_exception ("Exception caught:"); ret_val = 1; } return ret_val; }
int ACE_TMAIN(int argc, ACE_TCHAR *argv[]) { int exit_status = 0; try { CORBA::ORB_var orb (CORBA::ORB_init (argc, argv)); CORBA::Object_var compression_manager_obj ( orb->resolve_initial_references("CompressionManager")); ::Compression::CompressionManager_var compression_manager ( ::Compression::CompressionManager::_narrow ( compression_manager_obj.in ())); if (CORBA::is_nil(compression_manager.in ())) ACE_ERROR_RETURN ((LM_ERROR, " (%P|%t) Panic: nil compression manager\n"), 1); //register Zlib compressor ::Compression::CompressorFactory_ptr compressor_factory; ACE_NEW_RETURN (compressor_factory, TAO::Zlib_CompressorFactory (), 1); ::Compression::CompressorFactory_var compr_fact (compressor_factory); compression_manager->register_factory (compr_fact.in ()); //Register Client ZIOP policies CORBA::PolicyList policies(4); policies.length(4); ::Compression::CompressorIdLevelList compressor_id_list; compressor_id_list.length (1); compressor_id_list[0].compressor_id = ::Compression::COMPRESSORID_ZLIB; compressor_id_list[0].compression_level = 9; CORBA::Any any; any <<= compressor_id_list; policies[0] = orb->create_policy (ZIOP::COMPRESSOR_ID_LEVEL_LIST_POLICY_ID, any); any <<= static_cast <CORBA::ULong> (190u); // shutdown is 180, send_forty_two is 192 policies[1] = orb->create_policy (ZIOP::COMPRESSION_LOW_VALUE_POLICY_ID, any); any <<= CORBA::Any::from_boolean (true); policies[2] = orb->create_policy (ZIOP::COMPRESSION_ENABLING_POLICY_ID, any); any <<= static_cast <Compression::CompressionRatio> (0.50); // send_forty_two is 0.66, send_large_octet_array is 0.06 policies[3] = orb->create_policy (ZIOP::COMPRESSION_MIN_RATIO_POLICY_ID, any); // Parse our own client arguments if (parse_args (argc, argv) != 0) return 1; // Obtain the servant reference with our active ZIOP policies. CORBA::Object_var tmp (orb->string_to_object(ior)); tmp = tmp->_set_policy_overrides (policies, CORBA::ADD_OVERRIDE); /* Do an unchecked narrow since there's no way to do an is_a on * a multicast reference (yet...). */ Test::McastHello_var hello = TAO::Narrow_Utils<Test::McastHello>::unchecked_narrow ( tmp.in ()); if (CORBA::is_nil (hello.in ())) { ACE_ERROR_RETURN ((LM_DEBUG, "Nil Test::Hello reference <%s>\n", ior), 1); } // To enable us to check that we compress the correct messages. ::Compression::Compressor_var compressor ( compression_manager->get_compressor ( compressor_id_list[0].compressor_id, compressor_id_list[0].compression_level)); if (CORBA::is_nil (compressor.in ())) { ACE_ERROR_RETURN ((LM_ERROR, "ERROR : compressor not found!\n"), 1); } ACE_DEBUG ((LM_DEBUG, "Client sending send_forty_two() message to server\n")); hello->send_forty_two (42); // Note we can't actually check that we did NOT compress the message, // as the compressor is used to TRIAL the compression before it is // rejected based upon the min ratio. The compressor thus records // this trail compression data length. (ZIOP is almost completely // transparrent in operation to the client and server when operating). CORBA::ULong total_compressed_so_far= compressor->compressed_bytes (); Test::Octets payload (MAX_MIOP_OCTET_SEQUENCE); payload.length (MAX_MIOP_OCTET_SEQUENCE); for (CORBA::ULong j = 0; j != MAX_MIOP_OCTET_SEQUENCE; ++j) { payload[j] = j % 256; } ACE_DEBUG ((LM_DEBUG, "Client sending send_large_octet_array() message to server\n")); hello->send_large_octet_array (payload); // Check we did compress the message if (compressor->compressed_bytes ()-total_compressed_so_far) { ACE_DEBUG ((LM_DEBUG, "Correct. Client did use compression!\n")); } else { ACE_DEBUG ((LM_ERROR, "ERROR : check_results, no compression used!\n")); exit_status = 1; } total_compressed_so_far= compressor->compressed_bytes (); // Now shutdown the server ACE_DEBUG ((LM_DEBUG, "Client sending shutdown() message to server\n")); hello->shutdown (); // Check we did NOT compress the message if (compressor->compressed_bytes ()-total_compressed_so_far) { ACE_DEBUG ((LM_ERROR, "ERROR : check_results, Client did use compression!\n")); exit_status = 1; } else { ACE_DEBUG ((LM_DEBUG, "Correct. Client did NOT use compression!\n")); } orb->destroy (); } catch (const CORBA::Exception& ex) { ex._tao_print_exception ("Exception caught:"); exit_status = 1; } return exit_status; }
int ServerApp::run_i(int argc, ACE_TCHAR* argv[]) { // Initialize the ORB before parsing our own args. CORBA::ORB_var orb = CORBA::ORB_init(argc, argv); // Parse the command-line args for this application. // * Returns -1 if problems are encountered. // * Returns 1 if the usage statement was explicitly requested. // * Returns 0 otherwise. int result = this->parse_args(argc, argv); if (result != 0) { return result; } TheAppShutdown->init(orb.in(), num_clients_); // Get the Root POA PortableServer::POA_var root_poa = RefHelper<PortableServer::POA>::resolve_initial_ref(orb.in(), "RootPOA"); // Get the POAManager from the Root POA. PortableServer::POAManager_var poa_manager = root_poa->the_POAManager(); // Create the child POA Policies. CORBA::PolicyList policies(0); policies.length(0); // Create the child POA PortableServer::POA_var child_poa = AppHelper::create_poa("ChildPoa", root_poa.in(), poa_manager.in(), policies); // Create the thread pool servant dispatching strategy object, and // hold it in a (local) smart pointer variable. TAO_Intrusive_Ref_Count_Handle<TAO::CSD::TP_Strategy> csd_strategy = new TAO::CSD::TP_Strategy(); // Tell the strategy to apply itself to the child poa. if (csd_strategy->apply_to(child_poa.in()) == false) { ACE_ERROR((LM_ERROR, "Failed to apply CSD strategy to child poa.\n")); return -1; } // Create the servant object. Foo_A_i* servant = new Foo_A_i(); // Local smart pointer variable to deal with releasing the reference // to the servant object when the variable falls out of scope. PortableServer::ServantBase_var servant_owner(servant); // Obtain the object reference using the servant CORBA::Object_var obj = AppHelper::activate_servant(child_poa.in(), servant); // Stringify and save the object reference to a file AppHelper::ref_to_file(orb.in(), obj.in(), this->ior_filename_.c_str()); // Activate the POA Manager poa_manager->activate(); ACE_DEBUG((LM_DEBUG, "(%P|%t) ServerApp is ready. Running the ORB event loop.\n")); // Run the ORB event loop. orb->run (); ACE_DEBUG((LM_DEBUG, "(%P|%t) ServerApp ORB event loop has completed.\n")); TheAppShutdown->wait (); // Calling wait on ACE_Thread_Manager singleton to avoid the problem // that the main thread might exit before all CSD Threads exit. // Wait for all CSD task threads exit. ACE_Thread_Manager::instance ()->wait (); ACE_DEBUG((LM_DEBUG, "(%P|%t) ServerApp is destroying the Root POA.\n")); root_poa->destroy(1, 1); ACE_DEBUG((LM_DEBUG, "(%P|%t) ServerApp is destroying the ORB.\n")); orb->destroy(); ACE_DEBUG((LM_DEBUG, "(%P|%t) ServerApp has completed running successfully.\n")); return 0; }
void InfoRepo::init() { ACE_Argv_Type_Converter cvt(this->federatorConfig_.argc(), this->federatorConfig_.argv()); this->orb_ = CORBA::ORB_init(cvt.get_argc(), cvt.get_ASCII_argv(), ""); this->info_servant_ = new TAO_DDS_DCPSInfo_i(this->orb_, this->resurrect_, this, this->federatorConfig_.federationId()); // Install the DCPSInfo_i into the Federator::Manager. this->federator_.info() = this->info_servant_.in(); CORBA::Object_var obj = this->orb_->resolve_initial_references("RootPOA"); PortableServer::POA_var root_poa = PortableServer::POA::_narrow(obj); PortableServer::POAManager_var poa_manager = root_poa->the_POAManager(); // Use persistent and user id POA policies so the Info Repo's // object references are consistent. CORBA::PolicyList policies(2); policies.length(2); policies[0] = root_poa->create_id_assignment_policy(PortableServer::USER_ID); policies[1] = root_poa->create_lifespan_policy(PortableServer::PERSISTENT); PortableServer::POA_var info_poa = root_poa->create_POA("InfoRepo", poa_manager, policies); // Creation of the new POAs over, so destroy the Policy_ptr's. for (CORBA::ULong i = 0; i < policies.length(); ++i) { policies[i]->destroy(); } PortableServer::ObjectId_var oid = PortableServer::string_to_ObjectId("InfoRepo"); info_poa->activate_object_with_id(oid, this->info_servant_.in()); obj = info_poa->id_to_reference(oid); // the object is created locally, so it is safe to do an // _unchecked_narrow, this was needed to prevent an exception // when dealing with ImR-ified objects OpenDDS::DCPS::DCPSInfo_var info_repo = OpenDDS::DCPS::DCPSInfo::_unchecked_narrow(obj); CORBA::String_var objref_str = orb_->object_to_string(info_repo); // Initialize the DomainParticipantFactory DDS::DomainParticipantFactory_var dpf = TheParticipantFactoryWithArgs(cvt.get_argc(), cvt.get_TCHAR_argv()); // We need parse the command line options for DCPSInfoRepo after parsing DCPS specific // command line options. // Check the non-ORB arguments. this->parse_args(cvt.get_argc(), cvt.get_TCHAR_argv()); // Activate the POA manager before initialize built-in-topics // so invocations can be processed. poa_manager->activate(); if (this->use_bits_) { if (this->info_servant_->init_transport(this->listen_address_given_, this->listen_address_str_.c_str()) != 0 /* init_transport returns 0 for success */) { ACE_ERROR((LM_ERROR, ACE_TEXT("(%P|%t) ERROR: DCPSInfoRepo::init: ") ACE_TEXT("Unable to initialize transport.\n"))); throw InitError("Unable to initialize transport."); } } else { TheServiceParticipant->set_BIT(false); } // This needs to be done after initialization since we create the reference // to ourselves in the service here. OpenDDS::DCPS::Service_Participant* serv_part = TheServiceParticipant; serv_part->set_repo_ior(objref_str, OpenDDS::DCPS::Discovery::DEFAULT_REPO); OpenDDS::DCPS::Discovery_rch disc = serv_part->get_discovery(0 /*domainId*/); OpenDDS::DCPS::InfoRepoDiscovery_rch ird = OpenDDS::DCPS::static_rchandle_cast<OpenDDS::DCPS::InfoRepoDiscovery>(disc); if (!ird->set_ORB(orb_)) { ACE_ERROR((LM_ERROR, ACE_TEXT("(%P|%t) ERROR: DCPSInfoRepo::init: ") ACE_TEXT("Unable to set the ORB in InfoRepoDiscovery.\n"))); throw InitError("Unable to set the ORB in InfoRepoDiscovery."); } // Initialize persistence _after_ initializing the participant factory // and intializing the transport. if (!this->info_servant_->init_persistence()) { ACE_ERROR((LM_ERROR, ACE_TEXT("(%P|%t) ERROR: DCPSInfoRepo::init: ") ACE_TEXT("Unable to initialize persistence.\n"))); throw InitError("Unable to initialize persistence."); } // Initialize reassociation. if (this->reassociate_delay_ != ACE_Time_Value::zero && !this->info_servant_->init_reassociation(this->reassociate_delay_)) { ACE_ERROR((LM_ERROR, ACE_TEXT("(%P|%t) ERROR: DCPSInfoRepo::init: ") ACE_TEXT("Unable to initialize reassociation.\n"))); throw InitError("Unable to initialize reassociation."); } // Initialize dispatch checking if (this->dispatch_cleanup_delay_ != ACE_Time_Value::zero && !this->info_servant_->init_dispatchChecking(this->dispatch_cleanup_delay_)) { ACE_ERROR((LM_ERROR, ACE_TEXT("(%P|%t) ERROR: DCPSInfoRepo::init: ") ACE_TEXT("Unable to initialize Dispatch checking.\n"))); throw InitError("Unable to initialize dispatch checking."); } // Fire up the federator. OpenDDS::Federator::Manager_var federator; CORBA::String_var federator_ior; if (federator_.id().overridden()) { oid = PortableServer::string_to_ObjectId("Federator"); info_poa->activate_object_with_id(oid, &federator_); obj = info_poa->id_to_reference(oid); federator = OpenDDS::Federator::Manager::_narrow(obj); federator_ior = orb_->object_to_string(federator); // Add a local repository reference that can be returned via a // remote call to a peer. this->federator_.localRepo(info_repo); // It should be safe to initialize the federation mechanism at this // point. What we really needed to wait for is the initialization of // the service components - like the DomainParticipantFactory and the // repository bindings. // N.B. This is done *before* being added to the IOR table to avoid any // races with an eager client. this->federator_.orb(this->orb_); // // Add the federator to the info_servant update manager as an // additional updater interface to be called. // N.B. This needs to be done *after* the call to load_domains() // since that is where the update manager is initialized in the // info startup sequencing. this->info_servant_->add(&this->federator_); } // Grab the IOR table. CORBA::Object_var table_object = this->orb_->resolve_initial_references("IORTable"); IORTable::Table_var adapter = IORTable::Table::_narrow(table_object); if (CORBA::is_nil(adapter)) { ACE_ERROR((LM_ERROR, ACE_TEXT("Nil IORTable\n"))); } else { adapter->bind(OpenDDS::Federator::REPOSITORY_IORTABLE_KEY, objref_str); if (this->federator_.id().overridden()) { // Bind to '/Federator' adapter->bind(OpenDDS::Federator::FEDERATOR_IORTABLE_KEY, federator_ior); // Bind to '/Federator/1382379631' std::stringstream buffer(OpenDDS::Federator::FEDERATOR_IORTABLE_KEY); buffer << "/" << std::dec << this->federatorConfig_.federationDomain(); adapter->bind(buffer.str().c_str(), federator_ior); } } FILE* output_file = ACE_OS::fopen(this->ior_file_.c_str(), ACE_TEXT("w")); if (output_file == 0) { ACE_ERROR((LM_ERROR, ACE_TEXT("ERROR: Unable to open IOR file: %s\n"), ior_file_.c_str())); throw InitError("Unable to open IOR file."); } ACE_OS::fprintf(output_file, "%s", objref_str.in()); ACE_OS::fclose(output_file); // Initial federation join if specified on command line. if (this->federator_.id().overridden() && !this->federatorConfig_.federateIor().empty()) { if (OpenDDS::DCPS::DCPS_debug_level > 0) { ACE_DEBUG((LM_DEBUG, ACE_TEXT("(%P|%t) INFO: DCPSInfoRepo::init() - ") ACE_TEXT("joining federation with repository %s\n"), this->federatorConfig_.federateIor().c_str())); } obj = this->orb_->string_to_object( this->federatorConfig_.federateIor().c_str()); if (CORBA::is_nil(obj)) { ACE_ERROR((LM_ERROR, ACE_TEXT("(%P|%t) ERROR: could not resolve %s for initial federation.\n"), this->federatorConfig_.federateIor().c_str())); throw InitError("Unable to resolve IOR for initial federation."); } OpenDDS::Federator::Manager_var peer = OpenDDS::Federator::Manager::_narrow(obj); if (CORBA::is_nil(peer)) { ACE_ERROR((LM_ERROR, ACE_TEXT("(%P|%t) ERROR: could not narrow %s.\n"), this->federatorConfig_.federateIor().c_str())); throw InitError("Unable to narrow peer for initial federation."); } // Actually join. peer->join_federation(federator, this->federatorConfig_.federationDomain()); } }
int ACE_TMAIN(int argc, ACE_TCHAR *argv[]) { try { CORBA::ORB_var orb = CORBA::ORB_init (argc, argv); CORBA::Object_var poa_object = orb->resolve_initial_references("RootPOA"); PortableServer::POA_var root_poa = PortableServer::POA::_narrow (poa_object.in ()); if (CORBA::is_nil (root_poa.in ())) ACE_ERROR_RETURN ((LM_ERROR, " (%P|%t) Panic: nil RootPOA\n"), 1); PortableServer::POAManager_var poa_manager = root_poa->the_POAManager (); CORBA::Object_var object = orb->resolve_initial_references ("PolicyCurrent"); CORBA::PolicyCurrent_var policy_current = CORBA::PolicyCurrent::_narrow (object.in ()); if (CORBA::is_nil (policy_current.in ())) { ACE_ERROR ((LM_ERROR, "ERROR: Nil policy current\n")); return 1; } CORBA::Any scope_as_any; scope_as_any <<= Messaging::SYNC_WITH_SERVER; CORBA::PolicyList policies(1); policies.length (1); policies[0] = orb->create_policy (Messaging::SYNC_SCOPE_POLICY_TYPE, scope_as_any); policy_current->set_policy_overrides (policies, CORBA::ADD_OVERRIDE); policies[0]->destroy (); seed = (unsigned int) ACE_OS::gethrtime (); if (parse_args (argc, argv) != 0) return 1; ACE_DEBUG ((LM_DEBUG, "SEED = %u\n", seed)); Server_Peer *impl; ACE_NEW_RETURN (impl, Server_Peer (seed, orb.in (), payload_size), 1); PortableServer::ServantBase_var owner_transfer(impl); PortableServer::ObjectId_var id = root_poa->activate_object (impl); CORBA::Object_var object_act = root_poa->id_to_reference (id.in ()); Test::Peer_var peer = Test::Peer::_narrow (object_act.in ()); CORBA::String_var ior = orb->object_to_string (peer.in ()); // If the ior_output_file exists, output the ior to it FILE *output_file= ACE_OS::fopen (ior_output_file, "w"); if (output_file == 0) ACE_ERROR_RETURN ((LM_ERROR, "Cannot open output file for writing IOR: %s", ior_output_file), 1); ACE_OS::fprintf (output_file, "%s", ior.in ()); ACE_OS::fclose (output_file); poa_manager->activate (); Sleeper sleeper (orb.in ()); ACE_Time_Value interval(0, 500000); ACE_Reactor * reactor = orb->orb_core()->reactor(); reactor->schedule_timer(&sleeper, 0, interval, interval); // ACE_Time_Value run_time(600, 0); // orb->run (run_time); orb->run (); ACE_DEBUG ((LM_DEBUG, "(%P|%t) server - event loop finished\n")); root_poa->destroy (1, 1); orb->destroy (); } catch (const CORBA::Exception& ex) { ex._tao_print_exception ("Exception caught:"); return 1; } return 0; }
std::vector<ParsedStateMachinePtr> StateGraphParser::parse( iter_t& begin, iter_t end ) { //skip_parser_t skip_parser = SKIP_PARSER; //iter_pol_t iter_policy( skip_parser ); //#define SKIP_PARSER skip_parser_t skip_parser = comment_p( "#" ) | comment_p( "//" ) | comment_p( "/*", "*/" ) | (space_p - eol_p) | commonparser->skipper; iter_pol_t iter_policy( skip_parser ); scanner_pol_t policies( iter_policy ); scanner_t scanner( begin, end, policies ); // reset the condition-transition priority. rank = 0; this->storeOffset(); try { if ( ! production.parse( scanner ) ) { // on error, we clear all remaining data, cause we can't // guarantee consistency... clear(); throw file_parse_exception( new parse_exception_syntactic_error( "Syntax error" ), mpositer.get_position().file, mpositer.get_position().line, mpositer.get_position().column ); } std::vector<ParsedStateMachinePtr> ret = values( rootmachines ); rootmachines.clear(); return ret; } catch( const parser_error<std::string, iter_t>& e ) { // on error, we clear all remaining data, cause we can't // guarantee consistency... clear(); throw file_parse_exception( new parse_exception_syntactic_error( e.descriptor ), mpositer.get_position().file, mpositer.get_position().line, mpositer.get_position().column ); } catch( const parser_error<GraphSyntaxErrors, iter_t>& ) { // on error, we clear all remaining data, cause we can't // guarantee consistency... clear(); throw file_parse_exception( new parse_exception_syntactic_error( "Expected one of: entry, handle, exit, transitions" ), mpositer.get_position().file, mpositer.get_position().line, mpositer.get_position().column ); } catch( const parse_exception& e ) { // on error, we clear all remaining data, cause we can't // guarantee consistency... clear(); throw file_parse_exception( e.copy(), mpositer.get_position().file, mpositer.get_position().line, mpositer.get_position().column ); } // catch( ... ) { // assert( false ); // } }
int ACE_TMAIN(int argc, ACE_TCHAR *argv[]) { try { CORBA::ORB_var orb = CORBA::ORB_init (argc, argv); CORBA::Object_var poa_object = orb->resolve_initial_references("RootPOA"); PortableServer::POA_var root_poa = PortableServer::POA::_narrow (poa_object.in ()); if (CORBA::is_nil (root_poa.in ())) ACE_ERROR_RETURN ((LM_ERROR, " (%P|%t) Panic: nil RootPOA\n"), 1); PortableServer::POAManager_var poa_manager = root_poa->the_POAManager (); // Make all oneways "reliable." { CORBA::Object_var manager_object = orb->resolve_initial_references("ORBPolicyManager"); CORBA::PolicyManager_var policy_manager = CORBA::PolicyManager::_narrow(manager_object.in()); if (CORBA::is_nil (policy_manager.in ())) ACE_ERROR_RETURN ((LM_ERROR, " (%P|%t) Panic: nil PolicyManager\n"), 1); CORBA::Any policy_value; policy_value <<= Messaging::SYNC_WITH_SERVER; CORBA::PolicyList policies(1); policies.length(1); policies[0] = orb->create_policy (Messaging::SYNC_SCOPE_POLICY_TYPE, policy_value); policy_manager->set_policy_overrides (policies, CORBA::ADD_OVERRIDE); policies[0]->destroy (); } if (parse_args (argc, argv) != 0) return 1; CORBA::Object_var tmp = orb->string_to_object(ior); Test::Service_var service = Test::Service::_narrow(tmp.in ()); if (CORBA::is_nil (service.in ())) { ACE_ERROR_RETURN ((LM_DEBUG, "Nil service reference <%s>\n", ior), 1); } Callback *callback_impl; ACE_NEW_RETURN (callback_impl, Callback(orb.in ()), 1); PortableServer::ServantBase_var owner_transfer(callback_impl); PortableServer::ObjectId_var id = root_poa->activate_object (callback_impl); CORBA::Object_var object = root_poa->id_to_reference (id.in ()); Test::Callback_var callback = Test::Callback::_narrow (object.in ()); poa_manager->activate (); ACE_DEBUG ((LM_DEBUG, "(%P|%t) client - starting test\n")); service->run_test (callback.in ()); ACE_DEBUG ((LM_DEBUG, "(%P|%t) client - running ORB\n")); orb->run (); root_poa->destroy (1, 1); orb->destroy (); } catch (const CORBA::Exception& ex) { ex._tao_print_exception ("Exception caught:"); return 1; } return 0; }
int ACE_TMAIN(int argc, ACE_TCHAR *argv[]) { try { CORBA::ORB_var orb = CORBA::ORB_init (argc, argv); CORBA::Object_var poa_object = orb->resolve_initial_references("RootPOA"); PortableServer::POA_var root_poa = PortableServer::POA::_narrow (poa_object.in ()); if (CORBA::is_nil (root_poa.in ())) ACE_ERROR_RETURN ((LM_ERROR, " (%P|%t) Panic: nil RootPOA\n"), 1); PortableServer::POAManager_var poa_manager = root_poa->the_POAManager (); CORBA::Object_var object = orb->resolve_initial_references ("PolicyCurrent"); CORBA::PolicyCurrent_var policy_current = CORBA::PolicyCurrent::_narrow (object.in ()); if (CORBA::is_nil (policy_current.in ())) { ACE_ERROR ((LM_ERROR, "ERROR: Nil policy current\n")); return 1; } CORBA::Any scope_as_any; scope_as_any <<= Messaging::SYNC_NONE; CORBA::PolicyList policies(1); policies.length (1); policies[0] = orb->create_policy (Messaging::SYNC_SCOPE_POLICY_TYPE, scope_as_any); policy_current->set_policy_overrides (policies, CORBA::ADD_OVERRIDE); policies[0]->destroy (); if (parse_args (argc, argv) != 0) return 1; PortableServer::Servant_var<Echo_Caller> impl; { Echo_Caller * tmp; // ACE_NEW_RETURN is the worst possible way to handle // exceptions (think: what if the constructor allocates memory // and fails?), but I'm not in the mood to fight for a more // reasonable way to handle allocation errors in ACE. ACE_NEW_RETURN (tmp, Echo_Caller(orb.in()), 1); impl = tmp; } PortableServer::ObjectId_var id = root_poa->activate_object (impl.in ()); CORBA::Object_var object_act = root_poa->id_to_reference (id.in ()); Test::Echo_Caller_var server = Test::Echo_Caller::_narrow (object_act.in ()); CORBA::String_var ior = orb->object_to_string (server.in ()); // If the ior_output_file exists, output the ior to it FILE *output_file= ACE_OS::fopen (ior_output_file, "w"); if (output_file == 0) ACE_ERROR_RETURN ((LM_ERROR, "Cannot open output file for writing IOR: %s", ior_output_file), 1); ACE_OS::fprintf (output_file, "%s", ior.in ()); ACE_OS::fclose (output_file); poa_manager->activate (); orb->run(); ACE_DEBUG ((LM_DEBUG, "(%P|%t) server - event loop finished\n")); root_poa->destroy (1, 1); orb->destroy (); } catch (const CORBA::Exception& ex) { ex._tao_print_exception ("Exception caught in server:"); return 1; } return 0; }
ContainerT const &get_unput_queue() const { return policies().get_unput_queue(); }
int ACE_TMAIN(int argc, ACE_TCHAR *argv[]) { try { CORBA::ORB_var orb = CORBA::ORB_init (argc, argv); CORBA::Object_var object = orb->resolve_initial_references ("PolicyCurrent"); CORBA::PolicyCurrent_var policy_current = CORBA::PolicyCurrent::_narrow (object.in ()); if (CORBA::is_nil (policy_current.in ())) { ACE_ERROR ((LM_ERROR, "ERROR: Nil policy current\n")); return 1; } CORBA::Any scope_as_any; scope_as_any <<= Messaging::SYNC_NONE; CORBA::PolicyList policies(1); policies.length (1); policies[0] = orb->create_policy (Messaging::SYNC_SCOPE_POLICY_TYPE, scope_as_any); policy_current->set_policy_overrides (policies, CORBA::ADD_OVERRIDE); policies[0]->destroy (); 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; Server *server_impl = 0; ACE_NEW_RETURN (server_impl, Server (orb.in ()), 1); PortableServer::ServantBase_var owner_transfer(server_impl); PortableServer::ObjectId_var id = root_poa->activate_object (server_impl); object = root_poa->id_to_reference (id.in ()); Test::Server_var test_server = Test::Server::_narrow (object.in ()); CORBA::String_var ior = orb->object_to_string (test_server.in ()); // Output the IOR to the <ior_output_file> FILE *output_file= ACE_OS::fopen (ior_output_file, "w"); if (output_file == 0) ACE_ERROR_RETURN ((LM_ERROR, "Cannot open output file for writing IOR: %s\n", ior_output_file), 1); ACE_OS::fprintf (output_file, "%s", ior.in ()); ACE_OS::fclose (output_file); poa_manager->activate (); orb->run (); ACE_DEBUG ((LM_DEBUG, "(%P|%t) server - event loop finished\n")); root_poa->destroy (1, 1); orb->destroy (); } catch (const CORBA::Exception& ex) { ex._tao_print_exception ("Exception caught:"); return 1; } return 0; }
int ACE_TMAIN(int argc, ACE_TCHAR *argv[]) { int result = 1; try { CORBA::ORB_var orb = CORBA::ORB_init (argc, argv); if (parse_args (argc, argv) != 0) return 1; CORBA::Object_var tmp = orb->string_to_object(ior); Test::Server_var test_server = Test::Server::_narrow(tmp.in ()); if (CORBA::is_nil (test_server.in ())) ACE_ERROR_RETURN ((LM_DEBUG, "ERROR: Nil reference in Test::Server reference <%s>\n", ior), 1); CORBA::Any scope_as_any; scope_as_any <<= Messaging::SYNC_NONE; CORBA::PolicyList policies(1); policies.length (1); policies[0] = orb->create_policy (Messaging::SYNC_SCOPE_POLICY_TYPE, scope_as_any); tmp = test_server->_set_policy_overrides (policies, CORBA::ADD_OVERRIDE); policies[0]->destroy (); Test::Server_var test_server_no_sync = Test::Server::_narrow(tmp.in ()); if (CORBA::is_nil (test_server_no_sync.in ())) ACE_ERROR_RETURN ((LM_DEBUG, "ERROR: Nil reference in Test::Server reference <%s>\n", ior), 1); CORBA::Object_var poa_object = orb->resolve_initial_references("RootPOA"); if (CORBA::is_nil (poa_object.in ())) ACE_ERROR_RETURN ((LM_ERROR, " (%P|%t) Unable to initialize the POA.\n"), 1); PortableServer::POA_var root_poa = PortableServer::POA::_narrow (poa_object.in ()); PortableServer::POAManager_var poa_manager = root_poa->the_POAManager (); poa_manager->activate (); Worker worker (orb.in ()); if (worker.activate (THR_NEW_LWP | THR_JOINABLE, 1) != 0) ACE_ERROR_RETURN ((LM_ERROR, "Cannot activate client server thread\n"), 1); ACE_DEBUG ((LM_DEBUG, "(%P|%t) Test starting . . .\n")); Client client_impl; PortableServer::ObjectId_var id = root_poa->activate_object (&client_impl); tmp = root_poa->id_to_reference (id.in ()); Test::Client_var test_client = Test::Client::_narrow (tmp.in ()); // setup client callback at server test_server_no_sync->setup (test_client.in ()); // send oneway request to server test_server_no_sync->request (1); // sleep 2 sec to give ample opportunity for oneway reply to be received by worker ACE_OS::sleep (2); // check if reply received if (client_impl.reply_count () > 0) { ACE_DEBUG ((LM_INFO, "(%P|%t) Oneway reply correctly received\n")); result = 0; // test OK } else { ACE_ERROR ((LM_ERROR, "(%P|%t) ERROR: Oneway reply not received\n")); // send second request to trigger reception of first and second reply test_server_no_sync->request (2); // sleep 2 sec to give ample opportunity for oneway reply to be received by worker ACE_OS::sleep (2); if (client_impl.reply_count () > 1) { ACE_DEBUG ((LM_INFO, "(%P|%t) Received both replies after second request\n")); } else { ACE_ERROR ((LM_ERROR, "(%P|%t) FATAL ERROR: Still no replies received\n")); } } // shutdown server (use original synchronous reference to be sure to deliver message) test_server->shutdown (); // shutdown worker orb->shutdown (1); worker.thr_mgr ()->wait (); orb->destroy (); } catch (const CORBA::Exception& ex) { ex._tao_print_exception ("Exception caught:"); return 1; } return result; }
int ACE_TMAIN (int argc, ACE_TCHAR *argv[]) { try { // First initialize the ORB, that will remove some arguments... CORBA::ORB_var orb = CORBA::ORB_init (argc, argv, "TestORB"); if (parse_args (argc, argv) != 0) return 1; CORBA::Object_var poa_object = orb->resolve_initial_references ("RootPOA"); PortableServer::POA_var root_poa = PortableServer::POA::_narrow (poa_object.in()); PortableServer::POAManager_var poa_manager = root_poa->the_POAManager (); poa_manager->activate (); // Make policies for child POA 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 poa = root_poa->create_POA ( "MyPOA", poa_manager.in(), policies ); // Creation of the new POAs over, so destroy the Policy_ptr's. for ( CORBA::ULong i = 0 ; i < policies.length (); ++i ) { CORBA::Policy_ptr policy = policies[i]; policy->destroy (); } // use this poa for making system objects Quoter_Stock_i::set_default_POA ( poa.in() ) ; // Create the servant Quoter_Stock_Factory_i *stock_factory_i = 0; ACE_NEW_RETURN (stock_factory_i, Quoter_Stock_Factory_i, -1); PortableServer::ServantBase_var safe (stock_factory_i); // Activate it to obtain the object reference PortableServer::ObjectId_var id = root_poa->activate_object (stock_factory_i); CORBA::Object_var object_act = root_poa->id_to_reference (id.in ()); Quoter::Stock_Factory_var stock_factory = Quoter::Stock_Factory::_narrow (object_act.in ()); // Put the object reference as an IOR string CORBA::String_var ior = orb->object_to_string (stock_factory.in ()); // Output the IOR to the <ior_output_file> FILE *output_file= ACE_OS::fopen (ior_output_file, "w"); if (output_file == 0) ACE_ERROR_RETURN ((LM_ERROR, "Cannot open output file for writing IOR: %s\n", ior_output_file), 1); ACE_OS::fprintf (output_file, "%s", ior.in ()); ACE_OS::fclose (output_file); ACE_Time_Value timeout (15); orb->run (timeout); // Destroy the POA, waiting until the destruction terminates root_poa->destroy (1, 1); orb->destroy (); } catch (const CORBA::Exception & e) { cerr << "CORBA exception raised: " << e << endl; } return 0; }
int ACE_TMAIN(int argc, ACE_TCHAR *argv[]) { try { CORBA::ORB_var orb = CORBA::ORB_init (argc, argv); CORBA::Object_var poa_object = orb->resolve_initial_references("RootPOA"); PortableServer::POA_var root_poa = PortableServer::POA::_narrow (poa_object.in ()); if (CORBA::is_nil (root_poa.in ())) ACE_ERROR_RETURN ((LM_ERROR, " (%P|%t) Panic: nil RootPOA\n"), 1); PortableServer::POAManager_var poa_manager = root_poa->the_POAManager (); // Make all oneways "reliable." { CORBA::Object_var manager_object = orb->resolve_initial_references("ORBPolicyManager"); CORBA::PolicyManager_var policy_manager = CORBA::PolicyManager::_narrow(manager_object.in()); if (CORBA::is_nil (policy_manager.in ())) ACE_ERROR_RETURN ((LM_ERROR, " (%P|%t) Panic: nil PolicyManager\n"), 1); CORBA::Any policy_value; policy_value <<= Messaging::SYNC_WITH_SERVER; CORBA::PolicyList policies(1); policies.length(1); policies[0] = orb->create_policy (Messaging::SYNC_SCOPE_POLICY_TYPE, policy_value); policy_manager->set_policy_overrides (policies, CORBA::ADD_OVERRIDE); policies[0]->destroy (); } if (parse_args (argc, argv) != 0) return 1; Service *service_impl; ACE_NEW_RETURN (service_impl, Service(orb.in ()), 1); PortableServer::ServantBase_var owner_transfer(service_impl); PortableServer::ObjectId_var id = root_poa->activate_object (service_impl); CORBA::Object_var object = root_poa->id_to_reference (id.in ()); Test::Service_var service = Test::Service::_narrow (object.in ()); CORBA::String_var ior = orb->object_to_string (service.in ()); // If the ior_output_file exists, output the ior to it FILE *output_file= ACE_OS::fopen (ior_output_file, "w"); if (output_file == 0) ACE_ERROR_RETURN ((LM_ERROR, "Cannot open output file for writing IOR: %s", ior_output_file), 1); ACE_OS::fprintf (output_file, "%s", ior.in ()); ACE_OS::fclose (output_file); poa_manager->activate (); orb->run (); ACE_DEBUG ((LM_DEBUG, "Event loop finished\n")); root_poa->destroy (1, 1); orb->destroy (); } catch (const CORBA::Exception& ex) { ex._tao_print_exception ("Exception caught:"); return 1; } return 0; }
int ACE_TMAIN(int argc, ACE_TCHAR *argv[]) { try { CORBA::ORB_var orb = CORBA::ORB_init (argc, argv); CORBA::Object_var poa_object = orb->resolve_initial_references("RootPOA"); PortableServer::POA_var root_poa = PortableServer::POA::_narrow (poa_object.in ()); if (CORBA::is_nil (root_poa.in ())) ACE_ERROR_RETURN ((LM_ERROR, " (%P|%t) Panic: nil RootPOA\n"), 1); PortableServer::POAManager_var poa_manager = root_poa->the_POAManager (); CORBA::Object_var object = orb->resolve_initial_references ("PolicyCurrent"); CORBA::PolicyCurrent_var policy_current = CORBA::PolicyCurrent::_narrow (object.in ()); if (CORBA::is_nil (policy_current.in ())) { ACE_ERROR ((LM_ERROR, "ERROR: Nil policy current\n")); return 1; } CORBA::Any scope_as_any; scope_as_any <<= Messaging::SYNC_WITH_TRANSPORT; CORBA::PolicyList policies(1); policies.length (1); policies[0] = orb->create_policy (Messaging::SYNC_SCOPE_POLICY_TYPE, scope_as_any); policy_current->set_policy_overrides (policies, CORBA::ADD_OVERRIDE); policies[0]->destroy (); if (parse_args (argc, argv) != 0) return 1; PortableServer::Servant_var<Echo> impl; { Echo * tmp; // ACE_NEW_RETURN is the worst possible way to handle // exceptions (think: what if the constructor allocates memory // and fails?), but I'm not in the mood to fight for a more // reasonable way to handle allocation errors in ACE. ACE_NEW_RETURN (tmp, Echo (orb.in (), 100), 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 (echo.in ())) { ACE_ERROR_RETURN ((LM_DEBUG, "Nil Test::Echo_Caller reference <%s>\n", ior), 1); } poa_manager->activate (); Client_Task ctask (orb.in ()); server->start_task (echo.in()); if (ctask.activate (THR_NEW_LWP | THR_JOINABLE, 4, 1) == -1) { ACE_ERROR ((LM_ERROR, "Error activating client task\n")); return 1; } ACE_Thread_Manager::instance ()->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; }
int ServerApp::run (int argc, ACE_TCHAR* argv[]) { this->orb_ = CORBA::ORB_init (argc, argv); // Parse the command-line args for this application. // * Raises -1 if problems are encountered. // * Returns 1 if the usage statement was explicitly requested. // * Returns 0 otherwise. int result = this->parse_args (argc, argv); if (result != 0) { return result; } TheOrbShutdownTask::instance()->orb (this->orb_.in ()); if (synch_with_server_) { CORBA::Object_var manager_object = orb_->resolve_initial_references("ORBPolicyManager"); CORBA::PolicyManager_var policy_manager = CORBA::PolicyManager::_narrow(manager_object.in()); if (CORBA::is_nil (policy_manager.in ())) { ACE_ERROR ((LM_ERROR, " (%P|%t) Panic: nil PolicyManager\n")); throw TestException(); } CORBA::Any policy_value; policy_value <<= Messaging::SYNC_WITH_SERVER; CORBA::PolicyList policies(1); policies.length(1); policies[0] = orb_->create_policy (Messaging::SYNC_SCOPE_POLICY_TYPE, policy_value); policy_manager->set_policy_overrides (policies, CORBA::ADD_OVERRIDE); policies[0]->destroy (); } CORBA::Object_var obj = orb_->resolve_initial_references("RootPOA"); if (CORBA::is_nil(obj.in())) { ACE_ERROR((LM_ERROR, "(%P|%t) Failed to resolve initial ref for 'RootPOA'.\n")); throw TestException(); } PortableServer::POA_var root_poa = PortableServer::POA::_narrow(obj.in()); if (CORBA::is_nil(root_poa.in())) { ACE_ERROR((LM_ERROR, "(%P|%t) Failed to narrow obj ref to POA interface.\n")); throw TestException(); } PortableServer::POAManager_var poa_manager = root_poa->the_POAManager(); // Create the child POA. CORBA::PolicyList policies(1); policies.length(1); policies[0] = root_poa->create_id_assignment_policy(PortableServer::USER_ID); PortableServer::POA_var child_poa_1 = root_poa->create_POA("ChildPoa_1", poa_manager.in(), policies); if (CORBA::is_nil(child_poa_1.in())) { ACE_ERROR((LM_ERROR, "(%P|%t) ERROR [ServerApp::run()]: " "Failed to create the ChildPoa_1.\n")); throw TestException(); } PortableServer::POA_var child_poa_2 = root_poa->create_POA("ChildPoa_2", poa_manager.in(), policies); if (CORBA::is_nil(child_poa_2.in())) { ACE_ERROR((LM_ERROR, "(%P|%t) ERROR [ServerApp::run()]: " "Failed to create the ChildPoa_2.\n")); throw TestException(); } policies[0]->destroy (); // Create the thread pool servant dispatching strategy object, and // hold it in a (local) smart pointer variable. TAO_Intrusive_Ref_Count_Handle<TAO::CSD::TP_Strategy> csd_tp_strategy = new TAO::CSD::TP_Strategy(); // We need create multiple working threads otherwise it would deadlock // with the callback test. csd_tp_strategy->set_num_threads(2); // Tell the strategy to apply itself to the child poa. if (csd_tp_strategy->apply_to(child_poa_1.in()) == false) { ACE_ERROR((LM_ERROR, "(%P|%t) ERROR [ServerApp::run()]: " "Failed to apply custom dispatching strategy to child poa 1.\n")); throw TestException(); } Foo_var foo1 = this->create_foo(child_poa_1.in(), "foo_applied_strategy"); Foo_var foo2 = this->create_foo(child_poa_2.in(), "foo_not_applied_strategy"); Callback_var callback1 = this->create_callback(child_poa_1.in(), "callback_applied_strategy"); Callback_var callback2 = this->create_callback(child_poa_2.in(), "callback_not_applied_strategy"); // Activate the POA Manager poa_manager->activate(); ACE_DEBUG((LM_DEBUG, "(%P|%t) ServerApp is ready. Running the ORB event loop.\n")); // Wait for the custom stretegy launch the dispatching threads. ACE_OS::sleep (2); ClientTask client1 (foo1.in (), callback1.in ()); if (client1.open() != 0) { ACE_ERROR((LM_ERROR, "(%P|%t) Failed to open the collocated client1.\n")); throw TestException(); } ClientTask client2 (foo2.in (), callback2.in ()); if (client2.open() != 0) { ACE_ERROR((LM_ERROR, "(%P|%t) Failed to open the collocated client2.\n")); throw TestException(); } // Run the ORB event loop. orb_->run(); ACE_DEBUG((LM_DEBUG, "(%P|%t) ServerApp ORB has stopped running.\n")); ACE_DEBUG((LM_DEBUG, "(%P|%t) Wait for the OrbShutdownTask.\n")); TheOrbShutdownTask::instance()->wait (); ACE_DEBUG((LM_DEBUG, "(%P|%t) Wait for the collocated client task.\n")); client1.wait (); client2.wait (); ACE_DEBUG((LM_DEBUG, "(%P|%t) Stop the CSD strategy.\n")); ACE_DEBUG((LM_DEBUG, "(%P|%t) ServerApp is destroying the Root POA.\n")); // Tear-down the root poa and orb_. root_poa->destroy(1, 1); ACE_DEBUG((LM_DEBUG, "(%P|%t) ServerApp is destroying the ORB.\n")); orb_->destroy(); ACE_DEBUG((LM_DEBUG, "(%P|%t) ServerApp has completed running successfully.\n")); return 0; }
int ACE_TMAIN(int argc, ACE_TCHAR *argv[]) { try { CORBA::ORB_var orb = CORBA::ORB_init(argc, argv); if (parse_args(argc, argv) != 0) { return 1; } // Create a bidirectional POA CORBA::Object_var obj = orb->resolve_initial_references("RootPOA"); PortableServer::POA_var root_poa = PortableServer::POA::_narrow(obj.in()); PortableServer::POAManager_var poa_manager = root_poa->the_POAManager(); // Policies for the childPOA to be created. CORBA::PolicyList policies(1); policies.length(1); CORBA::Any pol; pol <<= BiDirPolicy::BOTH; policies[0] = orb->create_policy(BiDirPolicy::BIDIRECTIONAL_POLICY_TYPE, pol); // Create POA as child of RootPOA with the above policies. This POA // will receive request in the same connection in which it sent // the request PortableServer::POA_var poa = root_poa->create_POA("bidirPOA", poa_manager.in(), policies); // Creation of bidirPOA is over. Destroy the Policy objects. for (CORBA::ULong i = 0; i < policies.length (); ++i) { policies[i]->destroy (); } poa_manager->activate (); PortableServer::Servant_var<Simple_i> svt = new Simple_i(orb.in(), callback_count); // Register and activate Simple servant PortableServer::ObjectId_var id = poa->activate_object(svt.in()); obj = poa->id_to_reference(id.in()); Simple_var server = Simple::_narrow(obj.in()); CORBA::String_var ior = orb->object_to_string(server.in()); if (ior_output_file != ACE_TEXT("")) { std::ofstream outfile(ACE_TEXT_ALWAYS_CHAR(ior_output_file.c_str())); outfile << ior.in(); } std::cout << "Activated as " << ior.in() << std::endl; // Our own special orb->run() that knows how to callback clients while (true) { // returns 1 as soon as it has successfully called back. if (svt->call_client()) { break; } // We don't want to check for work pending, because we really want // to simulate a normal orb->run() while adding the ability to call // our routine which calls back to the client. orb->perform_work(); } std::cout << "Event loop finished." << std::endl; CORBA::Boolean etherealize = true, wait = true; poa->destroy(etherealize, wait); orb->destroy(); return 0; } catch(const CORBA::Exception& ex) { std::cerr << "Caught CORBA::Exception: " << std::endl << ex << std::endl; } return 1; }