2013-10-16 21:59:46 +00:00
|
|
|
// Copyright (c) 2013, Facebook, Inc. All rights reserved.
|
|
|
|
// This source code is licensed under the BSD-style license found in the
|
|
|
|
// LICENSE file in the root directory of this source tree. An additional grant
|
|
|
|
// of patent rights can be found in the PATENTS file in the same directory.
|
|
|
|
//
|
2013-10-05 05:32:05 +00:00
|
|
|
#pragma once
|
2013-01-11 19:09:23 +00:00
|
|
|
|
2015-07-01 23:13:49 +00:00
|
|
|
#ifdef FAILED
|
|
|
|
#undef FAILED
|
|
|
|
#endif
|
|
|
|
|
2013-10-04 04:49:15 +00:00
|
|
|
namespace rocksdb {
|
2013-01-11 19:09:23 +00:00
|
|
|
|
|
|
|
class LDBCommandExecuteResult {
|
|
|
|
public:
|
|
|
|
enum State {
|
|
|
|
EXEC_NOT_STARTED = 0, EXEC_SUCCEED = 1, EXEC_FAILED = 2,
|
|
|
|
};
|
|
|
|
|
2014-09-26 17:32:46 +00:00
|
|
|
LDBCommandExecuteResult() : state_(EXEC_NOT_STARTED), message_("") {}
|
2013-01-11 19:09:23 +00:00
|
|
|
|
2014-11-01 02:22:49 +00:00
|
|
|
LDBCommandExecuteResult(State state, std::string& msg) :
|
2014-09-26 17:32:46 +00:00
|
|
|
state_(state), message_(msg) {}
|
2013-01-11 19:09:23 +00:00
|
|
|
|
|
|
|
std::string ToString() {
|
|
|
|
std::string ret;
|
|
|
|
switch (state_) {
|
|
|
|
case EXEC_SUCCEED:
|
|
|
|
break;
|
|
|
|
case EXEC_FAILED:
|
|
|
|
ret.append("Failed: ");
|
|
|
|
break;
|
|
|
|
case EXEC_NOT_STARTED:
|
|
|
|
ret.append("Not started: ");
|
|
|
|
}
|
|
|
|
if (!message_.empty()) {
|
|
|
|
ret.append(message_);
|
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Reset() {
|
|
|
|
state_ = EXEC_NOT_STARTED;
|
|
|
|
message_ = "";
|
|
|
|
}
|
|
|
|
|
|
|
|
bool IsSucceed() {
|
|
|
|
return state_ == EXEC_SUCCEED;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool IsNotStarted() {
|
|
|
|
return state_ == EXEC_NOT_STARTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool IsFailed() {
|
|
|
|
return state_ == EXEC_FAILED;
|
|
|
|
}
|
|
|
|
|
2015-03-17 01:08:59 +00:00
|
|
|
static LDBCommandExecuteResult Succeed(std::string msg) {
|
2013-01-11 19:09:23 +00:00
|
|
|
return LDBCommandExecuteResult(EXEC_SUCCEED, msg);
|
|
|
|
}
|
|
|
|
|
2015-03-17 01:08:59 +00:00
|
|
|
static LDBCommandExecuteResult Failed(std::string msg) {
|
2013-01-11 19:09:23 +00:00
|
|
|
return LDBCommandExecuteResult(EXEC_FAILED, msg);
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
State state_;
|
|
|
|
std::string message_;
|
|
|
|
|
|
|
|
bool operator==(const LDBCommandExecuteResult&);
|
|
|
|
bool operator!=(const LDBCommandExecuteResult&);
|
|
|
|
};
|
|
|
|
|
|
|
|
}
|