datasourcemodules/bluetoothgpspositioningmodule/btgpspsy/src/Utils/btgpsdevman.cpp
changeset 36 b47902b73a93
parent 0 9cfd9a3ee49c
equal deleted inserted replaced
35:a2efdd544abf 36:b47902b73a93
       
     1 // Copyright (c) 2007-2009 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 //
       
    15 
       
    16 #include "btgpsdevman.h"    
       
    17 #include "btgpssimstubs.h"
       
    18 
       
    19 CBTGPSDevMan::~CBTGPSDevMan()
       
    20 	{
       
    21 	Cancel();
       
    22 	if (iResponse)
       
    23 		{
       
    24 		delete iResponse;
       
    25 		}
       
    26 	iRegistryView.Close();
       
    27 	iRegServer.Close();
       
    28 	
       
    29 	};
       
    30     
       
    31 	
       
    32 CBTGPSDevMan::CBTGPSDevMan() : CActive(EPriorityStandard)
       
    33 	{
       
    34 	CActiveScheduler::Add(this);
       
    35 	};
       
    36 
       
    37 /**
       
    38  * Get an array of devices that match the search pattern, from the registry.
       
    39  * results are returned via a callback function
       
    40  * 
       
    41  * @param aSearchPattern Search criteria for the devices to be returned
       
    42  * @param aDeviceArray Array owned by the client in which the result will be returned. Ownership is not transferred so this pointer must remain valid until the callback is made.
       
    43  */
       
    44 TInt CBTGPSDevMan::GetDevices(TBTRegistrySearch& aSearchPattern, RBTDeviceArray* aDeviceArray)
       
    45 	{
       
    46 	iDeviceArray = aDeviceArray;
       
    47 	Find(aSearchPattern);
       
    48 	return KErrNone;
       
    49 	};
       
    50     
       
    51 /**
       
    52  * Two Stage constructor
       
    53  * @param aObserver Interface used to call back when results are ready to be returned
       
    54  */
       
    55 CBTGPSDevMan* CBTGPSDevMan::NewL(MBTGPSDevManObserver* aObserver)
       
    56 	{
       
    57 	CBTGPSDevMan* self = new(ELeave) CBTGPSDevMan();
       
    58 	CleanupStack::PushL(self);
       
    59 	self->ConstructL(aObserver);
       
    60 	CleanupStack::Pop(self);
       
    61 	return self;
       
    62 	};
       
    63 
       
    64 	
       
    65 void CBTGPSDevMan::ConstructL(MBTGPSDevManObserver* aObserver)
       
    66 	{
       
    67 	iObserver = aObserver;
       
    68 	User::LeaveIfError(iRegServer.Connect());
       
    69 	User::LeaveIfError(iRegistryView.Open(iRegServer));
       
    70 	iResponse = CBTRegistryResponse::NewL(iRegistryView);
       
    71 	iDeviceArray = &(iResponse->Results());
       
    72 	};
       
    73 	
       
    74 
       
    75 void CBTGPSDevMan::DoCancel()
       
    76 	{
       
    77 	iRegistryView.CancelRequest(iStatus);
       
    78 	if (iResponse)
       
    79 		{
       
    80 		iResponse->Cancel();
       
    81 		}
       
    82 	};
       
    83 	
       
    84 
       
    85 void CBTGPSDevMan::RunL()
       
    86 	{
       
    87 	if ( iStatus >= KErrNone)
       
    88 		{
       
    89 		switch (iRegistryState)
       
    90 			{
       
    91 			case EFinding:
       
    92 				{
       
    93 				// search has completed, get the resultset
       
    94 				iResponse->Start(iStatus);
       
    95 				iRegistryState = EGetting;
       
    96 				SetActive ();
       
    97 				}
       
    98 				break;
       
    99 			case EGetting:
       
   100 				{
       
   101 				Deque();
       
   102 				iDeviceArray = &(iResponse->Results());
       
   103 				
       
   104 				#ifdef LBS_BTGPSPSY_SIM
       
   105 				TRAP_IGNORE(AddSimulatedPairedDevicesL(iDeviceArray));
       
   106 				#endif
       
   107 				
       
   108 				iObserver->HandleGetDevicesComplete(KErrNone, iDeviceArray);
       
   109 				}
       
   110 				break;
       
   111 			}
       
   112 		}
       
   113 	else
       
   114 		if (iStatus < KErrNone)
       
   115 			{
       
   116 			#ifdef LBS_BTGPSPSY_SIM
       
   117 			// Still need to add simulated paired devices if PSY is being build in simulation mode
       
   118 			TRAP_IGNORE(AddSimulatedPairedDevicesL(iDeviceArray));
       
   119 			if (iDeviceArray->Count() > 0)
       
   120 				{
       
   121 				iStatus = KErrNone;
       
   122 				}
       
   123 			#endif
       
   124 		
       
   125 			Deque();
       
   126 			iObserver->HandleGetDevicesComplete(iStatus.Int(), iDeviceArray);
       
   127 			}
       
   128 	};
       
   129 	
       
   130 TInt CBTGPSDevMan::RunError(TInt aError)
       
   131 	{
       
   132 	if(aError == KErrNoMemory)
       
   133 		{
       
   134 		iObserver->HandleGetDevicesComplete(KErrNoMemory, iDeviceArray);
       
   135 		return KErrNone;
       
   136 		}
       
   137 	return aError;
       
   138 	}
       
   139 	
       
   140 void CBTGPSDevMan::Find(TBTRegistrySearch aSearchPattern)
       
   141 	{
       
   142 	iRegistryView.CreateView(aSearchPattern, iStatus);
       
   143 	iRegistryState = EFinding;
       
   144 	SetActive();
       
   145 	};
       
   146