Пример #1
0
void TcpServerStream::Write(const std::string& data)
{
	std::vector<uint8_t> dataBuf(data.size());
	memcpy(dataBuf.data(), data.data(), dataBuf.size());

	Write(dataBuf);
}
Пример #2
0
bool dwgR::testReader(){
    bool isOk = false;

    std::ifstream filestr;
    filestr.open (fileName.c_str(), std::ios_base::in | std::ios::binary);
    if (!filestr.is_open() || !filestr.good() ){
        error = DRW::BAD_OPEN;
        return isOk;
    }

    dwgBuffer fileBuf(&filestr);
    duint8 strdata[fileBuf.size()];
    fileBuf.getBytes(strdata, fileBuf.size());
    dwgBuffer dataBuf(strdata, fileBuf.size());
    fileBuf.setPosition(0);
    DRW_DBG("\ndwgR::testReader filebuf size: ");DRW_DBG(fileBuf.size());
    DRW_DBG("\ndwgR::testReader dataBuf size: ");DRW_DBG(dataBuf.size());
    DRW_DBG("\n filebuf pos: ");DRW_DBG(fileBuf.getPosition());
    DRW_DBG("\n dataBuf pos: ");DRW_DBG(dataBuf.getPosition());
    DRW_DBG("\n filebuf bitpos: ");DRW_DBG(fileBuf.getBitPos());
    DRW_DBG("\n dataBuf bitpos: ");DRW_DBG(dataBuf.getBitPos());
    DRW_DBG("\n filebuf first byte : ");DRW_DBGH(fileBuf.getRawChar8());
    DRW_DBG("\n dataBuf  first byte : ");DRW_DBGH(dataBuf.getRawChar8());
    fileBuf.setBitPos(4);
    dataBuf.setBitPos(4);
    DRW_DBG("\n filebuf first byte : ");DRW_DBGH(fileBuf.getRawChar8());
    DRW_DBG("\n dataBuf  first byte : ");DRW_DBGH(dataBuf.getRawChar8());
    DRW_DBG("\n filebuf pos: ");DRW_DBG(fileBuf.getPosition());
    DRW_DBG("\n dataBuf pos: ");DRW_DBG(dataBuf.getPosition());
    DRW_DBG("\n filebuf bitpos: ");DRW_DBG(fileBuf.getBitPos());
    DRW_DBG("\n dataBuf bitpos: ");DRW_DBG(dataBuf.getBitPos());
    fileBuf.setBitPos(6);
    dataBuf.setBitPos(6);
    DRW_DBG("\n filebuf pos: ");DRW_DBG(fileBuf.getPosition());
    DRW_DBG("\n dataBuf pos: ");DRW_DBG(dataBuf.getPosition());
    DRW_DBG("\n filebuf bitpos: ");DRW_DBG(fileBuf.getBitPos());
    DRW_DBG("\n dataBuf bitpos: ");DRW_DBG(dataBuf.getBitPos());
    DRW_DBG("\n filebuf first byte : ");DRW_DBGH(fileBuf.getRawChar8());
    DRW_DBG("\n dataBuf  first byte : ");DRW_DBGH(dataBuf.getRawChar8());
    fileBuf.setBitPos(0);
    dataBuf.setBitPos(0);
    DRW_DBG("\n filebuf first byte : ");DRW_DBGH(fileBuf.getRawChar8());
    DRW_DBG("\n dataBuf  first byte : ");DRW_DBGH(dataBuf.getRawChar8());
    DRW_DBG("\n filebuf pos: ");DRW_DBG(fileBuf.getPosition());
    DRW_DBG("\n dataBuf pos: ");DRW_DBG(dataBuf.getPosition());
    DRW_DBG("\n filebuf bitpos: ");DRW_DBG(fileBuf.getBitPos());
    DRW_DBG("\n dataBuf bitpos: ");DRW_DBG(dataBuf.getBitPos());


    filestr.close();
    DRW_DBG("\n\n");
    return isOk;
}
//-----------------------------------------------------------------------------
// CSensorChannelDoubleTap::HandleDataReceivedL
//-----------------------------------------------------------------------------
//
void CSensorChannelDoubleTap::HandleDataReceivedL( CSensrvChannel& aChannel,
    TInt aCount,
    TInt /*aDataLost*/ )
    {
    FUNC_LOG;
    INFO_1( "Received double tapping data. Count: %d", aCount );

    // Ensure that we actually have data
    if( aCount )
        {
        TSensrvTappingData data;
        TPckg<TSensrvTappingData> dataBuf( data );
        if( aChannel.GetData( dataBuf ) == KErrNone )
            {
            // Define context
            iContext->SetSourceL( KSensorSource );
            iContext->SetTypeL( KSensorSourceEventDoubleTap );
            if( data.iDirection == (
                KSensrvAccelerometerDirectionXplus |
                KSensrvAccelerometerDirectionXminus ) )
                {
                // Tapping from X axel
                iContext->SetValueL( TPtrC(
                    KSensorSourceEventDoubleTapValues[EDoubleTapX] ) );
                }
            else if( data.iDirection == (
                KSensrvAccelerometerDirectionYplus |
                KSensrvAccelerometerDirectionYminus ) )
                {
                // Tapping from Y axel
                iContext->SetValueL( TPtrC(
                    KSensorSourceEventDoubleTapValues[EDoubleTapY] ) );
                }
            else
                {
                // Tapping from Z axel
                iContext->SetValueL( TPtrC(
                    KSensorSourceEventDoubleTapValues[EDoubleTapZ] ) );
                }

            INFO_1( "Double tap data from sensor. Direction: %x",
                data.iDirection );

            // Publish context - use change detection
            RThread thread;
            iCF.PublishContext( *iContext, thread );
            thread.Close();
            }
        }
    }
void SendEndStatus()
{
	for ( int i=0; i < 3; i++ )
	{
		char data[4096];
		bf_write dataBuf( data, sizeof( data ) );
		dataBuf.WriteByte( VMPI_PROTOCOL_VERSION );
		dataBuf.WriteByte( VMPI_NOTIFY_END_STATUS );
		dataBuf.WriteBytes( g_CurJobID, sizeof( g_CurJobID ) );
		g_pSocket->SendTo( &g_CurRespondAddr, data, dataBuf.GetNumBytesWritten() );
		
		Sleep( 50 );
	}
}
Пример #5
0
QString ExportManager::pixmapDataUri() const
{
    QImage image = mSavePixmap.toImage();
    QByteArray imageData;

    // write the image into the QByteArray using a QBuffer

    {
        QBuffer dataBuf(&imageData);
        dataBuf.open(QBuffer::WriteOnly);
        image.save(&dataBuf, "PNG");
    }

    // compose the data uri and return it

    QString uri = QStringLiteral("data:image/png;base64,") + QString::fromLatin1(imageData.toBase64());
    return uri;
}
    HRESULT CFShellUtil::GetFileVersionInfo(LPCTSTR pszFilePath, VS_FIXEDFILEINFO *pFileInfo, DWORD dwFlags)
    {
        //定义可以获得版本信息的路径
        static LPCTSTR PATH_VER_FIXEDFILEINFO = TEXT("\\");

        HRESULT hr = E_FAIL;
        BOOL bRet = FALSE;

        CHECK_POINTER_ISSTRING_PTR_RETURN_VALUE_IF_FAIL(pszFilePath,  HRESULT_FROM_WIN32(ERROR_INVALID_PARAMETER));
        CHECK_POINTER_WRITABLE_DATA_RETURN_VALUE_IF_FAIL(pFileInfo, sizeof(VS_FIXEDFILEINFO), HRESULT_FROM_WIN32(ERROR_INVALID_PARAMETER));

        DWORD dwValue = 0 ;
        DWORD dwSize = ::GetFileVersionInfoSizeEx(dwFlags, pszFilePath, &dwValue) ;
        API_VERIFY(0 != dwSize);

        if (dwSize != 0)
        {
            ZeroMemory(pFileInfo, sizeof(*pFileInfo)) ;
            CFMemAllocator<BYTE> dataBuf(dwSize);
            API_VERIFY(::GetFileVersionInfoEx(dwFlags, pszFilePath, 0, dwSize, dataBuf.GetMemory()));
            if (bRet)
            {
                BYTE *pbyBlock = NULL ;
                UINT cbBlock = 0 ;
                API_VERIFY(VerQueryValue(dataBuf.GetMemory(), PATH_VER_FIXEDFILEINFO, reinterpret_cast<void **>(&pbyBlock), &cbBlock));
                FTLASSERT(sizeof(*pFileInfo) == cbBlock);
                if (sizeof(*pFileInfo) == cbBlock)
                {
                    CopyMemory(pFileInfo, pbyBlock, cbBlock);
                    hr = S_OK;
                }
            }
        }
        if (FAILED(hr))
        {
            hr = HRESULT_FROM_WIN32(GetLastError());
        }
        
        return hr;
    }
Пример #7
0
void KHTMLPluginKTTSD::slotReadOut()
{
    // The parent is assumed to be a KHTMLPart
    if(!parent()->inherits("KHTMLPart"))
        QMessageBox::warning(0, i18n("Cannot Read source"), i18n("You cannot read anything except web pages with\n"
                                                                 "this plugin, sorry."));
    else
    {
        // If KTTSD not running, start it.
        DCOPClient *client = kapp->dcopClient();
        if(!client->isApplicationRegistered("kttsd"))
        {
            QString error;
            if(kapp->startServiceByDesktopName("kttsd", QStringList(), &error))
                QMessageBox::warning(0, i18n("Starting KTTSD Failed"), error);
        }

        // Find out if KTTSD supports xhtml (rich speak).
        QByteArray data;
        QBuffer dataBuf(data);
        QDataStream arg;
        dataBuf.open(IO_WriteOnly);
        arg.setDevice(&dataBuf);
        arg << "" << KSpeech::mtHtml;
        QCString replyType;
        QByteArray replyData;
        bool supportsXhtml = false;
        if(!client->call("kttsd", "KSpeech", "supportsMarkup(QString,uint)", data, replyType, replyData, true))
            QMessageBox::warning(0, i18n("DCOP Call Failed"), i18n("The DCOP call supportsMarkup failed."));
        else
        {
            QDataStream reply(replyData, IO_ReadOnly);
            reply >> supportsXhtml;
        }

        KHTMLPart *part = (KHTMLPart *)parent();

        QString query;
        if(supportsXhtml)
        {
            kdDebug() << "KTTS claims to support rich speak (XHTML to SSML)." << endl;
            if(part->hasSelection())
                query = part->selectedTextAsHTML();
            else
            {
                // TODO: Fooling around with the selection probably has unwanted
                // side effects, but until a method is supplied to get valid xhtml
                // from entire document..
                // query = part->document().toString().string();
                part->selectAll();
                query = part->selectedTextAsHTML();
                // Restore no selection.
                part->setSelection(part->document().createRange());
            }
        }
        else
        {
            if(part->hasSelection())
                query = part->selectedText();
            else
                query = part->htmlDocument().body().innerText().string();
        }
        // kdDebug() << "KHTMLPluginKTTSD::slotReadOut: query = " << query << endl;

        dataBuf.at(0); // reset data
        arg << query << "";
        if(!client->call("kttsd", "KSpeech", "setText(QString,QString)", data, replyType, replyData, true))
            QMessageBox::warning(0, i18n("DCOP Call Failed"), i18n("The DCOP call setText failed."));
        dataBuf.at(0);
        arg << 0;
        if(!client->call("kttsd", "KSpeech", "startText(uint)", data, replyType, replyData, true))
            QMessageBox::warning(0, i18n("DCOP Call Failed"), i18n("The DCOP call startText failed."));
    }
}
Пример #8
0
/* Create an uncompressed version of the file on the local file system.
 * Note this will save zero-length files.
 */
int TskL01Extract::saveFile(const uint64_t fileId, const ArchivedFile &archivedFile)
{
    try
    {
        // If a file with this id already exists we raise an error
        std::auto_ptr<TskFile> pFile(TskServices::Instance().getFileManager().getFile(fileId));
        if (pFile.get() != NULL && pFile->exists())
        {
            std::stringstream msg;
            msg << "File id " << fileId << " already exists.";
            throw TskFileException(msg.str());
        }

        // Create a blank file
        Poco::Path destPath(TskUtilities::toUTF8(TskServices::Instance().getFileManager().getPath(fileId)));
        Poco::File destFile(destPath);
        destFile.createFile();

        // Get data from archive
        if (archivedFile.size > 0)
        {
            Poco::FileOutputStream fos(destFile.path(), std::ios::binary);

            uint64_t chunkSize = ExtractChunkSize;
            if (archivedFile.size < ExtractChunkSize)
            {
                chunkSize = archivedFile.size;
            }

            Poco::SharedPtr<char, Poco::ReferenceCounter, ArrayReleasePolicy<char> > dataBuf(new char[chunkSize]);

            uint64_t accum = 0;
            ewf::libewf_error_t *ewfError = NULL;

            // Read and save data in chunks so that we only put <= ExtractChunkSize bytes on the heap at a time
            while (accum < archivedFile.size)
            {
                ssize_t bytesRead = ewf::libewf_file_entry_read_buffer(archivedFile.entry, dataBuf, chunkSize, &ewfError);
                if (bytesRead == -1)
                {
                    std::stringstream logMessage;
                    char errorString[512];
                    errorString[0] = '\0';
                    ewf::libewf_error_backtrace_sprint(ewfError, errorString, 512);
                    logMessage << "TskL01Extract::saveFile - Error : " << errorString << std::endl;
                    LOGERROR(logMessage.str());
                    return -1;
                }
               
                fos.write(dataBuf, bytesRead);
                accum += bytesRead;
            }
            fos.close();
        }
        return 0;
    }
    catch (Poco::Exception& ex)
    {
        std::wstringstream msg;
        msg << L"TskL01Extract::saveFile - Error saving file from stream : " << ex.displayText().c_str();
        LOGERROR(msg.str());
        return -2;
    }
}
Пример #9
0
bool MD32spr::LoadAnimation(char *animFile)
{
  size_t lineLen = 0;
  int tmp = -1, i = 0;
  int headActions = 1, upperActions = 0, lowerActions = 0;
  char *line;
  size_t fileSz;
  vfs->GetFileSize(animFile, fileSz);
  csRef < iDataBuffer > buf(vfs->ReadFile(animFile));
  DataBuffer dataBuf(**buf, fileSz);
  lineLen = dataBuf.GetMaxLineLength();
  line = (char *) cs_malloc(sizeof(char) * lineLen);
  char junk[4], name[15];
  while (!dataBuf.eof()) {
    dataBuf.GetLine(line);
    junk[0] = '\0';
    if (sscanf
	(line, "%d%d%d%d%s%s", &tmp, &tmp, &tmp, &tmp, junk, name) == 6) {
      if(stristr(name, "BOTH") || stristr(name, "TORSO")) {
	sscanf(line, "%d%d%d%d%s%s", &upperModel->animInfo[upperActions].startFrame,
	       &upperModel->animInfo[upperActions].numFrames, &upperModel->animInfo[upperActions].loopFrames,
	       &upperModel->animInfo[upperActions].fps, junk, upperModel->animInfo[upperActions].actionName);
	upperActions++;
      }
      if(stristr(name, "BOTH") || stristr(name, "LEGS")) {
	sscanf(line, "%d%d%d%d%s%s", &lowerModel->animInfo[lowerActions].startFrame,
	       &lowerModel->animInfo[lowerActions].numFrames, &lowerModel->animInfo[lowerActions].loopFrames,
	       &lowerModel->animInfo[lowerActions].fps, junk, lowerModel->animInfo[lowerActions].actionName);
	lowerActions++;
      }
    }
  }
  headModel->numActions = headActions;
  upperModel->numActions = upperActions;
  lowerModel->numActions = lowerActions;
  /*
   * Post Processing:
   * In some of the animation config files, the numbering leg animations of start frames continue 
   * after torso animations. To correct this we sum the number of torso animations and negate them
   * from leg animations thus resetting the start frames of leg animations.
   */
  int upperActionStart = 0, lowerActionStart = 0;
  for(i = 0; i < NUM_ACTIONS; i++)
    if(strcmp(upperModel->animInfo[i].actionName, "TORSO_GESTURE") == 0)
      break;
  upperActionStart = i;

  for(i = 0; i < NUM_ACTIONS; i++)
    if(strcmp(lowerModel->animInfo[i].actionName, "LEGS_WALKCR") == 0)
      break;
  lowerActionStart = i;

  if (upperModel->animInfo[upperActionStart].startFrame !=
      lowerModel->animInfo[lowerActionStart].startFrame) {
    int numTorsoFrames = 0;
    for (i = 0; i < upperActions; i++)
      if (stristr(upperModel->animInfo[i].actionName, "TORSO"))
	numTorsoFrames += upperModel->animInfo[i].numFrames;

    for (i = 0; i < lowerActions; i++)
      if (stristr(lowerModel->animInfo[i].actionName, "LEGS")) {
	lowerModel->animInfo[i].startFrame -= numTorsoFrames;
      }
  }
  return true;
}
Пример #10
0
Readable*
ModuleMap::getMapLoadingReadable(uint32 mapID,
                                 uint32 loadMapRequestType,
                                 const char* handshake,
                                 byte zoomlevel,
                                 MapSafeVector* loadedMaps )
{
   FileUtils::FilePtr file;

   MC2String cacheFileName = getCacheFilename(mapID,
                                           loadMapRequestType,
                                           zoomlevel);
   
   mc2dbg << "[ModuleMap]: Filename would be \""
          << cacheFileName << '"' << endl ;

   bool useCache = cacheFileName.length();
   
   if ( useCache ) {
      // If the cache filename exists we should try the cache.
      file.reset( fopen( cacheFileName.c_str(), "r" ) );
   }

   TCPSocket* tcpsock = NULL;
   uint32 mapVersion           = MAX_UINT32;
   uint32 generatorVersion     = MAX_UINT32;
   
   if ( file.get() != NULL ) {
      mc2dbg << "[ModuleMap]: Cached map found" << endl;

      // Check versions of map in file.
      ScopedArray<byte> headerBuf( new byte[CACHED_MAP_HEADER_SIZE] );
      
      uint32 fileMapVersion       = MAX_UINT32;
      uint32 fileGeneratorVersion = MAX_UINT32;
      uint32 fileMapID            = MAX_UINT32;
      
      if ( fread( headerBuf.get(), CACHED_MAP_HEADER_SIZE, 1, file.get() ) == 1 ) {
         DataBuffer dataBuf(headerBuf.get(), CACHED_MAP_HEADER_SIZE);
         uint32 first         = dataBuf.readNextLong();
         first = first;
         fileMapID            = dataBuf.readNextLong();
         fileMapVersion       = dataBuf.readNextLong();
         fileGeneratorVersion = dataBuf.readNextLong();
         if ( fileMapID == mapID ) {
            mapVersion = fileMapVersion;
            generatorVersion = fileGeneratorVersion;
         } else {
            mc2dbg << "[ModuleMap]: Wrong mapid in file - was "
                   << fileMapID << " should be " << mapID
                   << endl;
         }
      } 
      headerBuf.reset( NULL );

      mc2dbg << "[ModuleMap]: Version from file 0x"
             << hex << fileMapVersion << ":" << dec << fileGeneratorVersion
             << endl;
      
      tcpsock = getMapLoadingSocket(mapID,
                                    loadMapRequestType,
                                    handshake,
                                    zoomlevel,
                                    loadedMaps,
                                    &mapVersion,
                                    &generatorVersion);

      mc2dbg << "[ModuleMap]: Version from getMapLoadingSocket "
             << hex << "0x" << mapVersion << dec << ":" << generatorVersion
             << endl;
      
      if ( (tcpsock == NULL ) &&
           ( mapVersion == fileMapVersion ) &&
           ( generatorVersion == fileGeneratorVersion ) ) {
         mc2dbg << "[ModuleMap]: Cached file OK" << endl;
         return new FileReadable(file.release());
      } else {
         if ( tcpsock != NULL ) {
            mc2dbg << "[ModuleMap]: Versions differ (file/MM)." << endl;
         } else {
            mc2dbg << "[ModuleMap]: Wrong version or no socket." << endl;
         }
      }
   } else {
      mc2dbg << "[ModuleMap]: No cache file" << endl;
      // Just get the socket and load.
      tcpsock = getMapLoadingSocket(mapID,
                                    loadMapRequestType,
                                    handshake,
                                    zoomlevel,
                                    loadedMaps,
                                    &mapVersion,
                                    &generatorVersion);
   }
   
   if ( tcpsock != NULL && useCache ) {
      mc2dbg << "[ModuleMap]: Will write to cache" << endl;
      // We do not have the map cached or it may have been the wrong
      // version.
      int headerSize = 0;
      ScopedArray<byte> header( makeHeader( headerSize,
                                            mapID, mapVersion, 
                                            generatorVersion) );
               
      TCPSocketReadable* tsockRead = new TCPSocketReadable( tcpsock );
      
      return new AutoWritingReadable( tsockRead,
                                      cacheFileName.c_str(),
                                      header.get(),
                                      headerSize );
   } else if ( tcpsock ) {
      mc2dbg << "[ModuleMap]: Will not write to cache" << endl;
      return new TCPSocketReadable(tcpsock);
   } else {
      mc2dbg << "[ModuleMap]: No socket" << endl;
      // Loading failed
      return NULL;
   }
}