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 "Notify_Push_Consumer.h"
13 #include "Notify_Test_Client.h"
17 // ******************************************************************
19 // ******************************************************************
21 static const ACE_TCHAR
*ior
= ACE_TEXT ("file://supplier.ior");
22 static unsigned int expect_fail
= 0;
23 static Notify_Push_Consumer
* consumer_1
= 0;
25 // ******************************************************************
27 // ******************************************************************
29 class Consumer_Client
: public Notify_Test_Client
32 virtual int parse_args (int argc
, ACE_TCHAR
*argv
[]);
37 Consumer_Client::parse_args (int argc
, ACE_TCHAR
*argv
[])
39 ACE_Get_Opt
get_opts (argc
, argv
, ACE_TEXT("k:l:h:d:f:"));
42 while ((c
= get_opts ()) != -1)
46 ior
= get_opts
.optarg
;
50 expect_fail
= ACE_OS::atoi (get_opts
.optarg
);
54 ACE_ERROR_RETURN ((LM_ERROR
,
57 "-f <expect failure> "
62 // Indicates successful parsing of the command line
66 static CosNotifyFilter::Filter_ptr
67 create_proxyFilter (CosNotifyChannelAdmin::EventChannel_ptr ec
)
69 CosNotifyFilter::FilterFactory_var ffact
=
70 ec
->default_filter_factory ();
72 CosNotifyFilter::Filter_var filter
=
73 ffact
->create_filter ("EXTENDED_TCL");
75 if(!CORBA::is_nil(filter
.in()))
77 CosNotifyFilter::ConstraintExpSeq
constraint_list (1);
78 constraint_list
.length(1);
80 constraint_list
[0].event_types
.length (0);
82 constraint_list
[0].constraint_expr
=
83 CORBA::string_dup ("$.domain_name == 'domain1'");
85 CosNotifyFilter::ConstraintInfoSeq_var cons_info
= filter
->add_constraints (constraint_list
);
87 return filter
._retn();
91 create_consumers (CosNotifyChannelAdmin::ConsumerAdmin_ptr admin
,
92 Notify_Test_Client
* client
,
93 CosNotifyFilter::Filter_ptr filter
)
95 // startup the consumer
96 ACE_NEW_THROW_EX (consumer_1
,
97 Notify_Push_Consumer (*client
),
100 consumer_1
->init (client
->root_poa ());
102 consumer_1
->_connect (admin
, filter
);
105 // ******************************************************************
107 // ******************************************************************
109 int ACE_TMAIN (int argc
, ACE_TCHAR
*argv
[])
114 Consumer_Client client
;
116 status
= client
.init (argc
, argv
);
120 CosNotifyChannelAdmin::EventChannel_var ec
=
121 client
.create_event_channel ("MyEventChannel", 1);
123 CORBA::ORB_ptr orb
= client
.orb ();
124 CORBA::Object_var object
=
125 orb
->string_to_object (ior
);
127 sig_var sig
= sig::_narrow (object
.in ());
129 if (CORBA::is_nil (sig
.in ()))
131 ACE_ERROR_RETURN ((LM_ERROR
,
132 "Object reference <%s> is nil\n",
137 CosNotifyChannelAdmin::ConsumerAdmin_var admin
=
138 ec
->default_consumer_admin();
140 CosNotifyFilter::Filter_var filter
=
141 create_proxyFilter (ec
.in());
143 if (!CORBA::is_nil (admin
.in ()))
145 create_consumers (admin
.in (), &client
, filter
.in());
147 // Tell the supplier to go
150 ACE_Time_Value
tv(10, 0);
152 ACE_DEBUG((LM_DEBUG
, "Consumer done.\n"));
156 ACE_DEBUG((LM_DEBUG
, "Expected %d message(s) and received %d message(s).\n",
157 expect_fail
== 1 ? 0 : 1, consumer_1
->messages_received()));
159 if (1 == expect_fail
)
160 status
= consumer_1
->messages_received() == 0 ? 0 : 1;
162 status
= consumer_1
->messages_received() == 1 ? 0 : 1;
164 ACE_DEBUG((LM_DEBUG
, "Test status is %s.\n", status
== 1 ? "fail" : "pass"));
168 catch (const CORBA::Exception
& e
)
170 e
._tao_print_exception ("Error: Consumer exception: ");