00001 
00002 
00003 
00004 
00005 
00006 
00007 
00008 
00009 
00010 
00011 
00012 
00013 
00014 
00015 
00016 
00017 
00018 
00019 
00020 
00021 
00022 
00023 
00024 
00025 
00026 
00027 
00028 
00029 
00030 #ifndef ACE_CONFIGURATION_H
00031 #define ACE_CONFIGURATION_H
00032 #include  "ace/pre.h"
00033 
00034 #include "ace/SStringfwd.h"
00035 #include "ace/Hash_Map_With_Allocator_T.h"
00036 #include "ace/Malloc_T.h"
00037 #include "ace/MMAP_Memory_Pool.h"
00038 #include "ace/Local_Memory_Pool.h"
00039 #include "ace/Synch_Traits.h"
00040 
00041 
00042 #if !defined (ACE_LACKS_PRAGMA_ONCE)
00043 # pragma once
00044 #endif 
00045 
00046 
00047 
00048 #if !defined (ACE_CONFIG_SECTION_INDEX)
00049 #  define ACE_CONFIG_SECTION_INDEX "Config_Section_Index"
00050 #endif 
00051 
00052 #if !defined (ACE_DEFAULT_CONFIG_SECTION_SIZE)
00053 #define ACE_DEFAULT_CONFIG_SECTION_SIZE 16
00054 #endif 
00055 
00056 ACE_BEGIN_VERSIONED_NAMESPACE_DECL
00057 
00058 
00059 
00060 
00061 
00062 
00063 
00064 
00065 
00066 
00067 
00068 
00069 
00070 class ACE_Export ACE_Section_Key_Internal
00071 {
00072 public:
00073 
00074   virtual ~ACE_Section_Key_Internal (void);
00075 
00076 
00077   virtual int add_ref (void);
00078 
00079 
00080   virtual int dec_ref (void);
00081 protected:
00082   ACE_Section_Key_Internal (void);
00083   ACE_Section_Key_Internal (const ACE_Section_Key_Internal& rhs);
00084   ACE_Section_Key_Internal& operator= (ACE_Section_Key_Internal& rhs);
00085 
00086   u_int ref_count_;
00087 };
00088 
00089 
00090 
00091 
00092 
00093 
00094 
00095 
00096 
00097 
00098 class ACE_Export ACE_Configuration_Section_Key
00099 {
00100   friend class ACE_Configuration;
00101 public:
00102 
00103   ACE_Configuration_Section_Key (void);
00104 
00105 
00106 
00107 
00108 
00109   explicit ACE_Configuration_Section_Key (ACE_Section_Key_Internal *key);
00110 
00111 
00112   ACE_Configuration_Section_Key (const ACE_Configuration_Section_Key &rhs);
00113 
00114 
00115   ~ACE_Configuration_Section_Key (void);
00116 
00117 
00118 
00119   ACE_Configuration_Section_Key &
00120     operator= (const ACE_Configuration_Section_Key &rhs);
00121 private:
00122   ACE_Section_Key_Internal *key_;
00123 };
00124 
00125 
00126 
00127 
00128 
00129 
00130 
00131 
00132 
00133 
00134 
00135 
00136 
00137 
00138 class ACE_Export ACE_Configuration
00139 {
00140 public:
00141 
00142   enum VALUETYPE
00143   {
00144     STRING,
00145     INTEGER,
00146     BINARY,
00147     INVALID
00148   };
00149 
00150 
00151   virtual ~ACE_Configuration (void);
00152 
00153 
00154   
00155 
00156 
00157 
00158   virtual const ACE_Configuration_Section_Key& root_section (void) const;
00159 
00160 
00161 
00162 
00163 
00164 
00165 
00166 
00167 
00168 
00169 
00170 
00171 
00172 
00173   virtual int open_section (const ACE_Configuration_Section_Key &base,
00174                             const ACE_TCHAR *sub_section,
00175                             int create,
00176                             ACE_Configuration_Section_Key& result) = 0;
00177 
00178 
00179 
00180 
00181 
00182 
00183 
00184 
00185 
00186 
00187 
00188   virtual int remove_section (const ACE_Configuration_Section_Key &key,
00189                               const ACE_TCHAR *sub_section,
00190                               int recursive) = 0;
00191 
00192 
00193 
00194 
00195 
00196 
00197 
00198 
00199 
00200 
00201 
00202 
00203 
00204 
00205 
00206 
00207 
00208 
00209 
00210   virtual int enumerate_values (const ACE_Configuration_Section_Key& key,
00211                                 int index,
00212                                 ACE_TString& name,
00213                                 VALUETYPE& type) = 0;
00214 
00215 
00216 
00217 
00218 
00219 
00220 
00221 
00222 
00223 
00224 
00225 
00226 
00227 
00228 
00229 
00230 
00231 
00232   virtual int enumerate_sections (const ACE_Configuration_Section_Key& key,
00233                                   int index, ACE_TString& name) = 0;
00234 
00235 
00236 
00237 
00238 
00239 
00240 
00241 
00242 
00243 
00244 
00245   virtual int set_string_value (const ACE_Configuration_Section_Key& key,
00246                                 const ACE_TCHAR* name,
00247                                 const ACE_TString& value) = 0;
00248 
00249 
00250 
00251 
00252 
00253 
00254 
00255 
00256 
00257 
00258 
00259   virtual int set_integer_value (const ACE_Configuration_Section_Key& key,
00260                                  const ACE_TCHAR* name,
00261                                  u_int value) = 0;
00262 
00263 
00264 
00265 
00266 
00267 
00268 
00269 
00270 
00271 
00272 
00273 
00274   virtual int set_binary_value (const ACE_Configuration_Section_Key& key,
00275                                 const ACE_TCHAR* name,
00276                                 const void* data,
00277                                 size_t length) = 0;
00278 
00279 
00280 
00281 
00282 
00283 
00284 
00285 
00286 
00287 
00288 
00289   virtual int get_string_value (const ACE_Configuration_Section_Key& key,
00290                                 const ACE_TCHAR* name,
00291                                 ACE_TString& value) = 0;
00292 
00293 
00294 
00295 
00296 
00297 
00298 
00299 
00300 
00301 
00302 
00303   virtual int get_integer_value (const ACE_Configuration_Section_Key& key,
00304                                  const ACE_TCHAR* name,
00305                                  u_int& value) = 0;
00306 
00307 
00308 
00309 
00310 
00311 
00312 
00313 
00314 
00315 
00316 
00317 
00318 
00319 
00320 
00321   virtual int get_binary_value (const ACE_Configuration_Section_Key& key,
00322                                 const ACE_TCHAR* name,
00323                                 void*& data,
00324                                 size_t& length) = 0;
00325 
00326 
00327 
00328 
00329 
00330 
00331 
00332 
00333 
00334 
00335 
00336   virtual int find_value(const ACE_Configuration_Section_Key& key,
00337                          const ACE_TCHAR* name,
00338                          VALUETYPE& type) = 0;
00339 
00340 
00341 
00342 
00343 
00344 
00345 
00346 
00347 
00348   virtual int remove_value (const ACE_Configuration_Section_Key& key,
00349                             const ACE_TCHAR* name) = 0;
00350 
00351 
00352 
00353 
00354 
00355 
00356 
00357 
00358 
00359   int expand_path (const ACE_Configuration_Section_Key& key,
00360                    const ACE_TString& path_in,
00361                    ACE_Configuration_Section_Key& key_out,
00362                    int create = 1);
00363 
00364 
00365 
00366 
00367 
00368 
00369 
00370   int export_config (const ACE_TCHAR* filename);
00371 
00372 
00373 
00374 
00375 
00376 
00377 
00378   int import_config (const ACE_TCHAR* filename);
00379 
00380 
00381 
00382 
00383 
00384 
00385   bool operator==(const ACE_Configuration& rhs) const;
00386 
00387 
00388 
00389 
00390 
00391 
00392   bool operator!=(const ACE_Configuration& rhs) const;
00393 
00394 
00395 
00396 
00397   static ACE_TCHAR NULL_String_;
00398 
00399 protected:
00400 
00401   ACE_Configuration (void);
00402 
00403 
00404   ACE_Section_Key_Internal* get_internal_key
00405     (const ACE_Configuration_Section_Key& key);
00406 
00407 
00408 
00409 
00410 
00411 
00412 
00413 
00414   int validate_name (const ACE_TCHAR* name, int allow_path = 0);
00415 
00416 
00417 
00418 
00419 
00420 
00421 
00422   int validate_value_name (const ACE_TCHAR* name);
00423 
00424   
00425   ACE_Configuration (const ACE_Configuration& rhs);
00426   ACE_Configuration& operator= (const ACE_Configuration& rhs);
00427 
00428 
00429   ACE_Configuration_Section_Key root_;
00430 };
00431 
00432 #if defined (ACE_WIN32)
00433 
00434 
00435 
00436 
00437 
00438 
00439 
00440 
00441 class ACE_Export ACE_Section_Key_Win32 : public ACE_Section_Key_Internal
00442 {
00443 public:
00444 
00445   ACE_Section_Key_Win32 (HKEY hKey);
00446 
00447   HKEY hKey_;
00448 
00449 protected:
00450 
00451   virtual ~ACE_Section_Key_Win32 (void);
00452 
00453   
00454   ACE_Section_Key_Win32 (const ACE_Section_Key_Win32& rhs);
00455   ACE_Section_Key_Win32& operator= (const ACE_Section_Key_Win32& rhs);
00456 };
00457 
00458 
00459 
00460 
00461 
00462 
00463 
00464 
00465 
00466 
00467 class ACE_Export ACE_Configuration_Win32Registry : public ACE_Configuration
00468 {
00469 public:
00470 
00471 
00472 
00473 
00474 
00475 
00476   explicit ACE_Configuration_Win32Registry (HKEY hKey);
00477 
00478 
00479   virtual ~ACE_Configuration_Win32Registry (void);
00480 
00481   virtual int open_section (const ACE_Configuration_Section_Key& base,
00482                             const ACE_TCHAR* sub_section,
00483                             int create,
00484                             ACE_Configuration_Section_Key& result);
00485 
00486   virtual int remove_section (const ACE_Configuration_Section_Key& key,
00487                               const ACE_TCHAR* sub_section,
00488                               int recursive);
00489 
00490   virtual int enumerate_values (const ACE_Configuration_Section_Key& key,
00491                                 int index,
00492                                 ACE_TString& name,
00493                                 VALUETYPE& type);
00494 
00495   virtual int enumerate_sections (const ACE_Configuration_Section_Key& key,
00496                                   int index,
00497                                   ACE_TString& name);
00498 
00499   virtual int set_string_value (const ACE_Configuration_Section_Key& key,
00500                                 const ACE_TCHAR* name,
00501                                 const ACE_TString& value);
00502 
00503   virtual int set_integer_value (const ACE_Configuration_Section_Key& key,
00504                                  const ACE_TCHAR* name,
00505                                  u_int value);
00506 
00507   virtual int set_binary_value (const ACE_Configuration_Section_Key& key,
00508                                 const ACE_TCHAR* name,
00509                                 const void* data,
00510                                 size_t length);
00511 
00512   virtual int get_string_value (const ACE_Configuration_Section_Key& key,
00513                                 const ACE_TCHAR* name,
00514                                 ACE_TString& value);
00515 
00516   virtual int get_integer_value (const ACE_Configuration_Section_Key& key,
00517                                  const ACE_TCHAR* name,
00518                                  u_int& value);
00519 
00520   virtual int get_binary_value (const ACE_Configuration_Section_Key& key,
00521                                 const ACE_TCHAR* name,
00522                                 void*& data,
00523                                 size_t& length);
00524 
00525   virtual int find_value(const ACE_Configuration_Section_Key& key,
00526                          const ACE_TCHAR* name,
00527                          VALUETYPE& type);
00528 
00529 
00530   virtual int remove_value (const ACE_Configuration_Section_Key& key,
00531                             const ACE_TCHAR* name);
00532 
00533 
00534 
00535 
00536 
00537 
00538 
00539 
00540 
00541   static HKEY resolve_key (HKEY hKey,
00542                            const ACE_TCHAR* path,
00543                            int create = 1);
00544   virtual bool operator== (const ACE_Configuration_Win32Registry &rhs) const;
00545   virtual bool operator!= (const ACE_Configuration_Win32Registry &rhs) const;
00546 
00547 protected:
00548 
00549 
00550   int load_key (const ACE_Configuration_Section_Key& key, HKEY& hKey);
00551 
00552   
00553   ACE_Configuration_Win32Registry (void);
00554   ACE_Configuration_Win32Registry (const ACE_Configuration_Win32Registry& rhs);
00555   ACE_Configuration_Win32Registry& operator= (const ACE_Configuration_Win32Registry& rhs);
00556 };
00557 #endif 
00558 
00559 
00560 
00561 typedef ACE_Allocator_Adapter <ACE_Malloc <ACE_MMAP_MEMORY_POOL,
00562                                            ACE_SYNCH_MUTEX> >
00563         PERSISTENT_ALLOCATOR;
00564 typedef ACE_Allocator_Adapter <ACE_Malloc <ACE_LOCAL_MEMORY_POOL,
00565                                            ACE_SYNCH_MUTEX> >
00566         HEAP_ALLOCATOR;
00567 
00568 
00569 
00570 
00571 
00572 
00573 
00574 
00575 class ACE_Export ACE_Configuration_ExtId
00576 {
00577 public:
00578 
00579   ACE_Configuration_ExtId (void);
00580 
00581 
00582   explicit ACE_Configuration_ExtId (const ACE_TCHAR* name);
00583 
00584 
00585   ACE_Configuration_ExtId (const ACE_Configuration_ExtId& rhs);
00586 
00587 
00588   ~ACE_Configuration_ExtId (void);
00589 
00590 
00591   ACE_Configuration_ExtId& operator= (const ACE_Configuration_ExtId& rhs);
00592 
00593 
00594   bool operator==  (const ACE_Configuration_ExtId &rhs) const;
00595 
00596 
00597   bool operator!= (const ACE_Configuration_ExtId &rhs) const;
00598 
00599 
00600 
00601   void free (ACE_Allocator *alloc);
00602 
00603 
00604 
00605   u_long hash  (void) const;
00606 
00607   
00608 
00609   const ACE_TCHAR * name_;
00610 
00611   
00612   const ACE_TCHAR *name (void);
00613 };
00614 
00615 typedef ACE_Hash_Map_With_Allocator<ACE_Configuration_ExtId, int>
00616         SUBSECTION_MAP;
00617 typedef ACE_Hash_Map_Manager_Ex<ACE_Configuration_ExtId,
00618                                 int,
00619                                 ACE_Hash<ACE_Configuration_ExtId>,
00620                                 ACE_Equal_To<ACE_Configuration_ExtId>,
00621                                 ACE_Null_Mutex>
00622         SUBSECTION_HASH;
00623 
00624 
00625 typedef SUBSECTION_HASH::ENTRY SUBSECTION_ENTRY;
00626 
00627 
00628 
00629 
00630 
00631 
00632 
00633 
00634 
00635 class ACE_Export ACE_Configuration_Value_IntId
00636 {
00637 public:
00638 
00639   ACE_Configuration_Value_IntId (void);
00640 
00641 
00642   explicit ACE_Configuration_Value_IntId (ACE_TCHAR* string);
00643 
00644 
00645   explicit ACE_Configuration_Value_IntId (u_int integer);
00646 
00647 
00648   ACE_Configuration_Value_IntId (void* data, size_t length);
00649 
00650 
00651   ACE_Configuration_Value_IntId (const ACE_Configuration_Value_IntId& rhs);
00652 
00653 
00654   ~ACE_Configuration_Value_IntId (void);
00655 
00656 
00657   ACE_Configuration_Value_IntId& operator= (
00658     const ACE_Configuration_Value_IntId& rhs);
00659 
00660   void free (ACE_Allocator *alloc);
00661 
00662   
00663 
00664 
00665 
00666 
00667 
00668   ACE_Configuration::VALUETYPE  type_;
00669   union {
00670     void *     ptr_;
00671     u_int      int_;
00672   }                             data_;
00673   size_t                        length_;
00674 };
00675 
00676 typedef ACE_Hash_Map_With_Allocator<ACE_Configuration_ExtId,
00677                                     ACE_Configuration_Value_IntId>
00678         VALUE_MAP;
00679 typedef ACE_Hash_Map_Manager_Ex<ACE_Configuration_ExtId,
00680                                 ACE_Configuration_Value_IntId,
00681                                 ACE_Hash<ACE_Configuration_ExtId>,
00682                                 ACE_Equal_To<ACE_Configuration_ExtId>,
00683                                 ACE_Null_Mutex>
00684         VALUE_HASH;
00685 
00686 
00687 typedef VALUE_HASH::ENTRY VALUE_ENTRY;
00688 
00689 
00690 
00691 
00692 
00693 
00694 
00695 
00696 class ACE_Export ACE_Configuration_Section_IntId
00697 {
00698 public:
00699 
00700   ACE_Configuration_Section_IntId (void);
00701 
00702 
00703   ACE_Configuration_Section_IntId (VALUE_MAP* value_hash_map,
00704                                    SUBSECTION_MAP* section_hash_map);
00705 
00706 
00707   ACE_Configuration_Section_IntId (const ACE_Configuration_Section_IntId& rhs);
00708 
00709 
00710   ~ACE_Configuration_Section_IntId (void);
00711 
00712 
00713   ACE_Configuration_Section_IntId& operator= (
00714     const ACE_Configuration_Section_IntId& rhs);
00715 
00716 
00717   void free (ACE_Allocator *alloc);
00718 
00719   
00720   VALUE_MAP* value_hash_map_;
00721 
00722   SUBSECTION_MAP* section_hash_map_;
00723 };
00724 
00725 typedef ACE_Hash_Map_With_Allocator<ACE_Configuration_ExtId,
00726                                     ACE_Configuration_Section_IntId>
00727         SECTION_MAP;
00728 typedef ACE_Hash_Map_Manager_Ex<ACE_Configuration_ExtId,
00729                                 ACE_Configuration_Section_IntId,
00730                                 ACE_Hash<ACE_Configuration_ExtId>,
00731                                 ACE_Equal_To<ACE_Configuration_ExtId>,
00732                                 ACE_Null_Mutex>
00733         SECTION_HASH;
00734 
00735 
00736 typedef SECTION_HASH::ENTRY SECTION_ENTRY;
00737 
00738 
00739 
00740 
00741 
00742 
00743 
00744 
00745 
00746 class ACE_Export ACE_Configuration_Section_Key_Heap
00747   : public ACE_Section_Key_Internal
00748 {
00749 public:
00750 
00751   ACE_Configuration_Section_Key_Heap (const ACE_TCHAR* path);
00752 
00753 
00754   ACE_TCHAR* path_;
00755 
00756 
00757   VALUE_HASH::ITERATOR* value_iter_;
00758 
00759 
00760   SUBSECTION_HASH::ITERATOR* section_iter_;
00761 protected:
00762 
00763   virtual ~ACE_Configuration_Section_Key_Heap (void);
00764 
00765   
00766   ACE_Configuration_Section_Key_Heap (const ACE_Configuration_Section_Key_Heap& rhs);
00767   ACE_Configuration_Section_Key_Heap& operator= (const ACE_Configuration_Section_Key_Heap& rhs);
00768 };
00769 
00770 
00771 
00772 
00773 
00774 
00775 
00776 
00777 
00778 
00779 
00780 
00781 
00782 
00783 
00784 
00785 
00786 class ACE_Export ACE_Configuration_Heap : public ACE_Configuration
00787 {
00788 public:
00789 
00790 
00791   ACE_Configuration_Heap (void);
00792 
00793 
00794   virtual ~ACE_Configuration_Heap (void);
00795 
00796 
00797   int open (const ACE_TCHAR* file_name,
00798             void* base_address = ACE_DEFAULT_BASE_ADDR,
00799             size_t default_map_size = ACE_DEFAULT_CONFIG_SECTION_SIZE);
00800 
00801 
00802   int open (size_t default_map_size = ACE_DEFAULT_CONFIG_SECTION_SIZE);
00803 
00804   virtual int open_section (const ACE_Configuration_Section_Key& base,
00805                             const ACE_TCHAR* sub_section,
00806                             int create, ACE_Configuration_Section_Key& result);
00807 
00808   virtual int remove_section (const ACE_Configuration_Section_Key& key,
00809                               const ACE_TCHAR* sub_section,
00810                               int recursive);
00811 
00812   virtual int enumerate_values (const ACE_Configuration_Section_Key& key,
00813                                 int index,
00814                                 ACE_TString& name,
00815                                 VALUETYPE& type);
00816 
00817   virtual int enumerate_sections (const ACE_Configuration_Section_Key& key,
00818                                   int index,
00819                                   ACE_TString& name);
00820 
00821   virtual int set_string_value (const ACE_Configuration_Section_Key& key,
00822                                 const ACE_TCHAR* name,
00823                                 const ACE_TString& value);
00824 
00825   virtual int set_integer_value (const ACE_Configuration_Section_Key& key,
00826                                  const ACE_TCHAR* name,
00827                                  u_int value);
00828 
00829   virtual int set_binary_value (const ACE_Configuration_Section_Key& key,
00830                                 const ACE_TCHAR* name,
00831                                 const void* data,
00832                                 size_t length);
00833 
00834   virtual int get_string_value (const ACE_Configuration_Section_Key& key,
00835                                 const ACE_TCHAR* name,
00836                                 ACE_TString& value);
00837 
00838   virtual int get_integer_value (const ACE_Configuration_Section_Key& key,
00839                                  const ACE_TCHAR* name,
00840                                  u_int& value);
00841 
00842   virtual int get_binary_value (const ACE_Configuration_Section_Key& key,
00843                                 const ACE_TCHAR* name,
00844                                 void* &data,
00845                                 size_t &length);
00846 
00847   virtual int find_value(const ACE_Configuration_Section_Key& key,
00848                          const ACE_TCHAR* name,
00849                          VALUETYPE& type);
00850 
00851 
00852   virtual int remove_value (const ACE_Configuration_Section_Key& key,
00853                             const ACE_TCHAR* name);
00854 
00855 private:
00856 
00857   int open_simple_section (const ACE_Configuration_Section_Key &base,
00858                             const ACE_TCHAR *sub_section,
00859                             int create, ACE_Configuration_Section_Key &result);
00860 
00861   int add_section (const ACE_Configuration_Section_Key &base,
00862                    const ACE_TCHAR *sub_section,
00863                    ACE_Configuration_Section_Key &result);
00864 
00865 
00866   int create_index (void);
00867 
00868 
00869 
00870   int create_index_helper (void *buffer);
00871 
00872   int value_open_helper (size_t hash_table_size, void *buffer);
00873 
00874   int section_open_helper (size_t hash_table_size, void *buffer);
00875 
00876   int load_key (const ACE_Configuration_Section_Key& key, ACE_TString& name);
00877 
00878   int new_section (const ACE_TString& section,
00879                    ACE_Configuration_Section_Key& result);
00880 
00881   ACE_Configuration_Heap (const ACE_Configuration_Heap& rhs);
00882   ACE_Configuration_Heap& operator= (const ACE_Configuration_Heap& rhs);
00883 
00884   ACE_Allocator *allocator_;
00885   SECTION_MAP *index_;
00886   size_t default_map_size_;
00887 };
00888 
00889 ACE_END_VERSIONED_NAMESPACE_DECL
00890 
00891 #include  "ace/post.h"
00892 #endif