#1 2012-01-17 10:49:30

Leander007
Member
From: Slovenia
Registered: 2011-04-29
Posts: 113

SQLite3Service.TService (windows service) does not work as expected

or am I missing something?

Arnaud, you already explained usage of TService and somebody (Mick) already comment it, that some features does not work.

I'll be more precise:
You are using assembler tricks to call method of class instance instead of plain (stdcall) procedure :

Srv.FStatusHandle := RegisterServiceCtrlHandler(pointer(Srv.fSName), Srv.FJumper);

And this is just not working in my scenario (Delphi 2009, Vista as target). It looks that this jumper cannot run at all from service controller.

If I run this "jumper code" manually (from my code), then it works:

type
  TCtrlHandler = procedure(CtrlCode: DWord); stdcall;
(...)
  TCtrlHandler(Srv.FJumper)(SERVICE_STOPPED);

If I use plain (stdcall) procedure, then it works from service controller too:

procedure MyDoCtrlHandle(Code: DWORD); stdcall;
begin
  (...)
end;
(...)
Srv.FStatusHandle := RegisterServiceCtrlHandler(pointer(Srv.fSName), Addr(MyDoCtrlHandle));

I really don't have a clue what is wrong, maybe is just simpler to have some "safe fallback" similar to SvcMgr.TService:

TServiceController = procedure(CtrlCode: DWord); stdcall;
(...)
TService = class(TDataModule)
(...)
function GetServiceController: TServiceController; virtual; abstract;

This is less intuitive, but is more Pascal way smile. I don't know if this problem is easy solvable for you or is it better to add some kind of safe fallback too.


"Uncertainty in science: There no doubt exist natural laws, but once this fine reason of ours was corrupted, it corrupted everything.", Blaise Pascal

Offline

#2 2012-01-17 11:06:24

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,718
Website

Re: SQLite3Service.TService (windows service) does not work as expected

SQLite3Service purpose was mainly to be used within LVCL, so with Delphi 6-2007.
Purpose was to create small and efficient stand-alone services, without the overhead of the whole VCL (we do not need Forms to be linked to a service).

Therefore, it was tested and used only with Delphi 7.
It may be incompatible with Delphi 2009, indeed.

Perhaps it is better to use the standard way of writing services of Delphi 2009, instead of our SQLite3Service unit in this case.

Offline

#3 2012-01-17 12:51:43

Leander007
Member
From: Slovenia
Registered: 2011-04-29
Posts: 113

Re: SQLite3Service.TService (windows service) does not work as expected

I'm not fan of bloated implementations either.
Your TService is some kind well wrapped direct Win API solution.
I'll definitely take your class as base (at first my implementation was as composition, now sub-classing fits better) and only change that callback portion to "manual" Pascal way (I do not understand enough of assembler to correct your "automatic" way smile).


"Uncertainty in science: There no doubt exist natural laws, but once this fine reason of ours was corrupted, it corrupted everything.", Blaise Pascal

Offline

#4 2012-01-17 20:01:44

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,718
Website

Re: SQLite3Service.TService (windows service) does not work as expected

Nice.

If you found out an implementation compatible with latest version of Delphi, let me know.
I'll add this to the main source code trunk.

Thanks!

Offline

#5 2012-01-19 00:59:58

Leander007
Member
From: Slovenia
Registered: 2011-04-29
Posts: 113

Re: SQLite3Service.TService (windows service) does not work as expected

Hi, Arnaud.

I did small changes to the SQLite3Service unit (TService).
I only added common property ControlHandler for setting the callback handler and some minor changes to fit it properly in code.
If the handler is not set from "outside" then your hack is used.
So this "outside discipline" is some how similar to the SvcMgr.TService approach.
The difference is that our TService does not force you to subclassing (no abstract procedure), it could be easily used in composition scenario too (I moved DoCtrlHandle to the public visibility for that reason).
Anyway I think that this approach is good (it's just added choice, we lose nothing), even if the asm (automatic router smile) code would be corrected.
This always works, because is just basic Pascal smile.

I sent you code via mail (I don't want to bloat the forum smile).


"Uncertainty in science: There no doubt exist natural laws, but once this fine reason of ours was corrupted, it corrupted everything.", Blaise Pascal

Offline

#6 2012-01-19 13:02:17

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,718
Website

Re: SQLite3Service.TService (windows service) does not work as expected

Thanks for the report.

I've committed your modifications directly (and started preparing the 64 bit version).
See http://synopse.info/fossil/info/258bbd5b25

I've added some comments to the asm code in order to help you understand it.

Offline

Board footer

Powered by FluxBB