IEnumerator <ITask> ReplaceHandler(Replace replace) { _state = replace.Body; replace.ResponsePort.Post(DefaultReplaceResponseType.Instance); SendNotification(_submgrPort, replace); if (_streamPort != null) { _streamPort.Post(new Shutdown()); _streamPort = null; } if (!string.IsNullOrEmpty(_state.CaptureFile)) { _streamPort = SaveStream.Create(_state.CaptureFile, _state.Quality, _queue); } yield break; }
private void StartBehavior() { _fwdPort = ServiceForwarder <Srv1CameraServiceOperations>(ServiceInfo.Service); _utilitiesPort = DsspHttpUtilitiesService.Create(Environment); if (_state == null) { _state = new Srv1CameraState(); } // Listen on the main port for requests and call the appropriate handler. Activate( Arbiter.Interleave( new TeardownReceiverGroup( Arbiter.Receive <DsspDefaultDrop>(false, _mainPort, DropHandler) ), new ExclusiveReceiverGroup ( Arbiter.ReceiveWithIterator <Replace>(true, _mainPort, ReplaceHandler), Arbiter.ReceiveWithIterator <UpdateDevice>(true, _mainPort, UpdateDeviceHandler), Arbiter.ReceiveWithIterator <UpdateFormat>(true, _mainPort, UpdateFormatHandler), Arbiter.Receive(true, _framePort, FrameHandler), Arbiter.ReceiveWithIterator <HttpPost>(true, _mainPort, HttpPostHandler) ), new ConcurrentReceiverGroup ( Arbiter.ReceiveWithIterator <Get>(true, _mainPort, GetHandler), Arbiter.ReceiveWithIterator <QueryFrame>(true, _mainPort, QueryFrameHandler), Arbiter.ReceiveWithIterator <UpdateFrame>(true, _mainPort, UpdateFrameHandler), Arbiter.ReceiveWithIterator <HttpGet>(true, _mainPort, HttpGetHandler), Arbiter.ReceiveWithIterator <Subscribe>(true, _mainPort, SubscribeHandler), Arbiter.Receive <DsspDefaultLookup>(true, _mainPort, DefaultLookupHandler) )) ); SpawnIterator(_state, GetInitialState); }
IEnumerator <ITask> GetInitialState(Srv1CameraState initialState) { Srv1CameraState state = new Srv1CameraState(); state.CaptureFile = initialState.CaptureFile; state.Quality = initialState.Quality; yield return(InitializeInternalService()); foreach (object obj in new vision.CameraCollection()) { using (vision.Camera camera = obj as vision.Camera) { CameraInstance instance = new CameraInstance(); instance.FriendlyName = camera.Name; instance.DevicePath = camera.Path; instance.SupportedFormats = ConvertFormats(camera.Formats); state.Cameras.Add(instance); } } state.Image = null; Replace replace = new Replace(); replace.Body = state; _fwdPort.Post(replace); yield return(Arbiter.Choice( replace.ResponsePort, delegate(DefaultReplaceResponseType success) { }, delegate(Fault fault) { LogError(null, "Unable to set camera list", fault); } )); UpdateDeviceRequest request = new UpdateDeviceRequest(); if (initialState.Selected != null) { request.Selected = initialState.Selected; } else if (state.Cameras.Count > 0) { request.Selected = state.Cameras[0]; } else { yield break; } UpdateDevice update = new UpdateDevice(); update.Body = request; _fwdPort.Post(update); yield return(Arbiter.Choice( update.ResponsePort, delegate(DefaultUpdateResponseType success) { }, delegate(Fault fault) { LogError(null, "Unable to select camera", fault); } )); if (initialState.Selected == null || initialState.Selected.Format == null) { yield break; } UpdateFormat updateFormat = new UpdateFormat(); updateFormat.Body = initialState.Selected.Format; _fwdPort.Post(updateFormat); yield return(Arbiter.Choice( updateFormat.ResponsePort, delegate(DefaultUpdateResponseType success) { }, delegate(Fault fault) { LogError(null, "Unable to select format", fault); } )); }