1 #include "orbsvcs/Event/EC_Event_Channel.h"
2 #include "orbsvcs/Event/EC_Default_Factory.h"
3 #include "ace/Get_Opt.h"
4 #include "orbsvcs/CosNamingC.h"
5 #include "ace/OS_NS_stdio.h"
7 const ACE_TCHAR
*ior_output_file
= ACE_TEXT("ec.ior");
9 int parse_args (int argc
, ACE_TCHAR
*argv
[]);
12 ACE_TMAIN(int argc
, ACE_TCHAR
*argv
[])
14 TAO_EC_Default_Factory::init_svcs ();
18 // ORB initialization boiler plate...
20 CORBA::ORB_init (argc
, argv
);
22 CORBA::Object_var object
=
23 orb
->resolve_initial_references ("RootPOA");
24 PortableServer::POA_var poa
=
25 PortableServer::POA::_narrow (object
.in ());
26 PortableServer::POAManager_var poa_manager
=
27 poa
->the_POAManager ();
28 poa_manager
->activate ();
30 // Obtain the naming service
31 CORBA::Object_var naming_obj
=
32 orb
->resolve_initial_references ("NameService");
34 if (CORBA::is_nil (naming_obj
.in ()))
35 ACE_ERROR_RETURN ((LM_ERROR
,
36 " (%P|%t) Unable to get the Naming Service.\n"),
39 CosNaming::NamingContext_var naming_context
=
40 CosNaming::NamingContext::_narrow (naming_obj
.in ());
42 TAO_EC_Event_Channel_Attributes
attributes (poa
.in (),
45 TAO_EC_Event_Channel
ec_impl (attributes
);
48 RtecEventChannelAdmin::EventChannel_var event_channel
=
54 name
[0].id
= CORBA::string_dup ("EventService");
55 name
[0].kind
= CORBA::string_dup ("");
57 // Register with the name server
58 naming_context
->bind (name
, event_channel
.in ());
60 // Example code: How to write ior to file
61 CORBA::String_var ior
=
62 orb
->object_to_string (event_channel
.in ());
63 ACE_DEBUG ((LM_DEBUG
, "Activated as <%C>\n", ior
.in ()));
64 // If the ior_output_file exists, output the ior to it
65 if (ior_output_file
!= 0)
67 FILE *output_file
= ACE_OS::fopen (ior_output_file
, "w");
69 ACE_ERROR_RETURN ((LM_ERROR
,
70 "Cannot open output file for writing IOR: %s",
73 ACE_OS::fprintf (output_file
, "%s", ior
.in ());
74 ACE_OS::fclose (output_file
);
77 // Wait for events, using work_pending()/perform_work() may help
78 // or using another thread, this example is too simple for that.
81 // We don't do any cleanup, it is hard to do it after shutdown,
82 // and would complicate the example; plus it is almost
83 // impossible to do cleanup after ORB->run() because the POA is
84 // in the holding state. Applications should use
85 // work_pending()/perform_work() to do more interesting stuff.
86 // Check the supplier for the proper way to do cleanup.
88 catch (const CORBA::Exception
& ex
)
90 ex
._tao_print_exception ("Service");
96 // ****************************************************************
98 int parse_args (int argc
, ACE_TCHAR
*argv
[])
100 ACE_Get_Opt
get_opts (argc
, argv
, ACE_TEXT("o:"));
103 while ((c
= get_opts ()) != -1)
107 ior_output_file
= get_opts
.opt_arg ();
112 ACE_ERROR_RETURN ((LM_ERROR
,
119 // Indicates successful parsing of the command line