bluetoothmgmt/btmgr/BTManServer/btmanserverburmgr.h
branchRCL_3
changeset 13 20fda83a6398
child 18 f8503e232b0c
equal deleted inserted replaced
12:8a27654f7b62 13:20fda83a6398
       
     1 // Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies).
       
     2 // All rights reserved.
       
     3 // This component and the accompanying materials are made available
       
     4 // under the terms of "Eclipse Public License v1.0"
       
     5 // which accompanies this distribution, and is available
       
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     7 //
       
     8 // Initial Contributors:
       
     9 // Nokia Corporation - initial contribution.
       
    10 //
       
    11 // Contributors:
       
    12 //
       
    13 // Description:
       
    14 // Implements backup and restore support for the Bluetooth Manager server.
       
    15 //
       
    16 
       
    17 /**
       
    18  @file
       
    19  @internalAll
       
    20 */
       
    21 
       
    22 #ifndef BTMANSERVERBURMGR_H
       
    23 #define BTMANSERVERBURMGR_H
       
    24 
       
    25 #include <connect/abclient.h>
       
    26 
       
    27 #include "BTRegistryDB.h"
       
    28 
       
    29 #include "btmanserverburstatemachine.h"
       
    30 
       
    31 using namespace conn;
       
    32 
       
    33 _LIT(KBTBackupPanicCat, "BTManServer BUR Panic");
       
    34 // Used to allow state information to be encoded into a panic code.
       
    35 const TInt KBTBackupStatePanicMultiplier = 1000000;
       
    36 const TInt KBTBackupStateMultiplier = 1000;
       
    37 // Used to seperate the panic and state / event values in a panic code.
       
    38 const TInt KBTBackupStatePanicMajorDelimiter = 100000;
       
    39 const TInt KBTBackupStatePanicMinorDelimiter = 100;
       
    40 
       
    41 /**
       
    42 TBTBackupPanic - Panics that may be raised by the BUR manager
       
    43 **/
       
    44 enum TBTBackupPanic
       
    45 	{
       
    46 	EBTBURMgrAlreadyInOperation			= 0,	// A backup/restore event has been received during an ongoing BUR operation
       
    47 	EBTBURMgrExpectedDataMissing			= 1,	// An operation has found that it is missing essential data
       
    48 	EBTBURMgrBUROperationStartAlreadyNotified	= 2,	// An MBTNotify instance has already been told that a BUR operation has started (and has not received a corresponding BUROperationStop notification)
       
    49 	EBTBURMgrBUROperationStartNotNotified		= 3,	// An MBTNotify instance has been notified that a BUR operation has stopped, without receiving notification that it had started.
       
    50 
       
    51 	EBTBURMgrNoSessionAdded				= 4,	// No session has been registered on BTManServer for the BUR manager
       
    52 	EBTBURMgrInvalidRemoteDeviceIndex		= 5,	// An index for a remote device is invalid.
       
    53 	EBTBURMgrInvalidStateTransition			= 6,	// An attempted state transition was invalid.
       
    54 	EBTBURMgrInvalidState				= 7,	// Either the requested state was invalid or the current state is not valid for some operation.
       
    55 	EBTBURMgrInvalidStateIndex			= 8,	// A given state index is invalid.
       
    56 	EBTBURMgrMissingLocalAddress			= 9,	// A nonzero local address was expected but not found
       
    57 	EBTBURMgrUnexpectedMethodCall			= 10,	// A method was unexpectedly called
       
    58 	EBTBURMgrArraySizeMisMatch			= 11,	// An array does not have the expected size
       
    59 	EBTBURMgrUnknownBUREvent			= 12,	// An unrecognised backup or restore event was received.
       
    60 	EBTBURMgrActiveBackupClientNull			= 13,	// A pointer to a CActiveBackupClient instance is unexpectedly NULL
       
    61 	EBTBURMgrUnsupportedRegistryVersion		= 14,	// A new version of the registry is being used locally, which is not yet supported by this implementation.
       
    62 	EBTBURMgrUnexpectedRPropertyError		= 15,	// An RProperty::Get() call returned an error that was not expected.
       
    63 	EBTBURMgrInvalidBackupRestoreState		= 16,	// The masked value from the KUidBackupRestoreKey P&S key was not in the range of the TBURPartType enum.
       
    64 	EBTBURMgrDescriptorLengthTooLong		= 17,	// A descriptor length is greater than expected.
       
    65 	EBTBURMgrDescriptorUnexpectedLength		= 18,	// A descriptor length is different to what was expected.
       
    66 	};
       
    67 
       
    68 // The name of the backup file to which the BT registry will be copied to.
       
    69 _LIT(KBTManServerBackupFileName, "btregistrydb.bak");
       
    70 // The name of the restore file from which the BT registry will be restored from.
       
    71 _LIT(KBTManServerRestoreFileName, "btregistrydb.rst");
       
    72 
       
    73 // Some data range maximum values (where predefined const values are not available elsewhere)
       
    74 const TUint8 KBTBURMgrMaxGlobalSecurityValue	= 0x1F;		// All security options on in TBTDeviceSecurity
       
    75 const TUint8 KBTBURMgrMaxPageScanMode		= 0x3;		// Optional page scan mode III
       
    76 const TUint8 KBTBURMgrMaxPageScanPeriodMode	= 0x2;		// P2
       
    77 
       
    78 void InvalidStateTransitionPanic(TBTBURState aCurrentState, TBTBUREvent aEvent);
       
    79 
       
    80 
       
    81 class MBTBURNotify
       
    82 	{
       
    83 public:
       
    84 	/**
       
    85 	Invoked by CBTManServerBURMgr to provide notification that a backup or restore
       
    86 	operation has started.
       
    87 	**/
       
    88 	virtual void BUROperationStarted()=0;
       
    89 
       
    90 	/**
       
    91 	Invoked by CBTManServerBURMgr to provide notification that a backup or restore
       
    92 	operation has stopped.
       
    93 	**/
       
    94 	virtual void BUROperationStopped()=0;
       
    95 
       
    96 	};
       
    97 
       
    98 class CBTManServer;
       
    99 class CBTLocalAddressFetcher;
       
   100 class CBTBackupHandler;
       
   101 class CBTRestoreHandler;
       
   102 class CBTActiveBackupDataClient;
       
   103 
       
   104 NONSHARABLE_CLASS(CBTManServerBURMgr) : public CActive
       
   105 	{
       
   106 public:
       
   107 	static CBTManServerBURMgr* NewL(CBTManServer& aBTManServer, MBTBURNotify* aBURNotify, TInt aPriority=EPriorityStandard);
       
   108 	~CBTManServerBURMgr();
       
   109 
       
   110 	void RequestBURNotification(MBTBURNotify* aBURNotify);
       
   111 	void SetLocalAddress(TBTDevAddr& aLocalAddr);
       
   112 	void RestoreFileReady();
       
   113 
       
   114 	// Implementation of normal state action
       
   115 	void HandleStateNormal();
       
   116 
       
   117 	// Implementation of backup state-specific actions.
       
   118 	void HandleStateBackupRequestL();
       
   119 	void HandleStateBackupRequestError();
       
   120 	void HandleStateBackupOngoingL();
       
   121 	void HandleStateBackupOngoingError();
       
   122 	void HandleStateBackupIgnore();
       
   123 	
       
   124 	// Implementation of restore state-specific actions.
       
   125 	void HandleStateRestoreRequestL();
       
   126 	void HandleStateRestoreRequestError();
       
   127 	void HandleStateRestoreOngoingL();
       
   128 	void HandleStateRestoreOngoingError();
       
   129 	void HandleStateRestoreIgnore();
       
   130 
       
   131 	// Implementation of restore file processing state-specific actions.
       
   132 	void HandleStateProcessRestoreFileL();
       
   133 	void HandleStateProcessRestoreFileError(TInt aError);
       
   134 	void HandleStateRestoreFileProcessingComplete();
       
   135 
       
   136 	inline TInt TransitionState(TBTBUREvent aBUREvent);
       
   137 
       
   138 private:
       
   139 	CBTManServerBURMgr(CBTManServer& aBTManServer, MBTBURNotify* aBURNotify, TInt aPriority);
       
   140 	void ConstructL();
       
   141 
       
   142 	TBURPartType GetBURPartType(TInt aValue);
       
   143 
       
   144 	TBool RestoreFilePresent();
       
   145 	void CheckForRestoreFileL();
       
   146 
       
   147 	void SubscribeToBackupRestoreKey();
       
   148 	void ProcessBackupState(TBURPartType aBURStateValue);	
       
   149 	TBool DoesBURAffectMeL(CActiveBackupClient& aClient);
       
   150 
       
   151 	void NotifyBUROperationStarted();
       
   152 	void NotifyBUROperationStopped();
       
   153 	void NotifyAnyBUROperationStopped();
       
   154 
       
   155 	void DeleteFile(const TDesC& fileName);
       
   156 	void DeleteBackupFile();
       
   157 	void DeleteRestoreFile();
       
   158 
       
   159 	void RenameBackupFileForRestore();
       
   160 	void UpdateLocalDeviceNameL();
       
   161 
       
   162 	// From CActive:
       
   163 	void RunL();
       
   164 	TInt RunError(TInt aError);
       
   165 	void DoCancel();
       
   166 
       
   167 private:
       
   168 	CBTManServer& iBTManServer;
       
   169 	MBTBURNotify* iBURNotify;	// Does not own this object.
       
   170 
       
   171 	TBURPartType iBURState;
       
   172 
       
   173 	CActiveBackupClient* iActiveBackupClient;
       
   174 	RProperty iProperty;
       
   175 	CBTLocalAddressFetcher* iLocalAddrFetcher;
       
   176 
       
   177 	CBTManServerBURMgrStateFactory* iStateMachine;
       
   178 
       
   179 	CBTActiveBackupDataClient* iActiveBackupDataClient;
       
   180 	
       
   181 	TBool iBUROperationStartNotified;
       
   182 
       
   183 	CBTBackupHandler* iBackupHandler;
       
   184 	CBTRestoreHandler* iRestoreHandler;
       
   185 
       
   186 	TBTDevAddr iLocalAddr;
       
   187 
       
   188 	};
       
   189 
       
   190 class CBTRegistryBURData;
       
   191 
       
   192 NONSHARABLE_CLASS(CBTBackupHandler) : public CBase
       
   193 	{
       
   194 public:
       
   195 	static CBTBackupHandler* NewL(CBTManServerBURMgr& aBURMgr, CBTRegistry& aRegistry);
       
   196 	~CBTBackupHandler();
       
   197 
       
   198 	void CreateBackupFileL();
       
   199 
       
   200 private:
       
   201 	CBTBackupHandler(CBTManServerBURMgr& aBURMgr, CBTRegistry& aRegistry);
       
   202 	void ConstructL();
       
   203 
       
   204 private:
       
   205 	CBTManServerBURMgr& iBURMgr;
       
   206 	CBTRegistry& iRegistry;
       
   207 	CBTRegistryBURData* iRegistryData;
       
   208 	};
       
   209 
       
   210 NONSHARABLE_CLASS(CBTRestoreHandler) : public CBase
       
   211 	{ 
       
   212 public:
       
   213 	static CBTRestoreHandler* NewL(CBTManServerBURMgr& aBURMgr, CBTManServer& aManServer);
       
   214 	~CBTRestoreHandler();
       
   215 
       
   216 	void RestoreLocalDeviceNameL();
       
   217 	void RestoreRemoteDeviceTableL(TBTDevAddr& aLocalAddr);
       
   218 
       
   219 private:
       
   220 	CBTRestoreHandler(CBTManServerBURMgr& aBURMgr, CBTManServer& aManServer);
       
   221 	void ConstructL();
       
   222 
       
   223 	void LoadRestoreDataL();
       
   224 
       
   225 	void NotifyLocalTableChange();
       
   226 	void NotifyRemoteTableChangeL(const TBTDevAddr& aAddress);
       
   227 
       
   228 private:
       
   229 	CBTManServerBURMgr& iBURMgr;
       
   230 	CBTManServer& iManServer;
       
   231 	CBTRegistryBURData* iRegistryData;
       
   232 
       
   233 	TBTDevAddr iBTLocalAddr;
       
   234 	};
       
   235 
       
   236 
       
   237 NONSHARABLE_CLASS(CBTRegistryBURData) : public CBase
       
   238 	{
       
   239 public:		
       
   240 	static CBTRegistryBURData* NewL();
       
   241 	~CBTRegistryBURData();
       
   242 
       
   243 	void WriteToStreamL(RWriteStream& aStream) const;
       
   244 	void ReadFromStreamL(RReadStream& aStream);
       
   245 
       
   246 	void ReadFromRegistryL(CBTRegistry& aRegistry);
       
   247 	TBool WriteLocalDeviceNameToRegistryL(CBTRegistry& aRegistry) const;
       
   248 	TBool WriteRemoteDeviceToRegistryL(CBTRegistry& aRegistry, TInt aDeviceIndex) const;
       
   249 
       
   250 	inline TBool HasRegistryData() const;
       
   251 
       
   252 	void GetRegistryVersionL(TUint32& aRegistryVersionMajor, TUint32& aRegistryVersionMinor) const;
       
   253 	TBool IsLocalAddressNonZeroL() const;
       
   254 	TBool IsLocalAddressEqualL(TBTDevAddr& aAddr) const;
       
   255 	TInt CountRemoteDevicesL() const;
       
   256 	const CBTDevice& GetRemoteDeviceL(TInt aDeviceIndex) const;
       
   257 	TSecureId GetRemoteDeviceEntrySidL(TInt aDeviceIndex) const;
       
   258 	
       
   259 	void ClearRegistryData();
       
   260 
       
   261 private:
       
   262 	CBTRegistryBURData();
       
   263 	void ConstructL();
       
   264 
       
   265 	const TDesC8& GetLocalDeviceNameL() const;
       
   266 
       
   267 private:
       
   268 	TBool iHasRegistryData;
       
   269 
       
   270 	// Meta table:
       
   271 	TUint32 iRegistryVersionMajor;
       
   272 	TUint32 iRegistryVersionMinor;
       
   273 
       
   274 	// Persistence table
       
   275 	TBTLocalDevice* iLocalDevice;
       
   276 
       
   277 	// Remote device table:
       
   278 	CArrayFixFlat<TSecureId>* iRemoteDevicesSid;
       
   279 	CBTDeviceArray* iRemoteDevices;
       
   280 
       
   281 	};
       
   282 
       
   283 NONSHARABLE_CLASS(CBTLocalAddressFetcher) : public CActive
       
   284 	{
       
   285 public:
       
   286 	// High priority to ensure this AO fires before a client request to BTManServer
       
   287 	static CBTLocalAddressFetcher* NewL(CBTManServerBURMgr& aBURMgr, CBTRegistry& aRegistry, TInt aPriority=EPriorityHigh);
       
   288 	~CBTLocalAddressFetcher();
       
   289 
       
   290 	void FetchLocalAddress();
       
   291 
       
   292 
       
   293 private:
       
   294 	CBTLocalAddressFetcher(CBTManServerBURMgr& aBURMgr, CBTRegistry& aRegistry, TInt aPriority);
       
   295 	void ConstructL();
       
   296 	
       
   297 	void SubscribeToGetLocalDeviceAddressKey();
       
   298 	TBTDevAddr GetLocalAddressFromRegistryL();
       
   299 
       
   300 	// From CActive
       
   301 	void RunL();
       
   302 	void DoCancel();
       
   303 private:
       
   304 	CBTManServerBURMgr& iBURMgr;
       
   305 	CBTRegistry& iRegistry;
       
   306 	RProperty iProperty;
       
   307 
       
   308 	};
       
   309 
       
   310 NONSHARABLE_CLASS(CBTActiveBackupDataClient) : public CBase, public MActiveBackupDataClient
       
   311 	{
       
   312 public:
       
   313 	static CBTActiveBackupDataClient* NewL(CBTManServerBURMgr& aBURMgr);
       
   314 	~CBTActiveBackupDataClient();
       
   315 
       
   316 	// Backup methods (not used)
       
   317 	virtual void AllSnapshotsSuppliedL();
       
   318 	virtual void ReceiveSnapshotDataL(TDriveNumber aDrive, TDesC8& aBuffer, TBool aLastSection);
       
   319 	virtual TUint GetExpectedDataSize(TDriveNumber aDrive);
       
   320 	virtual void GetSnapshotDataL(TDriveNumber aDrive, TPtr8& aBuffer, TBool& aFinished);
       
   321 	virtual void InitialiseGetBackupDataL(TDriveNumber aDrive);
       
   322 	virtual void GetBackupDataSectionL(TPtr8& aBuffer, TBool& aFinished);
       
   323 
       
   324 	// Restore methods (only the notification method RestoreComplete() is used)
       
   325 	virtual void InitialiseRestoreBaseDataL(TDriveNumber aDrive);
       
   326 	virtual void RestoreBaseDataSectionL(TDesC8& aBuffer, TBool aFinished);
       
   327 	virtual void InitialiseRestoreIncrementDataL(TDriveNumber aDrive);
       
   328 	virtual void RestoreIncrementDataSectionL(TDesC8& aBuffer, TBool aFinished);
       
   329 	virtual void RestoreComplete(TDriveNumber aDrive);
       
   330 
       
   331 	// General methods
       
   332 	virtual void TerminateMultiStageOperation();
       
   333 
       
   334 	// Test methods
       
   335 	virtual TUint GetDataChecksum(TDriveNumber aDrive);
       
   336 	
       
   337 private:
       
   338 	CBTActiveBackupDataClient(CBTManServerBURMgr& aBURMgr);
       
   339 
       
   340 private:
       
   341 	CBTManServerBURMgr& iBURMgr;
       
   342 
       
   343 	};
       
   344 
       
   345 #include "btmanserverburmgr.inl"
       
   346 
       
   347 #endif //BTMANSERVERBURMGR_H