[Ace-users] [ace-users] When an Ace_Reactor calls handle_timeout() on an Ace_Event_Handler, is it possible to, within the handle_timeout() call, get at the timer_id that is associated with that particular invocation?

Douglas C. Schmidt schmidt at dre.vanderbilt.edu
Fri Feb 8 07:19:19 CST 2008


Hi Marc,

   Thanks for using the PRF.

>    ACE VERSION: 5.6.2
>
>    HOST MACHINE and OPERATING SYSTEM:
>        Not Available at the moment (sorry)/Red Hat 4
>
>    TARGET MACHINE and OPERATING SYSTEM, if different from HOST:
>    COMPILER NAME AND VERSION (AND PATCHLEVEL): Not Available at the moment 
>(sorry)
>
>    THE $ACE_ROOT/ace/config.h FILE: Not Available at the moment (sorry)
>
>    THE $ACE_ROOT/include/makeinclude/platform_macros.GNU FILE: Not 
>Available at the moment (sorry)
>
>    CONTENTS OF $ACE_ROOT/bin/MakeProjectCreator/config/default.features
>    (used by MPC when you generate your own makefiles): Not Available at the 
>moment (sorry)
>
>    AREA/CLASS/EXAMPLE AFFECTED:
>        Ace_Reactor/Ace_Event_Handler.  Nothing failed to compile, just 
>trying to figure out how to do something.
>    DOES THE PROBLEM AFFECT:
>        COMPILATION? No.
>        LINKING?
>        EXECUTION?  Yes.
>        OTHER (please specify)?
>
>    SYNOPSIS:
>        I'm trying to get access to the timer_id value created when a 
>schedule_timer() method is called
>from within the handle_timeout() call that results, but can't figure out 
>how.

The best way to do this is to use the Asynchronous Completion Token
pattern (see POSA2 www.cs.wustl.edu/~schmidt/POSA/POSA2) that's
implemented with the ACE timer queues and the handle_timeout()
method.  Here's some pseudo-code:

class My_Event_Handler : public ACE_Event_Handler
{
  virtual int handle_timeout (const ACE_Time_Value &,
                              const void *act);

// ...
};

My_Event_Handler eh = new My_Event_Handler;
const void *timer_act = new long;

long timer_id = timer_queue->schedule (eh, timer_act, ....);
*timer_act = timer_id;
...

Now, when My_Event_Handler::handle_timeout() is called back you can
get the timer_id as follows:

int My_Event_Handler::handle_timeout (const ACE_Time_Value &,
                                      const void *act)
{
  long timer_id = *static_cast <long *> (act);
  // .. Do something with timer_id
  delete act;
}

Naturally, you'll need to fix any typos in my pseudo-code ;-)

Take care,

     Doug

>    DESCRIPTION:
>        Hi all, ACE newbie here.  Sorry if this has been discussed, I 
>searched and couldn't find anything.  Basically,
>what I have is a message passing program that wants to read messages from an 
>input socket and send them out an output socket.
>The only tricky part is that I want to either delay (for a set amount of 
>time), or pause entirely, the sending of certain types of messages.
>My design was to have a first reactor that reads the input socket, checks 
>the incoming messages, and passes them on to a second
>reactor via the schedule_timer() method.  If the messages are to be sent 
>immediately, I send it with a zero timeout value.  If they are to
>be delayed, I send them with the appropriate delay value.  The message 
>content is passed within the act argument of the call, ensuring
>the appropriate message is associated with the appropriate event.
>
>The problem I have is that I also want to be able to change the delays of 
>certain messages on the fly.  That means if messages of type 1
>are to be delayed for 1 minute, but during that second the user decides to 
>change the delay to 5 seconds, I need to update the delay on
>the existing timer events that have already been sent for that message type. 
>My solution was this was to manually maintain the set of timer_id
>values that result from the schedule_timer() call, and upon a request for a 
>change just call the reschedule method for active timer_id values
>associated with that message type.  However, I need a way to then remove 
>timer_id values from this manually maintained set, and that's
>where my question comes in.  Is there a way to get at the timer_id 
>associated with a particular handle_timeout() call, from within the
>handle_timeout() call itself (or even the add_/remove_reference() calls)?
>
>I'm a little surprised that I haven't yet found an easy way to do this 
>because intuitively, if we are given access to the timer_id values and
>methods to manipulate their events, a relatively common approach would be to 
>save them into some sort of pool, process them when needed,
>and then remove them from the pool when handle_timeout() is called and they 
>are no longer needed.  I'm guessing that I'm just not seeing
>the set of calls I would need to do to do this.
>
>Any help anyone could offer would be much appreciated, including alternative 
>designs (which I already have, I just like mine better, so
>I'm trying to find a way to make it work).
>
>Thanks,
>Marc Novakouski 
>
>


-- 
Dr. Douglas C. Schmidt                       Professor and Associate Chair
Electrical Engineering and Computer Science  TEL: (615) 343-8197
Vanderbilt University                        WEB: www.dre.vanderbilt.edu/~schmidt
Nashville, TN 37203                          NET: d.schmidt at vanderbilt.edu



More information about the Ace-users mailing list