Skip to content

Commit

Permalink
Merge pull request #19 from hnez/bundle-polling
Browse files Browse the repository at this point in the history
Poll for RAUC updates and show notifications
  • Loading branch information
SmithChart committed May 30, 2023
2 parents 9a9bb7e + b61540a commit 88d20f1
Show file tree
Hide file tree
Showing 38 changed files with 3,033 additions and 1,565 deletions.
1 change: 1 addition & 0 deletions Cargo.toml
Expand Up @@ -36,6 +36,7 @@ png = "0.17"
rand = { version = "0.8", optional = true}
serde_json = "1.0"
serde_repr = "0.1"
serde_yaml = "0.9"
serde = { version = "1.0", features = ["derive"] }
sha-1 = "0.10"
surf = { version = "2.3", default-features = false, features = ["h1-client-no-tls"] }
Expand Down
Empty file.
1 change: 1 addition & 0 deletions demo_files/srv/tacd/state.json
@@ -1,6 +1,7 @@
{
"format_version": 1,
"persistent_topics": {
"/v1/tac/display/show_help": false,
"/v1/tac/setup_mode": false
}
}
8 changes: 8 additions & 0 deletions demo_files/usr/share/tacd/update_channels/01_stable.yaml
@@ -0,0 +1,8 @@
name: stable
display_name: Stable
description: |
Official updates bundles provided by the Linux Automation GmbH.
The released bundles are manually tested and signed before publication.
url: |
https://downloads.linux-automation.com/lxatac/software/stable/latest/lxatac-core-bundle-base-lxatac.raucb
polling_interval: "4d"
9 changes: 9 additions & 0 deletions demo_files/usr/share/tacd/update_channels/05_testing.yaml
@@ -0,0 +1,9 @@
name: testing
display_name: Testing
description: |
Testing bundles provided by the Linux Automation GmbH.
The released bundles are automatically tested on actual hardware and automatically uploaded.
Receives more frequent but less stable updates than the Stable channel.
url: |
https://downloads.linux-automation.com/lxatac/software/testing/latest/lxatac-core-bundle-base-lxatac.raucb
polling_interval: "24h"
162 changes: 134 additions & 28 deletions openapi.yaml
Expand Up @@ -30,6 +30,17 @@ paths:
'400':
description: The value could not be parsed into a screen name

/v1/tac/display/alerts:
get:
summary: A list of currently pending alerts shown on the local UI
tags: [User Interface]
responses:
'200':
content:
application/json:
schema:
$ref: '#/components/schemas/Alerts'

/v1/tac/display/buttons:
put:
summary: Simulate a button press/release on the device
Expand Down Expand Up @@ -78,6 +89,30 @@ paths:
'400':
description: The value could not be parsed into a boolean

/v1/tac/display/show_help:
get:
summary: Display a help menu on the local screen
tags: [User Interface]
responses:
'200':
content:
application/json:
schema:
type: boolean
put:
summary: Display a help menu on the local screen
tags: [User Interface]
requestBody:
content:
application/json:
schema:
type: boolean
responses:
'204':
description: Help will be shown or hidden as requested
'400':
description: The request could not be parsed as boolean

/v1/tac/led/{led}/pattern:
parameters:
- name: led
Expand Down Expand Up @@ -712,6 +747,43 @@ paths:
'400':
description: The value could not be parsed as string

/v1/tac/update/channels:
get:
summary: Get a list of update channels and available updates
tags: [Updating]
responses:
'200':
content:
application/json:
schema:
$ref: '#/components/schemas/UpdateChannels'

/v1/tac/update/channels/reload:
put:
summary: Request an update of the channels list and update availability
tags: [Updating]
requestBody:
content:
application/json:
schema:
type: boolean
responses:
'204':
description: An update was requested (if true was sent)
'400':
description: The value could not be parsed as boolean

/v1/tac/update/should_reboot:
get:
summary: Should the system be rebooted as there is a new bundle in the other slot?
tags: [Updating]
responses:
'200':
content:
application/json:
schema:
type: boolean

/v1/tac/network/hostname:
get:
summary: Get the systems hostname
Expand Down Expand Up @@ -772,38 +844,40 @@ components:
- System
- IoBus
- Uart
- ScreenSaver
- Breakout
- RebootConfirm
- Rauc

Alerts:
type: array
items:
type: string
enum:
- ScreenSaver
- Locator
- RebootConfirm
- UpdateAvailable
- UpdateInstallation
- Help
- Setup

ButtonEvent:
type: object
properties:
Press:
type: object
properties:
btn:
type: string
enum:
- Upper
- Lower
Release:
type: object
properties:
btn:
type: string
enum:
- Upper
- Lower
dur:
type: string
enum:
- Short
- Long
oneOf:
- required: [Press]
- required: [Release]
type: object
properties:
dir:
type: string
enum:
- Press
- Release
btn:
type: string
enum:
- Upper
- Lower
dur:
type: string
enum:
- Short
- Long

BlinkPattern:
type: object
Expand Down Expand Up @@ -933,6 +1007,38 @@ components:
nesting_depth:
type: number

UpdateChannels:
type: array
items:
type: object
properties:
name:
type: string
display_name:
type: string
description:
type: string
url:
type: string
polling_interval:
type: object
properties:
secs:
type: integer
nanos:
type: integer
enabled:
type: boolean
bundle:
type: object
properties:
compatible:
type: string
version:
type: string,
newer_than_installed:
type: boolean

ServiceStatus:
type: object
properties:
Expand Down
25 changes: 25 additions & 0 deletions src/broker/topic.rs
Expand Up @@ -17,6 +17,7 @@

use std::collections::VecDeque;
use std::marker::PhantomData;
use std::ops::Not;
use std::sync::{Arc, Mutex, Weak};

use async_std::channel::{unbounded, Receiver, Sender, TrySendError};
Expand Down Expand Up @@ -324,6 +325,30 @@ impl<E: Serialize + DeserializeOwned + Clone> Topic<E> {
}
}

impl<E: Serialize + DeserializeOwned + Clone + PartialEq> Topic<E> {
/// Set a new value for the topic and notify subscribers _if the value changed_
///
/// # Arguments
///
/// * `msg` - Value to set the topic to
pub fn set_if_changed(&self, msg: E) {
let msg = Some(msg);

self.modify(|prev| if prev != msg { msg } else { None });
}
}

impl<E: Serialize + DeserializeOwned + Clone + Not + Not<Output = E>> Topic<E> {
/// Toggle the value of a topic
///
/// # Arguments
///
/// * `default` - The value to assume if none was set yet
pub fn toggle(&self, default: E) {
self.modify(|prev| Some(!prev.unwrap_or(default)));
}
}

pub trait AnyTopic: Sync + Send {
fn path(&self) -> &TopicName;
fn web_readable(&self) -> bool;
Expand Down

0 comments on commit 88d20f1

Please sign in to comment.