#include <Offer_Database.h>
Collaboration diagram for TAO_Offer_Database< LOCK_TYPE >:
Public Types | |
typedef TAO_Service_Offer_Iterator< LOCK_TYPE > | offer_iterator |
typedef ACE_Hash_Map_Manager_Ex< CORBA::String_var, Offer_Map_Entry *, ACE_Hash< CORBA::String_var >, ACE_Equal_To< CORBA::String_var >, ACE_Null_Mutex > | Offer_Database |
Public Member Functions | |
TAO_Offer_Database (void) | |
No arg constructor. | |
~TAO_Offer_Database (void) | |
CosTrading::OfferId | insert_offer (const char *type, CosTrading::Offer *offer) |
int | remove_offer (const CosTrading::OfferId offer_id) throw (CosTrading::IllegalOfferId, CosTrading::UnknownOfferId) |
CosTrading::Offer * | lookup_offer (const CosTrading::OfferId offer_id) throw (CosTrading::IllegalOfferId, CosTrading::UnknownOfferId) |
CosTrading::Offer * | lookup_offer (const CosTrading::OfferId offer_id, char *&type_name) throw (CosTrading::IllegalOfferId, CosTrading::UnknownOfferId) |
TAO_Offer_Id_Iterator * | retrieve_all_offer_ids (void) |
Private Member Functions | |
CosTrading::Offer * | lookup_offer (const char *type, CORBA::ULong id) |
int | remove_offer (const char *type, CORBA::ULong id) |
void | operator= (const TAO_Offer_Database< LOCK_TYPE > &) |
TAO_Offer_Database (const TAO_Offer_Database< LOCK_TYPE > &) | |
Static Private Member Functions | |
CosTrading::OfferId | generate_offer_id (const char *type_name, CORBA::ULong id) |
void | parse_offer_id (const CosTrading::OfferId offer_id, char *&service_type, CORBA::ULong &id) throw (CosTrading::IllegalOfferId) |
Private Attributes | |
LOCK_TYPE | db_lock_ |
Offer_Database | offer_db_ |
Friends | |
class | TAO_Service_Offer_Iterator< LOCK_TYPE > |
Definition at line 51 of file Offer_Database.h.
|
Definition at line 111 of file Offer_Database.h. |
|
Definition at line 57 of file Offer_Database.h. |
|
No arg constructor.
Definition at line 13 of file Offer_Database.cpp.
00014 { 00015 } |
|
Definition at line 18 of file Offer_Database.cpp. References ACE_WRITE_GUARD, TAO_Offer_Database< LOCK_TYPE >::Offer_Map_Entry::lock_, and TAO_Offer_Database< LOCK_TYPE >::Offer_Map_Entry::offer_map_.
00019 { 00020 ACE_WRITE_GUARD (LOCK_TYPE, ace_mon, this->db_lock_); 00021 00022 for (ACE_TYPENAME Offer_Database::iterator type_iter (this->offer_db_); 00023 ! type_iter.done (); 00024 type_iter++) 00025 { 00026 Offer_Map_Entry* offer_map_entry = (*type_iter).int_id_; 00027 00028 { 00029 // Artificial scope, so the guard will release the lock before 00030 // we delete the lock along with the offer_map_entry. 00031 ACE_WRITE_GUARD (LOCK_TYPE, ace_mon, offer_map_entry->lock_); 00032 00033 for (TAO_Offer_Map::iterator offer_iter (*offer_map_entry->offer_map_); 00034 ! offer_iter.done (); 00035 offer_iter++) 00036 { 00037 // Delete all the offers in the offer map. 00038 CosTrading::Offer* offer = (*offer_iter).int_id_; 00039 delete offer; 00040 } 00041 00042 delete offer_map_entry->offer_map_; 00043 } 00044 00045 delete offer_map_entry; 00046 } 00047 } |
|
|
|
Take in a service type name for the offer the current value of of the counter and generate an offer id. Definition at line 301 of file Offer_Database.cpp. References CosTrading::OfferId, ACE_OS::sprintf(), CORBA::string_alloc(), CORBA::string_dup(), and ACE_OS::strlen(). Referenced by TAO_Service_Offer_Iterator< LOCK_TYPE >::get_id(), TAO_Offer_Database< LOCK_TYPE >::insert_offer(), and TAO_Offer_Database< LOCK_TYPE >::retrieve_all_offer_ids().
00302 { 00303 // holds final id string. 00304 size_t total_size = 16 + ACE_OS::strlen (service_type_name); 00305 00306 // hold portions of id string. 00307 CosTrading::OfferId offer_id = 00308 CORBA::string_alloc (static_cast<CORBA::ULong> (total_size)); 00309 char* return_value = 0; 00310 ACE_OS::sprintf (offer_id, "%016u%s", id, service_type_name); 00311 00312 return_value = CORBA::string_dup (offer_id); 00313 delete [] offer_id; 00314 00315 return return_value; 00316 } |
|
Add an offer of type and generate a CosTrading::OfferId for it. Returns 0 on failure. Definition at line 51 of file Offer_Database.cpp. References ACE_NEW_RETURN, ACE_READ_GUARD_RETURN, ACE_WRITE_GUARD_RETURN, ACE_Hash_Map_Manager_Ex< EXT_ID, INT_ID, HASH_KEY, COMPARE_KEYS, ACE_LOCK >::bind(), TAO_Offer_Database< LOCK_TYPE >::Offer_Map_Entry::counter_, TAO_Offer_Database< LOCK_TYPE >::db_lock_, ACE_Hash_Map_Manager_Ex< EXT_ID, INT_ID, HASH_KEY, COMPARE_KEYS, ACE_LOCK >::find(), TAO_Offer_Database< LOCK_TYPE >::generate_offer_id(), TAO_Offer_Database< LOCK_TYPE >::Offer_Map_Entry::lock_, TAO_Offer_Database< LOCK_TYPE >::offer_db_, TAO_Offer_Database< LOCK_TYPE >::Offer_Map_Entry::offer_map_, CosTrading::OfferId, and TAO_Offer_Map. Referenced by TAO_Register< TRADER_LOCK_TYPE, MAP_LOCK_TYPE >::_cxx_export().
00052 { 00053 CosTrading::OfferId return_value = 0; 00054 ACE_TYPENAME Offer_Database::ENTRY* database_entry = 0; 00055 CORBA::String_var service_type (type); 00056 00057 ACE_READ_GUARD_RETURN (LOCK_TYPE, ace_mon, this->db_lock_, 0); 00058 00059 if (this->offer_db_.find (service_type, database_entry) == -1) 00060 { 00061 // If there's no entry for the service type, create one. 00062 00063 Offer_Map_Entry* new_offer_map_entry = 0; 00064 ACE_NEW_RETURN (new_offer_map_entry, Offer_Map_Entry, 0); 00065 ACE_NEW_RETURN (new_offer_map_entry->offer_map_, TAO_Offer_Map, 0); 00066 new_offer_map_entry->counter_ = 1; 00067 00068 if (this->db_lock_.release () == -1) 00069 return 0; 00070 else 00071 { 00072 // Add the new entry; upgrade lock. 00073 ACE_WRITE_GUARD_RETURN (LOCK_TYPE, ace_mon, this->db_lock_, 0); 00074 this->offer_db_.bind (service_type, 00075 new_offer_map_entry, 00076 database_entry); 00077 } 00078 00079 if (this->db_lock_.acquire_read () == -1) 00080 return 0; 00081 } 00082 00083 Offer_Map_Entry* offer_map_entry = 00084 database_entry->int_id_; 00085 ACE_WRITE_GUARD_RETURN (LOCK_TYPE, ace_mon2, offer_map_entry->lock_, 0); 00086 00087 // Add the offer to the service offer table for this service type. 00088 offer_map_entry->offer_map_->bind (offer_map_entry->counter_, 00089 offer); 00090 return_value = this->generate_offer_id (type, 00091 offer_map_entry->counter_); 00092 offer_map_entry->counter_++; 00093 00094 return return_value; 00095 } |
|
Lookup an offer whose type is and id, . Return 0 on failure. Definition at line 217 of file Offer_Database.cpp. References ACE_READ_GUARD_RETURN, ACE_Hash_Map_Manager_Ex< EXT_ID, INT_ID, HASH_KEY, COMPARE_KEYS, ACE_LOCK >::find(), TAO_Offer_Database< LOCK_TYPE >::Offer_Map_Entry::lock_, TAO_Offer_Database< LOCK_TYPE >::offer_db_, and TAO_Offer_Database< LOCK_TYPE >::Offer_Map_Entry::offer_map_.
00218 { 00219 ACE_READ_GUARD_RETURN (LOCK_TYPE, ace_mon, this->db_lock_, 0); 00220 00221 CosTrading::Offer* return_value = 0; 00222 ACE_TYPENAME Offer_Database::ENTRY* db_entry = 0; 00223 CORBA::String_var service_type (type); 00224 00225 if (this->offer_db_.find (service_type, db_entry) == 0) 00226 { 00227 Offer_Map_Entry* offer_map_entry = db_entry->int_id_; 00228 ACE_READ_GUARD_RETURN (LOCK_TYPE, ace_mon, offer_map_entry->lock_, 0); 00229 00230 TAO_Offer_Map::ENTRY* offer_entry_ptr = 0; 00231 if (offer_map_entry->offer_map_->find (id, offer_entry_ptr) == 0) 00232 return_value = offer_entry_ptr->int_id_; 00233 } 00234 00235 return return_value; 00236 } |
|
Lookup an offer whose OfferId is and return in the type name of the object. Type name is just a pointer to a location in offer_id, so DON'T DELETE IT. Definition at line 177 of file Offer_Database.cpp. References ACE_CHECK_RETURN, ACE_ENV_ARG_PARAMETER, ACE_THROW_RETURN, and CosTrading::OfferId.
00182 { 00183 CORBA::ULong index; 00184 CosTrading::Offer* offer = 0; 00185 this->parse_offer_id (offer_id, type_name, index ACE_ENV_ARG_PARAMETER); 00186 ACE_CHECK_RETURN (offer); 00187 00188 if ((offer = this->lookup_offer (type_name, index)) == 0) 00189 ACE_THROW_RETURN (CosTrading::UnknownOfferId (offer_id), offer); 00190 00191 return offer; 00192 } |
|
Lookup an offer whose offer_id is , and return it. Otherwise, throw the appropriate exception. Definition at line 197 of file Offer_Database.cpp. References ACE_CHECK_RETURN, ACE_ENV_ARG_PARAMETER, ACE_THROW_RETURN, and CosTrading::OfferId. Referenced by TAO_Register< TRADER_LOCK_TYPE, MAP_LOCK_TYPE >::describe().
00201 { 00202 char* type_name; 00203 CORBA::ULong index; 00204 CosTrading::Offer* offer = 0; 00205 00206 this->parse_offer_id (offer_id, type_name, index ACE_ENV_ARG_PARAMETER); 00207 ACE_CHECK_RETURN (offer); 00208 00209 if ((offer = this->lookup_offer (type_name, index)) == 0) 00210 ACE_THROW_RETURN (CosTrading::UnknownOfferId (offer_id), offer); 00211 00212 return offer; 00213 } |
|
|
|
Take in a previously generated offer id and return the type and id that were used to generate the offer id. Definition at line 277 of file Offer_Database.cpp. References ACE_THROW, ACE_OS::atoi(), TAO_Trader_Base::is_valid_identifier_name(), and CosTrading::OfferId.
00282 { 00283 // Get service type: it is everything from 17th character to the end. 00284 service_type = (char *) offer_id + 16; 00285 00286 // Get id: temporarily put the end of string character where the service 00287 // type starts, convert to number, replace the character back. 00288 char* start_of_type = (char *) (offer_id + 16); 00289 char temp = *start_of_type; 00290 *start_of_type = '\0'; 00291 id = ACE_OS::atoi (offer_id); 00292 00293 *start_of_type = temp; 00294 00295 if (! TAO_Trader_Base::is_valid_identifier_name (service_type)) 00296 ACE_THROW (CosTrading::IllegalOfferId (offer_id)); 00297 } |
|
Remove an offers whose id is . Returns 0 on success, -1 on failure, and throws a CosTrading::IllegalOfferId if it can't parse the CosTrading::OfferId. Definition at line 99 of file Offer_Database.cpp. References ACE_READ_GUARD_RETURN, ACE_Hash_Map_Manager_Ex< EXT_ID, INT_ID, HASH_KEY, COMPARE_KEYS, ACE_LOCK >::current_size(), TAO_Offer_Database< LOCK_TYPE >::db_lock_, ACE_Hash_Map_Manager_Ex< EXT_ID, INT_ID, HASH_KEY, COMPARE_KEYS, ACE_LOCK >::find(), TAO_Offer_Database< LOCK_TYPE >::Offer_Map_Entry::lock_, TAO_Offer_Database< LOCK_TYPE >::offer_db_, TAO_Offer_Database< LOCK_TYPE >::Offer_Map_Entry::offer_map_, and ACE_Hash_Map_Manager_Ex< EXT_ID, INT_ID, HASH_KEY, COMPARE_KEYS, ACE_LOCK >::unbind().
00100 { 00101 ACE_READ_GUARD_RETURN (LOCK_TYPE, ace_mon, this->db_lock_, -1); 00102 00103 int return_value = -1; 00104 ACE_TYPENAME Offer_Database::ENTRY* db_entry = 0; 00105 CORBA::String_var service_type (type); 00106 00107 if (this->offer_db_.find (service_type, db_entry) == 0) 00108 { 00109 CosTrading::Offer* offer = 0; 00110 Offer_Map_Entry* offer_map_entry = db_entry->int_id_; 00111 00112 if (offer_map_entry->lock_.acquire_write () == -1) 00113 return -1; 00114 00115 return_value = offer_map_entry->offer_map_->unbind (id, offer); 00116 delete offer; 00117 00118 // If the service type has no more offers, free the map, lest 00119 // the memory forever persist. 00120 if (offer_map_entry->offer_map_->current_size () == 0) 00121 { 00122 if (this->db_lock_.release () == -1) 00123 return -1; 00124 else 00125 { 00126 // Promote the database lock. Will be released by 00127 // guard. 00128 if (this->db_lock_.acquire_write () == -1) 00129 return -1; 00130 00131 // Unbind the service type from the database. 00132 this->offer_db_.unbind (service_type); 00133 00134 // Now that the type has been removed, we can release 00135 // its lock. 00136 if (offer_map_entry->lock_.release () == -1) 00137 return -1; 00138 00139 // Delete the database resources for this type. 00140 delete offer_map_entry->offer_map_; 00141 delete offer_map_entry; 00142 } 00143 } 00144 else if (offer_map_entry->lock_.release () == -1) 00145 return -1; 00146 } 00147 00148 return return_value; 00149 } |
|
Definition at line 153 of file Offer_Database.cpp. References ACE_CHECK_RETURN, ACE_ENV_ARG_PARAMETER, ACE_THROW_RETURN, and CosTrading::OfferId. Referenced by TAO_Register< TRADER_LOCK_TYPE, MAP_LOCK_TYPE >::withdraw(), and TAO_Register< TRADER_LOCK_TYPE, MAP_LOCK_TYPE >::withdraw_using_constraint().
00157 { 00158 char* stype = 0; 00159 CORBA::ULong index; 00160 00161 this->parse_offer_id (offer_id, 00162 stype, 00163 index 00164 ACE_ENV_ARG_PARAMETER); 00165 ACE_CHECK_RETURN (-1); 00166 00167 if (this->remove_offer (stype, 00168 index) == -1) 00169 ACE_THROW_RETURN (CosTrading::UnknownOfferId (offer_id), 00170 -1); 00171 00172 return 0; 00173 } |
|
Return an iterator that will traverse and return all the offer ids in the service type map. Definition at line 239 of file Offer_Database.cpp. References ACE_NEW_RETURN, ACE_READ_GUARD_RETURN, TAO_Offer_Database< LOCK_TYPE >::generate_offer_id(), TAO_Offer_Id_Iterator::insert_id(), TAO_Offer_Database< LOCK_TYPE >::Offer_Map_Entry::lock_, TAO_Offer_Database< LOCK_TYPE >::Offer_Map_Entry::offer_map_, and CosTrading::OfferId. Referenced by TAO_Admin< TRADER_LOCK_TYPE, MAP_LOCK_TYPE >::list_offers().
00240 { 00241 // Fill an TAO_Offer_Id_Iterator with the offer_ids of all offers 00242 // exported to the TAO_Offer_Database. Iterates through the entire 00243 // map, cramming offer_id strings into a newly constructed 00244 // TAO_Offer_Id_Iterator. 00245 TAO_Offer_Id_Iterator* id_iterator; 00246 ACE_NEW_RETURN (id_iterator, 00247 TAO_Offer_Id_Iterator (), 00248 0); 00249 ACE_READ_GUARD_RETURN (LOCK_TYPE, ace_mon, this->db_lock_, 0); 00250 00251 for (ACE_TYPENAME Offer_Database::iterator type_iter (this->offer_db_); 00252 ! type_iter.done (); 00253 type_iter++) 00254 { 00255 const char* type_name = (*type_iter).ext_id_.in (); 00256 Offer_Map_Entry* offer_map_entry = (*type_iter).int_id_; 00257 00258 ACE_READ_GUARD_RETURN (LOCK_TYPE, ace_mon, offer_map_entry->lock_, 0); 00259 00260 for (TAO_Offer_Map::iterator offer_iter (*offer_map_entry->offer_map_); 00261 ! offer_iter.done (); 00262 offer_iter++) 00263 { 00264 CORBA::ULong offer_index = (*offer_iter).ext_id_; 00265 CosTrading::OfferId offer_id = 00266 this->generate_offer_id (type_name, offer_index); 00267 00268 id_iterator->insert_id (offer_id); 00269 } 00270 } 00271 00272 return id_iterator; 00273 } |
|
Definition at line 53 of file Offer_Database.h. |
|
Definition at line 149 of file Offer_Database.h. Referenced by TAO_Offer_Database< LOCK_TYPE >::insert_offer(), and TAO_Offer_Database< LOCK_TYPE >::remove_offer(). |
|
Definition at line 151 of file Offer_Database.h. Referenced by TAO_Offer_Database< LOCK_TYPE >::insert_offer(), TAO_Offer_Database< LOCK_TYPE >::lookup_offer(), and TAO_Offer_Database< LOCK_TYPE >::remove_offer(). |