Ocean
Loading...
Searching...
No Matches
AndroidFactory.h
Go to the documentation of this file.
1/*
2 * Copyright (c) Meta Platforms, Inc. and affiliates.
3 *
4 * This source code is licensed under the MIT license found in the
5 * LICENSE file in the root directory of this source tree.
6 */
7
8#ifndef META_OCEAN_DEVICES_ANDROID_ANDROID_FACTORY_H
9#define META_OCEAN_DEVICES_ANDROID_ANDROID_FACTORY_H
10
12
14
15#include <android/sensor.h>
16
17namespace Ocean
18{
19
20namespace Devices
21{
22
23namespace Android
24{
25
26/**
27 * This class implements a device factory for the Android feature based tracking system.
28 * @ingroup devicesandroid
29 */
30class OCEAN_DEVICES_ANDROID_EXPORT AndroidFactory : public Factory
31{
32 friend class AndroidSensor;
33
34 protected:
35
36 /**
37 * Definition of a pair combining a device type with a sensor.
38 */
39 using CustomDevicePair = std::pair<Device::DeviceType, const ASensor*>;
40
41 /**
42 * Definition of an unordered map mapping names of custom devices to sensors.
43 */
44 using CustomDeviceMap = std::unordered_map<std::string, CustomDevicePair>;
45
46 public:
47
48 /**
49 * Registers this factory at the manager.
50 * Beware: Unregister this factory if not needed anymore.
51 * @return True, if this factory hasn't been registered before
52 */
53 static bool registerFactory();
54
55 /**
56 * Unregisters this factory at the manger.
57 * This unregistration should be done after all created devices have been released.
58 * @return True, if this factory could be unregistered
59 */
60 static bool unregisterFactory();
61
62 /**
63 * Registers a custom device which is otherwise unknown to this factory.
64 * @param stringType The string type of the device, must be valid
65 * @param deviceType The device type of the device, must be valid
66 * @return The name of the custom device, an empty string if the device could not be registered
67 */
68 static std::string registerCustomDevice(const std::string& stringType, const Device::DeviceType& deviceType);
69
70 /**
71 * Sends a new GPS location to the tracker which is managed by this factory.
72 * This function is intended for location information which is determined e.g., on the Java side.
73 * @param latitude The position's latitude, in degree, always valid, with range [-90, 90]
74 * @param longitude The position's longitude, in degree, must be valid, with range [-180, 180]
75 * @param altitude The position's altitude, in meter, NumericF::minValue() if unknown
76 * @param direction The travel direction of the device, relative to north, in degree, north is 0 degree, east is 90 degree, with range [0, 360], -1 if unknown
77 * @param speed The device's speed, in meter per second, with range [0, infinity), -1 if unknown
78 * @param accuracy The horizontal accuracy as radius, in meter, with range [0, infinity), -1 if unknown
79 * @param altitudeAccuracy The vertical accuracy in meter, with range [0, infinity), -1 if unknown
80 * @param directionAccuracy The direction accuracy, in degree, with range [0, 180], -1 if unknown
81 * @param speedAccuracy The speed accuracy, in meter per second, with range [0, infinity), -1 if unknown
82 * @param timestamp The timestamp of the GPS location, must be valid
83 */
84 static void newGPSLocation(const double latitude, const double longitude, const float altitude, const float direction, const float speed, const float accuracy, const float altitudeAccuracy, const float directionAccuracy, const float speedAccuracy, const Timestamp& timestamp);
85
86 /**
87 * Registers a custom timestamp converter for all Android devices.
88 * @param timestampConverter The timestamp converter to be registered
89 */
90 static void registerCustomTimestampConverter(TimestampConverter&& timestampConverter);
91
92 private:
93
94 /**
95 * Creates a new factory.
96 */
98
99 /**
100 * Registers all devices.
101 */
103
104 /**
105 * Creates a new 3DOF acceleration sensor.
106 * The caller is responsible to release the sensor.
107 * @param name The name of the new device, must be valid
108 * @param deviceType The device type of the device, must be valid
109 * @return The new sensor, nullptr if the sensor could not be created
110 */
111 Device* createAndroidAccelerationSensor3DOF(const std::string& name, const Device::DeviceType& deviceType);
112
113 /**
114 * Creates a new 3DOF linear acceleration sensor.
115 * The caller is responsible to release the sensor.
116 * @param name The name of the new device, must be valid
117 * @param deviceType The device type of the device, must be valid
118 * @return The new sensor, nullptr if the sensor could not be created
119 */
120 Device* createAndroidLinearAccelerationSensor3DOF(const std::string& name, const Device::DeviceType& deviceType);
121
122 /**
123 * Creates a new 3DOF orientation tracker.
124 * The caller is responsible to release the tracker.
125 * @param name The name of the new device, must be valid
126 * @param deviceType The device type of the device, must be valid
127 * @return The new tracker, nullptr if the tracker could not be created
128 */
129 Device* createAndroidOrientationTracker3DOF(const std::string& name, const Device::DeviceType& deviceType);
130
131 /**
132 * Creates a new 3DOF raw gyro sensor.
133 * The caller is responsible to release the tracker.
134 * @param name The name of the new device, must be valid
135 * @param deviceType The device type of the device, must be valid
136 * @return The new sensor, nullptr if the sensor could not be created
137 */
138 Device* createAndroidGyroRawSensor3DOF(const std::string& name, const Device::DeviceType& deviceType);
139
140 /**
141 * Creates a new 3DOF unbiased gyro sensor.
142 * The caller is responsible to release the tracker.
143 * @param name The name of the new device, must be valid
144 * @param deviceType The device type of the device, must be valid
145 * @return The new sensor, nullptr if the sensor could not be created
146 */
147 Device* createAndroidGyroUnbiasedSensor3DOF(const std::string& name, const Device::DeviceType& deviceType);
148
149 /**
150 * Creates a new GPS tracker.
151 * The caller is responsible to release the tracker.
152 * @param name The name of the new device, must be valid
153 * @param deviceType The device type of the device, must be valid
154 * @return The new tracker, nullptr if the tracker could not be created
155 */
156 Device* createAndroidGPSTracker(const std::string& name, const Device::DeviceType& deviceType);
157
158 /**
159 * Creates a new 3DOF gravity tracker.
160 * The caller is responsible to release the tracker.
161 * @param name The name of the new device, must be valid
162 * @param deviceType The device type of the device, must be valid
163 * @return The new tracker, nullptr if the tracker could not be created
164 */
165 Device* createAndroidGravityTracker3DOF(const std::string& name, const Device::DeviceType& deviceType);
166
167 /**
168 * Creates a new 3DOF heading tracker.
169 * The caller is responsible to release the tracker.
170 * @param name The name of the new device, must be valid
171 * @param deviceType The device type of the device, must be valid
172 * @return The new tracker, nullptr if the tracker could not be created
173 */
174 Device* createAndroidHeadingTracker3DOF(const std::string& name, const Device::DeviceType& deviceType);
175
176 Device* createCustomDevice(const std::string& name, const Device::DeviceType& deviceType);
177
178 /**
179 * Registers a custom device which is otherwise unknown to this factory.
180 * @param deviceName The name of the device, must be valid
181 * @param stringType The string type of the device, must be valid
182 * @param deviceType The device type of the device, must be valid
183 * @return True, if the device could be registered
184 */
185 bool registerCustomDevice(const std::string& deviceName, const std::string& stringType, const Device::DeviceType& deviceType);
186
187 /**
188 * Returns the timestamp converter for all android devices.
189 * @return The timestamp converter
190 */
192
193 private:
194
195 /// The accelerometer sensor.
196 const ASensor* sensorAccelerometer_ = nullptr;
197
198 /// The linear accelerometer sensor.
199 const ASensor* sensorLinearAccelerometer_ = nullptr;
200
201 /// The rotation vector sensor.
202 const ASensor* sensorRotationVector_ = nullptr;
203
204 /// The game rotation vector sensor, this sensor does not use a magnetometer to avoid issues with changing magnetic fields near metal objects.
205 const ASensor* sensorGameRotationVector_ = nullptr;
206
207 /// The raw gyro sensor.
208 const ASensor* sensorGyroRaw_ = nullptr;
209
210 /// The unbiased gyro sensor.
211 const ASensor* sensorGyroUnbiased_ = nullptr;
212
213 /// The gravity sensor.
214 const ASensor* sensorGravity_ = nullptr;
215
216 /// The custom devices.
218
219 /// The factory's lock.
221};
222
223}
224
225}
226
227}
228
229#endif // META_OCEAN_DEVICES_ANDROID_ANDROID_FACTORY_H
This class implements a device factory for the Android feature based tracking system.
Definition AndroidFactory.h:31
static void newGPSLocation(const double latitude, const double longitude, const float altitude, const float direction, const float speed, const float accuracy, const float altitudeAccuracy, const float directionAccuracy, const float speedAccuracy, const Timestamp &timestamp)
Sends a new GPS location to the tracker which is managed by this factory.
static bool unregisterFactory()
Unregisters this factory at the manger.
Device * createAndroidGyroRawSensor3DOF(const std::string &name, const Device::DeviceType &deviceType)
Creates a new 3DOF raw gyro sensor.
Device * createAndroidOrientationTracker3DOF(const std::string &name, const Device::DeviceType &deviceType)
Creates a new 3DOF orientation tracker.
Device * createAndroidAccelerationSensor3DOF(const std::string &name, const Device::DeviceType &deviceType)
Creates a new 3DOF acceleration sensor.
Device * createAndroidHeadingTracker3DOF(const std::string &name, const Device::DeviceType &deviceType)
Creates a new 3DOF heading tracker.
void registerDevices()
Registers all devices.
Lock lock_
The factory's lock.
Definition AndroidFactory.h:220
static void registerCustomTimestampConverter(TimestampConverter &&timestampConverter)
Registers a custom timestamp converter for all Android devices.
Device * createAndroidGPSTracker(const std::string &name, const Device::DeviceType &deviceType)
Creates a new GPS tracker.
Device * createAndroidLinearAccelerationSensor3DOF(const std::string &name, const Device::DeviceType &deviceType)
Creates a new 3DOF linear acceleration sensor.
bool registerCustomDevice(const std::string &deviceName, const std::string &stringType, const Device::DeviceType &deviceType)
Registers a custom device which is otherwise unknown to this factory.
AndroidFactory()
Creates a new factory.
Device * createAndroidGravityTracker3DOF(const std::string &name, const Device::DeviceType &deviceType)
Creates a new 3DOF gravity tracker.
Device * createCustomDevice(const std::string &name, const Device::DeviceType &deviceType)
static bool registerFactory()
Registers this factory at the manager.
static std::string registerCustomDevice(const std::string &stringType, const Device::DeviceType &deviceType)
Registers a custom device which is otherwise unknown to this factory.
CustomDeviceMap customDeviceMap_
The custom devices.
Definition AndroidFactory.h:217
static TimestampConverter & timestampConverter()
Returns the timestamp converter for all android devices.
std::unordered_map< std::string, CustomDevicePair > CustomDeviceMap
Definition of an unordered map mapping names of custom devices to sensors.
Definition AndroidFactory.h:44
std::pair< Device::DeviceType, const ASensor * > CustomDevicePair
Definition of a pair combining a device type with a sensor.
Definition AndroidFactory.h:39
Device * createAndroidGyroUnbiasedSensor3DOF(const std::string &name, const Device::DeviceType &deviceType)
Creates a new 3DOF unbiased gyro sensor.
This class implements a sensor for the Android library.
Definition AndroidSensor.h:42
Definition of a class holding the major and minor device type.
Definition devices/Device.h:62
This class is the base class for all devices of any type.
Definition devices/Device.h:28
This class implements a factory able to create instances of devices.
Definition devices/Factory.h:28
This class implements a recursive lock object.
Definition Lock.h:31
This class is a helper class allowing to converter timestamps defined in a specific time domain to un...
Definition Timestamp.h:312
This class implements a timestamp.
Definition Timestamp.h:63
The namespace covering the entire Ocean framework.
Definition Accessor.h:15