public IEnumerator <ITask> WaitHandler(Wait wait)
        {
            // Create a variable to hold the completion status
            drive.DriveStage result = drive.DriveStage.InitialRequest;

            // Wait until the next Canceled or Completed notification
            // NOTE: There is no guarantee that the notification is the result
            // of a particular drive motion request, but it drive requests are
            // always paired with Waits then this should be the case.
            yield return((Receiver <drive.DriveStage>) Arbiter.Receive(false, completionPort,
                                                                       delegate(drive.DriveStage status) { result = status; }));

            // Make a new state and send it to ourselves as a Replace message
            // This will force a notification out to subscribers
            WaitForDriveCompletionState body = new WaitForDriveCompletionState();

            body.LastStatus = result;
            _mainPort.Post(new Replace(body));

            // Finally, send back the response message so that the caller
            // can now continue
            wait.ResponsePort.Post(new WaitResponseType(result));

            yield break;
        }
        /// <summary>
        /// Service start
        /// </summary>
        protected override void Start()
        {
            // Initialize the state
            if (_state == null)
            {
                _state = new WaitForDriveCompletionState();
            }
            _state.LastStatus = drive.DriveStage.InitialRequest;

            // Subscribe to the drive for notification messages
            _drivePort.Subscribe(_driveNotify);

            // Add the necessary receivers
            // NOTE: These are INDEPENDENT receivers.
            // This is OK because they do not affect the state of the service.
            Activate(Arbiter.ReceiveWithIterator <drive.DriveDistance>(true, _driveNotify, DriveDistanceUpdateHandler));
            Activate(Arbiter.ReceiveWithIterator <drive.RotateDegrees>(true, _driveNotify, RotateDegreesUpdateHandler));

            base.Start();
        }
 /// <summary>
 /// Creates a new instance of Replace
 /// </summary>
 /// <param name="body">the request message body</param>
 /// <param name="responsePort">the response port for the request</param>
 public Replace(WaitForDriveCompletionState body, PortSet <DefaultReplaceResponseType, Fault> responsePort)
     : base(body, responsePort)
 {
 }
 public void ReplaceHandler(Replace replace)
 {
     _state = replace.Body;
     SendNotification <Replace>(_submgrPort, replace.Body);
     replace.ResponsePort.Post(DefaultReplaceResponseType.Instance);
 }
 /// <summary>
 /// Creates a new instance of Replace
 /// </summary>
 /// <param name="body">the request message body</param>
 public Replace(WaitForDriveCompletionState body)
     : base(body)
 {
 }