Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ name = "historyprovider"
description = "historyprovider-rs"
license = "MIT"
repository = "https://github.com/silicon-heaven/historyprovider-rs"
version = "2.5.0"
version = "2.6.0"
edition = "2024"

[[bin]]
Expand Down
6 changes: 3 additions & 3 deletions src/sites.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ use crate::{AlarmWithTimestamp, State};
#[derive(Clone, Copy, Debug, Default, PartialEq)]
pub(crate) enum SiteOnlineStatus {
#[default]
Unknown,
Offline,
Online,
Unknown = 0,
Offline = 1,
Online = 2,
}

#[derive(Clone,Default)]
Expand Down
21 changes: 17 additions & 4 deletions src/tree.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,16 +30,18 @@ use crate::{AlarmWithTimestamp, HpConfig, State};

// History site node methods
const METH_GET_LOG: &str = "getLog";
const METH_ONLINE_STATUS: &str = "onlineStatus";
const METH_ALARM_TABLE: &str = "alarmTable";
const METH_STATE_ALARM_TABLE: &str = "stateAlarmTable";
const METH_ALARM_LOG: &str = "alarmLog";
const METH_PUSH_LOG: &str = "pushLog";

const META_METHOD_LS_FILES: MetaMethod = MetaMethod::new_static(METH_LS_FILES, 0, AccessLevel::Read, "Map|Null", "List", &[], "");
const META_METHOD_GET_LOG: MetaMethod = MetaMethod::new_static(METH_GET_LOG, 0, AccessLevel::Read, "RpcValue", "RpcValue", &[], "");
const META_METHOD_ALARM_TABLE: MetaMethod = MetaMethod::new_static(METH_ALARM_TABLE, 0, AccessLevel::Read, "RpcValue", "RpcValue", &[("alarmmod", Some("Null"))], "");
const META_METHOD_STATE_ALARM_TABLE: MetaMethod = MetaMethod::new_static(METH_STATE_ALARM_TABLE, 0, AccessLevel::Read, "RpcValue", "RpcValue", &[("statealarmmod", Some("Null"))], "");
const META_METHOD_ALARM_LOG: MetaMethod = MetaMethod::new_static(METH_ALARM_LOG, 0, AccessLevel::Read, "RpcValue", "RpcValue", &[], "");
const META_METHOD_ONLINE_STATUS: MetaMethod = MetaMethod::new_static(METH_ONLINE_STATUS, shvrpc::metamethod::Flag::IsGetter as _, AccessLevel::Read, "Null", "i[Unknown,Offline,Online]", &[("onlinestatuschng", None)], "");
const META_METHOD_ALARM_TABLE: MetaMethod = MetaMethod::new_static(METH_ALARM_TABLE, 0, AccessLevel::Read, "Null", "List", &[("alarmmod", Some("Null"))], "");
const META_METHOD_STATE_ALARM_TABLE: MetaMethod = MetaMethod::new_static(METH_STATE_ALARM_TABLE, 0, AccessLevel::Read, "Null", "List", &[("statealarmmod", Some("Null"))], "");
const META_METHOD_ALARM_LOG: MetaMethod = MetaMethod::new_static(METH_ALARM_LOG, 0, AccessLevel::Read, "Map", "List", &[], "");
const META_METHOD_PUSH_LOG: MetaMethod = MetaMethod::new_static(METH_PUSH_LOG, 0, AccessLevel::Write, "RpcValue", "RpcValue", &[], "");

// Root node methods
Expand Down Expand Up @@ -524,6 +526,16 @@ impl AlarmGetter for StateAlarm {
}
}

async fn online_status_handler(
site_path: &str,
app_state: Arc<State>,
) -> Result<RpcValue, RpcError> {
let Some(&site_state) = app_state.online_states.read().await.get(site_path) else {
return Err(RpcError::new(RpcErrorCode::InvalidParam, format!("Wrong onlineStatus path: {site_path}")));
};
Ok((site_state as i32).into())
}

async fn alarmtable_handler<Getter: AlarmGetter>(
site_path: &str,
app_state: Arc<State>,
Expand Down Expand Up @@ -654,7 +666,7 @@ pub(crate) async fn request_handler(
const METHODS: &[MetaMethod] = &[META_METHOD_GET_LOG, META_METHOD_PUSH_LOG];
METHODS
} else if sites_data.typeinfos.get(&path).is_some_and(Result::is_ok) {
const METHODS: &[MetaMethod] = &[META_METHOD_GET_LOG, META_METHOD_ALARM_TABLE, META_METHOD_STATE_ALARM_TABLE, META_METHOD_ALARM_LOG];
const METHODS: &[MetaMethod] = &[META_METHOD_GET_LOG, META_METHOD_ONLINE_STATUS, META_METHOD_ALARM_TABLE, META_METHOD_STATE_ALARM_TABLE, META_METHOD_ALARM_LOG];
METHODS
} else {
const METHODS: &[MetaMethod] = &[META_METHOD_GET_LOG, META_METHOD_ALARM_LOG];
Expand All @@ -677,6 +689,7 @@ pub(crate) async fn request_handler(
}
Method::Other(m) => match m.method() {
METH_GET_LOG => m.resolve(methods, async move || { getlog_handler_rq(&path, &param, app_state).await }),
METH_ONLINE_STATUS => m.resolve(methods, async move || { online_status_handler(&path, app_state).await }),
METH_ALARM_TABLE => m.resolve(methods, async move || { alarmtable_handler::<CommonAlarm>(&path, app_state).await }),
METH_STATE_ALARM_TABLE => m.resolve(methods, async move || { alarmtable_handler::<StateAlarm>(&path, app_state).await }),
METH_ALARM_LOG => m.resolve(methods, async move || { alarmlog_handler(&path, &param, app_state).await }),
Expand Down