All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
ndn::Face Class Reference

Abstraction to communicate with local or remote NDN forwarder. More...

#include <face.hpp>

Inheritance diagram for ndn::Face:
[legend]
Collaboration diagram for ndn::Face:
[legend]

Data Structures

class  Error
 

Public Member Functions

 Face ()
 Create a new Face using the default transport (UnixTransport) More...
 
 Face (const shared_ptr< boost::asio::io_service > &ioService)
 Create a new Face using the default transport (UnixTransport) More...
 
 Face (boost::asio::io_service &ioService)
 Create a new Face using the default transport (UnixTransport) More...
 
 Face (const std::string &host, const std::string &port="6363")
 Create a new Face using TcpTransport. More...
 
 Face (const shared_ptr< Transport > &transport)
 Create a new Face using the given Transport. More...
 
 Face (const shared_ptr< Transport > &transport, boost::asio::io_service &ioService)
 Create a new Face using the given Transport and IO service object. More...
 
void setController (const shared_ptr< Controller > &controller)
 Set controller used for prefix registration. More...
 
const PendingInterestId * expressInterest (const Interest &interest, const OnData &onData, const OnTimeout &onTimeout=OnTimeout())
 Express Interest. More...
 
const PendingInterestId * expressInterest (const Name &name, const Interest &tmpl, const OnData &onData, const OnTimeout &onTimeout=OnTimeout())
 Express Interest using name and Interest template. More...
 
void removePendingInterest (const PendingInterestId *pendingInterestId)
 Remove the pending interest entry with the pendingInterestId from the pending interest table. More...
 
const RegisteredPrefixId * setInterestFilter (const Name &prefix, const OnInterest &onInterest, const OnSetInterestFilterFailed &onSetInterestFilterFailed)
 Register prefix with the connected NDN hub and call onInterest when a matching interest is received. More...
 
void unsetInterestFilter (const RegisteredPrefixId *registeredPrefixId)
 Remove the registered prefix entry with the registeredPrefixId from the pending interest table. More...
 
void put (const Data &data)
 Publish data packet. More...
 
void processEvents (const time::milliseconds &timeout=time::milliseconds::zero(), bool keepThread=false)
 Process any data to receive or call timeout callbacks. More...
 
void shutdown ()
 Shutdown face operations. More...
 
shared_ptr
< boost::asio::io_service > 
ioService ()
 Get shared_ptr of the IO service object. More...
 
boost::asio::io_service & getIoService ()
 Get reference to IO service object. More...
 

Detailed Description

Abstraction to communicate with local or remote NDN forwarder.

Definition at line 54 of file face.hpp.

Constructor & Destructor Documentation

ndn::Face::Face ( )

Create a new Face using the default transport (UnixTransport)

Exceptions
ConfigFile::Erroron configuration file parse failure
Face::Erroron unsupported protocol

Definition at line 25 of file face.cpp.

ndn::Face::Face ( const shared_ptr< boost::asio::io_service > &  ioService)
explicit

Create a new Face using the default transport (UnixTransport)

Deprecated:
This constructor is deprecated. Use Face(boost::asio::io_service&) instead.
Parameters
ioServiceA shared pointer to boost::io_service object that should control all IO operations
Exceptions
ConfigFile::Erroron configuration file parse failure
Face::Erroron unsupported protocol

Definition at line 32 of file face.cpp.

ndn::Face::Face ( boost::asio::io_service &  ioService)
explicit

Create a new Face using the default transport (UnixTransport)

Usage examples:
Face face1;
Face face2(face1.getIoService());

// Now the following ensures that events on both faces are processed
face1.processEvents();
// or face1.getIoService().run();
or
boost::asio::io_service ioService;
Face face1(ioService);
Face face2(ioService);
...

ioService.run();
Parameters
ioServiceA reference to boost::io_service object that should control all IO operations.
Exceptions
ConfigFile::Erroron configuration file parse failure
Face::Erroron unsupported protocol

Definition at line 48 of file face.cpp.

ndn::Face::Face ( const std::string &  host,
const std::string &  port = "6363" 
)

Create a new Face using TcpTransport.

Parameters
hostThe host of the NDN hub.
portThe port or service name of the NDN hub. If omitted. use 6363.
Exceptions
Face::Erroron unsupported protocol

Definition at line 55 of file face.cpp.

ndn::Face::Face ( const shared_ptr< Transport > &  transport)
explicit

Create a new Face using the given Transport.

Parameters
transportA shared_ptr to a Transport object used for communication.
Exceptions
Face::Erroron unsupported protocol

Definition at line 61 of file face.cpp.

ndn::Face::Face ( const shared_ptr< Transport > &  transport,
boost::asio::io_service &  ioService 
)

Create a new Face using the given Transport and IO service object.

See Also
Face(boost::asio::io_service&)
Exceptions
Face::Erroron unsupported protocol

Definition at line 67 of file face.cpp.

Member Function Documentation

const PendingInterestId * ndn::Face::expressInterest ( const Interest interest,
const OnData onData,
const OnTimeout onTimeout = OnTimeout() 
)

Express Interest.

Parameters
interestA reference to the Interest. This copies the Interest.
onDataA function object to call when a matching data packet is received.
onTimeoutA function object to call if the interest times out. If onTimeout is an empty OnTimeout(), this does not use it.
Returns
The pending interest ID which can be used with removePendingInterest.

Definition at line 125 of file face.cpp.

const PendingInterestId * ndn::Face::expressInterest ( const Name name,
const Interest tmpl,
const OnData onData,
const OnTimeout onTimeout = OnTimeout() 
)

Express Interest using name and Interest template.

Parameters
nameName of the Interest
tmplInterest template to fill parameters
onDataA callback to call when a matching data packet is received.
onTimeoutA callback to call if the interest times out. If onTimeout is an empty OnTimeout(), this does not use it.
Returns
The pending interest ID which can be used with removePendingInterest.

Definition at line 141 of file face.cpp.

boost::asio::io_service& ndn::Face::getIoService ( )
inline

Get reference to IO service object.

Definition at line 288 of file face.hpp.

shared_ptr<boost::asio::io_service> ndn::Face::ioService ( )
inline

Get shared_ptr of the IO service object.

Deprecated:
Use getIoService instead

Definition at line 279 of file face.hpp.

void ndn::Face::processEvents ( const time::milliseconds &  timeout = time::milliseconds::zero(),
bool  keepThread = false 
)

Process any data to receive or call timeout callbacks.

This call will block forever (default timeout == 0) to process IO on the face. To exit, one expected to call face.shutdown() from one of the callback methods.

If positive timeout is specified, then processEvents will exit after this timeout, if not stopped earlier with face.shutdown() or when all active events finish. The call can be called repeatedly, if desired.

If negative timeout is specified, then processEvents will not block and process only pending events.

Parameters
timeoutmaximum time to block the thread.
keepThreadKeep thread in a blocked state (in event processing), even when there are no outstanding events (e.g., no Interest/Data is expected)
Exceptions
Thismay throw an exception for reading data or in the callback for processing the data. If you call this from an main event loop, you may want to catch and log/disregard all exceptions.

Definition at line 268 of file face.cpp.

void ndn::Face::put ( const Data data)

Publish data packet.

This method can be called to satisfy the incoming Interest or to put Data packet into the cache of the local NDN forwarder

Definition at line 185 of file face.cpp.

void ndn::Face::removePendingInterest ( const PendingInterestId *  pendingInterestId)

Remove the pending interest entry with the pendingInterestId from the pending interest table.

This does not affect another pending interest with a different pendingInterestId, even it if has the same interest name. If there is no entry with the pendingInterestId, do nothing.

Parameters
pendingInterestIdThe ID returned from expressInterest.

Definition at line 203 of file face.cpp.

void ndn::Face::setController ( const shared_ptr< Controller > &  controller)

Set controller used for prefix registration.

Definition at line 75 of file face.cpp.

const RegisteredPrefixId * ndn::Face::setInterestFilter ( const Name prefix,
const OnInterest onInterest,
const OnSetInterestFilterFailed onSetInterestFilterFailed 
)

Register prefix with the connected NDN hub and call onInterest when a matching interest is received.

Parameters
prefixA reference to a Name for the prefix to register
onInterestA function object to call when a matching interest is received
onRegisterFailedA function object to call if failed to retrieve the connected hub’s ID or failed to register the prefix. This calls onRegisterFailed(prefix) where prefix is the prefix given to registerPrefix.
flagsThe flags for finer control of which interests are forward to the application.
Returns
The registered prefix ID which can be used with removeRegisteredPrefix.

Definition at line 216 of file face.cpp.

void ndn::Face::shutdown ( )

Shutdown face operations.

This method cancels all pending operations and closes connection to NDN Forwarder.

Note that this method does not stop IO service and if the same IO service is shared between multiple Faces or with other IO objects (e.g., Scheduler).

Definition at line 309 of file face.cpp.

void ndn::Face::unsetInterestFilter ( const RegisteredPrefixId *  registeredPrefixId)

Remove the registered prefix entry with the registeredPrefixId from the pending interest table.

This does not affect another registered prefix with a different registeredPrefixId, even it if has the same prefix name. If there is no entry with the registeredPrefixId, do nothing.

Parameters
registeredPrefixIdThe ID returned from registerPrefix.

Definition at line 232 of file face.cpp.