summaryrefslogtreecommitdiff
path: root/src/mongo/util/options_parser/startup_option_init.h
blob: c027574dd21ed39eb03b46ab51596d407893013d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
/**
 *    Copyright (C) 2018-present MongoDB, Inc.
 *
 *    This program is free software: you can redistribute it and/or modify
 *    it under the terms of the Server Side Public License, version 1,
 *    as published by MongoDB, Inc.
 *
 *    This program is distributed in the hope that it will be useful,
 *    but WITHOUT ANY WARRANTY; without even the implied warranty of
 *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *    Server Side Public License for more details.
 *
 *    You should have received a copy of the Server Side Public License
 *    along with this program. If not, see
 *    <http://www.mongodb.com/licensing/server-side-public-license>.
 *
 *    As a special exception, the copyright holders give permission to link the
 *    code of portions of this program with the OpenSSL library under certain
 *    conditions as described in each individual source file and distribute
 *    linked combinations including the program with the OpenSSL library. You
 *    must comply with the Server Side Public License in all respects for
 *    all of the code used other than as permitted herein. If you modify file(s)
 *    with this exception, you may extend this exception to your version of the
 *    file(s), but you are not obligated to do so. If you do not wish to do so,
 *    delete this exception statement from your version. If you delete this
 *    exception statement from all source files in the program, then also delete
 *    it in the license file.
 */

/**
 * Utility macros for declaring global initializers for startup options.
 *
 * Should NOT be included by other header files.  Include only in source files.
 *
 * Initializer functions take a parameter of type ::mongo::InitializerContext*, and return
 * a Status.  Any status other than Status::OK() is considered a failure that will stop further
 * intializer processing.
 *
 * Note that currently storage and validation are done in the same stage, so do not try to do things
 * that depend on your initializer being between these two stages
 *
 * See comments in the included init.h file for more details.
 */

#pragma once

#include "mongo/base/init.h"

/**
 * Helper macros to use when handling startup options
 * Note that you should only need these if you are working with options or are using an initializer
 * before the "default" group, which is set to happen after all the option initialization is done
 */

/**
 * Macro to define an initializer function named "<fname>_Register" to register general startup
 * options that are always in the executable
 *
 * Usage:
 *     MONGO_GENERAL_STARTUP_OPTIONS_REGISTER(MongodOptions)(InitializerContext* context) {
 *         return Status::OK();
 *     }
 */
#define MONGO_GENERAL_STARTUP_OPTIONS_REGISTER(fname)                    \
    MONGO_INITIALIZER_GENERAL(fname##_Register,                          \
                              ("BeginGeneralStartupOptionRegistration"), \
                              ("EndGeneralStartupOptionRegistration"))

/**
 * Macro to define an initializer function named "<fname>_Register" to register module startup
 * options that are conditionally linked into the executable.  This will get run after the general
 * startup options, and thus options registered in these will appear after those in help output.
 *
 * Usage:
 *     MONGO_MODULE_STARTUP_OPTIONS_REGISTER(MongodOptions)(InitializerContext* context) {
 *         return Status::OK();
 *     }
 */
#define MONGO_MODULE_STARTUP_OPTIONS_REGISTER(fname)                   \
    MONGO_INITIALIZER_GENERAL(fname##_Register,                        \
                              ("EndGeneralStartupOptionRegistration"), \
                              ("EndStartupOptionRegistration"))

/**
 * Macro to define an initializer function named "<fname>_Parse" to parse the command line and
 * config file options.
 * This should only be defined once per binary.
 *
 * Usage:
 *     MONGO_STARTUP_OPTIONS_PARSE(MongodOptions)(InitializerContext* context) {
 *         return Status::OK();
 *     }
 */
#define MONGO_STARTUP_OPTIONS_PARSE(fname) \
    MONGO_INITIALIZER_GENERAL(             \
        fname##_Parse, ("BeginStartupOptionParsing"), ("EndStartupOptionParsing"))

/**
 * Macro to define an initializer function named "<fname>_Validate" to validate the command line and
 * config file options.
 *
 * Warning:  Validation still currently happens in the storage stage, so do not write an initializer
 * that depends on them being separate.
 *
 * Usage:
 *     MONGO_STARTUP_OPTIONS_PARSE(MongodOptions)(InitializerContext* context) {
 *         return Status::OK();
 *     }
 */
#define MONGO_STARTUP_OPTIONS_VALIDATE(fname) \
    MONGO_INITIALIZER_GENERAL(                \
        fname##_Validate, ("BeginStartupOptionValidation"), ("EndStartupOptionValidation"))

/**
 * Macro to define an initializer function named "<fname>_Store" to store the command line and
 * config file options.  This includes setting the values of global variables and configuring global
 * state.
 *
 * Warning:  Validation still currently happens in the storage stage, so do not write an initializer
 * that depends on them being separate.
 *
 * Usage:
 *     MONGO_STARTUP_OPTIONS_STORE(MongodOptions)(InitializerContext* context) {
 *         return Status::OK();
 *     }
 */
#define MONGO_STARTUP_OPTIONS_STORE(fname) \
    MONGO_INITIALIZER_GENERAL(             \
        fname##_Store, ("BeginStartupOptionStorage"), ("EndStartupOptionStorage"))

/**
 * Macro to define an initializer function named "<fname>_Post" to set internal values after storing
 * the command line and config file options.  This includes setting the values of global variables
 * and configuring global state.
 *
 * Usage:
 *     MONGO_STARTUP_OPTIONS_POST(MongodOptions)(InitializerContext* context) {
 *         return Status::OK();
 *     }
 */
#define MONGO_STARTUP_OPTIONS_POST(fname) \
    MONGO_INITIALIZER_GENERAL(            \
        fname##_Store, ("BeginPostStartupOptionStorage"), ("EndPostStartupOptionStorage"))