You've already forked lazarus-ccr
move initialization and finalization instructions to init/finit procs
git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@461 8e941d3f-bd1b-0410-a28a-d453659cc2b4
This commit is contained in:
@@ -1308,6 +1308,9 @@ const
|
||||
|
||||
function IsStoredPropClass(AClass : TClass;PropInfo : PPropInfo) : TPropStoreType;
|
||||
|
||||
procedure initialize_base_service_intf();
|
||||
procedure finalize_base_service_intf();
|
||||
|
||||
{$IFDEF HAS_FORMAT_SETTINGS}
|
||||
var
|
||||
wst_FormatSettings : TFormatSettings;
|
||||
@@ -1316,6 +1319,7 @@ var
|
||||
implementation
|
||||
uses imp_utils, record_rtti, basex_encode;
|
||||
|
||||
|
||||
type
|
||||
PObject = ^TObject;
|
||||
|
||||
@@ -5389,7 +5393,8 @@ begin
|
||||
inherited;
|
||||
end;
|
||||
|
||||
initialization
|
||||
procedure initialize_base_service_intf();
|
||||
begin
|
||||
{$IFDEF HAS_FORMAT_SETTINGS}
|
||||
{$IFDEF FPC}
|
||||
wst_FormatSettings := DefaultFormatSettings;
|
||||
@@ -5400,10 +5405,24 @@ initialization
|
||||
{$ENDIF}
|
||||
{$ENDIF HAS_FORMAT_SETTINGS}
|
||||
|
||||
TypeRegistryInstance := TTypeRegistry.Create();
|
||||
SerializeOptionsRegistryInstance := TSerializeOptionsRegistry.Create();
|
||||
if ( TypeRegistryInstance = nil ) then
|
||||
TypeRegistryInstance := TTypeRegistry.Create();
|
||||
if ( SerializeOptionsRegistryInstance = nil ) then
|
||||
SerializeOptionsRegistryInstance := TSerializeOptionsRegistry.Create();
|
||||
RegisterStdTypes();
|
||||
end;
|
||||
|
||||
finalization
|
||||
procedure finalize_base_service_intf();
|
||||
begin
|
||||
FreeAndNil(SerializeOptionsRegistryInstance);
|
||||
FreeAndNil(TypeRegistryInstance);
|
||||
end;
|
||||
|
||||
|
||||
initialization
|
||||
initialize_base_service_intf();
|
||||
|
||||
finalization
|
||||
finalize_base_service_intf();
|
||||
|
||||
end.
|
||||
|
@@ -101,7 +101,7 @@ end;
|
||||
|
||||
function wst_GetConfigFileName():string;
|
||||
begin
|
||||
Result := ChangeFileExt(GetAppConfigFile(True),'.' + sCONFIG_FILE_NAME);
|
||||
Result := ChangeFileExt(GetAppConfigFile(False,True),'.' + sCONFIG_FILE_NAME);
|
||||
end;
|
||||
|
||||
procedure wst_LoadConfigObject(AConfig: TWstConfigurationObject; AStream : TStream);overload;
|
||||
@@ -132,29 +132,40 @@ begin
|
||||
end;
|
||||
end;
|
||||
|
||||
function wst_CreateDefaultConfigObject() : TWstConfigurationObject;
|
||||
var
|
||||
c, i : Integer;
|
||||
servReg : IServerServiceRegistry;
|
||||
begin
|
||||
Result := TWstConfigurationObject.Create();
|
||||
try
|
||||
servReg := GetServerServiceRegistry();
|
||||
c := servReg.GetCount();
|
||||
Result.Services.SetLength(0);
|
||||
if ( c > 0 ) then begin
|
||||
Result.Services.SetLength(c);
|
||||
for i := 0 to Pred(c) do begin
|
||||
Result.Services[i].Name := servReg.GetName(i);
|
||||
end;
|
||||
end;
|
||||
except
|
||||
FreeAndNil(Result);
|
||||
raise;
|
||||
end;
|
||||
end;
|
||||
|
||||
procedure wst_CreateDefaultFile(ADest : TStream; AConfigObj : TWstConfigurationObject);overload;
|
||||
var
|
||||
locObj : TWstConfigurationObject;
|
||||
c, i : Integer;
|
||||
servReg : IServerServiceRegistry;
|
||||
frmt : IFormatterBase;
|
||||
createdHere : Boolean;
|
||||
begin
|
||||
if ( AConfigObj <> nil ) then
|
||||
locObj := AConfigObj
|
||||
else
|
||||
locObj := TWstConfigurationObject.Create();
|
||||
locObj := wst_CreateDefaultConfigObject();
|
||||
try
|
||||
createdHere := ( AConfigObj = nil );
|
||||
servReg := GetServerServiceRegistry();
|
||||
c := servReg.GetCount();
|
||||
locObj.Services.SetLength(0);
|
||||
if ( c > 0 ) then begin
|
||||
locObj.Services.SetLength(c);
|
||||
for i := 0 to Pred(c) do begin
|
||||
locObj.Services[i].Name := servReg.GetName(i);
|
||||
end;
|
||||
end;
|
||||
frmt := TSOAPBaseFormatter.Create();
|
||||
frmt.SetSerializationStyle(ssNodeSerialization);
|
||||
frmt.BeginObject(sAPPLICATION,TypeInfo(TWstConfigurationObject));
|
||||
@@ -185,12 +196,12 @@ var
|
||||
locFileName : string;
|
||||
begin
|
||||
if ( ConfigurationObjectInstance = nil ) then begin
|
||||
ConfigurationObjectInstance := TWstConfigurationObject.Create();
|
||||
ConfigurationObjectInstance := wst_CreateDefaultConfigObject();
|
||||
locFileName := wst_GetConfigFileName();
|
||||
if FileExists(locFileName) then
|
||||
wst_LoadConfigObject(ConfigurationObjectInstance,locFileName)
|
||||
else
|
||||
wst_CreateDefaultFile(locFileName,ConfigurationObjectInstance);
|
||||
{else
|
||||
wst_CreateDefaultFile(locFileName,ConfigurationObjectInstance);}
|
||||
end;
|
||||
Result := ConfigurationObjectInstance;
|
||||
end;
|
||||
@@ -259,19 +270,29 @@ begin
|
||||
Result := Result + 'False';
|
||||
end;
|
||||
|
||||
initialization
|
||||
procedure initialize_config_objects();
|
||||
begin
|
||||
GetTypeRegistry().Register(sWST_BASE_NS,TypeInfo(TwstConfigService),'Service');
|
||||
GetTypeRegistry().Register(sWST_BASE_NS,TypeInfo(TwstConfigServiceArray),'Services');
|
||||
GetTypeRegistry().Register(sWST_BASE_NS,TypeInfo(TWstConfigurationObject),'WST_Configuration');
|
||||
TwstConfigService.RegisterAttributeProperty('Name');
|
||||
GetTypeRegistry().ItemByTypeInfo[TypeInfo(TwstConfigServiceArray)].RegisterExternalPropertyName('Item','service');
|
||||
end;
|
||||
|
||||
finalization
|
||||
if ( ConfigurationObjectInstance <> nil ) and
|
||||
procedure finalize_config_objects();
|
||||
begin
|
||||
{if ( ConfigurationObjectInstance <> nil ) and
|
||||
( GetServerServiceRegistry.GetCount() <> ConfigurationObjectInstance.Services.Length )
|
||||
then begin
|
||||
wst_CreateDefaultFile(wst_GetConfigFileName(),nil);
|
||||
end;
|
||||
end;}
|
||||
FreeAndNil(ConfigurationObjectInstance);
|
||||
end;
|
||||
|
||||
initialization
|
||||
initialize_config_objects();
|
||||
|
||||
finalization
|
||||
finalize_config_objects();
|
||||
|
||||
end.
|
||||
|
@@ -62,6 +62,9 @@ type
|
||||
):PTypeInfo ;
|
||||
{$ENDIF WST_RECORD_RTTI}
|
||||
|
||||
procedure initialize_record_rtti();
|
||||
procedure finalize_record_rtti();
|
||||
|
||||
implementation
|
||||
uses Classes, imp_utils;
|
||||
|
||||
@@ -336,18 +339,31 @@ begin
|
||||
raise Exception.CreateFmt('"%s" is not a field of "%s".',[AFieldName,GetRecordTypeData()^.Name]);
|
||||
end;
|
||||
|
||||
initialization
|
||||
procedure initialize_record_rtti();
|
||||
begin
|
||||
{$IFDEF WST_RECORD_RTTI}
|
||||
RawTypeInfoList := TList.Create();
|
||||
if ( RawTypeInfoList = nil ) then
|
||||
RawTypeInfoList := TList.Create();
|
||||
{$ENDIF WST_RECORD_RTTI}
|
||||
end;
|
||||
|
||||
finalization
|
||||
procedure finalize_record_rtti();
|
||||
begin
|
||||
{$IFDEF WST_RECORD_RTTI}
|
||||
while ( RawTypeInfoList.Count > 0 ) do begin
|
||||
FreeRawTypeInfo(PTypeInfo(RawTypeInfoList.Items[0]));
|
||||
RawTypeInfoList.Delete(0);
|
||||
if ( RawTypeInfoList = nil ) then begin
|
||||
while ( RawTypeInfoList.Count > 0 ) do begin
|
||||
FreeRawTypeInfo(PTypeInfo(RawTypeInfoList.Items[0]));
|
||||
RawTypeInfoList.Delete(0);
|
||||
end;
|
||||
FreeAndNil(RawTypeInfoList);
|
||||
end;
|
||||
FreeAndNil(RawTypeInfoList);
|
||||
{$ENDIF WST_RECORD_RTTI}
|
||||
end;
|
||||
|
||||
initialization
|
||||
initialize_record_rtti();
|
||||
|
||||
finalization
|
||||
finalize_record_rtti();
|
||||
|
||||
end.
|
||||
|
@@ -210,6 +210,9 @@ Type
|
||||
function GetServiceImplementationRegistry():IServiceImplementationRegistry ;
|
||||
function GetServiceExtensionRegistry():IServiceExtensionRegistry;
|
||||
|
||||
procedure initialize_server_services_intf();
|
||||
procedure finalize_server_services_intf();
|
||||
|
||||
implementation
|
||||
Var
|
||||
FormatterRegistryInst : IFormatterRegistry = Nil;
|
||||
@@ -217,6 +220,7 @@ Var
|
||||
ServiceImplementationRegistryInst : IServiceImplementationRegistry = Nil;
|
||||
ServiceExtensionRegistryInst : IServiceExtensionRegistry = nil;
|
||||
|
||||
|
||||
procedure HandleServiceRequest(
|
||||
ARequestBuffer : IRequestBuffer;
|
||||
AServiceRegistry : IServerServiceRegistry
|
||||
@@ -284,6 +288,7 @@ type
|
||||
function GetName(const AIndex : Integer) : string;
|
||||
end;
|
||||
|
||||
|
||||
{ TBaseFormatterRegistryItem }
|
||||
|
||||
constructor TFormatterRegistryItem.Create(
|
||||
@@ -778,15 +783,31 @@ begin
|
||||
Result := False;
|
||||
end;
|
||||
|
||||
Initialization
|
||||
FormatterRegistryInst := TFormatterRegistry.Create() as IFormatterRegistry;
|
||||
ServerServiceRegistryInst := TServerServiceRegistry.Create() as IServerServiceRegistry;
|
||||
ServiceImplementationRegistryInst := TServiceImplementationRegistry.Create() As IServiceImplementationRegistry;
|
||||
ServiceExtensionRegistryInst := TServiceExtensionRegistry.Create() as IServiceExtensionRegistry;
|
||||
procedure initialize_server_services_intf();
|
||||
begin
|
||||
if ( FormatterRegistryInst = nil ) then
|
||||
FormatterRegistryInst := TFormatterRegistry.Create() as IFormatterRegistry;
|
||||
if ( ServerServiceRegistryInst = nil ) then begin
|
||||
ServerServiceRegistryInst := TServerServiceRegistry.Create() as IServerServiceRegistry;
|
||||
end;
|
||||
if ( ServiceImplementationRegistryInst = nil ) then
|
||||
ServiceImplementationRegistryInst := TServiceImplementationRegistry.Create() As IServiceImplementationRegistry;
|
||||
if ( ServiceExtensionRegistryInst = nil ) then
|
||||
ServiceExtensionRegistryInst := TServiceExtensionRegistry.Create() as IServiceExtensionRegistry;
|
||||
end;
|
||||
|
||||
Finalization
|
||||
procedure finalize_server_services_intf();
|
||||
begin
|
||||
ServiceExtensionRegistryInst := nil;
|
||||
ServiceImplementationRegistryInst := Nil;
|
||||
ServerServiceRegistryInst := Nil;
|
||||
FormatterRegistryInst := Nil;
|
||||
end;
|
||||
|
||||
initialization
|
||||
initialize_server_services_intf();
|
||||
|
||||
finalization
|
||||
finalize_server_services_intf();
|
||||
|
||||
end.
|
||||
|
@@ -1,32 +1,35 @@
|
||||
{$IFDEF FPC}
|
||||
{$mode objfpc}{$H+}
|
||||
{$DEFINE HAS_QWORD}
|
||||
{$UNDEF WST_INTF_DOM}
|
||||
//{$DEFINE USE_INLINE}
|
||||
{$IF Defined(FPC_VERSION) and (FPC_VERSION = 2) }
|
||||
{$IF Defined(FPC_RELEASE) and (FPC_RELEASE > 0) }
|
||||
{$define FPC_211}
|
||||
{$WARNINGS OFF}
|
||||
|
||||
{$IFDEF FPC}
|
||||
{$mode objfpc}{$H+}
|
||||
{$DEFINE HAS_QWORD}
|
||||
{$UNDEF WST_INTF_DOM}
|
||||
//{$DEFINE USE_INLINE}
|
||||
{$IF Defined(FPC_VERSION) and (FPC_VERSION = 2) }
|
||||
{$IF Defined(FPC_RELEASE) and (FPC_RELEASE > 0) }
|
||||
{$define FPC_211}
|
||||
{$IFEND}
|
||||
{$IFEND}
|
||||
{$IF Defined(FPC_211)}
|
||||
{$DEFINE HAS_FORMAT_SETTINGS}
|
||||
{$IFEND}
|
||||
{$IFEND}
|
||||
{$IF Defined(FPC_211)}
|
||||
{$DEFINE HAS_FORMAT_SETTINGS}
|
||||
{$IFEND}
|
||||
{$ENDIF}
|
||||
|
||||
{$IFNDEF FPC}
|
||||
{$DEFINE WST_DELPHI}
|
||||
{$UNDEF HAS_QWORD}
|
||||
{$UNDEF USE_INLINE}
|
||||
{$DEFINE WST_RECORD_RTTI}
|
||||
{$DEFINE WST_INTF_DOM}
|
||||
{$IFDEF VER150}
|
||||
{$DEFINE HAS_FORMAT_SETTINGS}
|
||||
{$ENDIF}
|
||||
{$ENDIF}
|
||||
|
||||
{$IFDEF CPU86}
|
||||
{$DEFINE HAS_COMP}
|
||||
{$ENDIF}
|
||||
{$IFNDEF FPC}
|
||||
{$DEFINE WST_DELPHI}
|
||||
{$DEFINE DELPHI}
|
||||
{$UNDEF HAS_QWORD}
|
||||
{$UNDEF USE_INLINE}
|
||||
{$DEFINE WST_RECORD_RTTI}
|
||||
{$DEFINE WST_INTF_DOM}
|
||||
{$IFDEF VER150}
|
||||
{$DEFINE HAS_FORMAT_SETTINGS}
|
||||
{$ENDIF}
|
||||
{$ENDIF}
|
||||
|
||||
{$IFDEF CPU86}
|
||||
{$DEFINE HAS_COMP}
|
||||
{$ENDIF}
|
||||
|
||||
{$WARNINGS ON}
|
||||
|
||||
|
94
wst/trunk/wst_initialization.pas
Normal file
94
wst/trunk/wst_initialization.pas
Normal file
@@ -0,0 +1,94 @@
|
||||
unit wst_initialization;
|
||||
|
||||
{$mode objfpc}{$H+}
|
||||
|
||||
interface
|
||||
|
||||
uses
|
||||
Classes, SysUtils;
|
||||
|
||||
type
|
||||
|
||||
TwstInitializationProc = procedure();
|
||||
TwstFinalizationProc = TwstInitializationProc;
|
||||
|
||||
procedure wst_initialize();
|
||||
procedure wst_add_init_proc(const AProc : TwstInitializationProc);
|
||||
procedure wst_add_final_proc(const AProc : TwstFinalizationProc);
|
||||
procedure wst_add_procs(const AInitProc : TwstInitializationProc; const AFinalProc : TwstFinalizationProc);
|
||||
procedure wst_finalize();
|
||||
|
||||
|
||||
implementation
|
||||
|
||||
var
|
||||
Initialized : Boolean = False;
|
||||
InitProcs : TList;
|
||||
FinalProcs : TList;
|
||||
|
||||
procedure wst_prepare();
|
||||
begin
|
||||
if ( InitProcs = nil ) then begin
|
||||
Initialized := False;
|
||||
InitProcs := TList.Create();
|
||||
FinalProcs := TList.Create();
|
||||
end;
|
||||
end;
|
||||
|
||||
procedure wst_add_init_proc(const AProc : TwstInitializationProc);
|
||||
begin
|
||||
wst_prepare();
|
||||
if ( AProc <> nil ) and ( InitProcs.IndexOf(AProc) = -1 ) then
|
||||
InitProcs.Add(AProc);
|
||||
end;
|
||||
|
||||
procedure wst_add_final_proc(const AProc : TwstFinalizationProc);
|
||||
begin
|
||||
wst_prepare();
|
||||
if ( AProc <> nil ) and ( FinalProcs.IndexOf(AProc) = -1 ) then
|
||||
FinalProcs.Add(AProc);
|
||||
end;
|
||||
|
||||
procedure wst_add_procs(const AInitProc : TwstInitializationProc; const AFinalProc : TwstFinalizationProc);
|
||||
begin
|
||||
wst_add_init_proc(AInitProc);
|
||||
wst_add_final_proc(AFinalProc);
|
||||
end;
|
||||
|
||||
procedure wst_initialize();
|
||||
var
|
||||
i, c : Integer;
|
||||
p : TwstInitializationProc;
|
||||
begin
|
||||
wst_prepare();
|
||||
Initialized := True;
|
||||
c := InitProcs.Count;
|
||||
for i := 0 to Pred(c) do begin
|
||||
p := TwstInitializationProc(InitProcs[i]);
|
||||
p();
|
||||
end;
|
||||
end;
|
||||
|
||||
procedure wst_finalize();
|
||||
var
|
||||
i, c : Integer;
|
||||
p : TwstInitializationProc;
|
||||
begin
|
||||
if Initialized then begin
|
||||
Initialized := False;
|
||||
if ( FinalProcs <> nil ) then begin
|
||||
c := FinalProcs.Count;
|
||||
for i := 0 to Pred(c) do begin
|
||||
p := TwstFinalizationProc(FinalProcs[i]);
|
||||
p();
|
||||
end;
|
||||
end;
|
||||
end;
|
||||
FreeAndNil(FinalProcs);
|
||||
FreeAndNil(InitProcs);
|
||||
end;
|
||||
|
||||
finalization
|
||||
wst_finalize();
|
||||
|
||||
end.
|
@@ -27,6 +27,9 @@ type
|
||||
Function GetWSTResourceManager(Force : Boolean = True) : TWSTResourceManager;
|
||||
Function SetWSTResourceManager(AValue : TWSTResourceManager) : TWSTResourceManager;
|
||||
|
||||
procedure initialize_wst_resources();
|
||||
procedure finalize_wst_resources();
|
||||
|
||||
implementation
|
||||
|
||||
ResourceString
|
||||
@@ -227,6 +230,7 @@ end;
|
||||
Function SetWSTResourceManager(AValue : TWSTResourceManager) : TWSTResourceManager;
|
||||
|
||||
begin
|
||||
Result := ResMGR;
|
||||
// Copy resources if needed.
|
||||
If Assigned(ResMGR) and Assigned(AValue) then
|
||||
AValue.Assign(ResMGR);
|
||||
@@ -234,8 +238,20 @@ begin
|
||||
ResMGR:=AValue;
|
||||
end;
|
||||
|
||||
initialization
|
||||
finalization
|
||||
procedure initialize_wst_resources();
|
||||
begin
|
||||
|
||||
end;
|
||||
|
||||
procedure finalize_wst_resources();
|
||||
begin
|
||||
FreeAndNil(ResMGR);
|
||||
end;
|
||||
|
||||
initialization
|
||||
initialize_wst_resources();
|
||||
|
||||
finalization
|
||||
finalize_wst_resources();
|
||||
|
||||
end.
|
||||
|
Reference in New Issue
Block a user