PassRefPtr<SerializedScriptValue> SerializedScriptValueFactory::create(v8::Isolate* isolate, v8::Local<v8::Value> value, MessagePortArray* messagePorts, ArrayBufferArray* arrayBuffers, ImageBitmapArray* imageBitmaps, WebBlobInfoArray* blobInfo, ExceptionState& exceptionState)
{
    RefPtr<SerializedScriptValue> serializedValue = create();
    SerializedScriptValueWriter writer;
    ScriptValueSerializer::Status status;
    String errorMessage;
    {
        v8::TryCatch tryCatch;
        status = doSerialize(value, writer, messagePorts, arrayBuffers, imageBitmaps, blobInfo, serializedValue.get(), tryCatch, errorMessage, isolate);
        if (status == ScriptValueSerializer::JSException) {
            // If there was a JS exception thrown, re-throw it.
            exceptionState.rethrowV8Exception(tryCatch.Exception());
            return serializedValue.release();
        }
    }
    switch (status) {
    case ScriptValueSerializer::InputError:
    case ScriptValueSerializer::DataCloneError:
        exceptionState.throwDOMException(ScriptValueSerializer::DataCloneError, errorMessage);
        return serializedValue.release();
    case ScriptValueSerializer::Success:
        transferData(serializedValue.get(), writer, arrayBuffers, imageBitmaps, exceptionState, isolate);
        return serializedValue.release();
    case ScriptValueSerializer::JSException:
        ASSERT_NOT_REACHED();
        break;
    }
    ASSERT_NOT_REACHED();
    return serializedValue.release();
}
Beispiel #2
0
/* 
 * sends the request then it gets data from the outside server then sends to outside client
 */
void* doit(void * data){
  struct treadInfo *thread=(struct doitInfo *)data;
  int   portValue=0;
  int  *port=&portValue;

  //ignore SIGPIPE singal
  signal(SIGPIPE, SIG_IGN);

  //builds the request from client
  struct requestInfo getRequest=request(thread,port);
  
  //connecting to server  if fails closes //need to change to own function
  (*thread).serverfd=serverConnection((char *)getRequest.hostname,*getRequest.port,thread);
  
  //prints out the request will add to request function
  printf("Thread %d: Forwarding request to end server:\n",(*thread).ID);
  printf("%s",(char *)getRequest.request);
  printf("*** End of Request ***\n\n");
  
  //set Rio
  rio_readinitb(&(*thread).rioWithServer,(*thread).serverfd);

  //send request
  rio_writen_w((*thread).serverfd,getRequest.request,strlen((const char *)getRequest.request),thread);

  //transfer recieved data from server to client
  transferData(thread);
  
  //should never reach this exit()
  exit(0);
}
Beispiel #3
0
void GridGpu::gridding(complexVector &trajData)
{
    if (trajData.size() != m_kSize)
        qCritical() << "Size of k-space data not equal to the size of trajactory.";

    transferData(trajData);
    cudaError_t status = kernelCall();
    if (status != cudaSuccess)
        qWarning() << cudaGetErrorString(status);
}
Beispiel #4
0
    void processQuery() {
        QTcpSocket *socket = qobject_cast<QTcpSocket*>(sender());
        QByteArray requestData = socket->readAll();

        int pos = requestData.indexOf("\r\n");
        QByteArray requestLine = requestData.left(pos);
        requestData.remove(0, pos + 2);

        QList<QByteArray> entries = requestLine.split(' ');
        QByteArray method = entries.value(0);
        QByteArray address = entries.value(1);
        QByteArray version = entries.value(2);

        QUrl url = QUrl::fromEncoded(address);
        if (!url.isValid()) {
            qWarning() << "Invalid URL:" << url;
            socket->disconnectFromHost();
            return;
        }

        QString host = url.host();
        int port = (url.port() < 0) ? 80 : url.port();
        QByteArray req = url.encodedPath();
        if (url.hasQuery())
            req.append('?').append(url.encodedQuery());
        requestLine = method + " " + req + " " + version + "\r\n";
        requestData.prepend(requestLine);

        QString key = host + ':' + QString::number(port);
        QTcpSocket *proxySocket = socket->findChild<QTcpSocket*>(key);
        if (proxySocket) {
            proxySocket->setObjectName(key);
            proxySocket->setProperty("url", url);
            proxySocket->setProperty("requestData", requestData);
            proxySocket->write(requestData);
        } else {
            proxySocket = new QTcpSocket(socket);
            proxySocket->setObjectName(key);
            proxySocket->setProperty("url", url);
            proxySocket->setProperty("requestData", requestData);
            connect(proxySocket, SIGNAL(connected()), this, SLOT(sendRequest()));
            connect(proxySocket, SIGNAL(readyRead()), this, SLOT(transferData()));
            connect(proxySocket, SIGNAL(disconnected()), this, SLOT(closeConnection()));
            connect(proxySocket, SIGNAL(error(QAbstractSocket::SocketError)), this, SLOT(closeConnection()));
            proxySocket->connectToHost(host, port);
        }
    }
//-------------------------------------------------------------------------------------------------------------------------------------------
void FBXReader::transferDataFromSceneToModel(FbxScene* scene, Model* &model){
    model = new Model();
    LOG_DEBUG << "Start transferring data from scene to model...";

    FbxNode* rootNode = scene->GetRootNode();
    model->InitRootNode();
    Node* rootModelNode = model->RootNode;
    for (int i = 0; i < rootNode->GetChildCount(); i++)
    {
        Node* newNode = new Node();
        if (transferData(rootNode->GetChild(i), newNode)){
            rootModelNode->Children.push_back(newNode);
            rootModelNode->NumChildren = rootModelNode->Children.size();
        }
    }

    LOG_DEBUG << "Finish traferring data from scene to model !";
}
Beispiel #6
0
void BufferInterface::readBack()throw(BufferException)
{
	assert( "CPU buffer must exist for readback" && mCPU_Handle);

	transferData(false);

//	if(
//		( hasBufferInContext(OPEN_GL_CONTEXT_TYPE) && PARA_COMP_MANAGER->graphicsAreInControl() )
//		||
//		! (hasBufferInContext(OPEN_CL_CONTEXT_TYPE))
//	)
//	{
//		//commented out the guard in case of driver bugs fu**ing up when doing too mush time-shared CL-GL-stuff
//		//TODO uncomment when stable work is assured
//		//if(isCLGLShared())
//		{
//			PARA_COMP_MANAGER->acquireSharedBuffersForGraphics();
//		}
//
//		GUARD(readGL(mCPU_Handle));
//		return;
//	}
//
//	if(
//		( hasBufferInContext(OPEN_CL_CONTEXT_TYPE) && PARA_COMP_MANAGER->computeIsInControl() )
//		||
//		! (hasBufferInContext(OPEN_GL_CONTEXT_TYPE))
//	)
//	{
//		//commented out the guard in case of driver bugs fu**ing up when doing too mush time-shared CL-GL-stuff
//		//TODO uncomment when stable work is assured
//		//if(isCLGLShared())
//		{
//			PARA_COMP_MANAGER->acquireSharedBuffersForCompute();
//		}
//
//		GUARD(readCL(mCPU_Handle));
//		return;
//	}
//
//	throw(BufferException("BufferInterface::readBack(): need at least one GL or GL usage context in Buffer"));
}
//-------------------------------------------------------------------------------------------------------------------------------------------
bool FBXReader::transferData(FbxNode* node, Node* modelNode){
    if (node == NULL){
        throw new Exception("node is NULL!");
    }

    if (modelNode == NULL){        
        throw new Exception("modelNode is NULL!");
    }    

    modelNode->NodeName = node->GetName();

    FbxNodeAttribute::EType nodeAttributeType = node->GetNodeAttribute()->GetAttributeType();
    FbxMesh* fbxMesh = (FbxMesh*)node->GetNodeAttribute();
    Mesh* newMesh = NULL;
    switch (nodeAttributeType){
    case FbxNodeAttribute::eMarker:
        // Do nothing
        break;
    case FbxNodeAttribute::eSkeleton:
        // Do nothing
        break;
    case FbxNodeAttribute::eMesh:            
            newMesh = new Mesh();
            transferMesh(fbxMesh, newMesh);
            modelNode->Meshes.push_back(newMesh);
            modelNode->NumMeshes = modelNode->Meshes.size();
        break;
    case FbxNodeAttribute::eNurbs:
        // Do nothing
        break;
    case FbxNodeAttribute::ePatch:
        // Do nothing
        break;
    case FbxNodeAttribute::eCamera:
        // Do nothing
        break;
    case FbxNodeAttribute::eLight:
        // Do nothing
        break;
    case FbxNodeAttribute::eLODGroup:
        // Do nothing
        break;
    default: LOG_WARNING << "Can not identify the type of this mesh !";
        break;
    }

    // Read geometric transformation
    transferGeometricTransformation(node, modelNode);

    LOG_DEBUG << "Transfer data successfully! " << "Node's name: " << modelNode->NodeName;

    for (int i = 0; i < node->GetChildCount(); i++)
    {
        Node* newNode = new Node();
        if (transferData(node->GetChild(i), newNode)){
            modelNode->Children.push_back(newNode);
            modelNode->NumChildren = modelNode->Children.size();
        }
    }

    if (modelNode->NumChildren == 0 && modelNode->NumMeshes == 0){
        return false;
    }

    return true;
}
Beispiel #8
0
    /*------------------------------------------------------------------------------*

     *------------------------------------------------------------------------------*/
    void WebProxy::processQuery() {
        QTcpSocket *socket = qobject_cast<QTcpSocket*>(sender());
        QByteArray requestData = socket->readAll();

        int pos = requestData.indexOf("\r\n");
        QByteArray requestLine = requestData.left(pos);
        requestData.remove(0, pos + 2);

        QList<QByteArray> entries = requestLine.split(' ');
        QByteArray method = entries.value(0);
        QByteArray address = entries.value(1);
        QByteArray version = entries.value(2);

        qDebug( )  << __FILE__ << __FUNCTION__ << "Processing " << address;

        QUrl url = QUrl::fromEncoded(address);
        if (!url.isValid()) {
            //qWarning() << "Invalid URL:" << url;
            socket->disconnectFromHost();
            return;
        }

        //Act as server is request are for local server
        if ((url.host() == "") && (QFile(address).exists())) {
            //qDebug( )  << __FILE__ << __FUNCTION__ << "Sending " << address;
            QByteArray header;
            QTextStream headerStream(&header, QIODevice::WriteOnly);
            //Construct response header
            headerStream << "HTTP/1.0 200 OK" << endl;
            headerStream << "Server: gpsbook/" << qApp->applicationVersion() << endl;
            headerStream << "Date: " << QDateTime::currentDateTime().toUTC().toString("ddd, dd MMM yyyy hh:mm:ss") << "GMT" << endl;
            headerStream << "Content-Type: text/html; charset=utf-8" << endl;
            headerStream << "Connection: close" << endl;
            headerStream << "Pragma: no-cache" << endl;
            headerStream << "Cache-Control: no-cache" << endl;
            QFile file(address);
            if (!file.open(QFile::ReadOnly | QFile::Text))
            {
                 qWarning() << "Cannot open:" << address;
                 socket->disconnectFromHost();
                 return ;
            }

            QByteArray content;
            QTextStream contentStream(&content, QIODevice::WriteOnly);

            while (!file.atEnd()) {
                contentStream << file.readLine() << endl;
            }

            headerStream << "Content-Length:" << content.size() << endl;
            headerStream << "" << endl;

            socket->write(header);
            socket->write(content);
            //qDebug( )  << __FILE__ << __FUNCTION__ << "File sent (" << content.size() << "bytes) :-)";
            socket->disconnectFromHost();
        return;
        }


#if ( QT_VERSION >= QT_VERSION_CHECK(5, 0, 0) )
        // Some finction of QUrl have been deprecated
        // This code is require for the internet browser and should be reviewed.
#else


#ifdef Q_OS_LINUX
        //Remove advert to speedup development ;-)
        if (url.toString().contains("googlesyndication") ||
            url.toString().contains("yieldmanager.com")) {
            socket->disconnectFromHost();
            return;
        }
#endif

        qDebug( )  << __FILE__ << __FUNCTION__ << "URL: " << url.toString();

        QString host = url.host();
        int port = (url.port() < 0) ? 80 : url.port();
        QByteArray req = url.encodedPath();
        if (url.hasQuery())
            req.append('?').append(url.encodedQuery());
        requestLine = method + " " + req + " " + version + "\r\n";
        requestData.prepend(requestLine);

        QString key = host + ':' + QString::number(port);
        QTcpSocket *proxySocket = socket->findChild<QTcpSocket*>(key);
        if (proxySocket) {
            proxySocket->setObjectName(key);
            proxySocket->setProperty("url", url);
            proxySocket->setProperty("requestData", requestData);
            proxySocket->write(requestData);
        } else {
            proxySocket = new QTcpSocket(socket);
            proxySocket->setObjectName(key);
            proxySocket->setProperty("url", url);
            proxySocket->setProperty("requestData", requestData);
            connect(proxySocket, SIGNAL(connected()), this, SLOT(sendRequest()));
            connect(proxySocket, SIGNAL(readyRead()), this, SLOT(transferData()));
            connect(proxySocket, SIGNAL(disconnected()), this, SLOT(closeConnection()));
            connect(proxySocket, SIGNAL(error(QAbstractSocket::SocketError)), this, SLOT(closeConnection()));
            proxySocket->connectToHost(host, port);
        }
#endif
    } //WebProxy::processQuery
	virtual void onReadyToSendData(TcpConnectionEvent sourceEvent)
	{
		if (!parent->isCanTransfer()) return;
		if (completed && written == 0) finishTransfer();
		transferData(sourceEvent);
	}
Beispiel #10
0
int transferData(int fd, char *data) {
	int ret;
	char rx[20] = {0, };
	uint8_t txData[20] = {0, };
	for (ret=0;ret<TRANSFER_SIZE;ret++) {
	  txData[ret] = data[ret];
	}

	struct spi_ioc_transfer tr = {
	  .tx_buf = (unsigned long)txData,
	  .rx_buf = (unsigned long)rx,
	  .len = ARRAY_SIZE(txData),
	  .delay_usecs = delay,
	  .speed_hz = speed,
	  .bits_per_word = bits,
	};

	ret = ioctl(fd, SPI_IOC_MESSAGE(1), &tr);
	if (ret < 1)
		pabort("can't send spi message");
	printf("rx: %d\n", rx[0]);
	// check rx packets for diffent commands
	return rx[0];
}

int transferCmd(int fd, char *data) {
  	int ret;
	char rx[1] = {0, };
	char txData[1] = {data[0]};
      

	struct spi_ioc_transfer tr = {
	  .tx_buf = (unsigned long)txData,
	  .rx_buf = (unsigned long)rx,
	  .len = ARRAY_SIZE(txData),
	  .delay_usecs = delay,
	  .speed_hz = speed,
	  .bits_per_word = bits,
	};

	ret = ioctl(fd, SPI_IOC_MESSAGE(1), &tr);
	if (ret < 1)
		pabort("can't send spi message");

	printf("rx: %d\n", rx[0]);
	
	// return codes: 1 is HB, 2 is nextSong, 3 is play/pause, 4 is micro wakeup
	return rx[0];
}

int main(int argc, char **argv)
{
  int hb = 1;
  int metaType = 0;  
  int charCount = 0;     

  if (argc == 5) {
    hb = 0;
  }

      int ret = 0;
      int fd;

      fd = open(device, O_RDWR);
      if (fd < 0)
	pabort("can't open device");

      /*
       * spi mode
       */
      ret = ioctl(fd, SPI_IOC_WR_MODE, &mode);
      if (ret == -1)
	pabort("can't set spi mode");

      ret = ioctl(fd, SPI_IOC_RD_MODE, &mode);
      if (ret == -1)
	pabort("can't get spi mode");

      /*
       * bits per word
       */
      ret = ioctl(fd, SPI_IOC_WR_BITS_PER_WORD, &bits);
      if (ret == -1)
	pabort("can't set bits per word");

      ret = ioctl(fd, SPI_IOC_RD_BITS_PER_WORD, &bits);
      if (ret == -1)
	pabort("can't get bits per word");

      /*
       * max speed hz
       */
      ret = ioctl(fd, SPI_IOC_WR_MAX_SPEED_HZ, &speed);
      if (ret == -1)
	pabort("can't set max speed hz");

      ret = ioctl(fd, SPI_IOC_RD_MAX_SPEED_HZ, &speed);
      if (ret == -1)
	pabort("can't get max speed hz");

      printf("spi mode: %d\n", mode);
      printf("bits per word: %d\n", bits);
      printf("max speed: %d Hz (%d KHz)\n", speed, speed/1000);

      uint8_t hbData[1];
      uint8_t mData[1];
      hbData[0] = 0xAA;
      mData[0] = 0xBB;
      int temp = 0;
      int count = 0;
      int nextSong = 0;
      int retTime = 0;
      struct timespec t;
      t.tv_sec = 0;      
      t.tv_nsec = 500000000; // .05 or 1/20 sec
      if (hb) {
	nextSong = transferCmd(fd, hbData);		
      }
      else {
       	temp = transferCmd(fd, mData);
	nanosleep(&t, NULL);

	//Send song title
	temp = transferData(fd, argv[1]);
        printf("\nfinished song!\n");

	//Send artist
	temp = transferData(fd, argv[2]);
        printf("\nfinished artist!\n");

	//Send album
	temp = transferData(fd, argv[3]);
        printf("\nfinished album!\n");

	//Send year
	temp = transferData(fd, argv[4]);
        printf("\nfinished year!\n");
	nextSong = 0;
      }
      /*       	while (1) { 
		count++;
		temp = transfer(fd, txData, 1);
		printf("%d: temp is: %d\n",count, temp);
		if (temp) {
		printf("found a special command\n");
		break;
		}
		else {
		printf("NOTHING\n");
		}
		} */
      close(fd);
      return nextSong;
}
Beispiel #11
0
//if both CL and GL are enabled, then the buffer is shared and the implementation
//will decide, which api will be used for the write;
void BufferInterface::copyFromHostToGPU()throw(BufferException)
{
	assert( "CPU buffer must exist for copy from host to GPU " && mCPU_Handle);

	transferData(true);
}