Skip to main content

Crate gc_gateway_controller

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§

config_database 🔒
gateway_controller
gateway_controller_builder 🔒
models 🔒
plugin_callback_handler 🔒

Structs§

GCDatapointConfig
Config for a datapoint
GCDatapointMetadata
Metadata for a datapoint
GCGatewayControllerBuilder
The GCGatewayControllerBuilder is a builder for the GCGatewayController Setting that cannot be changed at runtime need be set here.
GCPluginInstanceInfo
Plugin Instance Information

Traits§

GCGatewayInterface
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.

Type Aliases§

GCControllerPluginInstance
GCControllerPluginInstanceConfig