Add state tracking plumbing

Summary:
The plan is to get SonarState to take update events and aggregate them into an object, that can be displayed in the UI so you can see what sonar is currently trying to do, and what if anything is failing.
This is pretty rubbish right now, as it just uses a single string to represent state, this is just the initial version I'll iterate on.
I also need to pass the SonarState into the SonarWebSocketImpl, since that's where a lot of the heavy lifting is done, but as long as something is logging state updates here, it proves the concept.
SonarStateUpdateListener is the interface that will be implemented by android and iOS implementations. These implementations will notify an activity or screen that the state has changed and they should reflect that.

Reviewed By: passy

Differential Revision: D8932114

fbshipit-source-id: fb03babfe92be53771eb4d8f10de7ecdc7f1a6d8
This commit is contained in:
John Knox
2018-08-03 07:34:32 -07:00
committed by Facebook Github Bot
parent 3d66b1c9d0
commit fb447e4f84
11 changed files with 259 additions and 0 deletions

37
xplat/Sonar/SonarState.h Normal file
View File

@@ -0,0 +1,37 @@
/*
* 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>
class SonarStep;
class SonarStateUpdateListener;
class SonarState {
friend SonarStep;
public:
SonarState();
void setUpdateListener(std::shared_ptr<SonarStateUpdateListener>);
std::string getState();
/* 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 stateUpdates;
};