DWORD KUrlMonService::DoUpdateCfg()
{
	kws_log(TEXT("KNetFluxMgr::DoUpdateCfg start"));
	m_bUpdateThreadWorking = TRUE;
	try
	{
		while (1)
		{
			DWORD nWaitRes = ::WaitForSingleObject(m_hThreadExit, 1000 * 60 * 10);
			switch (nWaitRes)
			{
			case WAIT_TIMEOUT:
				UpdateCfg();
				break;
			case WAIT_OBJECT_0:
				goto exit0;
				break;
			default:
				goto exit0;
				break;
			}
		}
	}
	catch (...)
	{

	}

exit0:
	m_bUpdateThreadWorking = FALSE;
	return 0;
}
Exemple #2
0
main()
{
      char        Line[INI_LINESIZE];
      int         Int;
      long        Long;
      double      Double;
      Boolean_T   Bool;
      struct      CfgStruct this_var;
      FILE*       tst;
      long        prices[2];


      /*
      **  First work with a test file
      */
      tst = cant("test.ini", "w");
      fputs("[Section 1]\n", tst);
      fputs("[Section 2]\n", tst);
      fputs("[Section 3]\n", tst);
      fputs("[Section 4]\n", tst);
      fputs("[Section 5]\n", tst);
      fputs("[Section 6]\n", tst);
      fclose(tst);
      puts("Updating the test configuration file");

      puts("Updating section 1");
      UpdateCfg("test.ini", "Section 1", "string #1", "section 1 test");
      puts("Updating section 2");
      UpdateCfg("test.ini", "Section 2", "short #2", "2");
      puts("Updating section 3");
      UpdateCfg("test.ini", "Section 3", "long #3", "3");
      UpdateCfg("test.ini", "Section 4", "double #4", "4.4");
      UpdateCfg("test.ini", "Section 5", "boolean #5", "Y");
      UpdateCfg("test.ini", "Section 6", "boolean #6", "N");
      UpdateCfg("test.ini", "", "global string", "\"Hello, world!\" ;Comment");

      puts("I've finished the updates, now to try to get the data back");

      this_var.Name    = "global string";
      this_var.DataPtr = Line;
      this_var.VarType = Cfg_String;
      printf("ReadCfg(0) returned %d; Line=\n",
             ReadCfg("test.ini", "", &this_var));
      puts(Line);

      this_var.Name    = "string #1";
      this_var.DataPtr = Line;
      this_var.VarType = Cfg_String;
      printf("ReadCfg(1) returned %d; Line=\n",
             ReadCfg("test.ini", "Section 1", &this_var));
      puts(Line);

      this_var.Name    = "short #2";
      this_var.DataPtr = ∬
      this_var.VarType = Cfg_Short;
      printf("ReadCfg(2) returned %d; Value= ",
             ReadCfg("test.ini", "Section 2", &this_var));
      printf("%d\n", Int);

      this_var.Name    = "long #3";
      this_var.DataPtr = &Long;
      this_var.VarType = Cfg_Long;
      printf("ReadCfg(3) returned %d; Value = ",
             ReadCfg("test.ini", "Section 3", &this_var));
      printf("%ld\n", Long);

      this_var.Name    = "double #4";
      this_var.DataPtr = &Double;
      this_var.VarType = Cfg_Double;
      printf("ReadCfg(4) returned %d; Value = ",
             ReadCfg("test.ini", "Section 4", &this_var));
      printf("%f\n", Double);

      this_var.Name    = "boolean #5";
      this_var.DataPtr = &Bool;
      this_var.VarType = Cfg_Boolean;
      printf("ReadCfg(5) returned %d; Value = ",
             ReadCfg("test.ini", "Section 5", &this_var));
      printf("%c\n", Bool ? 'T' : 'F');

      this_var.Name    = "boolean #6";
      this_var.DataPtr = &Bool;
      this_var.VarType = Cfg_Boolean;
      printf("ReadCfg(6) returned %d; Value = ",
             ReadCfg("test.ini", "Section 6", &this_var));
      printf("%c\n", Bool ? 'T' : 'F');

      /*
      **  Look for non-existant sections and/or variables
      */

      Line[0] = NUL;
      this_var.Name    = "string #99";
      this_var.DataPtr = Line;
      this_var.VarType = Cfg_String;
      printf("ReadCfg(99) returned %d; Line=\n",
             ReadCfg("test.ini", "Section 99", &this_var));
      puts(Line);

      Line[0] = NUL;
      this_var.Name    = "string #99";
      this_var.DataPtr = Line;
      this_var.VarType = Cfg_String;
      printf("ReadCfg(0/99) returned %d; Line=\n",
             ReadCfg("test.ini", "", &this_var));
      puts(Line);

      Line[0] = NUL;
      this_var.Name    = "string #99";
      this_var.DataPtr = Line;
      this_var.VarType = Cfg_String;
      printf("ReadCfg(1/99) returned %d; Line=\n",
             ReadCfg("test.ini", "Section 1", &this_var));
      puts(Line);

      Line[0] = NUL;
      this_var.Name    = "string #1";
      this_var.DataPtr = Line;
      this_var.VarType = Cfg_String;
      printf("ReadCfg(1/100) returned %d; Line=\n",
             ReadCfg("test.ini", "Section 100", &this_var));
      puts(Line);

      /*
      **  Next, add a section and new variables
      */

      UpdateCfg("test.ini", "", "new global variable", "abc");
      UpdateCfg("test.ini", "Section -1", "new variable", "xyz");
     
      /*
      **  Next work with a sample real PRICES.INI file
      */

      this_var.Name    = "Price of #1";
      this_var.DataPtr = &prices[0];
      this_var.VarType = Cfg_Long;
      printf("ReadCfg(1) returned %d; Value = ",
             ReadCfg(PINI_fname, "", &this_var));
      printf("%ld\n", prices[0]);

      this_var.Name    = "Price of #2";
      this_var.DataPtr = &prices[1];
      this_var.VarType = Cfg_Long;
      printf("ReadCfg(2) returned %d; Value = ",
             ReadCfg(PINI_fname, "", &this_var));
      printf("%ld\n", prices[1]);

      UpdateCfg("prices.ini", "", "Price of #2", "999");

      this_var.Name    = "Price of #2";
      this_var.DataPtr = &prices[1];
      this_var.VarType = Cfg_Long;
      printf("ReadCfg(2) returned %d; Value = ",
             ReadCfg(PINI_fname, "", &this_var));
      printf("%ld\n", prices[1]);

      UpdateCfg(PINI_fname, "", "Price of #2", "389");

      this_var.Name    = "Price of #2";
      this_var.DataPtr = &prices[1];
      this_var.VarType = Cfg_Long;
      printf("ReadCfg(2) returned %d; Value = ",
             ReadCfg(PINI_fname, "", &this_var));
      printf("%ld\n", prices[1]);

      /*
      **  Finally, try an invalid file name
      */

      this_var.Name    = "global string";
      this_var.DataPtr = Line;
      this_var.VarType = Cfg_String;
      printf("ReadCfg(0) returned %d; Line=\n",
             ReadCfg("none.ini", "", &this_var));
      puts(Line);

      return EXIT_SUCCESS;
}