Merge pull request #2216 from jwillemsen/jwi-cxxversionchecks
[ACE_TAO.git] / ACE / examples / Shared_Malloc / Options.cpp
blob0c8fc3710d23e4e032c44be77937a1cb021e9378
1 #include "ace/Get_Opt.h"
2 #include "Options.h"
3 #include "ace/Log_Msg.h"
4 #include "ace/OS_NS_stdlib.h"
5 #include "ace/OS_NS_string.h"
7 // Static Singleton instance.
8 Options *Options::instance_ = 0;
10 Options *
11 Options::instance ()
13 if (Options::instance_ == 0)
14 Options::instance_ = new Options ();
16 return Options::instance_;
19 const char *
20 Options::program_name ()
22 return this->program_name_;
25 const char *
26 Options::slave_name ()
28 return this->slave_name_;
31 int
32 Options::debug ()
34 return this->debug_;
37 int
38 Options::exec_slave ()
40 return this->exec_slave_;
43 size_t
44 Options::iteration_count ()
46 return this->iteration_count_;
49 int
50 Options::use_sbrk ()
52 return this->use_sbrk_;
55 size_t
56 Options::max_msg_size ()
58 return this->max_msg_size_;
61 size_t
62 Options::spawn_count ()
64 return this->spawn_count_;
67 int
68 Options::spawn_threads ()
70 return this->spawn_threads_;
73 int
74 Options::use_mmap ()
76 return this->use_mmap_;
79 int
80 Options::use_shmem ()
82 return this->use_shmem_;
85 int
86 Options::child ()
88 return this->child_;
91 // Explain usage and exit.
93 void
94 Options::print_usage_and_die ()
96 //FUZZ: disable check_for_lack_ACE_OS
97 ACE_ERROR ((LM_ERROR,
98 ACE_TEXT ("usage: %n")
99 ACE_TEXT ("\n[-d] (run in debugging mode)\n")
100 ACE_TEXT ("[-e] (use exec(2) in addition to fork(2))\n")
101 ACE_TEXT ("[-l] (use C++ new operator rather than sbrk(2)\n")
102 ACE_TEXT ("[-L max_msg_size]\n")
103 ACE_TEXT ("[-m] (use mmap rather than SysV shared memory)\n")
104 ACE_TEXT ("[-p] (use processes rather than threads)\n")
105 ACE_TEXT ("[-s] (use SysV shared memory rather than mmap)\n")
106 ACE_TEXT ("[-t number of threads or processes to spawn]\n")
107 ACE_TEXT ("[-T] (enable tracking)\n")
108 ACE_TEXT ("[-n iteration_count]\n")));
109 //FUZZ: enable check_for_lack_ACE_OS
111 ACE_OS::exit (1);
112 /* NOTREACHED */
115 Options::Options ()
116 : debug_ (0),
117 exec_slave_ (0),
118 iteration_count_ (100),
119 use_sbrk_ (0),
120 use_shmem_ (0),
121 max_msg_size_ (127),
122 spawn_count_ (1),
123 spawn_threads_ (1),
124 use_mmap_ (0),
125 child_ (0)
127 ACE_OS::strcpy (this->slave_name_, "slave");
130 void
131 Options::parse_args (int argc, ACE_TCHAR *argv[])
133 ACE_Get_Opt get_opt (argc, argv, ACE_TEXT ("dehlL:mn:pst:T"));
135 ACE_OS::strcpy (this->program_name_, ACE_TEXT_ALWAYS_CHAR (argv[0]));
136 ACE_LOG_MSG->open (argv[0]);
138 // Put in a special-case check for child process.
139 if (ACE_OS::strcmp (this->program_name_, slave_name_) == 0)
141 this->child_ = 1;
142 this->use_mmap_ = 1;
145 for (int c;
146 (c = get_opt ()) != -1;
149 switch (c)
151 case 'd':
152 this->debug_ = 1;
153 break;
154 case 'e':
155 this->exec_slave_ = 1;
156 break;
157 case 'h':
158 this->print_usage_and_die ();
159 /* NOTREACHED */
160 break;
161 case 'l':
162 this->use_sbrk_ = 0;
163 break;
164 case 'L':
165 this->max_msg_size_ = ACE_OS::atoi (get_opt.opt_arg ());
166 break;
167 case 'm':
168 this->use_mmap_ = 1;
169 break;
170 case 'n':
171 this->iteration_count_ = ACE_OS::atoi (get_opt.opt_arg ());
172 break;
173 case 'p': // Spawn processes rather than threads
174 this->spawn_threads_ = 0;
175 break;
176 case 's':
177 // Use System V shared memory...
178 this->use_shmem_ = 1;
179 break;
180 case 't':
181 this->spawn_count_ = ACE_OS::atoi (get_opt.opt_arg ());
182 break;
183 case 'T':
184 #if defined (ACE_HAS_TRACE)
185 ACE_Trace::start_tracing ();
186 #endif /* ACE_HAS_TRACE */
187 break;
188 default:
189 this->print_usage_and_die ();
190 /* NOTREACHED */
191 break;
195 // Switch to using MMAP when the -p and -e options are enabled.
196 if (this->exec_slave_ == 1 && this->spawn_threads_ == 0)
197 this->use_mmap_ = 1;