Changeset 429
- Timestamp:
- Oct 17, 2012, 1:21:41 PM (12 years ago)
- Location:
- ModularSystem
- Files:
-
- 2 added
- 9 edited
Legend:
- Unmodified
- Added
- Removed
-
ModularSystem/Demo
- Property svn:ignore
-
old new 5 5 Demo.lps 6 6 Demo 7 heaptrclog.trc
-
- Property svn:ignore
-
ModularSystem/Demo/Demo.lpi
r428 r429 41 41 </Item2> 42 42 </RequiredPackages> 43 <Units Count=" 5">43 <Units Count="6"> 44 44 <Unit0> 45 45 <Filename Value="Demo.lpr"/> … … 70 70 <UnitName Value="UModuleACL"/> 71 71 </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> 72 80 </Units> 73 81 </ProjectOptions> … … 91 99 </CodeGeneration> 92 100 <Linking> 101 <Debugging> 102 <UseHeaptrc Value="True"/> 103 </Debugging> 93 104 <Options> 94 105 <Win32> … … 98 109 </Linking> 99 110 <Other> 111 <CustomOptions Value="-dDEBUG"/> 100 112 <CompilerPath Value="$(CompPath)"/> 101 113 </Other> -
ModularSystem/Demo/Demo.lpr
r394 r429 8 8 {$ENDIF}{$ENDIF} 9 9 Interfaces, // this includes the LCL widgetset 10 Forms, UMainForm, UModuleUser, UModuleBase, UModuleACL ;10 Forms, UMainForm, UModuleUser, UModuleBase, UModuleACL, ULogForm, SysUtils; 11 11 12 12 {$R *.res} 13 13 14 {$IFDEF DEBUG} 15 const 16 HeapTraceLog = 'heaptrclog.trc'; 17 {$ENDIF} 18 14 19 begin 20 {$IFDEF DEBUG} 21 // Heap trace 22 DeleteFile(ExtractFilePath(ParamStr(0)) + HeapTraceLog); 23 SetHeapTraceOutput(ExtractFilePath(ParamStr(0)) + HeapTraceLog); 24 {$ENDIF} 25 15 26 RequireDerivedFormResource := True; 16 27 Application.Initialize; 17 28 Application.CreateForm(TMainForm, MainForm); 29 Application.CreateForm(TLogForm, LogForm); 18 30 Application.Run; 19 31 end. -
ModularSystem/Demo/UMainForm.lfm
r428 r429 1 1 object MainForm: TMainForm 2 Left = 2 833 Height = 3 164 Top = 1 822 Left = 217 3 Height = 308 4 Top = 177 5 5 Width = 649 6 6 Caption = 'Module test' 7 ClientHeight = 3 167 ClientHeight = 308 8 8 ClientWidth = 649 9 9 OnCreate = FormCreate … … 13 13 object ListViewModules: TListView 14 14 Left = 8 15 Height = 2 6515 Height = 257 16 16 Top = 8 17 17 Width = 632 … … 51 51 OwnerData = True 52 52 PopupMenu = PopupMenu1 53 ReadOnly = True 53 54 RowSelect = True 54 55 TabOrder = 0 … … 60 61 Left = 8 61 62 Height = 25 62 Top = 2 8163 Top = 273 63 64 Width = 75 64 65 Action = AModuleInstall … … 69 70 Left = 88 70 71 Height = 25 71 Top = 2 8172 Top = 273 72 73 Width = 75 73 74 Action = AModuleUninstall … … 78 79 Left = 168 79 80 Height = 25 80 Top = 2 8181 Top = 273 81 82 Width = 75 82 83 Action = AModuleUpdate … … 87 88 Left = 248 88 89 Height = 25 89 Top = 2 8190 Top = 273 90 91 Width = 75 91 92 Action = AModuleStart … … 96 97 Left = 328 97 98 Height = 25 98 Top = 2 8199 Top = 273 99 100 Width = 75 100 101 Action = AModuleStop … … 145 146 end 146 147 end 148 object ModuleManager: TModuleManager 149 left = 296 150 top = 72 151 end 147 152 end -
ModularSystem/Demo/UMainForm.pas
r428 r429 1 1 unit UMainForm; 2 2 3 {$mode objfpc}{$H+}3 {$mode delphi}{$H+} 4 4 5 5 interface … … 32 32 MenuItem4: TMenuItem; 33 33 MenuItem5: TMenuItem; 34 ModuleManager: TModuleManager; 34 35 PopupMenu1: TPopupMenu; 35 36 procedure AModuleStartExecute(Sender: TObject); … … 47 48 procedure RegisterModules; 48 49 public 49 ModuleManager: TModuleManager;50 procedure Log(Text: string); 50 51 procedure RefreshList; 51 52 end; … … 63 64 64 65 uses 65 UModuleUser, UModuleBase, UModuleACL ;66 UModuleUser, UModuleBase, UModuleACL, ULogForm; 66 67 67 68 … … 106 107 end; 107 108 109 procedure TMainForm.Log(Text: string); 110 begin 111 LogForm.Memo1.Lines.Add(Text); 112 end; 113 108 114 procedure TMainForm.RefreshList; 109 115 begin … … 116 122 procedure TMainForm.FormCreate(Sender: TObject); 117 123 begin 118 ModuleManager := TModuleManager.Create(nil);119 124 RegisterModules; 120 125 end; … … 220 225 procedure TMainForm.FormDestroy(Sender: TObject); 221 226 begin 222 FreeAndNil(ModuleManager);223 227 end; 224 228 … … 226 230 begin 227 231 RefreshList; 232 LogForm.Show; 228 233 end; 229 234 -
ModularSystem/Demo/UModuleACL.pas
r428 r429 12 12 13 13 TModuleACL = class(TModule) 14 protected 15 procedure DoInstall; override; 16 procedure DoStart; override; 17 procedure DoStop; override; 18 procedure DoUninstall; override; 19 public 14 20 constructor Create(AOwner: TComponent); override; 15 21 destructor Destroy; override; … … 19 25 implementation 20 26 27 uses 28 UMainForm; 29 21 30 { TModuleACL } 31 32 procedure TModuleACL.DoStart; 33 begin 34 MainForm.Log(Identification + ' started'); 35 end; 36 37 procedure TModuleACL.DoStop; 38 begin 39 MainForm.Log(Identification + ' stopped'); 40 end; 41 42 procedure TModuleACL.DoInstall; 43 begin 44 MainForm.Log(Identification + ' installed'); 45 end; 46 47 procedure TModuleACL.DoUninstall; 48 begin 49 MainForm.Log(Identification + ' uninstalled'); 50 end; 22 51 23 52 constructor TModuleACL.Create(AOwner: TComponent); -
ModularSystem/Demo/UModuleBase.pas
r428 r429 9 9 10 10 type 11 12 { TModuleBase } 13 11 14 TModuleBase = class(TModule) 15 protected 16 procedure DoStart; override; 17 procedure DoStop; override; 18 procedure DoInstall; override; 19 procedure DoUninstall; override; 20 public 12 21 constructor Create(AOwner: TComponent); override; 13 22 destructor Destroy; override; … … 17 26 implementation 18 27 28 uses 29 UMainForm; 30 19 31 { TModuleUser } 32 33 procedure TModuleBase.DoStart; 34 begin 35 MainForm.Log(Identification + ' started'); 36 end; 37 38 procedure TModuleBase.DoStop; 39 begin 40 MainForm.Log(Identification + ' stopped'); 41 end; 42 43 procedure TModuleBase.DoInstall; 44 begin 45 MainForm.Log(Identification + ' installed'); 46 end; 47 48 procedure TModuleBase.DoUninstall; 49 begin 50 MainForm.Log(Identification + ' uninstalled'); 51 end; 20 52 21 53 constructor TModuleBase.Create(AOwner: TComponent); -
ModularSystem/Demo/UModuleUser.pas
r428 r429 13 13 14 14 TModuleUser = class(TModule) 15 protected 16 procedure DoInstall; override; 17 procedure DoStart; override; 18 procedure DoStop; override; 19 procedure DoUninstall; override; 20 public 15 21 constructor Create(AOwner: TComponent); override; 16 22 destructor Destroy; override; … … 19 25 implementation 20 26 27 uses 28 UMainForm; 29 21 30 { TModuleUser } 31 32 procedure TModuleUser.DoStart; 33 begin 34 MainForm.Log(Identification + ' started'); 35 end; 36 37 procedure TModuleUser.DoStop; 38 begin 39 MainForm.Log(Identification + ' stopped'); 40 end; 41 42 procedure TModuleUser.DoInstall; 43 begin 44 MainForm.Log(Identification + ' installed'); 45 end; 46 47 procedure TModuleUser.DoUninstall; 48 begin 49 MainForm.Log(Identification + ' uninstalled'); 50 end; 22 51 23 52 constructor TModuleUser.Create(AOwner: TComponent); -
ModularSystem/UModularSystem.pas
r428 r429 22 22 FRunning: Boolean; 23 23 FInstalled: Boolean; 24 Manager: TModuleManager;24 FManager: TModuleManager; 25 25 FVersion: string; 26 26 FIdentification: string; … … 34 34 procedure SetRunning(AValue: Boolean); 35 35 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; 40 41 public 41 42 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; 47 48 procedure EnumModulesStart(ModuleList: TStringList); 48 49 procedure EnumModulesStop(ModuleList: TStringList); … … 56 57 property Enabled: Boolean read FEnabled write SetEnabled; 57 58 published 59 property Manager: TModuleManager read FManager; 58 60 property Version: string read FVersion write FVersion; 59 61 property Identification: string read FIdentification write FIdentification; … … 260 262 begin 261 263 Modules.Add(Module); 262 Module. Manager := Self;264 Module.FManager := Self; 263 265 Module.API := API; 264 266 Module.Enabled := Enabled; … … 310 312 inherited; 311 313 Modules := TObjectList.Create; 314 //Modules.OwnsObjects := False; 312 315 end; 313 316 … … 316 319 StopAll; 317 320 FreeAndNil(Modules); 318 inherited Destroy;321 inherited; 319 322 end; 320 323 … … 344 347 RootKey := Context.RootKey; 345 348 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 347 351 OpenKey(Context.Key + '\' + Identification, True); 348 352 WriteBool('Run', Running); … … 361 365 end; 362 366 363 procedure TModule.BeforeStart; 364 begin 365 if Running then Exit; 367 procedure TModule.DoStart; 368 begin 369 370 end; 371 372 procedure TModule.DoStop; 373 begin 374 375 end; 376 377 procedure TModule.DoInstall; 378 begin 379 380 end; 381 382 procedure TModule.DoUninstall; 383 begin 384 385 end; 386 387 procedure TModule.DoUpgrade; 388 begin 389 390 end; 391 392 procedure TModule.SetInstalled(AValue: Boolean); 393 begin 394 if FInstalled = AValue then Exit; 395 if AValue then Install else Uninstall; 396 end; 397 398 procedure TModule.SetEnabled(AValue: Boolean); 399 begin 400 if FEnabled = AValue then Exit; 401 FEnabled := AValue; 402 if not FEnabled and FInstalled then Uninstall; 403 end; 404 405 procedure TModule.Start; 406 begin 407 if not Enabled or Running then Exit; 366 408 if not Installed then Install; 367 409 Manager.StartDependencies(Identification, Dependencies); 368 end; 369 370 procedure TModule.AfterStart; 371 begin 410 DoStart; 372 411 FRunning := True; 373 412 end; 374 413 375 procedure TModule. BeforeStop;414 procedure TModule.Stop; 376 415 begin 377 416 if not Running then Exit; 378 417 FRunning := False; 379 418 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; 409 420 end; 410 421 411 422 procedure TModule.Install; 412 423 begin 413 if Installed then Exit;424 if not Enabled or Installed then Exit; 414 425 Manager.InstallDependencies(Identification, Dependencies); 415 426 FInstalled := True; 416 427 if Assigned(Manager.FOnModuleChange) then 417 428 Manager.FOnModuleChange(Manager, Self); 429 DoInstall; 418 430 end; 419 431 … … 424 436 Manager.UninstallDependencies(Identification); 425 437 FInstalled := False; 438 DoUninstall; 426 439 if Assigned(Manager.FOnModuleChange) then 427 440 Manager.FOnModuleChange(Manager, Self); … … 430 443 procedure TModule.Upgrade; 431 444 begin 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; 433 452 end; 434 453 … … 474 493 begin 475 494 Running := False; 476 Description.Free;477 Dependencies.Free;478 inherited Destroy;495 FreeAndNil(FDescription); 496 FreeAndNil(FDependencies); 497 inherited; 479 498 end; 480 499
Note:
See TracChangeset
for help on using the changeset viewer.