1 #include "Process_Factory.h"
2 #include "Startup_Callback.h"
3 #include "ace/Process.h"
5 Process_Factory::Process_Factory (CORBA::ORB_ptr orb
)
6 : orb_ (CORBA::ORB::_duplicate (orb
))
7 , shutdown_received_ (0)
12 Process_Factory::shutdown_received ()
14 return this->shutdown_received_
;
18 Process_Factory::create_new_process ()
20 Startup_Callback
*startup_callback_impl
;
21 ACE_NEW_THROW_EX (startup_callback_impl
,
25 PortableServer::ServantBase_var
owner_transfer(startup_callback_impl
);
27 CORBA::Object_var poa_object
=
28 this->orb_
->resolve_initial_references("RootPOA");
30 PortableServer::POA_var root_poa
=
31 PortableServer::POA::_narrow (poa_object
.in ());
33 PortableServer::ObjectId_var id
=
34 root_poa
->activate_object (startup_callback_impl
);
36 CORBA::Object_var object
= root_poa
->id_to_reference (id
.in ());
38 Test::Startup_Callback_var startup_callback
=
39 Test::Startup_Callback::_narrow (object
.in ());
41 CORBA::String_var ior
=
42 this->orb_
->object_to_string (startup_callback
.in ());
44 const ACE_TCHAR
* argv
[3] = {
46 ACE_TEXT_CHAR_TO_TCHAR(ior
.in ()),
49 ACE_Process_Options options
;
50 #if !defined(ACE_WIN32)
51 options
.avoid_zombies (1);
52 #endif /* ACE_WIN32 */
53 options
.command_line (argv
);
55 ACE_Process child_process
;
57 child_process
.spawn (options
);
62 "(%P|%t) Process_Factory::create_new_process, "
63 " spawn call failed (%d)\n",
65 throw Test::Spawn_Failed ();
68 int process_has_started
= 0;
69 Test::Process_var the_process
;
70 for (int i
= 0; i
!= 500 && !process_has_started
; ++i
)
72 ACE_Time_Value
interval (0, 10000);
73 this->orb_
->perform_work (interval
);
76 startup_callback_impl
->process_has_started (the_process
.out ());
81 PortableServer::POA_var poa
=
82 startup_callback_impl
->_default_POA ();
83 PortableServer::ObjectId_var id
=
84 poa
->servant_to_id (startup_callback_impl
);
85 poa
->deactivate_object (id
.in ());
87 catch (const CORBA::Exception
&)
91 if (process_has_started
== 0)
94 "(%P|%t) Process_Factory::create_new_process, "
95 " timeout while waiting for child\n"));
96 (void) child_process
.terminate ();
97 throw Test::Spawn_Failed ();
100 return the_process
._retn ();
104 Process_Factory::noop ()
109 Process_Factory::shutdown ()
111 this->shutdown_received_
= 1;
112 this->orb_
->shutdown (false);