Files
flipper/xplat/Flipper/FlipperState.h
John Knox 1be54ebee1 Add optional debug log switch
Summary:
This won't affect runtime, but is useful when debugging issues with flipper itself.
Setting this flag means all state changes will be output in logcat.

Reviewed By: passy

Differential Revision: D10231148

fbshipit-source-id: 7ddd490290ad973fc339b2f5f93a6f9a1fab4577
2018-10-25 04:14:37 -07:00

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 FlipperStep;
class FlipperStateUpdateListener;
namespace facebook {
namespace flipper {
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 FlipperState {
friend FlipperStep;
public:
FlipperState();
void setUpdateListener(std::shared_ptr<FlipperStateUpdateListener>);
std::string getState();
std::vector<facebook::flipper::StateElement> getStateElements();
/* To record a state update, call start() with the name of the step to get a
FlipperStep 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<FlipperStep> start(std::string step);
private:
void success(std::string);
void failed(std::string, std::string);
void started(std::string);
std::shared_ptr<FlipperStateUpdateListener> mListener = nullptr;
std::string logs;
std::vector<std::string> insertOrder;
std::map<std::string, facebook::flipper::State> stateMap;
};