Comments (3)
First implementation (warning: it contains a leak):
(*
Brook FCL HTTP Daemon Broker unit.
Copyright (C) 2013 Silvio Clecio.
http://brookframework.org
All contributors:
Plase see the file CONTRIBUTORS.txt, included in this
distribution.
See the file LICENSE.txt, included in this distribution,
for details about the copyright.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
*)
unit BrookFCLHTTPDaemonBroker;
{$mode objfpc}{$H+}
interface
uses
{$IFDEF MSWINDOWS}
ServiceManager,
{$ENDIF}
BrookFCLHTTPAppBroker, BrookApplication, BrookConsts, DaemonApp, Classes,
SysUtils;
type
{ TBrookDaemonApplication }
TBrookDaemonApplication = class(TInterfacedObject, IBrookApplication)
public
constructor Create;
function Instance: TObject;
procedure Run;
end;
{ TBrookDaemonThread }
TBrookDaemonThread = class(TThread)
public
procedure Execute; override;
end;
{ TBrookHTTPDaemon }
TBrookHTTPDaemon = class(TCustomDaemon)
private
FThread: TThread;
public
function Install: Boolean; override;
function Uninstall: Boolean; override;
function Start: Boolean; override;
function Stop: Boolean; override;
procedure Log(const AMsg: string);
end;
{ TBrookHTTPDaemonMapper }
TBrookHTTPDaemonMapper = class(TCustomDaemonMapper)
public
constructor Create(AOwner: TComponent); override;
end;
implementation
var
_BrookHTTPApp: IBrookApplication = nil;
function BrookHTTPApp: IBrookApplication;
begin
if not Assigned(_BrookHTTPApp) then
_BrookHTTPApp := TBrookApplication.Create;
Result := _BrookHTTPApp;
end;
{ TBrookDaemonApplication }
constructor TBrookDaemonApplication.Create;
begin
Application.Title := 'Brook HTTP daemon application';
end;
function TBrookDaemonApplication.Instance: TObject;
begin
Result := BrookHTTPApp.Instance;
end;
procedure TBrookDaemonApplication.Run;
begin
Application.Run;
end;
{ TBrookDaemonThread }
procedure TBrookDaemonThread.Execute;
begin
BrookHTTPApp.Run;
end;
{ TBrookHTTPDaemon }
function TBrookHTTPDaemon.Start: Boolean;
begin
Result := inherited Start;
FThread := TBrookDaemonThread.Create(True);
FThread.Start;
Log('Start.');
end;
function TBrookHTTPDaemon.Stop: Boolean;
begin
Result := inherited Stop;
FThread.Terminate;
Log('Stop.');
end;
function TBrookHTTPDaemon.Install: Boolean;
{$IFDEF MSWINDOWS}
var
VSM: TServiceManager;
{$ENDIF}
begin
Result := inherited Install;
{$IFDEF MSWINDOWS}
VSM := TServiceManager.Create(nil);
try
VSM.Connect;
if VSM.Connected then
VSM.StartService(BROOK_HTTP_DAEMON_NAME, nil);
VSM.Disconnect;
finally
VSM.Free;
end;
{$ENDIF}
Log('Install.');
end;
function TBrookHTTPDaemon.Uninstall: Boolean;
{$IFDEF MSWINDOWS}
var
VSM: TServiceManager;
{$ENDIF}
begin
Result := inherited Uninstall;
{$IFDEF MSWINDOWS}
VSM := TServiceManager.Create(nil);
try
VSM.Connect;
if VSM.Connected then
VSM.StopService(BROOK_HTTP_DAEMON_NAME, True);
VSM.Disconnect;
finally
VSM.Free;
end;
{$ENDIF}
Log('Uninstall.');
end;
procedure TBrookHTTPDaemon.Log(const AMsg: string);
begin
Application.Log(etCustom, ClassName + ': ' + AMsg);
end;
{ TBrookHTTPDaemonMapper }
constructor TBrookHTTPDaemonMapper.Create(AOwner: TComponent);
var
VDaemonDef: TDaemonDef;
begin
inherited Create(AOwner);
VDaemonDef := DaemonDefs.Add as TDaemonDef;
VDaemonDef.Description := 'Brook HTTP daemon.';
VDaemonDef.DisplayName := 'Brook daemon';
VDaemonDef.Name := BROOK_HTTP_DAEMON_NAME;
VDaemonDef.DaemonClassName := 'TBrookHTTPDaemon';
VDaemonDef.WinBindings.ServiceType := stWin32;
end;
initialization
RegisterDaemonClass(TBrookHTTPDaemon);
RegisterDaemonMapper(TBrookHTTPDaemonMapper);
BrookUnregisterApp;
BrookRegisterApp(TBrookDaemonApplication.Create);
end.
from brookframework.
I sent a issue for Free Pascal team:
http://bugs.freepascal.org/view.php?id=23647
from brookframework.
Bug fixed (by myself :p ) in FCL (http://bugs.freepascal.org/view.php?id=23647).
from brookframework.
Related Issues (20)
- Why plugins projects on github to brookframework is closing? HOT 4
- Telegram plugin for brookframework HOT 15
- i18n HOT 4
- Version 4 ? HOT 14
- libbrook.pas in Source HOT 3
- tardigrade demos throwing errors in libbrook HOT 4
- Server requirements? HOT 4
- dopf & LastInsertID HOT 4
- httprouter.lpr throwing error HOT 2
- How am I supposed to free worker thread in brook daemon? HOT 9
- Use legacy application with tardigrade HOT 19
- CPU Activity is high for tardigrade projects BROOK4 HOT 4
- More documentation HOT 1
- Can't get POST request data HOT 13
- Brookframework with sagui (legacy) HOT 11
- HTTP Client HOT 1
- Where did the captcha plugin for 4.0 go? HOT 1
- Some suggestion about JTemplate? HOT 3
- [IDEA] New repository HOT 1
- EBrookHTTPServer: Failed to send data in request for HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from brookframework.