summaryrefslogtreecommitdiffstats
path: root/krfb/srvloc/kinetinterfacewatcher.h
blob: 95ddb3d914f3ed03cfbfbc1a4b1185616983bfaf (plain)
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
120
121
122
123
/*
 *  Watches Inet interfaces
 *  Copyright (C) 2002 Tim Jansen <[email protected]>
 *
 *  $Id$
 *
 *  This library is free software; you can redistribute it and/or
 *  modify it under the terms of the GNU Library General Public
 *  License as published by the Free Software Foundation; either
 *  version 2 of the License, or (at your option) any later version.
 *
 *  This library is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 *  Library General Public License for more details.
 *
 *  You should have received a copy of the GNU Library General Public License
 *  along with this library; see the file COPYING.LIB.  If not, write to
 *  the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
 *  Boston, MA 02110-1301, USA.
 */
#ifndef KINETINTERFACEWATCHER_H
#define KINETINTERFACEWATCHER_H

#include <kinetinterface.h>
#include <tqobject.h>
#include <tqvaluevector.h>
#include <tqcstring.h>
#include <tqstring.h>


class KInetInterfaceWatcherPrivate;


/**
 * KInetInterfaceWatcher can watch the state of one or all 
 * of the system's network interfaces. 
 * The watcher will emit the signal @ref changed() when an 
 * interface changed or a interface has been added or removed.
 *
 * @author Tim Jansen <[email protected]>
 * @short Watches the state of the network interfaces
 * @see KInetInterface
 * @since 3.2
 */
class KInetInterfaceWatcher : public TQObject {
  TQ_OBJECT
  
public:
  /**
   * Creates a new KInetInterfaceWatcher. Before you can use it,
   * you must @ref start() it.
   * 
   * @param interface the name of the interface to watch (e.g.'eth0')
   *                  or TQString() to watch all interfaces
   * @param minInterval the minimum interval between two checks in 
   *                    seconds. Be careful not to check too often, to
   *                    avoid unneccessary wasting of CPU time
   */
  KInetInterfaceWatcher(const TQString &interface = TQString(),
			int minInterval = 60);

  /**
   * Returns the name of the interface that is being watched.
   * @return the name of the interface, or TQString() if all
   *         interfaces are watched
   */
  TQString interface() const;

  /**
   * Starts the KInetInterfaceWatcher. It watches either one
   * or all network interfaces. When one of them changed.
   * it emits a @ref changed() signal.
   * @param interface the name of the interface to watch (e.g.'eth0')
   *                  or TQString() to watch all interfaces
   * @param minInterval the minimum interval between two checks in 
   *                    seconds. Be careful not to check too often, to
   *                    avoid unneccessary wasting of CPU time
   * @see changed()
   * @see stop()
   */
  void start(const TQString &interface = TQString(),
	     int minInterval = 60);

  /**
   * Stops watching the interfaces.
   * @see start()
   */
  void stop();

  /**
   * Destructor
   */
  virtual ~KInetInterfaceWatcher();

signals:
  /**
   * Emitted when one or more watched interfaces have changed. The 
   * @p interfaceName is the name of the interface being watched, not
   * the interface that has changed (because more than one interface
   * may have changed). 
   * A change occurred, when 
   * @li a new interface has been added (when watching a single interface, 
   *     only when an interface of that name has been added)
   * @li an interface has been removed (when watching a single interface,
   *     only when this interface has been removed)
   * @li the address or netmask of the interface changed
   *
   * No change will be emitted when the broadcast address or destination
   * address has changed.
   *
   * @param interfaceName the name of the interface that is watched,
   *                      by the emitter, or TQString() if all 
   *                      interfaces are being watched
   * @see start()
   */
  void changed(TQString interfaceName);

private:
  KInetInterfaceWatcherPrivate* d;
};

#endif