NDS3  1.0.0
API reference manual
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
definitions.h
Go to the documentation of this file.
1 /*
2  * Nominal Device Support v3 (NDS3)
3  *
4  * Copyright (c) 2015 Cosylab d.d.
5  *
6  * For more information about the license please refer to the license.txt
7  * file included in the distribution.
8  */
9 
10 #ifndef NDS3_DEFINITIONS_H
11 #define NDS3_DEFINITIONS_H
12 
13 
22 #include <cstdint>
23 #include <functional>
24 #include <time.h>
25 #include <string>
26 #include <list>
27 #include <vector>
28 #include <map>
29 
30 namespace nds
31 {
32 
36 enum class state_t
37 {
38  unknown,
39  off,
40  switchingOff,
41  initializing,
42  on,
43  stopping,
44  starting,
45  running,
46  fault,
48 };
49 
53 enum class dataType_t
54 {
55  /* The value zero is reserved to static asserts to verify that the correct cpp types are being used */
56  dataInt32 = 1,
57  dataFloat64,
62  dataString
63 };
64 
68 enum class scanType_t
69 {
70  periodic,
71  passive,
72  interrupt
73 };
74 
75 
80 enum class logLevel_t: std::uint8_t
81 {
82  debug,
83  info,
84  warning,
85  error,
86  none
87 };
88 
92 enum class dataDirection_t
93 {
94  input,
95  output
96 };
97 
103 enum class nodeType_t
104 {
105  generic,
106  inputChannel,
107  outputChannel,
110  stateMachine
111 };
112 
118 enum class inputPvType_t
119 {
120  generic,
121  getLocalState,
123 };
124 
130 enum class outputPvType_t
131 {
132  generic,
134 };
135 
142 #define ndsLogStream(node, logLevel) \
143  if(!(node).isLogLevelEnabled(logLevel)) {} else (node).getLogger(logLevel)
144 
157 #define ndsDebugStream(node) ndsLogStream(node, nds::logLevel_t::debug)
158 
171 #define ndsInfoStream(node) ndsLogStream(node, nds::logLevel_t::info)
172 
185 #define ndsWarningStream(node) ndsLogStream(node, nds::logLevel_t::warning)
186 
199 #define ndsErrorStream(node) ndsLogStream(node, nds::logLevel_t::error)
200 
204 typedef std::vector<std::string> parameters_t;
205 
216 typedef std::function<parameters_t (const parameters_t& parameters)> command_t;
217 
222 typedef std::map<std::string, std::string> namedParameters_t;
223 
224 class Factory;
225 
236 typedef std::function<void*(Factory& factory, const std::string& deviceName, const namedParameters_t& parameters)> allocateDriver_t;
237 
244 typedef std::function<void (void*)> deallocateDriver_t;
245 
246 
254 typedef std::function<void ()> stateChange_t;
255 
256 
271 typedef std::function<bool (const state_t, const state_t, const state_t)> allowChange_t;
272 
279 typedef std::function<timespec ()> getTimestampPlugin_t;
280 
281 typedef std::function<void ()> threadFunction_t;
282 
283 
288 typedef std::list<std::string> enumerationStrings_t;
289 
290 
291 } // namespace nds
292 
300 #define NDS_DEFINE_DRIVER(driverName, className)\
301 extern "C" \
302 { \
303 void* allocateDevice(nds::Factory& factory, const std::string& device, const nds::namedParameters_t& parameters) \
304 { \
305  return new className(factory, device, parameters); \
306 } \
307 void deallocateDevice(void* device) \
308 { \
309  delete (className*)device; \
310 } \
311 const char* getDeviceName() \
312 { \
313  return #driverName; \
314 } \
315 nds::RegisterDevice<className> registerDevice##driverName(#driverName); \
316 } // extern "C"
317 
318 // Generic helper definitions for shared library support
319 #if defined _WIN32 || defined __CYGWIN__
320  #define NDS3_HELPER_DLL_IMPORT __declspec(dllimport)
321  #define NDS3_HELPER_DLL_EXPORT __declspec(dllexport)
322 #else
323  #if __GNUC__ >= 4
324  #define NDS3_HELPER_DLL_IMPORT __attribute__ ((visibility ("default")))
325  #define NDS3_HELPER_DLL_EXPORT __attribute__ ((visibility ("default")))
326  #else
327  #define NDS3_HELPER_DLL_IMPORT
328  #define NDS3_HELPER_DLL_EXPORT
329  #endif
330 #endif
331 
332 
333 // NDS3_API is used for the public API symbols
334 
335 #ifdef NDS3_DLL // defined if NDS3 is compiled as a DLL
336  #ifdef NDS3_DLL_EXPORTS // defined if we are building the NDS3 DLL (instead of using it)
337  #define NDS3_API NDS3_HELPER_DLL_EXPORT
338  #else
339  #define NDS3_API NDS3_HELPER_DLL_IMPORT
340  #endif // NDS3_DLL_EXPORTS
341 #else // NDS3_DLL is not defined: this means NDS3 is a static lib.
342  #define NDS3_API
343 #endif // NDS3_DLL
344 
345 #endif // NDS3_DEFINITIONS_H
scanType_t
Specify how to get the PV value.
Definition: definitions.h:68
The PV is used to change the local state of a state machine.
The device is switched on.
Array of signed 32 bit integers.
The device server pushes the value to the control system when it changes.
The PV is used to retrieve the local state of a state machine.
An error caused the device to go to FAULT mode.
Debug information.
Non critical information.
Array of unsigned 8 bit integers.
The data is being written by the control system and read by the device support.
std::function< void(void *)> deallocateDriver_t
Definition for the function executed to deallocate a driver.
Definition: definitions.h:244
The node contains a PV that receives pushed data.
std::function< timespec()> getTimestampPlugin_t
Definition for a function called to retrieve a time.
Definition: definitions.h:279
std::function< void *(Factory &factory, const std::string &deviceName, const namedParameters_t &parameters)> allocateDriver_t
Definition for the function executed to allocate a driver.
Definition: definitions.h:224
The device is switched off.
Array of 64 bit floats.
Signed integer, 32 bits.
nodeType_t
Defines the nodes' roles in the tree structure: it is used to build the node's external name when usi...
Definition: definitions.h:103
logLevel_t
Defines the severities of the log information.
Definition: definitions.h:80
std::function< parameters_t(const parameters_t &parameters)> command_t
Definition of a function called to execute a node's command.
Definition: definitions.h:216
The device is switched on and is starting the operations.
outputPvType_t
Defines an output PV's role: this information is used to build the PV's external name when using the ...
Definition: definitions.h:130
std::function< bool(const state_t, const state_t, const state_t)> allowChange_t
Definition for a function called to allow or deny a state transition.
Definition: definitions.h:271
The node contains mainly input PVs.
std::function< void()> stateChange_t
Definition for the function executed during the state transition.
Definition: definitions.h:254
The state is Unknown.
std::list< std::string > enumerationStrings_t
List of strings used for enumeration in PVs that support the enumeration field.
Definition: definitions.h:288
The device is switched off but is in the process of switching on.
The data is being written by the device support and read by the control system.
The PV is used to retrieve the global state.
dataDirection_t
Defines in which direction the data is being transferred.
Definition: definitions.h:92
The node implements a state machine.
std::map< std::string, std::string > namedParameters_t
Map containing named parameters passed to the device during the initialization.
Definition: definitions.h:222
The node contains mainly output PVs.
The node contains a PV that pushes acquired data.
The control system polls the value only when needed.
std::vector< std::string > parameters_t
List of strings passed as parameters to nodes' commands.
Definition: definitions.h:204
dataType_t
PV data types.
Definition: definitions.h:53
The control system polls the value with a specified frequency.
Nothing is logger.
state_t
Available states, ordered by priority (lowest to higher).
Definition: definitions.h:36
The device is acquiring data but is in the process of stopping the operations.
Array of signed 8 bit integers.
Communicates with a static instance of the control system.
Definition: factory.h:43
The device is switched on but is in the process of switching off.
The device is operating.
Indicate the number of states in the enumeration.
inputPvType_t
Defines an input PV's role: this information is used to build the PV's external name when using the N...
Definition: definitions.h:118