stage.cpp
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2 /*
3  * Copyright (c) 2014-2017, Regents of the University of California,
4  * Arizona Board of Regents,
5  * Colorado State University,
6  * University Pierre & Marie Curie, Sorbonne University,
7  * Washington University in St. Louis,
8  * Beijing Institute of Technology,
9  * The University of Memphis.
10  *
11  * This file is part of NFD (Named Data Networking Forwarding Daemon).
12  * See AUTHORS.md for complete list of NFD authors and contributors.
13  *
14  * NFD is free software: you can redistribute it and/or modify it under the terms
15  * of the GNU General Public License as published by the Free Software Foundation,
16  * either version 3 of the License, or (at your option) any later version.
17  *
18  * NFD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
19  * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
20  * PURPOSE. See the GNU General Public License for more details.
21  *
22  * You should have received a copy of the GNU General Public License along with
23  * NFD, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
24  */
25 
26 #include "stage.hpp"
27 
28 namespace ndn {
29 namespace tools {
30 namespace autoconfig {
31 
32 void
34 {
35  if (m_isInProgress) {
36  BOOST_THROW_EXCEPTION(Error("Cannot start a stage when it's in progress"));
37  }
38  m_isInProgress = true;
39 
40  std::cerr << "Starting " << this->getName() << " stage" << std::endl;
41  this->doStart();
42 }
43 
44 void
45 Stage::provideHubFaceUri(const std::string& s)
46 {
47  FaceUri u;
48  if (u.parse(s)) {
49  this->succeed(u);
50  }
51  else {
52  this->fail("Cannot parse FaceUri: " + s);
53  }
54 }
55 
56 void
57 Stage::succeed(const FaceUri& hubFaceUri)
58 {
59  std::cerr << "Stage " << this->getName() << " succeeded with " << hubFaceUri << std::endl;
60  this->onSuccess(hubFaceUri);
61  m_isInProgress = false;
62 }
63 
64 void
65 Stage::fail(const std::string& msg)
66 {
67  std::cerr << "Stage " << this->getName() << " failed: " << msg << std::endl;
68  this->onFailure(msg);
69  m_isInProgress = false;
70 }
71 
72 } // namespace autoconfig
73 } // namespace tools
74 } // namespace ndn
Copyright (c) 2014-2017, Regents of the University of California, Arizona Board of Regents...
void fail(const std::string &msg)
Definition: stage.cpp:65
util::Signal< Stage, FaceUri > onSuccess
signal when a HUB FaceUri is found
Definition: stage.hpp:90
void start()
start running this stage
Definition: stage.cpp:33
util::Signal< Stage, std::string > onFailure
signal when discovery fails
Definition: stage.hpp:96
virtual const std::string & getName() const =0
get stage name
void succeed(const FaceUri &hubFaceUri)
Definition: stage.cpp:57
void provideHubFaceUri(const std::string &s)
parse HUB FaceUri from string and declare success
Definition: stage.cpp:45