static ssize_t fd_store(krb5_storage * sp, const void *data, size_t size) { const char *cbuf = (const char *)data; ssize_t count; size_t rem = size; /* similar pattern to net_write() to support pipes */ while (rem > 0) { count = write(FD(sp), cbuf, rem); if (count < 0) { if (errno == EINTR) continue; else return size - rem; } cbuf += count; rem -= count; } return size; }
static void fd_free(krb5_storage * sp) { close(FD(sp)); }
static off_t fd_seek(krb5_storage * sp, off_t offset, int whence) { return lseek(FD(sp), offset, whence); }
static ssize_t fd_store(krb5_storage * sp, const void *data, size_t size) { return net_write(FD(sp), data, size); }
static ssize_t fd_fetch(krb5_storage * sp, void *data, size_t size) { return net_read(FD(sp), data, size); }
bool ContextPrivate::save( const QString &pFileName, const QList<QUuid> *pNodeList ) const { QFileInfo FileInfo( pFileName ); QString TmpFileName = FileInfo.absoluteFilePath().append( ".out" ); if( true ) { QSettings CFG( TmpFileName, QSettings::IniFormat ); if( !CFG.isWritable() ) { return( false ); } CFG.clear(); emit saveStart( CFG ); CFG.beginGroup( "fugio" ); CFG.setValue( "version", int( 2 ) ); CFG.setValue( "duration", double( duration() ) ); CFG.endGroup(); //------------------------------------------------------------------------- CFG.beginGroup( "meta" ); for( auto it = mMetaInfoMap.begin() ; it != mMetaInfoMap.end() ; it++ ) { const QString K = mMetaNameMap.value( it.key() ); const QString V = it.value(); if( !K.isEmpty() && !V.isEmpty() ) { CFG.setValue( K, V ); } } CFG.endGroup(); //------------------------------------------------------------------------- CFG.beginGroup( "nodes" ); for( QSharedPointer<fugio::NodeInterface> N : mNodeHash.values() ) { if( !pNodeList || pNodeList->contains( N->uuid() ) ) { CFG.setValue( fugio::utils::uuid2string( N->uuid() ), fugio::utils::uuid2string( N->controlUuid() ) ); } } CFG.endGroup(); //------------------------------------------------------------------------- CFG.beginGroup( "connections" ); for( QSharedPointer<fugio::NodeInterface> N : mNodeHash.values() ) { if( !pNodeList || pNodeList->contains( N->uuid() ) ) { for( QSharedPointer<fugio::PinInterface> P : N->enumInputPins() ) { if( !P->isConnected() ) { continue; } QSharedPointer<fugio::PinInterface> ConPin = P->connectedPin(); if( !ConPin || !ConPin->node() ) { continue; } if( !pNodeList || pNodeList->contains( ConPin->node()->uuid() ) ) { CFG.setValue( fugio::utils::uuid2string( P->globalId() ), fugio::utils::uuid2string( ConPin->globalId() ) ); } } } } CFG.endGroup(); //------------------------------------------------------------------------- for( QSharedPointer<fugio::NodeInterface> N : mNodeHash.values() ) { if( !pNodeList || pNodeList->contains( N->uuid() ) ) { CFG.beginGroup( fugio::utils::uuid2string( N->uuid() ) ); N->saveSettings( CFG, false ); CFG.endGroup(); for( QSharedPointer<fugio::PinInterface> P : N->enumPins() ) { CFG.beginGroup( fugio::utils::uuid2string( P->globalId() ) ); P->saveSettings( CFG ); CFG.endGroup(); } } } //------------------------------------------------------------------------- CFG.beginGroup( "assets" ); for( auto it : mAssetMap.toStdMap() ) { QFileInfo FI( CFG.fileName() ); QDir FD( FI.absolutePath() ); QString AP = FD.absoluteFilePath( it.second ); qDebug() << AP; CFG.setValue( fugio::utils::uuid2string( it.first ), AP ); } CFG.endGroup(); //------------------------------------------------------------------------- emit saving( CFG ); emit saveEnd( CFG ); } QString TmpOld; if( FileInfo.exists() ) { TmpOld = FileInfo.dir().absoluteFilePath( FileInfo.completeBaseName() ).append( ".old" ); if( !QFile::rename( pFileName, TmpOld ) ) { qWarning() << "Couldn't rename output file"; return( false ); } } if( true ) { QFile SrcDat( TmpFileName ); QFile DstDat( pFileName ); if( !SrcDat.open( QFile::ReadOnly ) ) { qWarning() << "Couldn't open temporary file"; return( false ); } if( !DstDat.open( QFile::WriteOnly ) ) { qWarning() << "Couldn't open output file"; return( false ); } QStringList HdrLst; HdrLst << QString( ";-----------------------------------------------------------------" ); HdrLst << QString( "; Created with Fugio %1" ).arg( QCoreApplication::applicationVersion() ); for( auto it = mMetaInfoMap.begin() ; it != mMetaInfoMap.end() ; it++ ) { const QString K = mMetaNameMap.value( it.key() ); const QString V = it.value(); if( !K.isEmpty() && !V.isEmpty() ) { HdrLst << QString( "; %1: %2" ).arg( K ).arg( V ); } } HdrLst << QString( ";-----------------------------------------------------------------" ); HdrLst << QString( "" ); HdrLst << QString( "" ); QByteArray TmpDat; TmpDat = HdrLst.join( "\n" ).toLatin1(); while( !TmpDat.isEmpty() ) { if( DstDat.write( TmpDat ) != TmpDat.size() ) { qWarning() << "Couldn't write output data"; return( false ); } TmpDat = SrcDat.read( 1024 ); } SrcDat.close(); DstDat.close(); } if( !QFile::remove( TmpFileName ) ) { qWarning() << "Couldn't remove temporary file"; } if( !TmpOld.isEmpty() && !QFile::remove( TmpOld ) ) { qWarning() << "Couldn't remove old file"; } return( true ); }
ReadFile::~ReadFile() { fd.close(); fd = FD(); }
bool ReadFile::is_open() { return fd != FD(); }
FD prev() { return FD(fd - 1); }
FD next() { return FD(fd + 1); }
static FD stderr() { return FD(2); }
static FD stdout() { return FD(1); }
static FD stdin() { return FD(0); }
static FD cast_dammit(int f) { return FD(f); }
// Turn off engine for RTL // Move this line down below the HOME to return home with power before circling unpowered. FLAG_ON(F_LAND) // Fly home HOME // Once we arrive home, aim the turtle in the // direction that the plane is already moving. USE_CURRENT_ANGLE REPEAT_FOREVER // Fly a circle (36-point regular polygon) REPEAT(36) RT(10) FD(8) END END }; //////////////////////////////////////////////////////////////////////////////// // More Examples /* // Fly a 200m square starting at the current location and altitude, in the current direction REPEAT(4) FD(200) RT(90) END