Skip to content
This repository was archived by the owner on Jan 6, 2020. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions src/maidsafe/vault_manager/tools/commands/choose_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,13 @@ ChooseTest::ChooseTest(LocalNetworkController* local_network_controller)

void ChooseTest::GetChoice() {
TLOG(kYellow) << kInstructions_;
while (!DoGetChoice(choice_, static_cast<int*>(nullptr), 1, 2))
TLOG(kDefaultColour) << '\n' << kInstructions_;
try {
while (!DoGetChoice(choice_, static_cast<int*>(nullptr), 1, 2))
TLOG(kDefaultColour) << '\n' << kInstructions_;
} catch (...) {
// ctrl+C will trigger CommonErrors::unknown error to be raised
throw;
}
}

void ChooseTest::HandleChoice() {
Expand Down
43 changes: 40 additions & 3 deletions src/maidsafe/vault_manager/tools/main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,12 @@
See the Licences for the specific language governing permissions and limitations relating to
use of the MaidSafe Software. */

#ifdef MAIDSAFE_WIN32
#include <windows.h>
#else
#include <signal.h>
#endif

#include "boost/filesystem/path.hpp"

#include "maidsafe/common/error.h"
Expand All @@ -24,6 +30,24 @@
#include "maidsafe/vault_manager/tools/commands/commands.h"
#include "maidsafe/vault_manager/tools/local_network_controller.h"

void ShutDownLocalNetworkController(int /*signal*/) {
throw MakeError(maidsafe::CommonErrors::success);
}

#ifdef MAIDSAFE_WIN32
BOOL CtrlHandler(DWORD control_type) {
switch (control_type) {
case CTRL_C_EVENT:
case CTRL_CLOSE_EVENT:
case CTRL_SHUTDOWN_EVENT:
ShutDownLocalNetworkController(0);
return TRUE;
default:
return FALSE;
}
}
#endif

int main(int argc, char* argv[]) {
try {
boost::filesystem::path script_path;
Expand All @@ -35,15 +59,28 @@ int main(int argc, char* argv[]) {
BOOST_THROW_EXCEPTION(maidsafe::MakeError(maidsafe::CommonErrors::invalid_parameter));

maidsafe::vault_manager::tools::LocalNetworkController local_network_controller{ script_path };
for (;;) {

#ifndef MAIDSAFE_WIN32
signal(SIGINT, ShutDownLocalNetworkController);
signal(SIGTERM, ShutDownLocalNetworkController);
#else
SetConsoleCtrlHandler(reinterpret_cast<PHANDLER_ROUTINE>(CtrlHandler), TRUE);
#endif
for(;;) {
local_network_controller.current_command->PrintTitle();
local_network_controller.current_command->GetChoice();
try {
local_network_controller.current_command->GetChoice();
} catch (...) {
throw;
}

local_network_controller.current_command->HandleChoice();
}
}
catch (const maidsafe::maidsafe_error& error) {
// Success is thrown when Quit option is invoked.
if (error.code() == maidsafe::make_error_code(maidsafe::CommonErrors::success))
if ((error.code() == maidsafe::make_error_code(maidsafe::CommonErrors::success)) ||
(error.code() == maidsafe::make_error_code(maidsafe::CommonErrors::unknown)))
return 0;
TLOG(kRed) << boost::diagnostic_information(error) << "\n\n";
return maidsafe::ErrorToInt(error);
Expand Down