Skip to content

Commit

Permalink
First version which connects to localhost on Windows linked to robo-s…
Browse files Browse the repository at this point in the history
…hell-4.0.4 commit 9db1ab
  • Loading branch information
simsekgokhan committed Dec 5, 2018
1 parent f56ff4f commit 5dd5019
Show file tree
Hide file tree
Showing 12 changed files with 95 additions and 79 deletions.
6 changes: 4 additions & 2 deletions cmake/FindMongoDB.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ set(MongoDB_INCLUDE_DIRS
${MongoDB_DIR}/src/third_party/boost-1.60.0
${MongoDB_DIR}/src/third_party/mozjs-45/include
${MongoDB_DIR}/src/third_party/mozjs-45/mongo_sources
${MongoDB_DIR}/src/third_party/pcre-8.39
${MongoDB_DIR}/src/third_party/pcre-8.41
${MongoDB_BUILD_DIR}
)

Expand Down Expand Up @@ -92,7 +92,9 @@ foreach(lib ${MongoDB_RELATIVE_LIBS})
endforeach()

if(SYSTEM_WINDOWS)
list(APPEND MongoDB_LIBS $ENV{WindowsSdkDir}/Lib/winv6.3/um/x64/Crypt32.Lib)
list(APPEND MongoDB_LIBS $ENV{WindowsSdkDir}/Lib/10.0.17763.0/um/x64/Crypt32.Lib) # todo generic SDK version
list(APPEND MongoDB_LIBS $ENV{WindowsSdkDir}/Lib/10.0.17763.0/um/x64/Secur32.Lib)
list(APPEND MongoDB_LIBS $ENV{WindowsSdkDir}/Lib/10.0.17763.0/um/x64/Dnsapi.lib)
endif()

# Get MongoDB repository recent tag
Expand Down
2 changes: 1 addition & 1 deletion cmake/mongodb/windows-debug.objects

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion cmake/mongodb/windows-release.objects

Large diffs are not rendered by default.

4 changes: 4 additions & 0 deletions cmake/win_dbg_link_libs
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
DbgHelp.lib Iphlpapi.lib Psapi.lib advapi32.lib bcrypt.lib crypt32.lib
dnsapi.lib kernel32.lib shell32.lib pdh.lib version.lib winmm.lib ws2_32.lib
secur32.lib winmm.lib
/PDB:build\debug\mongo\mongo.pdb /DEBUG
3 changes: 3 additions & 0 deletions cmake/win_rel_link_libs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
DbgHelp.lib Iphlpapi.lib Psapi.lib advapi32.lib bcrypt.lib crypt32.lib dnsapi.lib
kernel32.lib shell32.lib pdh.lib version.lib winmm.lib ws2_32.lib secur32.lib winmm.lib
/PDB:build\opt\mongo\mongo.pdb /DEBUG
1 change: 1 addition & 0 deletions src/robomongo/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,7 @@ target_include_directories(robomongo

target_compile_definitions(robomongo
PRIVATE
BUILDING_ROBO
PROJECT_NAME="${PROJECT_NAME}"
PROJECT_NAME_TITLE="${PROJECT_NAME_TITLE}"
PROJECT_COPYRIGHT="${PROJECT_COPYRIGHT}"
Expand Down
17 changes: 16 additions & 1 deletion src/robomongo/app/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,13 @@
// Header "mongo/util/net/sock" is needed for mongo::enableIPv6()
// Header "mongo/platform/basic" is required by "sock.h" under Windows
#include <mongo/platform/basic.h>
#include <mongo/util/net/sock.h>
#include <mongo/util/net/socket_utils.h>
#include <mongo/base/initializer.h>
#include <mongo/util/net/ssl_options.h>
#include <mongo/db/service_context.h>
#include <mongo/transport/transport_layer_asio.h>
#include <mongo/shell/shell_options.h>
#include <mongo/db/storage/storage_engine_init.h>

#include "robomongo/core/AppRegistry.h"
#include "robomongo/core/settings/SettingsManager.h"
Expand Down Expand Up @@ -39,6 +43,17 @@ int main(int argc, char *argv[], char** envp)

// Initialization routine for MongoDB shell
mongo::runGlobalInitializersOrDie(argc, argv, envp);
mongo::setGlobalServiceContext(mongo::ServiceContext::make());
// Mongo-Todo: This should use a TransportLayerManager or TransportLayerFactory
auto serviceContext = mongo::getGlobalServiceContext();
mongo::transport::TransportLayerASIO::Options opts;
opts.enableIPv6 = mongo::shellGlobalParams.enableIPv6;
opts.mode = mongo::transport::TransportLayerASIO::Options::kEgress;
serviceContext->setTransportLayer(
std::make_unique<mongo::transport::TransportLayerASIO>(opts, nullptr));
auto tlPtr = serviceContext->getTransportLayer();
uassertStatusOK(tlPtr->setup());
uassertStatusOK(tlPtr->start());

// Initialize Qt application
QApplication app(argc, argv);
Expand Down
52 changes: 24 additions & 28 deletions src/robomongo/core/mongodb/MongoClient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,12 +82,8 @@ namespace Robomongo

std::vector<std::string> MongoClient::getDatabaseNames() const
{
typedef std::list<std::string> cont_string_t;
cont_string_t dbs = _dbclient->getDatabaseNames();
std::vector<std::string> dbNames;
for (cont_string_t::const_iterator i = dbs.begin(); i != dbs.end(); ++i) {
dbNames.push_back(*i);
}
std::list<std::string> const& dbs = _dbclient->getDatabaseNames();
std::vector<std::string> dbNames = {dbs.begin(), dbs.end()};
std::sort(dbNames.begin(), dbNames.end());
return dbNames;
}
Expand All @@ -101,7 +97,7 @@ namespace Robomongo

// Cursor may be NULL, it means we have connectivity problem
if (!cursor)
throw mongo::DBException("Network error while attempting to load list of users", 0);
throw std::runtime_error("Network error while attempting to load list of users"/*, 0*/);

float ver = getVersion();
while (cursor->more()) {
Expand Down Expand Up @@ -133,7 +129,7 @@ namespace Robomongo

std::string errorStr = _dbclient->getLastError();
if (!errorStr.empty())
throw mongo::DBException(errorStr, 0);
throw std::runtime_error(errorStr/*, 0*/);
}

void MongoClient::dropUser(const std::string &dbName, const mongo::OID &id)
Expand All @@ -149,7 +145,7 @@ namespace Robomongo

std::string errorStr = _dbclient->getLastError();
if (!errorStr.empty())
throw mongo::DBException(errorStr, 0);
throw std::runtime_error(errorStr/*, 0*/);
}

std::vector<MongoFunction> MongoClient::getFunctions(const std::string &dbName)
Expand All @@ -161,7 +157,7 @@ namespace Robomongo

// Cursor may be NULL, it means we have connectivity problem
if (!cursor)
throw mongo::DBException("Network error while attempting to load list of functions.", 0);
throw std::runtime_error("Network error while attempting to load list of functions."/*, 0*/);

while (cursor->more()) {
mongo::BSONObj bsonObj = cursor->next();
Expand Down Expand Up @@ -319,7 +315,7 @@ namespace Robomongo
_dbclient->insert(ns.toString(), obj);
std::string errorStr = _dbclient->getLastError();
if (!errorStr.empty())
throw mongo::DBException(errorStr, 0);
throw std::runtime_error(errorStr/* , 0 */);
} else { // this is update

std::string name = fun.name();
Expand All @@ -333,7 +329,7 @@ namespace Robomongo
_dbclient->update(ns.toString(), query, obj, true, false);
std::string errorStr = _dbclient->getLastError();
if (!errorStr.empty())
throw mongo::DBException(errorStr, 0);
throw std::runtime_error(errorStr/*, 0*/);
} else { // update function name (remove & insert)
_dbclient->insert(ns.toString(), obj);
std::string errorStr = _dbclient->getLastError();
Expand All @@ -347,7 +343,7 @@ namespace Robomongo
_dbclient->remove(ns.toString(), query, true);
}
else {
throw mongo::DBException(errorStr, 0);
throw std::runtime_error(errorStr/*, 0*/);
}
}
}
Expand All @@ -365,7 +361,7 @@ namespace Robomongo
_dbclient->remove(ns.toString(), query, true);
std::string errorStr = _dbclient->getLastError();
if (!errorStr.empty())
throw mongo::DBException(errorStr, 0);
throw std::runtime_error(errorStr/*, 0*/);
}

void MongoClient::createDatabase(const std::string &dbName)
Expand All @@ -380,7 +376,7 @@ namespace Robomongo

// If <dbName>.temp already exists, stop.
if (_dbclient->exists(ns.toString()))
throw mongo::DBException(dbName + ".temp already exists.", 0);
throw std::runtime_error(dbName + ".temp already exists."/*, 0*/);

// Building { _id : "temp" } document
mongo::BSONObjBuilder builder;
Expand All @@ -391,7 +387,7 @@ namespace Robomongo
_dbclient->insert(ns.toString(), obj);
std::string errorStr = _dbclient->getLastError();
if (!errorStr.empty())
throw mongo::DBException(errorStr, 0);
throw std::runtime_error(errorStr/*, 0*/);

// Drop temp collection
_dbclient->dropCollection(ns.toString());
Expand All @@ -405,7 +401,7 @@ namespace Robomongo
if (errStr.empty())
errStr = "Failed to get error message.";

throw mongo::DBException(errStr, 0);
throw std::runtime_error(errStr/*, 0*/);
}
}

Expand Down Expand Up @@ -437,11 +433,11 @@ namespace Robomongo
if (errStr.empty())
errStr = "Failed to get error message.";

throw mongo::DBException(errStr, 0);
throw std::runtime_error(errStr/*, 0*/);
}
}
else {
throw mongo::DBException("Collection with same name already exists.", 0);
throw std::runtime_error("Collection with same name already exists."/*, 0*/);
}
}

Expand All @@ -461,7 +457,7 @@ namespace Robomongo
if (errStr.empty())
errStr = "Failed to get error message.";

throw mongo::DBException(errStr, 0);
throw std::runtime_error(errStr/*, 0*/);
}
}

Expand All @@ -480,18 +476,18 @@ namespace Robomongo
if (errStr.empty())
errStr = "Failed to get error message.";

throw mongo::DBException(errStr, 0);
throw std::runtime_error(errStr/*, 0*/);
}
}
else {
throw mongo::DBException("Collection with same name already exists.", 0);
throw std::runtime_error("Collection with same name already exists."/*, 0*/);
}

std::unique_ptr<mongo::DBClientCursor> cursor(_dbclient->query(sourceCollection.toString(), mongo::Query()));

// Cursor may be NULL, it means we have connectivity problem
if (!cursor)
throw mongo::DBException("Network error while attempting to run query", 0);
throw std::runtime_error("Network error while attempting to run query"/*, 0*/);

while (cursor->more()) {
mongo::BSONObj bsonObj = cursor->next();
Expand All @@ -509,7 +505,7 @@ namespace Robomongo

// Cursor may be NULL, it means we have connectivity problem
if (!cursor)
throw mongo::DBException("Network error while attempting to run query", 0);
throw std::runtime_error("Network error while attempting to run query"/*, 0*/);

while (cursor->more()) {
mongo::BSONObj bsonObj = cursor->next();
Expand All @@ -526,11 +522,11 @@ namespace Robomongo
if (errStr.empty())
errStr = "Failed to get error message.";

throw mongo::DBException(errStr, 0);
throw std::runtime_error(errStr/*, 0*/);
}
}
else {
throw mongo::DBException("Collection does not exist.", 0);
throw std::runtime_error("Collection does not exist."/*, 0*/);
}
}

Expand Down Expand Up @@ -575,7 +571,7 @@ namespace Robomongo

// DBClientBase::query may return nullptr
if (!cursor)
throw mongo::DBException("Network error while attempting to run query", 0);
throw std::runtime_error("Network error while attempting to run query"/*, 0*/);

while (cursor->more()) {
mongo::BSONObj bsonObj = cursor->next();
Expand Down Expand Up @@ -631,6 +627,6 @@ namespace Robomongo
if (lastError.empty())
return;

throw mongo::DBException(lastError, mongo::ErrorCodes::InternalError);
throw std::runtime_error(lastError/*, mongo::ErrorCodes::InternalError*/);
}
}
Loading

0 comments on commit 5dd5019

Please sign in to comment.