0
|
1 |
/*
|
|
2 |
* Copyright (c) 2009 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:
|
|
15 |
*
|
|
16 |
*/
|
|
17 |
|
|
18 |
#include "TrkTcbSrvSession.h"
|
|
19 |
|
|
20 |
// System includes
|
|
21 |
|
|
22 |
//User Includes
|
|
23 |
#include "TrkTcbCmdCodes.h"
|
|
24 |
#include "TrkTcbSrvSessionEngine.h"
|
|
25 |
// Type definitions
|
|
26 |
|
|
27 |
// Constants
|
|
28 |
const TInt KTrkTcbServerTransferBufferExpandSize = 100;
|
|
29 |
const TInt KSlot0 = 0;
|
|
30 |
const TInt KSlot1 = 1;
|
|
31 |
//const TInt KSlot2 = 2;
|
|
32 |
const TInt KSlot3 = 3;
|
|
33 |
|
|
34 |
// Enumerations
|
|
35 |
|
|
36 |
// Classes referenced
|
|
37 |
|
|
38 |
|
|
39 |
//
|
|
40 |
// CTrkTcbSrvSession (source)
|
|
41 |
//
|
|
42 |
|
|
43 |
//
|
|
44 |
// CTrkTcbSrvServer::CTrkTcbSrvSession()
|
|
45 |
//
|
|
46 |
// Constructor
|
|
47 |
//
|
|
48 |
CTrkTcbSrvSession::CTrkTcbSrvSession()
|
|
49 |
{
|
|
50 |
}
|
|
51 |
|
|
52 |
//
|
|
53 |
// CTrkTcbSrvServer::~CTrkTcbSrvSession()
|
|
54 |
//
|
|
55 |
// Destructor
|
|
56 |
//
|
|
57 |
CTrkTcbSrvSession::~CTrkTcbSrvSession()
|
|
58 |
{
|
|
59 |
HandleServerDestruction();
|
|
60 |
delete iTransferBuffer;
|
|
61 |
}
|
|
62 |
|
|
63 |
//
|
|
64 |
// CTrkTcbSrvServer::ConstructL()
|
|
65 |
//
|
|
66 |
// Creates an instance of CTrkTcbSrvSession.
|
|
67 |
//
|
|
68 |
void CTrkTcbSrvSession::ConstructL()
|
|
69 |
{
|
|
70 |
iTransferBuffer = CBufFlat::NewL(KTrkTcbServerTransferBufferExpandSize);
|
|
71 |
iSessionEngine = CTrkTcbSrvSessionEngine::NewL();
|
|
72 |
}
|
|
73 |
|
|
74 |
//
|
|
75 |
// CTrkTcbSrvServer::NewL()
|
|
76 |
//
|
|
77 |
// Static self construction
|
|
78 |
//
|
|
79 |
CTrkTcbSrvSession* CTrkTcbSrvSession::NewL()
|
|
80 |
{
|
|
81 |
CTrkTcbSrvSession* self = new(ELeave) CTrkTcbSrvSession();
|
|
82 |
CleanupStack::PushL(self);
|
|
83 |
self->ConstructL();
|
|
84 |
CleanupStack::Pop(self);
|
|
85 |
return self;
|
|
86 |
}
|
|
87 |
|
|
88 |
//
|
|
89 |
// CTrkTcbSrvServer::HandleServerDestruction()
|
|
90 |
//
|
|
91 |
// Called by the server's destructor. We need to be told that the server is
|
|
92 |
// being destroyed.
|
|
93 |
//
|
|
94 |
void CTrkTcbSrvSession::HandleServerDestruction()
|
|
95 |
{
|
|
96 |
delete iSessionEngine;
|
|
97 |
iSessionEngine = NULL;
|
|
98 |
}
|
|
99 |
|
|
100 |
//
|
|
101 |
// CTrkTcbSrvServer::ServiceL()
|
|
102 |
//
|
|
103 |
// Services requests from a client.
|
|
104 |
// Called by the IPC framework whenever a client sends a request to the server.
|
|
105 |
//
|
|
106 |
void CTrkTcbSrvSession::ServiceL(const RMessage2& aMessage)
|
|
107 |
{
|
|
108 |
// Leave's are caught by CASSrvServer::RunError
|
|
109 |
iMessage = &aMessage;
|
|
110 |
|
|
111 |
const TBool completeMessage = DoServiceL();
|
|
112 |
|
|
113 |
//Right now there are no asynchronous message completion.
|
|
114 |
//So if the message is not completed, then there is an error and needs to be reported
|
|
115 |
//to the client.
|
|
116 |
if (completeMessage)
|
|
117 |
aMessage.Complete(KErrNone);
|
|
118 |
else
|
|
119 |
aMessage.Complete(KErrGeneral);
|
|
120 |
|
|
121 |
iMessage=NULL;
|
|
122 |
}
|
|
123 |
|
|
124 |
//
|
|
125 |
// CTrkTcbSrvServer::ServiceL()
|
|
126 |
//
|
|
127 |
// Services the requests.
|
|
128 |
//
|
|
129 |
TBool CTrkTcbSrvSession::DoServiceL()
|
|
130 |
{
|
|
131 |
TBool completeMessage = EFalse;
|
|
132 |
const TInt cmd = Message().Function();
|
|
133 |
//
|
|
134 |
switch(cmd)
|
|
135 |
{
|
|
136 |
case ETrkTcbCmdCodeOpenFile:
|
|
137 |
completeMessage = CmdOpenFileL();
|
|
138 |
break;
|
|
139 |
case ETrkTcbCmdCodeReadFile:
|
|
140 |
completeMessage = CmdReadFileL();
|
|
141 |
break;
|
|
142 |
case ETrkTcbCmdCodeWriteFile:
|
|
143 |
completeMessage = CmdWriteFileL();
|
|
144 |
break;
|
|
145 |
case ETrkTcbCmdCodeCloseFile:
|
|
146 |
completeMessage = CmdCloseFileL();
|
|
147 |
break;
|
|
148 |
case ETrkTcbCmdCodePositionFile:
|
|
149 |
completeMessage = CmdPositionFileL();
|
|
150 |
break;
|
|
151 |
case ETrkTcbCmdCodeShutDownServer:
|
|
152 |
completeMessage = CmdShutDownServer();
|
|
153 |
break;
|
|
154 |
|
|
155 |
default:
|
|
156 |
Message().Panic(KServerIntiatedSessionPanic, ETrkTcbServerInitiatedClientPanicInvalidOperation);
|
|
157 |
break;
|
|
158 |
}
|
|
159 |
|
|
160 |
return completeMessage;
|
|
161 |
}
|
|
162 |
|
|
163 |
//
|
|
164 |
// CTrkTcbSrvServer::CmdOpenFileL()
|
|
165 |
//
|
|
166 |
// Gets the data for open file request and calls the session engine open file method.
|
|
167 |
//
|
|
168 |
TBool CTrkTcbSrvSession::CmdOpenFileL()
|
|
169 |
{
|
|
170 |
const TInt fileNameLength = static_cast<TInt>(Message().Int0());
|
|
171 |
|
|
172 |
if (fileNameLength > 0)
|
|
173 |
{
|
|
174 |
HBufC* filePath = HBufC::NewLC(fileNameLength);
|
|
175 |
TPtr pFilePath(filePath->Des());
|
|
176 |
Message().ReadL(KSlot1, pFilePath);
|
|
177 |
|
|
178 |
const TUint mode = static_cast<TUint>(Message().Int2());
|
|
179 |
|
|
180 |
TTime modifiedTime;
|
|
181 |
iSessionEngine->OpenFileL(filePath->Des(), mode, modifiedTime);
|
|
182 |
|
|
183 |
TPckgC<TTime> package(modifiedTime);
|
|
184 |
Message().WriteL(KSlot3, package);
|
|
185 |
|
|
186 |
CleanupStack::PopAndDestroy(filePath);
|
|
187 |
|
|
188 |
return ETrue;
|
|
189 |
}
|
|
190 |
return EFalse;
|
|
191 |
}
|
|
192 |
|
|
193 |
//
|
|
194 |
// CTrkTcbSrvServer::CmdReadFileL()
|
|
195 |
//
|
|
196 |
// Gets the data for read file request and calls the session engine read file method.
|
|
197 |
//
|
|
198 |
TBool CTrkTcbSrvSession::CmdReadFileL()
|
|
199 |
{
|
|
200 |
const TInt dataLength = static_cast<TInt>(Message().Int0());
|
|
201 |
|
|
202 |
if (dataLength > 0)
|
|
203 |
{
|
|
204 |
HBufC8* fileData = HBufC8::NewLC(dataLength);
|
|
205 |
TPtr8 ptr(fileData->Des());
|
|
206 |
|
|
207 |
iSessionEngine->ReadFileL(ptr);
|
|
208 |
|
|
209 |
//write the file data into the client descriptor
|
|
210 |
Message().WriteL(KSlot1, ptr);
|
|
211 |
|
|
212 |
CleanupStack::PopAndDestroy(fileData);
|
|
213 |
}
|
|
214 |
|
|
215 |
return ETrue;
|
|
216 |
}
|
|
217 |
|
|
218 |
//
|
|
219 |
// CTrkTcbSrvServer::CmdWriteFileL()
|
|
220 |
//
|
|
221 |
// Gets the data for write file request and calls the session engine write file method.
|
|
222 |
//
|
|
223 |
TBool CTrkTcbSrvSession::CmdWriteFileL()
|
|
224 |
{
|
|
225 |
const TInt fileDataLength = static_cast<TInt>(Message().Int0());
|
|
226 |
|
|
227 |
if (fileDataLength > 0)
|
|
228 |
{
|
|
229 |
HBufC8* fileData = HBufC8::NewLC(fileDataLength);
|
|
230 |
TPtr8 pFileData(fileData->Des());
|
|
231 |
Message().ReadL(KSlot1, pFileData);
|
|
232 |
|
|
233 |
iSessionEngine->WriteFileL(*fileData);
|
|
234 |
|
|
235 |
CleanupStack::PopAndDestroy(fileData);
|
|
236 |
|
|
237 |
return ETrue;
|
|
238 |
}
|
|
239 |
return EFalse;
|
|
240 |
}
|
|
241 |
|
|
242 |
//
|
|
243 |
// CTrkTcbSrvServer::CmdCloseFileL()
|
|
244 |
//
|
|
245 |
// Gets the data for close file request and calls the session engine close file method.
|
|
246 |
//
|
|
247 |
TBool CTrkTcbSrvSession::CmdCloseFileL()
|
|
248 |
{
|
|
249 |
TTime modificationTime;
|
|
250 |
|
|
251 |
TPckg<TTime> package(modificationTime);
|
|
252 |
Message().ReadL(KSlot0, package);
|
|
253 |
|
|
254 |
iSessionEngine->CloseFileL(modificationTime);
|
|
255 |
|
|
256 |
return ETrue;
|
|
257 |
}
|
|
258 |
|
|
259 |
//
|
|
260 |
// CTrkTcbSrvServer::CmdPositionFileL()
|
|
261 |
//
|
|
262 |
// Gets the data for position file request and calls the session engine position file method.
|
|
263 |
//
|
|
264 |
TBool CTrkTcbSrvSession::CmdPositionFileL()
|
|
265 |
{
|
|
266 |
TSeek seek;
|
|
267 |
|
|
268 |
TPckg<TSeek> seekPckg(seek);
|
|
269 |
Message().ReadL(KSlot0, seekPckg);
|
|
270 |
|
|
271 |
TInt offset = static_cast<TInt>(Message().Int1());;
|
|
272 |
|
|
273 |
iSessionEngine->PositionFileL(seek, offset);
|
|
274 |
|
|
275 |
return ETrue;
|
|
276 |
}
|
|
277 |
|
|
278 |
//
|
|
279 |
// CTrkTcbSrvServer::CmdShutDownServer()
|
|
280 |
//
|
|
281 |
// Stops the active scheduler. This way, server process will run to completion.
|
|
282 |
//
|
|
283 |
TBool CTrkTcbSrvSession::CmdShutDownServer()
|
|
284 |
{
|
|
285 |
CActiveScheduler::Stop();
|
|
286 |
|
|
287 |
return ETrue;
|
|
288 |
}
|