Пример #1
0
        private IEnumerator <ITask> RefreshCameraList(WebCamState state, Port <EmptyValue> completionPort)
        {
            var devicePort = EnumDevices();

            yield return(Arbiter.Receive(false, devicePort, list => state.Cameras = list));

            completionPort.Post(EmptyValue.SharedInstance);
        }
Пример #2
0
        public void ReplaceHandler(mdwebcam.Replace replace)
        {
            _state = replace.Body;
            if (_streamPort != null)
            {
                _streamPort.Post(new Shutdown());
            }
            try
            {
                _streamPort = mdwebcam.ReadStream.Create(_state.CaptureFile, Environment.TaskQueue);
            }
            catch (Exception e)
            {
                LogError("Unable to open stream file: " + e.Message);
            }

            replace.ResponsePort.Post(DefaultReplaceResponseType.Instance);

            SendNotification(_subMgrPort, replace);
        }
Пример #3
0
        /// <summary>
        /// Complete second phase startup for this service
        /// </summary>
        protected override void Start()
        {
            _fwdPort    = ServiceForwarder <WebCamServiceOperations>(ServiceInfo.Service);
            _altFwdPort = ServiceForwarder <webcam.WebCamOperations>(AlternateContractServiceInfo[0].Service);

            _utilitiesPort = DsspHttpUtilitiesService.Create(Environment);

            _prefix          = new Uri(ServiceInfo.Service).AbsolutePath;
            _alternatePrefix = new Uri(AlternateContractServiceInfo[0].Service).AbsolutePath;

            if (_state == null)
            {
                _state = new WebCamState();
            }

            base.ActivateDsspOperationHandlers();

            if (_state.FramesOnDemand)
            {
                _framesOnDemand = true;
                Activate(Arbiter.ReceiveWithIterator(true, _framePort, OnDemandFrameHandler));
            }
            else
            {
                base.MainPortInterleave.CombineWith(
                    Arbiter.Interleave(
                        new TeardownReceiverGroup(),
                        new ExclusiveReceiverGroup
                        (
                            Arbiter.Receive(true, _framePort, FrameHandler)
                        ),
                        new ConcurrentReceiverGroup()
                        )
                    );
            }

            StartPipeServer();

            SpawnIterator(_state, GetInitialState);
        }
Пример #4
0
        public void ReplaceHandler(Replace replace)
        {
            _state = replace.Body;

            replace.ResponsePort.Post(DefaultReplaceResponseType.Instance);

#if !URT_MINCLR
            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);
            }
#else
            SendNotification(replace);
#endif
        }
Пример #5
0
        IEnumerator <ITask> GetInitialState(WebCamState initialState)
        {
            bool deviceSelected = false;

            try
            {
                WebCamState state = new WebCamState();
                state.CaptureFile    = initialState.CaptureFile;
                state.Quality        = initialState.Quality;
                state.FramesOnDemand = initialState.FramesOnDemand;

#if !URT_MINCLR
                yield return(InitializeInternalService());
#endif


                Port <EmptyValue> completion = new Port <EmptyValue>();

                SpawnIterator(state, completion, RefreshCameraList);

                yield return(Arbiter.Receive(false, completion, EmptyHandler));

                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);
                }
                                 ));

                int deviceIndex;

                if (initialState.Selected != null &&
                    (!string.IsNullOrEmpty(initialState.Selected.DevicePath) ||
                     !string.IsNullOrEmpty(initialState.Selected.FriendlyName)))
                {
                    deviceIndex = -1;
                }
                else
                {
                    deviceIndex = 0;
                }

                bool gotDevice = false;
                while (deviceIndex < state.Cameras.Count && !gotDevice)
                {
                    UpdateDeviceRequest request = new UpdateDeviceRequest();

                    if (deviceIndex < 0)
                    {
                        request.Selected       = initialState.Selected;
                        request.Selected.InUse = false;
                    }
                    else if (deviceIndex < state.Cameras.Count)
                    {
                        request.Selected = state.Cameras[deviceIndex];
                    }

                    if (!request.Selected.InUse)
                    {
                        UpdateDevice update = new UpdateDevice();
                        update.Body = request;
                        _fwdPort.Post(update);

                        yield return(Arbiter.Choice(
                                         update.ResponsePort,
                                         success => gotDevice = true,
                                         fault => LogInfo("Unable to select camera: " + deviceIndex + ": " + fault)
                                         ));
                    }
                    else
                    {
                        LogInfo("Not trying camera (InUse = true): " + deviceIndex);
                    }

                    deviceIndex++;
                }

                if (!gotDevice)
                {
                    LogError("Unable to select device");
                    yield break;
                }

                deviceSelected = true;

                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);
                }
                                 ));
            }
            finally
            {
                if (deviceSelected)
                {
                    DirectoryInsert();
                }
                else
                {
                    LogWarning(LogGroups.Console, "Dropping webcam service, no cameras found");
                    _fwdPort.Post(new DsspDefaultDrop());
                }
            }
        }