accessoryservices/accessoryserver/src/Server/AccSrvSettingsHandler.cpp
branchRCL_3
changeset 21 ccb4f6b3db21
parent 20 1ddbe54d0645
child 22 8cb079868133
equal deleted inserted replaced
20:1ddbe54d0645 21:ccb4f6b3db21
    71 // C++ default constructor can NOT contain any code, that
    71 // C++ default constructor can NOT contain any code, that
    72 // might leave.
    72 // might leave.
    73 // -----------------------------------------------------------------------------
    73 // -----------------------------------------------------------------------------
    74 //
    74 //
    75 CAccSrvSettingsHandler::CAccSrvSettingsHandler( CAccSrvConnectionController* aConCtrl,
    75 CAccSrvSettingsHandler::CAccSrvSettingsHandler( CAccSrvConnectionController* aConCtrl,
    76                                                 CAccSrvServerModel& aModel )
    76                                                 CAccSrvServerModel& aModel,
       
    77                                                 CAccPolAccessoryPolicy* aPolicy )
    77     : iConCtrl( aConCtrl ),
    78     : iConCtrl( aConCtrl ),
    78       iModel( aModel ),
    79       iModel( aModel ),
    79       iLightsOn( EAccSettingsLightsNotSet )
    80       iLightsOn( EAccSettingsLightsNotSet ),
       
    81       iPolicy( aPolicy )
    80     {
    82     {
    81     COM_TRACE_( "[AccFW:AccServer] CAccSrvSettingsHandler::CAccSrvSettingsHandler()" );
    83     COM_TRACE_( "[AccFW:AccServer] CAccSrvSettingsHandler::CAccSrvSettingsHandler()" );
    82 
    84 
    83     COM_TRACE_( "[AccFW:AccServer] CAccSrvSettingsHandler::CAccSrvSettingsHandler - return" );
    85     COM_TRACE_( "[AccFW:AccServer] CAccSrvSettingsHandler::CAccSrvSettingsHandler - return" );
    84     }
    86     }
   120 // Two-phased constructor.
   122 // Two-phased constructor.
   121 // -----------------------------------------------------------------------------
   123 // -----------------------------------------------------------------------------
   122 //
   124 //
   123 CAccSrvSettingsHandler* CAccSrvSettingsHandler::NewL(
   125 CAccSrvSettingsHandler* CAccSrvSettingsHandler::NewL(
   124                                            CAccSrvConnectionController* aConCtrl,
   126                                            CAccSrvConnectionController* aConCtrl,
   125                                            CAccSrvServerModel& aModel )
   127                                            CAccSrvServerModel& aModel,
       
   128                                            CAccPolAccessoryPolicy* aPolicy )
   126     {
   129     {
   127     COM_TRACE_( "[AccFW:AccServer] CAccSrvSettingsHandler::NewL()" );
   130     COM_TRACE_( "[AccFW:AccServer] CAccSrvSettingsHandler::NewL()" );
   128 
   131 
   129     CAccSrvSettingsHandler* self = new( ELeave ) CAccSrvSettingsHandler(
   132     CAccSrvSettingsHandler* self = new( ELeave ) CAccSrvSettingsHandler(
   130                                                     aConCtrl,
   133                                                     aConCtrl,
   131                                                     aModel );
   134                                                     aModel,
       
   135                                                     aPolicy );
   132     CleanupStack::PushL( self );
   136     CleanupStack::PushL( self );
   133     self->ConstructL();
   137     self->ConstructL();
   134     CleanupStack::Pop( self );
   138     CleanupStack::Pop( self );
   135 
   139 
   136     COM_TRACE_( "[AccFW:AccServer] CAccSrvSettingsHandler::NewL - return self" );
   140     COM_TRACE_( "[AccFW:AccServer] CAccSrvSettingsHandler::NewL - return self" );
   262     TLex8 l( ptrBuf );
   266     TLex8 l( ptrBuf );
   263     TInt32 temp;
   267     TInt32 temp;
   264     l.Val( temp );
   268     l.Val( temp );
   265     settings = static_cast< TUint32 >( temp );
   269     settings = static_cast< TUint32 >( temp );
   266 
   270 
   267 	CleanupStack::PopAndDestroy ( &session );
   271     CleanupStack::PopAndDestroy ( &session );
   268     CleanupStack::PopAndDestroy ( buf );
   272     CleanupStack::PopAndDestroy ( buf );
   269 
   273 
   270     COM_TRACE_1( "[AccFW:AccServer] CAccSrvSettingsHandler::GetSupportedHWDevicesL() - return %d", settings );
   274     COM_TRACE_1( "[AccFW:AccServer] CAccSrvSettingsHandler::GetSupportedHWDevicesL() - return %d", settings );
   271 
   275 
   272     return settings;
   276     return settings;
   284     {
   288     {
   285     COM_TRACE_3( "[AccFW:AccServer] CAccSrvSettingsHandler::SetHWDeviceSettingsL( %d, %d, %d  )", aSettings, aEnable, aForce );
   289     COM_TRACE_3( "[AccFW:AccServer] CAccSrvSettingsHandler::SetHWDeviceSettingsL( %d, %d, %d  )", aSettings, aEnable, aForce );
   286 
   290 
   287     // Valid settings
   291     // Valid settings
   288     TUint32 settings = ResolveNewSettingsL( aSettings, aEnable, aForce );
   292     TUint32 settings = ResolveNewSettingsL( aSettings, aEnable, aForce );
   289 
   293     TUint32 iOldDeviceType = iModel.DeviceType();
       
   294     
   290     // Update model
   295     // Update model
   291     iModel.SetDeviceType( settings );
   296     iModel.SetDeviceType( settings );
   292 
   297 
   293     // Update setting to CR
   298     // Update setting to CR
   294     CRepository* repository = CRepository::NewL( KCRUidAccServer );
   299     CRepository* repository = CRepository::NewL( KCRUidAccServer );
   295     TInt crSettings = static_cast<TInt>( settings );
   300     TInt crSettings = static_cast<TInt>( settings );
   296     repository->Set( KAccServerHWDevices, crSettings );
   301     repository->Set( KAccServerHWDevices, crSettings );
   297     delete repository;
   302     delete repository;
   298     repository = NULL;
   303     repository = NULL;
   299 
   304 
       
   305         //Check default selection. The newly set device-type after the model update.
       
   306         TInt defaultSelection( iModel.DeviceType() );
       
   307         TInt iReplyValue = KASNoDevice;
       
   308         TAccPolGenericID iGenericID;
       
   309        
       
   310         // get the last connected wired accessory
       
   311         if(iModel.GetLastConnectedWiredAccessory(iGenericID))
       
   312             {
       
   313             // Device Type Supplied
       
   314             if( iGenericID.DeviceTypeCaps(KDTHeadset) )
       
   315                 {       
       
   316                 // This is a Headset
       
   317                 if( iPolicy->IsCapabilityDefinedL(iGenericID, KAccIntegratedAudioInput) ) 
       
   318                     {
       
   319                     if(KASTTY == defaultSelection)
       
   320                         {
       
   321                         iReplyValue = defaultSelection;
       
   322                         }
       
   323                     else
       
   324                         {
       
   325                         iReplyValue = KASHeadset;
       
   326                         }             
       
   327                     }
       
   328                 // This is a Headphone
       
   329                 else 
       
   330                     {
       
   331                     if(KASMusicStand == defaultSelection) 
       
   332                         {
       
   333                         iReplyValue = defaultSelection;
       
   334                         }
       
   335                     else
       
   336                         {
       
   337                         iReplyValue = KASHeadphones;
       
   338                         }
       
   339                     }
       
   340                 }
       
   341             else if( iGenericID.DeviceTypeCaps(KDTTTY) )
       
   342                 {
       
   343                 if( iPolicy->IsCapabilityDefinedL(iGenericID, KAccIntegratedAudioInput) )
       
   344                     {
       
   345                     if(KASHeadset == defaultSelection)
       
   346                         {
       
   347                         iReplyValue = defaultSelection;
       
   348                         }
       
   349                     else
       
   350                         {
       
   351                         iReplyValue = KASTTY;
       
   352                         }
       
   353                     }
       
   354                 }
       
   355             else if( iGenericID.DeviceTypeCaps(KDTOffice) )
       
   356                 {
       
   357                 if(KASHeadphones == defaultSelection)
       
   358                     {
       
   359                     iReplyValue = defaultSelection;
       
   360                     }
       
   361                 else
       
   362                     {
       
   363                     iReplyValue = KASMusicStand;
       
   364                     }
       
   365                 }
       
   366             // Device Type Not Supplied
       
   367             else if( iGenericID.DeviceTypeCaps() == KASNoDevice )
       
   368                 {
       
   369                 iReplyValue = defaultSelection;
       
   370                 }
       
   371 
       
   372             if( (KASNoDevice != iReplyValue) && (iReplyValue != iOldDeviceType) )
       
   373                 {
       
   374                 //update generic id
       
   375                 iPolicy->UpdateGenericIDL( iGenericID, iReplyValue);
       
   376                 // Update the "iConnectionArray" of CAccSrvServerModel, 
       
   377                 // to reflect the update on generic-id done earlier.
       
   378                 TAccPolGenericID oldGenericId; 
       
   379                 iModel.FindWithUniqueIDL( iGenericID.UniqueID(), oldGenericId );
       
   380                 
       
   381                 iConCtrl->HandleConnectionUpdateValidationL( 
       
   382                             iGenericID, oldGenericId, this, KErrNone );
       
   383         
       
   384                 TASYCommandParamRecord asyCommandParamRecord;
       
   385                 asyCommandParamRecord.iCmdValue   = 0;//Not used in update command
       
   386                 asyCommandParamRecord.iGenericID  = iGenericID;     
       
   387 
       
   388                 //Send request to ASY Proxy Handler
       
   389                 COM_TRACE_( "[AccFW:AccServer] CAccSrvConnectionHandler::RunL() - Send update request");
       
   390                 TInt trId = iConCtrl->HandleASYCommsL( ECmdAccessoryUpdated,
       
   391                                                     asyCommandParamRecord );
       
   392                 
       
   393                 iConCtrl->HandleAccessoryModeChangedL();
       
   394           
       
   395                 }            
       
   396             }
       
   397        
   300     COM_TRACE_( "[AccFW:AccServer] CAccSrvSettingsHandler::SetHWDeviceSettingsL() - return" );
   398     COM_TRACE_( "[AccFW:AccServer] CAccSrvSettingsHandler::SetHWDeviceSettingsL() - return" );
   301     }
   399     }
   302 
   400 
   303 // -----------------------------------------------------------------------------
   401 // -----------------------------------------------------------------------------
   304 // CAccSrvSettingsHandler::GetHWDeviceSettings
   402 // CAccSrvSettingsHandler::GetHWDeviceSettings