server_description.hpp 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. // Copyright 2018-present MongoDB Inc.
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. //
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. #pragma once
  15. #include <bsoncxx/document/view.hpp>
  16. #include <bsoncxx/stdx/string_view.hpp>
  17. #include <mongocxx/config/prelude.hpp>
  18. namespace mongocxx {
  19. MONGOCXX_INLINE_NAMESPACE_BEGIN
  20. namespace events {
  21. ///
  22. /// Class representing what the driver knows about a MongoDB server.
  23. ///
  24. class MONGOCXX_API server_description {
  25. public:
  26. MONGOCXX_PRIVATE explicit server_description(const void* event);
  27. ///
  28. /// Destroys a server_description.
  29. ///
  30. ~server_description();
  31. ///
  32. /// An opaque id, unique to this server for this mongocxx::client or mongocxx::pool.
  33. ///
  34. /// @return The id.
  35. ///
  36. std::uint32_t id() const;
  37. ///
  38. /// The duration of the last isMaster call, indicating network latency.
  39. ///
  40. /// @return The duration in microseconds.
  41. ///
  42. std::int64_t round_trip_time() const;
  43. ///
  44. /// The server type: "Unknown", "Standalone", "Mongos", "PossiblePrimary", "RSPrimary",
  45. /// "RSSecondary", "RSArbiter", "RSOther", or "RSGhost".
  46. ///
  47. /// @return The type as a short-lived string view.
  48. ///
  49. bsoncxx::stdx::string_view type() const;
  50. ///
  51. /// The server's last response to the "isMaster" command, or an empty document if the driver
  52. /// has not yet reached the server or there was an error.
  53. ///
  54. /// @return The response as a short-lived document view.
  55. ///
  56. bsoncxx::document::view is_master() const;
  57. ///
  58. /// Returns the server host name.
  59. ///
  60. /// @return The host name.
  61. ///
  62. bsoncxx::stdx::string_view host() const;
  63. ///
  64. /// Returns the server port.
  65. ///
  66. /// @return The port.
  67. ///
  68. std::uint16_t port() const;
  69. private:
  70. const void* _sd;
  71. };
  72. } // namespace events
  73. MONGOCXX_INLINE_NAMESPACE_END
  74. } // namespace mongocxx
  75. #include <mongocxx/config/postlude.hpp>