Changes to attempt to silence bcc64x
[ACE_TAO.git] / TAO / orbsvcs / examples / RtEC / IIOPGateway / Gateway.cpp
blobc36aafa4ee10b84ec08b4b947a12e17ea5b6f816
1 #include "Gateway.h"
2 #include "orbsvcs/RtecEventChannelAdminC.h"
3 #include "orbsvcs/Event_Service_Constants.h"
4 #include "orbsvcs/CosNamingC.h"
5 #include "orbsvcs/Event/EC_Gateway_IIOP.h"
6 #include "orbsvcs/Event/EC_Gateway_IIOP_Factory.h"
7 #include "ace/Arg_Shifter.h"
8 #include "ace/Dynamic_Service.h"
10 static const ACE_TCHAR *supplierec = 0;
11 static const ACE_TCHAR *consumerec = 0;
13 int
14 ACE_TMAIN(int argc, ACE_TCHAR *argv[])
16 Gateway gateway;
18 return gateway.run (argc, argv);
21 // ****************************************************************
23 Gateway::Gateway ()
27 int
28 Gateway::run (int argc, ACE_TCHAR* argv[])
30 TAO_EC_Gateway_IIOP_Factory::init_svcs ();
32 try
34 // First parse our command line options
35 if (this->parse_args(argc, argv) != 0)
37 return -1;
40 // ORB initialization boiler plate...
41 CORBA::ORB_var orb =
42 CORBA::ORB_init (argc, argv);
44 CORBA::Object_var object =
45 orb->resolve_initial_references ("RootPOA");
46 PortableServer::POA_var poa =
47 PortableServer::POA::_narrow (object.in ());
48 PortableServer::POAManager_var poa_manager =
49 poa->the_POAManager ();
50 poa_manager->activate ();
52 // Obtain the event channel from the naming service
53 CORBA::Object_var naming_obj =
54 orb->resolve_initial_references ("NameService");
56 if (CORBA::is_nil (naming_obj.in ()))
57 ACE_ERROR_RETURN ((LM_ERROR,
58 " (%P|%t) Unable to get the Naming Service.\n"),
59 1);
61 CosNaming::NamingContext_var naming_context =
62 CosNaming::NamingContext::_narrow (naming_obj.in ());
64 CosNaming::Name supplierecname (1);
65 supplierecname.length (1);
66 supplierecname[0].id = CORBA::string_dup (ACE_TEXT_ALWAYS_CHAR(supplierec));
68 CORBA::Object_var supplierec_obj =
69 naming_context->resolve (supplierecname);
71 CosNaming::Name consumerecname (1);
72 consumerecname.length (1);
73 consumerecname[0].id = CORBA::string_dup (ACE_TEXT_ALWAYS_CHAR(consumerec));
75 CORBA::Object_var consumerec_obj =
76 naming_context->resolve (consumerecname);
78 RtecEventChannelAdmin::EventChannel_var supplier_event_channel =
79 RtecEventChannelAdmin::EventChannel::_narrow (supplierec_obj.in ());
81 if (CORBA::is_nil (supplier_event_channel.in ()))
82 ACE_ERROR_RETURN ((LM_ERROR,
83 " (%P|%t) Unable to get the supplier event channel.\n"),
84 1);
86 RtecEventChannelAdmin::EventChannel_var consumer_event_channel =
87 RtecEventChannelAdmin::EventChannel::_narrow (consumerec_obj.in ());
89 if (CORBA::is_nil (consumer_event_channel.in ()))
90 ACE_ERROR_RETURN ((LM_ERROR,
91 " (%P|%t) Unable to get the consumer event channel.\n"),
92 1);
94 TAO_EC_Gateway_IIOP gateway;
96 gateway.init(supplier_event_channel.in(), consumer_event_channel.in());
98 PortableServer::ObjectId_var gateway_oid =
99 poa->activate_object(&gateway);
101 CORBA::Object_var gateway_obj =
102 poa->id_to_reference(gateway_oid.in());
104 RtecEventChannelAdmin::Observer_var obs =
105 RtecEventChannelAdmin::Observer::_narrow(gateway_obj.in());
107 RtecEventChannelAdmin::Observer_Handle local_ec_obs_handle =
108 consumer_event_channel->append_observer (obs.in ());
110 // Wait for events, using work_pending()/perform_work() may help
111 // or using another thread, this example is too simple for that.
112 orb->run ();
114 consumer_event_channel->remove_observer (local_ec_obs_handle);
116 poa->deactivate_object (gateway_oid.in ());
118 // Destroy the POA
119 poa->destroy (1, 0);
121 catch (const CORBA::Exception& ex)
123 ex._tao_print_exception ("Gateway::run");
124 return 1;
127 return 0;
131 Gateway::parse_args (int argc, ACE_TCHAR *argv[])
133 ACE_Arg_Shifter arg_shifter (argc, argv);
135 while (arg_shifter.is_anything_left ())
137 const ACE_TCHAR *arg = arg_shifter.get_current ();
139 if (ACE_OS::strcmp (arg, ACE_TEXT("-s")) == 0)
141 arg_shifter.consume_arg ();
142 supplierec = arg_shifter.get_current ();
144 if (ACE_OS::strcmp (arg, ACE_TEXT("-c")) == 0)
146 arg_shifter.consume_arg ();
147 consumerec = arg_shifter.get_current ();
150 arg_shifter.ignore_arg ();
152 // Indicates successful parsing of the command line
153 return 0;