Viewing is open to everyone. Downloading and starring need a GitHub sign-in. Sign in with GitHub

NativeMethods.cs

v0.1.0-build.85 Latest Commit ede38f5

Size
19 KB
Lines
314
Language
csharp
SHA-256
a3cabfacf2c4…
View on GitHub

Sign in with GitHub to download. Each download is recorded with your GitHub username.

1// P/Invoke declarations for include/ckey/ckey.h and include/ckey/telemetry.h.
2// Every parameter is blittable (pointers, fixed-width integers, double,
3// nuint for size_t), so [LibraryImport] (net8.0) generates no marshalling
4// code and the [DllImport] fallback (netstandard2.0) marshals nothing either.
5// C enums are passed as int; ckey_status is returned as int.
6// Each function is declared twice (#if) with an identical signature; keep
7// the two halves in sync when the C ABI changes.
8using System.Runtime.InteropServices;
9
10namespace OpenCKey.Interop
11{
12 internal static class NativeLibraryName
13 {
14 /// <summary>ckeynative.dll / libckeynative.so / libckeynative.dylib (sdk/dotnet/native).</summary>
15 internal const string Name = "ckeynative";
16 }
17
18 /// <summary>Codec, scan, render and certify functions of the ckey native library.</summary>
19 internal static unsafe partial class NativeMethods
20 {
21#if NET7_0_OR_GREATER
22 [LibraryImport(NativeLibraryName.Name)]
23 internal static partial int ckey_safe_action_parse(byte* payload, nuint length, NativeSafeAction* output, NativeDiagnostics* diagnostics);
24#else
25 [DllImport(NativeLibraryName.Name, CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
26 internal static extern int ckey_safe_action_parse(byte* payload, nuint length, NativeSafeAction* output, NativeDiagnostics* diagnostics);
27#endif
28#if NET7_0_OR_GREATER
29 [LibraryImport(NativeLibraryName.Name)]
30 internal static partial int ckey_safe_action_verify(byte* payload, nuint length, byte* publicKey, ulong now, uint maxLifetime, NativeSafeAction* output, NativeDiagnostics* diagnostics);
31#else
32 [DllImport(NativeLibraryName.Name, CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
33 internal static extern int ckey_safe_action_verify(byte* payload, nuint length, byte* publicKey, ulong now, uint maxLifetime, NativeSafeAction* output, NativeDiagnostics* diagnostics);
34#endif
35#if NET7_0_OR_GREATER
36 [LibraryImport(NativeLibraryName.Name)]
37 internal static partial uint ckey_get_abi_version();
38#else
39 [DllImport(NativeLibraryName.Name, CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
40 internal static extern uint ckey_get_abi_version();
41#endif
42#if NET7_0_OR_GREATER
43 [LibraryImport(NativeLibraryName.Name)]
44 internal static partial byte* ckey_get_software_version();
45#else
46 [DllImport(NativeLibraryName.Name, CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
47 internal static extern byte* ckey_get_software_version();
48#endif
49#if NET7_0_OR_GREATER
50 [LibraryImport(NativeLibraryName.Name)]
51 internal static partial int ckey_decode_gray8(byte* gray, nuint width, nuint height, nuint stride, double* quad, byte* outPayload, nuint outCapacity, NativeDiagnostics* diagnostics);
52#else
53 [DllImport(NativeLibraryName.Name, CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
54 internal static extern int ckey_decode_gray8(byte* gray, nuint width, nuint height, nuint stride, double* quad, byte* outPayload, nuint outCapacity, NativeDiagnostics* diagnostics);
55#endif
56#if NET7_0_OR_GREATER
57 [LibraryImport(NativeLibraryName.Name)]
58 internal static partial int ckey_decode_text_gray8(byte* gray, nuint width, nuint height, nuint stride, double* quad, byte* outPayload, nuint outCapacity, nuint* outLength, NativeDiagnostics* diagnostics);
59#else
60 [DllImport(NativeLibraryName.Name, CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
61 internal static extern int ckey_decode_text_gray8(byte* gray, nuint width, nuint height, nuint stride, double* quad, byte* outPayload, nuint outCapacity, nuint* outLength, NativeDiagnostics* diagnostics);
62#endif
63#if NET7_0_OR_GREATER
64 [LibraryImport(NativeLibraryName.Name)]
65 internal static partial int ckey_decode_extended_gray8(byte* gray, nuint width, nuint height, nuint stride, double* quad, byte* outPayload, nuint outCapacity, nuint* outLength, NativeDiagnostics* diagnostics);
66#else
67 [DllImport(NativeLibraryName.Name, CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
68 internal static extern int ckey_decode_extended_gray8(byte* gray, nuint width, nuint height, nuint stride, double* quad, byte* outPayload, nuint outCapacity, nuint* outLength, NativeDiagnostics* diagnostics);
69#endif
70#if NET7_0_OR_GREATER
71 [LibraryImport(NativeLibraryName.Name)]
72 internal static partial nuint ckey_find_borders_gray8(byte* gray, nuint width, nuint height, nuint stride, double* outQuads, nuint maxQuads);
73#else
74 [DllImport(NativeLibraryName.Name, CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
75 internal static extern nuint ckey_find_borders_gray8(byte* gray, nuint width, nuint height, nuint stride, double* outQuads, nuint maxQuads);
76#endif
77#if NET7_0_OR_GREATER
78 [LibraryImport(NativeLibraryName.Name)]
79 internal static partial double ckey_refine_quad_gray8(byte* gray, nuint width, nuint height, nuint stride, double* borderQuad, int field, double* outQuad);
80#else
81 [DllImport(NativeLibraryName.Name, CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
82 internal static extern double ckey_refine_quad_gray8(byte* gray, nuint width, nuint height, nuint stride, double* borderQuad, int field, double* outQuad);
83#endif
84#if NET7_0_OR_GREATER
85 [LibraryImport(NativeLibraryName.Name)]
86 internal static partial uint ckey_scalable_modules_across(uint version);
87#else
88 [DllImport(NativeLibraryName.Name, CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
89 internal static extern uint ckey_scalable_modules_across(uint version);
90#endif
91#if NET7_0_OR_GREATER
92 [LibraryImport(NativeLibraryName.Name)]
93 internal static partial nuint ckey_scalable_capacity(uint version, int level, int layout);
94#else
95 [DllImport(NativeLibraryName.Name, CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
96 internal static extern nuint ckey_scalable_capacity(uint version, int level, int layout);
97#endif
98#if NET7_0_OR_GREATER
99 [LibraryImport(NativeLibraryName.Name)]
100 internal static partial int ckey_encode_scalable(byte* payload, nuint payloadLength, uint version, int level, int layout, NativeScalableSymbol* outSymbol, NativeDiagnostics* diagnostics);
101#else
102 [DllImport(NativeLibraryName.Name, CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
103 internal static extern int ckey_encode_scalable(byte* payload, nuint payloadLength, uint version, int level, int layout, NativeScalableSymbol* outSymbol, NativeDiagnostics* diagnostics);
104#endif
105#if NET7_0_OR_GREATER
106 [LibraryImport(NativeLibraryName.Name)]
107 internal static partial int ckey_decode_scalable_gray8(byte* gray, nuint width, nuint height, nuint stride, double* quad, byte* outPayload, nuint outCapacity, nuint* outLength, uint* outVersion, uint* outLayout, NativeDiagnostics* diagnostics);
108#else
109 [DllImport(NativeLibraryName.Name, CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
110 internal static extern int ckey_decode_scalable_gray8(byte* gray, nuint width, nuint height, nuint stride, double* quad, byte* outPayload, nuint outCapacity, nuint* outLength, uint* outVersion, uint* outLayout, NativeDiagnostics* diagnostics);
111#endif
112#if NET7_0_OR_GREATER
113 [LibraryImport(NativeLibraryName.Name)]
114 internal static partial double ckey_calibration_score_scalable_gray8(byte* gray, nuint width, nuint height, nuint stride, double* quad, uint* outVersion);
115#else
116 [DllImport(NativeLibraryName.Name, CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
117 internal static extern double ckey_calibration_score_scalable_gray8(byte* gray, nuint width, nuint height, nuint stride, double* quad, uint* outVersion);
118#endif
119#if NET7_0_OR_GREATER
120 [LibraryImport(NativeLibraryName.Name)]
121 internal static partial void ckey_style_default(NativeStyle* style);
122#else
123 [DllImport(NativeLibraryName.Name, CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
124 internal static extern void ckey_style_default(NativeStyle* style);
125#endif
126#if NET7_0_OR_GREATER
127 [LibraryImport(NativeLibraryName.Name)]
128 internal static partial int ckey_style_preset_fill(NativeStyle* style, int preset);
129#else
130 [DllImport(NativeLibraryName.Name, CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
131 internal static extern int ckey_style_preset_fill(NativeStyle* style, int preset);
132#endif
133#if NET7_0_OR_GREATER
134 [LibraryImport(NativeLibraryName.Name)]
135 internal static partial double ckey_scalable_logo_max_radius(uint version, int layout);
136#else
137 [DllImport(NativeLibraryName.Name, CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
138 internal static extern double ckey_scalable_logo_max_radius(uint version, int layout);
139#endif
140#if NET7_0_OR_GREATER
141 [LibraryImport(NativeLibraryName.Name)]
142 internal static partial double ckey_scalable_logo_load(NativeScalableSymbol* symbol, double logoRadius);
143#else
144 [DllImport(NativeLibraryName.Name, CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
145 internal static extern double ckey_scalable_logo_load(NativeScalableSymbol* symbol, double logoRadius);
146#endif
147#if NET7_0_OR_GREATER
148 [LibraryImport(NativeLibraryName.Name)]
149 internal static partial int ckey_check_scalable_style(NativeScalableSymbol* symbol, NativeStyle* style, NativeDiagnostics* diagnostics);
150#else
151 [DllImport(NativeLibraryName.Name, CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
152 internal static extern int ckey_check_scalable_style(NativeScalableSymbol* symbol, NativeStyle* style, NativeDiagnostics* diagnostics);
153#endif
154#if NET7_0_OR_GREATER
155 [LibraryImport(NativeLibraryName.Name)]
156 internal static partial int ckey_render_scalable_styled_svg(NativeScalableSymbol* symbol, NativeStyle* style, uint scale, byte* outUtf8, nuint outCapacity, nuint* outRequired);
157#else
158 [DllImport(NativeLibraryName.Name, CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
159 internal static extern int ckey_render_scalable_styled_svg(NativeScalableSymbol* symbol, NativeStyle* style, uint scale, byte* outUtf8, nuint outCapacity, nuint* outRequired);
160#endif
161#if NET7_0_OR_GREATER
162 [LibraryImport(NativeLibraryName.Name)]
163 internal static partial int ckey_render_scalable_print(NativeScalableSymbol* symbol, NativeStyle* style, double widthInches, double dpi, byte* outGray, nuint outCapacity, nuint* outSide);
164#else
165 [DllImport(NativeLibraryName.Name, CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
166 internal static extern int ckey_render_scalable_print(NativeScalableSymbol* symbol, NativeStyle* style, double widthInches, double dpi, byte* outGray, nuint outCapacity, nuint* outSide);
167#endif
168#if NET7_0_OR_GREATER
169 [LibraryImport(NativeLibraryName.Name)]
170 internal static partial void ckey_raster_options_default(NativeRasterOptions* options);
171#else
172 [DllImport(NativeLibraryName.Name, CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
173 internal static extern void ckey_raster_options_default(NativeRasterOptions* options);
174#endif
175#if NET7_0_OR_GREATER
176 [LibraryImport(NativeLibraryName.Name)]
177 internal static partial int ckey_render_scalable_raster(NativeScalableSymbol* symbol, NativeStyle* style, NativeRasterOptions* options, byte* output, nuint outCapacity, nuint* outRequired);
178#else
179 [DllImport(NativeLibraryName.Name, CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
180 internal static extern int ckey_render_scalable_raster(NativeScalableSymbol* symbol, NativeStyle* style, NativeRasterOptions* options, byte* output, nuint outCapacity, nuint* outRequired);
181#endif
182#if NET7_0_OR_GREATER
183 [LibraryImport(NativeLibraryName.Name)]
184 internal static partial int ckey_encode_png(byte* pixels, uint width, uint height, nuint stride, int format, double dpi, byte* output, nuint outCapacity, nuint* outRequired);
185#else
186 [DllImport(NativeLibraryName.Name, CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
187 internal static extern int ckey_encode_png(byte* pixels, uint width, uint height, nuint stride, int format, double dpi, byte* output, nuint outCapacity, nuint* outRequired);
188#endif
189#if NET7_0_OR_GREATER
190 [LibraryImport(NativeLibraryName.Name)]
191 internal static partial int ckey_render_scalable_pdf(NativeScalableSymbol* symbol, NativeStyle* style, double widthPt, uint transparent, byte* output, nuint outCapacity, nuint* outRequired);
192#else
193 [DllImport(NativeLibraryName.Name, CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
194 internal static extern int ckey_render_scalable_pdf(NativeScalableSymbol* symbol, NativeStyle* style, double widthPt, uint transparent, byte* output, nuint outCapacity, nuint* outRequired);
195#endif
196#if NET7_0_OR_GREATER
197 [LibraryImport(NativeLibraryName.Name)]
198 internal static partial void ckey_scan_model_default(NativeScanModel* model);
199#else
200 [DllImport(NativeLibraryName.Name, CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
201 internal static extern void ckey_scan_model_default(NativeScanModel* model);
202#endif
203#if NET7_0_OR_GREATER
204 [LibraryImport(NativeLibraryName.Name)]
205 internal static partial int ckey_certify_scalable_style(NativeScalableSymbol* symbol, NativeStyle* style, uint transparent, NativeBackdrop* backdrop, NativeScanModel* model, NativeStyle* outStyle, NativeCertification* output);
206#else
207 [DllImport(NativeLibraryName.Name, CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
208 internal static extern int ckey_certify_scalable_style(NativeScalableSymbol* symbol, NativeStyle* style, uint transparent, NativeBackdrop* backdrop, NativeScanModel* model, NativeStyle* outStyle, NativeCertification* output);
209#endif
210 }
211
212 /// <summary>Telemetry functions; absent when the native library was built with CKEY_DOTNET_TELEMETRY=OFF.</summary>
213 internal static unsafe partial class NativeTelemetry
214 {
215#if NET7_0_OR_GREATER
216 [LibraryImport(NativeLibraryName.Name)]
217 internal static partial int ckey_telemetry_set_mode(int mode);
218#else
219 [DllImport(NativeLibraryName.Name, CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
220 internal static extern int ckey_telemetry_set_mode(int mode);
221#endif
222#if NET7_0_OR_GREATER
223 [LibraryImport(NativeLibraryName.Name)]
224 internal static partial int ckey_telemetry_get_mode();
225#else
226 [DllImport(NativeLibraryName.Name, CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
227 internal static extern int ckey_telemetry_get_mode();
228#endif
229#if NET7_0_OR_GREATER
230 [LibraryImport(NativeLibraryName.Name)]
231 internal static partial int ckey_telemetry_set_client(byte* sdk, byte* sdkVersion, byte* platform);
232#else
233 [DllImport(NativeLibraryName.Name, CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
234 internal static extern int ckey_telemetry_set_client(byte* sdk, byte* sdkVersion, byte* platform);
235#endif
236#if NET7_0_OR_GREATER
237 [LibraryImport(NativeLibraryName.Name)]
238 internal static partial void ckey_telemetry_session_begin(ulong nowMs);
239#else
240 [DllImport(NativeLibraryName.Name, CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
241 internal static extern void ckey_telemetry_session_begin(ulong nowMs);
242#endif
243#if NET7_0_OR_GREATER
244 [LibraryImport(NativeLibraryName.Name)]
245 internal static partial void ckey_telemetry_frame(ulong nowMs, uint processingMs);
246#else
247 [DllImport(NativeLibraryName.Name, CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
248 internal static extern void ckey_telemetry_frame(ulong nowMs, uint processingMs);
249#endif
250#if NET7_0_OR_GREATER
251 [LibraryImport(NativeLibraryName.Name)]
252 internal static partial int ckey_telemetry_session_success(ulong nowMs, uint profileCode);
253#else
254 [DllImport(NativeLibraryName.Name, CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
255 internal static extern int ckey_telemetry_session_success(ulong nowMs, uint profileCode);
256#endif
257#if NET7_0_OR_GREATER
258 [LibraryImport(NativeLibraryName.Name)]
259 internal static partial void ckey_telemetry_session_end(ulong nowMs);
260#else
261 [DllImport(NativeLibraryName.Name, CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
262 internal static extern void ckey_telemetry_session_end(ulong nowMs);
263#endif
264#if NET7_0_OR_GREATER
265 [LibraryImport(NativeLibraryName.Name)]
266 internal static partial int ckey_telemetry_snapshot(NativeTelemetryCounters* output);
267#else
268 [DllImport(NativeLibraryName.Name, CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
269 internal static extern int ckey_telemetry_snapshot(NativeTelemetryCounters* output);
270#endif
271#if NET7_0_OR_GREATER
272 [LibraryImport(NativeLibraryName.Name)]
273 internal static partial int ckey_telemetry_should_send(ulong nowMs);
274#else
275 [DllImport(NativeLibraryName.Name, CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
276 internal static extern int ckey_telemetry_should_send(ulong nowMs);
277#endif
278#if NET7_0_OR_GREATER
279 [LibraryImport(NativeLibraryName.Name)]
280 internal static partial int ckey_telemetry_take_batch(byte* utcDay, byte* outJson, nuint capacity, nuint* outLength, ulong* outBatchId);
281#else
282 [DllImport(NativeLibraryName.Name, CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
283 internal static extern int ckey_telemetry_take_batch(byte* utcDay, byte* outJson, nuint capacity, nuint* outLength, ulong* outBatchId);
284#endif
285#if NET7_0_OR_GREATER
286 [LibraryImport(NativeLibraryName.Name)]
287 internal static partial int ckey_telemetry_batch_result(ulong batchId, int httpStatus, ulong nowMs);
288#else
289 [DllImport(NativeLibraryName.Name, CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
290 internal static extern int ckey_telemetry_batch_result(ulong batchId, int httpStatus, ulong nowMs);
291#endif
292#if NET7_0_OR_GREATER
293 [LibraryImport(NativeLibraryName.Name)]
294 internal static partial int ckey_telemetry_export_state(byte* output, nuint capacity, nuint* length);
295#else
296 [DllImport(NativeLibraryName.Name, CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
297 internal static extern int ckey_telemetry_export_state(byte* output, nuint capacity, nuint* length);
298#endif
299#if NET7_0_OR_GREATER
300 [LibraryImport(NativeLibraryName.Name)]
301 internal static partial int ckey_telemetry_import_state(byte* json);
302#else
303 [DllImport(NativeLibraryName.Name, CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
304 internal static extern int ckey_telemetry_import_state(byte* json);
305#endif
306#if NET7_0_OR_GREATER
307 [LibraryImport(NativeLibraryName.Name)]
308 internal static partial void ckey_telemetry_reset_for_testing();
309#else
310 [DllImport(NativeLibraryName.Name, CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
311 internal static extern void ckey_telemetry_reset_for_testing();
312#endif
313 }
314}