summaryrefslogtreecommitdiffstats
path: root/java/jni/BluetoothManager.cxx
blob: 749eac723a930f3a832d004a4ee4ac0d586a3faf (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
#include "tinyb/BluetoothAdapter.hpp"
#include "tinyb/BluetoothDevice.hpp"
#include "tinyb/BluetoothGattService.hpp"
#include "tinyb/BluetoothManager.hpp"

#include "BluetoothManager.h"

#include "helper.h"

using namespace tinyb;

jobject Java_BluetoothManager_getBluetoothType(JNIEnv *env, jobject obj)
{
    (void)obj;

    return get_bluetooth_type(env, "NONE");
}

jobject Java_BluetoothManager_getObject(JNIEnv *env, jobject obj, jobject type,
                                        jstring name, jstring identifier, jobject parent)
{
    (void)env;
    (void)obj;
    (void)type;
    (void)name;
    (void)identifier;
    (void)parent;

    return nullptr;
}

jobject Java_BluetoothManager_getObjects(JNIEnv *env, jobject obj, jobject type,
                                        jstring name, jstring identifier, jobject parent)
{
    (void)env;
    (void)obj;
    (void)type;
    (void)name;
    (void)identifier;
    (void)parent;

    return nullptr;
}

jobject Java_BluetoothManager_getAdapters(JNIEnv *env, jobject obj)
{
    BluetoothManager *manager = getInstance<BluetoothManager>(env, obj);

    std::vector<std::unique_ptr<BluetoothAdapter>> array = manager->get_adapters();
    jobject result = convert_vector_to_jobject<BluetoothAdapter>(env, array,
                                                                "BluetoothAdapter",
                                                                "(J)V");
    return result;
}

jobject Java_BluetoothManager_getDevices(JNIEnv *env, jobject obj)
{
    BluetoothManager *manager = getInstance<BluetoothManager>(env, obj);

    std::vector<std::unique_ptr<BluetoothDevice>> array = manager->get_devices();
    jobject result = convert_vector_to_jobject<BluetoothDevice>(env, array,
                                                                "BluetoothDevice",
                                                                "(J)V");
    return result;

}

jobject Java_BluetoothManager_getServices(JNIEnv *env, jobject obj)
{
    BluetoothManager *manager = getInstance<BluetoothManager>(env, obj);

    std::vector<std::unique_ptr<BluetoothGattService>> array = manager->get_services();
    jobject result = convert_vector_to_jobject<BluetoothGattService>(env, array,
                                                                "BluetoothGattService",
                                                                "(J)V");
    return result;
}

jboolean Java_BluetoothManager_setDefaultAdapter(JNIEnv *env, jobject obj, jobject adapter)
{
    BluetoothManager *manager = getInstance<BluetoothManager>(env, obj);
    BluetoothAdapter *b_adapter = getInstance<BluetoothAdapter>(env, adapter);

    return manager->set_default_adapter(b_adapter);
}

jboolean Java_BluetoothManager_startDiscovery(JNIEnv *env, jobject obj)
{
    BluetoothManager *manager = getInstance<BluetoothManager>(env, obj);
    return manager->start_discovery() ? JNI_TRUE : JNI_FALSE;
}

jboolean Java_BluetoothManager_stopDiscovery(JNIEnv *env, jobject obj)
{
    BluetoothManager *manager = getInstance<BluetoothManager>(env, obj);
    return manager->start_discovery() ? JNI_TRUE : JNI_FALSE;
}

void Java_BluetoothManager_init(JNIEnv *env, jobject obj)
{
    BluetoothManager *manager = BluetoothManager::get_bluetooth_manager();
    setInstance<BluetoothManager>(env, obj, manager);
}

void Java_BluetoothManager_delete(JNIEnv *env, jobject obj)
{
    BluetoothManager *manager = getInstance<BluetoothManager>(env, obj);
    delete manager;
}