-
Notifications
You must be signed in to change notification settings - Fork 1
/
shim.cpp
83 lines (67 loc) · 2.58 KB
/
shim.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
#include <cstring>
#include <unity/scopes/Category.h>
#include <unity/scopes/Runtime.h>
extern "C" {
#include "_cgo_export.h"
}
#include "version.h"
#include "helpers.h"
#include "smartptr_helper.h"
#include "scope.h"
using namespace unity::scopes;
using namespace gounityscopes::internal;
void run_scope(const StrData scope_name, const StrData runtime_config,
const StrData scope_config, void *pointer_to_iface,
char **error) {
try {
auto runtime = Runtime::create_scope_runtime(
from_gostring(scope_name), from_gostring(runtime_config));
ScopeAdapter scope(*reinterpret_cast<GoInterface*>(pointer_to_iface));
runtime->run_scope(&scope, from_gostring(scope_config));
} catch (const std::exception &e) {
*error = strdup(e.what());
}
}
char *scope_base_scope_directory(_ScopeBase *scope) {
ScopeBase *s = reinterpret_cast<ScopeBase*>(scope);
return strdup(s->scope_directory().c_str());
}
char *scope_base_cache_directory(_ScopeBase *scope) {
ScopeBase *s = reinterpret_cast<ScopeBase*>(scope);
return strdup(s->cache_directory().c_str());
}
char *scope_base_tmp_directory(_ScopeBase *scope) {
ScopeBase *s = reinterpret_cast<ScopeBase*>(scope);
return strdup(s->tmp_directory().c_str());
}
void *scope_base_settings(_ScopeBase *scope, int *length) {
ScopeBase *s = reinterpret_cast<ScopeBase*>(scope);
Variant settings(s->settings());
return as_bytes(settings.serialize_json(), length);
}
void destroy_category_ptr(SharedPtrData data) {
destroy_ptr<const Category>(data);
}
_ScopeMetadata** list_registry_scopes_metadata(_ScopeBase *scope, int *n_scopes) {
ScopeBase *s = reinterpret_cast<ScopeBase*>(scope);
auto registry = s->registry();
auto scopes = registry->list();
*n_scopes = scopes.size();
_ScopeMetadata** ret_data = reinterpret_cast<_ScopeMetadata**>(calloc(*n_scopes, sizeof(_ScopeMetadata*)));
int i = 0;
for( auto item: scopes ) {
ret_data[i++] = reinterpret_cast<_ScopeMetadata*>(new ScopeMetadata(item.second));
}
return ret_data;
}
_ChildScope **list_child_scopes(_ScopeBase *scope, int *n_scopes) {
ScopeBase *s = reinterpret_cast<ScopeBase*>(scope);
auto child_scopes = s->child_scopes();
*n_scopes = child_scopes.size();
_ChildScope** ret_data = reinterpret_cast<_ChildScope**>(calloc(*n_scopes, sizeof(_ChildScope*)));
int i = 0;
for (auto item: child_scopes) {
ret_data[i++] = reinterpret_cast<_ChildScope*>(new ChildScope(item.id, item.metadata, item.enabled, item.keywords));
}
return ret_data;
}