areaDetector  3-14
EPICS areaDetector framework
NDPluginDriver.h
Go to the documentation of this file.
1 #ifndef NDPluginDriver_H
2 #define NDPluginDriver_H
3 
4 #include <set>
5 #include <epicsTypes.h>
6 #include <epicsMessageQueue.h>
7 #include <epicsThread.h>
8 #include <epicsTime.h>
9 
10 #include <NDPluginAPI.h>
11 
12 #include "asynNDArrayDriver.h"
13 
14 class Throttler;
15 
16 // This class defines the object that is contained in the std::multilist for sorting output NDArrays
17 // It contains a pointer to the NDArray and the time that the object was added to the list
18 // It defines the < operator to use the NDArray::uniqueId field as the sort key
19 
20 // We would like to hide this class definition in NDPluginDriver.cpp and just forward reference it here.
21 // That works on Visual Studio, and on gcc if instantiating plugins as heap variables with "new", but fails on gcc
22 // if instantiating plugins as automatic variables.
23 //class sortedListElement;
24 
26  public:
27  sortedListElement(NDArray *pArray, epicsTimeStamp time);
28  friend bool operator<(const sortedListElement& lhs, const sortedListElement& rhs) {
29  return (lhs.pArray_->uniqueId < rhs.pArray_->uniqueId);
30  }
32  epicsTimeStamp insertionTime_;
33 };
34 
35 #define NDPluginDriverArrayPortString "NDARRAY_PORT"
36 #define NDPluginDriverArrayAddrString "NDARRAY_ADDR"
37 #define NDPluginDriverPluginTypeString "PLUGIN_TYPE"
38 #define NDPluginDriverDroppedArraysString "DROPPED_ARRAYS"
39 #define NDPluginDriverQueueSizeString "QUEUE_SIZE"
40 #define NDPluginDriverQueueFreeString "QUEUE_FREE"
41 #define NDPluginDriverMaxThreadsString "MAX_THREADS"
42 #define NDPluginDriverNumThreadsString "NUM_THREADS"
43 #define NDPluginDriverSortModeString "SORT_MODE"
44 #define NDPluginDriverSortTimeString "SORT_TIME"
45 #define NDPluginDriverSortSizeString "SORT_SIZE"
46 #define NDPluginDriverSortFreeString "SORT_FREE"
47 #define NDPluginDriverDisorderedArraysString "DISORDERED_ARRAYS"
48 #define NDPluginDriverDroppedOutputArraysString "DROPPED_OUTPUT_ARRAYS"
49 #define NDPluginDriverEnableCallbacksString "ENABLE_CALLBACKS"
50 #define NDPluginDriverBlockingCallbacksString "BLOCKING_CALLBACKS"
51 #define NDPluginDriverProcessPluginString "PROCESS_PLUGIN"
52 #define NDPluginDriverExecutionTimeString "EXECUTION_TIME"
53 #define NDPluginDriverMinCallbackTimeString "MIN_CALLBACK_TIME"
55 #define NDPluginDriverMaxByteRateString "MAX_BYTE_RATE"
57 class NDPLUGIN_API NDPluginDriver : public asynNDArrayDriver, public epicsThreadRunable {
58 public:
59  NDPluginDriver(const char *portName, int queueSize, int blockingCallbacks,
60  const char *NDArrayPort, int NDArrayAddr, int maxAddr,
61  int maxBuffers, size_t maxMemory, int interfaceMask, int interruptMask,
62  int asynFlags, int autoConnect, int priority, int stackSize, int maxThreads,
63  bool compressionAware = false);
64  ~NDPluginDriver();
65 
66  /* These are the methods that we override from asynNDArrayDriver */
67  virtual asynStatus writeInt32(asynUser *pasynUser, epicsInt32 value);
68  virtual asynStatus writeFloat64(asynUser *pasynUser, epicsFloat64 value);
69  virtual asynStatus writeOctet(asynUser *pasynUser, const char *value, size_t maxChars,
70  size_t *nActual);
71  virtual asynStatus readInt32Array(asynUser *pasynUser, epicsInt32 *value,
72  size_t nElements, size_t *nIn);
73 
74  /* These are the methods that are new to this class */
75  virtual void driverCallback(asynUser *pasynUser, void *genericPointer);
76  virtual void run(void);
77  virtual asynStatus start(void);
78  void sortingTask();
79 
80 protected:
81  virtual void processCallbacks(NDArray *pArray) = 0;
82  virtual void beginProcessCallbacks(NDArray *pArray);
83  virtual asynStatus endProcessCallbacks(NDArray *pArray, bool copyArray=false, bool readAttributes=true);
84  virtual asynStatus connectToArrayPort(void);
85  virtual asynStatus setArrayInterrupt(int connect);
86 
87 protected:
89  #define FIRST_NDPLUGIN_PARAM NDPluginDriverArrayPort
109 
111  bool throttled(NDArray *pArray);
112 
113 private:
114  void processTask();
115  asynStatus createCallbackThreads();
116  asynStatus startCallbackThreads();
117  asynStatus deleteCallbackThreads();
118  asynStatus createSortingThread();
119 
120  /* The asyn interfaces we access as a client */
121  void *asynGenericPointerInterruptPvt_;
122 
123  /* Our data */
124  int numThreads_;
125  bool pluginStarted_;
126  bool firstOutputArray_;
127  asynUser *pasynUserGenericPointer_;
128  void *asynGenericPointerPvt_;
129  asynGenericPointer *pasynGenericPointer_;
130  bool connectedToArrayPort_;
131  std::vector<epicsThread*>pThreads_;
132  epicsMessageQueue *pToThreadMsgQ_;
133  epicsMessageQueue *pFromThreadMsgQ_;
134  std::multiset<sortedListElement> sortedNDArrayList_;
135  int prevUniqueId_;
136  epicsThreadId sortingThreadId_;
137  epicsTimeStamp lastProcessTime_;
138  int dimsPrev_[ND_ARRAY_MAX_DIMS];
139  bool compressionAware_;
140  Throttler *throttler_;
141 };
142 
143 
144 #endif
#define ND_ARRAY_MAX_DIMS
NDArray.h.
Definition: NDArray.h:26
#define NDPLUGIN_API
Definition: NDPluginAPI.h:41
N-dimensional array class; each array has a set of dimensions, a data type, pointer to data,...
Definition: NDArray.h:99
int uniqueId
A number that must be unique for all NDArrays produced by a driver after is has started.
Definition: NDArray.h:121
Class from which actual plugin drivers are derived; derived from asynNDArrayDriver.
Definition: NDPluginDriver.h:57
int NDPluginDriverSortFree
Definition: NDPluginDriver.h:100
int NDPluginDriverQueueSize
Definition: NDPluginDriver.h:93
int NDPluginDriverEnableCallbacks
Definition: NDPluginDriver.h:103
int NDPluginDriverDroppedArrays
Definition: NDPluginDriver.h:92
int NDPluginDriverProcessPlugin
Definition: NDPluginDriver.h:105
int NDPluginDriverMinCallbackTime
Definition: NDPluginDriver.h:107
int NDPluginDriverBlockingCallbacks
Definition: NDPluginDriver.h:104
int NDPluginDriverMaxByteRate
Definition: NDPluginDriver.h:108
virtual void processCallbacks(NDArray *pArray)=0
int NDPluginDriverQueueFree
Definition: NDPluginDriver.h:94
int NDPluginDriverSortSize
Definition: NDPluginDriver.h:99
int NDPluginDriverNumThreads
Definition: NDPluginDriver.h:96
int NDPluginDriverMaxThreads
Definition: NDPluginDriver.h:95
int NDPluginDriverDisorderedArrays
Definition: NDPluginDriver.h:101
int NDPluginDriverSortTime
Definition: NDPluginDriver.h:98
int NDPluginDriverArrayAddr
Definition: NDPluginDriver.h:90
NDArray * pPrevInputArray_
Definition: NDPluginDriver.h:110
int NDPluginDriverSortMode
Definition: NDPluginDriver.h:97
int NDPluginDriverPluginType
Definition: NDPluginDriver.h:91
int NDPluginDriverArrayPort
Definition: NDPluginDriver.h:88
int NDPluginDriverExecutionTime
Definition: NDPluginDriver.h:106
int NDPluginDriverDroppedOutputArrays
Definition: NDPluginDriver.h:102
Definition: throttler.h:6
This is the class from which NDArray drivers are derived; implements the asynGenericPointer functions...
Definition: asynNDArrayDriver.h:136
virtual asynStatus writeInt32(asynUser *pasynUser, epicsInt32 value)
Definition: asynNDArrayDriver.cpp:671
virtual asynStatus writeOctet(asynUser *pasynUser, const char *value, size_t maxChars, size_t *nActual)
Called when asyn clients call pasynOctet->write().
Definition: asynNDArrayDriver.cpp:511
Definition: NDPluginDriver.h:25
sortedListElement(NDArray *pArray, epicsTimeStamp time)
Definition: NDPluginDriver.cpp:46
NDArray * pArray_
Definition: NDPluginDriver.h:31
friend bool operator<(const sortedListElement &lhs, const sortedListElement &rhs)
Definition: NDPluginDriver.h:28
epicsTimeStamp insertionTime_
Definition: NDPluginDriver.h:32
list value
Definition: makeDbAndEdl.py:234