GM6000 Digital Heater Controller Branch: main
SDX-1330
IndexedEntryReader.h
Go to the documentation of this file.
1#ifndef Cpl_Dm_Persistent_IndexedEntryReader_h_
2#define Cpl_Dm_Persistent_IndexedEntryReader_h_
3/*-----------------------------------------------------------------------------
4* This file is part of the Colony.Core Project. The Colony.Core Project is an
5* open source project with a BSD type of licensing agreement. See the license
6* agreement (license.txt) in the top/ directory or on the Internet at
7* http://integerfox.com/colony.core/license.txt
8*
9* Copyright (c) 2014-2022 John T. Taylor
10*
11* Redistributions of the source code must retain the above copyright notice.
12*----------------------------------------------------------------------------*/
13/** @file */
14
16#include <stdint.h>
17
18///
19namespace Cpl {
20///
21namespace Persistent {
22
23/** This abstract class defines interface for reading/retrieve 'entries' from a
24 a collection of entries (i.e. read an entry from a IndexedEntryRecord).
25
26 From a logical perspective, 'entries' are stored in a Ring Buffer. The
27 Ring Buffer can be 'traversed' from the either end (i.e. oldest to newest, or
28 newest to oldest).
29
30 Each entry that is stored has an 'index' value associated with it. This
31 'index' is used to uniquely identify each entry (even across overwritten
32 entries) and it is used to identify the relative age between the entries.
33
34 NOTE: ALL entries (for a given IndexEntryRecord) must be the same fixed
35 length.
36
37 NOTE: This interface/class is NOT THREAD SAFE and should only be 'used' from
38 the Record Server's thread.
39 */
41{
42public:
43 /** This structure define an 'marker' that identifies an entry's location
44 in persistent media.
45 */
46 typedef struct
47 {
48 uint64_t indexValue; //!< The index/timestamp value for the entry (Note: This is NOT the 'Buffer Index' used by the getByBufferIndex() call)
49 size_t mediaOffset; //!< Offset, within a RegionMedia to the start of the Entry
51
52public:
53 /** This method reads/retrieves the latest entry (from the list of Indexed
54 Entries) stored in the persistent media. The method is synchronous in
55 that the method does not return until the entry has been 'read' from
56 the persistent media.
57
58 Returns true if the latest entry is valid and has been read into 'dst';
59 else false is returned.
60
61 NOTE: When getLatest() returns false, this means there are NO entries
62 stored.
63
64 NOTE: 'dst' is ALWAYS updated EVEN if no entry was 'found', basically 'dst'
65 is used as a work buffer when traversing the list.
66 */
67 virtual bool getLatest( Payload& dst, EntryMarker_T& entryMarker ) noexcept = 0;
68
69public:
70 /** This method walks the entire 'list of entries' and returns the next
71 newer entry as specified by the 'newerThan' value. The traversal
72 starts with the 'beginHereMarker' The method is synchronous in that the
73 method does not return until the entry has been 'read' from the persistent
74 media.
75
76 Returns true if the 'next' entry was found and has been read into 'dst';
77 else false is returned.
78
79 NOTE: 'dst' is ALWAYS updated EVEN if no entry was 'found', basically 'dst'
80 is used as a work buffer when traversing the list.
81
82 */
83 virtual bool getNext( uint64_t newerThan,
84 const EntryMarker_T beginHereMarker,
85 Payload& dst,
86 EntryMarker_T& entryMarker) noexcept = 0;
87
88 /** This method is similar to getNext(), except that it returns the next
89 oldest entry.
90 */
91 virtual bool getPrevious( uint64_t olderThan,
92 const EntryMarker_T beginHereMarker,
93 Payload& dst,
94 EntryMarker_T& entryMarker ) noexcept = 0;
95
96public:
97 /** This method can be used to read an entry by its 'buffer index'. The
98 buffer index is a zero based index.
99
100 Returns true if the entry at 'bufferIndex' is a valid entry; else false
101 is returned. Note: if 'bufferIndex' is out of range, false is returned.
102
103 NOTE: 'dst' is ALWAYS updated EVEN if no valid entry was 'found',
104 basically 'dst' is used as a work buffer when traversing the list.
105 */
106 virtual bool getByBufferIndex( size_t bufferIndex,
107 Payload& dst,
108 EntryMarker_T& entryMarker ) noexcept = 0;
109
110
111 /** This method returns the maximum allowed 'bufferIndex' when calling
112 getByIndex().
113 */
114 virtual size_t getMaxIndex() const noexcept = 0;
115
116public:
117 /// Virtual destructor
118 virtual ~IndexedEntryReader() {}
119};
120
121
122
123}; // end namespaces
124};
125#endif // end header latch
This abstract class defines interface for reading/retrieve 'entries' from a a collection of entries (...
Definition IndexedEntryReader.h:41
virtual bool getNext(uint64_t newerThan, const EntryMarker_T beginHereMarker, Payload &dst, EntryMarker_T &entryMarker) noexcept=0
This method walks the entire 'list of entries' and returns the next newer entry as specified by the '...
size_t mediaOffset
Offset, within a RegionMedia to the start of the Entry.
Definition IndexedEntryReader.h:49
virtual bool getByBufferIndex(size_t bufferIndex, Payload &dst, EntryMarker_T &entryMarker) noexcept=0
This method can be used to read an entry by its 'buffer index'.
virtual bool getLatest(Payload &dst, EntryMarker_T &entryMarker) noexcept=0
This method reads/retrieves the latest entry (from the list of Indexed Entries) stored in the persist...
virtual bool getPrevious(uint64_t olderThan, const EntryMarker_T beginHereMarker, Payload &dst, EntryMarker_T &entryMarker) noexcept=0
This method is similar to getNext(), except that it returns the next oldest entry.
uint64_t indexValue
The index/timestamp value for the entry (Note: This is NOT the 'Buffer Index' used by the getByBuffer...
Definition IndexedEntryReader.h:48
virtual size_t getMaxIndex() const noexcept=0
This method returns the maximum allowed 'bufferIndex' when calling getByIndex().
This structure define an 'marker' that identifies an entry's location in persistent media.
Definition IndexedEntryReader.h:47
This abstract class defines the interface accessing the 'data payload' of an individual Record instan...
Definition Payload.h:29
The 'Cpl' namespace is the root name space for the Colony.
Definition Api16.h:20