Rename SonarState* to FlipperState*
Summary: Part of sonar to flipper rename Reviewed By: passy Differential Revision: D9919821 fbshipit-source-id: a44a2a04d5463750f884f8bf1328e02d56593e82
This commit is contained in:
committed by
Facebook Github Bot
parent
1d2793f701
commit
c1295b1bc9
69
xplat/Flipper/FlipperState.cpp
Normal file
69
xplat/Flipper/FlipperState.cpp
Normal file
@@ -0,0 +1,69 @@
|
||||
/*
|
||||
* Copyright (c) 2018-present, Facebook, Inc.
|
||||
*
|
||||
* This source code is licensed under the MIT license found in the LICENSE
|
||||
* file in the root directory of this source tree.
|
||||
*
|
||||
*/
|
||||
#include "FlipperState.h"
|
||||
#include "FlipperStateUpdateListener.h"
|
||||
#include "SonarStep.h"
|
||||
#include <vector>
|
||||
|
||||
using namespace facebook::flipper;
|
||||
|
||||
/* Class responsible for collecting state updates and combining them into a
|
||||
* view of the current state of the sonar client. */
|
||||
|
||||
|
||||
FlipperState::FlipperState(): log("") {}
|
||||
void FlipperState::setUpdateListener(
|
||||
std::shared_ptr<FlipperStateUpdateListener> listener) {
|
||||
mListener = listener;
|
||||
}
|
||||
|
||||
void FlipperState::started(std::string step) {
|
||||
if (stateMap.find(step) == stateMap.end()) {
|
||||
insertOrder.push_back(step);
|
||||
}
|
||||
stateMap[step] = State::in_progress;
|
||||
if (mListener) {
|
||||
mListener->onUpdate();
|
||||
}
|
||||
}
|
||||
|
||||
void FlipperState::success(std::string step) {
|
||||
log = log + "[Success] " + step + "\n";
|
||||
stateMap[step] = State::success;
|
||||
if (mListener) {
|
||||
mListener->onUpdate();
|
||||
}
|
||||
}
|
||||
|
||||
void FlipperState::failed(std::string step, std::string errorMessage) {
|
||||
log = log + "[Failed] " + step + ": " + errorMessage + "\n";
|
||||
stateMap[step] = State::failed;
|
||||
if (mListener) {
|
||||
mListener->onUpdate();
|
||||
}
|
||||
}
|
||||
|
||||
// TODO: Currently returns string, but should really provide a better
|
||||
// representation of the current state so the UI can show it in a more intuitive
|
||||
// way
|
||||
std::string FlipperState::getState() {
|
||||
return log;
|
||||
}
|
||||
|
||||
std::vector<StateElement> FlipperState::getStateElements() {
|
||||
std::vector<StateElement> v;
|
||||
for (auto stepName : insertOrder) {
|
||||
v.push_back(StateElement(stepName, stateMap[stepName]));
|
||||
}
|
||||
return v;
|
||||
}
|
||||
|
||||
std::shared_ptr<SonarStep> FlipperState::start(std::string step_name) {
|
||||
started(step_name);
|
||||
return std::make_shared<SonarStep>(step_name, this);
|
||||
}
|
||||
Reference in New Issue
Block a user