summaryrefslogtreecommitdiff
path: root/cpp/src/IceBT/Engine.cpp
diff options
context:
space:
mode:
authorMark Spruiell <mes@zeroc.com>2015-12-17 11:45:27 -0800
committerMark Spruiell <mes@zeroc.com>2015-12-17 11:45:27 -0800
commit884e2be89b0cd997f372c59f05bf05a9a5372b60 (patch)
tree53d2123abf22042f827d0e83b6093cea038c3b3a /cpp/src/IceBT/Engine.cpp
parentMerge branch '3.6' (diff)
downloadice-884e2be89b0cd997f372c59f05bf05a9a5372b60.tar.bz2
ice-884e2be89b0cd997f372c59f05bf05a9a5372b60.tar.xz
ice-884e2be89b0cd997f372c59f05bf05a9a5372b60.zip
Fixes for Bluetooth plug-ins.
Updates to testsuite to support Bluetooth and remote servers.
Diffstat (limited to 'cpp/src/IceBT/Engine.cpp')
-rw-r--r--cpp/src/IceBT/Engine.cpp86
1 files changed, 68 insertions, 18 deletions
diff --git a/cpp/src/IceBT/Engine.cpp b/cpp/src/IceBT/Engine.cpp
index 46e67f47016..308bb52f478 100644
--- a/cpp/src/IceBT/Engine.cpp
+++ b/cpp/src/IceBT/Engine.cpp
@@ -76,12 +76,34 @@ public:
// Block while we establish a DBus connection.
//
_dbusConnection = DBus::Connection::getSystemBus();
- _dbusConnection->addFilter(this);
}
catch(const DBus::Exception& ex)
{
throw BluetoothException(__FILE__, __LINE__, ex.reason);
}
+
+ _dbusConnection->addFilter(this);
+
+ try
+ {
+ //
+ // Use a call DefaultAdapter() to verify that the Bluetooth daemon is present and
+ // uses the expected version (BlueZ 4). If the system is running BlueZ 5, this call
+ // will return the error org.freedesktop.DBus.Error.UnknownMethod.
+ //
+ call("/", "org.bluez.Manager", "DefaultAdapter");
+ }
+ catch(const DBus::Exception& ex)
+ {
+ if(ex.reason.find("UnknownMethod") != string::npos)
+ {
+ throw BluetoothException(__FILE__, __LINE__, "Bluetooth daemon uses an unsupported version");
+ }
+ else
+ {
+ throw BluetoothException(__FILE__, __LINE__, ex.reason);
+ }
+ }
}
//
@@ -392,26 +414,50 @@ public:
string getDefaultAdapter() const
{
- //
- // The call to DefaultAdapter returns OBJ_PATH.
- //
- DBus::MessagePtr reply = call("/", "org.bluez.Manager", "DefaultAdapter");
- DBus::ValuePtr v = reply->read();
- DBus::ObjectPathValuePtr path = DBus::ObjectPathValuePtr::dynamicCast(v);
- assert(path);
- return path->v;
+ try
+ {
+ //
+ // The call to DefaultAdapter returns OBJ_PATH.
+ //
+ DBus::MessagePtr reply = call("/", "org.bluez.Manager", "DefaultAdapter");
+ DBus::ValuePtr v = reply->read();
+ DBus::ObjectPathValuePtr path = DBus::ObjectPathValuePtr::dynamicCast(v);
+ assert(path);
+ return path->v;
+ }
+ catch(const DBus::Exception& ex)
+ {
+ if(ex.reason.find("NoSuchAdapter") == string::npos)
+ {
+ throw BluetoothException(__FILE__, __LINE__, ex.reason);
+ }
+ }
+
+ return string();
}
string findAdapter(const string& addr) const
{
- //
- // The call to FindAdapter returns OBJ_PATH.
- //
- DBus::MessagePtr reply = call("/", "org.bluez.Manager", "FindAdapter", new DBus::StringValue(addr));
- DBus::ValuePtr v = reply->read();
- DBus::ObjectPathValuePtr path = DBus::ObjectPathValuePtr::dynamicCast(v);
- assert(path);
- return path->v;
+ try
+ {
+ //
+ // The call to FindAdapter returns OBJ_PATH.
+ //
+ DBus::MessagePtr reply = call("/", "org.bluez.Manager", "FindAdapter", new DBus::StringValue(addr));
+ DBus::ValuePtr v = reply->read();
+ DBus::ObjectPathValuePtr path = DBus::ObjectPathValuePtr::dynamicCast(v);
+ assert(path);
+ return path->v;
+ }
+ catch(const DBus::Exception& ex)
+ {
+ if(ex.reason.find("NoSuchAdapter") == string::npos)
+ {
+ throw BluetoothException(__FILE__, __LINE__, ex.reason);
+ }
+ }
+
+ return string();
}
VariantMap getAdapterProperties(const string& path) const
@@ -794,7 +840,11 @@ public:
{
if(channels.empty())
{
- cb->exception(BluetoothException(__FILE__, __LINE__, "no service found for " + uuid + " at " + addr));
+ //
+ // No service found for the UUID at the remote address. We treat this as if the
+ // server is not running.
+ //
+ cb->exception(ConnectFailedException(__FILE__, __LINE__, ECONNREFUSED));
}
else
{