Merge pull request #1551 from DOCGroup/plm_jira_333
[ACE_TAO.git] / TAO / orbsvcs / tests / Notify / Discarding / Sequence_Consumer.cpp
blob16973aee910522b5c479fc4bb8aec8cf553b7216
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 "Notify_Sequence_Push_Consumer.h"
11 #include "goC.h"
13 #include "Notify_Test_Client.h"
15 // ******************************************************************
16 // Data Section
17 // ******************************************************************
19 static const ACE_TCHAR *ior = ACE_TEXT ("file://supplier.ior");
20 static CORBA::Short discard_policy = CosNotification::AnyOrder;
21 static int sent = 40;
22 static Notify_Sequence_Push_Consumer* consumer_1 = 0;
24 // ******************************************************************
25 // Subroutine Section
26 // ******************************************************************
28 class Consumer_Client : public Notify_Test_Client
30 public:
31 virtual int parse_args (int argc, ACE_TCHAR *argv[]);
35 int
36 Consumer_Client::parse_args (int argc, ACE_TCHAR *argv[])
38 ACE_Get_Opt get_opts (argc, argv, ACE_TEXT("k:l:h:d:"));
39 int c;
41 while ((c = get_opts ()) != -1)
42 switch (c)
44 case 'k':
45 ior = get_opts.optarg;
46 break;
48 case 'd':
50 const ACE_TCHAR* discard = get_opts.optarg;
51 if (ACE_OS::strcmp (discard, ACE_TEXT ("fifo")) == 0)
53 discard_policy = CosNotification::FifoOrder;
55 else if (ACE_OS::strcmp (discard, ACE_TEXT ("priority")) == 0)
57 discard_policy = CosNotification::PriorityOrder;
59 else if (ACE_OS::strcmp (discard, ACE_TEXT ("lifo")) == 0)
61 discard_policy = CosNotification::LifoOrder;
63 else if (ACE_OS::strcmp (discard, ACE_TEXT ("deadline")) == 0)
65 discard_policy = CosNotification::DeadlineOrder;
66 #if !defined (ACE_HAS_TIMED_MESSAGE_BLOCKS)
67 ACE_ERROR_RETURN ((LM_ERROR,
68 "This order policy requires timed message "
69 "blocks.\nPlease #define "
70 "ACE_HAS_TIMED_MESSAGE_BLOCKS in your "
71 "config.h\n"), -1);
72 #endif
74 else
76 ACE_ERROR_RETURN ((LM_ERROR,
77 "Unknown discard policy: %s\n",
78 discard_policy),
79 -1);
81 break;
83 default:
84 ACE_ERROR_RETURN ((LM_ERROR,
85 "usage: %s "
86 "-k <ior> "
87 "-d <any|fifo|lifo|priority|deadline> "
88 "\n",
89 argv [0]),
90 -1);
92 // Indicates successful parsing of the command line
93 return 0;
97 static CosNotifyChannelAdmin::ConsumerAdmin_ptr
98 create_consumeradmin (CosNotifyChannelAdmin::EventChannel_ptr ec)
100 CosNotifyChannelAdmin::AdminID adminid = 0;
101 CosNotifyChannelAdmin::ConsumerAdmin_var admin =
102 ec->new_for_consumers (CosNotifyChannelAdmin::OR_OP,
103 adminid);
106 return CosNotifyChannelAdmin::ConsumerAdmin::_duplicate (admin.in ());
110 static void
111 create_consumers (CosNotifyChannelAdmin::ConsumerAdmin_ptr admin,
112 Notify_Test_Client* client)
114 // startup the consumer
115 ACE_NEW_THROW_EX (consumer_1,
116 Notify_Sequence_Push_Consumer ("consumer1", discard_policy, *client, sent),
117 CORBA::NO_MEMORY ());
119 consumer_1->init (client->root_poa ());
121 consumer_1->_connect (admin);
124 // ******************************************************************
125 // Main Section
126 // ******************************************************************
128 int ACE_TMAIN (int argc, ACE_TCHAR *argv[])
130 int status = 0;
133 Consumer_Client client;
135 status = client.init (argc, argv);
136 ACE_UNUSED_ARG(status);
137 ACE_ASSERT(status == 0);
139 CosNotifyChannelAdmin::EventChannel_var ec =
140 client.create_event_channel ("MyEventChannel", 1);
142 CORBA::ORB_ptr orb = client.orb ();
143 CORBA::Object_var object =
144 orb->string_to_object (ior);
146 sig_var sig = sig::_narrow (object.in ());
147 ACE_ASSERT(! CORBA::is_nil (sig.in ()));
149 CosNotifyChannelAdmin::ConsumerAdmin_var admin =
150 create_consumeradmin (ec.in ());
151 ACE_ASSERT(!CORBA::is_nil (admin.in ()));
153 create_consumers (admin.in (), &client);
155 // Tell the supplier to go
156 sig->go ();
158 ACE_DEBUG((LM_DEBUG, "Consumer waiting for events...\n"));
160 client.ORB_run( );
162 ACE_DEBUG((LM_DEBUG, "Consumer done.\n"));
163 consumer_1->disconnect();
165 sig->done ();
167 catch (const CORBA::Exception& e)
169 e._tao_print_exception ("Error: ");
170 status = 1;
173 return status;