Loading...
Searching...
No Matches
avahi_discover.h
Go to the documentation of this file.
/*
* Copyright (C) 2009, 2010 Hermann Meyer, James Warden, Andreas Degert
* Copyright (C) 2011 Pete Shorthose
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
* ---------------------------------------------------------------------------
*/
#pragma once
#ifndef SRC_HEADERS_AVAHI_DISCOVER_H_
#define SRC_HEADERS_AVAHI_DISCOVER_H_
#include "guitarix.h"
#include <avahi-gobject/ga-client.h>
#include <avahi-gobject/ga-service-browser.h>
#include <avahi-gobject/ga-service-resolver.h>
class AvahiBrowser {
public:
struct Entry {
AvahiIfIndex interface;
AvahiProtocol protocol;
Glib::ustring name;
std::string type;
std::string domain;
AvahiLookupResultFlags flags;
Entry() {}
Entry(AvahiIfIndex interface_, AvahiProtocol protocol_, const char *name_,
const char *type_, const char *domain_, AvahiLookupResultFlags flags_)
: interface(interface_), protocol(protocol_), name(name_), type(type_),
domain(domain_), flags(flags_) {}
bool operator==(const Entry& e) const {
return interface == e.interface && protocol == e.protocol && name == e.name
&& type == e.type && domain == e.domain;
}
};
private:
GaClient *client;
GaServiceBrowser *browser;
GaServiceResolver *resolver;
std::list<Entry> services;
std::map<Glib::ustring,int> service_names;
sigc::signal<void> changed;
bool cache_done;
Glib::ustring found_name;
Glib::ustring found_host;
static void new_service(
GaServiceBrowser *browser, AvahiIfIndex interface, AvahiProtocol protocol,
const char *name, const char *type, const char *domain, AvahiLookupResultFlags flags, void *data);
static void removed_service(
GaServiceBrowser *browser, AvahiIfIndex interface, AvahiProtocol protocol,
const char *name, const char *type, const char *domain, AvahiLookupResultFlags flags, void *data);
static void cache_exhausted(GaServiceBrowser *browser, void *data);
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);
static void on_failure(GaServiceResolver *resolver, GError *error, void *data);
public:
AvahiBrowser();
~AvahiBrowser();
sigc::signal<void>& signal_changed() { return changed; }
void get_service_names(std::vector<Glib::ustring>& r);
bool invoke_resolver(const Glib::ustring& name);
bool get_address_port(Glib::ustring& address, int& port, Glib::ustring& name, Glib::ustring& host);
};
class SelectInstance {
private:
Gtk::Window *splash;
Gtk::Dialog *win;
Gtk::TreeView *view;
AvahiBrowser av;
class ModelColumns: public Gtk::TreeModelColumnRecord {
public:
Gtk::TreeModelColumn<Glib::ustring> name;
ModelColumns() { add(name); }
} cols;
private:
void on_response(int response_id);
void on_row(const Gtk::TreePath& path, Gtk::TreeViewColumn* column);
void on_avahi_changed();
void on_selection_changed();
public:
SelectInstance(gx_system::CmdlineOptions& options, Gtk::Window *splash);
~SelectInstance();
bool get_address_port(Glib::ustring& address, int& port, Glib::ustring& name, Glib::ustring& host)
{ return av.get_address_port(address, port, name, host); }
};
#endif // SRC_HEADERS_AVAHI_DISCOVER_H_
AvahiBrowser
Definition avahi_discover.h:31
AvahiBrowser::cache_exhausted
static void cache_exhausted(GaServiceBrowser *browser, void *data)
AvahiBrowser::resolver
GaServiceResolver * resolver
Definition avahi_discover.h:53
AvahiBrowser::cache_done
bool cache_done
Definition avahi_discover.h:57
AvahiBrowser::get_address_port
bool get_address_port(Glib::ustring &address, int &port, Glib::ustring &name, Glib::ustring &host)
AvahiBrowser::new_service
static void new_service(GaServiceBrowser *browser, AvahiIfIndex interface, AvahiProtocol protocol, const char *name, const char *type, const char *domain, AvahiLookupResultFlags flags, void *data)
AvahiBrowser::~AvahiBrowser
~AvahiBrowser()
AvahiBrowser::browser
GaServiceBrowser * browser
Definition avahi_discover.h:52
AvahiBrowser::removed_service
static void removed_service(GaServiceBrowser *browser, AvahiIfIndex interface, AvahiProtocol protocol, const char *name, const char *type, const char *domain, AvahiLookupResultFlags flags, void *data)
AvahiBrowser::service_names
std::map< Glib::ustring, int > service_names
Definition avahi_discover.h:55
AvahiBrowser::signal_changed
sigc::signal< void > & signal_changed()
Definition avahi_discover.h:75
AvahiBrowser::services
std::list< Entry > services
Definition avahi_discover.h:54
AvahiBrowser::on_failure
static void on_failure(GaServiceResolver *resolver, GError *error, void *data)
AvahiBrowser::client
GaClient * client
Definition avahi_discover.h:51
AvahiBrowser::found_name
Glib::ustring found_name
Definition avahi_discover.h:58
AvahiBrowser::invoke_resolver
bool invoke_resolver(const Glib::ustring &name)
AvahiBrowser::AvahiBrowser
AvahiBrowser()
AvahiBrowser::changed
sigc::signal< void > changed
Definition avahi_discover.h:56
AvahiBrowser::found_host
Glib::ustring found_host
Definition avahi_discover.h:59
AvahiBrowser::on_found
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)
AvahiBrowser::get_service_names
void get_service_names(std::vector< Glib::ustring > &r)
SelectInstance::ModelColumns::name
Gtk::TreeModelColumn< Glib::ustring > name
Definition avahi_discover.h:89
SelectInstance::ModelColumns::ModelColumns
ModelColumns()
Definition avahi_discover.h:90
SelectInstance::get_address_port
bool get_address_port(Glib::ustring &address, int &port, Glib::ustring &name, Glib::ustring &host)
Definition avahi_discover.h:100
SelectInstance::SelectInstance
SelectInstance(gx_system::CmdlineOptions &options, Gtk::Window *splash)
SelectInstance::on_selection_changed
void on_selection_changed()
SelectInstance::on_avahi_changed
void on_avahi_changed()
SelectInstance::on_row
void on_row(const Gtk::TreePath &path, Gtk::TreeViewColumn *column)
SelectInstance::splash
Gtk::Window * splash
Definition avahi_discover.h:83
SelectInstance::on_response
void on_response(int response_id)
SelectInstance::~SelectInstance
~SelectInstance()
SelectInstance::av
AvahiBrowser av
Definition avahi_discover.h:86
SelectInstance::win
Gtk::Dialog * win
Definition avahi_discover.h:84
SelectInstance::view
Gtk::TreeView * view
Definition avahi_discover.h:85
SelectInstance::cols
SelectInstance::ModelColumns cols
gx_system::CmdlineOptions
Definition gx_system.h:395
guitarix.h
AvahiBrowser::Entry::Entry
Entry(AvahiIfIndex interface_, AvahiProtocol protocol_, const char *name_, const char *type_, const char *domain_, AvahiLookupResultFlags flags_)
Definition avahi_discover.h:41
AvahiBrowser::Entry::operator==
bool operator==(const Entry &e) const
Definition avahi_discover.h:45
AvahiBrowser::Entry::interface
AvahiIfIndex interface
Definition avahi_discover.h:34
AvahiBrowser::Entry::domain
std::string domain
Definition avahi_discover.h:38
AvahiBrowser::Entry::protocol
AvahiProtocol protocol
Definition avahi_discover.h:35
AvahiBrowser::Entry::type
std::string type
Definition avahi_discover.h:37
AvahiBrowser::Entry::flags
AvahiLookupResultFlags flags
Definition avahi_discover.h:39
AvahiBrowser::Entry::Entry
Entry()
Definition avahi_discover.h:40
AvahiBrowser::Entry::name
Glib::ustring name
Definition avahi_discover.h:36