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
|
// Copyright (c) 2014-2018 Josh Blum
// SPDX-License-Identifier: BSL-1.0
#include "ErrorHelpers.hpp"
#include "TypeHelpers.hpp"
#include <SoapySDR/Device.h>
#include <SoapySDR/Device.hpp>
#include <cstdlib>
#include <cstring>
extern "C" {
SoapySDRKwargs *SoapySDRDevice_enumerate(const SoapySDRKwargs *args, size_t *length)
{
*length = 0;
__SOAPY_SDR_C_TRY
return toKwargsList(SoapySDR::Device::enumerate(toKwargs(args)), length);
__SOAPY_SDR_C_CATCH_RET(nullptr);
}
SoapySDRKwargs *SoapySDRDevice_enumerateStrArgs(const char *args, size_t *length)
{
*length = 0;
__SOAPY_SDR_C_TRY
return toKwargsList(SoapySDR::Device::enumerate(args), length);
__SOAPY_SDR_C_CATCH_RET(nullptr);
}
SoapySDRDevice *SoapySDRDevice_make(const SoapySDRKwargs *args)
{
__SOAPY_SDR_C_TRY
return (SoapySDRDevice *)SoapySDR::Device::make(toKwargs(args));
__SOAPY_SDR_C_CATCH_RET(nullptr);
}
SoapySDRDevice *SoapySDRDevice_makeStrArgs(const char *args)
{
__SOAPY_SDR_C_TRY
return (SoapySDRDevice *)SoapySDR::Device::make((args==nullptr)?"":args);
__SOAPY_SDR_C_CATCH_RET(nullptr);
}
int SoapySDRDevice_unmake(SoapySDRDevice *device)
{
__SOAPY_SDR_C_TRY
SoapySDR::Device::unmake((SoapySDR::Device *)device);
__SOAPY_SDR_C_CATCH
}
/*******************************************************************
* Parallel support
******************************************************************/
SoapySDRDevice **SoapySDRDevice_make_list(const SoapySDRKwargs *argsList, const size_t length)
{
__SOAPY_SDR_C_TRY
auto outDevices = callocArrayType<SoapySDRDevice *>(length);
const auto devices = SoapySDR::Device::make(toKwargsList(argsList, length));
for (size_t i = 0; i < length; i++) outDevices[i] = (SoapySDRDevice *)devices[i];
return outDevices;
__SOAPY_SDR_C_CATCH_RET(nullptr);
}
SoapySDRDevice **SoapySDRDevice_make_listStrArgs(const char* const *argsList, const size_t length)
{
__SOAPY_SDR_C_TRY
auto outDevices = callocArrayType<SoapySDRDevice *>(length);
const auto devices = SoapySDR::Device::make(toStringVector(argsList, length));
for (size_t i = 0; i < length; i++) outDevices[i] = (SoapySDRDevice *)devices[i];
return outDevices;
__SOAPY_SDR_C_CATCH_RET(nullptr);
}
int SoapySDRDevice_unmake_list(SoapySDRDevice **devices, const size_t length)
{
__SOAPY_SDR_C_TRY
std::vector<SoapySDR::Device *> devicesVector(length);
for (size_t i = 0; i < length; i++) devicesVector[i] = (SoapySDR::Device *)devices[i];
SoapySDR_free(devices);
SoapySDR::Device::unmake(devicesVector);
__SOAPY_SDR_C_CATCH
}
}
|