mirror of
https://github.com/badaix/snapcast.git
synced 2025-04-29 02:07:55 +02:00
56 lines
2 KiB
C++
56 lines
2 KiB
C++
/***
|
|
This file is part of snapcast
|
|
Copyright (C) 2015 Johannes Pohl
|
|
|
|
This program is free software: you can redistribute it and/or modify
|
|
it under the terms of the GNU General Public License as published by
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
(at your option) any later version.
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
GNU General Public License for more details.
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
***/
|
|
|
|
#include <avahi-client/client.h>
|
|
#include <avahi-client/lookup.h>
|
|
|
|
#include <avahi-common/simple-watch.h>
|
|
#include <avahi-common/malloc.h>
|
|
#include <avahi-common/error.h>
|
|
|
|
#include <string>
|
|
|
|
|
|
struct AvahiResult
|
|
{
|
|
int proto_;
|
|
std::string ip_;
|
|
std::string host_;
|
|
size_t port_;
|
|
bool valid_;
|
|
};
|
|
|
|
|
|
class BrowseAvahi
|
|
{
|
|
public:
|
|
BrowseAvahi();
|
|
~BrowseAvahi();
|
|
bool browse(const std::string& serviceName, int proto, AvahiResult& result, int timeout);
|
|
|
|
private:
|
|
void cleanUp();
|
|
static void resolve_callback(AvahiServiceResolver *r, AVAHI_GCC_UNUSED AvahiIfIndex interface, AVAHI_GCC_UNUSED AvahiProtocol protocol, AvahiResolverEvent event, const char *name, const char *type, const char *domain, const char *host_name, const AvahiAddress *address, uint16_t port, AvahiStringList *txt, AvahiLookupResultFlags flags, AVAHI_GCC_UNUSED void* userdata);
|
|
static void browse_callback(AvahiServiceBrowser *b, AvahiIfIndex interface, AvahiProtocol protocol, AvahiBrowserEvent event, const char *name, const char *type, const char *domain, AVAHI_GCC_UNUSED AvahiLookupResultFlags flags, void* userdata);
|
|
static void client_callback(AvahiClient *c, AvahiClientState state, AVAHI_GCC_UNUSED void * userdata);
|
|
AvahiClient* client_;
|
|
AvahiResult result_;
|
|
AvahiServiceBrowser* sb_;
|
|
};
|
|
|
|
|