};
}
-CZeroconfBrowserAvahi::CZeroconfBrowserAvahi() : mp_client ( 0 ), mp_poll ( 0 ), m_shutdown(false), m_thread_id(0)
+CZeroconfBrowserAvahi::CZeroconfBrowserAvahi() : mp_client ( 0 ), mp_poll ( 0 )
{
if ( ! ( mp_poll = avahi_threaded_poll_new() ) )
{
CLog::Log ( LOGDEBUG, "CZeroconfAvahi::~CZeroconfAvahi() Going down! cleaning up..." );
if ( mp_poll )
{
- //normally we would stop the avahi thread here and do our work, but
- //it looks like this does not work -> www.avahi.org/ticket/251
- //so instead of calling
- //avahi_threaded_poll_stop(mp_poll);
- //we set m_shutdown=true, post an event and wait for it to stop itself
- struct timeval tv = { 0, 0 }; //TODO: does tv survive the thread?
- AvahiTimeout* lp_timeout;
- {
- ScopedEventLoopBlock l_block(mp_poll);
- const AvahiPoll* cp_apoll = avahi_threaded_poll_get(mp_poll);
- m_shutdown = true;
- lp_timeout = cp_apoll->timeout_new(cp_apoll,
- &tv,
- shutdownCallback,
- this);
- }
-
- //now wait for the thread to stop
- assert(m_thread_id);
- pthread_join(m_thread_id, NULL);
- avahi_threaded_poll_get(mp_poll)->timeout_free(lp_timeout);
+ //stop avahi polling thread
+ avahi_threaded_poll_stop(mp_poll);
}
//free the client (frees all browsers, groups, ...)
if ( mp_client )
void CZeroconfBrowserAvahi::clientCallback ( AvahiClient* fp_client, AvahiClientState f_state, void* fp_data )
{
CZeroconfBrowserAvahi* p_instance = static_cast<CZeroconfBrowserAvahi*> ( fp_data );
-
- //store our thread ID and check for shutdown -> check details in destructor
- p_instance->m_thread_id = pthread_self();
- if (p_instance->m_shutdown)
- {
- avahi_threaded_poll_quit(p_instance->mp_poll);
- return;
- }
-
switch ( f_state )
{
case AVAHI_CLIENT_S_RUNNING:
return ret;
}
-
-void CZeroconfBrowserAvahi::shutdownCallback(AvahiTimeout *fp_e, void *fp_data)
-{
- CZeroconfBrowserAvahi* p_instance = static_cast<CZeroconfBrowserAvahi*>(fp_data);
- //should only be called on shutdown
- if (p_instance->m_shutdown)
- {
- avahi_threaded_poll_quit(p_instance->mp_poll);
- }
-}
-
#endif //HAS_AVAHI
AvahiStringList *txt,
AvahiLookupResultFlags flags,
AVAHI_GCC_UNUSED void* userdata);
- //helper to workaround avahi bug
- static void shutdownCallback(AvahiTimeout *fp_e, void *fp_data);
//helpers
bool createClient();
static AvahiServiceBrowser* createServiceBrowser(const std::string& fcr_service_type, AvahiClient* fp_client, void* fp_userdata);
tDiscoveredServices m_discovered_services;
CZeroconfBrowser::ZeroconfService m_resolving_service;
CEvent m_resolved_event;
-
- //2 variables below are needed for workaround of avahi bug (see destructor for details)
- bool m_shutdown;
- pthread_t m_thread_id;
};
#endif //HAS_AVAHI