1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
//! # Nik's Open-source Smart Home Platform Client Library
//!
//! This crate is designed to serve as an easy to use API to communicate with the [NOSHP Server](https://github.com/niknik3610/IoT_Platform).
//!
//! # Example
//! This is a simple example of how to use this library. It will the server about two buttons
//! (defined in the config.toml file): "Turn On" and "Turn Off".
//! 
//! When either of these buttons are pressed, the callback assigned to them will be called, in this
//! case printing their respective actions. 
//!
//! The callback can have state assigned to it, and in the future will contain 
//! information about the user's actions. For example if they input a number into a field, this will be 
//! displayed in the request (not implemented yet).
//!
//! ```
//! #[derive(Default)]
//! struct ExampleState { 
//!     text: String,
//! }
//! impl State for ExampleState {}
//! pub const SERVER_IP: &str = "http://[::1]:50051";
//! 
//! const CONFIG_PATH: &str = "./example_config.toml";
//! #[tokio::main]
//! async fn main() -> Result<(), Box<dyn Error>> {
//!     let config = ClientConfig::load_config(CONFIG_PATH);
//!     let config = match config {
//!         Ok(r) => r,
//!         Err(e) => {
//!             eprintln!("Error loading config: {}", e.to_string());
//!             println!("Loading default config...");
//!             ParsedConfig::default()
//!         }
//!     };
//!
//!     let client_handler = ClientHandler::new();
//!
//!     client_handler
//!     .add_state(ExampleState { text: String::from("hello world") })
//!     .add_callback("Turn On", Box::new(turn_on_led))
//!     .add_callback("Turn Off", Box::new(turn_off_led))
//!     .run(config, String::from(SERVER_IP)).await.unwrap();
//!     return Ok(());
//! }
//!
//! fn turn_on_led(state: &mut ExampleState, req: Request) {
//!     println!("turned on led");
//! }
//! fn turn_off_led(state: &mut ExampleState, req: Request) {
//!     println!("turned off led");
//! } 
//! ```

pub mod client;
pub mod client_config;
pub mod client_types;

mod client_connection;
mod client_polling;
mod client_registration;