//TODO: ServiceEvent should be RemoteService and ServiceDescription
void ServiceDiscovery::addedService(const RemoteService& service)
{
        ServiceEvent event(service);
        ServiceConfiguration remoteConfig = service.getConfiguration();

        if(mLocalService && mMode == PUBLISH)
        {
            ServiceConfiguration localConfig = mLocalService->getConfiguration();

            if ( localConfig.getName() == remoteConfig.getName() && localConfig.getType() == remoteConfig.getType())
            {
                LOG_INFO("Service published: %s", service.getName().c_str());
                mPublished = true;
            }
        }

        {
            boost::unique_lock<boost::mutex> lock(mServicesMutex);
            ServiceDescription configuration = service.getConfiguration();
            LOG_INFO("+ %s type: %s", configuration.getName().c_str(), configuration.getType().c_str());
            mServices.push_back( configuration );
        }

        {
            boost::unique_lock<boost::mutex> lock(mAddedComponentMutex);
            ServiceAddedSignal.emit( event );
        }
}
void ServiceDiscovery::removedService(const RemoteService& service)
{
	ServiceEvent event(service);
	ServiceDescription serviceDescription = event.getServiceConfiguration(); 

	boost::unique_lock<boost::mutex> lock(mServicesMutex);
	List<ServiceDescription>::iterator it = mServices.find(serviceDescription);

	if (it != mServices.end())	
	{
		{
			boost::unique_lock<boost::mutex> removalLock(mRemovedComponentMutex);
			ServiceDescription configuration = *it;
			LOG_INFO("- %s type: %s", configuration.getName().c_str(), configuration.getType().c_str());
			ServiceRemovedSignal.emit( event );
		}

		mServices.erase(it);
	}
}
bool ServiceDescription::compareWithoutTXT(const ServiceDescription& other) const 
{
        if( interfaceIndex_ != other.getInterfaceIndex() && !(interfaceIndex_ == AVAHI_IF_UNSPEC || other.getInterfaceIndex() == AVAHI_IF_UNSPEC))
            return false;

        if(protocol_ != other.getProtocol() && !(protocol_ == AVAHI_PROTO_UNSPEC || other.getProtocol() == AVAHI_PROTO_UNSPEC))
            return false;

        if( getName() != other.getName())
            return false;

        if( getType() != other.getType())
            return false;

        // Compare domains and ignore consider that "" defaults to 'local'
	std::string td1 = (domain_ == "" || domain_ == "local") ? "" : domain_;
	std::string td2 = (other.getDomain() == "" || other.getDomain() == "local") ? "" : other.getDomain();

	if (td1 != td2)
		return false;

        return true;
}