int Task::svc (void) { try { // Priority Mapping Manager. CORBA::Object_var object = this->orb_->resolve_initial_references ("PriorityMappingManager"); RTCORBA::PriorityMappingManager_var mapping_manager = RTCORBA::PriorityMappingManager::_narrow (object.in ()); if (check_for_nil (mapping_manager.in (), "Mapping Manager") == -1) return -1; RTCORBA::PriorityMapping *pm = mapping_manager->mapping (); // RTCurrent. object = this->orb_->resolve_initial_references ("RTCurrent"); RTCORBA::Current_var current = RTCORBA::Current::_narrow (object.in ()); if (check_for_nil (current.in (), "RTCurrent") == -1) return -1; // Obtain Test object reference. object = this->orb_->string_to_object (ior); Test_var server = Test::_narrow (object.in ()); if (check_for_nil (server.in (), "Test object") == -1) return -1; // Check that test object is configured with CLIENT_PROPAGATED // PriorityModelPolicy. CORBA::Policy_var policy = server->_get_policy (RTCORBA::PRIORITY_MODEL_POLICY_TYPE); RTCORBA::PriorityModelPolicy_var priority_policy = RTCORBA::PriorityModelPolicy::_narrow (policy.in ()); if (check_for_nil (priority_policy.in (), "PriorityModelPolicy") == -1) return -1; RTCORBA::PriorityModel priority_model = priority_policy->priority_model (); if (priority_model != RTCORBA::CLIENT_PROPAGATED) ACE_ERROR_RETURN ((LM_ERROR, "ERROR: priority_model != " "RTCORBA::CLIENT_PROPAGATED!\n"), -1); // Spawn two worker threads. ACE_Barrier thread_barrier (2); int flags = THR_NEW_LWP | THR_JOINABLE | this->orb_->orb_core ()->orb_params ()->thread_creation_flags (); // Worker 1. Worker_Thread worker1 (this->orb_.in (), server.in (), protocol1, &thread_barrier); CORBA::Short native_priority1 = 0; if (pm->to_native (priority1, native_priority1) == 0) ACE_ERROR_RETURN ((LM_ERROR, "Cannot convert corba priority %d to native priority\n", priority1), -1); if (worker1.activate (flags, 1, 0, native_priority1) != 0) ACE_ERROR_RETURN ((LM_ERROR, "Cannot activate first client worker threads\n"), -1); // Worker 2. Worker_Thread worker2 (this->orb_.in (), server.in (), protocol2, &thread_barrier); CORBA::Short native_priority2 = 0; if (pm->to_native (priority2, native_priority2) == 0) ACE_ERROR_RETURN ((LM_ERROR, "Cannot convert corba priority %d to native priority\n", priority2), -1); if (worker2.activate (flags, 1, 0, native_priority2) != 0) ACE_ERROR_RETURN ((LM_ERROR, "Cannot activate second client worker threads\n"), -1); // Wait for worker threads to finish. ACE_Thread_Manager::instance ()->wait (); // Testing over. Shut down the server. ACE_DEBUG ((LM_DEBUG, "Client threads finished\n")); current->the_priority (priority1); server->shutdown (); } catch (const CORBA::Exception& ex) { ex._tao_print_exception ( "Unexpected exception in MT_Client_Protocol_Priority test client:"); return -1; } return 0; }
int Task::svc (void) { int result = 0; try { CORBA::Object_var object = this->orb_->string_to_object (ior); Test_var server = Test::_narrow (object.in ()); if (CORBA::is_nil (server.in ())) { ACE_ERROR_RETURN ((LM_ERROR, "ERROR: Object reference <%s> is nil\n", ior), -1); } // Check that the object is configured with CLIENT_PROPAGATED // PriorityModelPolicy. CORBA::Policy_var policy = server->_get_policy (RTCORBA::PRIORITY_MODEL_POLICY_TYPE); RTCORBA::PriorityModelPolicy_var priority_policy = RTCORBA::PriorityModelPolicy::_narrow (policy.in ()); if (CORBA::is_nil (priority_policy.in ())) ACE_ERROR_RETURN ((LM_ERROR, "ERROR: Priority Model Policy not exposed!\n"), -1); RTCORBA::PriorityModel priority_model = priority_policy->priority_model (); if (priority_model != RTCORBA::CLIENT_PROPAGATED) ACE_ERROR_RETURN ((LM_ERROR, "ERROR: priority_model != " "RTCORBA::CLIENT_PROPAGATED!\n"), -1); // Make several invocations, changing the priority of this thread // for each. object = this->orb_->resolve_initial_references ("RTCurrent"); RTCORBA::Current_var current = RTCORBA::Current::_narrow (object.in ()); object = this->orb_->resolve_initial_references ("PriorityMappingManager"); RTCORBA::PriorityMappingManager_var mapping_manager = RTCORBA::PriorityMappingManager::_narrow (object.in ()); RTCORBA::PriorityMapping *pm = mapping_manager->mapping (); int sched_policy = this->orb_->orb_core ()->orb_params ()->ace_sched_policy (); int max_priority = ACE_Sched_Params::priority_max (sched_policy); int min_priority = ACE_Sched_Params::priority_min (sched_policy); CORBA::Short native_priority = (max_priority - min_priority) / 2; CORBA::Short desired_priority = 0; for (int i = 0; i < 3; ++i) { if (pm->to_CORBA (native_priority, desired_priority) == 0) { ACE_ERROR ((LM_ERROR, "ERROR: Cannot convert native priority %d to corba priority\n", native_priority)); result = -1; break; } current->the_priority (desired_priority); CORBA::Short priority = current->the_priority (); if (desired_priority != priority) { ACE_ERROR ((LM_ERROR, "ERROR: No exception setting the priority but mismatch between requested and returned value from Current. " "Set to %d but Current::the_priority returns %d\n", desired_priority, priority)); result = -1; } server->test_method (priority); native_priority++; } // Shut down Server ORB. server->shutdown (); } catch (const CORBA::DATA_CONVERSION& ex) { ex._tao_print_exception ( "Most likely, this is due to the in-ability " "to set the thread priority."); return -1; } catch (const CORBA::Exception & ae) { ae._tao_print_exception ( "Caught exception:"); return -1; } return result; }