summaryrefslogtreecommitdiff
path: root/ACE/ace/Dynamic_Service_Base.cpp
blob: 301361a0b2d0a26d6834bff80738d1cdc159430d (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
#include "ace/Dynamic_Service_Base.h"
#include "ace/ACE.h"
#include "ace/Service_Config.h"
#include "ace/Service_Repository.h"
#include "ace/Service_Types.h"
#include "ace/Log_Msg.h"


ACE_RCSID (ace,
           Dynamic_Service_Base,
           "$Id$")

  ACE_BEGIN_VERSIONED_NAMESPACE_DECL


void
ACE_Dynamic_Service_Base::dump (void) const
{
#if defined (ACE_HAS_DUMP)
  ACE_TRACE ("ACE_Dynamic_Service_Base::dump");

  ACE_DEBUG ((LM_DEBUG, ACE_BEGIN_DUMP, this));
  ACE_DEBUG ((LM_DEBUG, ACE_LIB_TEXT ("\n")));
  ACE_DEBUG ((LM_DEBUG, ACE_END_DUMP));
#endif /* ACE_HAS_DUMP */
}

// Get the instance using <name> for the current global
// service configuration repository.

void *
ACE_Dynamic_Service_Base::instance (const ACE_TCHAR *name, bool no_global)
{
  ACE_TRACE ("ACE_Dynamic_Service_Base::instance");
  return instance (ACE_Service_Config::current (), name, no_global);
}


void *
ACE_Dynamic_Service_Base::instance (const ACE_TCHAR *name)
{
  ACE_TRACE ("ACE_Dynamic_Service_Base::instance");
  return instance (ACE_Service_Config::current (), name, false);
}


// Find a service registration

const ACE_Service_Type *
ACE_Dynamic_Service_Base::find_i (const ACE_Service_Gestalt* &repo,
                                  const ACE_TCHAR *name,
                                  bool no_global)
{
  ACE_TRACE ("ACE_Dynamic_Service_Base::find_i");
  const ACE_Service_Type *svc_rec = 0;

  ACE_Service_Gestalt* global = ACE_Service_Config::global ();

  for ( ; (repo->find (name, &svc_rec) == -1) && !no_global; repo = global)
    {
      // Check the static repo, too if different
      if (repo == global)
        break;
    }

  return svc_rec;
}


// Get the instance using <name> for specific configuration repository.

void *
ACE_Dynamic_Service_Base::instance (const ACE_Service_Gestalt* repo,
                                    const ACE_TCHAR *name,
                                    bool no_global)
{
  ACE_TRACE ("ACE_Dynamic_Service_Base::instance");

  void *obj = 0;
  const ACE_Service_Type_Impl *type = 0;

  const ACE_Service_Gestalt* repo_found = repo;
  const ACE_Service_Type *svc_rec = find_i (repo_found, name, no_global);
  if (svc_rec != 0)
    {
      type = svc_rec->type ();
      if (type != 0)
        obj = type->object ();
    }

  if (ACE::debug ())
    {
      ACE_Guard <ACE_Log_Msg> log_guard (*ACE_Log_Msg::instance ());

      ACE_DEBUG ((LM_DEBUG,
                  ACE_LIB_TEXT ("ACE (%P|%t) DSB::instance, repo=%@, name=%s")
                  ACE_LIB_TEXT (" type=%@ => %@"),
                  repo->repo_, name, type, obj));

      if (repo->repo_ != repo_found->repo_)
        ACE_DEBUG ((LM_DEBUG, ACE_LIB_TEXT (" [in repo=%@]\n"),
                    repo_found->repo_));
      else
        ACE_DEBUG ((LM_DEBUG, ACE_LIB_TEXT ("\n")));
    }

  return obj;
}


// Get the instance using <name> for specific configuration repository.

void *
ACE_Dynamic_Service_Base::instance (const ACE_Service_Gestalt* repo,
                                    const ACE_TCHAR *name)
{
  return instance(repo,name,false);
}


ACE_END_VERSIONED_NAMESPACE_DECL