BeeeOn Gateway  v2020.3.1-2-g6f737dc
Platform to interconnect the IoT world
SpecificZWaveMapperRegistry.h
1 #pragma once
2 
3 #include <map>
4 #include <string>
5 
6 #include <Poco/SharedPtr.h>
7 #include <Poco/Instantiator.h>
8 
9 #include "util/Loggable.h"
10 #include "zwave/ZWaveMapperRegistry.h"
11 
12 namespace BeeeOn {
13 
21 public:
23 
24  Mapper::Ptr resolve(const ZWaveNode &node) override;
25 
31  void setSpecMap(const std::map<std::string, std::string> &specMap);
32 
33 protected:
37  struct Spec {
38  const uint16_t vendor;
39  const uint16_t product;
40 
41  bool operator <(const Spec &other) const;
42  std::string toString() const;
43  static Spec parse(const std::string &input);
44  };
45 
50  public:
51  typedef Poco::SharedPtr<MapperInstantiator> Ptr;
52 
53  virtual ~MapperInstantiator();
54 
55  virtual Mapper::Ptr create(const ZWaveNode &node) = 0;
56  };
57 
63  template <typename MapperType>
65  public:
66  Mapper::Ptr create(const ZWaveNode &node) override
67  {
68  return new MapperType(node.id(), node.product());
69  }
70  };
71 
80  const std::string &name,
81  MapperInstantiator::Ptr instantiator);
82 
83 private:
84  typedef std::map<std::string, MapperInstantiator::Ptr> InstantiatorsMap;
85  InstantiatorsMap m_instantiators;
86  std::map<Spec, InstantiatorsMap::iterator> m_specMap;
87 };
88 
89 }
SpecificZWaveMapperRegistry implements the method resolve() generically. The subclass of SpecificZWav...
Definition: SpecificZWaveMapperRegistry.h:20
ZWaveMapperRegistry is mostly intended to map Z-Wave specific data type hierarchy to BeeeOn ModuleTyp...
Definition: ZWaveMapperRegistry.h:22
void registerInstantiator(const std::string &name, MapperInstantiator::Ptr instantiator)
The subclass would call this method for each instantiator type it offers. The name of instantiator is...
Definition: SpecificZWaveMapperRegistry.cpp:94
std::string product() const
Definition: ZWaveNode.cpp:313
Specification of a Z-Wave node to match.
Definition: SpecificZWaveMapperRegistry.h:37
Instantiator of specific Mapper implementations.
Definition: SpecificZWaveMapperRegistry.h:49
Mapper::Ptr resolve(const ZWaveNode &node) override
Try to resolve a Mapper implementation suitable for the given Z-Wave node.
Definition: SpecificZWaveMapperRegistry.cpp:56
ZWaveNode represents information from the Z-Wave network about a particular node. Each Z-Wave node is...
Definition: ZWaveNode.h:22
Definition: Loggable.h:19
const Identity & id() const
Definition: ZWaveNode.cpp:278
void setSpecMap(const std::map< std::string, std::string > &specMap)
Set the spec mapping where the map key is a string in form: VENDOR:PRODUCT and the value is the name ...
Definition: SpecificZWaveMapperRegistry.cpp:71
Template implementation of MapperInstantiator creating MapperType instances having constructor specif...
Definition: SpecificZWaveMapperRegistry.h:64