summaryrefslogtreecommitdiff
path: root/TAO/CIAO/tools/RTComponentServer/RTConfig_Manager.cpp
blob: cfeac13cd7de32ee5d3fac4d642450ce51a9edb1 (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
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
// $Id$

#include "RTConfig_Manager.h"
#include "ciao/CIAO_common.h"
#include "ace/SString.h"

#if !defined (__ACE_INLINE__)
# include "RTConfig_Manager.inl"
#endif /* __ACE_INLINE__ */

void
CIAO::RTResource_Config_Manager::init
(const CIAO::RTConfiguration::RTORB_Resource_Info &info
 ACE_ENV_ARG_DECL)
  ACE_THROW_SPEC ((CORBA::SystemException))
{
  CORBA::ULong i;

  // Creating and binding name with RT Threadpool
  for (i = 0; i < info.tp_configs.length (); ++i)
    {
      RTCORBA::ThreadpoolId thr_id =
        this->rtorb_->create_threadpool
        (info.tp_configs[i].stacksize,
         info.tp_configs[i].static_threads,
         info.tp_configs[i].dynamic_threads,
         info.tp_configs[i].default_priority,
         info.tp_configs[i].allow_request_buffering,
         info.tp_configs[i].max_buffered_requests,
         info.tp_configs[i].max_request_buffer_size
         ACE_ENV_ARG_PARAMETER);
      ACE_CHECK;                // Simply pass back the exception here
                                // for now.  We need to have a better way
                                // to handle execption here.
      if (this->threadpool_map_.bind (info.tp_configs[i].name.in (),
                                      thr_id) != 0)
        {
          ACE_DEBUG ((LM_DEBUG, "Error binding thread pool name: %s to map when initializing RTComponentServer resources.\n", info.tp_configs[i].name.in ()));
          ACE_THROW (CORBA::INTERNAL ());
        }
    }

  for (i = 0; i < info.tpl_configs.length (); ++i)
    {
      RTCORBA::ThreadpoolId thr_id =
        this->rtorb_->create_threadpool_with_lanes
        (info.tpl_configs[i].stacksize,
         info.tpl_configs[i].lanes,
         info.tpl_configs[i].allow_borrowing,
         info.tpl_configs[i].allow_request_buffering,
         info.tpl_configs[i].max_buffered_requests,
         info.tpl_configs[i].max_request_buffer_size
         ACE_ENV_ARG_PARAMETER);
      ACE_CHECK;                // Simply pass back the exception here
                                // for now.  We need to have a better way
                                // to handle execption here.

      if (this->threadpool_map_.bind (info.tpl_configs[i].name.in (),
                                      thr_id) != 0)
        {
          ACE_DEBUG ((LM_DEBUG, "Error binding thread pool name: %s to map when initializing RTComponentServer resources.\n", info.tpl_configs[i].name.in ()));
          ACE_THROW (CORBA::INTERNAL ());
        }
    }

  for (i = 0; i < info.pb_configs.length (); ++i)
    {
      RTCORBA::PriorityBands_var safebands = new RTCORBA::PriorityBands;

      safebands = info.pb_configs[i].bands;

      if (this->priority_bands_map_.bind (info.pb_configs[i].name.in (),
                                          safebands) != 0)
        {
          ACE_DEBUG ((LM_DEBUG, "Error binding priority bands name: %s to map when initializing RTComponentServer resources.\n", info.pb_configs[i].name.in ()));
          ACE_THROW (CORBA::INTERNAL ());
        }
    }
}

void
CIAO::RTResource_Config_Manager::fini (ACE_ENV_SINGLE_ARG_DECL)
  ACE_THROW_SPEC ((CORBA::SystemException))
{
  TP_MAP::ITERATOR iter = this->threadpool_map_.begin ();
  TP_MAP::ITERATOR end = this->threadpool_map_.end ();

  for (; iter != end; ++iter)
    {
      this->rtorb_->destroy_threadpool ((*iter).int_id_
                                        ACE_ENV_ARG_PARAMETER);
      ACE_CHECK;
    }

}

RTCORBA::ThreadpoolId
CIAO::RTResource_Config_Manager::find_threadpool_by_name (const char *name
                                                          ACE_ENV_ARG_DECL)
  ACE_THROW_SPEC ((CORBA::SystemException))
{
  if (name == 0)
    {
      ACE_DEBUG ((LM_DEBUG,
                  "Invalid name string found in \"find_threadpool_by_name\"\n"));
      ACE_THROW_RETURN (CORBA::INTERNAL (), 0);
    }


  RTCORBA::ThreadpoolId ret_id;    // return id

  if (this->threadpool_map_.find (name, ret_id) != 0)
    {
      ACE_DEBUG ((LM_DEBUG,
                  "Unable to find a threadpool named %s\n",
                  name));
      ACE_THROW_RETURN (CORBA::INTERNAL (), 0);
    }

  return ret_id;
}

RTCORBA::PriorityBands *
CIAO::RTResource_Config_Manager::find_priority_bands_by_name (const char *name
                                                              ACE_ENV_ARG_DECL)
  ACE_THROW_SPEC ((CORBA::SystemException))
{
  if (name == 0)
    {
      ACE_DEBUG ((LM_DEBUG,
                  "Invalid name string found in \"find_priority_bands_by_name\"\n"));
      ACE_THROW_RETURN (CORBA::INTERNAL (), 0);
    }

  PB_MAP::ENTRY *entry;

  if (this->priority_bands_map_.find (name, entry) != 0)
    {
      ACE_DEBUG ((LM_DEBUG,
                  "Unable to find a connection bands named %s\n",
                  name));
      ACE_THROW_RETURN (CORBA::INTERNAL (), 0);
    }

  RTCORBA::PriorityBands_var retv = new RTCORBA::PriorityBands;
  (*retv.ptr ()) = (*entry->int_id_.ptr ());
  return retv._retn ();
}

void
CIAO::RTPolicy_Set_Manager::init (const CIAO::RTConfiguration::Policy_Sets &sets
                                  ACE_ENV_ARG_DECL)
  ACE_THROW_SPEC ((CORBA::SystemException))
{
  if (CIAO::debug_level () > 10)
    ACE_DEBUG ((LM_DEBUG, "RTPolicy_Set_Manager::init\n"));

  for (CORBA::ULong i = 0; i < sets.length (); ++i)
    {
      CORBA::ULong np = sets[i].configs.length ();
      if (np == 0)
        continue;

      CORBA::PolicyList_var policy_list = new CORBA::PolicyList (np);
      policy_list->length (np);

      // Create a list of policies
      for (CORBA::ULong pc = 0; pc < np; ++pc)
        {
          policy_list[pc] = this->create_single_policy (sets[i].configs[pc]
                                                        ACE_ENV_ARG_PARAMETER);
          ACE_CHECK;
        }

      // Bind the policy list to the name.  The bind operation should
      // surrender the ownership of the newly created PolicyList
      // sequence to the map.
      if (this->policy_map_.bind (sets[i].name.in (),
                                  policy_list) != 0)
        {
          ACE_DEBUG ((LM_DEBUG,
                      "Error binding Policy_Set with name: %s\n",
                      sets[i].name.in ()));
          ACE_THROW (CORBA::INTERNAL ());
        }
    }
}

void
CIAO::RTPolicy_Set_Manager::fini (ACE_ENV_SINGLE_ARG_DECL_NOT_USED)
  ACE_THROW_SPEC ((CORBA::SystemException))
{
  // We are keeping the PolicyList in var variables in the map.
  // There's no need to release them explicitly.
}

CORBA::PolicyList *
CIAO::RTPolicy_Set_Manager::find_policies_by_name (const char *name
                                                   ACE_ENV_ARG_DECL)
  ACE_THROW_SPEC ((CORBA::SystemException))
{
  if (name == 0)
    {
      ACE_DEBUG ((LM_DEBUG,
                  "Invalid name string found in \"find_policies_by_name\"\n"));
      ACE_THROW_RETURN (CORBA::INTERNAL (), 0);
    }


  POLICY_MAP::ENTRY *entry;

  if (this->policy_map_.find (name, entry) != 0)
    {
      ACE_DEBUG ((LM_DEBUG,
                  "Unable to find a PolicyList named %s\n",
                  name));
      ACE_THROW_RETURN (CORBA::INTERNAL (), 0);
    }

  // duplicate the sequence PolicyList.
  CORBA::PolicyList_var retv =
    new CORBA::PolicyList (entry->int_id_.in ());

  return retv._retn ();
}

CORBA::Policy_ptr
CIAO::RTPolicy_Set_Manager::create_single_policy
(const CIAO::RTConfiguration::Policy_Config &policy_config
 ACE_ENV_ARG_DECL)
  ACE_THROW_SPEC ((CORBA::SystemException))
{
  if (CIAO::debug_level () > 10)
    ACE_DEBUG ((LM_DEBUG, "RTPolicy_Set_Manager::create_single_policy\n"));

  CORBA::Policy_var retv;

  switch (policy_config.type)
    {
    case RTCORBA::PRIORITY_MODEL_POLICY_TYPE:
      CIAO::RTConfiguration::Priority_Model_Config *tmp;

      if (policy_config.configuration >>= tmp)
        {
          retv = this->rtorb_->create_priority_model_policy (tmp->model,
                                                             tmp->default_priority
                                                             ACE_ENV_ARG_PARAMETER);
          ACE_CHECK_RETURN (0);
        }
      else
        {
          ACE_DEBUG ((LM_DEBUG,
                      "Error extracting PriorityModelPolicy configuration\n"));
          ACE_THROW_RETURN (CORBA::INTERNAL (), 0);
        }
      break;

    case RTCORBA::THREADPOOL_POLICY_TYPE:
      {
        const char *idref;
        policy_config.configuration >>= idref;
        RTCORBA::ThreadpoolId tpid =
          this->resource_manager_.find_threadpool_by_name (idref
                                                           ACE_ENV_ARG_PARAMETER);
        ACE_CHECK_RETURN (0);

        retv = this->rtorb_->create_threadpool_policy (tpid
                                                       ACE_ENV_ARG_PARAMETER);
        ACE_CHECK_RETURN (0);
      }
      break;

    case RTCORBA::PRIORITY_BANDED_CONNECTION_POLICY_TYPE:
      {
        const char *idref;
        policy_config.configuration >>= idref;
        RTCORBA::PriorityBands_var bands =
          this->resource_manager_.find_priority_bands_by_name (idref
                                                           ACE_ENV_ARG_PARAMETER);
        ACE_CHECK_RETURN (0);

        retv = 
          this->rtorb_->create_priority_banded_connection_policy (bands.in ()
                                                                  ACE_ENV_ARG_PARAMETER);
        ACE_CHECK_RETURN (0);
      }
      break;

    default:
      ACE_DEBUG ((LM_DEBUG,
                  "Invalid policy type - RTPolicy_Set_Manager::create_single_policy\n"));
      ACE_THROW_RETURN (CORBA::INTERNAL (), 0);
    }

  return retv._retn ();
}