1 #ifndef BLUETOOTHWRAPPER
2 #define BLUETOOTHWRAPPER
7 #include "bluetoothmanagerproxy.h"
8 #include "bluetoothadapterproxy.h"
9 #include "bluetoothserialproxy.h"
16 std::string getDeviceForAddress(std::string address, std::string adapterAddy = "")
19 OrgBluezManager* manager = org_bluez_manager_proxy_new_for_bus_sync(G_BUS_TYPE_SYSTEM,
20 G_DBUS_PROXY_FLAGS_NONE,
21 "org.bluez","/",NULL, &error);
25 DebugOut(DebugOut::Warning)<<"Error getting bluetooth manager proxy: "<<error->message<<endl;
36 if(!org_bluez_manager_call_find_adapter_sync(manager,adapterAddy.c_str(), &adapterPath, NULL, &error))
38 DebugOut(DebugOut::Warning)<<"Error getting bluetooth adapter ("<<adapterAddy<<"): "<<error->message<<endl;
48 if(!org_bluez_manager_call_default_adapter_sync(manager,&adapterPath, NULL, &error))
50 DebugOut(DebugOut::Warning)<<"Error getting bluetooth default adapter: "<<error->message<<endl;
58 OrgBluezAdapter* adapter = org_bluez_adapter_proxy_new_for_bus_sync(G_BUS_TYPE_SYSTEM,
59 G_DBUS_PROXY_FLAGS_NONE,
60 "org.bluez",adapterPath,NULL,&error);
63 DebugOut(DebugOut::Warning)<<"Error getting bluetooth adapter proxy: "<<error->message<<endl;
71 if(!org_bluez_adapter_call_find_device_sync(adapter,address.c_str(),&devicePath,NULL,&error) ||
72 std::string(devicePath) == "")
74 DebugOut(DebugOut::Warning)<<"Error finding bluetooth device: "<<address<<error->message<<endl;
81 OrgBluezSerial* serialDevice = org_bluez_serial_proxy_new_for_bus_sync(G_BUS_TYPE_SYSTEM,
82 G_DBUS_PROXY_FLAGS_NONE,
83 "org.bluez",devicePath,NULL,&error);
87 DebugOut(DebugOut::Warning)<<"Error getting bluetooth serial device proxy: "<<error->message<<endl;
92 gchar* serialDeviceName;
93 if(!org_bluez_serial_call_connect_sync(serialDevice,"spp",&serialDeviceName,NULL,&error))
95 DebugOut(DebugOut::Warning)<<"Error connecting bluetooth serial device: "<<address<<" - "<<error->message<<endl;
100 return serialDeviceName;
103 void disconnect(std::string address, std::string adapterAddy = "")
105 GError* error = NULL;
106 OrgBluezManager* manager = org_bluez_manager_proxy_new_for_bus_sync(G_BUS_TYPE_SYSTEM,
107 G_DBUS_PROXY_FLAGS_NONE,
108 "org.bluez","/",NULL, &error);
112 DebugOut(DebugOut::Warning)<<"Error getting bluetooth manager proxy: "<<error->message<<endl;
121 if(adapterAddy != "")
123 if(!org_bluez_manager_call_find_adapter_sync(manager,adapterAddy.c_str(), &adapterPath, NULL, &error))
125 DebugOut(DebugOut::Warning)<<"Error getting bluetooth adapter ("<<adapterAddy<<"): "<<error->message<<endl;
135 if(!org_bluez_manager_call_default_adapter_sync(manager,&adapterPath, NULL, &error))
137 DebugOut(DebugOut::Warning)<<"Error getting bluetooth default adapter: "<<error->message<<endl;
145 OrgBluezAdapter* adapter = org_bluez_adapter_proxy_new_for_bus_sync(G_BUS_TYPE_SYSTEM,
146 G_DBUS_PROXY_FLAGS_NONE,
147 "org.bluez",adapterPath,NULL,&error);
150 DebugOut(DebugOut::Warning)<<"Error getting bluetooth adapter proxy: "<<error->message<<endl;
158 if(!org_bluez_adapter_call_find_device_sync(adapter,address.c_str(),&devicePath,NULL,&error) ||
159 std::string(devicePath) == "")
161 DebugOut(DebugOut::Warning)<<"Error finding bluetooth device: "<<address<<error->message<<endl;
168 OrgBluezSerial* serialDevice = org_bluez_serial_proxy_new_for_bus_sync(G_BUS_TYPE_SYSTEM,
169 G_DBUS_PROXY_FLAGS_NONE,
170 "org.bluez",devicePath,NULL,&error);
174 DebugOut(DebugOut::Warning)<<"Error getting bluetooth serial device proxy: "<<error->message<<endl;
179 gchar* serialDeviceName;
180 if(!org_bluez_serial_call_disconnect_sync(serialDevice,"spp",NULL,&error))
182 DebugOut(DebugOut::Warning)<<"Error disconnecting bluetooth serial device: "<<address<<" - "<<error->message<<endl;