Crate gc_gateway_controller
Expand description
This module provides the main interface for managing the Gateway, including adding datapoints, managing plugins, and handling the message broker.
The controller is built using the GCGatewayControllerBuilder, for using concurrent runtime broker, the start_async_broker method should be called.
§Examples
§Initializing the Gateway Controller
use gc_gateway_controller::{GCGatewayControllerBuilder, GCGatewayInterface};
// Build the gateway controller
let mut controller_builder = GCGatewayControllerBuilder::new();
let controller = controller_builder.build();
// Starts the concurrent message broker
controller.start_async_broker();§Adding a Datapoint
use gc_gateway_controller::{GCGatewayController, GCDatapointMetadata, GCGatewayControllerBuilder, GCGatewayInterface};
// Add a datapoint with ID 0
let metadata = GCDatapointMetadata {
name: "Temperature".to_string(),
unit: "Celsius".to_string(),
description: "Room temperature".to_string(),
buffer_size: 1,
..Default::default()
};
controller.add_datapoint(0, metadata).unwrap();§Adding and Starting a Plugin Instance
ⓘ
// Import necessary modules
use gc_gateway_controller::{GCGatewayController, GCControllerPluginInstanceConfig, GCGatewayControllerBuilder};
use gc_error::GCGatewayError;
// Add a plugin instance
let plugin_path = "path/to/plugin";
let instance_name = "temperature_plugin";
let plugin_config: GCControllerPluginInstanceConfig = serde_json::json!({
"datapoint": 0,
"value": 25
});
controller.add_plugin_instance(instance_name, plugin_path, plugin_config).unwrap();
// Start the plugin instance
controller.start_plugin(instance_name).unwrap();§Publishing a Datapoint Value
// Import necessary modules
use gc_gateway_controller::{GCGatewayController, GCGatewayControllerBuilder, GCGatewayInterface};
use gc_abi::{GCDatapointValue, GCDatapointValueQuality};
// Publish a datapoint value
let value = GCDatapointValue::new_u32(0, 25, 0, GCDatapointValueQuality::new_good());
controller.publish_datapoint(value);Re-exports§
pub use gateway_controller::GCGatewayController;
Modules§
Structs§
- GCDatapoint
Config - Config for a datapoint
- GCDatapoint
Metadata - Metadata for a datapoint
- GCGateway
Controller Builder - The GCGatewayControllerBuilder is a builder for the GCGatewayController Setting that cannot be changed at runtime need be set here.
- GCPlugin
Instance Info - Plugin Instance Information
Traits§
- GCGateway
Interface - The main interface for managing the Gateway, including adding datapoints, managing plugins, and handling the message broker. This can be used to create mock implementations for testing purposes.