void RemoteHandler:: getFileList(){ string f_list; DIR* dirp = opendir(curr_dir.c_str()); struct dirent *dp; while ((dp = readdir(dirp)) != NULL){ struct stat buf; lstat(dp->d_name, &buf); string fname(dp->d_name); if (fname != ".") add_row(fname, &buf, f_list); } f_list += "\n"; //cout << f_list; int cmd_fd = c_node.command_fd; IOStream* ioStream; try{ ioStream->writen(cmd_fd, f_list.c_str(), f_list.length()); } catch(IOStream::IOException){ cerr << "IOException! Get File List Error!\n" << flush; return; } return; }
EGLint rcChooseConfig_enc(void *self , EGLint* attribs, uint32_t attribs_size, uint32_t* configs, uint32_t configs_size) { renderControl_encoder_context_t *ctx = (renderControl_encoder_context_t *)self; IOStream *stream = ctx->m_stream; const unsigned int __size_attribs = attribs_size; const unsigned int __size_configs = ((configs != NULL) ? configs_size*sizeof(uint32_t) : 0); unsigned char *ptr; const size_t packetSize = 8 + __size_attribs + 4 + __size_configs + 4 + 2*4; ptr = stream->alloc(packetSize); int tmp = OP_rcChooseConfig;memcpy(ptr, &tmp, 4); ptr += 4; memcpy(ptr, &packetSize, 4); ptr += 4; *(unsigned int *)(ptr) = __size_attribs; ptr += 4; memcpy(ptr, attribs, __size_attribs);ptr += __size_attribs; memcpy(ptr, &attribs_size, 4); ptr += 4; *(unsigned int *)(ptr) = __size_configs; ptr += 4; memcpy(ptr, &configs_size, 4); ptr += 4; if (configs != NULL) stream->readback(configs, __size_configs); EGLint retval; stream->readback(&retval, 4); return retval; }
// ------------------------------------------------------------------------------------------------ // Imports a texture file. bool Q3BSPFileImporter::importTextureFromArchive( const Q3BSP::Q3BSPModel *model, Q3BSP::Q3BSPZipArchive *archive, aiScene*, aiMaterial *pMatHelper, int textureId ) { if (nullptr == archive || nullptr == pMatHelper ) { return false; } if ( textureId < 0 || textureId >= static_cast<int>( model->m_Textures.size() ) ) { return false; } bool res = true; sQ3BSPTexture *pTexture = model->m_Textures[ textureId ]; if ( !pTexture ) { return false; } std::vector<std::string> supportedExtensions; supportedExtensions.push_back( ".jpg" ); supportedExtensions.push_back( ".png" ); supportedExtensions.push_back( ".tga" ); std::string textureName, ext; if ( expandFile( archive, pTexture->strName, supportedExtensions, textureName, ext ) ) { IOStream *pTextureStream = archive->Open( textureName.c_str() ); if ( pTextureStream ) { size_t texSize = pTextureStream->FileSize(); aiTexture *pTexture = new aiTexture; pTexture->mHeight = 0; pTexture->mWidth = static_cast<unsigned int>(texSize); unsigned char *pData = new unsigned char[ pTexture->mWidth ]; size_t readSize = pTextureStream->Read( pData, sizeof( unsigned char ), pTexture->mWidth ); (void)readSize; ai_assert( readSize == pTexture->mWidth ); pTexture->pcData = reinterpret_cast<aiTexel*>( pData ); pTexture->achFormatHint[ 0 ] = ext[ 1 ]; pTexture->achFormatHint[ 1 ] = ext[ 2 ]; pTexture->achFormatHint[ 2 ] = ext[ 3 ]; pTexture->achFormatHint[ 3 ] = '\0'; res = true; aiString name; name.data[ 0 ] = '*'; name.length = 1 + ASSIMP_itoa10( name.data + 1, static_cast<unsigned int>(MAXLEN-1), static_cast<int32_t>(mTextures.size()) ); archive->Close( pTextureStream ); pMatHelper->AddProperty( &name, AI_MATKEY_TEXTURE_DIFFUSE( 0 ) ); mTextures.push_back( pTexture ); } else { // If it doesn't exist in the archive, it is probably just a reference to an external file. // We'll leave it up to the user to figure out which extension the file has. aiString name; strncpy( name.data, pTexture->strName, sizeof name.data ); name.length = strlen( name.data ); pMatHelper->AddProperty( &name, AI_MATKEY_TEXTURE_DIFFUSE( 0 ) ); } } return res; }
static int XMLCALL _writeCallback(void *user_data, char const *buffer, int len) { IOStream *stream = (IOStream*)user_data; uint32 to_write = (uint32)(len&INT_MAX); uint32 written = stream->Write(buffer, to_write); if (written != to_write && !(*stream)) return -1; else return (int)written; }
static int XMLCALL _readCallback(void *user_data, char *buffer, int len) { IOStream *stream = (IOStream*)user_data; uint32 to_read = (uint32)(len&INT_MAX); uint32 readed = stream->Read(buffer, to_read); if (readed != to_read && !(*stream)) return -1; else return (int)readed; }
// Save (SLNDependency) //------------------------------------------------------------------------------ /*static*/ void SLNDependency::Save( IOStream & stream, const Array< SLNDependency > & slnDeps ) { const uint32_t num = (uint32_t)slnDeps.GetSize(); stream.Write( num ); for ( const SLNDependency & deps : slnDeps ) { stream.Write( deps.m_Projects ); stream.Write( deps.m_Dependencies ); } }
// Serialize //------------------------------------------------------------------------------ void Node::Serialize( IOStream & stream ) const { // Deps NODE_SAVE_DEPS( m_PreBuildDependencies ); NODE_SAVE_DEPS( m_StaticDependencies ); NODE_SAVE_DEPS( m_DynamicDependencies ); // Properties const ReflectionInfo * const ri = GetReflectionInfoV(); const ReflectionIter end = ri->End(); for ( ReflectionIter it = ri->Begin(); it != end; ++it ) { const ReflectedProperty & property = *it; const PropertyType pt = property.GetType(); switch ( pt ) { case PT_ASTRING: { if ( property.IsArray() ) { const Array< AString > * arrayOfStrings( nullptr ); property.GetProperty( this, arrayOfStrings ); VERIFY( stream.Write( *arrayOfStrings ) ); } else { AString string; // TODO:C remove this copy property.GetProperty( this, &string ); VERIFY( stream.Write( string ) ); } break; } case PT_BOOL: { bool b( false ); property.GetProperty( this, &b ); VERIFY( stream.Write( b ) ); break; } case PT_UINT32: { uint32_t u32( 0 ); property.GetProperty( this, &u32 ); VERIFY( stream.Write( u32 ) ); break; } default: { ASSERT( false ); // Unsupported type break; } } } }
// SLNSolutionFolder::Save //------------------------------------------------------------------------------ /*static*/ void SLNSolutionFolder::Save( IOStream & stream, const Array< SLNSolutionFolder > & solutionFolders ) { uint32_t numSolutionFolders = (uint32_t)solutionFolders.GetSize(); stream.Write( numSolutionFolders ); for ( uint32_t i=0; i<numSolutionFolders; ++i ) { const SLNSolutionFolder & sln = solutionFolders[ i ]; stream.Write( sln.m_Path ); stream.Write( sln.m_ProjectNames ); } }
// VSProjectFileType::Save //------------------------------------------------------------------------------ /*static*/ void VSProjectFileType::Save( IOStream & stream, const Array< VSProjectFileType > & fileTypes ) { uint32_t numFileTypes = (uint32_t)fileTypes.GetSize(); stream.Write( numFileTypes ); for ( uint32_t i=0; i<numFileTypes; ++i ) { const VSProjectFileType & ft = fileTypes[ i ]; stream.Write( ft.m_FileType ); stream.Write( ft.m_Pattern ); } }
// SaveNode //------------------------------------------------------------------------------ void Node::SaveNode( IOStream & fileStream, const Node * node ) const { // for null pointer, write an empty string if ( node == nullptr ) { fileStream.Write( AString::GetEmpty() ); } else { // for valid nodes, write the node name fileStream.Write( node->GetName() ); } }
bool AssbinImporter::CanRead( const std::string& pFile, IOSystem* pIOHandler, bool /*checkSig*/ ) const { IOStream * in = pIOHandler->Open(pFile); if (!in) return false; char s[32]; in->Read( s, sizeof(char), 32 ); pIOHandler->Close(in); return strncmp( s, "ASSIMP.binary-dump.", 19 ) == 0; }
void rcDestroyWindowSurface_enc(void *self , uint32_t windowSurface) { renderControl_encoder_context_t *ctx = (renderControl_encoder_context_t *)self; IOStream *stream = ctx->m_stream; unsigned char *ptr; const size_t packetSize = 8 + 4; ptr = stream->alloc(packetSize); int tmp = OP_rcDestroyWindowSurface;memcpy(ptr, &tmp, 4); ptr += 4; memcpy(ptr, &packetSize, 4); ptr += 4; memcpy(ptr, &windowSurface, 4); ptr += 4; }
void rcFBSetSwapInterval_enc(void *self , EGLint interval) { renderControl_encoder_context_t *ctx = (renderControl_encoder_context_t *)self; IOStream *stream = ctx->m_stream; unsigned char *ptr; const size_t packetSize = 8 + 4; ptr = stream->alloc(packetSize); int tmp = OP_rcFBSetSwapInterval;memcpy(ptr, &tmp, 4); ptr += 4; memcpy(ptr, &packetSize, 4); ptr += 4; memcpy(ptr, &interval, 4); ptr += 4; }
void rcBindRenderbuffer_enc(void *self , uint32_t colorBuffer) { renderControl_encoder_context_t *ctx = (renderControl_encoder_context_t *)self; IOStream *stream = ctx->m_stream; unsigned char *ptr; const size_t packetSize = 8 + 4; ptr = stream->alloc(packetSize); int tmp = OP_rcBindRenderbuffer;memcpy(ptr, &tmp, 4); ptr += 4; memcpy(ptr, &packetSize, 4); ptr += 4; memcpy(ptr, &colorBuffer, 4); ptr += 4; }
void RemoteHandler:: run(){ IOStream* ioStream; for(;;){ char command[256]; int rd = ioStream->readLine(c_node.command_fd, command, 256); if (rd >0) dispatch(command); else { cout << "client closed" << endl; exit(0); } } }
// LoadNode //------------------------------------------------------------------------------ /*static*/ bool Node::LoadNode( IOStream & stream, Node * & node ) { // read the name of the node AStackString< 512 > nodeName; if ( stream.Read( nodeName ) == false ) { node = nullptr; return false; } // empty name means the pointer was null, which is supported if ( nodeName.IsEmpty() ) { node = nullptr; return true; } // find the node by name - this should never fail NodeGraph & ng = FBuild::Get().GetDependencyGraph(); Node * n = ng.FindNode( nodeName ); if ( n == nullptr ) { node = nullptr; return false; } node = n; return true; }
// Serialize //------------------------------------------------------------------------------ void Job::Serialize( IOStream & stream ) { PROFILE_FUNCTION // write jobid stream.Write( m_JobId ); stream.Write( m_Node->GetName() ); // write properties of node Node::SaveRemote( stream, m_Node ); stream.Write( IsDataCompressed() ); stream.Write( m_DataSize ); stream.Write( m_Data, m_DataSize ); }
GLint rcGetRendererVersion_enc(void *self ) { renderControl_encoder_context_t *ctx = (renderControl_encoder_context_t *)self; IOStream *stream = ctx->m_stream; unsigned char *ptr; const size_t packetSize = 8; ptr = stream->alloc(packetSize); int tmp = OP_rcGetRendererVersion;memcpy(ptr, &tmp, 4); ptr += 4; memcpy(ptr, &packetSize, 4); ptr += 4; GLint retval; stream->readback(&retval, 4); return retval; }
bool readInput(IOStream &ioStream, int inputType, InputType*& source) { delete source; source=ioStream.GetInput((inputType ? static_cast<InputType*>(new ConfusionNet) : static_cast<InputType*>(new Sentence(Input)))); return (source ? true : false); }
// Load (SLNDependency) //------------------------------------------------------------------------------ /*static*/ bool SLNDependency::Load( IOStream & stream, Array< SLNDependency > & slnDeps ) { ASSERT( slnDeps.IsEmpty() ); uint32_t num( 0 ); if ( !stream.Read( num ) ) { return false; } slnDeps.SetSize( num ); for ( SLNDependency & deps : slnDeps ) { if ( stream.Read( deps.m_Projects ) == false ) { return false; } if ( stream.Read( deps.m_Dependencies ) == false ) { return false; } } return true; }
void CheesyVisionServer::Run() { cout << "Running Cheesy Vision Server" << endl; if (_listening == false) return; //Make sure we are listening SocketServerStreamProvider *sock; sock = new SocketServerStreamProvider(_listenPort); while (_listening) { try { IOStream *stream = sock->accept(); _lastHeartbeatTime = Timer::GetFPGATimestamp(); while (Timer::GetFPGATimestamp() < _lastHeartbeatTime + HEARTBEAT_TIMEOUT) { try { uint8_t byte; stream->read(&byte, 1); _curLeftStatus = (byte & (1 << 1)) > 0; _curRightStatus = (byte & (1 << 0)) > 0; UpdateCounts(_curLeftStatus,_curRightStatus); _lastHeartbeatTime = Timer::GetFPGATimestamp(); } catch (EOFException e) { //End of file, wait for a bit and read some more Wait(0.05); } } delete stream;//close, delete and recreate the stream } catch (IOException e) { printf("Socket IO error: %s\n", e.what()); //Catching this exception will dro } } Wait(0.05); delete sock; }
// //------------------------------------------------------------------------------ /*static*/ void Node::Save( IOStream & stream, const Node * node ) { ASSERT( node ); // save type uint32_t nodeType = (uint32_t)node->GetType(); stream.Write( nodeType ); // save stamp (but not for file nodes) if ( nodeType != Node::FILE_NODE ) { uint64_t stamp = node->GetStamp(); stream.Write( stamp ); } // save contents node->Save( stream ); }
void glUtilsWritePackPointerData(void* _stream, unsigned char *src, int size, GLenum type, unsigned int stride, unsigned int datalen) { IOStream* stream = reinterpret_cast<IOStream*>(_stream); unsigned int vsize = size * glSizeof(type); if (stride == 0) stride = vsize; if (stride == vsize) { stream->writeFully(src, datalen); } else { for (unsigned int i = 0; i < datalen; i += vsize) { stream->writeFully(src, (size_t)vsize); src += stride; } } }
int rcOpenColorBuffer2_enc(void *self , uint32_t colorbuffer) { renderControl_encoder_context_t *ctx = (renderControl_encoder_context_t *)self; IOStream *stream = ctx->m_stream; unsigned char *ptr; const size_t packetSize = 8 + 4; ptr = stream->alloc(packetSize); int tmp = OP_rcOpenColorBuffer2;memcpy(ptr, &tmp, 4); ptr += 4; memcpy(ptr, &packetSize, 4); ptr += 4; memcpy(ptr, &colorbuffer, 4); ptr += 4; int retval; stream->readback(&retval, 4); return retval; }
int rcFlushWindowColorBuffer_enc(void *self , uint32_t windowSurface) { renderControl_encoder_context_t *ctx = (renderControl_encoder_context_t *)self; IOStream *stream = ctx->m_stream; unsigned char *ptr; const size_t packetSize = 8 + 4; ptr = stream->alloc(packetSize); int tmp = OP_rcFlushWindowColorBuffer;memcpy(ptr, &tmp, 4); ptr += 4; memcpy(ptr, &packetSize, 4); ptr += 4; memcpy(ptr, &windowSurface, 4); ptr += 4; int retval; stream->readback(&retval, 4); return retval; }
void RemoteHandler:: getFile(char* filename){ string fullpath; int pos = curr_dir.find_last_of("/"); if(pos == curr_dir.length()-1) fullpath = curr_dir + string(filename); else fullpath = curr_dir + "/" + string(filename); int cmd_fd = c_node.command_fd; int data_fd = c_node.data_fd; IOStream* ioStream; FILE* fileFD = fopen(fullpath.c_str(), "r"); long fsize = fileSize(fileFD); char reply[128]; sprintf(reply, "size|%ld\n", fsize); try{ ioStream->writen(cmd_fd, reply, strlen(reply)); long toSend = fsize; long send_buf; long buf_size = 1024; char buf[buf_size]; send_buf = min(toSend, buf_size); while((fread(buf, 1, send_buf, fileFD) >0) && (toSend >0)){ ioStream->writen(data_fd, buf, send_buf); toSend = toSend-send_buf; send_buf = min(toSend, buf_size); } fclose(fileFD); cout << "[File Sent!]\n" << endl << flush; return; } catch(IOStream::IOException){ cerr << "IOException! in get file, write to GUI Error!\n" << flush; return; } }
bool Responder::onInput(IOStream& ios) { while (ios.buffer().in_avail() > 0) { if (advance(ios.buffer())) { if (_failed) { replyError(ios, _errorMessage.c_str(), 0); } else { try { _result = _proc->endCall(); reply(ios); } catch (const RemoteException& e) { ios.buffer().discard(); replyError(ios, e.what(), e.rc()); } catch (const std::exception& e) { ios.buffer().discard(); replyError(ios, e.what(), 0); } } _serviceRegistry.releaseProcedure(_proc); _proc = 0; _args = 0; _result = 0; _state = state_0; _failed = false; _errorMessage.clear(); _deserializer.begin(); return true; } } return false; }
// SLNSolutionFolder::Load //------------------------------------------------------------------------------ /*static*/ bool SLNSolutionFolder::Load( IOStream & stream, Array< SLNSolutionFolder > & solutionFolders ) { ASSERT( solutionFolders.IsEmpty() ); uint32_t numSolutionFolders( 0 ); if ( !stream.Read( numSolutionFolders ) ) { return false; } solutionFolders.SetSize( numSolutionFolders ); for ( uint32_t i=0; i<numSolutionFolders; ++i ) { SLNSolutionFolder & sln = solutionFolders[ i ]; if ( stream.Read( sln.m_Path ) == false ) { return false; } if ( stream.Read( sln.m_ProjectNames ) == false ) { return false; } } return true; }
// Save //------------------------------------------------------------------------------ void Dependencies::Save( IOStream & stream ) const { size_t numDeps = GetSize(); stream.Write( (uint32_t)numDeps ); Iter end = End(); for ( Iter it = Begin(); it != end; ++it ) { const Dependency & dep = *it; // Nodes are saved by index to simplify deserialization uint32_t index = dep.GetNode()->GetIndex(); stream.Write( index ); // Save weak flag bool isWeak = dep.IsWeak(); stream.Write( isWeak ); } }
// VSProjectFileType::Load //------------------------------------------------------------------------------ /*static*/ bool VSProjectFileType::Load( IOStream & stream, Array< VSProjectFileType > & fileTypes ) { ASSERT( fileTypes.IsEmpty() ); uint32_t numFileTypes( 0 ); if ( !stream.Read( numFileTypes ) ) { return false; } fileTypes.SetSize( numFileTypes ); for ( uint32_t i=0; i<numFileTypes; ++i ) { VSProjectFileType & ft = fileTypes[ i ]; if ( stream.Read( ft.m_FileType ) == false ) { return false; } if ( stream.Read( ft.m_Pattern ) == false ) { return false; } } return true; }