accessoryservices/accessoryserver/src/Server/AccSrvSubMode.cpp
changeset 0 4e1aa6a622a0
equal deleted inserted replaced
-1:000000000000 0:4e1aa6a622a0
       
     1 /*
       
     2 * Copyright (c) 2002-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:  Server-side sub-session of Accessory Mode
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 // INCLUDE FILES
       
    21 #include "AccSrvSubMode.h"
       
    22 #include "AccSrvMainSession.h"
       
    23 #include "AccClientServerMessages.h"
       
    24 #include "AccPolGenericID.h"
       
    25 #include "acc_debug.h"
       
    26 #include "AccSrvServerModel.h"
       
    27 #include <AsyCmdTypes.h>
       
    28 
       
    29 // EXTERNAL DATA STRUCTURES
       
    30 
       
    31 // EXTERNAL FUNCTION PROTOTYPES
       
    32 
       
    33 // CONSTANTS
       
    34 
       
    35 // MACROS
       
    36 
       
    37 // LOCAL CONSTANTS AND MACROS
       
    38 
       
    39 // MODULE DATA STRUCTURES
       
    40 
       
    41 // LOCAL FUNCTION PROTOTYPES
       
    42 
       
    43 // FORWARD DECLARATIONS
       
    44 
       
    45 // ============================= LOCAL FUNCTIONS ===============================
       
    46 
       
    47 // ============================ MEMBER FUNCTIONS ===============================
       
    48 
       
    49 // -----------------------------------------------------------------------------
       
    50 // CAccSrvSubMode::CAccSrvSubMode
       
    51 // C++ default constructor can NOT contain any code, that
       
    52 // might leave.
       
    53 // -----------------------------------------------------------------------------
       
    54 //
       
    55 CAccSrvSubMode::CAccSrvSubMode(
       
    56     CASYProxyAPI* aProxy,
       
    57     CAccSrvConnectionController* aConnectionController,
       
    58     CAccSrvServerModel* aServerModel )
       
    59     : CAccSrvSubBase( aProxy, aConnectionController, aServerModel ) ,
       
    60     iFirstOrder ( ETrue )
       
    61     {
       
    62     COM_TRACE_( "[AccFW:AccServer] CAccSrvSubMode::CAccSrvSubMode()" );
       
    63 
       
    64     iRecentAccessoryMode = iServerModel->AccessoryMode();
       
    65 
       
    66     COM_TRACE_( "[AccFW:AccServer] CAccSrvSubMode::CAccSrvSubMode - return void" );
       
    67     }
       
    68 
       
    69 // -----------------------------------------------------------------------------
       
    70 // CAccSrvSubMode::ConstructL
       
    71 // Symbian 2nd phase constructor can leave.
       
    72 // -----------------------------------------------------------------------------
       
    73 //
       
    74 void CAccSrvSubMode::ConstructL()
       
    75     {
       
    76     COM_TRACE_( "[AccFW:AccServer] CAccSrvSubMode::ConstructL()" );
       
    77 
       
    78     COM_TRACE_( "[AccFW:AccServer] CAccSrvSubMode::ConstructL - return void" );
       
    79     }
       
    80 
       
    81 // -----------------------------------------------------------------------------
       
    82 // CAccSrvSubMode::NewL
       
    83 // Two-phased constructor.
       
    84 // -----------------------------------------------------------------------------
       
    85 //
       
    86 CAccSrvSubMode* CAccSrvSubMode::NewL(
       
    87     CASYProxyAPI* aProxy,
       
    88     CAccSrvConnectionController* aConnectionController,
       
    89     CAccSrvServerModel* aServerModel )
       
    90     {
       
    91     if ( !aProxy )
       
    92         {
       
    93         User::Leave( KErrArgument );
       
    94         }
       
    95 
       
    96     CAccSrvSubMode* self = new ( ELeave ) CAccSrvSubMode( aProxy,
       
    97                                                           aConnectionController,
       
    98                                                           aServerModel );
       
    99 
       
   100     CleanupStack::PushL( self );
       
   101     self->ConstructL();
       
   102     CleanupStack::Pop( self );
       
   103 
       
   104     return self;
       
   105     }
       
   106 
       
   107 // Destructor
       
   108 CAccSrvSubMode::~CAccSrvSubMode()
       
   109     {
       
   110     COM_TRACE_( "[AccFW:AccServer] CAccSrvSubMode::~CAccSrvSubMode()" );
       
   111     RMessage2 dummy;
       
   112     
       
   113     CAccSrvSubMode::CancelGetAccessoryMode( dummy );//For iGetAccessoryModeAsync
       
   114     CAccSrvSubMode::CancelNotifyAccessoryModeChanged( dummy );//For iNotifyAccessoryModeChanged
       
   115 
       
   116     COM_TRACE_( "[AccFW:AccServer] CAccSrvSubMode::~CAccSrvSubMode - return void" );
       
   117     }
       
   118 
       
   119 // -----------------------------------------------------------------------------
       
   120 // CAccSrvSubMode::GetAccessoryModeL
       
   121 // -----------------------------------------------------------------------------
       
   122 //
       
   123 void CAccSrvSubMode::GetAccessoryModeL( const RMessage2& aMessage )
       
   124     {
       
   125     COM_TRACE_( "[AccFW:AccServer] CAccSrvSubMode::GetAccessoryModeL()" );
       
   126 
       
   127     if ( iServerModel->ASYsLoadCompleted() )
       
   128         {
       
   129         TAccPolAccessoryMode accMode = { EAccModeTextDevice, EFalse };
       
   130         accMode = iServerModel->AccessoryMode();
       
   131         TAccSrvAccessoryModePckg accModePckg( accMode );
       
   132         aMessage.WriteL( KAccServParamPosFirst, accModePckg );
       
   133         CAccSrvSubMode::Complete( aMessage, KErrNone, accMode );
       
   134         }
       
   135     else
       
   136         {
       
   137         COM_TRACE_( "[AccFW:AccServer] CAccSrvSubMode::GetAccessoryModeL - Mode not initialized yet" );
       
   138         User::Leave( KErrNotReady );
       
   139         }
       
   140 
       
   141     COM_TRACE_( "[AccFW:AccServer] CAccSrvSubMode::GetAccessoryModeL - return void" );
       
   142     }
       
   143 
       
   144 // -----------------------------------------------------------------------------
       
   145 // CAccSrvSubMode::GetAccessoryModeAsyncL
       
   146 // -----------------------------------------------------------------------------
       
   147 //
       
   148 void CAccSrvSubMode::GetAccessoryModeAsyncL( const RMessage2& aMessage )
       
   149     {
       
   150     COM_TRACE_( "[AccFW:AccServer] CAccSrvSubMode::GetAccessoryModeAsyncL()" );
       
   151 
       
   152     if ( iServerModel->ASYsLoadCompleted() )
       
   153         {
       
   154         COM_TRACE_( "[AccFW:AccServer] CAccSrvSubMode::GetAccessoryModeAsyncL - completing synchronously" );
       
   155         TAccPolAccessoryMode accMode = { EAccModeTextDevice, EFalse };
       
   156         accMode = iServerModel->AccessoryMode();
       
   157         TAccSrvAccessoryModePckg accModePckg( accMode );
       
   158         aMessage.WriteL( KAccServParamPosFirst, accModePckg );
       
   159         Write( aMessage, KAccSrvGetAccessoryModeBit );
       
   160         CAccSrvSubMode::Complete( aMessage, KErrNone, accMode );
       
   161         }
       
   162     else
       
   163         {
       
   164         iConnectionController->NotificationQueue().RegisterControlMessage( 
       
   165                                                         EAccessoryModeAsyncChanged,
       
   166                                                         this );
       
   167         iGetAccessoryModeAsync = aMessage;//Store RMessage2 for future completion
       
   168         }
       
   169 
       
   170     COM_TRACE_( "[AccFW:AccServer] CAccSrvSubMode::GetAccessoryModeAsyncL - return void" );
       
   171     }
       
   172 
       
   173 // -----------------------------------------------------------------------------
       
   174 // CAccSrvSubMode::CancelGetAccessoryModeL
       
   175 // -----------------------------------------------------------------------------
       
   176 //
       
   177 void CAccSrvSubMode::CancelGetAccessoryMode( const RMessage2& /*aMessage*/ )
       
   178     {
       
   179     COM_TRACE_( "[AccFW:AccServer] CAccSrvSubMode::CancelGetAccessoryModeL()" );
       
   180 
       
   181     // If request is null there is nothing to cancel
       
   182     if ( !iGetAccessoryModeAsync.IsNull() )
       
   183         {
       
   184         iConnectionController->NotificationQueue().CancelControlMessage( 
       
   185                                                         EAccessoryModeAsyncChanged,
       
   186                                                         this );
       
   187 
       
   188         Write( iGetAccessoryModeAsync, KAccSrvGetAccessoryModeBit );
       
   189         TAccPolAccessoryMode accessoryMode( iServerModel->AccessoryMode() );
       
   190         CAccSrvSubMode::Complete( iGetAccessoryModeAsync, KErrCancel, accessoryMode );
       
   191         }
       
   192     COM_TRACE_( "[AccFW:AccServer] CAccSrvSubMode::CancelGetAccessoryModeL - return void" );
       
   193     }
       
   194 
       
   195 // -----------------------------------------------------------------------------
       
   196 // CAccSrvSubMode::NotifyAccessoryModeChangedL
       
   197 // -----------------------------------------------------------------------------
       
   198 //
       
   199 void CAccSrvSubMode::NotifyAccessoryModeChangedL( const RMessage2& aMessage )
       
   200     {
       
   201     COM_TRACE_( "[AccFW:AccServer] CAccSrvSubMode::NotifyAccessoryModeChangedL()" );
       
   202 
       
   203     TAccPolAccessoryMode currentMode( iConnectionController->ServerModel().AccessoryMode() );
       
   204 
       
   205     iNotifyAccessoryModeChanged = aMessage;//Store RMessage2 for future completion, don't leave after this
       
   206 
       
   207     if ( iRecentAccessoryMode.iAccessoryMode == currentMode.iAccessoryMode && 
       
   208          iRecentAccessoryMode.iAudioOutputStatus == currentMode.iAudioOutputStatus || 
       
   209          iFirstOrder )
       
   210         {
       
   211         // Add session to queue.
       
   212         iConnectionController->NotificationQueue().RegisterControlMessage( 
       
   213                                                         EAccessoryModeChanged,
       
   214                                                         this );
       
   215         }
       
   216     else 
       
   217         {
       
   218         //Accessory mode has been changes before before notification is re-ordered
       
   219         CAccSrvSubMode::CompleteMessageL( EAccessoryModeChanged, KErrNone, KErrUnknown );
       
   220         }
       
   221 
       
   222     COM_TRACE_( "[AccFW:AccServer] CAccSrvSubMode::NotifyAccessoryModeChangedL - return void" );
       
   223     }
       
   224   
       
   225 // -----------------------------------------------------------------------------
       
   226 // CAccSrvSubMode::CancelNotifyAccessoryModeChangedL
       
   227 // -----------------------------------------------------------------------------
       
   228 //
       
   229 void CAccSrvSubMode::CancelNotifyAccessoryModeChanged( const RMessage2& /*aMessage*/ )
       
   230     {
       
   231     COM_TRACE_( "[AccFW:AccServer] CAccSrvSubMode::CancelNotifyAccessoryModeChanged()" );
       
   232 
       
   233     // If request is null there is nothing to cancel
       
   234     if ( !iNotifyAccessoryModeChanged.IsNull() )
       
   235         {
       
   236         iConnectionController->NotificationQueue().CancelControlMessage( 
       
   237                                                         EAccessoryModeChanged,
       
   238                                                         this );
       
   239         Write( iNotifyAccessoryModeChanged, KAccSrvNotifyAccessoryModeChangedBit );
       
   240         TAccPolAccessoryMode accessoryMode( iServerModel->AccessoryMode() );
       
   241         CAccSrvSubMode::Complete( iNotifyAccessoryModeChanged, KErrCancel, accessoryMode );
       
   242         }
       
   243     
       
   244     COM_TRACE_( "[AccFW:AccServer] CAccSrvSubMode::CancelNotifyAccessoryModeChanged - return void" );
       
   245     }
       
   246     
       
   247 // -----------------------------------------------------------------------------
       
   248 // CAccSrvSubMode::DispatchMessageL
       
   249 // Handles client request
       
   250 // -----------------------------------------------------------------------------
       
   251 //
       
   252 void CAccSrvSubMode::DispatchMessageL( const RMessage2& aMessage )
       
   253     {
       
   254     COM_TRACE_( "[AccFW:AccServer] CAccSrvSubMode::DispatchMessageL()" );
       
   255 
       
   256     TInt function = aMessage.Function();
       
   257 
       
   258     switch ( function )
       
   259         {
       
   260         case EAccSrvGetAccessoryMode:
       
   261             {
       
   262             GetAccessoryModeL( aMessage );
       
   263             break;
       
   264             }
       
   265         case EAccSrvCancelGetAccessoryMode:
       
   266             {
       
   267             CancelGetAccessoryMode( aMessage );
       
   268             break;
       
   269             }
       
   270         case EAccSrvGetAccessoryModeAsync:
       
   271             {
       
   272             GetAccessoryModeAsyncL( aMessage );
       
   273             break;
       
   274             }
       
   275         case EAccSrvNotifyAccessoryModeChanged:
       
   276             {
       
   277             NotifyAccessoryModeChangedL( aMessage );
       
   278             break;
       
   279             }
       
   280         case EAccSrvCancelNotifyAccessoryModeChanged:
       
   281             {
       
   282             CancelNotifyAccessoryModeChanged( aMessage );
       
   283             break;
       
   284             }
       
   285         default:
       
   286             {
       
   287             TRACE_ASSERT_ALWAYS;
       
   288             COM_TRACE_1( "[AccFW:AccServer] CAccSrvSubMode::DispatchMessageL - unhandled function %d", function );
       
   289             User::Leave( KErrGeneral );
       
   290             break;
       
   291             }
       
   292         } // switch( function )
       
   293 
       
   294     COM_TRACE_( "[AccFW:AccServer] CAccSrvSubMode::DispatchMessageL - return void" );
       
   295     }
       
   296 
       
   297 // -----------------------------------------------------------------------------
       
   298 // CAccSrvSubMode::CompleteMessageL
       
   299 // -----------------------------------------------------------------------------
       
   300 //
       
   301 TBool CAccSrvSubMode::CompleteMessageL( TMsgID aMsgID,
       
   302                                         TInt aErrorCode,
       
   303                                         TInt /*aUniqueID*/ )
       
   304     {
       
   305     COM_TRACE_2( "[AccFW:AccServer] CAccSrvSubMode::CompleteMessageL(msg=%d err=%d)", aMsgID, aErrorCode );
       
   306 
       
   307     if ( EAccessoryModeChanged == aMsgID )
       
   308         {
       
   309         //Write current accessory mode and
       
   310         //complete outstanding AccessoryAudioLinkOpen request
       
   311         TAccPolAccessoryMode accessoryMode;
       
   312         accessoryMode = iConnectionController->ServerModel().AccessoryMode();
       
   313         TPckg<TAccPolAccessoryMode> accessoryModePckg( accessoryMode );
       
   314 
       
   315         iNotifyAccessoryModeChanged.WriteL( KAccServParamPosFirst, accessoryModePckg );
       
   316         Write( iNotifyAccessoryModeChanged, KAccSrvNotifyAccessoryModeChangedBit );
       
   317         CAccSrvSubMode::Complete( iNotifyAccessoryModeChanged, aErrorCode, accessoryMode );
       
   318         }
       
   319     else if ( EAccessoryModeAsyncChanged == aMsgID )
       
   320         {
       
   321         //Write current accessory mode and
       
   322         //complete outstanding GetAccessoryMode ( Async )
       
   323         TAccPolAccessoryMode accessoryMode;
       
   324         accessoryMode = iServerModel->AccessoryMode();
       
   325         TAccSrvAccessoryModePckg accessoryModePckg( accessoryMode );
       
   326 
       
   327         iGetAccessoryModeAsync.WriteL( KAccServParamPosFirst, accessoryModePckg );
       
   328         Write( iGetAccessoryModeAsync, KAccSrvGetAccessoryModeBit );
       
   329         CAccSrvSubMode::Complete( iGetAccessoryModeAsync, aErrorCode, accessoryMode );
       
   330         }
       
   331     else
       
   332         {
       
   333         TRACE_ASSERT_ALWAYS;
       
   334         User::Leave( KErrGeneral );
       
   335         }
       
   336 
       
   337     COM_TRACE_( "[AccFW:AccServer] CAccSrvSubMode::CompleteMessageL - return" );
       
   338 
       
   339     return ETrue; // if it gets here, this is always ETrue
       
   340     }
       
   341 
       
   342 // -----------------------------------------------------------------------------
       
   343 // CAccSrvSubMode::Complete
       
   344 //
       
   345 // Mode request is completed with updated Accessory Mode.
       
   346 // This method stores also most recent accessory mode what client have.
       
   347 // -----------------------------------------------------------------------------
       
   348 //
       
   349 void CAccSrvSubMode::Complete( 
       
   350     const RMessage2& aMessage,
       
   351     TInt aErrorCode,
       
   352     TAccPolAccessoryMode& aAccessoryMode )
       
   353     {
       
   354     COM_TRACE_1( "[AccFW:AccServer] CAccSrvSubMode::Complete(Err=%d)", aErrorCode );
       
   355     
       
   356     if ( KErrCancel == aErrorCode )
       
   357         {
       
   358         //If Mode request is cancelled, Next Accessory NotifyAccessoryModeChanged() 
       
   359         //is not completed directly.
       
   360         iFirstOrder = ETrue;
       
   361         }
       
   362     else
       
   363         {
       
   364         iFirstOrder = EFalse; 
       
   365         }
       
   366     
       
   367     iRecentAccessoryMode = aAccessoryMode;    
       
   368     aMessage.Complete( aErrorCode );
       
   369     
       
   370     COM_TRACE_( "[AccFW:AccServer] CAccSrvSubMode::Complete - return void" );
       
   371     }
       
   372 
       
   373 // ========================== OTHER EXPORTED FUNCTIONS =========================
       
   374 
       
   375 //  End of File