pub async fn start<T: 'static + StationProvider + Sync + Send + Clone>(
    services: Vec<T>,
    config: Arc<Config>,
) -> std::io::Result<()> {
    let reporting_services = services.clone();
    // Start a server for each service that is passed in
    let servers: Vec<Server> = services
        .into_iter()
        .enumerate()
        .map(|(i, service)| {
            // Create port and address
            let port = config.port + i as u16;
            let bind_address = &config.bind_address;
            info!(
                "Starting http server for {} on http://{}:{}",
                service.geo().name,
                bind_address,
                port
            );

            // Construct some app_state we can pass around
            let app_state = web::Data::new(AppState::<T> {
                config: config.clone(),
                service: service.clone(),
                station_scan: Mutex::new(false),
            });

            let verbose = config.verbose;

            HttpServer::new(move || {
                App::new()
                    // Log HTTP requests if verbosity > 0
                    .wrap(Condition::new(verbose > 0, Compat::new(Logger::default())))
                    .app_data(app_state.clone())
                    .route("/", web::get().to(device_xml::<T>))
                    .route("/config", web::get().to(show_config::<T>))
                    .route("/device.xml", web::get().to(device_xml::<T>))
                    .route("/discover.json", web::get().to(discover::<T>))
                    .route("/epg.xml", web::get().to(epg_xml::<T>))
                    .route("/epg", web::get().to(epg::<T>))
                    .route("/lineup_status.json", web::get().to(lineup_status::<T>))
                    .route("/lineup.json", web::get().to(lineup_json::<T>))
                    .route("/lineup.post", web::post().to(lineup_post))
                    .route("/lineup.xml", web::get().to(lineup_xml::<T>))
                    .route("/tuner.m3u", web::get().to(tuner_m3u::<T>))
                    .service(web::resource("/watch/{id}.m3u").route(web::get().to(watch_m3u::<T>)))
                    .service(web::resource("/watch/{id}").route(web::get().to(watch::<T>)))
            })
            .bind((bind_address.to_owned(), port))
            .unwrap()
            .run()
        })
        .collect();

    // Report on what has been started
    if config.multiplex {
        info!("Tuners:");
        let mut table = Table::new();
        table.set_format(*format::consts::FORMAT_NO_LINESEP_WITH_TITLE);
        table.set_titles(row!["City", "Zip code", "DMA", "UUID", "Timezone"]);
        for s in reporting_services[0].services() {
            table.add_row(row![
                s.geo().name,
                s.zipcode(),
                s.geo().DMA,
                s.uuid(),
                s.geo().timezone.as_ref().unwrap_or(&"".to_string())
            ]);
        }

        for line in table.to_string().lines() {
            info!(" {}", line);
        }
        info!("");
        info!("Multiplexer:");
        let url = format!("http://{}:{}", config.bind_address, config.port);
        let mut table = Table::new();
        table.set_format(*format::consts::FORMAT_NO_LINESEP_WITH_TITLE);
        table.set_titles(row!["UID", "URL"]);
        table.add_row(row![reporting_services[0].uuid(), url]);
        for line in table.to_string().lines() {
            info!(" {}", line);
        }
    } else {
        info!("Tuners:");
        let mut table = Table::new();
        table.set_format(*format::consts::FORMAT_NO_LINESEP_WITH_TITLE);
        table.set_titles(row!["City", "Zip code", "DMA", "UUID", "Timezone", "URL"]);
        for is in reporting_services.iter().enumerate() {
            let (i, s) = is;
            let port = config.port + i as u16;
            let url = format!("http://{}:{}", config.bind_address, port);
            table.add_row(row![
                s.geo().name,
                s.zipcode(),
                s.geo().DMA,
                s.uuid(),
                s.geo().timezone.as_ref().unwrap_or(&"".to_string()),
                url
            ]);
        }
        for line in table.to_string().lines() {
            info!(" {}", line);
        }
    }

    info!("locast2tuner started..");
    future::try_join_all(servers).await?;
    Ok(())
}
/// Start the HTTP server that will handle media server requests
Start the HTTP server that will handle media server requests
Start the HTTP server that will handle media server requests
pub async fn start<T: 'static + StationProvider + Sync + Send + Clone>(
    services: Vec<T>,
    config: Arc<Config>,
) -> std::io::Result<()> {
    let reporting_services = services.clone();
    // Start a server for each service that is passed in
    let servers: Vec<Server> = services
        .into_iter()
        .enumerate()
        .map(|(i, service)| {
            // Create port and address
            let port = config.port + i as u16;
            let bind_address = &config.bind_address;
            info!(
                "Starting http server for {} on http://{}:{}",
                service.geo().name,
                bind_address,
                port
            );
            // Construct some app_state we can pass around
            let app_state = web::Data::new(AppState::<T> {
                config: config.clone(),
                service: service.clone(),
                station_scan: Mutex::new(false),
            });
            let verbose = config.verbose;
            HttpServer::new(move || {
                App::new()
                    // Log HTTP requests if verbosity > 0
                    .wrap(Condition::new(verbose > 0, Compat::new(Logger::default())))
                    .app_data(app_state.clone())
                    .route("/", web::get().to(device_xml::<T>))
                    .route("/config", web::get().to(show_config::<T>))
                    .route("/device.xml", web::get().to(device_xml::<T>))
                    .route("/discover.json", web::get().to(discover::<T>))
                    .route("/epg.xml", web::get().to(epg_xml::<T>))
                    .route("/epg", web::get().to(epg::<T>))
                    .route("/lineup_status.json", web::get().to(lineup_status::<T>))
                    .route("/lineup.json", web::get().to(lineup_json::<T>))
                    .route("/lineup.post", web::post().to(lineup_post))
                    .route("/lineup.xml", web::get().to(lineup_xml::<T>))
                    .route("/tuner.m3u", web::get().to(tuner_m3u::<T>))
                    .service(web::resource("/watch/{id}.m3u").route(web::get().to(watch_m3u::<T>)))
                    .service(web::resource("/watch/{id}").route(web::get().to(watch::<T>)))
            })
            .bind((bind_address.to_owned(), port))
            .unwrap()
            .run()
        })
        .collect();
    // Report on what has been started
    if config.multiplex {
        info!("Tuners:");
        let mut table = Table::new();
        table.set_format(*format::consts::FORMAT_NO_LINESEP_WITH_TITLE);
        table.set_titles(row!["City", "Zip code", "DMA", "UUID", "Timezone"]);
        for s in reporting_services[0].services() {
            table.add_row(row![
                s.geo().name,
                s.zipcode(),
                s.geo().DMA,
                s.uuid(),
                s.geo().timezone.as_ref().unwrap_or(&"".to_string())
            ]);
        }
        for line in table.to_string().lines() {
            info!(" {}", line);
        }
        info!("");
        info!("Multiplexer:");
        let url = format!("http://{}:{}", config.bind_address, config.port);
        let mut table = Table::new();
        table.set_format(*format::consts::FORMAT_NO_LINESEP_WITH_TITLE);
        table.set_titles(row!["UID", "URL"]);
        table.add_row(row![reporting_services[0].uuid(), url]);
        for line in table.to_string().lines() {
            info!(" {}", line);
        }
    } else {
        info!("Tuners:");
        let mut table = Table::new();
        table.set_format(*format::consts::FORMAT_NO_LINESEP_WITH_TITLE);
        table.set_titles(row!["City", "Zip code", "DMA", "UUID", "Timezone", "URL"]);
        for is in reporting_services.iter().enumerate() {
            let (i, s) = is;
            let port = config.port + i as u16;
            let url = format!("http://{}:{}", config.bind_address, port);
            table.add_row(row![
                s.geo().name,
                s.zipcode(),
                s.geo().DMA,
                s.uuid(),
                s.geo().timezone.as_ref().unwrap_or(&"".to_string()),
                url
            ]);
        }
        for line in table.to_string().lines() {
            info!(" {}", line);
        }
    }
    info!("locast2tuner started..");
    future::try_join_all(servers).await?;
    Ok(())
}
pub async fn start < T : ' static + StationProvider + Sync + Send + Clone > ( services : Vec < T > , config : Arc < Config > , ) -> std :: io :: Result < ( ) > { let reporting_services = services . clone ( ) ; // Start a server for each service that is passed in let servers : Vec < Server > = services . into_iter ( ) . enumerate ( ) . map ( | ( i , service ) | { // Create port and address let port = config . port + i as u16 ; let bind_address = & config . bind_address ; info ! ( " " service geo ( ) name bind_address port ) ; // Construct some app_state we can pass around let app_state = web :: Data :: new ( AppState :: < T > { config : config . clone ( ) , service : service . clone ( ) , station_scan : Mutex :: new ( false ) , } ) ; let verbose = config . verbose ; HttpServer :: new ( move | | { App :: new ( ) // Log HTTP requests if verbosity > 0 . wrap ( Condition :: new ( verbose > 0 , Compat :: new ( Logger :: default ( ) ) ) ) . app_data ( app_state . clone ( ) ) . route ( " " , web :: get ( ) . to ( device_xml :: < T > ) ) . route ( " " , web :: get ( ) . to ( show_config :: < T > ) ) . route ( " " , web :: get ( ) . to ( device_xml :: < T > ) ) . route ( " " , web :: get ( ) . to ( discover :: < T > ) ) . route ( " " , web :: get ( ) . to ( epg_xml :: < T > ) ) . route ( " " , web :: get ( ) . to ( epg :: < T > ) ) . route ( " " , web :: get ( ) . to ( lineup_status :: < T > ) ) . route ( " " , web :: get ( ) . to ( lineup_json :: < T > ) ) . route ( " " , web :: post ( ) . to ( lineup_post ) ) . route ( " " , web :: get ( ) . to ( lineup_xml :: < T > ) ) . route ( " " , web :: get ( ) . to ( tuner_m3u :: < T > ) ) . service ( web :: resource ( " " ) . route ( web :: get ( ) . to ( watch_m3u :: < T > ) ) ) . service ( web :: resource ( " " ) . route ( web :: get ( ) . to ( watch :: < T > ) ) ) } ) . bind ( ( bind_address . to_owned ( ) , port ) ) . unwrap ( ) . run ( ) } ) . collect ( ) ; // Report on what has been started if config . multiplex { info ! ( " " ) ; let mut table = Table :: new ( ) ; table . set_format ( * format :: consts :: FORMAT_NO_LINESEP_WITH_TITLE ) ; table . set_titles ( row ! [ " " " " " " " " " " ] ) ; for s in reporting_services [ 0 ] . services ( ) { table . add_row ( row ! [ s geo ( ) name s zipcode ( ) s geo ( ) DMA s uuid ( ) s geo ( ) timezone as_ref ( ) unwrap_or ( " " to_string ( ) ) ] ) ; } for line in table . to_string ( ) . lines ( ) { info ! ( " " line ) ; } info ! ( " " ) ; info ! ( " " ) ; let url = format ! ( " " config bind_address config port ) ; let mut table = Table :: new ( ) ; table . set_format ( * format :: consts :: FORMAT_NO_LINESEP_WITH_TITLE ) ; table . set_titles ( row ! [ " " " " ] ) ; table . add_row ( row ! [ reporting_services [ 0 ] uuid ( ) url ] ) ; for line in table . to_string ( ) . lines ( ) { info ! ( " " line ) ; } } else { info ! ( " " ) ; let mut table = Table :: new ( ) ; table . set_format ( * format :: consts :: FORMAT_NO_LINESEP_WITH_TITLE ) ; table . set_titles ( row ! [ " " " " " " " " " " " " ] ) ; for is in reporting_services . iter ( ) . enumerate ( ) { let ( i , s ) = is ; let port = config . port + i as u16 ; let url = format ! ( " " config bind_address port ) ; table . add_row ( row ! [ s geo ( ) name s zipcode ( ) s geo ( ) DMA s uuid ( ) s geo ( ) timezone as_ref ( ) unwrap_or ( " " to_string ( ) ) url ] ) ; } for line in table . to_string ( ) . lines ( ) { info ! ( " " line ) ; } } info ! ( " " ) ; future :: try_join_all ( servers ) . await ? ; Ok ( ( ) ) }
Start the HTTP server that will handle media server requests
Start the HTTP server that will handle media server requests
services
Vec<T>
config
Arc<Config>