NDS3  1.0.0
API reference manual
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
baseImpl.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 NDSBASEIMPL_H
11 #define NDSBASEIMPL_H
12 
13 #include <string>
14 #include <map>
15 #include <memory>
16 #include <array>
17 #include <set>
18 #include <mutex>
19 #include <ostream>
20 #include "nds3/definitions.h"
21 
22 
23 namespace nds
24 {
25 
26 
27 class NodeImpl;
28 class PortImpl;
29 class FactoryBaseImpl;
30 class LogStreamBufferImpl;
31 class LogStreamGetterImpl;
32 class ThreadBaseImpl;
33 
39 class NDS3_API BaseImpl: public std::enable_shared_from_this<BaseImpl>
40 {
41 protected:
42  BaseImpl(const std::string& name);
43 
44 public:
45  BaseImpl(const BaseImpl& right) = delete;
46 
47  virtual ~BaseImpl();
48 
58  void setExternalName(const std::string& externalName);
59 
66  virtual std::shared_ptr<PortImpl> getPort();
67 
73  const std::string& getComponentName() const;
74 
75  void setParent(std::shared_ptr<NodeImpl> pParent, const std::uint32_t parentLevel);
76 
77  std::shared_ptr<NodeImpl> getParent() const;
78 
79  std::uint32_t getNodeLevel() const;
80 
87  const std::string& getFullName() const;
88 
98  const std::string& getFullNameFromPort() const;
99 
105  const std::string& getFullExternalName() const;
106 
107  const std::string& getFullExternalNameFromPort() const;
108 
109 
110 
121  timespec getTimestamp() const;
122 
123  void setTimestampDelegate(getTimestampPlugin_t timestampDelegate);
124 
125  ThreadBaseImpl* runInThread(const std::string& name, threadFunction_t function);
126 
136  std::ostream& getLogger(const logLevel_t logLevel);
137 
145  bool isLogLevelEnabled(const logLevel_t logLevel) const;
146 
153  virtual void setLogLevel(const logLevel_t logLevel);
154 
163  void defineCommand(const std::string& command, const std::string& usage, const size_t numParameters, const command_t function);
164 
172  virtual void initialize(FactoryBaseImpl& controlSystem);
173 
178  virtual void deinitialize();
179 
180 
181  virtual std::string buildFullName(const FactoryBaseImpl& controlSystem) const ;
182  virtual std::string buildFullNameFromPort(const FactoryBaseImpl& controlSystem) const ;
183 
184  virtual std::string buildFullExternalName(const FactoryBaseImpl& controlSystem) const = 0;
185  virtual std::string buildFullExternalNameFromPort(const FactoryBaseImpl& controlSystem) const = 0;
186 
187 protected:
188  timespec getLocalTimestamp() const;
189 
196  virtual parameters_t commandSetLogLevel(const logLevel_t logLevel, const parameters_t& parameters);
197 
201  std::string m_name;
202 
206  std::string m_externalName;
207 
211  std::uint32_t m_nodeLevel;
212 
216  std::weak_ptr<NodeImpl> m_pParent;
217 
218  FactoryBaseImpl* m_pFactory;
219 
220  getTimestampPlugin_t m_timestampFunction;
221 
222  volatile logLevel_t m_logLevel;
223 
228  LogStreamGetterImpl* m_logStreamGetter;
229 
230  struct commandDefinition_t
231  {
232  commandDefinition_t(const std::string& command, const std::string& usage, const size_t numParameters, command_t function):
233  m_command(command), m_usage(usage), m_numParameters(numParameters), m_function(function)
234  {
235  }
236 
237  std::string m_command;
238  std::string m_usage;
239  size_t m_numParameters;
240  command_t m_function;
241  };
242 
243  typedef std::list<commandDefinition_t> commands_t;
244  commands_t m_commands;
245 
246 protected:
247  std::string m_cachedFullName;
248  std::string m_cachedFullNameFromPort;
249  std::string m_cachedFullExternalName;
250  std::string m_cahcedFullExternalNameFromPort;
251 };
252 
253 
254 }
255 
256 
257 
258 
259 
260 
261 
262 
263 
264 
265 #endif // NDSBASEIMPL_H
std::function< timespec()> getTimestampPlugin_t
Definition for a function called to retrieve a time.
Definition: definitions.h:279
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
Defines all the enumeration and common types used across the NDS library.
std::vector< std::string > parameters_t
List of strings passed as parameters to nodes' commands.
Definition: definitions.h:204