From fe26d40a25b309313356dc00ca6e77dcab461e29 Mon Sep 17 00:00:00 2001 From: yamuna Date: Mon, 16 Jun 2003 16:38:30 +0000 Subject: *** empty log message *** --- TAO/examples/RTScheduling/Starter.cpp | 180 ++++++++++++++++++++++++++++++++++ TAO/examples/RTScheduling/Starter.h | 39 ++++++++ TAO/examples/RTScheduling/Synch.idl | 6 ++ TAO/examples/RTScheduling/Synch_i.h | 25 +++++ 4 files changed, 250 insertions(+) create mode 100644 TAO/examples/RTScheduling/Starter.cpp create mode 100644 TAO/examples/RTScheduling/Starter.h create mode 100644 TAO/examples/RTScheduling/Synch.idl create mode 100644 TAO/examples/RTScheduling/Synch_i.h diff --git a/TAO/examples/RTScheduling/Starter.cpp b/TAO/examples/RTScheduling/Starter.cpp new file mode 100644 index 00000000000..de382699778 --- /dev/null +++ b/TAO/examples/RTScheduling/Starter.cpp @@ -0,0 +1,180 @@ +//$Id$ + +#include "Starter.h" + + +Starter::Starter (CORBA::ORB_ptr orb) +{ + // Initialize the naming service + if (this->naming_client_.init (orb) != 0) + ACE_ERROR ((LM_ERROR, + " (%P|%t) Unable to initialize " + "the TAO_Naming_Client. \n")); +} + +void +Starter::init (ACE_ENV_SINGLE_ARG_DECL) +{ + this->resolve_synch_objs (ACE_ENV_ARG_PARAMETER); + ACE_CHECK; + + this->fire (); +} + +void +Starter::fire (void) +{ + ACE_Time_Value base_time = ACE_OS::gettimeofday (); + for (Synchs::iterator iterator = this->synchs_.begin (); + iterator != this->synchs_.end (); + ++iterator) + { + (*iterator).int_id_.in ()->go (base_time.sec ()); + } +} + +void +Starter::resolve_synch_objs (ACE_ENV_SINGLE_ARG_DECL) +{ + CosNaming::Name name (1); + name.length (1); + + // Get the sender context. + name [0].id = + CORBA::string_dup ("Synch"); + + CORBA::Object_var object = + this->naming_client_->resolve (name + ACE_ENV_ARG_PARAMETER); + ACE_CHECK; + + this->synch_context_ = + CosNaming::NamingContext::_narrow (object.in ()); + + + CosNaming::BindingIterator_var iterator; + CosNaming::BindingList_var binding_list; + const CORBA::ULong chunk = 100; + + // Get the list of synchs registered for this sender. + this->synch_context_->list (chunk, + binding_list, + iterator + ACE_ENV_ARG_PARAMETER); + ACE_CHECK; + + // Add the receivers found in the bindinglist to the . + this->add_to_synchs (binding_list + ACE_ENV_ARG_PARAMETER); + ACE_CHECK; + + if (!CORBA::is_nil (iterator.in ())) + { + CORBA::Boolean more = 1; + + // Check to see if there are more receivers listed. + while (more) + { + more = iterator->next_n (chunk, + binding_list + ACE_ENV_ARG_PARAMETER); + ACE_CHECK; + + this->add_to_synchs (binding_list + ACE_ENV_ARG_PARAMETER); + ACE_CHECK; + } + } + +} + + +void +Starter::add_to_synchs (CosNaming::BindingList &binding_list + ACE_ENV_ARG_DECL) +{ + ACE_Time_Value base_time = ACE_OS::gettimeofday (); + for (CORBA::ULong i = 0; + i < binding_list.length (); + i++) + { + // Get the receiver name from the binding list. + ACE_CString synch_name = + binding_list [i].binding_name [0].id.in (); + + ACE_DEBUG ((LM_DEBUG, + "Synch Name %s\n", + synch_name.c_str ())); + + CosNaming::Name name (1); + name.length (1); + name [0].id = + CORBA::string_dup (synch_name.c_str ()); + + // Resolve the reference of the receiver from the receiver + // context. + CORBA::Object_var obj = + this->synch_context_->resolve (name + ACE_ENV_ARG_PARAMETER); + + Synch_var synch_obj = + Synch::_narrow (obj.in ()); + + + synch_obj->go (base_time.sec ()); + +// // Add this receiver to the receiver map. +// this->synchs_.bind (synch_name, +// synch_obj); + } +} + + +int +main (int argc, char** argv) +{ + ACE_TRY_NEW_ENV + { + CORBA::ORB_var orb = CORBA::ORB_init (argc, + argv, + "" + ACE_ENV_ARG_PARAMETER); + ACE_TRY_CHECK; + + Starter starter (orb.in ()); + + starter.init (ACE_ENV_ARG_PARAMETER); + ACE_TRY_CHECK; + + } + ACE_CATCHANY + { + ACE_PRINT_EXCEPTION (ACE_ANY_EXCEPTION, + "Caught exception:"); + return 1; + } + ACE_ENDTRY; + +} + + +#if defined (ACE_HAS_EXPLICIT_TEMPLATE_INSTANTIATION) + +template class ACE_Hash_Map_Entry; +template class ACE_Hash_Map_Manager; +template class ACE_Hash_Map_Manager_Ex, ACE_Equal_To, ACE_Null_Mutex>; +template class ACE_Hash_Map_Iterator_Base_Ex, ACE_Equal_To, ACE_Null_Mutex>; +template class ACE_Hash_Map_Iterator_Ex, ACE_Equal_To, ACE_Null_Mutex>; +template class ACE_Hash_Map_Reverse_Iterator_Ex, ACE_Equal_To, ACE_Null_Mutex>; + +#elif defined (ACE_HAS_TEMPLATE_INSTANTIATION_PRAGMA) + +#pragma instantiate ACE_Hash_Map_Entry +#pragma instantiate ACE_Hash_Map_Manager +#pragma instantiate ACE_Hash_Map_Manager_Ex, ACE_Equal_To, ACE_Null_Mutex> +#pragma instantiate ACE_Hash_Map_Iterator_Base_Ex, ACE_Equal_To, ACE_Null_Mutex> +#pragma instantiate ACE_Hash_Map_Iterator_Ex, ACE_Equal_To, ACE_Null_Mutex> +#pragma instantiate ACE_Hash_Map_Reverse_Iterator_Ex, ACE_Equal_To, ACE_Null_Mutex> + + +#endif /* ACE_HAS_EXPLICIT_TEMPLATE_INSTANTIATION */ diff --git a/TAO/examples/RTScheduling/Starter.h b/TAO/examples/RTScheduling/Starter.h new file mode 100644 index 00000000000..2c499cfda05 --- /dev/null +++ b/TAO/examples/RTScheduling/Starter.h @@ -0,0 +1,39 @@ +//$Id$ +#ifndef STARTER_H +#define STARTER_H + +#include "orbsvcs/Naming/Naming_Utils.h" +#include "SynchC.h" +#include "ace/SString.h" +#include "ace/Hash_Map_Manager.h" + +class Starter +{ + public: + + Starter (CORBA::ORB_ptr orb); + + void init (ACE_ENV_SINGLE_ARG_DECL_WITH_DEFAULTS); + + void fire (void); + + typedef ACE_Hash_Map_Manager Synchs; + + + private: + void resolve_synch_objs (ACE_ENV_SINGLE_ARG_DECL_WITH_DEFAULTS); + + void add_to_synchs (CosNaming::BindingList &binding_list + ACE_ENV_ARG_DECL_WITH_DEFAULTS); + + + /// A naming context. + CosNaming::NamingContext_var synch_context_; + TAO_Naming_Client naming_client_; + + Synchs synchs_; +}; + +#endif /*STARTER_H*/ diff --git a/TAO/examples/RTScheduling/Synch.idl b/TAO/examples/RTScheduling/Synch.idl new file mode 100644 index 00000000000..45ccc7b49c2 --- /dev/null +++ b/TAO/examples/RTScheduling/Synch.idl @@ -0,0 +1,6 @@ +//$Id$ + +interface Synch +{ + oneway void go (in long base_time); +}; diff --git a/TAO/examples/RTScheduling/Synch_i.h b/TAO/examples/RTScheduling/Synch_i.h new file mode 100644 index 00000000000..56657d1ee23 --- /dev/null +++ b/TAO/examples/RTScheduling/Synch_i.h @@ -0,0 +1,25 @@ +//$Id$ + +#ifndef SYNCH_I_H +#define SYNCH_I_H + +#include "SynchS.h" + +class Synch_i : public POA_Synch +{ + public: + + Synch_i (void); + virtual void go (CORBA::Long base_time) + ACE_THROW_SPEC ((CORBA::SystemException)); + + int synched (void); + + ACE_Time_Value* base_time (void); + + private: + int synched_; + ACE_Time_Value base_time_; +}; + +#endif /*SYNCH_I_H*/ -- cgit v1.2.1