#include <Configuration.h>
Inheritance diagram for ACE_Configuration_Heap:


Public Member Functions | |
| ACE_Configuration_Heap (void) | |
| Default ctor. | |
| virtual | ~ACE_Configuration_Heap (void) |
| Destructor. | |
| int | open (const ACE_TCHAR *file_name, void *base_address=ACE_DEFAULT_BASE_ADDR, size_t default_map_size=ACE_DEFAULT_CONFIG_SECTION_SIZE) |
| Opens a configuration based on a file name. | |
| int | open (size_t default_map_size=ACE_DEFAULT_CONFIG_SECTION_SIZE) |
| Opens a heap based configuration. | |
| virtual int | open_section (const ACE_Configuration_Section_Key &base, const ACE_TCHAR *sub_section, int create, ACE_Configuration_Section_Key &result) |
| virtual int | remove_section (const ACE_Configuration_Section_Key &key, const ACE_TCHAR *sub_section, int recursive) |
| Removes a named section. | |
| virtual int | enumerate_values (const ACE_Configuration_Section_Key &key, int index, ACE_TString &name, VALUETYPE &type) |
| virtual int | enumerate_sections (const ACE_Configuration_Section_Key &key, int index, ACE_TString &name) |
| virtual int | set_string_value (const ACE_Configuration_Section_Key &key, const ACE_TCHAR *name, const ACE_TString &value) |
| Sets a string-typed value. | |
| virtual int | set_integer_value (const ACE_Configuration_Section_Key &key, const ACE_TCHAR *name, u_int value) |
| Sets a integer-typed value. | |
| virtual int | set_binary_value (const ACE_Configuration_Section_Key &key, const ACE_TCHAR *name, const void *data, size_t length) |
| Sets a binary-typed value. | |
| virtual int | get_string_value (const ACE_Configuration_Section_Key &key, const ACE_TCHAR *name, ACE_TString &value) |
| Gets a string-typed value. | |
| virtual int | get_integer_value (const ACE_Configuration_Section_Key &key, const ACE_TCHAR *name, u_int &value) |
| Gets an integer-typed value. | |
| virtual int | get_binary_value (const ACE_Configuration_Section_Key &key, const ACE_TCHAR *name, void *&data, size_t &length) |
| Gets a binary-typed value. | |
| virtual int | find_value (const ACE_Configuration_Section_Key &key, const ACE_TCHAR *name, VALUETYPE &type) |
| virtual int | remove_value (const ACE_Configuration_Section_Key &key, const ACE_TCHAR *name) |
| Removes the the value name from key. returns non zero on error. | |
Private Member Functions | |
| int | open_simple_section (const ACE_Configuration_Section_Key &base, const ACE_TCHAR *sub_section, int create, ACE_Configuration_Section_Key &result) |
| may not contain path separators | |
| int | add_section (const ACE_Configuration_Section_Key &base, const ACE_TCHAR *sub_section, ACE_Configuration_Section_Key &result) |
| Adds a new section. | |
| int | create_index (void) |
| Helper for the method. | |
| int | create_index_helper (void *buffer) |
| int | value_open_helper (size_t hash_table_size, void *buffer) |
| int | section_open_helper (size_t hash_table_size, void *buffer) |
| int | load_key (const ACE_Configuration_Section_Key &key, ACE_TString &name) |
| int | new_section (const ACE_TString §ion, ACE_Configuration_Section_Key &result) |
| ACE_Configuration_Heap (const ACE_Configuration_Heap &rhs) | |
| ACE_Configuration_Heap & | operator= (const ACE_Configuration_Heap &rhs) |
Private Attributes | |
| ACE_Allocator * | allocator_ |
| SECTION_MAP * | index_ |
| size_t | default_map_size_ |
This class uses ACE's Allocators to manage a memory representation of a configuraiton database. A persistent heap may be used to store configurations persistently
Definition at line 786 of file Configuration.h.
|
|
Default ctor.
Definition at line 1250 of file Configuration.cpp. References ACE_NEW, and ACE_TEXT.
01251 : allocator_ (0), 01252 index_ (0), 01253 default_map_size_ (0) 01254 { 01255 ACE_Configuration_Section_Key_Heap *temp = 0; 01256 01257 ACE_NEW (temp, ACE_Configuration_Section_Key_Heap (ACE_TEXT (""))); 01258 root_ = ACE_Configuration_Section_Key (temp); 01259 } |
|
|
Destructor.
Definition at line 1261 of file Configuration.cpp. References ACE_Allocator::sync().
01262 {
01263 if (allocator_)
01264 allocator_->sync ();
01265
01266 delete allocator_;
01267 }
|
|
|
|
|
||||||||||||||||
|
Adds a new section.
Definition at line 1380 of file Configuration.cpp. References ACE_ASSERT, ACE_TCHAR, ACE_TEXT, ACE_TString, ACE_Hash_Map_With_Allocator< EXT_ID, INT_ID >::bind(), ACE_String_Base< CHAR >::fast_rep(), ACE_Hash_Map_With_Allocator< EXT_ID, INT_ID >::find(), ACE_Allocator::free(), index_, ACE_String_Base< CHAR >::length(), load_key(), ACE_Allocator::malloc(), new_section(), ACE_Configuration_Section_IntId::section_hash_map_, and ACE_OS::strcpy(). Referenced by open_simple_section().
01383 {
01384 ACE_ASSERT (this->allocator_);
01385 ACE_TString section;
01386 if (load_key (base, section))
01387 return -1;
01388
01389 // Find the base section
01390 ACE_Configuration_ExtId ExtId (section.fast_rep ());
01391 ACE_Configuration_Section_IntId IntId;
01392 if (index_->find (ExtId, IntId, allocator_))
01393 return -1;
01394
01395 // See if this section already exists
01396 ACE_Configuration_ExtId SubSectionExtId (sub_section);
01397 int ignored = 0;
01398
01399 if (!IntId.section_hash_map_->find (SubSectionExtId, ignored, allocator_))
01400 {
01401 // already exists!
01402 errno = EEXIST;
01403 return -1;
01404 }
01405
01406 // Create the new section name
01407 // only prepend a separater if were not at the root
01408 if (section.length ())
01409 section += ACE_TEXT ("\\");
01410
01411 section += sub_section;
01412
01413 // Add it to the base section
01414 ACE_TCHAR* pers_name = (ACE_TCHAR *) allocator_->malloc ((ACE_OS::strlen (sub_section) + 1) * sizeof (ACE_TCHAR));
01415 ACE_OS::strcpy (pers_name, sub_section);
01416 ACE_Configuration_ExtId SSExtId (pers_name);
01417 if (IntId.section_hash_map_->bind (SSExtId, ignored, allocator_))
01418 {
01419 allocator_->free (pers_name);
01420 return -1;
01421 }
01422 return (new_section (section, result));
01423 }
|
|
|
Helper for the method.
Definition at line 1319 of file Configuration.cpp. References ACE_CONFIG_SECTION_INDEX, ACE_ERROR, ACE_TEXT, ACE_Allocator::bind(), create_index_helper(), ACE_Allocator::find(), index_, LM_ERROR, ACE_Allocator::malloc(), new_section(), ACE_Allocator::remove(), and SECTION_MAP. Referenced by open().
01320 {
01321 void *section_index = 0;
01322
01323 // This is the easy case since if we find hash table in the
01324 // memory-mapped file we know it's already initialized.
01325 if (this->allocator_->find (ACE_CONFIG_SECTION_INDEX, section_index) == 0)
01326 this->index_ = (SECTION_MAP *) section_index;
01327
01328 // Create a new <index_> (because we've just created a new
01329 // memory-mapped file).
01330 else
01331 {
01332 size_t index_size = sizeof (SECTION_MAP);
01333 section_index = this->allocator_->malloc (index_size);
01334
01335 if (section_index == 0
01336 || create_index_helper (section_index) == -1
01337 || this->allocator_->bind (ACE_CONFIG_SECTION_INDEX,
01338 section_index) == -1)
01339 {
01340 // Attempt to clean up.
01341 ACE_ERROR ((LM_ERROR,
01342 ACE_TEXT ("create_index failed\n")));
01343 this->allocator_->remove ();
01344 return -1;
01345 }
01346 // Add the root section
01347 return new_section (ACE_TEXT (""), root_);
01348 }
01349 return 0;
01350 }
|
|
|
Helper for create_index() method: places hash table into an allocated space. Definition at line 1353 of file Configuration.cpp. References ACE_ASSERT, index_, and SECTION_MAP. Referenced by create_index().
01354 {
01355 ACE_ASSERT (this->allocator_);
01356 this->index_ = new (buffer) SECTION_MAP (this->allocator_);
01357 return 0;
01358 }
|
|
||||||||||||||||
|
Enumerates through the subsections in a section.
Implements ACE_Configuration. Definition at line 1746 of file Configuration.cpp. References ACE_ASSERT, ACE_NEW_RETURN, ACE_TString, ACE_Hash_Map_Manager_Ex< EXT_ID, INT_ID, ACE_Hash< EXT_ID >, ACE_Equal_To< EXT_ID >, ACE_Null_Mutex >::begin(), ACE_Hash_Map_Entry< EXT_ID, INT_ID >::ext_id_, ACE_Hash_Map_With_Allocator< EXT_ID, INT_ID >::find(), ACE_Configuration::get_internal_key(), index_, ACE_Configuration_Section_Key_Heap::path_, ACE_Configuration_Section_IntId::section_hash_map_, and ACE_Configuration_Section_Key_Heap::section_iter_. Referenced by remove_section().
01749 {
01750 ACE_ASSERT (this->allocator_);
01751 // cast to a heap section key
01752 ACE_Configuration_Section_Key_Heap* pKey =
01753 dynamic_cast<ACE_Configuration_Section_Key_Heap*> (get_internal_key (key));
01754 if (!pKey)
01755 return -1; // not a heap key!
01756
01757 // resolve the section
01758 ACE_Configuration_ExtId ExtId (pKey->path_);
01759 ACE_Configuration_Section_IntId IntId;
01760 if (index_->find (ExtId, IntId, allocator_))
01761 return -1; // unknown section
01762
01763 // Handle iterator resets
01764 if (index == 0)
01765 {
01766 if (pKey->section_iter_)
01767 delete pKey->section_iter_;
01768
01769 ACE_NEW_RETURN (pKey->section_iter_,
01770 SUBSECTION_HASH::ITERATOR (IntId.section_hash_map_->begin ()),
01771 -1);
01772 }
01773
01774 // Get the next entry
01775 ACE_Hash_Map_Entry<ACE_Configuration_ExtId, int>* entry = 0;
01776 if (!pKey->section_iter_->next (entry))
01777 return 1;
01778
01779 // Return the value of the iterator and advance it
01780 pKey->section_iter_->advance ();
01781 name = entry->ext_id_.name_;
01782
01783 return 0;
01784 }
|
|
||||||||||||||||||||
|
Enumerates through the values in a section.
Implements ACE_Configuration. Definition at line 1697 of file Configuration.cpp. References ACE_ASSERT, ACE_NEW_RETURN, ACE_TString, ACE_Hash_Map_Entry< EXT_ID, INT_ID >::ext_id_, ACE_Hash_Map_With_Allocator< EXT_ID, INT_ID >::find(), ACE_Configuration::get_internal_key(), index_, ACE_Hash_Map_Entry< EXT_ID, INT_ID >::int_id_, ACE_Configuration_Section_Key_Heap::path_, ACE_Configuration_Section_IntId::value_hash_map_, and ACE_Configuration_Section_Key_Heap::value_iter_.
01701 {
01702 ACE_ASSERT (this->allocator_);
01703 ACE_Configuration_Section_Key_Heap* pKey =
01704 dynamic_cast<ACE_Configuration_Section_Key_Heap*> (get_internal_key (key));
01705 if (!pKey)
01706 return -1;
01707
01708 name = pKey->path_;
01709
01710 // resolve the section
01711 ACE_Configuration_ExtId ExtId (pKey->path_);
01712 ACE_Configuration_Section_IntId IntId;
01713 if (index_->find (ExtId, IntId, allocator_))
01714 return -1;
01715
01716 // Handle iterator resets
01717 if (index == 0)
01718 {
01719 ACE_Hash_Map_Manager_Ex<ACE_Configuration_ExtId ,
01720 ACE_Configuration_Value_IntId,
01721 ACE_Hash<ACE_Configuration_ExtId>,
01722 ACE_Equal_To<ACE_Configuration_ExtId>,
01723 ACE_Null_Mutex>* hash_map = IntId.value_hash_map_;
01724 delete pKey->value_iter_;
01725
01726 ACE_NEW_RETURN (pKey->value_iter_,
01727 VALUE_HASH::ITERATOR (hash_map->begin ()),
01728 -1);
01729 }
01730
01731 // Get the next entry
01732 ACE_Hash_Map_Entry<ACE_Configuration_ExtId, ACE_Configuration_Value_IntId>* entry = 0;
01733
01734 if (!pKey->value_iter_->next (entry))
01735 return 1;
01736
01737 // Return the value of the iterator and advance it
01738 name = entry->ext_id_.name_;
01739 type = entry->int_id_.type_;
01740 pKey->value_iter_->advance ();
01741
01742 return 0;
01743 }
|
|
||||||||||||||||
|
Retrieves the type of a named configuration value.
Implements ACE_Configuration. Definition at line 2083 of file Configuration.cpp. References ACE_ASSERT, ACE_TCHAR, ACE_TString, ACE_String_Base< CHAR >::fast_rep(), ACE_Hash_Map_With_Allocator< EXT_ID, INT_ID >::find(), index_, load_key(), ACE_Configuration::validate_value_name(), VALUE_HASH, and ACE_Configuration_Section_IntId::value_hash_map_.
02086 {
02087 ACE_ASSERT (this->allocator_);
02088 const ACE_TCHAR *t_name = name ? name : &this->NULL_String_;
02089 if (validate_value_name (t_name))
02090 return -1;
02091
02092 // Get the section name from the key
02093 ACE_TString section;
02094 if (load_key (key, section))
02095 return -1;
02096
02097 // Find this section
02098 ACE_Configuration_ExtId ExtId (section.fast_rep ());
02099 ACE_Configuration_Section_IntId IntId;
02100 if (index_->find (ExtId, IntId, allocator_))
02101 return -1; // section does not exist
02102
02103 // Find it
02104 ACE_Configuration_ExtId ValueExtId (t_name);
02105 VALUE_HASH::ENTRY* value_entry;
02106 if (((VALUE_HASH *) IntId.value_hash_map_)->find (ValueExtId, value_entry))
02107 return -1; // value does not exist
02108
02109 type_out = value_entry->int_id_.type_;
02110 return 0;
02111 }
|
|
||||||||||||||||||||
|
Gets a binary-typed value.
Implements ACE_Configuration. Definition at line 2040 of file Configuration.cpp. References ACE_ASSERT, ACE_NEW_RETURN, ACE_TCHAR, ACE_TString, ACE_Configuration_Value_IntId::data_, ACE_String_Base< CHAR >::fast_rep(), ACE_Hash_Map_With_Allocator< EXT_ID, INT_ID >::find(), index_, ACE_Configuration_Value_IntId::length_, load_key(), ACE_OS::memcpy(), ACE_Configuration_Value_IntId::type_, ACE_Configuration::validate_value_name(), and ACE_Configuration_Section_IntId::value_hash_map_.
02045 {
02046 ACE_ASSERT (this->allocator_);
02047 const ACE_TCHAR *t_name = name ? name : &this->NULL_String_;
02048 if (validate_value_name (t_name))
02049 return -1;
02050
02051 // Get the section name from the key
02052 ACE_TString section;
02053 if (load_key (key, section))
02054 return -1;
02055
02056 // Find this section
02057 ACE_Configuration_ExtId ExtId (section.fast_rep ());
02058 ACE_Configuration_Section_IntId IntId;
02059 if (index_->find (ExtId, IntId, allocator_))
02060 return -1; // section does not exist
02061
02062 ACE_Configuration_ExtId VExtId (t_name);
02063 ACE_Configuration_Value_IntId VIntId;
02064 // See if it exists first
02065 if (IntId.value_hash_map_->find (VExtId, VIntId, allocator_))
02066 return -1; // unknown value
02067
02068 // Check type
02069 if (VIntId.type_ != ACE_Configuration::BINARY)
02070 {
02071 errno = ENOENT;
02072 return -1;
02073 }
02074
02075 // Make a copy
02076 ACE_NEW_RETURN (data, char[VIntId.length_], -1);
02077 ACE_OS::memcpy (data, VIntId.data_.ptr_, VIntId.length_);
02078 length = VIntId.length_;
02079 return 0;
02080 }
|
|
||||||||||||||||
|
Gets an integer-typed value.
Implements ACE_Configuration. Definition at line 1990 of file Configuration.cpp. References ACE_ASSERT, ACE_TCHAR, ACE_TString, ACE_Configuration_Value_IntId::data_, ACE_String_Base< CHAR >::fast_rep(), ACE_Hash_Map_With_Allocator< EXT_ID, INT_ID >::find(), index_, load_key(), ACE_Configuration_Value_IntId::type_, ACE_Configuration::validate_value_name(), and ACE_Configuration_Section_IntId::value_hash_map_.
01993 {
01994 ACE_ASSERT (this->allocator_);
01995
01996 const ACE_TCHAR *t_name = name ? name : &this->NULL_String_;
01997 if (validate_value_name (t_name))
01998 return -1;
01999
02000 // Get the section name from the key
02001 ACE_TString section (0, 0, false);
02002
02003 if (this->load_key (key, section) != 0)
02004 {
02005 return -1;
02006 }
02007
02008 // Find this section
02009 ACE_Configuration_ExtId ExtId (section.fast_rep ());
02010 ACE_Configuration_Section_IntId IntId;
02011
02012 if (index_->find (ExtId, IntId, allocator_) != 0)
02013 {
02014 return -1; // section does not exist
02015 }
02016
02017
02018 // See if it exists first
02019 ACE_Configuration_ExtId VExtId (t_name);
02020 ACE_Configuration_Value_IntId VIntId;
02021
02022 if (IntId.value_hash_map_->find (VExtId, VIntId, allocator_) != 0)
02023 {
02024 return -1; // unknown value
02025 }
02026
02027 // Check type
02028 if (VIntId.type_ != ACE_Configuration::INTEGER)
02029 {
02030 errno = ENOENT;
02031 return -1;
02032 }
02033
02034 // Everythings ok, return the data
02035 value = VIntId.data_.int_;
02036 return 0;
02037 }
|
|
||||||||||||||||
|
Gets a string-typed value.
Implements ACE_Configuration. Definition at line 1951 of file Configuration.cpp. References ACE_ASSERT, ACE_TCHAR, ACE_TString, ACE_Configuration_Value_IntId::data_, ACE_String_Base< CHAR >::fast_rep(), ACE_Hash_Map_With_Allocator< EXT_ID, INT_ID >::find(), index_, load_key(), ACE_Configuration_Value_IntId::type_, ACE_Configuration::validate_value_name(), and ACE_Configuration_Section_IntId::value_hash_map_.
01954 {
01955 ACE_ASSERT (this->allocator_);
01956 const ACE_TCHAR *t_name = name ? name : &this->NULL_String_;
01957 if (validate_value_name (t_name))
01958 return -1;
01959
01960 // Get the section name from the key
01961 ACE_TString section;
01962 if (load_key (key, section))
01963 return -1;
01964
01965 // Find this section
01966 ACE_Configuration_ExtId ExtId (section.fast_rep ());
01967 ACE_Configuration_Section_IntId IntId;
01968 if (index_->find (ExtId, IntId, allocator_))
01969 return -1; // section does not exist
01970
01971 // See if it exists first
01972 ACE_Configuration_ExtId VExtId (t_name);
01973 ACE_Configuration_Value_IntId VIntId;
01974 if (IntId.value_hash_map_->find (VExtId, VIntId, allocator_))
01975 return -1; // unknown value
01976
01977 // Check type
01978 if (VIntId.type_ != ACE_Configuration::STRING)
01979 {
01980 errno = ENOENT;
01981 return -1;
01982 }
01983
01984 // everythings ok, return the data
01985 value = static_cast<ACE_TCHAR*> (VIntId.data_.ptr_);
01986 return 0;
01987 }
|
|
||||||||||||
|
Definition at line 1361 of file Configuration.cpp. References ACE_ASSERT, ACE_TString, ACE_String_Base< CHAR >::assign_nocopy(), ACE_Configuration::get_internal_key(), and ACE_Configuration_Section_Key_Heap::path_. Referenced by add_section(), find_value(), get_binary_value(), get_integer_value(), get_string_value(), open_simple_section(), remove_section(), remove_value(), set_binary_value(), set_integer_value(), and set_string_value().
01363 {
01364 ACE_ASSERT (this->allocator_);
01365 ACE_Configuration_Section_Key_Heap* pKey =
01366 dynamic_cast<ACE_Configuration_Section_Key_Heap*> (get_internal_key (key));
01367
01368 if (!pKey)
01369 {
01370 return -1;
01371 }
01372
01373 ACE_TString temp (pKey->path_, 0, false);
01374 name.assign_nocopy (temp);
01375 return 0;
01376 }
|
|
||||||||||||
|
Definition at line 1426 of file Configuration.cpp. References ACE_ASSERT, ACE_NEW_RETURN, ACE_TCHAR, ACE_TString, ACE_Hash_Map_With_Allocator< EXT_ID, INT_ID >::bind(), default_map_size_, ACE_String_Base< CHAR >::fast_rep(), ACE_Allocator::free(), index_, ACE_String_Base< CHAR >::length(), ACE_Allocator::malloc(), section_open_helper(), ACE_OS::strcpy(), SUBSECTION_MAP, ACE_Allocator::sync(), VALUE_MAP, and value_open_helper(). Referenced by add_section(), and create_index().
01428 {
01429 ACE_ASSERT (this->allocator_);
01430 // Create a new section and add it to the global list
01431
01432 // Allocate memory for items to be stored in the table.
01433 size_t section_len = section.length () + 1;
01434 ACE_TCHAR *ptr = (ACE_TCHAR*) this->allocator_->malloc (section_len * sizeof (ACE_TCHAR));
01435
01436 int return_value = -1;
01437
01438 if (ptr == 0)
01439 return -1;
01440 else
01441 {
01442 // Populate memory with data.
01443 ACE_OS::strcpy (ptr, section.fast_rep ());
01444
01445 void *value_hash_map = 0;
01446 size_t map_size = sizeof (VALUE_MAP);
01447 value_hash_map = this->allocator_->malloc (map_size);
01448
01449 // If allocation failed ...
01450 if (value_hash_map == 0)
01451 return -1;
01452
01453 // Initialize allocated hash map through placement new.
01454 if (value_open_helper (default_map_size_, value_hash_map ) == -1)
01455 {
01456 this->allocator_->free (value_hash_map );
01457 return -1;
01458 }
01459
01460 // create the section map
01461 void* section_hash_map = 0;
01462 map_size = sizeof (SUBSECTION_MAP);
01463 section_hash_map = this->allocator_->malloc (map_size);
01464
01465 // If allocation failed
01466 if (section_hash_map == 0)
01467 return -1;
01468
01469 // initialize allocated hash map through placement new
01470 if (section_open_helper (default_map_size_, section_hash_map) == -1)
01471 {
01472 this->allocator_->free (value_hash_map );
01473 this->allocator_->free (section_hash_map);
01474 return -1;
01475 }
01476
01477 ACE_Configuration_ExtId name (ptr);
01478 ACE_Configuration_Section_IntId entry ((VALUE_MAP*) value_hash_map,
01479 (SUBSECTION_MAP*) section_hash_map);
01480
01481 // Do a normal bind. This will fail if there's already an
01482 // entry with the same name.
01483 return_value = this->index_->bind (name, entry, this->allocator_);
01484
01485 if (return_value == 1 /* Entry already existed so bind failed. */
01486 || return_value == -1 /* Unable to bind for other reasons. */)
01487 {
01488 // Free our dynamically allocated memory.
01489 this->allocator_->free (static_cast<void *> (ptr));
01490 return return_value;
01491 }
01492
01493 // If bind () succeed, it will automatically sync
01494 // up the map manager entry. However, we must sync up our
01495 // name/value memory.
01496 this->allocator_->sync (ptr, section_len);
01497 }
01498
01499 // set the result
01500 ACE_Configuration_Section_Key_Heap *temp;
01501 ACE_NEW_RETURN (temp,
01502 ACE_Configuration_Section_Key_Heap (ptr),
01503 -1);
01504 result = ACE_Configuration_Section_Key (temp);
01505 return return_value;
01506 }
|
|
|
Opens a heap based configuration.
Definition at line 1270 of file Configuration.cpp. References ACE_NEW_RETURN, create_index(), default_map_size_, and HEAP_ALLOCATOR.
01271 {
01272 default_map_size_ = default_map_size;
01273 // Create the allocator with the appropriate options.
01274 // The name used for the lock is the same as one used
01275 // for the file.
01276 ACE_NEW_RETURN (this->allocator_,
01277 HEAP_ALLOCATOR (),
01278 -1);
01279 return create_index ();
01280 }
|
|
||||||||||||||||
|
Opens a configuration based on a file name.
Definition at line 1284 of file Configuration.cpp. References ACE_OS::access(), ACE_ERROR_RETURN, ACE_NEW_RETURN, ACE_TCHAR, ACE_TEXT, create_index(), default_map_size_, F_OK, LM_ERROR, MAXNAMELEN, MAXPATHLEN, PERSISTENT_ALLOCATOR, and ACE_OS::strlen().
01287 {
01288 default_map_size_ = default_map_size;
01289
01290 // Make sure that the file name is of the legal length.
01291 if (ACE_OS::strlen (file_name) >= MAXNAMELEN + MAXPATHLEN)
01292 {
01293 errno = ENAMETOOLONG;
01294 return -1;
01295 }
01296
01297 ACE_MMAP_Memory_Pool::OPTIONS options (base_address);
01298
01299 // Create the allocator with the appropriate options. The name used
01300 // for the lock is the same as one used for the file.
01301 ACE_NEW_RETURN (this->allocator_,
01302 PERSISTENT_ALLOCATOR (file_name,
01303 file_name,
01304 &options),
01305 -1);
01306
01307 #if !defined (ACE_LACKS_ACCESS)
01308 // Now check if the backing store has been created successfully.
01309 if (ACE_OS::access (file_name, F_OK) != 0)
01310 ACE_ERROR_RETURN ((LM_ERROR,
01311 ACE_TEXT ("create_index\n")),
01312 -1);
01313 #endif /* ACE_LACKS_ACCESS */
01314
01315 return create_index ();
01316 }
|
|
||||||||||||||||||||
|
Opens a named section in an existing section.
Implements ACE_Configuration. Definition at line 1527 of file Configuration.cpp. References ACE_ASSERT, ACE_TCHAR, ACE_TEXT, ACE_TString, ACE_String_Base< CHAR >::c_str(), open_simple_section(), ACE_OS::strchr(), and ACE_Configuration::validate_name(). Referenced by remove_section().
01531 {
01532 ACE_ASSERT (this->allocator_);
01533 if (validate_name (sub_section, 1)) // 1 == allow_path
01534 return -1;
01535
01536 result = base;
01537
01538 for (const ACE_TCHAR* separator;
01539 (separator = ACE_OS::strchr (sub_section, ACE_TEXT ('\\'))) != 0;
01540 )
01541 {
01542 ACE_TString simple_section (sub_section, separator - sub_section);
01543 int ret_val =
01544 open_simple_section (result, simple_section.c_str (), create, result);
01545 if (ret_val)
01546 return ret_val;
01547 sub_section = separator + 1;
01548 }
01549
01550 return open_simple_section (result, sub_section, create, result);
01551 }
|
|
||||||||||||||||||||
|
may not contain path separators
Definition at line 1554 of file Configuration.cpp. References ACE_NEW_RETURN, ACE_TCHAR, ACE_TEXT, ACE_TString, add_section(), ACE_String_Base< CHAR >::fast_rep(), ACE_Hash_Map_With_Allocator< EXT_ID, INT_ID >::find(), index_, ACE_String_Base< CHAR >::length(), and load_key(). Referenced by open_section().
01558 {
01559 ACE_TString section (0, 0, false);
01560
01561 if (load_key (base, section))
01562 {
01563 return -1;
01564 }
01565
01566 // Only add the \\ if were not at the root
01567 if (section.length ())
01568 {
01569 section += ACE_TEXT ("\\");
01570 }
01571
01572 section += sub_section;
01573
01574 // resolve the section
01575 ACE_Configuration_ExtId ExtId (section.fast_rep ());
01576 ACE_Configuration_Section_IntId IntId;
01577
01578 if (index_->find (ExtId, IntId, allocator_))
01579 {
01580 if (!create)
01581 {
01582 errno = ENOENT;
01583 return -1;
01584 }
01585
01586 return add_section (base, sub_section, result);
01587 }
01588
01589 ACE_Configuration_Section_Key_Heap *temp;
01590 ACE_NEW_RETURN (temp,
01591 ACE_Configuration_Section_Key_Heap (section.fast_rep ()),
01592 -1);
01593 result = ACE_Configuration_Section_Key (temp);
01594 return 0;
01595 }
|
|
|
|
|
||||||||||||||||
|
Removes a named section.
Implements ACE_Configuration. Definition at line 1598 of file Configuration.cpp. References ACE_ASSERT, ACE_TCHAR, ACE_TEXT, ACE_TString, ACE_Hash_Map_Manager_Ex< ACE_Configuration_ExtId, ACE_Configuration_Value_IntId, ACE_Hash< ACE_Configuration_ExtId >, ACE_Equal_To< ACE_Configuration_ExtId >, ACE_Null_Mutex >::begin(), ACE_Hash_Map_Manager_Ex< ACE_Configuration_ExtId, ACE_Configuration_Value_IntId, ACE_Hash< ACE_Configuration_ExtId >, ACE_Equal_To< ACE_Configuration_ExtId >, ACE_Null_Mutex >::close(), enumerate_sections(), ACE_String_Base< CHAR >::fast_rep(), ACE_Hash_Map_Manager_Ex< ACE_Configuration_ExtId, ACE_Configuration_Section_IntId, ACE_Hash< ACE_Configuration_ExtId >, ACE_Equal_To< ACE_Configuration_ExtId >, ACE_Null_Mutex >::find(), ACE_Hash_Map_With_Allocator< EXT_ID, INT_ID >::find(), ACE_Configuration_Section_IntId::free(), ACE_Configuration_ExtId::free(), index_, ACE_String_Base< CHAR >::length(), load_key(), open_section(), SECTION_HASH, ACE_Configuration_Section_IntId::section_hash_map_, SUBSECTION_HASH, ACE_Hash_Map_Manager_Ex< ACE_Configuration_ExtId, ACE_Configuration_Section_IntId, ACE_Hash< ACE_Configuration_ExtId >, ACE_Equal_To< ACE_Configuration_ExtId >, ACE_Null_Mutex >::unbind(), ACE_Hash_Map_With_Allocator< EXT_ID, INT_ID >::unbind(), ACE_Configuration::validate_name(), and VALUE_HASH.
01601 {
01602 ACE_ASSERT (this->allocator_);
01603 if (validate_name (sub_section))
01604 return -1;
01605
01606 ACE_TString section;
01607 if (load_key (key, section))
01608 return -1;
01609
01610 // Find this key
01611 ACE_Configuration_ExtId ParentExtId (section.fast_rep ());
01612 ACE_Configuration_Section_IntId ParentIntId;
01613 if (index_->find (ParentExtId, ParentIntId, allocator_))
01614 return -1;// no parent key
01615
01616 // Find this subkey
01617 if (section.length ())
01618 section += ACE_TEXT ("\\");
01619
01620 section += sub_section;
01621 ACE_Configuration_ExtId SectionExtId (section.fast_rep ());
01622 SECTION_HASH::ENTRY* section_entry;
01623 SECTION_HASH* hashmap = index_;
01624 if (hashmap->find (SectionExtId, section_entry))
01625 return -1;
01626
01627 if (recursive)
01628 {
01629 ACE_Configuration_Section_Key section;
01630 if (open_section (key, sub_section, 0, section))
01631 return -1;
01632
01633 int index = 0;
01634 ACE_TString name;
01635 while (!enumerate_sections (section, index, name))
01636 {
01637 if (remove_section (section, name.fast_rep (), 1))
01638 return -1;
01639
01640 ++index;
01641 }
01642 }
01643
01644 // Now make sure we dont have any subkeys
01645 if (section_entry->int_id_.section_hash_map_->current_size ())
01646 {
01647 errno = ENOTEMPTY;
01648 return -1;
01649 }
01650
01651 // Now remove subkey from parent key
01652 ACE_Configuration_ExtId SubSExtId (sub_section);
01653 SUBSECTION_HASH::ENTRY* subsection_entry;
01654 if (((SUBSECTION_HASH*)ParentIntId.section_hash_map_)->
01655 find (SubSExtId, subsection_entry))
01656 return -1;
01657
01658 if (ParentIntId.section_hash_map_->unbind (SubSExtId, allocator_))
01659 return -1;
01660
01661 subsection_entry->ext_id_.free (allocator_);
01662
01663 // Remember the pointers so we can free them after we unbind
01664 ACE_Configuration_ExtId ExtIdToFree (section_entry->ext_id_);
01665 ACE_Configuration_Section_IntId IntIdToFree (section_entry->int_id_);
01666
01667 // iterate over all values and free memory
01668 VALUE_HASH* value_hash_map = section_entry->int_id_.value_hash_map_;
01669 VALUE_HASH::ITERATOR value_iter = value_hash_map->begin ();
01670 while (!value_iter.done ())
01671 {
01672 VALUE_HASH::ENTRY* value_entry = 0;
01673 if (!value_iter.next (value_entry))
01674 return 1;
01675
01676 value_entry->ext_id_.free (allocator_);
01677 value_entry->int_id_.free (allocator_);
01678
01679 value_iter.advance ();
01680 }
01681
01682 // remove it
01683 if (index_->unbind (SectionExtId, allocator_))
01684 return -1;
01685
01686 value_hash_map->close ();
01687 section_entry->int_id_.section_hash_map_->close (allocator_);
01688
01689 // Free the memory
01690 ExtIdToFree.free (allocator_);
01691 IntIdToFree.free (allocator_);
01692
01693 return 0;
01694 }
|
|
||||||||||||
|
Removes the the value name from key. returns non zero on error.
Implements ACE_Configuration. Definition at line 2114 of file Configuration.cpp. References ACE_ASSERT, ACE_TCHAR, ACE_TString, ACE_String_Base< CHAR >::fast_rep(), ACE_Hash_Map_With_Allocator< EXT_ID, INT_ID >::find(), index_, load_key(), ACE_Hash_Map_With_Allocator< EXT_ID, INT_ID >::unbind(), ACE_Configuration::validate_value_name(), VALUE_HASH, and ACE_Configuration_Section_IntId::value_hash_map_.
02116 {
02117 ACE_ASSERT (this->allocator_);
02118 const ACE_TCHAR *t_name = name ? name : &this->NULL_String_;
02119 if (validate_value_name (t_name))
02120 return -1;
02121
02122 // Get the section name from the key
02123 ACE_TString section;
02124 if (load_key (key, section))
02125 return -1;
02126
02127 // Find this section
02128 ACE_Configuration_ExtId ExtId (section.fast_rep ());
02129 ACE_Configuration_Section_IntId IntId;
02130 if (index_->find (ExtId, IntId, allocator_))
02131 return -1; // section does not exist
02132
02133 // Find it
02134 ACE_Configuration_ExtId ValueExtId (t_name);
02135 VALUE_HASH::ENTRY* value_entry;
02136 if (((VALUE_HASH *) IntId.value_hash_map_)->find (ValueExtId, value_entry))
02137 return -1;
02138
02139 // free it
02140 value_entry->ext_id_.free (allocator_);
02141 value_entry->int_id_.free (allocator_);
02142
02143 // Unbind it
02144 if (IntId.value_hash_map_->unbind (ValueExtId, allocator_))
02145 return -1;
02146
02147 return 0;
02148 }
|
|
||||||||||||
|
Definition at line 1518 of file Configuration.cpp. References ACE_ASSERT, and SUBSECTION_MAP. Referenced by new_section().
01520 {
01521 ACE_ASSERT (this->allocator_);
01522 new (buffer) SUBSECTION_MAP (hash_table_size, this->allocator_);
01523 return 0;
01524 }
|
|
||||||||||||||||||||
|
Sets a binary-typed value.
Implements ACE_Configuration. Definition at line 1893 of file Configuration.cpp. References ACE_ASSERT, ACE_TCHAR, ACE_TString, ACE_Hash_Map_With_Allocator< EXT_ID, INT_ID >::bind(), ACE_String_Base< CHAR >::fast_rep(), ACE_Hash_Map_With_Allocator< EXT_ID, INT_ID >::find(), ACE_Allocator::free(), index_, load_key(), ACE_Allocator::malloc(), ACE_OS::memcpy(), ACE_OS::strcpy(), ACE_Configuration::validate_value_name(), and ACE_Configuration_Section_IntId::value_hash_map_.
01897 {
01898 ACE_ASSERT (this->allocator_);
01899 const ACE_TCHAR *t_name = name ? name : &this->NULL_String_;
01900 if (validate_value_name (t_name))
01901 return -1;
01902
01903 // Get the section name from the key
01904 ACE_TString section;
01905 if (load_key (key, section))
01906 return -1;
01907
01908 // Find this section
01909 ACE_Configuration_ExtId section_ext (section.fast_rep ());
01910 ACE_Configuration_Section_IntId section_int;
01911 if (index_->find (section_ext, section_int, allocator_))
01912 return -1; // section does not exist
01913
01914 // Get the entry for this item (if it exists)
01915 VALUE_HASH::ENTRY* entry;
01916 ACE_Configuration_ExtId item_name (t_name);
01917 if (section_int.value_hash_map_->VALUE_HASH::find (item_name, entry) == 0)
01918 {
01919 // found item, replace it
01920 // Free the old value
01921 entry->int_id_.free (allocator_);
01922 // Allocate the new value in this heap
01923 ACE_TCHAR* pers_value = (ACE_TCHAR *) allocator_->malloc (length);
01924 ACE_OS::memcpy (pers_value, data, length);
01925 ACE_Configuration_Value_IntId new_value_int (pers_value, length);
01926 entry->int_id_ = new_value_int;
01927 }
01928 else
01929 {
01930 // it doesn't exist, bind it
01931 ACE_TCHAR* pers_name =
01932 (ACE_TCHAR *) allocator_->malloc ((ACE_OS::strlen (t_name) + 1) * sizeof (ACE_TCHAR));
01933 ACE_OS::strcpy (pers_name, t_name);
01934 ACE_TCHAR* pers_value = (ACE_TCHAR *) allocator_->malloc (length);
01935 ACE_OS::memcpy (pers_value, data, length);
01936 ACE_Configuration_ExtId item_name (pers_name);
01937 ACE_Configuration_Value_IntId item_value (pers_value, length);
01938 if (section_int.value_hash_map_->bind (item_name, item_value, allocator_))
01939 {
01940 allocator_->free (pers_value);
01941 allocator_->free (pers_name);
01942 return -1;
01943 }
01944 return 0;
01945 }
01946
01947 return 0;
01948 }
|
|
||||||||||||||||
|
Sets a integer-typed value.
Implements ACE_Configuration. Definition at line 1844 of file Configuration.cpp. References ACE_ASSERT, ACE_TCHAR, ACE_TString, ACE_Hash_Map_With_Allocator< EXT_ID, INT_ID >::bind(), ACE_String_Base< CHAR >::fast_rep(), ACE_Hash_Map_With_Allocator< EXT_ID, INT_ID >::find(), ACE_Allocator::free(), index_, load_key(), ACE_Allocator::malloc(), ACE_OS::strcpy(), ACE_Configuration::validate_value_name(), and ACE_Configuration_Section_IntId::value_hash_map_.
01847 {
01848 ACE_ASSERT (this->allocator_);
01849 const ACE_TCHAR *t_name = name ? name : &this->NULL_String_;
01850 if (validate_value_name (t_name))
01851 return -1;
01852
01853 // Get the section name from the key
01854 ACE_TString section;
01855 if (load_key (key, section))
01856 return -1;
01857
01858 // Find this section
01859 ACE_Configuration_ExtId section_ext (section.fast_rep ());
01860 ACE_Configuration_Section_IntId section_int;
01861 if (index_->find (section_ext, section_int, allocator_))
01862 return -1; // section does not exist
01863
01864 // Get the entry for this item (if it exists)
01865 VALUE_HASH::ENTRY* entry;
01866 ACE_Configuration_ExtId item_name (t_name);
01867 if (section_int.value_hash_map_->VALUE_HASH::find (item_name, entry) == 0)
01868 {
01869 // found item, replace it
01870 ACE_Configuration_Value_IntId new_value_int (value);
01871 entry->int_id_ = new_value_int;
01872 }
01873 else
01874 {
01875 // it doesn't exist, bind it
01876 ACE_TCHAR* pers_name =
01877 (ACE_TCHAR *) allocator_->malloc ((ACE_OS::strlen (t_name) + 1) * sizeof (ACE_TCHAR));
01878 ACE_OS::strcpy (pers_name, t_name);
01879 ACE_Configuration_ExtId item_name (pers_name);
01880 ACE_Configuration_Value_IntId item_value (value);
01881 if (section_int.value_hash_map_->bind (item_name, item_value, allocator_))
01882 {
01883 allocator_->free (pers_name);
01884 return -1;
01885 }
01886 return 0;
01887 }
01888
01889 return 0;
01890 }
|
|
||||||||||||||||
|
Sets a string-typed value.
Implements ACE_Configuration. Definition at line 1787 of file Configuration.cpp. References ACE_ASSERT, ACE_TCHAR, ACE_TString, ACE_Hash_Map_With_Allocator< EXT_ID, INT_ID >::bind(), ACE_String_Base< CHAR >::fast_rep(), ACE_Hash_Map_With_Allocator< EXT_ID, INT_ID >::find(), ACE_Allocator::free(), index_, ACE_String_Base< CHAR >::length(), load_key(), ACE_Allocator::malloc(), ACE_OS::strcpy(), ACE_Configuration::validate_value_name(), and ACE_Configuration_Section_IntId::value_hash_map_.
01790 {
01791 ACE_ASSERT (this->allocator_);
01792 const ACE_TCHAR *t_name = name ? name : &this->NULL_String_;
01793 if (validate_value_name (t_name))
01794 return -1;
01795
01796 ACE_TString section;
01797 if (load_key (key, section))
01798 return -1;
01799
01800 ACE_Configuration_ExtId section_ext (section.fast_rep ());
01801 ACE_Configuration_Section_IntId section_int;
01802 if (index_->find (section_ext, section_int, allocator_))
01803 return -1;
01804
01805 // Get the entry for this item (if it exists)
01806 VALUE_HASH::ENTRY* entry;
01807 ACE_Configuration_ExtId item_name (t_name);
01808 if (section_int.value_hash_map_->VALUE_HASH::find (item_name, entry) == 0)
01809 {
01810 // found item, replace it
01811 // Free the old value
01812 entry->int_id_.free (allocator_);
01813 // Allocate the new value in this heap
01814 ACE_TCHAR* pers_value =
01815 (ACE_TCHAR *) allocator_->malloc ((value.length () + 1) * sizeof (ACE_TCHAR));
01816 ACE_OS::strcpy (pers_value, value.fast_rep ());
01817 ACE_Configuration_Value_IntId new_value_int (pers_value);
01818 entry->int_id_ = new_value_int;
01819 }
01820 else
01821 {
01822 // it doesn't exist, bind it
01823 ACE_TCHAR* pers_name =
01824 (ACE_TCHAR *) allocator_->malloc ((ACE_OS::strlen (t_name) + 1) * sizeof (ACE_TCHAR));
01825 ACE_OS::strcpy (pers_name, t_name);
01826 ACE_TCHAR* pers_value =
01827 (ACE_TCHAR *) allocator_->malloc ((value.length () + 1) * sizeof (ACE_TCHAR));
01828 ACE_OS::strcpy (pers_value, value.fast_rep ());
01829 ACE_Configuration_ExtId item_name (pers_name);
01830 ACE_Configuration_Value_IntId item_value (pers_value);
01831 if (section_int.value_hash_map_->bind (item_name, item_value, allocator_))
01832 {
01833 allocator_->free (pers_value);
01834 allocator_->free (pers_name);
01835 return -1;
01836 }
01837 return 0;
01838 }
01839
01840 return 0;
01841 }
|
|
||||||||||||
|
Definition at line 1509 of file Configuration.cpp. References ACE_ASSERT, and VALUE_MAP. Referenced by new_section().
01511 {
01512 ACE_ASSERT (this->allocator_);
01513 new (buffer) VALUE_MAP (hash_table_size, this->allocator_);
01514 return 0;
01515 }
|
|
|
Definition at line 884 of file Configuration.h. |
|
|
Definition at line 886 of file Configuration.h. Referenced by new_section(), and open(). |
|
|
Definition at line 885 of file Configuration.h. Referenced by add_section(), create_index(), create_index_helper(), enumerate_sections(), enumerate_values(), find_value(), get_binary_value(), get_integer_value(), get_string_value(), new_section(), open_simple_section(), remove_section(), remove_value(), set_binary_value(), set_integer_value(), and set_string_value(). |
1.3.6