1 /*
2  * Copyright (C) 2019 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 SRC_PERFETTO_CMD_PACKET_WRITER_H_
18 #define SRC_PERFETTO_CMD_PACKET_WRITER_H_
19 
20 #include <memory>
21 #include <vector>
22 
23 #include <stdio.h>
24 
25 #include "perfetto/ext/tracing/core/trace_packet.h"
26 
27 namespace perfetto {
28 
29 class PacketWriter {
30  public:
31   PacketWriter();
32   virtual ~PacketWriter();
WritePackets(const std::vector<TracePacket> & packets)33   virtual bool WritePackets(const std::vector<TracePacket>& packets) {
34     for (const TracePacket& packet : packets) {
35       if (!WritePacket(packet)) {
36         return false;
37       }
38     }
39     return true;
40   }
41   virtual bool WritePacket(const TracePacket& packets) = 0;
42 };
43 
44 std::unique_ptr<PacketWriter> CreateFilePacketWriter(FILE*);
45 std::unique_ptr<PacketWriter> CreateZipPacketWriter(
46     std::unique_ptr<PacketWriter>);
47 
48 }  // namespace perfetto
49 
50 #endif  // SRC_PERFETTO_CMD_PACKET_WRITER_H_
51