summaryrefslogtreecommitdiff
path: root/trunk/TAO/examples/AMH/Sink_Server/MT_AMH_Server.cpp
blob: 43ef2b385cc8123ed3c7f1f5e8b66eb5b03ca669 (plain)
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
//
// $Id$
//

#include "MT_AMH_Server.h"
#include "tao/Strategies/advanced_resource.h"

#include "ace/Task.h"
#include "ace/Get_Opt.h"

MT_AMH_Server::MT_AMH_Server (int& argc, char **argv)
  : Base_Server (argc, argv) 
{
}

MT_AMH_Server::~MT_AMH_Server (void) 
{
}

void
MT_AMH_Server::usage (const char *message)
{
  static const char * usage =
    "invoke as: mt_server -o <ior_output_file> \n"
    " -n <num_threads> \n"
    "-s <sleep_time (in microseconds)> \n";

  // @@ Mayur, why don't you just place the usage message directly in
  //    the below ACE_ERROR macro?  It's not a big deal.  It's just
  //    something we normally do.
  //
  // Mayur: Seems cleaner to me this way.
  ACE_ERROR ((LM_ERROR, "%s : %s", message, usage));
}


int 
MT_AMH_Server::parse_args (void)
{

  // Let the base server parse it's argumrents first
  if (Base_Server::parse_args () != 1)
    {
      this->usage ("");
      ACE_OS::exit (1);
    }

  ACE_Get_Opt get_opts (this->argc_, this->argv_, "n:");
  int c;
  int count_argv = 0;

  while ((c = get_opts ()) != -1)
    {
      ++count_argv;
      switch (c)
        {
        case 'n':
          {
            this->nthreads_ = ACE_OS::atoi (get_opts.opt_arg ());

            {
              // Added unneeded '{ & }' just to satisfy Win32
              for (int i = count_argv; i <= this->argc_; ++i)
                this->argv_ [i] = this->argv_ [i+2];
            }

            // Decrement the value of this->argc_ to reflect the removal
            // of '-n' option.
            this->argc_ = this->argc_ - 2;
            return 1;
          }

        case '?':
        default:
          // Don't do anything.
          break;
        }
    }
  return 0;
}

void 
MT_AMH_Server::start_threads (void)
{
  // Each of this thread runs the event loop
  this->activate (THR_NEW_LWP | THR_JOINABLE, this->nthreads_, 1);
  this->thr_mgr ()->wait ();
}

int 
MT_AMH_Server::svc (void)
{
  run_event_loop ();
  return 1;
}