1 #include "orbsvcs/Log_Macros.h"
2 #include "Config_Backing_Store.h"
3 #include "Server_Info.h"
4 #include "Activator_Info.h"
6 #include "ace/OS_NS_unistd.h"
8 static const ACE_TCHAR
* STARTUP_COMMAND
= ACE_TEXT("StartupCommand");
9 static const ACE_TCHAR
* WORKING_DIR
= ACE_TEXT("WorkingDir");
10 static const ACE_TCHAR
* ENVIRONMENT
= ACE_TEXT("Environment");
11 static const ACE_TCHAR
* ACTIVATION
= ACE_TEXT("Activation");
12 static const ACE_TCHAR
* PARTIAL_IOR
= ACE_TEXT("Location");
13 static const ACE_TCHAR
* IOR
= ACE_TEXT("IOR");
14 static const ACE_TCHAR
* START_LIMIT
= ACE_TEXT("StartLimit");
15 static const ACE_TCHAR
* ACTIVATOR
= ACE_TEXT("Activator");
16 static const ACE_TCHAR
* SERVERS_ROOT_KEY
= ACE_TEXT("Servers");
17 static const ACE_TCHAR
* ACTIVATORS_ROOT_KEY
= ACE_TEXT("Activators");
18 static const ACE_TCHAR
* TOKEN
= ACE_TEXT("Token");
19 static const ACE_TCHAR
* SERVER_ID
= ACE_TEXT("ServerId");
20 static const ACE_TCHAR
* JACORB_SERVER
= ACE_TEXT("JacORBServer");
21 static const ACE_TCHAR
* ALTKEY
= ACE_TEXT("AltKey");
22 static const ACE_TCHAR
* POA
= ACE_TEXT("POA");
23 static const ACE_TCHAR
* PEERS
= ACE_TEXT("Peers");
24 static const ACE_TCHAR
* CONFIG_PID
= ACE_TEXT("Pid");
25 #if defined (ACE_WIN32) && !defined (ACE_LACKS_WIN32_REGISTRY)
26 static const ACE_TCHAR WIN32_REG_KEY
[] = ACE_TEXT ("Software\\TAO\\ImplementationRepository");
29 Config_Backing_Store::Config_Backing_Store (const Options
& opts
,
31 ACE_Configuration
& config
)
32 : Locator_Repository (opts
, orb
),
38 Config_Backing_Store::~Config_Backing_Store ()
43 int get_cstring_value (ACE_Configuration
&config
,
44 const ACE_Configuration_Section_Key
&key
,
45 const ACE_TCHAR
*name
,
49 const int ret
= config
.get_string_value (key
, name
, tmp
);
52 value
= ACE_TEXT_ALWAYS_CHAR (tmp
.c_str ());
57 int set_cstring_value (ACE_Configuration
&config
,
58 const ACE_Configuration_Section_Key
&key
,
59 const ACE_TCHAR
*name
,
60 const ACE_CString
&value
)
62 return config
.set_string_value (key
, name
, ACE_TEXT_CHAR_TO_TCHAR (value
.c_str ()));
66 void Config_Backing_Store::loadActivators ()
68 ACE_Configuration_Section_Key root
;
70 config_
.open_section (config_
.root_section (), ACTIVATORS_ROOT_KEY
, 0, root
);
75 while (config_
.enumerate_sections (root
, index
, name
) == 0)
80 ACE_Configuration_Section_Key key
;
82 // Can't fail, because we're enumerating
83 config_
.open_section (root
, name
.c_str(), 0, key
);
85 get_cstring_value (this->config_
, key
, IOR
, ior
);
86 config_
.get_integer_value (key
, TOKEN
, token
);
88 const ACE_CString name_cstr
= ACE_TEXT_ALWAYS_CHAR (name
.c_str ());
90 Activator_Info
* ai
= 0;
91 ACE_NEW (ai
, Activator_Info (name_cstr
, token
, ior
));
93 Activator_Info_Ptr
info (ai
);
94 activators ().bind (lcase (name_cstr
), info
);
101 Config_Backing_Store::loadServers ()
103 ACE_Configuration_Section_Key root
;
105 config_
.open_section (config_
.root_section (), SERVERS_ROOT_KEY
, 0, root
);
114 while (config_
.enumerate_sections (root
, index
, name
) == 0)
116 const ACE_CString name_cstr
= ACE_TEXT_ALWAYS_CHAR (name
.c_str ());
117 Server_Info_Ptr info
;
118 if (this->servers ().find (name_cstr
, info
) != 0)
120 ACE_NEW (si
, Server_Info
);
122 si
->key_name_
= name_cstr
;
125 ACE_Configuration_Section_Key key
;
127 // Can't fail, because we're enumerating
128 config_
.open_section (root
, name
.c_str(), 0, key
);
129 if (!get_cstring_value (this->config_
, key
, POA
, si
->poa_name
))
131 si
->poa_name
= si
->key_name_
;
134 // Ignore any missing values. Server name is enough on its own.
135 get_cstring_value (this->config_
, key
, SERVER_ID
, si
->server_id
);
136 get_cstring_value (this->config_
, key
, JACORB_SERVER
, tmp
);
137 si
->is_jacorb
= (tmp
== "1");
138 get_cstring_value (this->config_
, key
, ACTIVATOR
, si
->activator
);
139 get_cstring_value (this->config_
, key
, STARTUP_COMMAND
, si
->cmdline
);
140 get_cstring_value (this->config_
, key
, WORKING_DIR
, si
->dir
);
141 get_cstring_value (this->config_
, key
, ENVIRONMENT
, tmp
);
142 ImR_Utils::stringToEnvList (tmp
, si
->env_vars
);
143 config_
.get_integer_value (key
, ACTIVATION
, tmp_int
);
144 si
->activation_mode_
=
145 static_cast <ImplementationRepository::ActivationMode
> (tmp_int
);
146 get_cstring_value (this->config_
, key
, PARTIAL_IOR
, si
->partial_ior
);
147 get_cstring_value (this->config_
, key
, IOR
, si
->ior
);
148 config_
.get_integer_value (key
, START_LIMIT
, tmp_int
);
149 si
->start_limit_
= tmp_int
;
150 config_
.get_integer_value (key
, CONFIG_PID
, tmp_int
);
152 if (get_cstring_value (this->config_
, key
, ALTKEY
, tmp
))
154 if (tmp
.length () > 0 &&
155 this->servers ().find (tmp
, si
->alt_info_
) != 0)
157 Server_Info
*base_si
= 0;
158 ACE_NEW (base_si
, Server_Info
);
159 base_si
->key_name_
= tmp
;
160 si
->alt_info_
.reset (base_si
);
161 this->servers ().bind (tmp
, si
->alt_info_
);
164 get_cstring_value (this->config_
, key
, PEERS
, tmp
);
165 ImR_Utils::stringToPeerList (tmp
, si
->peers
);
166 this->servers ().bind (name_cstr
, info
);
174 Config_Backing_Store::persistent_remove (const ACE_CString
& name
,
177 const ACE_TCHAR
* const key
=
178 (activator
? ACTIVATORS_ROOT_KEY
: SERVERS_ROOT_KEY
);
179 return remove (name
, key
);
183 Config_Backing_Store::remove (const ACE_CString
& name
, const ACE_TCHAR
* key
)
185 ACE_Configuration_Section_Key root
;
186 int err
= config_
.open_section (config_
.root_section (), key
, 0, root
);
189 if (this->opts_
.debug () > 9)
191 ORBSVCS_DEBUG((LM_INFO
, ACE_TEXT ("could not remove %C, already gone!\n"),
194 return 0; // Already gone.
196 return config_
.remove_section (root
, ACE_TEXT_CHAR_TO_TCHAR (name
.c_str ()), 1);
199 static int get_key (ACE_Configuration
& cfg
, const ACE_CString
& name
,
200 const ACE_TCHAR
* const sub_section
,
201 ACE_Configuration_Section_Key
& key
)
203 ACE_Configuration_Section_Key root
;
204 int err
= cfg
.open_section (cfg
.root_section(), sub_section
, 1, root
);
207 ORBSVCS_ERROR ((LM_ERROR
, ACE_TEXT ("Unable to open config section:%s\n"),
211 err
= cfg
.open_section (root
, ACE_TEXT_CHAR_TO_TCHAR (name
.c_str ()), 1, key
);
214 ORBSVCS_ERROR((LM_ERROR
, ACE_TEXT ("Unable to open config section:%C\n"),
221 Config_Backing_Store::persistent_update (const Server_Info_Ptr
& info
, bool )
223 ACE_Configuration_Section_Key key
;
224 int err
= get_key(this->config_
, info
->key_name_
, SERVERS_ROOT_KEY
, key
);
227 ORBSVCS_ERROR((LM_ERROR
, ACE_TEXT ("ERROR: could not get key for %C\n"),
228 info
->key_name_
.c_str ()));
232 if (this->opts_
.debug() > 9)
234 ORBSVCS_DEBUG((LM_INFO
, ACE_TEXT ("updating %C\n"), info
->poa_name
.c_str()));
236 ACE_CString envstr
= ImR_Utils::envListToString (info
->env_vars
);
237 ACE_CString peerstr
= ImR_Utils::peerListToString (info
->peers
);
239 set_cstring_value (this->config_
, key
, POA
, info
->poa_name
);
240 set_cstring_value (this->config_
, key
, SERVER_ID
, info
->server_id
);
241 set_cstring_value (this->config_
, key
, JACORB_SERVER
, info
->is_jacorb
? "1" : "0");
242 set_cstring_value (this->config_
, key
, ACTIVATOR
, info
->activator
);
243 set_cstring_value (this->config_
, key
, STARTUP_COMMAND
, info
->cmdline
);
244 set_cstring_value (this->config_
, key
, WORKING_DIR
, info
->dir
);
245 set_cstring_value (this->config_
, key
, ENVIRONMENT
, envstr
);
246 this->config_
.set_integer_value (key
, ACTIVATION
, info
->activation_mode_
);
247 this->config_
.set_integer_value (key
, START_LIMIT
, info
->start_limit_
);
248 set_cstring_value (this->config_
, key
, PARTIAL_IOR
, info
->partial_ior
);
249 set_cstring_value (this->config_
, key
, IOR
, info
->ior
);
250 this->config_
.set_integer_value (key
, CONFIG_PID
, info
->pid
);
251 set_cstring_value (this->config_
, key
, ALTKEY
,
252 info
->alt_info_
.null () ? ACE_CString("") : info
->alt_info_
->key_name_
);
253 set_cstring_value (this->config_
, key
, PEERS
, peerstr
);
259 Config_Backing_Store::persistent_update (const Activator_Info_Ptr
& info
, bool )
261 ACE_Configuration_Section_Key key
;
262 int err
= get_key (this->config_
, info
->name
, ACTIVATORS_ROOT_KEY
, key
);
265 ORBSVCS_DEBUG((LM_INFO
,
266 ACE_TEXT ("ERROR: could not get key for activator %C\n"),
267 info
->name
.c_str ()));
271 if (this->opts_
.debug() > 9)
273 ORBSVCS_DEBUG((LM_INFO
, ACE_TEXT ("updating activator %C\n"),
274 info
->name
.c_str ()));
276 this->config_
.set_integer_value (key
, TOKEN
, info
->token
);
277 set_cstring_value (this->config_
, key
, IOR
, info
->ior
.c_str());
283 Config_Backing_Store::init_repo (PortableServer::POA_ptr
)
287 if (this->opts_
.debug () > 9)
289 ORBSVCS_DEBUG ((LM_INFO
, ACE_TEXT ("not loading\n")));
294 this->loadActivators();
300 Heap_Backing_Store::Heap_Backing_Store (const Options
& opts
,
302 : Config_Backing_Store (opts
, orb
, heap_
),
303 filename_ (opts
.persist_file_name())
305 if (opts
.repository_erase ())
307 if (this->opts_
.debug () > 9)
309 ORBSVCS_DEBUG ((LM_INFO
, ACE_TEXT ("Heap start clean\n")));
311 ACE_OS::unlink ( this->filename_
.c_str() );
314 status_
= heap_
.open (this->filename_
.c_str());
317 Heap_Backing_Store::~Heap_Backing_Store ()
322 Heap_Backing_Store::repo_mode() const
324 return this->filename_
.c_str();
327 #if defined (ACE_WIN32) && !defined (ACE_LACKS_WIN32_REGISTRY)
328 static HKEY
setup_registry (const bool start_clean
)
332 ACE_Configuration_Win32Registry
config ( HKEY_LOCAL_MACHINE
);
333 ACE_Configuration_Section_Key root
;
334 config
.open_section (config
.root_section(), ACE_TEXT ("Software\\TAO"), 0, root
);
335 config
.remove_section (root
, ACE_TEXT ("ImplementationRepository"), 1);
338 return ACE_Configuration_Win32Registry::
339 resolve_key (HKEY_LOCAL_MACHINE
, WIN32_REG_KEY
);
343 Registry_Backing_Store::Registry_Backing_Store(const Options
& opts
,
345 #if defined (ACE_WIN32) && !defined (ACE_LACKS_WIN32_REGISTRY)
346 : Config_Backing_Store(opts
, orb
, win32registry_
),
347 win32registry_ (setup_registry (opts
.repository_erase()))
349 : Config_Backing_Store (opts
, orb
, invalid_config_
)
352 #if defined (ACE_WIN32) && !defined (ACE_LACKS_WIN32_REGISTRY)
355 ORBSVCS_ERROR ((LM_ERROR
, ACE_TEXT ("Registry persistence is only ")
356 ACE_TEXT ("supported on Windows\n")));
361 Registry_Backing_Store::~Registry_Backing_Store ()
366 Registry_Backing_Store::repo_mode () const
368 return ACE_TEXT("Registry");