face: Extending Face interface to support ``put`` call
Also, this commit includes Face/Node/Transport enhancement in regard to
the error processing: io_service thread will be stopped and Node::Error
exception will be thrown)
Change-Id: Ibec2f75e7b7d2e9a221a857fdc63295dd7da16e0
diff --git a/include/ndn-cpp/node.hpp b/include/ndn-cpp/node.hpp
index b880c06..ef1d40e 100644
--- a/include/ndn-cpp/node.hpp
+++ b/include/ndn-cpp/node.hpp
@@ -42,6 +42,8 @@
class Node {
public:
+ struct Error : public std::runtime_error { Error(const std::string &what) : std::runtime_error(what) {} };
+
/**
* Create a new Node for communication with an NDN hub with the given Transport object and connectionInfo.
* @param transport A shared_ptr to a Transport object used for communication.
@@ -95,15 +97,29 @@
void
removeRegisteredPrefix(uint64_t registeredPrefixId);
+ /**
+ * @brief 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
+ */
+ void
+ put(const Data &data);
+
/**
- * Process any data to receive. For each element received, call onReceivedElement.
- * This is non-blocking and will return immediately if there is no data to receive.
- * You should repeatedly call this from an event loop, with calls to sleep as needed so that the loop doesn't use 100% of the CPU.
+ * 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 timeout is specified, then processEvents will exit after this timeout, if not stopped earlier with face.shutdown().
+ * The call can be called repeatedly, if desired.
+ *
* @throw This may 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.
*/
void
- processEvents();
+ processEvents(Milliseconds timeout = 0);
const ptr_lib::shared_ptr<Transport>&
getTransport() { return transport_; }
@@ -115,6 +131,9 @@
void
onReceiveElement(const Block &wire);
+ void
+ onTransportError();
+
private:
class PendingInterest {
public:
@@ -283,6 +302,7 @@
private:
boost::asio::io_service ioService_;
boost::asio::deadline_timer timer_;
+ boost::asio::deadline_timer processEventsTimeoutTimer_;
ptr_lib::shared_ptr<Transport> transport_;