void ResourceLoadNode::evaluateResource() { void const *urlMemberData = getConstData( "url", 0 ); bool sameURL = m_fabricResourceStreamData.isURLEqualTo( urlMemberData ); bool isFirstEvalAfterLoad = m_firstEvalAfterLoad; m_firstEvalAfterLoad = false; if( sameURL && m_inProgress ) return; if( sameURL && isFirstEvalAfterLoad ) return;//[JeromeCG 20111221] The data was already set asynchronously, during setResourceData, so the work is already done. if( sameURL && (m_keepMemoryCache || m_asFile) ) { //Set from m_fabricResourceStreamData //[JeromeCG 20110727] Note: if m_asFile, the handle was created as "readOnly", so in theory the data is still valid. setResourceData( NULL, false ); return; } // [JeromeCG 20110727] Note: we use a generation because if there was a previous uncompleted request we might receive more callbacks; // we create a new one in parallel instead of waiting its completion. m_streamGeneration++; m_fabricResourceStreamData.setURL( urlMemberData ); m_fabricResourceStreamData.setMIMEType( "" ); //[JeromeCG 20120119] setDataExternalLocation: Should we care about deleting the cache file? The browser created it... can it reuse the same temp file? Maybe the user still uses it? m_fabricResourceStreamData.setDataExternalLocation( "" ); m_fabricResourceStreamData.resizeData( 0 ); m_keepMemoryCache = false; setResourceData( NULL, false ); m_keepMemoryCache = getContext()->getRTManager()->getBooleanDesc()->getValue( getConstData( "keepMemoryCache", 0 ) ); m_asFile = getContext()->getRTManager()->getBooleanDesc()->getValue( getConstData( "storeDataAsFile", 0 ) ); std::string url = m_fabricResourceStreamData.getURL(); if( !url.empty() ) { m_inProgress = true; getContext()->getIOManager()->getResourceManager()->get( url.c_str(), this, m_asFile, (void*)m_streamGeneration ); } else releaseFile(); }
void ResourceLoadNode::onFailure( char const *errorDesc, void *userData ) { if( (size_t)userData != m_streamGeneration ) return; m_fabricResourceStreamData.resizeData( 0 ); m_fabricResourceStreamData.setDataExternalLocation( "" ); m_inProgress = false; setResourceData( errorDesc, true ); }
void fastPoll( void ) { MESSAGE_DATA msgData; BYTE buffer[ SCC_RANDOM_SIZE ]; sccGetRandomNumber( buffer, RANDOM_RANDOM ); setResourceData( &msgData, buffer, SCC_RANDOM_SIZE ); krnlSendMessage( SYSTEM_OBJECT_HANDLE, IMESSAGE_SETATTRIBUTE_S, &msgData, CRYPT_IATTRIBUTE_ENTROPY ); zeroise( buffer, SCC_RANDOM_SIZE ); }
void slowPoll( void ) { MESSAGE_DATA msgData; BYTE buffer[ SCC_RANDOM_SIZE * SCC_NO_CALLS ]; int quality = 100, i; for( i = 0; i < SCC_NO_CALLS; i++ ) sccGetRandomNumber( buffer + ( i * SCC_RANDOM_SIZE ), RANDOM_RANDOM ); /* Add the data to the randomness pool */ setResourceData( &msgData, buffer, SCC_RANDOM_SIZE * SCC_NO_CALLS ); krnlSendMessage( SYSTEM_OBJECT_HANDLE, IMESSAGE_SETATTRIBUTE_S, &msgData, CRYPT_IATTRIBUTE_ENTROPY ); zeroise( buffer, SCC_RANDOM_SIZE * SCC_NO_CALLS ); krnlSendMessage( SYSTEM_OBJECT_HANDLE, IMESSAGE_SETATTRIBUTE, &quality, CRYPT_IATTRIBUTE_ENTROPY_QUALITY ); }
void ResourceLoadNode::onProgress( char const *mimeType, size_t done, size_t total, void *userData ) { if( (size_t)userData != m_streamGeneration ) return; size_t prevSize = m_fabricResourceStreamData.getDataSize(); if ( total < prevSize ) m_fabricResourceStreamData.resizeData( total ); if( done < total ) { std::vector<std::string> src; src.push_back( "DG" ); src.push_back( getName() ); Util::SimpleString json; { JSON::Encoder jsonEncoder( &json ); JSON::ObjectEncoder jsonObjectEncoder = jsonEncoder.makeObject(); { JSON::Encoder memberEncoder = jsonObjectEncoder.makeMember( "received", 8 ); memberEncoder.makeInteger( done ); } { JSON::Encoder memberEncoder = jsonObjectEncoder.makeMember( "total", 5 ); memberEncoder.makeInteger( total ); } } getContext()->jsonNotify( src, "resourceLoadProgress", 20, &json ); } else { m_fabricResourceStreamData.setMIMEType( mimeType ); m_inProgress = false;//[JeromeCG 20111221] Important: set m_inProgress to false since setResourceData's notifications can trigger an evaluation setResourceData( NULL, true ); } }