87 lines
2.1 KiB
C++
87 lines
2.1 KiB
C++
#ifndef mEpicsCa_H
|
|
#define mEpicsCa_H
|
|
|
|
#include "cadef.h"
|
|
#include <optional>
|
|
#include <string>
|
|
|
|
/**
|
|
* @brief Information about the channel type (integer, double, string, ...)
|
|
*/
|
|
struct ChInfo {
|
|
// Channel type (like e.g. DBF_INT, DBF_DOUBLE, DBF_STRING etc.)
|
|
short type;
|
|
// Number of elements. Is 1 for most record types except for waveforms,
|
|
// whose length is defined in the record.
|
|
int count;
|
|
};
|
|
|
|
template <typename T> class mEpicsCa {
|
|
public:
|
|
/**
|
|
* @brief Construct a new m Epics Ca object
|
|
*
|
|
* @param pChanName
|
|
* @param pConnStateCallback
|
|
* @param pUserPrivate
|
|
* @param priority
|
|
* @param pChanID
|
|
*/
|
|
mEpicsCa(const char *pChanName, bool subscribe, caCh *pConnStateCallback,
|
|
void *pUserPrivate, double timeout = 2.0);
|
|
|
|
mEpicsCa(const char *pChanName, bool subscribe);
|
|
|
|
~mEpicsCa();
|
|
|
|
template <typename V> int get(V *value);
|
|
int get(char *buf, u_long len);
|
|
|
|
template <typename V> int put(V *value);
|
|
int put(const char *buf, u_long len);
|
|
|
|
bool connected();
|
|
|
|
double _timeout;
|
|
|
|
const std::optional<T> &cached() const;
|
|
|
|
private:
|
|
/**
|
|
* @brief A callback for reacting to channel access channel state changes.
|
|
* Overwritten by `*pConnStateCallback` if one is provided in the
|
|
* constructor.
|
|
*
|
|
* This default callback just announces the connection state change.
|
|
*
|
|
* @param args
|
|
* @param pMEpicsCa
|
|
*/
|
|
static void connStateCallback(struct connection_handler_args args);
|
|
|
|
static void eventCallback(struct event_handler_args args);
|
|
|
|
int getRaw(char *buf, size_t len);
|
|
int getRaw(int *value);
|
|
int getRaw(double *value);
|
|
int getRaw(uint16_t *value);
|
|
|
|
int putRaw(const char *buf, size_t len);
|
|
int putRaw(int *value);
|
|
int putRaw(double *value);
|
|
int putRaw(uint16_t *value);
|
|
|
|
std::optional<ChInfo> _channelInfo;
|
|
chid _pChanID;
|
|
std::string _chanName;
|
|
|
|
/*
|
|
In case the subscription mechanism is used, this variable holds the last
|
|
value returned by the callback.
|
|
*/
|
|
std::optional<T> _cached;
|
|
};
|
|
|
|
#include "m_epics_ca.tpp"
|
|
|
|
#endif |