Skip to content

Commit

Permalink
Add more docs.
Browse files Browse the repository at this point in the history
  • Loading branch information
Reboot-Codes committed Oct 2, 2024
1 parent cb8df54 commit d6ff1c8
Show file tree
Hide file tree
Showing 20 changed files with 120 additions and 15 deletions.
2 changes: 1 addition & 1 deletion clover-hub/src/server/modman/displays/mod.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::server::evtbuzz::models::Store;
use super::models::{Component, Module};

pub fn init_display(store: &Store, module: Module, id: String, component: Component) -> bool {
pub fn init_display_component(store: &Store, module: Module, id: String, component: Component) -> bool {
true
}
35 changes: 22 additions & 13 deletions clover-hub/src/server/modman/mod.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
pub mod models;
pub mod displays;
pub mod movement;

use std::sync::Arc;
use displays::init_display;
use displays::init_display_component;
use log::{debug, error, info, warn};
use models::Module;
use movement::init_movement_component;
use tokio::sync::mpsc::{unbounded_channel, UnboundedReceiver, UnboundedSender};
use tokio_util::sync::CancellationToken;
use url::Url;
Expand All @@ -23,7 +25,11 @@ async fn init_module(store: &Store, id: String, module: Module) -> (bool, usize)
} else {
for (component_id, component) in module.components.iter() {
if component.component_type.clone().starts_with(&"com.reboot-codes.clover.display".to_string()) {
if init_display(&store, module.clone(), component_id.clone(), component.clone()) { initialized_module_components += 1; }
if init_display_component(&store, module.clone(), component_id.clone(), component.clone()) { initialized_module_components += 1; }
}

if component.component_type.clone().starts_with(&"com.reboot-codes.clover.movement".to_string()) {
if init_movement_component(&store, module.clone(), component_id.clone(), component.clone()) { initialized_module_components += 1; }
}

// TODO: Add init functions for other component types.
Expand All @@ -40,6 +46,19 @@ async fn init_module(store: &Store, id: String, module: Module) -> (bool, usize)
}
}

if initialized_module {
// Update the store with new state of the module.
if initialized_module {
store.modules.lock().await.insert(id.clone(), Module {
module_type: module.module_type.clone(),
pretty_name: module.pretty_name.clone(),
initialized: true,
components: module.components.clone()
});
info!("Module: {} ({}), Initialized!", module.pretty_name.clone(), id.clone());
}
}

(initialized_module, initialized_module_components)
}

Expand All @@ -61,17 +80,7 @@ pub async fn modman_main(
// Initialize modules that were registered already via persistence.
for (id, module) in modules.iter() {
info!("Initializing pre configured module: {}:\n type: {}\n name: {}", id.clone(), module.module_type.clone(), module.pretty_name.clone());
let (initialized, _components_initialized) = init_module(&init_store, id.clone(), module.clone()).await;

// Update the store with new state of the module.
if initialized {
init_store.modules.lock().await.insert(id.clone(), Module {
module_type: module.module_type.clone(),
pretty_name: module.pretty_name.clone(),
initialized: true,
components: module.components.clone()
});
}
let _components_initialized = init_module(&init_store, id.clone(), module.clone()).await;
}
} else {
info!("No pre-configured modules to initialize.");
Expand Down
6 changes: 6 additions & 0 deletions clover-hub/src/server/modman/movement/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
use crate::server::evtbuzz::models::Store;
use super::models::{Component, Module};

pub fn init_movement_component(store: &Store, module: Module, id: String, component: Component) -> bool {
true
}
6 changes: 6 additions & 0 deletions clover-hub/src/server/modman/sensors/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
use crate::server::evtbuzz::models::Store;
use super::models::{Component, Module};

pub fn init_sensor_component(store: &Store, module: Module, id: String, component: Component) -> bool {
true
}
6 changes: 6 additions & 0 deletions clover-hub/src/server/modman/video/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
use crate::server::evtbuzz::models::Store;
use super::models::{Component, Module};

pub fn init_video_component(store: &Store, module: Module, id: String, component: Component) -> bool {
true
}
3 changes: 3 additions & 0 deletions docs/docs/components/CORE/applications/applib/_category_.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
link:
type: doc
id: intro
3 changes: 3 additions & 0 deletions docs/docs/components/CORE/applications/applib/intro.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# AppLib

A cross-language framework to write Clover Apps with.
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Application Manifest

The application manifest is used by [arbiter](/docs/components/clover-hub/server/arbiter/intro) to provide permission consent, and for the application daemon to know how to interface with the application in a higher level manner.
38 changes: 38 additions & 0 deletions docs/docs/components/clover-hub/server/arbiter/permission-model.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# Permission Model

Arbiter manages Clover's permission model. Due to the intimate nature of a Clover installation, Clover is built with attention to security and consent. This also means that all Modules, Applications, and Configuration Interfaces are constrained by an explicit declaration of intent before they're allowed to interface with [evtbuzz](/docs/components/clover-hub/server/evtbuzz/intro) and are only permitted to take specific actions as defined by that declaration.

Declarations are described in manifests. Everything is required to expose a manifest that can be accessed by CloverHub. Custom permissions can be registered and handled by arbiter as well for external APIs that use EvtBuzz.

## Permission types

| identifier |
|-|
| `com.reboot-codes.clover.arbiter.display.out` |
| `com.reboot-codes.clover.arbiter.video.in` |
| `com.reboot-codes.clover.arbiter.sensor.in` |
| `com.reboot-codes.clover.arbiter.sensor.out` |
| `com.reboot-codes.clover.arbiter.movement.in` |
| `com.reboot-codes.clover.arbiter.movement.out` |
| `com.reboot-codes.clover.arbiter.application.status` |
| `com.reboot-codes.clover.arbiter.application.register` |
| `com.reboot-codes.clover.arbiter.application.manage` |
| `com.reboot-codes.clover.arbiter.application.remove` |
| `com.reboot-codes.clover.arbiter.user.list` |
| `com.reboot-codes.clover.arbiter.user.add` |
| `com.reboot-codes.clover.arbiter.user.remove` |
| `com.reboot-codes.clover.arbiter.user.manage` |
| `com.reboot-codes.clover.arbiter.api-key.list` |
| `com.reboot-codes.clover.arbiter.api-key.keys` |
| `com.reboot-codes.clover.arbiter.api-key.add` |
| `com.reboot-codes.clover.arbiter.api-key.remove` |
| `com.reboot-codes.clover.arbiter.api-key.manage` |
| `com.reboot-codes.clover.arbiter.session.list` |
| `com.reboot-codes.clover.arbiter.session.add` |
| `com.reboot-codes.clover.arbiter.session.remove` |
| `com.reboot-codes.clover.arbiter.session.manage` |
| `com.reboot-codes.clover.arbiter.session.change-key` |
| `com.reboot-codes.clover.arbiter.client.list` |
| `com.reboot-codes.clover.arbiter.client.authorize` |
| `com.reboot-codes.clover.arbiter.client.unauthorize` |
| `com.reboot-codes.clover.arbiter.client.disconnect` |
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
link:
type: doc
id: intro
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Audio Streams

Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Stream Management

Arbiter is uniquely responsible for managing video and audio streams that aren't generated by [the renderer](/docs/components/clover-hub/server/renderer/intro) (despite arbiter handling what can actually be written to displays). This is mostly for internal and external cameras, microphones, and speakers.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# Video Stream
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# App Modules

An app module is a module provided by an app managed by the [app daemon](/docs/components/clover-hub/server/appd/intro), and is completely managed by it. The application manifest includes the module config instead of registering it with modman's module directory. This also means that app modules cannot be pre-configured, and will be configured after the app daemon starts up the application registering that module and its components.

This also means that user permission management for the module will actually be handled in the app flows instead of the module flows due to their dynamic nature. This is different from physical modules which are fully managed by modman and arbiter, and their configuration is handled in module flows.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# Audio
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Sensors

A sensor component is a bidirectional data component that encompasses everything from temperature, light, and capacitance measurements, to accent LEDs. Sensor components are used for anything that doesn't have a specialized component. For example, you'd use a sensor component for a bend sensor, however, you'd use a [movement component](/docs/components/clover-hub/server/modman/modules/components/movement) for a brushless motor with an encoder. For more complex LED matrices, you'll want to define a [display component](/docs/components/clover-hub/server/modman/modules/components/display) instead to take advantage of the hardware accelerated, centralized, and programmatically efficient [renderer](/docs/components/clover-hub/server/renderer/intro); however, the development libraries have smooth timing functions for things like LED strips when a sensor component is accessed as something like an LED/set of LEDs, or a servo, etc.
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Video

Video components take in a video stream from the outside for processing and/or reproduction. If you'd like to display video, please see the [display component docs](/docs/components/clover-hub/server/modman/components/display). Video components are managed by modman, however, their streams are exposed and managed by [arbiter](/docs/components/clover-hub/server/arbiter/video-streams), [Spanner Lib](/docs/components/spanner/lib/intro) and [AppLib](/docs/components/CORE/applications/applib/intro) will handle this for you when given the proper permissions so you don't have to worry about talking to arbiter directly.

Video components can be defined as a block device via video4linux, or as an RTSP/RTMP stream that Clover is authorized to reproduce. If your component needs extra authentication, or a specific process to authenticate, create an application that performs those steps, then exposes one of those streams, then register the component as an [app module](/docs/components/clover-hub/server/modman/modules/app-modules).
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Module Directory


Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Physical Modules

A physical piece of hardware who has static functions and statically exposed components. For more complex modules, you'll probably want an [app module](/docs/components/clover-hub/server/modman/modules/app-modules) instead, or you'll have to add a module configuration for each variation of the module to the module directory manually, which can get very unwieldy, very fast.
4 changes: 3 additions & 1 deletion docs/docs/components/clover-hub/server/renderer/intro.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# Renderer

Output independent, 2.5D UI renderer.
Output independent, hardware accelerated, 2.5D renderer.

The renderer service is only responsible for creating, managing, destroying, and writing to an arbitrary number of OpenGL contexts who's frames are captured and sent to [displays](/docs/components/clover-hub/server/modman/modules/components/display) registered with modman when permitted by [arbiter](/docs/components/clover-hub/server/arbiter/intro)'s permission model.

0 comments on commit d6ff1c8

Please sign in to comment.