extern "C" int
VSCPBlockingReceive(long handle, vscpEvent *pEvent, unsigned long timeout)
{
	int rv = 0;
 
    // Check pointer
    if ( NULL == pEvent) return CANAL_ERROR_PARAMETER;
    
	CRawEthernet *pdrvObj = theApp.getDriverObject(handle);
	if (NULL == pdrvObj) return CANAL_ERROR_MEMORY;
    
    if ( wxSEMA_TIMEOUT == pdrvObj->m_semReceiveQueue.WaitTimeout( timeout ) ) {
        return CANAL_ERROR_TIMEOUT;
    }
    
    //VSCPEVENTLIST_RECEIVE::compatibility_iterator nodeClient;

	pdrvObj->m_mutexReceiveQueue.Lock();
	//nodeClient = pdrvObj->m_receiveQueue.GetFirst();
	//vscpEvent *pLocalEvent = nodeClient->GetData();
    vscpEvent *pLocalEvent = pdrvObj->m_receiveList.front();
    pdrvObj->m_receiveList.pop_front();
	pdrvObj->m_mutexReceiveQueue.Unlock();
    if (NULL == pLocalEvent) return CANAL_ERROR_MEMORY;
    
    copyVSCPEvent( pEvent, pLocalEvent );
    //pdrvObj->m_receiveQueue.DeleteNode(nodeClient);
    deleteVSCPevent( pLocalEvent );
	
	return CANAL_ERROR_SUCCESS;
}
Example #2
0
void *RXWorkerThread::Entry()
{
  int rv;
  VscpTcpIf tcpifReceive;
  wxCommandEvent eventReceive( wxVSCP_IN_EVENT, m_pCtrlObject->m_windowID );
    wxCommandEvent eventConnectionLost( wxVSCP_RCV_LOST_EVENT, m_pCtrlObject->m_windowID );
  
  // Must be a valid control object pointer
    if ( NULL == m_pCtrlObject ) return NULL;
  
  // Connect to the server with the control interface
  if ( !tcpifReceive.doCmdOpen( m_pCtrlObject->m_ifVSCP.m_strHost,
                            m_pCtrlObject->m_ifVSCP.m_port,
                            m_pCtrlObject->m_ifVSCP.m_strUser,
                            m_pCtrlObject->m_ifVSCP.m_strPassword ) ) {
    //::wxGetApp().logMsg ( _("VSCP Receive thread - Unable to connect to server."), DAEMON_LOGMSG_CRITICAL );
    m_pCtrlObject->m_errorReceive = VSCP_SESSION_ERROR_UNABLE_TO_CONNECT;
        wxPostEvent( m_pCtrlObject->m_pWnd, eventConnectionLost );
    return NULL;
  }
  
  // Find the channel id
  tcpifReceive.doCmdGetChannelID( &m_pCtrlObject->m_rxChannelID );

  // Start Receive Loop
    tcpifReceive.doCmdEnterReceiveLoop();

  vscpEvent event;
    while ( !TestDestroy() && !m_pCtrlObject->m_bQuit )
    {

    if ( CANAL_ERROR_SUCCESS == 
            ( rv = tcpifReceive.doCmdBlockReceive( &event, 1000 ) ) ) {

      if ( NULL != m_pCtrlObject->m_pWnd ) {

        vscpEvent *pEvent = new vscpEvent;
        if ( NULL != pEvent ) {

          copyVSCPEvent( pEvent, &event );

          eventReceive.SetClientData( pEvent );
          wxPostEvent( m_pCtrlObject->m_pWnd, eventReceive );
        
        }

      } // Session window exist

    }
    else {
      if ( CANAL_ERROR_COMMUNICATION == rv ) m_pCtrlObject->m_bQuit = true;
    }

    } // while

  // Close the interface
  tcpifReceive.doCmdClose();

    wxPostEvent( m_pCtrlObject->m_pWnd, eventConnectionLost );

    return NULL;

}
extern "C" bool WINAPI EXPORT vscp_copyVSCPEvent( vscpEvent *pEventTo, 
                                                    const vscpEvent *pEventFrom )
{
    return copyVSCPEvent( pEventTo, pEventFrom );
}