8 #ifndef META_OCEAN_SYSTEM_USB_ANDROID_OCEAN_USB_MANAGER_H
9 #define META_OCEAN_SYSTEM_USB_ANDROID_OCEAN_USB_MANAGER_H
65 inline bool isValid()
const;
79 unsigned int vendorId_ = 0u;
82 unsigned int productId_ = 0u;
85 unsigned int deviceClass_ = 0u;
88 unsigned int deviceSubclass_ = 0u;
91 unsigned int deviceProtocol_ = 0u;
169 bool hasPermission(JNIEnv* jniEnv,
const std::string& deviceName,
bool& permissionGranted);
191 bool openDevice(JNIEnv* jniEnv,
const std::string& deviceName, int64_t& fileDescriptor);
232 uint32_t uniqueRequestIdCounter_ = 0u;
void Java_com_meta_ocean_system_usb_android_OceanUSBManager_onDevicePermission(JNIEnv *env, jobject javaThis, jstring deviceName, jboolean granted)
Native interface function for device permission events.
bool Java_com_meta_ocean_system_usb_android_OceanUSBManager_initialize(JNIEnv *env, jobject javaThis)
Native interface function to initialize the manager, this function should be called from the main thr...
This class implements a recursive lock object.
Definition: Lock.h:31
This template class is the base class for all singleton objects.
Definition: Singleton.h:71
This class holds the relevant information of a USB device.
Definition: OceanUSBManager.h:47
std::string toString() const
Returns the device information as a string.
std::string deviceName_
The device's name as defined by the system (may not be human readable).
Definition: OceanUSBManager.h:70
bool isValid() const
Returns whether this object holds valid device information.
Definition: OceanUSBManager.h:238
DeviceDescriptor()=default
Default constructor creating an invalid object.
std::string manufacturerName_
The manufacturer name of the device (human readable), empty if unknown.
Definition: OceanUSBManager.h:76
unsigned int vendorId_
The vendor id of the device.
Definition: OceanUSBManager.h:79
unsigned int productId_
The product id of the device.
Definition: OceanUSBManager.h:82
std::string productName_
The product name of the device (human readable).
Definition: OceanUSBManager.h:73
This class implements the native version of the USB manager for Android.
Definition: OceanUSBManager.h:37
OceanUSBManager()=default
Creates a default manager object which is not yet initialized.
std::pair< uint32_t, std::string > DevicePair
Definition of a pair combining a unique id with a device name.
Definition: OceanUSBManager.h:109
bool enumerateDevices(JNIEnv *jniEnv, DeviceDescriptors &deviceDescriptors, const unsigned int deviceClass=(unsigned int)(-1))
Enumerates all currently available USB devices.
Lock lock_
The manager's lock.
Definition: OceanUSBManager.h:235
bool initialize(JNIEnv *jniEnv)
Initializes the manager.
std::pair< uint32_t, PermissionCallback > PermissionCallbackPair
Definition of a pair combining a unique id with a permission callback.
Definition: OceanUSBManager.h:121
Platform::Android::ScopedJClass javaClassOceanUSBManager_
The JNI class object of the Java OceanUSBManager class, invalid if not yet initialized.
Definition: OceanUSBManager.h:226
bool openDevice(JNIEnv *jniEnv, const std::string &deviceName, int64_t &fileDescriptor)
Opens a specified device.
bool hasPermission(JNIEnv *jniEnv, const std::string &deviceName, bool &permissionGranted)
Returns whether the application has permission to access the specified device.
std::vector< DeviceDescriptor > DeviceDescriptors
Definition of a vector holding device descriptor objects.
Definition: OceanUSBManager.h:97
ScopedPermissionSubscription requestPermission(JNIEnv *jniEnv, const std::string &deviceName, PermissionCallback permissionCallback=nullptr)
Requests permission to access a specified device.
void onDevicePermission(const std::string &deviceName, bool granted)
Event functions for device permission events.
PermissionCallbackMap permissionCallbackMap_
The map mapping device names to permission callback functions.
Definition: OceanUSBManager.h:229
std::vector< PermissionCallbackPair > PermissionCallbackPairs
Definition of a vector holding permission callback pairs.
Definition: OceanUSBManager.h:126
std::unordered_map< std::string, PermissionCallbackPairs > PermissionCallbackMap
Definition of an unordered map mapping device names to permission callback functions.
Definition: OceanUSBManager.h:131
void releasePermissionRequest(const DevicePair &devicePair)
Releases a permission request which has been created before.
bool closeDevice(JNIEnv *jniEnv, const std::string &deviceName)
Closes a specified device.
std::function< void(const std::string &deviceName, bool granted)> PermissionCallback
Definition of a callback functio for permission events.
Definition: OceanUSBManager.h:104
bool isInitialized()
Returns whether the manager is initialized.
The namespace covering the entire Ocean framework.
Definition: Accessor.h:15