1 #include "orbsvcs/CosEvent/CEC_EventChannel.h"
2 #include "orbsvcs/CosEvent/CEC_Default_Factory.h"
3 #include "ace/Get_Opt.h"
4 #include "ace/OS_NS_stdio.h"
6 const ACE_TCHAR
*ior_output_file
= ACE_TEXT("ec.ior");
9 parse_args (int argc
, ACE_TCHAR
*argv
[])
11 ACE_Get_Opt
get_opts (argc
, argv
, ACE_TEXT("o:"));
14 while ((c
= get_opts ()) != -1)
18 ior_output_file
= get_opts
.opt_arg ();
23 ACE_ERROR_RETURN ((LM_ERROR
,
30 // Indicates successful parsing of the command line
35 ACE_TMAIN(int argc
, ACE_TCHAR
*argv
[])
37 TAO_CEC_Default_Factory::init_svcs ();
41 // ORB initialization boiler plate...
43 CORBA::ORB_init (argc
, argv
);
45 if (parse_args (argc
, argv
) == -1)
48 "Usage: Service [-o IOR_file_name]\n"));
52 CORBA::Object_var object
=
53 orb
->resolve_initial_references ("RootPOA");
54 PortableServer::POA_var poa
=
55 PortableServer::POA::_narrow (object
.in ());
56 PortableServer::POAManager_var poa_manager
=
57 poa
->the_POAManager ();
58 poa_manager
->activate ();
60 TAO_CEC_EventChannel_Attributes
attributes (poa
.in (),
63 TAO_CEC_EventChannel
ec_impl (attributes
);
66 CosEventChannelAdmin::EventChannel_var event_channel
=
69 CORBA::String_var ior
=
70 orb
->object_to_string (event_channel
.in ());
72 ACE_DEBUG ((LM_DEBUG
, "Activated as <%C>\n", ior
.in ()));
74 // If the ior_output_file exists, output the ior to it
75 if (ior_output_file
!= 0)
77 FILE *output_file
= ACE_OS::fopen (ior_output_file
, "w");
79 ACE_ERROR_RETURN ((LM_ERROR
,
80 "Cannot open output file for writing IOR: %s",
83 ACE_OS::fprintf (output_file
, "%s", ior
.in ());
84 ACE_OS::fclose (output_file
);
87 // Wait for events, using work_pending()/perform_work() may help
88 // or using another thread, this example is too simple for that.
91 // We don't do any cleanup, it is hard to do it after shutdown,
92 // and would complicate the example; plus it is almost
93 // impossible to do cleanup after ORB->run() because the POA is
94 // in the holding state. Applications should use
95 // work_pending()/perform_work() to do more interesting stuff.
96 // Check the supplier for the proper way to do cleanup.
98 catch (const CORBA::Exception
& ex
)
100 ex
._tao_print_exception ("Service");