libktorrent  2.2.0
portlist.h
1 /***************************************************************************
2  * Copyright (C) 2005 by Joris Guisson *
3  * joris.guisson@gmail.com *
4  * *
5  * This program is free software; you can redistribute it and/or modify *
6  * it under the terms of the GNU General Public License as published by *
7  * the Free Software Foundation; either version 2 of the License, or *
8  * (at your option) any later version. *
9  * *
10  * This program is distributed in the hope that it will be useful, *
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13  * GNU General Public License for more details. *
14  * *
15  * You should have received a copy of the GNU General Public License *
16  * along with this program; if not, write to the *
17  * Free Software Foundation, Inc., *
18  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. *
19  ***************************************************************************/
20 #ifndef NETPORTLIST_H
21 #define NETPORTLIST_H
22 
23 #include <QList>
24 #include <util/constants.h>
25 #include <ktorrent_export.h>
26 
27 namespace net
28 {
29  enum Protocol
30  {
31  TCP,
32  UDP
33  };
34 
35  struct KTORRENT_EXPORT Port
36  {
37  bt::Uint16 number;
38  Protocol proto;
39  bool forward;
40 
41  Port();
42  Port(bt::Uint16 number,Protocol proto,bool forward);
43  Port(const Port & p);
44 
45  bool operator == (const Port & p) const;
46  };
47 
51  class KTORRENT_EXPORT PortListener
52  {
53  public:
54  virtual ~PortListener() {}
55 
60  virtual void portAdded(const Port & port) = 0;
61 
66  virtual void portRemoved(const Port & port) = 0;
67  };
68 
75  class KTORRENT_EXPORT PortList : public QList<Port>
76  {
77  PortListener* lst;
78  public:
79  PortList();
80  virtual ~PortList();
81 
88  void addNewPort(bt::Uint16 number,Protocol proto,bool forward);
89 
95  void removePort(bt::Uint16 number,Protocol proto);
96 
101  void setListener(PortListener* pl) {lst = pl;}
102  };
103 
104 }
105 
106 #ifdef Q_CC_MSVC
107 #include <QHash>
108 inline uint qHash(const net::Port & port) {return qHash((uint)port.number);}
109 #endif
110 
111 
112 #endif
net::PortList
Definition: portlist.h:76
net::PortList::addNewPort
void addNewPort(bt::Uint16 number, Protocol proto, bool forward)
net::PortListener
Definition: portlist.h:52
net::PortListener::portAdded
virtual void portAdded(const Port &port)=0
net::PortList::removePort
void removePort(bt::Uint16 number, Protocol proto)
net::Port
Definition: portlist.h:36
net::PortListener::portRemoved
virtual void portRemoved(const Port &port)=0
net::PortList::setListener
void setListener(PortListener *pl)
Definition: portlist.h:101