Fawkes API Fawkes Development Version
resolver_thread.h
1
2/***************************************************************************
3 * resolver_thread.h - Fawkes network name resolver thread
4 *
5 * Created: Fri May 11 22:10:03 2007
6 * Copyright 2006-2007 Tim Niemueller [www.niemueller.de]
7 *
8 ****************************************************************************/
9
10/* This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version. A runtime exception applies to
14 * this software (see LICENSE.GPL_WRE file mentioned below for details).
15 *
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU Library General Public License for more details.
20 *
21 * Read the full text in the LICENSE.GPL_WRE file in the doc directory.
22 */
23
24#ifndef _NETCOMM_UTILS_RESOLVER_THREAD_H_
25#define _NETCOMM_UTILS_RESOLVER_THREAD_H_
26
27#include <core/threading/thread.h>
28#include <core/utils/lock_hashmap.h>
29#include <core/utils/lock_hashset.h>
30#include <utils/misc/string_compare.h>
31#ifdef HAVE_AVAHI
32# include <netcomm/dns-sd/avahi_resolver_handler.h>
33#endif
34#include <netinet/in.h>
35#include <sys/socket.h>
36
37#include <cstddef>
38#include <list>
39#include <map>
40#include <stdint.h>
41#include <string>
42#include <utility>
43
44namespace fawkes {
45
46class AvahiThread;
47class NetworkNameResolver;
48class Mutex;
49
50#ifdef HAVE_AVAHI
51class NetworkNameResolverThread : public Thread, public AvahiResolverHandler
52#else
54#endif
55{
56public:
57 NetworkNameResolverThread(NetworkNameResolver *resolver, AvahiThread *avahi_thread = NULL);
59
60 void resolve_name(const std::string &name);
61 void resolve_address(struct sockaddr *addr, socklen_t addrlen);
62
63 bool
64 resolve_name_immediately(const std::string &name, struct sockaddr **addr, socklen_t *addr_len);
65 bool resolve_address_immediately(struct sockaddr *addr, std::string &name, bool &namefound);
66
67 virtual void resolved_name(char *name, struct sockaddr *addr, socklen_t addrlen);
68 virtual void resolved_address(struct sockaddr *addr, socklen_t addrlen, char *name);
69 virtual void name_resolution_failed(char *name);
70 virtual void address_resolution_failed(struct sockaddr *addr, socklen_t addrlen);
71
72 virtual void loop();
73
74 /** Stub to see name in backtrace for easier debugging. @see Thread::run() */
75protected:
76 virtual void
78 {
80 }
81
82private:
83 NetworkNameResolver *resolver_;
84#ifdef HAVE_AVAHI
85 AvahiThread *avahi_thread_;
86#endif
87
88 Mutex * namesq_mutex_;
89 unsigned int namesq_active_;
90 typedef LockHashSet<std::string> NamesQMap;
91 NamesQMap namesqs_[2];
92 NamesQMap * namesq_;
93 NamesQMap * namesq_proc_;
94
95 Mutex * addrq_mutex_;
96 unsigned int addrq_active_;
97 typedef std::list<struct sockaddr *> AddrQList;
98 AddrQList addrqs_[2];
99 AddrQList * addrq_;
100 AddrQList * addrq_proc_;
101};
102
103} // end namespace fawkes
104
105#endif
Avahi main thread.
Definition: avahi_thread.h:55
Mutex mutual exclusion lock.
Definition: mutex.h:33
Worker thread for NetworkNameResolver.
virtual void address_resolution_failed(struct sockaddr *addr, socklen_t addrlen)
Address resolution failed.
bool resolve_name_immediately(const std::string &name, struct sockaddr **addr, socklen_t *addr_len)
Immediately resolve a name.
void resolve_name(const std::string &name)
Enqueue name for resolution.
void resolve_address(struct sockaddr *addr, socklen_t addrlen)
Enqueue address for resolution.
virtual void loop()
Thread loop.
virtual void name_resolution_failed(char *name)
Name resolution failed.
NetworkNameResolverThread(NetworkNameResolver *resolver, AvahiThread *avahi_thread=NULL)
Constructor.
virtual void run()
Stub to see name in backtrace for easier debugging.
virtual void resolved_name(char *name, struct sockaddr *addr, socklen_t addrlen)
Name has been successfully resolved.
bool resolve_address_immediately(struct sockaddr *addr, std::string &name, bool &namefound)
Immediately resolve address.
virtual void resolved_address(struct sockaddr *addr, socklen_t addrlen, char *name)
Address has been successfully resolved.
Network name and address resolver.
Definition: resolver.h:45
Thread class encapsulation of pthreads.
Definition: thread.h:46
const char * name() const
Get name of thread.
Definition: thread.h:100
virtual void run()
Code to execute in the thread.
Definition: thread.cpp:918
Fawkes library namespace.