accessoryservices/accessoryserver/src/Server/AccSrvConnectionController.cpp
branchRCL_3
changeset 21 ccb4f6b3db21
parent 20 1ddbe54d0645
child 22 8cb079868133
--- a/accessoryservices/accessoryserver/src/Server/AccSrvConnectionController.cpp	Thu Aug 19 11:09:10 2010 +0300
+++ b/accessoryservices/accessoryserver/src/Server/AccSrvConnectionController.cpp	Tue Aug 31 16:29:05 2010 +0300
@@ -40,8 +40,6 @@
 
 // CONSTANTS
 
-const TUid KAccFwUiNoteNotifierUid = { 0x10205061 };
-
 // MACROS
 
 // LOCAL CONSTANTS AND MACROS
@@ -63,21 +61,16 @@
 // -----------------------------------------------------------------------------
 //
 CAccSrvConnectionController::CAccSrvConnectionController()
-    : CActive( EPriorityStandard ),
-      iPolicy( NULL ),
+    : iPolicy( NULL ),
       iServerModel( NULL ),
       iNotificationQueue( NULL ),
       iConnectionStatusHandler( NULL ),
       iModeHandler( NULL ),
       iASYProxyHandler( NULL ),
-      iShowNotes( EFalse ),
-      iWiredConnPublisher( NULL ),
-      iReplyPck( iReplyValue)
+      iWiredConnPublisher( NULL )
     {
     COM_TRACE_( "[AccFW:AccServer] CAccSrvConnectionController::CAccSrvConnectionController()" );
 
-    CActiveScheduler::Add( this );//Add the active object to the active scheduler
-
     COM_TRACE_( "[AccFW:AccServer] CAccSrvConnectionController::CAccSrvConnectionController - return" );
     }
 
@@ -98,7 +91,7 @@
     iConnectionStatusHandler = CAccSrvConnectionStatusHandler::NewL( this );
     iModeHandler             = CAccSrvModeHandler::NewL( this );
     iASYProxyHandler         = CAccSrvASYProxyHandler::NewL( this );
-    iSettingsHandler         = CAccSrvSettingsHandler::NewL( this, *aServerModel );
+    iSettingsHandler         = CAccSrvSettingsHandler::NewL( this, *aServerModel, iPolicy );
     iWiredConnPublisher      = CAccSrvWiredConnectionPublisher::NewL();
 
     COM_TRACE_( "[AccFW:AccServer] CAccSrvConnectionController::ConstructL - return void" );
@@ -166,12 +159,6 @@
     // (used from handlers).
     iConnectionHandler.ResetAndDestroy();
     
-    if ( iNotifier.Handle() )
-        {
-        iNotifier.Close();
-        }
-    Cancel();
-
     COM_TRACE_( "[AccFW:AccServer] CAccSrvConnectionController::~CAccSrvConnectionController - return" );
     }
 
@@ -447,6 +434,95 @@
     }
 
 // -----------------------------------------------------------------------------
+// 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
 // -----------------------------------------------------------------------------
 //
@@ -622,14 +698,16 @@
     {
     COM_TRACE_( "[AccFW:AccServer] CAccSrvConnectionController::PromoteToConnectedL()" );
 
-    iServerModel->RemovePhysicalConnection( aGenericID ); //Move GID from physical connection array
-    iServerModel->AddConnectionL( aGenericID );            //to connection array
+    if( KErrNotFound != 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" );
     }
@@ -728,8 +806,6 @@
                                                  KErrNotFound );
     iSettingsHandler->ConnectionStatusChangedL( genericIDArray );
 
-    // Able to show notes
-    iShowNotes = ETrue;
     iModeHandler->IssueRequest();
 
     COM_TRACE_( "[AccFW:AccServer] CAccSrvConnectionController::HandleConnectionStatusChangedL - return void" );
@@ -779,7 +855,6 @@
                                                   iServerModel->UniqueID() );
         }
 
-
     
 
     if( iServerModel->SetAccessoryMode( accMode, aDbId ) ) //Store accessory mode
@@ -796,96 +871,6 @@
                                                          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
         {
@@ -911,28 +896,6 @@
     }
 
 // -----------------------------------------------------------------------------
-// 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
 // -----------------------------------------------------------------------------
 //