• 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_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(const sptr<IExecutorMessenger> & messenger,const std::vector<uint8_t> & publicKey,const std::vector<uint64_t> & templateIdList)32 int32_t ExecutorCallbackService::OnMessengerReady(const sptr<IExecutorMessenger> &messenger,
33     const std::vector<uint8_t> &publicKey, const std::vector<uint64_t> &templateIdList)
34 {
35     IAM_LOGD("start");
36     if (callback_ == nullptr) {
37         IAM_LOGE("callback is nullptr");
38         return GENERAL_ERROR;
39     }
40     auto wrapper = Common::MakeShared<ExecutorMessengerClient>(messenger);
41     if (wrapper == nullptr) {
42         IAM_LOGE("failed to create wrapper");
43         return GENERAL_ERROR;
44     }
45     callback_->OnMessengerReady(wrapper, publicKey, templateIdList);
46     return SUCCESS;
47 }
48 
OnBeginExecute(uint64_t scheduleId,const std::vector<uint8_t> & publicKey,const std::vector<uint8_t> & command)49 int32_t ExecutorCallbackService::OnBeginExecute(uint64_t scheduleId, const std::vector<uint8_t> &publicKey,
50     const std::vector<uint8_t> &command)
51 {
52     IAM_LOGD("start");
53     if (callback_ == nullptr) {
54         IAM_LOGE("callback is nullptr");
55         return GENERAL_ERROR;
56     }
57     Attributes attributes(command);
58     return callback_->OnBeginExecute(scheduleId, publicKey, attributes);
59 }
60 
OnEndExecute(uint64_t scheduleId,const std::vector<uint8_t> & command)61 int32_t ExecutorCallbackService::OnEndExecute(uint64_t scheduleId, const std::vector<uint8_t> &command)
62 {
63     IAM_LOGD("start");
64     if (callback_ == nullptr) {
65         IAM_LOGE("callback is nullptr");
66         return GENERAL_ERROR;
67     }
68     Attributes attributes(command);
69     return callback_->OnEndExecute(scheduleId, attributes);
70 }
71 
OnSetProperty(const std::vector<uint8_t> & properties)72 int32_t ExecutorCallbackService::OnSetProperty(const std::vector<uint8_t> &properties)
73 {
74     IAM_LOGD("start");
75     if (callback_ == nullptr) {
76         IAM_LOGE("callback is nullptr");
77         return GENERAL_ERROR;
78     }
79     Attributes attributes(properties);
80     return callback_->OnSetProperty(attributes);
81 }
82 
OnGetProperty(const std::vector<uint8_t> & condition,std::vector<uint8_t> & values)83 int32_t ExecutorCallbackService::OnGetProperty(const std::vector<uint8_t> &condition, std::vector<uint8_t> &values)
84 {
85     IAM_LOGD("start");
86     if (callback_ == nullptr) {
87         IAM_LOGE("callback is nullptr");
88         return GENERAL_ERROR;
89     }
90     Attributes conditionAttr(condition);
91     Attributes valuesAttr;
92     auto ret = callback_->OnGetProperty(conditionAttr, valuesAttr);
93     if (ret == SUCCESS) {
94         values = valuesAttr.Serialize();
95     }
96     return ret;
97 }
98 
OnSendData(uint64_t scheduleId,const std::vector<uint8_t> & extraInfo)99 int32_t ExecutorCallbackService::OnSendData(uint64_t scheduleId, const std::vector<uint8_t> &extraInfo)
100 {
101     IAM_LOGD("start");
102     if (callback_ == nullptr) {
103         IAM_LOGE("callback is nullptr");
104         return GENERAL_ERROR;
105     }
106     Attributes attributes(extraInfo);
107     return callback_->OnSendData(scheduleId, attributes);
108 }
109 
CallbackEnter(uint32_t code)110 int32_t ExecutorCallbackService::CallbackEnter([[maybe_unused]] uint32_t code)
111 {
112     IAM_LOGI("start, code:%{public}u", code);
113     return SUCCESS;
114 }
115 
CallbackExit(uint32_t code,int32_t result)116 int32_t ExecutorCallbackService::CallbackExit([[maybe_unused]] uint32_t code, [[maybe_unused]] int32_t result)
117 {
118     IAM_LOGI("leave, code:%{public}u, result:%{public}d", code, result);
119     return SUCCESS;
120 }
121 } // namespace UserAuth
122 } // namespace UserIam
123 } // namespace OHOS