Ocean
AKFactory.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_ARKIT_AK_FACTORY_H
9 #define META_OCEAN_DEVICES_ARKIT_AK_FACTORY_H
10 
12 
13 #include "ocean/base/Thread.h"
14 
15 #include "ocean/devices/Factory.h"
17 
18 namespace Ocean
19 {
20 
21 namespace Devices
22 {
23 
24 namespace ARKit
25 {
26 
27 /**
28  * This class implements a device factory for the ARKit tracking library.
29  * @ingroup devicesarkit
30  */
31 class OCEAN_DEVICES_ARKIT_EXPORT AKFactory : public Factory
32 {
34 
35  protected:
36 
37  /**
38  * This class implements a checker for the availability of GeoAnchors at the current location.
39  */
40  class OCEAN_DEVICES_ARKIT_EXPORT GeoAnchorAvailabilityChecker : protected Thread
41  {
42  public:
43 
44  /**
45  * Definition of individual availability states.
46  */
47  enum AvailabilityState : uint32_t
48  {
49  /// The availability is still not known.
50  AS_UNKNOWN = 0u,
51  /// Geo Anchors are know to be not available at the current location.
53  /// Geo Anchors are know to be available at the current location.
54  AS_AVAILABLE
55  };
56 
57  public:
58 
59  /**
60  * Creates a new object allowing to determine whether geo anchors are available.
61  * @param owner The owner of this object
62  */
64 
65  /**
66  * Destructs this object.
67  */
69 
70  /**
71  * Returns the availability state.
72  * @return The current availability state
73  */
74  inline AvailabilityState availabilityState() const;
75 
76  protected:
77 
78  /**
79  * The thread run function in which the availability state will be determined.
80  */
81  void threadRun() override;
82 
83  protected:
84 
85  /// The owner of this object.
87 
88  /// The checker's availability state.
89  AvailabilityState availabilityState_ = AS_UNKNOWN;
90 
91  /// The GPS tracker providing the current location.
93 
94  /// The checker's lock.
95  mutable Lock lock_;
96  };
97 
98  public:
99 
100  /**
101  * Registers this factory at the manager.
102  * Beware: Unregister this factory if not needed anymore.
103  * @return True, if this factory hasn't been registered before
104  */
105  static bool registerFactory();
106 
107  /**
108  * Unregisters this factory at the manger.
109  * This unregistration should be done after all created devices have been released.
110  * @return True, if this factory chould be unregistered
111  */
112  static bool unregisterFactory();
113 
114  private:
115 
116  /**
117  * Creates a new factory.
118  */
120 
121  /**
122  * Registers all devices.
123  */
125 
126  /**
127  * Event function which is called once the availability of geo anchors is known.
128  * @param availabilityState The known availability state, either AS_NOT_AVAILABLE or AS_AVAILABLE
129  */
131 
132  /**
133  * Creates a new 6DOF tracker.
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* createAKTracker6DOF(const std::string& name, const Device::DeviceType& deviceType);
140 
141  /**
142  * Creates a new 6DOF room plan 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 sensor, nullptr if the sensor could not be created
147  */
148  Device* createAKRoomPlanTracker6DOF(const std::string& name, const Device::DeviceType& deviceType);
149 
150  private:
151 
152  /// The checker for the availability of ARKit's Geo Anchors.
154 };
155 
157 {
158  const ScopedLock scopedLock(lock_);
159  return availabilityState_;
160 }
161 
162 }
163 
164 }
165 
166 }
167 
168 #endif // META_OCEAN_DEVICES_ARKIT_AK_FACTORY_H
This class implements a checker for the availability of GeoAnchors at the current location.
Definition: AKFactory.h:41
~GeoAnchorAvailabilityChecker() override
Destructs this object.
Lock lock_
The checker's lock.
Definition: AKFactory.h:95
GeoAnchorAvailabilityChecker(AKFactory &owner)
Creates a new object allowing to determine whether geo anchors are available.
AKFactory & owner_
The owner of this object.
Definition: AKFactory.h:86
AvailabilityState
Definition of individual availability states.
Definition: AKFactory.h:48
@ AS_NOT_AVAILABLE
Geo Anchors are know to be not available at the current location.
Definition: AKFactory.h:52
AvailabilityState availabilityState() const
Returns the availability state.
Definition: AKFactory.h:156
void threadRun() override
The thread run function in which the availability state will be determined.
AvailabilityState availabilityState_
The checker's availability state.
Definition: AKFactory.h:89
GPSTrackerRef gpsTracker_
The GPS tracker providing the current location.
Definition: AKFactory.h:92
This class implements a device factory for the ARKit tracking library.
Definition: AKFactory.h:32
static bool registerFactory()
Registers this factory at the manager.
GeoAnchorAvailabilityChecker geoAnchorAvailabilityChecker_
The checker for the availability of ARKit's Geo Anchors.
Definition: AKFactory.h:153
static bool unregisterFactory()
Unregisters this factory at the manger.
void registerDevices()
Registers all devices.
Device * createAKTracker6DOF(const std::string &name, const Device::DeviceType &deviceType)
Creates a new 6DOF tracker.
AKFactory()
Creates a new factory.
Device * createAKRoomPlanTracker6DOF(const std::string &name, const Device::DeviceType &deviceType)
Creates a new 6DOF room plan tracker.
void onKnownGeoAnchorAvailability(const GeoAnchorAvailabilityChecker::AvailabilityState availabilityState)
Event function which is called once the availability of geo anchors is known.
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 scoped lock object for recursive lock objects.
Definition: Lock.h:135
This class implements a thread.
Definition: Thread.h:115
The namespace covering the entire Ocean framework.
Definition: Accessor.h:15