There are peculiar ways status-report should be interpreted in various contexts. Easier to manage this within the Data Model.
84 lines
2.1 KiB
Rust
84 lines
2.1 KiB
Rust
/*
|
|
*
|
|
* Copyright (c) 2020-2022 Project CHIP Authors
|
|
*
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
* you may not use this file except in compliance with the License.
|
|
* You may obtain a copy of the License at
|
|
*
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
*
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
* See the License for the specific language governing permissions and
|
|
* limitations under the License.
|
|
*/
|
|
|
|
use crate::{
|
|
error::Error,
|
|
tlv::TLVWriter,
|
|
transport::{exchange::Exchange, proto_demux::ResponseRequired, session::Session},
|
|
};
|
|
|
|
use self::{
|
|
core::OpCode,
|
|
messages::msg::{InvReq, ReadReq, StatusResp, SubscribeReq, WriteReq},
|
|
};
|
|
|
|
#[derive(PartialEq)]
|
|
pub enum TransactionState {
|
|
Ongoing,
|
|
Complete,
|
|
}
|
|
pub struct Transaction<'a> {
|
|
pub state: TransactionState,
|
|
pub session: &'a mut Session,
|
|
pub exch: &'a mut Exchange,
|
|
}
|
|
|
|
pub trait InteractionConsumer {
|
|
fn consume_invoke_cmd(
|
|
&self,
|
|
req: &InvReq,
|
|
trans: &mut Transaction,
|
|
tw: &mut TLVWriter,
|
|
) -> Result<(), Error>;
|
|
|
|
fn consume_read_attr(
|
|
&self,
|
|
req: &ReadReq,
|
|
trans: &mut Transaction,
|
|
tw: &mut TLVWriter,
|
|
) -> Result<(), Error>;
|
|
|
|
fn consume_write_attr(
|
|
&self,
|
|
req: &WriteReq,
|
|
trans: &mut Transaction,
|
|
tw: &mut TLVWriter,
|
|
) -> Result<(), Error>;
|
|
|
|
fn consume_status_report(
|
|
&self,
|
|
_req: &StatusResp,
|
|
_trans: &mut Transaction,
|
|
_tw: &mut TLVWriter,
|
|
) -> Result<(OpCode, ResponseRequired), Error>;
|
|
|
|
fn consume_subscribe(
|
|
&self,
|
|
_req: &SubscribeReq,
|
|
_trans: &mut Transaction,
|
|
_tw: &mut TLVWriter,
|
|
) -> Result<(OpCode, ResponseRequired), Error>;
|
|
}
|
|
|
|
pub struct InteractionModel {
|
|
consumer: Box<dyn InteractionConsumer>,
|
|
}
|
|
pub mod command;
|
|
pub mod core;
|
|
pub mod messages;
|
|
pub mod read;
|
|
pub mod write;
|