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_TAG "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,ExecutorRole dstRole,const std::shared_ptr<AuthMessage> & msg)32 int32_t ExecutorMessengerClient::SendData(uint64_t scheduleId, ExecutorRole dstRole,
33 const std::shared_ptr<AuthMessage> &msg)
34 {
35 IAM_LOGI("start");
36 if (messenger_ == nullptr) {
37 IAM_LOGE("messenger is nullptr");
38 return GENERAL_ERROR;
39 }
40 std::vector<uint8_t> buffer;
41 if (msg == nullptr) {
42 IAM_LOGE("msg is nullptr");
43 return GENERAL_ERROR;
44 } else {
45 buffer = AuthMessageImpl::GetMsgBuffer(msg);
46 }
47 return messenger_->SendData(scheduleId, dstRole, buffer);
48 }
49
Finish(uint64_t scheduleId,int32_t resultCode,const Attributes & finalResult)50 int32_t ExecutorMessengerClient::Finish(uint64_t scheduleId, int32_t resultCode,
51 const Attributes &finalResult)
52 {
53 IAM_LOGI("start");
54 if (messenger_ == nullptr) {
55 IAM_LOGE("messenger is nullptr");
56 return GENERAL_ERROR;
57 }
58 auto attr = Common::MakeShared<Attributes>(finalResult.Serialize());
59 if (attr == nullptr) {
60 IAM_LOGE("failed to create attributes");
61 return GENERAL_ERROR;
62 }
63 return messenger_->Finish(scheduleId, static_cast<ResultCode>(resultCode), attr);
64 }
65 } // namespace UserAuth
66 } // namespace UserIam
67 } // namespace OHOS