diff options
author | cdgill <cdgill@ae88bc3d-4319-0410-8dbf-d08b4c9d3795> | 1998-09-21 02:47:15 +0000 |
---|---|---|
committer | cdgill <cdgill@ae88bc3d-4319-0410-8dbf-d08b4c9d3795> | 1998-09-21 02:47:15 +0000 |
commit | 64fb1212a819d6fc487817c10d708490a041cffc (patch) | |
tree | a7775f8cfbe4a42782e0a45a32521c05e64d9049 /examples | |
parent | 7d929ef40ef93132a79fe8114356f75a30dcbcbb (diff) | |
download | ATCD-64fb1212a819d6fc487817c10d708490a041cffc.tar.gz |
fourth checkin of bounded packet relay example: compiles
Diffstat (limited to 'examples')
-rw-r--r-- | examples/Bounded_Packet_Relay/BPR_Drivers.cpp | 112 | ||||
-rw-r--r-- | examples/Bounded_Packet_Relay/BPR_Drivers.h | 222 | ||||
-rw-r--r-- | examples/Bounded_Packet_Relay/Thread_Bounded_Packet_Relay.cpp | 82 | ||||
-rw-r--r-- | examples/Bounded_Packet_Relay/Thread_Bounded_Packet_Relay.h | 44 |
4 files changed, 243 insertions, 217 deletions
diff --git a/examples/Bounded_Packet_Relay/BPR_Drivers.cpp b/examples/Bounded_Packet_Relay/BPR_Drivers.cpp index 3252b477964..d97b7c6fa89 100644 --- a/examples/Bounded_Packet_Relay/BPR_Drivers.cpp +++ b/examples/Bounded_Packet_Relay/BPR_Drivers.cpp @@ -27,38 +27,10 @@ #define _BPR_DRIVER_CPP_ #include "ace/Auto_Ptr.h" -#include "BPR_Driver.h" +#include "BPR_Drivers.h" ACE_RCSID(Bounded_Packet_Relay, BPR_Driver, "$Id$") -// Constructor. - -BPR_Handler_Base (Bounded_Packet_Relay<ACE_Thread_Mutex> &relay, - Thread_Timer_Queue &queue) - : relay_ (relay), - queue (queue) -{ -} - -// Destructor. - -~BPR_Handler_Base (void) -{ -} - -// Helper method: clears all timers. - -int -clear_all_timers (void) -{ - // loop through the timers in the queue, cancelling each one - for (ACE_Timer_Node_T <ACE_Event_Handler *> *node; - (node = queue_->timer_queue ().get_first ()) != 0; - ) - queue_->cancel (node->get_timer_id (), 0); - - return 0; -} // Constructor. @@ -66,15 +38,14 @@ clear_all_timers (void) Input_Device_Wrapper_Base::Input_Device_Wrapper_Base (ACE_Thread_Manager *input_task_mgr) : ACE_Task_Base (input_task_mgr), send_input_msg_cmd_ (0), - input_rate_ (ACE_ONE_SECOND_IN_USECS), - reactor_, + input_period_ (ACE_ONE_SECOND_IN_USECS), is_active_ (0) { } // Destructor. -Input_Device_Wrapper_Base::Input_Device_Wrapper_Base (void) +Input_Device_Wrapper_Base::~Input_Device_Wrapper_Base (void) { delete send_input_msg_cmd_; } @@ -105,6 +76,7 @@ int Input_Device_Wrapper_Base::set_send_count (long count) { send_count_ = count; + return 0; } // Request that the input device stop sending messages @@ -176,7 +148,7 @@ Input_Device_Wrapper_Base::svc (void) if (count > 0) --count; - timeout = ACE_Time_Value (0, period_); + timeout = ACE_Time_Value (0, input_period_); reactor_.run_event_loop (timeout); } @@ -205,10 +177,10 @@ Input_Device_Wrapper_Base::send_input_message (ACE_Message_Block *amb) // Constructor. -template <class SYNCH> -Bounded_Packet_Relay<SYNCH>::Bounded_Packet_Relay (ACE_Thread_Manager *input_task_mgr, - Input_Device_Wrapper_Base *input_wrapper, - Output_Device_Wrapper_Base *output_wrapper) +template <ACE_SYNCH_DECL> +Bounded_Packet_Relay<ACE_SYNCH_USE>::Bounded_Packet_Relay (ACE_Thread_Manager *input_task_mgr, + Input_Device_Wrapper_Base *input_wrapper, + Output_Device_Wrapper_Base *output_wrapper) : input_task_mgr_ (input_task_mgr), input_wrapper_ (input_wrapper), input_thread_handle_ (0), @@ -219,7 +191,7 @@ Bounded_Packet_Relay<SYNCH>::Bounded_Packet_Relay (ACE_Thread_Manager *input_tas queue_lock_, transmission_number_ (0), packets_sent_ (0), - status_ (Bounded_Packet_Relay<SYNCH>::UN_INITIALIZED), + status_ (Bounded_Packet_Relay_Base::UN_INITIALIZED), elapsed_duration_ (0) { if (input_task_mgr_ == 0) @@ -228,8 +200,8 @@ Bounded_Packet_Relay<SYNCH>::Bounded_Packet_Relay (ACE_Thread_Manager *input_tas // Destructor. -template <class SYNCH> -Bounded_Packet_Relay<SYNCH>::~Bounded_Packet_Relay (void) +template <ACE_SYNCH_DECL> +Bounded_Packet_Relay<ACE_SYNCH_USE>::~Bounded_Packet_Relay (void) { delete input_wrapper_; delete output_wrapper_; @@ -237,13 +209,13 @@ Bounded_Packet_Relay<SYNCH>::~Bounded_Packet_Relay (void) // Requests output be sent to output device. -template <class SYNCH> int -Bounded_Packet_Relay<SYNCH>::send_input (void) +template <ACE_SYNCH_DECL> int +Bounded_Packet_Relay<ACE_SYNCH_USE>::send_input (void) { - ACE_Message_Block *item; - // Don't block, return immediately if queue is empty. - if (queue_.dequeue_head (item, ACE_OS::gettimeofday ()) < 0) + ACE_Message_Block *item; + ACE_Time_Value now = ACE_OS::gettimeofday (); + if (queue_.dequeue_head (item, &now) < 0) return 1; // If a message block was dequeued, send it to the output device. @@ -259,27 +231,27 @@ Bounded_Packet_Relay<SYNCH>::send_input (void) // Requests a transmission be started. -template <class SYNCH> int -Bounded_Packet_Relay<SYNCH>::start_transmission (u_long packet_count, - u_long arrival_period, - u_long logging_level) +template <ACE_SYNCH_DECL> int +Bounded_Packet_Relay<ACE_SYNCH_USE>::start_transmission (u_long packet_count, + u_long arrival_period, + u_long logging_level) { // Serialize access to start and end transmission calls, // statistics reporting calls. - ACE_GUARD_RETURN (SYNCH, ace_mon, this->transmission_lock_, -1); + ACE_GUARD_RETURN (ACE_SYNCH_MUTEX_T, ace_mon, this->transmission_lock_, -1); // If a transmission is already in progress, just return. if (status_ == STARTED) return 1; // Update statistics for a new transmission. - ++transmission_number; + ++transmission_number_; packets_sent_ = 0; status_ = STARTED; transmission_start_ = ACE_OS::gettimeofday (); // Initialize the output device. - if (output_wrapper_->modify_device_settings ((void *) &logging level) < 0) + if (output_wrapper_->modify_device_settings ((void *) &logging_level) < 0) { status_ = ERROR; transmission_end_ = ACE_OS::gettimeofday (); @@ -289,7 +261,7 @@ Bounded_Packet_Relay<SYNCH>::start_transmission (u_long packet_count, } // Initialize the input device. - if (input_wrapper_->set_input_period (u_long input_period) < 0) + if (input_wrapper_->set_input_period (arrival_period) < 0) { status_ = ERROR; transmission_end_ = ACE_OS::gettimeofday (); @@ -314,12 +286,12 @@ Bounded_Packet_Relay<SYNCH>::start_transmission (u_long packet_count, // Requests a transmission be ended. -template <class SYNCH> int -Bounded_Packet_Relay<SYNCH>::end_transmission (Transmission_Status status) +template <ACE_SYNCH_DECL> int +Bounded_Packet_Relay<ACE_SYNCH_USE>::end_transmission (Transmission_Status status) { // Serialize access to start and end transmission calls, // statistics reporting calls. - ACE_GUARD_RETURN (SYNCH, ace_mon, this->transmission_lock_, -1); + ACE_GUARD_RETURN (ACE_SYNCH_MUTEX_T, ace_mon, this->transmission_lock_, -1); // If a transmission is not already in progress, just return. if (status_ != STARTED) @@ -353,12 +325,12 @@ Bounded_Packet_Relay<SYNCH>::end_transmission (Transmission_Status status) // Requests a report of statistics from the last transmission. -template <class SYNCH> int -Bounded_Packet_Relay<SYNCH>::report_statistics (void) +template <ACE_SYNCH_DECL> int +Bounded_Packet_Relay<ACE_SYNCH_USE>::report_statistics (void) { // Serialize access to start and end transmission calls, // statistics reporting calls. - ACE_GUARD_RETURN (SYNCH, ace_mon, this->transmission_lock_, -1); + ACE_GUARD_RETURN (ACE_SYNCH_MUTEX_T, ace_mon, this->transmission_lock_, -1); // If a transmission is already in progress, just return. if (status_ == STARTED) @@ -417,22 +389,22 @@ Bounded_Packet_Relay<SYNCH>::report_statistics (void) // Public entry point to which to push input. -template <class SYNCH> int -Bounded_Packet_Relay<SYNCH>::receive_input (void * arg) +template <ACE_SYNCH_DECL> int +Bounded_Packet_Relay<ACE_SYNCH_USE>::receive_input (void * arg) { ACE_Message_Block *message = ACE_static_cast (ACE_Message_Block *, arg); if (queue_.enqueue_tail (message) < 0) ACE_ERROR_RETURN ((LM_ERROR, "%t %p\n", - "Bounded_Packet_Relay<SYNCH>::receive_input failed"), + "Bounded_Packet_Relay<ACE_SYNCH_USE>::receive_input failed"), -1); return 0; } // Parse the input and execute the corresponding command. -template <class TQ, class RECEIVER, class ACTION> int -Bounded_Packet_Relay_Driver<TQ, RECEIVER, ACTION>::parse_commands (const char *buf) +template <class TQ> int +Bounded_Packet_Relay_Driver<TQ>::parse_commands (const char *buf) { int option; @@ -562,8 +534,8 @@ Bounded_Packet_Relay_Driver<TQ, RECEIVER, ACTION>::parse_commands (const char *b // Runs the test. -template <class TQ, class RECEIVER, class ACTION> int -Bounded_Packet_Relay_Driver<TQ, RECEIVER, ACTION>::run (void) +template <class TQ> int +Bounded_Packet_Relay_Driver<TQ>::run (void) { this->init (); @@ -576,8 +548,8 @@ Bounded_Packet_Relay_Driver<TQ, RECEIVER, ACTION>::run (void) // Gets the next request from the user input. -template <class TQ, class RECEIVER, class ACTION> int -Bounded_Packet_Relay_Driver<TQ, RECEIVER, ACTION>::get_next_request (void) +template <class TQ> int +Bounded_Packet_Relay_Driver<TQ>::get_next_request (void) { char buf[BUFSIZ]; @@ -597,8 +569,8 @@ Bounded_Packet_Relay_Driver<TQ, RECEIVER, ACTION>::get_next_request (void) // Reads input from the user from ACE_STDIN into the buffer specified. -template <class TQ, class RECEIVER, class ACTION> ssize_t -Bounded_Packet_Relay_Driver<TQ, RECEIVER, ACTION>::read_input (char *buf, size_t bufsiz) +template <class TQ> ssize_t +Bounded_Packet_Relay_Driver<TQ>::read_input (char *buf, size_t bufsiz) { ACE_OS::memset (buf, 0, bufsiz); diff --git a/examples/Bounded_Packet_Relay/BPR_Drivers.h b/examples/Bounded_Packet_Relay/BPR_Drivers.h index 82eb3ead629..1b424c2eda5 100644 --- a/examples/Bounded_Packet_Relay/BPR_Drivers.h +++ b/examples/Bounded_Packet_Relay/BPR_Drivers.h @@ -31,6 +31,10 @@ #include "ace/Task.h" +// forward declarations +class Input_Device_Wrapper_Base; +class Output_Device_Wrapper_Base; + class Command_Base { // = TITLE @@ -46,39 +50,115 @@ public: // Invokes the method <action_> from the object <receiver_>. }; -class BPR_Handler_Base : public ACE_Event_Handler +class Bounded_Packet_Relay_Base +{ + // = TITLE + // Base class for the time-bounded packet relay class. + // + // = DESCRIPTION + // This enum must go here to avoid confusing certain broken C++ + // compilers. +public: + + // = Enumerates possible status values for a transmission. + + enum Transmission_Status + { + UN_INITIALIZED, + STARTED, + COMPLETED, + TIMED_OUT, + CANCELLED, + ERROR + }; +}; + +template <ACE_SYNCH_DECL> +class Bounded_Packet_Relay : public Bounded_Packet_Relay_Base { // = TITLE - // Base event handler class for bounded packet relay example. + // This class defines a packet relay abstraction for a transmission + // bounded external commands to start and end the transmission. The + // transmission may be bounded by the number of packets to send, the + // dration of the transmission, or any other factors. // // = DESCRIPTION - // The <handle_timeout> hook method calls the relay's send - // method and decrements its count of messages to send. - // If there are still messages to send, it re-registers itself - // with the timer queue. Otherwise it calls the relay's end - // transmission method, clears the timer queue, and then deletes "this". + // The relay abstraction implemented by this class registers a callback + // command with an input device wrapper, and relays input to an output + // device at a pace specified in the start transmission call. public: - BPR_Handler_Base (Bounded_Packet_Relay<ACE_Thread_Mutex> &relay, - Thread_Timer_Queue &queue); + + typedef int (Bounded_Packet_Relay::*ACTION) (void *); + // Command entry point type definition. + + // = Initialization method + + Bounded_Packet_Relay (ACE_Thread_Manager *input_task_mgr, + Input_Device_Wrapper_Base *input_wrapper, + Output_Device_Wrapper_Base *output_wrapper); // Constructor. - ~BPR_Handler_Base (void); + virtual ~Bounded_Packet_Relay (void); // Destructor. - virtual int clear_all_timers (void); - // Helper method: clears all timers. + int send_input (void); + // Requests output be sent to output device. + + int start_transmission (u_long packet_count, + u_long arrival_period, + u_long logging_level); + // Requests a transmission be started. -protected: + int end_transmission (Transmission_Status status); + // Requests a transmission be ended. + + int report_statistics (void); + // Requests a report of statistics from the last transmission. + + // = Command Accessible Entry Points. + + int receive_input (void *); + // Public entry point to which to push input. + +private: + // = Concurrency Management. + + ACE_Thread_Manager * input_task_mgr_; + // Thread manager for the input device task. + + Input_Device_Wrapper_Base * input_wrapper_; + // Pointer to the input device wrapper. + + Output_Device_Wrapper_Base * output_wrapper_; + // Pointer to the output device wrapper. + + ACE_Message_Queue<ACE_SYNCH_USE> queue_; + // Queue used to buffer input messages. - Bounded_Packet_Relay<ACE_Thread_Mutex> &relay_; - // Stores a reference to the relay object on which to invoke - // the appropritate calls when the timer expires. + ACE_SYNCH_MUTEX_T transmission_lock_; + // Lock for thread-safe synchronization + // of transmission startup and termination. + + // = Transmission Statistics + + u_long transmission_number_; + // Number of transmissions sent. + + u_long packets_sent_; + // Count of packets sent in the most recent transmission. + + Transmission_Status status_; + // Status of the current or most recent transmission. + + ACE_Time_Value transmission_start_; + // Start time of the most recent transmission. + + ACE_Time_Value transmission_end_; + // Ending time of the most recent transmission. - Thread_Timer_Queue &queue_; - // Store a reference to the timer queue, in which to re-register - // the send timer and handler if there are still sends to perform. }; + class Input_Device_Wrapper_Base : public ACE_Task_Base { // = TITLE @@ -179,110 +259,6 @@ public: // Provides an abstract interface to allow modifying device settings. }; -class Bounded_Packet_Relay_Base -{ - // = TITLE - // Base class for the time-bounded packet relay class. - // - // = DESCRIPTION - // This enum must go here to avoid confusing certain broken C++ - // compilers. -public: - enum Transmission_Status - { - UN_INITIALIZED, - STARTED, - COMPLETED, - TIMED_OUT, - CANCELLED, - ERROR - }; -}; - -template <class SYNCH> -class Bounded_Packet_Relay : public Bounded_Packet_Relay_Base -{ - // = TITLE - // This class defines a packet relay abstraction for a transmission - // bounded external commands to start and end the transmission. The - // transmission may be bounded by the number of packets to send, the - // dration of the transmission, or any other factors. - // - // = DESCRIPTION - // The relay abstraction implemented by this class registers a callback - // command with an input device wrapper, and relays input to an output - // device at a pace specified in the start transmission call. -public: - - typedef int (Bounded_Packet_Relay::*ACTION) (void *); - // Command entry point type definition. - - // = Enumerates possible status values at the end of a transmission. - - Bounded_Packet_Relay (ACE_Thread_Manager *input_task_mgr, - Input_Device_Wrapper_Base *input_wrapper, - Output_Device_Wrapper_Base *output_wrapper); - // Constructor. - - virtual ~Bounded_Packet_Relay (void); - // Destructor. - - int send_input (void); - // Requests output be sent to output device. - - int start_transmission (u_long packet_count, - u_long arrival_period, - u_long logging_level); - // Requests a transmission be started. - - int end_transmission (Transmission_Status status); - // Requests a transmission be ended. - - int report_statistics (void); - // Requests a report of statistics from the last transmission. - - // = Command Accessible Entry Points. - - int receive_input (void *); - // Public entry point to which to push input. - -private: - // = Concurrency Management. - - ACE_Thread_Manager * input_task_mgr_; - // Thread manager for the input device task. - - Input_Device_Wrapper_Base * input_wrapper_; - // Pointer to the input device wrapper. - - Output_Device_Wrapper_Base * output_wrapper_; - // Pointer to the output device wrapper. - - ACE_Message_Queue<SYNCH> queue_; - // Queue used to buffer input messages. - - SYNCH transmission_lock_; - // Lock for thread-safe synchronization - // of transmission startup and termination. - - // = Transmission Statistics - - u_long transmission_number_; - // Number of transmissions sent. - - u_long packets_sent_; - // Count of packets sent in the most recent transmission. - - Transmission_Status status_; - // Status of the current or most recent transmission. - - ACE_Time_Value transmission_start_; - // Start time of the most recent transmission. - - ACE_Time_Value transmission_end_; - // Ending time of the most recent transmission. - -}; template <class TQ> class Bounded_Packet_Relay_Driver diff --git a/examples/Bounded_Packet_Relay/Thread_Bounded_Packet_Relay.cpp b/examples/Bounded_Packet_Relay/Thread_Bounded_Packet_Relay.cpp index ea4804828ae..1612815bd3a 100644 --- a/examples/Bounded_Packet_Relay/Thread_Bounded_Packet_Relay.cpp +++ b/examples/Bounded_Packet_Relay/Thread_Bounded_Packet_Relay.cpp @@ -360,15 +360,15 @@ User_Input_Task::end_transmission (void *argument) if (relay_) { - Bounded_Packet_Relay::Transmission_Status *status; + Bounded_Packet_Relay_Base::Transmission_Status *status; status = - ACE_static_cast (Bounded_Packet_Relay::Transmission_Status *, + ACE_static_cast (Bounded_Packet_Relay_Base::Transmission_Status *, argument); if (status) { - switch (relay_->end_transmission (*status) + switch (relay_->end_transmission (*status)) { case 1: ACE_DEBUG ((LM_DEBUG, @@ -458,15 +458,61 @@ User_Input_Task::shutdown (void *argument) } +// Helper method: clears all timers. + +int +User_Input_Task::clear_all_timers (void) +{ + // loop through the timers in the queue, cancelling each one + for (ACE_Timer_Node_T <ACE_Event_Handler *> *node; + (node = queue_->timer_queue ().get_first ()) != 0; + ) + queue_->cancel (node->get_timer_id (), 0); + + return 0; +} + + +// Constructor. + +BPR_Handler_Base::BPR_Handler_Base ( + Bounded_Packet_Relay<ACE_MT_SYNCH> &relay, + Thread_Timer_Queue &queue) + : relay_ (relay), + queue_ (queue) +{ +} + +// Destructor. + +BPR_Handler_Base::~BPR_Handler_Base (void) +{ +} + +// Helper method: clears all timers. + +int +BPR_Handler_Base::clear_all_timers (void) +{ + // loop through the timers in the queue, cancelling each one + for (ACE_Timer_Node_T <ACE_Event_Handler *> *node; + (node = queue_.timer_queue ().get_first ()) != 0; + ) + queue_.cancel (node->get_timer_id (), 0); + + return 0; +} + + // Constructor. Send_Handler::Send_Handler (u_long send_count, const ACE_Time_Value &duration, - Bounded_Packet_Relay<ACE_Thread_Mutex> &relay, + Bounded_Packet_Relay<ACE_MT_SYNCH> &relay, Thread_Timer_Queue &queue) : BPR_Handler_Base (relay, queue), send_count_ (send_count), - duration_ (duration), + duration_ (duration) { } @@ -482,7 +528,7 @@ int Send_Handler::handle_timeout (const ACE_Time_Value ¤t_time, const void *arg) { - switch (relay_->send_input ()) + switch (relay_.send_input ()) { case 0: // Decrement count of packets to relay. @@ -492,8 +538,8 @@ Send_Handler::handle_timeout (const ACE_Time_Value ¤t_time, if (send_count_ > 0) { // Re-register the handler for a new timeout. - if (queue_->schedule (this, 0, - duration_ + ACE_OS::gettimeofday ()) < 0) + if (queue_.schedule (this, 0, + duration_ + ACE_OS::gettimeofday ()) < 0) ACE_ERROR_RETURN ((LM_ERROR, "Send_Handler::handle_timeout: " "failed to reschedule send handler"), @@ -505,7 +551,7 @@ Send_Handler::handle_timeout (const ACE_Time_Value ¤t_time, // All packets are sent, time to cancel any other // timers, end the transmission, and go away. this->clear_all_timers (); - relay_->end_transmission (Bounded_Packet_Relay::COMPLETED); + relay_.end_transmission (Bounded_Packet_Relay_Base::COMPLETED); delete this; return 0; } @@ -527,7 +573,7 @@ Send_Handler::cancelled (void) // Constructor. -Termination_Handler::Termination_Handler (Bounded_Packet_Relay<ACE_Thread_Mutex> &relay, +Termination_Handler::Termination_Handler (Bounded_Packet_Relay<ACE_MT_SYNCH> &relay, Thread_Timer_Queue &queue) : BPR_Handler_Base (relay, queue) { @@ -548,7 +594,7 @@ Termination_Handler::handle_timeout (const ACE_Time_Value ¤t_time, // Transmission timed out, so cancel any other // timers, end the transmission, and go away. this->clear_all_timers (); - relay_->end_transmission (Bounded_Packet_Relay::TIMED_OUT); + relay_.end_transmission (Bounded_Packet_Relay_Base::TIMED_OUT); delete this; return 0; } @@ -607,7 +653,7 @@ Thread_Bounded_Packet_Relay_Driver::display_menu (void) // Initialize the driver. int -Thread_Bounded_Packet_Relay_Driver::init (void); +Thread_Bounded_Packet_Relay_Driver::init (void) { // Initialize the <Command> objects with their corresponding // methods from <User_Input_Task>. @@ -673,16 +719,12 @@ Thread_Bounded_Packet_Relay_Driver::run (void) #if defined (ACE_HAS_EXPLICIT_TEMPLATE_INSTANTIATION) template class ACE_Thread_Timer_Queue_Adapter<Timer_Heap>; -template class Bounded_Packet_Relay_Driver<Thread_Timer_Queue, - Input_Task, - Input_Task::ACTION>; -template class Command<Input_Task, Input_Task::ACTION>; +template class Bounded_Packet_Relay_Driver<Thread_Timer_Queue>; +template class Command<User_Input_Task, User_Input_Task::ACTION>; #elif defined (ACE_HAS_TEMPLATE_INSTANTIATION_PRAGMA) #pragma instantiate ACE_Thread_Timer_Queue_Adapter<Timer_Heap> -#pragma instantiate Bounded_Packet_Relay_Driver<Thread_Timer_Queue, \ - Input_Task, \ - Input_Task::ACTION> -#pragma instantiate Command<Input_Task, Input_Task::ACTION> +#pragma instantiate Bounded_Packet_Relay_Driver<Thread_Timer_Queue> +#pragma instantiate Command<User_Input_Task, User_Input_Task::ACTION> #endif /* ACE_HAS_EXPLICIT_TEMPLATE_INSTANTIATION */ #if defined (ACE_MT_SAFE) && (ACE_MT_SAFE != 0) diff --git a/examples/Bounded_Packet_Relay/Thread_Bounded_Packet_Relay.h b/examples/Bounded_Packet_Relay/Thread_Bounded_Packet_Relay.h index b94bbbca282..4d97d40a37d 100644 --- a/examples/Bounded_Packet_Relay/Thread_Bounded_Packet_Relay.h +++ b/examples/Bounded_Packet_Relay/Thread_Bounded_Packet_Relay.h @@ -206,11 +206,14 @@ public: int shutdown (void *); // Shuts down the task. + int clear_all_timers (void); + // Helper method: clears all timers. + private: const int usecs_; // How many microseconds are in a second. - Bounded_Packet_Relay<ACE_Thread_Mutex> *relay_; + Bounded_Packet_Relay<ACE_MT_SYNCH> *relay_; // The bounded packet relay. Thread_Timer_Queue *queue_; @@ -236,6 +239,39 @@ private: }; +class BPR_Handler_Base : public ACE_Event_Handler +{ + // = TITLE + // Base event handler class for bounded packet relay example. + // + // = DESCRIPTION + // The <handle_timeout> hook method calls the relay's send + // method and decrements its count of messages to send. + // If there are still messages to send, it re-registers itself + // with the timer queue. Otherwise it calls the relay's end + // transmission method, clears the timer queue, and then deletes "this". +public: + BPR_Handler_Base (Bounded_Packet_Relay<ACE_MT_SYNCH> &relay, + Thread_Timer_Queue &queue); + // Constructor. + + ~BPR_Handler_Base (void); + // Destructor. + + virtual int clear_all_timers (void); + // Helper method: clears all timers. + +protected: + + Bounded_Packet_Relay<ACE_MT_SYNCH> &relay_; + // Stores a reference to the relay object on which to invoke + // the appropritate calls when the timer expires. + + Thread_Timer_Queue &queue_; + // Store a reference to the timer queue, in which to re-register + // the send timer and handler if there are still sends to perform. +}; + class Send_Handler : public BPR_Handler_Base { // = TITLE @@ -250,7 +286,7 @@ class Send_Handler : public BPR_Handler_Base public: Send_Handler (u_long send_count, const ACE_Time_Value &duration, - Bounded_Packet_Relay<ACE_Thread_Mutex> &relay, + Bounded_Packet_Relay<ACE_MT_SYNCH> &relay, Thread_Timer_Queue &queue); // Constructor. @@ -284,7 +320,7 @@ class Termination_Handler : public BPR_Handler_Base // The <handle_timeout> hook method calls the relay's end // transmission method, and then deletes "this". public: - Termination_Handler (Bounded_Packet_Relay<ACE_Thread_Mutex> &relay, + Termination_Handler (Bounded_Packet_Relay<ACE_MT_SYNCH> &relay, Thread_Timer_Queue &queue); // Constructor. @@ -315,7 +351,7 @@ public: // = Trait for commands issued from this driver - typedef Command<Input_Task, Input_Task::ACTION> COMMAND; + typedef Command<User_Input_Task, User_Input_Task::ACTION> COMMAND; // = Initialization and termination methods. |