face: move common declarations to face-common.hpp

Change-Id: I0e3e7a93f0693b0e24ca67493a4229987e792ef4
This commit is contained in:
Davide Pesavento
2019-07-14 21:48:22 -04:00
parent d214881326
commit cb425e83e4
18 changed files with 100 additions and 99 deletions
+9 -9
View File
@@ -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<void()>& f)
connectFaceClosedSignal(Face& face, std::function<void()> 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
+13 -31
View File
@@ -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 <boost/logic/tribool.hpp>
#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<void(const shared_ptr<Face>& face)>;
/** \brief Prototype for the callback that is invoked when a face fails to be created
*/
using FaceCreationFailedCallback = std::function<void(uint32_t status, const std::string& reason)>;
/** \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<time::nanoseconds> baseCongestionMarkingInterval;
optional<uint64_t> defaultCongestionThreshold;
optional<ssize_t> mtu;
bool wantLocalFields = false;
bool wantLpReliability = false;
boost::logic::tribool wantCongestionMarking = boost::logic::indeterminate;
};
using FaceCreatedCallback = std::function<void(const shared_ptr<Face>&)>;
/** \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<void(uint32_t status, const std::string& reason)>;
/** \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<void()>& f);
connectFaceClosedSignal(Face& face, std::function<void()> f);
} // namespace face
} // namespace nfd
+1
View File
@@ -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"
@@ -23,28 +23,77 @@
* NFD, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
*/
#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 <ndn-cxx/encoding/nfd-constants.hpp>
#include <boost/logic/tribool.hpp>
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<T>& 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<time::nanoseconds> baseCongestionMarkingInterval;
optional<uint64_t> defaultCongestionThreshold;
optional<ssize_t> 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<T>& 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<typename T>
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
-1
View File
@@ -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"
+1 -18
View File
@@ -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<Face>& flh);
} // namespace face
using face::EndpointId;
using face::FaceId;
using face::Face;
} // namespace nfd
+1 -3
View File
@@ -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.
+2 -5
View File
@@ -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 <ndn-cxx/lp/packet.hpp>
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
*/
+1 -4
View File
@@ -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 <ndn-cxx/lp/packet.hpp>
namespace nfd {
namespace face {
class LinkService;
/** \brief reassembles fragmented network-layer packets
* \sa https://redmine.named-data.net/projects/nfd/wiki/NDNLPv2
*/
+2 -2
View File
@@ -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 <boost/range/adaptor/map.hpp>
#include <boost/range/algorithm/copy.hpp>
#include <ndn-cxx/encoding/nfd-constants.hpp>
namespace nfd {
namespace face {
+1
View File
@@ -24,6 +24,7 @@
*/
#include "tcp-channel.hpp"
#include "face.hpp"
#include "generic-link-service.hpp"
#include "tcp-transport.hpp"
#include "common/global.hpp"
+1 -18
View File
@@ -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 <ndn-cxx/encoding/nfd-constants.hpp>
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 {
+1
View File
@@ -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"
+1
View File
@@ -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"
+1
View File
@@ -24,6 +24,7 @@
*/
#include "websocket-channel.hpp"
#include "face.hpp"
#include "generic-link-service.hpp"
#include "websocket-transport.hpp"
#include "common/global.hpp"
+1
View File
@@ -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 {
+1
View File
@@ -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"
+1
View File
@@ -24,6 +24,7 @@
*/
#include "face/ethernet-channel.hpp"
#include "face/face.hpp"
#include "tests/test-common.hpp"
#include "ethernet-fixture.hpp"