1 // ******************************************************************
3 // ******************************************************************
5 #include "ace/Get_Opt.h"
6 #include "ace/OS_NS_unistd.h"
7 #include "ace/OS_NS_stdio.h"
9 #include "Notify_Structured_Push_Consumer.h"
10 #include "MonitorTestInterfaceC.h"
12 #include "Notify_Test_Client.h"
14 // ******************************************************************
16 // ******************************************************************
18 static const ACE_TCHAR
*ior
= ACE_TEXT ("file://test_monitor.ior");
19 static const ACE_TCHAR
*ready_output_file
= ACE_TEXT ("ready.txt");
20 static unsigned int expected
= 2000;
21 static unsigned int delay_period
= 5;
22 static unsigned int delay_count
= 0;
23 static Notify_Structured_Push_Consumer
* consumer_1
= 0;
25 class Consumer_Client
: public Notify_Test_Client
28 virtual int parse_args (int argc
, ACE_TCHAR
*argv
[]);
33 Consumer_Client::parse_args (int argc
, ACE_TCHAR
*argv
[])
35 ACE_Get_Opt
get_opts (argc
, argv
, ACE_TEXT("k:e:p:d:o:"));
38 while ((c
= get_opts ()) != -1)
42 ior
= get_opts
.optarg
;
46 expected
= ACE_OS::atoi (get_opts
.optarg
);
50 delay_period
= ACE_OS::atoi (get_opts
.optarg
);
54 delay_count
= ACE_OS::atoi (get_opts
.optarg
);
58 ready_output_file
= get_opts
.optarg
;
62 ACE_ERROR_RETURN ((LM_ERROR
,
65 "-e <expected events> "
66 "-d <delay every 'n' seconds> "
67 "-p <how many seconds to delay> "
68 "-o <readyfile> -e <# of events> "
73 // Indicates successful parsing of the command line
78 static CosNotifyChannelAdmin::ConsumerAdmin_ptr
79 create_consumeradmin (CosNotifyChannelAdmin::EventChannel_ptr ec
)
81 CosNotifyChannelAdmin::AdminID adminid
= 0;
82 CosNotifyChannelAdmin::ConsumerAdmin_var admin
=
83 ec
->new_for_consumers (CosNotifyChannelAdmin::OR_OP
, adminid
);
85 return CosNotifyChannelAdmin::ConsumerAdmin::_duplicate (admin
.in ());
90 create_consumers (CosNotifyChannelAdmin::ConsumerAdmin_ptr admin
,
91 Notify_Test_Client
* client
)
93 // startup the consumer
94 ACE_NEW_THROW_EX (consumer_1
,
95 Notify_Structured_Push_Consumer ("consumer1",
99 consumer_1
->set_delay_parameters (delay_count
, delay_period
);
100 consumer_1
->init (client
->root_poa ());
101 consumer_1
->_connect (admin
);
104 // ******************************************************************
106 // ******************************************************************
108 int ACE_TMAIN (int argc
, ACE_TCHAR
*argv
[])
114 Consumer_Client client
;
115 status
= client
.init (argc
, argv
);
119 ACE_ERROR_RETURN ((LM_ERROR
,
120 "Error: Client init failed.\n"),
124 CosNotifyChannelAdmin::EventChannel_var ec
=
125 client
.create_event_channel ("MyEventChannel", 0);
127 #ifdef TEST_QOS_MAX_QUEUE_LENGTH
128 ACE_OS::printf ("%s: setting max queue length to 1000\n", argv
[0]);
129 CosNotification::AdminProperties
properties(1);
130 properties
.length(1);
131 properties
[0].name
= CORBA::string_dup (CosNotification::MaxQueueLength
);
132 properties
[0].value
<<= 1000;
133 ec
->set_admin(properties
);
134 #endif //TEST_QOS_MAX_QUEUE_LENGTH
136 CORBA::ORB_ptr orb
= client
.orb ();
137 CORBA::Object_var object
=
138 orb
->string_to_object (ior
);
140 MonitorTestInterface_var sig
=
141 MonitorTestInterface::_narrow (object
.in ());
143 if (CORBA::is_nil (sig
.in ()))
145 ACE_ERROR_RETURN ((LM_ERROR
,
146 "Error: Narrow failed.\n"),
150 CosNotifyChannelAdmin::ConsumerAdmin_var admin
=
151 create_consumeradmin (ec
.in ());
153 if (CORBA::is_nil (admin
.in ()))
155 ACE_ERROR_RETURN ((LM_ERROR
,
156 "Error: nil ConsumerAdmin.\n"),
160 create_consumers (admin
.in (), &client
);
162 sig
->running (MonitorTestInterface::Consumer
);
164 ACE_DEBUG ((LM_DEBUG
, "\nConsumer waiting for events...\n"));
166 FILE* ready_file
= ACE_OS::fopen (ACE_TEXT_ALWAYS_CHAR(ready_output_file
), "w");
170 ACE_ERROR_RETURN ((LM_ERROR
,
171 "Cannot open ready file for writing\n"),
175 ACE_OS::fprintf (ready_file
, "ready\n");
176 ACE_OS::fclose (ready_file
);
180 _cputs( "All events received. Still connected.\n");
181 _cputs( "Hit a key to exit consumer: " );
183 #endif // PAUSE_ON_EXIT
184 ACE_DEBUG ((LM_DEBUG
, "Consumer done.\n"));
185 consumer_1
->disconnect ();
189 sig
->finished (MonitorTestInterface::Consumer
);
191 catch (const CORBA::Exception
& e
)
193 e
._tao_print_exception ("Consumer Error: ");