Changeset 421 for ModularSystem/UModularSystem.pas
- Timestamp:
- Sep 17, 2012, 8:06:51 AM (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
ModularSystem/UModularSystem.pas
r404 r421 19 19 TModule = class(TComponent) 20 20 private 21 FRunning: Boolean; 21 22 FInstalled: Boolean; 22 23 Manager: TModuleManager; … … 29 30 FDescription: TStringList; 30 31 procedure SetInstalled(AValue: Boolean); 32 procedure SetRunning(AValue: Boolean); 31 33 public 32 34 API: TAPI; 33 35 MarkForInstall: Boolean; 36 procedure Start; virtual; 37 procedure Stop; virtual; 34 38 procedure Install; virtual; 35 39 procedure Uninstall; virtual; 36 procedure Update; virtual; 40 procedure Upgrade; virtual; 41 procedure EnumModulesStart(ModuleList: TStringList); 42 procedure EnumModulesStop(ModuleList: TStringList); 37 43 procedure EnumModulesInstall(ModuleList: TStringList); 38 44 procedure EnumModulesUninstall(ModuleList: TStringList); 39 constructor Create(Owner: TComponent); virtual; 45 procedure SetInstalledState(Value: Boolean); 46 constructor Create(Owner: TComponent); override; 40 47 destructor Destroy; override; 48 property Running: Boolean read FRunning write SetRunning; 41 49 property Installed: Boolean read FInstalled write SetInstalled; 42 50 published … … 50 58 end; 51 59 60 TModuleEvent = procedure (Sender: TObject; Module: TModule) of object; 61 52 62 { TModuleManager } 53 63 … … 55 65 private 56 66 FAPI: TAPI; 67 FOnModuleChange: TModuleEvent; 57 68 procedure SetAPI(AValue: TAPI); 58 69 public 59 70 Modules: TObjectList; // TObjectList<TModule> 60 71 function FindModuleByName(Name: string): TModule; 72 function ModuleRunning(Name: string): Boolean; 73 procedure StartDependencies(ModuleName: string; Dependencies: TStringList); 74 procedure StopDependencies(ModuleName: string); 75 procedure EnumModulesStart(Dependencies, ModuleList: TStringList); 76 procedure EnumModulesStop(ModuleName: string; ModuleList: TStringList); 61 77 procedure InstallDependencies(ModuleName: string; Dependencies: TStringList); 62 78 procedure UninstallDependencies(ModuleName: string); … … 65 81 procedure RegisterModule(Module: TModule; MarkForInstall: Boolean = False); 66 82 procedure UnregisterModule(Module: TModule); 83 procedure StartInstalled; 67 84 procedure InstallMarked; 85 procedure StopAll; 68 86 procedure UninstallAll; 69 87 constructor Create(AOwner: TComponent); override; 70 88 destructor Destroy; override; 71 89 property API: TAPI read FAPI write SetAPI; 90 property OnModuleChange: TModuleEvent read FOnModuleChange write FOnModuleChange; 72 91 end; 73 92 … … 107 126 end; 108 127 109 procedure TModuleManager.InstallDependencies(ModuleName: string; Dependencies: TStringList); 128 function TModuleManager.ModuleRunning(Name: string): Boolean; 129 var 130 Module: TModule; 131 begin 132 Module := FindModuleByName(Name); 133 if Assigned(Module) then begin 134 Result := Module.Running; 135 end else Result := False; 136 end; 137 138 procedure TModuleManager.StartDependencies(ModuleName: string; Dependencies: TStringList); 139 var 140 Module: TModule; 141 I: Integer; 142 begin 143 for I := 0 to Dependencies.Count - 1 do begin 144 Module := FindModuleByName(Dependencies[I]); 145 if Assigned(Module) then begin 146 if not Module.Running then Module.Start; 147 end else raise Exception.CreateFmt(SModuleNotFound, [ModuleName, Dependencies[I]]); 148 end; 149 end; 150 151 procedure TModuleManager.StopDependencies(ModuleName: string); 152 var 153 I: Integer; 154 begin 155 for I := 0 to Modules.Count - 1 do 156 with TModule(Modules[I]) do begin 157 if (Dependencies.IndexOf(ModuleName) <> - 1) and Running then Stop; 158 end; 159 end; 160 161 procedure TModuleManager.EnumModulesStart(Dependencies, 162 ModuleList: TStringList); 163 var 164 Module: TModule; 165 I: Integer; 166 begin 167 for I := 0 to Dependencies.Count - 1 do begin 168 Module := FindModuleByName(Dependencies[I]); 169 if Assigned(Module) then begin 170 if not Module.Running and (ModuleList.IndexOf(Module.Identification) = -1) then begin 171 ModuleList.Add(Module.Identification); 172 EnumModulesStart(Module.Dependencies, ModuleList); 173 end; 174 end else raise Exception.CreateFmt(SModuleNotFound, [Module.Identification]); 175 end; 176 end; 177 178 procedure TModuleManager.EnumModulesStop(ModuleName: string; 179 ModuleList: TStringList); 180 var 181 I: Integer; 182 begin 183 for I := 0 to Modules.Count - 1 do 184 with TModule(Modules[I]) do begin 185 if (Dependencies.IndexOf(ModuleName) <> -1) and Running and 186 (ModuleList.IndexOf(Identification) = -1) then begin 187 ModuleList.Add(Identification); 188 Self.EnumModulesStop(Identification, ModuleList); 189 end; 190 end; 191 end; 192 193 procedure TModuleManager.InstallDependencies(ModuleName: string; 194 Dependencies: TStringList); 110 195 var 111 196 Module: TModule; … … 176 261 end; 177 262 263 procedure TModuleManager.StartInstalled; 264 var 265 I: Integer; 266 begin 267 for I := 0 to Modules.Count - 1 do 268 with TModule(Modules[I]) do 269 if not Running and Installed then Start; 270 end; 271 178 272 procedure TModuleManager.InstallMarked; 179 273 var … … 185 279 end; 186 280 281 procedure TModuleManager.StopAll; 282 var 283 I: Integer; 284 begin 285 for I := 0 to Modules.Count - 1 do 286 with TModule(Modules[I]) do 287 if Running then Stop; 288 end; 289 187 290 procedure TModuleManager.UninstallAll; 188 291 var … … 202 305 destructor TModuleManager.Destroy; 203 306 begin 204 UninstallAll;307 StopAll; 205 308 FreeAndNil(Modules); 206 309 inherited Destroy; … … 209 312 { TModule } 210 313 314 procedure TModule.SetRunning(AValue: Boolean); 315 begin 316 if FRunning = AValue then Exit; 317 if AValue then Start else Stop; 318 end; 319 211 320 procedure TModule.SetInstalled(AValue: Boolean); 212 321 begin 213 322 if FInstalled = AValue then Exit; 214 323 if AValue then Install else Uninstall; 324 end; 325 326 procedure TModule.Start; 327 begin 328 if Running then Exit; 329 Manager.StartDependencies(Identification, Dependencies); 330 FRunning := True; 331 end; 332 333 procedure TModule.Stop; 334 begin 335 if not Running then Exit; 336 Manager.StopDependencies(Identification); 337 FRunning := False; 215 338 end; 216 339 … … 220 343 Manager.InstallDependencies(Identification, Dependencies); 221 344 FInstalled := True; 345 if Assigned(Manager.FOnModuleChange) then 346 Manager.FOnModuleChange(Manager, Self); 222 347 end; 223 348 … … 225 350 begin 226 351 if not Installed then Exit; 352 if Running then Stop; 227 353 Manager.UninstallDependencies(Identification); 228 354 FInstalled := False; 229 end; 230 231 procedure TModule.Update; 232 begin 233 if not Installed then Exit; 355 if Assigned(Manager.FOnModuleChange) then 356 Manager.FOnModuleChange(Manager, Self); 357 end; 358 359 procedure TModule.Upgrade; 360 begin 361 if not Running then Exit; 362 end; 363 364 procedure TModule.EnumModulesStart(ModuleList: TStringList); 365 begin 366 ModuleList.Clear; 367 Manager.EnumModulesStart(Dependencies, ModuleList); 368 end; 369 370 procedure TModule.EnumModulesStop(ModuleList: TStringList); 371 begin 372 ModuleList.Clear; 373 Manager.EnumModulesStop(Identification, ModuleList); 234 374 end; 235 375 … … 244 384 ModuleList.Clear; 245 385 Manager.EnumModulesUninstall(Identification, ModuleList); 386 end; 387 388 procedure TModule.SetInstalledState(Value: Boolean); 389 begin 390 FInstalled := Value; 391 if Assigned(Manager.FOnModuleChange) then 392 Manager.FOnModuleChange(Manager, Self); 246 393 end; 247 394 … … 255 402 destructor TModule.Destroy; 256 403 begin 257 Installed:= False;404 Running := False; 258 405 Description.Free; 259 406 Dependencies.Free;
Note:
See TracChangeset
for help on using the changeset viewer.