88import Foundation
99import java_swift
1010import java_util
11- // import JNI
11+ import JNI
1212
1313public extension Android . Bluetooth . LE {
1414
@@ -57,7 +57,7 @@ private func AndroidBluetoothLowEnergyScanCallback_onScanResult( _ __env: Unsafe
5757
5858 let swiftResult = AndroidBluetoothLowEnergyScanResult ( javaObject: result)
5959
60- AndroidBluetoothLowEnergyScanCallback_ListenerLocal_
60+ AndroidBluetoothLowEnergyScanCallbackListenerLocal
6161 . swiftObject ( jniEnv: __env, javaObject: __this, swiftObject: __swiftObject )
6262 . onScanResult ( callbackType: swiftCallbackType, result: swiftResult)
6363}
@@ -73,7 +73,7 @@ private func AndroidBluetoothLowEnergyScanCallback_onBatchScanResults( _ __env:
7373
7474 let results = swiftResultsList? . toArray ( ) ? . map { AndroidBluetoothLowEnergyScanResult ( casting: $0) ! } ?? [ ]
7575
76- AndroidBluetoothLowEnergyScanCallback_ListenerLocal_
76+ AndroidBluetoothLowEnergyScanCallbackListenerLocal
7777 . swiftObject ( jniEnv: __env, javaObject: __this, swiftObject: __swiftObject )
7878 . onBatchScanResults ( results: results)
7979}
@@ -87,39 +87,24 @@ private func AndroidBluetoothLowEnergyScanCallback_onScanFailed( _ __env: Unsafe
8787
8888 let error = AndroidBluetoothLowEnergyScanCallbackError ( rawValue: Int ( __errorCode) )
8989
90- AndroidBluetoothLowEnergyScanCallback_ListenerLocal_
90+ AndroidBluetoothLowEnergyScanCallbackListenerLocal
9191 . swiftObject ( jniEnv: __env, javaObject: __this, swiftObject: __swiftObject )
9292 . onScanFailed ( error: error)
9393}
9494
95- fileprivate class AndroidBluetoothLowEnergyScanCallback_ListenerLocal_ : JNILocalProxy < AndroidBluetoothLowEnergyScanCallback , Any > {
95+ internal class AndroidBluetoothLowEnergyScanCallbackListenerLocal : JNILocalProxy < AndroidBluetoothLowEnergyScanCallback , Any > {
9696
9797 fileprivate static let _proxyClass : jclass = {
98- var natives = [ JNINativeMethod] ( )
9998
100- let onScanResult_thunk : AndroidBluetoothLowEnergyScanCallback_onScanResult_type = AndroidBluetoothLowEnergyScanCallback_onScanResult
101-
102- natives. append ( JNINativeMethod ( name: strdup ( " __onScanResult " ) ,
103- signature: strdup ( " (JILandroid/bluetooth/le/ScanResult;)V " ) ,
104- fnPtr: unsafeBitCast ( onScanResult_thunk, to: UnsafeMutableRawPointer . self ) ) )
105-
106- let onBatchScanResults_thunk : AndroidBluetoothLowEnergyScanCallback_onBatchScanResults_type = AndroidBluetoothLowEnergyScanCallback_onBatchScanResults
107-
108- natives. append ( JNINativeMethod ( name: strdup ( " __onBatchScanResults " ) ,
109- signature: strdup ( " (JLjava/util/List;)V " ) ,
110- fnPtr: unsafeBitCast ( onBatchScanResults_thunk, to: UnsafeMutableRawPointer . self ) ) )
111-
112- let onScanFailed_thunk : AndroidBluetoothLowEnergyScanCallback_onScanFailed_type = AndroidBluetoothLowEnergyScanCallback_onScanFailed
113-
114- natives. append ( JNINativeMethod ( name: strdup ( " __onScanFailed " ) ,
115- signature: strdup ( " (JI)V " ) ,
116- fnPtr: unsafeBitCast ( onScanFailed_thunk, to: UnsafeMutableRawPointer . self ) ) )
117-
118- natives. append ( JNINativeMethod ( name: strdup ( " __finalize " ) ,
119- signature: strdup ( " (J)V " ) ,
120- fnPtr: unsafeBitCast ( JNIReleasableProxy__finalize_thunk, to: UnsafeMutableRawPointer . self ) ) )
99+ var natives : [ JNINativeMethod ] = [
100+ JNICache . Method. onScanResult. method,
101+ JNICache . Method. onBatchScanResults. method,
102+ JNICache . Method. onScanFailed. method,
103+ . finalize
104+ ]
121105
122106 let clazz = JNI . FindClass ( proxyClassName ( ) )
107+
123108 withUnsafePointer ( to: & natives[ 0 ] ) {
124109 nativesPtr in
125110 if JNI . api. RegisterNatives ( JNI . env, clazz, nativesPtr, jint ( natives. count) ) != jint ( JNI_OK) {
@@ -128,18 +113,74 @@ fileprivate class AndroidBluetoothLowEnergyScanCallback_ListenerLocal_: JNILocal
128113 }
129114
130115 defer { JNI . DeleteLocalRef ( clazz ) }
116+
131117 return JNI . api. NewGlobalRef ( JNI . env, clazz ) !
132118 } ( )
133119
134- override open class func proxyClassName( ) -> String { return " org/pureswift/swiftandroid/SwiftBluetoothScanCallback " }
120+ override open class func proxyClassName( ) -> String { return JNICache . className }
135121
136122 override open class func proxyClass( ) -> jclass ? { return _proxyClass }
137123}
138124
139125extension AndroidBluetoothLowEnergyScanCallback {
140126
141127 public func localJavaObject( _ locals: UnsafeMutablePointer < [ jobject ] > ) -> jobject ? {
142- return AndroidBluetoothLowEnergyScanCallback_ListenerLocal_ ( owned: self , proto: self ) . localJavaObject ( locals )
128+
129+ return AndroidBluetoothLowEnergyScanCallbackListenerLocal ( owned: self , proto: self ) . localJavaObject ( locals )
143130 }
144131
145132}
133+
134+ internal extension AndroidBluetoothLowEnergyScanCallbackListenerLocal {
135+
136+ /// JNI Cache
137+ struct JNICache {
138+
139+ static let classSignature = Android . SwiftSupport. className ( [ " SwiftBluetoothScanCallback " ] )
140+
141+ /// JNI Java class name
142+ static let className = classSignature. rawValue
143+
144+ /// JNI Method cache
145+ fileprivate enum Method {
146+
147+ enum onScanResult : JNINativeMethodEntry {
148+
149+ static let name = " __onScanResult "
150+
151+ /// "(JILandroid/bluetooth/le/ScanResult;)V"
152+ static let signature = JNIMethodSignature (
153+ argumentTypes: [
154+ . long,
155+ . object( Android . Bluetooth. LE. ScanResult. JNICache. classSignature)
156+ ] , returnType: . void)
157+
158+ static let thunk : AndroidBluetoothLowEnergyScanCallback_onScanResult_type = AndroidBluetoothLowEnergyScanCallback_onScanResult
159+ }
160+
161+ enum onBatchScanResults : JNINativeMethodEntry {
162+
163+ static let name = " __onBatchScanResults "
164+
165+ /// "(JLjava/util/List;)V"
166+ static let signature = JNIMethodSignature (
167+ argumentTypes: [
168+ . long,
169+ . object( JNIClassName ( rawValue: " java/util/List " ) !) ,
170+ ] , returnType: . void)
171+
172+ static let thunk : AndroidBluetoothLowEnergyScanCallback_onBatchScanResults_type = AndroidBluetoothLowEnergyScanCallback_onBatchScanResults
173+ }
174+
175+ enum onScanFailed : JNINativeMethodEntry {
176+
177+ static let name = " __onScanFailed "
178+
179+ /// "(JI)V"
180+ static let signature = JNIMethodSignature ( argumentTypes: [ . long, . int] , returnType: . void)
181+
182+ static let thunk : AndroidBluetoothLowEnergyScanCallback_onScanFailed_type = AndroidBluetoothLowEnergyScanCallback_onScanFailed
183+ }
184+ }
185+ }
186+ }
0 commit comments