Browse Source

Allow debug daemon on Windows (Lazarus)

Allow to debug deamon using Lazarus compiler on Windows (as a Service)
Program will run on Windows calling "pascalcoin_daemon.exe -r -d" and can be debugged on Lazarus. Will finish on pressed "q"
PascalCoin 4 years ago
parent
commit
6bfcbd4d26
3 changed files with 42 additions and 2 deletions
  1. 36 0
      src/core/upcdaemon.pas
  2. 2 2
      src/pascalcoin_daemon.lpi
  3. 4 0
      src/pascalcoin_daemon.pp

+ 36 - 0
src/core/upcdaemon.pas

@@ -26,6 +26,7 @@ uses
   Classes, SysUtils, daemonapp,
   SyncObjs, UOpenSSL, UCrypto, UNode, UFileStorage, UFolderHelper, UWallet, UConst, ULog, UNetProtocol,
   IniFiles, UBaseTypes,
+  {$IF Defined(FPC) and Defined(WINDOWS)}windows,jwawinsvc,crt,{$ENDIF}
   UThread, URPC, UPoolMining, UAccounts, UPCDataTypes;
 
 Const
@@ -91,6 +92,7 @@ Type
   protected
     Procedure DoOnCreate; override;
     Procedure DoOnDestroy; override;
+    Procedure DoOnRun; override;
   public
   end;
 
@@ -412,5 +414,39 @@ begin
   end;
 end;
 
+procedure TPCDaemonMapper.DoOnRun;
+{$IF Defined(FPC) and Defined(WINDOWS)}
+var LDT : TPCDaemonThread;
+{$ENDIF}
+begin
+  inherited DoOnRun;
+  {$IF Defined(FPC) and Defined(WINDOWS)}
+  // We are running -r command on windows
+  if Application.HasOption('d','debug') then begin
+    LDT:=TPCDaemonThread.Create;
+    LDT.FreeOnTerminate:=True;
+    if (Application.HasOption('b','block')) then begin
+      LDT.MaxBlockToRead:=StrToInt64Def(Application.GetOptionValue('b','block'),$FFFFFFFF);
+      TLog.NewLog(ltinfo,ClassName,'Max block to read: '+IntToStr(LDT.MaxBlockToRead));
+    end;
+    LDT.Start;
+    repeat
+      CheckSynchronize(10);
+      Sleep(1);
+
+      if Keypressed then begin
+        if (ReadKey in ['q','Q']) then begin
+          LDT.Terminate;
+        end;
+      end;
+
+    until LDT.Terminated;
+    LDT.Terminate;
+    LDT.WaitFor;
+    Application.Terminate;
+  end;
+  {$ENDIF}
+end;
+
 end.
 

+ 2 - 2
src/pascalcoin_daemon.lpi

@@ -25,14 +25,14 @@
     </PublishOptions>
     <RunParams>
       <local>
-        <CommandLineParams Value="-r"/>
+        <CommandLineParams Value="-r -d"/>
         <Display Use="True" Value=""/>
       </local>
       <FormatVersion Value="2"/>
       <Modes Count="1">
         <Mode0 Name="default">
           <local>
-            <CommandLineParams Value="-r"/>
+            <CommandLineParams Value="-r -d"/>
             <Display Use="True" Value=""/>
           </local>
         </Mode0>

+ 4 - 0
src/pascalcoin_daemon.pp

@@ -31,7 +31,11 @@ end;
 
 begin
   Application.Title:='PascalCoin Daemon application';
+  {$IF Defined(FPC) and Defined(WINDOWS)}
+  IsConsole := Not Application.HasOption('r','run');
+  {$ELSE}
   IsConsole:=False;
+  {$ENDIF}
   RegisterDaemonClass(TPCDaemon);
   RegisterDaemonMapper(TPCDaemonMapper);
   Application.GUIMainLoop:[email protected];