29
|
1 |
/*
|
|
2 |
* Copyright (c) 2006, 2007 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: This class implements functions of the notification of the
|
|
15 |
* PTP printer connction and disconnection.
|
|
16 |
*
|
|
17 |
*/
|
|
18 |
|
|
19 |
|
|
20 |
#include "dpsconnectnotifier.h"
|
|
21 |
#include "dpsusbnotifier.h"
|
49
|
22 |
#include "OstTraceDefinitions.h"
|
|
23 |
#ifdef OST_TRACE_COMPILER_IN_USE
|
|
24 |
#include "dpsconnectnotifierTraces.h"
|
29
|
25 |
#endif
|
|
26 |
|
|
27 |
const TUint KUsbAllStates = 0xFFFFFFFF;
|
|
28 |
|
|
29 |
// ---------------------------------------------------------------------------
|
|
30 |
//
|
|
31 |
// ---------------------------------------------------------------------------
|
|
32 |
//
|
|
33 |
CDpsConnectNotifier* CDpsConnectNotifier::NewL(CDpsUsbNotifier* aParent)
|
|
34 |
{
|
|
35 |
CDpsConnectNotifier* self = new(ELeave) CDpsConnectNotifier(aParent);
|
|
36 |
return self;
|
|
37 |
}
|
|
38 |
|
|
39 |
// ---------------------------------------------------------------------------
|
|
40 |
//
|
|
41 |
// ---------------------------------------------------------------------------
|
|
42 |
//
|
|
43 |
CDpsConnectNotifier::CDpsConnectNotifier(CDpsUsbNotifier* aParent) :
|
|
44 |
CActive(EPriorityNormal), iNotifier(aParent)
|
|
45 |
{
|
49
|
46 |
OstTraceFunctionEntry0( DUP1_CDPSCONNECTNOTIFIER_CDPSCONNECTNOTIFIER_CONS_ENTRY );
|
29
|
47 |
CActiveScheduler::Add(this);
|
49
|
48 |
OstTraceFunctionExit0( DUP1_CDPSCONNECTNOTIFIER_CDPSCONNECTNOTIFIER_CONS_EXIT );
|
29
|
49 |
}
|
|
50 |
|
|
51 |
// ---------------------------------------------------------------------------
|
|
52 |
//
|
|
53 |
// ---------------------------------------------------------------------------
|
|
54 |
//
|
|
55 |
CDpsConnectNotifier::~CDpsConnectNotifier()
|
|
56 |
{
|
49
|
57 |
OstTraceFunctionEntry0( CDPSCONNECTNOTIFIER_CDPSCONNECTNOTIFIER_DES_ENTRY );
|
29
|
58 |
Cancel();
|
49
|
59 |
OstTraceFunctionExit0( CDPSCONNECTNOTIFIER_CDPSCONNECTNOTIFIER_DES_EXIT );
|
29
|
60 |
}
|
|
61 |
|
|
62 |
// ---------------------------------------------------------------------------
|
|
63 |
//
|
|
64 |
// ---------------------------------------------------------------------------
|
|
65 |
//
|
|
66 |
void CDpsConnectNotifier::ConnectNotify()
|
|
67 |
{
|
49
|
68 |
OstTraceFunctionEntry0( CDPSCONNECTNOTIFIER_CONNECTNOTIFY_ENTRY );
|
29
|
69 |
if (!IsActive())
|
|
70 |
{
|
|
71 |
iNotifier->iUsbM.DeviceStateNotification(KUsbAllStates,
|
|
72 |
iNotifier->iConnectState,
|
|
73 |
iStatus);
|
|
74 |
SetActive();
|
49
|
75 |
}
|
|
76 |
OstTraceFunctionExit0( CDPSCONNECTNOTIFIER_CONNECTNOTIFY_EXIT );
|
29
|
77 |
}
|
|
78 |
|
|
79 |
// ---------------------------------------------------------------------------
|
|
80 |
//
|
|
81 |
// ---------------------------------------------------------------------------
|
|
82 |
//
|
|
83 |
void CDpsConnectNotifier::RunL()
|
|
84 |
{
|
49
|
85 |
OstTraceFunctionEntry0( CDPSCONNECTNOTIFIER_RUNL_ENTRY );
|
|
86 |
OstTrace1( TRACE_NORMAL, CDPSCONNECTNOTIFIER_RUNL, "status %d", iNotifier->iConnectState );
|
|
87 |
|
29
|
88 |
if (KErrNone == iStatus.Int())
|
|
89 |
{
|
|
90 |
|
|
91 |
// notify connect (by set personality)
|
|
92 |
if (iNotifier->iConnectState == EUsbDeviceStateConfigured &&
|
|
93 |
!iNotifier->iConfigured)
|
|
94 |
{
|
|
95 |
iNotifier->PtpNotify(KErrNone);
|
|
96 |
}
|
|
97 |
// Notify disconnect on cable disconnection and for compatible printer
|
|
98 |
// also when other device state than configured or suspended is entered.
|
|
99 |
else if ( (iNotifier->iConnectState == EUsbDeviceStateUndefined) ||
|
|
100 |
( iNotifier->IsConfigured() &&
|
|
101 |
(iNotifier->iConnectState != EUsbDeviceStateConfigured) &&
|
|
102 |
(iNotifier->iConnectState != EUsbDeviceStateSuspended) ) )
|
|
103 |
{
|
|
104 |
iNotifier->DisconnectNotify(iNotifier->iConnectState);
|
|
105 |
}
|
|
106 |
else // not the state we are interested, keep on listening
|
|
107 |
{
|
|
108 |
iNotifier->iUsbM.DeviceStateNotification(KUsbAllStates,
|
|
109 |
iNotifier->iConnectState,
|
|
110 |
iStatus);
|
|
111 |
SetActive();
|
|
112 |
}
|
|
113 |
|
|
114 |
}
|
|
115 |
else
|
|
116 |
{
|
49
|
117 |
OstTrace0( TRACE_WARNING, DUP1_CDPSCONNECTNOTIFIER_RUNL, "the iStatus is wrong!!!" );
|
|
118 |
}
|
|
119 |
OstTraceFunctionExit0( CDPSCONNECTNOTIFIER_RUNL_EXIT );
|
29
|
120 |
}
|
|
121 |
|
|
122 |
// ---------------------------------------------------------------------------
|
|
123 |
//
|
|
124 |
// ---------------------------------------------------------------------------
|
|
125 |
//
|
|
126 |
void CDpsConnectNotifier::DoCancel()
|
|
127 |
{
|
49
|
128 |
OstTraceFunctionEntry0( CDPSCONNECTNOTIFIER_DOCANCEL_ENTRY );
|
29
|
129 |
iNotifier->iUsbM.DeviceStateNotificationCancel();
|
49
|
130 |
OstTraceFunctionExit0( CDPSCONNECTNOTIFIER_DOCANCEL_EXIT );
|
29
|
131 |
}
|
|
132 |
|
|
133 |
// ---------------------------------------------------------------------------
|
|
134 |
//
|
|
135 |
// ---------------------------------------------------------------------------
|
|
136 |
//
|
|
137 |
TInt CDpsConnectNotifier::RunError(TInt aErr)
|
|
138 |
{
|
49
|
139 |
OstTraceDef1(OST_TRACE_CATEGORY_PRODUCTION, TRACE_IMPORTANT, CDPSCONNECTNOTIFIER_RUNERROR,
|
|
140 |
"CDpsConnectNotifier::RunError is %d", aErr );
|
29
|
141 |
return aErr;
|
|
142 |
}
|