MongoDB C++ Driver legacy-1.1.2
Loading...
Searching...
No Matches
init.h
1// @file init.h
2
3/* Copyright 2013 10gen Inc.
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 */
17
18#pragma once
19
20#include "mongo/base/status.h"
21#include "mongo/client/export_macros.h"
22#include "mongo/client/options.h"
23
24// NOTE: These functions are only intended to be used when linking against the libmongoclient
25// library. The below functions are not defined in servers like mongos or mongod, which have
26// their own initialization strategy.
27
32namespace mongo {
33
38namespace client {
39
49MONGO_CLIENT_API Status MONGO_CLIENT_FUNC initialize(const Options& options = Options());
50
61MONGO_CLIENT_API Status MONGO_CLIENT_FUNC shutdown();
62
69class MONGO_CLIENT_API GlobalInstance {
70 MONGO_DISALLOW_COPYING(GlobalInstance);
71
72public:
82 explicit GlobalInstance(const Options& options = Options());
83
90
92 const Status& status() const {
93 return _status;
94 }
95
97 bool initialized() const {
98 return status().isOK();
99 }
100
104 void assertInitialized() const;
105
113
114private:
115 bool _terminateNeeded;
116 const Status _status;
117};
118
119} // namespace client
120} // namespace mongo
Status represents an error state or the absence thereof.
Definition status.h:50
An RAII helper to simplify driver setup and teardown.
Definition init.h:69
void assertInitialized() const
Raises a UserAssertion exception if the GlobalInstance failed to initialize the library.
Status shutdown()
Immediately calls 'shutdown' on the driver and returns the resulting Status.
GlobalInstance(const Options &options=Options())
Invokes 'mongo::client::initialize" with the provided Options, or the default Options if none are pro...
bool initialized() const
Returns 'true' if initialization succeeded, 'false' otherwise.
Definition init.h:97
~GlobalInstance()
Invokes 'mongo::client::shutdown' if the GlobalInstance succeeded in initializing the library and if ...
const Status & status() const
Returns the Status generated by the internal call to 'client::initialize'.
Definition init.h:92
The Options structure is passed to mongo::client::initialize to configure various properties and conf...
Definition options.h:32
MONGO_CLIENT_API Status MONGO_CLIENT_FUNC shutdown()
Terminates the client driver.
MONGO_CLIENT_API Status MONGO_CLIENT_FUNC initialize(const Options &options=Options())
Initializes the client driver, possibly with custom options.
Utility functions for parsing numbers from strings.
Definition compare_numbers.h:20