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