NDS3  1.0.0
API reference manual
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
factoryBaseImpl.h
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 NDSFACTORYBASEIMPL_H
11 #define NDSFACTORYBASEIMPL_H
12 
13 #include <map>
14 #include <mutex>
15 #include <memory>
16 #include <thread>
17 #include "nds3/definitions.h"
18 
19 namespace nds
20 {
21 
22 class InterfaceBaseImpl;
23 class BaseImpl;
24 class NodeImpl;
25 class PVBaseImpl;
26 class LogStreamGetterImpl;
27 class ThreadBaseImpl;
28 class IniFileParserImpl;
29 
51 class NDS3_API FactoryBaseImpl: public std::enable_shared_from_this<FactoryBaseImpl>
52 {
53  friend class InterfaceBaseImpl;
54 public:
56 
57  virtual ~FactoryBaseImpl();
58 
65  virtual void preDelete();
66 
67  virtual ThreadBaseImpl* runInThread(const std::string& name, threadFunction_t function);
68 
69  static void loadDriver(const std::string& libraryName);
70 
82  void* createDevice(const std::string& driverName, const std::string& deviceName, const namedParameters_t& parameters);
83 
88  void destroyDevice(void* pDevice);
89 
90  void destroyDevice(const std::string& deviceName);
91 
92  void holdNode(void* pDeviceObject, std::shared_ptr<NodeImpl> pHoldNode);
93 
106  const std::string& getSeparator(const std::uint32_t nodeLevel) const;
107 
108  void loadNamingRules(std::istream& rules);
109  void setNamingRules(const std::string& rulesName);
110 
111  std::string getRootNodeName(const std::string& name) const;
112  std::string getGenericChannelName(const std::string& name) const;
113  std::string getInputChannelName(const std::string& name) const;
114  std::string getOutputChannelName(const std::string& name) const;
115  std::string getSourceChannelName(const std::string& name) const;
116  std::string getSinkChannelName(const std::string& name) const;
117  std::string getInputPVName(const std::string& name) const;
118  std::string getOutputPVName(const std::string& name) const;
119  std::string getStateMachineNodeName(const std::string& name) const;
120  std::string getStateMachineSetStateName(const std::string& name) const;
121  std::string getStateMachineGetStateName(const std::string& name) const;
122  std::string getStateMachineGetGlobalStateName(const std::string& name) const;
123  std::string getDecimationPVName(const std::string& name) const;
124 
125  std::string buildNameFromRule(const std::string& name,
126  const std::string& rule0,
127  const std::string& rule1 = "",
128  const std::string& rule2 = "",
129  const std::string& rule3 = "",
130  const std::string& rule4 = ""
131  ) const;
132 
133  virtual const std::string& getDefaultSeparator(const std::uint32_t nodeLevel) const = 0;
134 
135  virtual const std::string getName() const = 0;
136 
137 
146  virtual InterfaceBaseImpl* getNewInterface(const std::string& fullName) = 0;
147 
148  virtual void run(int argc,char *argv[]) = 0;
149 
150  virtual LogStreamGetterImpl* getLogStreamGetter() = 0;
151 
164  virtual void registerCommand(const BaseImpl& node,
165  const std::string& command,
166  const std::string& usage,
167  const size_t numParameters, command_t commandFunction) = 0;
168 
177  virtual void deregisterCommand(const BaseImpl& node) = 0;
178 
179 private:
180  struct allocatedDevice_t
181  {
182  void* m_pDevice;
183  deallocateDriver_t m_deallocationFunction;
184  };
185 
186  typedef std::map<std::string, allocatedDevice_t> allocatedDevices_t;
187  allocatedDevices_t m_allocatedDevices;
188 
189  typedef std::list<std::shared_ptr<NodeImpl> > nodesList_t;
190  typedef std::map<void*, nodesList_t> heldNodes_t;
191  heldNodes_t m_heldNodes;
192 
193  std::mutex m_mutex;
194 
195  std::unique_ptr<IniFileParserImpl> m_namingRules;
196  std::string m_namingRulesName;
197 
198 };
199 
200 }
201 
202 
203 #endif // NDSFACTORYBASEIMPL_H
std::function< void(void *)> deallocateDriver_t
Definition for the function executed to deallocate a driver.
Definition: definitions.h:244
This is the base class for objects that interact with specific control systems and has to be allocate...
Definition: factoryBaseImpl.h:51
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
Defines all the enumeration and common types used across the NDS library.
Represents the interface between NDS and the control system API.
Definition: interfaceBaseImpl.h:26
std::map< std::string, std::string > namedParameters_t
Map containing named parameters passed to the device during the initialization.
Definition: definitions.h:222