5 #ifndef UAVCAN_PROTOCOL_DYNAMIC_NODE_ID_SERVER_DISTRIBUTED_LOG_HPP_INCLUDED 6 #define UAVCAN_PROTOCOL_DYNAMIC_NODE_ID_SERVER_DISTRIBUTED_LOG_HPP_INCLUDED 16 namespace dynamic_node_id_server
77 out_entry.node_id =
static_cast<uint8_t>(node_id);
106 temp.node_id =
static_cast<uint8_t>(node_id);
108 return (temp == entry) ? 0 : -ErrFailure;
118 entries_[0] =
Entry();
137 if (stored_index != 0)
163 UAVCAN_TRACE(
"dynamic_node_id_server::distributed::Log",
"Initializing empty storage");
169 UAVCAN_TRACE(
"dynamic_node_id_server::distributed::Log",
"Failed to read last index");
177 last_index_ =
Index(value);
183 for (Index index = 0; index <=
last_index_; index++)
188 UAVCAN_TRACE(
"dynamic_node_id_server::distributed::Log",
"Failed to read entry at index %u: %d",
189 unsigned(index), result);
194 UAVCAN_TRACE(
"dynamic_node_id_server::distributed::Log",
"Restored %u log entries",
unsigned(last_index_));
220 uint32_t new_last_index = last_index_ + 1U;
226 if (new_last_index != last_index_ + 1U)
230 entries_[new_last_index] = entry;
231 last_index_ =
Index(new_last_index);
233 UAVCAN_TRACE(
"dynamic_node_id_server::distributed::Log",
"New entry, index %u, node ID %u, term %u",
234 unsigned(last_index_),
unsigned(entry.node_id),
unsigned(entry.term));
246 if (((index) >=
Capacity) || (index <= 0))
251 uint32_t new_last_index = index - 1U;
255 if (new_last_index != last_index_)
263 if (new_last_index != index - 1U)
267 UAVCAN_TRACE(
"dynamic_node_id_server::distributed::Log",
"Entries removed, last index %u --> %u",
268 unsigned(last_index_),
unsigned(new_last_index));
269 last_index_ =
Index(new_last_index);
288 return (index <= last_index_) ? &entries_[index] :
UAVCAN_NULLPTR;
297 if (other_last_term != entries_[last_index_].term)
299 return other_last_term > entries_[
last_index_].term;
310 #endif // Include guard
void appendFormatted(const char *const format, const A value)
IStorageBackend & storage_
int removeEntriesWhereIndexGreater(Index index)
int readEntryFromStorage(Index index, Entry &out_entry)
bool isOtherLogUpToDate(Index other_last_index, Term other_last_term) const
static IStorageBackend::String getLastIndexKey()
int initEmptyLogStorage()
virtual void onEvent(TraceCode event_code, int64_t event_argument)=0
#define UAVCAN_TRACE(...)
int writeEntryToStorage(Index index, const Entry &entry)
static IStorageBackend::String makeEntryKey(Index index, const char *postfix)
const Entry * getEntryAtIndex(Index index) const
int get(const IStorageBackend::String &key, uint32_t &out_value) const
int setAndGetBack(const IStorageBackend::String &key, uint32_t &inout_value)
Log(IStorageBackend &storage, IEventTracer &tracer)
Index getLastIndex() const
int removeEntriesWhereIndexGreaterOrEqual(Index index)
StorageType< Entry::FieldTypes::term >::Type Term
TraceRaftLogLastIndexRestored
virtual String get(const String &key) const =0
int append(const Entry &entry)
static const uavcan::int16_t ErrLogic
Internal logic error.