systemswstubs/asyreference/src/ASYReferenceCmdHandlerBase.cpp
changeset 0 0ce1b5ce9557
equal deleted inserted replaced
-1:000000000000 0:0ce1b5ce9557
       
     1 /*
       
     2 * Copyright (c) 2009 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:  Used as an reference implementation
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 // INCLUDE FILES
       
    20 
       
    21 #include "ASYReferenceCmdHandlerBase.h"
       
    22 #include "ASYReferenceMainServiceBase.h"
       
    23 #include "acc_debug.h"
       
    24 
       
    25 // EXTERNAL DATA STRUCTURES
       
    26 
       
    27 // EXTERNAL FUNCTION PROTOTYPES
       
    28 
       
    29 // CONSTANTS
       
    30     
       
    31 // MACROS
       
    32 
       
    33 // LOCAL CONSTANTS AND MACROS
       
    34 
       
    35 // MODULE DATA STRUCTURES
       
    36 
       
    37 // LOCAL FUNCTION PROTOTYPES
       
    38 
       
    39 // FORWARD DECLARATIONS
       
    40 
       
    41 // ============================= LOCAL FUNCTIONS ===============================
       
    42 
       
    43 // ============================ MEMBER FUNCTIONS ===============================
       
    44 
       
    45 // -----------------------------------------------------------------------------
       
    46 // Two-phased constructor.
       
    47 // -----------------------------------------------------------------------------
       
    48 //
       
    49 CASYReferenceCmdHandlerBase* CASYReferenceCmdHandlerBase::NewL()
       
    50     { 
       
    51      
       
    52     COM_TRACE_( "[AccFW:AsyReference] CASYReferenceCmdHandlerBase::NewL() - Enter" );
       
    53 
       
    54     CASYReferenceCmdHandlerBase * self = new(ELeave) CASYReferenceCmdHandlerBase( );
       
    55     CleanupStack::PushL( self );
       
    56     self->ConstructL();
       
    57     CleanupStack::Pop( self );
       
    58 
       
    59     COM_TRACE_( "[AccFW:AsyReference] CASYReferenceCmdHandlerBase::NewL() - Return" );
       
    60 
       
    61     return self;
       
    62     }
       
    63 
       
    64 // -----------------------------------------------------------------------------
       
    65 // destructor.
       
    66 // -----------------------------------------------------------------------------
       
    67 //
       
    68 CASYReferenceCmdHandlerBase::~CASYReferenceCmdHandlerBase()
       
    69     {        
       
    70     COM_TRACE_( "[AccFW:AsyReference] CASYReferenceCmdHandlerBase::~CASYReferenceCmdHandlerBase() - Enter" );
       
    71     COM_TRACE_( "[AccFW:AsyReference] CASYReferenceCmdHandlerBase::~CASYReferenceCmdHandlerBase() - Return" );
       
    72     }
       
    73 
       
    74 // -----------------------------------------------------------------------------
       
    75 // Two-phased constructor.
       
    76 // -----------------------------------------------------------------------------
       
    77 //
       
    78 CASYReferenceCmdHandlerBase::CASYReferenceCmdHandlerBase()        
       
    79     {    
       
    80     COM_TRACE_( "[AccFW:AsyReference] CASYReferenceCmdHandlerBase::CASYReferenceCmdHandlerBase() - Enter" );
       
    81     COM_TRACE_( "[AccFW:AsyReference] CASYReferenceCmdHandlerBase::CASYReferenceCmdHandlerBase() - Return" );
       
    82     }
       
    83 
       
    84 // -----------------------------------------------------------------------------
       
    85 // Two-phased constructor.
       
    86 // -----------------------------------------------------------------------------
       
    87 //
       
    88 void CASYReferenceCmdHandlerBase::ConstructL()
       
    89     {
       
    90     COM_TRACE_( "[AccFW:AsyReference] CASYReferenceCmdHandlerBase::CASYReferenceCmdHandlerBase() - Enter" );
       
    91     COM_TRACE_( "[AccFW:AsyReference] CASYReferenceCmdHandlerBase::CASYReferenceCmdHandlerBase() - Return" );
       
    92     }
       
    93 
       
    94 // -----------------------------------------------------------------------------
       
    95 // CASYReferenceCmdHandlerBase::ProcessCommandL
       
    96 // -----------------------------------------------------------------------------
       
    97 //
       
    98 void CASYReferenceCmdHandlerBase::ProcessCommandL(
       
    99      const TProcessCmdId aCommand,
       
   100      const TASYCmdParams& aCmdParams )
       
   101     {
       
   102 
       
   103     COM_TRACE_( "[AccFW:AsyReference] CASYReferenceCmdHandlerBase::ProcessCommandL() - Enter" );
       
   104 
       
   105     CASYReferenceMainServiceBase* connectionHandler = (CASYReferenceMainServiceBase *) ASYMainServiceBase();
       
   106 
       
   107     if( !connectionHandler )
       
   108         {        
       
   109         User::Leave( KErrGeneral );
       
   110         }
       
   111 
       
   112     switch( aCommand )
       
   113         {
       
   114         case ECmdProcessCommandInit:
       
   115             {
       
   116 
       
   117             // Command received from Accessory Server.
       
   118 
       
   119             // Connection handler state is set ongoing.
       
   120             connectionHandler->StateChangeL( CASYReferenceMainServiceBase::EStateInitOngoing );                        
       
   121             
       
   122             // [A.2] Process command init is received from Accessory Server
       
   123             //       At this point it is possible to request from an Accessory Driver/Domestic OS if the accessory connection exists.                                     
       
   124             //       In this example the Process response is send immediately to Accessory Server.
       
   125             TASYMsgAccessoryConnectionHandlerInitRetBuf package;
       
   126 
       
   127             // Accessory is not connected to terminal.
       
   128             package().iStateInfo.iState = AccessoryConnection::EStateNotConnected;
       
   129             package().iStateInfo.iAccessoryId = 0xffffff;
       
   130             TASYMessage message( KASYMessageGroupAccessoryMessage, KASYMsgAccessoryConnectionHandlerInitRet, package );            
       
   131 
       
   132             // Call straight ProcessResponse.
       
   133             ProcessResponseL( message );
       
   134 
       
   135             }
       
   136             break;
       
   137 
       
   138         case ECmdGetValueBool:
       
   139             {
       
   140                        
       
   141             // [E.1] Command received from Accessory Server
       
   142 
       
   143             TASYMsgAccessoryGetValueBooleanCmdBuf cmdPackage;                                 
       
   144 
       
   145             // Map and set feature
       
   146             MapCommandToAccessoryFeatureL( aCmdParams(), cmdPackage().iFeature );
       
   147 
       
   148             // Set Device ID
       
   149             TInt32 deviceId = ( TInt32 ) aCmdParams().iGenericID.HWDeviceID();            
       
   150             cmdPackage().iAccessoryId = deviceId;
       
   151             
       
   152             //
       
   153             // [E.2] Send request to an Accessory Driver/Domestic OS.
       
   154             //
       
   155 
       
   156             }
       
   157             break;
       
   158        
       
   159 
       
   160         case ECmdSetValueBool:
       
   161             {
       
   162 
       
   163             // [E.1] Command received from Accessory Server
       
   164 
       
   165             TASYMsgAccessorySetValueBooleanCmdBuf cmdPackage;            
       
   166 
       
   167             // Map and set feature
       
   168             MapCommandToAccessoryFeatureL( aCmdParams(), cmdPackage().iFeature );
       
   169 
       
   170             // Set Device ID
       
   171             TInt32 deviceId = ( TInt32 ) aCmdParams().iGenericID.HWDeviceID();            
       
   172             cmdPackage().iAccessoryId = deviceId;
       
   173 
       
   174             if( aCmdParams().iCmdValue )
       
   175                 {            
       
   176                 cmdPackage().iState = ETrue;
       
   177                 }
       
   178             else
       
   179                 {                
       
   180                 cmdPackage().iState = EFalse;
       
   181                 }
       
   182                         
       
   183             //
       
   184             // [E.2] Send request to an Accessory Driver/Domestic OS
       
   185             //            
       
   186 
       
   187             }
       
   188             break;
       
   189 
       
   190         default:
       
   191 
       
   192             User::Leave( KErrNotSupported );
       
   193             break;
       
   194         }
       
   195     
       
   196     COM_TRACE_( "[AccFW:AsyReference] CASYReferenceCmdHandlerBase::ProcessCommandL() - Enter" );
       
   197     }
       
   198 
       
   199 // -----------------------------------------------------------------------------
       
   200 // CASYReferenceCmdHandlerBase::ProcessResponseL
       
   201 // -----------------------------------------------------------------------------
       
   202 //
       
   203 void CASYReferenceCmdHandlerBase::ProcessResponseL( TASYMessage& aMessage )
       
   204     {
       
   205    
       
   206     COM_TRACE_( "[AccFW:AsyReference] CASYReferenceCmdHandlerBase::ProcessResponseL() - Enter" );
       
   207     // Response for previous made process command, received from an Accessory Driver/Domestic OS.
       
   208 
       
   209     CASYReferenceMainServiceBase* connectionHandler = (CASYReferenceMainServiceBase *) ASYMainServiceBase();  
       
   210 
       
   211     if( !connectionHandler )
       
   212         {        
       
   213         User::Leave( KErrGeneral );
       
   214         }
       
   215 
       
   216     switch ( aMessage.GroupId() )
       
   217         {
       
   218         case KASYMessageGroupAccessoryMessage:
       
   219 
       
   220             switch ( aMessage.MessageId() )
       
   221                 {
       
   222                 
       
   223                 case KASYMsgAccessoryConnectionHandlerInitRet:
       
   224                     {
       
   225                                         
       
   226                     connectionHandler->StateChangeL( CASYReferenceMainServiceBase::EStateInitOk );
       
   227 
       
   228                     TASYMsgAccessoryConnectionHandlerInitRetBuf package;
       
   229                     package.Copy( aMessage.Data() );
       
   230                     
       
   231                     if( package().iStateInfo.iState == AccessoryConnection::EStateConnected )
       
   232                         {
       
   233                         //
       
   234                         //  Accessory connection exists in Accessory Driver/Domestic OS, inform accessory connection handler.
       
   235                         //
       
   236                         connectionHandler->ConnectionStateChangedL( package().iStateInfo );
       
   237                         }
       
   238 
       
   239                     TAccValueTypeTBool state;
       
   240                     state.iValue = ETrue;
       
   241                     
       
   242                      // [A.3] After process responce for the previous made process command with init parameter
       
   243                      //       Server is aware wheather accessory was connected or not ( to Accessory Server ). 
       
   244                    
       
   245                     CASYCommandHandlerBase::ProcessResponseL( state, KErrNone );                    
       
   246        
       
   247                     }
       
   248                     break;
       
   249                 case KASYMsgAccessoryGetValueBooleanRet:
       
   250                     {
       
   251                                                        
       
   252                     //
       
   253                     // [E.3] Send response previous made process command ( to Accessory Server ).
       
   254                     //
       
   255                     TASYMsgAccessoryGetValueBooleanRetBuf response;
       
   256                     response.Copy( aMessage.Data() );
       
   257 
       
   258                     TAccValueTypeTBool state;
       
   259                     state.iValue = response().iFeatureState.iState;                    
       
   260                     CASYCommandHandlerBase::ProcessResponseL( state, KErrNone );
       
   261 
       
   262                     }
       
   263                     break;
       
   264                
       
   265                 case KASYMsgAccessorySetValueBooleanRet:
       
   266                     {
       
   267                                         
       
   268                     //
       
   269                     // [E.3] Send response previous made process command ( to Accessory Server ).
       
   270                     //
       
   271                    
       
   272                     TASYMsgAccessorySetValueBooleanRetBuf response;
       
   273                     response.Copy( aMessage.Data() );
       
   274 
       
   275                     TAccValueTypeTBool state;
       
   276                     TInt errorCode = response().iErrorCode;
       
   277                     state.iValue = response().iFeatureState.iState;                    
       
   278                     CASYCommandHandlerBase::ProcessResponseL( state, errorCode );
       
   279                     
       
   280                     }
       
   281                     break;
       
   282 
       
   283                 default:
       
   284                     {
       
   285                     
       
   286                     User::Leave( KErrGeneral );
       
   287                     }
       
   288                     break;
       
   289                 }
       
   290 
       
   291             break;
       
   292 
       
   293         default:
       
   294             {
       
   295             
       
   296             User::Leave( KErrGeneral );
       
   297             }
       
   298             break;
       
   299         }
       
   300 
       
   301     COM_TRACE_( "[AccFW:AsyReference] CASYReferenceCmdHandlerBase::ProcessResponseL() - Return" );
       
   302     }
       
   303 
       
   304 // -----------------------------------------------------------------------------
       
   305 // CSACAccessoryCommandHandler::ProcessErrorResponseL
       
   306 // -----------------------------------------------------------------------------
       
   307 //
       
   308 void CASYReferenceCmdHandlerBase::ProcessErrorResponseL( TInt /*aErrorCode*/, 
       
   309                                                          TASYMessage& /*aMessage*/ )
       
   310     {
       
   311 
       
   312     }
       
   313 
       
   314 
       
   315 // -----------------------------------------------------------------------------
       
   316 // 
       
   317 // -----------------------------------------------------------------------------
       
   318 void CASYReferenceCmdHandlerBase::MapCommandToAccessoryFeatureL( const TASYCommandParamRecord& aCommandParamRecord, 
       
   319                                                                  AccessoryFeature::TAccessoryFeature& aAccessoryFeature )
       
   320     {
       
   321     
       
   322     COM_TRACE_( "[AccFW:AsyReference] CASYReferenceCmdHandlerBase::MapCommandToAccessoryFeatureL() - Enter" );    
       
   323     TUint32 param;
       
   324 
       
   325     //Couple of accessory feature examples which can be requested from an Accessory Driver/Domestic OS.    
       
   326     aCommandParamRecord.iNameRecord.GetName( param );
       
   327         
       
   328     if( param == KAccAudioOutConnector )
       
   329         {        
       
   330         aAccessoryFeature = AccessoryFeature::EHeadphonesConnected;
       
   331         }
       
   332     else if( param == KAccExtPowerSupply )
       
   333         {
       
   334         
       
   335         aAccessoryFeature = AccessoryFeature::EExternalPowerSourceConnected;
       
   336         }    
       
   337     else
       
   338         {
       
   339         
       
   340         User::Leave( KErrArgument );
       
   341         }    
       
   342     COM_TRACE_( "[AccFW:AsyReference] CASYReferenceCmdHandlerBase::MapCommandToAccessoryFeatureL() - Return" );    
       
   343     }
       
   344 // -----------------------------------------------------------------------------
       
   345 // 
       
   346 // -----------------------------------------------------------------------------
       
   347 //
       
   348 void CASYReferenceCmdHandlerBase::RaiseEventL( TASYMessage& aMessage )
       
   349     {
       
   350    
       
   351     (void) aMessage;
       
   352     }
       
   353 
       
   354 // End of file
       
   355