diff --git a/clover-hub/src/server/modman/displays/mod.rs b/clover-hub/src/server/modman/displays/mod.rs index 8726a44..4ffd70b 100644 --- a/clover-hub/src/server/modman/displays/mod.rs +++ b/clover-hub/src/server/modman/displays/mod.rs @@ -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 } diff --git a/clover-hub/src/server/modman/mod.rs b/clover-hub/src/server/modman/mod.rs index 1dcaa2d..f7ccc59 100644 --- a/clover-hub/src/server/modman/mod.rs +++ b/clover-hub/src/server/modman/mod.rs @@ -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; @@ -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. @@ -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) } @@ -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."); diff --git a/clover-hub/src/server/modman/movement/mod.rs b/clover-hub/src/server/modman/movement/mod.rs new file mode 100644 index 0000000..b4a3151 --- /dev/null +++ b/clover-hub/src/server/modman/movement/mod.rs @@ -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 +} diff --git a/clover-hub/src/server/modman/sensors/mod.rs b/clover-hub/src/server/modman/sensors/mod.rs new file mode 100644 index 0000000..bda355a --- /dev/null +++ b/clover-hub/src/server/modman/sensors/mod.rs @@ -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 +} diff --git a/clover-hub/src/server/modman/video/mod.rs b/clover-hub/src/server/modman/video/mod.rs new file mode 100644 index 0000000..91bccf0 --- /dev/null +++ b/clover-hub/src/server/modman/video/mod.rs @@ -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 +} diff --git a/docs/docs/components/CORE/applications/applib/_category_.yaml b/docs/docs/components/CORE/applications/applib/_category_.yaml new file mode 100644 index 0000000..5b4474d --- /dev/null +++ b/docs/docs/components/CORE/applications/applib/_category_.yaml @@ -0,0 +1,3 @@ +link: + type: doc + id: intro diff --git a/docs/docs/components/CORE/applications/applib/intro.md b/docs/docs/components/CORE/applications/applib/intro.md new file mode 100644 index 0000000..25c42f0 --- /dev/null +++ b/docs/docs/components/CORE/applications/applib/intro.md @@ -0,0 +1,3 @@ +# AppLib + +A cross-language framework to write Clover Apps with. diff --git a/docs/docs/components/clover-hub/server/appd/application-manifest.md b/docs/docs/components/clover-hub/server/appd/application-manifest.md new file mode 100644 index 0000000..dd52a90 --- /dev/null +++ b/docs/docs/components/clover-hub/server/appd/application-manifest.md @@ -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. diff --git a/docs/docs/components/clover-hub/server/arbiter/permission-model.md b/docs/docs/components/clover-hub/server/arbiter/permission-model.md new file mode 100644 index 0000000..063d684 --- /dev/null +++ b/docs/docs/components/clover-hub/server/arbiter/permission-model.md @@ -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` | diff --git a/docs/docs/components/clover-hub/server/arbiter/stream-management/_category_.yaml b/docs/docs/components/clover-hub/server/arbiter/stream-management/_category_.yaml new file mode 100644 index 0000000..5b4474d --- /dev/null +++ b/docs/docs/components/clover-hub/server/arbiter/stream-management/_category_.yaml @@ -0,0 +1,3 @@ +link: + type: doc + id: intro diff --git a/docs/docs/components/clover-hub/server/arbiter/stream-management/audio-streams.md b/docs/docs/components/clover-hub/server/arbiter/stream-management/audio-streams.md new file mode 100644 index 0000000..9e27658 --- /dev/null +++ b/docs/docs/components/clover-hub/server/arbiter/stream-management/audio-streams.md @@ -0,0 +1,2 @@ +# Audio Streams + diff --git a/docs/docs/components/clover-hub/server/arbiter/stream-management/intro.md b/docs/docs/components/clover-hub/server/arbiter/stream-management/intro.md new file mode 100644 index 0000000..e78e56f --- /dev/null +++ b/docs/docs/components/clover-hub/server/arbiter/stream-management/intro.md @@ -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. diff --git a/docs/docs/components/clover-hub/server/arbiter/stream-management/video-streams.md b/docs/docs/components/clover-hub/server/arbiter/stream-management/video-streams.md new file mode 100644 index 0000000..62b989d --- /dev/null +++ b/docs/docs/components/clover-hub/server/arbiter/stream-management/video-streams.md @@ -0,0 +1 @@ +# Video Stream diff --git a/docs/docs/components/clover-hub/server/modman/modules/app-modules.md b/docs/docs/components/clover-hub/server/modman/modules/app-modules.md new file mode 100644 index 0000000..2b27b9f --- /dev/null +++ b/docs/docs/components/clover-hub/server/modman/modules/app-modules.md @@ -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. diff --git a/docs/docs/components/clover-hub/server/modman/modules/components/audio.md b/docs/docs/components/clover-hub/server/modman/modules/components/audio.md new file mode 100644 index 0000000..532a474 --- /dev/null +++ b/docs/docs/components/clover-hub/server/modman/modules/components/audio.md @@ -0,0 +1 @@ +# Audio diff --git a/docs/docs/components/clover-hub/server/modman/modules/components/sensor.md b/docs/docs/components/clover-hub/server/modman/modules/components/sensor.md new file mode 100644 index 0000000..8f62f14 --- /dev/null +++ b/docs/docs/components/clover-hub/server/modman/modules/components/sensor.md @@ -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. diff --git a/docs/docs/components/clover-hub/server/modman/modules/components/video.md b/docs/docs/components/clover-hub/server/modman/modules/components/video.md new file mode 100644 index 0000000..102e7fc --- /dev/null +++ b/docs/docs/components/clover-hub/server/modman/modules/components/video.md @@ -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). diff --git a/docs/docs/components/clover-hub/server/modman/modules/module-directory.md b/docs/docs/components/clover-hub/server/modman/modules/module-directory.md new file mode 100644 index 0000000..fe8a931 --- /dev/null +++ b/docs/docs/components/clover-hub/server/modman/modules/module-directory.md @@ -0,0 +1,3 @@ +# Module Directory + + diff --git a/docs/docs/components/clover-hub/server/modman/modules/physical-modules.md b/docs/docs/components/clover-hub/server/modman/modules/physical-modules.md new file mode 100644 index 0000000..bb32b2b --- /dev/null +++ b/docs/docs/components/clover-hub/server/modman/modules/physical-modules.md @@ -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. diff --git a/docs/docs/components/clover-hub/server/renderer/intro.md b/docs/docs/components/clover-hub/server/renderer/intro.md index f1fcbf5..fa46629 100644 --- a/docs/docs/components/clover-hub/server/renderer/intro.md +++ b/docs/docs/components/clover-hub/server/renderer/intro.md @@ -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.