-
-
Notifications
You must be signed in to change notification settings - Fork 113
/
Copy pathsteam_call_result.cpp
44 lines (36 loc) · 1.43 KB
/
steam_call_result.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
#include "steam_internal.h"
#include "steam_call_result.h"
#include "steam_utils.h"
#define FUNC(name, ...) SteamAPI_ISteamUtils_##name
namespace steam {
static const pair<int, const char*> texts[] = {{k_ESteamAPICallFailureSteamGone, "steam gone"},
{k_ESteamAPICallFailureNetworkFailure, "network failure"},
{k_ESteamAPICallFailureInvalidHandle, "invalid handle"},
{k_ESteamAPICallFailureMismatchedCallback, "mismatched callback"}};
string errorText(ESteamAPICallFailure failure) {
if (failure == k_ESteamAPICallFailureNone)
return {};
return "API call failure: " + formatError(failure, texts, arraySize(texts));
}
void CallResultBase::update(void* data, int data_size, int ident) {
using Status = QueryStatus;
bool failed = false;
if (status == Status::pending) {
auto utilsPtr = Utils::instance().ptr;
auto is_completed = FUNC(IsAPICallCompleted)(utilsPtr, handle, &failed);
if (!failed && is_completed) {
auto result = FUNC(GetAPICallResult)(utilsPtr, handle, data, data_size, ident, &failed);
if (result && !failed)
status = Status::completed;
}
if (failed) {
status = Status::failed;
failure = FUNC(GetAPICallFailureReason)(utilsPtr, handle);
}
}
}
string CallResultBase::failText() const {
return errorText(failure);
}
}
#undef FUNC