00001
00002
00003 #include "ace/Registry.h"
00004
00005 ACE_RCSID (ace,
00006 Registry,
00007 "$Id: Registry.cpp 88568 2010-01-15 10:23:25Z olli $")
00008
00009 #if defined (ACE_WIN32) && !defined (ACE_LACKS_WIN32_REGISTRY)
00010
00011 # include "ace/os_include/os_netdb.h"
00012 # include "ace/OS_NS_unistd.h"
00013
00014
00015
00016 #define ACE_REGISTRY_CALL_RETURN(X) \
00017 do { \
00018 if (X != ERROR_SUCCESS) \
00019 { \
00020 errno = X; \
00021 return -1; \
00022 } \
00023 else \
00024 return 0; \
00025 } while (0)
00026
00027
00028 ACE_BEGIN_VERSIONED_NAMESPACE_DECL
00029
00030 ACE_TCHAR const ACE_Registry::STRING_SEPARATOR[] = ACE_TEXT ("\\");
00031
00032 bool
00033 ACE_Registry::Name_Component::operator== (const Name_Component &rhs) const
00034 {
00035 return
00036 rhs.id_ == this->id_ &&
00037 rhs.kind_ == this->kind_;
00038 }
00039
00040 bool
00041 ACE_Registry::Name_Component::operator!= (const Name_Component &rhs) const
00042 {
00043 return !this->operator== (rhs);
00044 }
00045
00046
00047 ACE_Registry::Binding::Binding ()
00048 : name_ (),
00049 type_ (INVALID)
00050 {
00051 }
00052
00053
00054
00055
00056 ACE_Registry::Binding::Binding (const Name &name,
00057 Binding_Type type)
00058 : name_ (ACE_Registry::make_string (name)),
00059 type_ (type)
00060 {
00061 }
00062
00063
00064
00065
00066 ACE_Registry::Binding::Binding (const ACE_TString &name,
00067 Binding_Type type)
00068 : name_ (name),
00069 type_ (type)
00070 {
00071 }
00072
00073
00074 bool
00075 ACE_Registry::Binding::operator== (const Binding &rhs) const
00076 {
00077 return
00078 rhs.name_ == this->name_ &&
00079 rhs.type_ == this->type_;
00080 }
00081
00082 bool
00083 ACE_Registry::Binding::operator!= (const Binding &rhs) const
00084 {
00085 return !this->operator== (rhs);
00086 }
00087
00088
00089
00090 void
00091 ACE_Registry::Binding::name (Name &name)
00092 {
00093 name = ACE_Registry::make_name (this->name_);
00094 }
00095
00096
00097
00098
00099 void
00100 ACE_Registry::Binding::name (ACE_TString &name)
00101 {
00102 name = this->name_;
00103 }
00104
00105
00106
00107
00108 ACE_TString
00109 ACE_Registry::Binding::name (void)
00110 {
00111 return this->name_;
00112 }
00113
00114
00115
00116 ACE_Registry::Binding_Type
00117 ACE_Registry::Binding::type (void)
00118 {
00119 return this->type_;
00120 }
00121
00122
00123
00124 ACE_Registry::Object::Object (void *data,
00125 u_long size,
00126 u_long type)
00127 : data_ (data),
00128 size_ (size),
00129 type_ (type)
00130 {
00131 }
00132
00133
00134 void
00135 ACE_Registry::Object::data (void *data)
00136 {
00137 this->data_ = data;
00138 }
00139
00140
00141 void *
00142 ACE_Registry::Object::data (void) const
00143 {
00144 return this->data_;
00145 }
00146
00147
00148 void
00149 ACE_Registry::Object::size (u_long size)
00150 {
00151 this->size_ = size;
00152 }
00153
00154
00155 u_long
00156 ACE_Registry::Object::size (void) const
00157 {
00158 return this->size_;
00159 }
00160
00161
00162 void
00163 ACE_Registry::Object::type (u_long type)
00164 {
00165 this->type_ = type;
00166 }
00167
00168
00169 u_long
00170 ACE_Registry::Object::type (void) const
00171 {
00172 return this->type_;
00173 }
00174
00175
00176
00177 ACE_Registry::Naming_Context::Naming_Context (void)
00178 : key_ ((HKEY) 0),
00179 parent_key_ ((HKEY) 0),
00180 name_ ()
00181 {
00182 }
00183
00184
00185
00186 ACE_Registry::Naming_Context::Naming_Context (const HKEY &key)
00187 : key_ (key),
00188 parent_key_ ((HKEY) 0),
00189 name_ ()
00190 {
00191 }
00192
00193
00194 ACE_Registry::Naming_Context::Naming_Context (const Naming_Context &rhs)
00195 : key_ (rhs.key_),
00196 parent_key_ (rhs.parent_key_),
00197 name_ (rhs.name_)
00198 {
00199
00200
00201
00202 }
00203
00204
00205 const ACE_Registry::Naming_Context &
00206 ACE_Registry::Naming_Context::operator= (const Naming_Context &rhs)
00207 {
00208 ACE_UNUSED_ARG(rhs);
00209
00210
00211 return *this;
00212 }
00213
00214
00215
00216 ACE_Registry::Naming_Context::~Naming_Context ()
00217 {
00218 this->close ();
00219 }
00220
00221
00222
00223
00224 int
00225 ACE_Registry::Naming_Context::bind_new (const Name &name,
00226 const Object &object)
00227 {
00228 return this->bind_new (ACE_Registry::make_string (name), object);
00229 }
00230
00231
00232
00233
00234 int
00235 ACE_Registry::Naming_Context::bind_new (const ACE_TString &name,
00236 const Object &object)
00237 {
00238
00239 Object temp;
00240 long result = this->resolve (name, temp);
00241 if (result == 0)
00242
00243 result = -1;
00244 else
00245
00246 result = this->bind (name, object);
00247 return result;
00248 }
00249
00250
00251
00252
00253 int
00254 ACE_Registry::Naming_Context::bind (const Name &name,
00255 const Object &object)
00256 {
00257 return this->bind (ACE_Registry::make_string (name), object);
00258 }
00259
00260
00261
00262
00263 int
00264 ACE_Registry::Naming_Context::bind (const ACE_TString &name,
00265 const Object &object)
00266 {
00267 long result = ACE_TEXT_RegSetValueEx (this->key_,
00268 name.c_str (),
00269 0,
00270 object.type (),
00271 (const BYTE *) object.data (),
00272 object.size ());
00273 ACE_REGISTRY_CALL_RETURN (result);
00274 }
00275
00276
00277
00278
00279 int
00280 ACE_Registry::Naming_Context::rebind (const Name &name,
00281 const Object &new_object)
00282 {
00283 return this->rebind (ACE_Registry::make_string (name), new_object);
00284 }
00285
00286
00287
00288
00289 int
00290 ACE_Registry::Naming_Context::rebind (const ACE_TString &name,
00291 const Object &new_object)
00292 {
00293 Object old_object;
00294
00295 long result = this->resolve (name, old_object);
00296 if (result == 0)
00297
00298 result = this->bind (name, new_object);
00299 return result;
00300 }
00301
00302
00303
00304
00305 int
00306 ACE_Registry::Naming_Context::resolve (const Name &name,
00307 Object &object)
00308 {
00309 return this->resolve (ACE_Registry::make_string (name), object);
00310 }
00311
00312
00313
00314
00315 int
00316 ACE_Registry::Naming_Context::resolve (const ACE_TString &name,
00317 Object &object)
00318 {
00319
00320 u_long type;
00321 void *data = object.data ();
00322 u_long size = object.size ();
00323
00324 long result = ACE_TEXT_RegQueryValueEx (this->key_,
00325 name.c_str (),
00326 0,
00327 &type,
00328 (BYTE *)data,
00329 &size);
00330 if (result == ERROR_SUCCESS)
00331 {
00332
00333
00334 object.type (type);
00335 object.size (size);
00336 }
00337
00338 ACE_REGISTRY_CALL_RETURN (result);
00339 }
00340
00341
00342
00343
00344 int
00345 ACE_Registry::Naming_Context::unbind (const Name &name)
00346 {
00347 return this->unbind (ACE_Registry::make_string (name));
00348 }
00349
00350
00351
00352
00353 int
00354 ACE_Registry::Naming_Context::unbind (const ACE_TString &name)
00355 {
00356 long result = ACE_TEXT_RegDeleteValue (this->key_,
00357 name.c_str ());
00358
00359 ACE_REGISTRY_CALL_RETURN (result);
00360 }
00361
00362
00363
00364
00365 int
00366 ACE_Registry::Naming_Context::new_context (Naming_Context &naming_context)
00367 {
00368
00369 return naming_context.close ();
00370 }
00371
00372
00373
00374
00375 int
00376 ACE_Registry::Naming_Context::bind_new_context (const Name &name,
00377 Naming_Context &naming_context,
00378 u_long persistence,
00379 u_long security_access,
00380 LPSECURITY_ATTRIBUTES security_attributes)
00381 {
00382 return this->bind_new_context (ACE_Registry::make_string (name),
00383 naming_context,
00384 persistence,
00385 security_access,
00386 security_attributes);
00387 }
00388
00389
00390
00391
00392 int
00393 ACE_Registry::Naming_Context::bind_new_context (const ACE_TString &name,
00394 Naming_Context &naming_context,
00395 u_long persistence,
00396 u_long security_access,
00397 LPSECURITY_ATTRIBUTES security_attributes)
00398 {
00399 u_long reason;
00400
00401 long result = ACE_TEXT_RegCreateKeyEx (this->key_,
00402 name.c_str (),
00403 0,
00404 0,
00405 persistence,
00406 security_access,
00407 security_attributes,
00408 &naming_context.key_,
00409 &reason);
00410 if (result == ERROR_SUCCESS)
00411
00412 {
00413 if (reason == REG_CREATED_NEW_KEY)
00414
00415 {
00416
00417 naming_context.parent (this->key_);
00418
00419 naming_context.name (name);
00420 }
00421 else
00422
00423
00424 {
00425
00426 result = -1;
00427
00428 ::RegCloseKey (naming_context.key_);
00429
00430 naming_context.key_ = (HKEY) 0;
00431 }
00432 }
00433
00434 ACE_REGISTRY_CALL_RETURN (result);
00435 }
00436
00437
00438
00439
00440 int
00441 ACE_Registry::Naming_Context::bind_context (const Name &name,
00442 Naming_Context &naming_context,
00443 u_long persistence,
00444 u_long security_access,
00445 LPSECURITY_ATTRIBUTES security_attributes)
00446 {
00447 return this->bind_context (ACE_Registry::make_string (name),
00448 naming_context,
00449 persistence,
00450 security_access,
00451 security_attributes);
00452 }
00453
00454
00455
00456
00457 int
00458 ACE_Registry::Naming_Context::bind_context (const ACE_TString &name,
00459 Naming_Context &naming_context,
00460 u_long persistence,
00461 u_long security_access,
00462 LPSECURITY_ATTRIBUTES security_attributes)
00463 {
00464 u_long reason;
00465
00466 long result = ACE_TEXT_RegCreateKeyEx (this->key_,
00467 name.c_str (),
00468 0,
00469 0,
00470 persistence,
00471 security_access,
00472 security_attributes,
00473 &naming_context.key_,
00474 &reason);
00475 if (result == ERROR_SUCCESS)
00476 {
00477
00478 naming_context.parent (this->key_);
00479
00480 naming_context.name (name);
00481 }
00482
00483 ACE_REGISTRY_CALL_RETURN (result);
00484 }
00485
00486
00487
00488
00489 int
00490 ACE_Registry::Naming_Context::rebind_context (const Name &name,
00491 Naming_Context &new_naming_context)
00492 {
00493 return this->rebind_context (ACE_Registry::make_string (name),
00494 new_naming_context);
00495 }
00496
00497
00498
00499
00500 int
00501 ACE_Registry::Naming_Context::rebind_context (const ACE_TString &name,
00502 Naming_Context &new_naming_context)
00503 {
00504 Naming_Context old_naming_context;
00505
00506 long result = this->resolve_context (name,
00507 old_naming_context);
00508 if (result == 0)
00509 {
00510
00511 result = this->unbind_context (name);
00512 if (result == 0)
00513 {
00514
00515
00516
00517 result = this->bind_new_context (name, new_naming_context);
00518 }
00519 }
00520 return result;
00521 }
00522
00523
00524
00525
00526 int
00527 ACE_Registry::Naming_Context::unbind_context (const Name &name)
00528 {
00529 return this->unbind_context (ACE_Registry::make_string (name));
00530 }
00531
00532
00533
00534
00535 int
00536 ACE_Registry::Naming_Context::unbind_context (const ACE_TString &name)
00537 {
00538 long result = ACE_TEXT_RegDeleteKey (this->key_,
00539 name.c_str ());
00540
00541 ACE_REGISTRY_CALL_RETURN (result);
00542 }
00543
00544
00545
00546
00547 int
00548 ACE_Registry::Naming_Context::resolve_context (const Name &name,
00549 Naming_Context &naming_context,
00550 u_long security_access)
00551 {
00552 return this->resolve_context (ACE_Registry::make_string (name),
00553 naming_context,
00554 security_access);
00555 }
00556
00557
00558
00559
00560 int
00561 ACE_Registry::Naming_Context::resolve_context (const ACE_TString &name,
00562 Naming_Context &naming_context,
00563 u_long security_access)
00564 {
00565 long result = ACE_TEXT_RegOpenKeyEx (this->key_,
00566 name.c_str (),
00567 0,
00568 security_access,
00569 &naming_context.key_);
00570 if (result == ERROR_SUCCESS)
00571 {
00572
00573 naming_context.parent (this->key_);
00574
00575 naming_context.name (name);
00576 }
00577
00578 ACE_REGISTRY_CALL_RETURN (result);
00579 }
00580
00581
00582
00583 int
00584 ACE_Registry::Naming_Context::destroy (void)
00585 {
00586
00587 long result = ACE_TEXT_RegDeleteKey (this->parent_key_,
00588 this->name_.c_str ());
00589
00590 ACE_REGISTRY_CALL_RETURN (result);
00591 }
00592
00593
00594
00595 int
00596 ACE_Registry::Naming_Context::flush (void)
00597 {
00598 long result = ::RegFlushKey (this->key_);
00599 ACE_REGISTRY_CALL_RETURN (result);
00600 }
00601
00602
00603
00604 int
00605 ACE_Registry::Naming_Context::close (void)
00606 {
00607 long result = this->key_ ? ::RegCloseKey (this->key_) : ERROR_SUCCESS;
00608 ACE_REGISTRY_CALL_RETURN (result);
00609 }
00610
00611
00612
00613 ACE_TString
00614 ACE_Registry::make_string (const Name &const_name)
00615 {
00616 ACE_TString string;
00617 Name &name = const_cast<Name &> (const_name);
00618
00619
00620 for (Name::iterator iterator = name.begin ();
00621 iterator != name.end ();
00622 iterator++)
00623 {
00624 if (iterator != name.begin ())
00625
00626 string += STRING_SEPARATOR;
00627 const Name_Component &component = *iterator;
00628
00629 string += component.id_;
00630 }
00631
00632 return string;
00633 }
00634
00635
00636
00637 ACE_Registry::Name
00638 ACE_Registry::make_name (const ACE_TString &string)
00639 {
00640 ACE_TString::size_type new_position = 0;
00641 ACE_TString::size_type last_position = 0;
00642 Name name;
00643
00644
00645 while (new_position != ACE_TString::npos)
00646 {
00647 Name_Component component;
00648
00649 new_position = string.find (STRING_SEPARATOR, new_position);
00650 if (new_position != ACE_TString::npos)
00651
00652 {
00653
00654 component.id_ = string.substr (last_position,
00655 new_position - last_position);
00656
00657 new_position +=
00658 ACE_OS::strlen (STRING_SEPARATOR);
00659 }
00660 else
00661 {
00662
00663 component.id_ = string.substr (last_position);
00664 }
00665
00666 last_position = new_position;
00667
00668 name.insert (component);
00669 }
00670
00671 return name;
00672 }
00673
00674
00675
00676 void
00677 ACE_Registry::Naming_Context::key (HKEY key)
00678 {
00679 this->key_ = key;
00680 }
00681
00682
00683
00684 HKEY
00685 ACE_Registry::Naming_Context::key (void)
00686 {
00687 return this->key_;
00688 }
00689
00690
00691
00692 void
00693 ACE_Registry::Naming_Context::parent (HKEY parent)
00694 {
00695 this->parent_key_ = parent;
00696 }
00697
00698
00699
00700 HKEY
00701 ACE_Registry::Naming_Context::parent (void)
00702 {
00703 return this->parent_key_;
00704 }
00705
00706
00707
00708
00709 void
00710 ACE_Registry::Naming_Context::name (const Name &name)
00711 {
00712 this->name_ = ACE_Registry::make_string (name);
00713 }
00714
00715
00716
00717
00718 void
00719 ACE_Registry::Naming_Context::name (Name &name)
00720 {
00721 name = ACE_Registry::make_name (this->name_);
00722 }
00723
00724
00725
00726
00727 void
00728 ACE_Registry::Naming_Context::name (const ACE_TString &name)
00729 {
00730 this->name_ = name;
00731 }
00732
00733
00734
00735
00736 ACE_TString
00737 ACE_Registry::Naming_Context::name (void)
00738 {
00739 return this->name_;
00740 }
00741
00742
00743
00744
00745 void
00746 ACE_Registry::Naming_Context::name (ACE_TString &name)
00747 {
00748 name = this->name_;
00749 }
00750
00751
00752 static const ACE_Registry::Binding_List ace_binding_empty_list;
00753
00754
00755
00756
00757
00758 int
00759 ACE_Registry::Naming_Context::list (u_long how_many,
00760 Binding_List &list,
00761 Binding_Iterator &iter)
00762 {
00763
00764 list = ace_binding_empty_list;
00765
00766
00767 iter.reset ();
00768
00769
00770 iter.naming_context (*this);
00771
00772
00773 iter.current_enumeration (iter.object_iteration_);
00774
00775
00776 return iter.next_n (how_many, list);
00777 }
00778
00779
00780
00781
00782 int
00783 ACE_Registry::Naming_Context::list (Binding_List &list)
00784 {
00785
00786 list = ace_binding_empty_list;
00787
00788
00789 ACE_Registry::Binding_Iterator iterator;
00790
00791
00792 iterator.naming_context (*this);
00793
00794
00795 iterator.current_enumeration (iterator.object_iteration_);
00796
00797 long result = 0;
00798 while (1)
00799 {
00800 ACE_Registry::Binding binding;
00801 result = iterator.next_one (binding);
00802 if (result == 0)
00803 list.insert (binding);
00804 else
00805 break;
00806 }
00807 return 0;
00808 }
00809
00810
00811
00812 ACE_Registry::Binding_Iterator::Binding_Iterator ()
00813 {
00814 this->object_iteration_.iterator (this);
00815 this->context_iteration_.iterator (this);
00816 this->iteration_complete_.iterator (this);
00817 this->reset ();
00818 }
00819
00820
00821 void
00822 ACE_Registry::Binding_Iterator::reset ()
00823 {
00824 this->current_enumeration_ = &this->iteration_complete_;
00825 this->iteration_complete_.reset ();
00826 this->object_iteration_.reset ();
00827 this->context_iteration_.reset ();
00828 }
00829
00830
00831 void
00832 ACE_Registry::Binding_Iterator::Iteration_State::reset ()
00833 {
00834 this->index_ = 0;
00835 }
00836
00837
00838 void
00839 ACE_Registry::Binding_Iterator::Iteration_State::iterator (Binding_Iterator *iter)
00840 {
00841 this->parent_ = iter;
00842 }
00843
00844
00845 ACE_Registry::Binding_Iterator::Iteration_State::Iteration_State (void)
00846 : index_ (0)
00847 {
00848 }
00849
00850 ACE_Registry::Binding_Iterator::Iteration_State::~Iteration_State (void)
00851 {
00852 }
00853
00854
00855 int
00856 ACE_Registry::Binding_Iterator::next_one (Binding &binding)
00857 {
00858 u_long how_many = 1;
00859 Binding_List list;
00860
00861
00862 long result = this->next_n (how_many, list);
00863
00864 if (result == 0)
00865
00866 binding = (*list.begin ());
00867
00868 return result;
00869 }
00870
00871
00872
00873 int
00874 ACE_Registry::Binding_Iterator::next_n (u_long how_many,
00875 Binding_List &list)
00876 {
00877
00878 list = ace_binding_empty_list;
00879
00880 return this->current_enumeration_->next_n (how_many, list);
00881 }
00882
00883
00884
00885 int
00886 ACE_Registry::Binding_Iterator::destroy (void)
00887 {
00888 this->reset ();
00889 return 0;
00890 }
00891
00892
00893
00894 void
00895 ACE_Registry::Binding_Iterator::naming_context (Naming_Context &naming_context)
00896 {
00897 this->naming_context_ = &naming_context;
00898 }
00899
00900
00901 ACE_Registry::Naming_Context &
00902 ACE_Registry::Binding_Iterator::naming_context (void)
00903 {
00904 return *this->naming_context_;
00905 }
00906
00907
00908
00909 void
00910 ACE_Registry::Binding_Iterator::current_enumeration (Iteration_State ¤t_enumeration)
00911 {
00912 this->current_enumeration_ = ¤t_enumeration;
00913 }
00914
00915
00916 ACE_Registry::Binding_Iterator::Iteration_State &
00917 ACE_Registry::Binding_Iterator::current_enumeration (void)
00918 {
00919 return *this->current_enumeration_;
00920 }
00921
00922
00923 int
00924 ACE_Registry::Binding_Iterator::Object_Iteration::next_n (u_long how_many,
00925 Binding_List &list)
00926 {
00927
00928 u_long requested = how_many;
00929
00930
00931 while (how_many > 0)
00932 {
00933 ACE_TCHAR string [ACE_Registry::Naming_Context::MAX_OBJECT_NAME_SIZE];
00934 u_long size = sizeof string / sizeof (ACE_TCHAR);
00935 long result = ACE_TEXT_RegEnumValue (this->parent_->naming_context ().key (),
00936 this->index_,
00937 string,
00938 &size,
00939 0,
00940 0,
00941 0,
00942 0);
00943 switch (result)
00944 {
00945 case ERROR_SUCCESS:
00946
00947 {
00948
00949 this->index_++;
00950 how_many--;
00951
00952
00953
00954 Binding binding (string, OBJECT);
00955
00956 list.insert (binding);
00957 }
00958
00959 break;
00960
00961 case ERROR_NO_MORE_ITEMS:
00962
00963
00964 this->index_ = 0;
00965
00966
00967 this->parent_->current_enumeration (this->parent_->context_iteration_);
00968 result = this->parent_->current_enumeration ().next_n (how_many,
00969 list);
00970
00971 if (requested != how_many)
00972 return 0;
00973 else
00974 return result;
00975
00976 default:
00977
00978
00979 this->index_ = 0;
00980
00981 this->parent_->current_enumeration (this->parent_->iteration_complete_);
00982
00983 return -1;
00984 }
00985 }
00986
00987
00988
00989 return 0;
00990 }
00991
00992
00993 int
00994 ACE_Registry::Binding_Iterator::Context_Iteration::next_n (u_long how_many,
00995 Binding_List &list)
00996 {
00997
00998 u_long requested = how_many;
00999
01000
01001 while (how_many > 0)
01002 {
01003 ACE_TCHAR string [ACE_Registry::Naming_Context::MAX_CONTEXT_NAME_SIZE];
01004 u_long size = sizeof string / sizeof (ACE_TCHAR);
01005 long result = ACE_TEXT_RegEnumKeyEx (this->parent_->naming_context (). key (),
01006 this->index_,
01007 string,
01008 &size,
01009 0,
01010 0,
01011 0,
01012 0);
01013 switch (result)
01014 {
01015 case ERROR_SUCCESS:
01016
01017 {
01018
01019 this->index_++;
01020 how_many--;
01021
01022
01023
01024 Binding binding (string, CONTEXT);
01025
01026 list.insert (binding);
01027 }
01028
01029 break;
01030
01031 case ERROR_NO_MORE_ITEMS:
01032
01033
01034
01035
01036 default:
01037
01038
01039
01040 this->index_ = 0;
01041
01042 this->parent_->current_enumeration (this->parent_->iteration_complete_);
01043
01044
01045 if (requested != how_many)
01046 return 0;
01047 else
01048 return -1;
01049 }
01050 }
01051
01052
01053
01054 return 0;
01055 }
01056
01057
01058 int
01059 ACE_Registry::Binding_Iterator::Iteration_Complete::next_n (u_long how_many,
01060 Binding_List &list)
01061 {
01062 ACE_UNUSED_ARG(list);
01063 ACE_UNUSED_ARG(how_many);
01064
01065
01066 return -1;
01067 }
01068
01069
01070
01071
01072
01073
01074
01075 int
01076 ACE_Predefined_Naming_Contexts::connect (ACE_Registry::Naming_Context &naming_context,
01077 HKEY predefined,
01078 const ACE_TCHAR *machine_name)
01079 {
01080 #if defined (ACE_HAS_WINCE)
01081 ACE_UNUSED_ARG(naming_context);
01082 ACE_UNUSED_ARG(predefined);
01083 ACE_UNUSED_ARG(machine_name);
01084 return -1;
01085 #else
01086 long result = -1;
01087
01088 if (machine_name != 0 && ACE_OS::strcmp (ACE_TEXT ("localhost"), machine_name) == 0)
01089 machine_name = 0;
01090
01091 if (predefined == HKEY_LOCAL_MACHINE || predefined == HKEY_USERS)
01092 result =
01093 ACE_TEXT_RegConnectRegistry (const_cast<ACE_TCHAR *> (machine_name),
01094 predefined,
01095 &naming_context.key_);
01096 if (predefined == HKEY_CURRENT_USER || predefined == HKEY_CLASSES_ROOT)
01097 {
01098
01099 if (machine_name == 0 ||
01100 ACE_Predefined_Naming_Contexts::is_local_host (machine_name))
01101 {
01102 naming_context.key_ = predefined;
01103 result = 0;
01104 }
01105 else
01106 result = -1;
01107 }
01108
01109 ACE_REGISTRY_CALL_RETURN (result);
01110 #endif // ACE_HAS_WINCE
01111 }
01112
01113
01114
01115 int
01116 ACE_Predefined_Naming_Contexts::is_local_host (const ACE_TCHAR *machine_name)
01117 {
01118 ACE_TCHAR local_host[MAXHOSTNAMELEN];
01119 int result = ACE_OS::hostname (local_host, sizeof local_host / sizeof (ACE_TCHAR));
01120 if (result == 0)
01121 result = !ACE_OS::strcmp (local_host, machine_name);
01122 else
01123 result = 0;
01124 return result;
01125 }
01126
01127 ACE_END_VERSIONED_NAMESPACE_DECL
01128
01129 #endif