Merge pull request #2216 from jwillemsen/jwi-cxxversionchecks
[ACE_TAO.git] / ACE / examples / Misc / test_XtReactor2.cpp
blob4eb1ac92b698e0d6f3e97f60dae79467083805bd
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"
11 #include <Xm/PushB.h>
13 class Stdin : public ACE_Event_Handler
15 public:
16 ACE_HANDLE get_handle () const { return ACE_STDIN; }
18 int handle_input (ACE_HANDLE)
20 char c;
21 if (ACE_OS::read (ACE_STDIN, &c, 1)==1)
22 ACE_DEBUG ((LM_DEBUG,
23 "Got input '%d'\n",
24 (int) c));
25 return 0;
28 int handle_timeout (const ACE_Time_Value &tv,
29 const void *)
31 ACE_DEBUG ((LM_DEBUG,
32 "Timeout! %f\n",
33 (double) (tv.msec ()/1000.)));
34 return 0;
38 static void
39 ActivateCB (Widget, XtPointer, XtPointer)
41 ACE_DEBUG ((LM_DEBUG,
42 "Button pushed!\n"));
45 int
46 ACE_TMAIN (int argc, ACE_TCHAR**argv)
48 // The worlds most useless user interface
49 Widget top_level = XtVaAppInitialize (0,
50 "buttontest",
53 &argc,
54 argv,
56 static_cast<void *>(0));
57 char change[] = "change"; // XmCreatePushButton() wants a non-const
58 // string.
59 Widget button = XmCreatePushButton (top_level,
60 change,
62 0);
63 XtManageChild (button);
64 XtAddCallback (button,
65 XmNactivateCallback,
66 ActivateCB,
67 0);
69 // A reactor beastie.
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_,
76 Stdin,
77 -1);
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,
83 ACE_Time_Value (10),
84 ACE_Time_Value (10)) == -1)
85 ACE_ERROR_RETURN ((LM_ERROR,
86 "%p\n",
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));