コード例 #1
0
ファイル: RfxComService.cs プロジェクト: radtek/Automation
        private void ProcessActions(out bool waiting)
        {
            waiting = false;

            // Wait until there's actions to be processed.
            if (mActionQueue.Count == 0)
            {
                return;
            }

            // Acquire radio lock
            if (!mRadioLock.TryEnter(2000, "rfxcom"))
            {
                //// Wait a while for the radio lock to be freed up.
                //EventWaitHandle.WaitAny(mEvents, 100);
                waiting = true;
                return;
            }

            lock (mRadioLock)
            {
                mLockOwned = true;
            }

            DeviceAction action;

            lock (mActionQueue)
            {
                action = mActionQueue.Dequeue();
            }

            bool       result = false;
            DeviceBase device = action.Device;

            if (device is NexaLampDevice)
            {
                var package = Lighting2Protocol.BuildPackage((NexaLampDevice)device, action.Level);
                result = SendPackage(package);
            }
            else if (device is EverflourishDevice)
            {
                var package = Lighting5Protocol.BuildPackage((EverflourishDevice)device, action.Value);
                result = SendPackage(package);
            }

            if (!result)
            {
                Log.Warning("Failed processing action, releasing lock directly");
                mRadioLock.Release();
            }
        }