smf/smfservermodule/smfclient/client/smfclientqt.cpp
author James Aley <jamesa@symbian.org>
Mon, 07 Jun 2010 11:43:45 +0100
changeset 13 b5d63d5fc252
parent 10 77a56c951f86
permissions -rw-r--r--
Basic functionality on desktop server build. Started a test for GetServices
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
10
77a56c951f86 Fixed build for Qt desktop
James Aley <jamesa@symbian.org>
parents:
diff changeset
     1
/**
77a56c951f86 Fixed build for Qt desktop
James Aley <jamesa@symbian.org>
parents:
diff changeset
     2
 * Copyright (c) 2010 Sasken Communication Technologies Ltd.
77a56c951f86 Fixed build for Qt desktop
James Aley <jamesa@symbian.org>
parents:
diff changeset
     3
 * All rights reserved.
77a56c951f86 Fixed build for Qt desktop
James Aley <jamesa@symbian.org>
parents:
diff changeset
     4
 * This component and the accompanying materials are made available
77a56c951f86 Fixed build for Qt desktop
James Aley <jamesa@symbian.org>
parents:
diff changeset
     5
 * under the terms of the "Eclipse Public License v1.0"
77a56c951f86 Fixed build for Qt desktop
James Aley <jamesa@symbian.org>
parents:
diff changeset
     6
 * which accompanies  this distribution, and is available
77a56c951f86 Fixed build for Qt desktop
James Aley <jamesa@symbian.org>
parents:
diff changeset
     7
 * at the URL "http://www.eclipse.org/legal/epl-v10.html"
77a56c951f86 Fixed build for Qt desktop
James Aley <jamesa@symbian.org>
parents:
diff changeset
     8
 *
77a56c951f86 Fixed build for Qt desktop
James Aley <jamesa@symbian.org>
parents:
diff changeset
     9
 * Initial Contributors:
77a56c951f86 Fixed build for Qt desktop
James Aley <jamesa@symbian.org>
parents:
diff changeset
    10
 * Chandradeep Gandhi, Sasken Communication Technologies Ltd - Initial contribution
77a56c951f86 Fixed build for Qt desktop
James Aley <jamesa@symbian.org>
parents:
diff changeset
    11
 *
77a56c951f86 Fixed build for Qt desktop
James Aley <jamesa@symbian.org>
parents:
diff changeset
    12
 * Contributors:
77a56c951f86 Fixed build for Qt desktop
James Aley <jamesa@symbian.org>
parents:
diff changeset
    13
 * Manasij Roy, Nalina Hariharan
77a56c951f86 Fixed build for Qt desktop
James Aley <jamesa@symbian.org>
parents:
diff changeset
    14
 */
77a56c951f86 Fixed build for Qt desktop
James Aley <jamesa@symbian.org>
parents:
diff changeset
    15
77a56c951f86 Fixed build for Qt desktop
James Aley <jamesa@symbian.org>
parents:
diff changeset
    16
#include "smfclientqt.h"
77a56c951f86 Fixed build for Qt desktop
James Aley <jamesa@symbian.org>
parents:
diff changeset
    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
77a56c951f86 Fixed build for Qt desktop
James Aley <jamesa@symbian.org>
parents:
diff changeset
    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
77a56c951f86 Fixed build for Qt desktop
James Aley <jamesa@symbian.org>
parents:
diff changeset
    35
}
77a56c951f86 Fixed build for Qt desktop
James Aley <jamesa@symbian.org>
parents:
diff changeset
    36
77a56c951f86 Fixed build for Qt desktop
James Aley <jamesa@symbian.org>
parents:
diff changeset
    37
/**
77a56c951f86 Fixed build for Qt desktop
James Aley <jamesa@symbian.org>
parents:
diff changeset
    38
 * Send a request to the server.
77a56c951f86 Fixed build for Qt desktop
James Aley <jamesa@symbian.org>
parents:
diff changeset
    39
 * @param aSerializedData serialized by the caller.
77a56c951f86 Fixed build for Qt desktop
James Aley <jamesa@symbian.org>
parents:
diff changeset
    40
 * @param aInterfaceName Interface name
77a56c951f86 Fixed build for Qt desktop
James Aley <jamesa@symbian.org>
parents:
diff changeset
    41
 * @param requestType Opcode
77a56c951f86 Fixed build for Qt desktop
James Aley <jamesa@symbian.org>
parents:
diff changeset
    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
77a56c951f86 Fixed build for Qt desktop
James Aley <jamesa@symbian.org>
parents:
diff changeset
    44
                             SmfRequestTypeID requestType)
77a56c951f86 Fixed build for Qt desktop
James Aley <jamesa@symbian.org>
parents:
diff changeset
    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
77a56c951f86 Fixed build for Qt desktop
James Aley <jamesa@symbian.org>
parents:
diff changeset
    51
}
77a56c951f86 Fixed build for Qt desktop
James Aley <jamesa@symbian.org>
parents:
diff changeset
    52
77a56c951f86 Fixed build for Qt desktop
James Aley <jamesa@symbian.org>
parents:
diff changeset
    53
/**
77a56c951f86 Fixed build for Qt desktop
James Aley <jamesa@symbian.org>
parents:
diff changeset
    54
 * This overloaded API is for ESmfGetServices, where data should be
77a56c951f86 Fixed build for Qt desktop
James Aley <jamesa@symbian.org>
parents:
diff changeset
    55
 * fetched synchronously
77a56c951f86 Fixed build for Qt desktop
James Aley <jamesa@symbian.org>
parents:
diff changeset
    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
77a56c951f86 Fixed build for Qt desktop
James Aley <jamesa@symbian.org>
parents:
diff changeset
    58
            SmfRequestTypeID requestType)
77a56c951f86 Fixed build for Qt desktop
James Aley <jamesa@symbian.org>
parents:
diff changeset
    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
77a56c951f86 Fixed build for Qt desktop
James Aley <jamesa@symbian.org>
parents:
diff changeset
    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
77a56c951f86 Fixed build for Qt desktop
James Aley <jamesa@symbian.org>
parents:
diff changeset
    70
}
77a56c951f86 Fixed build for Qt desktop
James Aley <jamesa@symbian.org>
parents:
diff changeset
    71
77a56c951f86 Fixed build for Qt desktop
James Aley <jamesa@symbian.org>
parents:
diff changeset
    72
/**
77a56c951f86 Fixed build for Qt desktop
James Aley <jamesa@symbian.org>
parents:
diff changeset
    73
 * For testing purpose only
77a56c951f86 Fixed build for Qt desktop
James Aley <jamesa@symbian.org>
parents:
diff changeset
    74
 */
77a56c951f86 Fixed build for Qt desktop
James Aley <jamesa@symbian.org>
parents:
diff changeset
    75
int SmfClientQt::sendDummyRequest(QByteArray* provider,QString aInterfaceName,
77a56c951f86 Fixed build for Qt desktop
James Aley <jamesa@symbian.org>
parents:
diff changeset
    76
            SmfRequestTypeID requestType)
77a56c951f86 Fixed build for Qt desktop
James Aley <jamesa@symbian.org>
parents:
diff changeset
    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
77a56c951f86 Fixed build for Qt desktop
James Aley <jamesa@symbian.org>
parents:
diff changeset
    81
}
77a56c951f86 Fixed build for Qt desktop
James Aley <jamesa@symbian.org>
parents:
diff changeset
    82
77a56c951f86 Fixed build for Qt desktop
James Aley <jamesa@symbian.org>
parents:
diff changeset
    83
/**
77a56c951f86 Fixed build for Qt desktop
James Aley <jamesa@symbian.org>
parents:
diff changeset
    84
* CancelRequest.
77a56c951f86 Fixed build for Qt desktop
James Aley <jamesa@symbian.org>
parents:
diff changeset
    85
* Cancels an outstanding request.
77a56c951f86 Fixed build for Qt desktop
James Aley <jamesa@symbian.org>
parents:
diff changeset
    86
*/
77a56c951f86 Fixed build for Qt desktop
James Aley <jamesa@symbian.org>
parents:
diff changeset
    87
void SmfClientQt::CancelRequest()
77a56c951f86 Fixed build for Qt desktop
James Aley <jamesa@symbian.org>
parents:
diff changeset
    88
{
77a56c951f86 Fixed build for Qt desktop
James Aley <jamesa@symbian.org>
parents:
diff changeset
    89
77a56c951f86 Fixed build for Qt desktop
James Aley <jamesa@symbian.org>
parents:
diff changeset
    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
}