Skip to content
This repository was archived by the owner on Jan 4, 2023. It is now read-only.

Commit 898f6ac

Browse files
misteriosojopetreeftime
authored andcommitted
Added Java method BluetoothManager::getDiscovering()
Added a method to check if a discovery process is running directly from the BluetoothManager (completion to startDiscovery and stopDiscovery). Signed-off-by: Jorge Esteves <[email protected]>
1 parent fe5fd11 commit 898f6ac

File tree

4 files changed

+38
-0
lines changed

4 files changed

+38
-0
lines changed

api/tinyb/BluetoothManager.hpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -238,4 +238,10 @@ friend class BluetoothEventManager;
238238
*/
239239
bool stop_discovery(
240240
);
241+
242+
/** Returns if the discovers is running or not.
243+
* @return TRUE if discovery is running
244+
*/
245+
bool get_discovering(
246+
);
241247
};

java/BluetoothManager.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,11 @@ private native List<BluetoothObject> getObjects(int type, String name,
205205
*/
206206
public native boolean stopDiscovery() throws BluetoothException;
207207

208+
/** Returns if the discovers is running or not.
209+
* @return TRUE if discovery is running
210+
*/
211+
public native boolean getDiscovering() throws BluetoothException;
212+
208213
/**
209214
* When called, each new device found will fire an event to the passed
210215
* listener<p>

java/jni/BluetoothManager.cxx

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -370,6 +370,25 @@ jboolean Java_tinyb_BluetoothManager_stopDiscovery(JNIEnv *env, jobject obj)
370370
return JNI_FALSE;
371371
}
372372

373+
jboolean Java_tinyb_BluetoothManager_getDiscovering(JNIEnv *env, jobject obj)
374+
{
375+
try {
376+
BluetoothManager *manager = getInstance<BluetoothManager>(env, obj);
377+
return manager->get_discovering() ? JNI_TRUE : JNI_FALSE;
378+
} catch (std::bad_alloc &e) {
379+
raise_java_oom_exception(env, e);
380+
} catch (BluetoothException &e) {
381+
raise_java_bluetooth_exception(env, e);
382+
} catch (std::runtime_error &e) {
383+
raise_java_runtime_exception(env, e);
384+
} catch (std::invalid_argument &e) {
385+
raise_java_invalid_arg_exception(env, e);
386+
} catch (std::exception &e) {
387+
raise_java_exception(env, e);
388+
}
389+
return JNI_FALSE;
390+
}
391+
373392
void Java_tinyb_BluetoothManager_init(JNIEnv *env, jobject obj)
374393
{
375394
try {

src/BluetoothManager.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -391,3 +391,11 @@ bool BluetoothManager::stop_discovery()
391391
else
392392
return false;
393393
}
394+
395+
bool BluetoothManager::get_discovering()
396+
{
397+
if (default_adapter != NULL)
398+
return default_adapter->get_discovering();
399+
else
400+
return false;
401+
}

0 commit comments

Comments
 (0)