// TestSvc.cpp : Defines the entry point for the console application.
//

#include "stdio.h"
#include "KYLin.h"

// 
static int DoStart(const TKYStringList& AParams, bool AIsSvc)
{
   // ʾ
   if (!AIsSvc)
      printf("..... OnStart(IsSvc: false) is running.\n");

   // ??? ... ...

   return 0;
}

// ֹͣ
static void DoStop(bool AIsSvc)
{
   // ʾ
   if (!AIsSvc)
      printf("..... OnStop(IsSvc: false) is running.\n");

   // ??? ... ...
}

// ̨ʽִ
static void DoExecute(const TKYStringList& AParams, TKYSvcApp* ASvcApp)
{
   // ʾ
   printf("..... OnExecute is running.\n");

   // ȴ
   printf("press [Ctrl+C] stop application.\n");
   while (!ASvcApp->Terminated())
      ASvcApp->Notify()->Wait();
}

// ûԶ忪
static int DoUser(long ASwitch, int argc, char* argv[])
{
   printf("switch(%d) <%s> is run.\n", ASwitch, argv[1]);
   return 0;
}

// 
int main(int argc, char* argv[])
{
   // ʼ
   TKYSvcApp objApp("TestSvc", "Service demo", "Test TKYSvcApp demo");

   // /ֹͣĻص
   objApp.OnStart    = DoStart;
   objApp.OnStop     = DoStop;

   // ԶӦÿʱĻص
   /*
   objApp.OnExecute  = DoExecute;
   objApp.OnUser     = DoUser;
   //*/

   // ö
   /*
   objApp.SetRunLevel(235);                  // м [1, 2, 3, 4, 5]
   objApp.SetStartNo(20);                    // 
   objApp.SetStopNo(80);                     // ֹͣ
   objApp.SetIsAuto(false);                  // ֶ
   //*/

   // Զ(ע: Ĭϲؿͨ /? ʾ)
   /*
   objApp.ClearSwitchs();
   objApp.AddSwitch(TKYSvcApp::asHelp,       "/?",          "ʾϢ");  // ĬϵʾϢ
   objApp.AddSwitch(TKYSvcApp::asHelp,       "-help");
   objApp.AddSwitch(TKYSvcApp::asConsole,    "-console",    "̨ʽ");// ĬϵʾϢ
   objApp.AddSwitch(TKYSvcApp::asService,    "-service",    "ʽ");  // ĬϵʾϢ
   objApp.AddSwitch(TKYSvcApp::asInstall,    "-install");
   objApp.AddSwitch(TKYSvcApp::asUninstall,  "-remove");
   objApp.AddSwitch(TKYSvcApp::asStart,      "-start");
   objApp.AddSwitch(TKYSvcApp::asStop,       "-stop");
   objApp.AddSwitch(15,                      "-u1",         "my switch 1");
   objApp.AddSwitch(18,                      "-u2",         "my switch 2");
   objApp.AddSwitch(20,                      "-u3");
   //*/

   // 
   return objApp.Run(argc, argv);
}
