• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 //
2 // Copyright © 2020 Arm Ltd and Contributors. All rights reserved.
3 // SPDX-License-Identifier: MIT
4 //
5 #pragma once
6 
7 #include "ITimelineDecoder.hpp"
8 
9 #include <mutex>
10 #include <utility>
11 #include <vector>
12 
13 namespace arm
14 {
15 
16 namespace pipe
17 {
18 
19 class TimelineDecoder : public ITimelineDecoder
20 {
21 
22 public:
23 
24     struct Model
25     {
26         std::vector<Entity> m_Entities;
27         std::vector<EventClass> m_EventClasses;
28         std::vector<Event> m_Events;
29         std::vector<Label> m_Labels;
30         std::vector<Relationship> m_Relationships;
31     };
32 
33     using OnNewEntityCallback       =  void (*)(Model &, const Entity);
34     using OnNewEventClassCallback   =  void (*)(Model &, const EventClass);
35     using OnNewEventCallback        =  void (*)(Model &, const Event);
36     using OnNewLabelCallback        =  void (*)(Model &, const Label);
37     using OnNewRelationshipCallback =  void (*)(Model &, const Relationship);
38 
39     virtual TimelineStatus CreateEntity(const Entity &) override;
40     virtual TimelineStatus CreateEventClass(const EventClass &) override;
41     virtual TimelineStatus CreateEvent(const Event &) override;
42     virtual TimelineStatus CreateLabel(const Label &) override;
43     virtual TimelineStatus CreateRelationship(const Relationship &) override;
44 
45     template<class F>
ApplyToModel(F && f)46     decltype(auto) ApplyToModel(F&& f){
47         std::lock_guard<std::mutex> lock(m_ModelMutex);
48         return f(m_Model);
49     }
50 
51     TimelineStatus SetEntityCallback(const OnNewEntityCallback);
52     TimelineStatus SetEventClassCallback(const OnNewEventClassCallback);
53     TimelineStatus SetEventCallback(const OnNewEventCallback);
54     TimelineStatus SetLabelCallback(const OnNewLabelCallback);
55     TimelineStatus SetRelationshipCallback(const OnNewRelationshipCallback);
56 
57     void SetDefaultCallbacks();
58 
59     void print();
60 
61 private:
62     Model m_Model;
63     std::mutex m_ModelMutex;
64 
65     OnNewEntityCallback m_OnNewEntityCallback;
66     OnNewEventClassCallback m_OnNewEventClassCallback;
67     OnNewEventCallback m_OnNewEventCallback;
68     OnNewLabelCallback m_OnNewLabelCallback;
69     OnNewRelationshipCallback m_OnNewRelationshipCallback;
70 
71     void printLabels();
72     void printEntities();
73     void printEventClasses();
74     void printRelationships();
75     void printEvents();
76 };
77 
78 } // namespace pipe
79 } // namespace arm
80