devicefactory.h
Go to the documentation of this file.
1 
2 // Copyright (c) 2003-2021 Xsens Technologies B.V. or subsidiaries worldwide.
3 // All rights reserved.
4 //
5 // Redistribution and use in source and binary forms, with or without modification,
6 // are permitted provided that the following conditions are met:
7 //
8 // 1. Redistributions of source code must retain the above copyright notice,
9 // this list of conditions, and the following disclaimer.
10 //
11 // 2. Redistributions in binary form must reproduce the above copyright notice,
12 // this list of conditions, and the following disclaimer in the documentation
13 // and/or other materials provided with the distribution.
14 //
15 // 3. Neither the names of the copyright holders nor the names of their contributors
16 // may be used to endorse or promote products derived from this software without
17 // specific prior written permission.
18 //
19 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
20 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
21 // MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
22 // THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23 // SPECIAL, EXEMPLARY OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
24 // OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
25 // HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY OR
26 // TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
27 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.THE LAWS OF THE NETHERLANDS
28 // SHALL BE EXCLUSIVELY APPLICABLE AND ANY DISPUTES SHALL BE FINALLY SETTLED UNDER THE RULES
29 // OF ARBITRATION OF THE INTERNATIONAL CHAMBER OF COMMERCE IN THE HAGUE BY ONE OR MORE
30 // ARBITRATORS APPOINTED IN ACCORDANCE WITH SAID RULES.
31 //
32 
33 
34 // Copyright (c) 2003-2021 Xsens Technologies B.V. or subsidiaries worldwide.
35 // All rights reserved.
36 //
37 // Redistribution and use in source and binary forms, with or without modification,
38 // are permitted provided that the following conditions are met:
39 //
40 // 1. Redistributions of source code must retain the above copyright notice,
41 // this list of conditions, and the following disclaimer.
42 //
43 // 2. Redistributions in binary form must reproduce the above copyright notice,
44 // this list of conditions, and the following disclaimer in the documentation
45 // and/or other materials provided with the distribution.
46 //
47 // 3. Neither the names of the copyright holders nor the names of their contributors
48 // may be used to endorse or promote products derived from this software without
49 // specific prior written permission.
50 //
51 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
52 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
53 // MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
54 // THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
55 // SPECIAL, EXEMPLARY OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
56 // OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
57 // HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY OR
58 // TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
59 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.THE LAWS OF THE NETHERLANDS
60 // SHALL BE EXCLUSIVELY APPLICABLE AND ANY DISPUTES SHALL BE FINALLY SETTLED UNDER THE RULES
61 // OF ARBITRATION OF THE INTERNATIONAL CHAMBER OF COMMERCE IN THE HAGUE BY ONE OR MORE
62 // ARBITRATORS APPOINTED IN ACCORDANCE WITH SAID RULES.
63 //
64 
65 #ifndef DEVICE_FACTORY_H
66 #define DEVICE_FACTORY_H
67 
68 #include <memory>
69 #include <map>
70 #include <xstypes/xsdeviceid.h>
71 
72 struct Communicator;
73 struct XsDevice;
74 
76 {
77 public:
78  DeviceFactory();
79  virtual ~DeviceFactory() {}
80 
82  typedef unsigned int DeviceTypeId;
83 
85  typedef XsDevice* (*MasterConstructFunc)(DeviceFactory& deviceFactory, Communicator* comm);
86 
88  typedef XsDevice* (*StandaloneConstructFunc)(Communicator* comm);
89 
90  virtual XsDevice* createMasterDevice(Communicator* communicator, bool doInitialize = true);
91 
92  virtual DeviceTypeId deviceToTypeId(XsDeviceId const& deviceId) const;
93 
94  bool registerStandaloneDeviceType(DeviceTypeId deviceTypeId, StandaloneConstructFunc constructFunc);
95  bool registerMasterDeviceType(DeviceTypeId deviceTypeId, MasterConstructFunc constructFunc);
96 
97  bool initializeDevice(XsDevice& device) const;
98 
99  virtual void removeExistingDevice(XsDeviceId const& deviceId);
100  virtual void registerDevices();
101 
102 protected:
103  virtual XsDevice* constructDevice(DeviceTypeId deviceTypeId, Communicator* comm);
104 
105  virtual bool initializeDevice(XsDevice* device) const;
106 
107 private:
108  std::map<DeviceTypeId, MasterConstructFunc> m_masterConstructors;
109  std::map<DeviceTypeId, StandaloneConstructFunc> m_standaloneConstructors;
110 };
111 
112 namespace DeviceType
113 {
115 }
116 #endif
DeviceFactory::MasterConstructFunc
XsDevice *(* MasterConstructFunc)(DeviceFactory &deviceFactory, Communicator *comm)
A function prototype that provides the device factory and communicator.
Definition: devicefactory.h:85
DeviceType
Definition: devicefactory.h:112
DeviceFactory::StandaloneConstructFunc
XsDevice *(* StandaloneConstructFunc)(Communicator *comm)
A function prototype that provides the communicator.
Definition: devicefactory.h:88
DeviceFactory::removeExistingDevice
virtual void removeExistingDevice(XsDeviceId const &deviceId)
Tell our device manager to remove any devices matching deviceId.
Definition: devicefactory.cpp:218
DeviceFactory::DeviceTypeId
unsigned int DeviceTypeId
Provides the device type ID as unsigned int.
Definition: devicefactory.h:82
DeviceFactory::deviceToTypeId
virtual DeviceTypeId deviceToTypeId(XsDeviceId const &deviceId) const
converts an XsDeviceId to an DeviceTypeId
Definition: devicefactory.cpp:189
DeviceFactory::~DeviceFactory
virtual ~DeviceFactory()
Definition: devicefactory.h:79
DeviceFactory::registerStandaloneDeviceType
bool registerStandaloneDeviceType(DeviceTypeId deviceTypeId, StandaloneConstructFunc constructFunc)
Registers a standalone device type. After registration, the factory is able to cerate an instance of ...
Definition: devicefactory.cpp:113
Communicator
A base struct for a communication interface.
Definition: communicator.h:95
DeviceFactory::createMasterDevice
virtual XsDevice * createMasterDevice(Communicator *communicator, bool doInitialize=true)
Creates and initializes a master device with a specified communicator. The type of the new device is ...
Definition: devicefactory.cpp:160
DeviceType::INVALID
static const DeviceFactory::DeviceTypeId INVALID
Definition: devicefactory.h:114
DeviceFactory::constructDevice
virtual XsDevice * constructDevice(DeviceTypeId deviceTypeId, Communicator *comm)
Constructs a master device of a specified deviceTypeId with a specified communicator....
Definition: devicefactory.cpp:127
xsdeviceid.h
XsDeviceId
Contains an Xsens device ID and provides operations for determining the type of device.
Definition: xsdeviceid.h:192
DeviceFactory::m_standaloneConstructors
std::map< DeviceTypeId, StandaloneConstructFunc > m_standaloneConstructors
Definition: devicefactory.h:109
DeviceFactory::m_masterConstructors
std::map< DeviceTypeId, MasterConstructFunc > m_masterConstructors
Definition: devicefactory.h:108
DeviceFactory::DeviceFactory
DeviceFactory()
Default constructor.
Definition: devicefactory.cpp:87
DeviceFactory::registerMasterDeviceType
bool registerMasterDeviceType(DeviceTypeId deviceTypeId, MasterConstructFunc constructFunc)
Registers a master device type. After registration, the factory is able to cerate an instance of the ...
Definition: devicefactory.cpp:98
DeviceFactory::registerDevices
virtual void registerDevices()
register all known device types
Definition: devicefactory.cpp:246
DeviceFactory::initializeDevice
bool initializeDevice(XsDevice &device) const
Initializes a device (if not already initialized)
Definition: devicefactory.cpp:239
DeviceFactory
A Factory for the devices.
Definition: devicefactory.h:75
XsDevice
Definition: xsdevice_def.h:164


xsens_mti_driver
Author(s):
autogenerated on Sun Sep 3 2023 02:43:20