summaryrefslogtreecommitdiff
path: root/TAO/orbsvcs/ImplRepo_Service/Repository.cpp
blob: 10da79c6d8790013116ffe04fc8a586523b12df6 (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
/* -*- C++ -*- */
// $Id$
#include "Repository.h"
#include "Options.h"
#include "ace/ACE.h"

ACE_RCSID(ImplRepo_Service, Repository, "$Id$")



// 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 ACE_TString working_dir)
: starting_up_ (0),
  logical_server_name_ (logical_server_name),
  POA_name_ (POA_name),
  startup_command_ (startup_command),
  working_dir_ (working_dir),
  host_ (""),
  port_ (0),
  server_object_ior_ ("")
{
  // 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 host,
                                  const unsigned short port,
                                  const ACE_TString server_object_ior)
{
  this->host_ = host;
  this->port_ = port;
  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,
                               ACE_TString &working_dir)
{
  logical_server_name = this->logical_server_name_;
  startup_command = this->startup_command_;
  working_dir = this->working_dir_;
}


// Returns information about a running instance.

void
Server_Info::get_running_info (ACE_TString &host,
                               unsigned short &port,
                               ACE_TString &server_object_ior)
{
  host = this->host_;
  port = this->port_;
  server_object_ior = this->server_object_ior_;
}

// Default Constructor

Server_Repository::Server_Repository ()
{
  // Nothing
}


// 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 ACE_TString working_dir)
{
  Server_Info *new_server;
  ACE_NEW_RETURN (new_server,
                  Server_Info (POA_name, logical_server_name, startup_command, working_dir),
                  -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 host,
                           const unsigned short port,
                           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 (host, port, 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,
                                     ACE_TString &working_dir)
{
  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, working_dir);

  return retval;
}


// Returns information related to a running copy.

int
Server_Repository::get_running_info (const ACE_TString POA_name,
                                     ACE_TString &host,
                                     unsigned short &port,
                                     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 (host, port, 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)
{
  return this->repository_.unbind (POA_name);
}


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

Server_Repository::HASH_IR_ITER *
Server_Repository::new_iterator ()
{
  HASH_IR_ITER *hash_iter;
  ACE_NEW_RETURN (hash_iter,
                  Server_Repository::HASH_IR_ITER (this->repository_),
                  0);
  return hash_iter;
}


// Returns the number of entries in the repository.

size_t
Server_Repository::get_repository_size ()
{
  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>;
// The ACE_CString case is covered in TAO
template class ACE_Equal_To<ACE_CString>;

#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>
// The ACE_CString case is covered in TAO
#pragma instantiate ACE_Equal_To<ACE_CString>

#endif /* ACE_HAS_EXPLICIT_TEMPLATE_INSTANTIATION */