void AsioSessionState::doRegularFraming(size_t bytesTransferred) { RCF_ASSERT_LTEQ(bytesTransferred , mReadBufferRemaining); mReadBufferRemaining -= bytesTransferred; if (mReadBufferRemaining > 0) { beginRead(); } else if (mReadBufferRemaining == 0 && mIssueZeroByteRead) { if (!mAppReadBufferPtr || !mAppReadBufferPtr.unique()) { mAppReadBufferPtr = getObjectPool().getReallocBufferPtr(); } mAppReadBufferPtr->resize(4); mReadBufferRemaining = 4; mIssueZeroByteRead = false; beginRead(); } else { RCF_ASSERT_EQ(mReadBufferRemaining , 0); if (mState == ReadingDataCount) { ReallocBuffer & readBuffer = *mAppReadBufferPtr; RCF_ASSERT_EQ(readBuffer.size() , 4); unsigned int packetLength = 0; memcpy(&packetLength, &readBuffer[0], 4); networkToMachineOrder(&packetLength, 4, 1); if ( mTransport.getMaxMessageLength() && packetLength > mTransport.getMaxMessageLength()) { sendServerError(RcfError_ServerMessageLength); } else { readBuffer.resize(packetLength); mReadBufferRemaining = packetLength; mState = ReadingData; beginRead(); } } else if (mState == ReadingData) { mState = Ready; mTransport.getSessionManager().onReadCompleted( getSessionPtr()); } } }
/* virtual */ void XMLerLoadFileThread::run () { QFile xml( fileName() ); if ( !xml.exists() ) { emit error ( tr("File %1 does not exists.").arg( fileName() ) ); return; } /* QMap<QString, QString> info = getInformationFromFile(); */ QXmlSimpleReader reader; XMLerInputSource *source = new XMLerInputSource ( &xml ); /* connect source to slots in model */ connect ( source, SIGNAL(beginRead(qint64)), this, SLOT(on_beginProgress(qint64)) ); connect ( source, SIGNAL(readProgress(qint64)), this, SLOT(on_progress(qint64)) ); connect ( source, SIGNAL(endRead()), this, SLOT(on_endProgress()) ); reader.setContentHandler ( handler ); reader.setErrorHandler ( handler ); bool parseResult = reader.parse ( source, true ); /* FIXME: this is partial read */ if ( parseResult ) { bool partResult = parseResult; while ( partResult ) partResult = reader.parseContinue(); } if ( !parseResult ) { checkExceptionInHandler(); on_endProgress(); return; } /* set addition data (information) in document */ if ( handler->document() ) handler->document()->setFileName( fileName() ); /* CLEANIT if ( !info.isEmpty() ) { if ( info.contains ( "encoding" ) ) handler->document()->setCodec ( info.value ( "encoding" ) ); if ( info.contains ( "version" ) ) handler->document()->setVersion ( info.value ( "version" ) ); }*/ emit done ( handler->document() ); checkExceptionInHandler (); /* clean */ disconnect ( source, SIGNAL(beginRead(qint64)) ); disconnect ( source, SIGNAL(readProgress(qint64)) ); disconnect ( source, SIGNAL(endRead()) ); delete source; }
void AsioSessionState::doCustomFraming(size_t bytesTransferred) { RCF_ASSERT_LTEQ(bytesTransferred , mReadBufferRemaining); mReadBufferRemaining -= bytesTransferred; if (mReadBufferRemaining > 0) { beginRead(); } else if (mReadBufferRemaining == 0 && mIssueZeroByteRead) { if (!mAppReadBufferPtr || !mAppReadBufferPtr.unique()) { mAppReadBufferPtr = getObjectPool().getReallocBufferPtr(); } mAppReadBufferPtr->resize(4); mReadBufferRemaining = 4; mIssueZeroByteRead = false; beginRead(); } else { RCF_ASSERT_EQ(mReadBufferRemaining , 0); if (mState == ReadingDataCount) { ReallocBuffer & readBuffer = *mAppReadBufferPtr; RCF_ASSERT_EQ(readBuffer.size() , 4); std::size_t messageLength = mTransportFilters[0]->getFrameSize(); if ( mTransport.getMaxMessageLength() && messageLength > mTransport.getMaxMessageLength()) { sendServerError(RcfError_ServerMessageLength); } else { RCF_ASSERT( messageLength > 4 ); readBuffer.resize(messageLength); mReadBufferRemaining = messageLength - 4; mState = ReadingData; beginRead(); } } else if (mState == ReadingData) { mState = Ready; mTransport.getSessionManager().onReadCompleted( getSessionPtr()); } } }
int Application::readParticles(int fd) //returns <0 on Error { int i; //,nskip; if (beginRead(fd)) { return (-1); } rb.init(blockLen, header.np, fd); for (i = 0; i < (header.np / pfactor); i++) { rb.skip(pfactor - 1); //skip some particles if (rb.read() < 0) return (-1); rb.readFloat(px[i]); rb.readFloat(py[i]); rb.readFloat(pz[i]); rb.skip(2, 2); // skip to floats and two ints rb.readFloat(pu[i]); rb.readFloat(pv[i]); rb.readFloat(pw[i]); rb.readFloat(ptemp[i]); } if ((header.np - (header.np / pfactor) * pfactor)) rb.skip((header.np - (header.np / pfactor) * pfactor)); if (endRead(fd)) { return (-1); } return (0); }
void Device::beginRead() { auto device=shared_from_this(); auto on_read=[device]( const boost::system::error_code& error, size_t bytes_transferred ){ if(error){ std::cout << error.message() << std::endl; return; } // copy std::vector<unsigned char> tmp(device->m_buf, device->m_buf+bytes_transferred); // next device->beginRead(); // callback if(!tmp.empty()){ device->m_callback->onRead(device.get(), tmp); } }; m_stream->async_read_some( boost::asio::buffer(m_buf, sizeof(m_buf)), on_read ); }
Spectra *SpectraVFSCached::beginWrite( size_t _nSpectraIndex ) { if ( m_bReadOnly ) return NULL; return beginRead( _nSpectraIndex ); }
bool SdioDmaSdCard::readBlock(void *dest,uint32_t blockIndex) { _dmaFinished=_sdioFinished=false; // enable the relevant interrupts SdioInterruptFeature::enableInterrupts(SDIO_IT_DCRCFAIL | SDIO_IT_DTIMEOUT | SDIO_IT_DATAEND | SDIO_IT_RXOVERR | SDIO_IT_STBITERR); SdioDmaChannelInterruptFeature::enableInterrupts(SdioDmaChannelInterruptFeature::COMPLETE | SdioDmaChannelInterruptFeature::TRANSFER_ERROR); // issue the command if(!readBlockCommand(blockIndex,BLOCK_SIZE)) return false; // use DMA to transfer the data beginRead(dest,BLOCK_SIZE); // wait for completion or error if(!waitForTransfer()) return false; // wait for the peripheral to go quiet SdCardSdioFeature::waitForReceiveComplete(); return true; }
/* * GetNextThread - * NB - callers must continue to call this function until it returns FALSE */ BOOL GetNextThread( ThreadList *info, ThreadPlace *place, DWORD pid, BOOL first ) { DWORD curpid; PERF_COUNTER_DEFINITION *counter; BOOL error; error = FALSE; if( first ) { beginRead( FALSE ); initObj( ®Data, &threadObject, N_THREAD ); if( threadObject == NULL ) error = TRUE; if( !error ) { place->index = 0; place->obj = threadObject; place->pid = pid; place->inst = getFirstInstance( threadObject ); } } else { place->index ++; if( place->index < place->obj->NumInstances ) { place->inst = getNextInstance( place->inst ); } } if( !error ) { counter = findCounter( place->obj, N_PROCID ); if( counter == NULL ) error = TRUE; } if( !error ) { for( ; place->index < place->obj->NumInstances; place->index ++ ) { if( place->inst == NULL ) { error = TRUE; break; } curpid = getCounterDWORD( place->inst, counter ); if( curpid == place->pid ) break; place->inst = getNextInstance( place->inst ); } } if( !error && place->index >= place->obj->NumInstances ) error = TRUE; if( !error ) { counter = findCounter( place->obj, N_THREADID ); if( counter == NULL ) error = TRUE; } if( !error ) { info->tid = getCounterDWORD( place->inst, counter ); counter = findCounter( place->obj, N_BASE_PRIORITY ); if( counter == NULL ) error = TRUE; } if( !error ) { info->priority = getCounterDWORD( place->inst, counter ); } else { endRead( FALSE ); } return( !error ); }
Result read(void* buffer, size_t size, Flags flags, size_t* readSize) override { const void* src = nullptr; Result result = beginRead(&src, flags, readSize); if (result != Ok) return result; *readSize = std::min(*readSize, size); memcpy(buffer, src, *readSize); return endRead(*readSize); }
void AsioSessionState::onNetworkReadCompleted( AsioErrorCode error, size_t bytesTransferred) { RCF_LOG_4()(this)(bytesTransferred) << "AsioSessionState - read from socket completed."; ThreadTouchGuard threadTouchGuard; mLastError = error; mBytesReceivedCounter += bytesTransferred; #ifdef BOOST_WINDOWS if (error.value() == ERROR_OPERATION_ABORTED) { error = AsioErrorCode(); } #endif if (!error && !mTransport.mStopFlag) { if (bytesTransferred == 0 && mIssueZeroByteRead) { // TCP framing. if (!mAppReadBufferPtr || !mAppReadBufferPtr.unique()) { mAppReadBufferPtr = getObjectPool().getReallocBufferPtr(); } mAppReadBufferPtr->resize(4); mReadBufferRemaining = 4; mIssueZeroByteRead = false; beginRead(); } else if (mReflecting) { AsioErrorCode ec; onReflectedReadWriteCompleted(ec, bytesTransferred); } else { CurrentRcfSessionSentry guard(*mSessionPtr); mNetworkReadByteBuffer = ByteBuffer( mNetworkReadByteBuffer, 0, bytesTransferred); mTransportFilters.empty() ? onAppReadWriteCompleted(bytesTransferred) : mTransportFilters.back()->onReadCompleted(mNetworkReadByteBuffer); } } }
/* * GetThreadInfo */ BOOL GetThreadInfo( DWORD pid, DWORD tid, ThreadStats *info ) { PERF_COUNTER_DEFINITION *pid_counter; PERF_COUNTER_DEFINITION *tid_counter; PERF_COUNTER_DEFINITION *counter; PERF_INSTANCE_DEFINITION *inst; DWORD curid; DWORD i; BOOL error; error = FALSE; beginRead( FALSE ); initObj( ®Data, &threadObject, N_THREAD ); if( threadObject == NULL ) { error = TRUE; } if( !error ) { pid_counter = findCounter( threadObject, N_PROCID ); tid_counter = findCounter( threadObject, N_THREADID ); if( pid_counter == NULL || tid_counter == NULL ) error = TRUE; } if( !error ) { inst = getFirstInstance( threadObject ); for( i=0; i < threadObject->NumInstances; i++ ) { if( inst == NULL ) { error = TRUE; break; } curid = getCounterDWORD( inst, tid_counter ); if( curid == tid ) { curid = getCounterDWORD( inst, pid_counter ); if( curid == pid ) break; } inst = getNextInstance( inst ); } } if( !error && i == threadObject->NumInstances ) { error = TRUE; } else { info->tid = tid; info->pid = pid; counter = findCounter( threadObject, N_BASE_PRIORITY ); info->base_pri = getCounterDWORD( inst, counter ); counter = findCounter( threadObject, N_CUR_PRIORITY ); info->cur_pri = getCounterDWORD( inst, counter ); counter = findCounter( threadObject, N_THREAD_STATE ); info->state = getCounterDWORD( inst, counter ); counter = findCounter( threadObject, N_WAIT_REASON ); info->wait_reason = getCounterDWORD( inst, counter ); } endRead( FALSE ); return( !error ); }
bool Device::open(boost::asio::io_service &io_service, std::shared_ptr<ICallback> callback) { auto handle = CreateFile(m_path.c_str(), GENERIC_READ|GENERIC_WRITE, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_FLAG_OVERLAPPED, NULL); if(handle == INVALID_HANDLE_VALUE) { return false; } m_handle=std::shared_ptr<void>(handle, &::CloseHandle); // get hid caps { HIDP_PREPARSED_DATA* preparsedData=0; if (!HidD_GetPreparsedData(handle, &preparsedData)){ return false; } std::shared_ptr<HIDP_PREPARSED_DATA> parsed( preparsedData, HidD_FreePreparsedData); HIDP_CAPS caps; if (HidP_GetCaps(preparsedData, &caps) != HIDP_STATUS_SUCCESS) { return false; } std::cout << "Usage: " << caps.Usage << std::endl; std::cout << "UsagePage: " << caps.UsagePage << std::endl; std::cout << "InputReportByteLength: " << caps.InputReportByteLength << std::endl; std::cout << "OutputReportByteLength: " << caps.OutputReportByteLength << std::endl; std::cout << "FeatureReportByteLength: " << caps.FeatureReportByteLength << std::endl; } // setup stream m_stream=std::make_shared<boost::asio::windows::stream_handle>(io_service, handle); m_callback=callback; beginRead(); m_callback->onConnect(this); return true; }
void AsioSessionState::postRead() { if (mLastError) { return; } mState = AsioSessionState::ReadingDataCount; mAppReadByteBuffer.clear(); mAppReadBufferPtr.reset(); mNetworkReadByteBuffer.clear(); mNetworkReadBufferPtr.reset(); mReadBufferRemaining = 0; mIssueZeroByteRead = true; beginRead(); }
/* * GetProcessInfo */ BOOL GetProcessInfo( DWORD pid, ProcStats *info ) { DWORD i; PERF_COUNTER_DEFINITION *counter; PERF_INSTANCE_DEFINITION *inst; DWORD curpid; BOOL error; beginRead( FALSE ); error = FALSE; initObj( ®Data, &processObject, N_PROCESS ); if( processObject == NULL ) error = TRUE; if( !error ) { counter = findCounter( processObject, N_PROCID ); if( counter == NULL ) error = TRUE; } if( !error ) { inst = getFirstInstance( processObject ); for( i=0; i < processObject->NumInstances; i++ ) { if( inst == NULL ) { error = TRUE; break; } curpid = getCounterDWORD( inst, counter ); if( curpid == pid ) break; inst = getNextInstance( inst ); } } if( !error && curpid == pid && info != NULL ) { info->pid = curpid; counter = findCounter( processObject, N_BASE_PRIORITY ); if( counter == NULL ) { error = TRUE; } else { info->priority = getCounterDWORD( inst, counter ); wsprintf( info->name, "%ls", (char *)inst + inst->NameOffset ); } } endRead( FALSE ); return( !error && curpid == pid ); }
/* * GetNextProcess * NB - callers must continue to call this function until it returns FALSE */ BOOL GetNextProcess( ProcList *info, ProcPlace *place, BOOL first ) { PERF_COUNTER_DEFINITION *counter; BOOL error; error = FALSE; if( first ) { beginRead( FALSE ); initObj( ®Data, &processObject, N_PROCESS ); if( processObject == NULL ) error = TRUE; if( !error ) { place->index = 0; place->obj = processObject; place->inst = getFirstInstance( processObject ); } } else { place->index ++; if( place->index >= processObject->NumInstances ) { endRead( FALSE ); return( FALSE ); } place->inst = getNextInstance( place->inst ); } if( place->inst == NULL ) error = TRUE; if( !error ) { counter = findCounter( place->obj, N_PROCID ); if( counter == NULL ) error = TRUE; } if( !error ) { info->pid = getCounterDWORD( place->inst, counter ); counter = findCounter( place->obj, N_BASE_PRIORITY ); if( counter == NULL ) error = TRUE; } if( !error ) { info->priority = getCounterDWORD( place->inst, counter ); wsprintf( info->name, "%ls", (char *)( place->inst ) + place->inst->NameOffset ); } else { endRead( FALSE ); } return( !error ); }
bool SdioDmaSdCard::readBlocks(void *dest,uint32_t blockIndex,uint32_t numBlocks) { uint8_t *ptr; for(ptr=static_cast<uint8_t *>(dest);numBlocks;numBlocks--,blockIndex++,ptr+=BLOCK_SIZE) if(!readBlock(ptr,blockIndex)) return false; return true; #if 0 _dmaFinished=_sdioFinished=false; // enable the relevant interrupts SdioInterruptFeature::enableInterrupts(SDIO_IT_DCRCFAIL | SDIO_IT_DTIMEOUT | SDIO_IT_DATAEND | SDIO_IT_RXOVERR | SDIO_IT_STBITERR); SdioDmaChannelInterruptFeature::enableInterrupts(SdioDmaChannelInterruptFeature::COMPLETE | SdioDmaChannelInterruptFeature::TRANSFER_ERROR); // issue the command if(!readBlocksCommand(blockIndex,BLOCK_SIZE,numBlocks)) return false; // use DMA to transfer the data beginRead(dest,numBlocks*BLOCK_SIZE); // wait for completion or error if(!waitForTransfer()) return false; // wait for the peripheral to go quiet SdCardSdioFeature::waitForReceiveComplete(); return true; #endif }
/* * GetMemInfo */ BOOL GetMemInfo( DWORD procid, MemInfo *info ) { PERF_COUNTER_DEFINITION *counter; PERF_INSTANCE_DEFINITION *inst; DWORD curpid; DWORD i; beginRead( TRUE ); initObj( &costlyData, &procAddrObject, N_PROCESS_ADDR_SPACE ); if( procAddrObject == NULL ) { info->modlist = NULL; info->modcnt = 0; goto GETMEMINFO_ERROR; } info->modlist = GetModuleList( procid, &info->modcnt ); if( info->modlist == NULL ) goto GETMEMINFO_ERROR; counter = findCounter( procAddrObject, N_PROCID ); if( counter == NULL ) goto GETMEMINFO_ERROR; inst = getFirstInstance( procAddrObject ); for( i=0; ; i++ ) { if( i >= procAddrObject->NumInstances || inst == NULL ) { goto GETMEMINFO_ERROR; } curpid = getCounterDWORD( inst, counter ); if( curpid == procid ) break; inst = getNextInstance( inst ); } counter = findCounter( procAddrObject, N_MAP_SPACE_NO_ACC ); if( counter == NULL ) goto GETMEMINFO_ERROR; info->mapped.noaccess = getCounterDWORD( inst, counter ); counter = findCounter( procAddrObject, N_MAP_SPACE_READ ); if( counter == NULL ) goto GETMEMINFO_ERROR; info->mapped.read = getCounterDWORD( inst, counter ); counter = findCounter( procAddrObject, N_MAP_SPACE_WRITE ); if( counter == NULL ) goto GETMEMINFO_ERROR; info->mapped.write = getCounterDWORD( inst, counter ); counter = findCounter( procAddrObject, N_MAP_SPACE_COPY ); if( counter == NULL ) goto GETMEMINFO_ERROR; info->mapped.copy = getCounterDWORD( inst, counter ); counter = findCounter( procAddrObject, N_MAP_SPACE_EXEC ); if( counter == NULL ) goto GETMEMINFO_ERROR; info->mapped.exec = getCounterDWORD( inst, counter ); counter = findCounter( procAddrObject, N_MAP_SPACE_EXECREAD ); if( counter == NULL ) goto GETMEMINFO_ERROR; info->mapped.execread = getCounterDWORD( inst, counter ); counter = findCounter( procAddrObject, N_MAP_SPACE_EXECWRITE ); if( counter == NULL ) goto GETMEMINFO_ERROR; info->mapped.execwrite = getCounterDWORD( inst, counter ); counter = findCounter( procAddrObject, N_MAP_SPACE_EXECCOPY ); if( counter == NULL ) goto GETMEMINFO_ERROR; info->mapped.execcopy = getCounterDWORD( inst, counter ); info->mapped.tot = info->mapped.noaccess + info->mapped.read + info->mapped.write + info->mapped.copy + info->mapped.exec + info->mapped.execread + info->mapped.execwrite + info->mapped.execcopy; counter = findCounter( procAddrObject, N_RES_SPACE_NO_ACC ); if( counter == NULL ) goto GETMEMINFO_ERROR; info->res.noaccess = getCounterDWORD( inst, counter ); counter = findCounter( procAddrObject, N_RES_SPACE_READ ); if( counter == NULL ) goto GETMEMINFO_ERROR; info->res.read = getCounterDWORD( inst, counter ); counter = findCounter( procAddrObject, N_RES_SPACE_WRITE ); if( counter == NULL ) goto GETMEMINFO_ERROR; info->res.write = getCounterDWORD( inst, counter ); counter = findCounter( procAddrObject, N_RES_SPACE_COPY ); if( counter == NULL ) goto GETMEMINFO_ERROR; info->res.copy = getCounterDWORD( inst, counter ); counter = findCounter( procAddrObject, N_RES_SPACE_EXEC ); if( counter == NULL ) goto GETMEMINFO_ERROR; info->res.exec = getCounterDWORD( inst, counter ); counter = findCounter( procAddrObject, N_RES_SPACE_EXECREAD ); if( counter == NULL ) goto GETMEMINFO_ERROR; info->res.execread = getCounterDWORD( inst, counter ); counter = findCounter( procAddrObject, N_RES_SPACE_EXECWRITE ); if( counter == NULL ) goto GETMEMINFO_ERROR; info->res.execwrite = getCounterDWORD( inst, counter ); counter = findCounter( procAddrObject, N_RES_SPACE_EXECCOPY ); if( counter == NULL ) goto GETMEMINFO_ERROR; info->res.execcopy = getCounterDWORD( inst, counter ); info->res.tot = info->res.noaccess + info->res.read + info->res.write + info->res.copy + info->res.exec + info->res.execread + info->res.execwrite + info->res.execcopy; counter = findCounter( procAddrObject, N_IMAGE_SPACE_NO_ACC ); if( counter == NULL ) goto GETMEMINFO_ERROR; info->image.noaccess = getCounterDWORD( inst, counter ); counter = findCounter( procAddrObject, N_IMAGE_SPACE_READ ); if( counter == NULL ) goto GETMEMINFO_ERROR; info->image.read = getCounterDWORD( inst, counter ); counter = findCounter( procAddrObject, N_IMAGE_SPACE_WRITE ); if( counter == NULL ) goto GETMEMINFO_ERROR; info->image.write = getCounterDWORD( inst, counter ); counter = findCounter( procAddrObject, N_IMAGE_SPACE_COPY ); if( counter == NULL ) goto GETMEMINFO_ERROR; info->image.copy = getCounterDWORD( inst, counter ); counter = findCounter( procAddrObject, N_IMAGE_SPACE_EXEC ); if( counter == NULL ) goto GETMEMINFO_ERROR; info->image.exec = getCounterDWORD( inst, counter ); counter = findCounter( procAddrObject, N_IMAGE_SPACE_EXECREAD ); if( counter == NULL ) goto GETMEMINFO_ERROR; info->image.execread = getCounterDWORD( inst, counter ); counter = findCounter( procAddrObject, N_IMAGE_SPACE_EXECWRITE ); if( counter == NULL ) goto GETMEMINFO_ERROR; info->image.execwrite = getCounterDWORD( inst, counter ); counter = findCounter( procAddrObject, N_IMAGE_SPACE_EXECCOPY ); if( counter == NULL ) goto GETMEMINFO_ERROR; info->image.execcopy = getCounterDWORD( inst, counter ); info->image.tot = info->image.noaccess + info->image.read + info->image.write + info->image.copy + info->image.exec + info->image.execread + info->image.execwrite + info->image.execcopy; endRead( TRUE ); return( TRUE ); GETMEMINFO_ERROR: FreeModuleList( info->modlist, info->modcnt ); endRead( TRUE ); return( FALSE ); }
/* * GetImageMemInfo */ BOOL GetImageMemInfo( DWORD procid, char *imagename, MemByType *imageinfo ) { DWORD index; DWORD i; BOOL ret; char buf[ _MAX_PATH ]; PERF_COUNTER_DEFINITION *counter; PERF_INSTANCE_DEFINITION *inst; ret = FALSE; beginRead( FALSE ); beginRead( TRUE ); initObj( &costlyData, &imageObject, N_IMAGE ); initObj( ®Data, &processObject, N_PROCESS ); if( imageObject == NULL || processObject == NULL ) goto GETIMAGEMEM_ERROR; inst = getFirstInstance( imageObject ); if( !getProcessIndex( procid, &index ) ) goto GETIMAGEMEM_ERROR; for( i=0; i < imageObject->NumInstances; i += 1 ) { if( inst == NULL ) goto GETIMAGEMEM_ERROR; if( inst->ParentObjectInstance == index ) { wsprintf( buf, "%ls", (char *)inst + inst->NameOffset ); if( !strcmp( buf, imagename ) ) { counter = findCounter( imageObject, N_NO_ACCESS ); if( counter == NULL ) goto GETIMAGEMEM_ERROR; imageinfo->noaccess = getCounterDWORD( inst, counter ); counter = findCounter( imageObject, N_READ_ONLY ); if( counter == NULL ) goto GETIMAGEMEM_ERROR; imageinfo->read = getCounterDWORD( inst, counter ); counter = findCounter( imageObject, N_READ_WRITE ); if( counter == NULL ) goto GETIMAGEMEM_ERROR; imageinfo->write = getCounterDWORD( inst, counter ); counter = findCounter( imageObject, N_WRITE_COPY ); if( counter == NULL ) goto GETIMAGEMEM_ERROR; imageinfo->copy = getCounterDWORD( inst, counter ); counter = findCounter( imageObject, N_EXEC ); if( counter == NULL ) goto GETIMAGEMEM_ERROR; imageinfo->exec = getCounterDWORD( inst, counter ); counter = findCounter( imageObject, N_EXEC_READ ); if( counter == NULL ) goto GETIMAGEMEM_ERROR; imageinfo->execread = getCounterDWORD( inst, counter ); counter = findCounter( imageObject, N_EXEC_WRITE ); if( counter == NULL ) goto GETIMAGEMEM_ERROR; imageinfo->execwrite = getCounterDWORD( inst, counter ); counter = findCounter( imageObject, N_EXEC_COPY ); if( counter == NULL ) goto GETIMAGEMEM_ERROR; imageinfo->execcopy = getCounterDWORD( inst, counter ); imageinfo->tot = imageinfo->noaccess + imageinfo->read + imageinfo->write + imageinfo->copy + imageinfo->exec + imageinfo->execread + imageinfo->execwrite + imageinfo->execcopy; ret = TRUE; break; } } inst = getNextInstance( inst ); } endRead( TRUE ); endRead( FALSE ); return( ret); GETIMAGEMEM_ERROR: endRead( TRUE ); endRead( FALSE ); return( FALSE ); }
int Application::readHeader(int fd) //returns <0 on Error or FORMAT_ASCII or FORMAT_BINARY { if (beginRead(fd)) { lseek(fd, 0, SEEK_SET); return (-2); } if (read(fd, header.dataDate, 24) < 24) { Covise::sendError("KIVA: unexpected end of file in header"); return (-1); } if (read(fd, header.dataName, 80) < 80) { Covise::sendError("KIVA: unexpected end of file in header"); return (-1); } header.dataName[80] = '\0'; header.dataDate[24] = '\0'; //Covise::sendInfo(header.dataName); //Covise::sendInfo(header.dataDate); if (readFloat(fd, header.time) < 0) { return (-1); } if (readInt(fd, header.ncyc) < 0) { return (-1); } if (readFloat(fd, header.crank) < 0) { return (-1); } if (read(fd, header.jnm, 8) < 8) { Covise::sendError("KIVA: unexpected end of file in header"); return (-1); } header.jnm[8] = '\0'; if (readInt(fd, header.ifirst) < 0) { return (-1); } if (readInt(fd, header.ncells) < 0) { return (-1); } if (readInt(fd, header.nverts) < 0) { return (-1); } if (readFloat(fd, header.cylrad) < 0) { return (-1); } if (readFloat(fd, header.zpistn) < 0) { return (-1); } if (readFloat(fd, header.zhead) < 0) { return (-1); } if (readInt(fd, header.np) < 0) { return (-1); } if (readInt(fd, header.nrk) < 0) { return (-1); } if (readInt(fd, header.nsp) < 0) { return (-1); } if (readInt(fd, header.irez) < 0) { return (-1); } if (readInt(fd, header.numBoundaryVertices) < 0) { return (-1); } header.boundaryVertices = new int[header.numBoundaryVertices]; if (read(fd, header.boundaryVertices, header.numBoundaryVertices * sizeof(int)) < header.numBoundaryVertices * sizeof(int)) { Covise::sendError("KIVA: unexpected end of file in header"); return (-1); } if (readInt(fd, header.iper) < 0) { return (-1); } if (readFloat(fd, header.rhop) < 0) { return (-1); } if (readFloat(fd, header.cmueps) < 0) { return (-1); } if (readInt(fd, header.naxisj) < 0) { return (-1); } if (readInt(fd, header.nregions) < 0) { return (-1); } if (endRead(fd)) { return (-1); } header.numCoords = (header.nverts - header.ifirst) + 1; header.numElem = (header.ncells - header.ifirst) + 1; // sk 21.06.2001 //header.print(); return (FORMAT_BINARY); }
int Application::readData(int fd) //returns <0 on Error { int i; if (beginRead(fd)) { return (-1); } rb.init(blockLen, header.numCoords + header.ifirst - 1, fd); rb.skip(header.ifirst - 1); //skip some unused Vertices for (i = 0; i < header.numCoords; i++) { if (rb.read() < 0) return (-1); rb.skip(0, 2); // skip to floats (f +fv) and no ints if (i < header.numElem) { rb.readFloat(x_coord[i]); rb.readFloat(y_coord[i]); rb.readFloat(z_coord[i]); rb.readFloat(u[i]); rb.readFloat(v[i]); rb.readFloat(w[i]); rb.readFloat(p[i]); rb.readFloat(rho[i]); rb.readFloat(vol[i]); rb.readFloat(temp[i]); rb.readFloat(amu[i]); rb.readFloat(tke[i]); rb.readFloat(eps[i]); } else { rb.readFloat(x_coord[i]); rb.readFloat(y_coord[i]); rb.readFloat(z_coord[i]); rb.readFloat(u[i]); rb.readFloat(v[i]); rb.readFloat(w[i]); } } /* if(readDouble) lseek(fd,((header.ifirst-1)*15*8),SEEK_CUR); else lseek(fd,((header.ifirst-1)*15*4),SEEK_CUR); for(i=0;i<header.numCoords;i++) { if(i<header.numElem) { if(readDouble) { lseek(fd,(2*8),SEEK_CUR); //f + fv } else { lseek(fd,(2*4),SEEK_CUR); //f + fv } readFloat(fd,x_coord[i]); readFloat(fd,y_coord[i]); readFloat(fd,z_coord[i]); readFloat(fd,u[i]); readFloat(fd,v[i]); readFloat(fd,w[i]); readFloat(fd,p[i]); readFloat(fd,rho[i]); readFloat(fd,vol[i]); readFloat(fd,temp[i]); readFloat(fd,amu[i]); readFloat(fd,tke[i]); readFloat(fd,eps[i]); } else { if(readDouble) { lseek(fd,(2*8),SEEK_CUR); //f + fv } else { lseek(fd,(2*4),SEEK_CUR); //f + fv } readFloat(fd,x_coord[i]); readFloat(fd,y_coord[i]); readFloat(fd,z_coord[i]); readFloat(fd,u[i]); readFloat(fd,v[i]); readFloat(fd,w[i]); if(readDouble) { lseek(fd,(7*8),SEEK_CUR); } else { lseek(fd,(7*4),SEEK_CUR); } } }*/ if (endRead(fd)) { return (-1); } return (0); }
int Application::readConn(int fd) //returns <0 on Error { int i, i1, i2, i3, i4, i5, i6, i7, i8, *vlist, *elist, *tlist; if (beginRead(fd)) { return (-1); } rb.init(blockLen, header.numCoords + header.ifirst - 1, fd); rb.skip(header.ifirst - 1); //skip some unused Vertices /*if(readDouble) { lseek(fd,((header.ifirst-1)*(7*4+3*8)),SEEK_CUR); } else { lseek(fd,((header.ifirst-1)*10*4),SEEK_CUR); }*/ int *i1tab = new int[header.numCoords]; int *i3tab = new int[header.numCoords]; int *i8tab = new int[header.numCoords]; for (i = 0; i < header.numCoords; i++) { if (rb.read() < 0) return (-1); rb.readInt(i1tab[i]); rb.readInt(i3tab[i]); rb.readInt(i8tab[i]); /* readInt(fd,i1tab[i]); readInt(fd,i3tab[i]); readInt(fd,i8tab[i]); if(readDouble) { lseek(fd,(4*4+3*8),SEEK_CUR); } else { lseek(fd,(7*4),SEEK_CUR); }*/ } vlist = vl; elist = el; tlist = tl; for (i = 0; i < header.numElem; i++) { i1 = i1tab[i] - header.ifirst; i2 = i3tab[i1] - header.ifirst; i3 = i3tab[i] - header.ifirst; i4 = i; i5 = i8tab[i1] - header.ifirst; i6 = i8tab[i2] - header.ifirst; i7 = i8tab[i3] - header.ifirst; i8 = i8tab[i] - header.ifirst; *vlist = i1; vlist++; *vlist = i2; vlist++; *vlist = i3; vlist++; *vlist = i4; vlist++; *vlist = i5; vlist++; *vlist = i6; vlist++; *vlist = i7; vlist++; *vlist = i8; vlist++; *elist = i * 8; *tlist = TYPE_HEXAEDER; elist++; tlist++; } delete[] i1tab; delete[] i3tab; delete[] i8tab; if (endRead(fd)) { return (-1); } return (0); }