Merge pull request #2309 from mitza-oci/warnings
[ACE_TAO.git] / TAO / orbsvcs / tests / Notify / Ordering / Structured_Consumer.cpp
blob0df3dded203580f6b92089bddc44851ebdda28b4
1 #include "Notify_Structured_Push_Consumer.h"
2 #include "goC.h"
3 #include "Notify_Test_Client.h"
5 #include "orbsvcs/CosNotifyCommC.h"
6 #include "orbsvcs/CosNamingC.h"
8 #include "ace/Get_Opt.h"
9 #include "ace/OS_NS_unistd.h"
11 static const ACE_TCHAR *ior = ACE_TEXT ("file://supplier.ior");
12 static CORBA::Short order_policy = CosNotification::FifoOrder;
13 static int expected = 30;
14 static Notify_Structured_Push_Consumer* consumer_1;
15 static bool use_ordering = false;
17 class Consumer_Client : public Notify_Test_Client
19 public:
20 virtual int parse_args (int argc, ACE_TCHAR *argv[]);
23 int
24 Consumer_Client::parse_args (int argc, ACE_TCHAR *argv[])
26 ACE_Get_Opt get_opts (argc, argv, ACE_TEXT("ok:e:d:"));
27 int c;
29 while ((c = get_opts ()) != -1)
30 switch (c)
32 case 'k':
33 ior = get_opts.optarg;
34 break;
36 case 'o':
37 use_ordering = true;
38 break;
40 case 'e':
41 expected = ACE_OS::atoi (get_opts.optarg);
42 break;
44 case 'd':
46 const ACE_TCHAR *order = get_opts.optarg;
47 if (ACE_OS::strcmp (order, ACE_TEXT ("fifo")) == 0)
49 order_policy = CosNotification::FifoOrder;
51 else if (ACE_OS::strcmp (order, ACE_TEXT ("priority")) == 0)
53 order_policy = CosNotification::PriorityOrder;
55 else if (ACE_OS::strcmp (order, ACE_TEXT ("deadline")) == 0)
57 order_policy = CosNotification::DeadlineOrder;
58 #if !defined (ACE_HAS_TIMED_MESSAGE_BLOCKS)
59 ACE_ERROR_RETURN ((LM_ERROR,
60 "This order policy requires timed message"
61 "blocks.\nPlease #define "
62 "ACE_HAS_TIMED_MESSAGE_BLOCKS in your "
63 "config.h\n"), -1);
64 #endif
66 else
68 ACE_ERROR_RETURN ((LM_ERROR,
69 "Unknown order policy: %s\n",
70 order_policy),
71 -1);
73 break;
75 default:
76 ACE_ERROR_RETURN ((LM_ERROR,
77 "usage: %s "
78 "-k <ior> "
79 "-e <expected events> "
80 "-d <fifo|priority|deadline> "
81 "\n",
82 argv [0]),
83 -1);
85 // Indicates successful parsing of the command line
86 return 0;
89 static CosNotifyChannelAdmin::ConsumerAdmin_ptr
90 create_consumeradmin (CosNotifyChannelAdmin::EventChannel_ptr ec)
92 CosNotifyChannelAdmin::AdminID adminid = 0;
93 CosNotifyChannelAdmin::ConsumerAdmin_var admin =
94 ec->new_for_consumers (CosNotifyChannelAdmin::OR_OP,
95 adminid);
98 return CosNotifyChannelAdmin::ConsumerAdmin::_duplicate (admin.in ());
101 static void
102 create_consumers (CosNotifyChannelAdmin::ConsumerAdmin_ptr admin,
103 Notify_Test_Client* client)
105 // startup the first consumer
106 ACE_NEW_THROW_EX (consumer_1,
107 Notify_Structured_Push_Consumer ("consumer1",
108 order_policy,
109 use_ordering,
110 expected,
111 *client),
112 CORBA::NO_MEMORY ());
113 consumer_1->init (client->root_poa ());
115 consumer_1->_connect (admin);
118 int ACE_TMAIN (int argc, ACE_TCHAR *argv[])
122 Consumer_Client client;
124 int status = client.init (argc, argv);
125 ACE_UNUSED_ARG(status);
126 ACE_ASSERT(status == 0);
128 CosNotifyChannelAdmin::EventChannel_var ec =
129 client.create_event_channel ("MyEventChannel", 1);
131 CORBA::ORB_ptr orb = client.orb ();
132 CORBA::Object_var object =
133 orb->string_to_object (ior);
135 sig_var sig = sig::_narrow (object.in ());
137 ACE_ASSERT(! CORBA::is_nil (sig.in ()));
139 CosNotifyChannelAdmin::ConsumerAdmin_var admin =
140 create_consumeradmin (ec.in ());
142 ACE_ASSERT(!CORBA::is_nil (admin.in ()));
144 create_consumers (admin.in (), &client);
146 sig->go ();
148 client.ORB_run();
150 ACE_DEBUG((LM_DEBUG, "Consumer done.\n"));
151 consumer_1->disconnect();
153 sig->done ();
155 return 0;
157 catch (const CORBA::Exception& e)
159 e._tao_print_exception ("Error: ");
162 return 1;