added Avahi Zeroconf

This commit is contained in:
badaix 2015-02-19 22:35:35 +01:00
parent af7f230e97
commit e8ffa1f243
10 changed files with 302 additions and 133 deletions

View file

@ -10,21 +10,40 @@
#include <avahi-common/error.h>
#include <avahi-common/timeval.h>
#include <string>
#include <vector>
#include <thread>
#include <atomic>
struct AvahiService
{
AvahiService(const std::string& name, size_t port, int proto = AVAHI_PROTO_UNSPEC) : name_(name), port_(port), proto_(proto)
{
}
std::string name_;
size_t port_;
int proto_;
};
class PublishAvahi
{
public:
PublishAvahi();
PublishAvahi(const std::string& serviceName);
~PublishAvahi();
private:
void entry_group_callback(AvahiEntryGroup *g, AvahiEntryGroupState state, AVAHI_GCC_UNUSED void *userdata);
void create_services(AvahiClient *c);
void client_callback(AvahiClient *c, AvahiClientState state, AVAHI_GCC_UNUSED void * userdata);
void publish(const std::vector<AvahiService>& services);
std::vector<AvahiService> services;
AvahiEntryGroup *group;
AvahiSimplePoll *simple_poll;
char* name;
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::string serviceName_;
std::thread pollThread_;
void worker();
std::atomic<bool> active_;
};