Skip to content

Commit

Permalink
Remove id: Option<i32> from EntryUpdate and add it to ChangeNotification
Browse files Browse the repository at this point in the history
  • Loading branch information
rafaeling committed Oct 22, 2024
1 parent b66ae28 commit 8a605af
Show file tree
Hide file tree
Showing 7 changed files with 4 additions and 45 deletions.
31 changes: 3 additions & 28 deletions databroker/src/broker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ pub struct QueryField {

#[derive(Debug)]
pub struct ChangeNotification {
pub id: i32,
pub update: EntryUpdate,
pub fields: HashSet<Field>,
}
Expand Down Expand Up @@ -200,8 +201,6 @@ pub struct NotificationError {}

#[derive(Debug, Clone, Default)]
pub struct EntryUpdate {
pub id: Option<i32>,

pub path: Option<String>,

pub datapoint: Option<Datapoint>,
Expand Down Expand Up @@ -759,7 +758,6 @@ impl ChangeSubscription {
let mut update = EntryUpdate::default();
let mut notify_fields = HashSet::new();
// TODO: Perhaps make path optional
update.id = Some(entry.metadata.id);
update.path = Some(entry.metadata.path.clone());
if changed_fields.contains(&Field::Datapoint)
&& fields.contains(&Field::Datapoint)
Expand All @@ -777,6 +775,7 @@ impl ChangeSubscription {
// fill unit field always
update.unit.clone_from(&entry.metadata.unit);
notifications.updates.push(ChangeNotification {
id: *id,
update,
fields: notify_fields,
});
Expand Down Expand Up @@ -816,7 +815,6 @@ impl ChangeSubscription {
let mut update = EntryUpdate::default();
let mut notify_fields = HashSet::new();
// TODO: Perhaps make path optional
update.id = Some(entry.metadata.id);
update.path = Some(entry.metadata.path.clone());
if fields.contains(&Field::Datapoint) {
update.datapoint = Some(entry.datapoint.clone());
Expand All @@ -827,6 +825,7 @@ impl ChangeSubscription {
notify_fields.insert(Field::ActuatorTarget);
}
notifications.updates.push(ChangeNotification {
id: *id,
update,
fields: notify_fields,
});
Expand Down Expand Up @@ -2014,7 +2013,6 @@ mod tests {
.update_entries([(
id1,
EntryUpdate {
id: Some(id1),
path: None,
datapoint: Some(Datapoint {
ts: time1,
Expand Down Expand Up @@ -2047,7 +2045,6 @@ mod tests {
.update_entries([(
id1,
EntryUpdate {
id: Some(id1),
path: None,
datapoint: Some(Datapoint {
ts: time1,
Expand All @@ -2070,7 +2067,6 @@ mod tests {
.update_entries([(
id2,
EntryUpdate {
id: Some(id2),
path: None,
datapoint: None,
actuator_target: Some(Some(Datapoint {
Expand Down Expand Up @@ -2143,7 +2139,6 @@ mod tests {
.update_entries([(
id1,
EntryUpdate {
id: Some(id1),
path: None,
datapoint: Some(Datapoint {
ts: SystemTime::now(),
Expand All @@ -2170,7 +2165,6 @@ mod tests {
.update_entries([(
id1,
EntryUpdate {
id: Some(id1),
path: None,
datapoint: None,
actuator_target: None,
Expand All @@ -2193,7 +2187,6 @@ mod tests {
.update_entries([(
id1,
EntryUpdate {
id: Some(id1),
path: None,
datapoint: None,
actuator_target: None,
Expand All @@ -2213,7 +2206,6 @@ mod tests {
.update_entries([(
id1,
EntryUpdate {
id: Some(id1),
path: None,
datapoint: Some(Datapoint {
ts: time1,
Expand Down Expand Up @@ -2285,7 +2277,6 @@ mod tests {
.update_entries([(
id1,
EntryUpdate {
id: Some(id1),
path: None,
datapoint: Some(Datapoint {
ts: SystemTime::now(),
Expand Down Expand Up @@ -2388,7 +2379,6 @@ mod tests {
.update_entries([(
id1,
EntryUpdate {
id: Some(id1),
path: None,
datapoint: Some(Datapoint {
ts: SystemTime::now(),
Expand Down Expand Up @@ -2472,7 +2462,6 @@ mod tests {
.update_entries([(
id1,
EntryUpdate {
id: Some(id1),
path: None,
datapoint: Some(Datapoint {
ts: SystemTime::now(),
Expand Down Expand Up @@ -2532,7 +2521,6 @@ mod tests {
.update_entries([(
id1,
EntryUpdate {
id: Some(id1),
path: None,
datapoint: Some(Datapoint {
ts: SystemTime::now(),
Expand Down Expand Up @@ -2631,7 +2619,6 @@ mod tests {
(
id1,
EntryUpdate {
id: Some(id1),
path: None,
datapoint: Some(Datapoint {
ts: SystemTime::now(),
Expand All @@ -2649,7 +2636,6 @@ mod tests {
(
id2,
EntryUpdate {
id: Some(id2),
path: None,
datapoint: Some(Datapoint {
ts: SystemTime::now(),
Expand Down Expand Up @@ -2713,7 +2699,6 @@ mod tests {
.update_entries([(
id,
EntryUpdate {
id: Some(id),
path: None,
datapoint: Some(Datapoint {
ts,
Expand Down Expand Up @@ -2779,7 +2764,6 @@ mod tests {
.update_entries([(
id,
EntryUpdate {
id: Some(id),
path: None,
datapoint: Some(Datapoint {
ts,
Expand Down Expand Up @@ -2860,7 +2844,6 @@ mod tests {
.update_entries([(
id,
EntryUpdate {
id: Some(id),
path: None,
datapoint: Some(Datapoint {
ts,
Expand Down Expand Up @@ -2917,7 +2900,6 @@ mod tests {
.update_entries([(
id,
EntryUpdate {
id: Some(id),
path: None,
datapoint: Some(Datapoint {
ts,
Expand Down Expand Up @@ -2973,7 +2955,6 @@ mod tests {
.update_entries([(
id,
EntryUpdate {
id: Some(id),
path: None,
datapoint: Some(Datapoint {
ts,
Expand Down Expand Up @@ -3026,7 +3007,6 @@ mod tests {
.update_entries([(
id,
EntryUpdate {
id: Some(id),
path: None,
datapoint: Some(Datapoint {
ts,
Expand Down Expand Up @@ -3056,7 +3036,6 @@ mod tests {
.update_entries([(
id,
EntryUpdate {
id: Some(id),
path: None,
datapoint: Some(Datapoint {
ts,
Expand Down Expand Up @@ -3114,7 +3093,6 @@ mod tests {
.update_entries([(
id,
EntryUpdate {
id: Some(id),
path: None,
datapoint: Some(Datapoint {
ts,
Expand Down Expand Up @@ -3144,7 +3122,6 @@ mod tests {
.update_entries([(
id,
EntryUpdate {
id: Some(id),
path: None,
datapoint: Some(Datapoint {
ts,
Expand Down Expand Up @@ -3205,7 +3182,6 @@ mod tests {
.update_entries([(
id,
EntryUpdate {
id: Some(id),
path: None,
datapoint: Some(Datapoint {
ts,
Expand Down Expand Up @@ -3293,7 +3269,6 @@ mod tests {
.update_entries([(
id1,
EntryUpdate {
id: Some(id1),
path: None,
datapoint: Some(Datapoint {
ts: SystemTime::now(),
Expand Down
1 change: 0 additions & 1 deletion databroker/src/grpc/kuksa_val_v1/val.rs
Original file line number Diff line number Diff line change
Expand Up @@ -977,7 +977,6 @@ impl broker::EntryUpdate {
None
};
Self {
id: None,
path: None,
datapoint,
actuator_target,
Expand Down
11 changes: 1 addition & 10 deletions databroker/src/grpc/kuksa_val_v2/val.rs
Original file line number Diff line number Diff line change
Expand Up @@ -676,7 +676,6 @@ impl proto::val_server::Val for broker::DataBroker {
Err(err) => return Err(err),
},
broker::EntryUpdate {
id: None,
path: None,
datapoint: Some(broker::Datapoint::from(&request.data_point.unwrap())),
actuator_target: None,
Expand Down Expand Up @@ -983,7 +982,6 @@ async fn publish_values(
(
*id,
broker::EntryUpdate {
id: Some(*id),
path: None,
datapoint: Some(broker::Datapoint::from(datapoint)),
actuator_target: None,
Expand Down Expand Up @@ -1090,13 +1088,7 @@ fn convert_to_proto_stream_id(
None => None,
};
if let Some(dp) = update_datapoint {
entries.insert(
update
.update
.id
.expect("Something wrong with update id of subscriptions!"),
dp,
);
entries.insert(update.id, dp);
}
}
let response = proto::SubscribeByIdResponse { entries };
Expand Down Expand Up @@ -1142,7 +1134,6 @@ mod tests {
.update_entries([(
entry_id,
broker::EntryUpdate {
id: Some(entry_id),
path: None,
datapoint: Some(broker::Datapoint {
//ts: std::time::SystemTime::now(),
Expand Down
1 change: 0 additions & 1 deletion databroker/src/grpc/sdv_databroker_v1/broker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,6 @@ impl proto::broker_server::Broker for broker::DataBroker {
ids.push((
metadata.id,
broker::EntryUpdate {
id: Some(metadata.id),
path: None,
datapoint: None,
actuator_target: Some(Some(broker::Datapoint::from(
Expand Down
2 changes: 0 additions & 2 deletions databroker/src/grpc/sdv_databroker_v1/collector.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ impl proto::collector_server::Collector for broker::DataBroker {
(
*id,
broker::EntryUpdate {
id: Some(*id),
path: None,
datapoint: Some(broker::Datapoint::from(datapoint)),
actuator_target: None,
Expand Down Expand Up @@ -123,7 +122,6 @@ impl proto::collector_server::Collector for broker::DataBroker {
(
*id,
broker::EntryUpdate {
id: Some(*id),
path: None,
datapoint: Some(broker::Datapoint::from(datapoint)),
actuator_target: None,
Expand Down
2 changes: 0 additions & 2 deletions databroker/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,6 @@ async fn add_kuksa_attribute(
let ids = [(
id,
broker::EntryUpdate {
id: Some(id),
datapoint: Some(broker::Datapoint {
ts: std::time::SystemTime::now(),
source_ts: None,
Expand Down Expand Up @@ -135,7 +134,6 @@ async fn read_metadata_file<'a, 'b>(
let ids = [(
id,
broker::EntryUpdate {
id: Some(id),
datapoint: Some(broker::Datapoint {
ts: std::time::SystemTime::now(),
source_ts: None,
Expand Down
1 change: 0 additions & 1 deletion databroker/src/viss/v2/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,6 @@ impl Viss for Server {
let update = value
.try_into_type(&metadata.data_type)
.map(|actuator_target| broker::EntryUpdate {
id: None,
path: None,
datapoint: None,
actuator_target: Some(Some(broker::Datapoint {
Expand Down

0 comments on commit 8a605af

Please sign in to comment.