diff options
author | William R. Otte <wotte@dre.vanderbilt.edu> | 2006-07-24 15:50:21 +0000 |
---|---|---|
committer | William R. Otte <wotte@dre.vanderbilt.edu> | 2006-07-24 15:50:21 +0000 |
commit | 3aff90f4a822fcf5d902bbfbcc9fa931d6191a8c (patch) | |
tree | 197c810e5f5bce17b1233a7cb8d7b50c0bcd25e2 /TAO/tests/Exposed_Policies | |
parent | 6b846cf03c0bcbd8c276cb0af61a181e5f98eaae (diff) | |
download | ATCD-3aff90f4a822fcf5d902bbfbcc9fa931d6191a8c.tar.gz |
Repo restructuring
Diffstat (limited to 'TAO/tests/Exposed_Policies')
20 files changed, 1269 insertions, 0 deletions
diff --git a/TAO/tests/Exposed_Policies/.cvsignore b/TAO/tests/Exposed_Policies/.cvsignore new file mode 100644 index 00000000000..f2ad85300eb --- /dev/null +++ b/TAO/tests/Exposed_Policies/.cvsignore @@ -0,0 +1,2 @@ +client +server diff --git a/TAO/tests/Exposed_Policies/Counter.idl b/TAO/tests/Exposed_Policies/Counter.idl new file mode 100644 index 00000000000..d8fa1959ce3 --- /dev/null +++ b/TAO/tests/Exposed_Policies/Counter.idl @@ -0,0 +1,18 @@ +//$Id$ + +/// This interface abstracts a counter. It provides methods +/// for increasing and getting the value of the counter. +interface Counter +{ + /// Increases the counter value. + void increment (); + + /// Decreases the counter value. + long get_count (); + + /// Sets the counter value to zero. + void reset (); + + /// Shuts down the ORB on which this obj is running. + oneway void shutdown (); +}; diff --git a/TAO/tests/Exposed_Policies/Counter_i.cpp b/TAO/tests/Exposed_Policies/Counter_i.cpp new file mode 100644 index 00000000000..4a707034563 --- /dev/null +++ b/TAO/tests/Exposed_Policies/Counter_i.cpp @@ -0,0 +1,50 @@ +//$Id$ + +#include "Counter_i.h" + +ACE_RCSID(tao, Counter_Servant, "$Id$") + +// Dtor-Ctor Implementation. + +Counter_Servant::Counter_Servant (Policy_Tester *policy_tester) + : count_ (0), + policy_tester_ (policy_tester) +{ + // No-Op. +} + +Counter_Servant::~Counter_Servant (void) +{ + // No-Op. +} + +// Counter Interface Methods Implementation. + +void +Counter_Servant::increment (ACE_ENV_SINGLE_ARG_DECL_NOT_USED/*ACE_ENV_SINGLE_ARG_PARAMETER*/) + ACE_THROW_SPEC ((CORBA::SystemException)) +{ + ++this->count_; +} + +CORBA::Long +Counter_Servant::get_count (ACE_ENV_SINGLE_ARG_DECL_NOT_USED/*ACE_ENV_SINGLE_ARG_PARAMETER*/) + ACE_THROW_SPEC ((CORBA::SystemException)) +{ + return this->count_; +} + +void +Counter_Servant::reset (ACE_ENV_SINGLE_ARG_DECL_NOT_USED/*ACE_ENV_SINGLE_ARG_PARAMETER*/) + ACE_THROW_SPEC ((CORBA::SystemException)) +{ + this->count_ = 0; +} + +void +Counter_Servant::shutdown (ACE_ENV_SINGLE_ARG_DECL) + ACE_THROW_SPEC ((CORBA::SystemException)) +{ + this->policy_tester_->shutdown (ACE_ENV_SINGLE_ARG_PARAMETER); + ACE_TRY_CHECK; +} diff --git a/TAO/tests/Exposed_Policies/Counter_i.h b/TAO/tests/Exposed_Policies/Counter_i.h new file mode 100644 index 00000000000..503d9cd3296 --- /dev/null +++ b/TAO/tests/Exposed_Policies/Counter_i.h @@ -0,0 +1,55 @@ +//$Id$ + +// ============================================================================ +// +// = LIBRARY +// TAO/tests/Exposed_Policies +// +// = FILENAME +// Counter_i.h +// +// = DESCRIPTION +// This class implements the Counter IDL interface. +// +// = AUTHOR +// Angelo Corsaro <corsaro@cs.wustl.edu> +// +// ============================================================================ + +#ifndef COUNTER_I_H_ +#define COUNTER_I_H_ + +// -- App. Specific Include -- +#include "CounterS.h" +#include "Policy_Tester.h" + + +class Counter_Servant : public POA_Counter +{ +public: + + // = Ctor-Dtor Declaration + + Counter_Servant (Policy_Tester *policy_tester); + virtual ~Counter_Servant (void); + + // = Counter Interface Methods Overloading. + + virtual void increment (ACE_ENV_SINGLE_ARG_DECL_WITH_DEFAULTS) + ACE_THROW_SPEC ((CORBA::SystemException)); + + virtual CORBA::Long get_count (ACE_ENV_SINGLE_ARG_DECL_WITH_DEFAULTS) + ACE_THROW_SPEC ((CORBA::SystemException)); + + virtual void reset (ACE_ENV_SINGLE_ARG_DECL_WITH_DEFAULTS) + ACE_THROW_SPEC ((CORBA::SystemException)); + + virtual void shutdown (ACE_ENV_SINGLE_ARG_DECL_WITH_DEFAULTS) + ACE_THROW_SPEC ((CORBA::SystemException)); + +protected: + CORBA::Long count_; + Policy_Tester *policy_tester_; +}; + +#endif /*COUNTER_I_H_*/ diff --git a/TAO/tests/Exposed_Policies/Exposed_Policies.mpc b/TAO/tests/Exposed_Policies/Exposed_Policies.mpc new file mode 100644 index 00000000000..6e9c5283fe0 --- /dev/null +++ b/TAO/tests/Exposed_Policies/Exposed_Policies.mpc @@ -0,0 +1,25 @@ +// -*- MPC -*- +// $Id$ + +project(*Server): strategies, rt_server { + Source_Files { + Policy_Tester.cpp + Policy_Verifier.cpp + RT_Properties.cpp + server.cpp + } +} + +project(*Client): strategies, rt_server { + exename = client + after += *Server + + Source_Files { + CounterC.cpp + Policy_Tester.cpp + Policy_Verifier.cpp + RT_Properties.cpp + client.cpp + } +} + diff --git a/TAO/tests/Exposed_Policies/Object.cfg b/TAO/tests/Exposed_Policies/Object.cfg new file mode 100644 index 00000000000..68f5672d6ad --- /dev/null +++ b/TAO/tests/Exposed_Policies/Object.cfg @@ -0,0 +1 @@ +Priority 4 diff --git a/TAO/tests/Exposed_Policies/Object.cfg.tru64 b/TAO/tests/Exposed_Policies/Object.cfg.tru64 new file mode 100644 index 00000000000..adba1999c4a --- /dev/null +++ b/TAO/tests/Exposed_Policies/Object.cfg.tru64 @@ -0,0 +1 @@ +Priority 24 diff --git a/TAO/tests/Exposed_Policies/POA.cfg b/TAO/tests/Exposed_Policies/POA.cfg new file mode 100644 index 00000000000..d0e054fa835 --- /dev/null +++ b/TAO/tests/Exposed_Policies/POA.cfg @@ -0,0 +1,5 @@ +Priority 1 + +Priority_Bands 2 +Priority_Range 0 2 +Priority_Range 3 5 diff --git a/TAO/tests/Exposed_Policies/POA.cfg.tru64 b/TAO/tests/Exposed_Policies/POA.cfg.tru64 new file mode 100644 index 00000000000..d327282c330 --- /dev/null +++ b/TAO/tests/Exposed_Policies/POA.cfg.tru64 @@ -0,0 +1,5 @@ +Priority 21 + +Priority_Bands 2 +Priority_Range 20 22 +Priority_Range 23 25 diff --git a/TAO/tests/Exposed_Policies/Policy_Tester.cpp b/TAO/tests/Exposed_Policies/Policy_Tester.cpp new file mode 100644 index 00000000000..217eacdae41 --- /dev/null +++ b/TAO/tests/Exposed_Policies/Policy_Tester.cpp @@ -0,0 +1,298 @@ +// $Id$ + +// -- App. Specific Include -- +#include "Policy_Tester.h" +#include "RT_Properties.h" +#include "CounterC.h" + +// -- ACE Include -- +#include "ace/Arg_Shifter.h" +#include "ace/OS_NS_stdio.h" + +// -- RTCORBA Include -- +#include "tao/RTCORBA/RT_Policy_i.h" + +// -- RTCORBA Include -- +#include "tao/RTCORBA/RT_ORB.h" + +#include "tao/ORB_Constants.h" +#include "tao/ORB_Core.h" + +ACE_RCSID (tao, Policy_Tester, "$Id$") + +Policy_Tester::Policy_Tester (void) + : rt_object_properties_ (0), + rt_poa_properties_ (0) +{ + // No_Op +} + +Policy_Tester::~Policy_Tester (void) +{ +} + +void +Policy_Tester::run (ACE_ENV_SINGLE_ARG_DECL) +{ + PortableServer::POAManager_var poa_manager = + this->child_poa_->the_POAManager (ACE_ENV_SINGLE_ARG_PARAMETER); + ACE_CHECK; + + poa_manager->activate (ACE_ENV_SINGLE_ARG_PARAMETER); + ACE_CHECK; + + this->orb_->run (ACE_ENV_SINGLE_ARG_PARAMETER); + ACE_CHECK; +} + +int +Policy_Tester::init (int argc, + char *argv[] + ACE_ENV_ARG_DECL) +{ + // ORB Initialization. + this->orb_ = + CORBA::ORB_init (argc, argv, "" + ACE_ENV_ARG_PARAMETER); + ACE_CHECK_RETURN (-1); + + // Get a reference to the RT-ORB. + CORBA::Object_var object = + this->orb_->resolve_initial_references ("RTORB" + ACE_ENV_ARG_PARAMETER); + ACE_CHECK_RETURN (-1); + + this->rt_orb_ = RTCORBA::RTORB::_narrow (object.in () + ACE_ENV_ARG_PARAMETER); + ACE_CHECK_RETURN (-1); + + // Here we parse the command line paramether passed + // to the application. + + ACE_Arg_Shifter arg_shifter (argc, argv); + + while (arg_shifter.is_anything_left ()) + { + const char *arg = 0; + // IOR File Name Option. + if ((arg = arg_shifter.get_the_parameter ("-POAConfigFile"))) + { + this->rt_poa_properties_ = + RT_Properties::read_from (arg ACE_ENV_ARG_PARAMETER); + ACE_CHECK_RETURN (-1); + } + else if ((arg = arg_shifter.get_the_parameter ("-ObjectConfigFile"))) + { + this->rt_object_properties_ = + RT_Properties::read_from (arg ACE_ENV_ARG_PARAMETER); + ACE_CHECK_RETURN (-1); + } + else if ((arg = arg_shifter.get_the_parameter ("-BaseObjectIOR"))) + { + if (this->rt_poa_properties_ == 0) + { + ACE_NEW_THROW_EX (this->rt_poa_properties_, + RT_Properties, + CORBA::NO_MEMORY (TAO::VMCID, + CORBA::COMPLETED_NO)); + ACE_CHECK_RETURN (-1); + } + this->rt_poa_properties_->ior_source (arg); + } + else if ((arg = arg_shifter.get_the_parameter ("-OverriddenIOR"))) + { + if (this->rt_object_properties_ == 0) + { + ACE_NEW_THROW_EX (this->rt_object_properties_, + RT_Properties, + CORBA::NO_MEMORY (TAO::VMCID, + CORBA::COMPLETED_NO)); + ACE_CHECK_RETURN (-1); + } + this->rt_object_properties_->ior_source (arg); + } + else + arg_shifter.consume_arg (); + } + + if ((this->rt_poa_properties_ == 0) || (this->rt_object_properties_ == 0)) + { + ACE_DEBUG ((LM_DEBUG, + ACE_TEXT ("Configuration file missing!"))); + return -1; + } + + int result = + this->create_objects (ACE_ENV_SINGLE_ARG_PARAMETER); + ACE_CHECK_RETURN (-1); + + if (result != 0) + return result; + + return 0; +} + +CORBA::Boolean +Policy_Tester::check_reference (CORBA::Object_ptr object, + const char *msg) +{ + if (CORBA::is_nil (object)) + { + ACE_DEBUG ((LM_DEBUG, ACE_TEXT (msg))); + return 0; + } + return 1; +} + + +int +Policy_Tester::create_objects (ACE_ENV_SINGLE_ARG_DECL) +{ + CORBA::PolicyList poa_policy_list; + poa_policy_list.length (3); + + // Create the priority policy using the RT-ORB. + RTCORBA::Priority priority = this->rt_poa_properties_->priority (); + poa_policy_list[0] = + this->rt_orb_->create_priority_model_policy (RTCORBA::SERVER_DECLARED, + priority + ACE_ENV_ARG_PARAMETER); + ACE_CHECK_RETURN (-1); + + // Create priority Banded Connection Policy. + RTCORBA::PriorityBands poa_priority_bands = + this->rt_poa_properties_->priority_bands (); + + poa_policy_list[1] = + this->rt_orb_->create_priority_banded_connection_policy (poa_priority_bands + ACE_ENV_ARG_PARAMETER); + ACE_CHECK_RETURN (-1); + + // Client Protocol Policy. + RTCORBA::ProtocolList protocol_list; + protocol_list.length (1); + + protocol_list[0].protocol_type = IOP::TAG_INTERNET_IOP; + protocol_list[0].orb_protocol_properties = + TAO_Protocol_Properties_Factory::create_orb_protocol_property (IOP::TAG_INTERNET_IOP); + + protocol_list[0].transport_protocol_properties = + TAO_Protocol_Properties_Factory::create_transport_protocol_property (IOP::TAG_INTERNET_IOP, + this->orb_->orb_core ()); + + poa_policy_list[2] = + this->rt_orb_->create_client_protocol_policy (protocol_list); + + CORBA::Object_var object = + this->orb_->resolve_initial_references ("RootPOA" ACE_ENV_ARG_PARAMETER); + ACE_CHECK_RETURN (-1); + + this->poa_ = + PortableServer::POA::_narrow (object.in () ACE_ENV_ARG_PARAMETER); + ACE_CHECK_RETURN (-1); + + PortableServer::POAManager_var poa_mgr = + PortableServer::POAManager::_nil (); + + object = + this->poa_->create_POA ("Child_POA", + poa_mgr.in (), + poa_policy_list + ACE_ENV_ARG_PARAMETER); + ACE_CHECK_RETURN (-1); + + this->child_poa_ = + RTPortableServer::POA::_narrow (object.in () ACE_ENV_ARG_PARAMETER); + ACE_CHECK_RETURN (-1); + + // Create a Corba Object reference, using the policies + // set at the POA level. + object = + this->child_poa_->create_reference ("IDL:Counter:1.0" + ACE_ENV_ARG_PARAMETER); + ACE_CHECK_RETURN (-1); + + ACE_DEBUG ((LM_DEBUG, + ACE_TEXT ("Reference Created!\n"))); + + if (!check_reference (object.in (), + "Unable to create Object!\n")) + return -1; + + Counter_var base_object = Counter::_narrow (object.in () ACE_ENV_ARG_PARAMETER); + ACE_CHECK_RETURN (-1); + + if (!check_reference (base_object.in(), + "Unable to create a Object!\n")) + return -1; + + CORBA::String_var ior = + this->orb_->object_to_string (base_object.in () ACE_ENV_ARG_PARAMETER); + ACE_CHECK_RETURN (-1); + + ACE_DEBUG ((LM_DEBUG, + ACE_TEXT ("Activated as <%s>\n"), ior.in ())); + + FILE *output_file = ACE_OS::fopen (this->rt_poa_properties_->ior_source (), "w"); + if (output_file == 0) + ACE_ERROR_RETURN ((LM_ERROR, + ACE_TEXT ("Cannot open output file for writing IOR: %s"), + this->rt_poa_properties_->ior_source ()), + -1); + ACE_OS::fprintf (output_file, "%s", ior.in ()); + ACE_OS::fclose (output_file); + + // Now we create an object that overrides some of the policies + // set at the POA level. + + + // Create a Corba Object reference, using the policies + // set at the POA level. + + object = + this->child_poa_->create_reference_with_priority + ("IDL:Counter:1.0", + this->rt_object_properties_->priority () + ACE_ENV_ARG_PARAMETER); + ACE_CHECK_RETURN (-1); + + ACE_DEBUG ((LM_DEBUG, + ACE_TEXT ("Reference Created!\n"))); + + if (!check_reference (object.in (), + "Unable to create a Counter Object!\n")) + return -1; + + Counter_var over_object = Counter::_narrow (object.in () ACE_ENV_ARG_PARAMETER); + ACE_CHECK_RETURN (-1); + + if (!check_reference (over_object.in(), + "Unable to create Object!\n")) + return -1; + + + CORBA::String_var o_ior = + this->orb_->object_to_string (over_object.in () ACE_ENV_ARG_PARAMETER); + ACE_CHECK_RETURN (-1); + + ACE_DEBUG ((LM_DEBUG, + ACE_TEXT ("Activated as <%s>\n"), o_ior.in ())); + + output_file = ACE_OS::fopen (this->rt_object_properties_->ior_source (), "w"); + + if (output_file == 0) + ACE_ERROR_RETURN ((LM_ERROR, + ACE_TEXT ("Cannot open output file for writing IOR: %s"), + this->rt_object_properties_->ior_source ()), + -1); + ACE_OS::fprintf (output_file, "%s", o_ior.in ()); + ACE_OS::fclose (output_file); + return 0; +} + +void +Policy_Tester::shutdown (ACE_ENV_SINGLE_ARG_DECL) +{ + this->orb_->shutdown (0 ACE_ENV_ARG_PARAMETER); + ACE_CHECK; +} diff --git a/TAO/tests/Exposed_Policies/Policy_Tester.h b/TAO/tests/Exposed_Policies/Policy_Tester.h new file mode 100644 index 00000000000..970ed503b7f --- /dev/null +++ b/TAO/tests/Exposed_Policies/Policy_Tester.h @@ -0,0 +1,66 @@ +// $Id$ +// +// ============================================================================ +// +// = LIBRARY +// TAO/tests/Exposed_Policies +// +// = FILENAME +// Policy_Verifier.h +// +// = DESCRIPTION +// This class verifies that the policy are correctly embedded +// in the IOR. +// +// = AUTHOR +// Angelo Corsaro <corsaro@cs.wustl.edu> +// +// ============================================================================ + +#ifndef POLICY_TESTER_H_ +#define POLICY_TESTER_H_ + +// -- App. Specific Include -- +#include "RT_Properties.h" + +// -- TAO Include -- +#include "tao/ORB.h" +#include "tao/PortableServer/PortableServer.h" +#include "tao/RTPortableServer/RTPortableServer.h" + +class Policy_Tester +{ +public: + // Ctor/Dtor. + Policy_Tester (void); + ~Policy_Tester (void); + + void run (ACE_ENV_SINGLE_ARG_DECL); + // Runs the test. + + int init (int argc, + char *argv[] + ACE_ENV_ARG_DECL); + + void shutdown (ACE_ENV_SINGLE_ARG_DECL); +private: + // Helper method used internally. + int create_objects (ACE_ENV_SINGLE_ARG_DECL); + + CORBA::Boolean check_reference (CORBA::Object_ptr object, + const char *msg); + +private: + + int is_initialized_; + + RTCORBA::RTORB_var rt_orb_; + CORBA::ORB_var orb_; + PortableServer::POA_var poa_; + RTPortableServer::POA_var child_poa_; + RT_Properties *rt_object_properties_; + RT_Properties *rt_poa_properties_; +}; + + +#endif /* POLICY_TESTER_H_ */ diff --git a/TAO/tests/Exposed_Policies/Policy_Verifier.cpp b/TAO/tests/Exposed_Policies/Policy_Verifier.cpp new file mode 100644 index 00000000000..4541f43613c --- /dev/null +++ b/TAO/tests/Exposed_Policies/Policy_Verifier.cpp @@ -0,0 +1,267 @@ +#include "Policy_Verifier.h" +#include "ace/OS_NS_string.h" + +ACE_RCSID (tao, Policy_Verifier, "$Id$") + +Policy_Verifier::Policy_Verifier (void) + : priority_bands_ (0) +{ + ACE_OS::strcpy (this->base_object_ref_, + "file://default.ior"); + ACE_OS::strcpy (this->overridden_object_ref_, + "file://overridden.ior"); +} + +Policy_Verifier::~Policy_Verifier (void) +{ + // No Op. +} + +bool +Policy_Verifier::init (int argc, + char *argv[] + ACE_ENV_ARG_DECL) +{ + this->orb_ = + CORBA::ORB_init (argc, argv, "" ACE_ENV_ARG_PARAMETER); + ACE_CHECK_RETURN (false); + + ACE_Arg_Shifter arg_shifter (argc, argv); + + while (arg_shifter.is_anything_left ()) + { + const char *arg = 0; + // IOR File Name Option. + if ((arg = arg_shifter.get_the_parameter ("-POAConfigFile"))) + { + this->rt_poa_properties_ = + RT_Properties::read_from (arg ACE_ENV_ARG_PARAMETER); + ACE_CHECK_RETURN (false); + this->priority_bands_ = + this->rt_poa_properties_->priority_bands ().length (); + } + else if ((arg = arg_shifter.get_the_parameter ("-ObjectConfigFile"))) + { + this->rt_object_properties_ = + RT_Properties::read_from (arg ACE_ENV_ARG_PARAMETER); + ACE_CHECK_RETURN (false); + } + else if ((arg = arg_shifter.get_the_parameter ("-BaseObjectIOR"))) + { + if (this->rt_poa_properties_ == 0) + { + ACE_NEW_THROW_EX (this->rt_poa_properties_, + RT_Properties, + CORBA::NO_MEMORY (TAO::VMCID, + CORBA::COMPLETED_NO)); + ACE_CHECK_RETURN (false); + } + this->rt_poa_properties_->ior_source (arg); + ACE_OS::strcpy (this->base_object_ref_, "file://"); + ACE_OS::strcat (this->base_object_ref_, + this->rt_poa_properties_->ior_source ()); + } + else if ((arg = arg_shifter.get_the_parameter ("-OverriddenIOR"))) + { + if (this->rt_object_properties_ == 0) + { + ACE_NEW_THROW_EX (this->rt_object_properties_, + RT_Properties, + CORBA::NO_MEMORY (TAO::VMCID, + CORBA::COMPLETED_NO)); + ACE_CHECK_RETURN (false); + } + this->rt_object_properties_->ior_source (arg); + ACE_OS::strcpy (this->overridden_object_ref_, "file://"); + ACE_OS::strcat (this->overridden_object_ref_, + this->rt_object_properties_->ior_source ()); + } + else + { + arg_shifter.consume_arg (); + } + } + + if ((this->rt_poa_properties_ == 0) || (this->rt_object_properties_ == 0)) + { + ACE_DEBUG ((LM_DEBUG, + ACE_TEXT ("Configuration file missing!\n"))); + return false; + } + + // Get the Object references. + CORBA::Object_var object = this->orb_->string_to_object (this->base_object_ref_ + ACE_ENV_ARG_PARAMETER); + ACE_CHECK_RETURN (false); + + if (!Policy_Verifier::check_reference (object.in (), "Invalid IOR file!\n")) + return false; + + this->base_object_ = Counter::_narrow (object.in () ACE_ENV_ARG_PARAMETER); + ACE_CHECK_RETURN (false); + + if (!Policy_Verifier::check_reference (this->base_object_.in (), + "Unable to convert the IOR to the proper object reference.\n")) + return false; + + object = this->orb_->string_to_object (this->overridden_object_ref_ ACE_ENV_ARG_PARAMETER); + ACE_CHECK_RETURN (false); + + if (!Policy_Verifier::check_reference (object.in (), "Invalid IOR file!\n")) + return false; + + this->overridden_object_ = Counter::_narrow (object.in () ACE_ENV_ARG_PARAMETER); + ACE_CHECK_RETURN (false); + + if (!Policy_Verifier::check_reference (this->overridden_object_.in (), + "Unable to convert the IOR to the proper object reference.\n")) + return false; + + return true; +} + +void +Policy_Verifier::run (ACE_ENV_SINGLE_ARG_DECL ) +{ + this->verify_reference (this->base_object_.in (), + this->rt_poa_properties_ + ACE_ENV_ARG_PARAMETER); + ACE_CHECK; + + this->verify_reference (this->overridden_object_.in (), + this->rt_object_properties_ + ACE_ENV_ARG_PARAMETER); + ACE_CHECK; +} + +void +Policy_Verifier::verify_reference (Counter_ptr object, + RT_Properties *rt_properties + ACE_ENV_ARG_DECL) +{ + + ACE_TRY + { + CORBA::Policy_var policy_var = + object->_get_policy (RTCORBA::PRIORITY_MODEL_POLICY_TYPE + ACE_ENV_ARG_PARAMETER); + ACE_TRY_CHECK; + + if (Policy_Verifier::check_reference (policy_var.in (), "Unable to get Priority Policy.\n")) + { + RTCORBA::PriorityModelPolicy_var priority_policy = + RTCORBA::PriorityModelPolicy::_narrow (policy_var.in ()); + + RTCORBA::PriorityModel priority_model = + priority_policy->priority_model (ACE_ENV_SINGLE_ARG_PARAMETER); + ACE_TRY_CHECK; + + RTCORBA::Priority priority = + priority_policy->server_priority (ACE_ENV_SINGLE_ARG_PARAMETER); + ACE_TRY_CHECK; + + if (priority_model == RTCORBA::SERVER_DECLARED) + ACE_DEBUG ((LM_DEBUG, + ACE_TEXT ("\n\nPriority Model: RTCORBA::SERVER_DECLARED\n") + )); + + ACE_DEBUG ((LM_DEBUG, + ACE_TEXT ("Priority Model: %d\nCORBA Priority: %d\n\n"), + priority_model, + priority + )); + + + if (priority != rt_properties->priority ()) + ACE_DEBUG ((LM_DEBUG, + ACE_TEXT ("Priority Value Mismatch.\n"))); + } + + policy_var = object->_get_policy (RTCORBA::PRIORITY_BANDED_CONNECTION_POLICY_TYPE + ACE_ENV_ARG_PARAMETER); + ACE_TRY_CHECK; + + if (Policy_Verifier::check_reference (policy_var.in (), + "Unable to get Priority Banded Policy\n")) + { + + RTCORBA::PriorityBandedConnectionPolicy_var priority_banded_policy = + RTCORBA::PriorityBandedConnectionPolicy::_narrow (policy_var.in () + ACE_ENV_ARG_PARAMETER); + ACE_TRY_CHECK; + + + if (Policy_Verifier::check_reference (priority_banded_policy.in (), + "Unable to get Priority Banded Policy\n")) + { + + // Here we have a priority banded connection policy. + + RTCORBA::PriorityBands_var pb = + priority_banded_policy->priority_bands (); + unsigned int band_num = pb->length (); + if (band_num != this->priority_bands_) + ACE_DEBUG ((LM_DEBUG, + ACE_TEXT ("Mismatching Number of Priority Bands!\n"))); + + for (unsigned int i = 0; i < band_num; ++i) + { + ACE_DEBUG ((LM_DEBUG, + ACE_TEXT ("Priority Band <%d>: (%d, %d)\n"), + i, + pb[i].low, + pb[i].high + )); + + + if ((band_num == rt_properties->priority_bands ().length ()) && + ((pb[i].low != rt_properties->priority_bands ()[i].low) || + (pb[i].high != rt_properties->priority_bands ()[i].high))) + ACE_DEBUG ((LM_DEBUG, + ACE_TEXT ("Mismatching Priority Band Range!\n"))); + + } + } + } + policy_var = object->_get_policy (RTCORBA::CLIENT_PROTOCOL_POLICY_TYPE + ACE_ENV_ARG_PARAMETER); + ACE_TRY_CHECK; + + if (Policy_Verifier::check_reference (policy_var.in (), + "Unable to get Client Protocol Policy\n")) + { + RTCORBA::ClientProtocolPolicy_var client_protocol_policy = + RTCORBA::ClientProtocolPolicy::_narrow (policy_var.in () ACE_ENV_ARG_PARAMETER); + ACE_TRY_CHECK; + + RTCORBA::ProtocolList_var protocol_list = + client_protocol_policy->protocols (ACE_ENV_SINGLE_ARG_PARAMETER); + ACE_TRY_CHECK; + + for (unsigned int i = 0; i < protocol_list->length (); i++) + ACE_DEBUG ((LM_DEBUG, + ACE_TEXT ("\nThe Client Protocol Type: %d\n"), + protocol_list[i].protocol_type)); + + } + + } + ACE_CATCHANY + { + ACE_PRINT_EXCEPTION (ACE_ANY_EXCEPTION, "CORBA Exception Raised"); + } + + ACE_ENDTRY; +} + +CORBA::Boolean +Policy_Verifier::check_reference (CORBA::Object_ptr object, + const char *msg) +{ + if (CORBA::is_nil (object)) + { + ACE_DEBUG ((LM_DEBUG, ACE_TEXT (msg))); + return 0; + } + return 1; +} diff --git a/TAO/tests/Exposed_Policies/Policy_Verifier.h b/TAO/tests/Exposed_Policies/Policy_Verifier.h new file mode 100644 index 00000000000..8eeec72ae89 --- /dev/null +++ b/TAO/tests/Exposed_Policies/Policy_Verifier.h @@ -0,0 +1,72 @@ +// $Id$ +// +// ============================================================================ +// +// = LIBRARY +// TAO/tests/Exposed_Policies +// +// = FILENAME +// Policy_Verifier.h +// +// = DESCRIPTION +// This class verifies that the policy are correctly embedded +// in the IOR. +// +// = AUTHOR +// Angelo Corsaro <corsaro@cs.wustl.edu> +// +// ============================================================================ + +#ifndef POLICY_VERIFIER_H_ +#define POLICY_VERIFIER_H_ + +// -- App. Specific Include -- +#include "CounterC.h" +#include "RT_Properties.h" + +// -- ACE Include -- +#include "ace/Arg_Shifter.h" +#include "ace/Log_Msg.h" + +// -- TAO Include -- +#include "tao/Basic_Types.h" +#include "tao/ORB_Constants.h" + +class Policy_Verifier +{ +public: + + // -- Ctor/Dtor -- + Policy_Verifier (void); + ~Policy_Verifier (void); + + bool init (int argc, + char *argv[] + ACE_ENV_ARG_DECL_WITH_DEFAULTS); + + void run (ACE_ENV_SINGLE_ARG_DECL_WITH_DEFAULTS); + +private: + // -- Helper methods -- + void verify_reference (Counter_ptr counter, + RT_Properties *rt_properties + ACE_ENV_ARG_DECL_WITH_DEFAULTS); + + CORBA::Boolean check_reference (CORBA::Object_ptr object, + const char *msg); + +private: + + CORBA::ORB_var orb_; + + RT_Properties *rt_object_properties_; + RT_Properties *rt_poa_properties_; + unsigned int priority_bands_; + Counter_var base_object_; + Counter_var overridden_object_; + + char base_object_ref_[256]; + char overridden_object_ref_[256]; +}; + +#endif /* POLICY_VERIFIER_H_ */ diff --git a/TAO/tests/Exposed_Policies/README b/TAO/tests/Exposed_Policies/README new file mode 100644 index 00000000000..ad737b918e0 --- /dev/null +++ b/TAO/tests/Exposed_Policies/README @@ -0,0 +1,79 @@ +$Id$ + +This directory contains a test case used to verify that the client +exposed policies get embedded correctly in the IOR and exposed to the +client in the object reference. + +The policy tested are: + + - PriorityModelPolicy + - PriorityBandedConnectionPolicy + - ClientProtocolPolicy + +The policy can be set at POA level or at object level. The policies +that have to be associated with a POA or with an object are specified +using a configuration file. As an example we can consider the file +POA.cfg that contains the policy used to create a child POA: + +File: POA.cfg + + IOR_Source poa.ior + + Priority 10 + + Priority_Bands 5 + Priority_Range 3 5 + Priority_Range 7 11 + Priority_Range 5 9 + Priority_Range 1 5 + Priority_Range 10 15 + + +The tag used to decribe the information have the following meaning: + + - IOR_Source: Defines the name of the file that has to be used to + store the IOR of the object created. + + - Priority: Defines a CORBA::Priority value. + + - Priority_Bands: Defines the number of priority bands. + + - Priority_Range: Defines the priority range associated with a + priority_band. + + +The policies value that are specified in the config file can be used +to set the policy at POA level or to override those police on a Object +level basis (beaware that the only policy that can be overridden on an +Object basis is the Priority). + +In particular the option "-POAConfigFile" let you specify the policy +that have to be used when the POA is created. While the option +"-ObjectConfigFile" let you set the options on a object basis +overriding the policies that were set at a POA level. + + +When the test is run two object are created, of this object one has +the same priority that where specified when the POA was created, while +the other ovverride some of them as prescribed in the config file +specified with the option "-ObjectConfigFile". + +The config file are used by the client side to verify that what is +embedded in the IOR is correct. + + +USAGE: + + server -ORBSvcConf server.conf -ORBendpoint iiop://<hostaddr>:0/priority=<priority> -ORBendpoint iiop://<hostaddr>:0/priority=<priority> -POAConfigFile <config_file_name> -ObjectConfigFile <config_file_name> + + client -POAConfigFile <config_file_name> + -ObjectConfigFile <config_file_name> + + +EXAMPLE: + + $ server -POAConfigFile POA.cfg -ObjectConfigFile Object.cfg + + $ client -POAConfigFile POA.cfg -ObjectConfigFile Object.cfg + + $ client -POAConfigFile POA.cfg -ObjectConfigFile Object.cfg diff --git a/TAO/tests/Exposed_Policies/RT_Properties.cpp b/TAO/tests/Exposed_Policies/RT_Properties.cpp new file mode 100644 index 00000000000..4a23c92f0f5 --- /dev/null +++ b/TAO/tests/Exposed_Policies/RT_Properties.cpp @@ -0,0 +1,107 @@ +//$Id$ + +#include "RT_Properties.h" + +#include "tao/ORB_Constants.h" + +#include "ace/OS_NS_stdio.h" +#include "ace/OS_NS_string.h" + +ACE_RCSID (ExposedPolicies, RT_Properties, "$Id$") + +RT_Properties::RT_Properties (void) + : priority_ (10) +{ + ACE_OS::strcpy (ior_source_, "poa_default.ior"); +} + +RT_Properties::~RT_Properties (void) +{ + // No-Op. +} + +RT_Properties * +RT_Properties::read_from (const char *file_name + ACE_ENV_ARG_DECL) +{ + FILE *fp = ACE_OS::fopen (file_name, "r"); + + RT_Properties *rt_properties; + + ACE_NEW_THROW_EX (rt_properties, + RT_Properties, + CORBA::NO_MEMORY (TAO::VMCID, + CORBA::COMPLETED_NO)); + + // @@ Angelo: what if the length is more than 255? + char string_field[256]; + int int_field; + unsigned int i = 0; + + while (fscanf (fp, "%s", string_field) != EOF ) + { + if (ACE_OS::strcmp (string_field, "Priority") == 0) + { + fscanf (fp, "%d", &int_field); + rt_properties->priority (int_field); + } + else if (ACE_OS::strcmp (string_field, "Priority_Bands") == 0) + { + fscanf (fp, "%d", &int_field); + rt_properties->priority_bands_.length (int_field); + + } + else if (ACE_OS::strcmp (string_field, "Priority_Range") == 0) + { + fscanf (fp, "%d", &int_field); + rt_properties->priority_bands_[i].low = int_field; + + fscanf (fp, "%d", &int_field); + rt_properties->priority_bands_[i].high = int_field; + + ++i; + } + } + + + return rt_properties; +} + +void +RT_Properties::priority (RTCORBA::Priority priority) +{ + this->priority_ = priority; +} + +RTCORBA::Priority +RT_Properties::priority (void) +{ + return this->priority_; +} + +void +RT_Properties::priority_bands (const RTCORBA::PriorityBands& priority_bands) +{ + this->priority_bands_ = priority_bands; +} + +const RTCORBA::PriorityBands& +RT_Properties::priority_bands (void) +{ + return this->priority_bands_; +} + + +void +RT_Properties::ior_source (const char *s) +{ + // @@ Angelo: please use strncpy() for strings like this, otherwise + // you could blow the buffer limits! + ACE_OS::strcpy (this->ior_source_, s); +} + +const char * +RT_Properties::ior_source (void) +{ + return this->ior_source_; +} diff --git a/TAO/tests/Exposed_Policies/RT_Properties.h b/TAO/tests/Exposed_Policies/RT_Properties.h new file mode 100644 index 00000000000..35166b9d9fa --- /dev/null +++ b/TAO/tests/Exposed_Policies/RT_Properties.h @@ -0,0 +1,52 @@ +//$Id$ +// +// ============================================================================ +// +// = LIBRARY +// TAO +// +// = FILENAME +// RT_Properties.h +// +// = DESCRIPTION +// Defines a series of "real time" property that an Object +// or a POA created on a RT-ORB can have. +// +// = AUTHOR +// Angelo Corsaro <corsaro@cs.wustl.edu> +// +// ============================================================================ + +#ifndef RT_PROPERTIES_H_ +#define RT_PROPERTIES_H_ + +#include "tao/RTCORBA/RTCORBA.h" + +class RT_Properties +{ +public: + // -- Ctor/Dtor -- + RT_Properties (void); + ~RT_Properties (void); + + static RT_Properties * read_from (const char *file_name + ACE_ENV_ARG_DECL); + + // -- Accessor Methods -- + void priority (RTCORBA::Priority priority); + RTCORBA::Priority priority (void); + + void priority_bands (const RTCORBA::PriorityBands& priority_bands); + const RTCORBA::PriorityBands& priority_bands (void); + + void ior_source (const char *s); + const char* ior_source (void); + +private: + + RTCORBA::Priority priority_; + RTCORBA::PriorityBands priority_bands_; + char ior_source_[256]; +}; + +#endif /* RT_PROPERTIES_H_ */ diff --git a/TAO/tests/Exposed_Policies/client.cpp b/TAO/tests/Exposed_Policies/client.cpp new file mode 100644 index 00000000000..80bc23f24f3 --- /dev/null +++ b/TAO/tests/Exposed_Policies/client.cpp @@ -0,0 +1,46 @@ +// $Id$ + +// -- App. Specific Include -- +#include "CounterC.h" +// #include "util.h" + +// -- App. Specific Include -- +#include "Policy_Verifier.h" + +#include "tao/Strategies/advanced_resource.h" + +ACE_RCSID(tao, client, "$Id$") + +int +main (int argc, char *argv[]) +{ + int status = 0; + ACE_DECLARE_NEW_CORBA_ENV; + + ACE_TRY + { + Policy_Verifier policy_verifier; + + bool retval = policy_verifier.init (argc, argv ACE_ENV_ARG_PARAMETER); + ACE_TRY_CHECK; + + if (retval) + { + policy_verifier.run (ACE_ENV_SINGLE_ARG_PARAMETER); + ACE_TRY_CHECK; + } + else + { + status++; + } + } + ACE_CATCHANY + { + ACE_PRINT_EXCEPTION (ACE_ANY_EXCEPTION, "CORBA Exception Raised"); + status++; + } + + ACE_ENDTRY; + + return status; +} diff --git a/TAO/tests/Exposed_Policies/run_test.pl b/TAO/tests/Exposed_Policies/run_test.pl new file mode 100755 index 00000000000..9ea2e82c7d1 --- /dev/null +++ b/TAO/tests/Exposed_Policies/run_test.pl @@ -0,0 +1,68 @@ +eval '(exit $?0)' && eval 'exec perl -S $0 ${1+"$@"}' + & eval 'exec perl -S $0 $argv:q' + if 0; + +# $Id$ +# -*- perl -*- + +use lib "../../../bin"; +require PerlACE::Run_Test; + +$base_ior_file = PerlACE::LocalFile ("default.ior"); +$overridden_ior_file = PerlACE::LocalFile ("overridden.ior"); + +if (PerlACE::is_vxworks_test()) { + $SV = new PerlACE::ProcessVX ("server", + " -POAConfigFile POA.cfg" . + " -ObjectConfigFile Object.cfg" . + " -BaseObjectIOR default.ior" . + " -OverriddenIOR overridden.ior"); +} +else { + if ($^O eq "dec_osf") { + $poa_file = PerlACE::LocalFile ("POA.cfg.tru64"); + $obj_file = PerlACE::LocalFile ("Object.cfg.tru64"); + } + else { + $poa_file = PerlACE::LocalFile ("POA.cfg"); + $obj_file = PerlACE::LocalFile ("Object.cfg"); + } + $SV = new PerlACE::Process ("server", + " -POAConfigFile $poa_file" . + " -ObjectConfigFile $obj_file" . + " -BaseObjectIOR $base_ior_file" . + " -OverriddenIOR $overridden_ior_file"); +} + +$CL = new PerlACE::Process ("client", "-POAConfigFile $poa_file" + . " -ObjectConfigFile $obj_file" + . " -BaseObjectIOR $base_ior_file" + . " -OverriddenIOR $overridden_ior_file"); + +$status = 0; + +unlink($base_ior_file); +unlink($overridden_ior_file); +$SV->Spawn (); + +if (PerlACE::waitforfile_timed ($base_ior_file, 15) == -1) { + print STDERR "ERROR: cannot find file <$base_ior_file>\n"; + $SV->Kill (); + exit 1; +} + +$client = $CL->SpawnWaitKill (30); + +if ($client != 0) { + print STDERR "ERROR: client returned $client\n"; + $status = 1; +} + +$server = $SV->TerminateWaitKill (10); + +if ($server != 0) { + print STDERR "ERROR: server returned $server\n"; + $status = 1; +} + +exit $status; diff --git a/TAO/tests/Exposed_Policies/server.cpp b/TAO/tests/Exposed_Policies/server.cpp new file mode 100644 index 00000000000..ecc7d20d022 --- /dev/null +++ b/TAO/tests/Exposed_Policies/server.cpp @@ -0,0 +1,50 @@ +//$Id$ + +//////////////////////////////////////////////////////////////////////// +// This files tests the Client exposed policies: +// - PriorityModelPolicy +// - PriorityBandedConnectionPolicy +// - ClientProtocolPolicy +// +// This policies are embedded in the object reference, by writem +// them into the IOR. +// +// +// -- App. Specific Include -- +#include "Policy_Tester.h" + +#include "tao/Strategies/advanced_resource.h" + +ACE_RCSID(tao, server, "$Id$") + + +int +main (int argc, char *argv[]) +{ + ACE_DECLARE_NEW_CORBA_ENV; + + ACE_TRY + { + Policy_Tester policy_tester; + + int result = policy_tester.init (argc, argv ACE_ENV_ARG_PARAMETER); + ACE_TRY_CHECK; + + if (result != 0) + return result; + + policy_tester.run (ACE_ENV_SINGLE_ARG_PARAMETER); + ACE_TRY_CHECK; + } + + ACE_CATCHANY + { + ACE_PRINT_EXCEPTION (ACE_ANY_EXCEPTION, + ACE_TEXT ("CORBA Exception Raised.")); + return 1; + } + + ACE_ENDTRY; + + return 0; +} diff --git a/TAO/tests/Exposed_Policies/svc.conf b/TAO/tests/Exposed_Policies/svc.conf new file mode 100644 index 00000000000..37973382e2c --- /dev/null +++ b/TAO/tests/Exposed_Policies/svc.conf @@ -0,0 +1,2 @@ +# Regular test +static RT_ORB_Loader "-ORBSchedPolicy SCHED_FIFO" |