Changes to attempt to silence bcc64x
[ACE_TAO.git] / TAO / orbsvcs / tests / FtRtEvent / supplier.cpp
blob24aa27c21e45752949d55012b5e7d0f0e89354ad
1 #include "orbsvcs/CosNamingC.h"
2 #include "orbsvcs/FtRtecEventChannelAdminC.h"
3 #include "PushSupplier.h"
4 #include "ace/Get_Opt.h"
5 #include "ace/OS_NS_stdlib.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 ACE_Time_Value timer_interval(1,0);
17 CORBA::ORB_var orb;
18 std::unique_ptr<TAO_FTRTEC::FTEC_Gateway> gateway;
20 RtecEventChannelAdmin::EventChannel_ptr
21 get_event_channel(int argc, ACE_TCHAR** argv)
23 FtRtecEventChannelAdmin::EventChannel_var channel;
24 ACE_Get_Opt get_opt (argc, argv, ACE_TEXT("hi:nt:?"));
25 int opt;
26 int use_gateway = 1;
28 while ((opt = get_opt ()) != EOF)
30 switch (opt)
32 case 'i':
34 CORBA::Object_var obj = orb->string_to_object(get_opt.opt_arg ());
35 channel = FtRtecEventChannelAdmin::EventChannel::_narrow(obj.in());
37 break;
38 case 'n':
39 use_gateway = 0;
40 break;
41 case 't':
42 timer_interval.set(ACE_OS::atof(get_opt.opt_arg ()));
43 break;
44 case 'h':
45 case '?':
46 ACE_DEBUG((LM_DEBUG,
47 ACE_TEXT("Usage: %s ")
48 ACE_TEXT("-i ftrt_eventchannel_ior\n")
49 ACE_TEXT("-n do not use gateway\n")
50 ACE_TEXT("-t time Time interval in seconds between events (default 1.0)\n")
51 ACE_TEXT("\n"),
52 argv[0]));
53 return 0;
57 if (CORBA::is_nil(channel.in()))
59 /// Find the FTRTEC from the Naming Service
60 CosNaming::Name name(1);
61 name.length(1);
62 name[0].id = CORBA::string_dup("FT_EventService");
64 CosNaming::NamingContext_var naming_context =
65 resolve_init<CosNaming::NamingContext>(orb.in(), "NameService");
67 channel = resolve<FtRtecEventChannelAdmin::EventChannel> (naming_context.in (),
68 name);
71 if (use_gateway)
73 // use local gateway to communicate with FTRTEC
74 gateway.reset (new TAO_FTRTEC::FTEC_Gateway (orb.in (), channel.in ()));
75 return gateway->_this ();
77 else
78 return channel._retn ();
82 int ACE_TMAIN (int argc, ACE_TCHAR *argv[])
84 try{
85 orb = CORBA::ORB_init (argc, argv);
88 RtecEventChannelAdmin::EventChannel_var channel
89 = get_event_channel (argc, argv);
92 if (CORBA::is_nil (channel.in ()))
93 return -1;
95 PortableServer::POA_var poa =
96 resolve_init<PortableServer::POA> (orb.in (), "RootPOA");
98 PortableServer::POAManager_var mgr = poa->the_POAManager ();
100 mgr->activate ();
102 PushSupplier_impl push_supplier(orb.in ());
103 if (push_supplier.init(channel.in ()) == -1)
104 return -1;
106 RtecEventComm::PushSupplier_var
107 supplier = push_supplier._this();
109 orb->run();
111 catch (const CORBA::Exception& ex){
112 ex._tao_print_exception ("A CORBA Exception occurred.");
115 return 0;