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