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