Permalink
Browse files

Refs #10311. Convert PlaybackSock reference counting to ReferenceCoun…

…ter.
  • Loading branch information...
1 parent cd996fd commit 6e490cd7351bdabe204bd455c233f6759b7f7c05 @daniel-kristjansson daniel-kristjansson committed Jun 1, 2012
@@ -51,7 +51,7 @@ EncoderLink::EncoderLink(int capturecardnum, PlaybackSock *lsock,
lastWakeTime = QDateTime::currentDateTime();
if (sock)
- sock->UpRef();
+ sock->IncrRef();
}
/** \fn EncoderLink::EncoderLink(int, TVRec *)
@@ -92,7 +92,7 @@ void EncoderLink::SetSocket(PlaybackSock *lsock)
{
if (lsock)
{
- lsock->UpRef();
+ lsock->IncrRef();
if (gCoreContext->GetSettingOnHost("SleepCommand", hostname).isEmpty())
SetSleepStatus(sStatus_Undefined);
@@ -108,7 +108,7 @@ void EncoderLink::SetSocket(PlaybackSock *lsock)
}
if (sock)
- sock->DownRef();
+ sock->DecrRef();
sock = lsock;
}
@@ -417,7 +417,7 @@ void MainServer::ProcessRequestWork(MythSocket *sock)
LOG(VB_GENERAL, LOG_ERR, "ProcessRequest unknown socket");
return;
}
- pbs->UpRef();
+ pbs->IncrRef();
sockListLock.unlock();
if (command == "QUERY_RECORDINGS")
@@ -805,8 +805,7 @@ void MainServer::ProcessRequestWork(MythSocket *sock)
SendResponse(pbssock, strlist);
}
- // Decrease refcount..
- pbs->DownRef();
+ pbs->DecrRef();
}
void MainServer::customEvent(QEvent *e)
@@ -1137,7 +1136,7 @@ void MainServer::customEvent(QEvent *e)
vector<PlaybackSock *>::iterator it = playbackList.begin();
for (; it != playbackList.end(); ++it)
{
- (*it)->UpRef();
+ (*it)->IncrRef();
localPBSList.push_back(*it);
}
sockListLock.unlock();
@@ -1224,7 +1223,7 @@ void MainServer::customEvent(QEvent *e)
for (iter = localPBSList.begin(); iter != localPBSList.end(); ++iter)
{
PlaybackSock *pbs = *iter;
- pbs->DownRef();
+ pbs->DecrRef();
}
}
}
@@ -1771,7 +1770,7 @@ void MainServer::HandleQueryRecordings(QString type, PlaybackSock *pbs)
}
if (slave)
- slave->DownRef();
+ slave->DecrRef();
proginfo->ToStringList(outputlist);
}
@@ -2315,7 +2314,7 @@ void MainServer::HandleCheckRecordingActive(QStringList &slist,
if (slave)
{
result = slave->CheckRecordingActive(&pginfo);
- slave->DownRef();
+ slave->DecrRef();
}
}
else
@@ -2380,7 +2379,7 @@ void MainServer::DoHandleStopRecording(
SendResponse(pbssock, outputlist);
}
- slave->DownRef();
+ slave->DecrRef();
return;
}
else
@@ -2533,7 +2532,7 @@ void MainServer::DoHandleDeleteRecording(
SendResponse(pbssock, outputlist);
}
- slave->DownRef();
+ slave->DecrRef();
return;
}
}
@@ -2908,7 +2907,7 @@ void MainServer::HandleQueryCheckFile(QStringList &slist, PlaybackSock *pbs)
if (slave)
{
exists = slave->CheckFile(&recinfo);
- slave->DownRef();
+ slave->DecrRef();
QStringList outputlist( QString::number(exists) );
if (exists)
@@ -2989,7 +2988,7 @@ void MainServer::HandleQueryFileHash(QStringList &slist, PlaybackSock *pbs)
if (slave)
{
hash = slave->GetFileHash(filename, storageGroup);
- slave->DownRef();
+ slave->DecrRef();
}
else
{
@@ -3007,7 +3006,7 @@ void MainServer::HandleQueryFileHash(QStringList &slist, PlaybackSock *pbs)
if (slave)
{
hash = slave->GetFileHash(filename, storageGroup);
- slave->DownRef();
+ slave->DecrRef();
}
}
}
@@ -3260,7 +3259,7 @@ void MainServer::HandleSGGetFileList(QStringList &sList,
LOG(VB_FILE, LOG_INFO, "HandleSGGetFileList: Getting remote info");
strList = slave->GetSGFileList(wantHost, groupname, path,
fileNamesOnly);
- slave->DownRef();
+ slave->DecrRef();
slaveUnreachable = false;
}
else
@@ -3322,7 +3321,7 @@ void MainServer::HandleSGFileQuery(QStringList &sList,
{
LOG(VB_FILE, LOG_INFO, "HandleSGFileQuery: Getting remote info");
strList = slave->GetSGFileQuery(wantHost, groupname, filename);
- slave->DownRef();
+ slave->DecrRef();
slaveUnreachable = false;
}
else
@@ -4275,7 +4274,7 @@ void MainServer::HandleIsActiveBackendQuery(QStringList &slist,
if (slave != NULL)
{
retlist << "TRUE";
- slave->DownRef();
+ slave->DecrRef();
}
else
retlist << "FALSE";
@@ -4442,7 +4441,7 @@ void MainServer::BackendQueryDiskSpace(QStringList &strlist, bool consolidated,
continue;
backendsCounted[pbs->getHostname()] = true;
- pbs->UpRef();
+ pbs->IncrRef();
localPlaybackList.push_back(pbs);
allHostList += "," + pbs->getHostname();
}
@@ -4452,7 +4451,7 @@ void MainServer::BackendQueryDiskSpace(QStringList &strlist, bool consolidated,
for (list<PlaybackSock *>::iterator p = localPlaybackList.begin() ;
p != localPlaybackList.end() ; ++p) {
(*p)->GetDiskSpace(strlist);
- (*p)->DownRef();
+ (*p)->DecrRef();
}
}
@@ -5388,7 +5387,7 @@ void MainServer::HandleGenPreviewPixmap(QStringList &slist, PlaybackSock *pbs)
outputlist = slave->GenPreviewPixmap(token, &pginfo);
}
- slave->DownRef();
+ slave->DecrRef();
if (outputlist.empty() || outputlist[0] != "OK")
m_previewRequestedBy.remove(token);
@@ -5449,7 +5448,7 @@ void MainServer::HandlePixmapLastModified(QStringList &slist, PlaybackSock *pbs)
if (slave)
{
QDateTime slavetime = slave->PixmapLastModified(&pginfo);
- slave->DownRef();
+ slave->DecrRef();
strlist = (slavetime.isValid()) ?
QStringList(QString::number(slavetime.toTime_t())) :
@@ -5604,7 +5603,7 @@ void MainServer::HandlePixmapGetIfModified(
strlist = slave->ForwardRequest(slist);
- slave->DownRef(); slave = NULL;
+ slave->DecrRef();
if (!strlist.empty())
{
@@ -5674,7 +5673,7 @@ void MainServer::connectionClosed(MythSocket *socket)
{
playbackList.erase(it);
sockListLock.unlock();
- masterServer->DownRef();
+ masterServer->DecrRef();
masterServer = NULL;
MythEvent me("LOCAL_RECONNECT_TO_MASTER");
gCoreContext->dispatch(me);
@@ -5768,7 +5767,7 @@ void MainServer::connectionClosed(MythSocket *socket)
// delay handling the disconnect until a little later. #9885
SendSlaveDisconnectedEvent(disconnectedSlaves, needsReschedule);
- pbs->DownRef();
+ pbs->DecrRef();
return;
}
}
@@ -5809,7 +5808,7 @@ PlaybackSock *MainServer::GetSlaveByHostname(const QString &hostname)
(gCoreContext->IsThisHost(hostname, pbs->getHostname()))))
{
sockListLock.unlock();
- pbs->UpRef();
+ pbs->IncrRef();
return pbs;
}
}
@@ -5834,7 +5833,7 @@ PlaybackSock *MainServer::GetMediaServerByHostname(const QString &hostname)
((pbs->getHostname().toLower() == hostname.toLower()) ||
(gCoreContext->IsThisHost(hostname, pbs->getHostname()))))
{
- pbs->UpRef();
+ pbs->IncrRef();
return pbs;
}
}
@@ -14,14 +14,14 @@ using namespace std;
#define LOC QString("PlaybackSock: ")
#define LOC_ERR QString("PlaybackSock, Error: ")
-PlaybackSock::PlaybackSock(MainServer *parent, MythSocket *lsock,
- QString lhostname, PlaybackSockEventsMode eventsMode)
+PlaybackSock::PlaybackSock(
+ MainServer *parent, MythSocket *lsock,
+ QString lhostname, PlaybackSockEventsMode eventsMode) :
+ ReferenceCounter("PlaybackSock")
{
m_parent = parent;
QString localhostname = gCoreContext->GetHostName();
- refCount = 0;
-
sock = lsock;
hostname = lhostname;
m_eventsMode = eventsMode;
@@ -44,25 +44,6 @@ PlaybackSock::~PlaybackSock()
sock->DownRef();
}
-void PlaybackSock::UpRef(void)
-{
- QMutexLocker locker(&refLock);
- refCount++;
-}
-
-bool PlaybackSock::DownRef(void)
-{
- QMutexLocker locker(&refLock);
-
- refCount--;
- if (refCount < 0)
- {
- m_parent->DeletePBS(this);
- return true;
- }
- return false;
-}
-
bool PlaybackSock::wantsEvents(void) const
{
return (m_eventsMode != kPBSEvents_None);
@@ -9,6 +9,7 @@ using namespace std;
#include <QMutex>
#include <QSize>
+#include "referencecounter.h"
#include "programinfo.h" // For RecStatusType
#include "inputinfo.h"
@@ -23,16 +24,13 @@ typedef enum {
kPBSEvents_SystemOnly = 3
} PlaybackSockEventsMode;
-class PlaybackSock
+class PlaybackSock : public ReferenceCounter
{
public:
PlaybackSock(MainServer *parent, MythSocket *lsock,
QString lhostname, PlaybackSockEventsMode eventsMode);
virtual ~PlaybackSock();
- void UpRef(void);
- bool DownRef(void);
-
void SetDisconnected(void) { disconnected = true; }
bool IsDisconnected(void) const { return disconnected; }
@@ -118,14 +116,11 @@ class PlaybackSock
bool backend;
bool mediaserver;
- QMutex refLock;
QMutex sockLock;
bool expectingreply;
bool disconnected;
- int refCount;
-
MainServer *m_parent;
};

0 comments on commit 6e490cd

Please sign in to comment.