WIP
This commit is contained in:
+60
-51
@@ -10,6 +10,8 @@
|
||||
#include <math.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#define getControllerMethod pController
|
||||
|
||||
struct sinqAxisImpl {
|
||||
// Internal variables used in the movement timeout watchdog
|
||||
time_t expectedArrivalTime;
|
||||
@@ -29,9 +31,9 @@ struct sinqAxisImpl {
|
||||
};
|
||||
|
||||
// Generic fallback - if the compiler tries to compile this function, it fails.
|
||||
template <typename T>
|
||||
asynStatus setAxisParam(sinqAxis *axis, const char *indexName,
|
||||
int (sinqController::*func)(), T writeValue,
|
||||
template <typename A, typename C, typename T>
|
||||
asynStatus setAxisParam(A *axis, C *controller, const char *indexName,
|
||||
int (C::*func)(), T writeValue,
|
||||
const char *callerFunctionName, int lineNumber) {
|
||||
static_assert(
|
||||
sizeof(T) == 0,
|
||||
@@ -39,10 +41,11 @@ asynStatus setAxisParam(sinqAxis *axis, const char *indexName,
|
||||
return asynError;
|
||||
}
|
||||
|
||||
template <>
|
||||
asynStatus setAxisParam<int>(sinqAxis *axis, const char *indexName,
|
||||
int (sinqController::*func)(), int writeValue,
|
||||
const char *callerFunctionName, int lineNumber) {
|
||||
template <typename A, typename C, typename T,
|
||||
std::enable_if_t<std::is_same<T, int>::value, int> = 0>
|
||||
asynStatus setAxisParam(A *axis, C *controller, const char *indexName,
|
||||
int (C::*func)(), T writeValue,
|
||||
const char *callerFunctionName, int lineNumber) {
|
||||
int indexValue = (axis->pController()->*func)();
|
||||
asynStatus status = axis->setIntegerParam(indexValue, writeValue);
|
||||
if (status != asynSuccess) {
|
||||
@@ -52,19 +55,20 @@ asynStatus setAxisParam<int>(sinqAxis *axis, const char *indexName,
|
||||
return asynSuccess;
|
||||
}
|
||||
|
||||
template <>
|
||||
asynStatus setAxisParam<bool>(sinqAxis *axis, const char *indexName,
|
||||
int (sinqController::*func)(), bool writeValue,
|
||||
const char *callerFunctionName, int lineNumber) {
|
||||
template <typename A, typename C, typename T,
|
||||
std::enable_if_t<std::is_same<T, bool>::value, bool> = 0>
|
||||
asynStatus setAxisParam(A *axis, C *controller, const char *indexName,
|
||||
int (C::*func)(), T writeValue,
|
||||
const char *callerFunctionName, int lineNumber) {
|
||||
return setAxisParam(axis, indexName, func, static_cast<int>(writeValue),
|
||||
callerFunctionName, lineNumber);
|
||||
}
|
||||
|
||||
template <>
|
||||
asynStatus
|
||||
setAxisParam<double>(sinqAxis *axis, const char *indexName,
|
||||
int (sinqController::*func)(), double writeValue,
|
||||
const char *callerFunctionName, int lineNumber) {
|
||||
template <typename A, typename C, typename T,
|
||||
std::enable_if_t<std::is_same<T, double>::value, double> = 0>
|
||||
asynStatus setAxisParam(A *axis, C *controller, const char *indexName,
|
||||
int (sinqController::*func)(), T writeValue,
|
||||
const char *callerFunctionName, int lineNumber) {
|
||||
int indexValue = (axis->pController()->*func)();
|
||||
asynStatus status = axis->setDoubleParam(indexValue, writeValue);
|
||||
if (status != asynSuccess) {
|
||||
@@ -74,11 +78,11 @@ setAxisParam<double>(sinqAxis *axis, const char *indexName,
|
||||
return asynSuccess;
|
||||
}
|
||||
|
||||
template <>
|
||||
asynStatus setAxisParam<char *>(sinqAxis *axis, const char *indexName,
|
||||
int (sinqController::*func)(), char *writeValue,
|
||||
const char *callerFunctionName,
|
||||
int lineNumber) {
|
||||
template <typename A, typename C, typename T,
|
||||
std::enable_if_t<std::is_same<T, char *>::value, char *> = 0>
|
||||
asynStatus setAxisParam(A *axis, C *controller, const char *indexName,
|
||||
int (C::*func)(), T writeValue,
|
||||
const char *callerFunctionName, int lineNumber) {
|
||||
int indexValue = (axis->pController()->*func)();
|
||||
asynStatus status = axis->setStringParam(indexValue, writeValue);
|
||||
if (status != asynSuccess) {
|
||||
@@ -88,12 +92,12 @@ asynStatus setAxisParam<char *>(sinqAxis *axis, const char *indexName,
|
||||
return asynSuccess;
|
||||
}
|
||||
|
||||
template <>
|
||||
asynStatus setAxisParam<const char *>(sinqAxis *axis, const char *indexName,
|
||||
int (sinqController::*func)(),
|
||||
const char *writeValue,
|
||||
const char *callerFunctionName,
|
||||
int lineNumber) {
|
||||
template <
|
||||
typename A, typename C, typename T,
|
||||
std::enable_if_t<std::is_same<T, const char *>::value, const char *> = 0>
|
||||
asynStatus setAxisParam(A *axis, C *controller, const char *indexName,
|
||||
int (C::*func)(), T writeValue,
|
||||
const char *callerFunctionName, int lineNumber) {
|
||||
int indexValue = (axis->pController()->*func)();
|
||||
asynStatus status = axis->setStringParam(indexValue, writeValue);
|
||||
if (status != asynSuccess) {
|
||||
@@ -104,9 +108,9 @@ asynStatus setAxisParam<const char *>(sinqAxis *axis, const char *indexName,
|
||||
}
|
||||
|
||||
// Generic fallback - if the compiler tries to compile this function, it fails.
|
||||
template <typename T>
|
||||
asynStatus getAxisParam(sinqAxis *axis, const char *indexName,
|
||||
int (sinqController::*func)(), T *readValue,
|
||||
template <typename A, typename C, typename T>
|
||||
asynStatus getAxisParam(A *axis, C *controller, const char *indexName,
|
||||
int (C::*func)(), T *readValue,
|
||||
const char *callerFunctionName, int lineNumber) {
|
||||
static_assert(
|
||||
sizeof(T) == 0,
|
||||
@@ -114,9 +118,10 @@ asynStatus getAxisParam(sinqAxis *axis, const char *indexName,
|
||||
return asynError;
|
||||
}
|
||||
|
||||
template <>
|
||||
asynStatus getAxisParam<int>(sinqAxis *axis, const char *indexName,
|
||||
int (sinqController::*func)(), int *readValue,
|
||||
template <typename A, typename C, typename T,
|
||||
std::enable_if_t<std::is_same<T, int>::value, int> = 0>
|
||||
asynStatus getAxisParam<int>(A *axis, C *controller, const char *indexName,
|
||||
int (C::*func)(), T *readValue,
|
||||
const char *callerFunctionName, int lineNumber) {
|
||||
int indexValue = (axis->pController()->*func)();
|
||||
asynStatus status = axis->pController()->getIntegerParam(
|
||||
@@ -128,19 +133,21 @@ asynStatus getAxisParam<int>(sinqAxis *axis, const char *indexName,
|
||||
return asynSuccess;
|
||||
}
|
||||
|
||||
template <>
|
||||
asynStatus getAxisParam<bool>(sinqAxis *axis, const char *indexName,
|
||||
int (sinqController::*func)(), bool *readValue,
|
||||
template <typename A, typename C, typename T,
|
||||
std::enable_if_t<std::is_same<T, bool>::value, bool> = 0>
|
||||
asynStatus getAxisParam<bool>(A *axis, C *controller, const char *indexName,
|
||||
int (C::*func)(), T *readValue,
|
||||
const char *callerFunctionName, int lineNumber) {
|
||||
return getAxisParam(axis, indexName, func, (int *)readValue,
|
||||
callerFunctionName, lineNumber);
|
||||
}
|
||||
|
||||
template <>
|
||||
asynStatus
|
||||
getAxisParam<double>(sinqAxis *axis, const char *indexName,
|
||||
int (sinqController::*func)(), double *readValue,
|
||||
const char *callerFunctionName, int lineNumber) {
|
||||
template <typename A, typename C, typename T,
|
||||
std::enable_if_t<std::is_same<T, double>::value, double> = 0>
|
||||
asynStatus getAxisParam<double>(A *axis, C *controller, const char *indexName,
|
||||
int (C::*func)(), T *readValue,
|
||||
const char *callerFunctionName,
|
||||
int lineNumber) {
|
||||
int indexValue = (axis->pController()->*func)();
|
||||
asynStatus status = axis->pController()->getDoubleParam(
|
||||
axis->axisNo(), indexValue, readValue);
|
||||
@@ -151,9 +158,10 @@ getAxisParam<double>(sinqAxis *axis, const char *indexName,
|
||||
return asynSuccess;
|
||||
}
|
||||
|
||||
template <>
|
||||
asynStatus getAxisParam<char>(sinqAxis *axis, const char *indexName,
|
||||
int (sinqController::*func)(), char *readValue,
|
||||
template <typename A, typename C, typename T,
|
||||
std::enable_if_t<std::is_same<T, char>::value, char> = 0>
|
||||
asynStatus getAxisParam<char>(A *axis, C *controller, const char *indexName,
|
||||
int (C::*func)(), T *readValue,
|
||||
const char *callerFunctionName, int lineNumber) {
|
||||
|
||||
int maxChars = 200;
|
||||
@@ -168,20 +176,21 @@ asynStatus getAxisParam<char>(sinqAxis *axis, const char *indexName,
|
||||
return asynSuccess;
|
||||
}
|
||||
|
||||
template <size_t N>
|
||||
asynStatus getAxisParam(sinqAxis *axis, const char *indexName,
|
||||
int (sinqController::*func)(), char (&readValue)[N],
|
||||
template <typename A, typename C, typename T,
|
||||
std::enable_if_t<std::is_same<T, char>::value, char> = 0, size_t N>
|
||||
asynStatus getAxisParam(A *axis, C *controller, const char *indexName,
|
||||
int (C::*func)(), T (&readValue)[N],
|
||||
const char *callerFunctionName, int lineNumber) {
|
||||
// Decay the array to char*
|
||||
return getAxisParam<char>(axis, indexName, func,
|
||||
return getAxisParam<char>(axis, controller, indexName, func,
|
||||
static_cast<char *>(readValue),
|
||||
callerFunctionName, lineNumber);
|
||||
}
|
||||
|
||||
template <>
|
||||
template <typename A, typename C>
|
||||
asynStatus
|
||||
getAxisParam<std::string>(sinqAxis *axis, const char *indexName,
|
||||
int (sinqController::*func)(), std::string *readValue,
|
||||
getAxisParam<std::string>(A *axis, C *controller, const char *indexName,
|
||||
int (C::*func)(), std::string *readValue,
|
||||
const char *callerFunctionName, int lineNumber) {
|
||||
int indexValue = (axis->pController()->*func)();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user