diff options
author | Johnny Willemsen <jwillemsen@remedy.nl> | 2005-05-23 05:39:21 +0000 |
---|---|---|
committer | Johnny Willemsen <jwillemsen@remedy.nl> | 2005-05-23 05:39:21 +0000 |
commit | 34f3b40f962785c23631940c50ac8a23324b625c (patch) | |
tree | 7f35402a3a6b95126180ea09e145c012aa0fce1e | |
parent | 61fc6783c0e8ca19dbb50cfb42e4d512e4e5a991 (diff) | |
download | ATCD-34f3b40f962785c23631940c50ac8a23324b625c.tar.gz |
ChangeLogTag: Mon May 23 05:35:12 UTC 2005 Johnny Willemsen <jwillemsen@remedy.nl>
36 files changed, 6 insertions, 10360 deletions
diff --git a/TAO/ChangeLog b/TAO/ChangeLog index 9390477a70d..91c9c4a2c4f 100644 --- a/TAO/ChangeLog +++ b/TAO/ChangeLog @@ -1,3 +1,8 @@ +Mon May 23 05:35:12 UTC 2005 Johnny Willemsen <jwillemsen@remedy.nl> + + * orbsvcs/Event_Service/Event_Service.{h,cpp}: + Removed module_factory_, it was for the old ec + Mon May 23 05:31:12 UTC 2005 Johnny Willemsen <jwillemsen@remedy.nl> * examples/Simulator/Event_Supplier/DualEC_Sup.cpp: diff --git a/TAO/orbsvcs/orbsvcs/Event/BCU.cpp b/TAO/orbsvcs/orbsvcs/Event/BCU.cpp deleted file mode 100644 index 45d121f8b60..00000000000 --- a/TAO/orbsvcs/orbsvcs/Event/BCU.cpp +++ /dev/null @@ -1,32 +0,0 @@ -// $Id$ - -#include "ace/ACE.h" -#include "BCU.h" - -ACE_RCSID(Event, BCU, "$Id$") - -u_long -ACE_BCU (u_long n) -{ - const u_long ACE_BCU_PRIME_NUMBER = 9619; - - u_long retval = 0; - - while (n-- > 0) - retval = ACE::is_prime (ACE_BCU_PRIME_NUMBER, 2, ACE_BCU_PRIME_NUMBER / 2); - - return retval; -} - - -u_long -ACE_BCU (u_long number, - u_long n) -{ - u_long retval = 0; - - while (n-- > 0) - retval = ACE::is_prime (number, 2, number); - - return retval; -} diff --git a/TAO/orbsvcs/orbsvcs/Event/BCU.h b/TAO/orbsvcs/orbsvcs/Event/BCU.h deleted file mode 100644 index 45c8018f91b..00000000000 --- a/TAO/orbsvcs/orbsvcs/Event/BCU.h +++ /dev/null @@ -1,38 +0,0 @@ -/* -*- C++ -*- */ -//============================================================================= -/** - * @file BCU.h - * - * $Id$ - * - * @author David Levine and Tim Harrison (harrison@cs.wustl.edu) - * - * - * Times how long it takes to generate each of the first N prime - * numbers. - * - */ -//============================================================================= - - -#ifndef ACE_BCU_H -#define ACE_BCU_H -#include /**/ "ace/pre.h" - -#include "ace/os_include/os_stdint.h" - -#if !defined (ACE_LACKS_PRAGMA_ONCE) -# pragma once -#endif /* ACE_LACKS_PRAGMA_ONCE */ - -#include "old_event_export.h" - -// Check if a specific, hardcoded number is prime (via ACE::is_prime) <n> -// times. -TAO_RTOLDEvent_Export u_long ACE_BCU (u_long n); - -// Check if <number> is prime (via ACE::is_prime ()) <n> times. -TAO_RTOLDEvent_Export u_long ACE_BCU (u_long number, u_long n); - -#include /**/ "ace/post.h" -#endif /* ACE_BCU_H */ diff --git a/TAO/orbsvcs/orbsvcs/Event/Debug_Macros.h b/TAO/orbsvcs/orbsvcs/Event/Debug_Macros.h deleted file mode 100644 index 3b370380020..00000000000 --- a/TAO/orbsvcs/orbsvcs/Event/Debug_Macros.h +++ /dev/null @@ -1,19 +0,0 @@ -// $Id$ - -#ifndef DEBUG_MACROS_H -#define DEBUG_MACROS_H -#include /**/ "ace/pre.h" - -#if defined (ACE_ES_NOLOGGING) -#define ACE_ES_DEBUG(X) -#define ACE_ES_DEBUG_ST(X) -#else -#define ACE_ES_DEBUG(X) \ - do { \ - ACE_Log_Msg::instance ()->log X; \ - } while (0) -#define ACE_ES_DEBUG_ST(X) X -#endif /* ACE_ES_NOLOGGING */ - -#include /**/ "ace/post.h" -#endif // DEBUG_MACROS_H diff --git a/TAO/orbsvcs/orbsvcs/Event/Dispatching_Modules.cpp b/TAO/orbsvcs/orbsvcs/Event/Dispatching_Modules.cpp deleted file mode 100644 index 2ef2c864f4d..00000000000 --- a/TAO/orbsvcs/orbsvcs/Event/Dispatching_Modules.cpp +++ /dev/null @@ -1,779 +0,0 @@ -// $Id$ - -#include "ace/Sched_Params.h" -#include "orbsvcs/Scheduler_Factory.h" -#include "orbsvcs/Time_Utilities.h" -#include "Memory_Pools.h" - -#include "Dispatching_Modules.h" - -#if !defined (__ACE_INLINE__) -#include "Dispatching_Modules.i" -#endif /* __ACE_INLINE__ */ - -#include "tao/Timeprobe.h" - -ACE_RCSID (Event, - Dispatching_Modules, - "$Id$") - -#if defined (ACE_ENABLE_TIMEPROBES) - -static const char *TAO_Dispatching_Modules_Timeprobe_Description[] = -{ - "dispatch (dequeue) the event", - "push_source_type: Correlation Module", - "Priority_Dispatching::push - priority requested", - "Priority_Dispatching::push - priority obtained" -}; - -enum -{ - // Timeprobe description table start key - TAO_DISPATCHING_MODULES_DISPATCH_THE_EVENT = 5000, - TAO_DISPATCHING_MODULES_PUSH_SOURCE_TYPE_CORRELATION_MODULE, - TAO_DISPATCHING_MODULES_PRIORITY_DISPATCHING_PUSH_PRIORITY_REQUESTED, - TAO_DISPATCHING_MODULES_PRIORITY_DISPATCHING_PUSH_PRIORITY_OBTAINED -}; - -// Setup Timeprobes -ACE_TIMEPROBE_EVENT_DESCRIPTIONS (TAO_Dispatching_Modules_Timeprobe_Description, - TAO_DISPATCHING_MODULES_DISPATCH_THE_EVENT); - -#endif /* ACE_ENABLE_TIMEPROBES */ - -// ************************************************************ - -ACE_ES_Dispatch_Request:: -ACE_ES_Dispatch_Request (ACE_Push_Consumer_Proxy *consumer, - const TAO_EC_Event &event, - RtecScheduler::handle_t rt_info) - : priority_ (0), - rt_info_ (rt_info), - dispatching_module_ (0), - use_single_event_ (0), - consumer_ (consumer), - event_set_ (1) -{ - this->event_set_.set (event, 0); -} - -void -ACE_ES_Dispatch_Request::make_copy (RtecEventComm::EventSet &dest) const -{ - if (use_single_event_) - { - // The RtecEventComm::EventSet will hold a pointer to the - // buffer, without owning it, thus it is not removed! - // @@ TODO Check what happens in the collocated case. - dest.replace (1, 1, - const_cast<RtecEventComm::Event*> (&this->single_event_.event ()), - 0); - } - else if (this->event_set_.size () == 1) - { - dest.replace (1, 1, - const_cast<RtecEventComm::Event*> (&this->event_set_[0].event ()), - 0); - } - else - { - dest.length (static_cast<CORBA::ULong> (this->event_set_.size ())); - - int c = 0; - for (CORBA::ULong i = 0; i < this->event_set_.size (); ++i) - { - if (this->event_set_[i].empty ()) - continue; - dest[c] = this->event_set_[i].event (); - c++; - } - dest.length (c); - } -} - -void -ACE_ES_Dispatch_Request::append_event (const TAO_EC_Event& event) -{ - size_t size = this->event_set_.size (); - if (this->event_set_.size (size + 1) == 0) - this->event_set_.set (event, size); -} - -int -ACE_ES_Dispatch_Request::execute (u_long &command_action) -{ - ACE_TIMEPROBE (TAO_DISPATCHING_MODULES_DISPATCH_THE_EVENT); - - return dispatching_module_->dispatch_event (this, command_action); -} - -#if 0 -// @@ Memory pools -void * -ACE_ES_Dispatch_Request::operator new (size_t nbytes) -{ - if (nbytes > sizeof (ACE_ES_Dispatch_Request)) - { - ACE_ERROR ((LM_ERROR, "nbytes = %d, sizeof (ACE_ES_Dispatch_Request_Chunk) = %d.\n", - sizeof (ACE_ES_Dispatch_Request))); - ACE_ASSERT (nbytes <= sizeof (ACE_ES_Dispatch_Request)); - } - - return ACE_ES_Memory_Pools::new_Dispatch_Request (); -} - -void -ACE_ES_Dispatch_Request::operator delete (void *mem) -{ - ACE_ES_Memory_Pools::delete_Dispatch_Request (mem); -} -#endif /* 0 */ - -// ************************************************************ - -void -ACE_ES_Dispatching_Base::activate (int) -{ -} - -void -ACE_ES_Dispatching_Base::shutdown (void) -{ - ACE_DEBUG ((LM_DEBUG, - "EC (%t) ACE_ES_Dispatching_Base module shutting down.\n")); -} - -// Just forward the request. This is basically a hook for the RTU -// stuff. -int -ACE_ES_Dispatching_Base::dispatch_event (ACE_ES_Dispatch_Request *request, - u_long &command_action) -{ - ACE_DECLARE_NEW_CORBA_ENV; - ACE_TRY - { - // Forward the request. - up_->push (request ACE_ENV_ARG_PARAMETER); - ACE_TRY_CHECK; - } - ACE_CATCHANY - { - // No exceptions should be raised (push is a oneway) but we try - // to print something useful anyway. - ACE_PRINT_EXCEPTION (ACE_ANY_EXCEPTION, - "ACE_ES_Dispatching_Base::dispatch_event"); - } - ACE_ENDTRY; - - // Tell our caller to release the request. - command_action = ACE_RT_Task_Command::RELEASE; - - // Return zero so our calling thread does not exit. - return 0; -} - -// ************************************************************ - -ACE_ES_Priority_Dispatching::ACE_ES_Priority_Dispatching (ACE_EventChannel *channel) - : ACE_ES_Dispatching_Base (channel), - notification_strategy_ (this, channel->timer_module ()), - highest_priority_ (0), - shutdown_ (0), - threads_per_queue_ (0) -{ - // If we're single threaded, then we need to use the notification strategy. - if ((threads_per_queue_ == 0) && - (notification_strategy_.open () == -1)) - ACE_ERROR ((LM_ERROR, "%p.\n", "ACE_ES_Priority_Dispatching")); - - // Initialize the queues. - for (int x = 0; x < ACE_Scheduler_MAX_PRIORITIES; x++) - { - this->queues_[x] = 0; - } - - this->scheduler_ = - this->channel_->scheduler (); -} - -ACE_ES_Priority_Dispatching::~ACE_ES_Priority_Dispatching (void) -{ -} - - -void -ACE_ES_Priority_Dispatching::initialize_queues (void) -{ - for (int x = 0; x < ACE_Scheduler_MAX_PRIORITIES; x++) - { - if (this->queues_[x] != 0) - continue; - - // Convert ACE_Scheduler_Rate (it's really a period, not a rate!) - // to a form we can easily work with. - ACE_Time_Value period_tv; - ORBSVCS_Time::TimeT_to_Time_Value (period_tv, ACE_Scheduler_Rates[x]); - - RtecScheduler::Period_t period = period_tv.sec () * 10000000 + - period_tv.usec () * 10; - - ACE_NEW (this->queues_[x], - ACE_ES_Dispatch_Queue (this, - &this->notification_strategy_, - this->scheduler_.in ())); - this->queues_[x]->thr_mgr (&this->thr_mgr_); - - if ( this->queues_[x]->open_queue (period, - threads_per_queue_) == -1) - { - ACE_ERROR ((LM_ERROR, "%p.\n", - "ACE_ES_Priority_Dispatching::initialize_queues")); - return; - } - - this->queue_count_[x] = 1; - } - highest_priority_ = ACE_Scheduler_MAX_PRIORITIES - 1; -} - -void -ACE_ES_Priority_Dispatching::connected (ACE_Push_Consumer_Proxy *consumer - ACE_ENV_ARG_DECL) -{ - down_->connected (consumer ACE_ENV_ARG_PARAMETER); - ACE_CHECK; - - // This code does dynamic allocation of channel dispatch threads. - // It requires that consumer's priorities are known at connection - // time and that threads can request priorities from the scheduler - // at run-time. These are both antithetical to static scheduling. - // The constructor now allocates a thread per rate group. -#if 0 - // We have to tell the lower portions of the channel about the - // consumer first. This is so that any changes to the consumer's - // qos will take effect when we get the dispatch priority. - down_->connected (consumer ACE_ENV_ARG_PARAMETER); - ACE_CHECK; - - RtecScheduler::OS_Priority priority = - ACE_Scheduler::instance ().preemption_priority (consumer->qos ().rt_info_); - - { - ACE_ES_GUARD ace_mon (lock_); - - // If a queue has not been created for the consumer's priority, - // create one. - if (queues_[priority] == 0) - { - // Allocate a new dispatch queue. - queues_[priority] = new ACE_ES_Dispatch_Queue (this, ¬ification_strategy_); - if (queues_[priority] == 0) - TAO_THROW (CORBA::NO_MEMORY (0, , - "ACE_ES_Priority_Dispatching::connected")); - - // Initialize the dispatch queue corresponding to the - // consumer's priority. With a full implementation of the - // run-time scheduler, the dispatch queue can find it's - // scheduling qos online. However, we pass the rate in case - // one is not found. The rate can be used to obtain the - // proper priority. If threads_per_queue_ == 0, then these - // queues will be passive. Otherwise, they will be active. - // This switches us between MT_ORB and ST_ORB. If we're - // single-threaded, this registers us with the ReactorEx using - // our notification_strategy_. If we're multi-threaded, this - // spawns the threads. - if (queues_[priority]->open_queue (priority, - threads_per_queue_) == -1) - TAO_THROW (DISPATCH_ERROR (0, , - "ACE_ES_Priority_Dispatching::connected:" - "queue open failed.\n")); - - // When this goes down to 0, we will shutdown the queue. - queue_count_[priority] = 1; - - // Keep track of this to optimize handle_signal. - if (priority > highest_priority_) - highest_priority_ = priority; - - ACE_DEBUG ((LM_DEBUG, - "EC (%t) Created queue priority = %d.\n", priority)); - } - else - queue_count_[priority]++; - } -#endif -} - -void -ACE_ES_Priority_Dispatching::disconnected (ACE_Push_Consumer_Proxy *consumer) -{ - // We'll not dynamically close down queues. - ACE_UNUSED_ARG (consumer); - -#if 0 - RtecScheduler::OS_Priority priority = - ACE_Scheduler::instance ().preemption_priority (consumer->qos ().rt_info_); - - { - ACE_ES_GUARD ace_mon (lock_); - - // If there are no more users of this queue, then we *could* shut - // it down. However, we will not. - if (--queue_count_[priority] <= 0) - { - ACE_DEBUG ((LM_DEBUG, "EC (%t) unused dispatch queue priority = %d, " - "is_empty = %d.\n", - priority, queues_[priority]->msg_queue ()->is_empty ())); - - queues_[priority]->shutdown_task (); - } - } -#endif -} - -// @@ This method could have a bypass optimization. -// <request> has been dynamically allocated by the filtering module. -void -ACE_ES_Priority_Dispatching::push (ACE_ES_Dispatch_Request *request - ACE_ENV_ARG_DECL) -{ - ACE_TIMEPROBE (TAO_DISPATCHING_MODULES_PUSH_SOURCE_TYPE_CORRELATION_MODULE); - - RtecScheduler::OS_Priority thread_priority; - RtecScheduler::Preemption_Subpriority_t subpriority; - RtecScheduler::Preemption_Priority_t preemption_priority; - - if (request->rt_info () != 0) - { - ACE_TIMEPROBE (TAO_DISPATCHING_MODULES_PRIORITY_DISPATCHING_PUSH_PRIORITY_REQUESTED); -#if 1 - this->scheduler_->priority - (request->rt_info (), - thread_priority, - subpriority, - preemption_priority - ACE_ENV_ARG_PARAMETER); -#else - ACE_Scheduler_Factory::server ()->priority - (request->rt_info (), - thread_priority, - subpriority, - preemption_priority - ACE_ENV_ARG_PARAMETER); -#endif - ACE_TIMEPROBE (TAO_DISPATCHING_MODULES_PRIORITY_DISPATCHING_PUSH_PRIORITY_OBTAINED); - ACE_CHECK; - } - else - { - thread_priority = - ACE_Sched_Params::priority_min (ACE_SCHED_FIFO, - ACE_SCOPE_PROCESS); - subpriority = ACE_Scheduler_MIN_SUB_PRIORITY; - preemption_priority = ACE_Scheduler_MIN_PREEMPTION_PRIORITY; - } - - // If it's a request to forward an event, it needs a reference to us - // to call dispatch_event. - request->set (this, preemption_priority, subpriority); - - // Make sure that a queue exists for this priority. - if (queues_[preemption_priority] == 0) - { - ACE_ERROR ((LM_ERROR, "EC (%t): Push to closed queue %d," - " dropping event.\n", preemption_priority)); - return; -#if 0 - ACE_THROW (SYNC_ERROR (0, , "ACE_ES_Priority_Dispatching::push")); -#endif /* 0 */ - } - - // Enqueue the request. If we're multi-threaded, this request is a - // command object that will be called by the threads in the queue, - // or will be dequeued by this->handle_signal if we're - // single-threaded. - if (queues_[preemption_priority]->try_put (request) == -1) - { - if (ACE_ES_Dispatch_Request::release (request) != 0) - ACE_ERROR ((LM_ERROR, "ACE_ES_Priority_Dispatching::push" - " release failed.\n")); - if (errno != EPIPE) - { - ACE_THROW (CORBA::NO_MEMORY ()); - } - else - { - ACE_DEBUG ((LM_DEBUG, - "EC (%t) Request rejected from closed queue %d.\n", - preemption_priority)); - } - } -} - -// Start at highest priority queue checking for queued events -// continuing to lowest priority queue. If an event is ever found, -// dispatch it and then start back at the highest priority queue -// again. -int -ACE_ES_Priority_Dispatching::handle_signal (int, siginfo_t *, ucontext_t *) -{ - int done; - - do - { - done = 1; - for (int x = 0; x <= highest_priority_; x++) - { - // If the queue is not empty, dispatch the request and then - // start the for loop from the beginning. - if ((queues_[x] != 0) && (!queues_[x]->msg_queue ()->is_empty ())) - { - // Dequeue and service the request. - queues_[x]->svc_one (); - - // Exit the for loop and start over. - done = 0; - break; - } - - // If we get through the whole for loop without dispatching - // anything, then we're done. - } - } - while (!done); - - - return 0; -} - -// This is only for the non-win32 single-threaded implementation. -int -ACE_ES_Priority_Dispatching::handle_input (ACE_HANDLE) -{ - return this->handle_signal (0, 0, 0); -} - -void -ACE_ES_Priority_Dispatching::activate (int threads_per_queue) -{ - this->threads_per_queue_ = threads_per_queue; - this->initialize_queues (); -} - -// Shutdown each queue. When each queue exits, they will call back -// this->dispatch_queue_closed which allows us to free up resources. -// When the last queue has closed, we'll delete ourselves. -void -ACE_ES_Priority_Dispatching::shutdown (void) -{ - if (shutdown_) - return; - - ACE_DEBUG ((LM_DEBUG, "EC (%t) ACE_ES_Priority_Dispatching " - "module shutting down.\n")); - - shutdown_ = 1; - - // If we're single threaded, then we need to shut down the - // notification strategy so it can remove itself from the reactor. - if (threads_per_queue_ == 0) - notification_strategy_.shutdown (); - - // Whether these are active or not, they must be shut down. - for (int x = 0; x <= highest_priority_; x++) - if (queues_[x] != 0) - { - ACE_DEBUG ((LM_DEBUG, - "EC (%t) shutting down dispatch queue %d.\n", x)); - queues_[x]->shutdown_task (); - } - - if (this->thr_mgr_.wait () == -1) - ACE_ERROR ((LM_ERROR, "%p\n", - "Priority_Dispatching::shutdown - waiting")); - - for (int i = 0; i <= this->highest_priority_; ++i) - { - if (this->queues_[i] != 0) - { - delete this->queues_[i]; - this->queues_[i] = 0; - } - } -} - -// This gets called every time a Dispatch Queue closes down. We -// search for <queue> and delete it. If we have been told to delete -// ourself, after the last queue has been deleted, we delete -// ourselves. -void -ACE_ES_Priority_Dispatching::dispatch_queue_closed (ACE_ES_Dispatch_Queue *queue) -{ - ACE_UNUSED_ARG (queue); -} - -/* -ACE_HANDLE -ACE_ES_Priority_Dispatching::get_handle (void) const -{ - ACE_ES_Priority_Dispatching *fake_this = (ACE_ES_Priority_Dispatching *) this; - return fake_this->notification_strategy_.get_handle (); -} -*/ - -// ************************************************************ - -ACE_ES_Dispatch_Queue:: - ACE_ES_Dispatch_Queue (ACE_ES_Dispatching_Base *dispatching_module, - ACE_ES_Notification_Strategy *notification_strategy, - RtecScheduler::Scheduler_ptr scheduler) - : ACE_RT_Task (scheduler), - dispatching_module_ (dispatching_module), - notification_strategy_ (notification_strategy) -{ -} - -int -ACE_ES_Dispatch_Queue::open_queue (RtecScheduler::Period_t &period, - int threads) -{ - // First set up the correct message queue according to whether the - // dispatch queue will be active or not. - - // If there are no threads specified, we'll register with the - // reactor to be called back when someone queues a message. - if (threads == 0) - { - // Allocate a message queue that notifies a reactor when events - // arrive via the msg_queue call. If that succeeds, set the - // notification strategy in our message queue via the open call. - if (this->msg_queue () == 0 || - this->msg_queue ()->open (ACE_ES_QUEUE::DEFAULT_HWM, - ACE_ES_QUEUE::DEFAULT_LWM, - notification_strategy_) == -1) - ACE_ERROR_RETURN ((LM_ERROR, "%p msg_queue.open failed.\n", - "ACE_ES_Dispatch_Queue::open_queue"), -1); - } - else - { - // quick hack to test dynamic queue performance (to be replaced soon) - ACE_ES_QUEUE *mq = 0; -#if defined (TAO_USES_STRATEGY_SCHEDULER) -#if defined (TAO_USES_EDF_SCHEDULING) - - ACE_Deadline_Message_Strategy *adms = new ACE_Deadline_Message_Strategy; - - if (adms) - { - mq = new ACE_Dynamic_Message_Queue<ACE_SYNCH> (*adms); - } - -#elif defined (TAO_USES_MLF_SCHEDULING) || defined (TAO_USES_MUF_SCHEDULING) - - ACE_Laxity_Message_Strategy *alms = new ACE_Laxity_Message_Strategy; - - if (alms) - { - mq = new ACE_Dynamic_Message_Queue<ACE_SYNCH> (*alms); - } - -#else - mq = new ACE_ES_QUEUE; -#endif -#else - // Allocate a message queue that does not notify. - mq = new ACE_ES_MQ; -#endif - - if (mq == 0) - ACE_ERROR_RETURN ((LM_ERROR, "%p.\n", - "ACE_ES_Dispatch_Queue::open_queue"), -1); - else - { - // This deletes previous message queue. - this->msg_queue (mq); - // Set this so that the destructor of ACE_Task deletes our - // message queue. Note, this must be after the call to - // msg_queue. - delete_msg_queue_ = 1; - } - } - - // Create a name for ourselves using the period. The period is - // in 100 ns units; first convert to usec by dividing by 10. - char temp[64]; - ACE_OS::sprintf (temp, "ACE_ES_Dispatch_Queue-%u.us", period / 10); - - // Open the task. This will query the scheduler for our qos - // structure. It will also synch_threads if it succeeds. - int result = this->open_task (temp); - - switch (result) - { - case -1: - // Error. - ACE_ERROR_RETURN ((LM_ERROR, "%p.\n", - "ACE_ES_Dispatch_Queue::open_queue"), -1); - case 0: - { - ACE_DECLARE_NEW_CORBA_ENV; - ACE_TRY - {// @@ TODO: Handle exceptions... -#if 1 - this->scheduler_->set - (rt_info_, - RtecScheduler::VERY_HIGH_CRITICALITY, - ORBSVCS_Time::zero (), - ORBSVCS_Time::zero (), - ORBSVCS_Time::zero (), - period, - RtecScheduler::VERY_LOW_IMPORTANCE, - ORBSVCS_Time::zero (), - 1, - RtecScheduler::OPERATION - ACE_ENV_ARG_PARAMETER); -#else - ACE_Scheduler_Factory::server()->set (rt_info_, - RtecScheduler::VERY_HIGH_CRITICALITY, - ORBSVCS_Time::zero (), - ORBSVCS_Time::zero (), - ORBSVCS_Time::zero (), - period, - RtecScheduler::VERY_LOW_IMPORTANCE, - ORBSVCS_Time::zero (), - 1, - RtecScheduler::OPERATION - ACE_ENV_ARG_PARAMETER); -#endif - ACE_TRY_CHECK; - } - ACE_CATCHANY - { - ACE_PRINT_EXCEPTION (ACE_ANY_EXCEPTION, - "ACE_ES_Dispatch_Queue::exception"); - return -1; - } - ACE_ENDTRY; - } - // FALLTHROUGH - case 1: - // Found. - break; - } - - // Spawn threads. - return this->synch_threads (threads); -} - -// This is called back by ACE_RT_Task when all the threads have -// exited. We're going to forward this event to the dispatching -// module so it can clean up any resources. -void -ACE_ES_Dispatch_Queue::threads_closed (void) -{ - dispatching_module_->dispatch_queue_closed (this); -} - -// ************************************************************ - -ACE_ES_EFD_Dispatching::ACE_ES_EFD_Dispatching (ACE_EventChannel *channel) - : ACE_ES_Dispatching_Base (channel) -{ -} - -void -ACE_ES_EFD_Dispatching::push (ACE_ES_Dispatch_Request *request - ACE_ENV_ARG_DECL_NOT_USED) -{ - // If it's a request to forward an event, it needs a reference to us - // to call dispatch_event. - request->set (this, 0, ACE_Scheduler_MIN_SUB_PRIORITY); - - u_long command_action = ACE_RT_Task_Command::RELEASE; - - // This may be a request to delete a push consumer proxy, so we - // should execute it instead of just forwarding it. - request->execute (command_action); - - switch (command_action) - { - case ACE_RT_Task_Command::RELEASE: - // Free the request. - if (ACE_ES_Dispatch_Request::release (request) != 0) - ACE_ERROR ((LM_ERROR, "ACE_ES_EFD_Dispatching::push" - " release failed.\n")); - break; - - default: - ACE_ERROR ((LM_ERROR, "ACE_ES_EFD_Dispatching::push: unknown command action.\n")); - } -} - -// ************************************************************ - -ACE_ES_RTU_Dispatching::ACE_ES_RTU_Dispatching (ACE_EventChannel *channel) - : ACE_ES_Priority_Dispatching (channel) -{ -} - -// We're called from a dispatch queue, so we can not release the request. -int -ACE_ES_RTU_Dispatching::dispatch_event (ACE_ES_Dispatch_Request *request, - u_long &command_action) -{ - // Store the priority of the task currently running. - channel_->rtu_manager ()->priority (request->priority ()); - - ACE_DECLARE_NEW_CORBA_ENV; - ACE_TRY - { - // Forward the request. - up_->push (request ACE_ENV_ARG_PARAMETER); - ACE_TRY_CHECK; - } - ACE_CATCHANY - { - // No exceptions should be raised (push is a oneway) but we try - // to print something useful anyway. - ACE_PRINT_EXCEPTION (ACE_ANY_EXCEPTION, - "ACE_ES_Dispatching_Base::dispatch_event"); - } - ACE_ENDTRY; - - // Reset the priority. - channel_->rtu_manager ()->priority (ACE_Sched_Params::priority_min (ACE_SCHED_FIFO, ACE_SCOPE_PROCESS)); - - // If the task was preempted, enqueue the request on the head of the - // dispatch queue. - if (channel_->rtu_manager ()->not_done ()) - command_action = ACE_RT_Task_Command::UNGETQ; - else - // We're done with it. - command_action = ACE_RT_Task_Command::RELEASE; - - return 0; -} - -void -ACE_ES_RTU_Dispatching::push (ACE_ES_Dispatch_Request *request - ACE_ENV_ARG_DECL) -{ - // First enqueue the message in the proper queue. - ACE_ES_Priority_Dispatching::push (request ACE_ENV_ARG_PARAMETER); - ACE_CHECK; - - // If the current event is higher priority (lower value) than the - // current running task, then tell the task to preempt itself. - int request_priority = request->priority (); - int running_priority = channel_->rtu_manager ()->priority (); - if (request_priority < running_priority) - channel_->rtu_manager ()->should_preempt (1); - return; -} - -#if defined (ACE_HAS_EXPLICIT_TEMPLATE_INSTANTIATION) - -#elif defined(ACE_HAS_TEMPLATE_INSTANTIATION_PRAGMA) - -#endif /* ACE_HAS_EXPLICIT_TEMPLATE_INSTANTIATION */ diff --git a/TAO/orbsvcs/orbsvcs/Event/Dispatching_Modules.h b/TAO/orbsvcs/orbsvcs/Event/Dispatching_Modules.h deleted file mode 100644 index 03869de539b..00000000000 --- a/TAO/orbsvcs/orbsvcs/Event/Dispatching_Modules.h +++ /dev/null @@ -1,538 +0,0 @@ -/* -*- C++ -*- */ -//============================================================================= -/** - * @file Dispatching_Modules.h - * - * $Id$ - * - * @author Tim Harrison (harrison@cs.wustl.edu) - * - * This file holds the different Event Service dispatching - * mechanisms. These include null-dispatching (EFD), - * single-threaded with (RTU) and without preemption (LAME), and a - * multithreaded implementation. - * - * - */ -//============================================================================= - - -#ifndef ACE_DISPATCHING_MODULES_H -#define ACE_DISPATCHING_MODULES_H -#include /**/ "ace/pre.h" - -#include "ace/Reactor_Notification_Strategy.h" -#include "tao/Timeprobe.h" -#include "orbsvcs/Event/ReactorTask.h" -#include "orbsvcs/Event/Event_Manip.h" -#include "orbsvcs/Event/Event_Channel.h" - -// ************************************************************ - -// Forward declarations. -class ACE_ES_Dispatch_Queue; -class ACE_ES_Dispatch_Request; - -// ************************************************************ - -// Forward declarations. -class ACE_ES_Consumer_Module; - -/** - * @class ACE_ES_Dispatching_Base - * - * @brief Event Service Dispatch Module base class - * - * We inherit from ACE_Event_Handler so that we can be called back - * by the ReactorEx when requests are queued. The virtual - * dispatch_event method allows ACE_ES_Dispatch_Requests to call - * back the dispatching module when acting as command objects. When - * this implementation is used by the Event Channel it forwards all - * dispatch calls without any queuing. Therefore, it can be - * used to build an EFD. It is also inherited by the Priority - * Dispatching module. - */ -class TAO_RTOLDEvent_Export ACE_ES_Dispatching_Base : public ACE_Event_Handler -{ -public: - /// Default construction. - ACE_ES_Dispatching_Base (ACE_EventChannel *channel); - - /// Link to adjacent modules. - virtual void open (ACE_ES_Consumer_Module *up, - ACE_ES_Correlation_Module *down); - - /// Forward down_. - virtual void connected (ACE_Push_Consumer_Proxy *consumer - ACE_ENV_ARG_DECL_NOT_USED); - - /// Forward down_. - virtual void disconnecting (ACE_Push_Consumer_Proxy *consumer - ACE_ENV_ARG_DECL_NOT_USED); - - /// Release any unneeded dispatching resources. - virtual void disconnected (ACE_Push_Consumer_Proxy *consumer); - - // = Not needed. - // void connected (ACE_Push_Supplier_Proxy *supplier); - // void disconnecting (ACE_Push_Supplier_Proxy *supplier); - - /// Forward up_. - virtual void push (ACE_ES_Dispatch_Request *request - ACE_ENV_ARG_DECL_NOT_USED) = 0; - - /// Called by ACE_ES_Dispatch_Requests when dequeued by RT_Tasks. - virtual int dispatch_event (ACE_ES_Dispatch_Request *request, - u_long &command_action); - - /// Called when all the threads of a <q> have exited. - virtual void dispatch_queue_closed (ACE_ES_Dispatch_Queue *q); - - /// This is called by the Event Channel. It will create all the - /// threads and only return once they are all up and running. - virtual void activate (int threads_per_queue); - - /// This is called by the Event Channel. This will attempt to shut - /// down all of its threads gracefully. Wish it luck. - virtual void shutdown (void); - -protected: - /// Dat der channel. - ACE_EventChannel *channel_; - - /// To synchronize thr_count_. - ACE_ES_MUTEX lock_; - - /// The total number of threads in the Dispatching Module. This will - /// be the sum of all the Dispatch Queue threads. - int thr_count_; - - /// Next module up. - ACE_ES_Consumer_Module *up_; - - /// Next module down. - ACE_ES_Correlation_Module *down_; -}; - -// ************************************************************ - -/** - * @class ACE_ES_Dispatch_Request - * - * @brief ACE Event Service Dispatch Request - * - * Encapsulates a consumer and the events that will be sent to the - * consumer. Right now, this class keeps a single_event_ that can - * be used when only one event is sent to the consumer. Since this - * is frequently the case (except for correlations), this - * optimization reduces the amount of dynamic memory allocation is - * necessary. This class is also a GOF Command object since it can - * be dequeued by an RT_Task to call back the dispatching module - * for request dispatching. - */ -class TAO_RTOLDEvent_Export ACE_ES_Dispatch_Request : public ACE_RT_Task_Command -{ -public: - /// Default construction. - ACE_ES_Dispatch_Request (void); - - /// Default destruction. - virtual ~ACE_ES_Dispatch_Request (void); - - /// All the events must be added after construction to the - /// event_set. - ACE_ES_Dispatch_Request (ACE_Push_Consumer_Proxy *consumer, - RtecScheduler::handle_t rt_info); - - /// Set consumer_ to <consumer> and copy <event_set> to event_set_. - /// <rt_info> describes the method receiving this dispatch. - ACE_ES_Dispatch_Request (ACE_Push_Consumer_Proxy *consumer, - const TAO_EC_Event_Array &event_set, - RtecScheduler::handle_t rt_info); - - /** - * Set consumer_ to <consumer> and sets - * single_event_.header.creation_time to <time>. Sets - * use_single_event_ to 1. <rt_info> describes the method - * receiving this dispatch. - */ - ACE_ES_Dispatch_Request (ACE_Push_Consumer_Proxy *consumer, - const RtecEventComm::Time &time, - RtecScheduler::handle_t rt_info); - - /** - * Sets consumer_ and the first slot of event_set_. We use the - * event_set_ instead of the single_event_ so that we can just carry - * around the pointer to <event>. <rt_info> describes the method - * receiving this dispatch. - */ - ACE_ES_Dispatch_Request (ACE_Push_Consumer_Proxy *consumer, - const TAO_EC_Event &event, - RtecScheduler::handle_t rt_info); - - /// Description of the method receiving this request. - RtecScheduler::handle_t rt_info (void); - - /** - * For multi-threaded implementations, <dispatching_module> is - * called back when a request is dequeued. <priority> is the - * dispatch priority of the event. <sub_priority> is the enqueue - * priority of the event and will be forwarded to - * ACE_Message_Block. - */ - void set (ACE_ES_Dispatching_Base *dispatching_module, - RtecScheduler::OS_Priority priority, - RtecScheduler::Preemption_Subpriority_t sub_priority); - - /// Consumer accessor. - ACE_Push_Consumer_Proxy *consumer (void) const; - - /// If accessed, make_copy will use event_set_. - const TAO_EC_Event_Array &event_set (void) const; - - /// If accessed, make_copy will use event_set_. - TAO_EC_Event_Array &event_set (void); - - /// Append an event to the list of events in the Request. - void append_event (const TAO_EC_Event& event); - - /// Returns 1 if we're using single_event, or event_set_.size (). - CORBA::ULong number_of_events (void) const; - - /// Copy single_event or event_set into <dest>. - /// @@ Change the name to something more meaningful... - void make_copy (RtecEventComm::EventSet &dest) const; - - /// Calls dispatching_module_->dispatch_event. - virtual int execute (u_long &command_action); - - /// Priority accessor. - RtecScheduler::OS_Priority priority (void); - -#if 0 - // @@ Memory pools - // @@ This cannot be done: the object would be allocated using this - // class operator new, but it will be removed using the - // ACE_Message_Block operator delete! - /// Allocates memory from a thread-specific memory pool. - void *operator new (size_t nbytes); - - /// Returns memory to a thread-specific memory pool. - void operator delete (void *); -#endif - -protected: - RtecScheduler::OS_Priority priority_; - - /// Describes the method receiving this dispatch. - RtecScheduler::handle_t rt_info_; - - /// The dispatching module called back when we're dequeued by a - /// thread. - ACE_ES_Dispatching_Base *dispatching_module_; - - /// Is true if we're using a single event. Is 0 is we're using - /// event_set_. - int use_single_event_; - - /// The final destination for single_event_ or event_set_. - ACE_Push_Consumer_Proxy *consumer_; - - /// This is used for single event dispatches. - TAO_EC_Event single_event_; - - /// This is used for event sets that need to be dispatched. - TAO_EC_Event_Array event_set_; -}; - -// ************************************************************ - -#if defined (ACE_WIN32) -/** - * @class ACE_ES_ReactorEx_NS - * - * @brief Event Service ReactorEx Notification Strategy - * - * Integrates the ACE_Message_Queue notification to signal a - * handle that will wake up the ACE_ES_Priority_Dispatching - * module. This is used in place of the - * ACE_ReactorEx_Notification_Strategy to avoid any queueing by - * the ReactorEx::notify mechanism. - */ -class TAO_RTOLDEvent_Export ACE_ES_ReactorEx_NS : public ACE_Notification_Strategy -{ -public: - /// Stores away <eh> for when this->open is called. - ACE_ES_ReactorEx_NS (ACE_Event_Handler *eh, - TAO_EC_Timer_Module *tm); - - /// Registers eh_ with the ReactorEx to be notified when this->notify - /// is called. - int open (void); - - /// Removes self from the reactor. - void shutdown (void); - - // = These result in eh_->handle_signal getting called. eh_ should - // point to a dispatching module. - virtual int notify (void); - virtual int notify (ACE_Event_Handler *, - ACE_Reactor_Mask mask); - - // ACE_HANDLE get_handle (void); - // Returns event_.handle (). - -private: - /// Registered with the ReactorEx. - ACE_Auto_Event event_; - - /// To schedule timers. - TAO_EC_Timer_Module *timer_module_; -}; - -typedef ACE_ES_ReactorEx_NS ACE_ES_Notification_Strategy; - -#else // ******************************************************* - -/** - * @class ACE_ES_Reactor_NS - * - * @brief Event Service Reactor Notification Strategy - * - * Maps to the ACE_Reactor_Notification_Strategy interface. This - * version is for non WIN32 platforms. - */ -class TAO_RTOLDEvent_Export ACE_ES_Reactor_NS : public ACE_Reactor_Notification_Strategy -{ -public: - /// Calls ACE_Reactor_Notification_Strategy with the ORB's reactor - /// and signal mask. - ACE_ES_Reactor_NS (ACE_Event_Handler *eh, - TAO_EC_Timer_Module *tm); - - /// Does nothing. - int open (void); - - /// Does nothing. - void shutdown (void); -}; - -typedef ACE_ES_Reactor_NS ACE_ES_Notification_Strategy; - -#endif /* ACE_WIN32 */ - -// ************************************************************ - -/** - * @class ACE_ES_MQ - * - * @brief Event Service Message Queue - */ -class TAO_RTOLDEvent_Export ACE_ES_MQ : public ACE_ES_QUEUE -{ - /// Does nothing. - virtual int notify (void) { return 0;} -}; - -// ************************************************************ - -/** - * @class ACE_ES_Dispatch_Queue - * - * @brief Event Service Dispatch Queue - * - * An encapsulation of a dispatch queue. By inheriting from - * ACE_RT_Task, we can make this zero-threaded or multi-threaded. - */ -class TAO_RTOLDEvent_Export ACE_ES_Dispatch_Queue : public ACE_RT_Task -{ -public: - /// Stores <dispatching_module> for this->threads_closed. Stores - /// away <notification_strategy> for this->synch_threads. - ACE_ES_Dispatch_Queue (ACE_ES_Dispatching_Base *dispatching_module, - ACE_ES_Notification_Strategy *notification_strategy, - RtecScheduler::Scheduler_ptr scheduler); - - /// This is a hack to get the channel to work with the new - /// scheduler. - int open_queue (RtecScheduler::Period_t &period, - int threads); - -#if 0 - /** - * Creates a name from the <priority> and tries to find a scheduling - * qos structure. If one is not found, but created, qos_ is set - * with default values. Either way, if qos_->thread_ > 0, it calls - * this->synch_threads. Otherwise, our message queue will use - * notification_strategy_. This will cause the ReactorEx to call - * back the dispatching_module_ when requests are queued on our - * message queue. Returns 0 on success, -1 on failure. - */ - int open_queue (RtecScheduler::OS_Priority priority, - int threads); -#endif - - /// Called when every thread has exited. This will call - /// dispatching_module_->dispatch_queue_closed. - virtual void threads_closed (void); - -private: - /// Used in threads_closed. - ACE_ES_Dispatching_Base *dispatching_module_; - - /// Notifies the Dispatching Module when a request has been queued on - /// our message queue. - ACE_ES_Notification_Strategy *notification_strategy_; -}; - -// ************************************************************ - -/** - * @class ACE_ES_Priority_Dispatching - * - * @brief Event Service Priority Dispatching Module - * - * Inherits from ACE_Event_Handler to utilitize the - * ACE_Message_Queue notification strategy. This implementation - * does priority dispatching without preemption. - */ -class TAO_RTOLDEvent_Export ACE_ES_Priority_Dispatching : public ACE_ES_Dispatching_Base -{ -public: - /// Store <channel>. - ACE_ES_Priority_Dispatching (ACE_EventChannel *channel); - - /// Delete queues. - ~ACE_ES_Priority_Dispatching (void); - - /// Allocate any needed dispatching resources for this consumers - /// priority. - void connected (ACE_Push_Consumer_Proxy *consumer - ACE_ENV_ARG_DECL_NOT_USED); - - /// Release unneeded dispatch queues. - void disconnected (ACE_Push_Consumer_Proxy *consumer); - - // = Not needed. - // void connected (ACE_Push_Supplier_Proxy *supplier); - // void disconnecting (ACE_Push_Supplier_Proxy *supplier); - - /// Enqueues the request on the appropriate Dispatch Queue. - virtual void push (ACE_ES_Dispatch_Request *request - ACE_ENV_ARG_DECL_NOT_USED); - - /** - * Open all queues. - * Spawns <threads_per_queue> thread for each dispatch queue. - * If != 0, then the channel is an MT_CHANNEL. - * If == 0, then the channel is an ST_CHANNEL. - */ - virtual void activate (int threads_per_queue); - - /// Closes all queues "asynchronously." When all queues are closed, - /// deletes them all and then deletes itself. - virtual void shutdown (void); - - /// Called when all the threads of a <q> have exited. Deletes <q>. - virtual void dispatch_queue_closed (ACE_ES_Dispatch_Queue *q); - - // virtual ACE_HANDLE get_handle (void) const; - // Get the I/O handle. - -protected: - /// Called when input has arrived on a message queue. This is used - /// for single-threaded implementations. - virtual int handle_signal (int signum, siginfo_t * = 0, ucontext_t * = 0); - - /** - * For single-threaded implementations on non-win32 platforms that - * use the ACE_Reactor_Notification_Strategy. This just forwards - * all calls to this->handle_signal (). - */ - virtual int handle_input (ACE_HANDLE); - - /// Shared between all dispatch queues. - ACE_ES_Notification_Strategy notification_strategy_; - - /// This is a hack to create a queue for each of the 4 rate groups. - void initialize_queues (void); - - /// Pointers to dispatch queues. - ACE_ES_Dispatch_Queue *queues_[ACE_Scheduler_MAX_PRIORITIES]; - - /// The number of consumers using each queue. - int queue_count_[ACE_Scheduler_MAX_PRIORITIES]; - - /// The highest priority queue in queues_. This allows us to - /// optimize the handle_signal method. - int highest_priority_; - - /// Make sure to only shutdown the dispatching module once. - int shutdown_; - - /// The number of threads to spawn for each dispatch queue. - int threads_per_queue_; - - /// The thread manager for the threads of this object. - ACE_RT_Thread_Manager thr_mgr_; - - /// The scheduler. - RtecScheduler::Scheduler_var scheduler_; -}; - -// ************************************************************ - -/** - * @class ACE_ES_EFD_Dispatching - * - * @brief Event Service EFD Dispatching Module - * - * Implements a zero-threaded dispatcher with no preemption. - */ -class TAO_RTOLDEvent_Export ACE_ES_EFD_Dispatching : public ACE_ES_Dispatching_Base -{ -public: - /// Acquires the proper qos structure and passes <channel> onto to - /// the dispatching base constructor. - ACE_ES_EFD_Dispatching (ACE_EventChannel *channel); - - /// Forward up_. - virtual void push (ACE_ES_Dispatch_Request *request - ACE_ENV_ARG_DECL_NOT_USED); -}; - -// ************************************************************ - -/** - * @class ACE_ES_RTU_Dispatching - * - * @brief Event Service RTU Dispatching Module - * - * Implements a single-threaded dispatcher with delayed preemption. - */ -class TAO_RTOLDEvent_Export ACE_ES_RTU_Dispatching : public ACE_ES_Priority_Dispatching -{ -public: - /// Store <channel>. - ACE_ES_RTU_Dispatching (ACE_EventChannel *channel); - - /** - * Called by ACE_Dispatch_Queues and handle_signal when an event - * needs to be dequeued. Implements an RTU-like delayed preemption - * policy. - */ - virtual int dispatch_event (ACE_ES_Dispatch_Request *request, - u_long &command_action); - - /// Calls ACE_ES_Priority_Dispatching::push and then checks if - /// preemption is necessary. - virtual void push (ACE_ES_Dispatch_Request *request - ACE_ENV_ARG_DECL_NOT_USED); -}; - -#if defined (__ACE_INLINE__) -#include "Dispatching_Modules.i" -#endif /* __ACE_INLINE__ */ - -#include /**/ "ace/post.h" -#endif /* ACE_DISPATCHING_MODULES_H */ diff --git a/TAO/orbsvcs/orbsvcs/Event/Dispatching_Modules.i b/TAO/orbsvcs/orbsvcs/Event/Dispatching_Modules.i deleted file mode 100644 index bc9c5d483b4..00000000000 --- a/TAO/orbsvcs/orbsvcs/Event/Dispatching_Modules.i +++ /dev/null @@ -1,248 +0,0 @@ -/* -*- C++ -*- */ -// $Id$ - -ACE_INLINE -ACE_ES_Dispatch_Request::ACE_ES_Dispatch_Request (void) - : priority_ (0), - rt_info_ (0), - dispatching_module_ (0), - use_single_event_ (0), - consumer_ (0), - event_set_ (1) -{ -} - -ACE_INLINE -ACE_ES_Dispatch_Request::~ACE_ES_Dispatch_Request (void) -{ -} - -ACE_INLINE -ACE_ES_Dispatch_Request:: -ACE_ES_Dispatch_Request (ACE_Push_Consumer_Proxy *consumer, - RtecScheduler::handle_t rt_info) - : priority_ (0), - rt_info_ (rt_info), - dispatching_module_ (0), - use_single_event_ (0), - consumer_ (consumer), - event_set_ (1) -{ -} - -ACE_INLINE -ACE_ES_Dispatch_Request:: -ACE_ES_Dispatch_Request (ACE_Push_Consumer_Proxy *consumer, - const TAO_EC_Event_Array &event_set, - RtecScheduler::handle_t rt_info) - : priority_ (0), - rt_info_ (rt_info), - dispatching_module_ (0), - use_single_event_ (0), - consumer_ (consumer), - single_event_ (), - event_set_ (event_set) -{ -} - -#if 0 -ACE_INLINE -ACE_ES_Dispatch_Request::ACE_ES_Dispatch_Request (ACE_Push_Consumer_Proxy *consumer, - ACE_ES_Event_Container *event, - RtecScheduler::handle_t rt_info) : - priority_ (0), - rt_info_ (rt_info), - dispatching_module_ (0), - use_single_event_ (0), - consumer_ (consumer), - single_event_ (), - event_set_ () -{ - event_set_ += event; -} -#endif - -ACE_INLINE -ACE_ES_Dispatch_Request:: -ACE_ES_Dispatch_Request (ACE_Push_Consumer_Proxy *consumer, - const RtecEventComm::Time &time, - RtecScheduler::handle_t rt_info) - : priority_ (0), - rt_info_ (rt_info), - dispatching_module_ (0), - use_single_event_ (1), - consumer_ (consumer), - event_set_ (1) -{ - // @@ TODO this could be more efficient - RtecEventComm::Event tmp; - tmp.header.creation_time = time; - tmp.header.type = ACE_ES_EVENT_TIMEOUT; - TAO_EC_Event_Set* set = - TAO_EC_Event_Set::_create (tmp); - this->single_event_ = TAO_EC_Event (set, set->length ()); - - TAO_EC_Event_Set::_release (set); -} - -ACE_INLINE void -ACE_ES_Dispatch_Request::set (ACE_ES_Dispatching_Base *dispatching_module, - RtecScheduler::OS_Priority preemption_priority, - RtecScheduler::Preemption_Subpriority_t sub_priority) -{ - dispatching_module_ = dispatching_module; - priority_ = preemption_priority; - ACE_Message_Block::msg_priority (sub_priority); -} - -ACE_INLINE ACE_Push_Consumer_Proxy * -ACE_ES_Dispatch_Request::consumer (void) const -{ - return consumer_; -} - -ACE_INLINE const TAO_EC_Event_Array& -ACE_ES_Dispatch_Request::event_set (void) const -{ - return event_set_; -} - -ACE_INLINE TAO_EC_Event_Array& -ACE_ES_Dispatch_Request::event_set (void) -{ - return event_set_; -} - -ACE_INLINE CORBA::ULong -ACE_ES_Dispatch_Request::number_of_events (void) const -{ - if (this->use_single_event_) - return 1; - else - return static_cast<CORBA::ULong> (this->event_set_.size ()); -} - -ACE_INLINE RtecScheduler::OS_Priority -ACE_ES_Dispatch_Request::priority (void) -{ - return priority_; -} - -ACE_INLINE RtecScheduler::handle_t -ACE_ES_Dispatch_Request::rt_info (void) -{ - return rt_info_; -} - -// ************************************************************ - -ACE_INLINE -ACE_ES_Dispatching_Base::ACE_ES_Dispatching_Base (ACE_EventChannel *channel) - : channel_ (channel), - thr_count_ (0), - up_ (0), - down_ (0) -{ -} - -ACE_INLINE void -ACE_ES_Dispatching_Base::open (ACE_ES_Consumer_Module *up, - ACE_ES_Correlation_Module *down) -{ - up_ = up; - down_ = down; - // 1 == 2. -} - -ACE_INLINE void -ACE_ES_Dispatching_Base::connected (ACE_Push_Consumer_Proxy *consumer - ACE_ENV_ARG_DECL) -{ - down_->connected (consumer ACE_ENV_ARG_PARAMETER); -} - -ACE_INLINE void -ACE_ES_Dispatching_Base::disconnected (ACE_Push_Consumer_Proxy *consumer) -{ - // Do nothing. - ACE_UNUSED_ARG (consumer); -} - -ACE_INLINE void -ACE_ES_Dispatching_Base::disconnecting (ACE_Push_Consumer_Proxy *consumer - ACE_ENV_ARG_DECL) -{ - down_->disconnecting (consumer ACE_ENV_ARG_PARAMETER); -} - -ACE_INLINE void -ACE_ES_Dispatching_Base::dispatch_queue_closed (ACE_ES_Dispatch_Queue *q) -{ - ACE_UNUSED_ARG (q); -} - -// ************************************************************ - -#if defined (ACE_WIN32) -ACE_INLINE -ACE_ES_ReactorEx_NS::ACE_ES_ReactorEx_NS (ACE_Event_Handler *eh, - TAO_EC_Timer_Module* tm) - : ACE_Notification_Strategy (eh, ACE_Event_Handler::NULL_MASK), - timer_module_ (tm) -{ -} - -ACE_INLINE int -ACE_ES_ReactorEx_NS::open (void) -{ - return this->timer_module_->register_handler (0, - eh_, - event_.handle ()); -} - -ACE_INLINE void -ACE_ES_ReactorEx_NS::shutdown (void) -{ -// @@ TODO: Fix this. -// this->timer_module_->remove_handler (0, -// eh_, -// ACE_Event_Handler::DONT_CALL); -} - -ACE_INLINE int -ACE_ES_ReactorEx_NS::notify (void) -{ - return this->event_.signal (); -} - -ACE_INLINE int -ACE_ES_ReactorEx_NS::notify (ACE_Event_Handler *, - ACE_Reactor_Mask) -{ - return this->event_.signal (); -} - -#else /* !defined (ACE_WIN32) */ -// This class is only necessary on non-win32 platforms. -ACE_INLINE -ACE_ES_Reactor_NS::ACE_ES_Reactor_NS (ACE_Event_Handler *eh, - TAO_EC_Timer_Module *tm) - : ACE_Reactor_Notification_Strategy (tm->reactor (0), - eh, ACE_Event_Handler::READ_MASK) -{ -} - -ACE_INLINE int -ACE_ES_Reactor_NS::open (void) -{ - return 0; -} - -ACE_INLINE void -ACE_ES_Reactor_NS::shutdown (void) -{ -} - -#endif /* ACE_WIN32 */ - -// ************************************************************ diff --git a/TAO/orbsvcs/orbsvcs/Event/Event_Channel.cpp b/TAO/orbsvcs/orbsvcs/Event/Event_Channel.cpp deleted file mode 100644 index 0de783903ff..00000000000 --- a/TAO/orbsvcs/orbsvcs/Event/Event_Channel.cpp +++ /dev/null @@ -1,3532 +0,0 @@ -// $Id$ - -#include "ace/Service_Config.h" -#include "ace/Auto_Ptr.h" -#include "orbsvcs/Scheduler_Factory.h" -#include "orbsvcs/Event_Utilities.h" - -#include "orbsvcs/Event/Dispatching_Modules.h" -#include "orbsvcs/Event/Memory_Pools.h" -#include "orbsvcs/Event/EC_Gateway.h" -#include "orbsvcs/Event/Module_Factory.h" -#include "orbsvcs/Event/Event_Manip.h" -#include "orbsvcs/Event/Event_Channel.h" - -#if !defined (__ACE_INLINE__) -#include "Event_Channel.i" -#endif /* __ACE_INLINE__ */ - -ACE_RCSID(Event, Event_Channel, "$Id$") - -#include "tao/Timeprobe.h" - -#if defined (ACE_HAS_EXPLICIT_TEMPLATE_INSTANTIATION) -template class ACE_Atomic_Op<ACE_ES_MUTEX, int>; -template class ACE_Atomic_Op_Ex<ACE_ES_MUTEX, int>; -template class ACE_Map_Entry<ACE_ES_Subscription_Info::EXT, ACE_ES_Subscription_Info::INT>; -template class ACE_Map_Entry<ACE_ES_Subscription_Info::sEXT, ACE_ES_Subscription_Info::sINT>; -template class ACE_Map_Entry<RtecEventChannelAdmin::Observer_Handle, ACE_EventChannel::Observer_Entry>; -template class ACE_Map_Manager<ACE_ES_Subscription_Info::EXT, ACE_ES_Subscription_Info::INT, ACE_ES_Subscription_Info::SYNCH>; -template class ACE_Map_Manager<ACE_ES_Subscription_Info::sEXT, ACE_ES_Subscription_Info::sINT, ACE_ES_Subscription_Info::SYNCH>; -template class ACE_Map_Manager<RtecEventChannelAdmin::Observer_Handle, ACE_EventChannel::Observer_Entry, ACE_Null_Mutex>; -template class ACE_Map_Iterator_Base<ACE_ES_Subscription_Info::EXT, ACE_ES_Subscription_Info::INT, ACE_ES_Subscription_Info::SYNCH>; -template class ACE_Map_Iterator_Base<ACE_ES_Subscription_Info::sEXT, ACE_ES_Subscription_Info::sINT, ACE_ES_Subscription_Info::SYNCH>; -template class ACE_Map_Iterator_Base<RtecEventChannelAdmin::Observer_Handle, ACE_EventChannel::Observer_Entry, ACE_Null_Mutex>; -template class ACE_Map_Iterator<ACE_ES_Subscription_Info::EXT, ACE_ES_Subscription_Info::INT, ACE_ES_Subscription_Info::SYNCH>; -template class ACE_Map_Iterator<RtecEventChannelAdmin::Observer_Handle, ACE_EventChannel::Observer_Entry, ACE_Null_Mutex>; -template class ACE_Map_Reverse_Iterator<ACE_ES_Subscription_Info::EXT, ACE_ES_Subscription_Info::INT, ACE_ES_Subscription_Info::SYNCH>; -template class ACE_Map_Iterator<ACE_ES_Subscription_Info::sEXT, ACE_ES_Subscription_Info::sINT, ACE_ES_Subscription_Info::SYNCH>; -template class ACE_Map_Reverse_Iterator<ACE_ES_Subscription_Info::sEXT, ACE_ES_Subscription_Info::sINT, ACE_ES_Subscription_Info::SYNCH>; -template class ACE_Map_Reverse_Iterator<RtecEventChannelAdmin::Observer_Handle, ACE_EventChannel::Observer_Entry, ACE_Null_Mutex>; -template class ACE_Node<ACE_ES_Consumer_Rep *>; -template class ACE_Node<ACE_Push_Consumer_Proxy *>; -template class ACE_Node<ACE_Push_Supplier_Proxy *>; -template class ACE_Unbounded_Set<ACE_ES_Consumer_Rep *>; -template class ACE_Unbounded_Set<ACE_Push_Consumer_Proxy *>; -template class ACE_Unbounded_Set<ACE_Push_Supplier_Proxy *>; -template class ACE_Unbounded_Set_Iterator<ACE_ES_Consumer_Rep *>; -template class ACE_Unbounded_Set_Iterator<ACE_Push_Consumer_Proxy *>; -template class ACE_Unbounded_Set_Iterator<ACE_Push_Supplier_Proxy *>; - -template class ACE_Auto_Basic_Ptr<ACE_Push_Supplier_Proxy>; -template class ACE_Auto_Basic_Ptr<ACE_Push_Consumer_Proxy>; -template class auto_ptr<ACE_Push_Supplier_Proxy>; -template class auto_ptr<ACE_Push_Consumer_Proxy>; - -template class ACE_Array<TAO_EC_Event>; -template class ACE_Array_Base<TAO_EC_Event>; -template class ACE_Array_Iterator<TAO_EC_Event>; - -#elif defined(ACE_HAS_TEMPLATE_INSTANTIATION_PRAGMA) -#pragma instantiate ACE_Atomic_Op<ACE_ES_MUTEX, int> -#pragma instantiate ACE_Atomic_Op_Ex<ACE_ES_MUTEX, int> -#pragma instantiate ACE_Map_Entry<ACE_ES_Subscription_Info::EXT, ACE_ES_Subscription_Info::INT> -#pragma instantiate ACE_Map_Entry<ACE_ES_Subscription_Info::sEXT, ACE_ES_Subscription_Info::sINT> -#pragma instantiate ACE_Map_Entry<RtecEventChannelAdmin::Observer_Handle, ACE_EventChannel::Observer_Entry> -#pragma instantiate ACE_Map_Manager<ACE_ES_Subscription_Info::EXT, ACE_ES_Subscription_Info::INT, ACE_ES_Subscription_Info::SYNCH> -#pragma instantiate ACE_Map_Manager<ACE_ES_Subscription_Info::sEXT, ACE_ES_Subscription_Info::sINT, ACE_ES_Subscription_Info::SYNCH> -#pragma instantiate ACE_Map_Manager<RtecEventChannelAdmin::Observer_Handle, ACE_EventChannel::Observer_Entry, ACE_Null_Mutex> -#pragma instantiate ACE_Map_Iterator_Base<ACE_ES_Subscription_Info::EXT, ACE_ES_Subscription_Info::INT, ACE_ES_Subscription_Info::SYNCH> -#pragma instantiate ACE_Map_Iterator_Base<ACE_ES_Subscription_Info::sEXT, ACE_ES_Subscription_Info::sINT, ACE_ES_Subscription_Info::SYNCH> -#pragma instantiate ACE_Map_Iterator_Base<RtecEventChannelAdmin::Observer_Handle, ACE_EventChannel::Observer_Entry, ACE_Null_Mutex> -#pragma instantiate ACE_Map_Iterator<ACE_ES_Subscription_Info::EXT, ACE_ES_Subscription_Info::INT, ACE_ES_Subscription_Info::SYNCH> -#pragma instantiate ACE_Map_Iterator<RtecEventChannelAdmin::Observer_Handle, ACE_EventChannel::Observer_Entry, ACE_Null_Mutex> -#pragma instantiate ACE_Map_Reverse_Iterator<ACE_ES_Subscription_Info::EXT, ACE_ES_Subscription_Info::INT, ACE_ES_Subscription_Info::SYNCH> -#pragma instantiate ACE_Map_Iterator<ACE_ES_Subscription_Info::sEXT, ACE_ES_Subscription_Info::sINT, ACE_ES_Subscription_Info::SYNCH> -#pragma instantiate ACE_Map_Reverse_Iterator<ACE_ES_Subscription_Info::sEXT, ACE_ES_Subscription_Info::sINT, ACE_ES_Subscription_Info::SYNCH> -#pragma instantiate ACE_Map_Reverse_Iterator<RtecEventChannelAdmin::Observer_Handle, ACE_EventChannel::Observer_Entry, ACE_Null_Mutex> -#pragma instantiate ACE_Node<ACE_ES_Consumer_Rep *> -#pragma instantiate ACE_Node<ACE_Push_Consumer_Proxy *> -#pragma instantiate ACE_Node<ACE_Push_Supplier_Proxy *> -#pragma instantiate ACE_Unbounded_Set<ACE_ES_Consumer_Rep *> -#pragma instantiate ACE_Unbounded_Set<ACE_Push_Consumer_Proxy *> -#pragma instantiate ACE_Unbounded_Set<ACE_Push_Supplier_Proxy *> -#pragma instantiate ACE_Unbounded_Set_Iterator<ACE_ES_Consumer_Rep *> -#pragma instantiate ACE_Unbounded_Set_Iterator<ACE_Push_Consumer_Proxy *> -#pragma instantiate ACE_Unbounded_Set_Iterator<ACE_Push_Supplier_Proxy *> - -#pragma instantiate ACE_Auto_Basic_Ptr<ACE_Push_Supplier_Proxy> -#pragma instantiate ACE_Auto_Basic_Ptr<ACE_Push_Consumer_Proxy> -#pragma instantiate auto_ptr<ACE_Push_Supplier_Proxy> -#pragma instantiate auto_ptr<ACE_Push_Consumer_Proxy> - -#pragma instantiate ACE_Array<TAO_EC_Event> -#pragma instantiate ACE_Array_Base<TAO_EC_Event> -#pragma instantiate ACE_Array_Iterator<TAO_EC_Event> - -#endif /* ACE_HAS_EXPLICIT_TEMPLATE_INSTANTIATION */ - -#if defined (ACE_ENABLE_TIMEPROBES) - -static const char *TAO_Event_Channel_Timeprobe_Description[] = -{ - "Preemption_Priority - priority requested", - "connected - priority obtained", - "enter Push_Supplier_Proxy::push", - "enter ES_Consumer_Module::push", - "leave ES_Consumer_Module::push", - "enter ACE_ES_Correlation_Module::push", - "pushed to Correlation_Module", - "push_source_type: Dispatch Module enqueuing", - "ACE_ES_Consumer_Correlation::push, enter", - "Consumer_Correlation::push, determine NO CORR.", - "Consumer_Correlation::push, NO_CORR: alloc", - "Consumer_Rep_Timeout::execute", - "deliver to Subscription Module", - "begin push_source_type", - "end push_source_type", - "deliver to Supplier Module (thru Supplier Proxy)", - "connected - priority requested", - "Consumer_Name - priority requested", - "Consumer_Name - priority obtained", - "deliver event to consumer proxy", - "enter ACE_ES_Subscription_Module::push", - "push_source_type" -}; - -enum -{ - // Timeprobe description table start key - TAO_EVENT_CHANNEL_PREEMPTION_PRIORITY_PRIORITY_REQUESTED = 5100, - TAO_EVENT_CHANNEL_CONNECTED_PRIORITY_OBTAINED, - TAO_EVENT_CHANNEL_ENTER_PUSH_SUPPLIER_PROXY_PUSH, - TAO_EVENT_CHANNEL_ENTER_ES_CONSUMER_MODULE_PUSH, - TAO_EVENT_CHANNEL_LEAVE_ES_CONSUMER_MODULE_PUSH, - TAO_EVENT_CHANNEL_ENTER_ACE_ES_CORRELATION_MODULE_PUSH, - TAO_EVENT_CHANNEL_PUSHED_TO_CORRELATION_MODULE, - TAO_EVENT_CHANNEL_PUSH_SOURCE_TYPE_DISPATCH_MODULE_ENQUEUING, - TAO_EVENT_CHANNEL_ACE_ES_CONSUMER_CORRELATION_PUSH_ENTER, - TAO_EVENT_CHANNEL_CONSUMER_CORRELATION_PUSH_DETERMINE_NO_CORR, - TAO_EVENT_CHANNEL_CONSUMER_CORRELATION_PUSH_NO_CORR_ALLOC, - TAO_EVENT_CHANNEL_CONSUMER_REP_TIMEOUT_EXECUTE, - TAO_EVENT_CHANNEL_DELIVER_TO_SUBSCRIPTION_MODULE, - TAO_EVENT_CHANNEL_BEGIN_PUSH_SOURCE_TYPE, - TAO_EVENT_CHANNEL_END_PUSH_SOURCE_TYPE, - TAO_EVENT_CHANNEL_DELIVER_TO_SUPPLIER_MODULE_THRU_SUPPLIER_PROXY, - TAO_EVENT_CHANNEL_CONNECTED_PRIORITY_REQUESTED, - TAO_EVENT_CHANNEL_CONSUMER_NAME_PRIORITY_REQUESTED, - TAO_EVENT_CHANNEL_CONSUMER_NAME_PRIORITY_OBTAINED, - TAO_EVENT_CHANNEL_DELIVER_EVENT_TO_CONSUMER_PROXY, - TAO_EVENT_CHANNEL_ENTER_ACE_ES_SUBSCRIPTION_MODULE_PUSH, - TAO_EVENT_CHANNEL_PUSH_SOURCE_TYPE -}; - -// Setup Timeprobes -ACE_TIMEPROBE_EVENT_DESCRIPTIONS (TAO_Event_Channel_Timeprobe_Description, - TAO_EVENT_CHANNEL_PREEMPTION_PRIORITY_PRIORITY_REQUESTED); - -#endif /* ACE_ENABLE_TIMEPROBES */ - -static RtecScheduler::Preemption_Priority_t -Preemption_Priority (RtecScheduler::Scheduler_ptr scheduler, - RtecScheduler::handle_t rtinfo - ACE_ENV_ARG_DECL) -{ - RtecScheduler::OS_Priority thread_priority; - RtecScheduler::Preemption_Subpriority_t subpriority; - RtecScheduler::Preemption_Priority_t preemption_priority; - - ACE_TIMEPROBE (TAO_EVENT_CHANNEL_PREEMPTION_PRIORITY_PRIORITY_REQUESTED); - -#if 1 - scheduler->priority - (rtinfo, - thread_priority, - subpriority, - preemption_priority - ACE_ENV_ARG_PARAMETER); -#else - ACE_Scheduler_Factory::server ()->priority - (rtinfo, - thread_priority, - subpriority, - preemption_priority - ACE_ENV_ARG_PARAMETER); -#endif - ACE_CHECK_RETURN (0); - return preemption_priority; -} - -static RtecScheduler::OS_Priority -IntervalToPriority (RtecScheduler::Time interval) -{ - for (int x=0; x < ACE_Scheduler_MAX_PRIORITIES; x++) - if (interval <= ACE_Scheduler_Rates[x]) - return x; - - return ACE_Scheduler_MIN_PREEMPTION_PRIORITY; -} - -class TAO_RTOLDEvent_Export Shutdown_Consumer : public ACE_ES_Dispatch_Request -{ - // = TITLE - // Shutdown Consumer command - // - // = DESCRIPTION - // This command object is sent through the system when a consumer - // disconnects. When the Dispatching Module dequeues this request, - // it calls execute which execute calls back to the Consumer - // Module. At that point, the Consumer Module can tell the rest of - // the system that the consumer has disconnected and delete the - // consumer proxy. This allows all events queued for the consumer - // to be flushed to the consumer proxy (which will drop them). - // Events can be queued in the ReactorEx (in a dispatch set), or in - // the Dispatching Module. -public: - // When executed, tells <consumer_module> that <consumer> has shut - // down. - Shutdown_Consumer (ACE_ES_Consumer_Module *consumer_module, - ACE_Push_Consumer_Proxy *consumer, - RtecScheduler::Scheduler_ptr scheduler) - : consumer_module_ (consumer_module) - { - consumer_ = consumer; - - // Set rt_info_ to the lowest priority rt_info in consumer_. - // This is so the dispatching module can query us as a dispatch - // request to get the appropriate preemption priority. - ACE_ES_Dependency_Iterator iter (consumer->qos ().dependencies); - - RtecScheduler::Preemption_Priority_t p = - ACE_Scheduler_MIN_PREEMPTION_PRIORITY; - while (iter.advance_dependency () == 0) - { - ACE_DECLARE_NEW_CORBA_ENV; - ACE_TRY - { - RtecEventComm::EventType &type = (*iter).event.header.type; - - if (type != ACE_ES_GLOBAL_DESIGNATOR && - type != ACE_ES_CONJUNCTION_DESIGNATOR && - type != ACE_ES_DISJUNCTION_DESIGNATOR) - { - RtecScheduler::Preemption_Priority_t q = - ::Preemption_Priority (scheduler, (*iter).rt_info - ACE_ENV_ARG_PARAMETER); - ACE_TRY_CHECK; - if (rt_info_ == 0 || q < p) - { - this->rt_info_ = ((*iter).rt_info); - p = q; - } - } - } - ACE_CATCHANY - { - // Ignore exceptions... - } - ACE_ENDTRY; - } - } - - // Report to the consumer module that consumer_ has shutdown. - virtual int execute (u_long &command_action) - { - consumer_module_->shutdown_request (this); - command_action = ACE_RT_Task_Command::RELEASE; - return 0; - } - -#if 0 - // @@ Memory allocators - void *operator new (size_t /* nbytes */) - { return ::new char[sizeof (Shutdown_Consumer)]; } - - void operator delete (void *buf) - { ::delete [] static_cast<char*> (buf); } -#endif /* 0 */ - - // The module that we report to. - ACE_ES_Consumer_Module *consumer_module_; -}; - -class TAO_RTOLDEvent_Export Shutdown_Channel : public ACE_ES_Dispatch_Request -{ -public: - Shutdown_Channel (ACE_EventChannel *channel) : - channel_ (channel) {} - - // Report to the consumer module that consumer_ has shutdown. - virtual int execute (u_long &command_action) - { -#if 0 - channel_->destroy_i (); -#endif - command_action = ACE_RT_Task_Command::RELEASE; - return 0; - } - -#if 0 - // @@ Memory allocators - void *operator new (size_t /* nbytes */) - { return ::new char[sizeof (Shutdown_Channel)]; } - - void operator delete (void *buf) - { ::delete [] static_cast<char*> (buf); } -#endif - - ACE_EventChannel *channel_; -}; - -class TAO_RTOLDEvent_Export Flush_Queue_ACT : public ACE_Command_Base -{ - // = TITLE - // Flush Queue Asynchronous Completion Token - // - // = DESCRIPTION - // Carries a single dispatch request through the ReactorEx. - // Deletes itself when execute is called. -public: - Flush_Queue_ACT (ACE_ES_Dispatch_Request *request, - ACE_ES_Dispatching_Module *dispatching_module) : - request_ (request), - dispatching_module_ (dispatching_module) { } - - virtual int execute (void* /* arg = 0 */) - { - ACE_DECLARE_NEW_CORBA_ENV; - ACE_TRY - { - ACE_ES_Dispatch_Request *request = request_; - dispatching_module_->push (request ACE_ENV_ARG_PARAMETER); - ACE_TRY_CHECK; - delete this; - } - ACE_CATCHANY - { - ACE_PRINT_EXCEPTION (ACE_ANY_EXCEPTION, - "Flush_Queue_ACT::execute, " - "unexpected exception"); - } - ACE_ENDTRY; - return 0; - } - - ACE_ES_Dispatch_Request *request_; - ACE_ES_Dispatching_Module *dispatching_module_; -}; - -void -dump_event (const RtecEventComm::Event &event) -{ - ACE_DEBUG ((LM_DEBUG, "source_ = %ld " - "type_ = %d " - "time_ = %u.\n", - event.header.source, - event.header.type, - // The divide-by-1 is for ACE_U_LongLong support. - ORBSVCS_Time::to_hrtime (event.header.creation_time) / 1)); -} - -ACE_Push_Supplier_Proxy::ACE_Push_Supplier_Proxy (ACE_ES_Supplier_Module *sm) - : supplier_module_ (sm), - push_supplier_ (0) -{ -} - -void -ACE_Push_Supplier_Proxy::connect_push_supplier ( - RtecEventComm::PushSupplier_ptr push_supplier, - const RtecEventChannelAdmin::SupplierQOS &qos - ACE_ENV_ARG_DECL) - ACE_THROW_SPEC ((CORBA::SystemException, - RtecEventChannelAdmin::AlreadyConnected)) -{ - if (this->connected ()) - ACE_THROW (RtecEventChannelAdmin::AlreadyConnected()); - - this->push_supplier_ = - RtecEventComm::PushSupplier::_duplicate(push_supplier); - - //ACE_DEBUG ((LM_DEBUG, "EC (%t) connect_push_supplier QOS is ")); - //ACE_SupplierQOS_Factory::debug (qos); - - // Copy by value. - this->qos_ = qos; - - // ACE_SupplierQOS_Factory::debug (qos_); - - // @@ TODO: The SupplierQOS should have a more reasonable interface to - // obtain the supplier_id(), BTW, a callback to push_supplier will - // not work: it usually results in some form of dead-lock. - this->source_id_ = qos_.publications[0].event.header.source; - - supplier_module_->connected (this ACE_ENV_ARG_PARAMETER); -} - -void -ACE_Push_Supplier_Proxy::push (const RtecEventComm::EventSet &event - ACE_ENV_ARG_DECL) - ACE_THROW_SPEC ((CORBA::SystemException)) -{ - ACE_TIMEPROBE (TAO_EVENT_CHANNEL_ENTER_PUSH_SUPPLIER_PROXY_PUSH); - - // NOTE: Detecting that the supplier is collocated is a TAOism. - if (!this->push_supplier_->_is_collocated ()) - { - // NOTE: This is *extremely* non-portable, we know that the ORB - // core allocates this buffer from the global heap, hence it is - // safe to steal it (further the EC will release the buffer, but - // in another thread!). Other ORBs may do different things and - // this may not work! - RtecEventComm::EventSet& copy = - const_cast<RtecEventComm::EventSet&> (event); - - this->time_stamp (copy); - this->supplier_module_->push (this, copy ACE_ENV_ARG_PARAMETER); - ACE_CHECK; - } - else - { - RtecEventComm::EventSet copy = event; - this->time_stamp (copy); - this->supplier_module_->push (this, copy ACE_ENV_ARG_PARAMETER); - ACE_CHECK; - } -} - -void -ACE_Push_Supplier_Proxy::time_stamp (RtecEventComm::EventSet& event) -{ -#if !defined(TAO_LACKS_EVENT_CHANNEL_TIMESTAMPS) - ACE_hrtime_t ec_recv = ACE_OS::gethrtime (); - for (CORBA::ULong i = 0; i < event.length (); ++i) - { - ORBSVCS_Time::hrtime_to_TimeT (event[i].header.ec_recv_time, - ec_recv); - } -#else - ACE_UNUSED_ARG (event); -#endif /* TAO_LACKS_EVENT_CHANNEL_TIMESTAMPS */ -} - -void -ACE_Push_Supplier_Proxy::disconnect_push_consumer ( - ACE_ENV_SINGLE_ARG_DECL) - ACE_THROW_SPEC ((CORBA::SystemException)) -{ - ACE_TIMEPROBE_PRINT; - if (this->connected ()) - { - this->push_supplier_ = 0; - this->supplier_module_->disconnecting (this ACE_ENV_ARG_PARAMETER); - ACE_CHECK; - } -} - -void -ACE_Push_Supplier_Proxy::shutdown (void) -{ - ACE_DECLARE_NEW_CORBA_ENV; - ACE_TRY - { - push_supplier_->disconnect_push_supplier (ACE_ENV_SINGLE_ARG_PARAMETER); - ACE_TRY_CHECK; - } - ACE_CATCHANY - { - ACE_PRINT_EXCEPTION (ACE_ANY_EXCEPTION, - "ACE_Push_Supplier_Proxy::shutdown failed.\n"); - } - ACE_ENDTRY; -} - -ACE_Push_Consumer_Proxy::ACE_Push_Consumer_Proxy (ACE_ES_Consumer_Module *cm) - : push_consumer_ (0), - consumer_module_ (cm) -{ -} - -ACE_Push_Consumer_Proxy::~ACE_Push_Consumer_Proxy (void) -{ -} - -void -ACE_Push_Consumer_Proxy::push (const RtecEventComm::EventSet &events - ACE_ENV_ARG_DECL) -{ - ACE_TIMEPROBE (TAO_EVENT_CHANNEL_DELIVER_EVENT_TO_CONSUMER_PROXY); - - if (CORBA::is_nil (push_consumer_.in ())) - { - ACE_DEBUG ((LM_DEBUG, - "EC (%t) Push to disconnected consumer\n")); - return; - } - - push_consumer_->push (events ACE_ENV_ARG_PARAMETER); - ACE_CHECK; -} - -void -ACE_Push_Consumer_Proxy::connect_push_consumer ( - RtecEventComm::PushConsumer_ptr push_consumer, - const RtecEventChannelAdmin::ConsumerQOS &qos - ACE_ENV_ARG_DECL) - ACE_THROW_SPEC ((CORBA::SystemException, - RtecEventChannelAdmin::AlreadyConnected, - RtecEventChannelAdmin::TypeError)) -{ - if (this->connected ()) - ACE_THROW (RtecEventChannelAdmin::AlreadyConnected()); - - this->push_consumer_ = - RtecEventComm::PushConsumer::_duplicate(push_consumer); - // @@ TODO Find out why are two duplicates needed... - RtecEventComm::PushConsumer::_duplicate(push_consumer); - - //ACE_DEBUG ((LM_DEBUG, "EC (%t) connect_push_consumer QOS is ")); - //ACE_ConsumerQOS_Factory::debug (qos); - - // Copy by value. - this->qos_ = qos; - - // ACE_ConsumerQOS_Factory::debug (qos_); - - this->consumer_module_->connected (this ACE_ENV_ARG_PARAMETER); -} - -void -ACE_Push_Consumer_Proxy::disconnect_push_supplier ( - ACE_ENV_SINGLE_ARG_DECL) - ACE_THROW_SPEC ((CORBA::SystemException)) -{ - ACE_TIMEPROBE_PRINT; - this->push_consumer_ = RtecEventComm::PushConsumer::_nil (); - this->consumer_module_->disconnecting (this ACE_ENV_ARG_PARAMETER); -} - -void -ACE_Push_Consumer_Proxy::suspend_connection (ACE_ENV_SINGLE_ARG_DECL_NOT_USED) - ACE_THROW_SPEC ((CORBA::SystemException)) -{ - correlation_.suspend (); -} - -void -ACE_Push_Consumer_Proxy::resume_connection (ACE_ENV_SINGLE_ARG_DECL_NOT_USED) - ACE_THROW_SPEC ((CORBA::SystemException)) -{ - correlation_.resume (); -} - -void -ACE_Push_Consumer_Proxy::shutdown (void) -{ - ACE_DECLARE_NEW_CORBA_ENV; - ACE_TRY - { - this->push_consumer_->disconnect_push_consumer (ACE_ENV_SINGLE_ARG_PARAMETER); - ACE_TRY_CHECK; - } - ACE_CATCHANY - { - ACE_PRINT_EXCEPTION (ACE_ANY_EXCEPTION, - "ACE_Push_Consumer_Proxy::shutdown failed.\n"); - } - ACE_ENDTRY; -} - -ACE_EventChannel::ACE_EventChannel (RtecScheduler::Scheduler_ptr scheduler, - CORBA::Boolean activate_threads, - u_long type, - TAO_Module_Factory* factory) - : rtu_manager_ (0), - type_ (type), - state_ (INITIAL_STATE), - destroyed_ (0), - handle_generator_ (0), - own_factory_ (0), - module_factory_ (factory) -{ - this->scheduler_ = - RtecScheduler::Scheduler::_duplicate (scheduler); - - this->init (activate_threads); -} - -ACE_EventChannel::ACE_EventChannel (CORBA::Boolean activate_threads, - u_long type, - TAO_Module_Factory* factory) - : rtu_manager_ (0), - type_ (type), - state_ (INITIAL_STATE), - destroyed_ (0), - handle_generator_ (0), - own_factory_ (0), - module_factory_ (factory) -{ - this->scheduler_ = - RtecScheduler::Scheduler::_duplicate (ACE_Scheduler_Factory::server ()); - this->init (activate_threads); -} - -void -ACE_EventChannel::init (int activate_threads) -{ - if (this->module_factory_ == 0) - { - this->own_factory_ = 1; - ACE_NEW (this->module_factory_, TAO_Default_Module_Factory); - } - - consumer_module_ = - this->module_factory_->create_consumer_module (this); - - this->timer_module_ = - this->module_factory_->create_timer_module (this); - - this->dispatching_module_ = - this->module_factory_->create_dispatching_module(this); - - this->correlation_module_ = - this->module_factory_->create_correlation_module (this); - this->subscription_module_ = - this->module_factory_->create_subscription_module (this); - this->supplier_module_ = - this->module_factory_->create_supplier_module (this); - - consumer_module_->open (dispatching_module_); - dispatching_module_->open (consumer_module_, correlation_module_); - correlation_module_->open (dispatching_module_, subscription_module_); - subscription_module_->open (correlation_module_, supplier_module_); - supplier_module_->open (subscription_module_); - - if (activate_threads) - this->activate (); -} - -ACE_EventChannel::~ACE_EventChannel (void) -{ - ACE_DEBUG ((LM_DEBUG, - "EC (%t) ACE_EventChannel deleting all modules.\n")); - - // @@ This should go away, it is too late to raise a CORBA - // exception, at this point we should only be cleaning up memory, - // not sending messages. - ACE_DECLARE_NEW_CORBA_ENV; - ACE_TRY - { - this->destroy (ACE_ENV_SINGLE_ARG_PARAMETER); - ACE_TRY_CHECK; - } - ACE_CATCHANY - { - ACE_PRINT_EXCEPTION (ACE_ANY_EXCEPTION, - "ACE_EventChannel::~ACE_EventChannel"); - } - ACE_ENDTRY; - - this->cleanup_observers (); - - this->timer_module_->shutdown (); - this->dispatching_module_->shutdown (); - - this->module_factory_->destroy_timer_module (this->timer_module_); - this->module_factory_->destroy_supplier_module (this->supplier_module_); - this->module_factory_->destroy_subscription_module (this->subscription_module_); - this->module_factory_->destroy_correlation_module (this->correlation_module_); - this->module_factory_->destroy_dispatching_module(this->dispatching_module_); - this->module_factory_->destroy_consumer_module (this->consumer_module_); - - if (this->own_factory_) - delete this->module_factory_; -} - -void -ACE_EventChannel::destroy (ACE_ENV_SINGLE_ARG_DECL_NOT_USED) - ACE_THROW_SPEC ((CORBA::SystemException)) -{ - { - ACE_GUARD (ACE_ES_MUTEX, ace_mon, this->lock_); - - if (this->destroyed_ != 0) - return; - - this->destroyed_ = 1; - ACE_DEBUG ((LM_DEBUG, "EC (%t) Event Channel shutting down.\n")); - - } - this->cleanup_observers (); - - // Send a shutdown message through the modules. - this->supplier_module_->shutdown (); - -#if 0 - // Flush all messages in the channel. - Shutdown_Channel *sc = new Shutdown_Channel (this); - if (sc == 0) - ACE_THROW (CORBA::NO_MEMORY ()); - - // Create a wrapper around the dispatch request. - Flush_Queue_ACT *act = new Flush_Queue_ACT (sc, dispatching_module_); - if (act == 0) - ACE_THROW (CORBA::NO_MEMORY ()); - - // Set a 100ns timer. - if (this->timer_module ()->schedule_timer (0, // no rt-info - act, - ACE_Scheduler_MIN_PREEMPTION_PRIORITY, - 100, // 10 usec delta - 0) == -1) // no interval - { - ACE_ERROR ((LM_ERROR, "%p queue_request failed.\n", "ACE_ES_Consumer_Module")); - delete sc; - delete act; - } -#endif -} - -void -ACE_EventChannel::activate (void) -{ - this->dispatching_module_->activate (THREADS_PER_DISPATCH_QUEUE); - this->timer_module_->activate (); -} - -void -ACE_EventChannel::shutdown (void) -{ - this->cleanup_observers (); - - this->timer_module_->shutdown (); - this->dispatching_module_->shutdown (); -} - -void -ACE_EventChannel::report_connect (u_long event) -{ - ACE_GUARD (ACE_ES_MUTEX, ace_mon, this->lock_); - - this->report_connect_i (event); -} - -void -ACE_EventChannel::report_connect_i (u_long event) -{ - ACE_CLR_BITS (state_, event); -} - -void -ACE_EventChannel::report_disconnect (u_long event) -{ - // No need to gtrab the lock is already take by our callers. - ACE_GUARD (ACE_ES_MUTEX, ace_mon, this->lock_); - - this->report_disconnect (event); -} - -void -ACE_EventChannel::report_disconnect_i (u_long event) -{ - ACE_SET_BITS (state_, event); - if (state_ == SHUTDOWN) - ACE_DEBUG ((LM_DEBUG, - "EC (%t) Event Channel has no consumers or suppliers.\n")); -} - -void -ACE_EventChannel::add_gateway (TAO_EC_Gateway* gw - ACE_ENV_ARG_DECL) -{ - RtecEventChannelAdmin::Observer_var observer = gw->_this (ACE_ENV_SINGLE_ARG_PARAMETER); - ACE_CHECK; - - gw->observer_handle (this->append_observer (observer.in () ACE_ENV_ARG_PARAMETER)); - ACE_CHECK; -} - -void -ACE_EventChannel::del_gateway (TAO_EC_Gateway* gw - ACE_ENV_ARG_DECL) -{ - this->remove_observer (gw->observer_handle () ACE_ENV_ARG_PARAMETER); - ACE_CHECK; - - gw->observer_handle (0); -} - -void -ACE_EventChannel::update_consumer_gwys (ACE_ENV_SINGLE_ARG_DECL) -{ - Observer_Map observers; - { - ACE_GUARD_THROW_EX ( - ACE_ES_MUTEX, ace_mon, this->lock_, - RtecEventChannelAdmin::EventChannel::SYNCHRONIZATION_ERROR()); - ACE_CHECK; - - if (this->observers_.current_size () == 0 - || this->state_ == ACE_EventChannel::SHUTDOWN) - return; - - observers.open (this->observers_.current_size ()); - for (Observer_Map_Iterator i = this->observers_.begin (); - i != this->observers_.end (); - ++i) - { - observers.bind ((*i).ext_id_, (*i).int_id_); - } - } - - // ACE_DEBUG ((LM_DEBUG, - // "EC (%t) Event_Channel::update_consumer_gwys\n")); - - RtecEventChannelAdmin::ConsumerQOS c_qos; - this->consumer_module_->fill_qos (c_qos); - for (Observer_Map_Iterator i = observers.begin (); - i != observers.end (); - ++i) - { - (*i).int_id_.observer->update_consumer (c_qos ACE_ENV_ARG_PARAMETER); - ACE_CHECK; - } -} - -void -ACE_EventChannel::update_supplier_gwys (ACE_ENV_SINGLE_ARG_DECL) -{ - Observer_Map observers; - { - ACE_GUARD_THROW_EX (ACE_ES_MUTEX, ace_mon, this->lock_, - RtecEventChannelAdmin::EventChannel::SYNCHRONIZATION_ERROR()); - ACE_CHECK; - - if (this->observers_.current_size () == 0 - || this->state_ == ACE_EventChannel::SHUTDOWN) - return; - - observers.open (this->observers_.current_size ()); - for (Observer_Map_Iterator i = this->observers_.begin (); - i != this->observers_.end (); - ++i) - { - observers.bind ((*i).ext_id_, (*i).int_id_); - } - } - - // ACE_DEBUG ((LM_DEBUG, - // "EC (%t) Event_Channel::update_supplier_gwys\n")); - - RtecEventChannelAdmin::SupplierQOS s_qos; - this->supplier_module_->fill_qos (s_qos); - for (Observer_Map_Iterator i = observers.begin (); - i != observers.end (); - ++i) - { - (*i).int_id_.observer->update_supplier (s_qos ACE_ENV_ARG_PARAMETER); - ACE_CHECK; - } -} - -RtecEventChannelAdmin::Observer_Handle -ACE_EventChannel::append_observer (RtecEventChannelAdmin::Observer_ptr obs - ACE_ENV_ARG_DECL) - ACE_THROW_SPEC (( - CORBA::SystemException, - RtecEventChannelAdmin::EventChannel::SYNCHRONIZATION_ERROR, - RtecEventChannelAdmin::EventChannel::CANT_APPEND_OBSERVER)) -{ - ACE_GUARD_THROW_EX (ACE_ES_MUTEX, ace_mon, this->lock_, - RtecEventChannelAdmin::EventChannel::SYNCHRONIZATION_ERROR()); - ACE_CHECK_RETURN (0); - - this->handle_generator_++; - Observer_Entry entry (this->handle_generator_, - RtecEventChannelAdmin::Observer::_duplicate (obs)); - - if (this->observers_.bind (entry.handle, entry) == -1) - ACE_THROW_RETURN ( - RtecEventChannelAdmin::EventChannel::CANT_APPEND_OBSERVER(), - 0); - - RtecEventChannelAdmin::ConsumerQOS c_qos; - this->consumer_module_->fill_qos (c_qos); - obs->update_consumer (c_qos ACE_ENV_ARG_PARAMETER); - ACE_CHECK_RETURN (0); - - RtecEventChannelAdmin::SupplierQOS s_qos; - this->supplier_module_->fill_qos (s_qos); - obs->update_supplier (s_qos ACE_ENV_ARG_PARAMETER); - ACE_CHECK_RETURN (0); - - return entry.handle; -} - -void -ACE_EventChannel::remove_observer (RtecEventChannelAdmin::Observer_Handle h - ACE_ENV_ARG_DECL) - ACE_THROW_SPEC (( - CORBA::SystemException, - RtecEventChannelAdmin::EventChannel::SYNCHRONIZATION_ERROR, - RtecEventChannelAdmin::EventChannel::CANT_REMOVE_OBSERVER)) -{ - ACE_GUARD_THROW_EX (ACE_ES_MUTEX, ace_mon, this->lock_, - RtecEventChannelAdmin::EventChannel::SYNCHRONIZATION_ERROR()); - ACE_CHECK; - - if (this->observers_.unbind (h) == -1) - ACE_THROW ( - RtecEventChannelAdmin::EventChannel::CANT_REMOVE_OBSERVER()); -} - -void -ACE_EventChannel::cleanup_observers (void) -{ - ACE_GUARD (ACE_ES_MUTEX, ace_mon, this->lock_); - - // @@ TODO report back any errors here... - this->observers_.close (); -} - -int -ACE_EventChannel::schedule_timer (RtecScheduler::handle_t rt_info, - const ACE_Command_Base *act, - RtecScheduler::Preemption_Priority_t preemption_priority, - const RtecScheduler::Time &delta, - const RtecScheduler::Time &interval) -{ - if (rt_info != 0) - { - // Add the timer to the task's dependency list. - RtecScheduler::handle_t timer_rtinfo = - this->timer_module ()->rt_info (preemption_priority); - - ACE_DECLARE_NEW_CORBA_ENV; - ACE_TRY - { -#if 1 - this->scheduler_->add_dependency (rt_info, - timer_rtinfo, - 1, - RtecBase::ONE_WAY_CALL - ACE_ENV_ARG_PARAMETER); -#else - ACE_Scheduler_Factory::server()->add_dependency - (rt_info, - timer_rtinfo, - 1, - RtecBase::ONE_WAY_CALL - ACE_ENV_ARG_PARAMETER); -#endif - ACE_TRY_CHECK; - } - ACE_CATCHANY - { - ACE_PRINT_EXCEPTION (ACE_ANY_EXCEPTION, - "add dependency failed"); - } - ACE_ENDTRY; - } - - // @@ We're losing resolution here. - ACE_Time_Value tv_delta; - ORBSVCS_Time::TimeT_to_Time_Value (tv_delta, delta); - - ACE_Time_Value tv_interval; - ORBSVCS_Time::TimeT_to_Time_Value (tv_interval, interval); - - return this->timer_module ()->schedule_timer (preemption_priority, - const_cast<ACE_Command_Base*> (act), - tv_delta, - tv_interval); -} - -ACE_EventChannel::Observer_Entry::Observer_Entry (void) - : handle (0) -{ -} - -ACE_EventChannel::Observer_Entry::Observer_Entry (RtecEventChannelAdmin::Observer_Handle h, - RtecEventChannelAdmin::Observer_ptr o) - : handle (h), - observer (o) -{ -} - -ACE_ES_Disjunction_Group::~ACE_ES_Disjunction_Group (void) -{ -} - -ACE_ES_Conjunction_Group::~ACE_ES_Conjunction_Group (void) -{ -} - -ACE_ES_Subscription_Info::~ACE_ES_Subscription_Info (void) -{ - Subscriber_Map_Iterator iter (type_subscribers_); - - // Delete all type collections. - for (Subscriber_Map_Entry *temp = 0; - iter.next (temp) != 0; - iter.advance ()) - { - delete temp->int_id_; - } -} - -/* -void -ACE_ES_Subscription_Info::Type_Subscribers::operator= -(const ACE_ES_Subscription_Info::Type_Subscribers &rhs) -{ - ACE_ES_Subscription_Info::Subscriber_Set_Iterator iter (rhs.subscribers_); - - for (ACE_ES_Consumer_Rep **consumer = 0; - iter.next (consumer) != 0; - iter.advance ()) - { - if (subscribers_.insert (consumer) != 0) - ACE_ERROR ((LM_ERROR, "%p insert failed.\n", - "ACE_ES_Subscription_Info::Type_Subscribers::operator=")); - } - - // Pointer copy. - dependency_info_ = rhs.dependency_info_; -} -*/ - -// Remove <consumer> from the consumer set in <type_map> set -// corresponding to <type>. -int -ACE_ES_Subscription_Info::remove (Subscriber_Map &type_map, - ACE_ES_Consumer_Rep *consumer, - RtecEventComm::EventType type) -{ - Type_Subscribers *subscribers; - - // Find the type set within the type collection. - if (type_map.find (type, subscribers) == -1) - { - ACE_DEBUG ((LM_DEBUG, - "EC (%t) Info::remove - not found %d\n", type)); - // type_map does not contain the type. - return -1; - } - - // Remove the consumer from the type set. - if (subscribers->consumers_.remove (consumer) == -1) - ACE_ERROR_RETURN ((LM_ERROR, "%p remove failed.\n", - "ACE_ES_Subscriber_Info::remove"), -1); - // @@ Should probably remove the supplier from the consumers caller - // list. - - // @@ Should we release here? consumer->_release (); - -#if 0 - // If the set is empty, remove it from the type collection. - // NOT!!!! In some cases the map is initialized to the types that a - // certain supplier export; removing an entry from the map renders - // that supplier unable to send that event type. - // Before changing this ask me (coryan). - if (subscribers->consumers_.size () == 0) - { - Type_Subscribers *removed_subscribers; - if (type_map.unbind (type, removed_subscribers) == -1) - ACE_ERROR_RETURN ((LM_ERROR, "%p unbind failed.\n", - "ACE_ES_Subscriber_Info::remove"), -1); - - // Sanity check. - if (removed_subscribers != subscribers) - ACE_ERROR_RETURN ((LM_ERROR, "ACE_ES_Subscriber_Info::remove: " - "removed wrong set!\n"), -1); - - // Free up the set removed. - delete removed_subscribers; - } -#endif /* 0 */ - - return 0; -} - - -int -ACE_ES_Subscription_Info::remove (SourceID_Map &source_subscribers, - ACE_ES_Consumer_Rep *consumer, - RtecEventComm::EventSourceID sid) -{ - Subscriber_Set *subscribers; - - // Find the subscribers of <sid>. - if (source_subscribers.find (sid, subscribers) == -1) - // does not contain the <sid>. - return -1; - - // Remove the consumer from the subscriber set. - if (subscribers->remove (consumer) == -1) - ACE_ERROR_RETURN ((LM_ERROR, "%p remove failed.\n", - "ACE_ES_Subscriber_Info::remove"), -1); - - // @@ Should we release here? consumer->_release (); - - // @@ Should probably remove the supplier from the consumers caller - // list. - -#if 0 - // If the set is empty, remove it from the type collection. - // NOT!!!! In some cases the map is initialized to the types that a - // certain supplier export; removing an entry from the map renders - // that supplier unable to send that event type. - // Before changing this ask me (coryan). - if (subscribers->size () == 0) - { - Subscriber_Set *removed_subscribers; - if (source_subscribers.unbind (sid, removed_subscribers) == -1) - ACE_ERROR_RETURN ((LM_ERROR, "%p unbind failed.\n", - "ACE_ES_Subscriber_Info::remove"), -1); - - // Sanity check. - if (removed_subscribers != subscribers) - ACE_ERROR_RETURN ((LM_ERROR, "ACE_ES_Subscriber_Info::remove: " - "removed wrong set!\n"), -1); - - // Free up the set removed. - delete removed_subscribers; - } -#endif /* 0 */ - - return 0; -} - -void -ACE_ES_Subscription_Info::append_subscribers (Subscriber_Set &dest, - Subscriber_Set &src) -{ - Subscriber_Set_Iterator src_iter (src); - - // Iterate through the source set. Add each source proxy to the - // destination set. - for (ACE_ES_Consumer_Rep **proxy = 0; - src_iter.next (proxy) != 0; - src_iter.advance ()) - { - if (dest.insert (*proxy) == -1) - ACE_ERROR ((LM_ERROR, "%p: insert failed.\n", "append_subscribers")); - } -} - -int -ACE_ES_Subscription_Info::insert_or_allocate (SourceID_Map &sid_map, - ACE_ES_Consumer_Rep *consumer, - RtecEventComm::EventSourceID sid) -{ - Subscriber_Set *subscribers; - - if (sid_map.find (sid, subscribers) == -1) - { - // If the correct type set does not exist, make one with a null - // dependency info (since there is no supplier of this event). - subscribers = new Subscriber_Set; - - if (sid_map.bind (sid, subscribers) == -1) - { - ACE_ERROR ((LM_ERROR, "%p bind failed.\n", - "ACE_ES_Subscription_Info::insert_or_allocate")); - delete subscribers; - return -1; - } - } - - // 0 and 1 are success for insert. - if (subscribers->insert (consumer) == -1) - ACE_ERROR_RETURN ((LM_ERROR, "%p insert failed.\n", - "ACE_ES_Subscription_Info::insert_or_allocate"), - -1); - - consumer->_duplicate (); - return 0; -} - -int -ACE_ES_Subscription_Info::insert_or_allocate (Subscriber_Map &type_map, - ACE_ES_Consumer_Rep *consumer, - RtecEventComm::EventType type) -{ - Type_Subscribers *subscribers; - - if (type_map.find (type, subscribers) == -1) - { - // If the correct type set does not exist, make one with a null - // dependency info (since there is no supplier of this event). - subscribers = new Type_Subscribers (0); - - if (type_map.bind (type, subscribers) == -1) - { - ACE_ERROR ((LM_ERROR, "%p bind failed.\n", - "ACE_ES_Subscription_Info::insert_or_allocate")); - delete subscribers; - return -1; - } - } - - if (subscribers->consumers_.insert (consumer) == -1) - { - ACE_ERROR ((LM_ERROR, "%p insert failed.\n", - "ACE_ES_Subscription_Info::insert_or_allocate")); - } - - consumer->_duplicate (); - return 0; -} - -int -ACE_ES_Subscription_Info::insert_or_fail (Subscriber_Map &type_map, - ACE_ES_Consumer_Rep *consumer, - RtecEventComm::EventType type, - RtecScheduler::Dependency_Info *&dependency) -{ - Type_Subscribers *subscribers; - - // Get the subscriber set for <type>. - if (type_map.find (type, subscribers) == -1) - return -1; - - // Pass back the description of the method generating <type>. - dependency = subscribers->dependency_info_; - - // Insert the new consumer into the subscriber set. - if (subscribers->consumers_.insert (consumer) == -1) - { - ACE_ERROR_RETURN ((LM_ERROR, "%p insert failed.\n", - "ACE_ES_Subscription_Info::insert_or_fail"), - -1); - } - - consumer->_duplicate (); - return 0; -} - -ACE_ES_Consumer_Module::ACE_ES_Consumer_Module (ACE_EventChannel* channel) - : lock_ (), - all_consumers_ (), - channel_ (channel), - down_ (0) -{ -} - -void -ACE_ES_Consumer_Module::open (ACE_ES_Dispatching_Module *down) -{ - down_ = down; -} - -void -ACE_ES_Consumer_Module::connected (ACE_Push_Consumer_Proxy *consumer - ACE_ENV_ARG_DECL) -{ - // ACE_DEBUG ((LM_DEBUG, - // "EC (%t) Consumer_Module - connecting consumer %x\n", - // consumer)); - - this->channel_->report_connect (ACE_EventChannel::CONSUMER); - this->down_->connected (consumer ACE_ENV_ARG_PARAMETER); - ACE_CHECK; - - if (!consumer->qos ().is_gateway) - this->channel_->update_consumer_gwys (ACE_ENV_SINGLE_ARG_PARAMETER); -} - -void -ACE_ES_Consumer_Module::shutdown_request (ACE_ES_Dispatch_Request *request) -{ - ACE_TRY_NEW_ENV - { - Shutdown_Consumer *sc = (Shutdown_Consumer *) request; - - // Tell everyone else that the consumer is disconnected. This means - // that *nothing* is left in the system for the consumer, so - // everyone can free up any resources. - this->down_->disconnected (sc->consumer ()); - - // ACE_DEBUG ((LM_DEBUG, - // "EC (%t) Consumer_Module - remove consumer %x\n", - // sc->consumer ())); - - CORBA::Boolean dont_update = sc->consumer ()->qos ().is_gateway; - - // Deactivate the consumer proxy - PortableServer::POA_var poa = - sc->consumer ()->_default_POA (ACE_ENV_SINGLE_ARG_PARAMETER); - ACE_TRY_CHECK; - PortableServer::ObjectId_var id = - poa->servant_to_id (sc->consumer () ACE_ENV_ARG_PARAMETER); - ACE_TRY_CHECK; - poa->deactivate_object (id.in () ACE_ENV_ARG_PARAMETER); - ACE_TRY_CHECK; - - // Delete the consumer proxy, no need to delete it, is is owned - // by the POA - // delete sc->consumer (); - - if (!dont_update) - this->channel_->update_consumer_gwys (ACE_ENV_SINGLE_ARG_PARAMETER); - ACE_TRY_CHECK; - - ACE_GUARD_THROW_EX ( - ACE_ES_MUTEX, ace_mon, this->lock_, - RtecEventChannelAdmin::EventChannel::SYNCHRONIZATION_ERROR()); - ACE_TRY_CHECK; - - // Tell the channel that we may need to shut down. - if (all_consumers_.size () <= 0) - { - // ACE_DEBUG ((LM_DEBUG, - // "EC (%t) No more consumers connected.\n")); - channel_->report_disconnect_i (ACE_EventChannel::CONSUMER); - } - } - ACE_CATCHANY - { - ACE_PRINT_EXCEPTION (ACE_ANY_EXCEPTION, - "Consumer_Module::shutdown_request"); - } - ACE_ENDTRY; -} - -void -ACE_ES_Consumer_Module::shutdown (void) -{ - Consumers copy; - - { - ACE_Guard<ACE_ES_MUTEX> ace_mon (lock_); - if (ace_mon.locked () == 0) - goto DONE; - - if (all_consumers_.size () == 0) - goto DONE; - - // Make a copy so that the consumers can disconnect without the - // lock being held. - copy = all_consumers_; - } - - // This scope is just to thwart the compiler. It was complaining - // about the above goto's bypassing variable initializations. Yadda - // yadda. - { - Consumer_Iterator iter (copy); - - ACE_DECLARE_NEW_CORBA_ENV; - ACE_TRY - { - for (ACE_Push_Consumer_Proxy **proxy = 0; - iter.next (proxy) != 0; - iter.advance ()) - { - (*proxy)->shutdown (); - // @@ Cannnot use CORBA::release (*proxy), since it is a - // servant. - // Deactivate the proxy... - PortableServer::POA_var poa = - (*proxy)->_default_POA (ACE_ENV_SINGLE_ARG_PARAMETER); - ACE_TRY_CHECK; - PortableServer::ObjectId_var id = - poa->servant_to_id (*proxy ACE_ENV_ARG_PARAMETER); - ACE_TRY_CHECK; - poa->deactivate_object (id.in () ACE_ENV_ARG_PARAMETER); - ACE_TRY_CHECK; - - // Remove the consumer from our list. - { - ACE_Guard<ACE_ES_MUTEX> ace_mon (lock_); - if (ace_mon.locked () == 0) - ACE_ERROR ((LM_ERROR, "%p Failed to acquire lock.\n", "ACE_ES_Consumer_Module::shutdown")); - - if (all_consumers_.remove (*proxy) == -1) - ACE_ERROR ((LM_ERROR, "%p Failed to remove consumer.\n", "ACE_ES_Consumer_Module::shutdown")); - } - - // No need to delete it, owned by the POA - // delete *proxy; - } - } - ACE_CATCHANY - { - // Ignore the exceptions... - } - ACE_ENDTRY; - } - -DONE: - channel_->shutdown (); -} - -void -ACE_ES_Consumer_Module::disconnecting (ACE_Push_Consumer_Proxy *consumer - ACE_ENV_ARG_DECL) -{ - { - ACE_GUARD_THROW_EX ( - ACE_ES_MUTEX, ace_mon, this->lock_, - RtecEventChannelAdmin::EventChannel::SYNCHRONIZATION_ERROR()); - ACE_CHECK; - - if (all_consumers_.remove (consumer) == -1) - ACE_THROW (RtecEventChannelAdmin::EventChannel::SUBSCRIPTION_ERROR()); - } - - // Tell everyone else that the consumer is disconnecting. This - // allows them to remove the consumer from any subscription lists - // etc. However, messages may still be queued in the ReactorEx or - // in the Dispatching Module for this consumer, so no queues or - // proxies can be deleted just yet. - down_->disconnecting (consumer ACE_ENV_ARG_PARAMETER); - ACE_CHECK; - - // Send a shutdown message through the system. When this is - // dispatched, the consumer proxy will be deleted. <request> is - // queued in the Priority_Timer at <priority> level. It will be - // scheduled for dispatching in 1 nanosecond. This gives components - // a hook into the first queueing point in the channel. - - // Create a shutdown message. When this is dispatched, it will - // delete the proxy. - RtecScheduler::Scheduler_var scheduler = - this->channel_->scheduler (); - Shutdown_Consumer *sc = - new Shutdown_Consumer (this, consumer, scheduler.in ()); - if (sc == 0) - ACE_THROW (CORBA::NO_MEMORY ()); - - // Create a wrapper around the dispatch request. - Flush_Queue_ACT *act = - new Flush_Queue_ACT (sc, channel_->dispatching_module_); - if (act == 0) - ACE_THROW (CORBA::NO_MEMORY ()); - - // ACE_DEBUG ((LM_DEBUG, "EC (%t) initiating consumer disconnect.\n")); - - // Set a 100ns timer. - TimeBase::TimeT ns100; - ORBSVCS_Time::hrtime_to_TimeT (ns100, 100); - if (this->channel_->schedule_timer (0, // no rt_info - act, - ACE_Scheduler_MIN_PREEMPTION_PRIORITY, - ns100, - ORBSVCS_Time::zero ()) == -1) - { - ACE_ERROR ((LM_ERROR, "%p queue_request failed.\n", "ACE_ES_Consumer_Module")); - delete sc; - delete act; - } -} - -// This method executes in the same thread of control that will hand -// the event set to the consumer (or it's proxy). A network proxy may -// copy the event set to the network buffer. An active client may -// copy the event set to be queued. Or a same address-space consumer -// can read the set we allocated off the stack. -void -ACE_ES_Consumer_Module::push (const ACE_ES_Dispatch_Request *request - ACE_ENV_ARG_DECL) -{ - // ACE_DEBUG ((LM_DEBUG, "EC (%t) Consumer_Module::push\n")); - - ACE_FUNCTION_TIMEPROBE (TAO_EVENT_CHANNEL_ENTER_ES_CONSUMER_MODULE_PUSH); - // We'll create a temporary event set with the size of the incoming - // request. - RtecEventComm::EventSet event_set; - request->make_copy (event_set); - - // Forward the event set. -#if !defined(TAO_LACKS_EVENT_CHANNEL_TIMESTAMPS) - ACE_hrtime_t ec_send = ACE_OS::gethrtime (); - for (CORBA::ULong i = 0; i < event_set.length (); ++i) - { - RtecEventComm::Event& ev = event_set[i]; - ORBSVCS_Time::hrtime_to_TimeT (ev.header.ec_send_time, ec_send); - } -#endif /* TAO_LACKS_EVENT_CHANNEL_TIMESTAMPS */ - request->consumer ()->push (event_set ACE_ENV_ARG_PARAMETER); -} - -RtecEventChannelAdmin::ProxyPushSupplier_ptr -ACE_ES_Consumer_Module::obtain_push_supplier ( - ACE_ENV_SINGLE_ARG_DECL) - ACE_THROW_SPEC ((CORBA::SystemException)) -{ - RtecEventChannelAdmin::ProxyPushSupplier_ptr proxy = - RtecEventChannelAdmin::ProxyPushSupplier::_nil (); - - auto_ptr<ACE_Push_Consumer_Proxy> new_consumer (new ACE_Push_Consumer_Proxy (this)); - - // Get a new supplier proxy object. - if (new_consumer.get () == 0) - { - ACE_ERROR ((LM_ERROR, "ACE_EventChannel" - "::obtain_push_supplier failed.\n")); - ACE_THROW_RETURN (CORBA::NO_MEMORY (), proxy); - } - - { - ACE_GUARD_THROW_EX ( - ACE_ES_MUTEX, ace_mon, this->lock_, - CORBA::INTERNAL ()); - // @@ RtecEventChannelAdmin::EventChannel::SYNCHRONIZATION_ERROR()); - ACE_CHECK_RETURN (proxy); - - if (all_consumers_.insert (new_consumer.get ()) == -1) - ACE_ERROR ((LM_ERROR, "ACE_ES_Consumer_Module insert failed.\n")); - } - - proxy = new_consumer->_this (ACE_ENV_SINGLE_ARG_PARAMETER); - ACE_CHECK_RETURN (proxy); - - // Give away ownership to the POA.... - new_consumer.release ()->_remove_ref (ACE_ENV_SINGLE_ARG_PARAMETER); - ACE_CHECK_RETURN (proxy); - - return proxy; -} - -void -ACE_ES_Consumer_Module::fill_qos (RtecEventChannelAdmin::ConsumerQOS& c_qos) -{ - ACE_GUARD (ACE_ES_MUTEX, ace_mon, this->lock_); - - c_qos.is_gateway = 1; - - int count = 0; - { - for (Consumer_Iterator i = this->all_consumers_.begin (); - i != this->all_consumers_.end (); - ++i) - { - ACE_Push_Consumer_Proxy *c = *i; - - if (c->qos ().is_gateway) - continue; - - count += c->qos ().dependencies.length (); - } - } - - RtecEventChannelAdmin::DependencySet& dep = c_qos.dependencies; - - dep.length (count + 1); - - CORBA::ULong cc = 0; - dep[cc].event.header.type = ACE_ES_DISJUNCTION_DESIGNATOR; - dep[cc].event.header.source = 0; - dep[cc].event.header.creation_time = ORBSVCS_Time::zero (); - dep[cc].rt_info = 0; - cc++; - - for (Consumer_Iterator i = this->all_consumers_.begin (); - i != this->all_consumers_.end (); - ++i) - { - ACE_Push_Consumer_Proxy *c = *i; - - // ACE_DEBUG ((LM_DEBUG, "EC (%t) fill_qos ")); - // ACE_ConsumerQOS_Factory::debug (c->qos ()); - - if (c->qos ().is_gateway) - continue; - - CORBA::ULong count = c->qos ().dependencies.length (); - for (CORBA::ULong j = 0; j < count; ++j) - { - RtecEventComm::Event& event = - c->qos ().dependencies[j].event; - - RtecEventComm::EventType type = event.header.type; - - // Only type and source dependencies are relevant, notice - // that we turn conjunctions into disjunctions because - // correlations could be satisfied by events coming from - // several remote ECs. - // Notice that <0> is a *not* skipped, otherwise source only - // filtering does not work. - if (1 <= type && type <= ACE_ES_EVENT_UNDEFINED) - continue; - - // If the dependency is already there we don't add it. - CORBA::ULong k; - for (k = 0; k < cc; ++k) - { - if (dep[k].event.header.type == event.header.type - && dep[k].event.header.source == event.header.source) - break; - } - if (k == cc) - { - dep[cc].event.header.type = event.header.type; - dep[cc].event.header.source = event.header.source; - dep[cc].event.header.creation_time = ORBSVCS_Time::zero (); - // The RT_Info is filled up later. - dep[cc].rt_info = 0; - cc++; - } - } - } - dep.length (cc); - - // ACE_DEBUG ((LM_DEBUG, "EC (%t) Consumer::fill_qos - %d\n", cc)); -} - -ACE_ES_Correlation_Module::ACE_ES_Correlation_Module (ACE_EventChannel *channel) - : channel_ (channel), - up_ (0), - subscription_module_ (0) -{ -} - -void -ACE_ES_Correlation_Module::open (ACE_ES_Dispatching_Module *up, - ACE_ES_Subscription_Module *sm) -{ - up_ = up; - subscription_module_ = sm; -} - -void -ACE_ES_Correlation_Module::connected (ACE_Push_Consumer_Proxy *consumer - ACE_ENV_ARG_DECL) -{ - // Initialize the consumer correlation filter. - if (consumer->correlation ().connected (consumer, this) == -1) - ACE_THROW (RtecEventChannelAdmin::EventChannel::CORRELATION_ERROR()); -} - -void -ACE_ES_Correlation_Module::disconnecting (ACE_Push_Consumer_Proxy *consumer - ACE_ENV_ARG_DECL_NOT_USED) -{ - if (consumer->correlation ().disconnecting () == -1) - ACE_ERROR ((LM_ERROR, - "ACE_ES_Correlation_Module::disconnecting failed.\n")); -} - -int -ACE_ES_Correlation_Module::subscribe (ACE_ES_Consumer_Rep *consumer) -{ - return subscription_module_->subscribe (consumer); -} - -int -ACE_ES_Correlation_Module::unsubscribe (ACE_ES_Consumer_Rep *cr) -{ - return subscription_module_->unsubscribe (cr); -} - -void -ACE_ES_Correlation_Module::push (ACE_ES_Consumer_Rep *consumer, - const TAO_EC_Event& event - ACE_ENV_ARG_DECL) -{ - // ACE_DEBUG ((LM_DEBUG, "EC (%t) Correlation_Module::push\n")); - - ACE_TIMEPROBE (TAO_EVENT_CHANNEL_ENTER_ACE_ES_CORRELATION_MODULE_PUSH); - ACE_ES_Dispatch_Request *request = - consumer->correlation ()->push (consumer, event); - ACE_TIMEPROBE (TAO_EVENT_CHANNEL_PUSHED_TO_CORRELATION_MODULE); - - // If request == 0, then the event was queued for later. Otherwise, - // we need to push the event now. - if (request != 0) - { - up_->push (request ACE_ENV_ARG_PARAMETER); - ACE_CHECK; - } - - ACE_TIMEPROBE (TAO_EVENT_CHANNEL_PUSH_SOURCE_TYPE_DISPATCH_MODULE_ENQUEUING); -} - -// Must check consumer->qos ().use_timeout () before calling this. -// This method is supposed properly schedule a timer with respect to -// the consumer's priority AND the correlation that should receive the -// timeout event. -int -ACE_ES_Correlation_Module::schedule_timeout (ACE_ES_Consumer_Rep_Timeout *consumer) -{ - RtecEventComm::Time &interval = - consumer->dependency ()->event.header.creation_time; - RtecEventComm::Time &delay = - consumer->dependency ()->event.header.creation_time; - - // Store the preemption priority so we can cancel the correct timer. - // The priority values may change during the process lifetime (e.g., - // after the scheduler has been run). - consumer->preemption_priority (::IntervalToPriority (interval)); - - // ACE_DEBUG ((LM_DEBUG, - // "EC (%t) Adding timer at preemption %d, rate = (%d,%d)\n", - // consumer->preemption_priority (), - // interval.low, interval.high)); - - // Register the timer. - long id = - this->channel_->schedule_timer (consumer->dependency ()->rt_info, - consumer, - consumer->preemption_priority (), - delay, interval); - - // Store the timer id for canceling. - consumer->timer_id (id); - - if (id == -1) - ACE_ERROR_RETURN ((LM_ERROR, "%p schedule timer failed.\n", - "ACE_ES_Correlation_Module::schedule_timeout"), -1); - - return 0; -} - -// Must check consumer->qos ().timeout_ before calling this. -int -ACE_ES_Correlation_Module::cancel_timeout (ACE_ES_Consumer_Rep_Timeout *consumer) -{ - // Cancel the timer from the Priority Timer. - ACE_Command_Base *act; - this->channel_->cancel_timer (consumer->preemption_priority (), - consumer->timer_id (), - act); - - ACE_ASSERT (consumer == act); - - // Free up the Timer ACT. - // delete act; - - return 0; -} - - -int -ACE_ES_Correlation_Module::reschedule_timeout (ACE_ES_Consumer_Rep_Timeout *consumer) -{ - if (this->cancel_timeout (consumer) == -1) - ACE_ERROR_RETURN ((LM_ERROR, "%p.\n", "ACE_ES_Disjunction_Group::reschedule_deadline"), -1); - else - { - RtecEventComm::Time &interval = - consumer->dependency ()->event.header.creation_time; - RtecEventComm::Time &delay = - consumer->dependency ()->event.header.creation_time; - - // Store the preemption priority so we can cancel the correct timer. - // The priority values may change during the process lifetime (e.g., - // after the scheduler has been run). - consumer->preemption_priority (::IntervalToPriority (interval)); - - // Register the timer. - long id = - this->channel_->schedule_timer (0, // Do not pass an RT_Info. - consumer, - consumer->preemption_priority (), - delay, interval); - - // Store the timer id for canceling. - consumer->timer_id (id); - - if (id == -1) - ACE_ERROR_RETURN ((LM_ERROR, "%p schedule timer failed.\n", - "ACE_ES_Correlation_Module::reschedule_timeout"), -1); - - return 0; - } -} - -void -ACE_ES_Correlation_Module::shutdown (void) -{ - // Perhaps this should call disconnecting on all the consumers? - // We'll opt to just forward this message for now. - up_->shutdown (); -} - -ACE_ES_Consumer_Correlation::ACE_ES_Consumer_Correlation (void) : - correlation_module_ (0), - type_id_index_ (0), - channel_ (0), - qos_ (), - pending_events_ (0), - lock_ (), - consumer_ (0), - pending_flags_ (0), - consumer_reps_ (0), - n_consumer_reps_ (0), - timer_reps_ (0), - n_timer_reps_ (0), - conjunction_groups_ (0), - n_conjunction_groups_ (0), - disjunction_groups_ (0), - n_disjunction_groups_ (0), - connected_ (0) -{ -} - -ACE_ES_Consumer_Correlation::~ACE_ES_Consumer_Correlation (void) -{ - delete [] timer_reps_; - for (int i = 0; i < this->n_consumer_reps_; ++i) - { - ACE_ES_Consumer_Rep *r = this->consumer_reps_[i]; - if (r != 0) - { - this->correlation_module_->unsubscribe (r); - r->_release (); - } - } - delete [] consumer_reps_; - delete [] conjunction_groups_; - delete [] disjunction_groups_; - delete [] pending_events_; -} - -void -ACE_ES_Consumer_Correlation::disconnect_push_supplier (ACE_ENV_SINGLE_ARG_DECL_NOT_USED) - ACE_THROW_SPEC ((CORBA::SystemException)) -{ - this->connected_ = 0; -} - -int -ACE_ES_Consumer_Correlation::allocate_correlation_resources (ACE_ES_Dependency_Iterator &iter) -{ - n_conjunction_groups_ = iter.n_conjunctions (); - if (n_conjunction_groups_ > 0) - { - conjunction_groups_ = new ACE_ES_Conjunction_Group[n_conjunction_groups_]; - if (conjunction_groups_ == 0) - ACE_ERROR_RETURN ((LM_ERROR, "%p.\n", - "ACE_ES_Consumer_Correlation::" - "allocate_correlation_resources"), -1); - for (int n=0; n < n_conjunction_groups_; n++) - conjunction_groups_[n].set_correlation_module (correlation_module_); - } - - n_disjunction_groups_ = iter.n_disjunctions (); - if (n_disjunction_groups_ > 0) - { - disjunction_groups_ = new ACE_ES_Disjunction_Group[n_disjunction_groups_]; - if (disjunction_groups_ == 0) - ACE_ERROR_RETURN ((LM_ERROR, "%p.\n", - "ACE_ES_Consumer_Correlation::" - "allocate_correlation_resources"), -1); - for (int n=0; n < n_disjunction_groups_; n++) - disjunction_groups_[n].set_correlation_module (correlation_module_); - } - - n_consumer_reps_ = iter.n_events (); - if (n_consumer_reps_ > 0) - { - // This allocates more than is needed if there are repeats: - // (A+B)|(B+C). We allocate these individually so that they can - // be deleted individually. - - typedef ACE_ES_Consumer_Rep *reparray; - consumer_reps_ = new reparray[n_consumer_reps_]; - - for (int cr = 0; cr < n_consumer_reps_; cr++) - { - consumer_reps_[cr] = new ACE_ES_Consumer_Rep; - if (consumer_reps_[cr] == 0) - ACE_ERROR_RETURN ((LM_ERROR, "%p.\n", - "ACE_ES_Consumer_Correlation::" - "allocate_correlation_resources"), -1); - } - } - - n_timer_reps_ = iter.n_timeouts (); - if (n_timer_reps_ > 0) - { - timer_reps_ = new ACE_ES_Consumer_Rep_Timeout[n_timer_reps_]; - if (timer_reps_ == 0) - ACE_ERROR_RETURN ((LM_ERROR, "%p.\n", - "ACE_ES_Consumer_Correlation::" - "allocate_correlation_resources"), -1); - } - - // This allocates more than is needed. - // @@ throw an exception. - ACE_NEW_RETURN (this->pending_events_, - TAO_EC_Event_Array[n_consumer_reps_ + n_timer_reps_], - -1); - - return 0; -} - -// We don't need synchronization until after we've been connected and -// subscribed to events. -int -ACE_ES_Consumer_Correlation::connected (ACE_Push_Consumer_Proxy *consumer, - ACE_ES_Correlation_Module *correlation_module) -{ - correlation_module_ = correlation_module; - consumer_ = consumer; - - // for (CORBA_Types::ULong index=0; index < consumer->qos ().dependencies_.length (); index++) - // consumer->qos ().dependencies_[index].event.dump (); - - ACE_ES_Dependency_Iterator iter (consumer->qos ().dependencies); - iter.parse (); - if (this->allocate_correlation_resources (iter) == -1) - return -1; - - - int cgroup_index = -1; - int dgroup_index = -1; - int crep_index = 0; - int trep_index = 0; - RtecEventComm::EventType group_type = 0; - - while (iter.advance_dependency () == 0) - { - // Keep track of how many conjunction and disjunction groups are - // registered. Update the index pointers so that the helper - // functions can update the appropriate group objects. - switch ((*iter).event.header.type) - { - case ACE_ES_CONJUNCTION_DESIGNATOR: - cgroup_index++; - ACE_ASSERT (cgroup_index < n_conjunction_groups_); - group_type = ACE_ES_CONJUNCTION_DESIGNATOR; - continue; - - case ACE_ES_DISJUNCTION_DESIGNATOR: - dgroup_index++; - ACE_ASSERT (dgroup_index < n_disjunction_groups_); - group_type = ACE_ES_DISJUNCTION_DESIGNATOR; - continue; - - case ACE_ES_GLOBAL_DESIGNATOR: - group_type = ACE_ES_GLOBAL_DESIGNATOR; - continue; - - // These Delegate to the appropriate registration method. -#if 0 - // @@ TODO rt_info_ is a handle_t now, does checking against - // 0 still make sense? - // Check for a null rt_info. - if ((*iter).rt_info_ == 0) - { - ACE_ERROR ((LM_ERROR, "Found a ConsumerQOS::dependencies[].rt_info_ == 0.\n")); - continue; - } -#endif /* 0 */ - - case ACE_ES_EVENT_TIMEOUT: - // For backwards compatibility. - case ACE_ES_EVENT_DEADLINE_TIMEOUT: - if (this->register_deadline_timeout (*iter, - group_type, - cgroup_index, - dgroup_index, - trep_index) == -1) - return -1; - break; - - case ACE_ES_EVENT_INTERVAL_TIMEOUT: - if (this->register_interval_timeout (*iter, - group_type, - cgroup_index, - dgroup_index, - trep_index) == -1) - return -1; - break; - - case ACE_ES_EVENT_ACT: - // Store the ACT in the current conjunction or disjunction - // group. - switch (group_type) - { - case ACE_ES_CONJUNCTION_DESIGNATOR: - conjunction_groups_[cgroup_index].set_act ((*iter).event); - break; - case ACE_ES_DISJUNCTION_DESIGNATOR: - disjunction_groups_[cgroup_index].set_act ((*iter).event); - break; - case ACE_ES_GLOBAL_DESIGNATOR: - default: - ACE_ERROR ((LM_ERROR, "Warning: ACTs not implemented for Global.\n")); - } - break; - - default: - // Non-timer event subscription. - if (this->register_event (*iter, - group_type, - cgroup_index, - dgroup_index, - crep_index) == -1) - return -1; - break; - } - } - - // We may not use all of the consumer reps if there are repeats: - // (A+B)|(B+C). Must update n_consumer_reps_ so we don't try to - // unsubscribe a blank rep during disconnect. - if (crep_index < n_consumer_reps_) - n_consumer_reps_ = crep_index; - - return 0; -} - -int -ACE_ES_Consumer_Correlation::register_deadline_timeout (RtecEventChannelAdmin::Dependency &dependency, - RtecEventComm::EventType group_type, - int cgindex, - int dgindex, - int &trep_index) -{ - // new_timeout will be returned as an ACT. When executed, it will - // forward *iter.event_ to the consumer. - ACE_ES_Consumer_Rep_Timeout *new_timeout = &timer_reps_[trep_index++]; - new_timeout->init (this, dependency); - new_timeout->correlation_type (ACE_ES_Consumer_Rep::DEADLINE_TIMEOUT); - // Deadline timers do not need type ids. - - switch (group_type) - { - case ACE_ES_CONJUNCTION_DESIGNATOR: - // Reps keep pointers back to the groups that they're deadlines for. - new_timeout->add_disjunction_group (conjunction_groups_[cgindex]); - // Groups keep references to the deadline timers for rescheduling. - if (conjunction_groups_[cgindex].set_deadline_timeout (new_timeout) == -1) - return -1; - break; - - case ACE_ES_DISJUNCTION_DESIGNATOR: - new_timeout->add_disjunction_group (disjunction_groups_[dgindex]); - if (disjunction_groups_[dgindex].set_deadline_timeout (new_timeout) == -1) - return -1; - break; - - case ACE_ES_GLOBAL_DESIGNATOR: - ACE_ERROR_RETURN ((LM_ERROR, "No global deadline timeouts, yet!\n"), -1); - } - - return 0; -} - -int -ACE_ES_Consumer_Correlation::register_interval_timeout (RtecEventChannelAdmin::Dependency &dependency, - RtecEventComm::EventType group_type, - int cgindex, - int /* dgindex */, - int &trep_index) -{ - // new_timeout will be returned as an ACT. When executed, it will - // forward *iter.event_ to the consumer. - ACE_ES_Consumer_Rep_Timeout *new_timeout = &timer_reps_[trep_index++]; - new_timeout->init (this, dependency); - new_timeout->type_id (this->new_type_id ()); - - switch (group_type) - { - case ACE_ES_CONJUNCTION_DESIGNATOR: - // If it's a conjunction, then we need to perform correlations - // on the timeout. - new_timeout->correlation_type (ACE_ES_Consumer_Rep::CORRELATE); - conjunction_groups_[cgindex].add_type (new_timeout->type_id ()); - break; - - case ACE_ES_DISJUNCTION_DESIGNATOR: - case ACE_ES_GLOBAL_DESIGNATOR: - new_timeout->correlation_type (ACE_ES_Consumer_Rep::NO_CORRELATION); - break; - } - - // Schedule the timeout. - if (correlation_module_->schedule_timeout (new_timeout) == -1) - return -1; - else - return 0; -} - -// Search <creps> for a rep matching <dependency>. If one is not -// found, allocate one. All returned reps should have the appropriate -// type_id set. -ACE_ES_Consumer_Rep * -ACE_ES_Consumer_Correlation::get_consumer_rep (RtecEventChannelAdmin::Dependency &dependency, - int &crep_index) -{ - ACE_ES_Consumer_Rep *rep = 0; - - // Step through all existing consumer reps. - for (int x=0; x < crep_index; x++) - { - RtecEventComm::Event& e = consumer_reps_[x]->dependency ()->event; - // If <dependency> matches any previously subscribed consumer - // reps, we'll reuse it. - if (e.header.type == dependency.event.header.type - && e.header.source == dependency.event.header.source ) - { - rep = consumer_reps_[x]; - break; - } - } - - // Check if we didn't find it. - if (rep == 0) - { - if (crep_index >= n_consumer_reps_) - ACE_ERROR_RETURN ((LM_ERROR, "Too many event registrations.\n"), 0); - // Allocate a new rep and set its type id. - rep = consumer_reps_[crep_index]; - crep_index++; - rep->init (this, dependency); - rep->type_id (this->new_type_id ()); - } - - return rep; -} - -int -ACE_ES_Consumer_Correlation::new_type_id (void) -{ - int type_id = type_id_index_; - if (++type_id_index_ >= ACE_ES_MAX_SUBSCRIPTIONS) - ACE_ERROR_RETURN ((LM_ERROR, "ACE_ES_MAX_SUBSCRIPTIONS exceeded.\n"),0); - else - return type_id; -} - -int -ACE_ES_Consumer_Correlation::register_event (RtecEventChannelAdmin::Dependency &dependency, - RtecEventComm::EventType group_type, - int cgindex, - int dgindex, - int &crep_index) -{ - // These are stored in the subscription module data structures. - ACE_ES_Consumer_Rep *consumer_rep = this->get_consumer_rep (dependency, crep_index); - - if (consumer_rep == 0) - ACE_ERROR_RETURN ((LM_ERROR, "%p.\n", - "ACE_ES_Consumer_Correlation::register_event"), -1); - - switch (group_type) - { - case ACE_ES_CONJUNCTION_DESIGNATOR: - // If it's a conjunction, then we need to perform correlations - // on the object. Otherwise, NO_CORRELATION is set by default. - consumer_rep->correlation_type (ACE_ES_Consumer_Rep::CORRELATE); - conjunction_groups_[cgindex].add_type (consumer_rep->type_id ()); - break; - - case ACE_ES_DISJUNCTION_DESIGNATOR: - consumer_rep->add_disjunction_group (disjunction_groups_[dgindex]); - break; - - case ACE_ES_GLOBAL_DESIGNATOR: - ACE_ERROR ((LM_ERROR, "ACE_ES_Consumer_Correlation::register_event: " - "ACE_ES_GLOBAL_DESIGNATOR not implemented.\n")); - break; - } - - // Subscribe the consumer_rep to the suppliers. - if (correlation_module_->subscribe (consumer_rep) == -1) - return -1; - else - return 0; -} - -int -ACE_ES_Consumer_Correlation::disconnecting (void) -{ - // If we were forwarding events, disconnect as a supplier. - if (connected_) - { - ACE_DECLARE_NEW_CORBA_ENV; - ACE_TRY - { - channel_->disconnect_push_consumer (ACE_ENV_SINGLE_ARG_PARAMETER); - ACE_TRY_CHECK; - } - ACE_CATCHANY - { - ACE_PRINT_EXCEPTION (ACE_ANY_EXCEPTION, - "ACE_ES_Consumer_Correlation::" - "disconnecting failed.\n"); - } - ACE_ENDTRY; - } - - for (int j = 0; j < this->n_timer_reps_; ++j) - this->correlation_module_->cancel_timeout (&timer_reps_[j]); - - for (int i = 0; i < this->n_consumer_reps_; ++i) - { - ACE_ES_Consumer_Rep *r = this->consumer_reps_[i]; - if (r != 0) - { - r->disconnect (); - } - } - - return 0; -} - -ACE_ES_Dispatch_Request * -ACE_ES_Consumer_Correlation::push (ACE_ES_Consumer_Rep *cr, - const TAO_EC_Event& event) -{ - // ACE_DEBUG ((LM_DEBUG, "EC (%t) Consumer_Correlation_Module::push\n")); - - ACE_TIMEPROBE (TAO_EVENT_CHANNEL_ACE_ES_CONSUMER_CORRELATION_PUSH_ENTER); - - // Check if this event needs any correlating, or if it should just - // be forwarded real fast-like. - switch (cr->correlation_type ()) - { - case ACE_ES_Consumer_Rep::NO_CORRELATION: - { - // Calls reschedule on all disjunction groups it belongs to. - cr->reschedule_deadlines (); - - ACE_TIMEPROBE (TAO_EVENT_CHANNEL_CONSUMER_CORRELATION_PUSH_DETERMINE_NO_CORR); - ACE_ES_Dispatch_Request *request = - new ACE_ES_Dispatch_Request (consumer_, event, - cr->dependency ()->rt_info); - ACE_TIMEPROBE (TAO_EVENT_CHANNEL_CONSUMER_CORRELATION_PUSH_NO_CORR_ALLOC); - - if (request == 0) - ACE_ERROR_RETURN ((LM_ERROR, "%p.\n", - "ACE_ES_Consumer_Correlation::push"), 0); - - return request; - } - - case ACE_ES_Consumer_Rep::CORRELATE: - return this->correlate (cr, event); - - case ACE_ES_Consumer_Rep::DEADLINE_TIMEOUT: - { - ACE_ES_Dispatch_Request *request = - new ACE_ES_Dispatch_Request (consumer_, - cr->dependency ()->rt_info); - - if (request == 0) - ACE_ERROR_RETURN ((LM_ERROR, "%p.\n", - "ACE_ES_Consumer_Correlation::push"), 0); - - // Add the deadline timeout to the outbox. - request->append_event (event); - - // Add any pending events to the outbox. - cr->top_group ()->add_events (&(request->event_set ()), - pending_events_, pending_flags_); - - return request; - } - - default: - ACE_ERROR_RETURN ((LM_ERROR, "ACE_ES_Consumer_Correlation::push:" - " unknown correlation type\n"), 0); - } -} - -// @@ If we're just event forwarding, then no pending_events_ need to -// be kept! I'll add this optimization later. -ACE_ES_Dispatch_Request * -ACE_ES_Consumer_Correlation::correlate (ACE_ES_Consumer_Rep *cr, - const TAO_EC_Event &event) -{ - // If the consumer has specified correlation criteria, then we must - // first acquire the mutex. - ACE_Guard<ACE_ES_MUTEX> ace_mon (lock_); - if (ace_mon.locked () == 0) - ACE_ERROR_RETURN ((LM_ERROR, "%p.\n", - "ACE_ES_Consumer_Correlation::push"), 0); - - int bit = ACE_INT2BIT[cr->type_id ()]; - if (ACE_BIT_DISABLED (this->pending_flags_, bit)) - { - // Add the new event to the pending events. - pending_events_[cr->type_id ()] += event; - // Set the bit corresponding to the arrived event. - // This should be pending_flags_->event_arrived (index); - ACE_SET_BITS (pending_flags_, bit); - } - - ACE_ES_Dispatch_Request *request = 0; - TAO_EC_Event_Array *outbox = 0; - // Since add_events changes pending_flags_, we need to keep this - // for all iterations through the conjunction groups. - u_long freeze_pending_flags = pending_flags_; - - for (int x=0; x < n_conjunction_groups_; x++) - { - if (conjunction_groups_[x].should_forward (freeze_pending_flags)) - { - // If there is a deadline timer for this conjunction group, - // this will reschedule them. - conjunction_groups_[x].reschedule_deadline (); - - // First time in, allocate the new dispatch request. - if (request == 0) - { - request = - new ACE_ES_Dispatch_Request (consumer_, - cr->dependency ()->rt_info); - if (request == 0) - ACE_ERROR_RETURN ((LM_ERROR, "%p.\n", - "ACE_ES_Consumer_Correlation::correlate"), 0); - outbox = &(request->event_set ()); - } - - // Add each of the pending events for this correlation to - // the outgoing dispatch request. If outbox == 0, then - // this will just clear any pending events. - conjunction_groups_[x].add_events (outbox, - pending_events_, - pending_flags_); - } - } - - return request; -} - -ACE_ES_Consumer_Rep::~ACE_ES_Consumer_Rep (void) -{ -} - -int -ACE_ES_Consumer_Rep::execute (void* /* arg */) -{ - ACE_ERROR ((LM_ERROR, "Warning! ACE_ES_Consumer_Rep::execute called.\n")); - return -1; -} - -int -ACE_ES_Consumer_Rep_Timeout::execute (void* /* arg */) -{ - ACE_TIMEPROBE (TAO_EVENT_CHANNEL_CONSUMER_REP_TIMEOUT_EXECUTE); - if (this->receiving_events ()) - { - ACE_DECLARE_NEW_CORBA_ENV; - ACE_TRY - { - ACE_Time_Value tv = ACE_OS::gettimeofday (); - ORBSVCS_Time::Time_Value_to_TimeT (this->timeout_event_.header ().creation_time, tv); - correlation_->correlation_module_->push (this, - this->timeout_event_ - ACE_ENV_ARG_PARAMETER); - ACE_TRY_CHECK; - } - ACE_CATCHANY - { - ACE_PRINT_EXCEPTION (ACE_ANY_EXCEPTION, - "ACE_ES_Consumer_Rep_Timeout::execute: " - "unexpected exception.\n"); - } - ACE_ENDTRY; - } - return 0; -} - -ACE_ES_Subscription_Module::ACE_ES_Subscription_Module (ACE_EventChannel *channel) - : channel_ (channel), - up_ (0), - down_ (0) -{ - this->scheduler_ = this->channel_->scheduler (); -} - -void -ACE_ES_Subscription_Module::open (ACE_ES_Correlation_Module *up, - ACE_ES_Supplier_Module *down) -{ - // Brilliant. - up_ = up; - down_ = down; -} - -ACE_ES_Subscription_Module::~ACE_ES_Subscription_Module (void) -{ -} - -// When a supplier connects, we step through each of its -// publications. For each event type published, we allocate a set in -// the suppliers type collection. Then we build a subscribers list -// starting with any consumers having a type-based subscription in the -// global type collection. -void -ACE_ES_Subscription_Module::connected (ACE_Push_Supplier_Proxy *supplier - ACE_ENV_ARG_DECL) -{ - RtecEventComm::EventSourceID sid = 0; - // We will record the source_id for later usage. - { - ACE_ES_WGUARD ace_mon (lock_); - if (ace_mon.locked () == 0) - ACE_THROW (RtecEventChannelAdmin::EventChannel::SYNCHRONIZATION_ERROR()); - - if (all_suppliers_.insert (supplier) == -1) - ACE_ERROR ((LM_ERROR, "ACE_ES_Subscription_Module insert failed.\n")); - - // For every type that this supplier generates, bind a new - // Type_Subscribers to the type in the supplier proxy's type - // collection. - RtecEventChannelAdmin::PublicationSet &publications = - supplier->qos ().publications; - - sid = publications[0].event.header.source; - for (CORBA::ULong index=0; index < publications.length (); index++) - { - // Check to make sure an RT_Info was specified. -#if 0 - // @@ TODO: We should check if rt_info is a valid handle_t. - if (publications[index].dependency_info_.rt_info.value() == 0) - { - ACE_ERROR ((LM_ERROR, "Found a SupplierQOS::dependency_info_.rt_info_ == 0\n")); - continue; - } -#endif - - RtecEventComm::EventType event_type = - publications[index].event.header.type; - - // @@ TODO we should throw something Check to make sure a type - // was specified. - if (event_type == ACE_ES_EVENT_ANY) - { - ACE_ERROR ((LM_ERROR, "ACE_ES_Subscription_Module::connected: " - "source is publishing ACE_ES_EVENT_ANY.\n")); - continue; - } - - // Make a new set for the proxy. Include the dependency - // info describing the RT_Method that generates this event. - // This object will hold all the consumers that subscribe to - // this publication. - ACE_ES_Subscription_Info::Type_Subscribers *new_subscribers = - new ACE_ES_Subscription_Info::Type_Subscribers (&(publications[index].dependency_info)); - - if (new_subscribers == 0) - { - ACE_ERROR ((LM_ERROR, "%p.\n", "ACE_ES_Subscription_Module::connected")); - return; - } - - // Check the global type collection for consumers that register - // before suppliers. - ACE_ES_Subscription_Info::Type_Subscribers *existing_subscribers; - if (type_subscribers_.find (event_type, existing_subscribers) != -1) - { - // Iterate through existing subscribers. - ACE_ES_Subscription_Info::Subscriber_Set_Iterator iter (existing_subscribers->consumers_); - - for (ACE_ES_Consumer_Rep **proxy = 0; - iter.next (proxy) != 0; - iter.advance ()) - { - // Each existing subscriber will get appended to the - // new subscribers list. Dependencies are updated. - - // @@ TODO: Handle exceptions. -#if 1 - this->scheduler_->add_dependency - ((*proxy)->dependency()->rt_info, - new_subscribers->dependency_info_->rt_info, - new_subscribers->dependency_info_->number_of_calls, - RtecBase::ONE_WAY_CALL - ACE_ENV_ARG_PARAMETER); -#else - ACE_Scheduler_Factory::server()->add_dependency - ((*proxy)->dependency()->rt_info, - new_subscribers->dependency_info_->rt_info, - new_subscribers->dependency_info_->number_of_calls, - RtecBase::ONE_WAY_CALL - ACE_ENV_ARG_PARAMETER); -#endif - ACE_CHECK; - - if (new_subscribers->consumers_.insert (*proxy) == -1) - { - ACE_ERROR ((LM_ERROR, - "%p: add_dependency/insert failed.\n", - "ACE_ES_Subscription_Module::connected")); - continue; - } - (*proxy)->_duplicate (); - } - } -#if 0 - else - { - //ACE_DEBUG ((LM_DEBUG, - // "EC (%t) No consumers for type %d\n", event_type)); - } -#endif - - // Put the new subscribers for this event type in the supplier - // proxy's type map. - if (supplier->subscription_info ().type_subscribers_. - bind (event_type, new_subscribers) != 0) - { - // This may occur with a double bind, I think. - ACE_ERROR ((LM_ERROR, "%p can't initialize type.\n", - "ACE_ES_Subscription_Module::connected")); - delete new_subscribers; - continue; - } - } - } // release lock - - // Reregister any consumers that tried to subscribe before this - // supplier connected. - // NOTE: We used to call back the supplier here (using - // supplier->source_id()), this is ineffective and leads to all kind - // of dead-locks (the supplier is blocked and waiting for us). - // We use the information on the publications to get the source_id. - this->reregister_consumers (sid); -} - -// Step through each of the source_subscribers looking for consumers -// that registered for <source> before <source> connected. -void -ACE_ES_Subscription_Module::reregister_consumers (RtecEventComm::EventSourceID source_id) -{ - ACE_ES_Subscription_Info::Subscriber_Set *subscribers = 0; - if (source_subscribers_.find (source_id, subscribers) == -1) - // Not found. - return; - - ACE_ES_Subscription_Info::Subscriber_Set_Iterator iter (*subscribers); - - // Try to reregister all consumers. - for (ACE_ES_Consumer_Rep **consumer = 0; - iter.next (consumer) != 0; - iter.advance ()) - if (this->subscribe (*consumer) == -1) - ACE_ERROR ((LM_ERROR, "%p.\n" "ACE_ES_Subscription_Module::reregister_consumers")); -} - - -void -ACE_ES_Subscription_Module::disconnecting (ACE_Push_Supplier_Proxy *supplier - ACE_ENV_ARG_DECL) -{ - ACE_WRITE_GUARD_THROW_EX ( - ACE_ES_RW_LOCK, ace_mon, this->lock_, - RtecEventChannelAdmin::EventChannel::SYNCHRONIZATION_ERROR()); - ACE_CHECK; - - if (all_suppliers_.remove (supplier) == -1) - ACE_THROW (RtecEventChannelAdmin::EventChannel::SUBSCRIPTION_ERROR()); - - // Remove all consumers from the supplier's source-based subscription lists. - ACE_ES_Subscription_Info::Subscriber_Set_Iterator source_iterator - (supplier->subscription_info ().source_subscribers_); - - for (ACE_ES_Consumer_Rep **consumer; - source_iterator.next (consumer) != 0; - source_iterator.advance ()) - { - (*consumer)->_release (); - } - - // Get the subscriber list for each type. - ACE_ES_Subscription_Info::Subscriber_Map_Iterator type_map_iterator - (supplier->subscription_info ().type_subscribers_); - - for (ACE_ES_Subscription_Info::Subscriber_Map_Entry *entry; - type_map_iterator.next (entry) != 0; - type_map_iterator.advance ()) - { - // Remove all consumers from the supplier's source-based - // subscription lists. - ACE_ES_Subscription_Info::Subscriber_Set_Iterator type_iterator - (entry->int_id_->consumers_); - - for (ACE_ES_Consumer_Rep **c; - type_iterator.next (c) != 0; - type_iterator.advance ()) - { - (*c)->_release (); - } - } -} - -int -ACE_ES_Subscription_Module::subscribe_all (ACE_ES_Consumer_Rep *) -{ - ACE_ERROR_RETURN ((LM_ERROR, "Consumer tried to register for all" - "events! This is not implemented.\n"), -1); -} - -// Forward <events> to all consumers subscribed to <source> only. -int -ACE_ES_Subscription_Module::push_source (ACE_Push_Supplier_Proxy *source, - const TAO_EC_Event &event - ACE_ENV_ARG_DECL) -{ - // ACE_DEBUG ((LM_DEBUG, "EC (%t) Subscription_Module::push_source\n")); - - ACE_TIMEPROBE (TAO_EVENT_CHANNEL_ENTER_ACE_ES_SUBSCRIPTION_MODULE_PUSH); - // If there are now source-based subscribers for this supplier, - // return. - if (source->subscription_info ().source_subscribers_.size () == 0) - return 0; - - ACE_ES_Subscription_Info::Subscriber_Set &set = - source->subscription_info ().source_subscribers_; - - // List of consumers that need to be disconnected. - ACE_ES_Subscription_Info::Subscriber_Set disconnect_list; - - { - // Acquire a read lock. - ACE_ES_RGUARD ace_mon (source->subscription_info ().lock_); - if (ace_mon.locked () == 0) - ACE_ERROR_RETURN ((LM_ERROR, - "ACE_ES_Subscription_Module::push_source.\n"), -1); - - ACE_ES_Subscription_Info::Subscriber_Set_Iterator iter (set); - - // Iterate through all subscribers. - for (ACE_ES_Consumer_Rep **consumer = 0; - iter.next (consumer) != 0; - iter.advance ()) - { - // Only push the event if the consumer is not suspended - // and not disconnected. - if ((*consumer)->receiving_events ()) - { - up_->push (*consumer, event ACE_ENV_ARG_PARAMETER); - ACE_CHECK_RETURN (-1); - } - // If the consumer has disconnected, schedule it for - // disconnection. We can not modify our list now. It - // would mess up the iterator. - if ((*consumer)->disconnected ()) - disconnect_list.insert (*consumer); - } - // Release the read lock. - } - - // If there are consumers scheduled for disconnect, acquire a write - // lock and disconnect them. - if (disconnect_list.size () != 0) - { - ACE_ES_WGUARD ace_mon (source->subscription_info ().lock_); - if (ace_mon.locked () == 0) - ACE_ERROR_RETURN ((LM_ERROR, - "ACE_ES_Subscription_Module::push_source.\n"), -1); - - // Iterate through the disconnecting consumers. - for (ACE_ES_Subscription_Info::Subscriber_Set_Iterator iter = - disconnect_list.begin (), - end = disconnect_list.end (); - iter != end; - iter++) - { - ACE_ES_Consumer_Rep *consumer = (*iter); - // Remove the consumer from subscriber list. - if (set.remove (consumer) == -1) - ACE_ERROR ((LM_ERROR, "%p remove failed.\n", - "ACE_ES_Subscription_Module::push_source.\n")); - else - // Decrement the consumer rep's reference count. - consumer->_release (); - } - } - - return 0; -} - -// 1. figure out why we're going through the subscription module, -// instead of just passing through. -// 2. where is lock_? Is there only one per module!? - -int -ACE_ES_Subscription_Module::push_source_type (ACE_Push_Supplier_Proxy *source, - const TAO_EC_Event &event - ACE_ENV_ARG_DECL) -{ - // ACE_DEBUG ((LM_DEBUG, - // "EC (%t) Subscription_Module::push_source_type: \n")); - - // Step through each event in the set. For each event type, find - // the corresponding set in the type collection. Push the single - // event to each consumer in the set. - - ACE_ES_Subscription_Info::Subscriber_Map &supplier_map = - source->subscription_info ().type_subscribers_; - - ACE_ES_Subscription_Info::Subscriber_Set disconnect_list; - - ACE_ES_Subscription_Info::Subscriber_Set *set; - - { - ACE_ES_RGUARD ace_mon (source->subscription_info ().lock_); - if (ace_mon.locked () == 0) - { - ACE_TIMEPROBE (TAO_EVENT_CHANNEL_PUSH_SOURCE_TYPE); - ACE_ERROR_RETURN ((LM_ERROR, - "ACE_ES_Subscription_Module::" - "push_source_type.\n"), -1); - } - - ACE_ES_Subscription_Info::Type_Subscribers *subscribers; - - if (supplier_map.current_size () == 0) - { - ACE_TIMEPROBE (TAO_EVENT_CHANNEL_PUSH_SOURCE_TYPE); - // ACE_DEBUG ((LM_DEBUG, "EC (%t) Subscription_Module::" - // "push_source_type - empty supplier map\n")); - return 0; - } - - if (supplier_map.find (event.header ().type, subscribers) == -1) - { - ACE_DEBUG ((LM_ERROR, - "EC (%t) ACE_ES_Subscription_Module::push_source_type" - " Warning: event type %d not registered.\n", - event.header ().type)); - ACE_TIMEPROBE (TAO_EVENT_CHANNEL_PUSH_SOURCE_TYPE); - return 0; // continue anyway - } - - if (subscribers->consumers_.size () == 0) - { - // ACE_DEBUG ((LM_DEBUG, "EC (%t) Subscription_Module::" - // "push_source_type - empty consumer set for %d\n", - // event->type_)); - ACE_TIMEPROBE (TAO_EVENT_CHANNEL_PUSH_SOURCE_TYPE); - return 0; - } - - set = &subscribers->consumers_; - - // We've found the set of consumers subscribed to this type - // of event from this supplier. Forward the event to each. - ACE_ES_Subscription_Info::Subscriber_Set_Iterator iter (*set); - - for (ACE_ES_Consumer_Rep **consumer = 0; - iter.next (consumer) != 0; - iter.advance ()) - { - if ((*consumer)->receiving_events ()) - { - up_->push (*consumer, event ACE_ENV_ARG_PARAMETER); - ACE_CHECK_RETURN (-1); - } - if ((*consumer)->disconnected ()) - { - disconnect_list.insert (*consumer); - } - } - } - - // Acquire a write lock and remove all disconnected consumers. - if (disconnect_list.size () != 0) - { - // ACE_DEBUG ((LM_DEBUG, - // "EC (%t) Subscription_Module::push_source_type" - // " - disconnecting consumers\n")); - ACE_ES_WGUARD ace_mon (source->subscription_info ().lock_); - if (ace_mon.locked () == 0) - ACE_ERROR_RETURN ((LM_ERROR, - "ACE_ES_Subscription_Module::" - "push_source.\n"), -1); - - for (ACE_ES_Subscription_Info::Subscriber_Set_Iterator iter = - disconnect_list.begin (), - disconnect_list_end = disconnect_list.end (); - iter != disconnect_list_end; - iter++) - { - ACE_ES_Consumer_Rep *consumer = (*iter); - if (set->remove (consumer) == -1) - ACE_ERROR ((LM_ERROR, "%p remove failed.\n", - "ACE_ES_Subscription_Module::push_source.\n")); - else - consumer->_release (); - // ACE_DEBUG ((LM_DEBUG, "EC (%t) Subscription_Module::" - // "push_source_type - consumer %x removed\n", - // *Consumer)); - } - } - - ACE_TIMEPROBE (TAO_EVENT_CHANNEL_PUSH_SOURCE_TYPE); - return 0; -} - -int -ACE_ES_Subscription_Module::subscribe_source (ACE_ES_Consumer_Rep *consumer, - RtecEventComm::EventSourceID source) -{ - // Step through all Supplier Proxies looking for a match to - // -supplier-. Add the -consumer- to the correct supplier proxy. - Supplier_Iterator iter (all_suppliers_); - - for (ACE_Push_Supplier_Proxy **proxy = 0; - iter.next (proxy) != 0; - iter.advance ()) - { - // Operator == checks if <proxy> is a proxy for <supplier>. - if (!((**proxy) == source)) - continue; - - ACE_WRITE_GUARD_RETURN (ACE_ES_RW_LOCK, mon, - (*proxy)->subscription_info ().lock_, - -1); - - ACE_ES_Subscription_Info::Subscriber_Set &set = - (*proxy)->subscription_info ().source_subscribers_; - - // Insert the consumer to the supplier's subscription set for - // the type. - int insert_result = set.insert (consumer); - switch (insert_result) - { - case -1: - // Error. - ACE_ERROR_RETURN ((LM_ERROR, "%p.\n", - "Subscription Module::subscribe_source"), -1); - case 1: - // Already there. - break; - case 0: - default: - { - // Increment the consumer rep's reference count. - consumer->_duplicate (); - - // Add each of the supplier's dependency infos to the - // consumer's dependency list. - ACE_ES_Subscription_Info::Subscriber_Map_Iterator iter2 - ((*proxy)->subscription_info ().type_subscribers_); - - // Delete all type collections. - for (ACE_ES_Subscription_Info::Subscriber_Map_Entry *temp = 0; - iter2.next (temp) != 0; - iter2.advance ()) - { - ACE_DECLARE_NEW_CORBA_ENV; - ACE_TRY - { -#if 1 - this->scheduler_->add_dependency - (consumer->dependency()->rt_info, - temp->int_id_->dependency_info_->rt_info, - temp->int_id_->dependency_info_->number_of_calls, - RtecBase::ONE_WAY_CALL - ACE_ENV_ARG_PARAMETER); -#else - ACE_Scheduler_Factory::server()->add_dependency - (consumer->dependency()->rt_info, - temp->int_id_->dependency_info_->rt_info, - temp->int_id_->dependency_info_->number_of_calls, - RtecBase::ONE_WAY_CALL - ACE_ENV_ARG_PARAMETER); -#endif - ACE_TRY_CHECK; - } - ACE_CATCHANY - { - ACE_PRINT_EXCEPTION (ACE_ANY_EXCEPTION, - "error adding dependency"); - return -1; - } - ACE_ENDTRY; - } - } - } - } - - return ACE_ES_Subscription_Info::insert_or_allocate (source_subscribers_, - consumer, - source); -} - -// Step through all Supplier Proxies. For each proxy, if it generates -// <type>, add <consumer> to its subscription info. -int -ACE_ES_Subscription_Module::subscribe_type (ACE_ES_Consumer_Rep *consumer, - RtecEventComm::EventType type) -{ - // ACE_DEBUG ((LM_DEBUG, - // "EC (%t) Subscription_Module::subscribe_type - %d\n", type)); - - // First insert <consumer> into the global type collection set - // corresponding to <type>. The type collection will only be used - // when suppliers register late. - if (ACE_ES_Subscription_Info::insert_or_allocate (type_subscribers_, - consumer, type) == -1) - { - ACE_ERROR_RETURN ((LM_ERROR, - "Subscription_Module - insert_or_allocate failed\n"), - -1); - } - - Supplier_Iterator iter (all_suppliers_); - - for (ACE_Push_Supplier_Proxy **proxy = 0; - iter.next (proxy) != 0; - iter.advance ()) - { - ACE_WRITE_GUARD_RETURN (ACE_ES_RW_LOCK, mon, - (*proxy)->subscription_info ().lock_, - -1); - - // Insert the consumer to the supplier's subscription set for - // the type. If the supplier does not publish this type, the - // operation will fail. If this succeeds, dependency_info will - // be added to the consumer. - RtecScheduler::Dependency_Info *dependency_info; - if (ACE_ES_Subscription_Info::insert_or_fail - ((*proxy)->subscription_info ().type_subscribers_, - consumer, type, dependency_info) == 0) - { - // Success. Add the supplier dependency info to the - // consumer's dependency list. - // @@ TODO handle exceptions. - ACE_DECLARE_NEW_CORBA_ENV; - ACE_TRY - { -#if 1 - this->scheduler_->add_dependency - (consumer->dependency ()->rt_info, - dependency_info->rt_info, - dependency_info->number_of_calls, - RtecBase::ONE_WAY_CALL - ACE_ENV_ARG_PARAMETER); -#else - ACE_Scheduler_Factory::server()->add_dependency - (consumer->dependency ()->rt_info, - dependency_info->rt_info, - dependency_info->number_of_calls, - RtecBase::ONE_WAY_CALL - ACE_ENV_ARG_PARAMETER); -#endif - ACE_TRY_CHECK; - } - ACE_CATCHANY - { - ACE_PRINT_EXCEPTION (ACE_ANY_EXCEPTION, - "Subscription_Module::subscribe_type:" - " add_dependency failed.\n"); - return -1; - } - ACE_ENDTRY; - } - } - - return 0; -} - -int -ACE_ES_Subscription_Module::subscribe_source_type (ACE_ES_Consumer_Rep *consumer, - RtecEventComm::EventSourceID source, - RtecEventComm::EventType type) -{ - // Step through all Supplier Proxies looking for a match to - // <supplier>. Once we find one, find the correct set for the - // specified type. Add the <consumer> to that set. - Supplier_Iterator iter (all_suppliers_); - - for (ACE_Push_Supplier_Proxy **proxy = 0; - iter.next (proxy) != 0; - iter.advance ()) - { - ACE_WRITE_GUARD_RETURN (ACE_ES_RW_LOCK, mon, - (*proxy)->subscription_info ().lock_, - -1); - - if ((**proxy) == source) - { - // Insert the consumer to the supplier's subscription set for - // the type. - RtecScheduler::Dependency_Info *dependency_info; - int insert_result = ACE_ES_Subscription_Info::insert_or_fail - ((*proxy)->subscription_info().type_subscribers_, - consumer, type, dependency_info); - - switch (insert_result) - { - case -1: - // Error. - ACE_ERROR_RETURN ((LM_ERROR, "%p.\n", - "Subscription Module::subscribe_source_type"), -1); - case 0: - default: - { - // Success. - // Add the supplier to the consumer's dependency list. - // @@ TODO handle exceptions. - ACE_DECLARE_NEW_CORBA_ENV; - ACE_TRY - { -#if 1 - this->scheduler_->add_dependency - (consumer->dependency ()->rt_info, - dependency_info->rt_info, - dependency_info->number_of_calls, - RtecBase::ONE_WAY_CALL - ACE_ENV_ARG_PARAMETER); -#else - ACE_Scheduler_Factory::server()->add_dependency - (consumer->dependency ()->rt_info, - dependency_info->rt_info, - dependency_info->number_of_calls, - RtecBase::ONE_WAY_CALL - ACE_ENV_ARG_PARAMETER); -#endif - ACE_TRY_CHECK; - } - ACE_CATCHANY - { - ACE_PRINT_EXCEPTION (ACE_ANY_EXCEPTION, - "Subscription_Module::" - "subscribe_source_type:" - " add_dependency failed.\n"); - return -1; - } - ACE_ENDTRY; - } - /* FALLTHROUGH */ - case 1: - // Already there. - break; - } - - } - } - - return ACE_ES_Subscription_Info::insert_or_allocate (source_subscribers_, - consumer, - source); -} - -// <consumer> contains information for one type of subscription. -// Delegate to the appropriate method for subscription. -int -ACE_ES_Subscription_Module::subscribe (ACE_ES_Consumer_Rep *consumer) -{ - // We could have finer granularity by putting RGUARDs in some of the - // subscribe methods. - ACE_ES_WGUARD ace_mon (lock_); - if (ace_mon.locked () == 0) - ACE_ERROR_RETURN ((LM_ERROR, "%p.\n", - "ACE_ES_Subscription_Module::subscribe"), -1); - - int result = 0; - RtecEventComm::Event &event = consumer->dependency ()->event; - - if (event.header.source == 0) - // Not source-based subscription. - { - if (event.header.type == ACE_ES_EVENT_ANY) - result = this->subscribe_all (consumer); - else - result = this->subscribe_type (consumer, event.header.type); - } - else - // Source-based subscription. - { - if (event.header.type == ACE_ES_EVENT_ANY) - result = this->subscribe_source (consumer, event.header.source); - else - result = this->subscribe_source_type (consumer, - event.header.source, - event.header.type); - } - - return result; -} - -int -ACE_ES_Subscription_Module::unsubscribe (ACE_ES_Consumer_Rep *consumer) -{ - // We could have finer granularity by putting RGUARDs in some of the - // unsubscribe methods. - ACE_ES_WGUARD ace_mon (lock_); - if (ace_mon.locked () == 0) - ACE_ERROR_RETURN ((LM_ERROR, "%p.\n", - "ACE_ES_Subscription_Module::unsubscribe"), -1); - - RtecEventComm::Event &event = consumer->dependency ()->event; - - if (event.header.source == 0) - { - // Remove the consumer from the global type-based subscription list. - ACE_ES_Subscription_Info::remove (type_subscribers_, - consumer, - event.header.type); - } - else - // Remove the consumer from the global source-based subscription list. - ACE_ES_Subscription_Info::remove (source_subscribers_, - consumer, - event.header.source); - -#if 0 - // @@ TODO This code was removed and I'm (coryan) adding it again - // because it does seem necessary, the only explanation for its - // removal is this comment: - // - // /* - // - // This old code manually removed the consumer from the subscription - // lists. Now we do lazy removal. - // */ - // - // I quite not follow what was going on. - // - // [CORYAN]: The mistery seems resolved: the code was here to remove - // the consumer proxy from the supplier sets, but the "new" strategy - // was to remove them as the supplier tries to push events through - // them, unfortunately that code was broken and did not remove the - // objects at all, hence the apparent need to re-instate this code. - // Bottom line: it seems the code is not needed after all. - - int result = 0; - - if (event.header.source == 0) - { - if (event.header.type == ACE_ES_EVENT_ANY) - result = this->unsubscribe_all (consumer); - else - result = this->unsubscribe_type (consumer, event.header.type); - } - else - { - if (event.header.type == ACE_ES_EVENT_ANY) - result = this->unsubscribe_source (consumer, event.header.source); - else - result = this->unsubscribe_source_type (consumer, - event.header.source, - event.header.type); - } - return result; -#else - return 0; -#endif /* 0 */ -} - -int -ACE_ES_Subscription_Module::unsubscribe_all (ACE_ES_Consumer_Rep *) -{ - return 0; -} - -int -ACE_ES_Subscription_Module::unsubscribe_type (ACE_ES_Consumer_Rep *consumer, - RtecEventComm::EventType type) -{ - // Step through all Supplier Proxies trying to remove the - // consumer-type pair. ACE_ES_Subscription_Info::remove will fail - // if the supplier does not generate <type>, but that's ok. - Supplier_Iterator iter (all_suppliers_); - - for (ACE_Push_Supplier_Proxy **proxy = 0; - iter.next (proxy) != 0; - iter.advance ()) - { - ACE_WRITE_GUARD_RETURN (ACE_ES_RW_LOCK, mon, - (*proxy)->subscription_info ().lock_, - -1); - - // This remove will be harmless if the supplier does not - // generate <type>. - ACE_ES_Subscription_Info::remove ((*proxy)->subscription_info ().type_subscribers_, - consumer, type); - } - - return 0; -} - -int -ACE_ES_Subscription_Module::unsubscribe_source (ACE_ES_Consumer_Rep *consumer, - RtecEventComm::EventSourceID source) -{ - Supplier_Iterator iter (all_suppliers_); - - for (ACE_Push_Supplier_Proxy **proxy = 0; - iter.next (proxy) != 0; - iter.advance ()) - { - ACE_WRITE_GUARD_RETURN (ACE_ES_RW_LOCK, mon, - (*proxy)->subscription_info ().lock_, - -1); - - if ((**proxy) == source) - { - ACE_ES_Subscription_Info::Subscriber_Set &set = - (*proxy)->subscription_info ().source_subscribers_; - if (set.remove (consumer) == -1) - ACE_ERROR_RETURN ((LM_ERROR, "%p.\n", - "Subscription Module::unsubscribe_source"), -1); - consumer->_release (); - } - } - - return 0; -} - -int -ACE_ES_Subscription_Module::unsubscribe_source_type (ACE_ES_Consumer_Rep *consumer, - RtecEventComm::EventSourceID source, - RtecEventComm::EventType type) - -{ - Supplier_Iterator iter (all_suppliers_); - - // Step through all supplier proxies looking for a match to the - // consumer's event.header.source. This is the same as - // unsubscribe_type, only we can check the source first. - for (ACE_Push_Supplier_Proxy **proxy = 0; - iter.next (proxy) != 0; - iter.advance ()) - // If the proxy matches the source id we're looking for, try to - // remove <consumer> from the proxy's <event.header.type> set. - if ((**proxy) == source) - { - ACE_WRITE_GUARD_RETURN (ACE_ES_RW_LOCK, mon, - (*proxy)->subscription_info ().lock_, - -1); - - // Continue in spite of errors. - ACE_ES_Subscription_Info::remove ((*proxy)->subscription_info ().type_subscribers_, - consumer, type); - } - - return 0; -} - -void -ACE_ES_Subscription_Module::push (ACE_Push_Supplier_Proxy *source, - const TAO_EC_Event &event - ACE_ENV_ARG_DECL) -{ - // ACE_DEBUG ((LM_DEBUG, "EC (%t) Subscription_Module::push\n")); - - ACE_TIMEPROBE (TAO_EVENT_CHANNEL_DELIVER_TO_SUBSCRIPTION_MODULE); - // These are all inline function calls. - int result = this->push_source (source, event ACE_ENV_ARG_PARAMETER); - ACE_CHECK; - - if (result == -1) - return; - - { - ACE_FUNCTION_TIMEPROBE (TAO_EVENT_CHANNEL_BEGIN_PUSH_SOURCE_TYPE); - - result = this->push_source_type (source, event ACE_ENV_ARG_PARAMETER); - ACE_CHECK; - - if (result == -1) - return; - } -} - -void -ACE_ES_Subscription_Module::shutdown (void) -{ - ACE_ES_WGUARD ace_mon (lock_); - if (ace_mon.locked () == 0) - ACE_ERROR ((LM_ERROR, "%p.\n", - "ACE_ES_Subscription_Module::shutdown")); - - // Remove all type_subscribers_ and source_subscribers_. - - ACE_ES_Subscription_Info::Subscriber_Map_Iterator type_iter (type_subscribers_); - for (ACE_ES_Subscription_Info::Subscriber_Map_Entry *entry = 0; - type_iter.next (entry) != 0; - type_iter.advance ()) - { - ACE_ES_Subscription_Info::Subscriber_Set_Iterator ts_iter (entry->int_id_->consumers_); - - for (ACE_ES_Consumer_Rep **consumer = 0; - ts_iter.next (consumer) != 0; - ts_iter.advance ()) - (*consumer)->_release (); - - delete entry->int_id_; - } - - ACE_ES_Subscription_Info::SourceID_Map_Iterator source_iter (source_subscribers_); - - for (ACE_ES_Subscription_Info::SourceID_Map_Entry *entry2; - source_iter.next (entry2) != 0; - source_iter.advance ()) - { - ACE_ES_Subscription_Info::Subscriber_Set_Iterator ss_iter (*entry2->int_id_); - - for (ACE_ES_Consumer_Rep **consumer = 0; - ss_iter.next (consumer) != 0; - ss_iter.advance ()) - (*consumer)->_release (); - - delete entry2->int_id_; - } - - // We don't need to do anything to all_suppliers_ since the supplier - // module should have disconnected all suppliers. To be more - // independent from the supplier module, this method should iterate - // through all suppliers and call this->disconnecting. - up_->shutdown (); -} - -ACE_ES_Supplier_Module::ACE_ES_Supplier_Module (ACE_EventChannel *channel) : - all_suppliers_ (), - lock_ (), - up_ (0), - channel_ (channel) -{ -} - -void -ACE_ES_Supplier_Module::open (ACE_ES_Subscription_Module *up) -{ - // There is the theory of the Mobius, a twist, in the fabric of - // space, where time becomes a loop, where time becomes a loop. - up_ = up; -} - -void -ACE_ES_Supplier_Module::connected (ACE_Push_Supplier_Proxy *supplier - ACE_ENV_ARG_DECL) -{ - channel_->report_connect (ACE_EventChannel::SUPPLIER); - up_->connected (supplier ACE_ENV_ARG_PARAMETER); - ACE_CHECK; - - if (!supplier->qos ().is_gateway) - this->channel_->update_supplier_gwys (ACE_ENV_SINGLE_ARG_PARAMETER); -} - -void -ACE_ES_Supplier_Module::disconnecting (ACE_Push_Supplier_Proxy *supplier - ACE_ENV_ARG_DECL) -{ - CORBA::Boolean need_update = 0; - { - ACE_GUARD_THROW_EX ( - ACE_ES_MUTEX, ace_mon, this->lock_, - RtecEventChannelAdmin::EventChannel::SYNCHRONIZATION_ERROR()); - ACE_CHECK; - - if (all_suppliers_.remove (supplier) == -1) - ACE_THROW (RtecEventChannelAdmin::EventChannel::SUBSCRIPTION_ERROR()); - - up_->disconnecting (supplier ACE_ENV_ARG_PARAMETER); - ACE_CHECK; - - if (this->all_suppliers_.size () <= 0) - { - // ACE_DEBUG ((LM_DEBUG, "EC (%t) No more suppliers connected.\n")); - channel_->report_disconnect_i (ACE_EventChannel::SUPPLIER); - } - - need_update = (supplier->qos ().is_gateway == 0); - - // @@ TODO It would seem - // IMHO this release is broken: supplier is a parameter, we never - // actually increased its reference count, so we shouldn't decrease - // it. - // CORBA::release (supplier); - } - if (need_update) - this->channel_->update_supplier_gwys (ACE_ENV_SINGLE_ARG_PARAMETER); -} - -void -ACE_ES_Supplier_Module::shutdown (void) -{ - Suppliers copy; - - { - ACE_GUARD (ACE_ES_MUTEX, ace_mon, this->lock_); - - copy = all_suppliers_; - } - - if (copy.size () > 0) - { - Supplier_Iterator iter (copy); - - ACE_DECLARE_NEW_CORBA_ENV; - - for (ACE_Push_Supplier_Proxy **proxy = 0; - iter.next (proxy) != 0; - iter.advance ()) - { - (*proxy)->shutdown (); - this->disconnecting (*proxy ACE_ENV_ARG_PARAMETER); - } - } - - up_->shutdown (); -} - -RtecEventChannelAdmin::ProxyPushConsumer_ptr -ACE_ES_Supplier_Module::obtain_push_consumer (ACE_ENV_SINGLE_ARG_DECL) - ACE_THROW_SPEC ((CORBA::SystemException)) -{ - RtecEventChannelAdmin::ProxyPushConsumer_ptr proxy = - RtecEventChannelAdmin::ProxyPushConsumer::_nil (); - - auto_ptr<ACE_Push_Supplier_Proxy> new_supplier (new ACE_Push_Supplier_Proxy (this)); - - if (new_supplier.get () == 0) - ACE_THROW_RETURN (CORBA::NO_MEMORY (), proxy); - - { - ACE_GUARD_THROW_EX ( - ACE_ES_MUTEX, ace_mon, this->lock_, - CORBA::INTERNAL ()); - // @@ RtecEventChannelAdmin::EventChannel::SYNCHRONIZATION_ERROR()); - ACE_CHECK_RETURN (proxy); - - if (all_suppliers_.insert (new_supplier.get ()) == -1) - ACE_ERROR ((LM_ERROR, "ACE_ES_Supplier_Module insert failed.\n")); - } - - proxy = new_supplier->_this (ACE_ENV_SINGLE_ARG_PARAMETER); - ACE_CHECK_RETURN (proxy); - - // Give ownership to the POA - new_supplier.release ()->_remove_ref (ACE_ENV_SINGLE_ARG_PARAMETER); - ACE_CHECK_RETURN (proxy); - - return proxy; -} - -void -ACE_ES_Supplier_Module::push (ACE_Push_Supplier_Proxy *proxy, - RtecEventComm::EventSet &event_set - ACE_ENV_ARG_DECL) -{ - // Steal the events from the EventSet and put them into a reference - // counted event set. - TAO_EC_Event_Set* event = - TAO_EC_Event_Set::_create (event_set); - - if (event == 0) - ACE_THROW (CORBA::NO_MEMORY ()); - - // ACE_DEBUG ((LM_DEBUG, "EC (%t) Supplier_Module::push\n")); - for (CORBA::ULong i = 0; i < event->length (); ++i) - { - // This will guarantee that release gets called when we exit - // the scope. - TAO_EC_Event event_copy (event, i); - ACE_TIMEPROBE (TAO_EVENT_CHANNEL_DELIVER_TO_SUPPLIER_MODULE_THRU_SUPPLIER_PROXY); - up_->push (proxy, event_copy ACE_ENV_ARG_PARAMETER); - ACE_CHECK; - } - TAO_EC_Event_Set::_release (event); -} - -void -ACE_ES_Supplier_Module::fill_qos (RtecEventChannelAdmin::SupplierQOS& s_qos) -{ - ACE_GUARD (ACE_ES_MUTEX, ace_mon, this->lock_); - - s_qos.is_gateway = 1; - - int count = 0; - { - for (Supplier_Iterator i = this->all_suppliers_.begin (); - i != this->all_suppliers_.end (); - ++i) - { - ACE_Push_Supplier_Proxy *s = *i; - - if (s->qos ().is_gateway) - continue; - - count += s->qos ().publications.length (); - } - } - - RtecEventChannelAdmin::PublicationSet& pub = s_qos.publications; - - pub.length (count); - - CORBA::ULong sc = 0; - - for (Supplier_Iterator i = this->all_suppliers_.begin (); - i != this->all_suppliers_.end (); - ++i) - { - ACE_Push_Supplier_Proxy *s = *i; - - if (s->qos ().is_gateway) - continue; - - CORBA::ULong count = s->qos ().publications.length (); - for (CORBA::ULong j = 0; j < count; ++j) - { - RtecEventComm::Event& event = - s->qos ().publications[j].event; - - RtecEventComm::EventType type = event.header.type; - - // Only type and source dependencies are relevant, notice - // that we turn conjunctions into disjunctions because - // correlations could be satisfied by events coming from - // several remote ECs. - if (0 <= type && type <= ACE_ES_EVENT_UNDEFINED) - continue; - - // If the dependency is already there we don't add it. - CORBA::ULong k; - for (k = 0; k < sc; ++k) - { - if (pub[k].event.header.type == event.header.type - && pub[k].event.header.source == event.header.source) - break; - } - if (k == sc) - { - pub[sc].event.header.type = event.header.type; - pub[sc].event.header.source = event.header.source; - pub[sc].event.header.creation_time = ORBSVCS_Time::zero (); - pub[sc].dependency_info.dependency_type = - RtecBase::TWO_WAY_CALL; - pub[sc].dependency_info.number_of_calls = 1; - pub[sc].dependency_info.rt_info = 0; - sc++; - } - } - } - pub.length (sc); -} diff --git a/TAO/orbsvcs/orbsvcs/Event/Event_Channel.h b/TAO/orbsvcs/orbsvcs/Event/Event_Channel.h deleted file mode 100644 index acc771444c6..00000000000 --- a/TAO/orbsvcs/orbsvcs/Event/Event_Channel.h +++ /dev/null @@ -1,1495 +0,0 @@ -/* -*- C++ -*- */ -//============================================================================= -/** - * @file Event_Channel.h - * - * $Id$ - * - * @author Tim Harrison (harrison@cs.wustl.edu) - * - * TAO implementation of the Real Time Event Services. For more - * detailed information, see - * http://www.cs.wustl.edu/~schmidt/oopsla.ps.gz - * - * = NAMING CONVENTIONS - * Some of the naming might be confusing. For instance - * ACE_Push_Consumer_Proxy "is-a" ProxyPushSupplier. To the - * channel, ACE_Push_Consumer_Proxy is a proxy to push consumers. - * To a push consumer, ACE_Push_Consumer_Proxy is a proxy to push - * suppliers. I chose to name classes relative to the Event - * Channel. - * - * - */ -//============================================================================= - - -#ifndef ACE_EVENT_CHANNEL_H -#define ACE_EVENT_CHANNEL_H - -#include /**/ "ace/pre.h" - -#include "ace/Unbounded_Set.h" - -#if !defined (ACE_LACKS_PRAGMA_ONCE) -# pragma once -#endif /* ACE_LACKS_PRAGMA_ONCE */ - -#include "ace/Map_Manager.h" -#include "ace/Functor.h" - -#include "tao/Timeprobe.h" - -#include "orbsvcs/Scheduler_Factory.h" -#include "orbsvcs/Event/Local_ESTypes.h" -#include "orbsvcs/Event/Timer_Module.h" -#include "orbsvcs/Event/ReactorTask.h" -#include "orbsvcs/Event/Event_Manip.h" - -// ************************************************************ - -/** - * An array of Events. The Event Channel keeps several collections of - * TAO_EC_Event objects, this is implemented using a simple Event Array. - */ -typedef ACE_Array<TAO_EC_Event> TAO_EC_Event_Array; - -// ************************************************************ - -/** - * Append an event to an event Array. Simplify a common idiom when - * manipulating arrays of events. - */ -ACE_INLINE -void operator += (TAO_EC_Event_Array &dest, - const TAO_EC_Event &item); - -// ************************************************************ - -/** - * Compare two events. The Event Channel must compare events - * (actually event headers) for equality. - */ -ACE_INLINE bool -operator == (const RtecEventComm::Event &event1, - const RtecEventComm::Event &event2); - -// ************************************************************ - -/** - * Compare two TAO_EC_Events. This is only used in the instantiation of - * ACE_Array<TAO_EC_Event>. - */ -ACE_INLINE -bool operator != (const TAO_EC_Event &rhs, const TAO_EC_Event &lhs); - -// ************************************************************ - -/** - * Utility for debugging events. - */ -void TAO_RTOLDEvent_Export dump_event (const RtecEventComm::Event &event); - -// ************************************************************ - - -#if defined(_MSC_VER) -#pragma warning(push) -#pragma warning(disable:4250) -#endif /* _MSC_VER */ - -/** - * @class ACE_RTU_Manager - * - * @brief ACE RTU Manager - * - */ -class TAO_RTOLDEvent_Export ACE_RTU_Manager -{ -public: - /// If <active> == 0, everything returns 0. If <active> != 0, RTUs - /// galore. - ACE_RTU_Manager (int active); - - /// Returns 1 if the current task should preempt itself. Otherwise, - /// returns 0. Resets should_preempt to zero. - int should_preempt (void); - - /// Called by the dispatching module when the current task should - /// preempt itself. - void should_preempt (int s); - - /// If <nd> != 0, the current running task will be enqueued at the - /// head of its dispatch tail. - void not_done (int nd); - - /// Returns 1 if the current task needs to be dispatched again. - /// Resets not_done_ to 0; - int not_done (void); - - /// Get the priority of the current running task. - RtecScheduler::OS_Priority priority (void); - - /// Set the priority of the current running task. - void priority (RtecScheduler::OS_Priority priority); - -private: - int active_; - int should_preempt_; - int not_done_; - RtecScheduler::OS_Priority priority_; -}; - -// ************************************************************ - -// Chesire cat. -// Forward declarations. -class ACE_ES_Priority_Timer; -class ACE_ES_Consumer_Module; -// This forward decl and typedef allow us to remove inheritence later -// on without changing any code. -// -class ACE_ES_Correlation_Module; -class ACE_ES_Subscription_Module; -class ACE_ES_Supplier_Module; -class ACE_ES_Dispatching_Base; -typedef ACE_ES_Dispatching_Base ACE_ES_Dispatching_Module; - -// Forward declare the class used to connect several EC together. -class TAO_EC_Gateway; - -// Factory class for the modules in the EC. -class TAO_Module_Factory; - -/** - * @class ACE_EventChannel - * - * @brief TAO's Real-time Event Channel. - * - * This class implements the interface defined in - * RtecEventChannelAdmin.idl. For more details check: - * http://www.cs.wustl.edu/~coryan/EC/JSAC98.pdf - */ -class TAO_RTOLDEvent_Export ACE_EventChannel : public POA_RtecEventChannelAdmin::EventChannel -{ -public: - enum { INITIAL_STATE = 0, - CONSUMER = 1, SUPPLIER = 2, - SHUTDOWN = CONSUMER | SUPPLIER }; - - /** - * Construction of the given <type>. Check the **_CHANNEL - * enumerations defined below. - * By default we activate the threads on construction, but it is - * possible to create the EC first and activate the threads later. - * A factory for the modules can be provided, by default it uses - * TAO_EC_Default_Module_Factory - * If an scheduler is not provided it uses the singleton in - * ACE_Scheduler_Factory. - */ - ACE_EventChannel (CORBA::Boolean activate_threads = 1, - u_long type = ACE_DEFAULT_EVENT_CHANNEL_TYPE, - TAO_Module_Factory* factory = 0); - ACE_EventChannel (RtecScheduler::Scheduler_ptr scheduler, - CORBA::Boolean activate_threads = 1, - u_long type = ACE_DEFAULT_EVENT_CHANNEL_TYPE, - TAO_Module_Factory* factory = 0); - - /// Calls destroy. - virtual ~ACE_EventChannel (void); - - /// Allow transformations to RtecEventChannelAdmin::EventChannel. - RtecEventChannelAdmin::EventChannel_ptr get_ref (ACE_ENV_SINGLE_ARG_DECL_NOT_USED); - - /// Returns a reference to the RTU manager. - ACE_RTU_Manager *rtu_manager (void); - - // = These should be private. - ACE_ES_Consumer_Module *consumer_module_; - ACE_ES_Dispatching_Module *dispatching_module_; - ACE_ES_Correlation_Module *correlation_module_; - ACE_ES_Subscription_Module *subscription_module_; - ACE_ES_Supplier_Module *supplier_module_; - - /// Consumer or supplier connected. - void report_connect (u_long); - - /// Consumer or supplier disconnected. - void report_disconnect (u_long); - - /// Activate the internal threads of the EC - void activate (void); - - /// Do not call this. The last module has shut down. - void shutdown (void); - - /// Consumer or supplier connected. - void report_connect_i (u_long); - - /// Consumer or supplier disconnected. - void report_disconnect_i (u_long); - - /// Add gateways from the EC. - void add_gateway (TAO_EC_Gateway* gw ACE_ENV_ARG_DECL); - - /// Remove gateways from the EC. - void del_gateway (TAO_EC_Gateway* gw ACE_ENV_ARG_DECL); - - /// The consumer list has changed, thus the EC has to - /// inform any gateways it has. - void update_consumer_gwys (ACE_ENV_SINGLE_ARG_DECL); - - /// The supplier list has changed, thus the EC has to - /// inform any gateways it has. - void update_supplier_gwys (ACE_ENV_SINGLE_ARG_DECL); - - /// The timer module controls the strategy to dispatch timers. - TAO_EC_Timer_Module* timer_module (void) const; - - // = The RtecEventChannelAdmin::EventChannel methods. - - /// In this implementation of the EC this returns the interface for - /// the Consumer_Module. - virtual RtecEventChannelAdmin::ConsumerAdmin_ptr - for_consumers (ACE_ENV_SINGLE_ARG_DECL_NOT_USED) - ACE_THROW_SPEC ((CORBA::SystemException)); - - /// Return an interface to the Supplier_Module. - virtual RtecEventChannelAdmin::SupplierAdmin_ptr - for_suppliers (ACE_ENV_SINGLE_ARG_DECL_NOT_USED) - ACE_THROW_SPEC ((CORBA::SystemException)); - - /// Shutdown the EC, free all resources, stop all threads and then - /// shutdown the server where the Servant is running. - virtual void destroy (ACE_ENV_SINGLE_ARG_DECL_NOT_USED) - ACE_THROW_SPEC ((CORBA::SystemException)); - - /// The observer manipulators - virtual RtecEventChannelAdmin::Observer_Handle - append_observer (RtecEventChannelAdmin::Observer_ptr observer - ACE_ENV_ARG_DECL) - ACE_THROW_SPEC (( - CORBA::SystemException, - RtecEventChannelAdmin::EventChannel::SYNCHRONIZATION_ERROR, - RtecEventChannelAdmin::EventChannel::CANT_APPEND_OBSERVER)); - virtual void remove_observer (RtecEventChannelAdmin::Observer_Handle - ACE_ENV_ARG_DECL) - ACE_THROW_SPEC (( - CORBA::SystemException, - RtecEventChannelAdmin::EventChannel::SYNCHRONIZATION_ERROR, - RtecEventChannelAdmin::EventChannel::CANT_REMOVE_OBSERVER)); - - // = Timer managment - /// Schedule a timer at the appropriate priority for <preemption_priority>. - /// Returns the preemption priority used on success, -1 on failure. - int schedule_timer (RtecScheduler::handle_t rt_info, - const ACE_Command_Base *act, - RtecScheduler::OS_Priority preemption_priority, - const RtecScheduler::Time& delta, - const RtecScheduler::Time& interval = ORBSVCS_Time::zero ()); - - /** - * Cancel the timer associated with the priority of - * <preemption_priority> and <id>. <act> is filled in with the - * Timer_ACT used when scheduling the timer. Returns 0 on success, - * -1 on failure. - */ - int cancel_timer (RtecScheduler::OS_Priority preemption_priority, - int id, - ACE_Command_Base *&act); - - /** - * Return a reference to its SchedulerService, notice that it uses - * the CORBA semantics for memory managment, i.e. the user gains - * ownership of the reference returned. - */ - RtecScheduler::Scheduler_ptr scheduler (void); - - /** - * @struct Observer_Entry - * - * @brief The data kept for each observer. - * - * The observer and its handle are kept in a simple structure. - * In the future this structure could contain QoS information, - * such as: - * + how often do we update the observer? - * + When was the last update. - * + Does it want to receive all changes? - */ - struct Observer_Entry - { - - Observer_Entry (void); - Observer_Entry (RtecEventChannelAdmin::Observer_Handle h, - RtecEventChannelAdmin::Observer_ptr o); - - /// The handle - RtecEventChannelAdmin::Observer_Handle handle; - - /// The observer - RtecEventChannelAdmin::Observer_var observer; - - }; - -private: - /// Factor out commonality in the constructor. - void init (int activate_threads); - - /// Remove all the observers, this simplifies the shutdown process. - void cleanup_observers (void); - - /// The RTU manager dude! - ACE_RTU_Manager *rtu_manager_; - - /// Can be any **_CHANNEL. (well, except NO_CHANNEL). - u_long type_; - - /// Can be INITIAL_STATE, NO_CONSUMERS, NO_SUPPLIERS, or SHUTDOWN. - u_long state_; - - /// Used to lock shared state. - ACE_ES_MUTEX lock_; - - /// Ensures this->destory is executed only once. - int destroyed_; - - typedef ACE_Map_Manager<RtecEventChannelAdmin::Observer_Handle,Observer_Entry,ACE_Null_Mutex> Observer_Map; - typedef ACE_Map_Iterator<RtecEventChannelAdmin::Observer_Handle,Observer_Entry,ACE_Null_Mutex> Observer_Map_Iterator; - - /// The handles are generated in sequential order, but are opaque to - /// the client. - RtecEventChannelAdmin::Observer_Handle handle_generator_; - - /// Keep the set of Gateways, i.e. connections to peer EC. - Observer_Map observers_; - - /// The strategy to dispatch timers. - TAO_EC_Timer_Module* timer_module_; - - /// If 1 then we created the factory, thus we have to destroy it. - int own_factory_; - - /// This is the factory we use to create and destroy the Event - /// Channel modules. - TAO_Module_Factory* module_factory_; - - /// The scheduler - RtecScheduler::Scheduler_var scheduler_; -}; - -// ************************************************************ - -/** - * @class ACE_ES_Dependency_Iterator - * - * @brief ConsumerQOS Iterator - * - * This is used by the Event Channel to parse ConsumerDependency objects. - */ -class TAO_RTOLDEvent_Export ACE_ES_Dependency_Iterator -{ -public: - /// Construct and iterator for <rep>. - ACE_ES_Dependency_Iterator (RtecEventChannelAdmin::DependencySet &rep); - - /// Returns 0 if the advance succeeded. Returns -1 if there are no - /// more dependencies in the group. - int advance_dependency (void); - - /// Cache values for n_** methods. - int parse (void); - - /// Returns the number of conjunction groups in the dependency set. - int n_conjunctions (void); - - /// Returns the number of disjunction groups in the dependency set. - int n_disjunctions (void); - - /// Returns the number of timeouts registered. - int n_timeouts (void); - - /// Returns the number of events registered. - int n_events (void); - - /// Accessor to the current ConsumerDependency pointed to by the - /// iterator. - RtecEventChannelAdmin::Dependency &operator *(void); - - /// Returns the first RT_Info in the dependencies. - RtecScheduler::handle_t first_rt_info (void); - -protected: - /// The first rt_info in the dependencies. - RtecScheduler::handle_t rt_info_; - - /// Reference to the dependency array. - RtecEventChannelAdmin::DependencySet &rep_; - - /// Index into rep_. - int index_; - - /// The type of the current correlation group. - RtecEventComm::EventType group_type_; - - /// Number of conjunction groups. - int n_conjunctions_; - - /// Number of disjunction groups. - int n_disjunctions_; - - /// Number of timeouts registered. - int n_timeouts_; - - /// Number of events registered. - int n_events_; -}; - -// ************************************************************ -// Forward decl. -class ACE_ES_Consumer_Rep_Timeout; - -/** - * @class ACE_ES_Disjunction_Group - * - * @brief Disjunction Group - * - * Represents a disjunction group, such as (A|B|C). - */ -class TAO_RTOLDEvent_Export ACE_ES_Disjunction_Group -{ -public: - /// Default construction. - ACE_ES_Disjunction_Group (void); - - /// Destructor. - virtual ~ACE_ES_Disjunction_Group (void); - - /// <cm> is needed for rescheduling deadlines. - void set_correlation_module (ACE_ES_Correlation_Module *cm); - - /// If deadline_timer_rep_ is set, it is cancelled and rescheduled. - void reschedule_deadline (void); - - /// Set the group's reference to the deadline timer. Returns 0 on - /// success, -1 on failure. - int set_deadline_timeout (ACE_ES_Consumer_Rep_Timeout *cr); - - /// Does nothing. This is the only virtual method in this little - /// heirarchy with the conjunction group. - virtual void add_events (TAO_EC_Event_Array *outbox, - TAO_EC_Event_Array *pending_events, - u_long &pending_flags); - - /// Set the ACT for this group. - void set_act (RtecEventComm::Event &act); - -protected: - /// To be sent with this group. - TAO_EC_Event act_; - -private: - /// The disjunction group keeps a reference to the deadline timer. - ACE_ES_Consumer_Rep_Timeout *deadline_timer_rep_; - - /// Used for cancelling and scheduling deadline_timer_rep_. - ACE_ES_Correlation_Module *correlation_module_; -}; - -// ************************************************************ - -/** - * @class ACE_ES_Conjunction_Group - * - * @brief Conjunction Group - * - * Represents a conjunction group, such as (A+B+C). - */ -class TAO_RTOLDEvent_Export ACE_ES_Conjunction_Group : public ACE_ES_Disjunction_Group -{ -public: - /// Default construction. - ACE_ES_Conjunction_Group (void); - - /// Destructor. - virtual ~ACE_ES_Conjunction_Group (void); - - /// Set the <type_id>th bit in the forward_value_. - int add_type (int type_id); - - /// Returns 1 if this conjunction group's dependencies have been - /// satisfied. Returns 0 otherwise. - int should_forward (u_long pending_flags); - - /** - * For each bit set in forward_value_, the corresponding events in - * <pending_events> is added to <outbox>. Each bit set in - * <forward_value_> is cleared in <pending_flags>. If <oubox> == 0, - * then add_events just clears the pending events and flags. - */ - virtual void add_events (TAO_EC_Event_Array *outbox, - TAO_EC_Event_Array *pending_events, - u_long &pending_flags); - -private: - u_long forward_value_; -}; - -// ************************************************************ - -// Forward decl. -class ACE_ES_Consumer_Correlation; - -/** - * @class ACE_ES_Consumer_Rep - * - * @brief Consumer Representation. - * - * These are stored in the subscription module. They store - * information that allows optimized correlations. It represents - * the consumer that will handle *one* type of event. This - * probably shouldn't inherit from ACE_Command_Base since it's used - * only by ACE_ES_Consumer_Rep_Timeout. However, this allows me to - * minimize dynamic allocation. - */ -class TAO_RTOLDEvent_Export ACE_ES_Consumer_Rep : public ACE_Command_Base -{ -public: - /// Default construction. - ACE_ES_Consumer_Rep (void); - - /// <dep> describes the event subscribed to and the method handling - /// the event. <correlation> is the parent correlation object. - void init (ACE_ES_Consumer_Correlation *correlation, - RtecEventChannelAdmin::Dependency &dep); - - /// Virtual destruction. - virtual ~ACE_ES_Consumer_Rep (void); - - /// The event subscribed to and the method that will handle this - /// event. - RtecEventChannelAdmin::Dependency *dependency (void); - - /// Get the correlation group index of this consumer rep's event - /// type. - int type_id (void); - - /// Set the correlation group index of this consumer rep's event - /// type. - void type_id (int); - - enum Correlation_Type - { - NO_CORRELATION, - CORRELATE, - DEADLINE_TIMEOUT, - GLOBAL_DEADLINE - }; - - /// If this returns 0, then the event associated with this consumer - /// should be forwarded without running any correlations. - u_long correlation_type (void); - - /// Set whether the event should be correlated. <ct> is a - /// Correlation_Type. - void correlation_type (u_long ct); - - /// Add a disjunction group. - int add_disjunction_group (ACE_ES_Disjunction_Group &); - - /// Returns the first disjunction group added via - /// this->add_disjunction_group. - ACE_ES_Disjunction_Group *top_group (void); - - /// Calls reschedule_deadline on all disjunction groups added through - /// this->add_disjunction_group. - void reschedule_deadlines (void); - - /// Returns 1 if events should be sent to this consumer. Returns 0 - /// if they should not (suspended or disconnected). - int receiving_events (void); - - /// Stop forwarding events to the calling consumer. - void suspend (void); - - /// Resume forwarding events to the calling consumer. - void resume (void); - - /// Returns the Consumer_Correlation object for the target consumer. - ACE_ES_Consumer_Correlation *correlation (void); - - /// Schedules the consumer rep to be removed from all subscription - /// lists. - void disconnect (void); - - /// Returns 1 if the consumer rep should be removed from all - /// subscription lists. - int disconnected (void); - - /// Increments ref_count_. - void _duplicate (void); - - /// Decrements ref_count_ and deletes this if 0. - void _release (void); - -protected: - /// Whether the rep should be removed from all subscription lists. - int disconnected_; - - /** - * This is called when timeouts occur. This implementation prints - * out an error message (since it really shouldn't be implemented in - * this class). - */ - virtual int execute (void* arg = 0); - - /// Whether events should be dropped or forwarded. - int suspended_; - - /// Whether any correlating should be done for this event. - u_long correlation_type_; - - /// Event subscribed to. - RtecEventChannelAdmin::Dependency *dependency_; - - /// The target consumer of events. - ACE_ES_Consumer_Correlation *correlation_; - - /// Correlation group index of event_->type_. - int type_id_; - - /// This should be a set. We'll just have room for one now. - ACE_ES_Disjunction_Group *disjunction_group_; - - /// Lock for reference count. - ACE_Atomic_Op<ACE_ES_MUTEX, int> ref_count_; -}; - -/** - * @class ACE_ES_Consumer_Rep_Timeout - * - * @brief Consumer Representation. - * - * These are stored in the subscription module. They store - * information that allows optimized correlations. It represents - * the consumer that will handle *one* type of event. - */ -class TAO_RTOLDEvent_Export ACE_ES_Consumer_Rep_Timeout : public ACE_ES_Consumer_Rep -{ -public: - /// Default construction. - ACE_ES_Consumer_Rep_Timeout (void); - - /// <dep> describes the event subscribed to and the method handling - /// the event. <correlation> is the parent correlation object. - void init (ACE_ES_Consumer_Correlation *correlation, - RtecEventChannelAdmin::Dependency &dep); - - // = Get/set timer returned from the reactor. - long timer_id (void); - void timer_id (long); - - // = Get/set preemption priority. - RtecScheduler::OS_Priority preemption_priority (void); - void preemption_priority (RtecScheduler::OS_Priority pp); - -protected: - /// This is called when timeouts occur. Calls correlation_-> - virtual int execute (void* arg = 0); - - /// For cancelling timers. - long timer_id_; - - /// Store the preemption priority so we can cancel the correct timer. - /// The priority values may change during the life. - RtecScheduler::OS_Priority preemption_priority_; - - TAO_EC_Event timeout_event_; -}; - -// ************************************************************ - -/** - * @class ACE_ES_Subscription_Info - * - * @brief Event Service Subscription Info - * - * Contains information on all consumers subscribed to a supplier. - * Each Push_Supplier_Proxy has an instance of this class. This - * should really be defined in Channel_Modules.h, but I want to - * have an instance of it in each ACE_Push_Supplier_Proxy. This - * allows us to reduce the amount of dynamic memory allocation. - */ -class TAO_RTOLDEvent_Export ACE_ES_Subscription_Info -{ -public: - /// Free up dynamic resources. - ~ACE_ES_Subscription_Info (void); - - typedef ACE_Unbounded_Set_Iterator<ACE_ES_Consumer_Rep *> Subscriber_Set_Iterator; - typedef ACE_Unbounded_Set<ACE_ES_Consumer_Rep *> Subscriber_Set; - -/** - * @class Type_Subscribers - * - * There is one of these for each event type generated by the - * supplier. It contains the subscribers and the - * dependency_info_ describing the method that generates this - * event type. - */ - class Type_Subscribers - { - public: - /** - * Construction requires a dependency info describing the method - * that generates events for the consumers_. We use a pointer so - * that a null can be passed in this->insert_or_allocate. - */ - Type_Subscribers (RtecScheduler::Dependency_Info *d) - : dependency_info_ (d) {} - - // void operator= (const Subscriber_Set &); - // Copy. - - /// All the consumers that have registered for this event. - Subscriber_Set consumers_; - - /// Description of the method that generates this event. - RtecScheduler::Dependency_Info *dependency_info_; - }; - - typedef RtecEventComm::EventType EXT; - typedef Type_Subscribers *INT; - typedef ACE_Null_Mutex SYNCH; - typedef ACE_Map_Manager<EXT, INT, SYNCH> Subscriber_Map; - typedef ACE_Map_Iterator<EXT, INT, SYNCH> Subscriber_Map_Iterator; - typedef ACE_Map_Entry<EXT, INT> Subscriber_Map_Entry; - - /// Source-based subscribers. - Subscriber_Set source_subscribers_; - - /// Type-based subscribers. - Subscriber_Map type_subscribers_; - - // = These are just typedefs for source-based subscriptions. - typedef RtecEventComm::EventSourceID sEXT; - typedef Subscriber_Set *sINT; - typedef ACE_Map_Manager<sEXT, sINT, SYNCH> SourceID_Map; - typedef ACE_Map_Iterator<sEXT, sINT, SYNCH> SourceID_Map_Iterator; - typedef ACE_Map_Entry<sEXT, sINT> SourceID_Map_Entry; - - /// Serializes writes to source_subscribers_ and type_subscribers_. - ACE_ES_RW_LOCK lock_; - - /** - * <source_subscribers> contains a mapping of source id to consumer - * list. Insert <consumer> into the list of consumers subscribed to - * <sid>. Allocate a list for <sid> if necessary. - */ - static int insert_or_allocate (SourceID_Map &source_subscribers, - ACE_ES_Consumer_Rep *consumer, - RtecEventComm::EventSourceID sid); - - /** - * Add <consumer> to the set of consumers bound to <type> in - * <type_subscribers>. If there is consumer set for <type>, one is - * allocated. Returns -1 on failure, 0 otherwise. - */ - static int insert_or_allocate (Subscriber_Map &type_subscribers, - ACE_ES_Consumer_Rep *consumer, - RtecEventComm::EventType type); - - /** - * Add <consumer> to the set of consumers bound to <type> in - * <type_subscribers>. If there is consumer set for <type>, the - * operation fails. Returns -1 on failure, 0 otherwise. - */ - static int insert_or_fail (Subscriber_Map &type_subscribers, - ACE_ES_Consumer_Rep *consumer, - RtecEventComm::EventType type, - RtecScheduler::Dependency_Info *&dependency); - - /// Remove <consumer> from the consumer set in <type_map> set - /// corresponding to <type>. - static int remove (Subscriber_Map &type_map, - ACE_ES_Consumer_Rep *consumer, - RtecEventComm::EventType type); - - /// Remove <consumer> from the consumer set in the - /// <source_subscribers> set corresponding to <sid>. - static int remove (SourceID_Map &source_subscribers, - ACE_ES_Consumer_Rep *consumer, - RtecEventComm::EventSourceID sid); - - /// Insert all elements of <src> into <dest>. - static void append_subscribers (Subscriber_Set &dest, - Subscriber_Set &src); -}; - -// ************************************************************ - -// Forward declarations. -class ACE_ES_Dispatch_Request; -class ACE_Push_Consumer_Proxy; - -/** - * @class ACE_ES_Consumer_Correlation - * - * @brief Event Service Consumer_Correlation - * - * There is one Consumer Correlation object per call to - * connect_push_consumer. It handles all the consumer's - * correlation dependencies including timeouts. This is also a - * PushSupplier to support event forwarding. - */ -class TAO_RTOLDEvent_Export ACE_ES_Consumer_Correlation : public POA_RtecEventComm::PushSupplier -{ -public: - /// Default construction. - ACE_ES_Consumer_Correlation (void); - - /// Deletes lock_. - virtual ~ACE_ES_Consumer_Correlation (void); - - /** - * Initialization. <correlation_module> is stored for delegating - * channel operations. <consumer> is stored to access the consumers - * qos and filterin data. Returns 0 on success, -1 on failure. - */ - int connected (ACE_Push_Consumer_Proxy *consumer, - ACE_ES_Correlation_Module *correlation_module); - - /// Shutdown. - int disconnecting (void); - - /// Takes <event> and adds it to the correlation. Returns the - /// dispatch request that should be forwarded. - ACE_ES_Dispatch_Request *push (ACE_ES_Consumer_Rep *consumer, - const TAO_EC_Event& event); - - /// Stop forwarding events to the calling consumer. - void suspend (void); - - /// Resume forwarding events to the calling consumer. - void resume (void); - - /// Pointer back to the main correlation module. This is public so - /// that ACE_ES_Consumer_Rep_Timeout::execute can access it. - ACE_ES_Correlation_Module *correlation_module_; - -private: - /// Called when the channel disconnects us. - virtual void disconnect_push_supplier (ACE_ENV_SINGLE_ARG_DECL_NOT_USED) - ACE_THROW_SPEC ((CORBA::SystemException)); - - /// Dynamically allocates structures needed for correlations. 0 on - /// success, -1 on failure. - int allocate_correlation_resources (ACE_ES_Dependency_Iterator &iter); - - /// Helper function for this->push. - ACE_ES_Dispatch_Request * correlate (ACE_ES_Consumer_Rep *cr, - const TAO_EC_Event& event); - - // = Registration helper functions. - int register_deadline_timeout (RtecEventChannelAdmin::Dependency &dependency, - RtecEventComm::EventType group_type, - int cgindex, - int dgindex, - int &trep_index); - int register_interval_timeout (RtecEventChannelAdmin::Dependency &dependency, - RtecEventComm::EventType group_type, - int cgindex, - int dgindex, - int &trep_index); - int register_event (RtecEventChannelAdmin::Dependency &dependency, - RtecEventComm::EventType group_type, - int cgindex, - int dgindex, - int &crep_index); - - ACE_ES_Consumer_Rep *get_consumer_rep (RtecEventChannelAdmin::Dependency &dependency, - int &crep_index); - int new_type_id (void); - - int type_id_index_; - - /// For event forwarding. - RtecEventChannelAdmin::ProxyPushConsumer_ptr channel_; - - /// Supplier QOS specifications. - RtecEventChannelAdmin::SupplierQOS qos_; - - // Events waiting to be forwarded. - TAO_EC_Event_Array *pending_events_; - - // Used to synchronize pending_events_ and by the correlation module. - /// Used to lock shared state. - ACE_ES_MUTEX lock_; - - ACE_Push_Consumer_Proxy *consumer_; - - /// A bit is set for each dependency satisfied. - u_long pending_flags_; - - /// Array of consumer rep pointers. - ACE_ES_Consumer_Rep **consumer_reps_; - int n_consumer_reps_; - ACE_ES_Consumer_Rep_Timeout *timer_reps_; - int n_timer_reps_; - - ACE_ES_Conjunction_Group *conjunction_groups_; - int n_conjunction_groups_; - ACE_ES_Disjunction_Group *disjunction_groups_; - int n_disjunction_groups_; - - /// True when we're connected to the channel for forwarding. - int connected_; -}; - -// ************************************************************ - -/** - * @class ACE_ES_ACT - * - * @brief Event Service ACT - * - */ -class TAO_RTOLDEvent_Export ACE_ES_ACT -{ -public: - ACE_ES_ACT (void); - int has_act_; - RtecEventComm::Event act_; -}; - -// ************************************************************ - -// Forward declarations. -class ACE_ES_Dispatch_Request; - -/** - * @class ACE_ES_Consumer_Module - * - * @brief Event Service Consumer Module - * - * ProxyPushSupplier factory. - */ -class TAO_RTOLDEvent_Export ACE_ES_Consumer_Module : public POA_RtecEventChannelAdmin::ConsumerAdmin -{ -public: - /// Default construction. - ACE_ES_Consumer_Module (ACE_EventChannel *channel); - - /// Link to the next module. - void open (ACE_ES_Dispatching_Module *down); - - /// Factory method for push consumer proxies. - virtual RtecEventChannelAdmin::ProxyPushSupplier_ptr - obtain_push_supplier (ACE_ENV_SINGLE_ARG_DECL_NOT_USED) - ACE_THROW_SPEC ((CORBA::SystemException)); - - /// Register the consumer with the Event Service. This handles all - /// the details regarding Correlation_Module and Subscription_Module. - void connected (ACE_Push_Consumer_Proxy *consumer - ACE_ENV_ARG_DECL_NOT_USED); - - /// Unregister the consumer from the Event Service. - void disconnecting (ACE_Push_Consumer_Proxy *consumer - ACE_ENV_ARG_DECL_NOT_USED); - - virtual void push (const ACE_ES_Dispatch_Request *request - ACE_ENV_ARG_DECL_NOT_USED); - - /// Allow transformations to RtecEventChannelAdmin::ConsumerAdmin. - RtecEventChannelAdmin::ConsumerAdmin_ptr get_ref (ACE_ENV_SINGLE_ARG_DECL_NOT_USED); - - /// This is called by Shutdown_Consumer command objects when a - /// consumer proxy is ready to be deleted. - void shutdown_request (ACE_ES_Dispatch_Request *request); - - /// Actively disconnect from all consumers. - void shutdown (void); - - /** - * Fill the QoS with the disjuction off all the subscriptions in - * this EC. - * It leaves the gateways out of the list. - */ - void fill_qos (RtecEventChannelAdmin::ConsumerQOS& c_qos); - -private: - typedef ACE_Unbounded_Set_Iterator<ACE_Push_Consumer_Proxy *> Consumer_Iterator; - typedef ACE_Unbounded_Set<ACE_Push_Consumer_Proxy *> Consumers; - - /// Protects access to all_consumers_. - ACE_ES_MUTEX lock_; - - Consumers all_consumers_; - - /// Used to test for shutdown. - ACE_EventChannel *channel_; - - /// Next module down. - ACE_ES_Dispatching_Module *down_; -}; - -// ************************************************************ - -// Forward declaration. -class ACE_ES_Subscription_Module; - -/** - * @class ACE_ES_Correlation_Module - * - * @brief Event Service Correlation Module - * - */ -class TAO_RTOLDEvent_Export ACE_ES_Correlation_Module -{ -public: - /// Default construction. - ACE_ES_Correlation_Module (ACE_EventChannel *channel); - - /// Link to adjacent modules. - void open (ACE_ES_Dispatching_Module *up, - ACE_ES_Subscription_Module *down); - - /// Create the consumers filter object. - void connected (ACE_Push_Consumer_Proxy *consumer - ACE_ENV_ARG_DECL_NOT_USED); - - /// Release the consumers filter object. - void disconnecting (ACE_Push_Consumer_Proxy *consumer - ACE_ENV_ARG_DECL_NOT_USED); - - /** - * Take in an event and its subscriber. Apply consumer-specific - * filters to each event and forward any dispatch requests to the - * Dispatching Module. - */ - void push (ACE_ES_Consumer_Rep *consumer, - const TAO_EC_Event &event - ACE_ENV_ARG_DECL_NOT_USED); - - // = These are called by ACE_ES_Consumer_Reps. - - /// Forwards to the subscription module. - int subscribe (ACE_ES_Consumer_Rep *consumer); - - /// Forwards to the subscription module. - int unsubscribe (ACE_ES_Consumer_Rep *consumer); - - /// Schedule consumer timeout. Return 0 on success, -1 on failure. - int schedule_timeout (ACE_ES_Consumer_Rep_Timeout *consumer); - - /// Cancel consumer timeout. Return 0 on success, -1 on failure. - int cancel_timeout (ACE_ES_Consumer_Rep_Timeout *consumer); - - /// Reschedule consumer timeout. Return 0 on success, -1 on failure. - int reschedule_timeout (ACE_ES_Consumer_Rep_Timeout *consumer); - - /// The master channel. This is public so that Consumer_Correlation - /// objects can access it. - ACE_EventChannel *channel_; - - /// Does nothing. - void shutdown (void); - -private: - /// Next module up. - ACE_ES_Dispatching_Module *up_; - - /// Next module down. - ACE_ES_Subscription_Module *subscription_module_; -}; - -// ************************************************************ - -// Forward declaration. -class ACE_ES_Supplier_Module; -class ACE_Push_Supplier_Proxy; - -/** - * @class ACE_ES_Subscription_Module - * - * @brief Event Service Subscription Module - * - * = SYNCHRONIZATION - * This is currently implemented with very coarse-grain - * synchronization. Basically, there is a single readers/writer - * lock. All operations acquire the writer lock to change any - * subscription record. All operations acquire a reader lock to - * read any subscription record. This is fine for normal - * operations (which are *all* read operations). However, the - * initialization and shutdown periods might benefit from the - * potential increase in concurrency if we used finer grain locks - * (e.g., lock-per-source). - */ -class TAO_RTOLDEvent_Export ACE_ES_Subscription_Module -{ -public: - /// Default construction. - ACE_ES_Subscription_Module (ACE_EventChannel *channel); - - /// Link to the adjacent modules. - void open (ACE_ES_Correlation_Module *up, - ACE_ES_Supplier_Module *down); - - /// Deletes the lock_. - ~ACE_ES_Subscription_Module (void); - - /// Register a new consumer. Calls into <consumer> to figure out the - /// subscription options. Returns 0 on success, -1 on failure. - int subscribe (ACE_ES_Consumer_Rep *consumer); - - /// Removes the -consumer- from any subscription lists. - int unsubscribe (ACE_ES_Consumer_Rep *consumer); - - void connected (ACE_Push_Supplier_Proxy *supplier - ACE_ENV_ARG_DECL_NOT_USED); - void disconnecting (ACE_Push_Supplier_Proxy *supplier - ACE_ENV_ARG_DECL_NOT_USED); - - /// Takes in an event and pushes subscriber sets to the - /// Correlation Module. - void push (ACE_Push_Supplier_Proxy *source, - const TAO_EC_Event &event - ACE_ENV_ARG_DECL_NOT_USED); - - /// Unsubscribes all consumers from the suppliers. - void shutdown (void); - -private: - /// Reregister any consumers that registered for <source_id> before - /// it actually connected to the channel. - void reregister_consumers (RtecEventComm::EventSourceID source_id); - - /// The channel of all channels. - ACE_EventChannel *channel_; - - /// Source-only subscribers. - /* - typedef ACE_ES_Subscription_Info::Subscriber_Set INT; - typedef ACE_Null_Mutex SYNCH; - typedef ACE_Map_Manager<EXT, INT, SYNCH> Source_Collection; - typedef ACE_Map_Iterator<EXT, INT, SYNCH> Source_Collection_Iterator; - typedef ACE_Map_Entry<EXT, INT> Source_Collection_Entry; - Source_Collection source_subscription_info_; - */ - - // = Subscribe helper methods. Returns 0 on success, -1 on failure. - - int subscribe_all (ACE_ES_Consumer_Rep *consumer); - - int subscribe_type (ACE_ES_Consumer_Rep *consumer, - RtecEventComm::EventType type); - - int subscribe_source (ACE_ES_Consumer_Rep *consumer, - RtecEventComm::EventSourceID source); - - int subscribe_source_type (ACE_ES_Consumer_Rep *consumer, - RtecEventComm::EventSourceID source, - RtecEventComm::EventType type); - - int unsubscribe_all (ACE_ES_Consumer_Rep *consumer); - - int unsubscribe_type (ACE_ES_Consumer_Rep *consumer, - RtecEventComm::EventType type); - - int unsubscribe_source (ACE_ES_Consumer_Rep *consumer, - RtecEventComm::EventSourceID source); - - int unsubscribe_source_type (ACE_ES_Consumer_Rep *consumer, - RtecEventComm::EventSourceID source, - RtecEventComm::EventType type); - - // = Push helper methods. - - /// Push <event> to all consumers subscribed to all events from - /// <source>. Returns 0 on success, -1 on failure. - int push_source (ACE_Push_Supplier_Proxy *source, - const TAO_EC_Event &event - ACE_ENV_ARG_DECL); - - /// Push <event> to all consumers subscribed to <event>.type_ from - /// <source>. Returns 0 on success, -1 on failure. - int push_source_type (ACE_Push_Supplier_Proxy *source, - const TAO_EC_Event &event - ACE_ENV_ARG_DECL); - - /// Push <event> to all_suppliers_. - void push_all (const TAO_EC_Event &event - ACE_ENV_ARG_DECL_NOT_USED); - - /// Next module up stream. - ACE_ES_Correlation_Module *up_; - - /// Next module down stream. - ACE_ES_Supplier_Module *down_; - - typedef ACE_Unbounded_Set_Iterator<ACE_Push_Supplier_Proxy *> Supplier_Iterator; - typedef ACE_Unbounded_Set<ACE_Push_Supplier_Proxy *> Suppliers; - - /// All suppliers. - Suppliers all_suppliers_; - - /// Type-based subscribers. - ACE_ES_Subscription_Info::Subscriber_Map type_subscribers_; - - /// Source-based subscribers. - ACE_ES_Subscription_Info::SourceID_Map source_subscribers_; - - /// Protects access to all_suppliers_ and type_suppliers_; - ACE_ES_RW_LOCK lock_; - - /// The scheduler; - RtecScheduler::Scheduler_ptr scheduler_; -}; - -// ************************************************************ - -/** - * @class ACE_ES_Supplier_Module - * - * @brief Event Service Supplier Proxy Module - * - * ProxyPushConsumer factory. - */ -class TAO_RTOLDEvent_Export ACE_ES_Supplier_Module : public POA_RtecEventChannelAdmin::SupplierAdmin -{ -public: - /// Default construction. - ACE_ES_Supplier_Module (ACE_EventChannel *channel); - - /// Associate the module to a channel. - void open (ACE_ES_Subscription_Module *up); - - /// Factory method for push supplier proxies. - virtual RtecEventChannelAdmin::ProxyPushConsumer_ptr - obtain_push_consumer (ACE_ENV_SINGLE_ARG_DECL_NOT_USED) - ACE_THROW_SPEC ((CORBA::SystemException)); - - /// The supplier module acts on behalf of the supplier proxy to - /// forward events through the channel. - virtual void push (ACE_Push_Supplier_Proxy *proxy, - RtecEventComm::EventSet &event - ACE_ENV_ARG_DECL_NOT_USED); - - /// Register the consumer with the Event Service. This handles all - /// the details regarding Correlation_Module and Subscription_Module. - void connected (ACE_Push_Supplier_Proxy *supplier - ACE_ENV_ARG_DECL_NOT_USED); - - /// Unregister the consumer from the Event Service. - void disconnecting (ACE_Push_Supplier_Proxy *supplier - ACE_ENV_ARG_DECL_NOT_USED); - - /// Allow transformations to RtecEventComm::PushConsumer. - RtecEventChannelAdmin::SupplierAdmin_ptr get_ref (ACE_ENV_SINGLE_ARG_DECL_NOT_USED); - - /// Actively disconnect from all suppliers. - void shutdown (void); - - /** - * Fill the QoS with the disjuction off all the publications in - * this EC. - * It leaves the gateways out of the list. - */ - void fill_qos (RtecEventChannelAdmin::SupplierQOS& s_qos); - -private: - typedef ACE_Unbounded_Set_Iterator<ACE_Push_Supplier_Proxy *> Supplier_Iterator; - typedef ACE_Unbounded_Set<ACE_Push_Supplier_Proxy *> Suppliers; - - /// All suppliers. - Suppliers all_suppliers_; - - /// Protects access to all_suppliers_ and type_suppliers_; - ACE_ES_MUTEX lock_; - - ACE_ES_Subscription_Module *up_; - - /// Used to test for shutdown. - ACE_EventChannel *channel_; -}; - -// ************************************************************ - -// Forward declarations. -class ACE_EventChannel; - -// = Event Channel interfaces. - -/** - * @class ACE_Push_Supplier_Proxy - * - * @brief Push Supplier Proxy. - * - * To the channel, this is a proxy to suppliers. To suppliers, it - * exports a PushConsumer interface. It is a - * RtecEventChannelAdmin::ProxyPushConsumer. Suppliers use this - * interface to connect to the channel, push events to consumers, - * and to disconnect from the channel. - */ -class TAO_RTOLDEvent_Export ACE_Push_Supplier_Proxy : public POA_RtecEventChannelAdmin::ProxyPushConsumer, public PortableServer::RefCountServantBase -{ -public: - /// Must be created with an owning supplier admin. - ACE_Push_Supplier_Proxy (ACE_ES_Supplier_Module *supplier_module); - - // = Operations public to suppliers. - - /** - * Suppliers connect via this interface. <push_supplier> is a - * reference to the supplier. <qos> represents the publish types of - * the supplier. - */ - virtual void connect_push_supplier ( - RtecEventComm::PushSupplier_ptr push_supplier, - const RtecEventChannelAdmin::SupplierQOS& qos - ACE_ENV_ARG_DECL_NOT_USED) - ACE_THROW_SPEC ((CORBA::SystemException, - RtecEventChannelAdmin::AlreadyConnected)); - - /// Data arriving from a PushSupplier that must be sent to - /// consumers. This is the entry point of all events. - virtual void push (const RtecEventComm::EventSet &event - ACE_ENV_ARG_DECL_NOT_USED) - ACE_THROW_SPEC ((CORBA::SystemException)); - - /// Disconnect the supplier from the channel. - virtual void disconnect_push_consumer (ACE_ENV_SINGLE_ARG_DECL_NOT_USED) - ACE_THROW_SPEC ((CORBA::SystemException)); - - // = Operations for the Event Channel. - - /// Returns 1 if the proxy has been connected to a "remote" client. - int connected (void); - - /// Actively disconnect from the supplier. - void shutdown (void); - - // This is a hook so that the Subscription Module can associate - // state with supplier proxies. - ACE_ES_Subscription_Info &subscription_info (void); - - /// Filtering criteria. - RtecEventChannelAdmin::SupplierQOS &qos (void); - - /// Is this object a proxy for -rhs-. Simple pointer comparison for now. - bool operator== (const RtecEventComm::EventSourceID rhs); - - /// Returns underlying supplier object ref. - RtecEventComm::EventSourceID source_id (void); - - /// The QoS for this supplier - const RtecEventChannelAdmin::SupplierQOS& qos (void) const; - -private: - void time_stamp (RtecEventComm::EventSet &event); - -private: - /// Reference to the supplier's qos params. - RtecEventChannelAdmin::SupplierQOS qos_; - - ACE_ES_Subscription_Info subscription_info_; - - ACE_ES_Supplier_Module *supplier_module_; - - /// We keep a proxy of the Supplier source_id_; - RtecEventComm::EventSourceID source_id_; - - /// CORBA reference to remote push supplier. - RtecEventComm::PushSupplier_ptr push_supplier_; -}; - -// ************************************************************ - -/** - * @class ACE_Push_Consumer_Proxy - * - * @brief Push Consumer Proxy. - * - * This is the channels proxy to a push consumer. It implements - * the RtecEventChannelAdmin::ProxyPushSupplier IDL interface. - * Consumers use this interface to connect and disconnect from the - * channel. - */ -class TAO_RTOLDEvent_Export ACE_Push_Consumer_Proxy : public POA_RtecEventChannelAdmin::ProxyPushSupplier, public PortableServer::RefCountServantBase -{ -public: - /// Must be created with an consumer admin. - ACE_Push_Consumer_Proxy (ACE_ES_Consumer_Module *cm); - - /// Default destruction - virtual ~ACE_Push_Consumer_Proxy (void); - - // = Interfaces exported to consumers. - - /// A push consumer is connecting. <push_consumer> is a reference to - /// the consumer. <qos> is the subscription types for the consumer. - virtual void connect_push_consumer ( - RtecEventComm::PushConsumer_ptr push_consumer, - const RtecEventChannelAdmin::ConsumerQOS& qos - ACE_ENV_ARG_DECL_NOT_USED) - ACE_THROW_SPEC ((CORBA::SystemException, - RtecEventChannelAdmin::AlreadyConnected, - RtecEventChannelAdmin::TypeError)); - - /// The consumer is disconnecting. - virtual void disconnect_push_supplier (ACE_ENV_SINGLE_ARG_DECL_NOT_USED) - ACE_THROW_SPEC ((CORBA::SystemException)); - - /// Stop forwarding events to the calling consumer. - virtual void suspend_connection (ACE_ENV_SINGLE_ARG_DECL_NOT_USED) - ACE_THROW_SPEC ((CORBA::SystemException)); - - /// Resume forwarding events to the calling consumer. - virtual void resume_connection (ACE_ENV_SINGLE_ARG_DECL_NOT_USED) - ACE_THROW_SPEC ((CORBA::SystemException)); - - // = Event Channel operations. - - /// Push <events> to push_consumer_. - void push (const RtecEventComm::EventSet &events - ACE_ENV_ARG_DECL_NOT_USED); - - /// Returns 1 if the proxy has been connected to a "remote" client. - int connected (void); - - /// Actively disconnect from the consumer. - void shutdown (void); - - /// Access the consumer-specific Consumer_Correlation. - ACE_ES_Consumer_Correlation &correlation (void); - - /// Filtering criteria. - RtecEventChannelAdmin::ConsumerQOS &qos (void); - -private: - /// A reference to the consumers Quality of Service parameters. - RtecEventChannelAdmin::ConsumerQOS qos_; - - /// A hook so that the Correlation Module can associate correlation - /// information with the consumer. - ACE_ES_Consumer_Correlation correlation_; - - /// Reference to our push consumer. - RtecEventComm::PushConsumer_var push_consumer_; - - /// TODO: Maybe this should be a _var or _duplicate/_release should - /// be used - ACE_ES_Consumer_Module *consumer_module_; -}; - -#if defined (__ACE_INLINE__) -#include "Event_Channel.i" -#endif /* __ACE_INLINE__ */ - -#if defined(_MSC_VER) -#pragma warning(pop) -#endif /* _MSC_VER */ - -#include /**/ "ace/post.h" - -#endif /* ACE_EVENT_CHANNEL_H */ diff --git a/TAO/orbsvcs/orbsvcs/Event/Event_Channel.i b/TAO/orbsvcs/orbsvcs/Event/Event_Channel.i deleted file mode 100644 index 8007baa0d43..00000000000 --- a/TAO/orbsvcs/orbsvcs/Event/Event_Channel.i +++ /dev/null @@ -1,692 +0,0 @@ -/* -*- C++ -*- */ -// $Id$ - -const unsigned int ACE_INT2BIT[32] = -{ - 1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192, - 16384, 32768, 65536, 131072, 262144, 524288, 1048576, 2097152, - 4194304, 8388608, 16777216, 33554432, 67108864, 134217728, - 268435456, 536870912, 1073741824, 2147483648u, -}; - -// ************************************************** - -ACE_INLINE int -ACE_Push_Supplier_Proxy::connected (void) -{ - return !CORBA::is_nil((CORBA::Object*) push_supplier_); -} - -ACE_INLINE ACE_ES_Subscription_Info & -ACE_Push_Supplier_Proxy::subscription_info (void) -{ - return subscription_info_; -} - -ACE_INLINE RtecEventChannelAdmin::SupplierQOS & -ACE_Push_Supplier_Proxy::qos (void) -{ - return qos_; -} - -ACE_INLINE bool -ACE_Push_Supplier_Proxy::operator== (const RtecEventComm::EventSourceID rhs) -{ - // Pointer comparison is fine for now. - return (source_id_ == rhs); -} - -ACE_INLINE RtecEventComm::EventSourceID -ACE_Push_Supplier_Proxy::source_id (void) -{ - return source_id_; -} - -ACE_INLINE const RtecEventChannelAdmin::SupplierQOS& -ACE_Push_Supplier_Proxy::qos (void) const -{ - return this->qos_; -} - -// ************************************************** - -ACE_INLINE RtecEventChannelAdmin::ConsumerQOS & -ACE_Push_Consumer_Proxy::qos (void) -{ - return qos_; -} - -ACE_INLINE int -ACE_Push_Consumer_Proxy::connected (void) -{ - return !CORBA::is_nil(push_consumer_.in ()); -} - -ACE_INLINE ACE_ES_Consumer_Correlation & -ACE_Push_Consumer_Proxy::correlation (void) -{ - return correlation_; -} - -ACE_INLINE RtecEventChannelAdmin::ConsumerAdmin_ptr -ACE_ES_Consumer_Module::get_ref (ACE_ENV_SINGLE_ARG_DECL) -{ - return this->_this (ACE_ENV_SINGLE_ARG_PARAMETER); -} - -ACE_INLINE RtecEventChannelAdmin::SupplierAdmin_ptr -ACE_ES_Supplier_Module::get_ref (ACE_ENV_SINGLE_ARG_DECL) -{ - return this->_this (ACE_ENV_SINGLE_ARG_PARAMETER); -} - -// ************************************************** - -ACE_INLINE RtecEventChannelAdmin::EventChannel_ptr -ACE_EventChannel::get_ref (ACE_ENV_SINGLE_ARG_DECL) -{ - return this->_this (ACE_ENV_SINGLE_ARG_PARAMETER); -} - -ACE_INLINE RtecEventChannelAdmin::SupplierAdmin_ptr -ACE_EventChannel::for_suppliers (ACE_ENV_SINGLE_ARG_DECL) - ACE_THROW_SPEC ((CORBA::SystemException)) -{ - return supplier_module_->get_ref (ACE_ENV_SINGLE_ARG_PARAMETER); -} - -ACE_INLINE RtecEventChannelAdmin::ConsumerAdmin_ptr -ACE_EventChannel::for_consumers (ACE_ENV_SINGLE_ARG_DECL) - ACE_THROW_SPEC ((CORBA::SystemException)) -{ - return consumer_module_->get_ref (ACE_ENV_SINGLE_ARG_PARAMETER); -} - -ACE_INLINE TAO_EC_Timer_Module* -ACE_EventChannel::timer_module (void) const -{ - return this->timer_module_; -} - -// ************************************************************ - -// Makes a temporary Event_var and appends it to the <dest>. -ACE_INLINE void -operator += (TAO_EC_Event_Array &dest, - const TAO_EC_Event &item) -{ - size_t length = dest.size (); - dest.size (length + 1); - dest[length] = item; -} - -ACE_INLINE bool -operator == (const RtecEventComm::Event &event1, - const RtecEventComm::Event &event2) -{ - // Check if the sources are equal. 0 is a wildcard. - if ((event1.header.source != 0) - && (event2.header.source != 0) - && (event1.header.source != event2.header.source)) - return false; - - // Check if the types are equal. ACE_ES_EVENT_ANY is a wildcard. - if ((event1.header.type != ACE_ES_EVENT_ANY) && - (event2.header.type != ACE_ES_EVENT_ANY) && - (event1.header.type != event2.header.type)) - return false; - - return true; -} - -ACE_INLINE bool -operator != (const TAO_EC_Event& rhs, const TAO_EC_Event& lhs) -{ - if (rhs.empty () && lhs.empty ()) - return true; - if (rhs.empty () || lhs.empty ()) - return false; - return ! (rhs.event () == lhs.event ()); -} - - - -// ************************************************************ - -ACE_INLINE -ACE_ES_ACT::ACE_ES_ACT (void) - : has_act_ (0) -{ -} - -// ************************************************************ - -ACE_INLINE -ACE_ES_Disjunction_Group::ACE_ES_Disjunction_Group (void) : - act_ (), - deadline_timer_rep_ (0), - correlation_module_ (0) -{ -} - -ACE_INLINE void -ACE_ES_Disjunction_Group::set_correlation_module (ACE_ES_Correlation_Module *cm) -{ - correlation_module_ = cm; -} - -ACE_INLINE void -ACE_ES_Disjunction_Group::reschedule_deadline (void) -{ - if (deadline_timer_rep_ != 0) - { - if (correlation_module_->reschedule_timeout (deadline_timer_rep_) == -1) - ACE_ERROR ((LM_ERROR, "%p.\n", "ACE_ES_Disjunction_Group::reschedule_deadline")); - } -} - -ACE_INLINE int -ACE_ES_Disjunction_Group::set_deadline_timeout (ACE_ES_Consumer_Rep_Timeout *cr) -{ - deadline_timer_rep_ = cr; - // Schedule the timeout. - if (correlation_module_->schedule_timeout (deadline_timer_rep_) == -1) - return -1; - else - return 0; -} - -ACE_INLINE void -ACE_ES_Disjunction_Group::add_events (TAO_EC_Event_Array *outbox, - TAO_EC_Event_Array *, - u_long &) -{ - // Append the act. - if (!this->act_.empty ()) - *outbox += this->act_; -} - -ACE_INLINE void -ACE_ES_Disjunction_Group::set_act (RtecEventComm::Event &act) -{ - TAO_EC_Event_Set* set = TAO_EC_Event_Set::_create (act); - if (set == 0) - { - // @@ throw an exception... - ACE_ERROR ((LM_ERROR, "%p.\n", "ACE_ES_Disjunction_Group::set_act")); - return; - } - - this->act_ = TAO_EC_Event (set, 0); - TAO_EC_Event_Set::_release (set); -} - -// ************************************************************ - -ACE_INLINE -ACE_ES_Consumer_Rep::ACE_ES_Consumer_Rep (void) : - disconnected_ (0), - suspended_ (0), - correlation_type_ (ACE_ES_Consumer_Rep::NO_CORRELATION), - dependency_ (0), - correlation_ (0), - type_id_ (0), - disjunction_group_ (0), - ref_count_ (1) -{ -} - -ACE_INLINE void -ACE_ES_Consumer_Rep::init (ACE_ES_Consumer_Correlation *correlation, - RtecEventChannelAdmin::Dependency& dependency) -{ - dependency_ = &dependency; - correlation_ = correlation; -} - -ACE_INLINE RtecEventChannelAdmin::Dependency* -ACE_ES_Consumer_Rep::dependency (void) -{ - return dependency_; -} - -ACE_INLINE int -ACE_ES_Consumer_Rep::type_id (void) -{ - return type_id_; -} - -ACE_INLINE void -ACE_ES_Consumer_Rep::type_id (int id) -{ - type_id_ = id; -} - -ACE_INLINE ACE_ES_Consumer_Correlation * -ACE_ES_Consumer_Rep::correlation (void) -{ - return correlation_; -} - -ACE_INLINE u_long -ACE_ES_Consumer_Rep::correlation_type (void) -{ - return correlation_type_; -} - -ACE_INLINE void -ACE_ES_Consumer_Rep::correlation_type (u_long ct) -{ - correlation_type_ = ct; -} - -ACE_INLINE int -ACE_ES_Consumer_Rep::add_disjunction_group (ACE_ES_Disjunction_Group &dg) -{ - if (disjunction_group_ != 0) - ACE_ERROR ((LM_ERROR, "ACE_ES_Consumer_Rep::add_disjunction_group: " - "disjunction_group already set!\n")); - disjunction_group_ = &dg; - return 0; -} - -ACE_INLINE ACE_ES_Disjunction_Group * -ACE_ES_Consumer_Rep::top_group (void) -{ - return disjunction_group_; -} - -ACE_INLINE void -ACE_ES_Consumer_Rep::reschedule_deadlines (void) -{ - if (disjunction_group_ != 0) - disjunction_group_->reschedule_deadline (); -} - -ACE_INLINE int -ACE_ES_Consumer_Rep::receiving_events (void) -{ - return suspended_ == 0 && disconnected_ == 0; -} - -ACE_INLINE void -ACE_ES_Consumer_Rep::suspend (void) -{ - suspended_ = 1; -} - -ACE_INLINE void -ACE_ES_Consumer_Rep::resume (void) -{ - suspended_ = 0; -} - -ACE_INLINE void -ACE_ES_Consumer_Rep::_duplicate (void) -{ - // This is atomic. - ref_count_++; -} - -ACE_INLINE void -ACE_ES_Consumer_Rep::_release (void) -{ - // This is atomic. rc is because we want to avoid Atomic_Op's - // operator==. Don't change this code unless you think you're more - // studly than ACE_Atomic_Op. - int rc = --ref_count_; - - if (rc == 0) - delete this; -} - -ACE_INLINE int -ACE_ES_Consumer_Rep::disconnected (void) -{ - return disconnected_; -} - -ACE_INLINE void -ACE_ES_Consumer_Rep::disconnect (void) -{ - disconnected_ = 1; -} - -// ************************************************************ - -ACE_INLINE ACE_RTU_Manager * -ACE_EventChannel::rtu_manager (void) -{ - return rtu_manager_; -} - -ACE_INLINE -ACE_RTU_Manager::ACE_RTU_Manager (int active) - : active_ (active), - should_preempt_ (0), - not_done_ (0), - priority_ (ACE_Scheduler_MIN_PREEMPTION_PRIORITY) -{ -} - -ACE_INLINE int -ACE_RTU_Manager::should_preempt (void) -{ - if (!active_) - return 0; - else - { - // This routine was dead-code, but I'll leave it here until I - // find out what it is supposed to do. - ACE_ERROR ((LM_WARNING, - "EC (%t) RTU_Manager::should_preempt - obsolete\n")); - - int should_preempt = should_preempt_; - should_preempt_ = 0; - return should_preempt; - } -} - -ACE_INLINE void -ACE_RTU_Manager::should_preempt (int s) -{ - should_preempt_ = s; -} - -ACE_INLINE int -ACE_RTU_Manager::not_done (void) -{ - int not_done = not_done_; - not_done_ = 0; - return not_done; -} - -ACE_INLINE void -ACE_RTU_Manager::not_done (int nd) -{ - not_done_ = nd; -} - -ACE_INLINE RtecScheduler::OS_Priority -ACE_RTU_Manager::priority (void) -{ - return priority_; -} - -ACE_INLINE void -ACE_RTU_Manager::priority (RtecScheduler::OS_Priority p) -{ - priority_ = p; -} - -// ************************************************************ - -ACE_INLINE -ACE_ES_Consumer_Rep_Timeout::ACE_ES_Consumer_Rep_Timeout (void) - : timer_id_ (0), - preemption_priority_ (ACE_Scheduler_MIN_PREEMPTION_PRIORITY), - timeout_event_ () -{ -} - -ACE_INLINE void -ACE_ES_Consumer_Rep_Timeout::init (ACE_ES_Consumer_Correlation *correlation, - RtecEventChannelAdmin::Dependency &dep) -{ - TAO_EC_Event_Set *temp = TAO_EC_Event_Set::_create (dep.event); - // @@ TODO throw an exception - if (temp == 0) - { - ACE_ERROR ((LM_ERROR, "%p.\n", "ACE_ES_Consumer_Rep_Timeout::init")); - return; - } - - this->timeout_event_ = TAO_EC_Event (temp, 0); - TAO_EC_Event_Set::_release (temp); - - ACE_ES_Consumer_Rep::init (correlation, dep); -} - -ACE_INLINE long -ACE_ES_Consumer_Rep_Timeout::timer_id (void) -{ - return timer_id_; -} - -ACE_INLINE void -ACE_ES_Consumer_Rep_Timeout::timer_id (long id) -{ - timer_id_ = id; -} - -ACE_INLINE RtecScheduler::OS_Priority -ACE_ES_Consumer_Rep_Timeout::preemption_priority (void) -{ - return preemption_priority_; -} - -ACE_INLINE void -ACE_ES_Consumer_Rep_Timeout::preemption_priority (RtecScheduler::OS_Priority p) -{ - preemption_priority_ = p; -} - -// ************************************************************ - -ACE_INLINE void -ACE_ES_Consumer_Correlation::suspend (void) -{ - for (int x=0; x < n_timer_reps_; x++) - timer_reps_[x].suspend (); - - for (int y=0; y < n_consumer_reps_; y++) - consumer_reps_[y]->suspend (); -} - -ACE_INLINE void -ACE_ES_Consumer_Correlation::resume (void) -{ - for (int x=0; x < n_timer_reps_; x++) - timer_reps_[x].resume (); - - for (int y=0; y < n_consumer_reps_; y++) - consumer_reps_[y]->resume (); -} - -// ************************************************************ - -ACE_INLINE -ACE_ES_Dependency_Iterator::ACE_ES_Dependency_Iterator (RtecEventChannelAdmin::DependencySet &rep) : - rt_info_ (0), - rep_ (rep), - index_ (-1), - n_conjunctions_ (0), - n_disjunctions_ (0), - n_timeouts_ (0), - n_events_ (0) -{ -} - -ACE_INLINE int -ACE_ES_Dependency_Iterator::advance_dependency (void) -{ - index_++; - if ((CORBA::ULong) index_ >= rep_.length ()) - return -1; - else - return 0; -} - -ACE_INLINE RtecEventChannelAdmin::Dependency & -ACE_ES_Dependency_Iterator::operator *(void) -{ - return rep_[index_]; -} - -ACE_INLINE int -ACE_ES_Dependency_Iterator::parse (void) -{ - for (CORBA::ULong x = 0; x < rep_.length (); x++) - { - if (rt_info_ == 0) - rt_info_ = rep_[x].rt_info; - - switch (rep_[x].event.header.type) - { - case ACE_ES_CONJUNCTION_DESIGNATOR: - n_conjunctions_++; - break; - - case ACE_ES_DISJUNCTION_DESIGNATOR: - n_disjunctions_++; - break; - - case ACE_ES_EVENT_TIMEOUT: - case ACE_ES_EVENT_INTERVAL_TIMEOUT: - case ACE_ES_EVENT_DEADLINE_TIMEOUT: - n_timeouts_++; - break; - - default: - n_events_++; - break; - } - } - - return 0; -} - -ACE_INLINE int -ACE_ES_Dependency_Iterator::n_conjunctions (void) -{ - return n_conjunctions_; -} - -ACE_INLINE int -ACE_ES_Dependency_Iterator::n_disjunctions (void) -{ - return n_disjunctions_; -} - -ACE_INLINE int -ACE_ES_Dependency_Iterator::n_timeouts (void) -{ - return n_timeouts_; -} - -ACE_INLINE int -ACE_ES_Dependency_Iterator::n_events (void) -{ - return n_events_; -} - -ACE_INLINE RtecScheduler::handle_t -ACE_ES_Dependency_Iterator::first_rt_info (void) -{ - return rt_info_; -} - -// ************************************************************ - -ACE_INLINE -ACE_ES_Conjunction_Group::ACE_ES_Conjunction_Group (void) : - forward_value_ (0) -{ -} - -ACE_INLINE int -ACE_ES_Conjunction_Group::add_type (int type_id) -{ - ACE_SET_BITS (forward_value_, ACE_INT2BIT[type_id]); - return 0; -} - -/* - // Set length bits. - for (int x=0; x < length; x++) - { - forward_value_ <<= 1; - forward_value_ |= 1; - } - */ - -ACE_INLINE int -ACE_ES_Conjunction_Group::should_forward (u_long pending_flags) -{ - if ((forward_value_ & pending_flags) == forward_value_) - return 1; - else - return 0; -} - -ACE_INLINE void -ACE_ES_Conjunction_Group::add_events (TAO_EC_Event_Array *outbox, - TAO_EC_Event_Array *pending_events, - u_long &pending_flags) -{ - // Append the act first. - if (!this->act_.empty ()) - *outbox += this->act_; - - u_long fv = forward_value_; - int x = 0; - while (fv > 0) - { - // If this type_id is part of the correlation, then append each - // event pending to the outbox. - if (ACE_BIT_ENABLED (forward_value_, ACE_INT2BIT[x])) - { - // Step through each of the pending events. - TAO_EC_Event_Array &pending = pending_events[x]; - - size_t outbox_end = 0; - if (outbox != 0) - { - outbox_end = outbox->size (); - outbox->size (outbox_end + pending.size ()); - } - for (CORBA::ULong i = 0; i < pending.size (); ++i) - { - if (pending[i].empty ()) - continue; - - // Add the pending event to the outbox. - if (outbox != 0) - outbox->set (pending[i], outbox_end++); - - // Remove the event from the pending events array. - pending[i].clear (); - } - - // Reset the array length. - pending.size (0); - // Since we just emptied the events for this type, clear the - // x^th bit in pending flags. - ACE_CLR_BITS (pending_flags, ACE_INT2BIT[x]); - // Clear the x^th bit in fv. - ACE_CLR_BITS (fv, ACE_INT2BIT[x]); - } - - x++; - } -} - -// ************************************************************ - -ACE_INLINE int -ACE_EventChannel::cancel_timer (RtecScheduler::OS_Priority preemption_priority, - int id, - ACE_Command_Base *&act) -{ - return this->timer_module ()->cancel_timer (preemption_priority, - id, - act); -} - -ACE_INLINE RtecScheduler::Scheduler_ptr -ACE_EventChannel::scheduler (void) -{ - return RtecScheduler::Scheduler::_duplicate (this->scheduler_.in ()); -} - -// ************************************************************ diff --git a/TAO/orbsvcs/orbsvcs/Event/Event_Manip.cpp b/TAO/orbsvcs/orbsvcs/Event/Event_Manip.cpp deleted file mode 100644 index 0d8e97cb479..00000000000 --- a/TAO/orbsvcs/orbsvcs/Event/Event_Manip.cpp +++ /dev/null @@ -1,111 +0,0 @@ -/* -*- C++ -*- */ -// $Id$ -// -// ============================================================================ -// -// = LIBRARY -// TAO Real-tiem Event Services -// -// ============================================================================ - -#include "orbsvcs/Event/Event_Manip.h" - -#if !defined (__ACE_INLINE__) -#include "Event_Manip.i" -#endif /* __ACE_INLINE__ */ - -TAO_EC_Event_Set::~TAO_EC_Event_Set (void) -{ - RtecEventComm::EventSet::freebuf (this->buffer_); - this->buffer_ = 0; - this->length_ = 0; -} - -TAO_EC_Event_Set* -TAO_EC_Event_Set::_create (const RtecEventComm::Event& event) -{ - RtecEventComm::Event* buffer = - RtecEventComm::EventSet::allocbuf (1); - buffer[0] = event; - return new TAO_EC_Event_Set (1, buffer); -} - -TAO_EC_Event_Set* -TAO_EC_Event_Set::_create (RtecEventComm::EventSet& event_set) -{ - // Orphan the buffer.... - CORBA::ULong length = event_set.length (); - return new TAO_EC_Event_Set (length, - event_set.get_buffer (1)); -} - -CORBA::ULong -TAO_EC_Event_Set::_incr_refcnt (void) -{ - ACE_GUARD_RETURN (TAO_SYNCH_MUTEX, ace_mon, this->lock_, 0); - return this->refcnt_++; -} - -CORBA::ULong -TAO_EC_Event_Set::_decr_refcnt (void) -{ - { - ACE_GUARD_RETURN (TAO_SYNCH_MUTEX, ace_mon, this->lock_, 0); - this->refcnt_--; - if (this->refcnt_ != 0) - return this->refcnt_; - } - - delete this; - return 0; -} - -// **************************************************************** - -TAO_EC_Event::TAO_EC_Event (void) - : event_set_ (0), - index_ (0) -{ -} - -TAO_EC_Event::TAO_EC_Event (TAO_EC_Event_Set *event_set, - CORBA::ULong index) - : event_set_ (TAO_EC_Event_Set::_duplicate (event_set)), - index_ (index) -{ -} - -TAO_EC_Event::~TAO_EC_Event (void) -{ - TAO_EC_Event_Set::_release (this->event_set_); - this->event_set_ = 0; -} - -TAO_EC_Event::TAO_EC_Event (const TAO_EC_Event& rhs) - : event_set_ (TAO_EC_Event_Set::_duplicate (rhs.event_set_)), - index_ (rhs.index_) -{ -} - -TAO_EC_Event& -TAO_EC_Event::operator= (const TAO_EC_Event& rhs) -{ - if (this == &rhs) - return *this; - - // Be careful, increase the reference count and then release our - // event set, just in case they happen to be the same. - TAO_EC_Event_Set* tmp = - TAO_EC_Event_Set::_duplicate (rhs.event_set_); - - TAO_EC_Event_Set::_release (this->event_set_); - this->event_set_ = tmp; - this->index_ = rhs.index_; - - return *this; -} - - - - - diff --git a/TAO/orbsvcs/orbsvcs/Event/Event_Manip.h b/TAO/orbsvcs/orbsvcs/Event/Event_Manip.h deleted file mode 100644 index b78511867b5..00000000000 --- a/TAO/orbsvcs/orbsvcs/Event/Event_Manip.h +++ /dev/null @@ -1,148 +0,0 @@ -/* -*- C++ -*- */ -//============================================================================= -/** - * @file Event_Manip.h - * - * $Id$ - * - * @author Carlos O'Ryan (coryan@cs.wust.edu) - * - * The Event Channel uses some of this classes to simplify its event - * manipulation. - * For instance it keeps a reference counted RtecEventComm::EventSet - * and classes to automatically manage this reference count. - * - * - */ -//============================================================================= - - -#ifndef TAO_EC_EVENT_MANIP_H -#define TAO_EC_EVENT_MANIP_H -#include /**/ "ace/pre.h" - -#include "orbsvcs/RtecEventCommC.h" -#include "old_event_export.h" - -/** - * @class TAO_EC_Event_Set - * - * @brief A reference counted RtecEventComm::EventSet - * - * The Event_Channel receives an event set from its suppliers, but - * it has to pass it to (potentially) multiple consumers, running - * at different priorities. - * Thus is is difficult to know in advance the life time of this - * EventSet. - */ -class TAO_RTOLDEvent_Export TAO_EC_Event_Set -{ -public: - /// Constructor... - TAO_EC_Event_Set (CORBA::ULong length, - RtecEventComm::Event* buffer); - - /// destructor - ~TAO_EC_Event_Set (void); - - /// The length. - CORBA::ULong length (void) const; - - /// Access a particular element. - RtecEventComm::Event& operator[] (CORBA::ULong i) const; - - /// Create from an event set. - static TAO_EC_Event_Set* _create (const RtecEventComm::Event&); - static TAO_EC_Event_Set* _create (RtecEventComm::EventSet&); - - /// Reference counting. - static TAO_EC_Event_Set* _duplicate (TAO_EC_Event_Set*); - static void _release (TAO_EC_Event_Set*); - -private: - /// Manipulate the reference count. - CORBA::ULong _incr_refcnt (void); - CORBA::ULong _decr_refcnt (void); - -private: - ACE_UNIMPLEMENTED_FUNC (TAO_EC_Event_Set (const TAO_EC_Event_Set&)) - ACE_UNIMPLEMENTED_FUNC (TAO_EC_Event_Set& operator= (const TAO_EC_Event_Set&)) - -private: - /// The length of the buffer. - CORBA::ULong length_; - - /// The buffer. - RtecEventComm::Event* buffer_; - - /// Synchronize access to the class internals. - TAO_SYNCH_MUTEX lock_; - - /// The reference count. - CORBA::ULong refcnt_; -}; - -/** - * @class TAO_EC_Event - * - * @brief A smart event class. - * - * Inside the Event Channl a set of events is broken into the - * events that compose it and processed independently. - * To minimize data copying and memory allocations the Event is - * represented as a smart reference to one element of the - * reference counted Event Set (see TAO_EC_Event_Set above). - * Events can be chained together using a cont() field, much like - * ACE_Message_Block. - */ -class TAO_RTOLDEvent_Export TAO_EC_Event -{ -public: - /// Default constructor. - TAO_EC_Event (void); - - /// Constructor, we assume ownership (i.e. duplicate and release the - /// set) - TAO_EC_Event (TAO_EC_Event_Set *event_set, - CORBA::ULong index); - - /// Destructor - ~TAO_EC_Event (void); - - /// "Deep" copy, i.e. increases the reference count. - TAO_EC_Event (const TAO_EC_Event& event); - TAO_EC_Event& operator= (const TAO_EC_Event& event); - - /// Return true if there is no event inside this object. - int empty (void) const; - - /// Release the event... - void clear (void); - - /// The event.. - RtecEventComm::Event& event (void); - const RtecEventComm::Event& event (void) const; - - // = Shortcuts - RtecEventComm::EventHeader& header (void); - RtecEventComm::EventData& data (void); - const RtecEventComm::EventHeader& header (void) const; - const RtecEventComm::EventData& data (void) const; - - RtecEventComm::EventSourceID source (void) const; - RtecEventComm::EventType type (void) const; - -private: - /// The event set. - TAO_EC_Event_Set *event_set_; - - /// The position of the event in the set - CORBA::ULong index_; -}; - -#if defined (__ACE_INLINE__) -#include "Event_Manip.i" -#endif /* __ACE_INLINE__ */ - -#include /**/ "ace/post.h" -#endif /* TAO_EC_EVENT_MANIP_H */ diff --git a/TAO/orbsvcs/orbsvcs/Event/Event_Manip.i b/TAO/orbsvcs/orbsvcs/Event/Event_Manip.i deleted file mode 100644 index 15d2bf13371..00000000000 --- a/TAO/orbsvcs/orbsvcs/Event/Event_Manip.i +++ /dev/null @@ -1,104 +0,0 @@ -// $Id$ - -ACE_INLINE -TAO_EC_Event_Set::TAO_EC_Event_Set (CORBA::ULong length, - RtecEventComm::Event* buffer) - : length_ (length), - buffer_ (buffer), - refcnt_ (1) -{ -} - -ACE_INLINE CORBA::ULong -TAO_EC_Event_Set::length (void) const -{ - return this->length_; -} - -ACE_INLINE RtecEventComm::Event& -TAO_EC_Event_Set::operator[] (CORBA::ULong i) const -{ - return this->buffer_[i]; -} - -ACE_INLINE TAO_EC_Event_Set* -TAO_EC_Event_Set::_duplicate (TAO_EC_Event_Set* x) -{ - if (x == 0) - return 0; - x->_incr_refcnt (); - return x; -} - -ACE_INLINE void -TAO_EC_Event_Set::_release (TAO_EC_Event_Set* x) -{ - if (x == 0) - return; - x->_decr_refcnt (); -} - - -// **************************************************************** - -ACE_INLINE int -TAO_EC_Event::empty (void) const -{ - return this->event_set_ == 0; -} - -ACE_INLINE void -TAO_EC_Event::clear (void) -{ - TAO_EC_Event_Set::_release (this->event_set_); - this->event_set_ = 0; - this->index_ = 0; -} - -ACE_INLINE RtecEventComm::Event& -TAO_EC_Event::event (void) -{ - return (*this->event_set_)[this->index_]; -} - -ACE_INLINE const RtecEventComm::Event& -TAO_EC_Event::event (void) const -{ - return (*this->event_set_)[this->index_]; -} - -ACE_INLINE RtecEventComm::EventHeader& -TAO_EC_Event::header (void) -{ - return this->event ().header; -} - -ACE_INLINE const RtecEventComm::EventHeader& -TAO_EC_Event::header (void) const -{ - return this->event ().header; -} - -ACE_INLINE RtecEventComm::EventData& -TAO_EC_Event::data (void) -{ - return this->event ().data; -} - -ACE_INLINE const RtecEventComm::EventData& -TAO_EC_Event::data (void) const -{ - return this->event ().data; -} - -ACE_INLINE RtecEventComm::EventSourceID -TAO_EC_Event::source (void) const -{ - return this->event ().header.source; -} - -ACE_INLINE RtecEventComm::EventType -TAO_EC_Event::type (void) const -{ - return this->event ().header.type; -} diff --git a/TAO/orbsvcs/orbsvcs/Event/Fast_Reactor.h b/TAO/orbsvcs/orbsvcs/Event/Fast_Reactor.h deleted file mode 100644 index 78c2fada786..00000000000 --- a/TAO/orbsvcs/orbsvcs/Event/Fast_Reactor.h +++ /dev/null @@ -1,63 +0,0 @@ -// -// $Id$ -// -#ifndef FAST_REACTOR_H -#define FAST_REACTOR_H -#include /**/ "ace/pre.h" - -#if defined (ACE_OLD_STYLE_REACTOR) -# if defined (ACE_WIN32) -# include "ace/ReactorEx.h" - -#if !defined (ACE_LACKS_PRAGMA_ONCE) -# pragma once -#endif /* ACE_LACKS_PRAGMA_ONCE */ - -# define ACE_ES_FAST_REACTOR_BASE ACE_ReactorEx -# else -# include "ace/Reactor.h" -# define ACE_ES_FAST_REACTOR_BASE ACE_Reactor -# endif /* ACE_WIN32 */ -#else -# if defined (ACE_WIN32) -# include "ace/WFMO_Reactor.h" -# define ACE_ES_FAST_REACTOR_BASE ACE_WFMO_Reactor -# else -# include "ace/Select_Reactor.h" -# define ACE_ES_FAST_REACTOR_BASE ACE_Select_Reactor -# endif /* ACE_WIN32 */ -#endif /* ACE_OLD_STYLE_REACTOR */ -//## end module.includes - -#include "old_event_export.h" -#include "ace/OS_NS_sys_select.h" - -class TAO_RTOLDEvent_Export ACE_ES_Fast_Reactor : public ACE_ES_FAST_REACTOR_BASE -{ -public: - virtual int handle_events (ACE_Time_Value *max_wait_time = 0) - { - ACE_Time_Value timer_buf (0) ; - ACE_Time_Value *this_timeout = &timer_buf ; - - if (this->timer_queue_->calculate_timeout (max_wait_time, - this_timeout) == 0) - { - ACE_Time_Value t (0, 500000); - ACE_OS::select (0, 0, 0, 0, &t); - } - else - { - ACE_OS::select (0, 0, 0, 0, this_timeout); - } - - return this->timer_queue_->expire () == -1 ? -1 : 0; - } - virtual int handle_events (ACE_Time_Value &max_wait_time) - { - return this->handle_events (&max_wait_time); - } -}; - -#include /**/ "ace/post.h" -#endif /* FAST_REACTOR_H */ diff --git a/TAO/orbsvcs/orbsvcs/Event/GPlot_File.cpp b/TAO/orbsvcs/orbsvcs/Event/GPlot_File.cpp deleted file mode 100644 index 12e46cba5a4..00000000000 --- a/TAO/orbsvcs/orbsvcs/Event/GPlot_File.cpp +++ /dev/null @@ -1,182 +0,0 @@ -//============================================================================= -/** - * @file GPlot_File.cpp - * - * $Id$ - * - * @author Tim Harrison - */ -//============================================================================= - - -#include "GPlot_File.h" -#include "ace/OS_NS_string.h" -#include "ace/OS_NS_stdio.h" - -#if !defined (__ACE_INLINE__) -#include "GPlot_File.i" -#endif /* __ACE_INLINE__ */ - -ACE_RCSID(Event, GPlot_File, "$Id$") - -int -ACE_GPlot_File::open (const char *filename) -{ - ACE_OS::strcpy (filename_, filename); - - FILE *read_file = ACE_OS::fopen (ACE_TEXT_CHAR_TO_TCHAR(filename_), ACE_LIB_TEXT("r")); - - long entry; - char *value; - ACE_NEW_RETURN (value, char [32], -1); - - if (read_file > 0) - { - int result; - do - { - result = fscanf (read_file, - "%ld\t%s\n", - &entry, - value); - - //if ((result == -1) && (ACE_OS::last_error () != 0)) - //ACE_ERROR_RETURN ((LM_ERROR, "%p.\n", "ACE_GPlot_File::open"), -1); - - if (result > 0) - // Success. - map_.bind (entry, value); - else if (result != EOF) - // Error. - { - ACE_OS::fclose (read_file); - ACE_ERROR_RETURN - ((LM_ERROR, "Error reading GPlot file %s.\n", filename_), -1); - } - } while (result != EOF); - - fclose (read_file); - } - - write_file_ = ACE_OS::fopen (ACE_TEXT_CHAR_TO_TCHAR(filename_), ACE_LIB_TEXT("w")); - if (write_file_ == 0) - ACE_ERROR_RETURN ((LM_ERROR, "%p: can't open\n", filename_), -1); - - closed_ = 0; - - return 0; -} - - -void -ACE_GPlot_File::close (void) -{ - if (closed_ == 0) - { - closed_ = 1; - GPLOT_ITERATOR iterator ((GPLOT_MAP &) map_); - for (GPLOT_ENTRY *entry; iterator.next (entry); iterator.advance ()) - { - ACE_OS::fprintf (write_file_, "%ld\t%s\n", - entry->ext_id_, entry->int_id_); - delete [] entry->int_id_; - } - - ACE_OS::fclose (write_file_); - } -} - - -void -ACE_GPlot_File::dump (void) -{ - GPLOT_ITERATOR iterator ((GPLOT_MAP &) map_); - for (GPLOT_ENTRY *entry; iterator.next (entry); iterator.advance ()) - { - if (entry->int_id_ != 0) - ACE_DEBUG ((LM_DEBUG, "%d\t%s\n", entry->ext_id_, entry->int_id_)); - else - { - ACE_ERROR ((LM_ERROR, "Value for entry %d is null.\n", - entry->ext_id_)); - return; - } - } -} - - -int -ACE_GPlot_File::get (long entry, long &value) -{ - char *val; - - if (map_.find (entry, val) == -1) - return -1; - else - { - ::sscanf (val, "%ld", &value); - return 0; - } -} - - -int -ACE_GPlot_File::get (long entry, float &value) -{ - char *val; - - if (map_.find (entry, val) == -1) - return -1; - else - { - ::sscanf (val, "%f", &value); - return 0; - } -} - - -void -ACE_GPlot_File::set (long entry, long value) -{ - long old_entry; - char *val; - char *old_value = 0; - - ACE_NEW (val, char [32]); - - ::sprintf (val, "%ld", value); - map_.rebind (entry, val, old_entry, old_value); - - delete [] old_value; -} - - -void -ACE_GPlot_File::set (long entry, float value) -{ - long old_entry; - char *val; - char *old_value = 0; - - ACE_NEW (val, char [32]); - - ::sprintf (val, "%f", value); - map_.rebind (entry, val, old_entry, old_value); - - delete [] old_value; -} - - -#if defined (ACE_HAS_EXPLICIT_TEMPLATE_INSTANTIATION) -template class ACE_Map_Entry<long, char *>; -template class ACE_Map_Manager<long, char *, ACE_Null_Mutex>; -template class ACE_Map_Iterator_Base<long, char *, ACE_Null_Mutex>; -template class ACE_Map_Iterator<long, char *, ACE_Null_Mutex>; -template class ACE_Map_Reverse_Iterator<long, char *, ACE_Null_Mutex>; -#elif defined(ACE_HAS_TEMPLATE_INSTANTIATION_PRAGMA) -#pragma instantiate ACE_Map_Entry<long, char *> -#pragma instantiate ACE_Map_Manager<long, char *, ACE_Null_Mutex> -#pragma instantiate ACE_Map_Iterator_Base<long, char *, ACE_Null_Mutex> -#pragma instantiate ACE_Map_Iterator<long, char *, ACE_Null_Mutex> -#pragma instantiate ACE_Map_Reverse_Iterator<long, char *, ACE_Null_Mutex> -#endif /* ACE_HAS_EXPLICIT_TEMPLATE_INSTANTIATION */ diff --git a/TAO/orbsvcs/orbsvcs/Event/GPlot_File.h b/TAO/orbsvcs/orbsvcs/Event/GPlot_File.h deleted file mode 100644 index 2975c9df458..00000000000 --- a/TAO/orbsvcs/orbsvcs/Event/GPlot_File.h +++ /dev/null @@ -1,108 +0,0 @@ -//============================================================================= -/** - * @file GPlot_File.h - * - * $Id$ - * - * @author Tim Harrison - */ -//============================================================================= - - -#ifndef ACE_GPlot_File_H -#define ACE_GPlot_File_H -#include /**/ "ace/pre.h" - -#include "ace/Map_Manager.h" -#include "old_event_export.h" - -#if !defined (ACE_LACKS_PRAGMA_ONCE) -# pragma once -#endif /* ACE_LACKS_PRAGMA_ONCE */ - -#include "ace/Null_Mutex.h" - -/** - * @class ACE_GPlot_File - * - * @brief Reads and writes files in GPlot format. - * - * Gplot formats are as follows: - * entry value - * entry value - * entry value - * ... - * They represent x,y pairs to be graphed by GPlot. entry's are - * type long. value's are type long or float. - */ -class TAO_RTOLDEvent_Export ACE_GPlot_File -{ -public: - /// Construction. - ACE_GPlot_File (void); - - /// Destruction. Calls this->close. - ~ACE_GPlot_File (void); - - /** - * If the file does not exist, create it. If the file exists open - * the file and read all the entries into map_. Returns 0 on - * success, -1 on failure. - */ - int open (const char *filename); - - /// Close the file and sync all the contents. - void close (void); - - /// Get the entry at this value. Returns 0 if a value was found. - /// Returns -1 if no value has been set for <entry>. - int get (long entry, long &value); - - /// Get the entry at this value. Returns 0 if a value was found. - /// Returns -1 if no value has been set for <entry>. - int get (long entry, float &value); - - /// Set the entry at this value. - void set (long entry, long value); - - /// Set the entry at this value. - void set (long entry, float value); - - /// Compare <value> with the value at <entry>. Store the largest. - void set_greatest (long entry, long value); - - /// Compare <value> with the value at <entry>. Store the largest. - void set_greatest (long entry, float value); - - /// Compare <value> with the value at <entry>. Store the smallest. - void set_least (long entry, long value); - - /// Compare <value> with the value at <entry>. Store the smallest. - void set_least (long entry, float value); - - /// Dump state of the object. - void dump (void); - -private: - // = map_ stores all values. It is sync'ed to file when this->close - // is called. - typedef ACE_Map_Entry <long, char *> GPLOT_ENTRY; - typedef ACE_Map_Manager<long, char *, ACE_Null_Mutex> GPLOT_MAP; - typedef ACE_Map_Iterator <long, char *, ACE_Null_Mutex> GPLOT_ITERATOR; - - GPLOT_MAP map_; - - char filename_[BUFSIZ]; - FILE *write_file_; - - /// Only close once. - int closed_; -}; - -#if defined (__ACE_INLINE__) -#include "GPlot_File.i" -#endif /* __ACE_INLINE__ */ - - -#include /**/ "ace/post.h" -#endif /* ACE_GPlot_File_H */ diff --git a/TAO/orbsvcs/orbsvcs/Event/GPlot_File.i b/TAO/orbsvcs/orbsvcs/Event/GPlot_File.i deleted file mode 100644 index ab9f235dc39..00000000000 --- a/TAO/orbsvcs/orbsvcs/Event/GPlot_File.i +++ /dev/null @@ -1,70 +0,0 @@ -// $Id$ - -ACE_INLINE -ACE_GPlot_File::ACE_GPlot_File (void) - : closed_ (1) -{ -} - - -ACE_INLINE -ACE_GPlot_File::~ACE_GPlot_File (void) -{ - this->close (); -} - - -ACE_INLINE -void -ACE_GPlot_File::set_greatest (long entry, long value) -{ - long old_value; - - // If there was no previous value, or the <value> is greater than - // the previous value, set a new value. - if (this->get (entry, old_value) == -1 || - value > old_value) - this->set (entry, value); -} - - -ACE_INLINE -void -ACE_GPlot_File::set_greatest (long entry, float value) -{ - float old_value; - - // If there was no previous value, or the <value> is greater than - // the previous value, set a new value. - if (this->get (entry, old_value) == -1 || - value > old_value) - this->set (entry, value); -} - - -ACE_INLINE -void -ACE_GPlot_File::set_least (long entry, long value) -{ - long old_value; - - // If there was no previous value, or the <value> is less than - // the previous value, set a new value. - if (this->get (entry, old_value) == -1 || - value < old_value) - this->set (entry, value); -} - - -ACE_INLINE -void -ACE_GPlot_File::set_least (long entry, float value) -{ - float old_value; - - // If there was no previous value, or the <value> is less than - // the previous value, set a new value. - if (this->get (entry, old_value) == -1 || - value < old_value) - this->set (entry, value); -} diff --git a/TAO/orbsvcs/orbsvcs/Event/Local_ESTypes.cpp b/TAO/orbsvcs/orbsvcs/Event/Local_ESTypes.cpp deleted file mode 100644 index 795db6f4916..00000000000 --- a/TAO/orbsvcs/orbsvcs/Event/Local_ESTypes.cpp +++ /dev/null @@ -1,7 +0,0 @@ -// -// $Id$ -// - -#include "Local_ESTypes.h" - -ACE_RCSID(Event, Local_ESTypes, "$Id$") diff --git a/TAO/orbsvcs/orbsvcs/Event/Local_ESTypes.h b/TAO/orbsvcs/orbsvcs/Event/Local_ESTypes.h deleted file mode 100644 index cc7e66b9fb5..00000000000 --- a/TAO/orbsvcs/orbsvcs/Event/Local_ESTypes.h +++ /dev/null @@ -1,43 +0,0 @@ -/* -*- C++ -*- */ -//============================================================================= -/** - * @file Local_ESTypes.h - * - * $Id$ - * - * @author Tim Harrison (harrison@cs.wustl.edu) - * - * Manual types that would otherwise be defined/implemented via an - * IDL compiler. - * NOTE: the file is obsolecent, we have TAO now, but we keep it - * to speed up the porting. - * - * - */ -//============================================================================= - - -#ifndef ACE_LOCAL_ESTYPES_H -#define ACE_LOCAL_ESTYPES_H - -#include /**/ "ace/pre.h" - -#include "orbsvcs/Event_Service_Constants.h" - -#include "orbsvcs/RtecSchedulerC.h" -#include "orbsvcs/RtecSchedulerS.h" -#include "orbsvcs/RtecEventCommC.h" -#include "orbsvcs/RtecEventCommS.h" -#include "orbsvcs/RtecEventChannelAdminC.h" -#include "orbsvcs/RtecEventChannelAdminS.h" - -#define ACE_DEFAULT_EVENT_CHANNEL_TYPE 0 - -// These are to help MSVC++ 4.2 deal with inheritence of nested types. -// Not needed for Sun C++ or MSVC++ 5.0. - -typedef RtecEventComm::Event RtecEventComm_Event; - -#include /**/ "ace/post.h" - -#endif /* ACE_LOCAL_ESTYPES_H */ diff --git a/TAO/orbsvcs/orbsvcs/Event/Memory_Pools.cpp b/TAO/orbsvcs/orbsvcs/Event/Memory_Pools.cpp deleted file mode 100644 index 88af47cb106..00000000000 --- a/TAO/orbsvcs/orbsvcs/Event/Memory_Pools.cpp +++ /dev/null @@ -1,47 +0,0 @@ -// $Id$ - -#include "Memory_Pools.h" -#include "Event_Channel.h" - -#if !defined (__ACE_INLINE__) -#include "Memory_Pools.i" -#endif /* __ACE_INLINE__ */ - -ACE_RCSID(Event, Memory_Pools, "$Id$") - -//ACE_TSS<ACE_ES_Dispatch_Request_Allocator> ACE_ES_Memory_Pools::Dispatch_Request_; - -// ************************************************************ - -int -ACE_ES_Memory_Pools::thr_init (void) -{ - // Allocate the memory pool for this thread. - //Dispatch_Request_.ts_object (); - //Event_.ts_object (); - return 0; -} - -// ************************************************************ - -#if defined (ACE_HAS_EXPLICIT_TEMPLATE_INSTANTIATION) - -template class ACE_Cached_Mem_Pool_Node<ACE_ES_Dispatch_Request_Chunk>; -template class ACE_Locked_Free_List<ACE_Cached_Mem_Pool_Node<ACE_ES_Dispatch_Request_Chunk>, ACE_Null_Mutex>; -template class ACE_Free_List<ACE_Cached_Mem_Pool_Node<ACE_ES_Dispatch_Request_Chunk> >; -template class ACE_Cached_Allocator<ACE_ES_Dispatch_Request_Chunk, ACE_MEMORY_POOL_MUTEX>; -template class ACE_Singleton<ACE_ES_Dispatch_Request_Allocator,TAO_SYNCH_MUTEX>; - -#elif defined(ACE_HAS_TEMPLATE_INSTANTIATION_PRAGMA) - -#pragma instantiate ACE_Cached_Allocator<ACE_ES_Dispatch_Request_Chunk, ACE_MEMORY_POOL_MUTEX> -#pragma instantiate ACE_Cached_Mem_Pool_Node<ACE_ES_Dispatch_Request_Chunk> -#pragma instantiate ACE_Locked_Free_List<ACE_Cached_Mem_Pool_Node<ACE_ES_Dispatch_Request_Chunk>, ACE_Null_Mutex> -#pragma instantiate ACE_Free_List<ACE_Cached_Mem_Pool_Node<ACE_ES_Dispatch_Request_Chunk> > -#pragma instantiate ACE_Singleton<ACE_ES_Dispatch_Request_Allocator,TAO_SYNCH_MUTEX> - -#elif defined (ACE_HAS_EXPLICIT_STATIC_TEMPLATE_MEMBER_INSTANTIATION) - -template ACE_Singleton<ACE_ES_Dispatch_Request_Allocator, ACE_Thread_Mutex> *ACE_Singleton<ACE_ES_Dispatch_Request_Allocator, ACE_Thread_Mutex>::singleton_; - -#endif /* ACE_HAS_EXPLICIT_TEMPLATE_INSTANTIATION */ diff --git a/TAO/orbsvcs/orbsvcs/Event/Memory_Pools.h b/TAO/orbsvcs/orbsvcs/Event/Memory_Pools.h deleted file mode 100644 index c79028c029f..00000000000 --- a/TAO/orbsvcs/orbsvcs/Event/Memory_Pools.h +++ /dev/null @@ -1,92 +0,0 @@ -/* -*- C++ -*- */ -//============================================================================= -/** - * @file Memory_Pools.h - * - * $Id$ - * - * @author Tim Harrison (harrison@cs.wustl.edu) - */ -//============================================================================= - - -#ifndef ACE_MEMORY_POOLS_H -#define ACE_MEMORY_POOLS_H -#include /**/ "ace/pre.h" - -#include "ace/config-all.h" - -#if !defined (ACE_LACKS_PRAGMA_ONCE) -# pragma once -#endif /* ACE_LACKS_PRAGMA_ONCE */ - -#include "Event_Channel.h" -#include "Dispatching_Modules.h" -#include "ace/Malloc.h" -#include "ace/Thread_Mutex.h" -#include "ace/Null_Mutex.h" - -// ************************************************************ - -#if defined (ACE_HAS_THREAD_SPECIFIC_STORAGE) || defined (ACE_HAS_TSS_EMULATION) || !defined (ACE_HAS_THREADS) - typedef ACE_Null_Mutex ACE_MEMORY_POOL_MUTEX; -#else - // Use the same object for each thread. Therefore, we have to use - // real synchronization. - typedef TAO_SYNCH_MUTEX ACE_MEMORY_POOL_MUTEX; -#endif /* ACE_HAS_THREAD_SPECIFIC_STORAGE || ACE_HAS_TSS_EMULATION || !ACE_HAS_THREADS */ - -typedef char - ACE_ES_Dispatch_Request_Chunk[sizeof (ACE_ES_Dispatch_Request)]; - -typedef ACE_Cached_Allocator<ACE_ES_Dispatch_Request_Chunk, ACE_MEMORY_POOL_MUTEX> - _ACE_Dispatch_Request_Allocator; - -/** - * @class ACE_ES_Dispatch_Request_Allocator - * - * @brief Dispatch Request Allocator - * - * This just sets the size of the Event Container memory pool. - */ -class TAO_RTOLDEvent_Export ACE_ES_Dispatch_Request_Allocator : public _ACE_Dispatch_Request_Allocator -{ -public: - ACE_ES_Dispatch_Request_Allocator (void) : - _ACE_Dispatch_Request_Allocator (ACE_ES_DISPATCH_REQUEST_MEMORY_POOL) {} -}; - -// ************************************************************ - -typedef ACE_Malloc<ACE_LOCAL_MEMORY_POOL, TAO_SYNCH_MUTEX> ACE_ES_Event_Allocator; - -/** - * @class ACE_ES_Memory_Pools - * - * @brief Event Service Memory Pools. - * - * These have to be static in order to be accessed by operator - * news, right? - */ -class TAO_RTOLDEvent_Export ACE_ES_Memory_Pools -{ -public: - /** - * This can be called by every thread that will access these memory - * pools to preallocate the thread specific allocators. It is not - * mandatory. - */ - static int thr_init (void); - - static void *new_Dispatch_Request (void); - static void delete_Dispatch_Request (void *); - - typedef ACE_Singleton<ACE_ES_Dispatch_Request_Allocator,TAO_SYNCH_MUTEX> Dispatch_Request_; -}; - -#if defined (__ACE_INLINE__) -#include "Memory_Pools.i" -#endif /* __ACE_INLINE__ */ - -#include /**/ "ace/post.h" -#endif /* ACE_MEMORY_POOLS_H */ diff --git a/TAO/orbsvcs/orbsvcs/Event/Memory_Pools.i b/TAO/orbsvcs/orbsvcs/Event/Memory_Pools.i deleted file mode 100644 index fe240d52f02..00000000000 --- a/TAO/orbsvcs/orbsvcs/Event/Memory_Pools.i +++ /dev/null @@ -1,14 +0,0 @@ -/* -*- C++ -*- */ -// $Id$ - -ACE_INLINE void * -ACE_ES_Memory_Pools::new_Dispatch_Request (void) -{ - return Dispatch_Request_::instance ()->malloc (sizeof (ACE_ES_Dispatch_Request)); -} - -ACE_INLINE void -ACE_ES_Memory_Pools::delete_Dispatch_Request (void *mem) -{ - Dispatch_Request_::instance ()->free (mem); -} diff --git a/TAO/orbsvcs/orbsvcs/Event/Module_Factory.cpp b/TAO/orbsvcs/orbsvcs/Event/Module_Factory.cpp deleted file mode 100644 index 282d4786003..00000000000 --- a/TAO/orbsvcs/orbsvcs/Event/Module_Factory.cpp +++ /dev/null @@ -1,183 +0,0 @@ -// $Id$ - -#include "orbsvcs/Event/Dispatching_Modules.h" -#include "orbsvcs/Event/Timer_Module.h" -#include "orbsvcs/Event/Event_Channel.h" -#include "orbsvcs/Event/Module_Factory.h" - -#include "tao/ORB_Core.h" - -ACE_RCSID (Event, - Module_Factory, - "$Id$") - -TAO_Module_Factory::~TAO_Module_Factory (void) -{ -} - -// **************************************************************** - -TAO_Default_Module_Factory::TAO_Default_Module_Factory (void) -{ -} - -TAO_Default_Module_Factory::~TAO_Default_Module_Factory (void) -{ -} - -ACE_ES_Dispatching_Base* -TAO_Default_Module_Factory::create_dispatching_module (ACE_EventChannel* ec) -{ - return new ACE_ES_Priority_Dispatching (ec); -} - -void -TAO_Default_Module_Factory::destroy_dispatching_module (ACE_ES_Dispatching_Base* x) -{ - delete x; -} - -ACE_ES_Consumer_Module* -TAO_Default_Module_Factory::create_consumer_module (ACE_EventChannel* ec) -{ - return new ACE_ES_Consumer_Module (ec); -} - -void -TAO_Default_Module_Factory::destroy_consumer_module (ACE_ES_Consumer_Module* x) -{ - delete x; -} - -ACE_ES_Correlation_Module* -TAO_Default_Module_Factory::create_correlation_module (ACE_EventChannel* ec) -{ - return new ACE_ES_Correlation_Module (ec); -} - -void -TAO_Default_Module_Factory::destroy_correlation_module (ACE_ES_Correlation_Module* x) -{ - delete x; -} - -ACE_ES_Subscription_Module* -TAO_Default_Module_Factory::create_subscription_module (ACE_EventChannel* ec) -{ - return new ACE_ES_Subscription_Module (ec); -} - -void -TAO_Default_Module_Factory::destroy_subscription_module (ACE_ES_Subscription_Module* x) -{ - delete x; -} - -ACE_ES_Supplier_Module* -TAO_Default_Module_Factory::create_supplier_module (ACE_EventChannel* ec) -{ - return new ACE_ES_Supplier_Module (ec); -} - -void -TAO_Default_Module_Factory::destroy_supplier_module (ACE_ES_Supplier_Module* x) -{ - delete x; -} - -TAO_EC_Timer_Module* -TAO_Default_Module_Factory::create_timer_module (ACE_EventChannel* ec) -{ - RtecScheduler::Scheduler_var scheduler = ec->scheduler (); - return new TAO_EC_RPT_Timer_Module (scheduler.in ()); -} - -void -TAO_Default_Module_Factory::destroy_timer_module (TAO_EC_Timer_Module* x) -{ - delete x; -} - -// **************************************************************** - -TAO_Reactive_Module_Factory::TAO_Reactive_Module_Factory (void) -{ -} - -TAO_Reactive_Module_Factory::~TAO_Reactive_Module_Factory (void) -{ -} - -ACE_ES_Dispatching_Base* -TAO_Reactive_Module_Factory::create_dispatching_module (ACE_EventChannel* ec) -{ - return new ACE_ES_EFD_Dispatching(ec); -} - -void -TAO_Reactive_Module_Factory::destroy_dispatching_module (ACE_ES_Dispatching_Base* x) -{ - delete x; -} - -ACE_ES_Consumer_Module* -TAO_Reactive_Module_Factory::create_consumer_module (ACE_EventChannel* ec) -{ - return new ACE_ES_Consumer_Module (ec); -} - -void -TAO_Reactive_Module_Factory::destroy_consumer_module (ACE_ES_Consumer_Module* x) -{ - delete x; -} - -ACE_ES_Correlation_Module* -TAO_Reactive_Module_Factory::create_correlation_module (ACE_EventChannel* ec) -{ - return new ACE_ES_Correlation_Module (ec); -} - -void -TAO_Reactive_Module_Factory::destroy_correlation_module (ACE_ES_Correlation_Module* x) -{ - delete x; -} - -ACE_ES_Subscription_Module* -TAO_Reactive_Module_Factory::create_subscription_module (ACE_EventChannel* ec) -{ - return new ACE_ES_Subscription_Module (ec); -} - -void -TAO_Reactive_Module_Factory::destroy_subscription_module (ACE_ES_Subscription_Module* x) -{ - delete x; -} - -ACE_ES_Supplier_Module* -TAO_Reactive_Module_Factory::create_supplier_module (ACE_EventChannel* ec) -{ - return new ACE_ES_Supplier_Module (ec); -} - -void -TAO_Reactive_Module_Factory::destroy_supplier_module (ACE_ES_Supplier_Module* x) -{ - delete x; -} - -TAO_EC_Timer_Module* -TAO_Reactive_Module_Factory::create_timer_module (ACE_EventChannel* ec) -{ - ACE_UNUSED_ARG (ec); - - return new TAO_EC_ST_Timer_Module (TAO_ORB_Core_instance ()->reactor ()); -} - -void -TAO_Reactive_Module_Factory::destroy_timer_module (TAO_EC_Timer_Module* x) -{ - delete x; -} diff --git a/TAO/orbsvcs/orbsvcs/Event/Module_Factory.h b/TAO/orbsvcs/orbsvcs/Event/Module_Factory.h deleted file mode 100644 index 26c0c433850..00000000000 --- a/TAO/orbsvcs/orbsvcs/Event/Module_Factory.h +++ /dev/null @@ -1,174 +0,0 @@ -/* -*- C++ -*- */ -//============================================================================= -/** - * @file Module_Factory.h - * - * $Id$ - * - * @author Carlos O'Ryan - * - * The has strategies to handle several phases of the Event - * processing, for instance dispatching can be implemented using - * queues and different threads or just FIFO. - * The choice of the strategies is controlled by a Factory class - * that builds the right modules for the EC. - * - * @todo - * Some of the strategies are still hard-coded. - * - */ -//============================================================================= - - -#ifndef TAO_MODULE_FACTORY_H -#define TAO_MODULE_FACTORY_H - -#include /**/ "ace/pre.h" - -#include "old_event_export.h" - -class ACE_EventChannel; - -class ACE_ES_Dispatching_Base; -class ACE_ES_Consumer_Module; -class ACE_ES_Correlation_Module; -class ACE_ES_Subscription_Module; -class ACE_ES_Supplier_Module; -class ACE_ES_Priority_Timer; -class TAO_EC_Timer_Module; - -/** - * @class TAO_Module_Factory - * - * @brief Factory class for the Event Channel "modules". - * - * The Event Channel "modules" represent the different phases and - * strategies in event processing. Event Channel configuration is - * achieved by constructing modules with different dynamic - * types. This class encapsulates all the strategies creation in - * a single point. - */ -class TAO_RTOLDEvent_Export TAO_Module_Factory -{ -public: - virtual ~TAO_Module_Factory (void); - - virtual ACE_ES_Dispatching_Base* - create_dispatching_module (ACE_EventChannel*) = 0; - virtual void destroy_dispatching_module (ACE_ES_Dispatching_Base*) = 0; - - virtual ACE_ES_Consumer_Module* - create_consumer_module (ACE_EventChannel*) = 0; - virtual void destroy_consumer_module (ACE_ES_Consumer_Module*) = 0; - - virtual ACE_ES_Correlation_Module* - create_correlation_module (ACE_EventChannel*) = 0; - virtual void destroy_correlation_module (ACE_ES_Correlation_Module*) = 0; - - virtual ACE_ES_Subscription_Module* - create_subscription_module (ACE_EventChannel*) = 0; - virtual void destroy_subscription_module (ACE_ES_Subscription_Module*) = 0; - - virtual ACE_ES_Supplier_Module* - create_supplier_module (ACE_EventChannel*) = 0; - virtual void destroy_supplier_module (ACE_ES_Supplier_Module*) = 0; - - virtual TAO_EC_Timer_Module* - create_timer_module (ACE_EventChannel*) = 0; - virtual void destroy_timer_module (TAO_EC_Timer_Module*) = 0; - -}; - -// **************************************************************** - -/** - * @class TAO_Default_Module_Factory - * - * @brief Default factory class for the Event Channel. - * - * The Event Channel "modules" represent the different phases and - * strategies in event processing. Event Channel configuration is - * achieved by constructing modules with different dynamic - * types. This class encapsulates all the strategies creation in - * a single point. - */ -class TAO_RTOLDEvent_Export TAO_Default_Module_Factory : public TAO_Module_Factory -{ -public: - TAO_Default_Module_Factory (void); - virtual ~TAO_Default_Module_Factory (void); - - virtual ACE_ES_Dispatching_Base* - create_dispatching_module (ACE_EventChannel*); - virtual void destroy_dispatching_module (ACE_ES_Dispatching_Base*); - - virtual ACE_ES_Consumer_Module* - create_consumer_module (ACE_EventChannel*); - virtual void destroy_consumer_module (ACE_ES_Consumer_Module*); - - virtual ACE_ES_Correlation_Module* - create_correlation_module (ACE_EventChannel*); - virtual void destroy_correlation_module (ACE_ES_Correlation_Module*); - - virtual ACE_ES_Subscription_Module* - create_subscription_module (ACE_EventChannel*); - virtual void destroy_subscription_module (ACE_ES_Subscription_Module*); - - virtual ACE_ES_Supplier_Module* - create_supplier_module (ACE_EventChannel*); - virtual void destroy_supplier_module (ACE_ES_Supplier_Module*); - - virtual TAO_EC_Timer_Module* - create_timer_module (ACE_EventChannel*); - virtual void destroy_timer_module (TAO_EC_Timer_Module*); - -}; - -// **************************************************************** - -/** - * @class TAO_Reactive_Module_Factory - * - * @brief Factory class for the Event Channel "modules". - * - * This class factors out modules that require no extra threads - * for event or timer dispatching. - * An Event Channel configured with this factory can exhibit high - * priority inversion, but it should provide high-performance due - * to the elimination of context switching. - */ -class TAO_RTOLDEvent_Export TAO_Reactive_Module_Factory : public TAO_Module_Factory -{ -public: - TAO_Reactive_Module_Factory (void); - virtual ~TAO_Reactive_Module_Factory (void); - - virtual ACE_ES_Dispatching_Base* - create_dispatching_module (ACE_EventChannel*); - virtual void destroy_dispatching_module (ACE_ES_Dispatching_Base*); - - virtual ACE_ES_Consumer_Module* - create_consumer_module (ACE_EventChannel*); - virtual void destroy_consumer_module (ACE_ES_Consumer_Module*); - - virtual ACE_ES_Correlation_Module* - create_correlation_module (ACE_EventChannel*); - virtual void destroy_correlation_module (ACE_ES_Correlation_Module*); - - virtual ACE_ES_Subscription_Module* - create_subscription_module (ACE_EventChannel*); - virtual void destroy_subscription_module (ACE_ES_Subscription_Module*); - - virtual ACE_ES_Supplier_Module* - create_supplier_module (ACE_EventChannel*); - virtual void destroy_supplier_module (ACE_ES_Supplier_Module*); - - virtual TAO_EC_Timer_Module* - create_timer_module (ACE_EventChannel*); - virtual void destroy_timer_module (TAO_EC_Timer_Module*); - -}; - -#include /**/ "ace/post.h" - -#endif /* ACE_EVENT_CHANNEL_H */ diff --git a/TAO/orbsvcs/orbsvcs/Event/RT_Task.cpp b/TAO/orbsvcs/orbsvcs/Event/RT_Task.cpp deleted file mode 100644 index e6dd60806b1..00000000000 --- a/TAO/orbsvcs/orbsvcs/Event/RT_Task.cpp +++ /dev/null @@ -1,529 +0,0 @@ -// $Id$ - -#include "ace/Sched_Params.h" -#include "orbsvcs/Scheduler_Factory.h" -#include "RT_Task.h" -#include "Debug_Macros.h" -#include "Event_Channel.h" -#include "Memory_Pools.h" -#include "ace/OS_NS_errno.h" - -#if !defined (__ACE_INLINE__) -#include "RT_Task.i" -#endif /* __ACE_INLINE__ */ - -#include "tao/Timeprobe.h" -#include "ace/OS_NS_errno.h" - -#if defined (ACE_HAS_STHREADS) -# include "ace/OS_NS_unistd.h" -#endif /* ACE_HAS_STHREADS */ - -ACE_RCSID (Event, - RT_Task, - "$Id$") - -#if defined (ACE_ENABLE_TIMEPROBES) - -static const char *TAO_RT_Task_Timeprobe_Description[] = -{ - "RT_Task - start execute", - "RT_Task - end execute", - "synch_threads - priority requested", - "synch_threads - priority obtained" -}; - -enum -{ - // Timeprobe description table start key - TAO_RT_TASK_START_EXECUTE = 5200, - TAO_RT_TASK_END_EXECUTE, - TAO_RT_TASK_SYNCH_THREADS_PRIORITY_REQUESTED, - TAO_RT_TASK_SYNCH_THREADS_PRIORITY_OBTAINED -}; - -// Setup Timeprobes -ACE_TIMEPROBE_EVENT_DESCRIPTIONS (TAO_RT_Task_Timeprobe_Description, - TAO_RT_TASK_START_EXECUTE); - -#endif /* ACE_ENABLE_TIMEPROBES */ - -class ACE_RT_Task_Shutdown : public ACE_RT_Task_Command -// = TITLE -// Flush Queue Command. -// -// = DESCRIPTION -// This command object will call close on task_. This is used by -// single-threaded tasks to flush any queued messages. -{ -public: - ACE_RT_Task_Shutdown (ACE_ES_TASK *task) - : task_ (task) {} - - virtual int execute (u_long &command_action); - - ACE_ES_TASK *task_; -}; - -int -ACE_RT_Task_Shutdown::execute (u_long &command_action) -{ - ACE_UNUSED_ARG (command_action); - - if (task_ == 0) - return 1; - else - { - task_->close (0); - return 0; - } -} - -// ************************************************************ - -ACE_RT_Task::ACE_RT_Task (RtecScheduler::Scheduler_ptr scheduler) - : closed_ (0) -{ - if (CORBA::is_nil (scheduler)) - { - this->scheduler_ = - RtecScheduler::Scheduler::_duplicate (ACE_Scheduler_Factory::server ()); - } - else - { - this->scheduler_ = - RtecScheduler::Scheduler::_duplicate (scheduler); - } -} - -ACE_RT_Task::~ACE_RT_Task (void) -{ - msg_queue_->deactivate (); -} - -int -ACE_RT_Task::svc (void) -{ - ACE_DECLARE_NEW_CORBA_ENV; - ACE_TRY - { - // @@ TODO It may be necessary to pass the options to this class - -#if 0 - static char* const argv[] = { - "task" - }; - int argc = sizeof (argv)/sizeof (argv[0]); - CORBA::ORB_var orb = - CORBA::ORB_init (argc, argv, "" ACE_ENV_ARG_PARAMETER); - ACE_TRY_CHECK; -#endif - - RtecScheduler::OS_Priority thread_priority; - RtecScheduler::Preemption_Subpriority_t subpriority; - RtecScheduler::Preemption_Priority_t preemption_priority; - -#if 1 - this->scheduler_->priority - (this->rt_info_, - thread_priority, - subpriority, - preemption_priority ACE_ENV_ARG_PARAMETER); - ACE_TRY_CHECK; -#else - ACE_Scheduler_Factory::server ()->priority - (this->rt_info_, - thread_priority, - subpriority, - preemption_priority ACE_ENV_ARG_PARAMETER); - ACE_TRY_CHECK; -#endif - if (ACE_OS::thr_setprio (thread_priority) == -1) - { -#if defined (ACE_HAS_STHREADS) - if (thread_priority != 0 || ACE_OS::getuid () == 0) - // Solaris 2.5.1 doesn't allow setting a thread priority to 0 - // in Time Shared scheduling class. Maybe other priorities - // as well? -#endif /* ACE_HAS_STHREADS */ - ACE_ERROR ((LM_ERROR, "(%P|%t) %p\n", - "RT_Task thr_setprio failed, " - "this is OK if you don't want RT threads\n")); - - } - - int done = 0; - - ACE_hthread_t self; - ACE_OS::thr_self (self); - - int priority = 0; - if (ACE_OS::thr_getprio (self, priority) == 0) - ACE_DEBUG ((LM_DEBUG, "EC (%t) new thread priority = %d.\n", priority)); - - // Initialize channel thread-specific data. - ACE_ES_Memory_Pools::thr_init (); - - // Update the Scheduler's concept of this thread's rate group. - ACE_Scheduler_Factory::set_preemption_priority (preemption_priority); - - done = this->svc_hook (priority); - - while (!done) - { - done = this->svc_one (); - } - - ACE_DEBUG ((LM_DEBUG, "EC (%t) thread exiting.\n")); - } - ACE_CATCHANY - { - ACE_ERROR_RETURN ((LM_ERROR, "priority failed\n"), -1); - } - ACE_ENDTRY; - - return 0; -} - -int -ACE_RT_Task::svc_hook (RtecScheduler::OS_Priority) -{ - return 0; -} - -int -ACE_RT_Task::svc_one (void) -{ - // Dequeue the command. - ACE_Message_Block *mb; - - if (this->getq (mb) == -1) - { - if (ACE_OS::last_error () == ESHUTDOWN) - return 1; - else - // We'll continue in spite of this error. - ACE_ERROR ((LM_ERROR, "%p (%t) getq error.\n", "ACE_RT_Task::svc_one")); - } - - // Execute the command. - ACE_RT_Task_Command *command = (ACE_RT_Task_Command *) mb; - - int result; - u_long command_action = ACE_RT_Task_Command::RELEASE; - - { - ACE_FUNCTION_TIMEPROBE (TAO_RT_TASK_START_EXECUTE); - - // @@ Put exception handling around this! - result = command->execute (command_action); - } - - switch (command_action) - { - case ACE_RT_Task_Command::RELEASE: - // Free the message block. - if (ACE_RT_Task_Command::release (command) != 0) - ACE_ERROR ((LM_ERROR, "ACE_RT_Task::svc_one: " - "ACE_RT_Task_Command::release returned != 0!\n")); - break; - - case ACE_RT_Task_Command::UNGETQ: - this->ungetq (command); - break; - } - - return result; -} - -// A thread has exited. -int -ACE_RT_Task::close (u_long) -{ - // If we're the last one out, call threads_closed. - if (thr_count_ == 0) - this->threads_closed (); - - return 0; -} - -// All threads have exited. -void -ACE_RT_Task::threads_closed (void) -{ -} - -int -ACE_RT_Task::open_task (const char* name) -{ - const char *tempname = name; - char tempbuffer[64]; - if (tempname == 0) - { - ACE_OS::sprintf (tempbuffer, - "unnamed task %p", this); - tempname = tempbuffer; - } - - ACE_DECLARE_NEW_CORBA_ENV; - ACE_TRY - { -#if 1 - rt_info_ = - this->scheduler_->create (tempname ACE_ENV_ARG_PARAMETER); - ACE_TRY_CHECK; -#else - rt_info_ = - ACE_Scheduler_Factory::server()->create (tempname - ACE_ENV_ARG_PARAMETER); - ACE_TRY_CHECK; -#endif - // @@ TODO: We do no initialization of the new rt_info, the - // caller does, this is (IMnsHO) very error prone. - } - ACE_CATCH (RtecScheduler::DUPLICATE_NAME, dn_ex) - { - // @@ TODO: Its already registered, IMHO this should at least - // report a warning, but I'll stick to the previous code. - // ACE_ERROR_RETURN ((LM_WARNING, - // "RT_Info for %s was already createn", - // tempname), 0); - return 0; - } - ACE_ENDTRY; - - return 0; -} - -int -ACE_RT_Task::try_put (ACE_Message_Block *mb) -{ - if (!closed_) - { - return this->msg_queue ()->enqueue_prio (mb); - } - else - { - errno = EPIPE; - return -1; - } -} - -// The point of this method is to spawn or shutdown threads depending -// on any differences between the task's RT_Info::threads_ and how -// many threads are actually running. -int -ACE_RT_Task::synch_threads (size_t threads) -{ - if (threads > this->thr_count ()) - // Add threads. - { - RtecScheduler::OS_Priority thread_priority; - RtecScheduler::Preemption_Subpriority_t subpriority; - RtecScheduler::Preemption_Priority_t preemption_priority; - - ACE_DECLARE_NEW_CORBA_ENV; - ACE_TRY - { - { - // @@ TODO handle exceptions - ACE_FUNCTION_TIMEPROBE (TAO_RT_TASK_SYNCH_THREADS_PRIORITY_REQUESTED); -#if 1 - this->scheduler_->priority - (rt_info_, - thread_priority, - subpriority, - preemption_priority ACE_ENV_ARG_PARAMETER); - ACE_TRY_CHECK; -#else - ACE_Scheduler_Factory::server ()->priority - (rt_info_, - thread_priority, - subpriority, - preemption_priority ACE_ENV_ARG_PARAMETER); - ACE_TRY_CHECK; -#endif - } - - ACE_DEBUG ((LM_DEBUG, "EC (%t) spawning %d threads at os thread" - " priority %d.\n", - threads - this->thr_count (), - thread_priority)); - - // Add the difference. - // First try real-time scheduling with specified priority. - long flags = THR_BOUND | THR_SCHED_FIFO; - if (this->activate (flags, - (int)(threads - this->thr_count ()), - 1, // Force it to spawn more threads - thread_priority) == -1) - { - // That didn't work. Try default scheduling class with - // the requested priority. - flags = THR_BOUND; - if (this->activate (flags, - (int)(threads - this->thr_count ()), - 1, // Force it to spawn more threads - thread_priority) == -1) - { - // That didn't work. Finally, try default - // scheduling class with minimum priority. - - // On Linux, for example, only the superuser can set - // the policy to other than ACE_SCHED_OTHER. But - // with ACE_SCHED_OTHER, there is only one thread - // priority value, for example, 0. So, let the - // superuser run an interesting test, but for other - // users use the minimum ACE_SCHED_OTHER thread - // priority. - - RtecScheduler::OS_Priority fallback_priority = - ACE_Sched_Params::priority_min (ACE_SCHED_OTHER, - ACE_SCOPE_THREAD); - - ACE_DEBUG ((LM_DEBUG, - "EC (%t) task activation at priority %d " - "with flags 0x%X failed; retry at priority %d " - "with flags 0x%X\n", - thread_priority, - flags, - fallback_priority, - THR_BOUND)); - - flags = THR_BOUND; - - if (this->activate (flags, - (int)(threads - this->thr_count ()), - 1, // Force it to spawn more threads - fallback_priority) == -1) - { - ACE_DEBUG ((LM_ERROR, - "EC (%t) thread spawn at priority %d FAILED " - "(errno is %d%p)!!!!\n", - fallback_priority, - errno, - "")); - } - } - } - } - ACE_CATCHANY - { - ACE_PRINT_EXCEPTION (ACE_ANY_EXCEPTION, "priority failed\n"); - return -1; - } - ACE_ENDTRY; - - } - else - // Remove threads. - { - // kill_threads has to be off the stack in case the last thread - // deletes this RT_Task. - size_t kill_threads = this->thr_count () - threads; - - for (size_t x = 0; x < kill_threads; ++x) - { - // Create a new shutdown command with a task pointer of 0. - ACE_RT_Task_Shutdown *te = new ACE_RT_Task_Shutdown (0); - - if (te == 0) - return -1; - - ACE_DEBUG ((LM_DEBUG, "EC (%t) enqueueing thread exit.\n")); - if (this->putq (te) == -1) - { - ACE_ERROR ((LM_ERROR, "%p putq failed.\n", - "ACE_RT_Task::synch_threads")); - if (ACE_RT_Task_Shutdown::release (te) != 0) - ACE_ERROR ((LM_ERROR, "ACE_RT_Task::synch_threads: " - "ACE_RT_Task_Shutdown::release returned != 0!\n")); - return -1; - } - } - } - - return 0; -} - - -// If we are not active, we will flush the queue and then call -// this->close. Otherwise, we will send shutdown messages to each -// thread. ~ACE_Task_Exit will call this->close when each thread -// exits. -int -ACE_RT_Task::shutdown_task (void) -{ - // Be sure to only execute this once, and only if we're active. - if (closed_) - return 0; - - // This will keep any messages from entering the queue. - closed_ = 1; - - if (thr_count_ > 0) - return this->synch_threads (0); - else - { - // Create a new flush queue command. We're passive, so pass in - // a reference to the task for which close will be called. - ACE_RT_Task_Shutdown *fq = new ACE_RT_Task_Shutdown (this); - - if (fq == 0) - { - ACE_ERROR ((LM_ERROR, "%p.\n", "ACE_RT_Task::shutdown_threads")); - return -1; - } - - // Enqueue the command. - ACE_DEBUG ((LM_DEBUG, "EC (%t) enqueueing task shutdown.\n")); - if (this->putq (fq) == -1) - { - ACE_ERROR ((LM_ERROR, "%p putq failed.\n", - "ACE_RT_Task::shutdown_task")); - if (ACE_RT_Task_Shutdown::release (fq) != 0) - ACE_ERROR ((LM_ERROR, "ACE_RT_Task::shutdown_task: " - "ACE_RT_Task_Shutdown::release returned != 0!\n")); - return -1; - } - } - - return 0; -} - -// ************************************************************ - -ACE_RT_Thread_Manager::ACE_RT_Thread_Manager (void) - : flags_ (0) -{ -} - -void -ACE_RT_Thread_Manager::suspend_spawns (void) -{ - flags_ |= THR_SUSPENDED; -} - -void -ACE_RT_Thread_Manager::unsuspend_spawns (void) -{ - flags_ = 0; - this->resume_all (); -} - -int -ACE_RT_Thread_Manager::spawn_i (ACE_THR_FUNC func, - void *args, - long flags, - ACE_thread_t *t_id, - ACE_hthread_t *t_handle, - long priority, - int grp_id, - void *stack, - size_t stack_size, - ACE_Task_Base *task) -{ - flags |= flags_; - return ACE_Thread_Manager::spawn_i (func, args, flags, t_id, t_handle, - priority, grp_id, stack, stack_size, task); -} diff --git a/TAO/orbsvcs/orbsvcs/Event/RT_Task.h b/TAO/orbsvcs/orbsvcs/Event/RT_Task.h deleted file mode 100644 index 6bb34db4910..00000000000 --- a/TAO/orbsvcs/orbsvcs/Event/RT_Task.h +++ /dev/null @@ -1,203 +0,0 @@ -/* -*- C++ -*- */ - -//============================================================================= -/** - * @file RT_Task.h - * - * $Id$ - * - * @author Tim Harrison (harrison@cs.wustl.edu) - * - * Wrapper on top of ACE Task that integrates an Active Object with - * the Event Service. - * - * - */ -//============================================================================= - - -#ifndef ACE_RT_TASK_H -#define ACE_RT_TASK_H -#include /**/ "ace/pre.h" - -#include "ace/Task.h" - -#if !defined (ACE_LACKS_PRAGMA_ONCE) -# pragma once -#endif /* ACE_LACKS_PRAGMA_ONCE */ - -#include "orbsvcs/RtecSchedulerC.h" -#include "old_event_export.h" - -/** - * @class ACE_RT_Thread_Manager - * - * - */ -class TAO_RTOLDEvent_Export ACE_RT_Thread_Manager : public ACE_Thread_Manager -{ -public: - /// Default construction. - ACE_RT_Thread_Manager (void); - - /// Any threads spawned will be suspended until <unsuspend_spawns> is - /// called. - void suspend_spawns (void); - - /// Resumes all threads. - void unsuspend_spawns (void); - -protected: - virtual int spawn_i (ACE_THR_FUNC func, - void *args, - long flags, - ACE_thread_t * = 0, - ACE_hthread_t *t_handle = 0, - long priority = 0, - int grp_id = -1, - void *stack = 0, - size_t stack_size = 0, - ACE_Task_Base *task = 0); - - int flags_; -}; - -// ************************************************************ - -/** - * @class ACE_RT_Task_Command - * - * - */ -class TAO_RTOLDEvent_Export ACE_RT_Task_Command : public ACE_Message_Block -{ -public: - /// Guarantees that derived destructors get called. - virtual ~ACE_RT_Task_Command (void) {} - - enum { RELEASE, UNGETQ }; - - /** - * Execute the command. Returning 1 will make the calling thread - * exit. Returning 0 will allow the thread to continue dispatching - * commands. If <command_action> returns as RELEASE, the command - * will be released. If <command_action> == UNGETQ, then the - * command will be requeued and dispatched again. - */ - virtual int execute (u_long &command_action) = 0; -}; - -// ************************************************************ - -typedef ACE_Task<ACE_SYNCH> ACE_ES_TASK; -typedef ACE_Message_Queue<ACE_SYNCH> ACE_ES_QUEUE; - -/** - * @class ACE_RT_Task - * - * @brief ACE Real-Time Task - * - * Real-Time Active Object that integrates with a global - * scheduler and Event Service. For now, none of the management - * methods are synchronized. If it turns out that multiple - * threads will be calling the management methods, then we can - * add synchronization. For the most part, RT_Task threads - * should be dequeueing commands from the message queue. Only - * one thread should be calling any management methods. - */ -class TAO_RTOLDEvent_Export ACE_RT_Task : public ACE_ES_TASK -{ - friend class ACE_RT_Thread_Manager; -public: - /// Default construction. - ACE_RT_Task (RtecScheduler::Scheduler_ptr scheduler); - - /// Deactivates the queue. - ~ACE_RT_Task (void); - - // = Management methods. - - /** - * <name> is used to look up our qos info from the scheduler. If - * <name> == 0, then we create a "unique" name and ask the scheduler - * for a new qos structure. If we find an existing qos structure, - * calls this->synch_threads and returns 1. If a qos structure is not - * found, but created returns 0 and does not call synch_threads. - * Returns -1 on failure. - */ - int open_task (const char* name = 0); - - /// Enqueue a request. Returns 0 on success, -1 on failure. If the - /// task is shutdown, -1 is returned with errno == EPIPE. - int try_put (ACE_Message_Block *mb); - - /** - * If active, shutdown all running thread. Since this is - * accomplished via queued shutdown messages, this has the effect of - * flushing the queue. Once all threads exit, threads_closed will - * be called. If this is a passive object, then the queue will be - * flushed and threads_closed will be called. - */ - int shutdown_task (void); - - /** - * Compare <threads> with what is actually running. If there are - * any differences, update this RT_Task. This may involve spawning - * more threads or changing thread priorities, etc. This can be - * used to close all threads by sending a 0. - */ - int synch_threads (size_t threads); - - /// QOS accessor. The behavior of the task can be changed by setting - /// this and then calling this->synch_threads. - RtecScheduler::handle_t rt_info (void); - - /** - * Called when every thread has exited. This hook allows - * applications to specify semantics when all threads have exited. - * For instance, the Dispatching Module uses this hook to delete - * itself when an application is shutting down. - */ - virtual void threads_closed (void); - - /** - * This is called the first time the thread is spawned. <priority> - * is the priority of the current thread. If this returns != 1 - * (e.g., 0), the event loop will execute (calling this->svc_one). - * If this returns 1, the event loop will not execute. - */ - virtual int svc_hook (RtecScheduler::OS_Priority priority); - - /// Call this->getq once and execute the command. Returns the result - /// of command->execute (). - virtual int svc_one (void); - -protected: - /// Run by each thread spawned. Each thread dequeues - /// ACE_RT_Task_Commands and executes them. - virtual int svc (void); - - /// Called each time a thread exits. - virtual int close (u_long flags = 0); - - /// Enqueues shutdown message for every thread in the task. - void close_all_threads (void); - -protected: - /// Scheduling characteristics of this active object. - RtecScheduler::handle_t rt_info_; - - /// Set to 1 when this->shutdown_threads or this->close_queue is - /// called. Keeps us from enqueuing more that one shutdown message. - int closed_; - - /// The scheduler. - RtecScheduler::Scheduler_var scheduler_; -}; - -#if defined (__ACE_INLINE__) -#include "RT_Task.i" -#endif /* __ACE_INLINE__ */ - -#include /**/ "ace/post.h" -#endif /* ACE_RT_TASK_H */ diff --git a/TAO/orbsvcs/orbsvcs/Event/RT_Task.i b/TAO/orbsvcs/orbsvcs/Event/RT_Task.i deleted file mode 100644 index b6b21d50494..00000000000 --- a/TAO/orbsvcs/orbsvcs/Event/RT_Task.i +++ /dev/null @@ -1,8 +0,0 @@ -/* -*- C++ -*- */ -// $Id$ - -ACE_INLINE RtecScheduler::handle_t -ACE_RT_Task::rt_info (void) -{ - return rt_info_; -} diff --git a/TAO/orbsvcs/orbsvcs/Event/ReactorTask.cpp b/TAO/orbsvcs/orbsvcs/Event/ReactorTask.cpp deleted file mode 100644 index 92451aa9c6e..00000000000 --- a/TAO/orbsvcs/orbsvcs/Event/ReactorTask.cpp +++ /dev/null @@ -1,156 +0,0 @@ -// $Id$ - -#include "ace/High_Res_Timer.h" -#include "tao/Timeprobe.h" -#include "orbsvcs/Scheduler_Factory.h" - -#include "ReactorTask.h" - -ACE_RCSID (Event, - ReactorTask, - "$Id$") - -#if defined (ACE_ENABLE_TIMEPROBES) - -static const char *TAO_Reactor_Task_Timeprobe_Description[] = -{ - "Reactor_Task - waiting for events", - "Reactor_Task - events handled" -}; - -enum -{ - // Timeprobe description table start key - TAO_REACTOR_TASK_WAITING_FOR_EVENTS = 5300, - TAO_REACTOR_TASK_EVENTS_HANDLED -}; - -// Setup Timeprobes -ACE_TIMEPROBE_EVENT_DESCRIPTIONS (TAO_Reactor_Task_Timeprobe_Description, - TAO_REACTOR_TASK_WAITING_FOR_EVENTS); - -#endif /* ACE_ENABLE_TIMEPROBES */ - -ACE_ES_Reactor_Task:: - ACE_ES_Reactor_Task (RtecScheduler::Scheduler_ptr scheduler) - : ACE_RT_Task (scheduler), - // reactor_ (0, &timer_queue_), - done_ (0) -{ - // Change the timer mechanism used by the reactor and the timer - // queue. - timer_queue_.gettimeofday (ACE_OS::gettimeofday); -} - -ACE_ES_Reactor_Task::~ACE_ES_Reactor_Task (void) -{ -} - -int -ACE_ES_Reactor_Task::svc_hook(RtecScheduler::OS_Priority) -{ - // Make ourselves owner of the reactor. - reactor_.owner (ACE_Thread::self()); - return 0; -} - -int -ACE_ES_Reactor_Task::open_reactor (RtecScheduler::Period_t &period) -{ - // Create a name for ourselves using the period. The period is - // in 100 ns units; first convert to usec by dividing by 10. - char temp[64]; - ACE_OS::sprintf (temp, "Reactor_Task-%u.us", period / 10); - - // Open the task. This will query the scheduler for our qos - // structure. - int result = this->open_task (temp); - - switch (result) - { - case -1: - // Error. - ACE_ERROR ((LM_ERROR, "(%t) Scheduler could not find operation %s.\n", - temp)); - return -1; - - case 0: - // @@ TODO handle exceptions - { - ACE_DECLARE_NEW_CORBA_ENV; - ACE_TRY - { -#if 1 - this->scheduler_->set - (rt_info_, - RtecScheduler::VERY_HIGH_CRITICALITY, - ORBSVCS_Time::zero (), - ORBSVCS_Time::zero (), - ORBSVCS_Time::zero (), - period, - RtecScheduler::VERY_LOW_IMPORTANCE, - ORBSVCS_Time::zero (), - 1, - RtecScheduler::OPERATION - ACE_ENV_ARG_PARAMETER); -#else - ACE_Scheduler_Factory::server()->set - (rt_info_, - RtecScheduler::VERY_HIGH_CRITICALITY, - ORBSVCS_Time::zero (), - ORBSVCS_Time::zero (), - ORBSVCS_Time::zero (), - period, - RtecScheduler::VERY_LOW_IMPORTANCE, - ORBSVCS_Time::zero (), - 1, - RtecScheduler::OPERATION - ACE_ENV_ARG_PARAMETER); -#endif - ACE_TRY_CHECK; - } - ACE_CATCHANY - { - ACE_PRINT_EXCEPTION (ACE_ANY_EXCEPTION, - "set failed\n"); - } - ACE_ENDTRY; - } - break; - - case 1: - // Found. - break; - } - - return this->synch_threads (1); -} - -int ACE_ES_Reactor_Task::svc_one() -{ - ACE_TIMEPROBE (" Reactor_Task - waiting for events"); - if (reactor_.handle_events() == -1) - ACE_ERROR ((LM_ERROR, "(%t) %p.\n", "ACE_ES_Reactor_Task::svc")); - ACE_TIMEPROBE (" Reactor_Task - events handled"); - - if (done_) - ACE_DEBUG ((LM_DEBUG, "EC (%t) Timer Task is done.\n")); - - return done_; -} - -void ACE_ES_Reactor_Task::threads_closed() -{ -} - -void ACE_ES_Reactor_Task::shutdown_task() -{ - done_ = 1; - reactor_.notify(); -} - -ACE_ES_Reactor_Task::Reactor& -ACE_ES_Reactor_Task::get_reactor() -{ - return reactor_; -} diff --git a/TAO/orbsvcs/orbsvcs/Event/ReactorTask.h b/TAO/orbsvcs/orbsvcs/Event/ReactorTask.h deleted file mode 100644 index 7e441173215..00000000000 --- a/TAO/orbsvcs/orbsvcs/Event/ReactorTask.h +++ /dev/null @@ -1,83 +0,0 @@ -// $Id$ - -#if !defined ACE_ReactorTask_H -#define ACE_ReactorTask_H - -// BBM, moved this here from UPSingleProcessorOrb.h -//## begin module.includes preserve=yes -#include "Fast_Reactor.h" -#if defined (ACE_OLD_STYLE_REACTOR) -# define ACE_ORB_REACTOR ACE_ES_Fast_Reactor -#endif /* ACE_OLD_STYLE_REACTOR */ -//## end module.includes - -// Added these. -#include "ace/Timer_Heap.h" - -#if !defined (ACE_LACKS_PRAGMA_ONCE) -# pragma once -#endif /* ACE_LACKS_PRAGMA_ONCE */ - -#include "ace/Timer_List.h" -#include "ace/Reactor.h" -#include "Local_ESTypes.h" -#include "RT_Task.h" - -/** - * @class ACE_ES_Reactor_Task - * - * @brief Event Service Timer Task - * - * An active object that dispatches timers from its own ReactorEx. - */ -class TAO_RTOLDEvent_Export ACE_ES_Reactor_Task : public ACE_RT_Task -{ -public: - // BBM, added this. -#if defined (ACE_OLD_STYLE_REACTOR) - typedef ACE_ORB_REACTOR Reactor; -#else - typedef ACE_Reactor Reactor; -#endif /* ACE_OLD_STYLE_REACTOR */ - - /// Default construction. - ACE_ES_Reactor_Task (RtecScheduler::Scheduler_ptr scheduler); - - /// Destruction. - ~ACE_ES_Reactor_Task (void); - - /// Assume ownership of the reactor_. - virtual int svc_hook(RtecScheduler::OS_Priority); - - /// This is a hack for now. - int open_reactor (RtecScheduler::Period_t &period); - - /// Calls reactor_.handle_events until done_ is set. - virtual int svc_one(); - - /// Sets done_ and notifies the reactor_. - void shutdown_task(); - - /// ReactorEx accessor. - Reactor &get_reactor(); - - /// Deletes this. - virtual void threads_closed(); - -private: - /// The timer storage mechanism used by reactor_. - ACE_Timer_List timer_queue_; - -#ifndef ACE_OLD_STYLE_REACTOR - /// The timer dispatch mechanism. - ACE_ES_Fast_Reactor fast_reactor_; -#endif /* ! ACE_OLD_STYLE_REACTOR */ - - /// "Public" handle to fast_reactor_. - Reactor reactor_; - - /// When set, end the event loop. - sig_atomic_t done_; -}; - -#endif /* ACE_ReactorTask_H */ diff --git a/TAO/orbsvcs/orbsvcs/Event/Timer_Module.cpp b/TAO/orbsvcs/orbsvcs/Event/Timer_Module.cpp deleted file mode 100644 index ad34f801560..00000000000 --- a/TAO/orbsvcs/orbsvcs/Event/Timer_Module.cpp +++ /dev/null @@ -1,274 +0,0 @@ -// $Id$ - -#include "ace/Functor.h" - -#include "orbsvcs/Scheduler_Factory.h" -#include "ReactorTask.h" -#include "Timer_Module.h" - -#if ! defined (__ACE_INLINE__) -#include "Timer_Module.i" -#endif /* __ACE_INLINE__ */ - -ACE_RCSID (Event, - Timer_Module, - "$Id$") - -#include "tao/Timeprobe.h" - -#if defined (ACE_ENABLE_TIMEPROBES) -static const char *TAO_Timer_Module_Timeprobe_Description[] = -{ - "Timer_Module - start execute", - "Timer_Module - end execute" -}; - -enum -{ - // Timeprobe description table start key - TAO_EC_TIMER_MODULE_START_EXECUTE = 5400, - TAO_EC_TIMER_MODULE_END_EXECUTE -}; - -// Setup Timeprobes -ACE_TIMEPROBE_EVENT_DESCRIPTIONS (TAO_Timer_Module_Timeprobe_Description, - TAO_EC_TIMER_MODULE_START_EXECUTE); - -#endif /* ACE_ENABLE_TIMEPROBES */ - -// **************************************************************** - -TAO_EC_Timer_Module::~TAO_EC_Timer_Module (void) -{ -} - -// **************************************************************** - -TAO_EC_ST_Timer_Module::TAO_EC_ST_Timer_Module (ACE_Reactor* r) - : reactor_ (r) -{ -} - -TAO_EC_ST_Timer_Module::~TAO_EC_ST_Timer_Module (void) -{ -} - -void -TAO_EC_ST_Timer_Module::activate (void) -{ -} - -void -TAO_EC_ST_Timer_Module::shutdown (void) -{ - this->reactor_->cancel_timer (&this->timeout_handler_); -} - -RtecScheduler::handle_t -TAO_EC_ST_Timer_Module::rt_info (RtecScheduler::Preemption_Priority_t) -{ - // @@ TODO...... - return 0; -} - -int -TAO_EC_ST_Timer_Module::schedule_timer (RtecScheduler::Preemption_Priority_t, - ACE_Command_Base* act, - const ACE_Time_Value& delta, - const ACE_Time_Value& interval) -{ - return this->reactor_->schedule_timer (&this->timeout_handler_, - static_cast<void*> (act), - delta, interval); -} - -int -TAO_EC_ST_Timer_Module::cancel_timer (RtecScheduler::Preemption_Priority_t, - int id, - ACE_Command_Base*& act) -{ - const void *vp; - - int result = - this->reactor_->cancel_timer (id, &vp); - if (result == 0) - { - ACE_ERROR ((LM_ERROR, "TAO_EC_ST_Timer_Module::cancel_timer: " - "Tried to cancel nonexistent timer.\n")); - act = 0; - } - else - act = reinterpret_cast<ACE_Command_Base *> (const_cast<void *> (vp)); - - return result; -} - -int -TAO_EC_ST_Timer_Module::register_handler (RtecScheduler::Preemption_Priority_t, - ACE_Event_Handler* eh, - ACE_HANDLE handle) -{ - return this->reactor_->register_handler (eh, handle); -} - -ACE_Reactor* -TAO_EC_ST_Timer_Module::reactor (RtecScheduler::Preemption_Priority_t) -{ - return this->reactor_; -} - -// **************************************************************** - -TAO_EC_RPT_Timer_Module:: - TAO_EC_RPT_Timer_Module (RtecScheduler::Scheduler_ptr scheduler) - : shutdown_ (0) -{ - if (CORBA::is_nil (scheduler)) - { - this->scheduler_ = - RtecScheduler::Scheduler::_duplicate (ACE_Scheduler_Factory::server ()); - } - else - { - this->scheduler_ = - RtecScheduler::Scheduler::_duplicate (scheduler); - } - for (int i = 0; i < ACE_Scheduler_MAX_PRIORITIES; ++i) - this->reactorTasks[i] = 0; -} - -TAO_EC_RPT_Timer_Module::~TAO_EC_RPT_Timer_Module (void) -{ - this->shutdown (); - - for (int i = 0; i < ACE_Scheduler_MAX_PRIORITIES; ++i) - { - if (this->reactorTasks[i] != 0) - { - delete this->reactorTasks[i]; - this->reactorTasks[i] = 0; - } - } -} - -void TAO_EC_RPT_Timer_Module::activate (void) -{ - for (int i = 0; i < ACE_Scheduler_MAX_PRIORITIES; ++i) - { - if (this->reactorTasks[i] != 0) - continue; - - // Convert ACE_Scheduler_Rate (it's really a period, not a rate!) - // to a form we can easily work with. - ACE_Time_Value period_tv; - ORBSVCS_Time::TimeT_to_Time_Value (period_tv, ACE_Scheduler_Rates[i]); - - RtecScheduler::Period_t period = period_tv.sec () * 10000000 + - period_tv.usec () * 10; - - ACE_NEW (this->reactorTasks[i], - ReactorTask (this->scheduler_.in ())); - - if (!this->shutdown_) - { - this->reactorTasks[i]->thr_mgr (this->ThrMgr ()); - if (this->reactorTasks[i]->open_reactor (period) == -1) - { - ACE_ERROR ((LM_ERROR, "%p\n", - "EC (%t) Timer_Module - open reactor")); - } - } - } -} - -void -TAO_EC_RPT_Timer_Module::shutdown (void) -{ - if (this->shutdown_) - return; - - this->shutdown_ = 1; - for (int i = 0; i < ACE_Scheduler_MAX_PRIORITIES; ++i) - { - if (this->reactorTasks[i] != 0) - this->reactorTasks[i]->shutdown_task (); - this->reactorTasks[i]->get_reactor ().cancel_timer (&this->timeout_handler_); - } - - if (this->ThrMgr ()->wait () == -1) - ACE_ERROR ((LM_ERROR, "%p\n", "EC (%t) Timer_Module wait")); -} - -RtecScheduler::handle_t -TAO_EC_RPT_Timer_Module::rt_info (RtecScheduler::Preemption_Priority_t priority) -{ - return this->GetReactorTask (priority)->rt_info (); -} - -int -TAO_EC_RPT_Timer_Module::schedule_timer (RtecScheduler::Preemption_Priority_t priority, - ACE_Command_Base* act, - const ACE_Time_Value& delta, - const ACE_Time_Value& interval) -{ - ACE_Reactor& reactor = this->GetReactorTask (priority)->get_reactor (); - return reactor.schedule_timer (&this->timeout_handler_, - static_cast<void*> (act), - delta, interval); -} - -int -TAO_EC_RPT_Timer_Module::cancel_timer (RtecScheduler::Preemption_Priority_t priority, - int id, - ACE_Command_Base*& act) -{ - const void* vp; - ACE_Reactor& reactor = this->GetReactorTask (priority)->get_reactor (); - - int result = - reactor.cancel_timer (id, &vp); - if (result == 0) - { - ACE_ERROR ((LM_ERROR, "TAO_EC_ST_Timer_Module::cancel_timer: " - "Tried to cancel nonexistent timer.\n")); - act = 0; - } - else - act = reinterpret_cast<ACE_Command_Base *> (const_cast<void *> (vp)); - - return result; -} - -int -TAO_EC_RPT_Timer_Module::register_handler (RtecScheduler::Preemption_Priority_t priority, - ACE_Event_Handler* eh, - ACE_HANDLE handle) -{ - return this->GetReactorTask (priority)->get_reactor ().register_handler (eh, handle); -} - -ACE_Reactor* -TAO_EC_RPT_Timer_Module::reactor (RtecScheduler::Preemption_Priority_t priority) -{ - return &this->GetReactorTask (priority)->get_reactor (); -} - -// **************************************************************** - -int -TAO_EC_Timeout_Handler::handle_timeout (const ACE_Time_Value &, - const void *vp) -{ - ACE_Command_Base *act = static_cast<ACE_Command_Base*> (const_cast<void*> (vp)); - - if (act == 0) - ACE_ERROR_RETURN ((LM_ERROR, "ACE_ES_Priority_Timer::handle_timeout: " - "received act == 0!!!.\n"), 0); - - { - ACE_FUNCTION_TIMEPROBE (TAO_EC_TIMER_MODULE_START_EXECUTE); - act->execute (); - } - - return 0; -} diff --git a/TAO/orbsvcs/orbsvcs/Event/Timer_Module.h b/TAO/orbsvcs/orbsvcs/Event/Timer_Module.h deleted file mode 100644 index 2b93e920c66..00000000000 --- a/TAO/orbsvcs/orbsvcs/Event/Timer_Module.h +++ /dev/null @@ -1,208 +0,0 @@ -/* -*- C++ -*- */ -// -// $Id$ -// - -#ifndef TAO_EC_TIMER_MODULE_H -#define TAO_EC_TIMER_MODULE_H -#include /**/ "ace/pre.h" - -#include "ace/ACE.h" - -#if !defined (ACE_LACKS_PRAGMA_ONCE) -# pragma once -#endif /* ACE_LACKS_PRAGMA_ONCE */ - -#include "orbsvcs/Event_Service_Constants.h" -#include "orbsvcs/Event/RT_Task.h" - -class ACE_Command_Base; - -/** - * @class TAO_EC_Timer_Module - * - * @brief The timer managment module. - * - * The Event Channel can use several strategies to dispatch timers, - * for instance, it can use the ORB reactor or a pool of reactors running at - * different priorities or a pool of Thread_Timer_Queue_Adapters running at - * different priorities also. This class is the abstract base class to - * abstract this strategies. - */ -class TAO_RTOLDEvent_Export TAO_EC_Timer_Module -{ -public: - /// The dtor - virtual ~TAO_EC_Timer_Module (void); - - /// Activate the threads, it waits until the threads are up and - /// running. - virtual void activate (void) = 0; - - /// Deactivate the threads, it waits until all the threads have - /// terminated. - virtual void shutdown (void) = 0; - - /// The RT_Info handle for the "task" at <priority> - virtual RtecScheduler::handle_t - rt_info (RtecScheduler::OS_Priority priority) = 0; - - /// Add a timer at the given priority, returns the timer ID. - virtual int schedule_timer (RtecScheduler::Preemption_Priority_t priority, - ACE_Command_Base* act, - const ACE_Time_Value& delta, - const ACE_Time_Value& interval) = 0; - - /// Add a timer at the given priority. - virtual int cancel_timer (RtecScheduler::Preemption_Priority_t priority, - int id, - ACE_Command_Base*& act) = 0; - - /// Register a handler????? - virtual int register_handler (RtecScheduler::Preemption_Priority_t priority, - ACE_Event_Handler* eh, - ACE_HANDLE handle) = 0; - - /// Obtain the reactor for the given priority. - /// @@ This may prove tricky to implement with timer queues not based - /// on reactors. - virtual ACE_Reactor* reactor (RtecScheduler::Preemption_Priority_t priority) = 0; -}; - -// **************************************************************** - -/** - * @class TAO_EC_Timeout_Handler - * - * @brief Event Service Timeout handler. - * - * This is used by the Timer_Modules as an adaptor between the - * reactor (Event_Handler) and the Command objects. - */ -class TAO_RTOLDEvent_Export TAO_EC_Timeout_Handler : public ACE_Event_Handler -{ -public: - /// Default construction. - TAO_EC_Timeout_Handler (void); - -private: - /// Casts @ act to ACE_Command_Base and calls execute. - virtual int handle_timeout (const ACE_Time_Value &tv, - const void *act); -}; - -// **************************************************************** - -/** - * @class TAO_EC_ST_Timer_Module - * - * @brief A single threaded implementation for the timer module. - * - * This timer module uses a single Reactor to implement the timer, - * usually the ORB reactor is used for this purposes. - */ -class TAO_RTOLDEvent_Export TAO_EC_ST_Timer_Module : public TAO_EC_Timer_Module -{ -public: - /// The ctor. - TAO_EC_ST_Timer_Module (ACE_Reactor* reactor); - - /// The dtor - virtual ~TAO_EC_ST_Timer_Module (void); - - // = The TAO_EC_Timer_Module methods. - virtual void activate (void); - virtual void shutdown (void); - virtual RtecScheduler::handle_t - rt_info (RtecScheduler::Preemption_Priority_t priority); - virtual int schedule_timer (RtecScheduler::Preemption_Priority_t priority, - ACE_Command_Base* act, - const ACE_Time_Value& delta, - const ACE_Time_Value& interval); - virtual int cancel_timer (RtecScheduler::Preemption_Priority_t priority, - int id, - ACE_Command_Base*& act); - virtual int register_handler (RtecScheduler::Preemption_Priority_t priority, - ACE_Event_Handler* eh, - ACE_HANDLE handle); - virtual ACE_Reactor* reactor (RtecScheduler::Preemption_Priority_t priority); - -private: - /// The reactor. - ACE_Reactor* reactor_; - - /// To receive the timeouts. - TAO_EC_Timeout_Handler timeout_handler_; -}; - -// **************************************************************** - -class ACE_ES_Reactor_Task; - -/** - * @class TAO_EC_RPT_Timer_Module - * - * @brief A timer module using reactor-per-thread. - * - * This Timer Module uses a pool of ACE_ReactorTask to handle the - * dispatching of timeouts. In real-time multi-threaded enviroments - * each Reactor runs at a different priority. - */ -class TAO_RTOLDEvent_Export TAO_EC_RPT_Timer_Module : public TAO_EC_Timer_Module -{ -public: - /// Create the Timer Module - TAO_EC_RPT_Timer_Module (RtecScheduler::Scheduler_ptr scheduler); - - /// The dtor also shutdowns the Task_Manager. - virtual ~TAO_EC_RPT_Timer_Module (void); - - typedef ACE_ES_Reactor_Task ReactorTask; - - /// Obtain the ReactorTask for the given priority. - /// The Task must have been created already. - ReactorTask* GetReactorTask(RtecScheduler::Preemption_Priority_t priority); - - /// Returns a global ThreadManager for the Task pool. - ACE_RT_Thread_Manager* ThrMgr(); - - // = The TAO_EC_Timer_Module methods. - virtual void activate (void); - virtual void shutdown (void); - virtual RtecScheduler::handle_t - rt_info (RtecScheduler::Preemption_Priority_t priority); - virtual int schedule_timer (RtecScheduler::Preemption_Priority_t priority, - ACE_Command_Base* act, - const ACE_Time_Value& delta, - const ACE_Time_Value& interval); - virtual int cancel_timer (RtecScheduler::Preemption_Priority_t priority, - int id, - ACE_Command_Base*& act); - virtual int register_handler (RtecScheduler::Preemption_Priority_t priority, - ACE_Event_Handler* eh, - ACE_HANDLE handle); - virtual ACE_Reactor* reactor (RtecScheduler::Preemption_Priority_t priority); - -private: - /// The reactors are shutdown, do not attempt to restart them. - int shutdown_; - - /// The set of ReactorTasks - ReactorTask *reactorTasks[ACE_Scheduler_MAX_PRIORITIES]; - - /// The thread manager. - ACE_RT_Thread_Manager thr_mgr; - - /// To receive the timeouts. - TAO_EC_Timeout_Handler timeout_handler_; - - /// The scheduler. - RtecScheduler::Scheduler_var scheduler_; -}; - -#if defined (__ACE_INLINE__) -#include "Timer_Module.i" -#endif /* __ACE_INLINE__ */ - -#include /**/ "ace/post.h" -#endif /* TAO_EC_TIMER_MODULE_H */ diff --git a/TAO/orbsvcs/orbsvcs/Event/Timer_Module.i b/TAO/orbsvcs/orbsvcs/Event/Timer_Module.i deleted file mode 100644 index 0ea11e7dbc0..00000000000 --- a/TAO/orbsvcs/orbsvcs/Event/Timer_Module.i +++ /dev/null @@ -1,32 +0,0 @@ -// -// $Id$ -// - -ACE_INLINE TAO_EC_RPT_Timer_Module::ReactorTask* -TAO_EC_RPT_Timer_Module::GetReactorTask(RtecScheduler::Preemption_Priority_t priority) -{ - if (reactorTasks[priority] == 0) - { - this->activate (); - //ACE_ERROR_RETURN ((LM_ERROR, - //"%p no reactor task for priority %d.\n", - //"TAO_EC_RPT_Timer_Module::GetReactor", - //priority), 0); - } - - return reactorTasks[priority]; -} - -ACE_INLINE ACE_RT_Thread_Manager* -TAO_EC_RPT_Timer_Module::ThrMgr() -{ - return &thr_mgr; -} - -// **************************************************************** - -ACE_INLINE -TAO_EC_Timeout_Handler::TAO_EC_Timeout_Handler (void) -{ -} - diff --git a/TAO/orbsvcs/orbsvcs/Event/old_event_export.h b/TAO/orbsvcs/orbsvcs/Event/old_event_export.h deleted file mode 100644 index a9b872f2424..00000000000 --- a/TAO/orbsvcs/orbsvcs/Event/old_event_export.h +++ /dev/null @@ -1,40 +0,0 @@ - -// -*- C++ -*- -// $Id$ -// Definition for Win32 Export directives. -// This file is generated automatically by generate_export_file.pl -// ------------------------------ -#ifndef TAO_RTOLDEVENT_EXPORT_H -#define TAO_RTOLDEVENT_EXPORT_H - -#include "ace/config-all.h" - -#if defined (TAO_AS_STATIC_LIBS) -# if !defined (TAO_RTOLDEVENT_HAS_DLL) -# define TAO_RTOLDEVENT_HAS_DLL 0 -# endif /* ! TAO_RTOLDEVENT_HAS_DLL */ -#else -# if !defined (TAO_RTOLDEVENT_HAS_DLL) -# define TAO_RTOLDEVENT_HAS_DLL 1 -# endif /* ! TAO_RTOLDEVENT_HAS_DLL */ -#endif - -#if defined (TAO_RTOLDEVENT_HAS_DLL) && (TAO_RTOLDEVENT_HAS_DLL == 1) -# if defined (TAO_RTOLDEVENT_BUILD_DLL) -# define TAO_RTOLDEvent_Export ACE_Proper_Export_Flag -# define TAO_RTOLDEVENT_SINGLETON_DECLARATION(T) ACE_EXPORT_SINGLETON_DECLARATION (T) -# define TAO_RTOLDEVENT_SINGLETON_DECLARE(SINGLETON_TYPE, CLASS, LOCK) ACE_EXPORT_SINGLETON_DECLARE(SINGLETON_TYPE, CLASS, LOCK) -# else /* TAO_RTOLDEVENT_BUILD_DLL */ -# define TAO_RTOLDEvent_Export ACE_Proper_Import_Flag -# define TAO_RTOLDEVENT_SINGLETON_DECLARATION(T) ACE_IMPORT_SINGLETON_DECLARATION (T) -# define TAO_RTOLDEVENT_SINGLETON_DECLARE(SINGLETON_TYPE, CLASS, LOCK) ACE_IMPORT_SINGLETON_DECLARE(SINGLETON_TYPE, CLASS, LOCK) -# endif /* TAO_RTOLDEVENT_BUILD_DLL */ -#else /* TAO_RTOLDEVENT_HAS_DLL == 1 */ -# define TAO_RTOLDEvent_Export -# define TAO_RTOLDEVENT_SINGLETON_DECLARATION(T) -# define TAO_RTOLDEVENT_SINGLETON_DECLARE(SINGLETON_TYPE, CLASS, LOCK) -#endif /* TAO_RTOLDEVENT_HAS_DLL == 1 */ - -#endif /* TAO_RTOLDEVENT_EXPORT_H */ - -// End of auto generated file. diff --git a/TAO/orbsvcs/orbsvcs/Event_Service_Constants.h b/TAO/orbsvcs/orbsvcs/Event_Service_Constants.h index 075adda129a..d430e70b5f7 100644 --- a/TAO/orbsvcs/orbsvcs/Event_Service_Constants.h +++ b/TAO/orbsvcs/orbsvcs/Event_Service_Constants.h @@ -25,21 +25,6 @@ #include "orbsvcs/Time_Utilities.h" -/// This is the number of events a consumer can subscribe to. -const int ACE_ES_MAX_SUBSCRIPTIONS = 32; - -// Max number of suppliers that a channel can handle. -//const int ACE_ES_MAX_SUPPLIERS = 100; - -/// Max number of consumers that one supplier can have subscribed to -/// one type of event (including source-only). This restriction is -/// very lightweight since subscription lists are dynamic. This -/// constant is only used for ACE_ES_Simple_Set in Event_Channel.* for -/// disconnecting consumers. Since these objects are allocated off the -/// stack, we can increase this number without requiring more heap -/// memory. -const int ACE_ES_MAX_CONSUMERS_PER_SUPPLIER = 100; - // = Predefined event types. All application defined types should be // relative to ACE_ES_EVENT_UNDEFINED. const long ACE_ES_EVENT_ANY = 0; @@ -59,7 +44,7 @@ const long ACE_ES_MASKED_TYPE_DESIGNATOR = 13; const long ACE_ES_NULL_DESIGNATOR = 14; const long ACE_ES_EVENT_UNDEFINED = 16; -// = Predefined event sources. +/// Predefined event sources. const long ACE_ES_EVENT_SOURCE_ANY = 0; /// The max number of priorities provided by the target platform. @@ -90,38 +75,6 @@ const u_long ACE_Scheduler_MAX_SUB_PRIORITY = const u_long ACE_Scheduler_MIN_SUB_PRIORITY = ACE_Message_Block::MB_NORMAL; -#if defined(TAO_EC_USE_RECURSIVE_MUTEX) -typedef TAO_SYNCH_RECURSIVE_MUTEX ACE_ES_MUTEX; -typedef ACE_Guard<ACE_ES_RECURSIVE_MUTEX> ACE_ES_GUARD; -#else -typedef TAO_SYNCH_MUTEX ACE_ES_MUTEX; -typedef ACE_Guard<ACE_ES_MUTEX> ACE_ES_GUARD; -#endif - -typedef TAO_SYNCH_RW_MUTEX ACE_ES_RW_LOCK; -typedef ACE_Write_Guard<ACE_ES_RW_LOCK> ACE_ES_WGUARD; -typedef ACE_Read_Guard<ACE_ES_RW_LOCK> ACE_ES_RGUARD; - -// ************************************************************ -// Channel configuration parameters. - -/// ACE_ES_DISPATCHING_MODULE determines what Dispatching Module is -/// used by the channel. ACE_ES_Dispatching_Base is a null dispatcher -/// that can be used to build an EFD. -#define ACE_ES_DISPATCHING_MODULE ACE_ES_Priority_Dispatching -//#define ACE_ES_DISPATCHING_MODULE ACE_ES_Dispatching_Base - -/// This is the number of threads spawned for *each* priority queue in -/// the channel's Dispatching Module. This is used by the channel when -/// creating the dispatch module. -const int THREADS_PER_DISPATCH_QUEUE = 1; - -/// This is the chunk size of the cached allocator for -/// ACE_ES_Event_Container. -const int ACE_ES_EVENT_CONTAINER_MEMORY_POOL = 1024; -const int ACE_ES_EVENT_MEMORY_POOL = 1024; -const int ACE_ES_DISPATCH_REQUEST_MEMORY_POOL = 1024; - #include /**/ "ace/post.h" #endif /* ACE_ES_CONSTANTS_H */ diff --git a/TAO/orbsvcs/orbsvcs/RTOLDEvent.mpc b/TAO/orbsvcs/orbsvcs/RTOLDEvent.mpc deleted file mode 100644 index 120580ea013..00000000000 --- a/TAO/orbsvcs/orbsvcs/RTOLDEvent.mpc +++ /dev/null @@ -1,30 +0,0 @@ -// -*- MPC -*- -// $Id$ - -project(RTOLDEvent) : orbsvcslib, core, rtevent, rtsched { - sharedname = TAO_RTOLDEvent - dynamicflags = TAO_RTOLDEVENT_BUILD_DLL - tagchecks += RTOLDEvent - - IDL_Files { - } - - Source_Files(ORBSVCS_COMPONENTS) { - RTOLDEvent { - Event/BCU.cpp - Event/Dispatching_Modules.cpp - Event/Event_Channel.cpp - Event/Event_Manip.cpp - Event/GPlot_File.cpp - Event/Local_ESTypes.cpp - Event/Memory_Pools.cpp - Event/Module_Factory.cpp - Event/ReactorTask.cpp - Event/RT_Task.cpp - Event/Timer_Module.cpp - } - } - - Template_Files { - } -} diff --git a/TAO/orbsvcs/orbsvcs/RTOldEvent.rc b/TAO/orbsvcs/orbsvcs/RTOldEvent.rc deleted file mode 100644 index 475d7a08ecc..00000000000 --- a/TAO/orbsvcs/orbsvcs/RTOldEvent.rc +++ /dev/null @@ -1,30 +0,0 @@ -#include "..\..\tao\Version.h" - -1 VERSIONINFO - FILEVERSION TAO_MAJOR_VERSION,TAO_MINOR_VERSION,TAO_BETA_VERSION,0 - PRODUCTVERSION TAO_MAJOR_VERSION,TAO_MINOR_VERSION,TAO_BETA_VERSION,0 - FILEFLAGSMASK 0x3fL - FILEFLAGS 0x0L - FILEOS 0x4L - FILETYPE 0x1L - FILESUBTYPE 0x0L -BEGIN - BLOCK "StringFileInfo" - BEGIN - BLOCK "040904B0" - BEGIN - VALUE "FileDescription", "RTOldEvent\0" - VALUE "FileVersion", TAO_VERSION "\0" - VALUE "InternalName", "TAO_RTOldEventDLL\0" - VALUE "LegalCopyright", "\0" - VALUE "LegalTrademarks", "\0" - VALUE "OriginalFilename", "TAO_RTOldEvent.DLL\0" - VALUE "ProductName", "ORBSVCS\0" - VALUE "ProductVersion", TAO_VERSION "\0" - END - END - BLOCK "VarFileInfo" - BEGIN - VALUE "Translation", 0x409, 1200 - END -END |