File indexing completed on 2024-04-28 03:50:12

0001 // SPDX-License-Identifier: LGPL-2.1-or-later
0002 //
0003 // SPDX-FileCopyrightText: 2010 Wes Hardaker <hardaker@users.sourceforge.net>
0004 //
0005 
0006 #include "AprsFile.h"
0007 
0008 #include <QFile>
0009 
0010 #include "MarbleDebug.h"
0011 
0012 #include "AprsGatherer.h"
0013 
0014 using namespace Marble;
0015 
0016 AprsFile::AprsFile( const QString &fileName )
0017     : m_fileName( fileName ),
0018       m_errorCount( 0 )
0019 {
0020 }
0021 
0022 AprsFile::~AprsFile()
0023 {
0024 }
0025 
0026 QString
0027 AprsFile::sourceName() const
0028 {
0029     return QString( "File" );
0030 }
0031 
0032 bool
0033 AprsFile::canDoDirect() const
0034 {
0035     return true;
0036 }
0037 
0038 QIODevice *
0039 AprsFile::openSocket() 
0040 {
0041     QFile *file = new QFile( m_fileName );
0042     
0043     mDebug() << "opening File socket";
0044     if ( !file->open( QFile::ReadOnly ) ) {
0045         mDebug() << "opening File failed";
0046         delete file;
0047         return nullptr;
0048     }
0049     mDebug() << "Opened " << m_fileName.toLocal8Bit().data();
0050     return file;
0051 }
0052 
0053 void
0054 AprsFile::checkReadReturn( int length, QIODevice **socket,
0055                            AprsGatherer *gatherer ) 
0056 {
0057     Q_UNUSED( socket );
0058     if ( length < 0 || ( length == 0 && m_errorCount > 5 ) ) {
0059         gatherer->sleepFor( 1 ); // just wait for more
0060         return;
0061     }
0062     if ( length == 0 ) {
0063         ++m_errorCount;
0064         mDebug() << "**** Odd: read zero bytes from File socket";
0065     }
0066     return;
0067 }