Skip to content

Commit

Permalink
Refs #10311. Port UPNP code from RefCounted to ReferenceCounter.
Browse files Browse the repository at this point in the history
  • Loading branch information
daniel-kristjansson committed Jun 1, 2012
1 parent ca9086d commit 671017f
Show file tree
Hide file tree
Showing 13 changed files with 95 additions and 171 deletions.
29 changes: 14 additions & 15 deletions mythtv/libs/libmyth/backendselect.cpp
Expand Up @@ -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();
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -167,8 +165,6 @@ void BackendSelection::AddItem(DeviceLocation *dev)
}
else
m_mutex.unlock();

dev->Release();
}

/**
Expand Down Expand Up @@ -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();
}
}
}

Expand All @@ -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);
}

Expand Down Expand Up @@ -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"))
{
Expand Down
12 changes: 6 additions & 6 deletions mythtv/libs/libmyth/mythcontext.cpp
Expand Up @@ -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;
}
Expand Down Expand Up @@ -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;
Expand Down
2 changes: 2 additions & 0 deletions mythtv/libs/libmythupnp/eventing.cpp
Expand Up @@ -411,6 +411,8 @@ void Eventing::NotifySubscriber( SubscriberInfo *pInfo )

TaskQueue::Instance()->AddTask( 250, pEventTask );

pEventTask->DecrRef();

// ------------------------------------------------------------------
// Update the subscribers Key & last Notified fields
// ------------------------------------------------------------------
Expand Down
1 change: 0 additions & 1 deletion mythtv/libs/libmythupnp/httpserver.h
Expand Up @@ -33,7 +33,6 @@
#include "serverpool.h"
#include "httprequest.h"
#include "mthreadpool.h"
#include "refcounted.h"
#include "upnputil.h"
#include "compat.h"

Expand Down
74 changes: 0 additions & 74 deletions mythtv/libs/libmythupnp/refcounted.h

This file was deleted.

15 changes: 8 additions & 7 deletions mythtv/libs/libmythupnp/ssdp.cpp
Expand Up @@ -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++ )
{
Expand Down Expand Up @@ -154,12 +157,6 @@ void SSDP::EnableNotifications( int nServicePort )
"SSDP::EnableNotifications() - creating new task");
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.
// ------------------------------------------------------------------
Expand Down Expand Up @@ -505,6 +502,8 @@ bool SSDP::ProcessSearchRequest( const QStringMap &sHeaders,

TaskQueue::Instance()->AddTask( nNewMX, pTask );

pTask->DecrRef();

return true;
}

Expand All @@ -529,6 +528,8 @@ bool SSDP::ProcessSearchRequest( const QStringMap &sHeaders,

TaskQueue::Instance()->AddTask( nNewMX, pTask );

pTask->DecrRef();

return true;
}

Expand Down

0 comments on commit 671017f

Please sign in to comment.