summaryrefslogtreecommitdiff
path: root/TAO/orbsvcs/ImplRepo_Service/Repository.cpp
blob: d85e2e0fa7ee19fc274d2d2f4170163d68794e10 (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$
#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),
  ping_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 ping_ior)
{
  this->host_ = host;
  this->port_ = port;
  this->ping_ior_ = ping_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 &ping_ior)
{
  host = this->host_;
  port = this->port_;
  ping_ior = this->ping_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 ping_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, ping_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 &ping_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, ping_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);
}
  

#if defined (ACE_HAS_EXPLICIT_TEMPLATE_INSTANTIATION)
template class ACE_Hash_Map_Reverse_Iterator_Ex<ACE_TString, Repository_Record *, ACE_Hash<ACE_TString>, ACE_Equal_To<ACE_TString>, ACE_Null_Mutex>;
#elif defined (ACE_HAS_TEMPLATE_INSTANTIATION_PRAGMA)
#pragma instantiate ACE_Hash_Map_Reverse_Iterator_Ex<ACE_TString, Repository_Record *, ACE_Hash<ACE_TString>, ACE_Equal_To<ACE_TString>, ACE_Null_Mutex>;
#endif /* ACE_HAS_EXPLICIT_TEMPLATE_INSTANTIATION */