-
Notifications
You must be signed in to change notification settings - Fork 547
CXX-3320 migrate instance and logger to mongocxx::v1 #1469
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
efb65cb
2892b35
0370746
4508456
40218af
3483624
75d5e9e
cc5339f
ba058a4
91b3d62
20b931c
df7bf53
f24f3b6
0be7784
f2ecef1
d2de21a
bf715d7
5160285
3d276c8
42cac6f
33c1853
4ae0cd9
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -20,6 +20,14 @@ | |
|
|
||
| #include <mongocxx/v1/detail/prelude.hpp> | ||
|
|
||
| #include <mongocxx/v1/logger-fwd.hpp> | ||
|
|
||
| #include <mongocxx/v1/config/export.hpp> | ||
|
|
||
| #include <memory> | ||
| #include <system_error> | ||
| #include <type_traits> | ||
|
|
||
| namespace mongocxx { | ||
| namespace v1 { | ||
|
|
||
|
|
@@ -50,15 +58,123 @@ namespace v1 { | |
| /// @par Special exemptions | ||
| /// Only the following API are permitted to be used outside the lifetime of an instance object: | ||
| /// - @ref mongocxx::v1::logger | ||
| /// - @ref mongocxx::v1::default_logger | ||
| /// | ||
| /// @see | ||
| /// - [Initialization and Cleanup (mongoc)](https://mongoc.org/libmongoc/current/init-cleanup.html) | ||
| /// | ||
| class instance {}; | ||
| class instance { | ||
| private: | ||
| class impl; | ||
| std::unique_ptr<impl> _impl; | ||
|
|
||
| public: | ||
| /// | ||
| /// Cleanup the mongocxx (and mongoc) library. | ||
| /// | ||
| /// Calls [`mongoc_cleanup()`](https://mongoc.org/libmongoc/current/mongoc_cleanup.html). | ||
| /// | ||
| MONGOCXX_ABI_EXPORT_CDECL() ~instance(); | ||
|
|
||
| /// | ||
| /// This class is not moveable. | ||
| /// | ||
| instance(instance&&) = delete; | ||
|
|
||
| /// | ||
| /// This class is not moveable. | ||
| /// | ||
| instance& operator=(instance&&) = delete; | ||
|
|
||
| /// | ||
| /// This class is not copyable. | ||
| /// | ||
| instance(instance const&) = delete; | ||
|
|
||
| /// | ||
| /// This class is not copyable. | ||
| /// | ||
| instance& operator=(instance const&) = delete; | ||
|
Comment on lines
+79
to
+97
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Relative breaking change: |
||
|
|
||
| /// | ||
| /// Initialize the mongoc library with unstructured log messages disabled. | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Updated documentation to clarify that this all applies to "unstructured log handling" to leave open the design space for "structured log handling" support by the C++ Driver. Documentation also increased references to specific mongoc API to clarify behavior + defer much of the behavioral documentation to mongoc. |
||
| /// | ||
| /// Calls [`mongoc_init()`](https://mongoc.org/libmongoc/current/mongoc_init.html) after disabling unstructured | ||
| /// log messages by calling `mongoc_log_set_handler(nullptr, nullptr)`. | ||
| /// | ||
| /// @important To use mongoc's default log message handler, construct this object with | ||
| /// @ref instance(v1::default_logger tag) instead. | ||
| /// | ||
| /// @throws mongocxx::v1::exception with @ref mongocxx::v1::instance::errc::multiple_instances if an `instance` | ||
| /// object has already been created. | ||
| /// | ||
| /// @see | ||
| /// - [Custom Log Handlers (mongoc)](https://mongoc.org/libmongoc/current/unstructured_log.html#custom-log-handlers) | ||
| /// | ||
| MONGOCXX_ABI_EXPORT_CDECL() instance(); | ||
|
|
||
| /// | ||
| /// Initialize the mongoc library with the custom unstructured log message handler. | ||
| /// | ||
| /// Calls [`mongoc_init`](https://mongoc.org/libmongoc/current/mongoc_init.html) after registering the custom | ||
| /// unstructured log handler by calling `mongoc_log_set_handler()`. | ||
| /// | ||
| /// @param handler Disable unstructured logging when null. | ||
| /// | ||
| /// @throws mongocxx::v1::exception with @ref mongocxx::v1::instance::errc::multiple_instances if an `instance` | ||
| /// object has already been created. | ||
| /// | ||
| /// @see | ||
| /// - [Custom Log Handlers (mongoc)](https://mongoc.org/libmongoc/current/unstructured_log.html#custom-log-handlers) | ||
| /// | ||
| explicit MONGOCXX_ABI_EXPORT_CDECL() instance(std::unique_ptr<v1::logger> handler); | ||
|
|
||
| /// | ||
| /// Initialize the mongoc library with its default unstructured log handler. | ||
| /// | ||
| /// Calls [`mongoc_init`](https://mongoc.org/libmongoc/current/mongoc_init.html) without registering any custom | ||
| /// unstructured log handler. | ||
| /// | ||
| /// @param tag Unused: only for overload resolution. | ||
| /// | ||
| /// @throws mongocxx::v1::exception with @ref mongocxx::v1::instance::errc::multiple_instances if an `instance` | ||
| /// object has already been created. | ||
| /// | ||
| explicit MONGOCXX_ABI_EXPORT_CDECL() instance(v1::default_logger tag); | ||
|
|
||
| /// | ||
| /// Errors codes which may be returned by @ref mongocxx::v1::instance. | ||
| /// | ||
| /// @attention This feature is experimental! It is not ready for use! | ||
| /// | ||
| enum class errc { | ||
| zero, ///< Zero. | ||
| multiple_instances, ///< Cannot construct multiple instance objects in a given process. | ||
| }; | ||
|
|
||
| /// | ||
| /// The error category for @ref mongocxx::v1::instance::errc. | ||
| /// | ||
| /// @attention This feature is experimental! It is not ready for use! | ||
| /// | ||
| static MONGOCXX_ABI_EXPORT_CDECL(std::error_category const&) error_category(); | ||
|
|
||
| /// | ||
| /// Support implicit conversion to `std::error_code`. | ||
| /// | ||
| /// @attention This feature is experimental! It is not ready for use! | ||
| /// | ||
| friend std::error_code make_error_code(errc v) { | ||
| return {static_cast<int>(v), error_category()}; | ||
| } | ||
| }; | ||
|
|
||
| } // namespace v1 | ||
| } // namespace mongocxx | ||
|
|
||
| template <> | ||
| struct std::is_error_code_enum<mongocxx::v1::instance::errc> : true_type {}; | ||
|
|
||
| #include <mongocxx/v1/detail/postlude.hpp> | ||
|
|
||
| /// | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this be
zero, or something likeokay? Alternatively: setmongocxx = 1, give theenuma base type likeint, and then havesource_errc{}as the stand-in forzero, which is the non-error syntax forstd::errc.(I don't feel strongly about any of the above options, just something to consider.)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My reason for including the
zeroenumerator was twofold:= 1in the otherwise=-less list of enumerators (an inconsistency).zerocase in switch cases via-Wswitch/-Wswitch-enum.I opted for
zeroinstead ofokayto avoid implying anything beyond a description of the value itself, since "not zero" does not necessarily imply "not okay" or "not valid" given certain error code schemes (i.e. "HTTP status code 200").The default underlying type for a scoped enumeration is
int, so there is no need for explicit: intgivenenum class E.