// from MSocketObserver
void CBTHidConnection::HandleSocketError(TUint /*aSocketID*/,
        TBool aConnectionLost, TInt aErrorCode)
    {
        TRACE_INFO( (_L("[BTHID]\tCBTHidConnection::HandleSocketError: connlost %d, error code %d"), aConnectionLost, aErrorCode) );
    if (aConnectionLost)
        {
        ConnectionLost();
        }
    else
        {
        // If we failed to write to the device then inform Generic HID
        // of the failure
        if (iCommandIssued)
            {
            iCommandIssued = EFalse;

            // Reset this, so we don't leave it in a bad state.
            if (iCommandSegmenter)
                {
                iCommandSegmenter->Reset();
                }

            iObserver.HandleCommandAck(iConnID, aErrorCode);
            }
        }
    }
int cXVDRData::GetTimersCount()
{
  // return caches values on connection loss
  if(ConnectionLost())
    return m_timercount;

  cRequestPacket vrp;
  if (!vrp.init(XVDR_TIMER_GETCOUNT))
  {
    XBMC->Log(LOG_ERROR, "%s - Can't init cRequestPacket", __FUNCTION__);
    return -1;
  }

  cResponsePacket* vresp = ReadResult(&vrp);
  if (!vresp)
  {
    XBMC->Log(LOG_ERROR, "%s - Can't get response packet", __FUNCTION__);
    return m_timercount;
  }

  m_timercount = vresp->extract_U32();

  delete vresp;
  return m_timercount;
}
void NodeJSDebugger::OnStopDebugger(clDebugEvent& event)
{
    event.Skip();
    CHECK_RUNNING();

    event.Skip(false);
    m_node.Terminate();
#if defined(__WXGTK__)||defined(__WXOSX__)
    ConnectionLost("Debug session stopped");
#endif
}
Exemple #4
0
bool NHandsFree::
Write(void *buf, size_t len)
{
	ssize_t res;

	if (m_hfpd_state != NHS_HFPD_CONNECTED)
		return false;

	res = write(m_sock, buf, len);
	if ((res >= 0) && (res == (ssize_t) len))
		return true;

	ConnectionLost();
	return false;
}
BrowserClient::BrowserClient(RocketWebBrowser *listener, QTcpSocket *socket_) :
    socket(socket_)
{
    connect(socket, SIGNAL(readyRead()), SLOT(OnData()), Qt::UniqueConnection);
    connect(socket, SIGNAL(disconnected()), listener, SLOT(ConnectionLost()), Qt::QueuedConnection);

    connect(this, SIGNAL(UrlRequest(const BrowserProtocol::UrlMessage&)), 
        listener, SLOT(OnUrlRequest(const BrowserProtocol::UrlMessage&)));
    connect(this, SIGNAL(ResizeRequest(const BrowserProtocol::ResizeMessage&)), 
        listener, SLOT(OnResizeRequest(const BrowserProtocol::ResizeMessage&)));
    connect(this, SIGNAL(MouseMoveRequest(const BrowserProtocol::MouseMoveMessage&)), 
        listener, SLOT(OnMouseMoveRequest(const BrowserProtocol::MouseMoveMessage&)));
    connect(this, SIGNAL(MouseButtonRequest(const BrowserProtocol::MouseButtonMessage&)), 
        listener, SLOT(OnMouseButtonRequest(const BrowserProtocol::MouseButtonMessage&)));
    connect(this, SIGNAL(KeyboardRequest(const BrowserProtocol::KeyboardMessage&)), 
        listener, SLOT(OnKeyboardRequest(const BrowserProtocol::KeyboardMessage&)));
    connect(this, SIGNAL(TypedRequest(const BrowserProtocol::TypedMessage&)), 
        listener, SLOT(OnTypedRequest(const BrowserProtocol::TypedMessage&)));
}
Exemple #6
0
bool cXVDRDemux::SwitchChannel(const PVR_CHANNEL &channelinfo)
{
  XBMC->Log(LOG_DEBUG, "changing to channel %d", channelinfo.iChannelNumber);

  cRequestPacket vrp;
  uint32_t rc = 0;
  if (vrp.init(XVDR_CHANNELSTREAM_OPEN) && vrp.add_U32(channelinfo.iUniqueId) && ReadSuccess(&vrp, rc))
  {
    m_channelinfo = channelinfo;
    m_Streams.iStreamCount  = 0;

    return !ConnectionLost();
  }

  switch (rc)
  {
    // active recording
    case XVDR_RET_RECRUNNING:
     XBMC->QueueNotification(QUEUE_INFO, XBMC->GetLocalizedString(30062));
      break;
    // all receivers busy
    case XVDR_RET_DATALOCKED:
      XBMC->QueueNotification(QUEUE_INFO, XBMC->GetLocalizedString(30063));
      break;
    // encrypted channel
    case XVDR_RET_ENCRYPTED:
      XBMC->QueueNotification(QUEUE_INFO, XBMC->GetLocalizedString(30066));
      break;
    // error on switching channel
    default:
    case XVDR_RET_ERROR:
      XBMC->QueueNotification(QUEUE_INFO, XBMC->GetLocalizedString(30064));
      break;
    // invalid channel
    case XVDR_RET_DATAINVALID:
      XBMC->QueueNotification(QUEUE_ERROR, XBMC->GetLocalizedString(30065), channelinfo.strChannelName);
      break;
  }

  XBMC->Log(LOG_ERROR, "%s - failed to set channel", __FUNCTION__);
  return true;
}
bool cXVDRDemux::GetSignalStatus(PVR_SIGNAL_STATUS &qualityinfo)
{
    if (ConnectionLost())
        return false;

    if (m_Quality.fe_name.empty())
    {
        memset(&qualityinfo, 0, sizeof(PVR_SIGNAL_STATUS));
        return true;
    }

    strncpy(qualityinfo.strAdapterName, m_Quality.fe_name.c_str(), sizeof(qualityinfo.strAdapterName));
    strncpy(qualityinfo.strAdapterStatus, m_Quality.fe_status.c_str(), sizeof(qualityinfo.strAdapterStatus));
    qualityinfo.iSignal = (uint16_t)m_Quality.fe_signal;
    qualityinfo.iSNR = (uint16_t)m_Quality.fe_snr;
    qualityinfo.iBER = (uint32_t)m_Quality.fe_ber;
    qualityinfo.iUNC = (uint32_t)m_Quality.fe_unc;
    qualityinfo.dVideoBitrate = 0;
    qualityinfo.dAudioBitrate = 0;
    qualityinfo.dDolbyBitrate = 0;

    return true;
}
Exemple #8
0
void CReader::process()
{
    fd_set readfds;
    fd_set writefds;

    int maxfd;
    int status;

    while(true){
        FD_ZERO (&readfds);
        FD_ZERO (&writefds);
        FD_SET (*m_pSocket, &readfds);

        maxfd = (*m_pSocket) + 1;

        status = select(maxfd, &readfds, &writefds, NULL, NULL);

        if( status > 0 && FD_ISSET( *m_pSocket, &readfds ) ) {
            // incoming data
            memset(&buff, 0, 32);

            status = recv(*m_pSocket, buff, 31, 0);
            if(status < 0){
                // conection lost
                emit ConnectionLost();
                break;
            }
            printf("%s", buff);
        }
        else if(status < 0){
            // error on socket
            emit SocketError();
            break;
        }
    }
}
Exemple #9
0
void cXVDRData::Action()
{
  uint32_t lastPing = 0;
  cResponsePacket* vresp;

  SetPriority(19);

  while (Running())
  {
    // try to reconnect
    if(ConnectionLost() && !TryReconnect())
    {
      SleepMs(1000);
      continue;
   }

    // read message
    vresp = cXVDRSession::ReadMessage();

    // check if the connection is still up
    if (vresp == NULL)
    {
      if(time(NULL) - lastPing > 5)
      {
        lastPing = time(NULL);

        if(!SendPing())
          SignalConnectionLost();
      }
      continue;
    }

    // CHANNEL_REQUEST_RESPONSE

    if (vresp->getChannelID() == XVDR_CHANNEL_REQUEST_RESPONSE)
    {

      CMD_LOCK;
      SMessages::iterator it = m_queue.find(vresp->getRequestID());
      if (it != m_queue.end())
      {
        it->second.pkt = vresp;
        it->second.event->Signal();
      }
      else
      {
        delete vresp;
      }
    }

    // CHANNEL_STATUS

    else if (vresp->getChannelID() == XVDR_CHANNEL_STATUS)
    {
      if (vresp->getRequestID() == XVDR_STATUS_MESSAGE)
      {
        uint32_t type = vresp->extract_U32();
        char* msgstr  = vresp->extract_String();
        std::string text = msgstr;

        if (g_bCharsetConv)
          XBMC->UnknownToUTF8(text);

        if (type == 2)
          XBMC->QueueNotification(QUEUE_ERROR, text.c_str());
        if (type == 1)
          XBMC->QueueNotification(QUEUE_WARNING, text.c_str());
        else
          XBMC->QueueNotification(QUEUE_INFO, text.c_str());

        delete[] msgstr;
      }
      else if (vresp->getRequestID() == XVDR_STATUS_RECORDING)
      {
                          vresp->extract_U32(); // device currently unused
        uint32_t on     = vresp->extract_U32();
        char* str1      = vresp->extract_String();
        char* str2      = vresp->extract_String();

        PVR->Recording(str1, str2, on);
        PVR->TriggerTimerUpdate();

        delete[] str1;
        delete[] str2;
      }
      else if (vresp->getRequestID() == XVDR_STATUS_TIMERCHANGE)
      {
        XBMC->Log(LOG_DEBUG, "Server requested timer update");
        PVR->TriggerTimerUpdate();
      }
      else if (vresp->getRequestID() == XVDR_STATUS_CHANNELCHANGE)
      {
        XBMC->Log(LOG_DEBUG, "Server requested channel update");
        PVR->TriggerChannelUpdate();
      }
      else if (vresp->getRequestID() == XVDR_STATUS_RECORDINGSCHANGE)
      {
        XBMC->Log(LOG_DEBUG, "Server requested recordings update");
        PVR->TriggerRecordingUpdate();
      }

      delete vresp;
    }

    // UNKOWN CHANNELID

    else if (!OnResponsePacket(vresp))
    {
      XBMC->Log(LOG_ERROR, "%s - Rxd a response packet on channel %lu !!", __FUNCTION__, vresp->getChannelID());
      delete vresp;
    }
  }
}
Exemple #10
0
DemuxPacket* cXVDRDemux::Read()
{
    if(ConnectionLost())
    {
        SleepMs(100);
        return PVR->AllocateDemuxPacket(0);
    }

    cResponsePacket *resp = ReadMessage();

    if(resp == NULL)
        return PVR->AllocateDemuxPacket(0);

    if (resp->getChannelID() != XVDR_CHANNEL_STREAM)
    {
        delete resp;
        return PVR->AllocateDemuxPacket(0);
    }

    DemuxPacket* pkt = NULL;
    int iStreamId = -1;

    switch (resp->getOpCodeID())
    {
    case XVDR_STREAM_CHANGE:
        StreamChange(resp);
        pkt = PVR->AllocateDemuxPacket(0);
        pkt->iStreamId  = DMX_SPECIALID_STREAMCHANGE;
        delete resp;
        return pkt;

    case XVDR_STREAM_STATUS:
        StreamStatus(resp);
        break;

    case XVDR_STREAM_SIGNALINFO:
        StreamSignalInfo(resp);
        break;

    case XVDR_STREAM_CONTENTINFO:
        // send stream updates only if there are changes
        if(!StreamContentInfo(resp))
            break;

        pkt = PVR->AllocateDemuxPacket(sizeof(PVR_STREAM_PROPERTIES));
        memcpy(pkt->pData, &m_Streams, sizeof(PVR_STREAM_PROPERTIES));
        pkt->iStreamId  = DMX_SPECIALID_STREAMINFO;
        pkt->iSize      = sizeof(PVR_STREAM_PROPERTIES);
        delete resp;
        return pkt;

    case XVDR_STREAM_MUXPKT:
        // figure out the stream id for this packet
        for(unsigned int i = 0; i < m_Streams.iStreamCount; i++)
        {
            if(m_Streams.stream[i].iPhysicalId == (unsigned int)resp->getStreamID())
            {
                iStreamId = i;
                break;
            }
        }

        // stream found ?
        if(iStreamId != -1)
        {
            pkt = (DemuxPacket*)resp->getUserData();

            pkt->iSize     = resp->getUserDataLength();
            pkt->duration  = (double)resp->getDuration() * DVD_TIME_BASE / 1000000;
            pkt->dts       = (double)resp->getDTS() * DVD_TIME_BASE / 1000000;
            pkt->pts       = (double)resp->getPTS() * DVD_TIME_BASE / 1000000;
            pkt->iStreamId = iStreamId;

            delete resp;
            return pkt;
        }
        else
        {
            XBMC->Log(LOG_DEBUG, "stream id %i not found", resp->getStreamID());
        }
        break;
    }

    delete resp;
    return PVR->AllocateDemuxPacket(0);
}
Exemple #11
0
void NHandsFree::
AbortConnection(void)
{
	ConnectionLost();
}
Exemple #12
0
NHandsFree::
~NHandsFree()
{
	if (m_sock >= 0)
		ConnectionLost();
}
Exemple #13
0
bool NHandsFree::
ParseResponse(const char *buf)
{
	NHandsFreeCmd *cmd;

	assert(m_hfpd_state == NHS_HFPD_CONNECTED);

	cmd = m_cmd_head;
	if (cmd && cmd->Response(this, buf)) {
		if (m_hfpd_state != NHS_HFPD_CONNECTED)
			return false;
		m_cmd_head = cmd->next;
		if (!m_cmd_head) {
			assert(m_cmd_tail == cmd);
			m_cmd_tail = 0;
		} else {
			(void) SendCommand(m_cmd_head);
		}
		delete cmd;
		return true;
	}

	if (!strcmp(buf, "OK") ||!strncmp(buf, "ERROR", 5)) {
		/* We didn't ask for this */
		ConnectionLost();
		return false;
	}


	if ((buf[0] != '+') || (buf[2] && (buf[2] != ' '))) {
		/* What the hell is this? */
		return true;
	}

	switch (buf[1]) {
	case 'A':
		/* Bluetooth address of the associated device */
		break;

	case 'B':
		/* Battery charge level */
		break;

	case 'C':
		/* Call state */
		if (!strncmp(&buf[3], "IDLE", 4)) {
			m_call_state = NHS_CALL_NONE;
		}
		else if (!strncmp(&buf[3], "CONNECTING", 10)) {
			m_call_state = NHS_CALL_CONN;
		}
		else if (!strncmp(&buf[3], "ESTAB", 5)) {
			m_call_state = NHS_CALL_ESTAB;
		}
		else {
			return true;
		}

		m_call_waiting = !strcmp(&buf[7], ":WAITING");

		if (!m_call_waiting) {
			if (m_did_incoming_call_popup)
				m_did_incoming_call_popup = false;
			IncomingCallPopUp(false);
			m_callerid = "";
		}
		break;

	case 'D':
		/* Device connection state */
		if (!strcmp(&buf[3], "STOP")) {
			m_ag_state = NHS_AG_NOBT;
		}
		else if (!strcmp(&buf[3], "NODEV")) {
			m_ag_state = NHS_AG_NODEV;
		}
		else if (!strcmp(&buf[3], "DISCON")) {
			m_ag_state = NHS_AG_DISCON;
		}
		else if (!strcmp(&buf[3], "CONNECTING")) {
			m_ag_state = NHS_AG_CONNECTING;
		}
		else if (!strcmp(&buf[3], "CONN")) {
			m_ag_state = NHS_AG_CONN;
		}
		break;

	case 'I':
		/* Caller ID */
		m_callerid = &buf[3];
		return true;

	case 'R':
		/* Ringing! */
		if (!m_did_incoming_call_popup) {
			m_did_incoming_call_popup = true;
			IncomingCallPopUp(true);
		}
		break;

	case 'S':
		if (!strcmp(&buf[3], "NOSERVICE")) {
			m_service = false;
		}
		else if (!strncmp(&buf[3], "SERVICE", 7)) {
			m_service = true;
			if ((buf[10] == ':') && !strcmp(&buf[12], "BARS")) {
				m_signal_bars = buf[11] - '0';
			}
		}
		else if (!strncmp(&buf[3], "ROAM", 4)) {
			m_service = true;
			if ((buf[7] == ':') && !strcmp(&buf[9], "BARS")) {
				m_signal_bars = buf[8] - '0';
			}
		}
		break;

	case 'V':
		if (!strncmp(&buf[3], "DISCON", 5)) {
			m_voice_state = NHS_VOICE_DISCON;
		}
		else if (!strcmp(&buf[3], "CONN")) {
			m_voice_state = NHS_VOICE_CONN;
		}
		else if (!strcmp(&buf[3], "CONN:MUTE")) {
			m_voice_state = NHS_VOICE_MUTE;
		}
		break;

	default:
		return true;
	}

	UpdateStateIcons();
	return true;
}
Exemple #14
0
void NHandsFree::
DataReady(void)
{
	ssize_t ret, cons;

	assert(m_hfpd_state == NHS_HFPD_CONNECTED);
	assert(m_rsp_start + m_rsp_len < sizeof(m_rsp_buf));

	/* Fill m_rsp_buf, try to parse things */
	ret = read(m_sock, &m_rsp_buf[m_rsp_start],
		   sizeof(m_rsp_buf) - (m_rsp_start + m_rsp_len));

	if (ret < 0) {
		if ((errno == EAGAIN) || (errno == EINTR))
			return;

		ndebug::out(ndebug::LOG_ERR, "NHandsFree: %s:%s(%d) - "
			    "Read from socket (%d) - %s",
			    __FILE__, __FUNCTION__, __LINE__,
			    errno, strerror(errno));
		ConnectionLost();
		return;
	}

	if (ret == 0) {
		ndebug::out(ndebug::LOG_ERR, "NHandsFree: %s:%s(%d) - "
			    "Connection closed remotely",
			    __FILE__, __FUNCTION__, __LINE__);
		ConnectionLost();
		return;
	}

	assert((size_t)ret <= (sizeof(m_rsp_buf) - (m_rsp_start + m_rsp_len)));

	m_rsp_len += ret;

	/* Try to consume the buffer */
	do {
		cons = ParseLine(&m_rsp_buf[m_rsp_start], m_rsp_len);
		if (cons < 0)
			return;

		if (!cons) {
			/* Don't tolerate lines that are too long */
			if ((m_rsp_start + m_rsp_len) == sizeof(m_rsp_buf)) {
				if (m_rsp_start == 0) {
					ndebug::out(ndebug::LOG_ERR,
						    "NHandsFree: %s:%s(%d) - "
						    "line is too long",
						    __FILE__, __FUNCTION__,
						    __LINE__);
					ConnectionLost();
					return;
				}

				/* Compact the buffer */
				memmove(m_rsp_buf, &m_rsp_buf[m_rsp_start],
					m_rsp_len);
				m_rsp_start = 0;
			}

			return;
		}

		assert((size_t)cons <= m_rsp_len);

		if (cons == (ssize_t) m_rsp_len) {
			m_rsp_start = m_rsp_len = 0;
		} else {
			m_rsp_start += cons;
			m_rsp_len -= cons;
		}

	} while (m_rsp_len);
}
Exemple #15
0
//-----------------------------------------------------------------------------
//! 
//-----------------------------------------------------------------------------
tSiriusController::tSiriusController( tFusionClientAgent& rFusionClientAgent, tSiriusConnector& rSiriusConnector, QWidget* pParent  )
    : QObject( pParent )
    , m_rFusionClientAgent( rFusionClientAgent )
    , m_rSiriusConnector( rSiriusConnector )
    , m_VolumeControlType( eVCT_NativelyControlled )
    , m_pNotice( 0 )
    , m_pSelectFromAllAction( 0 )
    , m_pSelectFromFavoritesAction( 0 )
    , m_pAllChannelStatusAction( 0 )
    , m_pCategoryAction( 0 )
    , m_pChannelsSubMenuAction( 0 )
    , m_pOptionsAction( 0 )
    , m_pLockCodeAction( 0 )
    , m_pLockChannelAction( 0 )
    , m_pDetachSirius( 0 )
    , m_pSelectCategoryDialog( 0 )
    , m_pCategoryTable( 0 )
    , m_ChannelId( 0 )
    , m_pFavoriteChannels( 0 )
    , m_pChannelsDialog( 0 )
    , m_pChannelsTable( 0 )
    , m_pAllChannelStatusDialog( 0 )
    , m_pAllChannelStatusTable( 0 )
    , m_LockOpened( false )
    , m_UnlockDialogShowing( false )
{

    setObjectName( "Sirius Controller" );

    m_VolumeControlType = VolumeControlType();

    // If using NAS to control the Sirius volume (as opposed to changing
    // the volume of the weather module's sirius radio directory), then max
    // out the volume of the Sirius radio and ensure that it is unmuted.
    // Because the SDK used to interface with the weather module might not be
    // ready in time, set a timer to keep trying.
    if ( m_VolumeControlType == eVCT_AudioServerControlled )
    {
        m_rSiriusConnector.SetToNonNativeVolumeControlMode();
    }

    // Make the connections
    Connect( &m_rSiriusConnector, SIGNAL( ConnectionLost() ), this, SIGNAL( ConnectionLost() ) );
    Connect( &m_rSiriusConnector, SIGNAL( ConnectionEstablished() ), this, SIGNAL( ConnectionMade() ) );

    Connect( &m_rSiriusConnector, SIGNAL( CurrentChannelChanged( int, int, const QString&, const QString& ) ), 
        this, SLOT( SetChannel( int, int, const QString&, const QString& ) ) );

    Connect( &m_rSiriusConnector, SIGNAL( CurrentSongChanged( const QString&, const QString&, const QString& ) ), 
            this, SLOT( SetArtistSongComposer( const QString&, const QString&, const QString& ) ) );
    
    // SDKThread SIGNAL to SIGNAL pass throughs.
    Connect( &m_rSiriusConnector, SIGNAL( SignalStrengthChanged( int ) ), this, SIGNAL( SignalStrengthChanged( int ) ) );

    
    // All status messages for Sirius are handled by the tNoticeManager.
    // @todo [Glenn 30.09.13] We need a way of being informed by the tNoticeManager
    // that its messages/status has change. It was designed to be tightly coupled to 
    // GUI objects, so we'll have to make it more generic by emitting a MessageChanged signal
    // which this object can listen to.
    m_pNotice = new tNoticeManager( NULL );
    // Wire the notices to the source
    /*
    Connect( &m_rSiriusConnector, SIGNAL( SignalLost() ), m_pNotice, SLOT(NoticeSignalLost()) );
    Connect( &m_rSiriusConnector, SIGNAL( SignalRestored() ), m_pNotice, SLOT(NoticeSignalRestored()) );
    Connect( &m_rSiriusConnector, SIGNAL( AntennaDisconnected() ), m_pNotice, SLOT(NoticeAntennaDisconnected()) );
    Connect( &m_rSiriusConnector, SIGNAL( AntennaRestored() ), m_pNotice, SLOT(NoticeAntennaRestored()) );
    Connect( &m_rSiriusConnector, SIGNAL( GCIInProgress(int) ), m_pNotice, SLOT(NoticeGCIInProgress(int)) );
    Connect( &m_rSiriusConnector, SIGNAL( GCIDone() ), m_pNotice, SLOT(NoticeGCIDone()) );
    Connect( &m_rSiriusConnector, SIGNAL( PSVUpdated() ), m_pNotice, SLOT(NoticePSVUpdated()) );
    */

    CreateSiriusActions();
}