Merge pull request #2254 from esohns/fstat_size_64_bits
[ACE_TAO.git] / TAO / orbsvcs / examples / CosEC / Simple / Service.cpp
blob1e8c46938e53354ae62bcf42edd6f98f75f7c9ea
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");
8 int
9 parse_args (int argc, ACE_TCHAR *argv[])
11 ACE_Get_Opt get_opts (argc, argv, ACE_TEXT("o:"));
12 int c;
14 while ((c = get_opts ()) != -1)
15 switch (c)
17 case 'o':
18 ior_output_file = get_opts.opt_arg ();
19 break;
21 case '?':
22 default:
23 ACE_ERROR_RETURN ((LM_ERROR,
24 "usage: %s "
25 "-o <iorfile>"
26 "\n",
27 argv [0]),
28 -1);
30 // Indicates successful parsing of the command line
31 return 0;
34 int
35 ACE_TMAIN(int argc, ACE_TCHAR *argv[])
37 TAO_CEC_Default_Factory::init_svcs ();
39 try
41 // ORB initialization boiler plate...
42 CORBA::ORB_var orb =
43 CORBA::ORB_init (argc, argv);
45 if (parse_args (argc, argv) == -1)
47 ACE_ERROR ((LM_ERROR,
48 "Usage: Service [-o IOR_file_name]\n"));
49 return 1;
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 (),
61 poa.in ());
63 TAO_CEC_EventChannel ec_impl (attributes);
64 ec_impl.activate ();
66 CosEventChannelAdmin::EventChannel_var event_channel =
67 ec_impl._this ();
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");
78 if (output_file == 0)
79 ACE_ERROR_RETURN ((LM_ERROR,
80 "Cannot open output file for writing IOR: %s",
81 ior_output_file),
82 1);
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.
89 orb->run ();
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");
101 return 1;
103 return 0;