• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2017 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #ifndef CHRE_WIFI_OFFLOAD_CHANNEL_HISTOGRAM_H_
18 #define CHRE_WIFI_OFFLOAD_CHANNEL_HISTOGRAM_H_
19 
20 #include "chre/apps/wifi_offload/wifi_offload.h"
21 
22 #include "chre/apps/wifi_offload/flatbuffers_types_generated.h"
23 
24 namespace wifi_offload {
25 
26 /**
27  * A class to keep scan count for each channel. It provides an indexer to access
28  * each channel's scan count with channel number.
29  */
30 class ChannelHistogram {
31  public:
32   static constexpr uint8_t kNumChannels = 69;
33 
34   ChannelHistogram();
35 
36   ~ChannelHistogram() = default;
37 
38   static bool IsSupportedFrequency(uint32_t frequency);
39 
40   /* Gets the scaled scan count for a given channel number. All scan counts are
41    * scaled such that the largest non-zero count is always mapped to 255 */
42   uint8_t GetChannelScanCount(uint8_t channel_number) const;
43 
44   bool IncrementScanCountForFrequency(uint32_t frequency);
45 
46   bool IncrementScanCountForFrequencyForTest(uint32_t frequency,
47                                              uint32_t increase_count);
48 
49   bool IncrementScanCountForChannelForTest(uint8_t channel,
50                                            uint32_t increase_count);
51 
52   bool operator==(const ChannelHistogram &other) const;
53 
54   flatbuffers::Offset<flatbuffers::Vector<uint8_t>> Serialize(
55       flatbuffers::FlatBufferBuilder *builder) const;
56 
57   bool Deserialize(const flatbuffers::Vector<uint8_t> &fbs_scan_count);
58 
59  private:
60   uint32_t scan_count_internal_high_res_[kNumChannels];
61 };
62 
63 }  // namespace wifi_offload
64 
65 #endif  // CHRE_WIFI_OFFLOAD_CHANNEL_HISTOGRAM_H_
66