Exemple #1
0
 private HttpChannel()
 {
     this.availableMessages = new LinkedList <HttpMessage>();
     this.messageBits       = new List <byte[]>();
     this.State             = WebChannelState.Initializing;
     //this.messageBits = new StringBuilder();
 }
        public static WebChannelState ToWebChannelState(this TvControl.ChannelState state, int channelId)
        {
            WebChannelState newState = new WebChannelState();

            newState.ChannelId = channelId;
            switch (state)
            {
            case TvControl.ChannelState.tunable:
                newState.State = Interfaces.ChannelState.Tunable;
                break;

            case TvControl.ChannelState.timeshifting:
                newState.State = Interfaces.ChannelState.Timeshifting;
                break;

            case TvControl.ChannelState.recording:
                newState.State = Interfaces.ChannelState.Recording;
                break;

            case TvControl.ChannelState.nottunable:
                newState.State = Interfaces.ChannelState.NotTunable;
                break;

            default:
                newState.State = Interfaces.ChannelState.Unknown;
                break;
            }

            return(newState);
        }
Exemple #3
0
 public void Close(bool closeElementary = true)
 {
     if (closeElementary)
     {
         source.Close();
     }
     State = WebChannelState.Closed;
 }
Exemple #4
0
 public void Close(bool closeElementary = true)
 {
     if (closeElementary)
     {
         //stream.Flush();
         client.Close();
     }
     State = WebChannelState.Closed;
 }
Exemple #5
0
 private void BecomeOpen()
 {
     if (State != WebChannelState.Initializing)
     {
         throw new InvalidOperationException();
     }
     // claim received messages
     for (int i = 0; i < snoopedBitNo; i++)
     {
         // the source is supposed to drop the bit that we have read earlier
         source.EmitMessage();
     }
     // set state accordingly
     snoopedBitNo = 0;
     State        = WebChannelState.Open;
 }
    public static async Task<WebChannelState> ProcessAsync(IOwinContext context, string channelId, string userName)
    {
      if (!ServiceRegistration.IsRegistered<ITvProvider>())
        throw new BadRequestException("GetChannelState: ITvProvider not found");

      if (channelId == null)
        throw new BadRequestException("GetChannelState: channelId is null");
      if (userName == null)
        throw new BadRequestException("GetChannelState: userName is null");

      IChannelAndGroupInfoAsync channelAndGroupInfo = ServiceRegistration.Get<ITvProvider>() as IChannelAndGroupInfoAsync;
      var channel = await channelAndGroupInfo.GetChannelAsync(int.Parse(channelId));
      if (!channel.Success)
        throw new BadRequestException(string.Format("GetChannelState: Couldn't get channel with id: {0}", channelId));

      WebChannelState webChannelState = new WebChannelState
      {
        ChannelId = channel.Result.ChannelId,
        State = ChannelState.Tunable // TODO: implement in SlimTv
      };

      return webChannelState;
    }
Exemple #7
0
 protected TcpChannel()
 {
     State             = WebChannelState.Open;
     availableMessages = new LinkedList <byte[]>();
     sendBuffer        = new byte[0];
 }
Exemple #8
0
 public void Process()
 {
     // test for invalid state
     if (State == WebChannelState.Closed || State == WebChannelState.InitFailed)
     {
         return;
     }
     source.Process();
     if (source.State == WebChannelState.Closed)
     {
         State = WebChannelState.Closed;
         return;
     }
     if (State == WebChannelState.InitFailed)
     {
         State = WebChannelState.InitFailed;
         return;
     }
     if (State == WebChannelState.Initializing)
     {
         // only snoop new messages if still initializing
         int messageNo = source.AvailableMessageNo;
         while (messageNo > snoopedBitNo)
         {
             byte[] bit = source.SnoopMessage(snoopedBitNo);
             if (bit.Length <= 0)
             {
                 throw new InvalidOperationException();
             }
             messageBits.Add(bit);
             snoopedBitNo += 1;
         }
         // try to extract a header
         if (messageHeader.Length == 0)
         {
             int headerLength = ExtractHeaderLength();
             if (headerLength > 0)
             {
                 messageHeader        = ExtractHeader(headerLength);
                 missingContentLength = ExtractContentLength(messageHeader);
             }
         }
         // try to extract message content
         if (messageHeader.Length > 0 && missingContentLength > 0)
         {
             messageContent = ExtractContent(messageHeader.Length, missingContentLength);
             if (messageContent.Length >= 0)
             {
                 // first message extraction successful
                 PostMessage(messageHeader.Length, missingContentLength);
                 BecomeOpen();
             }
         }
         // or go with no content if this is not required
         if (messageHeader.Length > 0 && missingContentLength == 0)
         {
             PostMessage(messageHeader.Length, 0);
             BecomeOpen();
         }
     }
     else
     {
         // read new messages
         int messageNo = source.AvailableMessageNo;
         if (messageNo > 0)
         {
             byte[] bit = source.EmitMessage();
             if (bit.Length == 0)
             {
                 throw new InvalidOperationException();
             }
             messageBits.Add(bit);
         }
         // try to extract a header
         if (messageHeader.Length == 0)
         {
             int headerLength = ExtractHeaderLength();
             if (headerLength > 0)
             {
                 messageHeader        = ExtractHeader(headerLength);
                 missingContentLength = ExtractContentLength(messageHeader);
             }
         }
         // try to extract message content
         if (messageHeader.Length > 0 && missingContentLength > 0)
         {
             messageContent = ExtractContent(messageHeader.Length, missingContentLength);
             if (messageContent.Length >= 0)
             {
                 PostMessage(messageHeader.Length, missingContentLength);
             }
         }
     }
 }