Merge pull request #1844 from jrw972/monterey
[ACE_TAO.git] / TAO / orbsvcs / ImplRepo_Service / Server_Info.cpp
blob293d0f9511ac953e6f2a97bcd232694f7730ce12
1 #include "Server_Info.h"
3 Server_Info::Server_Info (void)
5 this->clear ();
8 Server_Info::Server_Info (const Server_Info &other)
10 *this = other;
13 Server_Info&
14 Server_Info::operator= (const Server_Info &other)
16 if (this != &other)
18 server_id = other.server_id;
19 poa_name = other.poa_name;
20 is_jacorb = other.is_jacorb;
21 key_name_ = other.key_name_;
22 activator = other.activator;
23 cmdline = other.cmdline;
24 dir = other.dir;
25 activation_mode_ = other.activation_mode_;
26 start_limit_ = other.start_limit_;
27 start_count_ = other.start_count_;
28 partial_ior = other.partial_ior;
29 ior = other.ior;
30 last_ping = other.last_ping;
31 server = other.server;
32 alt_info_ = other.alt_info_;
33 pid = other.pid;
34 death_notify = other.death_notify;
35 peers = other.peers;
36 env_vars = other.env_vars;
38 return *this;
41 Server_Info::Server_Info (const ACE_CString& fqname,
42 const ACE_CString& aname,
43 const ACE_CString& cmdline,
44 const ImplementationRepository::EnvironmentList& env,
45 const ACE_CString& working_dir,
46 ImplementationRepository::ActivationMode amode,
47 int limit,
48 const ACE_CString& partial_ior,
49 const ACE_CString& server_ior,
50 ImplementationRepository::ServerObject_ptr svrobj)
51 : server_id ()
52 , poa_name ()
53 , is_jacorb (false)
54 , key_name_ ()
55 , activator (aname)
56 , cmdline( cmdline)
57 , env_vars (env)
58 , dir (working_dir)
59 , activation_mode_ (amode)
60 , start_limit_ (1)
61 , start_count_ (0)
62 , partial_ior (partial_ior)
63 , ior (server_ior)
64 , server(ImplementationRepository::ServerObject::_duplicate (svrobj))
65 , peers ()
66 , alt_info_ ()
67 , pid (0)
68 , death_notify (false)
70 this->is_jacorb = parse_id (fqname.c_str(), this->server_id, this->poa_name);
71 Server_Info::gen_key (this->server_id, this->poa_name, this->key_name_);
72 this->start_limit (limit);
75 Server_Info::Server_Info (const ACE_CString& serverId,
76 const ACE_CString& pname,
77 bool jacorb,
78 Server_Info_Ptr alt)
79 : server_id (serverId)
80 , poa_name (pname)
81 , is_jacorb (jacorb)
82 , key_name_ ()
83 , activator ("")
84 , cmdline ("")
85 , env_vars ()
86 , dir ("")
87 , activation_mode_ (ImplementationRepository::NORMAL)
88 , start_limit_ (1)
89 , start_count_ (0)
90 , partial_ior ("")
91 , ior ("")
92 , server (ImplementationRepository::ServerObject::_nil())
93 , peers ()
94 , alt_info_ (alt)
95 , pid (0)
96 , death_notify (false)
98 Server_Info::gen_key (this->server_id, this->poa_name, this->key_name_);
101 Server_Info *
102 Server_Info::active_info (void)
104 return this->alt_info_.null() ? this : this->alt_info_.get();
107 const Server_Info *
108 Server_Info::active_info (void) const
110 return this->alt_info_.null() ? this : this->alt_info_.get();
113 void
114 Server_Info::start_limit (int lim)
116 this->active_info ()->start_limit_ = lim < 0 ? -lim : (lim == 0 ? 1 : lim);
119 bool
120 Server_Info::is_mode (ImplementationRepository::ActivationMode m) const
122 return this->active_info ()->activation_mode_ == m;
125 ImplementationRepository::ActivationMode
126 Server_Info::mode (void) const
128 return this->active_info ()->activation_mode_;
131 bool
132 Server_Info::has_peer (const char *name) const
134 return (this->key_name_ == name || this->poa_name == name);
137 bool
138 Server_Info::is_server (const char *name) const
140 for (CORBA::ULong i = 0; i < peers.length(); i++)
142 if (ACE_OS::strcmp (peers[i], name) == 0)
143 return true;
145 return false;
148 bool
149 Server_Info::is_running (void) const
151 return !CORBA::is_nil (this->server.in()) || this->ior.length () > 0;
154 bool
155 Server_Info::start_allowed (void)
157 Server_Info *active = this->active_info ();
158 bool allowed = active->start_count_ < active->start_limit_;
159 if (allowed)
161 active->start_count_++;
163 return allowed;
166 void
167 Server_Info::started (bool success)
169 Server_Info *active = this->active_info ();
170 if (success)
172 active->start_count_ = 0;
176 bool
177 Server_Info::parse_id (const char* id,
178 ACE_CString& server_id,
179 ACE_CString& pname)
181 pname = id;
182 server_id.clear ();
183 size_t idx = pname.find (':');
184 if (idx == ACE_CString::npos)
186 return false;
188 server_id = pname.substr (0, idx);
189 pname = pname.substr (idx + 1);
190 if (server_id != "JACORB")
192 return false;
194 idx = pname.find ('/');
195 if (idx == ACE_CString::npos)
197 server_id.clear ();
199 else
201 server_id = pname.substr (0, idx);
202 pname = pname.substr (idx + 1);
204 return true;
207 void
208 Server_Info::gen_id (const Server_Info * si, ACE_CString &id)
210 char sep = ':';
211 id = "";
212 if (si->is_jacorb)
214 id = "JACORB:";
215 sep = '/';
217 if (si->server_id.length() > 0)
219 id += si->server_id + sep;
221 id += si->poa_name;
224 void
225 Server_Info::gen_key (const ACE_CString& serverId,
226 const ACE_CString& poa_name,
227 ACE_CString &key)
229 if (serverId.length () > 0)
231 key = serverId + ":" + poa_name;
233 else
235 key = poa_name;
239 void
240 Server_Info::fqname_to_key (const char * fqname, ACE_CString& key)
242 ACE_CString serverId;
243 ACE_CString poa_name;
245 Server_Info::parse_id (fqname, serverId, poa_name);
246 Server_Info::gen_key (serverId, poa_name, key);
249 void
250 Server_Info::setImRInfo (ImplementationRepository::ServerInformation* info) const
252 ACE_CString id;
253 Server_Info::gen_id (this, id);
254 info->server = id.c_str();
255 const Server_Info *startup = this->active_info ();
256 info->startup.command_line = startup->cmdline.c_str ();
257 info->startup.environment = startup->env_vars;
258 info->startup.working_directory = startup->dir.c_str ();
259 info->startup.activation = startup->activation_mode_;
260 info->startup.activator = startup->activator.c_str ();
261 info->startup.start_limit =
262 startup->start_count_ >= startup->start_limit_ ? -startup->start_limit_ : startup->start_limit_;
263 info->partial_ior = partial_ior.c_str();
264 info->activeStatus = ImplementationRepository::ACTIVE_MAYBE;
267 ImplementationRepository::ServerInformation*
268 Server_Info::createImRServerInfo (void) const
270 ImplementationRepository::ServerInformation* info;
271 ACE_NEW_THROW_EX (info,
272 ImplementationRepository::ServerInformation,
273 CORBA::NO_MEMORY ());
274 this->setImRInfo (info);
276 return info;
279 void
280 Server_Info::clear (void)
282 server_id = "";
283 poa_name = "";
284 is_jacorb = false;
285 key_name_ = "";
286 activator = "";
287 cmdline = "";
288 env_vars.length (0);
289 dir = "";
290 activation_mode_ = ImplementationRepository::NORMAL;
291 start_limit_ = 1;
292 start_count_ = 0;
293 partial_ior = "";
294 ior = "";
295 last_ping = ACE_Time_Value::zero;
296 server = ImplementationRepository::ServerObject::_nil ();
297 peers.length (0);
298 alt_info_.reset ();
299 pid = 0;
300 death_notify = false;
303 void
304 Server_Info::reset_runtime (void)
306 this->partial_ior = "";
307 Server_Info *startup = this->active_info ();
308 startup->ior = "";
309 startup->death_notify = false;
310 startup->last_ping = ACE_Time_Value::zero;
311 startup->server = ImplementationRepository::ServerObject::_nil ();
314 void
315 Server_Info::update_options (const ImplementationRepository::StartupOptions &options)
317 Server_Info *startup = this->active_info ();
318 startup->activator = options.activator.in ();
319 startup->cmdline = options.command_line.in ();
320 startup->env_vars = options.environment;
321 startup->dir = options.working_directory.in ();
322 startup->activation_mode_ = options.activation;
323 startup->start_limit (options.start_limit);
324 startup->start_count_ = 0;
327 const char *
328 Server_Info::ping_id (void) const
330 return this->active_info ()->key_name_.c_str();
333 void
334 Server_Info::set_contact (const char *pior,
335 const char *srv_ior,
336 ImplementationRepository::ServerObject_ptr svrobj)
338 this->partial_ior = pior;
339 Server_Info *startup = this->active_info ();
340 startup->ior = srv_ior;
341 startup->server = ImplementationRepository::ServerObject::_duplicate (svrobj);