|
1 /* |
|
2 * Copyright (c) 2004-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 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 #include "CFSClient.h" |
|
20 #include "clientutils.h" |
|
21 #include "clientsession.h" |
|
22 |
|
23 CFSClient::CFSClient(TInt aUID, |
|
24 MCTToken& aToken, |
|
25 RFileStoreClientSession& aClient) |
|
26 : CActive(EPriorityNormal), |
|
27 iToken(aToken), |
|
28 iInterfaceUID(aUID), |
|
29 iClient(aClient), |
|
30 iRequestPtr(NULL, 0, 0) |
|
31 { |
|
32 } |
|
33 |
|
34 CFSClient::~CFSClient() |
|
35 { |
|
36 Cancel(); |
|
37 delete iRequestDataBuf; |
|
38 } |
|
39 |
|
40 CFSClient::TAsyncRequest::~TAsyncRequest() |
|
41 { |
|
42 __ASSERT_DEBUG(EIdle==iRequest, FSTokenPanic(ERequestOutstanding)); |
|
43 } |
|
44 |
|
45 void CFSClient::TAsyncRequest::operator()(TFSTokenMessages aRequest, TRequestStatus* aStatus) |
|
46 { |
|
47 __ASSERT_DEBUG(EIdle==iRequest, FSTokenPanic(ERequestOutstanding)); |
|
48 |
|
49 iRequest = aRequest; |
|
50 iClientStatus = aStatus; |
|
51 *aStatus = KRequestPending; |
|
52 } |
|
53 |
|
54 void CFSClient::TAsyncRequest::Complete(TInt aCompletionResult) |
|
55 { |
|
56 __ASSERT_DEBUG(EIdle!=iRequest, FSTokenPanic(ENoRequestOutstanding)); |
|
57 User::RequestComplete(iClientStatus, aCompletionResult); |
|
58 iRequest = EIdle; |
|
59 } |
|
60 |
|
61 void CFSClient::TAsyncRequest::Cancel() |
|
62 { |
|
63 User::RequestComplete(iClientStatus, KErrCancel); |
|
64 iRequest = EIdle; |
|
65 } |
|
66 |
|
67 void CFSClient::FreeRequestBuffer() const |
|
68 { |
|
69 delete iRequestDataBuf; |
|
70 iRequestDataBuf = NULL; |
|
71 iRequestPtr.Set(NULL, 0, 0); |
|
72 } |
|
73 |
|
74 TInt CFSClient::AllocRequestBuffer(TInt aReqdSize) const |
|
75 { |
|
76 ASSERT(aReqdSize > 0); |
|
77 TInt result = KErrNoMemory; |
|
78 |
|
79 FreeRequestBuffer(); |
|
80 iRequestDataBuf = HBufC8::NewMax(aReqdSize); |
|
81 if (iRequestDataBuf) |
|
82 { |
|
83 iRequestPtr.Set(iRequestDataBuf->Des()); |
|
84 iRequestPtr.FillZ(); |
|
85 result = KErrNone; |
|
86 } |
|
87 |
|
88 return result; |
|
89 } |
|
90 |
|
91 /** |
|
92 * Execute a synchronous request that returns a buffer of indetermintate length. |
|
93 * |
|
94 * If the initial buffer is too short, the server leaves with KErrOverflow and |
|
95 * passes us the required length - the reuest is then re-sent. |
|
96 */ |
|
97 void CFSClient::SendSyncRequestAndHandleOverflowL(TFSTokenMessages aMessage, |
|
98 TInt aInitialBufSize, |
|
99 const TIpcArgs& aArgs) const |
|
100 { |
|
101 User::LeaveIfError(AllocRequestBuffer(aInitialBufSize)); |
|
102 |
|
103 TInt err = iClient.SendRequest(aMessage, aArgs); |
|
104 if (err == KErrOverflow) |
|
105 { |
|
106 TInt sizeReqd = 0; |
|
107 TPckg<TInt> theSize(sizeReqd); |
|
108 theSize.Copy(iRequestPtr); |
|
109 User::LeaveIfError(AllocRequestBuffer(sizeReqd)); |
|
110 err = iClient.SendRequest(aMessage, aArgs); |
|
111 } |
|
112 |
|
113 User::LeaveIfError(err); |
|
114 } |
|
115 |
|
116 // ********************************************************************************* |
|
117 // CActive implementation |
|
118 // ********************************************************************************* |
|
119 |
|
120 void CFSClient::DoCancel() |
|
121 { |
|
122 iCurrentRequest.Cancel(); |
|
123 } |
|
124 |
|
125 TInt CFSClient::RunError(TInt aError) |
|
126 { |
|
127 iCurrentRequest.Complete(aError); |
|
128 return KErrNone; // Handled |
|
129 } |