command_failed_event.hpp 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  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 <memory>
  16. #include <bsoncxx/document/view.hpp>
  17. #include <mongocxx/config/prelude.hpp>
  18. namespace mongocxx {
  19. MONGOCXX_INLINE_NAMESPACE_BEGIN
  20. namespace events {
  21. ///
  22. /// An event notification sent when the driver fails to execute a MongoDB command.
  23. ///
  24. /// @see "CommandFailedEvent" in
  25. /// https://github.com/mongodb/specifications/blob/master/source/command-monitoring/command-monitoring.rst
  26. ///
  27. class MONGOCXX_API command_failed_event {
  28. public:
  29. MONGOCXX_PRIVATE explicit command_failed_event(const void* event);
  30. ///
  31. /// Destroys a command_failed_event.
  32. ///
  33. ~command_failed_event();
  34. ///
  35. /// Returns the server’s reply to the failed operation.
  36. ///
  37. /// @return The failure.
  38. ///
  39. bsoncxx::document::view failure() const;
  40. ///
  41. /// Returns the name of the command.
  42. ///
  43. /// @return The command name.
  44. ///
  45. bsoncxx::stdx::string_view command_name() const;
  46. ///
  47. /// Returns the duration of the failed operation.
  48. ///
  49. /// @return The duration in microseconds.
  50. ///
  51. std::int64_t duration() const;
  52. ///
  53. /// Returns the request id.
  54. ///
  55. /// @return The request id.
  56. ///
  57. std::int64_t request_id() const;
  58. ///
  59. /// Returns the operation id.
  60. ///
  61. /// @return The operation id.
  62. ///
  63. std::int64_t operation_id() const;
  64. ///
  65. /// Returns the host name.
  66. ///
  67. /// @return The host name.
  68. ///
  69. bsoncxx::stdx::string_view host() const;
  70. ///
  71. /// Returns the port.
  72. ///
  73. /// @return The port.
  74. ///
  75. std::uint16_t port() const;
  76. private:
  77. const void* _failed_event;
  78. };
  79. } // namespace events
  80. MONGOCXX_INLINE_NAMESPACE_END
  81. } // namespace mongocxx
  82. #include <mongocxx/config/postlude.hpp>