Ignore:
Timestamp:
Jun 8, 2010, 11:25:50 PM (11 years ago)
Author:
kopal
Message:

some improvements in executionEngine

  • now plugins can be executed more than one time (check routine checks every 10ms if one of the plugins may execute)
  • commented out slowing debug logging of execution engine
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/CrypPlugins/WorkspaceManager/Execution/ExecutionEngine.cs

    r1607 r1608  
    7878                schedulers[0].AddProtocol(updateGuiProtocol);
    7979                updateGuiProtocol.Start();
     80
     81                CheckExecutableProtocol checkExecutableProtocol = new CheckExecutableProtocol(schedulers[0], workspaceModel, this);
     82                schedulers[0].AddProtocol(checkExecutableProtocol);
     83                checkExecutableProtocol.Start();
    8084
    8185                int counter=0;
     
    180184        public override System.Collections.Generic.IEnumerator<ReceiverBase> Execute(AbstractStateMachine stateMachine)
    181185        {
    182             while (true)
     186            while (this.executionEngine.IsRunning)
    183187            {
    184188                yield return Timeout(1000, HandleUpdateGui);
     
    200204                    if (pluginModel.GuiNeedsUpdate)
    201205                    {
    202                         executionEngine.GuiLogMessage("UpdateGui for \"" + pluginModel.Name + "\"", NotificationLevel.Debug);
     206                        //executionEngine.GuiLogMessage("UpdateGui for \"" + pluginModel.Name + "\"", NotificationLevel.Debug);
    203207                        pluginModel.GuiNeedsUpdate = false;
    204208                        pluginModel.paint();
     
    213217        }
    214218    }
    215    
     219
     220    /// <summary>
     221    /// A Protocol for updating the GUI in time intervals
     222    /// </summary>
     223    public class CheckExecutableProtocol : ProtocolBase
     224    {
     225        private WorkspaceModel workspaceModel;
     226        private ExecutionEngine executionEngine;
     227
     228        /// <summary>
     229        /// Create a new protocol. Each protocol requires a scheduler which provides
     230        /// a thread for execution.
     231        /// </summary>
     232        /// <param name="scheduler"></param>
     233        public CheckExecutableProtocol(Scheduler scheduler, WorkspaceModel workspaceModel, ExecutionEngine executionEngine)
     234            : base(scheduler)
     235        {
     236            this.workspaceModel = workspaceModel;
     237            this.executionEngine = executionEngine;
     238        }
     239
     240        /// <summary>
     241        /// The main function of the protocol
     242        /// </summary>
     243        /// <param name="stateMachine"></param>
     244        /// <returns></returns>
     245        public override System.Collections.Generic.IEnumerator<ReceiverBase> Execute(AbstractStateMachine stateMachine)
     246        {
     247            while (this.executionEngine.IsRunning)
     248            {
     249                yield return Timeout(10, HandleCheckExecutable);
     250            }
     251        }
     252
     253        /// <summary>
     254        /// Handler function for a message.
     255        /// This handler must not block, because it executes inside the thread of the scheduler.
     256        /// </summary>
     257        /// <param name="msg"></param>
     258        private void HandleCheckExecutable()
     259        {
     260            foreach (PluginModel pluginModel in workspaceModel.AllPluginModels)
     261            {
     262                pluginModel.checkExecutable(pluginModel.PluginProtocol);
     263            }
     264        }
     265    }
     266
    216267    /// <summary>
    217268    /// A Protocol for a PluginModel
     
    241292        public override System.Collections.Generic.IEnumerator<ReceiverBase> Execute(AbstractStateMachine stateMachine)
    242293        {
    243             while (true)
     294            while (this.executionEngine.IsRunning)
    244295            {
    245296                yield return Receive<MessagePreExecution>(null, this.HandlePreExecute);
     
    262313        private void HandlePreExecute(MessagePreExecution msg)
    263314        {
    264             executionEngine.GuiLogMessage("HandlePreExecute for \"" + msg.PluginModel.Name + "\"", NotificationLevel.Debug);
     315            //executionEngine.GuiLogMessage("HandlePreExecute for \"" + msg.PluginModel.Name + "\"", NotificationLevel.Debug);
    265316            msg.PluginModel.Plugin.PreExecution();
    266317        }
     
    273324        private void HandleExecute(MessageExecution msg)
    274325        {
    275             executionEngine.GuiLogMessage("HandleExecute for \"" + msg.PluginModel.Name + "\"", NotificationLevel.Debug);
     326            //executionEngine.GuiLogMessage("HandleExecute for \"" + msg.PluginModel.Name + "\"", NotificationLevel.Debug);
    276327            //Fill the plugins Inputs with data
    277328            foreach (ConnectorModel connectorModel in pluginModel.InputConnectors)
     
    283334                    connectorModel.Data = null;
    284335                    connectorModel.HasData = false;
    285                     connectorModel.InputConnection.Active = false;
     336                    connectorModel.InputConnection.Active = false;                   
    286337                }
    287338            }
     339           
    288340            msg.PluginModel.Plugin.Execute();
     341                       
    289342        }
    290343
     
    296349        private void HandlePostExecute(MessagePostExecution msg)
    297350        {
    298             executionEngine.GuiLogMessage("HandlePostExecute for \"" + msg.PluginModel.Name + "\"", NotificationLevel.Debug);
     351            //executionEngine.GuiLogMessage("HandlePostExecute for \"" + msg.PluginModel.Name + "\"", NotificationLevel.Debug);
    299352            msg.PluginModel.Plugin.PostExecution();
     353                     
    300354        }
    301355    }
Note: See TracChangeset for help on using the changeset viewer.