summaryrefslogtreecommitdiff
path: root/TAO/tao/PortableGroup/POA_Hooks.cpp
blob: 7c5d58fd2380dd2b75f7bbe64fd67c64b767748f (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
// -*- C++ -*-
// $Id$

// =========================================================================
//
// = LIBRARY
//    PortableGroup
//
// = FILENAME
//    POA_Hooks.h
//
// = AUTHOR
//    Frank Hunleth <fhunleth@cs.wustl.edu>
//
// =========================================================================

#include "POA_Hooks.h"
#include "PortableGroup_Loader.h"
#include "tao/Stub.h"

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

TAO_POA_Hooks::TAO_POA_Hooks (TAO_PortableGroup_Loader *portable_group_adapter) :
  portable_group_adapter_ (portable_group_adapter)
{
}

TAO_POA_Hooks::~TAO_POA_Hooks (void)
{
}

PortableServer::ObjectId *
TAO_POA_Hooks::create_id_for_reference (
    TAO_POA &the_poa,
    CORBA::Object_ptr the_ref,
    CORBA::Environment &ACE_TRY_ENV)
    ACE_THROW_SPEC ((
      CORBA::SystemException,
      PortableServer::POA::WrongAdapter
    ))
{

  // Get the RepositoryId from the Group reference so
  // we know what kind of reference to make.
  const char* repository_id = the_ref->_stubobj ()->type_id;

  // Create a temporary object reference and then get the
  // ObjectId out of it.
  CORBA::Object_var obj_ref = the_poa.create_reference (repository_id,
                                                        ACE_TRY_ENV);
  ACE_CHECK_RETURN (0);

  PortableServer::ObjectId_var obj_id = the_poa.reference_to_id (obj_ref.in (),
                                                                 ACE_TRY_ENV);
  ACE_CHECK_RETURN (0);

  // Create the acceptors necessary to receive requests for the
  // specified group reference.
  this->create_group_acceptors (the_ref,
                                this->portable_group_adapter_->acceptor_registry_,
                                the_poa.orb_core (),
                                ACE_TRY_ENV);

  ACE_CHECK_RETURN (0);

  // Find the Group Component.
  PortableGroup::TagGroupTaggedComponent *tmp_group_id;
  ACE_NEW_THROW_EX (tmp_group_id,
                    PortableGroup::TagGroupTaggedComponent,
                    CORBA::NO_MEMORY (
                      CORBA::SystemException::_tao_minor_code (
                        TAO_DEFAULT_MINOR_CODE,
                        ENOMEM),
                      CORBA::COMPLETED_NO));
  ACE_CHECK_RETURN (0);

  PortableGroup::TagGroupTaggedComponent_var group_id = tmp_group_id;

  if (this->find_group_component (the_ref, group_id.inout ()) != 0)
    {
      // Group component wasn't found.  The group reference
      // that was passed in must be bogus.
      ACE_THROW_RETURN (CORBA::INV_OBJREF (),
                        0);
    }

  const TAO_ObjectKey &key = obj_ref->_object_key ();

  // Add a mapping from GroupId to Object key in the PortableGroup

  this->portable_group_adapter_->group_map_.add_groupid_objectkey_pair (
                                   group_id._retn (),
                                   key,
                                   ACE_TRY_ENV);
  ACE_CHECK_RETURN (0);

  return obj_id._retn ();
}

int
TAO_POA_Hooks::find_group_component (const CORBA::Object_ptr the_ref,
                                     PortableGroup::TagGroupTaggedComponent &group)
{
  const TAO_MProfile& profiles = the_ref->_stubobj ()->base_profiles ();
  const TAO_Profile* profile;
  CORBA::ULong slot;

  // Iterate through the tagged profiles, and
  // create acceptors for the multicast ones.
  slot = 0;
  while (profile = profiles.get_profile (slot))
    {
      if (this->find_group_component_in_profile (profile, group) == 0)
        return 0;

      ++slot;
    }

  // Not found.
  return -1;
}

int
TAO_POA_Hooks::find_group_component_in_profile (const TAO_Profile* profile,
                                                PortableGroup::TagGroupTaggedComponent &group)
{
  // Iterate through the tagged components looking for
  // group tag.
  const TAO_Tagged_Components& components = profile->tagged_components ();

  IOP::TaggedComponent tagged_component;
  tagged_component.tag = TAO_TAG_GROUP;

  // Try to find it.
  if (components.get_component (tagged_component) == 0)
    return -1;

  // Found it.
  const CORBA::Octet *buf =
    tagged_component.component_data.get_buffer ();

  TAO_InputCDR in_cdr (ACE_reinterpret_cast (const char*, buf),
                       tagged_component.component_data.length ());

  // Extract the Byte Order.
  CORBA::Boolean byte_order;
  if ((in_cdr >> ACE_InputCDR::to_boolean (byte_order)) == 0)
    return -1;
  in_cdr.reset_byte_order (ACE_static_cast(int, byte_order));

  if ((in_cdr >> group) == 0)
    return -1;

  return 0;
}

int
TAO_POA_Hooks::create_group_acceptors (CORBA::Object_ptr the_ref,
                                       TAO_PortableGroup_Acceptor_Registry &acceptor_registry,
                                       TAO_ORB_Core &orb_core,
                                       CORBA::Environment &ACE_TRY_ENV)
{
  const TAO_MProfile& profiles = the_ref->_stubobj ()->base_profiles ();
  const TAO_Profile* profile;
  CORBA::ULong slot;
  int num = 0;

  // Iterate through the tagged profiles, and
  // create acceptors for the multicast ones.
  slot = 0;
  while (profile = profiles.get_profile (slot))
    {
      if (profile->supports_multicast ())
        {
          acceptor_registry.open (profile, orb_core, ACE_TRY_ENV);
          ACE_CHECK_RETURN (0);
          ++num;
        }

      ++slot;
    }

  // Return the number of acceptors registered.
  return num;
}


PortableServer::IDs *
TAO_POA_Hooks::reference_to_ids (
    TAO_POA &the_poa,
    CORBA::Object_ptr the_ref,
    CORBA::Environment &ACE_TRY_ENV)
    ACE_THROW_SPEC ((
      CORBA::SystemException,
      PortableServer::POA::WrongAdapter
    ))
{

  return 0;
}


#if defined (ACE_HAS_EXPLICIT_TEMPLATE_INSTANTIATION)

#elif defined (ACE_HAS_TEMPLATE_INSTANTIATION_PRAGMA)

#endif /* ACE_HAS_EXPLICIT_TEMPLATE_INSTANTIATION */