File: execution_context.cpp

package info (click to toggle)
freespace2 24.2.0%2Brepack-1
  • links: PTS, VCS
  • area: non-free
  • in suites: forky, sid
  • size: 43,716 kB
  • sloc: cpp: 595,001; ansic: 21,741; python: 1,174; sh: 457; makefile: 248; xml: 181
file content (67 lines) | stat: -rw-r--r-- 1,868 bytes parent folder | download | duplicates (2)
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
#include "execution_context.h"

#include "enums.h"

namespace scripting {
namespace api {

execution_context_h::execution_context_h(std::shared_ptr<executor::IExecutionContext> executionContext)
	: m_executionContext(std::move(executionContext))
{
}
const std::shared_ptr<executor::IExecutionContext>& execution_context_h::getExecutionContext() const
{
	return m_executionContext;
}
bool execution_context_h::isValid() const { return m_executionContext != nullptr; }

ADE_OBJ(l_ExecutionContext,
	execution_context_h,
	"execution_context",
	"An execution context for asynchronous operations");

ADE_FUNC(determineState,
	l_ExecutionContext,
	nullptr,
	"Determines the current state of the context.",
	"enumeration",
	"One of the CONTEXT_ enumerations")
{
	execution_context_h* context = nullptr;
	if (!ade_get_args(L, "o", l_ExecutionContext.GetPtr(&context))) {
		return ADE_RETURN_FALSE;
	}

	if (!context->isValid()) {
		return ade_set_args(L, "o", l_Enum.Set(enum_h(LE_CONTEXT_INVALID)));
	}

	const auto state = context->getExecutionContext()->determineContextState();
	switch (state) {
	case executor::IExecutionContext::State::Valid:
		return ade_set_args(L, "o", l_Enum.Set(enum_h(LE_CONTEXT_VALID)));
	case executor::IExecutionContext::State::Suspended:
		return ade_set_args(L, "o", l_Enum.Set(enum_h(LE_CONTEXT_SUSPENDED)));
	case executor::IExecutionContext::State::Invalid:
	default:
		return ade_set_args(L, "o", l_Enum.Set(enum_h(LE_CONTEXT_INVALID)));
	}
}

ADE_FUNC(isValid,
	l_ExecutionContext,
	nullptr,
	"Determines if the handle is valid",
	"boolean",
	"true if valid, false otherwise")
{
	execution_context_h* context = nullptr;
	if (!ade_get_args(L, "o", l_ExecutionContext.GetPtr(&context))) {
		return ADE_RETURN_FALSE;
	}

	return ade_set_args(L, "b", context != nullptr && context->isValid());
}

} // namespace api
} // namespace scripting