fix abi interface
This commit is contained in:
@ -369,7 +369,25 @@ Fn load_symbol(ModuleHandle module, const char* name) {
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template <typename Fn>
|
||||||
|
Fn load_symbol_optional(ModuleHandle module, const char* name) {
|
||||||
|
#ifdef _WIN32
|
||||||
|
const auto addr = GetProcAddress(module, name);
|
||||||
|
return (addr != nullptr) ? reinterpret_cast<Fn>(addr) : nullptr;
|
||||||
|
#else
|
||||||
|
dlerror();
|
||||||
|
void* addr = dlsym(module, name);
|
||||||
|
const char* error = dlerror();
|
||||||
|
if ((addr == nullptr) || (error != nullptr)) {
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
return reinterpret_cast<Fn>(addr);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
struct Api {
|
struct Api {
|
||||||
|
using GetDevInfoFn = int32_t (*)(t_x502_hnd, t_x502_info*);
|
||||||
|
|
||||||
ModuleHandle x502_module = nullptr;
|
ModuleHandle x502_module = nullptr;
|
||||||
ModuleHandle e502_module = nullptr;
|
ModuleHandle e502_module = nullptr;
|
||||||
|
|
||||||
@ -377,6 +395,7 @@ struct Api {
|
|||||||
decltype(&X502_Free) Free = nullptr;
|
decltype(&X502_Free) Free = nullptr;
|
||||||
decltype(&X502_Close) Close = nullptr;
|
decltype(&X502_Close) Close = nullptr;
|
||||||
decltype(&X502_GetErrorString) GetErrorString = nullptr;
|
decltype(&X502_GetErrorString) GetErrorString = nullptr;
|
||||||
|
GetDevInfoFn GetDevInfo = nullptr;
|
||||||
decltype(&X502_GetDevInfo2) GetDevInfo2 = nullptr;
|
decltype(&X502_GetDevInfo2) GetDevInfo2 = nullptr;
|
||||||
decltype(&X502_SetMode) SetMode = nullptr;
|
decltype(&X502_SetMode) SetMode = nullptr;
|
||||||
decltype(&X502_StreamsStop) StreamsStop = nullptr;
|
decltype(&X502_StreamsStop) StreamsStop = nullptr;
|
||||||
@ -416,7 +435,11 @@ struct Api {
|
|||||||
Free = load_symbol<decltype(Free)>(x502_module, "X502_Free");
|
Free = load_symbol<decltype(Free)>(x502_module, "X502_Free");
|
||||||
Close = load_symbol<decltype(Close)>(x502_module, "X502_Close");
|
Close = load_symbol<decltype(Close)>(x502_module, "X502_Close");
|
||||||
GetErrorString = load_symbol<decltype(GetErrorString)>(x502_module, "X502_GetErrorString");
|
GetErrorString = load_symbol<decltype(GetErrorString)>(x502_module, "X502_GetErrorString");
|
||||||
GetDevInfo2 = load_symbol<decltype(GetDevInfo2)>(x502_module, "X502_GetDevInfo2");
|
GetDevInfo = load_symbol_optional<GetDevInfoFn>(x502_module, "X502_GetDevInfo");
|
||||||
|
GetDevInfo2 = load_symbol_optional<decltype(GetDevInfo2)>(x502_module, "X502_GetDevInfo2");
|
||||||
|
if ((GetDevInfo == nullptr) && (GetDevInfo2 == nullptr)) {
|
||||||
|
fail("Neither X502_GetDevInfo2 nor X502_GetDevInfo is available in x502 API library");
|
||||||
|
}
|
||||||
SetMode = load_symbol<decltype(SetMode)>(x502_module, "X502_SetMode");
|
SetMode = load_symbol<decltype(SetMode)>(x502_module, "X502_SetMode");
|
||||||
StreamsStop = load_symbol<decltype(StreamsStop)>(x502_module, "X502_StreamsStop");
|
StreamsStop = load_symbol<decltype(StreamsStop)>(x502_module, "X502_StreamsStop");
|
||||||
StreamsDisable = load_symbol<decltype(StreamsDisable)>(x502_module, "X502_StreamsDisable");
|
StreamsDisable = load_symbol<decltype(StreamsDisable)>(x502_module, "X502_StreamsDisable");
|
||||||
@ -669,7 +692,11 @@ int run(const Config& cfg) {
|
|||||||
device.opened = true;
|
device.opened = true;
|
||||||
|
|
||||||
t_x502_info info{};
|
t_x502_info info{};
|
||||||
|
if (api.GetDevInfo2 != nullptr) {
|
||||||
err = api.GetDevInfo2(device.hnd, &info, sizeof(info));
|
err = api.GetDevInfo2(device.hnd, &info, sizeof(info));
|
||||||
|
} else {
|
||||||
|
err = api.GetDevInfo(device.hnd, &info);
|
||||||
|
}
|
||||||
expect_ok(api, err, "Get device info");
|
expect_ok(api, err, "Get device info");
|
||||||
print_device_info(info);
|
print_device_info(info);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user