Merge pull request #2309 from mitza-oci/warnings
[ACE_TAO.git] / TAO / orbsvcs / tests / Trading / Offer_Importer.cpp
bloba9c4bfc2d5da065b2b37892c65ad3b41044c4668
1 #include "Offer_Importer.h"
3 TAO_Offer_Importer::TAO_Offer_Importer (CosTrading::Lookup_ptr lookup_if,
4 CORBA::Boolean verbose)
5 : verbose_ (verbose),
6 lookup_ (lookup_if)
10 void
11 TAO_Offer_Importer::perform_queries ()
13 ACE_DEBUG ((LM_DEBUG, "*** TAO_Offer_Importer::Federated Query.\n"));
15 TAO_Policy_Creator policies;
16 policies.exact_type_match (0);
17 policies.search_card (16*NUM_OFFERS);
18 policies.match_card (16*NUM_OFFERS);
19 policies.return_card (16*NUM_OFFERS);
20 policies.link_follow_rule (CosTrading::always);
21 this->perform_queries_with_policies (policies);
24 void
25 TAO_Offer_Importer::perform_directed_queries ()
27 ACE_DEBUG ((LM_DEBUG, "*** TAO_Offer_Importer::Directed Query.\n"));
29 TAO_Policy_Creator policies;
30 policies.exact_type_match (0);
31 policies.search_card (16*NUM_OFFERS);
32 policies.match_card (16*NUM_OFFERS);
33 policies.return_card (16*NUM_OFFERS);
34 policies.link_follow_rule (CosTrading::local_only);
36 if (this->verbose_)
37 ACE_DEBUG ((LM_DEBUG, "Obtaining link interface.\n"));
38 CosTrading::Link_var link_if = this->lookup_->link_if ();
40 if (this->verbose_)
42 ACE_DEBUG ((LM_DEBUG, "Obtaining references to traders directly"
43 " linked to the root trader.\n"));
45 CosTrading::LinkNameSeq_var link_name_seq = link_if->list_links ();
47 if (link_name_seq->length () > 0)
49 if (this->verbose_)
51 ACE_DEBUG ((LM_DEBUG, "Getting link information for %C\n",
52 static_cast<const char*> (link_name_seq[0u])));
55 CosTrading::Link::LinkInfo_var link_info =
56 link_if->describe_link (link_name_seq[0u]);
58 CosTrading::Lookup_ptr lookup_if = link_info->target.in ();
59 CosTrading::Link_var link_if2 = lookup_if->link_if ();
61 CosTrading::LinkNameSeq_var link_name_seq2 = link_if2->list_links ();
63 if (link_name_seq2->length () > 0)
65 CORBA::ULong i = 0;
66 CORBA::ULong length = link_name_seq2->length ();
67 for (i = 0; i < length; i++)
69 if (ACE_OS::strcmp (link_name_seq2[i], "Bootstrap") != 0)
70 break;
73 if (i < length)
75 CosTrading::LinkName* trader_name =
76 CosTrading::TraderName::allocbuf (2);
78 ACE_DEBUG ((LM_DEBUG, "*** Query through %C to destination %C.\n",
79 static_cast<const char*> (link_name_seq[0u]),
80 static_cast<const char*> (link_name_seq2[i])));
82 trader_name[0] = CORBA::string_dup (link_name_seq[0u]);
83 trader_name[1] = CORBA::string_dup (link_name_seq2[i]);
84 policies.starting_trader (new CosTrading::TraderName
85 (2, 2, trader_name, 1));
87 this->perform_queries_with_policies (policies);
90 else
92 ACE_ERROR ((LM_ERROR, ACE_TEXT("ERROR, This test requires a complete graph of three traders!\n")));
93 throw CORBA::BAD_INV_ORDER(); // Let outside world know we can't continue this way.
96 else
98 ACE_ERROR ((LM_ERROR, ACE_TEXT("ERROR, This test requires a complete graph of three traders!\n")));
99 throw CORBA::BAD_INV_ORDER(); // Let outside world know we can't continue this way.
104 void
105 TAO_Offer_Importer::perform_queries_with_policies (
106 const TAO_Policy_Creator& policies
111 CosTrading::Lookup::SpecifiedProps desired_props;
113 char* props[] =
115 (char*) TT_Info::REMOTE_IO_PROPERTY_NAMES[TT_Info::NAME],
116 (char*) TT_Info::REMOTE_IO_PROPERTY_NAMES[TT_Info::DESCRIPTION],
117 (char*) TT_Info::REMOTE_IO_PROPERTY_NAMES[TT_Info::LOCATION],
118 (char*) TT_Info::REMOTE_IO_PROPERTY_NAMES[TT_Info::HOST_NAME]
121 CosTrading::PropertyNameSeq prop_name_seq (4, 4, props, 0);
122 desired_props.prop_names (prop_name_seq);
124 for (int i = 0; i < TT_Info::NUM_QUERIES; i++)
126 ACE_DEBUG ((LM_DEBUG, "\n"));
127 ACE_DEBUG ((LM_DEBUG, "*** Performing query for %C.\n", TT_Info::QUERIES[i][0]));
128 ACE_DEBUG ((LM_DEBUG, "*** Query: %C\n", TT_Info::QUERIES[i][1]));
129 ACE_DEBUG ((LM_DEBUG, "*** Preferences: %C\n", TT_Info::QUERIES[i][2]));
130 CosTrading::OfferSeq_var offer_seq;
131 CosTrading::OfferIterator_var offer_iterator;
132 CosTrading::PolicyNameSeq_var limits_applied;
134 // Test with different how_many amount, both should work.
135 // Initially try to get this amount in the sequence.
136 CORBA::ULong how_many = 8;
137 if (i&0x0001)
139 how_many=0; // 0: Don't retrieve in offers but all in iterator.
142 this->lookup_->query (TT_Info::QUERIES[i][0],
143 TT_Info::QUERIES[i][1],
144 TT_Info::QUERIES[i][2],
145 policies.policy_seq (),
146 desired_props,
147 how_many,
148 offer_seq.out(),
149 offer_iterator.out(),
150 limits_applied.out());
152 CORBA::ULong seqlen = (offer_seq.ptr() == 0 ? 0 :
153 offer_seq->length ());
154 CORBA::ULong itrlen = (CORBA::is_nil(offer_iterator.in()) ? 0 :
155 offer_iterator->max_left ());
156 CORBA::ULong total = seqlen + itrlen;
157 CORBA::ULong expected = ACE_OS::atoi (TT_Info::QUERIES[i][3]);
159 if (total != expected)
161 ACE_ERROR ((LM_ERROR
162 ,"ERROR: Expected %d for query %d, got seq(%d) + itr(%d) = %d\n"
163 ,expected
165 ,seqlen
166 ,itrlen
167 ,total
169 throw CORBA::TRANSIENT(); // Try again later?
171 else if (this->verbose_)
173 ACE_DEBUG ((LM_DEBUG
174 ,"Expected %d for query %d, got seq(%d) + itr(%d) = %d\n"
175 ,expected
177 ,seqlen
178 ,itrlen
179 ,total
183 if (this->verbose_)
185 ACE_DEBUG ((LM_DEBUG, "*** Results:\n\n"));
186 this->display_results (*offer_seq.ptr(),
187 offer_iterator.in());
189 if (limits_applied->length () > 0)
190 ACE_DEBUG ((LM_DEBUG, "*** Limits Applied:\n\n"));
192 for (int length = limits_applied->length (), j = 0; j < length; j++)
194 const char *policy_name = (*limits_applied.ptr())[j];
195 ACE_DEBUG ((LM_DEBUG, "%C\n",
196 static_cast<const char*> (policy_name)));
201 catch (const CORBA::Exception& e)
203 e._tao_print_exception ("TAO_Offer_Importer::perform_queries_with_policies");
204 throw;
208 void
209 TAO_Offer_Importer::display_results (const CosTrading::OfferSeq& offer_seq,
210 CosTrading::OfferIterator_ptr offer_iterator) const
214 ACE_DEBUG ((LM_DEBUG, "------------------------------\n"));
215 ACE_DEBUG ((LM_DEBUG, "Offers in the sequence:\n"));
216 ACE_DEBUG ((LM_DEBUG, "------------------------------\n"));
217 for (CORBA::ULong i = 0; i < offer_seq.length (); i++)
219 // Call back to the exported object.
220 // FIXME: shouldn't this be done in a separate 'verify_results' method?
221 // (confirm () now skipped in quiet mode)
222 TAO_Trader_Test::Remote_Output_var remote_output =
223 TAO_Trader_Test::Remote_Output::_narrow (offer_seq[i].reference.in ());
225 remote_output->confirm ();
227 TT_Info::dump_properties (offer_seq[i].properties, 1);
228 ACE_DEBUG ((LM_DEBUG, "------------------------------\n"));
231 ACE_DEBUG ((LM_DEBUG, " Offers in the iterator:\n"));
232 ACE_DEBUG ((LM_DEBUG, "------------------------------\n"));
233 if (! CORBA::is_nil (offer_iterator))
235 CORBA::Boolean any_left = 0;
238 CosTrading::OfferSeq_var offers;
239 // Use of iterator->max_left() to get all iterator results is not
240 // recommended? (see p.879 Advanced CORBA programming book)
241 // Howmany to process is a choice between next_n call 'dispatch
242 // costs' and 'larges results marshalling bandwidth costs'.
243 CORBA::ULong how_many = 100;
244 any_left = offer_iterator->next_n (how_many, offers.out());
246 for (CORBA::ULong i = 0; i < offers->length (); i++)
248 // Call back to the exported object.
249 // FIXME: shouldn't this be done in a separate 'verify_results' method?
250 // (confirm () now skipped in quiet mode)
251 TAO_Trader_Test::Remote_Output_var remote_output =
252 TAO_Trader_Test::Remote_Output::_narrow ((*offers)[i].reference.in ());
254 remote_output->confirm ();
256 CosTrading::PropertySeq& props = (*offers)[i].properties;
257 TT_Info::dump_properties (props, 1);
259 ACE_DEBUG ((LM_DEBUG, "------------------------------\n"));
262 } while (any_left);
264 offer_iterator->destroy ();
267 catch (const CORBA::Exception& e)
269 e._tao_print_exception ("TAO_Offer_Importer::display_results");
270 throw;