summaryrefslogtreecommitdiff
path: root/TAO/orbsvcs/tests/Notify/lib/Periodic_Consumer_Command.cpp
blob: 12871ea3eb02b7e385d79c51946cb2a7c73910f8 (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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
// $Id$

#include "Periodic_Consumer_Command.h"

ACE_RCSID (lib,
           TAO_Periodic_Consumer_Command,
           "$Id$")

#include "LookupManager.h"
#include "Name.h"
#include "Periodic_Consumer.h"
#include "Relay_Consumer.h"
#include "Direct_Consumer.h"
#include "Activation_Manager.h"
#include "Options_Parser.h"
#include "orbsvcs/NotifyExtC.h"

TAO_Notify_Tests_Periodic_Consumer_Command::TAO_Notify_Tests_Periodic_Consumer_Command (void)
{
}

TAO_Notify_Tests_Periodic_Consumer_Command::~TAO_Notify_Tests_Periodic_Consumer_Command ()
{
}

const ACE_TCHAR*
TAO_Notify_Tests_Periodic_Consumer_Command::get_name (void)
{
  return TAO_Notify_Tests_Periodic_Consumer_Command::name ();
}

const ACE_TCHAR*
TAO_Notify_Tests_Periodic_Consumer_Command::name (void)
{
  return TAO_Notify_Tests_Name::periodic_consumer_command;
}

void
TAO_Notify_Tests_Periodic_Consumer_Command::init (ACE_TArg_Shifter< char >& arg_shifter)
{
  if (arg_shifter.is_anything_left ())
    {
      /// -Create consumer_name admin_name -POA [POA_name] consumer_specific_options
      if (arg_shifter.cur_arg_strncasecmp ("-Create") == 0)
        {
          this->command_ = CREATE;

          arg_shifter.consume_arg ();

          this->name_ = arg_shifter.get_current ();
          arg_shifter.consume_arg ();

          int is_relay = 0;
          int is_direct = 0;
          ACE_CString relay_destination;

          if (arg_shifter.cur_arg_strncasecmp ("-Relay") == 0)
            {
              is_relay = 1;

              arg_shifter.consume_arg ();

              relay_destination = arg_shifter.get_current ();
              arg_shifter.consume_arg ();
            }
          else if (arg_shifter.cur_arg_strncasecmp ("-Direct") == 0)
            {
              is_direct = 1;

              arg_shifter.consume_arg ();
            }

          TAO_Notify_Tests_Periodic_Consumer* consumer = 0;

          // create the consumer
          if (is_relay == 1)
            consumer = new TAO_Notify_Tests_Relay_Consumer (relay_destination);
          else if (is_direct == 1)
            consumer = new TAO_Notify_Tests_Direct_Consumer ();
          else
            consumer = new TAO_Notify_Tests_Periodic_Consumer ();

          consumer->set_name (this->name_);

         TAO_Notify_Tests_Activation_Manager* act_mgr = 0;
         LOOKUP_MANAGER->resolve (act_mgr);

         {
           ACE_DECLARE_NEW_CORBA_ENV;
           act_mgr->_register (consumer, this->name_.c_str () ACE_ENV_ARG_PARAMETER);
           ACE_CHECK;
         }

         consumer->init_state (arg_shifter);

        } /* -Create */
      else if (arg_shifter.cur_arg_strncasecmp ("-Subscription") == 0) // -Subscription admin_name +added_type1 +-added_type2 ... -added_type3 -added_type4..
        {
          this->command_ = SUBSCRIPTION;

          arg_shifter.consume_arg ();

          this->name_ = arg_shifter.get_current ();
          arg_shifter.consume_arg ();

          TAO_Notify_Tests_Options_Parser options_parser;
          options_parser.execute (this->added_, this->removed_, arg_shifter);
        } /* Subscription */
      else if (arg_shifter.cur_arg_strncasecmp ("-Disconnect") == 0) //
        {
          this->command_ = DISCONNECT;

          arg_shifter.consume_arg ();

          this->name_ = arg_shifter.get_current ();
          arg_shifter.consume_arg ();
        } /* disconnect */
      else if (arg_shifter.cur_arg_strncasecmp ("-Deactivate") == 0) //
        {
          this->command_ = DEACTIVATE;

          arg_shifter.consume_arg ();

          this->name_ = arg_shifter.get_current ();
          arg_shifter.consume_arg ();
        } /* deactivate */
      else if (arg_shifter.cur_arg_strncasecmp ("-Status") == 0) //
        {
          this->command_ = DUMP_STATE;

          arg_shifter.consume_arg ();

          this->name_ = arg_shifter.get_current ();
          arg_shifter.consume_arg ();
        } /* -Dump */
      else if (arg_shifter.cur_arg_strncasecmp ("-Set_QoS") == 0) // -Set_QoS ec_name [Qos Options]
        {
          this->command_ = SET_QOS;

          arg_shifter.consume_arg ();

          this->name_ = arg_shifter.get_current ();

          arg_shifter.consume_arg ();

          TAO_Notify_Tests_Options_Parser qos_parser;
          qos_parser.execute (this->qos_, arg_shifter);
        }
    }
}

TAO_Notify_Tests_Periodic_Consumer*
TAO_Notify_Tests_Periodic_Consumer_Command::consumer (void)
{
  TAO_Notify_Tests_Activation_Manager* act_mgr = 0;

  LOOKUP_MANAGER->resolve (act_mgr);

  // Locate the consumer
  TAO_Notify_Tests_Periodic_Consumer* consumer = 0;

  {
    ACE_DECLARE_NEW_CORBA_ENV;
    act_mgr->resolve (consumer, this->name_.c_str () ACE_ENV_ARG_PARAMETER);
    ACE_CHECK_RETURN (0);
  }

  if (consumer == 0)
    ACE_DEBUG ((LM_DEBUG, "Consumer %s not found by Lookup Manager\n", this->name_.c_str ()));

  return consumer;
}

void
TAO_Notify_Tests_Periodic_Consumer_Command::handle_set_qos (ACE_ENV_SINGLE_ARG_DECL)
{
  this->consumer ()->set_qos (this->qos_ ACE_ENV_ARG_PARAMETER);
  ACE_CHECK;
}

void
TAO_Notify_Tests_Periodic_Consumer_Command::handle_create (ACE_ENV_SINGLE_ARG_DECL)
{
  TAO_Notify_Tests_Periodic_Consumer* consumer = this->consumer ();

  if (consumer == 0)
    return;

  consumer->connect (ACE_ENV_SINGLE_ARG_PARAMETER);
  ACE_CHECK;

  ACE_DEBUG ((LM_DEBUG, "Consumer %s is connected\n", this->name_.c_str ()));
}

void
TAO_Notify_Tests_Periodic_Consumer_Command::handle_subscriptions (ACE_ENV_SINGLE_ARG_DECL)
{
  TAO_Notify_Tests_Periodic_Consumer* consumer= this->consumer ();
  if (consumer == 0)
    return;

  consumer->subscription_change (this->added_, this->removed_ ACE_ENV_ARG_PARAMETER);
  ACE_CHECK;
}

void
TAO_Notify_Tests_Periodic_Consumer_Command::handle_disconnect (ACE_ENV_SINGLE_ARG_DECL)
{
  TAO_Notify_Tests_Periodic_Consumer* consumer= this->consumer ();
  if (consumer == 0)
    return;

  consumer->disconnect (ACE_ENV_SINGLE_ARG_PARAMETER);
  ACE_CHECK;
}

void
TAO_Notify_Tests_Periodic_Consumer_Command::handle_deactivate (ACE_ENV_SINGLE_ARG_DECL)
{
  TAO_Notify_Tests_Periodic_Consumer* consumer = this->consumer ();
  if (consumer == 0)
    return;

  consumer->deactivate (ACE_ENV_SINGLE_ARG_PARAMETER);
  ACE_CHECK;
}

void
TAO_Notify_Tests_Periodic_Consumer_Command::handle_status (ACE_ENV_SINGLE_ARG_DECL)
{
  TAO_Notify_Tests_Periodic_Consumer* consumer = this->consumer ();

  if (consumer == 0)
    return;

  consumer->status (ACE_ENV_SINGLE_ARG_PARAMETER);
  ACE_CHECK;
}

void
TAO_Notify_Tests_Periodic_Consumer_Command::execute_i (ACE_ENV_SINGLE_ARG_DECL)
{
  if (this->command_ == CREATE)
    {
      this->handle_create (ACE_ENV_SINGLE_ARG_PARAMETER);
      ACE_CHECK;
    }
  else if (this->command_ == SUBSCRIPTION)
    {
      this->handle_subscriptions (ACE_ENV_SINGLE_ARG_PARAMETER);
      ACE_CHECK;
    }
  else if (this->command_ == DISCONNECT)
    {
      this->handle_disconnect (ACE_ENV_SINGLE_ARG_PARAMETER);
      ACE_CHECK;
    }
  else if (this->command_ == DEACTIVATE)
    {
      this->handle_deactivate (ACE_ENV_SINGLE_ARG_PARAMETER);
      ACE_CHECK;
    }
  else  if (this->command_ == DUMP_STATE)
    {
      this->handle_status (ACE_ENV_SINGLE_ARG_PARAMETER);
      ACE_CHECK;
    }
  else if (this->command_ == SET_QOS)
    {
      this->handle_set_qos (ACE_ENV_SINGLE_ARG_PARAMETER);
      ACE_CHECK;
    }
}