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