summaryrefslogtreecommitdiff
path: root/modules/CIAO/DAnCE/RedirectionService/RedirectionService.cpp
blob: 551d7bb5be68d6b71609b574a0c57f3cd42e7b08 (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
// $Id$

#include "RedirectionService.h"
#include "DAnCE/Logger/Log_Macros.h"

using namespace DAnCE;

RedirectionService::RedirectionService (CORBA::ORB_ptr orb,
                                        PortableServer::POA_ptr poa,
                                        CosNaming::NamingContext_ptr hosting_naming,
                                        CosNaming::NamingContext_ptr domain_naming,
                                        bool ns,
                                        bool sl)
    : orb_ (CORBA::ORB::_duplicate (orb))
    , poa_ (PortableServer::POA::_duplicate (poa))
    , naming_ (hosting_naming, domain_naming)
    , ns_ (ns)
    , sl_ (sl)
{
  DANCE_TRACE ("RedirectionService::RedirectionService");
  if (this->ns_)
    {
      if (CORBA::is_nil (hosting_naming))
        {
          DANCE_DEBUG ((LM_DEBUG, DLINFO ACE_TEXT("RedirectionService::RedirectionService - ")
                        ACE_TEXT("Name Service redirection is enabled but name context is nil.\n")));
        }
    }
}

RedirectionService::~RedirectionService()
{
  DANCE_TRACE ("RedirectionService::~RedirectionService");
  for (TLocators::iterator it = this->locators_.begin ();
       it != this->locators_.end ();
       ++it)
    {
      delete (*it).int_id_;
    }
}

void
RedirectionService::add_node (const ACE_CString& node)
{
  DANCE_TRACE ("RedirectionService::add_node");
  if (this->sl_)
    {
      CCMObjectLocator* locator = 0;
      if (0 != this->locators_.find (node, locator))
        {
          locator = new CCMObjectLocator (this->orb_.in(), this->poa_.in(), node.c_str());
          this->locators_.rebind (node, locator);
        }
    }

  if (this->ns_)
    {
      this->naming_.add_node (node);
    }
}

void
RedirectionService::registration_start (const ACE_CString& node, const ACE_CString& plan)
{
  DANCE_TRACE ("RedirectionService::registration_start");
  if (this->sl_)
    {
      CCMObjectLocator* locator = 0;
      if (0 != this->locators_.find (node, locator))
        {
          locator = new CCMObjectLocator (this->orb_.in(), this->poa_.in(), node.c_str());
          this->locators_.rebind (node, locator);
        }
      locator->start_register (plan);
    }
  if (this->ns_)
    {
      this->naming_.start_binding (node, plan);
    }
}

void
RedirectionService::registration (const ACE_CString& node, const ACE_CString& plan, const ACE_CString& component, const ACE_CString& port, CORBA::Object_ptr obj)
{
  DANCE_TRACE ("RedirectionService::registration");
  DANCE_DEBUG ((LM_DEBUG, DLINFO ACE_TEXT("RedirectionService::registration - ")
                ACE_TEXT("for node %C plan %C component %C and port %C is started.\n"),
                node.c_str(),
                plan.c_str(),
                component.c_str(),
                port.c_str()));
  CORBA::Object_var ns_obj = CORBA::Object::_duplicate (obj);
  if (this->sl_)
    {
      CCMObjectLocator* locator = 0;
      if (0 != this->locators_.find (node, locator))
        {
          locator = new CCMObjectLocator (this->orb_.in(), this->poa_.in(), node.c_str());
          this->locators_.rebind (node, locator);
        }
      ns_obj = locator->register_object (plan, component, port, obj);
    }
  if (this->ns_)
    {
      if (0 == port.length())
        {
          this->naming_.bind (node, plan, component, ns_obj.in());
        }
      else
        {
          this->naming_.bind (node, plan, component, port, ns_obj.in());
        }
    }
  DANCE_DEBUG ((LM_DEBUG, DLINFO ACE_TEXT("RedirectionService::registration - ")
                ACE_TEXT("Registration has been finished.\n")));
}

void
RedirectionService::registration (const ACE_CString& node, const ACE_CString& plan, const ACE_CString& component, CORBA::Object_ptr obj)
{
  DANCE_TRACE ("RedirectionService::registration");
  this->registration (node, plan, component, "", obj);
}

void
RedirectionService::registration_finish (const ACE_CString& node, const ACE_CString& plan)
{
  DANCE_TRACE ("RedirectionService::registration_finish");
  if (this->sl_)
    {
      CCMObjectLocator* locator;
      if (0 != this->locators_.find (node, locator))
        {
          locator = new CCMObjectLocator (this->orb_.in(), this->poa_.in(), node.c_str());
          this->locators_.rebind (node, locator);
        }
      locator->finish_register (plan);
    }
  if (this->ns_)
    {
      this->naming_.finish_binding (node, plan);
    }
}

void
RedirectionService::unregister (const ACE_CString& node, const ACE_CString& plan)
{
  DANCE_TRACE ("RedirectionService::unregister");
  DANCE_DEBUG((LM_TRACE, DLINFO ACE_TEXT("RedirectionService::unregister - ")
               ACE_TEXT("unregistering %C/%C...\n"), node.c_str(), plan.c_str()));
  if (this->ns_)
    {
      this->naming_.unbind_context (node, plan);
      DANCE_DEBUG((LM_TRACE, DLINFO ACE_TEXT("RedirectionService::unregister - ")
                   ACE_TEXT("finished.\n")));
    }
  else
    {
      DANCE_DEBUG((LM_TRACE, DLINFO ACE_TEXT("RedirectionService::unregister - ")
                   ACE_TEXT("nothing to do.\n")));
    }
}