ngscopeclient 0.1-dev+51fbda87c
HistoryManager.h
Go to the documentation of this file.
1/***********************************************************************************************************************
2* *
3* ngscopeclient *
4* *
5* Copyright (c) 2012-2024 Andrew D. Zonenberg and contributors *
6* All rights reserved. *
7* *
8* Redistribution and use in source and binary forms, with or without modification, are permitted provided that the *
9* following conditions are met: *
10* *
11* * Redistributions of source code must retain the above copyright notice, this list of conditions, and the *
12* following disclaimer. *
13* *
14* * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the *
15* following disclaimer in the documentation and/or other materials provided with the distribution. *
16* *
17* * Neither the name of the author nor the names of any contributors may be used to endorse or promote products *
18* derived from this software without specific prior written permission. *
19* *
20* THIS SOFTWARE IS PROVIDED BY THE AUTHORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED *
21* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL *
22* THE AUTHORS BE HELD LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES *
23* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR *
24* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT *
25* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE *
26* POSSIBILITY OF SUCH DAMAGE. *
27* *
28***********************************************************************************************************************/
29
35#ifndef HistoryManager_h
36#define HistoryManager_h
37
38#include "Marker.h"
39
40//Waveform history for a single instrument
41typedef std::map<StreamDescriptor, WaveformBase*> WaveformHistory;
42
47{
48public:
51
52 bool IsInUse();
53
56
59
61 std::string m_nickname;
62
64 std::map<std::shared_ptr<Oscilloscope>, WaveformHistory> m_history;
65
66 void LoadHistoryToSession(Session& session);
67};
68
73{
74public:
75 HistoryManager(Session& session);
77
78 bool OnMemoryPressure(MemoryPressureLevel level, MemoryPressureType type, size_t requestedSize);
79
80 void AddHistory(
81 const std::vector<std::shared_ptr<Oscilloscope>>& scopes,
82 bool deleteOld = true,
83 bool pin = false,
84 std::string nick = "",
85 TimePoint refTimeIfNoWaveforms = TimePoint(0, 0));
86
88
89 bool empty();
90
91 void SetMaxToCurrentDepth()
92 { m_maxDepth = m_history.size(); }
93
94 std::shared_ptr<HistoryPoint> GetHistory(TimePoint t);
95
96 bool HasHistory(TimePoint t);
97
99
100 void clear()
101 { m_history.clear(); }
102
103 std::list<std::shared_ptr<HistoryPoint>> m_history;
104
107
108protected:
109 Session& m_session;
110};
111
112#endif
MemoryPressureLevel
Levels of memory pressure.
Definition: AcceleratorBuffer.h:67
MemoryPressureType
Types of memory pressure.
Definition: AcceleratorBuffer.h:84
Declaration of Marker.
Keeps track of recently acquired waveforms.
Definition: HistoryManager.h:73
void LoadEmptyHistoryToSession(Session &session)
Loads an empty history (no data) to the current session.
Definition: HistoryManager.cpp:194
int m_maxDepth
has to be an int for imgui compatibility
Definition: HistoryManager.h:106
TimePoint GetMostRecentPoint()
Gets the timestamp of the most recent waveform.
Definition: HistoryManager.cpp:331
bool HasHistory(TimePoint t)
Checks if we have a history point for a specific timestamp.
Definition: HistoryManager.cpp:356
bool OnMemoryPressure(MemoryPressureLevel level, MemoryPressureType type, size_t requestedSize)
Called when we run out of memory.
Definition: HistoryManager.cpp:370
std::shared_ptr< HistoryPoint > GetHistory(TimePoint t)
Gets the history point for a specific timestamp.
Definition: HistoryManager.cpp:342
bool empty()
Returns true if we have no historical waveform data whatsoever (markers are allowed)
Definition: HistoryManager.cpp:173
void AddHistory(const std::vector< std::shared_ptr< Oscilloscope > > &scopes, bool deleteOld=true, bool pin=false, std::string nick="", TimePoint refTimeIfNoWaveforms=TimePoint(0, 0))
Adds new data to the history.
Definition: HistoryManager.cpp:226
A single point of waveform history.
Definition: HistoryManager.h:47
bool m_pinned
Set true to "pin" this waveform so it won't be purged from history regardless of age.
Definition: HistoryManager.h:58
bool IsInUse()
Returns true if at least one waveform in this history point is currently loaded into a scope.
Definition: HistoryManager.cpp:78
TimePoint m_time
Timestamp of the point.
Definition: HistoryManager.h:55
std::map< std::shared_ptr< Oscilloscope >, WaveformHistory > m_history
Waveform data.
Definition: HistoryManager.h:64
void LoadHistoryToSession(Session &session)
Update all instruments in the specified session with our saved historical data.
Definition: HistoryManager.cpp:99
std::string m_nickname
Free-form text nickname for this acquisition (may be blank)
Definition: HistoryManager.h:61
A Session stores all of the instrument configuration and other state the user has open.
Definition: Session.h:95
A timestamp, measured in seconds + femtoseconds.
Definition: Marker.h:42