Revert "Use a variable on the stack to not have a temporary in the call"
[ACE_TAO.git] / TAO / orbsvcs / tests / Notify / Bug_2415_Regression / Consumer.cpp
blob22e031184dfa4808538e6381b60155b5c4f4ff67
1 // ******************************************************************
2 // Include Section
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"
11 #include "goC.h"
13 #include "Notify_Test_Client.h"
15 #define TEST_OP 1
17 // ******************************************************************
18 // Data Section
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 // ******************************************************************
26 // Subroutine Section
27 // ******************************************************************
29 class Consumer_Client : public Notify_Test_Client
31 public:
32 virtual int parse_args (int argc, ACE_TCHAR *argv[]);
36 int
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:"));
40 int c;
42 while ((c = get_opts ()) != -1)
43 switch (c)
45 case 'k':
46 ior = get_opts.optarg;
47 break;
49 case 'f':
50 expect_fail = ACE_OS::atoi (get_opts.optarg);
51 break;
53 default:
54 ACE_ERROR_RETURN ((LM_ERROR,
55 "usage: %s "
56 "-k <ior> "
57 "-f <expect failure> "
58 "\n",
59 argv [0]),
60 -1);
62 // Indicates successful parsing of the command line
63 return 0;
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();
90 static void
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),
98 CORBA::NO_MEMORY ());
100 consumer_1->init (client->root_poa ());
102 consumer_1->_connect (admin, filter);
105 // ******************************************************************
106 // Main Section
107 // ******************************************************************
109 int ACE_TMAIN (int argc, ACE_TCHAR *argv[])
111 int status = 0;
114 Consumer_Client client;
116 status = client.init (argc, argv);
118 if (status == 0)
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",
133 ior),
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
148 sig->go ();
150 ACE_Time_Value tv(10, 0);
151 client.ORB_run(tv);
152 ACE_DEBUG((LM_DEBUG, "Consumer done.\n"));
154 sig->done ();
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;
161 else
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: ");
171 status = 1;
174 return status;