summaryrefslogtreecommitdiff
path: root/modules/CIAO/ciao/Servant_Impl_Utils_T.cpp
blob: ba292da07ea50a546cf257277978c9b07673e0d5 (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
// $Id$

#ifndef CIAO_SERVANT_IMPL_UTILS_T_C
#define CIAO_SERVANT_IMPL_UTILS_T_C

#include "Servant_Impl_Base.h"
#include "ciao/Cookies.h"

namespace CIAO
{
  template<typename T_var>
  void
  Servant_Impl_Base::describe_simplex_receptacle (
      const char *port_name,
      const char *port_type_repo_id,
      T_var &connection,
      ::Components::ReceptacleDescriptions_var &descriptions,
      CORBA::ULong slot
    )
  {
    ::Components::ReceptacleDescription *elem = 0;
    ACE_NEW (elem,
             ::OBV_Components::ReceptacleDescription);
    ::Components::ReceptacleDescription_var safe_elem = elem;

    elem->name (port_name);
    elem->type_id (port_type_repo_id);
    elem->is_multiple (false);
    elem->connections ().length (1UL);

    ::Components::ConnectionDescription *conn = 0;
    ACE_NEW (conn, ::OBV_Components::ConnectionDescription);
    ::Components::ConnectionDescription_var safe_conn = conn;

    conn->ck (0);
    conn->objref (connection.in ());

    elem->connections ()[0UL] = safe_conn._retn ();
    descriptions[slot] = safe_elem._retn ();
  }

  template<typename T_var>
  void
  Servant_Impl_Base::describe_multiplex_receptacle (
      const char *port_name,
      const char *port_type_repo_id,
      ACE_Active_Map_Manager<T_var> &objrefs,
      ::Components::ReceptacleDescriptions_var &descriptions,
      CORBA::ULong slot
    )
  {
    ::Components::ReceptacleDescription *elem = 0;
    ACE_NEW (elem,
             ::OBV_Components::ReceptacleDescription);
    ::Components::ReceptacleDescription_var safe_elem = elem;

    elem->name (port_name);
    elem->type_id (port_type_repo_id);
    elem->is_multiple (true);
    elem->connections ().length (objrefs.current_size ());

    CORBA::ULong map_slot = 0UL;
    ::Components::ConnectionDescription *conn = 0;

    for (typename ACE_Active_Map_Manager<T_var>::CONST_ITERATOR iter (
             objrefs
           );
         0 == iter.done ();
         iter.advance (), ++map_slot)
      {
        ACE_NEW (conn,
                 ::OBV_Components::ConnectionDescription);
        ::Components::ConnectionDescription_var safe_conn = conn;

        ::Components::Cookie *cookie_from_key = 0;
        ACE_NEW (cookie_from_key,
                 ::CIAO::Map_Key_Cookie ((*iter).ext_id_));

        // Valuetype member set operation calls add_ref.
        conn->ck (cookie_from_key);
        CORBA::remove_ref (cookie_from_key);

        conn->objref ((*iter).int_id_.in ());

        elem->connections ()[map_slot] = safe_conn._retn ();
      }

    descriptions[slot] = safe_elem._retn ();
  }

  template<typename T_var>
  void
  Servant_Impl_Base::describe_pub_event_source (
      const char *port_name,
      const char *port_type_repo_id,
      ACE_Active_Map_Manager<T_var> &consumers,
      ::Components::PublisherDescriptions_var &descriptions,
      CORBA::ULong slot
    )
  {
    ::Components::PublisherDescription *elem = 0;
    ACE_NEW (elem,
             ::OBV_Components::PublisherDescription);
    ::Components::PublisherDescription_var safe_elem = elem;

    elem->name (port_name);
    elem->type_id (port_type_repo_id);
    elem->consumer ().length (consumers.current_size ());

    CORBA::ULong map_slot = 0UL;
    ::Components::SubscriberDescription *sub = 0;

    for (typename ACE_Active_Map_Manager<T_var>::CONST_ITERATOR iter (
             consumers
           );
         0 == iter.done ();
         iter.advance (), ++map_slot)
      {
        ACE_NEW (sub,
                 ::OBV_Components::SubscriberDescription);
        ::Components::SubscriberDescription_var safe_sub = sub;

        ::Components::Cookie *cookie_from_key = 0;
        ACE_NEW (cookie_from_key,
                 ::CIAO::Map_Key_Cookie ((*iter).ext_id_));

        // Valuetype member set operation calls add_ref.
        sub->ck (cookie_from_key);
        CORBA::remove_ref (cookie_from_key);

        sub->consumer ((*iter).int_id_.in ());

        elem->consumer ()[map_slot] = safe_sub._retn ();
      }

    descriptions[slot] = safe_elem._retn ();
  }

  template<typename T_var>
  void
  Servant_Impl_Base::describe_emit_event_source (
      const char *port_name,
      const char *port_type_repo_id,
      T_var &consumer_ref,
      ::Components::EmitterDescriptions_var &descriptions,
      CORBA::ULong slot
    )
  {
    ::Components::EmitterDescription *elem = 0;
    ACE_NEW (elem,
             ::OBV_Components::EmitterDescription);
    ::Components::EmitterDescription_var safe_elem = elem;

    elem->name (port_name);
    elem->type_id (port_type_repo_id);

    // Valuetype 'set' call increments the reference count.
    elem->consumer (consumer_ref.in ());

    descriptions[slot] = safe_elem._retn ();
  }
}

#endif /* CIAO_SERVANT_IMPL_T_C */