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: Monitors for new data in RComm local media side
|
|
15 |
*
|
|
16 |
*/
|
|
17 |
|
|
18 |
|
|
19 |
#include "DunTransporter.h"
|
|
20 |
#include "DunDataWaiter.h"
|
|
21 |
#include "DunSignalCopy.h"
|
|
22 |
#include "DunDebug.h"
|
|
23 |
|
|
24 |
// ======== MEMBER FUNCTIONS ========
|
|
25 |
|
|
26 |
// ---------------------------------------------------------------------------
|
|
27 |
// Two-phased constructor.
|
|
28 |
// ---------------------------------------------------------------------------
|
|
29 |
//
|
|
30 |
CDunDataWaiter* CDunDataWaiter::NewL( MDunChannelAllocator* aChannelCallback )
|
|
31 |
{
|
|
32 |
CDunDataWaiter* self = new (ELeave) CDunDataWaiter( aChannelCallback );
|
|
33 |
CleanupStack::PushL( self );
|
|
34 |
self->ConstructL();
|
|
35 |
CleanupStack::Pop( self );
|
|
36 |
return self;
|
|
37 |
}
|
|
38 |
|
|
39 |
// ---------------------------------------------------------------------------
|
|
40 |
// Destructor.
|
|
41 |
// ---------------------------------------------------------------------------
|
|
42 |
//
|
|
43 |
CDunDataWaiter::~CDunDataWaiter()
|
|
44 |
{
|
|
45 |
FTRACE(FPrint( _L("CDunDataWaiter::~CDunDataWaiter()") ));
|
|
46 |
ResetData();
|
|
47 |
FTRACE(FPrint( _L("CDunDataWaiter::~CDunDataWaiter() complete") ));
|
|
48 |
}
|
|
49 |
|
|
50 |
// ---------------------------------------------------------------------------
|
|
51 |
// Resets data to initial values
|
|
52 |
// ---------------------------------------------------------------------------
|
|
53 |
//
|
|
54 |
void CDunDataWaiter::ResetData()
|
|
55 |
{
|
|
56 |
FTRACE(FPrint( _L("CDunDataWaiter::ResetData()") ));
|
|
57 |
Stop();
|
|
58 |
// APIs affecting this:
|
|
59 |
// AddConnMonCallbackL()
|
|
60 |
iCallbacks.Close();
|
|
61 |
// Internal
|
|
62 |
Initialize();
|
|
63 |
FTRACE(FPrint( _L("CDunDataWaiter::ResetData() complete") ));
|
|
64 |
}
|
|
65 |
|
|
66 |
// ---------------------------------------------------------------------------
|
|
67 |
// Adds callback for RunL error controlling
|
|
68 |
// The callback will be called when error is detected in asynchronous
|
|
69 |
// operation
|
|
70 |
// ---------------------------------------------------------------------------
|
|
71 |
//
|
|
72 |
TInt CDunDataWaiter::AddCallback( MDunConnMon* aCallback )
|
|
73 |
{
|
|
74 |
FTRACE(FPrint( _L("CDunDataWaiter::AddCallback()" ) ));
|
|
75 |
if ( !aCallback )
|
|
76 |
{
|
|
77 |
FTRACE(FPrint( _L("CDunDataWaiter::AddCallback() (ERROR) complete" ) ));
|
|
78 |
return KErrGeneral;
|
|
79 |
}
|
|
80 |
TInt retTemp = iCallbacks.Find( aCallback );
|
|
81 |
if ( retTemp != KErrNotFound )
|
|
82 |
{
|
|
83 |
FTRACE(FPrint( _L("CDunDataWaiter::AddCallback() (already exists) complete" ) ));
|
|
84 |
return KErrAlreadyExists;
|
|
85 |
}
|
|
86 |
retTemp = iCallbacks.Append( aCallback );
|
|
87 |
if ( retTemp != KErrNone )
|
|
88 |
{
|
|
89 |
FTRACE(FPrint( _L("CDunDataWaiter::AddCallback() (append failed!) complete" ) ));
|
|
90 |
return retTemp;
|
|
91 |
}
|
|
92 |
FTRACE(FPrint( _L("CDunDataWaiter::AddCallback() complete" ) ));
|
|
93 |
return KErrNone;
|
|
94 |
}
|
|
95 |
|
|
96 |
// ---------------------------------------------------------------------------
|
|
97 |
// Sets media to use for this endpoint
|
|
98 |
// ---------------------------------------------------------------------------
|
|
99 |
//
|
|
100 |
TInt CDunDataWaiter::SetMedia( RComm* aComm )
|
|
101 |
{
|
|
102 |
FTRACE(FPrint( _L("CDunDataWaiter::SetMedia(RComm) (addr=0x%08X)" ), aComm));
|
|
103 |
if ( !aComm )
|
|
104 |
{
|
|
105 |
FTRACE(FPrint( _L("CDunDataWaiter::SetMedia() (aComm) not initialized!" )));
|
|
106 |
return KErrGeneral;
|
|
107 |
}
|
|
108 |
TCommCaps2 caps;
|
|
109 |
aComm->Caps( caps );
|
|
110 |
if ( !(caps().iNotificationCaps & KNotifyDataAvailableSupported) )
|
|
111 |
{
|
|
112 |
FTRACE(FPrint( _L("CDunDataWaiter::SetMedia() (RComm) (not supported) complete" )));
|
|
113 |
return KErrNotSupported;
|
|
114 |
}
|
|
115 |
iComm = aComm;
|
|
116 |
FTRACE(FPrint( _L("CDunDataWaiter::SetMedia() (RComm) complete" )));
|
|
117 |
return KErrNone;
|
|
118 |
}
|
|
119 |
|
|
120 |
// ---------------------------------------------------------------------------
|
|
121 |
// Issues request to start waiting for new data in RComm
|
|
122 |
// ---------------------------------------------------------------------------
|
|
123 |
//
|
|
124 |
TInt CDunDataWaiter::IssueRequest()
|
|
125 |
{
|
|
126 |
FTRACE(FPrint( _L("CDunDataWaiter::IssueRequest()" )));
|
|
127 |
if ( iDataWaiterState != EDunStateIdle )
|
|
128 |
{
|
|
129 |
FTRACE(FPrint( _L("CDunDataWaiter::IssueRequest() (not ready) complete" )));
|
|
130 |
return KErrNotReady;
|
|
131 |
}
|
|
132 |
if ( !iComm )
|
|
133 |
{
|
|
134 |
FTRACE(FPrint( _L("CDunDataWaiter::IssueRequest() (iComm) not initialized!" ) ));
|
|
135 |
return KErrGeneral;
|
|
136 |
}
|
52
|
137 |
iComm->ResetBuffers();
|
29
|
138 |
iStatus = KRequestPending;
|
52
|
139 |
iDataWaiterState = EDunStateDataWaiting;
|
29
|
140 |
iComm->NotifyDataAvailable( iStatus );
|
|
141 |
SetActive();
|
|
142 |
FTRACE(FPrint( _L("CDunDataWaiter::IssueRequest() complete" )));
|
|
143 |
return KErrNone;
|
|
144 |
}
|
|
145 |
|
|
146 |
// ---------------------------------------------------------------------------
|
|
147 |
// Stops monitoring for new data
|
|
148 |
// ---------------------------------------------------------------------------
|
|
149 |
//
|
|
150 |
TInt CDunDataWaiter::Stop()
|
|
151 |
{
|
|
152 |
FTRACE(FPrint( _L("CDunDataWaiter::Stop()" )));
|
|
153 |
if ( iDataWaiterState != EDunStateDataWaiting )
|
|
154 |
{
|
|
155 |
FTRACE(FPrint( _L("CDunDataWaiter::Stop() (not ready) complete" )));
|
|
156 |
return KErrNotReady;
|
|
157 |
}
|
|
158 |
if ( !iComm )
|
|
159 |
{
|
|
160 |
FTRACE(FPrint( _L("CDunDataWaiter::Stop() (iComm) not initialized!" )));
|
|
161 |
return KErrGeneral;
|
|
162 |
}
|
|
163 |
iComm->NotifyDataAvailableCancel();
|
|
164 |
Cancel();
|
|
165 |
iDataWaiterState = EDunStateIdle;
|
|
166 |
FTRACE(FPrint( _L("CDunDataWaiter::Stop() complete" )));
|
|
167 |
return KErrNone;
|
|
168 |
}
|
|
169 |
|
|
170 |
// ---------------------------------------------------------------------------
|
|
171 |
// CDunDataWaiter::CDunDataWaiter
|
|
172 |
// ---------------------------------------------------------------------------
|
|
173 |
//
|
|
174 |
CDunDataWaiter::CDunDataWaiter( MDunChannelAllocator* aChannelCallback ) :
|
|
175 |
CActive( EPriorityHigh ),
|
|
176 |
iChannelCallback( aChannelCallback )
|
|
177 |
{
|
|
178 |
Initialize();
|
|
179 |
}
|
|
180 |
|
|
181 |
// ---------------------------------------------------------------------------
|
|
182 |
// CDunDataWaiter::ConstructL
|
|
183 |
// ---------------------------------------------------------------------------
|
|
184 |
//
|
|
185 |
void CDunDataWaiter::ConstructL()
|
|
186 |
{
|
|
187 |
FTRACE(FPrint( _L("CDunDataWaiter::ConstructL()" ) ));
|
|
188 |
if ( !iChannelCallback )
|
|
189 |
{
|
|
190 |
User::Leave( KErrGeneral );
|
|
191 |
}
|
|
192 |
CActiveScheduler::Add( this );
|
|
193 |
FTRACE(FPrint( _L("CDunDataWaiter::ConstructL() complete" ) ));
|
|
194 |
}
|
|
195 |
|
|
196 |
// ---------------------------------------------------------------------------
|
|
197 |
// Initializes this class
|
|
198 |
// ---------------------------------------------------------------------------
|
|
199 |
//
|
|
200 |
void CDunDataWaiter::Initialize()
|
|
201 |
{
|
|
202 |
FTRACE(FPrint( _L("CDunDataWaiter::Initialize()" ) ));
|
|
203 |
// Don't initialize iChannelCallback here (it is set through NewL)
|
|
204 |
iDataWaiterState = EDunStateIdle;
|
|
205 |
iComm = NULL;
|
|
206 |
FTRACE(FPrint( _L("CDunDataWaiter::Initialize() complete" ) ));
|
|
207 |
}
|
|
208 |
|
|
209 |
// ---------------------------------------------------------------------------
|
|
210 |
// From class CActive.
|
|
211 |
// Gets called when new data in RComm object
|
|
212 |
// ---------------------------------------------------------------------------
|
|
213 |
//
|
|
214 |
void CDunDataWaiter::RunL()
|
|
215 |
{
|
|
216 |
FTRACE(FPrint( _L("CDunDataWaiter::RunL()" ) ));
|
|
217 |
iDataWaiterState = EDunStateIdle;
|
|
218 |
TInt retTemp = iStatus.Int();
|
|
219 |
if ( retTemp != KErrNone )
|
|
220 |
{
|
|
221 |
FTRACE(FPrint( _L("CDunDataWaiter::RunL() (failed) complete (%d)"), retTemp));
|
|
222 |
TInt count = iCallbacks.Count();
|
|
223 |
TDunConnectionReason connReason;
|
|
224 |
connReason.iReasonType = EDunReasonTypeRunL;
|
|
225 |
connReason.iContext = EDunMediaContextLocal;
|
|
226 |
connReason.iSignalType = 0;
|
|
227 |
connReason.iSignalHigh = EFalse;
|
|
228 |
connReason.iDirection = EDunDirectionUndefined;
|
|
229 |
connReason.iErrorCode = retTemp;
|
|
230 |
for ( TInt i=0; i<count; i++ )
|
|
231 |
{
|
|
232 |
TRAP_IGNORE(
|
|
233 |
iCallbacks[i]->NotifyProgressChangeL( iComm, connReason ) );
|
|
234 |
}
|
|
235 |
return;
|
|
236 |
}
|
|
237 |
if ( iChannelCallback )
|
|
238 |
{
|
|
239 |
iChannelCallback->NotifyNewChannelRequest( iComm );
|
|
240 |
}
|
|
241 |
// Don't check other iMediaInUse values here
|
|
242 |
// They can't be other than EDunMediaRComm (checked in IssueRequest())
|
|
243 |
FTRACE(FPrint( _L("CDunDataWaiter::RunL() complete" ) ));
|
|
244 |
}
|
|
245 |
|
|
246 |
// ---------------------------------------------------------------------------
|
|
247 |
// From class CActive.
|
|
248 |
// Gets called on cancel
|
|
249 |
// ---------------------------------------------------------------------------
|
|
250 |
//
|
|
251 |
void CDunDataWaiter::DoCancel()
|
|
252 |
{
|
|
253 |
}
|