Changes to attempt to silence bcc64x
[ACE_TAO.git] / TAO / orbsvcs / tests / Notify / Blocking / Structured_Consumer.cpp
blob6bbac66f859da315b64e84f95a15b3b1e6a9d28b
1 // ******************************************************************
2 // Include Section
3 // ******************************************************************
5 #include "ace/Get_Opt.h"
6 #include "ace/OS_NS_unistd.h"
8 #include "orbsvcs/CosNotifyCommC.h"
9 #include "orbsvcs/CosNamingC.h"
10 #include "orbsvcs/TimeBaseC.h"
11 #include "Notify_Structured_Push_Consumer.h"
12 #include "goC.h"
14 #include "Notify_Test_Client.h"
16 // ******************************************************************
17 // Data Section
18 // ******************************************************************
20 static const ACE_TCHAR *ior = ACE_TEXT ("file://supplier.ior");
21 // TimeT is in 10ths of a microsecond
22 static TimeBase::TimeT blocking_timeout = 2 * 1000 * 1000 * 10; // 2 secs
23 // Must match the number sent by supplier. (-1 if blocking_timeout less than 1)
24 static unsigned int expected = 20;
25 static Notify_Structured_Push_Consumer* consumer_1 = 0;
27 class Consumer_Client : public Notify_Test_Client
29 public:
30 virtual int parse_args (int argc, ACE_TCHAR *argv[]);
34 int
35 Consumer_Client::parse_args (int argc, ACE_TCHAR *argv[])
37 ACE_Get_Opt get_opts (argc, argv, ACE_TEXT("k:e:t:"));
38 int c;
40 while ((c = get_opts ()) != -1)
41 switch (c)
43 case 'k':
44 ior = get_opts.optarg;
45 break;
47 case 'e':
48 expected = ACE_OS::atoi (get_opts.optarg);
49 break;
51 case 't':
52 blocking_timeout = ACE_OS::atoi (get_opts.optarg);
53 blocking_timeout *= 10 * 1000;
54 break;
56 default:
57 ACE_ERROR_RETURN ((LM_ERROR,
58 "usage: %s "
59 "-k <ior> "
60 "-e <expected events> "
61 "-t <relative blocking timeout milliseconds> "
62 "\n",
63 argv [0]),
64 -1);
66 // Indicates successful parsing of the command line
67 return 0;
71 static CosNotifyChannelAdmin::ConsumerAdmin_ptr
72 create_consumeradmin (CosNotifyChannelAdmin::EventChannel_ptr ec)
74 CosNotifyChannelAdmin::AdminID adminid = 0;
75 CosNotifyChannelAdmin::ConsumerAdmin_var admin =
76 ec->new_for_consumers (CosNotifyChannelAdmin::OR_OP,
77 adminid);
80 return CosNotifyChannelAdmin::ConsumerAdmin::_duplicate (admin.in ());
84 static void
85 create_consumers (CosNotifyChannelAdmin::ConsumerAdmin_ptr admin,
86 Notify_Test_Client* client)
88 // startup the consumer
89 ACE_NEW_THROW_EX (consumer_1,
90 Notify_Structured_Push_Consumer (
91 "consumer1",
92 blocking_timeout,
93 expected,
94 *client),
95 CORBA::NO_MEMORY ());
96 consumer_1->init (client->root_poa ());
98 consumer_1->_connect (admin);
101 // ******************************************************************
102 // Main Section
103 // ******************************************************************
105 int ACE_TMAIN (int argc, ACE_TCHAR *argv[])
107 int status = 0;
110 Consumer_Client client;
112 status = client.init (argc, argv);
113 if (status != 0)
114 ACE_ERROR_RETURN ((LM_ERROR, "Error: Client init failed.\n"),1);
116 CosNotifyChannelAdmin::EventChannel_var ec =
117 client.create_event_channel ("MyEventChannel", 1);
119 CORBA::ORB_ptr orb = client.orb ();
120 CORBA::Object_var object =
121 orb->string_to_object (ior);
123 sig_var sig = sig::_narrow (object.in ());
125 if (CORBA::is_nil (sig.in ()))
126 ACE_ERROR_RETURN ((LM_ERROR, "Error: Narrow failed.\n"),1);
128 CosNotifyChannelAdmin::ConsumerAdmin_var admin =
129 create_consumeradmin (ec.in ());
131 if (CORBA::is_nil (admin.in ()))
132 ACE_ERROR_RETURN ((LM_ERROR, "Error: nil ConsumerAdmin.\n"),1);
134 create_consumers (admin.in (), &client);
136 sig->go ();
138 ACE_DEBUG((LM_DEBUG, "\nConsumer waiting for events...\n"));
140 client.ORB_run ();
142 ACE_DEBUG((LM_DEBUG, "Consumer done.\n"));
143 consumer_1->disconnect();
145 sig->done ();
147 catch (const CORBA::Exception& e)
149 e._tao_print_exception ("Error: ");
150 status = 1;
153 return status;