Use =default for skeleton copy constructor
[ACE_TAO.git] / ACE / tests / Process_Strategy_Test.h
blob8075bd35e7c0f809d6a78413900ca6073c68bb67
1 /* -*- C++ -*- */
3 //=============================================================================
4 /**
5 * @file Process_Strategy_Test.h
7 * This file contains the definition of Counting_Service and
8 * Options.
10 * @author Doug Schmidt <d.schmidt@vanderbilt.edu> and Kevin Boyle <kboyle@sanwafp.com>
12 //=============================================================================
15 #ifndef ACE_TESTS_PROCESS_STRATEGY_TEST_H
16 #define ACE_TESTS_PROCESS_STRATEGY_TEST_H
18 #include "ace/Event_Handler.h"
20 #if !defined (ACE_LACKS_PRAGMA_ONCE)
21 # pragma once
22 #endif /* ACE_LACKS_PRAGMA_ONCE */
24 #include "ace/File_Lock.h"
25 #include "ace/SOCK_Stream.h"
26 #include "ace/Svc_Handler.h"
27 #include "ace/Strategies_T.h"
29 /**
30 * @class Counting_Service
32 * @brief Reads and increments the count in a shared file.
34 * Objects of this class execute in a separate process as a
35 * result of the <ACE_Strategy_Acceptor> and
36 * <ACE_Process_Strategy>.
38 class Counting_Service : public ACE_Svc_Handler <ACE_SOCK_STREAM, ACE_NULL_SYNCH>
40 public:
41 /// Constructor.
42 Counting_Service (ACE_Thread_Manager * = 0);
44 /// Hook that is used to initialize the service (called by the
45 /// <ACE_Strategy_Acceptor::handle_input> Template Method).
46 virtual int open (void *v);
48 protected:
49 // = Methods invoked via "pointer to method" table entry.
51 /// Handle the THREAD case.
52 virtual int svc ();
54 // = Operations corresponding to requests from the client.
55 /// Execute the read operation on the file.
56 int read ();
58 /// Execute the increment operation on the file.
59 int inc ();
61 // = Hooks called by <Reactor> and <Strategy_Acceptor>.
63 /// Hook called by the <Reactor> when data arrives from the client.
64 virtual int handle_input (ACE_HANDLE p = ACE_INVALID_HANDLE);
66 /// Closing down
67 virtual int handle_close (ACE_HANDLE = ACE_INVALID_HANDLE,
68 ACE_Reactor_Mask = ACE_Event_Handler::ALL_EVENTS_MASK);
71 class Process_Strategy : public ACE_Process_Strategy<Counting_Service>
73 public:
74 // Constructor
75 Process_Strategy (size_t n_processes = 1,
76 ACE_Event_Handler *acceptor = 0,
77 ACE_Reactor * = 0,
78 int flags = 0);
80 // Destructor
81 ~Process_Strategy ();
83 // Overwrite the process creation method to include connection
84 // counting
85 virtual int activate_svc_handler (Counting_Service *svc_handler,
86 void *arg = 0);
89 /**
90 * @class Options
92 * @brief Maintains the options for this program.
94 class Options : public ACE_Event_Handler
96 public:
97 /// Constructor.
98 Options ();
100 /// Destructor.
101 ~Options ();
103 /// Read command-line arguments and initialize options.
104 int parse_args (int argc, ACE_TCHAR *argv[]);
106 enum Concurrency_Type
108 PROCESS, // Run the test in separate processes.
109 REACTIVE, // Run the test reactively in one thread.
110 THREAD // Run the test as in separate threads.
113 // = Get/set concurrency type.
114 Concurrency_Type concurrency_type ();
115 void concurrency_type (Concurrency_Type);
117 /// Returns the file lock.
118 ACE_File_Lock &file_lock ();
120 /// Returns the filename that we're using as the lock.
121 const ACE_TCHAR *filename ();
123 /// Returns the concurrency strategy.
124 ACE_Concurrency_Strategy <Counting_Service> *concurrency_strategy ();
126 private:
127 /// Concurrency strategy that we're running.
128 Concurrency_Type concurrency_type_;
130 /// Lock for the counting file.
131 ACE_File_Lock file_lock_;
133 /// Activation strategy that either forks a new process or spawns a
134 /// new thread for each client connection.
135 ACE_Concurrency_Strategy<Counting_Service> *concurrency_strategy_;
137 /// Name of the counting file.
138 ACE_TCHAR filename_[MAXPATHLEN + 1];
141 #endif /* ACE_TESTS_PROCESS_STRATEGY_TEST_H */