fixed Avahi

This commit is contained in:
badaix 2016-10-16 15:04:13 +02:00
parent c6fcadfbd5
commit 7715f3bbd3
3 changed files with 13 additions and 15 deletions

View file

@ -19,7 +19,7 @@ endif
ifeq ($(TARGET), OPENWRT)
STRIP = echo
CXXFLAGS += -DNO_CPP11_STRING -pthread
CXXFLAGS += -DNO_CPP11_STRING -DHAS_AVAHI -pthread
LDFLAGS = -lvorbis -lvorbisenc -logg -lFLAC -lavahi-client -lavahi-common -latomic
OBJ += publishAvahi.o
@ -27,7 +27,7 @@ else ifeq ($(TARGET), FREEBSD)
CXX = /usr/local/bin/g++
STRIP = echo
CXXFLAGS += -DNO_CPP11_STRING -DFREEBSD -pthread
CXXFLAGS += -DNO_CPP11_STRING -DFREEBSD -DHAS_AVAHI -pthread
LDFLAGS = -lrt -lvorbis -lvorbisenc -logg -lFLAC -lavahi-client -lavahi-common -static-libgcc -static-libstdc++
OBJ += publishAvahi.o
@ -43,7 +43,7 @@ else
CXX = /usr/bin/g++
STRIP = strip
CXXFLAGS += -pthread
CXXFLAGS += -DHAS_AVAHI -pthread
LDFLAGS = -lrt -lvorbis -lvorbisenc -logg -lFLAC -lavahi-client -lavahi-common -static-libgcc -static-libstdc++
OBJ += publishAvahi.o

View file

@ -27,8 +27,8 @@ static AvahiEntryGroup *group;
static AvahiSimplePoll *simple_poll;
static char* name;
PublishAvahi::PublishAvahi(const std::string& serviceName) : PublishmDNS(serviceName)
client(NULL), active_(false)
PublishAvahi::PublishAvahi(const std::string& serviceName) : PublishmDNS(serviceName),
client_(NULL), active_(false)
{
group = NULL;
simple_poll = NULL;
@ -40,9 +40,6 @@ void PublishAvahi::publish(const std::vector<mDNSService>& services)
{
this->services = services;
AvahiClient *client = NULL;
int error;
/* Allocate main loop object */
if (!(simple_poll = avahi_simple_poll_new()))
{
@ -50,10 +47,11 @@ void PublishAvahi::publish(const std::vector<mDNSService>& services)
}
/* Allocate a new client */
client = avahi_client_new(avahi_simple_poll_get(simple_poll), AVAHI_CLIENT_IGNORE_USER_CONFIG, client_callback, this, &error);
int error;
client_ = avahi_client_new(avahi_simple_poll_get(simple_poll), AVAHI_CLIENT_IGNORE_USER_CONFIG, client_callback, this, &error);
/* Check wether creating the client object succeeded */
if (!client)
if (!client_)
{
logE << "Failed to create client: " << avahi_strerror(error) << "\n";
}
@ -74,8 +72,8 @@ PublishAvahi::~PublishAvahi()
active_ = false;
pollThread_.join();
if (client)
avahi_client_free(client);
if (client_)
avahi_client_free(client_);
if (simple_poll)
avahi_simple_poll_free(simple_poll);
@ -174,7 +172,7 @@ void PublishAvahi::create_services(AvahiClient *c)
/* Add the same service for BSD LPR */
for (size_t n=0; n<services.size(); ++n)
{
if ((ret = avahi_entry_group_add_service(group, AVAHI_IF_UNSPEC, services[n].proto_, AvahiPublishFlags(0), name, services[n].name_.c_str(), NULL, NULL, services[n].port_, NULL)) < 0)
if ((ret = avahi_entry_group_add_service(group, AVAHI_IF_UNSPEC, AVAHI_PROTO_UNSPEC, AvahiPublishFlags(0), name, services[n].name_.c_str(), NULL, NULL, services[n].port_, NULL)) < 0)
{
if (ret == AVAHI_ERR_COLLISION)

View file

@ -48,9 +48,9 @@ private:
static void entry_group_callback(AvahiEntryGroup *g, AvahiEntryGroupState state, AVAHI_GCC_UNUSED void *userdata);
static void client_callback(AvahiClient *c, AvahiClientState state, AVAHI_GCC_UNUSED void * userdata);
void create_services(AvahiClient *c);
AvahiClient* client;
std::thread pollThread_;
void worker();
AvahiClient* client_;
std::thread pollThread_;
std::atomic<bool> active_;
std::vector<mDNSService> services;
};