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