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"
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
20 virtual int parse_args (int argc
, ACE_TCHAR
*argv
[]);
24 Consumer_Client::parse_args (int argc
, ACE_TCHAR
*argv
[])
26 ACE_Get_Opt
get_opts (argc
, argv
, ACE_TEXT("ok:e:d:"));
29 while ((c
= get_opts ()) != -1)
33 ior
= get_opts
.optarg
;
41 expected
= ACE_OS::atoi (get_opts
.optarg
);
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 "
68 ACE_ERROR_RETURN ((LM_ERROR
,
69 "Unknown order policy: %s\n",
76 ACE_ERROR_RETURN ((LM_ERROR
,
79 "-e <expected events> "
80 "-d <fifo|priority|deadline> "
85 // Indicates successful parsing of the command line
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
,
98 return CosNotifyChannelAdmin::ConsumerAdmin::_duplicate (admin
.in ());
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",
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
);
150 ACE_DEBUG((LM_DEBUG
, "Consumer done.\n"));
151 consumer_1
->disconnect();
157 catch (const CORBA::Exception
& e
)
159 e
._tao_print_exception ("Error: ");