1 #include "Offer_Exporter.h"
2 #include "ace/INET_Addr.h"
3 #include "ace/OS_NS_stdio.h"
6 TAO_Offer_Exporter (CosTrading::Lookup_ptr lookup_if
,
7 CORBA::Boolean verbose
)
10 // Initialize the offer sequences and structures.
11 this->create_offers ();
13 // Obtain the necessary trading service interfaces.
14 this->register_
= lookup_if
->register_if ();
15 this->admin_
= lookup_if
->admin_if ();
18 TAO_Offer_Exporter::~TAO_Offer_Exporter (void)
20 while (! this->clean_up_
.is_empty ())
22 TAO_Dynamic_Property
* dp
= 0;
23 this->clean_up_
.dequeue_head (dp
);
29 TAO_Offer_Exporter::export_offers (void)
31 ACE_DEBUG ((LM_DEBUG
, "*** TAO_Offer_Exporter::Exporting offers.\n"));
33 // Set the PROPERTY_NAMES - TRADER_NAME.
34 for (int i
= 0; i
< NUM_OFFERS
; i
++)
36 this->props_plotters_
[i
][4].value
<<= "Default";
37 this->props_printers_
[i
][4].value
<<= "Default";
38 this->props_fs_
[i
][4].value
<<= "Default";
41 this->export_to (this->register_
.in ());
45 TAO_Offer_Exporter::export_to (CosTrading::Register_ptr reg
)
49 for (int i
= 0; i
< NUM_OFFERS
; i
++)
51 TAO_Trader_Test::Plotter_var pPlotter
= this->plotter_
[i
]._this ();
52 CosTrading::OfferId_var offer_id
=
53 reg
->_cxx_export (pPlotter
.in(),
54 TT_Info::INTERFACE_NAMES
[1],
55 this->props_plotters_
[i
]);
59 ACE_DEBUG ((LM_DEBUG
, "Registered offer id: %C.\n", offer_id
.in ()));
62 TAO_Trader_Test::Printer_var pPrinter
= this->printer_
[i
]._this ();
63 offer_id
= reg
->_cxx_export (pPrinter
.in(),
64 TT_Info::INTERFACE_NAMES
[2],
65 this->props_printers_
[i
]);
69 ACE_DEBUG ((LM_DEBUG
, "Registered offer id: %C.\n", offer_id
.in ()));
72 TAO_Trader_Test::File_System_var pFileSystem
= this->fs_
[i
]._this ();
73 offer_id
= reg
->_cxx_export (pFileSystem
.in(),
74 TT_Info::INTERFACE_NAMES
[3],
79 ACE_DEBUG ((LM_DEBUG
, "Registered offer id: %C.\n", offer_id
.in ()));
83 catch (const CORBA::Exception
& e
)
85 e
._tao_print_exception ("TAO_Offer_Exporter::export_to");
91 TAO_Offer_Exporter::export_offers_to_all (void)
93 ACE_DEBUG ((LM_DEBUG
, "*** TAO_Offer_Exporter::Exporting to all.\n"));
97 ACE_DEBUG ((LM_DEBUG
, "Obtaining link interface.\n"));
100 CosTrading::Link_var link_if
= this->register_
->link_if ();
104 ACE_DEBUG ((LM_DEBUG
, "Obtaining references to traders directly"
105 " linked to the root trader.\n"));
108 CosTrading::LinkNameSeq_var link_name_seq
= link_if
->list_links ();
112 ACE_DEBUG ((LM_DEBUG
, "Registering offers with each of the linked"
116 for (CORBA::ULong i
= link_name_seq
->length () - 1; i
> 0; i
--)
122 ACE_DEBUG ((LM_DEBUG
, "Getting link information for %C\n",
123 static_cast<const char*> (link_name_seq
[i
])));
126 CosTrading::Link::LinkInfo_var link_info
=
127 link_if
->describe_link (link_name_seq
[i
]);
129 // Set the PROPERTY_NAMES - TRADER_NAME.
130 for (int j
= 0; j
< NUM_OFFERS
; j
++)
132 this->props_plotters_
[j
][4].value
<<= link_name_seq
[i
];
133 this->props_printers_
[j
][4].value
<<= link_name_seq
[i
];
134 this->props_fs_
[j
][4].value
<<= link_name_seq
[i
];
139 ACE_DEBUG ((LM_DEBUG
, "Exporting offers to %C\n",
140 static_cast<const char*> (link_name_seq
[i
])));
143 this->export_to (link_info
->target_reg
.in ());
145 catch (const CORBA::Exception
& e
)
147 e
._tao_print_exception ("TAO_Offer_Exporter::export_offers_to_all");
155 TAO_Offer_Exporter::withdraw_offers (void)
157 ACE_DEBUG ((LM_DEBUG
, "*** TAO_Offer_Exporter::Withdrawing all offers.\n"));
163 CosTrading::OfferIdSeq_var offer_id_seq
= this->grab_offerids ();
165 if (offer_id_seq
.ptr () != 0)
167 length
= offer_id_seq
->length ();
168 for (CORBA::ULong i
= 0; i
< length
; i
++)
170 this->register_
->withdraw (offer_id_seq
[i
]);
174 catch (const CORBA::Exception
& e
)
176 e
._tao_print_exception ("TAO_Offer_Exporter::withdraw_offers");
182 TAO_Offer_Exporter::describe_offers (void)
184 ACE_DEBUG ((LM_DEBUG
, "*** TAO_Offer_Exporter::Describing all offers.\n"));
189 CosTrading::OfferIdSeq_var offer_id_seq
= this->grab_offerids ();
191 if (offer_id_seq
.ptr () != 0)
193 length
= offer_id_seq
->length ();
196 ACE_DEBUG ((LM_DEBUG
, "------------------------------\n"));
198 for (CORBA::ULong i
= 0; i
< length
; i
++)
200 CosTrading::Register::OfferInfo_var offer_info
=
201 this->register_
->describe (offer_id_seq
[i
]);
205 ACE_DEBUG ((LM_DEBUG
, "Offer Id: %C\n", (const char *) offer_id_seq
[i
]));
206 ACE_DEBUG ((LM_DEBUG
, "Service Type: %C\n", offer_info
->type
.in ()));
207 TT_Info::dump_properties (offer_info
->properties
, 0);
208 ACE_DEBUG ((LM_DEBUG
, "------------------------------\n"));
213 catch (const CORBA::Exception
& e
)
215 e
._tao_print_exception ("TAO_Offer_Exporter::describe_offers");
221 TAO_Offer_Exporter::modify_offers (void)
223 ACE_DEBUG ((LM_DEBUG
, "*** TAO_Offer_Exporter::Modifying all offers.\n"));
227 CosTrading::OfferIdSeq_var offer_id_seq
= this->grab_offerids ();
229 if (offer_id_seq
.ptr () != 0)
231 CORBA::ULong length
= offer_id_seq
->length ();
232 CosTrading::PropertyNameSeq del_list
;
233 CosTrading::PropertySeq modify_list
;
236 modify_list
.length (2);
237 del_list
[0] = TT_Info::REMOTE_IO_PROPERTY_NAMES
[TT_Info::DESCRIPTION
];
238 modify_list
[0].name
= TT_Info::REMOTE_IO_PROPERTY_NAMES
[TT_Info::LOCATION
];
239 modify_list
[0].value
<<= "MODIFIED";
240 modify_list
[1].name
= TT_Info::REMOTE_IO_PROPERTY_NAMES
[TT_Info::MISCELLANEOUS
];
241 modify_list
[1].value
<<= "MODIFIED";
243 for (CORBA::ULong i
= 0; i
< length
; i
++)
245 this->register_
->modify (offer_id_seq
[i
],
251 catch (const CORBA::Exception
& e
)
253 e
._tao_print_exception ("TAO_Offer_Exporter::modify_offers");
260 withdraw_offers_using_constraints (void)
262 ACE_DEBUG ((LM_DEBUG
, "*** TAO_Offer_Exporter::Withdrawing with constraint.\n"));
264 const char* constraint
=
265 "(not exist Description) and (Location == 'MODIFIED') and (exist Name)";
268 ACE_DEBUG ((LM_DEBUG
, "Constraint: %C\n", constraint
));
273 withdraw_using_constraint (TT_Info::INTERFACE_NAMES
[TT_Info::PLOTTER
],
277 withdraw_using_constraint (TT_Info::INTERFACE_NAMES
[TT_Info::PRINTER
],
281 withdraw_using_constraint (TT_Info::INTERFACE_NAMES
[TT_Info::FILESYSTEM
],
284 catch (const CORBA::Exception
& e
)
286 e
._tao_print_exception ("TAO_Offer_Exporter::withdraw_offers_using_constraints");
291 CosTrading::OfferIdSeq
*
292 TAO_Offer_Exporter::grab_offerids (void)
295 ACE_DEBUG ((LM_DEBUG
, "TAO_Offer_Exporter::Grabbing all offer ids.\n"));
297 CosTrading::OfferIdSeq_var offer_id_seq_result
;
300 CORBA::ULong length
= NUM_OFFERS
;
301 CosTrading::OfferIdIterator_var offer_id_iter
;
303 this->admin_
->list_offers (NUM_OFFERS
,
304 offer_id_seq_result
.out(),
305 offer_id_iter
.out());
307 // We might already have seq results but may have to process additional
308 // iterator result fragments.
309 if (!CORBA::is_nil (offer_id_iter
.in()))
311 CosTrading::OfferIdSeq_var offer_id_seq_remaining
;
312 CORBA::Boolean any_left
= 0;
316 offer_id_iter
->next_n (length
,
317 offer_id_seq_remaining
.out());
319 // Grow our result sequence with the remaining fragments.
320 CORBA::ULong offers
= offer_id_seq_remaining
->length ();
321 CORBA::ULong old_length
= offer_id_seq_result
->length ();
322 offer_id_seq_result
->length (old_length
+ offers
);
324 for (CORBA::ULong i
= 0; i
< offers
; i
++)
326 offer_id_seq_result
[i
+ old_length
] = CORBA::string_dup (offer_id_seq_remaining
[i
].in ());
332 offer_id_iter
->destroy ();
337 ACE_DEBUG ((LM_DEBUG
, "The following offer ids are registered:\n"));
338 for (CORBA::ULong i
=0; i
<offer_id_seq_result
->length(); i
++)
339 ACE_DEBUG ((LM_DEBUG
, "Offer Id: %C\n", offer_id_seq_result
[i
].in()));
342 catch (const CORBA::Exception
& e
)
344 e
._tao_print_exception ("TAO_Offer_Exporter::grab_offerids");
349 return offer_id_seq_result
._retn();
353 TAO_Offer_Exporter::create_offers (void)
355 ACE_DEBUG ((LM_DEBUG
, "*** TAO_Offer_Exporter::Creating offers.\n"));
356 const int QUEUE_SIZE
= 4;
358 int counter
= 0, i
= 0;
360 char description
[BUFSIZ
];
361 CORBA::Any extra_info
;
362 TAO_Trader_Test::StringSeq
string_seq (QUEUE_SIZE
);
363 TAO_Trader_Test::ULongSeq
ulong_seq (QUEUE_SIZE
);
365 CosTradingDynamic::DynamicProp
* dp_user_queue
;
366 CosTradingDynamic::DynamicProp
* dp_file_queue
;
367 CosTradingDynamic::DynamicProp
* dp_space_left
;
369 ACE_INET_Addr
addr ((u_short
) 0);
370 const char* hostname
= addr
.get_host_name ();
372 // Initialize plotters
373 string_seq
.length (QUEUE_SIZE
);
374 ulong_seq
.length (QUEUE_SIZE
);
375 for (i
= 0; i
< NUM_OFFERS
; i
++)
377 ACE_OS::sprintf (name
, "Plotter #%d", i
);
378 ACE_OS::sprintf (description
,
379 "%s is a plotter. It plots stuff.",
382 for (int j
= 0; j
< QUEUE_SIZE
; j
++, counter
= (counter
+ 1) % NUM_OFFERS
)
384 string_seq
[j
] = TT_Info::USERS
[counter
];
385 ulong_seq
[j
] = counter
* 10000;
388 TAO_Dynamic_Property
* user_queue
=
389 new TAO_Simple_Dynamic_Property
<TAO_Trader_Test::StringSeq
> (string_seq
);
390 TAO_Dynamic_Property
* file_sizes
=
391 new TAO_Simple_Dynamic_Property
<TAO_Trader_Test::ULongSeq
> (ulong_seq
);
393 this->clean_up_
.enqueue_head (user_queue
);
394 this->clean_up_
.enqueue_head (file_sizes
);
396 dp_user_queue
= user_queue
->construct_dynamic_prop
397 (TT_Info::PLOTTER_PROPERTY_NAMES
[TT_Info::PLOTTER_USER_QUEUE
],
398 TAO_Trader_Test::_tc_StringSeq
,
401 dp_file_queue
= file_sizes
->construct_dynamic_prop
402 (TT_Info::PLOTTER_PROPERTY_NAMES
[TT_Info::PLOTTER_FILE_SIZES_PENDING
],
403 TAO_Trader_Test::_tc_ULongSeq
,
406 this->props_plotters_
[i
].length (11);
407 this->props_plotters_
[i
][0].name
= TT_Info::REMOTE_IO_PROPERTY_NAMES
[TT_Info::NAME
];
408 this->props_plotters_
[i
][0].value
<<= name
;
409 this->props_plotters_
[i
][1].name
= TT_Info::REMOTE_IO_PROPERTY_NAMES
[TT_Info::LOCATION
];
410 this->props_plotters_
[i
][1].value
<<= TT_Info::LOCATIONS
[i
];
411 this->props_plotters_
[i
][2].name
= TT_Info::REMOTE_IO_PROPERTY_NAMES
[TT_Info::DESCRIPTION
];
412 this->props_plotters_
[i
][2].value
<<= description
;
413 this->props_plotters_
[i
][3].name
= TT_Info::REMOTE_IO_PROPERTY_NAMES
[TT_Info::HOST_NAME
];
414 this->props_plotters_
[i
][3].value
<<= hostname
;
415 this->props_plotters_
[i
][4].name
= TT_Info::REMOTE_IO_PROPERTY_NAMES
[TT_Info::TRADER_NAME
];
416 this->props_plotters_
[i
][4].value
<<= "Default";
417 this->props_plotters_
[i
][5].name
= TT_Info::PLOTTER_PROPERTY_NAMES
[TT_Info::PLOTTER_NUM_COLORS
];
418 this->props_plotters_
[i
][5].value
<<= (CORBA::Long
)(i
* 2);
419 this->props_plotters_
[i
][6].name
= TT_Info::PLOTTER_PROPERTY_NAMES
[TT_Info::PLOTTER_AUTO_LOADING
];
420 this->props_plotters_
[i
][6].value
<<= CORBA::Any::from_boolean ((CORBA::Boolean
) (i
% 2));
421 this->props_plotters_
[i
][7].name
= TT_Info::PLOTTER_PROPERTY_NAMES
[TT_Info::PLOTTER_COST_PER_PAGE
];
422 this->props_plotters_
[i
][7].value
<<= (CORBA::Float
) i
;
423 this->props_plotters_
[i
][8].name
= TT_Info::PLOTTER_PROPERTY_NAMES
[TT_Info::PLOTTER_MODEL_NUMBER
];
424 this->props_plotters_
[i
][8].value
<<= TT_Info::MODEL_NUMBERS
[i
];
425 this->props_plotters_
[i
][9].name
= TT_Info::PLOTTER_PROPERTY_NAMES
[TT_Info::PLOTTER_USER_QUEUE
];
426 this->props_plotters_
[i
][9].value
<<= dp_user_queue
;
428 this->props_plotters_
[i
][10].name
= TT_Info::PLOTTER_PROPERTY_NAMES
[TT_Info::PLOTTER_FILE_SIZES_PENDING
];
429 this->props_plotters_
[i
][10].value
<<= dp_file_queue
;
432 // Initialize printers
433 for (i
= 0; i
< NUM_OFFERS
; i
++)
435 ACE_OS::sprintf (name
, "Printer #%d", i
);
436 ACE_OS::sprintf (description
,
437 "%s is a printer. It prints stuff.",
440 for (int j
= 0; j
< QUEUE_SIZE
; j
++, counter
= (counter
+ 1) % NUM_OFFERS
)
442 string_seq
[j
] = TT_Info::USERS
[counter
];
443 ulong_seq
[j
] = counter
* 10000;
446 TAO_Dynamic_Property
* user_queue
=
447 new TAO_Simple_Dynamic_Property
<TAO_Trader_Test::StringSeq
> (string_seq
);
448 TAO_Dynamic_Property
* file_sizes
=
449 new TAO_Simple_Dynamic_Property
<TAO_Trader_Test::ULongSeq
> (ulong_seq
);
451 this->clean_up_
.enqueue_head (user_queue
);
452 this->clean_up_
.enqueue_head (file_sizes
);
454 dp_user_queue
= user_queue
->construct_dynamic_prop
455 (TT_Info::PRINTER_PROPERTY_NAMES
[TT_Info::PLOTTER_USER_QUEUE
],
456 TAO_Trader_Test::_tc_StringSeq
,
459 dp_file_queue
= file_sizes
->construct_dynamic_prop
460 (TT_Info::PRINTER_PROPERTY_NAMES
[TT_Info::PLOTTER_FILE_SIZES_PENDING
],
461 TAO_Trader_Test::_tc_ULongSeq
,
464 this->props_printers_
[i
].length (12);
465 this->props_printers_
[i
][0].name
= TT_Info::REMOTE_IO_PROPERTY_NAMES
[TT_Info::NAME
];
466 this->props_printers_
[i
][0].value
<<= name
;
467 this->props_printers_
[i
][1].name
= TT_Info::REMOTE_IO_PROPERTY_NAMES
[TT_Info::LOCATION
];
468 this->props_printers_
[i
][1].value
<<= TT_Info::LOCATIONS
[i
];
469 this->props_printers_
[i
][2].name
= TT_Info::REMOTE_IO_PROPERTY_NAMES
[TT_Info::DESCRIPTION
];
470 this->props_printers_
[i
][2].value
<<= description
;
471 this->props_printers_
[i
][3].name
= TT_Info::REMOTE_IO_PROPERTY_NAMES
[TT_Info::HOST_NAME
];
472 this->props_printers_
[i
][3].value
<<= hostname
;
473 this->props_printers_
[i
][4].name
= TT_Info::REMOTE_IO_PROPERTY_NAMES
[TT_Info::TRADER_NAME
];
474 this->props_printers_
[i
][4].value
<<= "Default";
475 this->props_printers_
[i
][5].name
= TT_Info::PRINTER_PROPERTY_NAMES
[TT_Info::PRINTER_COLOR
];
476 this->props_printers_
[i
][5].value
<<= CORBA::Any::from_boolean ((CORBA::Boolean
) (i
% 2));
477 this->props_printers_
[i
][6].name
= TT_Info::PRINTER_PROPERTY_NAMES
[TT_Info::PRINTER_DOUBLE_SIDED
];
478 this->props_printers_
[i
][6].value
<<= CORBA::Any::from_boolean ((CORBA::Boolean
) ((i
+ 1) % 2));
479 this->props_printers_
[i
][7].name
= TT_Info::PRINTER_PROPERTY_NAMES
[TT_Info::PRINTER_COST_PER_PAGE
];
480 this->props_printers_
[i
][7].value
<<= (CORBA::Float
) i
;
481 this->props_printers_
[i
][8].name
= TT_Info::PRINTER_PROPERTY_NAMES
[TT_Info::PRINTER_MODEL_NUMBER
];
482 this->props_printers_
[i
][8].value
<<= TT_Info::MODEL_NUMBERS
[i
];
483 this->props_printers_
[i
][9].name
= TT_Info::PRINTER_PROPERTY_NAMES
[TT_Info::PRINTER_PAGES_PER_SEC
];
484 this->props_printers_
[i
][9].value
<<= (CORBA::UShort
) i
;
485 this->props_printers_
[i
][10].name
= TT_Info::PRINTER_PROPERTY_NAMES
[TT_Info::PRINTER_USER_QUEUE
];
486 this->props_printers_
[i
][10].value
<<= dp_user_queue
;
487 this->props_printers_
[i
][11].name
= TT_Info::PRINTER_PROPERTY_NAMES
[TT_Info::PRINTER_FILE_SIZES_PENDING
];
488 this->props_printers_
[i
][11].value
<<= dp_file_queue
;
491 // Initialize FileSystem
492 for (i
= 0; i
< NUM_OFFERS
; i
++)
494 ACE_OS::sprintf (name
, "File System #%d", i
);
495 ACE_OS::sprintf (description
,
496 "%s is a File System. It stores stuff.",
499 TAO_Dynamic_Property
* space_left
=
500 new TAO_Simple_Dynamic_Property
<CORBA::ULong
> (i
* 4434343);
502 this->clean_up_
.enqueue_head (space_left
);
504 dp_space_left
= space_left
->construct_dynamic_prop
505 (TT_Info::FILESYSTEM_PROPERTY_NAMES
[TT_Info::SPACE_REMAINING
],
509 this->props_fs_
[i
].length (8);
510 this->props_fs_
[i
][0].name
= TT_Info::REMOTE_IO_PROPERTY_NAMES
[TT_Info::NAME
];
511 this->props_fs_
[i
][0].value
<<= name
;
512 this->props_fs_
[i
][1].name
= TT_Info::REMOTE_IO_PROPERTY_NAMES
[TT_Info::LOCATION
];
513 this->props_fs_
[i
][1].value
<<= TT_Info::LOCATIONS
[i
];
514 this->props_fs_
[i
][2].name
= TT_Info::REMOTE_IO_PROPERTY_NAMES
[TT_Info::DESCRIPTION
];
515 this->props_fs_
[i
][2].value
<<= description
;
516 this->props_fs_
[i
][3].name
= TT_Info::REMOTE_IO_PROPERTY_NAMES
[TT_Info::HOST_NAME
];
517 this->props_fs_
[i
][3].value
<<= hostname
;
518 this->props_fs_
[i
][4].name
= TT_Info::REMOTE_IO_PROPERTY_NAMES
[TT_Info::TRADER_NAME
];
519 this->props_fs_
[i
][4].value
<<= "Default";
520 this->props_fs_
[i
][5].name
= TT_Info::FILESYSTEM_PROPERTY_NAMES
[TT_Info::DISK_SIZE
];
521 this->props_fs_
[i
][5].value
<<= (CORBA::ULong
) (i
* 2000000);
522 this->props_fs_
[i
][6].name
= TT_Info::FILESYSTEM_PROPERTY_NAMES
[TT_Info::PERMISSION_LEVEL
];
523 this->props_fs_
[i
][6].value
<<= (CORBA::UShort
) (i
+ 1);
524 this->props_fs_
[i
][7].name
= TT_Info::FILESYSTEM_PROPERTY_NAMES
[TT_Info::SPACE_REMAINING
];
525 this->props_fs_
[i
][7].value
<<= dp_space_left
;