]>
Commit | Line | Data |
---|---|---|
f67539c2 TL |
1 | #include <opentracing/dynamic_load.h> |
2 | #include <opentracing/mocktracer/tracer_factory.h> | |
3 | #include <cstdio> | |
4 | #include <cstring> | |
5 | #include <exception> | |
6 | ||
7 | static int OpenTracingMakeTracerFactoryFct(const char* opentracing_version, | |
8 | const char* opentracing_abi_version, | |
9 | const void** error_category, | |
10 | void* error_message, | |
11 | void** tracer_factory) try { | |
12 | if (opentracing_version == nullptr || opentracing_abi_version == nullptr || | |
13 | error_category == nullptr || tracer_factory == nullptr) { | |
14 | fprintf(stderr, | |
15 | "`opentracing_version`, `opentracing_abi_version`, " | |
16 | "`error_category`, and `tracer_factory` must be non-null.\n"); | |
17 | std::terminate(); | |
18 | } | |
19 | ||
20 | if (std::strcmp(opentracing_abi_version, OPENTRACING_ABI_VERSION) != 0) { | |
21 | *error_category = | |
22 | static_cast<const void*>(&opentracing::dynamic_load_error_category()); | |
23 | auto& message = *static_cast<std::string*>(error_message); | |
24 | message = | |
25 | "incompatible OpenTracing ABI versions; " | |
26 | "expected " OPENTRACING_ABI_VERSION " but got "; | |
27 | message.append(opentracing_abi_version); | |
28 | return opentracing::incompatible_library_versions_error.value(); | |
29 | } | |
30 | ||
31 | *tracer_factory = new opentracing::mocktracer::MockTracerFactory{}; | |
32 | ||
33 | return 0; | |
34 | } catch (const std::bad_alloc&) { | |
35 | *error_category = static_cast<const void*>(&std::generic_category()); | |
36 | return static_cast<int>(std::errc::not_enough_memory); | |
37 | } | |
38 | ||
39 | OPENTRACING_DECLARE_IMPL_FACTORY(OpenTracingMakeTracerFactoryFct); |