#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 from . 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 1280 of file Configuration.cpp. References ACE_LIB_TEXT, and ACE_NEW.
01281 : allocator_ (0), 01282 index_ (0), 01283 default_map_size_ (0) 01284 { 01285 ACE_Configuration_Section_Key_Heap *temp = 0; 01286 01287 ACE_NEW (temp, ACE_Configuration_Section_Key_Heap (ACE_LIB_TEXT (""))); 01288 root_ = ACE_Configuration_Section_Key (temp); 01289 } |
|
|
Destructor.
Definition at line 1291 of file Configuration.cpp. References ACE_Allocator::sync().
01292 {
01293 if (allocator_)
01294 allocator_->sync ();
01295
01296 delete allocator_;
01297 }
|
|
|
|
|
||||||||||||||||
|
Adds a new section.
Definition at line 1410 of file Configuration.cpp. References ACE_ASSERT, ACE_LIB_TEXT, 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(), new_section(), ACE_Configuration_Section_IntId::section_hash_map_, and ACE_OS::strcpy(). Referenced by open_simple_section().
01413 {
01414 ACE_ASSERT (this->allocator_);
01415 ACE_TString section;
01416 if (load_key (base, section))
01417 return -1;
01418
01419 // Find the base section
01420 ACE_Configuration_ExtId ExtId (section.fast_rep ());
01421 ACE_Configuration_Section_IntId IntId;
01422 if (index_->find (ExtId, IntId, allocator_))
01423 return -1;
01424
01425 // See if this section already exists
01426 ACE_Configuration_ExtId SubSectionExtId (sub_section);
01427 int ignored = 0;
01428
01429 if (!IntId.section_hash_map_->find (SubSectionExtId, ignored, allocator_))
01430 {
01431 // already exists!
01432 errno = EEXIST;
01433 return -1;
01434 }
01435
01436 // Create the new section name
01437 // only prepend a separater if were not at the root
01438 if (section.length ())
01439 section += ACE_LIB_TEXT ("\\");
01440
01441 section += sub_section;
01442
01443 // Add it to the base section
01444 ACE_TCHAR* pers_name = (ACE_TCHAR *) allocator_->malloc ((ACE_OS::strlen (sub_section) + 1) * sizeof (ACE_TCHAR));
01445 ACE_OS::strcpy (pers_name, sub_section);
01446 ACE_Configuration_ExtId SSExtId (pers_name);
01447 if (IntId.section_hash_map_->bind (SSExtId, ignored, allocator_))
01448 {
01449 allocator_->free (pers_name);
01450 return -1;
01451 }
01452 return (new_section (section, result));
01453 }
|
|
|
Helper for the method.
Definition at line 1349 of file Configuration.cpp. References ACE_CONFIG_SECTION_INDEX, ACE_ERROR, ACE_LIB_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().
01350 {
01351 void *section_index = 0;
01352
01353 // This is the easy case since if we find hash table in the
01354 // memory-mapped file we know it's already initialized.
01355 if (this->allocator_->find (ACE_CONFIG_SECTION_INDEX, section_index) == 0)
01356 this->index_ = (SECTION_MAP *) section_index;
01357
01358 // Create a new <index_> (because we've just created a new
01359 // memory-mapped file).
01360 else
01361 {
01362 size_t index_size = sizeof (SECTION_MAP);
01363 section_index = this->allocator_->malloc (index_size);
01364
01365 if (section_index == 0
01366 || create_index_helper (section_index) == -1
01367 || this->allocator_->bind (ACE_CONFIG_SECTION_INDEX,
01368 section_index) == -1)
01369 {
01370 // Attempt to clean up.
01371 ACE_ERROR ((LM_ERROR,
01372 ACE_LIB_TEXT ("create_index failed\n")));
01373 this->allocator_->remove ();
01374 return -1;
01375 }
01376 // Add the root section
01377 return new_section (ACE_LIB_TEXT (""), root_);
01378 }
01379 return 0;
01380 }
|
|
|
Helper for create_index() method: places hash table into an allocated space. Definition at line 1383 of file Configuration.cpp. References ACE_ASSERT, index_, and SECTION_MAP. Referenced by create_index().
01384 {
01385 ACE_ASSERT (this->allocator_);
01386 this->index_ = new (buffer) SECTION_MAP (this->allocator_);
01387 return 0;
01388 }
|
|
||||||||||||||||
|
Enumerates through the subsections in a section.
Implements ACE_Configuration. Definition at line 1781 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().
01784 {
01785 ACE_ASSERT (this->allocator_);
01786 // cast to a heap section key
01787 ACE_Configuration_Section_Key_Heap* pKey =
01788 dynamic_cast<ACE_Configuration_Section_Key_Heap*> (get_internal_key (key));
01789 if (!pKey)
01790 return -1; // not a heap key!
01791
01792 // resolve the section
01793 ACE_Configuration_ExtId ExtId (pKey->path_);
01794 ACE_Configuration_Section_IntId IntId;
01795 if (index_->find (ExtId, IntId, allocator_))
01796 return -1; // unknown section
01797
01798 // Handle iterator resets
01799 if (index == 0)
01800 {
01801 if (pKey->section_iter_)
01802 delete pKey->section_iter_;
01803
01804 ACE_NEW_RETURN (pKey->section_iter_,
01805 SUBSECTION_HASH::ITERATOR (IntId.section_hash_map_->begin ()),
01806 -1);
01807 }
01808
01809 // Get the next entry
01810 ACE_Hash_Map_Entry<ACE_Configuration_ExtId, int>* entry = 0;
01811 if (!pKey->section_iter_->next (entry))
01812 return 1;
01813
01814 // Return the value of the iterator and advance it
01815 pKey->section_iter_->advance ();
01816 name = entry->ext_id_.name_;
01817
01818 return 0;
01819 }
|
|
||||||||||||||||||||
|
Enumerates through the values in a section.
Implements ACE_Configuration. Definition at line 1732 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_.
01736 {
01737 ACE_ASSERT (this->allocator_);
01738 ACE_Configuration_Section_Key_Heap* pKey =
01739 dynamic_cast<ACE_Configuration_Section_Key_Heap*> (get_internal_key (key));
01740 if (!pKey)
01741 return -1;
01742
01743 name = pKey->path_;
01744
01745 // resolve the section
01746 ACE_Configuration_ExtId ExtId (pKey->path_);
01747 ACE_Configuration_Section_IntId IntId;
01748 if (index_->find (ExtId, IntId, allocator_))
01749 return -1;
01750
01751 // Handle iterator resets
01752 if (index == 0)
01753 {
01754 ACE_Hash_Map_Manager_Ex<ACE_Configuration_ExtId ,
01755 ACE_Configuration_Value_IntId,
01756 ACE_Hash<ACE_Configuration_ExtId>,
01757 ACE_Equal_To<ACE_Configuration_ExtId>,
01758 ACE_Null_Mutex>* hash_map = IntId.value_hash_map_;
01759 delete pKey->value_iter_;
01760
01761 ACE_NEW_RETURN (pKey->value_iter_,
01762 VALUE_HASH::ITERATOR (hash_map->begin ()),
01763 -1);
01764 }
01765
01766 // Get the next entry
01767 ACE_Hash_Map_Entry<ACE_Configuration_ExtId, ACE_Configuration_Value_IntId>* entry = 0;
01768
01769 if (!pKey->value_iter_->next (entry))
01770 return 1;
01771
01772 // Return the value of the iterator and advance it
01773 name = entry->ext_id_.name_;
01774 type = entry->int_id_.type_;
01775 pKey->value_iter_->advance ();
01776
01777 return 0;
01778 }
|
|
||||||||||||||||
|
Retrieves the type of a named configuration value.
Implements ACE_Configuration. Definition at line 2117 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_.
02120 {
02121 ACE_ASSERT (this->allocator_);
02122 const ACE_TCHAR *t_name = name ? name : &this->NULL_String_;
02123 if (validate_value_name (t_name))
02124 return -1;
02125
02126 // Get the section name from the key
02127 ACE_TString section;
02128 if (load_key (key, section))
02129 return -1;
02130
02131 // Find this section
02132 ACE_Configuration_ExtId ExtId (section.fast_rep ());
02133 ACE_Configuration_Section_IntId IntId;
02134 if (index_->find (ExtId, IntId, allocator_))
02135 return -1; // section does not exist
02136
02137 // Find it
02138 ACE_Configuration_ExtId ValueExtId (t_name);
02139 VALUE_HASH::ENTRY* value_entry;
02140 if (((VALUE_HASH *) IntId.value_hash_map_)->find (ValueExtId, value_entry))
02141 return -1; // value does not exist
02142
02143 type_out = value_entry->int_id_.type_;
02144 return 0;
02145 }
|
|
||||||||||||||||||||
|
Gets a binary-typed value.
Implements ACE_Configuration. Definition at line 2075 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_.
02079 {
02080 ACE_ASSERT (this->allocator_);
02081 const ACE_TCHAR *t_name = name ? name : &this->NULL_String_;
02082 if (validate_value_name (t_name))
02083 return -1;
02084
02085 // Get the section name from the key
02086 ACE_TString section;
02087 if (load_key (key, section))
02088 return -1;
02089
02090 // Find this section
02091 ACE_Configuration_ExtId ExtId (section.fast_rep ());
02092 ACE_Configuration_Section_IntId IntId;
02093 if (index_->find (ExtId, IntId, allocator_))
02094 return -1; // section does not exist
02095
02096 ACE_Configuration_ExtId VExtId (t_name);
02097 ACE_Configuration_Value_IntId VIntId;
02098 // See if it exists first
02099 if (IntId.value_hash_map_->find (VExtId, VIntId, allocator_))
02100 return -1; // unknown value
02101
02102 // Check type
02103 if (VIntId.type_ != ACE_Configuration::BINARY)
02104 {
02105 errno = ENOENT;
02106 return -1;
02107 }
02108
02109 // Make a copy
02110 ACE_NEW_RETURN (data, char[VIntId.length_], -1);
02111 ACE_OS::memcpy (data, VIntId.data_.ptr_, VIntId.length_);
02112 length = VIntId.length_;
02113 return 0;
02114 }
|
|
||||||||||||||||
|
Gets an integer-typed value.
Implements ACE_Configuration. Definition at line 2025 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_.
02028 {
02029 ACE_ASSERT (this->allocator_);
02030
02031 const ACE_TCHAR *t_name = name ? name : &this->NULL_String_;
02032 if (validate_value_name (t_name))
02033 return -1;
02034
02035 // Get the section name from the key
02036 ACE_TString section (0, 0, 0);
02037
02038 if (this->load_key (key, section) != 0)
02039 {
02040 return -1;
02041 }
02042
02043 // Find this section
02044 ACE_Configuration_ExtId ExtId (section.fast_rep ());
02045 ACE_Configuration_Section_IntId IntId;
02046
02047 if (index_->find (ExtId, IntId, allocator_) != 0)
02048 {
02049 return -1; // section does not exist
02050 }
02051
02052
02053 // See if it exists first
02054 ACE_Configuration_ExtId VExtId (t_name);
02055 ACE_Configuration_Value_IntId VIntId;
02056
02057 if (IntId.value_hash_map_->find (VExtId, VIntId, allocator_) != 0)
02058 {
02059 return -1; // unknown value
02060 }
02061
02062 // Check type
02063 if (VIntId.type_ != ACE_Configuration::INTEGER)
02064 {
02065 errno = ENOENT;
02066 return -1;
02067 }
02068
02069 // Everythings ok, return the data
02070 value = VIntId.data_.int_;
02071 return 0;
02072 }
|
|
||||||||||||||||
|
Gets a string-typed value.
Implements ACE_Configuration. Definition at line 1986 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_.
01989 {
01990 ACE_ASSERT (this->allocator_);
01991 const ACE_TCHAR *t_name = name ? name : &this->NULL_String_;
01992 if (validate_value_name (t_name))
01993 return -1;
01994
01995 // Get the section name from the key
01996 ACE_TString section;
01997 if (load_key (key, section))
01998 return -1;
01999
02000 // Find this section
02001 ACE_Configuration_ExtId ExtId (section.fast_rep ());
02002 ACE_Configuration_Section_IntId IntId;
02003 if (index_->find (ExtId, IntId, allocator_))
02004 return -1; // section does not exist
02005
02006 // See if it exists first
02007 ACE_Configuration_ExtId VExtId (t_name);
02008 ACE_Configuration_Value_IntId VIntId;
02009 if (IntId.value_hash_map_->find (VExtId, VIntId, allocator_))
02010 return -1; // unknown value
02011
02012 // Check type
02013 if (VIntId.type_ != ACE_Configuration::STRING)
02014 {
02015 errno = ENOENT;
02016 return -1;
02017 }
02018
02019 // everythings ok, return the data
02020 value = static_cast<ACE_TCHAR*> (VIntId.data_.ptr_);
02021 return 0;
02022 }
|
|
||||||||||||
|
Definition at line 1391 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().
01393 {
01394 ACE_ASSERT (this->allocator_);
01395 ACE_Configuration_Section_Key_Heap* pKey =
01396 dynamic_cast<ACE_Configuration_Section_Key_Heap*> (get_internal_key (key));
01397
01398 if (!pKey)
01399 {
01400 return -1;
01401 }
01402
01403 ACE_TString temp (pKey->path_, 0, 0);
01404 name.assign_nocopy (temp);
01405 return 0;
01406 }
|
|
||||||||||||
|
Definition at line 1456 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().
01458 {
01459 ACE_ASSERT (this->allocator_);
01460 // Create a new section and add it to the global list
01461
01462 // Allocate memory for items to be stored in the table.
01463 size_t section_len = section.length () + 1;
01464 ACE_TCHAR *ptr = (ACE_TCHAR*) this->allocator_->malloc (section_len * sizeof (ACE_TCHAR));
01465
01466 int return_value = -1;
01467
01468 if (ptr == 0)
01469 return -1;
01470 else
01471 {
01472 // Populate memory with data.
01473 ACE_OS::strcpy (ptr, section.fast_rep ());
01474
01475 void *value_hash_map = 0;
01476 size_t map_size = sizeof (VALUE_MAP);
01477 value_hash_map = this->allocator_->malloc (map_size);
01478
01479 // If allocation failed ...
01480 if (value_hash_map == 0)
01481 return -1;
01482
01483 // Initialize allocated hash map through placement new.
01484 if (value_open_helper (default_map_size_, value_hash_map ) == -1)
01485 {
01486 this->allocator_->free (value_hash_map );
01487 return -1;
01488 }
01489
01490 // create the section map
01491 void* section_hash_map = 0;
01492 map_size = sizeof (SUBSECTION_MAP);
01493 section_hash_map = this->allocator_->malloc (map_size);
01494
01495 // If allocation failed
01496 if (section_hash_map == 0)
01497 return -1;
01498
01499 // initialize allocated hash map through placement new
01500 if (section_open_helper (default_map_size_, section_hash_map) == -1)
01501 {
01502 this->allocator_->free (value_hash_map );
01503 this->allocator_->free (section_hash_map);
01504 return -1;
01505 }
01506
01507 ACE_Configuration_ExtId name (ptr);
01508 ACE_Configuration_Section_IntId entry ((VALUE_MAP*) value_hash_map,
01509 (SUBSECTION_MAP*) section_hash_map);
01510
01511 // Do a normal bind. This will fail if there's already an
01512 // entry with the same name.
01513 return_value = this->index_->bind (name, entry, this->allocator_);
01514
01515 if (return_value == 1)
01516 {
01517 // Entry already existed so bind failed. Free our dynamically
01518 // allocated memory.
01519 this->allocator_->free ((void *) ptr);
01520 return return_value;
01521 }
01522
01523 if (return_value == -1)
01524 // Free our dynamically allocated memory.
01525 this->allocator_->free ((void *) ptr);
01526 else
01527 // If bind () succeed, it will automatically sync
01528 // up the map manager entry. However, we must sync up our
01529 // name/value memory.
01530 this->allocator_->sync (ptr, section_len);
01531
01532 }
01533
01534 // set the result
01535 ACE_Configuration_Section_Key_Heap *temp;
01536 ACE_NEW_RETURN (temp,
01537 ACE_Configuration_Section_Key_Heap (ptr),
01538 -1);
01539 result = ACE_Configuration_Section_Key (temp);
01540 return return_value;
01541 }
|
|
|
Opens a heap based configuration.
Definition at line 1300 of file Configuration.cpp. References ACE_NEW_RETURN, create_index(), default_map_size_, and HEAP_ALLOCATOR.
01301 {
01302 default_map_size_ = default_map_size;
01303 // Create the allocator with the appropriate options.
01304 // The name used for the lock is the same as one used
01305 // for the file.
01306 ACE_NEW_RETURN (this->allocator_,
01307 HEAP_ALLOCATOR (),
01308 -1);
01309 return create_index ();
01310 }
|
|
||||||||||||||||
|
Opens a configuration based on a file name.
Definition at line 1314 of file Configuration.cpp. References ACE_OS::access(), ACE_ERROR_RETURN, ACE_LIB_TEXT, ACE_NEW_RETURN, ACE_TCHAR, create_index(), default_map_size_, F_OK, LM_ERROR, MAXNAMELEN, MAXPATHLEN, PERSISTENT_ALLOCATOR, and ACE_OS::strlen().
01317 {
01318 default_map_size_ = default_map_size;
01319
01320 // Make sure that the file name is of the legal length.
01321 if (ACE_OS::strlen (file_name) >= MAXNAMELEN + MAXPATHLEN)
01322 {
01323 errno = ENAMETOOLONG;
01324 return -1;
01325 }
01326
01327 ACE_MMAP_Memory_Pool::OPTIONS options (base_address);
01328
01329 // Create the allocator with the appropriate options. The name used
01330 // for the lock is the same as one used for the file.
01331 ACE_NEW_RETURN (this->allocator_,
01332 PERSISTENT_ALLOCATOR (file_name,
01333 file_name,
01334 &options),
01335 -1);
01336
01337 #if !defined (ACE_LACKS_ACCESS)
01338 // Now check if the backing store has been created successfully.
01339 if (ACE_OS::access (file_name, F_OK) != 0)
01340 ACE_ERROR_RETURN ((LM_ERROR,
01341 ACE_LIB_TEXT ("create_index\n")),
01342 -1);
01343 #endif /* ACE_LACKS_ACCESS */
01344
01345 return create_index ();
01346 }
|
|
||||||||||||||||||||
|
Opens a named section in an existing section.
Implements ACE_Configuration. Definition at line 1562 of file Configuration.cpp. References ACE_ASSERT, ACE_LIB_TEXT, ACE_TCHAR, ACE_TString, ACE_String_Base< CHAR >::c_str(), open_simple_section(), ACE_OS::strchr(), and ACE_Configuration::validate_name(). Referenced by remove_section().
01566 {
01567 ACE_ASSERT (this->allocator_);
01568 if (validate_name (sub_section, 1)) // 1 == allow_path
01569 return -1;
01570
01571 result = base;
01572
01573 for (const ACE_TCHAR* separator;
01574 (separator = ACE_OS::strchr (sub_section, ACE_LIB_TEXT ('\\'))) != 0;
01575 )
01576 {
01577 ACE_TString simple_section (sub_section, separator - sub_section);
01578 int ret_val =
01579 open_simple_section (result, simple_section.c_str (), create, result);
01580 if (ret_val)
01581 return ret_val;
01582 sub_section = separator + 1;
01583 }
01584
01585 return open_simple_section (result, sub_section, create, result);
01586 }
|
|
||||||||||||||||||||
|
may not contain path separators
Definition at line 1589 of file Configuration.cpp. References ACE_LIB_TEXT, ACE_NEW_RETURN, ACE_TCHAR, 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().
01593 {
01594 ACE_TString section (0, 0, 0);
01595
01596 if (load_key (base, section))
01597 {
01598 return -1;
01599 }
01600
01601 // Only add the \\ if were not at the root
01602 if (section.length ())
01603 {
01604 section += ACE_LIB_TEXT ("\\");
01605 }
01606
01607 section += sub_section;
01608
01609 // resolve the section
01610 ACE_Configuration_ExtId ExtId (section.fast_rep ());
01611 ACE_Configuration_Section_IntId IntId;
01612
01613 if (index_->find (ExtId, IntId, allocator_))
01614 {
01615 if (!create)
01616 {
01617 errno = ENOENT;
01618 return -1;
01619 }
01620
01621 return add_section (base, sub_section, result);
01622 }
01623
01624 ACE_Configuration_Section_Key_Heap *temp;
01625 ACE_NEW_RETURN (temp,
01626 ACE_Configuration_Section_Key_Heap (section.fast_rep ()),
01627 -1);
01628 result = ACE_Configuration_Section_Key (temp);
01629 return 0;
01630 }
|
|
|
|
|
||||||||||||||||
|
Removes a named section.
Implements ACE_Configuration. Definition at line 1633 of file Configuration.cpp. References ACE_ASSERT, ACE_LIB_TEXT, ACE_TCHAR, 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.
01636 {
01637 ACE_ASSERT (this->allocator_);
01638 if (validate_name (sub_section))
01639 return -1;
01640
01641 ACE_TString section;
01642 if (load_key (key, section))
01643 return -1;
01644
01645 // Find this key
01646 ACE_Configuration_ExtId ParentExtId (section.fast_rep ());
01647 ACE_Configuration_Section_IntId ParentIntId;
01648 if (index_->find (ParentExtId, ParentIntId, allocator_))
01649 return -1;// no parent key
01650
01651 // Find this subkey
01652 if (section.length ())
01653 section += ACE_LIB_TEXT ("\\");
01654
01655 section += sub_section;
01656 ACE_Configuration_ExtId SectionExtId (section.fast_rep ());
01657 SECTION_HASH::ENTRY* section_entry;
01658 SECTION_HASH* hashmap = index_;
01659 if (hashmap->find (SectionExtId, section_entry))
01660 return -1;
01661
01662 if (recursive)
01663 {
01664 ACE_Configuration_Section_Key section;
01665 if (open_section (key, sub_section, 0, section))
01666 return -1;
01667
01668 int index = 0;
01669 ACE_TString name;
01670 while (!enumerate_sections (section, index, name))
01671 {
01672 if (remove_section (section, name.fast_rep (), 1))
01673 return -1;
01674
01675 ++index;
01676 }
01677 }
01678
01679 // Now make sure we dont have any subkeys
01680 if (section_entry->int_id_.section_hash_map_->current_size ())
01681 {
01682 errno = ENOTEMPTY;
01683 return -1;
01684 }
01685
01686 // Now remove subkey from parent key
01687 ACE_Configuration_ExtId SubSExtId (sub_section);
01688 SUBSECTION_HASH::ENTRY* subsection_entry;
01689 if (((SUBSECTION_HASH*)ParentIntId.section_hash_map_)->
01690 find (SubSExtId, subsection_entry))
01691 return -1;
01692
01693 if (ParentIntId.section_hash_map_->unbind (SubSExtId, allocator_))
01694 return -1;
01695
01696 subsection_entry->ext_id_.free (allocator_);
01697
01698 // Remember the pointers so we can free them after we unbind
01699 ACE_Configuration_ExtId ExtIdToFree (section_entry->ext_id_);
01700 ACE_Configuration_Section_IntId IntIdToFree (section_entry->int_id_);
01701
01702 // iterate over all values and free memory
01703 VALUE_HASH* value_hash_map = section_entry->int_id_.value_hash_map_;
01704 VALUE_HASH::ITERATOR value_iter = value_hash_map->begin ();
01705 while (!value_iter.done ())
01706 {
01707 VALUE_HASH::ENTRY* value_entry = 0;
01708 if (!value_iter.next (value_entry))
01709 return 1;
01710
01711 value_entry->ext_id_.free (allocator_);
01712 value_entry->int_id_.free (allocator_);
01713
01714 value_iter.advance ();
01715 }
01716
01717 // remove it
01718 if (index_->unbind (SectionExtId, allocator_))
01719 return -1;
01720
01721 value_hash_map->close ();
01722 section_entry->int_id_.section_hash_map_->close (allocator_);
01723
01724 // Free the memory
01725 ExtIdToFree.free (allocator_);
01726 IntIdToFree.free (allocator_);
01727
01728 return 0;
01729 }
|
|
||||||||||||
|
Removes the the value from . returns non zero on error.
Implements ACE_Configuration. Definition at line 2148 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_.
02150 {
02151 ACE_ASSERT (this->allocator_);
02152 const ACE_TCHAR *t_name = name ? name : &this->NULL_String_;
02153 if (validate_value_name (t_name))
02154 return -1;
02155
02156 // Get the section name from the key
02157 ACE_TString section;
02158 if (load_key (key, section))
02159 return -1;
02160
02161 // Find this section
02162 ACE_Configuration_ExtId ExtId (section.fast_rep ());
02163 ACE_Configuration_Section_IntId IntId;
02164 if (index_->find (ExtId, IntId, allocator_))
02165 return -1; // section does not exist
02166
02167 // Find it
02168 ACE_Configuration_ExtId ValueExtId (t_name);
02169 VALUE_HASH::ENTRY* value_entry;
02170 if (((VALUE_HASH *) IntId.value_hash_map_)->find (ValueExtId, value_entry))
02171 return -1;
02172
02173 // free it
02174 value_entry->ext_id_.free (allocator_);
02175 value_entry->int_id_.free (allocator_);
02176
02177 // Unbind it
02178 if (IntId.value_hash_map_->unbind (ValueExtId, allocator_))
02179 return -1;
02180
02181 return 0;
02182 }
|
|
||||||||||||
|
Definition at line 1553 of file Configuration.cpp. References ACE_ASSERT, and SUBSECTION_MAP. Referenced by new_section().
01555 {
01556 ACE_ASSERT (this->allocator_);
01557 new (buffer) SUBSECTION_MAP (hash_table_size, this->allocator_);
01558 return 0;
01559 }
|
|
||||||||||||||||||||
|
Sets a binary-typed value.
Implements ACE_Configuration. Definition at line 1928 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_.
01932 {
01933 ACE_ASSERT (this->allocator_);
01934 const ACE_TCHAR *t_name = name ? name : &this->NULL_String_;
01935 if (validate_value_name (t_name))
01936 return -1;
01937
01938 // Get the section name from the key
01939 ACE_TString section;
01940 if (load_key (key, section))
01941 return -1;
01942
01943 // Find this section
01944 ACE_Configuration_ExtId section_ext (section.fast_rep ());
01945 ACE_Configuration_Section_IntId section_int;
01946 if (index_->find (section_ext, section_int, allocator_))
01947 return -1; // section does not exist
01948
01949 // Get the entry for this item (if it exists)
01950 VALUE_HASH::ENTRY* entry;
01951 ACE_Configuration_ExtId item_name (t_name);
01952 if (section_int.value_hash_map_->VALUE_HASH::find (item_name, entry) == 0)
01953 {
01954 // found item, replace it
01955 // Free the old value
01956 entry->int_id_.free (allocator_);
01957 // Allocate the new value in this heap
01958 ACE_TCHAR* pers_value = (ACE_TCHAR *) allocator_->malloc (length);
01959 ACE_OS::memcpy (pers_value, data, length);
01960 ACE_Configuration_Value_IntId new_value_int (pers_value, length);
01961 entry->int_id_ = new_value_int;
01962 }
01963 else
01964 {
01965 // it doesn't exist, bind it
01966 ACE_TCHAR* pers_name =
01967 (ACE_TCHAR *) allocator_->malloc ((ACE_OS::strlen (t_name) + 1) * sizeof (ACE_TCHAR));
01968 ACE_OS::strcpy (pers_name, t_name);
01969 ACE_TCHAR* pers_value = (ACE_TCHAR *) allocator_->malloc (length);
01970 ACE_OS::memcpy (pers_value, data, length);
01971 ACE_Configuration_ExtId item_name (pers_name);
01972 ACE_Configuration_Value_IntId item_value (pers_value, length);
01973 if (section_int.value_hash_map_->bind (item_name, item_value, allocator_))
01974 {
01975 allocator_->free (pers_value);
01976 allocator_->free (pers_name);
01977 return -1;
01978 }
01979 return 0;
01980 }
01981
01982 return 0;
01983 }
|
|
||||||||||||||||
|
Sets a integer-typed value.
Implements ACE_Configuration. Definition at line 1879 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_.
01882 {
01883 ACE_ASSERT (this->allocator_);
01884 const ACE_TCHAR *t_name = name ? name : &this->NULL_String_;
01885 if (validate_value_name (t_name))
01886 return -1;
01887
01888 // Get the section name from the key
01889 ACE_TString section;
01890 if (load_key (key, section))
01891 return -1;
01892
01893 // Find this section
01894 ACE_Configuration_ExtId section_ext (section.fast_rep ());
01895 ACE_Configuration_Section_IntId section_int;
01896 if (index_->find (section_ext, section_int, allocator_))
01897 return -1; // section does not exist
01898
01899 // Get the entry for this item (if it exists)
01900 VALUE_HASH::ENTRY* entry;
01901 ACE_Configuration_ExtId item_name (t_name);
01902 if (section_int.value_hash_map_->VALUE_HASH::find (item_name, entry) == 0)
01903 {
01904 // found item, replace it
01905 ACE_Configuration_Value_IntId new_value_int (value);
01906 entry->int_id_ = new_value_int;
01907 }
01908 else
01909 {
01910 // it doesn't exist, bind it
01911 ACE_TCHAR* pers_name =
01912 (ACE_TCHAR *) allocator_->malloc ((ACE_OS::strlen (t_name) + 1) * sizeof (ACE_TCHAR));
01913 ACE_OS::strcpy (pers_name, t_name);
01914 ACE_Configuration_ExtId item_name (pers_name);
01915 ACE_Configuration_Value_IntId item_value (value);
01916 if (section_int.value_hash_map_->bind (item_name, item_value, allocator_))
01917 {
01918 allocator_->free (pers_name);
01919 return -1;
01920 }
01921 return 0;
01922 }
01923
01924 return 0;
01925 }
|
|
||||||||||||||||
|
Sets a string-typed value.
Implements ACE_Configuration. Definition at line 1822 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_.
01825 {
01826 ACE_ASSERT (this->allocator_);
01827 const ACE_TCHAR *t_name = name ? name : &this->NULL_String_;
01828 if (validate_value_name (t_name))
01829 return -1;
01830
01831 ACE_TString section;
01832 if (load_key (key, section))
01833 return -1;
01834
01835 ACE_Configuration_ExtId section_ext (section.fast_rep ());
01836 ACE_Configuration_Section_IntId section_int;
01837 if (index_->find (section_ext, section_int, allocator_))
01838 return -1;
01839
01840 // Get the entry for this item (if it exists)
01841 VALUE_HASH::ENTRY* entry;
01842 ACE_Configuration_ExtId item_name (t_name);
01843 if (section_int.value_hash_map_->VALUE_HASH::find (item_name, entry) == 0)
01844 {
01845 // found item, replace it
01846 // Free the old value
01847 entry->int_id_.free (allocator_);
01848 // Allocate the new value in this heap
01849 ACE_TCHAR* pers_value =
01850 (ACE_TCHAR *) allocator_->malloc ((value.length () + 1) * sizeof (ACE_TCHAR));
01851 ACE_OS::strcpy (pers_value, value.fast_rep ());
01852 ACE_Configuration_Value_IntId new_value_int (pers_value);
01853 entry->int_id_ = new_value_int;
01854 }
01855 else
01856 {
01857 // it doesn't exist, bind it
01858 ACE_TCHAR* pers_name =
01859 (ACE_TCHAR *) allocator_->malloc ((ACE_OS::strlen (t_name) + 1) * sizeof (ACE_TCHAR));
01860 ACE_OS::strcpy (pers_name, t_name);
01861 ACE_TCHAR* pers_value =
01862 (ACE_TCHAR *) allocator_->malloc ((value.length () + 1) * sizeof (ACE_TCHAR));
01863 ACE_OS::strcpy (pers_value, value.fast_rep ());
01864 ACE_Configuration_ExtId item_name (pers_name);
01865 ACE_Configuration_Value_IntId item_value (pers_value);
01866 if (section_int.value_hash_map_->bind (item_name, item_value, allocator_))
01867 {
01868 allocator_->free (pers_value);
01869 allocator_->free (pers_name);
01870 return -1;
01871 }
01872 return 0;
01873 }
01874
01875 return 0;
01876 }
|
|
||||||||||||
|
Definition at line 1544 of file Configuration.cpp. References ACE_ASSERT, and VALUE_MAP. Referenced by new_section().
01546 {
01547 ACE_ASSERT (this->allocator_);
01548 new (buffer) VALUE_MAP (hash_table_size, this->allocator_);
01549 return 0;
01550 }
|
|
|
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