|
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 /** |
|
17 @file |
|
18 @internalComponent |
|
19 */ |
|
20 |
|
21 #include "controllermanager.h" |
|
22 |
|
23 #include <bluetooth/hci/controllerstateobserver.h> |
|
24 #include <bluetooth/hci/hctlchannelobserver.h> |
|
25 |
|
26 #include "hctlusboriginal.h" |
|
27 #include "hctlusboriginalutils.h" |
|
28 |
|
29 #include <bluetooth/logger.h> |
|
30 |
|
31 #ifdef __FLOG_ACTIVE |
|
32 _LIT8(KLogComponent, LOG_COMPONENT_HCTL_USB_ORIGINAL); |
|
33 #endif |
|
34 |
|
35 |
|
36 CControllerManager* CControllerManager::NewL(CHCTLUsbOriginal& aHctl) |
|
37 { |
|
38 LOG_STATIC_FUNC |
|
39 CControllerManager* self = new(ELeave) CControllerManager(aHctl); |
|
40 return self; |
|
41 } |
|
42 |
|
43 CControllerManager::CControllerManager(CHCTLUsbOriginal& aHctl) |
|
44 : iHctl(aHctl) |
|
45 { |
|
46 LOG_FUNC |
|
47 } |
|
48 |
|
49 CControllerManager::~CControllerManager() |
|
50 { |
|
51 LOG_FUNC |
|
52 } |
|
53 |
|
54 TInt CControllerManager::MhpiGetPower(TBTPowerState& aState) |
|
55 { |
|
56 LOG_FUNC |
|
57 |
|
58 __ASSERT_DEBUG(iHctl.CurrentPowerState() == EBTOff || iHctl.DevicePresent(), |
|
59 PANIC(KUsbOriginalPanic, EStackOnWhenNoDeviceConnected)); |
|
60 |
|
61 // Return current state. |
|
62 aState = iHctl.CurrentPowerState(); |
|
63 return KErrNone; |
|
64 } |
|
65 |
|
66 TInt CControllerManager::MhpiSetPower(TBTPowerState aState) |
|
67 { |
|
68 LOG_FUNC |
|
69 |
|
70 TInt rerr = KErrAlreadyExists; |
|
71 // Check that the requested state differs from the current state. |
|
72 if(aState != iHctl.CurrentPowerState()) |
|
73 { |
|
74 __ASSERT_ALWAYS(aState == EBTOff || aState == EBTOn, |
|
75 PANIC(KUsbOriginalPanic, EUnexpectedCtrlMgrPowerState)); |
|
76 __ASSERT_ALWAYS(iControllerStateObserver, |
|
77 PANIC(KUsbOriginalPanic, EStateObserverNotAvailable)); |
|
78 |
|
79 rerr = KErrNotReady; |
|
80 if(aState == EBTOff || iHctl.DevicePresent()) |
|
81 { |
|
82 iControllerStateObserver->McsoProcessPowerChange(KErrNone, |
|
83 MControllerStateObserver::EBTFatalChange, |
|
84 aState); |
|
85 |
|
86 if(aState == EBTOff) |
|
87 { |
|
88 // Cancel any reads / writes. |
|
89 iHctl.HandlePowerOff(); |
|
90 } |
|
91 else |
|
92 { |
|
93 // Re-start the sender and receiver. |
|
94 iHctl.HandlePowerOn(); |
|
95 } |
|
96 |
|
97 rerr = KErrNone; |
|
98 } |
|
99 } |
|
100 |
|
101 return rerr; |
|
102 } |
|
103 |
|
104 void CControllerManager::HardReset() |
|
105 { |
|
106 LOG_FUNC |
|
107 |
|
108 // Check if the power is currently switched off. This takes priority over |
|
109 // hard reset. |
|
110 if(iHctl.CurrentPowerState() == EBTOn) |
|
111 { |
|
112 __ASSERT_ALWAYS(iControllerStateObserver, |
|
113 PANIC(KUsbOriginalPanic, EStateObserverNotAvailable)); |
|
114 __ASSERT_DEBUG(iHctl.DevicePresent(), |
|
115 PANIC(KUsbOriginalPanic, EStackOnWhenNoDeviceConnected)); |
|
116 |
|
117 // Switch the power off then on to perform the reset. |
|
118 iControllerStateObserver->McsoProcessHardResetPhaseChange(KErrNone, MControllerStateObserver::EBTFatalChange, EBTResetStarted); |
|
119 |
|
120 iHctl.HandlePowerOff(); |
|
121 // TODO should there be an asynchronous break here, or are we good? |
|
122 iHctl.HandlePowerOn(); |
|
123 |
|
124 // Reset is complete. |
|
125 iControllerStateObserver->McsoProcessHardResetPhaseChange(KErrNone, MControllerStateObserver::EBTFatalChange, EBTResetComplete); |
|
126 } |
|
127 } |
|
128 |
|
129 void CControllerManager::SetControllerStateObserver(MControllerStateObserver& aControllerStateObserver) |
|
130 { |
|
131 LOG_FUNC |
|
132 iControllerStateObserver = &aControllerStateObserver; |
|
133 } |