Damien Caliste wrote: > Hello, > > I guess that > https://git.sailfishos.org/deloptes/poc-bluez5-buteo-syncml-plugins is a > fork of buteo-sync-plugins with your changes. What about buteo-syncfw ? > > What client are you using on desktop side to test the plugin in phone ? >
I attach a new patch for buteo-syncfw produced on top of d37c8395 with Qt5 DBus only. I am testing it now and it looks working as desired. I forgot to answer the other question before. I use TDE with some patch in knotes and Syncevolution - the TDE plugins I wrote years ago and was using to sync the N9. I know there are plugins for Gnome/Evolution and KDE5/Akonadi - but no idea in what state they are. Any Syncevolution plugin would work of course. I must note that openobex 1.7 is not working with Syncevolution on the desktop. I still use 1.5. I use also openobex 1.5 now on the Xperia X - I did not want to risk troubles with a version I do not know is working well. Let me know if you are able to test it and what is your impression. I will push it to gitlab next as I think it is a preferable solution over the previous one. Most important, and here is the big thanks to Chris for adding the calendar, tasks and notes synchronization, which is actually working as shown below syncml-server[30748]: [D] unknown:0 - Incoming request to release storage with source URI "./calendar" syncml-server[30748]: [D] unknown:0 - Uninitiating ID mapper... syncml-server[30748]: [D] unknown:0 - ID mapper uninitiated syncml-server[30748]: [D] unknown:0 - Closing calendar storage... syncml-server[30748]: [D] unknown:0 - Done syncml-server[30748]: [D] unknown:0 - Closing calendar... syncml-server[30748]: [D] unknown:0 - Done syncml-server[30748]: [D] unknown:0 - SyncAgent: Synchronization status changed to: 208 syncml-server[30748]: [D] unknown:0 - SyncML new state 208 [30232]: [D] unknown:0 - Storage released syncml-server[30748]: [D] unknown:0 - SyncAgent: Synchronization finished with state: 301 syncml-server[30748]: [D] unknown:0 - Sync finished with state 301 syncml-server[30748]: [D] unknown:0 - Items for "./calendar" : syncml-server[30748]: [D] unknown:0 - LA: 0 LD: 0 LM: 0 RA: 0 RD: 0 RM: 1 syncml-server[30748]: [D] unknown:0 - Closing config... syncml-server[30748]: [D] unknown:0 - [Srvr]Sync successfully finished.
diff --git a/libbuteosyncfw/common/TransportTracker.cpp b/libbuteosyncfw/common/TransportTracker.cpp index 35097ec..800ae18 100644 --- a/libbuteosyncfw/common/TransportTracker.cpp +++ b/libbuteosyncfw/common/TransportTracker.cpp @@ -2,6 +2,7 @@ * This file is part of buteo-syncfw package * * Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). + * 2018 Upgraded to use bluez5 by delop...@gmail.com * * Contact: Sateesh Kavuri <sateesh.kav...@nokia.com> * @@ -38,7 +39,8 @@ TransportTracker::TransportTracker(QObject *aParent) : QObject(aParent), iUSBProxy(0), iInternet(0), - iSystemBus(QDBusConnection::systemBus()) + iSystemBus(QDBusConnection::systemBus()), + iDefaultBtAdapter(QString()) { FUNCTION_CALL_TRACE; @@ -65,18 +67,51 @@ TransportTracker::TransportTracker(QObject *aParent) : #endif // BT - // Set the bluetooth state - iTransportStates[Sync::CONNECTIVITY_BT] = btConnectivityStatus(); + // big help was found here + // https://github.com/zeenix/bluetooth-demo/blob/master/blueconnect.cpp + qDBusRegisterMetaType <InterfacesMap> (); + qDBusRegisterMetaType <InterfacesList> (); + qDBusRegisterMetaType <ObjectsMap> (); + + // listen for added interfaces if (!iSystemBus.connect("org.bluez", - "", - "org.bluez.Adapter", - "PropertyChanged", - this, - SLOT(onBtStateChanged(QString, QDBusVariant)))) + "/", + "org.freedesktop.DBus.ObjectManager", + "InterfacesAdded", + this, + SLOT(onInterfacesAdded(const QDBusObjectPath &, const InterfacesMap)))) { + LOG_WARNING("Failed to connect InterfacesAdded signal"); + } + + if (!iSystemBus.connect("org.bluez", + "/", + "org.freedesktop.DBus.ObjectManager", + "InterfacesRemoved", + this, + SLOT(onInterfacesRemoved(const QDBusObjectPath &, const QStringList)))) { + LOG_WARNING("Failed to connect InterfacesRemoved signal"); + } + + // get the initial state + bool btOn = btConnectivityStatus(); + if (btOn) { + if (!iSystemBus.connect("org.bluez", + iDefaultBtAdapter, + QString("org.freedesktop.DBus.Properties"), + QString("PropertiesChanged"), + this, + SLOT(onBtStateChanged(QString, QVariantMap, QStringList)))) { + LOG_WARNING("Failed to connect PropertiesChanged signal"); + } + } + else { - LOG_WARNING("Unable to connect to system bus for org.bluez.Adapter"); + LOG_WARNING("The BT adapter is powered off or missing"); } + // Set the bluetooth state + iTransportStates[Sync::CONNECTIVITY_BT] = btOn; + // Internet // @todo: enable when internet state is reported correctly. iInternet = new NetworkManager(this); @@ -116,15 +151,21 @@ void TransportTracker::onUsbStateChanged(bool aConnected) updateState(Sync::CONNECTIVITY_USB, aConnected); } -void TransportTracker::onBtStateChanged(QString aKey, QDBusVariant aValue) +void TransportTracker::onBtStateChanged(QString interface, QVariantMap changed, QStringList invalidated) { FUNCTION_CALL_TRACE; - if (aKey == "Powered") + Q_UNUSED(invalidated); + + if (interface == "org.bluez.Adapter1") { - bool btPowered = aValue.variant().toBool(); - LOG_DEBUG("BT power state " << btPowered); - updateState(Sync::CONNECTIVITY_BT, btPowered); + for (auto i = changed.begin(); i != changed.end(); ++i) { + if ( i.key() == "Powered") { + bool btOn = i.value().toBool(); + LOG_INFO("BT power state " << btOn); + updateState(Sync::CONNECTIVITY_BT, btOn); + } + } } } @@ -137,6 +178,83 @@ void TransportTracker::onInternetStateChanged(bool aConnected, Sync::InternetCon emit networkStateChanged(aConnected, aType); } +void TransportTracker::onInterfacesAdded(const QDBusObjectPath &path, + const InterfacesMap interfaces) +{ + FUNCTION_CALL_TRACE; + + for (auto i = interfaces.begin(); i != interfaces.end(); ++i) { + if (i.key() == "org.bluez.Adapter1") { + + if (!iDefaultBtAdapter.isEmpty() && path.path() != iDefaultBtAdapter) + continue; + + // If BT was enabled or dsiabled, give the framework 2sec to complete + LOG_INFO("BT state changed (sending update in 2sec)"); + QTime dieTime= QTime::currentTime().addSecs(2); + while (QTime::currentTime() < dieTime) + QCoreApplication::processEvents(QEventLoop::AllEvents, 100); + + if (iDefaultBtAdapter.isEmpty() || iDefaultBtAdapter != path.path()) { + iDefaultBtAdapter = path.path(); + LOG_DEBUG ("Using adapter path: " << iDefaultBtAdapter); + } + + QDBusInterface adapter("org.bluez", + iDefaultBtAdapter, + QString("org.bluez.Adapter1"), + iSystemBus); + + updateState(Sync::CONNECTIVITY_BT, adapter.property("Powered").toBool()); + + if (!iSystemBus.connect("org.bluez", + iDefaultBtAdapter, + QString("org.freedesktop.DBus.Properties"), + QString("PropertiesChanged"), + this, + SLOT(onBtStateChanged(QString, QVariantMap, QStringList)))) { + LOG_WARNING("Failed to connect PropertiesChanged signal"); + + } + else + LOG_DEBUG("'org.bluez.Adapter1' interface at " << iDefaultBtAdapter); + + + break; + } + } +} + +void TransportTracker::onInterfacesRemoved(const QDBusObjectPath &path, + const QStringList interfaces) +{ + FUNCTION_CALL_TRACE; + + for (auto i = interfaces.begin(); i != interfaces.end(); ++i) { + if (*i == "org.bluez.Adapter1") { + + if (path.path() != iDefaultBtAdapter) + continue; + + LOG_DEBUG("DBus adapter path: " << path.path() ); + if (!iSystemBus.disconnect("org.bluez", + path.path(), + QString("org.freedesktop.DBus.Properties"), + QString("PropertiesChanged"), + this, + SLOT(onBtStateChanged(QString, QVariantMap, QStringList)))) { + LOG_WARNING("Failed to disconnect PropertiesChanged signal"); + } + else + LOG_DEBUG("'org.bluez.Adapter1' interface removed from " << path.path()); + + iDefaultBtAdapter = QString(); + + break; + } + } +} + void TransportTracker::updateState(Sync::ConnectivityType aType, bool aState) { @@ -163,50 +281,38 @@ bool TransportTracker::btConnectivityStatus() FUNCTION_CALL_TRACE; bool btOn = false; - QDBusMessage methodCallMsg = QDBusMessage::createMethodCall("org.bluez", - "/", - "org.bluez.Manager", - "DefaultAdapter"); - QDBusMessage reply = iSystemBus.call(methodCallMsg); - if (reply.type() == QDBusMessage::ErrorMessage) - { - LOG_WARNING("This device does not have a BT adapter"); + QDBusInterface manager("org.bluez", + "/", + "org.freedesktop.DBus.ObjectManager", + iSystemBus); + + QDBusReply<ObjectsMap> reply = manager.call("GetManagedObjects"); + if (!reply.isValid()) { + LOG_WARNING( "Failed to connect BT ObjectManager: " << reply.error().message() ); return btOn; } - QList<QVariant> adapterList = reply.arguments(); - // We will take the first adapter in the list - QString adapterPath = qdbus_cast<QDBusObjectPath>(adapterList.at(0)).path(); + auto objects = reply.value(); + for (auto i = objects.begin(); i != objects.end(); ++i) { - if (!adapterPath.isEmpty() || !adapterPath.isNull()) - { - // Retrive the properties of the adapter and check for "Powered" key - methodCallMsg = QDBusMessage::createMethodCall("org.bluez", - adapterPath, - "org.bluez.Adapter", - "GetProperties"); - reply = iSystemBus.call(methodCallMsg); - if (reply.type() == QDBusMessage::ErrorMessage) - { - LOG_WARNING("Error in retrieving bluetooth properties"); - return btOn; - } + auto ifaces = i.value(); + for (auto j = ifaces.begin(); j != ifaces.end(); ++j) { - QDBusArgument arg = reply.arguments().at(0).value<QDBusArgument>(); - if (arg.currentType() == QDBusArgument::MapType) - { - // Scan through the dict returned and check for "Powered" entry - QMap<QString,QVariant> dict = qdbus_cast<QMap<QString,QVariant> >(arg); - QMap<QString,QVariant>::iterator iter; - for(iter = dict.begin(); iter != dict.end(); ++iter) + if (j.key() == "org.bluez.Adapter1") { - if (iter.key() == "Powered") - { - btOn = iter.value().toBool(); - LOG_DEBUG ("Bluetooth powered on? " << btOn); - break; + if (iDefaultBtAdapter.isEmpty() || iDefaultBtAdapter != i.key().path()) { + iDefaultBtAdapter = i.key().path(); + LOG_DEBUG ("Using adapter path: " << iDefaultBtAdapter); } + QDBusInterface adapter("org.bluez", + iDefaultBtAdapter, + QString("org.bluez.Adapter1"), + iSystemBus); + + btOn = adapter.property("Powered").toBool(); + + break; // use first adapter } } } diff --git a/libbuteosyncfw/common/TransportTracker.h b/libbuteosyncfw/common/TransportTracker.h index f43155d..065cbe3 100644 --- a/libbuteosyncfw/common/TransportTracker.h +++ b/libbuteosyncfw/common/TransportTracker.h @@ -31,70 +31,82 @@ #include <QDBusVariant> #include <QDBusConnection> +typedef QMap<QString,QVariantMap> InterfacesMap; +typedef QList<QString> InterfacesList; +typedef QMap<QDBusObjectPath,InterfacesMap> ObjectsMap; + +Q_DECLARE_METATYPE(InterfacesMap) +Q_DECLARE_METATYPE(InterfacesList) +Q_DECLARE_METATYPE(ObjectsMap) + namespace Buteo { class USBModedProxy; class NetworkManager; - /*! \brief Class for tracking transport states - * - * USB state is tracked with HAL, BT with Context Framework and Internet states with Buteo::NetworkManager. - */ + * + * USB state is tracked with HAL, BT with Context Framework and + * Internet states with Buteo::NetworkManager. + */ class TransportTracker : public QObject { - Q_OBJECT + Q_OBJECT public: - /*! \brief Constructor - * - * @param aParent Parent object - */ - TransportTracker(QObject *aParent = 0); + /*! \brief Constructor + * + * @param aParent Parent object + */ + TransportTracker(QObject *aParent = 0); - //! \brief Destructor - virtual ~TransportTracker(); + //! \brief Destructor + virtual ~TransportTracker(); - /*! \brief Checks the state of the given connectivity type - * - * @param aType Connectivity type - * @return True if available, false if not - */ - bool isConnectivityAvailable(Sync::ConnectivityType aType) const; + /*! \brief Checks the state of the given connectivity type + * + * @param aType Connectivity type + * @return True if available, false if not + */ + bool isConnectivityAvailable(Sync::ConnectivityType aType) const; signals: - /*! \brief Signal emitted when a connectivity state changes + /*! \brief Signal emitted when a connectivity state changes * * @param aType Connectivity type whose state has changed * @param aState New state. True if available, false if not. */ - void connectivityStateChanged(Sync::ConnectivityType aType, bool aState); + void connectivityStateChanged(Sync::ConnectivityType aType, bool aState); - /*! \brief Signal emitted when a n/w state changes + /*! \brief Signal emitted when a n/w state changes * * @param aState New state. True if available, false if not. * @param aType Connection type. The type of connetcion with the Internet. */ void networkStateChanged(bool aState, Sync::InternetConnectionType aType); - /*! \brief Signal emitted when a network session is successfully opened + /*! \brief Signal emitted when a network session is successfully opened */ void sessionConnected(); - /*! \brief Signal emitted when opening a network session fails + /*! \brief Signal emitted when opening a network session fails */ void sessionError(); private slots: - void onUsbStateChanged(bool aConnected); + void onUsbStateChanged(bool aConnected); - void onBtStateChanged(QString aKey, QDBusVariant aValue); + void onBtStateChanged(QString interface, QVariantMap changed, QStringList invalidated); void onInternetStateChanged(bool aConnected, Sync::InternetConnectionType aType); + void onInterfacesAdded(const QDBusObjectPath &path, const InterfacesMap interfaces); + + void onInterfacesRemoved(const QDBusObjectPath &path, const QStringList interfaces); + private: QMap<Sync::ConnectivityType, bool> iTransportStates; @@ -103,15 +115,16 @@ private: NetworkManager *iInternet; QDBusConnection iSystemBus; + QString iDefaultBtAdapter; mutable QMutex iMutex; - /*! \brief updates the state of the given connectivity type to input value - * - * @param aType Connectivity type - * @param aState Connectivity State - */ - void updateState(Sync::ConnectivityType aType, bool aState); + /*! \brief updates the state of the given connectivity type to input value + * + * @param aType Connectivity type + * @param aState Connectivity State + */ + void updateState(Sync::ConnectivityType aType, bool aState); #ifdef SYNCFW_UNIT_TESTS friend class TransportTrackerTest; @@ -122,6 +135,6 @@ private: }; -} +} // namespace Buteo #endif /* TRANSPORTTRACKER_H_ */ diff --git a/libbuteosyncfw/profile/BtHelper.cpp b/libbuteosyncfw/profile/BtHelper.cpp index 47269a4..ea5d987 100644 --- a/libbuteosyncfw/profile/BtHelper.cpp +++ b/libbuteosyncfw/profile/BtHelper.cpp @@ -25,141 +25,188 @@ #include "BtHelper.h" - const QString BT::BLUEZ_DEST = "org.bluez"; -const QString BT::BLUEZ_MANAGER_INTERFACE = "org.bluez.Manager"; -const QString BT::BLUEZ_ADAPTER_INTERFACE = "org.bluez.Adapter"; -const QString BT::BLUEZ_DEVICE_INTERFACE = "org.bluez.Device"; -const QString BT::GET_DEFAULT_ADAPTER = "DefaultAdapter"; -const QString BT::FIND_DEVICE = "FindDevice"; -const QString BT::DISCOVERSERVICES = "DiscoverServices"; -const QString BT::GETPROPERTIES = "GetProperties"; +const QString BT::BLUEZ_MANAGER_INTERFACE = "org.freedesktop.DBus.ObjectManager"; +const QString BT::BLUEZ_ADAPTER_INTERFACE = "org.bluez.Adapter1"; +const QString BT::BLUEZ_DEVICE_INTERFACE = "org.bluez.Device1"; +const QString BT::BLUEZ_PROPERTIES_INTERFACE = "org.freedesktop.DBus.Properties"; +const QString BT::GETMANAGEDOBJECTS = "GetManagedObjects"; +const QString BT::GETPROPERTIES = "GetAll"; + +// big help was found here +// https://github.com/zeenix/bluetooth-demo/blob/master/blueconnect.cpp + +typedef QMap<QString,QVariantMap> InterfacesMap; +typedef QMap<QDBusObjectPath,InterfacesMap> ObjectsMap; +Q_DECLARE_METATYPE(InterfacesMap) +Q_DECLARE_METATYPE(ObjectsMap) BtHelper::BtHelper(const QString& deviceAddress, - QObject* parent) : QObject(parent) + QObject* parent) : QObject(parent), + m_SystemBus(QDBusConnection::systemBus()), + m_AdapterPath(QString()) { + FUNCTION_CALL_TRACE; + m_deviceAddress = deviceAddress; + + qDBusRegisterMetaType <InterfacesMap> (); + qDBusRegisterMetaType <ObjectsMap> (); + + QDBusInterface managerInterface( BT::BLUEZ_DEST, "/", + BT::BLUEZ_MANAGER_INTERFACE, + m_SystemBus ); + + QDBusReply<ObjectsMap> reply = managerInterface.call("GetManagedObjects"); + if (!reply.isValid()) { + LOG_WARNING( "Failed to connect to ObjectManager: " << reply.error().message() ); + } + else + { + auto objects = reply.value(); + for (auto i = objects.begin(); i != objects.end(); ++i) { + + auto ifaces = i.value(); + for (auto j = ifaces.begin(); j != ifaces.end(); ++j) { + + if (j.key() == BT::BLUEZ_ADAPTER_INTERFACE) + { + m_AdapterPath = i.key().path(); + LOG_DEBUG ("[BtHelper] Using adapter path:" << m_AdapterPath); + break; // use first adapter + } + } + } + } } BtHelper::~BtHelper() { - LOG_DEBUG (""); + FUNCTION_CALL_TRACE; } - - bool BtHelper::isServiceSupported (const QList<QString>& servicesList, const QString& serviceUUID) { - LOG_DEBUG ("isServiceSupported"); - foreach (QString service, servicesList) { - //LOG_DEBUG ("Record : " << service); - if (service.contains(serviceUUID)){ - LOG_DEBUG ("Service found " << serviceUUID); - return true; - } - } - return false; + FUNCTION_CALL_TRACE; + + foreach (QString service, servicesList) { + if (service.contains(serviceUUID)){ + LOG_DEBUG ("Service found " << serviceUUID); + return true; + } + } + return false; } QString BtHelper::getDefaultAdapterPath() { - LOG_DEBUG ("getDefaultAdapterPath"); - - QDBusInterface managerInterface( BT::BLUEZ_DEST, "/", - BT::BLUEZ_MANAGER_INTERFACE, - QDBusConnection::systemBus() ); - - if( !managerInterface.isValid() ) { - LOG_DEBUG ("Manager interface is invalid"); - return QString(); - } - - QDBusReply<QDBusObjectPath> pathReply = managerInterface.call(BT::GET_DEFAULT_ADAPTER); + FUNCTION_CALL_TRACE; - if( !pathReply.isValid() ) { - LOG_DEBUG ("Not able to get the adapter path"); - return QString(); - } - return pathReply.value().path(); + return m_AdapterPath; } QString BtHelper::getDevicePath(QString &defaultAdapterPath) { - if (defaultAdapterPath.isEmpty()) { - LOG_DEBUG ( "Adapter path is empty"); - return QString(); - } - - QDBusInterface adapterInterface(BT::BLUEZ_DEST, defaultAdapterPath, - BT::BLUEZ_ADAPTER_INTERFACE, QDBusConnection::systemBus() ); - if( !adapterInterface.isValid() ) { - LOG_DEBUG ( "Adapter interface is invalid"); - return QString(); - } + FUNCTION_CALL_TRACE; + //In bluez5 ObjectManager is used to get the device + Q_UNUSED(defaultAdapterPath); - QDBusReply<QDBusObjectPath> pathReply = adapterInterface.call(BT::FIND_DEVICE, m_deviceAddress ); + QDBusInterface managerInterface( BT::BLUEZ_DEST, "/", + BT::BLUEZ_MANAGER_INTERFACE, + m_SystemBus ); - if( !pathReply.isValid() ) { - LOG_DEBUG ( "Not able to find the BT device"); + QDBusReply<ObjectsMap> reply = managerInterface.call("GetManagedObjects"); + if (!reply.isValid()) { + LOG_WARNING( "Failed to connect to ObjectManager: " << reply.error().message() ); return QString(); } - return pathReply.value().path(); + + auto objects = reply.value(); + for (auto i = objects.begin(); i != objects.end(); ++i) { + + auto ifaces = i.value(); + for (auto j = ifaces.begin(); j != ifaces.end(); ++j) { + if (j.key() == BT::BLUEZ_DEVICE_INTERFACE) + { + QString path = i.key().path(); + LOG_DEBUG ( "Object path:" << path ); + QDBusInterface dev(BT::BLUEZ_DEST, + path, + BT::BLUEZ_DEVICE_INTERFACE, + m_SystemBus); + bool connected = dev.property("Connected").toBool(); + if(connected) + { + LOG_DEBUG ( "[BtHelper]Device connected" << dev.property("Address")); + return path; + } + } + } + } + + LOG_DEBUG ( "[BtHelper]Not able to find the BT device"); + return QString(); } bool BtHelper::getServiceRecords(QList<QString>& servicesList) { - LOG_DEBUG ( "getServiceRecords()"); - - QString defaultAdapterPath = getDefaultAdapterPath(); - LOG_DEBUG ( "Adapter path = " << defaultAdapterPath) ; + FUNCTION_CALL_TRACE; - QString devicePath = getDevicePath(defaultAdapterPath); + QString adapterPath = getDefaultAdapterPath(); + if (adapterPath.isEmpty()) + return false; + QString devicePath = getDevicePath(adapterPath); if (devicePath.isEmpty()) - return false; + return false; LOG_DEBUG ( "Device path =" << devicePath); - QDBusInterface deviceInterface(BT::BLUEZ_DEST, devicePath, - BT::BLUEZ_DEVICE_INTERFACE, - QDBusConnection::systemBus() ); - if( deviceInterface.isValid() == false ) { + QDBusInterface deviceInterface(BT::BLUEZ_DEST, + devicePath, + BT::BLUEZ_DEVICE_INTERFACE, + m_SystemBus); + if(!deviceInterface.isValid()) { LOG_DEBUG ("Device interface is not valid"); return false; } + servicesList = deviceInterface.property("UUIDs").toStringList(); - QDBusMessage message = deviceInterface.call(BT::DISCOVERSERVICES, QString()); - QDBusArgument reply = QDBusReply<QDBusArgument>(message).value(); - QMap<uint, QString> mapVal; - reply >> mapVal; - servicesList = mapVal.values(); - if (servicesList.size() > 0) - return true; - return false; + if (servicesList.size() > 0) + return true; + return false; } QMap<QString, QVariant> BtHelper::getDeviceProperties() { - LOG_DEBUG ( "getDeviceProperties"); + FUNCTION_CALL_TRACE; QMap<QString, QVariant> mapVal; - QString defaultAdapterPath = getDefaultAdapterPath(); - LOG_DEBUG ( "Adapter path = " << defaultAdapterPath) ; - QString devicePath = getDevicePath(defaultAdapterPath); + QString adapterPath = getDefaultAdapterPath(); + if (adapterPath.isEmpty()) + return mapVal; + + QString devicePath = getDevicePath(adapterPath); if (devicePath.isEmpty()) - return mapVal; - LOG_DEBUG ( "Device path =" << devicePath); + return mapVal; - QDBusInterface deviceInterface(BT::BLUEZ_DEST, devicePath, - BT::BLUEZ_DEVICE_INTERFACE, - QDBusConnection::systemBus() ); - if( deviceInterface.isValid() == false ) { + QDBusInterface deviceInterface(BT::BLUEZ_DEST, + devicePath, + BT::BLUEZ_PROPERTIES_INTERFACE, + m_SystemBus ); + if(!deviceInterface.isValid()) { LOG_DEBUG ("Device interface is not valid"); return mapVal; } - QDBusMessage message = deviceInterface.call(BT::GETPROPERTIES); - QDBusArgument reply = QDBusReply<QDBusArgument>(message).value(); - reply >> mapVal; - return mapVal; + QDBusReply<QMap<QString, QVariant> > reply = + deviceInterface.call(BT::GETPROPERTIES, BT::BLUEZ_DEVICE_INTERFACE); + if (!reply.isValid()) { + LOG_WARNING( "Failed to get device properties: " << reply.error().message() ); + return mapVal; + } + + mapVal = reply.value(); + + return mapVal; } diff --git a/libbuteosyncfw/profile/BtHelper.h b/libbuteosyncfw/profile/BtHelper.h index 819be11..68c7aab 100644 --- a/libbuteosyncfw/profile/BtHelper.h +++ b/libbuteosyncfw/profile/BtHelper.h @@ -28,24 +28,23 @@ #include <QtDBus> #include <QMap> -/*! \brief Strings used for DBus communication with bluetooth daemon are grouped using this structure. +/*! \brief Strings used for DBus communication with bluetooth + * daemon are grouped using this structure. */ struct BT { /// Destination for Dbus command to bluez static const QString BLUEZ_DEST; - /// Bluez manager interface name + /// DBus object manager interface name static const QString BLUEZ_MANAGER_INTERFACE; /// Bluez adapter interface name static const QString BLUEZ_ADAPTER_INTERFACE; /// Bluez Device interface name static const QString BLUEZ_DEVICE_INTERFACE; - /// Method name for retrieving default adapter - static const QString GET_DEFAULT_ADAPTER; - /// Method name for finding the device - static const QString FIND_DEVICE; - /// Method name for discovering services - static const QString DISCOVERSERVICES; + /// DBus properties interface name + static const QString BLUEZ_PROPERTIES_INTERFACE; + /// Method name for discovering the managed object + static const QString GETMANAGEDOBJECTS; /// Method name for discovering services static const QString GETPROPERTIES; }; @@ -58,6 +57,8 @@ class BtHelper : public QObject private: QString m_deviceAddress; + QDBusConnection m_SystemBus; + QString m_AdapterPath; // Private methods @@ -65,23 +66,21 @@ private: */ QString getDefaultAdapterPath(); - /*! \brief Fetches the device path + /*! \brief Fetches the device path * \param defaultAdapterPath Default adapter path */ QString getDevicePath(QString& defaultAdapterPath); - /* \brief Open the serial port and get file descriptor for the port. - * \return File descriptor if opening port was success, otherwise -1 - */ + public: /*! \brief Constructor. * \param deviceAddess Bluetooth address of remote device * \param parent Parent object */ - BtHelper(const QString& deviceAddess, QObject* parent = 0); + BtHelper(const QString& deviceAddess, QObject* parent = 0); /*! \brief Destructor */ - ~BtHelper(); + ~BtHelper(); /*! \brief Fetch the bluetooth services supported by remote device. * \param servicesList outparam which will be populated with the services. diff --git a/unittests/tests/msyncdtests/TransportTrackerTest/TransportTrackerTest.cpp b/unittests/tests/msyncdtests/TransportTrackerTest/TransportTrackerTest.cpp index 0c37b4c..a671c4f 100644 --- a/unittests/tests/msyncdtests/TransportTrackerTest/TransportTrackerTest.cpp +++ b/unittests/tests/msyncdtests/TransportTrackerTest/TransportTrackerTest.cpp @@ -102,7 +102,12 @@ void TransportTrackerTest :: testStateChanged() // change BT state and verify bool btCurrentState = iTransportTracker->isConnectivityAvailable(Sync::CONNECTIVITY_BT); - iTransportTracker->onBtStateChanged("Powered", QDBusVariant(QVariant(!btCurrentState))); + + QVariantMap map; + QStringList list; + map["Powered"] = QVariant(!btCurrentState); + list << "Powered"; + iTransportTracker->onBtStateChanged("org.bluez.Adapter1", map, list); QCOMPARE(iTransportTracker->isConnectivityAvailable(Sync::CONNECTIVITY_BT), !btCurrentState); QCOMPARE(connectivityStateSpy.count(), 1);
_______________________________________________ SailfishOS.org Devel mailing list To unsubscribe, please send a mail to devel-unsubscr...@lists.sailfishos.org