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 "orbsvcs/TimeBaseC.h"
11 #include "Notify_Structured_Push_Consumer.h"
14 #include "Notify_Test_Client.h"
16 // ******************************************************************
18 // ******************************************************************
20 static const ACE_TCHAR
*ior
= ACE_TEXT ("file://supplier.ior");
21 // TimeT is in 10ths of a microsecond
22 static TimeBase::TimeT blocking_timeout
= 2 * 1000 * 1000 * 10; // 2 secs
23 // Must match the number sent by supplier. (-1 if blocking_timeout less than 1)
24 static unsigned int expected
= 20;
25 static Notify_Structured_Push_Consumer
* consumer_1
= 0;
27 class Consumer_Client
: public Notify_Test_Client
30 virtual int parse_args (int argc
, ACE_TCHAR
*argv
[]);
35 Consumer_Client::parse_args (int argc
, ACE_TCHAR
*argv
[])
37 ACE_Get_Opt
get_opts (argc
, argv
, ACE_TEXT("k:e:t:"));
40 while ((c
= get_opts ()) != -1)
44 ior
= get_opts
.optarg
;
48 expected
= ACE_OS::atoi (get_opts
.optarg
);
52 blocking_timeout
= ACE_OS::atoi (get_opts
.optarg
);
53 blocking_timeout
*= 10 * 1000;
57 ACE_ERROR_RETURN ((LM_ERROR
,
60 "-e <expected events> "
61 "-t <relative blocking timeout milliseconds> "
66 // Indicates successful parsing of the command line
71 static CosNotifyChannelAdmin::ConsumerAdmin_ptr
72 create_consumeradmin (CosNotifyChannelAdmin::EventChannel_ptr ec
)
74 CosNotifyChannelAdmin::AdminID adminid
= 0;
75 CosNotifyChannelAdmin::ConsumerAdmin_var admin
=
76 ec
->new_for_consumers (CosNotifyChannelAdmin::OR_OP
,
80 return CosNotifyChannelAdmin::ConsumerAdmin::_duplicate (admin
.in ());
85 create_consumers (CosNotifyChannelAdmin::ConsumerAdmin_ptr admin
,
86 Notify_Test_Client
* client
)
88 // startup the consumer
89 ACE_NEW_THROW_EX (consumer_1
,
90 Notify_Structured_Push_Consumer (
96 consumer_1
->init (client
->root_poa ());
98 consumer_1
->_connect (admin
);
101 // ******************************************************************
103 // ******************************************************************
105 int ACE_TMAIN (int argc
, ACE_TCHAR
*argv
[])
110 Consumer_Client client
;
112 status
= client
.init (argc
, argv
);
114 ACE_ERROR_RETURN ((LM_ERROR
, "Error: Client init failed.\n"),1);
116 CosNotifyChannelAdmin::EventChannel_var ec
=
117 client
.create_event_channel ("MyEventChannel", 1);
119 CORBA::ORB_ptr orb
= client
.orb ();
120 CORBA::Object_var object
=
121 orb
->string_to_object (ior
);
123 sig_var sig
= sig::_narrow (object
.in ());
125 if (CORBA::is_nil (sig
.in ()))
126 ACE_ERROR_RETURN ((LM_ERROR
, "Error: Narrow failed.\n"),1);
128 CosNotifyChannelAdmin::ConsumerAdmin_var admin
=
129 create_consumeradmin (ec
.in ());
131 if (CORBA::is_nil (admin
.in ()))
132 ACE_ERROR_RETURN ((LM_ERROR
, "Error: nil ConsumerAdmin.\n"),1);
134 create_consumers (admin
.in (), &client
);
138 ACE_DEBUG((LM_DEBUG
, "\nConsumer waiting for events...\n"));
142 ACE_DEBUG((LM_DEBUG
, "Consumer done.\n"));
143 consumer_1
->disconnect();
147 catch (const CORBA::Exception
& e
)
149 e
._tao_print_exception ("Error: ");