diff options
97 files changed, 535 insertions, 25 deletions
diff --git a/client/connpool.cpp b/client/connpool.cpp index f956c03821e..90271909ed3 100644 --- a/client/connpool.cpp +++ b/client/connpool.cpp @@ -22,6 +22,8 @@ #include "stdafx.h" #include "connpool.h" +namespace mongo { + DBConnectionPool pool; DBClientConnection* DBConnectionPool::get(const string& host) { @@ -44,3 +46,5 @@ DBClientConnection* DBConnectionPool::get(const string& host) { p->pool.pop(); return c; } + +} // namespace mongo diff --git a/client/connpool.h b/client/connpool.h index fafee2b7ab1..c811152e474 100644 --- a/client/connpool.h +++ b/client/connpool.h @@ -21,6 +21,8 @@ #include <queue> #include "dbclient.h" +namespace mongo { + struct PoolForHost { queue<DBClientConnection*> pool; }; @@ -86,3 +88,5 @@ public: } } }; + +} // namespace mongo diff --git a/client/dbclient.cpp b/client/dbclient.cpp index 1e67a24e870..7e68d35aac7 100644 --- a/client/dbclient.cpp +++ b/client/dbclient.cpp @@ -25,6 +25,8 @@ #include "../db/json.h" #include "../db/instance.h" +namespace mongo { + /* --- dbclientcommands --- */ inline bool DBClientWithCommands::isOk(const BSONObj& o) { @@ -611,3 +613,5 @@ BSONObj DBClientPaired::findOne(const char *a, BSONObj b, BSONObj *c, int d) { } + +} // namespace mongo diff --git a/client/dbclient.h b/client/dbclient.h index 420cd21da3c..10075497850 100644 --- a/client/dbclient.h +++ b/client/dbclient.h @@ -22,6 +22,8 @@ #include "../grid/message.h" #include "../db/jsobj.h" +namespace mongo { + /* the query field 'options' can have these bits set: */ enum QueryOptions { /* Tailable means cursor is not closed when the last data is retrieved. rather, the cursor marks @@ -438,3 +440,5 @@ public: }; + +} // namespace mongo diff --git a/client/examples/clientTest.cpp b/client/examples/clientTest.cpp index d9559dd8b0e..baff71aaa26 100644 --- a/client/examples/clientTest.cpp +++ b/client/examples/clientTest.cpp @@ -9,6 +9,7 @@ #include "mongo/client/dbclient.h" using namespace std; +using namespace mongo; int main(){ diff --git a/client/examples/first.cpp b/client/examples/first.cpp index 2fef4fa0710..3d2dd32f0b0 100644 --- a/client/examples/first.cpp +++ b/client/examples/first.cpp @@ -9,6 +9,7 @@ #include "mongo/client/dbclient.h" using namespace std; +using namespace mongo; void insert( DBClientConnection & conn , const char * name , int num ){ BSONObjBuilder obj; diff --git a/client/examples/second.cpp b/client/examples/second.cpp index c36c7b281c5..e1bd8d4737f 100644 --- a/client/examples/second.cpp +++ b/client/examples/second.cpp @@ -5,6 +5,7 @@ #include "mongo/client/dbclient.h" using namespace std; +using namespace mongo; int main(){ diff --git a/client/model.cpp b/client/model.cpp index aa4d756e055..19860d8b963 100644 --- a/client/model.cpp +++ b/client/model.cpp @@ -19,6 +19,8 @@ #include "stdafx.h" #include "model.h" +namespace mongo { + bool Model::load(BSONObj& query) { BSONObj b = conn()->findOne(getNS(), query); if ( b.isEmpty() ) @@ -27,3 +29,5 @@ bool Model::load(BSONObj& query) { unserialize(b); return true; } + +} // namespace mongo diff --git a/client/model.h b/client/model.h index 5371c4b16b7..88723dce7ac 100644 --- a/client/model.h +++ b/client/model.h @@ -20,6 +20,8 @@ #include "dbclient.h" +namespace mongo { + /* Model is a base class for defining objects which are serializable to the Mongo database via the database driver. @@ -52,3 +54,5 @@ public: /* true if successful */ bool load(BSONObj& query); }; + +} // namespace mongo diff --git a/db/btree.cpp b/db/btree.cpp index c09f8b90c4f..3a68f6ec88a 100644 --- a/db/btree.cpp +++ b/db/btree.cpp @@ -20,6 +20,8 @@ #include "btree.h" #include "pdfile.h" +namespace mongo { + /* it is easy to do custom sizes for a namespace - all the same for now */ const int BucketSize = 8192; const int KeyMax = BucketSize / 10; @@ -808,3 +810,4 @@ void BtreeBucket::shape(stringstream& ss) { _shape(0, ss); } +} // namespace mongo diff --git a/db/btree.h b/db/btree.h index b1f9abb4bb4..c05955c776f 100644 --- a/db/btree.h +++ b/db/btree.h @@ -23,6 +23,8 @@ #include "storage.h" #include "pdfile.h" +namespace mongo { + #pragma pack(push,1) struct _KeyNode { @@ -266,3 +268,5 @@ private: }; #pragma pack(pop) + +} // namespace mongo; diff --git a/db/btreecursor.cpp b/db/btreecursor.cpp index 3e568e273e5..18ce967af97 100644 --- a/db/btreecursor.cpp +++ b/db/btreecursor.cpp @@ -21,6 +21,8 @@ #include "pdfile.h" #include "jsobj.h" +namespace mongo { + extern int otherTraceLevel; DiskLoc maxDiskLoc(0x7fffffff, 0x7fffffff); @@ -229,3 +231,5 @@ struct BtreeUnitTest { assert( minDiskLoc.compare(maxDiskLoc) < 0 ); } } btut; + +} // namespace mongo diff --git a/db/clientcursor.cpp b/db/clientcursor.cpp index a26f08887ff..2ec0d7bfe97 100644 --- a/db/clientcursor.cpp +++ b/db/clientcursor.cpp @@ -28,6 +28,8 @@ #include <time.h> #include "db.h" +namespace mongo { + /* TODO: FIX cleanup of clientCursors when hit the end. (ntoreturn insufficient) */ CCById clientCursorsById; @@ -224,3 +226,5 @@ public: reg("intr.cursors"); } } _ciproto; + +} // namespace mongo diff --git a/db/clientcursor.h b/db/clientcursor.h index a99fe77692a..49d14ecdae0 100644 --- a/db/clientcursor.h +++ b/db/clientcursor.h @@ -26,6 +26,8 @@ #include "../stdafx.h" +namespace mongo { + typedef long long CursorId; class Cursor; class ClientCursor; @@ -86,3 +88,5 @@ public: void cleanupByLocation(DiskLoc loc); }; + +} // namespace mongo diff --git a/db/cloner.cpp b/db/cloner.cpp index 7625ba273b6..3f406f614a9 100644 --- a/db/cloner.cpp +++ b/db/cloner.cpp @@ -27,6 +27,8 @@ #include "instance.h" #include "repl.h" +namespace mongo { + void ensureHaveIdIndex(const char *ns); extern int port; @@ -263,3 +265,5 @@ public: return res; } } cmdcopydb; + +} // namespace mongo diff --git a/db/commands.cpp b/db/commands.cpp index 7e5aa65cc8e..b61c149b947 100644 --- a/db/commands.cpp +++ b/db/commands.cpp @@ -21,6 +21,8 @@ #include "jsobj.h" #include "commands.h" +namespace mongo { + map<string,Command*> *commands; Command::Command(const char *_name) : name(_name) { @@ -66,3 +68,5 @@ bool runCommandAgainstRegistered(const char *ns, BSONObj& jsobj, BSONObjBuilder& return false; } + +} // namespace mongo diff --git a/db/commands.h b/db/commands.h index 0c2a54a0dd7..e0719a7e00d 100644 --- a/db/commands.h +++ b/db/commands.h @@ -17,6 +17,8 @@ #pragma once +namespace mongo { + class BSONObj; class BSONObjBuilder; @@ -59,3 +61,5 @@ public: }; bool runCommandAgainstRegistered(const char *ns, BSONObj& jsobj, BSONObjBuilder& anObjBuilder); + +} // namespace mongo diff --git a/db/cursor.cpp b/db/cursor.cpp index b9523c09268..ff0d132800a 100644 --- a/db/cursor.cpp +++ b/db/cursor.cpp @@ -16,6 +16,8 @@ #include "pdfile.h" +namespace mongo { + class Forward : public AdvanceStrategy { virtual DiskLoc next( const DiskLoc &prev ) const { return prev.rec()->getNext( prev ); @@ -127,4 +129,5 @@ DiskLoc ReverseCappedCursor::next( const DiskLoc &prev ) const { i = reverse()->next( nsd->capFirstNewRecord ); return i; -}
\ No newline at end of file +} +} // namespace mongo diff --git a/db/cursor.h b/db/cursor.h index 18926902631..cdbbfffc79b 100644 --- a/db/cursor.h +++ b/db/cursor.h @@ -18,6 +18,8 @@ #include "../stdafx.h" +namespace mongo { + /* Query cursors, base class. This is for our internal cursors. "ClientCursor" is a separate concept and is for the user's cursor. */ @@ -197,3 +199,5 @@ public: private: NamespaceDetails *nsd; }; + +} // namespace mongo diff --git a/db/database.h b/db/database.h index d15b61815ab..32e92bb76a9 100644 --- a/db/database.h +++ b/db/database.h @@ -22,6 +22,8 @@ Each database database has its own set of files -- dbname.ns, dbname.0, dbname.1, ... */ +namespace mongo { + class Database { public: Database(const char *nm, bool& justCreated, const char *_path = dbpath) : @@ -128,3 +130,4 @@ private: bool _haveLogged; }; +} // namespace mongo diff --git a/db/db.cpp b/db/db.cpp index cf350dd1421..cce208374fa 100644 --- a/db/db.cpp +++ b/db/db.cpp @@ -27,6 +27,8 @@ #include "dbmessage.h" #include "instance.h" +namespace mongo { + extern bool objcheck, quiet, quota, verbose, cpu; bool useJNI = true; @@ -138,9 +140,13 @@ public: Message & container; }; +} // namespace mongo + #include "lasterror.h" #include "security.h" +namespace mongo { + /* we create one thread for each connection from an app server database. app server will open a pool of threads. */ @@ -322,6 +328,10 @@ int test2(); void testClient(); void pipeSigHandler( int signal ); +} // namespace mongo + +using namespace mongo; + int main(int argc, char* argv[], char *envp[] ) { srand(curTimeMillis()); @@ -506,6 +516,8 @@ usage: return 0; } +namespace mongo { + /* we do not use log() below as it uses a mutex and that could cause deadlocks. */ @@ -515,8 +527,12 @@ string getDbContext(); #if !defined(_WIN32) +} // namespace mongo + #include <signal.h> +namespace mongo { + void pipeSigHandler( int signal ) { psignal( signal, "Signal Received : "); } @@ -557,3 +573,5 @@ void setupSignals() { #else void setupSignals() {} #endif + +} // namespace mongo @@ -19,6 +19,8 @@ #include "../stdafx.h" #include "../grid/message.h" +namespace mongo { + void jniCallback(Message& m, Message& out); class MutexInfo { @@ -71,8 +73,12 @@ struct dblock : public lock { } }; +} // namespace mongo + #include "boost/version.hpp" +namespace mongo { + /* a scoped release of a mutex temporarily -- like a scopedlock but reversed. */ struct temprelease { @@ -93,8 +99,12 @@ struct temprelease { } }; +} // namespace mongo + #include "pdfile.h" +namespace mongo { + // tempish...move to TLS or pass all the way down as a parm extern map<string,Database*> databases; extern Database *database; @@ -190,4 +200,6 @@ struct dbtemprelease { } }; +} // namespace mongo + #include "dbinfo.h" diff --git a/db/dbcommands.cpp b/db/dbcommands.cpp index df313a15fc8..dc6f7dcb206 100644 --- a/db/dbcommands.cpp +++ b/db/dbcommands.cpp @@ -32,6 +32,8 @@ #include "instance.h" #include "lasterror.h" +namespace mongo { + extern bool quiet; extern int queryTraceLevel; extern int otherTraceLevel; @@ -147,7 +149,7 @@ string validateNS(const char *ns, NamespaceDetails *d) { valid = false; } } - ss << " deleted: n: " << ndel << " size: " << delSize << '\n'; + ss << " deleted: n: " << ndel << " size: " << delSize << endl; if ( incorrect ) { ss << " ?corrupt: " << incorrect << " records from datafile are in deleted list\n"; valid = false; @@ -709,3 +711,4 @@ bool _runCommands(const char *ns, BSONObj& _cmdobj, stringstream& ss, BufBuilder return true; } +} // namespace mongo diff --git a/db/dbeval.cpp b/db/dbeval.cpp index 5ca69eee6e0..3620211e6f7 100644 --- a/db/dbeval.cpp +++ b/db/dbeval.cpp @@ -31,6 +31,8 @@ #include "repl.h" #include "commands.h" +namespace mongo { + const int edebug=0; bool dbEval(const char *ns, BSONObj& cmd, BSONObjBuilder& result, string& errmsg) { @@ -78,7 +80,7 @@ bool dbEval(const char *ns, BSONObj& cmd, BSONObjBuilder& result, string& errmsg res = s.invoke(f); int m = t.millis(); if ( m > 100 ) { - stdcout() << "TEMP: dbeval too slow:" << endl; + stdcout() << "TEMP: dbeval too slow:" << endl; problem() << "dbeval time: " << dec << m << "ms " << ns << endl; OCCASIONALLY log() << code << endl; else if ( m >= 1000 ) log() << code << endl; @@ -115,3 +117,5 @@ public: return dbEval(ns, cmdObj, result, errmsg); } } cmdeval; + +} // namespace mongo diff --git a/db/dbhelpers.cpp b/db/dbhelpers.cpp index 21ceb981bcc..6616fd14314 100644 --- a/db/dbhelpers.cpp +++ b/db/dbhelpers.cpp @@ -21,6 +21,8 @@ #include "dbhelpers.h" #include "query.h" +namespace mongo { + /* Get the first object from a collection. Generally only useful if the collection only ever has a single object -- which is a "singleton collection. @@ -47,3 +49,5 @@ void emptyCollection(const char *ns) { DBContext context(ns); deleteObjects(ns, emptyObj, false); } + +} // namespace mongo diff --git a/db/dbhelpers.h b/db/dbhelpers.h index 9464e162c6e..c10689d8b04 100644 --- a/db/dbhelpers.h +++ b/db/dbhelpers.h @@ -22,6 +22,8 @@ #pragma once +namespace mongo { + /* Get/put the first object from a collection. Generally only useful if the collection only ever has a single object -- which is a "singleton collection". @@ -57,3 +59,5 @@ public: database = old; } }; + +} // namespace mongo diff --git a/db/dbinfo.cpp b/db/dbinfo.cpp index 79cbea23bc7..20396d3170c 100644 --- a/db/dbinfo.cpp +++ b/db/dbinfo.cpp @@ -19,6 +19,8 @@ #include "stdafx.h" #include "db.h" +namespace mongo { + void DBInfo::setHaveLogged() { if ( haveLogged() ) return; @@ -43,3 +45,5 @@ void DBInfo::dbDropped() { */ } + +} // namespace mongo diff --git a/db/dbinfo.h b/db/dbinfo.h index cfd16d64b1f..e78776b8de7 100644 --- a/db/dbinfo.h +++ b/db/dbinfo.h @@ -18,6 +18,8 @@ #pragma once +namespace mongo { + /* this is an "accessor" class to data held in local.dbinfo.<dbname> system.dbinfo contains: @@ -70,3 +72,5 @@ inline void Database::finishInit() { DBInfo i(name.c_str()); _haveLogged = i.haveLogged(); } + +} // namespace mongo diff --git a/db/dbmessage.h b/db/dbmessage.h index d3edd160b6f..9bbd989d2b1 100644 --- a/db/dbmessage.h +++ b/db/dbmessage.h @@ -18,6 +18,8 @@ #include "jsobj.h" #include "namespace.h" +namespace mongo { + /* For the database/server protocol, these objects and functions encapsulate the various messages transmitted over the connection. */ @@ -121,8 +123,12 @@ public: } }; +} // namespace mongo + #include "../client/dbclient.h" +namespace mongo { + inline void replyToQuery(int queryResultFlags, MessagingPort& p, Message& requestMsg, void *data, int size, @@ -145,8 +151,12 @@ inline void replyToQuery(int queryResultFlags, p.reply(requestMsg, *resp, requestMsg.data->id); } +} // namespace mongo + //#include "bsonobj.h" +namespace mongo { + inline void replyToQuery(int queryResultFlags, MessagingPort& p, Message& requestMsg, BSONObj& responseObj) @@ -155,3 +165,5 @@ inline void replyToQuery(int queryResultFlags, p, requestMsg, (void *) responseObj.objdata(), responseObj.objsize(), 1); } + +} // namespace mongo diff --git a/db/dbwebserver.cpp b/db/dbwebserver.cpp index 8b3844e2f73..eaa7128cefd 100644 --- a/db/dbwebserver.cpp +++ b/db/dbwebserver.cpp @@ -23,6 +23,8 @@ #include "replset.h" #include "instance.h" +namespace mongo { + extern int port; extern const char *replInfo; @@ -366,3 +368,5 @@ void webServerThread() { if ( mini.init(port+1000) ) mini.run(); } + +} // namespace mongo diff --git a/db/flushtest.cpp b/db/flushtest.cpp index 41a49e6ab74..64911a7e9a3 100644 --- a/db/flushtest.cpp +++ b/db/flushtest.cpp @@ -3,6 +3,8 @@ #include "../util/goodies.h" #include <fcntl.h> +namespace mongo { + // logstream defines these, we don't want that: #undef cout #undef endl @@ -128,3 +130,5 @@ int main(int argc, char* argv[], char *envp[] ) { return 0; } + +} // namespace mongo diff --git a/db/instance.cpp b/db/instance.cpp index 81a261e9d29..d3a18daae2c 100644 --- a/db/instance.cpp +++ b/db/instance.cpp @@ -26,6 +26,8 @@ #include "instance.h" #include "lasterror.h" +namespace mongo { + int nloggedsome = 0; #define LOGSOME if( ++nloggedsome < 1000 || nloggedsome % 100 == 0 ) @@ -520,3 +522,5 @@ void dbexit(int rc, const char *why) { exit(rc); } + +} // namespace mongo diff --git a/db/instance.h b/db/instance.h index ce7e23d9d6d..28f90171392 100644 --- a/db/instance.h +++ b/db/instance.h @@ -19,6 +19,8 @@ #pragma once +namespace mongo { + // turn on or off the oplog.* files which the db can generate. // these files are for diagnostic purposes and are unrelated to // local.oplog.$main used by replication. @@ -99,3 +101,5 @@ class DBDirectClient : public DBClientBase { return say( toSend ); } }; + +} // namespace mongo diff --git a/db/introspect.cpp b/db/introspect.cpp index cd2394c3242..d78bb68e59c 100644 --- a/db/introspect.cpp +++ b/db/introspect.cpp @@ -24,6 +24,8 @@ #include "jsobj.h" #include "pdfile.h" +namespace mongo { + typedef map<string,Cursor*> StringToCursor; StringToCursor *specialNamespaces; @@ -53,3 +55,5 @@ void profile(const char *str, theDataFileMgr.insert(database->profileName.c_str(), p.objdata(), p.objsize(), true); } + +} // namespace mongo diff --git a/db/introspect.h b/db/introspect.h index 71da3cefbb3..4046243fe0e 100644 --- a/db/introspect.h +++ b/db/introspect.h @@ -23,6 +23,8 @@ #include "jsobj.h" #include "pdfile.h" +namespace mongo { + auto_ptr<Cursor> getSpecialCursor(const char *ns); class SingleResultObjCursor : public Cursor { @@ -71,3 +73,5 @@ public: void profile(const char *str, int millis); + +} // namespace mongo diff --git a/db/javajs.cpp b/db/javajs.cpp index 54c4a161e90..b508d8da7cc 100644 --- a/db/javajs.cpp +++ b/db/javajs.cpp @@ -23,6 +23,8 @@ using namespace boost::filesystem; +namespace mongo { + //#define JNI_DEBUG 1 #ifdef JNI_DEBUG @@ -33,7 +35,7 @@ using namespace boost::filesystem; #define JNI_DEBUG(x) #endif - +} // namespace mongo #ifdef J_USE_OBJ #include "jsobj.h" @@ -44,6 +46,8 @@ using namespace boost::filesystem; using namespace std; +namespace mongo { + #if defined(_WIN32) /* [dm] this being undefined without us adding it here means there is no tss cleanup on windows for boost lib? @@ -627,7 +631,7 @@ int javajstest() { const int debug = 0; - JavaJSImpl& JavaJS = *::JavaJS; + JavaJSImpl& JavaJS = *mongo::JavaJS; if ( debug ) log() << "about to create scope" << endl; jlong scope = JavaJS.scopeCreate(); @@ -718,6 +722,8 @@ int javajstest() { } +} // namespace mongo + #if defined(_MAIN) int main() { return javajstest(); @@ -725,3 +731,4 @@ int main() { #endif #endif + diff --git a/db/javajs.h b/db/javajs.h index a57db1251a4..6f36475ecbb 100644 --- a/db/javajs.h +++ b/db/javajs.h @@ -35,6 +35,8 @@ #include "jsobj.h" +namespace mongo { + void jasserted(const char *msg, const char *file, unsigned line); #define jassert(_Expression) if ( ! ( _Expression ) ){ jasserted(#_Expression, __FILE__, __LINE__); } @@ -202,3 +204,5 @@ public: JNIEXPORT void JNICALL java_native_say(JNIEnv *, jclass, jobject outBuffer ); JNIEXPORT jint JNICALL java_native_call(JNIEnv *, jclass, jobject outBuffer , jobject inBuffer ); + +} // namespace mongo diff --git a/db/jsobj.cpp b/db/jsobj.cpp index 80184501bdd..9a4e7dcbc71 100644 --- a/db/jsobj.cpp +++ b/db/jsobj.cpp @@ -22,6 +22,8 @@ #include <limits> #include "../util/unittest.h" +namespace mongo { + BSONElement nullElement; ostream& operator<<( ostream &s, const OID &o ) { @@ -175,7 +177,7 @@ string BSONElement::jsonString( JsonStringFormat format, bool includeFieldNames s << number(); } else { stringstream ss; - ss << "Number " << number() << " cannot be represented in JSON" << endl; + ss << "Number " << number() << " cannot be represented in JSON"; string message = ss.str(); massert( message.c_str(), false ); } @@ -285,8 +287,7 @@ string BSONElement::jsonString( JsonStringFormat format, bool includeFieldNames default: stringstream ss; ss << "Cannot create a properly formatted JSON string with " - << "element: " << toString() << " of type: " << type() - << endl; + << "element: " << toString() << " of type: " << type(); string message = ss.str(); massert( message.c_str(), false ); } @@ -897,3 +898,5 @@ BSONObjBuilder& BSONObjBuilderValueStream::operator<<( const double value ){ return *_builder; } + +} // namespace mongo diff --git a/db/jsobj.h b/db/jsobj.h index cef9c7b796a..8f9c8b0e261 100644 --- a/db/jsobj.h +++ b/db/jsobj.h @@ -30,6 +30,8 @@ #include <set> +namespace mongo { + class BSONObj; class Record; class BSONObjBuilder; @@ -765,8 +767,12 @@ public: }; */ +} // namespace mongo + #include "matcher.h" +namespace mongo { + extern BSONObj maxKey; extern BSONObj minKey; @@ -869,3 +875,5 @@ inline void BSONObj::validateEmpty() { *this = emptyObj; } + +} // namespace mongo diff --git a/db/json.cpp b/db/json.cpp index 0debde27fa8..24ea7e8d16f 100644 --- a/db/json.cpp +++ b/db/json.cpp @@ -22,6 +22,8 @@ using namespace boost::spirit; +namespace mongo { + struct ObjectBuilder { BSONObjBuilder *back() { return builders.back().get(); } // Storage for field names of elements within builders.back(). @@ -491,3 +493,5 @@ BSONObj fromjson( const char *str ) { BSONObj fromjson( const string &str ) { return fromjson( str.c_str() ); } + +} // namespace mongo diff --git a/db/json.h b/db/json.h index f2bc1557d17..6c09f5f62fa 100644 --- a/db/json.h +++ b/db/json.h @@ -21,5 +21,9 @@ #include "../stdafx.h" #include "jsobj.h" +namespace mongo { + BSONObj fromjson(const char *str); BSONObj fromjson(const string &str); + +} // namespace mongo diff --git a/db/lasterror.cpp b/db/lasterror.cpp index a3f33cd5703..9fc0c3fa83d 100644 --- a/db/lasterror.cpp +++ b/db/lasterror.cpp @@ -3,4 +3,8 @@ #include "stdafx.h"
#include "lasterror.h"
+namespace mongo {
+
boost::thread_specific_ptr<LastError> lastError;
+
+} // namespace mongo
diff --git a/db/lasterror.h b/db/lasterror.h index 6030cb9e19b..8f5b59c55b0 100644 --- a/db/lasterror.h +++ b/db/lasterror.h @@ -19,6 +19,8 @@ #pragma once
#include <boost/thread/tss.hpp>
+ +namespace mongo { struct LastError {
string msg;
@@ -42,3 +44,5 @@ inline void raiseError(const char *msg) { }
le->raiseError(msg);
}
+ +} // namespace mongo diff --git a/db/matcher.cpp b/db/matcher.cpp index e95149208bf..ee36ea4daea 100644 --- a/db/matcher.cpp +++ b/db/matcher.cpp @@ -24,11 +24,17 @@ #include "javajs.h" #include "../util/unittest.h" +namespace mongo { + #if defined(_WIN32) +} // namespace mongo + #include <hash_map> using namespace stdext; +namespace mongo { + typedef const char * MyStr; struct less_str { bool operator()(const MyStr & x, const MyStr & y) const { @@ -43,7 +49,12 @@ typedef hash_map<const char*, int, hash_compare<const char *, less_str> > strhas #else +} // namespace mongo + #include <ext/hash_map> + +namespace mongo { + using namespace __gnu_cxx; typedef const char * MyStr; @@ -96,8 +107,12 @@ JSMatcher::~JSMatcher() { delete where; } +} // namespace mongo + #include "pdfile.h" +namespace mongo { + /* _jsobj - the query pattern indexKeyPattern - the "key pattern" / template of what is in the keys of the index we are using. used to set indexMatches return value from matches() @@ -527,3 +542,5 @@ struct RXTest : public UnitTest { assert( part.PartialMatch("dwight") ); } } rxtest; + +} // namespace mongo diff --git a/db/matcher.h b/db/matcher.h index 18b7d440bb1..555a9a96b6b 100644 --- a/db/matcher.h +++ b/db/matcher.h @@ -22,6 +22,8 @@ #include <pcrecpp.h> +namespace mongo { + class RegexMatcher { public: const char *fieldName; @@ -132,3 +134,5 @@ private: bool checkInIndex; }; + +} // namespace mongo diff --git a/db/minilex.h b/db/minilex.h index 4520d1e7ddf..1d2b774f9bf 100644 --- a/db/minilex.h +++ b/db/minilex.h @@ -17,6 +17,8 @@ * along with this program. If not, see <http://www.gnu.org/licenses/>. */ +namespace mongo { + struct MiniLex { strhashmap reserved; bool ic[256]; // ic=Identifier Character @@ -109,3 +111,5 @@ struct MiniLex { reserved["with "] = true; } }; + +} // namespace mongo diff --git a/db/namespace.cpp b/db/namespace.cpp index d637cb38ba6..33ee30b9af3 100644 --- a/db/namespace.cpp +++ b/db/namespace.cpp @@ -26,6 +26,8 @@ #include <list> #include "query.h" +namespace mongo { + /* deleted lists -- linked lists of deleted records -- tehy are placed in 'buckets' of various sizes so you can look for a deleterecord about the right size. */ @@ -539,3 +541,4 @@ void addNewNamespaceToCatalog(const char *ns, BSONObj *options = 0) { } } +} // namespace mongo diff --git a/db/namespace.h b/db/namespace.h index 29811cda923..3509133a8b9 100644 --- a/db/namespace.h +++ b/db/namespace.h @@ -26,6 +26,8 @@ #include "../util/hashtab.h" #include "../util/mmap.h" +namespace mongo { + class Cursor; #pragma pack(push,1) @@ -382,3 +384,5 @@ inline string nsToClient(const char *ns) { nsToClient(ns, buf); return buf; } + +} // namespace mongo diff --git a/db/pdfile.cpp b/db/pdfile.cpp index 3fe3516d060..ccf5806784c 100644 --- a/db/pdfile.cpp +++ b/db/pdfile.cpp @@ -35,6 +35,8 @@ _ disallow system* manipulations from the database. #include "query.h" #include "repl.h" +namespace mongo { + extern bool quota; extern int port; @@ -993,8 +995,12 @@ void pdfileInit() { theDataFileMgr.init(dbpath); } +} // namespace mongo + #include "clientcursor.h" +namespace mongo { + void dropDatabase(const char *ns) { // ns is of the form "<dbname>.$cmd" char cl[256]; @@ -1080,7 +1086,9 @@ boost::intmax_t dbSize( const char *database ) { } #if !defined(_WIN32) +} // namespace mongo #include <sys/statvfs.h> +namespace mongo { #endif boost::intmax_t freeSpace() { #if !defined(_WIN32) @@ -1147,3 +1155,5 @@ bool repairDatabase( const char *ns, string &errmsg, return true; } + +} // namespace mongo diff --git a/db/pdfile.h b/db/pdfile.h index a3e20a56e35..92186920f79 100644 --- a/db/pdfile.h +++ b/db/pdfile.h @@ -25,16 +25,18 @@ #pragma once -// see version, versionMinor, below. -const int VERSION = 4; -const int VERSION_MINOR = 4; - #include "../stdafx.h" #include "../util/mmap.h" #include "storage.h" #include "jsobj.h" #include "namespace.h" +// see version, versionMinor, below. +const int VERSION = 4; +const int VERSION_MINOR = 4; + +namespace mongo { + class PDFHeader; class Extent; class Record; @@ -282,8 +284,12 @@ inline Extent* PhysicalDataFile::getExtent(DiskLoc loc) { return e; } +} // namespace mongo + #include "cursor.h" +namespace mongo { + inline Record* PhysicalDataFile::recordAt(DiskLoc dl) { return header->getRecord(dl); } @@ -339,9 +345,13 @@ inline BtreeBucket* DiskLoc::btree() const { /*---------------------------------------------------------------------*/ +} // namespace mongo + #include "queryoptimizer.h" #include "database.h" +namespace mongo { + #define BOOST_CHECK_EXCEPTION( expression ) \ try { \ expression; \ @@ -434,3 +444,5 @@ inline Record* DataFileMgr::getRecord(const DiskLoc& dl) { assert( dl.a() != -1 ); return database->getFile(dl.a())->recordAt(dl); } + +} // namespace mongo diff --git a/db/query.cpp b/db/query.cpp index b32598e1262..f38fae6824c 100644 --- a/db/query.cpp +++ b/db/query.cpp @@ -31,6 +31,8 @@ #include "replset.h" #include "scanandorder.h" +namespace mongo { + /* We cut off further objects once we cross this threshold; thus, you might get a little bit more than this, it is a threshold rather than a limit. */ @@ -884,3 +886,5 @@ QueryResult* getMore(const char *ns, int ntoreturn, long long cursorid) { return qr; } + +} // namespace mongo diff --git a/db/query.h b/db/query.h index 9509447056e..4a121b8c1d7 100644 --- a/db/query.h +++ b/db/query.h @@ -66,6 +66,8 @@ // struct QueryOptions, QueryResult, QueryResultFlags in: #include "../client/dbclient.h" +namespace mongo { + // for an existing query (ie a ClientCursor), send back additional information. QueryResult* getMore(const char *ns, int ntoreturn, long long cursorid); @@ -78,4 +80,6 @@ void updateObjects(const char *ns, BSONObj updateobj, BSONObj pattern, bool upse int deleteObjects(const char *ns, BSONObj pattern, bool justOne, bool god=false); +} // namespace mongo + #include "clientcursor.h" diff --git a/db/queryoptimizer.cpp b/db/queryoptimizer.cpp index 88e930b50bd..9393796c29b 100644 --- a/db/queryoptimizer.cpp +++ b/db/queryoptimizer.cpp @@ -30,6 +30,8 @@ #include "scanandorder.h" #include "queryoptimizer.h" +namespace mongo { + QueryPlan QueryOptimizer::getPlan( const char *ns, BSONObj* query, @@ -42,3 +44,5 @@ QueryPlan QueryOptimizer::getPlan( return plan; } + +} // namespace mongo diff --git a/db/queryoptimizer.h b/db/queryoptimizer.h index 3c41928e7e3..c00b00bea72 100644 --- a/db/queryoptimizer.h +++ b/db/queryoptimizer.h @@ -18,6 +18,8 @@ #pragma once +namespace mongo { + class QueryPlan { public: QueryPlan() { @@ -47,3 +49,5 @@ public: BSONObj* order = 0, BSONObj* hint = 0); }; + +} // namespace mongo diff --git a/db/repl.cpp b/db/repl.cpp index 1a6bef00872..2a2b7e5f6b3 100644 --- a/db/repl.cpp +++ b/db/repl.cpp @@ -45,6 +45,8 @@ #include "db.h" #include "commands.h" +namespace mongo { + extern bool quiet; extern boost::mutex dbMutex; extern long long oplogSize; @@ -65,8 +67,12 @@ bool replacePeer = false; */ const char *allDead = 0; +} // namespace mongo + #include "replset.h" +namespace mongo { + #define debugrepl(z) log() << "debugrepl " << z << '\n' //define debugrepl @@ -1185,3 +1191,5 @@ void startReplication() { void pairWith(const char *remoteEnd, const char *arb) { replPair = new ReplPair(remoteEnd, arb); } + +} // namespace mongo diff --git a/db/repl.h b/db/repl.h index f2baeb29a4a..b8b2d4417f1 100644 --- a/db/repl.h +++ b/db/repl.h @@ -30,6 +30,8 @@ #include "../client/dbclient.h" +namespace mongo { + class DBClientConnection; class DBClientCursor; extern bool slave; @@ -182,3 +184,5 @@ inline void logOp(const char *opstr, const char *ns, BSONObj& obj, BSONObj *patt if ( master ) _logOp(opstr, ns, obj, patt, b); } + +} // namespace mongo diff --git a/db/replset.h b/db/replset.h index 1cc720a4d69..7ba3978d43b 100644 --- a/db/replset.h +++ b/db/replset.h @@ -21,6 +21,8 @@ #include "json.h" #include "../client/dbclient.h" +namespace mongo { + extern int port; extern const char *allDead; @@ -173,3 +175,5 @@ public: } }; + +} // namespace mongo diff --git a/db/resource.h b/db/resource.h index f22354edac9..59b9f5c3cb8 100644 --- a/db/resource.h +++ b/db/resource.h @@ -18,6 +18,8 @@ * along with this program. If not, see <http://www.gnu.org/licenses/>. */ +namespace mongo { + // Next default values for new objects // #ifdef APSTUDIO_INVOKED @@ -28,3 +30,5 @@ #define _APS_NEXT_SYMED_VALUE 101 #endif #endif + +} // namespace mongo diff --git a/db/scanandorder.h b/db/scanandorder.h index 30f27e08ddd..695672b7682 100644 --- a/db/scanandorder.h +++ b/db/scanandorder.h @@ -20,6 +20,8 @@ #pragma once +namespace mongo { + /* todo: _ handle compound keys with differing directions. we don't handle this yet: neither here nor in indexes i think!!! _ limit amount of data @@ -135,3 +137,5 @@ done: } }; + +} // namespace mongo diff --git a/db/security.cpp b/db/security.cpp index c3921d7ac51..3d78bfe6921 100644 --- a/db/security.cpp +++ b/db/security.cpp @@ -4,6 +4,8 @@ #include "security.h"
#include "../util/md5.hpp" +namespace mongo { + extern "C" int do_md5_test(void); boost::thread_specific_ptr<AuthenticationInfo> authInfo;
@@ -37,8 +39,12 @@ struct Security { }
} security;
+} // namespace mongo + #include "commands.h"
#include "jsobj.h"
+ +namespace mongo { class CmdGetNonce : public Command { public: @@ -61,3 +67,5 @@ public: } } cmdAuthenticate; + +} // namespace mongo diff --git a/db/security.h b/db/security.h index c52096a510f..9526a9af1ad 100644 --- a/db/security.h +++ b/db/security.h @@ -19,6 +19,8 @@ #pragma once
#include <boost/thread/tss.hpp>
+ +namespace mongo { class AuthenticationInfo : boost::noncopyable {
public:
@@ -29,3 +31,5 @@ public: };
extern boost::thread_specific_ptr<AuthenticationInfo> authInfo;
+ + } // namespace mongo diff --git a/db/storage.h b/db/storage.h index bef78e1473c..64aaf776e3d 100644 --- a/db/storage.h +++ b/db/storage.h @@ -22,6 +22,8 @@ #pragma once +namespace mongo { + #pragma pack(push,1) class Record; @@ -143,3 +145,5 @@ public: }; #pragma pack(pop) + +} // namespace mongo diff --git a/db/tests.cpp b/db/tests.cpp index 9dbbb632d3d..a26487e52a7 100644 --- a/db/tests.cpp +++ b/db/tests.cpp @@ -22,6 +22,8 @@ #include "stdafx.h" #include "../util/mmap.h" +namespace mongo { + int test2_old() { cout << "test2" << endl; printStackTrace(); @@ -61,3 +63,5 @@ int test2_old() { return 1; } + +} // namespace mongo diff --git a/dbgrid/dbgrid.cpp b/dbgrid/dbgrid.cpp index 9974e44859a..06b519b5001 100644 --- a/dbgrid/dbgrid.cpp +++ b/dbgrid/dbgrid.cpp @@ -22,6 +22,8 @@ #include "../client/connpool.h" #include "gridconfig.h" +namespace mongo { + bool dashDashInfer = false; vector<string> dashDashGridDb; int port = 27017; @@ -34,8 +36,12 @@ string getDbContext() { #if !defined(_WIN32) +} // namespace mongo + #include <signal.h> +namespace mongo { + void pipeSigHandler( int signal ) { psignal( signal, "Signal Received : "); } @@ -124,6 +130,10 @@ void start() { l.listen(); } +} // namespace mongo + +using namespace mongo; + int main(int argc, char* argv[], char *envp[] ) { #if !defined(_WIN32) signal(SIGPIPE, pipeSigHandler); @@ -179,8 +189,12 @@ int main(int argc, char* argv[], char *envp[] ) { return 0; } +namespace mongo { + #undef exit void dbexit(int rc, const char *why) { log() << "dbexit: " << why << " rc:" << rc << endl; exit(rc); } + +} // namespace mongo diff --git a/dbgrid/dbgrid_commands.cpp b/dbgrid/dbgrid_commands.cpp index 9cbf13a2136..fa62f299f1b 100644 --- a/dbgrid/dbgrid_commands.cpp +++ b/dbgrid/dbgrid_commands.cpp @@ -36,6 +36,8 @@ #include "../db/commands.h" #include "gridconfig.h" +namespace mongo { + extern string ourHostname; namespace dbgrid_cmds { @@ -80,3 +82,5 @@ public: } ismaster; } + +} // namespace mongo diff --git a/dbgrid/gridconfig.cpp b/dbgrid/gridconfig.cpp index 1cfa82d0564..5f6e90121e1 100644 --- a/dbgrid/gridconfig.cpp +++ b/dbgrid/gridconfig.cpp @@ -24,6 +24,8 @@ #include "gridconfig.h" #include "../client/model.h" +namespace mongo { + /* --- Machine --- */ map<string, Machine*> Machine::machines; @@ -63,3 +65,5 @@ Machine* Grid::owner(const char *ns, BSONObj& objOrKey) { uassert("dbgrid: not implemented 100", false); return 0; } + +} // namespace mongo diff --git a/dbgrid/gridconfig.h b/dbgrid/gridconfig.h index 8864951d070..54fce505517 100644 --- a/dbgrid/gridconfig.h +++ b/dbgrid/gridconfig.h @@ -27,6 +27,8 @@ #include "../client/model.h" #include "griddatabase.h" +namespace mongo { + /* Machine is the concept of a host that runs the db process. */ class Machine { @@ -103,3 +105,5 @@ public: }; extern Grid grid; + +} // namespace mongo diff --git a/dbgrid/griddatabase.cpp b/dbgrid/griddatabase.cpp index f403e466332..dcb8c957ad9 100644 --- a/dbgrid/griddatabase.cpp +++ b/dbgrid/griddatabase.cpp @@ -25,6 +25,8 @@ #include "../util/background.h" #include "griddatabase.h" +namespace mongo { + static boost::mutex griddb_mutex; GridDatabase gridDatabase; DBClientWithCommands *Model::globalConn = gridDatabase.conn; @@ -143,3 +145,5 @@ void GridDatabase::init() { l << "ok" << endl; } } + +} // namespace mongo diff --git a/dbgrid/griddatabase.h b/dbgrid/griddatabase.h index 4e88c4b03cc..5b274234d77 100644 --- a/dbgrid/griddatabase.h +++ b/dbgrid/griddatabase.h @@ -25,6 +25,8 @@ #include "shard.h" +namespace mongo { + class GridDatabase { public: DBClientWithCommands *conn; @@ -41,3 +43,5 @@ public: }; extern GridDatabase gridDatabase; + +} // namespace mongo diff --git a/dbgrid/request.cpp b/dbgrid/request.cpp index 9ae86caafa0..3b13ec2a59e 100644 --- a/dbgrid/request.cpp +++ b/dbgrid/request.cpp @@ -41,6 +41,8 @@ #include "../db/dbmessage.h" #include "../client/connpool.h" +namespace mongo { + const char *tempHost = "localhost:27018"; void getMore(Message& m, MessagingPort& p) { @@ -129,3 +131,5 @@ void processRequest(Message& m, MessagingPort& p) { writeOp(op, m, p); } } + +} // namespace mongo diff --git a/dbgrid/shard.cpp b/dbgrid/shard.cpp index 72958c0c289..97aed9e4b20 100644 --- a/dbgrid/shard.cpp +++ b/dbgrid/shard.cpp @@ -20,6 +20,8 @@ #include "shard.h" #include "griddatabase.h" +namespace mongo { + DBClientWithCommands* Shard::conn() { return gridDatabase.conn; } @@ -32,3 +34,5 @@ void Shard::unserialize(BSONObj& from) { name = from.getStringField("name"); uassert("bad grid.shards.name", !name.empty()); } + +} // namespace mongo diff --git a/dbgrid/shard.h b/dbgrid/shard.h index 2e49187ea38..00467322452 100644 --- a/dbgrid/shard.h +++ b/dbgrid/shard.h @@ -25,6 +25,8 @@ #include "../client/dbclient.h" #include "../client/model.h" +namespace mongo { + /* grid.shards { name: 'hostname' } @@ -40,3 +42,5 @@ public: virtual void unserialize(BSONObj& from); virtual DBClientWithCommands* conn(); }; + +} // namespace mongo diff --git a/dbtests/dbtests.cpp b/dbtests/dbtests.cpp index 26f3059c623..6cd51781782 100644 --- a/dbtests/dbtests.cpp +++ b/dbtests/dbtests.cpp @@ -25,7 +25,7 @@ using namespace std; -extern const char* dbpath; +extern const char* mongo::dbpath; string dbpathSpec = "/tmp/unittest/"; void usage() { diff --git a/dbtests/dbtests.h b/dbtests/dbtests.h index 105155a43c5..cfbf4b8ff85 100644 --- a/dbtests/dbtests.h +++ b/dbtests/dbtests.h @@ -19,6 +19,8 @@ #include <unittest/UnitTest.hpp> +using namespace mongo; + UnitTest::TestPtr btreeTests(); UnitTest::TestPtr jsobjTests(); UnitTest::TestPtr namespaceTests(); diff --git a/dbtests/pairingtests.cpp b/dbtests/pairingtests.cpp index 1794cb85dc0..d61febb0d53 100644 --- a/dbtests/pairingtests.cpp +++ b/dbtests/pairingtests.cpp @@ -22,7 +22,7 @@ #include "dbtests.h" #include "mockdbclient.h" -extern PairSync *pairSync; +extern PairSync *mongo::pairSync; namespace PairingTests { class Base { diff --git a/grid/message.cpp b/grid/message.cpp index 026959cd767..1af556e1aac 100644 --- a/grid/message.cpp +++ b/grid/message.cpp @@ -25,6 +25,8 @@ #include "../util/goodies.h" #include <fcntl.h> +namespace mongo { + // if you want trace output: #define mmm(x) @@ -152,8 +154,12 @@ MessagingPort::~MessagingPort() { ports.erase(this); } +} // namespace mongo + #include "../util/background.h" +namespace mongo { + class ConnectBG : public BackgroundJob { public: int sock; @@ -371,3 +377,5 @@ void MessagingPort::piggyBack( Message& toSend , int responseTo ){ piggyBackData->append( toSend ); } + +} // namespace mongo diff --git a/grid/message.h b/grid/message.h index 08a9c29840b..47a9c201b34 100644 --- a/grid/message.h +++ b/grid/message.h @@ -20,6 +20,8 @@ #include "../util/sock.h" +namespace mongo { + class Message; class MessagingPort; class PiggyBackData; @@ -174,3 +176,5 @@ public: private: bool freeIt; }; + +} // namespace mongo diff --git a/stdafx.cpp b/stdafx.cpp index b881d8a9a17..b4485e281f5 100644 --- a/stdafx.cpp +++ b/stdafx.cpp @@ -20,6 +20,8 @@ #include "stdafx.h" +namespace mongo { + // TODO: reference any additional headers you need in STDAFX.H // and not in this file @@ -28,9 +30,14 @@ Assertion lastAssert[4]; #undef assert #undef yassert + +} // namespace mongo + #include "assert.h" #include "db/lasterror.h" +namespace mongo { + string getDbContext(); /* "warning" assert -- safe to continue, so we don't throw exception. */ @@ -90,3 +97,5 @@ void sayDbContext(const char *errmsg) { printStackTrace(); } + +} // namespace mongo @@ -21,6 +21,8 @@ #pragma once +namespace mongo { + #define NOMINMAX #if defined(_WIN32) @@ -29,11 +31,15 @@ const bool debug=true; const bool debug=false; #endif +} // namespace mongo + #include <memory> #include "stdlib.h" #include "string.h" #include "limits.h" +namespace mongo { + void sayDbContext(const char *msg = 0); void dbexit(int returnCode, const char *whyMsg = ""); @@ -52,6 +58,8 @@ inline void * ourrealloc(void *ptr, size_t size) { #define malloc ourmalloc #define realloc ourrealloc +} // namespace mongo + #include "targetver.h" #include <string> @@ -59,6 +67,8 @@ inline void * ourrealloc(void *ptr, size_t size) { using namespace std; +namespace mongo { + /* these are manipulated outside of mutexes, so be careful */ struct Assertion { Assertion() { @@ -179,17 +189,26 @@ void msgasserted(const char *msg); */ #define dassert assert +} // namespace mongo + #include <stdio.h> #include <sstream> #include <signal.h> +namespace mongo { + typedef char _TCHAR; +} // namespace mongo + #include <iostream> #include <fstream> #include <map> #include <vector> #include <set> + +namespace mongo { + //using namespace std; #if !defined(_WIN32) @@ -214,8 +233,12 @@ typedef void *HANDLE; #define null (0) +} // namespace mongo + #include <vector> +namespace mongo { + // for debugging typedef struct _Ints { int i[100]; @@ -268,12 +291,15 @@ inline void our_debug_free(void *p) { #define exit dbexit +} // namespace mongo + #undef yassert #include <boost/archive/iterators/base64_from_binary.hpp> #include <boost/archive/iterators/binary_from_base64.hpp> #include <boost/archive/iterators/transform_width.hpp> #include <boost/filesystem/convenience.hpp> #include <boost/filesystem/operations.hpp> +#include <boost/program_options.hpp> #include <boost/shared_ptr.hpp> #define BOOST_SPIRIT_THREADSAFE //#define BOOST_SPIRIT_DEBUG diff --git a/tools/dump.cpp b/tools/dump.cpp index b9fb02e6996..92ad7059788 100644 --- a/tools/dump.cpp +++ b/tools/dump.cpp @@ -19,10 +19,10 @@ #include "../stdafx.h" #include "../client/dbclient.h" -#include <boost/program_options.hpp> - #include <fcntl.h> +namespace mongo { + namespace po = boost::program_options; namespace dump { @@ -108,8 +108,11 @@ namespace dump { } } -} +} // namespace dump + +} // namespace mongo +using namespace mongo; int main( int argc , char ** argv ){ diff --git a/tools/import.cpp b/tools/import.cpp index f74d2af0e1d..a388060ff7f 100644 --- a/tools/import.cpp +++ b/tools/import.cpp @@ -24,6 +24,8 @@ #include <fcntl.h> +namespace mongo { + namespace po = boost::program_options; namespace import { @@ -107,7 +109,11 @@ namespace import { drillDown( conn , dirRoot ); } -} +} // namespace import + +} // namespace mongo + +using namespace mongo; int main( int argc , char ** argv ){ @@ -151,4 +157,3 @@ int main( int argc , char ** argv ){ import::go( host , dir ); return 0; } - diff --git a/util/background.cpp b/util/background.cpp index de1524afe9c..a1413d3a5bf 100644 --- a/util/background.cpp +++ b/util/background.cpp @@ -18,6 +18,8 @@ #include "goodies.h" #include "background.h" +namespace mongo { + BackgroundJob *BackgroundJob::grab = 0; boost::mutex BackgroundJob::mutex; @@ -57,3 +59,5 @@ bool BackgroundJob::wait(int msMax) { } return true; } + +} // namespace mongo diff --git a/util/background.h b/util/background.h index 09cd08bc9bd..d4b9830c40f 100644 --- a/util/background.h +++ b/util/background.h @@ -16,6 +16,8 @@ #pragma once +namespace mongo { + /* object-orienty background thread dispatching. subclass and define run() @@ -66,3 +68,5 @@ private: static void thr(); volatile State state; }; + +} // namespace mongo diff --git a/util/builder.h b/util/builder.h index 6b75a1c24a3..e883ea2f1f2 100644 --- a/util/builder.h +++ b/util/builder.h @@ -22,6 +22,8 @@ #include "../stdafx.h" +namespace mongo { + class BufBuilder { public: BufBuilder(int initsize = 512) : size(initsize) { @@ -106,3 +108,5 @@ private: int l; int size; }; + +} // namespace mongo diff --git a/util/goodies.h b/util/goodies.h index f5dc39a23d0..3a9479d4106 100644 --- a/util/goodies.h +++ b/util/goodies.h @@ -21,12 +21,26 @@ #include "../stdafx.h" +namespace mongo { + #if !defined(_WIN32) + +} // namespace mongo + #include <pthread.h> + +namespace mongo { + inline pthread_t GetCurrentThreadId() { return pthread_self(); } + +} // namespace mongo + #include <execinfo.h> + +namespace mongo { + /* use "addr2line -CFe <exe>" to parse. */ inline void printStackTrace() { void *b[12]; @@ -95,8 +109,14 @@ inline void dumpmemory(const char *data, int len) { } #undef yassert + +} // namespace mongo + #include <boost/thread/thread.hpp> #include <boost/thread/xtime.hpp> + +namespace mongo { + #undef assert #define assert xassert #define yassert 1 @@ -127,8 +147,12 @@ struct WrappingInt { } }; +} // namespace mongo + #include <ctime> +namespace mongo { + inline void time_t_to_String(time_t t, char *buf) { #if defined(_WIN32) ctime_s(buf, 64, &t); @@ -243,8 +267,12 @@ inline bool endsWith(const char *p, const char *suffix) { return strcmp(p + a - b, suffix) == 0; } +} // namespace mongo + #include "boost/detail/endian.hpp" +namespace mongo { + inline unsigned long swapEndian(unsigned long x) { return ((x & 0xff) << 24) | @@ -263,3 +291,5 @@ inline unsigned long fixEndian(unsigned long x) { } #endif + +} // namespace mongo diff --git a/util/hashtab.h b/util/hashtab.h index 88a799ca01a..80a6ded1030 100644 --- a/util/hashtab.h +++ b/util/hashtab.h @@ -26,6 +26,8 @@ #include "../stdafx.h" #include <map> +namespace mongo { + #pragma pack(push,1) /* you should define: @@ -129,3 +131,5 @@ public: }; #pragma pack(pop) + +} // namespace mongo diff --git a/util/log.h b/util/log.h index a5f10bce6e8..6bcca584184 100644 --- a/util/log.h +++ b/util/log.h @@ -18,6 +18,8 @@ #pragma once +namespace mongo { + class Nullstream { public: Nullstream& operator<<(const char *) { @@ -54,9 +56,6 @@ public: return *this; } }; -inline Nullstream& endl ( Nullstream& os ) { - return os; -} extern Nullstream nullstream; #define LOGIT { boostlock lk(mutex); cout << x; return *this; } @@ -99,9 +98,6 @@ public: return *this; } }; -inline Logstream& endl ( Logstream& os ) { - return os; -} extern Logstream logstream; inline Logstream& problem() { @@ -115,3 +111,5 @@ inline ostream& stdcout() { return cout; } #define cout logstream + +} // namespace mongo diff --git a/util/lruishmap.h b/util/lruishmap.h index 944c492a1dc..bc55702edd6 100644 --- a/util/lruishmap.h +++ b/util/lruishmap.h @@ -21,6 +21,8 @@ #include "../stdafx.h" #include "../util/goodies.h" +namespace mongo { + /* Your K object must define: int hash() - must always return > 0. operator== @@ -73,3 +75,5 @@ private: int *hashes; V *values; }; + +} // namespace mongo diff --git a/util/md5.hpp b/util/md5.hpp index f529147dda3..428036c8d6d 100644 --- a/util/md5.hpp +++ b/util/md5.hpp @@ -3,6 +3,8 @@ #pragma once
#include "md5.h"
+ +namespace mongo { typedef unsigned char md5digest[16];
@@ -16,3 +18,5 @@ inline void md5(const void *buf, int nbytes, md5digest digest) { inline void md5(const char *str, md5digest digest) {
md5(str, strlen(str), digest);
}
+ +} // namespace mongo diff --git a/util/miniwebserver.cpp b/util/miniwebserver.cpp index 91e4dd880c4..2c342aa7f11 100644 --- a/util/miniwebserver.cpp +++ b/util/miniwebserver.cpp @@ -20,6 +20,8 @@ #include "stdafx.h" #include "miniwebserver.h" +namespace mongo { + MiniWebServer::MiniWebServer() { sock = 0; } @@ -181,3 +183,5 @@ void MiniWebServer::run() { closesocket(s); } } + +} // namespace mongo diff --git a/util/miniwebserver.h b/util/miniwebserver.h index ecf6046f841..a101e63fa32 100644 --- a/util/miniwebserver.h +++ b/util/miniwebserver.h @@ -20,6 +20,8 @@ #include "../grid/message.h" +namespace mongo { + class MiniWebServer { public: MiniWebServer(); @@ -49,3 +51,5 @@ private: int sock; }; + +} // namespace mongo diff --git a/util/mmap.cpp b/util/mmap.cpp index 8d3d2447692..447775cb2ad 100644 --- a/util/mmap.cpp +++ b/util/mmap.cpp @@ -19,6 +19,8 @@ #include "stdafx.h" #include "mmap.h" +namespace mongo { + set<MemoryMappedFile*> mmfiles; MemoryMappedFile::~MemoryMappedFile() { @@ -49,8 +51,12 @@ void MemoryMappedFile::updateLength( const char *filename, int &length ) const { #if defined(_WIN32) +} // namespace mongo + #include "windows.h" +namespace mongo { + MemoryMappedFile::MemoryMappedFile() { fd = 0; maphandle = 0; @@ -120,12 +126,16 @@ void MemoryMappedFile::flush(bool) { #else +} // namespace mongo + #include <errno.h> #include <sys/mman.h> #include <sys/types.h> #include <sys/stat.h> #include <fcntl.h> +namespace mongo { + MemoryMappedFile::MemoryMappedFile() { fd = 0; maphandle = 0; @@ -208,3 +218,5 @@ void MemoryMappedFile::flush(bool sync) { void* MemoryMappedFile::map(const char *filename) { return map( filename , file_size( filename ) ); // file_size is from boost } + +} // namespace mongo diff --git a/util/mmap.h b/util/mmap.h index ae79a58aad8..07cc885be2f 100644 --- a/util/mmap.h +++ b/util/mmap.h @@ -18,6 +18,8 @@ #pragma once +namespace mongo { + class MemoryMappedFile { public: static void closeAllFiles(); @@ -51,3 +53,5 @@ private: int len; }; + +} // namespace mongo diff --git a/util/sock.cpp b/util/sock.cpp index d89fdaac765..ec3a2c16fdf 100644 --- a/util/sock.cpp +++ b/util/sock.cpp @@ -19,6 +19,8 @@ #include "stdafx.h" #include "sock.h" +namespace mongo { + static boost::mutex sock_mutex; // .empty() if err string hostbyname(const char *hostname) { @@ -187,3 +189,5 @@ void xmain() { #endif + +} // namespace mongo diff --git a/util/sock.h b/util/sock.h index 89ac5ed8f44..d75095e28f0 100644 --- a/util/sock.h +++ b/util/sock.h @@ -22,6 +22,8 @@ #include <sstream> #include "goodies.h" +namespace mongo { + #if defined(_WIN32) //#include <winsock2.h> //#include <ws2tcpip.h> @@ -37,6 +39,9 @@ inline void disableNagle(int sock) { inline void prebindOptions( int sock ) { } #else + +} // namespace mongo + #include <sys/socket.h> #include <sys/types.h> #include <sys/socket.h> @@ -45,6 +50,9 @@ inline void prebindOptions( int sock ) { #include <arpa/inet.h> #include <errno.h> #include <netdb.h> + +namespace mongo { + inline void closesocket(int s) { close(s); } @@ -222,3 +230,5 @@ inline string getHostName() { } + +} // namespace mongo diff --git a/util/unittest.h b/util/unittest.h index df4fab6a2df..0bf2a46100a 100644 --- a/util/unittest.h +++ b/util/unittest.h @@ -18,6 +18,8 @@ #pragma once +namespace mongo { + /* The idea here is to let all initialization of global variables (classes inheriting from UnitTest) complete before we run the tests -- otherwise order of initilization being arbitrary may mess us up. The app's main() function should call runTests(). @@ -48,3 +50,5 @@ struct UnitTest { } }; + +} // namespace mongo diff --git a/util/util.cpp b/util/util.cpp index 2307e64ef84..4736ff86865 100644 --- a/util/util.cpp +++ b/util/util.cpp @@ -20,6 +20,8 @@ #include "goodies.h" #include "unittest.h" +namespace mongo { + vector<UnitTest*> *UnitTest::tests = 0; Nullstream nullstream; @@ -78,3 +80,5 @@ struct UtilTest : public UnitTest { } } utilTest; + +} // namespace mongo |