unit MyService;
interface
uses
Winapi.Windows,
Winapi.Messages, System.SysUtils, System.Classes,
Vcl.Graphics,
Vcl.Controls,
Vcl.SvcMgr,
Vcl.Dialogs,
AsteriskDataModul, Eventlog;
type
TWorkflowThread = class(TThread)
protected
procedure Execute; override;
var AsteriskCallControlModule: Tbc_Asterisk_CallControl;
end;
TBalyTelephoneControl = class(TService)
procedure ServiceAfterInstall(Sender: TService);
procedure ServiceExecute(Sender: TService);
procedure ServiceStart(Sender: TService; var Started: Boolean);
procedure ServiceStop(Sender: TService; var Stopped: Boolean);
procedure ServiceShutdown(Sender: TService);
private
{ Private-Deklarationen }
fWorkflowThread: TWorkflowThread;
public
function GetServiceController: TServiceController; override;
{ Public-Deklarationen }
end;
var
BalyTelephoneControl: TBalyTelephoneControl;
implementation
{$R *.dfm}
procedure ServiceController(CtrlCode: DWord); stdcall;
begin
BalyTelephoneControl.Controller(CtrlCode);
end;
function TBalyTelephoneControl.GetServiceController: TServiceController;
begin
Result := ServiceController;
end;
procedure TBalyTelephoneControl.ServiceAfterInstall(Sender: TService);
begin
LogMessage('Afterinstall');
end;
procedure TBalyTelephoneControl.ServiceExecute(Sender: TService);
begin
ServiceThread.ProcessRequests(true);
end;
procedure TBalyTelephoneControl.ServiceShutdown(Sender: TService);
begin
if Assigned(fWorkflowThread) then
begin
fWorkflowThread.Terminate;
while WaitForSingleObject(fWorkflowThread.Handle, WaitHint-100) = WAIT_TIMEOUT do
ReportStatus;
FreeAndNil(fWorkflowThread);
end;
end;
procedure TBalyTelephoneControl.ServiceStart(Sender: TService; var Started: Boolean);
begin
Eventlog.EventLog_Success('Service Start','Service Start','');
fWorkflowThread := TWorkflowThread.Create(False);
Started := True;
end;
procedure TBalyTelephoneControl.ServiceStop(Sender: TService; var Stopped: Boolean);
begin
Eventlog.EventLog_Success('Service Stop','Service Stop','');
ServiceShutdown(Sender);
Stopped := True;
end;
{ TWorkflowThread }
procedure TWorkflowThread.Execute;
begin
inherited;
try
if not(assigned(AsteriskCallControlModule)) then
begin
AsteriskCallControlModule := Tbc_Asterisk_CallControl.Create(nil);
end;
while not Terminated do
begin
Sleep(500);
end;
FreeAndNil(AsteriskCallControlModule);
except
on e:
Exception do Eventlog.EventLog_Error('Error',e.Message,'')
end;
end;
end.