android/jni/device.cpp
Go to the documentation of this file.
1 // License: Apache 2.0. See LICENSE file in root directory.
2 // Copyright(c) 2019 Intel Corporation. All Rights Reserved.
3 
4 #include <jni.h>
5 #include <memory>
6 #include <vector>
7 #include "error.h"
8 
9 #include "../../../include/librealsense2/rs.h"
10 #include "../../../include/librealsense2/hpp/rs_device.hpp"
11 #include "../../api.h"
12 
13 extern "C" JNIEXPORT jboolean JNICALL
15  jint info) {
16  rs2_error *e = NULL;
17  auto rv = rs2_supports_device_info(reinterpret_cast<const rs2_device *>(handle),
18  static_cast<rs2_camera_info>(info), &e);
19  handle_error(env, e);
20  return rv > 0;
21 }
22 
23 extern "C" JNIEXPORT jstring JNICALL
25  jint info) {
26  rs2_error *e = NULL;
27  const char* rv = rs2_get_device_info(reinterpret_cast<const rs2_device *>(handle),
28  static_cast<rs2_camera_info>(info), &e);
29  handle_error(env, e);
30  if (NULL == rv)
31  rv = "";
32  return env->NewStringUTF(rv);
33 }
34 
35 extern "C" JNIEXPORT void JNICALL
37  rs2_delete_device(reinterpret_cast<rs2_device *>(handle));
38 }
39 
40 extern "C"
41 JNIEXPORT jlongArray JNICALL
43  rs2_error* e = nullptr;
44  std::shared_ptr<rs2_sensor_list> list(
45  rs2_query_sensors(reinterpret_cast<const rs2_device *>(handle), &e),
47  handle_error(env, e);
48 
49  auto size = rs2_get_sensors_count(list.get(), &e);
50  handle_error(env, e);
51 
52  std::vector<rs2_sensor*> sensors;
53  for (auto i = 0; i < size; i++)
54  {
55  auto s = rs2_create_sensor(list.get(), i, &e);
56  handle_error(env, e);
57  sensors.push_back(s);
58  }
59  jlongArray rv = env->NewLongArray(sensors.size());
60 
61  for (auto i = 0; i < sensors.size(); i++)
62  {
63  env->SetLongArrayRegion(rv, i, 1, reinterpret_cast<const jlong *>(&sensors[i]));
64  }
65 
66  return rv;
67 }
68 
69 extern "C"
70 JNIEXPORT void JNICALL
72  jlong handle) {
73  rs2_error *e = NULL;
74  rs2_enter_update_state(reinterpret_cast<const rs2_device *>(handle), &e);
75  handle_error(env, e);
76 }
77 
78 extern "C"
79 JNIEXPORT void JNICALL
81  jobject instance,
82  jlong handle,
83  jbyteArray image_,
84  jint update_mode) {
85  jbyte *image = env->GetByteArrayElements(image_, NULL);
86  auto length = env->GetArrayLength(image_);
87  rs2_error *e = NULL;
88  jclass cls = env->GetObjectClass(instance);
89  jmethodID id = env->GetMethodID(cls, "onProgress", "(F)V");
90  auto cb = [&](float progress){ env->CallVoidMethod(instance, id, progress); };
91  rs2_update_firmware_unsigned_cpp(reinterpret_cast<const rs2_device *>(handle), image, length,
92  new rs2::update_progress_callback<decltype(cb)>(cb), update_mode, &e);
93  handle_error(env, e);
94  env->ReleaseByteArrayElements(image_, image, 0);
95 }
96 
97 extern "C"
98 JNIEXPORT jbyteArray JNICALL
100  jlong handle) {
101  rs2_error* e = NULL;
102  jclass cls = env->GetObjectClass(instance);
103  jmethodID id = env->GetMethodID(cls, "onProgress", "(F)V");
104  auto cb = [&](float progress){ env->CallVoidMethod(instance, id, progress); };
105 
106  std::shared_ptr<const rs2_raw_data_buffer> raw_data_buffer(
107  rs2_create_flash_backup_cpp(reinterpret_cast<rs2_device *>(handle), new rs2::update_progress_callback<decltype(cb)>(cb), &e),
108  [](const rs2_raw_data_buffer* buff){ if(buff) delete buff;});
109  handle_error(env, e);
110 
111  jbyteArray rv = env->NewByteArray(raw_data_buffer->buffer.size());
112  env->SetByteArrayRegion(rv, 0, raw_data_buffer->buffer.size(),
113  reinterpret_cast<const jbyte *>(raw_data_buffer->buffer.data()));
114  return rv;
115 }
116 
117 extern "C"
118 JNIEXPORT void JNICALL
120  jlong handle,
121  jbyteArray image_) {
122  jbyte *image = env->GetByteArrayElements(image_, NULL);
123  auto length = env->GetArrayLength(image_);
124  rs2_error *e = NULL;
125  jclass cls = env->GetObjectClass(instance);
126  jmethodID id = env->GetMethodID(cls, "onProgress", "(F)V");
127  auto cb = [&](float progress){ env->CallVoidMethod(instance, id, progress); };
128  rs2_update_firmware_cpp(reinterpret_cast<const rs2_device *>(handle), image, length,
129  new rs2::update_progress_callback<decltype(cb)>(cb), &e);
130  handle_error(env, e);
131  env->ReleaseByteArrayElements(image_, image, 0);
132 }
133 
134 extern "C"
135 JNIEXPORT void JNICALL
137  jlong handle) {
138  rs2_error *e = NULL;
139  rs2_hardware_reset(reinterpret_cast<const rs2_device *>(handle), &e);
140  handle_error(env, e);
141 }
142 
143 extern "C"
144 JNIEXPORT jboolean JNICALL
146  jlong handle, jint extension) {
147  rs2_error *e = NULL;
148  int rv = rs2_is_device_extendable_to(reinterpret_cast<const rs2_device *>(handle),
149  static_cast<rs2_extension>(extension), &e);
150  handle_error(env, e);
151  return rv > 0;
152 }
int rs2_get_sensors_count(const rs2_sensor_list *info_list, rs2_error **error)
Definition: rs.cpp:267
GLdouble s
rs2_sensor * rs2_create_sensor(const rs2_sensor_list *list, int index, rs2_error **error)
Definition: rs.cpp:308
GLuint64 GLenum void * handle
Definition: glext.h:7785
void rs2_delete_device(rs2_device *device)
Definition: rs.cpp:301
JNIEXPORT void JNICALL Java_com_intel_realsense_librealsense_Updatable_nEnterUpdateState(JNIEnv *env, jclass type, jlong handle)
def progress(args)
Definition: log.py:43
JNIEXPORT jboolean JNICALL Java_com_intel_realsense_librealsense_Device_nSupportsInfo(JNIEnv *env, jclass type, jlong handle, jint info)
void handle_error(JNIEnv *env, rs2_error *error)
Definition: error.cpp:6
e
Definition: rmse.py:177
JNIEXPORT void JNICALL Java_com_intel_realsense_librealsense_Device_nRelease(JNIEnv *env, jclass type, jlong handle)
GLenum GLenum GLsizei void * image
def info(name, value, persistent=False)
Definition: test.py:301
GLsizeiptr size
int rs2_supports_device_info(const rs2_device *device, rs2_camera_info info, rs2_error **error)
Definition: rs.cpp:715
int rs2_is_device_extendable_to(const rs2_device *device, rs2_extension extension, rs2_error **error)
Definition: rs.cpp:1425
void rs2_hardware_reset(const rs2_device *device, rs2_error **error)
Definition: rs.cpp:1176
JNIEXPORT jboolean JNICALL Java_com_intel_realsense_librealsense_Device_nIsDeviceExtendableTo(JNIEnv *env, jclass type, jlong handle, jint extension)
rs2_sensor_list * rs2_query_sensors(const rs2_device *device, rs2_error **error)
Definition: rs.cpp:236
void rs2_update_firmware_cpp(const rs2_device *device, const void *fw_image, int fw_image_size, rs2_update_progress_callback *callback, rs2_error **error)
Definition: rs.cpp:2917
JNIEXPORT void JNICALL Java_com_intel_realsense_librealsense_Updatable_nUpdateFirmwareUnsigned(JNIEnv *env, jobject instance, jlong handle, jbyteArray image_, jint update_mode)
const rs2_raw_data_buffer * rs2_create_flash_backup_cpp(const rs2_device *device, rs2_update_progress_callback *callback, rs2_error **error)
Definition: rs.cpp:2954
GLenum type
void rs2_enter_update_state(const rs2_device *device, rs2_error **error)
Definition: rs.cpp:3041
JNIEXPORT void JNICALL Java_com_intel_realsense_librealsense_UpdateDevice_nUpdateFirmware(JNIEnv *env, jobject instance, jlong handle, jbyteArray image_)
void rs2_update_firmware_unsigned_cpp(const rs2_device *device, const void *fw_image, int fw_image_size, rs2_update_progress_callback *callback, int update_mode, rs2_error **error)
Definition: rs.cpp:2996
void rs2_delete_sensor_list(rs2_sensor_list *info_list)
Definition: rs.cpp:282
#define NULL
Definition: tinycthread.c:47
JNIEXPORT void JNICALL Java_com_intel_realsense_librealsense_Device_nHardwareReset(JNIEnv *env, jclass type, jlong handle)
int i
GLenum GLuint GLenum GLsizei length
JNIEXPORT jstring JNICALL Java_com_intel_realsense_librealsense_Device_nGetInfo(JNIEnv *env, jclass type, jlong handle, jint info)
JNIEXPORT jbyteArray JNICALL Java_com_intel_realsense_librealsense_Updatable_nCreateFlashBackup(JNIEnv *env, jobject instance, jlong handle)
JNIEXPORT jlongArray JNICALL Java_com_intel_realsense_librealsense_Device_nQuerySensors(JNIEnv *env, jclass type, jlong handle)
const char * rs2_get_device_info(const rs2_device *device, rs2_camera_info info, rs2_error **error)
Definition: rs.cpp:703


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