NDEVR
API Documentation
Log.h
1/*--------------------------------------------------------------------------------------------
2Copyright (c) 2019, NDEVR LLC
3tyler.parke@ndevr.org
4 __ __ ____ _____ __ __ _______
5 | \ | | | __ \ | ___|\ \ / / | __ \
6 | \ | | | | \ \ | |___ \ \ / / | |__) |
7 | . \| | | |__/ / | |___ \ V / | _ /
8 | |\ |_|_____/__|_____|___\_/____| | \ \
9 |__| \__________________________________| \__\
10
11Subject to the terms of the Enterprise+ Agreement, NDEVR hereby grants
12Licensee a limited, non-exclusive, non-transferable, royalty-free license
13(without the right to sublicense) to use the API solely for the purpose of
14Licensee's internal development efforts to develop applications for which
15the API was provided.
16
17The above copyright notice and this permission notice shall be included in all
18copies or substantial portions of the Software.
19
20THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
21INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
22PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
23FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
24OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
25DEALINGS IN THE SOFTWARE.
26
27Library: Base
28File: Log
29Included in API: True
30Author(s): Tyler Parke
31 *-----------------------------------------------------------------------------------------**/
32#pragma once
33#include "DLLInfo.h"
34#include <NDEVR/LogMessage.h>
35#include <NDEVR/LogStream.h>
36#include <NDEVR/InfoPipe.h>
37#include <NDEVR/Set.h>
38#include <NDEVR/LogMessage.h>
39#include <NDEVR/Dictionary.h>
40#include <mutex>
41namespace NDEVR
42{
43 class String;
44
49 class Log final : public InfoPipe, public Buffer<LogMessage>
50 {
51 friend class LogManager;
52 public:
57 NDEVR_BASE_API explicit Log(uint08 id = 0);
58
63 NDEVR_BASE_API Log(const Log& log);
64
68 NDEVR_BASE_API virtual ~Log();
69 public:
75 NDEVR_BASE_API void addStream(LogStream* stream, bool add_all) final override;
76
81 NDEVR_BASE_API void removeStream(LogStream* stream) final override;
82
88 NDEVR_BASE_API void addMessage(uint04 id, const LogMessage& message) final override;
89
96 NDEVR_BASE_API void addMessage(uint04 id, const StringView& message, uint01 log_level = 10) final override;
97
104 NDEVR_BASE_API void addMessage(uint04 id, const TranslatedString& message, uint01 log_level = 10) final override;
105
111 NDEVR_BASE_API void addMessages(uint04 id, const Buffer<LogMessage>& messages) final override;
112
118 NDEVR_BASE_API void insertMessages(uint04 index, const Buffer<LogMessage>& messages);
119
124 NDEVR_BASE_API void concatenate(const Log& log);
125
129 NDEVR_BASE_API void sortMessagesByPriority();
130
134 NDEVR_BASE_API void sortMessagesByTime();
135
141 NDEVR_BASE_API void setProgressIdx(uint04 idx, fltp04 percent) final override;
142
148 NDEVR_BASE_API fltp04 progressIdx(uint04 idx) const final override;
149
155 NDEVR_BASE_API void addInput(const StringView& s, uint04 idx) final override;
156
161 NDEVR_BASE_API void addInput(const StringView& s) final override;
162 private:
169 NDEVR_BASE_API uint04 addProgressSource(const TranslatedString& name, fltp04 progress) final override;
170
175 NDEVR_BASE_API void removeProgressSource(uint04 idx) final override;
176
182 NDEVR_BASE_API uint04 addCancelGuard(const TranslatedString& name) final override;
183
188 NDEVR_BASE_API void removeCancelGuard(uint04 idx) final override;
189
194 NDEVR_BASE_API bool cancelRequested() const final override;
195
201 NDEVR_BASE_API bool cancelRequestedIdx(uint04 idx) const final override;
202
206 NDEVR_BASE_API void requestCancel() final override;
207
212 NDEVR_BASE_API void requestCancel(uint04) final override;
213
220 NDEVR_BASE_API virtual void addProgressSource(const TranslatedString& name, uint04 idx, fltp04 progress) final override;
221
227 NDEVR_BASE_API virtual void addCancelGuard(const TranslatedString& name, uint04 idx) final override;
228
234 NDEVR_BASE_API uint04 addInputGuard(const TranslatedString& name) final override;
235
241 NDEVR_BASE_API void addInputGuard(const TranslatedString& name, uint04 idx) final override;
242
247 NDEVR_BASE_API void removeInputGuard(uint04 idx) final override;
248
255 NDEVR_BASE_API void getInputIdx(String& s, uint04 idx, bool clear) final override;
256
261 NDEVR_BASE_API void clearInputIdx(uint04 idx) final override;
262
268 NDEVR_BASE_API LogMessage getSafe(uint04 idx) const;
269 protected:
273 private:
274 static constexpr fltp08 s_progress_epsilon = 0.001f;
275 Buffer<LogStream*> m_streams;
276 mutable std::mutex m_mtx;
277 };
278}
279
constexpr Buffer() noexcept
Definition Buffer.hpp:65
A hash-based key-value store, useful for quick associative lookups.
Definition Dictionary.h:64
A class that allows for specific log information to be conveyed to a InfoPipe object including inform...
Definition LogMessage.h:48
A listener that receives and processes log messages and progress updates from an InfoPipe.
Definition LogStream.h:49
void addInput(const StringView &s, uint04 idx) final override
Provides input text for a specific input guard by index.
void getInputIdx(String &s, uint04 idx, bool clear) final override
Retrieves the input string for a specific input guard.
Dictionary< uint04, bool > m_request_cancel
Maps cancel guard indices to their cancellation request state.
Definition Log.h:270
Dictionary< uint04, ProgressSource > m_progress
Maps progress source indices to their progress tracking data.
Definition Log.h:271
void sortMessagesByTime()
Sorts all stored messages by their timestamp.
void setProgressIdx(uint04 idx, fltp04 percent) final override
Sets the progress percentage for a tracked progress source.
bool cancelRequestedIdx(uint04 idx) const final override
Checks whether cancel has been requested for a specific guard.
fltp04 progressIdx(uint04 idx) const final override
Retrieves the current progress percentage for a tracked progress source.
void removeCancelGuard(uint04 idx) final override
Removes a previously registered cancel guard.
void removeInputGuard(uint04 idx) final override
Removes a previously registered input guard.
Log(uint08 id=0)
Constructs a Log with the given identifier.
uint04 addProgressSource(const TranslatedString &name, fltp04 progress) final override
Registers a new progress source with a display name and initial progress.
Log(const Log &log)
Copy constructs a Log from another Log.
void addMessage(uint04 id, const StringView &message, uint01 log_level=10) final override
Adds a message from a string view with a specified log level.
bool cancelRequested() const final override
Checks whether any cancel has been requested across all guards.
void addMessage(uint04 id, const LogMessage &message) final override
Adds a single LogMessage to the log and notifies all subscribed streams.
void requestCancel() final override
Requests cancellation of all active operations.
uint04 addInputGuard(const TranslatedString &name) final override
Registers a new input guard with a display name, returning the assigned index.
virtual ~Log()
Destructor.
uint04 addCancelGuard(const TranslatedString &name) final override
Registers a new cancel guard with a display name.
void addMessages(uint04 id, const Buffer< LogMessage > &messages) final override
Adds multiple LogMessages to the log and notifies all subscribed streams.
void concatenate(const Log &log)
Appends all messages from another Log into this one.
Dictionary< uint04, String > m_input
Maps input guard indices to their stored input strings.
Definition Log.h:272
void sortMessagesByPriority()
Sorts all stored messages by their priority level.
void insertMessages(uint04 index, const Buffer< LogMessage > &messages)
Inserts multiple LogMessages at a specific index in the log buffer.
void clearInputIdx(uint04 idx) final override
Clears the stored input for a specific input guard.
void removeStream(LogStream *stream) final override
Unsubscribes a LogStream so it no longer receives log messages.
void addStream(LogStream *stream, bool add_all) final override
Subscribes a LogStream to receive log messages.
void removeProgressSource(uint04 idx) final override
Removes a previously registered progress source.
The core String View class for the NDEVR API.
Definition StringView.h:58
The core String class for the NDEVR API.
Definition String.h:95
Any text displayed to the user should be defined as a TranslatedString which allows the program to lo...
The primary namespace for the NDEVR SDK.
float fltp04
Defines an alias representing a 4 byte floating-point number Bit layout is as follows: -Sign: 1 bit a...
uint64_t uint08
-Defines an alias representing an 8 byte, unsigned integer
uint32_t uint04
-Defines an alias representing a 4 byte, unsigned integer -Can represent exact integer values 0 throu...
double fltp08
Defines an alias representing an 8 byte floating-point number.
uint8_t uint01
-Defines an alias representing a 1 byte, unsigned integer -Can represent exact integer values 0 throu...
@ name
The display name of the object.
STL namespace.
Represents a named progress source with an identifier and completion percentage.