1 // ******************************************************************
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"
13 #include "Notify_Test_Client.h"
15 // ******************************************************************
17 // ******************************************************************
19 static const ACE_TCHAR
*ior
= ACE_TEXT ("file://supplier.ior");
20 static CORBA::Short discard_policy
= CosNotification::AnyOrder
;
22 static Notify_Sequence_Push_Consumer
* consumer_1
= 0;
24 // ******************************************************************
26 // ******************************************************************
28 class Consumer_Client
: public Notify_Test_Client
31 virtual int parse_args (int argc
, ACE_TCHAR
*argv
[]);
36 Consumer_Client::parse_args (int argc
, ACE_TCHAR
*argv
[])
38 ACE_Get_Opt
get_opts (argc
, argv
, ACE_TEXT("k:l:h:d:"));
41 while ((c
= get_opts ()) != -1)
45 ior
= get_opts
.optarg
;
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 "
76 ACE_ERROR_RETURN ((LM_ERROR
,
77 "Unknown discard policy: %s\n",
84 ACE_ERROR_RETURN ((LM_ERROR
,
87 "-d <any|fifo|lifo|priority|deadline> "
92 // Indicates successful parsing of the command line
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
,
106 return CosNotifyChannelAdmin::ConsumerAdmin::_duplicate (admin
.in ());
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 // ******************************************************************
126 // ******************************************************************
128 int ACE_TMAIN (int argc
, ACE_TCHAR
*argv
[])
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
158 ACE_DEBUG((LM_DEBUG
, "Consumer waiting for events...\n"));
162 ACE_DEBUG((LM_DEBUG
, "Consumer done.\n"));
163 consumer_1
->disconnect();
167 catch (const CORBA::Exception
& e
)
169 e
._tao_print_exception ("Error: ");