bool SCI_Transporter::initTransporter() { 
  DBUG_ENTER("SCI_Transporter::initTransporter");
  if(m_BufferSize < (2*MAX_MESSAGE_SIZE + 4096)){ 
    m_BufferSize = 2 * MAX_MESSAGE_SIZE + 4096; 
  } 

  // Allocate buffers for sending, send buffer size plus 2048 bytes for avoiding
  // the need to send twice when a large message comes around. Send buffer size is
  // measured in words. 
  Uint32 sz = 4 * m_PacketSize + MAX_MESSAGE_SIZE;;
  
  m_sendBuffer.m_sendBufferSize = 4 * ((sz + 3) / 4); 
  m_sendBuffer.m_buffer = new Uint32[m_sendBuffer.m_sendBufferSize / 4];
  m_sendBuffer.m_dataSize = 0;
 
  DBUG_PRINT("info",
  ("Created SCI Send Buffer with buffer size %d and packet size %d",
              m_sendBuffer.m_sendBufferSize, m_PacketSize * 4));
  if(!getLinkStatus(m_ActiveAdapterId) ||  
     (m_adapters > 1 &&
     !getLinkStatus(m_StandbyAdapterId))) { 
    DBUG_PRINT("error",
    ("The link is not fully operational. Check the cables and the switches")); 
    //NDB should terminate 
    report_error(TE_SCI_LINK_ERROR); 
    DBUG_RETURN(false); 
  } 
  DBUG_RETURN(true); 
} // initTransporter()  
void  
SCI_Transporter::setDisconnect() { 
  if(getLinkStatus(m_ActiveAdapterId)) 
    *m_remoteStatusFlag = SCIDISCONNECT; 
  if (m_adapters > 1) {
    if(getLinkStatus(m_StandbyAdapterId)) 
      *m_remoteStatusFlag2 = SCIDISCONNECT; 
  }
} 
Esempio n. 3
0
  Program::Program(const std::string& vShaderFile, const std::string& fShaderFile,
                   const std::string& gShaderFile)
  :  _vertexShader   (NULL)
  ,  _fragmentShader (NULL)
  ,  _geometryShader (NULL)
  {
    _handle = glCreateProgram();
    GL_ERR_CHECK();
    
    _vertexShader   = new Shader(vShaderFile, GL_VERTEX_SHADER);
    _fragmentShader = new Shader(fShaderFile, GL_FRAGMENT_SHADER);
    _geometryShader = new Shader(gShaderFile, GL_GEOMETRY_SHADER);
    
    glAttachShader(_handle, _vertexShader->getHandle());
    GL_ERR_CHECK();
    
    glAttachShader(_handle, _fragmentShader->getHandle());
    GL_ERR_CHECK();

    glAttachShader(_handle, _geometryShader->getHandle());
    GL_ERR_CHECK();
    
    // Link the program
    glLinkProgram(_handle);
    GL_ERR_CHECK();
    
    // Check for linker errors
    if(!getLinkStatus())
    {
      std::stringstream err;
      err << "GLSL program failed to link:" << std::endl;
      err << getLog() << std::endl;
      throw GL::Exception(err.str());
    }
  }
Esempio n. 4
0
 Program::Program(const std::string& vShaderFile, const std::string& fShaderFile)
 :  _vertexShader   (NULL)
 ,  _fragmentShader (NULL)
 ,  _geometryShader (NULL)
 {
    _handle = glCreateProgram();
    GL_ERR_CHECK();
    
    _vertexShader   = new Shader(vShaderFile, GL_VERTEX_SHADER);
    _fragmentShader = new Shader(fShaderFile, GL_FRAGMENT_SHADER);
    
    glAttachShader(_handle, _vertexShader->getHandle());
    GL_ERR_CHECK();
    
    glAttachShader(_handle, _fragmentShader->getHandle());
    GL_ERR_CHECK();
    
    // Link the program
    glLinkProgram(_handle);
    GL_ERR_CHECK();
    
    // Check for linker errors
    if(!getLinkStatus())
    {
       std::stringstream err;
       err << "GLSL program failed to link:" << std::endl;
       err << getLog() << std::endl;
       throw std::runtime_error(err.str());
    }
    bind();
    mapUniformNamesToIndices();
    mapAttributeNamesToIndices();
 }
Esempio n. 5
0
bool SCI_Transporter::initTransporter() { 
  DBUG_ENTER("SCI_Transporter::initTransporter");
  if(m_BufferSize < (2*MAX_MESSAGE_SIZE + 4096)){ 
    m_BufferSize = 2 * MAX_MESSAGE_SIZE + 4096; 
  } 

  DBUG_PRINT("info", ("SCI packet size %d", m_PacketSize * 4));
  if(!getLinkStatus(m_ActiveAdapterId) ||  
     (m_adapters > 1 &&
     !getLinkStatus(m_StandbyAdapterId))) { 
    DBUG_PRINT("error",
    ("The link is not fully operational. Check the cables and the switches")); 
    //NDB should terminate 
    report_error(TE_SCI_LINK_ERROR); 
    DBUG_RETURN(false); 
  } 
  DBUG_RETURN(true); 
} // initTransporter()  
//------------------------------------------------------------------------------
tOplkError edrv_sendTxBuffer(tEdrvTxBuffer* pBuffer_p)
{
    int         pcapRet;

    // Check parameter validity
    ASSERT(pBuffer_p != NULL);

    FTRACE_MARKER("%s", __func__);

    if (pBuffer_p->txBufferNumber.pArg != NULL)
        return kErrorInvalidOperation;

    if (getLinkStatus(edrvInstance_l.initParam.pDevName) == FALSE)
    {
        /* there's no link! We pretend that packet is sent and immediately call
         * tx handler! Otherwise the stack would hang! */
        if (pBuffer_p->pfnTxHandler != NULL)
        {
            pBuffer_p->pfnTxHandler(pBuffer_p);
        }
    }
    else
    {
        pthread_mutex_lock(&edrvInstance_l.mutex);
        if (edrvInstance_l.pTransmittedTxBufferLastEntry == NULL)
        {
            edrvInstance_l.pTransmittedTxBufferLastEntry =
                edrvInstance_l.pTransmittedTxBufferFirstEntry = pBuffer_p;
        }
        else
        {
            edrvInstance_l.pTransmittedTxBufferLastEntry->txBufferNumber.pArg = pBuffer_p;
            edrvInstance_l.pTransmittedTxBufferLastEntry = pBuffer_p;
        }
        pthread_mutex_unlock(&edrvInstance_l.mutex);

        pcapRet = pcap_sendpacket(edrvInstance_l.pPcap, pBuffer_p->pBuffer,
                                  (int)pBuffer_p->txFrameSize);
        if (pcapRet != 0)
        {
            DEBUG_LVL_EDRV_TRACE("%s() pcap_sendpacket returned %d (%s)\n",
                                 __func__, pcapRet, pcap_geterr(edrvInstance_l.pPcap));
            return kErrorInvalidOperation;
        }
    }

    return kErrorOk;
}
Esempio n. 7
0
void LocalBitmap::getDebugInfo()
{
	/* debug function: dumps everything human readable into llinfos */
	LL_INFOS() << "===[local bitmap debug]==="               << "\n"
			<< "path: "          << filename        << "\n"
			<< "name: "          << shortname       << "\n"
			<< "extension: "     << extension       << "\n"
			<< "uuid: "          << id              << "\n"
			<< "last modified: " << last_modified   << "\n"
			<< "link status: "   << getLinkStatus() << "\n"
			<< "keep updated: "  << keep_updating   << "\n"
			<< "type: "          << bitmap_type     << "\n"
			<< "is valid: "      << valid           << "\n"
			<< "=========================="               << LL_ENDL;
	
}
bool SCI_Transporter::doSend() { 
#ifdef DEBUG_TRANSPORTER  
  NDB_TICKS startSec=0, stopSec=0; 
  Uint32 startMicro=0, stopMicro=0, totalMicro=0; 
#endif
  sci_error_t             err; 
  Uint32 retry=0; 
 
  const char * const sendPtr = (char*)m_sendBuffer.m_buffer;
  const Uint32 sizeToSend    = 4 * m_sendBuffer.m_dataSize; //Convert to number of bytes
  
  if (sizeToSend > 0){
#ifdef DEBUG_TRANSPORTER 
    if(sizeToSend < 1024 ) 
      i1024++; 
    if(sizeToSend > 1024 && sizeToSend < 2048 ) 
      i10242048++; 
    if(sizeToSend==2048) 
      i2048++; 
    if(sizeToSend>2048 && sizeToSend < 4096) 
      i20484096++; 
    if(sizeToSend==4096) 
      i4096++; 
    if(sizeToSend==4097) 
      i4097++; 
#endif
      
  tryagain:
    retry++;
    if (retry > 3) { 
      DBUG_PRINT("error", ("SCI Transfer failed"));
      report_error(TE_SCI_UNRECOVERABLE_DATA_TFX_ERROR);
      return false; 
    } 
    Uint32 * insertPtr = (Uint32 *) 
      (m_TargetSegm[m_ActiveAdapterId].writer)->getWritePtr(sizeToSend); 
    
    if(insertPtr != 0) {	   
      
      const Uint32 remoteOffset=(Uint32) 
	((char*)insertPtr -  
	 (char*)(m_TargetSegm[m_ActiveAdapterId].mappedMemory)); 
      
      SCIMemCpy(m_TargetSegm[m_ActiveAdapterId].sequence, 
		(void*)sendPtr, 
		m_TargetSegm[m_ActiveAdapterId].rhm[m_ActiveAdapterId].map, 
		remoteOffset, 
		sizeToSend, 
		SCI_FLAG_ERROR_CHECK, 
		&err);   
      
      if (err != SCI_ERR_OK) { 
        if (err == SCI_ERR_OUT_OF_RANGE ||
            err == SCI_ERR_SIZE_ALIGNMENT ||
            err == SCI_ERR_OFFSET_ALIGNMENT) { 
          DBUG_PRINT("error", ("Data transfer error = %d", err));
          report_error(TE_SCI_UNRECOVERABLE_DATA_TFX_ERROR);
	  return false; 
        } 
        if(err == SCI_ERR_TRANSFER_FAILED) { 
	  if(getLinkStatus(m_ActiveAdapterId))
	    goto tryagain; 
          if (m_adapters == 1) {
            DBUG_PRINT("error", ("SCI Transfer failed"));
            report_error(TE_SCI_UNRECOVERABLE_DATA_TFX_ERROR);
	    return false; 
          }
	  m_failCounter++; 
	  Uint32 temp=m_ActiveAdapterId;	    	     
	  if (getLinkStatus(m_StandbyAdapterId)) { 
	    failoverShmWriter();		 
	    SCIStoreBarrier(m_TargetSegm[m_StandbyAdapterId].sequence,0); 
	    m_ActiveAdapterId=m_StandbyAdapterId; 
	    m_StandbyAdapterId=temp; 
            DBUG_PRINT("error", ("Swapping from adapter %u to %u",
                       m_StandbyAdapterId, m_ActiveAdapterId));
	  } else {
	    report_error(TE_SCI_UNRECOVERABLE_DATA_TFX_ERROR);
            DBUG_PRINT("error", ("SCI Transfer failed")); 
	  }
        }
      } else { 
	SHM_Writer * writer = (m_TargetSegm[m_ActiveAdapterId].writer);
	writer->updateWritePtr(sizeToSend); 
	
	Uint32 sendLimit = writer->getBufferSize();
	sendLimit -= writer->getWriteIndex();
	
	m_sendBuffer.m_dataSize = 0;
	m_sendBuffer.m_forceSendLimit = sendLimit;
      } 
    } else { 
      /** 
       * If we end up here, the SCI segment is full.  
       */ 
      DBUG_PRINT("error", ("the segment is full for some reason")); 
      return false; 
    } //if  
  } 
  return true; 
} // doSend() 
 bool link() {
     glLinkProgram(m_GLId);
     return getLinkStatus();
 }
Esempio n. 10
0
bool SCI_Transporter::doSend() { 
#ifdef DEBUG_TRANSPORTER  
  NDB_TICKS startSec=0, stopSec=0; 
  Uint32 startMicro=0, stopMicro=0, totalMicro=0; 
#endif
  sci_error_t             err; 
  Uint32 retry=0; 
 
  if (!fetch_send_iovec_data())
    return false;

  Uint32 used = m_send_iovec_used;
  if (used == 0)
    return true;                                // Nothing to send

#ifdef DEBUG_TRANSPORTER 
  Uint32 sizeToSend = 0;
  for (Uint32 i = 0; i < used; i++)
    sizeToSend += m_send_iovec[i].iov_len;

  if(sizeToSend < 1024 )
    i1024++;
  if(sizeToSend > 1024 && sizeToSend < 2048 )
    i10242048++;
  if(sizeToSend==2048)
    i2048++;
  if(sizeToSend>2048 && sizeToSend < 4096)
    i20484096++;
  if(sizeToSend==4096)
    i4096++;
  if(sizeToSend==4097)
    i4097++;
#endif
      
  bool status = true;
  Uint32 curr = 0;
  Uint32 total = 0;
  while (curr < used)
  {
  tryagain:
    if (retry > 3) { 
      DBUG_PRINT("error", ("SCI Transfer failed"));
      report_error(TE_SCI_UNRECOVERABLE_DATA_TFX_ERROR);
      status = false;
      break;
    } 
    Uint32 segSize = m_send_iovec[curr].iov_len;
    Uint32 * insertPtr = (Uint32 *) 
      (m_TargetSegm[m_ActiveAdapterId].writer)->getWritePtr(segSize);
    
    if(insertPtr != 0) {	   
      
      const Uint32 remoteOffset=(Uint32) 
	((char*)insertPtr -  
	 (char*)(m_TargetSegm[m_ActiveAdapterId].mappedMemory)); 
      
      SCIMemCpy(m_TargetSegm[m_ActiveAdapterId].sequence, 
		(void*)m_send_iovec[curr].iov_base,
		m_TargetSegm[m_ActiveAdapterId].rhm[m_ActiveAdapterId].map, 
		remoteOffset, 
		segSize,
		SCI_FLAG_ERROR_CHECK, 
		&err);   
      
      if (err != SCI_ERR_OK) { 
        if (err == SCI_ERR_OUT_OF_RANGE ||
            err == SCI_ERR_SIZE_ALIGNMENT ||
            err == SCI_ERR_OFFSET_ALIGNMENT) { 
          DBUG_PRINT("error", ("Data transfer error = %d", err));
          report_error(TE_SCI_UNRECOVERABLE_DATA_TFX_ERROR);
          status = false;
          break;
        } 
        if(err == SCI_ERR_TRANSFER_FAILED) { 
	  if(getLinkStatus(m_ActiveAdapterId))
          {
            retry++;
	    goto tryagain; 
          }
          if (m_adapters == 1) {
            DBUG_PRINT("error", ("SCI Transfer failed"));
            report_error(TE_SCI_UNRECOVERABLE_DATA_TFX_ERROR);
            status = false;
            break;
          }
	  m_failCounter++; 
	  Uint32 temp=m_ActiveAdapterId;	    	     
	  if (getLinkStatus(m_StandbyAdapterId)) { 
	    failoverShmWriter();		 
	    SCIStoreBarrier(m_TargetSegm[m_StandbyAdapterId].sequence,0); 
	    m_ActiveAdapterId=m_StandbyAdapterId; 
	    m_StandbyAdapterId=temp; 
            DBUG_PRINT("error", ("Swapping from adapter %u to %u",
                       m_StandbyAdapterId, m_ActiveAdapterId));
	  } else {
	    report_error(TE_SCI_UNRECOVERABLE_DATA_TFX_ERROR);
            DBUG_PRINT("error", ("SCI Transfer failed")); 
	  }
        }
        break;
      } else { 
	SHM_Writer * writer = (m_TargetSegm[m_ActiveAdapterId].writer);
	writer->updateWritePtr(segSize);
	
        curr++;
        total += segSize;
      } 
    } else { 
      /** 
       * If we end up here, the SCI segment is full. As long as we manage to
       * send _something_, that is ok.
       */ 
      if (curr == 0)
      {
        DBUG_PRINT("error", ("the segment is full for some reason"));
        status = false;
      }
      break;
    } //if  
  } 

  if (total > 0)
    iovec_data_sent(total);

  return status;
} // doSend() 
Esempio n. 11
0
void usart_rx_thread_entry(void *p)
{
	unsigned short max_interval,max_datalen;
	unsigned int current_mode;

	getFrameSplit(&max_interval,&max_datalen);
    current_mode = getWorkingMode();

    while( rt_sem_take(&rx_sem,RT_WAITING_FOREVER) == RT_EOK )
    {
        register rt_base_t temp;
        FEED_THE_DOG();

        // if rj45 not connected, we should route data between 232 and 485.
        if( getLinkStatus() == 0 )
        {
            // we split rx_buf to 2 parts in order to save space.
            int len1,len2;
            // Clear the semaphore.
            temp = rt_hw_interrupt_disable();
            rx_sem.value = 0;
            rt_hw_interrupt_enable(temp);
            do
            {
                usart_led_flash();

                // recv usart1
                rt_sem_take(&tx2_sem,RT_WAITING_FOREVER);
                len1 = rt_device_read(dev_uart1,0,rx_buf,RX_BUF_SIZE/2);
                if( len1 )
                    dev_uart2->write(dev_uart2, 0, rx_buf, len1);
                else
                    rt_sem_release(&tx2_sem);

                // recv usart2
                rt_sem_take(&tx1_sem,RT_WAITING_FOREVER);
                len2 = rt_device_read(dev_uart2,0,rx_buf+RX_BUF_SIZE/2,RX_BUF_SIZE/2);
                if( len2 )
                    dev_uart1->write(dev_uart1, 0, rx_buf+RX_BUF_SIZE/2, len2);
                else
                    rt_sem_release(&tx1_sem);
            }while( (len1 != 0) && (len2 != 0) );
            continue;
        }
        else
        {
            // Clear the semaphore.
            temp = rt_hw_interrupt_disable();
            rx_sem.value = 0;
            rt_hw_interrupt_enable(temp);
            while( 1 )
            {
                int len;

                usart_led_flash();

                // read data.
                len = rt_device_read(dev_uart1,0,rx_buf+rx_buf_offset,RX_BUF_SIZE-rx_buf_offset);
                if( len == 0 )
                {
                    len = rt_device_read(dev_uart2,0,rx_buf+rx_buf_offset,RX_BUF_SIZE-rx_buf_offset);
                }
                usart_bytes_recv += len;

                // If buffer is empty and we received data, start the timer.
                if( rx_buf_offset == 0 )
                {
                    if( len == 0 )
                    {
                        break;
                    }
                    else
                    {
                        // if interval less than 10ms, we send data immediately.
                        if( max_interval >= 10 )
                            rt_timer_start(&max_interval_timer);
                    }
                }

                // move offset pointer.
                rx_buf_offset += len;

                // check if we should send data out.
                if( rx_buf_offset < max_datalen &&
                    max_interval_timer.parent.flag & RT_TIMER_FLAG_ACTIVATED )
                {
                    break;
                }

                // Send data out.
                if((current_mode == TCP_SERVER)||
                        (current_mode == TCP_CLIENT)||
                        (current_mode == TCP_AUTO))
                {
                    int i;
                    // send data.
                    for( i = 0 ; i < SOCKET_LIST_SIZE ; i++ )
                    {
                        // we should not use RT_WAITING_FOREVER here.
                        if( rt_mutex_take(&(socket_list[i].mu_sock),10) != RT_EOK )
                            continue;
                        // slot not used.
                        if( socket_list[i].used )
                        {
                            // shall not blocking.
                            if( lwip_send(socket_list[i].socket,rx_buf,rx_buf_offset,0) < 0 )
                            {
                                // connection lost.
                                lwip_close(socket_list[i].socket);
                                socket_list[i].used = 0;
                                rt_kprintf("Connection lost.\n");
                            }
                        }
                        rt_mutex_release(&(socket_list[i].mu_sock));
                    }
                }
                else if( (current_mode == UDP)||
                        (current_mode == UDP_MULTICAST) )
                {
                    if( rt_mutex_take(&(socket_list[0].mu_sock),10) == RT_EOK )
                    {
                        if( socket_list[0].used )
                        {
                            lwip_sendto(socket_list[0].socket,rx_buf,rx_buf_offset,0,
                                    (struct sockaddr*)&(socket_list[0].cliaddr), sizeof(struct sockaddr));
                        }
                        rt_mutex_release(&(socket_list[0].mu_sock));
                    }
                }
                else
                {
                    rt_kprintf("fatal error! rx thread exits.\n");
                    return;
                }
                rx_buf_offset = 0;
            }
        }
    }
    rt_kprintf("Error taking semaphore, usart rx exit!\n");
}