Changeset 1607


Ignore:
Timestamp:
Jun 8, 2010, 8:42:03 PM (11 years ago)
Author:
kopal
Message:
  • added multiple schedulers to have multi core support in executionEngine
  • added gears4net protocol to update gui changes in time intervals
    • added needed interface IUpdateableView for updateable view elements
Location:
trunk/CrypPlugins/WorkspaceManager
Files:
1 added
5 edited

Legend:

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

    r1592 r1607  
    2626using System.Reflection;
    2727using Gears4Net;
     28using System.Windows.Threading;
    2829
    2930namespace WorkspaceManager.Execution
     
    3536    {
    3637        private WorkspaceManager WorkspaceManagerEditor;
    37         private Scheduler scheduler;
     38        private Scheduler[] schedulers;
    3839        private WorkspaceModel workspaceModel;
    3940     
     
    6768            {
    6869                IsRunning = true;
    69                 scheduler = new WinFormsScheduler("Scheduler");
     70
     71                schedulers = new Scheduler[System.Environment.ProcessorCount*2];
     72                for(int i=0;i<System.Environment.ProcessorCount*2;i++){
     73                    schedulers[i] = new WinFormsScheduler("Scheduler" + i);
     74                }
     75
    7076                workspaceModel.resetStates();
    71                
     77                UpdateGuiProtocol updateGuiProtocol = new UpdateGuiProtocol(schedulers[0], workspaceModel, this);
     78                schedulers[0].AddProtocol(updateGuiProtocol);
     79                updateGuiProtocol.Start();
     80
     81                int counter=0;
    7282                foreach (PluginModel pluginModel in workspaceModel.AllPluginModels)
    7383                {
    74                     PluginProtocol pluginProtocol = new PluginProtocol(scheduler, pluginModel,this);
     84                    PluginProtocol pluginProtocol = new PluginProtocol(schedulers[counter], pluginModel,this);
    7585                    pluginModel.PluginProtocol = pluginProtocol;
    76                     scheduler.AddProtocol(pluginProtocol);
     86                    schedulers[counter].AddProtocol(pluginProtocol);
    7787                    pluginModel.checkExecutable(pluginProtocol);
    7888                    pluginProtocol.Start();
     89                    counter = (counter + 1) % (System.Environment.ProcessorCount*2);
    7990                }
    8091            }
     
    8697        public void Stop()
    8798        {
    88             scheduler.Shutdown();           
     99            //First stop all Gears4Net Schedulers
     100            foreach (Scheduler scheduler in schedulers)
     101            {
     102                scheduler.Shutdown();
     103            }
     104            //Secondly stop alle plugins
    89105            foreach(PluginModel pluginModel in workspaceModel.AllPluginModels)
    90106            {
     
    137153    }
    138154
    139      /// <summary>
     155    /// <summary>
     156    /// A Protocol for updating the GUI in time intervals
     157    /// </summary>
     158    public class UpdateGuiProtocol : ProtocolBase
     159    {
     160        private WorkspaceModel workspaceModel;
     161        private ExecutionEngine executionEngine;
     162
     163        /// <summary>
     164        /// Create a new protocol. Each protocol requires a scheduler which provides
     165        /// a thread for execution.
     166        /// </summary>
     167        /// <param name="scheduler"></param>
     168        public UpdateGuiProtocol(Scheduler scheduler, WorkspaceModel workspaceModel, ExecutionEngine executionEngine)
     169            : base(scheduler)
     170        {
     171            this.workspaceModel = workspaceModel;
     172            this.executionEngine = executionEngine;
     173        }
     174
     175        /// <summary>
     176        /// The main function of the protocol
     177        /// </summary>
     178        /// <param name="stateMachine"></param>
     179        /// <returns></returns>
     180        public override System.Collections.Generic.IEnumerator<ReceiverBase> Execute(AbstractStateMachine stateMachine)
     181        {
     182            while (true)
     183            {
     184                yield return Timeout(1000, HandleUpdateGui);
     185            }
     186        }
     187
     188        /// <summary>
     189        /// Handler function for a message.
     190        /// This handler must not block, because it executes inside the thread of the scheduler.
     191        /// </summary>
     192        /// <param name="msg"></param>
     193        private void HandleUpdateGui()
     194        {
     195            //Get the gui Thread
     196            this.workspaceModel.WorkspaceManagerEditor.Presentation.Dispatcher.Invoke(DispatcherPriority.Normal, (SendOrPostCallback)delegate
     197            {
     198                foreach (PluginModel pluginModel in workspaceModel.AllPluginModels)
     199                {
     200                    if (pluginModel.GuiNeedsUpdate)
     201                    {
     202                        executionEngine.GuiLogMessage("UpdateGui for \"" + pluginModel.Name + "\"", NotificationLevel.Debug);
     203                        pluginModel.GuiNeedsUpdate = false;
     204                        pluginModel.paint();
     205                        if (pluginModel.UpdateableView != null)
     206                        {
     207                            pluginModel.UpdateableView.update();
     208                        }
     209                    }
     210                }
     211            }
     212            , null);
     213        }
     214    }
     215   
     216    /// <summary>
    140217    /// A Protocol for a PluginModel
    141218    /// </summary>
     
    164241        public override System.Collections.Generic.IEnumerator<ReceiverBase> Execute(AbstractStateMachine stateMachine)
    165242        {
    166             yield return Receive<MessagePreExecution>(null, this.HandlePreExecute);
    167             MessageExecution msg_exec = new MessageExecution();
    168             msg_exec.PluginModel = this.pluginModel;
    169             this.BroadcastMessageReliably(msg_exec);
    170             yield return Receive<MessageExecution>(null, this.HandleExecute);
    171             MessagePostExecution msg_post = new MessagePostExecution();
    172             msg_post.PluginModel = this.pluginModel;
    173             this.BroadcastMessageReliably(msg_post);
    174             yield return Receive<MessagePostExecution>(null, this.HandlePostExecute);
     243            while (true)
     244            {
     245                yield return Receive<MessagePreExecution>(null, this.HandlePreExecute);
     246                MessageExecution msg_exec = new MessageExecution();
     247                msg_exec.PluginModel = this.pluginModel;
     248                this.BroadcastMessageReliably(msg_exec);
     249                yield return Receive<MessageExecution>(null, this.HandleExecute);
     250                MessagePostExecution msg_post = new MessagePostExecution();
     251                msg_post.PluginModel = this.pluginModel;
     252                this.BroadcastMessageReliably(msg_post);
     253                yield return Receive<MessagePostExecution>(null, this.HandlePostExecute);
     254            }
    175255        }
    176256
  • trunk/CrypPlugins/WorkspaceManager/Model/PluginModel.cs

    r1591 r1607  
    236236            {
    237237                this.imageIndex = args.ImageIndex;
     238                this.GuiNeedsUpdate = true;
    238239            }
    239240        }
  • trunk/CrypPlugins/WorkspaceManager/Model/VisualElementModel.cs

    r1570 r1607  
    2121using System.Text;
    2222using System.Windows;
     23using WorkspaceManager.View.Interface;
    2324
    2425namespace WorkspaceManager.Model
     
    6465        /// </summary>
    6566        public string Name { get; set; }
     67
     68        /// <summary>
     69        /// Indicates that this Model Element needs a GUI Update
     70        /// </summary>
     71        public Boolean GuiNeedsUpdate { get; set; }
     72
     73        /// <summary>
     74        /// View Element of this VisualElement
     75        /// </summary>
     76        public IUpdateableView UpdateableView = null;
    6677    }
    6778
  • trunk/CrypPlugins/WorkspaceManager/View/Container/PluginContainerView.xaml.cs

    r1600 r1607  
    2020    /// Interaction logic for PluginContainerView.xaml
    2121    /// </summary>
    22     public partial class PluginContainerView : UserControl, IDraggable
     22    public partial class PluginContainerView : UserControl, IDraggable, IUpdateableView
    2323    {
    2424        public event EventHandler<ConnectorViewEventArgs> OnConnectorMouseLeftButtonDown;
    2525        public event EventHandler<PluginContainerViewDeleteViewEventArgs> Delete;
    2626        public event EventHandler<PluginContainerViewSettingsViewEventArgs> ShowSettings;
     27
     28        private Image img;
    2729
    2830        private List<ConnectorView> connectorViewList;
     
    5557            this.MouseLeave += new MouseEventHandler(PluginContainerView_MouseLeave);
    5658            this.model = model;
     59            this.model.UpdateableView = this;
    5760            this.RenderTransform = new TranslateTransform();
    5861            InitializeComponent();
     
    7578        {
    7679            //TODO: Better-> Bindings
    77             Image img = model.getImage();
     80            img = model.getImage();
    7881            img.Stretch = Stretch.Uniform;
    7982            PresentationPanel.Children.Add(img);
     
    194197            this.delete();
    195198        }
     199
     200        #region IUpdateableView Members
     201
     202        public void update()
     203        {
     204            PresentationPanel.Children.Remove(img);
     205            img = model.getImage();
     206            img.Stretch = Stretch.Uniform;
     207            PresentationPanel.Children.Add(img);
     208        }
     209
     210        #endregion
    196211    }
    197212
  • trunk/CrypPlugins/WorkspaceManager/WorkspaceManager.csproj

    r1600 r1607  
    109109    <Compile Include="View\Interface\IConnection.cs" />
    110110    <Compile Include="View\Interface\IDraggable.cs" />
     111    <Compile Include="View\Interface\IUpdateableView.cs" />
    111112    <Compile Include="View\VisualComponents\CryptoLineView.cs" />
    112113    <Compile Include="View\VisualComponents\BottomBox.xaml.cs">
Note: See TracChangeset for help on using the changeset viewer.