apm.hpp 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327
  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 <functional>
  16. #include <mongocxx/events/command_failed_event.hpp>
  17. #include <mongocxx/events/command_started_event.hpp>
  18. #include <mongocxx/events/command_succeeded_event.hpp>
  19. #include <mongocxx/events/heartbeat_failed_event.hpp>
  20. #include <mongocxx/events/heartbeat_started_event.hpp>
  21. #include <mongocxx/events/heartbeat_succeeded_event.hpp>
  22. #include <mongocxx/events/server_changed_event.hpp>
  23. #include <mongocxx/events/server_closed_event.hpp>
  24. #include <mongocxx/events/server_opening_event.hpp>
  25. #include <mongocxx/events/topology_changed_event.hpp>
  26. #include <mongocxx/events/topology_closed_event.hpp>
  27. #include <mongocxx/events/topology_opening_event.hpp>
  28. #include <mongocxx/config/prelude.hpp>
  29. namespace mongocxx {
  30. MONGOCXX_INLINE_NAMESPACE_BEGIN
  31. namespace options {
  32. class MONGOCXX_API apm {
  33. public:
  34. ///
  35. /// Set the command started monitoring callback. The callback takes a reference to a
  36. /// command_started_event which will only contain valid data for the duration of the callback.
  37. ///
  38. /// @param command_started
  39. /// The command started monitoring callback.
  40. ///
  41. /// @return
  42. /// A reference to the object on which this member function is being called. This facilitates
  43. /// method chaining.
  44. ///
  45. apm& on_command_started(
  46. std::function<void(const mongocxx::events::command_started_event&)> command_started);
  47. ///
  48. /// Retrieves the command started monitoring callback.
  49. ///
  50. /// @return The command started monitoring callback.
  51. ///
  52. const std::function<void(const mongocxx::events::command_started_event&)>& command_started()
  53. const;
  54. ///
  55. /// Set the command failed monitoring callback. The callback takes a reference to a
  56. /// command_failed_event which will only contain valid data for the duration of the callback.
  57. ///
  58. /// @param command_failed
  59. /// The command failed monitoring callback.
  60. ///
  61. /// @return
  62. /// A reference to the object on which this member function is being called. This facilitates
  63. /// method chaining.
  64. ///
  65. apm& on_command_failed(
  66. std::function<void(const mongocxx::events::command_failed_event&)> command_failed);
  67. ///
  68. /// Retrieves the command failed monitoring callback.
  69. ///
  70. /// @return The command failed monitoring callback.
  71. ///
  72. const std::function<void(const mongocxx::events::command_failed_event&)>& command_failed()
  73. const;
  74. ///
  75. /// Set the command succeeded monitoring callback. The callback takes a reference to a
  76. /// command_succeeded_event which will only contain valid data for the duration of the callback.
  77. ///
  78. /// @param command_succeeded
  79. /// The command succeeded monitoring callback.
  80. ///
  81. /// @return
  82. /// A reference to the object on which this member function is being called. This facilitates
  83. /// method chaining.
  84. ///
  85. apm& on_command_succeeded(
  86. std::function<void(const mongocxx::events::command_succeeded_event&)> command_succeeded);
  87. ///
  88. /// Retrieves the command succeeded monitoring callback.
  89. ///
  90. /// @return The command succeeded monitoring callback.
  91. ///
  92. const std::function<void(const mongocxx::events::command_succeeded_event&)>& command_succeeded()
  93. const;
  94. ///
  95. /// Set the server opening monitoring callback. The callback takes a reference to a
  96. /// server_opening_event which will only contain valid data for the duration of the callback.
  97. ///
  98. /// @param server_opening
  99. /// The server opening monitoring callback.
  100. ///
  101. /// @return
  102. /// A reference to the object on which this member function is being called. This facilitates
  103. /// method chaining.
  104. ///
  105. apm& on_server_opening(
  106. std::function<void(const mongocxx::events::server_opening_event&)> server_opening);
  107. ///
  108. /// Retrieves the server opening monitoring callback.
  109. ///
  110. /// @return The server opening monitoring callback.
  111. ///
  112. const std::function<void(const mongocxx::events::server_opening_event&)>& server_opening()
  113. const;
  114. ///
  115. /// Set the server closed monitoring callback. The callback takes a reference to a
  116. /// server_closed_event which will only contain valid data for the duration of the callback.
  117. ///
  118. /// @param server_closed
  119. /// The server closed monitoring callback.
  120. ///
  121. /// @return
  122. /// A reference to the object on which this member function is being called. This facilitates
  123. /// method chaining.
  124. ///
  125. apm& on_server_closed(
  126. std::function<void(const mongocxx::events::server_closed_event&)> server_closed);
  127. ///
  128. /// Retrieves the server closed monitoring callback.
  129. ///
  130. /// @return The server closed monitoring callback.
  131. ///
  132. const std::function<void(const mongocxx::events::server_closed_event&)>& server_closed() const;
  133. ///
  134. /// Set the server description changed monitoring callback. The callback takes a reference to a
  135. /// server_changed_event which will only contain valid data for the duration of the
  136. /// callback.
  137. ///
  138. /// @param server_changed
  139. /// The server description changed monitoring callback.
  140. ///
  141. /// @return
  142. /// A reference to the object on which this member function is being called. This facilitates
  143. /// method chaining.
  144. ///
  145. apm& on_server_changed(
  146. std::function<void(const mongocxx::events::server_changed_event&)> server_changed);
  147. ///
  148. /// Retrieves the server description changed monitoring callback.
  149. ///
  150. /// @return The server description changed monitoring callback.
  151. ///
  152. const std::function<void(const mongocxx::events::server_changed_event&)>& server_changed()
  153. const;
  154. ///
  155. /// Set the topology_opening monitoring callback. The callback takes a reference to a
  156. /// topology_opening_event which will only contain valid data for the duration of the callback.
  157. ///
  158. /// @param topology_opening
  159. /// The topology_opening monitoring callback.
  160. ///
  161. /// @return
  162. /// A reference to the object on which this member function is being called. This facilitates
  163. /// method chaining.
  164. ///
  165. apm& on_topology_opening(
  166. std::function<void(const mongocxx::events::topology_opening_event&)> topology_opening);
  167. ///
  168. /// Retrieves the topology_opening monitoring callback.
  169. ///
  170. /// @return The topology_opening monitoring callback.
  171. ///
  172. const std::function<void(const mongocxx::events::topology_opening_event&)>& topology_opening()
  173. const;
  174. ///
  175. /// Set the topology closed monitoring callback. The callback takes a reference to a
  176. /// topology_closed_event which will only contain valid data for the duration of the callback.
  177. ///
  178. /// @param topology_closed
  179. /// The topology closed monitoring callback.
  180. ///
  181. /// @return
  182. /// A reference to the object on which this member function is being called. This facilitates
  183. /// method chaining.
  184. ///
  185. apm& on_topology_closed(
  186. std::function<void(const mongocxx::events::topology_closed_event&)> topology_closed);
  187. ///
  188. /// Retrieves the topology closed monitoring callback.
  189. ///
  190. /// @return The topology closed monitoring callback.
  191. ///
  192. const std::function<void(const mongocxx::events::topology_closed_event&)>& topology_closed()
  193. const;
  194. ///
  195. /// Set the topology description changed monitoring callback. The callback takes a reference to
  196. /// a
  197. /// topology_changed_event which will only contain valid data for the duration of
  198. /// the callback.
  199. ///
  200. /// @param topology_changed
  201. /// The topology description changed monitoring callback.
  202. ///
  203. /// @return
  204. /// A reference to the object on which this member function is being called. This facilitates
  205. /// method chaining.
  206. ///
  207. apm& on_topology_changed(
  208. std::function<void(const mongocxx::events::topology_changed_event&)> topology_changed);
  209. ///
  210. /// Retrieves the topology description changed monitoring callback.
  211. ///
  212. /// @return The topology description changed monitoring callback.
  213. ///
  214. const std::function<void(const mongocxx::events::topology_changed_event&)>& topology_changed()
  215. const;
  216. ///
  217. /// Set the heartbeat started monitoring callback. The callback takes a reference to a
  218. /// heartbeat_started_event which will only contain valid data for the duration of the callback.
  219. ///
  220. /// @param heartbeat_started
  221. /// The heartbeat started monitoring callback.
  222. ///
  223. /// @return
  224. /// A reference to the object on which this member function is being called. This facilitates
  225. /// method chaining.
  226. ///
  227. apm& on_heartbeat_started(
  228. std::function<void(const mongocxx::events::heartbeat_started_event&)> heartbeat_started);
  229. ///
  230. /// Retrieves the heartbeat started monitoring callback.
  231. ///
  232. /// @return The heartbeat started monitoring callback.
  233. ///
  234. const std::function<void(const mongocxx::events::heartbeat_started_event&)>& heartbeat_started()
  235. const;
  236. ///
  237. /// Set the heartbeat failed monitoring callback. The callback takes a reference to a
  238. /// heartbeat_failed_event which will only contain valid data for the duration of the callback.
  239. ///
  240. /// @param heartbeat_failed
  241. /// The heartbeat failed monitoring callback.
  242. ///
  243. /// @return
  244. /// A reference to the object on which this member function is being called. This facilitates
  245. /// method chaining.
  246. ///
  247. apm& on_heartbeat_failed(
  248. std::function<void(const mongocxx::events::heartbeat_failed_event&)> heartbeat_failed);
  249. ///
  250. /// Retrieves the heartbeat failed monitoring callback.
  251. ///
  252. /// @return The heartbeat failed monitoring callback.
  253. ///
  254. const std::function<void(const mongocxx::events::heartbeat_failed_event&)>& heartbeat_failed()
  255. const;
  256. ///
  257. /// Set the heartbeat succeeded monitoring callback. The callback takes a reference to a
  258. /// heartbeat_succeeded_event which will only contain valid data for the duration of the
  259. /// callback.
  260. ///
  261. /// @param heartbeat_succeeded
  262. /// The heartbeat succeeded monitoring callback.
  263. ///
  264. /// @return
  265. /// A reference to the object on which this member function is being called. This facilitates
  266. /// method chaining.
  267. ///
  268. apm& on_heartbeat_succeeded(
  269. std::function<void(const mongocxx::events::heartbeat_succeeded_event&)>
  270. heartbeat_succeeded);
  271. ///
  272. /// Retrieves the heartbeat succeeded monitoring callback.
  273. ///
  274. /// @return The heartbeat succeeded monitoring callback.
  275. ///
  276. const std::function<void(const mongocxx::events::heartbeat_succeeded_event&)>&
  277. heartbeat_succeeded() const;
  278. private:
  279. std::function<void(const mongocxx::events::command_started_event&)> _command_started;
  280. std::function<void(const mongocxx::events::command_failed_event&)> _command_failed;
  281. std::function<void(const mongocxx::events::command_succeeded_event&)> _command_succeeded;
  282. std::function<void(const mongocxx::events::server_closed_event&)> _server_closed;
  283. std::function<void(const mongocxx::events::server_changed_event&)> _server_changed;
  284. std::function<void(const mongocxx::events::server_opening_event&)> _server_opening;
  285. std::function<void(const mongocxx::events::topology_closed_event&)> _topology_closed;
  286. std::function<void(const mongocxx::events::topology_changed_event&)> _topology_changed;
  287. std::function<void(const mongocxx::events::topology_opening_event&)> _topology_opening;
  288. std::function<void(const mongocxx::events::heartbeat_started_event&)> _heartbeat_started;
  289. std::function<void(const mongocxx::events::heartbeat_failed_event&)> _heartbeat_failed;
  290. std::function<void(const mongocxx::events::heartbeat_succeeded_event&)> _heartbeat_succeeded;
  291. };
  292. } // namespace options
  293. MONGOCXX_INLINE_NAMESPACE_END
  294. } // namespace mongocxx
  295. #include <mongocxx/config/postlude.hpp>