datasourcemodules/bluetoothgpspositioningmodule/btgpspsy/src/Utils/BTGPSDeviceManager.cpp
changeset 0 9cfd9a3ee49c
equal deleted inserted replaced
-1:000000000000 0:9cfd9a3ee49c
       
     1 // Copyright (c) 2004-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 <btdevice.h>
       
    21 #include <bt_sock.h>
       
    22 #include "BTGPSPanic.h"
       
    23 #include "BTGPSDeviceManager.h"
       
    24 #include "BTGPSDeviceListener.h"
       
    25 #include "BTGPSLogging.h"
       
    26 
       
    27 // EXTERNAL DATA STRUCTURES
       
    28 
       
    29 // EXTERNAL FUNCTION PROTOTYPES  
       
    30 
       
    31 // CONSTANTS
       
    32 
       
    33 // MACROS
       
    34 
       
    35 // LOCAL CONSTANTS AND MACROS
       
    36 
       
    37 // MODULE DATA STRUCTURES
       
    38 
       
    39 // LOCAL FUNCTION PROTOTYPES
       
    40 
       
    41 // FORWARD DECLARATIONS
       
    42 
       
    43 // ============================= LOCAL FUNCTIONS ===============================
       
    44 
       
    45 // ============================ MEMBER FUNCTIONS ===============================
       
    46 
       
    47 
       
    48 // -----------------------------------------------------------------------------
       
    49 // CBTGPSDeviceManager::NewL
       
    50 // -----------------------------------------------------------------------------
       
    51 CBTGPSDeviceManager* CBTGPSDeviceManager::NewL()
       
    52     {
       
    53     CBTGPSDeviceManager* self = new (ELeave) CBTGPSDeviceManager();
       
    54     CleanupStack::PushL(self);
       
    55     self->ConstructL();
       
    56     CleanupStack::Pop();
       
    57     return self;
       
    58     }
       
    59 
       
    60 // -----------------------------------------------------------------------------
       
    61 // CBTGPSDeviceManager::~CBTGPSDeviceManager
       
    62 // -----------------------------------------------------------------------------
       
    63 CBTGPSDeviceManager::~CBTGPSDeviceManager()
       
    64     {
       
    65 	delete iBtDevice;
       
    66     iListenerArray.Close();
       
    67     }
       
    68 
       
    69 // -----------------------------------------------------------------------------
       
    70 // CBTGPSDeviceManager::ConstructL
       
    71 // -----------------------------------------------------------------------------
       
    72 void CBTGPSDeviceManager::ConstructL()
       
    73     {
       
    74     iBtDevice = CBTDevice::NewL();
       
    75     }
       
    76 
       
    77 // -----------------------------------------------------------------------------
       
    78 // CBTGPSDeviceManager::CBTGPSDeviceManager
       
    79 // C++ default constructor can NOT contain any code, that
       
    80 // might leave.
       
    81 // -----------------------------------------------------------------------------
       
    82 CBTGPSDeviceManager::CBTGPSDeviceManager()
       
    83     {
       
    84     }
       
    85 
       
    86 // -----------------------------------------------------------------------------
       
    87 // CBTGPSDeviceManager::BtDevice
       
    88 // -----------------------------------------------------------------------------
       
    89 CBTDevice& CBTGPSDeviceManager::BtDevice()
       
    90     {
       
    91     return *iBtDevice;
       
    92     }
       
    93 
       
    94 // -----------------------------------------------------------------------------
       
    95 // CBTGPSDeviceManager::BtSockAddr
       
    96 // -----------------------------------------------------------------------------
       
    97 void CBTGPSDeviceManager::BtSockAddr(TBTSockAddr& aAddr) const
       
    98     {
       
    99     aAddr.SetBTAddr(iBtDevice->BDAddr());
       
   100     aAddr.SetPort(iPort);
       
   101     }
       
   102 
       
   103 // -----------------------------------------------------------------------------
       
   104 // CBTGPSDeviceManager::SetDeviceInfo
       
   105 // -----------------------------------------------------------------------------
       
   106 void CBTGPSDeviceManager::SetDeviceInfo(
       
   107 		    const TBTSockAddr& aAddr,
       
   108 		    const TBTDeviceType& aType)
       
   109     {
       
   110     iBtDevice->SetDeviceAddress(aAddr.BTAddr());
       
   111     iPort = aAddr.Port();
       
   112     iPaired = EFalse;
       
   113     iType = aType;
       
   114     StatusChanged();
       
   115     }
       
   116 
       
   117 
       
   118 // -----------------------------------------------------------------------------
       
   119 // CBTGPSDeviceManager::SetPort
       
   120 // -----------------------------------------------------------------------------
       
   121 void CBTGPSDeviceManager::SetPort(TInt aPort)
       
   122     {
       
   123     iPort = aPort;
       
   124     }
       
   125 
       
   126 // -----------------------------------------------------------------------------
       
   127 // CBTGPSDeviceManager::Port
       
   128 // -----------------------------------------------------------------------------
       
   129 TInt CBTGPSDeviceManager::Port() const
       
   130     {
       
   131     return iPort;
       
   132     }
       
   133 
       
   134 // -----------------------------------------------------------------------------
       
   135 // CBTGPSDeviceManager::IsPaired
       
   136 // -----------------------------------------------------------------------------
       
   137 TBool CBTGPSDeviceManager::IsPaired() const
       
   138     {
       
   139     return iPaired;
       
   140     }
       
   141 
       
   142 // -----------------------------------------------------------------------------
       
   143 // CBTGPSDeviceManager::SetPaired
       
   144 // -----------------------------------------------------------------------------
       
   145 void CBTGPSDeviceManager::SetPaired(TBool aPaired)
       
   146     {
       
   147     iPaired = aPaired;
       
   148     }
       
   149 
       
   150 // -----------------------------------------------------------------------------
       
   151 // CBTGPSDeviceManager::DeviceType
       
   152 // -----------------------------------------------------------------------------
       
   153 TBTDeviceType CBTGPSDeviceManager::DeviceType() const
       
   154     {
       
   155     return iType;
       
   156     }
       
   157 
       
   158 // -----------------------------------------------------------------------------
       
   159 // CBTGPSDeviceManager::IsGpsConnected
       
   160 // -----------------------------------------------------------------------------
       
   161 TBool CBTGPSDeviceManager::IsGpsConnected() const
       
   162     {
       
   163     return iType==EBTDeviceTypeNonNokGps || iType==EBTDeviceTypeNokGps;
       
   164     }
       
   165 
       
   166 // -----------------------------------------------------------------------------
       
   167 // CBTGPSDeviceManager::SetBTDeviceType
       
   168 // -----------------------------------------------------------------------------
       
   169 void CBTGPSDeviceManager::SetBTDeviceType(TBTDeviceType aType)
       
   170     {
       
   171     iType = aType;
       
   172     StatusChanged();
       
   173     }
       
   174 
       
   175 // -----------------------------------------------------------------------------
       
   176 // CBTGPSDeviceManager::DeviceConnectStatus
       
   177 // -----------------------------------------------------------------------------
       
   178 TBTDeviceConnectStatus CBTGPSDeviceManager::DeviceConnectStatus() const
       
   179     {
       
   180     return iConnectStatus;
       
   181     }
       
   182 
       
   183 // -----------------------------------------------------------------------------
       
   184 // CBTGPSDeviceManager::SetBTDeviceConnectStatus
       
   185 // -----------------------------------------------------------------------------
       
   186 void CBTGPSDeviceManager::SetBTDeviceConnectStatus(
       
   187         TBTDeviceConnectStatus aStatus,
       
   188         TInt aErr)
       
   189     {
       
   190     iConnectStatus = aStatus;
       
   191     iError = aErr;
       
   192     StatusChanged();   
       
   193     }
       
   194 
       
   195 // -----------------------------------------------------------------------------
       
   196 // CBTGPSDeviceManager::AddListenerL
       
   197 // -----------------------------------------------------------------------------
       
   198 void CBTGPSDeviceManager::AddListenerL(MBTGPSDeviceListener& aListener)
       
   199     {
       
   200     User::LeaveIfError(iListenerArray.Append(&aListener));
       
   201     }
       
   202 
       
   203 
       
   204 // -----------------------------------------------------------------------------
       
   205 // CBTGPSDeviceManager::RemoveListener
       
   206 // -----------------------------------------------------------------------------
       
   207 void CBTGPSDeviceManager::RemoveListener(MBTGPSDeviceListener& aListener)
       
   208     {
       
   209     TInt index = iListenerArray.Find(&aListener);
       
   210     if(index!=KErrNotFound)
       
   211         {
       
   212         iListenerArray.Remove(index);
       
   213         }
       
   214     }
       
   215 
       
   216 // -----------------------------------------------------------------------------
       
   217 // CBTGPSDeviceManager::StatusChanged
       
   218 // -----------------------------------------------------------------------------
       
   219 void CBTGPSDeviceManager::StatusChanged()
       
   220     {
       
   221     TRACESTRING("CBTGPSDeviceManager::StatusChanged start...")
       
   222     TRACESTRING2("ConnectStatus:%d", iConnectStatus)
       
   223     TRACESTRING2("DeviceType: %d", iType)
       
   224     //Broadcast BT device status change to listeners
       
   225     TInt count = iListenerArray.Count();
       
   226     for(TInt i=count-1; i>=0; i--)
       
   227         {
       
   228         iListenerArray[i]->BTDeviceStatusChanged(
       
   229             iConnectStatus,
       
   230             iType,
       
   231             iError);
       
   232         }
       
   233     TRACESTRING("CBTGPSDeviceManager::StatusChanged end")
       
   234     }
       
   235 
       
   236 
       
   237 //  End of File
       
   238 
       
   239 
       
   240