• 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_LABEL UserIam::Common::LABEL_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     if (callback_ == nullptr) {
36         IAM_LOGE("callback is nullptr");
37         return;
38     }
39     auto wrapper = Common::MakeShared<ExecutorMessengerClient>(messenger);
40     if (wrapper == nullptr) {
41         IAM_LOGE("failed to create wrapper");
42         return;
43     }
44     callback_->OnMessengerReady(wrapper, publicKey, templateIdList);
45 }
46 
OnBeginExecute(uint64_t scheduleId,const std::vector<uint8_t> & publicKey,const Attributes & command)47 int32_t ExecutorCallbackService::OnBeginExecute(uint64_t scheduleId, const std::vector<uint8_t> &publicKey,
48     const Attributes &command)
49 {
50     if (callback_ == nullptr) {
51         IAM_LOGE("callback is nullptr");
52         return GENERAL_ERROR;
53     }
54     return callback_->OnBeginExecute(scheduleId, publicKey, command);
55 }
56 
OnEndExecute(uint64_t scheduleId,const Attributes & command)57 int32_t ExecutorCallbackService::OnEndExecute(uint64_t scheduleId, const Attributes &command)
58 {
59     if (callback_ == nullptr) {
60         IAM_LOGE("callback is nullptr");
61         return GENERAL_ERROR;
62     }
63     return callback_->OnEndExecute(scheduleId, command);
64 }
65 
OnSetProperty(const Attributes & properties)66 int32_t ExecutorCallbackService::OnSetProperty(const Attributes &properties)
67 {
68     if (callback_ == nullptr) {
69         IAM_LOGE("callback is nullptr");
70         return GENERAL_ERROR;
71     }
72     return callback_->OnSetProperty(properties);
73 }
74 
OnGetProperty(const Attributes & condition,Attributes & values)75 int32_t ExecutorCallbackService::OnGetProperty(const Attributes &condition, Attributes &values)
76 {
77     if (callback_ == nullptr) {
78         IAM_LOGE("callback is nullptr");
79         return GENERAL_ERROR;
80     }
81     return callback_->OnGetProperty(condition, values);
82 }
83 } // namespace UserAuth
84 } // namespace UserIam
85 } // namespace OHOS