1 // The following test exercises the Eric C. Newton's <ecn@clark.net>
2 // XtReactor implementation.
4 #include "ace/OS_main.h"
5 #include "ace/XtReactor/XtReactor.h"
6 #include "ace/Reactor.h"
7 #include "ace/Message_Block.h"
8 #include "ace/Log_Msg.h"
9 #include "ace/OS_NS_unistd.h"
13 class Stdin
: public ACE_Event_Handler
16 ACE_HANDLE
get_handle () const { return ACE_STDIN
; }
18 int handle_input (ACE_HANDLE
)
21 if (ACE_OS::read (ACE_STDIN
, &c
, 1)==1)
28 int handle_timeout (const ACE_Time_Value
&tv
,
33 (double) (tv
.msec ()/1000.)));
39 ActivateCB (Widget
, XtPointer
, XtPointer
)
46 ACE_TMAIN (int argc
, ACE_TCHAR
**argv
)
48 // The worlds most useless user interface
49 Widget top_level
= XtVaAppInitialize (0,
56 static_cast<void *>(0));
57 char change
[] = "change"; // XmCreatePushButton() wants a non-const
59 Widget button
= XmCreatePushButton (top_level
,
63 XtManageChild (button
);
64 XtAddCallback (button
,
70 ACE_XtReactor
xreactor (XtWidgetToApplicationContext (top_level
));
71 ACE_Reactor
reactor (&xreactor
);
73 // Print a message when data is recv'd on stdin...
74 ACE_Event_Handler
* stdin_
;
75 ACE_NEW_RETURN (stdin_
,
78 reactor
.register_handler (stdin_
,
79 ACE_Event_Handler::READ_MASK
);
81 // Print a message every 10 seconds
82 if (reactor
.schedule_timer (stdin_
, 0,
84 ACE_Time_Value (10)) == -1)
85 ACE_ERROR_RETURN ((LM_ERROR
,
87 "schedule_timer"), -1);
89 // Show the top_level widget
90 XtRealizeWidget (top_level
);
92 // Demonstrate Reactor/Xt event loop unification:
93 XtAppMainLoop (XtWidgetToApplicationContext (top_level
));