Free Electron
ViewerSystem.h
Go to the documentation of this file.
1 /* Copyright (C) 2003-2021 Free Electron Organization
2  Any use of this software requires a license. If a valid license
3  was not distributed with this file, visit freeelectron.org. */
4 
5 /** @file */
6 
7 #pragma once
8 
9 namespace fe
10 {
11 namespace ext
12 {
13 
14 /**
15  * Base class for Viewer Systems.
16  *
17  * A Viewer System is a System that reacts to draw notes. It is unique in that
18  * it is aware of the thread it is being performed on. It delegates draw calls
19  * to different viewports based on the current thread id.
20  */
21 class FE_DL_EXPORT ViewerSystem :
22  virtual public SystemI,
23  public CastableAs<ViewerSystem>
24 {
25 public:
26  /**
27  * Draw stuff into the viewport.
28  *
29  * Should be overriden by final classes.
30  *
31  * @param viewportRecord The viewport on this thread.
32  */
33  virtual void draw(Record viewportRecord) = 0;
34 
35  /**
36  * Updates the Viewer records.
37  */
38  void updateViewports(const t_note_id &note_id);
39 
40  /**
41  * Perform processing due to having been signaled.
42  *
43  * This will delegate drawing to different viewports based on the current
44  * thread id.
45  */
46  void perform(const t_note_id &a_note_id) override;
47 
48  void connectOrchestrator(sp<OrchestratorI> orchestrator) override
49  {
50  m_dataset = orchestrator->dataset();
51  m_drawNote = orchestrator->connect(this, FE_NOTE_DRAW);
52  orchestrator->connect(this, &ViewerSystem::updateViewports, FE_NOTE_ADDED_VIEWPORT);
53  orchestrator->connect(this, &ViewerSystem::updateViewports, FE_NOTE_REMOVED_VIEWPORT);
54  };
55 
56 protected:
57  sp<RecordGroup> m_dataset;
58 
59  /** ID of the draw note. */
60  t_note_id m_drawNote;
61 
62  /** Accessors for viewport data. */
64 
65  /** Available viewports. */
66  std::map<std::thread::id, Record> m_viewportRecords;
67  /** Mutex for viewportRecords. It is needed since this system has multiple
68  * threads performing different notes. */
69  #if FE_CPLUSPLUS >= 201703L
70  std::shared_mutex m_viewportRecordsMutex; // C++17
71  #else
73  #endif
74 };
75 
76 } /* namespace ext */
77 } /* namespace fe */
Base class for Viewer Systems.
Definition: ViewerSystem.h:21
Accessor Set for a viewport.
Definition: AsViewport.h:17
t_note_id m_drawNote
ID of the draw note.
Definition: ViewerSystem.h:60
kernel
Definition: namespace.dox:3
void updateViewports(const t_note_id &note_id)
Updates the Viewer records.
Definition: ViewerSystem.cc:41
std::map< std::thread::id, Record > m_viewportRecords
Available viewports.
Definition: ViewerSystem.h:66
Mutex m_viewportRecordsMutex
Mutex for viewportRecords.
Definition: ViewerSystem.h:72
Reference to an instance of a Layout.
Definition: RecordSB.h:35
Intrusive Smart Pointer.
Definition: src/core/ptr.h:53
void connectOrchestrator(sp< OrchestratorI > orchestrator) override
Callback for the System to register itself to the orchestrator.
Definition: ViewerSystem.h:48
System Interface for MOA.
Definition: SystemI.h:18
AsViewport m_viewportAccessorSet
Accessors for viewport data.
Definition: ViewerSystem.h:63
Per-class participation non-RTTI fallback dynamic casting mechanism.
Definition: Castable.h:192