115 lines
3.5 KiB
C++
115 lines
3.5 KiB
C++
#ifndef __USER_SENSE_API_LIB_H__
|
|
#define __USER_SENSE_API_LIB_H__
|
|
|
|
#include <preprocessor.h>
|
|
#include <stdbool.h>
|
|
#include <user/senseDeviceSpec.h>
|
|
|
|
namespace smo {
|
|
namespace sense_api {
|
|
|
|
typedef int (sal_mlo_initializeIndFn)(void);
|
|
typedef int (sal_mlo_finalizeIndFn)(void);
|
|
typedef int (sal_mlo_attachDeviceReqFn)(const device::SenseDeviceSpec &desc);
|
|
typedef int (sal_mlo_detachDeviceReqFn)(const device::SenseDeviceSpec &desc);
|
|
|
|
struct Sal_Mgmt_LibOps
|
|
{
|
|
/* When Salmanoff loads a sense API lib, it calls this function to initialize
|
|
* the lib. When this returns, the lib should be ready to attach devices.
|
|
*/
|
|
sal_mlo_initializeIndFn *initializeInd;
|
|
/* Salmanoff calls this to finalize the lib and free its internal
|
|
* resources. When this returns, the lib should be ready to be unloaded.
|
|
*/
|
|
sal_mlo_finalizeIndFn *finalizeInd;
|
|
/* Salmanoff calls this to attach a device to the lib. When it returns, the
|
|
* device should be attached and ready to be implexed.
|
|
*/
|
|
sal_mlo_attachDeviceReqFn *attachDeviceReq;
|
|
// When this returns, the device should be detached.
|
|
sal_mlo_detachDeviceReqFn *detachDeviceReq;
|
|
|
|
static bool sanityCheck(const Sal_Mgmt_LibOps &ops)
|
|
{
|
|
if (!ops.initializeInd || !ops.finalizeInd
|
|
|| !ops.attachDeviceReq || !ops.detachDeviceReq)
|
|
{
|
|
return false;
|
|
}
|
|
|
|
return true;
|
|
}
|
|
};
|
|
|
|
/* Exported by all sense API Libraries to tell Salmanoff what API the lib uses
|
|
* to connect to providers; and also to state which implexor APIs it exports.
|
|
*/
|
|
class SenseApiDesc
|
|
{
|
|
public:
|
|
class ExportedImplexorApiDesc
|
|
{
|
|
public:
|
|
static bool sanityCheck(const ExportedImplexorApiDesc &desc)
|
|
{
|
|
if (desc.name.empty()) { return false; }
|
|
return true;
|
|
}
|
|
|
|
public:
|
|
std::string name;
|
|
};
|
|
|
|
public:
|
|
std::string stringify() const
|
|
{
|
|
std::string result = "Name: " + name + "\n";
|
|
result += "Exported Implexor APIs:\n";
|
|
for (const auto& api : exportedImplexorApis) {
|
|
result += " - " + api.name + "\n";
|
|
}
|
|
return result;
|
|
}
|
|
|
|
static bool sanityCheck(const SenseApiDesc &desc)
|
|
{
|
|
if (desc.name.empty() || desc.exportedImplexorApis.empty()) {
|
|
return false;
|
|
}
|
|
|
|
for (const auto& api : desc.exportedImplexorApis) {
|
|
if (!ExportedImplexorApiDesc::sanityCheck(api)) { return false; }
|
|
}
|
|
|
|
return Sal_Mgmt_LibOps::sanityCheck(desc.sal_mgmt_libOps);
|
|
}
|
|
|
|
std::string name;
|
|
// These are the implexors whose APIs this lib exports.
|
|
std::vector<ExportedImplexorApiDesc> exportedImplexorApis;
|
|
Sal_Mgmt_LibOps sal_mgmt_libOps;
|
|
};
|
|
|
|
|
|
#define SMO_GET_SENSE_API_DESC_FN_NAME getSenseApiDesc
|
|
#define SMO_GET_SENSE_API_DESC_FN_NAME_STR \
|
|
SMO_QUOTE(SMO_GET_SENSE_API_DESC_FN_NAME)
|
|
#define SMO_GET_SENSE_API_DESC_FN_TYPEDEF \
|
|
SMO_CONCAT(SMO_GET_SENSE_API_DESC_FN_NAME, Fn)
|
|
|
|
/* Every Sense API library must define a global instance of this
|
|
* function. Salmanoff will search for it and invoke it via dlsym().
|
|
*
|
|
* The function must return a SenseApiDesc struct that Smo will tell
|
|
* Smo what implexors can be used with it & what APIs it exports.
|
|
* The SenseApiDesc struct also gives Smo pointers to API functions
|
|
* to invoke for communication between Smo and the library.
|
|
*/
|
|
typedef const SenseApiDesc &(SMO_GET_SENSE_API_DESC_FN_TYPEDEF)(void);
|
|
|
|
} // namespace sense_api
|
|
} // namespace smo
|
|
|
|
#endif // __USER_SENSE_API_LIB_H__
|