1 /*
2  * Copyright (c) 2024 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 DUMMY_CONTEXT_POOL_H
17 #define DUMMY_CONTEXT_POOL_H
18 
19 #include "context_pool.h"
20 #include "context_callback_impl.h"
21 #include "simple_auth_context.h"
22 #include "dummy_authentication.h"
23 #include "dummy_iam_callback_interface.h"
24 #include "iam_ptr.h"
25 
26 
27 #undef private
28 
29 namespace OHOS {
30 namespace UserIam {
31 namespace UserAuth {
32 namespace {
33 class DummyContextPool : public ContextPool {
34 public:
35     class DummyContextPoolListener : public ContextPoolListener {
36     public:
37         DummyContextPoolListener() = default;
38         virtual ~DummyContextPoolListener() = default;
OnContextPoolInsert(const std::shared_ptr<Context> & context)39         void OnContextPoolInsert(const std::shared_ptr<Context> &context) {};
OnContextPoolDelete(const std::shared_ptr<Context> & context)40         void OnContextPoolDelete(const std::shared_ptr<Context> &context) {};
41     };
GetNewContextId()42     static uint64_t GetNewContextId()
43     {
44         return 0;
45     };
46     static ContextPool &Instance();
Insert(const std::shared_ptr<Context> & context)47     bool Insert(const std::shared_ptr<Context> &context)
48     {
49         return true;
50     };
Delete(uint64_t contextId)51     bool Delete(uint64_t contextId)
52     {
53         return true;
54     };
CancelAll()55     void CancelAll() const {};
Select(uint64_t contextId)56     std::weak_ptr<Context> Select(uint64_t contextId) const
57     {
58         constexpr uint32_t OPERATIONTYPE = 1;
59         constexpr uint64_t CONTEXT_ID = 1;
60         auto dummyAuthentication = Common::MakeShared<DummyAuthentication>();
61         auto contextCallback = Common::MakeShared<ContextCallbackImpl>(new (std::nothrow) DummyIamCallbackInterface(),
62         static_cast<UserAuth::OperationType>(OPERATIONTYPE));
63         auto context = Common::MakeShared<SimpleAuthContext>(CONTEXT_ID, dummyAuthentication, contextCallback);
64         return context;
65     };
Select(ContextType contextType)66     std::vector<std::weak_ptr<Context>> Select(ContextType contextType) const
67     {
68         return {};
69     };
InsertRemoteScheduleNode(std::shared_ptr<ScheduleNode> scheduleNode)70     void InsertRemoteScheduleNode(std::shared_ptr<ScheduleNode> scheduleNode) {};
RemoveRemoteScheduleNode(std::shared_ptr<ScheduleNode> scheduleNode)71     void RemoveRemoteScheduleNode(std::shared_ptr<ScheduleNode> scheduleNode) {};
SelectScheduleNodeByScheduleId(uint64_t scheduleId)72     std::shared_ptr<ScheduleNode> SelectScheduleNodeByScheduleId(uint64_t scheduleId)
73     {
74         return nullptr;
75     };
RegisterContextPoolListener(const std::shared_ptr<ContextPoolListener> & listener)76     bool RegisterContextPoolListener(const std::shared_ptr<ContextPoolListener> &listener)
77     {
78         return true;
79     };
DeregisterContextPoolListener(const std::shared_ptr<ContextPoolListener> & listener)80     bool DeregisterContextPoolListener(const std::shared_ptr<ContextPoolListener> &listener)
81     {
82         return true;
83     };
84 };
85 }
86 } // UserAuth
87 } // UserIam
88 } // OHOS
89 
90 #endif // DUMMY_CONTEXT_POOL_H