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_callback_service.h"
17
18 #include "executor_messenger_client.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 {
ExecutorCallbackService(const std::shared_ptr<ExecutorRegisterCallback> & impl)27 ExecutorCallbackService::ExecutorCallbackService(const std::shared_ptr<ExecutorRegisterCallback> &impl)
28 : callback_(impl)
29 {
30 }
31
OnMessengerReady(sptr<ExecutorMessengerInterface> & messenger,const std::vector<uint8_t> & publicKey,const std::vector<uint64_t> & templateIdList)32 void ExecutorCallbackService::OnMessengerReady(sptr<ExecutorMessengerInterface> &messenger,
33 const std::vector<uint8_t> &publicKey, const std::vector<uint64_t> &templateIdList)
34 {
35 IAM_LOGI("start");
36 if (callback_ == nullptr) {
37 IAM_LOGE("callback is nullptr");
38 return;
39 }
40 auto wrapper = Common::MakeShared<ExecutorMessengerClient>(messenger);
41 if (wrapper == nullptr) {
42 IAM_LOGE("failed to create wrapper");
43 return;
44 }
45 callback_->OnMessengerReady(wrapper, publicKey, templateIdList);
46 }
47
OnBeginExecute(uint64_t scheduleId,const std::vector<uint8_t> & publicKey,const Attributes & command)48 int32_t ExecutorCallbackService::OnBeginExecute(uint64_t scheduleId, const std::vector<uint8_t> &publicKey,
49 const Attributes &command)
50 {
51 IAM_LOGI("start");
52 if (callback_ == nullptr) {
53 IAM_LOGE("callback is nullptr");
54 return GENERAL_ERROR;
55 }
56 return callback_->OnBeginExecute(scheduleId, publicKey, command);
57 }
58
OnEndExecute(uint64_t scheduleId,const Attributes & command)59 int32_t ExecutorCallbackService::OnEndExecute(uint64_t scheduleId, const Attributes &command)
60 {
61 IAM_LOGI("start");
62 if (callback_ == nullptr) {
63 IAM_LOGE("callback is nullptr");
64 return GENERAL_ERROR;
65 }
66 return callback_->OnEndExecute(scheduleId, command);
67 }
68
OnSetProperty(const Attributes & properties)69 int32_t ExecutorCallbackService::OnSetProperty(const Attributes &properties)
70 {
71 IAM_LOGI("start");
72 if (callback_ == nullptr) {
73 IAM_LOGE("callback is nullptr");
74 return GENERAL_ERROR;
75 }
76 return callback_->OnSetProperty(properties);
77 }
78
OnGetProperty(const Attributes & condition,Attributes & values)79 int32_t ExecutorCallbackService::OnGetProperty(const Attributes &condition, Attributes &values)
80 {
81 IAM_LOGI("start");
82 if (callback_ == nullptr) {
83 IAM_LOGE("callback is nullptr");
84 return GENERAL_ERROR;
85 }
86 return callback_->OnGetProperty(condition, values);
87 }
88
OnSendData(uint64_t scheduleId,const Attributes & data)89 int32_t ExecutorCallbackService::OnSendData(uint64_t scheduleId, const Attributes &data)
90 {
91 IAM_LOGI("start");
92 if (callback_ == nullptr) {
93 IAM_LOGE("callback is nullptr");
94 return GENERAL_ERROR;
95 }
96 return callback_->OnSendData(scheduleId, data);
97 }
98 } // namespace UserAuth
99 } // namespace UserIam
100 } // namespace OHOS