• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2022 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #include "executor_messenger_client.h"
17 
18 #include "auth_message_impl.h"
19 #include "iam_logger.h"
20 #include "iam_ptr.h"
21 
22 #define LOG_LABEL UserIam::Common::LABEL_AUTH_EXECUTOR_MGR_SDK
23 
24 namespace OHOS {
25 namespace UserIam {
26 namespace UserAuth {
ExecutorMessengerClient(const sptr<ExecutorMessengerInterface> & messenger)27 ExecutorMessengerClient::ExecutorMessengerClient(const sptr<ExecutorMessengerInterface> &messenger)
28     : messenger_(messenger)
29 {
30 }
31 
SendData(uint64_t scheduleId,uint64_t transNum,ExecutorRole srcRole,ExecutorRole dstRole,const std::shared_ptr<AuthMessage> & msg)32 int32_t ExecutorMessengerClient::SendData(uint64_t scheduleId, uint64_t transNum, ExecutorRole srcRole,
33     ExecutorRole dstRole, const std::shared_ptr<AuthMessage> &msg)
34 {
35     if (messenger_ == nullptr) {
36         IAM_LOGE("messenger is nullptr");
37         return GENERAL_ERROR;
38     }
39     std::vector<uint8_t> buffer;
40     if (msg == nullptr) {
41         IAM_LOGE("msg is nullptr");
42         return GENERAL_ERROR;
43     } else {
44         buffer = AuthMessageImpl::GetMsgBuffer(msg);
45     }
46     return messenger_->SendData(scheduleId, transNum, srcRole, dstRole, buffer);
47 }
48 
Finish(uint64_t scheduleId,ExecutorRole srcRole,int32_t resultCode,const Attributes & finalResult)49 int32_t ExecutorMessengerClient::Finish(uint64_t scheduleId, ExecutorRole srcRole, int32_t resultCode,
50     const Attributes &finalResult)
51 {
52     if (messenger_ == nullptr) {
53         IAM_LOGE("messenger is nullptr");
54         return GENERAL_ERROR;
55     }
56     auto attr = Common::MakeShared<Attributes>(finalResult.Serialize());
57     if (attr == nullptr) {
58         IAM_LOGE("failed to create attributes");
59         return GENERAL_ERROR;
60     }
61     return messenger_->Finish(scheduleId, srcRole, static_cast<ResultCode>(resultCode), attr);
62 }
63 } // namespace UserAuth
64 } // namespace UserIam
65 } // namespace OHOS