unit uRODLIntfConverter; {----------------------------------------------------------------------------} { RemObjects SDK Library - CodeGen2 } { } { compiler: Delphi 5 and up, Kylix 2 and up } { platform: Win32, Linux } { } { (c)opyright RemObjects Software. all rights reserved. } { } { Using this code requires a valid license of the RemObjects SDK } { which can be obtained at http://www.remobjects.com. } {----------------------------------------------------------------------------} {$IFDEF LINUX} {$I ../RemObjects.inc} {$ELSE} {$I ..\RemObjects.inc} {$ENDIF LINUX} interface uses Classes, IniFiles, Contnrs, uRODLTemplateBasedConverter, uRODLSplitableConverter, uRODL, uROClasses, uRODLLineStream; type TRODLIntfConverter = class (TRODLSplitableConverter) private protected function GetSplitFilesSuffix: string; override; procedure AddEntityTypes(Types: {$IFDEF FPC}TStringList{$ELSE}THashedStringList{$ENDIF}; const AEntity: TRODLEntity; const unitName: string); override; procedure SetupFiles(const aLibrary: TRODLLibrary); override; function ValidateTargetEntity(const aLibrary: TRODLLibrary; const aTargetEntity: string): boolean; override; function GetServicesSectionClass: TServicesSectionClass; override; function GetEventSinksSectionClass: TEventSinksSectionClass; override; public constructor Create(const aLibrary: TRODLLibrary; const aTemplateFileName: string; const aUnitName: string; const ASplit: Boolean = False; const AOutputDir: string = ''; const AWrapperTemplateName: string = ''; const aTargetEntities: string = ''); override; end; TIntfServicesSection = class (TServicesSection) protected function GetAncestorName(const aService: TRODLBaseService): string; override; function GetProxyAncestorName(const aService: TRODLBaseService): string; override; end; TIntfEventSinksSection = class (TEventSinksSection) protected function GetAncestorName(const aService: TRODLBaseService): string; override; end; implementation uses SysUtils, uRODLTemplateBasedConverterUtils; { TRODLIntfConverter } procedure TRODLIntfConverter.AddEntityTypes(Types: {$IFDEF FPC}TStringList{$ELSE}THashedStringList{$ENDIF}; const AEntity: TRODLEntity; const unitName: string); {var enum: TRODLEnum; I: Integer;} begin if AEntity is TRODLService then begin Types.Values['I' + AEntity.Name] := unitName; Types.Values['T' + AEntity.Name + '_Proxy'] := unitName; Types.Values['Co' + AEntity.Name] := unitName; end else if AEntity is TRODLEnum then begin Types.Values[AEntity.Name] := unitName; // Not sure if there is a way to do something here for the enums { enum := AEntity as TRODLEnum; for I := 0 to enum.Count - 1 do begin Types.Values[GetEnumsSectionClass.GetEnumValueName(enum, I)] := unitName; end;} end else begin inherited AddEntityTypes(Types, AEntity, unitName); end; end; constructor TRODLIntfConverter.Create(const aLibrary: TRODLLibrary; const aTemplateFileName: string; const aUnitName: string; const ASplit: Boolean = False; const AOutputDir: string = ''; const AWrapperTemplateName: string = ''; const aTargetEntities: string = ''); begin // Call inherited with nil so that convert is not called, allowing us // to setup the optional sections. Setting up the optional sections before // calling the inherited Create is not an option, the section list would // not have been created inherited Create(nil, aTemplateFileName, aUnitName, ASplit, AOutputDir, AWrapperTemplateName, aTargetEntities); // Setup the optional section Sections.Add(TIfWSDLSection.Create(Self)); // Now that everything is done, call convert if need be. if (aLibrary <> nil) then Convert(aLibrary); end; function TRODLIntfConverter.GetEventSinksSectionClass: TEventSinksSectionClass; begin Result := TIntfEventSinksSection; end; function TRODLIntfConverter.GetServicesSectionClass: TServicesSectionClass; begin Result := TIntfServicesSection; end; function TRODLIntfConverter.GetSplitFilesSuffix: string; begin Result := DEFAULT_INTF_SUFFIX; end; procedure TRODLIntfConverter.SetupFiles(const aLibrary: TRODLLibrary); var I: Integer; newFile: TRODLSplitableConverterFile; begin FFiles.Clear; // one file per service for I := 0 to FOrderedServices.Count - 1 do begin newFile := TRODLSplitableConverterFile.Create(aLibrary, Self); newFile.Services.Add(FOrderedServices.Objects[I]); FFiles.Add(newFile); end; // one file for all enums newFile := TRODLSplitableConverterFile.Create(aLibrary, Self); for I := 0 to aLibrary.EnumCount - 1 do newFile.Enums.Add(aLibrary.Enums[I]); if newFile.Enums.Count > 0 then begin FFiles.Add(newFile); // because we put all enums in one file, we set the file name to "Enums" newFile.UnitName := FLibrary.Name + '_Enums' + SplitFilesSuffix; end; // one file per array for I := 0 to aLibrary.ArrayCount - 1 do begin newFile := TRODLSplitableConverterFile.Create(aLibrary, Self); newFile.Arrays.Add(aLibrary.Arrays[I]); FFiles.Add(newFile); end; // one file per struct for I := 0 to aLibrary.StructCount - 1 do begin newFile := TRODLSplitableConverterFile.Create(aLibrary, Self); newFile.Structs.Add(aLibrary.Structs[I]); FFiles.Add(newFile); end; // one file per event sink for I := 0 to aLibrary.EventSinkCount - 1 do begin newFile := TRODLSplitableConverterFile.Create(aLibrary, Self); newFile.EventSinks.Add(aLibrary.EventSinks[I]); FFiles.Add(newFile); end; // one file per exception for I := 0 to aLibrary.ExceptionCount - 1 do begin newFile := TRODLSplitableConverterFile.Create(aLibrary, Self); newFile.Exceptions.Add(aLibrary.Exceptions[I]); FFiles.Add(newFile); end; end; function TRODLIntfConverter.ValidateTargetEntity(const aLibrary: TRODLLibrary; const aTargetEntity: string): boolean; begin Result := True; end; { TIntfServicesSection } function TIntfServicesSection.GetAncestorName( const aService: TRODLBaseService): string; begin Result := inherited GetAncestorName(aService); if Length(Result) > 0 then Result := 'I' + Result; end; function TIntfServicesSection.GetProxyAncestorName( const aService: TRODLBaseService): string; begin Result := inherited GetProxyAncestorName(aService); if (Length(Result) > 0) and (Result <> DEFAULT_SERVICE_PROXY_ANCESTOR_NAME) then Result := 'T' + Result; end; { TIntfEventSinksSection } function TIntfEventSinksSection.GetAncestorName( const aService: TRODLBaseService): string; begin Result := inherited GetAncestorName(aService); if Length(Result) > 0 then Result := 'I' + Result; end; end.