1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
|
#include "orbsvcs/CosNotifyChannelAdminC.h"
#include "orbsvcs/CosNotifyChannelAdminS.h"
#include <iostream>
const char *ior = "file://ecf.ior";
CosNotifyChannelAdmin::EventChannel_var
get_event_channel(CORBA::ORB_ptr orb)
{
CosNotifyChannelAdmin::EventChannel_var ec;
CosNotifyChannelAdmin::ChannelID id;
CosNotification::QoSProperties init_qos(0);
CosNotification::AdminProperties init_admin(0);
std::cout << "Get CosNotifyChannelAdmin::EventChannelFactory" << std::endl;
std::cout << "IorEventChannelFactory=" << ior << std::endl;
CORBA::Object_var obj = orb->string_to_object(ior);
if (CORBA::is_nil(obj.in ()))
{
std::cerr << "Bad ec_fact.ior " << std::endl;
exit(1);
}
CosNotifyChannelAdmin::EventChannelFactory_var factory =
CosNotifyChannelAdmin::EventChannelFactory::_narrow(obj.in ());
if (CORBA::is_nil(factory.in()))
{
std::cerr << "Could not _narrow object to type CosNotifyChannelAdmin::EventChannelFactory" << std::endl;
exit(1);
}
//Get the first ec
CosNotifyChannelAdmin::ChannelIDSeq_var channelIdSeq;
try
{
channelIdSeq = factory->get_all_channels();
}
catch (const CORBA::SystemException& se )
{
std::cerr << "System exception occurred during get_all_channels: "
<< se << std::endl;
exit(1);
}
if( channelIdSeq->length() == 0 )
{
try
{
ec = factory->create_channel( init_qos, init_admin, id);
}
catch (const CORBA::SystemException& se )
{
std::cerr << "System exception occurred during find_channel: "
<< se << std::endl;
exit(1);
}
}
else {
try
{
ec = factory->get_event_channel(channelIdSeq.in()[0]);
}
catch (CosNotifyChannelAdmin::ChannelNotFound&)
{
std::cerr << "ChannelNotFound: "
<< channelIdSeq.in()[0] << std::endl;
exit(1);
}
catch (const CORBA::SystemException& se )
{
std::cerr << "System exception occurred during get_event_channel: "
<< se << std::endl;
exit(1);
}
}
return ec._retn();
}
void match_structure_test (const CosNotifyFilter::Filter_var& filter,
const CosNotification::StructuredEvent& event,
bool & expected_result)
{
bool bResult = false;
try{
bResult = filter->match_structured(event);
}
catch(CosNotifyFilter::UnsupportedFilterableData&)
{
std::cerr << "UnsupportedFilterableData!" << std::endl;
}
catch (const CORBA::SystemException& se )
{
std::cerr << "System exception occurred during match_structured: "
<< se << std::endl;
exit(1);
}
std::cout << "The result is:" << (bResult?"Match":"Unmatch") << std::endl;
if (bResult != expected_result)
{
// The result should be unmatched as it's filtered with event type.
std::cerr << "filter test failed." << std::endl;
exit(1);
}
}
void update_constraints (const CosNotifyFilter::Filter_var& filter,
const char* domain1, const char* type1,
const char* domain2, const char* type2)
{
filter->remove_all_constraints ();
CosNotification::EventTypeSeq event_types(2);
event_types.length(2);
event_types[0].domain_name = CORBA::string_dup(domain1);
event_types[0].type_name = CORBA::string_dup(type1);
event_types[1].domain_name = CORBA::string_dup(domain2);
event_types[1].type_name = CORBA::string_dup(type2);
CosNotifyFilter::ConstraintExpSeq constraints(1);
constraints.length(1);
constraints[0].event_types = event_types;
constraints[0].constraint_expr = CORBA::string_dup("");
CosNotifyFilter::ConstraintInfoSeq_var cons_info
= filter->add_constraints(constraints);
std::cout << "Constructing a filter..." << std::endl;
for (CORBA::ULong i = 0; i < event_types.length(); ++i)
{
std::cout << "\tevent_types[" << i << "].domain_name="
<< event_types[i].domain_name
<< std::endl;
std::cout << "\tevent_types[" << i << "].type_name="
<< event_types[i].type_name
<< std::endl;
}
std::cout << "\tIts constraint ="
<< constraints[0].constraint_expr.in ()
<< std::endl;
}
int ACE_TMAIN (int argc, ACE_TCHAR *argv[])
{
try
{
PortableServer::POAManager_var poa_manager;
CORBA::ORB_var orb = CORBA::ORB_init(argc, argv);
CORBA::Object_var poa_obj = orb->resolve_initial_references("RootPOA");
PortableServer::POA_var root_poa = PortableServer::POA::_narrow(poa_obj.in());
poa_manager = root_poa->the_POAManager();
poa_manager->activate();
/*Get event_channel*/
std::cout << "Get event_channel now" << std::endl;
CosNotifyChannelAdmin::EventChannel_var ec = get_event_channel(orb.in());
//Attaching a filter to pps
CosNotifyFilter::FilterFactory_var dff =
ec->default_filter_factory();
ACE_ASSERT(!CORBA::is_nil(dff.in()));
std::cout << "Test CosNotifyFilter::Filter::match_structured" << std::endl;
//Constructing a test event
CosNotification::StructuredEvent event;
event.header.fixed_header.event_type.domain_name =
CORBA::string_dup("Test_domain");
event.header.fixed_header.event_type.type_name =
CORBA::string_dup("Test_type_name");
event.header.variable_header.length(0);
event.remainder_of_body <<= "";
std::cout << "Constructing a test event" << std::endl;
std::cout << "\tIts header.fixed_header.event_type.domain_name="
<< event.header.fixed_header.event_type.domain_name
<< std::endl;
std::cout << "\tIts header.fixed_header.event_type.type_name="
<< event.header.fixed_header.event_type.type_name
<< std::endl;
CosNotifyFilter::Filter_var filter = dff->create_filter("EXTENDED_TCL");
update_constraints (filter, "DomainA", "TypeA", "DomainB", "TypeB");
bool expected_result = false;
match_structure_test (filter, event, expected_result);
update_constraints (filter, "*", "%ALL", "DomainB", "TypeB");
expected_result = true;
match_structure_test (filter, event, expected_result);
update_constraints (filter, "Test_domain", "%ALL", "DomainB", "TypeB");
expected_result = true;
match_structure_test (filter, event, expected_result);
update_constraints (filter, "*", "Test_type_name", "DomainB", "TypeB");
expected_result = true;
match_structure_test (filter, event, expected_result);
update_constraints (filter, "*", "*", "*", "*");
expected_result = true;
match_structure_test (filter, event, expected_result);
orb->shutdown();
}
catch(...)
{
std::cerr << "Filter: Some exceptions was caught!" << std::endl;
exit(1);
}
return 0;
}
|