smf/smfservermodule/smfserver/server/smfserverqtsession.cpp
author cgandhi
Thu, 05 Aug 2010 16:48:48 +0530
changeset 18 013a02bf2bb0
parent 13 b5d63d5fc252
permissions -rw-r--r--
pushing changes for common libs and trace messages
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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
 * 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
    16
 *
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
18
013a02bf2bb0 pushing changes for common libs and trace messages
cgandhi
parents: 13
diff changeset
    19
#include <qdebug.h>
013a02bf2bb0 pushing changes for common libs and trace messages
cgandhi
parents: 13
diff changeset
    20
13
b5d63d5fc252 Basic functionality on desktop server build. Started a test for GetServices
James Aley <jamesa@symbian.org>
parents:
diff changeset
    21
#include "smfserverqtsession.h"
b5d63d5fc252 Basic functionality on desktop server build. Started a test for GetServices
James Aley <jamesa@symbian.org>
parents:
diff changeset
    22
#include "smfserverqt_p.h"
b5d63d5fc252 Basic functionality on desktop server build. Started a test for GetServices
James Aley <jamesa@symbian.org>
parents:
diff changeset
    23
#include "smfserver.h"
b5d63d5fc252 Basic functionality on desktop server build. Started a test for GetServices
James Aley <jamesa@symbian.org>
parents:
diff changeset
    24
b5d63d5fc252 Basic functionality on desktop server build. Started a test for GetServices
James Aley <jamesa@symbian.org>
parents:
diff changeset
    25
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
    26
    : m_opCode(-1), m_clientConnection(clientConnection), m_server(server)
18
013a02bf2bb0 pushing changes for common libs and trace messages
cgandhi
parents: 13
diff changeset
    27
	{
13
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(readyRead()), this, SLOT(readDataFromClient()));
b5d63d5fc252 Basic functionality on desktop server build. Started a test for GetServices
James Aley <jamesa@symbian.org>
parents:
diff changeset
    29
    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
    30
            this, SLOT(socketError(QLocalSocket::LocalSocketError)));
18
013a02bf2bb0 pushing changes for common libs and trace messages
cgandhi
parents: 13
diff changeset
    31
	}
13
b5d63d5fc252 Basic functionality on desktop server build. Started a test for GetServices
James Aley <jamesa@symbian.org>
parents:
diff changeset
    32
b5d63d5fc252 Basic functionality on desktop server build. Started a test for GetServices
James Aley <jamesa@symbian.org>
parents:
diff changeset
    33
SmfServerQtSession::~SmfServerQtSession()
18
013a02bf2bb0 pushing changes for common libs and trace messages
cgandhi
parents: 13
diff changeset
    34
	{
13
b5d63d5fc252 Basic functionality on desktop server build. Started a test for GetServices
James Aley <jamesa@symbian.org>
parents:
diff changeset
    35
    // 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
    36
    // 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
    37
    delete m_clientConnection;
18
013a02bf2bb0 pushing changes for common libs and trace messages
cgandhi
parents: 13
diff changeset
    38
	}
13
b5d63d5fc252 Basic functionality on desktop server build. Started a test for GetServices
James Aley <jamesa@symbian.org>
parents:
diff changeset
    39
b5d63d5fc252 Basic functionality on desktop server build. Started a test for GetServices
James Aley <jamesa@symbian.org>
parents:
diff changeset
    40
void SmfServerQtSession::readDataFromClient()
18
013a02bf2bb0 pushing changes for common libs and trace messages
cgandhi
parents: 13
diff changeset
    41
	{
13
b5d63d5fc252 Basic functionality on desktop server build. Started a test for GetServices
James Aley <jamesa@symbian.org>
parents:
diff changeset
    42
    // 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
    43
    if(m_clientConnection->bytesAvailable() < sizeof(typeof(SmfRequestTypeID)))
18
013a02bf2bb0 pushing changes for common libs and trace messages
cgandhi
parents: 13
diff changeset
    44
    	{
13
b5d63d5fc252 Basic functionality on desktop server build. Started a test for GetServices
James Aley <jamesa@symbian.org>
parents:
diff changeset
    45
        // 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
    46
        return;
18
013a02bf2bb0 pushing changes for common libs and trace messages
cgandhi
parents: 13
diff changeset
    47
    	}
13
b5d63d5fc252 Basic functionality on desktop server build. Started a test for GetServices
James Aley <jamesa@symbian.org>
parents:
diff changeset
    48
b5d63d5fc252 Basic functionality on desktop server build. Started a test for GetServices
James Aley <jamesa@symbian.org>
parents:
diff changeset
    49
    if (m_opCode == -1)
18
013a02bf2bb0 pushing changes for common libs and trace messages
cgandhi
parents: 13
diff changeset
    50
    	{
13
b5d63d5fc252 Basic functionality on desktop server build. Started a test for GetServices
James Aley <jamesa@symbian.org>
parents:
diff changeset
    51
        QDataStream in(m_clientConnection);
b5d63d5fc252 Basic functionality on desktop server build. Started a test for GetServices
James Aley <jamesa@symbian.org>
parents:
diff changeset
    52
        in >> m_opCode;
18
013a02bf2bb0 pushing changes for common libs and trace messages
cgandhi
parents: 13
diff changeset
    53
    	}
13
b5d63d5fc252 Basic functionality on desktop server build. Started a test for GetServices
James Aley <jamesa@symbian.org>
parents:
diff changeset
    54
b5d63d5fc252 Basic functionality on desktop server build. Started a test for GetServices
James Aley <jamesa@symbian.org>
parents:
diff changeset
    55
    // 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
    56
    handleRequest();
18
013a02bf2bb0 pushing changes for common libs and trace messages
cgandhi
parents: 13
diff changeset
    57
	}
13
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
/**
b5d63d5fc252 Basic functionality on desktop server build. Started a test for GetServices
James Aley <jamesa@symbian.org>
parents:
diff changeset
    60
 * 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
    61
 */
b5d63d5fc252 Basic functionality on desktop server build. Started a test for GetServices
James Aley <jamesa@symbian.org>
parents:
diff changeset
    62
void SmfServerQtSession::handleRequest()
18
013a02bf2bb0 pushing changes for common libs and trace messages
cgandhi
parents: 13
diff changeset
    63
	{
13
b5d63d5fc252 Basic functionality on desktop server build. Started a test for GetServices
James Aley <jamesa@symbian.org>
parents:
diff changeset
    64
    switch (m_opCode)
18
013a02bf2bb0 pushing changes for common libs and trace messages
cgandhi
parents: 13
diff changeset
    65
		{
013a02bf2bb0 pushing changes for common libs and trace messages
cgandhi
parents: 13
diff changeset
    66
		case SmfGetService:
013a02bf2bb0 pushing changes for common libs and trace messages
cgandhi
parents: 13
diff changeset
    67
			handleGetService();
013a02bf2bb0 pushing changes for common libs and trace messages
cgandhi
parents: 13
diff changeset
    68
			break;
013a02bf2bb0 pushing changes for common libs and trace messages
cgandhi
parents: 13
diff changeset
    69
		default:
013a02bf2bb0 pushing changes for common libs and trace messages
cgandhi
parents: 13
diff changeset
    70
			qDebug()<<"Bad Request received =  "<<m_opCode);
013a02bf2bb0 pushing changes for common libs and trace messages
cgandhi
parents: 13
diff changeset
    71
		}
013a02bf2bb0 pushing changes for common libs and trace messages
cgandhi
parents: 13
diff changeset
    72
	}
13
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
/**
b5d63d5fc252 Basic functionality on desktop server build. Started a test for GetServices
James Aley <jamesa@symbian.org>
parents:
diff changeset
    75
 * 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
    76
 */
b5d63d5fc252 Basic functionality on desktop server build. Started a test for GetServices
James Aley <jamesa@symbian.org>
parents:
diff changeset
    77
void SmfServerQtSession::handleGetService()
18
013a02bf2bb0 pushing changes for common libs and trace messages
cgandhi
parents: 13
diff changeset
    78
	{
013a02bf2bb0 pushing changes for common libs and trace messages
cgandhi
parents: 13
diff changeset
    79
    qDebug()<<"SmfServerQtSession::handleGetService()";
13
b5d63d5fc252 Basic functionality on desktop server build. Started a test for GetServices
James Aley <jamesa@symbian.org>
parents:
diff changeset
    80
b5d63d5fc252 Basic functionality on desktop server build. Started a test for GetServices
James Aley <jamesa@symbian.org>
parents:
diff changeset
    81
    QDataStream in(m_clientConnection);
b5d63d5fc252 Basic functionality on desktop server build. Started a test for GetServices
James Aley <jamesa@symbian.org>
parents:
diff changeset
    82
b5d63d5fc252 Basic functionality on desktop server build. Started a test for GetServices
James Aley <jamesa@symbian.org>
parents:
diff changeset
    83
    // Get interface type requested
b5d63d5fc252 Basic functionality on desktop server build. Started a test for GetServices
James Aley <jamesa@symbian.org>
parents:
diff changeset
    84
    SmfInterfaceID ifName;
b5d63d5fc252 Basic functionality on desktop server build. Started a test for GetServices
James Aley <jamesa@symbian.org>
parents:
diff changeset
    85
    in >> ifName;
18
013a02bf2bb0 pushing changes for common libs and trace messages
cgandhi
parents: 13
diff changeset
    86
    qDebug()<<"Requested = "<<ifName;
13
b5d63d5fc252 Basic functionality on desktop server build. Started a test for GetServices
James Aley <jamesa@symbian.org>
parents:
diff changeset
    87
b5d63d5fc252 Basic functionality on desktop server build. Started a test for GetServices
James Aley <jamesa@symbian.org>
parents:
diff changeset
    88
    // 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
    89
    QMap<SmfPluginID, SmfProvider> services;
b5d63d5fc252 Basic functionality on desktop server build. Started a test for GetServices
James Aley <jamesa@symbian.org>
parents:
diff changeset
    90
    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
    91
b5d63d5fc252 Basic functionality on desktop server build. Started a test for GetServices
James Aley <jamesa@symbian.org>
parents:
diff changeset
    92
    // write back the results
b5d63d5fc252 Basic functionality on desktop server build. Started a test for GetServices
James Aley <jamesa@symbian.org>
parents:
diff changeset
    93
    QDataStream out(m_clientConnection);
b5d63d5fc252 Basic functionality on desktop server build. Started a test for GetServices
James Aley <jamesa@symbian.org>
parents:
diff changeset
    94
    out << services;
18
013a02bf2bb0 pushing changes for common libs and trace messages
cgandhi
parents: 13
diff changeset
    95
	}
13
b5d63d5fc252 Basic functionality on desktop server build. Started a test for GetServices
James Aley <jamesa@symbian.org>
parents:
diff changeset
    96
b5d63d5fc252 Basic functionality on desktop server build. Started a test for GetServices
James Aley <jamesa@symbian.org>
parents:
diff changeset
    97
void SmfServerQtSession::clientAuthorizationFinished(bool success)
18
013a02bf2bb0 pushing changes for common libs and trace messages
cgandhi
parents: 13
diff changeset
    98
	{
13
b5d63d5fc252 Basic functionality on desktop server build. Started a test for GetServices
James Aley <jamesa@symbian.org>
parents:
diff changeset
    99
    Q_UNUSED(success);
18
013a02bf2bb0 pushing changes for common libs and trace messages
cgandhi
parents: 13
diff changeset
   100
	}
13
b5d63d5fc252 Basic functionality on desktop server build. Started a test for GetServices
James Aley <jamesa@symbian.org>
parents:
diff changeset
   101
b5d63d5fc252 Basic functionality on desktop server build. Started a test for GetServices
James Aley <jamesa@symbian.org>
parents:
diff changeset
   102
void SmfServerQtSession::socketError(QLocalSocket::LocalSocketError error)
18
013a02bf2bb0 pushing changes for common libs and trace messages
cgandhi
parents: 13
diff changeset
   103
	{
13
b5d63d5fc252 Basic functionality on desktop server build. Started a test for GetServices
James Aley <jamesa@symbian.org>
parents:
diff changeset
   104
    switch (error)
18
013a02bf2bb0 pushing changes for common libs and trace messages
cgandhi
parents: 13
diff changeset
   105
		{
013a02bf2bb0 pushing changes for common libs and trace messages
cgandhi
parents: 13
diff changeset
   106
		case QLocalSocket::PeerClosedError:
013a02bf2bb0 pushing changes for common libs and trace messages
cgandhi
parents: 13
diff changeset
   107
			qDebug()<<"Peer closed connection.";
013a02bf2bb0 pushing changes for common libs and trace messages
cgandhi
parents: 13
diff changeset
   108
			break;
013a02bf2bb0 pushing changes for common libs and trace messages
cgandhi
parents: 13
diff changeset
   109
		case QLocalSocket::SocketTimeoutError:
013a02bf2bb0 pushing changes for common libs and trace messages
cgandhi
parents: 13
diff changeset
   110
			qDebug()<<"error: connection timed out.";
013a02bf2bb0 pushing changes for common libs and trace messages
cgandhi
parents: 13
diff changeset
   111
			break;
013a02bf2bb0 pushing changes for common libs and trace messages
cgandhi
parents: 13
diff changeset
   112
		default:
013a02bf2bb0 pushing changes for common libs and trace messages
cgandhi
parents: 13
diff changeset
   113
			qDebug()<<"error: unkown socket error: "<<error;
013a02bf2bb0 pushing changes for common libs and trace messages
cgandhi
parents: 13
diff changeset
   114
			break;
013a02bf2bb0 pushing changes for common libs and trace messages
cgandhi
parents: 13
diff changeset
   115
		}
013a02bf2bb0 pushing changes for common libs and trace messages
cgandhi
parents: 13
diff changeset
   116
	}