Skip to content

Commit

Permalink
changed: start zeroconf publishing via a job. speeds up XBMC startup …
Browse files Browse the repository at this point in the history
…a little
  • Loading branch information
WiSo committed Jan 28, 2012
1 parent 23a17db commit dbac078
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 4 deletions.
29 changes: 25 additions & 4 deletions xbmc/network/Zeroconf.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
#include "threads/CriticalSection.h"
#include "threads/SingleLock.h"
#include "threads/Atomics.h"
#include "utils/JobManager.h"

#ifndef HAS_ZEROCONF
//dummy implementation used if no zeroconf is present
Expand Down Expand Up @@ -76,7 +77,10 @@ bool CZeroconf::PublishService(const std::string& fcr_identifier,
if(!ret.second) //identifier exists
return false;
if(m_started)
return doPublishService(fcr_identifier, fcr_type, fcr_name, f_port, txt);
{
CPublish* publish = new CPublish(fcr_identifier, info);
CJobManager::GetInstance().AddJob(publish, NULL);
}
//not yet started, so its just queued
return true;
}
Expand Down Expand Up @@ -112,9 +116,9 @@ void CZeroconf::Start()
if(m_started)
return;
m_started = true;
for(tServiceMap::const_iterator it = m_service_map.begin(); it != m_service_map.end(); ++it){
doPublishService(it->first, it->second.type, it->second.name, it->second.port, it->second.txt);
}

CPublish* publish = new CPublish(m_service_map);
CJobManager::GetInstance().AddJob(publish, NULL);
}

void CZeroconf::Stop()
Expand Down Expand Up @@ -154,3 +158,20 @@ void CZeroconf::ReleaseInstance()
smp_instance = 0;
}

CZeroconf::CPublish::CPublish(const std::string& fcr_identifier, PublishInfo& pubinfo)
{
m_servmap.insert(std::make_pair(fcr_identifier, pubinfo));
}

CZeroconf::CPublish::CPublish(tServiceMap& servmap)
{
m_servmap = servmap;
}

bool CZeroconf::CPublish::DoWork()
{
for(tServiceMap::const_iterator it = m_servmap.begin(); it != m_servmap.end(); ++it)
CZeroconf::GetInstance()->doPublishService(it->first, it->second.type, it->second.name, it->second.port, it->second.txt);

return true;
}
13 changes: 13 additions & 0 deletions xbmc/network/Zeroconf.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@

#include <string>
#include <map>
#include "utils/Job.h"

class CCriticalSection;
/// this class provides support for zeroconf
Expand Down Expand Up @@ -117,4 +118,16 @@ class CZeroconf
//protects singleton creation/destruction
static long sm_singleton_guard;
static CZeroconf* smp_instance;

class CPublish : public CJob
{
public:
CPublish(const std::string& fcr_identifier, PublishInfo& pubinfo);
CPublish(tServiceMap& servmap);

bool DoWork();

private:
tServiceMap m_servmap;
};
};

0 comments on commit dbac078

Please sign in to comment.