|
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: |
|
15 * |
|
16 */ |
|
17 |
|
18 /** @file |
|
19 @internalComponent |
|
20 @test |
|
21 */ |
|
22 |
|
23 #include "devicewatcher.h" |
|
24 #include "ncmtestconsole.h" |
|
25 |
|
26 CDeviceWatcher* CDeviceWatcher::NewL(CUsbNcmConsole& aTestConsole) |
|
27 { |
|
28 LOG_STATIC_FUNC_ENTRY |
|
29 |
|
30 CDeviceWatcher* self = new(ELeave) CDeviceWatcher(aTestConsole); |
|
31 CleanupStack::PushL(self); |
|
32 self->ConstructL(); |
|
33 CleanupStack::Pop(self); |
|
34 return self; |
|
35 } |
|
36 CDeviceWatcher::~CDeviceWatcher() |
|
37 { |
|
38 Cancel(); |
|
39 iLdd.Close(); |
|
40 } |
|
41 |
|
42 CDeviceWatcher::CDeviceWatcher(CUsbNcmConsole& aTestConsole) |
|
43 : CActive(EPriorityStandard), iTestConsole(aTestConsole), iWatchMode(EWatchMode) |
|
44 { |
|
45 CActiveScheduler::Add(this); |
|
46 } |
|
47 |
|
48 void CDeviceWatcher::ConstructL() |
|
49 { |
|
50 User::LeaveIfError(iLdd.Open(0)); |
|
51 iLdd.AlternateDeviceStatusNotify(iStatus, iDeviceState); |
|
52 |
|
53 SetActive(); |
|
54 |
|
55 //Get current device state |
|
56 TUsbcDeviceState deviceState; |
|
57 User::LeaveIfError(iLdd.DeviceStatus(deviceState)); |
|
58 |
|
59 DisplayDeviceState(deviceState); |
|
60 |
|
61 } |
|
62 |
|
63 void CDeviceWatcher::DoCancel() |
|
64 { |
|
65 iLdd.AlternateDeviceStatusNotifyCancel(); |
|
66 } |
|
67 |
|
68 void CDeviceWatcher::RunL() |
|
69 { |
|
70 //Get USB device state change |
|
71 iLdd.AlternateDeviceStatusNotify(iStatus, iDeviceState); |
|
72 SetActive(); |
|
73 |
|
74 LOG_FUNC |
|
75 __FLOG_STATIC1(KSubSys, KLogComponent , _L8("CDeviceWatcherCommand::RunL - iStatus = %d"), iStatus.Int()); |
|
76 |
|
77 //Display the current state on main console |
|
78 DisplayDeviceState(iDeviceState); |
|
79 |
|
80 TUsbServiceState serviceState; |
|
81 User::LeaveIfError(iTestConsole.Usb().GetServiceState(serviceState)); |
|
82 |
|
83 __FLOG_STATIC3(KSubSys, KLogComponent , |
|
84 _L8("iDeviceState = %d, serviceState = %d, iStartNcm=%d"), |
|
85 iDeviceState, serviceState, iStartNcm); |
|
86 |
|
87 iOldDeviceState = iDeviceState; |
|
88 } |
|
89 |
|
90 TInt CDeviceWatcher::RunError(TInt aError) |
|
91 { |
|
92 User::Panic(_L("CDeviceWatcher"), aError); |
|
93 return aError; |
|
94 } |
|
95 |
|
96 TDeviceWatchMode CDeviceWatcher::GetWatchMode() const |
|
97 { |
|
98 return iWatchMode; |
|
99 } |
|
100 |
|
101 void CDeviceWatcher::SetWatchMode(TDeviceWatchMode aWatchMode) |
|
102 /** |
|
103 Set the watch mode : If the mode is EWatchMode, only monitor the USB device status. |
|
104 If the mode is EWatchAndStartMode, when cable plugin, NCM will be started automaticly |
|
105 @param aWatchMode The mode user want to set |
|
106 */ |
|
107 { |
|
108 iWatchMode = aWatchMode; |
|
109 switch(iWatchMode) |
|
110 { |
|
111 case EWatchMode: |
|
112 iStartNcm = EFalse; |
|
113 break; |
|
114 case EWatchAndStartMode: |
|
115 iStartNcm = ETrue; |
|
116 break; |
|
117 } |
|
118 //When USB device state changed, CDeviceWatcher will check iStartNcm. The detail please see |
|
119 //RunL() |
|
120 } |
|
121 |
|
122 void CDeviceWatcher::DisplayDeviceState(TUint aDeviceState) |
|
123 /** |
|
124 Display device status on main console |
|
125 @param aDeviceState the device state |
|
126 */ |
|
127 { |
|
128 TBuf<DISPLAY_USB_DEVICE_STATE_LEN> devStatus; |
|
129 switch(aDeviceState) |
|
130 { |
|
131 case EUsbcDeviceStateUndefined: |
|
132 devStatus = |
|
133 // 12345678901 |
|
134 _L("Undefined "); |
|
135 break; |
|
136 |
|
137 case EUsbcDeviceStateDefault: |
|
138 devStatus = |
|
139 // 12345678901 |
|
140 _L("Default "); |
|
141 break; |
|
142 |
|
143 case EUsbcDeviceStateAttached: |
|
144 devStatus = |
|
145 // 12345678901 |
|
146 _L("Attached "); |
|
147 break; |
|
148 |
|
149 case EUsbcDeviceStatePowered: |
|
150 devStatus = |
|
151 // 12345678901 |
|
152 _L("Powered "); |
|
153 break; |
|
154 |
|
155 case EUsbcDeviceStateConfigured: |
|
156 devStatus = |
|
157 // 12345678901 |
|
158 _L("Configured "); |
|
159 break; |
|
160 |
|
161 case EUsbcDeviceStateAddress: |
|
162 devStatus = |
|
163 // 12345678901 |
|
164 _L("Address "); |
|
165 break; |
|
166 |
|
167 case EUsbcDeviceStateSuspended: |
|
168 devStatus = |
|
169 // 12345678901 |
|
170 _L("Suspended "); |
|
171 break; |
|
172 default: |
|
173 devStatus = |
|
174 // 12345678901 |
|
175 _L("Unknown "); |
|
176 break; |
|
177 } |
|
178 iTestConsole.SetDisplayItem(EUsbDeviceStateItem, devStatus); |
|
179 } |