//DevMpf.h /********************COPYRIGHT NOTIFICATION********************************** This software was developed under a United States Government license described on the COPYRIGHT_UniversityOfChicago file included as part of this distribution. ****************************************************************************/ /* Current Author: Marty Kraimer Original Author: Jim Kowalkowski (for Hideos) Date: 01JUL98 This is the main base class for any EPICS MPF device support. All EPICS device support that communicates with MPF tasks should be derived from this class. This class hides most of the details of EPICS device support and the MPF (Message Passing Facility). Each instance of a device is bound to one MPF server, the name of the MPF task it is bound to is the first string in parm field of the record's link. */ #ifndef DevMpfH #define DevMpfH class Message; class MessageClient; class dbCommon; class link; extern "C" { #include "callback.h" #include "dbScan.h" #include "devSup.h" }; #include "Message.h" #include "WatchDog.h" #include "ConnectMessage.h" #include "OutOfBandMessage.h" /*------------------------------------------------------------------------*/ /* generic structure for device support */ typedef struct { long number; DEVSUPFUN report; DEVSUPFUN init; DEVSUPFUN init_record; long (*get_ioint_info)(int,dbCommon*,IOSCANPVT*); DEVSUPFUN read_write; long (*conv)(void*,int); } MPF_DSET; /* Macros that generate DSETs */ #define MAKE_DSET(name,init_func) extern "C" { MPF_DSET name = \ { 5,NULL,NULL,init_func,DevMpf::ioint,DevMpf::read_write,NULL };}; #define MAKE_LINCONV_DSET(name,init_func) extern "C" { MPF_DSET name = \ { 6,NULL,NULL,init_func,DevMpf::ioint,DevMpf::read_write,\ DevMpf::linconv};}; /*------------------------------------------------------------------------*/ // return codes for startIO(). #define MPF_OK 0 #define MPF_NoConvert 2 enum replyType {replyTypeNone, replyTypeCompleteIO, replyTypeReceiveReply}; class DevMpf; // Following needed if messageClientCallback called during iocInit class CallbackRetry { friend class DevMpf; WatchDog *wdId; DevMpf *pDevMpf; Message *message; void *clientPvt; }; class DevMpf { public: DevMpf(dbCommon*,link*,bool iointValid); // Following must be implemented by device support modules virtual long startIO(dbCommon*)=0; // start async IO virtual long completeIO(dbCommon*,Message *)=0; // end async IO // Following can be implemented by device support modules virtual void receiveReply(dbCommon*,Message *); // virtual void connectIO(dbCommon*,Message *); // connection message virtual void outOfBandIO(dbCommon*,Message *);// outOfBand message virtual long convert(dbCommon*,int pass); // do linear conversion // send a message to MPF server with no reply expected int send(Message*); // send a message to MPF server and wait for reply via completeIO int sendReply(Message*); // send a message stating the type of reply int send(Message*,replyType); // This routine gets a pointer to the user portion of the parm field const char* getUserParm() const { return((const char*)userParm); } long getStatus() const { return(status);} // Following are DSET routines static long read_write(void*); // generic DSET read/write routine static long ioint(int cmd,dbCommon*,IOSCANPVT* iopvt); // DSET i/o intr static long linconv(void*,int); // calls convert IOSCANPVT ioscanpvt; bool iointValid; private: static void callbackAgain(void *pvt); static void messageClientCallback(Message *message,void *clientPvt); long status; dbCommon *precord; link *plink; char* userParm; CALLBACK cb; MessageClient *pMessageClient; connectStatus connectState; Message *replyMessage; CallbackRetry *pCallbackRetry; SEM_ID connectWait; // disallow copy constructor, assignment operator DevMpf(const DevMpf &); DevMpf& operator=(const DevMpf&); }; #endif // DevMpfH