Skip to main content

ri/java/classes/
device.rs

1//! Copyright © 2025-2026 Wenze Wei. All Rights Reserved.
2//!
3//! This file is part of Ri.
4//! The Ri project belongs to the Dunimd Team.
5//!
6//! Licensed under the Apache License, Version 2.0 (the "License");
7//! You may not use this file except in compliance with the License.
8//! You may obtain a copy of the License at
9//!
10//!     http://www.apache.org/licenses/LICENSE-2.0
11//!
12//! Unless required by applicable law or agreed to in writing, software
13//! distributed under the License is distributed on an "AS IS" BASIS,
14//! WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15//! See the License for the specific language governing permissions and
16//! limitations under the License.
17
18//! # Device Module JNI Bindings
19//!
20//! JNI bindings for Ri device classes.
21
22use jni::JNIEnv;
23use jni::objects::{JClass, JString, JObject};
24use jni::sys::{jlong, jboolean, jint, jdouble, jstring, jlongArray, jobjectArray};
25use crate::device::{
26    RiDeviceControlModule, RiDeviceControlConfig, RiDevice, RiDeviceType, RiDeviceStatus,
27    RiDeviceCapabilities, RiDeviceHealthMetrics, RiDeviceConfig, RiNetworkDeviceInfo,
28    RiDiscoveryResult, RiResourceRequest, RiResourceAllocation, RiDeviceSchedulingConfig,
29};
30use crate::java::exception::check_not_null;
31
32// =============================================================================
33// RiDeviceControlModule JNI Bindings
34// =============================================================================
35
36#[no_mangle]
37pub extern "system" fn Java_com_dunimd_ri_device_RiDeviceControlModule_new0(
38    mut env: JNIEnv,
39    _class: JClass,
40    config_ptr: jlong,
41) -> jlong {
42    if !check_not_null(&mut env, config_ptr, "RiDeviceControlConfig") {
43        return 0;
44    }
45    0
46}
47
48#[no_mangle]
49pub extern "system" fn Java_com_dunimd_ri_device_RiDeviceControlModule_free0(
50    _env: JNIEnv,
51    _class: JClass,
52    ptr: jlong,
53) {
54    if ptr != 0 {
55        unsafe {
56            let _ = Box::from_raw(ptr as *mut RiDeviceControlModule);
57        }
58    }
59}
60
61// =============================================================================
62// RiDeviceControlConfig JNI Bindings
63// =============================================================================
64
65#[no_mangle]
66pub extern "system" fn Java_com_dunimd_ri_device_RiDeviceControlConfig_new0(
67    _env: JNIEnv,
68    _class: JClass,
69) -> jlong {
70    let config = Box::new(RiDeviceControlConfig::default());
71    Box::into_raw(config) as jlong
72}
73
74#[no_mangle]
75pub extern "system" fn Java_com_dunimd_ri_device_RiDeviceControlConfig_free0(
76    _env: JNIEnv,
77    _class: JClass,
78    ptr: jlong,
79) {
80    if ptr != 0 {
81        unsafe {
82            let _ = Box::from_raw(ptr as *mut RiDeviceControlConfig);
83        }
84    }
85}
86
87// =============================================================================
88// RiDevice JNI Bindings
89// =============================================================================
90
91#[no_mangle]
92pub extern "system" fn Java_com_dunimd_ri_device_RiDevice_new0(
93    mut env: JNIEnv,
94    _class: JClass,
95    name: JString,
96    device_type: jint,
97) -> jlong {
98    let name_str: String = env.get_string(&name)
99        .expect("Failed to get name")
100        .into();
101    
102    let dtype = match device_type {
103        0 => RiDeviceType::CPU,
104        1 => RiDeviceType::GPU,
105        2 => RiDeviceType::Memory,
106        3 => RiDeviceType::Storage,
107        4 => RiDeviceType::Network,
108        5 => RiDeviceType::Sensor,
109        6 => RiDeviceType::Actuator,
110        _ => RiDeviceType::Custom,
111    };
112    
113    let device = Box::new(RiDevice::new(name_str, dtype));
114    Box::into_raw(device) as jlong
115}
116
117#[no_mangle]
118pub extern "system" fn Java_com_dunimd_ri_device_RiDevice_getId0<'local>(
119    mut env: JNIEnv<'local>,
120    _class: JClass<'local>,
121    ptr: jlong,
122) -> jstring {
123    if !check_not_null(&mut env, ptr, "RiDevice") {
124        return std::ptr::null_mut();
125    }
126    
127    let device = unsafe { &*(ptr as *const RiDevice) };
128    env.new_string(device.id()).unwrap().into_raw()
129}
130
131#[no_mangle]
132pub extern "system" fn Java_com_dunimd_ri_device_RiDevice_getName0<'local>(
133    mut env: JNIEnv<'local>,
134    _class: JClass<'local>,
135    ptr: jlong,
136) -> jstring {
137    if !check_not_null(&mut env, ptr, "RiDevice") {
138        return std::ptr::null_mut();
139    }
140    
141    let device = unsafe { &*(ptr as *const RiDevice) };
142    env.new_string(device.name()).unwrap().into_raw()
143}
144
145#[no_mangle]
146pub extern "system" fn Java_com_dunimd_ri_device_RiDevice_getDeviceType0(
147    mut env: JNIEnv,
148    _class: JClass,
149    ptr: jlong,
150) -> jint {
151    if !check_not_null(&mut env, ptr, "RiDevice") {
152        return 0;
153    }
154    
155    let device = unsafe { &*(ptr as *const RiDevice) };
156    device.device_type() as jint
157}
158
159#[no_mangle]
160pub extern "system" fn Java_com_dunimd_ri_device_RiDevice_getStatus0(
161    mut env: JNIEnv,
162    _class: JClass,
163    ptr: jlong,
164) -> jint {
165    if !check_not_null(&mut env, ptr, "RiDevice") {
166        return 0;
167    }
168    
169    let device = unsafe { &*(ptr as *const RiDevice) };
170    device.status() as jint
171}
172
173#[no_mangle]
174pub extern "system" fn Java_com_dunimd_ri_device_RiDevice_setStatus0(
175    mut env: JNIEnv,
176    _class: JClass,
177    ptr: jlong,
178    status: jint,
179) {
180    if !check_not_null(&mut env, ptr, "RiDevice") {
181        return;
182    }
183    
184    let device = unsafe { &mut *(ptr as *mut RiDevice) };
185    let status_val = match status {
186        0 => RiDeviceStatus::Unknown,
187        1 => RiDeviceStatus::Available,
188        2 => RiDeviceStatus::Busy,
189        3 => RiDeviceStatus::Error,
190        4 => RiDeviceStatus::Offline,
191        5 => RiDeviceStatus::Maintenance,
192        6 => RiDeviceStatus::Degraded,
193        _ => RiDeviceStatus::Allocated,
194    };
195    device.set_status(status_val);
196}
197
198#[no_mangle]
199pub extern "system" fn Java_com_dunimd_ri_device_RiDevice_getCapabilities0(
200    mut env: JNIEnv,
201    _class: JClass,
202    ptr: jlong,
203) -> jlong {
204    if !check_not_null(&mut env, ptr, "RiDevice") {
205        return 0;
206    }
207    
208    let device = unsafe { &*(ptr as *const RiDevice) };
209    let capabilities = Box::new(device.capabilities().clone());
210    Box::into_raw(capabilities) as jlong
211}
212
213#[no_mangle]
214pub extern "system" fn Java_com_dunimd_ri_device_RiDevice_setCapabilities0(
215    mut env: JNIEnv,
216    _class: JClass,
217    ptr: jlong,
218    capabilities_ptr: jlong,
219) {
220    if !check_not_null(&mut env, ptr, "RiDevice") || !check_not_null(&mut env, capabilities_ptr, "RiDeviceCapabilities") {
221        return;
222    }
223    
224    let device = unsafe { &mut *(ptr as *mut RiDevice) };
225    let capabilities = unsafe { &*(capabilities_ptr as *const RiDeviceCapabilities) };
226    let _ = device.clone().with_capabilities(capabilities.clone());
227}
228
229#[no_mangle]
230pub extern "system" fn Java_com_dunimd_ri_device_RiDevice_getHealthMetrics0(
231    mut env: JNIEnv,
232    _class: JClass,
233    ptr: jlong,
234) -> jlong {
235    if !check_not_null(&mut env, ptr, "RiDevice") {
236        return 0;
237    }
238    
239    let device = unsafe { &*(ptr as *const RiDevice) };
240    let metrics = Box::new(device.health_metrics().clone());
241    Box::into_raw(metrics) as jlong
242}
243
244#[no_mangle]
245pub extern "system" fn Java_com_dunimd_ri_device_RiDevice_isAvailable0(
246    mut env: JNIEnv,
247    _class: JClass,
248    ptr: jlong,
249) -> jboolean {
250    if !check_not_null(&mut env, ptr, "RiDevice") {
251        return 0;
252    }
253    
254    let device = unsafe { &*(ptr as *const RiDevice) };
255    device.is_available() as jboolean
256}
257
258#[no_mangle]
259pub extern "system" fn Java_com_dunimd_ri_device_RiDevice_isAllocated0(
260    mut env: JNIEnv,
261    _class: JClass,
262    ptr: jlong,
263) -> jboolean {
264    if !check_not_null(&mut env, ptr, "RiDevice") {
265        return 0;
266    }
267    
268    let device = unsafe { &*(ptr as *const RiDevice) };
269    device.is_allocated() as jboolean
270}
271
272#[no_mangle]
273pub extern "system" fn Java_com_dunimd_ri_device_RiDevice_getHealthScore0(
274    mut env: JNIEnv,
275    _class: JClass,
276    ptr: jlong,
277) -> jint {
278    if !check_not_null(&mut env, ptr, "RiDevice") {
279        return 0;
280    }
281    
282    let device = unsafe { &*(ptr as *const RiDevice) };
283    device.health_score() as jint
284}
285
286#[no_mangle]
287pub extern "system" fn Java_com_dunimd_ri_device_RiDevice_free0(
288    _env: JNIEnv,
289    _class: JClass,
290    ptr: jlong,
291) {
292    if ptr != 0 {
293        unsafe {
294            let _ = Box::from_raw(ptr as *mut RiDevice);
295        }
296    }
297}
298
299// =============================================================================
300// RiDeviceCapabilities JNI Bindings
301// =============================================================================
302
303#[no_mangle]
304pub extern "system" fn Java_com_dunimd_ri_device_RiDeviceCapabilities_new0(
305    _env: JNIEnv,
306    _class: JClass,
307) -> jlong {
308    let capabilities = Box::new(RiDeviceCapabilities::new());
309    Box::into_raw(capabilities) as jlong
310}
311
312#[no_mangle]
313pub extern "system" fn Java_com_dunimd_ri_device_RiDeviceCapabilities_getComputeUnits0(
314    mut env: JNIEnv,
315    _class: JClass,
316    ptr: jlong,
317) -> jint {
318    if !check_not_null(&mut env, ptr, "RiDeviceCapabilities") {
319        return -1;
320    }
321    
322    let capabilities = unsafe { &*(ptr as *const RiDeviceCapabilities) };
323    capabilities.compute_units.map(|v| v as jint).unwrap_or(-1)
324}
325
326#[no_mangle]
327pub extern "system" fn Java_com_dunimd_ri_device_RiDeviceCapabilities_setComputeUnits0(
328    mut env: JNIEnv,
329    _class: JClass,
330    ptr: jlong,
331    units: jint,
332) {
333    if !check_not_null(&mut env, ptr, "RiDeviceCapabilities") {
334        return;
335    }
336    
337    let capabilities = unsafe { &mut *(ptr as *mut RiDeviceCapabilities) };
338    capabilities.compute_units = Some(units as usize);
339}
340
341#[no_mangle]
342pub extern "system" fn Java_com_dunimd_ri_device_RiDeviceCapabilities_getMemoryGb0(
343    mut env: JNIEnv,
344    _class: JClass,
345    ptr: jlong,
346) -> jdouble {
347    if !check_not_null(&mut env, ptr, "RiDeviceCapabilities") {
348        return -1.0;
349    }
350    
351    let capabilities = unsafe { &*(ptr as *const RiDeviceCapabilities) };
352    capabilities.memory_gb.unwrap_or(-1.0)
353}
354
355#[no_mangle]
356pub extern "system" fn Java_com_dunimd_ri_device_RiDeviceCapabilities_setMemoryGb0(
357    mut env: JNIEnv,
358    _class: JClass,
359    ptr: jlong,
360    memory_gb: jdouble,
361) {
362    if !check_not_null(&mut env, ptr, "RiDeviceCapabilities") {
363        return;
364    }
365    
366    let capabilities = unsafe { &mut *(ptr as *mut RiDeviceCapabilities) };
367    capabilities.memory_gb = Some(memory_gb);
368}
369
370#[no_mangle]
371pub extern "system" fn Java_com_dunimd_ri_device_RiDeviceCapabilities_getStorageGb0(
372    mut env: JNIEnv,
373    _class: JClass,
374    ptr: jlong,
375) -> jdouble {
376    if !check_not_null(&mut env, ptr, "RiDeviceCapabilities") {
377        return -1.0;
378    }
379    
380    let capabilities = unsafe { &*(ptr as *const RiDeviceCapabilities) };
381    capabilities.storage_gb.unwrap_or(-1.0)
382}
383
384#[no_mangle]
385pub extern "system" fn Java_com_dunimd_ri_device_RiDeviceCapabilities_setStorageGb0(
386    mut env: JNIEnv,
387    _class: JClass,
388    ptr: jlong,
389    storage_gb: jdouble,
390) {
391    if !check_not_null(&mut env, ptr, "RiDeviceCapabilities") {
392        return;
393    }
394    
395    let capabilities = unsafe { &mut *(ptr as *mut RiDeviceCapabilities) };
396    capabilities.storage_gb = Some(storage_gb);
397}
398
399#[no_mangle]
400pub extern "system" fn Java_com_dunimd_ri_device_RiDeviceCapabilities_getBandwidthGbps0(
401    mut env: JNIEnv,
402    _class: JClass,
403    ptr: jlong,
404) -> jdouble {
405    if !check_not_null(&mut env, ptr, "RiDeviceCapabilities") {
406        return -1.0;
407    }
408    
409    let capabilities = unsafe { &*(ptr as *const RiDeviceCapabilities) };
410    capabilities.bandwidth_gbps.unwrap_or(-1.0)
411}
412
413#[no_mangle]
414pub extern "system" fn Java_com_dunimd_ri_device_RiDeviceCapabilities_setBandwidthGbps0(
415    mut env: JNIEnv,
416    _class: JClass,
417    ptr: jlong,
418    bandwidth_gbps: jdouble,
419) {
420    if !check_not_null(&mut env, ptr, "RiDeviceCapabilities") {
421        return;
422    }
423    
424    let capabilities = unsafe { &mut *(ptr as *mut RiDeviceCapabilities) };
425    capabilities.bandwidth_gbps = Some(bandwidth_gbps);
426}
427
428#[no_mangle]
429pub extern "system" fn Java_com_dunimd_ri_device_RiDeviceCapabilities_meetsRequirements0(
430    mut env: JNIEnv,
431    _class: JClass,
432    ptr: jlong,
433    requirements_ptr: jlong,
434) -> jboolean {
435    if !check_not_null(&mut env, ptr, "RiDeviceCapabilities") || !check_not_null(&mut env, requirements_ptr, "RiDeviceCapabilities") {
436        return 0;
437    }
438    
439    let capabilities = unsafe { &*(ptr as *const RiDeviceCapabilities) };
440    let requirements = unsafe { &*(requirements_ptr as *const RiDeviceCapabilities) };
441    capabilities.meets_requirements(requirements) as jboolean
442}
443
444#[no_mangle]
445pub extern "system" fn Java_com_dunimd_ri_device_RiDeviceCapabilities_free0(
446    _env: JNIEnv,
447    _class: JClass,
448    ptr: jlong,
449) {
450    if ptr != 0 {
451        unsafe {
452            let _ = Box::from_raw(ptr as *mut RiDeviceCapabilities);
453        }
454    }
455}
456
457// =============================================================================
458// RiDeviceHealthMetrics JNI Bindings
459// =============================================================================
460
461#[no_mangle]
462pub extern "system" fn Java_com_dunimd_ri_device_RiDeviceHealthMetrics_new0(
463    _env: JNIEnv,
464    _class: JClass,
465) -> jlong {
466    let metrics = Box::new(RiDeviceHealthMetrics::default());
467    Box::into_raw(metrics) as jlong
468}
469
470#[no_mangle]
471pub extern "system" fn Java_com_dunimd_ri_device_RiDeviceHealthMetrics_getCpuUsagePercent0(
472    mut env: JNIEnv,
473    _class: JClass,
474    ptr: jlong,
475) -> jdouble {
476    if !check_not_null(&mut env, ptr, "RiDeviceHealthMetrics") {
477        return 0.0;
478    }
479    
480    let metrics = unsafe { &*(ptr as *const RiDeviceHealthMetrics) };
481    metrics.cpu_usage_percent
482}
483
484#[no_mangle]
485pub extern "system" fn Java_com_dunimd_ri_device_RiDeviceHealthMetrics_setCpuUsagePercent0(
486    mut env: JNIEnv,
487    _class: JClass,
488    ptr: jlong,
489    percent: jdouble,
490) {
491    if !check_not_null(&mut env, ptr, "RiDeviceHealthMetrics") {
492        return;
493    }
494    
495    let metrics = unsafe { &mut *(ptr as *mut RiDeviceHealthMetrics) };
496    metrics.cpu_usage_percent = percent;
497}
498
499#[no_mangle]
500pub extern "system" fn Java_com_dunimd_ri_device_RiDeviceHealthMetrics_getMemoryUsagePercent0(
501    mut env: JNIEnv,
502    _class: JClass,
503    ptr: jlong,
504) -> jdouble {
505    if !check_not_null(&mut env, ptr, "RiDeviceHealthMetrics") {
506        return 0.0;
507    }
508    
509    let metrics = unsafe { &*(ptr as *const RiDeviceHealthMetrics) };
510    metrics.memory_usage_percent
511}
512
513#[no_mangle]
514pub extern "system" fn Java_com_dunimd_ri_device_RiDeviceHealthMetrics_setMemoryUsagePercent0(
515    mut env: JNIEnv,
516    _class: JClass,
517    ptr: jlong,
518    percent: jdouble,
519) {
520    if !check_not_null(&mut env, ptr, "RiDeviceHealthMetrics") {
521        return;
522    }
523    
524    let metrics = unsafe { &mut *(ptr as *mut RiDeviceHealthMetrics) };
525    metrics.memory_usage_percent = percent;
526}
527
528#[no_mangle]
529pub extern "system" fn Java_com_dunimd_ri_device_RiDeviceHealthMetrics_getTemperatureCelsius0(
530    mut env: JNIEnv,
531    _class: JClass,
532    ptr: jlong,
533) -> jdouble {
534    if !check_not_null(&mut env, ptr, "RiDeviceHealthMetrics") {
535        return 0.0;
536    }
537    
538    let metrics = unsafe { &*(ptr as *const RiDeviceHealthMetrics) };
539    metrics.temperature_celsius
540}
541
542#[no_mangle]
543pub extern "system" fn Java_com_dunimd_ri_device_RiDeviceHealthMetrics_setTemperatureCelsius0(
544    mut env: JNIEnv,
545    _class: JClass,
546    ptr: jlong,
547    temperature: jdouble,
548) {
549    if !check_not_null(&mut env, ptr, "RiDeviceHealthMetrics") {
550        return;
551    }
552    
553    let metrics = unsafe { &mut *(ptr as *mut RiDeviceHealthMetrics) };
554    metrics.temperature_celsius = temperature;
555}
556
557#[no_mangle]
558pub extern "system" fn Java_com_dunimd_ri_device_RiDeviceHealthMetrics_getErrorCount0(
559    mut env: JNIEnv,
560    _class: JClass,
561    ptr: jlong,
562) -> jlong {
563    if !check_not_null(&mut env, ptr, "RiDeviceHealthMetrics") {
564        return 0;
565    }
566    
567    let metrics = unsafe { &*(ptr as *const RiDeviceHealthMetrics) };
568    metrics.error_count as jlong
569}
570
571#[no_mangle]
572pub extern "system" fn Java_com_dunimd_ri_device_RiDeviceHealthMetrics_setErrorCount0(
573    mut env: JNIEnv,
574    _class: JClass,
575    ptr: jlong,
576    count: jlong,
577) {
578    if !check_not_null(&mut env, ptr, "RiDeviceHealthMetrics") {
579        return;
580    }
581    
582    let metrics = unsafe { &mut *(ptr as *mut RiDeviceHealthMetrics) };
583    metrics.error_count = count as u32;
584}
585
586#[no_mangle]
587pub extern "system" fn Java_com_dunimd_ri_device_RiDeviceHealthMetrics_getThroughput0(
588    mut env: JNIEnv,
589    _class: JClass,
590    ptr: jlong,
591) -> jlong {
592    if !check_not_null(&mut env, ptr, "RiDeviceHealthMetrics") {
593        return 0;
594    }
595    
596    let metrics = unsafe { &*(ptr as *const RiDeviceHealthMetrics) };
597    metrics.throughput as jlong
598}
599
600#[no_mangle]
601pub extern "system" fn Java_com_dunimd_ri_device_RiDeviceHealthMetrics_setThroughput0(
602    mut env: JNIEnv,
603    _class: JClass,
604    ptr: jlong,
605    throughput: jlong,
606) {
607    if !check_not_null(&mut env, ptr, "RiDeviceHealthMetrics") {
608        return;
609    }
610    
611    let metrics = unsafe { &mut *(ptr as *mut RiDeviceHealthMetrics) };
612    metrics.throughput = throughput as u64;
613}
614
615#[no_mangle]
616pub extern "system" fn Java_com_dunimd_ri_device_RiDeviceHealthMetrics_getNetworkLatencyMs0(
617    mut env: JNIEnv,
618    _class: JClass,
619    ptr: jlong,
620) -> jdouble {
621    if !check_not_null(&mut env, ptr, "RiDeviceHealthMetrics") {
622        return 0.0;
623    }
624    
625    let metrics = unsafe { &*(ptr as *const RiDeviceHealthMetrics) };
626    metrics.network_latency_ms
627}
628
629#[no_mangle]
630pub extern "system" fn Java_com_dunimd_ri_device_RiDeviceHealthMetrics_setNetworkLatencyMs0(
631    mut env: JNIEnv,
632    _class: JClass,
633    ptr: jlong,
634    latency_ms: jdouble,
635) {
636    if !check_not_null(&mut env, ptr, "RiDeviceHealthMetrics") {
637        return;
638    }
639    
640    let metrics = unsafe { &mut *(ptr as *mut RiDeviceHealthMetrics) };
641    metrics.network_latency_ms = latency_ms;
642}
643
644#[no_mangle]
645pub extern "system" fn Java_com_dunimd_ri_device_RiDeviceHealthMetrics_getDiskIops0(
646    mut env: JNIEnv,
647    _class: JClass,
648    ptr: jlong,
649) -> jlong {
650    if !check_not_null(&mut env, ptr, "RiDeviceHealthMetrics") {
651        return 0;
652    }
653    
654    let metrics = unsafe { &*(ptr as *const RiDeviceHealthMetrics) };
655    metrics.disk_iops as jlong
656}
657
658#[no_mangle]
659pub extern "system" fn Java_com_dunimd_ri_device_RiDeviceHealthMetrics_setDiskIops0(
660    mut env: JNIEnv,
661    _class: JClass,
662    ptr: jlong,
663    iops: jlong,
664) {
665    if !check_not_null(&mut env, ptr, "RiDeviceHealthMetrics") {
666        return;
667    }
668    
669    let metrics = unsafe { &mut *(ptr as *mut RiDeviceHealthMetrics) };
670    metrics.disk_iops = iops as u64;
671}
672
673#[no_mangle]
674pub extern "system" fn Java_com_dunimd_ri_device_RiDeviceHealthMetrics_getResponseTimeMs0(
675    mut env: JNIEnv,
676    _class: JClass,
677    ptr: jlong,
678) -> jdouble {
679    if !check_not_null(&mut env, ptr, "RiDeviceHealthMetrics") {
680        return 0.0;
681    }
682    
683    let metrics = unsafe { &*(ptr as *const RiDeviceHealthMetrics) };
684    metrics.response_time_ms
685}
686
687#[no_mangle]
688pub extern "system" fn Java_com_dunimd_ri_device_RiDeviceHealthMetrics_setResponseTimeMs0(
689    mut env: JNIEnv,
690    _class: JClass,
691    ptr: jlong,
692    response_time_ms: jdouble,
693) {
694    if !check_not_null(&mut env, ptr, "RiDeviceHealthMetrics") {
695        return;
696    }
697    
698    let metrics = unsafe { &mut *(ptr as *mut RiDeviceHealthMetrics) };
699    metrics.response_time_ms = response_time_ms;
700}
701
702#[no_mangle]
703pub extern "system" fn Java_com_dunimd_ri_device_RiDeviceHealthMetrics_free0(
704    _env: JNIEnv,
705    _class: JClass,
706    ptr: jlong,
707) {
708    if ptr != 0 {
709        unsafe {
710            let _ = Box::from_raw(ptr as *mut RiDeviceHealthMetrics);
711        }
712    }
713}
714
715// =============================================================================
716// RiDeviceConfig JNI Bindings
717// =============================================================================
718
719#[no_mangle]
720pub extern "system" fn Java_com_dunimd_ri_device_RiDeviceConfig_new0(
721    _env: JNIEnv,
722    _class: JClass,
723) -> jlong {
724    let config = Box::new(RiDeviceConfig::default());
725    Box::into_raw(config) as jlong
726}
727
728#[no_mangle]
729pub extern "system" fn Java_com_dunimd_ri_device_RiDeviceConfig_isCpuDiscoveryEnabled0(
730    mut env: JNIEnv,
731    _class: JClass,
732    ptr: jlong,
733) -> jboolean {
734    if !check_not_null(&mut env, ptr, "RiDeviceConfig") {
735        return 0;
736    }
737    
738    let config = unsafe { &*(ptr as *const RiDeviceConfig) };
739    config.enable_cpu_discovery as jboolean
740}
741
742#[no_mangle]
743pub extern "system" fn Java_com_dunimd_ri_device_RiDeviceConfig_setCpuDiscoveryEnabled0(
744    mut env: JNIEnv,
745    _class: JClass,
746    ptr: jlong,
747    enabled: jboolean,
748) {
749    if !check_not_null(&mut env, ptr, "RiDeviceConfig") {
750        return;
751    }
752    
753    let config = unsafe { &mut *(ptr as *mut RiDeviceConfig) };
754    config.enable_cpu_discovery = enabled != 0;
755}
756
757#[no_mangle]
758pub extern "system" fn Java_com_dunimd_ri_device_RiDeviceConfig_isGpuDiscoveryEnabled0(
759    mut env: JNIEnv,
760    _class: JClass,
761    ptr: jlong,
762) -> jboolean {
763    if !check_not_null(&mut env, ptr, "RiDeviceConfig") {
764        return 0;
765    }
766    
767    let config = unsafe { &*(ptr as *const RiDeviceConfig) };
768    config.enable_gpu_discovery as jboolean
769}
770
771#[no_mangle]
772pub extern "system" fn Java_com_dunimd_ri_device_RiDeviceConfig_setGpuDiscoveryEnabled0(
773    mut env: JNIEnv,
774    _class: JClass,
775    ptr: jlong,
776    enabled: jboolean,
777) {
778    if !check_not_null(&mut env, ptr, "RiDeviceConfig") {
779        return;
780    }
781    
782    let config = unsafe { &mut *(ptr as *mut RiDeviceConfig) };
783    config.enable_gpu_discovery = enabled != 0;
784}
785
786#[no_mangle]
787pub extern "system" fn Java_com_dunimd_ri_device_RiDeviceConfig_getDiscoveryTimeoutSecs0(
788    mut env: JNIEnv,
789    _class: JClass,
790    ptr: jlong,
791) -> jlong {
792    if !check_not_null(&mut env, ptr, "RiDeviceConfig") {
793        return 0;
794    }
795    
796    let config = unsafe { &*(ptr as *const RiDeviceConfig) };
797    config.discovery_timeout_secs as jlong
798}
799
800#[no_mangle]
801pub extern "system" fn Java_com_dunimd_ri_device_RiDeviceConfig_setDiscoveryTimeoutSecs0(
802    mut env: JNIEnv,
803    _class: JClass,
804    ptr: jlong,
805    timeout_secs: jlong,
806) {
807    if !check_not_null(&mut env, ptr, "RiDeviceConfig") {
808        return;
809    }
810    
811    let config = unsafe { &mut *(ptr as *mut RiDeviceConfig) };
812    config.discovery_timeout_secs = timeout_secs as u64;
813}
814
815#[no_mangle]
816pub extern "system" fn Java_com_dunimd_ri_device_RiDeviceConfig_getMaxDevicesPerType0(
817    mut env: JNIEnv,
818    _class: JClass,
819    ptr: jlong,
820) -> jint {
821    if !check_not_null(&mut env, ptr, "RiDeviceConfig") {
822        return 0;
823    }
824    
825    let config = unsafe { &*(ptr as *const RiDeviceConfig) };
826    config.max_devices_per_type as jint
827}
828
829#[no_mangle]
830pub extern "system" fn Java_com_dunimd_ri_device_RiDeviceConfig_setMaxDevicesPerType0(
831    mut env: JNIEnv,
832    _class: JClass,
833    ptr: jlong,
834    max: jint,
835) {
836    if !check_not_null(&mut env, ptr, "RiDeviceConfig") {
837        return;
838    }
839    
840    let config = unsafe { &mut *(ptr as *mut RiDeviceConfig) };
841    config.max_devices_per_type = max as usize;
842}
843
844#[no_mangle]
845pub extern "system" fn Java_com_dunimd_ri_device_RiDeviceConfig_free0(
846    _env: JNIEnv,
847    _class: JClass,
848    ptr: jlong,
849) {
850    if ptr != 0 {
851        unsafe {
852            let _ = Box::from_raw(ptr as *mut RiDeviceConfig);
853        }
854    }
855}
856
857// =============================================================================
858// RiDeviceSchedulingConfig JNI Bindings
859// =============================================================================
860
861#[no_mangle]
862pub extern "system" fn Java_com_dunimd_ri_device_RiDeviceSchedulingConfig_new0(
863    _env: JNIEnv,
864    _class: JClass,
865) -> jlong {
866    let config = Box::new(RiDeviceSchedulingConfig::default());
867    Box::into_raw(config) as jlong
868}
869
870#[no_mangle]
871pub extern "system" fn Java_com_dunimd_ri_device_RiDeviceSchedulingConfig_isDiscoveryEnabled0(
872    mut env: JNIEnv,
873    _class: JClass,
874    ptr: jlong,
875) -> jboolean {
876    if !check_not_null(&mut env, ptr, "RiDeviceSchedulingConfig") {
877        return 0;
878    }
879    
880    let config = unsafe { &*(ptr as *const RiDeviceSchedulingConfig) };
881    config.discovery_enabled as jboolean
882}
883
884#[no_mangle]
885pub extern "system" fn Java_com_dunimd_ri_device_RiDeviceSchedulingConfig_setDiscoveryEnabled0(
886    mut env: JNIEnv,
887    _class: JClass,
888    ptr: jlong,
889    enabled: jboolean,
890) {
891    if !check_not_null(&mut env, ptr, "RiDeviceSchedulingConfig") {
892        return;
893    }
894    
895    let config = unsafe { &mut *(ptr as *mut RiDeviceSchedulingConfig) };
896    config.discovery_enabled = enabled != 0;
897}
898
899#[no_mangle]
900pub extern "system" fn Java_com_dunimd_ri_device_RiDeviceSchedulingConfig_getDiscoveryIntervalSecs0(
901    mut env: JNIEnv,
902    _class: JClass,
903    ptr: jlong,
904) -> jlong {
905    if !check_not_null(&mut env, ptr, "RiDeviceSchedulingConfig") {
906        return 0;
907    }
908    
909    let config = unsafe { &*(ptr as *const RiDeviceSchedulingConfig) };
910    config.discovery_interval_secs as jlong
911}
912
913#[no_mangle]
914pub extern "system" fn Java_com_dunimd_ri_device_RiDeviceSchedulingConfig_setDiscoveryIntervalSecs0(
915    mut env: JNIEnv,
916    _class: JClass,
917    ptr: jlong,
918    interval_secs: jlong,
919) {
920    if !check_not_null(&mut env, ptr, "RiDeviceSchedulingConfig") {
921        return;
922    }
923    
924    let config = unsafe { &mut *(ptr as *mut RiDeviceSchedulingConfig) };
925    config.discovery_interval_secs = interval_secs as u64;
926}
927
928#[no_mangle]
929pub extern "system" fn Java_com_dunimd_ri_device_RiDeviceSchedulingConfig_isAutoSchedulingEnabled0(
930    mut env: JNIEnv,
931    _class: JClass,
932    ptr: jlong,
933) -> jboolean {
934    if !check_not_null(&mut env, ptr, "RiDeviceSchedulingConfig") {
935        return 0;
936    }
937    
938    let config = unsafe { &*(ptr as *const RiDeviceSchedulingConfig) };
939    config.auto_scheduling_enabled as jboolean
940}
941
942#[no_mangle]
943pub extern "system" fn Java_com_dunimd_ri_device_RiDeviceSchedulingConfig_setAutoSchedulingEnabled0(
944    mut env: JNIEnv,
945    _class: JClass,
946    ptr: jlong,
947    enabled: jboolean,
948) {
949    if !check_not_null(&mut env, ptr, "RiDeviceSchedulingConfig") {
950        return;
951    }
952    
953    let config = unsafe { &mut *(ptr as *mut RiDeviceSchedulingConfig) };
954    config.auto_scheduling_enabled = enabled != 0;
955}
956
957#[no_mangle]
958pub extern "system" fn Java_com_dunimd_ri_device_RiDeviceSchedulingConfig_getMaxConcurrentTasks0(
959    mut env: JNIEnv,
960    _class: JClass,
961    ptr: jlong,
962) -> jint {
963    if !check_not_null(&mut env, ptr, "RiDeviceSchedulingConfig") {
964        return 0;
965    }
966    
967    let config = unsafe { &*(ptr as *const RiDeviceSchedulingConfig) };
968    config.max_concurrent_tasks as jint
969}
970
971#[no_mangle]
972pub extern "system" fn Java_com_dunimd_ri_device_RiDeviceSchedulingConfig_setMaxConcurrentTasks0(
973    mut env: JNIEnv,
974    _class: JClass,
975    ptr: jlong,
976    max: jint,
977) {
978    if !check_not_null(&mut env, ptr, "RiDeviceSchedulingConfig") {
979        return;
980    }
981    
982    let config = unsafe { &mut *(ptr as *mut RiDeviceSchedulingConfig) };
983    config.max_concurrent_tasks = max as usize;
984}
985
986#[no_mangle]
987pub extern "system" fn Java_com_dunimd_ri_device_RiDeviceSchedulingConfig_getResourceAllocationTimeoutSecs0(
988    mut env: JNIEnv,
989    _class: JClass,
990    ptr: jlong,
991) -> jlong {
992    if !check_not_null(&mut env, ptr, "RiDeviceSchedulingConfig") {
993        return 0;
994    }
995    
996    let config = unsafe { &*(ptr as *const RiDeviceSchedulingConfig) };
997    config.resource_allocation_timeout_secs as jlong
998}
999
1000#[no_mangle]
1001pub extern "system" fn Java_com_dunimd_ri_device_RiDeviceSchedulingConfig_setResourceAllocationTimeoutSecs0(
1002    mut env: JNIEnv,
1003    _class: JClass,
1004    ptr: jlong,
1005    timeout_secs: jlong,
1006) {
1007    if !check_not_null(&mut env, ptr, "RiDeviceSchedulingConfig") {
1008        return;
1009    }
1010    
1011    let config = unsafe { &mut *(ptr as *mut RiDeviceSchedulingConfig) };
1012    config.resource_allocation_timeout_secs = timeout_secs as u64;
1013}
1014
1015#[no_mangle]
1016pub extern "system" fn Java_com_dunimd_ri_device_RiDeviceSchedulingConfig_free0(
1017    _env: JNIEnv,
1018    _class: JClass,
1019    ptr: jlong,
1020) {
1021    if ptr != 0 {
1022        unsafe {
1023            let _ = Box::from_raw(ptr as *mut RiDeviceSchedulingConfig);
1024        }
1025    }
1026}
1027
1028// =============================================================================
1029// RiNetworkDeviceInfo JNI Bindings
1030// =============================================================================
1031
1032#[no_mangle]
1033pub extern "system" fn Java_com_dunimd_ri_device_RiNetworkDeviceInfo_new0(
1034    mut env: JNIEnv,
1035    _class: JClass,
1036    id: JString,
1037    device_type: JString,
1038    source: JString,
1039) -> jlong {
1040    let id_str: String = env.get_string(&id)
1041        .expect("Failed to get id")
1042        .into();
1043    let device_type_str: String = env.get_string(&device_type)
1044        .expect("Failed to get device type")
1045        .into();
1046    let source_str: String = env.get_string(&source)
1047        .expect("Failed to get source")
1048        .into();
1049    
1050    let info = Box::new(RiNetworkDeviceInfo {
1051        id: id_str,
1052        device_type: device_type_str,
1053        source: source_str,
1054        compute_units: None,
1055        memory_gb: None,
1056        storage_gb: None,
1057        bandwidth_gbps: None,
1058    });
1059    Box::into_raw(info) as jlong
1060}
1061
1062#[no_mangle]
1063pub extern "system" fn Java_com_dunimd_ri_device_RiNetworkDeviceInfo_getId0<'local>(
1064    mut env: JNIEnv<'local>,
1065    _class: JClass<'local>,
1066    ptr: jlong,
1067) -> jstring {
1068    if !check_not_null(&mut env, ptr, "RiNetworkDeviceInfo") {
1069        return std::ptr::null_mut();
1070    }
1071    
1072    let info = unsafe { &*(ptr as *const RiNetworkDeviceInfo) };
1073    env.new_string(&info.id).unwrap().into_raw()
1074}
1075
1076#[no_mangle]
1077pub extern "system" fn Java_com_dunimd_ri_device_RiNetworkDeviceInfo_getDeviceType0<'local>(
1078    mut env: JNIEnv<'local>,
1079    _class: JClass<'local>,
1080    ptr: jlong,
1081) -> jstring {
1082    if !check_not_null(&mut env, ptr, "RiNetworkDeviceInfo") {
1083        return std::ptr::null_mut();
1084    }
1085    
1086    let info = unsafe { &*(ptr as *const RiNetworkDeviceInfo) };
1087    env.new_string(&info.device_type).unwrap().into_raw()
1088}
1089
1090#[no_mangle]
1091pub extern "system" fn Java_com_dunimd_ri_device_RiNetworkDeviceInfo_getSource0<'local>(
1092    mut env: JNIEnv<'local>,
1093    _class: JClass<'local>,
1094    ptr: jlong,
1095) -> jstring {
1096    if !check_not_null(&mut env, ptr, "RiNetworkDeviceInfo") {
1097        return std::ptr::null_mut();
1098    }
1099    
1100    let info = unsafe { &*(ptr as *const RiNetworkDeviceInfo) };
1101    env.new_string(&info.source).unwrap().into_raw()
1102}
1103
1104#[no_mangle]
1105pub extern "system" fn Java_com_dunimd_ri_device_RiNetworkDeviceInfo_getComputeUnits0(
1106    mut env: JNIEnv,
1107    _class: JClass,
1108    ptr: jlong,
1109) -> jint {
1110    if !check_not_null(&mut env, ptr, "RiNetworkDeviceInfo") {
1111        return -1;
1112    }
1113    
1114    let info = unsafe { &*(ptr as *const RiNetworkDeviceInfo) };
1115    info.compute_units.map(|v| v as jint).unwrap_or(-1)
1116}
1117
1118#[no_mangle]
1119pub extern "system" fn Java_com_dunimd_ri_device_RiNetworkDeviceInfo_setComputeUnits0(
1120    mut env: JNIEnv,
1121    _class: JClass,
1122    ptr: jlong,
1123    units: jint,
1124) {
1125    if !check_not_null(&mut env, ptr, "RiNetworkDeviceInfo") {
1126        return;
1127    }
1128    
1129    let info = unsafe { &mut *(ptr as *mut RiNetworkDeviceInfo) };
1130    info.compute_units = Some(units as usize);
1131}
1132
1133#[no_mangle]
1134pub extern "system" fn Java_com_dunimd_ri_device_RiNetworkDeviceInfo_getMemoryGb0(
1135    mut env: JNIEnv,
1136    _class: JClass,
1137    ptr: jlong,
1138) -> jdouble {
1139    if !check_not_null(&mut env, ptr, "RiNetworkDeviceInfo") {
1140        return -1.0;
1141    }
1142    
1143    let info = unsafe { &*(ptr as *const RiNetworkDeviceInfo) };
1144    info.memory_gb.unwrap_or(-1.0)
1145}
1146
1147#[no_mangle]
1148pub extern "system" fn Java_com_dunimd_ri_device_RiNetworkDeviceInfo_setMemoryGb0(
1149    mut env: JNIEnv,
1150    _class: JClass,
1151    ptr: jlong,
1152    memory_gb: jdouble,
1153) {
1154    if !check_not_null(&mut env, ptr, "RiNetworkDeviceInfo") {
1155        return;
1156    }
1157    
1158    let info = unsafe { &mut *(ptr as *mut RiNetworkDeviceInfo) };
1159    info.memory_gb = Some(memory_gb);
1160}
1161
1162#[no_mangle]
1163pub extern "system" fn Java_com_dunimd_ri_device_RiNetworkDeviceInfo_getStorageGb0(
1164    mut env: JNIEnv,
1165    _class: JClass,
1166    ptr: jlong,
1167) -> jdouble {
1168    if !check_not_null(&mut env, ptr, "RiNetworkDeviceInfo") {
1169        return -1.0;
1170    }
1171    
1172    let info = unsafe { &*(ptr as *const RiNetworkDeviceInfo) };
1173    info.storage_gb.unwrap_or(-1.0)
1174}
1175
1176#[no_mangle]
1177pub extern "system" fn Java_com_dunimd_ri_device_RiNetworkDeviceInfo_setStorageGb0(
1178    mut env: JNIEnv,
1179    _class: JClass,
1180    ptr: jlong,
1181    storage_gb: jdouble,
1182) {
1183    if !check_not_null(&mut env, ptr, "RiNetworkDeviceInfo") {
1184        return;
1185    }
1186    
1187    let info = unsafe { &mut *(ptr as *mut RiNetworkDeviceInfo) };
1188    info.storage_gb = Some(storage_gb);
1189}
1190
1191#[no_mangle]
1192pub extern "system" fn Java_com_dunimd_ri_device_RiNetworkDeviceInfo_getBandwidthGbps0(
1193    mut env: JNIEnv,
1194    _class: JClass,
1195    ptr: jlong,
1196) -> jdouble {
1197    if !check_not_null(&mut env, ptr, "RiNetworkDeviceInfo") {
1198        return -1.0;
1199    }
1200    
1201    let info = unsafe { &*(ptr as *const RiNetworkDeviceInfo) };
1202    info.bandwidth_gbps.unwrap_or(-1.0)
1203}
1204
1205#[no_mangle]
1206pub extern "system" fn Java_com_dunimd_ri_device_RiNetworkDeviceInfo_setBandwidthGbps0(
1207    mut env: JNIEnv,
1208    _class: JClass,
1209    ptr: jlong,
1210    bandwidth_gbps: jdouble,
1211) {
1212    if !check_not_null(&mut env, ptr, "RiNetworkDeviceInfo") {
1213        return;
1214    }
1215    
1216    let info = unsafe { &mut *(ptr as *mut RiNetworkDeviceInfo) };
1217    info.bandwidth_gbps = Some(bandwidth_gbps);
1218}
1219
1220#[no_mangle]
1221pub extern "system" fn Java_com_dunimd_ri_device_RiNetworkDeviceInfo_free0(
1222    _env: JNIEnv,
1223    _class: JClass,
1224    ptr: jlong,
1225) {
1226    if ptr != 0 {
1227        unsafe {
1228            let _ = Box::from_raw(ptr as *mut RiNetworkDeviceInfo);
1229        }
1230    }
1231}
1232
1233// =============================================================================
1234// RiDiscoveryResult JNI Bindings
1235// =============================================================================
1236
1237#[no_mangle]
1238pub extern "system" fn Java_com_dunimd_ri_device_RiDiscoveryResult_getDiscoveredDevices0(
1239    mut env: JNIEnv,
1240    _class: JClass,
1241    ptr: jlong,
1242) -> jlongArray {
1243    if !check_not_null(&mut env, ptr, "RiDiscoveryResult") {
1244        return std::ptr::null_mut();
1245    }
1246    
1247    let result = unsafe { &*(ptr as *const RiDiscoveryResult) };
1248    let devices: Vec<jlong> = result.discovered_devices.iter().map(|_| 0 as jlong).collect();
1249    
1250    let array = env.new_long_array(devices.len() as i32).unwrap();
1251    env.set_long_array_region(&array, 0, &devices).unwrap();
1252    array.into_raw()
1253}
1254
1255#[no_mangle]
1256pub extern "system" fn Java_com_dunimd_ri_device_RiDiscoveryResult_getUpdatedDevices0(
1257    mut env: JNIEnv,
1258    _class: JClass,
1259    ptr: jlong,
1260) -> jlongArray {
1261    if !check_not_null(&mut env, ptr, "RiDiscoveryResult") {
1262        return std::ptr::null_mut();
1263    }
1264    
1265    let result = unsafe { &*(ptr as *const RiDiscoveryResult) };
1266    let devices: Vec<jlong> = result.updated_devices.iter().map(|_| 0 as jlong).collect();
1267    
1268    let array = env.new_long_array(devices.len() as i32).unwrap();
1269    env.set_long_array_region(&array, 0, &devices).unwrap();
1270    array.into_raw()
1271}
1272
1273#[no_mangle]
1274pub extern "system" fn Java_com_dunimd_ri_device_RiDiscoveryResult_getRemovedDevices0(
1275    mut env: JNIEnv,
1276    _class: JClass,
1277    ptr: jlong,
1278) -> jobjectArray {
1279    if !check_not_null(&mut env, ptr, "RiDiscoveryResult") {
1280        return std::ptr::null_mut();
1281    }
1282    
1283    let result = unsafe { &*(ptr as *const RiDiscoveryResult) };
1284    let string_class = env.find_class("java/lang/String").unwrap();
1285    let array = env.new_object_array(result.removed_devices.len() as i32, string_class, JObject::null()).unwrap();
1286    
1287    for (i, id) in result.removed_devices.iter().enumerate() {
1288        let jstr = env.new_string(id).unwrap();
1289        env.set_object_array_element(&array, i as i32, jstr).unwrap();
1290    }
1291    
1292    array.into_raw()
1293}
1294
1295#[no_mangle]
1296pub extern "system" fn Java_com_dunimd_ri_device_RiDiscoveryResult_getTotalDevices0(
1297    mut env: JNIEnv,
1298    _class: JClass,
1299    ptr: jlong,
1300) -> jint {
1301    if !check_not_null(&mut env, ptr, "RiDiscoveryResult") {
1302        return 0;
1303    }
1304    
1305    let result = unsafe { &*(ptr as *const RiDiscoveryResult) };
1306    result.total_devices as jint
1307}
1308
1309#[no_mangle]
1310pub extern "system" fn Java_com_dunimd_ri_device_RiDiscoveryResult_free0(
1311    _env: JNIEnv,
1312    _class: JClass,
1313    ptr: jlong,
1314) {
1315    if ptr != 0 {
1316        unsafe {
1317            let _ = Box::from_raw(ptr as *mut RiDiscoveryResult);
1318        }
1319    }
1320}
1321
1322// =============================================================================
1323// RiResourceRequest JNI Bindings
1324// =============================================================================
1325
1326#[no_mangle]
1327pub extern "system" fn Java_com_dunimd_ri_device_RiResourceRequest_new0(
1328    mut env: JNIEnv,
1329    _class: JClass,
1330    request_id: JString,
1331    device_type: jint,
1332    capabilities_ptr: jlong,
1333) -> jlong {
1334    let request_id_str: String = env.get_string(&request_id)
1335        .expect("Failed to get request id")
1336        .into();
1337    
1338    let dtype = match device_type {
1339        0 => RiDeviceType::CPU,
1340        1 => RiDeviceType::GPU,
1341        2 => RiDeviceType::Memory,
1342        3 => RiDeviceType::Storage,
1343        4 => RiDeviceType::Network,
1344        5 => RiDeviceType::Sensor,
1345        6 => RiDeviceType::Actuator,
1346        _ => RiDeviceType::Custom,
1347    };
1348    
1349    let capabilities = if capabilities_ptr != 0 {
1350        unsafe { &*(capabilities_ptr as *const RiDeviceCapabilities) }.clone()
1351    } else {
1352        RiDeviceCapabilities::new()
1353    };
1354    
1355    let request = Box::new(RiResourceRequest {
1356        request_id: request_id_str,
1357        device_type: dtype,
1358        required_capabilities: capabilities,
1359        priority: 5,
1360        timeout_secs: 60,
1361        sla_class: None,
1362        resource_weights: None,
1363        affinity: None,
1364        anti_affinity: None,
1365    });
1366    Box::into_raw(request) as jlong
1367}
1368
1369#[no_mangle]
1370pub extern "system" fn Java_com_dunimd_ri_device_RiResourceRequest_getRequestId0<'local>(
1371    mut env: JNIEnv<'local>,
1372    _class: JClass<'local>,
1373    ptr: jlong,
1374) -> jstring {
1375    if !check_not_null(&mut env, ptr, "RiResourceRequest") {
1376        return std::ptr::null_mut();
1377    }
1378    
1379    let request = unsafe { &*(ptr as *const RiResourceRequest) };
1380    env.new_string(&request.request_id).unwrap().into_raw()
1381}
1382
1383#[no_mangle]
1384pub extern "system" fn Java_com_dunimd_ri_device_RiResourceRequest_getDeviceType0(
1385    mut env: JNIEnv,
1386    _class: JClass,
1387    ptr: jlong,
1388) -> jint {
1389    if !check_not_null(&mut env, ptr, "RiResourceRequest") {
1390        return 0;
1391    }
1392    
1393    let request = unsafe { &*(ptr as *const RiResourceRequest) };
1394    request.device_type as jint
1395}
1396
1397#[no_mangle]
1398pub extern "system" fn Java_com_dunimd_ri_device_RiResourceRequest_getRequiredCapabilities0(
1399    mut env: JNIEnv,
1400    _class: JClass,
1401    ptr: jlong,
1402) -> jlong {
1403    if !check_not_null(&mut env, ptr, "RiResourceRequest") {
1404        return 0;
1405    }
1406    
1407    let request = unsafe { &*(ptr as *const RiResourceRequest) };
1408    let capabilities = Box::new(request.required_capabilities.clone());
1409    Box::into_raw(capabilities) as jlong
1410}
1411
1412#[no_mangle]
1413pub extern "system" fn Java_com_dunimd_ri_device_RiResourceRequest_getPriority0(
1414    mut env: JNIEnv,
1415    _class: JClass,
1416    ptr: jlong,
1417) -> jint {
1418    if !check_not_null(&mut env, ptr, "RiResourceRequest") {
1419        return 0;
1420    }
1421    
1422    let request = unsafe { &*(ptr as *const RiResourceRequest) };
1423    request.priority as jint
1424}
1425
1426#[no_mangle]
1427pub extern "system" fn Java_com_dunimd_ri_device_RiResourceRequest_setPriority0(
1428    mut env: JNIEnv,
1429    _class: JClass,
1430    ptr: jlong,
1431    priority: jint,
1432) {
1433    if !check_not_null(&mut env, ptr, "RiResourceRequest") {
1434        return;
1435    }
1436    
1437    let request = unsafe { &mut *(ptr as *mut RiResourceRequest) };
1438    request.priority = priority as u8;
1439}
1440
1441#[no_mangle]
1442pub extern "system" fn Java_com_dunimd_ri_device_RiResourceRequest_getTimeoutSecs0(
1443    mut env: JNIEnv,
1444    _class: JClass,
1445    ptr: jlong,
1446) -> jlong {
1447    if !check_not_null(&mut env, ptr, "RiResourceRequest") {
1448        return 0;
1449    }
1450    
1451    let request = unsafe { &*(ptr as *const RiResourceRequest) };
1452    request.timeout_secs as jlong
1453}
1454
1455#[no_mangle]
1456pub extern "system" fn Java_com_dunimd_ri_device_RiResourceRequest_setTimeoutSecs0(
1457    mut env: JNIEnv,
1458    _class: JClass,
1459    ptr: jlong,
1460    timeout_secs: jlong,
1461) {
1462    if !check_not_null(&mut env, ptr, "RiResourceRequest") {
1463        return;
1464    }
1465    
1466    let request = unsafe { &mut *(ptr as *mut RiResourceRequest) };
1467    request.timeout_secs = timeout_secs as u64;
1468}
1469
1470#[no_mangle]
1471pub extern "system" fn Java_com_dunimd_ri_device_RiResourceRequest_free0(
1472    _env: JNIEnv,
1473    _class: JClass,
1474    ptr: jlong,
1475) {
1476    if ptr != 0 {
1477        unsafe {
1478            let _ = Box::from_raw(ptr as *mut RiResourceRequest);
1479        }
1480    }
1481}
1482
1483// =============================================================================
1484// RiResourceAllocation JNI Bindings
1485// =============================================================================
1486
1487#[no_mangle]
1488pub extern "system" fn Java_com_dunimd_ri_device_RiResourceAllocation_getAllocationId0<'local>(
1489    mut env: JNIEnv<'local>,
1490    _class: JClass<'local>,
1491    ptr: jlong,
1492) -> jstring {
1493    if !check_not_null(&mut env, ptr, "RiResourceAllocation") {
1494        return std::ptr::null_mut();
1495    }
1496    
1497    let allocation = unsafe { &*(ptr as *const RiResourceAllocation) };
1498    env.new_string(&allocation.allocation_id).unwrap().into_raw()
1499}
1500
1501#[no_mangle]
1502pub extern "system" fn Java_com_dunimd_ri_device_RiResourceAllocation_getDeviceId0<'local>(
1503    mut env: JNIEnv<'local>,
1504    _class: JClass<'local>,
1505    ptr: jlong,
1506) -> jstring {
1507    if !check_not_null(&mut env, ptr, "RiResourceAllocation") {
1508        return std::ptr::null_mut();
1509    }
1510    
1511    let allocation = unsafe { &*(ptr as *const RiResourceAllocation) };
1512    env.new_string(&allocation.device_id).unwrap().into_raw()
1513}
1514
1515#[no_mangle]
1516pub extern "system" fn Java_com_dunimd_ri_device_RiResourceAllocation_getDeviceName0<'local>(
1517    mut env: JNIEnv<'local>,
1518    _class: JClass<'local>,
1519    ptr: jlong,
1520) -> jstring {
1521    if !check_not_null(&mut env, ptr, "RiResourceAllocation") {
1522        return std::ptr::null_mut();
1523    }
1524    
1525    let allocation = unsafe { &*(ptr as *const RiResourceAllocation) };
1526    env.new_string(&allocation.device_name).unwrap().into_raw()
1527}
1528
1529#[no_mangle]
1530pub extern "system" fn Java_com_dunimd_ri_device_RiResourceAllocation_getAllocatedAt0<'local>(
1531    mut env: JNIEnv<'local>,
1532    _class: JClass<'local>,
1533    ptr: jlong,
1534) -> jstring {
1535    if !check_not_null(&mut env, ptr, "RiResourceAllocation") {
1536        return std::ptr::null_mut();
1537    }
1538    
1539    let allocation = unsafe { &*(ptr as *const RiResourceAllocation) };
1540    env.new_string(&allocation.allocated_at.to_rfc3339()).unwrap().into_raw()
1541}
1542
1543#[no_mangle]
1544pub extern "system" fn Java_com_dunimd_ri_device_RiResourceAllocation_getExpiresAt0<'local>(
1545    mut env: JNIEnv<'local>,
1546    _class: JClass<'local>,
1547    ptr: jlong,
1548) -> jstring {
1549    if !check_not_null(&mut env, ptr, "RiResourceAllocation") {
1550        return std::ptr::null_mut();
1551    }
1552    
1553    let allocation = unsafe { &*(ptr as *const RiResourceAllocation) };
1554    env.new_string(&allocation.expires_at.to_rfc3339()).unwrap().into_raw()
1555}
1556
1557#[no_mangle]
1558pub extern "system" fn Java_com_dunimd_ri_device_RiResourceAllocation_isExpired0(
1559    mut env: JNIEnv,
1560    _class: JClass,
1561    ptr: jlong,
1562) -> jboolean {
1563    if !check_not_null(&mut env, ptr, "RiResourceAllocation") {
1564        return 1;
1565    }
1566    
1567    let allocation = unsafe { &*(ptr as *const RiResourceAllocation) };
1568    (chrono::Utc::now() > allocation.expires_at) as jboolean
1569}
1570
1571#[no_mangle]
1572pub extern "system" fn Java_com_dunimd_ri_device_RiResourceAllocation_getRemainingTimeSecs0(
1573    mut env: JNIEnv,
1574    _class: JClass,
1575    ptr: jlong,
1576) -> jlong {
1577    if !check_not_null(&mut env, ptr, "RiResourceAllocation") {
1578        return 0;
1579    }
1580    
1581    let allocation = unsafe { &*(ptr as *const RiResourceAllocation) };
1582    (allocation.expires_at - chrono::Utc::now()).num_seconds().max(0) as jlong
1583}
1584
1585#[no_mangle]
1586pub extern "system" fn Java_com_dunimd_ri_device_RiResourceAllocation_getRequest0(
1587    mut env: JNIEnv,
1588    _class: JClass,
1589    ptr: jlong,
1590) -> jlong {
1591    if !check_not_null(&mut env, ptr, "RiResourceAllocation") {
1592        return 0;
1593    }
1594    
1595    let allocation = unsafe { &*(ptr as *const RiResourceAllocation) };
1596    let request = Box::new(allocation.request.clone());
1597    Box::into_raw(request) as jlong
1598}
1599
1600#[no_mangle]
1601pub extern "system" fn Java_com_dunimd_ri_device_RiResourceAllocation_free0(
1602    _env: JNIEnv,
1603    _class: JClass,
1604    ptr: jlong,
1605) {
1606    if ptr != 0 {
1607        unsafe {
1608            let _ = Box::from_raw(ptr as *mut RiResourceAllocation);
1609        }
1610    }
1611}
1612
1613// =============================================================================
1614// RiDeviceController JNI Bindings
1615// =============================================================================
1616
1617#[no_mangle]
1618pub extern "system" fn Java_com_dunimd_ri_device_RiDeviceController_new0(
1619    _env: JNIEnv,
1620    _class: JClass,
1621) -> jlong {
1622    0
1623}
1624
1625#[no_mangle]
1626pub extern "system" fn Java_com_dunimd_ri_device_RiDeviceController_getAllDevices0(
1627    mut env: JNIEnv,
1628    _class: JClass,
1629    ptr: jlong,
1630) -> jlongArray {
1631    if !check_not_null(&mut env, ptr, "RiDeviceController") {
1632        return std::ptr::null_mut();
1633    }
1634    
1635    let devices: Vec<jlong> = Vec::new();
1636    let array = env.new_long_array(0).unwrap();
1637    array.into_raw()
1638}
1639
1640#[no_mangle]
1641pub extern "system" fn Java_com_dunimd_ri_device_RiDeviceController_getDevice0(
1642    mut env: JNIEnv,
1643    _class: JClass,
1644    ptr: jlong,
1645    device_id: JString,
1646) -> jlong {
1647    if !check_not_null(&mut env, ptr, "RiDeviceController") {
1648        return 0;
1649    }
1650    
1651    0
1652}
1653
1654#[no_mangle]
1655pub extern "system" fn Java_com_dunimd_ri_device_RiDeviceController_addDevice0(
1656    mut env: JNIEnv,
1657    _class: JClass,
1658    ptr: jlong,
1659    device_ptr: jlong,
1660) {
1661    if !check_not_null(&mut env, ptr, "RiDeviceController") || !check_not_null(&mut env, device_ptr, "RiDevice") {
1662        return;
1663    }
1664}
1665
1666#[no_mangle]
1667pub extern "system" fn Java_com_dunimd_ri_device_RiDeviceController_removeDevice0(
1668    mut env: JNIEnv,
1669    _class: JClass,
1670    ptr: jlong,
1671    device_id: JString,
1672) -> jboolean {
1673    if !check_not_null(&mut env, ptr, "RiDeviceController") {
1674        return 0;
1675    }
1676    
1677    0
1678}
1679
1680#[no_mangle]
1681pub extern "system" fn Java_com_dunimd_ri_device_RiDeviceController_getDeviceCount0(
1682    mut env: JNIEnv,
1683    _class: JClass,
1684    ptr: jlong,
1685) -> jint {
1686    if !check_not_null(&mut env, ptr, "RiDeviceController") {
1687        return 0;
1688    }
1689    
1690    0
1691}
1692
1693#[no_mangle]
1694pub extern "system" fn Java_com_dunimd_ri_device_RiDeviceController_free0(
1695    _env: JNIEnv,
1696    _class: JClass,
1697    ptr: jlong,
1698) {
1699}