2025-01-08 11:49:28 -04:00
|
|
|
#ifndef SENSE_API_PROVIDER_DESC_H
|
|
|
|
|
#define SENSE_API_PROVIDER_DESC_H
|
|
|
|
|
|
|
|
|
|
#include <string>
|
|
|
|
|
#include <memory>
|
|
|
|
|
#include <vector>
|
|
|
|
|
#include <dlfcn.h>
|
|
|
|
|
#include <functional>
|
|
|
|
|
#include <user/senseApiDesc.h>
|
|
|
|
|
|
|
|
|
|
namespace hk {
|
|
|
|
|
namespace sense_api {
|
|
|
|
|
|
2025-01-08 11:50:16 -04:00
|
|
|
/* C++ version of the C struct above, which Harikoff uses to manage the
|
2025-01-08 11:49:28 -04:00
|
|
|
* lib and connect implexors to it.
|
|
|
|
|
*/
|
|
|
|
|
class SenseApiDesc
|
|
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
class ExportedImplexorApiDesc
|
|
|
|
|
{
|
|
|
|
|
public:
|
2025-01-09 06:03:43 -04:00
|
|
|
ExportedImplexorApiDesc(const CExportedImplexorApiDesc& cDesc)
|
|
|
|
|
// The caller should sanity check before calling this constructor.
|
|
|
|
|
: name(cDesc.name)
|
|
|
|
|
{}
|
|
|
|
|
|
2025-01-08 11:49:28 -04:00
|
|
|
const std::string name;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
public:
|
2025-01-09 06:03:43 -04:00
|
|
|
SenseApiDesc() = default;
|
2025-01-08 11:49:28 -04:00
|
|
|
SenseApiDesc(const CSenseApiDesc& cDesc)
|
2025-01-09 06:03:43 -04:00
|
|
|
// The caller should sanity check before calling this constructor.
|
|
|
|
|
: name(cDesc.name)
|
|
|
|
|
{
|
|
|
|
|
for (uint32_t i = 0; i < cDesc.numExportedImplexorApis; ++i)
|
|
|
|
|
{
|
|
|
|
|
if (!CExportedImplexorApiDesc_sanityCheck(
|
|
|
|
|
&cDesc.exportedImplexorApis[i]))
|
|
|
|
|
{
|
|
|
|
|
throw std::runtime_error(
|
|
|
|
|
"Sanity check failed for exported implexor API descriptor");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
exportedImplexorApis.push_back(
|
|
|
|
|
ExportedImplexorApiDesc(cDesc.exportedImplexorApis[i]));
|
|
|
|
|
}
|
|
|
|
|
}
|
2025-01-08 11:49:28 -04:00
|
|
|
|
|
|
|
|
std::string name;
|
|
|
|
|
// These are the implexors whose APIs this lib exports.
|
|
|
|
|
std::vector<ExportedImplexorApiDesc> exportedImplexorApis;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
class SenseApiLib
|
|
|
|
|
{
|
|
|
|
|
public:
|
2025-01-09 06:03:43 -04:00
|
|
|
SenseApiLib(
|
|
|
|
|
const std::string& path, void *_dlopen_handle, getSenseApiDescFn *descFn)
|
2025-01-08 17:16:49 -04:00
|
|
|
: libraryPath(path),
|
2025-01-09 06:03:43 -04:00
|
|
|
dlopen_handle(
|
|
|
|
|
_dlopen_handle, reinterpret_cast<void(*)(void*)>(&dlclose)),
|
|
|
|
|
HK_GET_SENSE_API_DESC_FN_NAME(descFn)
|
2025-01-08 11:49:28 -04:00
|
|
|
{}
|
|
|
|
|
|
2025-01-09 06:03:43 -04:00
|
|
|
void setSenseApiDesc(const CSenseApiDesc* desc)
|
|
|
|
|
{
|
|
|
|
|
if (!CSenseApiDesc_sanityCheck(desc) ||
|
2025-01-09 17:18:24 -04:00
|
|
|
!Csal_mgmt_libOps_sanityCheck(desc->sal_mgmt_libOps))
|
2025-01-09 06:03:43 -04:00
|
|
|
{
|
|
|
|
|
throw std::runtime_error(
|
|
|
|
|
std::string(__func__) + ": Sanity check failed for sense API "
|
|
|
|
|
"descriptor in library '" + libraryPath + "'");
|
|
|
|
|
}
|
|
|
|
|
for (uint32_t i = 0; i < desc->numExportedImplexorApis; ++i)
|
|
|
|
|
{
|
|
|
|
|
if (!CExportedImplexorApiDesc_sanityCheck(
|
|
|
|
|
&desc->exportedImplexorApis[i]))
|
|
|
|
|
{
|
|
|
|
|
throw std::runtime_error(
|
|
|
|
|
std::string(__func__) + ": Sanity check failed for "
|
|
|
|
|
"exported implexor API descriptor in library '"
|
|
|
|
|
+ libraryPath + "'");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
new (&senseApiDesc) SenseApiDesc(*desc); // Placement new
|
|
|
|
|
}
|
|
|
|
|
|
2025-01-08 11:49:28 -04:00
|
|
|
public:
|
|
|
|
|
std::string libraryPath;
|
2025-01-09 06:03:43 -04:00
|
|
|
std::unique_ptr<void, void(*)(void*)> dlopen_handle;
|
|
|
|
|
/* UNIMPLEMENTED: API-specific cmdline options. These affect this specific
|
|
|
|
|
* sense api lib's behaviour globally.
|
|
|
|
|
*/
|
|
|
|
|
std::vector<std::string> options;
|
2025-01-08 11:49:28 -04:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @brief Every sense API lib is required to provide a function that returns
|
|
|
|
|
* a CSenseApiDesc struct. This struct states which API the lib uses to
|
|
|
|
|
* connect Harikoff to the sense provider it supports.
|
|
|
|
|
*
|
|
|
|
|
* This getter function should be visible to dlsym() so that Harikoff can
|
|
|
|
|
* find it in the lib after loading it, and call it.
|
|
|
|
|
*/
|
2025-01-09 06:03:43 -04:00
|
|
|
std::function<getSenseApiDescFn> HK_GET_SENSE_API_DESC_FN_NAME;
|
2025-01-08 11:49:28 -04:00
|
|
|
|
|
|
|
|
/**
|
2025-01-09 06:03:43 -04:00
|
|
|
* @brief Harikoff will call the `HK_GET_SENSE_API_DESC_FN_NAME` getter
|
|
|
|
|
* function and use the data it provides in order to fill out this
|
|
|
|
|
* descriptor.
|
2025-01-08 11:49:28 -04:00
|
|
|
*/
|
2025-01-09 06:03:43 -04:00
|
|
|
SenseApiDesc senseApiDesc;
|
2025-01-08 11:49:28 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
} // namespace sense_api
|
|
|
|
|
} // namespace hk
|
|
|
|
|
|
|
|
|
|
#endif // SENSE_API_PROVIDER_DESC_H
|