added release signal and fixed bug in ayncagent that was causing crashes
authorKevron Rees <kevron_m_rees@linux.intel.com>
Tue, 9 Nov 2010 01:21:27 +0000 (17:21 -0800)
committerKevron Rees <kevron_m_rees@linux.intel.com>
Tue, 9 Nov 2010 01:21:27 +0000 (17:21 -0800)
asyncagent.cpp
asyncagent.h
bluetoothbaseagent.cpp
bluetoothbaseagent.h
bluetoothdevice.cpp
bluetoothdevice.h
bluetoothdevicemodel.cpp
bluetoothdevicemodel.h
nearbydevicesmodel.cpp
nearbydevicesmodel.h

index 8d39865..453969d 100644 (file)
@@ -66,15 +66,25 @@ QString AsyncAgent::requestPidCode(OrgBluezDeviceInterface &device)
        return "";
 }
 
+void AsyncAgent::release()
+{
+       qDebug("releasing!");
+       if (!QMetaObject::invokeMethod(parent(), "release", Qt::QueuedConnection))
+               qDebug("sending relay signal failed!!!");
+}
+
 
 void AsyncAgent::replyRequestConfirmation(bool confirmed)
 {
        if(!confirmed)
        {
-               reject();
+               qDebug("rejecting");
+               QDBusMessage reply = pendingMessage.createErrorReply("org.bluez.Error.Rejected", "The request was rejected");
+               m_connection.send(reply);
        }
        else
        {
+               qDebug("accepting");
                QDBusMessage reply = pendingMessage.createReply();
                m_connection.send(reply);
        }
index 86f179d..f9fdcef 100644 (file)
@@ -23,6 +23,7 @@ public:
        void requestConfirmation(OrgBluezDeviceInterface &device, uint key);
        uint requestPasskey(OrgBluezDeviceInterface &device);
        QString requestPidCode(OrgBluezDeviceInterface &device);
+       void release();
 
 signals:
 
index e0ee7fe..a49ef4e 100644 (file)
@@ -82,17 +82,3 @@ QString BluetoothBaseAgent::requestPidCode(OrgBluezDeviceInterface &device)
        return "";
 }
 
-void BluetoothBaseAgent::accept()
-{
-       requestAccepted = true;
-}
-
-void BluetoothBaseAgent::doReject()
-{
-       if(requestAccepted)
-       {
-               requestAccepted=false;
-               return;
-       }
-       reject();
-}
index ff01440..8b65bd3 100644 (file)
@@ -34,10 +34,6 @@ public slots:
        virtual uint requestPasskey(OrgBluezDeviceInterface &device);
        virtual QString requestPidCode(OrgBluezDeviceInterface &device);
 
-       virtual void reject() { sendErrorReply("org.bluez.Error.Rejected", "The request was rejected"); }
-
-       virtual void accept();
-       virtual void doReject();
 private:
        bool requestAccepted;
 };
index ad001f5..6d6c96e 100644 (file)
@@ -100,41 +100,6 @@ bool BluetoothDevice::connected()
        return props["Connected"].toBool();
 }
 
-QString BluetoothDevice::connectedProfile()
-{
-       foreach(QString profile, profiles())
-       {
-               if(profile == BluetoothProfiles::a2sink)
-               {
-                       OrgBluezAudioSinkInterface sink("org.bluez",m_device->path(),
-                                                                                       QDBusConnection::systemBus());
-                       if(sink.IsConnected())
-                               return BluetoothProfiles::a2sink;
-               }
-               else if(profile == BluetoothProfiles::a2src)
-               {
-                       OrgBluezAudioSourceInterface source("org.bluez",m_device->path(),
-                                                                                       QDBusConnection::systemBus());
-                       QVariantMap props = source.GetProperties();
-
-                       if(props["State"].toString() == "connected")
-                       {
-                               return BluetoothProfiles::a2src;
-                       }
-
-               }
-               else if(profile == BluetoothProfiles::hs)
-               {
-                       OrgBluezHeadsetInterface headset("org.bluez",m_device->path(),
-                                                                                       QDBusConnection::systemBus());
-                       if(headset.IsConnected())
-                       {
-                               return BluetoothProfiles::hs;
-                       }
-               }
-       }
-}
-
 QString BluetoothDevice::alias()
 {
        QVariantMap props = m_device->GetProperties();
@@ -166,6 +131,8 @@ QString BluetoothDevice::path()
 
 void BluetoothDevice::propertyChanged(QString name,QDBusVariant value)
 {
+       emit propertyChanged(name,value.variant());
+
        if(name == "Connected")
        {
                emit connetedChanged();
index efce46d..5bc0ee4 100644 (file)
@@ -25,6 +25,7 @@ public:
 
 signals:
        void connetedChanged();
+       void propertyChanged(QString name, QVariant value);
 
 public slots:
        void unpair();
@@ -33,7 +34,6 @@ public slots:
 
        QStringList profiles();
        bool isProfileSupported(QString profile);
-       QString connectedProfile();
 
        ///properties:
        bool connected();
index d127425..4749a7e 100644 (file)
@@ -84,6 +84,7 @@ BluetoothDevice* BluetoothDevicesModel::device(QString path)
                if(device->path() == path)
                        return device;
        }
+       return NULL;
 }
 
 void BluetoothDevicesModel::adapterAdded(QDBusObjectPath path)
@@ -113,7 +114,7 @@ void BluetoothDevicesModel::adapterAdded(QDBusObjectPath path)
        QList<QDBusObjectPath> list = adapter->ListDevices();
        foreach(QDBusObjectPath item, list)
        {
-               m_devices.append(new BluetoothDevice(item));
+               deviceCreated(item);
        }
 }
 
@@ -138,9 +139,12 @@ void BluetoothDevicesModel::adapterRemoved(QDBusObjectPath)
 
 void BluetoothDevicesModel::deviceCreated(QDBusObjectPath devicepath)
 {
+       BluetoothDevice* device = new BluetoothDevice(devicepath,this);
+
+       connect(device,SIGNAL(propertyChanged(QString,QVariant)),this,SLOT(devicePropertyChanged(QString,QVariant)));
 
        beginInsertRows(QModelIndex(),m_devices.size()+1,m_devices.size()+1);
-       m_devices.append(new BluetoothDevice(devicepath));
+       m_devices.append(device);
        endInsertRows();
 }
 
@@ -152,9 +156,19 @@ void BluetoothDevicesModel::deviceRemoved(QDBusObjectPath devicepath)
                if(m_devices[i]->path() == devicepath.path())
                {
                        beginRemoveRows(QModelIndex(), i, i);
-                       delete m_devices[i];
+                       m_devices[i]->deleteLater();
                        m_devices.removeAt(i);
                        endRemoveRows();
                }
        }
 }
+
+void BluetoothDevicesModel::devicePropertyChanged(QString name, QVariant value)
+{
+       if(name == "Paired" && value.toBool() == true)
+       {
+               qDebug()<<"device property changed: "<<name<<" "<<value;
+               BluetoothDevice* device = qobject_cast<BluetoothDevice*>(sender());
+               emit devicePaired(device);
+       }
+}
index fb2052f..150a475 100644 (file)
@@ -37,7 +37,10 @@ private slots:
        void deviceCreated(QDBusObjectPath);
        void deviceRemoved(QDBusObjectPath);
 
+       void devicePropertyChanged(QString name, QVariant value);
 
+signals:
+       void devicePaired(BluetoothDevice*);
 
 private:
        OrgBluezManagerInterface *manager;
index 0aa8c36..6bdda1f 100644 (file)
@@ -64,7 +64,7 @@ void NearbyDevicesModel::pair(QString hwaddy)
 
        qDebug()<<"attempting to pair with "<<hwaddy;
        if(!adapter) return;
-       agent = new AsyncAgent("/temp/agent",this);
+       agent = new AsyncAgent("/temp/agent", this);
 
        adapter->CreatePairedDevice(hwaddy,
                                   QDBusObjectPath("/temp/agent"),"");
@@ -91,6 +91,7 @@ void NearbyDevicesModel::removeAll(bool)
 
 void NearbyDevicesModel::replyRequestConfirmation(bool confirmed)
 {
+       qDebug()<<"reply to RequestConfirmation:"<<confirmed;
        if(agent) agent->replyRequestConfirmation(confirmed);
 }
 
index 10a5031..7e3197f 100644 (file)
@@ -55,6 +55,7 @@ signals:
        void requestConfirmation(QString device, uint code);
        void requestPasskey(QString device);
        void requestPidCode(QString device);
+       void release();
 
        void nearbyDeviceFound(int index);
        void nearbyDeviceRemoved(int index);