• 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 #ifndef EXCECUTOR_H
17 #define EXCECUTOR_H
18 
19 #include <cstdint>
20 #include <mutex>
21 #include <set>
22 #include <string>
23 
24 #include "nocopyable.h"
25 
26 #include "co_auth_client_callback.h"
27 #include "executor_mgr_wrapper.h"
28 #include "iasync_command.h"
29 #include "iam_defines.h"
30 #include "iam_executor_iauth_executor_hdi.h"
31 
32 namespace OHOS {
33 namespace UserIam {
34 namespace UserAuth {
35 class Executor : public std::enable_shared_from_this<Executor>, public NoCopyable {
36 public:
37     Executor(std::shared_ptr<ExecutorMgrWrapper> executorMgrWrapper, std::shared_ptr<IAuthExecutorHdi> executorHdi,
38         uint16_t hdiId);
39     ~Executor() override = default;
40 
41     void OnHdiDisconnect();
42     void Register();
43     void AddCommand(std::shared_ptr<IAsyncCommand> command);
44     void RemoveCommand(std::shared_ptr<IAsyncCommand> command);
45     void SetExecutorIndex(uint64_t executorIndex);
46     std::shared_ptr<IAuthExecutorHdi> GetExecutorHdi();
47     const char *GetDescription();
48     int32_t GetAuthType() const;
49     int32_t GetExecutorRole() const;
50 
51 private:
52     void RegisterExecutorCallback(ExecutorInfo &executorInfo);
53     void UnregisterExecutorCallback();
54     void RespondCallbackOnDisconnect();
55     std::recursive_mutex registerMutex_;
56     std::recursive_mutex mutex_;
57     std::shared_ptr<ExecutorRegisterCallback> executorCallback_ {nullptr};
58     std::set<std::shared_ptr<IAsyncCommand>> command2Respond_;
59     std::shared_ptr<ExecutorMgrWrapper> executorMgrWrapper_ {nullptr};
60     std::shared_ptr<IAuthExecutorHdi> executorHdi_ {nullptr};
61     std::string description_;
62     uint16_t hdiId_ = 0;
63     int32_t authType_ = INVALID_AUTH_TYPE;
64     int32_t executorRole_ = -1;
65     std::optional<uint64_t> executorIndex_ = std::nullopt;
66 };
67 } // namespace UserAuth
68 } // namespace UserIam
69 } // namespace OHOS
70 
71 #endif // EXCECUTOR_H