1 // ******************************************************************
3 // ******************************************************************
5 #include "ace/Get_Opt.h"
7 #include "orbsvcs/CosNotifyCommC.h"
8 #include "orbsvcs/CosNamingC.h"
9 #include "Notify_Structured_Push_Consumer.h"
11 #include "ace/OS_NS_sys_time.h"
13 #include "Notify_Test_Client.h"
15 // ******************************************************************
17 // ******************************************************************
19 static Notify_Structured_Push_Consumer
* consumers
[1024] = {0};
20 static const ACE_TCHAR
*ior
= ACE_TEXT ("file://supplier.ior");
21 static unsigned int consumer_count
= 1;
22 static unsigned int expected
= 1;
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:e:c:f"));
41 while ((c
= get_opts ()) != -1)
45 ior
= get_opts
.optarg
;
49 consumer_count
= ACE_OS::atoi (get_opts
.optarg
);
53 expected
= ACE_OS::atoi (get_opts
.optarg
);
57 ACE_ERROR_RETURN ((LM_ERROR
,
60 "-c <# of consumers> "
61 "-e <expected events> "
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::AND_OP
,
80 return CosNotifyChannelAdmin::ConsumerAdmin::_duplicate (admin
.in ());
85 create_consumers (CosNotifyChannelAdmin::ConsumerAdmin_ptr admin
,
86 Notify_Test_Client
* client
)
88 for (unsigned int i
= 0; i
< consumer_count
; i
++)
90 // startup the consumers
92 ACE_OS::sprintf (name
, "consumer%u", i
);
93 ACE_NEW_THROW_EX (consumers
[ i
],
94 Notify_Structured_Push_Consumer (
100 consumers
[ i
]->init (client
->root_poa ());
102 consumers
[ i
]->connect (admin
);
107 disconnect_consumers (void)
109 for (unsigned int i
= 0; i
< consumer_count
; i
++)
111 consumers
[ i
]->disconnect ();
115 // ******************************************************************
117 // ******************************************************************
119 int ACE_TMAIN (int argc
, ACE_TCHAR
*argv
[])
124 Consumer_Client client
;
126 status
= client
.init (argc
, argv
);
130 CosNotifyChannelAdmin::EventChannel_var ec
=
131 client
.create_event_channel ("MyEventChannel", 1);
133 CORBA::Object_var object
=
134 client
.orb ()->string_to_object (ior
);
136 sig_var sig
= sig::_narrow (object
.in ());
138 if (CORBA::is_nil (sig
.in ()))
140 ACE_ERROR_RETURN ((LM_ERROR
,
141 "Object reference <%s> is nil\n",
146 CosNotifyChannelAdmin::ConsumerAdmin_var admin
=
147 create_consumeradmin (ec
.in ());
149 if (!CORBA::is_nil (admin
.in ()))
151 create_consumers (admin
.in (), &client
);
153 // Tell the supplier to go
158 disconnect_consumers();
160 ACE_DEBUG ((LM_DEBUG
, "Consumer done.\n"));
165 catch (const CORBA::Exception
& e
)
167 e
._tao_print_exception ("Error: ");