• 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 #include "chre/apps/wifi_offload/scan_result_message.h"
18 #include "chre/apps/wifi_offload/vector_serialization.h"
19 
20 namespace wifi_offload {
21 
SetScanResults(const Vector<ScanResult> & results)22 void ScanResultMessage::SetScanResults(const Vector<ScanResult> &results) {
23   scan_results_.clear();
24   scan_results_.reserve(results.size());
25   for (const auto &result : results) {
26     scan_results_.emplace_back(result);
27   }
28 }
29 
GetScanResults(Vector<ScanResult> * results)30 void ScanResultMessage::GetScanResults(Vector<ScanResult> *results) {
31   if (results == nullptr) {
32     LOGE("ScanResultsMessage output pointer is null in GetScanResults.");
33     return;
34   }
35 
36   results->clear();
37   results->reserve(scan_results_.size());
38   for (const auto &result : scan_results_) {
39     results->emplace_back(result);
40   }
41 }
42 
Serialize(flatbuffers::FlatBufferBuilder * builder) const43 flatbuffers::Offset<ScanResultMessage::FbsType> ScanResultMessage::Serialize(
44     flatbuffers::FlatBufferBuilder *builder) const {
45   auto results = SerializeVector(scan_results_, builder);
46   return fbs::CreateScanResultMessage(*builder, results);
47 }
48 
Deserialize(const ScanResultMessage::FbsType & fbs_result_message)49 bool ScanResultMessage::Deserialize(
50     const ScanResultMessage::FbsType &fbs_result_message) {
51   const auto &fbs_results = fbs_result_message.scan_results();
52   if (fbs_results == nullptr || fbs_results->size() == 0) {
53     LOGE(
54         "Failed to deserialize ScanResultsMessage. Null or incomplete "
55         "members.");
56     return false;
57   }
58 
59   if (!DeserializeVector<ScanResult>(*fbs_results, &scan_results_)) {
60     LOGE(
61         "Failed to deserialize ScanResultMessage. Null or incomplete members.");
62     return false;
63   }
64 
65   return true;
66 }
67 
68 }  // namespace wifi_offload
69