Changeset 429


Ignore:
Timestamp:
Oct 17, 2012, 1:21:41 PM (12 years ago)
Author:
chronos
Message:
Location:
ModularSystem
Files:
2 added
9 edited

Legend:

Unmodified
Added
Removed
  • ModularSystem/Demo

    • Property svn:ignore
      •  

        old new  
        55Demo.lps
        66Demo
         7heaptrclog.trc
  • ModularSystem/Demo/Demo.lpi

    r428 r429  
    4141      </Item2>
    4242    </RequiredPackages>
    43     <Units Count="5">
     43    <Units Count="6">
    4444      <Unit0>
    4545        <Filename Value="Demo.lpr"/>
     
    7070        <UnitName Value="UModuleACL"/>
    7171      </Unit4>
     72      <Unit5>
     73        <Filename Value="ULogForm.pas"/>
     74        <IsPartOfProject Value="True"/>
     75        <ComponentName Value="LogForm"/>
     76        <HasResources Value="True"/>
     77        <ResourceBaseClass Value="Form"/>
     78        <UnitName Value="ULogForm"/>
     79      </Unit5>
    7280    </Units>
    7381  </ProjectOptions>
     
    9199    </CodeGeneration>
    92100    <Linking>
     101      <Debugging>
     102        <UseHeaptrc Value="True"/>
     103      </Debugging>
    93104      <Options>
    94105        <Win32>
     
    98109    </Linking>
    99110    <Other>
     111      <CustomOptions Value="-dDEBUG"/>
    100112      <CompilerPath Value="$(CompPath)"/>
    101113    </Other>
  • ModularSystem/Demo/Demo.lpr

    r394 r429  
    88  {$ENDIF}{$ENDIF}
    99  Interfaces, // this includes the LCL widgetset
    10   Forms, UMainForm, UModuleUser, UModuleBase, UModuleACL;
     10  Forms, UMainForm, UModuleUser, UModuleBase, UModuleACL, ULogForm, SysUtils;
    1111
    1212{$R *.res}
    1313
     14{$IFDEF DEBUG}
     15const
     16  HeapTraceLog = 'heaptrclog.trc';
     17{$ENDIF}
     18
    1419begin
     20  {$IFDEF DEBUG}
     21  // Heap trace
     22  DeleteFile(ExtractFilePath(ParamStr(0)) + HeapTraceLog);
     23  SetHeapTraceOutput(ExtractFilePath(ParamStr(0)) + HeapTraceLog);
     24  {$ENDIF}
     25
    1526  RequireDerivedFormResource := True;
    1627  Application.Initialize;
    1728  Application.CreateForm(TMainForm, MainForm);
     29  Application.CreateForm(TLogForm, LogForm);
    1830  Application.Run;
    1931end.
  • ModularSystem/Demo/UMainForm.lfm

    r428 r429  
    11object MainForm: TMainForm
    2   Left = 283
    3   Height = 316
    4   Top = 182
     2  Left = 217
     3  Height = 308
     4  Top = 177
    55  Width = 649
    66  Caption = 'Module test'
    7   ClientHeight = 316
     7  ClientHeight = 308
    88  ClientWidth = 649
    99  OnCreate = FormCreate
     
    1313  object ListViewModules: TListView
    1414    Left = 8
    15     Height = 265
     15    Height = 257
    1616    Top = 8
    1717    Width = 632
     
    5151    OwnerData = True
    5252    PopupMenu = PopupMenu1
     53    ReadOnly = True
    5354    RowSelect = True
    5455    TabOrder = 0
     
    6061    Left = 8
    6162    Height = 25
    62     Top = 281
     63    Top = 273
    6364    Width = 75
    6465    Action = AModuleInstall
     
    6970    Left = 88
    7071    Height = 25
    71     Top = 281
     72    Top = 273
    7273    Width = 75
    7374    Action = AModuleUninstall
     
    7879    Left = 168
    7980    Height = 25
    80     Top = 281
     81    Top = 273
    8182    Width = 75
    8283    Action = AModuleUpdate
     
    8788    Left = 248
    8889    Height = 25
    89     Top = 281
     90    Top = 273
    9091    Width = 75
    9192    Action = AModuleStart
     
    9697    Left = 328
    9798    Height = 25
    98     Top = 281
     99    Top = 273
    99100    Width = 75
    100101    Action = AModuleStop
     
    145146    end
    146147  end
     148  object ModuleManager: TModuleManager
     149    left = 296
     150    top = 72
     151  end
    147152end
  • ModularSystem/Demo/UMainForm.pas

    r428 r429  
    11unit UMainForm;
    22
    3 {$mode objfpc}{$H+}
     3{$mode delphi}{$H+}
    44
    55interface
     
    3232    MenuItem4: TMenuItem;
    3333    MenuItem5: TMenuItem;
     34    ModuleManager: TModuleManager;
    3435    PopupMenu1: TPopupMenu;
    3536    procedure AModuleStartExecute(Sender: TObject);
     
    4748    procedure RegisterModules;
    4849  public
    49     ModuleManager: TModuleManager;
     50    procedure Log(Text: string);
    5051    procedure RefreshList;
    5152  end;
     
    6364
    6465uses
    65   UModuleUser, UModuleBase, UModuleACL;
     66  UModuleUser, UModuleBase, UModuleACL, ULogForm;
    6667
    6768
     
    106107end;
    107108
     109procedure TMainForm.Log(Text: string);
     110begin
     111  LogForm.Memo1.Lines.Add(Text);
     112end;
     113
    108114procedure TMainForm.RefreshList;
    109115begin
     
    116122procedure TMainForm.FormCreate(Sender: TObject);
    117123begin
    118   ModuleManager := TModuleManager.Create(nil);
    119124  RegisterModules;
    120125end;
     
    220225procedure TMainForm.FormDestroy(Sender: TObject);
    221226begin
    222   FreeAndNil(ModuleManager);
    223227end;
    224228
     
    226230begin
    227231  RefreshList;
     232  LogForm.Show;
    228233end;
    229234
  • ModularSystem/Demo/UModuleACL.pas

    r428 r429  
    1212
    1313  TModuleACL = class(TModule)
     14  protected
     15    procedure DoInstall; override;
     16    procedure DoStart; override;
     17    procedure DoStop; override;
     18    procedure DoUninstall; override;
     19  public
    1420    constructor Create(AOwner: TComponent); override;
    1521    destructor Destroy; override;
     
    1925implementation
    2026
     27uses
     28  UMainForm;
     29
    2130{ TModuleACL }
     31
     32procedure TModuleACL.DoStart;
     33begin
     34  MainForm.Log(Identification + ' started');
     35end;
     36
     37procedure TModuleACL.DoStop;
     38begin
     39  MainForm.Log(Identification + ' stopped');
     40end;
     41
     42procedure TModuleACL.DoInstall;
     43begin
     44  MainForm.Log(Identification + ' installed');
     45end;
     46
     47procedure TModuleACL.DoUninstall;
     48begin
     49  MainForm.Log(Identification + ' uninstalled');
     50end;
    2251
    2352constructor TModuleACL.Create(AOwner: TComponent);
  • ModularSystem/Demo/UModuleBase.pas

    r428 r429  
    99
    1010type
     11
     12  { TModuleBase }
     13
    1114  TModuleBase = class(TModule)
     15  protected
     16    procedure DoStart; override;
     17    procedure DoStop; override;
     18    procedure DoInstall; override;
     19    procedure DoUninstall; override;
     20  public
    1221    constructor Create(AOwner: TComponent); override;
    1322    destructor Destroy; override;
     
    1726implementation
    1827
     28uses
     29  UMainForm;
     30
    1931{ TModuleUser }
     32
     33procedure TModuleBase.DoStart;
     34begin
     35  MainForm.Log(Identification + ' started');
     36end;
     37
     38procedure TModuleBase.DoStop;
     39begin
     40  MainForm.Log(Identification + ' stopped');
     41end;
     42
     43procedure TModuleBase.DoInstall;
     44begin
     45  MainForm.Log(Identification + ' installed');
     46end;
     47
     48procedure TModuleBase.DoUninstall;
     49begin
     50  MainForm.Log(Identification + ' uninstalled');
     51end;
    2052
    2153constructor TModuleBase.Create(AOwner: TComponent);
  • ModularSystem/Demo/UModuleUser.pas

    r428 r429  
    1313
    1414  TModuleUser = class(TModule)
     15  protected
     16    procedure DoInstall; override;
     17    procedure DoStart; override;
     18    procedure DoStop; override;
     19    procedure DoUninstall; override;
     20  public
    1521    constructor Create(AOwner: TComponent); override;
    1622    destructor Destroy; override;
     
    1925implementation
    2026
     27uses
     28  UMainForm;
     29
    2130{ TModuleUser }
     31
     32procedure TModuleUser.DoStart;
     33begin
     34  MainForm.Log(Identification + ' started');
     35end;
     36
     37procedure TModuleUser.DoStop;
     38begin
     39  MainForm.Log(Identification + ' stopped');
     40end;
     41
     42procedure TModuleUser.DoInstall;
     43begin
     44  MainForm.Log(Identification + ' installed');
     45end;
     46
     47procedure TModuleUser.DoUninstall;
     48begin
     49  MainForm.Log(Identification + ' uninstalled');
     50end;
    2251
    2352constructor TModuleUser.Create(AOwner: TComponent);
  • ModularSystem/UModularSystem.pas

    r428 r429  
    2222    FRunning: Boolean;
    2323    FInstalled: Boolean;
    24     Manager: TModuleManager;
     24    FManager: TModuleManager;
    2525    FVersion: string;
    2626    FIdentification: string;
     
    3434    procedure SetRunning(AValue: Boolean);
    3535  protected
    36     procedure BeforeStart; virtual;
    37     procedure AfterStart; virtual;
    38     procedure BeforeStop; virtual;
    39     procedure AfterStop; virtual;
     36    procedure DoStart; virtual;
     37    procedure DoStop; virtual;
     38    procedure DoInstall; virtual;
     39    procedure DoUninstall; virtual;
     40    procedure DoUpgrade; virtual;
    4041  public
    4142    API: TAPI;
    42     procedure Start; virtual;
    43     procedure Stop; virtual;
    44     procedure Install; virtual;
    45     procedure Uninstall; virtual;
    46     procedure Upgrade; virtual;
     43    procedure Start;
     44    procedure Stop;
     45    procedure Install;
     46    procedure Uninstall;
     47    procedure Upgrade;
    4748    procedure EnumModulesStart(ModuleList: TStringList);
    4849    procedure EnumModulesStop(ModuleList: TStringList);
     
    5657    property Enabled: Boolean read FEnabled write SetEnabled;
    5758  published
     59    property Manager: TModuleManager read FManager;
    5860    property Version: string read FVersion write FVersion;
    5961    property Identification: string read FIdentification write FIdentification;
     
    260262begin
    261263  Modules.Add(Module);
    262   Module.Manager := Self;
     264  Module.FManager := Self;
    263265  Module.API := API;
    264266  Module.Enabled := Enabled;
     
    310312  inherited;
    311313  Modules := TObjectList.Create;
     314  //Modules.OwnsObjects := False;
    312315end;
    313316
     
    316319  StopAll;
    317320  FreeAndNil(Modules);
    318   inherited Destroy;
     321  inherited;
    319322end;
    320323
     
    344347    RootKey := Context.RootKey;
    345348    for I := 0 to Modules.Count - 1 do
    346     with TModule(Modules[I]) do begin
     349    with TModule(Modules[I]) do
     350    if Enabled then begin
    347351      OpenKey(Context.Key + '\' + Identification, True);
    348352      WriteBool('Run', Running);
     
    361365end;
    362366
    363 procedure TModule.BeforeStart;
    364 begin
    365   if Running then Exit;
     367procedure TModule.DoStart;
     368begin
     369
     370end;
     371
     372procedure TModule.DoStop;
     373begin
     374
     375end;
     376
     377procedure TModule.DoInstall;
     378begin
     379
     380end;
     381
     382procedure TModule.DoUninstall;
     383begin
     384
     385end;
     386
     387procedure TModule.DoUpgrade;
     388begin
     389
     390end;
     391
     392procedure TModule.SetInstalled(AValue: Boolean);
     393begin
     394  if FInstalled = AValue then Exit;
     395  if AValue then Install else Uninstall;
     396end;
     397
     398procedure TModule.SetEnabled(AValue: Boolean);
     399begin
     400  if FEnabled = AValue then Exit;
     401  FEnabled := AValue;
     402  if not FEnabled and FInstalled then Uninstall;
     403end;
     404
     405procedure TModule.Start;
     406begin
     407  if not Enabled or Running then Exit;
    366408  if not Installed then Install;
    367409  Manager.StartDependencies(Identification, Dependencies);
    368 end;
    369 
    370 procedure TModule.AfterStart;
    371 begin
     410  DoStart;
    372411  FRunning := True;
    373412end;
    374413
    375 procedure TModule.BeforeStop;
     414procedure TModule.Stop;
    376415begin
    377416  if not Running then Exit;
    378417  FRunning := False;
    379418  Manager.StopDependencies(Identification);
    380 end;
    381 
    382 procedure TModule.AfterStop;
    383 begin
    384 end;
    385 
    386 procedure TModule.SetInstalled(AValue: Boolean);
    387 begin
    388   if FInstalled = AValue then Exit;
    389   if AValue then Install else Uninstall;
    390 end;
    391 
    392 procedure TModule.SetEnabled(AValue: Boolean);
    393 begin
    394   if FEnabled = AValue then Exit;
    395   FEnabled := AValue;
    396   if not FEnabled and FInstalled then Uninstall;
    397 end;
    398 
    399 procedure TModule.Start;
    400 begin
    401   BeforeStart;
    402   AfterStart;
    403 end;
    404 
    405 procedure TModule.Stop;
    406 begin
    407   BeforeStop;
    408   AfterStop;
     419  DoStop;
    409420end;
    410421
    411422procedure TModule.Install;
    412423begin
    413   if Installed then Exit;
     424  if not Enabled or Installed then Exit;
    414425  Manager.InstallDependencies(Identification, Dependencies);
    415426  FInstalled := True;
    416427  if Assigned(Manager.FOnModuleChange) then
    417428    Manager.FOnModuleChange(Manager, Self);
     429  DoInstall;
    418430end;
    419431
     
    424436  Manager.UninstallDependencies(Identification);
    425437  FInstalled := False;
     438  DoUninstall;
    426439  if Assigned(Manager.FOnModuleChange) then
    427440    Manager.FOnModuleChange(Manager, Self);
     
    430443procedure TModule.Upgrade;
    431444begin
    432   if not Running then Exit;
     445  if not Enabled or not Installed then Exit;
     446  if Running then try
     447    Stop;
     448    DoUpgrade;
     449  finally
     450    Start;
     451  end else DoUpgrade;
    433452end;
    434453
     
    474493begin
    475494  Running := False;
    476   Description.Free;
    477   Dependencies.Free;
    478   inherited Destroy;
     495  FreeAndNil(FDescription);
     496  FreeAndNil(FDependencies);
     497  inherited;
    479498end;
    480499
Note: See TracChangeset for help on using the changeset viewer.