From 6ae48c25cbbdd327a17a89d3168877382abd8999 Mon Sep 17 00:00:00 2001 From: Pavel Kirienko Date: Wed, 6 May 2015 18:01:27 +0300 Subject: [PATCH] Naming cleanup --- .../dynamic_node_id_allocation_server.hpp | 78 +++++++++---------- .../uc_dynamic_node_id_allocation_server.cpp | 31 ++++---- 2 files changed, 50 insertions(+), 59 deletions(-) diff --git a/libuavcan/include/uavcan/protocol/dynamic_node_id_allocation_server.hpp b/libuavcan/include/uavcan/protocol/dynamic_node_id_allocation_server.hpp index 41f337c02d..80a8c21fb7 100644 --- a/libuavcan/include/uavcan/protocol/dynamic_node_id_allocation_server.hpp +++ b/libuavcan/include/uavcan/protocol/dynamic_node_id_allocation_server.hpp @@ -75,10 +75,13 @@ public: */ namespace dynamic_node_id_server_impl { + +using namespace protocol::dynamic_node_id::server; + /** * Raft term */ -typedef StorageType::Type Term; +typedef StorageType::Type Term; /** * This class extends the storage backend interface with serialization/deserialization functionality. @@ -106,7 +109,7 @@ public: */ int setAndGetBack(const IDynamicNodeIDStorageBackend::String& key, uint32_t& inout_value); int setAndGetBack(const IDynamicNodeIDStorageBackend::String& key, - protocol::dynamic_node_id::server::Entry::FieldTypes::unique_id& inout_value); + Entry::FieldTypes::unique_id& inout_value); /** * Getters simply read and deserialize the value. @@ -117,7 +120,7 @@ public: */ int get(const IDynamicNodeIDStorageBackend::String& key, uint32_t& out_value) const; int get(const IDynamicNodeIDStorageBackend::String& key, - protocol::dynamic_node_id::server::Entry::FieldTypes::unique_id& out_value) const; + Entry::FieldTypes::unique_id& out_value) const; }; /** @@ -134,14 +137,14 @@ public: private: IDynamicNodeIDStorageBackend& storage_; - protocol::dynamic_node_id::server::Entry entries_[Capacity]; + Entry entries_[Capacity]; Index last_index_; // Index zero always contains an empty entry static IDynamicNodeIDStorageBackend::String getLastIndexKey() { return "log_last_index"; } static IDynamicNodeIDStorageBackend::String makeEntryKey(Index index, const char* postfix); - int readEntryFromStorage(Index index, protocol::dynamic_node_id::server::Entry& out_entry); - int writeEntryToStorage(Index index, const protocol::dynamic_node_id::server::Entry& entry); + int readEntryFromStorage(Index index, Entry& out_entry); + int writeEntryToStorage(Index index, const Entry& entry); int initEmptyLogStorage(); @@ -165,7 +168,7 @@ public: * This method invokes storage IO. * Returned value indicates whether the entry was successfully appended. */ - int append(const protocol::dynamic_node_id::server::Entry& entry); + int append(const Entry& entry); /** * This method invokes storage IO. @@ -177,7 +180,7 @@ public: * Returns nullptr if there's no such index. * This method does not use storage IO. */ - const protocol::dynamic_node_id::server::Entry* getEntryAtIndex(Index index) const; + const Entry* getEntryAtIndex(Index index) const; Index getLastIndex() const { return last_index_; } @@ -234,7 +237,7 @@ class ClusterManager : private TimerBase { typedef MethodBinder&)> + (const ReceivedDataStructure&)> DiscoveryCallback; struct Server @@ -251,13 +254,13 @@ class ClusterManager : private TimerBase void resetIndices(const Log& log); }; - enum { MaxServers = protocol::dynamic_node_id::server::Discovery::FieldTypes::known_nodes::MaxSize }; + enum { MaxServers = Discovery::FieldTypes::known_nodes::MaxSize }; IDynamicNodeIDStorageBackend& storage_; const Log& log_; - Subscriber discovery_sub_; - mutable Publisher discovery_pub_; + Subscriber discovery_sub_; + mutable Publisher discovery_pub_; Server servers_[MaxServers - 1]; ///< Minus one because the local server is not listed there. @@ -278,7 +281,7 @@ class ClusterManager : private TimerBase virtual void handleTimerEvent(const TimerEvent&); - void handleDiscovery(const ReceivedDataStructure& msg); + void handleDiscovery(const ReceivedDataStructure& msg); void startDiscoveryPublishingTimerIfNotRunning(); @@ -359,24 +362,18 @@ public: */ class RaftCore : private TimerBase { - typedef MethodBinder AppendEntriesCallback; + typedef MethodBinder&, + ServiceResponseDataStructure&)> + AppendEntriesCallback; - typedef MethodBinder RequestVoteCallback; + typedef MethodBinder&, + ServiceResponseDataStructure&)> + RequestVoteCallback; - typedef MethodBinder&)> + typedef MethodBinder&)> AppendEntriesResponseCallback; - typedef MethodBinder&)> + typedef MethodBinder&)> RequestVoteResponseCallback; enum ServerState @@ -386,24 +383,20 @@ class RaftCore : private TimerBase ServerStateLeader }; - dynamic_node_id_server_impl::PersistentState persistent_state_; - - dynamic_node_id_server_impl::Log::Index commit_index_; - - dynamic_node_id_server_impl::ClusterManager cluster_; + PersistentState persistent_state_; + Log::Index commit_index_; + ClusterManager cluster_; MonotonicTime last_activity_timestamp_; bool active_mode_; ServerState server_state_; - ServiceServer append_entries_srv_; - ServiceServer request_vote_srv_; + ServiceServer append_entries_srv_; + ServiceServer request_vote_srv_; - ServiceClient append_entries_client_; - ServiceClient request_vote_client_; + ServiceClient append_entries_client_; + ServiceClient request_vote_client_; virtual void handleTimerEvent(const TimerEvent&); @@ -431,17 +424,17 @@ public: * Inserts one entry into log. This operation may fail, which will not be reported. * Failures are tolerble because all operations are idempotent. */ - void appendLog(const protocol::dynamic_node_id::server::Entry& entry); + void appendLog(const Entry& entry); /** * This class is used to perform log searches. */ struct LogEntryInfo { - protocol::dynamic_node_id::server::Entry entry; + Entry entry; bool committed; - LogEntryInfo(const protocol::dynamic_node_id::server::Entry& arg_entry, bool arg_committed) + LogEntryInfo(const Entry& arg_entry, bool arg_committed) : entry(arg_entry) , committed(arg_committed) { } @@ -462,8 +455,7 @@ public: UAVCAN_ASSERT(try_implicit_cast(predicate, true)); for (int index = static_cast(persistent_state_.getLog().getLastIndex()); index--; index >= 0) { - const protocol::dynamic_node_id::server::Entry* const entry = - persistent_state_.getLog().getEntryAtIndex(Log::Index(index)); + const Entry* const entry = persistent_state_.getLog().getEntryAtIndex(Log::Index(index)); UAVCAN_ASSERT(entry != NULL); const LogEntryInfo info(*entry, Log::Index(index) <= commit_index_); if (predicate(info)) diff --git a/libuavcan/src/protocol/uc_dynamic_node_id_allocation_server.cpp b/libuavcan/src/protocol/uc_dynamic_node_id_allocation_server.cpp index 3c40a56ade..b3d7ff63c9 100644 --- a/libuavcan/src/protocol/uc_dynamic_node_id_allocation_server.cpp +++ b/libuavcan/src/protocol/uc_dynamic_node_id_allocation_server.cpp @@ -39,14 +39,14 @@ int MarshallingStorageDecorator::setAndGetBack(const IDynamicNodeIDStorageBacken } int MarshallingStorageDecorator::setAndGetBack(const IDynamicNodeIDStorageBackend::String& key, - protocol::dynamic_node_id::server::Entry::FieldTypes::unique_id& inout_value) + Entry::FieldTypes::unique_id& inout_value) { IDynamicNodeIDStorageBackend::String serialized; - for (uint8_t i = 0; i < protocol::dynamic_node_id::server::Entry::FieldTypes::unique_id::MaxSize; i++) + for (uint8_t i = 0; i < Entry::FieldTypes::unique_id::MaxSize; i++) { serialized.appendFormatted("%02x", inout_value.at(i)); } - UAVCAN_ASSERT(serialized.size() == protocol::dynamic_node_id::server::Entry::FieldTypes::unique_id::MaxSize * 2); + UAVCAN_ASSERT(serialized.size() == Entry::FieldTypes::unique_id::MaxSize * 2); UAVCAN_TRACE("MarshallingStorageDecorator", "Set %s = %s", key.c_str(), serialized.c_str()); storage_.set(key, serialized); @@ -109,9 +109,9 @@ int MarshallingStorageDecorator::get(const IDynamicNodeIDStorageBackend::String& } int MarshallingStorageDecorator::get(const IDynamicNodeIDStorageBackend::String& key, - protocol::dynamic_node_id::server::Entry::FieldTypes::unique_id& out_value) const + Entry::FieldTypes::unique_id& out_value) const { - static const uint8_t NumBytes = protocol::dynamic_node_id::server::Entry::FieldTypes::unique_id::MaxSize; + static const uint8_t NumBytes = Entry::FieldTypes::unique_id::MaxSize; /* * Reading the storage @@ -164,7 +164,7 @@ IDynamicNodeIDStorageBackend::String Log::makeEntryKey(Index index, const char* return str; } -int Log::readEntryFromStorage(Index index, protocol::dynamic_node_id::server::Entry& out_entry) +int Log::readEntryFromStorage(Index index, Entry& out_entry) { const MarshallingStorageDecorator io(storage_); @@ -195,9 +195,9 @@ int Log::readEntryFromStorage(Index index, protocol::dynamic_node_id::server::En return 0; } -int Log::writeEntryToStorage(Index index, const protocol::dynamic_node_id::server::Entry& entry) +int Log::writeEntryToStorage(Index index, const Entry& entry) { - protocol::dynamic_node_id::server::Entry temp = entry; + Entry temp = entry; MarshallingStorageDecorator io(storage_); @@ -231,7 +231,7 @@ int Log::initEmptyLogStorage() /* * Writing the zero entry - it must always be default-initialized */ - entries_[0] = protocol::dynamic_node_id::server::Entry(); + entries_[0] = Entry(); int res = writeEntryToStorage(0, entries_[0]); if (res < 0) { @@ -302,7 +302,7 @@ int Log::init() return 0; } -int Log::append(const protocol::dynamic_node_id::server::Entry& entry) +int Log::append(const Entry& entry) { if ((last_index_ + 1) >= Capacity) { @@ -364,7 +364,7 @@ int Log::removeEntriesWhereIndexGreaterOrEqual(Index index) return 0; } -const protocol::dynamic_node_id::server::Entry* Log::getEntryAtIndex(Index index) const +const Entry* Log::getEntryAtIndex(Index index) const { UAVCAN_ASSERT(last_index_ < Capacity); return (index <= last_index_) ? &entries_[index] : NULL; @@ -397,7 +397,7 @@ int PersistentState::init() return res; } - const protocol::dynamic_node_id::server::Entry* const last_entry = log_.getEntryAtIndex(log_.getLastIndex()); + const Entry* const last_entry = log_.getEntryAtIndex(log_.getLastIndex()); if (last_entry == NULL) { UAVCAN_ASSERT(0); @@ -603,7 +603,7 @@ void ClusterManager::handleTimerEvent(const TimerEvent&) /* * Filling the message */ - protocol::dynamic_node_id::server::Discovery msg; + Discovery msg; msg.configured_cluster_size = cluster_size_; msg.known_nodes.push_back(getNode().getNodeID().get()); // Putting ourselves at index 0 @@ -639,7 +639,7 @@ void ClusterManager::handleTimerEvent(const TimerEvent&) } } -void ClusterManager::handleDiscovery(const ReceivedDataStructure& msg) +void ClusterManager::handleDiscovery(const ReceivedDataStructure& msg) { /* * Validating cluster configuration @@ -683,8 +683,7 @@ void ClusterManager::startDiscoveryPublishingTimerIfNotRunning() { if (!isRunning()) { - startPeriodic( - MonotonicDuration::fromMSec(protocol::dynamic_node_id::server::Discovery::BROADCASTING_INTERVAL_MS)); + startPeriodic(MonotonicDuration::fromMSec(Discovery::BROADCASTING_INTERVAL_MS)); } }