Sophie

Sophie

distrib > Mandriva > 10.0 > i586 > media > contrib > by-pkgid > 21280410b6ea906d791d7a12afae2579 > files > 418

libace5-doc-5.4-2mdk.i586.rpm

<HTML>
<!-- ex01.html,v 1.2 2000/06/04 22:02:08 brunsch Exp -->
<HEAD>
   <META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=iso-8859-1">
   <META NAME="Author" CONTENT="Ambreen Ilyas">
   <META NAME="GENERATOR" CONTENT="Mozilla/4.05 [en] (X11; I; SunOS 5.5.1 sun4u) [Netscape]">
   <TITLE>Example 1</TITLE>
</HEAD>
<BODY>
<FONT COLOR="#CC0000">/////////////////////////////////////////////////////////////////////////////////////////////////////////////////</FONT>
<BR><FONT COLOR="#CC0000">//// This example is from the ACE Programmers
Guide.</FONT>
<BR><FONT COLOR="#CC0000">////&nbsp; Chapter:&nbsp; "The Reactor" (Event
Management)</FONT>
<BR><FONT COLOR="#CC0000">//// For details please see the guide at</FONT>
<BR><FONT COLOR="#CC0000">//// http://www.cs.wustl.edu/~schmidt/ACE.html</FONT>
<BR><FONT COLOR="#CC0000">////&nbsp; AUTHOR: Umar Syyid (usyyid@hns.com)</FONT>
<BR><FONT COLOR="#CC0000">//// and Ambreen Ilyas (ambreen@bitsmart.com)</FONT>
<BR><FONT COLOR="#CC0000">/////////////////////////////////////////////////////////////////////////////////////////////////////////////</FONT>

<P><FONT COLOR="#FF0000">//Example 1</FONT>
<BR><FONT COLOR="#000099">#include</FONT> <FONT COLOR="#006600">&lt;signal.h></FONT>
<BR><FONT COLOR="#000099">#include</FONT> <FONT COLOR="#006600">"ace/Reactor.h"</FONT>
<BR><FONT COLOR="#000099">#include</FONT> <FONT COLOR="#006600">"ace/Event_Handler.h"</FONT>

<P><FONT COLOR="#FF0000">//Create our subclass to handle the signal events</FONT>
<BR><FONT COLOR="#FF0000">//that we wish to handle. Since we know that
this particular</FONT>
<BR><FONT COLOR="#FF0000">//event handler is going to be using signals
we only overload the</FONT>
<BR><FONT COLOR="#FF0000">//handle_signal method.</FONT>

<P>class
<BR>MyEventHandler: public ACE_Event_Handler{
<BR>int
<BR>handle_signal(int signum, siginfo_t*,ucontext_t*){
<BR>&nbsp;switch(signum){
<BR>&nbsp; case SIGWINCH:
<BR>&nbsp;&nbsp; ACE_DEBUG((LM_DEBUG, "You pressed SIGWINCH \n"));
<BR>&nbsp;&nbsp; break;

<P>&nbsp; case SIGINT:
<BR>&nbsp;&nbsp; ACE_DEBUG((LM_DEBUG, "You pressed SIGINT \n"));
<BR>&nbsp;&nbsp; break;
<BR>&nbsp;&nbsp; }
<BR>&nbsp;return 0;
<BR>&nbsp;}
<BR>};

<P>int main(int argc, char *argv[]){
<BR><FONT COLOR="#FF0000">&nbsp;//instantiate the handler</FONT>
<BR>&nbsp;MyEventHandler *eh =new MyEventHandler;

<P><FONT COLOR="#FF0000">//Register the handler asking to call back when
either SIGWINCH</FONT>
<BR><FONT COLOR="#FF0000">//or SIGINT signals occur. Note that in both
the cases we asked the</FONT>
<BR><FONT COLOR="#FF0000">//Reactor to call back the same Event_Handler
i.e., MyEventHandler.</FONT>
<BR><FONT COLOR="#FF0000">//This is the reason why we had to write a switch
statement in the handle_signal()</FONT>
<BR><FONT COLOR="#FF0000">//method above. Also note that the</FONT>
<BR><FONT COLOR="#FF0000">//ACE_Reactor is being used as a Singleton object&nbsp;
(Singleton pattern)</FONT>

<P>&nbsp;ACE_Reactor::instance()->register_handler(SIGWINCH,eh);
<BR>&nbsp;ACE_Reactor::instance()->register_handler(SIGINT,eh);
<BR>&nbsp;while(1)
<BR>&nbsp;<FONT COLOR="#FF0000"> //Start the reactors event loop</FONT>
<BR>&nbsp; ACE_Reactor::instance()->handle_events();
<BR>}

<P>&nbsp;<A HREF="ex02.html">Next Example</A>
<BR>&nbsp;
</BODY>
</HTML>