184b580c4SWaldemar Kornewald/*
2abdb7d1aSWaldemar Kornewald * Copyright 2003-2005, Haiku Inc.
384b580c4SWaldemar Kornewald * Distributed under the terms of the MIT License.
484b580c4SWaldemar Kornewald */
520d09e03SWaldemar Kornewald
620d09e03SWaldemar Kornewald#ifndef _PPP_INTERFACE_LISTENER__H
720d09e03SWaldemar Kornewald#define _PPP_INTERFACE_LISTENER__H
820d09e03SWaldemar Kornewald
920d09e03SWaldemar Kornewald#include <PPPManager.h>
1020d09e03SWaldemar Kornewald#include <Locker.h>
1120d09e03SWaldemar Kornewald
1220d09e03SWaldemar Kornewaldclass BHandler;
1320d09e03SWaldemar Kornewald
1420d09e03SWaldemar Kornewald
1520d09e03SWaldemar Kornewald#define PPP_REPORT_MESSAGE	'P3RM'
163f3689bbSWaldemar Kornewald	//!< The what field of PPPInterfaceListener report messages.
1720d09e03SWaldemar Kornewald
1820d09e03SWaldemar Kornewald
1920d09e03SWaldemar Kornewaldclass PPPInterfaceListener {
2020d09e03SWaldemar Kornewald	public:
2120d09e03SWaldemar Kornewald		PPPInterfaceListener(BHandler *target);
2220d09e03SWaldemar Kornewald		PPPInterfaceListener(const PPPInterfaceListener& copy);
2320d09e03SWaldemar Kornewald		~PPPInterfaceListener();
2420d09e03SWaldemar Kornewald
2520d09e03SWaldemar Kornewald		status_t InitCheck() const;
2620d09e03SWaldemar Kornewald
273f3689bbSWaldemar Kornewald		//!	Returns the target BHandler for the report messages.
2820d09e03SWaldemar Kornewald		BHandler *Target() const
2920d09e03SWaldemar Kornewald			{ return fTarget; }
3020d09e03SWaldemar Kornewald		void SetTarget(BHandler *target);
3120d09e03SWaldemar Kornewald
32abdb7d1aSWaldemar Kornewald		//!	Returns whether the listener is watching an interface.
33abdb7d1aSWaldemar Kornewald		bool IsWatching() const
34abdb7d1aSWaldemar Kornewald			{ return fIsWatching; }
353f3689bbSWaldemar Kornewald		//!	Returns which interface is being watched or \c PPP_UNDEFINED_INTERFACE_ID.
36abdb7d1aSWaldemar Kornewald		ppp_interface_id Interface() const
37abdb7d1aSWaldemar Kornewald			{ return fInterface; }
386cfb4dcaSWaldemar Kornewald
393f3689bbSWaldemar Kornewald		//!	Returns the internal PPPManager object used for accessing the PPP stack.
406cfb4dcaSWaldemar Kornewald		const PPPManager& Manager() const
416cfb4dcaSWaldemar Kornewald			{ return fManager; }
426cfb4dcaSWaldemar Kornewald
435a483e4dSWaldemar Kornewald		bool WatchInterface(ppp_interface_id ID);
44abdb7d1aSWaldemar Kornewald		void WatchManager();
45abdb7d1aSWaldemar Kornewald		void StopWatchingInterface();
46abdb7d1aSWaldemar Kornewald		void StopWatchingManager();
4720d09e03SWaldemar Kornewald
483f3689bbSWaldemar Kornewald		//!	Just sets the target to the given listener's target.
4920d09e03SWaldemar Kornewald		PPPInterfaceListener& operator= (const PPPInterfaceListener& copy)
5020d09e03SWaldemar Kornewald			{ SetTarget(copy.Target()); return *this; }
5120d09e03SWaldemar Kornewald
5220d09e03SWaldemar Kornewald	private:
5320d09e03SWaldemar Kornewald		void Construct();
5420d09e03SWaldemar Kornewald
5520d09e03SWaldemar Kornewald	private:
5620d09e03SWaldemar Kornewald		BHandler *fTarget;
5720d09e03SWaldemar Kornewald		thread_id fReportThread;
5820d09e03SWaldemar Kornewald
59abdb7d1aSWaldemar Kornewald		bool fIsWatching;
60abdb7d1aSWaldemar Kornewald		ppp_interface_id fInterface;
616cfb4dcaSWaldemar Kornewald
6220d09e03SWaldemar Kornewald		PPPManager fManager;
6320d09e03SWaldemar Kornewald};
6420d09e03SWaldemar Kornewald
6520d09e03SWaldemar Kornewald
6620d09e03SWaldemar Kornewald#endif
67