1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 #ifndef MEDIA_CAST_LOGGING_SIMPLE_EVENT_SUBSCRIBER_H_
6 #define MEDIA_CAST_LOGGING_SIMPLE_EVENT_SUBSCRIBER_H_
7 
8 #include <vector>
9 
10 #include "base/compiler_specific.h"
11 #include "base/macros.h"
12 #include "base/threading/thread_checker.h"
13 #include "media/cast/logging/raw_event_subscriber.h"
14 
15 namespace media {
16 namespace cast {
17 
18 // RawEventSubscriber implementation that records all incoming raw events
19 // in std::vector's.
20 // The user of this class can call the GetXXXEventsAndReset functions to get
21 // list of events that have acccumulated since last inovcation.
22 class SimpleEventSubscriber final : public RawEventSubscriber {
23  public:
24   SimpleEventSubscriber();
25 
26   ~SimpleEventSubscriber() final;
27 
28   // RawEventSubscriber implementations.
29   void OnReceiveFrameEvent(const FrameEvent& frame_event) final;
30   void OnReceivePacketEvent(const PacketEvent& packet_event) final;
31 
32   // Assigns frame events received so far to |frame_events| and clears them
33   // from this object.
34   void GetFrameEventsAndReset(std::vector<FrameEvent>* frame_events);
35 
36   // Assigns packet events received so far to |packet_events| and clears them
37   // from this object.
38   void GetPacketEventsAndReset(std::vector<PacketEvent>* packet_events);
39 
40  private:
41   std::vector<FrameEvent> frame_events_;
42   std::vector<PacketEvent> packet_events_;
43 
44   // All functions must be called on the main thread.
45   base::ThreadChecker thread_checker_;
46 
47   DISALLOW_COPY_AND_ASSIGN(SimpleEventSubscriber);
48 };
49 
50 }  // namespace cast
51 }  // namespace media
52 
53 #endif  // MEDIA_CAST_LOGGING_SIMPLE_EVENT_SUBSCRIBER_H_
54