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-2022, 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::autoconfig {
29 
30 void
32 {
33  if (m_isInProgress) {
34  NDN_THROW(Error("Cannot start a stage when it's in progress"));
35  }
36  m_isInProgress = true;
37 
38  std::cerr << "Starting " << this->getName() << " stage" << std::endl;
39  this->doStart();
40 }
41 
42 void
43 Stage::provideHubFaceUri(const std::string& s)
44 {
45  FaceUri u;
46  if (u.parse(s)) {
47  this->succeed(u);
48  }
49  else {
50  this->fail("Cannot parse FaceUri: " + s);
51  }
52 }
53 
54 void
55 Stage::succeed(const FaceUri& hubFaceUri)
56 {
57  std::cerr << "Stage " << this->getName() << " succeeded with " << hubFaceUri << std::endl;
58  this->onSuccess(hubFaceUri);
59  m_isInProgress = false;
60 }
61 
62 void
63 Stage::fail(const std::string& msg)
64 {
65  std::cerr << "Stage " << this->getName() << " failed: " << msg << std::endl;
66  this->onFailure(msg);
67  m_isInProgress = false;
68 }
69 
70 } // namespace ndn::autoconfig
void start()
Start running this stage.
Definition: stage.cpp:31
void provideHubFaceUri(const std::string &s)
Parse HUB FaceUri from string and declare success.
Definition: stage.cpp:43
signal::Signal< Stage, FaceUri > onSuccess
Signal emitted when a HUB FaceUri is found.
Definition: stage.hpp:85
virtual const std::string & getName() const =0
Get stage name.
signal::Signal< Stage, std::string > onFailure
Signal emitted when discovery fails.
Definition: stage.hpp:92
void succeed(const FaceUri &hubFaceUri)
Definition: stage.cpp:55
void fail(const std::string &msg)
Definition: stage.cpp:63