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>
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,
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,
103 this->fetchDataset(make_shared<Dataset>(param), onSuccess, onFailure, options);
108 startCommand(
const shared_ptr<ControlCommand>& command,
115 processCommandResponse(
const Data& data,
116 const shared_ptr<ControlCommand>& command,
121 processValidatedCommandResponse(
const Data& data,
122 const shared_ptr<ControlCommand>& command,
126 template<
typename Dataset>
128 fetchDataset(shared_ptr<Dataset> dataset,
129 const std::function<
void(
typename Dataset::ResultType)>& onSuccess,
134 fetchDataset(
const Name& prefix,
135 const std::function<
void(
const ConstBufferPtr&)>& processResponse,
139 template<
typename Dataset>
141 processDatasetResponse(shared_ptr<Dataset> dataset,
142 const std::function<
void(
typename Dataset::ResultType)>& onSuccess,
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&) {};
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);
207 catch (
const tlv::Error& e) {
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) 2011-2015 Regents of the University of California.
The interface of signing key management.
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
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
Copyright (c) 2011-2015 Regents of the University of California.
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.
const Name & getPrefix() const
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
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