[][src]Crate kubos_app

A simple API to make standalone Rust applications with high-level hooks for mission life-cycle management

Examples

use failure::{bail, Error};
use kubos_app::*;
use std::time::Duration;

struct MyApp;

impl AppHandler for MyApp {
  fn on_boot(&self, _args: Vec<String>) -> Result<(), Error> {
    println!("OnBoot logic");

    let request = r#"mutation {
            power(state: ON) {
                success
            }
        }"#;

    match query(&ServiceConfig::new("radio-service")?, request, Some(Duration::from_secs(1))) {
        Err(error) => bail!("Failed to communicate with radio service: {}", error),
        Ok(data) => {
            if let Some(success) = data.get("power")
                .and_then(|power| power.get("success"))
            {
                match success.as_bool() {
                    Some(true) => println!("Successfully turned on radio"),
                    Some(false) => eprintln!("Failed to turn on radio"),
                    None => eprintln!("Failed to fetch radio power state")
                }
            } else {
                bail!("Failed to fetch radio power state");
            }
        }
    }

    Ok(())
  }
  fn on_command(&self, _args: Vec<String>) -> Result<(), Error> {
    println!("OnCommand logic");
    Ok(())
  }
}

fn main() -> Result<(), Error> {
    let app = MyApp { };
    app_main!(&app)?;
    Ok(())
}

Macros

app_main

A helper macro which detects the requested run level and calls the appropriate handler function. Logging will be set up automatically for the application. The log name will be taken from the package name specified in the application's Cargo.toml file. Note: Any hyphens will be automatically converted to underscores (test-app -> test_app)

Structs

ServiceConfig

KubOS config used by either Apps or Services. KubOS config files use the TOML format, and can may contain multiple named Categories. Typically each category corresponds to an App or Service name. This allows one config file to store configuration for multiple Apps / Services at a time.

Enums

RunLevel

The different ways an application can be started

Traits

AppHandler

Common trait which is used to ensure handlers for all required run levels are defined

Functions

app_start

The entry point for all KubOS applications. The preferred way to use this application is through the app_main! macro

query

Execute a GraphQL query against a running KubOS Service using UDP.