ndn-handle: insert, insert status check command
Also, BaseHandle takes reference instead of pointer
Change-Id: Ife53fcebe52c99252e418a46d7361bae8e638bdf
diff --git a/ndn-handle/base-handle.hpp b/ndn-handle/base-handle.hpp
index 97df137..05a2070 100644
--- a/ndn-handle/base-handle.hpp
+++ b/ndn-handle/base-handle.hpp
@@ -15,32 +15,89 @@
{
public:
- BaseHandle(Face* face, StorageHandle* storageHandle)
+ class Error : std::runtime_error
+ {
+ public:
+ explicit
+ Error(const std::string& what)
+ : std::runtime_error(what)
+ {
+ }
+ };
+
+public:
+ BaseHandle(Face& face, StorageHandle& storageHandle, KeyChain& keyChain, Scheduler& scheduler)
: m_face(face)
, m_storageHandle(storageHandle)
+ , m_keyChain(keyChain)
+ , m_scheduler(scheduler)
{
}
virtual void
listen(const Name& prefix) = 0;
- inline Face*
+protected:
+
+ inline Face&
getFace()
{
return m_face;
}
- inline StorageHandle*
+ inline StorageHandle&
getStorageHandle()
{
return m_storageHandle;
}
+ inline Scheduler&
+ getScheduler()
+ {
+ return m_scheduler;
+ }
+
+ uint64_t
+ generateProcessId();
+
+ void
+ reply(const Interest& commandInterest, const RepoCommandResponse& response);
+
+
+ /**
+ * @brief extract RepoCommandParameter from a command Interest.
+ * @param interest command Interest
+ * @param prefix Name prefix up to command-verb
+ * @param[out] parameter parsed parameter
+ * @throw RepoCommandParameter::Error parse error
+ */
+ void
+ extractParameter(const Interest& interest, const Name& prefix, RepoCommandParameter& parameter);
+
private:
- Face* m_face;
- StorageHandle* m_storageHandle;
+
+ Face& m_face;
+ StorageHandle& m_storageHandle;
+ KeyChain& m_keyChain;
+ Scheduler& m_scheduler;
};
+inline void
+BaseHandle::reply(const Interest& commandInterest, const RepoCommandResponse& response)
+{
+ Data rdata(commandInterest.getName());
+ rdata.setContent(response.wireEncode());
+ m_keyChain.sign(rdata);
+ m_face.put(rdata);
+}
+
+inline void
+BaseHandle::extractParameter(const Interest& interest, const Name& prefix,
+ RepoCommandParameter& parameter)
+{
+ parameter.wireDecode(interest.getName().get(prefix.size()).blockFromValue());
+}
+
} //namespace repo
#endif // REPO_NDN_HANDLE_BASE_HANDLE_HPP