Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

data-sync-2.0 #4327

Open
wants to merge 6 commits into
base: release-2.10.2
Choose a base branch
from
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
94 changes: 94 additions & 0 deletions fisco-bcos/datasync/Common.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
/**
* @CopyRight:
* FISCO-BCOS is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* FISCO-BCOS 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with FISCO-BCOS. If not, see <http://www.gnu.org/licenses/>
* (c) 2016-2018 fisco-dev contributors.
*
* @brief: class to handle exit
*
* @file: ExitHandler.h
* @author: yujiechen
* @date 2018-11-07
*/
#pragma once
#include "libconfig/GlobalConfigure.h"
#include "libinitializer/GlobalConfigureInitializer.h"
#include <boost/filesystem.hpp>
#include <boost/program_options.hpp>
#include <chrono>
#include <ctime>

class ExitHandler
{
public:
void exit() { exitHandler(0); }
static void exitHandler(int) { dev::g_BCOSConfig.shouldExit.store(true); }
bool shouldExit() const { return dev::g_BCOSConfig.shouldExit.load(); }
};

void setDefaultOrCLocale()
{
#if __unix__
if (!std::setlocale(LC_ALL, ""))
{
setenv("LC_ALL", "C", 1);
}
#endif
}

std::string initCommandLine(int argc, const char* argv[])
{
boost::program_options::options_description main_options("Usage of FISCO-BCOS");
main_options.add_options()("help,h", "print help information")(
"version,v", "version of FISCO-BCOS")("config,c",
boost::program_options::value<std::string>()->default_value("./config.ini"),
"config file path, eg. config.ini");
boost::program_options::variables_map vm;
try
{
boost::program_options::store(
boost::program_options::parse_command_line(argc, argv, main_options), vm);
}
catch (...)
{
std::cout << "invalid parameters" << std::endl;
std::cout << main_options << std::endl;
exit(0);
}
/// help information
if (vm.count("help") || vm.count("h"))
{
std::cout << main_options << std::endl;
exit(0);
}
/// version information
if (vm.count("version") || vm.count("v"))
{
dev::version();
exit(0);
}
std::string configPath("./config.ini");
if (vm.count("config") || vm.count("c"))
{
configPath = vm["config"].as<std::string>();
if (boost::filesystem::exists(configPath))
{
std::cout << "config file path : " << configPath << std::endl;
return configPath;
}
}
std::cout << main_options << std::endl;
exit(0);

return configPath;
}