summaryrefslogtreecommitdiff
path: root/TAO/orbsvcs/Notify_Service/Notify_Service.cpp
blob: b3f2afec4ac748d69ca244d1cc625e148d6e9b2e (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
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
#include "orbsvcs/Log_Macros.h"
#include "Notify_Service.h"

#include "orbsvcs/Daemon_Utilities.h"

#include "orbsvcs/Notify/Service.h"
#include "orbsvcs/Notify/EventChannelFactory.h"

#include "tao/debug.h"
#include "tao/IORTable/IORTable.h"
#include "tao/ORB_Core.h"

#if defined (TAO_HAS_NOTIFICATION_MONITOR_CONTROL) && defined (TAO_AS_STATIC_LIBS)
// for static builds, be sure the library is included
#include "orbsvcs/orbsvcs/Notify/MonitorControlExt/MC_Notify_Service.h"
#include "orbsvcs/orbsvcs/Notify/MonitorControl/MonitorManager.h"
#endif

#if defined (TAO_EXPLICIT_NEGOTIATE_CODESETS)
#include "tao/Codeset/Codeset.h"
#endif /* TAO_EXPLICIT_NEGOTIATE_CODESETS */

#if defined (TAO_HAS_CORBA_MESSAGING) && TAO_HAS_CORBA_MESSAGING != 0
#include "tao/Messaging/Messaging.h"
#endif /* TAO_HAS_CORBA_MESSAGING != 0 */

#include "ace/Arg_Shifter.h"
#include "ace/Get_Opt.h"
#include "ace/Sched_Params.h"
#include "ace/Synch.h"
#include "ace/Argv_Type_Converter.h"
#include "ace/Logging_Strategy.h"

TAO_Notify_Service_Driver::TAO_Notify_Service_Driver (void)
: notify_service_ (0)
, bootstrap_ (false)
, use_name_svc_ (true)
, ior_output_file_name_ (0)
, notify_factory_name_ (NOTIFY_KEY)
, register_event_channel_ (false)
, nthreads_ (1)
, separate_dispatching_orb_ (false)
, timeout_ (0)
, logging_worker_(this)
, shutdown_orb_ (true)
, shutdown_dispatching_orb_ (true)
{
}

TAO_Notify_Service_Driver::~TAO_Notify_Service_Driver (void)
{
}

int
TAO_Notify_Service_Driver::init_ORB (int& argc, ACE_TCHAR *argv [])
{
  this->orb_ = CORBA::ORB_init (argc, argv);

  ACE_LOG_MSG->open
    (argv[0], ACE_Log_Msg::SYSLOG, ACE_TEXT ("TAO Notify"));

  this->apply_timeout (this->orb_.in ());

  CORBA::Object_var object =
    this->orb_->resolve_initial_references("RootPOA");

  if (CORBA::is_nil (object.in ()))
    ORBSVCS_ERROR_RETURN ((LM_ERROR,
                       " (%P|%t) Unable to resolve the RootPOA.\n"),
                      -1);

  this->poa_ =
    PortableServer::POA::_narrow (object.in ());

  PortableServer::POAManager_var poa_manager =
    this->poa_->the_POAManager ();

  poa_manager->activate ();

  return 0;
}

int
TAO_Notify_Service_Driver::init_dispatching_ORB (int& argc, ACE_TCHAR *argv [])
{
  this->dispatching_orb_ = CORBA::ORB_init (argc, argv, "dispatcher");

  this->apply_timeout (this->dispatching_orb_.in ());

  return 0;
}

void
TAO_Notify_Service_Driver::apply_timeout (CORBA::ORB_ptr orb)
{
#if defined (TAO_HAS_CORBA_MESSAGING) && TAO_HAS_CORBA_MESSAGING != 0
  if (this->timeout_ != 0)
    {
      // convert from msec to "TimeT"
      CORBA::Any timeout;
      TimeBase::TimeT value = 10000 * this->timeout_;
      timeout <<= value;

      CORBA::Object_var object =
        orb->resolve_initial_references ("ORBPolicyManager");
      CORBA::PolicyManager_var policy_manager =
        CORBA::PolicyManager::_narrow (object.in ());
      if (CORBA::is_nil (policy_manager.in ()))
        throw CORBA::INTERNAL ();

      CORBA::PolicyList policy_list (1);
      policy_list.length (1);
      policy_list[0] = orb->create_policy (
                              Messaging::RELATIVE_RT_TIMEOUT_POLICY_TYPE,
                              timeout);
      policy_manager->set_policy_overrides (policy_list, CORBA::SET_OVERRIDE);
      policy_list[0]->destroy ();
  }
#else
  ACE_UNUSED_ARG (orb);
#endif /* TAO_HAS_CORBA_MESSAGING != 0 */
}

int
TAO_Notify_Service_Driver::init (int argc, ACE_TCHAR *argv[])
{
  // Check if -ORBDaemon is specified and if so, daemonize at this moment,
  // -ORBDaemon in the ORB core is faulty, see bugzilla 3335
  TAO_Daemon_Utility::check_for_daemon (argc, argv);

  if (this->parse_args(argc, argv) != 0)
    return -1;

  // initalize the ORB.
  if (this->init_ORB (argc, argv) != 0)
    return -1;

  this->notify_service_ = TAO_Notify_Service::load_default ();

  if (this->notify_service_ == 0)
    {
      if (TAO_debug_level > 0)
        {
          ORBSVCS_ERROR ((LM_ERROR,
                      ACE_TEXT ("Service not found. Check service ")
                      ACE_TEXT ("configurator file.\n")));
        }
      return -1;
    }

  if (this->separate_dispatching_orb_)
    {
      if (this->init_dispatching_ORB (argc, argv) != 0)
        {
          return -1;
        }

      this->notify_service_->init_service2 (this->orb_.in (), this->dispatching_orb_.in());
    }
  else
    {
      this->notify_service_->init_service (this->orb_.in ());
    }

  this->logging_worker_.start();

  if (this->nthreads_ > 0) // we have chosen to run in a thread pool.
    {
      if (TAO_debug_level > 0)
        {
          ORBSVCS_DEBUG ((LM_DEBUG,
                      ACE_TEXT("Running %d ORB threads\n"),
                      this->nthreads_));
        }
      worker_.orb (this->orb_.in ());

      // Task activation flags.
      long const flags =
        THR_NEW_LWP |
        THR_JOINABLE |
        this->orb_->orb_core ()->orb_params ()->thread_creation_flags ();

      int const priority =
        ACE_Sched_Params::priority_min (ACE_Utils::truncate_cast<ACE_Sched_Params::Policy> (this->orb_->orb_core ()->orb_params ()->sched_policy ()),
                                        ACE_Utils::truncate_cast<int> (this->orb_->orb_core ()->orb_params ()->scope_policy ()));

      if (worker_.activate (flags,
                            this->nthreads_, 0, priority) != 0)
        {
          ORBSVCS_ERROR_RETURN ((LM_ERROR,
                             "Cannot activate client threads\n"), -1);
        }
    }

  // Check first if the naming service
  if (this->use_name_svc_)
    {
      // Resolve the naming service.
      int const ns_ret = this->resolve_naming_service ();

      if (ns_ret != 0)
        return -1;
    }

  if (TAO_debug_level > 0)
    {
      ORBSVCS_DEBUG ((LM_DEBUG,
                  ACE_TEXT("\nStarting up the Notification Service...\n")));
    }

  // Activate the factory
  this->notify_factory_ =
    notify_service_->create (this->poa_.in (),
                             this->notify_factory_name_.c_str ());

  ACE_ASSERT (!CORBA::is_nil (this->notify_factory_.in ()));

  if (this->bootstrap_) // Enable corbaloc usage
    {
      CORBA::Object_var table_object =
        this->orb_->resolve_initial_references ("IORTable");

      IORTable::Table_var adapter =
        IORTable::Table::_narrow (table_object.in ());

      if (CORBA::is_nil (adapter.in ()))
        {
          if (TAO_debug_level > 0)
            {
              ORBSVCS_ERROR ((LM_ERROR,
                          "Nil IORTable. corbaloc support not enabled.\n"));
            }
        }
      else
        {
          CORBA::String_var ior =
            this->orb_->object_to_string (this->notify_factory_.in ());
          adapter->bind (this->notify_factory_name_.c_str (), ior.in ());
        }
    }

  // Register with the Name service, if asked
  if (this->use_name_svc_ && !CORBA::is_nil (this->naming_.in ()))
    {
      CosNaming::Name_var name =
        this->naming_->to_name (this->notify_factory_name_.c_str ());

      this->naming_->rebind (name.in (),
                             this->notify_factory_.in ());

      if (TAO_debug_level > 0)
        {
          ORBSVCS_DEBUG ((LM_DEBUG,
                      "Registered with the naming service as: %C\n",
                      this->notify_factory_name_.c_str()));
        }

      if (this->register_event_channel_)
        {
          // If we don't have any name configured, default to the standard name
          if (this->notify_channel_name_.is_empty ())
            {
              notify_channel_name_.insert (NOTIFY_CHANNEL_NAME);
            }

          for (ACE_Unbounded_Set<ACE_CString>::const_iterator ci (
                this->notify_channel_name_); !ci.done(); ci++)
            {
              // create an event channel
              CosNotifyChannelAdmin::ChannelID id;

              CosNotification::QoSProperties initial_qos;
              CosNotification::AdminProperties initial_admin;

              CosNotifyChannelAdmin::EventChannel_var ec;
              TAO_Notify_EventChannelFactory* factory_impl =
                dynamic_cast<TAO_Notify_EventChannelFactory*> (
                  this->notify_factory_->_servant ());
              if (factory_impl == 0)
                {
                  ec = this->notify_factory_->create_channel (initial_qos,
                                                              initial_admin,
                                                              id);
                }
              else
                {
                  ec = factory_impl->create_named_channel (
                                       initial_qos, initial_admin,id,
                                       (*ci).c_str ());
                }

              name = this->naming_->to_name ((*ci).c_str ());

              this->naming_->rebind (name.in (), ec.in ());

              if (TAO_debug_level > 0)
                {
                  ORBSVCS_DEBUG ((LM_DEBUG,
                              "Registered an Event Channel with the naming "
                              "service as: %C\n",
                              (*ci).c_str()));
                }
            }
        }
    }

  // Write IOR to a file, if asked.
  // Note: do this last to ensure that we're up and running before the file is written
  CORBA::String_var str =
    this->orb_->object_to_string (this->notify_factory_.in ());

  if (this->ior_output_file_name_)
    {
       FILE* ior_output_file = ACE_OS::fopen (ior_output_file_name_,
                                              ACE_TEXT("w"));
       if (ior_output_file == 0)
        {
          ORBSVCS_ERROR_RETURN ((LM_ERROR,
                             "Unable to open %s for writing: %p\n",
                             this->ior_output_file_name_, "Notify_Service"),
                             -1);
        }

      ACE_OS::fprintf (ior_output_file, "%s", str.in ());
      ACE_OS::fclose (ior_output_file);
    }
  else if (TAO_debug_level > 0)
    {
      ORBSVCS_DEBUG ((LM_DEBUG,
                  ACE_TEXT ("The Notification Event Channel Factory IOR is <%C>\n"),
                  str.in ()));
    }

  return 0;
}

int
TAO_Notify_Service_Driver::resolve_naming_service (void)
{
  try
    {
      CORBA::Object_var naming_obj =
        this->orb_->resolve_initial_references ("NameService");

      // Need to check return value for errors.
      if (CORBA::is_nil (naming_obj.in ()))
        ORBSVCS_ERROR_RETURN ((LM_ERROR,
                           " (%P|%t) Unable to resolve the Naming Service.\n"),
                          -1);

      this->naming_ = CosNaming::NamingContextExt::_narrow (naming_obj.in ());
    }
  catch (const CORBA::Exception &)
    {
        ORBSVCS_ERROR_RETURN ((LM_ERROR,
                           " (%P|%t) Unable to resolve the Naming Service.\n"),
                          -1);
    }
  catch (...)
    {
        ORBSVCS_ERROR_RETURN ((LM_ERROR,
                           " (%P|%t) Unable to resolve the Naming Service.\n"),
                          -1);
    }
  return 0;
}

int
TAO_Notify_Service_Driver::run (void)
{
  if (TAO_debug_level > 0 )
    ORBSVCS_DEBUG ((LM_DEBUG,
                ACE_TEXT ("%C: Running the Notification Service\n"),
                __FILE__));

  if (this->nthreads_ > 0)
    {
      this->worker_.wait ();
      return 0;
    }
  else
    {
      this->orb_->run ();
    }

  this->logging_worker_.end();
  return 0;
}

int
TAO_Notify_Service_Driver::fini (void)
{
  /// Release all the _vars as the ORB about to go away.
  CosNotifyChannelAdmin::EventChannelFactory_var factory =
    this->notify_factory_._retn ();
  CORBA::ORB_var orb = this->orb_._retn ();
  CORBA::ORB_var dispatching_orb = this->dispatching_orb_._retn ();
  PortableServer::POA_var poa = this->poa_._retn ();
  CosNaming::NamingContextExt_var naming = this->naming_._retn ();

  // This must be called to ensure that all services shut down
  // correctly.  Depending upon the type of service loaded, it may
  // or may not actually perform any actions.
  this->notify_service_->finalize_service (factory.in ());
  factory = CosNotifyChannelAdmin::EventChannelFactory::_nil ();

  this->notify_service_->fini ();

  // Deactivate.
  if (this->use_name_svc_ && !CORBA::is_nil (naming.in ()))
    {
      // Unbind all event channels from the naming service
      if (this->register_event_channel_)
        {
          for (ACE_Unbounded_Set<ACE_CString>::const_iterator ci (
               this->notify_channel_name_); !ci.done(); ci++)
            {
              CosNaming::Name_var name = naming->to_name ((*ci).c_str ());
              naming->unbind (name.in ());
            }
        }

      // Unbind from the naming service.
      CosNaming::Name_var name =
        naming->to_name (this->notify_factory_name_.c_str ());

      naming->unbind (name.in ());

      naming = CosNaming::NamingContextExt::_nil ();
    }

  if (!CORBA::is_nil (poa.in ()))
    {
      poa->destroy (true, true);
      poa = PortableServer::POA::_nil ();
    }

  if (this->shutdown_dispatching_orb_ && !CORBA::is_nil (dispatching_orb_.in ()))
    {
      dispatching_orb->shutdown ();
    }

  // shutdown the ORB.
  if (this->shutdown_orb_ && !CORBA::is_nil (orb.in ()))
    {
      orb->shutdown ();
    }

  // Make sure all worker threads are gone.
  this->worker_.wait ();
  this->logging_worker_.wait ();

  // Destroy the ORB
  if (this->shutdown_dispatching_orb_ && !CORBA::is_nil (dispatching_orb_.in ()))
    {
      dispatching_orb->destroy ();
    }

  // Destroy the ORB.
  if (this->shutdown_orb_ && !CORBA::is_nil (orb.in ()))
    {
      orb->destroy ();
    }

  dispatching_orb_ = CORBA::ORB::_nil ();

  worker_.orb (CORBA::ORB::_nil ());

  orb = CORBA::ORB::_nil ();

  return 0;
}

int
TAO_Notify_Service_Driver::parse_args (int argc, ACE_TCHAR *argv[])
{
  ACE_Arg_Shifter arg_shifter (argc, argv);

  const ACE_TCHAR* current_arg = 0;
  while (arg_shifter.is_anything_left ())
    {
      if (0 != (current_arg = arg_shifter.get_the_parameter (ACE_TEXT("-Factory"))))
        {
          this->notify_factory_name_.set (ACE_TEXT_ALWAYS_CHAR(current_arg));
          arg_shifter.consume_arg ();
        }
      else if (arg_shifter.cur_arg_strncasecmp (ACE_TEXT("-ShutdownORB")) == 0)
        {
          current_arg = arg_shifter.get_the_parameter
                              (ACE_TEXT("-ShutdownORB"));
          if (current_arg != 0 &&
              (ACE_OS::strcmp(ACE_TEXT ("0"), current_arg) == 0 ||
               ACE_OS::strcmp(ACE_TEXT ("1"), current_arg) == 0))
            {
              this->shutdown_orb_ =
                            static_cast<bool> (ACE_OS::atoi(current_arg));
            }
          if (current_arg != 0)
            arg_shifter.consume_arg ();
        }
      else if (arg_shifter.cur_arg_strncasecmp (ACE_TEXT("-ShutdownDispatchingORB")) == 0)
        {
          current_arg = arg_shifter.get_the_parameter
                              (ACE_TEXT("-ShutdownDispatchingORB"));
          if (current_arg != 0 &&
              (ACE_OS::strcmp(ACE_TEXT ("0"), current_arg) == 0 ||
               ACE_OS::strcmp(ACE_TEXT ("1"), current_arg) == 0))
            {
              this->shutdown_dispatching_orb_ =
                            static_cast<bool> (ACE_OS::atoi(current_arg));
            }
          if (current_arg != 0)
            arg_shifter.consume_arg ();
        }
      else if (arg_shifter.cur_arg_strncasecmp (ACE_TEXT("-UseSeparateDispatchingORB")) == 0)
        {
          current_arg = arg_shifter.get_the_parameter
                              (ACE_TEXT("-UseSeparateDispatchingORB"));
          if (current_arg != 0 &&
              (ACE_OS::strcmp(ACE_TEXT ("0"), current_arg) == 0 ||
               ACE_OS::strcmp(ACE_TEXT ("1"), current_arg) == 0))
            {
              if (TAO_debug_level > 0)
                {
                  ORBSVCS_DEBUG ((LM_DEBUG,
                              ACE_TEXT ("Using separate dispatching ORB\n")));
                }
              this->separate_dispatching_orb_ =
                            static_cast<bool> (ACE_OS::atoi(current_arg));
            }
          else
            {
              if (TAO_debug_level > 0)
                {
                  ORBSVCS_DEBUG ((LM_DEBUG,
                              ACE_TEXT ("WARNING: Unrecognized ")
                              ACE_TEXT ("argument (%s) to ")
                              ACE_TEXT ("-UseSeparateDispatchingORB.\n"),
                              (current_arg == 0 ? ACE_TEXT ("''") : current_arg)));
                }
            }
          if (current_arg != 0)
            arg_shifter.consume_arg ();
        }
      else if (arg_shifter.cur_arg_strncasecmp (ACE_TEXT("-Boot")) == 0)
        {
          this->bootstrap_ = true;
          // Make it bootstrappable

          arg_shifter.consume_arg ();
        }
      else if (arg_shifter.cur_arg_strncasecmp (ACE_TEXT("-NameSvc")) == 0)
        {
          this->use_name_svc_ = true;
          // Register ref with the name service

          arg_shifter.consume_arg ();
        }
      else if (arg_shifter.cur_arg_strncasecmp (ACE_TEXT("-NoNameSvc")) == 0)
        {
          this->use_name_svc_ = false;
          // Don't Register ref with the name service

          arg_shifter.consume_arg ();
        }
      else if (0 != (current_arg = arg_shifter.get_the_parameter (ACE_TEXT("-IORoutput"))))
        {
          this->ior_output_file_name_ = current_arg;
          arg_shifter.consume_arg ();
        }
      else if (0 != (current_arg = arg_shifter.get_the_parameter (ACE_TEXT("-ChannelName"))))
        {
          this->notify_channel_name_.insert(ACE_CString(ACE_TEXT_ALWAYS_CHAR(current_arg)));
          arg_shifter.consume_arg ();
        }
      else if (arg_shifter.cur_arg_strncasecmp (ACE_TEXT("-Channel")) == 0)
        {
          this->register_event_channel_ = true;
          // Register one EC with naming.

          arg_shifter.consume_arg ();
        }
      else if (0 != (current_arg = arg_shifter.get_the_parameter (ACE_TEXT("-Notify_TPReactor"))))
        {
          if (TAO_debug_level > 0)
            {
              ORBSVCS_DEBUG((LM_DEBUG,
                         ACE_TEXT ("-Notify_TPReactor option is deprecated, ")
                         ACE_TEXT ("use -RunThreads option\n")));
            }

          this->nthreads_ = ACE_OS::atoi (current_arg);
          arg_shifter.consume_arg ();
        }
      else if (0 != (current_arg = arg_shifter.get_the_parameter (ACE_TEXT("-RunThreads"))))
        {
          this->nthreads_ = ACE_OS::atoi (current_arg);
          arg_shifter.consume_arg ();
        }
      else if (0 != (current_arg = arg_shifter.get_the_parameter (ACE_TEXT("-Timeout"))))
        {
#if defined (TAO_HAS_CORBA_MESSAGING) && TAO_HAS_CORBA_MESSAGING != 0
          this->timeout_ = ACE_OS::atoi (current_arg);
          arg_shifter.consume_arg ();
#else
          if (TAO_debug_level > 0)
            {
              ORBSVCS_DEBUG((LM_DEBUG,
                         ACE_TEXT ("WARNING: CORBA Messaging has been disabled.")
                         ACE_TExT ("The timeout will not be applied.\n")));
            }
#endif /* TAO_HAS_CORBA_MESSAGING != 0 */
        }
      else if ((current_arg = arg_shifter.get_the_parameter (ACE_TEXT("-LoggingInterval"))))
        {
          this->logging_interval_ = ACE_Time_Value (ACE_OS::atoi (current_arg));
          arg_shifter.consume_arg ();
        }
      else if (arg_shifter.cur_arg_strncasecmp (ACE_TEXT("-?")) == 0)
        {
          ORBSVCS_DEBUG((LM_DEBUG,
                     ACE_TEXT ("usage: %s -Factory factory_name ")
                     ACE_TEXT ("-Boot -[No]NameSvc ")
                     ACE_TEXT ("-IORoutput file_name ")
                     ACE_TEXT ("-Channel -ChannelName channel_name ")
                     ACE_TEXT ("-RunThreads threads ")
                     ACE_TEXT ("-Timeout <msec>\n")
                     ACE_TEXT ("-ShutdownORB 1|0")
                     ACE_TEXT ("-ShutdownDispatchingORB 1|0")
                     ACE_TEXT ("default: %s -Factory NotifyEventChannelFactory ")
                     ACE_TEXT ("-NameSvc -Channel NotifyEventChannel -ORBRunThreads 1\n"),
                     argv[0], argv[0]));

          arg_shifter.consume_arg ();

          return -1;
        }
      else
        {
          arg_shifter.ignore_arg ();
        }
    }
  return 0;
}

/*****************************************************************/
LoggingWorker::LoggingWorker(TAO_Notify_Service_Driver* ns)
: ns_ (ns),
  started_ (false),
  timer_id_ (-1)
{
}

void
LoggingWorker::start ()
{
  ACE_Logging_Strategy* logging_strategy =
    ACE_Dynamic_Service<ACE_Logging_Strategy>::instance ("Logging_Strategy");
  if (logging_strategy == 0)
    {
      ORBSVCS_ERROR ((LM_ERROR, ACE_TEXT ("(%P|%t) logging_strategy == 0\n")));
    }
  else
    {
      if (this->activate (THR_NEW_LWP | THR_JOINABLE, 1) == -1)
        {
          if (TAO_debug_level > 0)
            {
              ORBSVCS_ERROR ((LM_ERROR,
                         ACE_TEXT ("(%P|%t) Can not activate the ")
                         ACE_TEXT ("logging event thread\n")));
            }
        }
      else {
        if (this->ns_->logging_interval_ > ACE_Time_Value::zero)
        {
          timer_id_ = this->ns_->orb_->orb_core()->reactor()->
              schedule_timer (logging_strategy, 0, this->ns_->logging_interval_,
                              this->ns_->logging_interval_);
          if (timer_id_ == -1)
            {
              ORBSVCS_ERROR ((LM_ERROR,
                          ACE_TEXT("(%P|%t) Failed to schedule ")
                          ACE_TEXT("logging switch timer\n")));
            }
        }
      }
    }
}

int
LoggingWorker::svc (void)
{
  if (TAO_debug_level > 0)
    {
      ORBSVCS_DEBUG ((LM_DEBUG,
                  ACE_TEXT ("(%P|%t) Running logging reactor \n")));
    }
  started_ = true;
  this->logging_reactor_.run_event_loop();

  return 0;
}

void
LoggingWorker::end ()
{
  if (started_)
  {
    this->logging_reactor_.end_event_loop();
    this->wait ();
  }

  if (timer_id_ != -1)
    {
      this->ns_->orb_->orb_core()->reactor()->
        cancel_timer (timer_id_);
      timer_id_ = -1;
    }
}

Worker::Worker (void)
{
}

void
Worker::orb (CORBA::ORB_ptr orb)
{
  orb_ = CORBA::ORB::_duplicate (orb);
}

int
Worker::svc (void)
{
#if 0
  // ACE_Thread::getprio() fails on systems that do not support thread
  // priorities.  While we could just treat the failure as benign, I'm
  // just disabling it altogether.  It doesn't provide much value, and
  // makes service startup needlessly more verbose.  See bugzilla 2477
  // for details.

  ACE_hthread_t current;
  ACE_Thread::self (current);

  int priority;
  if (ACE_Thread::getprio (current, priority) == -1)
    {
      if (TAO_debug_level > 0)
        {
          ORBSVCS_ERROR ((LM_ERROR,
                      ACE_TEXT ("TAO (%P|%t) - Failed to get ")
                      ACE_TEXT ("Worker thread priority\n")));
        }
      return -1;
    }

  if (TAO_debug_level > 0)
    {
      ORBSVCS_DEBUG ((LM_DEBUG,
                  ACE_TEXT ("Activated Worker Thread to run ")
                  ACE_TEXT ("the ORB @ priority:%d\n", priority));
    }
#endif

  try
    {
      if (!CORBA::is_nil (this->orb_.in ()))
        {
          this->orb_->run ();
        }
    }
  catch (const CORBA::Exception&)
    {
    }
  return 0;
}

ACE_STATIC_SVC_DEFINE (TAO_Notify_Service_Driver,
                       ACE_TEXT ("TAO_Notify_Service_Driver"),
                       ACE_SVC_OBJ_T,
                       &ACE_SVC_NAME (TAO_Notify_Service_Driver),
                       ACE_Service_Type::DELETE_THIS | ACE_Service_Type::DELETE_OBJ,
                       0)


ACE_FACTORY_DEFINE (TAO_Notify_Service, TAO_Notify_Service_Driver)


#if defined (TAO_HAS_NOTIFICATION_MONITOR_CONTROL) && defined (TAO_AS_STATIC_LIBS)
ACE_STATIC_SVC_REQUIRE(TAO_MC_Notify_Service)
ACE_STATIC_SVC_REQUIRE(TAO_MonitorAndControl)
#endif


#if defined (TAO_AS_STATIC_LIBS)
ACE_STATIC_SVC_REQUIRE(ACE_Logging_Strategy)
#endif