コード例 #1
0
bool cXBMCChannelScan::OnResponsePacket(cXVDRResponsePacket* resp)
{
  uint32_t requestID = resp->getRequestID();

  if (requestID == XVDR_SCANNER_PERCENTAGE)
  {
    uint32_t percent = resp->extract_U32();
    if (percent >= 0 && percent <= 100)
      SetProgress(percent);
  }
  else if (requestID == XVDR_SCANNER_SIGNAL)
  {
    uint32_t strength = resp->extract_U32();
    uint32_t locked   = resp->extract_U32();
    SetSignal(strength, locked);
  }
  else if (requestID == XVDR_SCANNER_DEVICE)
  {
    const char* str = resp->extract_String();
    m_window->SetControlLabel(LABEL_DEVICE, str);
  }
  else if (requestID == XVDR_SCANNER_TRANSPONDER)
  {
    const char* str = resp->extract_String();
    m_window->SetControlLabel(LABEL_TRANSPONDER, str);
  }
  else if (requestID == XVDR_SCANNER_NEWCHANNEL)
  {
    uint32_t isRadio      = resp->extract_U32();
    uint32_t isEncrypted  = resp->extract_U32();
    uint32_t isHD         = resp->extract_U32();
    const char* str       = resp->extract_String();

    CAddonListItem* item = GUI->ListItem_create(str, NULL, NULL, NULL, NULL);
    if (isEncrypted)
      item->SetProperty("IsEncrypted", "yes");
    if (isRadio)
      item->SetProperty("IsRadio", "yes");
    if (isHD)
      item->SetProperty("IsHD", "yes");

    m_window->AddItem(item, 0);
    GUI->ListItem_destroy(item);
  }
  else if (requestID == XVDR_SCANNER_FINISHED)
  {
    if (!m_Canceled)
    {
      m_window->SetControlLabel(HEADER_LABEL, XBMC->GetLocalizedString(30036));
      m_window->SetControlLabel(BUTTON_START, XBMC->GetLocalizedString(30024));
      m_window->SetControlLabel(LABEL_STATUS, XBMC->GetLocalizedString(30041));
    }
    else
    {
      m_window->SetControlLabel(HEADER_LABEL, XBMC->GetLocalizedString(30042));
    }
  }
  else if (requestID == XVDR_SCANNER_STATUS)
  {
    uint32_t status = resp->extract_U32();
    if (status == 0)
    {
      if (m_Canceled)
        m_window->SetControlLabel(LABEL_STATUS, XBMC->GetLocalizedString(16200));
      else
        m_window->SetControlLabel(LABEL_STATUS, XBMC->GetLocalizedString(30040));

      m_window->SetControlLabel(BUTTON_START, XBMC->GetLocalizedString(30024));
      m_stopped = true;
    }
    else if (status == 1)
    {
      m_window->SetControlLabel(LABEL_STATUS, XBMC->GetLocalizedString(30039));
    }
    else if (status == 2)
    {
      m_window->SetControlLabel(LABEL_STATUS, XBMC->GetLocalizedString(30037));
      m_window->SetControlLabel(BUTTON_START, XBMC->GetLocalizedString(30024));
      m_window->SetControlLabel(HEADER_LABEL, XBMC->GetLocalizedString(30043));
      m_stopped = true;
    }
    else if (status == 3)
    {
      m_window->SetControlLabel(LABEL_STATUS, XBMC->GetLocalizedString(30038));
    }
  }
  else {
    return false;
  }

  return true;
}
コード例 #2
0
void cVNSIChannelScan::Action()
{
  uint32_t channelID;
  uint32_t requestID;
  uint32_t userDataLength;
  uint8_t* userData;

  bool readSuccess;

  cResponsePacket* vresp;

  while (Running())
  {
    readSuccess = readData((uint8_t*)&channelID, sizeof(uint32_t));
    if (!readSuccess && !IsClientConnected())
      return; // return to stop this thread

    if (!readSuccess) continue; // no data was read but the connection is ok.

    // Data was read
    channelID = ntohl(channelID);
    if (channelID == CHANNEL_REQUEST_RESPONSE)
    {
      if (!readData((uint8_t*)&requestID, sizeof(uint32_t))) break;
      requestID = ntohl(requestID);
      if (!readData((uint8_t*)&userDataLength, sizeof(uint32_t))) break;
      userDataLength = ntohl(userDataLength);
      if (userDataLength > 5000000) break; // how big can these packets get?
      userData = NULL;
      if (userDataLength > 0)
      {
        userData = (uint8_t*)malloc(userDataLength);
        if (!userData) break;
        if (!readData(userData, userDataLength)) break;
      }

      vresp = new cResponsePacket();
      vresp->setResponse(requestID, userData, userDataLength);

      CMD_LOCK;
      SMessages::iterator it = m_queue.find(requestID);
      if (it != m_queue.end())
      {
        it->second.pkt = vresp;
        it->second.event->Signal();
      }
      else
      {
        delete vresp;
      }
    }
    else if (channelID == CHANNEL_SCAN)
    {
      if (!readData((uint8_t*)&requestID, sizeof(uint32_t))) break;
      requestID = ntohl(requestID);
      if (!readData((uint8_t*)&userDataLength, sizeof(uint32_t))) break;
      userDataLength = ntohl(userDataLength);
      if (userDataLength > 5000000) break; // how big can these packets get?
      userData = NULL;
      if (userDataLength > 0)
      {
        userData = (uint8_t*)malloc(userDataLength);
        if (!userData) break;
        if (!readData(userData, userDataLength)) break;
      }

      if (requestID == VDR_SCANNER_PERCENTAGE)
      {
        uint32_t percent = ntohl(*(uint32_t*)&userData[0]);
        if (percent >= 0 && percent <= 100)
          SetProgress(percent);
      }
      else if (requestID == VDR_SCANNER_SIGNAL)
      {
        uint32_t strength = ntohl(*(uint32_t*)&userData[0]);
        uint32_t locked   = ntohl(*(uint32_t*)&userData[4]);
        SetSignal(strength, locked);
      }
      else if (requestID == VDR_SCANNER_DEVICE)
      {
        int length = strlen((char*)&userData[0]);
        char* str = new char[length + 1];
        strcpy(str, (char*)&userData[0]);
        m_window->SetControlLabel(LABEL_DEVICE, str);
        delete[] str;
      }
      else if (requestID == VDR_SCANNER_TRANSPONDER)
      {
        int length = strlen((char*)&userData[0]);
        char* str = new char[length + 1];
        strcpy(str, (char*)&userData[0]);
        m_window->SetControlLabel(LABEL_TRANSPONDER, str);
        delete[] str;
      }
      else if (requestID == VDR_SCANNER_NEWCHANNEL)
      {
        uint32_t isRadio      = ntohl(*(uint32_t*)&userData[0]);
        uint32_t isEncrypted  = ntohl(*(uint32_t*)&userData[4]);
        uint32_t isHD         = ntohl(*(uint32_t*)&userData[8]);
        int length = strlen((char*)&userData[12]);
        char* str = new char[length + 1];
        strcpy(str, (char*)&userData[12]);

        CAddonListItem* item = GUI->ListItem_create(str, NULL, NULL, NULL, NULL);
        if (isEncrypted)
          item->SetProperty("IsEncrypted", "yes");
        if (isRadio)
          item->SetProperty("IsRadio", "yes");
        if (isHD)
          item->SetProperty("IsHD", "yes");
        m_window->AddItem(item, 0);
        GUI->ListItem_destroy(item);

        delete[] str;
      }
      else if (requestID == VDR_SCANNER_FINISHED)
      {
        if (!m_Canceled)
        {
          m_window->SetControlLabel(HEADER_LABEL, XBMC->GetLocalizedString(30036));
          m_window->SetControlLabel(BUTTON_START, XBMC->GetLocalizedString(30024));
          m_window->SetControlLabel(LABEL_STATUS, XBMC->GetLocalizedString(30041));
        }
        else
        {
          m_window->SetControlLabel(HEADER_LABEL, XBMC->GetLocalizedString(30042));
        }
      }
      else if (requestID == VDR_SCANNER_STATUS)
      {
        uint32_t status = ntohl(*(uint32_t*)&userData[0]);
        if (status == 0)
        {
          if (m_Canceled)
            m_window->SetControlLabel(LABEL_STATUS, XBMC->GetLocalizedString(16200));
          else
            m_window->SetControlLabel(LABEL_STATUS, XBMC->GetLocalizedString(30040));
          m_window->SetControlLabel(BUTTON_START, XBMC->GetLocalizedString(30024));
          m_stopped = true;
        }
        else if (status == 1)
        {
          m_window->SetControlLabel(LABEL_STATUS, XBMC->GetLocalizedString(30039));
        }
        else if (status == 2)
        {
          m_window->SetControlLabel(LABEL_STATUS, XBMC->GetLocalizedString(30037));
          m_window->SetControlLabel(BUTTON_START, XBMC->GetLocalizedString(30024));
          m_window->SetControlLabel(HEADER_LABEL, XBMC->GetLocalizedString(30043));
          m_stopped = true;
        }
        else if (status == 3)
        {
          m_window->SetControlLabel(LABEL_STATUS, XBMC->GetLocalizedString(30038));
        }
      }

      if (userData)
        free(userData);
    }
    else
    {
      XBMC->Log(LOG_ERROR, "cVNSIChannelScan::Action() - Rxd a wrong response packet on channel %lu !!", channelID);
      break;
    }
  }
}