|
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 |
|
18 SmfClientQt::SmfClientQt(QObject *parent) |
|
19 : QObject(parent) |
|
20 { |
|
21 m_serverConnection = new QLocalSocket(); |
|
22 |
|
23 connect(m_serverConnection, SIGNAL(connected()), this, SLOT(connectionEstablished())); |
|
24 connect(m_serverConnection, SIGNAL(readyRead()), this, SLOT(readIncomingData())); |
|
25 connect(m_serverConnection, SIGNAL(error(QLocalSocket::LocalSocketError)), |
|
26 this, SLOT(handleError(QLocalSocket::LocalSocketError))); |
|
27 |
|
28 m_serverConnection->connectToServer("SmfServerQt", QIODevice::ReadWrite); |
|
29 } |
|
30 |
|
31 SmfClientQt::~SmfClientQt() |
|
32 { |
|
33 m_serverConnection->close(); |
|
34 delete m_serverConnection; |
|
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 */ |
|
43 int SmfClientQt::sendRequest(QByteArray& serializedData, QString interfaceName, |
|
44 SmfRequestTypeID requestType) |
|
45 { |
|
46 QDataStream out(m_serverConnection); |
|
47 out << requestType; |
|
48 out << interfaceName; |
|
49 out << serializedData.size(); |
|
50 out << serializedData; |
|
51 } |
|
52 |
|
53 /** |
|
54 * This overloaded API is for ESmfGetServices, where data should be |
|
55 * fetched synchronously |
|
56 */ |
|
57 QByteArray SmfClientQt::sendRequest(QString interfaceName, |
|
58 SmfRequestTypeID requestType) |
|
59 { |
|
60 QDataStream out(m_serverConnection); |
|
61 out << requestType; |
|
62 out << interfaceName; |
|
63 |
|
64 // TODO: This needs to be asynchronous. Remove this wait when user API is updated. |
|
65 m_serverConnection->waitForBytesWritten(-1); |
|
66 |
|
67 QByteArray in; |
|
68 out >> in; |
|
69 return in; |
|
70 } |
|
71 |
|
72 /** |
|
73 * For testing purpose only |
|
74 */ |
|
75 int SmfClientQt::sendDummyRequest(QByteArray* provider,QString aInterfaceName, |
|
76 SmfRequestTypeID requestType) |
|
77 { |
|
78 Q_UNUSED(provider); |
|
79 Q_UNUSED(aInterfaceName); |
|
80 Q_UNUSED(requestType); |
|
81 // ToDo :- |
|
82 } |
|
83 |
|
84 /** |
|
85 * CancelRequest. |
|
86 * Cancels an outstanding request. |
|
87 */ |
|
88 void SmfClientQt::CancelRequest() |
|
89 { |
|
90 // ToDo :- |
|
91 } |
|
92 |
|
93 void SmfClientQt::connectionEstablished() |
|
94 { |
|
95 qDebug() << "Connected to server successfully."; |
|
96 // ToDo :- |
|
97 } |
|
98 |
|
99 void SmfClientQt::readIncomingData() |
|
100 { |
|
101 // ToDo :- |
|
102 } |
|
103 |
|
104 void SmfClientQt::handleError(QLocalSocket::LocalSocketError error) |
|
105 { |
|
106 switch(error) |
|
107 { |
|
108 case QLocalSocket::ServerNotFoundError: |
|
109 qDebug() << "Server not found."; |
|
110 break; |
|
111 |
|
112 default: |
|
113 qDebug() << "Unhandled socket error"; |
|
114 break; |
|
115 } |
|
116 } |