engine/inc/ConnectionEngine.h
author Sebastian Brannstrom <sebastianb@symbian.org>
Sat, 16 Oct 2010 19:49:47 +0100
branchsymbian1
changeset 245 3f57982a6f10
parent 90 d0c0c3e6f7a1
child 176 1c8b56cb6409
child 284 69385a7c9810
permissions -rw-r--r--
Fix for 3843, Podcatcher will now stop downloading when 1 MB disk space remains

/*
 * Copyright (c) 2007-2010 Sebastian Brannstrom, Lars Persson, EmbedDev AB
 *
 * All rights reserved.
 * This component and the accompanying materials are made available
 * under the terms of the License "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:
 * EmbedDev AB - initial contribution.
 *
 * Contributors:
 *
 * Description:
 *
 */

#ifndef PODCAST_CONNECTIONENGINE_H
#define PODCAST_CONNECTIONENGINE_H


// Connect using mobility extension
#include <in_sock.h>
#include <connpref.h>
#include <commdbconnpref.h>
#include <comms-infras/cs_mobility_apiext.h>

// Using connection manager settings UI
#include <cmapplicationsettingsui.h>
class CPodcastModel;

class MConnectionObserver
	{
public:
	virtual void ConnectionSelectionStart() = 0;
	virtual void ConnectionSelectionEnd() = 0;
	virtual void ConnectCompleteL(TInt aErrorCode) = 0;
	virtual void Disconnected() = 0;
	};

/**
 * This class helps to connect using three available methods
 * SNAP, Mobility extension and Connection manager UI
 */
class CConnectionEngine:public CActive, public MMobilityProtocolResp
	{
public:
	enum TConnectionType
		{
		EUserSelectConnection,		
		ESNAPConnection,		
		EMobilityConnection,
		EDefaultConnection,
		EIAPConnection
		};
	
	enum TConnectionState
		{
		ENotConnected,
		EConnecting,
		EConnected
		};

	static CConnectionEngine* NewL(CPodcastModel& aPodcastModel);
	~CConnectionEngine();
	void StartL(TConnectionType aConnectionType);
	RConnection& Connection();
	TConnectionState ConnectionState();
	IMPORT_C void AddObserver(MConnectionObserver* aObserver);
	RSocketServ& SockServ();
	void Stop();
private: // Methods
	CConnectionEngine(CPodcastModel& aPodcastModel);
	void ConstructL();
protected:
	// From CActive
	void RunL();
	void DoCancel();
	TInt RunError( TInt aError );
protected:
	// From MMobilityProtocolResp
	void PreferredCarrierAvailable( TAccessPointInfo aOldAPInfo,
			TAccessPointInfo aNewAPInfo,
			TBool aIsUpgrade,
			TBool aIsSeamless );
	
	void NewCarrierActive( TAccessPointInfo aNewAPInfo, TBool aIsSeamless );
	void Error( TInt aError );
protected:
	// UI Setting
	TBool ConnectionSettingL();
	
	void ReportConnectionL(TInt aError);
	void ReportConnectionSelectionStart();
	void ReportConnectionSelectionEnd();
	
private:
	RConnection                   iConnection;
	RSocketServ                   iSocketServer;
	// Connect using mobility extension
	CActiveCommsMobilityApiExt*   iMobility;

	// Using connection manager settings UI
	TCmSettingSelection   iUserSelection;
	
	// Connect using Commdb
	TCommDbConnPref iCommdbPreference;
	
	// Connect using SNAP setting
	TConnSnapPref iSnapPreference;
	
	TConnectionType iConnectionType;
	TConnectionState iConnectionState;
	RPointerArray<MConnectionObserver> iObserverArray;
	CPodcastModel &iPodcastModel; 	// reference to the model
	};

#endif // PODCAST_CONNECTIONENGINE_H