• 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 RESSCHED_SERVICES_RESSCHEDMGR_RESSCHEDFWK_INCLUDE_RES_SCHED_MGR_H
17 #define RESSCHED_SERVICES_RESSCHEDMGR_RESSCHEDFWK_INCLUDE_RES_SCHED_MGR_H
18 
19 #include <sys/types.h>
20 #include <string>
21 #include "event_handler.h"
22 #include "single_instance.h"
23 #include "nlohmann/json.hpp"
24 
25 namespace OHOS {
26 namespace ResourceSchedule {
27 class ResSchedMgr {
28     DECLARE_SINGLE_INSTANCE(ResSchedMgr);
29 
30 public:
31     /**
32      * Init resource schedule manager.
33      */
34     void Init();
35 
36     /**
37      * Stop resource schedule manager.
38      */
39     void Stop();
40 
41     /**
42      * Report data from other modules, will report resource data async.
43      *
44      * @param resType Resource type
45      * @param value bit64 content.
46      * @param payload Extra content.
47      */
48     void ReportData(uint32_t resType, int64_t value = 0, const nlohmann::json& payload = nullptr);
49 
50 private:
51     void DispatchResourceInner(uint32_t resType, int64_t value, const nlohmann::json& payload);
52     // main handler, use for report data
53     std::shared_ptr<AppExecFwk::EventHandler> mainHandler_ = nullptr;
54     std::mutex mainHandlerMutex_;
55 };
56 } // namespace ResourceSchedule
57 } // namespace OHOS
58 
59 #endif // RESSCHED_SERVICES_RESSCHEDMGR_RESSCHEDFWK_INCLUDE_RES_SCHED_MGR_H
60