Summary: Adds a more structured representation of state updates than a multiline string. Also changes the string form to omit [started] records. Reviewed By: danielbuechele Differential Revision: D9315503 fbshipit-source-id: 55b8f9572091fd42fe852c8d26a8f2a53f76c82a
59 lines
1.4 KiB
C++
59 lines
1.4 KiB
C++
/*
|
|
* 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.
|
|
*
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
#include <memory>
|
|
#include <string>
|
|
#include <vector>
|
|
#include <map>
|
|
|
|
class SonarStep;
|
|
class SonarStateUpdateListener;
|
|
|
|
namespace facebook {
|
|
namespace sonar {
|
|
|
|
enum State { success, in_progress, failed };
|
|
|
|
class StateElement {
|
|
public:
|
|
StateElement(std::string name, State state): name_(name), state_(state) {};
|
|
std::string name_;
|
|
State state_;
|
|
};
|
|
|
|
}
|
|
}
|
|
|
|
class SonarState {
|
|
friend SonarStep;
|
|
|
|
public:
|
|
SonarState();
|
|
void setUpdateListener(std::shared_ptr<SonarStateUpdateListener>);
|
|
std::string getState();
|
|
std::vector<facebook::sonar::StateElement> getStateElements();
|
|
|
|
/* To record a state update, call start() with the name of the step to get a
|
|
SonarStep object. Call complete on this to register it successful,
|
|
the absense of the completion call when it is destructed will register as a
|
|
step failure. */
|
|
std::shared_ptr<SonarStep> start(std::string step);
|
|
|
|
private:
|
|
void success(std::string);
|
|
void failed(std::string, std::string);
|
|
void started(std::string);
|
|
|
|
std::shared_ptr<SonarStateUpdateListener> mListener = nullptr;
|
|
std::string log;
|
|
std::vector<std::string> insertOrder;
|
|
std::map<std::string, facebook::sonar::State> stateMap;
|
|
};
|