当前位置: 首页>>代码示例>>C++>>正文


C++ SignalHandler::UnBlock方法代码示例

本文整理汇总了C++中SignalHandler::UnBlock方法的典型用法代码示例。如果您正苦于以下问题:C++ SignalHandler::UnBlock方法的具体用法?C++ SignalHandler::UnBlock怎么用?C++ SignalHandler::UnBlock使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在SignalHandler的用法示例。


在下文中一共展示了SignalHandler::UnBlock方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: main

int main(int argc, char **argv)
{
	std::string LocSocket = "/tmp/ipdupdetect";
	std::unique_ptr<PIDFile> PidFile;
	std::string LocPidFile = "";
	const char *opts = "hdp:";
	int longindex = 0;
	int c = 0;
	int debug = 0;
	struct option loptions[]
	{
		{"help", 0, 0, 'h'},
		{"pid", 1, 0, 'p'},
		{"debug", 0, 0, 'd'},
		{0, 0, 0, 0}
	};
	
	while( (c = getopt_long(argc, argv, opts, loptions, &longindex)) >= 0)
	{
		switch(c)
		{
			case 'd':
				debug = 1;
				break;
			case 'h':
				print_help(stdout, argv[0]);
				exit(EXIT_SUCCESS);
				break;
			case 'p':
				LocPidFile = optarg;
				break;
			default:
				break;
		}
	}
	
	//Add Logging
	if (isatty(fileno(stdout)) == 1)
	{
		std::shared_ptr<ILogger> tmp = std::make_shared<LogStdoutColor>();
		LogManager::Add(tmp);
	} else {
		std::shared_ptr<ILogger> tmp = std::make_shared<LogStdout>();
		LogManager::Add(tmp);
	}

	if (debug)
	{
		LogManager::SetLevel(LOGGER_DEBUG);
	}
	else
	{
		LogManager::SetLevel(LOGGER_INFO);
	}
	
	if (LocPidFile != "")
	{
		PidFile.reset(new PIDFile(LocPidFile));
		if (PidFile->Create() == false)
		{
			LogCritical("Cannot Create PID file '%s'", LocPidFile.c_str());
			exit(EXIT_FAILURE);
		}
		LogInfo("Created PID file '%s'", LocPidFile.c_str());
	}

	SigHandler SHandler;
	SignalHandler Signals = SignalHandler(&SHandler);
	Signals.Block();

	do
	{
		ServerManager *SrvManager = NULL;
		MonitorManager MManager;
		Service *Srv = new Service(&MManager); //Bind instance of MonitorManager to the ServiceProxy
		struct timespec timeout = {60, 0}; //Timeout to reprocess interface list
		ScopedLock lock(&ExitLock);
		SHandler.SetMonitorManager(&MManager); //Bind MonitorManager to signal handler proxy

		
		ServerUnixPolled Unix(LocSocket); //Create a suitable socket
		SrvManager = new ServerManager(Srv); //Create a new server instance
		SrvManager->ServerAdd(&Unix); //Bind our Service proxy to the socket instance

		Signals.UnBlock();
		while(DoExit == false)
		{
			MManager.Scan();
			MManager.Purge();
			ExitLock.Wait(&timeout);
		}
		lock.Unlock(); //Required to prevent hang in signals
		
		SrvManager->ServerRemove(&Unix);
		delete Srv;
		delete SrvManager;
		
		Signals.Block();
		SHandler.SetMonitorManager(NULL);
		Signals.UnBlock();
//.........这里部分代码省略.........
开发者ID:mistralol,项目名称:ipdupdetect,代码行数:101,代码来源:main.cpp


注:本文中的SignalHandler::UnBlock方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。