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_RPC_LOG_RECORD_H_
18 #define CHRE_WIFI_OFFLOAD_RPC_LOG_RECORD_H_
19 
20 #include "chre/apps/wifi_offload/wifi_offload.h"
21 
22 #include "chre/apps/wifi_offload/generated/flatbuffers_types_generated.h"
23 
24 namespace wifi_offload {
25 
26 class RpcLogRecord {
27  public:
28   /**
29    * Enumerates the type of log that is recorded
30    */
31   enum class RpcLogRecordType : uint8_t {
32     CMD_BASE = 0x00,
33     CMD_INIT,
34     CMD_CONFIG_SCANS,
35     CMD_SUBSCRIBE_SCAN_RESULTS,
36     CMD_UNSUBSCRIBE_SCAN_RESULTS,
37     CMD_GET_SCAN_STATS,
38     CMD_RESET,
39     CMD_LAST_ITEM,
40 
41     EVENT_RECVD_BASE = 0x40,
42     EVENT_RECVD_SCAN_RESULT_ASYNC,
43     EVENT_RECVD_SCAN_RESULT,
44     EVENT_RECVD_LAST_ITEM,
45 
46     EVENT_SENT_BASE = 0x80,
47     EVENT_SENT_SCAN_RESULT,
48     EVENT_SENT_ABORT,
49     EVENT_SENT_ERROR,
50     EVENT_SENT_LAST_ITEM,
51 
52     REQ_BASE = 0xc0,
53     REQ_SCAN,
54     REQ_LAST_ITEM,
55   };
56 
57   /* Corresponding flatbuffers-generated data-type used to serialize and
58    * deserialize instances of this class */
59   using FbsType = fbs::RpcLogRecord;
60 
61   RpcLogRecord();
62   ~RpcLogRecord() = default;
63 
64   bool operator==(const RpcLogRecord &other) const;
65 
66   flatbuffers::Offset<RpcLogRecord::FbsType> Serialize(
67       flatbuffers::FlatBufferBuilder *builder) const;
68 
69   bool Deserialize(const RpcLogRecord::FbsType &fbs_record);
70 
71   RpcLogRecordType record_type_;
72   uint32_t timestamp_chre_ms_;  // See chreGetTime()
73 };
74 
75 }  // namespace wifi_offload
76 
77 #endif  // CHRE_WIFI_OFFLOAD_RPC_LOG_RECORD_H_
78