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#include "chre/apps/wifi_offload/scan_filter.h" 18#include "chre/apps/wifi_offload/vector_serialization.h" 19 20namespace wifi_offload { 21 22ScanFilter::ScanFilter() : min_rssi_threshold_dbm_(0) {} 23 24bool ScanFilter::operator==(const ScanFilter &other) const { 25 if (this == &other) { 26 return true; 27 } 28 return networks_to_match_ == other.networks_to_match_ && 29 min_rssi_threshold_dbm_ == other.min_rssi_threshold_dbm_; 30} 31 32flatbuffers::Offset<ScanFilter::FbsType> ScanFilter::Serialize( 33 flatbuffers::FlatBufferBuilder *builder) const { 34 auto netList = SerializeVector(networks_to_match_, builder); 35 return fbs::CreateScanFilter(*builder, netList, min_rssi_threshold_dbm_); 36} 37 38bool ScanFilter::Deserialize(const ScanFilter::FbsType &fbs_filter) { 39 const auto &fbsNetList = fbs_filter.networks_to_match(); 40 if (fbsNetList == nullptr) { 41 LOGE("Failed to deserialize ScanFilter. Null or incomplete members."); 42 return false; 43 } 44 45 if (!DeserializeVector<PreferredNetwork>(*fbsNetList, &networks_to_match_)) { 46 LOGE("Failed to deserialize ScanFilter. Null or incomplete members."); 47 return false; 48 } 49 50 min_rssi_threshold_dbm_ = fbs_filter.min_rssi_threshold_dbm(); 51 return true; 52} 53 54void ScanFilter::Log() const { 55 LOGI("ScanFilter:"); 56 LOGI(" min rssi threshold: %" PRId8 "dBm", min_rssi_threshold_dbm_); 57 LOGI(" number of networks to match: %zu", networks_to_match_.size()); 58 for (auto &net : networks_to_match_) { 59 net.Log(); 60 } 61} 62 63} // namespace wifi_offload 64