Skip to content

Commit

Permalink
cppcheck: Fix "one definition rule" is violation for FileTransfer.
Browse files Browse the repository at this point in the history
This class is defined in two different locations:

    libs/libmythprotoserver/sockethandler/filetransfer.h
    programs/mythbackend/filetransfer.h

Eliminate the error by changing the class name in mythbackend to
BEFileTransfer.

https://en.cppreference.com/w/cpp/language/definition#One_Definition_Rule
  • Loading branch information
linuxdude42 committed Jan 3, 2023
1 parent ed43659 commit 270b4f2
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 34 deletions.
34 changes: 17 additions & 17 deletions mythtv/programs/mythbackend/filetransfer.cpp
Expand Up @@ -16,9 +16,9 @@
// MythBackend
#include "filetransfer.h"

FileTransfer::FileTransfer(QString &filename, MythSocket *remote,
BEFileTransfer::BEFileTransfer(QString &filename, MythSocket *remote,
bool usereadahead, std::chrono::milliseconds timeout) :
ReferenceCounter(QString("FileTransfer:%1").arg(filename)),
ReferenceCounter(QString("BEFileTransfer:%1").arg(filename)),
m_rbuffer(MythMediaBuffer::Create(filename, false, usereadahead, timeout, true)),
m_sock(remote)
{
Expand All @@ -28,8 +28,8 @@ FileTransfer::FileTransfer(QString &filename, MythSocket *remote,
m_rbuffer->Start();
}

FileTransfer::FileTransfer(QString &filename, MythSocket *remote, bool write) :
ReferenceCounter(QString("FileTransfer:%1").arg(filename)),
BEFileTransfer::BEFileTransfer(QString &filename, MythSocket *remote, bool write) :
ReferenceCounter(QString("BEFileTransfer:%1").arg(filename)),
m_rbuffer(MythMediaBuffer::Create(filename, write)),
m_sock(remote), m_writemode(write)
{
Expand All @@ -42,11 +42,11 @@ FileTransfer::FileTransfer(QString &filename, MythSocket *remote, bool write) :
m_rbuffer->Start();
}

FileTransfer::~FileTransfer()
BEFileTransfer::~BEFileTransfer()
{
Stop();

if (m_sock) // FileTransfer becomes responsible for deleting the socket
if (m_sock) // BEFileTransfer becomes responsible for deleting the socket
m_sock->DecrRef();

if (m_rbuffer)
Expand All @@ -62,12 +62,12 @@ FileTransfer::~FileTransfer()
}
}

bool FileTransfer::isOpen(void)
bool BEFileTransfer::isOpen(void)
{
return m_rbuffer && m_rbuffer->IsOpen();
}

bool FileTransfer::ReOpen(const QString& newFilename)
bool BEFileTransfer::ReOpen(const QString& newFilename)
{
if (!m_writemode)
return false;
Expand All @@ -78,7 +78,7 @@ bool FileTransfer::ReOpen(const QString& newFilename)
return false;
}

void FileTransfer::Stop(void)
void BEFileTransfer::Stop(void)
{
if (m_readthreadlive)
{
Expand All @@ -98,7 +98,7 @@ void FileTransfer::Stop(void)
m_pginfo->UpdateInUseMark();
}

void FileTransfer::Pause(void)
void BEFileTransfer::Pause(void)
{
LOG(VB_FILE, LOG_INFO, "calling StopReads()");
if (m_rbuffer)
Expand All @@ -110,7 +110,7 @@ void FileTransfer::Pause(void)
m_pginfo->UpdateInUseMark();
}

void FileTransfer::Unpause(void)
void BEFileTransfer::Unpause(void)
{
LOG(VB_FILE, LOG_INFO, "calling StartReads()");
if (m_rbuffer)
Expand All @@ -125,7 +125,7 @@ void FileTransfer::Unpause(void)
m_pginfo->UpdateInUseMark();
}

int FileTransfer::RequestBlock(int size)
int BEFileTransfer::RequestBlock(int size)
{
if (!m_readthreadlive || !m_rbuffer)
return -1;
Expand Down Expand Up @@ -165,7 +165,7 @@ int FileTransfer::RequestBlock(int size)
return (ret < 0) ? -1 : tot;
}

int FileTransfer::WriteBlock(int size)
int BEFileTransfer::WriteBlock(int size)
{
if (!m_writemode || !m_rbuffer)
return -1;
Expand Down Expand Up @@ -226,7 +226,7 @@ int FileTransfer::WriteBlock(int size)
return (ret < 0) ? -1 : tot;
}

long long FileTransfer::Seek(long long curpos, long long pos, int whence)
long long BEFileTransfer::Seek(long long curpos, long long pos, int whence)
{
if (m_pginfo)
m_pginfo->UpdateInUseMark();
Expand Down Expand Up @@ -258,23 +258,23 @@ long long FileTransfer::Seek(long long curpos, long long pos, int whence)
return ret;
}

uint64_t FileTransfer::GetFileSize(void)
uint64_t BEFileTransfer::GetFileSize(void)
{
if (m_pginfo)
m_pginfo->UpdateInUseMark();

return m_rbuffer ? m_rbuffer->GetRealFileSize() : 0;
}

QString FileTransfer::GetFileName(void)
QString BEFileTransfer::GetFileName(void)
{
if (!m_rbuffer)
return {};

return m_rbuffer->GetFilename();
}

void FileTransfer::SetTimeout(bool fast)
void BEFileTransfer::SetTimeout(bool fast)
{
if (m_pginfo)
m_pginfo->UpdateInUseMark();
Expand Down
10 changes: 5 additions & 5 deletions mythtv/programs/mythbackend/filetransfer.h
Expand Up @@ -17,14 +17,14 @@ class MythMediaBuffer;
class MythSocket;
class QString;

class FileTransfer : public ReferenceCounter
class BEFileTransfer : public ReferenceCounter
{
friend class QObject; // quiet OSX gcc warning

public:
FileTransfer(QString &filename, MythSocket *remote,
bool usereadahead, std::chrono::milliseconds timeout);
FileTransfer(QString &filename, MythSocket *remote, bool write);
BEFileTransfer(QString &filename, MythSocket *remote,
bool usereadahead, std::chrono::milliseconds timeout);
BEFileTransfer(QString &filename, MythSocket *remote, bool write);

MythSocket *getSocket() { return m_sock; }

Expand All @@ -46,7 +46,7 @@ class FileTransfer : public ReferenceCounter
void SetTimeout(bool fast);

private:
~FileTransfer() override;
~BEFileTransfer() override;

volatile bool m_readthreadlive {true};
bool m_readsLocked {false};
Expand Down
18 changes: 9 additions & 9 deletions mythtv/programs/mythbackend/mainserver.cpp
Expand Up @@ -1959,7 +1959,7 @@ void MainServer::HandleAnnounce(QStringList &slist, QStringList commands,
for (++it; it != slist.cend(); ++it)
checkfiles += *it;

FileTransfer *ft = nullptr;
BEFileTransfer *ft = nullptr;
bool writemode = false;
bool usereadahead = true;
std::chrono::milliseconds timeout_ms = 2s;
Expand Down Expand Up @@ -2054,14 +2054,14 @@ void MainServer::HandleAnnounce(QStringList &slist, QStringList commands,
QWriteLocker lock(&m_sockListLock);
if (!m_controlSocketList.remove(socket))
return; // socket was disconnected
ft = new FileTransfer(filename, socket, writemode);
ft = new BEFileTransfer(filename, socket, writemode);
}
else
{
QWriteLocker lock(&m_sockListLock);
if (!m_controlSocketList.remove(socket))
return; // socket was disconnected
ft = new FileTransfer(filename, socket, usereadahead, timeout_ms);
ft = new BEFileTransfer(filename, socket, usereadahead, timeout_ms);
}

if (!ft->isOpen())
Expand All @@ -2070,7 +2070,7 @@ void MainServer::HandleAnnounce(QStringList &slist, QStringList commands,
QString("Can't open %1").arg(filename));
errlist << "filetransfer_unable_to_open_file";
socket->WriteStringList(errlist);
socket->IncrRef(); // FileTransfer took ownership of the socket, take it back
socket->IncrRef(); // BEFileTransfer took ownership of the socket, take it back
ft->DecrRef();
return;
}
Expand Down Expand Up @@ -7084,13 +7084,13 @@ void MainServer::HandleFileTransferQuery(QStringList &slist,
QStringList retlist;

m_sockListLock.lockForRead();
FileTransfer *ft = GetFileTransferByID(recnum);
BEFileTransfer *ft = GetFileTransferByID(recnum);
if (!ft)
{
if (command == "DONE")
{
// if there is an error opening the file, we may not have a
// FileTransfer instance for this connection.
// BEFileTransfer instance for this connection.
retlist << "OK";
}
else
Expand Down Expand Up @@ -7924,7 +7924,7 @@ void MainServer::connectionClosed(MythSocket *socket)
MythSocket *sock = (*ft)->getSocket();
if (sock == socket)
{
LOG(VB_GENERAL, LOG_INFO, QString("FileTransfer sock(%1) disconnected")
LOG(VB_GENERAL, LOG_INFO, QString("BEFileTransfer sock(%1) disconnected")
.arg(quintptr(socket),0,16) );
(*ft)->DecrRef();
m_fileTransferList.erase(ft);
Expand Down Expand Up @@ -8007,7 +8007,7 @@ PlaybackSock *MainServer::GetPlaybackBySock(MythSocket *sock)
}

/// Warning you must hold a sockListLock lock before calling this
FileTransfer *MainServer::GetFileTransferByID(int id)
BEFileTransfer *MainServer::GetFileTransferByID(int id)
{
for (auto & ft : m_fileTransferList)
if (id == ft->getSocket()->GetSocketDescriptor())
Expand All @@ -8016,7 +8016,7 @@ FileTransfer *MainServer::GetFileTransferByID(int id)
}

/// Warning you must hold a sockListLock lock before calling this
FileTransfer *MainServer::GetFileTransferBySock(MythSocket *sock)
BEFileTransfer *MainServer::GetFileTransferBySock(MythSocket *sock)
{
for (auto & ft : m_fileTransferList)
if (sock == ft->getSocket())
Expand Down
6 changes: 3 additions & 3 deletions mythtv/programs/mythbackend/mainserver.h
Expand Up @@ -282,8 +282,8 @@ class MainServer : public QObject, public MythSocketCBs

PlaybackSock *GetSlaveByHostname(const QString &hostname);
PlaybackSock *GetPlaybackBySock(MythSocket *socket);
FileTransfer *GetFileTransferByID(int id);
FileTransfer *GetFileTransferBySock(MythSocket *socket);
BEFileTransfer *GetFileTransferByID(int id);
BEFileTransfer *GetFileTransferBySock(MythSocket *socket);

static QString LocalFilePath(const QString &path, const QString &wantgroup);

Expand Down Expand Up @@ -319,7 +319,7 @@ class MainServer : public QObject, public MythSocketCBs

QReadWriteLock m_sockListLock;
std::vector<PlaybackSock *> m_playbackList;
std::vector<FileTransfer *> m_fileTransferList;
std::vector<BEFileTransfer *> m_fileTransferList;
QSet<MythSocket*> m_controlSocketList;
std::vector<MythSocket*> m_decrRefSocketList;

Expand Down

0 comments on commit 270b4f2

Please sign in to comment.