Guitarix
avahi_discover.h
Go to the documentation of this file.
1/*
2 * Copyright (C) 2009, 2010 Hermann Meyer, James Warden, Andreas Degert
3 * Copyright (C) 2011 Pete Shorthose
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 Free Software
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18 * ---------------------------------------------------------------------------
19 */
20
21#pragma once
22
23#ifndef SRC_HEADERS_AVAHI_DISCOVER_H_
24#define SRC_HEADERS_AVAHI_DISCOVER_H_
25
26#include "guitarix.h"
27#include <avahi-gobject/ga-client.h>
28#include <avahi-gobject/ga-service-browser.h>
29#include <avahi-gobject/ga-service-resolver.h>
30
32public:
33 struct Entry {
34 AvahiIfIndex interface;
35 AvahiProtocol protocol;
36 Glib::ustring name;
37 std::string type;
38 std::string domain;
39 AvahiLookupResultFlags flags;
40 Entry() {}
41 Entry(AvahiIfIndex interface_, AvahiProtocol protocol_, const char *name_,
42 const char *type_, const char *domain_, AvahiLookupResultFlags flags_)
43 : interface(interface_), protocol(protocol_), name(name_), type(type_),
44 domain(domain_), flags(flags_) {}
45 bool operator==(const Entry& e) const {
46 return interface == e.interface && protocol == e.protocol && name == e.name
47 && type == e.type && domain == e.domain;
48 }
49 };
50private:
51 GaClient *client;
52 GaServiceBrowser *browser;
53 GaServiceResolver *resolver;
54 std::list<Entry> services;
55 std::map<Glib::ustring,int> service_names;
56 sigc::signal<void> changed;
58 Glib::ustring found_name;
59 Glib::ustring found_host;
60 static void new_service(
61 GaServiceBrowser *browser, AvahiIfIndex interface, AvahiProtocol protocol,
62 const char *name, const char *type, const char *domain, AvahiLookupResultFlags flags, void *data);
63 static void removed_service(
64 GaServiceBrowser *browser, AvahiIfIndex interface, AvahiProtocol protocol,
65 const char *name, const char *type, const char *domain, AvahiLookupResultFlags flags, void *data);
66 static void cache_exhausted(GaServiceBrowser *browser, void *data);
67 static void on_found(GaServiceResolver *resolver, AvahiIfIndex interface, AvahiProtocol protocol,
68 const char *name, const char *type, const char *domain, const char *host_name,
69 const AvahiAddress * a, uint16_t port, AvahiStringList * txt,
70 AvahiLookupResultFlags flags, void *data);
71 static void on_failure(GaServiceResolver *resolver, GError *error, void *data);
72public:
75 sigc::signal<void>& signal_changed() { return changed; }
76 void get_service_names(std::vector<Glib::ustring>& r);
77 bool invoke_resolver(const Glib::ustring& name);
78 bool get_address_port(Glib::ustring& address, int& port, Glib::ustring& name, Glib::ustring& host);
79};
80
82private:
83 Gtk::Window *splash;
84 Gtk::Dialog *win;
85 Gtk::TreeView *view;
87 class ModelColumns: public Gtk::TreeModelColumnRecord {
88 public:
89 Gtk::TreeModelColumn<Glib::ustring> name;
90 ModelColumns() { add(name); }
92private:
93 void on_response(int response_id);
94 void on_row(const Gtk::TreePath& path, Gtk::TreeViewColumn* column);
97public:
100 bool get_address_port(Glib::ustring& address, int& port, Glib::ustring& name, Glib::ustring& host)
101 { return av.get_address_port(address, port, name, host); }
102};
103
104#endif // SRC_HEADERS_AVAHI_DISCOVER_H_
static void cache_exhausted(GaServiceBrowser *browser, void *data)
GaServiceResolver * resolver
bool get_address_port(Glib::ustring &address, int &port, Glib::ustring &name, Glib::ustring &host)
static void new_service(GaServiceBrowser *browser, AvahiIfIndex interface, AvahiProtocol protocol, const char *name, const char *type, const char *domain, AvahiLookupResultFlags flags, void *data)
GaServiceBrowser * browser
static void removed_service(GaServiceBrowser *browser, AvahiIfIndex interface, AvahiProtocol protocol, const char *name, const char *type, const char *domain, AvahiLookupResultFlags flags, void *data)
std::map< Glib::ustring, int > service_names
sigc::signal< void > & signal_changed()
std::list< Entry > services
static void on_failure(GaServiceResolver *resolver, GError *error, void *data)
GaClient * client
Glib::ustring found_name
bool invoke_resolver(const Glib::ustring &name)
sigc::signal< void > changed
Glib::ustring found_host
static void on_found(GaServiceResolver *resolver, AvahiIfIndex interface, AvahiProtocol protocol, const char *name, const char *type, const char *domain, const char *host_name, const AvahiAddress *a, uint16_t port, AvahiStringList *txt, AvahiLookupResultFlags flags, void *data)
void get_service_names(std::vector< Glib::ustring > &r)
Gtk::TreeModelColumn< Glib::ustring > name
bool get_address_port(Glib::ustring &address, int &port, Glib::ustring &name, Glib::ustring &host)
SelectInstance(gx_system::CmdlineOptions &options, Gtk::Window *splash)
void on_selection_changed()
void on_avahi_changed()
void on_row(const Gtk::TreePath &path, Gtk::TreeViewColumn *column)
Gtk::Window * splash
void on_response(int response_id)
AvahiBrowser av
Gtk::Dialog * win
Gtk::TreeView * view
SelectInstance::ModelColumns cols
Entry(AvahiIfIndex interface_, AvahiProtocol protocol_, const char *name_, const char *type_, const char *domain_, AvahiLookupResultFlags flags_)
bool operator==(const Entry &e) const
AvahiIfIndex interface
std::string domain
AvahiProtocol protocol
std::string type
AvahiLookupResultFlags flags
Entry()
Glib::ustring name