author | James Aley <jamesa@symbian.org> |
Mon, 07 Jun 2010 11:43:45 +0100 | |
changeset 13 | b5d63d5fc252 |
parent 10 | 77a56c951f86 |
permissions | -rw-r--r-- |
10 | 1 |
/** |
2 |
* Copyright (c) 2010 Sasken Communication Technologies Ltd. |
|
3 |
* All rights reserved. |
|
4 |
* This component and the accompanying materials are made available |
|
5 |
* under the terms of the "Eclipse Public License v1.0" |
|
6 |
* which accompanies this distribution, and is available |
|
7 |
* at the URL "http://www.eclipse.org/legal/epl-v10.html" |
|
8 |
* |
|
9 |
* Initial Contributors: |
|
10 |
* Chandradeep Gandhi, Sasken Communication Technologies Ltd - Initial contribution |
|
11 |
* |
|
12 |
* Contributors: |
|
13 |
* Manasij Roy, Nalina Hariharan |
|
14 |
*/ |
|
15 |
||
16 |
#include "smfclientqt.h" |
|
17 |
||
13
b5d63d5fc252
Basic functionality on desktop server build. Started a test for GetServices
James Aley <jamesa@symbian.org>
parents:
10
diff
changeset
|
18 |
SmfClientQt::SmfClientQt(QObject *parent) |
b5d63d5fc252
Basic functionality on desktop server build. Started a test for GetServices
James Aley <jamesa@symbian.org>
parents:
10
diff
changeset
|
19 |
: QObject(parent) |
10 | 20 |
{ |
13
b5d63d5fc252
Basic functionality on desktop server build. Started a test for GetServices
James Aley <jamesa@symbian.org>
parents:
10
diff
changeset
|
21 |
m_serverConnection = new QLocalSocket(); |
b5d63d5fc252
Basic functionality on desktop server build. Started a test for GetServices
James Aley <jamesa@symbian.org>
parents:
10
diff
changeset
|
22 |
|
b5d63d5fc252
Basic functionality on desktop server build. Started a test for GetServices
James Aley <jamesa@symbian.org>
parents:
10
diff
changeset
|
23 |
connect(m_serverConnection, SIGNAL(connected()), this, SLOT(connectionEstablished())); |
b5d63d5fc252
Basic functionality on desktop server build. Started a test for GetServices
James Aley <jamesa@symbian.org>
parents:
10
diff
changeset
|
24 |
connect(m_serverConnection, SIGNAL(readyRead()), this, SLOT(readIncomingData())); |
b5d63d5fc252
Basic functionality on desktop server build. Started a test for GetServices
James Aley <jamesa@symbian.org>
parents:
10
diff
changeset
|
25 |
connect(m_serverConnection, SIGNAL(error(QLocalSocket::LocalSocketError)), |
b5d63d5fc252
Basic functionality on desktop server build. Started a test for GetServices
James Aley <jamesa@symbian.org>
parents:
10
diff
changeset
|
26 |
this, SLOT(handleError(QLocalSocket::LocalSocketError))); |
b5d63d5fc252
Basic functionality on desktop server build. Started a test for GetServices
James Aley <jamesa@symbian.org>
parents:
10
diff
changeset
|
27 |
|
b5d63d5fc252
Basic functionality on desktop server build. Started a test for GetServices
James Aley <jamesa@symbian.org>
parents:
10
diff
changeset
|
28 |
m_serverConnection->connectToServer("SmfServerQt", QIODevice::ReadWrite); |
b5d63d5fc252
Basic functionality on desktop server build. Started a test for GetServices
James Aley <jamesa@symbian.org>
parents:
10
diff
changeset
|
29 |
} |
b5d63d5fc252
Basic functionality on desktop server build. Started a test for GetServices
James Aley <jamesa@symbian.org>
parents:
10
diff
changeset
|
30 |
|
b5d63d5fc252
Basic functionality on desktop server build. Started a test for GetServices
James Aley <jamesa@symbian.org>
parents:
10
diff
changeset
|
31 |
SmfClientQt::~SmfClientQt() |
b5d63d5fc252
Basic functionality on desktop server build. Started a test for GetServices
James Aley <jamesa@symbian.org>
parents:
10
diff
changeset
|
32 |
{ |
b5d63d5fc252
Basic functionality on desktop server build. Started a test for GetServices
James Aley <jamesa@symbian.org>
parents:
10
diff
changeset
|
33 |
m_serverConnection->close(); |
b5d63d5fc252
Basic functionality on desktop server build. Started a test for GetServices
James Aley <jamesa@symbian.org>
parents:
10
diff
changeset
|
34 |
delete m_serverConnection; |
10 | 35 |
} |
36 |
||
37 |
/** |
|
38 |
* Send a request to the server. |
|
39 |
* @param aSerializedData serialized by the caller. |
|
40 |
* @param aInterfaceName Interface name |
|
41 |
* @param requestType Opcode |
|
42 |
*/ |
|
13
b5d63d5fc252
Basic functionality on desktop server build. Started a test for GetServices
James Aley <jamesa@symbian.org>
parents:
10
diff
changeset
|
43 |
int SmfClientQt::sendRequest(QByteArray& serializedData, QString interfaceName, |
10 | 44 |
SmfRequestTypeID requestType) |
45 |
{ |
|
13
b5d63d5fc252
Basic functionality on desktop server build. Started a test for GetServices
James Aley <jamesa@symbian.org>
parents:
10
diff
changeset
|
46 |
QDataStream out(m_serverConnection); |
b5d63d5fc252
Basic functionality on desktop server build. Started a test for GetServices
James Aley <jamesa@symbian.org>
parents:
10
diff
changeset
|
47 |
out << requestType; |
b5d63d5fc252
Basic functionality on desktop server build. Started a test for GetServices
James Aley <jamesa@symbian.org>
parents:
10
diff
changeset
|
48 |
out << interfaceName; |
b5d63d5fc252
Basic functionality on desktop server build. Started a test for GetServices
James Aley <jamesa@symbian.org>
parents:
10
diff
changeset
|
49 |
out << serializedData.size(); |
b5d63d5fc252
Basic functionality on desktop server build. Started a test for GetServices
James Aley <jamesa@symbian.org>
parents:
10
diff
changeset
|
50 |
out << serializedData; |
10 | 51 |
} |
52 |
||
53 |
/** |
|
54 |
* This overloaded API is for ESmfGetServices, where data should be |
|
55 |
* fetched synchronously |
|
56 |
*/ |
|
13
b5d63d5fc252
Basic functionality on desktop server build. Started a test for GetServices
James Aley <jamesa@symbian.org>
parents:
10
diff
changeset
|
57 |
QByteArray SmfClientQt::sendRequest(QString interfaceName, |
10 | 58 |
SmfRequestTypeID requestType) |
59 |
{ |
|
13
b5d63d5fc252
Basic functionality on desktop server build. Started a test for GetServices
James Aley <jamesa@symbian.org>
parents:
10
diff
changeset
|
60 |
QDataStream out(m_serverConnection); |
b5d63d5fc252
Basic functionality on desktop server build. Started a test for GetServices
James Aley <jamesa@symbian.org>
parents:
10
diff
changeset
|
61 |
out << requestType; |
b5d63d5fc252
Basic functionality on desktop server build. Started a test for GetServices
James Aley <jamesa@symbian.org>
parents:
10
diff
changeset
|
62 |
out << interfaceName; |
10 | 63 |
|
13
b5d63d5fc252
Basic functionality on desktop server build. Started a test for GetServices
James Aley <jamesa@symbian.org>
parents:
10
diff
changeset
|
64 |
// TODO: This needs to be asynchronous. Remove this wait when user API is updated. |
b5d63d5fc252
Basic functionality on desktop server build. Started a test for GetServices
James Aley <jamesa@symbian.org>
parents:
10
diff
changeset
|
65 |
m_serverConnection->waitForBytesWritten(-1); |
b5d63d5fc252
Basic functionality on desktop server build. Started a test for GetServices
James Aley <jamesa@symbian.org>
parents:
10
diff
changeset
|
66 |
|
b5d63d5fc252
Basic functionality on desktop server build. Started a test for GetServices
James Aley <jamesa@symbian.org>
parents:
10
diff
changeset
|
67 |
QByteArray in; |
b5d63d5fc252
Basic functionality on desktop server build. Started a test for GetServices
James Aley <jamesa@symbian.org>
parents:
10
diff
changeset
|
68 |
out >> in; |
b5d63d5fc252
Basic functionality on desktop server build. Started a test for GetServices
James Aley <jamesa@symbian.org>
parents:
10
diff
changeset
|
69 |
return in; |
10 | 70 |
} |
71 |
||
72 |
/** |
|
73 |
* For testing purpose only |
|
74 |
*/ |
|
75 |
int SmfClientQt::sendDummyRequest(QByteArray* provider,QString aInterfaceName, |
|
76 |
SmfRequestTypeID requestType) |
|
77 |
{ |
|
13
b5d63d5fc252
Basic functionality on desktop server build. Started a test for GetServices
James Aley <jamesa@symbian.org>
parents:
10
diff
changeset
|
78 |
Q_UNUSED(provider); |
b5d63d5fc252
Basic functionality on desktop server build. Started a test for GetServices
James Aley <jamesa@symbian.org>
parents:
10
diff
changeset
|
79 |
Q_UNUSED(aInterfaceName); |
b5d63d5fc252
Basic functionality on desktop server build. Started a test for GetServices
James Aley <jamesa@symbian.org>
parents:
10
diff
changeset
|
80 |
Q_UNUSED(requestType); |
10 | 81 |
} |
82 |
||
83 |
/** |
|
84 |
* CancelRequest. |
|
85 |
* Cancels an outstanding request. |
|
86 |
*/ |
|
87 |
void SmfClientQt::CancelRequest() |
|
88 |
{ |
|
89 |
||
90 |
} |
|
13
b5d63d5fc252
Basic functionality on desktop server build. Started a test for GetServices
James Aley <jamesa@symbian.org>
parents:
10
diff
changeset
|
91 |
|
b5d63d5fc252
Basic functionality on desktop server build. Started a test for GetServices
James Aley <jamesa@symbian.org>
parents:
10
diff
changeset
|
92 |
void SmfClientQt::connectionEstablished() |
b5d63d5fc252
Basic functionality on desktop server build. Started a test for GetServices
James Aley <jamesa@symbian.org>
parents:
10
diff
changeset
|
93 |
{ |
b5d63d5fc252
Basic functionality on desktop server build. Started a test for GetServices
James Aley <jamesa@symbian.org>
parents:
10
diff
changeset
|
94 |
qDebug() << "Connected to server successfully."; |
b5d63d5fc252
Basic functionality on desktop server build. Started a test for GetServices
James Aley <jamesa@symbian.org>
parents:
10
diff
changeset
|
95 |
} |
b5d63d5fc252
Basic functionality on desktop server build. Started a test for GetServices
James Aley <jamesa@symbian.org>
parents:
10
diff
changeset
|
96 |
|
b5d63d5fc252
Basic functionality on desktop server build. Started a test for GetServices
James Aley <jamesa@symbian.org>
parents:
10
diff
changeset
|
97 |
void SmfClientQt::readIncomingData() |
b5d63d5fc252
Basic functionality on desktop server build. Started a test for GetServices
James Aley <jamesa@symbian.org>
parents:
10
diff
changeset
|
98 |
{ |
b5d63d5fc252
Basic functionality on desktop server build. Started a test for GetServices
James Aley <jamesa@symbian.org>
parents:
10
diff
changeset
|
99 |
} |
b5d63d5fc252
Basic functionality on desktop server build. Started a test for GetServices
James Aley <jamesa@symbian.org>
parents:
10
diff
changeset
|
100 |
|
b5d63d5fc252
Basic functionality on desktop server build. Started a test for GetServices
James Aley <jamesa@symbian.org>
parents:
10
diff
changeset
|
101 |
void SmfClientQt::handleError(QLocalSocket::LocalSocketError error) |
b5d63d5fc252
Basic functionality on desktop server build. Started a test for GetServices
James Aley <jamesa@symbian.org>
parents:
10
diff
changeset
|
102 |
{ |
b5d63d5fc252
Basic functionality on desktop server build. Started a test for GetServices
James Aley <jamesa@symbian.org>
parents:
10
diff
changeset
|
103 |
switch(error) |
b5d63d5fc252
Basic functionality on desktop server build. Started a test for GetServices
James Aley <jamesa@symbian.org>
parents:
10
diff
changeset
|
104 |
{ |
b5d63d5fc252
Basic functionality on desktop server build. Started a test for GetServices
James Aley <jamesa@symbian.org>
parents:
10
diff
changeset
|
105 |
case QLocalSocket::ServerNotFoundError: |
b5d63d5fc252
Basic functionality on desktop server build. Started a test for GetServices
James Aley <jamesa@symbian.org>
parents:
10
diff
changeset
|
106 |
qDebug() << "Server not found."; |
b5d63d5fc252
Basic functionality on desktop server build. Started a test for GetServices
James Aley <jamesa@symbian.org>
parents:
10
diff
changeset
|
107 |
break; |
b5d63d5fc252
Basic functionality on desktop server build. Started a test for GetServices
James Aley <jamesa@symbian.org>
parents:
10
diff
changeset
|
108 |
default: |
b5d63d5fc252
Basic functionality on desktop server build. Started a test for GetServices
James Aley <jamesa@symbian.org>
parents:
10
diff
changeset
|
109 |
qDebug() << "Unhandled socket error"; |
b5d63d5fc252
Basic functionality on desktop server build. Started a test for GetServices
James Aley <jamesa@symbian.org>
parents:
10
diff
changeset
|
110 |
break; |
b5d63d5fc252
Basic functionality on desktop server build. Started a test for GetServices
James Aley <jamesa@symbian.org>
parents:
10
diff
changeset
|
111 |
} |
b5d63d5fc252
Basic functionality on desktop server build. Started a test for GetServices
James Aley <jamesa@symbian.org>
parents:
10
diff
changeset
|
112 |
} |