• 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_service.h"
17 
18 #include <cinttypes>
19 
20 #include "iam_logger.h"
21 #include "iam_common_defines.h"
22 
23 #define LOG_LABEL UserIam::Common::LABEL_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,uint64_t transNum,ExecutorRole srcRole,ExecutorRole dstRole,const std::vector<uint8_t> & msg)42 int32_t ExecutorMessengerService::SendData(uint64_t scheduleId, uint64_t transNum, ExecutorRole srcRole,
43     ExecutorRole 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->ContinueSchedule(srcRole, dstRole, transNum, msg);
51     if (!result) {
52         IAM_LOGE("continue schedule failed");
53         return GENERAL_ERROR;
54     }
55     return SUCCESS;
56 }
57 
Finish(uint64_t scheduleId,ExecutorRole srcRole,ResultCode resultCode,const std::shared_ptr<Attributes> & finalResult)58 int32_t ExecutorMessengerService::Finish(uint64_t scheduleId, ExecutorRole srcRole, ResultCode resultCode,
59     const std::shared_ptr<Attributes> &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     bool result = scheduleNode->ContinueSchedule(resultCode, finalResult);
67     if (!result) {
68         IAM_LOGE("continue schedule failed");
69         return GENERAL_ERROR;
70     }
71     return SUCCESS;
72 }
73 } // namespace UserAuth
74 } // namespace UserIam
75 } // namespace OHOS