Merge pull request #2309 from mitza-oci/warnings
[ACE_TAO.git] / TAO / orbsvcs / tests / FtRtEvent / consumer.cpp
blob89ac54b9f05faa4f22de96787fcf4af107e6a9cf
1 #include "orbsvcs/CosNamingC.h"
2 #include "orbsvcs/FtRtecEventChannelAdminC.h"
3 #include "orbsvcs/Event_Utilities.h"
4 #include "PushConsumer.h"
5 #include "ace/Get_Opt.h"
6 #include "orbsvcs/FtRtEvent/Utils/resolve_init.h"
7 #include "orbsvcs/FtRtEvent/Utils/FTEC_Gateway.h"
9 /// include this file to statically linked with FT ORB
10 #include "orbsvcs/FaultTolerance/FT_ClientService_Activate.h"
12 /// include this file to statically linked with Transaction Depth
13 #include "orbsvcs/FtRtEvent/ClientORB/FTRT_ClientORB_Loader.h"
14 #include <memory>
16 CORBA::ORB_var orb;
17 std::unique_ptr<TAO_FTRTEC::FTEC_Gateway> gateway;
19 RtecEventChannelAdmin::EventChannel_ptr
20 get_event_channel(int argc, ACE_TCHAR** argv)
22 FtRtecEventChannelAdmin::EventChannel_var channel;
23 ACE_Get_Opt get_opt (argc, argv, ACE_TEXT("hi:n"));
24 int opt;
25 int use_gateway = 1;
27 while ((opt = get_opt ()) != EOF)
29 switch (opt)
31 case 'i':
33 CORBA::Object_var obj = orb->string_to_object(get_opt.opt_arg ());
34 channel = FtRtecEventChannelAdmin::EventChannel::_narrow(obj.in());
36 break;
37 case 'n':
38 use_gateway = 0;
39 break;
40 case 'h':
41 case '?':
42 ACE_DEBUG((LM_DEBUG,
43 ACE_TEXT("Usage: %s ")
44 ACE_TEXT("-i ftrt_eventchannel_ior\n")
45 ACE_TEXT("-n do not use gateway\n")
46 ACE_TEXT("\n"),
47 argv[0]));
48 return 0;
52 if (CORBA::is_nil(channel.in()))
54 CosNaming::Name name(1);
55 name.length(1);
56 name[0].id = CORBA::string_dup("FT_EventService");
58 CosNaming::NamingContext_var naming_context =
59 resolve_init<CosNaming::NamingContext>(orb.in(), "NameService");
61 channel = resolve<FtRtecEventChannelAdmin::EventChannel>(naming_context.in(),
62 name);
65 if (use_gateway)
67 gateway.reset (new TAO_FTRTEC::FTEC_Gateway(orb.in(), channel.in()));
68 return gateway->_this();
70 else
71 return channel._retn();
74 int ACE_TMAIN (int argc, ACE_TCHAR *argv[])
76 try{
77 orb = CORBA::ORB_init (argc, argv);
79 RtecEventChannelAdmin::EventChannel_var channel
80 = get_event_channel (argc, argv);
83 if (CORBA::is_nil(channel.in()))
84 ACE_ERROR_RETURN ((LM_ERROR, "Cannot Find FT_EventService\n"), -1);
86 PortableServer::POA_var poa =
87 resolve_init<PortableServer::POA>(orb.in(), "RootPOA");
89 PortableServer::POAManager_var mgr = poa->the_POAManager();
91 mgr->activate();
93 PushConsumer_impl push_consumer_impl(orb.in());
94 RtecEventChannelAdmin::ConsumerAdmin_var consumer_admin =
95 channel->for_consumers();
97 RtecEventChannelAdmin::ProxyPushSupplier_var supplier =
98 consumer_admin->obtain_push_supplier();
100 RtecEventChannelAdmin::ConsumerQOS qos;
101 qos.is_gateway = 1;
102 qos.dependencies.length(1);
104 RtecEventComm::EventHeader& h0 =
105 qos.dependencies[0].event.header;
106 h0.type = ACE_ES_EVENT_UNDEFINED; // first free event type
107 h0.source = ACE_ES_EVENT_SOURCE_ANY;
109 RtecEventComm::PushConsumer_var push_consumer =
110 push_consumer_impl._this();
112 supplier->connect_push_consumer(push_consumer.in(),
113 qos);
115 orb->run();
117 catch (const CORBA::Exception& ex){
118 ex._tao_print_exception ("A CORBA Exception occurred.");
119 return -1;
122 return 0;