1 #ifndef ACE_BUILD_SVC_DLL
2 # define ACE_BUILD_SVC_DLL
5 #ifndef Alt_Resource_Factory_BUILD_DLL
6 # define Alt_Resource_Factory_BUILD_DLL
9 #include "Time_Date_i.h"
11 #include "Time_Date.h"
12 #include "tao/TAO_Singleton_Manager.h"
13 #include "tao/debug.h"
14 #include "ace/Reactor.h"
15 #include "ace/Get_Opt.h"
16 #include "ace/Dynamic_Service.h"
20 My_Resource_Factory::get_reactor ()
22 #if defined (ACE_HAS_THREADS)
23 // Use whatever the default is if we've got threads.
24 return TAO_Default_Resource_Factory::get_reactor ();
26 // Just use the Singleton Reactor.
27 return ACE_Reactor::instance ();
28 #endif /* ACE_HAS_THREADS */
31 ACE_FACTORY_DEFINE (Alt_Resource_Factory
, My_Resource_Factory
)
37 ACE_TEXT ("\n\tRunning ORB event loop (%t)\n\n")));
41 // Run the ORB event loop in its own thread.
44 catch (const CORBA::Exception
& ex
)
46 ex
._tao_print_exception ("Exception in DLL_ORB::svc");
54 DLL_ORB::init (int argc
, ACE_TCHAR
*argv
[])
56 // Prevent TAO from registering with the ACE_Object_Manager so
57 // that it can be dynamically unloaded successfully.
59 int register_with_object_manager
= 0;
60 if (TAO_Singleton_Manager::instance ()->init (register_with_object_manager
) == -1)
62 // ACE_ERROR_RETURN ((LM_ERROR,
64 // ACE_TEXT ("Unable to pre-initialize ORB")),
71 ACE_TEXT ("\n\tInitialize ORB (%t)\n\n")));
73 // Initialize the ORB.
74 this->orb_
= CORBA::ORB_init (argc
,
78 if (CORBA::is_nil (this->orb_
.in ()))
81 CORBA::Object_var poa_object
=
82 this->orb_
->resolve_initial_references ("RootPOA");
84 if (CORBA::is_nil (poa_object
.in ()))
85 ACE_ERROR_RETURN ((LM_ERROR
,
86 ACE_TEXT (" (%P|%t) Unable to initialize the POA.\n")),
90 PortableServer::POA::_narrow (poa_object
.in ());
93 this->poa_
->the_POAManager ();
95 this->poa_manager_
->activate ();
97 #if defined (ACE_HAS_THREADS)
98 // Become an Active Object so that the ORB
99 // will execute in a separate thread.
100 return this->activate ();
103 #endif /* ACE_HAS_THREADS */
105 catch (const CORBA::Exception
& ex
)
107 ex
._tao_print_exception ("DLL_ORB::init");
116 ACE_DEBUG ((LM_DEBUG
,
117 ACE_TEXT ("\n\tFinalizing the service (%t)\n\n")));
118 return TAO_Singleton_Manager::instance ()->fini ();
122 Time_Date_Servant::Time_Date_Servant ()
124 , ior_output_file_ (0)
130 Time_Date_Servant::parse_args (int argc
, ACE_TCHAR
*argv
[])
132 ACE_Get_Opt
get_opts (argc
, argv
, ACE_TEXT ("dn:o:"));
137 while ((c
= get_opts ()) != -1)
140 case 'd': // debug flag.
143 case 'o': // output the IOR to a file.
144 this->ior_output_file_
= get_opts
.opt_arg ();
146 // Find the ORB in the Service Repository.
148 this->orb_
= ACE_TEXT_ALWAYS_CHAR(get_opts
.opt_arg ());
150 case '?': // display help for use of the server.
152 ACE_ERROR_RETURN ((LM_ERROR
,
153 ACE_TEXT ("usage: %s")
155 ACE_TEXT (" [-o] <ior_output_file>")
161 // Indicates successful parsing of command line.
166 Time_Date_Servant::init (int argc
, ACE_TCHAR
*argv
[])
170 ACE_DEBUG ((LM_DEBUG
,
171 ACE_TEXT ("\n\tTime_Date servant\n\n")));
173 this->parse_args (argc
, argv
);
176 ACE_Dynamic_Service
<DLL_ORB
>::instance (this->orb_
.c_str ());
179 ACE_ERROR_RETURN ((LM_ERROR
,
180 ACE_TEXT ("can't find %C in the Service Repository\n"),
181 this->orb_
.c_str ()),
184 Time_Date_i
* servant
= 0;
185 ACE_NEW_THROW_EX (servant
,
187 CORBA::NO_MEMORY ());
188 PortableServer::ServantBase_var
safe_servant (servant
);
189 servant
->orb (orb
->orb_
.in ());
191 CORBA::Object_var poa_object
=
192 orb
->orb_
->resolve_initial_references("RootPOA");
194 PortableServer::POA_var root_poa
=
195 PortableServer::POA::_narrow (poa_object
.in ());
197 PortableServer::ObjectId_var id
=
198 root_poa
->activate_object (servant
);
200 CORBA::Object_var object
= root_poa
->id_to_reference (id
.in ());
202 CORBA::Object_var obj
=
203 CORBA::Object::_narrow (object
.in ());
205 CORBA::String_var str
=
206 orb
->orb_
->object_to_string (obj
.in ());
208 if (this->ior_output_file_
)
210 FILE *output_file
= ACE_OS::fopen (this->ior_output_file_
, "w");
211 if (output_file
== 0)
212 ACE_ERROR_RETURN ((LM_ERROR
,
213 ACE_TEXT ("Unable to open %s for writing (%p)\n"),
214 this->ior_output_file_
,
217 ACE_OS::fprintf (output_file
,
220 ACE_OS::fclose (output_file
);
223 catch (const CORBA::Exception
& ex
)
225 ex
._tao_print_exception ("DLL_ORB::init");
231 // The following Factory is used by the <ACE_Service_Config> and
232 // dll_orb.conf file to dynamically initialize the state of the
233 // Time_Date service.
234 ACE_SVC_FACTORY_DEFINE (DLL_ORB
)
235 ACE_SVC_FACTORY_DEFINE (Time_Date_Servant
)