Changes to attempt to silence bcc64x
[ACE_TAO.git] / TAO / orbsvcs / tests / Notify / Ordering / Sequence_Consumer.cpp
blobc586dd0e012ee46bee455ebac55da16321966fd4
1 #include "Notify_Sequence_Push_Consumer.h"
2 #include "goC.h"
4 #include "Notify_Test_Client.h"
6 #include "orbsvcs/CosNotifyCommC.h"
7 #include "orbsvcs/CosNamingC.h"
9 #include "ace/Get_Opt.h"
10 #include "ace/OS_NS_unistd.h"
11 #include "ace/OS_NS_sys_stat.h"
13 static const ACE_TCHAR *ior = ACE_TEXT ("file://supplier.ior");
14 static CORBA::Short order_policy = CosNotification::FifoOrder;
15 static int expected = 30; // Must match the amount sent by supplier
16 static Notify_Sequence_Push_Consumer* consumer_1;
17 static bool use_ordering = false;
19 class Consumer_Client : public Notify_Test_Client
21 public:
22 virtual int parse_args (int argc, ACE_TCHAR *argv[]);
26 int
27 Consumer_Client::parse_args (int argc, ACE_TCHAR *argv[])
29 ACE_Get_Opt get_opts (argc, argv, ACE_TEXT("ok:e:d:"));
30 int c;
32 while ((c = get_opts ()) != -1)
33 switch (c)
35 case 'k':
36 ior = get_opts.optarg;
37 break;
39 case 'e':
40 expected = ACE_OS::atoi (get_opts.optarg);
41 break;
43 case 'o':
44 use_ordering = true;
45 break;
47 case 'd':
49 const ACE_TCHAR *order = get_opts.optarg;
50 if (ACE_OS::strcmp (order, ACE_TEXT ("fifo")) == 0)
52 order_policy = CosNotification::FifoOrder;
54 else if (ACE_OS::strcmp (order, ACE_TEXT ("priority")) == 0)
56 order_policy = CosNotification::PriorityOrder;
58 else if (ACE_OS::strcmp (order, ACE_TEXT ("deadline")) == 0)
60 order_policy = CosNotification::DeadlineOrder;
61 #if !defined (ACE_HAS_TIMED_MESSAGE_BLOCKS)
62 ACE_ERROR_RETURN ((LM_ERROR,
63 "This order policy requires timed message "
64 "blocks.\nPlease #define "
65 "ACE_HAS_TIMED_MESSAGE_BLOCKS in your "
66 "config.h\n"), -1);
67 #endif
69 else
71 ACE_ERROR_RETURN ((LM_ERROR,
72 "Unknown ordering policy: %s\n",
73 order_policy),
74 -1);
76 break;
78 default:
79 ACE_ERROR_RETURN ((LM_ERROR,
80 "usage: %s "
81 "-k <ior> "
82 "-e <expected events> "
83 "-d <fifo|priority|deadline> "
84 "\n",
85 argv [0]),
86 -1);
88 // Indicates successful parsing of the command line
89 return 0;
93 static CosNotifyChannelAdmin::ConsumerAdmin_ptr
94 create_consumeradmin (CosNotifyChannelAdmin::EventChannel_ptr ec)
96 CosNotifyChannelAdmin::AdminID adminid = 0;
97 CosNotifyChannelAdmin::ConsumerAdmin_var admin =
98 ec->new_for_consumers (CosNotifyChannelAdmin::OR_OP,
99 adminid);
102 return CosNotifyChannelAdmin::ConsumerAdmin::_duplicate (admin.in ());
106 static void
107 create_consumers (CosNotifyChannelAdmin::ConsumerAdmin_ptr admin,
108 Notify_Test_Client* client)
110 ACE_NEW_THROW_EX (consumer_1,
111 Notify_Sequence_Push_Consumer ("consumer1",
112 order_policy,
113 use_ordering,
114 expected,
115 *client),
116 CORBA::NO_MEMORY ());
118 consumer_1->init (client->root_poa ());
120 consumer_1->_connect (admin);
123 int ACE_TMAIN (int argc, ACE_TCHAR *argv[])
127 Consumer_Client client;
129 int status = client.init (argc, argv);
130 ACE_UNUSED_ARG(status);
131 ACE_ASSERT(status == 0);
133 CosNotifyChannelAdmin::EventChannel_var ec =
134 client.create_event_channel ("MyEventChannel", 1);
136 CORBA::ORB_ptr orb = client.orb ();
137 CORBA::Object_var object =
138 orb->string_to_object (ior);
140 sig_var sig = sig::_narrow (object.in ());
142 ACE_ASSERT(! CORBA::is_nil (sig.in ()));
144 CosNotifyChannelAdmin::ConsumerAdmin_var admin =
145 create_consumeradmin (ec.in ());
147 ACE_ASSERT(!CORBA::is_nil (admin.in ()));
148 create_consumers (admin.in (), &client);
150 sig->go ();
152 client.ORB_run();
154 ACE_DEBUG((LM_DEBUG, "Consumer done.\n"));
155 consumer_1->disconnect();
157 sig->done ();
159 return 0;
161 catch (const CORBA::Exception& e)
163 e._tao_print_exception ("Error: ");
166 return 1;