initial Bluetooth Device Model addition
[profile/ivi/bluetooth-qt.git] / bluetoothbaseagent.cpp
1 #include "bluetoothbaseagent.h"
2
3 #include "agentadaptor.h"
4 #include "bluemanager.h"
5 #include "blueadapter.h"
6 #include <QTimer>
7
8 BluetoothBaseAgent::BluetoothBaseAgent(QString path, QObject *parent):QObject(parent),requestAccepted(false)
9 {
10         new AgentAdaptor(this);
11         QDBusConnection::systemBus().registerObject(path,this);
12
13         OrgBluezManagerInterface manager(
14                         "org.bluez",
15                         "/", QDBusConnection::systemBus());
16
17         QDBusObjectPath adapterpath = manager.DefaultAdapter();
18
19         OrgBluezAdapterInterface adapter(
20                         "org.bluez",
21                         adapterpath.path(),
22                         QDBusConnection::systemBus());
23
24         adapter.RegisterAgent(QDBusObjectPath("/pairing/agent"),"");
25
26         qDebug()<<"last error: "<<adapter.lastError().message();
27
28 }
29
30 void BluetoothBaseAgent::authorize(OrgBluezDeviceInterface &device, QString uuid)
31 {
32         Q_UNUSED(uuid);
33         Q_UNUSED(device);
34         qDebug("authorize");
35 }
36
37 void BluetoothBaseAgent::confirmModeChange(QString mode)
38 {
39         qDebug()<<"mode changed "<<mode;
40 }
41
42 void BluetoothBaseAgent::displayPasskey(OrgBluezDeviceInterface &device, uint key)
43 {
44         qDebug()<<"display key "<<device.path()<<" "<<key;
45 }
46
47 void BluetoothBaseAgent::release()
48 {
49         qDebug("release called");
50 }
51
52 void BluetoothBaseAgent::requestConfirmation(OrgBluezDeviceInterface &device, uint key)
53 {
54         QVariantMap props = device.GetProperties();
55
56         QString alias = props["Alias"].toString();
57
58         qDebug()<<"Pairing with "<< alias << " with key: "+QString::number(key);
59 }
60
61 uint BluetoothBaseAgent::requestPasskey(OrgBluezDeviceInterface &device)
62 {
63         Q_UNUSED(device);
64         qDebug("requestKey");
65         return 0;
66 }
67
68 QString BluetoothBaseAgent::requestPidCode(OrgBluezDeviceInterface &device)
69 {
70         Q_UNUSED(device);
71         return "";
72 }
73
74 void BluetoothBaseAgent::accept()
75 {
76         requestAccepted = true;
77 }
78
79 void BluetoothBaseAgent::doReject()
80 {
81         if(requestAccepted)
82         {
83                 requestAccepted=false;
84                 return;
85         }
86         reject();
87 }