summaryrefslogtreecommitdiff
path: root/TAO/tao/TAO_Internal.cpp
blob: 8873a811a89800eb1da62108210886f36078a5be (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
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
// $Id$

#include "tao/TAO_Internal.h"
#include "tao/TAO_Singleton.h"
#include "tao/default_server.h"
#include "tao/default_client.h"
#include "tao/default_resource.h"
#include "tao/IIOP_Factory.h"
#include "tao/MCAST_Parser.h"
#include "tao/CORBANAME_Parser.h"
#include "tao/CORBALOC_Parser.h"
#include "tao/FILE_Parser.h"
#include "tao/HTTP_Parser.h"
#include "tao/DLL_Parser.h"
#include "tao/ORB_Core.h"
#include "tao/Adapter_Factory.h"
#include "tao/Default_Stub_Factory.h"
#include "tao/Default_Endpoint_Selector_Factory.h"
#include "tao/Default_Protocols_Hooks.h"
#include "tao/Default_Thread_Lane_Resources_Manager.h"
#include "tao/Default_Collocation_Resolver.h"
#include "tao/Codeset_Manager_Factory_Base.h"
#include "tao/Codeset_Manager.h"
#include "tao/debug.h"
#include "tao/StringSeqC.h"

#include "ace/Dynamic_Service.h"
#include "ace/Arg_Shifter.h"
#include "ace/Argv_Type_Converter.h"
#include "ace/Env_Value_T.h"
#include "ace/ACE.h"
#include "ace/OS_NS_stdio.h"
#include "ace/Static_Object_Lock.h"

ACE_RCSID (tao,
           TAO_Internal,
           "$Id$")

#ifndef TAO_DEFAULT_RESOURCE_FACTORY_ARGS
#  define TAO_DEFAULT_RESOURCE_FACTORY_ARGS 0
#endif  /* !TAO_DEFAULT_RESOURCE_FACTORY_ARGS */

#ifndef TAO_DEFAULT_SERVER_STRATEGY_FACTORY_ARGS
#  define TAO_DEFAULT_SERVER_STRATEGY_FACTORY_ARGS 0
#endif  /* !TAO_DEFAULT_SERVER_STRATEGY_FACTORY_ARGS */

#ifndef TAO_DEFAULT_CLIENT_STRATEGY_FACTORY_ARGS
#  define TAO_DEFAULT_CLIENT_STRATEGY_FACTORY_ARGS 0
#endif  /* !TAO_DEFAULT_RESOURCE_FACTORY_ARGS */


namespace
{
  /**
   * Parses the supplied command-line arguments to extract any that
   * apply to the process (globally)
   *
   * @brief Modifies the argc to reflect any arguments it has
   * "consumed"
   *
   * When multiple ORBs are being configured, the global options are
   * only processed for the first ORB loaded. However subsequent ORBs
   * may be supplied with some of these options, so they need to be
   * eliminated as though they were processed. For this reason,
   * this function is called for every ORB, but only the first call
   * sets apply_values to true
   *
   */
  int
  parse_global_args_i (int &argc,
                       char **argv,
                       CORBA::StringSeq &svc_config_argv,
                       bool apply_values);

  /**
   * Parses the supplied command-line arguments to extract any that
   * specify a Service Configurator file (-ORBSvcConf). This is done
   * separately, because depending on the context, the configuration
   * file may apply to the process-wide service repository, or to the
   * orb-specific (private) one.
   *
   * @brief Modifies the argc to reflect any arguments it has
   * "consumed"
   */
  int
  parse_svcconf_args_i (int &argc,
                       char **argv,
                       CORBA::StringSeq &svc_config_argv);

  /**
   * Initialize the ACE Service Configurator with the process-global
   * services (available to any ORB).
   *
   * @return @c 0 if successful, @c -1 with @c errno set if failure.
   *
   * @note You can provide your program a set of default `svc.conf'
   *       entries by setting @a ignore_default_svc_conf_file to
   *       non-zero and use @c default_svc_conf_entries() before
   *       calling @c open_global_services().  In addition, you can @a
   *       skip_service_config_open altogether, which used to be
   *       important when the ORB is linked in via the
   *       ACE_Service_Config, since the ACE_Service_Config was
   *       non-reentrant.  However, the ACE_Service_Config is now
   *       reentrant meaning that it is really no longer necessary to
   *       do so.
   */
  void register_global_services_i (ACE_Service_Gestalt * pcfg);
  void register_additional_services_i (ACE_Service_Gestalt * pcfg);

  /**
   * Parses the supplied command-line arguments to extract any
   * instance-specific ones.
   *
   * @brief Modifies the argc to reflect any arguments it has
   * "consumed"
   */
  int
  parse_private_args_i (int &argc,
                        char **argv,
                        CORBA::StringSeq & svc_config_argv,
                        bool & skip_service_config_open);

  /**
   * Initialize ORB-local (private) ACE Service Configurator
   * repository.
   *
   * @return @c 0 if successful, @c -1 with @c errno set if failure.
   *
   */
  int open_private_services_i (ACE_Service_Gestalt* pcfg,
                               int & argc,
                               char ** argv,
                               bool skip_service_config_open = false,
                               bool ignore_default_svc_conf_file = false);

  /**
   * Number of times open_services() has been called.  Incremented by
   * open_global_services_i(), and decremented by close_services().
   *
   * @note In/decrement operations are atomic.
   */
  long service_open_count = 0;

  /**
   * Part of a condition variable, which helps to ensure non-default
   * ORBs can not proceed with their initialization, until the globaly
   * required services have been instantiated by the default
   * ORB. Usually, the first ORB to be created is designated the
   * default ORB (reference the CORBA spec)
   */
  bool is_ubergestalt_ready = false;

  char const * resource_factory_args =
    TAO_DEFAULT_RESOURCE_FACTORY_ARGS;
  char const * server_strategy_factory_args =
    TAO_DEFAULT_SERVER_STRATEGY_FACTORY_ARGS;
  char const * client_strategy_factory_args =
    TAO_DEFAULT_CLIENT_STRATEGY_FACTORY_ARGS;

#if (TAO_NEGOTIATE_CODESETS == 1)
  bool negotiate_codesets = true;
#else
  bool negotiate_codesets = false;
#endif /* TAO_NEGOTIATE_CODESETS */
} // anonymous namespace

TAO_BEGIN_VERSIONED_NAMESPACE_DECL

#if defined (ACE_HAS_THREADS)
/// A little helper class to get around the TAO_Singleton::instance ()
/// inability to pass default initialization arguments to the
/// singleton ctor.

class TAO_Ubergestalt_Ready_Condition
  : public ACE_SYNCH_RECURSIVE_CONDITION
{
public:
  static TAO_Ubergestalt_Ready_Condition* instance (void)
  {
    // The first thread to get here will initialize the static
    // local. Any subsequent threads synchronizaton will be handled by
    // TAO_Singleton
    static TAO_Ubergestalt_Ready_Condition *i_ =
      TAO_Singleton <TAO_Ubergestalt_Ready_Condition,
                     TAO_SYNCH_RECURSIVE_MUTEX>::instance ();

    return i_;
  };

  TAO_Ubergestalt_Ready_Condition (void)
    : ACE_SYNCH_RECURSIVE_CONDITION
  (this->mutex_)
  {
    // empty
  };

private:
  /// The mutex, associated with the condition. Do not use the ACE
  /// global mutex, because it causes deadlocks with other thrads that
  /// may be in DLL_Manager::open()
  ACE_Recursive_Thread_Mutex mutex_;
};
#endif // ACE_HAS_THREADS

int
TAO::ORB::open_services (ACE_Service_Gestalt* pcfg,
                         int &argc,
                         ACE_TCHAR **argv)
{
  {
    ACE_MT (ACE_GUARD_RETURN (TAO_SYNCH_RECURSIVE_MUTEX,
                              guard,
                              TAO_Ubergestalt_Ready_Condition::instance ()->mutex (),
                              -1));

    // Wait in line, while the default ORB (which isn't us) completes
    // initialization of the globaly required service objects
    if (service_open_count == 1)
      {
        if (TAO_debug_level > 4)
          ACE_DEBUG ((LM_DEBUG,
                      ACE_TEXT ("TAO (%P|%t) Waiting for the default ")
                      ACE_TEXT ("ORB to complete the global ")
                      ACE_TEXT ("initialization\n")));

        ACE_MT (while (!is_ubergestalt_ready)
                TAO_Ubergestalt_Ready_Condition::instance ()->wait ());

        if (TAO_debug_level > 4)
          ACE_DEBUG ((LM_DEBUG,
                      ACE_TEXT ("TAO (%P|%t) The default ")
                      ACE_TEXT ("ORB must have completed the global ")
                      ACE_TEXT ("initialization...\n")));

      }
    else
      {
        if (TAO_debug_level > 4)
          ACE_DEBUG ((LM_DEBUG,
                      ACE_TEXT ("TAO (%P|%t) We are %sthe default ")
                      ACE_TEXT ("ORB ...\n"),
                      (service_open_count == 0) ? "" : "not "));
      }

    service_open_count++;
  }

  // Construct an argument vector specific to the Service
  // Configurator.
  CORBA::StringSeq svc_config_argv;

  // Be certain to copy the program name so that service configurator
  // has something to skip!
  ACE_CString argv0 ("");

  if (argc > 0 && argv != 0)
    {
      argv0 = ACE_TEXT_ALWAYS_CHAR (argv[0]);
    }

  svc_config_argv.length (1);
  svc_config_argv[0] = argv0.c_str ();

  // Should we skip the ACE_Service_Config::open() method, e.g., if we
  // already being configured by the ACE Service Configurator.
  //
  // @@ This is no longer needed since the Service Configurator is now
  // reentrant.(-Ossama)
  // @@ Leaving it in, since the -ORBSkipServiceConfigOpen is still
  // available. (-Iliyan)
  bool skip_service_config_open = false;

  // Extract any ORB options from the argument vector.
  if (parse_private_args_i (argc,
                            argv,
                            svc_config_argv,
                            skip_service_config_open) == -1)
    {
      return -1;
    }

  // Construct an argument vector specific to the process-wide
  // (global) Service Configurator instance.
  CORBA::StringSeq global_svc_config_argv;

  ACE_Service_Gestalt * theone = ACE_Service_Config::global ();

  if (service_open_count == 1)
    {
      ACE_Service_Config_Guard config_guard (theone);

      if (TAO_debug_level > 2)
        {
          ACE_DEBUG ((LM_DEBUG,
                      ACE_TEXT ("TAO (%P|%t) Initializing the ")
                      ACE_TEXT ("process-wide services\n")));
        }

      register_global_services_i (theone);

      // Be certain to copy the program name so that service configurator
      // has something to skip!
      ACE_CString argv0 ("");

      if (argc > 0 && argv != 0)
        {
          argv0 = ACE_TEXT_ALWAYS_CHAR (argv[0]);
        }

      global_svc_config_argv.length (1);
      global_svc_config_argv[0] = argv0.c_str ();

      if (parse_global_args_i (argc, argv, global_svc_config_argv, true) == -1)
        {
          return -1;
        }

      if (parse_svcconf_args_i (argc, argv, global_svc_config_argv) == -1)
        {
          return -1;
        }

      int global_svc_config_argc = global_svc_config_argv.length ();
      int status =
        open_private_services_i (theone,
                                 global_svc_config_argc,
                                 global_svc_config_argv.get_buffer (),
                                 skip_service_config_open);

      if (status == -1 && TAO_debug_level > 0)
        {
          if (TAO_debug_level > 0)
            {
              ACE_ERROR_RETURN ((LM_DEBUG,
                                 ACE_TEXT ("TAO (%P|%t) Failed to ")
                                 ACE_TEXT ("open process-wide service ")
                                 ACE_TEXT ("configuration\n")),
                                -1);
            }

          return -1;
        }

      register_additional_services_i (theone);


      if (TAO_debug_level > 4)
        ACE_DEBUG ((LM_DEBUG,
                    ACE_TEXT ("TAO (%P|%t) Default ORB - global ")
                    ACE_TEXT ("initialization completed.\n")));

      // Notify all other threads that may be waiting, that the global
      // gestalt has been initialized.
      {
        ACE_MT (ACE_GUARD_RETURN (TAO_SYNCH_RECURSIVE_MUTEX,
                                  guard,
                                  TAO_Ubergestalt_Ready_Condition::instance ()->mutex (),
                                  -1));

        is_ubergestalt_ready = true;
        ACE_MT (if (TAO_Ubergestalt_Ready_Condition::instance ()->
                    broadcast () == -1)
                return -1);
      }

    }
  else
    {
      int status =
        parse_global_args_i(argc, argv,global_svc_config_argv, false);
      if (status == -1 && TAO_debug_level > 0)
        ACE_DEBUG ((LM_DEBUG,
                    ACE_TEXT ("TAO (%P|%t) Skipping the process-wide ")
                    ACE_TEXT ("service configuration, service_open_count ")
                    ACE_TEXT ("= %d, status = %d\n"),
                    service_open_count,
                    status));
    }

  if (TAO_debug_level > 2)
    {
      ACE_DEBUG ((LM_DEBUG,
                  ACE_TEXT ("TAO (%P|%t) Initializing the ")
                  ACE_TEXT ("orb-specific services\n")));
    }

  if (parse_svcconf_args_i (argc, argv, svc_config_argv) == -1)
    {
      return -1;
    }

  int svc_config_argc = svc_config_argv.length ();
  int status =
    open_private_services_i (pcfg,
                             svc_config_argc,
                             svc_config_argv.get_buffer (),
                             skip_service_config_open);

  if (status >= 0)
    {
      return 0;
    }

  if (TAO_debug_level > 0)
    {
      ACE_ERROR_RETURN ((LM_DEBUG,
                         ACE_TEXT ("TAO (%P|%t) Failed to ")
                         ACE_TEXT ("open orb service configuration\n")),
                        -1);
    }

  return -1;
}

int
TAO::ORB::close_services (ACE_Service_Gestalt* pcfg)
{
  ACE_MT (ACE_GUARD_RETURN (TAO_SYNCH_RECURSIVE_MUTEX,
                            guard,
                            *ACE_Static_Object_Lock::instance (),
                            -1));
  service_open_count--;

  return pcfg->close ();
}

void
TAO::ORB::default_svc_conf_entries (char const * rf_args,
                                    char const * ssf_args,
                                    char const * csf_args)
{
  resource_factory_args        = rf_args;
  server_strategy_factory_args = ssf_args;
  client_strategy_factory_args = csf_args;
}

TAO_END_VERSIONED_NAMESPACE_DECL

// -----------------------------------------------------
namespace
{
  /// Open services, belonging to the gestalt instance.

  int
  open_private_services_i (ACE_Service_Gestalt * pcfg,
                           int & argc,
                           ACE_TCHAR ** argv,
                           bool skip_service_config_open,
                           bool ignore_default_svc_conf_file)
  {

    if (skip_service_config_open)
      {
        return 0;
      }

#if defined (TAO_PLATFORM_SVC_CONF_FILE_NOTSUP)
    ignore_default_svc_conf_file = true;
#endif /* TAO_PLATFORM_SVC_CONF_FILE_NOTSUP */

    return pcfg->open (argc,
                       argv,
                       ACE_DEFAULT_LOGGER_KEY,
                       0, // Don't ignore static services.
                       ignore_default_svc_conf_file);
  }

  /// @brief registers all process-wide (global) services, available
  /// to all ORBs
  void
  register_global_services_i (ACE_Service_Gestalt * pcfg)
  {
    // This has to be done before intializing the resource
    // factory. Codesets is a special library since its configuration
    // is optional and it may be linked statically.
    if (negotiate_codesets)
      {
        TAO_Codeset_Manager_Factory_Base *factory =
          ACE_Dynamic_Service<TAO_Codeset_Manager_Factory_Base>::instance (
            "TAO_Codeset");

        if (factory == 0 || factory->is_default ())
          {
#if !defined (TAO_AS_STATIC_LIBS)
            // only for dynamic libs, check to see if default factory
            // and if so, remove it
            ACE_Service_Config::process_directive (
              ACE_REMOVE_SERVICE_DIRECTIVE ("TAO_Codeset"));

            ACE_Service_Config::process_directive (
              ACE_DYNAMIC_SERVICE_DIRECTIVE (
                "TAO_Codeset",
                "TAO_Codeset",
                "_make_TAO_Codeset_Manager_Factory",
                ""));

            factory =
              ACE_Dynamic_Service<
                  TAO_Codeset_Manager_Factory_Base
                >::instance ("TAO_Codeset");
#endif
          }

        if (factory == 0)
          {
            if (TAO_debug_level > 0)
              {
                ACE_ERROR ((LM_ERROR,
                            ACE_TEXT ("(%P|%t) ORB_Core: ")
                            ACE_TEXT ("Unable to initialize ")
                            ACE_TEXT ("Codeset Manager\n")));
              }
          }
      }

    pcfg->process_directive (
      ace_svc_desc_TAO_Default_Resource_Factory);
    pcfg->process_directive (
      ace_svc_desc_TAO_Default_Client_Strategy_Factory);
    pcfg->process_directive (
      ace_svc_desc_TAO_Default_Server_Strategy_Factory);

    // Configure the IIOP factory. You do *NOT* need modify this
    // code to add your own protocol, instead simply add the
    // following to your svc.conf file:
    //
    // dynamic PN_Factory Service_Object * LIB:_make_PN_Protocol_Factory() ""
    // static Resource_Factory "-ORBProtocolFactory PN_Factory"
    //
    // where PN is the name of your protocol and LIB is the base
    // name of the shared library that implements the protocol.

#if defined (TAO_HAS_IIOP) && (TAO_HAS_IIOP != 0)
    pcfg->process_directive (ace_svc_desc_TAO_IIOP_Protocol_Factory);
#endif /* TAO_HAS_IIOP && TAO_HAS_IIOP != 0 */

    // add descriptor to list of static objects.
    pcfg->process_directive (ace_svc_desc_TAO_MCAST_Parser);
    pcfg->process_directive (ace_svc_desc_TAO_CORBANAME_Parser);
    pcfg->process_directive (ace_svc_desc_TAO_CORBALOC_Parser);
    pcfg->process_directive (ace_svc_desc_TAO_FILE_Parser);
    pcfg->process_directive (ace_svc_desc_TAO_DLL_Parser);
    pcfg->process_directive (ace_svc_desc_TAO_HTTP_Parser);
    pcfg->process_directive (ace_svc_desc_TAO_Default_Stub_Factory);
    pcfg->process_directive (
      ace_svc_desc_TAO_Default_Endpoint_Selector_Factory);
    pcfg->process_directive (ace_svc_desc_TAO_Default_Protocols_Hooks);
    pcfg->process_directive (
      ace_svc_desc_TAO_Default_Thread_Lane_Resources_Manager_Factory);
    pcfg->process_directive (ace_svc_desc_TAO_Default_Collocation_Resolver);

  } /* register_global_services_i */

  void
  register_additional_services_i (ACE_Service_Gestalt * pcfg)
  {
    // @@ What the heck do these things do and do we need to avoid
    //    calling them if we're not invoking the svc.conf file?
    // @@ They are needed for platforms that have no file system,
    //    like VxWorks.

    if (resource_factory_args != 0)
      {
        pcfg->process_directive(
          ACE_TEXT_CHAR_TO_TCHAR (resource_factory_args));
      }

    if (client_strategy_factory_args != 0)
      {
        pcfg->process_directive
          (ACE_TEXT_CHAR_TO_TCHAR (client_strategy_factory_args));
      }

    if (server_strategy_factory_args != 0)
      {
        pcfg->process_directive
          (ACE_TEXT_CHAR_TO_TCHAR (server_strategy_factory_args));
      }

    // If available, allow the Adapter Factory to setup.
    ACE_Service_Object *adapter_factory =
      ACE_Dynamic_Service<ACE_Service_Object>::instance (
        pcfg,
        TAO_ORB_Core::poa_factory_name ().c_str ());

    if (adapter_factory != 0)
      {
        adapter_factory->init (0, 0);
      }

    ACE_Service_Object * const pi_server_loader =
      ACE_Dynamic_Service<ACE_Service_Object>::instance (
        pcfg,
        "PI_Server_Loader");

    if (pi_server_loader != 0)
      {
        pi_server_loader->init (0, 0);
      }

    ACE_Service_Object * const bidir_loader =
      ACE_Dynamic_Service<ACE_Service_Object>::instance (
        pcfg,
        "BiDirGIOP_Loader");

    if (bidir_loader != 0)
      {
        bidir_loader->init (0, 0);
      }

    ACE_Service_Object * const messaging_loader =
      ACE_Dynamic_Service<ACE_Service_Object>::instance (
        pcfg,
        "Messaging_Loader");

    if (messaging_loader != 0)
      {
        messaging_loader->init (0, 0);
      }

    // Handle RTCORBA library special case.  Since RTCORBA needs
    // its init method call to register several hooks, call it
    // here if it hasn't already been called.
    ACE_Service_Object * const rt_loader =
      ACE_Dynamic_Service<ACE_Service_Object>::instance (
        pcfg,
        "RT_ORB_Loader");

    if (rt_loader != 0)
      {
        rt_loader->init (0, 0);
      }

    ACE_Service_Object * const rtscheduler_loader =
      ACE_Dynamic_Service<ACE_Service_Object>::instance (
        pcfg,
        "RTScheduler_Loader");

    if (rtscheduler_loader != 0)
      {
        rtscheduler_loader->init (0, 0);
      }

  } /* register_additional_services_i */

  int
  parse_svcconf_args_i (int &argc,
                        char **argv,
                        CORBA::StringSeq &svc_config_argv)
  {
    // Extract the Service Configurator ORB options from the argument
    // vector.
    ACE_Arg_Shifter arg_shifter (argc, argv);
    CORBA::ULong len = 0;

    while (arg_shifter.is_anything_left ())
      {
        const ACE_TCHAR *current_arg =
          arg_shifter.get_the_parameter (ACE_TEXT ("-ORBSvcConf"));

        if (0 != current_arg)
          {
            // Specify the name of the svc.conf file to be used.

            // Proceeds only if the configuration file exists.
            FILE * const conf_file =
              ACE_OS::fopen (current_arg, ACE_TEXT ("r"));

            if (0 == conf_file)
              {
                // Assigning EINVAL to errno to make an exception
                // thrown.  calling code does not throw an exception if
                // the errno is set to ENOENT for some reason.
                errno = EINVAL;

                ACE_ERROR_RETURN ((LM_ERROR,
                                   ACE_TEXT ("TAO (%P|%t) Service ")
                                   ACE_TEXT ("Configurator ")
                                   ACE_TEXT ("unable to open file %s\n"),
                                   current_arg),
                                  -1);
              }
            else
              {
                ACE_OS::fclose (conf_file);
              }

            len = svc_config_argv.length ();
            svc_config_argv.length (len + 2);  // 2 arguments to add

            svc_config_argv[len] = CORBA::string_dup ("-f");
            svc_config_argv[len + 1] =
              CORBA::string_dup (ACE_TEXT_ALWAYS_CHAR (current_arg));

            arg_shifter.consume_arg ();
          }
        // Can't interpret this argument.  Move on to the next argument.
        else
          {
            // Any arguments that don't match are ignored so that the
            // caller can still use them.
            arg_shifter.ignore_arg ();
          }
      }

    return 0;
  } /* parse_svcconf_args_i */

  int
  parse_private_args_i (int &argc,
                        char **argv,
                        CORBA::StringSeq &svc_config_argv,
                        bool & skip_service_config_open)
  {
    // Extract the Service Configurator ORB options from the argument
    // vector.
    ACE_Arg_Shifter arg_shifter (argc, argv);
    CORBA::ULong len = 0;

    while (arg_shifter.is_anything_left ())
      {
        const ACE_TCHAR *current_arg = 0;
        int result =
          arg_shifter.cur_arg_strncasecmp (
            ACE_TEXT ("-ORBSkipServiceConfigOpen"));

        if (0 == result)  // Start with the parameterless flags.
          {
            skip_service_config_open = true;

            arg_shifter.consume_arg ();
          }
        else  // Continue with flags that accept parameters.
          {
            current_arg =
              arg_shifter.get_the_parameter (
                ACE_TEXT ("-ORBSvcConfDirective"));

            if (0 != current_arg)
              {
                len = svc_config_argv.length ();
                svc_config_argv.length (len + 2);  // 2 arguments to add

                // This is used to pass arguments to the Service
                // Configurator using the "command line" to provide
                // configuration information rather than using a svc.conf
                // file.  Pass the "-S" to the service configurator.
                svc_config_argv[len] = CORBA::string_dup ("-S");
                svc_config_argv[len + 1] =
                  CORBA::string_dup (ACE_TEXT_ALWAYS_CHAR (current_arg));

                arg_shifter.consume_arg ();
              }
            else
              {
                current_arg =
                  arg_shifter.get_the_parameter (
                    ACE_TEXT ("-ORBServiceConfigLoggerKey"));

                if (0 != current_arg)
                  {
                    len = svc_config_argv.length ();
                    svc_config_argv.length (len + 2);  // 2 arguments to add

                    svc_config_argv[len] = CORBA::string_dup ("-k");
                    svc_config_argv[len + 1] =
                      CORBA::string_dup (ACE_TEXT_ALWAYS_CHAR (current_arg));

                    arg_shifter.consume_arg ();
                  }
                // Can't interpret this argument.
                // Move on to the next argument.
                else
                  {
                    // Any arguments that don't match are ignored so that
                    // the caller can still use them.
                    arg_shifter.ignore_arg ();
                  }
              }
          }
      }

    return 0;
  } /* parse_private_args_i */

  int
  parse_global_args_i (int &argc,
                       char **argv,
                       CORBA::StringSeq &svc_config_argv,
                       bool apply_values)
  {
    // NOTE: When adding new global arguments, ensure they are only
    // applied when apply_values is true, but that they are always
    // consumed, if they need to be consumed.
#if defined (TAO_DEBUG) && !defined (ACE_HAS_WINCE)
    // Make it a little easier to debug programs using this code.
    if (apply_values)
      {
        TAO_debug_level = ACE_Env_Value<u_int> ("TAO_ORB_DEBUG", 0);

        char * const value = ACE_OS::getenv ("TAO_ORB_DEBUG");

        if (value != 0)
          {
            TAO_debug_level = ACE_OS::atoi (value);

            if (TAO_debug_level <= 0)
              {
                TAO_debug_level = 1;
              }

            ACE_DEBUG ((LM_DEBUG,
                        ACE_TEXT ("TAO_debug_level == %d\n"),
                        TAO_debug_level));
          }
      }
#endif  /* TAO_DEBUG && !ACE_HAS_WINCE */


    // Extract the Service Configurator ORB options from the argument
    // vector.
    ACE_Arg_Shifter arg_shifter (argc, argv);
    CORBA::ULong len = 0;

    while (arg_shifter.is_anything_left ())
      {
        const ACE_TCHAR *current_arg = 0;
        int strcmp_result =
          arg_shifter.cur_arg_strncasecmp (ACE_TEXT ("-ORBDebug"));

        if (0 == strcmp_result)
          {
            if (apply_values)
              {
                // Later, replace all of these
                // warning this turns on a daemon.
                ACE::debug (1);
              }

            arg_shifter.consume_arg ();
          }
        else
          {
            current_arg =
              arg_shifter.get_the_parameter (
                ACE_TEXT ("-ORBNegotiateCodesets"));

            if (0 != current_arg)
              {
                if (apply_values)
                  {
                    // Don't consume, the ORB_Core::init will use it again.
                    negotiate_codesets = (ACE_OS::atoi (current_arg));
                  }
              }
            else
              {
                current_arg =
                  arg_shifter.get_the_parameter (
                    ACE_TEXT ("-ORBDebugLevel"));

                if (0 != current_arg)
                  {
                    if (apply_values)
                      {
                        TAO_debug_level =
                          ACE_OS::atoi (current_arg);
                      }

                    arg_shifter.consume_arg ();
                  }
                else
                  {
                    strcmp_result =
                      arg_shifter.cur_arg_strncasecmp (
                        ACE_TEXT ("-ORBDaemon"));

                    if (0 == strcmp_result)
                      {
                        // Be a daemon.
                        if (apply_values)
                          {
                            len = svc_config_argv.length ();
                            svc_config_argv.length (len + 1);

                            svc_config_argv[len] =
                              CORBA::string_dup ("-b");
                          }

                        arg_shifter.consume_arg ();
                      }
                    // Can't interpret this argument.
                    // Move on to the next argument.
                    else
                      {
                        // Any arguments that don't match are ignored so
                        // that the caller can still use them.
                        arg_shifter.ignore_arg ();
                      }
                  }
              }
          }
      }

    return 0;
  } /* parse_global_args_i */
} // anonymous namespace.