bluetoothengine/btsap/src/BTSapState.cpp
changeset 0 f63038272f30
child 65 001a94c71129
equal deleted inserted replaced
-1:000000000000 0:f63038272f30
       
     1 /*
       
     2 * Copyright (c) 2004-2006 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description: 
       
    15 *     This class is a base state class for all BTSap states
       
    16 *
       
    17 *
       
    18 */
       
    19 
       
    20 
       
    21 
       
    22 // INCLUDE FILES
       
    23 #include <e32property.h>
       
    24 #include <startupdomainpskeys.h>
       
    25 #include "BTSapDomainPSKeys.h"
       
    26 
       
    27 #include <btnotif.h>
       
    28 #include "BTSapServerState.h"
       
    29 #include "debug.h"
       
    30 
       
    31 CBTSapServerState::TState::TState(CBTSapServerState& aServerState)
       
    32 :   iSimStatus(0),
       
    33     iServerState(aServerState),
       
    34     iResponseMessage(aServerState.BTSapResponseMessage()),
       
    35     iStatus(NULL)
       
    36     {
       
    37     }
       
    38 
       
    39 TInt CBTSapServerState::TState::AcceptSapConnection()
       
    40     {
       
    41     BTSAP_TRACE_OPT(KBTSAP_TRACE_ERROR, BTSapPrintTrace(_L("[BTSap]  TState: AcceptSapConnection: Not Ready#")));
       
    42     return KErrNotReady;
       
    43     }
       
    44 
       
    45 TInt CBTSapServerState::TState::RejectSapConnection(TBTSapRejectReason /*aReason*/)
       
    46     {
       
    47     BTSAP_TRACE_OPT(KBTSAP_TRACE_ERROR, BTSapPrintTrace(_L("[BTSap]  TState: RejectSapConnection: Not Ready#")));
       
    48     return KErrNotReady;
       
    49     }
       
    50 
       
    51 TInt CBTSapServerState::TState::DisconnectSapConnection(TBTSapDisconnectType /*aType*/)
       
    52     {
       
    53     BTSAP_TRACE_OPT(KBTSAP_TRACE_ERROR, BTSapPrintTrace(_L("[BTSap]  TState: DisconnectSapConnection: Not Ready#")));
       
    54     return KErrNotReady;
       
    55     }
       
    56 
       
    57 void CBTSapServerState::TState::SimCardStatusChanged(TCardStatus /*aCardStatus*/)
       
    58     {
       
    59     BTSAP_TRACE_OPT(KBTSAP_TRACE_ERROR, BTSapPrintTrace(_L("[BTSap]  TState: SimCardStatusChanged: Not Ready#")));
       
    60     }
       
    61 
       
    62 TInt CBTSapServerState::TState::ChangeState(TBTSapServerState& aNextState)
       
    63     {
       
    64     TInt retVal = KErrNone;
       
    65 
       
    66     if (aNextState != EStatePowerOff &&
       
    67         aNextState != EStateReset &&
       
    68         aNextState != EStateDisconnect)
       
    69         {
       
    70         aNextState = EStateIdle;
       
    71         retVal = KErrNotSupported;
       
    72         }
       
    73 
       
    74     return retVal;
       
    75     }
       
    76 
       
    77 void CBTSapServerState::TState::NotifySapState(TSapConnectionState aState)
       
    78     {
       
    79     BTSAP_TRACE_OPT(KBTSAP_TRACE_FUNCTIONS, BTSapPrintTrace(_L("[BTSap]  NotifySapState: %d"), aState));
       
    80 
       
    81     TBool simPresent = IsSimPresent();
       
    82 
       
    83     switch(aState)
       
    84         {
       
    85         case ESapNotConnected:
       
    86             {
       
    87             // If the next state is ESapNotConnected, we need to verify the previous state
       
    88             TInt previousState;
       
    89             RProperty::Get(KPSUidBluetoothSapConnectionState, KBTSapConnectionState, previousState);
       
    90 
       
    91             // Only show NotConnected if the previous state was connecting (ie. connection failed)
       
    92             if(previousState == ESapConnecting)
       
    93                 {
       
    94                 if( simPresent )
       
    95                     {
       
    96                     StartBTNotifier(EBTSapFailed);
       
    97                     }
       
    98                 else
       
    99                     {
       
   100                     // Notify the user of the specific reason that connection 
       
   101                     // could not be completed: there is no SIM present
       
   102                     StartBTNotifier(EBTSapNoSim);
       
   103                     }
       
   104                 }
       
   105             break;
       
   106             }
       
   107 
       
   108         case ESapConnecting:
       
   109             {
       
   110             if( simPresent )
       
   111                 {
       
   112                 // Don't show the note if no SIM is present
       
   113                 StartBTNotifier(EBTEnterSap);
       
   114                 }
       
   115             break;
       
   116             }
       
   117         case ESapConnected:
       
   118             StartBTNotifier(EBTSapOk);
       
   119             break;
       
   120 
       
   121         default:
       
   122             BTSAP_TRACE_OPT(KBTSAP_TRACE_ERROR, BTSapPrintTrace(_L("[BTSap]  Invalid state!!! %d"), aState));
       
   123             break;
       
   124         }
       
   125 
       
   126     RProperty::Set(KPSUidBluetoothSapConnectionState, KBTSapConnectionState, aState);
       
   127     }
       
   128 
       
   129 void CBTSapServerState::TState::StartBTNotifier(TInt note)
       
   130     {
       
   131     BTSAP_TRACE_OPT(KBTSAP_TRACE_FUNCTIONS, BTSapPrintTrace(_L("[BTSap]  StartBTNotifier: %d"), note));
       
   132 
       
   133     RNotifier notifier;
       
   134     TInt err = notifier.Connect();
       
   135     if(err != KErrNone)
       
   136         {
       
   137         BTSAP_TRACE_OPT(KBTSAP_TRACE_ERROR, BTSapPrintTrace(_L("[BTSap]  NotifySapState: Couldn't connect to notifier: %d"), err));
       
   138         }
       
   139     else
       
   140         {
       
   141         TBTGenericInfoNotiferParamsPckg type;
       
   142         type().iMessageType = (TBTGenericInfoNoteType) note;
       
   143 
       
   144         err = notifier.StartNotifier(KBTGenericInfoNotifierUid, type);
       
   145 
       
   146         if (err != KErrNone)
       
   147             {
       
   148             BTSAP_TRACE_OPT(KBTSAP_TRACE_ERROR, BTSapPrintTrace(_L("[BTSap]  NotifySapState: Couldn't start notifier: err = %d"), err));
       
   149             }
       
   150 
       
   151         notifier.Close();
       
   152         }
       
   153     }
       
   154 
       
   155 TBool CBTSapServerState::TState::IsSimPresent()
       
   156     {
       
   157 #ifdef __WINS__
       
   158 
       
   159 	BTSAP_TRACE_OPT(KBTSAP_TRACE_FUNCTIONS, BTSapPrintTrace(_L("[BTSap]  CBTSapServerState::TStateConnect::IsSimPresent ON THE WINS SIDE")));
       
   160 	return ETrue;
       
   161 
       
   162 #else   //__WINS__
       
   163 
       
   164     BTSAP_TRACE_OPT(KBTSAP_TRACE_FUNCTIONS, BTSapPrintTrace(_L("[BTSap]  CBTSapServerState::TStateConnect::IsSimPresent, SimStatus: %d"), iSimStatus));
       
   165 
       
   166     TInt err = KErrNone;
       
   167     if( iSimStatus == 0 )
       
   168         {
       
   169         err = RProperty::Get(KPSUidStartup, KPSSimStatus, iSimStatus);
       
   170         }
       
   171     TBool retVal = !(err || iSimStatus == ESimNotPresent || iSimStatus == ESimNotSupported);
       
   172 
       
   173     BTSAP_TRACE_OPT(KBTSAP_TRACE_INFO, BTSapPrintTrace(_L("[BTSap]  TStateConnect::IsSimPresent: err = %d, retVal = %d"), err, retVal));
       
   174     return retVal;
       
   175 
       
   176 #endif  //__WINS__
       
   177     }
       
   178 //  End of File