accessoryservices/accessoryserver/src/Server/AccSrvConnectionController.cpp
branchRCL_3
changeset 21 ccb4f6b3db21
parent 20 1ddbe54d0645
child 22 8cb079868133
equal deleted inserted replaced
20:1ddbe54d0645 21:ccb4f6b3db21
    38 
    38 
    39 // EXTERNAL FUNCTION PROTOTYPES
    39 // EXTERNAL FUNCTION PROTOTYPES
    40 
    40 
    41 // CONSTANTS
    41 // CONSTANTS
    42 
    42 
    43 const TUid KAccFwUiNoteNotifierUid = { 0x10205061 };
       
    44 
       
    45 // MACROS
    43 // MACROS
    46 
    44 
    47 // LOCAL CONSTANTS AND MACROS
    45 // LOCAL CONSTANTS AND MACROS
    48 
    46 
    49 // MODULE DATA STRUCTURES
    47 // MODULE DATA STRUCTURES
    61 // C++ default constructor can NOT contain any code, that
    59 // C++ default constructor can NOT contain any code, that
    62 // might leave.
    60 // might leave.
    63 // -----------------------------------------------------------------------------
    61 // -----------------------------------------------------------------------------
    64 //
    62 //
    65 CAccSrvConnectionController::CAccSrvConnectionController()
    63 CAccSrvConnectionController::CAccSrvConnectionController()
    66     : CActive( EPriorityStandard ),
    64     : iPolicy( NULL ),
    67       iPolicy( NULL ),
       
    68       iServerModel( NULL ),
    65       iServerModel( NULL ),
    69       iNotificationQueue( NULL ),
    66       iNotificationQueue( NULL ),
    70       iConnectionStatusHandler( NULL ),
    67       iConnectionStatusHandler( NULL ),
    71       iModeHandler( NULL ),
    68       iModeHandler( NULL ),
    72       iASYProxyHandler( NULL ),
    69       iASYProxyHandler( NULL ),
    73       iShowNotes( EFalse ),
    70       iWiredConnPublisher( NULL )
    74       iWiredConnPublisher( NULL ),
       
    75       iReplyPck( iReplyValue)
       
    76     {
    71     {
    77     COM_TRACE_( "[AccFW:AccServer] CAccSrvConnectionController::CAccSrvConnectionController()" );
    72     COM_TRACE_( "[AccFW:AccServer] CAccSrvConnectionController::CAccSrvConnectionController()" );
    78 
       
    79     CActiveScheduler::Add( this );//Add the active object to the active scheduler
       
    80 
    73 
    81     COM_TRACE_( "[AccFW:AccServer] CAccSrvConnectionController::CAccSrvConnectionController - return" );
    74     COM_TRACE_( "[AccFW:AccServer] CAccSrvConnectionController::CAccSrvConnectionController - return" );
    82     }
    75     }
    83 
    76 
    84 
    77 
    96     iPolicy                  = CAccPolAccessoryPolicy::NewL( &iServerModel->CapabilityStorage());
    89     iPolicy                  = CAccPolAccessoryPolicy::NewL( &iServerModel->CapabilityStorage());
    97     iNotificationQueue       = CAccSrvNotificationQueue::NewL();
    90     iNotificationQueue       = CAccSrvNotificationQueue::NewL();
    98     iConnectionStatusHandler = CAccSrvConnectionStatusHandler::NewL( this );
    91     iConnectionStatusHandler = CAccSrvConnectionStatusHandler::NewL( this );
    99     iModeHandler             = CAccSrvModeHandler::NewL( this );
    92     iModeHandler             = CAccSrvModeHandler::NewL( this );
   100     iASYProxyHandler         = CAccSrvASYProxyHandler::NewL( this );
    93     iASYProxyHandler         = CAccSrvASYProxyHandler::NewL( this );
   101     iSettingsHandler         = CAccSrvSettingsHandler::NewL( this, *aServerModel );
    94     iSettingsHandler         = CAccSrvSettingsHandler::NewL( this, *aServerModel, iPolicy );
   102     iWiredConnPublisher      = CAccSrvWiredConnectionPublisher::NewL();
    95     iWiredConnPublisher      = CAccSrvWiredConnectionPublisher::NewL();
   103 
    96 
   104     COM_TRACE_( "[AccFW:AccServer] CAccSrvConnectionController::ConstructL - return void" );
    97     COM_TRACE_( "[AccFW:AccServer] CAccSrvConnectionController::ConstructL - return void" );
   105     }
    98     }
   106 
    99 
   164 
   157 
   165     // Handlers must be deleted after iPolicy and iASYProxyHandler
   158     // Handlers must be deleted after iPolicy and iASYProxyHandler
   166     // (used from handlers).
   159     // (used from handlers).
   167     iConnectionHandler.ResetAndDestroy();
   160     iConnectionHandler.ResetAndDestroy();
   168     
   161     
   169     if ( iNotifier.Handle() )
       
   170         {
       
   171         iNotifier.Close();
       
   172         }
       
   173     Cancel();
       
   174 
       
   175     COM_TRACE_( "[AccFW:AccServer] CAccSrvConnectionController::~CAccSrvConnectionController - return" );
   162     COM_TRACE_( "[AccFW:AccServer] CAccSrvConnectionController::~CAccSrvConnectionController - return" );
   176     }
   163     }
   177 
   164 
   178 
   165 
   179 // -----------------------------------------------------------------------------
   166 // -----------------------------------------------------------------------------
   445 
   432 
   446     COM_TRACE_( "[AccFW:AccServer] CAccSrvConnectionController::HandleConnectionUpdateValidationL - return void" );
   433     COM_TRACE_( "[AccFW:AccServer] CAccSrvConnectionController::HandleConnectionUpdateValidationL - return void" );
   447     }
   434     }
   448 
   435 
   449 // -----------------------------------------------------------------------------
   436 // -----------------------------------------------------------------------------
       
   437 // CAccSrvConnectionController::HandleConnectionUpdateValidationL
       
   438 // -----------------------------------------------------------------------------
       
   439 //
       
   440 void CAccSrvConnectionController::HandleConnectionUpdateValidationL( 
       
   441     const TAccPolGenericID& aGenericID, 
       
   442     TAccPolGenericID& aOldGenericId,
       
   443     const CAccSrvSettingsHandler* /*aCaller*/,    
       
   444     TInt aError )
       
   445     {
       
   446     COM_TRACE_( "[AccFW:AccServer] CAccSrvConnectionController::HandleConnectionUpdateValidationL()" );
       
   447     
       
   448     TInt err ( KErrNone );
       
   449     TAccSrvConnection isValidConnection(EAccSrvConnect);
       
   450     TBool isConnected( iServerModel->IsConnected( aGenericID ) );
       
   451 
       
   452     if( KErrNone == aError )
       
   453         {   
       
   454         isValidConnection = iPolicy->IsValidConnectionL( aGenericID, err );
       
   455         }
       
   456     else
       
   457         {
       
   458         err = aError;
       
   459         isValidConnection = EAccSrvDeny;
       
   460         }
       
   461 
       
   462     if( iServerModel->FindAndRemoveCancelledConnectAccessory( aGenericID.UniqueID() ) )
       
   463         {
       
   464         //Connection of this accessory is cancelled.
       
   465         err = KErrCancel;
       
   466         isValidConnection = EAccSrvDeny;
       
   467         }
       
   468     
       
   469     switch( isValidConnection )
       
   470         {
       
   471         case EAccSrvDetect:
       
   472             {
       
   473             }
       
   474             break;
       
   475 
       
   476         case EAccSrvConnect:
       
   477             {
       
   478             if( isConnected )
       
   479                 {
       
   480                 //update connection generic id array
       
   481                 iServerModel->UpdateConnectionL( aGenericID);
       
   482                 
       
   483                 // Complete all possible connection status related requests
       
   484                 iNotificationQueue->CompleteControlMessageL( EAccessoryConnectionStatusChanged,
       
   485                                                              KErrNone,
       
   486                                                              aGenericID.UniqueID() );
       
   487                 iNotificationQueue->CompleteControlMessageL( EAccessoryDisconnected,
       
   488                                                              KErrNone,
       
   489                                                              aOldGenericId.UniqueID() );
       
   490                 iNotificationQueue->CompleteControlMessageL( ENewAccessoryConnected,
       
   491                                                              KErrNone,
       
   492                                                              aGenericID.UniqueID() );
       
   493                 }
       
   494 
       
   495             }
       
   496             break;
       
   497 
       
   498         case EAccSrvDeny:
       
   499             {
       
   500             iServerModel->RemovePhysicalConnection( aGenericID );
       
   501             iServerModel->RemoveASYThreadID( aGenericID.UniqueID() );//Remove ThreadID GID mapping
       
   502             iServerModel->CapabilityStorage().RemoveCapabilityList( aGenericID);
       
   503             
       
   504          
       
   505             }
       
   506             break;
       
   507 
       
   508         default:
       
   509             {
       
   510             TRACE_ASSERT_ALWAYS;//unhandled enum
       
   511             }
       
   512             break;
       
   513         }
       
   514 
       
   515     iNotificationQueue->CompleteControlMessageL( EConnectAccessory,
       
   516                                                  err,
       
   517                                                  aGenericID.UniqueID() );
       
   518     
       
   519 
       
   520     COM_TRACE_( "[AccFW:AccServer] CAccSrvConnectionController::HandleConnectionUpdateValidationL - return void" );
       
   521     }
       
   522 
       
   523 
       
   524 
       
   525 // -----------------------------------------------------------------------------
   450 // CAccSrvConnectionController::ConnectionHandlingCancel
   526 // CAccSrvConnectionController::ConnectionHandlingCancel
   451 // -----------------------------------------------------------------------------
   527 // -----------------------------------------------------------------------------
   452 //
   528 //
   453 void CAccSrvConnectionController::ConnectionHandlingCancel(
   529 void CAccSrvConnectionController::ConnectionHandlingCancel(
   454     const CAccSrvConnectionHandler* aCaller )
   530     const CAccSrvConnectionHandler* aCaller )
   620 void CAccSrvConnectionController::PromoteToConnectedL(
   696 void CAccSrvConnectionController::PromoteToConnectedL(
   621     const TAccPolGenericID& aGenericID )
   697     const TAccPolGenericID& aGenericID )
   622     {
   698     {
   623     COM_TRACE_( "[AccFW:AccServer] CAccSrvConnectionController::PromoteToConnectedL()" );
   699     COM_TRACE_( "[AccFW:AccServer] CAccSrvConnectionController::PromoteToConnectedL()" );
   624 
   700 
   625     iServerModel->RemovePhysicalConnection( aGenericID ); //Move GID from physical connection array
   701     if( KErrNotFound != iServerModel->RemovePhysicalConnection( aGenericID )) //Move GID from physical connection array
   626     iServerModel->AddConnectionL( aGenericID );            //to connection array
   702       {
   627 
   703 	    iServerModel->AddConnectionL( aGenericID );            //to connection array
   628     iNotificationQueue->CompleteControlMessageL( ENewAccessoryConnected,
   704 
   629                                                  KErrNone,
   705 	    iNotificationQueue->CompleteControlMessageL( ENewAccessoryConnected,
   630                                                  aGenericID.UniqueID() );
   706 	                                                 KErrNone,
   631 
   707 	                                                 aGenericID.UniqueID() );
   632     iConnectionStatusHandler->IssueRequest();
   708 
       
   709 	    iConnectionStatusHandler->IssueRequest();
       
   710 	  }
   633 
   711 
   634     COM_TRACE_( "[AccFW:AccServer] CAccSrvConnectionController::PromoteToConnectedL - return void" );
   712     COM_TRACE_( "[AccFW:AccServer] CAccSrvConnectionController::PromoteToConnectedL - return void" );
   635     }
   713     }
   636 
   714 
   637 // -----------------------------------------------------------------------------
   715 // -----------------------------------------------------------------------------
   726     iNotificationQueue->CompleteControlMessageL( EAccessoryConnectionStatusChanged,
   804     iNotificationQueue->CompleteControlMessageL( EAccessoryConnectionStatusChanged,
   727                                                  KErrNone,
   805                                                  KErrNone,
   728                                                  KErrNotFound );
   806                                                  KErrNotFound );
   729     iSettingsHandler->ConnectionStatusChangedL( genericIDArray );
   807     iSettingsHandler->ConnectionStatusChangedL( genericIDArray );
   730 
   808 
   731     // Able to show notes
       
   732     iShowNotes = ETrue;
       
   733     iModeHandler->IssueRequest();
   809     iModeHandler->IssueRequest();
   734 
   810 
   735     COM_TRACE_( "[AccFW:AccServer] CAccSrvConnectionController::HandleConnectionStatusChangedL - return void" );
   811     COM_TRACE_( "[AccFW:AccServer] CAccSrvConnectionController::HandleConnectionStatusChangedL - return void" );
   736     }
   812     }
   737     
   813     
   777                                                   aAudioOutputStatus, 
   853                                                   aAudioOutputStatus, 
   778                                                   iServerModel->AccessoryMode(), 
   854                                                   iServerModel->AccessoryMode(), 
   779                                                   iServerModel->UniqueID() );
   855                                                   iServerModel->UniqueID() );
   780         }
   856         }
   781 
   857 
   782 
       
   783     
   858     
   784 
   859 
   785     if( iServerModel->SetAccessoryMode( accMode, aDbId ) ) //Store accessory mode
   860     if( iServerModel->SetAccessoryMode( accMode, aDbId ) ) //Store accessory mode
   786         {
   861         {
   787         if( iModeHandler->IsActive() || iConnectionStatusHandler->IsActive() )
   862         if( iModeHandler->IsActive() || iConnectionStatusHandler->IsActive() )
   794             {
   869             {
   795             iNotificationQueue->CompleteControlMessageL( EAccessoryModeChanged,
   870             iNotificationQueue->CompleteControlMessageL( EAccessoryModeChanged,
   796                                                          KErrNone,
   871                                                          KErrNone,
   797                                                          KErrNotFound );
   872                                                          KErrNotFound );
   798             }
   873             }
   799 	
       
   800 		    COM_TRACE_( "[AccFW:AccServer] CAccSrvConnectionController::HandleAccessoryModeChangedL - Show information note!" );			
       
   801 
       
   802 		    TBool showNote( EFalse );
       
   803 		    TInt noteValue( 0 );
       
   804 			
       
   805 		    switch ( accMode.iAccessoryMode )
       
   806 		      {
       
   807 			    case EAccModeWiredHeadset:
       
   808 			    case EAccModeWiredCarKit:
       
   809 			    case EAccModeTextDevice:
       
   810 			    case EAccModeLoopset:
       
   811 			    case EAccModeMusicStand:
       
   812 			    case EAccModeTVOut:
       
   813 			    case EAccModeHeadphones:
       
   814 			    {
       
   815 				  TAccPolGenericID genericID;
       
   816 				  iServerModel->GetLastConnectedAccessoryL( genericID );
       
   817 				  TUint32 num = genericID.SubblockCaps();
       
   818 				  if ( genericID.PhysicalConnectionCaps() != KPCHDMI ) // No info note for HDMI
       
   819 				      {
       
   820                       if( num & KSBAudioSubblock )
       
   821                           {
       
   822                             CCapValue* capValue = iServerModel->CapabilityStorage().GetCapability( genericID, KAccIntegratedAudioInput );
       
   823                             if( iInformationNoteDefault )
       
   824                                   {
       
   825                                   noteValue = iInformationNoteDefault;
       
   826                                   showNote = ETrue;
       
   827                                   }
       
   828                             if( !capValue && !iInformationNoteDefault )
       
   829                                   {
       
   830                                   showNote = ETrue;
       
   831                                   }
       
   832                             }
       
   833                         else
       
   834                             {
       
   835                             if( iInformationNoteDefault )
       
   836                                   {
       
   837                                   noteValue = iInformationNoteDefault;
       
   838                                   showNote = ETrue;
       
   839                                   }
       
   840                             }
       
   841 				      }
       
   842 				  }
       
   843 			    break;			  
       
   844 			    default:
       
   845 			    {
       
   846 				  showNote = EFalse;				
       
   847 			    }
       
   848 			    break;
       
   849 		    }
       
   850 
       
   851 		    if ( showNote && iShowNotes )
       
   852 		        {		    	
       
   853 		        if( iServerModel->IdleDetected() )
       
   854 		            {
       
   855                     if ( iNotifier.Handle() )
       
   856                         {
       
   857                         iNotifier.Close();
       
   858                         }
       
   859 			        if( IsActive() )
       
   860 			            {
       
   861     		            Cancel();
       
   862     		            }
       
   863 
       
   864 			        //connect to notifier
       
   865 		            COM_TRACE_( "[AccFW:AccServer] CAccSrvConnectionController::HandleAccessoryModeChangedL - notifier.Connect" );
       
   866 		            TInt err = iNotifier.Connect();
       
   867 		            if(err != KErrNone)
       
   868 		                {
       
   869 		                //ok if cannot show note, this is possible during boot
       
   870 		                COM_TRACE_1( "[AccFW:AccServer] CAccSrvConnectionController::HandleAccessoryModeChangedL - Couldn't connect to notifier: err = %d", err);	
       
   871 		                }
       
   872 		            else
       
   873 		                {
       
   874 		                TPckg<TInt> valuePckg( noteValue );
       
   875 		                iStatus = KRequestPending;
       
   876                         iNotifier.StartNotifierAndGetResponse( 
       
   877                                         iStatus, 
       
   878                                         KAccFwUiNoteNotifierUid, 
       
   879                                         valuePckg, 
       
   880                                         iReplyPck);
       
   881                         SetActive();
       
   882     		            }
       
   883     		        }
       
   884 		        //reset values
       
   885 	            iShowNotes = EFalse;
       
   886 			    iInformationNoteUID = 0;
       
   887 			    iInformationNoteDefault = 0;			      
       
   888     		    }
       
   889         }        
   874         }        
   890     else
   875     else
   891         {
   876         {
   892         // Accessory Mode was allready up-to-date,
   877         // Accessory Mode was allready up-to-date,
   893         // no need to complete Accessory Mode changed notification.
   878         // no need to complete Accessory Mode changed notification.
   906 	const TUint32 aDefaultValue )
   891 	const TUint32 aDefaultValue )
   907     {
   892     {
   908 	COM_TRACE_( "[AccFW:AccServer] CAccSrvConnectionController::SetDefaultAccessoryInformation()" );
   893 	COM_TRACE_( "[AccFW:AccServer] CAccSrvConnectionController::SetDefaultAccessoryInformation()" );
   909 	iInformationNoteUID = aGenericID.UniqueID();
   894 	iInformationNoteUID = aGenericID.UniqueID();
   910 	iInformationNoteDefault = aDefaultValue;
   895 	iInformationNoteDefault = aDefaultValue;
   911     }
       
   912 
       
   913 // -----------------------------------------------------------------------------
       
   914 // CAccSrvConnectionController::RunL
       
   915 // -----------------------------------------------------------------------------
       
   916 //
       
   917 void CAccSrvConnectionController::RunL()
       
   918     {
       
   919     COM_TRACE_( "[AccFW:AccServer] CAccSrvConnectionController::RunL()" );
       
   920     
       
   921     iNotifier.Close();
       
   922     }
       
   923 
       
   924 // -----------------------------------------------------------------------------
       
   925 // CAccSrvConnectionController::DoCancel
       
   926 // -----------------------------------------------------------------------------
       
   927 //
       
   928 void CAccSrvConnectionController::DoCancel()
       
   929     {
       
   930     COM_TRACE_( "[AccFW:AccServer] CAccSrvConnectionController::DoCancel()" );
       
   931 
       
   932     COM_TRACE_( "[AccFW:AccServer] CAccSrvConnectionController::DoCancel - return void" );
       
   933     }
   896     }
   934 
   897 
   935 // -----------------------------------------------------------------------------
   898 // -----------------------------------------------------------------------------
   936 // CAccSrvConnectionController::RegisterControlMessageL
   899 // CAccSrvConnectionController::RegisterControlMessageL
   937 // -----------------------------------------------------------------------------
   900 // -----------------------------------------------------------------------------