ivila commented on code in PR #175:
URL: 
https://github.com/apache/incubator-teaclave-trustzone-sdk/pull/175#discussion_r2011233621


##########
examples/client_pool-rs/host/src/pool/connection.rs:
##########
@@ -0,0 +1,81 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you 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 optee_teec::{Context, ErrorKind, Operation, Param, Session, Uuid};
+use optee_teec::{ParamNone, ParamTmpRef, ParamType, ParamValue};
+
+pub struct Connection {
+    session: Session,
+    identity: [u8; proto::IDENTITY_SIZE],
+    last_err: Option<ErrorKind>,
+}
+
+impl Connection {
+    pub fn new(ctx: &mut Context, uuid: Uuid) -> optee_teec::Result<Self> {
+        let mut identity = [0_u8; proto::IDENTITY_SIZE];
+        let session = {
+            let mut operation = Operation::new(
+                0,
+                ParamTmpRef::new_output(&mut identity),
+                ParamNone,
+                ParamNone,
+                ParamNone,
+            );
+            ctx.open_session_with_operation(uuid, &mut operation)?
+        };
+        Ok(Connection {
+            session,
+            identity,
+            last_err: None,
+        })
+    }
+
+    pub fn invoke_command<A: Param, B: Param, C: Param, D: Param>(
+        &mut self,
+        command_id: u32,
+        operation: &mut Operation<A, B, C, D>,
+    ) -> optee_teec::Result<()> {
+        let result = self.session.invoke_command(command_id, operation);
+        self.last_err = match result.as_ref() {
+            Ok(()) => None,
+            Err(err) => Some(err.kind()),
+        };
+        result
+    }
+
+    pub fn identity(&self) -> &[u8] {
+        &self.identity
+    }
+
+    pub fn valid(&self) -> optee_teec::Result<()> {
+        match self.last_err {
+            Some(ErrorKind::TargetDead) => Err(ErrorKind::TargetDead.into()),
+            _ => Ok(()),

Review Comment:
   > Why other errors will be mapped to Ok?
   
   Similar to `ServerDead` in `HTTP`, for `TEEC_Session`, if the TA instance is 
still alive, we consider it valid. The only scenario where this isn’t the case 
is when the TA panics, causing every command call to return 
`ErrorKind::TargetDead` and `ErrorOrigin::TEE`, as specified in the "TEE 
Internal Core API Specification – Public Release v1.3.1".
   
   I add some comments on the method already.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscr...@teaclave.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscr...@teaclave.apache.org
For additional commands, e-mail: dev-h...@teaclave.apache.org

Reply via email to