bthci/hci2implementations/hctls/usb_original/hctl/src/devicestatemanager.cpp
changeset 27 83036355c0f3
equal deleted inserted replaced
4:28479eeba3fb 27:83036355c0f3
       
     1 // Copyright (c) 2007-2010 Nokia Corporation and/or its subsidiary(-ies).
       
     2 // All rights reserved.
       
     3 // This component and the accompanying materials are made available
       
     4 // under the terms of "Eclipse Public License v1.0"
       
     5 // which accompanies this distribution, and is available
       
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     7 //
       
     8 // Initial Contributors:
       
     9 // Nokia Corporation - initial contribution.
       
    10 //
       
    11 // Contributors:
       
    12 //
       
    13 // Description:
       
    14 // 
       
    15 
       
    16 #include "devicestatemanager.h"
       
    17 
       
    18 #include <d32usbdi.h>
       
    19 
       
    20 #include <bluetooth/logger.h>
       
    21 
       
    22 #ifdef __FLOG_ACTIVE
       
    23 _LIT8(KLogComponent, LOG_COMPONENT_HCTL_USB_ORIGINAL);
       
    24 #endif
       
    25 
       
    26 CDeviceStateManager* CDeviceStateManager::NewL(RUsbInterface& aAclInterface, RUsbInterface& aScoInterface)
       
    27 	{
       
    28 	LOG_STATIC_FUNC
       
    29 	CDeviceStateManager* self = new(ELeave) CDeviceStateManager;
       
    30 	CleanupStack::PushL(self);
       
    31 	self->ConstructL(aAclInterface, aScoInterface);
       
    32 	CleanupStack::Pop(self);
       
    33 	return self;
       
    34 	}
       
    35 
       
    36 CDeviceStateManager::~CDeviceStateManager()
       
    37 	{
       
    38 	LOG_FUNC
       
    39 	delete iScoManager;
       
    40 	delete iAclManager;
       
    41 	}
       
    42 
       
    43 void CDeviceStateManager::Suspend()
       
    44 	{
       
    45 	LOG_FUNC
       
    46 	iAclManager->Suspend();
       
    47 	iScoManager->Suspend();
       
    48 	}
       
    49 
       
    50 void CDeviceStateManager::Resume()
       
    51 	{
       
    52 	LOG_FUNC
       
    53 	iAclManager->Resume();
       
    54 	iScoManager->Resume();
       
    55 	}
       
    56 
       
    57 CDeviceStateManager::CDeviceStateManager()
       
    58 	{
       
    59 	LOG_FUNC
       
    60 	}
       
    61 
       
    62 void CDeviceStateManager::ConstructL(RUsbInterface& aAclInterface, RUsbInterface& aScoInterface)
       
    63 	{
       
    64 	LOG_FUNC
       
    65 	iAclManager = CInterfaceStateManager::NewL(aAclInterface);
       
    66 	iScoManager = CInterfaceStateManager::NewL(aScoInterface);
       
    67 	}
       
    68 	
       
    69 
       
    70 
       
    71 CInterfaceStateManager* CInterfaceStateManager::NewL(RUsbInterface& aInterface)
       
    72 	{
       
    73 	LOG_STATIC_FUNC
       
    74 	return new(ELeave) CInterfaceStateManager(aInterface);
       
    75 	}
       
    76 
       
    77 CInterfaceStateManager::~CInterfaceStateManager()
       
    78 	{
       
    79 	LOG_FUNC
       
    80 	Cancel();
       
    81 	}
       
    82 
       
    83 CInterfaceStateManager::CInterfaceStateManager(RUsbInterface& aInterface)
       
    84 	: CActive(EPriorityStandard)
       
    85 	, iInterface(aInterface)
       
    86 	{
       
    87 	LOG_FUNC
       
    88 	CActiveScheduler::Add(this);
       
    89 	}
       
    90 
       
    91 void CInterfaceStateManager::DoCancel()
       
    92 	{
       
    93 	LOG_FUNC
       
    94 	iInterface.CancelPermitSuspend();
       
    95 	}
       
    96 
       
    97 void CInterfaceStateManager::RunL()
       
    98 	{
       
    99 	LOG_FUNC
       
   100 	if(iStatus.Int() == KErrNone)
       
   101 		{
       
   102 		RequestSuspend();
       
   103 		}
       
   104 	// Ignore error - we'll try again on the next explict resume
       
   105 	}
       
   106 
       
   107 void CInterfaceStateManager::RequestSuspend()
       
   108 	{
       
   109 	iInterface.PermitSuspendAndWaitForResume(iStatus);
       
   110 	SetActive();
       
   111 	}
       
   112 
       
   113 void CInterfaceStateManager::Suspend()
       
   114 	{
       
   115 	LOG_FUNC
       
   116 	if(!IsActive()) // Only suspend if we aren't already suspended.
       
   117 		{
       
   118 		RequestSuspend();
       
   119 		}
       
   120 	}
       
   121 
       
   122 void CInterfaceStateManager::Resume()
       
   123 	{
       
   124 	LOG_FUNC
       
   125 	Cancel();
       
   126 	}
       
   127 
       
   128