Merge pull request #1551 from DOCGroup/plm_jira_333
[ACE_TAO.git] / TAO / examples / AMH / Sink_Server / MT_AMH_Server.cpp
blob33e6ccb54ab4a66ff3c82c72f245f473ca5e93b6
2 #include "MT_AMH_Server.h"
3 #include "tao/Strategies/advanced_resource.h"
5 #include "ace/Task.h"
6 #include "ace/Get_Opt.h"
8 MT_AMH_Server::MT_AMH_Server (int &argc, ACE_TCHAR **argv)
9 : Base_Server (argc, argv)
13 MT_AMH_Server::~MT_AMH_Server (void)
17 void
18 MT_AMH_Server::usage (const char *message)
20 static const char * usage =
21 "invoke as: mt_server -o <ior_output_file>\n"
22 " -n <num_threads>\n"
23 "-s <sleep_time (in microseconds)>\n";
25 // @@ Mayur, why don't you just place the usage message directly in
26 // the below ACE_ERROR macro? It's not a big deal. It's just
27 // something we normally do.
29 // Mayur: Seems cleaner to me this way.
30 ACE_ERROR ((LM_ERROR, "%C : %C", message, usage));
34 int
35 MT_AMH_Server::parse_args (void)
38 // Let the base server parse it's argumrents first
39 if (Base_Server::parse_args () != 1)
41 this->usage ("");
42 ACE_OS::exit (1);
45 ACE_Get_Opt get_opts (this->argc_, this->argv_, ACE_TEXT("n:"));
46 int c;
47 int count_argv = 0;
49 while ((c = get_opts ()) != -1)
51 ++count_argv;
52 switch (c)
54 case 'n':
56 this->nthreads_ = ACE_OS::atoi (get_opts.opt_arg ());
59 // Added unneeded '{ & }' just to satisfy Win32
60 for (int i = count_argv; i <= this->argc_; ++i)
61 this->argv_ [i] = this->argv_ [i+2];
64 // Decrement the value of this->argc_ to reflect the removal
65 // of '-n' option.
66 this->argc_ = this->argc_ - 2;
67 return 1;
70 case '?':
71 default:
72 // Don't do anything.
73 break;
76 return 0;
79 void
80 MT_AMH_Server::start_threads (void)
82 // Each of this thread runs the event loop
83 this->activate (THR_NEW_LWP | THR_JOINABLE, this->nthreads_, 1);
84 this->thr_mgr ()->wait ();
87 int
88 MT_AMH_Server::svc (void)
90 run_event_loop ();
91 return 1;