Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Migration of unmigrated content due to installation of a new plugin

Simplification of the event handling

Current implementation:

Code Block
	public enum EventType 
	{
		Warning,
		Informative,
		ValueOutOfRange,
		GlobalProgress,
		TimeStepProgres,
		DataChanged,
		TargetBeforeGetValuesCall,
		SourceAfterGetValuesCall,
		SourceBeforeGetValuesReturn,
		TargetAfterGetValuesReturn,
		Other
	}

	public interface IEvent
	{
		EventType Type {get;}
		string Description {get;}
		IPublisher Sender {get;}
		DateTime SimulationTime {get;}
		object GetAttribute(string key);
	}

	public interface IListener
	{
		void OnEvent(IEvent anEvent);
		int GetAcceptedEventTypeCount();
		EventType GetAcceptedEventType(int acceptedEventTypeIndex);
	}

	public interface IPublisher 
	{
		void Subscribe(IListener listener, EventType eventType);
		void UnSubscribe(IListener listener, EventType eventType);
		void SendEvent(IEvent Event);
		int GetPublishedEventTypeCount();
		EventType GetPublishedEventType(int providedEventTypeIndex);
	}

        public interface ILinkableComponent : IPublisher
        {
                ...
        }

This is quite a log long way as for an ordinary user who implements simple linkable component (or even complex one).

...

Then event-related code will look like:

Code Block

        // event args which will be used only when we need to pass additional data there, otherwise null
        public interface ILinkableComponentILinkableComponentEventArgs
        {
                EventType Type  ...
{ get; }
		string Description { get; }
		DateTime Time { get; }
                publicIExchangeItem eventChangedItem LinkableComponentEventHandler{ DataChangedget; }
                bool publicStop event{ LinkableComponentEventHandlerget; Progressed;set; } // used if simulation should be stopped!
        }


        public enum EventType 
	{
		Warning,
		Informative,
		ValueOutOfRange,
		GlobalProgress,
		TimeStepProgres,
		DataChanged,
		TargetBeforeGetValuesCall,
		SourceAfterGetValuesCall,
		SourceBeforeGetValuesReturn,
		TargetAfterGetValuesReturn,
		Other
	}

    // C# way
    
    public delegate void LinkableComponentEventHandler(object source, ILinkableComponentEventArgs args);

    public interface ILinkableComponent
  //  {
        event args which will be used only when we need to pass additional data there, otherwise null LinkableComponentEventHandler Progressed;
    }



    // Java way (Observable is a class, Observer is an interface!)

    public class LinkableComponentObservable extends Observable
 public  interface ILinkableComponentEventArgs{
        {
		string Description { get; }
		DateTime Time { get; }
public void notifyObservers(ILinkableComponentEventArgs args);
    }


    public interface ILinkableComponent
    {
       IExchangeItem ChangedItempublic {LinkableComponentObservable getgetObservable(); }
        }

Here we are (only) replacing the OpenMI definition of the IListener and IPublisher interfaces in the Standard with the language specific classes that implement the notification/event mechanism in C# and Java. Development becomes a little bit easier (which in my opinion can also (and better) be done in the SDK), but the Standard no longer contains only interfaces and becomes more implementation language specific.

Logging in the OpenMI SDK

And for logging, somewhere in SDK it will be:

...