~evarlast/ubuntu/utopic/mongodb/upstart-workaround-debian-bug-718702

« back to all changes in this revision

Viewing changes to src/mongo/db/server_parameters.h

  • Committer: Package Import Robot
  • Author(s): James Page, James Page, Robie Basak
  • Date: 2013-05-29 17:44:42 UTC
  • mfrom: (44.1.7 sid)
  • Revision ID: package-import@ubuntu.com-20130529174442-z0a4qmoww4y0t458
Tags: 1:2.4.3-1ubuntu1
[ James Page ]
* Merge from Debian unstable, remaining changes:
  - Enable SSL support:
    + d/control: Add libssl-dev to BD's.
    + d/rules: Enabled --ssl option.
    + d/mongodb.conf: Add example SSL configuration options.
  - d/mongodb-server.mongodb.upstart: Add upstart configuration.
  - d/rules: Don't strip binaries during scons build for Ubuntu.
  - d/control: Add armhf to target archs.
  - d/p/SConscript.client.patch: fixup install of client libraries.
  - d/p/0010-install-libs-to-usr-lib-not-usr-lib64-Closes-588557.patch:
    Install libraries to lib not lib64.
* Dropped changes:
  - d/p/arm-support.patch: Included in Debian.
  - d/p/double-alignment.patch: Included in Debian.
  - d/rules,control: Debian also builds with avaliable system libraries
    now.
* Fix FTBFS due to gcc and boost upgrades in saucy:
  - d/p/0008-ignore-unused-local-typedefs.patch: Add -Wno-unused-typedefs
    to unbreak building with g++-4.8.
  - d/p/0009-boost-1.53.patch: Fixup signed/unsigned casting issue.

[ Robie Basak ]
* d/p/0011-Use-a-signed-char-to-store-BSONType-enumerations.patch: Fixup
  build failure on ARM due to missing signed'ness of char cast.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
// server_parameters.h
 
2
 
 
3
/**
 
4
*    Copyright (C) 2012 10gen Inc.
 
5
*
 
6
*    This program is free software: you can redistribute it and/or  modify
 
7
*    it under the terms of the GNU Affero General Public License, version 3,
 
8
*    as published by the Free Software Foundation.
 
9
*
 
10
*    This program is distributed in the hope that it will be useful,
 
11
*    but WITHOUT ANY WARRANTY; without even the implied warranty of
 
12
*    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
13
*    GNU Affero General Public License for more details.
 
14
*
 
15
*    You should have received a copy of the GNU Affero General Public License
 
16
*    along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
17
*/
 
18
 
 
19
#pragma once
 
20
 
 
21
#include <string>
 
22
#include <map>
 
23
 
 
24
#include "mongo/base/status.h"
 
25
#include "mongo/db/jsobj.h"
 
26
 
 
27
namespace mongo {
 
28
 
 
29
    class ServerParameterSet;
 
30
 
 
31
    /**
 
32
     * Lets you make server level settings easily configurable.
 
33
     * Hooks into (set|get)Paramter, as well as command line processing
 
34
     */
 
35
    class ServerParameter {
 
36
    public:
 
37
        typedef std::map< std::string, ServerParameter* > Map;
 
38
 
 
39
        ServerParameter( ServerParameterSet* sps, const std::string& name,
 
40
                         bool allowedToChangeAtStartup, bool allowedToChangeAtRuntime );
 
41
        ServerParameter( ServerParameterSet* sps, const std::string& name );
 
42
        virtual ~ServerParameter();
 
43
 
 
44
        std::string name() const { return _name; }
 
45
 
 
46
        /**
 
47
         * @return if you can set on command line or config file
 
48
         */
 
49
        bool allowedToChangeAtStartup() const { return _allowedToChangeAtStartup; }
 
50
 
 
51
        /**
 
52
         * @param if you can use (get|set)Parameter
 
53
         */
 
54
        bool allowedToChangeAtRuntime() const { return _allowedToChangeAtRuntime; }
 
55
 
 
56
 
 
57
        virtual void append( BSONObjBuilder& b, const string& name ) = 0;
 
58
 
 
59
        virtual Status set( const BSONElement& newValueElement ) = 0;
 
60
 
 
61
        virtual Status setFromString( const string& str ) = 0;
 
62
 
 
63
    private:
 
64
        string _name;
 
65
        bool _allowedToChangeAtStartup;
 
66
        bool _allowedToChangeAtRuntime;
 
67
    };
 
68
 
 
69
    class ServerParameterSet {
 
70
    public:
 
71
        typedef std::map< std::string, ServerParameter* > Map;
 
72
 
 
73
        void add( ServerParameter* sp );
 
74
 
 
75
        const Map& getMap() const { return _map; }
 
76
 
 
77
        static ServerParameterSet* getGlobal();
 
78
 
 
79
    private:
 
80
        Map _map;
 
81
    };
 
82
 
 
83
    /**
 
84
     * Implementation of ServerParameter for reading and writing a server parameter with a given
 
85
     * name and type into a specific C++ variable.
 
86
     */
 
87
    template<typename T>
 
88
    class ExportedServerParameter : public ServerParameter {
 
89
    public:
 
90
 
 
91
        /**
 
92
         * Construct an ExportedServerParameter in parameter set "sps", named "name", whose storage
 
93
         * is at "value".
 
94
         *
 
95
         * If allowedToChangeAtStartup is true, the parameter may be set at the command line,
 
96
         * e.g. via the --setParameter switch.  If allowedToChangeAtRuntime is true, the parameter
 
97
         * may be set at runtime, e.g.  via the setParameter command.
 
98
         */
 
99
        ExportedServerParameter( ServerParameterSet* sps, const std::string& name, T* value,
 
100
                                 bool allowedToChangeAtStartup, bool allowedToChangeAtRuntime)
 
101
            : ServerParameter( sps, name, allowedToChangeAtStartup, allowedToChangeAtRuntime ),
 
102
              _value( value ) {}
 
103
        virtual ~ExportedServerParameter() {}
 
104
 
 
105
        virtual void append( BSONObjBuilder& b, const string& name ) {
 
106
            b.append( name, *_value );
 
107
        }
 
108
 
 
109
        virtual Status set( const BSONElement& newValueElement );
 
110
        virtual Status set( const T& newValue );
 
111
 
 
112
        virtual const T& get() const { return *_value; }
 
113
 
 
114
        virtual Status setFromString( const string& str );
 
115
 
 
116
    protected:
 
117
 
 
118
        virtual Status validate( const T& potentialNewValue ){ return Status::OK(); }
 
119
 
 
120
        T* _value; // owned elsewhere
 
121
    };
 
122
}
 
123
 
 
124
#define MONGO_EXPORT_SERVER_PARAMETER_IMPL( NAME, TYPE, INITIAL_VALUE, \
 
125
                                            CHANGE_AT_STARTUP, CHANGE_AT_RUNTIME ) \
 
126
    TYPE NAME = INITIAL_VALUE;                                          \
 
127
    ExportedServerParameter<TYPE> _##NAME(\
 
128
            ServerParameterSet::getGlobal(), #NAME, &NAME, CHANGE_AT_STARTUP, CHANGE_AT_RUNTIME )
 
129
 
 
130
/**
 
131
 * Create a global variable of type "TYPE" named "NAME" with the given INITIAL_VALUE.  The
 
132
 * value may be set at startup or at runtime.
 
133
 */
 
134
#define MONGO_EXPORT_SERVER_PARAMETER( NAME, TYPE, INITIAL_VALUE ) \
 
135
    MONGO_EXPORT_SERVER_PARAMETER_IMPL( NAME, TYPE, INITIAL_VALUE, true, true )
 
136
 
 
137
/**
 
138
 * Like MONGO_EXPORT_SERVER_PARAMETER, but the value may only be set at startup.
 
139
 */
 
140
#define MONGO_EXPORT_STARTUP_SERVER_PARAMETER( NAME, TYPE, INITIAL_VALUE ) \
 
141
    MONGO_EXPORT_SERVER_PARAMETER_IMPL( NAME, TYPE, INITIAL_VALUE, true, false )
 
142
 
 
143
/**
 
144
 * Like MONGO_EXPORT_SERVER_PARAMETER, but the value may only be set at runtime.
 
145
 */
 
146
#define MONGO_EXPORT_RUNTIME_SERVER_PARAMETER( NAME, TYPE, INITIAL_VALUE ) \
 
147
    MONGO_EXPORT_SERVER_PARAMETER_IMPL( NAME, TYPE, INITIAL_VALUE, false, true )
 
148
 
 
149
#include "server_parameters_inline.h"