sl@0
|
1 |
// Copyright (c) 1999-2009 Nokia Corporation and/or its subsidiary(-ies).
|
sl@0
|
2 |
// All rights reserved.
|
sl@0
|
3 |
// This component and the accompanying materials are made available
|
sl@0
|
4 |
// under the terms of "Eclipse Public License v1.0"
|
sl@0
|
5 |
// which accompanies this distribution, and is available
|
sl@0
|
6 |
// at the URL "http://www.eclipse.org/legal/epl-v10.html".
|
sl@0
|
7 |
//
|
sl@0
|
8 |
// Initial Contributors:
|
sl@0
|
9 |
// Nokia Corporation - initial contribution.
|
sl@0
|
10 |
//
|
sl@0
|
11 |
// Contributors:
|
sl@0
|
12 |
//
|
sl@0
|
13 |
// Description:
|
sl@0
|
14 |
//
|
sl@0
|
15 |
|
sl@0
|
16 |
#include <e32std.h>
|
sl@0
|
17 |
#include <redircli.h>
|
sl@0
|
18 |
#include <redircliinternal.h>
|
sl@0
|
19 |
|
sl@0
|
20 |
#ifndef EKA2
|
sl@0
|
21 |
GLDEF_C TInt E32Dll(TDllReason)
|
sl@0
|
22 |
{
|
sl@0
|
23 |
return KErrNone;
|
sl@0
|
24 |
}
|
sl@0
|
25 |
#endif
|
sl@0
|
26 |
|
sl@0
|
27 |
// server name
|
sl@0
|
28 |
_LIT(KRedirServerName,"RedirServer");
|
sl@0
|
29 |
|
sl@0
|
30 |
enum TRedirStream
|
sl@0
|
31 |
{
|
sl@0
|
32 |
ERedirRead,
|
sl@0
|
33 |
ERedirWrite,
|
sl@0
|
34 |
ERedirFlush
|
sl@0
|
35 |
};
|
sl@0
|
36 |
|
sl@0
|
37 |
// A version must be specified when creating a session with the server
|
sl@0
|
38 |
const TUint KRedirServMajorVersionNumber=1;
|
sl@0
|
39 |
const TUint KRedirServMinorVersionNumber=0;
|
sl@0
|
40 |
const TUint KRedirServBuildVersionNumber=0;
|
sl@0
|
41 |
|
sl@0
|
42 |
|
sl@0
|
43 |
//**********************************
|
sl@0
|
44 |
// CRedirSession
|
sl@0
|
45 |
//**********************************
|
sl@0
|
46 |
// This class represents a session in the server.
|
sl@0
|
47 |
// Functions are provided to respond appropriately to client messages.
|
sl@0
|
48 |
NONSHARABLE_CLASS(CRedirSession) : public CSession2
|
sl@0
|
49 |
{
|
sl@0
|
50 |
public:
|
sl@0
|
51 |
static CRedirSession* NewL(CStreamBase2* aStream);
|
sl@0
|
52 |
//service request
|
sl@0
|
53 |
virtual void ServiceL(const RMessage2 &aMessage);
|
sl@0
|
54 |
private :
|
sl@0
|
55 |
// construct/destruct
|
sl@0
|
56 |
CRedirSession(CStreamBase2* aStream);
|
sl@0
|
57 |
~CRedirSession();
|
sl@0
|
58 |
//services available to handle read/write requests
|
sl@0
|
59 |
TInt WriteStreamL(const RMessage2& aMessage);
|
sl@0
|
60 |
private:
|
sl@0
|
61 |
CStreamBase2* iStream;
|
sl@0
|
62 |
};
|
sl@0
|
63 |
|
sl@0
|
64 |
// ------------------- CRedirServer2 implementation --------------------------
|
sl@0
|
65 |
|
sl@0
|
66 |
|
sl@0
|
67 |
/**
|
sl@0
|
68 |
Constructs and allocates memory for a new CRedirServer2 object.
|
sl@0
|
69 |
@return RedirServer
|
sl@0
|
70 |
@param aStreamFactory Stream factory.
|
sl@0
|
71 |
*/
|
sl@0
|
72 |
EXPORT_C CRedirServer2* CRedirServer2::NewL(CStreamFactoryBase2* aStreamFactory)
|
sl@0
|
73 |
{
|
sl@0
|
74 |
CRedirServer2* r=new(ELeave) CRedirServer2(aStreamFactory);
|
sl@0
|
75 |
CleanupStack::PushL(r);
|
sl@0
|
76 |
r->StartL(KRedirServerName);
|
sl@0
|
77 |
CleanupStack::Pop();
|
sl@0
|
78 |
return r;
|
sl@0
|
79 |
}
|
sl@0
|
80 |
|
sl@0
|
81 |
/**
|
sl@0
|
82 |
Default constructor
|
sl@0
|
83 |
@param aStreamFactory Stream factory.
|
sl@0
|
84 |
*/
|
sl@0
|
85 |
CRedirServer2::CRedirServer2(CStreamFactoryBase2* aStreamFactory)
|
sl@0
|
86 |
: CServer2(EPriority)
|
sl@0
|
87 |
{
|
sl@0
|
88 |
iStreamFactory = aStreamFactory;
|
sl@0
|
89 |
}
|
sl@0
|
90 |
|
sl@0
|
91 |
/**
|
sl@0
|
92 |
Virtual destructor
|
sl@0
|
93 |
*/
|
sl@0
|
94 |
CRedirServer2::~CRedirServer2()
|
sl@0
|
95 |
{
|
sl@0
|
96 |
}
|
sl@0
|
97 |
|
sl@0
|
98 |
/**
|
sl@0
|
99 |
Create a new server session.
|
sl@0
|
100 |
Checks if the aVersion is the right version and make a new session.
|
sl@0
|
101 |
@leave KErrNotSupported
|
sl@0
|
102 |
@return Sharable Session for all threads within a single process.
|
sl@0
|
103 |
@param aVersion Contains version information.
|
sl@0
|
104 |
A version is defined by a set of three numbers:major,minor,build version number
|
sl@0
|
105 |
*/
|
sl@0
|
106 |
CSession2* CRedirServer2::NewSessionL(const TVersion& aVersion, const RMessage2& /*aMessage*/) const
|
sl@0
|
107 |
{
|
sl@0
|
108 |
|
sl@0
|
109 |
TVersion v(KRedirServMajorVersionNumber,KRedirServMinorVersionNumber,
|
sl@0
|
110 |
KRedirServBuildVersionNumber);
|
sl@0
|
111 |
if (!User::QueryVersionSupported(v,aVersion))
|
sl@0
|
112 |
User::Leave(KErrNotSupported);
|
sl@0
|
113 |
// get a stream object from the current stream factory
|
sl@0
|
114 |
CStreamBase2* stream = iStreamFactory->GetStream();
|
sl@0
|
115 |
return CRedirSession::NewL(stream);
|
sl@0
|
116 |
}
|
sl@0
|
117 |
|
sl@0
|
118 |
/**
|
sl@0
|
119 |
Sets the stream factory
|
sl@0
|
120 |
@param aStreamFactory a factory to be set
|
sl@0
|
121 |
*/
|
sl@0
|
122 |
EXPORT_C void CRedirServer2::SetStreamFactory(CStreamFactoryBase2* aStreamFactory)
|
sl@0
|
123 |
{
|
sl@0
|
124 |
// set the stream factory
|
sl@0
|
125 |
iStreamFactory = aStreamFactory;
|
sl@0
|
126 |
}
|
sl@0
|
127 |
|
sl@0
|
128 |
// ------------------- CRedirSession2 implementation --------------------------
|
sl@0
|
129 |
CRedirSession* CRedirSession::NewL(CStreamBase2* aStream)
|
sl@0
|
130 |
{
|
sl@0
|
131 |
return new(ELeave) CRedirSession(aStream);
|
sl@0
|
132 |
}
|
sl@0
|
133 |
|
sl@0
|
134 |
CRedirSession::CRedirSession(CStreamBase2* aStream)
|
sl@0
|
135 |
: iStream(aStream)
|
sl@0
|
136 |
{}
|
sl@0
|
137 |
|
sl@0
|
138 |
CRedirSession::~CRedirSession()
|
sl@0
|
139 |
{
|
sl@0
|
140 |
// The stream returned by GetStream() is effectively a singleton as
|
sl@0
|
141 |
// implemented in the current redirector, so we leave deletion to
|
sl@0
|
142 |
// the factory
|
sl@0
|
143 |
}
|
sl@0
|
144 |
|
sl@0
|
145 |
void CRedirSession::ServiceL(const RMessage2& aMessage)
|
sl@0
|
146 |
{
|
sl@0
|
147 |
TInt ret = KErrNone;
|
sl@0
|
148 |
switch (aMessage.Function())
|
sl@0
|
149 |
{
|
sl@0
|
150 |
case ERedirRead:
|
sl@0
|
151 |
// call the Stream to do the read for us
|
sl@0
|
152 |
iStream->Read(aMessage);
|
sl@0
|
153 |
break;
|
sl@0
|
154 |
case ERedirWrite:
|
sl@0
|
155 |
TRAP(ret,WriteStreamL(aMessage));
|
sl@0
|
156 |
aMessage.Complete(ret);
|
sl@0
|
157 |
break;
|
sl@0
|
158 |
case ERedirFlush:
|
sl@0
|
159 |
// TO DO: ignore flushing?
|
sl@0
|
160 |
aMessage.Complete(ret);
|
sl@0
|
161 |
break;
|
sl@0
|
162 |
default:
|
sl@0
|
163 |
aMessage.Complete(KErrNotSupported);
|
sl@0
|
164 |
break;
|
sl@0
|
165 |
}
|
sl@0
|
166 |
return;
|
sl@0
|
167 |
}
|
sl@0
|
168 |
|
sl@0
|
169 |
TInt CRedirSession::WriteStreamL(const RMessage2& aMessage)
|
sl@0
|
170 |
{
|
sl@0
|
171 |
const TInt KMaxTransfer=256;
|
sl@0
|
172 |
//
|
sl@0
|
173 |
// retrieve the length of the buffer the client wants to write
|
sl@0
|
174 |
TInt length = aMessage.Int1();
|
sl@0
|
175 |
// retrieve the descriptor to be written
|
sl@0
|
176 |
TBuf8<KMaxTransfer> bufDes;
|
sl@0
|
177 |
for (TInt offset=0;offset<length;offset+=KMaxTransfer)
|
sl@0
|
178 |
{
|
sl@0
|
179 |
aMessage.ReadL(0, bufDes, offset);
|
sl@0
|
180 |
// send descriptor to stream for printing
|
sl@0
|
181 |
iStream->Write(bufDes);
|
sl@0
|
182 |
}
|
sl@0
|
183 |
return KErrNone;
|
sl@0
|
184 |
}
|
sl@0
|
185 |
|
sl@0
|
186 |
// -------------- CLIENT IMPLEMENTATION -----------------------------
|
sl@0
|
187 |
|
sl@0
|
188 |
EXPORT_C TInt RRedirSession2::Connect()
|
sl@0
|
189 |
{
|
sl@0
|
190 |
TVersion version(KRedirServMajorVersionNumber,KRedirServMinorVersionNumber,
|
sl@0
|
191 |
KRedirServBuildVersionNumber);
|
sl@0
|
192 |
return CreateSession(KRedirServerName,version,1); // only one message allowed - no concurrency
|
sl@0
|
193 |
}
|
sl@0
|
194 |
|
sl@0
|
195 |
TInt RRedirSession2::CheckEOF(TRequestStatus& aStatus)
|
sl@0
|
196 |
{
|
sl@0
|
197 |
if (Handle()!=0)
|
sl@0
|
198 |
return KErrNone;
|
sl@0
|
199 |
TRequestStatus* aStatusPtr=&aStatus;
|
sl@0
|
200 |
User::RequestComplete(aStatusPtr,KErrEof);
|
sl@0
|
201 |
return KErrEof;
|
sl@0
|
202 |
}
|
sl@0
|
203 |
|
sl@0
|
204 |
EXPORT_C void RRedirSession2::Read(TRequestStatus& aStatus, TDes8& aDes)
|
sl@0
|
205 |
{
|
sl@0
|
206 |
Read(aStatus, aDes, aDes.MaxLength());
|
sl@0
|
207 |
}
|
sl@0
|
208 |
|
sl@0
|
209 |
EXPORT_C void RRedirSession2::Read(TRequestStatus& aStatus, TDes8& aDes, TInt aLength)
|
sl@0
|
210 |
{
|
sl@0
|
211 |
if (CheckEOF(aStatus))
|
sl@0
|
212 |
return;
|
sl@0
|
213 |
SendReceive(ERedirRead,TIpcArgs(&aDes,aLength),aStatus);
|
sl@0
|
214 |
}
|
sl@0
|
215 |
|
sl@0
|
216 |
EXPORT_C void RRedirSession2::Write(TRequestStatus& aStatus, const TDesC8& aDes)
|
sl@0
|
217 |
{
|
sl@0
|
218 |
Write(aStatus, aDes, aDes.Length());
|
sl@0
|
219 |
}
|
sl@0
|
220 |
|
sl@0
|
221 |
EXPORT_C void RRedirSession2::Write(TRequestStatus& aStatus, const TDesC8& aDes, TInt aLength)
|
sl@0
|
222 |
//
|
sl@0
|
223 |
// Write aLength bytes
|
sl@0
|
224 |
//
|
sl@0
|
225 |
{
|
sl@0
|
226 |
if (CheckEOF(aStatus))
|
sl@0
|
227 |
return;
|
sl@0
|
228 |
SendReceive(ERedirWrite,TIpcArgs(&aDes,aLength),aStatus);
|
sl@0
|
229 |
}
|
sl@0
|
230 |
|
sl@0
|
231 |
EXPORT_C void RRedirSession2::Flush(TRequestStatus& aStatus)
|
sl@0
|
232 |
//
|
sl@0
|
233 |
// Flush output
|
sl@0
|
234 |
//
|
sl@0
|
235 |
{
|
sl@0
|
236 |
if (CheckEOF(aStatus))
|
sl@0
|
237 |
return;
|
sl@0
|
238 |
SendReceive(ERedirFlush,aStatus);
|
sl@0
|
239 |
}
|
sl@0
|
240 |
|
sl@0
|
241 |
|
sl@0
|
242 |
|