bffa2b837c
* OptionsParser now has a singleton.
* We now use the cmdline opt -p <senseApiLibPath>, and search for
the specified library in:
* senseApiLibPath, then CWD, then the place where our executable
is running from, and then finally we let the hosting OS do
its own search.
* We now call dlsym() on dlopen()'d libs to to get the senseApiDescFn
pointer.
74 lines
1.9 KiB
C++
74 lines
1.9 KiB
C++
#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 {
|
|
|
|
/* C++ version of the C struct above, which Harikoff uses to manage the
|
|
* lib and connect implexors to it.
|
|
*/
|
|
class SenseApiDesc
|
|
{
|
|
public:
|
|
class ExportedImplexorApiDesc
|
|
{
|
|
public:
|
|
const std::string name;
|
|
};
|
|
|
|
public:
|
|
SenseApiDesc(const CSenseApiDesc& cDesc)
|
|
: cDescriptor(cDesc), name(cDesc.name)
|
|
{}
|
|
|
|
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;
|
|
};
|
|
|
|
class SenseApiLib
|
|
{
|
|
public:
|
|
typedef const CSenseApiDesc* (SenseApiDescGetterFn)(void);
|
|
|
|
public:
|
|
SenseApiLib(const std::string& path)
|
|
: libraryPath(path), handle(nullptr, &dlclose)
|
|
{}
|
|
|
|
public:
|
|
std::string libraryPath;
|
|
std::unique_ptr<void, decltype(&dlclose)> handle;
|
|
|
|
/**
|
|
* @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.
|
|
*/
|
|
std::function<SenseApiDescGetterFn> getSenseApiDescriptor;
|
|
|
|
/**
|
|
* @brief Harikoff will call the `getSenseApiDescriptor` getter function and
|
|
* use the data it provides in order to fill out this descriptor.
|
|
*/
|
|
std::unique_ptr<SenseApiDesc> apiDescriptor;
|
|
};
|
|
|
|
} // namespace sense_api
|
|
} // namespace hk
|
|
|
|
#endif // SENSE_API_PROVIDER_DESC_H
|