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 FRAMEWORKS_SERVICES_MEDIA_MULTI_STAGES_CAPTURE_INCLUDE_MULTISTAGES_CAPTURE_DFX_REQUEST_POLICY_H
17 #define FRAMEWORKS_SERVICES_MEDIA_MULTI_STAGES_CAPTURE_INCLUDE_MULTISTAGES_CAPTURE_DFX_REQUEST_POLICY_H
18 
19 #include <mutex>
20 #include <string>
21 #include <thread>
22 
23 #include "request_policy.h"
24 
25 namespace OHOS {
26 namespace Media {
27 #define EXPORT __attribute__ ((visibility ("default")))
28 struct RequestCount {
29     int32_t highQualityCount;
30     int32_t balanceQualityCount;
31     int32_t emergencyQualityCount;
32 };
33 
34 class MultiStagesCaptureDfxRequestPolicy {
35 public:
36     EXPORT static MultiStagesCaptureDfxRequestPolicy &GetInstance();
37     EXPORT void SetPolicy(const std::string &callingPackage, const RequestPolicy policy);
38 
39 private:
40     MultiStagesCaptureDfxRequestPolicy();
41     ~MultiStagesCaptureDfxRequestPolicy();
42 
43     MultiStagesCaptureDfxRequestPolicy(const MultiStagesCaptureDfxRequestPolicy &policy) = delete;
44     const MultiStagesCaptureDfxRequestPolicy &operator=(const MultiStagesCaptureDfxRequestPolicy &policy) = delete;
45 
46     EXPORT void GetCount(const RequestPolicy policy, RequestCount &count);
47     bool ShouldReport();
48     void Report();
49 
50     int64_t lastReportTime_ {0};
51     volatile bool isReporting_ {false};
52     std::mutex shouldReportMutex_;
53     std::unordered_map<std::string, RequestCount> requestCountMap_;
54 };
55 
56 } // namespace Media
57 } // namespace OHOS
58 #endif  // FRAMEWORKS_SERVICES_MEDIA_MULTI_STAGES_CAPTURE_INCLUDE_MULTISTAGES_CAPTURE_DFX_REQUEST_POLICY_H