smf/smfservermodule/smfserver/server/smfserver.h
author cgandhi
Mon, 11 Oct 2010 21:59:54 +0530
changeset 26 83d6a149c755
parent 25 a180113055cb
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:
 * SMF Server component which handles the client requests and delegates 
 * them propoerly to the appropriate component
 * 
 */

#ifndef SMFSERVER_H
#define SMFSERVER_H

#include <QObject>
#include <QMap>
#include <smfglobal.h>
#include <smfcredmgrclientglobal.h>

#include "smfserverglobal.h"

// Forward declarations(Other components of the SMF)
class SmfTransportManager;
class SmfPluginManager;
class SmfCredMgrClient;
class SmfProvider;
//Private implementation for different platforms
#ifdef Q_OS_SYMBIAN
	class SmfServerSymbian;
	class SmfServerSymbianSession;
#else
	class SmfServerQt;
	class SmfServerQtSession;
#endif


//For the time being, need to change later
typedef QString SmfInterfaceID;
//For the time being, need to change later
typedef QString SmfPluginID;
//TODO:- define proper enums after consulting with CM owner
typedef int NotificationType;

	
/**
 * SmfServer manages the client requests and delegates them to the appropriate SMF component,
 * service the clients synchronously or asynchronously
 */
class SmfServer : public QObject
	{
	Q_OBJECT
	
public:
	SmfServer(QObject* parent = 0);
	~SmfServer();
	
	/**
	 * Does the following,-
	 * First it'll check whether server is already running, if already 
	 * running it'll simply return
	 * else it'll start the server exe and initialize all other SMF 
	 * components returns whether server is started successfully or not
	 */
	bool startServer();
	
public:
	/**
	 * Requests Plugin Manager to get a list of plugin IDs who implement
	 * the interface interfaceID.
	 * This is used for SmfClient::GetServices () where we need a list of plugins
	 */
	void getPlugins ( const SmfInterfaceID& interfaceID, 
			QMap<SmfPluginID,SmfProvider>& pluginIDMap);
	
	/**
	 * Same as above, except this is used for rest of the requests where we need
	 * a particular plugin
	 */
	SmfPluginID getPlugin ( const SmfInterfaceID& interfaceID, SmfProvider provider);
	
	/**
	 * Requests the Credential Manager to filter out non-authorized plugin IDs
	 * from the list and get authorized plugins into authList.
	 */
	void getAuthorizedPlugins ( QList<SmfPluginID>& list, QList<SmfPluginID>& authList );
	
	/**
	 * Request CM API to get the list of authenticated plugins
	 * @see SmfCredMgrClient::authenticatedPluginList()
	 */
	QStringList getAuthenticatedPluginList ( QString RegistrationToken );
	
	/**
	 * Request the Plugin manager to get the data.
	 * @param requestID Corresponds to a client's session
	 * @param pluginID Plugin for which the request is intended
	 * @param interfaceID Interface name
	 * @param dataForPlugin Data to be sent for this request
	 */
	SmfError sendToPluginManager ( int requestID, SmfPluginID pluginID, 
			SmfInterfaceID interfaceID, SmfRequestTypeID requestTypeID,
			QByteArray dataForPlugin = QByteArray() );
	
	/**
	 * Request the Plugin manager to get the data.
	 * @param requestID Corresponds to a client's session
	 * @param pluginID Plugin for which the request is intended
	 * @param interfaceID Interface name
	 * @param dataForPlugin Data to be sent for this request
	 */
	SmfError sendToPluginManager ( SmfPluginID pluginID, 
			SmfInterfaceID interfaceID, SmfRequestTypeID requestTypeID,
			QByteArray dataForPlugin, QByteArray &outputData);
	
	/**
	 * Delegates the request to DSM and receives data synshronously.
	 * @param qtdataForDSM Data to be passed to DSM
	 * @param opcode Opcode
	 * @param qtdataFromDSM Data received from DSM
	 * @return Error value returned from DSM
	 */
	SmfError sendToDSM ( QByteArray qtdataForDSM, SmfRequestTypeID opcode,
			QByteArray& qtdataFromDSM );
	
public slots:

#ifdef Q_FOR_FUTURE
	/**
	 * This slot is called when Credential Manager is done with the autherizing
	 * the client for the first time. See isClientAuthorized() and authorizeClient().
	 * success specifies the success of the authorization, authID is the authentication
	 * ID in case its not same as SID of the client.
	 */
	void clientAuthorizationFinished ( bool success, SmfClientAuthID authID );
#endif
	
	/**
	 * This slot is called as a result of trigger from Plugin manager when the 
	 * parsed data is available.
	 * @param requestID The request ID for which result is available
	 * @param parsedData Serialized data
	 */
	void resultsAvailable ( int requestID, QByteArray* parsedData, SmfError error );

	/**
	 * This slot is called when the data store updates are available as a result of
	 * "runSavedRequest()".
	 * Note:- The "10.4.1.11	updateDatastore" can be merged with this 
	 */
	void dataStoreUpdateAvailable ( QByteArray* respData ){ Q_UNUSED(respData) }
	
	/**
	 * Server calls this method when it receives message from the CM
	 * that authentication keys for the pluginID has expired
	 */
	void authenticationKeysExpired ( NotificationType type, SmfPluginID id );

private:
	SmfTransportInitializeResult prepareTransport();

private:
	//private impl
#ifdef Q_OS_SYMBIAN
	SmfServerSymbian* m_SmfServerPrivate;
#else
	SmfServerQt* m_SmfServerPrivate;
#endif
	//Handles of other SMF components
	SmfTransportManager* m_transportManager;
	SmfPluginManager* m_pluginManager;
	SmfCredMgrClient* m_credentialMngr;
	};

#endif // SMFSERVER_H