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


C++ FileLoader::load_cfg方法代码示例

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


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

示例1: main

int main(void) 
{
	/* Our process ID and Session ID */
	pid_t pid, sid;

	/* Fork off the parent process */
	pid = fork();
	if (pid < 0) 
	{
		exit(EXIT_FAILURE);
	}
	
	/* If we got a good PID, then we can exit the parent process. */
	if (pid > 0) 
	{
		exit(EXIT_SUCCESS);
	}

	/* Change the file mode mask */
	umask(0);

	/* Open any logs here */
	FILE *logFile;
	logFile = fopen("/var/log/ojNodeManager.log", "w+");
	if(logFile == NULL)
	{
		// Log error
		exit(EXIT_FAILURE);
	}

	/* Create a new SID for the child process */
	/* this is a unique session ID */
	sid = setsid();
	if (sid < 0) 
	{
		/* Log the failure */
		fprintf(logFile, "Did not get a valid SID value\n");
		exit(EXIT_FAILURE);
	}
	
	/* Change the current working directory */
	if ((chdir("/")) < 0) 
	{
		/* Log the failure */
		fprintf(logFile, "Could not change working directory to '/'\n");
		exit(EXIT_FAILURE);
	}
	
	/* Close out the standard file descriptors */
	close(STDIN_FILENO);
	close(STDOUT_FILENO);
	close(STDERR_FILENO);
	
	/* Daemon-specific initialization goes here */
	MyHandler *handler = new MyHandler(logFile);
	FileLoader *configData = new FileLoader();
	
	// Tests that the config file is valid
	if(!configData->load_cfg("/etc/ojNodeManager.conf"))
	{
		// "/etc/ojNodeManager.conf" not opened correctly
		// For backwards compatibility, we'll try to open "/etc/nodeManager.conf"
		if(!configData->load_cfg("/etc/ojNodeManager.conf"))
		{
			// Neither file loaded properly!
			// Log failure
			fprintf(logFile, "Could not open OpenJAUS Node Manager configuration file. Check that it exists? \"/etc/ojNodeManager.conf\"\n");
			exit(EXIT_FAILURE);
		}
	}
	
	printf("Starting OpenJAUS Node Manager Service Version %s (JULY 9, 2008)\n", OJ_NODE_MANAGER_VERSION);
	fflush(logFile);
	
	// Our Node Manager object
	NodeManager *nm;
	
	// Create our NodeManager object
	try
	{
		nm = new NodeManager(configData, handler);
	}
	catch(char *exceptionString)
	{
		// Log exception to the log file
		fprintf(logFile, "ojNodeManager Exception: %s\n", exceptionString);
		fprintf(logFile, "Terminating Program...\n");
		exit(EXIT_FAILURE);
	}
	catch(...)
	{
		fprintf(logFile, "Node Manager Construction Failed. Terminating Program...\n");
		exit(EXIT_FAILURE);
	}
	
	/* The Big Loop */
	while(true) 
	{
	   /* Do some task here ... */
	   
//.........这里部分代码省略.........
开发者ID:OpenJAUS,项目名称:openjaus,代码行数:101,代码来源:ojnmService.cpp


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