zeroconf/avahi/Poll: move to namespace Avahi

This commit is contained in:
Max Kellermann 2021-02-23 21:39:03 +01:00
parent 1ac16516a1
commit 07865d0707
3 changed files with 22 additions and 13 deletions

View File

@ -36,7 +36,7 @@
static constexpr Domain avahi_domain("avahi"); static constexpr Domain avahi_domain("avahi");
static char *avahi_name; static char *avahi_name;
static MyAvahiPoll *avahi_poll; static Avahi::Poll *avahi_poll;
static AvahiClient *avahi_client; static AvahiClient *avahi_client;
static AvahiEntryGroup *avahi_group; static AvahiEntryGroup *avahi_group;
@ -241,7 +241,7 @@ AvahiInit(EventLoop &loop, const char *serviceName)
avahi_name = avahi_strdup(serviceName); avahi_name = avahi_strdup(serviceName);
avahi_poll = new MyAvahiPoll(loop); avahi_poll = new Avahi::Poll(loop);
int error; int error;
avahi_client = avahi_client_new(avahi_poll, AVAHI_CLIENT_NO_FAIL, avahi_client = avahi_client_new(avahi_poll, AVAHI_CLIENT_NO_FAIL,

View File

@ -39,6 +39,7 @@ ToAvahiWatchEvent(unsigned e) noexcept
} }
struct AvahiWatch final { struct AvahiWatch final {
private:
SocketEvent event; SocketEvent event;
const AvahiWatchCallback callback; const AvahiWatchCallback callback;
@ -109,7 +110,9 @@ private:
} }
}; };
MyAvahiPoll::MyAvahiPoll(EventLoop &_loop) noexcept namespace Avahi {
Poll::Poll(EventLoop &_loop) noexcept
:event_loop(_loop) :event_loop(_loop)
{ {
watch_new = WatchNew; watch_new = WatchNew;
@ -122,20 +125,22 @@ MyAvahiPoll::MyAvahiPoll(EventLoop &_loop) noexcept
} }
AvahiWatch * AvahiWatch *
MyAvahiPoll::WatchNew(const AvahiPoll *api, int fd, AvahiWatchEvent event, Poll::WatchNew(const AvahiPoll *api, int fd, AvahiWatchEvent event,
AvahiWatchCallback callback, void *userdata) noexcept AvahiWatchCallback callback, void *userdata) noexcept
{ {
const MyAvahiPoll &poll = *(const MyAvahiPoll *)api; const Poll &poll = *(const Poll *)api;
return new AvahiWatch(poll.event_loop, SocketDescriptor(fd), event, return new AvahiWatch(poll.event_loop, SocketDescriptor(fd), event,
callback, userdata); callback, userdata);
} }
AvahiTimeout * AvahiTimeout *
MyAvahiPoll::TimeoutNew(const AvahiPoll *api, const struct timeval *tv, Poll::TimeoutNew(const AvahiPoll *api, const struct timeval *tv,
AvahiTimeoutCallback callback, void *userdata) noexcept AvahiTimeoutCallback callback, void *userdata) noexcept
{ {
const MyAvahiPoll &poll = *(const MyAvahiPoll *)api; const Poll &poll = *(const Poll *)api;
return new AvahiTimeout(poll.event_loop, tv, callback, userdata); return new AvahiTimeout(poll.event_loop, tv, callback, userdata);
} }
} // namespace Avahi

View File

@ -24,14 +24,16 @@
class EventLoop; class EventLoop;
class MyAvahiPoll final : public AvahiPoll { namespace Avahi {
class Poll final : public AvahiPoll {
EventLoop &event_loop; EventLoop &event_loop;
public: public:
explicit MyAvahiPoll(EventLoop &_loop) noexcept; explicit Poll(EventLoop &_loop) noexcept;
MyAvahiPoll(const MyAvahiPoll &) = delete; Poll(const Poll &) = delete;
MyAvahiPoll &operator=(const MyAvahiPoll &) = delete; Poll &operator=(const Poll &) = delete;
EventLoop &GetEventLoop() const noexcept { EventLoop &GetEventLoop() const noexcept {
return event_loop; return event_loop;
@ -49,4 +51,6 @@ private:
void *userdata) noexcept; void *userdata) noexcept;
}; };
} // namespace Avahi
#endif #endif