22 #ifndef NDN_MGMT_NFD_CONTROLLER_HPP 23 #define NDN_MGMT_NFD_CONTROLLER_HPP 29 #include "../../security/command-interest-signer.hpp" 30 #include "../../security/validator-null.hpp" 31 #include "../../security/v2/key-chain.hpp" 32 #include "../../security/v2/validator.hpp" 72 template<
typename Command>
75 const CommandSucceedCallback& onSuccess,
76 const CommandFailCallback& onFailure,
79 shared_ptr<ControlCommand> command = make_shared<Command>();
80 this->startCommand(command, parameters, onSuccess, onFailure, options);
85 template<
typename Dataset>
86 typename std::enable_if<std::is_default_constructible<Dataset>::value>::type
87 fetch(
const std::function<
void(
typename Dataset::ResultType)>& onSuccess,
88 const DatasetFailCallback& onFailure,
91 this->fetchDataset(make_shared<Dataset>(), onSuccess, onFailure, options);
96 template<
typename Dataset,
typename ParamType =
typename Dataset::ParamType>
99 const std::function<
void(
typename Dataset::ResultType)>& onSuccess,
100 const DatasetFailCallback& onFailure,
103 this->fetchDataset(make_shared<Dataset>(param), onSuccess, onFailure, options);
108 startCommand(
const shared_ptr<ControlCommand>& command,
110 const CommandSucceedCallback& onSuccess,
111 const CommandFailCallback& onFailure,
115 processCommandResponse(
const Data& data,
116 const shared_ptr<ControlCommand>& command,
117 const CommandSucceedCallback& onSuccess,
118 const CommandFailCallback& onFailure);
121 processValidatedCommandResponse(
const Data& data,
122 const shared_ptr<ControlCommand>& command,
123 const CommandSucceedCallback& onSuccess,
124 const CommandFailCallback& onFailure);
126 template<
typename Dataset>
128 fetchDataset(shared_ptr<Dataset> dataset,
129 const std::function<
void(
typename Dataset::ResultType)>& onSuccess,
130 const DatasetFailCallback& onFailure,
134 fetchDataset(
const Name& prefix,
135 const std::function<
void(
const ConstBufferPtr&)>& processResponse,
136 const DatasetFailCallback& onFailure,
139 template<
typename Dataset>
141 processDatasetResponse(shared_ptr<Dataset> dataset,
142 const std::function<
void(
typename Dataset::ResultType)>& onSuccess,
143 const DatasetFailCallback& onFailure,
147 processDatasetFetchError(
const DatasetFailCallback& onFailure, uint32_t code, std::string msg);
177 template<
typename Dataset>
179 Controller::fetchDataset(shared_ptr<Dataset> dataset,
180 const std::function<
void(
typename Dataset::ResultType)>& onSuccess1,
181 const DatasetFailCallback& onFailure1,
184 const std::function<void(typename Dataset::ResultType)>& onSuccess = onSuccess1 ?
185 onSuccess1 : [] (
const typename Dataset::ResultType&) {};
186 const DatasetFailCallback& onFailure = onFailure1 ?
187 onFailure1 : [] (uint32_t,
const std::string&) {};
189 Name prefix = dataset->getDatasetPrefix(options.
getPrefix());
190 this->fetchDataset(prefix,
191 bind(&Controller::processDatasetResponse<Dataset>,
this, dataset, onSuccess, onFailure, _1),
196 template<
typename Dataset>
198 Controller::processDatasetResponse(shared_ptr<Dataset> dataset,
199 const std::function<
void(
typename Dataset::ResultType)>& onSuccess,
200 const DatasetFailCallback& onFailure,
203 typename Dataset::ResultType result;
205 result = dataset->parseResult(payload);
218 #endif // NDN_MGMT_NFD_CONTROLLER_HPP Helper class to create command interests.
void start(const ControlParameters ¶meters, const CommandSucceedCallback &onSuccess, const CommandFailCallback &onFailure, const CommandOptions &options=CommandOptions())
start command execution
Copyright (c) 2013-2017 Regents of the University of California.
represents parameters in a ControlCommand request or response
security::CommandInterestSigner m_signer
std::enable_if< std::is_default_constructible< Dataset >::value >::type fetch(const std::function< void(typename Dataset::ResultType)> &onSuccess, const DatasetFailCallback &onFailure, const CommandOptions &options=CommandOptions())
start dataset fetching
function< void(const ControlResponse &)> CommandFailCallback
a callback on command failure
const Name & getPrefix() const
static const uint32_t ERROR_TIMEOUT
error code for timeout
function< void(const ControlParameters &)> CommandSucceedCallback
a callback on command success
static const uint32_t ERROR_LBOUND
inclusive lower bound of error codes
contains options for ControlCommand execution
security::v2::Validator & getAcceptAllValidator()
Provide a communication channel with local or remote NDN forwarder.
NFD Management protocol client.
static const uint32_t ERROR_VALIDATION
error code for response validation failure
Controller(Face &face, KeyChain &keyChain, security::v2::Validator &validator=security::getAcceptAllValidator())
construct a Controller that uses face for transport, and uses the passed KeyChain to sign commands ...
Represents an absolute name.
security::v2::Validator & m_validator
Represents a Data packet.
void fetch(const ParamType ¶m, const std::function< void(typename Dataset::ResultType)> &onSuccess, const DatasetFailCallback &onFailure, const CommandOptions &options=CommandOptions())
start dataset fetching
represents an error in TLV encoding or decoding
Interface for validating data and interest packets.
static const uint32_t ERROR_SERVER
error code for server error
static const uint32_t ERROR_NACK
error code for network Nack
function< void(uint32_t code, const std::string &reason)> DatasetFailCallback
a callback on dataset retrieval failure
shared_ptr< const Buffer > ConstBufferPtr