accessoryservices/accessoryserver/src/Server/AccSrvConnectionController.cpp
branchRCL_3
changeset 22 8cb079868133
parent 21 ccb4f6b3db21
child 23 c26be94c8889
--- a/accessoryservices/accessoryserver/src/Server/AccSrvConnectionController.cpp	Tue Aug 31 16:29:05 2010 +0300
+++ b/accessoryservices/accessoryserver/src/Server/AccSrvConnectionController.cpp	Wed Sep 01 12:34:26 2010 +0100
@@ -40,6 +40,8 @@
 
 // CONSTANTS
 
+const TUid KAccFwUiNoteNotifierUid = { 0x10205061 };
+
 // MACROS
 
 // LOCAL CONSTANTS AND MACROS
@@ -61,16 +63,21 @@
 // -----------------------------------------------------------------------------
 //
 CAccSrvConnectionController::CAccSrvConnectionController()
-    : iPolicy( NULL ),
+    : CActive( EPriorityStandard ),
+      iPolicy( NULL ),
       iServerModel( NULL ),
       iNotificationQueue( NULL ),
       iConnectionStatusHandler( NULL ),
       iModeHandler( NULL ),
       iASYProxyHandler( NULL ),
-      iWiredConnPublisher( NULL )
+      iShowNotes( EFalse ),
+      iWiredConnPublisher( NULL ),
+      iReplyPck( iReplyValue)
     {
     COM_TRACE_( "[AccFW:AccServer] CAccSrvConnectionController::CAccSrvConnectionController()" );
 
+    CActiveScheduler::Add( this );//Add the active object to the active scheduler
+
     COM_TRACE_( "[AccFW:AccServer] CAccSrvConnectionController::CAccSrvConnectionController - return" );
     }
 
@@ -91,7 +98,7 @@
     iConnectionStatusHandler = CAccSrvConnectionStatusHandler::NewL( this );
     iModeHandler             = CAccSrvModeHandler::NewL( this );
     iASYProxyHandler         = CAccSrvASYProxyHandler::NewL( this );
-    iSettingsHandler         = CAccSrvSettingsHandler::NewL( this, *aServerModel, iPolicy );
+    iSettingsHandler         = CAccSrvSettingsHandler::NewL( this, *aServerModel );
     iWiredConnPublisher      = CAccSrvWiredConnectionPublisher::NewL();
 
     COM_TRACE_( "[AccFW:AccServer] CAccSrvConnectionController::ConstructL - return void" );
@@ -159,6 +166,12 @@
     // (used from handlers).
     iConnectionHandler.ResetAndDestroy();
     
+    if ( iNotifier.Handle() )
+        {
+        iNotifier.Close();
+        }
+    Cancel();
+
     COM_TRACE_( "[AccFW:AccServer] CAccSrvConnectionController::~CAccSrvConnectionController - return" );
     }
 
@@ -434,95 +447,6 @@
     }
 
 // -----------------------------------------------------------------------------
-// CAccSrvConnectionController::HandleConnectionUpdateValidationL
-// -----------------------------------------------------------------------------
-//
-void CAccSrvConnectionController::HandleConnectionUpdateValidationL( 
-    const TAccPolGenericID& aGenericID, 
-    TAccPolGenericID& aOldGenericId,
-    const CAccSrvSettingsHandler* /*aCaller*/,    
-    TInt aError )
-    {
-    COM_TRACE_( "[AccFW:AccServer] CAccSrvConnectionController::HandleConnectionUpdateValidationL()" );
-    
-    TInt err ( KErrNone );
-    TAccSrvConnection isValidConnection(EAccSrvConnect);
-    TBool isConnected( iServerModel->IsConnected( aGenericID ) );
-
-    if( KErrNone == aError )
-        {   
-        isValidConnection = iPolicy->IsValidConnectionL( aGenericID, err );
-        }
-    else
-        {
-        err = aError;
-        isValidConnection = EAccSrvDeny;
-        }
-
-    if( iServerModel->FindAndRemoveCancelledConnectAccessory( aGenericID.UniqueID() ) )
-        {
-        //Connection of this accessory is cancelled.
-        err = KErrCancel;
-        isValidConnection = EAccSrvDeny;
-        }
-    
-    switch( isValidConnection )
-        {
-        case EAccSrvDetect:
-            {
-            }
-            break;
-
-        case EAccSrvConnect:
-            {
-            if( isConnected )
-                {
-                //update connection generic id array
-                iServerModel->UpdateConnectionL( aGenericID);
-                
-                // Complete all possible connection status related requests
-                iNotificationQueue->CompleteControlMessageL( EAccessoryConnectionStatusChanged,
-                                                             KErrNone,
-                                                             aGenericID.UniqueID() );
-                iNotificationQueue->CompleteControlMessageL( EAccessoryDisconnected,
-                                                             KErrNone,
-                                                             aOldGenericId.UniqueID() );
-                iNotificationQueue->CompleteControlMessageL( ENewAccessoryConnected,
-                                                             KErrNone,
-                                                             aGenericID.UniqueID() );
-                }
-
-            }
-            break;
-
-        case EAccSrvDeny:
-            {
-            iServerModel->RemovePhysicalConnection( aGenericID );
-            iServerModel->RemoveASYThreadID( aGenericID.UniqueID() );//Remove ThreadID GID mapping
-            iServerModel->CapabilityStorage().RemoveCapabilityList( aGenericID);
-            
-         
-            }
-            break;
-
-        default:
-            {
-            TRACE_ASSERT_ALWAYS;//unhandled enum
-            }
-            break;
-        }
-
-    iNotificationQueue->CompleteControlMessageL( EConnectAccessory,
-                                                 err,
-                                                 aGenericID.UniqueID() );
-    
-
-    COM_TRACE_( "[AccFW:AccServer] CAccSrvConnectionController::HandleConnectionUpdateValidationL - return void" );
-    }
-
-
-
-// -----------------------------------------------------------------------------
 // CAccSrvConnectionController::ConnectionHandlingCancel
 // -----------------------------------------------------------------------------
 //
@@ -698,16 +622,14 @@
     {
     COM_TRACE_( "[AccFW:AccServer] CAccSrvConnectionController::PromoteToConnectedL()" );
 
-    if( KErrNotFound != iServerModel->RemovePhysicalConnection( aGenericID )) //Move GID from physical connection array
-      {
-	    iServerModel->AddConnectionL( aGenericID );            //to connection array
+    iServerModel->RemovePhysicalConnection( aGenericID ); //Move GID from physical connection array
+    iServerModel->AddConnectionL( aGenericID );            //to connection array
 
-	    iNotificationQueue->CompleteControlMessageL( ENewAccessoryConnected,
-	                                                 KErrNone,
-	                                                 aGenericID.UniqueID() );
+    iNotificationQueue->CompleteControlMessageL( ENewAccessoryConnected,
+                                                 KErrNone,
+                                                 aGenericID.UniqueID() );
 
-	    iConnectionStatusHandler->IssueRequest();
-	  }
+    iConnectionStatusHandler->IssueRequest();
 
     COM_TRACE_( "[AccFW:AccServer] CAccSrvConnectionController::PromoteToConnectedL - return void" );
     }
@@ -806,6 +728,8 @@
                                                  KErrNotFound );
     iSettingsHandler->ConnectionStatusChangedL( genericIDArray );
 
+    // Able to show notes
+    iShowNotes = ETrue;
     iModeHandler->IssueRequest();
 
     COM_TRACE_( "[AccFW:AccServer] CAccSrvConnectionController::HandleConnectionStatusChangedL - return void" );
@@ -855,6 +779,7 @@
                                                   iServerModel->UniqueID() );
         }
 
+
     
 
     if( iServerModel->SetAccessoryMode( accMode, aDbId ) ) //Store accessory mode
@@ -871,6 +796,96 @@
                                                          KErrNone,
                                                          KErrNotFound );
             }
+	
+		    COM_TRACE_( "[AccFW:AccServer] CAccSrvConnectionController::HandleAccessoryModeChangedL - Show information note!" );			
+
+		    TBool showNote( EFalse );
+		    TInt noteValue( 0 );
+			
+		    switch ( accMode.iAccessoryMode )
+		      {
+			    case EAccModeWiredHeadset:
+			    case EAccModeWiredCarKit:
+			    case EAccModeTextDevice:
+			    case EAccModeLoopset:
+			    case EAccModeMusicStand:
+			    case EAccModeTVOut:
+			    case EAccModeHeadphones:
+			    {
+				  TAccPolGenericID genericID;
+				  iServerModel->GetLastConnectedAccessoryL( genericID );
+				  TUint32 num = genericID.SubblockCaps();
+				  if ( genericID.PhysicalConnectionCaps() != KPCHDMI ) // No info note for HDMI
+				      {
+                      if( num & KSBAudioSubblock )
+                          {
+                            CCapValue* capValue = iServerModel->CapabilityStorage().GetCapability( genericID, KAccIntegratedAudioInput );
+                            if( iInformationNoteDefault )
+                                  {
+                                  noteValue = iInformationNoteDefault;
+                                  showNote = ETrue;
+                                  }
+                            if( !capValue && !iInformationNoteDefault )
+                                  {
+                                  showNote = ETrue;
+                                  }
+                            }
+                        else
+                            {
+                            if( iInformationNoteDefault )
+                                  {
+                                  noteValue = iInformationNoteDefault;
+                                  showNote = ETrue;
+                                  }
+                            }
+				      }
+				  }
+			    break;			  
+			    default:
+			    {
+				  showNote = EFalse;				
+			    }
+			    break;
+		    }
+
+		    if ( showNote && iShowNotes )
+		        {		    	
+		        if( iServerModel->IdleDetected() )
+		            {
+                    if ( iNotifier.Handle() )
+                        {
+                        iNotifier.Close();
+                        }
+			        if( IsActive() )
+			            {
+    		            Cancel();
+    		            }
+
+			        //connect to notifier
+		            COM_TRACE_( "[AccFW:AccServer] CAccSrvConnectionController::HandleAccessoryModeChangedL - notifier.Connect" );
+		            TInt err = iNotifier.Connect();
+		            if(err != KErrNone)
+		                {
+		                //ok if cannot show note, this is possible during boot
+		                COM_TRACE_1( "[AccFW:AccServer] CAccSrvConnectionController::HandleAccessoryModeChangedL - Couldn't connect to notifier: err = %d", err);	
+		                }
+		            else
+		                {
+		                TPckg<TInt> valuePckg( noteValue );
+		                iStatus = KRequestPending;
+                        iNotifier.StartNotifierAndGetResponse( 
+                                        iStatus, 
+                                        KAccFwUiNoteNotifierUid, 
+                                        valuePckg, 
+                                        iReplyPck);
+                        SetActive();
+    		            }
+    		        }
+		        //reset values
+	            iShowNotes = EFalse;
+			    iInformationNoteUID = 0;
+			    iInformationNoteDefault = 0;			      
+    		    }
         }        
     else
         {
@@ -896,6 +911,28 @@
     }
 
 // -----------------------------------------------------------------------------
+// CAccSrvConnectionController::RunL
+// -----------------------------------------------------------------------------
+//
+void CAccSrvConnectionController::RunL()
+    {
+    COM_TRACE_( "[AccFW:AccServer] CAccSrvConnectionController::RunL()" );
+    
+    iNotifier.Close();
+    }
+
+// -----------------------------------------------------------------------------
+// CAccSrvConnectionController::DoCancel
+// -----------------------------------------------------------------------------
+//
+void CAccSrvConnectionController::DoCancel()
+    {
+    COM_TRACE_( "[AccFW:AccServer] CAccSrvConnectionController::DoCancel()" );
+
+    COM_TRACE_( "[AccFW:AccServer] CAccSrvConnectionController::DoCancel - return void" );
+    }
+
+// -----------------------------------------------------------------------------
 // CAccSrvConnectionController::RegisterControlMessageL
 // -----------------------------------------------------------------------------
 //