diff --git a/databroker-cli/src/kuksa_cli.rs b/databroker-cli/src/kuksa_cli.rs index 5dd91099..1b86f054 100644 --- a/databroker-cli/src/kuksa_cli.rs +++ b/databroker-cli/src/kuksa_cli.rs @@ -312,7 +312,7 @@ pub async fn kuksa_main(_cli: Cli) -> Result<(), Box> { } } Err(err) => { - cli::print_error(cmd, &format!("Malformed token: {err}"))? + cli::print_error(cmd, format!("Malformed token: {err}"))? } } } @@ -350,12 +350,12 @@ pub async fn kuksa_main(_cli: Cli) -> Result<(), Box> { } } Err(err) => { - cli::print_error(cmd, &format!("Malformed token: {err}"))? + cli::print_error(cmd, format!("Malformed token: {err}"))? } }, Err(err) => cli::print_error( cmd, - &format!( + format!( "Failed to open token file \"{token_filename}\": {err}" ), )?, diff --git a/databroker-cli/src/sdv_cli.rs b/databroker-cli/src/sdv_cli.rs index 398a866c..e52dd642 100644 --- a/databroker-cli/src/sdv_cli.rs +++ b/databroker-cli/src/sdv_cli.rs @@ -256,7 +256,7 @@ pub async fn sdv_main(_cli: Cli) -> Result<(), Box> { } } Err(err) => { - cli::print_error(cmd, &format!("Malformed token: {err}"))? + cli::print_error(cmd, format!("Malformed token: {err}"))? } } } @@ -295,12 +295,12 @@ pub async fn sdv_main(_cli: Cli) -> Result<(), Box> { } } Err(err) => { - cli::print_error(cmd, &format!("Malformed token: {err}"))? + cli::print_error(cmd, format!("Malformed token: {err}"))? } }, Err(err) => cli::print_error( cmd, - &format!( + format!( "Failed to open token file \"{token_filename}\": {err}" ), )?, diff --git a/databroker/src/broker.rs b/databroker/src/broker.rs index cbeb9c8c..faba9423 100644 --- a/databroker/src/broker.rs +++ b/databroker/src/broker.rs @@ -15,7 +15,7 @@ use crate::permissions::{PermissionError, Permissions}; pub use crate::types; use crate::query; -pub use crate::types::{ChangeType, DataType, DataValue, EntryType, ValueFailure}; +pub use crate::types::{ChangeType, DataType, DataValue, EntryType}; use tokio::sync::{broadcast, mpsc, RwLock}; use tokio_stream::wrappers::ReceiverStream; diff --git a/databroker/src/grpc/kuksa_val_v2/conversions.rs b/databroker/src/grpc/kuksa_val_v2/conversions.rs index 1d7aae72..bb80817c 100644 --- a/databroker/src/grpc/kuksa_val_v2/conversions.rs +++ b/databroker/src/grpc/kuksa_val_v2/conversions.rs @@ -11,7 +11,6 @@ // * SPDX-License-Identifier: Apache-2.0 // ********************************************************************************/ use databroker_proto::kuksa::val::v2 as proto; -use proto::datapoint::{ValueState::Failure, ValueState::Value}; use crate::broker; @@ -48,151 +47,125 @@ impl From for Option { match from.value { broker::DataValue::NotAvailable => None, broker::DataValue::Bool(value) => Some(proto::Datapoint { - value_state: Some(proto::datapoint::ValueState::Value(proto::Value { - typed_value: Some(proto::value::TypedValue::Bool(value)), - })), timestamp: Some(from.ts.into()), + value: Some(proto::Value { + typed_value: Some(proto::value::TypedValue::Bool(value)), + }), }), broker::DataValue::String(value) => Some(proto::Datapoint { - value_state: Some(proto::datapoint::ValueState::Value(proto::Value { - typed_value: Some(proto::value::TypedValue::String(value)), - })), timestamp: Some(from.ts.into()), + value: Some(proto::Value { + typed_value: Some(proto::value::TypedValue::String(value)), + }), }), broker::DataValue::Int32(value) => Some(proto::Datapoint { - value_state: Some(proto::datapoint::ValueState::Value(proto::Value { - typed_value: Some(proto::value::TypedValue::Int32(value)), - })), timestamp: Some(from.ts.into()), + value: Some(proto::Value { + typed_value: Some(proto::value::TypedValue::Int32(value)), + }), }), broker::DataValue::Int64(value) => Some(proto::Datapoint { - value_state: Some(proto::datapoint::ValueState::Value(proto::Value { - typed_value: Some(proto::value::TypedValue::Int64(value)), - })), timestamp: Some(from.ts.into()), + value: Some(proto::Value { + typed_value: Some(proto::value::TypedValue::Int64(value)), + }), }), broker::DataValue::Uint32(value) => Some(proto::Datapoint { - value_state: Some(proto::datapoint::ValueState::Value(proto::Value { - typed_value: Some(proto::value::TypedValue::Uint32(value)), - })), timestamp: Some(from.ts.into()), + value: Some(proto::Value { + typed_value: Some(proto::value::TypedValue::Uint32(value)), + }), }), broker::DataValue::Uint64(value) => Some(proto::Datapoint { - value_state: Some(proto::datapoint::ValueState::Value(proto::Value { - typed_value: Some(proto::value::TypedValue::Uint64(value)), - })), timestamp: Some(from.ts.into()), + value: Some(proto::Value { + typed_value: Some(proto::value::TypedValue::Uint64(value)), + }), }), broker::DataValue::Float(value) => Some(proto::Datapoint { - value_state: Some(proto::datapoint::ValueState::Value(proto::Value { - typed_value: Some(proto::value::TypedValue::Float(value)), - })), timestamp: Some(from.ts.into()), + value: Some(proto::Value { + typed_value: Some(proto::value::TypedValue::Float(value)), + }), }), broker::DataValue::Double(value) => Some(proto::Datapoint { - value_state: Some(proto::datapoint::ValueState::Value(proto::Value { - typed_value: Some(proto::value::TypedValue::Double(value)), - })), timestamp: Some(from.ts.into()), + value: Some(proto::Value { + typed_value: Some(proto::value::TypedValue::Double(value)), + }), }), broker::DataValue::BoolArray(values) => Some(proto::Datapoint { - value_state: Some(proto::datapoint::ValueState::Value(proto::Value { + timestamp: Some(from.ts.into()), + value: Some(proto::Value { typed_value: Some(proto::value::TypedValue::BoolArray(proto::BoolArray { values, })), - })), - timestamp: Some(from.ts.into()), + }), }), broker::DataValue::StringArray(values) => Some(proto::Datapoint { - value_state: Some(proto::datapoint::ValueState::Value(proto::Value { + timestamp: Some(from.ts.into()), + value: Some(proto::Value { typed_value: Some(proto::value::TypedValue::StringArray(proto::StringArray { values, })), - })), - timestamp: Some(from.ts.into()), + }), }), broker::DataValue::Int32Array(values) => Some(proto::Datapoint { - value_state: Some(proto::datapoint::ValueState::Value(proto::Value { + timestamp: Some(from.ts.into()), + value: Some(proto::Value { typed_value: Some(proto::value::TypedValue::Int32Array(proto::Int32Array { values, })), - })), - timestamp: Some(from.ts.into()), + }), }), broker::DataValue::Int64Array(values) => Some(proto::Datapoint { - value_state: Some(proto::datapoint::ValueState::Value(proto::Value { + timestamp: Some(from.ts.into()), + value: Some(proto::Value { typed_value: Some(proto::value::TypedValue::Int64Array(proto::Int64Array { values, })), - })), - timestamp: Some(from.ts.into()), + }), }), broker::DataValue::Uint32Array(values) => Some(proto::Datapoint { - value_state: Some(proto::datapoint::ValueState::Value(proto::Value { + timestamp: Some(from.ts.into()), + value: Some(proto::Value { typed_value: Some(proto::value::TypedValue::Uint32Array(proto::Uint32Array { values, })), - })), - timestamp: Some(from.ts.into()), + }), }), broker::DataValue::Uint64Array(values) => Some(proto::Datapoint { - value_state: Some(proto::datapoint::ValueState::Value(proto::Value { + timestamp: Some(from.ts.into()), + value: Some(proto::Value { typed_value: Some(proto::value::TypedValue::Uint64Array(proto::Uint64Array { values, })), - })), - timestamp: Some(from.ts.into()), + }), }), broker::DataValue::FloatArray(values) => Some(proto::Datapoint { - value_state: Some(proto::datapoint::ValueState::Value(proto::Value { + timestamp: Some(from.ts.into()), + value: Some(proto::Value { typed_value: Some(proto::value::TypedValue::FloatArray(proto::FloatArray { values, })), - })), - timestamp: Some(from.ts.into()), + }), }), broker::DataValue::DoubleArray(values) => Some(proto::Datapoint { - value_state: Some(proto::datapoint::ValueState::Value(proto::Value { + timestamp: Some(from.ts.into()), + value: Some(proto::Value { typed_value: Some(proto::value::TypedValue::DoubleArray(proto::DoubleArray { values, })), - })), - timestamp: Some(from.ts.into()), + }), }), } } } -impl From<&broker::ValueFailure> for i32 { - fn from(from: &broker::ValueFailure) -> Self { - match from { - broker::ValueFailure::Unspecified => 0, - broker::ValueFailure::InvalidValue => 1, - broker::ValueFailure::NotProvided => 2, - broker::ValueFailure::UnknownSignal => 3, - broker::ValueFailure::AccessDenied => 4, - broker::ValueFailure::InternalError => 5, - } - } -} - -impl From<&proto::ValueFailure> for broker::ValueFailure { - fn from(value_failure: &proto::ValueFailure) -> Self { - match value_failure { - proto::ValueFailure::Unspecified => broker::ValueFailure::Unspecified, - proto::ValueFailure::InvalidValue => broker::ValueFailure::InvalidValue, - proto::ValueFailure::NotProvided => broker::ValueFailure::NotProvided, - proto::ValueFailure::UnknownSignal => broker::ValueFailure::UnknownSignal, - proto::ValueFailure::AccessDenied => broker::ValueFailure::AccessDenied, - proto::ValueFailure::InternalError => broker::ValueFailure::InternalError, - } - } -} - impl From<&proto::Datapoint> for broker::DataValue { fn from(datapoint: &proto::Datapoint) -> Self { - match &datapoint.value_state { - Some(Value(value)) => match &value.typed_value { + match &datapoint.value { + Some(value) => match &value.typed_value { Some(proto::value::TypedValue::String(value)) => { broker::DataValue::String(value.to_owned()) } @@ -229,7 +202,6 @@ impl From<&proto::Datapoint> for broker::DataValue { } None => broker::DataValue::NotAvailable, }, - Some(Failure(_)) => broker::DataValue::NotAvailable, None => broker::DataValue::NotAvailable, } } diff --git a/databroker/src/grpc/kuksa_val_v2/val.rs b/databroker/src/grpc/kuksa_val_v2/val.rs index 95f2061b..54fcf920 100644 --- a/databroker/src/grpc/kuksa_val_v2/val.rs +++ b/databroker/src/grpc/kuksa_val_v2/val.rs @@ -22,7 +22,7 @@ use crate::{ use databroker_proto::kuksa::val::v2::{ self as proto, open_provider_stream_request::Action::{ - BatchActuateStreamResponse, ProvidedActuation, PublishValuesRequest, + BatchActuateStreamResponse, ProvideActuationRequest, PublishValuesRequest, }, open_provider_stream_response, OpenProviderStreamResponse, PublishValuesResponse, }; @@ -133,19 +133,19 @@ impl proto::val_server::Val for broker::DataBroker { } } - type SubscribeIdStream = Pin< + type SubscribeByIdStream = Pin< Box< - dyn Stream> + dyn Stream> + Send + Sync + 'static, >, >; - async fn subscribe_id( + async fn subscribe_by_id( &self, - _request: tonic::Request, - ) -> Result, tonic::Status> { + _request: tonic::Request, + ) -> Result, tonic::Status> { Err(tonic::Status::new( tonic::Code::Unimplemented, "Unimplemented", @@ -361,7 +361,7 @@ impl proto::val_server::Val for broker::DataBroker { /// ``` /// `request`: /// OpenProviderStreamRequest { - /// action: ProvidedActuation { + /// action: ProvideActuationRequest { /// { /// signal: id: 30, /// }, @@ -374,7 +374,7 @@ impl proto::val_server::Val for broker::DataBroker { /// /// `response`: /// OpenProviderStreamStream { - /// action: ProvideActuatorResponse { } + /// action: ProvideActuattionResponse { } /// } /// ``` /// @@ -434,7 +434,7 @@ impl proto::val_server::Val for broker::DataBroker { /// /// * `request` - The request should contain the necessary permissions if the databroker is started with secure mode. /// The request `OpenProviderStreamRequest` can contain messages according to the action: - /// - Action 1: `ProvidedActuation` + /// - Action 1: `ProvideActuationRequest` /// - Action 2: `PublishValuesRequest` /// - Action 3: `BatchActuateStreamResponse` /// @@ -482,7 +482,7 @@ impl proto::val_server::Val for broker::DataBroker { match request { Some(req) => { match req.action { - Some(ProvidedActuation(_provided_actuation)) => { + Some(ProvideActuationRequest(_provide_actuation_request)) => { if let Err(err) = response_stream_sender.send(Err(tonic::Status::new(tonic::Code::Unimplemented, "Unimplemented"))).await { debug!("Failed to send error response: {}", err); } @@ -656,7 +656,7 @@ mod tests { use crate::{broker::DataBroker, permissions}; use databroker_proto::kuksa::val::v2::val_server::Val; use proto::open_provider_stream_response::Action::{ - BatchActuateStreamRequest, ProvideActuatorResponse, PublishValuesResponse, + BatchActuateStreamRequest, ProvideActuationResponse, PublishValuesResponse, }; use proto::{open_provider_stream_request, OpenProviderStreamRequest, PublishValuesRequest}; @@ -677,7 +677,7 @@ mod tests { { match (response.get(key), expected_response.get(key)) { (Some(entry1), Some(entry2)) => { - assert_eq!(entry1.value_state, entry2.value_state); + assert_eq!(entry1.value, entry2.value); } (Some(entry1), None) => { assert!(f, "Key '{}' is only in response: {:?}", key, entry1) @@ -729,7 +729,7 @@ mod tests { Some(proto::Datapoint { timestamp, - value_state: Some(proto::datapoint::ValueState::Value(value)), + value: Some(value), }) }, }; @@ -785,7 +785,7 @@ mod tests { Some(proto::Datapoint { timestamp, - value_state: Some(proto::datapoint::ValueState::Value(value)), + value: Some(value), }) }, }; @@ -852,9 +852,9 @@ mod tests { }), data_point: Some(proto::Datapoint { timestamp: None, - value_state: Some(proto::datapoint::ValueState::Value(proto::Value { + value: Some(proto::Value { typed_value: Some(proto::value::TypedValue::Bool(true)), - })), + }), }), }); request @@ -880,9 +880,9 @@ mod tests { }), data_point: Some(proto::Datapoint { timestamp: None, - value_state: Some(proto::datapoint::ValueState::Value(proto::Value { + value: Some(proto::Value { typed_value: Some(proto::value::TypedValue::Bool(false)), - })), + }), }), }); request_false @@ -917,11 +917,9 @@ mod tests { "test.datapoint1".to_string(), proto::Datapoint { timestamp: None, - value_state: Some(proto::datapoint::ValueState::Value( - proto::Value { - typed_value: Some(proto::value::TypedValue::Bool(true)), - }, - )), + value: Some(proto::Value { + typed_value: Some(proto::value::TypedValue::Bool(true)), + }), }, ); } @@ -932,11 +930,9 @@ mod tests { "test.datapoint1".to_string(), proto::Datapoint { timestamp: None, - value_state: Some(proto::datapoint::ValueState::Value( - proto::Value { - typed_value: Some(proto::value::TypedValue::Bool(false)), - }, - )), + value: Some(proto::Value { + typed_value: Some(proto::value::TypedValue::Bool(false)), + }), }, ); } @@ -993,7 +989,7 @@ mod tests { let datapoint = proto::Datapoint { timestamp, - value_state: Some(proto::datapoint::ValueState::Value(value)), + value: Some(value), }; let mut map = HashMap::new(); @@ -1020,7 +1016,7 @@ mod tests { while let Some(value) = receiver.recv().await { match value { Ok(value) => match value.action { - Some(ProvideActuatorResponse(_)) => { + Some(ProvideActuationResponse(_)) => { panic!("Should not happen") } Some(PublishValuesResponse(publish_values_response)) => { diff --git a/databroker/src/types.rs b/databroker/src/types.rs index ed3f029f..6d9241fd 100644 --- a/databroker/src/types.rs +++ b/databroker/src/types.rs @@ -55,16 +55,6 @@ pub enum ChangeType { Continuous, } -#[derive(Debug, Clone, PartialEq)] -pub enum ValueFailure { - Unspecified, - InvalidValue, - NotProvided, - UnknownSignal, - AccessDenied, - InternalError, -} - #[derive(Debug, Clone, PartialEq)] pub enum DataValue { NotAvailable, diff --git a/databroker/src/viss/v2/conversions.rs b/databroker/src/viss/v2/conversions.rs index e6fcf06c..a209cb6a 100644 --- a/databroker/src/viss/v2/conversions.rs +++ b/databroker/src/viss/v2/conversions.rs @@ -270,7 +270,6 @@ impl From for Value { broker::DataValue::DoubleArray(array) => { Value::Array(array.iter().map(|value| value.to_string()).collect()) } - broker::DataValue::ValueFailure(_) => Value::None, } } } diff --git a/proto/kuksa/val/v2/types.proto b/proto/kuksa/val/v2/types.proto index 9adc6053..ff87d13a 100644 --- a/proto/kuksa/val/v2/types.proto +++ b/proto/kuksa/val/v2/types.proto @@ -18,13 +18,11 @@ import "google/protobuf/timestamp.proto"; option go_package = "kuksa/val/v2"; +// A Datapoint represents a timestamped value. +// The 'value' field can be explicitly 'None', meaning the Datapoint exists but no value is present. message Datapoint { - google.protobuf.Timestamp timestamp = 1; - - oneof value_state { - ValueFailure failure = 2; - Value value = 3; - } + google.protobuf.Timestamp timestamp = 1; // The timestamp of the datapoint. + Value value = 2; // The value associated with the timestamp. If no value is present, this field can be 'None'. } message Value { @@ -147,22 +145,6 @@ message ValueRestrictionString { repeated string allowed_values = 1; } -enum ValueFailure { - // Unspecified value failure, reserved for gRPC backwards compatibility - // (see https://protobuf.dev/programming-guides/dos-donts/#unspecified-enum) - UNSPECIFIED = 0; - // The signal is known and provided, but doesn't have a valid value - INVALID_VALUE = 1; - // The signal is known, but no value is provided currently - NOT_PROVIDED = 2; - // The referred signal is unknown on the system - UNKNOWN_SIGNAL = 3; - // The client does not have the necessary access rights to the signal - ACCESS_DENIED = 4; - // Unexpected internal error - INTERNAL_ERROR = 5; -} - // VSS Data type of a signal // // Protobuf doesn't support int8, int16, uint8 or uint16. diff --git a/proto/kuksa/val/v2/val.proto b/proto/kuksa/val/v2/val.proto index 67d1a86f..fc1c5b3c 100644 --- a/proto/kuksa/val/v2/val.proto +++ b/proto/kuksa/val/v2/val.proto @@ -54,7 +54,7 @@ service VAL { // Returns (GRPC error code): // NOT_FOUND if any of the signals are non-existant. // PERMISSION_DENIED if access is denied for any of the signals. - rpc SubscribeId(SubscribeRequestId) returns (stream SubscribeResponseId); + rpc SubscribeById(SubscribeByIdRequest) returns (stream SubscribeByIdResponse); // Actuate a single actuator // @@ -149,11 +149,11 @@ message SubscribeResponse { map entries = 1; } -message SubscribeRequestId { +message SubscribeByIdRequest { repeated int32 signal_ids = 1; } -message SubscribeResponseId { +message SubscribeByIdResponse { map entries = 1; } @@ -199,11 +199,11 @@ message PublishValuesResponse { map status = 2; } -message ProvidedActuation { +message ProvideActuationRequest { repeated SignalID actuator_identifiers = 1; } -message ProvideActuatorResponse { +message ProvideActuationResponse { } message BatchActuateStreamRequest { @@ -216,7 +216,7 @@ message BatchActuateStreamResponse { message OpenProviderStreamRequest { oneof action { // Inform server of an actuator this provider provides. - ProvidedActuation provided_actuation = 1; + ProvideActuationRequest provide_actuation_request = 1; // Publish a value. PublishValuesRequest publish_values_request = 2; // Sent to acknowledge the acceptance of a batch actuate @@ -228,7 +228,7 @@ message OpenProviderStreamRequest { message OpenProviderStreamResponse { oneof action { // Response to a provide actuator request. - ProvideActuatorResponse provide_actuator_response = 1; + ProvideActuationResponse provide_actuation_response = 1; // Acknowledgement that a published value was received. PublishValuesResponse publish_values_response = 2; // Send a batch actuate request to a provider. @@ -241,6 +241,7 @@ message GetServerInfoRequest { } message GetServerInfoResponse { - string name = 1; - string version = 2; + string name = 1; + string version = 2; + string commit_hash = 3; }