smf/smfservermodule/smfserver/server/smfserverqtsession.cpp
author cgandhi
Mon, 11 Oct 2010 21:59:54 +0530
changeset 26 83d6a149c755
parent 18 013a02bf2bb0
permissions -rw-r--r--
Submitting following changes - AuthApps for Last.fm and Twitter added API for checking ServiceAuthorization added for SMFCredMgrClient API added for forcefully removing credential details from SMFCredMgr Extra argument checks in SMfClient APIs APIs for service login and logout from SMFClient Redundant members removed from SmfServerSymbian DSM bug fixes Test Apps included

/**
 * Copyright (c) 2010 Sasken Communication Technologies Ltd.
 * All rights reserved.
 * This component and the accompanying materials are made available
 * under the terms of the "Eclipse Public License v1.0"
 * which accompanies  this distribution, and is available
 * at the URL "http://www.eclipse.org/legal/epl-v10.html"
 *
 * Initial Contributors:
 * Chandradeep Gandhi, Sasken Communication Technologies Ltd - Initial contribution
 *
 * Contributors:
 * Manasij Roy, Nalina Hariharan
 *
 * Description: Session implementation for Qt desktop builds
 *
 */

#include <qdebug.h>

#include "smfserverqtsession.h"
#include "smfserverqt_p.h"
#include "smfserver.h"

SmfServerQtSession::SmfServerQtSession(QLocalSocket *clientConnection, SmfServerQt *server)
    : m_opCode(-1), m_clientConnection(clientConnection), m_server(server)
	{
    connect(m_clientConnection, SIGNAL(readyRead()), this, SLOT(readDataFromClient()));
    connect(m_clientConnection, SIGNAL(error(QLocalSocket::LocalSocketError)),
            this, SLOT(socketError(QLocalSocket::LocalSocketError)));
	}

SmfServerQtSession::~SmfServerQtSession()
	{
    // The socket has the QLocalServer as a parent, but it should be deleted to
    // save unnecessary accumulation of these objects in memory. It won't be double deleted.
    delete m_clientConnection;
	}

void SmfServerQtSession::readDataFromClient()
	{
    // TODO: This needs to be much safer.
    if(m_clientConnection->bytesAvailable() < sizeof(typeof(SmfRequestTypeID)))
    	{
        // Don't read yet, haven't received opcode
        return;
    	}

    if (m_opCode == -1)
    	{
        QDataStream in(m_clientConnection);
        in >> m_opCode;
    	}

    // m_opCode set, so handle request
    handleRequest();
	}

/**
 * Call the appropriate handler function
 */
void SmfServerQtSession::handleRequest()
	{
    switch (m_opCode)
		{
		case SmfGetService:
			handleGetService();
			break;
		default:
			qDebug()<<"Bad Request received =  "<<m_opCode);
		}
	}

/**
 * Find available services for specified interface and return list to client.
 */
void SmfServerQtSession::handleGetService()
	{
    qDebug()<<"SmfServerQtSession::handleGetService()";

    QDataStream in(m_clientConnection);

    // Get interface type requested
    SmfInterfaceID ifName;
    in >> ifName;
    qDebug()<<"Requested = "<<ifName;

    // Get the available services for this interface
    QMap<SmfPluginID, SmfProvider> services;
    m_server->wrapper()->getPlugins(ifName, services);

    // write back the results
    QDataStream out(m_clientConnection);
    out << services;
	}

void SmfServerQtSession::clientAuthorizationFinished(bool success)
	{
    Q_UNUSED(success);
	}

void SmfServerQtSession::socketError(QLocalSocket::LocalSocketError error)
	{
    switch (error)
		{
		case QLocalSocket::PeerClosedError:
			qDebug()<<"Peer closed connection.";
			break;
		case QLocalSocket::SocketTimeoutError:
			qDebug()<<"error: connection timed out.";
			break;
		default:
			qDebug()<<"error: unkown socket error: "<<error;
			break;
		}
	}