bluetoothengine/btsap/inc/BTSapServerState.h
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 *     BTSap Plugin header definition
       
    16 *
       
    17 *
       
    18 */
       
    19 
       
    20 
       
    21 #ifndef BT_SAP_SERVER_STATE_H
       
    22 #define BT_SAP_SERVER_STATE_H
       
    23 
       
    24 //  INCLUDES
       
    25 #include <e32base.h>
       
    26 #include <e32property.h>
       
    27 
       
    28 #ifdef _DUMMY_CUSTOM_API
       
    29 #include <DummyCustomAPI.h>
       
    30 #else
       
    31 #include <rmmcustomapi.h>
       
    32 #endif
       
    33 
       
    34 #include "BTSapPlugin.h"
       
    35 #include "BTSapMessage.h"
       
    36 
       
    37 enum TBTSapServerState
       
    38     {
       
    39     EStateInit,
       
    40     EStateNotConnected,
       
    41     EStateConnect,
       
    42     EStateDisconnect,
       
    43     EStateIdle,
       
    44     EStateAPDU,
       
    45     EStateATR,
       
    46     EStatePowerOff,
       
    47     EStatePowerOn,
       
    48     EStateReset,
       
    49     EStateCardReaderStatus
       
    50     };
       
    51 
       
    52 enum TSapConnectionCompleteReason
       
    53     {
       
    54     EConnectionError,
       
    55     EUserAccepted,
       
    56     EUserRejected
       
    57     };
       
    58 
       
    59 enum TSapConnectionState
       
    60     {
       
    61     ESapNotConnected,
       
    62     ESapConnecting,
       
    63     ESapConnected
       
    64     };
       
    65 
       
    66 // FORWARD DECLARATIONS
       
    67 class CBTSapSocketHandler;
       
    68 class CBTSapRequestHandler;
       
    69 class CBTSapSimCardStatusNotifier;
       
    70 class RTelServer;
       
    71 class RMobilePhone;
       
    72 class MSapStatusObserver;
       
    73 
       
    74 /*
       
    75 * An abstarct interface that defines a callback method
       
    76 * for the SAP connection state observer. SapStatusChangedL
       
    77 * is called by CBTSapStatusObserver when the SAP connection
       
    78 * state has changed. aStatus represents the new status value.
       
    79 */
       
    80 class MSapStatusObserver
       
    81     {
       
    82     public:
       
    83     virtual void SapStatusChangedL(TInt aStatus) = 0;
       
    84     };
       
    85     
       
    86 /*
       
    87 * An observer that monitors KPSUidBluetoothSapConnectionState
       
    88 * P&S key. The clients can call SubscribeSapStatusL in order to 
       
    89 * get a chenged new SAP connection status returned via 
       
    90 * MSapStatusObserver::SapStatusChangedL.
       
    91 */ 
       
    92 class CBTSapStatusObserver : public CActive
       
    93     {
       
    94 public:
       
    95     /**
       
    96     * Two-phased constructor.
       
    97     */
       
    98     static CBTSapStatusObserver* NewL();
       
    99     /**
       
   100     * Destructor.
       
   101     */
       
   102     virtual ~CBTSapStatusObserver();
       
   103     
       
   104     /**
       
   105     * Starts listening KPSUidBluetoothSapConnectionState P&S key.
       
   106     * When the key value is changed, the new state is indicated
       
   107     * through the observer interface (MSapStatusObserver).
       
   108     */
       
   109     void SubscribeSapStatusL(MSapStatusObserver* aObserver);
       
   110       
       
   111 private:
       
   112     /**
       
   113     * Two-Phase constructor
       
   114     */
       
   115     void ConstructL();
       
   116     
       
   117     /**
       
   118     * Default constructor
       
   119     */
       
   120     CBTSapStatusObserver();
       
   121     
       
   122     // From CActive
       
   123     virtual void DoCancel();
       
   124     virtual void RunL();
       
   125       
       
   126 private:
       
   127     MSapStatusObserver* iObserver;
       
   128     RProperty iProperty;
       
   129     };
       
   130 
       
   131 
       
   132 /**
       
   133 *  CBTSapServerState core class
       
   134 *
       
   135 */
       
   136 class CBTSapServerState : public CActive, MSapStatusObserver
       
   137     {
       
   138 private:
       
   139     class TState
       
   140         {
       
   141     public:
       
   142         TState(CBTSapServerState& aServerState);
       
   143         virtual void Enter(TRequestStatus& aStatus) = 0;
       
   144         virtual TBTSapServerState Complete(TInt aReason = KErrNone) = 0;
       
   145         virtual void Cancel() = 0;
       
   146 
       
   147         virtual TInt DisconnectSapConnection(TBTSapDisconnectType aType);
       
   148         virtual TInt AcceptSapConnection();
       
   149         virtual TInt RejectSapConnection(TBTSapRejectReason aReason);
       
   150         virtual void SimCardStatusChanged(TCardStatus aCardStatus);
       
   151         virtual TInt ChangeState(TBTSapServerState& aNextState);
       
   152 
       
   153         void NotifySapState(TSapConnectionState aState);
       
   154         void StartBTNotifier(TInt type);
       
   155         TBool IsSimPresent();
       
   156 
       
   157     protected:
       
   158         TInt iSimStatus;
       
   159         CBTSapServerState& iServerState;
       
   160         TBTSapMessage& iResponseMessage; //
       
   161         TRequestStatus* iStatus; // TState can't access parent's member directly
       
   162         };
       
   163 
       
   164     class TStateInit : public TState
       
   165         {
       
   166     public:
       
   167         TStateInit(CBTSapServerState& aServerState);
       
   168         void Enter(TRequestStatus& aStatus);
       
   169         TBTSapServerState Complete(TInt aReason);
       
   170         void Cancel();
       
   171         };
       
   172 
       
   173     class TStateNotConnected : public TState
       
   174         {
       
   175     public:
       
   176         TStateNotConnected(CBTSapServerState& aServerState);
       
   177         void Enter(TRequestStatus& aStatus);
       
   178         TBTSapServerState Complete(TInt aReason);
       
   179         void Cancel();
       
   180 
       
   181         TInt ChangeState(TBTSapServerState& aNextState);
       
   182         };
       
   183 
       
   184     class TStateIdle : public TState
       
   185         {
       
   186     public:
       
   187         TStateIdle(CBTSapServerState& aServerState);
       
   188         void Enter(TRequestStatus& aStatus);
       
   189         TBTSapServerState Complete(TInt aReason);
       
   190         void Cancel();
       
   191 
       
   192         TInt DisconnectSapConnection(TBTSapDisconnectType aType);
       
   193         void SimCardStatusChanged(TCardStatus aCardStatus);
       
   194         TInt ChangeState(TBTSapServerState& aNextState);
       
   195         };
       
   196 
       
   197     class TStateConnect : public TStateIdle
       
   198         {
       
   199     public:
       
   200         TStateConnect(CBTSapServerState& aServerState);
       
   201         void Enter(TRequestStatus& aStatus);
       
   202         TBTSapServerState Complete(TInt aReason);
       
   203         void Cancel();
       
   204 
       
   205         TInt AcceptSapConnection();
       
   206         TInt RejectSapConnection(TBTSapRejectReason aReason);
       
   207         TInt ChangeState(TBTSapServerState& aNextState);
       
   208         void SimCardStatusChanged(TCardStatus aCardStatus);
       
   209 
       
   210     private:
       
   211         void CheckMaxMsgSize(TConnectionStatus& aMsgSizeStatus);
       
   212         TBool IsCallOngoing();
       
   213 
       
   214     private:
       
   215         TBool iConnectRequestOK;
       
   216         TCardStatus iCardStatus;
       
   217         RProperty iProperty;
       
   218         };
       
   219 
       
   220     class TStateDisconnect : public TStateIdle
       
   221         {
       
   222     public:
       
   223         TStateDisconnect(CBTSapServerState& aServerState);
       
   224         void Enter(TRequestStatus& aStatus);
       
   225         TBTSapServerState Complete(TInt aReason);
       
   226         void Cancel();
       
   227 
       
   228         TInt ChangeState(TBTSapServerState& aNextState);
       
   229         };
       
   230 
       
   231     class TStateAPDU : public TStateIdle
       
   232         {
       
   233     public:
       
   234         TStateAPDU(CBTSapServerState& aServerState);
       
   235         void Enter(TRequestStatus& aStatus);
       
   236         TBTSapServerState Complete(TInt aReason);
       
   237         void Cancel();
       
   238 
       
   239         TInt ChangeState(TBTSapServerState& aNextState);
       
   240 
       
   241     private:
       
   242         TBuf8<KMaxMsgSize> iApduCmd;
       
   243         TBuf8<KMaxMsgSize> iApduResp;
       
   244         RMmCustomAPI::TApduParameters iApduParameters;
       
   245         };
       
   246 
       
   247     class TStateATR : public TStateIdle
       
   248         {
       
   249     public:
       
   250         TStateATR(CBTSapServerState& aServerState);
       
   251         void Enter(TRequestStatus& aStatus);
       
   252         TBTSapServerState Complete(TInt aReason);
       
   253         void Cancel();
       
   254 
       
   255         TInt ChangeState(TBTSapServerState& aNextState);
       
   256 
       
   257     private:
       
   258         TBuf8<KMaxMsgSize> iATR;
       
   259         };
       
   260 
       
   261     class TStatePowerOff : public TStateIdle
       
   262         {
       
   263     public:
       
   264         TStatePowerOff(CBTSapServerState& aServerState);
       
   265         void Enter(TRequestStatus& aStatus);
       
   266         TBTSapServerState Complete(TInt aReason);
       
   267         void Cancel();
       
   268 
       
   269         TInt ChangeState(TBTSapServerState& aNextState);
       
   270         };
       
   271 
       
   272     class TStatePowerOn : public TStateIdle
       
   273         {
       
   274     public:
       
   275         TStatePowerOn(CBTSapServerState& aServerState);
       
   276         void Enter(TRequestStatus& aStatus);
       
   277         TBTSapServerState Complete(TInt aReason);
       
   278         void Cancel();
       
   279 
       
   280         TInt ChangeState(TBTSapServerState& aNextState);
       
   281         void SimCardStatusChanged(TCardStatus aCardStatus);
       
   282 
       
   283     private:
       
   284         TResultCode iResultCode;
       
   285         TCardStatus iCardStatus;
       
   286         };
       
   287 
       
   288     class TStateReset : public TStateIdle
       
   289         {
       
   290     public:
       
   291         TStateReset(CBTSapServerState& aServerState);
       
   292         void Enter(TRequestStatus& aStatus);
       
   293         TBTSapServerState Complete(TInt aReason);
       
   294         void Cancel();
       
   295 
       
   296         TInt ChangeState(TBTSapServerState& aNextState);
       
   297         void SimCardStatusChanged(TCardStatus aCardStatus);
       
   298 
       
   299     private:
       
   300         TResultCode iResultCode;
       
   301         TCardStatus iCardStatus;
       
   302         };
       
   303 
       
   304     class TStateCardReaderStatus : public TStateIdle
       
   305         {
       
   306     public:
       
   307         TStateCardReaderStatus(CBTSapServerState& aServerState);
       
   308         void Enter(TRequestStatus& aStatus);
       
   309         TBTSapServerState Complete(TInt aReason);
       
   310         void Cancel();
       
   311 
       
   312         TInt ChangeState(TBTSapServerState& aNextState);
       
   313 
       
   314     private:
       
   315         RMmCustomAPI::TSimCardReaderStatus iCardReaderStatus;
       
   316         };
       
   317 
       
   318 public:
       
   319     /**
       
   320     * Two-phased constructor.
       
   321     */
       
   322     static CBTSapServerState* NewL(CBTSapPlugin& aBTSapPlugin);
       
   323     /**
       
   324     * Destructor.
       
   325     */
       
   326     virtual ~CBTSapServerState();
       
   327 
       
   328 public:
       
   329 
       
   330     void StartL();
       
   331 
       
   332     void ChangeState(const TBTSapServerState aNextState);
       
   333 
       
   334     TBTSapServerState CurrentState();
       
   335 
       
   336     TInt DisconnectSapConnection(TBTSapDisconnectType aType);
       
   337 
       
   338     TInt AcceptSapConnection();
       
   339 
       
   340     TInt RejectSapConnection(TBTSapRejectReason aReason);
       
   341 
       
   342     TBool IsSapConnected();
       
   343 
       
   344     TInt GetRemoteBTAddress(TBTDevAddr& aBTDevAddr);
       
   345     
       
   346     TInt CreateStatesL();
       
   347     
       
   348     TInt ReleaseStatesL();
       
   349     
       
   350     TInt DisconnectCompleteL(TInt aErr);
       
   351 
       
   352 public:
       
   353 
       
   354     TInt HandleStateChangeRequest(TBTSapServerState& aNextState);
       
   355 
       
   356     void SendErrorResponse();
       
   357 
       
   358     void SimCardStatusChanged(TCardStatus aCardStatus);
       
   359 
       
   360     CBTSapSocketHandler& BTSapSocketHandler();
       
   361 
       
   362     CBTSapSimCardStatusNotifier& BTSapSimCardStatusNotifier();
       
   363 
       
   364     RMmCustomAPI& SubscriptionModule();
       
   365 
       
   366     TBTSapMessage& BTSapRequestMessage();
       
   367 
       
   368     TBTSapMessage& BTSapResponseMessage();
       
   369 
       
   370     // From MSapStatusObserver
       
   371     void SapStatusChangedL(TInt aStatus);
       
   372 
       
   373 private:
       
   374 
       
   375     void OpenSubscriptionModuleL();
       
   376 
       
   377 private:     // From CActive
       
   378 
       
   379     /**
       
   380     * DoCancel() has to be implemented by all the classes deriving CActive.
       
   381     * Request cancellation routine.
       
   382     * @param none
       
   383     * @return none 
       
   384     */
       
   385     virtual void DoCancel();
       
   386 
       
   387     /**
       
   388     * RunL is called by framework after request is being completed.
       
   389     * @param nones
       
   390     * @return none 
       
   391     */
       
   392     virtual void RunL();
       
   393 
       
   394 private:
       
   395 
       
   396     /**
       
   397     * Default constructor
       
   398     */
       
   399     CBTSapServerState(CBTSapPlugin& aBTSapPlugin);
       
   400 
       
   401     /**
       
   402     * Two-Phase constructor
       
   403     */
       
   404     void ConstructL();
       
   405 
       
   406 private:    // Data
       
   407 
       
   408     CBTSapPlugin& iBTSapPlugin;
       
   409     CBTSapSocketHandler* iSocketHandler;
       
   410     CBTSapRequestHandler* iRequestHandler;
       
   411     CBTSapSimCardStatusNotifier* iSimCardStatusNotifier;
       
   412 
       
   413     TBTSapServerState iCurrentState;
       
   414     RPointerArray <TState> iStateArray;
       
   415 
       
   416     RTelServer iTelServer;
       
   417     RMobilePhone iPhone;
       
   418     RMmCustomAPI iSubscriptionModule;
       
   419 
       
   420     TBTSapMessage iResponseMessage;
       
   421     TBTSapMessage iRequestMessage;
       
   422     CBTSapStatusObserver* iStatusObserver;
       
   423     TBool iStatesCreated;
       
   424     };
       
   425 
       
   426 #endif      // BT_SAP_SERVER_STATE_H
       
   427 
       
   428 // End of File