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 protected:
33
34 /**
35 * Definition of a pair combining a device type with a sensor.
36 */
37 using CustomDevicePair = std::pair<Device::DeviceType, const ASensor*>;
38
39 /**
40 * Definition of an unordered map mapping names of custom devices to sensors.
41 */
42 using CustomDeviceMap = std::unordered_map<std::string, CustomDevicePair>;
43
44 public:
45
46 /**
47 * Registers this factory at the manager.
48 * Beware: Unregister this factory if not needed anymore.
49 * @return True, if this factory hasn't been registered before
50 */
51 static bool registerFactory();
52
53 /**
54 * Unregisters this factory at the manger.
55 * This unregistration should be done after all created devices have been released.
56 * @return True, if this factory could be unregistered
57 */
58 static bool unregisterFactory();
59
60 /**
61 * Registers a custom device which is otherwise unknown to this factory.
62 * @param stringType The string type of the device, must be valid
63 * @param deviceType The device type of the device, must be valid
64 * @return The name of the custom device, an empty string if the device could not be registered
65 */
66 static std::string registerCustomDevice(const std::string& stringType, const Device::DeviceType& deviceType);
67
68 /**
69 * Sends a new GPS location to the tracker which is managed by this factory.
70 * This function is intended for location information which is determined e.g., on the Java side.
71 * @param latitude The position's latitude, in degree, always valid, with range [-90, 90]
72 * @param longitude The position's longitude, in degree, must be valid, with range [-180, 180]
73 * @param altitude The position's altitude, in meter, NumericF::minValue() if unknown
74 * @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
75 * @param speed The device's speed, in meter per second, with range [0, infinity), -1 if unknown
76 * @param accuracy The horizontal accuracy as radius, in meter, with range [0, infinity), -1 if unknown
77 * @param altitudeAccuracy The vertical accuracy in meter, with range [0, infinity), -1 if unknown
78 * @param directionAccuracy The direction accuracy, in degree, with range [0, 180], -1 if unknown
79 * @param speedAccuracy The speed accuracy, in meter per second, with range [0, infinity), -1 if unknown
80 * @param timestamp The timestamp of the GPS location, must be valid
81 */
82 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);
83
84 private:
85
86 /**
87 * Creates a new factory.
88 */
90
91 /**
92 * Registers all devices.
93 */
95
96 /**
97 * Creates a new 3DOF acceleration sensor.
98 * The caller is responsible to release the sensor.
99 * @param name The name of the new device, must be valid
100 * @param deviceType The device type of the device, must be valid
101 * @return The new sensor, nullptr if the sensor could not be created
102 */
103 Device* createAndroidAccelerationSensor3DOF(const std::string& name, const Device::DeviceType& deviceType);
104
105 /**
106 * Creates a new 3DOF linear acceleration sensor.
107 * The caller is responsible to release the sensor.
108 * @param name The name of the new device, must be valid
109 * @param deviceType The device type of the device, must be valid
110 * @return The new sensor, nullptr if the sensor could not be created
111 */
112 Device* createAndroidLinearAccelerationSensor3DOF(const std::string& name, const Device::DeviceType& deviceType);
113
114 /**
115 * Creates a new 3DOF orientation tracker.
116 * The caller is responsible to release the tracker.
117 * @param name The name of the new device, must be valid
118 * @param deviceType The device type of the device, must be valid
119 * @return The new tracker, nullptr if the tracker could not be created
120 */
121 Device* createAndroidOrientationTracker3DOF(const std::string& name, const Device::DeviceType& deviceType);
122
123 /**
124 * Creates a new 3DOF raw gyro sensor.
125 * The caller is responsible to release the tracker.
126 * @param name The name of the new device, must be valid
127 * @param deviceType The device type of the device, must be valid
128 * @return The new sensor, nullptr if the sensor could not be created
129 */
130 Device* createAndroidGyroRawSensor3DOF(const std::string& name, const Device::DeviceType& deviceType);
131
132 /**
133 * Creates a new 3DOF unbiased gyro sensor.
134 * The caller is responsible to release the tracker.
135 * @param name The name of the new device, must be valid
136 * @param deviceType The device type of the device, must be valid
137 * @return The new sensor, nullptr if the sensor could not be created
138 */
139 Device* createAndroidGyroUnbiasedSensor3DOF(const std::string& name, const Device::DeviceType& deviceType);
140
141 /**
142 * Creates a new GPS tracker.
143 * The caller is responsible to release the tracker.
144 * @param name The name of the new device, must be valid
145 * @param deviceType The device type of the device, must be valid
146 * @return The new tracker, nullptr if the tracker could not be created
147 */
148 Device* createAndroidGPSTracker(const std::string& name, const Device::DeviceType& deviceType);
149
150 /**
151 * Creates a new 3DOF gravity tracker.
152 * The caller is responsible to release the tracker.
153 * @param name The name of the new device, must be valid
154 * @param deviceType The device type of the device, must be valid
155 * @return The new tracker, nullptr if the tracker could not be created
156 */
157 Device* createAndroidGravityTracker3DOF(const std::string& name, const Device::DeviceType& deviceType);
158
159 /**
160 * Creates a new 3DOF heading tracker.
161 * The caller is responsible to release the tracker.
162 * @param name The name of the new device, must be valid
163 * @param deviceType The device type of the device, must be valid
164 * @return The new tracker, nullptr if the tracker could not be created
165 */
166 Device* createAndroidHeadingTracker3DOF(const std::string& name, const Device::DeviceType& deviceType);
167
168 Device* createCustomDevice(const std::string& name, const Device::DeviceType& deviceType);
169
170 /**
171 * Registers a custom device which is otherwise unknown to this factory.
172 * @param deviceName The name of the device, must be valid
173 * @param stringType The string type of the device, must be valid
174 * @param deviceType The device type of the device, must be valid
175 * @return True, if the device could be registered
176 */
177 bool registerCustomDevice(const std::string& deviceName, const std::string& stringType, const Device::DeviceType& deviceType);
178
179 private:
180
181 /// The accelerometer sensor.
182 const ASensor* sensorAccelerometer_ = nullptr;
183
184 /// The linear accelerometer sensor.
185 const ASensor* sensorLinearAccelerometer_ = nullptr;
186
187 /// The rotation vector sensor.
188 const ASensor* sensorRotationVector_ = nullptr;
189
190 /// The game rotation vector sensor, this sensor does not use a magnetometer to avoid issues with changing magnetic fields near metal objects.
191 const ASensor* sensorGameRotationVector_ = nullptr;
192
193 /// The raw gyro sensor.
194 const ASensor* sensorGyroRaw_ = nullptr;
195
196 /// The unbiased gyro sensor.
197 const ASensor* sensorGyroUnbiased_ = nullptr;
198
199 /// The gravity sensor.
200 const ASensor* sensorGravity_ = nullptr;
201
202 /// The custom devices.
204
205 /// The factory's lock.
207};
208
209}
210
211}
212
213}
214
215#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:206
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:203
std::unordered_map< std::string, CustomDevicePair > CustomDeviceMap
Definition of an unordered map mapping names of custom devices to sensors.
Definition AndroidFactory.h:42
std::pair< Device::DeviceType, const ASensor * > CustomDevicePair
Definition of a pair combining a device type with a sensor.
Definition AndroidFactory.h:37
Device * createAndroidGyroUnbiasedSensor3DOF(const std::string &name, const Device::DeviceType &deviceType)
Creates a new 3DOF unbiased gyro sensor.
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 implements a timestamp.
Definition Timestamp.h:36
The namespace covering the entire Ocean framework.
Definition Accessor.h:15