management: Controller accepts CommandOptions
refs #2039
The following are deprecated:
* Controller::start overloads, except the overload taking CommandOptions
* Controller::Sign typedef
* Controller::getDefaultCommandTimeout
* ControlCommand::getPrefix
* ControlCommand::getRequestName(ControlParameters)
Change-Id: I8c405498597bdca115b71eec87acf23d28a266b1
diff --git a/src/management/nfd-controller.cpp b/src/management/nfd-controller.cpp
index 2d5b348..1517522 100644
--- a/src/management/nfd-controller.cpp
+++ b/src/management/nfd-controller.cpp
@@ -25,6 +25,10 @@
namespace ndn {
namespace nfd {
+const uint32_t Controller::ERROR_TIMEOUT = 10060;
+const uint32_t Controller::ERROR_SERVER = 500;
+const uint32_t Controller::ERROR_LBOUND = 400;
+
Controller::Controller(Face& face)
: m_face(face)
, m_internalKeyChain(make_shared<KeyChain>())
@@ -43,6 +47,38 @@
const ControlParameters& parameters,
const CommandSucceedCallback& onSuccess,
const CommandFailCallback& onFailure,
+ const CommandOptions& options)
+{
+ Name requestName = command->getRequestName(options.getPrefix(), parameters);
+ Interest interest(requestName);
+ interest.setInterestLifetime(options.getTimeout());
+
+ switch (options.getSigningParamsKind()) {
+ case CommandOptions::SIGNING_PARAMS_DEFAULT:
+ m_keyChain.sign(interest);
+ break;
+ case CommandOptions::SIGNING_PARAMS_IDENTITY:
+ m_keyChain.signByIdentity(interest, options.getSigningIdentity());
+ break;
+ case CommandOptions::SIGNING_PARAMS_CERTIFICATE:
+ m_keyChain.sign(interest, options.getSigningCertificate());
+ break;
+ default:
+ BOOST_ASSERT(false);
+ break;
+ }
+
+ m_face.expressInterest(interest,
+ bind(&Controller::processCommandResponse, this, _2,
+ command, onSuccess, onFailure),
+ bind(onFailure, ERROR_TIMEOUT, "request timed out"));
+}
+
+void
+Controller::startCommand(const shared_ptr<ControlCommand>& command,
+ const ControlParameters& parameters,
+ const CommandSucceedCallback& onSuccess,
+ const CommandFailCallback& onFailure,
const Sign& sign,
const time::milliseconds& timeout)
{
@@ -53,12 +89,10 @@
interest.setInterestLifetime(timeout);
sign(interest);
- // http://msdn.microsoft.com/en-us/library/windows/desktop/ms740668.aspx
- const uint32_t timeoutCode = 10060;
m_face.expressInterest(interest,
bind(&Controller::processCommandResponse, this, _2,
command, onSuccess, onFailure),
- bind(onFailure, timeoutCode, "Command Interest timed out"));
+ bind(onFailure, ERROR_TIMEOUT, "request timed out"));
}
void
@@ -69,21 +103,18 @@
{
/// \todo verify Data signature
- const uint32_t serverErrorCode = 500;
-
ControlResponse response;
try {
response.wireDecode(data.getContent().blockFromValue());
}
- catch (ndn::tlv::Error& e) {
+ catch (tlv::Error& e) {
if (static_cast<bool>(onFailure))
- onFailure(serverErrorCode, e.what());
+ onFailure(ERROR_SERVER, e.what());
return;
}
uint32_t code = response.getCode();
- const uint32_t errorCodeLowerBound = 400;
- if (code >= errorCodeLowerBound) {
+ if (code >= ERROR_LBOUND) {
if (static_cast<bool>(onFailure))
onFailure(code, response.getText());
return;
@@ -93,9 +124,9 @@
try {
parameters.wireDecode(response.getBody());
}
- catch (ndn::tlv::Error& e) {
+ catch (tlv::Error& e) {
if (static_cast<bool>(onFailure))
- onFailure(serverErrorCode, e.what());
+ onFailure(ERROR_SERVER, e.what());
return;
}
@@ -104,7 +135,7 @@
}
catch (ControlCommand::ArgumentError& e) {
if (static_cast<bool>(onFailure))
- onFailure(serverErrorCode, e.what());
+ onFailure(ERROR_SERVER, e.what());
return;
}