asyn 4-28
/home/epics/devel/asyn-R4-29/asyn/asynPortClient/asynPortClient.h
Go to the documentation of this file.
00001 #ifndef asynPortClient_H
00002 #define asynPortClient_H
00003 
00004 #include <stdexcept>
00005 #include <string>
00006 
00007 #include <epicsString.h>
00008 
00009 #include <asynDriver.h>
00010 #include <asynInt32.h>
00011 #include <asynInt32SyncIO.h>
00012 #include <asynUInt32Digital.h>
00013 #include <asynUInt32DigitalSyncIO.h>
00014 #include <asynFloat64.h>
00015 #include <asynFloat64SyncIO.h>
00016 #include <asynOctet.h>
00017 #include <asynOctetSyncIO.h>
00018 #include <asynInt8Array.h>
00019 #include <asynInt8ArraySyncIO.h>
00020 #include <asynInt16Array.h>
00021 #include <asynInt16ArraySyncIO.h>
00022 #include <asynInt32Array.h>
00023 #include <asynInt32ArraySyncIO.h>
00024 #include <asynFloat32Array.h>
00025 #include <asynFloat32ArraySyncIO.h>
00026 #include <asynFloat64Array.h>
00027 #include <asynFloat64ArraySyncIO.h>
00028 #include <asynGenericPointer.h>
00029 #include <asynGenericPointerSyncIO.h>
00030 #include <asynEnum.h>
00031 #include <asynEnumSyncIO.h>
00032 #include <asynOption.h>
00033 #include <asynOptionSyncIO.h>
00034 #include <asynCommonSyncIO.h>
00035 #include <asynDrvUser.h>
00036 
00037 #define DEFAULT_TIMEOUT 1.0
00038 
00039 
00042 class epicsShareClass asynPortClient {
00043 public:
00044     asynPortClient(const char *portName, int addr, const char* asynInterfaceType, const char *drvInfo, double timeout);
00045     virtual ~asynPortClient();
00046     void setTimeout(double timeout)
00047         { timeout_ = timeout; };
00048     void report(FILE *fp, int details);
00049 protected:
00050     asynUser *pasynUser_;
00051     asynUser *pasynUserSyncIO_;
00052     asynInterface *pasynInterface_;
00053     double timeout_;
00054     char *portName_;
00055     int addr_;
00056     char *asynInterfaceType_;
00057     char *drvInfo_;
00058     void *drvPvt;
00059     void *interruptPvt_;
00060 };
00061 
00062 
00064 class epicsShareClass asynInt32Client : public asynPortClient {
00065 public:
00072     asynInt32Client(const char *portName, int addr, const char *drvInfo, double timeout=DEFAULT_TIMEOUT)
00073     : asynPortClient(portName, addr, asynInt32Type, drvInfo, timeout) {
00074         pInterface_ = (asynInt32 *)pasynInterface_->pinterface;
00075         if (pasynInt32SyncIO->connect(portName, addr, &pasynUserSyncIO_, drvInfo)) 
00076             throw std::runtime_error(std::string("pasynInt32SyncIO->connect failed"));
00077     };
00079     virtual ~asynInt32Client() { 
00080         pasynInt32SyncIO->disconnect(pasynUserSyncIO_); 
00081     }; 
00084     virtual asynStatus read(epicsInt32 *value) { 
00085         return pasynInt32SyncIO->read(pasynUserSyncIO_, value, timeout_);
00086     };
00089     virtual asynStatus write(epicsInt32 value) { 
00090         return pasynInt32SyncIO->write(pasynUserSyncIO_, value, timeout_); 
00091     };
00095     virtual asynStatus getBounds(epicsInt32 *low, epicsInt32 *high) { 
00096         return pasynInt32SyncIO->getBounds(pasynUserSyncIO_, low, high); 
00097     };
00100     virtual asynStatus registerInterruptUser(interruptCallbackInt32 pCallback) { 
00101         return pInterface_->registerInterruptUser(pasynInterface_->drvPvt, pasynUser_,
00102                                                   pCallback, this, &interruptPvt_); 
00103     };
00104 private:
00105     asynInt32 *pInterface_;
00106 };
00107 
00108 
00110 class epicsShareClass asynUInt32DigitalClient : public asynPortClient {
00111 public:
00118     asynUInt32DigitalClient(const char *portName, int addr, const char *drvInfo, double timeout=DEFAULT_TIMEOUT)
00119     : asynPortClient(portName, addr, asynUInt32DigitalType, drvInfo, timeout) {
00120         pInterface_ = (asynUInt32Digital *)pasynInterface_->pinterface;
00121         if (pasynInt32SyncIO->connect(portName, addr, &pasynUserSyncIO_, drvInfo))
00122             throw std::runtime_error(std::string("pasynInt32SyncIO->connect failed"));
00123     };
00125     virtual ~asynUInt32DigitalClient() {
00126         pasynUInt32DigitalSyncIO->disconnect(pasynUserSyncIO_); 
00127     }; 
00131     virtual asynStatus read(epicsUInt32 *value, epicsUInt32 mask) { 
00132         return pasynUInt32DigitalSyncIO->read(pasynUserSyncIO_, value, mask, timeout_); 
00133     };
00137     virtual asynStatus write(epicsUInt32 value, epicsUInt32 mask){ 
00138         return pasynUInt32DigitalSyncIO->write(pasynUserSyncIO_, value, mask, timeout_); 
00139     };
00143     virtual asynStatus setInterrupt(epicsUInt32 mask, interruptReason reason) { 
00144         return pasynUInt32DigitalSyncIO->setInterrupt(pasynUserSyncIO_, mask, reason, timeout_); 
00145     };
00148     virtual asynStatus clearInterrupt(epicsUInt32 mask) { 
00149         return pasynUInt32DigitalSyncIO->clearInterrupt(pasynUserSyncIO_, mask, timeout_); 
00150     };
00154     virtual asynStatus getInterrupt(epicsUInt32 *mask, interruptReason reason) { 
00155         return pasynUInt32DigitalSyncIO->getInterrupt(pasynUserSyncIO_, mask, reason, timeout_); 
00156     };
00160     virtual asynStatus registerInterruptUser(interruptCallbackUInt32Digital pCallback, epicsUInt32 mask) { 
00161         return pInterface_->registerInterruptUser(pasynInterface_->drvPvt, pasynUser_,
00162                                                   pCallback, this, mask, &interruptPvt_); 
00163     };
00164 private:
00165     asynUInt32Digital *pInterface_;
00166 };
00167 
00168 
00170 class epicsShareClass asynFloat64Client : public asynPortClient {
00171 public:
00178     asynFloat64Client(const char *portName, int addr, const char *drvInfo, double timeout=DEFAULT_TIMEOUT)
00179     : asynPortClient(portName, addr, asynFloat64Type, drvInfo, timeout) {
00180         pInterface_ = (asynFloat64 *)pasynInterface_->pinterface;
00181         if (pasynFloat64SyncIO->connect(portName, addr, &pasynUserSyncIO_, drvInfo))
00182             throw std::runtime_error(std::string("pasynFloat64SyncIO->connect failed"));
00183     };
00185     virtual ~asynFloat64Client() { 
00186         pasynFloat64SyncIO->disconnect(pasynUserSyncIO_); 
00187     }; 
00190     virtual asynStatus read(epicsFloat64 *value) {
00191         return pasynFloat64SyncIO->read(pasynUserSyncIO_, value, timeout_); 
00192     };
00195     virtual asynStatus write(epicsFloat64 value) { 
00196         return pasynFloat64SyncIO->write(pasynUserSyncIO_, value, timeout_); 
00197     };
00200     virtual asynStatus registerInterruptUser(interruptCallbackFloat64 pCallback) { 
00201         return pInterface_->registerInterruptUser(pasynInterface_->drvPvt, pasynUser_,
00202                                                   pCallback, this, &interruptPvt_); 
00203     };
00204 private:
00205     asynFloat64 *pInterface_;
00206 };
00207 
00208 
00210 class epicsShareClass asynOctetClient : public asynPortClient {
00211 public:
00218     asynOctetClient(const char *portName, int addr, const char *drvInfo, double timeout=DEFAULT_TIMEOUT)
00219     : asynPortClient(portName, addr, asynOctetType, drvInfo, timeout) {
00220         pInterface_ = (asynOctet *)pasynInterface_->pinterface;
00221         if (pasynOctetSyncIO->connect(portName, addr, &pasynUserSyncIO_, drvInfo)) 
00222             throw std::runtime_error(std::string("pasynOctetSyncIO->connect failed"));
00223     };
00225     virtual ~asynOctetClient() { 
00226         pasynOctetSyncIO->disconnect(pasynUserSyncIO_); 
00227     }; 
00232     virtual asynStatus write(const char *buffer, size_t bufferLen, size_t *nActual) { 
00233         return pasynOctetSyncIO->write(pasynUserSyncIO_, buffer, bufferLen, timeout_, nActual); 
00234     };
00240     virtual asynStatus read(char *buffer, size_t bufferLen, size_t *nActual, int *eomReason) {
00241         return pasynOctetSyncIO->read(pasynUserSyncIO_, buffer, bufferLen, timeout_, nActual, eomReason); 
00242     };
00251     virtual asynStatus writeRead(const char *writeBuffer, size_t writeBufferLen, char *readBuffer, size_t readBufferLen, 
00252                                  size_t *nBytesOut, size_t *nBytesIn, int *eomReason) { 
00253         return pasynOctetSyncIO->writeRead(pasynUserSyncIO_, writeBuffer, writeBufferLen, readBuffer, readBufferLen,
00254                                            timeout_, nBytesOut, nBytesIn, eomReason); 
00255     };
00257     virtual asynStatus flush() { 
00258         return pasynOctetSyncIO->flush(pasynUserSyncIO_); 
00259     };
00263     virtual asynStatus setInputEos(const char *eos, int eosLen) { 
00264         return pasynOctetSyncIO->setInputEos(pasynUserSyncIO_, eos, eosLen); 
00265     };
00270     virtual asynStatus getInputEos(char *eos, int eosSize, int *eosLen) { 
00271         return pasynOctetSyncIO->getInputEos(pasynUserSyncIO_, eos, eosSize, eosLen); 
00272     };
00276     virtual asynStatus setOutputEos(const char *eos, int eosLen) { 
00277         return pasynOctetSyncIO->setOutputEos(pasynUserSyncIO_, eos, eosLen); 
00278     };
00283     virtual asynStatus getOutputEos(char *eos, int eosSize, int *eosLen) { 
00284         return pasynOctetSyncIO->getOutputEos(pasynUserSyncIO_, eos, eosSize, eosLen); 
00285     };
00288     virtual asynStatus registerInterruptUser(interruptCallbackOctet pCallback) { 
00289         return pInterface_->registerInterruptUser(pasynInterface_->drvPvt, pasynUser_,
00290                                                   pCallback, this, &interruptPvt_); 
00291     };
00292 private:
00293     asynOctet *pInterface_;
00294 };
00295   
00296 
00298 class epicsShareClass asynInt8ArrayClient : public asynPortClient {
00299 public:
00306     asynInt8ArrayClient(const char *portName, int addr, const char *drvInfo, double timeout=DEFAULT_TIMEOUT)
00307     : asynPortClient(portName, addr, asynInt8ArrayType, drvInfo, timeout) {
00308         pInterface_ = (asynInt8Array *)pasynInterface_->pinterface;
00309         if (pasynInt8ArraySyncIO->connect(portName, addr, &pasynUserSyncIO_, drvInfo)) 
00310             throw std::runtime_error(std::string("pasynInt8ArraySyncIO->connect failed"));
00311     };
00313     virtual ~asynInt8ArrayClient() {
00314         pasynInt8ArraySyncIO->disconnect(pasynUserSyncIO_);
00315     };
00320     virtual asynStatus read(epicsInt8 *value, size_t nElements, size_t *nIn) {
00321         return pasynInt8ArraySyncIO->read(pasynUserSyncIO_, value, nElements, nIn, timeout_);
00322     };
00326     virtual asynStatus write(epicsInt8 *value, size_t nElements) {
00327         return pasynInt8ArraySyncIO->write(pasynUserSyncIO_, value, nElements, timeout_);
00328     };
00331     virtual asynStatus registerInterruptUser(interruptCallbackInt8Array pCallback) { 
00332         return pInterface_->registerInterruptUser(pasynInterface_->drvPvt, pasynUser_,
00333                                                       pCallback, this, &interruptPvt_); 
00334     };
00335 private:
00336     asynInt8Array *pInterface_;
00337 };
00338 
00339 
00341 class epicsShareClass asynInt16ArrayClient : public asynPortClient {
00342 public:
00349     asynInt16ArrayClient(const char *portName, int addr, const char *drvInfo, double timeout=DEFAULT_TIMEOUT)
00350     : asynPortClient(portName, addr, asynInt16ArrayType, drvInfo, timeout) {
00351         pInterface_ = (asynInt16Array *)pasynInterface_->pinterface;
00352         if (pasynInt16ArraySyncIO->connect(portName, addr, &pasynUserSyncIO_, drvInfo)) 
00353             throw std::runtime_error(std::string("pasynInt16ArraySyncIO->connect failed"));
00354     };
00356     virtual ~asynInt16ArrayClient() {
00357         pasynInt16ArraySyncIO->disconnect(pasynUserSyncIO_);
00358     };
00363     virtual asynStatus read(epicsInt16 *value, size_t nElements, size_t *nIn) {
00364         return pasynInt16ArraySyncIO->read(pasynUserSyncIO_, value, nElements, nIn, timeout_);
00365     };
00369     virtual asynStatus write(epicsInt16 *value, size_t nElements) {
00370         return pasynInt16ArraySyncIO->write(pasynUserSyncIO_, value, nElements, timeout_);
00371     };
00374     virtual asynStatus registerInterruptUser(interruptCallbackInt16Array pCallback) { 
00375         return pInterface_->registerInterruptUser(pasynInterface_->drvPvt, pasynUser_,
00376                                                        pCallback, this, &interruptPvt_); 
00377     };
00378 private:
00379     asynInt16Array *pInterface_;
00380 };
00381 
00382 
00384 class epicsShareClass asynInt32ArrayClient : public asynPortClient {
00385 public:
00392     asynInt32ArrayClient(const char *portName, int addr, const char *drvInfo, double timeout=DEFAULT_TIMEOUT)
00393     : asynPortClient(portName, addr, asynInt32ArrayType, drvInfo, timeout) {
00394         pInterface_ = (asynInt32Array *)pasynInterface_->pinterface;
00395         if (pasynInt32ArraySyncIO->connect(portName, addr, &pasynUserSyncIO_, drvInfo)) 
00396             throw std::runtime_error(std::string("pasynInt32ArraySyncIO->connect failed"));
00397     };
00399     virtual ~asynInt32ArrayClient() {
00400         pasynInt32ArraySyncIO->disconnect(pasynUserSyncIO_);
00401     };
00406     virtual asynStatus read(epicsInt32 *value, size_t nElements, size_t *nIn) {
00407         return pasynInt32ArraySyncIO->read(pasynUserSyncIO_, value, nElements, nIn, timeout_);
00408     };
00412     virtual asynStatus write(epicsInt32 *value, size_t nElements) {
00413         return pasynInt32ArraySyncIO->write(pasynUserSyncIO_, value, nElements, timeout_);
00414     };
00417     virtual asynStatus registerInterruptUser(interruptCallbackInt32Array pCallback) { 
00418         return pInterface_->registerInterruptUser(pasynInterface_->drvPvt, pasynUser_,
00419                                                   pCallback, this, &interruptPvt_); 
00420     };
00421 private:
00422     asynInt32Array *pInterface_;
00423 };
00424 
00425 
00427 class epicsShareClass asynFloat32ArrayClient : public asynPortClient {
00428 public:
00435     asynFloat32ArrayClient(const char *portName, int addr, const char *drvInfo, double timeout=DEFAULT_TIMEOUT)
00436     : asynPortClient(portName, addr, asynFloat32ArrayType, drvInfo, timeout) {
00437         pInterface_ = (asynFloat32Array *)pasynInterface_->pinterface;
00438         if (pasynFloat32ArraySyncIO->connect(portName, addr, &pasynUserSyncIO_, drvInfo)) 
00439             throw std::runtime_error(std::string("pasynFloat64ArraySyncIO->connect failed"));
00440     };
00442     virtual ~asynFloat32ArrayClient() {
00443         pasynFloat32ArraySyncIO->disconnect(pasynUserSyncIO_);
00444     };
00449     virtual asynStatus read(epicsFloat32 *value, size_t nElements, size_t *nIn) {
00450         return pasynFloat32ArraySyncIO->read(pasynUserSyncIO_, value, nElements, nIn, timeout_);
00451     };
00455     virtual asynStatus write(epicsFloat32 *value, size_t nElements) {
00456         return pasynFloat32ArraySyncIO->write(pasynUserSyncIO_, value, nElements, timeout_);
00457     };
00460     virtual asynStatus registerInterruptUser(interruptCallbackFloat32Array pCallback) { 
00461         return pInterface_->registerInterruptUser(pasynInterface_->drvPvt, pasynUser_,
00462                                                   pCallback, this, &interruptPvt_); 
00463     };
00464 private:
00465     asynFloat32Array *pInterface_;
00466 };
00467 
00468 
00470 class epicsShareClass asynFloat64ArrayClient : public asynPortClient {
00471 public:
00478     asynFloat64ArrayClient(const char *portName, int addr, const char *drvInfo, double timeout=DEFAULT_TIMEOUT)
00479     : asynPortClient(portName, addr, asynFloat64ArrayType, drvInfo, timeout) {
00480         pInterface_ = (asynFloat64Array *)pasynInterface_->pinterface;
00481         if (pasynFloat64ArraySyncIO->connect(portName, addr, &pasynUserSyncIO_, drvInfo)) 
00482             throw std::runtime_error(std::string("pasynFloat64ArraySyncIO->connect failed"));
00483     };
00485     virtual ~asynFloat64ArrayClient() {
00486         pasynFloat64ArraySyncIO->disconnect(pasynUserSyncIO_);
00487     };
00492     virtual asynStatus read(epicsFloat64 *value, size_t nElements, size_t *nIn) {
00493         return pasynFloat64ArraySyncIO->read(pasynUserSyncIO_, value, nElements, nIn, timeout_);
00494     };
00498     virtual asynStatus write(epicsFloat64 *value, size_t nElements) {
00499         return pasynFloat64ArraySyncIO->write(pasynUserSyncIO_, value, nElements, timeout_);
00500     };
00503     virtual asynStatus registerInterruptUser(interruptCallbackFloat64Array pCallback) { 
00504         return pInterface_->registerInterruptUser(pasynInterface_->drvPvt, pasynUser_,
00505                                                   pCallback, this, &interruptPvt_); 
00506     };
00507 private:
00508     asynFloat64Array *pInterface_;
00509 };
00510 
00511 
00513 class epicsShareClass asynGenericPointerClient : public asynPortClient {
00514 public:
00521     asynGenericPointerClient(const char *portName, int addr, const char *drvInfo, double timeout=DEFAULT_TIMEOUT)
00522     : asynPortClient(portName, addr, asynGenericPointerType, drvInfo, timeout) {
00523         pInterface_ = (asynGenericPointer *)pasynInterface_->pinterface;
00524         if (pasynGenericPointerSyncIO->connect(portName, addr, &pasynUserSyncIO_, drvInfo)) 
00525             throw std::runtime_error(std::string("pasynGenericPointerSyncIO->connect failed"));
00526     };
00528     virtual ~asynGenericPointerClient() {
00529         pasynGenericPointerSyncIO->disconnect(pasynUserSyncIO_);
00530     };
00533     virtual asynStatus read(void *pointer) {
00534         return pasynGenericPointerSyncIO->read(pasynUserSyncIO_, pointer, timeout_);
00535     };
00538     virtual asynStatus write(void *pointer) {
00539         return pasynGenericPointerSyncIO->write(pasynUserSyncIO_, pointer, timeout_);
00540     };
00543     virtual asynStatus registerInterruptUser(interruptCallbackGenericPointer pCallback) { 
00544         return pInterface_->registerInterruptUser(pasynInterface_->drvPvt, pasynUser_,
00545                                                   pCallback, this, &interruptPvt_); 
00546     };
00547 private:
00548     asynGenericPointer *pInterface_;
00549 };
00550 
00551 
00553 class epicsShareClass asynOptionClient : public asynPortClient {
00554 public:
00561     asynOptionClient(const char *portName, int addr, const char *drvInfo, double timeout=DEFAULT_TIMEOUT)
00562     : asynPortClient(portName, addr, asynOptionType, drvInfo, timeout) {
00563         pInterface_ = (asynOption *)pasynInterface_->pinterface;
00564         if (pasynOptionSyncIO->connect(portName, addr, &pasynUserSyncIO_, drvInfo)) 
00565             throw std::runtime_error(std::string("pasynOptionSyncIO->connect failed"));
00566     };
00568     virtual ~asynOptionClient() {
00569         pasynOptionSyncIO->disconnect(pasynUserSyncIO_);
00570     };
00575     virtual asynStatus getOption(const char *key, char *value, int maxChars) {
00576         return pasynOptionSyncIO->getOption(pasynUserSyncIO_, key, value, maxChars, timeout_);
00577     };
00581     virtual asynStatus setOption(const char *key, const char *value) {
00582         return pasynOptionSyncIO->setOption(pasynUserSyncIO_, key, value, timeout_);
00583     };
00584 private:
00585     asynOption *pInterface_;
00586 };
00587 
00588 
00590 class epicsShareClass asynEnumClient : public asynPortClient {
00591 public:
00598     asynEnumClient(const char *portName, int addr, const char *drvInfo, double timeout=DEFAULT_TIMEOUT)
00599     : asynPortClient(portName, addr, asynEnumType, drvInfo, timeout) {
00600         pInterface_ = (asynEnum *)pasynInterface_->pinterface;
00601         if (pasynEnumSyncIO->connect(portName, addr, &pasynUserSyncIO_, drvInfo)) 
00602             throw std::runtime_error(std::string("pasynEnumSyncIO->connect failed"));
00603     };
00605     virtual ~asynEnumClient() {
00606         pasynEnumSyncIO->disconnect(pasynUserSyncIO_);
00607     };
00614     virtual asynStatus read(char *strings[], int values[], int severities[], size_t nElements, size_t *nIn) {
00615         return pasynEnumSyncIO->read(pasynUserSyncIO_, strings, values, severities, nElements, nIn, timeout_);
00616     };
00622     virtual asynStatus write(char *strings[], int values[], int severities[], size_t nElements) {
00623         return pasynEnumSyncIO->write(pasynUserSyncIO_, strings, values, severities, nElements, timeout_);
00624     };
00625 private:
00626     asynEnum *pInterface_;
00627 };
00628 
00629 
00631 class epicsShareClass asynCommonClient : public asynPortClient {
00632 public:
00639     asynCommonClient(const char *portName, int addr, const char *drvInfo, double timeout=DEFAULT_TIMEOUT)
00640     : asynPortClient(portName, addr, asynCommonType, drvInfo, timeout) {
00641         pInterface_ = (asynCommon *)pasynInterface_->pinterface;
00642         if (pasynCommonSyncIO->connect(portName, addr, &pasynUserSyncIO_, drvInfo)) 
00643             throw std::runtime_error(std::string("pasynCommonSyncIO->connect failed"));
00644     };
00646     virtual ~asynCommonClient() {
00647         pasynCommonSyncIO->disconnect(pasynUserSyncIO_);
00648     };
00652     virtual void report(FILE *fp, int details) {
00653         pasynCommonSyncIO->report(pasynUserSyncIO_, fp, details);
00654     };
00656     virtual asynStatus connect() {
00657         return pasynCommonSyncIO->connectDevice(pasynUserSyncIO_);
00658     };
00660     virtual asynStatus disconnect() {
00661         return pasynCommonSyncIO->disconnectDevice(pasynUserSyncIO_);
00662     };
00663 private:
00664     asynCommon *pInterface_;
00665 };  
00666     
00667 #endif