|
1 /**************************************************************************** |
|
2 ** |
|
3 ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). |
|
4 ** All rights reserved. |
|
5 ** Contact: Nokia Corporation (qt-info@nokia.com) |
|
6 ** |
|
7 ** This file is part of the Qt Mobility Components. |
|
8 ** |
|
9 ** $QT_BEGIN_LICENSE:LGPL$ |
|
10 ** No Commercial Usage |
|
11 ** This file contains pre-release code and may not be distributed. |
|
12 ** You may use this file in accordance with the terms and conditions |
|
13 ** contained in the Technology Preview License Agreement accompanying |
|
14 ** this package. |
|
15 ** |
|
16 ** GNU Lesser General Public License Usage |
|
17 ** Alternatively, this file may be used under the terms of the GNU Lesser |
|
18 ** General Public License version 2.1 as published by the Free Software |
|
19 ** Foundation and appearing in the file LICENSE.LGPL included in the |
|
20 ** packaging of this file. Please review the following information to |
|
21 ** ensure the GNU Lesser General Public License version 2.1 requirements |
|
22 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. |
|
23 ** |
|
24 ** In addition, as a special exception, Nokia gives you certain additional |
|
25 ** rights. These rights are described in the Nokia Qt LGPL Exception |
|
26 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. |
|
27 ** |
|
28 ** If you have questions regarding the use of this file, please contact |
|
29 ** Nokia at qt-info@nokia.com. |
|
30 ** |
|
31 ** |
|
32 ** |
|
33 ** |
|
34 ** |
|
35 ** |
|
36 ** |
|
37 ** |
|
38 ** $QT_END_LICENSE$ |
|
39 ** |
|
40 ****************************************************************************/ |
|
41 |
|
42 #include "dbuscomm_maemo_p.h" |
|
43 |
|
44 #include <iostream> |
|
45 using namespace std; |
|
46 |
|
47 QTM_BEGIN_NAMESPACE |
|
48 |
|
49 DBusComm::DBusComm() |
|
50 { |
|
51 positioningdService = QString("com.nokia.positioningd.client"); |
|
52 positioningdPath = QString("/com/nokia/positioningd/client"); |
|
53 positioningdInterface = QString("com.nokia.positioningd.client"); |
|
54 } |
|
55 |
|
56 |
|
57 int DBusComm::init() |
|
58 { |
|
59 |
|
60 if (!QDBusConnection::sessionBus().isConnected()) { |
|
61 cerr << "Cannot connect to the D-BUS session bus." << endl; |
|
62 return -1; |
|
63 } |
|
64 |
|
65 // Application auto-start by dbus may take a while, so try |
|
66 // connecting a few times. |
|
67 |
|
68 int cnt = 3; |
|
69 do { |
|
70 cout << "Connecting to positioning daemon" << endl; |
|
71 positioningdProxy = new QDBusInterface(positioningdService, |
|
72 positioningdPath, |
|
73 positioningdInterface, |
|
74 QDBusConnection::sessionBus()); |
|
75 usleep(500000); |
|
76 cnt--; |
|
77 } while (cnt && (positioningdProxy->isValid() == false)); |
|
78 |
|
79 if (positioningdProxy->isValid() == false) { |
|
80 cerr << "DBus connection to positioning daemon failed." << endl; |
|
81 return -1; |
|
82 } |
|
83 |
|
84 createUniqueName(); |
|
85 |
|
86 dbusServer = new DBusServer(&serverObj); |
|
87 dbusServer->setHandlerObject(this); |
|
88 |
|
89 QDBusConnection::sessionBus().registerObject(myPath, &serverObj); |
|
90 |
|
91 if (!QDBusConnection::sessionBus().registerService(myService)) { |
|
92 cerr << qPrintable(QDBusConnection::sessionBus().lastError().message()) << endl; |
|
93 return -1; |
|
94 } |
|
95 |
|
96 return 0; |
|
97 } |
|
98 |
|
99 |
|
100 int DBusComm::receiveDBusMessage(const QByteArray &message) |
|
101 { |
|
102 emit receivedMessage(message); |
|
103 |
|
104 return 0; |
|
105 } |
|
106 |
|
107 |
|
108 int DBusComm::receivePositionUpdate(const QGeoPositionInfo &update) |
|
109 { |
|
110 emit receivedPositionUpdate(update); |
|
111 |
|
112 return 0; |
|
113 } |
|
114 |
|
115 |
|
116 int DBusComm::receiveSettings(const QGeoPositionInfoSource::PositioningMethod methods, |
|
117 const int interval) |
|
118 { |
|
119 cout << "Interval confirmed to be :" << interval << "\n"; |
|
120 // FIXME save these |
|
121 |
|
122 return 0; |
|
123 } |
|
124 |
|
125 |
|
126 bool DBusComm::sendDBusRegister() |
|
127 { |
|
128 int n; |
|
129 QDBusReply<int> reply; |
|
130 |
|
131 reply = positioningdProxy->call("registerListener", |
|
132 myService.toAscii().constData(), |
|
133 myPath.toAscii().constData()); |
|
134 if (reply.isValid()) { |
|
135 n = reply.value(); |
|
136 clientId = n; |
|
137 cout << "Register client ID: " << n << endl; |
|
138 } else { |
|
139 cerr << endl << "DBus error:\n"; |
|
140 cerr << reply.error().name().toAscii().constData() << endl; |
|
141 cerr << reply.error().message().toAscii().constData() << endl; |
|
142 return false; |
|
143 } |
|
144 |
|
145 return true; |
|
146 } |
|
147 |
|
148 |
|
149 int DBusComm::sessionConfigRequest(const int command, const int method, |
|
150 const int interval) const |
|
151 { |
|
152 int n; |
|
153 QDBusReply<bool> reply; |
|
154 |
|
155 positioningdProxy->call("configSession", clientId, command, method, interval); |
|
156 cout << "sessionConfigRequest cmd: cmd:" << command << " method: "; |
|
157 cout << method << " interval: " << interval << "\n"; |
|
158 if (reply.isValid()) { |
|
159 n = reply.value(); |
|
160 cout << "sessionConfigRequest:Reply: " << n << endl; |
|
161 } else { |
|
162 cerr << endl << "DBus error:\n"; |
|
163 cerr << reply.error().name().toAscii().constData() << endl; |
|
164 cerr << reply.error().message().toAscii().constData() << endl; |
|
165 } |
|
166 |
|
167 return 0; |
|
168 } |
|
169 |
|
170 |
|
171 void DBusComm::createUniqueName() |
|
172 { |
|
173 QFile uuidfile("/proc/sys/kernel/random/uuid"); |
|
174 if (!uuidfile.open(QIODevice::ReadOnly)) { |
|
175 cerr << "UUID file failed."; |
|
176 exit(0); |
|
177 } |
|
178 |
|
179 QTextStream in(&uuidfile); |
|
180 QString uuid = 'I' + in.readLine(); |
|
181 uuid.replace('-', 'I'); |
|
182 myService = "com.nokia.qlocation." + uuid; |
|
183 myPath = "/com/nokia/qlocation/" + uuid; |
|
184 myInterface = "com.nokia.qlocation.updates"; |
|
185 |
|
186 } |
|
187 |
|
188 #include "moc_dbuscomm_maemo_p.cpp" |
|
189 QTM_END_NAMESPACE |
|
190 |