Beispiel #1
0
void cleanup(struct connection *pConn)
{
  cleanupBuffers(pConn);
  if(pConn->hairtunes != NULL)
  {

    closePipe(&(pConn->hairtunes->in[0]));
    closePipe(&(pConn->hairtunes->in[1]));
    closePipe(&(pConn->hairtunes->out[0]));
    closePipe(&(pConn->hairtunes->out[1]));
  }
  if(pConn->keys != NULL)
  {
    if(pConn->keys->aesiv != NULL)
    {
      free(pConn->keys->aesiv);
    }
    if(pConn->keys->aeskey != NULL)
    {
      free(pConn->keys->aeskey);
    }
    if(pConn->keys->fmt != NULL)
    {
      free(pConn->keys->fmt);
    }
    pConn->keys = NULL;
  }
  if(pConn->clientSocket != -1)
  {
    close(pConn->clientSocket);
    pConn->clientSocket = -1;
  }
}
 void LineSegmentCollector::triggerCallback(
   const jsk_recognition_msgs::TimeRange::ConstPtr& trigger)
 {
   boost::mutex::scoped_lock lock(mutex_);
   time_range_ = trigger;
   cleanupBuffers(time_range_->start);
 }
Beispiel #3
0
void CGDISimpleThread::cleanup() {
	cleanupBuffers();

	if ( hDesktopDC )
		ReleaseDC( hDesktopWnd, hDesktopDC );
	if ( hCaptureDC )
		DeleteDC( hCaptureDC );	
}
Beispiel #4
0
/**
 * Delete all arrays (if not already done before....)
 */
SciIllLib::CMesh::~CMesh()
{
    glDeleteVertexArrays(1, &m_vao);
    glDeleteBuffers(3, &m_vbo[0]);
    glDeleteBuffers(1, &m_vboIdx);

    if (m_arrIdx != NULL)
        delete [] m_arrIdx;
    
    cleanupBuffers();
    
    delete m_shader;
}
Beispiel #5
0
bool BoardFXO::KhompPvtFXO::setupConnection()
{
    if(!call()->_flags.check(Kflags::IS_INCOMING) && !call()->_flags.check(Kflags::IS_OUTGOING))
    {
        DBG(FUNC,PVT_FMT(_target, "Channel already disconnected"));
        return false;
    }

    callFXO()->_flags.clear(Kflags::CALL_WAIT_SEIZE);
    callFXO()->_flags.clear(Kflags::WAIT_SEND_DTMF);

    /* if received some disconnect from 'drop collect call'
       feature of some pbx, then leave the call rock and rolling */
    //Board::board(_target.device)->_timers.del(callFXO()->_idx_disconnect);

    bool fax_detected = callFXO()->_flags.check(Kflags::FAX_DETECTED) || (callFXO()->_var_fax_adjust == T_TRUE);

    bool res_out_of_band_dtmf = (call()->_var_dtmf_state == T_UNKNOWN || fax_detected ?
        Opt::_options._suppression_delay() && Opt::_options._out_of_band_dtmfs() && !fax_detected : (call()->_var_dtmf_state == T_TRUE));

    bool res_echo_cancellator = (call()->_var_echo_state == T_UNKNOWN || fax_detected ?
        Opt::_options._echo_canceller() && !fax_detected : (call()->_var_echo_state == T_TRUE));

    bool res_auto_gain_cntrol = (call()->_var_gain_state == T_UNKNOWN || fax_detected ?
        Opt::_options._auto_gain_control() && !fax_detected : (call()->_var_gain_state == T_TRUE));

    if (!call()->_flags.check(Kflags::REALLY_CONNECTED))
    {
        obtainRX(res_out_of_band_dtmf);

        /* esvazia buffers de leitura/escrita */
        cleanupBuffers();

        if (!call()->_flags.check(Kflags::KEEP_DTMF_SUPPRESSION))
            dtmfSuppression(res_out_of_band_dtmf);

        if (!call()->_flags.check(Kflags::KEEP_ECHO_CANCELLATION))
            echoCancellation(res_echo_cancellator);

        if (!call()->_flags.check(Kflags::KEEP_AUTO_GAIN_CONTROL))
            autoGainControl(res_auto_gain_cntrol);

        startListen(false);

        startStream();

        DBG(FUNC, PVT_FMT(_target, "(FXO) Audio callbacks initialized successfully"));
    }

    return KhompPvt::setupConnection();
}
 inline void TreeBcast_slu<T>::Reset(){
   assert(done_);
   cleanupBuffers();
   done_=false;
   fwded_=false;
   recvDataPtrs_.assign(GetNumMsgToRecv(),NULL);
   recvRequests_.assign(GetNumMsgToRecv(),MPI_REQUEST_NULL);
   sendDataPtrs_.assign(GetNumMsgToSend(),NULL);
   sendRequests_.assign(GetNumMsgToSend(),MPI_REQUEST_NULL);
   // isAllocated_=false;
   isReady_=false;
   recvCount_ = 0;
   sendCount_ = 0;
   recvPostedCount_ = 0;
   sendPostedCount_ = 0;
 }
Beispiel #7
0
bool BoardGSM::KhompPvtGSM::setupConnection()
{
    if(!call()->_flags.check(Kflags::IS_INCOMING) && !call()->_flags.check(Kflags::IS_OUTGOING))
    {
        DBG(FUNC,PVT_FMT(_target, "Channel already disconnected"));
        return false;
    }

    bool res_out_of_band_dtmf = (call()->_var_dtmf_state == T_UNKNOWN ?
                                 Opt::_options._suppression_delay() && Opt::_options._out_of_band_dtmfs() : (call()->_var_dtmf_state == T_TRUE));

    bool res_echo_cancellator = (call()->_var_echo_state == T_UNKNOWN ?
                                 Opt::_options._echo_canceller() : (call()->_var_echo_state == T_TRUE));


    bool res_auto_gain_cntrol = (call()->_var_gain_state == T_UNKNOWN ?
                                 Opt::_options._auto_gain_control() : (call()->_var_gain_state == T_TRUE));


    if (!call()->_flags.check(Kflags::REALLY_CONNECTED))
    {
        obtainRX(res_out_of_band_dtmf);

        /* esvazia buffers de leitura/escrita */
        cleanupBuffers();

        if (!call()->_flags.check(Kflags::KEEP_DTMF_SUPPRESSION))
            dtmfSuppression(res_out_of_band_dtmf);

        if (!call()->_flags.check(Kflags::KEEP_ECHO_CANCELLATION))
            echoCancellation(res_echo_cancellator);

        if (!call()->_flags.check(Kflags::KEEP_AUTO_GAIN_CONTROL))
            autoGainControl(res_auto_gain_cntrol);

        startListen(false);

        startStream();

        DBG(FUNC, PVT_FMT(_target, "(GSM) Audio callbacks initialized successfully"));
    }

    return Board::KhompPvt::setupConnection();
}
Beispiel #8
0
bool SciIllLib::CMesh::InitializeGLBuffer()
{
  CGLInfo::CheckError("IntializeGLBuffer");
	GLint locAttrVertex = m_shader->attribLocation("vertex");
	GLint locAttrNormal = m_shader->attribLocation("normal");
	GLint locAttrTexCoord = m_shader->attribLocation("texCoord");
	GLint locAttrTangent = m_shader->attribLocation("tangent");
	GLint locAttrBinormal = m_shader->attribLocation("binormal");

  glGenVertexArrays(1, &m_vao);
  glBindVertexArray(m_vao);
  
	glGenBuffers(5, &m_vbo[0]);
    
  bool found = false;
  found |= setupVertexAttrib(locAttrVertex,    m_vbo[VBO_VERTEX],      4, m_arrVertex);
  found |= setupVertexAttrib(locAttrNormal,    m_vbo[VBO_NORMAL],      4, m_arrNormal);
  found |= setupVertexAttrib(locAttrTexCoord,  m_vbo[VBO_TEXCOORD],    2, m_arrTexCoord);
  
  if (locAttrTangent * locAttrBinormal > 0)
  {
      calculateTB(m_arrVertex, m_arrTexCoord);
      found |= setupVertexAttrib(locAttrTangent,   m_vbo[VBO_TANGENT],     3, m_arrTangent);
      found |= setupVertexAttrib(locAttrBinormal,  m_vbo[VBO_BINORMAL],    3, m_arrBinormal);
  }
  if (found)
  {
      glGenBuffers(1, &m_vboIdx);
      glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, m_vboIdx);
      glBufferData(GL_ELEMENT_ARRAY_BUFFER, m_countIdx * sizeof(GLuint), m_arrIdx, GL_STATIC_DRAW);
  }

  cleanupBuffers();
  
  glBindVertexArray(0);

	return true;
}
Beispiel #9
0
//parseMessage(tConn->recv.data, tConn->recv.mark, &tConn->resp, ipstr, pHWADDR, tConn->keys);
int parseMessage(struct connection *pConn, unsigned char *pIpBin, unsigned int pIpBinLen, char *pHWID)
{
  int tReturn = 0; // 0 = good, 1 = Needs More Data, -1 = close client socket.
  if(pConn->resp.data == NULL)
  {
    initBuffer(&(pConn->resp), MAX_SIZE);
  }

  char *tContent = getFromHeader(pConn->recv.data, "Content-Length", NULL);
  if(tContent != NULL)
  {
    int tContentSize = atoi(tContent);
    if(pConn->recv.marker == 0 || strlen(pConn->recv.data+pConn->recv.marker) != tContentSize)
    {
      if(isLogEnabledFor(HEADER_LOG_LEVEL))
      {
        slog(HEADER_LOG_LEVEL, "Content-Length: %s value -> %d\n", tContent, tContentSize);
        if(pConn->recv.marker != 0)
        {
          slog(HEADER_LOG_LEVEL, "ContentPtr has %d, but needs %d\n", 
                  strlen(pConn->recv.data+pConn->recv.marker), tContentSize);
        }
      }
      // check if value in tContent > 2nd read from client.
      return 1; // means more content-length needed
    }
  }
  else
  {
    slog(LOG_DEBUG_VV, "No content, header only\n");
  }

  // "Creates" a new Response Header for our response message
  addToShairBuffer(&(pConn->resp), "RTSP/1.0 200 OK\r\n");

  if(isLogEnabledFor(LOG_INFO))
  {
    int tLen = strchr(pConn->recv.data, ' ') - pConn->recv.data;
    if(tLen < 0 || tLen > 20)
    {
      tLen = 20;
    }
    slog(LOG_INFO, "********** RECV %.*s **********\n", tLen, pConn->recv.data);
  }

  if(pConn->password != NULL)
  {
    
  }

  if(buildAppleResponse(pConn, pIpBin, pIpBinLen, pHWID)) // need to free sig
  {
    slog(LOG_DEBUG_V, "Added AppleResponse to Apple-Challenge request\n");
  }

  // Find option, then based on option, do different actions.
  if(strncmp(pConn->recv.data, "OPTIONS", 7) == 0)
  {
    propogateCSeq(pConn);
    addToShairBuffer(&(pConn->resp),
      "Public: ANNOUNCE, SETUP, RECORD, PAUSE, FLUSH, TEARDOWN, OPTIONS, GET_PARAMETER, SET_PARAMETER\r\n");
  }
  else if(!strncmp(pConn->recv.data, "ANNOUNCE", 8))
  {
    char *tContent = pConn->recv.data + pConn->recv.marker;
    int tSize = 0;
    char *tHeaderVal = getFromContent(tContent, "a=aesiv", &tSize); // Not allocated memory, just pointing
    if(tSize > 0)
    {
      int tKeySize = 0;
      char tEncodedAesIV[tSize + 2];
      getTrimmed(tHeaderVal, tSize, TRUE, TRUE, tEncodedAesIV);
      slog(LOG_DEBUG_VV, "AESIV: [%.*s] Size: %d  Strlen: %d\n", tSize, tEncodedAesIV, tSize, strlen(tEncodedAesIV));
      char *tDecodedIV =  decode_base64((unsigned char*) tEncodedAesIV, tSize, &tSize);

      // grab the key, copy it out of the receive buffer
      tHeaderVal = getFromContent(tContent, "a=rsaaeskey", &tKeySize);
      char tEncodedAesKey[tKeySize + 2]; // +1 for nl, +1 for \0
      getTrimmed(tHeaderVal, tKeySize, TRUE, TRUE, tEncodedAesKey);
      slog(LOG_DEBUG_VV, "AES KEY: [%s] Size: %d  Strlen: %d\n", tEncodedAesKey, tKeySize, strlen(tEncodedAesKey));
      // remove base64 coding from key
      char *tDecodedAesKey = decode_base64((unsigned char*) tEncodedAesKey,
                              tKeySize, &tKeySize);  // Need to free DecodedAesKey

      // Grab the formats
      int tFmtpSize = 0;
      char *tFmtp = getFromContent(tContent, "a=fmtp", &tFmtpSize);  // Don't need to free
      tFmtp = getTrimmedMalloc(tFmtp, tFmtpSize, TRUE, FALSE); // will need to free
      slog(LOG_DEBUG_VV, "Format: %s\n", tFmtp);

      RSA *rsa = loadKey();
      // Decrypt the binary aes key
      char *tDecryptedKey = malloc(RSA_size(rsa) * sizeof(char)); // Need to Free Decrypted key
      //char tDecryptedKey[RSA_size(rsa)];
      if(RSA_private_decrypt(tKeySize, (unsigned char *)tDecodedAesKey, 
      (unsigned char*) tDecryptedKey, rsa, RSA_PKCS1_OAEP_PADDING) >= 0)
      {
        slog(LOG_DEBUG, "Decrypted AES key from RSA Successfully\n");
      }
      else
      {
        slog(LOG_INFO, "Error Decrypting AES key from RSA\n");
      }
      free(tDecodedAesKey);
      RSA_free(rsa);

      setKeys(pConn->keys, tDecodedIV, tDecryptedKey, tFmtp);

      propogateCSeq(pConn);
    }
  }
  else if(!strncmp(pConn->recv.data, "SETUP", 5))
  {
    // Setup pipes
//    struct comms *tComms = pConn->hairtunes;
//   if (! (pipe(tComms->in) == 0 && pipe(tComms->out) == 0))
//    {
//      slog(LOG_INFO, "Error setting up hairtunes communications...some things probably wont work very well.\n");
//    }
    
    // Setup fork
    char tPort[8] = "6000";  // get this from dup()'d stdout of child pid

    printf("******** SETUP!!!!!\n");
#ifndef BOXEE
    int tPid = fork();
    if(tPid == 0)
    {
#endif
      int tDataport=0;
      char tCPortStr[8] = "59010";
      char tTPortStr[8] = "59012";
      int tSize = 0;

      char *tFound  =getFromSetup(pConn->recv.data, "control_port", &tSize);
      getTrimmed(tFound, tSize, 1, 0, tCPortStr);
      tFound = getFromSetup(pConn->recv.data, "timing_port", &tSize);
      getTrimmed(tFound, tSize, 1, 0, tTPortStr);

      slog(LOG_DEBUG_VV, "converting %s and %s from str->int\n", tCPortStr, tTPortStr);
      int tControlport = atoi(tCPortStr);
      int tTimingport = atoi(tTPortStr);

      slog(LOG_DEBUG_V, "Got %d for CPort and %d for TPort\n", tControlport, tTimingport);
      char *tRtp = NULL;
      char *tPipe = NULL;
      char *tAoDriver = NULL;
      char *tAoDeviceName = NULL;
      char *tAoDeviceId = NULL;
      struct keyring *tKeys = pConn->keys;

#ifndef BOXEE
      // *************************************************
      // ** Setting up Pipes, AKA no more debug/output  **
      // *************************************************
      dup2(tComms->in[0],0);   // Input to child
      closePipe(&(tComms->in[0]));
      closePipe(&(tComms->in[1]));

      dup2(tComms->out[1], 1); // Output from child
      closePipe(&(tComms->out[1]));
      closePipe(&(tComms->out[0]));

      pConn->keys = NULL;
      pConn->hairtunes = NULL;

      // Free up any recv buffers, etc..
      if(pConn->clientSocket != -1)
      {
        close(pConn->clientSocket);
        pConn->clientSocket = -1;
      }
      cleanupBuffers(pConn);
#endif
      hairtunes_init(tKeys->aeskey, tKeys->aesiv, tKeys->fmt, tControlport, tTimingport,
                      tDataport, tRtp, tPipe, tAoDriver, tAoDeviceName, tAoDeviceId);
#ifndef BOXEE
      // Quit when finished.
      slog(LOG_DEBUG, "Returned from hairtunes init....returning -1, should close out this whole side of the fork\n");
      return -1;
    }
    else if(tPid >0)
    {
      // Ensure Connection has access to the pipe.
      closePipe(&(tComms->in[0]));
      closePipe(&(tComms->out[1]));

      char tFromHairtunes[80];
      int tRead = read(tComms->out[0], tFromHairtunes, 80);
      if(tRead <= 0)
      {
        slog(LOG_INFO, "Error reading port from hairtunes function, assuming default port: %d\n", tPort);
      }
      else
      {
        int tSize = 0;
        char *tPortStr = getFromHeader(tFromHairtunes, "port", &tSize);
        if(tPortStr != NULL)
        {
          getTrimmed(tPortStr, tSize, TRUE, FALSE, tPort);
        }
        else
        {
          slog(LOG_INFO, "Read %d bytes, Error translating %s into a port\n", tRead, tFromHairtunes);
        }
      }

      int tSize;
#endif

      //  READ Ports from here?close(pConn->hairtunes_pipes[0]);
      propogateCSeq(pConn);
      tSize = 0;
      char *tTransport = getFromHeader(pConn->recv.data, "Transport", &tSize);
      addToShairBuffer(&(pConn->resp), "Transport: ");
      addNToShairBuffer(&(pConn->resp), tTransport, tSize);
      // Append server port:
      addToShairBuffer(&(pConn->resp), ";server_port=");
      addToShairBuffer(&(pConn->resp), tPort);
      addToShairBuffer(&(pConn->resp), "\r\nSession: DEADBEEF\r\n");
#ifndef BOXEE
    }
    else
    {
      slog(LOG_INFO, "Error forking process....dere' be errors round here.\n");
      return -1;
    }
#endif
  }
  else if(!strncmp(pConn->recv.data, "TEARDOWN", 8))
  {
    // Be smart?  Do more finish up stuff...
    addToShairBuffer(&(pConn->resp), "Connection: close\r\n");
    propogateCSeq(pConn);
#ifndef BOXEE
    close(pConn->hairtunes->in[1]);
    slog(LOG_DEBUG, "Tearing down connection, closing pipes\n");
#else
    hairtunes_cleanup();
#endif
    //close(pConn->hairtunes->out[0]);
    tReturn = -1;  // Close client socket, but sends an ACK/OK packet first
  }
  else if(!strncmp(pConn->recv.data, "FLUSH", 5))
  {
    // TBD FLUSH
#ifndef BOXEE
    write(pConn->hairtunes->in[1], "flush\n", 6);
#else
    hairtunes_flush();
#endif
    propogateCSeq(pConn);
  }
  else if(!strncmp(pConn->recv.data, "SET_PARAMETER", 13))
  {
    propogateCSeq(pConn);
    int tSize = 0;
    char *tVol = getFromHeader(pConn->recv.data, "volume", &tSize);
    slog(LOG_DEBUG_VV, "About to write [vol: %.*s] data to hairtunes\n", tSize, tVol);
    // TBD VOLUME
#ifndef BOXEE
    write(pConn->hairtunes->in[1], "vol: ", 5);
    write(pConn->hairtunes->in[1], tVol, tSize);
    write(pConn->hairtunes->in[1], "\n", 1);
#else
    hairtunes_setvolume(atof(tVol));
#endif
    slog(LOG_DEBUG_VV, "Finished writing data write data to hairtunes\n");
  }
  else
  {
    slog(LOG_DEBUG, "\n\nUn-Handled recv: %s\n", pConn->recv.data);
    propogateCSeq(pConn);
  }
  addToShairBuffer(&(pConn->resp), "\r\n");
  return tReturn;
}
Beispiel #10
0
void handleClient(int pSock, char *pPassword, char *pHWADDR)
{
  slog(LOG_DEBUG_VV, "In Handle Client\n");
  fflush(stdout);

  socklen_t len;
  struct sockaddr_storage addr;
  #ifdef AF_INET6
  unsigned char ipbin[INET6_ADDRSTRLEN];
  #else
  unsigned char ipbin[INET_ADDRSTRLEN];
  #endif
  unsigned int ipbinlen;
  int port;
  char ipstr[64];

  len = sizeof addr;
  getsockname(pSock, (struct sockaddr*)&addr, &len);

  // deal with both IPv4 and IPv6:
  if (addr.ss_family == AF_INET) {
      slog(LOG_DEBUG_V, "Constructing ipv4 address\n");
      struct sockaddr_in *s = (struct sockaddr_in *)&addr;
      port = ntohs(s->sin_port);
      inet_ntop(AF_INET, &s->sin_addr, ipstr, sizeof ipstr);
      memcpy(ipbin, &s->sin_addr, 4);
      ipbinlen = 4;
  } else { // AF_INET6
      struct sockaddr_in6 *s = (struct sockaddr_in6 *)&addr;
      port = ntohs(s->sin6_port);
      inet_ntop(AF_INET6, &s->sin6_addr, ipstr, sizeof ipstr);

      union {
        struct sockaddr_in6 s;
        unsigned char bin[sizeof(struct sockaddr_in6)];
      } addr;
      memcpy(&addr.s, &s->sin6_addr, sizeof(struct sockaddr_in6));

      if(memcmp(&addr.bin[0], "\x00\x00\x00\x00" "\x00\x00\x00\x00" "\x00\x00\xff\xff", 12) == 0)
      {
        // its ipv4...
        slog(LOG_DEBUG_V, "Constructing ipv4 from ipv6 address\n");
        memcpy(ipbin, &addr.bin[12], 4);
        ipbinlen = 4;
      }
      else
      {
        slog(LOG_DEBUG_V, "Constructing ipv6 address\n");
        memcpy(ipbin, &s->sin6_addr, 16);
        ipbinlen = 16;
      }
  }

  slog(LOG_DEBUG_V, "Peer IP address: %s\n", ipstr);
  slog(LOG_DEBUG_V, "Peer port      : %d\n", port);

  int tMoreDataNeeded = 1;
  struct keyring     tKeys;
  struct comms       tComms;
  struct connection  tConn;
  initConnection(&tConn, &tKeys, &tComms, pSock, pPassword);

  while(1)
  {
    tMoreDataNeeded = 1;

    initBuffer(&tConn.recv, 80); // Just a random, small size to seed the buffer with.
    initBuffer(&tConn.resp, 80);
    
    int tError = FALSE;
    while(1 == tMoreDataNeeded)
    {
      tError = readDataFromClient(pSock, &(tConn.recv));
      if(!tError && strlen(tConn.recv.data) > 0)
      {
        slog(LOG_DEBUG_VV, "Finished Reading some data from client\n");
        // parse client request
        tMoreDataNeeded = parseMessage(&tConn, ipbin, ipbinlen, pHWADDR);
        if(1 == tMoreDataNeeded)
        {
          slog(LOG_DEBUG_VV, "\n\nNeed to read more data\n");
        }
        else if(-1 == tMoreDataNeeded) // Forked process down below ended.
        {
          slog(LOG_DEBUG_V, "Forked Process ended...cleaning up\n");
          cleanup(&tConn);
          // pSock was already closed
          return;
        }
        // if more data needed,
      }
      else
      {
        slog(LOG_DEBUG, "Error reading from socket, closing client\n");
        // Error reading data....quit.
        cleanup(&tConn);
        return;
      }
    }
    slog(LOG_DEBUG_VV, "Writing: %d chars to socket\n", tConn.resp.current);
    //tConn->resp.data[tConn->resp.current-1] = '\0';
    writeDataToClient(pSock, &(tConn.resp));
   // Finished reading one message...
    cleanupBuffers(&tConn);
  }
  cleanup(&tConn);
  fflush(stdout);
}
Beispiel #11
0
static void handleClient(int pSock, char *pPassword, char *pHWADDR)
{
  slog(LOG_DEBUG_VV, "In Handle Client\n");
  fflush(stdout);

  socklen_t len;
  struct sockaddr_storage addr;
  #ifdef AF_INET6
  unsigned char ipbin[INET6_ADDRSTRLEN];
  #else
  unsigned char ipbin[INET_ADDRSTRLEN];
  #endif
  unsigned int ipbinlen;
  int port = 0;
  char ipstr[64];

  len = sizeof addr;
  getsockname(pSock, (struct sockaddr*)&addr, &len);

  // deal with both IPv4 and IPv6:
  if (addr.ss_family == AF_INET) {
      slog(LOG_DEBUG_V, "Constructing ipv4 address\n");
      struct sockaddr_in *s = (struct sockaddr_in *)&addr;
      port = ntohs(s->sin_port);
      inet_ntop(AF_INET, &s->sin_addr, ipstr, sizeof ipstr);
      memcpy(ipbin, &s->sin_addr, 4);
      ipbinlen = 4;
  }

  slog(LOG_DEBUG_V, "Peer IP address: %s\n", ipstr);
  slog(LOG_DEBUG_V, "Peer port      : %d\n", port);

  int tMoreDataNeeded = 1;
  struct keyring     tKeys;
  struct comms       tComms;
  struct connection  tConn;
  fd_set rfds;
  int max_fd = pSock + 1;
  int session_started = 0;
  struct timeval recv_timeout;
  recv_timeout.tv_sec = GET_CONN_TIMEOUT(session_started);
  recv_timeout.tv_usec = 0;
  int selsock = 0;
  char rbuf[80];
  int rlen;
  unsigned long udp_pkc = 0, udp_pkc_new;
  FD_ZERO(&rfds);
  initConnection(&tConn, &tKeys, &tComms, pSock, pPassword);

  FD_SET(pSock, &rfds);
  while((selsock = select(max_fd, &rfds, 0, 0, &recv_timeout)) != -1)
  {
      if((selsock == 0) && (session_started)){
          if((tComms.in[1] > 2) && (tComms.out[0] > 2)){
              fprintf(stderr,"timeout\n");
              write(tComms.in[1], "status\n", 7);
              rlen = read(tComms.out[0], rbuf, sizeof(rbuf));
              rbuf[rlen] = 0;
              udp_pkc_new = strtoul(rbuf, NULL, 10);
              if(udp_pkc_new == udp_pkc) {
                  fprintf(stderr,"no traffic, disconn\n");
                  fprintf(stderr, "get timeout rtp packet\n");
                  slog(LOG_DEBUG_V, "Forked Process ended...cleaning up\n");
                  cleanup(&tConn);
                  // pSock was already closed
                  return;
              }
              fprintf(stderr,"ok\n");
              udp_pkc = udp_pkc_new;
          }
      } 
      if(FD_ISSET(pSock, &rfds)) {
          tMoreDataNeeded = 1;

          initBuffer(&tConn.recv, 80); // Just a random, small size to seed the buffer with.
          initBuffer(&tConn.resp, 80);

          int tError = FALSE;
          while(1 == tMoreDataNeeded)
          {
              tError = readDataFromClient(pSock, &(tConn.recv));
              if(!tError && strlen(tConn.recv.data) > 0)
              {
                  slog(LOG_DEBUG_VV, "Finished Reading some data from client\n");
                  // parse client request
                  tMoreDataNeeded = parseMessage(&tConn, ipbin, ipbinlen, pHWADDR);
                  if((tComms.in[0] > 0) || (tComms.in[2] > 0) || (tComms.out[0] > 0) || (tComms.out[1] > 0)) {
                      session_started = 1;
                  }
                  if(1 == tMoreDataNeeded)
                  {
                      slog(LOG_DEBUG_VV, "\n\nNeed to read more data\n");
                  }
                  else if(-1 == tMoreDataNeeded) // Forked process down below ended.
                  {
                      slog(LOG_DEBUG_V, "Forked Process ended...cleaning up\n");
                      cleanup(&tConn);
                      // pSock was already closed
                      return;
                  }
                  // if more data needed,
              }
              else
              {
                  slog(LOG_DEBUG, "Error reading from socket, closing client\n");
                  // Error reading data....quit.
                  cleanup(&tConn);
                  return;
              }
          }
          slog(LOG_DEBUG_VV, "Writing: %d chars to socket\n", tConn.resp.current);
          //tConn->resp.data[tConn->resp.current-1] = '\0';
          writeDataToClient(pSock, &(tConn.resp));
          // Finished reading one message...
          cleanupBuffers(&tConn);
      }
      FD_SET(pSock, &rfds);
      recv_timeout.tv_sec = GET_CONN_TIMEOUT(session_started);;
      recv_timeout.tv_usec = 0;
  }
  cleanup(&tConn);
  fflush(stdout);
}
 TreeBcast_slu<T>::~TreeBcast_slu(){
   cleanupBuffers();
   MPI_Type_free( &type_ );
 }
Beispiel #13
0
/**
 * Loada heightmap and create the mesh.
 * @param filename filename that contains the heightmap
 * @param scale that is applied to the height (compared to max(width,height))
 * @param locAttrVertex location/index of the vertexattribute vertex-position
 * @param locAttrNormal location/index of the vertexattribute vertex-normal
 * @param locAttrTexCoord location/index of the vertexattribute vertex-texture coordinate
 */
bool SciIllLib::CMesh::InitializeGLBuffer()
{
    CGLInfo::CheckError("IntializeGLBuffer");
	GLint locAttrVertex = m_shader->attribLocation("vertex");
	GLint locAttrNormal = m_shader->attribLocation("normal");
	GLint locAttrTexCoord = m_shader->attribLocation("texCoord");
	GLint locAttrTangent = m_shader->attribLocation("tangent");
	GLint locAttrBinormal = m_shader->attribLocation("binormal");

    glGenVertexArrays(1, &m_vao);
    glBindVertexArray(m_vao);
    
    
	glGenBuffers(5, &m_vbo[0]);
    
    bool found = false;
    found |= setupVertexAttrib(locAttrVertex,    m_vbo[VBO_VERTEX],      4, m_arrVertex);
    found |= setupVertexAttrib(locAttrNormal,    m_vbo[VBO_NORMAL],      4, m_arrNormal);
    found |= setupVertexAttrib(locAttrTexCoord,  m_vbo[VBO_TEXCOORD],    2, m_arrTexCoord);
    
    if (locAttrTangent * locAttrBinormal > 0){
        calculateTB(m_arrVertex, m_arrTexCoord);
        found |= setupVertexAttrib(locAttrTangent,   m_vbo[VBO_TANGENT],     3, m_arrTangent);
        found |= setupVertexAttrib(locAttrBinormal,  m_vbo[VBO_BINORMAL],    3, m_arrBinormal);
    }
    //found |= setupVertexAttrib(locAttrTangent,   m_vbo[VBO_TANGENT],     3, m_arrTangent);
    //found |= setupVertexAttrib(locAttrBinormal,  m_vbo[VBO_BINORMAL],    3, m_arrBinormal);
    /*
	int idx = 0;
	if (locAttrVertex >= 0)
	{
		glBindBuffer(GL_ARRAY_BUFFER, m_vbo[VBO_VERTEX]);
		glBufferData(GL_ARRAY_BUFFER, m_countElements * 4 * sizeof(GLfloat), m_arrVertex, GL_STATIC_DRAW);
		glVertexAttribPointer(locAttrVertex, 4, GL_FLOAT, GL_FALSE, 0, 0);
		CGLInfo::CheckError("VA1 initialized ?");
		glEnableVertexAttribArray(locAttrVertex);
		CGLInfo::CheckError("VA1 initialized !");
	}

	if (locAttrNormal >= 0)
	{
		glBindBuffer(GL_ARRAY_BUFFER, m_vbo[VBO_NORMAL]);
		glBufferData(GL_ARRAY_BUFFER, m_countElements * 4 * sizeof(GLfloat), m_arrNormal, GL_STATIC_DRAW);
		glVertexAttribPointer(locAttrNormal, 4, GL_FLOAT, GL_FALSE, 0, 0);
		CGLInfo::CheckError("VA2 initialized ?");
		glEnableVertexAttribArray(locAttrNormal);
		CGLInfo::CheckError("VA2 initialized");
	}

    if (locAttrTexCoord >= 0)
	{
		glBindBuffer(GL_ARRAY_BUFFER, m_vbo[VBO_TEXCOORD]);
		glBufferData(GL_ARRAY_BUFFER, m_countElements * 2 * sizeof(GLfloat), m_arrTexCoord, GL_STATIC_DRAW);
		glVertexAttribPointer(locAttrTexCoord, 2, GL_FLOAT, GL_FALSE, 0, 0);
		CGLInfo::CheckError("VA3 initialized ?");
		glEnableVertexAttribArray(locAttrTexCoord);
		CGLInfo::CheckError("VA3 initialized");
	}

    if (locAttrTangent >= 0)
	{
		glBindBuffer(GL_ARRAY_BUFFER, m_vbo[VBO_TANGENT]);
		glBufferData(GL_ARRAY_BUFFER, m_countElements * 2 * sizeof(GLfloat), m_arrTexCoord, GL_STATIC_DRAW);
		glVertexAttribPointer(locAttrTexCoord, 2, GL_FLOAT, GL_FALSE, 0, 0);
		CGLInfo::CheckError("VA3 initialized ?");
		glEnableVertexAttribArray(locAttrTexCoord);
		CGLInfo::CheckError("VA3 initialized");
	}
    
    if (locAttrTexCoord >= 0)
	{
		glBindBuffer(GL_ARRAY_BUFFER, m_vbo[idx++]);
		glBufferData(GL_ARRAY_BUFFER, m_countElements * 2 * sizeof(GLfloat), m_arrTexCoord, GL_STATIC_DRAW);
		glVertexAttribPointer(locAttrTexCoord, 2, GL_FLOAT, GL_FALSE, 0, 0);
		CGLInfo::CheckError("VA3 initialized ?");
		glEnableVertexAttribArray(locAttrTexCoord);
		CGLInfo::CheckError("VA3 initialized");
	}
    */
    if (found)
    {
        glGenBuffers(1, &m_vboIdx);
        glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, m_vboIdx);
        glBufferData(GL_ELEMENT_ARRAY_BUFFER, m_countIdx * sizeof(GLuint), m_arrIdx, GL_STATIC_DRAW);
    }

    cleanupBuffers();
    
    glBindVertexArray(0);

	return true;
}
void CUniCaptureThread::run() {
	emit setIsRunning( true );
	init();

	delayTime = 10;	// initial delay time
	frameCounter = 0;
	frameTimer.start();
	
	while( !*stopThread ) {
		if ( *readyToProcess == true ) {			
			// Check resolution changes
			QRect screenGeometry = scr->geometry();

			int nScreenWidth  = screenGeometry.width();
			int nScreenHeight = screenGeometry.height();

			if ( nScreenWidth != ScreenWidth || nScreenHeight != ScreenHeight )	{
				ScreenWidth = nScreenWidth;
				ScreenHeight = nScreenHeight;

				cleanupBuffers();
				initBuffers();
			}  

			// Creating and filling regions data
			CRegions * regions = new CRegions( settings->getHorizontalSegmentWidth( ScreenWidth ), settings->getHorizontalHeight( ScreenHeight ),
				settings->getVerticalWidth( ScreenWidth ), settings->getVerticalSegmentHeight( ScreenHeight ) );
			
			// Horizontals
			// Top
			for ( unsigned short x = 0; x < settings->LEDnumH; x++ ) {
				QImage im = scr->grabWindow( desktopID, x * regions->hWidth, 0, regions->hWidth, regions->hHeight ).toImage();
				unsigned char * bufH_tmp = new unsigned char[ bufHSize ];
				memcpy( bufH_tmp, im.bits(), bufHSize );

				regions->regionHTop.push_back( bufH_tmp );
			}
			
			// Bottom
			for ( unsigned short x = 0; x < settings->LEDnumH; x++ ) {
				QImage im = scr->grabWindow( desktopID, x * regions->hWidth, ScreenHeight - regions->hHeight, regions->hWidth, regions->hHeight ).toImage();
				unsigned char * bufH_tmp = new unsigned char[ bufHSize ];
				memcpy( bufH_tmp, im.bits(), bufHSize );

				regions->regionHBottom.push_back( bufH_tmp );			
			}

			// Verticals
			// Left
			for ( int x = 0; x < settings->LEDnumV; x++ ) {
				QImage im = scr->grabWindow( desktopID, 0, x * regions->vHeight, regions->vWidth, regions->vHeight ).toImage();
				unsigned char * bufV_tmp = new unsigned char[ bufVSize ];
				memcpy( bufV_tmp, im.bits(), bufVSize );

				regions->regionVLeft.push_back( bufV_tmp );
			}
			
			// Right
			for ( int x = 0; x < settings->LEDnumV; x++ ) {
				QImage im = scr->grabWindow( desktopID, ScreenWidth - regions->vWidth, x * regions->vHeight, regions->vWidth, regions->vHeight ).toImage();
				unsigned char * bufV_tmp = new unsigned char[ bufVSize ];
				memcpy( bufV_tmp, im.bits(), bufVSize );

				regions->regionVRight.push_back( bufV_tmp );			
			}

			*readyToProcess = false;
			emit onImageCaptured( regions );
			++frameCounter;
			updateDelayTime();
		}		
		usleep( delayTime );
	}

	cleanup();
	emit setIsRunning( false );
	//*stopThread = true;
}
void CUniCaptureThread::cleanup() {
	cleanupBuffers();
}
Beispiel #16
0
void CGDISimpleThread::run() {
	emit setIsRunning( true );
	init();

	delayTime = 10;	// initial delay time
	frameCounter = 0;
	frameTimer.start();
	
	while( !*stopThread ) {
		if ( *readyToProcess == true ) {
			// Check for resolution changes
			int nScreenWidth = GetSystemMetrics(SM_CXSCREEN);
			int nScreenHeight = GetSystemMetrics(SM_CYSCREEN);

			if ( nScreenWidth != ScreenWidth || nScreenHeight != ScreenHeight )	{
				ScreenWidth = nScreenWidth;
				ScreenHeight = nScreenHeight;

				cleanupBuffers();
				initBuffers();
			}  

			// Creating and filling regions data
			CRegions * regions = new CRegions( settings->getHorizontalSegmentWidth( ScreenWidth ), settings->getHorizontalHeight( ScreenHeight ),
				settings->getVerticalWidth( ScreenWidth ), settings->getVerticalSegmentHeight( ScreenHeight ) );

			// Horizontals
			SelectObject( hCaptureDC, hCaptureBitmapH );
			// Top
			for ( unsigned short x = 0; x < settings->LEDnumH; x++ ) {
				BitBlt( hCaptureDC, 0, 0, regions->hWidth, regions->hHeight, hDesktopDC, x * regions->hWidth, 0, SRCCOPY|CAPTUREBLT );
				GetBitmapBits( hCaptureBitmapH, bufHSize, bufH );

				unsigned char * bufH_tmp = new unsigned char[ bufHSize ];
				memcpy( bufH_tmp, bufH, bufHSize );

				regions->regionHTop.push_back( bufH_tmp );
			}
			
			// Bottom
			for ( unsigned short x = 0; x < settings->LEDnumH; x++ ) {
				BitBlt( hCaptureDC, 0, 0, regions->hWidth, regions->hHeight, hDesktopDC, x * regions->hWidth, ScreenHeight - regions->hHeight, SRCCOPY|CAPTUREBLT );
				GetBitmapBits( hCaptureBitmapH, bufHSize, bufH );

				unsigned char * bufH_tmp = new unsigned char[ bufHSize ];
				memcpy( bufH_tmp, bufH, bufHSize );

				regions->regionHBottom.push_back( bufH_tmp );			
			}

			// Verticals
			SelectObject(hCaptureDC,hCaptureBitmapV);
			// Left
			for ( int x = 0; x < settings->LEDnumV; x++ ) {
				BitBlt( hCaptureDC, 0, 0, regions->vWidth, regions->vHeight, hDesktopDC, 0, x * regions->vHeight, SRCCOPY|CAPTUREBLT );
				GetBitmapBits( hCaptureBitmapV, bufVSize, bufV );

				unsigned char * bufV_tmp = new unsigned char[ bufVSize ];
				memcpy( bufV_tmp, bufV, bufVSize );

				regions->regionVLeft.push_back( bufV_tmp );
			}
			
			// Right
			for ( int x = 0; x < settings->LEDnumV; x++ ) {
				BitBlt( hCaptureDC, 0, 0, regions->vWidth, regions->vHeight, hDesktopDC, ScreenWidth - regions->vWidth, x * regions->vHeight, SRCCOPY|CAPTUREBLT );
				GetBitmapBits( hCaptureBitmapV, bufVSize, bufV );

				unsigned char * bufV_tmp = new unsigned char[ bufVSize ];
				memcpy( bufV_tmp, bufV, bufVSize );

				regions->regionVRight.push_back( bufV_tmp );			
			}

			*readyToProcess = false;
			emit onImageCaptured( regions );
			++frameCounter;
			updateDelayTime();
		}		
		usleep( delayTime );
	}
	cleanup();
	emit setIsRunning( false );
	//*stopThread = true;
}