Merge pull request #1844 from jrw972/monterey
[ACE_TAO.git] / ACE / tests / MT_Reactor_Timer_Test.h
blob4c0a9e68f3563e83b48dfdb06c371e090ae30a4a
1 /* -*- C++ -*- */
3 //=============================================================================
4 /**
5 * @file MT_Reactor_Timer_Test.h
7 * This file contains class definitions needed for template
8 * instantiation in the MT_Reactor_Timer_Test.cpp file.
10 * @author Steve Huston <shuston@riverace.com>
12 //=============================================================================
15 #ifndef ACE_TESTS_MT_REACTOR_TIMER_TEST_H
16 #define ACE_TESTS_MT_REACTOR_TIMER_TEST_H
18 #include "ace/Reactor.h"
20 #if !defined (ACE_LACKS_PRAGMA_ONCE)
21 # pragma once
22 #endif /* ACE_LACKS_PRAGMA_ONCE */
24 #include "ace/Task.h"
25 #include "ace/Pipe.h"
27 /**
28 * @class Time_Handler
30 * @brief Test out the multi-threading features of the Reactor's timer
31 * mechanism.
33 class Time_Handler : public ACE_Task<ACE_SYNCH>
35 public:
36 Time_Handler (void);
38 void setup (void);
40 int verify_results(void);
42 /// Run by a daemon thread to handle deferred processing.
43 virtual int svc (void);
45 virtual int handle_timeout (const ACE_Time_Value &tv,
46 const void *arg);
48 private:
49 enum
51 TIMER_SLOTS = 10
54 /**
55 * The timer_id_ array holds timer IDs. They also have some other values
56 * that are specific to this test:
57 * -1 the timer has not been set
58 * -2 the timer was set, but has been cancelled
59 * -3 the timer was set, and it already fired
61 long timer_id_[TIMER_SLOTS];
62 enum { TIMER_NOTSET = -1, TIMER_CANCELLED = -2, TIMER_FIRED = -3 };
64 long prev_timer_;
66 #if defined ACE_HAS_THREADS
67 ACE_Thread_Mutex lock_;
68 #endif /* ACE_HAS_THREADS */
72 /**
73 * @class Dispatch_Count_Handler
75 * @brief A simple test to ensure that the Reactor counts the number of
76 * dispatches correctly.
78 class Dispatch_Count_Handler : public ACE_Event_Handler
80 public:
81 Dispatch_Count_Handler (void);
83 /// Clean up resources from the Reactor.
84 int handle_close (ACE_HANDLE h,
85 ACE_Reactor_Mask m);
87 /// Keep track of the number of timeouts.
88 virtual int handle_timeout (const ACE_Time_Value &tv,
89 const void *arg);
91 /// Keep track of the number of I/O events.
92 virtual int handle_input (ACE_HANDLE);
94 /// Keep track of the number of notifies.
95 virtual int handle_exception (ACE_HANDLE);
97 /// Verify that the expected events did happen.
98 int verify_results (void);
100 private:
101 /// Provide something to trigger I/O.
102 ACE_Pipe pipe_;
104 int input_seen_;
105 int notify_seen_;
106 size_t timers_fired_;
110 #endif /* ACE_TESTS_MT_REACTOR_TIMER_TEST_H */