PageRenderTime 51ms CodeModel.GetById 20ms RepoModel.GetById 0ms app.codeStats 0ms

/dep/acelite/ace/Registry.cpp

https://github.com/chucho/FaceCore
C++ | 1125 lines | 1115 code | 7 blank | 3 comment | 5 complexity | 0745c5e445c049bf232847aedea2c082 MD5 | raw file
  1. // $Id: Registry.cpp 91286 2010-08-05 09:04:31Z johnnyw $
  2. #include "ace/Registry.h"
  3. #if defined (ACE_WIN32) && !defined (ACE_LACKS_WIN32_REGISTRY)
  4. # include "ace/os_include/os_netdb.h"
  5. # include "ace/OS_NS_unistd.h"
  6. // Funky macro to deal with strange error passing semantics
  7. // of Win32 Reg*() functions
  8. #define ACE_REGISTRY_CALL_RETURN(X) \
  9. do { \
  10. if (X != ERROR_SUCCESS) \
  11. { \
  12. errno = X; \
  13. return -1; \
  14. } \
  15. else \
  16. return 0; \
  17. } while (0)
  18. ACE_BEGIN_VERSIONED_NAMESPACE_DECL
  19. ACE_TCHAR const ACE_Registry::STRING_SEPARATOR[] = ACE_TEXT ("\\");
  20. bool
  21. ACE_Registry::Name_Component::operator== (const Name_Component &rhs) const
  22. {
  23. return
  24. rhs.id_ == this->id_ &&
  25. rhs.kind_ == this->kind_;
  26. }
  27. bool
  28. ACE_Registry::Name_Component::operator!= (const Name_Component &rhs) const
  29. {
  30. return !this->operator== (rhs);
  31. }
  32. // Simple binding constructor
  33. ACE_Registry::Binding::Binding ()
  34. : name_ (),
  35. type_ (INVALID)
  36. {
  37. }
  38. // Binding constructor
  39. // (Name version)
  40. ACE_Registry::Binding::Binding (const Name &name,
  41. Binding_Type type)
  42. : name_ (ACE_Registry::make_string (name)),
  43. type_ (type)
  44. {
  45. }
  46. // Binding constructor
  47. // (String version)
  48. ACE_Registry::Binding::Binding (const ACE_TString &name,
  49. Binding_Type type)
  50. : name_ (name),
  51. type_ (type)
  52. {
  53. }
  54. bool
  55. ACE_Registry::Binding::operator== (const Binding &rhs) const
  56. {
  57. return
  58. rhs.name_ == this->name_ &&
  59. rhs.type_ == this->type_;
  60. }
  61. bool
  62. ACE_Registry::Binding::operator!= (const Binding &rhs) const
  63. {
  64. return !this->operator== (rhs);
  65. }
  66. // Name accessor
  67. // (Name version)
  68. void
  69. ACE_Registry::Binding::name (Name &name)
  70. {
  71. name = ACE_Registry::make_name (this->name_);
  72. }
  73. // Name accessors
  74. // (String version)
  75. void
  76. ACE_Registry::Binding::name (ACE_TString &name)
  77. {
  78. name = this->name_;
  79. }
  80. // Name accessors
  81. // (String version)
  82. ACE_TString
  83. ACE_Registry::Binding::name (void)
  84. {
  85. return this->name_;
  86. }
  87. // Type accessor
  88. ACE_Registry::Binding_Type
  89. ACE_Registry::Binding::type (void)
  90. {
  91. return this->type_;
  92. }
  93. // Simple object constructor
  94. ACE_Registry::Object::Object (void *data,
  95. u_long size,
  96. u_long type)
  97. : data_ (data),
  98. size_ (size),
  99. type_ (type)
  100. {
  101. }
  102. // Object accessors and set methods
  103. void
  104. ACE_Registry::Object::data (void *data)
  105. {
  106. this->data_ = data;
  107. }
  108. void *
  109. ACE_Registry::Object::data (void) const
  110. {
  111. return this->data_;
  112. }
  113. void
  114. ACE_Registry::Object::size (u_long size)
  115. {
  116. this->size_ = size;
  117. }
  118. u_long
  119. ACE_Registry::Object::size (void) const
  120. {
  121. return this->size_;
  122. }
  123. void
  124. ACE_Registry::Object::type (u_long type)
  125. {
  126. this->type_ = type;
  127. }
  128. u_long
  129. ACE_Registry::Object::type (void) const
  130. {
  131. return this->type_;
  132. }
  133. // Simple context constructor
  134. ACE_Registry::Naming_Context::Naming_Context (void)
  135. : key_ ((HKEY) 0),
  136. parent_key_ ((HKEY) 0),
  137. name_ ()
  138. {
  139. }
  140. // Context constructor
  141. ACE_Registry::Naming_Context::Naming_Context (const HKEY &key)
  142. : key_ (key),
  143. parent_key_ ((HKEY) 0),
  144. name_ ()
  145. {
  146. }
  147. ACE_Registry::Naming_Context::Naming_Context (const Naming_Context &rhs)
  148. : key_ (rhs.key_),
  149. parent_key_ (rhs.parent_key_),
  150. name_ (rhs.name_)
  151. {
  152. // This is incorrect.
  153. // Rather than copying key, we should call ::DuplicateHandle()
  154. // But since this is private (and not used), I don't care much
  155. }
  156. const ACE_Registry::Naming_Context &
  157. ACE_Registry::Naming_Context::operator= (const Naming_Context &rhs)
  158. {
  159. ACE_UNUSED_ARG(rhs);
  160. // Not implemented
  161. return *this;
  162. }
  163. // Destructor
  164. ACE_Registry::Naming_Context::~Naming_Context ()
  165. {
  166. this->close ();
  167. }
  168. // Insert <object> with <name> into <this> context
  169. // (Name version)
  170. int
  171. ACE_Registry::Naming_Context::bind_new (const Name &name,
  172. const Object &object)
  173. {
  174. return this->bind_new (ACE_Registry::make_string (name), object);
  175. }
  176. // Insert <object> with <name> into <this> context
  177. // (String version)
  178. int
  179. ACE_Registry::Naming_Context::bind_new (const ACE_TString &name,
  180. const Object &object)
  181. {
  182. // temporary object
  183. Object temp;
  184. long result = this->resolve (name, temp);
  185. if (result == 0)
  186. // resolve succeeded
  187. result = -1;
  188. else
  189. // resolve failed
  190. result = this->bind (name, object);
  191. return result;
  192. }
  193. // Insert or update <object> with <name> into <this> context
  194. // (Name version)
  195. int
  196. ACE_Registry::Naming_Context::bind (const Name &name,
  197. const Object &object)
  198. {
  199. return this->bind (ACE_Registry::make_string (name), object);
  200. }
  201. // Insert or update <object> with <name> into <this> context
  202. // (String version)
  203. int
  204. ACE_Registry::Naming_Context::bind (const ACE_TString &name,
  205. const Object &object)
  206. {
  207. long result = ACE_TEXT_RegSetValueEx (this->key_,
  208. name.c_str (),
  209. 0,
  210. object.type (),
  211. (const BYTE *) object.data (),
  212. object.size ());
  213. ACE_REGISTRY_CALL_RETURN (result);
  214. }
  215. // Update <object> with <name> in <this> context
  216. // (Name version)
  217. int
  218. ACE_Registry::Naming_Context::rebind (const Name &name,
  219. const Object &new_object)
  220. {
  221. return this->rebind (ACE_Registry::make_string (name), new_object);
  222. }
  223. // Update <object> with <name> in <this> context
  224. // (String version)
  225. int
  226. ACE_Registry::Naming_Context::rebind (const ACE_TString &name,
  227. const Object &new_object)
  228. {
  229. Object old_object;
  230. // find the old one first
  231. long result = this->resolve (name, old_object);
  232. if (result == 0)
  233. // no need to delete first
  234. result = this->bind (name, new_object);
  235. return result;
  236. }
  237. // Find <object> with <name> in <this> context
  238. // (Name version)
  239. int
  240. ACE_Registry::Naming_Context::resolve (const Name &name,
  241. Object &object)
  242. {
  243. return this->resolve (ACE_Registry::make_string (name), object);
  244. }
  245. // Find <object> with <name> in <this> context
  246. // (String version)
  247. int
  248. ACE_Registry::Naming_Context::resolve (const ACE_TString &name,
  249. Object &object)
  250. {
  251. // Get object state
  252. u_long type;
  253. void *data = object.data ();
  254. u_long size = object.size ();
  255. long result = ACE_TEXT_RegQueryValueEx (this->key_,
  256. name.c_str (),
  257. 0,
  258. &type,
  259. (BYTE *)data,
  260. &size);
  261. if (result == ERROR_SUCCESS)
  262. {
  263. // Reset object state
  264. // No need to set object.data()
  265. object.type (type);
  266. object.size (size);
  267. }
  268. ACE_REGISTRY_CALL_RETURN (result);
  269. }
  270. // Remove object with <name> in <this> context
  271. // (Name version)
  272. int
  273. ACE_Registry::Naming_Context::unbind (const Name &name)
  274. {
  275. return this->unbind (ACE_Registry::make_string (name));
  276. }
  277. // Remove object with <name> in <this> context
  278. // (String version)
  279. int
  280. ACE_Registry::Naming_Context::unbind (const ACE_TString &name)
  281. {
  282. long result = ACE_TEXT_RegDeleteValue (this->key_,
  283. name.c_str ());
  284. ACE_REGISTRY_CALL_RETURN (result);
  285. }
  286. // Create new <naming_context> relative to <this> context
  287. // This method may not mean a lot in this implementation
  288. int
  289. ACE_Registry::Naming_Context::new_context (Naming_Context &naming_context)
  290. {
  291. // Make sure that we reset the state and close keys
  292. return naming_context.close ();
  293. }
  294. // Insert <naming_context> with <name> relative to <this> context
  295. // (Name version)
  296. int
  297. ACE_Registry::Naming_Context::bind_new_context (const Name &name,
  298. Naming_Context &naming_context,
  299. u_long persistence,
  300. u_long security_access,
  301. LPSECURITY_ATTRIBUTES security_attributes)
  302. {
  303. return this->bind_new_context (ACE_Registry::make_string (name),
  304. naming_context,
  305. persistence,
  306. security_access,
  307. security_attributes);
  308. }
  309. // Insert <naming_context> with <name> relative to <this> context
  310. // (String version)
  311. int
  312. ACE_Registry::Naming_Context::bind_new_context (const ACE_TString &name,
  313. Naming_Context &naming_context,
  314. u_long persistence,
  315. u_long security_access,
  316. LPSECURITY_ATTRIBUTES security_attributes)
  317. {
  318. u_long reason;
  319. long result = ACE_TEXT_RegCreateKeyEx (this->key_,
  320. name.c_str (),
  321. 0,
  322. 0,
  323. persistence,
  324. security_access,
  325. security_attributes,
  326. &naming_context.key_,
  327. &reason);
  328. if (result == ERROR_SUCCESS)
  329. // If create succeeds
  330. {
  331. if (reason == REG_CREATED_NEW_KEY)
  332. // If new key: success
  333. {
  334. // Set the correct parent
  335. naming_context.parent (this->key_);
  336. // Set the correct name
  337. naming_context.name (name);
  338. }
  339. else
  340. // reason == REG_OPENED_EXISTING_KEY
  341. // Failed to make new key
  342. {
  343. // reset result to failure
  344. result = -1;
  345. // Close the key first
  346. ::RegCloseKey (naming_context.key_);
  347. // Reset key
  348. naming_context.key_ = (HKEY) 0;
  349. }
  350. }
  351. ACE_REGISTRY_CALL_RETURN (result);
  352. }
  353. // Insert or update <naming_context> with <name> relative to <this> context
  354. // (Name version)
  355. int
  356. ACE_Registry::Naming_Context::bind_context (const Name &name,
  357. /* const */ Naming_Context &naming_context,
  358. u_long persistence,
  359. u_long security_access,
  360. LPSECURITY_ATTRIBUTES security_attributes)
  361. {
  362. return this->bind_context (ACE_Registry::make_string (name),
  363. naming_context,
  364. persistence,
  365. security_access,
  366. security_attributes);
  367. }
  368. // Insert or update <naming_context> with <name> relative to <this> context
  369. // (String version)
  370. int
  371. ACE_Registry::Naming_Context::bind_context (const ACE_TString &name,
  372. /* const */ Naming_Context &naming_context,
  373. u_long persistence,
  374. u_long security_access,
  375. LPSECURITY_ATTRIBUTES security_attributes)
  376. {
  377. u_long reason;
  378. long result = ACE_TEXT_RegCreateKeyEx (this->key_,
  379. name.c_str (),
  380. 0,
  381. 0,
  382. persistence,
  383. security_access,
  384. security_attributes,
  385. &naming_context.key_,
  386. &reason);
  387. if (result == ERROR_SUCCESS)
  388. {
  389. // Set the correct parent
  390. naming_context.parent (this->key_);
  391. // Set the correct name
  392. naming_context.name (name);
  393. }
  394. ACE_REGISTRY_CALL_RETURN (result);
  395. }
  396. // Rename <naming_context> to <name>
  397. // (Name version)
  398. int
  399. ACE_Registry::Naming_Context::rebind_context (const Name &name,
  400. /* const */ Naming_Context &new_naming_context)
  401. {
  402. return this->rebind_context (ACE_Registry::make_string (name),
  403. new_naming_context);
  404. }
  405. // Rename <naming_context> to <name>
  406. // (String version)
  407. int
  408. ACE_Registry::Naming_Context::rebind_context (const ACE_TString &name,
  409. /* const */ Naming_Context &new_naming_context)
  410. {
  411. Naming_Context old_naming_context;
  412. // find the old one first
  413. long result = this->resolve_context (name,
  414. old_naming_context);
  415. if (result == 0)
  416. {
  417. // naming_context is found: delete entry
  418. result = this->unbind_context (name);
  419. if (result == 0)
  420. {
  421. // successful deletion; rebind
  422. // beware of race conditions here
  423. // (lets resolve this later)
  424. result = this->bind_new_context (name, new_naming_context);
  425. }
  426. }
  427. return result;
  428. }
  429. // Remove naming_context with <name> from <this> context
  430. // (Name version)
  431. int
  432. ACE_Registry::Naming_Context::unbind_context (const Name &name)
  433. {
  434. return this->unbind_context (ACE_Registry::make_string (name));
  435. }
  436. // Remove naming_context with <name> from <this> context
  437. // (String version)
  438. int
  439. ACE_Registry::Naming_Context::unbind_context (const ACE_TString &name)
  440. {
  441. long result = ACE_TEXT_RegDeleteKey (this->key_,
  442. name.c_str ());
  443. ACE_REGISTRY_CALL_RETURN (result);
  444. }
  445. // Find <naming_context> with <name> in <this> context
  446. // (Name version)
  447. int
  448. ACE_Registry::Naming_Context::resolve_context (const Name &name,
  449. Naming_Context &naming_context,
  450. u_long security_access)
  451. {
  452. return this->resolve_context (ACE_Registry::make_string (name),
  453. naming_context,
  454. security_access);
  455. }
  456. // Find <naming_context> with <name> in <this> context
  457. // (String version)
  458. int
  459. ACE_Registry::Naming_Context::resolve_context (const ACE_TString &name,
  460. Naming_Context &naming_context,
  461. u_long security_access)
  462. {
  463. long result = ACE_TEXT_RegOpenKeyEx (this->key_,
  464. name.c_str (),
  465. 0,
  466. security_access,
  467. &naming_context.key_);
  468. if (result == ERROR_SUCCESS)
  469. {
  470. // set the correct parent
  471. naming_context.parent (this->key_);
  472. // set the correct name
  473. naming_context.name (name);
  474. }
  475. ACE_REGISTRY_CALL_RETURN (result);
  476. }
  477. // Same as unbind_context() with <this> as naming_context
  478. int
  479. ACE_Registry::Naming_Context::destroy (void)
  480. {
  481. // hopefully the parent_key_ is still open
  482. long result = ACE_TEXT_RegDeleteKey (this->parent_key_,
  483. this->name_.c_str ());
  484. ACE_REGISTRY_CALL_RETURN (result);
  485. }
  486. // Sync content of context to disk
  487. int
  488. ACE_Registry::Naming_Context::flush (void)
  489. {
  490. long result = ::RegFlushKey (this->key_);
  491. ACE_REGISTRY_CALL_RETURN (result);
  492. }
  493. // Close the handle of the context
  494. int
  495. ACE_Registry::Naming_Context::close (void)
  496. {
  497. long result = this->key_ ? ::RegCloseKey (this->key_) : ERROR_SUCCESS;
  498. ACE_REGISTRY_CALL_RETURN (result);
  499. }
  500. // Convert a <name> to a <string>
  501. ACE_TString
  502. ACE_Registry::make_string (const Name &const_name)
  503. {
  504. ACE_TString string;
  505. Name &name = const_cast<Name &> (const_name);
  506. // Iterator through the components of name
  507. for (Name::iterator iterator = name.begin ();
  508. iterator != name.end ();
  509. iterator++)
  510. {
  511. if (iterator != name.begin ())
  512. // If this is not the first component, we will add separators
  513. string += STRING_SEPARATOR;
  514. const Name_Component &component = *iterator;
  515. // Add to string
  516. string += component.id_;
  517. }
  518. return string;
  519. }
  520. // Convert a <string> to a <name>
  521. ACE_Registry::Name
  522. ACE_Registry::make_name (const ACE_TString &string)
  523. {
  524. ACE_TString::size_type new_position = 0;
  525. ACE_TString::size_type last_position = 0;
  526. Name name;
  527. // Rememeber: NPOS is -1
  528. while (new_position != ACE_TString::npos)
  529. {
  530. Name_Component component;
  531. // Find the separator
  532. new_position = string.find (STRING_SEPARATOR, new_position);
  533. if (new_position != ACE_TString::npos)
  534. // If we have not gone past the end
  535. {
  536. // Get the substring
  537. component.id_ = string.substr (last_position,
  538. new_position - last_position);
  539. // Skip past the seperator
  540. new_position +=
  541. ACE_OS::strlen (STRING_SEPARATOR);
  542. }
  543. else
  544. {
  545. // Get the last substring
  546. component.id_ = string.substr (last_position);
  547. }
  548. // Update positions
  549. last_position = new_position;
  550. // Insert component into name
  551. name.insert (component);
  552. }
  553. return name;
  554. }
  555. // Set key
  556. void
  557. ACE_Registry::Naming_Context::key (HKEY key)
  558. {
  559. this->key_ = key;
  560. }
  561. // Get key
  562. HKEY
  563. ACE_Registry::Naming_Context::key (void)
  564. {
  565. return this->key_;
  566. }
  567. // Set parent
  568. void
  569. ACE_Registry::Naming_Context::parent (HKEY parent)
  570. {
  571. this->parent_key_ = parent;
  572. }
  573. // Get parent
  574. HKEY
  575. ACE_Registry::Naming_Context::parent (void)
  576. {
  577. return this->parent_key_;
  578. }
  579. // Set name
  580. // (Name version)
  581. void
  582. ACE_Registry::Naming_Context::name (const Name &name)
  583. {
  584. this->name_ = ACE_Registry::make_string (name);
  585. }
  586. // Get name
  587. // (Name version)
  588. void
  589. ACE_Registry::Naming_Context::name (Name &name)
  590. {
  591. name = ACE_Registry::make_name (this->name_);
  592. }
  593. // Set name
  594. // (String version)
  595. void
  596. ACE_Registry::Naming_Context::name (const ACE_TString &name)
  597. {
  598. this->name_ = name;
  599. }
  600. // Get name
  601. // (String version)
  602. ACE_TString
  603. ACE_Registry::Naming_Context::name (void)
  604. {
  605. return this->name_;
  606. }
  607. // Get name
  608. // (String version)
  609. void
  610. ACE_Registry::Naming_Context::name (ACE_TString &name)
  611. {
  612. name = this->name_;
  613. }
  614. // Empty list
  615. static const ACE_Registry::Binding_List ace_binding_empty_list;
  616. // listing function: iterator creator
  617. // This is useful when there are many objects and contexts
  618. // in <this> context and you only want to look at a few entries
  619. // at a time
  620. int
  621. ACE_Registry::Naming_Context::list (u_long how_many,
  622. Binding_List &list,
  623. Binding_Iterator &iter)
  624. {
  625. // Make sure that the list is empty
  626. list = ace_binding_empty_list;
  627. // Correctly initalize the iterator
  628. iter.reset ();
  629. // Make sure that the iterator uses <this> naming context
  630. iter.naming_context (*this);
  631. // Start iterations from the objects
  632. iter.current_enumeration (iter.object_iteration_);
  633. // Get the next <how_many> values
  634. return iter.next_n (how_many, list);
  635. }
  636. // listing function: iterator creator
  637. // This gives back a listing of all entries in <this> context.
  638. int
  639. ACE_Registry::Naming_Context::list (Binding_List &list)
  640. {
  641. // Make sure that the list is empty
  642. list = ace_binding_empty_list;
  643. // Create an iterator
  644. ACE_Registry::Binding_Iterator iterator;
  645. // Make sure that the iterator uses <this> naming context
  646. iterator.naming_context (*this);
  647. // Start iterations from the objects
  648. iterator.current_enumeration (iterator.object_iteration_);
  649. long result = 0;
  650. while (1)
  651. {
  652. ACE_Registry::Binding binding;
  653. result = iterator.next_one (binding);
  654. if (result == 0)
  655. list.insert (binding);
  656. else
  657. break;
  658. }
  659. return 0;
  660. }
  661. // Default constructor
  662. ACE_Registry::Binding_Iterator::Binding_Iterator ()
  663. {
  664. this->object_iteration_.iterator (this);
  665. this->context_iteration_.iterator (this);
  666. this->iteration_complete_.iterator (this);
  667. this->reset ();
  668. }
  669. void
  670. ACE_Registry::Binding_Iterator::reset ()
  671. {
  672. this->current_enumeration_ = &this->iteration_complete_;
  673. this->iteration_complete_.reset ();
  674. this->object_iteration_.reset ();
  675. this->context_iteration_.reset ();
  676. }
  677. void
  678. ACE_Registry::Binding_Iterator::Iteration_State::reset ()
  679. {
  680. this->index_ = 0;
  681. }
  682. void
  683. ACE_Registry::Binding_Iterator::Iteration_State::iterator (Binding_Iterator *iter)
  684. {
  685. this->parent_ = iter;
  686. }
  687. ACE_Registry::Binding_Iterator::Iteration_State::Iteration_State (void)
  688. : index_ (0)
  689. {
  690. }
  691. ACE_Registry::Binding_Iterator::Iteration_State::~Iteration_State (void)
  692. {
  693. }
  694. // Next entry
  695. int
  696. ACE_Registry::Binding_Iterator::next_one (Binding &binding)
  697. {
  698. u_long how_many = 1;
  699. Binding_List list;
  700. // Get next n (where n is one)
  701. long result = this->next_n (how_many, list);
  702. if (result == 0)
  703. // Success
  704. binding = (*list.begin ());
  705. return result;
  706. }
  707. // Next <how_many> entries
  708. int
  709. ACE_Registry::Binding_Iterator::next_n (u_long how_many,
  710. Binding_List &list)
  711. {
  712. // Make sure that the list is empty
  713. list = ace_binding_empty_list;
  714. return this->current_enumeration_->next_n (how_many, list);
  715. }
  716. // Destroy iterator
  717. int
  718. ACE_Registry::Binding_Iterator::destroy (void)
  719. {
  720. this->reset ();
  721. return 0;
  722. }
  723. // Set/Get naming_context
  724. void
  725. ACE_Registry::Binding_Iterator::naming_context (Naming_Context &naming_context)
  726. {
  727. this->naming_context_ = &naming_context;
  728. }
  729. ACE_Registry::Naming_Context &
  730. ACE_Registry::Binding_Iterator::naming_context (void)
  731. {
  732. return *this->naming_context_;
  733. }
  734. // Set/Get current enumeration
  735. void
  736. ACE_Registry::Binding_Iterator::current_enumeration (Iteration_State &current_enumeration)
  737. {
  738. this->current_enumeration_ = &current_enumeration;
  739. }
  740. ACE_Registry::Binding_Iterator::Iteration_State &
  741. ACE_Registry::Binding_Iterator::current_enumeration (void)
  742. {
  743. return *this->current_enumeration_;
  744. }
  745. int
  746. ACE_Registry::Binding_Iterator::Object_Iteration::next_n (u_long how_many,
  747. Binding_List &list)
  748. {
  749. // Make a copy
  750. u_long requested = how_many;
  751. // While there are more entries to be added to the list
  752. while (how_many > 0)
  753. {
  754. ACE_TCHAR string [ACE_Registry::Naming_Context::MAX_OBJECT_NAME_SIZE];
  755. u_long size = sizeof string / sizeof (ACE_TCHAR);
  756. long result = ACE_TEXT_RegEnumValue (this->parent_->naming_context ().key (),
  757. this->index_,
  758. string,
  759. &size,
  760. 0,
  761. 0,
  762. 0,
  763. 0);
  764. switch (result)
  765. {
  766. case ERROR_SUCCESS:
  767. // Object found
  768. {
  769. // Readjust counters
  770. this->index_++;
  771. how_many--;
  772. // Add to list
  773. // Create binding
  774. Binding binding (string, OBJECT);
  775. // Add to binding list
  776. list.insert (binding);
  777. }
  778. // Continue to add to list
  779. break;
  780. case ERROR_NO_MORE_ITEMS:
  781. // Enumeration of objects complete
  782. // Reset index
  783. this->index_ = 0;
  784. // Current enumeration will become CONTEXTS
  785. this->parent_->current_enumeration (this->parent_->context_iteration_);
  786. result = this->parent_->current_enumeration ().next_n (how_many,
  787. list);
  788. // If we were able to add objects
  789. if (requested != how_many)
  790. return 0;
  791. else
  792. return result;
  793. default:
  794. // Strange error
  795. // Reset index
  796. this->index_ = 0;
  797. // Current enumeration will become COMPLETE
  798. this->parent_->current_enumeration (this->parent_->iteration_complete_);
  799. // strange error
  800. return -1;
  801. }
  802. }
  803. // If we reach here, all of <how_many> pairs were added to the list
  804. // Since more entries may be available
  805. // current enumeration will remain OBJECTS
  806. return 0;
  807. }
  808. int
  809. ACE_Registry::Binding_Iterator::Context_Iteration::next_n (u_long how_many,
  810. Binding_List &list)
  811. {
  812. // Make a copy
  813. u_long requested = how_many;
  814. // While there are more entries to be added to the list
  815. while (how_many > 0)
  816. {
  817. ACE_TCHAR string [ACE_Registry::Naming_Context::MAX_CONTEXT_NAME_SIZE];
  818. u_long size = sizeof string / sizeof (ACE_TCHAR);
  819. long result = ACE_TEXT_RegEnumKeyEx (this->parent_->naming_context (). key (),
  820. this->index_,
  821. string,
  822. &size,
  823. 0,
  824. 0,
  825. 0,
  826. 0);
  827. switch (result)
  828. {
  829. case ERROR_SUCCESS:
  830. // Object found
  831. {
  832. // Readjust counters
  833. this->index_++;
  834. how_many--;
  835. // Add to list
  836. // Create binding
  837. Binding binding (string, CONTEXT);
  838. // Add to binding list
  839. list.insert (binding);
  840. }
  841. // Continue to add to list
  842. break;
  843. case ERROR_NO_MORE_ITEMS:
  844. // Enumeration of objects complete
  845. /* FALL THROUGH */
  846. default:
  847. // Strange error
  848. // Reset index
  849. this->index_ = 0;
  850. // Current enumeration will become CONTEXTS
  851. this->parent_->current_enumeration (this->parent_->iteration_complete_);
  852. // If we were able to add contexts
  853. if (requested != how_many)
  854. return 0;
  855. else
  856. return -1;
  857. }
  858. }
  859. // If we reach here, all of <how_many> pairs were added to the list
  860. // Since more entries may be available
  861. // current enumeration will remain CONTEXTS
  862. return 0;
  863. }
  864. int
  865. ACE_Registry::Binding_Iterator::Iteration_Complete::next_n (u_long how_many,
  866. Binding_List &list)
  867. {
  868. ACE_UNUSED_ARG(list);
  869. ACE_UNUSED_ARG(how_many);
  870. // No more values
  871. return -1;
  872. }
  873. // Factory method to connect to predefined registries
  874. // This method works for both remote and local machines
  875. // However, for remote machines CLASSES_ROOT and CURRENT_USER
  876. // types are not allowed
  877. /* static */
  878. int
  879. ACE_Predefined_Naming_Contexts::connect (ACE_Registry::Naming_Context &naming_context,
  880. HKEY predefined,
  881. const ACE_TCHAR *machine_name)
  882. {
  883. #if defined (ACE_HAS_WINCE)
  884. ACE_UNUSED_ARG(naming_context);
  885. ACE_UNUSED_ARG(predefined);
  886. ACE_UNUSED_ARG(machine_name);
  887. return -1;
  888. #else
  889. long result = -1;
  890. if (machine_name != 0 && ACE_OS::strcmp (ACE_TEXT ("localhost"), machine_name) == 0)
  891. machine_name = 0;
  892. if (predefined == HKEY_LOCAL_MACHINE || predefined == HKEY_USERS)
  893. result =
  894. ACE_TEXT_RegConnectRegistry (const_cast<ACE_TCHAR *> (machine_name),
  895. predefined,
  896. &naming_context.key_);
  897. if (predefined == HKEY_CURRENT_USER || predefined == HKEY_CLASSES_ROOT)
  898. {
  899. // Make sure that for these types, the machine is local
  900. if (machine_name == 0 ||
  901. ACE_Predefined_Naming_Contexts::is_local_host (machine_name))
  902. {
  903. naming_context.key_ = predefined;
  904. result = 0;
  905. }
  906. else
  907. result = -1;
  908. }
  909. ACE_REGISTRY_CALL_RETURN (result);
  910. #endif // ACE_HAS_WINCE
  911. }
  912. // Check if <machine_name> is the local host
  913. /* static */
  914. int
  915. ACE_Predefined_Naming_Contexts::is_local_host (const ACE_TCHAR *machine_name)
  916. {
  917. ACE_TCHAR local_host[MAXHOSTNAMELEN];
  918. int result = ACE_OS::hostname (local_host, sizeof local_host / sizeof (ACE_TCHAR));
  919. if (result == 0)
  920. result = !ACE_OS::strcmp (local_host, machine_name);
  921. else
  922. result = 0;
  923. return result;
  924. }
  925. ACE_END_VERSIONED_NAMESPACE_DECL
  926. #endif /* ACE_WIN32 && !ACE_LACKS_WIN32_REGISTRY */