enumerator-usbhost.cpp
Go to the documentation of this file.
1 // License: Apache 2.0. See LICENSE file in root directory.
2 // Copyright(c) 2015 Intel Corporation. All Rights Reserved.
3 
4 #ifdef RS2_USE_ANDROID_BACKEND
5 
6 #include <jni.h>
7 #include "device-usbhost.h"
8 #include "interface-usbhost.h"
9 #include "../usb/usb-device.h"
10 #include "../usb/usb-enumerator.h"
11 #include "../types.h"
12 #include "usbhost.h"
13 #include "../android/device_watcher.h"
14 
15 #include <string>
16 #include <regex>
17 #include <sstream>
18 #include <mutex>
19 
20 static std::vector<std::shared_ptr<librealsense::platform::usb_device>> _devices;
21 
22 namespace librealsense
23 {
24  namespace platform
25  {
26  std::vector<usb_device_info> usb_enumerator::query_devices_info()
27  {
28  std::vector<usb_device_info> rv;
29  for(auto&& dev : _devices)
30  {
31  auto d = std::static_pointer_cast<usb_device_usbhost>(dev);
32  auto sdi = d->get_subdevices_info();
33  rv.insert(rv.end(), sdi.begin(), sdi.end());
34  }
35  return rv;
36  }
37 
39  {
40  for(auto&& dev : _devices)
41  {
42  if(info.id == dev->get_info().id)
43  return dev;
44  }
45  return nullptr;
46  }
47  }
48 }
49 
50 extern "C" JNIEXPORT void JNICALL
51 Java_com_intel_realsense_librealsense_DeviceWatcher_nAddUsbDevice(JNIEnv *env, jclass type,
52  jstring deviceName_, jint fileDescriptor) {
53  LOG_DEBUG("AddUsbDevice, previous device count: " << _devices.size());
54  const char *deviceName = env->GetStringUTFChars(deviceName_, 0);
55  LOG_DEBUG("AddUsbDevice, adding device: " << deviceName << ", descriptor: " << fileDescriptor);
56 
57  auto handle = usb_device_new(deviceName, fileDescriptor);
58  env->ReleaseStringUTFChars(deviceName_, deviceName);
59 
60  if (handle != NULL) {
61  LOG_DEBUG("AddUsbDevice, create");
62  auto d = std::make_shared<librealsense::platform::usb_device_usbhost>(handle);
63  _devices.push_back(d);
64  }
65 
66  LOG_DEBUG("AddUsbDevice, notify");
67 
69 
70  LOG_DEBUG("AddUsbDevice, current device count: " << _devices.size());
71 }
72 
73 extern "C" JNIEXPORT void JNICALL
74 Java_com_intel_realsense_librealsense_DeviceWatcher_nRemoveUsbDevice(JNIEnv *env, jclass type,
75  jint fileDescriptor) {
76  LOG_DEBUG("RemoveUsbDevice, previous device count: " << _devices.size());
77 
78  _devices.erase(std::remove_if(_devices.begin(), _devices.end(),
79  [fileDescriptor](std::shared_ptr<librealsense::platform::usb_device> dev)
80  {
81  auto d = std::static_pointer_cast<librealsense::platform::usb_device_usbhost>(dev);
82  if(fileDescriptor == d->get_file_descriptor()){
83 // d->release();
84  LOG_DEBUG("RemoveUsbDevice, removing device: " << d->get_info().unique_id << ", descriptor: " << fileDescriptor);
85  return true;
86  }
87  return false;
88  }), _devices.end());
89 
91 
92  LOG_DEBUG("RemoveUsbDevice, current device count: " << _devices.size());
93 }
94 
95 #endif
static rs_usb_device create_usb_device(const usb_device_info &info)
static std::vector< usb_device_info > query_devices_info()
GLuint64 GLenum void * handle
Definition: glext.h:7785
d
Definition: rmse.py:171
static std::shared_ptr< device_watcher_usbhost > instance()
def info(name, value, persistent=False)
Definition: test.py:301
GLenum type
#define NULL
Definition: tinycthread.c:47
struct usb_device * usb_device_new(const char *dev_name, int fd)
Definition: usbhost.c:370
#define LOG_DEBUG(...)
Definition: src/types.h:239
std::shared_ptr< usb_device > rs_usb_device
Definition: usb-device.h:29


librealsense2
Author(s): Sergey Dorodnicov , Doron Hirshberg , Mark Horn , Reagan Lopez , Itay Carpis
autogenerated on Mon May 3 2021 02:47:14