ADApp/pluginSrc/NDPluginDriver.cpp
NDPluginDriver::NDPluginDriver(const char *portName, int queueSize, int blockingCallbacks, 
                               const char *NDArrayPort, int NDArrayAddr, int maxAddr, int numParams,
                               int maxBuffers, size_t maxMemory, int interfaceMask, int interruptMask,
                               int asynFlags, int autoConnect, int priority, int stackSize)

    : asynNDArrayDriver(portName, maxAddr, numParams+NUM_NDPLUGIN_PARAMS, maxBuffers, maxMemory,
          interfaceMask | asynInt32Mask | asynFloat64Mask | asynOctetMask | asynInt32ArrayMask | asynDrvUserMask,
          interruptMask | asynInt32Mask | asynFloat64Mask | asynOctetMask | asynInt32ArrayMask,
          asynFlags, autoConnect, priority, stackSize),
    newQueueSize_(0)    
{
    static const char *functionName = "NDPluginDriver";
    char taskName[256];
    asynUser *pasynUser;
    this->pThreadStartedEvent = new epicsEvent;

    strcpy(taskName, portName);
    strcat(taskName, "_Plugin");
    /* We use the same stack size for our callback thread as for the port thread */
    if (stackSize <= 0) stackSize = epicsThreadGetStackSize(epicsThreadStackMedium);
    this->pThread = new epicsThread(*this, taskName,
                                    stackSize, epicsThreadPriorityMedium);

    lock();
    
    /* Initialize some members to 0 */
    memset(&this->lastProcessTime, 0, sizeof(this->lastProcessTime));
    memset(&this->dimsPrev, 0, sizeof(this->dimsPrev));
    this->pasynGenericPointer = NULL;
    this->asynGenericPointerPvt = NULL;
    this->asynGenericPointerInterruptPvt = NULL;
    this->connectedToArrayPort = false;
       
    /* Create asynUser for communicating with NDArray port */
    pasynUser = pasynManager->createAsynUser(0, 0);
    pasynUser->userPvt = this;
    this->pasynUserGenericPointer = pasynUser;
    this->pasynUserGenericPointer->reason = NDArrayData;

    /* Create the message queue for the input arrays */
    this->msgQId = epicsMessageQueueCreate(queueSize, sizeof(NDArray*));
    if (!this->msgQId) {
        printf("%s:%s: epicsMessageQueueCreate failure\n", driverName, functionName);
        return;
    }
    
    createParam(NDPluginDriverArrayPortString,         asynParamOctet, &NDPluginDriverArrayPort);
    createParam(NDPluginDriverArrayAddrString,         asynParamInt32, &NDPluginDriverArrayAddr);
    createParam(NDPluginDriverPluginTypeString,        asynParamOctet, &NDPluginDriverPluginType);
    createParam(NDPluginDriverDroppedArraysString,     asynParamInt32, &NDPluginDriverDroppedArrays);
    createParam(NDPluginDriverQueueSizeString,         asynParamInt32, &NDPluginDriverQueueSize);
    createParam(NDPluginDriverQueueFreeString,         asynParamInt32, &NDPluginDriverQueueFree);
    createParam(NDPluginDriverEnableCallbacksString,   asynParamInt32, &NDPluginDriverEnableCallbacks);
    createParam(NDPluginDriverBlockingCallbacksString, asynParamInt32, &NDPluginDriverBlockingCallbacks);
    createParam(NDPluginDriverMinCallbackTimeString,   asynParamFloat64, &NDPluginDriverMinCallbackTime);

    /* Here we set the values of read-only parameters and of read/write parameters that cannot
     * or should not get their values from the database.  Note that values set here will override
     * those in the database for output records because if asyn device support reads a value from 
     * the driver with no error during initialization then it sets the output record to that value.  
     * If a value is not set here then the read request will return an error (uninitialized).
     * Values set here will be overridden by values from save/restore if they exist. */
    setStringParam (NDPluginDriverArrayPort, NDArrayPort);
    setIntegerParam(NDPluginDriverArrayAddr, NDArrayAddr);
    setIntegerParam(NDPluginDriverDroppedArrays, 0);
    setIntegerParam(NDPluginDriverQueueSize, queueSize);
    setIntegerParam(NDPluginDriverBlockingCallbacks, blockingCallbacks);
    unlock();
}
/** Constructor for NDPluginDriver; most parameters are simply passed to asynNDArrayDriver::asynNDArrayDriver.
  * After calling the base class constructor this method creates a thread to execute the NDArray callbacks, 
  * and sets reasonable default values for all of the parameters defined in NDPluginDriver.h.
  * \param[in] portName The name of the asyn port driver to be created.
  * \param[in] queueSize The number of NDArrays that the input queue for this plugin can hold when 
  *            NDPluginDriverBlockingCallbacks=0.  Larger queues can decrease the number of dropped arrays,
  *            at the expense of more NDArray buffers being allocated from the underlying driver's NDArrayPool.
  * \param[in] blockingCallbacks Initial setting for the NDPluginDriverBlockingCallbacks flag.
  *            0=callbacks are queued and executed by the callback thread; 1 callbacks execute in the thread
  *            of the driver doing the callbacks.
  * \param[in] NDArrayPort Name of asyn port driver for initial source of NDArray callbacks.
  * \param[in] NDArrayAddr asyn port driver address for initial source of NDArray callbacks.
  * \param[in] maxAddr The maximum  number of asyn addr addresses this driver supports. 1 is minimum.
  * \param[in] numParams The number of parameters that the derived class supports.
  * \param[in] maxBuffers The maximum number of NDArray buffers that the NDArrayPool for this driver is 
  *            allowed to allocate. Set this to -1 to allow an unlimited number of buffers.
  * \param[in] maxMemory The maximum amount of memory that the NDArrayPool for this driver is 
  *            allowed to allocate. Set this to -1 to allow an unlimited amount of memory.
  * \param[in] interfaceMask Bit mask defining the asyn interfaces that this driver supports.
  * \param[in] interruptMask Bit mask definining the asyn interfaces that can generate interrupts (callbacks)
  * \param[in] asynFlags Flags when creating the asyn port driver; includes ASYN_CANBLOCK and ASYN_MULTIDEVICE.
  * \param[in] autoConnect The autoConnect flag for the asyn port driver.
  * \param[in] priority The thread priority for the asyn port driver thread if ASYN_CANBLOCK is set in asynFlags.
  * \param[in] stackSize The stack size for the asyn port driver thread if ASYN_CANBLOCK is set in asynFlags.
  */
Constructor for NDPluginDriver; most parameters are simply passed to asynNDArrayDriver::asynNDArrayDriver.
After calling the base class constructor this method creates a thread to execute the NDArray callbacks,
and sets reasonable default values for all of the parameters defined in NDPluginDriver.h.
\param[in] portName The name of the asyn port driver to be created.
\param[in] queueSize The number of NDArrays that the input queue for this plugin can hold when
NDPluginDriverBlockingCallbacks=0.  Larger queues can decrease the number of dropped arrays,
at the expense of more NDArray buffers being allocated from the underlying driver's NDArrayPool.
\param[in] blockingCallbacks Initial setting for the NDPluginDriverBlockingCallbacks flag.
0=callbacks are queued and executed by the callback thread; 1 callbacks execute in the thread
of the driver doing the callbacks.
\param[in] NDArrayPort Name of asyn port driver for initial source of NDArray callbacks.
\param[in] NDArrayAddr asyn port driver address for initial source of NDArray callbacks.
\param[in] maxAddr The maximum  number of asyn addr addresses this driver supports. 1 is minimum.
\param[in] numParams The number of parameters that the derived class supports.
\param[in] maxBuffers The maximum number of NDArray buffers that the NDArrayPool for this driver is
allowed to allocate. Set this to -1 to allow an unlimited number of buffers.
\param[in] maxMemory The maximum amount of memory that the NDArrayPool for this driver is
allowed to allocate. Set this to -1 to allow an unlimited amount of memory.
\param[in] interfaceMask Bit mask defining the asyn interfaces that this driver supports.
\param[in] interruptMask Bit mask definining the asyn interfaces that can generate interrupts (callbacks)
\param[in] asynFlags Flags when creating the asyn port driver; includes ASYN_CANBLOCK and ASYN_MULTIDEVICE.
\param[in] autoConnect The autoConnect flag for the asyn port driver.
\param[in] priority The thread priority for the asyn port driver thread if ASYN_CANBLOCK is set in asynFlags.
\param[in] stackSize The stack size for the asyn port driver thread if ASYN_CANBLOCK is set in asynFlags.
Constructor for NDPluginDriver ; most parameters are simply passed to asynNDArrayDriver :: asynNDArrayDriver . After calling the base class constructor this method creates a thread to execute the NDArray callbacks and sets reasonable default values for all of the parameters defined in NDPluginDriver . h . \ param [ in ] portName The name of the asyn port driver to be created . \ param [ in ] queueSize The number of NDArrays that the input queue for this plugin can hold when NDPluginDriverBlockingCallbacks = 0 . Larger queues can decrease the number of dropped arrays at the expense of more NDArray buffers being allocated from the underlying driver ' s NDArrayPool . \ param [ in ] blockingCallbacks Initial setting for the NDPluginDriverBlockingCallbacks flag . 0 = callbacks are queued and executed by the callback thread ; 1 callbacks execute in the thread of the driver doing the callbacks . \ param [ in ] NDArrayPort Name of asyn port driver for initial source of NDArray callbacks . \ param [ in ] NDArrayAddr asyn port driver address for initial source of NDArray callbacks . \ param [ in ] maxAddr The maximum number of asyn addr addresses this driver supports . 1 is minimum . \ param [ in ] numParams The number of parameters that the derived class supports . \ param [ in ] maxBuffers The maximum number of NDArray buffers that the NDArrayPool for this driver is allowed to allocate . Set this to - 1 to allow an unlimited number of buffers . \ param [ in ] maxMemory The maximum amount of memory that the NDArrayPool for this driver is allowed to allocate . Set this to - 1 to allow an unlimited amount of memory . \ param [ in ] interfaceMask Bit mask defining the asyn interfaces that this driver supports . \ param [ in ] interruptMask Bit mask definining the asyn interfaces that can generate interrupts ( callbacks ) \ param [ in ] asynFlags Flags when creating the asyn port driver ; includes ASYN_CANBLOCK and ASYN_MULTIDEVICE . \ param [ in ] autoConnect The autoConnect flag for the asyn port driver . \ param [ in ] priority The thread priority for the asyn port driver thread if ASYN_CANBLOCK is set in asynFlags . \ param [ in ] stackSize The stack size for the asyn port driver thread if ASYN_CANBLOCK is set in asynFlags .
NDPluginDriver::NDPluginDriver(const char *portName, int queueSize, int blockingCallbacks, 
                               const char *NDArrayPort, int NDArrayAddr, int maxAddr, int numParams,
                               int maxBuffers, size_t maxMemory, int interfaceMask, int interruptMask,
                               int asynFlags, int autoConnect, int priority, int stackSize)
    : asynNDArrayDriver(portName, maxAddr, numParams+NUM_NDPLUGIN_PARAMS, maxBuffers, maxMemory,
          interfaceMask | asynInt32Mask | asynFloat64Mask | asynOctetMask | asynInt32ArrayMask | asynDrvUserMask,
          interruptMask | asynInt32Mask | asynFloat64Mask | asynOctetMask | asynInt32ArrayMask,
          asynFlags, autoConnect, priority, stackSize),
    newQueueSize_(0)    
{
    static const char *functionName = "NDPluginDriver";
    char taskName[256];
    asynUser *pasynUser;
    this->pThreadStartedEvent = new epicsEvent;
    strcpy(taskName, portName);
    strcat(taskName, "_Plugin");
    if (stackSize <= 0) stackSize = epicsThreadGetStackSize(epicsThreadStackMedium);
    this->pThread = new epicsThread(*this, taskName,
                                    stackSize, epicsThreadPriorityMedium);
    lock();
    memset(&this->lastProcessTime, 0, sizeof(this->lastProcessTime));
    memset(&this->dimsPrev, 0, sizeof(this->dimsPrev));
    this->pasynGenericPointer = NULL;
    this->asynGenericPointerPvt = NULL;
    this->asynGenericPointerInterruptPvt = NULL;
    this->connectedToArrayPort = false;
    pasynUser = pasynManager->createAsynUser(0, 0);
    pasynUser->userPvt = this;
    this->pasynUserGenericPointer = pasynUser;
    this->pasynUserGenericPointer->reason = NDArrayData;
    this->msgQId = epicsMessageQueueCreate(queueSize, sizeof(NDArray*));
    if (!this->msgQId) {
        printf("%s:%s: epicsMessageQueueCreate failure\n", driverName, functionName);
        return;
    }
    createParam(NDPluginDriverArrayPortString,         asynParamOctet, &NDPluginDriverArrayPort);
    createParam(NDPluginDriverArrayAddrString,         asynParamInt32, &NDPluginDriverArrayAddr);
    createParam(NDPluginDriverPluginTypeString,        asynParamOctet, &NDPluginDriverPluginType);
    createParam(NDPluginDriverDroppedArraysString,     asynParamInt32, &NDPluginDriverDroppedArrays);
    createParam(NDPluginDriverQueueSizeString,         asynParamInt32, &NDPluginDriverQueueSize);
    createParam(NDPluginDriverQueueFreeString,         asynParamInt32, &NDPluginDriverQueueFree);
    createParam(NDPluginDriverEnableCallbacksString,   asynParamInt32, &NDPluginDriverEnableCallbacks);
    createParam(NDPluginDriverBlockingCallbacksString, asynParamInt32, &NDPluginDriverBlockingCallbacks);
    createParam(NDPluginDriverMinCallbackTimeString,   asynParamFloat64, &NDPluginDriverMinCallbackTime);
    setStringParam (NDPluginDriverArrayPort, NDArrayPort);
    setIntegerParam(NDPluginDriverArrayAddr, NDArrayAddr);
    setIntegerParam(NDPluginDriverDroppedArrays, 0);
    setIntegerParam(NDPluginDriverQueueSize, queueSize);
    setIntegerParam(NDPluginDriverBlockingCallbacks, blockingCallbacks);
    unlock();
}
NDPluginDriver :: NDPluginDriver ( const char * portName , int queueSize , int blockingCallbacks , const char * NDArrayPort , int NDArrayAddr , int maxAddr , int numParams , int maxBuffers , size_t maxMemory , int interfaceMask , int interruptMask , int asynFlags , int autoConnect , int priority , int stackSize ) : asynNDArrayDriver ( portName , maxAddr , numParams + NUM_NDPLUGIN_PARAMS , maxBuffers , maxMemory , interfaceMask | asynInt32Mask | asynFloat64Mask | asynOctetMask | asynInt32ArrayMask | asynDrvUserMask , interruptMask | asynInt32Mask | asynFloat64Mask | asynOctetMask | asynInt32ArrayMask , asynFlags , autoConnect , priority , stackSize ) , newQueueSize_ ( 0 ) { static const char * functionName = " " ; char taskName [ 256 ] ; asynUser * pasynUser ; this -> pThreadStartedEvent = new epicsEvent ; strcpy ( taskName , portName ) ; strcat ( taskName , " " ) ; if ( stackSize <= 0 ) stackSize = epicsThreadGetStackSize ( epicsThreadStackMedium ) ; this -> pThread = new epicsThread ( * this , taskName , stackSize , epicsThreadPriorityMedium ) ; lock ( ) ; memset ( & this -> lastProcessTime , 0 , sizeof ( this -> lastProcessTime ) ) ; memset ( & this -> dimsPrev , 0 , sizeof ( this -> dimsPrev ) ) ; this -> pasynGenericPointer = NULL ; this -> asynGenericPointerPvt = NULL ; this -> asynGenericPointerInterruptPvt = NULL ; this -> connectedToArrayPort = false ; pasynUser = pasynManager -> createAsynUser ( 0 , 0 ) ; pasynUser -> userPvt = this ; this -> pasynUserGenericPointer = pasynUser ; this -> pasynUserGenericPointer -> reason = NDArrayData ; this -> msgQId = epicsMessageQueueCreate ( queueSize , sizeof ( NDArray * ) ) ; if ( ! this -> msgQId ) { printf ( " \n " , driverName , functionName ) ; return ; } createParam ( NDPluginDriverArrayPortString , asynParamOctet , & NDPluginDriverArrayPort ) ; createParam ( NDPluginDriverArrayAddrString , asynParamInt32 , & NDPluginDriverArrayAddr ) ; createParam ( NDPluginDriverPluginTypeString , asynParamOctet , & NDPluginDriverPluginType ) ; createParam ( NDPluginDriverDroppedArraysString , asynParamInt32 , & NDPluginDriverDroppedArrays ) ; createParam ( NDPluginDriverQueueSizeString , asynParamInt32 , & NDPluginDriverQueueSize ) ; createParam ( NDPluginDriverQueueFreeString , asynParamInt32 , & NDPluginDriverQueueFree ) ; createParam ( NDPluginDriverEnableCallbacksString , asynParamInt32 , & NDPluginDriverEnableCallbacks ) ; createParam ( NDPluginDriverBlockingCallbacksString , asynParamInt32 , & NDPluginDriverBlockingCallbacks ) ; createParam ( NDPluginDriverMinCallbackTimeString , asynParamFloat64 , & NDPluginDriverMinCallbackTime ) ; setStringParam ( NDPluginDriverArrayPort , NDArrayPort ) ; setIntegerParam ( NDPluginDriverArrayAddr , NDArrayAddr ) ; setIntegerParam ( NDPluginDriverDroppedArrays , 0 ) ; setIntegerParam ( NDPluginDriverQueueSize , queueSize ) ; setIntegerParam ( NDPluginDriverBlockingCallbacks , blockingCallbacks ) ; unlock ( ) ; }
Constructor for NDPluginDriver; most parameters are simply passed to asynNDArrayDriver::asynNDArrayDriver.
Constructor for NDPluginDriver ; most parameters are simply passed to asynNDArrayDriver :: asynNDArrayDriver .
/* We use the same stack size for our callback thread as for the port thread */ /* Initialize some members to 0 */ /* Create asynUser for communicating with NDArray port */ /* Create the message queue for the input arrays */ /* Here we set the values of read-only parameters and of read/write parameters that cannot
     * or should not get their values from the database.  Note that values set here will override
     * those in the database for output records because if asyn device support reads a value from 
     * the driver with no error during initialization then it sets the output record to that value.  
     * If a value is not set here then the read request will return an error (uninitialized).
     * Values set here will be overridden by values from save/restore if they exist. */