accessoryservices/accessoryserver/src/Server/AccSrvConnectionHandler.cpp
changeset 0 4e1aa6a622a0
child 13 cef4ff1e6c4f
child 43 0b0048910c20
equal deleted inserted replaced
-1:000000000000 0:4e1aa6a622a0
       
     1 /*
       
     2 * Copyright (c) 2002-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:  Connection Handler
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 // INCLUDE FILES
       
    21 #include "AccSrvConnectionHandler.h"
       
    22 #include "AccSrvConnectionController.h" //MAccSrvConnectionControllerObserver
       
    23 #include "AccPolSubblockNameArrayAccessor.h"
       
    24 #include "AccPolAccessoryPolicy.h"
       
    25 #include "AccSrvASYProxyHandler.h"
       
    26 #include "AccSrvServerModel.h"
       
    27 #include "AccPolGenericIDAccessor.h"
       
    28 #include "AccPolicyDB.h"
       
    29 #include "acc_debug.h"
       
    30 
       
    31 // EXTERNAL DATA STRUCTURES
       
    32 
       
    33 // EXTERNAL FUNCTION PROTOTYPES
       
    34 
       
    35 // CONSTANTS
       
    36 
       
    37 const TUid KAccFwUiDialogNotifierUid = { 0x10205062 };
       
    38 
       
    39 // MACROS
       
    40 
       
    41 // LOCAL CONSTANTS AND MACROS
       
    42 
       
    43 // MODULE DATA STRUCTURES
       
    44 
       
    45 // LOCAL FUNCTION PROTOTYPES
       
    46 
       
    47 // FORWARD DECLARATIONS
       
    48 
       
    49 // ============================= LOCAL FUNCTIONS ===============================
       
    50 
       
    51 // ============================ MEMBER FUNCTIONS ===============================
       
    52 
       
    53 // -----------------------------------------------------------------------------
       
    54 // CAccSrvConnectionHandler::CAccSrvConnectionHandler
       
    55 // -----------------------------------------------------------------------------
       
    56 //
       
    57 CAccSrvConnectionHandler::CAccSrvConnectionHandler(
       
    58     MAccSrvConnectionControllerObserver* aCallback,
       
    59     CAccSrvServerModel * aModel,
       
    60     CAccPolAccessoryPolicy* aPolicy )
       
    61     : CAccSrvHandlerBase (aCallback),
       
    62       iPolicy( aPolicy ),
       
    63       iModel( aModel),
       
    64       iReplyValue(0),
       
    65       iReplyPck( iReplyValue)
       
    66     {
       
    67     COM_TRACE_( "[AccFW:AccServer] CAccSrvConnectionHandler::CAccSrvConnectionHandler()" );
       
    68     }
       
    69 
       
    70 // -----------------------------------------------------------------------------
       
    71 // CAccSrvConnectionHandler::ConstructL
       
    72 // Symbian 2nd phase constructor can leave.
       
    73 // -----------------------------------------------------------------------------
       
    74 //
       
    75 void CAccSrvConnectionHandler::ConstructL()
       
    76     {
       
    77     COM_TRACE_( "[AccFW:AccServer] CAccSrvConnectionHandler::ConstructL()" );
       
    78     }
       
    79 
       
    80 
       
    81 // -----------------------------------------------------------------------------
       
    82 // CAccSrvConnectionHandler::NewL
       
    83 // Two-phased constructor.
       
    84 // -----------------------------------------------------------------------------
       
    85 //
       
    86 CAccSrvConnectionHandler* CAccSrvConnectionHandler::NewL( 
       
    87     MAccSrvConnectionControllerObserver* aCallback,
       
    88 	CAccSrvServerModel* aModel,
       
    89     CAccPolAccessoryPolicy* aPolicy )
       
    90     {
       
    91     COM_TRACE_( "[AccFW:AccServer] CAccSrvConnectionHandler::NewL()" );
       
    92 
       
    93     CAccSrvConnectionHandler* self = new( ELeave ) CAccSrvConnectionHandler( 
       
    94                                                         aCallback, aModel, aPolicy );
       
    95 
       
    96     CleanupStack::PushL( self );
       
    97     self->ConstructL();
       
    98     CleanupStack::Pop( self );
       
    99 
       
   100     COM_TRACE_( "[AccFW:AccServer] CAccSrvConnectionHandler::NewL - return self" );
       
   101     return self;
       
   102     }
       
   103 
       
   104 // Destructor
       
   105 CAccSrvConnectionHandler::~CAccSrvConnectionHandler()
       
   106     {
       
   107     COM_TRACE_( "[AccFW:AccServer] CAccSrvConnectionHandler::~CAccSrvConnectionHandler()" );
       
   108 
       
   109 	//closes notfier connection
       
   110     iNotifier.Close();
       
   111     iRequestDataArray.Close();
       
   112     }
       
   113 
       
   114 // -----------------------------------------------------------------------------
       
   115 // CAccSrvConnectionHandler::RunL
       
   116 // -----------------------------------------------------------------------------
       
   117 //
       
   118 void CAccSrvConnectionHandler::RunL()
       
   119     {
       
   120     COM_TRACE_( "[AccFW:AccServer] CAccSrvConnectionHandler::RunL()" );
       
   121 
       
   122 	switch ( iState )
       
   123 	    {	
       
   124 		/*
       
   125 		Get response from the user (the notifier completes asyncronous command). Send
       
   126 		accessory update command to ASY. 
       
   127 		*/
       
   128 	
       
   129 		case EGetSelectionFromUser:
       
   130 	    	{
       
   131 		    COM_TRACE_( "[AccFW:AccServer] CAccSrvConnectionHandler::RunL() - Get selection from user" );
       
   132 				
       
   133 			if ( iReplyValue )
       
   134 			    {
       
   135 			    COM_TRACE_1( "[AccFW:AccServer] CAccSrvConnectionHandler::RunL() - User selection %d", iReplyValue );
       
   136 
       
   137 				//update generic id
       
   138 				iPolicy->UpdateGenericIDL( iGenericID, iReplyValue);
       
   139 		
       
   140 				TASYCommandParamRecord asyCommandParamRecord;
       
   141     		    asyCommandParamRecord.iCmdValue   = 0;//Not used in update command
       
   142         		asyCommandParamRecord.iGenericID  = iGenericID;		
       
   143 
       
   144 			    //Send request to ASY Proxy Handler
       
   145 			    COM_TRACE_( "[AccFW:AccServer] CAccSrvConnectionHandler::RunL() - Send update request");
       
   146 			    TInt trId = iCallback->HandleASYCommsL( ECmdAccessoryUpdated,
       
   147         		                               		asyCommandParamRecord );
       
   148 
       
   149 	    		//Stored request data is used when response is received from ASY
       
   150 		    	//(i.e. HandleValueMessageL)
       
   151     			StoreRequestData( asyCommandParamRecord.iNameRecord, trId, ETrue );
       
   152 
       
   153 	    		//Store this object to queue to be able to receive response from ASY
       
   154     			iCallback->RegisterControlMessageL( ESetValue, this );
       
   155 
       
   156     			//closes notfier connection
       
   157                 iNotifier.Close();
       
   158 			    }
       
   159 			else
       
   160 			    {
       
   161                 // If this is KErrCancel, cancel is already done. Handle only if user has cancelled the dialog
       
   162                 if ( KErrNone == iStatus.Int() )
       
   163                     {
       
   164                     COM_TRACE_( "[AccFW:AccServer] CAccSrvConnectionHandler::RunL() - User cancel");
       
   165     	      	    iCallback->ConnectionHandlingCancel( this);	
       
   166                     }
       
   167 			    }
       
   168             
       
   169 	    	}
       
   170             break;
       
   171 
       
   172 		case EInitializeConnection:
       
   173 		    {
       
   174 		    if( iCallback->ServerModelHandle().ASYsLoadCompleted() )
       
   175 	            {
       
   176    	        	if ( iConnectionUpdate )
       
   177    	        	    {
       
   178    	        		//get new capabilities to use
       
   179 				    COM_TRACE_( "[AccFW:AccServer] CAccSrvConnectionHandler::RunL() - Connection update, set new capabilities");
       
   180    	        		iModel->CapabilityStorage().UseUpdatedGenericIDL( iGenericID);
       
   181    	        	    }
       
   182    	        
       
   183     	    	if ( InitializeCriticalCapsL() )
       
   184             	    {	
       
   185 	            	//ASY query started
       
   186     	    	    }
       
   187         		else
       
   188     	            {
       
   189     	        	if ( iConnectionUpdate )
       
   190     	        	    {
       
   191 	    	        	//No critical caps, continue connection handling
       
   192 	    	        	TAccPolGenericID oldGenericId; 
       
   193 	    	        	iModel->FindWithUniqueIDL(  iGenericID.UniqueID(), oldGenericId);
       
   194     		        	iCallback->HandleConnectionUpdateValidationL( 
       
   195                             iGenericID, oldGenericId, this, KErrNone );    	        		
       
   196     	        	    }
       
   197     	        	else
       
   198     	        	    {
       
   199 	    	        	//No critical caps, continue connection handling
       
   200     		        	iCallback->HandleConnectValidationL( iGenericID, this, KErrNone );
       
   201 	   	        	    }
       
   202 	                }
       
   203 	    	    }
       
   204 	    	else
       
   205         	    {
       
   206 	    	    //ASY is not ready yet, wait for an another RunL-loop
       
   207     	    	CAccSrvHandlerBase::IssueRequest();
       
   208         	    }			
       
   209 		    }
       
   210 		    break;
       
   211 
       
   212 		case EWaitForUINotifier:
       
   213 		    {
       
   214             // If cancelled, do not show dialog
       
   215             if ( KErrCancel != iStatus.Int() )
       
   216                 {
       
   217                 COM_TRACE_( "[AccFW:AccServer] CAccSrvConnectionHandler::RunL() - Change in boot state, try again open selection dialog" );
       
   218 			    OpenSelectionDialogL();			
       
   219 		        }
       
   220 			}
       
   221 		    break;
       
   222 
       
   223 		default:
       
   224             TRACE_ASSERT_ALWAYS;
       
   225             break;
       
   226 	    }
       
   227 
       
   228     COM_TRACE_( "[AccFW:AccServer] CAccSrvConnectionHandler::RunL - return void" );
       
   229     }
       
   230 
       
   231 // -----------------------------------------------------------------------------
       
   232 // CAccSrvConnectionHandler::StartConnectionHandling
       
   233 // -----------------------------------------------------------------------------
       
   234 //
       
   235 void CAccSrvConnectionHandler::StartConnectionHandlingL( 
       
   236     TAccPolGenericID& aGenericID, 
       
   237     TBool aEvaluateConnectionRules, 
       
   238     TBool aUpdatedConnection )
       
   239     {
       
   240     COM_TRACE_( "[AccFW:AccServer] CAccSrvConnectionHandler::StartConnectionHandling()" );
       
   241 
       
   242     iGenericID = aGenericID;
       
   243     iConnectionUpdate = aUpdatedConnection;
       
   244     
       
   245     //evaluate connection rules
       
   246     if ( aEvaluateConnectionRules )
       
   247         {
       
   248   		COM_TRACE_( "[AccFW:AccServer] CAccSrvConnectionHandler::StartConnectionHandling() - Evaluate connection rules" );
       
   249  
       
   250     	//check rules
       
   251     	TUint32 selectionListBitmask( 0 );	
       
   252     	iPolicy->EvaluateConnectionRulesL( iGenericID, selectionListBitmask );
       
   253     	
       
   254     	if ( selectionListBitmask )
       
   255     	    {
       
   256 	  		COM_TRACE_1( "[AccFW:AccServer] CAccSrvConnectionHandler::StartConnectionHandling() - Selection bitmask: 0x%bb", selectionListBitmask);
       
   257     		
       
   258     		//remove not supported items...
       
   259     		selectionListBitmask = selectionListBitmask & iModel->SupportedDevicesL();
       
   260     			
       
   261     		//Check default selection
       
   262     		TInt defaultSelection( iModel->DeviceType() );
       
   263     		
       
   264     		if ( selectionListBitmask == ( KASTTY | KASHeadset ) )
       
   265     		    {
       
   266     			if ( defaultSelection != KASTTY )
       
   267     			    {
       
   268     				defaultSelection = KASHeadset;
       
   269     			    }
       
   270     			else
       
   271     			    {
       
   272     				defaultSelection = KASTTY;
       
   273     			    }
       
   274     		    }
       
   275     		else
       
   276     		    {
       
   277     			if ( defaultSelection == KASHeadset )
       
   278     			    {
       
   279     				defaultSelection = 0;
       
   280     			    }
       
   281     			
       
   282     			defaultSelection = selectionListBitmask & defaultSelection;	
       
   283     		    }
       
   284     		
       
   285     		if ( defaultSelection )
       
   286     		    {
       
   287     			iReplyValue = defaultSelection;
       
   288     			iCallback->SetDefaultAccessoryInformation( iGenericID, defaultSelection );
       
   289     			CAccSrvHandlerBase::IssueRequest();
       
   290     		    }
       
   291     		else
       
   292     		    {
       
   293     			//check that more than one accessories in the selection list
       
   294     			TUint32 bitmask( 1 );
       
   295     			TInt accCount( 0 ); 
       
   296     			for ( TInt i( 0 ); i < 32; i++  )
       
   297     			    {
       
   298     				if ( selectionListBitmask & bitmask )
       
   299     				    {
       
   300     					if ( ++accCount > 1 )
       
   301     					    {
       
   302     						//more than one accessories, stop the loop
       
   303     						break;
       
   304     					    }
       
   305     				    }
       
   306     				bitmask <<= 1;
       
   307     			    }
       
   308     		
       
   309     			if ( accCount > 1 )
       
   310     			    {
       
   311 	    			//if there is possible selection show UI
       
   312 		    		SetupSelectionDialogL( selectionListBitmask );    			
       
   313     			    }
       
   314     			else
       
   315     			    {
       
   316     				//only one selection, don't show selection dialog
       
   317     				iState = EGetSelectionFromUser;	
       
   318     				iReplyValue = selectionListBitmask;
       
   319     				iCallback->SetDefaultAccessoryInformation( iGenericID, selectionListBitmask );
       
   320     				CAccSrvHandlerBase::IssueRequest();
       
   321     			    }
       
   322     		    }
       
   323     		
       
   324     	    }
       
   325     	else
       
   326     	    {
       
   327     		iState = EInitializeConnection;	
       
   328         	}
       
   329     	
       
   330         }
       
   331     else
       
   332         {
       
   333   		COM_TRACE_( "[AccFW:AccServer] CAccSrvConnectionHandler::StartConnectionHandling() - No connection rules" );
       
   334     	iState = EInitializeConnection;
       
   335         }
       
   336 
       
   337 
       
   338     // Atleas one Asynchronous request is made for ourselves,
       
   339     // clients ConnectAccessory asynchronous request will be completed
       
   340     // during it.
       
   341     if ( iState == EInitializeConnection )
       
   342         {
       
   343  	    CAccSrvHandlerBase::IssueRequest();
       
   344         }
       
   345 
       
   346     COM_TRACE_( "[AccFW:AccServer] CAccSrvConnectionHandler::StartConnectionHandling- return void" );
       
   347     }
       
   348 
       
   349 // -----------------------------------------------------------------------------
       
   350 // CAccSrvConnectionHandler::OpenSelectionDialogL
       
   351 // -----------------------------------------------------------------------------
       
   352 //
       
   353 void CAccSrvConnectionHandler::OpenSelectionDialogL()
       
   354     {
       
   355 	COM_TRACE_( "[AccFW:AccServer] CAccSrvConnectionHandler::OpenSelectionDialogL() - start" );
       
   356 			    
       
   357 
       
   358 	if ( !iModel->IdleDetected() )	
       
   359 	    {
       
   360 		COM_TRACE_( "[AccFW:AccServer] CAccSrvConnectionHandler::OpenSelectionDialogL() - Idle is not detected" );
       
   361 
       
   362 		//boot is ongoing, wait for that ui notifier is ready	
       
   363 		iState = EWaitForUINotifier;
       
   364 		
       
   365 		//wait for idle
       
   366 		Cancel();
       
   367 		iStatus = KRequestPending;
       
   368 		iModel->WaitForIdle( &iStatus );
       
   369 		SetActive();
       
   370 	    }
       
   371 	else
       
   372 	    {
       
   373 		COM_TRACE_( "[AccFW:AccServer] CAccSrvConnectionHandler::OpenSelectionDialogL() - Boot ok, connect notifier" );
       
   374 
       
   375 		iState = EGetSelectionFromUser;
       
   376 		
       
   377    		//selection bit mask package
       
   378 	    TPckg<TUint32> selectionBitmaskPackage( iSelectionListBitmask );
       
   379 	
       
   380 		//activate active object
       
   381 		Cancel();
       
   382 		iStatus = KRequestPending;
       
   383 	
       
   384 		//open ui		
       
   385 		COM_TRACE_( "[AccFW:AccServer] CAccSrvConnectionHandler::OpenSelectionDialogL() - Open selection dialog" );
       
   386         User::LeaveIfError( iNotifier.Connect() );
       
   387 		iNotifier.StartNotifierAndGetResponse( 
       
   388                         iStatus, 
       
   389                         KAccFwUiDialogNotifierUid, 
       
   390                         selectionBitmaskPackage, 
       
   391                         iReplyPck);		
       
   392 		SetActive();
       
   393 	    }
       
   394 
       
   395 	COM_TRACE_( "[AccFW:AccServer] CAccSrvConnectionHandler::OpenSelectionDialogL() - end" );
       
   396     }
       
   397 
       
   398 // -----------------------------------------------------------------------------
       
   399 // CAccSrvConnectionHandler::OpenSelectionDialogL
       
   400 // -----------------------------------------------------------------------------
       
   401 //
       
   402 void CAccSrvConnectionHandler::SetupSelectionDialogL( TUint32 aSelectionListBitmask )
       
   403     {
       
   404 	COM_TRACE_( "[AccFW:AccServer] CAccSrvConnectionHandler::SetupSelectionDialogL() - start" );
       
   405 	iSelectionListBitmask = aSelectionListBitmask;		    
       
   406 	//open dialog	
       
   407 	OpenSelectionDialogL();
       
   408 	COM_TRACE_( "[AccFW:AccServer] CAccSrvConnectionHandler::SetupSelectionDialogL() - end" );	
       
   409     }
       
   410 
       
   411 
       
   412 // -----------------------------------------------------------------------------
       
   413 // CAccSrvConnectionHandler::UniqueIDForConnectionHandler
       
   414 // -----------------------------------------------------------------------------
       
   415 //
       
   416 TInt CAccSrvConnectionHandler::UniqueIDForConnectionHandler()
       
   417     {
       
   418 	return iGenericID.UniqueID();
       
   419     }
       
   420         
       
   421 // -----------------------------------------------------------------------------
       
   422 // CAccSrvConnectionHandler::CancelConnectionHandling
       
   423 // -----------------------------------------------------------------------------
       
   424 //
       
   425 void CAccSrvConnectionHandler::CancelConnectionHandling() 
       
   426     {
       
   427 	COM_TRACE_( "[AccFW:AccServer] CAccSrvConnectionHandler::CancelConnectionHandling() - start" );
       
   428 
       
   429     if ( iNotifier.Handle() )
       
   430         {
       
   431         // If notifier exists, it must be cancelled
       
   432         iNotifier.CancelNotifier( KAccFwUiDialogNotifierUid );
       
   433         iNotifier.Close();
       
   434         // No need to cancel notifier request, cancel comes from notifier
       
   435         }
       
   436 
       
   437     else if ( IsActive() )
       
   438         {
       
   439         if ( EWaitForUINotifier == iState )
       
   440             {
       
   441             // Internal request, cancel in different way
       
   442             iModel->CancelWaitForIdle();
       
   443             }
       
   444         else
       
   445             {
       
   446             Cancel();   
       
   447             }
       
   448         }
       
   449     
       
   450 	// remove this from NotificationQueue
       
   451     iCallback->CancelControlMessage( ESetValue, this );
       
   452 	COM_TRACE_( "[AccFW:AccServer] CAccSrvConnectionHandler::CancelConnectionHandling() - end" );
       
   453     }
       
   454 
       
   455 // -----------------------------------------------------------------------------
       
   456 // CAccSrvConnectionHandler::ResetHandler
       
   457 // Resets member variables and is free to handle next connection
       
   458 // -----------------------------------------------------------------------------
       
   459 //
       
   460 void CAccSrvConnectionHandler::ResetHandler()
       
   461     {
       
   462     COM_TRACE_( "[AccFW:AccServer] CAccSrvConnectionHandler::ResetHandler() - start" );
       
   463     // Reset member variables related to connection
       
   464     iSelectionListBitmask = 0;
       
   465     iReplyValue = 0;
       
   466     iState = EGetSelectionFromUser;
       
   467     iRequestDataArray.Reset();
       
   468     // Reset generic id. This also indicates that this hander has no connection
       
   469     TAccPolGenericID temp;
       
   470     iGenericID = temp;
       
   471     // No need to reset iPolicy, iModel or iGenericID
       
   472     COM_TRACE_( "[AccFW:AccServer] CAccSrvConnectionHandler::ResetHandler() - end" );
       
   473     }
       
   474 
       
   475 // -----------------------------------------------------------------------------
       
   476 // CAccSrvConnectionHandler::IsFree
       
   477 // -----------------------------------------------------------------------------
       
   478 //
       
   479 TBool CAccSrvConnectionHandler::IsFree()
       
   480     {
       
   481     COM_TRACE_1( "[AccFW:AccServer] CAccSrvConnectionHandler::IsFree() - UniqueID(%i)", iGenericID.UniqueID() );
       
   482     return ( KErrNotFound == iGenericID.UniqueID() );
       
   483     }
       
   484 
       
   485 // -----------------------------------------------------------------------------
       
   486 // CAccSrvConnectionHandler::InitializeCriticalCapsL
       
   487 // -----------------------------------------------------------------------------
       
   488 //
       
   489 TBool CAccSrvConnectionHandler::InitializeCriticalCapsL()
       
   490     {
       
   491     COM_TRACE_( "[AccFW:AccServer] CAccSrvConnectionHandler::InitializeCriticalCapsL()" );
       
   492 
       
   493     TBool                    ASYqueryStarted( EFalse );
       
   494     TAccPolNameRecord        nameRecord;
       
   495     TUint32					 name( 0 );
       
   496     TASYCommandParamRecord   asyCommandParamRecord;
       
   497 
       
   498     CAccPolSubblockNameArray* criticalCapabilities = CAccPolSubblockNameArray::NewL();
       
   499     CleanupStack::PushL( criticalCapabilities );
       
   500 
       
   501     //After this query, criticalCapabilities contains all critical capabilities from iGenericID
       
   502     iPolicy->ResolveCriticalCapabilitiesL( iGenericID, *criticalCapabilities );
       
   503 
       
   504     TInt nameCount( TAccPolSubblockNameArrayAccessor::GetCount( *criticalCapabilities ) );
       
   505 
       
   506     for ( TInt i( 0 ) ; i<nameCount ; ++i )
       
   507         {
       
   508         TAccPolSubblockNameArrayAccessor::GetName( *criticalCapabilities,
       
   509                                                     i,
       
   510                                                     name );
       
   511   	    nameRecord.SetName( name );
       
   512         asyCommandParamRecord.iNameRecord = nameRecord;
       
   513         asyCommandParamRecord.iCmdValue   = 0;//Not used in Getters
       
   514         asyCommandParamRecord.iGenericID  = iGenericID;
       
   515 
       
   516 		    CCapValue* capValue = iModel->CapabilityStorage().GetCapability( iGenericID, name );
       
   517 		
       
   518 		    if ( !capValue)
       
   519 		        {
       
   520 			      User::Leave( KErrArgument );
       
   521 		        }
       
   522 
       
   523 		    if ( capValue->Type() == EAPVBool || 
       
   524              capValue->Type() == EAPVUInt || 
       
   525              capValue->Type() == EAPVInt )
       
   526 		        {
       
   527 			      TInt32 value( 0 );
       
   528 			      TInt err( capValue->ValueInt( value ) );
       
   529 		
       
   530 			      if ( value == KErrUnknown && err == KErrNone )
       
   531 			          {
       
   532     		        StartASYCommandHandlingL( capValue->Type(), asyCommandParamRecord );
       
   533 		            ASYqueryStarted = ETrue;
       
   534 			          }
       
   535 		        }
       
   536 		    else
       
   537 		       {
       
   538     	     StartASYCommandHandlingL( capValue->Type(), asyCommandParamRecord );
       
   539 	         ASYqueryStarted = ETrue;
       
   540 		       }
       
   541        }
       
   542 
       
   543     CleanupStack::PopAndDestroy( criticalCapabilities );
       
   544 
       
   545     //In case of BT, query supported BT-profiles from BT-ASY
       
   546     if ( iGenericID.PhysicalConnectionCaps( KPCBluetooth ) )
       
   547         {
       
   548         TAccPolNameRecord emptyNameRecord;
       
   549 
       
   550         asyCommandParamRecord.iNameRecord = emptyNameRecord;
       
   551         asyCommandParamRecord.iCmdValue   = iGenericID.DeviceAddress();
       
   552         asyCommandParamRecord.iGenericID  = iGenericID;
       
   553 
       
   554         StartASYCommandHandlingL( EAPVDes8, asyCommandParamRecord );
       
   555 
       
   556         ASYqueryStarted = ETrue;
       
   557         }
       
   558 
       
   559     COM_TRACE_1( "[AccFW:AccServer] CAccSrvConnectionHandler::InitializeCriticalCapsL - return %d", ASYqueryStarted );
       
   560     return ( ASYqueryStarted );
       
   561     }
       
   562 
       
   563 // -----------------------------------------------------------------------------
       
   564 // CAccSrvConnectionHandler::StartASYCommandHandlingL
       
   565 // -----------------------------------------------------------------------------
       
   566 //
       
   567 void CAccSrvConnectionHandler::StartASYCommandHandlingL( 
       
   568     TAccPolValueType aValueType,
       
   569     TASYCommandParamRecord& aASYCommandParam )
       
   570     {
       
   571     TProcessCmdId command( ECmdBadFunction );
       
   572     TInt          trId( 0 );
       
   573 
       
   574     switch ( aValueType )
       
   575         {
       
   576         case EAPVBool:
       
   577             {
       
   578             command = ECmdGetValueBool;
       
   579             }
       
   580             break;
       
   581 
       
   582         case EAPVInt:
       
   583             {
       
   584             command = ECmdGetValueTInt;
       
   585             }
       
   586             break;
       
   587 
       
   588         case EAPVDes8:
       
   589             {
       
   590             if ( aASYCommandParam.iGenericID.PhysicalConnectionCaps( KPCBluetooth ) )
       
   591                 {
       
   592                 //Supported profiles are queried from BT-ASY
       
   593                 command = ECmdGetSupportedBTProfiles;
       
   594                 }
       
   595             else
       
   596                 {
       
   597                 command = ECmdGetValueTDes8;
       
   598                 }
       
   599             }
       
   600             break;
       
   601 
       
   602         default:
       
   603             {
       
   604             TRACE_ASSERT_ALWAYS;
       
   605             }
       
   606             break;
       
   607         }
       
   608 
       
   609     //Send request to ASY Proxy Handler
       
   610     trId = iCallback->HandleASYCommsL( command, aASYCommandParam );
       
   611 
       
   612     //Stored request data is used when response is received from ASY
       
   613     //(i.e. HandleValueMessageL)
       
   614     StoreRequestData( aASYCommandParam.iNameRecord, trId, EFalse );
       
   615 
       
   616     //Store this object to queue to be able to receive response from ASY
       
   617     iCallback-> RegisterControlMessageL( EGetValue, this );
       
   618 
       
   619     }
       
   620 // -----------------------------------------------------------------------------
       
   621 // CAccSrvConnectionHandler::StoreRequestData
       
   622 // -----------------------------------------------------------------------------
       
   623 //
       
   624 void CAccSrvConnectionHandler::StoreRequestData( TAccPolNameRecord aName,
       
   625                                                  TInt aTrId,
       
   626                                                  TBool aUpdateConnectionNotification )
       
   627     {
       
   628     COM_TRACE_( "[AccFW:AccServer] CAccSrvConnectionHandler::StoreRequestData()" );
       
   629 
       
   630     TAccSrvRequestData requestData;
       
   631     requestData.iName = aName;
       
   632     requestData.iTrId = aTrId;
       
   633     requestData.iUpdateNotification = aUpdateConnectionNotification;
       
   634 
       
   635     iRequestDataArray.Append( requestData );
       
   636 
       
   637     COM_TRACE_( "[AccFW:AccServer] CAccSrvConnectionHandler::StoreRequestData - return void" );
       
   638     }
       
   639 
       
   640 // -----------------------------------------------------------------------------
       
   641 // CAccSrvConnectionHandler::FindRequestData
       
   642 //
       
   643 // Find the location of aTrId from iRequestDataArray
       
   644 // -----------------------------------------------------------------------------
       
   645 //
       
   646 TInt CAccSrvConnectionHandler::FindRequestData( TInt aTrId )
       
   647     {
       
   648     COM_TRACE_( "[AccFW:AccServer] CAccSrvConnectionHandler::FindRequestData()" );
       
   649 
       
   650     TInt index( KErrNotFound );
       
   651     TInt count( iRequestDataArray.Count() );
       
   652 
       
   653     for ( TInt i( 0 ); i < count ; ++i )
       
   654         {
       
   655         if( iRequestDataArray.operator[]( i ).iTrId == aTrId )
       
   656             {
       
   657             index = i;//match found
       
   658             }
       
   659         }
       
   660 
       
   661     COM_TRACE_1( "[AccFW:AccServer] CAccSrvConnectionHandler::FindRequestData - return %d", index );
       
   662     return index;
       
   663     }
       
   664 
       
   665 // -----------------------------------------------------------------------------
       
   666 // CAccSrvConnectionHandler::HandleValueMessageL (From MQueueObserver)
       
   667 // -----------------------------------------------------------------------------
       
   668 //
       
   669 void CAccSrvConnectionHandler::HandleValueMessageL( TMsgID aMsgID,
       
   670                                                     TAccValueTypeTBool aValue,
       
   671                                                     TInt aErrorCode,
       
   672                                                     TInt aTrId )
       
   673     {
       
   674     COM_TRACE_( "[AccFW:AccServer] CAccSrvConnectionHandler::HandleValueMessageL() - TBool" );
       
   675 
       
   676     HandleValueMessagesL( aMsgID, aValue.iValue, aErrorCode, aTrId );
       
   677 
       
   678     COM_TRACE_( "[AccFW:AccServer] CAccSrvConnectionHandler::HandleValueMessageL - TBool - return void" );
       
   679     }
       
   680 
       
   681 // -----------------------------------------------------------------------------
       
   682 // CAccSrvConnectionHandler::HandleValueMessageL (From MQueueObserver)
       
   683 // -----------------------------------------------------------------------------
       
   684 //
       
   685 void CAccSrvConnectionHandler::HandleValueMessageL( TMsgID aMsgID,
       
   686                                                     TAccValueTypeTInt aValue,
       
   687                                                     TInt aErrorCode,
       
   688                                                     TInt aTrId )
       
   689     {
       
   690     COM_TRACE_( "[AccFW:AccServer] CAccSrvConnectionHandler::HandleValueMessageL() - TInt" );
       
   691 
       
   692     HandleValueMessagesL( aMsgID, aValue.iValue, aErrorCode, aTrId );
       
   693 
       
   694     COM_TRACE_( "[AccFW:AccServer] CAccSrvConnectionHandler::HandleValueMessageL - TInt - return void" );
       
   695     }
       
   696 
       
   697 // -----------------------------------------------------------------------------
       
   698 // CAccSrvConnectionHandler::HandleValueMessagesL
       
   699 // -----------------------------------------------------------------------------
       
   700 //
       
   701 void CAccSrvConnectionHandler::HandleValueMessagesL( TMsgID /*aMsgID*/,
       
   702                                                      TInt aValue,
       
   703                                                      TInt aErrorCode,
       
   704                                                      TInt aTrId )
       
   705     {
       
   706     COM_TRACE_1( "[AccFW:AccServer] CAccSrvConnectionHandler::HandleValueMessagesL(value=%d)", aValue );
       
   707     
       
   708     TInt index( FindRequestData( aTrId ) );
       
   709     TAccSrvRequestData requestData;
       
   710     TBool isUpdate( EFalse );
       
   711     
       
   712     if ( KErrNotFound != index )
       
   713         {
       
   714         requestData.iName = iRequestDataArray.operator[]( index ).iName;
       
   715         requestData.iTrId = iRequestDataArray.operator[]( index ).iTrId;
       
   716         requestData.iUpdateNotification = 
       
   717             iRequestDataArray.operator[]( index ).iUpdateNotification;
       
   718 
       
   719         if ( KErrNone == aErrorCode )
       
   720             {
       
   721         
       
   722 	        if ( requestData.iUpdateNotification )
       
   723                 {
       
   724     	    	//ASY response to accessory update command, continue connection process....
       
   725 	        	iState = EInitializeConnection;
       
   726             	IssueRequest();	
       
   727             	isUpdate = ETrue;
       
   728         	    }
       
   729 	        else
       
   730                 {
       
   731         		//Store value to capability storage
       
   732         		TUint32 name;
       
   733     	    	requestData.iName.GetName( name );
       
   734 	        
       
   735             	CCapValue* value = iModel->CapabilityStorage().GetCapability( iGenericID, name );
       
   736         
       
   737     	    	if ( !value)
       
   738 	        	    {
       
   739             		User::Leave( KErrArgument );
       
   740         		    }
       
   741 	        	value->SetValueL( aValue );
       
   742                 }
       
   743             }
       
   744         else
       
   745             {
       
   746             COM_TRACE_1( "[AccFW:AccServer] CAccSrvConnectionHandler::HandleValueMessagesL - Error response received(err=%d)", aErrorCode );    
       
   747             }
       
   748 
       
   749         iRequestDataArray.Remove( index );//Remove this request from iRequestDataArray
       
   750         }
       
   751     else
       
   752         {
       
   753         COM_TRACE_1( "[AccFW:AccServer] CAccSrvConnectionHandler::HandleValueMessagesL - Unidentified response received(TrID=%d)", aTrId );    
       
   754         TRACE_ASSERT_ALWAYS;
       
   755         }
       
   756     
       
   757     if ( 0 == iRequestDataArray.Count() && !isUpdate )
       
   758         {
       
   759         //No more pending requests
       
   760         iCallback->HandleConnectValidationL( iGenericID, this, KErrNone );
       
   761         }
       
   762     else
       
   763         {
       
   764         //Wait next response
       
   765         }
       
   766 
       
   767     COM_TRACE_( "[AccFW:AccServer] CAccSrvConnectionHandler::HandleValueMessagesL - return void " );
       
   768     }            
       
   769 
       
   770 // -----------------------------------------------------------------------------
       
   771 // CAccSrvConnectionHandler::HandleValueMessageL (From MQueueObserver)
       
   772 //
       
   773 // Resolve the Generic ID according to the profile information
       
   774 // received from BT-ASY.
       
   775 //
       
   776 // TASYBTAccInfo type is only supported object in aValue. Its assumed that ASY
       
   777 // uses package buffer to make type safe transfer for that object i.e.
       
   778 //      TASYBTAccInfo btInfo
       
   779 //      TASYBTAccInfoPckgC btInfoPckgC( btInfo )
       
   780 // -----------------------------------------------------------------------------
       
   781 //
       
   782 void CAccSrvConnectionHandler::HandleValueMessageL( TMsgID /*aMsgID*/,
       
   783                                                     TDesC8& aValue,
       
   784                                                     TInt aErrorCode,
       
   785                                                     TInt aTrId )
       
   786     {
       
   787     COM_TRACE_1( "[AccFW:AccServer] CAccSrvConnectionHandler::HandleValueMessageL(err=%d) - TDesC8", aErrorCode );
       
   788 
       
   789     TInt index( FindRequestData( aTrId ) );
       
   790     
       
   791     if ( KErrNotFound != index)
       
   792         {
       
   793         iRequestDataArray.Remove( index );//Remove this request from iRequestDataArray
       
   794         //RequestData was not used in this case
       
   795         }
       
   796     else
       
   797         {
       
   798         TRACE_ASSERT_ALWAYS;//iRequestDataArray is out of sync
       
   799         }
       
   800         
       
   801     if ( KErrNone == aErrorCode )
       
   802         {
       
   803         ResolveGenericIDL( aValue );    
       
   804         } 
       
   805 
       
   806     if ( 0 == iRequestDataArray.Count() )
       
   807         {
       
   808         //No more pending requests
       
   809         iCallback->HandleConnectValidationL( iGenericID, this, aErrorCode );
       
   810         }
       
   811     else
       
   812         {
       
   813         //Wait next response
       
   814         }
       
   815 
       
   816     COM_TRACE_( "[AccFW:AccServer] CAccSrvConnectionHandler::HandleValueMessageL - TDesC8 - return void" );
       
   817     }
       
   818 
       
   819 // -----------------------------------------------------------------------------
       
   820 // CAccSrvConnectionHandler::HandleValueMessagesL
       
   821 // -----------------------------------------------------------------------------
       
   822 //
       
   823 void CAccSrvConnectionHandler::HandleValueMessageL( TMsgID /*aMsgID*/,
       
   824                                                     TInt /*aTrId*/,
       
   825                                                     TPtr8* /*aPtrBuf*/,
       
   826                                                     TInt /*aErrorCode*/ )
       
   827     {
       
   828     User::Leave( KErrNotSupported );
       
   829     }                              
       
   830                                    
       
   831 // -----------------------------------------------------------------------------
       
   832 // CAccSrvConnectionHandler::ResolveGenericIDL
       
   833 //
       
   834 // Fill Generic ID according supported profiles received from BT-ASY.
       
   835 // -----------------------------------------------------------------------------
       
   836 //
       
   837 void CAccSrvConnectionHandler::ResolveGenericIDL( TDesC8& aValue )
       
   838     {
       
   839     COM_TRACE_( "[AccFW:AccServer] CAccSrvConnectionHandler::ResolveGenericIDL()" );
       
   840 
       
   841     TPckg<TASYBTAccInfo>    btInfoPckg( *static_cast<TPckg<TASYBTAccInfo> *>( &aValue ) );
       
   842 
       
   843     COM_TRACE_3( "[AccFW:AccServer] CAccSrvConnectionHandler::ResolveGenericIDL - model=%d type=%d prof=%d", btInfoPckg().iDeviceInfo, btInfoPckg().iDeviceType, btInfoPckg().iProfiles );
       
   844     COM_TRACE_4( "[AccFW:AccServer] CAccSrvConnectionHandler::ResolveGenericIDL - HSP=%d HFP=%d AVRCP=%d A2DP=%d", btInfoPckg().iSupportedFeatures[0], btInfoPckg().iSupportedFeatures[1], btInfoPckg().iSupportedFeatures[2], btInfoPckg().iSupportedFeatures[3]);
       
   845 
       
   846     TAccPolGenericIDAccessor::SetHWDeviceID( iGenericID, 
       
   847                                              btInfoPckg().iDeviceInfo );
       
   848     TAccPolGenericIDAccessor::SetFeatureAttributeL( iGenericID,
       
   849                                                     KAccPolDTDeviceType,
       
   850                                                     btInfoPckg().iDeviceType );
       
   851             
       
   852     if ( btInfoPckg().iReserved & KAccInfoDRM )
       
   853         {
       
   854         //If accessory have recording possibility, KAccNoDRMOutput capability is set.
       
   855         //i.e. Capturing Major Service Class is indicated by accessory.
       
   856         COM_TRACE_( "[AccFW:AccServer] CAccSrvConnectionHandler::ResolveGenericIDL - DRM output not allowed" );
       
   857         iModel->CapabilityStorage().SetCapabilityL( iGenericID, KAccNoDRMOutput );
       
   858         }
       
   859 
       
   860     if ( btInfoPckg().iReserved & KAccInfoLatency )
       
   861         {
       
   862         //If accessory provides latency information, KAccAudioLatency capability is set.
       
   863         //Initialize capability value as 0. Will be updated via notification.
       
   864         COM_TRACE_( "[AccFW:AccServer] CAccSrvConnectionHandler::ResolveGenericIDL - Latency set" );
       
   865         iModel->CapabilityStorage().SetCapabilityL( iGenericID, KAccAudioLatency, EAPVAccessory, EAPVInt, 0 );
       
   866         }
       
   867 
       
   868     ResolveGidL();
       
   869 
       
   870     // Fill the Audio subblock and Bluetooth subblock
       
   871     if ( KAccInfoHSP & btInfoPckg().iProfiles )//Headset Profile (HSP)
       
   872         {
       
   873         ResolveHSPSpecificGidL( btInfoPckg().iSupportedFeatures.At( EAccInfoHSPIndex ) );
       
   874         }
       
   875 
       
   876     if ( KAccInfoHFP & btInfoPckg().iProfiles )//Handsfree Profile (HFP)
       
   877         {
       
   878         ResolveHFPSpecificGidL( btInfoPckg().iSupportedFeatures.At( EAccInfoHFPIndex ) );
       
   879         }
       
   880 
       
   881     if ( KAccInfoAVRCP & btInfoPckg().iProfiles )//Audio Video Remote Control Profile (AVRCP)
       
   882         {
       
   883         ResolveAVRCPSpecificGidL( btInfoPckg().iSupportedFeatures.At( EAccInfoAVRCPIndex ) );
       
   884         }
       
   885 
       
   886     if ( KAccInfoA2DP & btInfoPckg().iProfiles )//Advanced Audio Distribution Profile (A2DP)
       
   887         {
       
   888         ResolveA2DPSpecificGidL( btInfoPckg().iSupportedFeatures.At( EAccInfoA2DPIndex ) );
       
   889         }
       
   890 
       
   891     //Update GenericID to CapabilityStorage 
       
   892     iModel->CapabilityStorage().SetGenericIDHeaderL( 
       
   893         *( reinterpret_cast<TAccPolGIDHeader*>( &iGenericID ) ) );
       
   894     
       
   895     COM_TRACE_( "[AccFW:AccServer] CAccSrvConnectionHandler::ResolveGenericIDL - return void" );
       
   896     }
       
   897 
       
   898 // -----------------------------------------------------------------------------
       
   899 // CAccSrvConnectionHandler::ResolveGidL
       
   900 // -----------------------------------------------------------------------------
       
   901 //
       
   902 void CAccSrvConnectionHandler::ResolveGidL()
       
   903     {
       
   904     COM_TRACE_( "[AccFW:AccServer] CAccSrvConnectionHandler::ResolveGidL()" );
       
   905     TInt value;
       
   906 
       
   907     //Set Audio Output Type capability. For CarKits its public, otherwise private.
       
   908     if ( iGenericID.DeviceTypeCaps( KDTCarKit ) )
       
   909         {
       
   910         value = EAccAudioOutPutTypePublic;
       
   911         }
       
   912     else
       
   913         {
       
   914         value = EAccAudioOutPutTypePrivate;
       
   915         }
       
   916 
       
   917     //Set KAccAudioOutputType capability 
       
   918 	iModel->CapabilityStorage().SetCapabilityL( 
       
   919         iGenericID, KAccAudioOutputType, EAPVPolicy, EAPVInt, value );
       
   920 	
       
   921 	//Set KAccSetVolumeLevel capability with zero value.
       
   922 	//Real values are filled according to supported features.
       
   923 	iModel->CapabilityStorage().SetCapabilityL( 
       
   924         iGenericID, KAccSetVolumeLevel, EAPVPolicy, EAPVInt, 0 );
       
   925 	
       
   926 	//Set KSBAudioSubblock capability group
       
   927 	TAccPolGenericIDAccessor::SetFeatureAttributeL( iGenericID, 
       
   928 	                                                KAccPolSBCapabilities, 
       
   929 	                                                iGenericID.SubblockCaps() | 
       
   930                                                   KSBAudioSubblock );
       
   931 	
       
   932     COM_TRACE_( "[AccFW:AccServer] CAccSrvConnectionHandler::ResolveGidL - return void" );
       
   933     }
       
   934 
       
   935 // -----------------------------------------------------------------------------
       
   936 // CAccSrvConnectionHandler::ResolveHSPSpecificGidL
       
   937 //
       
   938 // HEADSET PROFILE 1.1 / supported features:
       
   939 //   Remote audio volume control
       
   940 //     -Boolean
       
   941 //     -Optional
       
   942 //     -Default=False
       
   943 // -----------------------------------------------------------------------------
       
   944 //
       
   945 void CAccSrvConnectionHandler::ResolveHSPSpecificGidL( TUint16 aSupportedFeatures )
       
   946     {
       
   947     COM_TRACE_( "[AccFW:AccServer] CAccSrvConnectionHandler::ResolveHSPSpecificGidL()" );
       
   948 
       
   949     /******************
       
   950      * Audio subblock *
       
   951      ******************/
       
   952     //following capabilities are fixed (because of Headset profile is supported)
       
   953    	iModel->CapabilityStorage().SetCapabilityL( iGenericID, KAccMonoAudio );
       
   954     iModel->CapabilityStorage().SetCapabilityL( iGenericID,	KAccIntegratedAudioInput );//i.e. all HSP accessories has microphone
       
   955     
       
   956     if ( aSupportedFeatures )
       
   957         {
       
   958         //Remote audio volume control is supported.
       
   959         UpdateSetVolumeLevelCapabilityL( KAccSetVolumeLevelHSP );
       
   960         }
       
   961     
       
   962     //KSBAudioSubblock capability group is allready set in CAccSrvConnectionHandler::ResolveGidL()
       
   963     
       
   964     /**********************
       
   965      * Bluetooth subblock *
       
   966      **********************/
       
   967     //Set KAccBTHSP capability and KSBBluetoothSubblock capability group
       
   968    	iModel->CapabilityStorage().SetCapabilityL( iGenericID, KAccBTHSP);
       
   969    	TAccPolGenericIDAccessor::SetFeatureAttributeL( iGenericID, 
       
   970 	                                                  KAccPolSBCapabilities, 
       
   971 	                                                  iGenericID.SubblockCaps() | 
       
   972                                                     KSBBluetoothSubblock );
       
   973 
       
   974     COM_TRACE_( "[AccFW:AccServer] CAccSrvConnectionHandler::ResolveHSPSpecificGidL - return void" );
       
   975     }
       
   976 
       
   977 // -----------------------------------------------------------------------------
       
   978 // CAccSrvConnectionHandler::ResolveHFPSpecificGidL
       
   979 //
       
   980 // Accessory device type is resolved according to this table:
       
   981 // Profile supported          Accessory type
       
   982 // -----------------          --------------
       
   983 // both headset and handsfree headset
       
   984 // headset                    headset
       
   985 // handsfree                  carkit
       
   986 //
       
   987 // Hands-Free Profile 1.0 / supported features bitmap:
       
   988 // 000000
       
   989 // ^^^^^^
       
   990 // ||||||
       
   991 // ||||||--Bit 0----- EC and/or NR function
       
   992 // |||||---Bit 1----- Call waiting and 3-way calling
       
   993 // ||||----Bit 2----- CLI presentation capability
       
   994 // |||-----Bit 3----- Voice recognition activation
       
   995 // ||------Bit 4----- Remote volume control
       
   996 // |-------Bit 5-31-- Unused (available for PAP and other extensibility)
       
   997 // -----------------------------------------------------------------------------
       
   998 //
       
   999 void CAccSrvConnectionHandler::ResolveHFPSpecificGidL( TUint16 aSupportedFeatures )
       
  1000     {
       
  1001     COM_TRACE_( "[AccFW:AccServer] CAccBTConnectionHandler::ResolveHFPSpecificGidL()" );
       
  1002 
       
  1003     /******************
       
  1004      * Audio subblock *
       
  1005      ******************/
       
  1006     // The default value for supported features of a HF device according to the
       
  1007     // HF profile specification is 0.
       
  1008     if ( aSupportedFeatures & 0x1 )//Bit 0 -> EC and/or NR function
       
  1009         {
       
  1010 		iModel->CapabilityStorage().SetCapabilityL( iGenericID, 
       
  1011 		                                            KAccAcousticEchoControl, 
       
  1012 		                                            EAPVAccessory, 
       
  1013 		                                            EAPVBool, 
       
  1014 		                                            EFalse  );
       
  1015 		iModel->CapabilityStorage().SetCapabilityL( iGenericID, 
       
  1016 		                                            KAccNoiseReduction,
       
  1017 		                                            EAPVAccessory,
       
  1018 		                                            EAPVBool,
       
  1019 		                                            EFalse  );
       
  1020         }
       
  1021 
       
  1022 
       
  1023     if ( aSupportedFeatures & 0x8 )//Bit 3 -> Voice recognition
       
  1024        {
       
  1025        iModel->CapabilityStorage().SetCapabilityL( iGenericID, 
       
  1026                                                    KAccBTVoiceRecognition );       
       
  1027        COM_TRACE_( "[AccFW:AccServer] CAccSrvConnectionHandler::ResolveHFPSpecificGidL - KAccVoiceRecognition supported." );                                                   
       
  1028        }
       
  1029     else
       
  1030        {
       
  1031     	 COM_TRACE_( "[AccFW:AccServer] CAccSrvConnectionHandler::ResolveHFPSpecificGidL - KAccVoiceRecognition not supported." );                                                   
       
  1032        }
       
  1033     
       
  1034 
       
  1035     if ( aSupportedFeatures & 0x10 )//Bit 4 -> Remote volume control
       
  1036         {
       
  1037         //Remote audio volume control is supported.
       
  1038         UpdateSetVolumeLevelCapabilityL( KAccSetVolumeLevelHFP );
       
  1039         }
       
  1040         
       
  1041     //following capabilities are fixed (because of Handsfree profile is supported)
       
  1042 	iModel->CapabilityStorage().SetCapabilityL( iGenericID, KAccMonoAudio );
       
  1043 	iModel->CapabilityStorage().SetCapabilityL( iGenericID,	KAccIntegratedAudioInput );//i.e. all HFP accessories has microphone
       
  1044 	
       
  1045 	//KSBAudioSubblock capability group is allready set in CAccSrvConnectionHandler::ResolveGidL()
       
  1046 	
       
  1047     /**********************
       
  1048      * Bluetooth subblock *
       
  1049      **********************/
       
  1050     //Set KAccBTHSP capability and KSBBluetoothSubblock capability group
       
  1051 	iModel->CapabilityStorage().SetCapabilityL( iGenericID, KAccBTHFP );
       
  1052 	TAccPolGenericIDAccessor::SetFeatureAttributeL( iGenericID, 
       
  1053 	                                                KAccPolSBCapabilities, 
       
  1054 	                                                iGenericID.SubblockCaps() | 
       
  1055                                                   KSBBluetoothSubblock );
       
  1056 
       
  1057     COM_TRACE_( "[AccFW:AccServer] CAccSrvConnectionHandler::ResolveHFPSpecificGidL - return void" );
       
  1058     }
       
  1059 
       
  1060 // -----------------------------------------------------------------------------
       
  1061 // CAccSrvConnectionHandler::ResolveAVRCPSpecificGidL
       
  1062 //
       
  1063 // AUDIO/VIDEO REMOTE CONTROL PROFILE 1.0 / supported features bitmap:
       
  1064 // AVRCP
       
  1065 // Service Record for TG (Accessory is TG)
       
  1066 //        Bit 0 = Category 1
       
  1067 //        Bit 1 = Category 2
       
  1068 //        Bit 2 = Category 3
       
  1069 //        Bit 3 = Category 4
       
  1070 //        Bit 4-15 = Reserved for Future Additions
       
  1071 //
       
  1072 // Service Record for CT
       
  1073 //        Bit 0 = Category 1
       
  1074 //        Bit 1 = Category 2
       
  1075 //        Bit 2 = Category 3
       
  1076 //        Bit 3 = Category 4
       
  1077 //        Bit 4-15 = Reserved for Future Additions
       
  1078 // -----------------------------------------------------------------------------
       
  1079 //
       
  1080 void CAccSrvConnectionHandler::ResolveAVRCPSpecificGidL(
       
  1081     TUint16 /*aSupportedFeatures*/ )
       
  1082     {
       
  1083     COM_TRACE_( "[AccFW:AccServer] CAccSrvConnectionHandler::ResolveAVRCPSpecificGidL()" );
       
  1084 
       
  1085     /******************
       
  1086      * Audio subblock *
       
  1087      ******************/
       
  1088     //AVRCP doesn't support remote audio volume control.
       
  1089 
       
  1090     /**********************
       
  1091      * Bluetooth subblock *
       
  1092      **********************/
       
  1093     //Set KAccBTAVRCP capability and KSBBluetoothSubblock capability group
       
  1094     iModel->CapabilityStorage().SetCapabilityL( iGenericID, KAccBTAVRCP );
       
  1095    	TAccPolGenericIDAccessor::SetFeatureAttributeL( iGenericID, 
       
  1096 	                                                  KAccPolSBCapabilities, 
       
  1097 	                                                  iGenericID.SubblockCaps() | 
       
  1098                                                     KSBBluetoothSubblock );
       
  1099 
       
  1100     COM_TRACE_( "[AccFW:AccServer] CAccSrvConnectionHandler::ResolveAVRCPSpecificGidL - return void" );
       
  1101     }
       
  1102 
       
  1103 // -----------------------------------------------------------------------------
       
  1104 // CAccSrvConnectionHandler::ResolveA2DPSpecificGidL
       
  1105 //
       
  1106 // ADVANCED AUDIO DISTRIBUTION PROFILE SPECIFICATION 1.0 / supported features bitmap:
       
  1107 // A2DP
       
  1108 //
       
  1109 // Service Record for Sink (Accessory is sink)
       
  1110 //        Bit 0 = Headphone
       
  1111 //        Bit 1 = Speaker
       
  1112 //        Bit 2 = Recorder
       
  1113 //        Bit 3 = Amplifier
       
  1114 //        Bit 4-15 = Reserved for Future Additions
       
  1115 //
       
  1116 // Service Record for Source
       
  1117 //        Bit 0 = Player
       
  1118 //        Bit 1 = Microphone
       
  1119 //        Bit 2 = Tuner
       
  1120 //        Bit 3 = Mixer
       
  1121 //        Bit 4-15 = Reserved for Future Additions
       
  1122 // -----------------------------------------------------------------------------
       
  1123 //
       
  1124 void CAccSrvConnectionHandler::ResolveA2DPSpecificGidL( TUint16 /*aSupportedFeatures*/ )
       
  1125     {
       
  1126     COM_TRACE_( "[AccFW:AccServer] CAccSrvConnectionHandler::ResolveA2DPSpecificGidL()" );
       
  1127 
       
  1128     /******************
       
  1129      * Audio subblock *
       
  1130      ******************/
       
  1131     iModel->CapabilityStorage().SetCapabilityL( iGenericID, KAccStereoAudio );
       
  1132     //KSBAudioSubblock capability group is allready set in CAccSrvConnectionHandler::ResolveGidL()
       
  1133      
       
  1134     /**********************
       
  1135      * Bluetooth subblock *
       
  1136      **********************/
       
  1137     //Set KAccBTA2DP capability and KSBBluetoothSubblock capability group
       
  1138     iModel->CapabilityStorage().SetCapabilityL( iGenericID, KAccBTA2DP );
       
  1139    	TAccPolGenericIDAccessor::SetFeatureAttributeL( iGenericID, 
       
  1140 	                                                  KAccPolSBCapabilities, 
       
  1141 	                                                  iGenericID.SubblockCaps() | 
       
  1142                                                     KSBBluetoothSubblock );
       
  1143 
       
  1144     COM_TRACE_( "[AccFW:AccServer] CAccSrvConnectionHandler::ResolveA2DPSpecificGidL - return void" );
       
  1145     }
       
  1146 
       
  1147 // -----------------------------------------------------------------------------
       
  1148 // CAccSrvConnectionHandler::UpdateSetVolumeLevelCapabilityL
       
  1149 //
       
  1150 // Read the existing KAccSetVolumeLevel capability value and update it
       
  1151 // according to the aCapability parameter.
       
  1152 // -----------------------------------------------------------------------------
       
  1153 //
       
  1154 void CAccSrvConnectionHandler::UpdateSetVolumeLevelCapabilityL( TInt32 aCapability )
       
  1155     {
       
  1156     COM_TRACE_1( "[AccFW:AccServer] CAccSrvConnectionHandler::UpdateSetVolumeLevelCapabilityL(%d)", aCapability ); 
       
  1157                
       
  1158     CCapValue* capValue = iModel->CapabilityStorage().GetCapability( 
       
  1159                                                         iGenericID, KAccSetVolumeLevel );
       
  1160     
       
  1161     if ( capValue )
       
  1162         {    
       
  1163         TInt32 currentValue( 0 );
       
  1164         if( KErrNone == capValue->ValueInt( currentValue ) )
       
  1165             {
       
  1166             currentValue = currentValue | aCapability;
       
  1167             iModel->CapabilityStorage().SetCapabilityL( 
       
  1168                                             iGenericID, 
       
  1169                                             KAccSetVolumeLevel,
       
  1170                                             EAPVPolicy, 
       
  1171                                             EAPVInt, 
       
  1172                                             currentValue );            
       
  1173             }
       
  1174         }
       
  1175             
       
  1176     COM_TRACE_( "[AccFW:AccServer] CAccSrvConnectionHandler::UpdateSetVolumeLevelCapabilityL - return void" );
       
  1177     }
       
  1178     
       
  1179 // -----------------------------------------------------------------------------
       
  1180 // CAccSrvConnectionHandler::RunError
       
  1181 //
       
  1182 // Called if RunL Leaves
       
  1183 // -----------------------------------------------------------------------------
       
  1184 //
       
  1185 TInt CAccSrvConnectionHandler::RunError( TInt aError )
       
  1186     {
       
  1187     COM_TRACE_1( "[AccFW:AccServer] CAccSrvConnectionHandler::RunError(%d)", aError );
       
  1188     
       
  1189     aError = KErrNone;// Avoid Panic in CActiveScheduler
       
  1190 
       
  1191     COM_TRACE_( "[AccFW:AccServer] CAccSrvConnectionHandler::RunError - return KErrNone" );
       
  1192 
       
  1193     return aError;
       
  1194     }
       
  1195 
       
  1196 // -----------------------------------------------------------------------------
       
  1197 // CAccSrvConnectionHandler::CompleteMessageL (From MQueueObserver)
       
  1198 // -----------------------------------------------------------------------------
       
  1199 //
       
  1200 TBool CAccSrvConnectionHandler::CompleteMessageL( TMsgID /*aMsgID*/,
       
  1201                                                   TInt /*aErrorCode*/,
       
  1202                                                   TInt /*aUniqueID*/ )
       
  1203     {
       
  1204     //Not used, must define it here because pure virtual in base class (MQueueObserver)
       
  1205     TRACE_ASSERT_ALWAYS;
       
  1206     return EFalse;
       
  1207     }
       
  1208     
       
  1209 // -----------------------------------------------------------------------------
       
  1210 //CAccSrvConnectionHandler::CompleteProcessCommandL
       
  1211 // -----------------------------------------------------------------------------
       
  1212 //
       
  1213 TBool CAccSrvConnectionHandler::CompleteProcessCommandL( 
       
  1214     TProcessCmdId /*aCmdn*/,
       
  1215     TInt /*aTrId*/,
       
  1216     TASYCommandParamRecord& /*aASYCommandParamRecord*/,
       
  1217     TPtr8* /*aPtrBuf*/ )
       
  1218     {
       
  1219     //Not used, must define it here because pure virtual in base class (MQueueObserver)
       
  1220     TRACE_ASSERT_ALWAYS;
       
  1221     return EFalse;
       
  1222     }
       
  1223 // End of File