NDS3  1.0.0
API reference manual
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
ndsFactoryImpl.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 NDSFACTORYIMPL_H
11 #define NDSFACTORYIMPL_H
12 
13 #include <string>
14 #include <map>
15 #include <list>
16 #include <memory>
17 #include <mutex>
18 #include <dirent.h>
19 #include "nds3/definitions.h"
20 
21 namespace nds
22 {
23 
24 class FactoryBaseImpl;
25 class DynamicModule;
26 class PVBaseInImpl;
27 class PVBaseOutImpl;
28 
29 class NdsFactoryImpl
30 {
31 public:
32  static NdsFactoryImpl& getInstance();
33 
34  NdsFactoryImpl();
35 
36  ~NdsFactoryImpl();
37 
38  std::shared_ptr<FactoryBaseImpl> getControlSystem(const std::string& controlSystem);
39 
40  void loadDriver(const std::string& driverModuleName);
41 
49  void registerDriver(const std::string& driverName, allocateDriver_t allocateFunction, deallocateDriver_t deallocateFunction);
50 
55  void registerControlSystem(std::shared_ptr<FactoryBaseImpl> pControlSystem);
56 
65  std::pair<void*, deallocateDriver_t> createDevice(FactoryBaseImpl& factory, const std::string& driverName, const std::string& deviceName, const namedParameters_t& parameters);
66 
75  void subscribe(const std::string& pushFrom, PVBaseOutImpl* pReceiver);
76 
77  void subscribe(const std::string& pushFrom, const std::string& pushTo);
78 
79  void unsubscribe(PVBaseOutImpl* pReceiver);
80 
81  void unsubscribe(const std::string& pushTo);
82 
83  void replicate(const std::string& replicateSource, PVBaseInImpl* pDestination);
84 
85  void replicate(const std::string& replicateSource, const std::string& replicateDestination);
86 
87  void stopReplicationTo(PVBaseInImpl* pDestination);
88 
89  void stopReplicationTo(const std::string& replicateDestination);
90 
91 
92  void registerInputPV(PVBaseInImpl* pSender);
93  void deregisterInputPV(PVBaseInImpl* pSender);
94  void registerOutputPV(PVBaseOutImpl* pReceiver);
95  void deregisterOutputPV(PVBaseOutImpl* pReceiver);
96 
97 private:
98  typedef std::list<std::string> fileNames_t;
99 
100  static fileNames_t listFiles(const fileNames_t& folders, const std::string& prefix, const std::string& suffix);
101 
102  static fileNames_t separateFoldersList(const char* foldersList);
103 
104  typedef std::map<std::string, std::shared_ptr<FactoryBaseImpl> > controlSystems_t;
105  controlSystems_t m_controlSystems;
106  std::mutex m_lockControlSystems;
107 
108  typedef std::map<std::string, std::pair<allocateDriver_t, deallocateDriver_t> > driverAllocDeallocMap_t;
109  driverAllocDeallocMap_t m_driversAllocDealloc;
110  std::mutex m_lockDrivers;
111 
112  typedef std::list<std::shared_ptr<DynamicModule> > modules_t;
113  modules_t m_modules;
114 
115  typedef std::map<std::string, PVBaseInImpl*> registeredInputPVs_t;
116  registeredInputPVs_t m_registeredInputPVs;
117 
118  typedef std::map<std::string, PVBaseOutImpl*> registeredOutputPVs_t;
119  registeredOutputPVs_t m_registeredOutputPVs;
120 
121  std::recursive_mutex m_lockRegisteredPVs;
122 };
123 
131 class DynamicModule
132 {
133 public:
134  DynamicModule(const std::string& libraryName);
135  ~DynamicModule();
136 
137  void* getAddress(const std::string& functionName);
138 
139 public:
140  void* m_moduleHandle;
141 };
142 
143 
148 class Directory
149 {
150 public:
151  Directory(const std::string& directory);
152  ~Directory();
153 
154  std::string getNextFileName();
155 
156 private:
157  DIR* m_pDirectory;
158 };
159 
160 }
161 #endif // NDSFACTORYIMPL_H
std::function< void(void *)> deallocateDriver_t
Definition for the function executed to deallocate a driver.
Definition: definitions.h:244
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
Defines all the enumeration and common types used across the NDS library.
std::map< std::string, std::string > namedParameters_t
Map containing named parameters passed to the device during the initialization.
Definition: definitions.h:222