From cb425e83e43bf25997fd978ff4745aceb7b108f9 Mon Sep 17 00:00:00 2001 From: Davide Pesavento Date: Sun, 14 Jul 2019 21:48:22 -0400 Subject: [PATCH] face: move common declarations to face-common.hpp Change-Id: I0e3e7a93f0693b0e24ca67493a4229987e792ef4 --- daemon/face/channel.cpp | 18 ++--- daemon/face/channel.hpp | 44 ++++-------- daemon/face/ethernet-channel.cpp | 1 + daemon/face/{face-log.hpp => face-common.hpp} | 70 ++++++++++++++++--- daemon/face/face-system.hpp | 1 - daemon/face/face.hpp | 19 +---- daemon/face/link-service.hpp | 4 +- daemon/face/lp-fragmenter.hpp | 7 +- daemon/face/lp-reassembler.hpp | 5 +- daemon/face/protocol-factory.hpp | 4 +- daemon/face/tcp-channel.cpp | 1 + daemon/face/transport.hpp | 19 +---- daemon/face/udp-channel.cpp | 1 + daemon/face/unix-stream-channel.cpp | 1 + daemon/face/websocket-channel.cpp | 1 + daemon/mgmt/face-manager.hpp | 1 + tests/daemon/face/channel-fixture.hpp | 1 + tests/daemon/face/ethernet-channel.t.cpp | 1 + 18 files changed, 100 insertions(+), 99 deletions(-) rename daemon/face/{face-log.hpp => face-common.hpp} (55%) diff --git a/daemon/face/channel.cpp b/daemon/face/channel.cpp index ed13cb23..8b1333ea 100644 --- a/daemon/face/channel.cpp +++ b/daemon/face/channel.cpp @@ -1,6 +1,6 @@ /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ -/** - * Copyright (c) 2014-2017, Regents of the University of California, +/* + * Copyright (c) 2014-2019, Regents of the University of California, * Arizona Board of Regents, * Colorado State University, * University Pierre & Marie Curie, Sorbonne University, @@ -24,6 +24,7 @@ */ #include "channel.hpp" +#include "face.hpp" namespace nfd { namespace face { @@ -37,14 +38,13 @@ Channel::setUri(const FaceUri& uri) } void -connectFaceClosedSignal(Face& face, const std::function& f) +connectFaceClosedSignal(Face& face, std::function f) { - face.afterStateChange.connect( - [f] (FaceState oldState, FaceState newState) { - if (newState == FaceState::CLOSED) { - f(); - } - }); + face.afterStateChange.connect([f = std::move(f)] (auto, FaceState newState) { + if (newState == FaceState::CLOSED) { + f(); + } + }); } } // namespace face diff --git a/daemon/face/channel.hpp b/daemon/face/channel.hpp index 6d2c2217..4b4b8c6c 100644 --- a/daemon/face/channel.hpp +++ b/daemon/face/channel.hpp @@ -1,6 +1,6 @@ /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ /* - * Copyright (c) 2014-2018, Regents of the University of California, + * Copyright (c) 2014-2019, Regents of the University of California, * Arizona Board of Regents, * Colorado State University, * University Pierre & Marie Curie, Sorbonne University, @@ -27,23 +27,12 @@ #define NFD_DAEMON_FACE_CHANNEL_HPP #include "channel-log.hpp" -#include "face.hpp" - -#include +#include "face-common.hpp" namespace nfd { namespace face { -/** \brief Prototype for the callback that is invoked when a face is created - * (in response to an incoming connection or after a connection is established) - */ -using FaceCreatedCallback = std::function& face)>; - -/** \brief Prototype for the callback that is invoked when a face fails to be created - */ -using FaceCreationFailedCallback = std::function; - -/** \brief represent a channel that communicates on a local endpoint +/** \brief Represents a channel that listens on a local endpoint. * \sa FaceSystem * * A channel can listen on a local endpoint and initiate outgoing connection from a local endpoint. @@ -79,31 +68,24 @@ private: FaceUri m_uri; }; -/** \brief Parameters used to set Transport properties or LinkService options on a newly created face - * - * Parameters are passed as a struct rather than individually, so that a future change in the list - * of parameters does not require an update to the method signature in all subclasses. +/** \brief Prototype for the callback that is invoked when a face is created + * (in response to an incoming connection or after a connection is established). */ -struct FaceParams -{ - ndn::nfd::FacePersistency persistency = ndn::nfd::FACE_PERSISTENCY_PERSISTENT; - optional baseCongestionMarkingInterval; - optional defaultCongestionThreshold; - optional mtu; - bool wantLocalFields = false; - bool wantLpReliability = false; - boost::logic::tribool wantCongestionMarking = boost::logic::indeterminate; -}; +using FaceCreatedCallback = std::function&)>; -/** \brief invokes a callback when the face is closed +/** \brief Prototype for the callback that is invoked when a face fails to be created. + */ +using FaceCreationFailedCallback = std::function; + +/** \brief Invokes a callback when a face is closed. * \param face the face * \param f the callback to be invoked when the face enters CLOSED state * - * This function connects a callback to the afterStateChange signal on the \p face, + * This function connects a callback to the afterStateChange signal of \p face, * and invokes \p f when the state becomes CLOSED. */ void -connectFaceClosedSignal(Face& face, const std::function& f); +connectFaceClosedSignal(Face& face, std::function f); } // namespace face } // namespace nfd diff --git a/daemon/face/ethernet-channel.cpp b/daemon/face/ethernet-channel.cpp index 9c27adaa..0104b197 100644 --- a/daemon/face/ethernet-channel.cpp +++ b/daemon/face/ethernet-channel.cpp @@ -25,6 +25,7 @@ #include "ethernet-channel.hpp" #include "ethernet-protocol.hpp" +#include "face.hpp" #include "generic-link-service.hpp" #include "unicast-ethernet-transport.hpp" #include "common/global.hpp" diff --git a/daemon/face/face-log.hpp b/daemon/face/face-common.hpp similarity index 55% rename from daemon/face/face-log.hpp rename to daemon/face/face-common.hpp index b193d82d..f2333096 100644 --- a/daemon/face/face-log.hpp +++ b/daemon/face/face-common.hpp @@ -23,28 +23,77 @@ * NFD, e.g., in COPYING.md file. If not, see . */ -#ifndef NFD_DAEMON_FACE_FACE_LOG_HPP -#define NFD_DAEMON_FACE_FACE_LOG_HPP +#ifndef NFD_DAEMON_FACE_FACE_COMMON_HPP +#define NFD_DAEMON_FACE_FACE_COMMON_HPP +#include "core/common.hpp" #include "common/logger.hpp" +#include + +#include + namespace nfd { namespace face { -/** \brief for internal use by FaceLogging macros +class Face; +class LinkService; + +/** \brief Identifies a face. + */ +using FaceId = uint64_t; + +/// indicates an invalid FaceId +const FaceId INVALID_FACEID = ndn::nfd::INVALID_FACE_ID; +/// identifies the InternalFace used in management +const FaceId FACEID_INTERNAL_FACE = 1; +/// identifies a packet comes from the ContentStore +const FaceId FACEID_CONTENT_STORE = 254; +/// identifies the NullFace that drops every packet +const FaceId FACEID_NULL = 255; +/// upper bound of reserved FaceIds +const FaceId FACEID_RESERVED_MAX = 255; + +/** \brief Identifies a remote endpoint on the link. * - * FaceLogHelper wraps a Face, LinkService, or Transport object. + * This ID is only meaningful in the context of the same Transport. + * Incoming packets from the same remote endpoint have the same EndpointId, + * and incoming packets from different remote endpoints have different EndpointIds. * - * std::ostream& operator<<(std::ostream& os, const FaceLogHelper& flh) + * Typically, a point-to-point Transport has only one meaningful EndpointId (usually 0). + */ +using EndpointId = uint64_t; + +/** \brief Parameters used to set Transport properties or LinkService options on a newly created face. + * + * Parameters are passed as a struct rather than individually, so that a future change in the list + * of parameters does not require an update to the method signature in all subclasses. + */ +struct FaceParams +{ + ndn::nfd::FacePersistency persistency = ndn::nfd::FACE_PERSISTENCY_PERSISTENT; + optional baseCongestionMarkingInterval; + optional defaultCongestionThreshold; + optional mtu; + bool wantLocalFields = false; + bool wantLpReliability = false; + boost::logic::tribool wantCongestionMarking = boost::logic::indeterminate; +}; + +/** \brief For internal use by FaceLogging macros. + * + * FaceLogHelper wraps a reference to Face, LinkService, or Transport object. + * + * `std::ostream& operator<<(std::ostream& os, const FaceLogHelper& flh)` * should be specialized to print "[id=888,local=scheme://local/uri,remote=scheme://remote/uri] " - * which appears as part of the log message. + * which will appear as part of the log message. */ template class FaceLogHelper { public: explicit - FaceLogHelper(const T& obj1) + FaceLogHelper(const T& obj1) noexcept : obj(obj1) { } @@ -54,6 +103,10 @@ public: }; } // namespace face + +using face::EndpointId; +using face::FaceId; + } // namespace nfd /** \defgroup FaceLogging Face logging macros @@ -66,6 +119,7 @@ public: */ /** \cond */ +// implementation detail #define NFD_LOG_FACE(level, msg) NFD_LOG_##level( \ ::nfd::face::FaceLogHelper< \ typename std::remove_cv< \ @@ -92,4 +146,4 @@ public: /** @} */ -#endif // NFD_DAEMON_FACE_FACE_LOG_HPP +#endif // NFD_DAEMON_FACE_FACE_COMMON_HPP diff --git a/daemon/face/face-system.hpp b/daemon/face/face-system.hpp index 2bcdfad8..84a2dcef 100644 --- a/daemon/face/face-system.hpp +++ b/daemon/face/face-system.hpp @@ -26,7 +26,6 @@ #ifndef NFD_DAEMON_FACE_FACE_SYSTEM_HPP #define NFD_DAEMON_FACE_FACE_SYSTEM_HPP -#include "channel.hpp" #include "network-predicate.hpp" #include "common/config-file.hpp" diff --git a/daemon/face/face.hpp b/daemon/face/face.hpp index e96bc310..dc8c20d5 100644 --- a/daemon/face/face.hpp +++ b/daemon/face/face.hpp @@ -26,29 +26,14 @@ #ifndef NFD_DAEMON_FACE_FACE_HPP #define NFD_DAEMON_FACE_FACE_HPP +#include "face-common.hpp" #include "face-counters.hpp" -#include "face-log.hpp" #include "link-service.hpp" #include "transport.hpp" namespace nfd { namespace face { -/** \brief identifies a face - */ -typedef uint64_t FaceId; - -/// indicates an invalid FaceId -const FaceId INVALID_FACEID = 0; -/// identifies the InternalFace used in management -const FaceId FACEID_INTERNAL_FACE = 1; -/// identifies a packet comes from the ContentStore -const FaceId FACEID_CONTENT_STORE = 254; -/// identifies the NullFace that drops every packet -const FaceId FACEID_NULL = 255; -/// upper bound of reserved FaceIds -const FaceId FACEID_RESERVED_MAX = 255; - /** \brief indicates the state of a face */ typedef TransportState FaceState; @@ -295,8 +280,6 @@ operator<<(std::ostream& os, const FaceLogHelper& flh); } // namespace face -using face::EndpointId; -using face::FaceId; using face::Face; } // namespace nfd diff --git a/daemon/face/link-service.hpp b/daemon/face/link-service.hpp index 83961376..415c1858 100644 --- a/daemon/face/link-service.hpp +++ b/daemon/face/link-service.hpp @@ -26,15 +26,13 @@ #ifndef NFD_DAEMON_FACE_LINK_SERVICE_HPP #define NFD_DAEMON_FACE_LINK_SERVICE_HPP -#include "face-log.hpp" +#include "face-common.hpp" #include "transport.hpp" #include "common/counter.hpp" namespace nfd { namespace face { -class Face; - /** \brief counters provided by LinkService * \note The type name 'LinkServiceCounters' is implementation detail. * Use 'LinkService::Counters' in public API. diff --git a/daemon/face/lp-fragmenter.hpp b/daemon/face/lp-fragmenter.hpp index 51d14d93..d98d7529 100644 --- a/daemon/face/lp-fragmenter.hpp +++ b/daemon/face/lp-fragmenter.hpp @@ -1,6 +1,6 @@ /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ /* - * Copyright (c) 2014-2018, Regents of the University of California, + * Copyright (c) 2014-2019, Regents of the University of California, * Arizona Board of Regents, * Colorado State University, * University Pierre & Marie Curie, Sorbonne University, @@ -26,16 +26,13 @@ #ifndef NFD_DAEMON_FACE_LP_FRAGMENTER_HPP #define NFD_DAEMON_FACE_LP_FRAGMENTER_HPP -#include "core/common.hpp" -#include "face-log.hpp" +#include "face-common.hpp" #include namespace nfd { namespace face { -class LinkService; - /** \brief fragments network-layer packets into NDNLPv2 link-layer packets * \sa https://redmine.named-data.net/projects/nfd/wiki/NDNLPv2 */ diff --git a/daemon/face/lp-reassembler.hpp b/daemon/face/lp-reassembler.hpp index e9f05563..95c66ff5 100644 --- a/daemon/face/lp-reassembler.hpp +++ b/daemon/face/lp-reassembler.hpp @@ -26,16 +26,13 @@ #ifndef NFD_DAEMON_FACE_LP_REASSEMBLER_HPP #define NFD_DAEMON_FACE_LP_REASSEMBLER_HPP -#include "face-log.hpp" -#include "transport.hpp" +#include "face-common.hpp" #include namespace nfd { namespace face { -class LinkService; - /** \brief reassembles fragmented network-layer packets * \sa https://redmine.named-data.net/projects/nfd/wiki/NDNLPv2 */ diff --git a/daemon/face/protocol-factory.hpp b/daemon/face/protocol-factory.hpp index a3cb6259..ed87de32 100644 --- a/daemon/face/protocol-factory.hpp +++ b/daemon/face/protocol-factory.hpp @@ -1,6 +1,6 @@ /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ /* - * Copyright (c) 2014-2018, Regents of the University of California, + * Copyright (c) 2014-2019, Regents of the University of California, * Arizona Board of Regents, * Colorado State University, * University Pierre & Marie Curie, Sorbonne University, @@ -27,11 +27,11 @@ #define NFD_DAEMON_FACE_PROTOCOL_FACTORY_HPP #include "channel.hpp" +#include "face.hpp" #include "face-system.hpp" #include #include -#include namespace nfd { namespace face { diff --git a/daemon/face/tcp-channel.cpp b/daemon/face/tcp-channel.cpp index a26c91e7..cfbaed6b 100644 --- a/daemon/face/tcp-channel.cpp +++ b/daemon/face/tcp-channel.cpp @@ -24,6 +24,7 @@ */ #include "tcp-channel.hpp" +#include "face.hpp" #include "generic-link-service.hpp" #include "tcp-transport.hpp" #include "common/global.hpp" diff --git a/daemon/face/transport.hpp b/daemon/face/transport.hpp index 2dd81a05..dd6bb413 100644 --- a/daemon/face/transport.hpp +++ b/daemon/face/transport.hpp @@ -26,29 +26,12 @@ #ifndef NFD_DAEMON_FACE_TRANSPORT_HPP #define NFD_DAEMON_FACE_TRANSPORT_HPP -#include "face-log.hpp" +#include "face-common.hpp" #include "common/counter.hpp" -#include - namespace nfd { namespace face { -class Face; -class LinkService; - -/** \brief Identifies a remote endpoint on the link. - * - * This ID is only meaningful in the context of the same Transport. - * Incoming packets from the same remote endpoint have the same EndpointId, - * and incoming packets from different remote endpoints have different EndpointIds. - * - * Typically, a point-to-point Transport has only one meaningful EndpointId (usually 0). - * - * \sa FaceEndpoint - */ -using EndpointId = uint64_t; - /** \brief Indicates the state of a transport. */ enum class TransportState { diff --git a/daemon/face/udp-channel.cpp b/daemon/face/udp-channel.cpp index 7f4a4d91..5a237584 100644 --- a/daemon/face/udp-channel.cpp +++ b/daemon/face/udp-channel.cpp @@ -24,6 +24,7 @@ */ #include "udp-channel.hpp" +#include "face.hpp" #include "generic-link-service.hpp" #include "unicast-udp-transport.hpp" #include "common/global.hpp" diff --git a/daemon/face/unix-stream-channel.cpp b/daemon/face/unix-stream-channel.cpp index 4ef1a183..b60ba788 100644 --- a/daemon/face/unix-stream-channel.cpp +++ b/daemon/face/unix-stream-channel.cpp @@ -24,6 +24,7 @@ */ #include "unix-stream-channel.hpp" +#include "face.hpp" #include "generic-link-service.hpp" #include "unix-stream-transport.hpp" #include "common/global.hpp" diff --git a/daemon/face/websocket-channel.cpp b/daemon/face/websocket-channel.cpp index 20b66863..a2660c6a 100644 --- a/daemon/face/websocket-channel.cpp +++ b/daemon/face/websocket-channel.cpp @@ -24,6 +24,7 @@ */ #include "websocket-channel.hpp" +#include "face.hpp" #include "generic-link-service.hpp" #include "websocket-transport.hpp" #include "common/global.hpp" diff --git a/daemon/mgmt/face-manager.hpp b/daemon/mgmt/face-manager.hpp index 620ab99e..4e233cb8 100644 --- a/daemon/mgmt/face-manager.hpp +++ b/daemon/mgmt/face-manager.hpp @@ -27,6 +27,7 @@ #define NFD_DAEMON_MGMT_FACE_MANAGER_HPP #include "manager-base.hpp" +#include "face/face.hpp" #include "face/face-system.hpp" namespace nfd { diff --git a/tests/daemon/face/channel-fixture.hpp b/tests/daemon/face/channel-fixture.hpp index 3e130958..2ec7d8a5 100644 --- a/tests/daemon/face/channel-fixture.hpp +++ b/tests/daemon/face/channel-fixture.hpp @@ -27,6 +27,7 @@ #define NFD_TESTS_DAEMON_FACE_CHANNEL_FIXTURE_HPP #include "face/channel.hpp" +#include "face/face.hpp" #include "tests/test-common.hpp" #include "tests/daemon/limited-io.hpp" diff --git a/tests/daemon/face/ethernet-channel.t.cpp b/tests/daemon/face/ethernet-channel.t.cpp index c1311da0..950bdd2c 100644 --- a/tests/daemon/face/ethernet-channel.t.cpp +++ b/tests/daemon/face/ethernet-channel.t.cpp @@ -24,6 +24,7 @@ */ #include "face/ethernet-channel.hpp" +#include "face/face.hpp" #include "tests/test-common.hpp" #include "ethernet-fixture.hpp"