author | cgandhi <chandradeep.gandhi@sasken.com> |
Wed, 23 Jun 2010 20:47:13 +0530 | |
changeset 15 | 9b00ca3cc206 |
parent 13 | b5d63d5fc252 |
child 18 | 013a02bf2bb0 |
permissions | -rw-r--r-- |
13
b5d63d5fc252
Basic functionality on desktop server build. Started a test for GetServices
James Aley <jamesa@symbian.org>
parents:
diff
changeset
|
1 |
/** |
b5d63d5fc252
Basic functionality on desktop server build. Started a test for GetServices
James Aley <jamesa@symbian.org>
parents:
diff
changeset
|
2 |
* Copyright (c) 2010 Sasken Communication Technologies Ltd. |
b5d63d5fc252
Basic functionality on desktop server build. Started a test for GetServices
James Aley <jamesa@symbian.org>
parents:
diff
changeset
|
3 |
* All rights reserved. |
b5d63d5fc252
Basic functionality on desktop server build. Started a test for GetServices
James Aley <jamesa@symbian.org>
parents:
diff
changeset
|
4 |
* This component and the accompanying materials are made available |
b5d63d5fc252
Basic functionality on desktop server build. Started a test for GetServices
James Aley <jamesa@symbian.org>
parents:
diff
changeset
|
5 |
* under the terms of the "Eclipse Public License v1.0" |
b5d63d5fc252
Basic functionality on desktop server build. Started a test for GetServices
James Aley <jamesa@symbian.org>
parents:
diff
changeset
|
6 |
* which accompanies this distribution, and is available |
b5d63d5fc252
Basic functionality on desktop server build. Started a test for GetServices
James Aley <jamesa@symbian.org>
parents:
diff
changeset
|
7 |
* at the URL "http://www.eclipse.org/legal/epl-v10.html" |
b5d63d5fc252
Basic functionality on desktop server build. Started a test for GetServices
James Aley <jamesa@symbian.org>
parents:
diff
changeset
|
8 |
* |
b5d63d5fc252
Basic functionality on desktop server build. Started a test for GetServices
James Aley <jamesa@symbian.org>
parents:
diff
changeset
|
9 |
* Initial Contributors: |
b5d63d5fc252
Basic functionality on desktop server build. Started a test for GetServices
James Aley <jamesa@symbian.org>
parents:
diff
changeset
|
10 |
* Chandradeep Gandhi, Sasken Communication Technologies Ltd - Initial contribution |
b5d63d5fc252
Basic functionality on desktop server build. Started a test for GetServices
James Aley <jamesa@symbian.org>
parents:
diff
changeset
|
11 |
* |
b5d63d5fc252
Basic functionality on desktop server build. Started a test for GetServices
James Aley <jamesa@symbian.org>
parents:
diff
changeset
|
12 |
* Contributors: |
b5d63d5fc252
Basic functionality on desktop server build. Started a test for GetServices
James Aley <jamesa@symbian.org>
parents:
diff
changeset
|
13 |
* Manasij Roy, Nalina Hariharan |
b5d63d5fc252
Basic functionality on desktop server build. Started a test for GetServices
James Aley <jamesa@symbian.org>
parents:
diff
changeset
|
14 |
* |
b5d63d5fc252
Basic functionality on desktop server build. Started a test for GetServices
James Aley <jamesa@symbian.org>
parents:
diff
changeset
|
15 |
* |
b5d63d5fc252
Basic functionality on desktop server build. Started a test for GetServices
James Aley <jamesa@symbian.org>
parents:
diff
changeset
|
16 |
* Description: Session implementation for Qt desktop builds |
b5d63d5fc252
Basic functionality on desktop server build. Started a test for GetServices
James Aley <jamesa@symbian.org>
parents:
diff
changeset
|
17 |
* |
b5d63d5fc252
Basic functionality on desktop server build. Started a test for GetServices
James Aley <jamesa@symbian.org>
parents:
diff
changeset
|
18 |
*/ |
b5d63d5fc252
Basic functionality on desktop server build. Started a test for GetServices
James Aley <jamesa@symbian.org>
parents:
diff
changeset
|
19 |
|
b5d63d5fc252
Basic functionality on desktop server build. Started a test for GetServices
James Aley <jamesa@symbian.org>
parents:
diff
changeset
|
20 |
#include "smfserverqtsession.h" |
b5d63d5fc252
Basic functionality on desktop server build. Started a test for GetServices
James Aley <jamesa@symbian.org>
parents:
diff
changeset
|
21 |
#include "smfserverqt_p.h" |
b5d63d5fc252
Basic functionality on desktop server build. Started a test for GetServices
James Aley <jamesa@symbian.org>
parents:
diff
changeset
|
22 |
#include "smfserver.h" |
b5d63d5fc252
Basic functionality on desktop server build. Started a test for GetServices
James Aley <jamesa@symbian.org>
parents:
diff
changeset
|
23 |
|
b5d63d5fc252
Basic functionality on desktop server build. Started a test for GetServices
James Aley <jamesa@symbian.org>
parents:
diff
changeset
|
24 |
SmfServerQtSession::SmfServerQtSession(QLocalSocket *clientConnection, SmfServerQt *server) |
b5d63d5fc252
Basic functionality on desktop server build. Started a test for GetServices
James Aley <jamesa@symbian.org>
parents:
diff
changeset
|
25 |
: m_opCode(-1), m_clientConnection(clientConnection), m_server(server) |
b5d63d5fc252
Basic functionality on desktop server build. Started a test for GetServices
James Aley <jamesa@symbian.org>
parents:
diff
changeset
|
26 |
{ |
b5d63d5fc252
Basic functionality on desktop server build. Started a test for GetServices
James Aley <jamesa@symbian.org>
parents:
diff
changeset
|
27 |
connect(m_clientConnection, SIGNAL(readyRead()), this, SLOT(readDataFromClient())); |
b5d63d5fc252
Basic functionality on desktop server build. Started a test for GetServices
James Aley <jamesa@symbian.org>
parents:
diff
changeset
|
28 |
connect(m_clientConnection, SIGNAL(error(QLocalSocket::LocalSocketError)), |
b5d63d5fc252
Basic functionality on desktop server build. Started a test for GetServices
James Aley <jamesa@symbian.org>
parents:
diff
changeset
|
29 |
this, SLOT(socketError(QLocalSocket::LocalSocketError))); |
b5d63d5fc252
Basic functionality on desktop server build. Started a test for GetServices
James Aley <jamesa@symbian.org>
parents:
diff
changeset
|
30 |
} |
b5d63d5fc252
Basic functionality on desktop server build. Started a test for GetServices
James Aley <jamesa@symbian.org>
parents:
diff
changeset
|
31 |
|
b5d63d5fc252
Basic functionality on desktop server build. Started a test for GetServices
James Aley <jamesa@symbian.org>
parents:
diff
changeset
|
32 |
SmfServerQtSession::~SmfServerQtSession() |
b5d63d5fc252
Basic functionality on desktop server build. Started a test for GetServices
James Aley <jamesa@symbian.org>
parents:
diff
changeset
|
33 |
{ |
b5d63d5fc252
Basic functionality on desktop server build. Started a test for GetServices
James Aley <jamesa@symbian.org>
parents:
diff
changeset
|
34 |
// The socket has the QLocalServer as a parent, but it should be deleted to |
b5d63d5fc252
Basic functionality on desktop server build. Started a test for GetServices
James Aley <jamesa@symbian.org>
parents:
diff
changeset
|
35 |
// save unnecessary accumulation of these objects in memory. It won't be double deleted. |
b5d63d5fc252
Basic functionality on desktop server build. Started a test for GetServices
James Aley <jamesa@symbian.org>
parents:
diff
changeset
|
36 |
delete m_clientConnection; |
b5d63d5fc252
Basic functionality on desktop server build. Started a test for GetServices
James Aley <jamesa@symbian.org>
parents:
diff
changeset
|
37 |
} |
b5d63d5fc252
Basic functionality on desktop server build. Started a test for GetServices
James Aley <jamesa@symbian.org>
parents:
diff
changeset
|
38 |
|
b5d63d5fc252
Basic functionality on desktop server build. Started a test for GetServices
James Aley <jamesa@symbian.org>
parents:
diff
changeset
|
39 |
void SmfServerQtSession::readDataFromClient() |
b5d63d5fc252
Basic functionality on desktop server build. Started a test for GetServices
James Aley <jamesa@symbian.org>
parents:
diff
changeset
|
40 |
{ |
b5d63d5fc252
Basic functionality on desktop server build. Started a test for GetServices
James Aley <jamesa@symbian.org>
parents:
diff
changeset
|
41 |
// TODO: This needs to be much safer. |
b5d63d5fc252
Basic functionality on desktop server build. Started a test for GetServices
James Aley <jamesa@symbian.org>
parents:
diff
changeset
|
42 |
if(m_clientConnection->bytesAvailable() < sizeof(typeof(SmfRequestTypeID))) |
b5d63d5fc252
Basic functionality on desktop server build. Started a test for GetServices
James Aley <jamesa@symbian.org>
parents:
diff
changeset
|
43 |
{ |
b5d63d5fc252
Basic functionality on desktop server build. Started a test for GetServices
James Aley <jamesa@symbian.org>
parents:
diff
changeset
|
44 |
// Don't read yet, haven't received opcode |
b5d63d5fc252
Basic functionality on desktop server build. Started a test for GetServices
James Aley <jamesa@symbian.org>
parents:
diff
changeset
|
45 |
return; |
b5d63d5fc252
Basic functionality on desktop server build. Started a test for GetServices
James Aley <jamesa@symbian.org>
parents:
diff
changeset
|
46 |
} |
b5d63d5fc252
Basic functionality on desktop server build. Started a test for GetServices
James Aley <jamesa@symbian.org>
parents:
diff
changeset
|
47 |
|
b5d63d5fc252
Basic functionality on desktop server build. Started a test for GetServices
James Aley <jamesa@symbian.org>
parents:
diff
changeset
|
48 |
if (m_opCode == -1) |
b5d63d5fc252
Basic functionality on desktop server build. Started a test for GetServices
James Aley <jamesa@symbian.org>
parents:
diff
changeset
|
49 |
{ |
b5d63d5fc252
Basic functionality on desktop server build. Started a test for GetServices
James Aley <jamesa@symbian.org>
parents:
diff
changeset
|
50 |
QDataStream in(m_clientConnection); |
b5d63d5fc252
Basic functionality on desktop server build. Started a test for GetServices
James Aley <jamesa@symbian.org>
parents:
diff
changeset
|
51 |
in >> m_opCode; |
b5d63d5fc252
Basic functionality on desktop server build. Started a test for GetServices
James Aley <jamesa@symbian.org>
parents:
diff
changeset
|
52 |
} |
b5d63d5fc252
Basic functionality on desktop server build. Started a test for GetServices
James Aley <jamesa@symbian.org>
parents:
diff
changeset
|
53 |
|
b5d63d5fc252
Basic functionality on desktop server build. Started a test for GetServices
James Aley <jamesa@symbian.org>
parents:
diff
changeset
|
54 |
// m_opCode set, so handle request |
b5d63d5fc252
Basic functionality on desktop server build. Started a test for GetServices
James Aley <jamesa@symbian.org>
parents:
diff
changeset
|
55 |
handleRequest(); |
b5d63d5fc252
Basic functionality on desktop server build. Started a test for GetServices
James Aley <jamesa@symbian.org>
parents:
diff
changeset
|
56 |
} |
b5d63d5fc252
Basic functionality on desktop server build. Started a test for GetServices
James Aley <jamesa@symbian.org>
parents:
diff
changeset
|
57 |
|
b5d63d5fc252
Basic functionality on desktop server build. Started a test for GetServices
James Aley <jamesa@symbian.org>
parents:
diff
changeset
|
58 |
/** |
b5d63d5fc252
Basic functionality on desktop server build. Started a test for GetServices
James Aley <jamesa@symbian.org>
parents:
diff
changeset
|
59 |
* Call the appropriate handler function |
b5d63d5fc252
Basic functionality on desktop server build. Started a test for GetServices
James Aley <jamesa@symbian.org>
parents:
diff
changeset
|
60 |
*/ |
b5d63d5fc252
Basic functionality on desktop server build. Started a test for GetServices
James Aley <jamesa@symbian.org>
parents:
diff
changeset
|
61 |
void SmfServerQtSession::handleRequest() |
b5d63d5fc252
Basic functionality on desktop server build. Started a test for GetServices
James Aley <jamesa@symbian.org>
parents:
diff
changeset
|
62 |
{ |
b5d63d5fc252
Basic functionality on desktop server build. Started a test for GetServices
James Aley <jamesa@symbian.org>
parents:
diff
changeset
|
63 |
switch (m_opCode) |
b5d63d5fc252
Basic functionality on desktop server build. Started a test for GetServices
James Aley <jamesa@symbian.org>
parents:
diff
changeset
|
64 |
{ |
b5d63d5fc252
Basic functionality on desktop server build. Started a test for GetServices
James Aley <jamesa@symbian.org>
parents:
diff
changeset
|
65 |
case SmfGetService: |
b5d63d5fc252
Basic functionality on desktop server build. Started a test for GetServices
James Aley <jamesa@symbian.org>
parents:
diff
changeset
|
66 |
handleGetService(); |
b5d63d5fc252
Basic functionality on desktop server build. Started a test for GetServices
James Aley <jamesa@symbian.org>
parents:
diff
changeset
|
67 |
break; |
b5d63d5fc252
Basic functionality on desktop server build. Started a test for GetServices
James Aley <jamesa@symbian.org>
parents:
diff
changeset
|
68 |
default: |
b5d63d5fc252
Basic functionality on desktop server build. Started a test for GetServices
James Aley <jamesa@symbian.org>
parents:
diff
changeset
|
69 |
m_server->writeLog(QString("Bad Request received: ") + m_opCode); |
b5d63d5fc252
Basic functionality on desktop server build. Started a test for GetServices
James Aley <jamesa@symbian.org>
parents:
diff
changeset
|
70 |
} |
b5d63d5fc252
Basic functionality on desktop server build. Started a test for GetServices
James Aley <jamesa@symbian.org>
parents:
diff
changeset
|
71 |
} |
b5d63d5fc252
Basic functionality on desktop server build. Started a test for GetServices
James Aley <jamesa@symbian.org>
parents:
diff
changeset
|
72 |
|
b5d63d5fc252
Basic functionality on desktop server build. Started a test for GetServices
James Aley <jamesa@symbian.org>
parents:
diff
changeset
|
73 |
/** |
b5d63d5fc252
Basic functionality on desktop server build. Started a test for GetServices
James Aley <jamesa@symbian.org>
parents:
diff
changeset
|
74 |
* Find available services for specified interface and return list to client. |
b5d63d5fc252
Basic functionality on desktop server build. Started a test for GetServices
James Aley <jamesa@symbian.org>
parents:
diff
changeset
|
75 |
*/ |
b5d63d5fc252
Basic functionality on desktop server build. Started a test for GetServices
James Aley <jamesa@symbian.org>
parents:
diff
changeset
|
76 |
void SmfServerQtSession::handleGetService() |
b5d63d5fc252
Basic functionality on desktop server build. Started a test for GetServices
James Aley <jamesa@symbian.org>
parents:
diff
changeset
|
77 |
{ |
b5d63d5fc252
Basic functionality on desktop server build. Started a test for GetServices
James Aley <jamesa@symbian.org>
parents:
diff
changeset
|
78 |
m_server->writeLog("SmfServerQtSession::handleGetService()"); |
b5d63d5fc252
Basic functionality on desktop server build. Started a test for GetServices
James Aley <jamesa@symbian.org>
parents:
diff
changeset
|
79 |
|
b5d63d5fc252
Basic functionality on desktop server build. Started a test for GetServices
James Aley <jamesa@symbian.org>
parents:
diff
changeset
|
80 |
QDataStream in(m_clientConnection); |
b5d63d5fc252
Basic functionality on desktop server build. Started a test for GetServices
James Aley <jamesa@symbian.org>
parents:
diff
changeset
|
81 |
|
b5d63d5fc252
Basic functionality on desktop server build. Started a test for GetServices
James Aley <jamesa@symbian.org>
parents:
diff
changeset
|
82 |
// Get interface type requested |
b5d63d5fc252
Basic functionality on desktop server build. Started a test for GetServices
James Aley <jamesa@symbian.org>
parents:
diff
changeset
|
83 |
SmfInterfaceID ifName; |
b5d63d5fc252
Basic functionality on desktop server build. Started a test for GetServices
James Aley <jamesa@symbian.org>
parents:
diff
changeset
|
84 |
in >> ifName; |
b5d63d5fc252
Basic functionality on desktop server build. Started a test for GetServices
James Aley <jamesa@symbian.org>
parents:
diff
changeset
|
85 |
m_server->writeLog("Requested: " + ifName); |
b5d63d5fc252
Basic functionality on desktop server build. Started a test for GetServices
James Aley <jamesa@symbian.org>
parents:
diff
changeset
|
86 |
|
b5d63d5fc252
Basic functionality on desktop server build. Started a test for GetServices
James Aley <jamesa@symbian.org>
parents:
diff
changeset
|
87 |
// Get the available services for this interface |
b5d63d5fc252
Basic functionality on desktop server build. Started a test for GetServices
James Aley <jamesa@symbian.org>
parents:
diff
changeset
|
88 |
QMap<SmfPluginID, SmfProvider> services; |
b5d63d5fc252
Basic functionality on desktop server build. Started a test for GetServices
James Aley <jamesa@symbian.org>
parents:
diff
changeset
|
89 |
m_server->wrapper()->getPlugins(ifName, services); |
b5d63d5fc252
Basic functionality on desktop server build. Started a test for GetServices
James Aley <jamesa@symbian.org>
parents:
diff
changeset
|
90 |
|
b5d63d5fc252
Basic functionality on desktop server build. Started a test for GetServices
James Aley <jamesa@symbian.org>
parents:
diff
changeset
|
91 |
// write back the results |
b5d63d5fc252
Basic functionality on desktop server build. Started a test for GetServices
James Aley <jamesa@symbian.org>
parents:
diff
changeset
|
92 |
QDataStream out(m_clientConnection); |
b5d63d5fc252
Basic functionality on desktop server build. Started a test for GetServices
James Aley <jamesa@symbian.org>
parents:
diff
changeset
|
93 |
out << services; |
b5d63d5fc252
Basic functionality on desktop server build. Started a test for GetServices
James Aley <jamesa@symbian.org>
parents:
diff
changeset
|
94 |
} |
b5d63d5fc252
Basic functionality on desktop server build. Started a test for GetServices
James Aley <jamesa@symbian.org>
parents:
diff
changeset
|
95 |
|
b5d63d5fc252
Basic functionality on desktop server build. Started a test for GetServices
James Aley <jamesa@symbian.org>
parents:
diff
changeset
|
96 |
void SmfServerQtSession::clientAuthorizationFinished(bool success) |
b5d63d5fc252
Basic functionality on desktop server build. Started a test for GetServices
James Aley <jamesa@symbian.org>
parents:
diff
changeset
|
97 |
{ |
b5d63d5fc252
Basic functionality on desktop server build. Started a test for GetServices
James Aley <jamesa@symbian.org>
parents:
diff
changeset
|
98 |
Q_UNUSED(success); |
b5d63d5fc252
Basic functionality on desktop server build. Started a test for GetServices
James Aley <jamesa@symbian.org>
parents:
diff
changeset
|
99 |
} |
b5d63d5fc252
Basic functionality on desktop server build. Started a test for GetServices
James Aley <jamesa@symbian.org>
parents:
diff
changeset
|
100 |
|
b5d63d5fc252
Basic functionality on desktop server build. Started a test for GetServices
James Aley <jamesa@symbian.org>
parents:
diff
changeset
|
101 |
void SmfServerQtSession::socketError(QLocalSocket::LocalSocketError error) |
b5d63d5fc252
Basic functionality on desktop server build. Started a test for GetServices
James Aley <jamesa@symbian.org>
parents:
diff
changeset
|
102 |
{ |
b5d63d5fc252
Basic functionality on desktop server build. Started a test for GetServices
James Aley <jamesa@symbian.org>
parents:
diff
changeset
|
103 |
switch (error) |
b5d63d5fc252
Basic functionality on desktop server build. Started a test for GetServices
James Aley <jamesa@symbian.org>
parents:
diff
changeset
|
104 |
{ |
b5d63d5fc252
Basic functionality on desktop server build. Started a test for GetServices
James Aley <jamesa@symbian.org>
parents:
diff
changeset
|
105 |
case QLocalSocket::PeerClosedError: |
b5d63d5fc252
Basic functionality on desktop server build. Started a test for GetServices
James Aley <jamesa@symbian.org>
parents:
diff
changeset
|
106 |
m_server->writeLog("Peer closed connection."); |
b5d63d5fc252
Basic functionality on desktop server build. Started a test for GetServices
James Aley <jamesa@symbian.org>
parents:
diff
changeset
|
107 |
break; |
b5d63d5fc252
Basic functionality on desktop server build. Started a test for GetServices
James Aley <jamesa@symbian.org>
parents:
diff
changeset
|
108 |
case QLocalSocket::SocketTimeoutError: |
b5d63d5fc252
Basic functionality on desktop server build. Started a test for GetServices
James Aley <jamesa@symbian.org>
parents:
diff
changeset
|
109 |
m_server->writeLog("error: connection timed out."); |
b5d63d5fc252
Basic functionality on desktop server build. Started a test for GetServices
James Aley <jamesa@symbian.org>
parents:
diff
changeset
|
110 |
break; |
b5d63d5fc252
Basic functionality on desktop server build. Started a test for GetServices
James Aley <jamesa@symbian.org>
parents:
diff
changeset
|
111 |
default: |
b5d63d5fc252
Basic functionality on desktop server build. Started a test for GetServices
James Aley <jamesa@symbian.org>
parents:
diff
changeset
|
112 |
m_server->writeLog("error: unkown socket error: " + error); |
b5d63d5fc252
Basic functionality on desktop server build. Started a test for GetServices
James Aley <jamesa@symbian.org>
parents:
diff
changeset
|
113 |
break; |
b5d63d5fc252
Basic functionality on desktop server build. Started a test for GetServices
James Aley <jamesa@symbian.org>
parents:
diff
changeset
|
114 |
} |
b5d63d5fc252
Basic functionality on desktop server build. Started a test for GetServices
James Aley <jamesa@symbian.org>
parents:
diff
changeset
|
115 |
} |
b5d63d5fc252
Basic functionality on desktop server build. Started a test for GetServices
James Aley <jamesa@symbian.org>
parents:
diff
changeset
|
116 |