QtZeroConf
 All Classes Functions Variables Pages
zconfservicebrowser.h
1 /*
2  * This file is part of qtzeroconf. (c) 2012 Johannes Hilden
3  * https://github.com/johanneshilden/qtzeroconf
4  *
5  * qtzeroconf is free software; you can redistribute it and/or modify it
6  * under the terms of the GNU Lesser General Public License as
7  * published by the Free Software Foundation; either version 2.1 of the
8  * License, or (at your option) any later version.
9  *
10  * qtzeroconf is distributed in the hope that it will be useful, but WITHOUT
11  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
12  * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General
13  * Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public
16  * License along with qtzeroconf; if not, write to the Free Software
17  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
18  */
19 
20 #ifndef ZCONFSERVICEBROWSER_H
21 #define ZCONFSERVICEBROWSER_H
22 
23 #include <QObject>
24 #include <stdint-gcc.h>
25 #include <avahi-client/lookup.h>
26 
28 {
29  QString ip;
30  QString domain;
31  QString host;
32  uint16_t port;
33  AvahiProtocol protocol;
34  AvahiLookupResultFlags flags;
35 
36  QString protocolName() const;
37  inline bool isValid() const { return !(ip.isEmpty() && host.isEmpty()); }
38 
39  inline bool isCached() const { return flags & AVAHI_LOOKUP_RESULT_CACHED; }
40  inline bool isWideArea() const { return flags & AVAHI_LOOKUP_RESULT_WIDE_AREA; }
41  inline bool isMulticast() const { return flags & AVAHI_LOOKUP_RESULT_MULTICAST; }
42  inline bool isLocal() const { return flags & AVAHI_LOOKUP_RESULT_LOCAL; }
43 };
44 
45 class ZConfServiceBrowserPrivate;
46 class ZConfServiceBrowser : public QObject
47 {
48  Q_OBJECT
49 
50 public:
51  explicit ZConfServiceBrowser(QObject *parent = 0);
53 
54  void browse(QString serviceType = "_http._tcp");
55  ZConfServiceEntry serviceEntry(QString name);
56 
57 signals:
58  void serviceEntryAdded(QString);
59  void serviceEntryRemoved(QString);
60 
61 protected slots:
62  void createServiceBrowser();
63 
64 protected:
65  ZConfServiceBrowserPrivate *const d_ptr;
66 
67 private:
68  Q_DECLARE_PRIVATE(ZConfServiceBrowser);
69 };
70 
71 #endif // ZCONFSERVICEBROWSER_H