extern "C" int CanalClose( long handle )
{
	int rv = 0;

	VscpTcpIf *pvscpif =  theApp.getDriverObject( handle );
	if ( NULL == pvscpif ) return CANAL_ERROR_MEMORY;
	pvscpif->doCmdClose();
	theApp.removeDriverObject( handle );
	rv = CANAL_ERROR_SUCCESS;
	return rv;
}
Exemple #2
0
void *TXWorkerThread::Entry()
{
  eventOutQueue::compatibility_iterator node;
  vscpEvent *pEvent;

  // Must be a valid control object pointer
    if ( NULL == m_pCtrlObject ) return NULL;

    wxCommandEvent eventConnectionLost( wxVSCP_CTRL_LOST_EVENT, m_pCtrlObject->m_windowID );
  
  /// TCP/IP Control
  VscpTcpIf tcpifControl;
  


  
  // Connect to the server with the control interface
  if ( !tcpifControl.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 TX thread - Unable to connect to server."), DAEMON_LOGMSG_CRITICAL );
    m_pCtrlObject->m_errorControl = VSCP_SESSION_ERROR_UNABLE_TO_CONNECT;
        wxPostEvent( m_pCtrlObject->m_pWnd, eventConnectionLost );
    return NULL;
  }
  
  // Get channel ID
  tcpifControl.doCmdGetChannelID( &m_pCtrlObject->m_txChannelID );
  
    while ( !TestDestroy() && !m_pCtrlObject->m_bQuit )
    {
    if ( wxSEMA_TIMEOUT == m_pCtrlObject->m_semOutQue.WaitTimeout( 500 ) ) continue;
    m_pCtrlObject->m_mutexOutQueue.Lock();
    node = m_pCtrlObject->m_outQueue.GetFirst();
    pEvent = node->GetData();
    tcpifControl.doCmdSend( pEvent );
    m_pCtrlObject->m_outQueue.DeleteNode( node );
    deleteVSCPevent( pEvent );
    m_pCtrlObject->m_mutexOutQueue.Unlock();
    } // while
  
  // Close the interface
  tcpifControl.doCmdClose();

    wxPostEvent( m_pCtrlObject->m_pWnd, eventConnectionLost );

    return NULL;

}
CVSCPL1App::~CVSCPL1App()
{
	LOCK_MUTEX( m_objMutex );
	
	for ( int i = 0; i<VSCP_LEVEL1_INTERFACE_MAX_OPEN; i++ ) {
		
		if ( NULL == m_pvscpifArray[ i ] ) {
			
			VscpTcpIf *pvscpif =  getDriverObject( i );
			if ( NULL != pvscpif ) { 
				pvscpif->doCmdClose();	
				delete m_pvscpifArray[ i ];
				m_pvscpifArray[ i ] = NULL; 
			}
		}
	}

	UNLOCK_MUTEX( m_objMutex );	
	pthread_mutex_destroy( &m_objMutex );
}
Exemple #4
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;

}