Public Member Functions | List of all members
ndn::ThreadsafeFace Class Reference

A ThreadsafeFace extends Face to use a Boost asio io_service to process events and schedule communication calls. More...

#include <threadsafe-face.hpp>

Inheritance diagram for ndn::ThreadsafeFace:
ndn::Face

Public Member Functions

 ThreadsafeFace (boost::asio::io_service &ioService, const ptr_lib::shared_ptr< Transport > &transport, const ptr_lib::shared_ptr< const Transport::ConnectionInfo > &connectionInfo)
 Create a new Face for communication with an NDN hub with the given Transport object and connectionInfo. More...
 
 ThreadsafeFace (boost::asio::io_service &ioService, const char *host, unsigned short port=6363)
 Create a new ThreadsafeFace for communication with an NDN hub at host:port using the an AsyncTcpTransport. More...
 
 ThreadsafeFace (boost::asio::io_service &ioService)
 Create a new Face for communication with an NDN hub using a default connection as follows. More...
 
virtual uint64_t expressInterest (const Interest &interest, const OnData &onData, const OnTimeout &onTimeout, const OnNetworkNack &onNetworkNack, WireFormat &wireFormat=*WireFormat::getDefaultWireFormat())
 Override to use the ioService given to the constructor to dispatch expressInterest to be called in a thread-safe manner. More...
 
virtual uint64_t expressInterest (const Name &name, const Interest *interestTemplate, const OnData &onData, const OnTimeout &onTimeout, const OnNetworkNack &onNetworkNack, WireFormat &wireFormat=*WireFormat::getDefaultWireFormat())
 Override to use the ioService given to the constructor to dispatch expressInterest to be called in a thread-safe manner. More...
 
uint64_t expressInterest (const Name &name, const OnData &onData, const OnTimeout &onTimeout=OnTimeout(), WireFormat &wireFormat=*WireFormat::getDefaultWireFormat())
 
virtual void removePendingInterest (uint64_t pendingInterestId)
 Override to use the ioService given to the constructor to dispatch removePendingInterest to be called in a thread-safe manner. More...
 
virtual uint64_t registerPrefix (const Name &prefix, const OnInterestCallback &onInterest, const OnRegisterFailed &onRegisterFailed, const OnRegisterSuccess &onRegisterSuccess, const ForwardingFlags &flags=ForwardingFlags(), WireFormat &wireFormat=*WireFormat::getDefaultWireFormat())
 Override to use the ioService given to the constructor to dispatch registerPrefix to be called in a thread-safe manner. More...
 
uint64_t registerPrefix (const Name &prefix, const OnInterestCallback &onInterest, const OnRegisterFailed &onRegisterFailed, const ForwardingFlags &flags, WireFormat &wireFormat=*WireFormat::getDefaultWireFormat())
 
uint64_t registerPrefix (const Name &prefix, const OnInterestCallback &onInterest, const OnRegisterFailed &onRegisterFailed)
 
uint64_t DEPRECATED_IN_NDN_CPP registerPrefix (const Name &prefix, const OnInterest &onInterest, const OnRegisterFailed &onRegisterFailed, const ForwardingFlags &flags=ForwardingFlags(), WireFormat &wireFormat=*WireFormat::getDefaultWireFormat())
 
virtual void removeRegisteredPrefix (uint64_t registeredPrefixId)
 Override to use the ioService given to the constructor to dispatch removeRegisteredPrefix to be called in a thread-safe manner. More...
 
virtual uint64_t setInterestFilter (const InterestFilter &filter, const OnInterestCallback &onInterest)
 Override to use the ioService given to the constructor to dispatch setInterestFilter to be called in a thread-safe manner. More...
 
virtual uint64_t setInterestFilter (const Name &prefix, const OnInterestCallback &onInterest)
 Override to use the ioService given to the constructor to dispatch setInterestFilter to be called in a thread-safe manner. More...
 
virtual void unsetInterestFilter (uint64_t interestFilterId)
 Override to use the ioService given to the constructor to dispatch unsetInterestFilter to be called in a thread-safe manner. More...
 
virtual void send (const uint8_t *encoding, size_t encodingLength)
 Override to use the ioService given to the constructor to dispatch send to be called in a thread-safe manner. More...
 
virtual void callLater (Milliseconds delayMilliseconds, const Callback &callback)
 Override to call callback() after the given delay, using a basic_deadline_timer with the ioService given to the constructor. More...
 
- Public Member Functions inherited from ndn::Face
 Face (const ptr_lib::shared_ptr< Transport > &transport, const ptr_lib::shared_ptr< const Transport::ConnectionInfo > &connectionInfo)
 Create a new Face for communication with an NDN hub with the given Transport object and connectionInfo. More...
 
 Face (const char *host, unsigned short port=6363)
 Create a new Face for communication with an NDN hub at host:port using the default TcpTransport. More...
 
 Face ()
 Create a new Face for communication with an NDN hub using a default connection as follows. More...
 
uint64_t expressInterest (const Name &name, const OnData &onData, const OnTimeout &onTimeout, const OnNetworkNack &onNetworkNack, WireFormat &wireFormat=*WireFormat::getDefaultWireFormat())
 Encode name as an Interest, using a default interest lifetime. More...
 
uint64_t expressInterest (const Interest &interest, const OnData &onData, const OnTimeout &onTimeout=OnTimeout(), WireFormat &wireFormat=*WireFormat::getDefaultWireFormat())
 Send the Interest through the transport, read the entire response and call onData or onTimeout as described below. More...
 
uint64_t expressInterest (const Name &name, const Interest *interestTemplate, const OnData &onData, const OnTimeout &onTimeout=OnTimeout(), WireFormat &wireFormat=*WireFormat::getDefaultWireFormat())
 Encode name as an Interest. More...
 
uint64_t expressInterest (const Name &name, const OnData &onData, const OnTimeout &onTimeout=OnTimeout(), WireFormat &wireFormat=*WireFormat::getDefaultWireFormat())
 Encode name as an Interest, using a default interest lifetime. More...
 
void setCommandSigningInfo (KeyChain &keyChain, const Name &certificateName)
 Set the KeyChain and certificate name used to sign command interests (e.g. More...
 
void setCommandCertificateName (const Name &certificateName)
 Set the certificate name used to sign command interest (e.g. More...
 
KeyChaingetCommandKeyChain ()
 
const NamegetCommandCertificateName ()
 
virtual void makeCommandInterest (Interest &interest, WireFormat &wireFormat=*WireFormat::getDefaultWireFormat())
 Append a timestamp component and a random value component to interest's name. More...
 
uint64_t registerPrefix (const Name &prefix, const OnInterestCallback &onInterest, const OnRegisterFailed &onRegisterFailed, const ForwardingFlags &flags, WireFormat &wireFormat=*WireFormat::getDefaultWireFormat())
 Register prefix with the connected NDN hub and call onInterest when a matching interest is received. More...
 
uint64_t registerPrefix (const Name &prefix, const OnInterestCallback &onInterest, const OnRegisterFailed &onRegisterFailed)
 Register prefix with the connected NDN hub and call onInterest when a matching interest is received. More...
 
uint64_t DEPRECATED_IN_NDN_CPP registerPrefix (const Name &prefix, const OnInterest &onInterest, const OnRegisterFailed &onRegisterFailed, const ForwardingFlags &flags=ForwardingFlags(), WireFormat &wireFormat=*WireFormat::getDefaultWireFormat())
 
void putData (const Data &data, WireFormat &wireFormat=*WireFormat::getDefaultWireFormat())
 The OnInterestCallback calls this to put a Data packet which satisfies an Interest. More...
 
void send (const Blob &encoding)
 Send the encoded packet out through the face. More...
 
void processEvents ()
 Process any packets to receive and call callbacks such as onData, onInterest or onTimeout. More...
 
virtual bool isLocal ()
 Check if the face is local based on the current connection through the Transport; some Transport may cause network I/O (e.g. More...
 
void shutdown ()
 Shut down and disconnect this Face.
 

Additional Inherited Members

- Public Types inherited from ndn::Face
typedef func_lib::function< void()> Callback
 Face::Callback is used internally in callLater.
 
- Static Public Member Functions inherited from ndn::Face
static size_t getMaxNdnPacketSize ()
 Get the practical limit of the size of a network-layer packet. More...
 
- Static Protected Member Functions inherited from ndn::Face
static std::string getUnixSocketFilePathForLocalhost ()
 If the forwarder's Unix socket file path exists, then return the file path. More...
 
static ptr_lib::shared_ptr< const InterestgetInterestCopy (const Name &name, const Interest *interestTemplate)
 Do the work of expressInterest to make an Interest based on name and interestTemplate. More...
 
- Protected Attributes inherited from ndn::Face
Nodenode_
 
KeyChaincommandKeyChain_
 
Name commandCertificateName_
 

Detailed Description

A ThreadsafeFace extends Face to use a Boost asio io_service to process events and schedule communication calls.

You must start the service on the thread in which you want the library to call communication callbacks such as onData and onInterest. For usage, see the example test-get-async-threadsafe.cpp.

Constructor & Destructor Documentation

ndn::ThreadsafeFace::ThreadsafeFace ( boost::asio::io_service &  ioService,
const ptr_lib::shared_ptr< Transport > &  transport,
const ptr_lib::shared_ptr< const Transport::ConnectionInfo > &  connectionInfo 
)

Create a new Face for communication with an NDN hub with the given Transport object and connectionInfo.

Parameters
ioServiceThe asio io_service. It is the responsibility of the application to start and stop the service.
transportA shared_ptr to a Transport object used for communication. If you do not want to call processEvents, then the transport should be an async transport like AsyncTcpTransport, in which case the transport should use the same ioService.
transportA shared_ptr to a Transport::ConnectionInfo to be used to connect to the transport.
ndn::ThreadsafeFace::ThreadsafeFace ( boost::asio::io_service &  ioService,
const char *  host,
unsigned short  port = 6363 
)

Create a new ThreadsafeFace for communication with an NDN hub at host:port using the an AsyncTcpTransport.

With this constructor, you do not need to call processEvents since the ioService does all processing.

Parameters
ioServiceThe asio io_service. It is the responsibility of the application to start and stop the service.
hostThe host of the NDN hub.
port(optional) The port of the NDN hub. If omitted, use 6363.
ndn::ThreadsafeFace::ThreadsafeFace ( boost::asio::io_service &  ioService)

Create a new Face for communication with an NDN hub using a default connection as follows.

If the forwarder's Unix socket file exists, then connect using AsyncUnixTransport. Otherwise, connect to "localhost" on port 6363 using AsyncTcpTransport. With this constructor, you do not need to call processEvents since the ioService does all processing.

Parameters
ioServiceThe asio io_service. It is the responsibility of the application to start and stop the service.

Member Function Documentation

virtual void ndn::ThreadsafeFace::callLater ( Milliseconds  delayMilliseconds,
const Callback callback 
)
virtual

Override to call callback() after the given delay, using a basic_deadline_timer with the ioService given to the constructor.

Even though this is public, it is not part of the public API of Face.

Parameters
delayMillisecondsThe delay in milliseconds.
callbackThis calls callback.callback() after the delay.

Reimplemented from ndn::Face.

virtual uint64_t ndn::ThreadsafeFace::expressInterest ( const Interest interest,
const OnData onData,
const OnTimeout onTimeout,
const OnNetworkNack onNetworkNack,
WireFormat wireFormat = *WireFormat::getDefaultWireFormat() 
)
virtual

Override to use the ioService given to the constructor to dispatch expressInterest to be called in a thread-safe manner.

See Face.expressInterest for calling details.

Reimplemented from ndn::Face.

virtual uint64_t ndn::ThreadsafeFace::expressInterest ( const Name name,
const Interest interestTemplate,
const OnData onData,
const OnTimeout onTimeout,
const OnNetworkNack onNetworkNack,
WireFormat wireFormat = *WireFormat::getDefaultWireFormat() 
)
virtual

Override to use the ioService given to the constructor to dispatch expressInterest to be called in a thread-safe manner.

See Face.expressInterest for calling details.

Reimplemented from ndn::Face.

virtual uint64_t ndn::ThreadsafeFace::registerPrefix ( const Name prefix,
const OnInterestCallback onInterest,
const OnRegisterFailed onRegisterFailed,
const OnRegisterSuccess onRegisterSuccess,
const ForwardingFlags flags = ForwardingFlags(),
WireFormat wireFormat = *WireFormat::getDefaultWireFormat() 
)
virtual

Override to use the ioService given to the constructor to dispatch registerPrefix to be called in a thread-safe manner.

See Face.registerPrefix for calling details.

Reimplemented from ndn::Face.

virtual void ndn::ThreadsafeFace::removePendingInterest ( uint64_t  pendingInterestId)
virtual

Override to use the ioService given to the constructor to dispatch removePendingInterest to be called in a thread-safe manner.

See Face.removePendingInterest for calling details.

Reimplemented from ndn::Face.

virtual void ndn::ThreadsafeFace::removeRegisteredPrefix ( uint64_t  registeredPrefixId)
virtual

Override to use the ioService given to the constructor to dispatch removeRegisteredPrefix to be called in a thread-safe manner.

See Face.removeRegisteredPrefix for calling details.

Reimplemented from ndn::Face.

virtual void ndn::ThreadsafeFace::send ( const uint8_t *  encoding,
size_t  encodingLength 
)
virtual

Override to use the ioService given to the constructor to dispatch send to be called in a thread-safe manner.

See Face.send for calling details.

Reimplemented from ndn::Face.

virtual uint64_t ndn::ThreadsafeFace::setInterestFilter ( const InterestFilter filter,
const OnInterestCallback onInterest 
)
virtual

Override to use the ioService given to the constructor to dispatch setInterestFilter to be called in a thread-safe manner.

See Face.setInterestFilter for calling details.

Reimplemented from ndn::Face.

virtual uint64_t ndn::ThreadsafeFace::setInterestFilter ( const Name prefix,
const OnInterestCallback onInterest 
)
virtual

Override to use the ioService given to the constructor to dispatch setInterestFilter to be called in a thread-safe manner.

See Face.setInterestFilter for calling details.

Reimplemented from ndn::Face.

virtual void ndn::ThreadsafeFace::unsetInterestFilter ( uint64_t  interestFilterId)
virtual

Override to use the ioService given to the constructor to dispatch unsetInterestFilter to be called in a thread-safe manner.

See Face.unsetInterestFilter for calling details.

Reimplemented from ndn::Face.


The documentation for this class was generated from the following file: