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
23 #define LOG_TAG "USER_AUTH_SA"
24
25 namespace OHOS {
26 namespace UserIam {
27 namespace UserAuth {
ExecutorMessengerService()28 ExecutorMessengerService::ExecutorMessengerService()
29 {
30 IAM_LOGI("ExecutorMessengerService init");
31 }
32
GetInstance()33 sptr<ExecutorMessengerService> ExecutorMessengerService::GetInstance()
34 {
35 static sptr<ExecutorMessengerService> instance(new (std::nothrow) ExecutorMessengerService());
36 if (instance == nullptr) {
37 IAM_LOGE("instance is nullptr");
38 }
39 return instance;
40 }
41
SendData(uint64_t scheduleId,ExecutorRole dstRole,const std::vector<uint8_t> & msg)42 int32_t ExecutorMessengerService::SendData(uint64_t scheduleId, ExecutorRole dstRole, const std::vector<uint8_t> &msg)
43 {
44 auto scheduleNode = ContextPool::Instance().SelectScheduleNodeByScheduleId(scheduleId);
45 if (scheduleNode == nullptr) {
46 IAM_LOGE("selected schedule node is nullptr");
47 return GENERAL_ERROR;
48 }
49 bool result = scheduleNode->SendMessage(dstRole, msg);
50 if (!result) {
51 IAM_LOGE("continue schedule failed");
52 return GENERAL_ERROR;
53 }
54 return SUCCESS;
55 }
56
Finish(uint64_t scheduleId,ResultCode resultCode,const std::shared_ptr<Attributes> & finalResult)57 int32_t ExecutorMessengerService::Finish(uint64_t scheduleId, ResultCode resultCode,
58 const std::shared_ptr<Attributes> &finalResult)
59 {
60 auto scheduleNode = ContextPool::Instance().SelectScheduleNodeByScheduleId(scheduleId);
61 if (scheduleNode == nullptr) {
62 IAM_LOGE("selected schedule node is nullptr");
63 return GENERAL_ERROR;
64 }
65 bool result = scheduleNode->ContinueSchedule(resultCode, finalResult);
66 if (!result) {
67 IAM_LOGE("continue schedule failed");
68 return GENERAL_ERROR;
69 }
70 return SUCCESS;
71 }
72 } // namespace UserAuth
73 } // namespace UserIam
74 } // namespace OHOS