Permalink
Browse files

Refs #10311. Port UPNP code from RefCounted to ReferenceCounter.

  • Loading branch information...
1 parent ca9086d commit 671017faca19fc71253f6db119414ec59fb829df @daniel-kristjansson daniel-kristjansson committed May 31, 2012
@@ -28,10 +28,8 @@ BackendSelection::~BackendSelection()
ItemMap::iterator it;
for (it = m_devices.begin(); it != m_devices.end(); ++it)
{
- DeviceLocation *dev = *it;
-
- if (dev)
- dev->Release();
+ if (*it)
+ (*it)->DecrRef();
}
m_devices.clear();
@@ -132,7 +130,7 @@ void BackendSelection::AddItem(DeviceLocation *dev)
// The devices' USN should be unique. Don't add if it is already there:
if (m_devices.find(USN) == m_devices.end())
{
- dev->AddRef();
+ dev->IncrRef();
m_devices.insert(USN, dev);
m_mutex.unlock();
@@ -167,8 +165,6 @@ void BackendSelection::AddItem(DeviceLocation *dev)
}
else
m_mutex.unlock();
-
- dev->Release();
}
/**
@@ -246,11 +242,14 @@ void BackendSelection::Init(void)
{
EntryMap ourMap;
pEntries->GetEntryMap(ourMap);
- pEntries->Release();
+ pEntries->DecrRef();
EntryMap::const_iterator it;
for (it = ourMap.begin(); it != ourMap.end(); ++it)
- AddItem(*it); // this does an (*it)->Release()
+ {
+ AddItem(*it);
+ (*it)->DecrRef();
+ }
}
}
@@ -267,11 +266,8 @@ void BackendSelection::RemoveItem(QString USN)
if (it != m_devices.end())
{
- DeviceLocation *dev = *it;
-
- if (dev)
- dev->Release();
-
+ if (*it)
+ (*it)->DecrRef();
m_devices.erase(it);
}
@@ -312,7 +308,10 @@ void BackendSelection::customEvent(QEvent *event)
{
DeviceLocation *devLoc = SSDP::Instance()->Find(URI, URN);
if (devLoc)
- AddItem(devLoc); // this does a Release()
+ {
+ AddItem(devLoc);
+ devLoc->DecrRef();
+ }
}
else if (message.startsWith("SSDP_REMOVE"))
{
@@ -835,19 +835,20 @@ int MythContextPrivate::UPnPautoconf(const int milliSeconds)
if (count != 1)
{
- backends->Release();
+ backends->DecrRef();
return count;
}
// Get this backend's location:
DeviceLocation *BE = backends->GetFirst();
- backends->Release();
+ backends->DecrRef();
+ backends = NULL;
// We don't actually know the backend's access PIN, so this will
// only work for ones that have PIN access disabled (i.e. 0000)
int ret = (UPnPconnect(BE, QString::null)) ? 1 : -1;
- BE->Release();
+ BE->DecrRef();
return ret;
}
@@ -915,12 +916,11 @@ bool MythContextPrivate::DefaultUPnP(QString &error)
if (UPnPconnect(pDevLoc, PIN))
{
- pDevLoc->Release();
-
+ pDevLoc->DecrRef();
return true;
}
- pDevLoc->Release();
+ pDevLoc->DecrRef();
error = "Cannot connect to default backend via UPnP. Wrong saved PIN?";
return false;
@@ -411,6 +411,8 @@ void Eventing::NotifySubscriber( SubscriberInfo *pInfo )
TaskQueue::Instance()->AddTask( 250, pEventTask );
+ pEventTask->DecrRef();
+
// ------------------------------------------------------------------
// Update the subscribers Key & last Notified fields
// ------------------------------------------------------------------
@@ -33,7 +33,6 @@
#include "serverpool.h"
#include "httprequest.h"
#include "mthreadpool.h"
-#include "refcounted.h"
#include "upnputil.h"
#include "compat.h"
@@ -1,74 +0,0 @@
-//////////////////////////////////////////////////////////////////////////////
-// Program Name: refcounted.h
-// Created : Oct. 21, 2005
-//
-// Purpose : Reference Counted Base Class
-//
-// Copyright (c) 2005 David Blain <dblain@mythtv.org>
-//
-// Licensed under the GPL v2 or later, see COPYING for details
-//
-//////////////////////////////////////////////////////////////////////////////
-
-#ifndef __REFCOUNTED_H__
-#define __REFCOUNTED_H__
-
-#include <QMutex>
-
-/////////////////////////////////////////////////////////////////////////////
-/////////////////////////////////////////////////////////////////////////////
-//
-// RefCounted Class Definition/Implementation
-//
-/////////////////////////////////////////////////////////////////////////////
-/////////////////////////////////////////////////////////////////////////////
-
-class RefCounted
-{
- protected:
-
- long m_nRefCount;
- QMutex m_mutex;
-
- protected:
-
- // Destructor protected to force use of release;
-
- virtual ~RefCounted() {};
-
- public:
-
- // ------------------------------------------------------------------
-
- RefCounted() : m_nRefCount( 0 )
- {
- }
-
- // ------------------------------------------------------------------
-
- long AddRef()
- {
- m_mutex.lock();
- long nRef = (++m_nRefCount);
- m_mutex.unlock();
-
- return( nRef );
- }
-
- // ------------------------------------------------------------------
-
- long Release()
- {
-
- m_mutex.lock();
- long nRef = (--m_nRefCount);
- m_mutex.unlock();
-
- if (nRef <= 0)
- delete this;
-
- return( nRef );
- }
-};
-
-#endif
@@ -122,7 +122,10 @@ SSDP::~SSDP()
wait();
if (m_pNotifyTask != NULL)
- m_pNotifyTask->Release();
+ {
+ m_pNotifyTask->DecrRef();
+ m_pNotifyTask = NULL;
+ }
for (int nIdx = 0; nIdx < (int)NumberOfSockets; nIdx++ )
{
@@ -155,12 +158,6 @@ void SSDP::EnableNotifications( int nServicePort )
m_pNotifyTask = new UPnpNotifyTask( m_nServicePort );
// ------------------------------------------------------------------
- // Let's make sure to hold on to a reference of the NotifyTask.
- // ------------------------------------------------------------------
-
- m_pNotifyTask->AddRef();
-
- // ------------------------------------------------------------------
// First Send out Notification that we are leaving the network.
// ------------------------------------------------------------------
@@ -505,6 +502,8 @@ bool SSDP::ProcessSearchRequest( const QStringMap &sHeaders,
TaskQueue::Instance()->AddTask( nNewMX, pTask );
+ pTask->DecrRef();
+
return true;
}
@@ -529,6 +528,8 @@ bool SSDP::ProcessSearchRequest( const QStringMap &sHeaders,
TaskQueue::Instance()->AddTask( nNewMX, pTask );
+ pTask->DecrRef();
+
return true;
}
Oops, something went wrong.

0 comments on commit 671017f

Please sign in to comment.