/
ExecStatus.cpp
116 lines (99 loc) · 2.78 KB
/
ExecStatus.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
// #include "RealisticRendering.h"
#include "UnrealCVPrivate.h"
#include "ExecStatus.h"
bool operator==(const FExecStatus& ExecStatus, const FExecStatusType& ExecStatusType)
{
return (ExecStatus.ExecStatusType == ExecStatusType);
}
bool operator!=(const FExecStatus& ExecStatus, const FExecStatusType& ExecStatusType)
{
return (ExecStatus.ExecStatusType != ExecStatusType);
}
FExecStatus& FExecStatus::operator+=(const FExecStatus& Src)
{
this->MessageBody += "\n" + Src.MessageBody;
if (Src.ExecStatusType == FExecStatusType::OK)
{
}
return *this;
}
FPromise::FPromise()
{
}
FPromise::FPromise(FPromiseDelegate InPromiseDelegate) : PromiseDelegate(InPromiseDelegate) {}
FExecStatus FPromise::CheckStatus()
{
check(this);
return PromiseDelegate.Execute();
}
// DECLARE_DELEGATE_OneParam(FDispatcherDelegate, const TArray< FString >&);
// FExecStatus FExecStatus::Pending = FExecStatus("pending");
// FExecStatus FExecStatus::OK = FExecStatus("ok"); // The status should start with ok or error for client to understand
FExecStatus FExecStatus::InvalidArgument = FExecStatus(FExecStatusType::Error, "Argument Invalid");
// FExecStatus FExecStatus::Error = FExecStatus("error");
FPromise& FExecStatus::GetPromise()
{
check(this->ExecStatusType == FExecStatusType::Pending);
// Check should be in a single line, make it easier to read and debug
// The promise is set only when the operation is async and ExecStatus is pending
return this->Promise;
}
FExecStatus FExecStatus::OK(FString InMessage)
{
return FExecStatus(FExecStatusType::OK, InMessage);
}
FExecStatus FExecStatus::Pending(FString InMessage)
{
return FExecStatus(FExecStatusType::Pending, InMessage);
}
FExecStatus FExecStatus::AsyncQuery(FPromise Promise)
{
return FExecStatus(FExecStatusType::Pending, Promise);
}
FExecStatus FExecStatus::Error(FString ErrorMessage)
{
return FExecStatus(FExecStatusType::Error, ErrorMessage);
}
FString FExecStatus::GetMessage() const // Define how to format the reply string
{
FString TypeName;
switch (ExecStatusType)
{
case FExecStatusType::OK:
if (MessageBody == "")
return "ok";
else
return MessageBody;
case FExecStatusType::Error:
TypeName = "error"; break;
case FExecStatusType::Pending:
TypeName = "pending"; break;
default:
TypeName = "unknown";
}
FString Message = FString::Printf(TEXT("%s %s"), *TypeName, *MessageBody);
return Message;
}
FExecStatus::FExecStatus(FExecStatusType InExecStatusType, FPromise InPromise)
{
ExecStatusType = InExecStatusType;
Promise = InPromise;
}
FExecStatus::FExecStatus(FExecStatusType InExecStatusType, FString InMessage)
{
ExecStatusType = InExecStatusType;
MessageBody = InMessage;
/*
if (InMessage != "")
{
Message = InMessage;
}
else
{
Message = "error Message can not be empty";
}
*/
}
FExecStatus::~FExecStatus()
{
}