3 //=============================================================================
5 * @file Process_Strategy_Test.h
7 * This file contains the definition of Counting_Service and
8 * Options. Some compilers need it in a .h file for template
9 * instantiation (such as AIX C Set ++).
11 * @author Doug Schmidt <d.schmidt@vanderbilt.edu> and Kevin Boyle <kboyle@sanwafp.com>
13 //=============================================================================
16 #ifndef ACE_TESTS_PROCESS_STRATEGY_TEST_H
17 #define ACE_TESTS_PROCESS_STRATEGY_TEST_H
19 #include "ace/Event_Handler.h"
21 #if !defined (ACE_LACKS_PRAGMA_ONCE)
23 #endif /* ACE_LACKS_PRAGMA_ONCE */
25 #include "ace/File_Lock.h"
26 #include "ace/SOCK_Stream.h"
27 #include "ace/Svc_Handler.h"
28 #include "ace/Strategies_T.h"
31 * @class Counting_Service
33 * @brief Reads and increments the count in a shared file.
35 * Objects of this class execute in a separate process as a
36 * result of the <ACE_Strategy_Acceptor> and
37 * <ACE_Process_Strategy>.
39 class Counting_Service
: public ACE_Svc_Handler
<ACE_SOCK_STREAM
, ACE_NULL_SYNCH
>
43 Counting_Service (ACE_Thread_Manager
* = 0);
45 /// Hook that is used to initialize the service (called by the
46 /// <ACE_Strategy_Acceptor::handle_input> Template Method).
47 virtual int open (void *v
);
50 // = Methods invoked via "pointer to method" table entry.
52 /// Handle the THREAD case.
53 virtual int svc (void);
55 // = Operations corresponding to requests from the client.
56 /// Execute the read operation on the file.
59 /// Execute the increment operation on the file.
62 // = Hooks called by <Reactor> and <Strategy_Acceptor>.
64 /// Hook called by the <Reactor> when data arrives from the client.
65 virtual int handle_input (ACE_HANDLE p
= ACE_INVALID_HANDLE
);
68 virtual int handle_close (ACE_HANDLE
= ACE_INVALID_HANDLE
,
69 ACE_Reactor_Mask
= ACE_Event_Handler::ALL_EVENTS_MASK
);
72 class Process_Strategy
: public ACE_Process_Strategy
<Counting_Service
>
77 Process_Strategy (size_t n_processes
= 1,
78 ACE_Event_Handler
*acceptor
= 0,
83 ~Process_Strategy (void);
85 // Overwrite the process creation method to include connection
87 virtual int activate_svc_handler (Counting_Service
*svc_handler
,
94 * @brief Maintains the options for this program.
96 class Options
: public ACE_Event_Handler
105 /// Read command-line arguments and initialize options.
106 int parse_args (int argc
, ACE_TCHAR
*argv
[]);
108 enum Concurrency_Type
110 PROCESS
, // Run the test in separate processes.
111 REACTIVE
, // Run the test reactively in one thread.
112 THREAD
// Run the test as in separate threads.
115 // = Get/set concurrency type.
116 Concurrency_Type
concurrency_type (void);
117 void concurrency_type (Concurrency_Type
);
119 /// Returns the file lock.
120 ACE_File_Lock
&file_lock (void);
122 /// Returns the filename that we're using as the lock.
123 const ACE_TCHAR
*filename (void);
125 /// Returns the concurrency strategy.
126 ACE_Concurrency_Strategy
<Counting_Service
> *concurrency_strategy (void);
129 /// Concurrency strategy that we're running.
130 Concurrency_Type concurrency_type_
;
132 /// Lock for the counting file.
133 ACE_File_Lock file_lock_
;
135 /// Activation strategy that either forks a new process or spawns a
136 /// new thread for each client connection.
137 ACE_Concurrency_Strategy
<Counting_Service
> *concurrency_strategy_
;
139 /// Name of the counting file.
140 ACE_TCHAR filename_
[MAXPATHLEN
+ 1];
143 #endif /* ACE_TESTS_PROCESS_STRATEGY_TEST_H */