• 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 AUTH_RES_POOL_H
17 #define AUTH_RES_POOL_H
18 
19 #include <mutex>
20 #include <map>
21 #include <iterator>
22 #include <string>
23 #include "coauth_stub.h"
24 #include "coauth_errors.h"
25 #include "coauth_hilog_wrapper.h"
26 #include "iexecutor_callback.h"
27 
28 namespace OHOS {
29 namespace UserIAM {
30 namespace CoAuth {
31     using ResAuthExecutor       = UserIAM::AuthResPool::AuthExecutor;
32     using ResIQueryCallback     = UserIAM::AuthResPool::IQueryCallback;
33     using ResAuthAttributes     = UserIAM::AuthResPool::AuthAttributes;
34     using ResIExecutorCallback  = UserIAM::AuthResPool::IExecutorCallback;
35 
36 class AuthResPool {
37 public:
38     typedef struct {
39         std::shared_ptr<ResAuthExecutor> executorInfo;
40         sptr<ResIExecutorCallback> callback;
41     } ExecutorRegister;
42 
43     typedef struct {
44         uint64_t executorNum;
45         sptr<ICoAuthCallback> callback;
46     } ScheduleRegister;
47     int32_t Insert(uint64_t executorID, std::shared_ptr<ResAuthExecutor> executorInfo,
48                    sptr<ResIExecutorCallback> callback);
49     int32_t Insert(uint64_t scheduleId, uint64_t executorNum, sptr<ICoAuthCallback> callback);
50     int32_t FindExecutorCallback(uint64_t executorID, sptr<ResIExecutorCallback> &callback);
51     int32_t FindExecutorCallback(uint32_t authType, sptr<ResIExecutorCallback> &callback);
52     int32_t DeleteExecutorCallback(uint64_t executorID);
53     int32_t FindScheduleCallback(uint64_t scheduleId, sptr<ICoAuthCallback> &callback);
54     int32_t ScheduleCountMinus(uint64_t scheduleId);
55     int32_t GetScheduleCount(uint64_t scheduleId, uint64_t &scheduleCount);
56     int32_t DeleteScheduleCallback(uint64_t scheduleId);
57 
58 private:
59     std::mutex authMutex_;
60     std::mutex scheMutex_;
61     std::map<uint64_t, std::shared_ptr<ExecutorRegister>> authResPool_;
62     std::map<uint64_t, std::shared_ptr<ScheduleRegister>> scheResPool_;
63 };
64 } // namespace CoAuth
65 } // namespace UserIAM
66 } // namespace OHOS
67 #endif // AUTH_RES_POOL_H
68