diff options
author | Shaun Verch <shaun.verch@10gen.com> | 2013-09-05 16:03:15 -0400 |
---|---|---|
committer | Shaun Verch <shaun.verch@10gen.com> | 2013-09-05 16:03:15 -0400 |
commit | 49fd378c1de587c185da9e47d753e5622be1d16c (patch) | |
tree | fe867225d3b7e140b8318b87c971ef80bd1fdee1 /src | |
parent | 9d6ae725a6bf4a8a57bac8bfd6e5f598055e9fdf (diff) | |
download | mongo-49fd378c1de587c185da9e47d753e5622be1d16c.tar.gz |
SERVER-8510 Bring back Module class
Diffstat (limited to 'src')
-rw-r--r-- | src/mongo/SConscript | 3 | ||||
-rw-r--r-- | src/mongo/db/db.cpp | 5 | ||||
-rw-r--r-- | src/mongo/db/module.cpp | 68 | ||||
-rw-r--r-- | src/mongo/db/module.h | 70 | ||||
-rw-r--r-- | src/mongo/db/mongod.vcxproj | 2 | ||||
-rw-r--r-- | src/mongo/db/mongod.vcxproj.filters | 6 | ||||
-rw-r--r-- | src/mongo/dbtests/test.vcxproj | 1 | ||||
-rwxr-xr-x | src/mongo/dbtests/test.vcxproj.filters | 3 |
8 files changed, 157 insertions, 1 deletions
diff --git a/src/mongo/SConscript b/src/mongo/SConscript index 58b3966fb78..09d0d37fc2b 100644 --- a/src/mongo/SConscript +++ b/src/mongo/SConscript @@ -691,7 +691,8 @@ serverOnlyFiles += [ "s/d_logic.cpp", "s/d_state.cpp", "s/d_split.cpp", "s/d_merge.cpp", - "client/distlock_test.cpp" ] + "client/distlock_test.cpp", + "db/module.cpp" ] env.StaticLibrary("defaultversion", "s/default_version.cpp") diff --git a/src/mongo/db/db.cpp b/src/mongo/db/db.cpp index b4888277077..9a11d6ce083 100644 --- a/src/mongo/db/db.cpp +++ b/src/mongo/db/db.cpp @@ -45,6 +45,7 @@ #include "mongo/db/introspect.h" #include "mongo/db/json.h" #include "mongo/db/kill_current_op.h" +#include "mongo/db/module.h" #include "mongo/db/mongod_options.h" #include "mongo/db/pdfile.h" #include "mongo/db/query/internal_plans.h" @@ -699,6 +700,8 @@ namespace mongo { log() << startupWarningsLog; } + Module::initAll(); + if ( scriptingEnabled ) { ScriptEngine::setup(); globalScriptEngine->setCheckInterruptCallback( jsInterruptCallback ); @@ -1214,6 +1217,8 @@ static void startupConfigActions(const std::vector<std::string>& argv) { } } + Module::configAll(params); + #ifdef _WIN32 ntservice::configureService(initService, params, diff --git a/src/mongo/db/module.cpp b/src/mongo/db/module.cpp new file mode 100644 index 00000000000..f3035b56dde --- /dev/null +++ b/src/mongo/db/module.cpp @@ -0,0 +1,68 @@ +// module.cpp +/* + * Copyright (C) 2010 10gen Inc. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License, version 3, + * as published by the Free Software Foundation. + * + * 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 + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + */ + +#include "mongo/pch.h" + +#include "mongo/db/module.h" + +namespace mongo { + + std::list<Module*> * Module::_all; + + Module::Module( const string& name ) + : _name( name ) , _options( (string)"Module " + name + " options" ) { + if ( ! _all ) + _all = new list<Module*>(); + _all->push_back( this ); + } + + Module::~Module() {} + + void Module::addOptions( boost::program_options::options_description& options ) { + if ( ! _all ) { + return; + } + for ( list<Module*>::iterator i=_all->begin(); i!=_all->end(); i++ ) { + Module* m = *i; + options.add( m->_options ); + } + } + + void Module::configAll( boost::program_options::variables_map& params ) { + if ( ! _all ) { + return; + } + for ( list<Module*>::iterator i=_all->begin(); i!=_all->end(); i++ ) { + Module* m = *i; + m->config( params ); + } + + } + + + void Module::initAll() { + if ( ! _all ) { + return; + } + for ( list<Module*>::iterator i=_all->begin(); i!=_all->end(); i++ ) { + Module* m = *i; + m->init(); + } + + } + +} diff --git a/src/mongo/db/module.h b/src/mongo/db/module.h new file mode 100644 index 00000000000..662624aba9e --- /dev/null +++ b/src/mongo/db/module.h @@ -0,0 +1,70 @@ +// module.h + +/** +* Copyright (C) 2008 10gen Inc.info +* +* This program is free software: you can redistribute it and/or modify +* it under the terms of the GNU Affero General Public License, version 3, +* as published by the Free Software Foundation. +* +* 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 +* GNU Affero General Public License for more details. +* +* You should have received a copy of the GNU Affero General Public License +* along with this program. If not, see <http://www.gnu.org/licenses/>. +*/ + +#pragma once + +#include <boost/program_options.hpp> +#include <list> +#include <string> + +namespace mongo { + + /** + * Module is the base class for adding modules to MongoDB + * modules allow adding hooks and features to mongo + * the idea is to add hooks into the main code for module support where needed + * some ideas are: monitoring, indexes, full text search + */ + class Module { + public: + Module( const std::string& name ); + virtual ~Module(); + + boost::program_options::options_description_easy_init add_options() { + return _options.add_options(); + } + + /** + * read config from command line + */ + virtual void config( boost::program_options::variables_map& params ) = 0; + + /** + * called after configuration when the server is ready start + */ + virtual void init() = 0; + + /** + * called when the database is about to shutdown + */ + virtual void shutdown() = 0; + + const std::string& getName() { return _name; } + + // --- static things + + static void addOptions( boost::program_options::options_description& options ); + static void configAll( boost::program_options::variables_map& params ); + static void initAll(); + + private: + static std::list<Module*> * _all; + std::string _name; + boost::program_options::options_description _options; + }; +} diff --git a/src/mongo/db/mongod.vcxproj b/src/mongo/db/mongod.vcxproj index 71d8a36759f..3ec79fb6c0f 100644 --- a/src/mongo/db/mongod.vcxproj +++ b/src/mongo/db/mongod.vcxproj @@ -4516,6 +4516,7 @@ cscript //Nologo "$(ProjectDir)..\shell\createCPPfromJavaScriptFiles.js" "$(Proj <ClInclude Include="matcher_covered.h" />
<ClInclude Include="memconcept.h" />
<ClInclude Include="minilex.h" />
+ <ClInclude Include="module.h" />
<ClInclude Include="namespace_details-inl.h" />
<ClInclude Include="namespace_details.h" />
<ClInclude Include="field_ref.h" />
@@ -4572,6 +4573,7 @@ cscript //Nologo "$(ProjectDir)..\shell\createCPPfromJavaScriptFiles.js" "$(Proj <ClCompile Include="lasterror.cpp" />
<ClCompile Include="matcher_covered.cpp" />
<ClCompile Include="..\util\mmap_win.cpp" />
+ <ClCompile Include="module.cpp" />
<ClCompile Include="..\client\parallel.cpp" />
<ClCompile Include="pdfile.cpp" />
<ClCompile Include="scanandorder.cpp" />
diff --git a/src/mongo/db/mongod.vcxproj.filters b/src/mongo/db/mongod.vcxproj.filters index 6de0eb09d8e..c252ef2faa1 100644 --- a/src/mongo/db/mongod.vcxproj.filters +++ b/src/mongo/db/mongod.vcxproj.filters @@ -623,6 +623,9 @@ <ClCompile Include="memconcept.cpp">
<Filter>db\Source Files\e to n</Filter>
</ClCompile>
+ <ClCompile Include="module.cpp">
+ <Filter>db\Source Files\e to n</Filter>
+ </ClCompile>
<ClCompile Include="namespace_details.cpp">
<Filter>db\Source Files\e to n</Filter>
</ClCompile>
@@ -3926,6 +3929,9 @@ <ClInclude Include="minilex.h">
<Filter>db\Header Files\e to n</Filter>
</ClInclude>
+ <ClInclude Include="module.h">
+ <Filter>db\Header Files\e to n</Filter>
+ </ClInclude>
<ClInclude Include="cloner.h">
<Filter>db\Header Files\a to d</Filter>
</ClInclude>
diff --git a/src/mongo/dbtests/test.vcxproj b/src/mongo/dbtests/test.vcxproj index 3efb016e395..c53ff79b844 100644 --- a/src/mongo/dbtests/test.vcxproj +++ b/src/mongo/dbtests/test.vcxproj @@ -758,6 +758,7 @@ cscript //Nologo "$(ProjectDir)..\shell\createCPPfromJavaScriptFiles.js" "$(Proj <ClInclude Include="..\db\matcher\match_details.h" />
<ClInclude Include="..\db\matcher_covered.h" />
<ClInclude Include="..\db\memconcept.h" />
+ <ClInclude Include="..\db\module.h" />
<ClInclude Include="..\db\mongomutex.h" />
<ClInclude Include="..\db\namespace_details-inl.h" />
<ClInclude Include="..\db\namespace_details.h" />
diff --git a/src/mongo/dbtests/test.vcxproj.filters b/src/mongo/dbtests/test.vcxproj.filters index 601db43b28a..befe7dcdf2f 100755 --- a/src/mongo/dbtests/test.vcxproj.filters +++ b/src/mongo/dbtests/test.vcxproj.filters @@ -880,6 +880,9 @@ <ClInclude Include="..\db\memconcept.h">
<Filter>db\Header Files\e to n</Filter>
</ClInclude>
+ <ClInclude Include="..\db\module.h">
+ <Filter>db\Header Files\e to n</Filter>
+ </ClInclude>
<ClInclude Include="..\util\admin_access.h">
<Filter>util\Header Files</Filter>
</ClInclude>
|