• 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 IAM_SCHEDULE_NODE_H
17 #define IAM_SCHEDULE_NODE_H
18 
19 #include <cstdint>
20 #include <memory>
21 #include <optional>
22 
23 #include "finite_state_machine.h"
24 #include "iam_common_defines.h"
25 #include "resource_node.h"
26 #include "schedule_node_callback.h"
27 #include "thread_handler.h"
28 
29 namespace OHOS {
30 namespace UserIam {
31 namespace UserAuth {
32 class Context;
33 class ScheduleNode {
34 public:
35     class Builder;
36     enum State : uint32_t {
37         S_INIT = 0,
38         S_VERIFY_STARING = 1,
39         S_COLLECT_STARING = 2,
40         S_AUTH_PROCESSING = 3,
41         S_COLLECT_STOPPING = 4,
42         S_VERIFY_STOPPING = 5,
43         S_END = 6
44     };
45     enum Event : uint32_t {
46         E_START_AUTH = 0,
47         E_VERIFY_STARTED_SUCCESS = 1,
48         E_VERIFY_STARTED_FAILED = 2,
49         E_COLLECT_STARTED_SUCCESS = 3,
50         E_COLLECT_STARTED_FAILED = 4,
51         E_SCHEDULE_RESULT_RECEIVED = 5,
52         E_COLLECT_STOPPED_SUCCESS = 6,
53         E_COLLECT_STOPPED_FAILED = 7,
54         E_VERIFY_STOPPED_SUCCESS = 8,
55         E_VERIFY_STOPPED_FAILED = 9,
56         E_STOP_AUTH = 10,
57         E_TIME_OUT = 11,
58     };
59     virtual ~ScheduleNode() = default;
60     virtual uint64_t GetScheduleId() const = 0;
61     virtual uint64_t GetContextId() const = 0;
62     virtual AuthType GetAuthType() const = 0;
63     virtual uint64_t GetExecutorMatcher() const = 0;
64     virtual ScheduleMode GetScheduleMode() const = 0;
65     virtual std::weak_ptr<ResourceNode> GetCollectorExecutor() const = 0;
66     virtual std::weak_ptr<ResourceNode> GetVerifyExecutor() const = 0;
67     virtual std::optional<std::vector<uint64_t>> GetTemplateIdList() const = 0;
68     virtual State GetCurrentScheduleState() const = 0;
69     virtual bool StartSchedule() = 0;
70     virtual bool StopSchedule() = 0;
71     virtual bool ContinueSchedule(ExecutorRole srcRole, ExecutorRole dstRole, uint64_t transNum,
72         const std::vector<uint8_t> &msg) = 0;
73     virtual bool ContinueSchedule(ResultCode resultCode, const std::shared_ptr<Attributes> &finalResult) = 0;
74 };
75 
76 class ScheduleNode::Builder {
77 public:
78     static std::shared_ptr<Builder> New(const std::shared_ptr<ResourceNode> &collector,
79         const std::shared_ptr<ResourceNode> &verifier);
80     virtual ~Builder() = default;
81     virtual std::shared_ptr<Builder> SetScheduleId(uint64_t scheduleId) = 0;
82     virtual std::shared_ptr<Builder> SetAccessTokenId(uint32_t tokenId) = 0;
83     virtual std::shared_ptr<Builder> SetPinSubType(PinSubType pinSubType) = 0;
84     virtual std::shared_ptr<Builder> SetTemplateIdList(const std::vector<uint64_t> &templateIdList) = 0;
85     virtual std::shared_ptr<Builder> SetAuthType(AuthType authType) = 0;
86     virtual std::shared_ptr<Builder> SetExecutorMatcher(uint32_t executorMatcher) = 0;
87     virtual std::shared_ptr<Builder> SetScheduleMode(ScheduleMode scheduleMode) = 0;
88     virtual std::shared_ptr<Builder> SetScheduleCallback(const std::shared_ptr<ScheduleNodeCallback> &callback) = 0;
89     virtual std::shared_ptr<Builder> SetExpiredTime(uint32_t ms) = 0;
90     virtual std::shared_ptr<Builder> SetParametersAttributes(const std::shared_ptr<Attributes> &parameters) = 0;
91     virtual std::shared_ptr<Builder> SetThreadHandler(const std::shared_ptr<ThreadHandler> &threadHandler) = 0;
92     virtual std::shared_ptr<Builder> SetEndAfterFirstFail(const bool endAfterFirstFail) = 0;
93     virtual std::shared_ptr<Builder> SetExtraInfo(const std::vector<uint8_t> &extraInfo) = 0;
94     virtual std::shared_ptr<ScheduleNode> Build() = 0;
95 };
96 } // namespace UserAuth
97 } // namespace UserIam
98 } // namespace OHOS
99 #endif // IAM_SCHEDULE_NODE_H