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_service.h"
17
18 #include <cinttypes>
19
20 #include "iam_logger.h"
21 #include "iam_common_defines.h"
22 #include "iam_ptr.h"
23
24 #define LOG_TAG "USER_AUTH_SA"
25
26 namespace OHOS {
27 namespace UserIam {
28 namespace UserAuth {
ExecutorMessengerService()29 ExecutorMessengerService::ExecutorMessengerService()
30 {
31 IAM_LOGI("ExecutorMessengerService init");
32 }
33
GetInstance()34 sptr<ExecutorMessengerService> ExecutorMessengerService::GetInstance()
35 {
36 static sptr<ExecutorMessengerService> instance(new (std::nothrow) ExecutorMessengerService());
37 if (instance == nullptr) {
38 IAM_LOGE("instance is nullptr");
39 }
40 return instance;
41 }
42
SendData(uint64_t scheduleId,int32_t dstRole,const std::vector<uint8_t> & msg)43 int32_t ExecutorMessengerService::SendData(uint64_t scheduleId, int32_t dstRole, const std::vector<uint8_t> &msg)
44 {
45 auto scheduleNode = ContextPool::Instance().SelectScheduleNodeByScheduleId(scheduleId);
46 if (scheduleNode == nullptr) {
47 IAM_LOGE("selected schedule node is nullptr");
48 return GENERAL_ERROR;
49 }
50 bool result = scheduleNode->SendMessage(static_cast<ExecutorRole>(dstRole), msg);
51 if (!result) {
52 IAM_LOGE("continue schedule failed");
53 return GENERAL_ERROR;
54 }
55 return SUCCESS;
56 }
57
Finish(uint64_t scheduleId,int32_t resultCode,const std::vector<uint8_t> & finalResult)58 int32_t ExecutorMessengerService::Finish(uint64_t scheduleId, int32_t resultCode,
59 const std::vector<uint8_t> &finalResult)
60 {
61 auto scheduleNode = ContextPool::Instance().SelectScheduleNodeByScheduleId(scheduleId);
62 if (scheduleNode == nullptr) {
63 IAM_LOGE("selected schedule node is nullptr");
64 return GENERAL_ERROR;
65 }
66
67 auto attributes = Common::MakeShared<Attributes>(finalResult);
68 if (attributes == nullptr) {
69 IAM_LOGE("failed to create attributes");
70 return GENERAL_ERROR;
71 }
72
73 bool result = scheduleNode->ContinueSchedule(static_cast<ResultCode>(resultCode), attributes);
74 if (!result) {
75 IAM_LOGE("continue schedule failed");
76 return GENERAL_ERROR;
77 }
78 return SUCCESS;
79 }
80
CallbackEnter(uint32_t code)81 int32_t ExecutorMessengerService::CallbackEnter([[maybe_unused]] uint32_t code)
82 {
83 IAM_LOGI("start, code:%{public}u", code);
84 return SUCCESS;
85 }
86
CallbackExit(uint32_t code,int32_t result)87 int32_t ExecutorMessengerService::CallbackExit([[maybe_unused]] uint32_t code, [[maybe_unused]] int32_t result)
88 {
89 IAM_LOGI("leave, code:%{public}u, result:%{public}d", code, result);
90 return SUCCESS;
91 }
92 } // namespace UserAuth
93 } // namespace UserIam
94 } // namespace OHOS