|
1 /* |
|
2 * Copyright (c) 2004-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 the License "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: |
|
15 * Class definition for Device State Notifier Base Class |
|
16 * |
|
17 */ |
|
18 |
|
19 |
|
20 /** |
|
21 @file |
|
22 @internalTechnology |
|
23 */ |
|
24 |
|
25 #include <e32base.h> |
|
26 |
|
27 #include "cactivedevicestatenotifierbase.h" |
|
28 |
|
29 CActiveDeviceStateNotifierBase::CActiveDeviceStateNotifierBase(CBulkOnlyTransport& aBot, |
|
30 MLddDeviceStateNotification& aLddDeviceStateNotification) |
|
31 /** |
|
32 * |
|
33 */ |
|
34 : CActive(EPriorityStandard), |
|
35 iBot(aBot), |
|
36 iLddDeviceStateNotification(aLddDeviceStateNotification), |
|
37 iDeviceState(EUsbcNoState), |
|
38 iOldDeviceState(EUsbcNoState) |
|
39 { |
|
40 |
|
41 } |
|
42 |
|
43 |
|
44 CActiveDeviceStateNotifierBase* CActiveDeviceStateNotifierBase::NewL(CBulkOnlyTransport& aBot, |
|
45 MLddDeviceStateNotification& aLddDeviceStateNotification) |
|
46 /** |
|
47 * |
|
48 */ |
|
49 { |
|
50 CActiveDeviceStateNotifierBase* self = new (ELeave) CActiveDeviceStateNotifierBase(aBot, aLddDeviceStateNotification); |
|
51 CleanupStack::PushL(self); |
|
52 self->ConstructL(); |
|
53 CActiveScheduler::Add(self); |
|
54 CleanupStack::Pop(); // self |
|
55 return (self); |
|
56 } |
|
57 |
|
58 |
|
59 void CActiveDeviceStateNotifierBase::ConstructL() |
|
60 /** |
|
61 * |
|
62 */ |
|
63 { |
|
64 __FNLOG("CActiveDeviceStateNotifierBase::ConstructL"); |
|
65 } |
|
66 |
|
67 |
|
68 CActiveDeviceStateNotifierBase::~CActiveDeviceStateNotifierBase() |
|
69 /** |
|
70 * |
|
71 */ |
|
72 { |
|
73 __PRINT(_L("CActiveDeviceStateNotifierBase::~CActiveDeviceStateNotifierBase()")); |
|
74 Cancel(); // base class |
|
75 } |
|
76 |
|
77 |
|
78 void CActiveDeviceStateNotifierBase::DoCancel() |
|
79 /** |
|
80 * |
|
81 */ |
|
82 { |
|
83 __PRINT(_L("CActiveDeviceStateNotifierBase::DoCancel()")); |
|
84 iLddDeviceStateNotification.Cancel(); |
|
85 } |
|
86 |
|
87 |
|
88 void CActiveDeviceStateNotifierBase::RunL() |
|
89 /** |
|
90 * |
|
91 */ |
|
92 { |
|
93 __FNLOG("CActiveDeviceStateNotifierBase::RunL"); |
|
94 // This displays the device state. |
|
95 // In a real world program, the user could take here appropriate action (cancel a |
|
96 // transfer request or whatever). |
|
97 __PRINT1(_L("DeviceState Notification = %d"), iDeviceState); |
|
98 |
|
99 if (!(iDeviceState & KUsbAlternateSetting)) |
|
100 { |
|
101 switch (iDeviceState) |
|
102 { |
|
103 case EUsbcDeviceStateUndefined: //0 |
|
104 case EUsbcDeviceStateDefault: //3 |
|
105 iBot.HwStop(); |
|
106 break; |
|
107 |
|
108 case EUsbcDeviceStateAttached: //1 |
|
109 case EUsbcDeviceStatePowered: //2 |
|
110 // do nothing |
|
111 break; |
|
112 |
|
113 case EUsbcDeviceStateAddress: //4 |
|
114 if (iOldDeviceState == EUsbcDeviceStateConfigured) |
|
115 { |
|
116 iBot.StopBulkOnlyEndpoint(); |
|
117 } |
|
118 break; |
|
119 |
|
120 case EUsbcDeviceStateConfigured: //5 |
|
121 if (iOldDeviceState == EUsbcDeviceStateSuspended) |
|
122 { |
|
123 iBot.HwResume(); |
|
124 } |
|
125 else |
|
126 { |
|
127 iBot.HwStart(); |
|
128 } |
|
129 break; |
|
130 case EUsbcDeviceStateSuspended: //6 |
|
131 if (iOldDeviceState == EUsbcDeviceStateConfigured) |
|
132 { |
|
133 iBot.HwSuspend(); |
|
134 } |
|
135 break; |
|
136 default: |
|
137 __PRINT(_L("Device State notifier: ***BAD***\n")); |
|
138 iBot.HwStop(); |
|
139 break; |
|
140 } |
|
141 iOldDeviceState = iDeviceState; |
|
142 } |
|
143 else if (iDeviceState & KUsbAlternateSetting) |
|
144 { |
|
145 __PRINT1(_L("Device State notifier: Alternate interface setting has changed: now %d\n"), iDeviceState & ~KUsbAlternateSetting); |
|
146 } |
|
147 Activate(); |
|
148 } |
|
149 |
|
150 |
|
151 void CActiveDeviceStateNotifierBase::Activate() |
|
152 /** |
|
153 * |
|
154 */ |
|
155 { |
|
156 __FNLOG("CActiveDeviceStateNotifierBase::Activate"); |
|
157 if (IsActive()) |
|
158 { |
|
159 __PRINT(_L("Still active\n")); |
|
160 return; |
|
161 } |
|
162 iLddDeviceStateNotification.Activate(iStatus, iDeviceState); |
|
163 SetActive(); |
|
164 } |
|
165 |
|
166 |
|
167 |
|
168 |