diff options
author | yamuna <yamuna@ae88bc3d-4319-0410-8dbf-d08b4c9d3795> | 2002-06-27 01:30:42 +0000 |
---|---|---|
committer | yamuna <yamuna@ae88bc3d-4319-0410-8dbf-d08b4c9d3795> | 2002-06-27 01:30:42 +0000 |
commit | 9e25676578ed5ed5718a048c344450bc6ddf3926 (patch) | |
tree | 1fc2c5b395c6855351cdcad3354167a422942d7c | |
parent | 272d84910cf16e86f526bfa20e7ccb574f4eefef (diff) | |
download | ATCD-9e25676578ed5ed5718a048c344450bc6ddf3926.tar.gz |
ChangelogTag: Wed June 26 2:09:00 2002 Yamuna Krishnamurthy <yamuna@oomworks.com>
-rw-r--r-- | TAO/tests/RTCORBA/Diffserv/client.cpp | 348 |
1 files changed, 348 insertions, 0 deletions
diff --git a/TAO/tests/RTCORBA/Diffserv/client.cpp b/TAO/tests/RTCORBA/Diffserv/client.cpp new file mode 100644 index 00000000000..ed082904499 --- /dev/null +++ b/TAO/tests/RTCORBA/Diffserv/client.cpp @@ -0,0 +1,348 @@ +// $Id$ + +#include "testC.h" +#include "Client_ORBInitializer.h" +#include "tao/RTCORBA/RTCORBA.h" +#include "tao/RTCORBA/RT_Policy_i.h" +#include "tao/RTCORBA/Network_Priority_Mapping_Manager.h" +#include "tao/RTCORBA/Network_Priority_Mapping.h" +#include "ace/Get_Opt.h" +#include "Custom_Network_Priority_Mapping.h" +//#include "../check_supported_priorities.cpp" +//#include "../main_thread_policy.cpp" +#include "tao/Stub.h" + +const char *ior = "file://test1.ior"; +int n = 1; +int desired_priority = 0; + +int +check_for_nil (CORBA::Object_ptr obj, const char *msg) +{ + if (CORBA::is_nil (obj)) + ACE_ERROR_RETURN ((LM_ERROR, + "ERROR: Object reference <%s> is nil\n", + msg), + -1); + else + return 0; +} + +enum +{ + OBJECT, + THREAD, + ORB +}; + +void +change_network_priority (int enable_network_priority, + int level, + Test_var &server, + CORBA::ORB_ptr orb) +{ + ACE_TRY_NEW_ENV + { + CORBA::Object_var object = + orb->resolve_initial_references ("RTORB" ACE_ENV_ARG_PARAMETER); + ACE_TRY_CHECK; + RTCORBA::RTORB_var rt_orb = + RTCORBA::RTORB::_narrow (object.in () + ACE_ENV_ARG_PARAMETER); + ACE_TRY_CHECK; + + if (check_for_nil (rt_orb.in (), "RTORB") == -1) + ACE_ERROR ((LM_ERROR, + "RTORB is nil\n")); + + //Set the tcp protocol protperties + RTCORBA::TCPProtocolProperties_var tcp_properties = + rt_orb->create_tcp_protocol_properties (ACE_DEFAULT_MAX_SOCKET_BUFSIZ, + ACE_DEFAULT_MAX_SOCKET_BUFSIZ, + 1, + 0, + 1, + enable_network_priority + ACE_ENV_ARG_PARAMETER); + ACE_TRY_CHECK; + + RTCORBA::ProtocolList protocols; + protocols.length (1); + protocols[0].protocol_type = 0; + protocols[0].transport_protocol_properties = + RTCORBA::ProtocolProperties::_duplicate (tcp_properties.in ()); + protocols[0].orb_protocol_properties = + RTCORBA::ProtocolProperties::_nil (); + + CORBA::PolicyList policy_list; + policy_list.length (1); + policy_list[0] = + rt_orb->create_client_protocol_policy (protocols + ACE_ENV_ARG_PARAMETER); + ACE_TRY_CHECK; + + + switch (level) + { + //Change policy at ORB level + case ORB: + { + // PolicyManager. + object = orb->resolve_initial_references ("ORBPolicyManager" + ACE_ENV_ARG_PARAMETER); + ACE_TRY_CHECK; + CORBA::PolicyManager_var policy_manager = + CORBA::PolicyManager::_narrow (object.in () ACE_ENV_ARG_PARAMETER); + ACE_TRY_CHECK; + + policy_manager->set_policy_overrides (policy_list, + CORBA::SET_OVERRIDE + ACE_ENV_ARG_PARAMETER); + + ACE_TRY_CHECK; + break; + } + //Change policy at THREAD level + case THREAD: + orb->orb_core ()->policy_current ().set_policy_overrides (policy_list, + CORBA::SET_OVERRIDE + ACE_ENV_ARG_PARAMETER); + + ACE_TRY_CHECK; + break; + //Change policy at OBJECT level + case OBJECT: + { + CORBA::Object_var object = server->_set_policy_overrides (policy_list, + CORBA::SET_OVERRIDE + ACE_ENV_ARG_PARAMETER); + ACE_TRY_CHECK; + server = Test::_narrow (object.in () ACE_ENV_ARG_PARAMETER); + ACE_TRY_CHECK; + break; + } + }; + + } + ACE_CATCHANY + { + ACE_PRINT_EXCEPTION (ACE_ANY_EXCEPTION, + "Caught exception:"); + } + ACE_ENDTRY; +} + + + +int +parse_args (int argc, char *argv[]) +{ + ACE_Get_Opt get_opts (argc, argv, "k:n:p:sc"); + int c; + + while ((c = get_opts ()) != -1) + switch (c) + { + case 'k': + ior = get_opts.opt_arg (); + break; + case 'n':// number of itarations + n = ACE_OS::atoi (get_opts.opt_arg ()); + break; + case 'p':// desired priority + desired_priority = ACE_OS::atoi (get_opts.opt_arg ()); + break; + case 'c': + ior = "file://test1.ior"; + break; + case 's': + ior = "file://test2.ior"; + break; + case '?': + default: + ACE_ERROR_RETURN ((LM_ERROR, + "usage: %s " + "-k <ior> " + "-n <number_of_iterations>" + "-p <desired priority>" + "\n", + argv [0]), + -1); + } + + return 0; +} + +void +toggle (int &i) +{ + if (i == 0) + i = 1; + else i = 0; +} +int +main (int argc, char *argv[]) +{ + + + ACE_TRY_NEW_ENV + { + + // Initialize and obtain reference to the Test object. + CORBA::ORB_var orb = + CORBA::ORB_init (argc, argv, "" ACE_ENV_ARG_PARAMETER); + ACE_TRY_CHECK; + + //set_main_thread_policy (orb.in ()); + + // Make sure we can support multiple priorities that are required + // for this test. + // check_supported_priorities (); + //check_supported_priorities (orb.in ()); + + + if (parse_args (argc, argv) != 0) + return 1; + + CORBA::Object_var client_object = + orb->string_to_object (ior ACE_ENV_ARG_PARAMETER); + ACE_TRY_CHECK; + + Test_var server = + Test::_narrow (client_object.in () ACE_ENV_ARG_PARAMETER); + ACE_TRY_CHECK; + + 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 + // ACE_ENV_ARG_PARAMETER); + // ACE_TRY_CHECK; + + // RTCORBA::PriorityModelPolicy_var priority_policy = + // RTCORBA::PriorityModelPolicy::_narrow (policy.in () ACE_ENV_ARG_PARAMETER); + // ACE_TRY_CHECK; + + // 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 (ACE_ENV_SINGLE_ARG_PARAMETER); + // ACE_TRY_CHECK; + + // if (priority_model != RTCORBA::CLIENT_PROPAGATED) + // ACE_ERROR_RETURN ((LM_ERROR, + // "ERROR: priority_model != " + // "RTCORBA::CLIENT_PROPAGATED!\n"), + // 1); + + + CORBA::Object_var object = orb->resolve_initial_references ("NetworkPriorityMappingManager" + ACE_ENV_ARG_PARAMETER); + ACE_TRY_CHECK; + + RTCORBA::NetworkPriorityMappingManager_var mapping_manager = + RTCORBA::NetworkPriorityMappingManager::_narrow (object.in () + ACE_ENV_ARG_PARAMETER); + ACE_TRY_CHECK; + + TAO_Custom_Network_Priority_Mapping *cnpm = 0; + ACE_NEW_RETURN (cnpm, + TAO_Custom_Network_Priority_Mapping, + -1); + + cnpm->desired_priority (desired_priority); + + //RTCORBA::NetworkPriorityMapping_var npm = + //RTCORBA::NetworkPriorityMapping::_narrow (tnpm + // ACE_ENV_ARG_PARAMETER); + //ACE_TRY_CHECK; + + mapping_manager->mapping (cnpm); + + ACE_DEBUG ((LM_DEBUG, + "Desired Priority = %d\n", + desired_priority)); + + object = + orb->resolve_initial_references ("RTCurrent" ACE_ENV_ARG_PARAMETER); + ACE_TRY_CHECK; + RTCORBA::Current_var current = + RTCORBA::Current::_narrow (object.in () ACE_ENV_ARG_PARAMETER); + ACE_TRY_CHECK; + + current->the_priority (0 ACE_ENV_ARG_PARAMETER); + ACE_TRY_CHECK; + + //CORBA::Short priority = + // current->the_priority (ACE_ENV_SINGLE_ARG_PARAMETER); + // ACE_TRY_CHECK; + + // if (desired_priority != priority) + // ACE_ERROR_RETURN ((LM_ERROR, + // "ERROR: Unable to set thread " + // "priority to %d\n", desired_priority), + // 1); + + int enp = 0; //enable_network_priority + // Make several invocation, + + for (int i = 0; i < n; ++i) + { + switch (i) + { + case 0://Set + case 1://Unset + toggle (enp); + change_network_priority (enp, ORB, server ,orb.in ()); + break; + case 2://Set + case 3://Unset + toggle (enp); + change_network_priority (enp, THREAD, server, orb.in ()); + break; + case 4://Set + case 5://Unset + default: + toggle (enp); + change_network_priority (enp, OBJECT, server, orb.in ()); + break; + }; + + server->test_method (0 ACE_ENV_ARG_PARAMETER); + ACE_TRY_CHECK; + + } + // Shut down Server ORB. + server->shutdown ();//(0 ACE_ENV_SINGLE_ARG_PARAMETER); + ACE_TRY_CHECK; + } + ACE_CATCH (CORBA::DATA_CONVERSION, ex) + { + ACE_PRINT_EXCEPTION(ex, + "Most likely, this is due to the in-ability " + "to set the thread priority."); + return 1; + } + ACE_CATCHANY + { + ACE_PRINT_EXCEPTION (ACE_ANY_EXCEPTION, + "Caught exception:"); + return 1; + } + ACE_ENDTRY; + + return 0; +} + + |