1 // ******************************************************************
3 // ******************************************************************
5 #include "ace/Get_Opt.h"
6 #include "ace/OS_NS_unistd.h"
8 #include "tao/ORB_Core.h"
10 #include "MonitorTestInterfaceC.h"
11 #include "Notify_StructuredPushSupplier.h"
12 #include "Notify_Test_Client.h"
14 // ******************************************************************
16 // ******************************************************************
18 static TAO_Notify_Tests_StructuredPushSupplier
* supplier_1
= 0;
19 static int max_events
= 2000;
20 static const ACE_TCHAR
*ior_output_file
= ACE_TEXT ("supplier.ior");
21 static const ACE_TCHAR
*ior
= ACE_TEXT ("file://test_monitor.ior");
23 // ******************************************************************
25 // ******************************************************************
27 class Supplier_Client
: public Notify_Test_Client
30 virtual int parse_args (int argc
, ACE_TCHAR
*argv
[]);
34 Supplier_Client::parse_args (int argc
, ACE_TCHAR
*argv
[])
36 ACE_Get_Opt
get_opts (argc
, argv
, ACE_TEXT("k:o:e:"));
39 while ((c
= get_opts ()) != -1)
43 ior
= get_opts
.optarg
;
47 max_events
= ACE_OS::atoi (get_opts
.optarg
);
51 ior_output_file
= get_opts
.optarg
;
55 ACE_ERROR_RETURN ((LM_ERROR
,
58 "-o <iorfile> -e <# of events> "
64 // Indicates successful parsing of the command line
69 static CosNotifyChannelAdmin::SupplierAdmin_ptr
70 create_supplieradmin (CosNotifyChannelAdmin::EventChannel_ptr ec
)
72 CosNotifyChannelAdmin::AdminID adminid
= 0;
73 CosNotifyChannelAdmin::SupplierAdmin_var admin
=
74 ec
->new_for_suppliers (CosNotifyChannelAdmin::AND_OP
, adminid
);
76 return CosNotifyChannelAdmin::SupplierAdmin::_duplicate (admin
.in ());
83 CosNotification::StructuredEvent event
;
85 event
.header
.fixed_header
.event_type
.domain_name
= CORBA::string_dup ("DOC_TAO");
86 event
.header
.fixed_header
.event_type
.type_name
= CORBA::string_dup ("examples");
88 event
.filterable_data
.length (1);
89 event
.filterable_data
[0].name
= CORBA::string_dup ("id");
90 event
.filterable_data
[0].value
<<= id
;
94 supplier_1
->send_event (event
);
96 catch (const CORBA::Exception
& e
)
98 e
._tao_print_exception ("Error: ");
103 create_suppliers (CosNotifyChannelAdmin::SupplierAdmin_ptr admin
,
104 PortableServer::POA_ptr poa
)
106 // startup the supplier
107 ACE_NEW_THROW_EX (supplier_1
,
108 TAO_Notify_Tests_StructuredPushSupplier (),
109 CORBA::NO_MEMORY ());
111 supplier_1
->init (poa
);
112 supplier_1
->connect (admin
);
114 CosNotification::EventTypeSeq
added (1);
115 CosNotification::EventTypeSeq
removed (1);
118 added
[0].domain_name
= CORBA::string_dup ("DOC_TAO");
119 added
[0].type_name
= CORBA::string_dup ("examples");
121 removed
[0].domain_name
= CORBA::string_dup ("*");
122 removed
[0].type_name
= CORBA::string_dup ("*");
124 supplier_1
->offer_change (added
, removed
);
128 // ******************************************************************
130 // ******************************************************************
132 int ACE_TMAIN (int argc
, ACE_TCHAR
*argv
[])
137 Supplier_Client client
;
138 status
= client
.init (argc
, argv
);
142 CosNotifyChannelAdmin::EventChannel_var ec
=
143 client
.create_event_channel ("MyEventChannel", 1);
145 CORBA::ORB_ptr orb
= client
.orb ();
146 CORBA::Object_var object
=
147 orb
->string_to_object (ior
);
149 MonitorTestInterface_var sig
=
150 MonitorTestInterface::_narrow (object
.in ());
152 if (CORBA::is_nil (sig
.in ()))
153 ACE_ERROR_RETURN ((LM_ERROR
, "Error: Structured Supplier: Narrow to MonitorTestInterface failed.\n"),1);
154 CosNotifyChannelAdmin::SupplierAdmin_var admin
=
155 create_supplieradmin (ec
.in ());
156 if (!CORBA::is_nil (admin
.in ()))
158 create_suppliers (admin
.in (), client
.root_poa ());
160 sig
->running (MonitorTestInterface::Supplier
);
161 ACE_DEBUG ((LM_DEBUG
,
162 "1 supplier sending %d events...\n", max_events
));
163 for (int i
= 0; i
< max_events
; ++i
)
165 ACE_DEBUG ((LM_DEBUG
, "+"));
168 ACE_DEBUG ((LM_DEBUG
,
169 "\nSupplier sent %d events.\n", max_events
));
170 sig
->finished (MonitorTestInterface::Supplier
);
171 supplier_1
->disconnect ();
175 catch (const CORBA::Exception
& e
)
177 e
._tao_print_exception ("Supplier Error: ");