Go to the documentation of this file.
5 #ifndef UAVCAN_PROTOCOL_DYNAMIC_NODE_ID_SERVER_DISTRIBUTED_PERSISTENT_STATE_HPP_INCLUDED
6 #define UAVCAN_PROTOCOL_DYNAMIC_NODE_ID_SERVER_DISTRIBUTED_PERSISTENT_STATE_HPP_INCLUDED
17 namespace dynamic_node_id_server
42 ,
log_(storage, tracer)
61 UAVCAN_TRACE(
"dynamic_node_id_server::distributed::PersistentState",
"Log init failed: %d", res);
72 const bool log_is_empty = (
log_.
getLastIndex() == 0) && (last_entry->term == 0);
86 UAVCAN_TRACE(
"dynamic_node_id_server::distributed::PersistentState",
87 "Failed to init current term: %d", res);
101 UAVCAN_TRACE(
"dynamic_node_id_server::distributed::PersistentState",
102 "Failed to read current term: %d", res);
109 if (current_term_ < last_entry->term)
111 UAVCAN_TRACE(
"dynamic_node_id_server::distributed::PersistentState",
112 "Persistent storage is damaged: current term is less than term of the last log entry (%u < %u)",
128 UAVCAN_TRACE(
"dynamic_node_id_server::distributed::PersistentState",
129 "Failed to init votedFor: %d", res);
132 if (stored_voted_for != 0)
144 UAVCAN_TRACE(
"dynamic_node_id_server::distributed::PersistentState",
145 "Failed to read votedFor: %d", res);
150 return -ErrInvalidConfiguration;
176 return -ErrInvalidParam;
207 return -ErrInvalidParam;
221 if (node_id.
get() != tmp)
237 #endif // Include guard
TraceRaftVotedForRestored
const Log & getLog() const
StorageType< Entry::FieldTypes::term >::Type Term
bool isVotedForSet() const
const Entry * getEntryAtIndex(Index index) const
IStorageBackend & storage_
int setVotedFor(NodeID node_id)
int setAndGetBack(const IStorageBackend::String &key, uint32_t &inout_value)
int get(const IStorageBackend::String &key, uint32_t &out_value) const
#define UAVCAN_TRACE(...)
static const uavcan::int16_t ErrLogic
Internal logic error.
int setCurrentTerm(Term term)
TraceRaftCurrentTermUpdate
virtual void onEvent(TraceCode event_code, int64_t event_argument)=0
Term getCurrentTerm() const
virtual String get(const String &key) const =0
TraceRaftCurrentTermRestored
NodeID getVotedFor() const
static IStorageBackend::String getCurrentTermKey()
PersistentState(IStorageBackend &storage, IEventTracer &tracer)
static IStorageBackend::String getVotedForKey()
Index getLastIndex() const