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/rpc_log_record.h" 18 19 namespace wifi_offload { 20 RpcLogRecord()21RpcLogRecord::RpcLogRecord() 22 : record_type_(RpcLogRecordType::CMD_BASE), timestamp_chre_ms_(0) {} 23 operator ==(const RpcLogRecord & other) const24bool RpcLogRecord::operator==(const RpcLogRecord &other) const { 25 if (this == &other) { 26 return true; 27 } 28 return record_type_ == other.record_type_ && 29 timestamp_chre_ms_ == other.timestamp_chre_ms_; 30 } 31 Serialize(flatbuffers::FlatBufferBuilder * builder) const32flatbuffers::Offset<RpcLogRecord::FbsType> RpcLogRecord::Serialize( 33 flatbuffers::FlatBufferBuilder *builder) const { 34 return fbs::CreateRpcLogRecord(*builder, static_cast<uint8_t>(record_type_), 35 timestamp_chre_ms_); 36 } 37 Deserialize(const RpcLogRecord::FbsType & fbs_record)38bool RpcLogRecord::Deserialize(const RpcLogRecord::FbsType &fbs_record) { 39 uint8_t rec = fbs_record.record_type(); 40 if ((rec > static_cast<uint8_t>(RpcLogRecordType::CMD_BASE) && 41 rec < static_cast<uint8_t>(RpcLogRecordType::CMD_LAST_ITEM)) || 42 (rec > static_cast<uint8_t>(RpcLogRecordType::EVENT_RECVD_BASE) && 43 rec < static_cast<uint8_t>(RpcLogRecordType::EVENT_RECVD_LAST_ITEM)) || 44 (rec > static_cast<uint8_t>(RpcLogRecordType::EVENT_SENT_BASE) && 45 rec < static_cast<uint8_t>(RpcLogRecordType::EVENT_SENT_LAST_ITEM)) || 46 (rec > static_cast<uint8_t>(RpcLogRecordType::REQ_BASE) && 47 rec < static_cast<uint8_t>(RpcLogRecordType::REQ_LAST_ITEM))) { 48 record_type_ = static_cast<RpcLogRecordType>(fbs_record.record_type()); 49 } else { 50 LOGE("Failed to deserialize RpcLogRecord. Invalid record type %" PRIu8, 51 rec); 52 return false; 53 } 54 55 timestamp_chre_ms_ = fbs_record.timestamp_chre_ms(); 56 return true; 57 } 58 59 } // namespace wifi_offload 60