1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113
|
/* -*- C++ -*- */
//=============================================================================
/**
* @file MT_Reactor_Timer_Test.h
*
* $Id: MT_Reactor_Timer_Test.h 93638 2011-03-24 13:16:05Z johnnyw $
*
* This file contains class definitions needed for template
* instantiation in the MT_Reactor_Timer_Test.cpp file.
*
*
* @author Steve Huston <shuston@riverace.com>
*/
//=============================================================================
#ifndef ACE_TESTS_MT_REACTOR_TIMER_TEST_H
#define ACE_TESTS_MT_REACTOR_TIMER_TEST_H
#include "ace/Reactor.h"
#if !defined (ACE_LACKS_PRAGMA_ONCE)
# pragma once
#endif /* ACE_LACKS_PRAGMA_ONCE */
#include "ace/Task.h"
#include "ace/Pipe.h"
/**
* @class Time_Handler
*
* @brief Test out the multi-threading features of the Reactor's timer
* mechanism.
*/
class Time_Handler : public ACE_Task<ACE_SYNCH>
{
public:
Time_Handler (void);
void setup (void);
int verify_results(void);
/// Run by a daemon thread to handle deferred processing.
virtual int svc (void);
virtual int handle_timeout (const ACE_Time_Value &tv,
const void *arg);
private:
enum
{
TIMER_SLOTS = 10
};
/**
* The timer_id_ array holds timer IDs. They also have some other values
* that are specific to this test:
* -1 the timer has not been set
* -2 the timer was set, but has been cancelled
* -3 the timer was set, and it already fired
*/
long timer_id_[TIMER_SLOTS];
enum { TIMER_NOTSET = -1, TIMER_CANCELLED = -2, TIMER_FIRED = -3 };
long prev_timer_;
#if defined ACE_HAS_THREADS
ACE_Thread_Mutex lock_;
#endif /* ACE_HAS_THREADS */
};
/**
* @class Dispatch_Count_Handler
*
* @brief A simple test to ensure that the Reactor counts the number of
* dispatches correctly.
*/
class Dispatch_Count_Handler : public ACE_Event_Handler
{
public:
Dispatch_Count_Handler (void);
/// Clean up resources from the Reactor.
int handle_close (ACE_HANDLE h,
ACE_Reactor_Mask m);
/// Keep track of the number of timeouts.
virtual int handle_timeout (const ACE_Time_Value &tv,
const void *arg);
/// Keep track of the number of I/O events.
virtual int handle_input (ACE_HANDLE);
/// Keep track of the number of notifies.
virtual int handle_exception (ACE_HANDLE);
/// Verify that the expected events did happen.
int verify_results (void);
private:
/// Provide something to trigger I/O.
ACE_Pipe pipe_;
int input_seen_;
int notify_seen_;
size_t timers_fired_;
};
#endif /* ACE_TESTS_MT_REACTOR_TIMER_TEST_H */
|