• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2023 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 ACCESS_MANAGER_H
17 #define ACCESS_MANAGER_H
18 
19 #include <map>
20 #include <memory>
21 #include <mutex>
22 #include <vector>
23 
24 #include "singleton.h"
25 
26 #include "i_access.h"
27 #include "startup_constant.h"
28 
29 namespace OHOS {
30 namespace UpdateEngine {
31 class IAccessManager {
32 public:
33     virtual ~IAccessManager() = default;
34     virtual bool IsIdle() = 0;
35     virtual std::vector<ScheduleTask> GetScheduleTasks() = 0;
36     virtual bool Exit() = 0;
37     virtual bool Register(AccessType type, const std::shared_ptr<IAccess> &access) = 0;
38     virtual bool Unregister(AccessType type) = 0;
39     virtual void SetRemoteIdle(bool isRemoteIdle) = 0;
40 };
41 
42 class AccessManager final : public IAccessManager, public DelayedSingleton<AccessManager> {
43     DECLARE_DELAYED_SINGLETON(AccessManager);
44 
45 public:
46     bool IsIdle() final;
47     std::vector<ScheduleTask> GetScheduleTasks() final;
48     bool Exit() final;
49 
50     bool Register(AccessType type, const std::shared_ptr<IAccess> &access) final;
51     bool Unregister(AccessType type) final;
52     void SetRemoteIdle(bool isRemoteIdle) final;
53 
54 private:
55     std::recursive_mutex mutex_;
56     std::map<AccessType, std::shared_ptr<IAccess>> accessMap_;
57     bool isRemoteIdle_ = true;
58 };
59 } // namespace UpdateEngine
60 } // namespace OHOS
61 #endif // ACCESS_MANAGER_H