0
|
1 |
/*
|
|
2 |
* Copyright (c) 2007-2008 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 the License "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 |
|
|
19 |
|
|
20 |
// INCLUDE FILES
|
|
21 |
#include <pipeisi.h> // isi pipe
|
|
22 |
|
|
23 |
#include "dpdef.h" // dataport definitions
|
|
24 |
#include "dpdataport.h" // dataport main and c32 interface
|
|
25 |
#include "dppif.h" // pipe interface (pif)
|
|
26 |
#include "dpmif.h" // message inteface (mif)
|
|
27 |
#include "dplog.h" // dataport logging
|
|
28 |
#include <pipe_sharedisi.h>
|
|
29 |
#include "osttracedefinitions.h"
|
|
30 |
#ifdef OST_TRACE_COMPILER_IN_USE
|
|
31 |
#include "dppiftraces.h"
|
|
32 |
#endif
|
|
33 |
|
|
34 |
|
|
35 |
// EXTERNAL DATA STRUCTURES
|
|
36 |
// none
|
|
37 |
|
|
38 |
// EXTERNAL FUNCTION PROTOTYPES
|
|
39 |
// none
|
|
40 |
|
|
41 |
// CONSTANTS
|
|
42 |
// none
|
|
43 |
|
|
44 |
// MACROS
|
|
45 |
// none
|
|
46 |
|
|
47 |
// LOCAL CONSTANTS AND MACROS
|
|
48 |
// none
|
|
49 |
|
|
50 |
// MODULE DATA STRUCTURES
|
|
51 |
// none
|
|
52 |
|
|
53 |
// LOCAL FUNCTION PROTOTYPES
|
|
54 |
// none
|
|
55 |
|
|
56 |
// FORWARD DECLARATIONS
|
|
57 |
// none
|
|
58 |
|
|
59 |
// ============================= LOCAL FUNCTIONS ===============================
|
|
60 |
|
|
61 |
// none
|
|
62 |
|
|
63 |
|
|
64 |
// ============================ MEMBER FUNCTIONS ===============================
|
|
65 |
|
|
66 |
// ---------------------------------------------------------
|
|
67 |
// CDpPif::CDpPif
|
|
68 |
// C++ default constructor.
|
|
69 |
// ---------------------------------------------------------
|
|
70 |
CDpPif::CDpPif(
|
|
71 |
CDpDataPort& aDataPort ) :
|
|
72 |
CActive( KDpPifPriority ),
|
|
73 |
iDataPort( aDataPort ),
|
|
74 |
iPipeState( EDpPipeDisconnected ),
|
|
75 |
iPipeHandle( PN_PIPE_INVALID_HANDLE ),
|
|
76 |
iPifState( EDpPifInitial )
|
|
77 |
{
|
|
78 |
OstTrace0( TRACE_NORMAL, CDPPIF_CDPPIF, "CDpPif::CDpPif" );
|
|
79 |
LOGM(" CDpPif::CDpPif");
|
|
80 |
|
|
81 |
CActiveScheduler::Add( this );
|
|
82 |
}
|
|
83 |
|
|
84 |
// ---------------------------------------------------------
|
|
85 |
// CDpPif::~CDpPif
|
|
86 |
// Destructor
|
|
87 |
// ---------------------------------------------------------
|
|
88 |
CDpPif::~CDpPif()
|
|
89 |
{
|
|
90 |
OstTrace0( TRACE_NORMAL, DUP1_CDPPIF_CDPPIF, "CDpPif::~CDpPif" );
|
|
91 |
LOGM(" CDpPif::~CDpPif");
|
|
92 |
}
|
|
93 |
|
|
94 |
// ---------------------------------------------------------
|
|
95 |
// CDpPif::RunL
|
|
96 |
// PIF state is changed here after registering.
|
|
97 |
// ---------------------------------------------------------
|
|
98 |
//
|
|
99 |
void CDpPif::RunL()
|
|
100 |
{
|
|
101 |
OstTrace0( TRACE_NORMAL, CDPPIF_RUNL, "CDpPif::RunL" );
|
|
102 |
OstTrace1( TRACE_NORMAL, DUP1_CDPPIF_RUNL, "CDpPif:: Port: %u", iDataPort.PortUnit() );
|
|
103 |
|
|
104 |
LOGM1("CDpPif::RunL - Port %d", iDataPort.PortUnit() );
|
|
105 |
|
|
106 |
// which state in initializing are we
|
|
107 |
switch ( iPifState )
|
|
108 |
{
|
|
109 |
case EDpPifRegister:
|
|
110 |
{
|
|
111 |
// if pns_name_add failed, there's not much to do,
|
|
112 |
// we just wait to get thrown away...
|
|
113 |
if ( KErrNone == iStatus.Int() )
|
|
114 |
{
|
|
115 |
iPifState = EDpPifReady;
|
|
116 |
}
|
|
117 |
//no else
|
|
118 |
break;
|
|
119 |
}
|
|
120 |
case EDpPifReady:
|
|
121 |
case EDpPifInitial:
|
|
122 |
{
|
|
123 |
break;
|
|
124 |
}
|
|
125 |
default:
|
|
126 |
{
|
|
127 |
LOG1(" ERROR, CDpPif::RunL, Unsupported PIFState: %d", iPifState );
|
|
128 |
OstTrace1( TRACE_NORMAL, DUP2_CDPPIF_RUNL, "ERROR, CDpPif::RunL, Unsupported PIFState: %d", iPifState );
|
|
129 |
|
|
130 |
User::Leave( KErrGeneral );
|
|
131 |
}
|
|
132 |
}
|
|
133 |
}
|
|
134 |
|
|
135 |
// ---------------------------------------------------------
|
|
136 |
// CDpPif::RunError
|
|
137 |
// Leave in RunL() is handled here. Error code is returned,
|
|
138 |
// when internal error has occured (unsupported pipe state).
|
|
139 |
// ---------------------------------------------------------
|
|
140 |
//
|
|
141 |
TInt CDpPif::RunError(
|
|
142 |
TInt aError )
|
|
143 |
{
|
|
144 |
OstTrace0( TRACE_NORMAL, CDPPIF_RUNERROR, "CDpPif::RunError" );
|
|
145 |
OstTraceExt2( TRACE_NORMAL, DUP1_CDPPIF_RUNERROR, "CDpPif:: Port: %u, error code: %d", iDataPort.PortUnit(), aError );
|
|
146 |
|
|
147 |
LOGM2("CDpPif::RunError - Port %d, error code: %d",
|
|
148 |
iDataPort.PortUnit(), aError );
|
|
149 |
|
|
150 |
return aError;
|
|
151 |
}
|
|
152 |
|
|
153 |
// ---------------------------------------------------------
|
|
154 |
// CDpPif::DoCancel
|
|
155 |
// This method signals PIF with KErrCancel, if PIF is
|
|
156 |
// registered state.
|
|
157 |
// ---------------------------------------------------------
|
|
158 |
//
|
|
159 |
void CDpPif::DoCancel()
|
|
160 |
{
|
|
161 |
OstTrace0( TRACE_NORMAL, CDPPIF_DOCANCEL, "CDpPif::DoCancel" );
|
|
162 |
LOGM(" CDpPif::DoCancel");
|
|
163 |
|
|
164 |
if ( IsActive() )
|
|
165 |
{
|
|
166 |
iDataPort.SignalPif( KErrCancel );
|
|
167 |
}
|
|
168 |
}
|
|
169 |
|
|
170 |
// ---------------------------------------------------------
|
|
171 |
// CDpPif::InitiatePipe
|
|
172 |
// This method registers DataPort to Name Service.
|
|
173 |
// ---------------------------------------------------------
|
|
174 |
//
|
|
175 |
TInt CDpPif::InitiatePipe(
|
|
176 |
const TUint aUnit )
|
|
177 |
{
|
|
178 |
OstTrace0( TRACE_NORMAL, CDPPIF_INITIATEPIPE, "CDpPif::InitiatePipe" );
|
|
179 |
OstTrace1( TRACE_NORMAL, DUP1_CDPPIF_INITIATEPIPE, "CDpPif:: Port: %u", aUnit );
|
|
180 |
|
|
181 |
LOGM1(" CDpPif::InitiatePipe - Port %d", aUnit );
|
|
182 |
|
|
183 |
TInt ret( KErrNone );
|
|
184 |
|
|
185 |
if ( !iPepRegistered )
|
|
186 |
{
|
|
187 |
// pep_register
|
|
188 |
|
|
189 |
TRAP( ret, iDataPort.Mif().SendNameAddReqL( aUnit ) );
|
|
190 |
|
|
191 |
if ( KErrNone == ret )
|
|
192 |
{
|
|
193 |
// set active
|
|
194 |
if ( !IsActive() )
|
|
195 |
{
|
|
196 |
iStatus = KRequestPending;
|
|
197 |
SetActive();
|
|
198 |
}
|
|
199 |
//no else
|
|
200 |
|
|
201 |
iPepRegistered = ETrue;
|
|
202 |
// state_change
|
|
203 |
iPifState = EDpPifRegister;
|
|
204 |
}
|
|
205 |
//no else
|
|
206 |
}
|
|
207 |
else
|
|
208 |
{
|
|
209 |
// registered pipe already exists
|
|
210 |
ret = KErrAlreadyExists;
|
|
211 |
}
|
|
212 |
|
|
213 |
return ret;
|
|
214 |
}
|
|
215 |
|
|
216 |
// ---------------------------------------------------------
|
|
217 |
// CDpPif::ClosePipeL
|
|
218 |
// This method unregisters DataPort from Name Service.
|
|
219 |
// ---------------------------------------------------------
|
|
220 |
//
|
|
221 |
void CDpPif::ClosePipeL( const TUint aUnit )
|
|
222 |
{
|
|
223 |
OstTrace0( TRACE_NORMAL, CDPPIF_CLOSEPIPEL, "CDpPif::ClosePipeL" );
|
|
224 |
OstTrace1( TRACE_NORMAL, DUP1_CDPPIF_CLOSEPIPEL, "CDpPif:: Port: %u", aUnit );
|
|
225 |
|
|
226 |
LOGM1(" CDpPif::ClosePipeL - Port %d", aUnit );
|
|
227 |
|
|
228 |
iPepRegistered = EFalse;
|
|
229 |
|
|
230 |
iDataPort.Mif().SendNameRemoveReqL( aUnit );
|
|
231 |
|
|
232 |
// state_change
|
|
233 |
iPifState = EDpPifInitial;
|
|
234 |
}
|
|
235 |
|
|
236 |
// -----------------------------------------------------------------------------
|
|
237 |
// CDpPif::Attach
|
|
238 |
// Attach observer to CDpSubject.
|
|
239 |
// -----------------------------------------------------------------------------
|
|
240 |
//
|
|
241 |
void CDpPif::Attach( CDpObserver& aObserver )
|
|
242 |
{
|
|
243 |
OstTrace0( TRACE_NORMAL, CDPPIF_ATTACH, "CDpPif::Attach" );
|
|
244 |
iDpSubject.Attach( aObserver );
|
|
245 |
}
|
|
246 |
|
|
247 |
// -----------------------------------------------------------------------------
|
|
248 |
// CDpPif::Detach
|
|
249 |
// Detach observer from CDpSubject.
|
|
250 |
// -----------------------------------------------------------------------------
|
|
251 |
//
|
|
252 |
void CDpPif::Detach( CDpObserver& aObserver )
|
|
253 |
{
|
|
254 |
OstTrace0( TRACE_NORMAL, CDPPIF_DETACH, "CDpPif::Detach" );
|
|
255 |
iDpSubject.Detach( aObserver );
|
|
256 |
}
|
|
257 |
|
|
258 |
// -----------------------------------------------------------------------------
|
|
259 |
// CDpPif::Notify
|
|
260 |
// Notify all observers of CDpSubject object.
|
|
261 |
// -----------------------------------------------------------------------------
|
|
262 |
//
|
|
263 |
void CDpPif::Notify()
|
|
264 |
{
|
|
265 |
OstTrace0( TRACE_NORMAL, CDPPIF_NOTIFY, "CDpPif::Notify" );
|
|
266 |
iDpSubject.Notify();
|
|
267 |
}
|
|
268 |
|
|
269 |
// ================= OTHER EXPORTED FUNCTIONS ==============
|
|
270 |
// none
|
|
271 |
|
|
272 |
// End of File
|