Skip to content

Commit c7c4f6b

Browse files
committed
tacd: finish the http server setup in init()
This allows us to display an error message if the server setup fails. Signed-off-by: Leonard Göhrs <l.goehrs@pengutronix.de>
1 parent 06fea51 commit c7c4f6b

File tree

1 file changed

+13
-17
lines changed

1 file changed

+13
-17
lines changed

src/main.rs

Lines changed: 13 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -52,12 +52,12 @@ use regulators::Regulators;
5252
use setup_mode::SetupMode;
5353
use system::System;
5454
use temperatures::Temperatures;
55-
use ui::{message, setup_display, Display, Ui, UiResources};
55+
use ui::{message, setup_display, Display, ScreenShooter, Ui, UiResources};
5656
use usb_hub::UsbHub;
5757
use watchdog::Watchdog;
5858
use watched_tasks::WatchedTasksBuilder;
5959

60-
async fn init() -> Result<(Ui, HttpServer, WatchedTasksBuilder)> {
60+
async fn init(screenshooter: ScreenShooter) -> Result<(Ui, WatchedTasksBuilder)> {
6161
// The tacd spawns a couple of async tasks that should run as long as
6262
// the tacd runs and if any one fails the tacd should stop.
6363
// These tasks are spawned via the watched task builder.
@@ -157,26 +157,21 @@ async fn init() -> Result<(Ui, HttpServer, WatchedTasksBuilder)> {
157157
// and expose the topics via HTTP and MQTT-over-websocket.
158158
bb.build(&mut wtb, &mut http_server.server)?;
159159

160+
// Expose the display as a .png on the web server
161+
ui::serve_display(&mut http_server.server, screenshooter);
162+
163+
// Start serving files and the API
164+
http_server.serve(&mut wtb)?;
165+
160166
// If a watchdog was requested by systemd we can now start feeding it
161167
if let Some(watchdog) = watchdog {
162168
watchdog.keep_fed(&mut wtb)?;
163169
}
164170

165-
Ok((ui, http_server, wtb))
171+
Ok((ui, wtb))
166172
}
167173

168-
async fn run(
169-
ui: Ui,
170-
mut http_server: HttpServer,
171-
display: Display,
172-
mut wtb: WatchedTasksBuilder,
173-
) -> Result<()> {
174-
// Expose the display as a .png on the web server
175-
ui::serve_display(&mut http_server.server, display.screenshooter());
176-
177-
// Start serving files and the API
178-
http_server.serve(&mut wtb)?;
179-
174+
async fn run(ui: Ui, display: Display, mut wtb: WatchedTasksBuilder) -> Result<()> {
180175
// Start drawing the UI
181176
ui.run(&mut wtb, display)?;
182177

@@ -191,9 +186,10 @@ async fn main() -> Result<()> {
191186

192187
// Show a splash screen very early on
193188
let display = setup_display();
189+
let screenshooter = display.screenshooter();
194190

195-
match init().await {
196-
Ok((ui, http_server, wtb)) => run(ui, http_server, display, wtb).await,
191+
match init(screenshooter).await {
192+
Ok((ui, wtb)) => run(ui, display, wtb).await,
197193
Err(e) => {
198194
// Display a detailed error message on stderr (and thus in the journal) ...
199195
error!("Failed to initialize tacd: {e}");

0 commit comments

Comments
 (0)