File: resolver.h

package info (click to toggle)
sigx 2.0.2-3
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 1,144 kB
  • ctags: 1,311
  • sloc: cpp: 3,103; ansic: 653; xml: 206; python: 65; makefile: 26
file content (119 lines) | stat: -rw-r--r-- 2,977 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
#ifndef RESOLVERTHREAD_H
#define RESOLVERTHREAD_H

#include <sigxconfig.h>
#ifdef SIGC_MSC
#include <Winsock2.h>
// in_addr_t is not defined on windows
typedef ULONG in_addr_t;
#else
#include <netinet/in.h> // in_addr
#endif
#include <sigc++/functors/slot.h>
#include <glibmm/thread.h> // Glib::Private
#include <sigx/glib_threadable.h>
#include <sigx/request_f.h>
#include <sigx/signal_f.h>


/*	Resolves IP addresses to host names.
 *	
 *	IP addresses are resolved by using gethostbyaddr().
 *	You can feed the resolver with addresses by calling resolve(). Results
 *	are signaled after resolving with signal_resolved() to which you can 
 *	connect.
 *	@attention Do not use two IPResolverThreads but only one instance because 
 *	gethostbyaddr() might not be threadsafe on some systems.
 */
class IPResolverThread: public sigx::glib_threadable
{
public:
	// convenience sigc::slot typedefs
	typedef sigc::slot<void> slot_resolving_stopped_t;
	typedef sigc::slot<void> slot_finished_t;
	typedef sigc::slot<void, const std::string&, in_addr_t, int> slot_resolved_t;

protected:
	typedef sigc::signal<void> signal_resolving_stopped_t;
	typedef sigc::signal<void> signal_finished_t;
	typedef sigc::signal<void, const std::string&, in_addr_t, int /*error*/> signal_resolved_t;


public:
	IPResolverThread();


protected:
	// virtuals from sigx::glib_threadable
	virtual void on_startup();
	virtual void on_cleanup();

	/**	@short marshalls the resolving requests and optimizes them
	 *	@note handler for resolve.
	 */
	void on_marshall_resolving(in_addr_t nIP);

	/**	@short resolves an ip address to the hostname and emits a signal. @see signal_resolved
	 */
	bool resolve_next();

	/**	@short Resolves the specified ip address.
	 *	@return Resolving error.
	 */
	int resolve_this(in_addr addr);

	/**	@short stops resolving and emits signal_resolving_stopped() when stopped.
	 *	@note handler for stop_resolving().
	 */
	void on_stop_resolving();

public:
	/**	@name request interface
	 *	All the requests you can send to this thread.
	 */
	//@{
	/**	@short resolves the provided ip.
	 *	
	 *	the result is broadcast with signal_resolved().
	 *	
	 *	@note asynchronous
	 */
	sigx::request_f<in_addr_t> resolve;

	/**	@short stops resolving.
	 *	
	 *	broadcasts signal_resolving_stopped() when stopped.
	 *	
	 *	@note asynchronous
	 */
	sigx::request_f<> stop_resolving;
	//@}

	/**	@name signal interface
	 *	All the messages you can connect to.
	 */
	//@{
	/**	
	 *	@ingroup signal_api
	 */
	sigx::signal_f<signal_resolving_stopped_t> signal_resolving_stopped;

	/**	
	 *	@ingroup signal_api
	 */
	sigx::signal_f<signal_finished_t> signal_finished;

	/**	emitted if resolving ended, no matter whether successful or not.
	 *	host constains an emtpy string if not successful.
	 *	for type of signal and slot @see signal_resolved_t
	 */
	sigx::signal_f<signal_resolved_t> signal_resolved;
	//@}

	
private:
	struct ThreadData;
	Glib::Private<ThreadData> m_ThreadData;
};

#endif