MongoDB C++ Driver  legacy-1.1.2
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 
32 namespace mongo {
33 
38 namespace client {
39 
49 MONGO_CLIENT_API Status MONGO_CLIENT_FUNC initialize(const Options& options = Options());
50 
61 MONGO_CLIENT_API Status MONGO_CLIENT_FUNC shutdown();
62 
69 class MONGO_CLIENT_API GlobalInstance {
70  MONGO_DISALLOW_COPYING(GlobalInstance);
71 
72 public:
82  explicit GlobalInstance(const Options& options = Options());
83 
89  ~GlobalInstance();
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 
112  Status shutdown();
113 
114 private:
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
bool initialized() const
Returns 'true' if initialization succeeded, 'false' otherwise.
Definition: init.h:97
MONGO_CLIENT_API Status MONGO_CLIENT_FUNC shutdown()
Terminates the client driver.
Utility functions for parsing numbers from strings.
Definition: compare_numbers.h:20
const Status & status() const
Returns the Status generated by the internal call to 'client::initialize'.
Definition: init.h:92
MONGO_CLIENT_API Status MONGO_CLIENT_FUNC initialize(const Options &options=Options())
Initializes the client driver, possibly with custom options.
The Options structure is passed to mongo::client::initialize to configure various properties and conf...
Definition: options.h:32
An RAII helper to simplify driver setup and teardown.
Definition: init.h:69
MONGO_CLIENT_API Status(MONGO_CLIENT_FUNC *saslClientAuthenticate)(DBClientWithCommands *client
Attempts to authenticate "client" using the SASL protocol.