23
23
#define NDN_CXX_MGMT_DISPATCHER_HPP
24
24
25
25
#include " ndn-cxx/face.hpp"
26
- #include " ndn-cxx/encoding/block.hpp"
27
26
#include " ndn-cxx/ims/in-memory-storage-fifo.hpp"
27
+ #include " ndn-cxx/mgmt/control-parameters-base.hpp"
28
28
#include " ndn-cxx/mgmt/control-response.hpp"
29
- #include " ndn-cxx/mgmt/control-parameters.hpp"
30
29
#include " ndn-cxx/mgmt/status-dataset-context.hpp"
31
30
#include " ndn-cxx/security/key-chain.hpp"
32
31
@@ -75,7 +74,7 @@ using RejectContinuation = std::function<void(RejectReply)>;
75
74
* Either \p accept or \p reject must be called after authorization completes.
76
75
*/
77
76
using Authorization = std::function<void (const Name& prefix, const Interest& interest,
78
- const ControlParameters * params,
77
+ const ControlParametersBase * params,
79
78
const AcceptContinuation& accept,
80
79
const RejectContinuation& reject)>;
81
80
@@ -92,23 +91,24 @@ makeAcceptAllAuthorization();
92
91
* \param params The parsed ControlParameters; guaranteed to be of the correct (sub-)type
93
92
* for the command.
94
93
*/
95
- using ValidateParameters = std::function<bool (ControlParameters & params)>;
94
+ using ValidateParameters = std::function<bool (ControlParametersBase & params)>;
96
95
97
96
/* *
98
97
* \brief A function to be called after a ControlCommandHandler completes.
99
98
* \param resp The response that should be sent back to the requester.
100
99
*/
101
100
using CommandContinuation = std::function<void (const ControlResponse& resp)>;
102
101
103
- /* * \brief A function to handle an authorized ControlCommand.
104
- * \param prefix top-level prefix, e.g., "/localhost/nfd";
105
- * \param interest incoming Interest
106
- * \param params parsed ControlParameters;
107
- * This is guaranteed to have correct type for the command,
108
- * and is valid (e.g., has all required fields).
102
+ /* *
103
+ * \brief A function to handle an authorized ControlCommand.
104
+ * \param prefix Top-level prefix, e.g., `/localhost/nfd`.
105
+ * \param interest Incoming Interest carrying the request.
106
+ * \param params The parsed ControlParameters; guaranteed to be of the correct (sub-)type
107
+ * and to be valid for the command (e.g., has all the required fields).
108
+ * \param done Function that must be called after command processing is complete.
109
109
*/
110
110
using ControlCommandHandler = std::function<void (const Name& prefix, const Interest& interest,
111
- const ControlParameters & params,
111
+ const ControlParametersBase & params,
112
112
const CommandContinuation& done)>;
113
113
114
114
// ---- STATUS DATASET ----
@@ -211,7 +211,7 @@ class Dispatcher : noncopyable
211
211
* 8. Send the signed Data packet.
212
212
*/
213
213
template <typename ParametersType,
214
- std::enable_if_t <std::is_convertible_v<ParametersType*, ControlParameters *>, int > = 0 >
214
+ std::enable_if_t <std::is_convertible_v<ParametersType*, ControlParametersBase *>, int > = 0 >
215
215
void
216
216
addControlCommand (const PartialName& relPrefix,
217
217
Authorization authorize,
@@ -222,7 +222,7 @@ class Dispatcher : noncopyable
222
222
223
223
auto relPrefixLen = relPrefix.size ();
224
224
ParametersParser parse = [relPrefixLen] (const Name& prefix,
225
- const auto & interest) -> shared_ptr<ControlParameters> {
225
+ const auto & interest) -> ControlParametersPtr {
226
226
const name::Component& comp = interest.getName ().get (prefix.size () + relPrefixLen);
227
227
return make_shared<ParametersType>(comp.blockFromValue ());
228
228
};
@@ -349,14 +349,15 @@ class Dispatcher : noncopyable
349
349
addNotificationStream (const PartialName& relPrefix);
350
350
351
351
private:
352
+ using ControlParametersPtr = shared_ptr<ControlParametersBase>;
352
353
using InterestHandler = std::function<void (const Name& prefix, const Interest&)>;
353
354
354
355
/* *
355
356
* @brief The parser for extracting the parameters from a command request.
356
357
* @return A shared pointer to the extracted ControlParameters.
357
358
* @throw tlv::Error The request parameters cannot be parsed.
358
359
*/
359
- using ParametersParser = std::function<shared_ptr<ControlParameters> (const Name& prefix, const Interest&)>;
360
+ using ParametersParser = std::function<ControlParametersPtr (const Name& prefix, const Interest&)>;
360
361
361
362
void
362
363
checkPrefix (const PartialName& relPrefix) const ;
@@ -443,7 +444,7 @@ class Dispatcher : noncopyable
443
444
void
444
445
processAuthorizedCommand (const Name& prefix,
445
446
const Interest& interest,
446
- const shared_ptr<ControlParameters> & parameters,
447
+ const ControlParametersPtr & parameters,
447
448
const ValidateParameters& validate,
448
449
const ControlCommandHandler& handler);
449
450
@@ -490,17 +491,17 @@ class Dispatcher : noncopyable
490
491
postNotification (const Block& notification, const PartialName& relPrefix);
491
492
492
493
private:
494
+ Face& m_face;
495
+ KeyChain& m_keyChain;
496
+ security::SigningInfo m_signingInfo;
497
+
493
498
struct TopPrefixEntry
494
499
{
495
500
ScopedRegisteredPrefixHandle registeredPrefix;
496
501
std::vector<ScopedInterestFilterHandle> interestFilters;
497
502
};
498
503
std::unordered_map<Name, TopPrefixEntry> m_topLevelPrefixes;
499
504
500
- Face& m_face;
501
- KeyChain& m_keyChain;
502
- security::SigningInfo m_signingInfo;
503
-
504
505
std::unordered_map<PartialName, InterestHandler> m_handlers;
505
506
506
507
// NotificationStream name => next sequence number
0 commit comments