datasourcemodules/bluetoothgpspositioningmodule/btgpspsy/src/Connecting/BTGPSDeviceInfoHandler.cpp
changeset 36 b47902b73a93
parent 0 9cfd9a3ee49c
equal deleted inserted replaced
35:a2efdd544abf 36:b47902b73a93
       
     1 // Copyright (c) 2006-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 
       
    17 
       
    18 // INCLUDE FILES
       
    19 #include <e32std.h>
       
    20 #include "BTGPSDeviceManager.h"
       
    21 #include "BTGPSDeviceInfoHandler.h"
       
    22 #include "BTGPSConnectManagerExt.h"
       
    23 #include "BTGPSSettingManager.h"
       
    24 #include "BTGPSHandlerFactory.h"
       
    25 #include "BTGPSLogging.h"
       
    26 
       
    27 // EXTERNAL DATA STRUCTURES
       
    28 
       
    29 // EXTERNAL FUNCTION PROTOTYPES  
       
    30 
       
    31 // CONSTANTS
       
    32 // Device array granularity
       
    33 const TInt KBTGPSDeviceArrayGranularity = 1;
       
    34 
       
    35 // ============================= LOCAL FUNCTIONS ===============================
       
    36 
       
    37 // ============================ MEMBER FUNCTIONS ===============================
       
    38 
       
    39 
       
    40 // -----------------------------------------------------------------------------
       
    41 // CBTGPSDeviceInfoHandler::NewL
       
    42 // -----------------------------------------------------------------------------
       
    43 CBTGPSDeviceInfoHandler* CBTGPSDeviceInfoHandler::NewL(
       
    44         MBTGPSConnectManagerExt& aManagerExt)
       
    45     {
       
    46     CBTGPSDeviceInfoHandler* self = new (ELeave) CBTGPSDeviceInfoHandler(
       
    47         aManagerExt);
       
    48     CleanupStack::PushL(self);
       
    49     self->ConstructL();
       
    50     CleanupStack::Pop();
       
    51     return self;
       
    52     }
       
    53 
       
    54 // -----------------------------------------------------------------------------
       
    55 // CBTGPSDeviceInfoHandler::~CBTGPSDeviceInfoHandler
       
    56 // -----------------------------------------------------------------------------
       
    57 CBTGPSDeviceInfoHandler::~CBTGPSDeviceInfoHandler()
       
    58     {
       
    59     
       
    60     if(iIdle)
       
    61         {
       
    62         iIdle->Cancel();
       
    63         delete iIdle;
       
    64         }
       
    65     if(iDeviceArray)
       
    66         {
       
    67         iDeviceArray->ResetAndDestroy();
       
    68         delete iDeviceArray;
       
    69         }
       
    70     delete iBtDevMan;
       
    71     }
       
    72 
       
    73 
       
    74 // -----------------------------------------------------------------------------
       
    75 // CBTGPSDeviceInfoHandler::ConstructL
       
    76 // -----------------------------------------------------------------------------
       
    77 void CBTGPSDeviceInfoHandler::ConstructL()
       
    78     {
       
    79     TRACESTRING("CBTGPSDeviceInfoHandler::ConstructL start...")
       
    80     
       
    81     //construct idle object
       
    82     iIdle = CIdle::NewL(CActive::EPriorityStandard);
       
    83     
       
    84     //construct BT device manager
       
    85     iBtDevMan = CBTGPSDevMan::NewL(this);
       
    86     iDeviceArray = new (ELeave) RBTDeviceArray( KBTGPSDeviceArrayGranularity );
       
    87     
       
    88     TInt err(KErrNone);
       
    89 
       
    90     err = iManagerExt.SettingManager().GetBTDeviceInfo(iValid, iBtSockAddr);
       
    91 
       
    92     if(err!=KErrNone || !iValid)
       
    93         {
       
    94         //device information is not found in setting
       
    95         iErrCode = KErrNotFound;
       
    96         iIdle->Start(TCallBack(
       
    97             HandlerCompleteCallback, 
       
    98             this));
       
    99         return;
       
   100         }
       
   101 
       
   102     //Get paired devices
       
   103     TBTRegistrySearch searchPattern;
       
   104     searchPattern.FindBonded();
       
   105     iBtDevMan->GetDevices(searchPattern, iDeviceArray);
       
   106     
       
   107     TRACESTRING("CBTGPSDeviceInfoHandler::ConstructL end")
       
   108     }
       
   109 
       
   110 // -----------------------------------------------------------------------------
       
   111 // CBTGPSDeviceInfoHandler::CBTGPSDeviceInfoHandler
       
   112 // C++ default constructor can NOT contain any code, that
       
   113 // might leave.
       
   114 // -----------------------------------------------------------------------------
       
   115 CBTGPSDeviceInfoHandler::CBTGPSDeviceInfoHandler(
       
   116         MBTGPSConnectManagerExt& aManagerExt)
       
   117     : iManagerExt(aManagerExt)
       
   118     {
       
   119     }
       
   120 
       
   121 // -----------------------------------------------------------------------------
       
   122 // CBTGPSDeviceInfoHandler::HandleAddDeviceComplete
       
   123 // -----------------------------------------------------------------------------
       
   124 void CBTGPSDeviceInfoHandler::HandleAddDeviceComplete(
       
   125         TInt /*aErr*/ )
       
   126     {
       
   127     //nothing to do
       
   128     }
       
   129 
       
   130 // -----------------------------------------------------------------------------
       
   131 // CBTGPSDeviceInfoHandler::HandleDeleteDevicesComplete
       
   132 // -----------------------------------------------------------------------------
       
   133 void CBTGPSDeviceInfoHandler::HandleDeleteDevicesComplete(
       
   134         TInt /*aErr*/ )
       
   135     {
       
   136     //nothing to do
       
   137     }
       
   138 
       
   139 // -----------------------------------------------------------------------------
       
   140 // CBTGPSDeviceInfoHandler::HandleGetDevicesComplete
       
   141 // -----------------------------------------------------------------------------
       
   142 void CBTGPSDeviceInfoHandler::HandleGetDevicesComplete(
       
   143             TInt aErr, 
       
   144             RBTDeviceArray* aDeviceArray)
       
   145     {
       
   146     TRACESTRING2("CBTGPSDeviceInfoHandler::HandleGetDevicesComplete start...%d", aErr)
       
   147     iErrCode = aErr;
       
   148 
       
   149   	if(iErrCode==KErrNone && aDeviceArray)
       
   150   	    {
       
   151   	    iErrCode = KErrNotFound;
       
   152   	    
       
   153         TInt count = aDeviceArray->Count();
       
   154         for (TInt i = 0; i < count; i++)
       
   155             {
       
   156             const TBTDevAddr& dev = (*aDeviceArray)[i]->BDAddr();
       
   157             if(dev == iBtSockAddr.BTAddr())
       
   158                 {
       
   159                 //BT Address is paired
       
   160                 //Set device info to device manager
       
   161                 TBTDeviceType deviceType(EBTDeviceTypeUnknown);
       
   162                 switch(iValid)
       
   163                     {
       
   164                     case TBTGPSSettingsApi::EBtDeviceInvalid:
       
   165                         break;
       
   166                     case TBTGPSSettingsApi::EBtDeviceNonNokGps:
       
   167                         deviceType = EBTDeviceTypeNonNokGps;
       
   168                         break;
       
   169                     case TBTGPSSettingsApi::EBtDeviceNokGps:
       
   170                     default:
       
   171                          deviceType = EBTDeviceTypeNokGps;
       
   172                     break;
       
   173                     }
       
   174                 iManagerExt.DeviceManager().SetDeviceInfo(
       
   175                     iBtSockAddr,
       
   176                     deviceType);
       
   177 
       
   178               	//Notify device is paired
       
   179               	iErrCode = KErrNone;
       
   180               	break;
       
   181                 }
       
   182             }
       
   183   	    }
       
   184     //Notify result
       
   185     iIdle->Start(TCallBack(
       
   186         HandlerCompleteCallback, 
       
   187         this));
       
   188     }
       
   189 
       
   190 // -----------------------------------------------------------------------------
       
   191 // CBTGPSDeviceInfoHandler::HandlerCompleteCallback
       
   192 // -----------------------------------------------------------------------------
       
   193 TInt CBTGPSDeviceInfoHandler::HandlerCompleteCallback(TAny* aAny)
       
   194     {
       
   195     reinterpret_cast<CBTGPSDeviceInfoHandler*>( aAny )->
       
   196         HandlerCompleteNotify();
       
   197         
       
   198     return KErrNone;
       
   199     }
       
   200 
       
   201 // -----------------------------------------------------------------------------
       
   202 // CBTGPSDeviceInfoHandler::HandlerCompleteNotify
       
   203 // -----------------------------------------------------------------------------
       
   204 void CBTGPSDeviceInfoHandler::HandlerCompleteNotify()
       
   205     {
       
   206     iManagerExt.HandlerComplete(EDeviceInfoHandler,iErrCode);
       
   207     }
       
   208 
       
   209 //  End of File