-
Notifications
You must be signed in to change notification settings - Fork 109
/
Copy pathlibapi.cpp.mako
216 lines (190 loc) · 6.5 KB
/
libapi.cpp.mako
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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
<%!
import re
from templates import helper as th
def define_dbg(obj, tags):
if re.match("class", obj['type']):
return True
if 'class' not in obj or obj['class'] in tags:
return re.match("enum", obj['type']) or re.match("struct|union", obj['type'])
return False
%><%
n=namespace
N=n.upper()
x=tags['$x']
X=x.upper()
%>/*
*
* Copyright (C) 2019-2024 Intel Corporation
*
* SPDX-License-Identifier: MIT
*
* @file ${name}.cpp
*
* @brief C++ static library for ${n}
*
*/
#include "${x}_lib.h"
extern "C" {
%for s in specs:
## FUNCTION ###################################################################
%for obj in th.filter_items(s['objects'], 'type', 'function'):
///////////////////////////////////////////////////////////////////////////////
%if 'condition' in obj:
#if ${th.subt(n, tags, obj['condition'])}
%endif
%for line in th.make_desc_lines(n, tags, obj):
/// ${line}
%endfor
%for line in th.make_details_lines(n, tags, obj):
/// ${line}
%endfor
///
%for line in th.make_returns_lines(n, tags, obj, meta=meta):
/// ${line}
%endfor
${x}_result_t ${X}_APICALL
${th.make_func_name(n, tags, obj)}(
%for line in th.make_param_lines(n, tags, obj):
${line}
%endfor
)
{
%if re.match("Init", obj['name']):
%if re.match("zes", n):
#ifdef DYNAMIC_LOAD_LOADER
if (!${x}_lib::context) {
${x}_lib::context = new ${x}_lib::context_t;
}
#endif
static ${x}_result_t result = ${X}_RESULT_SUCCESS;
std::call_once(${x}_lib::context->initOnceSysMan, [flags]() {
result = ${x}_lib::context->Init(flags, true, nullptr);
});
if( ${X}_RESULT_SUCCESS != result )
return result;
if(ze_lib::destruction) {
return ${X}_RESULT_ERROR_UNINITIALIZED;
}
auto ${th.make_pfn_name(n, tags, obj)} = ${x}_lib::context->${n}DdiTable.load()->${th.get_table_name(n, tags, obj)}.${th.make_pfn_name(n, tags, obj)};
if( nullptr == ${th.make_pfn_name(n, tags, obj)} ) {
if(!ze_lib::context->isInitialized)
return ${X}_RESULT_ERROR_UNINITIALIZED;
else
return ${X}_RESULT_ERROR_UNSUPPORTED_FEATURE;
}
return ${th.make_pfn_name(n, tags, obj)}( ${", ".join(th.make_param_lines(n, tags, obj, format=["name"]))} );
}
%else:
%if re.match("InitDrivers", obj['name']):
${x}_result_t result = ${X}_RESULT_SUCCESS;
#ifdef DYNAMIC_LOAD_LOADER
if (!${x}_lib::context) {
${x}_lib::context = new ${x}_lib::context_t;
}
#endif
std::call_once(${x}_lib::context->initOnceDrivers, [desc,&result]() {
result = ${x}_lib::context->Init(0, false, desc);
return result;
});
if (result != ${X}_RESULT_SUCCESS) {
return result;
}
if(ze_lib::destruction) {
return ${X}_RESULT_ERROR_UNINITIALIZED;
}
auto ${th.make_pfn_name(n, tags, obj)} = ${x}_lib::context->${n}DdiTable.load()->${th.get_table_name(n, tags, obj)}.${th.make_pfn_name(n, tags, obj)};
if( nullptr == ${th.make_pfn_name(n, tags, obj)} ) {
if(!ze_lib::context->isInitialized)
return ${X}_RESULT_ERROR_UNINITIALIZED;
else
return ${X}_RESULT_ERROR_UNSUPPORTED_FEATURE;
}
result = ${th.make_pfn_name(n, tags, obj)}( ${", ".join(th.make_param_lines(n, tags, obj, format=["name"]))} );
if (result == ${X}_RESULT_SUCCESS) {
if (phDrivers) {
ze_lib::context->${n}Inuse = true;
}
}
return result;
%else:
static ${x}_result_t result = ${X}_RESULT_SUCCESS;
#ifdef DYNAMIC_LOAD_LOADER
if (!${x}_lib::context) {
${x}_lib::context = new ${x}_lib::context_t;
}
#endif
std::call_once(${x}_lib::context->initOnce, [flags]() {
result = ${x}_lib::context->Init(flags, false, nullptr);
if( ${X}_RESULT_SUCCESS != result )
return result;
if(ze_lib::destruction) {
return ${X}_RESULT_ERROR_UNINITIALIZED;
}
auto ${th.make_pfn_name(n, tags, obj)} = ${x}_lib::context->${n}DdiTable.load()->${th.get_table_name(n, tags, obj)}.${th.make_pfn_name(n, tags, obj)};
if( nullptr == ${th.make_pfn_name(n, tags, obj)} ) {
if(!ze_lib::context->isInitialized)
return ${X}_RESULT_ERROR_UNINITIALIZED;
else
return ${X}_RESULT_ERROR_UNSUPPORTED_FEATURE;
}
result = ${th.make_pfn_name(n, tags, obj)}( ${", ".join(th.make_param_lines(n, tags, obj, format=["name"]))} );
return result;
});
if(ze_lib::destruction) {
result = ${X}_RESULT_ERROR_UNINITIALIZED;
}
return result;
%endif
}
%endif
%else:
#ifdef DYNAMIC_LOAD_LOADER
ze_result_t result = ${X}_RESULT_SUCCESS;
if(ze_lib::destruction) {
return ${X}_RESULT_ERROR_UNINITIALIZED;
}
%if re.match(r"\w+DriverGet$", th.make_func_name(n, tags, obj)):
if (${x}_lib::context->${n}DdiTable == nullptr) {
return ${X}_RESULT_ERROR_UNINITIALIZED;
}
%endif
static const ${th.make_pfn_type(n, tags, obj)} ${th.make_pfn_name(n, tags, obj)} = [&result] {
auto ${th.make_pfn_name(n, tags, obj)} = ${x}_lib::context->${n}DdiTable.load()->${th.get_table_name(n, tags, obj)}.${th.make_pfn_name(n, tags, obj)};
if( nullptr == ${th.make_pfn_name(n, tags, obj)} ) {
result = ${X}_RESULT_ERROR_UNSUPPORTED_FEATURE;
}
return ${th.make_pfn_name(n, tags, obj)};
}();
if (result != ${X}_RESULT_SUCCESS) {
return result;
}
return ${th.make_pfn_name(n, tags, obj)}( ${", ".join(th.make_param_lines(n, tags, obj, format=["name"]))} );
#else
if(ze_lib::destruction) {
return ${X}_RESULT_ERROR_UNINITIALIZED;
}
%if re.match(r"\w+DriverGet$", th.make_func_name(n, tags, obj)):
if (${x}_lib::context->${n}DdiTable == nullptr) {
return ${X}_RESULT_ERROR_UNINITIALIZED;
}
%endif
auto ${th.make_pfn_name(n, tags, obj)} = ${x}_lib::context->${n}DdiTable.load()->${th.get_table_name(n, tags, obj)}.${th.make_pfn_name(n, tags, obj)};
if( nullptr == ${th.make_pfn_name(n, tags, obj)} ) {
if(!ze_lib::context->isInitialized)
return ${X}_RESULT_ERROR_UNINITIALIZED;
else
return ${X}_RESULT_ERROR_UNSUPPORTED_FEATURE;
}
%if re.match(r"\w+DriverGet$", th.make_func_name(n, tags, obj)):
ze_lib::context->${n}Inuse = true;
%endif
return ${th.make_pfn_name(n, tags, obj)}( ${", ".join(th.make_param_lines(n, tags, obj, format=["name"]))} );
#endif
}
%endif
%if 'condition' in obj:
#endif // ${th.subt(n, tags, obj['condition'])}
%endif
%endfor
%endfor
} // extern "C"