コード例 #1
0
ファイル: evmngr.cs プロジェクト: wangyakai01/APSIMClassic
        //============================================================================
        /// <summary>
        /// Adds a new event to the this event manager's list.
        /// </summary>
        /// <param name="sName">Name of the event.</param>
        /// <param name="iRegID">Event ID.</param>
        //============================================================================
        public void addEventType(string sName, int iRegID)
        {
            TMEvent anEvent;

            anEvent = new TMEvent(parentComp, this, sName, iRegID);
            eventList.Add(anEvent);
        }
コード例 #2
0
ファイル: mevent.cs プロジェクト: wangyakai01/APSIMClassic
 //=======================================================================
 /// <summary>
 /// A copy constructor for the TMEvent.
 /// </summary>
 /// <param name="anEvent">Event to copy</param>
 //=======================================================================
 public TMEvent(TMEvent anEvent)
     : base(anEvent)
 {
     requestList = new List <uint>();
     //copy all the attributes of 'event'
     eventName      = anEvent.eventName;
     parentComp     = anEvent.parentComp;
     parentMgr      = anEvent.parentMgr;
     eventID        = anEvent.eventID;
     FParams        = anEvent.FParams; //should I be making a copy? (probably not. It is owned by the comp)
     waiting        = false;           //not waiting for msg returns
     nextEventState = anEvent.nextEventState;
 }
コード例 #3
0
ファイル: evmngr.cs プロジェクト: wangyakai01/APSIMClassic
        //============================================================================
        /// <summary>
        /// Tracks the requests made to the rest of the system.
        /// </summary>
        /// <param name="eventID">Event ID.</param>
        /// <param name="msgID">Message ID.</param>
        //============================================================================
        public void addRequest(int eventID, uint msgID)
        {
            RequestRecord request;
            int           eventIndex;

            request         = new RequestRecord();
            request.eventID = eventID;
            request.msgID   = msgID;
            requestList.Add(request);

            //add the msgID to the request list of the event
            eventIndex = eventIdx(eventID);
            if (eventIndex >= 0)
            {
                TMEvent anEvent = (TMEvent)eventList[eventIndex];
                anEvent.addRequest(msgID);
                eventList[eventIndex] = anEvent;
            }
        }
コード例 #4
0
ファイル: evmngr.cs プロジェクト: wangyakai01/APSIMClassic
        //============================================================================
        /// <summary>
        /// Starts an execution of an event. If an event object exists and is idle, it
        /// is started. To allow for threaded processing, a new event object will be
        /// created if none are found to be idle.
        /// </summary>
        /// <param name="iRegID">ID of the event.</param>
        /// <param name="iSender">Component ID requesting the event.</param>
        /// <param name="iPublisher">Component that published this event.</param>
        /// <param name="iMsgID">Message ID of this event msg.</param>
        /// <param name="dataParams">Param data.</param>
        /// <param name="bNotify"> </param>
        //============================================================================
        public void beginEvent(int iRegID, uint iSender, uint iPublisher, uint iMsgID, TDDMLValue dataParams, bool bNotify)
        {
            bool    found       = false;
            TMEvent anEvent     = null;
            TMEvent eventToCopy = null;

            string errorMsg;

            int i = 0;

            //look through the list of defined events to see if one is available to run
            while ((!found) && (i < eventList.Count))
            {
                anEvent = (TMEvent)eventList[i];
                if ((uint)(anEvent.getEventID()) == iRegID)                    //if the event is the correct type
                {
                    found = (anEvent.getCurrentState() == TStateMachine.IDLE); //if it is idle, use this event
                    if (!found)
                    {
                        eventToCopy = anEvent;
                    }
                }
                i++;
            }

            //create a copy of a non idle event if necessary
            if (!found)
            {
                if (eventToCopy == null)
                {
                    errorMsg = String.Format("No event registered for {0}", iRegID);
                    throw (new ApplicationException(errorMsg));
                }
                anEvent = new TMEvent(eventToCopy);
            }

            anEvent.iPublisher = iPublisher;
            anEvent.bNotify    = bNotify;    // set up info for later acknowledgement
            anEvent.iNotifyTo  = iSender;
            anEvent.iNotifyMsg = iMsgID;
            anEvent.beginEvent(dataParams);  //now activate the event
        }
コード例 #5
0
ファイル: evmngr.cs プロジェクト: wangyakai01/APSIMClassic
        //============================================================================
        /// <summary>
        /// Informs the event that sent the msgID, that a return has occured. The
        /// number of remaining requests required by the event is checked. If no returns
        /// are still pending then the event is resumed.
        /// </summary>
        /// <param name="msgID">Message ID.</param>
        //============================================================================
        public void completeRequest(uint msgID)
        {
            int  anEventIdx;
            bool found;
            int  remainingRequests;

            //scan through the request list and find the event that triggered it
            int i = 0;

            found = false;
            while ((!found) && (i < requestList.Count))
            {
                RequestRecord request = (RequestRecord)requestList[i];
                if (request.msgID == msgID)
                {                                           //if the msg request if found
                    found      = true;
                    anEventIdx = eventIdx(request.eventID); //get the TMEvent belonging to the request
                    if (anEventIdx >= 0)
                    {
                        TMEvent anEvent = (TMEvent)eventList[anEventIdx];

                        //now delete the request from the the Event Manager's requestList
                        requestList.RemoveAt(i);
                        remainingRequests = anEvent.completeRequest(msgID); //tell the event that the request is complete
                        if (remainingRequests < 1)                          //if there are no pending requests then
                        {
                            //event.resumeEvent;                                    //resume the event
                            anEvent.setWaiting(false);
                        }
                        eventList[anEventIdx] = anEvent;
                    }
                }
                else
                {
                    i++;   //next event
                }
            }
        }