engine/inc/ConnectionEngine.h
author Sebastian Brannstrom <sebastianb@symbian.org>
Sun, 11 Jul 2010 11:36:24 +0100
branch3rded
changeset 177 269e3f3e544a
parent 176 1c8b56cb6409
permissions -rw-r--r--
Lots of fixes for 3rd edition. First test SIS file, 0.90(3)

/*
 * 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:
	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 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