0
|
1 |
/*
|
|
2 |
* Copyright (c) 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 |
// INCLUDE FILES
|
|
18 |
#include <e32std.h>
|
|
19 |
#include "toolsusbportlistener.h"
|
|
20 |
|
|
21 |
// LOCAL FUNCTION PROTOTYPES
|
|
22 |
|
|
23 |
// LOCAL CONSTANTS
|
|
24 |
|
|
25 |
const TUint KUsbDeviceStateMask = 0x00ff;
|
|
26 |
#define KPersonalityPCSuite 113
|
|
27 |
#define KPersonalityPCSuiteMTP 5
|
|
28 |
|
|
29 |
//
|
|
30 |
// CToolsUsbPortListener::CToolsUsbPortListener
|
|
31 |
// Constructor
|
|
32 |
//
|
|
33 |
CToolsUsbPortListener::CToolsUsbPortListener (MToolsConnectionListener *aConnectionListener)
|
|
34 |
:CToolsCommPortListener(aConnectionListener, CActive::EPriorityStandard)
|
|
35 |
{
|
|
36 |
iUsbDeviceState = EUsbDeviceStateUndefined;
|
|
37 |
iConnected = EFalse;
|
|
38 |
iPersonalityId = 0;
|
|
39 |
|
|
40 |
// For platsim, getting the USB device state is not supported.
|
|
41 |
// Infact it panics the server, so don't bother with the USB state for platsim.
|
|
42 |
#ifndef __PLATSIM__
|
|
43 |
TInt err = iUsbServer.Connect();
|
|
44 |
|
|
45 |
err = iUsbServer.GetDeviceState( iUsbDeviceState );
|
|
46 |
if (!err)
|
|
47 |
err = iUsbServer.GetCurrentPersonalityId( iPersonalityId );
|
|
48 |
|
|
49 |
if (!err && iUsbDeviceState == EUsbDeviceStateConfigured
|
|
50 |
&& iPersonalityId == KPersonalityPCSuiteMTP)
|
|
51 |
iConnected = ETrue;
|
|
52 |
|
|
53 |
CActiveScheduler::Add( this );
|
|
54 |
#endif
|
|
55 |
|
|
56 |
}
|
|
57 |
|
|
58 |
//
|
|
59 |
// CToolsUsbPortListener::~CToolsUsbPortListener
|
|
60 |
// Destructor
|
|
61 |
//
|
|
62 |
CToolsUsbPortListener::~CToolsUsbPortListener()
|
|
63 |
{
|
|
64 |
#ifndef __PLATSIM__
|
|
65 |
Cancel(); // Ensure that any outstanding requests are cancelled
|
|
66 |
Deque();
|
|
67 |
iUsbServer.Close();
|
|
68 |
#endif
|
|
69 |
}
|
|
70 |
|
|
71 |
//
|
|
72 |
// CToolsUsbPortListener::ListenL
|
|
73 |
// Starts listening for usb connection status notifications..
|
|
74 |
//
|
|
75 |
void CToolsUsbPortListener::ListenL()
|
|
76 |
{
|
|
77 |
IssueRequestL();
|
|
78 |
}
|
|
79 |
|
|
80 |
//
|
|
81 |
// CToolsUsbPortListener::IsConnectionAvailable
|
|
82 |
//
|
|
83 |
TBool CToolsUsbPortListener::IsConnectionAvailable()
|
|
84 |
{
|
|
85 |
#ifndef __PLATSIM__
|
|
86 |
TInt err = iUsbServer.GetDeviceState( iUsbDeviceState );
|
|
87 |
if (!err)
|
|
88 |
err = iUsbServer.GetCurrentPersonalityId( iPersonalityId );
|
|
89 |
|
|
90 |
if (!err && iUsbDeviceState == EUsbDeviceStateConfigured
|
|
91 |
&& iPersonalityId == KPersonalityPCSuiteMTP)
|
|
92 |
{
|
|
93 |
iConnected = ETrue;
|
|
94 |
return ETrue;
|
|
95 |
}
|
|
96 |
#endif
|
|
97 |
return EFalse;
|
|
98 |
}
|
|
99 |
|
|
100 |
//
|
|
101 |
// CToolsUsbPortListener::IssueRequestL
|
|
102 |
//
|
|
103 |
void CToolsUsbPortListener::IssueRequestL()
|
|
104 |
{
|
|
105 |
#ifndef __PLATSIM__
|
|
106 |
if ( iUsbDeviceState == EUsbDeviceStateUndefined )
|
|
107 |
{
|
|
108 |
User::LeaveIfError( iUsbServer.GetDeviceState( iUsbDeviceState ) );
|
|
109 |
}
|
|
110 |
|
|
111 |
iUsbServer.DeviceStateNotification(KUsbDeviceStateMask, iUsbDeviceState, iStatus);
|
|
112 |
SetActive();
|
|
113 |
#endif
|
|
114 |
}
|
|
115 |
|
|
116 |
//
|
|
117 |
// CToolsUsbPortListener::StopListening
|
|
118 |
// Cancel any pending requests for connection status notifications.
|
|
119 |
//
|
|
120 |
void CToolsUsbPortListener::StopListening()
|
|
121 |
{
|
|
122 |
Cancel();
|
|
123 |
}
|
|
124 |
|
|
125 |
//
|
|
126 |
// CToolsUsbPortListener::DoCancel
|
|
127 |
// This method gets called from CActive::Cancel();
|
|
128 |
//
|
|
129 |
void CToolsUsbPortListener::DoCancel()
|
|
130 |
{
|
|
131 |
#ifndef __PLATSIM__
|
|
132 |
iUsbServer.DeviceStateNotificationCancel();
|
|
133 |
#endif
|
|
134 |
iUsbDeviceState = EUsbDeviceStateUndefined;
|
|
135 |
}
|
|
136 |
|
|
137 |
//
|
|
138 |
// CToolsUsbPortListener::RunL
|
|
139 |
// This method gets called whenever there is a change in the connection status.
|
|
140 |
// Right now we are interested only when the cable is disconnected.
|
|
141 |
// For all the other notifications, just reissues the request.
|
|
142 |
//
|
|
143 |
void CToolsUsbPortListener::RunL()
|
|
144 |
{
|
|
145 |
#ifndef __PLATSIM__
|
|
146 |
User::LeaveIfError( iStatus.Int() );
|
|
147 |
|
|
148 |
iUsbServer.GetCurrentPersonalityId( iPersonalityId );
|
|
149 |
|
|
150 |
if ( iUsbDeviceState == EUsbDeviceStateUndefined ||
|
|
151 |
(iUsbDeviceState == EUsbDeviceStateConfigured && iPersonalityId != KPersonalityPCSuiteMTP) )
|
|
152 |
{
|
|
153 |
iConnectionListener->ConnectionUnAvailable();
|
|
154 |
iConnected = EFalse;
|
|
155 |
}
|
|
156 |
// There is something wrong with USB cable status notifications
|
|
157 |
// When the cable is disconnected, first you get a notification
|
|
158 |
// with the device state as configured.
|
|
159 |
// So we need to work around using a local status flag
|
|
160 |
else if ( iUsbDeviceState == EUsbDeviceStateConfigured &&
|
|
161 |
iPersonalityId == KPersonalityPCSuiteMTP &&
|
|
162 |
!iConnected)
|
|
163 |
{
|
|
164 |
iConnected = ETrue;
|
|
165 |
iConnectionListener->ConnectionAvailable();;
|
|
166 |
}
|
|
167 |
|
|
168 |
IssueRequestL();
|
|
169 |
#endif
|
|
170 |
}
|
|
171 |
|
|
172 |
TConnectionStatus CToolsUsbPortListener::GetUsbConnStatus()
|
|
173 |
{
|
|
174 |
if(iConnected)
|
|
175 |
return EUsbConnected;
|
|
176 |
|
|
177 |
return EUsbNotConnected;
|
|
178 |
}
|
|
179 |
|
|
180 |
|
|
181 |
|