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
|
//
// $Id$
//
#include "Process_Factory.h"
#include "Startup_Callback.h"
#include "ace/Process.h"
ACE_RCSID(Client_Leaks, Process_Factory, "$Id$")
Process_Factory::Process_Factory (CORBA::ORB_ptr orb)
: orb_ (CORBA::ORB::_duplicate (orb))
, shutdown_received_ (0)
{
}
int
Process_Factory::shutdown_received (void)
{
return this->shutdown_received_;
}
Test::Process_ptr
Process_Factory::create_new_process (ACE_ENV_SINGLE_ARG_DECL)
ACE_THROW_SPEC ((CORBA::SystemException,Test::Spawn_Failed))
{
Startup_Callback *startup_callback_impl;
ACE_NEW_THROW_EX (startup_callback_impl,
Startup_Callback,
CORBA::NO_MEMORY ());
ACE_CHECK_RETURN (Test::Process::_nil ());
PortableServer::ServantBase_var owner_transfer(startup_callback_impl);
Test::Startup_Callback_var startup_callback =
startup_callback_impl->_this (ACE_ENV_SINGLE_ARG_PARAMETER);
ACE_CHECK_RETURN (Test::Process::_nil ());
CORBA::String_var ior =
this->orb_->object_to_string (startup_callback.in () ACE_ENV_ARG_PARAMETER);
ACE_CHECK_RETURN (Test::Process::_nil ());
ACE::String_Conversion::Convert_In<ACE_TCHAR, ACE_ANTI_TCHAR > tchar_ior( ior.in () );
const ACE_TCHAR* argv[3] = {
ACE_TEXT("child"),
tchar_ior.c_str (),
0};
ACE_Process_Options options;
#if !defined(ACE_WIN32)
options.avoid_zombies (1);
#endif /* ACE_WIN32 */
options.command_line (argv);
ACE_Process child_process;
pid_t pid =
child_process.spawn (options);
if (pid == -1)
{
ACE_DEBUG ((LM_DEBUG,
"(%P|%t) Process_Factory::create_new_process, "
" spawn call failed (%d)\n",
errno));
ACE_THROW_RETURN (Test::Spawn_Failed (), Test::Process::_nil ());
}
int process_has_started = 0;
Test::Process_var the_process;
for (int i = 0; i != 500 && !process_has_started; ++i)
{
ACE_Time_Value interval (0, 10000);
this->orb_->perform_work (interval ACE_ENV_ARG_PARAMETER);
ACE_CHECK_RETURN (Test::Process::_nil ());
process_has_started =
startup_callback_impl->process_has_started (the_process.out ());
}
ACE_TRY
{
PortableServer::POA_var poa =
startup_callback_impl->_default_POA (ACE_ENV_SINGLE_ARG_PARAMETER);
ACE_TRY_CHECK;
PortableServer::ObjectId_var id =
poa->servant_to_id (startup_callback_impl ACE_ENV_ARG_PARAMETER);
ACE_TRY_CHECK;
poa->deactivate_object (id.in () ACE_ENV_ARG_PARAMETER);
ACE_TRY_CHECK;
}
ACE_CATCHANY
{
}
ACE_ENDTRY;
if (process_has_started == 0)
{
ACE_DEBUG ((LM_DEBUG,
"(%P|%t) Process_Factory::create_new_process, "
" timeout while waiting for child\n"));
(void) child_process.terminate ();
ACE_THROW_RETURN (Test::Spawn_Failed (), Test::Process::_nil ());
}
return the_process._retn ();
}
void
Process_Factory::noop (ACE_ENV_SINGLE_ARG_DECL_NOT_USED)
ACE_THROW_SPEC ((CORBA::SystemException))
{
}
void
Process_Factory::shutdown (ACE_ENV_SINGLE_ARG_DECL)
ACE_THROW_SPEC ((CORBA::SystemException))
{
this->shutdown_received_ = 1;
this->orb_->shutdown (0 ACE_ENV_ARG_PARAMETER);
}
|