1 #include "Notify_Structured_Push_Consumer.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"
10 #include "ace/OS_NS_strings.h"
12 static const ACE_TCHAR
*ior
= ACE_TEXT ("file://supplier.ior");
13 static CORBA::Short discard_policy
= CosNotification::FifoOrder
;
14 CORBA::Long max_events_per_consumer
= 4;
15 static Notify_Structured_Push_Consumer
* consumer_1
;
17 class Consumer_Client
: public Notify_Test_Client
20 virtual int parse_args (int argc
, ACE_TCHAR
*argv
[]);
25 Consumer_Client::parse_args (int argc
, ACE_TCHAR
*argv
[])
27 ACE_Get_Opt
get_opts (argc
, argv
, ACE_TEXT("k:e:d:"));
30 while ((c
= get_opts ()) != -1)
34 ior
= get_opts
.optarg
;
39 const ACE_TCHAR
*discard
= get_opts
.optarg
;
40 if (ACE_OS::strcasecmp (discard
, ACE_TEXT ("fifo")) == 0)
42 discard_policy
= CosNotification::FifoOrder
;
44 else if (ACE_OS::strcasecmp (discard
, ACE_TEXT ("priority")) == 0)
46 discard_policy
= CosNotification::PriorityOrder
;
48 else if (ACE_OS::strcasecmp (discard
, ACE_TEXT ("lifo")) == 0)
50 discard_policy
= CosNotification::LifoOrder
;
52 else if (ACE_OS::strcasecmp (discard
, ACE_TEXT ("deadline")) == 0)
54 discard_policy
= CosNotification::DeadlineOrder
;
55 #if !defined (ACE_HAS_TIMED_MESSAGE_BLOCKS)
56 ACE_ERROR_RETURN ((LM_ERROR
,
57 "This order policy requires timed message "
58 "blocks.\nPlease #define "
59 "ACE_HAS_TIMED_MESSAGE_BLOCKS in your "
65 ACE_ERROR_RETURN ((LM_ERROR
,
66 "Unknown discard policy: %s\n",
73 ACE_ERROR_RETURN ((LM_ERROR
,
76 "-d <fifo|priority|lifo|deadline> "
81 // Indicates successful parsing of the command line
86 static CosNotifyChannelAdmin::ConsumerAdmin_ptr
87 create_consumeradmin (CosNotifyChannelAdmin::EventChannel_ptr ec
)
89 CosNotifyChannelAdmin::AdminID adminid
= 0;
90 CosNotifyChannelAdmin::ConsumerAdmin_var admin
=
91 ec
->new_for_consumers (CosNotifyChannelAdmin::OR_OP
,
95 return CosNotifyChannelAdmin::ConsumerAdmin::_duplicate (admin
.in ());
100 create_consumers (CosNotifyChannelAdmin::ConsumerAdmin_ptr admin
,
101 Notify_Test_Client
* client
)
103 ACE_DEBUG ((LM_DEBUG
, "Max Events per Consumer = %d...\n", max_events_per_consumer
));
105 // startup the consumer
106 ACE_NEW_THROW_EX (consumer_1
,
107 Notify_Structured_Push_Consumer (
110 max_events_per_consumer
,
112 CORBA::NO_MEMORY ());
113 consumer_1
->init (client
->root_poa ());
115 consumer_1
->_connect (admin
);
118 // ******************************************************************
120 // ******************************************************************
122 int ACE_TMAIN (int argc
, ACE_TCHAR
*argv
[])
127 Consumer_Client client
;
129 status
= client
.init (argc
, argv
);
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 if (CORBA::is_nil (sig
.in ()))
144 ACE_ERROR_RETURN ((LM_ERROR
,
145 "Object reference <%s> is nil\n",
150 CosNotifyChannelAdmin::ConsumerAdmin_var admin
=
151 create_consumeradmin (ec
.in ());
153 if (!CORBA::is_nil (admin
.in ()))
155 create_consumers (admin
.in (), &client
);
156 // Tell the supplier to go
159 ACE_DEBUG((LM_DEBUG
, "Consumer waiting for events...\n"));
163 ACE_DEBUG((LM_DEBUG
, "Consumer done.\n"));
164 consumer_1
->disconnect();
170 catch (const CORBA::Exception
& e
)
172 e
._tao_print_exception ("Error: ");