summaryrefslogtreecommitdiff
path: root/TAO/tao/ORBInitializer_Registry.cpp
blob: 8a00ecd6f7770cf230d8f42c2c4efa52add64286 (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
#include "tao/ORBInitializer_Registry.h"
#include "tao/ORBInitializer_Registry_Adapter.h"
#include "tao/PortableInterceptorC.h"
#include "tao/ORB.h"
#include "tao/ORB_Constants.h"
#include "tao/TAO_Singleton_Manager.h"
#include "tao/SystemException.h"

#include "ace/Service_Config.h"
#include "ace/Dynamic_Service.h"
#include "ace/Static_Object_Lock.h"
#include "ace/Recursive_Thread_Mutex.h"
#include "ace/Log_Msg.h"

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


// ****************************************************************

TAO_BEGIN_VERSIONED_NAMESPACE_DECL

namespace PortableInterceptor
{
  void
  register_orb_initializer (
    ORBInitializer_ptr init
    )
  {
    {
      // Using ACE_Static_Object_Lock::instance() precludes
      // register_orb_initializer() from being called within a static
      // object CTOR.
      ACE_MT (ACE_GUARD (TAO_SYNCH_RECURSIVE_MUTEX,
                         guard,
                         *ACE_Static_Object_Lock::instance ()));

      // Make sure TAO's singleton manager is initialized.
      if (TAO_Singleton_Manager::instance ()->init () == -1)
        {
          ACE_ERROR ((LM_ERROR,
                      ACE_TEXT ("(%P|%t) register_orb_initializer: ")
                      ACE_TEXT ("Unable to pre-initialize TAO\n")));
        }

      TAO::ORB::init_orb_globals ();
    }

    // If not, lookup it up.
    TAO::ORBInitializer_Registry_Adapter *orbinitializer_registry_ =
      ACE_Dynamic_Service<TAO::ORBInitializer_Registry_Adapter>::instance
      ("ORBInitializer_Registry", true); // only look in the local repo

  #if !defined (TAO_AS_STATIC_LIBS)
    if (orbinitializer_registry_ == 0)
      {
        ACE_Service_Config::process_directive (
          ACE_DYNAMIC_SERVICE_DIRECTIVE("ORBInitializer_Registry",
                                        "TAO_PI",
                                        "_make_ORBInitializer_Registry",
                                        ""));
        orbinitializer_registry_ =
          ACE_Dynamic_Service<TAO::ORBInitializer_Registry_Adapter>::instance
            ("ORBInitializer_Registry");
      }

  #endif /* !TAO_AS_STATIC_LIBS */

    if (orbinitializer_registry_ != 0)
      {
        orbinitializer_registry_->register_orb_initializer (
          init
         );
      }
    else
      {
        ACE_ERROR ((LM_ERROR,
                    ACE_TEXT ("(%P|%t) %p\n"),
                    ACE_TEXT ("ERROR: ORBInitializer Registry unable to find the ")
                    ACE_TEXT ("ORBInitializer Registry instance")));

        throw ( ::CORBA::INTERNAL ());
      }
  }
}

TAO_END_VERSIONED_NAMESPACE_DECL