1/*
2 * Copyright 2003-2005, Haiku Inc.
3 * Distributed under the terms of the MIT License.
4 */
5
6#ifndef _PPP_INTERFACE_LISTENER__H
7#define _PPP_INTERFACE_LISTENER__H
8
9#include <PPPManager.h>
10#include <Locker.h>
11
12class BHandler;
13
14
15#define PPP_REPORT_MESSAGE	'P3RM'
16	//!< The what field of PPPInterfaceListener report messages.
17
18
19class PPPInterfaceListener {
20	public:
21		PPPInterfaceListener(BHandler *target);
22		PPPInterfaceListener(const PPPInterfaceListener& copy);
23		~PPPInterfaceListener();
24
25		status_t InitCheck() const;
26
27		//!	Returns the target BHandler for the report messages.
28		BHandler *Target() const
29			{ return fTarget; }
30		void SetTarget(BHandler *target);
31
32		//!	Returns whether the listener is watching an interface.
33		bool IsWatching() const
34			{ return fIsWatching; }
35		//!	Returns which interface is being watched or \c PPP_UNDEFINED_INTERFACE_ID.
36		ppp_interface_id Interface() const
37			{ return fInterface; }
38
39		//!	Returns the internal PPPManager object used for accessing the PPP stack.
40		const PPPManager& Manager() const
41			{ return fManager; }
42
43		bool WatchInterface(ppp_interface_id ID);
44		void WatchManager();
45		void StopWatchingInterface();
46		void StopWatchingManager();
47
48		//!	Just sets the target to the given listener's target.
49		PPPInterfaceListener& operator= (const PPPInterfaceListener& copy)
50			{ SetTarget(copy.Target()); return *this; }
51
52	private:
53		void Construct();
54
55	private:
56		BHandler *fTarget;
57		thread_id fReportThread;
58
59		bool fIsWatching;
60		ppp_interface_id fInterface;
61
62		PPPManager fManager;
63};
64
65
66#endif
67