Ignore:
Timestamp:
Oct 31, 2013, 10:13:01 PM (11 years ago)
Author:
chronos
Message:
  • Přidáno: Kaskádové řešení závislostí modulů při spouštění a zastavení.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/Common/AppModule.php

    r586 r587  
    66        const Normal = 1;
    77        const Application = 2;
     8}
     9
     10class ModuleAction
     11{
     12  const Start = 0;
     13  const Stop = 1;
     14  const Install = 2;
     15  const Uninstall = 3;
     16  const Upgrade = 4;
     17  const Enable = 5;
     18  const Disable = 6;
     19}
     20
     21class ModuleCondition
     22{
     23  const All = 0;
     24  const Enabled = 1;
     25  const NotEnabled = 2;
     26  const Installed = 3;
     27  const NotInstalled = 4;
     28  const Running = 5;
     29  const NotRunning = 6;
    830}
    931
     
    5375  {
    5476    if($this->Running) return;
     77    $List = array();
     78    $this->Manager->EnumDependenciesCascade($this, $List, array(ModuleCondition::NotRunning));
     79    $this->Manager->Perform($List, array(ModuleAction::Start), array(ModuleCondition::NotRunning));
    5580    $this->DoStart();
    5681        $this->Running = true;
     
    6085  {
    6186        if(!$this->Running) return;
    62         $this->Running = false;
     87    $this->Running = false;
     88        $List = array();
     89        $this->Manager->EnumSuperiorDependenciesCascade($this, $List, array(ModuleCondition::Running));
     90    $this->Manager->Perform($List, array(ModuleAction::Stop), array(ModuleCondition::Running));
    6391        $this->DoStop(); 
    6492  }
     
    100128  }
    101129 
     130  function Perform($List, $Actions, $Conditions = array(ModuleCondition::All))
     131  {
     132    foreach($List as $Index => $Module)
     133    {
     134      if(in_array(ModuleCondition::All, $Conditions) or
     135        ($Module->Running and in_array(ModuleCondition::Running, $Conditions)) or
     136        (!$Module->Running and in_array(ModuleCondition::NotRunning, $Conditions)) or
     137        ($Module->Installed and in_array(ModuleCondition::Installed, $Conditions)) or
     138        (!$Module->Installed and in_array(ModuleCondition::NotInstalled, $Conditions)))
     139      {
     140        foreach($Actions as $Action)
     141        {
     142          if($Action == ModuleAction::Start) $Module->Start();
     143          if($Action == ModuleAction::Stop) $Module->Stop();
     144          if($Action == ModuleAction::Install) $Module->Install();
     145          if($Action == ModuleAction::Uninstall) $Module->Uninstall();
     146        }
     147      }
     148    }
     149  }
     150 
     151  function EnumDependenciesCascade($Module, &$List, $Conditions = array(ModuleCondition::All))
     152  {
     153    foreach($Module->Dependencies as $Dependency)
     154    {
     155      $DepModule = $this->Modules[$Dependency];
     156       if(in_array(ModuleCondition::All, $Conditions) or
     157        ($Module->Running and in_array(ModuleCondition::Running, $Conditions)) or
     158        (!$Module->Running and in_array(ModuleCondition::NotRunning, $Conditions)) or
     159        ($Module->Installed and in_array(ModuleCondition::Installed, $Conditions)) or
     160        (!$Module->Installed and in_array(ModuleCondition::NotInstalled, $Conditions)))
     161      {
     162        array_push($List, $DepModule);
     163        $this->EnumDependenciesCascade($DepModule, $List, $Conditions);
     164      }
     165    }
     166  }
     167 
     168  function EnumSuperiorDependenciesCascade($Module, &$List, $Conditions = array(ModuleCondition::All))
     169  {
     170    foreach($this->Modules as $RefModule)
     171    {
     172      $DepModule = $this->Modules[$Dependency];
     173      if(in_array($Module->Name, $RefModule->Dependencies) and
     174          (in_array(ModuleCondition::All, $Conditions) or
     175          ($Module->Running and in_array(ModuleCondition::Running, $Conditions)) or
     176          (!$Module->Running and in_array(ModuleCondition::NotRunning, $Conditions)) or
     177          ($Module->Installed and in_array(ModuleCondition::Installed, $Conditions)) or
     178          (!$Module->Installed and in_array(ModuleCondition::NotInstalled, $Conditions))))
     179      {
     180        array_push($List, $DepModule);
     181        $this->EnumSuperiorDependenciesCascade($DepModule, $List, $Conditions);
     182      }
     183    }
     184  }
     185 
    102186  function StartAll()
    103187  {
    104188    foreach($this->Modules as $Index => $Module)
    105189    {
    106       //DebugLog('Init module '.$Module->Name);
    107       if($this->Modules[$Index]->Running == false)
    108         $this->Modules[$Index]->Start();
     190      $this->Modules[$Index]->Start();
    109191    }
    110192  }
     
    114196    foreach($this->Modules as $Index => $Module)
    115197    {
    116       //DebugLog('Init module '.$Module->Name);
    117       if($this->Modules[$Index]->Running == true)
    118         $this->Modules[$Index]->Stop();
     198      $this->Modules[$Index]->Stop();
    119199    }
    120200  }
Note: See TracChangeset for help on using the changeset viewer.