Update browser for new ServiceType
Signed-off-by: Walker Crouse <Walker.Crouse@bjss.com>
This commit is contained in:
parent
2d526471e3
commit
2654a20723
|
@ -85,11 +85,11 @@ fn on_service_registered(
|
||||||
use std::any::Any;
|
use std::any::Any;
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
use std::time::Duration;
|
use std::time::Duration;
|
||||||
use zeroconf::{MdnsBrowser, ServiceDiscovery};
|
|
||||||
use zeroconf::prelude::*;
|
use zeroconf::prelude::*;
|
||||||
|
use zeroconf::{MdnsBrowser, ServiceDiscovery, ServiceType};
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
let mut browser = MdnsBrowser::new("_http._tcp");
|
let mut browser = MdnsBrowser::new(ServiceType::new("http", "tcp").unwrap());
|
||||||
|
|
||||||
browser.set_service_discovered_callback(Box::new(on_service_discovered));
|
browser.set_service_discovered_callback(Box::new(on_service_discovered));
|
||||||
|
|
||||||
|
|
|
@ -502,7 +502,7 @@ checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "zeroconf"
|
name = "zeroconf"
|
||||||
version = "0.7.2"
|
version = "0.8.2"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"avahi-sys",
|
"avahi-sys",
|
||||||
"bonjour-sys",
|
"bonjour-sys",
|
||||||
|
|
|
@ -1,11 +1,11 @@
|
||||||
use std::any::Any;
|
use std::any::Any;
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
use std::time::Duration;
|
use std::time::Duration;
|
||||||
use zeroconf::{MdnsBrowser, ServiceDiscovery};
|
|
||||||
use zeroconf::prelude::*;
|
use zeroconf::prelude::*;
|
||||||
|
use zeroconf::{MdnsBrowser, ServiceDiscovery, ServiceType};
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
let mut browser = MdnsBrowser::new("_http._tcp");
|
let mut browser = MdnsBrowser::new(ServiceType::new("http", "tcp").unwrap());
|
||||||
|
|
||||||
browser.set_service_discovered_callback(Box::new(on_service_discovered));
|
browser.set_service_discovered_callback(Box::new(on_service_discovered));
|
||||||
|
|
||||||
|
|
|
@ -1,13 +1,13 @@
|
||||||
//! Trait definition for cross-platform browser
|
//! Trait definition for cross-platform browser
|
||||||
|
|
||||||
use crate::{EventLoop, NetworkInterface, Result, TxtRecord};
|
use crate::{EventLoop, NetworkInterface, Result, ServiceType, TxtRecord};
|
||||||
use std::any::Any;
|
use std::any::Any;
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
|
|
||||||
/// Interface for interacting with underlying mDNS implementation service browsing capabilities.
|
/// Interface for interacting with underlying mDNS implementation service browsing capabilities.
|
||||||
pub trait TMdnsBrowser {
|
pub trait TMdnsBrowser {
|
||||||
/// Creates a new `MdnsBrowser` that browses for the specified `kind` (e.g. `_http._tcp`)
|
/// Creates a new `MdnsBrowser` that browses for the specified `kind` (e.g. `_http._tcp`)
|
||||||
fn new(kind: &str) -> Self;
|
fn new(service_type: ServiceType) -> Self;
|
||||||
|
|
||||||
/// Sets the network interface on which to browse for services on.
|
/// Sets the network interface on which to browse for services on.
|
||||||
///
|
///
|
||||||
|
@ -49,7 +49,7 @@ pub type ServiceDiscoveredCallback = dyn Fn(Result<ServiceDiscovery>, Option<Arc
|
||||||
)]
|
)]
|
||||||
pub struct ServiceDiscovery {
|
pub struct ServiceDiscovery {
|
||||||
name: String,
|
name: String,
|
||||||
kind: String,
|
service_type: ServiceType,
|
||||||
domain: String,
|
domain: String,
|
||||||
host_name: String,
|
host_name: String,
|
||||||
address: String,
|
address: String,
|
||||||
|
|
|
@ -75,11 +75,11 @@
|
||||||
//! use std::any::Any;
|
//! use std::any::Any;
|
||||||
//! use std::sync::Arc;
|
//! use std::sync::Arc;
|
||||||
//! use std::time::Duration;
|
//! use std::time::Duration;
|
||||||
//! use zeroconf::{MdnsBrowser, ServiceDiscovery};
|
|
||||||
//! use zeroconf::prelude::*;
|
//! use zeroconf::prelude::*;
|
||||||
|
//! use zeroconf::{MdnsBrowser, ServiceDiscovery, ServiceType};
|
||||||
//!
|
//!
|
||||||
//! fn main() {
|
//! fn main() {
|
||||||
//! let mut browser = MdnsBrowser::new("_http._tcp");
|
//! let mut browser = MdnsBrowser::new(ServiceType::new("http", "tcp").unwrap());
|
||||||
//!
|
//!
|
||||||
//! browser.set_service_discovered_callback(Box::new(on_service_discovered));
|
//! browser.set_service_discovered_callback(Box::new(on_service_discovered));
|
||||||
//!
|
//!
|
||||||
|
|
|
@ -14,7 +14,10 @@ use super::{
|
||||||
use crate::ffi::{c_str, AsRaw, FromRaw};
|
use crate::ffi::{c_str, AsRaw, FromRaw};
|
||||||
use crate::prelude::*;
|
use crate::prelude::*;
|
||||||
use crate::Result;
|
use crate::Result;
|
||||||
use crate::{EventLoop, NetworkInterface, ServiceDiscoveredCallback, ServiceDiscovery, TxtRecord};
|
use crate::{
|
||||||
|
EventLoop, NetworkInterface, ServiceDiscoveredCallback, ServiceDiscovery, ServiceType,
|
||||||
|
TxtRecord,
|
||||||
|
};
|
||||||
use avahi_sys::{
|
use avahi_sys::{
|
||||||
AvahiAddress, AvahiBrowserEvent, AvahiClient, AvahiClientFlags, AvahiClientState, AvahiIfIndex,
|
AvahiAddress, AvahiBrowserEvent, AvahiClient, AvahiClientFlags, AvahiClientState, AvahiIfIndex,
|
||||||
AvahiLookupResultFlags, AvahiProtocol, AvahiResolverEvent, AvahiServiceBrowser,
|
AvahiLookupResultFlags, AvahiProtocol, AvahiResolverEvent, AvahiServiceBrowser,
|
||||||
|
@ -23,6 +26,7 @@ use avahi_sys::{
|
||||||
use libc::{c_char, c_void};
|
use libc::{c_char, c_void};
|
||||||
use std::any::Any;
|
use std::any::Any;
|
||||||
use std::ffi::CString;
|
use std::ffi::CString;
|
||||||
|
use std::str::FromStr;
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
use std::{fmt, ptr};
|
use std::{fmt, ptr};
|
||||||
|
|
||||||
|
@ -37,12 +41,12 @@ pub struct AvahiMdnsBrowser {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl TMdnsBrowser for AvahiMdnsBrowser {
|
impl TMdnsBrowser for AvahiMdnsBrowser {
|
||||||
fn new(kind: &str) -> Self {
|
fn new(service_type: ServiceType) -> Self {
|
||||||
Self {
|
Self {
|
||||||
client: None,
|
client: None,
|
||||||
poll: None,
|
poll: None,
|
||||||
browser: None,
|
browser: None,
|
||||||
kind: c_string!(kind.to_string()),
|
kind: c_string!(service_type.to_string()),
|
||||||
context: Box::into_raw(Box::default()),
|
context: Box::into_raw(Box::default()),
|
||||||
interface_index: constants::AVAHI_IF_UNSPEC,
|
interface_index: constants::AVAHI_IF_UNSPEC,
|
||||||
}
|
}
|
||||||
|
@ -268,7 +272,7 @@ unsafe fn handle_resolver_found(
|
||||||
|
|
||||||
let result = ServiceDiscovery::builder()
|
let result = ServiceDiscovery::builder()
|
||||||
.name(name.to_string())
|
.name(name.to_string())
|
||||||
.kind(kind.to_string())
|
.service_type(ServiceType::from_str(kind)?)
|
||||||
.domain(domain.to_string())
|
.domain(domain.to_string())
|
||||||
.host_name(host_name.to_string())
|
.host_name(host_name.to_string())
|
||||||
.address(address)
|
.address(address)
|
||||||
|
|
|
@ -25,7 +25,7 @@ fn service_register_is_browsable() {
|
||||||
service.set_txt_record(txt.clone());
|
service.set_txt_record(txt.clone());
|
||||||
|
|
||||||
service.set_registered_callback(Box::new(|_, context| {
|
service.set_registered_callback(Box::new(|_, context| {
|
||||||
let mut browser = MdnsBrowser::new("_http._tcp");
|
let mut browser = MdnsBrowser::new(ServiceType::new("http", "tcp").unwrap());
|
||||||
|
|
||||||
let context = context
|
let context = context
|
||||||
.as_ref()
|
.as_ref()
|
||||||
|
|
Loading…
Reference in New Issue