SenseApiLib, SenseApiDesc improvements, new Sense API Mgmt Lib Ops role
SenseApiDesc: * Use a number count for num exported implexor APIs instead of NULL-terminated list. * Add sanity checker functions for structs. SenseApiLib: * Invoke the new sanity checkers on new Lib objects. * SenseApiDesc is now a member object instead of being pointed to. SenseApiManager: * loadSenseApiLib now calls the SenseApiDesc getter function. * loadSenseApiLib now fills out the SenseApiLib class object. New Sense API Mgmt Sub-API: This sub-api (metalanguage, some might call it) is used to initialize the lib's connection to the provider. After this call, the lib should be ready to attach new devices to its provider on behalf of Hk.
This commit is contained in:
@@ -20,18 +20,35 @@ public:
|
||||
class ExportedImplexorApiDesc
|
||||
{
|
||||
public:
|
||||
ExportedImplexorApiDesc(const CExportedImplexorApiDesc& cDesc)
|
||||
// The caller should sanity check before calling this constructor.
|
||||
: name(cDesc.name)
|
||||
{}
|
||||
|
||||
const std::string name;
|
||||
};
|
||||
|
||||
public:
|
||||
SenseApiDesc() = default;
|
||||
SenseApiDesc(const CSenseApiDesc& cDesc)
|
||||
: cDescriptor(cDesc), name(cDesc.name)
|
||||
{}
|
||||
// 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]));
|
||||
}
|
||||
}
|
||||
|
||||
std::reference_wrapper<const CSenseApiDesc> cDescriptor;
|
||||
std::string name;
|
||||
// These options affect the sense api lib's behaviour globally.
|
||||
std::vector<std::string> options;
|
||||
// These are the implexors whose APIs this lib exports.
|
||||
std::vector<ExportedImplexorApiDesc> exportedImplexorApis;
|
||||
};
|
||||
@@ -39,14 +56,44 @@ public:
|
||||
class SenseApiLib
|
||||
{
|
||||
public:
|
||||
SenseApiLib(const std::string& path)
|
||||
SenseApiLib(
|
||||
const std::string& path, void *_dlopen_handle, getSenseApiDescFn *descFn)
|
||||
: libraryPath(path),
|
||||
handle(nullptr, reinterpret_cast<void(*)(void*)>(&dlclose))
|
||||
dlopen_handle(
|
||||
_dlopen_handle, reinterpret_cast<void(*)(void*)>(&dlclose)),
|
||||
HK_GET_SENSE_API_DESC_FN_NAME(descFn)
|
||||
{}
|
||||
|
||||
void setSenseApiDesc(const CSenseApiDesc* desc)
|
||||
{
|
||||
if (!CSenseApiDesc_sanityCheck(desc) ||
|
||||
!Csal_libMgmtOps_sanityCheck(desc->sal_libMgmtOps))
|
||||
{
|
||||
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
|
||||
}
|
||||
|
||||
public:
|
||||
std::string libraryPath;
|
||||
std::unique_ptr<void, void(*)(void*)> handle;
|
||||
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;
|
||||
|
||||
/**
|
||||
* @brief Every sense API lib is required to provide a function that returns
|
||||
@@ -56,13 +103,14 @@ public:
|
||||
* This getter function should be visible to dlsym() so that Harikoff can
|
||||
* find it in the lib after loading it, and call it.
|
||||
*/
|
||||
std::function<getSenseApiDescFn> getSenseApiDescriptor;
|
||||
std::function<getSenseApiDescFn> HK_GET_SENSE_API_DESC_FN_NAME;
|
||||
|
||||
/**
|
||||
* @brief Harikoff will call the `getSenseApiDescriptor` getter function and
|
||||
* use the data it provides in order to fill out this descriptor.
|
||||
* @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.
|
||||
*/
|
||||
std::unique_ptr<SenseApiDesc> apiDescriptor;
|
||||
SenseApiDesc senseApiDesc;
|
||||
};
|
||||
|
||||
} // namespace sense_api
|
||||
|
||||
Reference in New Issue
Block a user