summaryrefslogtreecommitdiff
path: root/TAO/orbsvcs/ImplRepo_Service/Repository.cpp
blob: 20ccae97f13dd5b2d74ea18fb7547054da7579a6 (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
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
/* -*- C++ -*- */
// $Id$
#include "Repository.h"
#include "Options.h"
#include "ace/ACE.h"

// Initialize the command_line and working_dir.

Server_Info::Server_Info (
    const ACE_TString POA_name,
    const ACE_TString logical_server_name,
    const ACE_TString startup_command,
    const ImplementationRepository::EnvironmentList environment_vars,
    const ACE_TString working_dir,
    const ImplementationRepository::ActivationMode activation
  )
: starting_up_ (0),
  logical_server_name_ (logical_server_name),
  POA_name_ (POA_name),
  startup_command_ (startup_command),
  environment_vars_ (environment_vars),
  working_dir_ (working_dir),
  location_ (""),
  server_object_ior_ (""),
  activation_ (activation)
{
  // Nothing
}


Server_Info::~Server_Info ()
{
  // Nothing
}


// Updates information that is relevant only when an instance
// of the server is running.

void
Server_Info::update_running_info (const ACE_TString location,
                                  const ACE_TString server_object_ior)
{
  this->location_ = location;
  this->server_object_ior_ = server_object_ior;
}


// Returns startup information.

void
Server_Info::get_startup_info (
    ACE_TString &logical_server_name,
    ACE_TString &startup_command,
    ImplementationRepository::EnvironmentList &environment_vars,
    ACE_TString &working_dir,
    ImplementationRepository::ActivationMode &activation
  )
{
  logical_server_name = this->logical_server_name_;
  startup_command = this->startup_command_;
  environment_vars = this->environment_vars_;
  working_dir = this->working_dir_;
  activation = this->activation_;
}


// Returns information about a running instance.

void
Server_Info::get_running_info (ACE_TString &location,
                               ACE_TString &server_object_ior)
{
  location = this->location_;
  server_object_ior = this->server_object_ior_;
}


// Default Constructor

Server_Repository::Server_Repository ()
{
  // Nothing
}


// Destructor

Server_Repository::~Server_Repository ()
{
  // Nothing
}


// Initialize the the configuration class.

int
Server_Repository::init ()
{
  ACE_Configuration *config = OPTIONS::instance ()->config ();

  // iterate through the list of registered servers and register them
  config->open_section (config->root_section (), 
                        ACE_LIB_TEXT("Servers"),
                        1, 
                        this->servers_);
  int index = 0;
  ACE_TString name;
 
  while (config->enumerate_sections (servers_, index, name) == 0)
    {
      ACE_TString logical, startup, working_dir;
      u_int activation_val = 0;
      ImplementationRepository::ActivationMode activation;

      ImplementationRepository::EnvironmentList environment_vars;

      ACE_Configuration_Section_Key server_key;
      int error = 0;
   
      error += config->open_section (this->servers_, 
                                     name.c_str(), 
                                     0, 
                                     server_key);

      error += config->get_string_value (server_key, 
                                         ACE_LIB_TEXT("LogicalServer"),
                                         logical);

      error += config->get_string_value (server_key, 
                                         ACE_LIB_TEXT("StartupCommand"),
                                         startup);

      error += config->get_string_value (server_key, 
                                         ACE_LIB_TEXT("WorkingDir"),
                                         working_dir);

      error += config->get_integer_value (server_key, 
                                          ACE_LIB_TEXT("Activation"),
                                          activation_val);

      activation =
        ACE_static_cast (ImplementationRepository::ActivationMode, activation_val);

      // Maybe environments variables?? need a straightforward 
      // way to store env vars.

      if (error != 0)
        {
          ACE_DEBUG ((LM_DEBUG, 
                      ACE_TEXT ("Error reading configuration data for ")
                      ACE_TEXT ("service '%s',skipping\n"), 
                      name.c_str ()));
        }
      else
        {
          this->add (name, 
                     logical, 
                     startup, 
                     environment_vars, 
                     working_dir, 
                     activation);
        }

      index++;
    }

  return 0;
}


// Add a new server to the Repository

int
Server_Repository::add (
    const ACE_TString POA_name,
    const ACE_TString logical_server_name,
    const ACE_TString startup_command,
    const ImplementationRepository::EnvironmentList environment_vars,
    const ACE_TString working_dir,
    const ImplementationRepository::ActivationMode activation
  )
{
  ACE_Configuration *config = OPTIONS::instance ()->config ();
  
  // @@ Add this to the persistent configuration; environment_vars??
  ACE_Configuration_Section_Key server;
  config->open_section (this->servers_, 
                        POA_name.c_str(), 
                        1, 
                        server);

  config->set_string_value (server, 
                            ACE_LIB_TEXT("LogicalServer"),
                            logical_server_name);

  config->set_string_value (server, 
                            ACE_LIB_TEXT("StartupCommand"),
                            startup_command);

  config->set_string_value (server, 
                            ACE_LIB_TEXT("WorkingDir"),
                            working_dir);

  config->set_integer_value (server, 
                             ACE_LIB_TEXT("Activation"),
                             activation);

  Server_Info *new_server = 0;
  ACE_NEW_RETURN (new_server,
                  Server_Info (POA_name,
                               logical_server_name,
                               startup_command,
                               environment_vars,
                               working_dir,
                               activation),
                  -1);

  return this->repository_.bind (POA_name, 
                                 new_server);
}


// Update the associated process information.

int
Server_Repository::update (const ACE_TString POA_name,
                           const ACE_TString location,
                           const ACE_TString server_object_ior)
{
  Server_Info *server;
  int retval = this->repository_.find (POA_name, 
                                       server);

  // Only fill in data if it was found
  if (retval == 0)
    {
      server->update_running_info (location, 
                                   server_object_ior);
    }

  return retval;
}


// Returns information related to startup.

int
Server_Repository::get_startup_info (
    const ACE_TString POA_name,
    ACE_TString &logical_server_name,
    ACE_TString &startup_command,
    ImplementationRepository::EnvironmentList &environment_vars,
    ACE_TString &working_dir,
    ImplementationRepository::ActivationMode &activation
  )
{
  Server_Info *server;
  int retval = this->repository_.find (POA_name, server);

  // Only fill in data if it was found
  if (retval == 0)
    {
      server->get_startup_info (logical_server_name, 
                                startup_command, 
                                environment_vars, 
                                working_dir, 
                                activation);
    }

  return retval;
}


// Returns information related to a running copy.

int
Server_Repository::get_running_info (const ACE_TString POA_name,
                                     ACE_TString &location,
                                     ACE_TString &server_object_ior)
{
  Server_Info *server;
  int retval = this->repository_.find (POA_name, 
                                       server);

  // Only fill in data if it was found
  if (retval == 0)
    {
      server->get_running_info (location, 
                                server_object_ior);
    }

  return retval;
}


// Checks the starting_up_ variable in the Server_Info and
// returns the previous value or -1 if the POA_name wasn't found

int
Server_Repository::starting_up (const ACE_TString POA_name, 
                                int new_value)
{
  Server_Info *server;
  int retval = this->repository_.find (POA_name, 
                                       server);

  // Only fill in data if it was found
  if (retval == 0)
  {
    retval = server->starting_up_;
    server->starting_up_ = new_value;
  }

  return retval;
}


// Same as above but does not alter the value

int
Server_Repository::starting_up (const ACE_TString POA_name)
{
  Server_Info *server;
  int retval = this->repository_.find (POA_name, 
                                       server);

  // Only fill in data if it was found
  if (retval == 0)
    {
      retval = server->starting_up_;
    }

  return retval;
}


// Removes the server from the Repository.

int
Server_Repository::remove (const ACE_TString POA_name)
{
  ACE_Configuration *config = OPTIONS::instance ()->config ();

  // Remove the persistent configuration information
  config->remove_section (this->servers_, 
                          POA_name.c_str(), 
                          1);

  return this->repository_.unbind (POA_name);
}


// Returns a new iterator that travels over the repository.

Server_Repository::HASH_IMR_ITER *
Server_Repository::new_iterator (void)
{
  HASH_IMR_ITER *hash_iter = 0;
  ACE_NEW_RETURN (hash_iter,
                  Server_Repository::HASH_IMR_ITER (this->repository_),
                  0);

  return hash_iter;
}


// Returns the number of entries in the repository.

size_t
Server_Repository::get_repository_size (void)
{
  return this->repository_.current_size ();
}


#if defined (ACE_HAS_EXPLICIT_TEMPLATE_INSTANTIATION)

template class ACE_Hash_Map_Entry<ACE_TString, Server_Info *>;
template class ACE_Hash_Map_Manager_Ex<ACE_TString, Server_Info *,ACE_Hash<ACE_CString>, ACE_Equal_To<ACE_TString>, ACE_Null_Mutex>;
template class ACE_Hash_Map_Iterator_Base_Ex<ACE_TString, Server_Info *,ACE_Hash<ACE_TString>, ACE_Equal_To<ACE_TString>, ACE_Null_Mutex>;
template class ACE_Hash_Map_Iterator_Ex<ACE_TString, Server_Info *,ACE_Hash<ACE_TString>, ACE_Equal_To<ACE_TString>, ACE_Null_Mutex>;
template class ACE_Hash_Map_Reverse_Iterator_Ex<ACE_TString, Server_Info *,ACE_Hash<ACE_TString>, ACE_Equal_To<ACE_TString>, ACE_Null_Mutex>;

#if defined(__SUNPRO_CC) && (__SUNPRO_CC == 0x500)
// This template is already defined in TAO, but Sun/CC 5.0 is broken
template class ACE_Equal_To<ACE_CString>;
#endif /* __SUNPRO_CC */
// Instantiate for ACE_WString because ACE_TString can be either
// ACE_CString or ACE_WString.
template class ACE_Equal_To<ACE_WString>;

#elif defined (ACE_HAS_TEMPLATE_INSTANTIATION_PRAGMA)

#pragma instantiate ACE_Hash_Map_Entry<ACE_TString, Server_Info *>
#pragma instantiate ACE_Hash_Map_Manager_Ex<ACE_CString, Server_Info *,ACE_Hash<ACE_TString>, ACE_Equal_To<ACE_TString>, ACE_Null_Mutex>
#pragma instantiate ACE_Hash_Map_Iterator_Base_Ex<ACE_CString, Server_Info *,ACE_Hash<ACE_TString>, ACE_Equal_To<ACE_TString>, ACE_Null_Mutex>
#pragma instantiate ACE_Hash_Map_Iterator_Ex<ACE_TString, Server_Info *,ACE_Hash<ACE_TString>, ACE_Equal_To<ACE_TString>, ACE_Null_Mutex>
#pragma instantiate ACE_Hash_Map_Reverse_Iterator_Ex<ACE_TString, Server_Info *,ACE_Hash<ACE_TString>, ACE_Equal_To<ACE_TString>, ACE_Null_Mutex>

#if defined(__SUNPRO_CC) && (__SUNPRO_CC == 0x500)
// This template is already defined in TAO, but Sun/CC 5.0 is broken
#pragma instantiate ACE_Equal_To<ACE_CString>
#endif /* __SUNPRO_CC */
// Instantiate for ACE_WString because ACE_TString can be either
// ACE_CString or ACE_WString.
#pragma instantiate ACE_Equal_To<ACE_WString>

#endif /* ACE_HAS_EXPLICIT_TEMPLATE_INSTANTIATION */