-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserviceunit.pas
152 lines (112 loc) · 3.31 KB
/
serviceunit.pas
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
unit serviceunit;
//------------------------------------------------------------------------------
// Сервис
//------------------------------------------------------------------------------
{$mode objfpc}{$H+}
interface
uses
Classes, SysUtils, FileUtil, Forms, DaemonApp, PipeCommThreadUnit,
IniFiles, AtolKKTUnit, LoggerUnit;
const
APP_NAME = 'AtolKKTService';
type
{ TAtolKKTService }
TAtolKKTService = class(TDaemon)
ApplicationProperties1: TApplicationProperties;
procedure ApplicationProperties1Exception(Sender: TObject; E: Exception);
procedure DataModuleContinue(Sender: TCustomDaemon; var OK: Boolean);
procedure DataModuleCreate(Sender: TObject);
procedure DataModuleDestroy(Sender: TObject);
//procedure DataModuleExecute(Sender: TCustomDaemon);
procedure DataModuleShutDown(Sender: TCustomDaemon);
procedure DataModuleStart(Sender: TCustomDaemon; var OK: Boolean);
procedure DataModuleStop(Sender: TCustomDaemon; var OK: Boolean);
private
atol_cash_register_pipe: string;
PipeComm: TPipeComm;
procedure InitPipe;
procedure ClosePipe;
public
end;
var
AtolKKTService: TAtolKKTService;
implementation
procedure RegisterDaemon;
begin
RegisterDaemonClass(TAtolKKTService)
end;
{$R *.lfm}
{ TAtolKKTService }
procedure TAtolKKTService.DataModuleStart(Sender: TCustomDaemon; var OK: Boolean);
var ini: TIniFile;
local_log: boolean;
begin
ini := TIniFile.Create(ExtractFilePath(ParamStr(0))+'ini.ini');
local_log := ini.ReadBool('Logs','LocalLog',True);
if (local_log) then
MyLogger.startLog();
//event_log := ini.ReadBool('Logs','EventLog',True);
MyLogger.LogText('Служба запускается');
atol_cash_register_pipe := ini.ReadString('Options','AtolCashRegisterPipe','');
ini.Free;
MyLogger.LogText('init pipe');
// запускаем поток чтения PIPE
InitPipe;
MyLogger.LogText('pipe init is done');
MyLogger.LogText('Служба запущена');
OK := true;
ReportStatus;
end;
procedure TAtolKKTService.DataModuleStop(Sender: TCustomDaemon; var OK: Boolean);
begin
ClosePipe;
MyLogger.LogText('pipe is closed (on stop)');
OK := true;
ReportStatus;
end;
procedure TAtolKKTService.ApplicationProperties1Exception(Sender: TObject; E: Exception);
var err_code: integer;
begin
if (E is EATOLException) then
begin
err_code := (E as EATOLException).ErrorCode;
end
else err_code := 0;
MyLogger.LogError(err_code, e.Message);
end;
procedure TAtolKKTService.DataModuleContinue(Sender: TCustomDaemon;
var OK: Boolean);
begin
MyLogger.LogText('Служба возобновлена!');
OK := true;
ReportStatus;
end;
procedure TAtolKKTService.DataModuleCreate(Sender: TObject);
begin
end;
procedure TAtolKKTService.DataModuleDestroy(Sender: TObject);
begin
end;
{
procedure TAtolKKTService.DataModuleExecute(Sender: TCustomDaemon);
begin
MyLogger.LogText('Служба запущена!');
ReportStatus;
end;
}
procedure TAtolKKTService.DataModuleShutDown(Sender: TCustomDaemon);
begin
ClosePipe;
MyLogger.LogText('pipe is closed (on shutdown)');
end;
procedure TAtolKKTService.InitPipe;
begin
PipeComm := TPipeComm.Create(False, atol_cash_register_pipe);
end;
procedure TAtolKKTService.ClosePipe;
begin
PipeComm.Terminate;
end;
initialization
RegisterDaemon;
end.